--- ray/src/px/pcomb.c 2003/08/04 22:37:53 2.27 +++ ray/src/px/pcomb.c 2009/08/10 04:26:38 2.44 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: pcomb.c,v 2.27 2003/08/04 22:37:53 greg Exp $"; +static const char RCSid[] = "$Id: pcomb.c,v 2.44 2009/08/10 04:26:38 greg Exp $"; #endif /* * Combine picture files according to calcomp functions. @@ -7,13 +7,14 @@ static const char RCSid[] = "$Id: pcomb.c,v 2.27 2003/ * 1/4/89 */ -#include "standard.h" #include "platform.h" +#include "standard.h" +#include "rtprocess.h" #include "color.h" #include "calcomp.h" #include "view.h" -#define MAXINP 32 /* maximum number of input files */ +#define MAXINP 1024 /* maximum number of input files */ #define WINSIZ 64 /* scanline window size */ #define MIDSCN ((WINSIZ-1)/2+1) @@ -32,6 +33,7 @@ int nfiles; /* number of input files */ char ourfmt[LPICFMT+1] = PICFMT; /* input picture format */ +char StandardInput[] = ""; char Command[] = ""; char vcolin[3][4] = {"ri", "gi", "bi"}; char vcolout[3][4] = {"ro", "go", "bo"}; @@ -66,21 +68,34 @@ int xpos, ypos; /* output position */ char *progname; /* global argv[0] */ +int echoheader = 1; int wrongformat = 0; int gotview; -FILE *popen(); -extern char *emalloc(); +static gethfunc headline; +static void checkfile(void); +static double rgb_bright(COLOR clr); +static double xyz_bright(COLOR clr); +static void init(void); +static void combine(void); +static void advance(void); +static double l_expos(char *nam); +static double l_pixaspect(char *nm); +static double l_colin(char *nam); +static double l_ray(char *nam); +static double l_psize(char *nm); -main(argc, argv) -int argc; -char *argv[]; +int +main( + int argc, + char *argv[] +) { int original; double f; - int a, i; + int a; SET_DEFAULT_BINARY(); SET_FILE_BINARY(stdin); SET_FILE_BINARY(stdout); @@ -96,6 +111,9 @@ char *argv[]; case 'w': nowarn = !nowarn; continue; + case 'h': + echoheader = !echoheader; + continue; case 'f': case 'e': a++; @@ -123,7 +141,7 @@ char *argv[]; if (argv[a][0] == '-') switch (argv[a][1]) { case '\0': - input[nfiles].name = ""; + input[nfiles].name = StandardInput; input[nfiles].fp = stdin; break; case 'o': @@ -180,6 +198,8 @@ char *argv[]; continue; case 'w': continue; + case 'h': + continue; case 'f': fcompile(argv[++a]); continue; @@ -214,13 +234,17 @@ 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 */ } -tabputs(s) /* put out string preceded by a tab */ -char *s; +static int +headline( /* check header line & echo if requested */ + char *s, + void *p +) { char fmt[32]; double d; @@ -246,20 +270,26 @@ char *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); } -checkfile() /* ready a file */ +static void +checkfile(void) /* ready a file */ { register 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, NULL); if (wrongformat < 0) { eputs(input[nfiles].name); eputs(": not a Radiance picture\n"); @@ -291,17 +321,19 @@ checkfile() /* ready a file */ } -double -rgb_bright(clr) -COLOR clr; +static double +rgb_bright( + COLOR clr +) { return(bright(clr)); } -double -xyz_bright(clr) -COLOR clr; +static double +xyz_bright( + COLOR clr +) { return(clr[CIEY]); } @@ -310,10 +342,9 @@ COLOR clr; double (*ourbright)() = rgb_bright; -init() /* perform final setup */ +static void +init(void) /* perform final setup */ { - double l_colin(char *), l_expos(char *), l_pixaspect(char *), - l_ray(char *), l_psize(char *); register int i; /* define constants */ varset("PI", ':', PI); @@ -340,7 +371,8 @@ init() /* perform final setup */ } -combine() /* combine pictures */ +static void +combine(void) /* combine pictures */ { EPNODE *coldef[3], *brtdef; COLOR *scanout; @@ -366,7 +398,7 @@ combine() /* 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) { @@ -398,13 +430,14 @@ combine() /* combine pictures */ } -advance() /* read in data for next scanline */ +static void +advance(void) /* read in data for next scanline */ { int ytarget; register COLOR *st; register 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 */ @@ -417,24 +450,28 @@ advance() /* 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); } } -double -l_expos(nam) /* return picture exposure */ -register char *nam; +static double +l_expos( /* return picture exposure */ + 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; @@ -443,34 +480,45 @@ register char *nam; return(colval(input[fn].expos,n)); eputs("Bad call to l_expos()!\n"); quit(1); + return 1; /* pro forma return */ } -double +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); } -double -l_colin(nam) /* return color value for picture */ -register char *nam; +static double +l_colin( /* return color value for picture */ + register char *nam +) { int fn; register 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) { @@ -509,25 +557,31 @@ register char *nam; return(colval(input[fn].scan[MIDSCN+yoff][xscan+xoff],n)); eputs("Bad call to l_colin()!\n"); quit(1); + return 1; /* pro forma return */ } -double -l_ray(nam) /* return ray origin or direction */ -register char *nam; +static double +l_ray( /* return ray origin or direction */ + register 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; - 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; @@ -548,10 +602,11 @@ register char *nam; return(i < 3 ? lorg[fn][i] : ldir[fn][i-3]); eputs("Bad call to l_ray()!\n"); quit(1); + return 1; /* pro forma return */ } -double +static double l_psize(char *nm) /* compute pixel size in steradians */ { static unsigned long ltick[MAXINP]; @@ -563,32 +618,34 @@ l_psize(char *nm) /* compute pixel size in steradians register 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) errno = EDOM; else if (input[fn].vw.type != VT_PAR && - funvalue(vray[6], 1, &d) >= 0) { + funvalue(vray[6], 1, &d) >= -FTINY) { for (i = 0; i < 3; i++) dir0[i] = funvalue(vray[3+i], 1, &d); pix2loc(locx, &input[fn].rs, xscan+1, ymax-1-yscan); pix2loc(locy, &input[fn].rs, xscan, ymax-yscan); if (viewray(org, dirx, &input[fn].vw, - locx[0], locx[1]) >= 0 && + locx[0], locx[1]) >= -FTINY && viewray(org, diry, &input[fn].vw, - locy[0], locy[1]) >= 0) { + locy[0], locy[1]) >= -FTINY) { /* approximate solid angle */ for (i = 0; i < 3; i++) { dirx[i] -= dir0[i]; diry[i] -= dir0[i]; } fcross(dir0, dirx, diry); - psize[fn] = sqrt(DOT(dir0,dir0)); + psize[fn] = VLEN(dir0); } } ltick[fn] = eclock; @@ -597,26 +654,23 @@ l_psize(char *nm) /* compute pixel size in steradians } -void -wputs(msg) -char *msg; +extern void +wputs(char *msg) { if (!nowarn) eputs(msg); } -void -eputs(msg) -char *msg; +extern void +eputs(char *msg) { fputs(msg, stderr); } -void -quit(code) /* exit gracefully */ -int code; +extern void +quit(int code) /* exit gracefully */ { register int i; /* close input files */