1 // ==========================================================
2 // Tone mapping operators
3 //
4 // Design and implementation by
5 // - Herv� Drolon (drolon@infonie.fr)
6 //
7 // This file is part of FreeImage 3
8 //
9 // COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
10 // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
11 // THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
12 // OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
13 // CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
14 // THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
15 // SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
16 // PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
17 // THIS DISCLAIMER.
18 //
19 // Use at your own risk!
20 // ==========================================================
21
22 #include "FreeImage.h"
23 #include "Utilities.h"
24
25 /**
26 Performs a tone mapping on a 48-bit RGB or a 96-bit RGBF image and returns a 24-bit image.
27 The meaning of the parameters depends on the choosen algorithm.
28 When both parameters are set to zero, a default set of parameters is used.
29 @param dib Input RGB/RGBF image
30 @param tmo Tone mapping operator
31 @param first_param First parameter of the algorithm
32 @param second_param Second parameter of the algorithm
33 return Returns a 24-bit tone mapped image if successful, returns NULL otherwise
34 */
35 FIBITMAP * DLL_CALLCONV
FreeImage_ToneMapping(FIBITMAP * dib,FREE_IMAGE_TMO tmo,double first_param,double second_param)36 FreeImage_ToneMapping(FIBITMAP *dib, FREE_IMAGE_TMO tmo, double first_param, double second_param) {
37 if(FreeImage_HasPixels(dib)) {
38 switch(tmo) {
39 // Adaptive logarithmic mapping (F. Drago, 2003)
40 case FITMO_DRAGO03:
41 if((first_param == 0) && (second_param == 0)) {
42 // use default values (gamma = 2.2, exposure = 0)
43 return FreeImage_TmoDrago03(dib, 2.2, 0);
44 } else {
45 // use user's value
46 return FreeImage_TmoDrago03(dib, first_param, second_param);
47 }
48 break;
49 // Dynamic range reduction inspired by photoreceptor phhysiology (E. Reinhard, 2005)
50 case FITMO_REINHARD05:
51 if((first_param == 0) && (second_param == 0)) {
52 // use default values by setting intensity to 0 and contrast to 0
53 return FreeImage_TmoReinhard05(dib, 0, 0);
54 } else {
55 // use user's value
56 return FreeImage_TmoReinhard05(dib, first_param, second_param);
57 }
58 break;
59 // Gradient Domain HDR Compression (R. Fattal, 2002)
60 case FITMO_FATTAL02:
61 if((first_param == 0) && (second_param == 0)) {
62 // use default values by setting color saturation to 0.5 and attenuation to 0.85
63 return FreeImage_TmoFattal02(dib, 0.5, 0.85);
64 } else {
65 // use user's value
66 return FreeImage_TmoFattal02(dib, first_param, second_param);
67 }
68 break;
69 }
70 }
71
72 return NULL;
73 }
74
75
76