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.13 by gwlarson, Tue Oct 27 09:08:26 1998 UTC vs.
Revision 3.34 by greg, Tue Jun 3 21:31:51 2025 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 "pcond.h"
12  
13  
14   #define LDMAX           100             /* default max. display luminance */
15 < #define LDDYN           32              /* default dynamic range */
15 > #define LDDYN           100             /* default dynamic range */
16  
17   int     what2do = 0;                    /* desired adjustments */
18  
# Line 20 | Line 20 | double ldmax = LDMAX;                  /* maximum output luminance */
20   double  lddyn = LDDYN;                  /* display dynamic range */
21   double  Bldmin, Bldmax;                 /* Bl(ldmax/lddyn) and Bl(ldmax) */
22  
23 char    *progname;                      /* global argv[0] */
24
23   char    *infn;                          /* input file name */
24   FILE    *infp;                          /* input stream */
25   FILE    *mapfp = NULL;                  /* tone-mapping function stream */
# Line 32 | Line 30 | double fixfrac = 0.;                   /* histogram share due to fixat
30   RESOLU  inpres;                         /* input picture resolution */
31  
32   COLOR   *fovimg;                        /* foveal (1 degree) averaged image */
33 < short   fvxr, fvyr;                     /* foveal image resolution */
33 > int     fvxr, fvyr;                     /* foveal image resolution */
34 > float   *crfimg;                        /* contrast reduction factors */
35   short   (*fixlst)[2];                   /* fixation history list */
36   int     nfixations;                     /* number of fixation points */
37 < float   bwhist[HISTRES];                /* luminance histogram */
37 > double  bwhist[HISTRES];                /* luminance histogram */
38   double  histot;                         /* total count of histogram */
39   double  bwmin, bwmax;                   /* histogram limits */
40   double  bwavg;                          /* mean brightness */
41  
42   double  scalef = 0.;                    /* linear scaling factor */
43  
44 + static gethfunc headline;
45 + static void getahead(void);
46 + static void mapimage(void);
47 + static void getfovimg(void);
48 + static void check2do(void);
49  
50 < main(argc, argv)
51 < int     argc;
52 < char    *argv[];
50 >
51 >
52 > int
53 > main(
54 >        int     argc,
55 >        char    *argv[]
56 > )
57   {
58          static RGBPRIMS outprimS;
59          int     i;
60 < #define bool(flg)               switch (argv[i][2]) { \
60 > #define check_bool(flg)         switch (argv[i][2]) { \
61                                  case '\0': what2do ^= flg; break; \
62                                  case 'y': case 'Y': case 't': case 'T': \
63                                  case '+': case '1': what2do |= flg; break; \
# Line 57 | Line 65 | char   *argv[];
65                                  case '-': case '0': what2do &= ~(flg); break; \
66                                  default: goto userr; }
67  
68 <        progname = argv[0];
68 >        fixargv0(argv[0]);              /* sets global progname */
69  
70          for (i = 1; i < argc && argv[i][0] == '-'; i++)
71                  switch (argv[i][1]) {
72                  case 'h':
73 <                        bool(DO_HUMAN);
73 >                        check_bool(DO_HUMAN);
74                          break;
75                  case 'a':
76 <                        bool(DO_ACUITY);
76 >                        check_bool(DO_ACUITY);
77                          break;
78                  case 'v':
79 <                        bool(DO_VEIL);
79 >                        check_bool(DO_VEIL);
80                          break;
81                  case 's':
82 <                        bool(DO_HSENS);
82 >                        check_bool(DO_HSENS);
83                          break;
84                  case 'c':
85 <                        bool(DO_COLOR);
85 >                        check_bool(DO_COLOR);
86                          break;
87                  case 'w':
88 <                        bool(DO_CWEIGHT);
88 >                        check_bool(DO_CWEIGHT);
89                          break;
90                  case 'i':
91                          if (i+1 >= argc) goto userr;
# Line 86 | Line 94 | char   *argv[];
94                          else what2do &= ~DO_FIXHIST;
95                          break;
96                  case 'I':
97 <                        bool(DO_PREHIST);
97 >                        check_bool(DO_PREHIST);
98                          break;
99                  case 'l':
100 <                        bool(DO_LINEAR);
100 >                        check_bool(DO_LINEAR);
101                          break;
102                  case 'p':
103                          if (i+8 >= argc) goto userr;
# Line 106 | Line 114 | char   *argv[];
114                  case 'e':
115                          if (i+1 >= argc) goto userr;
116                          scalef = atof(argv[++i]);
117 <                        if (argv[i][0] == '+' | argv[i][0] == '-')
117 >                        if ((argv[i][0] == '+') | (argv[i][0] == '-'))
118                                  scalef = pow(2.0, scalef);
119                          what2do |= DO_LINEAR;
120                          break;
# Line 151 | Line 159 | char   *argv[];
159                                  progname);
160                  exit(1);
161          }
162 <        if (outprims == stdprims & inprims != stdprims)
162 >        if ((outprims == stdprims) & (inprims != stdprims))
163                  outprims = inprims;
164          Bldmin = Bl(ldmax/lddyn);
165          Bldmax = Bl(ldmax);
# Line 163 | Line 171 | char   *argv[];
171                                          /* open output file */
172          if (i+2 == argc && freopen(argv[i+1], "w", stdout) == NULL)
173                  syserror(argv[i+1]);
174 < #ifdef MSDOS
175 <        setmode(fileno(infp), O_BINARY);
168 <        setmode(fileno(stdout), O_BINARY);
169 < #endif
174 >        SET_FILE_BINARY(infp);
175 >        SET_FILE_BINARY(stdout);
176          getahead();                     /* load input header */
177          printargs(argc, argv, stdout);  /* add to output header */
178 <        if (mbcalfile == NULL & outprims != stdprims)
178 >        if ((mbcalfile == NULL) & (outprims != stdprims))
179                  fputprims(outprims, stdout);
180          if ((what2do & (DO_PREHIST|DO_VEIL|DO_ACUITY)) != DO_PREHIST)
181                  getfovimg();            /* get foveal sample image? */
# Line 185 | Line 191 | userr:
191          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",
192                          progname);
193          exit(1);
194 < #undef bool
194 >        return 1; /* pro forma return */
195 > #undef check_bool
196   }
197  
198  
199 < syserror(s)                             /* report system error and exit */
200 < char    *s;
199 > void
200 > syserror(                               /* report system error and exit */
201 >        char    *s
202 > )
203   {
204          fprintf(stderr, "%s: ", progname);
205          perror(s);
# Line 198 | Line 207 | char   *s;
207   }
208  
209  
210 < headline(s)                             /* process header line */
211 < char    *s;
210 > static int
211 > headline(                               /* process header line */
212 >        char    *s,
213 >        void    *p
214 > )
215   {
216          static RGBPRIMS inprimS;
217 <        char    fmt[32];
217 >        char    fmt[MAXFMTLEN];
218  
219          if (formatval(fmt, s)) {        /* check if format string */
220 <                if (!strcmp(fmt,COLRFMT)) lumf = rgblum;
221 <                else if (!strcmp(fmt,CIEFMT)) lumf = cielum;
222 <                else lumf = NULL;
220 >                if (!strcmp(fmt,COLRFMT) || !strcmp(fmt,SPECFMT))
221 >                        lumf = rgblum;
222 >                else if (!strcmp(fmt,CIEFMT))
223 >                        lumf = cielum;
224 >                else
225 >                        lumf = NULL;
226                  return(0);              /* don't echo */
227          }
228 <        if (isprims(s)) {               /* get input primaries */
229 <                primsval(inprimS, s);
230 <                inprims= inprimS;
228 >        if (isncomp(s)) {
229 >                NCSAMP = ncompval(s);
230 >                return(0);
231 >        }
232 >        if (iswlsplit(s)) {
233 >                wlsplitval(WLPART, s);
234 >                return(0);
235 >        }
236 >                                        /* get input primaries */
237 >        if (isprims(s) && primsval(inprimS, s)) {
238 >                inprims = inprimS;
239                  return(0);              /* don't echo */
240          }
241          if (isexpos(s)) {               /* picture exposure */
# Line 227 | Line 250 | char   *s;
250   }
251  
252  
253 < getahead()                      /* load picture header */
253 > static void
254 > getahead(void)                  /* load picture header */
255   {
256          char    *err;
257  
# Line 238 | Line 262 | getahead()                     /* load picture header */
262                  exit(1);
263          }
264          if (lumf == rgblum)
265 <                comprgb2xyzmat(inrgb2xyz, inprims);
265 >                comprgb2xyzWBmat(inrgb2xyz, inprims);
266          else if (mbcalfile != NULL) {
267                  fprintf(stderr, "%s: macbethcal only works with RGB pictures\n",
268                                  progname);
269                  exit(1);
270          }
271 <        if (!gotview || ourview.type == VT_PAR) {
272 <                copystruct(&ourview, &stdview);
271 >        if (!gotview || ourview.type == VT_PAR ||
272 >                        (ourview.horiz <= 5.) | (ourview.vert <= 5.)) {
273 >                ourview = stdview;
274                  ourview.type = VT_PER;
275                  if (pixaspect*inpres.yr < inpres.xr) {
276                          ourview.horiz = 40.0;
# Line 265 | Line 290 | getahead()                     /* load picture header */
290   }
291  
292  
293 < mapimage()                              /* map picture and send to stdout */
293 > static void
294 > mapimage(void)                          /* map picture and send to stdout */
295   {
296          COLOR   *scan;
297  
298          comphist();                     /* generate adaptation histogram */
299          check2do();                     /* modify what2do flags */
300          if (what2do&DO_VEIL)
301 <                compveil();
302 <        if (!(what2do&DO_LINEAR) && mkbrmap() < 0)      /* make tone map */
303 <                what2do |= DO_LINEAR;   /* failed! -- use linear scaling */
301 >                compveil();             /* compute veil image */
302 >        if (!(what2do&DO_LINEAR))
303 >                if (mkbrmap() < 0)      /* make tone map */
304 >                        what2do |= DO_LINEAR;   /* failed! -- use linear */
305 > #if ADJ_VEIL
306 >                else if (what2do&DO_VEIL)
307 >                        adjveil();      /* else adjust veil image */
308 > #endif
309          if (what2do&DO_LINEAR) {
310                  if (scalef <= FTINY) {
311                          if (what2do&DO_HSENS)
# Line 300 | Line 331 | mapimage()                             /* map picture and send to stdout */
331   }
332  
333  
334 < getfovimg()                     /* load foveal sampled image */
334 > static void
335 > getfovimg(void)                 /* load foveal sampled image */
336   {
337 <        extern FILE     *popen();
306 <        char    combuf[128];
337 >        char    combuf[PATH_MAX];
338          FILE    *fp;
339          int     x, y;
340                                                  /* compute image size */
# Line 311 | Line 342 | getfovimg()                    /* load foveal sampled image */
342          if (fvxr < 2) fvxr = 2;
343          fvyr = sqrt(ourview.vn2)/FOVDIA + 0.5;
344          if (fvyr < 2) fvyr = 2;
345 <        if (!(inpres.or & YMAJOR)) {            /* picture is rotated? */
345 >        if (!(inpres.rt & YMAJOR)) {            /* picture is rotated? */
346                  y = fvyr;
347                  fvyr = fvxr;
348                  fvxr = y;
349          }
350          if ((fovimg = (COLOR *)malloc(fvxr*fvyr*sizeof(COLOR))) == NULL)
351                  syserror("malloc");
352 <        sprintf(combuf, "pfilt -1 -b -pa 0 -x %d -y %d %s", fvxr, fvyr, infn);
352 >        sprintf(combuf, "pfilt -1 -b -pa 0 -x %d -y %d \"%s\"", fvxr, fvyr, infn);
353          if ((fp = popen(combuf, "r")) == NULL)
354                  syserror("popen");
355 +        SET_FILE_BINARY(fp);
356          getheader(fp, NULL, NULL);      /* skip header */
357 <        if (fgetresolu(&x, &y, fp) < 0 || x != fvxr | y != fvyr)
357 >        if (fgetresolu(&x, &y, fp) < 0 || (x != fvxr) | (y != fvyr))
358                  goto readerr;
359          for (y = 0; y < fvyr; y++)
360 <                if (freadscan(fovscan(y), fvxr, fp) < 0)
360 >                if (fread2scan(fovscan(y), fvxr, fp, NCSAMP, WLPART) < 0)
361                          goto readerr;
362          pclose(fp);
363          return;
# Line 336 | Line 368 | readerr:
368   }
369  
370  
371 < check2do()              /* check histogram to see what isn't worth doing */
371 > static void
372 > check2do(void)          /* check histogram to see what isn't worth doing */
373   {
374          double  sum;
375          double  b, l;
376 <        register int    i;
376 >        int     i;
377  
378                                          /* check for within display range */
379          if (bwmax - bwmin <= Bldmax - Bldmin)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines