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.2 by greg, Tue Apr 15 20:04:41 1997 UTC vs.
Revision 3.6 by gregl, Tue Jul 29 11:54:45 1997 UTC

# Line 8 | Line 8
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 39 | Line 40
40   #define TM_E_TMINVAL    3               /* no valid tone mapping */
41   #define TM_E_TMFAIL     4               /* cannot compute tone mapping */
42   #define TM_E_BADFILE    5               /* cannot open or understand file */
43 + #define TM_E_CODERR1    6               /* code consistency error 1 */
44 + #define TM_E_CODERR2    7               /* code consistency error 2 */
45  
46 +
47   /****    Conversion Constants and Table Sizes    ****/
48  
49   #define TM_BRTSCALE     128             /* brightness scale factor (integer) */
50  
51 < #define TM_GAMTSZ       1024            /* gamma lookup table size */
51 > #define TM_MAXPKG       8               /* maximum number of color formats */
52  
49 /****    Global Data Structures    ****/
53  
54 + /****    Global Data Types and Structures    ****/
55 +
56 + #ifndef MEM_PTR
57 + #define MEM_PTR         void *
58 + #endif
59 +
60   extern char     *tmErrorMessage[];      /* error messages */
61 + extern int      tmLastError;            /* last error incurred by library */
62 + extern char     *tmLastFunction;        /* error-generating function name */
63  
64   typedef short   TMbright;               /* encoded luminance type */
65  
# Line 57 | Line 68 | extern struct tmStruct {
68          int             flags;          /* flags of what to do */
69          RGBPRIMP        monpri;         /* monitor RGB primaries */
70          double          mongam;         /* monitor gamma value (approx.) */
60        BYTE            gamb[TM_GAMTSZ];/* gamma lookup table from mongam */
71          COLOR           clf;            /* computed luminance coefficients */
72 <        COLR            clfb;           /* normalized version of clf */
72 >        int             cdiv[3];        /* computed color divisors */
73          RGBPRIMP        inppri;         /* current input primaries */
74          double          inpsf;          /* current input scalefactor */
65        TMbright        inpsfb;         /* encoded version of inpsf */
75          COLORMAT        cmat;           /* color conversion matrix */
76          TMbright        brmin, brmax;   /* input brightness limits */  
77          int             *histo;         /* input histogram */
78          unsigned short  *lumap;         /* computed luminance map */
79          struct tmStruct *tmprev;        /* previous tone mapping */
80 +        MEM_PTR         pd[TM_MAXPKG];  /* pointers to private data */
81   }       *tmTop;                 /* current tone mapping stack */
82 <
82 >
83 >                                /* conversion package functions */
84 > #ifdef  NOPROTO
85 > struct tmPackage {
86 >        MEM_PTR         (*Init)();      /* initialize private data */
87 >        void            (*NewSpace)();  /* new input color space (optional) */
88 >        void            (*Free)();      /* free private data */
89 > };
90 > #else
91 > struct tmPackage {
92 >        MEM_PTR         (*Init)(struct tmStruct *tms);
93 >        int             (*NewSpace)(struct tmStruct *tms);
94 >        void            (*Free)(MEM_PTR pp);
95 > };
96 > #endif
97 >                                /* our list of conversion packages */
98 > extern struct tmPackage *tmPkg[TM_MAXPKG];
99 > extern int      tmNumPkgs;      /* number of registered packages */
100 >
101 >
102   /****    Useful Macros    ****/
103  
104 +                                /* compute luminance from encoded value */
105   #define tmLuminance(li) exp((li)/(double)TM_BRTSCALE)
106  
107 +                                /* does tone mapping need color matrix? */
108 + #define tmNeedMatrix(t) ((t)->monpri != (t)->inppri)
109 +
110 +                                /* register a conversion package */
111 + #define tmRegPkg(pf)    ( tmNumPkgs >= TM_MAXPKG ? -1 : \
112 +                                (tmPkg[tmNumPkgs] = (pf), tmNumPkgs++) )
113 +
114 +                                /* get the specific package's data */
115 + #define tmPkgData(t,i)  ((t)->pd[i]!=NULL ? (t)->pd[i] : (*tmPkg[i]->Init)(t))
116 +
117 +
118   /****    Library Function Calls    ****/
119  
120 < #ifdef NOPROTO
120 > #ifdef  NOPROTO
121  
122 < extern struct tmStruct  *tmInit(), *tmPop();
122 > extern struct tmStruct  *tmInit(), *tmPop(), *tmDup();
123   extern void     tmClearHisto(), tmDone();
124   extern int      tmSetSpace(), tmCvColors(), tmCvColrs();
125   extern int      tmAddHisto(), tmComputeMapping(), tmMapPixels();
# Line 183 | Line 224 | tmLoadPicture(TMbright **lpp, BYTE **cpp, int *xp, int
224                  char *fname, FILE *fp);
225   /*
226          Load Radiance picture and convert to tone mapping representation.
227 +        Memory for the luminance and chroma arrays is allocated using
228 +        malloc(3), and should be freed with free(3) when no longer needed.
229 +        Calls tmSetSpace() to calibrate input color space.
230  
231          lpp     -       returned array of encoded luminances, English ordering.
232          cpp     -       returned array of encoded chrominances (Note 2).
# Line 203 | Line 247 | tmMapPicture(BYTE **psp, int *xp, int *yp, int flags,
247          If fp is TM_GETFILE and (flags&TM_F_UNIMPL)!=0, tmMapPicture()
248          calls pcond to perform the actual conversion, which takes
249          longer but gives access to all the TM_F_* features.
250 +        Memory for the final pixel array is allocated using malloc(3),
251 +        and should be freed with free(3) when it is no longer needed.
252  
253          psp     -       returned array of tone mapped pixels, English ordering.
254          xp, yp  -       returned picture dimensions.
# Line 245 | Line 291 | tmPush(struct tmStruct *tms);
291          returns -       0 on success, TM_E_* if tms is invalid.
292   */
293  
294 + extern struct tmStruct *
295 + tmDup(void);
296 + /*
297 +        Duplicate the current tone mapping into a new structure on the stack.
298 +
299 +        returns -       pointer to new top, or NULL on error.
300 + */
301 +
302   extern void
303   tmDone(struct tmStruct *tms);
304   /*
# Line 258 | Line 312 | tmDone(struct tmStruct *tms);
312   */
313  
314   #endif
315 <
315 >
316 >
317   /****    Notes    ****/
318   /*
319          General:
# Line 267 | Line 322 | tmDone(struct tmStruct *tms);
322          pixel values to chroma and luminance encodings, which can
323          be passed to tmAddHisto() to put into the tone mapping histogram.
324          This histogram is then used along with the display parameters
325 <        by tmComputMapping() to compute the luminance mapping function.
325 >        by tmComputeMapping() to compute the luminance mapping function.
326          (Colors are tone-mapped as they are converted if TM_F_MESOPIC
327          is set.)  The encoded chroma and luminance values may then be
328          passed to tmMapPixels() to apply the computed tone mapping in
# Line 280 | Line 335 | tmDone(struct tmStruct *tms);
335          used during final mapping, setting the cs parameter to TM_NOCHROM
336          on the first pass will save time.)  Another memory saving option
337          if third and subsequent passes are not needed is to use the
338 <        same array to store the mapped pixels as is used to store
338 >        same array to store the mapped pixels as used to store
339          the encoded chroma values.  This way, only two extra bytes
340          for storing encoded luminances are required per pixel.  This
341          is the method employed by tmMapPicture(), for example.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines