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 |
+ |
#include "tifftypes.h" |
14 |
|
|
15 |
|
/**** Argument Macros ****/ |
16 |
|
/* Flags of what to do */ |
35 |
|
#define TM_NOCHROMP (BYTE **)NULL /* indicate no chrominances */ |
36 |
|
#define TM_GETFILE (FILE *)NULL /* indicate file must be opened */ |
37 |
|
|
38 |
+ |
|
39 |
|
/**** Error Return Values ****/ |
40 |
|
|
41 |
|
#define TM_E_OK 0 /* normal return status */ |
52 |
|
|
53 |
|
#define TM_BRTSCALE 128 /* brightness scale factor (integer) */ |
54 |
|
|
55 |
+ |
#define TM_NOBRT (-1<<15) /* bogus brightness value */ |
56 |
+ |
#define TM_NOLUM (1e-17) /* ridiculously small luminance */ |
57 |
+ |
|
58 |
|
#define TM_MAXPKG 8 /* maximum number of color formats */ |
59 |
|
|
60 |
|
|
65 |
|
#endif |
66 |
|
|
67 |
|
extern char *tmErrorMessage[]; /* error messages */ |
68 |
+ |
extern int tmLastError; /* last error incurred by library */ |
69 |
+ |
extern char *tmLastFunction; /* error-generating function name */ |
70 |
|
|
71 |
|
typedef short TMbright; /* encoded luminance type */ |
72 |
|
|
80 |
|
RGBPRIMP inppri; /* current input primaries */ |
81 |
|
double inpsf; /* current input scalefactor */ |
82 |
|
COLORMAT cmat; /* color conversion matrix */ |
83 |
< |
TMbright brmin, brmax; /* input brightness limits */ |
83 |
> |
TMbright hbrmin, hbrmax; /* histogram brightness limits */ |
84 |
|
int *histo; /* input histogram */ |
85 |
+ |
TMbright mbrmin, mbrmax; /* mapped brightness limits */ |
86 |
|
unsigned short *lumap; /* computed luminance map */ |
87 |
|
struct tmStruct *tmprev; /* previous tone mapping */ |
88 |
|
MEM_PTR pd[TM_MAXPKG]; /* pointers to private data */ |
89 |
|
} *tmTop; /* current tone mapping stack */ |
90 |
|
|
91 |
|
/* conversion package functions */ |
82 |
– |
#ifdef NOPROTO |
92 |
|
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 { |
93 |
|
MEM_PTR (*Init)(struct tmStruct *tms); |
94 |
< |
int (*NewSpace)(struct tmStruct *tms); |
94 |
> |
void (*NewSpace)(struct tmStruct *tms); |
95 |
|
void (*Free)(MEM_PTR pp); |
96 |
|
}; |
94 |
– |
#endif |
97 |
|
/* our list of conversion packages */ |
98 |
|
extern struct tmPackage *tmPkg[TM_MAXPKG]; |
99 |
|
extern int tmNumPkgs; /* number of registered packages */ |
102 |
|
/**** Useful Macros ****/ |
103 |
|
|
104 |
|
/* compute luminance from encoded value */ |
105 |
< |
#define tmLuminance(li) exp((li)/(double)TM_BRTSCALE) |
105 |
> |
#define tmLuminance(li) exp((li)*(1./TM_BRTSCALE)) |
106 |
|
|
107 |
|
/* does tone mapping need color matrix? */ |
108 |
|
#define tmNeedMatrix(t) ((t)->monpri != (t)->inppri) |
117 |
|
|
118 |
|
/**** Library Function Calls ****/ |
119 |
|
|
118 |
– |
#ifdef NOPROTO |
120 |
|
|
120 |
– |
extern struct tmStruct *tmInit(), *tmPop(), *tmDup(); |
121 |
– |
extern void tmClearHisto(), tmDone(); |
122 |
– |
extern int tmSetSpace(), tmCvColors(), tmCvColrs(); |
123 |
– |
extern int tmAddHisto(), tmComputeMapping(), tmMapPixels(); |
124 |
– |
extern int tmLoadPicture(), tmMapPicture(), tmPull(), tmPush(); |
125 |
– |
|
126 |
– |
#else |
127 |
– |
|
121 |
|
extern struct tmStruct * |
122 |
|
tmInit(int flags, RGBPRIMP monpri, double gamval); |
123 |
|
/* |
148 |
|
*/ |
149 |
|
|
150 |
|
extern int |
158 |
– |
tmCvColors(TMbright *ls, BYTE *cs, COLOR *scan, int len); |
159 |
– |
/* |
160 |
– |
Convert RGB/XYZ float scanline to encoded luminance and chrominance. |
161 |
– |
|
162 |
– |
ls - returned encoded luminance values. |
163 |
– |
cs - returned encoded chrominance values (Note 2). |
164 |
– |
scan - input scanline. |
165 |
– |
len - scanline length. |
166 |
– |
|
167 |
– |
returns - 0 on success, TM_E_* on error. |
168 |
– |
*/ |
169 |
– |
|
170 |
– |
extern int |
171 |
– |
tmCvColrs(TMbright *ls, BYTE *cs, COLR *scan, int len); |
172 |
– |
/* |
173 |
– |
Convert RGBE/XYZE scanline to encoded luminance and chrominance. |
174 |
– |
|
175 |
– |
ls - returned encoded luminance values. |
176 |
– |
cs - returned encoded chrominance values (Note 2). |
177 |
– |
scan - input scanline. |
178 |
– |
len - scanline length. |
179 |
– |
|
180 |
– |
returns - 0 on success, TM_E_* on error. |
181 |
– |
*/ |
182 |
– |
|
183 |
– |
extern int |
151 |
|
tmAddHisto(TMbright *ls, int len, int wt); |
152 |
|
/* |
153 |
|
Add brightness values to current histogram. |
160 |
|
*/ |
161 |
|
|
162 |
|
extern int |
163 |
+ |
tmFixedMapping(double expmult, double gamval); |
164 |
+ |
/* |
165 |
+ |
Assign a fixed, linear tone-mapping using the given multiplier, |
166 |
+ |
which is the ratio of maximum output to uncalibrated input. |
167 |
+ |
This mapping will be used in subsequent calls to tmMapPixels() |
168 |
+ |
until a new tone mapping is computed. |
169 |
+ |
Only the min. and max. values are used from the histogram. |
170 |
+ |
|
171 |
+ |
expmult - the fixed exposure multiplier to use. |
172 |
+ |
gamval - display gamma response (0. for default). |
173 |
+ |
returns - 0 on success, TM_E_* on error. |
174 |
+ |
*/ |
175 |
+ |
|
176 |
+ |
extern int |
177 |
|
tmComputeMapping(double gamval, double Lddyn, double Ldmax); |
178 |
|
/* |
179 |
< |
Compute tone mapping function. |
179 |
> |
Compute tone mapping function from the current histogram. |
180 |
> |
This mapping will be used in subsequent calls to tmMapPixels() |
181 |
> |
until a new tone mapping is computed. |
182 |
> |
I.e., calls to tmAddHisto() have no immediate effect. |
183 |
|
|
184 |
|
gamval - display gamma response (0. for default). |
185 |
|
Lddyn - the display's dynamic range (0. for default). |
201 |
|
returns - 0 on success, TM_E_* on failure. |
202 |
|
*/ |
203 |
|
|
220 |
– |
extern int |
221 |
– |
tmLoadPicture(TMbright **lpp, BYTE **cpp, int *xp, int *yp, |
222 |
– |
char *fname, FILE *fp); |
223 |
– |
/* |
224 |
– |
Load Radiance picture and convert to tone mapping representation. |
225 |
– |
Calls tmSetSpace() to calibrate input color space. |
226 |
– |
|
227 |
– |
lpp - returned array of encoded luminances, English ordering. |
228 |
– |
cpp - returned array of encoded chrominances (Note 2). |
229 |
– |
xp, yp - returned picture dimensions. |
230 |
– |
fname - picture file name. |
231 |
– |
fp - pointer to open file (Note 3). |
232 |
– |
|
233 |
– |
returns - 0 on success, TM_E_* on failure. |
234 |
– |
*/ |
235 |
– |
|
236 |
– |
extern int |
237 |
– |
tmMapPicture(BYTE **psp, int *xp, int *yp, int flags, |
238 |
– |
RGBPRIMP monpri, double gamval, double Lddyn, double Ldmax, |
239 |
– |
char *fname, FILE *fp); |
240 |
– |
/* |
241 |
– |
Load and apply tone mapping to Radiance picture. |
242 |
– |
Stack is restored to its original state upon return. |
243 |
– |
If fp is TM_GETFILE and (flags&TM_F_UNIMPL)!=0, tmMapPicture() |
244 |
– |
calls pcond to perform the actual conversion, which takes |
245 |
– |
longer but gives access to all the TM_F_* features. |
246 |
– |
|
247 |
– |
psp - returned array of tone mapped pixels, English ordering. |
248 |
– |
xp, yp - returned picture dimensions. |
249 |
– |
flags - TM_F_* flags indicating what is to be done. |
250 |
– |
monpri - display monitor primaries (Note 1). |
251 |
– |
gamval - display gamma response. |
252 |
– |
Lddyn - the display's dynamic range (0. for default). |
253 |
– |
Ldmax - maximum display luminance in cd/m^2 (0. for default). |
254 |
– |
fname - picture file name. |
255 |
– |
fp - pointer to open file (Note 3). |
256 |
– |
|
257 |
– |
returns - 0 on success, TM_E_* on failure. |
258 |
– |
*/ |
259 |
– |
|
204 |
|
extern struct tmStruct * |
205 |
|
tmPop(void); |
206 |
|
/* |
249 |
|
tms - tone mapping structure to free. |
250 |
|
*/ |
251 |
|
|
252 |
< |
#endif |
252 |
> |
extern int |
253 |
> |
tmCvColors(TMbright *ls, BYTE *cs, COLOR *scan, int len); |
254 |
> |
/* |
255 |
> |
Convert RGB/XYZ float scanline to encoded luminance and chrominance. |
256 |
|
|
257 |
+ |
ls - returned encoded luminance values. |
258 |
+ |
cs - returned encoded chrominance values (Note 2). |
259 |
+ |
scan - input scanline. |
260 |
+ |
len - scanline length. |
261 |
|
|
262 |
+ |
returns - 0 on success, TM_E_* on error. |
263 |
+ |
*/ |
264 |
+ |
|
265 |
+ |
extern int |
266 |
+ |
tmCvGrays(TMbright *ls, float *scan, int len); |
267 |
+ |
/* |
268 |
+ |
Convert gray float scanline to encoded luminance. |
269 |
+ |
|
270 |
+ |
ls - returned encoded luminance values. |
271 |
+ |
scan - input scanline. |
272 |
+ |
len - scanline length. |
273 |
+ |
|
274 |
+ |
returns - 0 on success, TM_E_* on error. |
275 |
+ |
*/ |
276 |
+ |
|
277 |
+ |
extern int |
278 |
+ |
tmCvColrs(TMbright *ls, BYTE *cs, COLR *scan, int len); |
279 |
+ |
/* |
280 |
+ |
Convert RGBE/XYZE scanline to encoded luminance and chrominance. |
281 |
+ |
|
282 |
+ |
ls - returned encoded luminance values. |
283 |
+ |
cs - returned encoded chrominance values (Note 2). |
284 |
+ |
scan - input scanline. |
285 |
+ |
len - scanline length. |
286 |
+ |
|
287 |
+ |
returns - 0 on success, TM_E_* on error. |
288 |
+ |
*/ |
289 |
+ |
|
290 |
+ |
extern int |
291 |
+ |
tmLoadPicture(TMbright **lpp, BYTE **cpp, int *xp, int *yp, |
292 |
+ |
char *fname, FILE *fp); |
293 |
+ |
/* |
294 |
+ |
Load Radiance picture and convert to tone mapping representation. |
295 |
+ |
Memory for the luminance and chroma arrays is allocated using |
296 |
+ |
malloc(3), and should be freed with free(3) when no longer needed. |
297 |
+ |
Calls tmSetSpace() to calibrate input color space. |
298 |
+ |
|
299 |
+ |
lpp - returned array of encoded luminances, picture ordering. |
300 |
+ |
cpp - returned array of encoded chrominances (Note 2). |
301 |
+ |
xp, yp - returned picture dimensions. |
302 |
+ |
fname - picture file name. |
303 |
+ |
fp - pointer to open file (Note 3). |
304 |
+ |
|
305 |
+ |
returns - 0 on success, TM_E_* on failure. |
306 |
+ |
*/ |
307 |
+ |
|
308 |
+ |
extern int |
309 |
+ |
tmMapPicture(BYTE **psp, int *xp, int *yp, int flags, |
310 |
+ |
RGBPRIMP monpri, double gamval, double Lddyn, double Ldmax, |
311 |
+ |
char *fname, FILE *fp); |
312 |
+ |
/* |
313 |
+ |
Load and apply tone mapping to Radiance picture. |
314 |
+ |
Stack is restored to its original state upon return. |
315 |
+ |
If fp is TM_GETFILE and (flags&TM_F_UNIMPL)!=0, tmMapPicture() |
316 |
+ |
calls pcond to perform the actual conversion, which takes |
317 |
+ |
longer but gives access to all the TM_F_* features. |
318 |
+ |
Memory for the final pixel array is allocated using malloc(3), |
319 |
+ |
and should be freed with free(3) when it is no longer needed. |
320 |
+ |
|
321 |
+ |
psp - returned array of tone mapped pixels, picture ordering. |
322 |
+ |
xp, yp - returned picture dimensions. |
323 |
+ |
flags - TM_F_* flags indicating what is to be done. |
324 |
+ |
monpri - display monitor primaries (Note 1). |
325 |
+ |
gamval - display gamma response. |
326 |
+ |
Lddyn - the display's dynamic range (0. for default). |
327 |
+ |
Ldmax - maximum display luminance in cd/m^2 (0. for default). |
328 |
+ |
fname - picture file name. |
329 |
+ |
fp - pointer to open file (Note 3). |
330 |
+ |
|
331 |
+ |
returns - 0 on success, TM_E_* on failure. |
332 |
+ |
*/ |
333 |
+ |
|
334 |
+ |
extern int |
335 |
+ |
tmCvRGB48(TMbright *ls, BYTE *cs, uint16 (*scan)[3], int len, double gv); |
336 |
+ |
/* |
337 |
+ |
Convert 48-bit RGB scanline to encoded luminance and chrominance. |
338 |
+ |
|
339 |
+ |
ls - returned encoded luminance values. |
340 |
+ |
cs - returned encoded chrominance values (Note 2). |
341 |
+ |
scan - input scanline. |
342 |
+ |
len - scanline length. |
343 |
+ |
gv - input gamma value. |
344 |
+ |
|
345 |
+ |
returns - 0 on success, TM_E_* on error. |
346 |
+ |
*/ |
347 |
+ |
|
348 |
+ |
extern int |
349 |
+ |
tmCvGray16(TMbright *ls, uint16 *scan, int len, double gv); |
350 |
+ |
/* |
351 |
+ |
Convert 16-bit gray scanline to encoded luminance. |
352 |
+ |
|
353 |
+ |
ls - returned encoded luminance values. |
354 |
+ |
scan - input scanline. |
355 |
+ |
len - scanline length. |
356 |
+ |
gv - input gamma value. |
357 |
+ |
|
358 |
+ |
returns - 0 on success, TM_E_* on error. |
359 |
+ |
*/ |
360 |
+ |
|
361 |
|
/**** Notes ****/ |
362 |
|
/* |
363 |
|
General: |
366 |
|
pixel values to chroma and luminance encodings, which can |
367 |
|
be passed to tmAddHisto() to put into the tone mapping histogram. |
368 |
|
This histogram is then used along with the display parameters |
369 |
< |
by tmComputMapping() to compute the luminance mapping function. |
369 |
> |
by tmComputeMapping() to compute the luminance mapping function. |
370 |
|
(Colors are tone-mapped as they are converted if TM_F_MESOPIC |
371 |
|
is set.) The encoded chroma and luminance values may then be |
372 |
|
passed to tmMapPixels() to apply the computed tone mapping in |
428 |
|
function will open the file, read its contents and close it |
429 |
|
before returning, whether or not an error was encountered. |
430 |
|
*/ |
431 |
+ |
|
432 |
+ |
#ifdef __cplusplus |
433 |
+ |
} |
434 |
+ |
#endif |
435 |
+ |
#endif /* _RAD_TONEMAP_H_ */ |
436 |
+ |
|