| 1 |
< |
/* Copyright (c) 1996 Regents of the University of California */ |
| 1 |
> |
/* Copyright (c) 1997 Regents of the University of California */ |
| 2 |
|
|
| 3 |
|
#ifndef lint |
| 4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
| 26 |
|
|
| 27 |
|
char *infn; /* input file name */ |
| 28 |
|
FILE *infp; /* input stream */ |
| 29 |
+ |
FILE *mapfp = NULL; /* tone-mapping function stream */ |
| 30 |
|
VIEW ourview = STDVIEW; /* picture view */ |
| 31 |
|
int gotview = 0; /* picture has view */ |
| 32 |
|
double pixaspect = 1.0; /* pixel aspect ratio */ |
| 114 |
|
if (i+1 >= argc) goto userr; |
| 115 |
|
ldmin = atof(argv[++i]); |
| 116 |
|
break; |
| 117 |
+ |
case 'm': |
| 118 |
+ |
if (i+1 >= argc) goto userr; |
| 119 |
+ |
if ((mapfp = fopen(argv[++i], "w")) == NULL) { |
| 120 |
+ |
fprintf(stderr, |
| 121 |
+ |
"%s: cannot open for writing\n", |
| 122 |
+ |
argv[i]); |
| 123 |
+ |
exit(1); |
| 124 |
+ |
} |
| 125 |
+ |
break; |
| 126 |
|
default: |
| 127 |
|
goto userr; |
| 128 |
|
} |
| 157 |
|
if (outprims != inprims) |
| 158 |
|
fputprims(outprims, stdout); |
| 159 |
|
mapimage(); /* map the picture */ |
| 160 |
+ |
if (mapfp != NULL) /* write out basic mapping */ |
| 161 |
+ |
putmapping(mapfp); |
| 162 |
|
exit(0); |
| 163 |
|
userr: |
| 164 |
< |
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] inpic [outpic]\n", |
| 164 |
> |
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", |
| 165 |
|
progname); |
| 166 |
|
exit(1); |
| 167 |
|
#undef bool |
| 290 |
|
fprintf(stderr, "%s: linear scaling factor = %f\n", |
| 291 |
|
progname, scalef); |
| 292 |
|
#endif |
| 293 |
< |
if (scalef < 0.99 | scalef > 1.01) |
| 282 |
< |
fputexpos(scalef, stdout); /* write in header */ |
| 293 |
> |
fputexpos(inpexp*scalef, stdout); /* record exposure */ |
| 294 |
|
if (lumf == cielum) scalef /= WHTEFFICACY; |
| 295 |
|
} |
| 296 |
|
putchar('\n'); /* complete header */ |
| 357 |
|
if (lwmin < LMIN) lwmin = LMIN; |
| 358 |
|
if (lwmax > LMAX) lwmax = LMAX; |
| 359 |
|
/* compute histogram */ |
| 360 |
< |
bwmin = Bl(lwmin)*(1. - .01/HISTRES); |
| 361 |
< |
bwmax = Bl(lwmax)*(1. + .01/HISTRES); |
| 360 |
> |
bwmin = Bl(lwmin); |
| 361 |
> |
bwmax = Bl(lwmax); |
| 362 |
|
bwavg = 0.; |
| 363 |
|
for (y = 0; y < fvyr; y++) |
| 364 |
|
for (x = 0; x < fvxr; x++) { |
| 366 |
|
frandom() > centprob(x,y)) |
| 367 |
|
continue; |
| 368 |
|
l = plum(fovscan(y)[x]); |
| 369 |
+ |
if (l < lwmin) continue; |
| 370 |
+ |
if (l > lwmax) continue; |
| 371 |
|
b = Bl(l); |
| 359 |
– |
if (b < bwmin) continue; |
| 360 |
– |
if (b > bwmax) continue; |
| 372 |
|
bwavg += b; |
| 373 |
|
bwhc(b)++; |
| 374 |
|
histot++; |
| 389 |
|
register int i; |
| 390 |
|
|
| 391 |
|
/* check for within display range */ |
| 392 |
< |
if (!(what2do&DO_LINEAR) && Lb(bwmax)/Lb(bwmin) <= ldmax/ldmin) |
| 392 |
> |
l = Lb(bwmax)/Lb(bwmin); |
| 393 |
> |
if (l <= ldmax/ldmin) |
| 394 |
|
what2do |= DO_LINEAR; |
| 395 |
+ |
/* determine if veiling significant */ |
| 396 |
+ |
if (l < 100.) /* heuristic */ |
| 397 |
+ |
what2do &= ~DO_VEIL; |
| 398 |
|
|
| 399 |
< |
if (!(what2do & (DO_ACUITY|DO_COLOR|DO_VEIL))) |
| 399 |
> |
if (!(what2do & (DO_ACUITY|DO_COLOR))) |
| 400 |
|
return; |
| 401 |
|
/* find 5th percentile */ |
| 402 |
|
sum = histot*0.05 + .5; |
| 405 |
|
break; |
| 406 |
|
b = (i+.5)*(bwmax-bwmin)/HISTRES + bwmin; |
| 407 |
|
l = Lb(b); |
| 393 |
– |
#if 0 |
| 408 |
|
/* determine if acuity adj. useful */ |
| 409 |
|
if (what2do&DO_ACUITY && |
| 410 |
|
hacuity(l) >= (inpres.xr/sqrt(ourview.hn2) + |
| 411 |
< |
inpres.yr/sqrt(ourview.vn2))/(2.*180./PI*2.)) |
| 411 |
> |
inpres.yr/sqrt(ourview.vn2))/(2.*180./PI)) |
| 412 |
|
what2do &= ~DO_ACUITY; |
| 399 |
– |
#endif |
| 413 |
|
/* color sensitivity loss? */ |
| 414 |
< |
if (l >= 6.0) |
| 414 |
> |
if (l >= TopMesopic) |
| 415 |
|
what2do &= ~DO_COLOR; |
| 403 |
– |
if (!(what2do&DO_VEIL)) |
| 404 |
– |
return; |
| 405 |
– |
/* find 50th percentile (median) */ |
| 406 |
– |
sum = histot*0.50 + .5; |
| 407 |
– |
for (i = 0; i < HISTRES; i++) |
| 408 |
– |
if ((sum -= bwhist[i]) <= 0) |
| 409 |
– |
break; |
| 410 |
– |
/* determine if veiling significant */ |
| 411 |
– |
b = (i+.5)*(bwmax-bwmin)/HISTRES + bwmin; |
| 412 |
– |
if ((b-bwmin)/(bwmax-bwmin) >= 0.70) /* heuristic */ |
| 413 |
– |
what2do &= ~DO_VEIL; |
| 416 |
|
} |