| 1 |
< |
/* Copyright (c) 1994 Regents of the University of California */ |
| 1 |
> |
/* Copyright (c) 1997 Regents of the University of California */ |
| 2 |
|
|
| 3 |
|
#ifndef lint |
| 4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
| 105 |
|
c_ccname = NULL; |
| 106 |
|
return(MG_OK); |
| 107 |
|
} |
| 108 |
+ |
if (!isname(av[1])) |
| 109 |
+ |
return(MG_EILL); |
| 110 |
|
lp = lu_find(&clr_tab, av[1]); /* lookup context */ |
| 111 |
|
if (lp == NULL) |
| 112 |
|
return(MG_EMEM); |
| 177 |
|
if (!isflt(av[1])) |
| 178 |
|
return(MG_ETYPE); |
| 179 |
|
wsum = atof(av[1]); |
| 178 |
– |
if (wsum < 0.) |
| 179 |
– |
return(MG_EILL); |
| 180 |
|
if ((lp = lu_find(&clr_tab, av[2])) == NULL) |
| 181 |
|
return(MG_EMEM); |
| 182 |
|
if (lp->data == NULL) |
| 186 |
|
if (!isflt(av[i])) |
| 187 |
|
return(MG_ETYPE); |
| 188 |
|
w = atof(av[i]); |
| 189 |
– |
if (w < 0.) |
| 190 |
– |
return(MG_EILL); |
| 189 |
|
if ((lp = lu_find(&clr_tab, av[i+1])) == NULL) |
| 190 |
|
return(MG_EMEM); |
| 191 |
|
if (lp->data == NULL) |
| 194 |
|
w, (C_COLOR *)lp->data); |
| 195 |
|
wsum += w; |
| 196 |
|
} |
| 197 |
+ |
if (wsum <= 0.) |
| 198 |
+ |
return(MG_EILL); |
| 199 |
|
c_ccolor->clock++; |
| 200 |
|
return(MG_OK); |
| 201 |
|
} |
| 221 |
|
c_cmname = NULL; |
| 222 |
|
return(MG_OK); |
| 223 |
|
} |
| 224 |
+ |
if (!isname(av[1])) |
| 225 |
+ |
return(MG_EILL); |
| 226 |
|
lp = lu_find(&mat_tab, av[1]); /* lookup context */ |
| 227 |
|
if (lp == NULL) |
| 228 |
|
return(MG_EMEM); |
| 261 |
|
*c_cmaterial = *(C_MATERIAL *)lp->data; |
| 262 |
|
c_cmaterial->clock = i + 1; |
| 263 |
|
return(MG_OK); |
| 264 |
+ |
case MG_E_IR: /* set index of refraction */ |
| 265 |
+ |
if (ac != 3) |
| 266 |
+ |
return(MG_EARGC); |
| 267 |
+ |
if (!isflt(av[1]) | !isflt(av[2])) |
| 268 |
+ |
return(MG_ETYPE); |
| 269 |
+ |
c_cmaterial->nr = atof(av[1]); |
| 270 |
+ |
c_cmaterial->ni = atof(av[2]); |
| 271 |
+ |
if (c_cmaterial->nr <= FTINY) |
| 272 |
+ |
return(MG_EILL); |
| 273 |
+ |
c_cmaterial->clock++; |
| 274 |
+ |
return(MG_OK); |
| 275 |
|
case MG_E_RD: /* set diffuse reflectance */ |
| 276 |
|
if (ac != 2) |
| 277 |
|
return(MG_EARGC); |
| 368 |
|
c_cvname = NULL; |
| 369 |
|
return(MG_OK); |
| 370 |
|
} |
| 371 |
+ |
if (!isname(av[1])) |
| 372 |
+ |
return(MG_EILL); |
| 373 |
|
lp = lu_find(&vtx_tab, av[1]); /* lookup context */ |
| 374 |
|
if (lp == NULL) |
| 375 |
|
return(MG_EMEM); |
| 569 |
|
int n, imax; |
| 570 |
|
int wl; |
| 571 |
|
double wl0, wlstep; |
| 572 |
+ |
double boxpos, boxstep; |
| 573 |
|
/* check bounds */ |
| 574 |
|
if (wlmax <= C_CMINWL | wlmax <= wlmin | wlmin >= C_CMAXWL) |
| 575 |
|
return(MG_EILL); |
| 582 |
|
wlmax -= wlstep; |
| 583 |
|
ac--; |
| 584 |
|
} |
| 569 |
– |
if (ac < 2) |
| 570 |
– |
return(MG_EILL); |
| 585 |
|
imax = ac; /* box filter if necessary */ |
| 586 |
+ |
boxpos = 0; |
| 587 |
+ |
boxstep = 1; |
| 588 |
|
if (wlstep < C_CWLI) { |
| 589 |
+ |
imax = (wlmax - wlmin)/C_CWLI + (1-FTINY); |
| 590 |
+ |
boxpos = (wlmin - C_CMINWL)/C_CWLI; |
| 591 |
+ |
boxstep = wlstep/C_CWLI; |
| 592 |
|
wlstep = C_CWLI; |
| 574 |
– |
imax = (wlmax - wlmin)/wlstep; |
| 593 |
|
} |
| 594 |
|
scale = 0.; /* get values and maximum */ |
| 595 |
|
pos = 0; |
| 596 |
|
for (i = 0; i < imax; i++) { |
| 597 |
|
va[i] = 0.; n = 0; |
| 598 |
< |
while (pos < (i+.5)*ac/imax) { |
| 598 |
> |
while (boxpos < i+.5 && pos < ac) { |
| 599 |
|
if (!isflt(av[pos])) |
| 600 |
|
return(MG_ETYPE); |
| 601 |
|
va[i] += atof(av[pos++]); |
| 602 |
|
n++; |
| 603 |
+ |
boxpos += boxstep; |
| 604 |
|
} |
| 605 |
|
if (n > 1) |
| 606 |
|
va[i] /= (double)n; |
| 588 |
– |
if (va[i] < 0.) |
| 589 |
– |
return(MG_EILL); |
| 607 |
|
if (va[i] > scale) |
| 608 |
|
scale = va[i]; |
| 609 |
+ |
else if (va[i] < -scale) |
| 610 |
+ |
scale = -va[i]; |
| 611 |
|
} |
| 612 |
< |
if (scale == 0.) |
| 612 |
> |
if (scale <= FTINY) |
| 613 |
|
return(MG_EILL); |
| 614 |
|
scale = C_CMAXV / scale; |
| 615 |
|
clr->ssum = 0; /* convert to our spacing */ |
| 665 |
|
} else { /* CIE xy mixing */ |
| 666 |
|
c_ccvt(c1, C_CSXY); |
| 667 |
|
c_ccvt(c2, C_CSXY); |
| 668 |
< |
scale = 1. / (w1/c1->cy + w2/c2->cy); |
| 668 |
> |
scale = w1/c1->cy + w2/c2->cy; |
| 669 |
> |
if (scale == 0.) |
| 670 |
> |
return; |
| 671 |
> |
scale = 1. / scale; |
| 672 |
|
cres->cx = (c1->cx*w1/c1->cy + c2->cx*w2/c2->cy) * scale; |
| 673 |
|
cres->cy = (w1 + w2) * scale; |
| 674 |
|
cres->flags = C_CDXY|C_CSXY; |