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.6 by greg, Tue Jan 7 14:48:50 1997 UTC vs.
Revision 3.10 by greg, Wed Feb 5 16:08:14 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 30 | 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 < 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 78 | 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 104 | Line 111 | char   *argv[];
111                          if (i+1 >= argc) goto userr;
112                          mbcalfile = argv[++i];
113                          break;
114 +                case 'm':
115 +                        if (i+1 >= argc) goto userr;
116 +                        cwarpfile = argv[++i];
117 +                        break;
118                  case 't':
119                          if (i+1 >= argc) goto userr;
120                          ldmax = atof(argv[++i]);
# Line 114 | Line 125 | char   *argv[];
125                          if (i+1 >= argc) goto userr;
126                          ldmin = atof(argv[++i]);
127                          break;
128 <                case 'm':
128 >                case 'd':
129                          if (i+1 >= argc) goto userr;
130                          if ((mapfp = fopen(argv[++i], "w")) == NULL) {
131                                  fprintf(stderr,
# Line 126 | Line 137 | char   *argv[];
137                  default:
138                          goto userr;
139                  }
140 <        if (mbcalfile != NULL & outprims != stdprims) {
141 <                fprintf(stderr, "%s: only one of -p or -f option supported\n",
140 >        if ((mbcalfile != NULL) + (cwarpfile != NULL) +
141 >                        (outprims != stdprims) > 1) {
142 >                fprintf(stderr,
143 >                        "%s: only one of -p, -m or -f option supported\n",
144                                  progname);
145                  exit(1);
146          }
# Line 144 | Line 157 | char   *argv[];
157          Bldmax = Bl(ldmax);
158          if (i >= argc || i+2 < argc)
159                  goto userr;
160 +                                        /* open input file */
161          if ((infp = fopen(infn=argv[i], "r")) == NULL)
162                  syserror(infn);
163 +                                        /* open output file */
164          if (i+2 == argc && freopen(argv[i+1], "w", stdout) == NULL)
165                  syserror(argv[i+1]);
166   #ifdef MSDOS
# Line 154 | Line 169 | char   *argv[];
169   #endif
170          getahead();                     /* load input header */
171          printargs(argc, argv, stdout);  /* add to output header */
172 <        if (outprims != inprims)
172 >        if (mbcalfile == NULL & outprims != stdprims)
173                  fputprims(outprims, stdout);
174 +        getfovimg();                    /* get foveal sample image */
175 +        if (what2do&DO_FIXHIST)         /* get fixation history? */
176 +                getfixations(stdin);
177          mapimage();                     /* map the picture */
178          if (mapfp != NULL)              /* write out basic mapping */
179                  putmapping(mapfp);
180          exit(0);
181   userr:
182 <        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",
182 >        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|-m rgb.cwp][-t Ldmax][-b Ldmin][-d mapfile] inpic [outpic]\n",
183                          progname);
184          exit(1);
185   #undef bool
# Line 248 | Line 266 | mapimage()                             /* map picture and send to stdout */
266   {
267          COLOR   *scan;
268  
269 < #ifdef DEBUG
252 <        fprintf(stderr, "%s: generating histogram...", progname);
253 < #endif
254 <        fovhist();                      /* generate adaptation histogram */
255 < #ifdef DEBUG
256 <        fputs("done\n", stderr);
257 < #endif
269 >        comphist();                     /* generate adaptation histogram */
270          check2do();                     /* modify what2do flags */
271 <        if (what2do&DO_VEIL) {
260 < #ifdef DEBUG
261 <                fprintf(stderr, "%s: computing veiling...", progname);
262 < #endif
271 >        if (what2do&DO_VEIL)
272                  compveil();
273 < #ifdef DEBUG
274 <                fputs("done\n", stderr);
266 < #endif
267 <        }
268 < #ifdef DEBUG
269 <        fprintf(stderr, "%s: computing brightness mapping...", progname);
270 < #endif
271 <        if (!(what2do&DO_LINEAR) && mkbrmap() < 0) {    /* make tone map */
272 <                what2do |= DO_LINEAR;           /* use linear scaling */
273 < #ifdef DEBUG
274 <                fputs("failed!\n", stderr);
275 <        } else
276 <                fputs("done\n", stderr);
277 < #else
278 <        }
279 < #endif
273 >        if (!(what2do&DO_LINEAR) && mkbrmap() < 0)      /* make tone map */
274 >                what2do |= DO_LINEAR;   /* failed! -- use linear scaling */
275          if (what2do&DO_LINEAR) {
276                  if (scalef <= FTINY) {
277                          if (what2do&DO_HSENS)
# Line 286 | Line 281 | mapimage()                             /* map picture and send to stdout */
281                                  scalef = Lb(0.5*(Bldmax+Bldmin)) / Lb(bwavg);
282                          scalef *= WHTEFFICACY/(inpexp*ldmax);
283                  }
289 #ifdef DEBUG
290                fprintf(stderr, "%s: linear scaling factor = %f\n",
291                                progname, scalef);
292 #endif
284                  fputexpos(inpexp*scalef, stdout);       /* record exposure */
285                  if (lumf == cielum) scalef /= WHTEFFICACY;
286          }
287 <        putchar('\n');                  /* complete header */
287 >        fputformat(COLRFMT, stdout);    /* complete header */
288 >        putchar('\n');
289          fputsresolu(&inpres, stdout);   /* resolution doesn't change */
290 <
290 >                                        /* condition our image */
291          for (scan = firstscan(); scan != NULL; scan = nextscan())
292                  if (fwritescan(scan, scanlen(&inpres), stdout) < 0) {
293                          fprintf(stderr, "%s: scanline write error\n",
# Line 305 | Line 297 | mapimage()                             /* map picture and send to stdout */
297   }
298  
299  
300 < double
309 < centprob(x, y)                  /* center-weighting probability function */
310 < int     x, y;
300 > getfovimg()                     /* load foveal sampled image */
301   {
312        double  xr, yr;
313
314        xr = (x+.5)/fvxr - .5;
315        yr = (y+.5)/fvyr - .5;
316        return(1. - xr*xr - yr*yr);     /* radial, == 0.5 at corners */
317 }
318
319
320 fovhist()                       /* create foveal sampled image and histogram */
321 {
302          extern FILE     *popen();
303          char    combuf[128];
324        double  l, b, lwmin, lwmax;
304          FILE    *fp;
305          int     x, y;
306 <
306 >                                                /* compute image size */
307          fvxr = sqrt(ourview.hn2)/FOVDIA + 0.5;
308          if (fvxr < 2) fvxr = 2;
309          fvyr = sqrt(ourview.vn2)/FOVDIA + 0.5;
# Line 336 | Line 315 | fovhist()                      /* create foveal sampled image and histogr
315          }
316          if ((fovimg = (COLOR *)malloc(fvxr*fvyr*sizeof(COLOR))) == NULL)
317                  syserror("malloc");
318 <        sprintf(combuf, "pfilt -1 -b -x %d -y %d %s", fvxr, fvyr, infn);
318 >        sprintf(combuf, "pfilt -1 -b -pa 0 -x %d -y %d %s", fvxr, fvyr, infn);
319          if ((fp = popen(combuf, "r")) == NULL)
320                  syserror("popen");
321          getheader(fp, NULL, NULL);      /* skip header */
# Line 346 | Line 325 | fovhist()                      /* create foveal sampled image and histogr
325                  if (freadscan(fovscan(y), fvxr, fp) < 0)
326                          goto readerr;
327          pclose(fp);
349        lwmin = 1e10;                   /* find extrema */
350        lwmax = 0.;
351        for (y = 0; y < fvyr; y++)
352                for (x = 0; x < fvxr; x++) {
353                        l = plum(fovscan(y)[x]);
354                        if (l < lwmin) lwmin = l;
355                        if (l > lwmax) lwmax = l;
356                }
357        if (lwmin < LMIN) lwmin = LMIN;
358        if (lwmax > LMAX) lwmax = LMAX;
359                                        /* compute histogram */
360        bwmin = Bl(lwmin)*(1. - .01/HISTRES);
361        bwmax = Bl(lwmax)*(1. + .01/HISTRES);
362        bwavg = 0.;
363        for (y = 0; y < fvyr; y++)
364                for (x = 0; x < fvxr; x++) {
365                        if (what2do & DO_CWEIGHT &&
366                                        frandom() > centprob(x,y))
367                                continue;
368                        l = plum(fovscan(y)[x]);
369                        b = Bl(l);
370                        if (b < bwmin) continue;
371                        if (b > bwmax) continue;
372                        bwavg += b;
373                        bwhc(b)++;
374                        histot++;
375                }
376        bwavg /= (double)histot;
328          return;
329   readerr:
330          fprintf(stderr, "%s: error reading from pfilt process in fovimage\n",
# Line 384 | Line 335 | readerr:
335  
336   check2do()              /* check histogram to see what isn't worth doing */
337   {
338 <        long    sum;
338 >        double  sum;
339          double  b, l;
340          register int    i;
341  
342                                          /* check for within display range */
343 <        l = Lb(bwmax)/Lb(bwmin);
393 <        if (l <= ldmax/ldmin)
343 >        if (bwmax - bwmin <= Bldmax - Bldmin)
344                  what2do |= DO_LINEAR;
345                                          /* determine if veiling significant */
346 <        if (l < 100.)                   /* heuristic */
346 >        if (bwmax - bwmin < 4.5)                /* heuristic */
347                  what2do &= ~DO_VEIL;
348  
349          if (!(what2do & (DO_ACUITY|DO_COLOR)))
350                  return;
351                                          /* find 5th percentile */
352 <        sum = histot*0.05 + .5;
352 >        sum = histot*0.05;
353          for (i = 0; i < HISTRES; i++)
354                  if ((sum -= bwhist[i]) <= 0)
355                          break;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines