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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines