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 |
|
|
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 */ |
108 |
|
case 'e': |
109 |
|
if (i+1 >= argc) goto userr; |
110 |
|
scalef = atof(argv[++i]); |
111 |
< |
if (argv[i][0] == '+' | argv[i][0] == '-') |
111 |
> |
if ((argv[i][0] == '+') | (argv[i][0] == '-')) |
112 |
|
scalef = pow(2.0, scalef); |
113 |
|
what2do |= DO_LINEAR; |
114 |
|
break; |
153 |
|
progname); |
154 |
|
exit(1); |
155 |
|
} |
156 |
< |
if (outprims == stdprims & inprims != stdprims) |
156 |
> |
if ((outprims == stdprims) & (inprims != stdprims)) |
157 |
|
outprims = inprims; |
158 |
|
Bldmin = Bl(ldmax/lddyn); |
159 |
|
Bldmax = Bl(ldmax); |
165 |
|
/* open output file */ |
166 |
|
if (i+2 == argc && freopen(argv[i+1], "w", stdout) == NULL) |
167 |
|
syserror(argv[i+1]); |
168 |
< |
#ifdef MSDOS |
169 |
< |
setmode(fileno(infp), O_BINARY); |
168 |
< |
setmode(fileno(stdout), O_BINARY); |
169 |
< |
#endif |
168 |
> |
SET_FILE_BINARY(infp); |
169 |
> |
SET_FILE_BINARY(stdout); |
170 |
|
getahead(); /* load input header */ |
171 |
|
printargs(argc, argv, stdout); /* add to output header */ |
172 |
< |
if (mbcalfile == NULL & outprims != stdprims) |
172 |
> |
if ((mbcalfile == NULL) & (outprims != stdprims)) |
173 |
|
fputprims(outprims, stdout); |
174 |
|
if ((what2do & (DO_PREHIST|DO_VEIL|DO_ACUITY)) != DO_PREHIST) |
175 |
|
getfovimg(); /* get foveal sample image? */ |
208 |
|
if (!strcmp(fmt,COLRFMT)) lumf = rgblum; |
209 |
|
else if (!strcmp(fmt,CIEFMT)) lumf = cielum; |
210 |
|
else lumf = NULL; |
211 |
< |
return; /* don't echo */ |
211 |
> |
return(0); /* don't echo */ |
212 |
|
} |
213 |
|
if (isprims(s)) { /* get input primaries */ |
214 |
|
primsval(inprimS, s); |
215 |
|
inprims= inprimS; |
216 |
< |
return; /* don't echo */ |
216 |
> |
return(0); /* don't echo */ |
217 |
|
} |
218 |
|
if (isexpos(s)) { /* picture exposure */ |
219 |
|
inpexp *= exposval(s); |
220 |
< |
return; /* don't echo */ |
220 |
> |
return(0); /* don't echo */ |
221 |
|
} |
222 |
|
if (isaspect(s)) /* pixel aspect ratio */ |
223 |
|
pixaspect *= aspectval(s); |
224 |
|
if (isview(s)) /* image view */ |
225 |
|
gotview += sscanview(&ourview, s); |
226 |
< |
fputs(s, stdout); |
226 |
> |
return(fputs(s, stdout)); |
227 |
|
} |
228 |
|
|
229 |
|
|
238 |
|
exit(1); |
239 |
|
} |
240 |
|
if (lumf == rgblum) |
241 |
< |
comprgb2xyzmat(inrgb2xyz, inprims); |
241 |
> |
comprgb2xyzWBmat(inrgb2xyz, inprims); |
242 |
|
else if (mbcalfile != NULL) { |
243 |
|
fprintf(stderr, "%s: macbethcal only works with RGB pictures\n", |
244 |
|
progname); |
245 |
|
exit(1); |
246 |
|
} |
247 |
|
if (!gotview || ourview.type == VT_PAR) { |
248 |
< |
copystruct(&ourview, &stdview); |
248 |
> |
ourview = stdview; |
249 |
|
ourview.type = VT_PER; |
250 |
|
if (pixaspect*inpres.yr < inpres.xr) { |
251 |
|
ourview.horiz = 40.0; |
272 |
|
comphist(); /* generate adaptation histogram */ |
273 |
|
check2do(); /* modify what2do flags */ |
274 |
|
if (what2do&DO_VEIL) |
275 |
< |
compveil(); |
276 |
< |
if (!(what2do&DO_LINEAR) && mkbrmap() < 0) /* make tone map */ |
277 |
< |
what2do |= DO_LINEAR; /* failed! -- use linear scaling */ |
275 |
> |
compveil(); /* compute veil image */ |
276 |
> |
if (!(what2do&DO_LINEAR)) |
277 |
> |
if (mkbrmap() < 0) /* make tone map */ |
278 |
> |
what2do |= DO_LINEAR; /* failed! -- use linear */ |
279 |
> |
#if ADJ_VEIL |
280 |
> |
else if (what2do&DO_VEIL) |
281 |
> |
adjveil(); /* else adjust veil image */ |
282 |
> |
#endif |
283 |
|
if (what2do&DO_LINEAR) { |
284 |
|
if (scalef <= FTINY) { |
285 |
|
if (what2do&DO_HSENS) |
307 |
|
|
308 |
|
getfovimg() /* load foveal sampled image */ |
309 |
|
{ |
310 |
< |
extern FILE *popen(); |
306 |
< |
char combuf[128]; |
310 |
> |
char combuf[PATH_MAX]; |
311 |
|
FILE *fp; |
312 |
|
int x, y; |
313 |
|
/* compute image size */ |
315 |
|
if (fvxr < 2) fvxr = 2; |
316 |
|
fvyr = sqrt(ourview.vn2)/FOVDIA + 0.5; |
317 |
|
if (fvyr < 2) fvyr = 2; |
318 |
< |
if (!(inpres.or & YMAJOR)) { /* picture is rotated? */ |
318 |
> |
if (!(inpres.rt & YMAJOR)) { /* picture is rotated? */ |
319 |
|
y = fvyr; |
320 |
|
fvyr = fvxr; |
321 |
|
fvxr = y; |
322 |
|
} |
323 |
|
if ((fovimg = (COLOR *)malloc(fvxr*fvyr*sizeof(COLOR))) == NULL) |
324 |
|
syserror("malloc"); |
325 |
< |
sprintf(combuf, "pfilt -1 -b -pa 0 -x %d -y %d %s", fvxr, fvyr, infn); |
325 |
> |
sprintf(combuf, "pfilt -1 -b -pa 0 -x %d -y %d \"%s\"", fvxr, fvyr, infn); |
326 |
|
if ((fp = popen(combuf, "r")) == NULL) |
327 |
|
syserror("popen"); |
328 |
|
getheader(fp, NULL, NULL); /* skip header */ |
329 |
< |
if (fgetresolu(&x, &y, fp) < 0 || x != fvxr | y != fvyr) |
329 |
> |
if (fgetresolu(&x, &y, fp) < 0 || (x != fvxr) | (y != fvyr)) |
330 |
|
goto readerr; |
331 |
|
for (y = 0; y < fvyr; y++) |
332 |
|
if (freadscan(fovscan(y), fvxr, fp) < 0) |