--- ray/src/px/pcomb.c 2005/02/16 03:26:33 2.36 +++ ray/src/px/pcomb.c 2023/11/20 21:44:29 2.56 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: pcomb.c,v 2.36 2005/02/16 03:26:33 greg Exp $"; +static const char RCSid[] = "$Id: pcomb.c,v 2.56 2023/11/20 21:44:29 greg Exp $"; #endif /* * Combine picture files according to calcomp functions. @@ -9,13 +9,13 @@ static const char RCSid[] = "$Id: pcomb.c,v 2.36 2005/ #include "platform.h" #include "standard.h" -#include "rtprocess.h" +#include "paths.h" #include "color.h" #include "calcomp.h" #include "view.h" -#define MAXINP 32 /* maximum number of input files */ -#define WINSIZ 64 /* scanline window size */ +#define MAXINP 1024 /* maximum number of input files */ +#define WINSIZ 127 /* scanline window size */ #define MIDSCN ((WINSIZ-1)/2+1) struct { @@ -31,8 +31,10 @@ struct { int nfiles; /* number of input files */ -char ourfmt[LPICFMT+1] = PICFMT; /* input picture format */ +VIEW *commvp = NULL; /* common view parameters */ +char ourfmt[MAXFMTLEN] = PICFMT; /* input picture format */ + char StandardInput[] = ""; char Command[] = ""; char vcolin[3][4] = {"ri", "gi", "bi"}; @@ -68,12 +70,13 @@ int xpos, ypos; /* output position */ char *progname; /* global argv[0] */ +int echoheader = 1; int wrongformat = 0; int gotview; -static gethfunc tabputs; -static void checkfile(void); +static gethfunc headline; +static void checkfile(int orig); static double rgb_bright(COLOR clr); static double xyz_bright(COLOR clr); static void init(void); @@ -95,10 +98,13 @@ main( int original; double f; int a; + SET_DEFAULT_BINARY(); SET_FILE_BINARY(stdin); SET_FILE_BINARY(stdout); progname = argv[0]; + esupport |= E_VARIABLE|E_FUNCTION|E_RCONST; + esupport &= ~(E_OUTCHAN|E_INCHAN); /* scan options */ for (a = 1; a < argc; a++) { if (argv[a][0] == '-') @@ -110,6 +116,9 @@ main( case 'w': nowarn = !nowarn; continue; + case 'h': + echoheader = !echoheader; + continue; case 'f': case 'e': a++; @@ -168,22 +177,14 @@ main( quit(1); } } - checkfile(); - if (original) { - colval(input[nfiles].coef,RED) /= - colval(input[nfiles].expos,RED); - colval(input[nfiles].coef,GRN) /= - colval(input[nfiles].expos,GRN); - colval(input[nfiles].coef,BLU) /= - colval(input[nfiles].expos,BLU); - setcolor(input[nfiles].expos, 1.0, 1.0, 1.0); - } + checkfile(original); nfiles++; original = 0; } init(); /* set constants */ /* go back and get expressions */ for (a = 1; a < argc; a++) { + char *fpath; if (argv[a][0] == '-') switch (argv[a][1]) { case 'x': @@ -194,8 +195,18 @@ main( continue; case 'w': continue; + case 'h': + continue; case 'f': - fcompile(argv[++a]); + fpath = getpath(argv[++a], getrlibpath(), 0); + if (fpath == NULL) { + eputs(argv[0]); + eputs(": cannot find file '"); + eputs(argv[a]); + eputs("'\n"); + quit(1); + } + fcompile(fpath); continue; case 'e': scompile(argv[++a], NULL, 0); @@ -203,11 +214,7 @@ main( } break; } - /* set/get output resolution */ - if (!vardefined(vxres)) - varset(vxres, ':', (double)xmax); - if (!vardefined(vyres)) - varset(vyres, ':', (double)ymax); + /* get output resolution */ xres = varvalue(vxres) + .5; yres = varvalue(vyres) + .5; if (xres <= 0 || yres <= 0) { @@ -217,6 +224,11 @@ main( } /* complete header */ printargs(argc, argv, stdout); + if (commvp != NULL) { + fputs(VIEWSTR, stdout); + fprintview(commvp, stdout); + fputc('\n', stdout); + } if (strcmp(ourfmt, PICFMT)) fputformat(ourfmt, stdout); /* print format if known */ putchar('\n'); @@ -228,19 +240,20 @@ usage: eputs("Usage: "); eputs(argv[0]); eputs( -" [-w][-x xr][-y yr][-e expr][-f file] [ [-o][-s f][-c r g b] pic ..]\n"); +" [-w][-h][-x xr][-y yr][-e expr][-f file] [ [-o][-s f][-c r g b] hdr ..]\n"); quit(1); return 1; /* pro forma return */ } static int -tabputs( /* put out string preceded by a tab */ +headline( /* check header line & echo if requested */ char *s, void *p ) { - char fmt[32]; + int orig = *(int *)p; + char fmt[MAXFMTLEN]; double d; COLOR ctmp; @@ -254,31 +267,50 @@ tabputs( /* put out string preceded by a tab */ wrongformat = globmatch(PICFMT, fmt) ? 1 : -1; return(0); /* don't echo */ } - if (isexpos(s)) { /* exposure */ + if (orig) { /* undo exposure? */ + if (isexpos(s)) { + d = 1./exposval(s); + scalecolor(input[nfiles].coef, d); + return(0); /* don't echo */ + } + if (iscolcor(s)) { + int i; + colcorval(ctmp, s); + for (i = 3; i--; ) + colval(input[nfiles].coef,i) /= colval(ctmp,i); + return(0); /* don't echo */ + } + } else if (isexpos(s)) { /* record exposure? */ d = exposval(s); scalecolor(input[nfiles].expos, d); - } else if (iscolcor(s)) { /* color correction */ + } else if (iscolcor(s)) { colcorval(ctmp, s); multcolor(input[nfiles].expos, ctmp); - } else if (isaspect(s)) + } + if (isaspect(s)) input[nfiles].pa *= aspectval(s); else if (isview(s) && sscanview(&input[nfiles].vw, s) > 0) gotview++; - /* echo line */ - putchar('\t'); - return(fputs(s, stdout)); + + if (echoheader) { /* echo line */ + putchar('\t'); + return(fputs(s, stdout)); + } + return(0); } static void -checkfile(void) /* ready a file */ +checkfile(int orig) /* ready a file */ { - register int i; + int i; /* process header */ gotview = 0; - fputs(input[nfiles].name, stdout); - fputs(":\n", stdout); - getheader(input[nfiles].fp, tabputs, NULL); + if (echoheader) { + fputs(input[nfiles].name, stdout); + fputs(":\n", stdout); + } + getheader(input[nfiles].fp, headline, &orig); if (wrongformat < 0) { eputs(input[nfiles].name); eputs(": not a Radiance picture\n"); @@ -290,6 +322,8 @@ checkfile(void) /* ready a file */ } if (!gotview || setview(&input[nfiles].vw) != NULL) input[nfiles].vw.type = 0; + else if (commvp == NULL) + commvp = &input[nfiles].vw; if (!fgetsresolu(&input[nfiles].rs, input[nfiles].fp)) { eputs(input[nfiles].name); eputs(": bad picture size\n"); @@ -334,7 +368,7 @@ double (*ourbright)() = rgb_bright; static void init(void) /* perform final setup */ { - register int i; + int i; /* define constants */ varset("PI", ':', PI); varset(vnfiles, ':', (double)nfiles); @@ -357,6 +391,9 @@ init(void) /* perform final setup */ ourbright = xyz_bright; } else varset(vwhteff, ':', WHTEFFICACY); + /* these may be overridden */ + varset(vxres, ':', (double)xmax); + varset(vyres, ':', (double)ymax); } @@ -366,7 +403,7 @@ combine(void) /* combine pictures */ EPNODE *coldef[3], *brtdef; COLOR *scanout; double d; - register int i, j; + int i, j; /* check defined variables */ for (j = 0; j < 3; j++) { if (vardefined(vcolout[j])) @@ -387,7 +424,7 @@ combine(void) /* combine pictures */ advance(); varset(vypos, '=', (double)ypos); for (xpos = 0; xpos < xres; xpos++) { - xscan = (long)xpos*xmax/xres; + xscan = (xpos+.5)*xmax/xres; varset(vxpos, '=', (double)xpos); eclock++; if (brtdef != NULL) { @@ -423,10 +460,10 @@ static void advance(void) /* read in data for next scanline */ { int ytarget; - register COLOR *st; - register int i, j; + COLOR *st; + int i, j; - for (ytarget = (long)ypos*ymax/yres; yscan > ytarget; yscan--) + for (ytarget = (ypos+.5)*ymax/yres; yscan > ytarget; yscan--) for (i = 0; i < nfiles; i++) { st = input[i].scan[WINSIZ-1]; for (j = WINSIZ-1; j > 0; j--) /* rotate window */ @@ -439,25 +476,28 @@ advance(void) /* read in data for next scanline */ eputs(": read error\n"); quit(1); } - if (fabs(colval(input[i].coef,RED)-1.0) > 1e-3 || - fabs(colval(input[i].coef,GRN)-1.0) > 1e-3 || - fabs(colval(input[i].coef,BLU)-1.0) > 1e-3) - for (j = 0; j < xmax; j++) /* adjust color */ - multcolor(st[j], input[i].coef); + for (j = 0; j < xmax; j++) /* adjust color */ + multcolor(st[j], input[i].coef); } } static double l_expos( /* return picture exposure */ - register char *nam + char *nam ) { - register int fn, n; + int fn, n; + double d; - fn = argument(1) - .5; - if (fn < 0 || fn >= nfiles) - return(1.0); + d = argument(1); + if (d <= -0.5 || d >= nfiles+0.5) { + errno = EDOM; + return(0.0); + } + if (d < 0.5) + return((double)nfiles); + fn = d - 0.5; if (nam == vbrtexp) return((*ourbright)(input[fn].expos)); n = 3; @@ -473,29 +513,38 @@ l_expos( /* return picture exposure */ static double l_pixaspect(char *nm) /* return pixel aspect ratio */ { - register int fn; + int fn; + double d; - fn = argument(1) - .5; - if (fn < 0 || fn >= nfiles) - return(1.0); + d = argument(1); + if (d <= -0.5 || d >= nfiles+0.5) { + errno = EDOM; + return(0.0); + } + if (d < 0.5) + return((double)nfiles); + fn = d - 0.5; return(input[fn].pa); } static double l_colin( /* return color value for picture */ - register char *nam + char *nam ) { int fn; - register int n, xoff, yoff; + int n, xoff, yoff; double d; - fn = argument(1) - .5; - if (fn < 0 || fn >= nfiles) { + d = argument(1); + if (d <= -0.5 || d >= nfiles+0.5) { errno = EDOM; return(0.0); } + if (d < 0.5) + return((double)nfiles); + fn = d - 0.5; xoff = yoff = 0; n = nargum(); if (n >= 2) { @@ -540,21 +589,25 @@ l_colin( /* return color value for picture */ static double l_ray( /* return ray origin or direction */ - register char *nam + char *nam ) { static unsigned long ltick[MAXINP]; static FVECT lorg[MAXINP], ldir[MAXINP]; static double ldist[MAXINP]; RREAL loc[2]; + double d; int fn; - register int i; + int i; - fn = argument(1) - .5; - if (fn < 0 || fn >= nfiles) { + d = argument(1); + if (d <= -0.5 || d >= nfiles+0.5) { errno = EDOM; return(0.0); } + if (d < 0.5) + return((double)nfiles); + fn = d - 0.5; if (ltick[fn] != eclock) { /* need to compute? */ lorg[fn][0] = lorg[fn][1] = lorg[fn][2] = 0.0; ldir[fn][0] = ldir[fn][1] = ldir[fn][2] = 0.0; @@ -588,14 +641,16 @@ l_psize(char *nm) /* compute pixel size in steradians RREAL locx[2], locy[2]; double d; int fn; - register int i; + int i; d = argument(1); - if (d < .5 || d >= nfiles+.5) { + if (d <= -0.5 || d >= nfiles+0.5) { errno = EDOM; return(0.0); } - fn = d - .5; + if (d < 0.5) + return((double)nfiles); + fn = d - 0.5; if (ltick[fn] != eclock) { /* need to compute? */ psize[fn] = 0.0; if (input[fn].vw.type == 0) @@ -626,7 +681,7 @@ l_psize(char *nm) /* compute pixel size in steradians extern void -wputs(char *msg) +wputs(const char *msg) { if (!nowarn) eputs(msg); @@ -634,7 +689,7 @@ wputs(char *msg) extern void -eputs(char *msg) +eputs(const char *msg) { fputs(msg, stderr); } @@ -643,7 +698,7 @@ eputs(char *msg) extern void quit(int code) /* exit gracefully */ { - register int i; + int i; /* close input files */ for (i = 0; i < nfiles; i++) if (input[i].name == Command)