| 19 | 
  | 
#include "calcomp.h" | 
| 20 | 
  | 
 | 
| 21 | 
  | 
#define MAXINP          32              /* maximum number of input files */ | 
| 22 | 
+ | 
#define WINSIZ          9               /* scanline window size */ | 
| 23 | 
+ | 
#define MIDSCN          4               /* current scan position */ | 
| 24 | 
  | 
 | 
| 25 | 
+ | 
#define BRT             (-1)            /* special index for brightness */ | 
| 26 | 
+ | 
 | 
| 27 | 
  | 
struct { | 
| 28 | 
  | 
        char    *name;          /* file name */ | 
| 29 | 
  | 
        FILE    *fp;            /* stream pointer */ | 
| 30 | 
< | 
        COLOR   *scan;          /* input scanline */ | 
| 30 | 
> | 
        COLOR   *scan[WINSIZ];  /* input scanline window */ | 
| 31 | 
  | 
        COLOR   coef;           /* coefficient */ | 
| 32 | 
  | 
}       input[MAXINP];                  /* input pictures */ | 
| 33 | 
  | 
 | 
| 46 | 
  | 
 | 
| 47 | 
  | 
int     nowarn = 0;                     /* no warning messages? */ | 
| 48 | 
  | 
 | 
| 49 | 
+ | 
int     original = 0;                   /* origninal values? */ | 
| 50 | 
+ | 
 | 
| 51 | 
  | 
int     xres=0, yres=0;                 /* picture resolution */ | 
| 52 | 
  | 
 | 
| 53 | 
  | 
int     xpos, ypos;                     /* picture position */ | 
| 54 | 
  | 
 | 
| 55 | 
+ | 
int     wrongformat = 0; | 
| 56 | 
  | 
 | 
| 57 | 
+ | 
 | 
| 58 | 
  | 
tputs(s)                        /* put out string preceded by a tab */ | 
| 59 | 
  | 
char    *s; | 
| 60 | 
  | 
{ | 
| 61 | 
< | 
        putchar('\t'); | 
| 62 | 
< | 
        fputs(s, stdout); | 
| 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 | 
  | 
 | 
| 87 | 
  | 
{ | 
| 88 | 
  | 
        extern double   l_redin(), l_grnin(), l_bluin(), l_brtin(), atof(); | 
| 89 | 
  | 
        double  f; | 
| 90 | 
< | 
        int     a; | 
| 90 | 
> | 
        int     a, i; | 
| 91 | 
  | 
         | 
| 92 | 
< | 
        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); | 
| 92 | 
> | 
        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++) | 
| 98 | 
  | 
                if (argv[a][0] == '-') | 
| 110 | 
  | 
                        case 'w': | 
| 111 | 
  | 
                                nowarn = !nowarn; | 
| 112 | 
  | 
                                break; | 
| 113 | 
+ | 
                        case 'o': | 
| 114 | 
+ | 
                                original = !original; | 
| 115 | 
+ | 
                                break; | 
| 116 | 
  | 
                        case 'f': | 
| 117 | 
  | 
                                fcompile(argv[++a]); | 
| 118 | 
  | 
                                break; | 
| 162 | 
  | 
                } | 
| 163 | 
  | 
                fputs(input[nfiles].name, stdout); | 
| 164 | 
  | 
                fputs(":\n", stdout); | 
| 165 | 
< | 
                getheader(input[nfiles].fp, tputs); | 
| 165 | 
> | 
                getheader(input[nfiles].fp, tputs, NULL); | 
| 166 | 
> | 
                if (wrongformat) { | 
| 167 | 
> | 
                        eputs(input[nfiles].name); | 
| 168 | 
> | 
                        eputs(": not in Radiance picture format\n"); | 
| 169 | 
> | 
                        quit(1); | 
| 170 | 
> | 
                } | 
| 171 | 
  | 
                if (fgetresolu(&xpos, &ypos, input[nfiles].fp) != | 
| 172 | 
  | 
                                (YMAJOR|YDECR)) { | 
| 173 | 
  | 
                        eputs(input[nfiles].name); | 
| 182 | 
  | 
                        eputs(": resolution mismatch\n"); | 
| 183 | 
  | 
                        quit(1); | 
| 184 | 
  | 
                } | 
| 185 | 
< | 
                input[nfiles].scan = (COLOR *)emalloc(xres*sizeof(COLOR)); | 
| 185 | 
> | 
                for (i = 0; i < WINSIZ; i++) | 
| 186 | 
> | 
                        input[nfiles].scan[i] = | 
| 187 | 
> | 
                                        (COLOR *)emalloc(xres*sizeof(COLOR)); | 
| 188 | 
  | 
                nfiles++; | 
| 189 | 
  | 
        } | 
| 190 | 
  | 
        printargs(argc, argv, stdout); | 
| 191 | 
+ | 
        fputformat(COLRFMT, stdout); | 
| 192 | 
  | 
        putchar('\n'); | 
| 193 | 
  | 
        fputresolu(YMAJOR|YDECR, xres, yres, stdout); | 
| 194 | 
  | 
        combine(); | 
| 196 | 
  | 
usage: | 
| 197 | 
  | 
        eputs("Usage: "); | 
| 198 | 
  | 
        eputs(argv[0]); | 
| 199 | 
< | 
eputs(" [-w][-x xr][-y yr][-e expr][-f file] [ [-s f][-c r g b] picture ..]\n"); | 
| 199 | 
> | 
        eputs( | 
| 200 | 
> | 
" [-w][-h][-x xr][-y yr][-e expr][-f file] [ [-s f][-c r g b] pic ..]\n"); | 
| 201 | 
  | 
        quit(1); | 
| 202 | 
  | 
} | 
| 203 | 
  | 
 | 
| 219 | 
  | 
                brtdef = eparse(vbrtout); | 
| 220 | 
  | 
        else | 
| 221 | 
  | 
                brtdef = NULL; | 
| 222 | 
< | 
                                                /* predefine variables */ | 
| 223 | 
< | 
        varset(vnfiles, (double)nfiles); | 
| 224 | 
< | 
        varset(vxres, (double)xres); | 
| 225 | 
< | 
        varset(vyres, (double)yres); | 
| 222 | 
> | 
                                                /* define constants */ | 
| 223 | 
> | 
        varset(vnfiles, ':', (double)nfiles); | 
| 224 | 
> | 
        varset(vxres, ':', (double)xres); | 
| 225 | 
> | 
        varset(vyres, ':', (double)yres); | 
| 226 | 
  | 
                                                /* allocate scanline */ | 
| 227 | 
  | 
        scanout = (COLOR *)emalloc(xres*sizeof(COLOR)); | 
| 228 | 
+ | 
                                                /* initialize input */ | 
| 229 | 
+ | 
        initinp(); | 
| 230 | 
  | 
                                                /* combine files */ | 
| 231 | 
  | 
        for (ypos = yres-1; ypos >= 0; ypos--) { | 
| 232 | 
< | 
            for (i = 0; i < nfiles; i++) | 
| 233 | 
< | 
                    if (freadscan(input[i].scan, xres, input[i].fp) < 0) { | 
| 194 | 
< | 
                            eputs(input[i].name); | 
| 195 | 
< | 
                            eputs(": read error\n"); | 
| 196 | 
< | 
                            quit(1); | 
| 197 | 
< | 
                    } | 
| 198 | 
< | 
            varset(vypos, (double)ypos); | 
| 232 | 
> | 
            advance(); | 
| 233 | 
> | 
            varset(vypos, '=', (double)ypos); | 
| 234 | 
  | 
            for (xpos = 0; xpos < xres; xpos++) { | 
| 235 | 
< | 
                varset(vxpos, (double)xpos); | 
| 235 | 
> | 
                varset(vxpos, '=', (double)xpos); | 
| 236 | 
  | 
                eclock++; | 
| 237 | 
  | 
                if (brtdef != NULL) { | 
| 238 | 
  | 
                    d = evalue(brtdef); | 
| 242 | 
  | 
                } else { | 
| 243 | 
  | 
                    for (j = 0; j < 3; j++) { | 
| 244 | 
  | 
                        if (coldef[j] != NULL) { | 
| 245 | 
< | 
                                colval(scanout[xpos],j) = evalue(coldef[j]); | 
| 245 | 
> | 
                                d = evalue(coldef[j]); | 
| 246 | 
  | 
                        } else { | 
| 247 | 
< | 
                            colval(scanout[xpos],j) = 0.0; | 
| 247 | 
> | 
                            d = 0.0; | 
| 248 | 
  | 
                            for (i = 0; i < nfiles; i++) | 
| 249 | 
< | 
                                colval(scanout[xpos],j) += | 
| 215 | 
< | 
                                        colval(input[i].coef,j) * | 
| 216 | 
< | 
                                        colval(input[i].scan[xpos],j); | 
| 249 | 
> | 
                                d += colval(input[i].scan[MIDSCN][xpos],j); | 
| 250 | 
  | 
                        } | 
| 251 | 
< | 
                        if (colval(scanout[xpos],j) < 0.0) | 
| 252 | 
< | 
                            colval(scanout[xpos],j) = 0.0; | 
| 251 | 
> | 
                        if (d < 0.0) | 
| 252 | 
> | 
                            d = 0.0; | 
| 253 | 
> | 
                        colval(scanout[xpos],j) = d; | 
| 254 | 
  | 
                    } | 
| 255 | 
  | 
                } | 
| 256 | 
  | 
            } | 
| 263 | 
  | 
} | 
| 264 | 
  | 
 | 
| 265 | 
  | 
 | 
| 266 | 
+ | 
initinp()                       /* initilize scan windows */ | 
| 267 | 
+ | 
{ | 
| 268 | 
+ | 
        for (ypos = yres+(MIDSCN-1); ypos >= yres; ypos--) | 
| 269 | 
+ | 
                advance(); | 
| 270 | 
+ | 
} | 
| 271 | 
+ | 
 | 
| 272 | 
+ | 
 | 
| 273 | 
+ | 
advance()                       /* read in next scanline */ | 
| 274 | 
+ | 
{ | 
| 275 | 
+ | 
        register COLOR  *st; | 
| 276 | 
+ | 
        register int    i, j; | 
| 277 | 
+ | 
 | 
| 278 | 
+ | 
        for (i = 0; i < nfiles; i++) { | 
| 279 | 
+ | 
                st = input[i].scan[WINSIZ-1]; | 
| 280 | 
+ | 
                for (j = WINSIZ-1; j > 0; j--)  /* rotate window */ | 
| 281 | 
+ | 
                        input[i].scan[j] = input[i].scan[j-1]; | 
| 282 | 
+ | 
                input[i].scan[0] = st; | 
| 283 | 
+ | 
                if (ypos < MIDSCN)              /* hit bottom */ | 
| 284 | 
+ | 
                        continue; | 
| 285 | 
+ | 
                if (freadscan(st, xres, input[i].fp) < 0) { | 
| 286 | 
+ | 
                        eputs(input[i].name); | 
| 287 | 
+ | 
                        eputs(": read error\n"); | 
| 288 | 
+ | 
                        quit(1); | 
| 289 | 
+ | 
                } | 
| 290 | 
+ | 
                for (j = 0; j < xres; j++)      /* adjust color */ | 
| 291 | 
+ | 
                        multcolor(st[j], input[i].coef); | 
| 292 | 
+ | 
        } | 
| 293 | 
+ | 
} | 
| 294 | 
+ | 
 | 
| 295 | 
+ | 
 | 
| 296 | 
  | 
double | 
| 297 | 
< | 
colin(fn, ci)                   /* return color value for picture */ | 
| 298 | 
< | 
register int    fn, ci; | 
| 297 | 
> | 
colin(ci)                       /* return color value for picture */ | 
| 298 | 
> | 
register int    ci; | 
| 299 | 
  | 
{ | 
| 300 | 
< | 
        if (fn == 0) | 
| 301 | 
< | 
                return((double)nfiles); | 
| 302 | 
< | 
        if (fn < 1 || fn > nfiles) { | 
| 300 | 
> | 
        int     n, fn; | 
| 301 | 
> | 
        register int    xoff, yoff; | 
| 302 | 
> | 
        double  d; | 
| 303 | 
> | 
 | 
| 304 | 
> | 
        fn = (d = argument(1)) - .5; | 
| 305 | 
> | 
        if (d <= -.5 || fn >= nfiles) { | 
| 306 | 
  | 
                errno = EDOM; | 
| 307 | 
  | 
                return(0.0); | 
| 308 | 
  | 
        } | 
| 309 | 
< | 
        return(colval(input[fn-1].scan[xpos],ci)); | 
| 309 | 
> | 
        if (d < .5) | 
| 310 | 
> | 
                return((double)nfiles); | 
| 311 | 
> | 
        xoff = yoff = 0; | 
| 312 | 
> | 
        n = nargum(); | 
| 313 | 
> | 
        if (n >= 2) { | 
| 314 | 
> | 
                d = argument(2); | 
| 315 | 
> | 
                if (d < 0.0) { | 
| 316 | 
> | 
                        xoff = d-.5; | 
| 317 | 
> | 
                        if (xpos+xoff < 0) | 
| 318 | 
> | 
                                xoff = -xpos; | 
| 319 | 
> | 
                } else { | 
| 320 | 
> | 
                        xoff = d+.5; | 
| 321 | 
> | 
                        if (xpos+xoff >= xres) | 
| 322 | 
> | 
                                xoff = xres-1-xpos; | 
| 323 | 
> | 
                } | 
| 324 | 
> | 
        } | 
| 325 | 
> | 
        if (n >= 3) { | 
| 326 | 
> | 
                d = argument(3); | 
| 327 | 
> | 
                if (d < 0.0) { | 
| 328 | 
> | 
                        yoff = d-.5; | 
| 329 | 
> | 
                        if (yoff+MIDSCN < 0) | 
| 330 | 
> | 
                                yoff = -MIDSCN; | 
| 331 | 
> | 
                        if (ypos+yoff < 0) | 
| 332 | 
> | 
                                yoff = -ypos; | 
| 333 | 
> | 
                } else { | 
| 334 | 
> | 
                        yoff = d+.5; | 
| 335 | 
> | 
                        if (yoff+MIDSCN >= WINSIZ) | 
| 336 | 
> | 
                                yoff = WINSIZ-1-MIDSCN; | 
| 337 | 
> | 
                        if (ypos+yoff >= yres) | 
| 338 | 
> | 
                                yoff = yres-1-ypos; | 
| 339 | 
> | 
                } | 
| 340 | 
> | 
        } | 
| 341 | 
> | 
        if (ci == BRT) | 
| 342 | 
> | 
                return(bright(input[fn].scan[MIDSCN+yoff][xpos+xoff])); | 
| 343 | 
> | 
        return(colval(input[fn].scan[MIDSCN+yoff][xpos+xoff],ci)); | 
| 344 | 
  | 
} | 
| 345 | 
  | 
 | 
| 346 | 
  | 
 | 
| 347 | 
  | 
double | 
| 348 | 
  | 
l_redin()                       /* get red color */ | 
| 349 | 
  | 
{ | 
| 350 | 
< | 
        return(colin((int)(argument(1)+.5), RED)); | 
| 350 | 
> | 
        return(colin(RED)); | 
| 351 | 
  | 
} | 
| 352 | 
  | 
 | 
| 353 | 
  | 
 | 
| 354 | 
  | 
double | 
| 355 | 
  | 
l_grnin()                       /* get green color */ | 
| 356 | 
  | 
{ | 
| 357 | 
< | 
        return(colin((int)(argument(1)+.5), GRN)); | 
| 357 | 
> | 
        return(colin(GRN)); | 
| 358 | 
  | 
} | 
| 359 | 
  | 
 | 
| 360 | 
  | 
 | 
| 361 | 
  | 
double | 
| 362 | 
  | 
l_bluin()                       /* get blue color */ | 
| 363 | 
  | 
{ | 
| 364 | 
< | 
        return(colin((int)(argument(1)+.5), BLU)); | 
| 364 | 
> | 
        return(colin(BLU)); | 
| 365 | 
  | 
} | 
| 366 | 
  | 
 | 
| 367 | 
  | 
 | 
| 368 | 
  | 
double | 
| 369 | 
  | 
l_brtin()                       /* get brightness value */ | 
| 370 | 
  | 
{ | 
| 371 | 
< | 
        register int    fn; | 
| 271 | 
< | 
 | 
| 272 | 
< | 
        fn = argument(1)+.5; | 
| 273 | 
< | 
        if (fn == 0) | 
| 274 | 
< | 
                return((double)nfiles); | 
| 275 | 
< | 
        if (fn < 1 || fn > nfiles) { | 
| 276 | 
< | 
                errno = EDOM; | 
| 277 | 
< | 
                return(0.0); | 
| 278 | 
< | 
        } | 
| 279 | 
< | 
        return(bright(input[fn-1].scan[xpos])); | 
| 371 | 
> | 
        return(colin(BRT)); | 
| 372 | 
  | 
} | 
| 373 | 
  | 
 | 
| 374 | 
  | 
 |