File indexing completed on 2025-01-19 03:50:56
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2009-11-21 0007 * Description : Wavelets Noise Reduction batch tool. 0008 * 0009 * SPDX-FileCopyrightText: 2009-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #include "noisereduction.h" 0016 0017 // Qt includes 0018 0019 #include <QWidget> 0020 0021 // KDE includes 0022 0023 #include <klocalizedstring.h> 0024 0025 // Local includes 0026 0027 #include "dimg.h" 0028 #include "nrestimate.h" 0029 #include "nrfilter.h" 0030 0031 namespace DigikamBqmNoiseReductionPlugin 0032 { 0033 0034 NoiseReduction::NoiseReduction(QObject* const parent) 0035 : BatchTool (QLatin1String("NoiseReduction"), EnhanceTool, parent), 0036 m_settingsView(nullptr) 0037 { 0038 } 0039 0040 NoiseReduction::~NoiseReduction() 0041 { 0042 } 0043 0044 BatchTool* NoiseReduction::clone(QObject* const parent) const 0045 { 0046 return new NoiseReduction(parent); 0047 } 0048 0049 void NoiseReduction::registerSettingsWidget() 0050 { 0051 m_settingsWidget = new QWidget; 0052 m_settingsView = new NRSettings(m_settingsWidget); 0053 0054 connect(m_settingsView, SIGNAL(signalEstimateNoise()), 0055 this, SLOT(slotSettingsChanged())); 0056 0057 connect(m_settingsView, SIGNAL(signalSettingsChanged()), 0058 this, SLOT(slotSettingsChanged())); 0059 0060 BatchTool::registerSettingsWidget(); 0061 } 0062 0063 BatchToolSettings NoiseReduction::defaultSettings() 0064 { 0065 BatchToolSettings prm; 0066 NRContainer defaultPrm = m_settingsView->defaultSettings(); 0067 0068 prm.insert(QLatin1String("YThreshold"), (double)defaultPrm.thresholds[0]); 0069 prm.insert(QLatin1String("CrThreshold"), (double)defaultPrm.thresholds[1]); 0070 prm.insert(QLatin1String("CbThreshold"), (double)defaultPrm.thresholds[2]); 0071 prm.insert(QLatin1String("YSoftness"), (double)defaultPrm.softness[0]); 0072 prm.insert(QLatin1String("CrSoftness"), (double)defaultPrm.softness[1]); 0073 prm.insert(QLatin1String("CbSoftness"), (double)defaultPrm.softness[2]); 0074 prm.insert(QLatin1String("EstimateNoise"), false); 0075 0076 return prm; 0077 } 0078 0079 void NoiseReduction::slotAssignSettings2Widget() 0080 { 0081 NRContainer prm; 0082 prm.thresholds[0] = settings()[QLatin1String("YThreshold")].toDouble(); 0083 prm.thresholds[1] = settings()[QLatin1String("CrThreshold")].toDouble(); 0084 prm.thresholds[2] = settings()[QLatin1String("CbThreshold")].toDouble(); 0085 prm.softness[0] = settings()[QLatin1String("YSoftness")].toDouble(); 0086 prm.softness[1] = settings()[QLatin1String("CrSoftness")].toDouble(); 0087 prm.softness[2] = settings()[QLatin1String("CbSoftness")].toDouble(); 0088 m_settingsView->setSettings(prm); 0089 m_settingsView->setEstimateNoise(settings()[QLatin1String("EstimateNoise")].toBool()); 0090 } 0091 0092 void NoiseReduction::slotSettingsChanged() 0093 { 0094 BatchToolSettings prm; 0095 NRContainer currentPrm = m_settingsView->settings(); 0096 0097 prm.insert(QLatin1String("YThreshold"), (double)currentPrm.thresholds[0]); 0098 prm.insert(QLatin1String("CrThreshold"), (double)currentPrm.thresholds[1]); 0099 prm.insert(QLatin1String("CbThreshold"), (double)currentPrm.thresholds[2]); 0100 prm.insert(QLatin1String("YSoftness"), (double)currentPrm.softness[0]); 0101 prm.insert(QLatin1String("CrSoftness"), (double)currentPrm.softness[1]); 0102 prm.insert(QLatin1String("CbSoftness"), (double)currentPrm.softness[2]); 0103 prm.insert(QLatin1String("EstimateNoise"), m_settingsView->estimateNoise()); 0104 0105 BatchTool::slotSettingsChanged(prm); 0106 } 0107 0108 bool NoiseReduction::toolOperations() 0109 { 0110 if (!loadToDImg()) 0111 { 0112 return false; 0113 } 0114 0115 NRContainer prm; 0116 0117 if (settings()[QLatin1String("EstimateNoise")].toBool()) 0118 { 0119 NREstimate nre(&image()); 0120 nre.startFilterDirectly(); 0121 prm = nre.settings(); 0122 } 0123 else 0124 { 0125 prm.thresholds[0] = settings()[QLatin1String("YThreshold")].toDouble(); 0126 prm.thresholds[1] = settings()[QLatin1String("CrThreshold")].toDouble(); 0127 prm.thresholds[2] = settings()[QLatin1String("CbThreshold")].toDouble(); 0128 prm.softness[0] = settings()[QLatin1String("YSoftness")].toDouble(); 0129 prm.softness[1] = settings()[QLatin1String("CrSoftness")].toDouble(); 0130 prm.softness[2] = settings()[QLatin1String("CbSoftness")].toDouble(); 0131 } 0132 0133 NRFilter wnr(&image(), nullptr, prm); 0134 applyFilter(&wnr); 0135 0136 return (savefromDImg()); 0137 } 0138 0139 } // namespace DigikamBqmNoiseReductionPlugin 0140 0141 #include "moc_noisereduction.cpp"