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.5 by greg, Fri Oct 11 10:46:57 1996 UTC vs.
Revision 3.9 by greg, Wed Jan 29 13:22:08 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 */
31 + double  fixfrac = 0.;                   /* histogram share due to fixations */
32   RESOLU  inpres;                         /* input picture resolution */
33  
34   COLOR   *fovimg;                        /* foveal (1 degree) averaged image */
35   short   fvxr, fvyr;                     /* foveal image resolution */
36 < int     bwhist[HISTRES];                /* luminance histogram */
37 < long    histot;                         /* total count of histogram */
36 > short   (*fixlst)[2];                   /* fixation history list */
37 > int     nfixations;                     /* number of fixation points */
38 > float   bwhist[HISTRES];                /* luminance histogram */
39 > double  histot;                         /* total count of histogram */
40   double  bwmin, bwmax;                   /* histogram limits */
41   double  bwavg;                          /* mean brightness */
42  
# Line 77 | Line 79 | char   *argv[];
79                  case 'w':
80                          bool(DO_CWEIGHT);
81                          break;
82 +                case 'i':
83 +                        if (i+1 >= argc) goto userr;
84 +                        fixfrac = atof(argv[++i]);
85 +                        if (fixfrac > FTINY) what2do |= DO_FIXHIST;
86 +                        else what2do &= ~DO_FIXHIST;
87 +                        break;
88                  case 'l':
89                          bool(DO_LINEAR);
90                          break;
# Line 113 | Line 121 | char   *argv[];
121                          if (i+1 >= argc) goto userr;
122                          ldmin = atof(argv[++i]);
123                          break;
124 +                case 'm':
125 +                        if (i+1 >= argc) goto userr;
126 +                        if ((mapfp = fopen(argv[++i], "w")) == NULL) {
127 +                                fprintf(stderr,
128 +                                        "%s: cannot open for writing\n",
129 +                                                argv[i]);
130 +                                exit(1);
131 +                        }
132 +                        break;
133                  default:
134                          goto userr;
135                  }
# Line 134 | Line 151 | char   *argv[];
151          Bldmax = Bl(ldmax);
152          if (i >= argc || i+2 < argc)
153                  goto userr;
154 +                                        /* open input file */
155          if ((infp = fopen(infn=argv[i], "r")) == NULL)
156                  syserror(infn);
157 +                                        /* open output file */
158          if (i+2 == argc && freopen(argv[i+1], "w", stdout) == NULL)
159                  syserror(argv[i+1]);
160   #ifdef MSDOS
# Line 144 | Line 163 | char   *argv[];
163   #endif
164          getahead();                     /* load input header */
165          printargs(argc, argv, stdout);  /* add to output header */
166 <        if (outprims != inprims)
166 >        if (mbcalfile == NULL & outprims != stdprims)
167                  fputprims(outprims, stdout);
168 +        getfovimg();                    /* get foveal sample image */
169 +        if (what2do&DO_FIXHIST)         /* get fixation history? */
170 +                getfixations(stdin);
171          mapimage();                     /* map the picture */
172 +        if (mapfp != NULL)              /* write out basic mapping */
173 +                putmapping(mapfp);
174          exit(0);
175   userr:
176 <        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",
176 >        fprintf(stderr, "Usage: %s [-{h|a|v|s|c|l|w}[+-]][-i ffrac][-e ev][-p xr yr xg yg xb yb xw yw|-f mbf.cal][-t Ldmax][-b Ldmin][-m mapfile] inpic [outpic]\n",
177                          progname);
178          exit(1);
179   #undef bool
# Line 236 | Line 260 | mapimage()                             /* map picture and send to stdout */
260   {
261          COLOR   *scan;
262  
263 < #ifdef DEBUG
240 <        fprintf(stderr, "%s: generating histogram...", progname);
241 < #endif
242 <        fovhist();                      /* generate adaptation histogram */
243 < #ifdef DEBUG
244 <        fputs("done\n", stderr);
245 < #endif
263 >        comphist();                     /* generate adaptation histogram */
264          check2do();                     /* modify what2do flags */
265 <        if (what2do&DO_VEIL) {
248 < #ifdef DEBUG
249 <                fprintf(stderr, "%s: computing veiling...", progname);
250 < #endif
265 >        if (what2do&DO_VEIL)
266                  compveil();
267 < #ifdef DEBUG
268 <                fputs("done\n", stderr);
254 < #endif
255 <        }
256 < #ifdef DEBUG
257 <        fprintf(stderr, "%s: computing brightness mapping...", progname);
258 < #endif
259 <        if (!(what2do&DO_LINEAR) && mkbrmap() < 0) {    /* make tone map */
260 <                what2do |= DO_LINEAR;           /* use linear scaling */
261 < #ifdef DEBUG
262 <                fputs("failed!\n", stderr);
263 <        } else
264 <                fputs("done\n", stderr);
265 < #else
266 <        }
267 < #endif
267 >        if (!(what2do&DO_LINEAR) && mkbrmap() < 0)      /* make tone map */
268 >                what2do |= DO_LINEAR;   /* failed! -- use linear scaling */
269          if (what2do&DO_LINEAR) {
270                  if (scalef <= FTINY) {
271                          if (what2do&DO_HSENS)
# Line 274 | Line 275 | mapimage()                             /* map picture and send to stdout */
275                                  scalef = Lb(0.5*(Bldmax+Bldmin)) / Lb(bwavg);
276                          scalef *= WHTEFFICACY/(inpexp*ldmax);
277                  }
277 #ifdef DEBUG
278                fprintf(stderr, "%s: linear scaling factor = %f\n",
279                                progname, scalef);
280 #endif
278                  fputexpos(inpexp*scalef, stdout);       /* record exposure */
279                  if (lumf == cielum) scalef /= WHTEFFICACY;
280          }
281 <        putchar('\n');                  /* complete header */
281 >        fputformat(COLRFMT, stdout);    /* complete header */
282 >        putchar('\n');
283          fputsresolu(&inpres, stdout);   /* resolution doesn't change */
284 <
284 >                                        /* condition our image */
285          for (scan = firstscan(); scan != NULL; scan = nextscan())
286                  if (fwritescan(scan, scanlen(&inpres), stdout) < 0) {
287                          fprintf(stderr, "%s: scanline write error\n",
# Line 293 | Line 291 | mapimage()                             /* map picture and send to stdout */
291   }
292  
293  
294 < double
297 < centprob(x, y)                  /* center-weighting probability function */
298 < int     x, y;
294 > getfovimg()                     /* load foveal sampled image */
295   {
300        double  xr, yr;
301
302        xr = (x+.5)/fvxr - .5;
303        yr = (y+.5)/fvyr - .5;
304        return(1. - xr*xr - yr*yr);     /* radial, == 0.5 at corners */
305 }
306
307
308 fovhist()                       /* create foveal sampled image and histogram */
309 {
296          extern FILE     *popen();
297          char    combuf[128];
312        double  l, b, lwmin, lwmax;
298          FILE    *fp;
299          int     x, y;
300 <
300 >                                                /* compute image size */
301          fvxr = sqrt(ourview.hn2)/FOVDIA + 0.5;
302          if (fvxr < 2) fvxr = 2;
303          fvyr = sqrt(ourview.vn2)/FOVDIA + 0.5;
# Line 324 | Line 309 | fovhist()                      /* create foveal sampled image and histogr
309          }
310          if ((fovimg = (COLOR *)malloc(fvxr*fvyr*sizeof(COLOR))) == NULL)
311                  syserror("malloc");
312 <        sprintf(combuf, "pfilt -1 -b -x %d -y %d %s", fvxr, fvyr, infn);
312 >        sprintf(combuf, "pfilt -1 -b -pa 0 -x %d -y %d %s", fvxr, fvyr, infn);
313          if ((fp = popen(combuf, "r")) == NULL)
314                  syserror("popen");
315          getheader(fp, NULL, NULL);      /* skip header */
# Line 334 | Line 319 | fovhist()                      /* create foveal sampled image and histogr
319                  if (freadscan(fovscan(y), fvxr, fp) < 0)
320                          goto readerr;
321          pclose(fp);
337        lwmin = 1e10;                   /* find extrema */
338        lwmax = 0.;
339        for (y = 0; y < fvyr; y++)
340                for (x = 0; x < fvxr; x++) {
341                        l = plum(fovscan(y)[x]);
342                        if (l < lwmin) lwmin = l;
343                        if (l > lwmax) lwmax = l;
344                }
345        if (lwmin < LMIN) lwmin = LMIN;
346        if (lwmax > LMAX) lwmax = LMAX;
347                                        /* compute histogram */
348        bwmin = Bl(lwmin)*(1. - .01/HISTRES);
349        bwmax = Bl(lwmax)*(1. + .01/HISTRES);
350        bwavg = 0.;
351        for (y = 0; y < fvyr; y++)
352                for (x = 0; x < fvxr; x++) {
353                        if (what2do & DO_CWEIGHT &&
354                                        frandom() > centprob(x,y))
355                                continue;
356                        l = plum(fovscan(y)[x]);
357                        b = Bl(l);
358                        if (b < bwmin) continue;
359                        if (b > bwmax) continue;
360                        bwavg += b;
361                        bwhc(b)++;
362                        histot++;
363                }
364        bwavg /= (double)histot;
322          return;
323   readerr:
324          fprintf(stderr, "%s: error reading from pfilt process in fovimage\n",
# Line 372 | Line 329 | readerr:
329  
330   check2do()              /* check histogram to see what isn't worth doing */
331   {
332 <        long    sum;
332 >        double  sum;
333          double  b, l;
334          register int    i;
335  
336                                          /* check for within display range */
337 <        l = Lb(bwmax)/Lb(bwmin);
381 <        if (l <= ldmax/ldmin)
337 >        if (bwmax - bwmin <= Bldmax - Bldmin)
338                  what2do |= DO_LINEAR;
339                                          /* determine if veiling significant */
340 <        if (l < 100.)                   /* heuristic */
340 >        if (bwmax - bwmin < 4.5)                /* heuristic */
341                  what2do &= ~DO_VEIL;
342  
343          if (!(what2do & (DO_ACUITY|DO_COLOR)))
344                  return;
345                                          /* find 5th percentile */
346 <        sum = histot*0.05 + .5;
346 >        sum = histot*0.05;
347          for (i = 0; i < HISTRES; i++)
348                  if ((sum -= bwhist[i]) <= 0)
349                          break;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines