--- ray/src/px/pinterp.c 1999/07/16 16:11:31 2.32 +++ ray/src/px/pinterp.c 2003/10/20 16:01:55 2.38 @@ -1,25 +1,23 @@ -/* Copyright (c) 1999 Silicon Graphics, Inc. */ - #ifndef lint -static char SCCSid[] = "$SunId$ SGI"; +static const char RCSid[] = "$Id: pinterp.c,v 2.38 2003/10/20 16:01:55 greg 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 "platform.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 +28,7 @@ static char SCCSid[] = "$SunId$ SGI"; #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) */ @@ -89,8 +87,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 +210,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 +233,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,6 +248,7 @@ char *argv[]; if (!(doavg | doblur)) rexpadj = pow(2.0, (double)expadj); } + } /* set view */ if (nextview(doblur ? stdin : (FILE *)NULL) == EOF) { fprintf(stderr, "%s: no view on standard input!\n", @@ -262,7 +260,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 +277,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 +300,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); @@ -377,7 +376,7 @@ FILE *fp; exit(1); } if (!nvavg) { /* first view */ - copystruct(&avgview, &ourview); + avgview = ourview; return(nvavg++); } /* add to average view */ @@ -416,7 +415,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; } @@ -437,7 +436,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); @@ -450,7 +449,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); } @@ -473,8 +472,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); @@ -484,7 +483,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++) @@ -493,7 +492,8 @@ 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), + SEEK_SET) < 0) syserror(zspec); /* load image */ for (y = ylim.min; y <= ylim.max; y++) { @@ -508,10 +508,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); @@ -524,9 +524,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]; @@ -610,7 +610,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; @@ -643,10 +643,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 @@ -680,7 +680,7 @@ register FVECT pos; 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 @@ -704,7 +704,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]; @@ -714,7 +714,7 @@ 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); @@ -760,8 +760,8 @@ 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), - 0) < 0) + if (lseek(zfd, (off_t)y*scanlen(&tresolu)*sizeof(float), + SEEK_SET) < 0) syserror("lseek"); if (read(zfd, (char *)zline, scanlen(&tresolu)*sizeof(float)) @@ -806,13 +806,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); } @@ -921,7 +921,7 @@ int samp; xback = -2; } } - free((char *)yback); + free((void *)yback); } @@ -942,7 +942,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; @@ -965,9 +965,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; } } @@ -1050,7 +1050,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; @@ -1099,7 +1099,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); } @@ -1118,7 +1118,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]); @@ -1133,11 +1133,10 @@ char *prog, *args; caldone() /* done with calculation */ { - if (childpid == -1) + if (!PDesc.running) return; clearqueue(); - close_process(PDesc); - childpid = -1; + close_process(&PDesc); } @@ -1172,8 +1171,9 @@ 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+1), + 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+1)) { fprintf(stderr, "%s: error reading from rtrace process\n",