| 35 |  |  | 
| 36 |  | char    *vcolin[3] = {"ri", "gi", "bi"}; | 
| 37 |  | char    *vcolout[3] = {"ro", "go", "bo"}; | 
| 38 | < | #define vbrtin          "li" | 
| 39 | < | #define vbrtout         "lo" | 
| 38 | > | char    vbrtin[] = "li"; | 
| 39 | > | char    vbrtout[] = "lo"; | 
| 40 | > | char    *vcolcoef[3] = {"rc", "gc", "bc"}; | 
| 41 | > | char    vbrtcoef[] = "lc"; | 
| 42 |  |  | 
| 43 |  | #define vnfiles         "nfiles" | 
| 44 |  | #define vxres           "xres" | 
| 57 |  | int     wrongformat = 0; | 
| 58 |  |  | 
| 59 |  |  | 
| 58 | – | tputs(s)                        /* put out string preceded by a tab */ | 
| 59 | – | char    *s; | 
| 60 | – | { | 
| 61 | – | char    fmt[32]; | 
| 62 | – | double  d; | 
| 63 | – | COLOR   ctmp; | 
| 64 | – |  | 
| 65 | – | if (isformat(s)) {                      /* check format */ | 
| 66 | – | formatval(fmt, s); | 
| 67 | – | wrongformat = strcmp(fmt, COLRFMT); | 
| 68 | – | } else if (original && isexpos(s)) {    /* exposure */ | 
| 69 | – | d = 1.0/exposval(s); | 
| 70 | – | scalecolor(input[nfiles].coef, d); | 
| 71 | – | } else if (original && iscolcor(s)) {   /* color correction */ | 
| 72 | – | colcorval(ctmp, s); | 
| 73 | – | colval(input[nfiles].coef,RED) /= colval(ctmp,RED); | 
| 74 | – | colval(input[nfiles].coef,GRN) /= colval(ctmp,GRN); | 
| 75 | – | colval(input[nfiles].coef,BLU) /= colval(ctmp,BLU); | 
| 76 | – | } else {                                /* echo unaffected line */ | 
| 77 | – | putchar('\t'); | 
| 78 | – | fputs(s, stdout); | 
| 79 | – | } | 
| 80 | – |  | 
| 81 | – | } | 
| 82 | – |  | 
| 83 | – |  | 
| 60 |  | main(argc, argv) | 
| 61 |  | int     argc; | 
| 62 |  | char    *argv[]; | 
| 63 |  | { | 
| 88 | – | extern double   l_redin(), l_grnin(), l_bluin(), l_brtin(), atof(); | 
| 64 |  | double  f; | 
| 65 |  | int     a, i; | 
| 66 | < |  | 
| 67 | < | funset(vcolin[RED], 1, '=', l_redin); | 
| 93 | < | funset(vcolin[GRN], 1, '=', l_grnin); | 
| 94 | < | funset(vcolin[BLU], 1, '=', l_bluin); | 
| 95 | < | funset(vbrtin, 1, '=', l_brtin); | 
| 96 | < |  | 
| 97 | < | for (a = 1; a < argc; a++) | 
| 66 | > | /* scan options */ | 
| 67 | > | for (a = 1; a < argc; a++) { | 
| 68 |  | if (argv[a][0] == '-') | 
| 69 |  | switch (argv[a][1]) { | 
| 100 | – | case '\0': | 
| 101 | – | case 's': | 
| 102 | – | case 'c': | 
| 103 | – | goto getfiles; | 
| 70 |  | case 'x': | 
| 71 |  | xres = atoi(argv[++a]); | 
| 72 | < | break; | 
| 72 | > | continue; | 
| 73 |  | case 'y': | 
| 74 |  | yres = atoi(argv[++a]); | 
| 75 | < | break; | 
| 75 | > | continue; | 
| 76 |  | case 'w': | 
| 77 |  | nowarn = !nowarn; | 
| 78 | < | break; | 
| 78 | > | continue; | 
| 79 |  | case 'o': | 
| 80 |  | original = !original; | 
| 81 | < | break; | 
| 81 | > | continue; | 
| 82 |  | case 'f': | 
| 117 | – | fcompile(argv[++a]); | 
| 118 | – | break; | 
| 83 |  | case 'e': | 
| 84 | < | scompile(argv[++a], NULL, 0); | 
| 121 | < | break; | 
| 122 | < | default: | 
| 123 | < | goto usage; | 
| 84 | > | continue; | 
| 85 |  | } | 
| 86 | < | else | 
| 87 | < | break; | 
| 88 | < | getfiles: | 
| 86 | > | break; | 
| 87 | > | } | 
| 88 | > | /* process files */ | 
| 89 |  | for (nfiles = 0; nfiles < MAXINP; nfiles++) | 
| 90 |  | setcolor(input[nfiles].coef, 1.0, 1.0, 1.0); | 
| 91 |  | nfiles = 0; | 
| 121 |  | quit(1); | 
| 122 |  | } | 
| 123 |  | } | 
| 124 | < | fputs(input[nfiles].name, stdout); | 
| 124 | > | nfiles++; | 
| 125 | > | } | 
| 126 | > | initfiles();            /* initialize files and variables */ | 
| 127 | > | /* go back and get expressions */ | 
| 128 | > | for (a = 1; a < argc; a++) { | 
| 129 | > | if (argv[a][0] == '-') | 
| 130 | > | switch (argv[a][1]) { | 
| 131 | > | case 'x': | 
| 132 | > | case 'y': | 
| 133 | > | case 'w': | 
| 134 | > | case 'o': | 
| 135 | > | continue; | 
| 136 | > | case 'f': | 
| 137 | > | fcompile(argv[++a]); | 
| 138 | > | continue; | 
| 139 | > | case 'e': | 
| 140 | > | scompile(argv[++a], NULL, 0); | 
| 141 | > | continue; | 
| 142 | > | } | 
| 143 | > | break; | 
| 144 | > | } | 
| 145 | > | /* complete header */ | 
| 146 | > | printargs(argc, argv, stdout); | 
| 147 | > | fputformat(COLRFMT, stdout); | 
| 148 | > | putchar('\n'); | 
| 149 | > | fputresolu(YMAJOR|YDECR, xres, yres, stdout); | 
| 150 | > | /* combine pictures */ | 
| 151 | > | combine(); | 
| 152 | > | quit(0); | 
| 153 | > | usage: | 
| 154 | > | eputs("Usage: "); | 
| 155 | > | eputs(argv[0]); | 
| 156 | > | eputs( | 
| 157 | > | " [-w][-h][-x xr][-y yr][-e expr][-f file] [ [-s f][-c r g b] pic ..]\n"); | 
| 158 | > | quit(1); | 
| 159 | > | } | 
| 160 | > |  | 
| 161 | > |  | 
| 162 | > | tputs(s)                        /* put out string preceded by a tab */ | 
| 163 | > | char    *s; | 
| 164 | > | { | 
| 165 | > | char    fmt[32]; | 
| 166 | > | double  d; | 
| 167 | > | COLOR   ctmp; | 
| 168 | > |  | 
| 169 | > | if (isformat(s)) {                      /* check format */ | 
| 170 | > | formatval(fmt, s); | 
| 171 | > | wrongformat = strcmp(fmt, COLRFMT); | 
| 172 | > | } else if (original && isexpos(s)) {    /* exposure */ | 
| 173 | > | d = 1.0/exposval(s); | 
| 174 | > | scalecolor(input[nfiles].coef, d); | 
| 175 | > | } else if (original && iscolcor(s)) {   /* color correction */ | 
| 176 | > | colcorval(ctmp, s); | 
| 177 | > | colval(input[nfiles].coef,RED) /= colval(ctmp,RED); | 
| 178 | > | colval(input[nfiles].coef,GRN) /= colval(ctmp,GRN); | 
| 179 | > | colval(input[nfiles].coef,BLU) /= colval(ctmp,BLU); | 
| 180 | > | } else {                                /* echo unaffected line */ | 
| 181 | > | putchar('\t'); | 
| 182 | > | fputs(s, stdout); | 
| 183 | > | } | 
| 184 | > |  | 
| 185 | > | } | 
| 186 | > |  | 
| 187 | > |  | 
| 188 | > | initfiles()                     /* ready files and set variables */ | 
| 189 | > | { | 
| 190 | > | double  l_colin(), l_coef(); | 
| 191 | > | register int    n, i; | 
| 192 | > | /* process picture headers */ | 
| 193 | > | for (n = 0; n < nfiles; n++) { | 
| 194 | > | fputs(input[n].name, stdout); | 
| 195 |  | fputs(":\n", stdout); | 
| 196 | < | getheader(input[nfiles].fp, tputs, NULL); | 
| 196 | > | getheader(input[n].fp, tputs, NULL); | 
| 197 |  | if (wrongformat) { | 
| 198 | < | eputs(input[nfiles].name); | 
| 198 | > | eputs(input[n].name); | 
| 199 |  | eputs(": not in Radiance picture format\n"); | 
| 200 |  | quit(1); | 
| 201 |  | } | 
| 202 | < | if (fgetresolu(&xpos, &ypos, input[nfiles].fp) != | 
| 203 | < | (YMAJOR|YDECR)) { | 
| 173 | < | eputs(input[nfiles].name); | 
| 202 | > | if (fgetresolu(&xpos, &ypos, input[n].fp) != (YMAJOR|YDECR)) { | 
| 203 | > | eputs(input[n].name); | 
| 204 |  | eputs(": bad picture size\n"); | 
| 205 |  | quit(1); | 
| 206 |  | } | 
| 208 |  | xres = xpos; | 
| 209 |  | yres = ypos; | 
| 210 |  | } else if (xpos != xres || ypos != yres) { | 
| 211 | < | eputs(argv[0]); | 
| 211 | > | eputs(input[n].name); | 
| 212 |  | eputs(": resolution mismatch\n"); | 
| 213 |  | quit(1); | 
| 214 |  | } | 
| 215 |  | for (i = 0; i < WINSIZ; i++) | 
| 216 | < | input[nfiles].scan[i] = | 
| 187 | < | (COLOR *)emalloc(xres*sizeof(COLOR)); | 
| 188 | < | nfiles++; | 
| 216 | > | input[n].scan[i] = (COLOR *)emalloc(xres*sizeof(COLOR)); | 
| 217 |  | } | 
| 218 | < | printargs(argc, argv, stdout); | 
| 219 | < | fputformat(COLRFMT, stdout); | 
| 220 | < | putchar('\n'); | 
| 221 | < | fputresolu(YMAJOR|YDECR, xres, yres, stdout); | 
| 222 | < | combine(); | 
| 223 | < | quit(0); | 
| 224 | < | usage: | 
| 225 | < | eputs("Usage: "); | 
| 226 | < | eputs(argv[0]); | 
| 227 | < | eputs( | 
| 228 | < | " [-w][-h][-x xr][-y yr][-e expr][-f file] [ [-s f][-c r g b] pic ..]\n"); | 
| 229 | < | quit(1); | 
| 218 | > | /* prime input */ | 
| 219 | > | for (ypos = yres+(MIDSCN-1); ypos >= yres; ypos--) | 
| 220 | > | advance(); | 
| 221 | > | /* define constants */ | 
| 222 | > | varset(vnfiles, ':', (double)nfiles); | 
| 223 | > | varset(vxres, ':', (double)xres); | 
| 224 | > | varset(vyres, ':', (double)yres); | 
| 225 | > | /* set functions */ | 
| 226 | > | for (i = 0; i < 3; i++) { | 
| 227 | > | funset(vcolcoef[i], 1, ':', l_coef); | 
| 228 | > | funset(vcolin[i], 1, '=', l_colin); | 
| 229 | > | } | 
| 230 | > | funset(vbrtcoef, 1, ':', l_coef); | 
| 231 | > | funset(vbrtin, 1, '=', l_colin); | 
| 232 |  | } | 
| 233 |  |  | 
| 234 |  |  | 
| 249 |  | brtdef = eparse(vbrtout); | 
| 250 |  | else | 
| 251 |  | brtdef = NULL; | 
| 222 | – | /* define constants */ | 
| 223 | – | varset(vnfiles, ':', (double)nfiles); | 
| 224 | – | varset(vxres, ':', (double)xres); | 
| 225 | – | varset(vyres, ':', (double)yres); | 
| 252 |  | /* allocate scanline */ | 
| 253 |  | scanout = (COLOR *)emalloc(xres*sizeof(COLOR)); | 
| 228 | – | /* initialize input */ | 
| 229 | – | initinp(); | 
| 254 |  | /* combine files */ | 
| 255 |  | for (ypos = yres-1; ypos >= 0; ypos--) { | 
| 256 |  | advance(); | 
| 287 |  | } | 
| 288 |  |  | 
| 289 |  |  | 
| 266 | – | initinp()                       /* initilize scan windows */ | 
| 267 | – | { | 
| 268 | – | for (ypos = yres+(MIDSCN-1); ypos >= yres; ypos--) | 
| 269 | – | advance(); | 
| 270 | – | } | 
| 271 | – |  | 
| 272 | – |  | 
| 290 |  | advance()                       /* read in next scanline */ | 
| 291 |  | { | 
| 292 |  | register COLOR  *st; | 
| 311 |  |  | 
| 312 |  |  | 
| 313 |  | double | 
| 314 | < | colin(ci)                       /* return color value for picture */ | 
| 315 | < | register int    ci; | 
| 314 | > | l_coef(nam)                     /* return picture coefficients */ | 
| 315 | > | register char   *nam; | 
| 316 |  | { | 
| 317 | < | int     n, fn; | 
| 301 | < | register int    xoff, yoff; | 
| 317 | > | register int    fn, n; | 
| 318 |  | double  d; | 
| 319 |  |  | 
| 320 |  | fn = (d = argument(1)) - .5; | 
| 324 |  | } | 
| 325 |  | if (d < .5) | 
| 326 |  | return((double)nfiles); | 
| 327 | + | if (nam == vbrtcoef) | 
| 328 | + | return(bright(input[fn].coef)); | 
| 329 | + | n = 3; | 
| 330 | + | while (n--) | 
| 331 | + | if (nam == vcolcoef[n]) | 
| 332 | + | return(colval(input[fn].coef,n)); | 
| 333 | + | eputs("Bad call to l_coef()!\n"); | 
| 334 | + | quit(1); | 
| 335 | + | } | 
| 336 | + |  | 
| 337 | + |  | 
| 338 | + | double | 
| 339 | + | l_colin(nam)                    /* return color value for picture */ | 
| 340 | + | register char   *nam; | 
| 341 | + | { | 
| 342 | + | int     fn; | 
| 343 | + | register int    n, xoff, yoff; | 
| 344 | + | double  d; | 
| 345 | + |  | 
| 346 | + | fn = (d = argument(1)) - .5; | 
| 347 | + | if (d <= -.5 || fn >= nfiles) { | 
| 348 | + | errno = EDOM; | 
| 349 | + | return(0.0); | 
| 350 | + | } | 
| 351 | + | if (d < .5) | 
| 352 | + | return((double)nfiles); | 
| 353 |  | xoff = yoff = 0; | 
| 354 |  | n = nargum(); | 
| 355 |  | if (n >= 2) { | 
| 380 |  | yoff = yres-1-ypos; | 
| 381 |  | } | 
| 382 |  | } | 
| 383 | < | if (ci == BRT) | 
| 383 | > | if (nam == vbrtin) | 
| 384 |  | return(bright(input[fn].scan[MIDSCN+yoff][xpos+xoff])); | 
| 385 | < | return(colval(input[fn].scan[MIDSCN+yoff][xpos+xoff],ci)); | 
| 386 | < | } | 
| 387 | < |  | 
| 388 | < |  | 
| 389 | < | double | 
| 390 | < | l_redin()                       /* get red color */ | 
| 349 | < | { | 
| 350 | < | return(colin(RED)); | 
| 351 | < | } | 
| 352 | < |  | 
| 353 | < |  | 
| 354 | < | double | 
| 355 | < | l_grnin()                       /* get green color */ | 
| 356 | < | { | 
| 357 | < | return(colin(GRN)); | 
| 358 | < | } | 
| 359 | < |  | 
| 360 | < |  | 
| 361 | < | double | 
| 362 | < | l_bluin()                       /* get blue color */ | 
| 363 | < | { | 
| 364 | < | return(colin(BLU)); | 
| 365 | < | } | 
| 366 | < |  | 
| 367 | < |  | 
| 368 | < | double | 
| 369 | < | l_brtin()                       /* get brightness value */ | 
| 370 | < | { | 
| 371 | < | return(colin(BRT)); | 
| 385 | > | n = 3; | 
| 386 | > | while (n--) | 
| 387 | > | if (nam == vcolin[n]) | 
| 388 | > | return(colval(input[fn].scan[MIDSCN+yoff][xpos+xoff],n)); | 
| 389 | > | eputs("Bad call to l_colin()!\n"); | 
| 390 | > | quit(1); | 
| 391 |  | } | 
| 392 |  |  | 
| 393 |  |  |