ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/mgflib/cvrgb.c
Revision: 1.3
Committed: Sat Nov 15 17:54:06 2003 UTC (20 years, 5 months ago) by schorsch
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R7P1, rad4R0, rad3R6, rad3R6P1, rad3R8, rad3R9, rad3R7P2
Changes since 1.2: +7 -5 lines
Log Message:
Continued ANSIfication and reduced compile warnings.

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: cvrgb.c,v 1.2 2003/02/28 20:11:29 greg Exp $";
3 #endif
4 /*
5 * Convert MGF color to RGB representation defined below.
6 */
7
8 #include <stdio.h>
9 #include <stdlib.h>
10
11 #include "parser.h"
12
13 /* Change the following to suit your standard */
14 #define CIE_x_r 0.640 /* nominal CRT primaries */
15 #define CIE_y_r 0.330
16 #define CIE_x_g 0.290
17 #define CIE_y_g 0.600
18 #define CIE_x_b 0.150
19 #define CIE_y_b 0.060
20 #define CIE_x_w 0.3333 /* use true white */
21 #define CIE_y_w 0.3333
22
23 #define CIE_C_rD ( (1./CIE_y_w) * \
24 ( CIE_x_w*(CIE_y_g - CIE_y_b) - \
25 CIE_y_w*(CIE_x_g - CIE_x_b) + \
26 CIE_x_g*CIE_y_b - CIE_x_b*CIE_y_g ) )
27 #define CIE_C_gD ( (1./CIE_y_w) * \
28 ( CIE_x_w*(CIE_y_b - CIE_y_r) - \
29 CIE_y_w*(CIE_x_b - CIE_x_r) - \
30 CIE_x_r*CIE_y_b + CIE_x_b*CIE_y_r ) )
31 #define CIE_C_bD ( (1./CIE_y_w) * \
32 ( CIE_x_w*(CIE_y_r - CIE_y_g) - \
33 CIE_y_w*(CIE_x_r - CIE_x_g) + \
34 CIE_x_r*CIE_y_g - CIE_x_g*CIE_y_r ) )
35
36
37 float xyz2rgbmat[3][3] = { /* XYZ to RGB conversion matrix */
38 {(CIE_y_g - CIE_y_b - CIE_x_b*CIE_y_g + CIE_y_b*CIE_x_g)/CIE_C_rD,
39 (CIE_x_b - CIE_x_g - CIE_x_b*CIE_y_g + CIE_x_g*CIE_y_b)/CIE_C_rD,
40 (CIE_x_g*CIE_y_b - CIE_x_b*CIE_y_g)/CIE_C_rD},
41 {(CIE_y_b - CIE_y_r - CIE_y_b*CIE_x_r + CIE_y_r*CIE_x_b)/CIE_C_gD,
42 (CIE_x_r - CIE_x_b - CIE_x_r*CIE_y_b + CIE_x_b*CIE_y_r)/CIE_C_gD,
43 (CIE_x_b*CIE_y_r - CIE_x_r*CIE_y_b)/CIE_C_gD},
44 {(CIE_y_r - CIE_y_g - CIE_y_r*CIE_x_g + CIE_y_g*CIE_x_r)/CIE_C_bD,
45 (CIE_x_g - CIE_x_r - CIE_x_g*CIE_y_r + CIE_x_r*CIE_y_g)/CIE_C_bD,
46 (CIE_x_r*CIE_y_g - CIE_x_g*CIE_y_r)/CIE_C_bD}
47 };
48
49
50 void
51 mgf2rgb( /* convert MGF color to RGB */
52 register C_COLOR *cin, /* input MGF chrominance */
53 double intensity, /* input luminance or reflectance */
54 register float cout[3] /* output RGB color */
55 )
56 {
57 static double cie[3];
58 /* get CIE XYZ representation */
59 c_ccvt(cin, C_CSXY);
60 cie[0] = intensity*cin->cx/cin->cy;
61 cie[1] = intensity;
62 cie[2] = intensity*(1./cin->cy - 1.) - cie[0];
63 /* convert to RGB */
64 cout[0] = xyz2rgbmat[0][0]*cie[0] + xyz2rgbmat[0][1]*cie[1]
65 + xyz2rgbmat[0][2]*cie[2];
66 if(cout[0] < 0.) cout[0] = 0.;
67 cout[1] = xyz2rgbmat[1][0]*cie[0] + xyz2rgbmat[1][1]*cie[1]
68 + xyz2rgbmat[1][2]*cie[2];
69 if(cout[1] < 0.) cout[1] = 0.;
70 cout[2] = xyz2rgbmat[2][0]*cie[0] + xyz2rgbmat[2][1]*cie[1]
71 + xyz2rgbmat[2][2]*cie[2];
72 if(cout[2] < 0.) cout[2] = 0.;
73 }