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.4 by greg, Fri May 18 20:43:13 2012 UTC vs.
Revision 3.6 by greg, Tue Jul 17 23:40:24 2012 UTC

# Line 22 | Line 22 | float  XYZfromSharp[3][3] = {
22          {-0.0123,  0.0167,  0.9955}
23   };
24  
25 < C_COLOR         c_dfcolor = C_DEFCOLOR;
25 > const C_COLOR   c_dfcolor = C_DEFCOLOR;
26  
27                                  /* CIE 1931 Standard Observer curves */
28 < static const C_COLOR    cie_xf = { 1, NULL, C_CDSPEC|C_CSSPEC|C_CSXY|C_CSEFF,
28 > const C_COLOR   c_x31 = { 1, NULL, C_CDSPEC|C_CSSPEC|C_CSXY|C_CSEFF,
29                          {14,42,143,435,1344,2839,3483,3362,2908,1954,956,
30                          320,49,93,633,1655,2904,4334,5945,7621,9163,10263,
31                          10622,10026,8544,6424,4479,2835,1649,874,468,227,
32                          114,58,29,14,7,3,2,1,0}, 106836L, .467, .368, 362.230
33                          };
34 < static const C_COLOR    cie_yf = { 1, NULL, C_CDSPEC|C_CSSPEC|C_CSXY|C_CSEFF,
34 > const C_COLOR   c_y31 = { 1, NULL, C_CDSPEC|C_CSSPEC|C_CSXY|C_CSEFF,
35                          {0,1,4,12,40,116,230,380,600,910,1390,2080,3230,
36                          5030,7100,8620,9540,9950,9950,9520,8700,7570,6310,
37                          5030,3810,2650,1750,1070,610,320,170,82,41,21,10,
38                          5,2,1,1,0,0}, 106856L, .398, .542, 493.525
39                          };
40 < static const C_COLOR    cie_zf = { 1, NULL, C_CDSPEC|C_CSSPEC|C_CSXY|C_CSEFF,
40 > const C_COLOR   c_z31 = { 1, NULL, C_CDSPEC|C_CSSPEC|C_CSXY|C_CSEFF,
41                          {65,201,679,2074,6456,13856,17471,17721,16692,
42                          12876,8130,4652,2720,1582,782,422,203,87,39,21,17,
43                          11,8,3,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
# Line 112 | Line 112 | c_fromSharpRGB(float cin[3], C_COLOR *cout)
112          return(xyz[1]);
113   }
114  
115 < /* assign arbitrary spectrum */
115 > /* assign arbitrary spectrum and return Y value */
116   double
117   c_sset(C_COLOR *clr, double wlmin, double wlmax, const float spec[], int nwl)
118   {
# Line 134 | Line 134 | c_sset(C_COLOR *clr, double wlmin, double wlmax, const
134                  wlmax -= wlstep;
135                  --nwl;
136          }
137 +        if ((nwl <= 1) | (wlmin >= wlmax))
138 +                return(0.);
139          imax = nwl;                     /* box filter if necessary */
140          boxpos = 0;
141          boxstep = 1;
# Line 159 | Line 161 | c_sset(C_COLOR *clr, double wlmin, double wlmax, const
161                          scale = va[i];
162                  else if (va[i] < -scale)
163                          scale = -va[i];
164 <                yval += va[i] * cie_yf.ssamp[i];
164 >                yval += va[i] * c_y31.ssamp[i];
165          }
166          if (scale <= 1e-7)
167                  return(0.);
168 <        yval /= (double)cie_yf.ssum;
168 >        yval /= (double)c_y31.ssum;
169          scale = C_CMAXV / scale;
170          clr->ssum = 0;                  /* convert to our spacing */
171          wl0 = wlmin;
# Line 218 | Line 220 | c_ccvt(C_COLOR *clr, int fl)
220          if (fl & C_CSXY) {              /* cspec -> cxy */
221                  x = y = z = 0.;
222                  for (i = 0; i < C_CNSS; i++) {
223 <                        x += cie_xf.ssamp[i] * clr->ssamp[i];
224 <                        y += cie_yf.ssamp[i] * clr->ssamp[i];
225 <                        z += cie_zf.ssamp[i] * clr->ssamp[i];
223 >                        x += c_x31.ssamp[i] * clr->ssamp[i];
224 >                        y += c_y31.ssamp[i] * clr->ssamp[i];
225 >                        z += c_z31.ssamp[i] * clr->ssamp[i];
226                  }
227 <                x /= (double)cie_xf.ssum;
228 <                y /= (double)cie_yf.ssum;
229 <                z /= (double)cie_zf.ssum;
227 >                x /= (double)c_x31.ssum;
228 >                y /= (double)c_y31.ssum;
229 >                z /= (double)c_z31.ssum;
230                  z += x + y;
231                  clr->cx = x / z;
232                  clr->cy = y / z;
233                  clr->flags |= C_CSXY;
234 <        } else if (fl & C_CSSPEC) {     /* cxy -> cspec */
234 >        }
235 >        if (fl & C_CSSPEC) {            /* cxy -> cspec */
236                  x = clr->cx;
237                  y = clr->cy;
238                  z = 1. - x - y;
# Line 248 | Line 251 | c_ccvt(C_COLOR *clr, int fl)
251                  if (clr->flags & C_CSSPEC) {            /* from spectrum */
252                          y = 0.;
253                          for (i = 0; i < C_CNSS; i++)
254 <                                y += cie_yf.ssamp[i] * clr->ssamp[i];
254 >                                y += c_y31.ssamp[i] * clr->ssamp[i];
255                          clr->eff = C_CLPWM * y / clr->ssum;
256                  } else /* clr->flags & C_CSXY */ {      /* from (x,y) */
257 <                        clr->eff = clr->cx*cie_xf.eff + clr->cy*cie_yf.eff +
258 <                                        (1. - clr->cx - clr->cy)*cie_zf.eff;
257 >                        clr->eff = clr->cx*c_x31.eff + clr->cy*c_y31.eff +
258 >                                        (1. - clr->cx - clr->cy)*c_z31.eff;
259                  }
260                  clr->flags |= C_CSEFF;
261          }
# Line 331 | Line 334 | c_cmult(C_COLOR *cres, C_COLOR *c1, double y1, C_COLOR
334                          cres->ssum += cres->ssamp[i] = cmix[i] / cmax;
335                  cres->flags = C_CDSPEC|C_CSSPEC;
336  
337 <                c_ccvt(cres, C_CSEFF);                  /* nasty, but true */
338 <                yres = y1 * y2 * cie_yf.ssum * C_CLPWM /
337 >                c_ccvt(cres, C_CSEFF);                  /* below is correct */
338 >                yres = y1 * y2 * c_y31.ssum * C_CLPWM /
339                          (c1->eff*c1->ssum * c2->eff*c2->ssum) *
340                          cres->eff*( cres->ssum*(double)cmax +
341                                                  C_CNSS/2.0*(cmax-1) );

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines