--- ray/src/px/pinterp.c 1994/12/23 22:35:12 2.19 +++ ray/src/px/pinterp.c 2003/02/22 02:07:27 2.33 @@ -1,9 +1,6 @@ -/* Copyright (c) 1994 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: pinterp.c,v 2.33 2003/02/22 02:07:27 greg Exp $"; #endif - /* * Interpolate and extrapolate pictures with different view parameters. * @@ -18,22 +15,26 @@ static char SCCSid[] = "$SunId$ LBL"; #include "color.h" -#include "resolu.h" +#define LOG2 0.69314718055994530942 #define pscan(y) (ourpict+(y)*hresolu) #define sscan(y) (ourspict+(y)*hresolu) #define wscan(y) (ourweigh+(y)*hresolu) #define zscan(y) (ourzbuf+(y)*hresolu) +#define bscan(y) (ourbpict+(y)*hresolu) #define averaging (ourweigh != NULL) +#define blurring (ourbpict != NULL) +#define usematrix (hasmatrix & !averaging) +#define zisnorm (!usematrix | ourview.type != VT_PER) -#define MAXWT 100. /* maximum pixel weight (averaging) */ +#define MAXWT 1000. /* maximum pixel weight (averaging) */ #define F_FORE 1 /* fill foreground */ #define F_BACK 2 /* fill background */ #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)) @@ -52,10 +53,14 @@ double pixaspect = 1.0; /* pixel aspect ratio */ double zeps = .02; /* allowed z epsilon */ COLR *ourpict; /* output picture (COLR's) */ -COLOR *ourspict; /* output pixel sums (-a option) */ -float *ourweigh = NULL; /* output pixel weights (-a option) */ +COLOR *ourspict; /* output pixel sums (averaging) */ +float *ourweigh = NULL; /* output pixel weights (averaging) */ float *ourzbuf; /* corresponding z-buffer */ +COLOR *ourbpict = NULL; /* blurred picture (view averaging) */ +VIEW avgview; /* average view for -B option */ +int nvavg; /* number of views averaged */ + char *progname; int fillo = F_FORE|F_BACK; /* selected fill options */ @@ -65,10 +70,13 @@ int (*fillfunc)() = backfill; /* selected fill functio COLR backcolr = BLKCOLR; /* background color */ COLOR backcolor = BLKCOLOR; /* background color (float) */ double backz = 0.0; /* background z value */ -int normdist = 1; /* normalized distance? */ -double ourexp = -1; /* output picture exposure */ +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 */ -VIEW theirview = STDVIEW; /* input view */ +VIEW theirview; /* input view */ int gotview; /* got input view? */ int wrongformat = 0; /* input in another format? */ RESOLU tresolu; /* input resolution */ @@ -80,7 +88,7 @@ int PDesc[3] = {-1,-1,-1}; /* rtrace process descript #define childpid (PDesc[2]) 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(); @@ -89,32 +97,41 @@ main(argc, argv) /* interpolate pictures */ int argc; char *argv[]; { -#define check(ol,al) if (argv[i][ol] || \ - badarg(argc-i-1,argv+i+1,al)) \ +#define check(ol,al) if (argv[an][ol] || \ + badarg(argc-an-1,argv+an+1,al)) \ goto badopt int gotvfile = 0; int doavg = -1; + int doblur = 0; char *zfile = NULL; - char *err; - int i, rval; + char *expcomp = NULL; + int i, an, rval; progname = argv[0]; - for (i = 1; i < argc && argv[i][0] == '-'; i++) { - rval = getviewopt(&ourview, argc-i, argv+i); + for (an = 1; an < argc && argv[an][0] == '-'; an++) { + rval = getviewopt(&ourview, argc-an, argv+an); if (rval >= 0) { - i += rval; + an += rval; continue; } - switch (argv[i][1]) { + switch (argv[an][1]) { + case 'e': /* exposure */ + check(2,"f"); + expcomp = argv[++an]; + break; case 't': /* threshold */ check(2,"f"); - zeps = atof(argv[++i]); + zeps = atof(argv[++an]); break; case 'a': /* average */ check(2,NULL); doavg = 1; break; + case 'B': /* blur views */ + check(2,NULL); + doblur = 1; + break; case 'q': /* quick (no avg.) */ check(2,NULL); doavg = 0; @@ -124,7 +141,7 @@ char *argv[]; normdist = !normdist; break; case 'f': /* fill type */ - switch (argv[i][2]) { + switch (argv[an][2]) { case '0': /* none */ check(3,NULL); fillo = 0; @@ -143,27 +160,27 @@ char *argv[]; break; case 's': /* sample */ check(3,"i"); - fillsamp = atoi(argv[++i]); + fillsamp = atoi(argv[++an]); break; case 'c': /* color */ check(3,"fff"); fillfunc = backfill; - setcolor(backcolor, atof(argv[i+1]), - atof(argv[i+2]), atof(argv[i+3])); + setcolor(backcolor, atof(argv[an+1]), + atof(argv[an+2]), atof(argv[an+3])); setcolr(backcolr, colval(backcolor,RED), colval(backcolor,GRN), colval(backcolor,BLU)); - i += 3; + an += 3; break; case 'z': /* z value */ check(3,"f"); fillfunc = backfill; - backz = atof(argv[++i]); + backz = atof(argv[++an]); break; case 'r': /* rtrace */ check(3,"s"); fillfunc = rcalfill; - calstart(RTCOM, argv[++i]); + calstart(RTCOM, argv[++an]); break; default: goto badopt; @@ -171,56 +188,72 @@ char *argv[]; break; case 'z': /* z file */ check(2,"s"); - zfile = argv[++i]; + zfile = argv[++an]; break; case 'x': /* x resolution */ check(2,"i"); - hresolu = atoi(argv[++i]); + hresolu = atoi(argv[++an]); break; case 'y': /* y resolution */ check(2,"i"); - vresolu = atoi(argv[++i]); + vresolu = atoi(argv[++an]); break; case 'p': /* pixel aspect */ - if (argv[i][2] != 'a') + if (argv[an][2] != 'a') goto badopt; check(3,"f"); - pixaspect = atof(argv[++i]); + pixaspect = atof(argv[++an]); break; case 'v': /* view file */ - if (argv[i][2] != 'f') + if (argv[an][2] != 'f') goto badopt; check(3,"s"); - gotvfile = viewfile(argv[++i], &ourview, 0, 0); + gotvfile = viewfile(argv[++an], &ourview, NULL); if (gotvfile < 0) - syserror(argv[i]); + syserror(argv[an]); else if (gotvfile == 0) { fprintf(stderr, "%s: bad view file\n", - argv[i]); + argv[an]); exit(1); } break; default: badopt: fprintf(stderr, "%s: command line error at '%s'\n", - progname, argv[i]); + progname, argv[an]); goto userr; } } /* check arguments */ - if ((argc-i)%2) + if ((argc-an)%2) goto userr; if (fillsamp == 1) fillo &= ~F_BACK; + if (doavg < 0) + doavg = (argc-an) > 2; + if (expcomp != NULL) + if (expcomp[0] == '+' | expcomp[0] == '-') { + expadj = atof(expcomp) + (expcomp[0]=='+' ? .5 : -.5); + if (doavg | doblur) + rexpadj = pow(2.0, atof(expcomp)); + else + rexpadj = pow(2.0, (double)expadj); + } else { + if (!isflt(expcomp)) + goto userr; + rexpadj = atof(expcomp); + expadj = log(rexpadj)/LOG2 + (rexpadj>1 ? .5 : -.5); + if (!(doavg | doblur)) + rexpadj = pow(2.0, (double)expadj); + } /* set view */ - if ((err = setview(&ourview)) != NULL) { - fprintf(stderr, "%s: %s\n", progname, err); + if (nextview(doblur ? stdin : (FILE *)NULL) == EOF) { + fprintf(stderr, "%s: no view on standard input!\n", + progname); exit(1); } normaspect(viewaspect(&ourview), &pixaspect, &hresolu, &vresolu); /* allocate frame */ - if (doavg < 0) - doavg = (argc-i) > 2; if (doavg) { ourspict = (COLOR *)bmalloc(hresolu*vresolu*sizeof(COLOR)); ourweigh = (float *)bmalloc(hresolu*vresolu*sizeof(float)); @@ -231,36 +264,49 @@ char *argv[]; if (ourpict == NULL) syserror(progname); } + if (doblur) { + ourbpict = (COLOR *)bmalloc(hresolu*vresolu*sizeof(COLOR)); + if (ourbpict == NULL) + syserror(progname); + } ourzbuf = (float *)bmalloc(hresolu*vresolu*sizeof(float)); if (ourzbuf == NULL) syserror(progname); - bzero((char *)ourzbuf, hresolu*vresolu*sizeof(float)); /* new header */ newheader("RADIANCE", stdout); - /* get input */ - for ( ; i < argc; i += 2) - addpicture(argv[i], argv[i+1]); - /* fill in spaces */ - if (fillo&F_BACK) - backpicture(fillfunc, fillsamp); - else - fillpicture(fillfunc); + fputnow(stdout); + /* run pictures */ + do { + bzero((char *)ourzbuf, hresolu*vresolu*sizeof(float)); + for (i = an; i < argc; i += 2) + addpicture(argv[i], argv[i+1]); + if (fillo&F_BACK) /* fill in spaces */ + backpicture(fillfunc, fillsamp); + else + fillpicture(fillfunc); + /* aft clipping */ + clipaft(); + } while (addblur() && nextview(stdin) != EOF); /* close calculation */ caldone(); - /* aft clipping */ - clipaft(); /* add to header */ printargs(argc, argv, stdout); - if (gotvfile) { + compavgview(); + if (doblur | gotvfile) { fputs(VIEWSTR, stdout); - fprintview(&ourview, stdout); + 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 < .995 || ourexp > 1.005)) + if (ourexp > 0) + ourexp *= rexpadj; + else + 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(); @@ -271,36 +317,106 @@ char *argv[]; exit(0); userr: fprintf(stderr, - "Usage: %s [view opts][-t eps][-z zout][-fT][-n] pfile zspec ..\n", + "Usage: %s [view opts][-t eps][-z zout][-e spec][-B][-a|-q][-fT][-n] pfile zspec ..\n", progname); exit(1); #undef check } +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); } - putc('\t', stdout); - fputs(s, stdout); - + if (nvavg < 2) { + putc('\t', stdout); + fputs(s, stdout); + } if (isexpos(s)) { theirexp *= exposval(s); - return; + return(0); } if (isview(s) && sscanview(&theirview, s) > 0) gotview++; + return(0); } +nextview(fp) /* get and set next view */ +FILE *fp; +{ + char linebuf[256]; + char *err; + register int i; + + if (fp != NULL) { + do /* get new view */ + if (fgets(linebuf, sizeof(linebuf), fp) == NULL) + return(EOF); + while (!isview(linebuf) || !sscanview(&ourview, linebuf)); + } + /* set new view */ + if ((err = setview(&ourview)) != NULL) { + fprintf(stderr, "%s: %s\n", progname, err); + exit(1); + } + if (!nvavg) { /* first view */ + copystruct(&avgview, &ourview); + return(nvavg++); + } + /* add to average view */ + for (i = 0; i < 3; i++) { + avgview.vp[i] += ourview.vp[i]; + avgview.vdir[i] += ourview.vdir[i]; + avgview.vup[i] += ourview.vup[i]; + } + avgview.horiz += ourview.horiz; + avgview.vert += ourview.vert; + avgview.hoff += ourview.hoff; + avgview.voff += ourview.voff; + avgview.vfore += ourview.vfore; + avgview.vaft += ourview.vaft; + return(nvavg++); +} + + +compavgview() /* compute average view */ +{ + register int i; + double f; + + if (nvavg < 2) + return; + f = 1.0/nvavg; + for (i = 0; i < 3; i++) { + avgview.vp[i] *= f; + avgview.vdir[i] *= f; + avgview.vup[i] *= f; + } + avgview.horiz *= f; + avgview.vert *= f; + avgview.hoff *= f; + avgview.voff *= f; + avgview.vfore *= f; + avgview.vaft *= f; + if (setview(&avgview) != NULL) /* in case of emergency... */ + copystruct(&avgview, &ourview); + pixaspect = viewaspect(&avgview) * hresolu / vresolu; +} + + addpicture(pfile, zspec) /* add picture to output */ char *pfile, *zspec; { @@ -317,8 +433,10 @@ char *pfile, *zspec; syserror(pfile); /* get header with exposure and view */ theirexp = 1.0; + copystruct(&theirview, &stdview); gotview = 0; - printf("%s:\n", pfile); + if (nvavg < 2) + printf("%s:\n", pfile); getheader(pfp, headline, NULL); if (wrongformat || !gotview || !fgetsresolu(&tresolu, pfp)) { fprintf(stderr, "%s: picture format error\n", pfile); @@ -351,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); @@ -371,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++) { @@ -386,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); @@ -402,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]; @@ -490,7 +608,7 @@ double z; l1 = ABS(s1x); if (p1isy = (ABS(s1y) > l1)) l1 = ABS(s1y); - if (l1 < 1) + else if (l1 < 1) l1 = 1; } else { l1 = s1x = s1y = 1; @@ -521,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 @@ -548,28 +666,29 @@ double z; double movepixel(pos) /* reposition image point */ -FVECT pos; +register FVECT pos; { - double d0, d1; FVECT pt, tdir, odir; - register int i; + double d; if (pos[2] <= 0) /* empty pixel */ return(0); - if (normdist && theirview.type == VT_PER) { /* adjust distance */ - d0 = pos[0] + theirview.hoff - .5; - d1 = pos[1] + theirview.voff - .5; - pos[2] /= sqrt(1. + d0*d0*theirview.hn2 + d1*d1*theirview.vn2); - } - if (!averaging && hasmatrix) { + if (usematrix) { pos[0] += theirview.hoff - .5; pos[1] += theirview.voff - .5; + if (normdist & theirview.type == VT_PER) + d = sqrt(1. + pos[0]*pos[0]*theirview.hn2 + + pos[1]*pos[1]*theirview.vn2); + else + d = 1.; + pos[2] += d*theirview.vfore; if (theirview.type == VT_PER) { + pos[2] /= d; pos[0] *= pos[2]; pos[1] *= pos[2]; } multp3(pos, pos, theirs2ours); - if (pos[2] <= 0) + if (pos[2] <= ourview.vfore) return(0); if (ourview.type == VT_PER) { pos[0] /= pos[2]; @@ -577,9 +696,13 @@ FVECT pos; } pos[0] += .5 - ourview.hoff; pos[1] += .5 - ourview.voff; + 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); pt[0] += tdir[0]*pos[2]; pt[1] += tdir[1]*pos[2]; pt[2] += tdir[2]*pos[2]; @@ -587,21 +710,22 @@ 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]; - d0 = DOT(odir,tdir); /* compute pixel weight */ - if (d0 <= FTINY) - return(0); /* relative angle >= 90 degrees */ - if (d0 >= 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.-d0)); + return(1./sqrt(d)); } @@ -632,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, @@ -682,6 +806,7 @@ int zfd; } 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); return(yl->max >= yl->min); @@ -792,7 +917,7 @@ int samp; xback = -2; } } - free((char *)yback); + free((void *)yback); } @@ -805,27 +930,30 @@ int (*fill)(); for (x = 0; x < hresolu; x++) if (zscan(y)[x] <= 0) (*fill)(x,y); + if (fill == rcalfill) + clearqueue(); } clipaft() /* perform aft clipping as indicated */ { register int x, y; + int adjtest = ourview.type == VT_PER & zisnorm; double tstdist; double yzn2, vx; if (ourview.vaft <= FTINY) - return; + return(0); tstdist = ourview.vaft - ourview.vfore; for (y = 0; y < vresolu; y++) { - if (ourview.type == VT_PER) { /* adjust distance */ + if (adjtest) { /* adjust test */ yzn2 = (y+.5)/vresolu + ourview.voff - .5; yzn2 = 1. + yzn2*yzn2*ourview.vn2; tstdist = (ourview.vaft - ourview.vfore)*sqrt(yzn2); } for (x = 0; x < hresolu; x++) if (zscan(y)[x] > tstdist) { - if (ourview.type == VT_PER) { + if (adjtest) { vx = (x+.5)/hresolu + ourview.hoff - .5; if (zscan(y)[x] <= (ourview.vaft - ourview.vfore) * @@ -839,61 +967,110 @@ clipaft() /* perform aft clipping as indicated */ zscan(y)[x] = 0.0; } } + return(1); } -writepicture() /* write out picture */ +addblur() /* add to blurred picture */ { + COLOR cval; + double d; + register int i; + + if (!blurring) + return(0); + i = hresolu*vresolu; + if (nvavg < 2) + if (averaging) + while (i--) { + copycolor(ourbpict[i], ourspict[i]); + d = 1.0/ourweigh[i]; + scalecolor(ourbpict[i], d); + } + else + while (i--) + colr_color(ourbpict[i], ourpict[i]); + else + if (averaging) + while (i--) { + copycolor(cval, ourspict[i]); + d = 1.0/ourweigh[i]; + scalecolor(cval, d); + addcolor(ourbpict[i], cval); + } + else + while (i--) { + colr_color(cval, ourpict[i]); + addcolor(ourbpict[i], cval); + } + /* print view */ + printf("VIEW%d:", nvavg); + fprintview(&ourview, stdout); + putchar('\n'); + return(1); +} + + +writepicture() /* write out picture (alters buffer) */ +{ int y; register int x; double d; fprtresolu(hresolu, vresolu, stdout); for (y = vresolu-1; y >= 0; y--) - if (averaging) { + if (blurring) { + for (x = 0; x < hresolu; x++) { /* compute avg. */ + d = rexpadj/nvavg; + scalecolor(bscan(y)[x], d); + } + if (fwritescan(bscan(y), hresolu, stdout) < 0) + syserror(progname); + } else if (averaging) { for (x = 0; x < hresolu; x++) { /* average pixels */ - d = 1./wscan(y)[x]; + d = rexpadj/wscan(y)[x]; scalecolor(sscan(y)[x], d); } if (fwritescan(sscan(y), hresolu, stdout) < 0) syserror(progname); - } else if (fwritecolrs(pscan(y), hresolu, stdout) < 0) - syserror(progname); + } else { + if (expadj) + shiftcolrs(pscan(y), hresolu, expadj); + if (fwritecolrs(pscan(y), hresolu, stdout) < 0) + syserror(progname); + } } -writedistance(fname) /* write out z file */ +writedistance(fname) /* write out z file (alters buffer) */ char *fname; { - int donorm = normdist && ourview.type == VT_PER; + int donorm = normdist & !zisnorm ? 1 : + ourview.type == VT_PER & !normdist & zisnorm ? -1 : 0; int fd; int y; - float *zout; if ((fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) syserror(fname); - if (donorm - && (zout = (float *)malloc(hresolu*sizeof(float))) == NULL) - syserror(progname); for (y = vresolu-1; y >= 0; y--) { if (donorm) { - double vx, yzn2; + double vx, yzn2, d; register int x; yzn2 = (y+.5)/vresolu + ourview.voff - .5; yzn2 = 1. + yzn2*yzn2*ourview.vn2; for (x = 0; x < hresolu; x++) { vx = (x+.5)/hresolu + ourview.hoff - .5; - zout[x] = zscan(y)[x] - * sqrt(vx*vx*ourview.hn2 + yzn2); + d = sqrt(vx*vx*ourview.hn2 + yzn2); + if (donorm > 0) + zscan(y)[x] *= d; + else + zscan(y)[x] /= d; } - } else - zout = zscan(y); - if (write(fd, (char *)zout, hresolu*sizeof(float)) + } + if (write(fd, (char *)zscan(y), hresolu*sizeof(float)) < hresolu*sizeof(float)) syserror(fname); } - if (donorm) - free((char *)zout); close(fd); } @@ -978,6 +1155,7 @@ clearqueue() /* process queue */ float fbuf[6*(PACKSIZ+1)]; register float *fbp; register int i; + double vx, vy; if (queuesiz == 0) return; @@ -991,9 +1169,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); @@ -1012,7 +1191,14 @@ clearqueue() /* process queue */ } else setcolr(pscan(queue[i][1])[queue[i][0]], fbp[0], fbp[1], fbp[2]); - zscan(queue[i][1])[queue[i][0]] = fbp[3]; + if (zisnorm) + zscan(queue[i][1])[queue[i][0]] = fbp[3]; + else { + vx = (queue[i][0]+.5)/hresolu + ourview.hoff - .5; + vy = (queue[i][1]+.5)/vresolu + ourview.voff - .5; + zscan(queue[i][1])[queue[i][0]] = fbp[3] / sqrt(1. + + vx*vx*ourview.hn2 + vy*vy*ourview.vn2); + } fbp += 4; } queuesiz = 0;