1 |
< |
/* Copyright (c) 1997 Regents of the University of California */ |
2 |
< |
|
3 |
< |
/* SCCSid "$SunId$ LBL" */ |
4 |
< |
|
1 |
> |
/* RCSid $Id$ */ |
2 |
|
/* |
3 |
|
* Header file for tone mapping functions. |
4 |
+ |
* |
5 |
+ |
* Include after "color.h" |
6 |
|
*/ |
7 |
< |
/* required non-system header files */ |
8 |
< |
#include "color.h" |
7 |
> |
#ifndef _RAD_TONEMAP_H_ |
8 |
> |
#define _RAD_TONEMAP_H_ |
9 |
> |
#ifdef __cplusplus |
10 |
> |
extern "C" { |
11 |
> |
#endif |
12 |
|
|
13 |
|
/**** Argument Macros ****/ |
14 |
|
/* Flags of what to do */ |
33 |
|
#define TM_NOCHROMP (BYTE **)NULL /* indicate no chrominances */ |
34 |
|
#define TM_GETFILE (FILE *)NULL /* indicate file must be opened */ |
35 |
|
|
36 |
+ |
|
37 |
|
/**** Error Return Values ****/ |
38 |
|
|
39 |
|
#define TM_E_OK 0 /* normal return status */ |
42 |
|
#define TM_E_TMINVAL 3 /* no valid tone mapping */ |
43 |
|
#define TM_E_TMFAIL 4 /* cannot compute tone mapping */ |
44 |
|
#define TM_E_BADFILE 5 /* cannot open or understand file */ |
45 |
+ |
#define TM_E_CODERR1 6 /* code consistency error 1 */ |
46 |
+ |
#define TM_E_CODERR2 7 /* code consistency error 2 */ |
47 |
|
|
48 |
+ |
|
49 |
|
/**** Conversion Constants and Table Sizes ****/ |
50 |
|
|
51 |
|
#define TM_BRTSCALE 128 /* brightness scale factor (integer) */ |
52 |
|
|
53 |
< |
#define TM_GAMTSZ 1024 /* gamma lookup table size */ |
53 |
> |
#define TM_NOBRT (-1<<15) /* bogus brightness value */ |
54 |
> |
#define TM_NOLUM (1e-17) /* ridiculously small luminance */ |
55 |
|
|
56 |
< |
/**** Global Data Structures ****/ |
56 |
> |
#define TM_MAXPKG 8 /* maximum number of color formats */ |
57 |
|
|
58 |
+ |
|
59 |
+ |
/**** Global Data Types and Structures ****/ |
60 |
+ |
|
61 |
+ |
#ifndef MEM_PTR |
62 |
+ |
#define MEM_PTR void * |
63 |
+ |
#endif |
64 |
+ |
|
65 |
|
extern char *tmErrorMessage[]; /* error messages */ |
66 |
+ |
extern int tmLastError; /* last error incurred by library */ |
67 |
+ |
extern char *tmLastFunction; /* error-generating function name */ |
68 |
|
|
69 |
|
typedef short TMbright; /* encoded luminance type */ |
70 |
|
|
73 |
|
int flags; /* flags of what to do */ |
74 |
|
RGBPRIMP monpri; /* monitor RGB primaries */ |
75 |
|
double mongam; /* monitor gamma value (approx.) */ |
60 |
– |
BYTE gamb[TM_GAMTSZ];/* gamma lookup table from mongam */ |
76 |
|
COLOR clf; /* computed luminance coefficients */ |
77 |
< |
COLR clfb; /* normalized version of clf */ |
77 |
> |
int cdiv[3]; /* computed color divisors */ |
78 |
|
RGBPRIMP inppri; /* current input primaries */ |
79 |
|
double inpsf; /* current input scalefactor */ |
65 |
– |
TMbright inpsfb; /* encoded version of inpsf */ |
80 |
|
COLORMAT cmat; /* color conversion matrix */ |
81 |
< |
TMbright brmin, brmax; /* input brightness limits */ |
81 |
> |
TMbright hbrmin, hbrmax; /* histogram brightness limits */ |
82 |
|
int *histo; /* input histogram */ |
83 |
+ |
TMbright mbrmin, mbrmax; /* mapped brightness limits */ |
84 |
|
unsigned short *lumap; /* computed luminance map */ |
85 |
|
struct tmStruct *tmprev; /* previous tone mapping */ |
86 |
+ |
MEM_PTR pd[TM_MAXPKG]; /* pointers to private data */ |
87 |
|
} *tmTop; /* current tone mapping stack */ |
88 |
< |
|
88 |
> |
|
89 |
> |
/* conversion package functions */ |
90 |
> |
struct tmPackage { |
91 |
> |
MEM_PTR (*Init)(struct tmStruct *tms); |
92 |
> |
void (*NewSpace)(struct tmStruct *tms); |
93 |
> |
void (*Free)(MEM_PTR pp); |
94 |
> |
}; |
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 |
< |
#define tmLuminance(li) exp((li)/(double)TM_BRTSCALE) |
102 |
> |
/* compute luminance from encoded value */ |
103 |
> |
#define tmLuminance(li) exp((li)*(1./TM_BRTSCALE)) |
104 |
|
|
105 |
< |
/**** Library Function Calls ****/ |
105 |
> |
/* does tone mapping need color matrix? */ |
106 |
> |
#define tmNeedMatrix(t) ((t)->monpri != (t)->inppri) |
107 |
|
|
108 |
< |
#ifdef NOPROTO |
108 |
> |
/* register a conversion package */ |
109 |
> |
#define tmRegPkg(pf) ( tmNumPkgs >= TM_MAXPKG ? -1 : \ |
110 |
> |
(tmPkg[tmNumPkgs] = (pf), tmNumPkgs++) ) |
111 |
|
|
112 |
< |
extern struct tmStruct *tmInit(), *tmPop(), *tmDup(); |
113 |
< |
extern void tmClearHisto(), tmDone(); |
83 |
< |
extern int tmSetSpace(), tmCvColors(), tmCvColrs(); |
84 |
< |
extern int tmAddHisto(), tmComputeMapping(), tmMapPixels(); |
85 |
< |
extern int tmLoadPicture(), tmMapPicture(), tmPull(), tmPush(); |
112 |
> |
/* get the specific package's data */ |
113 |
> |
#define tmPkgData(t,i) ((t)->pd[i]!=NULL ? (t)->pd[i] : (*tmPkg[i]->Init)(t)) |
114 |
|
|
87 |
– |
#else |
115 |
|
|
116 |
+ |
/**** Library Function Calls ****/ |
117 |
+ |
|
118 |
+ |
|
119 |
|
extern struct tmStruct * |
120 |
|
tmInit(int flags, RGBPRIMP monpri, double gamval); |
121 |
|
/* |
146 |
|
*/ |
147 |
|
|
148 |
|
extern int |
119 |
– |
tmCvColors(TMbright *ls, BYTE *cs, COLOR *scan, int len); |
120 |
– |
/* |
121 |
– |
Convert RGB/XYZ float scanline to encoded luminance and chrominance. |
122 |
– |
|
123 |
– |
ls - returned encoded luminance values. |
124 |
– |
cs - returned encoded chrominance values (Note 2). |
125 |
– |
scan - input scanline. |
126 |
– |
len - scanline length. |
127 |
– |
|
128 |
– |
returns - 0 on success, TM_E_* on error. |
129 |
– |
*/ |
130 |
– |
|
131 |
– |
extern int |
132 |
– |
tmCvColrs(TMbright *ls, BYTE *cs, COLR *scan, int len); |
133 |
– |
/* |
134 |
– |
Convert RGBE/XYZE scanline to encoded luminance and chrominance. |
135 |
– |
|
136 |
– |
ls - returned encoded luminance values. |
137 |
– |
cs - returned encoded chrominance values (Note 2). |
138 |
– |
scan - input scanline. |
139 |
– |
len - scanline length. |
140 |
– |
|
141 |
– |
returns - 0 on success, TM_E_* on error. |
142 |
– |
*/ |
143 |
– |
|
144 |
– |
extern int |
149 |
|
tmAddHisto(TMbright *ls, int len, int wt); |
150 |
|
/* |
151 |
|
Add brightness values to current histogram. |
158 |
|
*/ |
159 |
|
|
160 |
|
extern int |
161 |
+ |
tmFixedMapping(double expmult, double gamval); |
162 |
+ |
/* |
163 |
+ |
Assign a fixed, linear tone-mapping using the given multiplier, |
164 |
+ |
which is the ratio of maximum output to uncalibrated input. |
165 |
+ |
This mapping will be used in subsequent calls to tmMapPixels() |
166 |
+ |
until a new tone mapping is computed. |
167 |
+ |
Only the min. and max. values are used from the histogram. |
168 |
+ |
|
169 |
+ |
expmult - the fixed exposure multiplier to use. |
170 |
+ |
gamval - display gamma response (0. for default). |
171 |
+ |
returns - 0 on success, TM_E_* on error. |
172 |
+ |
*/ |
173 |
+ |
|
174 |
+ |
extern int |
175 |
|
tmComputeMapping(double gamval, double Lddyn, double Ldmax); |
176 |
|
/* |
177 |
< |
Compute tone mapping function. |
177 |
> |
Compute tone mapping function from the current histogram. |
178 |
> |
This mapping will be used in subsequent calls to tmMapPixels() |
179 |
> |
until a new tone mapping is computed. |
180 |
> |
I.e., calls to tmAddHisto() have no immediate effect. |
181 |
|
|
182 |
|
gamval - display gamma response (0. for default). |
183 |
|
Lddyn - the display's dynamic range (0. for default). |
199 |
|
returns - 0 on success, TM_E_* on failure. |
200 |
|
*/ |
201 |
|
|
181 |
– |
extern int |
182 |
– |
tmLoadPicture(TMbright **lpp, BYTE **cpp, int *xp, int *yp, |
183 |
– |
char *fname, FILE *fp); |
184 |
– |
/* |
185 |
– |
Load Radiance picture and convert to tone mapping representation. |
186 |
– |
Calls tmSetSpace() to calibrate input color space. |
187 |
– |
|
188 |
– |
lpp - returned array of encoded luminances, English ordering. |
189 |
– |
cpp - returned array of encoded chrominances (Note 2). |
190 |
– |
xp, yp - returned picture dimensions. |
191 |
– |
fname - picture file name. |
192 |
– |
fp - pointer to open file (Note 3). |
193 |
– |
|
194 |
– |
returns - 0 on success, TM_E_* on failure. |
195 |
– |
*/ |
196 |
– |
|
197 |
– |
extern int |
198 |
– |
tmMapPicture(BYTE **psp, int *xp, int *yp, int flags, |
199 |
– |
RGBPRIMP monpri, double gamval, double Lddyn, double Ldmax, |
200 |
– |
char *fname, FILE *fp); |
201 |
– |
/* |
202 |
– |
Load and apply tone mapping to Radiance picture. |
203 |
– |
Stack is restored to its original state upon return. |
204 |
– |
If fp is TM_GETFILE and (flags&TM_F_UNIMPL)!=0, tmMapPicture() |
205 |
– |
calls pcond to perform the actual conversion, which takes |
206 |
– |
longer but gives access to all the TM_F_* features. |
207 |
– |
|
208 |
– |
psp - returned array of tone mapped pixels, English ordering. |
209 |
– |
xp, yp - returned picture dimensions. |
210 |
– |
flags - TM_F_* flags indicating what is to be done. |
211 |
– |
monpri - display monitor primaries (Note 1). |
212 |
– |
gamval - display gamma response. |
213 |
– |
Lddyn - the display's dynamic range (0. for default). |
214 |
– |
Ldmax - maximum display luminance in cd/m^2 (0. for default). |
215 |
– |
fname - picture file name. |
216 |
– |
fp - pointer to open file (Note 3). |
217 |
– |
|
218 |
– |
returns - 0 on success, TM_E_* on failure. |
219 |
– |
*/ |
220 |
– |
|
202 |
|
extern struct tmStruct * |
203 |
|
tmPop(void); |
204 |
|
/* |
247 |
|
tms - tone mapping structure to free. |
248 |
|
*/ |
249 |
|
|
250 |
< |
#endif |
251 |
< |
|
250 |
> |
extern int |
251 |
> |
tmCvColors(TMbright *ls, BYTE *cs, COLOR *scan, int len); |
252 |
> |
/* |
253 |
> |
Convert RGB/XYZ float scanline to encoded luminance and chrominance. |
254 |
> |
|
255 |
> |
ls - returned encoded luminance values. |
256 |
> |
cs - returned encoded chrominance values (Note 2). |
257 |
> |
scan - input scanline. |
258 |
> |
len - scanline length. |
259 |
> |
|
260 |
> |
returns - 0 on success, TM_E_* on error. |
261 |
> |
*/ |
262 |
> |
|
263 |
> |
extern int |
264 |
> |
tmCvGrays(TMbright *ls, float *scan, int len); |
265 |
> |
/* |
266 |
> |
Convert gray float scanline to encoded luminance. |
267 |
> |
|
268 |
> |
ls - returned encoded luminance values. |
269 |
> |
scan - input scanline. |
270 |
> |
len - scanline length. |
271 |
> |
|
272 |
> |
returns - 0 on success, TM_E_* on error. |
273 |
> |
*/ |
274 |
> |
|
275 |
> |
extern int |
276 |
> |
tmCvColrs(TMbright *ls, BYTE *cs, COLR *scan, int len); |
277 |
> |
/* |
278 |
> |
Convert RGBE/XYZE scanline to encoded luminance and chrominance. |
279 |
> |
|
280 |
> |
ls - returned encoded luminance values. |
281 |
> |
cs - returned encoded chrominance values (Note 2). |
282 |
> |
scan - input scanline. |
283 |
> |
len - scanline length. |
284 |
> |
|
285 |
> |
returns - 0 on success, TM_E_* on error. |
286 |
> |
*/ |
287 |
> |
|
288 |
> |
extern int |
289 |
> |
tmLoadPicture(TMbright **lpp, BYTE **cpp, int *xp, int *yp, |
290 |
> |
char *fname, FILE *fp); |
291 |
> |
/* |
292 |
> |
Load Radiance picture and convert to tone mapping representation. |
293 |
> |
Memory for the luminance and chroma arrays is allocated using |
294 |
> |
malloc(3), and should be freed with free(3) when no longer needed. |
295 |
> |
Calls tmSetSpace() to calibrate input color space. |
296 |
> |
|
297 |
> |
lpp - returned array of encoded luminances, picture ordering. |
298 |
> |
cpp - returned array of encoded chrominances (Note 2). |
299 |
> |
xp, yp - returned picture dimensions. |
300 |
> |
fname - picture file name. |
301 |
> |
fp - pointer to open file (Note 3). |
302 |
> |
|
303 |
> |
returns - 0 on success, TM_E_* on failure. |
304 |
> |
*/ |
305 |
> |
|
306 |
> |
extern int |
307 |
> |
tmMapPicture(BYTE **psp, int *xp, int *yp, int flags, |
308 |
> |
RGBPRIMP monpri, double gamval, double Lddyn, double Ldmax, |
309 |
> |
char *fname, FILE *fp); |
310 |
> |
/* |
311 |
> |
Load and apply tone mapping to Radiance picture. |
312 |
> |
Stack is restored to its original state upon return. |
313 |
> |
If fp is TM_GETFILE and (flags&TM_F_UNIMPL)!=0, tmMapPicture() |
314 |
> |
calls pcond to perform the actual conversion, which takes |
315 |
> |
longer but gives access to all the TM_F_* features. |
316 |
> |
Memory for the final pixel array is allocated using malloc(3), |
317 |
> |
and should be freed with free(3) when it is no longer needed. |
318 |
> |
|
319 |
> |
psp - returned array of tone mapped pixels, picture ordering. |
320 |
> |
xp, yp - returned picture dimensions. |
321 |
> |
flags - TM_F_* flags indicating what is to be done. |
322 |
> |
monpri - display monitor primaries (Note 1). |
323 |
> |
gamval - display gamma response. |
324 |
> |
Lddyn - the display's dynamic range (0. for default). |
325 |
> |
Ldmax - maximum display luminance in cd/m^2 (0. for default). |
326 |
> |
fname - picture file name. |
327 |
> |
fp - pointer to open file (Note 3). |
328 |
> |
|
329 |
> |
returns - 0 on success, TM_E_* on failure. |
330 |
> |
*/ |
331 |
> |
|
332 |
> |
|
333 |
> |
|
334 |
|
/**** Notes ****/ |
335 |
|
/* |
336 |
|
General: |
339 |
|
pixel values to chroma and luminance encodings, which can |
340 |
|
be passed to tmAddHisto() to put into the tone mapping histogram. |
341 |
|
This histogram is then used along with the display parameters |
342 |
< |
by tmComputMapping() to compute the luminance mapping function. |
342 |
> |
by tmComputeMapping() to compute the luminance mapping function. |
343 |
|
(Colors are tone-mapped as they are converted if TM_F_MESOPIC |
344 |
|
is set.) The encoded chroma and luminance values may then be |
345 |
|
passed to tmMapPixels() to apply the computed tone mapping in |
401 |
|
function will open the file, read its contents and close it |
402 |
|
before returning, whether or not an error was encountered. |
403 |
|
*/ |
404 |
+ |
|
405 |
+ |
#ifdef __cplusplus |
406 |
+ |
} |
407 |
+ |
#endif |
408 |
+ |
#endif /* _RAD_TONEMAP_H_ */ |
409 |
+ |
|