--- ray/src/px/pfilt.c 1996/10/02 16:56:16 2.19 +++ ray/src/px/pfilt.c 2023/12/09 02:33:14 2.37 @@ -1,9 +1,6 @@ -/* Copyright (c) 1996 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: pfilt.c,v 2.37 2023/12/09 02:33:14 greg Exp $"; #endif - /* * pfilt.c - program to post-process picture file. * @@ -11,23 +8,17 @@ static char SCCSid[] = "$SunId$ LBL"; * 6/23/93 Added additional buffers for value spreading */ -#include "standard.h" +#include "copyright.h" #include - -#include "color.h" - +#include "pfilt.h" +#include "platform.h" +#include "paths.h" #include "view.h" -#include "resolu.h" - -#include "paths.h" - -extern float *matchlamp(); - #define FEQ(a,b) ((a) >= .98*(b) && (a) <= 1.02*(b)) -double CHECKRAD = 1.5; /* radius to check for filtering */ +double CHECKRAD = 2.0; /* radius to check for filtering */ #define THRESHRAD 5.0 /* maximum sample spread in output */ @@ -78,22 +69,30 @@ int xbrad; /* x box size */ int ybrad; /* y box size */ int barsize; /* size of input scan bar */ -COLOR **scanin; /* input scan bar */ -COLOR *scanout; /* output scan line */ -COLOR **scoutbar; /* output scan bar (if thresh > 0) */ +COLORV **scanin; /* input scan bar */ +COLORV *scanout; /* output scan line */ +COLORV **scoutbar; /* output scan bar (if thresh > 0) */ float **greybar; /* grey-averaged input values */ int obarsize = 0; /* size of output scan bar */ int orad = 0; /* output window radius */ char *progname; +static gethfunc headline; +static void copyfile(FILE *in, FILE *out); +static void pass1(FILE *in); +static void pass2(FILE *in); +static void scan2init(void); +static void scan2sync(int r); +static void scan2flush(void); -main(argc, argv) -int argc; -char **argv; + +int +main( + int argc, + char **argv +) { - extern long ftell(); - extern int quit(), headline(); FILE *fin; float *lampcolor; char *lamptype = NULL; @@ -101,18 +100,19 @@ char **argv; double outaspect = 0.0; double d; int i, j; -#ifdef MSDOS - extern int _fmode; - _fmode = O_BINARY; - setmode(fileno(stdin), O_BINARY); - setmode(fileno(stdout), O_BINARY); -#endif + SET_DEFAULT_BINARY(); + SET_FILE_BINARY(stdin); + SET_FILE_BINARY(stdout); if (signal(SIGINT, quit) == SIG_IGN) signal(SIGINT, SIG_IGN); +#ifdef SIGHUP if (signal(SIGHUP, quit) == SIG_IGN) signal(SIGHUP, SIG_IGN); +#endif signal(SIGTERM, quit); +#ifdef SIGPIPE signal(SIGPIPE, quit); +#endif #ifdef SIGXCPU signal(SIGXCPU, quit); signal(SIGXFSZ, quit); @@ -205,7 +205,7 @@ char **argv; case 'm': thresh = atof(argv[++i]); if (rad <= FTINY) - rad = 1.0; + rad = 0.6; break; case 'b': rad = thresh = 0.0; @@ -266,6 +266,10 @@ char **argv; progname); quit(1); } + if (setspectrsamp(CNDX, WLPART) < 0) { + fprintf(stderr, "%s: bad number of components\n", progname); + quit(1); + } /* add new header info. */ printargs(i, argv, stdout); /* get picture size */ @@ -310,55 +314,79 @@ char **argv; pass2(fin); quit(estatus); + return estatus; /* pro forma return */ } -double -rgb_bright(clr) -COLOR clr; +static double +rgb_bright( + SCOLOR clr +) { return(bright(clr)); } -double -xyz_bright(clr) -COLOR clr; +static double +xyz_bright( + SCOLOR clr +) { - return(clr[CIEY]); + return(colval(clr,CIEY)); } -double (*ourbright)() = rgb_bright; +static double +spec_bright( + SCOLOR clr +) +{ + return(pbright(clr)); +} -headline(s) /* process line from header */ -char *s; +brightfunc_t *ourbright = rgb_bright; + +static int +headline( /* process line from header */ + char *s, + void *p +) { - char fmt[32]; + char fmt[MAXFMTLEN]; fputs(s, stdout); /* copy to output */ if (isaspect(s)) /* get aspect ratio */ inpaspect *= aspectval(s); else if (isexpos(s)) /* get exposure */ hotlvl *= exposval(s); + else if (isncomp(s)) /* get #components (spectral) */ + NCSAMP = ncompval(s); + else if (iswlsplit(s)) /* get wavelength partitions */ + wlsplitval(WLPART, s); 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 if (!strcmp(SPECFMT, fmt)) + ourbright = spec_bright; else wrongformat = !globmatch(PICFMT, fmt); } else if (isview(s) && sscanview(&ourview, s) > 0) gotview++; + return(0); } -copyfile(in, out) /* copy a file */ -register FILE *in, *out; +static void +copyfile( /* copy a file */ + FILE *in, + FILE *out +) { - register int c; + int c; while ((c = getc(in)) != EOF) putc(c, out); @@ -370,21 +398,23 @@ register FILE *in, *out; } -pass1(in) /* first pass of picture file */ -FILE *in; +static void +pass1( /* first pass of picture file */ + FILE *in +) { int i; - COLOR *scan; + COLORV *scan; pass1init(); - scan = (COLOR *)malloc(xres*sizeof(COLOR)); + scan = (COLORV *)malloc(xres*NCSAMP*sizeof(COLORV)); if (scan == NULL) { fprintf(stderr, "%s: out of memory\n", progname); quit(1); } for (i = 0; i < yres; i++) { - if (freadscan(scan, xres, in) < 0) { + if (freadsscan(scan, NCSAMP, xres, in) < 0) { nrows = (long)nrows * i / yres; /* adjust frame */ if (nrows <= 0) { fprintf(stderr, "%s: empty frame\n", progname); @@ -399,12 +429,14 @@ FILE *in; } pass1scan(scan, i); } - free((char *)scan); + free(scan); } -pass2(in) /* last pass on file, write to stdout */ -FILE *in; +static void +pass2( /* last pass on file, write to stdout */ + FILE *in +) { int yread; int ycent, xcent; @@ -417,8 +449,8 @@ FILE *in; ycent = (r+.5)*yres/nrows; while (yread <= ycent+yrad) { if (yread < yres) { - if (freadscan(scanin[yread%barsize], - xres, in) < 0) { + if (freadsscan(scanin[yread%barsize], + NCSAMP, xres, in) < 0) { fprintf(stderr, "%s: truncated input (y=%d)\n", progname, yres-1-yread); @@ -435,18 +467,18 @@ FILE *in; if (thresh > FTINY) dothresh(xcent, ycent, c, r); else if (rad > FTINY) - dogauss(scanout[c], xcent, ycent, c, r); + dogauss(scanout+c*NCSAMP, xcent, ycent, c, r); else - dobox(scanout[c], xcent, ycent, c, r); + dobox(scanout+c*NCSAMP, xcent, ycent, c, r); } - if (scanout != NULL && fwritescan(scanout, ncols, stdout) < 0) { + if (scanout != NULL && fwritesscan(scanout, NCSAMP, ncols, stdout) < 0) { fprintf(stderr, "%s: write error in pass2\n", progname); quit(1); } } /* skip leftover input */ while (yread < yres) { - if (freadscan(scanin[0], xres, in) < 0) + if (freadsscan(scanin[0], NCSAMP, xres, in) < 0) break; yread++; } @@ -454,11 +486,12 @@ FILE *in; } -scan2init() /* prepare scanline arrays */ +static void +scan2init(void) /* prepare scanline arrays */ { COLOR ctmp; double d; - register int i; + int i; xbrad = xres/ncols/2 + 1; ybrad = yres/nrows/2 + 1; @@ -481,27 +514,27 @@ scan2init() /* prepare scanline arrays */ yrad = ybrad; } barsize = 2*yrad + 1; - scanin = (COLOR **)malloc(barsize*sizeof(COLOR *)); + scanin = (COLORV **)malloc(barsize*sizeof(COLORV *)); if (scanin == NULL) goto memerr; for (i = 0; i < barsize; i++) { - scanin[i] = (COLOR *)malloc(xres*sizeof(COLOR)); + scanin[i] = (COLORV *)malloc(xres*NCSAMP*sizeof(COLORV)); if (scanin[i] == NULL) goto memerr; } if (obarsize > 0) { - scoutbar = (COLOR **)malloc(obarsize*sizeof(COLOR *)); + scoutbar = (COLORV **)malloc(obarsize*sizeof(COLORV *)); greybar = (float **)malloc(obarsize*sizeof(float *)); - if (scoutbar == NULL | greybar == NULL) + if ((scoutbar == NULL) | (greybar == NULL)) goto memerr; for (i = 0; i < obarsize; i++) { - scoutbar[i] = (COLOR *)malloc(ncols*sizeof(COLOR)); + scoutbar[i] = (COLORV *)malloc(ncols*NCSAMP*sizeof(COLORV)); greybar[i] = (float *)malloc(ncols*sizeof(float)); - if (scoutbar[i] == NULL | greybar[i] == NULL) + if ((scoutbar[i] == NULL) | (greybar[i] == NULL)) goto memerr; } } else { - scanout = (COLOR *)malloc(ncols*sizeof(COLOR)); + scanout = (COLORV *)malloc(ncols*NCSAMP*sizeof(COLORV)); if (scanout == NULL) goto memerr; } @@ -512,7 +545,7 @@ scan2init() /* prepare scanline arrays */ fputaspect(d, stdout); } /* record exposure */ - d = (*ourbright)(exposure); + d = bright(exposure); if (!FEQ(d,1.0)) fputexpos(d, stdout); /* record color correction */ @@ -531,13 +564,15 @@ memerr: } -scan2sync(r) /* synchronize grey averages and output scan */ -int r; +static void +scan2sync( /* synchronize grey averages and output scan */ + int r +) { static int nextrow = 0; - COLOR ctmp; + SCOLOR ctmp; int ybot; - register int c; + int c; /* average input scanlines */ while (nextrow <= r+orad && nextrow < nrows) { ybot = (nextrow+.5)*yres/nrows; @@ -546,7 +581,7 @@ int r; greybar[nextrow%obarsize][c] = (*ourbright)(ctmp); } /* and zero output scanline */ - bzero((char *)scoutbar[nextrow%obarsize], ncols*sizeof(COLOR)); + memset(scoutbar[nextrow%obarsize], 0, ncols*NCSAMP*sizeof(COLORV)); nextrow++; } /* point to top scanline for output */ @@ -557,12 +592,13 @@ int r; } -scan2flush() /* flush output buffer */ +static void +scan2flush(void) /* flush output buffer */ { - register int r; + int r; for (r = nrows-orad; r < nrows; r++) - if (fwritescan(scoutbar[r%obarsize], ncols, stdout) < 0) + if (fwritesscan(scoutbar[r%obarsize], NCSAMP, ncols, stdout) < 0) break; if (fflush(stdout) < 0) { fprintf(stderr, "%s: write error at end of pass2\n", progname); @@ -571,6 +607,7 @@ scan2flush() /* flush output buffer */ } +void quit(code) /* remove temporary file and exit */ int code; {