| 1 |
#ifndef lint
|
| 2 |
static const char RCSid[] = "$Id: ccyrgb.c,v 3.3 2012/05/17 17:10:23 greg Exp $";
|
| 3 |
#endif
|
| 4 |
/*
|
| 5 |
* Convert MGF color to RGB representation
|
| 6 |
*/
|
| 7 |
|
| 8 |
#include <stdio.h>
|
| 9 |
#include "color.h"
|
| 10 |
#include "ccolor.h"
|
| 11 |
|
| 12 |
void
|
| 13 |
ccy2rgb( /* convert MGF color to RGB */
|
| 14 |
C_COLOR *cin, /* input MGF chrominance */
|
| 15 |
double cieY, /* input luminance or reflectance */
|
| 16 |
COLOR cout /* output RGB color */
|
| 17 |
)
|
| 18 |
{
|
| 19 |
double d;
|
| 20 |
COLOR xyz;
|
| 21 |
/* get CIE XYZ representation */
|
| 22 |
c_ccvt(cin, C_CSXY);
|
| 23 |
d = cin->cx/cin->cy;
|
| 24 |
xyz[CIEX] = d * cieY;
|
| 25 |
xyz[CIEY] = cieY;
|
| 26 |
xyz[CIEZ] = (1./cin->cy - d - 1.) * cieY;
|
| 27 |
cie_rgb(cout, xyz);
|
| 28 |
}
|
| 29 |
|
| 30 |
/* Convert RGB to MGF color and value */
|
| 31 |
double
|
| 32 |
rgb2ccy(COLOR cin, C_COLOR *cout)
|
| 33 |
{
|
| 34 |
COLOR xyz;
|
| 35 |
double df;
|
| 36 |
|
| 37 |
rgb_cie(xyz, cin);
|
| 38 |
*cout = c_dfcolor;
|
| 39 |
df = xyz[CIEX] + xyz[CIEY] + xyz[CIEZ];
|
| 40 |
if (df <= .0)
|
| 41 |
return(.0);
|
| 42 |
df = 1./df;
|
| 43 |
cout->cx = xyz[CIEX]*df;
|
| 44 |
cout->cy = xyz[CIEZ]*df;
|
| 45 |
cout->flags = (C_CSXY|C_CDXY);
|
| 46 |
|
| 47 |
return(xyz[CIEY]);
|
| 48 |
}
|