--- ray/src/px/pfilt.c 1998/10/27 09:08:26 2.20 +++ ray/src/px/pfilt.c 2004/03/29 00:34:23 2.30 @@ -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.30 2004/03/29 00:34:23 schorsch Exp $"; #endif - /* * pfilt.c - program to post-process picture file. * @@ -11,23 +8,23 @@ static char SCCSid[] = "$SunId$ LBL"; * 6/23/93 Added additional buffers for value spreading */ -#include "standard.h" +#include "copyright.h" #include +#include +#include "platform.h" +#include "standard.h" +#include "rtio.h" #include "color.h" - #include "view.h" - -#include "resolu.h" - #include "paths.h" +#include "pfilt.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 */ @@ -87,13 +84,25 @@ int orad = 0; /* output window radius */ char *progname; +static gethfunc headline; +static brightfunc_t rgb_bright; +static brightfunc_t xyz_bright; +//static double rgb_bright(COLOR clr); +//static double xyz_bright(COLOR clr); +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 +110,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 +215,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; @@ -310,31 +320,35 @@ char **argv; pass2(fin); quit(estatus); + return estatus; /* pro forma return */ } -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]); } -double (*ourbright)() = rgb_bright; +brightfunc_t *ourbright = rgb_bright; - -int -headline(s) /* process line from header */ -char *s; +static int +headline( /* process line from header */ + char *s, + void *p +) { char fmt[32]; @@ -357,8 +371,11 @@ char *s; } -copyfile(in, out) /* copy a file */ -register FILE *in, *out; +static void +copyfile( /* copy a file */ + register FILE *in, + register FILE *out +) { register int c; @@ -372,8 +389,10 @@ 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; @@ -401,12 +420,14 @@ FILE *in; } pass1scan(scan, i); } - free((char *)scan); + free((void *)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; @@ -456,7 +477,8 @@ FILE *in; } -scan2init() /* prepare scanline arrays */ +static void +scan2init(void) /* prepare scanline arrays */ { COLOR ctmp; double d; @@ -494,12 +516,12 @@ scan2init() /* prepare scanline arrays */ if (obarsize > 0) { scoutbar = (COLOR **)malloc(obarsize*sizeof(COLOR *)); 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)); greybar[i] = (float *)malloc(ncols*sizeof(float)); - if (scoutbar[i] == NULL | greybar[i] == NULL) + if ((scoutbar[i] == NULL) | (greybar[i] == NULL)) goto memerr; } } else { @@ -533,8 +555,10 @@ 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; @@ -548,7 +572,7 @@ int r; greybar[nextrow%obarsize][c] = (*ourbright)(ctmp); } /* and zero output scanline */ - bzero((char *)scoutbar[nextrow%obarsize], ncols*sizeof(COLOR)); + memset((char *)scoutbar[nextrow%obarsize], '\0', ncols*sizeof(COLOR)); nextrow++; } /* point to top scanline for output */ @@ -559,7 +583,8 @@ int r; } -scan2flush() /* flush output buffer */ +static void +scan2flush(void) /* flush output buffer */ { register int r; @@ -573,6 +598,7 @@ scan2flush() /* flush output buffer */ } +void quit(code) /* remove temporary file and exit */ int code; {