| 13 |
|
#include "lookup.h" |
| 14 |
|
|
| 15 |
|
/* default context values */ |
| 16 |
– |
static C_COLOR c_dfcolor = C_DEFCOLOR; |
| 16 |
|
static C_MATERIAL c_dfmaterial = C_DEFMATERIAL; |
| 17 |
|
static C_VERTEX c_dfvertex = C_DEFVERTEX; |
| 18 |
|
|
| 33 |
|
static LUTAB mat_tab = LU_SINIT(free,free); /* material lookup table */ |
| 34 |
|
static LUTAB vtx_tab = LU_SINIT(free,free); /* vertex lookup table */ |
| 35 |
|
|
| 37 |
– |
/* CIE 1931 Standard Observer curves */ |
| 38 |
– |
static C_COLOR cie_xf = { 1, NULL, C_CDSPEC|C_CSSPEC|C_CSXY|C_CSEFF, |
| 39 |
– |
{14,42,143,435,1344,2839,3483,3362,2908,1954,956, |
| 40 |
– |
320,49,93,633,1655,2904,4334,5945,7621,9163,10263, |
| 41 |
– |
10622,10026,8544,6424,4479,2835,1649,874,468,227, |
| 42 |
– |
114,58,29,14,7,3,2,1,0}, 106836L, .467, .368, 362.230 |
| 43 |
– |
}; |
| 44 |
– |
static C_COLOR cie_yf = { 1, NULL, C_CDSPEC|C_CSSPEC|C_CSXY|C_CSEFF, |
| 45 |
– |
{0,1,4,12,40,116,230,380,600,910,1390,2080,3230, |
| 46 |
– |
5030,7100,8620,9540,9950,9950,9520,8700,7570,6310, |
| 47 |
– |
5030,3810,2650,1750,1070,610,320,170,82,41,21,10, |
| 48 |
– |
5,2,1,1,0,0}, 106856L, .398, .542, 493.525 |
| 49 |
– |
}; |
| 50 |
– |
static C_COLOR cie_zf = { 1, NULL, C_CDSPEC|C_CSSPEC|C_CSXY|C_CSEFF, |
| 51 |
– |
{65,201,679,2074,6456,13856,17471,17721,16692, |
| 52 |
– |
12876,8130,4652,2720,1582,782,422,203,87,39,21,17, |
| 53 |
– |
11,8,3,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
| 54 |
– |
106770L, .147, .077, 54.363 |
| 55 |
– |
}; |
| 56 |
– |
/* Derived CIE 1931 Primaries (imaginary) */ |
| 57 |
– |
static C_COLOR cie_xp = { 1, NULL, C_CDSPEC|C_CSSPEC|C_CSXY, |
| 58 |
– |
{-174,-198,-195,-197,-202,-213,-235,-272,-333, |
| 59 |
– |
-444,-688,-1232,-2393,-4497,-6876,-6758,-5256, |
| 60 |
– |
-3100,-815,1320,3200,4782,5998,6861,7408,7754, |
| 61 |
– |
7980,8120,8199,8240,8271,8292,8309,8283,8469, |
| 62 |
– |
8336,8336,8336,8336,8336,8336}, |
| 63 |
– |
127424L, 1., .0, |
| 64 |
– |
}; |
| 65 |
– |
static C_COLOR cie_yp = { 1, NULL, C_CDSPEC|C_CSSPEC|C_CSXY, |
| 66 |
– |
{-451,-431,-431,-430,-427,-417,-399,-366,-312, |
| 67 |
– |
-204,57,691,2142,4990,8810,9871,9122,7321,5145, |
| 68 |
– |
3023,1123,-473,-1704,-2572,-3127,-3474,-3704, |
| 69 |
– |
-3846,-3927,-3968,-3999,-4021,-4038,-4012,-4201, |
| 70 |
– |
-4066,-4066,-4066,-4066,-4066,-4066}, |
| 71 |
– |
-23035L, .0, 1., |
| 72 |
– |
}; |
| 73 |
– |
static C_COLOR cie_zp = { 1, NULL, C_CDSPEC|C_CSSPEC|C_CSXY, |
| 74 |
– |
{4051,4054,4052,4053,4054,4056,4059,4064,4071, |
| 75 |
– |
4074,4056,3967,3677,2933,1492,313,-440,-795, |
| 76 |
– |
-904,-918,-898,-884,-869,-863,-855,-855,-851, |
| 77 |
– |
-848,-847,-846,-846,-846,-845,-846,-843,-845, |
| 78 |
– |
-845,-845,-845,-845,-845}, |
| 79 |
– |
36057L, .0, .0, |
| 80 |
– |
}; |
| 81 |
– |
|
| 36 |
|
static int setspectrum(); |
| 37 |
|
static int setbbtemp(); |
| 38 |
|
static void mixcolors(); |
| 440 |
|
if ((lp = lu_find(&clr_tab, name)) == NULL) |
| 441 |
|
return(NULL); |
| 442 |
|
return((C_COLOR *)lp->data); |
| 489 |
– |
} |
| 490 |
– |
|
| 491 |
– |
|
| 492 |
– |
int |
| 493 |
– |
c_isgrey(clr) /* check if color is grey */ |
| 494 |
– |
register C_COLOR *clr; |
| 495 |
– |
{ |
| 496 |
– |
if (!(clr->flags & (C_CSXY|C_CSSPEC))) |
| 497 |
– |
return(1); /* no settings == grey */ |
| 498 |
– |
c_ccvt(clr, C_CSXY); |
| 499 |
– |
return(clr->cx >= .323 && clr->cx <= .343 && |
| 500 |
– |
clr->cy >= .323 && clr->cy <= .343); |
| 501 |
– |
} |
| 502 |
– |
|
| 503 |
– |
|
| 504 |
– |
void |
| 505 |
– |
c_ccvt(clr, fl) /* convert color representations */ |
| 506 |
– |
register C_COLOR *clr; |
| 507 |
– |
int fl; |
| 508 |
– |
{ |
| 509 |
– |
double x, y, z; |
| 510 |
– |
register int i; |
| 511 |
– |
|
| 512 |
– |
fl &= ~clr->flags; /* ignore what's done */ |
| 513 |
– |
if (!fl) /* everything's done! */ |
| 514 |
– |
return; |
| 515 |
– |
if (!(clr->flags & (C_CSXY|C_CSSPEC))) /* nothing set! */ |
| 516 |
– |
*clr = c_dfcolor; |
| 517 |
– |
if (fl & C_CSXY) { /* cspec -> cxy */ |
| 518 |
– |
x = y = z = 0.; |
| 519 |
– |
for (i = 0; i < C_CNSS; i++) { |
| 520 |
– |
x += cie_xf.ssamp[i] * clr->ssamp[i]; |
| 521 |
– |
y += cie_yf.ssamp[i] * clr->ssamp[i]; |
| 522 |
– |
z += cie_zf.ssamp[i] * clr->ssamp[i]; |
| 523 |
– |
} |
| 524 |
– |
x /= (double)cie_xf.ssum; |
| 525 |
– |
y /= (double)cie_yf.ssum; |
| 526 |
– |
z /= (double)cie_zf.ssum; |
| 527 |
– |
z += x + y; |
| 528 |
– |
clr->cx = x / z; |
| 529 |
– |
clr->cy = y / z; |
| 530 |
– |
clr->flags |= C_CSXY; |
| 531 |
– |
} else if (fl & C_CSSPEC) { /* cxy -> cspec */ |
| 532 |
– |
x = clr->cx; |
| 533 |
– |
y = clr->cy; |
| 534 |
– |
z = 1. - x - y; |
| 535 |
– |
clr->ssum = 0; |
| 536 |
– |
for (i = 0; i < C_CNSS; i++) { |
| 537 |
– |
clr->ssamp[i] = x*cie_xp.ssamp[i] + y*cie_yp.ssamp[i] |
| 538 |
– |
+ z*cie_zp.ssamp[i] + .5; |
| 539 |
– |
if (clr->ssamp[i] < 0) /* out of gamut! */ |
| 540 |
– |
clr->ssamp[i] = 0; |
| 541 |
– |
else |
| 542 |
– |
clr->ssum += clr->ssamp[i]; |
| 543 |
– |
} |
| 544 |
– |
clr->flags |= C_CSSPEC; |
| 545 |
– |
} |
| 546 |
– |
if (fl & C_CSEFF) { /* compute efficacy */ |
| 547 |
– |
if (clr->flags & C_CSSPEC) { /* from spectrum */ |
| 548 |
– |
y = 0.; |
| 549 |
– |
for (i = 0; i < C_CNSS; i++) |
| 550 |
– |
y += cie_yf.ssamp[i] * clr->ssamp[i]; |
| 551 |
– |
clr->eff = C_CLPWM * y / clr->ssum; |
| 552 |
– |
} else /* clr->flags & C_CSXY */ { /* from (x,y) */ |
| 553 |
– |
clr->eff = clr->cx*cie_xf.eff + clr->cy*cie_yf.eff + |
| 554 |
– |
(1. - clr->cx - clr->cy)*cie_zf.eff; |
| 555 |
– |
} |
| 556 |
– |
clr->flags |= C_CSEFF; |
| 557 |
– |
} |
| 443 |
|
} |
| 444 |
|
|
| 445 |
|
|