--- ray/src/px/pfilt.c 1995/05/31 08:50:27 2.14 +++ ray/src/px/pfilt.c 1996/05/22 10:42:08 2.18 @@ -1,4 +1,4 @@ -/* Copyright (c) 1992 Regents of the University of California */ +/* Copyright (c) 1996 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -17,6 +17,8 @@ static char SCCSid[] = "$SunId$ LBL"; #include "color.h" +#include "view.h" + #include "resolu.h" #include "paths.h" @@ -64,6 +66,12 @@ int correctaspect = 0; /* aspect ratio correction? * int wrongformat = 0; +VIEW ourview = STDVIEW; +int gotview = 0; +int wrapfilt = 0; /* wrap filter horizontally? */ + +int estatus = 0; /* exit status (for non-fatal errors) */ + int xrad; /* x search radius */ int yrad; /* y search radius */ int xbrad; /* x box size */ @@ -147,7 +155,7 @@ char **argv; fprintf(stderr, "%s: exposure out of range\n", argv[0]); - exit(1); + quit(1); } switch (argv[i][2]) { case '\0': @@ -267,6 +275,9 @@ char **argv; } if (!(order & YMAJOR)) inpaspect = 1.0/inpaspect; + /* wrap around for cylindrical view? */ + wrapfilt = gotview && ourview.type == VT_CYL && + ourview.horiz >= 360.-FTINY && order & YMAJOR; /* compute output resolution */ if (ncols <= 0) ncols = x_c*xres + .5; @@ -298,10 +309,29 @@ char **argv; } pass2(fin); - quit(0); + quit(estatus); } +double +rgb_bright(clr) +COLOR clr; +{ + return(bright(clr)); +} + + +double +xyz_bright(clr) +COLOR clr; +{ + return(clr[CIEY]); +} + + +double (*ourbright)() = rgb_bright; + + headline(s) /* process line from header */ char *s; { @@ -310,12 +340,18 @@ char *s; fputs(s, stdout); /* copy to output */ if (isaspect(s)) /* get aspect ratio */ inpaspect *= aspectval(s); - else if (isexpos(s)) + else if (isexpos(s)) /* get exposure */ hotlvl *= exposval(s); - else if (isformat(s)) { - formatval(fmt, s); - wrongformat = strcmp(fmt, COLRFMT); - } + else if (formatval(fmt, s)) { /* get format */ + wrongformat = 0; + if (!strcmp(COLRFMT, fmt)) + ourbright = rgb_bright; + else if (!strcmp(CIEFMT, fmt)) + ourbright = xyz_bright; + else + wrongformat = !globmatch(PICFMT, fmt); + } else if (isview(s) && sscanview(&ourview, s) > 0) + gotview++; } @@ -358,6 +394,7 @@ FILE *in; progname, (int)(100L*i/yres)); yres = i; y_r = (double)nrows/yres; + estatus++; break; } pass1scan(scan, i); @@ -430,9 +467,9 @@ scan2init() /* prepare scanline arrays */ rad *= (y_r + x_c)/2.0; if (thresh > FTINY) { - xrad = CHECKRAD*THRESHRAD*rad/x_c + xbrad; - yrad = CHECKRAD*THRESHRAD*rad/y_r + ybrad; orad = CHECKRAD*THRESHRAD*rad + 1; + xrad = orad/x_c + xbrad; + yrad = orad/y_r + ybrad; obarsize = 2*orad + 1; } else { xrad = CHECKRAD*rad/x_c + 1; @@ -475,7 +512,7 @@ scan2init() /* prepare scanline arrays */ fputaspect(d, stdout); } /* record exposure */ - d = bright(exposure); + d = (*ourbright)(exposure); if (!FEQ(d,1.0)) fputexpos(d, stdout); /* record color correction */ @@ -502,11 +539,11 @@ int r; int ybot; register int c; /* average input scanlines */ - while (nextrow < r+orad && nextrow < nrows) { + while (nextrow <= r+orad && nextrow < nrows) { ybot = (long)nextrow*yres/nrows; for (c = 0; c < ncols; c++) { dobox(ctmp, (int)((long)c*xres/ncols),ybot, c,nextrow); - greybar[nextrow%obarsize][c] = bright(ctmp); + greybar[nextrow%obarsize][c] = (*ourbright)(ctmp); } /* and zero output scanline */ bzero((char *)scoutbar[nextrow%obarsize], ncols*sizeof(COLOR)); @@ -529,7 +566,7 @@ scan2flush() /* flush output buffer */ break; if (fflush(stdout) < 0) { fprintf(stderr, "%s: write error at end of pass2\n", progname); - exit(1); + quit(1); } }