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; |
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 |