--- ray/src/common/tonemap.h 1998/10/05 16:49:52 3.9 +++ ray/src/common/tonemap.h 2003/06/27 06:53:22 3.14 @@ -1,14 +1,15 @@ -/* Copyright (c) 1998 Silicon Graphics, Inc. */ - -/* SCCSid "$SunId$ SGI" */ - +/* RCSid $Id: tonemap.h,v 3.14 2003/06/27 06:53:22 greg Exp $ */ /* * Header file for tone mapping functions. * * Include after "color.h" */ +#ifndef _RAD_TONEMAP_H_ +#define _RAD_TONEMAP_H_ +#ifdef __cplusplus +extern "C" { +#endif - /**** Argument Macros ****/ /* Flags of what to do */ #define TM_F_HCONTR 01 /* human contrast sensitivity */ @@ -49,6 +50,9 @@ #define TM_BRTSCALE 128 /* brightness scale factor (integer) */ +#define TM_NOBRT (-1<<15) /* bogus brightness value */ +#define TM_NOLUM (1e-17) /* ridiculously small luminance */ + #define TM_MAXPKG 8 /* maximum number of color formats */ @@ -83,19 +87,11 @@ extern struct tmStruct { } *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 (*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 */ @@ -104,7 +100,7 @@ extern int tmNumPkgs; /* number of registered packages /**** Useful Macros ****/ /* compute luminance from encoded value */ -#define tmLuminance(li) exp((li)/(double)TM_BRTSCALE) +#define tmLuminance(li) exp((li)*(1./TM_BRTSCALE)) /* does tone mapping need color matrix? */ #define tmNeedMatrix(t) ((t)->monpri != (t)->inppri) @@ -119,16 +115,7 @@ extern int tmNumPkgs; /* number of registered packages /**** Library Function Calls ****/ -#ifdef NOPROTO -extern struct tmStruct *tmInit(), *tmPop(), *tmDup(); -extern void tmClearHisto(), tmDone(); -extern int tmSetSpace(), tmCvColors(), tmCvColrs(); -extern int tmAddHisto(), tmComputeMapping(), tmMapPixels(); -extern int tmLoadPicture(), tmMapPicture(), tmPull(), tmPush(); - -#else - extern struct tmStruct * tmInit(int flags, RGBPRIMP monpri, double gamval); /* @@ -159,32 +146,6 @@ tmClearHisto(void); */ extern int -tmCvColors(TMbright *ls, BYTE *cs, COLOR *scan, int len); -/* - Convert RGB/XYZ float scanline to encoded luminance and chrominance. - - ls - returned encoded luminance values. - cs - returned encoded chrominance values (Note 2). - scan - input scanline. - len - scanline length. - - returns - 0 on success, TM_E_* on error. -*/ - -extern int -tmCvColrs(TMbright *ls, BYTE *cs, COLR *scan, int len); -/* - Convert RGBE/XYZE scanline to encoded luminance and chrominance. - - ls - returned encoded luminance values. - cs - returned encoded chrominance values (Note 2). - scan - input scanline. - len - scanline length. - - returns - 0 on success, TM_E_* on error. -*/ - -extern int tmAddHisto(TMbright *ls, int len, int wt); /* Add brightness values to current histogram. @@ -197,11 +158,26 @@ tmAddHisto(TMbright *ls, int len, int wt); */ extern int +tmFixedMapping(double expmult, double gamval); +/* + Assign a fixed, linear tone-mapping using the given multiplier, + which is the ratio of maximum output to uncalibrated input. + This mapping will be used in subsequent calls to tmMapPixels() + until a new tone mapping is computed. + Only the min. and max. values are used from the histogram. + + expmult - the fixed exposure multiplier to use. + gamval - display gamma response (0. for default). + returns - 0 on success, TM_E_* on error. +*/ + +extern int tmComputeMapping(double gamval, double Lddyn, double Ldmax); /* - Compute tone mapping function. This mapping will be used - in subsequent calls to tmMapPixels() until a new tone mapping - is computed. I.e., calls to tmAddHisto() have no immediate effect. + Compute tone mapping function from the current histogram. + This mapping will be used in subsequent calls to tmMapPixels() + until a new tone mapping is computed. + I.e., calls to tmAddHisto() have no immediate effect. gamval - display gamma response (0. for default). Lddyn - the display's dynamic range (0. for default). @@ -223,50 +199,6 @@ tmMapPixels(BYTE *ps, TMbright *ls, BYTE *cs, int len) returns - 0 on success, TM_E_* on failure. */ -extern int -tmLoadPicture(TMbright **lpp, BYTE **cpp, int *xp, int *yp, - char *fname, FILE *fp); -/* - Load Radiance picture and convert to tone mapping representation. - Memory for the luminance and chroma arrays is allocated using - malloc(3), and should be freed with free(3) when no longer needed. - Calls tmSetSpace() to calibrate input color space. - - lpp - returned array of encoded luminances, picture ordering. - cpp - returned array of encoded chrominances (Note 2). - xp, yp - returned picture dimensions. - fname - picture file name. - fp - pointer to open file (Note 3). - - returns - 0 on success, TM_E_* on failure. -*/ - -extern int -tmMapPicture(BYTE **psp, int *xp, int *yp, int flags, - RGBPRIMP monpri, double gamval, double Lddyn, double Ldmax, - char *fname, FILE *fp); -/* - Load and apply tone mapping to Radiance picture. - Stack is restored to its original state upon return. - If fp is TM_GETFILE and (flags&TM_F_UNIMPL)!=0, tmMapPicture() - calls pcond to perform the actual conversion, which takes - longer but gives access to all the TM_F_* features. - Memory for the final pixel array is allocated using malloc(3), - and should be freed with free(3) when it is no longer needed. - - psp - returned array of tone mapped pixels, picture ordering. - xp, yp - returned picture dimensions. - flags - TM_F_* flags indicating what is to be done. - monpri - display monitor primaries (Note 1). - gamval - display gamma response. - Lddyn - the display's dynamic range (0. for default). - Ldmax - maximum display luminance in cd/m^2 (0. for default). - fname - picture file name. - fp - pointer to open file (Note 3). - - returns - 0 on success, TM_E_* on failure. -*/ - extern struct tmStruct * tmPop(void); /* @@ -315,9 +247,90 @@ tmDone(struct tmStruct *tms); tms - tone mapping structure to free. */ -#endif +extern int +tmCvColors(TMbright *ls, BYTE *cs, COLOR *scan, int len); +/* + Convert RGB/XYZ float scanline to encoded luminance and chrominance. + ls - returned encoded luminance values. + cs - returned encoded chrominance values (Note 2). + scan - input scanline. + len - scanline length. + returns - 0 on success, TM_E_* on error. +*/ + +extern int +tmCvGrays(TMbright *ls, float *scan, int len); +/* + Convert gray float scanline to encoded luminance. + + ls - returned encoded luminance values. + scan - input scanline. + len - scanline length. + + returns - 0 on success, TM_E_* on error. +*/ + +extern int +tmCvColrs(TMbright *ls, BYTE *cs, COLR *scan, int len); +/* + Convert RGBE/XYZE scanline to encoded luminance and chrominance. + + ls - returned encoded luminance values. + cs - returned encoded chrominance values (Note 2). + scan - input scanline. + len - scanline length. + + returns - 0 on success, TM_E_* on error. +*/ + +extern int +tmLoadPicture(TMbright **lpp, BYTE **cpp, int *xp, int *yp, + char *fname, FILE *fp); +/* + Load Radiance picture and convert to tone mapping representation. + Memory for the luminance and chroma arrays is allocated using + malloc(3), and should be freed with free(3) when no longer needed. + Calls tmSetSpace() to calibrate input color space. + + lpp - returned array of encoded luminances, picture ordering. + cpp - returned array of encoded chrominances (Note 2). + xp, yp - returned picture dimensions. + fname - picture file name. + fp - pointer to open file (Note 3). + + returns - 0 on success, TM_E_* on failure. +*/ + +extern int +tmMapPicture(BYTE **psp, int *xp, int *yp, int flags, + RGBPRIMP monpri, double gamval, double Lddyn, double Ldmax, + char *fname, FILE *fp); +/* + Load and apply tone mapping to Radiance picture. + Stack is restored to its original state upon return. + If fp is TM_GETFILE and (flags&TM_F_UNIMPL)!=0, tmMapPicture() + calls pcond to perform the actual conversion, which takes + longer but gives access to all the TM_F_* features. + Memory for the final pixel array is allocated using malloc(3), + and should be freed with free(3) when it is no longer needed. + + psp - returned array of tone mapped pixels, picture ordering. + xp, yp - returned picture dimensions. + flags - TM_F_* flags indicating what is to be done. + monpri - display monitor primaries (Note 1). + gamval - display gamma response. + Lddyn - the display's dynamic range (0. for default). + Ldmax - maximum display luminance in cd/m^2 (0. for default). + fname - picture file name. + fp - pointer to open file (Note 3). + + returns - 0 on success, TM_E_* on failure. +*/ + + + /**** Notes ****/ /* General: @@ -388,3 +401,9 @@ tmDone(struct tmStruct *tms); function will open the file, read its contents and close it before returning, whether or not an error was encountered. */ + +#ifdef __cplusplus +} +#endif +#endif /* _RAD_TONEMAP_H_ */ +