| 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 */ |
| 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 |
|
|
| 62 |
|
typedef short TMbright; /* encoded luminance type */ |
| 66 |
|
int flags; /* flags of what to do */ |
| 67 |
|
RGBPRIMP monpri; /* monitor RGB primaries */ |
| 68 |
|
double mongam; /* monitor gamma value (approx.) */ |
| 60 |
– |
BYTE gamb[TM_GAMTSZ];/* gamma lookup table from mongam */ |
| 69 |
|
COLOR clf; /* computed luminance coefficients */ |
| 70 |
< |
COLR clfb; /* normalized version of clf */ |
| 70 |
> |
int cdiv[3]; /* computed color divisors */ |
| 71 |
|
RGBPRIMP inppri; /* current input primaries */ |
| 72 |
|
double inpsf; /* current input scalefactor */ |
| 65 |
– |
TMbright inpsfb; /* encoded version of inpsf */ |
| 73 |
|
COLORMAT cmat; /* color conversion matrix */ |
| 74 |
|
TMbright brmin, brmax; /* input brightness limits */ |
| 75 |
|
int *histo; /* input histogram */ |
| 76 |
|
unsigned short *lumap; /* computed luminance map */ |
| 77 |
|
struct tmStruct *tmprev; /* previous tone mapping */ |
| 78 |
+ |
MEM_PTR pd[TM_MAXPKG]; /* pointers to private data */ |
| 79 |
|
} *tmTop; /* current tone mapping stack */ |
| 80 |
< |
|
| 80 |
> |
|
| 81 |
> |
/* conversion package functions */ |
| 82 |
> |
#ifdef NOPROTO |
| 83 |
> |
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 { |
| 90 |
> |
MEM_PTR (*Init)(struct tmStruct *tms); |
| 91 |
> |
int (*NewSpace)(struct tmStruct *tms); |
| 92 |
> |
void (*Free)(MEM_PTR pp); |
| 93 |
> |
}; |
| 94 |
> |
#endif |
| 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 |
+ |
/* compute luminance from encoded value */ |
| 103 |
|
#define tmLuminance(li) exp((li)/(double)TM_BRTSCALE) |
| 104 |
|
|
| 105 |
+ |
/* does tone mapping need color matrix? */ |
| 106 |
+ |
#define tmNeedMatrix(t) ((t)->monpri != (t)->inppri) |
| 107 |
+ |
|
| 108 |
+ |
/* register a conversion package */ |
| 109 |
+ |
#define tmRegPkg(pf) ( tmNumPkgs >= TM_MAXPKG ? -1 : \ |
| 110 |
+ |
(tmPkg[tmNumPkgs] = (pf), tmNumPkgs++) ) |
| 111 |
+ |
|
| 112 |
+ |
/* get the specific package's data */ |
| 113 |
+ |
#define tmPkgData(t,i) ((t)->pd[i]!=NULL ? (t)->pd[i] : (*tmPkg[i]->Init)(t)) |
| 114 |
+ |
|
| 115 |
+ |
|
| 116 |
|
/**** Library Function Calls ****/ |
| 117 |
|
|
| 118 |
< |
#ifdef NOPROTO |
| 118 |
> |
#ifdef NOPROTO |
| 119 |
|
|
| 120 |
|
extern struct tmStruct *tmInit(), *tmPop(), *tmDup(); |
| 121 |
|
extern void tmClearHisto(), tmDone(); |
| 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. |
| 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. |
| 310 |
|
*/ |
| 311 |
|
|
| 312 |
|
#endif |
| 313 |
< |
|
| 313 |
> |
|
| 314 |
> |
|
| 315 |
|
/**** Notes ****/ |
| 316 |
|
/* |
| 317 |
|
General: |
| 320 |
|
pixel values to chroma and luminance encodings, which can |
| 321 |
|
be passed to tmAddHisto() to put into the tone mapping histogram. |
| 322 |
|
This histogram is then used along with the display parameters |
| 323 |
< |
by tmComputMapping() to compute the luminance mapping function. |
| 323 |
> |
by tmComputeMapping() to compute the luminance mapping function. |
| 324 |
|
(Colors are tone-mapped as they are converted if TM_F_MESOPIC |
| 325 |
|
is set.) The encoded chroma and luminance values may then be |
| 326 |
|
passed to tmMapPixels() to apply the computed tone mapping in |