| 77 |
|
#define NMBNEU 6 /* Number of MacBeth neutral colors */ |
| 78 |
|
short mbneu[NMBNEU] = {Black,Neutral35,Neutral5,Neutral65,Neutral8,White}; |
| 79 |
|
|
| 80 |
< |
#define NMBMOD 16 /* Number of MacBeth unsaturated colors */ |
| 81 |
< |
short mbmod[NMBMOD] = { |
| 82 |
< |
DarkSkin,LightSkin,BlueSky,Foliage,BlueFlower,BluishGreen, |
| 83 |
< |
PurplishBlue,ModerateRed,YellowGreen,OrangeYellow, |
| 84 |
< |
Black,Neutral35,Neutral5,Neutral65,Neutral8,White |
| 85 |
< |
}; |
| 80 |
> |
#define NEUFLGS (1L<<White|1L<<Neutral8|1L<<Neutral65| \ |
| 81 |
> |
1L<<Neutral5|1L<<Neutral35|1L<<Black) |
| 82 |
|
|
| 83 |
< |
#define NMBSAT 8 /* Number of MacBeth saturated colors */ |
| 84 |
< |
short mbsat[NMBSAT] = { |
| 85 |
< |
Red,Green,Blue,Magenta,Yellow,Cyan, |
| 90 |
< |
Orange,Purple |
| 91 |
< |
}; |
| 83 |
> |
#define SATFLGS (1L<<Red|1L<<Green|1L<<Blue|1L<<Magenta|1L<<Yellow| \ |
| 84 |
> |
1L<<Cyan|1L<<Orange|1L<<Purple|1L<<PurplishBlue| \ |
| 85 |
> |
1L<<YellowGreen|1<<OrangeYellow|1L<<BlueFlower) |
| 86 |
|
|
| 87 |
+ |
#define UNSFLGS (1L<<DarkSkin|1L<<LightSkin|1L<<BlueSky|1L<<Foliage| \ |
| 88 |
+ |
1L<<BluishGreen|1L<<ModerateRed) |
| 89 |
+ |
|
| 90 |
+ |
#define REQFLGS NEUFLGS /* need these colors */ |
| 91 |
+ |
#define MODFLGS (NEUFLGS|UNSFLGS) /* should be in gamut */ |
| 92 |
+ |
|
| 93 |
+ |
#define RG_BORD 0 /* patch border */ |
| 94 |
+ |
#define RG_CENT 01 /* central region of patch */ |
| 95 |
+ |
#define RG_ORIG 02 /* original color region */ |
| 96 |
+ |
#define RG_CORR 04 /* corrected color region */ |
| 97 |
+ |
|
| 98 |
|
int xmax, ymax; /* input image dimensions */ |
| 99 |
|
int bounds[4][2]; /* image coordinates of chart corners */ |
| 100 |
|
double imgxfm[3][3]; /* coordinate transformation matrix */ |
| 101 |
|
|
| 102 |
< |
COLOR picRGB[24]; /* picture colors */ |
| 102 |
> |
COLOR inpRGB[24]; /* measured or scanned input colors */ |
| 103 |
> |
long inpflags = 0; /* flags of which colors were input */ |
| 104 |
> |
long gmtflags = 0; /* flags of out-of-gamut colors */ |
| 105 |
|
|
| 106 |
|
COLOR bramp[NMBNEU][2]; /* brightness ramp (per primary) */ |
| 107 |
|
double solmat[3][3]; /* color mapping matrix */ |
| 116 |
|
int argc; |
| 117 |
|
char **argv; |
| 118 |
|
{ |
| 119 |
+ |
int inpispic = 1; |
| 120 |
|
int i; |
| 121 |
|
|
| 122 |
|
progname = argv[0]; |
| 123 |
< |
if (argc > 2 && !strcmp(argv[1], "-d")) { /* debug output */ |
| 124 |
< |
if ((debugfp = fopen(argv[2], "w")) == NULL) { |
| 125 |
< |
perror(argv[2]); |
| 126 |
< |
exit(1); |
| 127 |
< |
} |
| 123 |
> |
for (i = 1; i < argc && argv[i][0] == '-'; i++) |
| 124 |
> |
switch (argv[i][1]) { |
| 125 |
> |
case 'd': /* debug output */ |
| 126 |
> |
i++; |
| 127 |
> |
if (badarg(argc-i, argv+i, "s")) |
| 128 |
> |
goto userr; |
| 129 |
> |
if ((debugfp = fopen(argv[i], "w")) == NULL) { |
| 130 |
> |
perror(argv[i]); |
| 131 |
> |
exit(1); |
| 132 |
> |
} |
| 133 |
|
#ifdef MSDOS |
| 134 |
< |
setmode(fileno(debugfp), O_BINARY); |
| 134 |
> |
setmode(fileno(debugfp), O_BINARY); |
| 135 |
|
#endif |
| 136 |
< |
newheader("RADIANCE", debugfp); |
| 137 |
< |
printargs(argc, argv, debugfp); |
| 138 |
< |
argv += 2; |
| 139 |
< |
argc -= 2; |
| 140 |
< |
} |
| 141 |
< |
if (argc != 3 && argc != 11) |
| 142 |
< |
goto userr; |
| 143 |
< |
if (strcmp(argv[1], "-") && freopen(argv[1], "r", stdin) == NULL) { |
| 136 |
> |
newheader("RADIANCE", debugfp); /* start */ |
| 137 |
> |
printargs(argc, argv, debugfp); /* header */ |
| 138 |
> |
break; |
| 139 |
> |
case 'p': /* picture position */ |
| 140 |
> |
if (badarg(argc-i-1, argv+i+1, "iiiiiiii")) |
| 141 |
> |
goto userr; |
| 142 |
> |
bounds[0][0] = atoi(argv[++i]); |
| 143 |
> |
bounds[0][1] = atoi(argv[++i]); |
| 144 |
> |
bounds[1][0] = atoi(argv[++i]); |
| 145 |
> |
bounds[1][1] = atoi(argv[++i]); |
| 146 |
> |
bounds[2][0] = atoi(argv[++i]); |
| 147 |
> |
bounds[2][1] = atoi(argv[++i]); |
| 148 |
> |
bounds[3][0] = atoi(argv[++i]); |
| 149 |
> |
bounds[3][1] = atoi(argv[++i]); |
| 150 |
> |
inpispic = 2; |
| 151 |
> |
break; |
| 152 |
> |
case 'c': /* color input */ |
| 153 |
> |
inpispic = 0; |
| 154 |
> |
break; |
| 155 |
> |
default: |
| 156 |
> |
goto userr; |
| 157 |
> |
} |
| 158 |
> |
/* open files */ |
| 159 |
> |
if (i < argc && freopen(argv[i], "r", stdin) == NULL) { |
| 160 |
|
perror(argv[1]); |
| 161 |
|
exit(1); |
| 162 |
|
} |
| 163 |
< |
if (strcmp(argv[2], "-") && freopen(argv[2], "w", stdout) == NULL) { |
| 163 |
> |
if (i+1 < argc && freopen(argv[i+1], "w", stdout) == NULL) { |
| 164 |
|
perror(argv[2]); |
| 165 |
|
exit(1); |
| 166 |
|
} |
| 167 |
+ |
if (inpispic) { /* load input picture header */ |
| 168 |
|
#ifdef MSDOS |
| 169 |
< |
setmode(fileno(stdin), O_BINARY); |
| 169 |
> |
setmode(fileno(stdin), O_BINARY); |
| 170 |
|
#endif |
| 171 |
< |
if (checkheader(stdin, COLRFMT, NULL) < 0 || |
| 172 |
< |
fgetresolu(&xmax, &ymax, stdin) < 0) { |
| 173 |
< |
fprintf(stderr, "%s: bad input picture\n", progname); |
| 174 |
< |
exit(1); |
| 145 |
< |
} |
| 146 |
< |
/* get chart boundaries */ |
| 147 |
< |
if (argc == 11) { |
| 148 |
< |
for (i = 0; i < 4; i++) { |
| 149 |
< |
if (!isint(argv[2*i+3]) | !isint(argv[2*i+4])) |
| 150 |
< |
goto userr; |
| 151 |
< |
bounds[i][0] = atoi(argv[2*i+3]); |
| 152 |
< |
bounds[i][1] = atoi(argv[2*i+4]); |
| 171 |
> |
if (checkheader(stdin, COLRFMT, NULL) < 0 || |
| 172 |
> |
fgetresolu(&xmax, &ymax, stdin) < 0) { |
| 173 |
> |
fprintf(stderr, "%s: bad input picture\n", progname); |
| 174 |
> |
exit(1); |
| 175 |
|
} |
| 176 |
< |
} else { |
| 176 |
> |
} else { /* else set default xmax and ymax */ |
| 177 |
> |
xmax = 512; |
| 178 |
> |
ymax = 2*512/3; |
| 179 |
> |
} |
| 180 |
> |
if (inpispic != 2) { /* use default boundaries */ |
| 181 |
|
bounds[0][0] = bounds[2][0] = .029*xmax + .5; |
| 182 |
|
bounds[0][1] = bounds[1][1] = .956*ymax + .5; |
| 183 |
|
bounds[1][0] = bounds[3][0] = .971*xmax + .5; |
| 184 |
|
bounds[2][1] = bounds[3][1] = .056*ymax + .5; |
| 185 |
|
} |
| 186 |
|
init(); /* initialize */ |
| 187 |
< |
getcolors(); /* get picture colors */ |
| 187 |
> |
if (inpispic) /* get picture colors */ |
| 188 |
> |
getpicture(); |
| 189 |
> |
else |
| 190 |
> |
getcolors(); |
| 191 |
|
compute(); /* compute color mapping */ |
| 192 |
|
/* print comment */ |
| 193 |
< |
printf("{ Color correction file computed by %s }\n", progname); |
| 194 |
< |
printf("{ from scanned MacBetch color chart %s }\n", argv[1]); |
| 193 |
> |
printf("{\n\tColor correction file computed by:\n\t\t"); |
| 194 |
> |
printargs(argc, argv, stdout); |
| 195 |
> |
printf("\n\tUsage: pcomb -f %s uncorrected.pic > corrected.pic\n", |
| 196 |
> |
i+1 < argc ? argv[i+1] : "{this_file}"); |
| 197 |
> |
printf("}\n"); |
| 198 |
|
putmapping(); /* put out color mapping */ |
| 199 |
< |
putdebug(); /* put out debug picture */ |
| 199 |
> |
if (debugfp != NULL) /* put out debug picture */ |
| 200 |
> |
if (inpispic) |
| 201 |
> |
picdebug(); |
| 202 |
> |
else |
| 203 |
> |
clrdebug(); |
| 204 |
|
exit(0); |
| 205 |
|
userr: |
| 206 |
< |
fprintf(stderr, "Usage: %s [-d dbg.pic] input.pic output.cal [xul yul xur yur xll yll xlr ylr]\n", |
| 206 |
> |
fprintf(stderr, |
| 207 |
> |
"Usage: %s [-d dbg.pic][-p xul yul xur yur xll yll xlr ylr] input.pic [output.cal]\n", |
| 208 |
|
progname); |
| 209 |
+ |
fprintf(stderr, " or: %s [-d dbg.pic] -c [xyY.dat [output.cal]]\n", |
| 210 |
+ |
progname); |
| 211 |
|
exit(1); |
| 212 |
|
} |
| 213 |
|
|
| 215 |
|
init() /* initialize */ |
| 216 |
|
{ |
| 217 |
|
double quad[4][2]; |
| 218 |
+ |
register int i; |
| 219 |
|
/* make coordinate transformation */ |
| 220 |
|
quad[0][0] = bounds[0][0]; |
| 221 |
|
quad[0][1] = bounds[0][1]; |
| 230 |
|
fprintf(stderr, "%s: bad chart boundaries\n", progname); |
| 231 |
|
exit(1); |
| 232 |
|
} |
| 233 |
+ |
/* map MacBeth colors to RGB space */ |
| 234 |
+ |
for (i = 0; i < 24; i++) |
| 235 |
+ |
xyY2RGB(mbRGB[i], mbxyY[i]); |
| 236 |
|
} |
| 237 |
|
|
| 238 |
|
|
| 239 |
|
int |
| 240 |
< |
chartndx(x, y) /* find color number for position */ |
| 240 |
> |
chartndx(x, y, np) /* find color number for position */ |
| 241 |
|
int x, y; |
| 242 |
+ |
int *np; |
| 243 |
|
{ |
| 244 |
|
double ipos[3], cpos[3]; |
| 245 |
|
int ix, iy; |
| 252 |
|
cpos[0] /= cpos[2]; |
| 253 |
|
cpos[1] /= cpos[2]; |
| 254 |
|
if (cpos[0] < 0. || cpos[0] >= 6. || cpos[1] < 0. || cpos[1] >= 4.) |
| 255 |
< |
return(-1); |
| 255 |
> |
return(RG_BORD); |
| 256 |
|
ix = cpos[0]; |
| 257 |
|
iy = cpos[1]; |
| 258 |
|
fx = cpos[0] - ix; |
| 259 |
|
fy = cpos[1] - iy; |
| 260 |
< |
if (fx < .35 || fx >= .65 || fy < .35 || fy >= .65) |
| 261 |
< |
return(-1); |
| 262 |
< |
return(iy*6 + ix); |
| 260 |
> |
*np = iy*6 + ix; |
| 261 |
> |
if (fx >= 0.35 && fx < 0.65 && fy >= 0.35 && fy < 0.65) |
| 262 |
> |
return(RG_CENT); |
| 263 |
> |
if (fx < 0.05 || fx >= 0.95 || fy < 0.05 || fy >= 0.95) |
| 264 |
> |
return(RG_BORD); |
| 265 |
> |
if (fx >= 0.5) /* right side is corrected */ |
| 266 |
> |
return(RG_CORR); |
| 267 |
> |
return(RG_ORIG); /* left side is original */ |
| 268 |
|
} |
| 269 |
|
|
| 270 |
|
|
| 271 |
< |
getcolors() /* load in picture colors */ |
| 271 |
> |
getpicture() /* load in picture colors */ |
| 272 |
|
{ |
| 273 |
|
COLR *scanln; |
| 274 |
|
COLOR pval; |
| 275 |
|
int ccount[24]; |
| 276 |
|
double d; |
| 277 |
< |
int y; |
| 278 |
< |
register int x, i; |
| 277 |
> |
int y, i; |
| 278 |
> |
register int x; |
| 279 |
|
|
| 280 |
|
scanln = (COLR *)malloc(xmax*sizeof(COLR)); |
| 281 |
|
if (scanln == NULL) { |
| 283 |
|
exit(1); |
| 284 |
|
} |
| 285 |
|
for (i = 0; i < 24; i++) { |
| 286 |
< |
setcolor(picRGB[i], 0., 0., 0.); |
| 286 |
> |
setcolor(inpRGB[i], 0., 0., 0.); |
| 287 |
|
ccount[i] = 0; |
| 288 |
|
} |
| 289 |
|
for (y = ymax-1; y >= 0; y--) { |
| 292 |
|
progname); |
| 293 |
|
exit(1); |
| 294 |
|
} |
| 295 |
< |
for (x = 0; x < xmax; x++) { |
| 296 |
< |
i = chartndx(x, y); |
| 248 |
< |
if (i >= 0) { |
| 295 |
> |
for (x = 0; x < xmax; x++) |
| 296 |
> |
if (chartndx(x, y, &i) == RG_CENT) { |
| 297 |
|
colr_color(pval, scanln[x]); |
| 298 |
< |
addcolor(picRGB[i], pval); |
| 298 |
> |
addcolor(inpRGB[i], pval); |
| 299 |
|
ccount[i]++; |
| 300 |
|
} |
| 301 |
+ |
} |
| 302 |
+ |
for (i = 0; i < 24; i++) { /* compute averages */ |
| 303 |
+ |
if (ccount[i] == 0) |
| 304 |
+ |
continue; |
| 305 |
+ |
d = 1./ccount[i]; |
| 306 |
+ |
scalecolor(inpRGB[i], d); |
| 307 |
+ |
inpflags |= 1L<<i; |
| 308 |
+ |
} |
| 309 |
+ |
free((char *)scanln); |
| 310 |
+ |
} |
| 311 |
+ |
|
| 312 |
+ |
|
| 313 |
+ |
getcolors() /* get xyY colors from standard input */ |
| 314 |
+ |
{ |
| 315 |
+ |
int gotwhite = 0; |
| 316 |
+ |
COLOR whiteclr; |
| 317 |
+ |
int n; |
| 318 |
+ |
float xyYin[3]; |
| 319 |
+ |
|
| 320 |
+ |
while (fgetval(stdin, 'i', &n) == 1) { /* read colors */ |
| 321 |
+ |
if (n < 0 | n > 24 || |
| 322 |
+ |
fgetval(stdin, 'f', &xyYin[0]) != 1 || |
| 323 |
+ |
fgetval(stdin, 'f', &xyYin[1]) != 1 || |
| 324 |
+ |
fgetval(stdin, 'f', &xyYin[2]) != 1 || |
| 325 |
+ |
xyYin[0] < 0. | xyYin[0] > 1. | |
| 326 |
+ |
xyYin[1] < 0. | xyYin[1] > 1.) { |
| 327 |
+ |
fprintf(stderr, "%s: bad color input data\n", |
| 328 |
+ |
progname); |
| 329 |
+ |
exit(1); |
| 330 |
|
} |
| 331 |
+ |
if (n == 0) { /* calibration white */ |
| 332 |
+ |
xyY2RGB(whiteclr, xyYin); |
| 333 |
+ |
gotwhite++; |
| 334 |
+ |
} else { /* standard color */ |
| 335 |
+ |
n--; |
| 336 |
+ |
xyY2RGB(inpRGB[n], xyYin); |
| 337 |
+ |
inpflags |= 1L<<n; |
| 338 |
+ |
} |
| 339 |
|
} |
| 340 |
< |
for (i = 0; i < 24; i++) { |
| 341 |
< |
if (ccount[i] == 0) { |
| 342 |
< |
fprintf(stderr, "%s: bad chart boundaries\n", |
| 340 |
> |
/* normalize colors */ |
| 341 |
> |
if (!gotwhite) { |
| 342 |
> |
if (!(inpflags & 1L<<White)) { |
| 343 |
> |
fprintf(stderr, "%s: missing input for White\n", |
| 344 |
|
progname); |
| 345 |
|
exit(1); |
| 346 |
|
} |
| 347 |
< |
d = 1.0/ccount[i]; |
| 348 |
< |
scalecolor(picRGB[i], d); |
| 347 |
> |
setcolor(whiteclr, |
| 348 |
> |
colval(inpRGB[White],RED)/colval(mbRGB[White],RED), |
| 349 |
> |
colval(inpRGB[White],GRN)/colval(mbRGB[White],GRN), |
| 350 |
> |
colval(inpRGB[White],BLU)/colval(mbRGB[White],BLU)); |
| 351 |
|
} |
| 352 |
< |
free((char *)scanln); |
| 352 |
> |
for (n = 0; n < 24; n++) |
| 353 |
> |
if (inpflags & 1L<<n) |
| 354 |
> |
setcolor(inpRGB[n], |
| 355 |
> |
colval(inpRGB[n],RED)/colval(whiteclr,RED), |
| 356 |
> |
colval(inpRGB[n],GRN)/colval(whiteclr,GRN), |
| 357 |
> |
colval(inpRGB[n],BLU)/colval(whiteclr,BLU)); |
| 358 |
|
} |
| 359 |
|
|
| 360 |
|
|
| 361 |
|
bresp(y, x) /* piecewise linear interpolation of primaries */ |
| 362 |
|
COLOR y, x; |
| 363 |
|
{ |
| 271 |
– |
double cv[3]; |
| 364 |
|
register int i, n; |
| 365 |
|
|
| 366 |
|
for (i = 0; i < 3; i++) { |
| 367 |
|
for (n = 0; n < NMBNEU-2; n++) |
| 368 |
|
if (colval(x,i) < colval(bramp[n+1][0],i)) |
| 369 |
|
break; |
| 370 |
< |
cv[i] = ((colval(bramp[n+1][0],i) - colval(x,i)) * |
| 370 |
> |
colval(y,i) = ((colval(bramp[n+1][0],i) - colval(x,i)) * |
| 371 |
|
colval(bramp[n][1],i) + |
| 372 |
|
(colval(x,i) - colval(bramp[n][0],i)) * |
| 373 |
|
colval(bramp[n+1][1],i)) / |
| 374 |
|
(colval(bramp[n+1][0],i) - colval(bramp[n][0],i)); |
| 283 |
– |
if (cv[i] < 0.) cv[i] = 0.; |
| 375 |
|
} |
| 285 |
– |
setcolor(y, cv[0], cv[1], cv[2]); |
| 376 |
|
} |
| 377 |
|
|
| 378 |
|
|
| 379 |
|
compute() /* compute color mapping */ |
| 380 |
|
{ |
| 381 |
< |
COLOR clrin[NMBMOD], clrout[NMBMOD]; |
| 381 |
> |
COLOR clrin[24], clrout[24]; |
| 382 |
> |
long cflags; |
| 383 |
|
COLOR ctmp; |
| 384 |
< |
double d; |
| 385 |
< |
register int i; |
| 386 |
< |
/* map MacBeth colors to RGB space */ |
| 387 |
< |
for (i = 0; i < 24; i++) { |
| 388 |
< |
d = mbxyY[i][2] / mbxyY[i][1]; |
| 389 |
< |
ctmp[0] = mbxyY[i][0] * d; |
| 299 |
< |
ctmp[1] = mbxyY[i][2]; |
| 300 |
< |
ctmp[2] = (1. - mbxyY[i][0] - mbxyY[i][1]) * d; |
| 301 |
< |
cie_rgb(mbRGB[i], ctmp); |
| 384 |
> |
register int i, j, n; |
| 385 |
> |
/* did we get what we need? */ |
| 386 |
> |
if ((inpflags & REQFLGS) != REQFLGS) { |
| 387 |
> |
fprintf(stderr, "%s: missing required input colors\n", |
| 388 |
> |
progname); |
| 389 |
> |
exit(1); |
| 390 |
|
} |
| 391 |
|
/* compute piecewise luminance curve */ |
| 392 |
|
for (i = 0; i < NMBNEU; i++) { |
| 393 |
< |
copycolor(bramp[i][0], picRGB[mbneu[i]]); |
| 393 |
> |
copycolor(bramp[i][0], inpRGB[mbneu[i]]); |
| 394 |
|
copycolor(bramp[i][1], mbRGB[mbneu[i]]); |
| 395 |
|
} |
| 396 |
< |
/* compute color matrix */ |
| 397 |
< |
for (i = 0; i < NMBMOD; i++) { |
| 398 |
< |
bresp(clrin[i], picRGB[mbmod[i]]); |
| 399 |
< |
copycolor(clrout[i], mbRGB[mbmod[i]]); |
| 400 |
< |
} |
| 401 |
< |
compsoln(clrin, clrout, NMBMOD); |
| 396 |
> |
/* compute color mapping */ |
| 397 |
> |
do { |
| 398 |
> |
cflags = inpflags & ~gmtflags; |
| 399 |
> |
n = 0; /* compute transform matrix */ |
| 400 |
> |
for (i = 0; i < 24; i++) |
| 401 |
> |
if (cflags & 1L<<i) { |
| 402 |
> |
bresp(clrin[n], inpRGB[i]); |
| 403 |
> |
copycolor(clrout[n], mbRGB[i]); |
| 404 |
> |
n++; |
| 405 |
> |
} |
| 406 |
> |
compsoln(clrin, clrout, n); |
| 407 |
> |
/* check out-of-gamut colors */ |
| 408 |
> |
for (i = 0; i < 24; i++) |
| 409 |
> |
if (cflags & 1L<<i) { |
| 410 |
> |
cresp(ctmp, mbRGB[i]); |
| 411 |
> |
for (j = 0; j < 3; j++) |
| 412 |
> |
if (colval(ctmp,j) <= 0. || |
| 413 |
> |
colval(ctmp,j) >= 1.) { |
| 414 |
> |
gmtflags |= 1L<<i; |
| 415 |
> |
break; |
| 416 |
> |
} |
| 417 |
> |
} |
| 418 |
> |
} while (cflags & gmtflags); |
| 419 |
> |
if (gmtflags & MODFLGS) |
| 420 |
> |
fprintf(stderr, |
| 421 |
> |
"%s: warning - some moderate colors are out of gamut\n", |
| 422 |
> |
progname); |
| 423 |
|
} |
| 424 |
|
|
| 425 |
|
|
| 471 |
|
double colv[3], rowv[3]; |
| 472 |
|
register int i, j, k; |
| 473 |
|
|
| 474 |
< |
if (n < 3 | n > NMBMOD) { |
| 475 |
< |
fprintf(stderr, "%s: inconsistent code!\n", progname); |
| 474 |
> |
if (n < 3) { |
| 475 |
> |
fprintf(stderr, "%s: too few colors to match!\n", progname); |
| 476 |
|
exit(1); |
| 477 |
|
} |
| 478 |
|
if (n == 3) |
| 524 |
|
cvtcolor(cout, cin) /* convert color according to our mapping */ |
| 525 |
|
COLOR cout, cin; |
| 526 |
|
{ |
| 527 |
+ |
COLOR ctmp; |
| 528 |
+ |
|
| 529 |
+ |
bresp(ctmp, cin); |
| 530 |
+ |
cresp(cout, ctmp); |
| 531 |
+ |
if (colval(cout,RED) < 0.) |
| 532 |
+ |
colval(cout,RED) = 0.; |
| 533 |
+ |
if (colval(cout,GRN) < 0.) |
| 534 |
+ |
colval(cout,GRN) = 0.; |
| 535 |
+ |
if (colval(cout,BLU) < 0.) |
| 536 |
+ |
colval(cout,BLU) = 0.; |
| 537 |
+ |
} |
| 538 |
+ |
|
| 539 |
+ |
|
| 540 |
+ |
cresp(cout, cin) /* transform color according to matrix */ |
| 541 |
+ |
COLOR cout, cin; |
| 542 |
+ |
{ |
| 543 |
|
double r, g, b; |
| 544 |
|
|
| 545 |
< |
bresp(cout, cin); |
| 546 |
< |
r = colval(cout,0)*solmat[0][0] + colval(cout,1)*solmat[0][1] |
| 547 |
< |
+ colval(cout,2)*solmat[0][2]; |
| 548 |
< |
if (r < 0) r = 0; |
| 549 |
< |
g = colval(cout,0)*solmat[1][0] + colval(cout,1)*solmat[1][1] |
| 550 |
< |
+ colval(cout,2)*solmat[1][2]; |
| 426 |
< |
if (g < 0) g = 0; |
| 427 |
< |
b = colval(cout,0)*solmat[2][0] + colval(cout,1)*solmat[2][1] |
| 428 |
< |
+ colval(cout,2)*solmat[2][2]; |
| 429 |
< |
if (b < 0) b = 0; |
| 545 |
> |
r = colval(cin,0)*solmat[0][0] + colval(cin,1)*solmat[0][1] |
| 546 |
> |
+ colval(cin,2)*solmat[0][2]; |
| 547 |
> |
g = colval(cin,0)*solmat[1][0] + colval(cin,1)*solmat[1][1] |
| 548 |
> |
+ colval(cin,2)*solmat[1][2]; |
| 549 |
> |
b = colval(cin,0)*solmat[2][0] + colval(cin,1)*solmat[2][1] |
| 550 |
> |
+ colval(cin,2)*solmat[2][2]; |
| 551 |
|
setcolor(cout, r, g, b); |
| 552 |
|
} |
| 553 |
|
|
| 554 |
|
|
| 555 |
< |
putdebug() /* put out debugging picture */ |
| 555 |
> |
xyY2RGB(rgbout, xyYin) /* convert xyY to RGB */ |
| 556 |
> |
COLOR rgbout; |
| 557 |
> |
register float xyYin[3]; |
| 558 |
|
{ |
| 559 |
+ |
COLOR ctmp; |
| 560 |
+ |
double d; |
| 561 |
+ |
|
| 562 |
+ |
d = xyYin[2] / xyYin[1]; |
| 563 |
+ |
ctmp[0] = xyYin[0] * d; |
| 564 |
+ |
ctmp[1] = xyYin[2]; |
| 565 |
+ |
ctmp[2] = (1. - xyYin[0] - xyYin[1]) * d; |
| 566 |
+ |
cie_rgb(rgbout, ctmp); |
| 567 |
+ |
} |
| 568 |
+ |
|
| 569 |
+ |
|
| 570 |
+ |
picdebug() /* put out debugging picture */ |
| 571 |
+ |
{ |
| 572 |
+ |
static COLOR blkcol = BLKCOLOR; |
| 573 |
|
COLOR *scan; |
| 574 |
< |
int y; |
| 575 |
< |
register int x, i; |
| 574 |
> |
int y, i; |
| 575 |
> |
register int x, rg; |
| 576 |
|
|
| 440 |
– |
if (debugfp == NULL) |
| 441 |
– |
return; |
| 577 |
|
if (fseek(stdin, 0L, 0) == EOF) { |
| 578 |
|
fprintf(stderr, "%s: cannot seek on input picture\n", progname); |
| 579 |
|
exit(1); |
| 590 |
|
fputformat(COLRFMT, debugfp); |
| 591 |
|
putc('\n', debugfp); |
| 592 |
|
fprtresolu(xmax, ymax, debugfp); |
| 593 |
+ |
/* write debug picture */ |
| 594 |
|
for (y = ymax-1; y >= 0; y--) { |
| 595 |
|
if (freadscan(scan, xmax, stdin) < 0) { |
| 596 |
|
fprintf(stderr, "%s: error rereading input picture\n", |
| 598 |
|
exit(1); |
| 599 |
|
} |
| 600 |
|
for (x = 0; x < xmax; x++) { |
| 601 |
< |
i = chartndx(x, y); |
| 602 |
< |
if (i < 0) |
| 601 |
> |
rg = chartndx(x, y, &i); |
| 602 |
> |
if (rg == RG_CENT) { |
| 603 |
> |
if (!(1L<<i & gmtflags) || (x+y)&07) |
| 604 |
> |
copycolor(scan[x], mbRGB[i]); |
| 605 |
> |
else |
| 606 |
> |
copycolor(scan[x], blkcol); |
| 607 |
> |
} else if (rg == RG_CORR) |
| 608 |
|
cvtcolor(scan[x], scan[x]); |
| 609 |
< |
else |
| 610 |
< |
copycolor(scan[x], mbRGB[i]); |
| 609 |
> |
else if (rg != RG_ORIG) |
| 610 |
> |
copycolor(scan[x], blkcol); |
| 611 |
|
} |
| 612 |
|
if (fwritescan(scan, xmax, debugfp) < 0) { |
| 613 |
|
fprintf(stderr, "%s: error writing debugging picture\n", |
| 615 |
|
exit(1); |
| 616 |
|
} |
| 617 |
|
} |
| 618 |
+ |
/* clean up */ |
| 619 |
+ |
fclose(debugfp); |
| 620 |
+ |
free((char *)scan); |
| 621 |
+ |
} |
| 622 |
+ |
|
| 623 |
+ |
|
| 624 |
+ |
clrdebug() /* put out debug picture from color input */ |
| 625 |
+ |
{ |
| 626 |
+ |
static COLR blkclr = BLKCOLR; |
| 627 |
+ |
COLR mbclr[24], cvclr[24], orclr[24]; |
| 628 |
+ |
COLR *scan; |
| 629 |
+ |
COLOR ctmp; |
| 630 |
+ |
int y, i; |
| 631 |
+ |
register int x, rg; |
| 632 |
+ |
/* convert colors */ |
| 633 |
+ |
for (i = 0; i < 24; i++) { |
| 634 |
+ |
setcolr(mbclr[i], colval(mbRGB[i],RED), |
| 635 |
+ |
colval(mbRGB[i],GRN), colval(mbRGB[i],BLU)); |
| 636 |
+ |
if (inpflags & 1L<<i) { |
| 637 |
+ |
setcolr(orclr[i], colval(inpRGB[i],RED), |
| 638 |
+ |
colval(inpRGB[i],GRN), |
| 639 |
+ |
colval(inpRGB[i],BLU)); |
| 640 |
+ |
cvtcolor(ctmp, inpRGB[i]); |
| 641 |
+ |
setcolr(cvclr[i], colval(ctmp,RED), |
| 642 |
+ |
colval(ctmp,GRN), colval(ctmp,BLU)); |
| 643 |
+ |
} |
| 644 |
+ |
} |
| 645 |
+ |
/* allocate scanline */ |
| 646 |
+ |
scan = (COLR *)malloc(xmax*sizeof(COLR)); |
| 647 |
+ |
if (scan == NULL) { |
| 648 |
+ |
perror(progname); |
| 649 |
+ |
exit(1); |
| 650 |
+ |
} |
| 651 |
+ |
/* finish debug header */ |
| 652 |
+ |
fputformat(COLRFMT, debugfp); |
| 653 |
+ |
putc('\n', debugfp); |
| 654 |
+ |
fprtresolu(xmax, ymax, debugfp); |
| 655 |
+ |
/* write debug picture */ |
| 656 |
+ |
for (y = ymax-1; y >= 0; y--) { |
| 657 |
+ |
for (x = 0; x < xmax; x++) { |
| 658 |
+ |
rg = chartndx(x, y, &i); |
| 659 |
+ |
if (rg == RG_CENT) { |
| 660 |
+ |
if (!(1L<<i & gmtflags) || (x+y)&07) |
| 661 |
+ |
copycolr(scan[x], mbclr[i]); |
| 662 |
+ |
else |
| 663 |
+ |
copycolr(scan[x], blkclr); |
| 664 |
+ |
} else if (rg == RG_BORD || !(1L<<i & inpflags)) |
| 665 |
+ |
copycolr(scan[x], blkclr); |
| 666 |
+ |
else if (rg == RG_ORIG) |
| 667 |
+ |
copycolr(scan[x], orclr[i]); |
| 668 |
+ |
else /* rg == RG_CORR */ |
| 669 |
+ |
copycolr(scan[x], cvclr[i]); |
| 670 |
+ |
} |
| 671 |
+ |
if (fwritecolrs(scan, xmax, debugfp) < 0) { |
| 672 |
+ |
fprintf(stderr, "%s: error writing debugging picture\n", |
| 673 |
+ |
progname); |
| 674 |
+ |
exit(1); |
| 675 |
+ |
} |
| 676 |
+ |
} |
| 677 |
+ |
/* clean up */ |
| 678 |
+ |
fclose(debugfp); |
| 679 |
|
free((char *)scan); |
| 680 |
|
} |