ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cal/cal/Sharp.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

# User Rev Content
1 greg 1.1 {
2     Convert between XYZ and Sharp RGB coordinates
3    
4     3/22/02
5     }
6    
7     {*** The whole calculation is based on the CIE (x,y) chromaticities below ***}
8    
9     CIE_x_r : .6898;
10     CIE_y_r : .3206;
11     CIE_x_g : .0736;
12     CIE_y_g : .9003;
13     CIE_x_b : .1166;
14     CIE_y_b : .0374;
15     CIE_x_w : 1/3;
16     CIE_y_w : 1/3;
17    
18     WHTEFFICACY : 179. ; { luminous efficacy of uniform white light }
19    
20     { Derived constants }
21    
22     CIE_D : CIE_x_r*(CIE_y_g - CIE_y_b) +
23     CIE_x_g*(CIE_y_b - CIE_y_r) +
24     CIE_x_b*(CIE_y_r - CIE_y_g) ;
25    
26     CIE_C_rD : (1./CIE_y_w) * ( CIE_x_w*(CIE_y_g - CIE_y_b) -
27     CIE_y_w*(CIE_x_g - CIE_x_b) +
28     CIE_x_g*CIE_y_b - CIE_x_b*CIE_y_g ) ;
29    
30     CIE_C_gD : (1./CIE_y_w) * ( CIE_x_w*(CIE_y_b - CIE_y_r) -
31     CIE_y_w*(CIE_x_b - CIE_x_r) -
32     CIE_x_r*CIE_y_b + CIE_x_b*CIE_y_r ) ;
33    
34     CIE_C_bD : (1./CIE_y_w) * ( CIE_x_w*(CIE_y_r - CIE_y_g) -
35     CIE_y_w*(CIE_x_r - CIE_x_g) +
36     CIE_x_r*CIE_y_g - CIE_x_g*CIE_y_r ) ;
37    
38     { Convert CIE XYZ coordinates to RGB }
39    
40     XYZ2RGB(i,j) : select(i*3+j+1,
41     (CIE_y_g - CIE_y_b - CIE_x_b*CIE_y_g + CIE_y_b*CIE_x_g)/CIE_C_rD,
42     (CIE_x_b - CIE_x_g - CIE_x_b*CIE_y_g + CIE_x_g*CIE_y_b)/CIE_C_rD,
43     (CIE_x_g*CIE_y_b - CIE_x_b*CIE_y_g)/CIE_C_rD,
44     (CIE_y_b - CIE_y_r - CIE_y_b*CIE_x_r + CIE_y_r*CIE_x_b)/CIE_C_gD,
45     (CIE_x_r - CIE_x_b - CIE_x_r*CIE_y_b + CIE_x_b*CIE_y_r)/CIE_C_gD,
46     (CIE_x_b*CIE_y_r - CIE_x_r*CIE_y_b)/CIE_C_gD,
47     (CIE_y_r - CIE_y_g - CIE_y_r*CIE_x_g + CIE_y_g*CIE_x_r)/CIE_C_bD,
48     (CIE_x_g - CIE_x_r - CIE_x_g*CIE_y_r + CIE_x_r*CIE_y_g)/CIE_C_bD,
49     (CIE_x_r*CIE_y_g - CIE_x_g*CIE_y_r)/CIE_C_bD
50     );
51    
52     noneg(x) : if(x, x, 0);
53    
54     R(X,Y,Z) : noneg(XYZ2RGB(0,0)*X + XYZ2RGB(0,1)*Y + XYZ2RGB(0,2)*Z);
55     G(X,Y,Z) : noneg(XYZ2RGB(1,0)*X + XYZ2RGB(1,1)*Y + XYZ2RGB(1,2)*Z);
56     B(X,Y,Z) : noneg(XYZ2RGB(2,0)*X + XYZ2RGB(2,1)*Y + XYZ2RGB(2,2)*Z);
57    
58     { Convert RGB to CIE XYZ coordinates }
59    
60     RGB2XYZ(i,j) : select(i*3+j+1,
61     CIE_x_r*CIE_C_rD/CIE_D,CIE_x_g*CIE_C_gD/CIE_D,CIE_x_b*CIE_C_bD/CIE_D,
62     CIE_y_r*CIE_C_rD/CIE_D,CIE_y_g*CIE_C_gD/CIE_D,CIE_y_b*CIE_C_bD/CIE_D,
63     (1.-CIE_x_r-CIE_y_r)*CIE_C_rD/CIE_D,
64     (1.-CIE_x_g-CIE_y_g)*CIE_C_gD/CIE_D,
65     (1.-CIE_x_b-CIE_y_b)*CIE_C_bD/CIE_D
66     );
67    
68     X(R,G,B) : RGB2XYZ(0,0)*R + RGB2XYZ(0,1)*G + RGB2XYZ(0,2)*B;
69     Y(R,G,B) : RGB2XYZ(1,0)*R + RGB2XYZ(1,1)*G + RGB2XYZ(1,2)*B;
70     Z(R,G,B) : RGB2XYZ(2,0)*R + RGB2XYZ(2,1)*G + RGB2XYZ(2,2)*B;
71    
72     { Convert spectral radiance in watts/sr/m^2 to luminance in cd/m^2 }
73    
74     luminance(r,g,b) = WHTEFFICACY * Y(r,g,b) ;