| 1 |
– |
/* Copyright (c) 1996 Regents of the University of California */ |
| 2 |
– |
|
| 1 |
|
#ifndef lint |
| 2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
| 2 |
> |
static const char RCSid[] = "$Id$"; |
| 3 |
|
#endif |
| 6 |
– |
|
| 4 |
|
/* |
| 5 |
|
* Input and output conditioning routines for pcond. |
| 6 |
+ |
* Added white-balance adjustment 10/01 (GW). |
| 7 |
|
*/ |
| 8 |
|
|
| 9 |
|
#include "pcond.h" |
| 10 |
+ |
#include "warp3d.h" |
| 11 |
|
|
| 12 |
|
|
| 13 |
|
RGBPRIMP inprims = stdprims; /* input primaries */ |
| 18 |
|
double inpexp = 1.0; /* input exposure value */ |
| 19 |
|
|
| 20 |
|
char *mbcalfile = NULL; /* macbethcal mapping file */ |
| 21 |
+ |
char *cwarpfile = NULL; /* color space warping file */ |
| 22 |
|
|
| 23 |
|
static struct mbc { |
| 24 |
– |
float xa[3][6], ya[3][6]; |
| 24 |
|
COLORMAT cmat; |
| 25 |
+ |
float xa[3][6], ya[3][6]; |
| 26 |
+ |
COLOR cmin, cmax; |
| 27 |
|
} mbcond; /* macbethcal conditioning struct */ |
| 28 |
|
|
| 29 |
+ |
static WARP3D *cwarp; /* color warping structure */ |
| 30 |
+ |
|
| 31 |
|
static COLOR *scanbuf; /* scanline processing buffer */ |
| 32 |
|
static int nread; /* number of scanlines processed */ |
| 33 |
|
|
| 63 |
|
nextscan() /* read and condition next scanline */ |
| 64 |
|
{ |
| 65 |
|
if (nread >= numscans(&inpres)) { |
| 66 |
< |
free((char *)scanbuf); |
| 66 |
> |
if (cwarpfile != NULL) |
| 67 |
> |
free3dw(cwarp); |
| 68 |
> |
free((void *)scanbuf); |
| 69 |
|
return(scanbuf = NULL); |
| 70 |
|
} |
| 71 |
|
if (what2do&DO_ACUITY) |
| 85 |
|
mapscan(scanbuf, scanlen(&inpres)); |
| 86 |
|
if (mbcalfile != NULL) /* device color correction */ |
| 87 |
|
mbscan(scanbuf, scanlen(&inpres), &mbcond); |
| 88 |
+ |
else if (cwarpfile != NULL) /* device color space warp */ |
| 89 |
+ |
cwscan(scanbuf, scanlen(&inpres), cwarp); |
| 90 |
|
else if (lumf == cielum | inprims != outprims) |
| 91 |
|
matscan(scanbuf, scanlen(&inpres), mbcond.cmat); |
| 92 |
|
nread++; |
| 99 |
|
{ |
| 100 |
|
if (mbcalfile != NULL) /* load macbethcal file */ |
| 101 |
|
getmbcalfile(mbcalfile, &mbcond); |
| 102 |
< |
else |
| 102 |
> |
else if (cwarpfile != NULL) { |
| 103 |
> |
if ((cwarp = load3dw(cwarpfile, NULL)) == NULL) |
| 104 |
> |
syserror(cwarpfile); |
| 105 |
> |
} else |
| 106 |
|
if (lumf == rgblum) |
| 107 |
< |
comprgb2rgbmat(mbcond.cmat, inprims, outprims); |
| 107 |
> |
comprgb2rgbWBmat(mbcond.cmat, inprims, outprims); |
| 108 |
|
else |
| 109 |
< |
compxyz2rgbmat(mbcond.cmat, outprims); |
| 109 |
> |
compxyz2rgbWBmat(mbcond.cmat, outprims); |
| 110 |
|
if (what2do&DO_ACUITY) |
| 111 |
|
initacuity(); |
| 112 |
|
scanbuf = (COLOR *)malloc(scanlen(&inpres)*sizeof(COLOR)); |
| 136 |
|
{ |
| 137 |
|
while (len--) { |
| 138 |
|
colortrans(sl[0], mat, sl[0]); |
| 139 |
+ |
clipgamut(sl[0], bright(sl[0]), CGAMUT, cblack, cwhite); |
| 140 |
|
sl++; |
| 141 |
|
} |
| 142 |
|
} |
| 151 |
|
register int i, j; |
| 152 |
|
|
| 153 |
|
while (len--) { |
| 154 |
+ |
colortrans(sl[0], mb->cmat, sl[0]); |
| 155 |
+ |
clipgamut(sl[0], bright(sl[0]), CGAMUT, mb->cmin, mb->cmax); |
| 156 |
|
for (i = 0; i < 3; i++) { |
| 157 |
|
d = colval(sl[0],i); |
| 158 |
|
for (j = 0; j < 4 && mb->xa[i][j+1] <= d; j++) |
| 161 |
|
(d - mb->xa[i][j])*mb->ya[i][j+1] ) / |
| 162 |
|
(mb->xa[i][j+1] - mb->xa[i][j]); |
| 163 |
|
} |
| 151 |
– |
colortrans(sl[0], mb->cmat, sl[0]); |
| 164 |
|
sl++; |
| 165 |
|
} |
| 166 |
|
} |
| 167 |
|
|
| 168 |
|
|
| 169 |
+ |
cwscan(sl, len, wp) /* apply color space warp to scaline */ |
| 170 |
+ |
COLOR *sl; |
| 171 |
+ |
int len; |
| 172 |
+ |
WARP3D *wp; |
| 173 |
+ |
{ |
| 174 |
+ |
int rval; |
| 175 |
+ |
|
| 176 |
+ |
while (len--) { |
| 177 |
+ |
rval = warp3d(sl[0], sl[0], wp); |
| 178 |
+ |
if (rval & W3ERROR) |
| 179 |
+ |
syserror("warp3d"); |
| 180 |
+ |
if (rval & W3BADMAP) { |
| 181 |
+ |
fprintf(stderr, "%s: %s: bad color space map\n", |
| 182 |
+ |
progname, cwarpfile); |
| 183 |
+ |
exit(1); |
| 184 |
+ |
} |
| 185 |
+ |
clipgamut(sl[0], bright(sl[0]), CGAMUT, cblack, cwhite); |
| 186 |
+ |
sl++; |
| 187 |
+ |
} |
| 188 |
+ |
} |
| 189 |
+ |
|
| 190 |
+ |
|
| 191 |
|
getmbcalfile(fn, mb) /* load macbethcal file */ |
| 192 |
|
char *fn; |
| 193 |
|
register struct mbc *mb; |
| 196 |
|
char buf[128]; |
| 197 |
|
FILE *fp; |
| 198 |
|
int inpflags = 0; |
| 199 |
+ |
register int i; |
| 200 |
|
|
| 201 |
|
if ((fp = fopen(fn, "r")) == NULL) |
| 202 |
|
syserror(fn); |
| 275 |
|
exit(1); |
| 276 |
|
} |
| 277 |
|
fclose(fp); |
| 278 |
+ |
/* compute gamut */ |
| 279 |
+ |
for (i = 0; i < 3; i++) { |
| 280 |
+ |
colval(mb->cmin,i) = mb->xa[i][0] - |
| 281 |
+ |
mb->ya[i][0] * |
| 282 |
+ |
(mb->xa[i][1]-mb->xa[i][0]) / |
| 283 |
+ |
(mb->ya[i][1]-mb->ya[i][0]); |
| 284 |
+ |
colval(mb->cmax,i) = mb->xa[i][4] + |
| 285 |
+ |
(1.-mb->ya[i][4]) * |
| 286 |
+ |
(mb->xa[i][5] - mb->xa[i][4]) / |
| 287 |
+ |
(mb->ya[i][5] - mb->ya[i][4]); |
| 288 |
+ |
} |
| 289 |
|
} |