--- ray/src/common/tonemap.c 2008/07/03 03:35:10 3.32 +++ ray/src/common/tonemap.c 2011/04/22 14:35:54 3.36 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: tonemap.c,v 3.32 2008/07/03 03:35:10 greg Exp $"; +static const char RCSid[] = "$Id: tonemap.c,v 3.36 2011/04/22 14:35:54 greg Exp $"; #endif /* * Tone mapping functions. @@ -12,6 +12,7 @@ static const char RCSid[] = "$Id: tonemap.c,v 3.32 200 #include "copyright.h" #include +#include #include #include "tmprivat.h" #include "tmerrmsg.h" @@ -133,18 +134,16 @@ MEM_PTR dat if (tms->inppri != tms->monpri && PRIMEQ(tms->inppri, tms->monpri)) tms->inppri = tms->monpri; /* no xform */ - comprgb2rgbWBmat(tms->cmat, tms->inppri, tms->monpri); + if (!comprgb2rgbWBmat(tms->cmat, tms->inppri, tms->monpri)) + returnErr(TM_E_ILLEGAL); } for (i = 0; i < 3; i++) for (j = 0; j < 3; j++) tms->cmat[i][j] *= tms->inpsf; /* set color divisors */ for (i = 0; i < 3; i++) - if (tms->clf[i] > .001) - tms->cdiv[i] = - 256.*pow(tms->clf[i], 1./tms->mongam); - else - tms->cdiv[i] = 1; + tms->cdiv[i] = 256.*pow(tms->clf[i] < .001 ? .001 : + tms->clf[i], 1./tms->mongam); /* notify packages */ for (i = tmNumPkgs; i--; ) if (tms->pd[i] != NULL && tmPkg[i]->NewSpace != NULL) @@ -179,9 +178,7 @@ double lum #endif return(TM_NOBRT); d = TM_BRTSCALE*log(lum); - if (d > 0.) - return((TMbright)(d+.5)); - return((TMbright)(d-.5)); + return((TMbright)(d + .5 - (d < 0.))); } @@ -419,27 +416,6 @@ double La } -static int -tmNewMap( /* allocate new tone-mapping array */ -TMstruct *tms -) -{ - if (tms->lumap != NULL && (tms->mbrmax - tms->mbrmin) != - (tms->hbrmax - tms->hbrmin)) { - free((MEM_PTR)tms->lumap); - tms->lumap = NULL; - } - tms->mbrmin = tms->hbrmin; - tms->mbrmax = tms->hbrmax; - if (tms->mbrmin > tms->mbrmax) - return 0; - if (tms->lumap == NULL) - tms->lumap = (unsigned short *)malloc(sizeof(unsigned short)* - (tms->mbrmax-tms->mbrmin+1)); - return(tms->lumap != NULL); -} - - int tmFixedMapping( /* compute fixed, linear tone-mapping */ TMstruct *tms, @@ -615,8 +591,6 @@ int len } - - TMstruct * tmDup( /* duplicate top tone mapping */ TMstruct *tms @@ -691,6 +665,27 @@ tmMkMesofact() /* build mesopic lookup factor table tmMesofact[i-BMESLOWER] = 256. * (tmLuminance(i) - LMESLOWER) / (LMESUPPER - LMESLOWER); +} + + +int +tmNewMap( /* allocate new tone-mapping array */ +TMstruct *tms +) +{ + if (tms->lumap != NULL && (tms->mbrmax - tms->mbrmin) != + (tms->hbrmax - tms->hbrmin)) { + free((MEM_PTR)tms->lumap); + tms->lumap = NULL; + } + tms->mbrmin = tms->hbrmin; + tms->mbrmax = tms->hbrmax; + if (tms->mbrmin > tms->mbrmax) + return 0; + if (tms->lumap == NULL) + tms->lumap = (unsigned short *)malloc(sizeof(unsigned short)* + (tms->mbrmax-tms->mbrmin+1)); + return(tms->lumap != NULL); }