1
/* ============================================================
3
* This file is a part of digiKam project
4
* http://www.digikam.org
7
* Description : LDR ToneMapper <http://zynaddsubfx.sourceforge.net/other/tonemapping>.
9
* Copyright (C) 2009 by Nasca Octavian Paul <zynaddsubfx at yahoo dot com>
10
* Copyright (C) 2009 by Gilles Caulier <caulier dot gilles at gmail dot com>
12
* This program is free software; you can redistribute it
13
* and/or modify it under the terms of the GNU General
14
* Public License as published by the Free Software Foundation;
15
* either version 2, or (at your option)
18
* This program is distributed in the hope that it will be useful,
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
* GNU General Public License for more details.
23
* ============================================================ */
38
#include "tonemappingparameters.h"
41
#pragma warning ( disable : 4800 ) // forcing value to bool 'true' or 'false' (performance warning)
44
namespace DigikamLocalContrastImagesPlugin
47
class ToneMappingParametersPriv
51
ToneMappingParametersPriv()
58
/** To cancel computation from user interface.
62
/** For progress CallBack method from User interface
64
ToneMappingCallbackPtr callBack;
68
ToneMappingParameters::ToneMappingParameters()
70
d = new ToneMappingParametersPriv;
72
info_fast_mode = true;
73
high_saturation = 100;
75
stretch_contrast = true;
78
for (int i = 0 ; i < TONEMAPPING_MAX_STAGES ; i++)
80
stage[i].enabled = (i == 0);
81
stage[i].power = 30.0;
85
unsharp_mask.enabled = false;
86
unsharp_mask.power = 30.0;
87
unsharp_mask.blur = 4.0;
88
unsharp_mask.threshold = 0;
91
ToneMappingParameters::~ToneMappingParameters()
96
ToneMappingParameters& ToneMappingParameters::operator=(const ToneMappingParameters& prm)
102
bool ToneMappingParameters::cancel()
110
void ToneMappingParameters::setCancel(bool* b)
115
void ToneMappingParameters::setProgressCallBackFunction(void* data, ToneMappingCallbackPtr cb)
121
void ToneMappingParameters::postProgress(int progress)
123
d->callBack(d->data, progress);
126
REALTYPE ToneMappingParameters::get_power(int nstage)
128
REALTYPE power = stage[nstage].power;
129
power = (REALTYPE)(pow(power/100.0, 1.5)*100.0);
133
REALTYPE ToneMappingParameters::get_blur(int nstage)
135
return stage[nstage].blur;
138
REALTYPE ToneMappingParameters::get_unsharp_mask_power()
140
REALTYPE power = unsharp_mask.power;
141
power = (REALTYPE)(pow(power/100.0, 3.0)*10.0);
145
REALTYPE ToneMappingParameters::get_unsharp_mask_blur()
147
return unsharp_mask.blur;
150
void ToneMappingParameters::save_parameters(const char* filename)
152
FILE *f = fopen(filename, "w");
154
fprintf(f, "Tonemapping_by_PAUL\n");
155
fprintf(f, "1\n");//version
157
fprintf(f, "info_fast_mode %d\n", info_fast_mode);
158
fprintf(f, "low_saturation %d\n", low_saturation);
159
fprintf(f, "high_saturation %d\n", high_saturation);
160
fprintf(f, "stretch_contrast %d\n", stretch_contrast);
161
fprintf(f, "function_id %d\n", function_id);
163
for (int i=0 ; i < TONEMAPPING_MAX_STAGES ; i++)
165
fprintf(f, "STAGE %d\n", i);
166
fprintf(f, "enabled %d\n", stage[i].enabled);
167
fprintf(f, "power %g\n", stage[i].power);
168
fprintf(f, "blur %g\n", stage[i].blur);
171
fprintf(f, "unsharp_mask_enabled %d\n", unsharp_mask.enabled);
172
fprintf(f, "unsharp_mask_power %g\n", unsharp_mask.power);
173
fprintf(f, "unsharp_mask_blur %g\n", unsharp_mask.blur);
174
fprintf(f, "unsharp_mask_threshold %d\n", unsharp_mask.threshold);
179
bool ToneMappingParameters::load_parameters(const char* filename)
181
FILE *f = fopen(filename, "r");
182
if (!f) return false;
184
const int max_line = 1024;
188
fgets(line, max_line, f);
189
if (feof(f)) return false;
190
if (strstr(line, "Tonemapping_by_PAUL") != line) return false;
191
fgets(line, max_line, f);//version
192
int current_stage = 0;
196
for (int i = 0 ; i < max_line ; i++)
199
fgets(line, max_line-1,f);
201
if (strlen(line) < 3) continue;
204
for (int i=0 ; i < max_line ; i++)
214
const char *par = line;
215
const char *sval = &line[space];
216
int ipar = atoi(sval);
217
REALTYPE fpar = (REALTYPE)(atof(sval));
219
if (strstr(par, "info_fast_mode") == par) info_fast_mode = ipar;
220
if (strstr(par, "low_saturation") == par) low_saturation = ipar;
221
if (strstr(par, "high_saturation") == par) high_saturation = ipar;
222
if (strstr(par, "stretch_contrast") == par) stretch_contrast = ipar;
223
if (strstr(par, "function_id") == par) function_id = ipar;
225
if (strstr(par, "STAGE") == par)
227
if (ipar < 0) ipar = 0;
228
if (ipar > (TONEMAPPING_MAX_STAGES-1)) ipar = TONEMAPPING_MAX_STAGES-1;
229
current_stage = ipar;
232
if (strstr(par, "enabled") == par) stage[current_stage].enabled = ipar;
233
if (strstr(par, "power") == par) stage[current_stage].power = fpar;
234
if (strstr(par, "blur") == par) stage[current_stage].blur = fpar;
236
if (strstr(par, "unsharp_mask_enabled") == par) unsharp_mask.enabled = ipar;
237
if (strstr(par, "unsharp_mask_power") == par) unsharp_mask.power = fpar;
238
if (strstr(par, "unsharp_mask_blur") == par) unsharp_mask.blur = fpar;
239
if (strstr(par, "unsharp_mask_threshold") == par) unsharp_mask.threshold = ipar;
247
} // namespace DigikamNoiseReductionImagesPlugin