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 |
|
*/ |
8 |
– |
/* required non-system header files */ |
9 |
– |
#include "color.h" |
7 |
|
|
8 |
+ |
/* ==================================================================== |
9 |
+ |
* The Radiance Software License, Version 1.0 |
10 |
+ |
* |
11 |
+ |
* Copyright (c) 1990 - 2002 The Regents of the University of California, |
12 |
+ |
* through Lawrence Berkeley National Laboratory. All rights reserved. |
13 |
+ |
* |
14 |
+ |
* Redistribution and use in source and binary forms, with or without |
15 |
+ |
* modification, are permitted provided that the following conditions |
16 |
+ |
* are met: |
17 |
+ |
* |
18 |
+ |
* 1. Redistributions of source code must retain the above copyright |
19 |
+ |
* notice, this list of conditions and the following disclaimer. |
20 |
+ |
* |
21 |
+ |
* 2. Redistributions in binary form must reproduce the above copyright |
22 |
+ |
* notice, this list of conditions and the following disclaimer in |
23 |
+ |
* the documentation and/or other materials provided with the |
24 |
+ |
* distribution. |
25 |
+ |
* |
26 |
+ |
* 3. The end-user documentation included with the redistribution, |
27 |
+ |
* if any, must include the following acknowledgment: |
28 |
+ |
* "This product includes Radiance software |
29 |
+ |
* (http://radsite.lbl.gov/) |
30 |
+ |
* developed by the Lawrence Berkeley National Laboratory |
31 |
+ |
* (http://www.lbl.gov/)." |
32 |
+ |
* Alternately, this acknowledgment may appear in the software itself, |
33 |
+ |
* if and wherever such third-party acknowledgments normally appear. |
34 |
+ |
* |
35 |
+ |
* 4. The names "Radiance," "Lawrence Berkeley National Laboratory" |
36 |
+ |
* and "The Regents of the University of California" must |
37 |
+ |
* not be used to endorse or promote products derived from this |
38 |
+ |
* software without prior written permission. For written |
39 |
+ |
* permission, please contact [email protected]. |
40 |
+ |
* |
41 |
+ |
* 5. Products derived from this software may not be called "Radiance", |
42 |
+ |
* nor may "Radiance" appear in their name, without prior written |
43 |
+ |
* permission of Lawrence Berkeley National Laboratory. |
44 |
+ |
* |
45 |
+ |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED |
46 |
+ |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
47 |
+ |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
48 |
+ |
* DISCLAIMED. IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR |
49 |
+ |
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
50 |
+ |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
51 |
+ |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
52 |
+ |
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
53 |
+ |
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
54 |
+ |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
55 |
+ |
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
56 |
+ |
* SUCH DAMAGE. |
57 |
+ |
* ==================================================================== |
58 |
+ |
* |
59 |
+ |
* This software consists of voluntary contributions made by many |
60 |
+ |
* individuals on behalf of Lawrence Berkeley National Laboratory. For more |
61 |
+ |
* information on Lawrence Berkeley National Laboratory, please see |
62 |
+ |
* <http://www.lbl.gov/>. |
63 |
+ |
*/ |
64 |
|
|
65 |
+ |
#ifdef __cplusplus |
66 |
+ |
extern "C" { |
67 |
+ |
#endif |
68 |
+ |
|
69 |
|
/**** Argument Macros ****/ |
70 |
|
/* Flags of what to do */ |
71 |
|
#define TM_F_HCONTR 01 /* human contrast sensitivity */ |
89 |
|
#define TM_NOCHROMP (BYTE **)NULL /* indicate no chrominances */ |
90 |
|
#define TM_GETFILE (FILE *)NULL /* indicate file must be opened */ |
91 |
|
|
92 |
+ |
|
93 |
|
/**** Error Return Values ****/ |
94 |
|
|
95 |
|
#define TM_E_OK 0 /* normal return status */ |
106 |
|
|
107 |
|
#define TM_BRTSCALE 128 /* brightness scale factor (integer) */ |
108 |
|
|
109 |
+ |
#define TM_NOBRT (-1<<15) /* bogus brightness value */ |
110 |
+ |
#define TM_NOLUM (1e-17) /* ridiculously small luminance */ |
111 |
+ |
|
112 |
|
#define TM_MAXPKG 8 /* maximum number of color formats */ |
113 |
|
|
114 |
|
|
119 |
|
#endif |
120 |
|
|
121 |
|
extern char *tmErrorMessage[]; /* error messages */ |
122 |
+ |
extern int tmLastError; /* last error incurred by library */ |
123 |
+ |
extern char *tmLastFunction; /* error-generating function name */ |
124 |
|
|
125 |
|
typedef short TMbright; /* encoded luminance type */ |
126 |
|
|
134 |
|
RGBPRIMP inppri; /* current input primaries */ |
135 |
|
double inpsf; /* current input scalefactor */ |
136 |
|
COLORMAT cmat; /* color conversion matrix */ |
137 |
< |
TMbright brmin, brmax; /* input brightness limits */ |
137 |
> |
TMbright hbrmin, hbrmax; /* histogram brightness limits */ |
138 |
|
int *histo; /* input histogram */ |
139 |
+ |
TMbright mbrmin, mbrmax; /* mapped brightness limits */ |
140 |
|
unsigned short *lumap; /* computed luminance map */ |
141 |
|
struct tmStruct *tmprev; /* previous tone mapping */ |
142 |
|
MEM_PTR pd[TM_MAXPKG]; /* pointers to private data */ |
152 |
|
#else |
153 |
|
struct tmPackage { |
154 |
|
MEM_PTR (*Init)(struct tmStruct *tms); |
155 |
< |
int (*NewSpace)(struct tmStruct *tms); |
155 |
> |
void (*NewSpace)(struct tmStruct *tms); |
156 |
|
void (*Free)(MEM_PTR pp); |
157 |
|
}; |
158 |
|
#endif |
164 |
|
/**** Useful Macros ****/ |
165 |
|
|
166 |
|
/* compute luminance from encoded value */ |
167 |
< |
#define tmLuminance(li) exp((li)/(double)TM_BRTSCALE) |
167 |
> |
#define tmLuminance(li) exp((li)*(1./TM_BRTSCALE)) |
168 |
|
|
169 |
|
/* does tone mapping need color matrix? */ |
170 |
|
#define tmNeedMatrix(t) ((t)->monpri != (t)->inppri) |
182 |
|
#ifdef NOPROTO |
183 |
|
|
184 |
|
extern struct tmStruct *tmInit(), *tmPop(), *tmDup(); |
185 |
+ |
extern int tmSetSpace(), tmPull(), tmPush(); |
186 |
|
extern void tmClearHisto(), tmDone(); |
187 |
< |
extern int tmSetSpace(), tmCvColors(), tmCvColrs(); |
188 |
< |
extern int tmAddHisto(), tmComputeMapping(), tmMapPixels(); |
189 |
< |
extern int tmLoadPicture(), tmMapPicture(), tmPull(), tmPush(); |
187 |
> |
extern int tmAddHisto(); |
188 |
> |
extern int tmFixedMapping(), tmComputeMapping(), tmMapPixels(); |
189 |
> |
extern int tmCvColors(), tmCvGrays(), tmCvColrs(); |
190 |
> |
extern int tmLoadPicture(), tmMapPicture(); |
191 |
|
|
192 |
|
#else |
193 |
|
|
221 |
|
*/ |
222 |
|
|
223 |
|
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 |
224 |
|
tmAddHisto(TMbright *ls, int len, int wt); |
225 |
|
/* |
226 |
|
Add brightness values to current histogram. |
233 |
|
*/ |
234 |
|
|
235 |
|
extern int |
236 |
+ |
tmFixedMapping(double expmult, double gamval); |
237 |
+ |
/* |
238 |
+ |
Assign a fixed, linear tone-mapping using the given multiplier, |
239 |
+ |
which is the ratio of maximum output to uncalibrated input. |
240 |
+ |
This mapping will be used in subsequent calls to tmMapPixels() |
241 |
+ |
until a new tone mapping is computed. |
242 |
+ |
Only the min. and max. values are used from the histogram. |
243 |
+ |
|
244 |
+ |
expmult - the fixed exposure multiplier to use. |
245 |
+ |
gamval - display gamma response (0. for default). |
246 |
+ |
returns - 0 on success, TM_E_* on error. |
247 |
+ |
*/ |
248 |
+ |
|
249 |
+ |
extern int |
250 |
|
tmComputeMapping(double gamval, double Lddyn, double Ldmax); |
251 |
|
/* |
252 |
< |
Compute tone mapping function. |
252 |
> |
Compute tone mapping function from the current histogram. |
253 |
> |
This mapping will be used in subsequent calls to tmMapPixels() |
254 |
> |
until a new tone mapping is computed. |
255 |
> |
I.e., calls to tmAddHisto() have no immediate effect. |
256 |
|
|
257 |
|
gamval - display gamma response (0. for default). |
258 |
|
Lddyn - the display's dynamic range (0. for default). |
274 |
|
returns - 0 on success, TM_E_* on failure. |
275 |
|
*/ |
276 |
|
|
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 |
– |
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). |
231 |
– |
xp, yp - returned picture dimensions. |
232 |
– |
fname - picture file name. |
233 |
– |
fp - pointer to open file (Note 3). |
234 |
– |
|
235 |
– |
returns - 0 on success, TM_E_* on failure. |
236 |
– |
*/ |
237 |
– |
|
238 |
– |
extern int |
239 |
– |
tmMapPicture(BYTE **psp, int *xp, int *yp, int flags, |
240 |
– |
RGBPRIMP monpri, double gamval, double Lddyn, double Ldmax, |
241 |
– |
char *fname, FILE *fp); |
242 |
– |
/* |
243 |
– |
Load and apply tone mapping to Radiance picture. |
244 |
– |
Stack is restored to its original state upon return. |
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. |
253 |
– |
flags - TM_F_* flags indicating what is to be done. |
254 |
– |
monpri - display monitor primaries (Note 1). |
255 |
– |
gamval - display gamma response. |
256 |
– |
Lddyn - the display's dynamic range (0. for default). |
257 |
– |
Ldmax - maximum display luminance in cd/m^2 (0. for default). |
258 |
– |
fname - picture file name. |
259 |
– |
fp - pointer to open file (Note 3). |
260 |
– |
|
261 |
– |
returns - 0 on success, TM_E_* on failure. |
262 |
– |
*/ |
263 |
– |
|
277 |
|
extern struct tmStruct * |
278 |
|
tmPop(void); |
279 |
|
/* |
322 |
|
tms - tone mapping structure to free. |
323 |
|
*/ |
324 |
|
|
325 |
+ |
extern int |
326 |
+ |
tmCvColors(TMbright *ls, BYTE *cs, COLOR *scan, int len); |
327 |
+ |
/* |
328 |
+ |
Convert RGB/XYZ float scanline to encoded luminance and chrominance. |
329 |
+ |
|
330 |
+ |
ls - returned encoded luminance values. |
331 |
+ |
cs - returned encoded chrominance values (Note 2). |
332 |
+ |
scan - input scanline. |
333 |
+ |
len - scanline length. |
334 |
+ |
|
335 |
+ |
returns - 0 on success, TM_E_* on error. |
336 |
+ |
*/ |
337 |
+ |
|
338 |
+ |
extern int |
339 |
+ |
tmCvGrays(TMbright *ls, float *scan, int len); |
340 |
+ |
/* |
341 |
+ |
Convert gray float scanline to encoded luminance. |
342 |
+ |
|
343 |
+ |
ls - returned encoded luminance values. |
344 |
+ |
scan - input scanline. |
345 |
+ |
len - scanline length. |
346 |
+ |
|
347 |
+ |
returns - 0 on success, TM_E_* on error. |
348 |
+ |
*/ |
349 |
+ |
|
350 |
+ |
extern int |
351 |
+ |
tmCvColrs(TMbright *ls, BYTE *cs, COLR *scan, int len); |
352 |
+ |
/* |
353 |
+ |
Convert RGBE/XYZE scanline to encoded luminance and chrominance. |
354 |
+ |
|
355 |
+ |
ls - returned encoded luminance values. |
356 |
+ |
cs - returned encoded chrominance values (Note 2). |
357 |
+ |
scan - input scanline. |
358 |
+ |
len - scanline length. |
359 |
+ |
|
360 |
+ |
returns - 0 on success, TM_E_* on error. |
361 |
+ |
*/ |
362 |
+ |
|
363 |
+ |
extern int |
364 |
+ |
tmLoadPicture(TMbright **lpp, BYTE **cpp, int *xp, int *yp, |
365 |
+ |
char *fname, FILE *fp); |
366 |
+ |
/* |
367 |
+ |
Load Radiance picture and convert to tone mapping representation. |
368 |
+ |
Memory for the luminance and chroma arrays is allocated using |
369 |
+ |
malloc(3), and should be freed with free(3) when no longer needed. |
370 |
+ |
Calls tmSetSpace() to calibrate input color space. |
371 |
+ |
|
372 |
+ |
lpp - returned array of encoded luminances, picture ordering. |
373 |
+ |
cpp - returned array of encoded chrominances (Note 2). |
374 |
+ |
xp, yp - returned picture dimensions. |
375 |
+ |
fname - picture file name. |
376 |
+ |
fp - pointer to open file (Note 3). |
377 |
+ |
|
378 |
+ |
returns - 0 on success, TM_E_* on failure. |
379 |
+ |
*/ |
380 |
+ |
|
381 |
+ |
extern int |
382 |
+ |
tmMapPicture(BYTE **psp, int *xp, int *yp, int flags, |
383 |
+ |
RGBPRIMP monpri, double gamval, double Lddyn, double Ldmax, |
384 |
+ |
char *fname, FILE *fp); |
385 |
+ |
/* |
386 |
+ |
Load and apply tone mapping to Radiance picture. |
387 |
+ |
Stack is restored to its original state upon return. |
388 |
+ |
If fp is TM_GETFILE and (flags&TM_F_UNIMPL)!=0, tmMapPicture() |
389 |
+ |
calls pcond to perform the actual conversion, which takes |
390 |
+ |
longer but gives access to all the TM_F_* features. |
391 |
+ |
Memory for the final pixel array is allocated using malloc(3), |
392 |
+ |
and should be freed with free(3) when it is no longer needed. |
393 |
+ |
|
394 |
+ |
psp - returned array of tone mapped pixels, picture ordering. |
395 |
+ |
xp, yp - returned picture dimensions. |
396 |
+ |
flags - TM_F_* flags indicating what is to be done. |
397 |
+ |
monpri - display monitor primaries (Note 1). |
398 |
+ |
gamval - display gamma response. |
399 |
+ |
Lddyn - the display's dynamic range (0. for default). |
400 |
+ |
Ldmax - maximum display luminance in cd/m^2 (0. for default). |
401 |
+ |
fname - picture file name. |
402 |
+ |
fp - pointer to open file (Note 3). |
403 |
+ |
|
404 |
+ |
returns - 0 on success, TM_E_* on failure. |
405 |
+ |
*/ |
406 |
+ |
|
407 |
|
#endif |
408 |
|
|
409 |
|
|
477 |
|
function will open the file, read its contents and close it |
478 |
|
before returning, whether or not an error was encountered. |
479 |
|
*/ |
480 |
+ |
|
481 |
+ |
#ifdef __cplusplus |
482 |
+ |
} |
483 |
+ |
#endif |