--- ray/src/common/tonemap.h 1997/04/15 16:53:03 3.1 +++ ray/src/common/tonemap.h 1997/04/18 13:59:48 3.4 @@ -8,6 +8,7 @@ /* required non-system header files */ #include "color.h" + /**** Argument Macros ****/ /* Flags of what to do */ #define TM_F_HCONTR 01 /* human contrast sensitivity */ @@ -18,7 +19,7 @@ #define TM_F_CWEIGHT 040 /* center weighting */ #define TM_F_FOVEAL 0100 /* use foveal sample size */ #define TM_F_BW 0200 /* luminance only */ -#define TM_F_NOERRS 0400 /* don't report errors to stderr */ +#define TM_F_NOSTDERR 0400 /* don't report errors to stderr */ /* combined modes */ #define TM_F_CAMERA 0 #define TM_F_HUMAN (TM_F_HCONTR|TM_F_MESOPIC|TM_F_VEIL|\ @@ -39,15 +40,23 @@ #define TM_E_TMINVAL 3 /* no valid tone mapping */ #define TM_E_TMFAIL 4 /* cannot compute tone mapping */ #define TM_E_BADFILE 5 /* cannot open or understand file */ +#define TM_E_CODERR1 6 /* code consistency error 1 */ +#define TM_E_CODERR2 7 /* code consistency error 2 */ + /**** Conversion Constants and Table Sizes ****/ #define TM_BRTSCALE 128 /* brightness scale factor (integer) */ -#define TM_GAMTSZ 1024 /* gamma lookup table size */ +#define TM_MAXPKG 8 /* maximum number of color formats */ -/**** Global Data Structures ****/ +/**** Global Data Types and Structures ****/ + +#ifndef MEM_PTR +#define MEM_PTR void * +#endif + extern char *tmErrorMessage[]; /* error messages */ typedef short TMbright; /* encoded luminance type */ @@ -57,28 +66,58 @@ extern struct tmStruct { int flags; /* flags of what to do */ RGBPRIMP monpri; /* monitor RGB primaries */ double mongam; /* monitor gamma value (approx.) */ - BYTE gamb[TM_GAMTSZ];/* gamma lookup table from mongam */ COLOR clf; /* computed luminance coefficients */ - COLR clfb; /* normalized version of clf */ + int cdiv[3]; /* computed color divisors */ RGBPRIMP inppri; /* current input primaries */ double inpsf; /* current input scalefactor */ - TMbright inpsfb; /* encoded version of inpsf */ COLORMAT cmat; /* color conversion matrix */ TMbright brmin, brmax; /* input brightness limits */ int *histo; /* input histogram */ unsigned short *lumap; /* computed luminance map */ struct tmStruct *tmprev; /* previous tone mapping */ + MEM_PTR pd[TM_MAXPKG]; /* pointers to private data */ } *tmTop; /* current tone mapping stack */ - + + /* conversion package functions */ +#ifdef NOPROTO +struct tmPackage { + MEM_PTR (*Init)(); /* initialize private data */ + void (*NewSpace)(); /* new input color space (optional) */ + void (*Free)(); /* free private data */ +}; +#else +struct tmPackage { + MEM_PTR (*Init)(struct tmStruct *tms); + int (*NewSpace)(struct tmStruct *tms); + void (*Free)(MEM_PTR pp); +}; +#endif + /* our list of conversion packages */ +extern struct tmPackage *tmPkg[TM_MAXPKG]; +extern int tmNumPkgs; /* number of registered packages */ + + /**** Useful Macros ****/ + /* compute luminance from encoded value */ #define tmLuminance(li) exp((li)/(double)TM_BRTSCALE) + /* does tone mapping need color matrix? */ +#define tmNeedMatrix(t) ((t)->monpri != (t)->inppri) + + /* register a conversion package */ +#define tmRegPkg(pf) ( tmNumPkgs >= TM_MAXPKG ? -1 : \ + (tmPkg[tmNumPkgs] = (pf), tmNumPkgs++) ) + + /* get the specific package's data */ +#define tmPkgData(t,i) ((t)->pd[i]!=NULL ? (t)->pd[i] : (*tmPkg[i]->Init)(t)) + + /**** Library Function Calls ****/ -#ifdef NOPROTO +#ifdef NOPROTO -extern struct tmStruct *tmInit(), *tmPop(); +extern struct tmStruct *tmInit(), *tmPop(), *tmDup(); extern void tmClearHisto(), tmDone(); extern int tmSetSpace(), tmCvColors(), tmCvColrs(); extern int tmAddHisto(), tmComputeMapping(), tmMapPixels(); @@ -183,6 +222,7 @@ tmLoadPicture(TMbright **lpp, BYTE **cpp, int *xp, int char *fname, FILE *fp); /* Load Radiance picture and convert to tone mapping representation. + Calls tmSetSpace() to calibrate input color space. lpp - returned array of encoded luminances, English ordering. cpp - returned array of encoded chrominances (Note 2). @@ -245,6 +285,14 @@ tmPush(struct tmStruct *tms); returns - 0 on success, TM_E_* if tms is invalid. */ +extern struct tmStruct * +tmDup(void); +/* + Duplicate the current tone mapping into a new structure on the stack. + + returns - pointer to new top, or NULL on error. +*/ + extern void tmDone(struct tmStruct *tms); /* @@ -258,7 +306,8 @@ tmDone(struct tmStruct *tms); */ #endif - + + /**** Notes ****/ /* General: @@ -280,7 +329,7 @@ tmDone(struct tmStruct *tms); used during final mapping, setting the cs parameter to TM_NOCHROM on the first pass will save time.) Another memory saving option if third and subsequent passes are not needed is to use the - same array to store the mapped pixels as is used to store + same array to store the mapped pixels as used to store the encoded chroma values. This way, only two extra bytes for storing encoded luminances are required per pixel. This is the method employed by tmMapPicture(), for example.