--- ray/src/px/pf3.c 2003/06/30 14:59:12 2.16 +++ ray/src/px/pf3.c 2018/07/26 23:50:40 2.19 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: pf3.c,v 2.16 2003/06/30 14:59:12 schorsch Exp $"; +static const char RCSid[] = "$Id: pf3.c,v 2.19 2018/07/26 23:50:40 greg Exp $"; #endif /* * pf3.c - routines for gaussian and box filtering @@ -12,41 +12,12 @@ static const char RCSid[] = "$Id: pf3.c,v 2.16 2003/06 #include #include "color.h" +#include "pfilt.h" #define RSCA 1.13 /* square-radius multiplier: sqrt(4/PI) */ #define TEPS 0.2 /* threshold proximity goal */ #define REPS 0.1 /* radius proximity goal */ -extern double CHECKRAD; /* radius over which gaussian is summed */ - -extern double rad; /* output pixel radius for filtering */ - -extern double thresh; /* maximum contribution for subpixel */ - -extern int nrows; /* number of rows for output */ -extern int ncols; /* number of columns for output */ - -extern int xres, yres; /* resolution of input */ - -extern double x_c, y_r; /* conversion factors */ - -extern int xrad; /* x search radius */ -extern int yrad; /* y search radius */ -extern int xbrad; /* x box size */ -extern int ybrad; /* y box size */ - -extern int barsize; /* size of input scan bar */ -extern COLOR **scanin; /* input scan bar */ -extern COLOR *scanout; /* output scan line */ -extern COLOR **scoutbar; /* output scan bar (if thresh > 0) */ -extern float **greybar; /* grey-averaged input values */ -extern int obarsize; /* size of output scan bar */ -extern int orad; /* output window radius */ - -extern int wrapfilt; /* wrap filter horizontally? */ - -extern char *progname; - float *gausstable; /* gauss lookup table */ float *ringsum; /* sum of ring values */ @@ -54,31 +25,31 @@ short *ringwt; /* weight (count) of ring values */ short *ringndx; /* ring index table */ float *warr; /* array of pixel weights */ -extern double (*ourbright)(); /* brightness computation function */ +#define lookgauss(x) gausstable[(int)(20.*(x)+.5)] -double pickfilt(); +static double pickfilt(double p0); +static void sumans(int px, int py, int rcent, int ccent, double m); -#define lookgauss(x) gausstable[(int)(10.*(x)+.5)] - -initmask() /* initialize gaussian lookup table */ +void +initmask(void) /* initialize gaussian lookup table */ { int gtabsiz; double gaussN; double d; - register int x; + int x; - gtabsiz = 111*CHECKRAD*CHECKRAD; + gtabsiz = 444*CHECKRAD*CHECKRAD; gausstable = (float *)malloc(gtabsiz*sizeof(float)); if (gausstable == NULL) goto memerr; d = x_c*y_r*0.25/(rad*rad); gausstable[0] = exp(-d); for (x = 1; x < gtabsiz; x++) - if (x*0.1 <= d) + if (x*0.05 <= d) gausstable[x] = gausstable[0]; else - gausstable[x] = exp(-x*0.1); + gausstable[x] = exp(-x*0.05); if (obarsize == 0) return; /* compute integral of filter */ @@ -101,7 +72,7 @@ initmask() /* initialize gaussian lookup table */ ringsum = (float *)malloc((orad+1)*sizeof(float)); ringwt = (short *)malloc((orad+1)*sizeof(short)); warr = (float *)malloc(obarsize*obarsize*sizeof(float)); - if (ringsum == NULL | ringwt == 0 | warr == NULL) + if ((ringsum == NULL) | (ringwt == 0) | (warr == NULL)) goto memerr; return; memerr: @@ -110,16 +81,20 @@ memerr: } -dobox(csum, xcent, ycent, c, r) /* simple box filter */ -COLOR csum; -int xcent, ycent; -int c, r; +void +dobox( /* simple box filter */ + COLOR csum, + int xcent, + int ycent, + int c, + int r +) { int wsum; double d; int y; - register int x, offs; - register COLOR *scan; + int x, offs; + COLOR *scan; wsum = 0; setcolor(csum, 0.0, 0.0, 0.0); @@ -148,16 +123,20 @@ int c, r; } -dogauss(csum, xcent, ycent, c, r) /* gaussian filter */ -COLOR csum; -int xcent, ycent; -int c, r; +void +dogauss( /* gaussian filter */ + COLOR csum, + int xcent, + int ycent, + int c, + int r +) { double dy, dx, weight, wsum; COLOR ctmp; int y; - register int x, offs; - register COLOR *scan; + int x, offs; + COLOR *scan; wsum = FTINY; setcolor(csum, 0.0, 0.0, 0.0); @@ -183,14 +162,18 @@ int c, r; } -dothresh(xcent, ycent, ccent, rcent) /* gaussian threshold filter */ -int xcent, ycent; -int ccent, rcent; +void +dothresh( /* gaussian threshold filter */ + int xcent, + int ycent, + int ccent, + int rcent +) { double d; int r, y, offs; - register int c, x; - register float *gscan; + int c, x; + float *gscan; /* compute ring sums */ memset((char *)ringsum, '\0', (orad+1)*sizeof(float)); memset((char *)ringwt, '\0', (orad+1)*sizeof(short)); @@ -230,15 +213,16 @@ int ccent, rcent; } -double -pickfilt(p0) /* find filter multiplier for p0 */ -double p0; +static double +pickfilt( /* find filter multiplier for p0 */ + double p0 +) { double m = 1.0; double t, num, denom, avg, wsum; double mlimit[2]; int ilimit = 4.0/TEPS; - register int i; + int i; /* iterative search for m */ mlimit[0] = 1.0; mlimit[1] = orad/rad/CHECKRAD; do { @@ -290,17 +274,21 @@ double p0; } -sumans(px, py, rcent, ccent, m) /* sum input pixel to output */ -int px, py; -int rcent, ccent; -double m; +static void +sumans( /* sum input pixel to output */ + int px, + int py, + int rcent, + int ccent, + double m +) { double dy2, dx; COLOR pval, ctmp; int ksiz, r, offs; double pc, pr, norm; - register int i, c; - register COLOR *scan; + int i, c; + COLOR *scan; /* * This normalization method fails at the picture borders because * a different number of input pixels contribute there. @@ -339,7 +327,7 @@ double m; scan = scoutbar[r%obarsize]; for (c = ccent-ksiz; c <= ccent+ksiz; c++) { offs = c < 0 ? ncols : c >= ncols ? -ncols : 0; - if (offs && !wrapfilt) + if ((offs != 0) & !wrapfilt) continue; copycolor(ctmp, pval); dx = norm*warr[i++];