--- ray/src/px/pcomb.c 1991/05/24 14:46:14 1.15 +++ ray/src/px/pcomb.c 1991/05/24 17:14:49 1.17 @@ -29,6 +29,7 @@ struct { FILE *fp; /* stream pointer */ COLOR *scan[WINSIZ]; /* input scanline window */ COLOR coef; /* coefficient */ + COLOR expos; /* recorded exposure */ } input[MAXINP]; /* input pictures */ int nfiles; /* number of input files */ @@ -37,8 +38,8 @@ char *vcolin[3] = {"ri", "gi", "bi"}; char *vcolout[3] = {"ro", "go", "bo"}; char vbrtin[] = "li"; char vbrtout[] = "lo"; -char *vcolcoef[3] = {"rc", "gc", "bc"}; -char vbrtcoef[] = "lc"; +char *vcolexp[3] = {"re", "ge", "be"}; +char vbrtexp[] = "le"; #define vnfiles "nfiles" #define vxres "xres" @@ -76,18 +77,18 @@ char *argv[]; case 'w': nowarn = !nowarn; continue; - case 'o': - original = !original; - continue; case 'f': case 'e': + a++; continue; } break; } /* process files */ - for (nfiles = 0; nfiles < MAXINP; nfiles++) + for (nfiles = 0; nfiles < MAXINP; nfiles++) { setcolor(input[nfiles].coef, 1.0, 1.0, 1.0); + setcolor(input[nfiles].expos, 1.0, 1.0, 1.0); + } nfiles = 0; for ( ; a < argc; a++) { if (nfiles >= MAXINP) { @@ -101,6 +102,9 @@ char *argv[]; input[nfiles].name = ""; input[nfiles].fp = stdin; break; + case 'o': + original++; + break; case 's': f = atof(argv[++a]); scalecolor(input[nfiles].coef, f); @@ -121,17 +125,20 @@ char *argv[]; quit(1); } } + checkfile(); + original = 0; nfiles++; } - initfiles(); /* initialize files and variables */ + init(); /* set constant expressions */ /* go back and get expressions */ for (a = 1; a < argc; a++) { if (argv[a][0] == '-') switch (argv[a][1]) { case 'x': case 'y': + a++; + continue; case 'w': - case 'o': continue; case 'f': fcompile(argv[++a]); @@ -169,52 +176,63 @@ char *s; if (isformat(s)) { /* check format */ formatval(fmt, s); wrongformat = strcmp(fmt, COLRFMT); - } else if (original && isexpos(s)) { /* exposure */ - d = 1.0/exposval(s); - scalecolor(input[nfiles].coef, d); - } else if (original && iscolcor(s)) { /* color correction */ + return; /* don't echo */ + } + if (isexpos(s)) { /* exposure */ + d = exposval(s); + scalecolor(input[nfiles].expos, d); + if (original) + scalecolor(input[nfiles].coef, 1.0/d); + } else if (iscolcor(s)) { /* color correction */ colcorval(ctmp, s); - colval(input[nfiles].coef,RED) /= colval(ctmp,RED); - colval(input[nfiles].coef,GRN) /= colval(ctmp,GRN); - colval(input[nfiles].coef,BLU) /= colval(ctmp,BLU); - } else { /* echo unaffected line */ - putchar('\t'); - fputs(s, stdout); + multcolor(input[nfiles].expos, ctmp); + if (original) { + colval(input[nfiles].coef,RED) /= colval(ctmp,RED); + colval(input[nfiles].coef,GRN) /= colval(ctmp,GRN); + colval(input[nfiles].coef,BLU) /= colval(ctmp,BLU); + } } - + /* echo line */ + putchar('\t'); + fputs(s, stdout); } -initfiles() /* ready files and set variables */ +checkfile() /* ready a file */ { - double l_colin(), l_coef(); - register int n, i; - /* process picture headers */ - for (n = 0; n < nfiles; n++) { - fputs(input[n].name, stdout); - fputs(":\n", stdout); - getheader(input[n].fp, tputs, NULL); - if (wrongformat) { - eputs(input[n].name); - eputs(": not in Radiance picture format\n"); - quit(1); - } - if (fgetresolu(&xpos, &ypos, input[n].fp) != (YMAJOR|YDECR)) { - eputs(input[n].name); - eputs(": bad picture size\n"); - quit(1); - } - if (xres == 0 && yres == 0) { - xres = xpos; - yres = ypos; - } else if (xpos != xres || ypos != yres) { - eputs(input[n].name); - eputs(": resolution mismatch\n"); - quit(1); - } - for (i = 0; i < WINSIZ; i++) - input[n].scan[i] = (COLOR *)emalloc(xres*sizeof(COLOR)); + register int i; + /* process header */ + fputs(input[nfiles].name, stdout); + fputs(":\n", stdout); + getheader(input[nfiles].fp, tputs, NULL); + if (wrongformat) { + eputs(input[nfiles].name); + eputs(": not in Radiance picture format\n"); + quit(1); } + if (fgetresolu(&xpos, &ypos, input[nfiles].fp) != (YMAJOR|YDECR)) { + eputs(input[nfiles].name); + eputs(": bad picture size\n"); + quit(1); + } + if (xres == 0 && yres == 0) { + xres = xpos; + yres = ypos; + } else if (xpos != xres || ypos != yres) { + eputs(input[nfiles].name); + eputs(": resolution mismatch\n"); + quit(1); + } + /* allocate scanlines */ + for (i = 0; i < WINSIZ; i++) + input[nfiles].scan[i] = (COLOR *)emalloc(xres*sizeof(COLOR)); +} + + +init() /* perform final setup */ +{ + double l_colin(), l_expos(); + register int i; /* prime input */ for (ypos = yres+(MIDSCN-1); ypos >= yres; ypos--) advance(); @@ -224,10 +242,10 @@ initfiles() /* ready files and set variables */ varset(vyres, ':', (double)yres); /* set functions */ for (i = 0; i < 3; i++) { - funset(vcolcoef[i], 1, ':', l_coef); + funset(vcolexp[i], 1, ':', l_expos); funset(vcolin[i], 1, '=', l_colin); } - funset(vbrtcoef, 1, ':', l_coef); + funset(vbrtexp, 1, ':', l_expos); funset(vbrtin, 1, '=', l_colin); } @@ -311,26 +329,27 @@ advance() /* read in next scanline */ double -l_coef(nam) /* return picture coefficients */ +l_expos(nam) /* return picture exposure */ register char *nam; { register int fn, n; double d; - fn = (d = argument(1)) - .5; - if (d <= -.5 || fn >= nfiles) { + d = argument(1); + if (d > -.5 && d < .5) + return((double)nfiles); + fn = d - .5; + if (fn < 0 || fn >= nfiles) { errno = EDOM; return(0.0); } - if (d < .5) - return((double)nfiles); - if (nam == vbrtcoef) - return(bright(input[fn].coef)); + if (nam == vbrtexp) + return(bright(input[fn].expos)); n = 3; while (n--) - if (nam == vcolcoef[n]) - return(colval(input[fn].coef,n)); - eputs("Bad call to l_coef()!\n"); + if (nam == vcolexp[n]) + return(colval(input[fn].expos,n)); + eputs("Bad call to l_expos()!\n"); quit(1); } @@ -343,13 +362,14 @@ register char *nam; register int n, xoff, yoff; double d; - fn = (d = argument(1)) - .5; - if (d <= -.5 || fn >= nfiles) { + d = argument(1); + if (d > -.5 && d < .5) + return((double)nfiles); + fn = d - .5; + if (fn < 0 || fn >= nfiles) { errno = EDOM; return(0.0); } - if (d < .5) - return((double)nfiles); xoff = yoff = 0; n = nargum(); if (n >= 2) {