--- ray/src/px/pcond2.c 1996/10/04 18:34:57 3.3 +++ ray/src/px/pcond2.c 1997/01/31 15:56:20 3.7 @@ -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"; @@ -21,8 +21,9 @@ double inpexp = 1.0; /* input exposure value */ char *mbcalfile = NULL; /* macbethcal mapping 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 COLOR *scanbuf; /* scanline processing buffer */ @@ -60,10 +61,8 @@ COLOR * nextscan() /* read and condition next scanline */ { if (nread >= numscans(&inpres)) { -#ifdef DEBUG - fputs("done\n", stderr); -#endif - return(NULL); + free((char *)scanbuf); + return(scanbuf = NULL); } if (what2do&DO_ACUITY) acuscan(scanbuf, nread); @@ -99,23 +98,12 @@ firstscan() /* return first processed scanline */ comprgb2rgbmat(mbcond.cmat, inprims, outprims); else compxyz2rgbmat(mbcond.cmat, outprims); - if (what2do&DO_ACUITY) { -#ifdef DEBUG - fprintf(stderr, "%s: initializing acuity sampling...", - progname); -#endif + if (what2do&DO_ACUITY) initacuity(); -#ifdef DEBUG - fprintf(stderr, "done\n"); -#endif - } scanbuf = (COLOR *)malloc(scanlen(&inpres)*sizeof(COLOR)); if (scanbuf == NULL) syserror("malloc"); nread = 0; -#ifdef DEBUG - fprintf(stderr, "%s: processing image...", progname); -#endif return(nextscan()); } @@ -139,6 +127,7 @@ COLORMAT mat; { while (len--) { colortrans(sl[0], mat, sl[0]); + clipgamut(sl[0], bright(sl[0]), CGAMUT, cblack, cwhite); sl++; } } @@ -153,6 +142,8 @@ register struct mbc *mb; register int i, j; 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++) @@ -161,7 +152,6 @@ register struct mbc *mb; (d - mb->xa[i][j])*mb->ya[i][j+1] ) / (mb->xa[i][j+1] - mb->xa[i][j]); } - colortrans(sl[0], mb->cmat, sl[0]); sl++; } } @@ -175,6 +165,7 @@ register struct mbc *mb; char buf[128]; FILE *fp; int inpflags = 0; + register int i; if ((fp = fopen(fn, "r")) == NULL) syserror(fn); @@ -229,19 +220,19 @@ register struct mbc *mb; inpflags |= 040; else if (!(inpflags & 0100) && sscanf(buf, - "ro = %f*rn + %f*gn + %f*bn", + "r = %f*r1 + %f*g1 + %f*b1", &mb->cmat[0][0], &mb->cmat[0][1], &mb->cmat[0][2]) == 3) inpflags |= 0100; else if (!(inpflags & 0200) && sscanf(buf, - "go = %f*rn + %f*gn + %f*bn", + "g = %f*r1 + %f*g1 + %f*b1", &mb->cmat[1][0], &mb->cmat[1][1], &mb->cmat[1][2]) == 3) inpflags |= 0200; else if (!(inpflags & 0400) && sscanf(buf, - "bo = %f*rn + %f*gn + %f*bn", + "b = %f*r1 + %f*g1 + %f*b1", &mb->cmat[2][0], &mb->cmat[2][1], &mb->cmat[2][2]) == 3) inpflags |= 0400; @@ -253,4 +244,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]); + } }