| 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 "rtprocess.h" |
| 11 |
|
#include "pcond.h" |
| 12 |
|
|
| 13 |
|
|
| 32 |
|
RESOLU inpres; /* input picture resolution */ |
| 33 |
|
|
| 34 |
|
COLOR *fovimg; /* foveal (1 degree) averaged image */ |
| 35 |
< |
short fvxr, fvyr; /* foveal image resolution */ |
| 35 |
> |
int fvxr, fvyr; /* foveal image resolution */ |
| 36 |
> |
float *crfimg; /* contrast reduction factors */ |
| 37 |
|
short (*fixlst)[2]; /* fixation history list */ |
| 38 |
|
int nfixations; /* number of fixation points */ |
| 39 |
< |
float bwhist[HISTRES]; /* luminance histogram */ |
| 39 |
> |
double bwhist[HISTRES]; /* luminance histogram */ |
| 40 |
|
double histot; /* total count of histogram */ |
| 41 |
|
double bwmin, bwmax; /* histogram limits */ |
| 42 |
|
double bwavg; /* mean brightness */ |
| 107 |
|
case 'e': |
| 108 |
|
if (i+1 >= argc) goto userr; |
| 109 |
|
scalef = atof(argv[++i]); |
| 110 |
< |
if (argv[i][0] == '+' | argv[i][0] == '-') |
| 110 |
> |
if ((argv[i][0] == '+') | (argv[i][0] == '-')) |
| 111 |
|
scalef = pow(2.0, scalef); |
| 112 |
|
what2do |= DO_LINEAR; |
| 113 |
|
break; |
| 152 |
|
progname); |
| 153 |
|
exit(1); |
| 154 |
|
} |
| 155 |
< |
if (outprims == stdprims & inprims != stdprims) |
| 155 |
> |
if ((outprims == stdprims) & (inprims != stdprims)) |
| 156 |
|
outprims = inprims; |
| 157 |
|
Bldmin = Bl(ldmax/lddyn); |
| 158 |
|
Bldmax = Bl(ldmax); |
| 164 |
|
/* open output file */ |
| 165 |
|
if (i+2 == argc && freopen(argv[i+1], "w", stdout) == NULL) |
| 166 |
|
syserror(argv[i+1]); |
| 167 |
< |
#ifdef MSDOS |
| 168 |
< |
setmode(fileno(infp), O_BINARY); |
| 168 |
< |
setmode(fileno(stdout), O_BINARY); |
| 169 |
< |
#endif |
| 167 |
> |
SET_FILE_BINARY(infp); |
| 168 |
> |
SET_FILE_BINARY(stdout); |
| 169 |
|
getahead(); /* load input header */ |
| 170 |
|
printargs(argc, argv, stdout); /* add to output header */ |
| 171 |
< |
if (mbcalfile == NULL & outprims != stdprims) |
| 171 |
> |
if ((mbcalfile == NULL) & (outprims != stdprims)) |
| 172 |
|
fputprims(outprims, stdout); |
| 173 |
|
if ((what2do & (DO_PREHIST|DO_VEIL|DO_ACUITY)) != DO_PREHIST) |
| 174 |
|
getfovimg(); /* get foveal sample image? */ |
| 237 |
|
exit(1); |
| 238 |
|
} |
| 239 |
|
if (lumf == rgblum) |
| 240 |
< |
comprgb2xyzmat(inrgb2xyz, inprims); |
| 240 |
> |
comprgb2xyzWBmat(inrgb2xyz, inprims); |
| 241 |
|
else if (mbcalfile != NULL) { |
| 242 |
|
fprintf(stderr, "%s: macbethcal only works with RGB pictures\n", |
| 243 |
|
progname); |
| 244 |
|
exit(1); |
| 245 |
|
} |
| 246 |
|
if (!gotview || ourview.type == VT_PAR) { |
| 247 |
< |
copystruct(&ourview, &stdview); |
| 247 |
> |
ourview = stdview; |
| 248 |
|
ourview.type = VT_PER; |
| 249 |
|
if (pixaspect*inpres.yr < inpres.xr) { |
| 250 |
|
ourview.horiz = 40.0; |
| 271 |
|
comphist(); /* generate adaptation histogram */ |
| 272 |
|
check2do(); /* modify what2do flags */ |
| 273 |
|
if (what2do&DO_VEIL) |
| 274 |
< |
compveil(); |
| 275 |
< |
if (!(what2do&DO_LINEAR) && mkbrmap() < 0) /* make tone map */ |
| 276 |
< |
what2do |= DO_LINEAR; /* failed! -- use linear scaling */ |
| 274 |
> |
compveil(); /* compute veil image */ |
| 275 |
> |
if (!(what2do&DO_LINEAR)) |
| 276 |
> |
if (mkbrmap() < 0) /* make tone map */ |
| 277 |
> |
what2do |= DO_LINEAR; /* failed! -- use linear */ |
| 278 |
> |
#if ADJ_VEIL |
| 279 |
> |
else if (what2do&DO_VEIL) |
| 280 |
> |
adjveil(); /* else adjust veil image */ |
| 281 |
> |
#endif |
| 282 |
|
if (what2do&DO_LINEAR) { |
| 283 |
|
if (scalef <= FTINY) { |
| 284 |
|
if (what2do&DO_HSENS) |
| 306 |
|
|
| 307 |
|
getfovimg() /* load foveal sampled image */ |
| 308 |
|
{ |
| 305 |
– |
extern FILE *popen(); |
| 309 |
|
char combuf[128]; |
| 310 |
|
FILE *fp; |
| 311 |
|
int x, y; |
| 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; |
| 325 |
|
if ((fp = popen(combuf, "r")) == NULL) |
| 326 |
|
syserror("popen"); |
| 327 |
|
getheader(fp, NULL, NULL); /* skip header */ |
| 328 |
< |
if (fgetresolu(&x, &y, fp) < 0 || x != fvxr | y != fvyr) |
| 328 |
> |
if (fgetresolu(&x, &y, fp) < 0 || (x != fvxr) | (y != fvyr)) |
| 329 |
|
goto readerr; |
| 330 |
|
for (y = 0; y < fvyr; y++) |
| 331 |
|
if (freadscan(fovscan(y), fvxr, fp) < 0) |