ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cal/cal/xyz_srgb.cal
Revision: 1.1
Committed: Sat Feb 22 02:07:21 2003 UTC (21 years, 2 months 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 :.640; { CCIR709 primaries }
13 CIE_y_r :.330;
14 CIE_x_g :.300;
15 CIE_y_g :.600;
16 CIE_x_b :0.150;
17 CIE_y_b :0.060;
18
19 CIE_x_w:.3127; { Illuminant D65 }
20 CIE_y_w:.3290;
21
22 WHTEFFICACY : 179. ; { luminous efficacy of uniform white light }
23
24 { Derived constants }
25
26 CIE_D : CIE_x_r*(CIE_y_g - CIE_y_b) +
27 CIE_x_g*(CIE_y_b - CIE_y_r) +
28 CIE_x_b*(CIE_y_r - CIE_y_g) ;
29
30 CIE_C_rD : (1./CIE_y_w) * ( CIE_x_w*(CIE_y_g - CIE_y_b) -
31 CIE_y_w*(CIE_x_g - CIE_x_b) +
32 CIE_x_g*CIE_y_b - CIE_x_b*CIE_y_g ) ;
33
34 CIE_C_gD : (1./CIE_y_w) * ( CIE_x_w*(CIE_y_b - CIE_y_r) -
35 CIE_y_w*(CIE_x_b - CIE_x_r) -
36 CIE_x_r*CIE_y_b + CIE_x_b*CIE_y_r ) ;
37
38 CIE_C_bD : (1./CIE_y_w) * ( CIE_x_w*(CIE_y_r - CIE_y_g) -
39 CIE_y_w*(CIE_x_r - CIE_x_g) +
40 CIE_x_r*CIE_y_g - CIE_x_g*CIE_y_r ) ;
41
42 { Convert CIE XYZ coordinates to RGB }
43
44 XYZ2RGB(i,j) : select(i*3+j+1,
45 (CIE_y_g - CIE_y_b - CIE_x_b*CIE_y_g + CIE_y_b*CIE_x_g)/CIE_C_rD,
46 (CIE_x_b - CIE_x_g - CIE_x_b*CIE_y_g + CIE_x_g*CIE_y_b)/CIE_C_rD,
47 (CIE_x_g*CIE_y_b - CIE_x_b*CIE_y_g)/CIE_C_rD,
48 (CIE_y_b - CIE_y_r - CIE_y_b*CIE_x_r + CIE_y_r*CIE_x_b)/CIE_C_gD,
49 (CIE_x_r - CIE_x_b - CIE_x_r*CIE_y_b + CIE_x_b*CIE_y_r)/CIE_C_gD,
50 (CIE_x_b*CIE_y_r - CIE_x_r*CIE_y_b)/CIE_C_gD,
51 (CIE_y_r - CIE_y_g - CIE_y_r*CIE_x_g + CIE_y_g*CIE_x_r)/CIE_C_bD,
52 (CIE_x_g - CIE_x_r - CIE_x_g*CIE_y_r + CIE_x_r*CIE_y_g)/CIE_C_bD,
53 (CIE_x_r*CIE_y_g - CIE_x_g*CIE_y_r)/CIE_C_bD
54 );
55
56 { noneg(x) : if(x, x, 0); }
57 noneg(x) : x;
58
59 R(X,Y,Z) : noneg(XYZ2RGB(0,0)*X + XYZ2RGB(0,1)*Y + XYZ2RGB(0,2)*Z);
60 G(X,Y,Z) : noneg(XYZ2RGB(1,0)*X + XYZ2RGB(1,1)*Y + XYZ2RGB(1,2)*Z);
61 B(X,Y,Z) : noneg(XYZ2RGB(2,0)*X + XYZ2RGB(2,1)*Y + XYZ2RGB(2,2)*Z);
62
63 { Convert RGB to CIE XYZ coordinates }
64
65 RGB2XYZ(i,j) : select(i*3+j+1,
66 CIE_x_r*CIE_C_rD/CIE_D,CIE_x_g*CIE_C_gD/CIE_D,CIE_x_b*CIE_C_bD/CIE_D,
67 CIE_y_r*CIE_C_rD/CIE_D,CIE_y_g*CIE_C_gD/CIE_D,CIE_y_b*CIE_C_bD/CIE_D,
68 (1.-CIE_x_r-CIE_y_r)*CIE_C_rD/CIE_D,
69 (1.-CIE_x_g-CIE_y_g)*CIE_C_gD/CIE_D,
70 (1.-CIE_x_b-CIE_y_b)*CIE_C_bD/CIE_D
71 );
72
73 X(R,G,B) : RGB2XYZ(0,0)*R + RGB2XYZ(0,1)*G + RGB2XYZ(0,2)*B;
74 Y(R,G,B) : RGB2XYZ(1,0)*R + RGB2XYZ(1,1)*G + RGB2XYZ(1,2)*B;
75 Z(R,G,B) : RGB2XYZ(2,0)*R + RGB2XYZ(2,1)*G + RGB2XYZ(2,2)*B;
76
77 { Convert spectral radiance in watts/sr/m^2 to luminance in cd/m^2 }
78
79 luminance(r,g,b) = WHTEFFICACY * Y(r,g,b) ;