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 */ |
44 |
|
|
45 |
|
double scalef = 0.; /* linear scaling factor */ |
46 |
|
|
47 |
+ |
static gethfunc headline; |
48 |
|
|
49 |
+ |
|
50 |
|
main(argc, argv) |
51 |
|
int argc; |
52 |
|
char *argv[]; |
110 |
|
case 'e': |
111 |
|
if (i+1 >= argc) goto userr; |
112 |
|
scalef = atof(argv[++i]); |
113 |
< |
if (argv[i][0] == '+' | argv[i][0] == '-') |
113 |
> |
if ((argv[i][0] == '+') | (argv[i][0] == '-')) |
114 |
|
scalef = pow(2.0, scalef); |
115 |
|
what2do |= DO_LINEAR; |
116 |
|
break; |
155 |
|
progname); |
156 |
|
exit(1); |
157 |
|
} |
158 |
< |
if (outprims == stdprims & inprims != stdprims) |
158 |
> |
if ((outprims == stdprims) & (inprims != stdprims)) |
159 |
|
outprims = inprims; |
160 |
|
Bldmin = Bl(ldmax/lddyn); |
161 |
|
Bldmax = Bl(ldmax); |
167 |
|
/* open output file */ |
168 |
|
if (i+2 == argc && freopen(argv[i+1], "w", stdout) == NULL) |
169 |
|
syserror(argv[i+1]); |
170 |
< |
#ifdef MSDOS |
171 |
< |
setmode(fileno(infp), O_BINARY); |
168 |
< |
setmode(fileno(stdout), O_BINARY); |
169 |
< |
#endif |
170 |
> |
SET_FILE_BINARY(infp); |
171 |
> |
SET_FILE_BINARY(stdout); |
172 |
|
getahead(); /* load input header */ |
173 |
|
printargs(argc, argv, stdout); /* add to output header */ |
174 |
< |
if (mbcalfile == NULL & outprims != stdprims) |
174 |
> |
if ((mbcalfile == NULL) & (outprims != stdprims)) |
175 |
|
fputprims(outprims, stdout); |
176 |
|
if ((what2do & (DO_PREHIST|DO_VEIL|DO_ACUITY)) != DO_PREHIST) |
177 |
|
getfovimg(); /* get foveal sample image? */ |
200 |
|
} |
201 |
|
|
202 |
|
|
203 |
< |
headline(s) /* process header line */ |
204 |
< |
char *s; |
203 |
> |
static int |
204 |
> |
headline( /* process header line */ |
205 |
> |
char *s, |
206 |
> |
void *p |
207 |
> |
) |
208 |
|
{ |
209 |
|
static RGBPRIMS inprimS; |
210 |
|
char fmt[32]; |
243 |
|
exit(1); |
244 |
|
} |
245 |
|
if (lumf == rgblum) |
246 |
< |
comprgb2xyzmat(inrgb2xyz, inprims); |
246 |
> |
comprgb2xyzWBmat(inrgb2xyz, inprims); |
247 |
|
else if (mbcalfile != NULL) { |
248 |
|
fprintf(stderr, "%s: macbethcal only works with RGB pictures\n", |
249 |
|
progname); |
250 |
|
exit(1); |
251 |
|
} |
252 |
|
if (!gotview || ourview.type == VT_PAR) { |
253 |
< |
copystruct(&ourview, &stdview); |
253 |
> |
ourview = stdview; |
254 |
|
ourview.type = VT_PER; |
255 |
|
if (pixaspect*inpres.yr < inpres.xr) { |
256 |
|
ourview.horiz = 40.0; |
277 |
|
comphist(); /* generate adaptation histogram */ |
278 |
|
check2do(); /* modify what2do flags */ |
279 |
|
if (what2do&DO_VEIL) |
280 |
< |
compveil(); |
281 |
< |
if (!(what2do&DO_LINEAR) && mkbrmap() < 0) /* make tone map */ |
282 |
< |
what2do |= DO_LINEAR; /* failed! -- use linear scaling */ |
280 |
> |
compveil(); /* compute veil image */ |
281 |
> |
if (!(what2do&DO_LINEAR)) |
282 |
> |
if (mkbrmap() < 0) /* make tone map */ |
283 |
> |
what2do |= DO_LINEAR; /* failed! -- use linear */ |
284 |
> |
#if ADJ_VEIL |
285 |
> |
else if (what2do&DO_VEIL) |
286 |
> |
adjveil(); /* else adjust veil image */ |
287 |
> |
#endif |
288 |
|
if (what2do&DO_LINEAR) { |
289 |
|
if (scalef <= FTINY) { |
290 |
|
if (what2do&DO_HSENS) |
312 |
|
|
313 |
|
getfovimg() /* load foveal sampled image */ |
314 |
|
{ |
315 |
< |
extern FILE *popen(); |
306 |
< |
char combuf[128]; |
315 |
> |
char combuf[PATH_MAX]; |
316 |
|
FILE *fp; |
317 |
|
int x, y; |
318 |
|
/* compute image size */ |
320 |
|
if (fvxr < 2) fvxr = 2; |
321 |
|
fvyr = sqrt(ourview.vn2)/FOVDIA + 0.5; |
322 |
|
if (fvyr < 2) fvyr = 2; |
323 |
< |
if (!(inpres.or & YMAJOR)) { /* picture is rotated? */ |
323 |
> |
if (!(inpres.rt & YMAJOR)) { /* picture is rotated? */ |
324 |
|
y = fvyr; |
325 |
|
fvyr = fvxr; |
326 |
|
fvxr = y; |
327 |
|
} |
328 |
|
if ((fovimg = (COLOR *)malloc(fvxr*fvyr*sizeof(COLOR))) == NULL) |
329 |
|
syserror("malloc"); |
330 |
< |
sprintf(combuf, "pfilt -1 -b -pa 0 -x %d -y %d %s", fvxr, fvyr, infn); |
330 |
> |
sprintf(combuf, "pfilt -1 -b -pa 0 -x %d -y %d \"%s\"", fvxr, fvyr, infn); |
331 |
|
if ((fp = popen(combuf, "r")) == NULL) |
332 |
|
syserror("popen"); |
333 |
|
getheader(fp, NULL, NULL); /* skip header */ |
334 |
< |
if (fgetresolu(&x, &y, fp) < 0 || x != fvxr | y != fvyr) |
334 |
> |
if (fgetresolu(&x, &y, fp) < 0 || (x != fvxr) | (y != fvyr)) |
335 |
|
goto readerr; |
336 |
|
for (y = 0; y < fvyr; y++) |
337 |
|
if (freadscan(fovscan(y), fvxr, fp) < 0) |