--- ray/src/px/pinterp.c 2004/03/28 20:33:14 2.41 +++ ray/src/px/pinterp.c 2025/07/02 16:54:44 2.55 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: pinterp.c,v 2.41 2004/03/28 20:33:14 schorsch Exp $"; +static const char RCSid[] = "$Id: pinterp.c,v 2.55 2025/07/02 16:54:44 greg Exp $"; #endif /* * Interpolate and extrapolate pictures with different view parameters. @@ -28,7 +28,7 @@ static const char RCSid[] = "$Id: pinterp.c,v 2.41 200 #define averaging (ourweigh != NULL) #define blurring (ourbpict != NULL) #define usematrix (hasmatrix & !averaging) -#define zisnorm ((!usematrix) | (ourview.type != VT_PER)) +#define zisnorm (!usematrix | (ourview.type != VT_PER)) #define MAXWT 1000. /* maximum pixel weight (averaging) */ @@ -64,15 +64,13 @@ COLOR *ourbpict = NULL; /* blurred picture (view aver VIEW avgview; /* average view for -B option */ int nvavg; /* number of views averaged */ -char *progname; - int fillo = F_FORE|F_BACK; /* selected fill options */ int fillsamp = 0; /* sample separation (0 == inf) */ COLR backcolr = BLKCOLR; /* background color */ COLOR backcolor = BLKCOLOR; /* background color (float) */ double backz = 0.0; /* background z value */ int normdist = 1; /* i/o normalized distance? */ -char ourfmt[LPICFMT+1] = PICFMT; /* original picture format */ +char ourfmt[MAXFMTLEN] = PICFMT; /* original picture format */ double ourexp = -1; /* original picture exposure */ int expadj = 0; /* exposure adjustment (f-stops) */ double rexpadj = 1; /* real exposure adjustment */ @@ -134,8 +132,11 @@ main( /* interpolate pictures */ char *expcomp = NULL; int i, an, rval; - progname = argv[0]; + SET_DEFAULT_BINARY(); + SET_FILE_BINARY(stdout); + fixargv0(argv[0]); /* sets global progname */ + for (an = 1; an < argc && argv[an][0] == '-'; an++) { rval = getviewopt(&ourview, argc-an, argv+an); if (rval >= 0) { @@ -325,7 +326,7 @@ main( /* interpolate pictures */ fprintview(&avgview, stdout); putc('\n', stdout); } - if ((pixaspect < .99) | (pixaspect > 1.01)) + if ((pixaspect < .995) | (pixaspect > 1.005)) fputaspect(pixaspect, stdout); if (ourexp > 0) ourexp *= rexpadj; @@ -358,7 +359,7 @@ headline( /* process header string */ void *p ) { - char fmt[32]; + char fmt[MAXFMTLEN]; if (isheadid(s)) return(0); @@ -391,7 +392,7 @@ nextview( /* get and set next view */ { char linebuf[256]; char *err; - register int i; + int i; if (fp != NULL) { do /* get new view */ @@ -414,6 +415,7 @@ nextview( /* get and set next view */ avgview.vdir[i] += ourview.vdir[i]; avgview.vup[i] += ourview.vup[i]; } + avgview.vdist += ourview.vdist; avgview.horiz += ourview.horiz; avgview.vert += ourview.vert; avgview.hoff += ourview.hoff; @@ -427,7 +429,7 @@ nextview( /* get and set next view */ static void compavgview(void) /* compute average view */ { - register int i; + int i; double f; if (nvavg < 2) @@ -438,6 +440,7 @@ compavgview(void) /* compute average view */ avgview.vdir[i] *= f; avgview.vup[i] *= f; } + avgview.vdist *= f; avgview.horiz *= f; avgview.vert *= f; avgview.hoff *= f; @@ -492,14 +495,19 @@ addpicture( /* add picture to output */ zin = (float *)malloc(scanlen(&tresolu)*sizeof(float)); if (zin == NULL) syserror(progname); - if ((zfd = open(zspec, O_RDONLY)) == -1) { - double zvalue; - register int x; - if (!isflt(zspec) || (zvalue = atof(zspec)) <= 0.0) - syserror(zspec); + if (isflt(zspec)) { /* depth is a constant? */ + double zvalue = atof(zspec); + int x; + if (zvalue <= 0.0) { + fprintf(stderr, "%s: illegal Z-value %s\n", + progname, zspec); + exit(1); + } for (x = scanlen(&tresolu); x-- > 0; ) zin[x] = zvalue; - } + zfd = -1; + } else if ((zfd = open_float_depth(zspec, (long)tresolu.xr*tresolu.yr)) < 0) + exit(1); /* compute transferrable perimeter */ xlim = (struct bound *)malloc(numscans(&tresolu)*sizeof(struct bound)); if (xlim == NULL) @@ -553,12 +561,12 @@ addpicture( /* add picture to output */ static int pixform( /* compute view1 to view2 matrix */ - register MAT4 xfmat, - register VIEW *vw1, - register VIEW *vw2 + MAT4 xfmat, + VIEW *vw1, + VIEW *vw2 ) { - double m4t[4][4]; + MAT4 m4t; if ((vw1->type != VT_PER) & (vw1->type != VT_PAR)) return(0); @@ -607,7 +615,7 @@ addscanline( /* add scanline to output */ FVECT pos; struct position lastx, newpos; double wt; - register int x; + int x; lastx.z = 0; for (x = xl->max; x >= xl->min; x--) { @@ -645,7 +653,7 @@ addpixel( /* fill in pixel parallelogram */ int l1, l2, c1, c2; /* side lengths and counters */ int p1isy; /* p0p1 along y? */ int x1, y1; /* p1 position */ - register int x, y; /* final position */ + int x, y; /* final position */ /* compute vector p0p1 */ if (fillo&F_FORE && ABS(p1->z-p0->z) <= zt) { @@ -712,7 +720,7 @@ addpixel( /* fill in pixel parallelogram */ static double movepixel( /* reposition image point */ - register FVECT pos + FVECT pos ) { FVECT pt, tdir, odir; @@ -743,22 +751,21 @@ movepixel( /* reposition image point */ } pos[0] += .5 - ourview.hoff; pos[1] += .5 - ourview.voff; + if ((pos[0] < 0) | (pos[0] >= 1-FTINY) | + (pos[1] < 0) | (pos[1] >= 1-FTINY)) + return(0); pos[2] -= ourview.vfore; } else { if (viewray(pt, tdir, &theirview, pos[0], pos[1]) < -FTINY) return(0); - if ((!normdist) & (theirview.type == VT_PER)) /* adjust */ - pos[2] *= sqrt(1. + pos[0]*pos[0]*theirview.hn2 - + pos[1]*pos[1]*theirview.vn2); + if (!normdist & (theirview.type == VT_PER)) /* adjust */ + pos[2] /= DOT(theirview.vdir, tdir); pt[0] += tdir[0]*pos[2]; pt[1] += tdir[1]*pos[2]; pt[2] += tdir[2]*pos[2]; - viewloc(pos, &ourview, pt); - if (pos[2] <= 0) + if (viewloc(pos, &ourview, pt) != VL_GOOD) return(0); } - if ((pos[0] < 0) | (pos[0] >= 1-FTINY) | (pos[1] < 0) | (pos[1] >= 1-FTINY)) - return(0); if (!averaging) return(1); /* compute pixel weight */ @@ -778,7 +785,7 @@ movepixel( /* reposition image point */ static int getperim( /* compute overlapping image area */ - register struct bound *xl, + struct bound *xl, struct bound *yl, float *zline, int zfd @@ -786,7 +793,7 @@ getperim( /* compute overlapping image area */ { int step; FVECT pos; - register int x, y; + int x, y; /* set up step size */ if (scanlen(&tresolu) < numscans(&tresolu)) step = scanlen(&tresolu)/NSTEPS; @@ -870,7 +877,7 @@ backpicture( /* background fill algorithm */ { int *yback, xback; int y; - register int x, i; + int x, i; /* get back buffer */ yback = (int *)malloc(hresolu*sizeof(int)); if (yback == NULL) @@ -977,7 +984,7 @@ fillpicture( /* paint in empty pixels using fill */ fillfunc_t *fill ) { - register int x, y; + int x, y; for (y = 0; y < vresolu; y++) for (x = 0; x < hresolu; x++) @@ -991,7 +998,7 @@ fillpicture( /* paint in empty pixels using fill */ static int clipaft(void) /* perform aft clipping as indicated */ { - register int x, y; + int x, y; int adjtest = (ourview.type == VT_PER) & zisnorm; double tstdist; double yzn2, vx; @@ -1030,7 +1037,7 @@ addblur(void) /* add to blurred picture */ { COLOR cval; double d; - register int i; + int i; if (!blurring) return(0); @@ -1070,7 +1077,7 @@ static void writepicture(void) /* write out picture (alters buffer) */ { int y; - register int x; + int x; double d; fprtresolu(hresolu, vresolu, stdout); @@ -1113,7 +1120,7 @@ writedistance( /* write out z file (alters buffer) * for (y = vresolu-1; y >= 0; y--) { if (donorm) { double vx, yzn2, d; - register int x; + int x; yzn2 = (y+.5)/vresolu + ourview.voff - .5; yzn2 = 1. + yzn2*yzn2*ourview.vn2; for (x = 0; x < hresolu; x++) { @@ -1157,9 +1164,9 @@ calstart( /* start fill calculation char combuf[512]; char *argv[64]; int rval; - register char **wp, *cp; + char **wp, *cp; - if (PDesc.running) { + if (PDesc.flags & PF_RUNNING) { fprintf(stderr, "%s: too many calculations\n", progname); exit(1); } @@ -1194,7 +1201,7 @@ calstart( /* start fill calculation static void caldone(void) /* done with calculation */ { - if (!PDesc.running) + if (!(PDesc.flags & PF_RUNNING)) return; clearqueue(); close_process(&PDesc); @@ -1221,8 +1228,8 @@ clearqueue(void) /* process queue */ { FVECT orig, dir; float fbuf[6*(PACKSIZ+1)]; - register float *fbp; - register int i; + float *fbp; + int i; double vx, vy; if (queuesiz == 0) @@ -1237,7 +1244,7 @@ clearqueue(void) /* process queue */ } /* mark end and get results */ memset((char *)fbp, '\0', 6*sizeof(float)); - if (process(&PDesc, (char *)fbuf, (char *)fbuf, + if (process(&PDesc, fbuf, fbuf, 4*sizeof(float)*(queuesiz+1), 6*sizeof(float)*(queuesiz+1)) != 4*sizeof(float)*(queuesiz+1)) {