ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cal/cal/xyz_rgb.cal
Revision: 1.1
Committed: Sat Feb 22 02:07:21 2003 UTC (21 years, 1 month ago) by greg
Branch: MAIN
CVS Tags: rad3R5, rad3R6, rad3R6P1
Log Message:
Changes and check-in for 3.5 release
Includes new source files and modifications not recorded for many years
See ray/doc/notes/ReleaseNotes for notes between 3.1 and 3.5 release

File Contents

# Content
1 {
2 Convert between XYZ and RGB coordinates.
3
4 2/17/95
5
6 Be sure that CIE_x_r, etc. definitions are consistent with
7 those in ray/src/common/color.h.
8 }
9
10 {*** The whole calculation is based on the CIE (x,y) chromaticities below ***}
11
12 CIE_x_r : 0.640 ; { nominal CRT primaries }
13 CIE_y_r : 0.330 ;
14 CIE_x_g : 0.290 ;
15 CIE_y_g : 0.600 ;
16 CIE_x_b : 0.150 ;
17 CIE_y_b : 0.060 ;
18 CIE_x_w : 1/3 ; { use true white }
19 CIE_y_w : 1/3 ;
20
21 WHTEFFICACY : 179. ; { luminous efficacy of uniform white light }
22
23 { Derived constants }
24
25 CIE_D : CIE_x_r*(CIE_y_g - CIE_y_b) +
26 CIE_x_g*(CIE_y_b - CIE_y_r) +
27 CIE_x_b*(CIE_y_r - CIE_y_g) ;
28
29 CIE_C_rD : (1./CIE_y_w) * ( CIE_x_w*(CIE_y_g - CIE_y_b) -
30 CIE_y_w*(CIE_x_g - CIE_x_b) +
31 CIE_x_g*CIE_y_b - CIE_x_b*CIE_y_g ) ;
32
33 CIE_C_gD : (1./CIE_y_w) * ( CIE_x_w*(CIE_y_b - CIE_y_r) -
34 CIE_y_w*(CIE_x_b - CIE_x_r) -
35 CIE_x_r*CIE_y_b + CIE_x_b*CIE_y_r ) ;
36
37 CIE_C_bD : (1./CIE_y_w) * ( CIE_x_w*(CIE_y_r - CIE_y_g) -
38 CIE_y_w*(CIE_x_r - CIE_x_g) +
39 CIE_x_r*CIE_y_g - CIE_x_g*CIE_y_r ) ;
40
41 { Convert CIE XYZ coordinates to RGB }
42
43 XYZ2RGB(i,j) : select(i*3+j+1,
44 (CIE_y_g - CIE_y_b - CIE_x_b*CIE_y_g + CIE_y_b*CIE_x_g)/CIE_C_rD,
45 (CIE_x_b - CIE_x_g - CIE_x_b*CIE_y_g + CIE_x_g*CIE_y_b)/CIE_C_rD,
46 (CIE_x_g*CIE_y_b - CIE_x_b*CIE_y_g)/CIE_C_rD,
47 (CIE_y_b - CIE_y_r - CIE_y_b*CIE_x_r + CIE_y_r*CIE_x_b)/CIE_C_gD,
48 (CIE_x_r - CIE_x_b - CIE_x_r*CIE_y_b + CIE_x_b*CIE_y_r)/CIE_C_gD,
49 (CIE_x_b*CIE_y_r - CIE_x_r*CIE_y_b)/CIE_C_gD,
50 (CIE_y_r - CIE_y_g - CIE_y_r*CIE_x_g + CIE_y_g*CIE_x_r)/CIE_C_bD,
51 (CIE_x_g - CIE_x_r - CIE_x_g*CIE_y_r + CIE_x_r*CIE_y_g)/CIE_C_bD,
52 (CIE_x_r*CIE_y_g - CIE_x_g*CIE_y_r)/CIE_C_bD
53 );
54
55 noneg(x) : if(x, x, 0);
56
57 R(X,Y,Z) : noneg(XYZ2RGB(0,0)*X + XYZ2RGB(0,1)*Y + XYZ2RGB(0,2)*Z);
58 G(X,Y,Z) : noneg(XYZ2RGB(1,0)*X + XYZ2RGB(1,1)*Y + XYZ2RGB(1,2)*Z);
59 B(X,Y,Z) : noneg(XYZ2RGB(2,0)*X + XYZ2RGB(2,1)*Y + XYZ2RGB(2,2)*Z);
60
61 { Convert RGB to CIE XYZ coordinates }
62
63 RGB2XYZ(i,j) : select(i*3+j+1,
64 CIE_x_r*CIE_C_rD/CIE_D,CIE_x_g*CIE_C_gD/CIE_D,CIE_x_b*CIE_C_bD/CIE_D,
65 CIE_y_r*CIE_C_rD/CIE_D,CIE_y_g*CIE_C_gD/CIE_D,CIE_y_b*CIE_C_bD/CIE_D,
66 (1.-CIE_x_r-CIE_y_r)*CIE_C_rD/CIE_D,
67 (1.-CIE_x_g-CIE_y_g)*CIE_C_gD/CIE_D,
68 (1.-CIE_x_b-CIE_y_b)*CIE_C_bD/CIE_D
69 );
70
71 X(R,G,B) : RGB2XYZ(0,0)*R + RGB2XYZ(0,1)*G + RGB2XYZ(0,2)*B;
72 Y(R,G,B) : RGB2XYZ(1,0)*R + RGB2XYZ(1,1)*G + RGB2XYZ(1,2)*B;
73 Z(R,G,B) : RGB2XYZ(2,0)*R + RGB2XYZ(2,1)*G + RGB2XYZ(2,2)*B;
74
75 { Convert spectral radiance in watts/sr/m^2 to luminance in cd/m^2 }
76
77 luminance(r,g,b) = WHTEFFICACY * Y(r,g,b) ;