--- ray/src/px/pcond2.c 1997/01/30 17:06:27 3.6 +++ ray/src/px/pcond2.c 1997/02/05 16:08:18 3.8 @@ -1,4 +1,4 @@ -/* Copyright (c) 1996 Regents of the University of California */ +/* Copyright (c) 1997 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -9,6 +9,7 @@ static char SCCSid[] = "$SunId$ LBL"; */ #include "pcond.h" +#include "warp3d.h" RGBPRIMP inprims = stdprims; /* input primaries */ @@ -19,12 +20,16 @@ double (*lumf)() = rgblum; /* input luminance functio double inpexp = 1.0; /* input exposure value */ char *mbcalfile = NULL; /* macbethcal mapping file */ +char *cwarpfile = NULL; /* color space warping file */ static struct mbc { - float xa[3][6], ya[3][6]; COLORMAT cmat; + float xa[3][6], ya[3][6]; + COLOR cmin, cmax; } mbcond; /* macbethcal conditioning struct */ +static WARP3D *cwarp; /* color warping structure */ + static COLOR *scanbuf; /* scanline processing buffer */ static int nread; /* number of scanlines processed */ @@ -60,6 +65,8 @@ COLOR * nextscan() /* read and condition next scanline */ { if (nread >= numscans(&inpres)) { + if (cwarpfile != NULL) + free3dw(cwarp); free((char *)scanbuf); return(scanbuf = NULL); } @@ -80,6 +87,8 @@ nextscan() /* read and condition next scanline */ mapscan(scanbuf, scanlen(&inpres)); if (mbcalfile != NULL) /* device color correction */ mbscan(scanbuf, scanlen(&inpres), &mbcond); + else if (cwarpfile != NULL) /* device color space warp */ + cwscan(scanbuf, scanlen(&inpres), cwarp); else if (lumf == cielum | inprims != outprims) matscan(scanbuf, scanlen(&inpres), mbcond.cmat); nread++; @@ -92,7 +101,10 @@ firstscan() /* return first processed scanline */ { if (mbcalfile != NULL) /* load macbethcal file */ getmbcalfile(mbcalfile, &mbcond); - else + else if (cwarpfile != NULL) { + if ((cwarp = load3dw(cwarpfile, NULL)) == NULL) + syserror(cwarpfile); + } else if (lumf == rgblum) comprgb2rgbmat(mbcond.cmat, inprims, outprims); else @@ -126,6 +138,7 @@ COLORMAT mat; { while (len--) { colortrans(sl[0], mat, sl[0]); + clipgamut(sl[0], bright(sl[0]), CGAMUT, cblack, cwhite); sl++; } } @@ -141,6 +154,7 @@ register struct mbc *mb; while (len--) { colortrans(sl[0], mb->cmat, sl[0]); + clipgamut(sl[0], bright(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++) @@ -154,6 +168,28 @@ register struct mbc *mb; } +cwscan(sl, len, wp) /* apply color space warp to scaline */ +COLOR *sl; +int len; +WARP3D *wp; +{ + int rval; + + while (len--) { + rval = warp3d(sl[0], sl[0], wp); + if (rval & W3ERROR) + syserror("warp3d"); + if (rval & W3BADMAP) { + fprintf(stderr, "%s: %s: bad color space map\n", + progname, cwarpfile); + exit(1); + } + clipgamut(sl[0], bright(sl[0]), CGAMUT, cblack, cwhite); + sl++; + } +} + + getmbcalfile(fn, mb) /* load macbethcal file */ char *fn; register struct mbc *mb; @@ -162,6 +198,7 @@ register struct mbc *mb; char buf[128]; FILE *fp; int inpflags = 0; + register int i; if ((fp = fopen(fn, "r")) == NULL) syserror(fn); @@ -240,4 +277,15 @@ register struct mbc *mb; exit(1); } fclose(fp); + /* compute gamut */ + for (i = 0; i < 3; i++) { + colval(mb->cmin,i) = mb->xa[i][0] - + mb->ya[i][0] * + (mb->xa[i][1]-mb->xa[i][0]) / + (mb->ya[i][1]-mb->ya[i][0]); + colval(mb->cmax,i) = mb->xa[i][4] + + (1.-mb->ya[i][4]) * + (mb->xa[i][5] - mb->xa[i][4]) / + (mb->ya[i][5] - mb->ya[i][4]); + } }