| 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 |
|
|
| 10 |
+ |
#include "tifftypes.h" |
| 11 |
|
|
| 12 |
+ |
#ifdef __cplusplus |
| 13 |
+ |
extern "C" { |
| 14 |
+ |
#endif |
| 15 |
+ |
|
| 16 |
|
/**** Argument Macros ****/ |
| 17 |
|
/* Flags of what to do */ |
| 18 |
|
#define TM_F_HCONTR 01 /* human contrast sensitivity */ |
| 36 |
|
#define TM_NOCHROMP (BYTE **)NULL /* indicate no chrominances */ |
| 37 |
|
#define TM_GETFILE (FILE *)NULL /* indicate file must be opened */ |
| 38 |
|
|
| 39 |
+ |
|
| 40 |
|
/**** Error Return Values ****/ |
| 41 |
|
|
| 42 |
|
#define TM_E_OK 0 /* normal return status */ |
| 53 |
|
|
| 54 |
|
#define TM_BRTSCALE 128 /* brightness scale factor (integer) */ |
| 55 |
|
|
| 56 |
+ |
#define TM_NOBRT (-1<<15) /* bogus brightness value */ |
| 57 |
+ |
#define TM_NOLUM (1e-17) /* ridiculously small luminance */ |
| 58 |
+ |
|
| 59 |
|
#define TM_MAXPKG 8 /* maximum number of color formats */ |
| 60 |
|
|
| 61 |
|
|
| 90 |
|
} *tmTop; /* current tone mapping stack */ |
| 91 |
|
|
| 92 |
|
/* conversion package functions */ |
| 85 |
– |
#ifdef NOPROTO |
| 93 |
|
struct tmPackage { |
| 87 |
– |
MEM_PTR (*Init)(); /* initialize private data */ |
| 88 |
– |
void (*NewSpace)(); /* new input color space (optional) */ |
| 89 |
– |
void (*Free)(); /* free private data */ |
| 90 |
– |
}; |
| 91 |
– |
#else |
| 92 |
– |
struct tmPackage { |
| 94 |
|
MEM_PTR (*Init)(struct tmStruct *tms); |
| 95 |
< |
int (*NewSpace)(struct tmStruct *tms); |
| 95 |
> |
void (*NewSpace)(struct tmStruct *tms); |
| 96 |
|
void (*Free)(MEM_PTR pp); |
| 97 |
|
}; |
| 97 |
– |
#endif |
| 98 |
|
/* our list of conversion packages */ |
| 99 |
|
extern struct tmPackage *tmPkg[TM_MAXPKG]; |
| 100 |
|
extern int tmNumPkgs; /* number of registered packages */ |
| 103 |
|
/**** Useful Macros ****/ |
| 104 |
|
|
| 105 |
|
/* compute luminance from encoded value */ |
| 106 |
< |
#define tmLuminance(li) exp((li)/(double)TM_BRTSCALE) |
| 106 |
> |
#define tmLuminance(li) exp((li)*(1./TM_BRTSCALE)) |
| 107 |
|
|
| 108 |
|
/* does tone mapping need color matrix? */ |
| 109 |
|
#define tmNeedMatrix(t) ((t)->monpri != (t)->inppri) |
| 118 |
|
|
| 119 |
|
/**** Library Function Calls ****/ |
| 120 |
|
|
| 121 |
– |
#ifdef NOPROTO |
| 121 |
|
|
| 123 |
– |
extern struct tmStruct *tmInit(), *tmPop(), *tmDup(); |
| 124 |
– |
extern void tmClearHisto(), tmDone(); |
| 125 |
– |
extern int tmSetSpace(), tmCvColors(), tmCvColrs(); |
| 126 |
– |
extern int tmAddHisto(), tmComputeMapping(), tmMapPixels(); |
| 127 |
– |
extern int tmLoadPicture(), tmMapPicture(), tmPull(), tmPush(); |
| 128 |
– |
|
| 129 |
– |
#else |
| 130 |
– |
|
| 122 |
|
extern struct tmStruct * |
| 123 |
|
tmInit(int flags, RGBPRIMP monpri, double gamval); |
| 124 |
|
/* |
| 149 |
|
*/ |
| 150 |
|
|
| 151 |
|
extern int |
| 161 |
– |
tmCvColors(TMbright *ls, BYTE *cs, COLOR *scan, int len); |
| 162 |
– |
/* |
| 163 |
– |
Convert RGB/XYZ float scanline to encoded luminance and chrominance. |
| 164 |
– |
|
| 165 |
– |
ls - returned encoded luminance values. |
| 166 |
– |
cs - returned encoded chrominance values (Note 2). |
| 167 |
– |
scan - input scanline. |
| 168 |
– |
len - scanline length. |
| 169 |
– |
|
| 170 |
– |
returns - 0 on success, TM_E_* on error. |
| 171 |
– |
*/ |
| 172 |
– |
|
| 173 |
– |
extern int |
| 174 |
– |
tmCvColrs(TMbright *ls, BYTE *cs, COLR *scan, int len); |
| 175 |
– |
/* |
| 176 |
– |
Convert RGBE/XYZE scanline to encoded luminance and chrominance. |
| 177 |
– |
|
| 178 |
– |
ls - returned encoded luminance values. |
| 179 |
– |
cs - returned encoded chrominance values (Note 2). |
| 180 |
– |
scan - input scanline. |
| 181 |
– |
len - scanline length. |
| 182 |
– |
|
| 183 |
– |
returns - 0 on success, TM_E_* on error. |
| 184 |
– |
*/ |
| 185 |
– |
|
| 186 |
– |
extern int |
| 152 |
|
tmAddHisto(TMbright *ls, int len, int wt); |
| 153 |
|
/* |
| 154 |
|
Add brightness values to current histogram. |
| 161 |
|
*/ |
| 162 |
|
|
| 163 |
|
extern int |
| 164 |
+ |
tmFixedMapping(double expmult, double gamval); |
| 165 |
+ |
/* |
| 166 |
+ |
Assign a fixed, linear tone-mapping using the given multiplier, |
| 167 |
+ |
which is the ratio of maximum output to uncalibrated input. |
| 168 |
+ |
This mapping will be used in subsequent calls to tmMapPixels() |
| 169 |
+ |
until a new tone mapping is computed. |
| 170 |
+ |
Only the min. and max. values are used from the histogram. |
| 171 |
+ |
|
| 172 |
+ |
expmult - the fixed exposure multiplier to use. |
| 173 |
+ |
gamval - display gamma response (0. for default). |
| 174 |
+ |
returns - 0 on success, TM_E_* on error. |
| 175 |
+ |
*/ |
| 176 |
+ |
|
| 177 |
+ |
extern int |
| 178 |
|
tmComputeMapping(double gamval, double Lddyn, double Ldmax); |
| 179 |
|
/* |
| 180 |
< |
Compute tone mapping function. This mapping will be used |
| 181 |
< |
in subsequent calls to tmMapPixels() until a new tone mapping |
| 182 |
< |
is computed. I.e., calls to tmAddHisto() have no immediate effect. |
| 180 |
> |
Compute tone mapping function from the current histogram. |
| 181 |
> |
This mapping will be used in subsequent calls to tmMapPixels() |
| 182 |
> |
until a new tone mapping is computed. |
| 183 |
> |
I.e., calls to tmAddHisto() have no immediate effect. |
| 184 |
|
|
| 185 |
|
gamval - display gamma response (0. for default). |
| 186 |
|
Lddyn - the display's dynamic range (0. for default). |
| 202 |
|
returns - 0 on success, TM_E_* on failure. |
| 203 |
|
*/ |
| 204 |
|
|
| 205 |
+ |
extern struct tmStruct * |
| 206 |
+ |
tmPop(void); |
| 207 |
+ |
/* |
| 208 |
+ |
Pops current tone mapping from stack. |
| 209 |
+ |
|
| 210 |
+ |
returns - pointer to tone mapping structure, or NULL if none. |
| 211 |
+ |
*/ |
| 212 |
+ |
|
| 213 |
|
extern int |
| 214 |
+ |
tmPull(struct tmStruct *tms); |
| 215 |
+ |
/* |
| 216 |
+ |
Pull tone mapping from anywhere in stack. |
| 217 |
+ |
|
| 218 |
+ |
tms - tone mapping structure to find. |
| 219 |
+ |
|
| 220 |
+ |
returns - 1 if found in stack, 0 otherwise. |
| 221 |
+ |
*/ |
| 222 |
+ |
|
| 223 |
+ |
extern int |
| 224 |
+ |
tmPush(struct tmStruct *tms); |
| 225 |
+ |
/* |
| 226 |
+ |
Make tone mapping active by (pulling it and) pushing it to the top. |
| 227 |
+ |
|
| 228 |
+ |
tms - initialized tone mapping structure. |
| 229 |
+ |
|
| 230 |
+ |
returns - 0 on success, TM_E_* if tms is invalid. |
| 231 |
+ |
*/ |
| 232 |
+ |
|
| 233 |
+ |
extern struct tmStruct * |
| 234 |
+ |
tmDup(void); |
| 235 |
+ |
/* |
| 236 |
+ |
Duplicate the current tone mapping into a new structure on the stack. |
| 237 |
+ |
|
| 238 |
+ |
returns - pointer to new top, or NULL on error. |
| 239 |
+ |
*/ |
| 240 |
+ |
|
| 241 |
+ |
extern void |
| 242 |
+ |
tmDone(struct tmStruct *tms); |
| 243 |
+ |
/* |
| 244 |
+ |
Free data associated with the given tone mapping structure. |
| 245 |
+ |
Calls tmPull() first to remove it from the stack if present. |
| 246 |
+ |
The calls tmDone(tmPop()), tmDone(tmTop) and tmDone(NULL) |
| 247 |
+ |
all have the same effect, which is to remove and free |
| 248 |
+ |
the current tone mapping. |
| 249 |
+ |
|
| 250 |
+ |
tms - tone mapping structure to free. |
| 251 |
+ |
*/ |
| 252 |
+ |
|
| 253 |
+ |
extern int |
| 254 |
+ |
tmCvColors(TMbright *ls, BYTE *cs, COLOR *scan, int len); |
| 255 |
+ |
/* |
| 256 |
+ |
Convert RGB/XYZ float scanline to encoded luminance and chrominance. |
| 257 |
+ |
|
| 258 |
+ |
ls - returned encoded luminance values. |
| 259 |
+ |
cs - returned encoded chrominance values (Note 2). |
| 260 |
+ |
scan - input scanline. |
| 261 |
+ |
len - scanline length. |
| 262 |
+ |
|
| 263 |
+ |
returns - 0 on success, TM_E_* on error. |
| 264 |
+ |
*/ |
| 265 |
+ |
|
| 266 |
+ |
extern int |
| 267 |
+ |
tmCvGrays(TMbright *ls, float *scan, int len); |
| 268 |
+ |
/* |
| 269 |
+ |
Convert gray float scanline to encoded luminance. |
| 270 |
+ |
|
| 271 |
+ |
ls - returned encoded luminance values. |
| 272 |
+ |
scan - input scanline. |
| 273 |
+ |
len - scanline length. |
| 274 |
+ |
|
| 275 |
+ |
returns - 0 on success, TM_E_* on error. |
| 276 |
+ |
*/ |
| 277 |
+ |
|
| 278 |
+ |
extern int |
| 279 |
+ |
tmCvColrs(TMbright *ls, BYTE *cs, COLR *scan, int len); |
| 280 |
+ |
/* |
| 281 |
+ |
Convert RGBE/XYZE scanline to encoded luminance and chrominance. |
| 282 |
+ |
|
| 283 |
+ |
ls - returned encoded luminance values. |
| 284 |
+ |
cs - returned encoded chrominance values (Note 2). |
| 285 |
+ |
scan - input scanline. |
| 286 |
+ |
len - scanline length. |
| 287 |
+ |
|
| 288 |
+ |
returns - 0 on success, TM_E_* on error. |
| 289 |
+ |
*/ |
| 290 |
+ |
|
| 291 |
+ |
extern int |
| 292 |
|
tmLoadPicture(TMbright **lpp, BYTE **cpp, int *xp, int *yp, |
| 293 |
|
char *fname, FILE *fp); |
| 294 |
|
/* |
| 297 |
|
malloc(3), and should be freed with free(3) when no longer needed. |
| 298 |
|
Calls tmSetSpace() to calibrate input color space. |
| 299 |
|
|
| 300 |
< |
lpp - returned array of encoded luminances, English ordering. |
| 300 |
> |
lpp - returned array of encoded luminances, picture ordering. |
| 301 |
|
cpp - returned array of encoded chrominances (Note 2). |
| 302 |
|
xp, yp - returned picture dimensions. |
| 303 |
|
fname - picture file name. |
| 319 |
|
Memory for the final pixel array is allocated using malloc(3), |
| 320 |
|
and should be freed with free(3) when it is no longer needed. |
| 321 |
|
|
| 322 |
< |
psp - returned array of tone mapped pixels, English ordering. |
| 322 |
> |
psp - returned array of tone mapped pixels, picture ordering. |
| 323 |
|
xp, yp - returned picture dimensions. |
| 324 |
|
flags - TM_F_* flags indicating what is to be done. |
| 325 |
|
monpri - display monitor primaries (Note 1). |
| 332 |
|
returns - 0 on success, TM_E_* on failure. |
| 333 |
|
*/ |
| 334 |
|
|
| 269 |
– |
extern struct tmStruct * |
| 270 |
– |
tmPop(void); |
| 271 |
– |
/* |
| 272 |
– |
Pops current tone mapping from stack. |
| 273 |
– |
|
| 274 |
– |
returns - pointer to tone mapping structure, or NULL if none. |
| 275 |
– |
*/ |
| 276 |
– |
|
| 335 |
|
extern int |
| 336 |
< |
tmPull(struct tmStruct *tms); |
| 336 |
> |
tmCvRGB48(TMbright *ls, BYTE *cs, uint16 (*scan)[3], int len, double gv); |
| 337 |
|
/* |
| 338 |
< |
Pull tone mapping from anywhere in stack. |
| 338 |
> |
Convert 48-bit RGB scanline to encoded luminance and chrominance. |
| 339 |
|
|
| 340 |
< |
tms - tone mapping structure to find. |
| 340 |
> |
ls - returned encoded luminance values. |
| 341 |
> |
cs - returned encoded chrominance values (Note 2). |
| 342 |
> |
scan - input scanline. |
| 343 |
> |
len - scanline length. |
| 344 |
> |
gv - input gamma value. |
| 345 |
|
|
| 346 |
< |
returns - 1 if found in stack, 0 otherwise. |
| 346 |
> |
returns - 0 on success, TM_E_* on error. |
| 347 |
|
*/ |
| 348 |
|
|
| 349 |
|
extern int |
| 350 |
< |
tmPush(struct tmStruct *tms); |
| 350 |
> |
tmCvGray16(TMbright *ls, uint16 *scan, int len, double gv); |
| 351 |
|
/* |
| 352 |
< |
Make tone mapping active by (pulling it and) pushing it to the top. |
| 352 |
> |
Convert 16-bit gray scanline to encoded luminance. |
| 353 |
|
|
| 354 |
< |
tms - initialized tone mapping structure. |
| 354 |
> |
ls - returned encoded luminance values. |
| 355 |
> |
scan - input scanline. |
| 356 |
> |
len - scanline length. |
| 357 |
> |
gv - input gamma value. |
| 358 |
|
|
| 359 |
< |
returns - 0 on success, TM_E_* if tms is invalid. |
| 359 |
> |
returns - 0 on success, TM_E_* on error. |
| 360 |
|
*/ |
| 361 |
|
|
| 297 |
– |
extern struct tmStruct * |
| 298 |
– |
tmDup(void); |
| 299 |
– |
/* |
| 300 |
– |
Duplicate the current tone mapping into a new structure on the stack. |
| 301 |
– |
|
| 302 |
– |
returns - pointer to new top, or NULL on error. |
| 303 |
– |
*/ |
| 304 |
– |
|
| 305 |
– |
extern void |
| 306 |
– |
tmDone(struct tmStruct *tms); |
| 307 |
– |
/* |
| 308 |
– |
Free data associated with the given tone mapping structure. |
| 309 |
– |
Calls tmPull() first to remove it from the stack if present. |
| 310 |
– |
The calls tmDone(tmPop()), tmDone(tmTop) and tmDone(NULL) |
| 311 |
– |
all have the same effect, which is to remove and free |
| 312 |
– |
the current tone mapping. |
| 313 |
– |
|
| 314 |
– |
tms - tone mapping structure to free. |
| 315 |
– |
*/ |
| 316 |
– |
|
| 317 |
– |
#endif |
| 318 |
– |
|
| 319 |
– |
|
| 362 |
|
/**** Notes ****/ |
| 363 |
|
/* |
| 364 |
|
General: |
| 429 |
|
function will open the file, read its contents and close it |
| 430 |
|
before returning, whether or not an error was encountered. |
| 431 |
|
*/ |
| 432 |
+ |
|
| 433 |
+ |
#ifdef __cplusplus |
| 434 |
+ |
} |
| 435 |
+ |
#endif |
| 436 |
+ |
#endif /* _RAD_TONEMAP_H_ */ |
| 437 |
+ |
|