| 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 "pcond.h" |
| 11 |
|
|
| 12 |
|
|
| 13 |
|
#define LDMAX 100 /* default max. display luminance */ |
| 14 |
< |
#define LDMINF 0.01 /* default min. display lum. factor */ |
| 14 |
> |
#define LDDYN 32 /* default dynamic range */ |
| 15 |
|
|
| 16 |
|
int what2do = 0; /* desired adjustments */ |
| 17 |
|
|
| 18 |
|
double ldmax = LDMAX; /* maximum output luminance */ |
| 19 |
< |
double ldmin = 0.; /* minimum output luminance */ |
| 20 |
< |
double Bldmin, Bldmax; /* Bl(ldmin) and Bl(ldmax) */ |
| 19 |
> |
double lddyn = LDDYN; /* display dynamic range */ |
| 20 |
> |
double Bldmin, Bldmax; /* Bl(ldmax/lddyn) and Bl(ldmax) */ |
| 21 |
|
|
| 22 |
|
char *progname; /* global argv[0] */ |
| 23 |
|
|
| 31 |
|
RESOLU inpres; /* input picture resolution */ |
| 32 |
|
|
| 33 |
|
COLOR *fovimg; /* foveal (1 degree) averaged image */ |
| 34 |
< |
short fvxr, fvyr; /* foveal image resolution */ |
| 34 |
> |
int fvxr, fvyr; /* foveal image resolution */ |
| 35 |
> |
float *crfimg; /* contrast reduction factors */ |
| 36 |
|
short (*fixlst)[2]; /* fixation history list */ |
| 37 |
|
int nfixations; /* number of fixation points */ |
| 38 |
< |
float bwhist[HISTRES]; /* luminance histogram */ |
| 38 |
> |
double bwhist[HISTRES]; /* luminance histogram */ |
| 39 |
|
double histot; /* total count of histogram */ |
| 40 |
|
double bwmin, bwmax; /* histogram limits */ |
| 41 |
|
double bwavg; /* mean brightness */ |
| 85 |
|
if (fixfrac > FTINY) what2do |= DO_FIXHIST; |
| 86 |
|
else what2do &= ~DO_FIXHIST; |
| 87 |
|
break; |
| 88 |
+ |
case 'I': |
| 89 |
+ |
bool(DO_PREHIST); |
| 90 |
+ |
break; |
| 91 |
|
case 'l': |
| 92 |
|
bool(DO_LINEAR); |
| 93 |
|
break; |
| 114 |
|
if (i+1 >= argc) goto userr; |
| 115 |
|
mbcalfile = argv[++i]; |
| 116 |
|
break; |
| 117 |
< |
case 't': |
| 117 |
> |
case 'm': |
| 118 |
|
if (i+1 >= argc) goto userr; |
| 119 |
+ |
cwarpfile = argv[++i]; |
| 120 |
+ |
break; |
| 121 |
+ |
case 'u': |
| 122 |
+ |
if (i+1 >= argc) goto userr; |
| 123 |
|
ldmax = atof(argv[++i]); |
| 124 |
|
if (ldmax <= FTINY) |
| 125 |
|
goto userr; |
| 126 |
|
break; |
| 127 |
< |
case 'b': |
| 127 |
> |
case 'd': |
| 128 |
|
if (i+1 >= argc) goto userr; |
| 129 |
< |
ldmin = atof(argv[++i]); |
| 129 |
> |
lddyn = atof(argv[++i]); |
| 130 |
|
break; |
| 131 |
< |
case 'm': |
| 131 |
> |
case 'x': |
| 132 |
|
if (i+1 >= argc) goto userr; |
| 133 |
|
if ((mapfp = fopen(argv[++i], "w")) == NULL) { |
| 134 |
|
fprintf(stderr, |
| 140 |
|
default: |
| 141 |
|
goto userr; |
| 142 |
|
} |
| 143 |
< |
if (mbcalfile != NULL & outprims != stdprims) { |
| 144 |
< |
fprintf(stderr, "%s: only one of -p or -f option supported\n", |
| 143 |
> |
if ((what2do & (DO_FIXHIST|DO_PREHIST)) == (DO_FIXHIST|DO_PREHIST)) { |
| 144 |
> |
fprintf(stderr, "%s: only one of -i or -I option\n", progname); |
| 145 |
> |
exit(1); |
| 146 |
> |
} |
| 147 |
> |
if ((mbcalfile != NULL) + (cwarpfile != NULL) + |
| 148 |
> |
(outprims != stdprims) > 1) { |
| 149 |
> |
fprintf(stderr, |
| 150 |
> |
"%s: only one of -p, -m or -f option supported\n", |
| 151 |
|
progname); |
| 152 |
|
exit(1); |
| 153 |
|
} |
| 154 |
|
if (outprims == stdprims & inprims != stdprims) |
| 155 |
|
outprims = inprims; |
| 156 |
< |
if (ldmin <= FTINY) |
| 144 |
< |
ldmin = ldmax*LDMINF; |
| 145 |
< |
else if (ldmin >= ldmax) { |
| 146 |
< |
fprintf(stderr, "%s: Ldmin (%f) >= Ldmax (%f)!\n", progname, |
| 147 |
< |
ldmin, ldmax); |
| 148 |
< |
exit(1); |
| 149 |
< |
} |
| 150 |
< |
Bldmin = Bl(ldmin); |
| 156 |
> |
Bldmin = Bl(ldmax/lddyn); |
| 157 |
|
Bldmax = Bl(ldmax); |
| 158 |
|
if (i >= argc || i+2 < argc) |
| 159 |
|
goto userr; |
| 163 |
|
/* open output file */ |
| 164 |
|
if (i+2 == argc && freopen(argv[i+1], "w", stdout) == NULL) |
| 165 |
|
syserror(argv[i+1]); |
| 166 |
< |
#ifdef MSDOS |
| 167 |
< |
setmode(fileno(infp), O_BINARY); |
| 162 |
< |
setmode(fileno(stdout), O_BINARY); |
| 163 |
< |
#endif |
| 166 |
> |
SET_FILE_BINARY(infp); |
| 167 |
> |
SET_FILE_BINARY(stdout); |
| 168 |
|
getahead(); /* load input header */ |
| 169 |
|
printargs(argc, argv, stdout); /* add to output header */ |
| 170 |
|
if (mbcalfile == NULL & outprims != stdprims) |
| 171 |
|
fputprims(outprims, stdout); |
| 172 |
< |
getfovimg(); /* get foveal sample image */ |
| 173 |
< |
if (what2do&DO_FIXHIST) /* get fixation history? */ |
| 172 |
> |
if ((what2do & (DO_PREHIST|DO_VEIL|DO_ACUITY)) != DO_PREHIST) |
| 173 |
> |
getfovimg(); /* get foveal sample image? */ |
| 174 |
> |
if (what2do&DO_PREHIST) /* get histogram? */ |
| 175 |
> |
gethisto(stdin); |
| 176 |
> |
else if (what2do&DO_FIXHIST) /* get fixation history? */ |
| 177 |
|
getfixations(stdin); |
| 178 |
|
mapimage(); /* map the picture */ |
| 179 |
|
if (mapfp != NULL) /* write out basic mapping */ |
| 180 |
|
putmapping(mapfp); |
| 181 |
|
exit(0); |
| 182 |
|
userr: |
| 183 |
< |
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", |
| 183 |
> |
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", |
| 184 |
|
progname); |
| 185 |
|
exit(1); |
| 186 |
|
#undef bool |
| 206 |
|
if (!strcmp(fmt,COLRFMT)) lumf = rgblum; |
| 207 |
|
else if (!strcmp(fmt,CIEFMT)) lumf = cielum; |
| 208 |
|
else lumf = NULL; |
| 209 |
< |
return; /* don't echo */ |
| 209 |
> |
return(0); /* don't echo */ |
| 210 |
|
} |
| 211 |
|
if (isprims(s)) { /* get input primaries */ |
| 212 |
|
primsval(inprimS, s); |
| 213 |
|
inprims= inprimS; |
| 214 |
< |
return; /* don't echo */ |
| 214 |
> |
return(0); /* don't echo */ |
| 215 |
|
} |
| 216 |
|
if (isexpos(s)) { /* picture exposure */ |
| 217 |
|
inpexp *= exposval(s); |
| 218 |
< |
return; /* don't echo */ |
| 218 |
> |
return(0); /* don't echo */ |
| 219 |
|
} |
| 220 |
|
if (isaspect(s)) /* pixel aspect ratio */ |
| 221 |
|
pixaspect *= aspectval(s); |
| 222 |
|
if (isview(s)) /* image view */ |
| 223 |
|
gotview += sscanview(&ourview, s); |
| 224 |
< |
fputs(s, stdout); |
| 224 |
> |
return(fputs(s, stdout)); |
| 225 |
|
} |
| 226 |
|
|
| 227 |
|
|
| 236 |
|
exit(1); |
| 237 |
|
} |
| 238 |
|
if (lumf == rgblum) |
| 239 |
< |
comprgb2xyzmat(inrgb2xyz, inprims); |
| 239 |
> |
comprgb2xyzWBmat(inrgb2xyz, inprims); |
| 240 |
|
else if (mbcalfile != NULL) { |
| 241 |
|
fprintf(stderr, "%s: macbethcal only works with RGB pictures\n", |
| 242 |
|
progname); |
| 270 |
|
comphist(); /* generate adaptation histogram */ |
| 271 |
|
check2do(); /* modify what2do flags */ |
| 272 |
|
if (what2do&DO_VEIL) |
| 273 |
< |
compveil(); |
| 274 |
< |
if (!(what2do&DO_LINEAR) && mkbrmap() < 0) /* make tone map */ |
| 275 |
< |
what2do |= DO_LINEAR; /* failed! -- use linear scaling */ |
| 273 |
> |
compveil(); /* compute veil image */ |
| 274 |
> |
if (!(what2do&DO_LINEAR)) |
| 275 |
> |
if (mkbrmap() < 0) /* make tone map */ |
| 276 |
> |
what2do |= DO_LINEAR; /* failed! -- use linear */ |
| 277 |
> |
#if ADJ_VEIL |
| 278 |
> |
else if (what2do&DO_VEIL) |
| 279 |
> |
adjveil(); /* else adjust veil image */ |
| 280 |
> |
#endif |
| 281 |
|
if (what2do&DO_LINEAR) { |
| 282 |
|
if (scalef <= FTINY) { |
| 283 |
|
if (what2do&DO_HSENS) |
| 314 |
|
if (fvxr < 2) fvxr = 2; |
| 315 |
|
fvyr = sqrt(ourview.vn2)/FOVDIA + 0.5; |
| 316 |
|
if (fvyr < 2) fvyr = 2; |
| 317 |
< |
if (!(inpres.or & YMAJOR)) { /* picture is rotated? */ |
| 317 |
> |
if (!(inpres.rt & YMAJOR)) { /* picture is rotated? */ |
| 318 |
|
y = fvyr; |
| 319 |
|
fvyr = fvxr; |
| 320 |
|
fvxr = y; |