96 |
|
{ |
97 |
|
double xyz[3], sf; |
98 |
|
|
99 |
– |
xyz[0] = XYZfromSharp[0][0]*cin[0] + XYZfromSharp[0][1]*cin[1] + |
100 |
– |
XYZfromSharp[0][2]*cin[2]; |
99 |
|
xyz[1] = XYZfromSharp[1][0]*cin[0] + XYZfromSharp[1][1]*cin[1] + |
100 |
|
XYZfromSharp[1][2]*cin[2]; |
101 |
+ |
if (xyz[1] <= 1e-6) { |
102 |
+ |
*cout = c_dfcolor; /* punting, here... */ |
103 |
+ |
return xyz[1]; |
104 |
+ |
} |
105 |
+ |
xyz[0] = XYZfromSharp[0][0]*cin[0] + XYZfromSharp[0][1]*cin[1] + |
106 |
+ |
XYZfromSharp[0][2]*cin[2]; |
107 |
|
xyz[2] = XYZfromSharp[2][0]*cin[0] + XYZfromSharp[2][1]*cin[1] + |
108 |
|
XYZfromSharp[2][2]*cin[2]; |
109 |
< |
|
109 |
> |
|
110 |
|
sf = 1./(xyz[0] + xyz[1] + xyz[2]); |
111 |
|
|
112 |
|
cout->cx = xyz[0] * sf; |
116 |
|
return(xyz[1]); |
117 |
|
} |
118 |
|
|
119 |
< |
/* assign arbitrary spectrum */ |
119 |
> |
/* assign arbitrary spectrum and return Y value */ |
120 |
|
double |
121 |
|
c_sset(C_COLOR *clr, double wlmin, double wlmax, const float spec[], int nwl) |
122 |
|
{ |
138 |
|
wlmax -= wlstep; |
139 |
|
--nwl; |
140 |
|
} |
141 |
+ |
if ((nwl <= 1) | (wlmin >= wlmax)) |
142 |
+ |
return(0.); |
143 |
|
imax = nwl; /* box filter if necessary */ |
144 |
|
boxpos = 0; |
145 |
|
boxstep = 1; |
235 |
|
clr->cx = x / z; |
236 |
|
clr->cy = y / z; |
237 |
|
clr->flags |= C_CSXY; |
238 |
< |
} else if (fl & C_CSSPEC) { /* cxy -> cspec */ |
238 |
> |
} |
239 |
> |
if (fl & C_CSSPEC) { /* cxy -> cspec */ |
240 |
|
x = clr->cx; |
241 |
|
y = clr->cy; |
242 |
|
z = 1. - x - y; |
338 |
|
cres->ssum += cres->ssamp[i] = cmix[i] / cmax; |
339 |
|
cres->flags = C_CDSPEC|C_CSSPEC; |
340 |
|
|
341 |
< |
c_ccvt(cres, C_CSEFF); /* don't touch below */ |
341 |
> |
c_ccvt(cres, C_CSEFF); /* below is correct */ |
342 |
|
yres = y1 * y2 * c_y31.ssum * C_CLPWM / |
343 |
|
(c1->eff*c1->ssum * c2->eff*c2->ssum) * |
344 |
|
cres->eff*( cres->ssum*(double)cmax + |
390 |
|
#undef C2 |
391 |
|
#undef bbsp |
392 |
|
#undef bblm |
393 |
+ |
|
394 |
+ |
#define UV_NORMF 410. |
395 |
+ |
|
396 |
+ |
/* encode (x,y) chromaticity */ |
397 |
+ |
C_CHROMA |
398 |
+ |
c_encodeChroma(C_COLOR *clr) |
399 |
+ |
{ |
400 |
+ |
double df; |
401 |
+ |
int ub, vb; |
402 |
+ |
|
403 |
+ |
c_ccvt(clr, C_CSXY); |
404 |
+ |
df = UV_NORMF/(-2.*clr->cx + 12.*clr->cy + 3.); |
405 |
+ |
ub = 4.*clr->cx * df; |
406 |
+ |
if (ub < 0) ub = 0; |
407 |
+ |
else if (ub > 0xff) ub = 0xff; |
408 |
+ |
vb = 9.*clr->cy * df; |
409 |
+ |
if (vb < 0) vb = 0; |
410 |
+ |
else if (vb > 0xff) vb = 0xff; |
411 |
+ |
|
412 |
+ |
return(vb<<8 | ub); |
413 |
+ |
} |
414 |
+ |
|
415 |
+ |
/* decode (x,y) chromaticity */ |
416 |
+ |
void |
417 |
+ |
c_decodeChroma(C_COLOR *cres, C_CHROMA ccode) |
418 |
+ |
{ |
419 |
+ |
double up = ((ccode & 0xff) + .5)*(1./UV_NORMF); |
420 |
+ |
double vp = ((ccode>>8 & 0xff) + .5)*(1./UV_NORMF); |
421 |
+ |
double df = 1./(6.*up - 16.*vp + 12.); |
422 |
+ |
|
423 |
+ |
cres->cx = 9.*up * df; |
424 |
+ |
cres->cy = 4.*vp * df; |
425 |
+ |
cres->flags = C_CDXY|C_CSXY; |
426 |
+ |
} |
427 |
+ |
|
428 |
+ |
#undef UV_NORMF |