ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/mgflib/cvrgb.c
Revision: 1.2
Committed: Fri Feb 28 20:11:29 2003 UTC (21 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Changes since 1.1: +2 -4 lines
Log Message:
Updates for 3.5 release

File Contents

# User Rev Content
1 greg 1.1 #ifndef lint
2 greg 1.2 static const char RCSid[] = "$Id$";
3 greg 1.1 #endif
4     /*
5     * Convert MGF color to RGB representation defined below.
6     */
7    
8     #include <stdio.h>
9 greg 1.2 #include <stdlib.h>
10 greg 1.1
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     mgf2rgb(cin, intensity, cout) /* convert MGF color to RGB */
51     register C_COLOR *cin; /* input MGF chrominance */
52     double intensity; /* input luminance or reflectance */
53     register float cout[3]; /* output RGB color */
54     {
55     static double cie[3];
56     /* get CIE XYZ representation */
57     c_ccvt(cin, C_CSXY);
58     cie[0] = intensity*cin->cx/cin->cy;
59     cie[1] = intensity;
60     cie[2] = intensity*(1./cin->cy - 1.) - cie[0];
61     /* convert to RGB */
62     cout[0] = xyz2rgbmat[0][0]*cie[0] + xyz2rgbmat[0][1]*cie[1]
63     + xyz2rgbmat[0][2]*cie[2];
64     if(cout[0] < 0.) cout[0] = 0.;
65     cout[1] = xyz2rgbmat[1][0]*cie[0] + xyz2rgbmat[1][1]*cie[1]
66     + xyz2rgbmat[1][2]*cie[2];
67     if(cout[1] < 0.) cout[1] = 0.;
68     cout[2] = xyz2rgbmat[2][0]*cie[0] + xyz2rgbmat[2][1]*cie[1]
69     + xyz2rgbmat[2][2]*cie[2];
70     if(cout[2] < 0.) cout[2] = 0.;
71     }