| 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 "pcond.h" |
| 11 |
|
|
| 12 |
|
|
| 31 |
|
RESOLU inpres; /* input picture resolution */ |
| 32 |
|
|
| 33 |
|
COLOR *fovimg; /* foveal (1 degree) averaged image */ |
| 34 |
< |
short fvxr, fvyr; /* foveal image resolution */ |
| 34 |
> |
int fvxr, fvyr; /* foveal image resolution */ |
| 35 |
> |
float *crfimg; /* contrast reduction factors */ |
| 36 |
|
short (*fixlst)[2]; /* fixation history list */ |
| 37 |
|
int nfixations; /* number of fixation points */ |
| 38 |
< |
float bwhist[HISTRES]; /* luminance histogram */ |
| 38 |
> |
double bwhist[HISTRES]; /* luminance histogram */ |
| 39 |
|
double histot; /* total count of histogram */ |
| 40 |
|
double bwmin, bwmax; /* histogram limits */ |
| 41 |
|
double bwavg; /* mean brightness */ |
| 163 |
|
/* open output file */ |
| 164 |
|
if (i+2 == argc && freopen(argv[i+1], "w", stdout) == NULL) |
| 165 |
|
syserror(argv[i+1]); |
| 166 |
< |
#ifdef MSDOS |
| 167 |
< |
setmode(fileno(infp), O_BINARY); |
| 168 |
< |
setmode(fileno(stdout), O_BINARY); |
| 169 |
< |
#endif |
| 166 |
> |
SET_FILE_BINARY(infp); |
| 167 |
> |
SET_FILE_BINARY(stdout); |
| 168 |
|
getahead(); /* load input header */ |
| 169 |
|
printargs(argc, argv, stdout); /* add to output header */ |
| 170 |
|
if (mbcalfile == NULL & outprims != stdprims) |
| 206 |
|
if (!strcmp(fmt,COLRFMT)) lumf = rgblum; |
| 207 |
|
else if (!strcmp(fmt,CIEFMT)) lumf = cielum; |
| 208 |
|
else lumf = NULL; |
| 209 |
< |
return; /* don't echo */ |
| 209 |
> |
return(0); /* don't echo */ |
| 210 |
|
} |
| 211 |
|
if (isprims(s)) { /* get input primaries */ |
| 212 |
|
primsval(inprimS, s); |
| 213 |
|
inprims= inprimS; |
| 214 |
< |
return; /* don't echo */ |
| 214 |
> |
return(0); /* don't echo */ |
| 215 |
|
} |
| 216 |
|
if (isexpos(s)) { /* picture exposure */ |
| 217 |
|
inpexp *= exposval(s); |
| 218 |
< |
return; /* don't echo */ |
| 218 |
> |
return(0); /* don't echo */ |
| 219 |
|
} |
| 220 |
|
if (isaspect(s)) /* pixel aspect ratio */ |
| 221 |
|
pixaspect *= aspectval(s); |
| 222 |
|
if (isview(s)) /* image view */ |
| 223 |
|
gotview += sscanview(&ourview, s); |
| 224 |
< |
fputs(s, stdout); |
| 224 |
> |
return(fputs(s, stdout)); |
| 225 |
|
} |
| 226 |
|
|
| 227 |
|
|
| 236 |
|
exit(1); |
| 237 |
|
} |
| 238 |
|
if (lumf == rgblum) |
| 239 |
< |
comprgb2xyzmat(inrgb2xyz, inprims); |
| 239 |
> |
comprgb2xyzWBmat(inrgb2xyz, inprims); |
| 240 |
|
else if (mbcalfile != NULL) { |
| 241 |
|
fprintf(stderr, "%s: macbethcal only works with RGB pictures\n", |
| 242 |
|
progname); |
| 270 |
|
comphist(); /* generate adaptation histogram */ |
| 271 |
|
check2do(); /* modify what2do flags */ |
| 272 |
|
if (what2do&DO_VEIL) |
| 273 |
< |
compveil(); |
| 274 |
< |
if (!(what2do&DO_LINEAR) && mkbrmap() < 0) /* make tone map */ |
| 275 |
< |
what2do |= DO_LINEAR; /* failed! -- use linear scaling */ |
| 273 |
> |
compveil(); /* compute veil image */ |
| 274 |
> |
if (!(what2do&DO_LINEAR)) |
| 275 |
> |
if (mkbrmap() < 0) /* make tone map */ |
| 276 |
> |
what2do |= DO_LINEAR; /* failed! -- use linear */ |
| 277 |
> |
#if ADJ_VEIL |
| 278 |
> |
else if (what2do&DO_VEIL) |
| 279 |
> |
adjveil(); /* else adjust veil image */ |
| 280 |
> |
#endif |
| 281 |
|
if (what2do&DO_LINEAR) { |
| 282 |
|
if (scalef <= FTINY) { |
| 283 |
|
if (what2do&DO_HSENS) |
| 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; |