1 |
greg |
3.7 |
/* RCSid $Id$ */ |
2 |
greg |
3.1 |
/* |
3 |
|
|
* Private header file for tone mapping routines. |
4 |
|
|
*/ |
5 |
|
|
|
6 |
greg |
3.7 |
#include "copyright.h" |
7 |
greg |
3.6 |
|
8 |
greg |
3.4 |
#ifndef MEM_PTR |
9 |
greg |
3.6 |
#define MEM_PTR void * |
10 |
greg |
3.4 |
#endif |
11 |
gwlarson |
3.5 |
#include "color.h" |
12 |
greg |
3.1 |
#include "tonemap.h" |
13 |
greg |
3.2 |
|
14 |
greg |
3.6 |
#ifdef __cplusplus |
15 |
|
|
extern "C" { |
16 |
|
|
#endif |
17 |
|
|
|
18 |
greg |
3.2 |
/* required constants */ |
19 |
|
|
#ifndef M_LN2 |
20 |
|
|
#define M_LN2 0.69314718055994530942 |
21 |
|
|
#endif |
22 |
|
|
#ifndef M_LN10 |
23 |
|
|
#define M_LN10 2.30258509299404568402 |
24 |
|
|
#endif |
25 |
greg |
3.1 |
/* minimum values and defaults */ |
26 |
|
|
#define MINGAM 0.75 |
27 |
|
|
#define DEFGAM 2.2 |
28 |
|
|
#define MINLDDYN 2. |
29 |
|
|
#define DEFLDDYN 32. |
30 |
|
|
#define MINLDMAX 1. |
31 |
|
|
#define DEFLDMAX 100. |
32 |
|
|
|
33 |
greg |
3.6 |
#define BRT2SCALE(l2) (int)(M_LN2*TM_BRTSCALE*(l2) + ((l2)>0 ? .5 : -.5)) |
34 |
greg |
3.1 |
|
35 |
|
|
#define HISTEP 8 /* steps in BRTSCALE for each bin */ |
36 |
|
|
|
37 |
|
|
#define MINBRT (-16*TM_BRTSCALE) /* minimum usable brightness */ |
38 |
|
|
#define MINLUM (1.125352e-7) /* tmLuminance(MINBRT) */ |
39 |
|
|
|
40 |
|
|
#define LMESLOWER (5.62e-3) /* lower mesopic limit */ |
41 |
greg |
3.3 |
#define LMESUPPER (5.62) /* upper mesopic limit */ |
42 |
|
|
#if (TM_BRTSCALE==128) |
43 |
greg |
3.2 |
#define BMESLOWER (-663) /* encoded LMESLOWER */ |
44 |
|
|
#define BMESUPPER (221) /* encoded LMESUPPER */ |
45 |
greg |
3.3 |
#else |
46 |
|
|
#define BMESLOWER ((int)(-5.18*TM_BRTSCALE-.5)) |
47 |
|
|
#define BMESUPPER ((int)(1.73*TM_BRTSCALE+.5)) |
48 |
|
|
#endif |
49 |
greg |
3.1 |
|
50 |
|
|
#ifndef int4 |
51 |
|
|
#define int4 int /* assume 32-bit integers */ |
52 |
|
|
#endif |
53 |
|
|
/* approximate scotopic lum. */ |
54 |
|
|
#define SCO_rf 0.062 |
55 |
|
|
#define SCO_gf 0.608 |
56 |
|
|
#define SCO_bf 0.330 |
57 |
|
|
#define scotlum(c) (SCO_rf*(c)[RED] + SCO_gf*(c)[GRN] + SCO_bf*(c)[BLU]) |
58 |
|
|
#define normscot(c) ( ( (int4)(SCO_rf*256.+.5)*(c)[RED] + \ |
59 |
|
|
(int4)(SCO_gf*256.+.5)*(c)[GRN] + \ |
60 |
|
|
(int4)(SCO_bf*256.+.5)*(c)[BLU] ) >> 8 ) |
61 |
|
|
|
62 |
|
|
#ifndef malloc |
63 |
greg |
3.4 |
MEM_PTR malloc(); |
64 |
|
|
MEM_PTR calloc(); |
65 |
greg |
3.1 |
#endif |
66 |
|
|
extern int tmErrorReturn(); |
67 |
|
|
|
68 |
greg |
3.6 |
/* lookup for mesopic scaling */ |
69 |
|
|
extern BYTE tmMesofact[BMESUPPER-BMESLOWER]; |
70 |
|
|
|
71 |
|
|
extern void tmMkMesofact(); /* build tmMesofact */ |
72 |
|
|
|
73 |
greg |
3.1 |
#define returnErr(code) return(tmErrorReturn(funcName,code)) |
74 |
|
|
#define returnOK return(TM_E_OK) |
75 |
|
|
|
76 |
|
|
#define FEQ(a,b) ((a) < (b)+1e-5 && (b) < (a)+1e-5) |
77 |
|
|
|
78 |
greg |
3.6 |
#define PRIMEQ(p1,p2) (FEQ((p1)[0][0],(p2)[0][0])&&FEQ((p1)[0][1],(p2)[0][1])\ |
79 |
|
|
&&FEQ((p1)[1][0],(p2)[1][0])&&FEQ((p1)[1][1],(p2)[1][1])\ |
80 |
|
|
&&FEQ((p1)[2][0],(p2)[2][0])&&FEQ((p1)[2][1],(p2)[2][1])\ |
81 |
|
|
&&FEQ((p1)[3][0],(p2)[3][0])&&FEQ((p1)[3][1],(p2)[3][1])) |
82 |
|
|
|
83 |
|
|
#ifdef __cplusplus |
84 |
|
|
} |
85 |
|
|
#endif |