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.7 by gregl, Mon Nov 17 13:54:35 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 + 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 */  
76 >        TMbright        hbrmin, hbrmax; /* histogram brightness limits */      
77          int             *histo;         /* input histogram */
78 +        TMbright        mbrmin, mbrmax; /* mapped brightness limits */
79          unsigned short  *lumap;         /* computed luminance map */
80          struct tmStruct *tmprev;        /* previous tone mapping */
81 +        MEM_PTR         pd[TM_MAXPKG];  /* pointers to private data */
82   }       *tmTop;                 /* current tone mapping stack */
83 <
83 >
84 >                                /* conversion package functions */
85 > #ifdef  NOPROTO
86 > struct tmPackage {
87 >        MEM_PTR         (*Init)();      /* initialize private data */
88 >        void            (*NewSpace)();  /* new input color space (optional) */
89 >        void            (*Free)();      /* free private data */
90 > };
91 > #else
92 > struct tmPackage {
93 >        MEM_PTR         (*Init)(struct tmStruct *tms);
94 >        int             (*NewSpace)(struct tmStruct *tms);
95 >        void            (*Free)(MEM_PTR pp);
96 > };
97 > #endif
98 >                                /* our list of conversion packages */
99 > extern struct tmPackage *tmPkg[TM_MAXPKG];
100 > extern int      tmNumPkgs;      /* number of registered packages */
101 >
102 >
103   /****    Useful Macros    ****/
104  
105 +                                /* compute luminance from encoded value */
106   #define tmLuminance(li) exp((li)/(double)TM_BRTSCALE)
107  
108 +                                /* does tone mapping need color matrix? */
109 + #define tmNeedMatrix(t) ((t)->monpri != (t)->inppri)
110 +
111 +                                /* register a conversion package */
112 + #define tmRegPkg(pf)    ( tmNumPkgs >= TM_MAXPKG ? -1 : \
113 +                                (tmPkg[tmNumPkgs] = (pf), tmNumPkgs++) )
114 +
115 +                                /* get the specific package's data */
116 + #define tmPkgData(t,i)  ((t)->pd[i]!=NULL ? (t)->pd[i] : (*tmPkg[i]->Init)(t))
117 +
118 +
119   /****    Library Function Calls    ****/
120  
121 < #ifdef NOPROTO
121 > #ifdef  NOPROTO
122  
123 < extern struct tmStruct  *tmInit(), *tmPop();
123 > extern struct tmStruct  *tmInit(), *tmPop(), *tmDup();
124   extern void     tmClearHisto(), tmDone();
125   extern int      tmSetSpace(), tmCvColors(), tmCvColrs();
126   extern int      tmAddHisto(), tmComputeMapping(), tmMapPixels();
# Line 156 | Line 198 | tmAddHisto(TMbright *ls, int len, int wt);
198   extern int
199   tmComputeMapping(double gamval, double Lddyn, double Ldmax);
200   /*
201 <        Compute tone mapping function.
201 >        Compute tone mapping function.  This mapping will be used
202 >        in subsequent calls to tmMapPixels() until a new tone mapping
203 >        is computed.  I.e., calls to tmAddHisto() have no immediate effect.
204  
205          gamval  -       display gamma response (0. for default).
206          Lddyn   -       the display's dynamic range (0. for default).
# Line 183 | Line 227 | tmLoadPicture(TMbright **lpp, BYTE **cpp, int *xp, int
227                  char *fname, FILE *fp);
228   /*
229          Load Radiance picture and convert to tone mapping representation.
230 +        Memory for the luminance and chroma arrays is allocated using
231 +        malloc(3), and should be freed with free(3) when no longer needed.
232 +        Calls tmSetSpace() to calibrate input color space.
233  
234          lpp     -       returned array of encoded luminances, English ordering.
235          cpp     -       returned array of encoded chrominances (Note 2).
# Line 203 | Line 250 | tmMapPicture(BYTE **psp, int *xp, int *yp, int flags,
250          If fp is TM_GETFILE and (flags&TM_F_UNIMPL)!=0, tmMapPicture()
251          calls pcond to perform the actual conversion, which takes
252          longer but gives access to all the TM_F_* features.
253 +        Memory for the final pixel array is allocated using malloc(3),
254 +        and should be freed with free(3) when it is no longer needed.
255  
256          psp     -       returned array of tone mapped pixels, English ordering.
257          xp, yp  -       returned picture dimensions.
# Line 245 | Line 294 | tmPush(struct tmStruct *tms);
294          returns -       0 on success, TM_E_* if tms is invalid.
295   */
296  
297 + extern struct tmStruct *
298 + tmDup(void);
299 + /*
300 +        Duplicate the current tone mapping into a new structure on the stack.
301 +
302 +        returns -       pointer to new top, or NULL on error.
303 + */
304 +
305   extern void
306   tmDone(struct tmStruct *tms);
307   /*
# Line 258 | Line 315 | tmDone(struct tmStruct *tms);
315   */
316  
317   #endif
318 <
318 >
319 >
320   /****    Notes    ****/
321   /*
322          General:
# Line 267 | Line 325 | tmDone(struct tmStruct *tms);
325          pixel values to chroma and luminance encodings, which can
326          be passed to tmAddHisto() to put into the tone mapping histogram.
327          This histogram is then used along with the display parameters
328 <        by tmComputMapping() to compute the luminance mapping function.
328 >        by tmComputeMapping() to compute the luminance mapping function.
329          (Colors are tone-mapped as they are converted if TM_F_MESOPIC
330          is set.)  The encoded chroma and luminance values may then be
331          passed to tmMapPixels() to apply the computed tone mapping in
# Line 280 | Line 338 | tmDone(struct tmStruct *tms);
338          used during final mapping, setting the cs parameter to TM_NOCHROM
339          on the first pass will save time.)  Another memory saving option
340          if third and subsequent passes are not needed is to use the
341 <        same array to store the mapped pixels as is used to store
341 >        same array to store the mapped pixels as used to store
342          the encoded chroma values.  This way, only two extra bytes
343          for storing encoded luminances are required per pixel.  This
344          is the method employed by tmMapPicture(), for example.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines