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.2 by greg, Thu May 17 05:47:59 2012 UTC vs.
Revision 3.3 by greg, Thu May 17 17:10:23 2012 UTC

# Line 110 | Line 110 | c_fromSharpRGB(float cin[3], C_COLOR *cout)
110          return(xyz[1]);
111   }
112  
113 + /* assign arbitrary spectrum */
114 + double
115 + c_sset(C_COLOR *clr, double wlmin, double wlmax, const float spec[], int nwl)
116 + {
117 +        double  yval, scale;
118 +        float   va[C_CNSS];
119 +        int     i, pos, n, imax, wl;
120 +        double  wl0, wlstep;
121 +        double  boxpos, boxstep;
122 +                                        /* check arguments */
123 +        if ((nwl <= 1) | (spec == NULL) | (wlmin >= C_CMAXWL) |
124 +                        (wlmax <= C_CMINWL) | (wlmin >= wlmax))
125 +                return(0.);
126 +        wlstep = (wlmax - wlmin)/(nwl-1);
127 +        while (wlmin < C_CMINWL) {
128 +                wlmin += wlstep;
129 +                --nwl; ++spec;
130 +        }
131 +        while (wlmax > C_CMAXWL) {
132 +                wlmax -= wlstep;
133 +                --nwl;
134 +        }
135 +        imax = nwl;                     /* box filter if necessary */
136 +        boxpos = 0;
137 +        boxstep = 1;
138 +        if (wlstep < C_CWLI) {
139 +                imax = (wlmax - wlmin)/C_CWLI + 1e-7;
140 +                boxpos = (wlmin - C_CMINWL)/C_CWLI;
141 +                boxstep = wlstep/C_CWLI;
142 +                wlstep = C_CWLI;
143 +        }
144 +        scale = 0.;                     /* get values and maximum */
145 +        yval = 0.;
146 +        pos = 0;
147 +        for (i = 0; i < imax; i++) {
148 +                va[i] = 0.; n = 0;
149 +                while (boxpos < i+.5 && pos < nwl) {
150 +                        va[i] += spec[pos++];
151 +                        n++;
152 +                        boxpos += boxstep;
153 +                }
154 +                if (n > 1)
155 +                        va[i] /= (double)n;
156 +                if (va[i] > scale)
157 +                        scale = va[i];
158 +                else if (va[i] < -scale)
159 +                        scale = -va[i];
160 +                yval += va[i] * cie_yf.ssamp[i];
161 +        }
162 +        if (scale <= 1e-7)
163 +                return(0.);
164 +        yval /= (double)cie_yf.ssum;
165 +        scale = C_CMAXV / scale;
166 +        clr->ssum = 0;                  /* convert to our spacing */
167 +        wl0 = wlmin;
168 +        pos = 0;
169 +        for (i = 0, wl = C_CMINWL; i < C_CNSS; i++, wl += C_CWLI)
170 +                if ((wl < wlmin) | (wl > wlmax))
171 +                        clr->ssamp[i] = 0;
172 +                else {
173 +                        while (wl0 + wlstep < wl+1e-7) {
174 +                                wl0 += wlstep;
175 +                                pos++;
176 +                        }
177 +                        if ((wl+1e-7 >= wl0) & (wl-1e-7 <= wl0))
178 +                                clr->ssamp[i] = scale*va[pos] + .5;
179 +                        else            /* interpolate if necessary */
180 +                                clr->ssamp[i] = .5 + scale / wlstep *
181 +                                                ( va[pos]*(wl0+wlstep - wl) +
182 +                                                        va[pos+1]*(wl - wl0) );
183 +                        clr->ssum += clr->ssamp[i];
184 +                }
185 +        clr->flags = C_CDSPEC|C_CSSPEC;
186 +        return(yval);
187 + }
188 +
189   /* check if color is grey */
190   int
191   c_isgrey(C_COLOR *clr)
# Line 199 | Line 275 | c_cmix(C_COLOR *cres, double w1, C_COLOR *c1, double w
275                          cmix[i] = w1*c1->ssamp[i] + w2*c2->ssamp[i];
276                          if (cmix[i] > scale)
277                                  scale = cmix[i];
278 +                        else if (cmix[i] < -scale)
279 +                                scale = -cmix[i];
280                  }
281                  scale = C_CMAXV / scale;
282                  cres->ssum = 0;
# Line 238 | Line 316 | c_cmult(C_COLOR *cres, C_COLOR *c1, double y1, C_COLOR
316                          cmix[i] = c1->ssamp[i] * c2->ssamp[i];
317                          if (cmix[i] > cmax)
318                                  cmax = cmix[i];
319 +                        else if (cmix[i] < -cmax)
320 +                                cmax = -cmix[i];
321                  }
322                  cmax /= C_CMAXV;
323                  if (!cmax) {
# Line 250 | Line 330 | c_cmult(C_COLOR *cres, C_COLOR *c1, double y1, C_COLOR
330                  cres->flags = C_CDSPEC|C_CSSPEC;
331  
332                  c_ccvt(cres, C_CSEFF);                  /* nasty, but true */
333 <                yres = (y1 * y2 * cie_yf.ssum * C_CLPWM) /
333 >                yres = y1 * y2 * cie_yf.ssum * C_CLPWM /
334                          (c1->eff*c1->ssum * c2->eff*c2->ssum) *
335                          cres->eff*( cres->ssum*(double)cmax +
336                                                  C_CNSS/2.0*(cmax-1) );

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines