386 |
|
#undef C2 |
387 |
|
#undef bbsp |
388 |
|
#undef bblm |
389 |
+ |
|
390 |
+ |
#define UV_NORMF 410. |
391 |
+ |
|
392 |
+ |
/* encode (x,y) chromaticity */ |
393 |
+ |
C_CHROMA |
394 |
+ |
c_encodeChroma(C_COLOR *clr) |
395 |
+ |
{ |
396 |
+ |
double df; |
397 |
+ |
int ub, vb; |
398 |
+ |
|
399 |
+ |
c_ccvt(clr, C_CSXY); |
400 |
+ |
df = UV_NORMF/(-2.*clr->cx + 12.*clr->cy + 3.); |
401 |
+ |
ub = 4.*clr->cx * df; |
402 |
+ |
if (ub < 0) ub = 0; |
403 |
+ |
else if (ub > 0xff) ub = 0xff; |
404 |
+ |
vb = 9.*clr->cy * df; |
405 |
+ |
if (vb < 0) vb = 0; |
406 |
+ |
else if (vb > 0xff) vb = 0xff; |
407 |
+ |
|
408 |
+ |
return(vb<<8 | ub); |
409 |
+ |
} |
410 |
+ |
|
411 |
+ |
/* decode (x,y) chromaticity */ |
412 |
+ |
void |
413 |
+ |
c_decodeChroma(C_COLOR *cres, C_CHROMA ccode) |
414 |
+ |
{ |
415 |
+ |
double up = ((ccode & 0xff) + .5)*(1./UV_NORMF); |
416 |
+ |
double vp = ((ccode>>8 & 0xff) + .5)*(1./UV_NORMF); |
417 |
+ |
double df = 1./(6.*up - 16.*vp + 12.); |
418 |
+ |
|
419 |
+ |
cres->cx = 9.*up * df; |
420 |
+ |
cres->cy = 4.*vp * df; |
421 |
+ |
cres->flags = C_CDXY|C_CSXY; |
422 |
+ |
} |
423 |
+ |
|
424 |
+ |
#undef UV_NORMF |