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.8 by greg, Sun Apr 5 01:32:01 2015 UTC vs.
Revision 3.9 by greg, Sat Jan 23 18:58:35 2016 UTC

# Line 6 | Line 6 | static const char RCSid[] = "$Id$";
6   */
7  
8   #include <stdio.h>
9 + #include <stdlib.h>
10   #include <math.h>
11   #include "ccolor.h"
12  
13 + #undef frand
14 + #define frand() (rand()*(1./(RAND_MAX+.5)))
15 +
16                                          /* Sharp primary matrix */
17   float   XYZtoSharp[3][3] = {
18          { 1.2694, -0.0988, -0.1706},
# Line 24 | Line 28 | float  XYZfromSharp[3][3] = {
28  
29   const C_COLOR   c_dfcolor = C_DEFCOLOR;
30  
31 + const C_CHROMA  c_dfchroma = 49750;     /* c_encodeChroma(&c_dfcolor) */
32 +
33                                  /* CIE 1931 Standard Observer curves */
34   const C_COLOR   c_x31 = { 1, NULL, C_CDSPEC|C_CSSPEC|C_CSXY|C_CSEFF,
35                          {14,42,143,435,1344,2839,3483,3362,2908,1954,956,
# Line 183 | Line 189 | c_sset(C_COLOR *clr, double wlmin, double wlmax, const
189                                  pos++;
190                          }
191                          if ((wl+1e-7 >= wl0) & (wl-1e-7 <= wl0))
192 <                                clr->ssamp[i] = scale*va[pos] + .5;
192 >                                clr->ssamp[i] = scale*va[pos] + frand();
193                          else            /* interpolate if necessary */
194 <                                clr->ssamp[i] = .5 + scale / wlstep *
194 >                                clr->ssamp[i] = frand() + scale / wlstep *
195                                                  ( va[pos]*(wl0+wlstep - wl) +
196                                                          va[pos+1]*(wl - wl0) );
197                          clr->ssum += clr->ssamp[i];
# Line 243 | Line 249 | c_ccvt(C_COLOR *clr, int fl)
249                  clr->ssum = 0;
250                  for (i = 0; i < C_CNSS; i++) {
251                          clr->ssamp[i] = x*cie_xp.ssamp[i] + y*cie_yp.ssamp[i]
252 <                                        + z*cie_zp.ssamp[i] + .5;
252 >                                        + z*cie_zp.ssamp[i] + frand();
253                          if (clr->ssamp[i] < 0)          /* out of gamut! */
254                                  clr->ssamp[i] = 0;
255                          else
# Line 290 | Line 296 | c_cmix(C_COLOR *cres, double w1, C_COLOR *c1, double w
296                  scale = C_CMAXV / scale;
297                  cres->ssum = 0;
298                  for (i = 0; i < C_CNSS; i++)
299 <                        cres->ssum += cres->ssamp[i] = scale*cmix[i] + .5;
299 >                        cres->ssum += cres->ssamp[i] = scale*cmix[i] + frand();
300                  cres->flags = C_CDSPEC|C_CSSPEC;
301          } else {                                        /* CIE xy mixing */
302                  c_ccvt(c1, C_CSXY);
# Line 380 | Line 386 | c_bbtemp(C_COLOR *clr, double tk)
386          clr->ssum = 0;
387          for (i = 0; i < C_CNSS; i++) {
388                  wl = (C_CMINWL + i*C_CWLI)*1e-9;
389 <                clr->ssum += clr->ssamp[i] = sf*bbsp(wl,tk) + .5;
389 >                clr->ssum += clr->ssamp[i] = sf*bbsp(wl,tk) + frand();
390          }
391          clr->flags = C_CDSPEC|C_CSSPEC;
392          return(1);
# Line 402 | Line 408 | c_encodeChroma(C_COLOR *clr)
408  
409          c_ccvt(clr, C_CSXY);
410          df = UV_NORMF/(-2.*clr->cx + 12.*clr->cy + 3.);
411 <        ub = 4.*clr->cx * df;
412 <        if (ub < 0) ub = 0;
413 <        else if (ub > 0xff) ub = 0xff;
414 <        vb = 9.*clr->cy * df;
415 <        if (vb < 0) vb = 0;
416 <        else if (vb > 0xff) vb = 0xff;
411 >        ub = 4.*clr->cx*df + frand();
412 >        ub *= (ub > 0);
413 >        if (ub > 0xff) ub = 0xff;
414 >        vb = 9.*clr->cy*df + frand();
415 >        vb *= (vb > 0);
416 >        if (vb > 0xff) vb = 0xff;
417  
418          return(vb<<8 | ub);
419   }
# Line 416 | Line 422 | c_encodeChroma(C_COLOR *clr)
422   void
423   c_decodeChroma(C_COLOR *cres, C_CHROMA ccode)
424   {
425 <        double  up = ((ccode & 0xff) + .5)*(1./UV_NORMF);
426 <        double  vp = ((ccode>>8 & 0xff) + .5)*(1./UV_NORMF);
425 >        double  up = (ccode & 0xff)*(1./UV_NORMF);
426 >        double  vp = (ccode>>8 & 0xff)*(1./UV_NORMF);
427          double  df = 1./(6.*up - 16.*vp + 12.);
428  
429          cres->cx = 9.*up * df;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines