| 1 |
< |
/* Copyright (c) 1995 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"; |
| 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 REQFLGS (1L<<White|1L<<Neutral8|1L<<Neutral65| \ |
| 88 |
< |
1L<<Neutral5|1L<<Neutral35|1L<<Black) |
| 87 |
> |
#define UNSFLGS (1L<<DarkSkin|1L<<LightSkin|1L<<BlueSky|1L<<Foliage| \ |
| 88 |
> |
1L<<BluishGreen|1L<<ModerateRed) |
| 89 |
|
|
| 90 |
< |
#define CENTCVG 0.3 /* measured coverage of square sample */ |
| 91 |
< |
#define FULLCVG 0.9 /* coverage of entire square */ |
| 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 scanning = 1; /* scanned input (or recorded output)? */ |
| 99 |
+ |
|
| 100 |
|
int xmax, ymax; /* input image dimensions */ |
| 101 |
|
int bounds[4][2]; /* image coordinates of chart corners */ |
| 102 |
|
double imgxfm[3][3]; /* coordinate transformation matrix */ |
| 103 |
|
|
| 104 |
|
COLOR inpRGB[24]; /* measured or scanned input colors */ |
| 105 |
|
long inpflags = 0; /* flags of which colors were input */ |
| 106 |
+ |
long gmtflags = 0; /* flags of out-of-gamut colors */ |
| 107 |
|
|
| 108 |
|
COLOR bramp[NMBNEU][2]; /* brightness ramp (per primary) */ |
| 109 |
< |
double solmat[3][3]; /* color mapping matrix */ |
| 109 |
> |
COLORMAT solmat; /* color mapping matrix */ |
| 110 |
> |
COLOR colmin, colmax; /* gamut limits */ |
| 111 |
|
|
| 112 |
|
FILE *debugfp = NULL; /* debug output picture */ |
| 113 |
|
char *progname; |
| 119 |
|
int argc; |
| 120 |
|
char **argv; |
| 121 |
|
{ |
| 119 |
– |
int inpispic = 1; |
| 122 |
|
int i; |
| 123 |
|
|
| 124 |
|
progname = argv[0]; |
| 149 |
|
bounds[2][1] = atoi(argv[++i]); |
| 150 |
|
bounds[3][0] = atoi(argv[++i]); |
| 151 |
|
bounds[3][1] = atoi(argv[++i]); |
| 152 |
< |
inpispic = 2; |
| 152 |
> |
scanning = 2; |
| 153 |
|
break; |
| 154 |
|
case 'c': /* color input */ |
| 155 |
< |
inpispic = 0; |
| 155 |
> |
scanning = 0; |
| 156 |
|
break; |
| 157 |
|
default: |
| 158 |
|
goto userr; |
| 159 |
|
} |
| 160 |
|
/* open files */ |
| 161 |
|
if (i < argc && freopen(argv[i], "r", stdin) == NULL) { |
| 162 |
< |
perror(argv[1]); |
| 162 |
> |
perror(argv[i]); |
| 163 |
|
exit(1); |
| 164 |
|
} |
| 165 |
|
if (i+1 < argc && freopen(argv[i+1], "w", stdout) == NULL) { |
| 166 |
< |
perror(argv[2]); |
| 166 |
> |
perror(argv[i+1]); |
| 167 |
|
exit(1); |
| 168 |
|
} |
| 169 |
< |
if (inpispic) { /* load input picture header */ |
| 169 |
> |
if (scanning) { /* load input picture header */ |
| 170 |
|
#ifdef MSDOS |
| 171 |
|
setmode(fileno(stdin), O_BINARY); |
| 172 |
|
#endif |
| 179 |
|
xmax = 512; |
| 180 |
|
ymax = 2*512/3; |
| 181 |
|
} |
| 182 |
< |
if (inpispic != 2) { /* use default boundaries */ |
| 182 |
> |
if (scanning != 2) { /* use default boundaries */ |
| 183 |
|
bounds[0][0] = bounds[2][0] = .029*xmax + .5; |
| 184 |
|
bounds[0][1] = bounds[1][1] = .956*ymax + .5; |
| 185 |
|
bounds[1][0] = bounds[3][0] = .971*xmax + .5; |
| 186 |
|
bounds[2][1] = bounds[3][1] = .056*ymax + .5; |
| 187 |
|
} |
| 188 |
|
init(); /* initialize */ |
| 189 |
< |
if (inpispic) /* get picture colors */ |
| 189 |
> |
if (scanning) /* get picture colors */ |
| 190 |
|
getpicture(); |
| 191 |
|
else |
| 192 |
|
getcolors(); |
| 193 |
|
compute(); /* compute color mapping */ |
| 194 |
|
/* print comment */ |
| 195 |
< |
printf("{ Color correction file computed by:\n\t"); |
| 195 |
> |
printf("{\n\tColor correction file computed by:\n\t\t"); |
| 196 |
|
printargs(argc, argv, stdout); |
| 197 |
+ |
printf("\n\tUsage: pcomb -f %s uncorrected.pic > corrected.pic\n", |
| 198 |
+ |
i+1 < argc ? argv[i+1] : "{this_file}"); |
| 199 |
+ |
if (!scanning) |
| 200 |
+ |
printf("\t Or: pcond [options] -f %s orig.pic > output.pic\n", |
| 201 |
+ |
i+1 < argc ? argv[i+1] : "{this_file}"); |
| 202 |
|
printf("}\n"); |
| 203 |
|
putmapping(); /* put out color mapping */ |
| 204 |
|
if (debugfp != NULL) /* put out debug picture */ |
| 205 |
< |
if (inpispic) |
| 205 |
> |
if (scanning) |
| 206 |
|
picdebug(); |
| 207 |
|
else |
| 208 |
|
clrdebug(); |
| 242 |
|
|
| 243 |
|
|
| 244 |
|
int |
| 245 |
< |
chartndx(x, y, cvg) /* find color number for position */ |
| 245 |
> |
chartndx(x, y, np) /* find color number for position */ |
| 246 |
|
int x, y; |
| 247 |
< |
double cvg; |
| 247 |
> |
int *np; |
| 248 |
|
{ |
| 249 |
|
double ipos[3], cpos[3]; |
| 250 |
|
int ix, iy; |
| 251 |
|
double fx, fy; |
| 245 |
– |
double cmin, cmax; |
| 252 |
|
|
| 253 |
|
ipos[0] = x; |
| 254 |
|
ipos[1] = y; |
| 257 |
|
cpos[0] /= cpos[2]; |
| 258 |
|
cpos[1] /= cpos[2]; |
| 259 |
|
if (cpos[0] < 0. || cpos[0] >= 6. || cpos[1] < 0. || cpos[1] >= 4.) |
| 260 |
< |
return(-1); |
| 260 |
> |
return(RG_BORD); |
| 261 |
|
ix = cpos[0]; |
| 262 |
|
iy = cpos[1]; |
| 263 |
|
fx = cpos[0] - ix; |
| 264 |
|
fy = cpos[1] - iy; |
| 265 |
< |
cmin = .5*(1.-cvg); |
| 266 |
< |
cmax = 1. - cmin; |
| 267 |
< |
if (fx < cmin || fx >= cmax || fy < cmin || fy >= cmax) |
| 268 |
< |
return(-1); |
| 269 |
< |
return(iy*6 + ix); |
| 265 |
> |
*np = iy*6 + ix; |
| 266 |
> |
if (fx >= 0.35 && fx < 0.65 && fy >= 0.35 && fy < 0.65) |
| 267 |
> |
return(RG_CENT); |
| 268 |
> |
if (fx < 0.05 || fx >= 0.95 || fy < 0.05 || fy >= 0.95) |
| 269 |
> |
return(RG_BORD); |
| 270 |
> |
if (fx >= 0.5) /* right side is corrected */ |
| 271 |
> |
return(RG_CORR); |
| 272 |
> |
return(RG_ORIG); /* left side is original */ |
| 273 |
|
} |
| 274 |
|
|
| 275 |
|
|
| 279 |
|
COLOR pval; |
| 280 |
|
int ccount[24]; |
| 281 |
|
double d; |
| 282 |
< |
int y; |
| 283 |
< |
register int x, i; |
| 282 |
> |
int y, i; |
| 283 |
> |
register int x; |
| 284 |
|
|
| 285 |
|
scanln = (COLR *)malloc(xmax*sizeof(COLR)); |
| 286 |
|
if (scanln == NULL) { |
| 297 |
|
progname); |
| 298 |
|
exit(1); |
| 299 |
|
} |
| 300 |
< |
for (x = 0; x < xmax; x++) { |
| 301 |
< |
i = chartndx(x, y, CENTCVG); |
| 293 |
< |
if (i >= 0) { |
| 300 |
> |
for (x = 0; x < xmax; x++) |
| 301 |
> |
if (chartndx(x, y, &i) == RG_CENT) { |
| 302 |
|
colr_color(pval, scanln[x]); |
| 303 |
|
addcolor(inpRGB[i], pval); |
| 304 |
|
ccount[i]++; |
| 305 |
|
} |
| 298 |
– |
} |
| 306 |
|
} |
| 307 |
|
for (i = 0; i < 24; i++) { /* compute averages */ |
| 308 |
|
if (ccount[i] == 0) |
| 327 |
|
fgetval(stdin, 'f', &xyYin[0]) != 1 || |
| 328 |
|
fgetval(stdin, 'f', &xyYin[1]) != 1 || |
| 329 |
|
fgetval(stdin, 'f', &xyYin[2]) != 1 || |
| 330 |
< |
xyYin[0] < 0. | xyYin[0] > 1. | |
| 331 |
< |
xyYin[1] < 0. | xyYin[1] > 1.) { |
| 330 |
> |
xyYin[0] < 0. | xyYin[1] < 0. || |
| 331 |
> |
xyYin[0] + xyYin[1] > 1.) { |
| 332 |
|
fprintf(stderr, "%s: bad color input data\n", |
| 333 |
|
progname); |
| 334 |
|
exit(1); |
| 366 |
|
bresp(y, x) /* piecewise linear interpolation of primaries */ |
| 367 |
|
COLOR y, x; |
| 368 |
|
{ |
| 362 |
– |
double cv[3]; |
| 369 |
|
register int i, n; |
| 370 |
|
|
| 371 |
|
for (i = 0; i < 3; i++) { |
| 372 |
|
for (n = 0; n < NMBNEU-2; n++) |
| 373 |
|
if (colval(x,i) < colval(bramp[n+1][0],i)) |
| 374 |
|
break; |
| 375 |
< |
cv[i] = ((colval(bramp[n+1][0],i) - colval(x,i)) * |
| 375 |
> |
colval(y,i) = ((colval(bramp[n+1][0],i) - colval(x,i)) * |
| 376 |
|
colval(bramp[n][1],i) + |
| 377 |
|
(colval(x,i) - colval(bramp[n][0],i)) * |
| 378 |
|
colval(bramp[n+1][1],i)) / |
| 379 |
|
(colval(bramp[n+1][0],i) - colval(bramp[n][0],i)); |
| 374 |
– |
if (cv[i] < 0.) cv[i] = 0.; |
| 380 |
|
} |
| 376 |
– |
setcolor(y, cv[0], cv[1], cv[2]); |
| 381 |
|
} |
| 382 |
|
|
| 383 |
|
|
| 384 |
|
compute() /* compute color mapping */ |
| 385 |
|
{ |
| 386 |
< |
COLOR clrin[NMBMOD], clrout[NMBMOD]; |
| 386 |
> |
COLOR clrin[24], clrout[24]; |
| 387 |
> |
long cflags; |
| 388 |
> |
COLOR ctmp; |
| 389 |
|
register int i, n; |
| 390 |
|
/* did we get what we need? */ |
| 391 |
|
if ((inpflags & REQFLGS) != REQFLGS) { |
| 398 |
|
copycolor(bramp[i][0], inpRGB[mbneu[i]]); |
| 399 |
|
copycolor(bramp[i][1], mbRGB[mbneu[i]]); |
| 400 |
|
} |
| 401 |
< |
/* compute color matrix */ |
| 402 |
< |
for (n = 0, i = 0; i < NMBMOD; i++) |
| 403 |
< |
if (inpflags & 1L<<mbmod[i]) { |
| 404 |
< |
bresp(clrin[n], inpRGB[mbmod[i]]); |
| 405 |
< |
copycolor(clrout[n], mbRGB[mbmod[i]]); |
| 406 |
< |
n++; |
| 401 |
> |
/* compute color space gamut */ |
| 402 |
> |
if (scanning) { |
| 403 |
> |
copycolor(colmin, cblack); |
| 404 |
> |
copycolor(colmax, cwhite); |
| 405 |
> |
} else |
| 406 |
> |
for (i = 0; i < 3; i++) { |
| 407 |
> |
colval(colmin,i) = colval(bramp[0][0],i) - |
| 408 |
> |
colval(bramp[0][1],i) * |
| 409 |
> |
(colval(bramp[1][0],i)-colval(bramp[0][0],i)) / |
| 410 |
> |
(colval(bramp[1][1],i)-colval(bramp[1][0],i)); |
| 411 |
> |
colval(colmax,i) = colval(bramp[NMBNEU-2][0],i) + |
| 412 |
> |
(1.-colval(bramp[NMBNEU-2][1],i)) * |
| 413 |
> |
(colval(bramp[NMBNEU-1][0],i) - |
| 414 |
> |
colval(bramp[NMBNEU-2][0],i)) / |
| 415 |
> |
(colval(bramp[NMBNEU-1][1],i) - |
| 416 |
> |
colval(bramp[NMBNEU-2][1],i)); |
| 417 |
|
} |
| 418 |
< |
compsoln(clrin, clrout, n); |
| 418 |
> |
/* compute color mapping */ |
| 419 |
> |
do { |
| 420 |
> |
cflags = inpflags & ~gmtflags; |
| 421 |
> |
n = 0; /* compute transform matrix */ |
| 422 |
> |
for (i = 0; i < 24; i++) |
| 423 |
> |
if (cflags & 1L<<i) { |
| 424 |
> |
bresp(clrin[n], inpRGB[i]); |
| 425 |
> |
copycolor(clrout[n], mbRGB[i]); |
| 426 |
> |
n++; |
| 427 |
> |
} |
| 428 |
> |
compsoln(clrin, clrout, n); |
| 429 |
> |
/* check out-of-gamut colors */ |
| 430 |
> |
for (i = 0; i < 24; i++) |
| 431 |
> |
if (cflags & 1L<<i && cvtcolor(ctmp, mbRGB[i])) |
| 432 |
> |
gmtflags |= 1L<<i; |
| 433 |
> |
} while (cflags & gmtflags); |
| 434 |
> |
if (gmtflags & MODFLGS) |
| 435 |
> |
fprintf(stderr, |
| 436 |
> |
"%s: warning - some moderate colors are out of gamut\n", |
| 437 |
> |
progname); |
| 438 |
|
} |
| 439 |
|
|
| 440 |
|
|
| 452 |
|
for (i = 0; i < NMBNEU; i++) |
| 453 |
|
printf(",%g", colval(bramp[i][1],j)); |
| 454 |
|
printf(");\n"); |
| 420 |
– |
printf("%c = %ci(1);\n", cchar[j], cchar[j]); |
| 455 |
|
printf("%cfi(n) = if(n-%g, %d, if(%cxa(n+1)-%c, n, %cfi(n+1)));\n", |
| 456 |
|
cchar[j], NMBNEU-1.5, NMBNEU-1, cchar[j], |
| 457 |
|
cchar[j], cchar[j]); |
| 458 |
|
printf("%cndx = %cfi(1);\n", cchar[j], cchar[j]); |
| 459 |
< |
printf("%cn = ((%cxa(%cndx+1)-%c)*%cya(%cndx) + ", |
| 460 |
< |
cchar[j], cchar[j], cchar[j], |
| 461 |
< |
cchar[j], cchar[j], cchar[j]); |
| 459 |
> |
printf("%c%c = ((%cxa(%cndx+1)-%c)*%cya(%cndx) + ", |
| 460 |
> |
cchar[j], scanning?'n':'o', cchar[j], |
| 461 |
> |
cchar[j], cchar[j], cchar[j], cchar[j]); |
| 462 |
|
printf("(%c-%cxa(%cndx))*%cya(%cndx+1)) /\n", |
| 463 |
|
cchar[j], cchar[j], cchar[j], |
| 464 |
|
cchar[j], cchar[j]); |
| 466 |
|
cchar[j], cchar[j], cchar[j], cchar[j]); |
| 467 |
|
} |
| 468 |
|
/* print color mapping */ |
| 469 |
< |
printf("ro = %g*rn + %g*gn + %g*bn ;\n", |
| 470 |
< |
solmat[0][0], solmat[0][1], solmat[0][2]); |
| 471 |
< |
printf("go = %g*rn + %g*gn + %g*bn ;\n", |
| 472 |
< |
solmat[1][0], solmat[1][1], solmat[1][2]); |
| 473 |
< |
printf("bo = %g*rn + %g*gn + %g*bn ;\n", |
| 474 |
< |
solmat[2][0], solmat[2][1], solmat[2][2]); |
| 469 |
> |
if (scanning) { |
| 470 |
> |
printf("r = ri(1); g = gi(1); b = bi(1);\n"); |
| 471 |
> |
printf("ro = %g*rn + %g*gn + %g*bn ;\n", |
| 472 |
> |
solmat[0][0], solmat[0][1], solmat[0][2]); |
| 473 |
> |
printf("go = %g*rn + %g*gn + %g*bn ;\n", |
| 474 |
> |
solmat[1][0], solmat[1][1], solmat[1][2]); |
| 475 |
> |
printf("bo = %g*rn + %g*gn + %g*bn ;\n", |
| 476 |
> |
solmat[2][0], solmat[2][1], solmat[2][2]); |
| 477 |
> |
} else { |
| 478 |
> |
printf("r1 = ri(1); g1 = gi(1); b1 = bi(1);\n"); |
| 479 |
> |
printf("r = %g*r1 + %g*g1 + %g*b1 ;\n", |
| 480 |
> |
solmat[0][0], solmat[0][1], solmat[0][2]); |
| 481 |
> |
printf("g = %g*r1 + %g*g1 + %g*b1 ;\n", |
| 482 |
> |
solmat[1][0], solmat[1][1], solmat[1][2]); |
| 483 |
> |
printf("b = %g*r1 + %g*g1 + %g*b1 ;\n", |
| 484 |
> |
solmat[2][0], solmat[2][1], solmat[2][2]); |
| 485 |
> |
} |
| 486 |
|
} |
| 487 |
|
|
| 488 |
|
|
| 496 |
|
double colv[3], rowv[3]; |
| 497 |
|
register int i, j, k; |
| 498 |
|
|
| 499 |
< |
if (n < 3 | n > NMBMOD) { |
| 500 |
< |
fprintf(stderr, "%s: bad number of colors to match\n", progname); |
| 499 |
> |
if (n < 3) { |
| 500 |
> |
fprintf(stderr, "%s: too few colors to match!\n", progname); |
| 501 |
|
exit(1); |
| 502 |
|
} |
| 503 |
|
if (n == 3) |
| 546 |
|
} |
| 547 |
|
|
| 548 |
|
|
| 549 |
+ |
int |
| 550 |
|
cvtcolor(cout, cin) /* convert color according to our mapping */ |
| 551 |
|
COLOR cout, cin; |
| 552 |
|
{ |
| 553 |
< |
double r, g, b; |
| 553 |
> |
COLOR ctmp; |
| 554 |
> |
int clipped; |
| 555 |
|
|
| 556 |
< |
bresp(cout, cin); |
| 557 |
< |
r = colval(cout,0)*solmat[0][0] + colval(cout,1)*solmat[0][1] |
| 558 |
< |
+ colval(cout,2)*solmat[0][2]; |
| 559 |
< |
if (r < 0) r = 0; |
| 560 |
< |
g = colval(cout,0)*solmat[1][0] + colval(cout,1)*solmat[1][1] |
| 561 |
< |
+ colval(cout,2)*solmat[1][2]; |
| 562 |
< |
if (g < 0) g = 0; |
| 563 |
< |
b = colval(cout,0)*solmat[2][0] + colval(cout,1)*solmat[2][1] |
| 517 |
< |
+ colval(cout,2)*solmat[2][2]; |
| 518 |
< |
if (b < 0) b = 0; |
| 519 |
< |
setcolor(cout, r, g, b); |
| 556 |
> |
if (scanning) { |
| 557 |
> |
bresp(ctmp, cin); |
| 558 |
> |
clipped = cresp(cout, ctmp); |
| 559 |
> |
} else { |
| 560 |
> |
clipped = cresp(ctmp, cin); |
| 561 |
> |
bresp(cout, ctmp); |
| 562 |
> |
} |
| 563 |
> |
return(clipped); |
| 564 |
|
} |
| 565 |
|
|
| 566 |
|
|
| 567 |
+ |
int |
| 568 |
+ |
cresp(cout, cin) /* transform color according to matrix */ |
| 569 |
+ |
COLOR cout, cin; |
| 570 |
+ |
{ |
| 571 |
+ |
colortrans(cout, solmat, cin); |
| 572 |
+ |
return(clipgamut(cout, bright(cout), CGAMUT, colmin, colmax)); |
| 573 |
+ |
} |
| 574 |
+ |
|
| 575 |
+ |
|
| 576 |
|
xyY2RGB(rgbout, xyYin) /* convert xyY to RGB */ |
| 577 |
|
COLOR rgbout; |
| 578 |
|
register float xyYin[3]; |
| 584 |
|
ctmp[0] = xyYin[0] * d; |
| 585 |
|
ctmp[1] = xyYin[2]; |
| 586 |
|
ctmp[2] = (1. - xyYin[0] - xyYin[1]) * d; |
| 587 |
< |
cie_rgb(rgbout, ctmp); |
| 587 |
> |
/* allow negative values */ |
| 588 |
> |
colortrans(rgbout, xyz2rgbmat, ctmp); |
| 589 |
|
} |
| 590 |
|
|
| 591 |
|
|
| 592 |
|
picdebug() /* put out debugging picture */ |
| 593 |
|
{ |
| 594 |
+ |
static COLOR blkcol = BLKCOLOR; |
| 595 |
|
COLOR *scan; |
| 596 |
< |
int y; |
| 597 |
< |
register int x, i; |
| 596 |
> |
int y, i; |
| 597 |
> |
register int x, rg; |
| 598 |
|
|
| 599 |
|
if (fseek(stdin, 0L, 0) == EOF) { |
| 600 |
|
fprintf(stderr, "%s: cannot seek on input picture\n", progname); |
| 620 |
|
exit(1); |
| 621 |
|
} |
| 622 |
|
for (x = 0; x < xmax; x++) { |
| 623 |
< |
i = chartndx(x, y, CENTCVG); |
| 624 |
< |
if (i < 0) |
| 623 |
> |
rg = chartndx(x, y, &i); |
| 624 |
> |
if (rg == RG_CENT) { |
| 625 |
> |
if (!(1L<<i & gmtflags) || (x+y)&07) { |
| 626 |
> |
copycolor(scan[x], mbRGB[i]); |
| 627 |
> |
clipgamut(scan[x], bright(scan[x]), |
| 628 |
> |
CGAMUT, cblack, cwhite); |
| 629 |
> |
} else |
| 630 |
> |
copycolor(scan[x], blkcol); |
| 631 |
> |
} else if (rg == RG_CORR) |
| 632 |
|
cvtcolor(scan[x], scan[x]); |
| 633 |
< |
else |
| 634 |
< |
copycolor(scan[x], mbRGB[i]); |
| 633 |
> |
else if (rg != RG_ORIG) |
| 634 |
> |
copycolor(scan[x], blkcol); |
| 635 |
|
} |
| 636 |
|
if (fwritescan(scan, xmax, debugfp) < 0) { |
| 637 |
|
fprintf(stderr, "%s: error writing debugging picture\n", |
| 648 |
|
clrdebug() /* put out debug picture from color input */ |
| 649 |
|
{ |
| 650 |
|
static COLR blkclr = BLKCOLR; |
| 651 |
< |
COLR mbclr[24], cvclr[24]; |
| 651 |
> |
COLR mbclr[24], cvclr[24], orclr[24]; |
| 652 |
|
COLR *scan; |
| 653 |
< |
COLOR ctmp; |
| 654 |
< |
int y; |
| 655 |
< |
register int i, x; |
| 653 |
> |
COLOR ctmp, ct2; |
| 654 |
> |
int y, i; |
| 655 |
> |
register int x, rg; |
| 656 |
|
/* convert colors */ |
| 657 |
|
for (i = 0; i < 24; i++) { |
| 658 |
< |
setcolr(mbclr[i], colval(mbRGB[i],RED), |
| 659 |
< |
colval(mbRGB[i],GRN), colval(mbRGB[i],BLU)); |
| 658 |
> |
copycolor(ctmp, mbRGB[i]); |
| 659 |
> |
clipgamut(ctmp, bright(ctmp), CGAMUT, cblack, cwhite); |
| 660 |
> |
setcolr(mbclr[i], colval(ctmp,RED), |
| 661 |
> |
colval(ctmp,GRN), colval(ctmp,BLU)); |
| 662 |
|
if (inpflags & 1L<<i) { |
| 663 |
< |
cvtcolor(ctmp, inpRGB[i]); |
| 664 |
< |
setcolr(cvclr[i], colval(ctmp,RED), |
| 663 |
> |
copycolor(ctmp, inpRGB[i]); |
| 664 |
> |
clipgamut(ctmp, bright(ctmp), CGAMUT, cblack, cwhite); |
| 665 |
> |
setcolr(orclr[i], colval(ctmp,RED), |
| 666 |
|
colval(ctmp,GRN), colval(ctmp,BLU)); |
| 667 |
+ |
bresp(ctmp, inpRGB[i]); |
| 668 |
+ |
colortrans(ct2, solmat, ctmp); |
| 669 |
+ |
clipgamut(ct2, bright(ct2), CGAMUT, cblack, cwhite); |
| 670 |
+ |
setcolr(cvclr[i], colval(ct2,RED), |
| 671 |
+ |
colval(ct2,GRN), colval(ct2,BLU)); |
| 672 |
|
} |
| 673 |
|
} |
| 674 |
|
/* allocate scanline */ |
| 683 |
|
fprtresolu(xmax, ymax, debugfp); |
| 684 |
|
/* write debug picture */ |
| 685 |
|
for (y = ymax-1; y >= 0; y--) { |
| 686 |
< |
for (x = 0; x < xmax; x++) |
| 687 |
< |
if ((i = chartndx(x, y, CENTCVG)) >= 0) |
| 688 |
< |
copycolr(scan[x], mbclr[i]); |
| 689 |
< |
else if ((i = chartndx(x, y, FULLCVG)) >= 0 && |
| 690 |
< |
inpflags & 1L<<i) |
| 691 |
< |
copycolr(scan[x], cvclr[i]); |
| 692 |
< |
else |
| 686 |
> |
for (x = 0; x < xmax; x++) { |
| 687 |
> |
rg = chartndx(x, y, &i); |
| 688 |
> |
if (rg == RG_CENT) { |
| 689 |
> |
if (!(1L<<i & gmtflags) || (x+y)&07) |
| 690 |
> |
copycolr(scan[x], mbclr[i]); |
| 691 |
> |
else |
| 692 |
> |
copycolr(scan[x], blkclr); |
| 693 |
> |
} else if (rg == RG_BORD || !(1L<<i & inpflags)) |
| 694 |
|
copycolr(scan[x], blkclr); |
| 695 |
+ |
else if (rg == RG_ORIG) |
| 696 |
+ |
copycolr(scan[x], orclr[i]); |
| 697 |
+ |
else /* rg == RG_CORR */ |
| 698 |
+ |
copycolr(scan[x], cvclr[i]); |
| 699 |
+ |
} |
| 700 |
|
if (fwritecolrs(scan, xmax, debugfp) < 0) { |
| 701 |
|
fprintf(stderr, "%s: error writing debugging picture\n", |
| 702 |
|
progname); |