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 |
|
|
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; |
140 |
|
default: |
141 |
|
goto userr; |
142 |
|
} |
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, |
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); |
161 |
< |
setmode(fileno(stdout), O_BINARY); |
162 |
< |
#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|-m rgb.cwp][-u Ldmax][-d Lddyn][-x 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); |
243 |
|
exit(1); |
244 |
|
} |
245 |
|
if (!gotview || ourview.type == VT_PAR) { |
246 |
< |
copystruct(&ourview, &stdview); |
246 |
> |
ourview = stdview; |
247 |
|
ourview.type = VT_PER; |
248 |
|
if (pixaspect*inpres.yr < inpres.xr) { |
249 |
|
ourview.horiz = 40.0; |
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; |