--- ray/src/px/pinterp.c 1995/10/16 11:40:16 2.27 +++ ray/src/px/pinterp.c 2003/07/21 22:30:18 2.36 @@ -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.36 2003/07/21 22:30:18 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) @@ -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,7 +232,7 @@ char *argv[]; fillo &= ~F_BACK; if (doavg < 0) doavg = (argc-an) > 2; - if (expcomp != NULL) + if (expcomp != NULL) { if (expcomp[0] == '+' | expcomp[0] == '-') { expadj = atof(expcomp) + (expcomp[0]=='+' ? .5 : -.5); if (doavg | doblur) @@ -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); @@ -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 */ @@ -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); @@ -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); @@ -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); @@ -672,7 +672,6 @@ register FVECT pos; { FVECT pt, tdir, odir; double d; - register int i; if (pos[2] <= 0) /* empty pixel */ return(0); @@ -717,15 +716,18 @@ register FVECT pos; 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); } @@ -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; } } @@ -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);