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.19 by greg, Fri Dec 23 22:35:12 1994 UTC vs.
Revision 2.21 by greg, Mon Dec 26 21:02:31 1994 UTC

# 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 averaging       (ourweigh != NULL)
30  
31 < #define MAXWT           100.            /* maximum pixel weight (averaging) */
31 > #define MAXWT           1000.           /* maximum pixel weight (averaging) */
32  
33   #define F_FORE          1               /* fill foreground */
34   #define F_BACK          2               /* fill background */
# Line 52 | Line 54 | double pixaspect = 1.0;                /* pixel aspect ratio */
54   double  zeps = .02;                     /* allowed z epsilon */
55  
56   COLR    *ourpict;                       /* output picture (COLR's) */
57 < COLOR   *ourspict;                      /* output pixel sums (-a option) */
58 < float   *ourweigh = NULL;               /* output pixel weights (-a option) */
57 > COLOR   *ourspict;                      /* output pixel sums (averaging) */
58 > float   *ourweigh = NULL;               /* output pixel weights (averaging) */
59   float   *ourzbuf;                       /* corresponding z-buffer */
60  
61   char    *progname;
# Line 66 | Line 68 | COLR   backcolr = BLKCOLR;             /* background color */
68   COLOR   backcolor = BLKCOLOR;           /* background color (float) */
69   double  backz = 0.0;                    /* background z value */
70   int     normdist = 1;                   /* normalized distance? */
71 < double  ourexp = -1;                    /* output picture exposure */
71 > double  ourexp = -1;                    /* original picture exposure */
72 > int     expadj = 0;                     /* exposure adjustment (f-stops) */
73 > double  rexpadj = 1;                    /* real exposure adjustment */
74  
75   VIEW    theirview = STDVIEW;            /* input view */
76   int     gotview;                        /* got input view? */
# Line 95 | Line 99 | char   *argv[];
99          int     gotvfile = 0;
100          int     doavg = -1;
101          char    *zfile = NULL;
102 +        char    *expcomp = NULL;
103          char    *err;
104          int     i, rval;
105  
# Line 107 | Line 112 | char   *argv[];
112                          continue;
113                  }
114                  switch (argv[i][1]) {
115 +                case 'e':                               /* exposure */
116 +                        check(2,"f");
117 +                        expcomp = argv[++i];
118 +                        break;
119                  case 't':                               /* threshold */
120                          check(2,"f");
121                          zeps = atof(argv[++i]);
# Line 212 | Line 221 | char   *argv[];
221                  goto userr;
222          if (fillsamp == 1)
223                  fillo &= ~F_BACK;
224 +        if (doavg < 0)
225 +                doavg = (argc-i) > 2;
226 +        if (expcomp != NULL)
227 +                if (expcomp[0] == '+' | expcomp[0] == '-') {
228 +                        expadj = atof(expcomp) + (expcomp[0]=='+' ? .5 : -.5);
229 +                        if (doavg)
230 +                                rexpadj = pow(2.0, atof(expcomp));
231 +                        else
232 +                                rexpadj = pow(2.0, (double)expadj);
233 +                } else {
234 +                        if (!isflt(expcomp))
235 +                                goto userr;
236 +                        rexpadj = atof(expcomp);
237 +                        expadj = log(rexpadj)/LOG2 + (rexpadj>1 ? .5 : -.5);
238 +                        if (!doavg)
239 +                                rexpadj = pow(2.0, (double)expadj);
240 +                }
241                                                  /* set view */
242          if ((err = setview(&ourview)) != NULL) {
243                  fprintf(stderr, "%s: %s\n", progname, err);
# Line 219 | Line 245 | char   *argv[];
245          }
246          normaspect(viewaspect(&ourview), &pixaspect, &hresolu, &vresolu);
247                                                  /* allocate frame */
222        if (doavg < 0)
223                doavg = (argc-i) > 2;
248          if (doavg) {
249                  ourspict = (COLOR *)bmalloc(hresolu*vresolu*sizeof(COLOR));
250                  ourweigh = (float *)bmalloc(hresolu*vresolu*sizeof(float));
# Line 256 | Line 280 | char   *argv[];
280                  fprintview(&ourview, stdout);
281                  putc('\n', stdout);
282          }
283 <        if (pixaspect < .99 || pixaspect > 1.01)
283 >        if (pixaspect < .99 | pixaspect > 1.01)
284                  fputaspect(pixaspect, stdout);
285 <        if (ourexp > 0 && (ourexp < .995 || ourexp > 1.005))
285 >        if (ourexp > 0)
286 >                ourexp *= rexpadj;
287 >        else
288 >                ourexp = rexpadj;
289 >        if (ourexp < .995 | ourexp > 1.005)
290                  fputexpos(ourexp, stdout);
291          fputformat(COLRFMT, stdout);
292          putc('\n', stdout);
# Line 271 | Line 299 | char   *argv[];
299          exit(0);
300   userr:
301          fprintf(stderr,
302 <        "Usage: %s [view opts][-t eps][-z zout][-fT][-n] pfile zspec ..\n",
302 >        "Usage: %s [view opts][-t eps][-z zout][-e spec][-a|-q][-fT][-n] pfile zspec ..\n",
303                          progname);
304          exit(1);
305   #undef check
# Line 490 | Line 518 | double z;
518                  l1 = ABS(s1x);
519                  if (p1isy = (ABS(s1y) > l1))
520                          l1 = ABS(s1y);
521 <                if (l1 < 1)
521 >                else if (l1 < 1)
522                          l1 = 1;
523          } else {
524                  l1 = s1x = s1y = 1;
# Line 548 | Line 576 | double z;
576  
577   double
578   movepixel(pos)                          /* reposition image point */
579 < FVECT   pos;
579 > register FVECT  pos;
580   {
553        double  d0, d1;
581          FVECT   pt, tdir, odir;
582 +        double  d;
583          register int    i;
584          
585          if (pos[2] <= 0)                /* empty pixel */
586                  return(0);
559        if (normdist && theirview.type == VT_PER) {     /* adjust distance */
560                d0 = pos[0] + theirview.hoff - .5;
561                d1 = pos[1] + theirview.voff - .5;
562                pos[2] /= sqrt(1. + d0*d0*theirview.hn2 + d1*d1*theirview.vn2);
563        }
587          if (!averaging && hasmatrix) {
588                  pos[0] += theirview.hoff - .5;
589                  pos[1] += theirview.voff - .5;
590                  if (theirview.type == VT_PER) {
591 +                        if (normdist)                   /* adjust distance */
592 +                                pos[2] /= sqrt(1. + pos[0]*pos[0]*theirview.hn2
593 +                                                + pos[1]*pos[1]*theirview.vn2);
594                          pos[0] *= pos[2];
595                          pos[1] *= pos[2];
596                  }
# Line 580 | Line 606 | FVECT  pos;
606          } else {
607                  if (viewray(pt, tdir, &theirview, pos[0], pos[1]) < -FTINY)
608                          return(0);
609 +                if (!normdist && theirview.type == VT_PER)      /* adjust */
610 +                        pos[2] *= sqrt(1. + pos[0]*pos[0]*theirview.hn2
611 +                                        + pos[1]*pos[1]*theirview.vn2);
612                  pt[0] += tdir[0]*pos[2];
613                  pt[1] += tdir[1]*pos[2];
614                  pt[2] += tdir[2]*pos[2];
# Line 596 | Line 625 | FVECT  pos;
625          else
626                  for (i = 0; i < 3; i++)
627                          odir[i] = (pt[i] - ourview.vp[i])/pos[2];
628 <        d0 = DOT(odir,tdir);                    /* compute pixel weight */
629 <        if (d0 <= FTINY)
601 <                return(0);              /* relative angle >= 90 degrees */
602 <        if (d0 >= 1.-1./MAXWT/MAXWT)
628 >        d = DOT(odir,tdir);                     /* compute pixel weight */
629 >        if (d >= 1.-1./MAXWT/MAXWT)
630                  return(MAXWT);          /* clip to maximum weight */
631 <        return(1./sqrt(1.-d0));
631 >        return(1./sqrt(1.-d));
632   }
633  
634  
# Line 682 | Line 709 | int    zfd;
709          }
710          if (yl->max >= numscans(&tresolu))
711                  yl->max = numscans(&tresolu) - 1;
712 +        y -= step;
713          for (x = numscans(&tresolu) - 1; x > y; x--)    /* fill bottom rows */
714                  copystruct(xl+x, xl+y);
715          return(yl->max >= yl->min);
# Line 842 | Line 870 | clipaft()                      /* perform aft clipping as indicated */
870   }
871  
872  
873 < writepicture()                          /* write out picture */
873 > writepicture()                          /* write out picture (alters buffer) */
874   {
875          int     y;
876          register int    x;
# Line 852 | Line 880 | writepicture()                         /* write out picture */
880          for (y = vresolu-1; y >= 0; y--)
881                  if (averaging) {
882                          for (x = 0; x < hresolu; x++) { /* average pixels */
883 <                                d = 1./wscan(y)[x];
883 >                                d = rexpadj/wscan(y)[x];
884                                  scalecolor(sscan(y)[x], d);
885                          }
886                          if (fwritescan(sscan(y), hresolu, stdout) < 0)
887                                  syserror(progname);
888 <                } else if (fwritecolrs(pscan(y), hresolu, stdout) < 0)
889 <                        syserror(progname);
888 >                } else {
889 >                        if (expadj)
890 >                                shiftcolrs(pscan(y), hresolu, expadj);
891 >                        if (fwritecolrs(pscan(y), hresolu, stdout) < 0)
892 >                                syserror(progname);
893 >                }
894   }
895  
896  
897   writedistance(fname)                    /* write out z file */
898   char    *fname;
899   {
900 <        int     donorm = normdist && ourview.type == VT_PER;
900 >        int     donorm = normdist && ourview.type == VT_PER &&
901 >                        !averaging && hasmatrix;
902          int     fd;
903          int     y;
904          float   *zout;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines