| 1 |
/* ============================================================ |
| 2 |
* |
| 3 |
* This file is a part of digiKam project |
| 4 |
* https://www.digikam.org |
| 5 |
* |
| 6 |
* Date : 2009-02-19 |
| 7 |
* Description : Restoration 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 "restoration.h" |
| 16 |
|
| 17 |
// Qt includes |
| 18 |
|
| 19 |
#include <QLabel> |
| 20 |
#include <QWidget> |
| 21 |
#include <QComboBox> |
| 22 |
#include <QStandardPaths> |
| 23 |
|
| 24 |
// KDE includes |
| 25 |
|
| 26 |
#include <klocalizedstring.h> |
| 27 |
|
| 28 |
// Local includes |
| 29 |
|
| 30 |
#include "dlayoutbox.h" |
| 31 |
#include "dimg.h" |
| 32 |
#include "dactivelabel.h" |
| 33 |
|
| 34 |
namespace DigikamBqmRestorationPlugin |
| 35 |
{ |
| 36 |
|
| 37 |
Restoration::Restoration(QObject* const parent) |
| 38 |
: BatchTool(QLatin1String("Restoration"), EnhanceTool, parent) |
| 39 |
{ |
| 40 |
} |
| 41 |
|
| 42 |
BatchTool* Restoration::clone(QObject* const parent) const |
| 43 |
{ |
| 44 |
return new Restoration(parent); |
| 45 |
} |
| 46 |
|
| 47 |
void Restoration::registerSettingsWidget() |
| 48 |
{ |
| 49 |
DVBox* const vbox = new DVBox; |
| 50 |
|
| 51 |
DActiveLabel* const cimgLogoLabel = new DActiveLabel(QUrl(QLatin1String("http://cimg.sourceforge.net")), // krazy:exclude=insecurenet |
| 52 |
QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1String("digikam/data/logo-cimg.webp")), |
| 53 |
vbox); |
| 54 |
cimgLogoLabel->setToolTip(i18n("Visit CImg library website")); |
| 55 |
|
| 56 |
new QLabel(i18n("Filter:"), vbox); |
| 57 |
m_comboBox = new QComboBox(vbox); |
| 58 |
m_comboBox->insertItem(ReduceUniformNoise, i18n("Reduce Uniform Noise")); |
| 59 |
m_comboBox->insertItem(ReduceJPEGArtefacts, i18n("Reduce JPEG Artifacts")); |
| 60 |
m_comboBox->insertItem(ReduceTexturing, i18n("Reduce Texturing")); |
| 61 |
m_comboBox->setWhatsThis(i18n("<p>Select the filter preset to use for photograph restoration here:</p>" |
| 62 |
"<p><b>None</b>: Most common values. Puts settings to default.<br>" |
| 63 |
"<b>Reduce Uniform Noise</b>: reduce small image artifacts such as sensor noise.<br>" |
| 64 |
"<b>Reduce JPEG Artifacts</b>: reduce large image artifacts, such as a JPEG compression mosaic.<br>" |
| 65 |
"<b>Reduce Texturing</b>: reduce image artifacts, such as paper texture, or Moire patterns " |
| 66 |
"on scanned images.</p>")); |
| 67 |
|
| 68 |
QLabel* const space = new QLabel(vbox); |
| 69 |
vbox->setStretchFactor(space, 10); |
| 70 |
|
| 71 |
m_settingsWidget = vbox; |
| 72 |
|
| 73 |
connect(m_comboBox, SIGNAL(activated(int)), |
| 74 |
this, SLOT(slotSettingsChanged())); |
| 75 |
|
| 76 |
BatchTool::registerSettingsWidget(); |
| 77 |
} |
| 78 |
|
| 79 |
BatchToolSettings Restoration::defaultSettings() |
| 80 |
{ |
| 81 |
BatchToolSettings settings; |
| 82 |
settings.insert(QLatin1String("RestorationMethod"), ReduceUniformNoise); |
| 83 |
|
| 84 |
return settings; |
| 85 |
} |
| 86 |
|
| 87 |
void Restoration::slotAssignSettings2Widget() |
| 88 |
{ |
| 89 |
m_comboBox->setCurrentIndex(settings().value(QLatin1String("RestorationMethod")).toInt()); |
| 90 |
} |
| 91 |
|
| 92 |
void Restoration::slotSettingsChanged() |
| 93 |
{ |
| 94 |
BatchToolSettings settings; |
| 95 |
settings.insert(QLatin1String("RestorationMethod"), (int)m_comboBox->currentIndex()); |
| 96 |
BatchTool::slotSettingsChanged(settings); |
| 97 |
} |
| 98 |
|
| 99 |
bool Restoration::toolOperations() |
| 100 |
{ |
| 101 |
if (!loadToDImg()) |
| 102 |
{ |
| 103 |
return false; |
| 104 |
} |
| 105 |
|
| 106 |
int type = settings().value(QLatin1String("RestorationMethod")).toInt(); |
| 107 |
|
| 108 |
GreycstorationContainer settings; |
| 109 |
settings.setRestorationDefaultSettings(); |
| 110 |
|
| 111 |
switch (type) |
| 112 |
{ |
| 113 |
case ReduceUniformNoise: |
| 114 |
{ |
| 115 |
settings.amplitude = 40.0; |
| 116 |
break; |
| 117 |
} |
| 118 |
|
| 119 |
case ReduceJPEGArtefacts: |
| 120 |
{ |
| 121 |
settings.sharpness = 0.3F; |
| 122 |
settings.sigma = 1.0; |
| 123 |
settings.amplitude = 100.0; |
| 124 |
settings.nbIter = 2; |
| 125 |
break; |
| 126 |
} |
| 127 |
|
| 128 |
case ReduceTexturing: |
| 129 |
{ |
| 130 |
settings.sharpness = 0.5F; |
| 131 |
settings.sigma = 1.5; |
| 132 |
settings.amplitude = 100.0; |
| 133 |
settings.nbIter = 2; |
| 134 |
break; |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
m_cimgIface = new GreycstorationFilter(this); |
| 139 |
m_cimgIface->setMode(GreycstorationFilter::Restore); |
| 140 |
m_cimgIface->setOriginalImage(image()); |
| 141 |
m_cimgIface->setSettings(settings); |
| 142 |
m_cimgIface->setup(); |
| 143 |
|
| 144 |
applyFilter(m_cimgIface); |
| 145 |
|
| 146 |
delete m_cimgIface; |
| 147 |
m_cimgIface = nullptr; |
| 148 |
|
| 149 |
return (savefromDImg()); |
| 150 |
} |
| 151 |
|
| 152 |
void Restoration::cancel() |
| 153 |
{ |
| 154 |
if (m_cimgIface) |
| 155 |
{ |
| 156 |
m_cimgIface->cancelFilter(); |
| 157 |
} |
| 158 |
|
| 159 |
BatchTool::cancel(); |
| 160 |
} |
| 161 |
|
| 162 |
} // namespace DigikamBqmRestorationPlugin |
| 163 |
|
| 164 |
#include "moc_restoration.cpp" |