| 1 |
< |
/* Copyright (c) 1996 Regents of the University of California */ |
| 1 |
> |
/* Copyright (c) 1997 Regents of the University of California */ |
| 2 |
|
|
| 3 |
|
#ifndef lint |
| 4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
| 20 |
|
|
| 21 |
|
char *mbcalfile = NULL; /* macbethcal mapping file */ |
| 22 |
|
|
| 23 |
< |
static struct mbc mbcond; /* macbethcal conditioning struct */ |
| 23 |
> |
static struct mbc { |
| 24 |
> |
COLORMAT cmat; |
| 25 |
> |
float xa[3][6], ya[3][6]; |
| 26 |
> |
COLOR cmin, cmax; |
| 27 |
> |
} mbcond; /* macbethcal conditioning struct */ |
| 28 |
|
|
| 29 |
|
static COLOR *scanbuf; /* scanline processing buffer */ |
| 30 |
|
static int nread; /* number of scanlines processed */ |
| 61 |
|
nextscan() /* read and condition next scanline */ |
| 62 |
|
{ |
| 63 |
|
if (nread >= numscans(&inpres)) { |
| 64 |
< |
#ifdef DEBUG |
| 65 |
< |
fputs("done\n", stderr); |
| 62 |
< |
#endif |
| 63 |
< |
return(NULL); |
| 64 |
> |
free((char *)scanbuf); |
| 65 |
> |
return(scanbuf = NULL); |
| 66 |
|
} |
| 67 |
< |
if (freadscan(scanbuf, scanlen(&inpres), infp) < 0) { |
| 67 |
> |
if (what2do&DO_ACUITY) |
| 68 |
> |
acuscan(scanbuf, nread); |
| 69 |
> |
else if (freadscan(scanbuf, scanlen(&inpres), infp) < 0) { |
| 70 |
|
fprintf(stderr, "%s: %s: scanline read error\n", |
| 71 |
|
progname, infn); |
| 72 |
|
exit(1); |
| 73 |
|
} |
| 70 |
– |
nread++; |
| 74 |
|
if (what2do&DO_VEIL) /* add veiling */ |
| 75 |
< |
addveil(scanbuf, nread-1); |
| 75 |
> |
addveil(scanbuf, nread); |
| 76 |
|
if (what2do&DO_COLOR) /* scotopic color loss */ |
| 77 |
|
scotscan(scanbuf, scanlen(&inpres)); |
| 78 |
|
if (what2do&DO_LINEAR) /* map luminances */ |
| 83 |
|
mbscan(scanbuf, scanlen(&inpres), &mbcond); |
| 84 |
|
else if (lumf == cielum | inprims != outprims) |
| 85 |
|
matscan(scanbuf, scanlen(&inpres), mbcond.cmat); |
| 86 |
+ |
nread++; |
| 87 |
|
return(scanbuf); |
| 88 |
|
} |
| 89 |
|
|
| 98 |
|
comprgb2rgbmat(mbcond.cmat, inprims, outprims); |
| 99 |
|
else |
| 100 |
|
compxyz2rgbmat(mbcond.cmat, outprims); |
| 101 |
+ |
if (what2do&DO_ACUITY) |
| 102 |
+ |
initacuity(); |
| 103 |
|
scanbuf = (COLOR *)malloc(scanlen(&inpres)*sizeof(COLOR)); |
| 104 |
|
if (scanbuf == NULL) |
| 105 |
|
syserror("malloc"); |
| 106 |
|
nread = 0; |
| 101 |
– |
#ifdef DEBUG |
| 102 |
– |
fprintf(stderr, "%s: processing image...", progname); |
| 103 |
– |
#endif |
| 107 |
|
return(nextscan()); |
| 108 |
|
} |
| 109 |
|
|
| 127 |
|
{ |
| 128 |
|
while (len--) { |
| 129 |
|
colortrans(sl[0], mat, sl[0]); |
| 130 |
+ |
clipgamut(sl[0], bright(sl[0]), CGAMUT, cblack, cwhite); |
| 131 |
|
sl++; |
| 132 |
|
} |
| 133 |
|
} |
| 142 |
|
register int i, j; |
| 143 |
|
|
| 144 |
|
while (len--) { |
| 145 |
+ |
colortrans(sl[0], mb->cmat, sl[0]); |
| 146 |
+ |
clipgamut(sl[0], bright(sl[0]), CGAMUT, mb->cmin, mb->cmax); |
| 147 |
|
for (i = 0; i < 3; i++) { |
| 148 |
|
d = colval(sl[0],i); |
| 149 |
|
for (j = 0; j < 4 && mb->xa[i][j+1] <= d; j++) |
| 152 |
|
(d - mb->xa[i][j])*mb->ya[i][j+1] ) / |
| 153 |
|
(mb->xa[i][j+1] - mb->xa[i][j]); |
| 154 |
|
} |
| 149 |
– |
colortrans(sl[0], mb->cmat, sl[0]); |
| 155 |
|
sl++; |
| 156 |
|
} |
| 157 |
|
} |
| 165 |
|
char buf[128]; |
| 166 |
|
FILE *fp; |
| 167 |
|
int inpflags = 0; |
| 168 |
+ |
register int i; |
| 169 |
|
|
| 170 |
|
if ((fp = fopen(fn, "r")) == NULL) |
| 171 |
|
syserror(fn); |
| 220 |
|
inpflags |= 040; |
| 221 |
|
else if (!(inpflags & 0100) && |
| 222 |
|
sscanf(buf, |
| 223 |
< |
"ro = %f*rn + %f*gn + %f*bn", |
| 223 |
> |
"r = %f*r1 + %f*g1 + %f*b1", |
| 224 |
|
&mb->cmat[0][0], &mb->cmat[0][1], |
| 225 |
|
&mb->cmat[0][2]) == 3) |
| 226 |
|
inpflags |= 0100; |
| 227 |
|
else if (!(inpflags & 0200) && |
| 228 |
|
sscanf(buf, |
| 229 |
< |
"go = %f*rn + %f*gn + %f*bn", |
| 229 |
> |
"g = %f*r1 + %f*g1 + %f*b1", |
| 230 |
|
&mb->cmat[1][0], &mb->cmat[1][1], |
| 231 |
|
&mb->cmat[1][2]) == 3) |
| 232 |
|
inpflags |= 0200; |
| 233 |
|
else if (!(inpflags & 0400) && |
| 234 |
|
sscanf(buf, |
| 235 |
< |
"bo = %f*rn + %f*gn + %f*bn", |
| 235 |
> |
"b = %f*r1 + %f*g1 + %f*b1", |
| 236 |
|
&mb->cmat[2][0], &mb->cmat[2][1], |
| 237 |
|
&mb->cmat[2][2]) == 3) |
| 238 |
|
inpflags |= 0400; |
| 244 |
|
exit(1); |
| 245 |
|
} |
| 246 |
|
fclose(fp); |
| 247 |
+ |
/* compute gamut */ |
| 248 |
+ |
for (i = 0; i < 3; i++) { |
| 249 |
+ |
colval(mb->cmin,i) = mb->xa[i][0] - |
| 250 |
+ |
mb->ya[i][0] * |
| 251 |
+ |
(mb->xa[i][1]-mb->xa[i][0]) / |
| 252 |
+ |
(mb->ya[i][1]-mb->ya[i][0]); |
| 253 |
+ |
colval(mb->cmax,i) = mb->xa[i][4] + |
| 254 |
+ |
(1.-mb->ya[i][4]) * |
| 255 |
+ |
(mb->xa[i][5] - mb->xa[i][4]) / |
| 256 |
+ |
(mb->ya[i][5] - mb->ya[i][4]); |
| 257 |
+ |
} |
| 258 |
|
} |