1 |
greg |
3.1 |
#ifndef lint |
2 |
greg |
3.3 |
static const char RCSid[] = "$Id: ccyrgb.c,v 3.2 2011/06/28 21:11:04 greg Exp $"; |
3 |
greg |
3.1 |
#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 |
greg |
3.2 |
return(.0); |
42 |
greg |
3.1 |
df = 1./df; |
43 |
|
|
cout->cx = xyz[CIEX]*df; |
44 |
|
|
cout->cy = xyz[CIEZ]*df; |
45 |
|
|
cout->flags = (C_CSXY|C_CDXY); |
46 |
greg |
3.3 |
cout->clock++; |
47 |
greg |
3.1 |
|
48 |
|
|
return(xyz[CIEY]); |
49 |
|
|
} |