--- ray/src/px/pcond2.c 1999/01/25 11:51:37 3.9 +++ ray/src/px/pcond2.c 2015/08/21 05:48:28 3.18 @@ -1,11 +1,9 @@ -/* Copyright (c) 1997 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: pcond2.c,v 3.18 2015/08/21 05:48:28 greg Exp $"; #endif - /* * Input and output conditioning routines for pcond. + * Added white-balance adjustment 10/01 (GW). */ #include "pcond.h" @@ -33,11 +31,18 @@ static WARP3D *cwarp; /* color warping structure */ static COLOR *scanbuf; /* scanline processing buffer */ static int nread; /* number of scanlines processed */ +static void sfscan(COLOR *sl, int len, double sf); +static void matscan(COLOR *sl, int len, COLORMAT mat); +static void mbscan(COLOR *sl, int len, struct mbc *mb); +static void cwscan(COLOR *sl, int len, WARP3D *wp); +static void getmbcalfile(char *fn, struct mbc *mb); + double -rgblum(clr, scotopic) /* compute (scotopic) luminance of RGB color */ -COLOR clr; -int scotopic; +rgblum( /* compute (scotopic) luminance of RGB color */ + COLOR clr, + int scotopic +) { if (scotopic) /* approximate */ return( WHTSEFFICACY * (colval(clr,RED)*.062 + @@ -49,9 +54,10 @@ int scotopic; double -cielum(xyz, scotopic) /* compute (scotopic) luminance of CIE color */ -COLOR xyz; -int scotopic; +cielum( /* compute (scotopic) luminance of CIE color */ + COLOR xyz, + int scotopic +) { if (scotopic) /* approximate */ return(colval(xyz,CIEY) * @@ -62,12 +68,12 @@ int scotopic; COLOR * -nextscan() /* read and condition next scanline */ +nextscan(void) /* read and condition next scanline */ { if (nread >= numscans(&inpres)) { if (cwarpfile != NULL) free3dw(cwarp); - free((char *)scanbuf); + free((void *)scanbuf); return(scanbuf = NULL); } if (what2do&DO_ACUITY) @@ -89,7 +95,7 @@ nextscan() /* read and condition next scanline */ mbscan(scanbuf, scanlen(&inpres), &mbcond); else if (cwarpfile != NULL) /* device color space warp */ cwscan(scanbuf, scanlen(&inpres), cwarp); - else if (lumf == cielum | inprims != outprims) + else if ((lumf == cielum) | (inprims != outprims)) matscan(scanbuf, scanlen(&inpres), mbcond.cmat); nread++; return(scanbuf); @@ -97,7 +103,7 @@ nextscan() /* read and condition next scanline */ COLOR * -firstscan() /* return first processed scanline */ +firstscan(void) /* return first processed scanline */ { if (mbcalfile != NULL) /* load macbethcal file */ getmbcalfile(mbcalfile, &mbcond); @@ -106,9 +112,9 @@ firstscan() /* return first processed scanline */ syserror(cwarpfile); } else if (lumf == rgblum) - comprgb2rgbmat(mbcond.cmat, inprims, outprims); + comprgb2rgbWBmat(mbcond.cmat, inprims, outprims); else - compxyz2rgbmat(mbcond.cmat, outprims); + compxyz2rgbWBmat(mbcond.cmat, outprims); if (what2do&DO_ACUITY) initacuity(); scanbuf = (COLOR *)malloc(scanlen(&inpres)*sizeof(COLOR)); @@ -119,10 +125,12 @@ firstscan() /* return first processed scanline */ } -sfscan(sl, len, sf) /* apply scalefactor to scanline */ -register COLOR *sl; -int len; -double sf; +static void +sfscan( /* apply scalefactor to scanline */ + COLOR *sl, + int len, + double sf +) { while (len--) { scalecolor(sl[0], sf); @@ -131,30 +139,52 @@ double sf; } -matscan(sl, len, mat) /* apply color matrix to scaline */ -register COLOR *sl; -int len; -COLORMAT mat; +static double +greypoint( /* compute gamut mapping grey target */ + COLOR col +) { + COLOR gryc; + int i; + /* improves saturated color rendering */ + copycolor(gryc, col); + for (i = 3; i--; ) + if (gryc[i] > 1) + gryc[i] = 1; + else if (gryc[i] < 0) + gryc[i] = 0; + return(bright(gryc)); +} + + +static void +matscan( /* apply color matrix to scaline */ + COLOR *sl, + int len, + COLORMAT mat +) +{ while (len--) { colortrans(sl[0], mat, sl[0]); - clipgamut(sl[0], bright(sl[0]), CGAMUT, cblack, cwhite); + clipgamut(sl[0], greypoint(sl[0]), CGAMUT, cblack, cwhite); sl++; } } -mbscan(sl, len, mb) /* apply macbethcal adj. to scaline */ -COLOR *sl; -int len; -register struct mbc *mb; +static void +mbscan( /* apply macbethcal adj. to scaline */ + COLOR *sl, + int len, + struct mbc *mb +) { double d; - register int i, j; + int i, j; while (len--) { colortrans(sl[0], mb->cmat, sl[0]); - clipgamut(sl[0], bright(sl[0]), CGAMUT, mb->cmin, mb->cmax); + clipgamut(sl[0], greypoint(sl[0]), CGAMUT, mb->cmin, mb->cmax); for (i = 0; i < 3; i++) { d = colval(sl[0],i); for (j = 0; j < 4 && mb->xa[i][j+1] <= d; j++) @@ -168,10 +198,12 @@ register struct mbc *mb; } -cwscan(sl, len, wp) /* apply color space warp to scaline */ -COLOR *sl; -int len; -WARP3D *wp; +static void +cwscan( /* apply color space warp to scaline */ + COLOR *sl, + int len, + WARP3D *wp +) { int rval; @@ -184,21 +216,22 @@ WARP3D *wp; progname, cwarpfile); exit(1); } - clipgamut(sl[0], bright(sl[0]), CGAMUT, cblack, cwhite); + clipgamut(sl[0], greypoint(sl[0]), CGAMUT, cblack, cwhite); sl++; } } -getmbcalfile(fn, mb) /* load macbethcal file */ -char *fn; -register struct mbc *mb; +static void +getmbcalfile( /* load macbethcal file */ + char *fn, + struct mbc *mb +) { - extern char *fgets(); char buf[128]; FILE *fp; int inpflags = 0; - register int i; + int i; if ((fp = fopen(fn, "r")) == NULL) syserror(fn);