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.22 by greg, Tue Dec 27 18:04:29 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 + #define usematrix       (hasmatrix & !averaging)
31 + #define zisnorm         (!usematrix | ourview.type != VT_PER)
32  
33   #define MAXWT           1000.           /* maximum pixel weight (averaging) */
34  
# Line 65 | Line 69 | int    (*fillfunc)() = backfill;       /* selected fill functio
69   COLR    backcolr = BLKCOLR;             /* background color */
70   COLOR   backcolor = BLKCOLOR;           /* background color (float) */
71   double  backz = 0.0;                    /* background z value */
72 < int     normdist = 1;                   /* normalized distance? */
73 < double  ourexp = -1;                    /* output picture exposure */
72 > int     normdist = 1;                   /* i/o normalized distance? */
73 > double  ourexp = -1;                    /* original picture exposure */
74 > int     expadj = 0;                     /* exposure adjustment (f-stops) */
75 > double  rexpadj = 1;                    /* real exposure adjustment */
76  
77   VIEW    theirview = STDVIEW;            /* input view */
78   int     gotview;                        /* got input view? */
# Line 95 | Line 101 | char   *argv[];
101          int     gotvfile = 0;
102          int     doavg = -1;
103          char    *zfile = NULL;
104 +        char    *expcomp = NULL;
105          char    *err;
106          int     i, rval;
107  
# Line 107 | Line 114 | char   *argv[];
114                          continue;
115                  }
116                  switch (argv[i][1]) {
117 +                case 'e':                               /* exposure */
118 +                        check(2,"f");
119 +                        expcomp = argv[++i];
120 +                        break;
121                  case 't':                               /* threshold */
122                          check(2,"f");
123                          zeps = atof(argv[++i]);
# Line 214 | Line 225 | char   *argv[];
225                  fillo &= ~F_BACK;
226          if (doavg < 0)
227                  doavg = (argc-i) > 2;
228 +        if (expcomp != NULL)
229 +                if (expcomp[0] == '+' | expcomp[0] == '-') {
230 +                        expadj = atof(expcomp) + (expcomp[0]=='+' ? .5 : -.5);
231 +                        if (doavg)
232 +                                rexpadj = pow(2.0, atof(expcomp));
233 +                        else
234 +                                rexpadj = pow(2.0, (double)expadj);
235 +                } else {
236 +                        if (!isflt(expcomp))
237 +                                goto userr;
238 +                        rexpadj = atof(expcomp);
239 +                        expadj = log(rexpadj)/LOG2 + (rexpadj>1 ? .5 : -.5);
240 +                        if (!doavg)
241 +                                rexpadj = pow(2.0, (double)expadj);
242 +                }
243                                                  /* set view */
244          if ((err = setview(&ourview)) != NULL) {
245                  fprintf(stderr, "%s: %s\n", progname, err);
# Line 256 | Line 282 | char   *argv[];
282                  fprintview(&ourview, stdout);
283                  putc('\n', stdout);
284          }
285 <        if (pixaspect < .99 || pixaspect > 1.01)
285 >        if (pixaspect < .99 | pixaspect > 1.01)
286                  fputaspect(pixaspect, stdout);
287 <        if (ourexp > 0 && (ourexp < .995 || ourexp > 1.005))
287 >        if (ourexp > 0)
288 >                ourexp *= rexpadj;
289 >        else
290 >                ourexp = rexpadj;
291 >        if (ourexp < .995 | ourexp > 1.005)
292                  fputexpos(ourexp, stdout);
293          fputformat(COLRFMT, stdout);
294          putc('\n', stdout);
# Line 271 | Line 301 | char   *argv[];
301          exit(0);
302   userr:
303          fprintf(stderr,
304 <        "Usage: %s [view opts][-t eps][-z zout][-fT][-n] pfile zspec ..\n",
304 >        "Usage: %s [view opts][-t eps][-z zout][-e spec][-a|-q][-fT][-n] pfile zspec ..\n",
305                          progname);
306          exit(1);
307   #undef check
# Line 556 | Line 586 | register FVECT pos;
586          
587          if (pos[2] <= 0)                /* empty pixel */
588                  return(0);
589 <        if (!averaging && hasmatrix) {
589 >        if (usematrix) {
590                  pos[0] += theirview.hoff - .5;
591                  pos[1] += theirview.voff - .5;
592                  if (theirview.type == VT_PER) {
# Line 578 | Line 608 | register FVECT pos;
608          } else {
609                  if (viewray(pt, tdir, &theirview, pos[0], pos[1]) < -FTINY)
610                          return(0);
611 <                if (!normdist && theirview.type == VT_PER)      /* adjust */
611 >                if (!normdist & theirview.type == VT_PER)       /* adjust */
612                          pos[2] *= sqrt(1. + pos[0]*pos[0]*theirview.hn2
613                                          + pos[1]*pos[1]*theirview.vn2);
614                  pt[0] += tdir[0]*pos[2];
# Line 811 | Line 841 | int    (*fill)();
841   clipaft()                       /* perform aft clipping as indicated */
842   {
843          register int    x, y;
844 +        int     adjtest = ourview.type == VT_PER & zisnorm;
845          double  tstdist;
846          double  yzn2, vx;
847  
# Line 818 | Line 849 | clipaft()                      /* perform aft clipping as indicated */
849                  return;
850          tstdist = ourview.vaft - ourview.vfore;
851          for (y = 0; y < vresolu; y++) {
852 <                if (ourview.type == VT_PER) {           /* adjust distance */
852 >                if (adjtest) {                          /* adjust test */
853                          yzn2 = (y+.5)/vresolu + ourview.voff - .5;
854                          yzn2 = 1. + yzn2*yzn2*ourview.vn2;
855                          tstdist = (ourview.vaft - ourview.vfore)*sqrt(yzn2);
856                  }
857                  for (x = 0; x < hresolu; x++)
858                          if (zscan(y)[x] > tstdist) {
859 <                                if (ourview.type == VT_PER) {
859 >                                if (adjtest) {
860                                          vx = (x+.5)/hresolu + ourview.hoff - .5;
861                                          if (zscan(y)[x] <= (ourview.vaft -
862                                                          ourview.vfore) *
# Line 842 | Line 873 | clipaft()                      /* perform aft clipping as indicated */
873   }
874  
875  
876 < writepicture()                          /* write out picture */
876 > writepicture()                          /* write out picture (alters buffer) */
877   {
878          int     y;
879          register int    x;
# Line 852 | Line 883 | writepicture()                         /* write out picture */
883          for (y = vresolu-1; y >= 0; y--)
884                  if (averaging) {
885                          for (x = 0; x < hresolu; x++) { /* average pixels */
886 <                                d = 1./wscan(y)[x];
886 >                                d = rexpadj/wscan(y)[x];
887                                  scalecolor(sscan(y)[x], d);
857                                wscan(y)[x] = 1;
888                          }
889                          if (fwritescan(sscan(y), hresolu, stdout) < 0)
890                                  syserror(progname);
891 <                } else if (fwritecolrs(pscan(y), hresolu, stdout) < 0)
892 <                        syserror(progname);
891 >                } else {
892 >                        if (expadj)
893 >                                shiftcolrs(pscan(y), hresolu, expadj);
894 >                        if (fwritecolrs(pscan(y), hresolu, stdout) < 0)
895 >                                syserror(progname);
896 >                }
897   }
898  
899  
900 < writedistance(fname)                    /* write out z file */
900 > writedistance(fname)                    /* write out z file (alters buffer) */
901   char    *fname;
902   {
903 <        int     donorm = normdist && ourview.type == VT_PER;
903 >        int     donorm = normdist & !zisnorm ? 1 :
904 >                        ourview.type == VT_PER & !normdist & zisnorm ? -1 : 0;
905          int     fd;
906          int     y;
872        float   *zout;
907  
908          if ((fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1)
909                  syserror(fname);
876        if (donorm
877        && (zout = (float *)malloc(hresolu*sizeof(float))) == NULL)
878                syserror(progname);
910          for (y = vresolu-1; y >= 0; y--) {
911                  if (donorm) {
912 <                        double  vx, yzn2;
912 >                        double  vx, yzn2, d;
913                          register int    x;
914                          yzn2 = (y+.5)/vresolu + ourview.voff - .5;
915                          yzn2 = 1. + yzn2*yzn2*ourview.vn2;
916                          for (x = 0; x < hresolu; x++) {
917                                  vx = (x+.5)/hresolu + ourview.hoff - .5;
918 <                                zout[x] = zscan(y)[x]
919 <                                        * sqrt(vx*vx*ourview.hn2 + yzn2);
918 >                                d = sqrt(vx*vx*ourview.hn2 + yzn2);
919 >                                if (donorm > 0)
920 >                                        zscan(y)[x] *= d;
921 >                                else
922 >                                        zscan(y)[x] /= d;
923                          }
924 <                } else
925 <                        zout = zscan(y);
892 <                if (write(fd, (char *)zout, hresolu*sizeof(float))
924 >                }
925 >                if (write(fd, (char *)zscan(y), hresolu*sizeof(float))
926                                  < hresolu*sizeof(float))
927                          syserror(fname);
928          }
896        if (donorm)
897                free((char *)zout);
929          close(fd);
930   }
931  
# Line 979 | Line 1010 | clearqueue()                           /* process queue */
1010          float   fbuf[6*(PACKSIZ+1)];
1011          register float  *fbp;
1012          register int    i;
1013 +        double  vx, vy;
1014  
1015          if (queuesiz == 0)
1016                  return;
# Line 1013 | Line 1045 | clearqueue()                           /* process queue */
1045                  } else
1046                          setcolr(pscan(queue[i][1])[queue[i][0]],
1047                                          fbp[0], fbp[1], fbp[2]);
1048 <                zscan(queue[i][1])[queue[i][0]] = fbp[3];
1048 >                if (zisnorm)
1049 >                        zscan(queue[i][1])[queue[i][0]] = fbp[3];
1050 >                else {
1051 >                        vx = (queue[i][0]+.5)/hresolu + ourview.hoff - .5;
1052 >                        vy = (queue[i][1]+.5)/vresolu + ourview.voff - .5;
1053 >                        zscan(queue[i][1])[queue[i][0]] = fbp[3] / sqrt(1. +
1054 >                                        vx*vx*ourview.hn2 + vy*vy*ourview.vn2);
1055 >                }
1056                  fbp += 4;
1057          }
1058          queuesiz = 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines