~cosme/ubuntu/precise/freeimage/freeimage-3.15.1

« back to all changes in this revision

Viewing changes to Source/FreeImage/tmoDrago03.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cosme Domínguez Díaz
  • Date: 2010-07-20 13:42:15 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100720134215-xt1454zaedv3b604
Tags: 3.13.1-0ubuntu1
* New upstream release. Closes: (LP: #607800)
 - Updated debian/freeimage-get-orig-source script.
 - Removing no longer necessary debian/patches/* and
   the patch system in debian/rules.
 - Updated debian/rules to work with the new Makefiles.
 - Drop from -O3 to -O2 and use lzma compression saves
   ~10 MB of free space. 
* lintian stuff
 - fixed debhelper-but-no-misc-depends
 - fixed ldconfig-symlink-missing-for-shlib

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
Bias function
36
36
*/
37
37
static inline double 
38
 
biasFunction(double b, double x) {
 
38
biasFunction(const double b, const double x) {
39
39
        return pow (x, b);              // pow(x, log(bias)/log(0.5)
40
40
}
41
41
 
46
46
See http://www.nezumi.demon.co.uk/consult/logx.htm
47
47
*/
48
48
static inline double 
49
 
pade_log(double x) {
 
49
pade_log(const double x) {
50
50
        if(x < 1) {
51
51
                return (x * (6 + x) / (6 + 4 * x));
52
 
        } else if(x >= 1 && x < 2) {
 
52
        } else if(x < 2) {
53
53
                return (x * (6 + 0.7662 * x) / (5.9897 + 3.7658 * x));
54
54
        }
55
55
        return log(x + 1);
63
63
@param biasParam Bias parameter (a zero value default to 0.85)
64
64
@param exposure Exposure parameter (default to 0)
65
65
@return Returns TRUE if successful, returns FALSE otherwise
66
 
@see calculateLuminance
67
66
*/
68
67
static BOOL 
69
 
ToneMappingDrago03(FIBITMAP *dib, float maxLum, float avgLum, float biasParam, float exposure) {
 
68
ToneMappingDrago03(FIBITMAP *dib, const float maxLum, const float avgLum, float biasParam, const float exposure) {
70
69
        const float LOG05 = -0.693147F; // log(0.5) 
71
70
 
72
71
        double Lmax, divider, interpol, biasP;
76
75
        if(FreeImage_GetImageType(dib) != FIT_RGBF)
77
76
                return FALSE;
78
77
 
79
 
        unsigned width  = FreeImage_GetWidth(dib);
80
 
        unsigned height = FreeImage_GetHeight(dib);
81
 
        unsigned pitch  = FreeImage_GetPitch(dib);
 
78
        const unsigned width  = FreeImage_GetWidth(dib);
 
79
        const unsigned height = FreeImage_GetHeight(dib);
 
80
        const unsigned pitch  = FreeImage_GetPitch(dib);
82
81
 
83
82
 
84
83
        // arbitrary Bias Parameter 
102
101
                FIRGBF *pixel = (FIRGBF*)bits;
103
102
                for(x = 0; x < width; x++) {
104
103
                        double Yw = pixel[x].red / avgLum;
105
 
                        if(exposure != 1.0) {
106
 
                                Yw *= exposure;
107
 
                        }
 
104
                        Yw *= exposure;
108
105
                        interpol = log(2 + biasFunction(biasP, Yw / Lmax) * 8);
109
106
                        L = pade_log(Yw);// log(Yw + 1)
110
107
                        pixel[x].red = (float)((L / interpol) / divider);
137
134
                                for(j = 0; j < 3; j++) {
138
135
                                        index = (y + i)*fpitch + (x + j);
139
136
                                        image[index].red /= (float)avgLum;
140
 
                                        if (exposure != 1) {
141
 
                                                image[index].red *= exposure; 
142
 
                                        }
 
137
                                        image[index].red *= exposure; 
143
138
                                        average += image[index].red;
144
139
                                }
145
140
                        }
178
173
                FIRGBF *pixel = (FIRGBF*)bits;
179
174
                for(x = max_width; x < width; x++) {
180
175
                        double Yw = pixel[x].red / avgLum;
181
 
                        if(exposure != 1.0) {
182
 
                                Yw *= exposure;
183
 
                        }
 
176
                        Yw *= exposure;
184
177
                        interpol = log(2 + biasFunction(biasP, Yw / Lmax) * 8);
185
178
                        L = pade_log(Yw);// log(Yw + 1)
186
179
                        pixel[x].red = (float)((L / interpol) / divider);
194
187
                FIRGBF *pixel = (FIRGBF*)bits;
195
188
                for(x = 0; x < max_width; x++) {
196
189
                        double Yw = pixel[x].red / avgLum;
197
 
                        if(exposure != 1.0) {
198
 
                                Yw *= exposure;
199
 
                        }
 
190
                        Yw *= exposure;
200
191
                        interpol = log(2 + biasFunction(biasP, Yw / Lmax) * 8);
201
192
                        L = pade_log(Yw);// log(Yw + 1)
202
193
                        pixel[x].red = (float)((L / interpol) / divider);
217
208
@return Returns TRUE if successful, returns FALSE otherwise
218
209
*/
219
210
static BOOL 
220
 
REC709GammaCorrection(FIBITMAP *dib, float gammaval) {
 
211
REC709GammaCorrection(FIBITMAP *dib, const float gammaval) {
221
212
        if(FreeImage_GetImageType(dib) != FIT_RGBF)
222
213
                return FALSE;
223
214
 
224
215
        float slope = 4.5F;
225
216
        float start = 0.018F;
226
217
        
227
 
        float fgamma = (float)((0.45 / gammaval) * 2);
 
218
        const float fgamma = (float)((0.45 / gammaval) * 2);
228
219
        if(gammaval >= 2.1F) {
229
220
                start = (float)(0.018 / ((gammaval - 2) * 7.5));
230
221
                slope = (float)(4.5 * ((gammaval - 2) * 7.5));
233
224
                slope = (float)(4.5 / ((2 - gammaval) * 7.5));
234
225
        }
235
226
 
236
 
        unsigned width  = FreeImage_GetWidth(dib);
237
 
        unsigned height = FreeImage_GetHeight(dib);
238
 
        unsigned pitch  = FreeImage_GetPitch(dib);
 
227
        const unsigned width  = FreeImage_GetWidth(dib);
 
228
        const unsigned height = FreeImage_GetHeight(dib);
 
229
        const unsigned pitch  = FreeImage_GetPitch(dib);
239
230
 
240
231
        BYTE *bits = (BYTE*)FreeImage_GetBits(dib);
241
232
        for(unsigned y = 0; y < height; y++) {
257
248
// ----------------------------------------------------------
258
249
 
259
250
/**
260
 
Apply the Adaptive Logarithmic Mapping operator to a RGBF image and convert to 24-bit RGB
261
 
@param src Input RGBF image
 
251
Apply the Adaptive Logarithmic Mapping operator to a HDR image and convert to 24-bit RGB
 
252
@param src Input RGB16 or RGB[A]F image
262
253
@param gamma Gamma correction (gamma > 0). 1 means no correction, 2.2 in the original paper.
263
254
@param exposure Exposure parameter (0 means no correction, 0 in the original paper)
264
 
If set to FALSE, src is left unchanged: a temporary working image is allocated. 
265
255
@return Returns a 24-bit RGB image if successful, returns NULL otherwise
266
256
*/
267
257
FIBITMAP* DLL_CALLCONV 
277
267
        if(!dib) return NULL;
278
268
 
279
269
        // default algorithm parameters
280
 
        float biasParam = 0.85F;
281
 
        float expoParam = (float)pow(2.0, exposure); //default exposure is 1, 2^0
 
270
        const float biasParam = 0.85F;
 
271
        const float expoParam = (float)pow(2.0, exposure); //default exposure is 1, 2^0
282
272
 
283
273
        // convert to Yxy
284
274
        ConvertInPlaceRGBFToYxy(dib);
298
288
        // clean-up and return
299
289
        FreeImage_Unload(dib);
300
290
 
 
291
        // copy metadata from src to dst
 
292
        FreeImage_CloneMetadata(dst, src);
 
293
        
301
294
        return dst;
302
295
}