--- ray/src/px/pcond.c 1998/03/12 15:47:33 3.12 +++ ray/src/px/pcond.c 2003/07/27 22:12:03 3.17 @@ -1,13 +1,12 @@ -/* Copyright (c) 1997 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: pcond.c,v 3.17 2003/07/27 22:12:03 schorsch Exp $"; #endif - /* * Condition Radiance picture for display/output + * Added white-balance adjustment 10/01 (GW). */ +#include "platform.h" #include "pcond.h" @@ -32,10 +31,11 @@ double fixfrac = 0.; /* histogram share due to fixat RESOLU inpres; /* input picture resolution */ COLOR *fovimg; /* foveal (1 degree) averaged image */ -short fvxr, fvyr; /* foveal image resolution */ +int fvxr, fvyr; /* foveal image resolution */ +float *crfimg; /* contrast reduction factors */ short (*fixlst)[2]; /* fixation history list */ int nfixations; /* number of fixation points */ -float bwhist[HISTRES]; /* luminance histogram */ +double bwhist[HISTRES]; /* luminance histogram */ double histot; /* total count of histogram */ double bwmin, bwmax; /* histogram limits */ double bwavg; /* mean brightness */ @@ -106,7 +106,7 @@ char *argv[]; case 'e': if (i+1 >= argc) goto userr; scalef = atof(argv[++i]); - if (argv[i][0] == '+' | argv[i][0] == '-') + if ((argv[i][0] == '+') | (argv[i][0] == '-')) scalef = pow(2.0, scalef); what2do |= DO_LINEAR; break; @@ -151,7 +151,7 @@ char *argv[]; progname); exit(1); } - if (outprims == stdprims & inprims != stdprims) + if ((outprims == stdprims) & (inprims != stdprims)) outprims = inprims; Bldmin = Bl(ldmax/lddyn); Bldmax = Bl(ldmax); @@ -163,13 +163,11 @@ char *argv[]; /* open output file */ if (i+2 == argc && freopen(argv[i+1], "w", stdout) == NULL) syserror(argv[i+1]); -#ifdef MSDOS - setmode(fileno(infp), O_BINARY); - setmode(fileno(stdout), O_BINARY); -#endif + SET_FILE_BINARY(infp); + SET_FILE_BINARY(stdout); getahead(); /* load input header */ printargs(argc, argv, stdout); /* add to output header */ - if (mbcalfile == NULL & outprims != stdprims) + if ((mbcalfile == NULL) & (outprims != stdprims)) fputprims(outprims, stdout); if ((what2do & (DO_PREHIST|DO_VEIL|DO_ACUITY)) != DO_PREHIST) getfovimg(); /* get foveal sample image? */ @@ -208,22 +206,22 @@ char *s; if (!strcmp(fmt,COLRFMT)) lumf = rgblum; else if (!strcmp(fmt,CIEFMT)) lumf = cielum; else lumf = NULL; - return; /* don't echo */ + return(0); /* don't echo */ } if (isprims(s)) { /* get input primaries */ primsval(inprimS, s); inprims= inprimS; - return; /* don't echo */ + return(0); /* don't echo */ } if (isexpos(s)) { /* picture exposure */ inpexp *= exposval(s); - return; /* don't echo */ + return(0); /* don't echo */ } if (isaspect(s)) /* pixel aspect ratio */ pixaspect *= aspectval(s); if (isview(s)) /* image view */ gotview += sscanview(&ourview, s); - fputs(s, stdout); + return(fputs(s, stdout)); } @@ -238,14 +236,14 @@ getahead() /* load picture header */ exit(1); } if (lumf == rgblum) - comprgb2xyzmat(inrgb2xyz, inprims); + comprgb2xyzWBmat(inrgb2xyz, inprims); else if (mbcalfile != NULL) { fprintf(stderr, "%s: macbethcal only works with RGB pictures\n", progname); exit(1); } if (!gotview || ourview.type == VT_PAR) { - copystruct(&ourview, &stdview); + ourview = stdview; ourview.type = VT_PER; if (pixaspect*inpres.yr < inpres.xr) { ourview.horiz = 40.0; @@ -272,9 +270,14 @@ mapimage() /* map picture and send to stdout */ comphist(); /* generate adaptation histogram */ check2do(); /* modify what2do flags */ if (what2do&DO_VEIL) - compveil(); - if (!(what2do&DO_LINEAR) && mkbrmap() < 0) /* make tone map */ - what2do |= DO_LINEAR; /* failed! -- use linear scaling */ + compveil(); /* compute veil image */ + if (!(what2do&DO_LINEAR)) + if (mkbrmap() < 0) /* make tone map */ + what2do |= DO_LINEAR; /* failed! -- use linear */ +#if ADJ_VEIL + else if (what2do&DO_VEIL) + adjveil(); /* else adjust veil image */ +#endif if (what2do&DO_LINEAR) { if (scalef <= FTINY) { if (what2do&DO_HSENS) @@ -311,7 +314,7 @@ getfovimg() /* load foveal sampled image */ if (fvxr < 2) fvxr = 2; fvyr = sqrt(ourview.vn2)/FOVDIA + 0.5; if (fvyr < 2) fvyr = 2; - if (!(inpres.or & YMAJOR)) { /* picture is rotated? */ + if (!(inpres.rt & YMAJOR)) { /* picture is rotated? */ y = fvyr; fvyr = fvxr; fvxr = y; @@ -322,7 +325,7 @@ getfovimg() /* load foveal sampled image */ if ((fp = popen(combuf, "r")) == NULL) syserror("popen"); getheader(fp, NULL, NULL); /* skip header */ - if (fgetresolu(&x, &y, fp) < 0 || x != fvxr | y != fvyr) + if (fgetresolu(&x, &y, fp) < 0 || (x != fvxr) | (y != fvyr)) goto readerr; for (y = 0; y < fvyr; y++) if (freadscan(fovscan(y), fvxr, fp) < 0)