--- ray/src/px/pcond2.c 1997/01/31 15:56:20 3.7 +++ ray/src/px/pcond2.c 1999/01/25 11:51:37 3.9 @@ -9,6 +9,7 @@ static char SCCSid[] = "$SunId$ LBL"; */ #include "pcond.h" +#include "warp3d.h" RGBPRIMP inprims = stdprims; /* input primaries */ @@ -19,6 +20,7 @@ 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 { COLORMAT cmat; @@ -26,6 +28,8 @@ static struct mbc { 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 */ @@ -61,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); } @@ -81,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++; @@ -93,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 @@ -157,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; @@ -220,19 +253,19 @@ register struct mbc *mb; inpflags |= 040; else if (!(inpflags & 0100) && sscanf(buf, - "r = %f*r1 + %f*g1 + %f*b1", + "ro = %f*rn + %f*gn + %f*bn", &mb->cmat[0][0], &mb->cmat[0][1], &mb->cmat[0][2]) == 3) inpflags |= 0100; else if (!(inpflags & 0200) && sscanf(buf, - "g = %f*r1 + %f*g1 + %f*b1", + "go = %f*rn + %f*gn + %f*bn", &mb->cmat[1][0], &mb->cmat[1][1], &mb->cmat[1][2]) == 3) inpflags |= 0200; else if (!(inpflags & 0400) && sscanf(buf, - "b = %f*r1 + %f*g1 + %f*b1", + "bo = %f*rn + %f*gn + %f*bn", &mb->cmat[2][0], &mb->cmat[2][1], &mb->cmat[2][2]) == 3) inpflags |= 0400;