12 |
|
|
13 |
|
|
14 |
|
#define LDMAX 100 /* default max. display luminance */ |
15 |
< |
#define LDMINF 0.01 /* default min. display lum. factor */ |
15 |
> |
#define LDDYN 32 /* default dynamic range */ |
16 |
|
|
17 |
|
int what2do = 0; /* desired adjustments */ |
18 |
|
|
19 |
|
double ldmax = LDMAX; /* maximum output luminance */ |
20 |
< |
double ldmin = 0.; /* minimum output luminance */ |
21 |
< |
double Bldmin, Bldmax; /* Bl(ldmin) and Bl(ldmax) */ |
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 |
|
|
28 |
|
VIEW ourview = STDVIEW; /* picture view */ |
29 |
|
int gotview = 0; /* picture has view */ |
30 |
|
double pixaspect = 1.0; /* pixel aspect ratio */ |
31 |
+ |
double fixfrac = 0.; /* histogram share due to fixations */ |
32 |
|
RESOLU inpres; /* input picture resolution */ |
33 |
|
|
34 |
|
COLOR *fovimg; /* foveal (1 degree) averaged image */ |
35 |
|
short fvxr, fvyr; /* foveal image resolution */ |
36 |
+ |
short (*fixlst)[2]; /* fixation history list */ |
37 |
+ |
int nfixations; /* number of fixation points */ |
38 |
|
float bwhist[HISTRES]; /* luminance histogram */ |
39 |
|
double histot; /* total count of histogram */ |
40 |
|
double bwmin, bwmax; /* histogram limits */ |
79 |
|
case 'w': |
80 |
|
bool(DO_CWEIGHT); |
81 |
|
break; |
82 |
+ |
case 'i': |
83 |
+ |
if (i+1 >= argc) goto userr; |
84 |
+ |
fixfrac = atof(argv[++i]); |
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) |
135 |
< |
ldmin = ldmax*LDMINF; |
136 |
< |
else if (ldmin >= ldmax) { |
137 |
< |
fprintf(stderr, "%s: Ldmin (%f) >= Ldmax (%f)!\n", progname, |
138 |
< |
ldmin, ldmax); |
139 |
< |
exit(1); |
140 |
< |
} |
141 |
< |
Bldmin = Bl(ldmin); |
156 |
> |
Bldmin = Bl(ldmax/lddyn); |
157 |
|
Bldmax = Bl(ldmax); |
158 |
|
if (i >= argc || i+2 < argc) |
159 |
|
goto userr; |
160 |
+ |
/* open input file */ |
161 |
|
if ((infp = fopen(infn=argv[i], "r")) == NULL) |
162 |
|
syserror(infn); |
163 |
+ |
/* open output file */ |
164 |
|
if (i+2 == argc && freopen(argv[i+1], "w", stdout) == NULL) |
165 |
|
syserror(argv[i+1]); |
166 |
|
#ifdef MSDOS |
169 |
|
#endif |
170 |
|
getahead(); /* load input header */ |
171 |
|
printargs(argc, argv, stdout); /* add to output header */ |
172 |
< |
if (outprims != inprims) |
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? */ |
176 |
+ |
if (what2do&DO_PREHIST) /* get histogram? */ |
177 |
+ |
gethisto(stdin); |
178 |
+ |
else if (what2do&DO_FIXHIST) /* get fixation history? */ |
179 |
+ |
getfixations(stdin); |
180 |
|
mapimage(); /* map the picture */ |
181 |
|
if (mapfp != NULL) /* write out basic mapping */ |
182 |
|
putmapping(mapfp); |
183 |
|
exit(0); |
184 |
|
userr: |
185 |
< |
fprintf(stderr, "Usage: %s [-{h|a|v|s|c|l|w}[+-]][-e ev][-p xr yr xg yg xb yb xw yw|-f mbf.cal][-t Ldmax][-b Ldmin][-m mapfile] inpic [outpic]\n", |
185 |
> |
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", |
186 |
|
progname); |
187 |
|
exit(1); |
188 |
|
#undef bool |
269 |
|
{ |
270 |
|
COLOR *scan; |
271 |
|
|
249 |
– |
#ifdef DEBUG |
250 |
– |
fprintf(stderr, "%s: generating histogram...", progname); |
251 |
– |
#endif |
252 |
– |
getfovimg(); /* get foveal sample image */ |
272 |
|
comphist(); /* generate adaptation histogram */ |
254 |
– |
#ifdef DEBUG |
255 |
– |
fputs("done\n", stderr); |
256 |
– |
#endif |
273 |
|
check2do(); /* modify what2do flags */ |
274 |
< |
if (what2do&DO_VEIL) { |
259 |
< |
#ifdef DEBUG |
260 |
< |
fprintf(stderr, "%s: computing veiling...", progname); |
261 |
< |
#endif |
274 |
> |
if (what2do&DO_VEIL) |
275 |
|
compveil(); |
276 |
< |
#ifdef DEBUG |
277 |
< |
fputs("done\n", stderr); |
265 |
< |
#endif |
266 |
< |
} |
267 |
< |
#ifdef DEBUG |
268 |
< |
fprintf(stderr, "%s: computing brightness mapping...", progname); |
269 |
< |
#endif |
270 |
< |
if (!(what2do&DO_LINEAR) && mkbrmap() < 0) { /* make tone map */ |
271 |
< |
what2do |= DO_LINEAR; /* use linear scaling */ |
272 |
< |
#ifdef DEBUG |
273 |
< |
fputs("failed!\n", stderr); |
274 |
< |
} else |
275 |
< |
fputs("done\n", stderr); |
276 |
< |
#else |
277 |
< |
} |
278 |
< |
#endif |
276 |
> |
if (!(what2do&DO_LINEAR) && mkbrmap() < 0) /* make tone map */ |
277 |
> |
what2do |= DO_LINEAR; /* failed! -- use linear scaling */ |
278 |
|
if (what2do&DO_LINEAR) { |
279 |
|
if (scalef <= FTINY) { |
280 |
|
if (what2do&DO_HSENS) |
284 |
|
scalef = Lb(0.5*(Bldmax+Bldmin)) / Lb(bwavg); |
285 |
|
scalef *= WHTEFFICACY/(inpexp*ldmax); |
286 |
|
} |
288 |
– |
#ifdef DEBUG |
289 |
– |
fprintf(stderr, "%s: linear scaling factor = %f\n", |
290 |
– |
progname, scalef); |
291 |
– |
#endif |
287 |
|
fputexpos(inpexp*scalef, stdout); /* record exposure */ |
288 |
|
if (lumf == cielum) scalef /= WHTEFFICACY; |
289 |
|
} |
290 |
< |
putchar('\n'); /* complete header */ |
290 |
> |
fputformat(COLRFMT, stdout); /* complete header */ |
291 |
> |
putchar('\n'); |
292 |
|
fputsresolu(&inpres, stdout); /* resolution doesn't change */ |
293 |
< |
|
293 |
> |
/* condition our image */ |
294 |
|
for (scan = firstscan(); scan != NULL; scan = nextscan()) |
295 |
|
if (fwritescan(scan, scanlen(&inpres), stdout) < 0) { |
296 |
|
fprintf(stderr, "%s: scanline write error\n", |
300 |
|
} |
301 |
|
|
302 |
|
|
307 |
– |
double |
308 |
– |
centprob(x, y) /* center-weighting probability function */ |
309 |
– |
int x, y; |
310 |
– |
{ |
311 |
– |
double xr, yr, p; |
312 |
– |
/* paraboloid, 0 at 90 degrees from center */ |
313 |
– |
xr = (x - .5*(fvxr-1))/90.; /* 180 degree fisheye has fv?r == 90 */ |
314 |
– |
yr = (y - .5*(fvyr-1))/90.; |
315 |
– |
p = 1. - xr*xr - yr*yr; |
316 |
– |
return(p < 0. ? 0. : p); |
317 |
– |
} |
318 |
– |
|
319 |
– |
|
303 |
|
getfovimg() /* load foveal sampled image */ |
304 |
|
{ |
305 |
|
extern FILE *popen(); |
318 |
|
} |
319 |
|
if ((fovimg = (COLOR *)malloc(fvxr*fvyr*sizeof(COLOR))) == NULL) |
320 |
|
syserror("malloc"); |
321 |
< |
sprintf(combuf, "pfilt -1 -b -x %d -y %d %s", fvxr, fvyr, infn); |
321 |
> |
sprintf(combuf, "pfilt -1 -b -pa 0 -x %d -y %d %s", fvxr, fvyr, infn); |
322 |
|
if ((fp = popen(combuf, "r")) == NULL) |
323 |
|
syserror("popen"); |
324 |
|
getheader(fp, NULL, NULL); /* skip header */ |
336 |
|
} |
337 |
|
|
338 |
|
|
356 |
– |
comphist() /* create foveal sampled image and histogram */ |
357 |
– |
{ |
358 |
– |
double l, b, lwmin, lwmax; |
359 |
– |
register int x, y; |
360 |
– |
|
361 |
– |
lwmin = 1e10; /* find extrema */ |
362 |
– |
lwmax = 0.; |
363 |
– |
for (y = 0; y < fvyr; y++) |
364 |
– |
for (x = 0; x < fvxr; x++) { |
365 |
– |
l = plum(fovscan(y)[x]); |
366 |
– |
if (l < lwmin) lwmin = l; |
367 |
– |
if (l > lwmax) lwmax = l; |
368 |
– |
} |
369 |
– |
lwmin -= FTINY; |
370 |
– |
lwmax += FTINY; |
371 |
– |
if (lwmin < LMIN) lwmin = LMIN; |
372 |
– |
if (lwmax > LMAX) lwmax = LMAX; |
373 |
– |
/* compute histogram */ |
374 |
– |
bwmin = Bl(lwmin); |
375 |
– |
bwmax = Bl(lwmax); |
376 |
– |
bwavg = 0.; |
377 |
– |
for (y = 0; y < fvyr; y++) |
378 |
– |
for (x = 0; x < fvxr; x++) { |
379 |
– |
l = plum(fovscan(y)[x]); |
380 |
– |
if (l < lwmin) continue; |
381 |
– |
if (l > lwmax) continue; |
382 |
– |
b = Bl(l); |
383 |
– |
bwavg += b; |
384 |
– |
l = what2do&DO_CWEIGHT ? centprob(x,y) : 1.; |
385 |
– |
bwhist[bwhi(b)] += l; |
386 |
– |
histot += l; |
387 |
– |
} |
388 |
– |
bwavg /= histot; |
389 |
– |
} |
390 |
– |
|
391 |
– |
|
339 |
|
check2do() /* check histogram to see what isn't worth doing */ |
340 |
|
{ |
341 |
|
double sum; |
343 |
|
register int i; |
344 |
|
|
345 |
|
/* check for within display range */ |
346 |
< |
l = Lb(bwmax)/Lb(bwmin); |
400 |
< |
if (l <= ldmax/ldmin) |
346 |
> |
if (bwmax - bwmin <= Bldmax - Bldmin) |
347 |
|
what2do |= DO_LINEAR; |
348 |
|
/* determine if veiling significant */ |
349 |
< |
if (l < 100.) /* heuristic */ |
349 |
> |
if (bwmax - bwmin < 4.5) /* heuristic */ |
350 |
|
what2do &= ~DO_VEIL; |
351 |
|
|
352 |
|
if (!(what2do & (DO_ACUITY|DO_COLOR))) |