ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/tonemap.h
(Generate patch)

Comparing ray/src/common/tonemap.h (file contents):
Revision 3.3 by greg, Wed Apr 16 20:28:07 1997 UTC vs.
Revision 3.11 by greg, Sat Feb 22 02:07:22 2003 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1997 Regents of the University of California */
2 <
3 < /* SCCSid "$SunId$ LBL" */
4 <
1 > /* RCSid: $Id$ */
2   /*
3   * Header file for tone mapping functions.
4 + *
5 + * Include after "color.h"
6   */
8                                /* required non-system header files */
9 #include        "color.h"
7  
8 + /* ====================================================================
9 + * The Radiance Software License, Version 1.0
10 + *
11 + * Copyright (c) 1990 - 2002 The Regents of the University of California,
12 + * through Lawrence Berkeley National Laboratory.   All rights reserved.
13 + *
14 + * Redistribution and use in source and binary forms, with or without
15 + * modification, are permitted provided that the following conditions
16 + * are met:
17 + *
18 + * 1. Redistributions of source code must retain the above copyright
19 + *         notice, this list of conditions and the following disclaimer.
20 + *
21 + * 2. Redistributions in binary form must reproduce the above copyright
22 + *       notice, this list of conditions and the following disclaimer in
23 + *       the documentation and/or other materials provided with the
24 + *       distribution.
25 + *
26 + * 3. The end-user documentation included with the redistribution,
27 + *           if any, must include the following acknowledgment:
28 + *             "This product includes Radiance software
29 + *                 (http://radsite.lbl.gov/)
30 + *                 developed by the Lawrence Berkeley National Laboratory
31 + *               (http://www.lbl.gov/)."
32 + *       Alternately, this acknowledgment may appear in the software itself,
33 + *       if and wherever such third-party acknowledgments normally appear.
34 + *
35 + * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
36 + *       and "The Regents of the University of California" must
37 + *       not be used to endorse or promote products derived from this
38 + *       software without prior written permission. For written
39 + *       permission, please contact [email protected].
40 + *
41 + * 5. Products derived from this software may not be called "Radiance",
42 + *       nor may "Radiance" appear in their name, without prior written
43 + *       permission of Lawrence Berkeley National Laboratory.
44 + *
45 + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
46 + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
47 + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
48 + * DISCLAIMED.   IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
49 + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
50 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
51 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
52 + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
53 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
54 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
55 + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 + * SUCH DAMAGE.
57 + * ====================================================================
58 + *
59 + * This software consists of voluntary contributions made by many
60 + * individuals on behalf of Lawrence Berkeley National Laboratory.   For more
61 + * information on Lawrence Berkeley National Laboratory, please see
62 + * <http://www.lbl.gov/>.
63 + */
64 +
65 + #ifdef __cplusplus
66 + extern "C" {
67 + #endif
68 +
69   /****    Argument Macros    ****/
70                                  /* Flags of what to do */
71   #define TM_F_HCONTR     01              /* human contrast sensitivity */
# Line 31 | Line 89
89   #define TM_NOCHROMP     (BYTE **)NULL   /* indicate no chrominances */
90   #define TM_GETFILE      (FILE *)NULL    /* indicate file must be opened */
91  
92 +
93   /****    Error Return Values    ****/
94  
95   #define TM_E_OK         0               /* normal return status */
# Line 39 | Line 98
98   #define TM_E_TMINVAL    3               /* no valid tone mapping */
99   #define TM_E_TMFAIL     4               /* cannot compute tone mapping */
100   #define TM_E_BADFILE    5               /* cannot open or understand file */
101 + #define TM_E_CODERR1    6               /* code consistency error 1 */
102 + #define TM_E_CODERR2    7               /* code consistency error 2 */
103  
104 +
105   /****    Conversion Constants and Table Sizes    ****/
106  
107   #define TM_BRTSCALE     128             /* brightness scale factor (integer) */
108  
109 < #define TM_GAMTSZ       1024            /* gamma lookup table size */
109 > #define TM_NOBRT        (-1<<15)        /* bogus brightness value */
110 > #define TM_NOLUM        (1e-17)         /* ridiculously small luminance */
111  
112 < /****    Global Data Structures    ****/
112 > #define TM_MAXPKG       8               /* maximum number of color formats */
113  
114 +
115 + /****    Global Data Types and Structures    ****/
116 +
117 + #ifndef MEM_PTR
118 + #define MEM_PTR         void *
119 + #endif
120 +
121   extern char     *tmErrorMessage[];      /* error messages */
122 + extern int      tmLastError;            /* last error incurred by library */
123 + extern char     *tmLastFunction;        /* error-generating function name */
124  
125   typedef short   TMbright;               /* encoded luminance type */
126  
# Line 57 | Line 129 | extern struct tmStruct {
129          int             flags;          /* flags of what to do */
130          RGBPRIMP        monpri;         /* monitor RGB primaries */
131          double          mongam;         /* monitor gamma value (approx.) */
60        BYTE            gamb[TM_GAMTSZ];/* gamma lookup table from mongam */
132          COLOR           clf;            /* computed luminance coefficients */
133 <        COLR            clfb;           /* normalized version of clf */
133 >        int             cdiv[3];        /* computed color divisors */
134          RGBPRIMP        inppri;         /* current input primaries */
135          double          inpsf;          /* current input scalefactor */
65        TMbright        inpsfb;         /* encoded version of inpsf */
136          COLORMAT        cmat;           /* color conversion matrix */
137 <        TMbright        brmin, brmax;   /* input brightness limits */  
137 >        TMbright        hbrmin, hbrmax; /* histogram brightness limits */      
138          int             *histo;         /* input histogram */
139 +        TMbright        mbrmin, mbrmax; /* mapped brightness limits */
140          unsigned short  *lumap;         /* computed luminance map */
141          struct tmStruct *tmprev;        /* previous tone mapping */
142 +        MEM_PTR         pd[TM_MAXPKG];  /* pointers to private data */
143   }       *tmTop;                 /* current tone mapping stack */
144 <
144 >
145 >                                /* conversion package functions */
146 > #ifdef  NOPROTO
147 > struct tmPackage {
148 >        MEM_PTR         (*Init)();      /* initialize private data */
149 >        void            (*NewSpace)();  /* new input color space (optional) */
150 >        void            (*Free)();      /* free private data */
151 > };
152 > #else
153 > struct tmPackage {
154 >        MEM_PTR         (*Init)(struct tmStruct *tms);
155 >        void            (*NewSpace)(struct tmStruct *tms);
156 >        void            (*Free)(MEM_PTR pp);
157 > };
158 > #endif
159 >                                /* our list of conversion packages */
160 > extern struct tmPackage *tmPkg[TM_MAXPKG];
161 > extern int      tmNumPkgs;      /* number of registered packages */
162 >
163 >
164   /****    Useful Macros    ****/
165  
166 < #define tmLuminance(li) exp((li)/(double)TM_BRTSCALE)
166 >                                /* compute luminance from encoded value */
167 > #define tmLuminance(li) exp((li)*(1./TM_BRTSCALE))
168  
169 +                                /* does tone mapping need color matrix? */
170 + #define tmNeedMatrix(t) ((t)->monpri != (t)->inppri)
171 +
172 +                                /* register a conversion package */
173 + #define tmRegPkg(pf)    ( tmNumPkgs >= TM_MAXPKG ? -1 : \
174 +                                (tmPkg[tmNumPkgs] = (pf), tmNumPkgs++) )
175 +
176 +                                /* get the specific package's data */
177 + #define tmPkgData(t,i)  ((t)->pd[i]!=NULL ? (t)->pd[i] : (*tmPkg[i]->Init)(t))
178 +
179 +
180   /****    Library Function Calls    ****/
181  
182 < #ifdef NOPROTO
182 > #ifdef  NOPROTO
183  
184   extern struct tmStruct  *tmInit(), *tmPop(), *tmDup();
185 + extern int      tmSetSpace(), tmPull(), tmPush();
186   extern void     tmClearHisto(), tmDone();
187 < extern int      tmSetSpace(), tmCvColors(), tmCvColrs();
188 < extern int      tmAddHisto(), tmComputeMapping(), tmMapPixels();
189 < extern int      tmLoadPicture(), tmMapPicture(), tmPull(), tmPush();
187 > extern int      tmAddHisto();
188 > extern int      tmFixedMapping(), tmComputeMapping(), tmMapPixels();
189 > extern int      tmCvColors(), tmCvGrays(), tmCvColrs();
190 > extern int      tmLoadPicture(), tmMapPicture();
191  
192   #else
193  
# Line 116 | Line 221 | tmClearHisto(void);
221   */
222  
223   extern int
119 tmCvColors(TMbright *ls, BYTE *cs, COLOR *scan, int len);
120 /*
121        Convert RGB/XYZ float scanline to encoded luminance and chrominance.
122
123        ls      -       returned encoded luminance values.
124        cs      -       returned encoded chrominance values (Note 2).
125        scan    -       input scanline.
126        len     -       scanline length.
127
128        returns -       0 on success, TM_E_* on error.
129 */
130
131 extern int
132 tmCvColrs(TMbright *ls, BYTE *cs, COLR *scan, int len);
133 /*
134        Convert RGBE/XYZE scanline to encoded luminance and chrominance.
135
136        ls      -       returned encoded luminance values.
137        cs      -       returned encoded chrominance values (Note 2).
138        scan    -       input scanline.
139        len     -       scanline length.
140
141        returns -       0 on success, TM_E_* on error.
142 */
143
144 extern int
224   tmAddHisto(TMbright *ls, int len, int wt);
225   /*
226          Add brightness values to current histogram.
# Line 154 | Line 233 | tmAddHisto(TMbright *ls, int len, int wt);
233   */
234  
235   extern int
236 + tmFixedMapping(double expmult, double gamval);
237 + /*
238 +        Assign a fixed, linear tone-mapping using the given multiplier,
239 +        which is the ratio of maximum output to uncalibrated input.
240 +        This mapping will be used in subsequent calls to tmMapPixels()
241 +        until a new tone mapping is computed.
242 +        Only the min. and max. values are used from the histogram.
243 +        
244 +        expmult -       the fixed exposure multiplier to use.
245 +        gamval  -       display gamma response (0. for default).
246 +        returns -       0 on success, TM_E_* on error.
247 + */
248 +
249 + extern int
250   tmComputeMapping(double gamval, double Lddyn, double Ldmax);
251   /*
252 <        Compute tone mapping function.
252 >        Compute tone mapping function from the current histogram.
253 >        This mapping will be used in subsequent calls to tmMapPixels()
254 >        until a new tone mapping is computed.
255 >        I.e., calls to tmAddHisto() have no immediate effect.
256  
257          gamval  -       display gamma response (0. for default).
258          Lddyn   -       the display's dynamic range (0. for default).
# Line 178 | Line 274 | tmMapPixels(BYTE *ps, TMbright *ls, BYTE *cs, int len)
274          returns -       0 on success, TM_E_* on failure.
275   */
276  
181 extern int
182 tmLoadPicture(TMbright **lpp, BYTE **cpp, int *xp, int *yp,
183                char *fname, FILE *fp);
184 /*
185        Load Radiance picture and convert to tone mapping representation.
186        Calls tmSetSpace() to calibrate input color space.
187
188        lpp     -       returned array of encoded luminances, English ordering.
189        cpp     -       returned array of encoded chrominances (Note 2).
190        xp, yp  -       returned picture dimensions.
191        fname   -       picture file name.
192        fp      -       pointer to open file (Note 3).
193
194        returns -       0 on success, TM_E_* on failure.
195 */
196
197 extern int
198 tmMapPicture(BYTE **psp, int *xp, int *yp, int flags,
199                RGBPRIMP monpri, double gamval, double Lddyn, double Ldmax,
200                char *fname, FILE *fp);
201 /*
202        Load and apply tone mapping to Radiance picture.
203        Stack is restored to its original state upon return.
204        If fp is TM_GETFILE and (flags&TM_F_UNIMPL)!=0, tmMapPicture()
205        calls pcond to perform the actual conversion, which takes
206        longer but gives access to all the TM_F_* features.
207
208        psp     -       returned array of tone mapped pixels, English ordering.
209        xp, yp  -       returned picture dimensions.
210        flags   -       TM_F_* flags indicating what is to be done.
211        monpri  -       display monitor primaries (Note 1).
212        gamval  -       display gamma response.
213        Lddyn   -       the display's dynamic range (0. for default).
214        Ldmax   -       maximum display luminance in cd/m^2 (0. for default).
215        fname   -       picture file name.
216        fp      -       pointer to open file (Note 3).
217
218        returns -       0 on success, TM_E_* on failure.
219 */
220
277   extern struct tmStruct *
278   tmPop(void);
279   /*
# Line 266 | Line 322 | tmDone(struct tmStruct *tms);
322          tms     -       tone mapping structure to free.
323   */
324  
325 + extern int
326 + tmCvColors(TMbright *ls, BYTE *cs, COLOR *scan, int len);
327 + /*
328 +        Convert RGB/XYZ float scanline to encoded luminance and chrominance.
329 +
330 +        ls      -       returned encoded luminance values.
331 +        cs      -       returned encoded chrominance values (Note 2).
332 +        scan    -       input scanline.
333 +        len     -       scanline length.
334 +
335 +        returns -       0 on success, TM_E_* on error.
336 + */
337 +
338 + extern int
339 + tmCvGrays(TMbright *ls, float *scan, int len);
340 + /*
341 +        Convert gray float scanline to encoded luminance.
342 +
343 +        ls      -       returned encoded luminance values.
344 +        scan    -       input scanline.
345 +        len     -       scanline length.
346 +
347 +        returns -       0 on success, TM_E_* on error.
348 + */
349 +
350 + extern int
351 + tmCvColrs(TMbright *ls, BYTE *cs, COLR *scan, int len);
352 + /*
353 +        Convert RGBE/XYZE scanline to encoded luminance and chrominance.
354 +
355 +        ls      -       returned encoded luminance values.
356 +        cs      -       returned encoded chrominance values (Note 2).
357 +        scan    -       input scanline.
358 +        len     -       scanline length.
359 +
360 +        returns -       0 on success, TM_E_* on error.
361 + */
362 +
363 + extern int
364 + tmLoadPicture(TMbright **lpp, BYTE **cpp, int *xp, int *yp,
365 +                char *fname, FILE *fp);
366 + /*
367 +        Load Radiance picture and convert to tone mapping representation.
368 +        Memory for the luminance and chroma arrays is allocated using
369 +        malloc(3), and should be freed with free(3) when no longer needed.
370 +        Calls tmSetSpace() to calibrate input color space.
371 +
372 +        lpp     -       returned array of encoded luminances, picture ordering.
373 +        cpp     -       returned array of encoded chrominances (Note 2).
374 +        xp, yp  -       returned picture dimensions.
375 +        fname   -       picture file name.
376 +        fp      -       pointer to open file (Note 3).
377 +
378 +        returns -       0 on success, TM_E_* on failure.
379 + */
380 +
381 + extern int
382 + tmMapPicture(BYTE **psp, int *xp, int *yp, int flags,
383 +                RGBPRIMP monpri, double gamval, double Lddyn, double Ldmax,
384 +                char *fname, FILE *fp);
385 + /*
386 +        Load and apply tone mapping to Radiance picture.
387 +        Stack is restored to its original state upon return.
388 +        If fp is TM_GETFILE and (flags&TM_F_UNIMPL)!=0, tmMapPicture()
389 +        calls pcond to perform the actual conversion, which takes
390 +        longer but gives access to all the TM_F_* features.
391 +        Memory for the final pixel array is allocated using malloc(3),
392 +        and should be freed with free(3) when it is no longer needed.
393 +
394 +        psp     -       returned array of tone mapped pixels, picture ordering.
395 +        xp, yp  -       returned picture dimensions.
396 +        flags   -       TM_F_* flags indicating what is to be done.
397 +        monpri  -       display monitor primaries (Note 1).
398 +        gamval  -       display gamma response.
399 +        Lddyn   -       the display's dynamic range (0. for default).
400 +        Ldmax   -       maximum display luminance in cd/m^2 (0. for default).
401 +        fname   -       picture file name.
402 +        fp      -       pointer to open file (Note 3).
403 +
404 +        returns -       0 on success, TM_E_* on failure.
405 + */
406 +
407   #endif
408 <
408 >
409 >
410   /****    Notes    ****/
411   /*
412          General:
# Line 276 | Line 415 | tmDone(struct tmStruct *tms);
415          pixel values to chroma and luminance encodings, which can
416          be passed to tmAddHisto() to put into the tone mapping histogram.
417          This histogram is then used along with the display parameters
418 <        by tmComputMapping() to compute the luminance mapping function.
418 >        by tmComputeMapping() to compute the luminance mapping function.
419          (Colors are tone-mapped as they are converted if TM_F_MESOPIC
420          is set.)  The encoded chroma and luminance values may then be
421          passed to tmMapPixels() to apply the computed tone mapping in
# Line 338 | Line 477 | tmDone(struct tmStruct *tms);
477          function will open the file, read its contents and close it
478          before returning, whether or not an error was encountered.
479   */
480 +
481 + #ifdef __cplusplus
482 + }
483 + #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines