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.9 by gwlarson, Mon Oct 5 16:49:52 1998 UTC vs.
Revision 3.11 by greg, Sat Feb 22 02:07:22 2003 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1998 Silicon Graphics, Inc. */
2 <
3 < /* SCCSid "$SunId$ SGI" */
4 <
1 > /* RCSid: $Id$ */
2   /*
3   * Header file for tone mapping functions.
4   *
5   * Include after "color.h"
6   */
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 49 | 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 92 | 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 104 | 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 122 | 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 159 | Line 221 | tmClearHisto(void);
221   */
222  
223   extern int
162 tmCvColors(TMbright *ls, BYTE *cs, COLOR *scan, int len);
163 /*
164        Convert RGB/XYZ float scanline to encoded luminance and chrominance.
165
166        ls      -       returned encoded luminance values.
167        cs      -       returned encoded chrominance values (Note 2).
168        scan    -       input scanline.
169        len     -       scanline length.
170
171        returns -       0 on success, TM_E_* on error.
172 */
173
174 extern int
175 tmCvColrs(TMbright *ls, BYTE *cs, COLR *scan, int len);
176 /*
177        Convert RGBE/XYZE scanline to encoded luminance and chrominance.
178
179        ls      -       returned encoded luminance values.
180        cs      -       returned encoded chrominance values (Note 2).
181        scan    -       input scanline.
182        len     -       scanline length.
183
184        returns -       0 on success, TM_E_* on error.
185 */
186
187 extern int
224   tmAddHisto(TMbright *ls, int len, int wt);
225   /*
226          Add brightness values to current histogram.
# Line 197 | 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.  This mapping will be used
253 <        in subsequent calls to tmMapPixels() until a new tone mapping
254 <        is computed.  I.e., calls to tmAddHisto() have no immediate effect.
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 223 | Line 274 | tmMapPixels(BYTE *ps, TMbright *ls, BYTE *cs, int len)
274          returns -       0 on success, TM_E_* on failure.
275   */
276  
226 extern int
227 tmLoadPicture(TMbright **lpp, BYTE **cpp, int *xp, int *yp,
228                char *fname, FILE *fp);
229 /*
230        Load Radiance picture and convert to tone mapping representation.
231        Memory for the luminance and chroma arrays is allocated using
232        malloc(3), and should be freed with free(3) when no longer needed.
233        Calls tmSetSpace() to calibrate input color space.
234
235        lpp     -       returned array of encoded luminances, picture ordering.
236        cpp     -       returned array of encoded chrominances (Note 2).
237        xp, yp  -       returned picture dimensions.
238        fname   -       picture file name.
239        fp      -       pointer to open file (Note 3).
240
241        returns -       0 on success, TM_E_* on failure.
242 */
243
244 extern int
245 tmMapPicture(BYTE **psp, int *xp, int *yp, int flags,
246                RGBPRIMP monpri, double gamval, double Lddyn, double Ldmax,
247                char *fname, FILE *fp);
248 /*
249        Load and apply tone mapping to Radiance picture.
250        Stack is restored to its original state upon return.
251        If fp is TM_GETFILE and (flags&TM_F_UNIMPL)!=0, tmMapPicture()
252        calls pcond to perform the actual conversion, which takes
253        longer but gives access to all the TM_F_* features.
254        Memory for the final pixel array is allocated using malloc(3),
255        and should be freed with free(3) when it is no longer needed.
256
257        psp     -       returned array of tone mapped pixels, picture ordering.
258        xp, yp  -       returned picture dimensions.
259        flags   -       TM_F_* flags indicating what is to be done.
260        monpri  -       display monitor primaries (Note 1).
261        gamval  -       display gamma response.
262        Lddyn   -       the display's dynamic range (0. for default).
263        Ldmax   -       maximum display luminance in cd/m^2 (0. for default).
264        fname   -       picture file name.
265        fp      -       pointer to open file (Note 3).
266
267        returns -       0 on success, TM_E_* on failure.
268 */
269
277   extern struct tmStruct *
278   tmPop(void);
279   /*
# Line 315 | 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 388 | 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