| 1 | 
greg | 
1.1 | 
#ifndef lint | 
| 2 | 
schorsch | 
2.25 | 
static const char       RCSid[] = "$Id: pcompos.c,v 2.24 2003/07/27 22:12:03 schorsch Exp $"; | 
| 3 | 
greg | 
1.1 | 
#endif | 
| 4 | 
  | 
  | 
/* | 
| 5 | 
  | 
  | 
 *  pcompos.c - program to composite pictures. | 
| 6 | 
  | 
  | 
 * | 
| 7 | 
  | 
  | 
 *     6/30/87 | 
| 8 | 
  | 
  | 
 */ | 
| 9 | 
  | 
  | 
 | 
| 10 | 
  | 
  | 
#include  <stdio.h> | 
| 11 | 
greg | 
2.16 | 
#include  <math.h> | 
| 12 | 
schorsch | 
2.22 | 
#include  <time.h> | 
| 13 | 
schorsch | 
2.23 | 
#include  <string.h> | 
| 14 | 
greg | 
2.16 | 
 | 
| 15 | 
schorsch | 
2.22 | 
#include "copyright.h" | 
| 16 | 
greg | 
2.21 | 
 | 
| 17 | 
schorsch | 
2.22 | 
#include  "platform.h" | 
| 18 | 
schorsch | 
2.25 | 
#include  "rtprocess.h" | 
| 19 | 
greg | 
1.1 | 
#include  "color.h" | 
| 20 | 
greg | 
1.10 | 
#include  "resolu.h" | 
| 21 | 
greg | 
1.1 | 
 | 
| 22 | 
greg | 
2.15 | 
#define  MAXFILE        64 | 
| 23 | 
greg | 
1.1 | 
 | 
| 24 | 
greg | 
2.17 | 
#define  HASMIN         1 | 
| 25 | 
  | 
  | 
#define  HASMAX         2 | 
| 26 | 
  | 
  | 
 | 
| 27 | 
greg | 
1.1 | 
                                        /* output picture size */ | 
| 28 | 
  | 
  | 
int  xsiz = 0; | 
| 29 | 
  | 
  | 
int  ysiz = 0; | 
| 30 | 
  | 
  | 
                                        /* input dimensions */ | 
| 31 | 
  | 
  | 
int  xmin = 0; | 
| 32 | 
  | 
  | 
int  ymin = 0; | 
| 33 | 
  | 
  | 
int  xmax = 0; | 
| 34 | 
  | 
  | 
int  ymax = 0; | 
| 35 | 
  | 
  | 
 | 
| 36 | 
  | 
  | 
COLR  bgcolr = BLKCOLR;                 /* background color */ | 
| 37 | 
  | 
  | 
 | 
| 38 | 
greg | 
1.9 | 
int  labelht = 24;                      /* label height */ | 
| 39 | 
  | 
  | 
 | 
| 40 | 
greg | 
1.1 | 
int  checkthresh = 0;                   /* check threshold value */ | 
| 41 | 
  | 
  | 
 | 
| 42 | 
greg | 
2.14 | 
char  Command[] = "<Command>"; | 
| 43 | 
  | 
  | 
char  Label[] = "<Label>"; | 
| 44 | 
  | 
  | 
 | 
| 45 | 
greg | 
1.1 | 
char  *progname; | 
| 46 | 
  | 
  | 
 | 
| 47 | 
  | 
  | 
struct { | 
| 48 | 
greg | 
1.7 | 
        char  *name;                    /* file or command name */ | 
| 49 | 
greg | 
1.1 | 
        FILE  *fp;                      /* stream pointer */ | 
| 50 | 
  | 
  | 
        int  xres, yres;                /* picture size */ | 
| 51 | 
  | 
  | 
        int  xloc, yloc;                /* anchor point */ | 
| 52 | 
greg | 
2.17 | 
        int  flags;                     /* HASMIN, HASMAX */ | 
| 53 | 
greg | 
1.1 | 
        COLR  thmin, thmax;             /* thresholds */ | 
| 54 | 
  | 
  | 
} input[MAXFILE];               /* our input files */ | 
| 55 | 
  | 
  | 
 | 
| 56 | 
  | 
  | 
int  nfile;                     /* number of files */ | 
| 57 | 
  | 
  | 
 | 
| 58 | 
greg | 
2.19 | 
char  ourfmt[LPICFMT+1] = PICFMT; | 
| 59 | 
greg | 
1.6 | 
int  wrongformat = 0; | 
| 60 | 
greg | 
1.1 | 
 | 
| 61 | 
greg | 
2.21 | 
FILE  *lblopen(); | 
| 62 | 
  | 
  | 
void  quit(); | 
| 63 | 
greg | 
1.7 | 
 | 
| 64 | 
greg | 
2.15 | 
 | 
| 65 | 
greg | 
1.1 | 
tabputs(s)                      /* print line preceded by a tab */ | 
| 66 | 
  | 
  | 
char  *s; | 
| 67 | 
  | 
  | 
{ | 
| 68 | 
greg | 
1.6 | 
        char  fmt[32]; | 
| 69 | 
  | 
  | 
 | 
| 70 | 
greg | 
2.18 | 
        if (isheadid(s)) | 
| 71 | 
gwlarson | 
2.20 | 
                return(0); | 
| 72 | 
greg | 
2.19 | 
        if (formatval(fmt, s)) { | 
| 73 | 
  | 
  | 
                if (globmatch(ourfmt, fmt)) { | 
| 74 | 
  | 
  | 
                        wrongformat = 0; | 
| 75 | 
  | 
  | 
                        strcpy(ourfmt, fmt); | 
| 76 | 
  | 
  | 
                } else | 
| 77 | 
  | 
  | 
                        wrongformat = 1; | 
| 78 | 
  | 
  | 
        } else { | 
| 79 | 
greg | 
1.6 | 
                putc('\t', stdout); | 
| 80 | 
  | 
  | 
                fputs(s, stdout); | 
| 81 | 
  | 
  | 
        } | 
| 82 | 
gwlarson | 
2.20 | 
        return(0); | 
| 83 | 
greg | 
1.1 | 
} | 
| 84 | 
  | 
  | 
 | 
| 85 | 
  | 
  | 
 | 
| 86 | 
  | 
  | 
main(argc, argv) | 
| 87 | 
  | 
  | 
int  argc; | 
| 88 | 
  | 
  | 
char  *argv[]; | 
| 89 | 
  | 
  | 
{ | 
| 90 | 
greg | 
1.7 | 
        int  ncolumns = 0; | 
| 91 | 
greg | 
1.9 | 
        int  autolabel = 0; | 
| 92 | 
greg | 
2.11 | 
        int  curcol = 0, x0 = 0, curx = 0, cury = 0, spacing = 0; | 
| 93 | 
greg | 
2.17 | 
        int  xsgn, ysgn; | 
| 94 | 
greg | 
1.9 | 
        char  *thislabel; | 
| 95 | 
greg | 
1.1 | 
        int  an; | 
| 96 | 
schorsch | 
2.22 | 
        SET_DEFAULT_BINARY(); | 
| 97 | 
  | 
  | 
        SET_FILE_BINARY(stdin); | 
| 98 | 
  | 
  | 
        SET_FILE_BINARY(stdout); | 
| 99 | 
greg | 
1.1 | 
        progname = argv[0]; | 
| 100 | 
  | 
  | 
 | 
| 101 | 
  | 
  | 
        for (an = 1; an < argc && argv[an][0] == '-'; an++) | 
| 102 | 
  | 
  | 
                switch (argv[an][1]) { | 
| 103 | 
  | 
  | 
                case 'x': | 
| 104 | 
greg | 
2.11 | 
                        xsiz = atoi(argv[++an]); | 
| 105 | 
greg | 
1.1 | 
                        break; | 
| 106 | 
  | 
  | 
                case 'y': | 
| 107 | 
greg | 
2.11 | 
                        ysiz = atoi(argv[++an]); | 
| 108 | 
greg | 
1.1 | 
                        break; | 
| 109 | 
  | 
  | 
                case 'b': | 
| 110 | 
  | 
  | 
                        setcolr(bgcolr, atof(argv[an+1]), | 
| 111 | 
  | 
  | 
                                        atof(argv[an+2]), | 
| 112 | 
  | 
  | 
                                        atof(argv[an+3])); | 
| 113 | 
  | 
  | 
                        an += 3; | 
| 114 | 
  | 
  | 
                        break; | 
| 115 | 
greg | 
1.7 | 
                case 'a': | 
| 116 | 
  | 
  | 
                        ncolumns = atoi(argv[++an]); | 
| 117 | 
  | 
  | 
                        break; | 
| 118 | 
greg | 
2.11 | 
                case 's': | 
| 119 | 
  | 
  | 
                        spacing = atoi(argv[++an]); | 
| 120 | 
  | 
  | 
                        break; | 
| 121 | 
  | 
  | 
                case 'o': | 
| 122 | 
  | 
  | 
                        curx = x0 = atoi(argv[++an]); | 
| 123 | 
  | 
  | 
                        cury = atoi(argv[++an]); | 
| 124 | 
  | 
  | 
                        break; | 
| 125 | 
greg | 
1.7 | 
                case 'l': | 
| 126 | 
greg | 
1.9 | 
                        switch (argv[an][2]) { | 
| 127 | 
  | 
  | 
                        case 'a': | 
| 128 | 
  | 
  | 
                                autolabel++; | 
| 129 | 
  | 
  | 
                                break; | 
| 130 | 
  | 
  | 
                        case 'h': | 
| 131 | 
  | 
  | 
                                labelht = atoi(argv[++an]); | 
| 132 | 
  | 
  | 
                                break; | 
| 133 | 
  | 
  | 
                        case '\0': | 
| 134 | 
  | 
  | 
                                goto dofiles; | 
| 135 | 
  | 
  | 
                        default: | 
| 136 | 
  | 
  | 
                                goto userr; | 
| 137 | 
  | 
  | 
                        } | 
| 138 | 
greg | 
1.7 | 
                        break; | 
| 139 | 
greg | 
1.1 | 
                case '\0': | 
| 140 | 
  | 
  | 
                case 't': | 
| 141 | 
  | 
  | 
                        goto dofiles; | 
| 142 | 
  | 
  | 
                default: | 
| 143 | 
  | 
  | 
                        goto userr; | 
| 144 | 
  | 
  | 
                } | 
| 145 | 
  | 
  | 
dofiles: | 
| 146 | 
greg | 
2.18 | 
        newheader("RADIANCE", stdout); | 
| 147 | 
greg | 
2.21 | 
        fputnow(stdout); | 
| 148 | 
greg | 
1.1 | 
        for (nfile = 0; an < argc; nfile++) { | 
| 149 | 
greg | 
1.9 | 
                if (nfile >= MAXFILE) | 
| 150 | 
  | 
  | 
                        goto toomany; | 
| 151 | 
greg | 
2.6 | 
                thislabel = NULL; | 
| 152 | 
greg | 
2.17 | 
                input[nfile].flags = 0; | 
| 153 | 
  | 
  | 
                xsgn = ysgn = '-'; | 
| 154 | 
  | 
  | 
                while (an < argc && (argv[an][0] == '-' || argv[an][0] == '+' | 
| 155 | 
  | 
  | 
                                || argv[an][0] == '=')) { | 
| 156 | 
greg | 
1.1 | 
                        switch (argv[an][1]) { | 
| 157 | 
  | 
  | 
                        case 't': | 
| 158 | 
  | 
  | 
                                checkthresh = 1; | 
| 159 | 
  | 
  | 
                                if (argv[an][0] == '-') { | 
| 160 | 
greg | 
2.17 | 
                                        input[nfile].flags |= HASMIN; | 
| 161 | 
greg | 
1.1 | 
                                        setcolr(input[nfile].thmin, | 
| 162 | 
  | 
  | 
                                                        atof(argv[an+1]), | 
| 163 | 
  | 
  | 
                                                        atof(argv[an+1]), | 
| 164 | 
  | 
  | 
                                                        atof(argv[an+1])); | 
| 165 | 
greg | 
2.17 | 
                                } else if (argv[an][0] == '+') { | 
| 166 | 
  | 
  | 
                                        input[nfile].flags |= HASMAX; | 
| 167 | 
greg | 
1.1 | 
                                        setcolr(input[nfile].thmax, | 
| 168 | 
  | 
  | 
                                                        atof(argv[an+1]), | 
| 169 | 
  | 
  | 
                                                        atof(argv[an+1]), | 
| 170 | 
  | 
  | 
                                                        atof(argv[an+1])); | 
| 171 | 
greg | 
2.17 | 
                                } else | 
| 172 | 
  | 
  | 
                                        goto userr; | 
| 173 | 
  | 
  | 
                                an++; | 
| 174 | 
greg | 
1.1 | 
                                break; | 
| 175 | 
greg | 
1.9 | 
                        case 'l': | 
| 176 | 
  | 
  | 
                                if (strcmp(argv[an], "-l")) | 
| 177 | 
  | 
  | 
                                        goto userr; | 
| 178 | 
greg | 
2.17 | 
                                thislabel = argv[++an]; | 
| 179 | 
greg | 
1.9 | 
                                break; | 
| 180 | 
greg | 
2.17 | 
                        case '+': | 
| 181 | 
  | 
  | 
                        case '-': | 
| 182 | 
  | 
  | 
                        case '0': | 
| 183 | 
  | 
  | 
                                if (argv[an][0] != '=') | 
| 184 | 
  | 
  | 
                                        goto userr; | 
| 185 | 
  | 
  | 
                                xsgn = argv[an][1]; | 
| 186 | 
  | 
  | 
                                ysgn = argv[an][2]; | 
| 187 | 
  | 
  | 
                                if (ysgn != '+' && ysgn != '-' && ysgn != '0') | 
| 188 | 
  | 
  | 
                                        goto userr; | 
| 189 | 
  | 
  | 
                                break; | 
| 190 | 
greg | 
1.1 | 
                        case '\0': | 
| 191 | 
  | 
  | 
                                if (argv[an][0] == '-') | 
| 192 | 
  | 
  | 
                                        goto getfile; | 
| 193 | 
greg | 
1.9 | 
                                goto userr; | 
| 194 | 
greg | 
1.1 | 
                        default: | 
| 195 | 
  | 
  | 
                                goto userr; | 
| 196 | 
  | 
  | 
                        } | 
| 197 | 
greg | 
2.17 | 
                        an++; | 
| 198 | 
  | 
  | 
                } | 
| 199 | 
greg | 
1.1 | 
getfile: | 
| 200 | 
greg | 
1.7 | 
                if (argc-an < (ncolumns ? 1 : 3)) | 
| 201 | 
greg | 
1.1 | 
                        goto userr; | 
| 202 | 
greg | 
2.6 | 
                if (autolabel && thislabel == NULL) | 
| 203 | 
  | 
  | 
                        thislabel = argv[an]; | 
| 204 | 
greg | 
1.1 | 
                if (!strcmp(argv[an], "-")) { | 
| 205 | 
  | 
  | 
                        input[nfile].name = "<stdin>"; | 
| 206 | 
  | 
  | 
                        input[nfile].fp = stdin; | 
| 207 | 
  | 
  | 
                } else { | 
| 208 | 
greg | 
2.4 | 
                        if (argv[an][0] == '!') { | 
| 209 | 
greg | 
2.14 | 
                                input[nfile].name = Command; | 
| 210 | 
greg | 
2.4 | 
                                input[nfile].fp = popen(argv[an]+1, "r"); | 
| 211 | 
  | 
  | 
                        } else { | 
| 212 | 
  | 
  | 
                                input[nfile].name = argv[an]; | 
| 213 | 
  | 
  | 
                                input[nfile].fp = fopen(argv[an], "r"); | 
| 214 | 
  | 
  | 
                        } | 
| 215 | 
  | 
  | 
                        if (input[nfile].fp == NULL) { | 
| 216 | 
greg | 
1.5 | 
                                perror(argv[an]); | 
| 217 | 
greg | 
1.1 | 
                                quit(1); | 
| 218 | 
  | 
  | 
                        } | 
| 219 | 
  | 
  | 
                } | 
| 220 | 
  | 
  | 
                an++; | 
| 221 | 
  | 
  | 
                                                /* get header */ | 
| 222 | 
  | 
  | 
                printf("%s:\n", input[nfile].name); | 
| 223 | 
greg | 
1.6 | 
                getheader(input[nfile].fp, tabputs, NULL); | 
| 224 | 
  | 
  | 
                if (wrongformat) { | 
| 225 | 
greg | 
2.21 | 
                        fprintf(stderr, "%s: incompatible input format\n", | 
| 226 | 
greg | 
1.6 | 
                                        input[nfile].name); | 
| 227 | 
  | 
  | 
                        quit(1); | 
| 228 | 
  | 
  | 
                } | 
| 229 | 
greg | 
1.1 | 
                                                /* get picture size */ | 
| 230 | 
greg | 
1.4 | 
                if (fgetresolu(&input[nfile].xres, &input[nfile].yres, | 
| 231 | 
greg | 
1.10 | 
                                input[nfile].fp) < 0) { | 
| 232 | 
greg | 
1.1 | 
                        fprintf(stderr, "%s: bad picture size\n", | 
| 233 | 
  | 
  | 
                                        input[nfile].name); | 
| 234 | 
  | 
  | 
                        quit(1); | 
| 235 | 
  | 
  | 
                } | 
| 236 | 
greg | 
1.7 | 
                if (ncolumns > 0) { | 
| 237 | 
  | 
  | 
                        if (curcol >= ncolumns) { | 
| 238 | 
greg | 
2.11 | 
                                cury = ymax + spacing; | 
| 239 | 
  | 
  | 
                                curx = x0; | 
| 240 | 
greg | 
1.7 | 
                                curcol = 0; | 
| 241 | 
  | 
  | 
                        } | 
| 242 | 
  | 
  | 
                        input[nfile].xloc = curx; | 
| 243 | 
  | 
  | 
                        input[nfile].yloc = cury; | 
| 244 | 
greg | 
2.11 | 
                        curx += input[nfile].xres + spacing; | 
| 245 | 
greg | 
1.7 | 
                        curcol++; | 
| 246 | 
  | 
  | 
                } else { | 
| 247 | 
  | 
  | 
                        input[nfile].xloc = atoi(argv[an++]); | 
| 248 | 
greg | 
2.17 | 
                        if (xsgn == '+') | 
| 249 | 
  | 
  | 
                                input[nfile].xloc -= input[nfile].xres; | 
| 250 | 
  | 
  | 
                        else if (xsgn == '0') | 
| 251 | 
  | 
  | 
                                input[nfile].xloc -= input[nfile].xres/2; | 
| 252 | 
greg | 
1.7 | 
                        input[nfile].yloc = atoi(argv[an++]); | 
| 253 | 
greg | 
2.17 | 
                        if (ysgn == '+') | 
| 254 | 
  | 
  | 
                                input[nfile].yloc -= input[nfile].yres; | 
| 255 | 
  | 
  | 
                        else if (ysgn == '0') | 
| 256 | 
  | 
  | 
                                input[nfile].yloc -= input[nfile].yres/2; | 
| 257 | 
greg | 
1.7 | 
                } | 
| 258 | 
greg | 
1.1 | 
                if (input[nfile].xloc < xmin) | 
| 259 | 
  | 
  | 
                        xmin = input[nfile].xloc; | 
| 260 | 
  | 
  | 
                if (input[nfile].yloc < ymin) | 
| 261 | 
  | 
  | 
                        ymin = input[nfile].yloc; | 
| 262 | 
  | 
  | 
                if (input[nfile].xloc+input[nfile].xres > xmax) | 
| 263 | 
  | 
  | 
                        xmax = input[nfile].xloc+input[nfile].xres; | 
| 264 | 
  | 
  | 
                if (input[nfile].yloc+input[nfile].yres > ymax) | 
| 265 | 
  | 
  | 
                        ymax = input[nfile].yloc+input[nfile].yres; | 
| 266 | 
greg | 
1.9 | 
                if (thislabel != NULL) { | 
| 267 | 
  | 
  | 
                        if (++nfile >= MAXFILE) | 
| 268 | 
  | 
  | 
                                goto toomany; | 
| 269 | 
greg | 
2.14 | 
                        input[nfile].name = Label; | 
| 270 | 
greg | 
2.17 | 
                        input[nfile].flags = 0; | 
| 271 | 
greg | 
2.7 | 
                        input[nfile].xres = input[nfile-1].xres; | 
| 272 | 
  | 
  | 
                        input[nfile].yres = labelht; | 
| 273 | 
greg | 
1.9 | 
                        if ((input[nfile].fp = lblopen(thislabel, | 
| 274 | 
  | 
  | 
                                        &input[nfile].xres, | 
| 275 | 
  | 
  | 
                                        &input[nfile].yres)) == NULL) | 
| 276 | 
greg | 
1.7 | 
                                goto labelerr; | 
| 277 | 
  | 
  | 
                        input[nfile].xloc = input[nfile-1].xloc; | 
| 278 | 
  | 
  | 
                        input[nfile].yloc = input[nfile-1].yloc + | 
| 279 | 
greg | 
1.9 | 
                                        input[nfile-1].yres-input[nfile].yres; | 
| 280 | 
greg | 
1.7 | 
                } | 
| 281 | 
greg | 
1.1 | 
        } | 
| 282 | 
  | 
  | 
        if (xsiz <= 0) | 
| 283 | 
  | 
  | 
                xsiz = xmax; | 
| 284 | 
greg | 
2.11 | 
        else if (xsiz > xmax) | 
| 285 | 
  | 
  | 
                xmax = xsiz; | 
| 286 | 
greg | 
1.1 | 
        if (ysiz <= 0) | 
| 287 | 
  | 
  | 
                ysiz = ymax; | 
| 288 | 
greg | 
2.11 | 
        else if (ysiz > ymax) | 
| 289 | 
  | 
  | 
                ymax = ysiz; | 
| 290 | 
greg | 
1.1 | 
                                        /* add new header info. */ | 
| 291 | 
  | 
  | 
        printargs(argc, argv, stdout); | 
| 292 | 
greg | 
2.19 | 
        if (strcmp(ourfmt, PICFMT)) | 
| 293 | 
  | 
  | 
                fputformat(ourfmt, stdout);     /* print format if known */ | 
| 294 | 
greg | 
1.10 | 
        putchar('\n'); | 
| 295 | 
  | 
  | 
        fprtresolu(xsiz, ysiz, stdout); | 
| 296 | 
greg | 
1.1 | 
 | 
| 297 | 
  | 
  | 
        compos(); | 
| 298 | 
  | 
  | 
         | 
| 299 | 
  | 
  | 
        quit(0); | 
| 300 | 
  | 
  | 
userr: | 
| 301 | 
greg | 
2.11 | 
        fprintf(stderr, | 
| 302 | 
  | 
  | 
        "Usage: %s [-x xr][-y yr][-b r g b][-a n][-s p][-o x0 y0][-la][-lh h] ", | 
| 303 | 
greg | 
1.8 | 
                        progname); | 
| 304 | 
greg | 
2.17 | 
        fprintf(stderr, "[-t min1][+t max1][-l lab][=SS] pic1 x1 y1 ..\n"); | 
| 305 | 
greg | 
1.7 | 
        quit(1); | 
| 306 | 
greg | 
1.9 | 
toomany: | 
| 307 | 
  | 
  | 
        fprintf(stderr, "%s: only %d files and labels allowed\n", | 
| 308 | 
  | 
  | 
                        progname, MAXFILE); | 
| 309 | 
  | 
  | 
        quit(1); | 
| 310 | 
greg | 
1.7 | 
labelerr: | 
| 311 | 
  | 
  | 
        fprintf(stderr, "%s: error opening label\n", progname); | 
| 312 | 
greg | 
1.1 | 
        quit(1); | 
| 313 | 
  | 
  | 
} | 
| 314 | 
  | 
  | 
 | 
| 315 | 
  | 
  | 
 | 
| 316 | 
  | 
  | 
compos()                                /* composite pictures */ | 
| 317 | 
  | 
  | 
{ | 
| 318 | 
  | 
  | 
        COLR  *scanin, *scanout; | 
| 319 | 
  | 
  | 
        int  y; | 
| 320 | 
  | 
  | 
        register int  x, i; | 
| 321 | 
  | 
  | 
 | 
| 322 | 
greg | 
1.3 | 
        scanin = (COLR *)malloc((xmax-xmin)*sizeof(COLR)); | 
| 323 | 
greg | 
1.1 | 
        if (scanin == NULL) | 
| 324 | 
  | 
  | 
                goto memerr; | 
| 325 | 
  | 
  | 
        scanin -= xmin; | 
| 326 | 
  | 
  | 
        if (checkthresh) { | 
| 327 | 
  | 
  | 
                scanout = (COLR *)malloc(xsiz*sizeof(COLR)); | 
| 328 | 
  | 
  | 
                if (scanout == NULL) | 
| 329 | 
  | 
  | 
                        goto memerr; | 
| 330 | 
  | 
  | 
        } else | 
| 331 | 
  | 
  | 
                scanout = scanin; | 
| 332 | 
  | 
  | 
        for (y = ymax-1; y >= 0; y--) { | 
| 333 | 
  | 
  | 
                for (x = 0; x < xsiz; x++) | 
| 334 | 
  | 
  | 
                        copycolr(scanout[x], bgcolr); | 
| 335 | 
  | 
  | 
                for (i = 0; i < nfile; i++) { | 
| 336 | 
  | 
  | 
                        if (input[i].yloc > y || | 
| 337 | 
  | 
  | 
                                        input[i].yloc+input[i].yres <= y) | 
| 338 | 
  | 
  | 
                                continue; | 
| 339 | 
  | 
  | 
                        if (freadcolrs(scanin+input[i].xloc, | 
| 340 | 
  | 
  | 
                                        input[i].xres, input[i].fp) < 0) { | 
| 341 | 
greg | 
1.2 | 
                                fprintf(stderr, "%s: read error (y==%d)\n", | 
| 342 | 
  | 
  | 
                                                input[i].name, | 
| 343 | 
  | 
  | 
                                                y-input[i].yloc); | 
| 344 | 
greg | 
1.1 | 
                                quit(1); | 
| 345 | 
  | 
  | 
                        } | 
| 346 | 
  | 
  | 
                        if (y >= ysiz) | 
| 347 | 
  | 
  | 
                                continue; | 
| 348 | 
  | 
  | 
                        if (checkthresh) { | 
| 349 | 
  | 
  | 
                                x = input[i].xloc+input[i].xres; | 
| 350 | 
  | 
  | 
                                if (x > xsiz) | 
| 351 | 
  | 
  | 
                                        x = xsiz; | 
| 352 | 
  | 
  | 
                                for (x--; x >= 0 && x >= input[i].xloc; x--) { | 
| 353 | 
greg | 
2.17 | 
                                        if (input[i].flags & HASMIN && | 
| 354 | 
greg | 
1.1 | 
                                        cmpcolr(scanin[x], input[i].thmin) <= 0) | 
| 355 | 
  | 
  | 
                                                continue; | 
| 356 | 
greg | 
2.17 | 
                                        if (input[i].flags & HASMAX && | 
| 357 | 
greg | 
1.1 | 
                                        cmpcolr(scanin[x], input[i].thmax) >= 0) | 
| 358 | 
  | 
  | 
                                                continue; | 
| 359 | 
  | 
  | 
                                        copycolr(scanout[x], scanin[x]); | 
| 360 | 
  | 
  | 
                                } | 
| 361 | 
  | 
  | 
                        } | 
| 362 | 
  | 
  | 
                } | 
| 363 | 
  | 
  | 
                if (y >= ysiz) | 
| 364 | 
  | 
  | 
                        continue; | 
| 365 | 
  | 
  | 
                if (fwritecolrs(scanout, xsiz, stdout) < 0) { | 
| 366 | 
greg | 
1.5 | 
                        perror(progname); | 
| 367 | 
greg | 
1.1 | 
                        quit(1); | 
| 368 | 
  | 
  | 
                } | 
| 369 | 
  | 
  | 
        } | 
| 370 | 
  | 
  | 
        return; | 
| 371 | 
  | 
  | 
memerr: | 
| 372 | 
greg | 
1.5 | 
        perror(progname); | 
| 373 | 
greg | 
1.1 | 
        quit(1); | 
| 374 | 
  | 
  | 
} | 
| 375 | 
  | 
  | 
 | 
| 376 | 
  | 
  | 
 | 
| 377 | 
  | 
  | 
int | 
| 378 | 
  | 
  | 
cmpcolr(c1, c2)                 /* compare two colr's (improvisation) */ | 
| 379 | 
  | 
  | 
register COLR  c1, c2; | 
| 380 | 
  | 
  | 
{ | 
| 381 | 
  | 
  | 
        register int  i, j; | 
| 382 | 
  | 
  | 
 | 
| 383 | 
  | 
  | 
        j = 4;                          /* check exponents first! */ | 
| 384 | 
  | 
  | 
        while (j--) | 
| 385 | 
schorsch | 
2.24 | 
                if ( (i = c1[j] - c2[j]) ) | 
| 386 | 
greg | 
1.1 | 
                        return(i); | 
| 387 | 
  | 
  | 
        return(0); | 
| 388 | 
greg | 
1.9 | 
} | 
| 389 | 
  | 
  | 
 | 
| 390 | 
  | 
  | 
 | 
| 391 | 
  | 
  | 
FILE * | 
| 392 | 
  | 
  | 
lblopen(s, xp, yp)              /* open pipe to label generator */ | 
| 393 | 
  | 
  | 
char  *s; | 
| 394 | 
  | 
  | 
int  *xp, *yp; | 
| 395 | 
  | 
  | 
{ | 
| 396 | 
  | 
  | 
        char  com[128]; | 
| 397 | 
  | 
  | 
        FILE  *fp; | 
| 398 | 
  | 
  | 
 | 
| 399 | 
greg | 
2.7 | 
        sprintf(com, "psign -s -.15 -a 2 -x %d -y %d '%.90s'", *xp, *yp, s); | 
| 400 | 
greg | 
1.9 | 
        if ((fp = popen(com, "r")) == NULL) | 
| 401 | 
  | 
  | 
                return(NULL); | 
| 402 | 
  | 
  | 
        if (checkheader(fp, COLRFMT, NULL) < 0) | 
| 403 | 
  | 
  | 
                goto err; | 
| 404 | 
greg | 
1.10 | 
        if (fgetresolu(xp, yp, fp) < 0) | 
| 405 | 
greg | 
1.9 | 
                goto err; | 
| 406 | 
  | 
  | 
        return(fp); | 
| 407 | 
  | 
  | 
err: | 
| 408 | 
  | 
  | 
        pclose(fp); | 
| 409 | 
  | 
  | 
        return(NULL); | 
| 410 | 
greg | 
1.1 | 
} | 
| 411 | 
  | 
  | 
 | 
| 412 | 
  | 
  | 
 | 
| 413 | 
greg | 
2.21 | 
void | 
| 414 | 
greg | 
1.1 | 
quit(code)              /* exit gracefully */ | 
| 415 | 
  | 
  | 
int  code; | 
| 416 | 
  | 
  | 
{ | 
| 417 | 
greg | 
2.13 | 
        register int  i; | 
| 418 | 
  | 
  | 
                                /* close input files */ | 
| 419 | 
  | 
  | 
        for (i = 0; i < nfile; i++) | 
| 420 | 
greg | 
2.14 | 
                if (input[i].name == Command || input[i].name == Label) | 
| 421 | 
  | 
  | 
                        pclose(input[i].fp); | 
| 422 | 
  | 
  | 
                else | 
| 423 | 
  | 
  | 
                        fclose(input[i].fp); | 
| 424 | 
greg | 
1.1 | 
        exit(code); | 
| 425 | 
  | 
  | 
} |