| 1 |
/* ============================================================ |
| 2 |
* |
| 3 |
* This file is a part of digiKam project |
| 4 |
* https://www.digikam.org |
| 5 |
* |
| 6 |
* Date : 2009-11-21 |
| 7 |
* Description : Wavelets Noise Reduction batch tool. |
| 8 |
* |
| 9 |
* SPDX-FileCopyrightText: 2009-2026 by Gilles Caulier <caulier dot gilles at gmail dot com> |
| 10 |
* |
| 11 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 12 |
* |
| 13 |
* ============================================================ */ |
| 14 |
|
| 15 |
#include "noisereduction.h" |
| 16 |
|
| 17 |
// Qt includes |
| 18 |
|
| 19 |
#include <QWidget> |
| 20 |
|
| 21 |
// KDE includes |
| 22 |
|
| 23 |
#include <klocalizedstring.h> |
| 24 |
|
| 25 |
// Local includes |
| 26 |
|
| 27 |
#include "dimg.h" |
| 28 |
#include "nrestimate.h" |
| 29 |
#include "nrfilter.h" |
| 30 |
|
| 31 |
namespace DigikamBqmNoiseReductionPlugin |
| 32 |
{ |
| 33 |
|
| 34 |
NoiseReduction::NoiseReduction(QObject* const parent) |
| 35 |
: BatchTool (QLatin1String("NoiseReduction"), EnhanceTool, parent) |
| 36 |
{ |
| 37 |
} |
| 38 |
|
| 39 |
BatchTool* NoiseReduction::clone(QObject* const parent) const |
| 40 |
{ |
| 41 |
return new NoiseReduction(parent); |
| 42 |
} |
| 43 |
|
| 44 |
void NoiseReduction::registerSettingsWidget() |
| 45 |
{ |
| 46 |
m_settingsWidget = new QWidget; |
| 47 |
m_settingsView = new NRSettings(m_settingsWidget); |
| 48 |
|
| 49 |
connect(m_settingsView, SIGNAL(signalEstimateNoise()), |
| 50 |
this, SLOT(slotSettingsChanged())); |
| 51 |
|
| 52 |
connect(m_settingsView, SIGNAL(signalSettingsChanged()), |
| 53 |
this, SLOT(slotSettingsChanged())); |
| 54 |
|
| 55 |
BatchTool::registerSettingsWidget(); |
| 56 |
} |
| 57 |
|
| 58 |
BatchToolSettings NoiseReduction::defaultSettings() |
| 59 |
{ |
| 60 |
BatchToolSettings prm; |
| 61 |
NRContainer defaultPrm = m_settingsView->defaultSettings(); |
| 62 |
|
| 63 |
prm.insert(QLatin1String("YThreshold"), (double)defaultPrm.thresholds[0]); |
| 64 |
prm.insert(QLatin1String("CrThreshold"), (double)defaultPrm.thresholds[1]); |
| 65 |
prm.insert(QLatin1String("CbThreshold"), (double)defaultPrm.thresholds[2]); |
| 66 |
prm.insert(QLatin1String("YSoftness"), (double)defaultPrm.softness[0]); |
| 67 |
prm.insert(QLatin1String("CrSoftness"), (double)defaultPrm.softness[1]); |
| 68 |
prm.insert(QLatin1String("CbSoftness"), (double)defaultPrm.softness[2]); |
| 69 |
prm.insert(QLatin1String("EstimateNoise"), false); |
| 70 |
|
| 71 |
return prm; |
| 72 |
} |
| 73 |
|
| 74 |
void NoiseReduction::slotAssignSettings2Widget() |
| 75 |
{ |
| 76 |
NRContainer prm; |
| 77 |
prm.thresholds[0] = settings().value(QLatin1String("YThreshold")).toDouble(); |
| 78 |
prm.thresholds[1] = settings().value(QLatin1String("CrThreshold")).toDouble(); |
| 79 |
prm.thresholds[2] = settings().value(QLatin1String("CbThreshold")).toDouble(); |
| 80 |
prm.softness[0] = settings().value(QLatin1String("YSoftness")).toDouble(); |
| 81 |
prm.softness[1] = settings().value(QLatin1String("CrSoftness")).toDouble(); |
| 82 |
prm.softness[2] = settings().value(QLatin1String("CbSoftness")).toDouble(); |
| 83 |
m_settingsView->setSettings(prm); |
| 84 |
m_settingsView->setEstimateNoise(settings().value(QLatin1String("EstimateNoise")).toBool()); |
| 85 |
} |
| 86 |
|
| 87 |
void NoiseReduction::slotSettingsChanged() |
| 88 |
{ |
| 89 |
BatchToolSettings prm; |
| 90 |
NRContainer currentPrm = m_settingsView->settings(); |
| 91 |
|
| 92 |
prm.insert(QLatin1String("YThreshold"), (double)currentPrm.thresholds[0]); |
| 93 |
prm.insert(QLatin1String("CrThreshold"), (double)currentPrm.thresholds[1]); |
| 94 |
prm.insert(QLatin1String("CbThreshold"), (double)currentPrm.thresholds[2]); |
| 95 |
prm.insert(QLatin1String("YSoftness"), (double)currentPrm.softness[0]); |
| 96 |
prm.insert(QLatin1String("CrSoftness"), (double)currentPrm.softness[1]); |
| 97 |
prm.insert(QLatin1String("CbSoftness"), (double)currentPrm.softness[2]); |
| 98 |
prm.insert(QLatin1String("EstimateNoise"), m_settingsView->estimateNoise()); |
| 99 |
|
| 100 |
BatchTool::slotSettingsChanged(prm); |
| 101 |
} |
| 102 |
|
| 103 |
bool NoiseReduction::toolOperations() |
| 104 |
{ |
| 105 |
if (!loadToDImg()) |
| 106 |
{ |
| 107 |
return false; |
| 108 |
} |
| 109 |
|
| 110 |
NRContainer prm; |
| 111 |
|
| 112 |
if (settings().value(QLatin1String("EstimateNoise")).toBool()) |
| 113 |
{ |
| 114 |
NREstimate nre(&image()); |
| 115 |
nre.startFilterDirectly(); |
| 116 |
prm = nre.settings(); |
| 117 |
} |
| 118 |
else |
| 119 |
{ |
| 120 |
prm.thresholds[0] = settings().value(QLatin1String("YThreshold")).toDouble(); |
| 121 |
prm.thresholds[1] = settings().value(QLatin1String("CrThreshold")).toDouble(); |
| 122 |
prm.thresholds[2] = settings().value(QLatin1String("CbThreshold")).toDouble(); |
| 123 |
prm.softness[0] = settings().value(QLatin1String("YSoftness")).toDouble(); |
| 124 |
prm.softness[1] = settings().value(QLatin1String("CrSoftness")).toDouble(); |
| 125 |
prm.softness[2] = settings().value(QLatin1String("CbSoftness")).toDouble(); |
| 126 |
} |
| 127 |
|
| 128 |
NRFilter wnr(&image(), nullptr, prm); |
| 129 |
applyFilter(&wnr); |
| 130 |
|
| 131 |
return (savefromDImg()); |
| 132 |
} |
| 133 |
|
| 134 |
} // namespace DigikamBqmNoiseReductionPlugin |
| 135 |
|
| 136 |
#include "moc_noisereduction.cpp" |