42 |
|
static C_COLOR cie_zf = C_CIEZ; |
43 |
|
|
44 |
|
static int setspectrum(); |
45 |
+ |
static int setbbtemp(); |
46 |
|
static void mixcolors(); |
47 |
|
|
48 |
|
|
106 |
|
case MG_E_CXY: /* assign CIE XY value */ |
107 |
|
if (ac != 3) |
108 |
|
return(MG_EARGC); |
109 |
< |
if (!isflt(av[1]) || !isflt(av[2])) |
109 |
> |
if (!isflt(av[1]) | !isflt(av[2])) |
110 |
|
return(MG_ETYPE); |
111 |
|
c_ccolor->cx = atof(av[1]); |
112 |
|
c_ccolor->cy = atof(av[2]); |
119 |
|
case MG_E_CSPEC: /* assign spectral values */ |
120 |
|
if (ac < 5) |
121 |
|
return(MG_EARGC); |
122 |
< |
if (!isflt(av[1]) || !isflt(av[2])) |
122 |
> |
if (!isflt(av[1]) | !isflt(av[2])) |
123 |
|
return(MG_ETYPE); |
124 |
|
return(setspectrum(c_ccolor, atof(av[1]), atof(av[2]), |
125 |
|
ac-3, av+3)); |
126 |
+ |
case MG_E_CCT: /* assign black body spectrum */ |
127 |
+ |
if (ac != 2) |
128 |
+ |
return(MG_EARGC); |
129 |
+ |
if (!isflt(av[1])) |
130 |
+ |
return(MG_ETYPE); |
131 |
+ |
return(setbbtemp(c_ccolor, atof(av[1]))); |
132 |
|
case MG_E_CMIX: /* mix colors */ |
133 |
|
if (ac < 5 || (ac-1)%2) |
134 |
|
return(MG_EARGC); |
255 |
|
case MG_E_RS: /* set specular reflectance */ |
256 |
|
if (ac != 3) |
257 |
|
return(MG_EARGC); |
258 |
< |
if (!isflt(av[1]) || !isflt(av[2])) |
258 |
> |
if (!isflt(av[1]) | !isflt(av[2])) |
259 |
|
return(MG_ETYPE); |
260 |
|
c_cmaterial->rs = atof(av[1]); |
261 |
|
c_cmaterial->rs_a = atof(av[2]); |
268 |
|
case MG_E_TS: /* set specular transmittance */ |
269 |
|
if (ac != 3) |
270 |
|
return(MG_EARGC); |
271 |
< |
if (!isflt(av[1]) || !isflt(av[2])) |
271 |
> |
if (!isflt(av[1]) | !isflt(av[2])) |
272 |
|
return(MG_ETYPE); |
273 |
|
c_cmaterial->ts = atof(av[1]); |
274 |
|
c_cmaterial->ts_a = atof(av[2]); |
355 |
|
case MG_E_POINT: /* set point */ |
356 |
|
if (ac != 4) |
357 |
|
return(MG_EARGC); |
358 |
< |
if (!isflt(av[1]) || !isflt(av[2]) || !isflt(av[3])) |
358 |
> |
if (!isflt(av[1]) | !isflt(av[2]) | !isflt(av[3])) |
359 |
|
return(MG_ETYPE); |
360 |
|
c_cvertex->p[0] = atof(av[1]); |
361 |
|
c_cvertex->p[1] = atof(av[2]); |
365 |
|
case MG_E_NORMAL: /* set normal */ |
366 |
|
if (ac != 4) |
367 |
|
return(MG_EARGC); |
368 |
< |
if (!isflt(av[1]) || !isflt(av[2]) || !isflt(av[3])) |
368 |
> |
if (!isflt(av[1]) | !isflt(av[2]) | !isflt(av[3])) |
369 |
|
return(MG_ETYPE); |
370 |
|
c_cvertex->n[0] = atof(av[1]); |
371 |
|
c_cvertex->n[1] = atof(av[2]); |
481 |
|
clr->ssum += clr->ssamp[i] = |
482 |
|
x * cie_xf.ssamp[i] + |
483 |
|
y * cie_yf.ssamp[i] + |
484 |
< |
z * cie_zf.ssamp[i] ; |
484 |
> |
z * cie_zf.ssamp[i] + .5; |
485 |
|
clr->flags |= C_CSSPEC; |
486 |
|
} |
487 |
|
if (fl & C_CSEFF) { /* compute efficacy */ |
563 |
|
pos++; |
564 |
|
} |
565 |
|
if (wl+FTINY >= wl0 & wl-FTINY <= wl0) |
566 |
< |
clr->ssamp[i] = scale*va[pos]; |
566 |
> |
clr->ssamp[i] = scale*va[pos] + .5; |
567 |
|
else /* interpolate if necessary */ |
568 |
< |
clr->ssamp[i] = scale / wlstep * |
568 |
> |
clr->ssamp[i] = .5 + scale / wlstep * |
569 |
|
( va[pos]*(wl0+wlstep - wl) + |
570 |
|
va[pos+1]*(wl - wl0) ); |
571 |
|
clr->ssum += clr->ssamp[i]; |
610 |
|
cres->flags = C_CDXY|C_CSXY; |
611 |
|
} |
612 |
|
} |
613 |
+ |
|
614 |
+ |
|
615 |
+ |
#define C1 3.741832e-16 /* W-m^2 */ |
616 |
+ |
#define C2 1.4388e-2 /* m-K */ |
617 |
+ |
|
618 |
+ |
#define bbsp(l,t) (C1/((l)*(l)*(l)*(l)*(l)*(exp(C2/((t)*(l)))-1.))) |
619 |
+ |
#define bblm(t) (C2/5./(t)) |
620 |
+ |
|
621 |
+ |
static int |
622 |
+ |
setbbtemp(clr, tk) /* set black body spectrum */ |
623 |
+ |
register C_COLOR *clr; |
624 |
+ |
double tk; |
625 |
+ |
{ |
626 |
+ |
double sf, wl; |
627 |
+ |
register int i; |
628 |
+ |
|
629 |
+ |
if (tk < 1000) |
630 |
+ |
return(MG_EILL); |
631 |
+ |
wl = bblm(tk); /* scalefactor based on peak */ |
632 |
+ |
if (wl < C_CMINWL*1e-9) |
633 |
+ |
wl = C_CMINWL*1e-9; |
634 |
+ |
else if (wl > C_CMAXWL*1e-9) |
635 |
+ |
wl = C_CMAXWL*1e-9; |
636 |
+ |
sf = C_CMAXV/bbsp(wl,tk); |
637 |
+ |
clr->ssum = 0; |
638 |
+ |
for (i = 0; i < C_CNSS; i++) { |
639 |
+ |
wl = (C_CMINWL + i*C_CWLI)*1e-9; |
640 |
+ |
clr->ssum += clr->ssamp[i] = sf*bbsp(wl,tk) + .5; |
641 |
+ |
} |
642 |
+ |
clr->flags = C_CDSPEC|C_CSSPEC; |
643 |
+ |
clr->clock++; |
644 |
+ |
return(MG_OK); |
645 |
+ |
} |
646 |
+ |
|
647 |
+ |
#undef C1 |
648 |
+ |
#undef C2 |
649 |
+ |
#undef bbsp |
650 |
+ |
#undef bblm |