1 // Copyright 2004 David Hilvert <dhilvert@auricle.dyndns.org>,
2 // <dhilvert@ugcs.caltech.edu>
4 /* This file is part of the Anti-Lamenessing Engine.
6 The Anti-Lamenessing Engine is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 The Anti-Lamenessing Engine is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with the Anti-Lamenessing Engine; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * exposure_default.h: Default exposure properties.
25 #ifndef __exposure_default_h__
26 #define __exposure_default_h__
29 * The default exposure is modeled after the simple power transfer function
32 * http://netpbm.sourceforge.net/doc/pnmgamma.html
34 * Note: optimizations in d2/image_rw.h depend on the details of this function.
37 class exposure_default
: public exposure
{
39 pixel
linearize(pixel input
) const {
42 * Calling pow() may be expensive on some platforms (e.g.,
43 * those lacking hardware support for floating point).
46 return ppow(input
, 1/0.45) * get_multiplier();
48 const int table_size
= 1024;
49 const int table_bits
= 10;
50 const int interp_bits
= 6;
51 static int table_is_built
= 0;
52 static ale_real table
[table_size
];
56 if (!table_is_built
) {
57 for (int i
= 0; i
< table_size
; i
++) {
58 table
[i
] = pow((float) i
/ (float) (table_size
- 1), 1/0.45);
63 for (int k
= 0; k
< 3; k
++) {
70 } else if (input
[k
] <= 0) {
75 int index1
= ale_real_to_int(input
[k
], 65535);
77 int index2
= index1
>> (16 - table_bits
);
78 int index3
= (index1
>> (16 - table_bits
- interp_bits
))
79 & ((1 << interp_bits
) - 1);
81 if (index2
>= table_size
- 1) {
86 ale_real frac
= ale_real_from_int((index3
<< (16 - interp_bits
)), 65535);
88 result
[k
] = (1 - frac
) * table
[index2
] + frac
* table
[index2
+ 1];
91 return result
* get_multiplier();
94 pixel
unlinearize(pixel input
) const {
97 * Calling pow() may be expensive on some platforms (e.g.,
98 * those lacking hardware support for floating point).
101 return ppow(input
/ get_multiplier(), 0.45);
104 input
/= get_multiplier();
106 const int table_size
= 1024;
107 const int table_bits
= 10;
108 const int interp_bits
= 6;
109 static int table_is_built
= 0;
110 static ale_real table
[table_size
];
114 if (!table_is_built
) {
115 for (int i
= 0; i
< table_size
; i
++) {
116 table
[i
] = pow((float) i
/ (float) (table_size
- 1), 0.45);
121 for (int k
= 0; k
< 3; k
++) {
128 } else if (input
[k
] <= 0) {
133 int index1
= ale_real_to_int(input
[k
], 65535);
135 int index2
= index1
>> (16 - table_bits
);
136 int index3
= (index1
>> (16 - table_bits
- interp_bits
))
137 & ((1 << interp_bits
) - 1);
139 if (index2
>= table_size
- 1) {
144 ale_real frac
= ale_real_from_int((index3
<< (16 - interp_bits
)), 65535);
146 result
[k
] = (1 - frac
) * table
[index2
] + frac
* table
[index2
+ 1];