ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/pinterp.c
(Generate patch)

Comparing ray/src/px/pinterp.c (file contents):
Revision 2.20 by greg, Mon Dec 26 19:57:22 1994 UTC vs.
Revision 2.31 by gwlarson, Tue Oct 27 09:08:26 1998 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1994 Regents of the University of California */
1 > /* Copyright (c) 1995 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 20 | Line 20 | static char SCCSid[] = "$SunId$ LBL";
20  
21   #include "resolu.h"
22  
23 + #define LOG2            0.69314718055994530942
24 +
25   #define pscan(y)        (ourpict+(y)*hresolu)
26   #define sscan(y)        (ourspict+(y)*hresolu)
27   #define wscan(y)        (ourweigh+(y)*hresolu)
28   #define zscan(y)        (ourzbuf+(y)*hresolu)
29 + #define bscan(y)        (ourbpict+(y)*hresolu)
30   #define averaging       (ourweigh != NULL)
31 + #define blurring        (ourbpict != NULL)
32 + #define usematrix       (hasmatrix & !averaging)
33 + #define zisnorm         (!usematrix | ourview.type != VT_PER)
34  
35   #define MAXWT           1000.           /* maximum pixel weight (averaging) */
36  
# Line 33 | Line 39 | static char SCCSid[] = "$SunId$ LBL";
39  
40   #define PACKSIZ         256             /* max. calculation packet size */
41  
42 < #define RTCOM           "rtrace -h- -ovl -fff "
42 > #define RTCOM           "rtrace -h- -ovl -fff -ld- -i- -I- "
43  
44   #define ABS(x)          ((x)>0?(x):-(x))
45  
# Line 55 | Line 61 | COLR   *ourpict;                       /* output picture (COLR's) */
61   COLOR   *ourspict;                      /* output pixel sums (averaging) */
62   float   *ourweigh = NULL;               /* output pixel weights (averaging) */
63   float   *ourzbuf;                       /* corresponding z-buffer */
64 + COLOR   *ourbpict = NULL;               /* blurred picture (view averaging) */
65  
66 + VIEW    avgview;                        /* average view for -B option */
67 + int     nvavg;                          /* number of views averaged */
68 +
69   char    *progname;
70  
71   int     fillo = F_FORE|F_BACK;          /* selected fill options */
# Line 65 | Line 75 | int    (*fillfunc)() = backfill;       /* selected fill functio
75   COLR    backcolr = BLKCOLR;             /* background color */
76   COLOR   backcolor = BLKCOLOR;           /* background color (float) */
77   double  backz = 0.0;                    /* background z value */
78 < int     normdist = 1;                   /* normalized distance? */
79 < double  ourexp = -1;                    /* output picture exposure */
78 > int     normdist = 1;                   /* i/o normalized distance? */
79 > char    ourfmt[LPICFMT+1] = PICFMT;     /* original picture format */
80 > double  ourexp = -1;                    /* original picture exposure */
81 > int     expadj = 0;                     /* exposure adjustment (f-stops) */
82 > double  rexpadj = 1;                    /* real exposure adjustment */
83  
84 < VIEW    theirview = STDVIEW;            /* input view */
84 > VIEW    theirview;                      /* input view */
85   int     gotview;                        /* got input view? */
86   int     wrongformat = 0;                /* input in another format? */
87   RESOLU  tresolu;                        /* input resolution */
# Line 80 | Line 93 | int    PDesc[3] = {-1,-1,-1};          /* rtrace process descript
93   #define childpid        (PDesc[2])
94   unsigned short  queue[PACKSIZ][2];      /* pending pixels */
95   int     packsiz;                        /* actual packet size */
96 < int     queuesiz;                       /* number of pixels pending */
96 > int     queuesiz = 0;                   /* number of pixels pending */
97  
98   extern double   movepixel();
99  
# Line 89 | Line 102 | main(argc, argv)                       /* interpolate pictures */
102   int     argc;
103   char    *argv[];
104   {
105 < #define  check(ol,al)           if (argv[i][ol] || \
106 <                                badarg(argc-i-1,argv+i+1,al)) \
105 > #define  check(ol,al)           if (argv[an][ol] || \
106 >                                badarg(argc-an-1,argv+an+1,al)) \
107                                  goto badopt
108          int     gotvfile = 0;
109          int     doavg = -1;
110 +        int     doblur = 0;
111          char    *zfile = NULL;
112 <        char    *err;
113 <        int     i, rval;
112 >        char    *expcomp = NULL;
113 >        int     i, an, rval;
114  
115          progname = argv[0];
116  
117 <        for (i = 1; i < argc && argv[i][0] == '-'; i++) {
118 <                rval = getviewopt(&ourview, argc-i, argv+i);
117 >        for (an = 1; an < argc && argv[an][0] == '-'; an++) {
118 >                rval = getviewopt(&ourview, argc-an, argv+an);
119                  if (rval >= 0) {
120 <                        i += rval;
120 >                        an += rval;
121                          continue;
122                  }
123 <                switch (argv[i][1]) {
123 >                switch (argv[an][1]) {
124 >                case 'e':                               /* exposure */
125 >                        check(2,"f");
126 >                        expcomp = argv[++an];
127 >                        break;
128                  case 't':                               /* threshold */
129                          check(2,"f");
130 <                        zeps = atof(argv[++i]);
130 >                        zeps = atof(argv[++an]);
131                          break;
132                  case 'a':                               /* average */
133                          check(2,NULL);
134                          doavg = 1;
135                          break;
136 +                case 'B':                               /* blur views */
137 +                        check(2,NULL);
138 +                        doblur = 1;
139 +                        break;
140                  case 'q':                               /* quick (no avg.) */
141                          check(2,NULL);
142                          doavg = 0;
# Line 124 | Line 146 | char   *argv[];
146                          normdist = !normdist;
147                          break;
148                  case 'f':                               /* fill type */
149 <                        switch (argv[i][2]) {
149 >                        switch (argv[an][2]) {
150                          case '0':                               /* none */
151                                  check(3,NULL);
152                                  fillo = 0;
# Line 143 | Line 165 | char   *argv[];
165                                  break;
166                          case 's':                               /* sample */
167                                  check(3,"i");
168 <                                fillsamp = atoi(argv[++i]);
168 >                                fillsamp = atoi(argv[++an]);
169                                  break;
170                          case 'c':                               /* color */
171                                  check(3,"fff");
172                                  fillfunc = backfill;
173 <                                setcolor(backcolor, atof(argv[i+1]),
174 <                                        atof(argv[i+2]), atof(argv[i+3]));
173 >                                setcolor(backcolor, atof(argv[an+1]),
174 >                                        atof(argv[an+2]), atof(argv[an+3]));
175                                  setcolr(backcolr, colval(backcolor,RED),
176                                                  colval(backcolor,GRN),
177                                                  colval(backcolor,BLU));
178 <                                i += 3;
178 >                                an += 3;
179                                  break;
180                          case 'z':                               /* z value */
181                                  check(3,"f");
182                                  fillfunc = backfill;
183 <                                backz = atof(argv[++i]);
183 >                                backz = atof(argv[++an]);
184                                  break;
185                          case 'r':                               /* rtrace */
186                                  check(3,"s");
187                                  fillfunc = rcalfill;
188 <                                calstart(RTCOM, argv[++i]);
188 >                                calstart(RTCOM, argv[++an]);
189                                  break;
190                          default:
191                                  goto badopt;
# Line 171 | Line 193 | char   *argv[];
193                          break;
194                  case 'z':                               /* z file */
195                          check(2,"s");
196 <                        zfile = argv[++i];
196 >                        zfile = argv[++an];
197                          break;
198                  case 'x':                               /* x resolution */
199                          check(2,"i");
200 <                        hresolu = atoi(argv[++i]);
200 >                        hresolu = atoi(argv[++an]);
201                          break;
202                  case 'y':                               /* y resolution */
203                          check(2,"i");
204 <                        vresolu = atoi(argv[++i]);
204 >                        vresolu = atoi(argv[++an]);
205                          break;
206                  case 'p':                               /* pixel aspect */
207 <                        if (argv[i][2] != 'a')
207 >                        if (argv[an][2] != 'a')
208                                  goto badopt;
209                          check(3,"f");
210 <                        pixaspect = atof(argv[++i]);
210 >                        pixaspect = atof(argv[++an]);
211                          break;
212                  case 'v':                               /* view file */
213 <                        if (argv[i][2] != 'f')
213 >                        if (argv[an][2] != 'f')
214                                  goto badopt;
215                          check(3,"s");
216 <                        gotvfile = viewfile(argv[++i], &ourview, 0, 0);
216 >                        gotvfile = viewfile(argv[++an], &ourview, 0, 0);
217                          if (gotvfile < 0)
218 <                                syserror(argv[i]);
218 >                                syserror(argv[an]);
219                          else if (gotvfile == 0) {
220                                  fprintf(stderr, "%s: bad view file\n",
221 <                                                argv[i]);
221 >                                                argv[an]);
222                                  exit(1);
223                          }
224                          break;
225                  default:
226                  badopt:
227                          fprintf(stderr, "%s: command line error at '%s'\n",
228 <                                        progname, argv[i]);
228 >                                        progname, argv[an]);
229                          goto userr;
230                  }
231          }
232                                                  /* check arguments */
233 <        if ((argc-i)%2)
233 >        if ((argc-an)%2)
234                  goto userr;
235          if (fillsamp == 1)
236                  fillo &= ~F_BACK;
237          if (doavg < 0)
238 <                doavg = (argc-i) > 2;
238 >                doavg = (argc-an) > 2;
239 >        if (expcomp != NULL)
240 >                if (expcomp[0] == '+' | expcomp[0] == '-') {
241 >                        expadj = atof(expcomp) + (expcomp[0]=='+' ? .5 : -.5);
242 >                        if (doavg | doblur)
243 >                                rexpadj = pow(2.0, atof(expcomp));
244 >                        else
245 >                                rexpadj = pow(2.0, (double)expadj);
246 >                } else {
247 >                        if (!isflt(expcomp))
248 >                                goto userr;
249 >                        rexpadj = atof(expcomp);
250 >                        expadj = log(rexpadj)/LOG2 + (rexpadj>1 ? .5 : -.5);
251 >                        if (!(doavg | doblur))
252 >                                rexpadj = pow(2.0, (double)expadj);
253 >                }
254                                                  /* set view */
255 <        if ((err = setview(&ourview)) != NULL) {
256 <                fprintf(stderr, "%s: %s\n", progname, err);
255 >        if (nextview(doblur ? stdin : (FILE *)NULL) == EOF) {
256 >                fprintf(stderr, "%s: no view on standard input!\n",
257 >                                progname);
258                  exit(1);
259          }
260          normaspect(viewaspect(&ourview), &pixaspect, &hresolu, &vresolu);
# Line 231 | Line 269 | char   *argv[];
269                  if (ourpict == NULL)
270                          syserror(progname);
271          }
272 +        if (doblur) {
273 +                ourbpict = (COLOR *)bmalloc(hresolu*vresolu*sizeof(COLOR));
274 +                if (ourbpict == NULL)
275 +                        syserror(progname);
276 +        }
277          ourzbuf = (float *)bmalloc(hresolu*vresolu*sizeof(float));
278          if (ourzbuf == NULL)
279                  syserror(progname);
237        bzero((char *)ourzbuf, hresolu*vresolu*sizeof(float));
280                                                          /* new header */
281          newheader("RADIANCE", stdout);
282 <                                                        /* get input */
283 <        for ( ; i < argc; i += 2)
284 <                addpicture(argv[i], argv[i+1]);
285 <                                                        /* fill in spaces */
286 <        if (fillo&F_BACK)
287 <                backpicture(fillfunc, fillsamp);
288 <        else
289 <                fillpicture(fillfunc);
282 >                                                        /* run pictures */
283 >        do {
284 >                bzero((char *)ourzbuf, hresolu*vresolu*sizeof(float));
285 >                for (i = an; i < argc; i += 2)
286 >                        addpicture(argv[i], argv[i+1]);
287 >                if (fillo&F_BACK)                       /* fill in spaces */
288 >                        backpicture(fillfunc, fillsamp);
289 >                else
290 >                        fillpicture(fillfunc);
291 >                                                        /* aft clipping */
292 >                clipaft();
293 >        } while (addblur() && nextview(stdin) != EOF);
294                                                          /* close calculation */
295          caldone();
250                                                        /* aft clipping */
251        clipaft();
296                                                          /* add to header */
297          printargs(argc, argv, stdout);
298 <        if (gotvfile) {
298 >        compavgview();
299 >        if (doblur | gotvfile) {
300                  fputs(VIEWSTR, stdout);
301 <                fprintview(&ourview, stdout);
301 >                fprintview(&avgview, stdout);
302                  putc('\n', stdout);
303          }
304 <        if (pixaspect < .99 || pixaspect > 1.01)
304 >        if (pixaspect < .99 | pixaspect > 1.01)
305                  fputaspect(pixaspect, stdout);
306 <        if (ourexp > 0 && (ourexp < .995 || ourexp > 1.005))
306 >        if (ourexp > 0)
307 >                ourexp *= rexpadj;
308 >        else
309 >                ourexp = rexpadj;
310 >        if (ourexp < .995 | ourexp > 1.005)
311                  fputexpos(ourexp, stdout);
312 <        fputformat(COLRFMT, stdout);
312 >        if (strcmp(ourfmt, PICFMT))             /* print format if known */
313 >                fputformat(ourfmt, stdout);
314          putc('\n', stdout);
315                                                          /* write picture */
316          writepicture();
# Line 271 | Line 321 | char   *argv[];
321          exit(0);
322   userr:
323          fprintf(stderr,
324 <        "Usage: %s [view opts][-t eps][-z zout][-fT][-n] pfile zspec ..\n",
324 >        "Usage: %s [view opts][-t eps][-z zout][-e spec][-B][-a|-q][-fT][-n] pfile zspec ..\n",
325                          progname);
326          exit(1);
327   #undef check
328   }
329  
330  
331 + int
332   headline(s)                             /* process header string */
333   char    *s;
334   {
335          char    fmt[32];
336  
337          if (isheadid(s))
338 <                return;
338 >                return(0);
339          if (formatval(fmt, s)) {
340 <                wrongformat = strcmp(fmt, COLRFMT);
341 <                return;
340 >                if (globmatch(ourfmt, fmt)) {
341 >                        wrongformat = 0;
342 >                        strcpy(ourfmt, fmt);
343 >                } else
344 >                        wrongformat = 1;
345 >                return(0);
346          }
347 <        putc('\t', stdout);
348 <        fputs(s, stdout);
349 <
347 >        if (nvavg < 2) {
348 >                putc('\t', stdout);
349 >                fputs(s, stdout);
350 >        }
351          if (isexpos(s)) {
352                  theirexp *= exposval(s);
353 <                return;
353 >                return(0);
354          }
355          if (isview(s) && sscanview(&theirview, s) > 0)
356                  gotview++;
357 +        return(0);
358   }
359  
360  
361 + nextview(fp)                            /* get and set next view */
362 + FILE    *fp;
363 + {
364 +        char    linebuf[256];
365 +        char    *err;
366 +        register int    i;
367 +
368 +        if (fp != NULL) {
369 +                do                      /* get new view */
370 +                        if (fgets(linebuf, sizeof(linebuf), fp) == NULL)
371 +                                return(EOF);
372 +                while (!isview(linebuf) || !sscanview(&ourview, linebuf));
373 +        }
374 +                                        /* set new view */
375 +        if ((err = setview(&ourview)) != NULL) {
376 +                fprintf(stderr, "%s: %s\n", progname, err);
377 +                exit(1);
378 +        }
379 +        if (!nvavg) {                   /* first view */
380 +                copystruct(&avgview, &ourview);
381 +                return(nvavg++);
382 +        }
383 +                                        /* add to average view */
384 +        for (i = 0; i < 3; i++) {
385 +                avgview.vp[i] += ourview.vp[i];
386 +                avgview.vdir[i] += ourview.vdir[i];
387 +                avgview.vup[i] += ourview.vup[i];
388 +        }
389 +        avgview.horiz += ourview.horiz;
390 +        avgview.vert += ourview.vert;
391 +        avgview.hoff += ourview.hoff;
392 +        avgview.voff += ourview.voff;
393 +        avgview.vfore += ourview.vfore;
394 +        avgview.vaft += ourview.vaft;
395 +        return(nvavg++);
396 + }
397 +
398 +
399 + compavgview()                           /* compute average view */
400 + {
401 +        register int    i;
402 +        double  f;
403 +
404 +        if (nvavg < 2)
405 +                return;
406 +        f = 1.0/nvavg;
407 +        for (i = 0; i < 3; i++) {
408 +                avgview.vp[i] *= f;
409 +                avgview.vdir[i] *= f;
410 +                avgview.vup[i] *= f;
411 +        }
412 +        avgview.horiz *= f;
413 +        avgview.vert *= f;
414 +        avgview.hoff *= f;
415 +        avgview.voff *= f;
416 +        avgview.vfore *= f;
417 +        avgview.vaft *= f;
418 +        if (setview(&avgview) != NULL)          /* in case of emergency... */
419 +                copystruct(&avgview, &ourview);
420 +        pixaspect = viewaspect(&avgview) * hresolu / vresolu;
421 + }
422 +
423 +
424   addpicture(pfile, zspec)                /* add picture to output */
425   char    *pfile, *zspec;
426   {
# Line 317 | Line 437 | char   *pfile, *zspec;
437                  syserror(pfile);
438                                          /* get header with exposure and view */
439          theirexp = 1.0;
440 +        copystruct(&theirview, &stdview);
441          gotview = 0;
442 <        printf("%s:\n", pfile);
442 >        if (nvavg < 2)
443 >                printf("%s:\n", pfile);
444          getheader(pfp, headline, NULL);
445          if (wrongformat || !gotview || !fgetsresolu(&tresolu, pfp)) {
446                  fprintf(stderr, "%s: picture format error\n", pfile);
# Line 402 | Line 524 | register VIEW  *vw1, *vw2;
524   {
525          double  m4t[4][4];
526  
527 <        if (vw1->type != VT_PER && vw1->type != VT_PAR)
527 >        if (vw1->type != VT_PER & vw1->type != VT_PAR)
528                  return(0);
529 <        if (vw2->type != VT_PER && vw2->type != VT_PAR)
529 >        if (vw2->type != VT_PER & vw2->type != VT_PAR)
530                  return(0);
531          setident4(xfmat);
532          xfmat[0][0] = vw1->hvec[0];
# Line 521 | Line 643 | double z;
643                  y1 = p0->y + c1*s1y/l1;
644                  for (c2 = l2; c2-- > 0; ) {
645                          x = x1 + c2*s2x/l2;
646 <                        if (x < 0 || x >= hresolu)
646 >                        if (x < 0 | x >= hresolu)
647                                  continue;
648                          y = y1 + c2*s2y/l2;
649 <                        if (y < 0 || y >= vresolu)
649 >                        if (y < 0 | y >= vresolu)
650                                  continue;
651                          if (averaging) {
652                                  if (zscan(y)[x] <= 0 || zscan(y)[x]-z
# Line 556 | Line 678 | register FVECT pos;
678          
679          if (pos[2] <= 0)                /* empty pixel */
680                  return(0);
681 <        if (!averaging && hasmatrix) {
681 >        if (usematrix) {
682                  pos[0] += theirview.hoff - .5;
683                  pos[1] += theirview.voff - .5;
684 +                if (normdist & theirview.type == VT_PER)
685 +                        d = sqrt(1. + pos[0]*pos[0]*theirview.hn2
686 +                                        + pos[1]*pos[1]*theirview.vn2);
687 +                else
688 +                        d = 1.;
689 +                pos[2] += d*theirview.vfore;
690                  if (theirview.type == VT_PER) {
691 <                        if (normdist)                   /* adjust distance */
564 <                                pos[2] /= sqrt(1. + pos[0]*pos[0]*theirview.hn2
565 <                                                + pos[1]*pos[1]*theirview.vn2);
691 >                        pos[2] /= d;
692                          pos[0] *= pos[2];
693                          pos[1] *= pos[2];
694                  }
695                  multp3(pos, pos, theirs2ours);
696 <                if (pos[2] <= 0)
696 >                if (pos[2] <= ourview.vfore)
697                          return(0);
698                  if (ourview.type == VT_PER) {
699                          pos[0] /= pos[2];
# Line 575 | Line 701 | register FVECT pos;
701                  }
702                  pos[0] += .5 - ourview.hoff;
703                  pos[1] += .5 - ourview.voff;
704 +                pos[2] -= ourview.vfore;
705          } else {
706                  if (viewray(pt, tdir, &theirview, pos[0], pos[1]) < -FTINY)
707                          return(0);
708 <                if (!normdist && theirview.type == VT_PER)      /* adjust */
708 >                if (!normdist & theirview.type == VT_PER)       /* adjust */
709                          pos[2] *= sqrt(1. + pos[0]*pos[0]*theirview.hn2
710                                          + pos[1]*pos[1]*theirview.vn2);
711                  pt[0] += tdir[0]*pos[2];
# Line 588 | Line 715 | register FVECT pos;
715                  if (pos[2] <= 0)
716                          return(0);
717          }
718 <        if (pos[0] < 0 || pos[0] >= 1-FTINY || pos[1] < 0 || pos[1] >= 1-FTINY)
718 >        if (pos[0] < 0 | pos[0] >= 1-FTINY | pos[1] < 0 | pos[1] >= 1-FTINY)
719                  return(0);
720          if (!averaging)
721                  return(1);
# Line 805 | Line 932 | int    (*fill)();
932                  for (x = 0; x < hresolu; x++)
933                          if (zscan(y)[x] <= 0)
934                                  (*fill)(x,y);
935 +        if (fill == rcalfill)
936 +                clearqueue();
937   }
938  
939  
940   clipaft()                       /* perform aft clipping as indicated */
941   {
942          register int    x, y;
943 +        int     adjtest = ourview.type == VT_PER & zisnorm;
944          double  tstdist;
945          double  yzn2, vx;
946  
947          if (ourview.vaft <= FTINY)
948 <                return;
948 >                return(0);
949          tstdist = ourview.vaft - ourview.vfore;
950          for (y = 0; y < vresolu; y++) {
951 <                if (ourview.type == VT_PER) {           /* adjust distance */
951 >                if (adjtest) {                          /* adjust test */
952                          yzn2 = (y+.5)/vresolu + ourview.voff - .5;
953                          yzn2 = 1. + yzn2*yzn2*ourview.vn2;
954                          tstdist = (ourview.vaft - ourview.vfore)*sqrt(yzn2);
955                  }
956                  for (x = 0; x < hresolu; x++)
957                          if (zscan(y)[x] > tstdist) {
958 <                                if (ourview.type == VT_PER) {
958 >                                if (adjtest) {
959                                          vx = (x+.5)/hresolu + ourview.hoff - .5;
960                                          if (zscan(y)[x] <= (ourview.vaft -
961                                                          ourview.vfore) *
# Line 839 | Line 969 | clipaft()                      /* perform aft clipping as indicated */
969                                  zscan(y)[x] = 0.0;
970                          }
971          }
972 +        return(1);
973   }
974  
975  
976 < writepicture()                          /* write out picture */
976 > addblur()                               /* add to blurred picture */
977   {
978 +        COLOR   cval;
979 +        double  d;
980 +        register int    i;
981 +
982 +        if (!blurring)
983 +                return(0);
984 +        i = hresolu*vresolu;
985 +        if (nvavg < 2)
986 +                if (averaging)
987 +                        while (i--) {
988 +                                copycolor(ourbpict[i], ourspict[i]);
989 +                                d = 1.0/ourweigh[i];
990 +                                scalecolor(ourbpict[i], d);
991 +                        }
992 +                else
993 +                        while (i--)
994 +                                colr_color(ourbpict[i], ourpict[i]);
995 +        else
996 +                if (averaging)
997 +                        while (i--) {
998 +                                copycolor(cval, ourspict[i]);
999 +                                d = 1.0/ourweigh[i];
1000 +                                scalecolor(cval, d);
1001 +                                addcolor(ourbpict[i], cval);
1002 +                        }
1003 +                else
1004 +                        while (i--) {
1005 +                                colr_color(cval, ourpict[i]);
1006 +                                addcolor(ourbpict[i], cval);
1007 +                        }
1008 +                                /* print view */
1009 +        printf("VIEW%d:", nvavg);
1010 +        fprintview(&ourview, stdout);
1011 +        putchar('\n');
1012 +        return(1);
1013 + }
1014 +
1015 +
1016 + writepicture()                          /* write out picture (alters buffer) */
1017 + {
1018          int     y;
1019          register int    x;
1020          double  d;
1021  
1022          fprtresolu(hresolu, vresolu, stdout);
1023          for (y = vresolu-1; y >= 0; y--)
1024 <                if (averaging) {
1024 >                if (blurring) {
1025 >                        for (x = 0; x < hresolu; x++) { /* compute avg. */
1026 >                                d = rexpadj/nvavg;
1027 >                                scalecolor(bscan(y)[x], d);
1028 >                        }
1029 >                        if (fwritescan(bscan(y), hresolu, stdout) < 0)
1030 >                                syserror(progname);
1031 >                } else if (averaging) {
1032                          for (x = 0; x < hresolu; x++) { /* average pixels */
1033 <                                d = 1./wscan(y)[x];
1033 >                                d = rexpadj/wscan(y)[x];
1034                                  scalecolor(sscan(y)[x], d);
857                                wscan(y)[x] = 1;
1035                          }
1036                          if (fwritescan(sscan(y), hresolu, stdout) < 0)
1037                                  syserror(progname);
1038 <                } else if (fwritecolrs(pscan(y), hresolu, stdout) < 0)
1039 <                        syserror(progname);
1038 >                } else {
1039 >                        if (expadj)
1040 >                                shiftcolrs(pscan(y), hresolu, expadj);
1041 >                        if (fwritecolrs(pscan(y), hresolu, stdout) < 0)
1042 >                                syserror(progname);
1043 >                }
1044   }
1045  
1046  
1047 < writedistance(fname)                    /* write out z file */
1047 > writedistance(fname)                    /* write out z file (alters buffer) */
1048   char    *fname;
1049   {
1050 <        int     donorm = normdist && ourview.type == VT_PER;
1050 >        int     donorm = normdist & !zisnorm ? 1 :
1051 >                        ourview.type == VT_PER & !normdist & zisnorm ? -1 : 0;
1052          int     fd;
1053          int     y;
872        float   *zout;
1054  
1055          if ((fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1)
1056                  syserror(fname);
876        if (donorm
877        && (zout = (float *)malloc(hresolu*sizeof(float))) == NULL)
878                syserror(progname);
1057          for (y = vresolu-1; y >= 0; y--) {
1058                  if (donorm) {
1059 <                        double  vx, yzn2;
1059 >                        double  vx, yzn2, d;
1060                          register int    x;
1061                          yzn2 = (y+.5)/vresolu + ourview.voff - .5;
1062                          yzn2 = 1. + yzn2*yzn2*ourview.vn2;
1063                          for (x = 0; x < hresolu; x++) {
1064                                  vx = (x+.5)/hresolu + ourview.hoff - .5;
1065 <                                zout[x] = zscan(y)[x]
1066 <                                        * sqrt(vx*vx*ourview.hn2 + yzn2);
1065 >                                d = sqrt(vx*vx*ourview.hn2 + yzn2);
1066 >                                if (donorm > 0)
1067 >                                        zscan(y)[x] *= d;
1068 >                                else
1069 >                                        zscan(y)[x] /= d;
1070                          }
1071 <                } else
1072 <                        zout = zscan(y);
892 <                if (write(fd, (char *)zout, hresolu*sizeof(float))
1071 >                }
1072 >                if (write(fd, (char *)zscan(y), hresolu*sizeof(float))
1073                                  < hresolu*sizeof(float))
1074                          syserror(fname);
1075          }
896        if (donorm)
897                free((char *)zout);
1076          close(fd);
1077   }
1078  
# Line 979 | Line 1157 | clearqueue()                           /* process queue */
1157          float   fbuf[6*(PACKSIZ+1)];
1158          register float  *fbp;
1159          register int    i;
1160 +        double  vx, vy;
1161  
1162          if (queuesiz == 0)
1163                  return;
# Line 992 | Line 1171 | clearqueue()                           /* process queue */
1171          }
1172                                          /* mark end and get results */
1173          bzero((char *)fbp, 6*sizeof(float));
1174 <        if (process(PDesc, fbuf, fbuf, 4*sizeof(float)*queuesiz,
1174 >        if (process(PDesc, fbuf, fbuf, 4*sizeof(float)*(queuesiz+1),
1175                          6*sizeof(float)*(queuesiz+1)) !=
1176 <                        4*sizeof(float)*queuesiz) {
1176 >                        4*sizeof(float)*(queuesiz+1)) {
1177                  fprintf(stderr, "%s: error reading from rtrace process\n",
1178                                  progname);
1179                  exit(1);
# Line 1013 | Line 1192 | clearqueue()                           /* process queue */
1192                  } else
1193                          setcolr(pscan(queue[i][1])[queue[i][0]],
1194                                          fbp[0], fbp[1], fbp[2]);
1195 <                zscan(queue[i][1])[queue[i][0]] = fbp[3];
1195 >                if (zisnorm)
1196 >                        zscan(queue[i][1])[queue[i][0]] = fbp[3];
1197 >                else {
1198 >                        vx = (queue[i][0]+.5)/hresolu + ourview.hoff - .5;
1199 >                        vy = (queue[i][1]+.5)/vresolu + ourview.voff - .5;
1200 >                        zscan(queue[i][1])[queue[i][0]] = fbp[3] / sqrt(1. +
1201 >                                        vx*vx*ourview.hn2 + vy*vy*ourview.vn2);
1202 >                }
1203                  fbp += 4;
1204          }
1205          queuesiz = 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines