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.1 by greg, Tue Apr 15 16:53:03 1997 UTC vs.
Revision 3.10 by gwlarson, Sun Dec 20 16:38:29 1998 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1997 Regents of the University of California */
1 > /* Copyright (c) 1998 Silicon Graphics, Inc. */
2  
3 < /* SCCSid "$SunId$ LBL" */
3 > /* SCCSid "$SunId$ SGI" */
4  
5   /*
6   * Header file for tone mapping functions.
7 + *
8 + * Include after "color.h"
9   */
8                                /* required non-system header files */
9 #include        "color.h"
10  
11 +
12   /****    Argument Macros    ****/
13                                  /* Flags of what to do */
14   #define TM_F_HCONTR     01              /* human contrast sensitivity */
# Line 18 | Line 19
19   #define TM_F_CWEIGHT    040             /* center weighting */
20   #define TM_F_FOVEAL     0100            /* use foveal sample size */
21   #define TM_F_BW         0200            /* luminance only */
22 < #define TM_F_NOERRS     0400            /* don't report errors to stderr */
22 > #define TM_F_NOSTDERR   0400            /* don't report errors to stderr */
23                                  /* combined modes */
24   #define TM_F_CAMERA     0
25   #define TM_F_HUMAN      (TM_F_HCONTR|TM_F_MESOPIC|TM_F_VEIL|\
# Line 31 | Line 32
32   #define TM_NOCHROMP     (BYTE **)NULL   /* indicate no chrominances */
33   #define TM_GETFILE      (FILE *)NULL    /* indicate file must be opened */
34  
35 +
36   /****    Error Return Values    ****/
37  
38   #define TM_E_OK         0               /* normal return status */
# Line 39 | Line 41
41   #define TM_E_TMINVAL    3               /* no valid tone mapping */
42   #define TM_E_TMFAIL     4               /* cannot compute tone mapping */
43   #define TM_E_BADFILE    5               /* cannot open or understand file */
44 + #define TM_E_CODERR1    6               /* code consistency error 1 */
45 + #define TM_E_CODERR2    7               /* code consistency error 2 */
46  
47 +
48   /****    Conversion Constants and Table Sizes    ****/
49  
50   #define TM_BRTSCALE     128             /* brightness scale factor (integer) */
51  
52 < #define TM_GAMTSZ       1024            /* gamma lookup table size */
52 > #define TM_NOBRT        (-1<<15)        /* bogus brightness value */
53  
54 < /****    Global Data Structures    ****/
54 > #define TM_MAXPKG       8               /* maximum number of color formats */
55  
56 +
57 + /****    Global Data Types and Structures    ****/
58 +
59 + #ifndef MEM_PTR
60 + #define MEM_PTR         void *
61 + #endif
62 +
63   extern char     *tmErrorMessage[];      /* error messages */
64 + extern int      tmLastError;            /* last error incurred by library */
65 + extern char     *tmLastFunction;        /* error-generating function name */
66  
67   typedef short   TMbright;               /* encoded luminance type */
68  
# Line 57 | Line 71 | extern struct tmStruct {
71          int             flags;          /* flags of what to do */
72          RGBPRIMP        monpri;         /* monitor RGB primaries */
73          double          mongam;         /* monitor gamma value (approx.) */
60        BYTE            gamb[TM_GAMTSZ];/* gamma lookup table from mongam */
74          COLOR           clf;            /* computed luminance coefficients */
75 <        COLR            clfb;           /* normalized version of clf */
75 >        int             cdiv[3];        /* computed color divisors */
76          RGBPRIMP        inppri;         /* current input primaries */
77          double          inpsf;          /* current input scalefactor */
65        TMbright        inpsfb;         /* encoded version of inpsf */
78          COLORMAT        cmat;           /* color conversion matrix */
79 <        TMbright        brmin, brmax;   /* input brightness limits */  
79 >        TMbright        hbrmin, hbrmax; /* histogram brightness limits */      
80          int             *histo;         /* input histogram */
81 +        TMbright        mbrmin, mbrmax; /* mapped brightness limits */
82          unsigned short  *lumap;         /* computed luminance map */
83          struct tmStruct *tmprev;        /* previous tone mapping */
84 +        MEM_PTR         pd[TM_MAXPKG];  /* pointers to private data */
85   }       *tmTop;                 /* current tone mapping stack */
86 <
86 >
87 >                                /* conversion package functions */
88 > #ifdef  NOPROTO
89 > struct tmPackage {
90 >        MEM_PTR         (*Init)();      /* initialize private data */
91 >        void            (*NewSpace)();  /* new input color space (optional) */
92 >        void            (*Free)();      /* free private data */
93 > };
94 > #else
95 > struct tmPackage {
96 >        MEM_PTR         (*Init)(struct tmStruct *tms);
97 >        int             (*NewSpace)(struct tmStruct *tms);
98 >        void            (*Free)(MEM_PTR pp);
99 > };
100 > #endif
101 >                                /* our list of conversion packages */
102 > extern struct tmPackage *tmPkg[TM_MAXPKG];
103 > extern int      tmNumPkgs;      /* number of registered packages */
104 >
105 >
106   /****    Useful Macros    ****/
107  
108 +                                /* compute luminance from encoded value */
109   #define tmLuminance(li) exp((li)/(double)TM_BRTSCALE)
110  
111 +                                /* does tone mapping need color matrix? */
112 + #define tmNeedMatrix(t) ((t)->monpri != (t)->inppri)
113 +
114 +                                /* register a conversion package */
115 + #define tmRegPkg(pf)    ( tmNumPkgs >= TM_MAXPKG ? -1 : \
116 +                                (tmPkg[tmNumPkgs] = (pf), tmNumPkgs++) )
117 +
118 +                                /* get the specific package's data */
119 + #define tmPkgData(t,i)  ((t)->pd[i]!=NULL ? (t)->pd[i] : (*tmPkg[i]->Init)(t))
120 +
121 +
122   /****    Library Function Calls    ****/
123  
124 < #ifdef NOPROTO
124 > #ifdef  NOPROTO
125  
126 < extern struct tmStruct  *tmInit(), *tmPop();
126 > extern struct tmStruct  *tmInit(), *tmPop(), *tmDup();
127   extern void     tmClearHisto(), tmDone();
128   extern int      tmSetSpace(), tmCvColors(), tmCvColrs();
129   extern int      tmAddHisto(), tmComputeMapping(), tmMapPixels();
# Line 156 | Line 201 | tmAddHisto(TMbright *ls, int len, int wt);
201   extern int
202   tmComputeMapping(double gamval, double Lddyn, double Ldmax);
203   /*
204 <        Compute tone mapping function.
204 >        Compute tone mapping function.  This mapping will be used
205 >        in subsequent calls to tmMapPixels() until a new tone mapping
206 >        is computed.  I.e., calls to tmAddHisto() have no immediate effect.
207  
208          gamval  -       display gamma response (0. for default).
209          Lddyn   -       the display's dynamic range (0. for default).
# Line 183 | Line 230 | tmLoadPicture(TMbright **lpp, BYTE **cpp, int *xp, int
230                  char *fname, FILE *fp);
231   /*
232          Load Radiance picture and convert to tone mapping representation.
233 +        Memory for the luminance and chroma arrays is allocated using
234 +        malloc(3), and should be freed with free(3) when no longer needed.
235 +        Calls tmSetSpace() to calibrate input color space.
236  
237 <        lpp     -       returned array of encoded luminances, English ordering.
237 >        lpp     -       returned array of encoded luminances, picture ordering.
238          cpp     -       returned array of encoded chrominances (Note 2).
239          xp, yp  -       returned picture dimensions.
240          fname   -       picture file name.
# Line 203 | Line 253 | tmMapPicture(BYTE **psp, int *xp, int *yp, int flags,
253          If fp is TM_GETFILE and (flags&TM_F_UNIMPL)!=0, tmMapPicture()
254          calls pcond to perform the actual conversion, which takes
255          longer but gives access to all the TM_F_* features.
256 +        Memory for the final pixel array is allocated using malloc(3),
257 +        and should be freed with free(3) when it is no longer needed.
258  
259 <        psp     -       returned array of tone mapped pixels, English ordering.
259 >        psp     -       returned array of tone mapped pixels, picture ordering.
260          xp, yp  -       returned picture dimensions.
261          flags   -       TM_F_* flags indicating what is to be done.
262          monpri  -       display monitor primaries (Note 1).
# Line 245 | Line 297 | tmPush(struct tmStruct *tms);
297          returns -       0 on success, TM_E_* if tms is invalid.
298   */
299  
300 + extern struct tmStruct *
301 + tmDup(void);
302 + /*
303 +        Duplicate the current tone mapping into a new structure on the stack.
304 +
305 +        returns -       pointer to new top, or NULL on error.
306 + */
307 +
308   extern void
309   tmDone(struct tmStruct *tms);
310   /*
# Line 258 | Line 318 | tmDone(struct tmStruct *tms);
318   */
319  
320   #endif
321 <
321 >
322 >
323   /****    Notes    ****/
324   /*
325          General:
# Line 267 | Line 328 | tmDone(struct tmStruct *tms);
328          pixel values to chroma and luminance encodings, which can
329          be passed to tmAddHisto() to put into the tone mapping histogram.
330          This histogram is then used along with the display parameters
331 <        by tmComputMapping() to compute the luminance mapping function.
331 >        by tmComputeMapping() to compute the luminance mapping function.
332          (Colors are tone-mapped as they are converted if TM_F_MESOPIC
333          is set.)  The encoded chroma and luminance values may then be
334          passed to tmMapPixels() to apply the computed tone mapping in
# Line 280 | Line 341 | tmDone(struct tmStruct *tms);
341          used during final mapping, setting the cs parameter to TM_NOCHROM
342          on the first pass will save time.)  Another memory saving option
343          if third and subsequent passes are not needed is to use the
344 <        same array to store the mapped pixels as is used to store
344 >        same array to store the mapped pixels as used to store
345          the encoded chroma values.  This way, only two extra bytes
346          for storing encoded luminances are required per pixel.  This
347          is the method employed by tmMapPicture(), for example.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines