569 |
|
return 0; /* should be internal error */ |
570 |
|
/* get BSDF value */ |
571 |
|
yval = SDlookupTre(sdt->stc[tt_Y], gridPos, hc); |
572 |
+ |
if (coef == NULL) /* just getting hypercube? */ |
573 |
+ |
return 1; |
574 |
|
if (sdt->stc[tt_u] == NULL || sdt->stc[tt_v] == NULL) { |
575 |
< |
if (coef != NULL) *coef = yval; |
575 |
> |
*coef = yval; |
576 |
|
return 1; /* no color */ |
577 |
|
} |
576 |
– |
if (coef == NULL) /* just getting hypercube? */ |
577 |
– |
return 1; |
578 |
|
/* else decode color */ |
579 |
|
SDyuv2rgb(yval, SDlookupTre(sdt->stc[tt_u], gridPos, NULL), |
580 |
|
SDlookupTre(sdt->stc[tt_v], gridPos, NULL), coef); |
789 |
|
for (i = sdt->stc[tt_Y]->ndim - 2; i--; ) |
790 |
|
inCoord[i] = floor(inCoord[i]/quantum)*quantum + .5*quantum; |
791 |
|
cdlast = NULL; /* check for direction in cache list */ |
792 |
+ |
/* PLACE MUTEX LOCK HERE FOR THREAD-SAFE */ |
793 |
|
for (cd = (SDTreCDst *)sdc->cdList; cd != NULL; |
794 |
|
cdlast = cd, cd = cd->next) { |
795 |
|
if (cd->sidef != mode) |
808 |
|
cd->next = (SDTreCDst *)sdc->cdList; |
809 |
|
sdc->cdList = (SDCDst *)cd; |
810 |
|
} |
811 |
+ |
/* END MUTEX LOCK */ |
812 |
|
return (SDCDst *)cd; /* ready to go */ |
813 |
|
} |
814 |
|
|
926 |
|
} |
927 |
|
|
928 |
|
/* Advance pointer past matching token (or any token if c==0) */ |
929 |
< |
#define eat_token(spp,c) (next_token(spp)==(c) ^ !(c) ? *(*(spp))++ : 0) |
929 |
> |
#define eat_token(spp,c) ((next_token(spp)==(c)) ^ !(c) ? *(*(spp))++ : 0) |
930 |
|
|
931 |
|
/* Count words from this point in string to '}' */ |
932 |
|
static int |
1176 |
|
static double |
1177 |
|
subtract_min_Y(SDNode *st) |
1178 |
|
{ |
1179 |
< |
float vmin; |
1179 |
> |
const float vmaxmin = 1.5/M_PI; |
1180 |
> |
float vmin; |
1181 |
|
/* be sure to skip unused portion */ |
1182 |
|
if (st->ndim == 3) { |
1183 |
|
int n; |
1184 |
< |
vmin = 1./M_PI; |
1184 |
> |
vmin = vmaxmin; |
1185 |
|
if (st->log2GR < 0) { |
1186 |
|
for (n = 0; n < 8; n += 2) { |
1187 |
|
float v = SDgetTreMin(st->u.t[n]); |
1197 |
|
} else /* anisotropic covers entire tree */ |
1198 |
|
vmin = SDgetTreMin(st); |
1199 |
|
|
1200 |
< |
if (vmin <= FTINY) |
1201 |
< |
return .0; |
1200 |
> |
if ((vmin >= vmaxmin) | (vmin <= .01/M_PI)) |
1201 |
> |
return .0; /* not worth bothering about */ |
1202 |
|
|
1203 |
|
SDsubtractTreVal(st, vmin); |
1204 |
|
|
1317 |
|
my_min.new_stu = my_min.new_stv = NULL; |
1318 |
|
/* get minimum RGB value */ |
1319 |
|
SDtraverseTre(stc[tt_Y], NULL, 0, get_min_RGB, &my_min); |
1320 |
< |
ymin = tt_RGB_coef[0]*my_min.rgb[0] + |
1321 |
< |
tt_RGB_coef[1]*my_min.rgb[1] + |
1322 |
< |
tt_RGB_coef[2]*my_min.rgb[2]; |
1323 |
< |
if (ymin <= 1e-5) { |
1324 |
< |
*cs = c_dfcolor; |
1322 |
< |
return .0; /* not worth bothering about */ |
1323 |
< |
} |
1324 |
< |
/* adjust u' & v' values */ |
1320 |
> |
/* convert to C_COLOR */ |
1321 |
> |
ymin = c_fromSharpRGB(my_min.rgb, cs); |
1322 |
> |
if ((ymin >= .5*FHUGE) | (ymin <= .01/M_PI)) |
1323 |
> |
return .0; /* close to zero or no tree */ |
1324 |
> |
/* adjust u' & v' trees */ |
1325 |
|
SDtraverseTre(stc[tt_u], NULL, 0, adjust_utree, &my_min); |
1326 |
|
SDtraverseTre(stc[tt_v], NULL, 0, adjust_vtree, &my_min); |
1327 |
|
SDfreeTre(stc[tt_u]); SDfreeTre(stc[tt_v]); |
1328 |
|
stc[tt_u] = SDsimplifyTre(my_min.new_stu); |
1329 |
|
stc[tt_v] = SDsimplifyTre(my_min.new_stv); |
1330 |
< |
/* finally, subtract Y value */ |
1330 |
> |
/* subtract Y & return hemispherical */ |
1331 |
|
SDsubtractTreVal(stc[tt_Y], ymin); |
1332 |
< |
/* return color and Y */ |
1333 |
< |
c_fromSharpRGB(my_min.rgb, cs); |
1334 |
< |
return M_PI*ymin; |
1332 |
> |
|
1333 |
> |
return M_PI * ymin; |
1334 |
|
} |
1335 |
|
|
1336 |
|
/* Extract and separate diffuse portion of BSDF */ |
1357 |
|
memcpy(df->comp[0].cspec, tt_RGB_prim, sizeof(tt_RGB_prim)); |
1358 |
|
dv->cieY = subtract_min_RGB(&dv->spec, sdt->stc); |
1359 |
|
} else { |
1360 |
< |
df->comp[0].cspec[0] = c_dfcolor; |
1360 |
> |
df->comp[0].cspec[0] = dv->spec = c_dfcolor; |
1361 |
|
dv->cieY = subtract_min_Y(sdt->stc[tt_Y]); |
1362 |
|
} |
1363 |
|
df->maxHemi -= dv->cieY; /* adjust maximum hemispherical */ |
1364 |
< |
/* make sure everything is set */ |
1365 |
< |
c_ccvt(&dv->spec, C_CSXY+C_CSSPEC); |
1364 |
> |
|
1365 |
> |
c_ccvt(&dv->spec, C_CSXY); /* make sure (x,y) is set */ |
1366 |
|
} |
1367 |
|
|
1368 |
|
/* Load a variable-resolution BSDF tree from an open XML file */ |
1422 |
|
} |
1423 |
|
|
1424 |
|
/* Variable resolution BSDF methods */ |
1425 |
< |
SDFunc SDhandleTre = { |
1425 |
> |
const SDFunc SDhandleTre = { |
1426 |
|
&SDgetTreBSDF, |
1427 |
|
&SDqueryTreProjSA, |
1428 |
|
&SDgetTreCDist, |