1 |
< |
/* Copyright (c) 1997 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
2 |
|
|
3 |
< |
/* SCCSid "$SunId$ LBL" */ |
3 |
> |
/* SCCSid "$SunId$ SGI" */ |
4 |
|
|
5 |
|
/* |
6 |
|
* Header file for tone mapping functions. |
7 |
+ |
* |
8 |
+ |
* Include after "color.h" |
9 |
|
*/ |
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 */ |
32 |
|
#define TM_NOCHROMP (BYTE **)NULL /* indicate no chrominances */ |
33 |
|
#define TM_GETFILE (FILE *)NULL /* indicate file must be opened */ |
34 |
|
|
35 |
+ |
|
36 |
|
/**** Error Return Values ****/ |
37 |
|
|
38 |
|
#define TM_E_OK 0 /* normal return status */ |
41 |
|
#define TM_E_TMINVAL 3 /* no valid tone mapping */ |
42 |
|
#define TM_E_TMFAIL 4 /* cannot compute tone mapping */ |
43 |
|
#define TM_E_BADFILE 5 /* cannot open or understand file */ |
44 |
+ |
#define TM_E_CODERR1 6 /* code consistency error 1 */ |
45 |
+ |
#define TM_E_CODERR2 7 /* code consistency error 2 */ |
46 |
|
|
47 |
+ |
|
48 |
|
/**** Conversion Constants and Table Sizes ****/ |
49 |
|
|
50 |
|
#define TM_BRTSCALE 128 /* brightness scale factor (integer) */ |
51 |
|
|
52 |
< |
#define TM_GAMTSZ 1024 /* gamma lookup table size */ |
52 |
> |
#define TM_MAXPKG 8 /* maximum number of color formats */ |
53 |
|
|
49 |
– |
/**** Global Data Structures ****/ |
54 |
|
|
55 |
+ |
/**** Global Data Types and Structures ****/ |
56 |
+ |
|
57 |
+ |
#ifndef MEM_PTR |
58 |
+ |
#define MEM_PTR void * |
59 |
+ |
#endif |
60 |
+ |
|
61 |
|
extern char *tmErrorMessage[]; /* error messages */ |
62 |
+ |
extern int tmLastError; /* last error incurred by library */ |
63 |
+ |
extern char *tmLastFunction; /* error-generating function name */ |
64 |
|
|
65 |
|
typedef short TMbright; /* encoded luminance type */ |
66 |
|
|
69 |
|
int flags; /* flags of what to do */ |
70 |
|
RGBPRIMP monpri; /* monitor RGB primaries */ |
71 |
|
double mongam; /* monitor gamma value (approx.) */ |
60 |
– |
BYTE gamb[TM_GAMTSZ];/* gamma lookup table from mongam */ |
72 |
|
COLOR clf; /* computed luminance coefficients */ |
73 |
< |
COLR clfb; /* normalized version of clf */ |
73 |
> |
int cdiv[3]; /* computed color divisors */ |
74 |
|
RGBPRIMP inppri; /* current input primaries */ |
75 |
|
double inpsf; /* current input scalefactor */ |
65 |
– |
TMbright inpsfb; /* encoded version of inpsf */ |
76 |
|
COLORMAT cmat; /* color conversion matrix */ |
77 |
< |
TMbright brmin, brmax; /* input brightness limits */ |
77 |
> |
TMbright hbrmin, hbrmax; /* histogram brightness limits */ |
78 |
|
int *histo; /* input histogram */ |
79 |
+ |
TMbright mbrmin, mbrmax; /* mapped brightness limits */ |
80 |
|
unsigned short *lumap; /* computed luminance map */ |
81 |
|
struct tmStruct *tmprev; /* previous tone mapping */ |
82 |
+ |
MEM_PTR pd[TM_MAXPKG]; /* pointers to private data */ |
83 |
|
} *tmTop; /* current tone mapping stack */ |
84 |
< |
|
84 |
> |
|
85 |
> |
/* conversion package functions */ |
86 |
> |
#ifdef NOPROTO |
87 |
> |
struct tmPackage { |
88 |
> |
MEM_PTR (*Init)(); /* initialize private data */ |
89 |
> |
void (*NewSpace)(); /* new input color space (optional) */ |
90 |
> |
void (*Free)(); /* free private data */ |
91 |
> |
}; |
92 |
> |
#else |
93 |
> |
struct tmPackage { |
94 |
> |
MEM_PTR (*Init)(struct tmStruct *tms); |
95 |
> |
int (*NewSpace)(struct tmStruct *tms); |
96 |
> |
void (*Free)(MEM_PTR pp); |
97 |
> |
}; |
98 |
> |
#endif |
99 |
> |
/* our list of conversion packages */ |
100 |
> |
extern struct tmPackage *tmPkg[TM_MAXPKG]; |
101 |
> |
extern int tmNumPkgs; /* number of registered packages */ |
102 |
> |
|
103 |
> |
|
104 |
|
/**** Useful Macros ****/ |
105 |
|
|
106 |
+ |
/* compute luminance from encoded value */ |
107 |
|
#define tmLuminance(li) exp((li)/(double)TM_BRTSCALE) |
108 |
|
|
109 |
+ |
/* does tone mapping need color matrix? */ |
110 |
+ |
#define tmNeedMatrix(t) ((t)->monpri != (t)->inppri) |
111 |
+ |
|
112 |
+ |
/* register a conversion package */ |
113 |
+ |
#define tmRegPkg(pf) ( tmNumPkgs >= TM_MAXPKG ? -1 : \ |
114 |
+ |
(tmPkg[tmNumPkgs] = (pf), tmNumPkgs++) ) |
115 |
+ |
|
116 |
+ |
/* get the specific package's data */ |
117 |
+ |
#define tmPkgData(t,i) ((t)->pd[i]!=NULL ? (t)->pd[i] : (*tmPkg[i]->Init)(t)) |
118 |
+ |
|
119 |
+ |
|
120 |
|
/**** Library Function Calls ****/ |
121 |
|
|
122 |
< |
#ifdef NOPROTO |
122 |
> |
#ifdef NOPROTO |
123 |
|
|
124 |
|
extern struct tmStruct *tmInit(), *tmPop(), *tmDup(); |
125 |
|
extern void tmClearHisto(), tmDone(); |
199 |
|
extern int |
200 |
|
tmComputeMapping(double gamval, double Lddyn, double Ldmax); |
201 |
|
/* |
202 |
< |
Compute tone mapping function. |
202 |
> |
Compute tone mapping function. This mapping will be used |
203 |
> |
in subsequent calls to tmMapPixels() until a new tone mapping |
204 |
> |
is computed. I.e., calls to tmAddHisto() have no immediate effect. |
205 |
|
|
206 |
|
gamval - display gamma response (0. for default). |
207 |
|
Lddyn - the display's dynamic range (0. for default). |
228 |
|
char *fname, FILE *fp); |
229 |
|
/* |
230 |
|
Load Radiance picture and convert to tone mapping representation. |
231 |
+ |
Memory for the luminance and chroma arrays is allocated using |
232 |
+ |
malloc(3), and should be freed with free(3) when no longer needed. |
233 |
|
Calls tmSetSpace() to calibrate input color space. |
234 |
|
|
235 |
|
lpp - returned array of encoded luminances, English ordering. |
251 |
|
If fp is TM_GETFILE and (flags&TM_F_UNIMPL)!=0, tmMapPicture() |
252 |
|
calls pcond to perform the actual conversion, which takes |
253 |
|
longer but gives access to all the TM_F_* features. |
254 |
+ |
Memory for the final pixel array is allocated using malloc(3), |
255 |
+ |
and should be freed with free(3) when it is no longer needed. |
256 |
|
|
257 |
|
psp - returned array of tone mapped pixels, English ordering. |
258 |
|
xp, yp - returned picture dimensions. |
316 |
|
*/ |
317 |
|
|
318 |
|
#endif |
319 |
< |
|
319 |
> |
|
320 |
> |
|
321 |
|
/**** Notes ****/ |
322 |
|
/* |
323 |
|
General: |
326 |
|
pixel values to chroma and luminance encodings, which can |
327 |
|
be passed to tmAddHisto() to put into the tone mapping histogram. |
328 |
|
This histogram is then used along with the display parameters |
329 |
< |
by tmComputMapping() to compute the luminance mapping function. |
329 |
> |
by tmComputeMapping() to compute the luminance mapping function. |
330 |
|
(Colors are tone-mapped as they are converted if TM_F_MESOPIC |
331 |
|
is set.) The encoded chroma and luminance values may then be |
332 |
|
passed to tmMapPixels() to apply the computed tone mapping in |