--- ray/src/common/tonemap.h 2005/01/07 20:33:02 3.17 +++ ray/src/common/tonemap.h 2021/01/06 19:25:00 3.27 @@ -1,4 +1,4 @@ -/* RCSid $Id: tonemap.h,v 3.17 2005/01/07 20:33:02 greg Exp $ */ +/* RCSid $Id: tonemap.h,v 3.27 2021/01/06 19:25:00 greg Exp $ */ /* * Header file for tone mapping functions. * @@ -7,14 +7,14 @@ #ifndef _RAD_TONEMAP_H_ #define _RAD_TONEMAP_H_ -#include "tifftypes.h" +#include "tiff.h" /* needed for int32, etc. */ #ifdef __cplusplus extern "C" { #endif /**** Argument Macros ****/ - /* Flags of what to do */ + /* flags of what to do */ #define TM_F_HCONTR 01 /* human contrast sensitivity */ #define TM_F_MESOPIC 02 /* mesopic color sensitivity */ #define TM_F_LINEAR 04 /* linear brightness mapping */ @@ -32,8 +32,8 @@ extern "C" { /* special pointer values */ #define TM_XYZPRIM (RGBPRIMP)NULL /* indicate XYZ primaries (Note 1) */ -#define TM_NOCHROM (BYTE *)NULL /* indicate no chrominance */ -#define TM_NOCHROMP (BYTE **)NULL /* indicate no chrominances */ +#define TM_NOCHROM (uby8 *)NULL /* indicate no chrominance */ +#define TM_NOCHROMP (uby8 **)NULL /* indicate no chrominances */ #define TM_GETFILE (FILE *)NULL /* indicate file must be opened */ @@ -51,9 +51,9 @@ extern "C" { /**** Conversion Constants and Table Sizes ****/ -#define TM_BRTSCALE 128 /* brightness scale factor (integer) */ +#define TM_BRTSCALE 256 /* brightness scale factor (integer) */ -#define TM_NOBRT (-1<<15) /* bogus brightness value */ +#define TM_NOBRT (~0x7fff) /* bogus brightness value */ #define TM_NOLUM (1e-17) /* ridiculously small luminance */ #define TM_MAXPKG 8 /* maximum number of color formats */ @@ -64,15 +64,17 @@ extern "C" { #ifndef MEM_PTR #define MEM_PTR void * #endif +#ifndef HIST_TYP +#define HIST_TYP unsigned long +#endif +#define TMAP_TYP unsigned short extern char *tmErrorMessage[]; /* error messages */ -extern int tmLastError; /* last error incurred by library */ -extern char *tmLastFunction; /* error-generating function name */ typedef short TMbright; /* encoded luminance type */ /* basic tone mapping data structure */ -typedef struct tmStruct { +typedef struct { int flags; /* flags of what to do */ RGBPRIMP monpri; /* monitor RGB primaries */ double mongam; /* monitor gamma value (approx.) */ @@ -80,12 +82,15 @@ typedef struct tmStruct { int cdiv[3]; /* computed color divisors */ RGBPRIMP inppri; /* current input primaries */ double inpsf; /* current input scalefactor */ + MEM_PTR inpdat; /* current input client data */ COLORMAT cmat; /* color conversion matrix */ TMbright hbrmin, hbrmax; /* histogram brightness limits */ - int *histo; /* input histogram */ + HIST_TYP *histo; /* input histogram */ TMbright mbrmin, mbrmax; /* mapped brightness limits */ - unsigned short *lumap; /* computed luminance map */ + TMAP_TYP *lumap; /* computed luminance map */ MEM_PTR pd[TM_MAXPKG]; /* pointers to private data */ + int lastError; /* last error incurred */ + const char *lastFunc; /* error-generating function name */ } TMstruct; /* conversion package functions */ @@ -117,7 +122,24 @@ extern int tmNumPkgs; /* number of registered packages /**** Library Function Calls ****/ +extern TMbright +tmCvLuminance(double lum); +/* + Convert a single luminance value to an encoded brightness value. + */ +extern int +tmCvLums(TMbright *ls, float *scan, int len); +/* + Convert luminance values to encoded brightness values using lookup. + + ls - returned encoded luminance values. + scan - input scanline. + len - scanline length. + + returns - 0 on success, TM_E_* on error. + */ + extern TMstruct * tmInit(int flags, RGBPRIMP monpri, double gamval); /* @@ -131,13 +153,14 @@ tmInit(int flags, RGBPRIMP monpri, double gamval); */ extern int -tmSetSpace(TMstruct *tms, RGBPRIMP pri, double sf); +tmSetSpace(TMstruct *tms, RGBPRIMP pri, double sf, MEM_PTR dat); /* Set color primaries and scale factor for incoming scanlines. tms - tone mapping structure pointer. pri - RGB color input primaries (Note 1). sf - scale factor to get to luminance in cd/m^2. + dat - application-specific data (NULL if not needed) returns - 0 on success, TM_E_* code on failure. */ @@ -175,6 +198,7 @@ tmFixedMapping(TMstruct *tms, double expmult, double g tms - tone mapping structure pointer. expmult - the fixed exposure multiplier to use. gamval - display gamma response (0. for default). + returns - 0 on success, TM_E_* on error. */ @@ -195,7 +219,7 @@ tmComputeMapping(TMstruct *tms, double gamval, double */ extern int -tmMapPixels(TMstruct *tms, BYTE *ps, TMbright *ls, BYTE *cs, int len); +tmMapPixels(TMstruct *tms, uby8 *ps, TMbright *ls, uby8 *cs, int len); /* Apply tone mapping function to pixel values. @@ -214,6 +238,7 @@ tmDup(TMstruct *orig); Duplicate the given tone mapping into a new struct. orig - tone mapping structure to duplicate. + returns - pointer to new struct, or NULL on error. */ @@ -226,13 +251,12 @@ tmDone(TMstruct *tms); */ extern int -tmCvColors(TMstruct *tms, TMbright *ls, BYTE *cs, COLOR *scan, int len); +tmCvGrays(TMstruct *tms, TMbright *ls, float *scan, int len); /* - Convert RGB/XYZ float scanline to encoded luminance and chrominance. + Convert gray float scanline to encoded luminance. tms - tone mapping structure pointer. ls - returned encoded luminance values. - cs - returned encoded chrominance values (Note 2). scan - input scanline. len - scanline length. @@ -240,12 +264,13 @@ tmCvColors(TMstruct *tms, TMbright *ls, BYTE *cs, COLO */ extern int -tmCvGrays(TMstruct *tms, TMbright *ls, float *scan, int len); +tmCvColors(TMstruct *tms, TMbright *ls, uby8 *cs, COLOR *scan, int len); /* - Convert gray float scanline to encoded luminance. + Convert RGB/XYZ float scanline to encoded luminance and chrominance. tms - tone mapping structure pointer. ls - returned encoded luminance values. + cs - returned encoded chrominance values (Note 2). scan - input scanline. len - scanline length. @@ -253,7 +278,7 @@ tmCvGrays(TMstruct *tms, TMbright *ls, float *scan, in */ extern int -tmCvColrs(TMstruct *tms, TMbright *ls, BYTE *cs, COLR *scan, int len); +tmCvColrs(TMstruct *tms, TMbright *ls, uby8 *cs, COLR *scan, int len); /* Convert RGBE/XYZE scanline to encoded luminance and chrominance. @@ -267,7 +292,7 @@ tmCvColrs(TMstruct *tms, TMbright *ls, BYTE *cs, COLR */ extern int -tmLoadPicture(TMstruct *tms, TMbright **lpp, BYTE **cpp, int *xp, int *yp, +tmLoadPicture(TMstruct *tms, TMbright **lpp, uby8 **cpp, int *xp, int *yp, char *fname, FILE *fp); /* Load Radiance picture and convert to tone mapping representation. @@ -286,7 +311,7 @@ tmLoadPicture(TMstruct *tms, TMbright **lpp, BYTE **cp */ extern int -tmMapPicture(BYTE **psp, int *xp, int *yp, int flags, +tmMapPicture(uby8 **psp, int *xp, int *yp, int flags, RGBPRIMP monpri, double gamval, double Lddyn, double Ldmax, char *fname, FILE *fp); /* @@ -311,7 +336,7 @@ tmMapPicture(BYTE **psp, int *xp, int *yp, int flags, */ extern int -tmCvRGB48(TMstruct *tms, TMbright *ls, BYTE *cs, uint16 (*scan)[3], +tmCvRGB48(TMstruct *tms, TMbright *ls, uby8 *cs, uint16 (*scan)[3], int len, double gv); /* Convert 48-bit RGB scanline to encoded luminance and chrominance.