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.10 by greg, Wed Feb 5 16:08:14 1997 UTC vs.
Revision 3.24 by schorsch, Wed Jun 7 17:52:04 2006 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1997 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Condition Radiance picture for display/output
6 + *  Added white-balance adjustment 10/01 (GW).
7   */
8  
9 + #include "platform.h"
10 + #include "paths.h"
11 + #include "rtprocess.h"
12   #include "pcond.h"
13  
14  
15   #define LDMAX           100             /* default max. display luminance */
16 < #define LDMINF          0.01            /* default min. display lum. factor */
16 > #define LDDYN           32              /* default dynamic range */
17  
18   int     what2do = 0;                    /* desired adjustments */
19  
20   double  ldmax = LDMAX;                  /* maximum output luminance */
21 < double  ldmin = 0.;                     /* minimum output luminance */
22 < double  Bldmin, Bldmax;                 /* Bl(ldmin) and Bl(ldmax) */
21 > double  lddyn = LDDYN;                  /* display dynamic range */
22 > double  Bldmin, Bldmax;                 /* Bl(ldmax/lddyn) and Bl(ldmax) */
23  
24   char    *progname;                      /* global argv[0] */
25  
# Line 32 | Line 33 | double fixfrac = 0.;                   /* histogram share due to fixat
33   RESOLU  inpres;                         /* input picture resolution */
34  
35   COLOR   *fovimg;                        /* foveal (1 degree) averaged image */
36 < short   fvxr, fvyr;                     /* foveal image resolution */
36 > int     fvxr, fvyr;                     /* foveal image resolution */
37 > float   *crfimg;                        /* contrast reduction factors */
38   short   (*fixlst)[2];                   /* fixation history list */
39   int     nfixations;                     /* number of fixation points */
40 < float   bwhist[HISTRES];                /* luminance histogram */
40 > double  bwhist[HISTRES];                /* luminance histogram */
41   double  histot;                         /* total count of histogram */
42   double  bwmin, bwmax;                   /* histogram limits */
43   double  bwavg;                          /* mean brightness */
44  
45   double  scalef = 0.;                    /* linear scaling factor */
46  
47 + static gethfunc headline;
48 + static void getahead(void);
49 + static void mapimage(void);
50 + static void getfovimg(void);
51 + static void check2do(void);
52  
53 < main(argc, argv)
54 < int     argc;
55 < char    *argv[];
53 >
54 >
55 > int
56 > main(
57 >        int     argc,
58 >        char    *argv[]
59 > )
60   {
61          static RGBPRIMS outprimS;
62          int     i;
# Line 85 | Line 96 | char   *argv[];
96                          if (fixfrac > FTINY) what2do |= DO_FIXHIST;
97                          else what2do &= ~DO_FIXHIST;
98                          break;
99 +                case 'I':
100 +                        bool(DO_PREHIST);
101 +                        break;
102                  case 'l':
103                          bool(DO_LINEAR);
104                          break;
# Line 103 | Line 117 | char   *argv[];
117                  case 'e':
118                          if (i+1 >= argc) goto userr;
119                          scalef = atof(argv[++i]);
120 <                        if (argv[i][0] == '+' | argv[i][0] == '-')
120 >                        if ((argv[i][0] == '+') | (argv[i][0] == '-'))
121                                  scalef = pow(2.0, scalef);
122                          what2do |= DO_LINEAR;
123                          break;
# Line 115 | Line 129 | char   *argv[];
129                          if (i+1 >= argc) goto userr;
130                          cwarpfile = argv[++i];
131                          break;
132 <                case 't':
132 >                case 'u':
133                          if (i+1 >= argc) goto userr;
134                          ldmax = atof(argv[++i]);
135                          if (ldmax <= FTINY)
136                                  goto userr;
137                          break;
138 <                case 'b':
138 >                case 'd':
139                          if (i+1 >= argc) goto userr;
140 <                        ldmin = atof(argv[++i]);
140 >                        lddyn = atof(argv[++i]);
141                          break;
142 <                case 'd':
142 >                case 'x':
143                          if (i+1 >= argc) goto userr;
144                          if ((mapfp = fopen(argv[++i], "w")) == NULL) {
145                                  fprintf(stderr,
# Line 137 | Line 151 | char   *argv[];
151                  default:
152                          goto userr;
153                  }
154 +        if ((what2do & (DO_FIXHIST|DO_PREHIST)) == (DO_FIXHIST|DO_PREHIST)) {
155 +                fprintf(stderr, "%s: only one of -i or -I option\n", progname);
156 +                exit(1);
157 +        }
158          if ((mbcalfile != NULL) + (cwarpfile != NULL) +
159                          (outprims != stdprims) > 1) {
160                  fprintf(stderr,
# Line 144 | Line 162 | char   *argv[];
162                                  progname);
163                  exit(1);
164          }
165 <        if (outprims == stdprims & inprims != stdprims)
165 >        if ((outprims == stdprims) & (inprims != stdprims))
166                  outprims = inprims;
167 <        if (ldmin <= FTINY)
150 <                ldmin = ldmax*LDMINF;
151 <        else if (ldmin >= ldmax) {
152 <                fprintf(stderr, "%s: Ldmin (%f) >= Ldmax (%f)!\n", progname,
153 <                                ldmin, ldmax);
154 <                exit(1);
155 <        }
156 <        Bldmin = Bl(ldmin);
167 >        Bldmin = Bl(ldmax/lddyn);
168          Bldmax = Bl(ldmax);
169          if (i >= argc || i+2 < argc)
170                  goto userr;
# Line 163 | Line 174 | char   *argv[];
174                                          /* open output file */
175          if (i+2 == argc && freopen(argv[i+1], "w", stdout) == NULL)
176                  syserror(argv[i+1]);
177 < #ifdef MSDOS
178 <        setmode(fileno(infp), O_BINARY);
168 <        setmode(fileno(stdout), O_BINARY);
169 < #endif
177 >        SET_FILE_BINARY(infp);
178 >        SET_FILE_BINARY(stdout);
179          getahead();                     /* load input header */
180          printargs(argc, argv, stdout);  /* add to output header */
181 <        if (mbcalfile == NULL & outprims != stdprims)
181 >        if ((mbcalfile == NULL) & (outprims != stdprims))
182                  fputprims(outprims, stdout);
183 <        getfovimg();                    /* get foveal sample image */
184 <        if (what2do&DO_FIXHIST)         /* get fixation history? */
183 >        if ((what2do & (DO_PREHIST|DO_VEIL|DO_ACUITY)) != DO_PREHIST)
184 >                getfovimg();            /* get foveal sample image? */
185 >        if (what2do&DO_PREHIST)         /* get histogram? */
186 >                gethisto(stdin);
187 >        else if (what2do&DO_FIXHIST)    /* get fixation history? */
188                  getfixations(stdin);
189          mapimage();                     /* map the picture */
190          if (mapfp != NULL)              /* write out basic mapping */
191                  putmapping(mapfp);
192          exit(0);
193   userr:
194 <        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",
194 >        fprintf(stderr, "Usage: %s [-{h|a|v|s|c|l|w}[+-]][-I|-i ffrac][-e ev][-p xr yr xg yg xb yb xw yw|-f mbf.cal|-m rgb.cwp][-u Ldmax][-d Lddyn][-x mapfile] inpic [outpic]\n",
195                          progname);
196          exit(1);
197 +        return 1; /* pro forma return */
198   #undef bool
199   }
200  
201  
202 < syserror(s)                             /* report system error and exit */
203 < char    *s;
202 > extern void
203 > syserror(                               /* report system error and exit */
204 >        char    *s
205 > )
206   {
207          fprintf(stderr, "%s: ", progname);
208          perror(s);
# Line 195 | Line 210 | char   *s;
210   }
211  
212  
213 < headline(s)                             /* process header line */
214 < char    *s;
213 > static int
214 > headline(                               /* process header line */
215 >        char    *s,
216 >        void    *p
217 > )
218   {
219          static RGBPRIMS inprimS;
220          char    fmt[32];
# Line 205 | Line 223 | char   *s;
223                  if (!strcmp(fmt,COLRFMT)) lumf = rgblum;
224                  else if (!strcmp(fmt,CIEFMT)) lumf = cielum;
225                  else lumf = NULL;
226 <                return;                 /* don't echo */
226 >                return(0);              /* don't echo */
227          }
228          if (isprims(s)) {               /* get input primaries */
229                  primsval(inprimS, s);
230                  inprims= inprimS;
231 <                return;                 /* don't echo */
231 >                return(0);              /* don't echo */
232          }
233          if (isexpos(s)) {               /* picture exposure */
234                  inpexp *= exposval(s);
235 <                return;                 /* don't echo */
235 >                return(0);              /* don't echo */
236          }
237          if (isaspect(s))                /* pixel aspect ratio */
238                  pixaspect *= aspectval(s);
239          if (isview(s))                  /* image view */
240                  gotview += sscanview(&ourview, s);
241 <        fputs(s, stdout);
241 >        return(fputs(s, stdout));
242   }
243  
244  
245 < getahead()                      /* load picture header */
245 > static void
246 > getahead(void)                  /* load picture header */
247   {
248          char    *err;
249  
# Line 235 | Line 254 | getahead()                     /* load picture header */
254                  exit(1);
255          }
256          if (lumf == rgblum)
257 <                comprgb2xyzmat(inrgb2xyz, inprims);
257 >                comprgb2xyzWBmat(inrgb2xyz, inprims);
258          else if (mbcalfile != NULL) {
259                  fprintf(stderr, "%s: macbethcal only works with RGB pictures\n",
260                                  progname);
261                  exit(1);
262          }
263 <        if (!gotview || ourview.type == VT_PAR) {
264 <                copystruct(&ourview, &stdview);
263 >        if (!gotview || ourview.type == VT_PAR ||
264 >                        (ourview.horiz <= 5.) | (ourview.vert <= 5.)) {
265 >                ourview = stdview;
266                  ourview.type = VT_PER;
267                  if (pixaspect*inpres.yr < inpres.xr) {
268                          ourview.horiz = 40.0;
# Line 262 | Line 282 | getahead()                     /* load picture header */
282   }
283  
284  
285 < mapimage()                              /* map picture and send to stdout */
285 > static void
286 > mapimage(void)                          /* map picture and send to stdout */
287   {
288          COLOR   *scan;
289  
290          comphist();                     /* generate adaptation histogram */
291          check2do();                     /* modify what2do flags */
292          if (what2do&DO_VEIL)
293 <                compveil();
294 <        if (!(what2do&DO_LINEAR) && mkbrmap() < 0)      /* make tone map */
295 <                what2do |= DO_LINEAR;   /* failed! -- use linear scaling */
293 >                compveil();             /* compute veil image */
294 >        if (!(what2do&DO_LINEAR))
295 >                if (mkbrmap() < 0)      /* make tone map */
296 >                        what2do |= DO_LINEAR;   /* failed! -- use linear */
297 > #if ADJ_VEIL
298 >                else if (what2do&DO_VEIL)
299 >                        adjveil();      /* else adjust veil image */
300 > #endif
301          if (what2do&DO_LINEAR) {
302                  if (scalef <= FTINY) {
303                          if (what2do&DO_HSENS)
# Line 297 | Line 323 | mapimage()                             /* map picture and send to stdout */
323   }
324  
325  
326 < getfovimg()                     /* load foveal sampled image */
326 > static void
327 > getfovimg(void)                 /* load foveal sampled image */
328   {
329 <        extern FILE     *popen();
303 <        char    combuf[128];
329 >        char    combuf[PATH_MAX];
330          FILE    *fp;
331          int     x, y;
332                                                  /* compute image size */
# Line 308 | Line 334 | getfovimg()                    /* load foveal sampled image */
334          if (fvxr < 2) fvxr = 2;
335          fvyr = sqrt(ourview.vn2)/FOVDIA + 0.5;
336          if (fvyr < 2) fvyr = 2;
337 <        if (!(inpres.or & YMAJOR)) {            /* picture is rotated? */
337 >        if (!(inpres.rt & YMAJOR)) {            /* picture is rotated? */
338                  y = fvyr;
339                  fvyr = fvxr;
340                  fvxr = y;
341          }
342          if ((fovimg = (COLOR *)malloc(fvxr*fvyr*sizeof(COLOR))) == NULL)
343                  syserror("malloc");
344 <        sprintf(combuf, "pfilt -1 -b -pa 0 -x %d -y %d %s", fvxr, fvyr, infn);
344 >        sprintf(combuf, "pfilt -1 -b -pa 0 -x %d -y %d \"%s\"", fvxr, fvyr, infn);
345          if ((fp = popen(combuf, "r")) == NULL)
346                  syserror("popen");
347          getheader(fp, NULL, NULL);      /* skip header */
348 <        if (fgetresolu(&x, &y, fp) < 0 || x != fvxr | y != fvyr)
348 >        if (fgetresolu(&x, &y, fp) < 0 || (x != fvxr) | (y != fvyr))
349                  goto readerr;
350          for (y = 0; y < fvyr; y++)
351                  if (freadscan(fovscan(y), fvxr, fp) < 0)
# Line 333 | Line 359 | readerr:
359   }
360  
361  
362 < check2do()              /* check histogram to see what isn't worth doing */
362 > static void
363 > check2do(void)          /* check histogram to see what isn't worth doing */
364   {
365          double  sum;
366          double  b, l;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines