--- ray/src/px/pinterp.c 1995/10/16 11:40:16 2.27 +++ ray/src/px/pinterp.c 2003/07/27 22:12:03 2.37 @@ -1,25 +1,22 @@ -/* Copyright (c) 1995 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: pinterp.c,v 2.37 2003/07/27 22:12:03 schorsch Exp $"; #endif - /* * Interpolate and extrapolate pictures with different view parameters. * * Greg Ward 09Dec89 */ -#include "standard.h" +#include "copyright.h" #include +#include +#include "standard.h" +#include "rtprocess.h" /* Windows: must come before color.h */ #include "view.h" - #include "color.h" -#include "resolu.h" - #define LOG2 0.69314718055994530942 #define pscan(y) (ourpict+(y)*hresolu) @@ -30,7 +27,7 @@ static char SCCSid[] = "$SunId$ LBL"; #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) */ @@ -39,7 +36,7 @@ static char SCCSid[] = "$SunId$ LBL"; #define PACKSIZ 256 /* max. calculation packet size */ -#define RTCOM "rtrace -h- -ovl -fff " +#define RTCOM "rtrace -h- -ovl -fff -ld- -i- -I- " #define ABS(x) ((x)>0?(x):-(x)) @@ -89,8 +86,7 @@ double theirexp; /* input picture exposure */ MAT4 theirs2ours; /* transformation matrix */ int hasmatrix = 0; /* has transformation matrix */ -int PDesc[3] = {-1,-1,-1}; /* rtrace process descriptor */ -#define childpid (PDesc[2]) +static SUBPROC PDesc = SP_INACTIVE; /* rtrace process descriptor */ unsigned short queue[PACKSIZ][2]; /* pending pixels */ int packsiz; /* actual packet size */ int queuesiz = 0; /* number of pixels pending */ @@ -213,7 +209,7 @@ char *argv[]; if (argv[an][2] != 'f') goto badopt; check(3,"s"); - gotvfile = viewfile(argv[++an], &ourview, 0, 0); + gotvfile = viewfile(argv[++an], &ourview, NULL); if (gotvfile < 0) syserror(argv[an]); else if (gotvfile == 0) { @@ -236,8 +232,8 @@ char *argv[]; fillo &= ~F_BACK; if (doavg < 0) doavg = (argc-an) > 2; - if (expcomp != NULL) - if (expcomp[0] == '+' | expcomp[0] == '-') { + if (expcomp != NULL) { + if ((expcomp[0] == '+') | (expcomp[0] == '-')) { expadj = atof(expcomp) + (expcomp[0]=='+' ? .5 : -.5); if (doavg | doblur) rexpadj = pow(2.0, atof(expcomp)); @@ -251,8 +247,9 @@ char *argv[]; if (!(doavg | doblur)) rexpadj = pow(2.0, (double)expadj); } + } /* set view */ - if (nextview(doblur ? stdin : NULL) == EOF) { + if (nextview(doblur ? stdin : (FILE *)NULL) == EOF) { fprintf(stderr, "%s: no view on standard input!\n", progname); exit(1); @@ -262,7 +259,7 @@ char *argv[]; if (doavg) { ourspict = (COLOR *)bmalloc(hresolu*vresolu*sizeof(COLOR)); ourweigh = (float *)bmalloc(hresolu*vresolu*sizeof(float)); - if (ourspict == NULL | ourweigh == NULL) + if ((ourspict == NULL) | (ourweigh == NULL)) syserror(progname); } else { ourpict = (COLR *)bmalloc(hresolu*vresolu*sizeof(COLR)); @@ -279,9 +276,10 @@ char *argv[]; syserror(progname); /* new header */ newheader("RADIANCE", stdout); + fputnow(stdout); /* run pictures */ do { - bzero((char *)ourzbuf, hresolu*vresolu*sizeof(float)); + memset((char *)ourzbuf, '\0', hresolu*vresolu*sizeof(float)); for (i = an; i < argc; i += 2) addpicture(argv[i], argv[i+1]); if (fillo&F_BACK) /* fill in spaces */ @@ -301,13 +299,13 @@ char *argv[]; fprintview(&avgview, stdout); putc('\n', stdout); } - if (pixaspect < .99 | pixaspect > 1.01) + if ((pixaspect < .99) | (pixaspect > 1.01)) fputaspect(pixaspect, stdout); if (ourexp > 0) ourexp *= rexpadj; else ourexp = rexpadj; - if (ourexp < .995 | ourexp > 1.005) + if ((ourexp < .995) | (ourexp > 1.005)) fputexpos(ourexp, stdout); if (strcmp(ourfmt, PICFMT)) /* print format if known */ fputformat(ourfmt, stdout); @@ -328,20 +326,21 @@ userr: } +int headline(s) /* process header string */ char *s; { char fmt[32]; if (isheadid(s)) - return; + return(0); if (formatval(fmt, s)) { if (globmatch(ourfmt, fmt)) { wrongformat = 0; strcpy(ourfmt, fmt); } else wrongformat = 1; - return; + return(0); } if (nvavg < 2) { putc('\t', stdout); @@ -349,10 +348,11 @@ char *s; } if (isexpos(s)) { theirexp *= exposval(s); - return; + return(0); } if (isview(s) && sscanview(&theirview, s) > 0) gotview++; + return(0); } @@ -375,7 +375,7 @@ FILE *fp; exit(1); } if (!nvavg) { /* first view */ - copystruct(&avgview, &ourview); + avgview = ourview; return(nvavg++); } /* add to average view */ @@ -414,7 +414,7 @@ compavgview() /* compute average view */ avgview.vfore *= f; avgview.vaft *= f; if (setview(&avgview) != NULL) /* in case of emergency... */ - copystruct(&avgview, &ourview); + avgview = ourview; pixaspect = viewaspect(&avgview) * hresolu / vresolu; } @@ -435,7 +435,7 @@ char *pfile, *zspec; syserror(pfile); /* get header with exposure and view */ theirexp = 1.0; - copystruct(&theirview, &stdview); + theirview = stdview; gotview = 0; if (nvavg < 2) printf("%s:\n", pfile); @@ -448,7 +448,7 @@ char *pfile, *zspec; ourexp = theirexp; else if (ABS(theirexp-ourexp) > .01*ourexp) fprintf(stderr, "%s: different exposure (warning)\n", pfile); - if (err = setview(&theirview)) { + if ( (err = setview(&theirview)) ) { fprintf(stderr, "%s: %s\n", pfile, err); exit(1); } @@ -471,8 +471,8 @@ char *pfile, *zspec; if (xlim == NULL) syserror(progname); if (!getperim(xlim, &ylim, zin, zfd)) { /* overlapping area? */ - free((char *)zin); - free((char *)xlim); + free((void *)zin); + free((void *)xlim); if (zfd != -1) close(zfd); fclose(pfp); @@ -482,7 +482,7 @@ char *pfile, *zspec; scanin = (COLR *)malloc(scanlen(&tresolu)*sizeof(COLR)); plast = (struct position *)calloc(scanlen(&tresolu), sizeof(struct position)); - if (scanin == NULL | plast == NULL) + if ((scanin == NULL) | (plast == NULL)) syserror(progname); /* skip to starting point */ for (y = 0; y < ylim.min; y++) @@ -491,7 +491,7 @@ char *pfile, *zspec; exit(1); } if (zfd != -1 && lseek(zfd, - (long)ylim.min*scanlen(&tresolu)*sizeof(float), 0) < 0) + (off_t)ylim.min*scanlen(&tresolu)*sizeof(float), 0) < 0) syserror(zspec); /* load image */ for (y = ylim.min; y <= ylim.max; y++) { @@ -506,10 +506,10 @@ char *pfile, *zspec; addscanline(xlim+y, y, scanin, zin, plast); } /* clean up */ - free((char *)xlim); - free((char *)scanin); - free((char *)zin); - free((char *)plast); + free((void *)xlim); + free((void *)scanin); + free((void *)zin); + free((void *)plast); fclose(pfp); if (zfd != -1) close(zfd); @@ -522,9 +522,9 @@ register VIEW *vw1, *vw2; { double m4t[4][4]; - if (vw1->type != VT_PER & vw1->type != VT_PAR) + if ((vw1->type != VT_PER) & (vw1->type != VT_PAR)) return(0); - if (vw2->type != VT_PER & vw2->type != VT_PAR) + if ((vw2->type != VT_PER) & (vw2->type != VT_PAR)) return(0); setident4(xfmat); xfmat[0][0] = vw1->hvec[0]; @@ -608,7 +608,7 @@ double z; s1x = p1->x - p0->x; s1y = p1->y - p0->y; l1 = ABS(s1x); - if (p1isy = (ABS(s1y) > l1)) + if ( (p1isy = (ABS(s1y) > l1)) ) l1 = ABS(s1y); else if (l1 < 1) l1 = 1; @@ -641,10 +641,10 @@ double z; y1 = p0->y + c1*s1y/l1; for (c2 = l2; c2-- > 0; ) { x = x1 + c2*s2x/l2; - if (x < 0 | x >= hresolu) + if ((x < 0) | (x >= hresolu)) continue; y = y1 + c2*s2y/l2; - if (y < 0 | y >= vresolu) + if ((y < 0) | (y >= vresolu)) continue; if (averaging) { if (zscan(y)[x] <= 0 || zscan(y)[x]-z @@ -672,14 +672,13 @@ register FVECT pos; { FVECT pt, tdir, odir; double d; - register int i; if (pos[2] <= 0) /* empty pixel */ return(0); if (usematrix) { pos[0] += theirview.hoff - .5; pos[1] += theirview.voff - .5; - if (normdist & theirview.type == VT_PER) + if (normdist & (theirview.type == VT_PER)) d = sqrt(1. + pos[0]*pos[0]*theirview.hn2 + pos[1]*pos[1]*theirview.vn2); else @@ -703,7 +702,7 @@ register FVECT pos; } else { if (viewray(pt, tdir, &theirview, pos[0], pos[1]) < -FTINY) return(0); - if (!normdist & theirview.type == VT_PER) /* adjust */ + if ((!normdist) & (theirview.type == VT_PER)) /* adjust */ pos[2] *= sqrt(1. + pos[0]*pos[0]*theirview.hn2 + pos[1]*pos[1]*theirview.vn2); pt[0] += tdir[0]*pos[2]; @@ -713,19 +712,22 @@ register FVECT pos; if (pos[2] <= 0) return(0); } - if (pos[0] < 0 | pos[0] >= 1-FTINY | pos[1] < 0 | pos[1] >= 1-FTINY) + if ((pos[0] < 0) | (pos[0] >= 1-FTINY) | (pos[1] < 0) | (pos[1] >= 1-FTINY)) return(0); if (!averaging) return(1); - if (ourview.type == VT_PAR) /* compute our direction */ - VCOPY(odir, ourview.vdir); - else - for (i = 0; i < 3; i++) - odir[i] = (pt[i] - ourview.vp[i])/pos[2]; - d = DOT(odir,tdir); /* compute pixel weight */ - if (d >= 1.-1./MAXWT/MAXWT) + /* compute pixel weight */ + if (ourview.type == VT_PAR) { + d = DOT(ourview.vdir,tdir); + d = 1. - d*d; + } else { + VSUB(odir, pt, ourview.vp); + d = DOT(odir,tdir); + d = 1. - d*d/DOT(odir,odir); + } + if (d <= 1./MAXWT/MAXWT) return(MAXWT); /* clip to maximum weight */ - return(1./sqrt(1.-d)); + return(1./sqrt(d)); } @@ -756,7 +758,7 @@ int zfd; yl->min = 32000; yl->max = 0; /* search for points on image */ for (y = step - 1; y < numscans(&tresolu); y += step) { if (zfd != -1) { - if (lseek(zfd, (long)y*scanlen(&tresolu)*sizeof(float), + if (lseek(zfd, (off_t)y*scanlen(&tresolu)*sizeof(float), 0) < 0) syserror("lseek"); if (read(zfd, (char *)zline, @@ -802,13 +804,13 @@ int zfd; xl[y-1].max = xl[y-step].max; } for (x = 2; x < step; x++) - copystruct(xl+y-x, xl+y-1); + *(xl+y-x) = *(xl+y-1); } if (yl->max >= numscans(&tresolu)) yl->max = numscans(&tresolu) - 1; y -= step; for (x = numscans(&tresolu) - 1; x > y; x--) /* fill bottom rows */ - copystruct(xl+x, xl+y); + *(xl+x) = *(xl+y); return(yl->max >= yl->min); } @@ -917,7 +919,7 @@ int samp; xback = -2; } } - free((char *)yback); + free((void *)yback); } @@ -938,7 +940,7 @@ int (*fill)(); clipaft() /* perform aft clipping as indicated */ { register int x, y; - int adjtest = ourview.type == VT_PER & zisnorm; + int adjtest = (ourview.type == VT_PER) & zisnorm; double tstdist; double yzn2, vx; @@ -961,9 +963,9 @@ clipaft() /* perform aft clipping as indicated */ continue; } if (averaging) - bzero(sscan(y)[x], sizeof(COLOR)); + memset(sscan(y)[x], '\0', sizeof(COLOR)); else - bzero(pscan(y)[x], sizeof(COLR)); + memset(pscan(y)[x], '\0', sizeof(COLR)); zscan(y)[x] = 0.0; } } @@ -1046,7 +1048,7 @@ writedistance(fname) /* write out z file (alters buf char *fname; { int donorm = normdist & !zisnorm ? 1 : - ourview.type == VT_PER & !normdist & zisnorm ? -1 : 0; + (ourview.type == VT_PER) & !normdist & zisnorm ? -1 : 0; int fd; int y; @@ -1095,7 +1097,7 @@ char *prog, *args; int rval; register char **wp, *cp; - if (childpid != -1) { + if (PDesc.running) { fprintf(stderr, "%s: too many calculations\n", progname); exit(1); } @@ -1114,7 +1116,7 @@ char *prog, *args; } *wp = NULL; /* start process */ - if ((rval = open_process(PDesc, argv)) < 0) + if ((rval = open_process(&PDesc, argv)) < 0) syserror(progname); if (rval == 0) { fprintf(stderr, "%s: command not found\n", argv[0]); @@ -1129,11 +1131,10 @@ char *prog, *args; caldone() /* done with calculation */ { - if (childpid == -1) + if (!PDesc.running) return; clearqueue(); - close_process(PDesc); - childpid = -1; + close_process(&PDesc); } @@ -1168,10 +1169,11 @@ clearqueue() /* process queue */ *fbp++ = dir[0]; *fbp++ = dir[1]; *fbp++ = dir[2]; } /* mark end and get results */ - bzero((char *)fbp, 6*sizeof(float)); - if (process(PDesc, fbuf, fbuf, 4*sizeof(float)*queuesiz, + memset((char *)fbp, '\0', 6*sizeof(float)); + if (process(&PDesc, (char *)fbuf, (char *)fbuf, + 4*sizeof(float)*(queuesiz+1), 6*sizeof(float)*(queuesiz+1)) != - 4*sizeof(float)*queuesiz) { + 4*sizeof(float)*(queuesiz+1)) { fprintf(stderr, "%s: error reading from rtrace process\n", progname); exit(1);