--- ray/src/common/tonemap.c 2021/01/06 19:25:00 3.38 +++ ray/src/common/tonemap.c 2021/01/07 02:13:49 3.40 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: tonemap.c,v 3.38 2021/01/06 19:25:00 greg Exp $"; +static const char RCSid[] = "$Id: tonemap.c,v 3.40 2021/01/07 02:13:49 greg Exp $"; #endif /* * Tone mapping functions. @@ -67,7 +67,7 @@ double gamval tmnew->mongam = gamval; /* set color divisors */ for (i = 0; i < 3; i++) - tmnew->cdiv[i] = 256.*pow(tmnew->clf[i], 1./tmnew->mongam); + tmnew->cdiv[i] = TM_BRES*pow(tmnew->clf[i], 1./tmnew->mongam); /* set input transform */ tmnew->inppri = tmnew->monpri; @@ -143,7 +143,7 @@ MEM_PTR dat tms->cmat[i][j] *= tms->inpsf; /* set color divisors */ for (i = 0; i < 3; i++) - tms->cdiv[i] = 256.*pow(tms->clf[i] < .001 ? .001 : + tms->cdiv[i] = TM_BRES*pow(tms->clf[i] < .001 ? .001 : tms->clf[i], 1./tms->mongam); /* notify packages */ for (i = tmNumPkgs; i--; ) @@ -379,7 +379,7 @@ int wt if (newhist == NULL) returnErr(TM_E_NOMEM); if (oldlen) { /* copy and free old */ - memcpy((MEM_PTR)newhist+(oldorig-horig), + memcpy((MEM_PTR)(newhist+(oldorig-horig)), (MEM_PTR)tms->histo, oldlen*sizeof(HIST_TYP)); free((MEM_PTR)tms->histo); } @@ -436,7 +436,7 @@ double gamval gamval = tms->mongam; d = log(expmult/tms->inpsf); for (i = tms->mbrmax-tms->mbrmin+1; i--; ) { - double val = 256. * exp( + double val = TM_BRES * exp( ( d + (tms->mbrmin+i)*(1./TM_BRTSCALE) ) / gamval); tms->lumap[i] = val >= (double)0xffff ? 0xffff : (int)val; @@ -457,9 +457,8 @@ double Ldmax HIST_TYP *histo; float *cumf; int brt0, histlen; - HIST_TYP threshold, ceiling, trimmings; + HIST_TYP threshold, ceiling, trimmings, histot; double logLddyn, Ldmin, Ldavg, Lwavg, Tr, Lw, Ld; - HIST_TYP histot; double sum; double d; int i, j; @@ -540,7 +539,7 @@ double Ldmax d -= (double)j; Ld = Ldmin*exp(logLddyn*((1.-d)*cumf[j]+d*cumf[j+1])); d = (Ld - Ldmin)/(Ldmax - Ldmin); - tms->lumap[i] = 256.*pow(d, 1./gamval); + tms->lumap[i] = TM_BRES*pow(d, 1./gamval); } free((MEM_PTR)histo); /* clean up and return */ free((MEM_PTR)cumf);