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-02-19 0007 * Description : Restoration 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 "restoration.h" 0016 0017 // Qt includes 0018 0019 #include <QLabel> 0020 #include <QWidget> 0021 #include <QComboBox> 0022 #include <QStandardPaths> 0023 0024 // KDE includes 0025 0026 #include <klocalizedstring.h> 0027 0028 // Local includes 0029 0030 #include "dlayoutbox.h" 0031 #include "dimg.h" 0032 #include "dactivelabel.h" 0033 0034 namespace DigikamBqmRestorationPlugin 0035 { 0036 0037 Restoration::Restoration(QObject* const parent) 0038 : BatchTool(QLatin1String("Restoration"), EnhanceTool, parent), 0039 m_comboBox (nullptr), 0040 m_cimgIface(nullptr) 0041 { 0042 } 0043 0044 Restoration::~Restoration() 0045 { 0046 } 0047 0048 BatchTool* Restoration::clone(QObject* const parent) const 0049 { 0050 return new Restoration(parent); 0051 } 0052 0053 void Restoration::registerSettingsWidget() 0054 { 0055 DVBox* const vbox = new DVBox; 0056 0057 DActiveLabel* const cimgLogoLabel = new DActiveLabel(QUrl(QLatin1String("http://cimg.sourceforge.net")), // krazy:exclude=insecurenet 0058 QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1String("digikam/data/logo-cimg.png")), 0059 vbox); 0060 cimgLogoLabel->setToolTip(i18n("Visit CImg library website")); 0061 0062 new QLabel(i18n("Filter:"), vbox); 0063 m_comboBox = new QComboBox(vbox); 0064 m_comboBox->insertItem(ReduceUniformNoise, i18n("Reduce Uniform Noise")); 0065 m_comboBox->insertItem(ReduceJPEGArtefacts, i18n("Reduce JPEG Artifacts")); 0066 m_comboBox->insertItem(ReduceTexturing, i18n("Reduce Texturing")); 0067 m_comboBox->setWhatsThis(i18n("<p>Select the filter preset to use for photograph restoration here:</p>" 0068 "<p><b>None</b>: Most common values. Puts settings to default.<br/>" 0069 "<b>Reduce Uniform Noise</b>: reduce small image artifacts such as sensor noise.<br/>" 0070 "<b>Reduce JPEG Artifacts</b>: reduce large image artifacts, such as a JPEG compression mosaic.<br/>" 0071 "<b>Reduce Texturing</b>: reduce image artifacts, such as paper texture, or Moire patterns " 0072 "on scanned images.</p>")); 0073 0074 QLabel* const space = new QLabel(vbox); 0075 vbox->setStretchFactor(space, 10); 0076 0077 m_settingsWidget = vbox; 0078 0079 connect(m_comboBox, SIGNAL(activated(int)), 0080 this, SLOT(slotSettingsChanged())); 0081 0082 BatchTool::registerSettingsWidget(); 0083 } 0084 0085 BatchToolSettings Restoration::defaultSettings() 0086 { 0087 BatchToolSettings settings; 0088 settings.insert(QLatin1String("RestorationMethod"), ReduceUniformNoise); 0089 0090 return settings; 0091 } 0092 0093 void Restoration::slotAssignSettings2Widget() 0094 { 0095 m_comboBox->setCurrentIndex(settings()[QLatin1String("RestorationMethod")].toInt()); 0096 } 0097 0098 void Restoration::slotSettingsChanged() 0099 { 0100 BatchToolSettings settings; 0101 settings.insert(QLatin1String("RestorationMethod"), (int)m_comboBox->currentIndex()); 0102 BatchTool::slotSettingsChanged(settings); 0103 } 0104 0105 bool Restoration::toolOperations() 0106 { 0107 if (!loadToDImg()) 0108 { 0109 return false; 0110 } 0111 0112 int type = settings()[QLatin1String("RestorationMethod")].toInt(); 0113 0114 GreycstorationContainer settings; 0115 settings.setRestorationDefaultSettings(); 0116 0117 switch (type) 0118 { 0119 case ReduceUniformNoise: 0120 { 0121 settings.amplitude = 40.0; 0122 break; 0123 } 0124 0125 case ReduceJPEGArtefacts: 0126 { 0127 settings.sharpness = 0.3F; 0128 settings.sigma = 1.0; 0129 settings.amplitude = 100.0; 0130 settings.nbIter = 2; 0131 break; 0132 } 0133 0134 case ReduceTexturing: 0135 { 0136 settings.sharpness = 0.5F; 0137 settings.sigma = 1.5; 0138 settings.amplitude = 100.0; 0139 settings.nbIter = 2; 0140 break; 0141 } 0142 } 0143 0144 m_cimgIface = new GreycstorationFilter(this); 0145 m_cimgIface->setMode(GreycstorationFilter::Restore); 0146 m_cimgIface->setOriginalImage(image()); 0147 m_cimgIface->setSettings(settings); 0148 m_cimgIface->setup(); 0149 0150 applyFilter(m_cimgIface); 0151 0152 delete m_cimgIface; 0153 m_cimgIface = nullptr; 0154 0155 return (savefromDImg()); 0156 } 0157 0158 void Restoration::cancel() 0159 { 0160 if (m_cimgIface) 0161 { 0162 m_cimgIface->cancelFilter(); 0163 } 0164 0165 BatchTool::cancel(); 0166 } 0167 0168 } // namespace DigikamBqmRestorationPlugin 0169 0170 #include "moc_restoration.cpp"