--- ray/src/px/pinterp.c 1990/03/06 11:14:36 1.25 +++ ray/src/px/pinterp.c 1990/09/04 21:16:25 1.29 @@ -16,8 +16,6 @@ static char SCCSid[] = "$SunId$ LBL"; #include "color.h" -#include "random.h" - #ifndef BSD #define vfork fork #endif @@ -25,10 +23,6 @@ static char SCCSid[] = "$SunId$ LBL"; #define pscan(y) (ourpict+(y)*hresolu) #define zscan(y) (ourzbuf+(y)*hresolu) -#define PMASK 0xfffffff /* probability mask */ -#define sampval(x) (long)((x)*(PMASK+1)+.5) -#define samp(p) ((p) > (random()&PMASK)) - #define F_FORE 1 /* fill foreground */ #define F_BACK 2 /* fill background */ @@ -53,7 +47,7 @@ float *ourzbuf; /* corresponding z-buffer */ char *progname; int fillo = F_FORE|F_BACK; /* selected fill options */ -long sampprob = 0; /* sample probability */ +int fillsamp = 0; /* sample separation (0 == inf) */ extern int backfill(), rcalfill(); /* fill functions */ int (*fillfunc)() = backfill; /* selected fill function */ COLR backcolr = BLKCOLR; /* background color */ @@ -121,7 +115,7 @@ char *argv[]; break; case 's': /* sample */ check(3,1); - sampprob = sampval(atof(argv[++i])); + fillsamp = atoi(argv[++i]); break; case 'c': /* color */ check(3,3); @@ -200,7 +194,7 @@ char *argv[]; addpicture(argv[i], argv[i+1]); /* fill in spaces */ if (fillo&F_BACK) - backpicture(fillfunc, sampprob); + backpicture(fillfunc, fillsamp); else fillpicture(fillfunc); /* close calculation */ @@ -460,7 +454,11 @@ double z; y1 = p0->y + c1*s1y/l1; for (c2 = l2; c2-- > 0; ) { x = x1 + c2*s2x/l2; + if (x < 0 || x >= hresolu) + continue; y = y1 + c2*s2y/l2; + if (y < 0 || y >= vresolu) + continue; if (zscan(y)[x] <= 0 || zscan(y)[x]-z > zeps*zscan(y)[x]) { zscan(y)[x] = z; @@ -471,9 +469,9 @@ double z; } -backpicture(fill, prob) /* background fill algorithm */ +backpicture(fill, samp) /* background fill algorithm */ int (*fill)(); -long prob; +int samp; { int *yback, xback; int y; @@ -524,29 +522,40 @@ long prob; xback = x-1; } /* - * Check to see if we have no background for - * this pixel. If not, or sampling was - * requested, use the given fill function. + * If we have no background for this pixel, + * use the given fill function. */ - if ((xback < 0 && yback[x] < 0) || samp(prob)) { - (*fill)(x,y); - continue; - } + if (xback < 0 && yback[x] < 0) + goto fillit; /* * Compare, and use the background that is * farther, unless one of them is next to us. + * If the background is too distant, call + * the fill function. */ if ( yback[x] < 0 || (xback >= 0 && ABS(x-xback) <= 1) || ( ABS(y-yback[x]) > 1 && zscan(yback[x])[x] < zscan(y)[xback] ) ) { + if (samp > 0 && ABS(x-xback) >= samp) + goto fillit; copycolr(pscan(y)[x],pscan(y)[xback]); zscan(y)[x] = zscan(y)[xback]; } else { + if (samp > 0 && ABS(y-yback[x]) > samp) + goto fillit; copycolr(pscan(y)[x],pscan(yback[x])[x]); zscan(y)[x] = zscan(yback[x])[x]; } + continue; + fillit: + (*fill)(x,y); + if (fill == rcalfill) { /* use it */ + clearqueue(); + xback = x; + yback[x] = y; + } } else { /* full pixel */ yback[x] = -2; xback = -2; @@ -599,10 +608,10 @@ char *fname; if (donorm) { double vx, yzn2; register int x; - yzn2 = y - .5*(vresolu-1); + yzn2 = (y+.5)/vresolu + ourview.voff - .5; yzn2 = 1. + yzn2*yzn2*ourview.vn2; for (x = 0; x < hresolu; x++) { - vx = x - .5*(hresolu-1); + vx = (x+.5)/hresolu + ourview.hoff - .5; zout[x] = zscan(y)[x] * sqrt(vx*vx*ourview.hn2 + yzn2); }