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.21 by greg, Mon Dec 26 21:02:31 1994 UTC vs.
Revision 2.28 by greg, Mon Jun 24 09:17:47 1996 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 26 | Line 26 | static char SCCSid[] = "$SunId$ LBL";
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 57 | 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 67 | 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? */
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 84 | 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 93 | 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    *expcomp = NULL;
113 <        char    *err;
104 <        int     i, rval;
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[++i];
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 133 | 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 152 | 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 180 | 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)
242 >                        if (doavg | doblur)
243                                  rexpadj = pow(2.0, atof(expcomp));
244                          else
245                                  rexpadj = pow(2.0, (double)expadj);
# Line 235 | Line 248 | char   *argv[];
248                                  goto userr;
249                          rexpadj = atof(expcomp);
250                          expadj = log(rexpadj)/LOG2 + (rexpadj>1 ? .5 : -.5);
251 <                        if (!doavg)
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 255 | 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);
261        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();
274                                                        /* aft clipping */
275        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)
# Line 288 | Line 309 | char   *argv[];
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 299 | Line 321 | char   *argv[];
321          exit(0);
322   userr:
323          fprintf(stderr,
324 <        "Usage: %s [view opts][-t eps][-z zout][-e spec][-a|-q][-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
# Line 314 | Line 336 | char   *s;
336          if (isheadid(s))
337                  return;
338          if (formatval(fmt, s)) {
339 <                wrongformat = strcmp(fmt, COLRFMT);
339 >                if (globmatch(ourfmt, fmt)) {
340 >                        wrongformat = 0;
341 >                        strcpy(ourfmt, fmt);
342 >                } else
343 >                        wrongformat = 1;
344                  return;
345          }
346 <        putc('\t', stdout);
347 <        fputs(s, stdout);
348 <
346 >        if (nvavg < 2) {
347 >                putc('\t', stdout);
348 >                fputs(s, stdout);
349 >        }
350          if (isexpos(s)) {
351                  theirexp *= exposval(s);
352                  return;
# Line 329 | Line 356 | char   *s;
356   }
357  
358  
359 + nextview(fp)                            /* get and set next view */
360 + FILE    *fp;
361 + {
362 +        char    linebuf[256];
363 +        char    *err;
364 +        register int    i;
365 +
366 +        if (fp != NULL) {
367 +                do                      /* get new view */
368 +                        if (fgets(linebuf, sizeof(linebuf), fp) == NULL)
369 +                                return(EOF);
370 +                while (!isview(linebuf) || !sscanview(&ourview, linebuf));
371 +        }
372 +                                        /* set new view */
373 +        if ((err = setview(&ourview)) != NULL) {
374 +                fprintf(stderr, "%s: %s\n", progname, err);
375 +                exit(1);
376 +        }
377 +        if (!nvavg) {                   /* first view */
378 +                copystruct(&avgview, &ourview);
379 +                return(nvavg++);
380 +        }
381 +                                        /* add to average view */
382 +        for (i = 0; i < 3; i++) {
383 +                avgview.vp[i] += ourview.vp[i];
384 +                avgview.vdir[i] += ourview.vdir[i];
385 +                avgview.vup[i] += ourview.vup[i];
386 +        }
387 +        avgview.horiz += ourview.horiz;
388 +        avgview.vert += ourview.vert;
389 +        avgview.hoff += ourview.hoff;
390 +        avgview.voff += ourview.voff;
391 +        avgview.vfore += ourview.vfore;
392 +        avgview.vaft += ourview.vaft;
393 +        return(nvavg++);
394 + }
395 +
396 +
397 + compavgview()                           /* compute average view */
398 + {
399 +        register int    i;
400 +        double  f;
401 +
402 +        if (nvavg < 2)
403 +                return;
404 +        f = 1.0/nvavg;
405 +        for (i = 0; i < 3; i++) {
406 +                avgview.vp[i] *= f;
407 +                avgview.vdir[i] *= f;
408 +                avgview.vup[i] *= f;
409 +        }
410 +        avgview.horiz *= f;
411 +        avgview.vert *= f;
412 +        avgview.hoff *= f;
413 +        avgview.voff *= f;
414 +        avgview.vfore *= f;
415 +        avgview.vaft *= f;
416 +        if (setview(&avgview) != NULL)          /* in case of emergency... */
417 +                copystruct(&avgview, &ourview);
418 +        pixaspect = viewaspect(&avgview) * hresolu / vresolu;
419 + }
420 +
421 +
422   addpicture(pfile, zspec)                /* add picture to output */
423   char    *pfile, *zspec;
424   {
# Line 345 | Line 435 | char   *pfile, *zspec;
435                  syserror(pfile);
436                                          /* get header with exposure and view */
437          theirexp = 1.0;
438 +        copystruct(&theirview, &stdview);
439          gotview = 0;
440 <        printf("%s:\n", pfile);
440 >        if (nvavg < 2)
441 >                printf("%s:\n", pfile);
442          getheader(pfp, headline, NULL);
443          if (wrongformat || !gotview || !fgetsresolu(&tresolu, pfp)) {
444                  fprintf(stderr, "%s: picture format error\n", pfile);
# Line 430 | Line 522 | register VIEW  *vw1, *vw2;
522   {
523          double  m4t[4][4];
524  
525 <        if (vw1->type != VT_PER && vw1->type != VT_PAR)
525 >        if (vw1->type != VT_PER & vw1->type != VT_PAR)
526                  return(0);
527 <        if (vw2->type != VT_PER && vw2->type != VT_PAR)
527 >        if (vw2->type != VT_PER & vw2->type != VT_PAR)
528                  return(0);
529          setident4(xfmat);
530          xfmat[0][0] = vw1->hvec[0];
# Line 549 | Line 641 | double z;
641                  y1 = p0->y + c1*s1y/l1;
642                  for (c2 = l2; c2-- > 0; ) {
643                          x = x1 + c2*s2x/l2;
644 <                        if (x < 0 || x >= hresolu)
644 >                        if (x < 0 | x >= hresolu)
645                                  continue;
646                          y = y1 + c2*s2y/l2;
647 <                        if (y < 0 || y >= vresolu)
647 >                        if (y < 0 | y >= vresolu)
648                                  continue;
649                          if (averaging) {
650                                  if (zscan(y)[x] <= 0 || zscan(y)[x]-z
# Line 584 | Line 676 | register FVECT pos;
676          
677          if (pos[2] <= 0)                /* empty pixel */
678                  return(0);
679 <        if (!averaging && hasmatrix) {
679 >        if (usematrix) {
680                  pos[0] += theirview.hoff - .5;
681                  pos[1] += theirview.voff - .5;
682 +                if (normdist & theirview.type == VT_PER)
683 +                        d = sqrt(1. + pos[0]*pos[0]*theirview.hn2
684 +                                        + pos[1]*pos[1]*theirview.vn2);
685 +                else
686 +                        d = 1.;
687 +                pos[2] += d*theirview.vfore;
688                  if (theirview.type == VT_PER) {
689 <                        if (normdist)                   /* adjust distance */
592 <                                pos[2] /= sqrt(1. + pos[0]*pos[0]*theirview.hn2
593 <                                                + pos[1]*pos[1]*theirview.vn2);
689 >                        pos[2] /= d;
690                          pos[0] *= pos[2];
691                          pos[1] *= pos[2];
692                  }
693                  multp3(pos, pos, theirs2ours);
694 <                if (pos[2] <= 0)
694 >                if (pos[2] <= ourview.vfore)
695                          return(0);
696                  if (ourview.type == VT_PER) {
697                          pos[0] /= pos[2];
# Line 603 | Line 699 | register FVECT pos;
699                  }
700                  pos[0] += .5 - ourview.hoff;
701                  pos[1] += .5 - ourview.voff;
702 +                pos[2] -= ourview.vfore;
703          } else {
704                  if (viewray(pt, tdir, &theirview, pos[0], pos[1]) < -FTINY)
705                          return(0);
706 <                if (!normdist && theirview.type == VT_PER)      /* adjust */
706 >                if (!normdist & theirview.type == VT_PER)       /* adjust */
707                          pos[2] *= sqrt(1. + pos[0]*pos[0]*theirview.hn2
708                                          + pos[1]*pos[1]*theirview.vn2);
709                  pt[0] += tdir[0]*pos[2];
# Line 616 | Line 713 | register FVECT pos;
713                  if (pos[2] <= 0)
714                          return(0);
715          }
716 <        if (pos[0] < 0 || pos[0] >= 1-FTINY || pos[1] < 0 || pos[1] >= 1-FTINY)
716 >        if (pos[0] < 0 | pos[0] >= 1-FTINY | pos[1] < 0 | pos[1] >= 1-FTINY)
717                  return(0);
718          if (!averaging)
719                  return(1);
# Line 833 | Line 930 | int    (*fill)();
930                  for (x = 0; x < hresolu; x++)
931                          if (zscan(y)[x] <= 0)
932                                  (*fill)(x,y);
933 +        if (fill == rcalfill)
934 +                clearqueue();
935   }
936  
937  
938   clipaft()                       /* perform aft clipping as indicated */
939   {
940          register int    x, y;
941 +        int     adjtest = ourview.type == VT_PER & zisnorm;
942          double  tstdist;
943          double  yzn2, vx;
944  
945          if (ourview.vaft <= FTINY)
946 <                return;
946 >                return(0);
947          tstdist = ourview.vaft - ourview.vfore;
948          for (y = 0; y < vresolu; y++) {
949 <                if (ourview.type == VT_PER) {           /* adjust distance */
949 >                if (adjtest) {                          /* adjust test */
950                          yzn2 = (y+.5)/vresolu + ourview.voff - .5;
951                          yzn2 = 1. + yzn2*yzn2*ourview.vn2;
952                          tstdist = (ourview.vaft - ourview.vfore)*sqrt(yzn2);
953                  }
954                  for (x = 0; x < hresolu; x++)
955                          if (zscan(y)[x] > tstdist) {
956 <                                if (ourview.type == VT_PER) {
956 >                                if (adjtest) {
957                                          vx = (x+.5)/hresolu + ourview.hoff - .5;
958                                          if (zscan(y)[x] <= (ourview.vaft -
959                                                          ourview.vfore) *
# Line 867 | Line 967 | clipaft()                      /* perform aft clipping as indicated */
967                                  zscan(y)[x] = 0.0;
968                          }
969          }
970 +        return(1);
971   }
972  
973  
974 + addblur()                               /* add to blurred picture */
975 + {
976 +        COLOR   cval;
977 +        double  d;
978 +        register int    i;
979 +
980 +        if (!blurring)
981 +                return(0);
982 +        i = hresolu*vresolu;
983 +        if (nvavg < 2)
984 +                if (averaging)
985 +                        while (i--) {
986 +                                copycolor(ourbpict[i], ourspict[i]);
987 +                                d = 1.0/ourweigh[i];
988 +                                scalecolor(ourbpict[i], d);
989 +                        }
990 +                else
991 +                        while (i--)
992 +                                colr_color(ourbpict[i], ourpict[i]);
993 +        else
994 +                if (averaging)
995 +                        while (i--) {
996 +                                copycolor(cval, ourspict[i]);
997 +                                d = 1.0/ourweigh[i];
998 +                                scalecolor(cval, d);
999 +                                addcolor(ourbpict[i], cval);
1000 +                        }
1001 +                else
1002 +                        while (i--) {
1003 +                                colr_color(cval, ourpict[i]);
1004 +                                addcolor(ourbpict[i], cval);
1005 +                        }
1006 +                                /* print view */
1007 +        printf("VIEW%d:", nvavg);
1008 +        fprintview(&ourview, stdout);
1009 +        putchar('\n');
1010 +        return(1);
1011 + }
1012 +
1013 +
1014   writepicture()                          /* write out picture (alters buffer) */
1015   {
1016          int     y;
# Line 878 | Line 1019 | writepicture()                         /* write out picture (alters buffer)
1019  
1020          fprtresolu(hresolu, vresolu, stdout);
1021          for (y = vresolu-1; y >= 0; y--)
1022 <                if (averaging) {
1022 >                if (blurring) {
1023 >                        for (x = 0; x < hresolu; x++) { /* compute avg. */
1024 >                                d = rexpadj/nvavg;
1025 >                                scalecolor(bscan(y)[x], d);
1026 >                        }
1027 >                        if (fwritescan(bscan(y), hresolu, stdout) < 0)
1028 >                                syserror(progname);
1029 >                } else if (averaging) {
1030                          for (x = 0; x < hresolu; x++) { /* average pixels */
1031                                  d = rexpadj/wscan(y)[x];
1032                                  scalecolor(sscan(y)[x], d);
# Line 894 | Line 1042 | writepicture()                         /* write out picture (alters buffer)
1042   }
1043  
1044  
1045 < writedistance(fname)                    /* write out z file */
1045 > writedistance(fname)                    /* write out z file (alters buffer) */
1046   char    *fname;
1047   {
1048 <        int     donorm = normdist && ourview.type == VT_PER &&
1049 <                        !averaging && hasmatrix;
1048 >        int     donorm = normdist & !zisnorm ? 1 :
1049 >                        ourview.type == VT_PER & !normdist & zisnorm ? -1 : 0;
1050          int     fd;
1051          int     y;
904        float   *zout;
1052  
1053          if ((fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1)
1054                  syserror(fname);
908        if (donorm
909        && (zout = (float *)malloc(hresolu*sizeof(float))) == NULL)
910                syserror(progname);
1055          for (y = vresolu-1; y >= 0; y--) {
1056                  if (donorm) {
1057 <                        double  vx, yzn2;
1057 >                        double  vx, yzn2, d;
1058                          register int    x;
1059                          yzn2 = (y+.5)/vresolu + ourview.voff - .5;
1060                          yzn2 = 1. + yzn2*yzn2*ourview.vn2;
1061                          for (x = 0; x < hresolu; x++) {
1062                                  vx = (x+.5)/hresolu + ourview.hoff - .5;
1063 <                                zout[x] = zscan(y)[x]
1064 <                                        * sqrt(vx*vx*ourview.hn2 + yzn2);
1063 >                                d = sqrt(vx*vx*ourview.hn2 + yzn2);
1064 >                                if (donorm > 0)
1065 >                                        zscan(y)[x] *= d;
1066 >                                else
1067 >                                        zscan(y)[x] /= d;
1068                          }
1069 <                } else
1070 <                        zout = zscan(y);
924 <                if (write(fd, (char *)zout, hresolu*sizeof(float))
1069 >                }
1070 >                if (write(fd, (char *)zscan(y), hresolu*sizeof(float))
1071                                  < hresolu*sizeof(float))
1072                          syserror(fname);
1073          }
928        if (donorm)
929                free((char *)zout);
1074          close(fd);
1075   }
1076  
# Line 1011 | Line 1155 | clearqueue()                           /* process queue */
1155          float   fbuf[6*(PACKSIZ+1)];
1156          register float  *fbp;
1157          register int    i;
1158 +        double  vx, vy;
1159  
1160          if (queuesiz == 0)
1161                  return;
# Line 1045 | Line 1190 | clearqueue()                           /* process queue */
1190                  } else
1191                          setcolr(pscan(queue[i][1])[queue[i][0]],
1192                                          fbp[0], fbp[1], fbp[2]);
1193 <                zscan(queue[i][1])[queue[i][0]] = fbp[3];
1193 >                if (zisnorm)
1194 >                        zscan(queue[i][1])[queue[i][0]] = fbp[3];
1195 >                else {
1196 >                        vx = (queue[i][0]+.5)/hresolu + ourview.hoff - .5;
1197 >                        vy = (queue[i][1]+.5)/vresolu + ourview.voff - .5;
1198 >                        zscan(queue[i][1])[queue[i][0]] = fbp[3] / sqrt(1. +
1199 >                                        vx*vx*ourview.hn2 + vy*vy*ourview.vn2);
1200 >                }
1201                  fbp += 4;
1202          }
1203          queuesiz = 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines