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

Comparing ray/src/px/pcond4.c (file contents):
Revision 3.8 by greg, Tue Oct 8 12:48:00 1996 UTC vs.
Revision 3.14 by greg, Tue Jan 28 16:31:17 1997 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1996 Regents of the University of California */
1 > /* Copyright (c) 1997 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 14 | Line 14 | static char SCCSid[] = "$SunId$ LBL";
14  
15   #define VADAPT          0.08            /* fraction of adaptation from veil */
16  
17 < extern COLOR    *fovimg;                /* foveal (1 degree) averaged image */
18 < extern short    fvxr, fvyr;             /* foveal image resolution */
17 > static COLOR    *veilimg = NULL;        /* veiling image */
18  
20 #define fovscan(y)      (fovimg+(y)*fvxr)
21
22 static COLOR    *veilimg;               /* veiling image */
23
19   #define veilscan(y)     (veilimg+(y)*fvxr)
20  
21   static float    (*raydir)[3] = NULL;    /* ray direction for each pixel */
# Line 83 | Line 78 | compveil()                             /* compute veiling image */
78          COLOR   ctmp, vsum;
79          int     px, py;
80          register int    x, y;
81 +
82 +        if (veilimg != NULL)            /* already done? */
83 +                return;
84                                          /* compute ray directions */
85          compraydir();
86                                          /* compute veil image */
# Line 100 | Line 98 | compveil()                             /* compute veiling image */
98                                                          rdirscan(y)[x]);
99                                          if (t2 <= FTINY) continue;
100                                          /*      use approximation instead
101 <                                        t2 = acos(t2);
102 <                                        t2 = 1./(t2*t2);
101 >                                        t3 = acos(t2);
102 >                                        t2 = t2/(t3*t3);
103                                          */
104 <                                        t2 = .5 / (1. - t2);
104 >                                        t2 *= .5 / (1. - t2);
105                                          copycolor(ctmp, fovscan(y)[x]);
106                                          scalecolor(ctmp, t2);
107                                          addcolor(vsum, ctmp);
# Line 113 | Line 111 | compveil()                             /* compute veiling image */
111                          scalecolor(vsum, VADAPT/t2sum);
112                          copycolor(veilscan(py)[px], vsum);
113                  }
114 +                                        /* modify FOV sample image */
115 +        for (y = 0; y < fvyr; y++)
116 +                for (x = 0; x < fvxr; x++) {
117 +                        scalecolor(fovscan(y)[x], 1.-VADAPT);
118 +                        addcolor(fovscan(y)[x], veilscan(y)[x]);
119 +                }
120 +        comphist();                     /* recompute histogram */
121   }
122  
123  
# Line 166 | Line 171 | float  *inpacuD;               /* input acuity data (cycles/degree)
171   double
172   hacuity(La)                     /* return visual acuity in cycles/degree */
173   double  La;
174 < {                               /* data due to S. Shaler (we should fit it!) */
175 < #define NPOINTS 20
176 <        static float    l10lum[NPOINTS] = {
172 <                -3.10503,-2.66403,-2.37703,-2.09303,-1.64403,-1.35803,
173 <                -1.07403,-0.67203,-0.38503,-0.10103,0.29397,0.58097,0.86497,
174 <                1.25697,1.54397,1.82797,2.27597,2.56297,2.84697,3.24897
175 <        };
176 <        static float    resfreq[NPOINTS] = {
177 <                2.09,3.28,3.79,4.39,6.11,8.83,10.94,18.66,23.88,31.05,37.42,
178 <                37.68,41.60,43.16,45.30,47.00,48.43,48.32,51.06,51.09
179 <        };
180 <        double  l10La;
181 <        register int    i;
182 <                                        /* check limits */
183 <        if (La <= 7.85e-4)
184 <                return(resfreq[0]);
185 <        if (La >= 1.78e3)
186 <                return(resfreq[NPOINTS-1]);
187 <                                        /* interpolate data */
188 <        l10La = log10(La);
189 <        for (i = 0; i < NPOINTS-2 && l10lum[i+1] <= l10La; i++)
190 <                ;
191 <        return( ( (l10lum[i+1] - l10La)*resfreq[i] +
192 <                        (l10La - l10lum[i])*resfreq[i+1] ) /
193 <                        (l10lum[i+1] - l10lum[i]) );
194 < #undef NPOINTS
174 > {
175 >                                        /* functional fit */
176 >        return(17.25*atan(1.4*log10(La) + 0.35) + 25.72);
177   }
178  
179  
# Line 241 | Line 223 | int    y;
223          register int    x;
224                                          /* compute foveal y position */
225          iy = dy = (y+.5)/numscans(&inpres)*fvyr - .5;
226 <        if (iy >= fvyr-1) iy--;
226 >        while (iy >= fvyr-1) iy--;
227          dy -= (double)iy;
228          for (x = 0; x < scanlen(&inpres); x++) {
229                                          /* compute foveal x position */
230                  ix = dx = (x+.5)/scanlen(&inpres)*fvxr - .5;
231 <                if (ix >= fvxr-1) ix--;
231 >                while (ix >= fvxr-1) ix--;
232                  dx -= (double)ix;
233                                          /* interpolate sample rate */
234                  sr = (1.-dy)*((1.-dx)*tsampr(ix,iy) + dx*tsampr(ix+1,iy)) +
# Line 302 | Line 284 | SCANBAR        *sb;
284          dy -= (double)iy;
285                                          /* get scanlines */
286          sl0 = getascan(sb, iy);
287 <        if (sl0 == NULL) {
288 <                fprintf(stderr, "%s: internal - cannot backspace in ascanval\n",
289 <                                progname);
290 <                exit(1);
309 <        }
287 > #ifdef DEBUG
288 >        if (sl0 == NULL)
289 >                error(INTERNAL, "cannot backspace in ascanval");
290 > #endif
291          sl1 = getascan(sb, iy+1);
292                                          /* 2D linear interpolation */
293          copycolor(col, sl0[ix]);
# Line 322 | Line 303 | SCANBAR        *sb;
303          scalecolor(col, 1.-dy);
304          scalecolor(c1y, dy);
305          addcolor(col, c1y);
306 +        for (ix = 0; ix < 3; ix++)      /* make sure no negative */
307 +                if (colval(col,ix) < 0.)
308 +                        colval(col,ix) = 0.;
309   }
310  
311  
312   SCANBAR *
313 < sballoc(sr, ns, sl)             /* allocate scanbar */
314 < int     sr;             /* sampling rate */
313 > sballoc(se, ns, sl)             /* allocate scanbar */
314 > int     se;             /* sampling rate exponent */
315   int     ns;             /* number of scanlines */
316   int     sl;             /* original scanline length */
317   {
318          SCANBAR *sbarr;
319          register SCANBAR        *sb;
320  
321 <        sbarr = sb = (SCANBAR *)malloc((sr+1)*sizeof(SCANBAR));
321 >        sbarr = sb = (SCANBAR *)malloc((se+1)*sizeof(SCANBAR));
322          if (sb == NULL)
323                  syserror("malloc");
324          do {
325 <                sb->sdata = (COLOR *)malloc((sl>>sr)*ns*sizeof(COLOR));
325 >                sb->sampe = se;
326 >                sb->len = sl>>se;
327 >                sb->nscans = ns;
328 >                sb->sdata = (COLOR *)malloc(sb->len*ns*sizeof(COLOR));
329                  if (sb->sdata == NULL)
330                          syserror("malloc");
344                sb->sampe = sr;
345                sb->nscans = ns;
346                sb->len = sl>>sr;
331                  sb->nread = 0;
332                  ns <<= 1;
333                  sb++;
334 <        } while (--sr >= 0);
334 >        } while (--se >= 0);
335          return(sbarr);
336   }
337  
# Line 376 | Line 360 | initacuity()                   /* initialize variable acuity sampling
360                          }
361                          fcross(cp, diffx, diffy);
362                          omega = 0.5 * sqrt(DOT(cp,cp));
363 <                        if (omega <= FTINY)
363 >                        if (omega <= FTINY*FTINY)
364                                  tsampr(x,y) = 1.;
365                          else if ((tsampr(x,y) = PI/180. / sqrt(omega) /
366                                          hacuity(plum(fovscan(y)[x]))) > maxsr)
# Line 388 | Line 372 | initacuity()                   /* initialize variable acuity sampling
372                  tsampr(x,fvyr-1) = tsampr(x,fvyr-2);
373          }
374          for (y = 0; y < fvyr; y++) {
375 <                tsampr(y,0) = tsampr(y,1);
376 <                tsampr(y,fvxr-1) = tsampr(y,fvxr-2);
375 >                tsampr(0,y) = tsampr(1,y);
376 >                tsampr(fvxr-1,y) = tsampr(fvxr-2,y);
377          }
378                                          /* initialize with next power of two */
379          rootbar = sballoc((int)(log(maxsr)/log(2.))+1, 2, scanlen(&inpres));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines