| 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 |
+ |
#include "copyright.h" |
| 9 |
|
|
| 10 |
+ |
#ifdef __cplusplus |
| 11 |
+ |
extern "C" { |
| 12 |
+ |
#endif |
| 13 |
+ |
|
| 14 |
|
/**** Argument Macros ****/ |
| 15 |
|
/* Flags of what to do */ |
| 16 |
|
#define TM_F_HCONTR 01 /* human contrast sensitivity */ |
| 34 |
|
#define TM_NOCHROMP (BYTE **)NULL /* indicate no chrominances */ |
| 35 |
|
#define TM_GETFILE (FILE *)NULL /* indicate file must be opened */ |
| 36 |
|
|
| 37 |
+ |
|
| 38 |
|
/**** Error Return Values ****/ |
| 39 |
|
|
| 40 |
|
#define TM_E_OK 0 /* normal return status */ |
| 51 |
|
|
| 52 |
|
#define TM_BRTSCALE 128 /* brightness scale factor (integer) */ |
| 53 |
|
|
| 54 |
+ |
#define TM_NOBRT (-1<<15) /* bogus brightness value */ |
| 55 |
+ |
#define TM_NOLUM (1e-17) /* ridiculously small luminance */ |
| 56 |
+ |
|
| 57 |
|
#define TM_MAXPKG 8 /* maximum number of color formats */ |
| 58 |
|
|
| 59 |
|
|
| 64 |
|
#endif |
| 65 |
|
|
| 66 |
|
extern char *tmErrorMessage[]; /* error messages */ |
| 67 |
+ |
extern int tmLastError; /* last error incurred by library */ |
| 68 |
+ |
extern char *tmLastFunction; /* error-generating function name */ |
| 69 |
|
|
| 70 |
|
typedef short TMbright; /* encoded luminance type */ |
| 71 |
|
|
| 79 |
|
RGBPRIMP inppri; /* current input primaries */ |
| 80 |
|
double inpsf; /* current input scalefactor */ |
| 81 |
|
COLORMAT cmat; /* color conversion matrix */ |
| 82 |
< |
TMbright brmin, brmax; /* input brightness limits */ |
| 82 |
> |
TMbright hbrmin, hbrmax; /* histogram brightness limits */ |
| 83 |
|
int *histo; /* input histogram */ |
| 84 |
+ |
TMbright mbrmin, mbrmax; /* mapped brightness limits */ |
| 85 |
|
unsigned short *lumap; /* computed luminance map */ |
| 86 |
|
struct tmStruct *tmprev; /* previous tone mapping */ |
| 87 |
|
MEM_PTR pd[TM_MAXPKG]; /* pointers to private data */ |
| 97 |
|
#else |
| 98 |
|
struct tmPackage { |
| 99 |
|
MEM_PTR (*Init)(struct tmStruct *tms); |
| 100 |
< |
int (*NewSpace)(struct tmStruct *tms); |
| 100 |
> |
void (*NewSpace)(struct tmStruct *tms); |
| 101 |
|
void (*Free)(MEM_PTR pp); |
| 102 |
|
}; |
| 103 |
|
#endif |
| 109 |
|
/**** Useful Macros ****/ |
| 110 |
|
|
| 111 |
|
/* compute luminance from encoded value */ |
| 112 |
< |
#define tmLuminance(li) exp((li)/(double)TM_BRTSCALE) |
| 112 |
> |
#define tmLuminance(li) exp((li)*(1./TM_BRTSCALE)) |
| 113 |
|
|
| 114 |
|
/* does tone mapping need color matrix? */ |
| 115 |
|
#define tmNeedMatrix(t) ((t)->monpri != (t)->inppri) |
| 127 |
|
#ifdef NOPROTO |
| 128 |
|
|
| 129 |
|
extern struct tmStruct *tmInit(), *tmPop(), *tmDup(); |
| 130 |
+ |
extern int tmSetSpace(), tmPull(), tmPush(); |
| 131 |
|
extern void tmClearHisto(), tmDone(); |
| 132 |
< |
extern int tmSetSpace(), tmCvColors(), tmCvColrs(); |
| 133 |
< |
extern int tmAddHisto(), tmComputeMapping(), tmMapPixels(); |
| 134 |
< |
extern int tmLoadPicture(), tmMapPicture(), tmPull(), tmPush(); |
| 132 |
> |
extern int tmAddHisto(); |
| 133 |
> |
extern int tmFixedMapping(), tmComputeMapping(), tmMapPixels(); |
| 134 |
> |
extern int tmCvColors(), tmCvGrays(), tmCvColrs(); |
| 135 |
> |
extern int tmLoadPicture(), tmMapPicture(); |
| 136 |
|
|
| 137 |
|
#else |
| 138 |
|
|
| 166 |
|
*/ |
| 167 |
|
|
| 168 |
|
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 |
| 169 |
|
tmAddHisto(TMbright *ls, int len, int wt); |
| 170 |
|
/* |
| 171 |
|
Add brightness values to current histogram. |
| 178 |
|
*/ |
| 179 |
|
|
| 180 |
|
extern int |
| 181 |
+ |
tmFixedMapping(double expmult, double gamval); |
| 182 |
+ |
/* |
| 183 |
+ |
Assign a fixed, linear tone-mapping using the given multiplier, |
| 184 |
+ |
which is the ratio of maximum output to uncalibrated input. |
| 185 |
+ |
This mapping will be used in subsequent calls to tmMapPixels() |
| 186 |
+ |
until a new tone mapping is computed. |
| 187 |
+ |
Only the min. and max. values are used from the histogram. |
| 188 |
+ |
|
| 189 |
+ |
expmult - the fixed exposure multiplier to use. |
| 190 |
+ |
gamval - display gamma response (0. for default). |
| 191 |
+ |
returns - 0 on success, TM_E_* on error. |
| 192 |
+ |
*/ |
| 193 |
+ |
|
| 194 |
+ |
extern int |
| 195 |
|
tmComputeMapping(double gamval, double Lddyn, double Ldmax); |
| 196 |
|
/* |
| 197 |
< |
Compute tone mapping function. |
| 197 |
> |
Compute tone mapping function from the current histogram. |
| 198 |
> |
This mapping will be used in subsequent calls to tmMapPixels() |
| 199 |
> |
until a new tone mapping is computed. |
| 200 |
> |
I.e., calls to tmAddHisto() have no immediate effect. |
| 201 |
|
|
| 202 |
|
gamval - display gamma response (0. for default). |
| 203 |
|
Lddyn - the display's dynamic range (0. for default). |
| 219 |
|
returns - 0 on success, TM_E_* on failure. |
| 220 |
|
*/ |
| 221 |
|
|
| 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 |
– |
|
| 222 |
|
extern struct tmStruct * |
| 223 |
|
tmPop(void); |
| 224 |
|
/* |
| 267 |
|
tms - tone mapping structure to free. |
| 268 |
|
*/ |
| 269 |
|
|
| 270 |
+ |
extern int |
| 271 |
+ |
tmCvColors(TMbright *ls, BYTE *cs, COLOR *scan, int len); |
| 272 |
+ |
/* |
| 273 |
+ |
Convert RGB/XYZ float scanline to encoded luminance and chrominance. |
| 274 |
+ |
|
| 275 |
+ |
ls - returned encoded luminance values. |
| 276 |
+ |
cs - returned encoded chrominance values (Note 2). |
| 277 |
+ |
scan - input scanline. |
| 278 |
+ |
len - scanline length. |
| 279 |
+ |
|
| 280 |
+ |
returns - 0 on success, TM_E_* on error. |
| 281 |
+ |
*/ |
| 282 |
+ |
|
| 283 |
+ |
extern int |
| 284 |
+ |
tmCvGrays(TMbright *ls, float *scan, int len); |
| 285 |
+ |
/* |
| 286 |
+ |
Convert gray float scanline to encoded luminance. |
| 287 |
+ |
|
| 288 |
+ |
ls - returned encoded luminance values. |
| 289 |
+ |
scan - input scanline. |
| 290 |
+ |
len - scanline length. |
| 291 |
+ |
|
| 292 |
+ |
returns - 0 on success, TM_E_* on error. |
| 293 |
+ |
*/ |
| 294 |
+ |
|
| 295 |
+ |
extern int |
| 296 |
+ |
tmCvColrs(TMbright *ls, BYTE *cs, COLR *scan, int len); |
| 297 |
+ |
/* |
| 298 |
+ |
Convert RGBE/XYZE scanline to encoded luminance and chrominance. |
| 299 |
+ |
|
| 300 |
+ |
ls - returned encoded luminance values. |
| 301 |
+ |
cs - returned encoded chrominance values (Note 2). |
| 302 |
+ |
scan - input scanline. |
| 303 |
+ |
len - scanline length. |
| 304 |
+ |
|
| 305 |
+ |
returns - 0 on success, TM_E_* on error. |
| 306 |
+ |
*/ |
| 307 |
+ |
|
| 308 |
+ |
extern int |
| 309 |
+ |
tmLoadPicture(TMbright **lpp, BYTE **cpp, int *xp, int *yp, |
| 310 |
+ |
char *fname, FILE *fp); |
| 311 |
+ |
/* |
| 312 |
+ |
Load Radiance picture and convert to tone mapping representation. |
| 313 |
+ |
Memory for the luminance and chroma arrays is allocated using |
| 314 |
+ |
malloc(3), and should be freed with free(3) when no longer needed. |
| 315 |
+ |
Calls tmSetSpace() to calibrate input color space. |
| 316 |
+ |
|
| 317 |
+ |
lpp - returned array of encoded luminances, picture ordering. |
| 318 |
+ |
cpp - returned array of encoded chrominances (Note 2). |
| 319 |
+ |
xp, yp - returned picture dimensions. |
| 320 |
+ |
fname - picture file name. |
| 321 |
+ |
fp - pointer to open file (Note 3). |
| 322 |
+ |
|
| 323 |
+ |
returns - 0 on success, TM_E_* on failure. |
| 324 |
+ |
*/ |
| 325 |
+ |
|
| 326 |
+ |
extern int |
| 327 |
+ |
tmMapPicture(BYTE **psp, int *xp, int *yp, int flags, |
| 328 |
+ |
RGBPRIMP monpri, double gamval, double Lddyn, double Ldmax, |
| 329 |
+ |
char *fname, FILE *fp); |
| 330 |
+ |
/* |
| 331 |
+ |
Load and apply tone mapping to Radiance picture. |
| 332 |
+ |
Stack is restored to its original state upon return. |
| 333 |
+ |
If fp is TM_GETFILE and (flags&TM_F_UNIMPL)!=0, tmMapPicture() |
| 334 |
+ |
calls pcond to perform the actual conversion, which takes |
| 335 |
+ |
longer but gives access to all the TM_F_* features. |
| 336 |
+ |
Memory for the final pixel array is allocated using malloc(3), |
| 337 |
+ |
and should be freed with free(3) when it is no longer needed. |
| 338 |
+ |
|
| 339 |
+ |
psp - returned array of tone mapped pixels, picture ordering. |
| 340 |
+ |
xp, yp - returned picture dimensions. |
| 341 |
+ |
flags - TM_F_* flags indicating what is to be done. |
| 342 |
+ |
monpri - display monitor primaries (Note 1). |
| 343 |
+ |
gamval - display gamma response. |
| 344 |
+ |
Lddyn - the display's dynamic range (0. for default). |
| 345 |
+ |
Ldmax - maximum display luminance in cd/m^2 (0. for default). |
| 346 |
+ |
fname - picture file name. |
| 347 |
+ |
fp - pointer to open file (Note 3). |
| 348 |
+ |
|
| 349 |
+ |
returns - 0 on success, TM_E_* on failure. |
| 350 |
+ |
*/ |
| 351 |
+ |
|
| 352 |
|
#endif |
| 353 |
|
|
| 354 |
|
|
| 422 |
|
function will open the file, read its contents and close it |
| 423 |
|
before returning, whether or not an error was encountered. |
| 424 |
|
*/ |
| 425 |
+ |
|
| 426 |
+ |
#ifdef __cplusplus |
| 427 |
+ |
} |
| 428 |
+ |
#endif |