| 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"; |
| 9 |
|
*/ |
| 10 |
|
|
| 11 |
|
#include "pcond.h" |
| 12 |
+ |
#include "warp3d.h" |
| 13 |
|
|
| 14 |
|
|
| 15 |
|
RGBPRIMP inprims = stdprims; /* input primaries */ |
| 20 |
|
double inpexp = 1.0; /* input exposure value */ |
| 21 |
|
|
| 22 |
|
char *mbcalfile = NULL; /* macbethcal mapping file */ |
| 23 |
+ |
char *cwarpfile = NULL; /* color space warping file */ |
| 24 |
|
|
| 25 |
< |
static struct mbc mbcond; /* macbethcal conditioning struct */ |
| 25 |
> |
static struct mbc { |
| 26 |
> |
COLORMAT cmat; |
| 27 |
> |
float xa[3][6], ya[3][6]; |
| 28 |
> |
COLOR cmin, cmax; |
| 29 |
> |
} mbcond; /* macbethcal conditioning struct */ |
| 30 |
|
|
| 31 |
+ |
static WARP3D *cwarp; /* color warping structure */ |
| 32 |
+ |
|
| 33 |
|
static COLOR *scanbuf; /* scanline processing buffer */ |
| 34 |
|
static int nread; /* number of scanlines processed */ |
| 35 |
|
|
| 65 |
|
nextscan() /* read and condition next scanline */ |
| 66 |
|
{ |
| 67 |
|
if (nread >= numscans(&inpres)) { |
| 68 |
< |
#ifdef DEBUG |
| 69 |
< |
fputs("done\n", stderr); |
| 70 |
< |
#endif |
| 71 |
< |
return(NULL); |
| 68 |
> |
if (cwarpfile != NULL) |
| 69 |
> |
free3dw(cwarp); |
| 70 |
> |
free((char *)scanbuf); |
| 71 |
> |
return(scanbuf = NULL); |
| 72 |
|
} |
| 73 |
< |
if (freadscan(scanbuf, scanlen(&inpres), infp) < 0) { |
| 73 |
> |
if (what2do&DO_ACUITY) |
| 74 |
> |
acuscan(scanbuf, nread); |
| 75 |
> |
else if (freadscan(scanbuf, scanlen(&inpres), infp) < 0) { |
| 76 |
|
fprintf(stderr, "%s: %s: scanline read error\n", |
| 77 |
|
progname, infn); |
| 78 |
|
exit(1); |
| 79 |
|
} |
| 70 |
– |
nread++; |
| 80 |
|
if (what2do&DO_VEIL) /* add veiling */ |
| 81 |
< |
addveil(scanbuf, nread-1); |
| 81 |
> |
addveil(scanbuf, nread); |
| 82 |
|
if (what2do&DO_COLOR) /* scotopic color loss */ |
| 83 |
|
scotscan(scanbuf, scanlen(&inpres)); |
| 84 |
|
if (what2do&DO_LINEAR) /* map luminances */ |
| 87 |
|
mapscan(scanbuf, scanlen(&inpres)); |
| 88 |
|
if (mbcalfile != NULL) /* device color correction */ |
| 89 |
|
mbscan(scanbuf, scanlen(&inpres), &mbcond); |
| 90 |
+ |
else if (cwarpfile != NULL) /* device color space warp */ |
| 91 |
+ |
cwscan(scanbuf, scanlen(&inpres), cwarp); |
| 92 |
|
else if (lumf == cielum | inprims != outprims) |
| 93 |
|
matscan(scanbuf, scanlen(&inpres), mbcond.cmat); |
| 94 |
+ |
nread++; |
| 95 |
|
return(scanbuf); |
| 96 |
|
} |
| 97 |
|
|
| 101 |
|
{ |
| 102 |
|
if (mbcalfile != NULL) /* load macbethcal file */ |
| 103 |
|
getmbcalfile(mbcalfile, &mbcond); |
| 104 |
< |
else |
| 104 |
> |
else if (cwarpfile != NULL) { |
| 105 |
> |
if ((cwarp = load3dw(cwarpfile, NULL)) == NULL) |
| 106 |
> |
syserror(cwarpfile); |
| 107 |
> |
} else |
| 108 |
|
if (lumf == rgblum) |
| 109 |
|
comprgb2rgbmat(mbcond.cmat, inprims, outprims); |
| 110 |
|
else |
| 111 |
|
compxyz2rgbmat(mbcond.cmat, outprims); |
| 112 |
+ |
if (what2do&DO_ACUITY) |
| 113 |
+ |
initacuity(); |
| 114 |
|
scanbuf = (COLOR *)malloc(scanlen(&inpres)*sizeof(COLOR)); |
| 115 |
|
if (scanbuf == NULL) |
| 116 |
|
syserror("malloc"); |
| 117 |
|
nread = 0; |
| 101 |
– |
#ifdef DEBUG |
| 102 |
– |
fprintf(stderr, "%s: processing image...", progname); |
| 103 |
– |
#endif |
| 118 |
|
return(nextscan()); |
| 119 |
|
} |
| 120 |
|
|
| 138 |
|
{ |
| 139 |
|
while (len--) { |
| 140 |
|
colortrans(sl[0], mat, sl[0]); |
| 141 |
+ |
clipgamut(sl[0], bright(sl[0]), CGAMUT, cblack, cwhite); |
| 142 |
|
sl++; |
| 143 |
|
} |
| 144 |
|
} |
| 153 |
|
register int i, j; |
| 154 |
|
|
| 155 |
|
while (len--) { |
| 156 |
+ |
colortrans(sl[0], mb->cmat, sl[0]); |
| 157 |
+ |
clipgamut(sl[0], bright(sl[0]), CGAMUT, mb->cmin, mb->cmax); |
| 158 |
|
for (i = 0; i < 3; i++) { |
| 159 |
|
d = colval(sl[0],i); |
| 160 |
|
for (j = 0; j < 4 && mb->xa[i][j+1] <= d; j++) |
| 163 |
|
(d - mb->xa[i][j])*mb->ya[i][j+1] ) / |
| 164 |
|
(mb->xa[i][j+1] - mb->xa[i][j]); |
| 165 |
|
} |
| 149 |
– |
colortrans(sl[0], mb->cmat, sl[0]); |
| 166 |
|
sl++; |
| 167 |
|
} |
| 168 |
|
} |
| 169 |
|
|
| 170 |
|
|
| 171 |
+ |
cwscan(sl, len, wp) /* apply color space warp to scaline */ |
| 172 |
+ |
COLOR *sl; |
| 173 |
+ |
int len; |
| 174 |
+ |
WARP3D *wp; |
| 175 |
+ |
{ |
| 176 |
+ |
int rval; |
| 177 |
+ |
|
| 178 |
+ |
while (len--) { |
| 179 |
+ |
rval = warp3d(sl[0], sl[0], wp); |
| 180 |
+ |
if (rval & W3ERROR) |
| 181 |
+ |
syserror("warp3d"); |
| 182 |
+ |
if (rval & W3BADMAP) { |
| 183 |
+ |
fprintf(stderr, "%s: %s: bad color space map\n", |
| 184 |
+ |
progname, cwarpfile); |
| 185 |
+ |
exit(1); |
| 186 |
+ |
} |
| 187 |
+ |
clipgamut(sl[0], bright(sl[0]), CGAMUT, cblack, cwhite); |
| 188 |
+ |
sl++; |
| 189 |
+ |
} |
| 190 |
+ |
} |
| 191 |
+ |
|
| 192 |
+ |
|
| 193 |
|
getmbcalfile(fn, mb) /* load macbethcal file */ |
| 194 |
|
char *fn; |
| 195 |
|
register struct mbc *mb; |
| 198 |
|
char buf[128]; |
| 199 |
|
FILE *fp; |
| 200 |
|
int inpflags = 0; |
| 201 |
+ |
register int i; |
| 202 |
|
|
| 203 |
|
if ((fp = fopen(fn, "r")) == NULL) |
| 204 |
|
syserror(fn); |
| 277 |
|
exit(1); |
| 278 |
|
} |
| 279 |
|
fclose(fp); |
| 280 |
+ |
/* compute gamut */ |
| 281 |
+ |
for (i = 0; i < 3; i++) { |
| 282 |
+ |
colval(mb->cmin,i) = mb->xa[i][0] - |
| 283 |
+ |
mb->ya[i][0] * |
| 284 |
+ |
(mb->xa[i][1]-mb->xa[i][0]) / |
| 285 |
+ |
(mb->ya[i][1]-mb->ya[i][0]); |
| 286 |
+ |
colval(mb->cmax,i) = mb->xa[i][4] + |
| 287 |
+ |
(1.-mb->ya[i][4]) * |
| 288 |
+ |
(mb->xa[i][5] - mb->xa[i][4]) / |
| 289 |
+ |
(mb->ya[i][5] - mb->ya[i][4]); |
| 290 |
+ |
} |
| 291 |
|
} |