| 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 REQFLGS NEUFLGS /* need these colors */ |
| 91 |
+ |
#define MODFLGS (NEUFLGS|UNSFLGS) /* should be in gamut */ |
| 92 |
+ |
|
| 93 |
|
#define CENTCVG 0.3 /* measured coverage of square sample */ |
| 94 |
|
#define FULLCVG 0.9 /* coverage of entire square */ |
| 95 |
|
|
| 99 |
|
|
| 100 |
|
COLOR inpRGB[24]; /* measured or scanned input colors */ |
| 101 |
|
long inpflags = 0; /* flags of which colors were input */ |
| 102 |
+ |
long gmtflags = 0; /* flags of out-of-gamut colors */ |
| 103 |
|
|
| 104 |
|
COLOR bramp[NMBNEU][2]; /* brightness ramp (per primary) */ |
| 105 |
|
double solmat[3][3]; /* color mapping matrix */ |
| 357 |
|
bresp(y, x) /* piecewise linear interpolation of primaries */ |
| 358 |
|
COLOR y, x; |
| 359 |
|
{ |
| 362 |
– |
double cv[3]; |
| 360 |
|
register int i, n; |
| 361 |
|
|
| 362 |
|
for (i = 0; i < 3; i++) { |
| 363 |
|
for (n = 0; n < NMBNEU-2; n++) |
| 364 |
|
if (colval(x,i) < colval(bramp[n+1][0],i)) |
| 365 |
|
break; |
| 366 |
< |
cv[i] = ((colval(bramp[n+1][0],i) - colval(x,i)) * |
| 366 |
> |
colval(y,i) = ((colval(bramp[n+1][0],i) - colval(x,i)) * |
| 367 |
|
colval(bramp[n][1],i) + |
| 368 |
|
(colval(x,i) - colval(bramp[n][0],i)) * |
| 369 |
|
colval(bramp[n+1][1],i)) / |
| 370 |
|
(colval(bramp[n+1][0],i) - colval(bramp[n][0],i)); |
| 374 |
– |
if (cv[i] < 0.) cv[i] = 0.; |
| 371 |
|
} |
| 376 |
– |
setcolor(y, cv[0], cv[1], cv[2]); |
| 372 |
|
} |
| 373 |
|
|
| 374 |
|
|
| 375 |
|
compute() /* compute color mapping */ |
| 376 |
|
{ |
| 377 |
< |
COLOR clrin[NMBMOD], clrout[NMBMOD]; |
| 378 |
< |
register int i, n; |
| 377 |
> |
COLOR clrin[24], clrout[24]; |
| 378 |
> |
long cflags; |
| 379 |
> |
COLOR ctmp; |
| 380 |
> |
register int i, j, n; |
| 381 |
|
/* did we get what we need? */ |
| 382 |
|
if ((inpflags & REQFLGS) != REQFLGS) { |
| 383 |
|
fprintf(stderr, "%s: missing required input colors\n", |
| 389 |
|
copycolor(bramp[i][0], inpRGB[mbneu[i]]); |
| 390 |
|
copycolor(bramp[i][1], mbRGB[mbneu[i]]); |
| 391 |
|
} |
| 392 |
< |
/* compute color matrix */ |
| 393 |
< |
for (n = 0, i = 0; i < NMBMOD; i++) |
| 394 |
< |
if (inpflags & 1L<<mbmod[i]) { |
| 395 |
< |
bresp(clrin[n], inpRGB[mbmod[i]]); |
| 396 |
< |
copycolor(clrout[n], mbRGB[mbmod[i]]); |
| 397 |
< |
n++; |
| 398 |
< |
} |
| 399 |
< |
compsoln(clrin, clrout, n); |
| 392 |
> |
/* compute color mapping */ |
| 393 |
> |
do { |
| 394 |
> |
cflags = inpflags & ~gmtflags; |
| 395 |
> |
n = 0; /* compute transform matrix */ |
| 396 |
> |
for (i = 0; i < 24; i++) |
| 397 |
> |
if (cflags & 1L<<i) { |
| 398 |
> |
bresp(clrin[n], inpRGB[i]); |
| 399 |
> |
copycolor(clrout[n], mbRGB[i]); |
| 400 |
> |
n++; |
| 401 |
> |
} |
| 402 |
> |
compsoln(clrin, clrout, n); |
| 403 |
> |
/* check out-of-gamut colors */ |
| 404 |
> |
for (i = 0; i < 24; i++) |
| 405 |
> |
if (cflags & 1L<<i) { |
| 406 |
> |
cresp(ctmp, mbRGB[i]); |
| 407 |
> |
for (j = 0; j < 3; j++) |
| 408 |
> |
if (colval(ctmp,j) <= 0. || |
| 409 |
> |
colval(ctmp,j) >= 1.) { |
| 410 |
> |
gmtflags |= 1L<<i; |
| 411 |
> |
break; |
| 412 |
> |
} |
| 413 |
> |
} |
| 414 |
> |
} while (cflags & gmtflags); |
| 415 |
> |
if (gmtflags & MODFLGS) |
| 416 |
> |
fprintf(stderr, |
| 417 |
> |
"%s: warning - some moderate colors are out of gamut\n", |
| 418 |
> |
progname); |
| 419 |
|
} |
| 420 |
|
|
| 421 |
|
|
| 467 |
|
double colv[3], rowv[3]; |
| 468 |
|
register int i, j, k; |
| 469 |
|
|
| 470 |
< |
if (n < 3 | n > NMBMOD) { |
| 471 |
< |
fprintf(stderr, "%s: bad number of colors to match\n", progname); |
| 470 |
> |
if (n < 3) { |
| 471 |
> |
fprintf(stderr, "%s: too few colors to match!\n", progname); |
| 472 |
|
exit(1); |
| 473 |
|
} |
| 474 |
|
if (n == 3) |
| 520 |
|
cvtcolor(cout, cin) /* convert color according to our mapping */ |
| 521 |
|
COLOR cout, cin; |
| 522 |
|
{ |
| 523 |
+ |
COLOR ctmp; |
| 524 |
+ |
|
| 525 |
+ |
bresp(ctmp, cin); |
| 526 |
+ |
cresp(cout, ctmp); |
| 527 |
+ |
if (colval(cout,RED) < 0.) |
| 528 |
+ |
colval(cout,RED) = 0.; |
| 529 |
+ |
if (colval(cout,GRN) < 0.) |
| 530 |
+ |
colval(cout,GRN) = 0.; |
| 531 |
+ |
if (colval(cout,BLU) < 0.) |
| 532 |
+ |
colval(cout,BLU) = 0.; |
| 533 |
+ |
} |
| 534 |
+ |
|
| 535 |
+ |
|
| 536 |
+ |
cresp(cout, cin) /* transform color according to matrix */ |
| 537 |
+ |
COLOR cout, cin; |
| 538 |
+ |
{ |
| 539 |
|
double r, g, b; |
| 540 |
|
|
| 541 |
< |
bresp(cout, cin); |
| 542 |
< |
r = colval(cout,0)*solmat[0][0] + colval(cout,1)*solmat[0][1] |
| 543 |
< |
+ colval(cout,2)*solmat[0][2]; |
| 544 |
< |
if (r < 0) r = 0; |
| 545 |
< |
g = colval(cout,0)*solmat[1][0] + colval(cout,1)*solmat[1][1] |
| 546 |
< |
+ colval(cout,2)*solmat[1][2]; |
| 515 |
< |
if (g < 0) g = 0; |
| 516 |
< |
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; |
| 541 |
> |
r = colval(cin,0)*solmat[0][0] + colval(cin,1)*solmat[0][1] |
| 542 |
> |
+ colval(cin,2)*solmat[0][2]; |
| 543 |
> |
g = colval(cin,0)*solmat[1][0] + colval(cin,1)*solmat[1][1] |
| 544 |
> |
+ colval(cin,2)*solmat[1][2]; |
| 545 |
> |
b = colval(cin,0)*solmat[2][0] + colval(cin,1)*solmat[2][1] |
| 546 |
> |
+ colval(cin,2)*solmat[2][2]; |
| 547 |
|
setcolor(cout, r, g, b); |
| 548 |
|
} |
| 549 |
|
|
| 565 |
|
|
| 566 |
|
picdebug() /* put out debugging picture */ |
| 567 |
|
{ |
| 568 |
+ |
static COLOR blkcol = BLKCOLOR; |
| 569 |
|
COLOR *scan; |
| 570 |
|
int y; |
| 571 |
|
register int x, i; |
| 597 |
|
i = chartndx(x, y, CENTCVG); |
| 598 |
|
if (i < 0) |
| 599 |
|
cvtcolor(scan[x], scan[x]); |
| 600 |
< |
else |
| 600 |
> |
else if (!(1L<<i & gmtflags) || (x+y)&07) |
| 601 |
|
copycolor(scan[x], mbRGB[i]); |
| 602 |
+ |
else |
| 603 |
+ |
copycolor(scan[x], blkcol); |
| 604 |
|
} |
| 605 |
|
if (fwritescan(scan, xmax, debugfp) < 0) { |
| 606 |
|
fprintf(stderr, "%s: error writing debugging picture\n", |
| 645 |
|
/* write debug picture */ |
| 646 |
|
for (y = ymax-1; y >= 0; y--) { |
| 647 |
|
for (x = 0; x < xmax; x++) |
| 648 |
< |
if ((i = chartndx(x, y, CENTCVG)) >= 0) |
| 649 |
< |
copycolr(scan[x], mbclr[i]); |
| 650 |
< |
else if ((i = chartndx(x, y, FULLCVG)) >= 0 && |
| 648 |
> |
if ((i = chartndx(x, y, CENTCVG)) >= 0) { |
| 649 |
> |
if (!(1L<<i & gmtflags) || (x+y)&07) |
| 650 |
> |
copycolr(scan[x], mbclr[i]); |
| 651 |
> |
else |
| 652 |
> |
copycolr(scan[x], blkclr); |
| 653 |
> |
} else if ((i = chartndx(x, y, FULLCVG)) >= 0 && |
| 654 |
|
inpflags & 1L<<i) |
| 655 |
|
copycolr(scan[x], cvclr[i]); |
| 656 |
|
else |