ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/ccolor.c
(Generate patch)

Comparing ray/src/common/ccolor.c (file contents):
Revision 3.1 by greg, Fri Feb 18 00:40:25 2011 UTC vs.
Revision 3.2 by greg, Thu May 17 05:47:59 2012 UTC

# Line 13 | Line 13 | static const char RCSid[] = "$Id$";
13   C_COLOR         c_dfcolor = C_DEFCOLOR;
14  
15                                  /* CIE 1931 Standard Observer curves */
16 < static C_COLOR  cie_xf = { 1, NULL, C_CDSPEC|C_CSSPEC|C_CSXY|C_CSEFF,
16 > static const C_COLOR    cie_xf = { 1, NULL, C_CDSPEC|C_CSSPEC|C_CSXY|C_CSEFF,
17                          {14,42,143,435,1344,2839,3483,3362,2908,1954,956,
18                          320,49,93,633,1655,2904,4334,5945,7621,9163,10263,
19                          10622,10026,8544,6424,4479,2835,1649,874,468,227,
20                          114,58,29,14,7,3,2,1,0}, 106836L, .467, .368, 362.230
21                          };
22 < static C_COLOR  cie_yf = { 1, NULL, C_CDSPEC|C_CSSPEC|C_CSXY|C_CSEFF,
22 > static const C_COLOR    cie_yf = { 1, NULL, C_CDSPEC|C_CSSPEC|C_CSXY|C_CSEFF,
23                          {0,1,4,12,40,116,230,380,600,910,1390,2080,3230,
24                          5030,7100,8620,9540,9950,9950,9520,8700,7570,6310,
25                          5030,3810,2650,1750,1070,610,320,170,82,41,21,10,
26                          5,2,1,1,0,0}, 106856L, .398, .542, 493.525
27                          };
28 < static C_COLOR  cie_zf = { 1, NULL, C_CDSPEC|C_CSSPEC|C_CSXY|C_CSEFF,
28 > static const C_COLOR    cie_zf = { 1, NULL, C_CDSPEC|C_CSSPEC|C_CSXY|C_CSEFF,
29                          {65,201,679,2074,6456,13856,17471,17721,16692,
30                          12876,8130,4652,2720,1582,782,422,203,87,39,21,17,
31                          11,8,3,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
32                          106770L, .147, .077, 54.363
33                          };
34                                  /* Derived CIE 1931 Primaries (imaginary) */
35 < static C_COLOR  cie_xp = { 1, NULL, C_CDSPEC|C_CSSPEC|C_CSXY,
35 > static const C_COLOR    cie_xp = { 1, NULL, C_CDSPEC|C_CSSPEC|C_CSXY,
36                          {-174,-198,-195,-197,-202,-213,-235,-272,-333,
37                          -444,-688,-1232,-2393,-4497,-6876,-6758,-5256,
38                          -3100,-815,1320,3200,4782,5998,6861,7408,7754,
# Line 40 | Line 40 | static C_COLOR cie_xp = { 1, NULL, C_CDSPEC|C_CSSPEC|C
40                          8336,8336,8336,8336,8336,8336},
41                          127424L, 1., .0,
42                          };
43 < static C_COLOR  cie_yp = { 1, NULL, C_CDSPEC|C_CSSPEC|C_CSXY,
43 > static const C_COLOR    cie_yp = { 1, NULL, C_CDSPEC|C_CSSPEC|C_CSXY,
44                          {-451,-431,-431,-430,-427,-417,-399,-366,-312,
45                          -204,57,691,2142,4990,8810,9871,9122,7321,5145,
46                          3023,1123,-473,-1704,-2572,-3127,-3474,-3704,
# Line 48 | Line 48 | static C_COLOR cie_yp = { 1, NULL, C_CDSPEC|C_CSSPEC|C
48                          -4066,-4066,-4066,-4066,-4066,-4066},
49                          -23035L, .0, 1.,
50                          };
51 < static C_COLOR  cie_zp = { 1, NULL, C_CDSPEC|C_CSSPEC|C_CSXY,
51 > static const C_COLOR    cie_zp = { 1, NULL, C_CDSPEC|C_CSSPEC|C_CSXY,
52                          {4051,4054,4052,4053,4054,4056,4059,4064,4071,
53                          4074,4056,3967,3677,2933,1492,313,-440,-795,
54                          -904,-918,-898,-884,-869,-863,-855,-855,-851,
# Line 57 | Line 57 | static C_COLOR cie_zp = { 1, NULL, C_CDSPEC|C_CSSPEC|C
57                          36057L, .0, .0,
58                          };
59  
60 +                                        /* Sharp primary matrix */
61 + static const float      toSharp[3][3] = {
62 +        { 1.2694, -0.0988, -0.1706},
63 +        {-0.8364,  1.8006,  0.0357},
64 +        { 0.0297, -0.0315,  1.0018}
65 + };
66 +                                        /* inverse Sharp primary matrix */
67 + static const float      fromSharp[3][3] = {
68 +        { 0.8156,  0.0472,  0.1372},
69 +        { 0.3791,  0.5769,  0.0440},
70 +        {-0.0123,  0.0167,  0.9955}
71 + };
72 +
73 + static void
74 + c_toSharpRGB(C_COLOR *cin, double cieY, float cout[3])
75 + {
76 +        double  xyz[3];
77 +
78 +        c_ccvt(cin, C_CSXY);
79 +
80 +        xyz[0] = cin->cx/cin->cy * cieY;
81 +        xyz[1] = cieY;
82 +        xyz[2] = (1. - cin->cx - cin->cy)/cin->cy * cieY;
83 +
84 +        cout[0] = toSharp[0][0]*xyz[0] + toSharp[0][1]*xyz[1] +
85 +                                toSharp[0][2]*xyz[2];
86 +        cout[1] = toSharp[1][0]*xyz[0] + toSharp[1][1]*xyz[1] +
87 +                                toSharp[1][2]*xyz[2];
88 +        cout[2] = toSharp[2][0]*xyz[0] + toSharp[2][1]*xyz[1] +
89 +                                toSharp[2][2]*xyz[2];
90 + }
91 +
92 + static double
93 + c_fromSharpRGB(float cin[3], C_COLOR *cout)
94 + {
95 +        double  xyz[3], sf;
96 +
97 +        xyz[0] = fromSharp[0][0]*cin[0] + fromSharp[0][1]*cin[1] +
98 +                                fromSharp[0][2]*cin[2];
99 +        xyz[1] = fromSharp[1][0]*cin[0] + fromSharp[1][1]*cin[1] +
100 +                                fromSharp[1][2]*cin[2];
101 +        xyz[2] = fromSharp[2][0]*cin[0] + fromSharp[2][1]*cin[1] +
102 +                                fromSharp[2][2]*cin[2];
103 +                                
104 +        sf = 1./(xyz[0] + xyz[1] + xyz[2]);
105 +
106 +        cout->cx = xyz[0] * sf;
107 +        cout->cy = xyz[1] * sf;
108 +        cout->flags = C_CDXY|C_CSXY;
109 +        
110 +        return(xyz[1]);
111 + }
112 +
113   /* check if color is grey */
114   int
115   c_isgrey(C_COLOR *clr)
# Line 127 | Line 180 | c_ccvt(C_COLOR *clr, int fl)
180          }
181   }
182  
183 < /* mix two colors according to weights given -- cres can be c1 or c2 */
183 > /* mix two colors according to weights given -- cres may be c1 or c2 */
184   void
185   c_cmix(C_COLOR *cres, double w1, C_COLOR *c1, double w2, C_COLOR *c2)
186   {
187          double  scale;
135        float   cmix[C_CNSS];
188          int     i;
189  
190          if ((c1->flags|c2->flags) & C_CDSPEC) {         /* spectral mixing */
191 +                float   cmix[C_CNSS];
192 +
193                  c_ccvt(c1, C_CSSPEC|C_CSEFF);
194                  c_ccvt(c2, C_CSSPEC|C_CSEFF);
195                  w1 /= c1->eff*c1->ssum;
# Line 168 | Line 222 | c_cmix(C_COLOR *cres, double w1, C_COLOR *c1, double w
222          }
223   }
224  
225 + /* multiply two colors -- cres may be c1 or c2 */
226 + double
227 + c_cmult(C_COLOR *cres, C_COLOR *c1, double y1, C_COLOR *c2, double y2)
228 + {
229 +        double  yres;
230 +        int     i;
231 +
232 +        if ((c1->flags|c2->flags) & C_CDSPEC) {
233 +                long    cmix[C_CNSS], cmax = 0;         /* spectral multiply */
234 +
235 +                c_ccvt(c1, C_CSSPEC|C_CSEFF);
236 +                c_ccvt(c2, C_CSSPEC|C_CSEFF);
237 +                for (i = 0; i < C_CNSS; i++) {
238 +                        cmix[i] = c1->ssamp[i] * c2->ssamp[i];
239 +                        if (cmix[i] > cmax)
240 +                                cmax = cmix[i];
241 +                }
242 +                cmax /= C_CMAXV;
243 +                if (!cmax) {
244 +                        *cres = c_dfcolor;
245 +                        return(0.);
246 +                }
247 +                cres->ssum = 0;
248 +                for (i = 0; i < C_CNSS; i++)
249 +                        cres->ssum += cres->ssamp[i] = cmix[i] / cmax;
250 +                cres->flags = C_CDSPEC|C_CSSPEC;
251 +
252 +                c_ccvt(cres, C_CSEFF);                  /* nasty, but true */
253 +                yres = (y1 * y2 * cie_yf.ssum * C_CLPWM) /
254 +                        (c1->eff*c1->ssum * c2->eff*c2->ssum) *
255 +                        cres->eff*( cres->ssum*(double)cmax +
256 +                                                C_CNSS/2.0*(cmax-1) );
257 +        } else {
258 +                float   rgb1[3], rgb2[3];               /* CIE xy multiply */
259 +
260 +                c_toSharpRGB(c1, y1, rgb1);
261 +                c_toSharpRGB(c2, y2, rgb2);
262 +                
263 +                rgb2[0] *= rgb1[0]; rgb2[1] *= rgb1[1]; rgb2[2] *= rgb1[2];
264 +
265 +                yres = c_fromSharpRGB(rgb2, cres);
266 +        }
267 +        return(yres);
268 + }
269 +
270   #define C1              3.741832e-16    /* W-m^2 */
271   #define C2              1.4388e-2       /* m-K */
272  
273   #define bbsp(l,t)       (C1/((l)*(l)*(l)*(l)*(l)*(exp(C2/((t)*(l)))-1.)))
274 < #define bblm(t)         (C2/5./(t))
274 > #define bblm(t)         (C2*0.2/(t))
275  
276   /* set black body spectrum */
277   int

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines