--- ray/src/common/tonemap.c 2005/01/07 20:33:02 3.16 +++ ray/src/common/tonemap.c 2005/11/15 06:53:00 3.19 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: tonemap.c,v 3.16 2005/01/07 20:33:02 greg Exp $"; +static const char RCSid[] = "$Id: tonemap.c,v 3.19 2005/11/15 06:53:00 greg Exp $"; #endif /* * Tone mapping functions. @@ -22,10 +22,7 @@ static const char RCSid[] = "$Id: tonemap.c,v 3.16 200 struct tmPackage *tmPkg[TM_MAXPKG]; int tmNumPkgs = 0; /* number of registered packages */ -int tmLastError; /* last error incurred by library */ -char *tmLastFunction; /* error-generating function name */ - TMstruct * tmInit( /* initialize new tone mapping */ int flags, @@ -71,6 +68,7 @@ double gamval tmnew->inpsf = WHTEFFICACY; tmnew->cmat[0][1] = tmnew->cmat[0][2] = tmnew->cmat[1][0] = tmnew->cmat[1][2] = tmnew->cmat[2][0] = tmnew->cmat[2][1] = 0.; + tmnew->inpdat = NULL; tmnew->hbrmin = 10; tmnew->hbrmax = -10; tmnew->histo = NULL; tmnew->mbrmin = 10; tmnew->mbrmax = -10; @@ -78,6 +76,8 @@ double gamval /* zero private data */ for (i = TM_MAXPKG; i--; ) tmnew->pd[i] = NULL; + tmnew->lastError = TM_E_OK; + tmnew->lastFunc = "NoErr"; /* return new TMstruct */ return(tmnew); } @@ -87,10 +87,11 @@ int tmSetSpace( /* set input color space for conversions */ TMstruct *tms, RGBPRIMP pri, -double sf +double sf, +MEM_PTR dat ) { - static char funcName[] = "tmSetSpace"; + static const char funcName[] = "tmSetSpace"; int i, j; /* error check */ if (tms == NULL) @@ -98,10 +99,11 @@ double sf if (sf <= 1e-12) returnErr(TM_E_ILLEGAL); /* check if no change */ - if (pri == tms->inppri && FEQ(sf, tms->inpsf)) + if (pri == tms->inppri && FEQ(sf, tms->inpsf) && dat == tms->inpdat) returnOK; tms->inppri = pri; /* let's set it */ tms->inpsf = sf; + tms->inpdat = dat; if (tms->flags & TM_F_BW) { /* color doesn't matter */ tms->monpri = tms->inppri; /* eliminate xform */ @@ -167,7 +169,7 @@ COLOR *scan, int len ) { - static char funcName[] = "tmCvColors"; + static const char funcName[] = "tmCvColors"; static COLOR csmall = {.5*MINLUM, .5*MINLUM, .5*MINLUM}; COLOR cmon; double lum, slum; @@ -237,6 +239,22 @@ int len } +TMbright +tmCvLuminance( /* convert a single luminance */ +double lum +) +{ + double d; + + if (lum <= TM_NOLUM) + return(TM_NOBRT); + d = TM_BRTSCALE*log(lum); + if (d > 0.) + return((TMbright)(d+.5)); + return((TMbright)(d-.5)); +} + + int tmCvGrays( /* convert float gray values */ TMstruct *tms, @@ -245,7 +263,7 @@ float *scan, int len ) { - static char funcName[] = "tmCvGrays"; + static const char funcName[] = "tmCvGrays"; double d; int i; @@ -272,7 +290,7 @@ int len, int wt ) { - static char funcName[] = "tmAddHisto"; + static const char funcName[] = "tmAddHisto"; int oldorig=0, oldlen, horig, hlen; int i, j; @@ -375,7 +393,7 @@ double expmult, double gamval ) { - static char funcName[] = "tmFixedMapping"; + static const char funcName[] = "tmFixedMapping"; double d; int i; @@ -402,7 +420,7 @@ double Lddyn, double Ldmax ) { - static char funcName[] = "tmComputeMapping"; + static const char funcName[] = "tmComputeMapping"; int *histo; float *cumf; int brt0, histlen, threshold, ceiling, trimmings; @@ -510,7 +528,7 @@ BYTE *cs, int len ) { - static char funcName[] = "tmMapPixels"; + static const char funcName[] = "tmMapPixels"; int32 li, pv; if (tms == NULL || tms->lumap == NULL) @@ -622,15 +640,17 @@ tmMkMesofact() /* build mesopic lookup factor table int tmErrorReturn( /* error return (with message) */ -char *func, +const char *func, TMstruct *tms, int err ) { - tmLastFunction = func; - tmLastError = err; - if (tms != NULL && tms->flags & TM_F_NOSTDERR) - return(err); + if (tms != NULL) { + tms->lastFunc = func; + tms->lastError = err; + if (tms->flags & TM_F_NOSTDERR) + return(err); + } fputs(func, stderr); fputs(": ", stderr); fputs(tmErrorMessage[err], stderr);