--- ray/src/px/pcomb.c 1991/11/12 16:04:51 2.1 +++ ray/src/px/pcomb.c 1993/04/29 15:46:48 2.11 @@ -1,4 +1,4 @@ -/* Copyright (c) 1991 Regents of the University of California */ +/* Copyright (c) 1992 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -10,16 +10,16 @@ static char SCCSid[] = "$SunId$ LBL"; * 1/4/89 */ -#include +#include "standard.h" -#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 */ @@ -27,6 +27,8 @@ static char SCCSid[] = "$SunId$ LBL"; struct { char *name; /* file or command name */ FILE *fp; /* stream pointer */ + VIEW vw; /* view for picture */ + RESOLU rs; /* image resolution and orientation */ COLOR *scan[WINSIZ]; /* input scanline window */ COLOR coef; /* coefficient */ COLOR expos; /* recorded exposure */ @@ -34,6 +36,7 @@ struct { int nfiles; /* number of input files */ +char Command[] = ""; char vcolin[3][4] = {"ri", "gi", "bi"}; char vcolout[3][4] = {"ro", "go", "bo"}; char vbrtin[] = "li"; @@ -41,6 +44,8 @@ char vbrtout[] = "lo"; char vcolexp[3][4] = {"re", "ge", "be"}; char vbrtexp[] = "le"; +char vray[6][4] = {"Ox", "Oy", "Oz", "Dx", "Dy", "Dz"}; + char vnfiles[] = "nfiles"; char vxmax[] = "xmax"; char vymax[] = "ymax"; @@ -59,11 +64,16 @@ int xres, yres; /* output resolution */ int xpos, ypos; /* output position */ +char *progname; /* global argv[0] */ + int wrongformat = 0; +int gotview; FILE *popen(); +extern char *emalloc(); + main(argc, argv) int argc; char *argv[]; @@ -71,6 +81,13 @@ char *argv[]; int original; double f; int a, i; +#ifdef MSDOS + extern int _fmode; + _fmode = O_BINARY; + 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] == '-') @@ -93,6 +110,7 @@ char *argv[]; 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); } nfiles = 0; original = 0; @@ -124,10 +142,13 @@ char *argv[]; goto usage; } else { - input[nfiles].name = argv[a]; - input[nfiles].fp = argv[a][0]=='!' ? - popen(argv[a]+1, "r") : - fopen(argv[a], "r"); + if (argv[a][0] == '!') { + input[nfiles].name = Command; + input[nfiles].fp = popen(argv[a]+1, "r"); + } else { + input[nfiles].name = argv[a]; + input[nfiles].fp = fopen(argv[a], "r"); + } if (input[nfiles].fp == NULL) { perror(argv[a]); quit(1); @@ -191,7 +212,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); } @@ -214,7 +235,8 @@ char *s; } else if (iscolcor(s)) { /* color correction */ colcorval(ctmp, s); multcolor(input[nfiles].expos, ctmp); - } + } else if (isview(s) && sscanview(&input[nfiles].vw, s) > 0) + gotview++; /* echo line */ putchar('\t'); fputs(s, stdout); @@ -223,9 +245,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); @@ -234,15 +256,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); @@ -255,7 +280,7 @@ checkfile() /* ready a file */ init() /* perform final setup */ { - double l_colin(), l_expos(); + double l_colin(), l_expos(), l_ray(); register int i; /* define constants */ varset(vnfiles, ':', (double)nfiles); @@ -268,6 +293,8 @@ 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); } @@ -343,13 +370,16 @@ advance() /* read in data for next scanline */ input[i].scan[0] = st; if (yscan <= MIDSCN) /* hit bottom? */ continue; - if (freadscan(st, xmax, input[i].fp) < 0) { /* read */ + if (freadscan(st, xmax, input[i].fp) < 0) { /* read */ eputs(input[i].name); eputs(": read error\n"); quit(1); } - for (j = 0; j < xmax; j++) /* adjust color */ - multcolor(st[j], input[i].coef); + 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); } } @@ -431,6 +461,47 @@ register char *nam; } +double +l_ray(nam) /* return ray origin or direction */ +register char *nam; +{ + static 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 = ERANGE; + 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); +} + + wputs(msg) char *msg; { @@ -446,8 +517,15 @@ char *msg; } -quit(code) -int code; +quit(code) /* exit gracefully */ +int code; { + register int i; + /* close input files */ + for (i = 0; i < nfiles; i++) + if (input[i].name == Command) + pclose(input[i].fp); + else + fclose(input[i].fp); exit(code); }