1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428 | /* ============================================================
*
* This file is a part of digiKam project
* https://www.digikam.org
*
* Date : 2009-11-22
* Description : noise reduction settings view.
*
* SPDX-FileCopyrightText: 2009-2026 by Gilles Caulier <caulier dot gilles at gmail dot com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* ============================================================ */
#include "nrsettings.h"
// Qt includes
#include <QGridLayout>
#include <QLabel>
#include <QString>
#include <QFile>
#include <QTextStream>
#include <QCheckBox>
#include <QUrl>
#include <QApplication>
#include <QStyle>
#include <QStandardPaths>
#include <QMessageBox>
// KDE includes
#include <kconfiggroup.h>
#include <klocalizedstring.h>
// Local includes
#include "dexpanderbox.h"
#include "dfiledialog.h"
#include "dnuminput.h"
#include "digikam_debug.h"
namespace Digikam
{
class Q_DECL_HIDDEN NRSettings::Private
{
public:
Private() = default;
const QString configThrLumInputAdjustmentEntry = QLatin1String("ThrLumAdjustment");
const QString configSoftLumInputAdjustmentEntry = QLatin1String("SoftLumAdjustment");
const QString configThrCrInputAdjustmentEntry = QLatin1String("ThrCrAdjustment");
const QString configSoftCrInputAdjustmentEntry = QLatin1String("SoftCrAdjustment");
const QString configThrCbInputAdjustmentEntry = QLatin1String("ThrCbAdjustment");
const QString configSoftCbInputAdjustmentEntry = QLatin1String("SoftCbAdjustment");
const QString configCheckAutoEstimationEntry = QLatin1String("AutoNRAdjustment");
QWidget* luminanceBox = nullptr;
QWidget* chrominanceRedBox = nullptr;
QWidget* chrominanceBlueBox = nullptr;
QCheckBox* checkAutoEst = nullptr;
DExpanderBox* advExpanderBox = nullptr;
DDoubleNumInput* thrLumInput = nullptr;
DDoubleNumInput* softLumInput = nullptr;
DDoubleNumInput* thrCrInput = nullptr;
DDoubleNumInput* softCrInput = nullptr;
DDoubleNumInput* thrCbInput = nullptr;
DDoubleNumInput* softCbInput = nullptr;
};
// --------------------------------------------------------
NRSettings::NRSettings(QWidget* const parent)
: QWidget(parent),
d (new Private)
{
const int spacing = layoutSpacing();
QGridLayout* const grid = new QGridLayout(parent);
QString thHelp = i18n("<b>Threshold</b>: Adjusts the threshold for denoising of "
"the image in a range from 0.0 (none) to 10.0. "
"The threshold is the value below which everything is considered noise.");
QString soHelp = i18n("<b>Softness</b>: This adjusts the softness of the thresholding "
"(soft as opposed to hard thresholding). The higher the softness "
"the more noise remains in the image.");
// -------------------------------------------------------------
d->checkAutoEst = new QCheckBox(i18n("Estimate Noise"));
d->checkAutoEst->setWhatsThis( i18n("Compute automatically all noise reduction settings by a parse of "
"noise contained in image."));
d->advExpanderBox = new DExpanderBox;
d->advExpanderBox->setObjectName(QLatin1String("Noise Reduction Settings Expander"));
// -------------------------------------------------------------
d->luminanceBox = new QWidget(d->advExpanderBox);
QGridLayout* const lumLay = new QGridLayout(d->luminanceBox);
QLabel* const label3 = new QLabel(i18n("Threshold:"), d->luminanceBox);
d->thrLumInput = new DDoubleNumInput(d->luminanceBox);
d->thrLumInput->setDecimals(2);
d->thrLumInput->setRange(0.0, 10.0, 0.1);
d->thrLumInput->setDefaultValue(1.2);
d->thrLumInput->setWhatsThis(thHelp);
QLabel* const label4 = new QLabel(i18n("Softness:"), d->luminanceBox);
d->softLumInput = new DDoubleNumInput(d->luminanceBox);
d->softLumInput->setDecimals(1);
d->softLumInput->setRange(0.0, 1.0, 0.1);
d->softLumInput->setDefaultValue(0.9);
d->softLumInput->setWhatsThis(soHelp);
lumLay->addWidget(label3, 0, 0, 1, 1);
lumLay->addWidget(d->thrLumInput, 0, 1, 1, 1);
lumLay->addWidget(label4, 1, 0, 1, 1);
lumLay->addWidget(d->softLumInput, 1, 1, 1, 1);
lumLay->setRowStretch(2, 10);
lumLay->setContentsMargins(spacing, spacing, spacing, spacing);
lumLay->setSpacing(0);
// -------------------------------------------------------------
d->chrominanceRedBox = new QWidget(d->advExpanderBox);
QGridLayout* const cRedLay = new QGridLayout(d->chrominanceRedBox);
QLabel* const label5 = new QLabel(i18n("Threshold:"), d->chrominanceRedBox);
d->thrCrInput = new DDoubleNumInput(d->chrominanceRedBox);
d->thrCrInput->setDecimals(2);
d->thrCrInput->setRange(0.0, 10.0, 0.1);
d->thrCrInput->setDefaultValue(1.2);
d->thrCrInput->setWhatsThis(thHelp);
QLabel* const label6 = new QLabel(i18n("Softness:"), d->chrominanceRedBox);
d->softCrInput = new DDoubleNumInput(d->chrominanceRedBox);
d->softCrInput->setDecimals(1);
d->softCrInput->setRange(0.0, 1.0, 0.1);
d->softCrInput->setDefaultValue(0.9);
d->softCrInput->setWhatsThis(soHelp);
cRedLay->addWidget(label5, 0, 0, 1, 1);
cRedLay->addWidget(d->thrCrInput, 0, 1, 1, 1);
cRedLay->addWidget(label6, 1, 0, 1, 1);
cRedLay->addWidget(d->softCrInput, 1, 1, 1, 1);
cRedLay->setRowStretch(2, 10);
cRedLay->setContentsMargins(spacing, spacing, spacing, spacing);
cRedLay->setSpacing(0);
// -------------------------------------------------------------
d->chrominanceBlueBox = new QWidget(d->advExpanderBox);
QGridLayout* const cBlueLay = new QGridLayout(d->chrominanceBlueBox);
QLabel* const label7 = new QLabel(i18n("Threshold:"), d->chrominanceBlueBox);
d->thrCbInput = new DDoubleNumInput(d->chrominanceBlueBox);
d->thrCbInput->setDecimals(2);
d->thrCbInput->setRange(0.0, 10.0, 0.1);
d->thrCbInput->setDefaultValue(1.2);
d->thrCbInput->setWhatsThis(thHelp);
QLabel* const label8 = new QLabel(i18n("Softness:"), d->chrominanceBlueBox);
d->softCbInput = new DDoubleNumInput(d->chrominanceBlueBox);
d->softCbInput->setDecimals(1);
d->softCbInput->setRange(0.0, 1.0, 0.1);
d->softCbInput->setDefaultValue(0.9);
d->softCbInput->setWhatsThis(soHelp);
cBlueLay->addWidget(label7, 0, 0, 1, 1);
cBlueLay->addWidget(d->thrCbInput, 0, 1, 1, 1);
cBlueLay->addWidget(label8, 1, 0, 1, 1);
cBlueLay->addWidget(d->softCbInput, 1, 1, 1, 1);
cBlueLay->setRowStretch(2, 10);
cBlueLay->setContentsMargins(spacing, spacing, spacing, spacing);
cBlueLay->setSpacing(0);
// -------------------------------------------------------------
d->advExpanderBox->addItem(d->luminanceBox,
QIcon(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1String("digikam/data/colors-luma.png"))),
i18n("Luminance"),
QLatin1String("Luminance"), true);
d->advExpanderBox->addItem(d->chrominanceBlueBox,
QIcon(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1String("digikam/data/colors-chromablue.png"))),
i18n("Chrominance Blue"),
QLatin1String("ChrominanceBlue"), true);
d->advExpanderBox->addItem(d->chrominanceRedBox,
QIcon(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1String("digikam/data/colors-chromared.png"))),
i18n("Chrominance Red"),
QLatin1String("ChrominanceRed"), true);
d->advExpanderBox->addStretch();
// -------------------------------------------------------------
grid->addWidget(d->checkAutoEst, 0, 0, 1, 2);
grid->addWidget(d->advExpanderBox, 1, 0, 1, 2);
grid->setRowStretch(1, 10);
grid->setContentsMargins(spacing, spacing, spacing, spacing);
grid->setSpacing(spacing);
// -------------------------------------------------------------
connect(d->checkAutoEst, SIGNAL(clicked(bool)),
this, SLOT(slotDisableParameters(bool)));
connect(d->thrLumInput, SIGNAL(valueChanged(double)),
this, SIGNAL(signalSettingsChanged()));
connect(d->softLumInput, SIGNAL(valueChanged(double)),
this, SIGNAL(signalSettingsChanged()));
connect(d->thrCrInput, SIGNAL(valueChanged(double)),
this, SIGNAL(signalSettingsChanged()));
connect(d->softCrInput, SIGNAL(valueChanged(double)),
this, SIGNAL(signalSettingsChanged()));
connect(d->thrCbInput, SIGNAL(valueChanged(double)),
this, SIGNAL(signalSettingsChanged()));
connect(d->softCbInput, SIGNAL(valueChanged(double)),
this, SIGNAL(signalSettingsChanged()));
}
NRSettings::~NRSettings()
{
delete d;
}
void NRSettings::setEstimateNoise(bool b)
{
d->checkAutoEst->setChecked(b);
}
bool NRSettings::estimateNoise() const
{
return d->checkAutoEst->isChecked();
}
void NRSettings::slotDisableParameters(bool b)
{
d->luminanceBox->setDisabled(b);
d->chrominanceRedBox->setDisabled(b);
d->chrominanceBlueBox->setDisabled(b);
qApp->processEvents();
if (b)
{
Q_EMIT signalEstimateNoise();
}
}
NRContainer NRSettings::settings() const
{
NRContainer prm;
prm.thresholds[0] = d->thrLumInput->value();
prm.thresholds[1] = d->thrCbInput->value();
prm.thresholds[2] = d->thrCrInput->value();
prm.softness[0] = 1.0 - d->softLumInput->value();
prm.softness[1] = 1.0 - d->softCbInput->value();
prm.softness[2] = 1.0 - d->softCrInput->value();
return prm;
}
void NRSettings::setSettings(const NRContainer& settings)<--- Shadow argument
{
blockSignals(true);
d->thrLumInput->setValue(settings.thresholds[0]);
d->thrCbInput->setValue(settings.thresholds[1]);
d->thrCrInput->setValue(settings.thresholds[2]);
d->softLumInput->setValue(1.0 - settings.softness[0]);
d->softCbInput->setValue(1.0 - settings.softness[1]);
d->softCrInput->setValue(1.0 - settings.softness[2]);
blockSignals(false);
}
void NRSettings::resetToDefault()
{
blockSignals(true);
d->checkAutoEst->setChecked(false);
d->thrLumInput->slotReset();
d->softLumInput->slotReset();
d->thrCbInput->slotReset();
d->softCbInput->slotReset();
d->thrCrInput->slotReset();
d->softCrInput->slotReset();
blockSignals(false);
}
NRContainer NRSettings::defaultSettings() const
{
NRContainer prm;
prm.thresholds[0] = d->thrLumInput->defaultValue();
prm.thresholds[1] = d->thrCbInput->defaultValue();
prm.thresholds[2] = d->thrCrInput->defaultValue();
prm.softness[0] = 1.0 - d->softLumInput->defaultValue();
prm.softness[1] = 1.0 - d->softCbInput->defaultValue();
prm.softness[2] = 1.0 - d->softCrInput->defaultValue();
return prm;
}
void NRSettings::readSettings(const KConfigGroup& group)
{
NRContainer prm;
NRContainer defaultPrm = defaultSettings();
prm.thresholds[0] = group.readEntry(d->configThrLumInputAdjustmentEntry, defaultPrm.thresholds[0]);
prm.thresholds[1] = group.readEntry(d->configThrCbInputAdjustmentEntry, defaultPrm.thresholds[1]);
prm.thresholds[2] = group.readEntry(d->configThrCrInputAdjustmentEntry, defaultPrm.thresholds[2]);
prm.softness[0] = group.readEntry(d->configSoftLumInputAdjustmentEntry, defaultPrm.softness[0]);
prm.softness[1] = group.readEntry(d->configSoftCbInputAdjustmentEntry, defaultPrm.softness[1]);
prm.softness[2] = group.readEntry(d->configSoftCrInputAdjustmentEntry, defaultPrm.softness[2]);
bool b = group.readEntry(d->configCheckAutoEstimationEntry, false);
d->checkAutoEst->setChecked(b);
slotDisableParameters(b);
if (!b)
{
setSettings(prm);
}
}
void NRSettings::writeSettings(KConfigGroup& group)
{
NRContainer prm = settings();
group.writeEntry(d->configThrLumInputAdjustmentEntry, prm.thresholds[0]);
group.writeEntry(d->configThrCbInputAdjustmentEntry, prm.thresholds[1]);
group.writeEntry(d->configThrCrInputAdjustmentEntry, prm.thresholds[2]);
group.writeEntry(d->configSoftLumInputAdjustmentEntry, prm.softness[0]);
group.writeEntry(d->configSoftCbInputAdjustmentEntry, prm.softness[1]);
group.writeEntry(d->configSoftCrInputAdjustmentEntry, prm.softness[2]);
group.writeEntry(d->configCheckAutoEstimationEntry, d->checkAutoEst->isChecked());
}
void NRSettings::loadSettings()
{
QUrl loadRestorationFile = DFileDialog::getOpenFileUrl(qApp->activeWindow(), i18nc("@title:window", "Photograph Noise Reduction Settings File to Load"),
QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)),
QLatin1String("*"));
if (loadRestorationFile.isEmpty())
{
return;
}
QFile file(loadRestorationFile.toLocalFile());
if (file.open(QIODevice::ReadOnly))
{
QTextStream stream(&file);
if (stream.readLine() != QLatin1String("# Photograph Wavelets Noise Reduction Configuration File V2"))
{
QMessageBox::critical(qApp->activeWindow(), qApp->applicationName(),
i18n("\"%1\" is not a Photograph Noise Reduction settings text file.",
loadRestorationFile.fileName()));
file.close();
return;
}
blockSignals(true);
d->thrLumInput->setValue(stream.readLine().toDouble());
d->softLumInput->setValue(stream.readLine().toDouble());
d->thrCrInput->setValue(stream.readLine().toDouble());
d->softCrInput->setValue(stream.readLine().toDouble());
d->thrCbInput->setValue(stream.readLine().toDouble());
d->softCbInput->setValue(stream.readLine().toDouble());
blockSignals(false);
}
else
{
QMessageBox::critical(qApp->activeWindow(), qApp->applicationName(),
i18n("Cannot load settings from the Photograph Noise Reduction text file."));
}
file.close();
}
void NRSettings::saveAsSettings()
{
QUrl saveRestorationFile = DFileDialog::getSaveFileUrl(qApp->activeWindow(), i18nc("@title:window", "Photograph Noise Reduction Settings File to Save"),
QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)),
QLatin1String("*"));
if (saveRestorationFile.isEmpty())
{
return;
}
QFile file(saveRestorationFile.toLocalFile());
if (file.open(QIODevice::WriteOnly))
{
QTextStream stream(&file);
stream << QLatin1String("# Photograph Wavelets Noise Reduction Configuration File V2\n");
stream << d->thrLumInput->value() << QLatin1Char('\n');
stream << d->softLumInput->value() << QLatin1Char('\n');
stream << d->thrCrInput->value() << QLatin1Char('\n');
stream << d->softCrInput->value() << QLatin1Char('\n');
stream << d->thrCbInput->value() << QLatin1Char('\n');
stream << d->softCbInput->value() << QLatin1Char('\n');
}
else
{
QMessageBox::critical(qApp->activeWindow(), qApp->applicationName(),
i18n("Cannot save settings to the Photograph Noise Reduction text file."));
}
file.close();
}
} // namespace Digikam
#include "moc_nrsettings.cpp"
|