--- ray/src/common/tonemap.c 2006/05/10 15:21:58 3.23 +++ ray/src/common/tonemap.c 2006/08/09 16:26:54 3.28 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: tonemap.c,v 3.23 2006/05/10 15:21:58 greg Exp $"; +static const char RCSid[] = "$Id: tonemap.c,v 3.28 2006/08/09 16:26:54 greg Exp $"; #endif /* * Tone mapping functions. @@ -23,7 +23,7 @@ struct tmPackage *tmPkg[TM_MAXPKG]; int tmNumPkgs = 0; /* number of registered packages */ /* luminance->brightness lookup */ -static TMbright *tmFloat2BrtLUT; +static TMbright *tmFloat2BrtLUT = NULL; #define tmCvLumLUfp(pf) tmFloat2BrtLUT[*(int32 *)(pf) >> 15] @@ -53,7 +53,7 @@ double gamval tmnew->clf[GRN] = rgb2xyzmat[1][1]; tmnew->clf[BLU] = rgb2xyzmat[1][2]; } else { - comprgb2xyzWBmat(cmat, tmnew->monpri=monpri); + comprgb2xyzmat(cmat, tmnew->monpri=monpri); tmnew->clf[RED] = cmat[1][0]; tmnew->clf[GRN] = cmat[1][1]; tmnew->clf[BLU] = cmat[1][2]; @@ -116,7 +116,7 @@ MEM_PTR dat tms->clf[CIEX] = tms->clf[CIEZ] = 0.; tms->clf[CIEY] = 1.; } else { - comprgb2xyzWBmat(tms->cmat, tms->monpri); + comprgb2xyzmat(tms->cmat, tms->monpri); tms->clf[RED] = tms->cmat[1][0]; tms->clf[GRN] = tms->cmat[1][1]; tms->clf[BLU] = tms->cmat[1][2]; @@ -232,13 +232,14 @@ int len ) { static const char funcName[] = "tmCvGrays"; - double d; int i; if (tms == NULL) returnErr(TM_E_TMINVAL); if ((ls == NULL) | (scan == NULL) | (len < 0)) returnErr(TM_E_ILLEGAL); + if (tmFloat2BrtLUT == NULL) /* initialize */ + tmCvLums(NULL, NULL, 0); for (i = len; i--; ) { float lum = tms->inpsf * scan[i]; if (lum <= TM_NOLUM) @@ -260,7 +261,6 @@ int len ) { static const char funcName[] = "tmCvColors"; - static COLOR csmall = {.5*MINLUM, .5*MINLUM, .5*MINLUM}; static BYTE gamtab[1024]; static double curgam = .0; COLOR cmon; @@ -271,7 +271,8 @@ int len returnErr(TM_E_TMINVAL); if ((ls == NULL) | (scan == NULL) | (len < 0)) returnErr(TM_E_ILLEGAL); - tmCvLums(NULL, NULL, 0); /* initialize */ + if (tmFloat2BrtLUT == NULL) /* initialize */ + tmCvLums(NULL, NULL, 0); if (cs != TM_NOCHROM && fabs(tms->mongam - curgam) > .02) { curgam = tms->mongam; /* (re)build table */ for (i = 1024; i--; ) @@ -298,17 +299,18 @@ int len lum = tms->clf[RED]*cmon[RED] + tms->clf[GRN]*cmon[GRN] + tms->clf[BLU]*cmon[BLU] ; - if (lum <= TM_NOLUM) /* convert brightness */ + if (lum <= TM_NOLUM) { /* convert brightness */ + lum = cmon[RED] = cmon[GRN] = cmon[BLU] = TM_NOLUM; ls[i] = TM_NOBRT; - else + } else ls[i] = tmCvLumLUfp(&lum); if (cs == TM_NOCHROM) /* no color? */ continue; if (tms->flags & TM_F_MESOPIC && lum < LMESUPPER) { slum = scotlum(cmon); /* mesopic adj. */ - if (lum < LMESLOWER) + if (lum < LMESLOWER) { cmon[RED] = cmon[GRN] = cmon[BLU] = slum; - else { + } else { d = (lum - LMESLOWER)/(LMESUPPER - LMESLOWER); if (tms->flags & TM_F_BW) cmon[RED] = cmon[GRN] = @@ -456,10 +458,12 @@ double gamval if (gamval < MINGAM) gamval = tms->mongam; d = log(expmult/tms->inpsf); - for (i = tms->mbrmax-tms->mbrmin+1; i--; ) - tms->lumap[i] = 256. * exp( + for (i = tms->mbrmax-tms->mbrmin+1; i--; ) { + double val = 256. * exp( ( d + (tms->mbrmin+i)*(1./TM_BRTSCALE) ) - / gamval ); + / gamval); + tms->lumap[i] = val >= (double)0xffff ? 0xffff : (int)val; + } returnOK; }