--- ray/src/px/pinterp.c 1995/09/14 13:40:17 2.24 +++ ray/src/px/pinterp.c 2003/06/26 00:58:10 2.34 @@ -1,25 +1,21 @@ -/* 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.34 2003/06/26 00:58:10 schorsch Exp $"; #endif - /* * Interpolate and extrapolate pictures with different view parameters. * * Greg Ward 09Dec89 */ -#include "standard.h" +#include "copyright.h" #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) @@ -39,7 +35,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)) @@ -61,7 +57,7 @@ COLR *ourpict; /* output picture (COLR's) */ COLOR *ourspict; /* output pixel sums (averaging) */ float *ourweigh = NULL; /* output pixel weights (averaging) */ float *ourzbuf; /* corresponding z-buffer */ -COLOR *ourbpict = NULL; /* blurred picture */ +COLOR *ourbpict = NULL; /* blurred picture (view averaging) */ VIEW avgview; /* average view for -B option */ int nvavg; /* number of views averaged */ @@ -76,6 +72,7 @@ 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 */ double ourexp = -1; /* original picture exposure */ int expadj = 0; /* exposure adjustment (f-stops) */ double rexpadj = 1; /* real exposure adjustment */ @@ -88,11 +85,10 @@ 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; /* number of pixels pending */ +int queuesiz = 0; /* number of pixels pending */ extern double movepixel(); @@ -212,7 +208,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) { @@ -251,7 +247,7 @@ char *argv[]; 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); @@ -278,6 +274,7 @@ char *argv[]; syserror(progname); /* new header */ newheader("RADIANCE", stdout); + fputnow(stdout); /* run pictures */ do { bzero((char *)ourzbuf, hresolu*vresolu*sizeof(float)); @@ -308,7 +305,8 @@ char *argv[]; ourexp = rexpadj; if (ourexp < .995 | ourexp > 1.005) fputexpos(ourexp, stdout); - fputformat(COLRFMT, stdout); + if (strcmp(ourfmt, PICFMT)) /* print format if known */ + fputformat(ourfmt, stdout); putc('\n', stdout); /* write picture */ writepicture(); @@ -326,16 +324,21 @@ userr: } +int headline(s) /* process header string */ char *s; { char fmt[32]; if (isheadid(s)) - return; + return(0); if (formatval(fmt, s)) { - wrongformat = strcmp(fmt, COLRFMT); - return; + if (globmatch(ourfmt, fmt)) { + wrongformat = 0; + strcpy(ourfmt, fmt); + } else + wrongformat = 1; + return(0); } if (nvavg < 2) { putc('\t', stdout); @@ -343,10 +346,11 @@ char *s; } if (isexpos(s)) { theirexp *= exposval(s); - return; + return(0); } if (isview(s) && sscanview(&theirview, s) > 0) gotview++; + return(0); } @@ -465,8 +469,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); @@ -485,7 +489,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++) { @@ -500,10 +504,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); @@ -516,9 +520,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]; @@ -635,10 +639,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 @@ -666,14 +670,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 @@ -707,19 +710,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)); } @@ -750,7 +756,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, @@ -911,7 +917,7 @@ int samp; xback = -2; } } - free((char *)yback); + free((void *)yback); } @@ -924,6 +930,8 @@ int (*fill)(); for (x = 0; x < hresolu; x++) if (zscan(y)[x] <= 0) (*fill)(x,y); + if (fill == rcalfill) + clearqueue(); } @@ -1087,7 +1095,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); } @@ -1106,7 +1114,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]); @@ -1121,11 +1129,10 @@ char *prog, *args; caldone() /* done with calculation */ { - if (childpid == -1) + if (!PDesc.running) return; clearqueue(); - close_process(PDesc); - childpid = -1; + close_process(&PDesc); } @@ -1161,9 +1168,10 @@ clearqueue() /* process queue */ } /* mark end and get results */ bzero((char *)fbp, 6*sizeof(float)); - if (process(PDesc, fbuf, fbuf, 4*sizeof(float)*queuesiz, + 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);