ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/ccyrgb.c
Revision: 3.1
Committed: Fri Feb 18 00:40:25 2011 UTC (13 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
Log Message:
Major code reorg, moving mgflib to common and introducing BSDF material

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: cvrgb.c,v 1.3 2003/11/15 17:54:06 schorsch 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;
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 }