--- ray/src/common/tonemap.h 2005/11/14 22:18:18 3.20 +++ ray/src/common/tonemap.h 2024/11/21 17:15:54 3.33 @@ -1,4 +1,4 @@ -/* RCSid $Id: tonemap.h,v 3.20 2005/11/14 22:18:18 greg Exp $ */ +/* RCSid $Id: tonemap.h,v 3.33 2024/11/21 17:15:54 greg Exp $ */ /* * Header file for tone mapping functions. * @@ -7,7 +7,7 @@ #ifndef _RAD_TONEMAP_H_ #define _RAD_TONEMAP_H_ -#include "tifftypes.h" +#include "tiff.h" /* needed for int32, etc. */ #ifdef __cplusplus extern "C" { @@ -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,19 +51,24 @@ 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_BRES 4096 /* luminance tone-map resolution */ + #define TM_MAXPKG 8 /* maximum number of color formats */ /**** Global Data Types and Structures ****/ -#ifndef MEM_PTR -#define MEM_PTR void * +#ifndef HIST_TYP +#define HIST_TYP unsigned long #endif +#ifndef TMAP_TYP +#define TMAP_TYP uint16 +#endif extern char *tmErrorMessage[]; /* error messages */ @@ -78,22 +83,21 @@ typedef struct { 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 */ - MEM_PTR pd[TM_MAXPKG]; /* pointers to private data */ + TMAP_TYP *lumap; /* computed luminance map */ + void *pd[TM_MAXPKG]; /* pointers to private data */ int lastError; /* last error incurred */ const char *lastFunc; /* error-generating function name */ } TMstruct; /* conversion package functions */ struct tmPackage { - MEM_PTR (*Init)(TMstruct *tms); + void * (*Init)(TMstruct *tms); void (*NewSpace)(TMstruct *tms); - void (*Free)(MEM_PTR pp); + void (*Free)(void *pp); }; /* our list of conversion packages */ extern struct tmPackage *tmPkg[TM_MAXPKG]; @@ -118,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); /* @@ -132,14 +153,13 @@ tmInit(int flags, RGBPRIMP monpri, double gamval); */ extern int -tmSetSpace(TMstruct *tms, RGBPRIMP pri, double sf, MEM_PTR dat); +tmSetSpace(TMstruct *tms, RGBPRIMP pri, double sf); /* 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. */ @@ -166,7 +186,7 @@ tmAddHisto(TMstruct *tms, TMbright *ls, int len, int w */ extern int -tmFixedMapping(TMstruct *tms, double expmult, double gamval); +tmFixedMapping(TMstruct *tms, double expmult, double gamval, double Lddyn); /* Assign a fixed, linear tone-mapping using the given multiplier, which is the ratio of maximum output to uncalibrated input. @@ -177,6 +197,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). + Lddyn - the display's dynamic range (0. for default). returns - 0 on success, TM_E_* on error. */ @@ -198,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. @@ -230,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. @@ -244,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. @@ -257,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. @@ -271,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. @@ -290,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); /* @@ -315,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.