--- ray/src/common/tonemap.h 2003/02/22 02:07:22 3.11 +++ ray/src/common/tonemap.h 2005/11/14 22:18:18 3.20 @@ -1,73 +1,20 @@ -/* RCSid: $Id: tonemap.h,v 3.11 2003/02/22 02:07:22 greg Exp $ */ +/* RCSid $Id: tonemap.h,v 3.20 2005/11/14 22:18:18 greg Exp $ */ /* * Header file for tone mapping functions. * * Include after "color.h" */ +#ifndef _RAD_TONEMAP_H_ +#define _RAD_TONEMAP_H_ -/* ==================================================================== - * The Radiance Software License, Version 1.0 - * - * Copyright (c) 1990 - 2002 The Regents of the University of California, - * through Lawrence Berkeley National Laboratory. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes Radiance software - * (http://radsite.lbl.gov/) - * developed by the Lawrence Berkeley National Laboratory - * (http://www.lbl.gov/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Radiance," "Lawrence Berkeley National Laboratory" - * and "The Regents of the University of California" must - * not be used to endorse or promote products derived from this - * software without prior written permission. For written - * permission, please contact radiance@radsite.lbl.gov. - * - * 5. Products derived from this software may not be called "Radiance", - * nor may "Radiance" appear in their name, without prior written - * permission of Lawrence Berkeley National Laboratory. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of Lawrence Berkeley National Laboratory. For more - * information on Lawrence Berkeley National Laboratory, please see - * . - */ +#include "tifftypes.h" #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 */ @@ -119,13 +66,11 @@ extern "C" { #endif 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 */ -extern struct tmStruct { +typedef struct { int flags; /* flags of what to do */ RGBPRIMP monpri; /* monitor RGB primaries */ double mongam; /* monitor gamma value (approx.) */ @@ -133,29 +78,23 @@ extern 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 */ TMbright mbrmin, mbrmax; /* mapped brightness limits */ 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 */ + int lastError; /* last error incurred */ + const char *lastFunc; /* error-generating function name */ +} TMstruct; /* 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); - void (*NewSpace)(struct tmStruct *tms); + MEM_PTR (*Init)(TMstruct *tms); + void (*NewSpace)(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 */ @@ -179,52 +118,46 @@ extern int tmNumPkgs; /* number of registered packages /**** Library Function Calls ****/ -#ifdef NOPROTO -extern struct tmStruct *tmInit(), *tmPop(), *tmDup(); -extern int tmSetSpace(), tmPull(), tmPush(); -extern void tmClearHisto(), tmDone(); -extern int tmAddHisto(); -extern int tmFixedMapping(), tmComputeMapping(), tmMapPixels(); -extern int tmCvColors(), tmCvGrays(), tmCvColrs(); -extern int tmLoadPicture(), tmMapPicture(); - -#else - -extern struct tmStruct * +extern TMstruct * tmInit(int flags, RGBPRIMP monpri, double gamval); /* - Initialize new tone mapping and push it onto stack. + Allocate and initialize new tone mapping. flags - TM_F_* flags indicating what is to be done. monpri - display monitor primaries (Note 1). gamval - display gamma response (can be approximate). - returns - new tmTop, or NULL if insufficient memory. + returns - new tone-mapping pointer, or NULL if no memory. */ extern int -tmSetSpace(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. */ extern void -tmClearHisto(void); +tmClearHisto(TMstruct *tms); /* Clear histogram for current tone mapping. + + tms - tone mapping structure pointer. */ extern int -tmAddHisto(TMbright *ls, int len, int wt); +tmAddHisto(TMstruct *tms, TMbright *ls, int len, int wt); /* Add brightness values to current histogram. + tms - tone mapping structure pointer. ls - encoded luminance values. len - number of luminance values. wt - integer weight to use for each value (usually 1 or -1). @@ -233,7 +166,7 @@ tmAddHisto(TMbright *ls, int len, int wt); */ extern int -tmFixedMapping(double expmult, double gamval); +tmFixedMapping(TMstruct *tms, double expmult, double gamval); /* Assign a fixed, linear tone-mapping using the given multiplier, which is the ratio of maximum output to uncalibrated input. @@ -241,19 +174,22 @@ tmFixedMapping(double expmult, double gamval); until a new tone mapping is computed. Only the min. and max. values are used from the histogram. + 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. */ extern int -tmComputeMapping(double gamval, double Lddyn, double Ldmax); +tmComputeMapping(TMstruct *tms, double gamval, double Lddyn, double Ldmax); /* 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. + tms - tone mapping structure pointer. gamval - display gamma response (0. for default). Lddyn - the display's dynamic range (0. for default). Ldmax - maximum display luminance in cd/m^2 (0. for default). @@ -262,10 +198,11 @@ tmComputeMapping(double gamval, double Lddyn, double L */ extern int -tmMapPixels(BYTE *ps, TMbright *ls, BYTE *cs, int len); +tmMapPixels(TMstruct *tms, BYTE *ps, TMbright *ls, BYTE *cs, int len); /* Apply tone mapping function to pixel values. + tms - tone mapping structure pointer. ps - returned pixel values (Note 2). ls - encoded luminance values. cs - encoded chrominance values (Note 2). @@ -274,59 +211,30 @@ tmMapPixels(BYTE *ps, TMbright *ls, BYTE *cs, int len) returns - 0 on success, TM_E_* on failure. */ -extern struct tmStruct * -tmPop(void); +extern TMstruct * +tmDup(TMstruct *orig); /* - Pops current tone mapping from stack. + Duplicate the given tone mapping into a new struct. - returns - pointer to tone mapping structure, or NULL if none. -*/ + orig - tone mapping structure to duplicate. -extern int -tmPull(struct tmStruct *tms); -/* - Pull tone mapping from anywhere in stack. - - tms - tone mapping structure to find. - - returns - 1 if found in stack, 0 otherwise. + returns - pointer to new struct, or NULL on error. */ -extern int -tmPush(struct tmStruct *tms); -/* - Make tone mapping active by (pulling it and) pushing it to the top. - - tms - initialized tone mapping structure. - - 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); +tmDone(TMstruct *tms); /* Free data associated with the given tone mapping structure. - Calls tmPull() first to remove it from the stack if present. - The calls tmDone(tmPop()), tmDone(tmTop) and tmDone(NULL) - all have the same effect, which is to remove and free - the current tone mapping. tms - tone mapping structure to free. */ extern int -tmCvColors(TMbright *ls, BYTE *cs, COLOR *scan, int len); +tmCvColors(TMstruct *tms, TMbright *ls, BYTE *cs, COLOR *scan, int len); /* 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. @@ -336,10 +244,11 @@ tmCvColors(TMbright *ls, BYTE *cs, COLOR *scan, int le */ extern int -tmCvGrays(TMbright *ls, float *scan, int len); +tmCvGrays(TMstruct *tms, TMbright *ls, float *scan, int len); /* Convert gray float scanline to encoded luminance. + tms - tone mapping structure pointer. ls - returned encoded luminance values. scan - input scanline. len - scanline length. @@ -348,10 +257,11 @@ tmCvGrays(TMbright *ls, float *scan, int len); */ extern int -tmCvColrs(TMbright *ls, BYTE *cs, COLR *scan, int len); +tmCvColrs(TMstruct *tms, TMbright *ls, BYTE *cs, COLR *scan, int len); /* Convert RGBE/XYZE 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. @@ -361,7 +271,7 @@ tmCvColrs(TMbright *ls, BYTE *cs, COLR *scan, int len) */ extern int -tmLoadPicture(TMbright **lpp, BYTE **cpp, int *xp, int *yp, +tmLoadPicture(TMstruct *tms, TMbright **lpp, BYTE **cpp, int *xp, int *yp, char *fname, FILE *fp); /* Load Radiance picture and convert to tone mapping representation. @@ -369,6 +279,7 @@ tmLoadPicture(TMbright **lpp, BYTE **cpp, int *xp, int malloc(3), and should be freed with free(3) when no longer needed. Calls tmSetSpace() to calibrate input color space. + tms - tone mapping structure pointer. lpp - returned array of encoded luminances, picture ordering. cpp - returned array of encoded chrominances (Note 2). xp, yp - returned picture dimensions. @@ -384,7 +295,6 @@ tmMapPicture(BYTE **psp, int *xp, int *yp, int flags, 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. @@ -404,9 +314,36 @@ tmMapPicture(BYTE **psp, int *xp, int *yp, int flags, returns - 0 on success, TM_E_* on failure. */ -#endif +extern int +tmCvRGB48(TMstruct *tms, TMbright *ls, BYTE *cs, uint16 (*scan)[3], + int len, double gv); +/* + Convert 48-bit RGB 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. + gv - input gamma value. + returns - 0 on success, TM_E_* on error. +*/ + +extern int +tmCvGray16(TMstruct *tms, TMbright *ls, uint16 *scan, int len, double gv); +/* + Convert 16-bit gray scanline to encoded luminance. + + tms - tone mapping structure pointer. + ls - returned encoded luminance values. + scan - input scanline. + len - scanline length. + gv - input gamma value. + + returns - 0 on success, TM_E_* on error. +*/ + /**** Notes ****/ /* General: @@ -481,3 +418,5 @@ tmMapPicture(BYTE **psp, int *xp, int *yp, int flags, #ifdef __cplusplus } #endif +#endif /* _RAD_TONEMAP_H_ */ +