--- ray/src/px/pcomb.c 1992/09/21 12:13:48 2.7 +++ ray/src/px/pcomb.c 1996/08/30 17:39:39 2.17 @@ -10,27 +10,26 @@ static char SCCSid[] = "$SunId$ LBL"; * 1/4/89 */ -#include +#include "standard.h" -#ifdef MSDOS -#include -#endif - -#include - #include "color.h" -#include "resolu.h" +#include "resolu.h" #include "calcomp.h" +#include "view.h" + #define MAXINP 32 /* maximum number of input files */ -#define WINSIZ 9 /* scanline window size */ -#define MIDSCN 4 /* current scan position */ +#define WINSIZ 17 /* scanline window size */ +#define MIDSCN ((WINSIZ-1)/2+1) struct { char *name; /* file or command name */ FILE *fp; /* stream pointer */ + VIEW vw; /* view for picture */ + RESOLU rs; /* image resolution and orientation */ + float pa; /* pixel aspect ratio */ COLOR *scan[WINSIZ]; /* input scanline window */ COLOR coef; /* coefficient */ COLOR expos; /* recorded exposure */ @@ -38,6 +37,8 @@ struct { int nfiles; /* number of input files */ +char ourfmt[LPICFMT+1] = PICFMT; /* input picture format */ + char Command[] = ""; char vcolin[3][4] = {"ri", "gi", "bi"}; char vcolout[3][4] = {"ro", "go", "bo"}; @@ -46,6 +47,10 @@ char vbrtout[] = "lo"; char vcolexp[3][4] = {"re", "ge", "be"}; char vbrtexp[] = "le"; +char vray[6][4] = {"Ox", "Oy", "Oz", "Dx", "Dy", "Dz"}; + +char vpsize[] = "S"; + char vnfiles[] = "nfiles"; char vxmax[] = "xmax"; char vymax[] = "ymax"; @@ -64,7 +69,10 @@ int xres, yres; /* output resolution */ int xpos, ypos; /* output position */ +char *progname; /* global argv[0] */ + int wrongformat = 0; +int gotview; FILE *popen(); @@ -84,6 +92,7 @@ char *argv[]; setmode(fileno(stdin), O_BINARY); setmode(fileno(stdout), O_BINARY); #endif + progname = argv[0]; /* scan options */ for (a = 1; a < argc; a++) { if (argv[a][0] == '-') @@ -102,10 +111,13 @@ char *argv[]; } break; } + newheader("RADIANCE", stdout); /* start header */ /* process files */ 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); + copystruct(&input[nfiles].vw, &stdview); + input[nfiles].pa = 1.0; } nfiles = 0; original = 0; @@ -197,7 +209,8 @@ char *argv[]; } /* complete header */ printargs(argc, argv, stdout); - fputformat(COLRFMT, stdout); + if (strcmp(ourfmt, PICFMT)) + fputformat(ourfmt, stdout); /* print format if known */ putchar('\n'); fprtresolu(xres, yres, stdout); /* combine pictures */ @@ -207,7 +220,7 @@ usage: eputs("Usage: "); eputs(argv[0]); eputs( -" [-w][-x xr][-y yr][-e expr][-f file] [ [-s f][-c r g b] pic ..]\n"); +" [-w][-x xr][-y yr][-e expr][-f file] [ [-o][-s f][-c r g b] pic ..]\n"); quit(1); } @@ -219,10 +232,15 @@ char *s; double d; COLOR ctmp; - if (isformat(s)) { /* check format */ - formatval(fmt, s); - wrongformat = strcmp(fmt, COLRFMT); + if (isheadid(s)) /* header id */ return; /* don't echo */ + if (formatval(fmt, s)) { /* check format */ + if (globmatch(ourfmt, fmt)) { + wrongformat = 0; + strcpy(ourfmt, fmt); + } else + wrongformat = 1; + return; /* don't echo */ } if (isexpos(s)) { /* exposure */ d = exposval(s); @@ -230,7 +248,10 @@ char *s; } else if (iscolcor(s)) { /* color correction */ colcorval(ctmp, s); multcolor(input[nfiles].expos, ctmp); - } + } else if (isaspect(s)) { + input[nfiles].pa *= aspectval(s); + } else if (isview(s) && sscanview(&input[nfiles].vw, s) > 0) + gotview++; /* echo line */ putchar('\t'); fputs(s, stdout); @@ -239,9 +260,9 @@ char *s; checkfile() /* ready a file */ { - int xinp, yinp; register int i; /* process header */ + gotview = 0; fputs(input[nfiles].name, stdout); fputs(":\n", stdout); getheader(input[nfiles].fp, tputs, NULL); @@ -250,15 +271,18 @@ checkfile() /* ready a file */ eputs(": not in Radiance picture format\n"); quit(1); } - if (fgetresolu(&xinp, &yinp, input[nfiles].fp) < 0) { + if (!gotview || setview(&input[nfiles].vw) != NULL) + input[nfiles].vw.type = 0; + if (!fgetsresolu(&input[nfiles].rs, input[nfiles].fp)) { eputs(input[nfiles].name); eputs(": bad picture size\n"); quit(1); } if (xmax == 0 && ymax == 0) { - xmax = xinp; - ymax = yinp; - } else if (xinp != xmax || yinp != ymax) { + xmax = scanlen(&input[nfiles].rs); + ymax = numscans(&input[nfiles].rs); + } else if (scanlen(&input[nfiles].rs) != xmax || + numscans(&input[nfiles].rs) != ymax) { eputs(input[nfiles].name); eputs(": resolution mismatch\n"); quit(1); @@ -269,9 +293,28 @@ checkfile() /* ready a file */ } +double +rgb_bright(clr) +COLOR clr; +{ + return(bright(clr)); +} + + +double +xyz_bright(clr) +COLOR clr; +{ + return(clr[CIEY]); +} + + +double (*ourbright)() = rgb_bright; + + init() /* perform final setup */ { - double l_colin(), l_expos(); + double l_colin(), l_expos(), l_ray(), l_psize(); register int i; /* define constants */ varset(vnfiles, ':', (double)nfiles); @@ -284,6 +327,12 @@ init() /* perform final setup */ } funset(vbrtexp, 1, ':', l_expos); funset(vbrtin, 1, '=', l_colin); + for (i = 0; i < 6; i++) + funset(vray[i], 1, '=', l_ray); + funset(vpsize, 1, '=', l_psize); + /* set brightness function */ + if (!strcmp(ourfmt, CIEFMT)) + ourbright = xyz_bright; } @@ -347,7 +396,6 @@ combine() /* combine pictures */ advance() /* read in data for next scanline */ { - extern double fabs(); int ytarget; register COLOR *st; register int i, j; @@ -384,7 +432,7 @@ register char *nam; if (fn < 0 || fn >= nfiles) return(1.0); if (nam == vbrtexp) - return(bright(input[fn].expos)); + return((*ourbright)(input[fn].expos)); n = 3; while (n--) if (nam == vcolexp[n]) @@ -441,13 +489,102 @@ register char *nam; } } if (nam == vbrtin) - return(bright(input[fn].scan[MIDSCN+yoff][xscan+xoff])); + return((*ourbright)(input[fn].scan[MIDSCN+yoff][xscan+xoff])); n = 3; while (n--) if (nam == vcolin[n]) return(colval(input[fn].scan[MIDSCN+yoff][xscan+xoff],n)); eputs("Bad call to l_colin()!\n"); quit(1); +} + + +double +l_ray(nam) /* return ray origin or direction */ +register char *nam; +{ + static unsigned long ltick[MAXINP]; + static FVECT lorg[MAXINP], ldir[MAXINP]; + FLOAT loc[2]; + double d; + int fn; + register int i; + + 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 (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; + if (input[fn].vw.type == 0) + errno = EDOM; + else { + pix2loc(loc, &input[fn].rs, xscan, ymax-1-yscan); + if (viewray(lorg[fn], ldir[fn], + &input[fn].vw, loc[0], loc[1]) < 0) + errno = ERANGE; + ltick[fn] = eclock; + } + } + i = 6; + while (i--) + if (nam == vray[i]) + return(i < 3 ? lorg[fn][i] : ldir[fn][i-3]); + eputs("Bad call to l_ray()!\n"); + quit(1); +} + + +double +l_psize() /* compute pixel size in steradians */ +{ + static unsigned long ltick[MAXINP]; + static double psize[MAXINP]; + FVECT dir0, org1, dir1; + FLOAT loc[2]; + double d; + int fn; + + 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 (ltick[fn] < eclock) /* need to compute? */ + if (input[fn].vw.type == 0 || input[fn].vw.type == VT_PAR) + errno = EDOM; + else { + errno = 0; + dir0[0] = funvalue(vray[3], 1, &d); + if (errno) + return(0.0); + dir0[1] = funvalue(vray[4], 1, &d); + if (errno) + return(0.0); + dir0[2] = funvalue(vray[5], 1, &d); + if (errno) + return(0.0); + pix2loc(loc, &input[fn].rs, xscan+1, ymax-yscan); + psize[fn] = 0.0; + if (viewray(org1, dir1, + &input[fn].vw, loc[0], loc[1]) < 0) + errno = ERANGE; + else { + /* approximate solid angle */ + psize[fn] = dist2(dir0, dir1) * input[fn].pa / + (1.0 + input[fn].pa*input[fn].pa); + ltick[fn] = eclock; + } + } + return(psize[fn]); }