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

Comparing ray/src/px/pcond.c (file contents):
Revision 3.3 by greg, Sat Oct 5 11:16:51 1996 UTC vs.
Revision 3.8 by greg, Thu Jan 9 13:56:23 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 10 | Line 10 | static char SCCSid[] = "$SunId$ LBL";
10  
11   #include "pcond.h"
12  
13 #include "random.h"
13  
15
14   #define LDMAX           100             /* default max. display luminance */
15   #define LDMINF          0.01            /* default min. display lum. factor */
16  
# Line 26 | Line 24 | char   *progname;                      /* global argv[0] */
24  
25   char    *infn;                          /* input file name */
26   FILE    *infp;                          /* input stream */
27 + FILE    *mapfp = NULL;                  /* tone-mapping function stream */
28   VIEW    ourview = STDVIEW;              /* picture view */
29   int     gotview = 0;                    /* picture has view */
30   double  pixaspect = 1.0;                /* pixel aspect ratio */
# Line 33 | Line 32 | RESOLU inpres;                         /* input picture resolution */
32  
33   COLOR   *fovimg;                        /* foveal (1 degree) averaged image */
34   short   fvxr, fvyr;                     /* foveal image resolution */
35 < int     bwhist[HISTRES];                /* luminance histogram */
36 < long    histot;                         /* total count of histogram */
35 > float   bwhist[HISTRES];                /* luminance histogram */
36 > double  histot;                         /* total count of histogram */
37   double  bwmin, bwmax;                   /* histogram limits */
38   double  bwavg;                          /* mean brightness */
39  
# Line 113 | Line 112 | char   *argv[];
112                          if (i+1 >= argc) goto userr;
113                          ldmin = atof(argv[++i]);
114                          break;
115 +                case 'm':
116 +                        if (i+1 >= argc) goto userr;
117 +                        if ((mapfp = fopen(argv[++i], "w")) == NULL) {
118 +                                fprintf(stderr,
119 +                                        "%s: cannot open for writing\n",
120 +                                                argv[i]);
121 +                                exit(1);
122 +                        }
123 +                        break;
124                  default:
125                          goto userr;
126                  }
# Line 147 | Line 155 | char   *argv[];
155          if (outprims != inprims)
156                  fputprims(outprims, stdout);
157          mapimage();                     /* map the picture */
158 +        if (mapfp != NULL)              /* write out basic mapping */
159 +                putmapping(mapfp);
160          exit(0);
161   userr:
162 <        fprintf(stderr, "Usage: %s [-{h|a|v|s|c|l|w}[+-]][-e ev][-p xr yr xg yg xb yb xw yw|-f mbf.cal][-t Ldmax][-b Ldmin] inpic [outpic]\n",
162 >        fprintf(stderr, "Usage: %s [-{h|a|v|s|c|l|w}[+-]][-e ev][-p xr yr xg yg xb yb xw yw|-f mbf.cal][-t Ldmax][-b Ldmin][-m mapfile] inpic [outpic]\n",
163                          progname);
164          exit(1);
165   #undef bool
# Line 239 | Line 249 | mapimage()                             /* map picture and send to stdout */
249   #ifdef DEBUG
250          fprintf(stderr, "%s: generating histogram...", progname);
251   #endif
252 <        fovhist();                      /* generate adaptation histogram */
252 >        getfovimg();                    /* get foveal sample image */
253 >        comphist();                     /* generate adaptation histogram */
254   #ifdef DEBUG
255          fputs("done\n", stderr);
256   #endif
# Line 278 | Line 289 | mapimage()                             /* map picture and send to stdout */
289                  fprintf(stderr, "%s: linear scaling factor = %f\n",
290                                  progname, scalef);
291   #endif
292 <                if (scalef < 0.99 | scalef > 1.01)
282 <                        fputexpos(scalef, stdout);      /* write in header */
292 >                fputexpos(inpexp*scalef, stdout);       /* record exposure */
293                  if (lumf == cielum) scalef /= WHTEFFICACY;
294          }
295          putchar('\n');                  /* complete header */
# Line 298 | Line 308 | double
308   centprob(x, y)                  /* center-weighting probability function */
309   int     x, y;
310   {
311 <        double  xr, yr;
312 <
313 <        xr = (x+.5)/fvxr - .5;
314 <        yr = (y+.5)/fvyr - .5;
315 <        return(1. - xr*xr - yr*yr);     /* radial, == 0.5 at corners */
311 >        double  xr, yr, p;
312 >                                /* paraboloid, 0 at 90 degrees from center */
313 >        xr = (x - .5*(fvxr-1))/90.;     /* 180 degree fisheye has fv?r == 90 */
314 >        yr = (y - .5*(fvyr-1))/90.;
315 >        p = 1. - xr*xr - yr*yr;
316 >        return(p < 0. ? 0. : p);
317   }
318  
319  
320 < fovhist()                       /* create foveal sampled image and histogram */
320 > getfovimg()                     /* load foveal sampled image */
321   {
322          extern FILE     *popen();
323          char    combuf[128];
313        double  l, b, lwmin, lwmax;
324          FILE    *fp;
325          int     x, y;
326 <
326 >                                                /* compute image size */
327          fvxr = sqrt(ourview.hn2)/FOVDIA + 0.5;
328          if (fvxr < 2) fvxr = 2;
329          fvyr = sqrt(ourview.vn2)/FOVDIA + 0.5;
# Line 335 | Line 345 | fovhist()                      /* create foveal sampled image and histogr
345                  if (freadscan(fovscan(y), fvxr, fp) < 0)
346                          goto readerr;
347          pclose(fp);
348 +        return;
349 + readerr:
350 +        fprintf(stderr, "%s: error reading from pfilt process in fovimage\n",
351 +                        progname);
352 +        exit(1);
353 + }
354 +
355 +
356 + comphist()                      /* create foveal sampled image and histogram */
357 + {
358 +        double  l, b, lwmin, lwmax;
359 +        register int    x, y;
360 +
361          lwmin = 1e10;                   /* find extrema */
362          lwmax = 0.;
363          for (y = 0; y < fvyr; y++)
# Line 343 | Line 366 | fovhist()                      /* create foveal sampled image and histogr
366                          if (l < lwmin) lwmin = l;
367                          if (l > lwmax) lwmax = l;
368                  }
369 +        lwmin -= FTINY;
370 +        lwmax += FTINY;
371          if (lwmin < LMIN) lwmin = LMIN;
372          if (lwmax > LMAX) lwmax = LMAX;
373                                          /* compute histogram */
374 <        bwmin = Bl(lwmin)*(1. - .01/HISTRES);
375 <        bwmax = Bl(lwmax)*(1. + .01/HISTRES);
374 >        bwmin = Bl(lwmin);
375 >        bwmax = Bl(lwmax);
376          bwavg = 0.;
377          for (y = 0; y < fvyr; y++)
378                  for (x = 0; x < fvxr; x++) {
354                        if (what2do & DO_CWEIGHT &&
355                                        frandom() > centprob(x,y))
356                                continue;
379                          l = plum(fovscan(y)[x]);
380 +                        if (l < lwmin) continue;
381 +                        if (l > lwmax) continue;
382                          b = Bl(l);
359                        if (b < bwmin) continue;
360                        if (b > bwmax) continue;
383                          bwavg += b;
384 <                        bwhc(b)++;
385 <                        histot++;
384 >                        l = what2do&DO_CWEIGHT ? centprob(x,y) : 1.;
385 >                        bwhist[bwhi(b)] += l;
386 >                        histot += l;
387                  }
388 <        bwavg /= (double)histot;
366 <        return;
367 < readerr:
368 <        fprintf(stderr, "%s: error reading from pfilt process in fovimage\n",
369 <                        progname);
370 <        exit(1);
388 >        bwavg /= histot;
389   }
390  
391  
392   check2do()              /* check histogram to see what isn't worth doing */
393   {
394 <        long    sum;
394 >        double  sum;
395          double  b, l;
396          register int    i;
397  
# Line 388 | Line 406 | check2do()             /* check histogram to see what isn't worth
406          if (!(what2do & (DO_ACUITY|DO_COLOR)))
407                  return;
408                                          /* find 5th percentile */
409 <        sum = histot*0.05 + .5;
409 >        sum = histot*0.05;
410          for (i = 0; i < HISTRES; i++)
411                  if ((sum -= bwhist[i]) <= 0)
412                          break;
# Line 397 | Line 415 | check2do()             /* check histogram to see what isn't worth
415                                          /* determine if acuity adj. useful */
416          if (what2do&DO_ACUITY &&
417                          hacuity(l) >= (inpres.xr/sqrt(ourview.hn2) +
418 <                        inpres.yr/sqrt(ourview.vn2))/(2.*180./PI*2.))
418 >                        inpres.yr/sqrt(ourview.vn2))/(2.*180./PI))
419                  what2do &= ~DO_ACUITY;
420                                          /* color sensitivity loss? */
421 <        if (l >= 6.0)
421 >        if (l >= TopMesopic)
422                  what2do &= ~DO_COLOR;
423   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines