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.4 by greg, Fri Apr 18 13:59:48 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 32 | 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 48 | Line 106
106  
107   #define TM_BRTSCALE     128             /* brightness scale factor (integer) */
108  
109 + #define TM_NOBRT        (-1<<15)        /* bogus brightness value */
110 + #define TM_NOLUM        (1e-17)         /* ridiculously small luminance */
111 +
112   #define TM_MAXPKG       8               /* maximum number of color formats */
113  
114  
# Line 58 | Line 119
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 71 | Line 134 | extern struct tmStruct {
134          RGBPRIMP        inppri;         /* current input primaries */
135          double          inpsf;          /* current input scalefactor */
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 */
# Line 88 | Line 152 | struct tmPackage {
152   #else
153   struct tmPackage {
154          MEM_PTR         (*Init)(struct tmStruct *tms);
155 <        int             (*NewSpace)(struct tmStruct *tms);
155 >        void            (*NewSpace)(struct tmStruct *tms);
156          void            (*Free)(MEM_PTR pp);
157   };
158   #endif
# Line 100 | Line 164 | extern int     tmNumPkgs;      /* number of registered packages
164   /****    Useful Macros    ****/
165  
166                                  /* compute luminance from encoded value */
167 < #define tmLuminance(li) exp((li)/(double)TM_BRTSCALE)
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)
# Line 118 | Line 182 | extern int     tmNumPkgs;      /* number of registered packages
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 155 | Line 221 | tmClearHisto(void);
221   */
222  
223   extern int
158 tmCvColors(TMbright *ls, BYTE *cs, COLOR *scan, int len);
159 /*
160        Convert RGB/XYZ float scanline to encoded luminance and chrominance.
161
162        ls      -       returned encoded luminance values.
163        cs      -       returned encoded chrominance values (Note 2).
164        scan    -       input scanline.
165        len     -       scanline length.
166
167        returns -       0 on success, TM_E_* on error.
168 */
169
170 extern int
171 tmCvColrs(TMbright *ls, BYTE *cs, COLR *scan, int len);
172 /*
173        Convert RGBE/XYZE scanline to encoded luminance and chrominance.
174
175        ls      -       returned encoded luminance values.
176        cs      -       returned encoded chrominance values (Note 2).
177        scan    -       input scanline.
178        len     -       scanline length.
179
180        returns -       0 on success, TM_E_* on error.
181 */
182
183 extern int
224   tmAddHisto(TMbright *ls, int len, int wt);
225   /*
226          Add brightness values to current histogram.
# Line 193 | 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 217 | Line 274 | tmMapPixels(BYTE *ps, TMbright *ls, BYTE *cs, int len)
274          returns -       0 on success, TM_E_* on failure.
275   */
276  
220 extern int
221 tmLoadPicture(TMbright **lpp, BYTE **cpp, int *xp, int *yp,
222                char *fname, FILE *fp);
223 /*
224        Load Radiance picture and convert to tone mapping representation.
225        Calls tmSetSpace() to calibrate input color space.
226
227        lpp     -       returned array of encoded luminances, English ordering.
228        cpp     -       returned array of encoded chrominances (Note 2).
229        xp, yp  -       returned picture dimensions.
230        fname   -       picture file name.
231        fp      -       pointer to open file (Note 3).
232
233        returns -       0 on success, TM_E_* on failure.
234 */
235
236 extern int
237 tmMapPicture(BYTE **psp, int *xp, int *yp, int flags,
238                RGBPRIMP monpri, double gamval, double Lddyn, double Ldmax,
239                char *fname, FILE *fp);
240 /*
241        Load and apply tone mapping to Radiance picture.
242        Stack is restored to its original state upon return.
243        If fp is TM_GETFILE and (flags&TM_F_UNIMPL)!=0, tmMapPicture()
244        calls pcond to perform the actual conversion, which takes
245        longer but gives access to all the TM_F_* features.
246
247        psp     -       returned array of tone mapped pixels, English ordering.
248        xp, yp  -       returned picture dimensions.
249        flags   -       TM_F_* flags indicating what is to be done.
250        monpri  -       display monitor primaries (Note 1).
251        gamval  -       display gamma response.
252        Lddyn   -       the display's dynamic range (0. for default).
253        Ldmax   -       maximum display luminance in cd/m^2 (0. for default).
254        fname   -       picture file name.
255        fp      -       pointer to open file (Note 3).
256
257        returns -       0 on success, TM_E_* on failure.
258 */
259
277   extern struct tmStruct *
278   tmPop(void);
279   /*
# Line 305 | 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  
409  
# Line 316 | 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 378 | 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