--- ray/src/px/pf3.c 1989/02/02 10:49:26 1.1 +++ ray/src/px/pf3.c 1992/11/12 11:35:55 2.4 @@ -1,4 +1,4 @@ -/* Copyright (c) 1986 Regents of the University of California */ +/* Copyright (c) 1992 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -12,9 +12,11 @@ static char SCCSid[] = "$SunId$ LBL"; #include +#include + #include "color.h" -#define FTINY 1e-7 +#define FTINY 1e-7 extern double rad; /* output pixel radius for filtering */ @@ -38,13 +40,12 @@ extern char *progname; float *exptable; /* exponent table */ -#define lookexp(x) exptable[(int)(-10.*(x)+.5)] +#define lookexp(x) exptable[(int)(-10.*(x)+.5)] initmask() /* initialize gaussian lookup table */ { extern char *malloc(); - extern double exp(); register int x; exptable = (float *)malloc(100*sizeof(float)); @@ -66,21 +67,21 @@ int c, r; static double d; static int y; register int x; - register COLOR *scan; + register COLOR *scan; wsum = 0; setcolor(csum, 0.0, 0.0, 0.0); for (y = ycent+1-yrad; y <= ycent+yrad; y++) { - if (y < 0 || y >= yres) - continue; - d = y_r < 1.0 ? y_r*y - r : y - ycent; + if (y < 0) continue; + if (y >= yres) break; + d = y_r < 1.0 ? y_r*y - r : (double)(y - ycent); if (d > 0.5+FTINY || d < -0.5-FTINY) continue; scan = scanin[y%barsize]; for (x = xcent+1-xrad; x <= xcent+xrad; x++) { - if (x < 0 || x >= xres) - continue; - d = x_c < 1.0 ? x_c*x - c : x - xcent; + if (x < 0) continue; + if (x >= xres) break; + d = x_c < 1.0 ? x_c*x - c : (double)(x - xcent); if (d > 0.5+FTINY || d < -0.5-FTINY) continue; wsum++; @@ -101,19 +102,19 @@ int c, r; static COLOR ctmp; static int y; register int x; - register COLOR *scan; + register COLOR *scan; wsum = FTINY; setcolor(csum, 0.0, 0.0, 0.0); - for (y = ycent+1-yrad; y <= ycent+yrad; y++) { - if (y < 0 || y >= yres) - continue; - dy = (y_r*y - r)/rad; + for (y = ycent-yrad; y <= ycent+yrad; y++) { + if (y < 0) continue; + if (y >= yres) break; + dy = (y_r*(y+.5) - (r+.5))/rad; scan = scanin[y%barsize]; - for (x = xcent+1-xrad; x <= xcent+xrad; x++) { - if (x < 0 || x >= xres) - continue; - dx = (x_c*x - c)/rad; + for (x = xcent-xrad; x <= xcent+xrad; x++) { + if (x < 0) continue; + if (x >= xres) break; + dx = (x_c*(x+.5) - (c+.5))/rad; weight = lookexp(-(dx*dx + dy*dy)); wsum += weight; copycolor(ctmp, scan[x]);