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.8 by greg, Thu Jan 9 13:56:23 1997 UTC vs.
Revision 3.9 by greg, Wed Jan 29 13:22:08 1997 UTC

# Line 28 | Line 28 | 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 + 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 */
# Line 76 | 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 142 | 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 152 | 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][-m mapfile] 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 246 | Line 260 | mapimage()                             /* map picture and send to stdout */
260   {
261          COLOR   *scan;
262  
249 #ifdef DEBUG
250        fprintf(stderr, "%s: generating histogram...", progname);
251 #endif
252        getfovimg();                    /* get foveal sample image */
263          comphist();                     /* generate adaptation histogram */
254 #ifdef DEBUG
255        fputs("done\n", stderr);
256 #endif
264          check2do();                     /* modify what2do flags */
265 <        if (what2do&DO_VEIL) {
259 < #ifdef DEBUG
260 <                fprintf(stderr, "%s: computing veiling...", progname);
261 < #endif
265 >        if (what2do&DO_VEIL)
266                  compveil();
267 < #ifdef DEBUG
268 <                fputs("done\n", stderr);
265 < #endif
266 <        }
267 < #ifdef DEBUG
268 <        fprintf(stderr, "%s: computing brightness mapping...", progname);
269 < #endif
270 <        if (!(what2do&DO_LINEAR) && mkbrmap() < 0) {    /* make tone map */
271 <                what2do |= DO_LINEAR;           /* use linear scaling */
272 < #ifdef DEBUG
273 <                fputs("failed!\n", stderr);
274 <        } else
275 <                fputs("done\n", stderr);
276 < #else
277 <        }
278 < #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 285 | Line 275 | mapimage()                             /* map picture and send to stdout */
275                                  scalef = Lb(0.5*(Bldmax+Bldmin)) / Lb(bwavg);
276                          scalef *= WHTEFFICACY/(inpexp*ldmax);
277                  }
288 #ifdef DEBUG
289                fprintf(stderr, "%s: linear scaling factor = %f\n",
290                                progname, scalef);
291 #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 304 | Line 291 | mapimage()                             /* map picture and send to stdout */
291   }
292  
293  
307 double
308 centprob(x, y)                  /* center-weighting probability function */
309 int     x, y;
310 {
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
294   getfovimg()                     /* load foveal sampled image */
295   {
296          extern FILE     *popen();
# Line 335 | Line 309 | getfovimg()                    /* load foveal sampled image */
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 353 | Line 327 | readerr:
327   }
328  
329  
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++)
364                for (x = 0; x < fvxr; x++) {
365                        l = plum(fovscan(y)[x]);
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);
375        bwmax = Bl(lwmax);
376        bwavg = 0.;
377        for (y = 0; y < fvyr; y++)
378                for (x = 0; x < fvxr; x++) {
379                        l = plum(fovscan(y)[x]);
380                        if (l < lwmin) continue;
381                        if (l > lwmax) continue;
382                        b = Bl(l);
383                        bwavg += b;
384                        l = what2do&DO_CWEIGHT ? centprob(x,y) : 1.;
385                        bwhist[bwhi(b)] += l;
386                        histot += l;
387                }
388        bwavg /= histot;
389 }
390
391
330   check2do()              /* check histogram to see what isn't worth doing */
331   {
332          double  sum;
# Line 396 | Line 334 | check2do()             /* check histogram to see what isn't worth
334          register int    i;
335  
336                                          /* check for within display range */
337 <        l = Lb(bwmax)/Lb(bwmin);
400 <        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)))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines