| 1 |
/* ============================================================ |
| 2 |
* |
| 3 |
* This file is a part of digiKam project |
| 4 |
* https://www.digikam.org |
| 5 |
* |
| 6 |
* Date : 2009-05-02 |
| 7 |
* Description : sharpen image batch tool. |
| 8 |
* |
| 9 |
* SPDX-FileCopyrightText: 2009 by Matthias Welwarsky <matze at welwarsky dot de> |
| 10 |
* SPDX-FileCopyrightText: 2010-2026 by Gilles Caulier <caulier dot gilles at gmail dot com> |
| 11 |
* |
| 12 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 13 |
* |
| 14 |
* ============================================================ */ |
| 15 |
|
| 16 |
#include "sharpen.h" |
| 17 |
|
| 18 |
// Qt includes |
| 19 |
|
| 20 |
#include <QLabel> |
| 21 |
#include <QWidget> |
| 22 |
|
| 23 |
// KDE includes |
| 24 |
|
| 25 |
#include <klocalizedstring.h> |
| 26 |
|
| 27 |
// Local includes |
| 28 |
|
| 29 |
#include "digikam_config.h" |
| 30 |
#include "dimg.h" |
| 31 |
#include "sharpenfilter.h" |
| 32 |
#include "unsharpmaskfilter.h" |
| 33 |
|
| 34 |
#ifdef HAVE_EIGEN3 |
| 35 |
# include "refocusfilter.h" |
| 36 |
#endif // HAVE_EIGEN3 |
| 37 |
|
| 38 |
namespace DigikamBqmSharpenPlugin |
| 39 |
{ |
| 40 |
|
| 41 |
Sharpen::Sharpen(QObject* const parent) |
| 42 |
: BatchTool(QLatin1String("Sharpen"), EnhanceTool, parent) |
| 43 |
{ |
| 44 |
} |
| 45 |
|
| 46 |
BatchTool* Sharpen::clone(QObject* const parent) const |
| 47 |
{ |
| 48 |
return new Sharpen(parent); |
| 49 |
} |
| 50 |
|
| 51 |
void Sharpen::registerSettingsWidget() |
| 52 |
{ |
| 53 |
m_settingsWidget = new QWidget; |
| 54 |
m_settingsView = new SharpSettings(m_settingsWidget); |
| 55 |
|
| 56 |
connect(m_settingsView, SIGNAL(signalSettingsChanged()), |
| 57 |
this, SLOT(slotSettingsChanged())); |
| 58 |
|
| 59 |
BatchTool::registerSettingsWidget(); |
| 60 |
} |
| 61 |
|
| 62 |
BatchToolSettings Sharpen::defaultSettings() |
| 63 |
{ |
| 64 |
BatchToolSettings settings; |
| 65 |
SharpContainer defaultPrm = m_settingsView->defaultSettings(); |
| 66 |
|
| 67 |
// sharpen method |
| 68 |
|
| 69 |
settings.insert(QLatin1String("SharpenFilterType"), (int)defaultPrm.method); |
| 70 |
|
| 71 |
// simple sharp |
| 72 |
|
| 73 |
settings.insert(QLatin1String("SimpleSharpRadius"), (int)defaultPrm.ssRadius); |
| 74 |
|
| 75 |
// unsharp mask |
| 76 |
|
| 77 |
settings.insert(QLatin1String("UnsharpMaskRadius"), (double)defaultPrm.umRadius); |
| 78 |
settings.insert(QLatin1String("UnsharpMaskAmount"), (double)defaultPrm.umAmount); |
| 79 |
settings.insert(QLatin1String("UnsharpMaskThreshold"), (double)defaultPrm.umThreshold); |
| 80 |
settings.insert(QLatin1String("UnsharpMaskLuma"), (bool)defaultPrm.umLumaOnly); |
| 81 |
|
| 82 |
#ifdef HAVE_EIGEN3 |
| 83 |
|
| 84 |
// refocus |
| 85 |
|
| 86 |
settings.insert(QLatin1String("RefocusRadius"), (double)defaultPrm.rfRadius); |
| 87 |
settings.insert(QLatin1String("RefocusCorrelation"), (double)defaultPrm.rfCorrelation); |
| 88 |
settings.insert(QLatin1String("RefocusNoise"), (double)defaultPrm.rfNoise); |
| 89 |
settings.insert(QLatin1String("RefocusGauss"), (double)defaultPrm.rfGauss); |
| 90 |
settings.insert(QLatin1String("RefocusMatrixSize"), (int)defaultPrm.rfMatrix); |
| 91 |
|
| 92 |
#endif // HAVE_EIGEN3 |
| 93 |
|
| 94 |
return settings; |
| 95 |
} |
| 96 |
|
| 97 |
void Sharpen::slotAssignSettings2Widget() |
| 98 |
{ |
| 99 |
SharpContainer prm; |
| 100 |
|
| 101 |
// sharpen method |
| 102 |
|
| 103 |
prm.method = settings().value(QLatin1String("SharpenFilterType")).toInt(); |
| 104 |
|
| 105 |
// simple sharp |
| 106 |
|
| 107 |
prm.ssRadius = settings().value(QLatin1String("SimpleSharpRadius")).toInt(); |
| 108 |
|
| 109 |
// unsharp mask |
| 110 |
|
| 111 |
prm.umRadius = settings().value(QLatin1String("UnsharpMaskRadius")).toDouble(); |
| 112 |
prm.umAmount = settings().value(QLatin1String("UnsharpMaskAmount")).toDouble(); |
| 113 |
prm.umThreshold = settings().value(QLatin1String("UnsharpMaskThreshold")).toDouble(); |
| 114 |
prm.umLumaOnly = settings().value(QLatin1String("UnsharpMaskLuma")).toBool(); |
| 115 |
|
| 116 |
#ifdef HAVE_EIGEN3 |
| 117 |
|
| 118 |
// refocus |
| 119 |
|
| 120 |
prm.rfRadius = settings().value(QLatin1String("RefocusRadius")).toDouble(); |
| 121 |
prm.rfCorrelation = settings().value(QLatin1String("RefocusCorrelation")).toDouble(); |
| 122 |
prm.rfNoise = settings().value(QLatin1String("RefocusNoise")).toDouble(); |
| 123 |
prm.rfGauss = settings().value(QLatin1String("RefocusGauss")).toDouble(); |
| 124 |
prm.rfMatrix = settings().value(QLatin1String("RefocusMatrixSize")).toInt(); |
| 125 |
|
| 126 |
#endif // HAVE_EIGEN3 |
| 127 |
|
| 128 |
m_settingsView->setSettings(prm); |
| 129 |
} |
| 130 |
|
| 131 |
void Sharpen::slotSettingsChanged() |
| 132 |
{ |
| 133 |
BatchToolSettings settings; |
| 134 |
SharpContainer prm = m_settingsView->settings(); |
| 135 |
|
| 136 |
// sharpen method |
| 137 |
|
| 138 |
settings.insert(QLatin1String("SharpenFilterType"), (int)prm.method); |
| 139 |
|
| 140 |
// simple sharp |
| 141 |
|
| 142 |
settings.insert(QLatin1String("SimpleSharpRadius"), (int)prm.ssRadius); |
| 143 |
|
| 144 |
// unsharp mask |
| 145 |
|
| 146 |
settings.insert(QLatin1String("UnsharpMaskRadius"), (double)prm.umRadius); |
| 147 |
settings.insert(QLatin1String("UnsharpMaskAmount"), (double)prm.umAmount); |
| 148 |
settings.insert(QLatin1String("UnsharpMaskThreshold"), (double)prm.umThreshold); |
| 149 |
settings.insert(QLatin1String("UnsharpMaskLuma"), (bool)prm.umLumaOnly); |
| 150 |
|
| 151 |
#ifdef HAVE_EIGEN3 |
| 152 |
|
| 153 |
// refocus |
| 154 |
|
| 155 |
settings.insert(QLatin1String("RefocusRadius"), (double)prm.rfRadius); |
| 156 |
settings.insert(QLatin1String("RefocusCorrelation"), (double)prm.rfCorrelation); |
| 157 |
settings.insert(QLatin1String("RefocusNoise"), (double)prm.rfNoise); |
| 158 |
settings.insert(QLatin1String("RefocusGauss"), (double)prm.rfGauss); |
| 159 |
settings.insert(QLatin1String("RefocusMatrixSize"), (int)prm.rfMatrix); |
| 160 |
|
| 161 |
#endif // HAVE_EIGEN3 |
| 162 |
|
| 163 |
BatchTool::slotSettingsChanged(settings); |
| 164 |
} |
| 165 |
|
| 166 |
bool Sharpen::toolOperations() |
| 167 |
{ |
| 168 |
if (!loadToDImg()) |
| 169 |
{ |
| 170 |
return false; |
| 171 |
} |
| 172 |
|
| 173 |
int filterType = settings().value(QLatin1String("SharpenFilterType")).toInt(); |
| 174 |
|
| 175 |
switch (filterType) |
| 176 |
{ |
| 177 |
case SharpContainer::SimpleSharp: |
| 178 |
{ |
| 179 |
double radius = settings().value(QLatin1String("SimpleSharpRadius")).toInt() / 10.0; |
| 180 |
double sigma; |
| 181 |
|
| 182 |
if (radius < 1.0) |
| 183 |
{ |
| 184 |
sigma = radius; |
| 185 |
} |
| 186 |
else |
| 187 |
{ |
| 188 |
sigma = sqrt(radius); |
| 189 |
} |
| 190 |
|
| 191 |
SharpenFilter filter(&image(), nullptr, radius, sigma); |
| 192 |
applyFilter(&filter); |
| 193 |
break; |
| 194 |
} |
| 195 |
|
| 196 |
case SharpContainer::UnsharpMask: |
| 197 |
{ |
| 198 |
double r = settings().value(QLatin1String("UnsharpMaskRadius")).toDouble(); |
| 199 |
double a = settings().value(QLatin1String("UnsharpMaskAmount")).toDouble(); |
| 200 |
double th = settings().value(QLatin1String("UnsharpMaskThreshold")).toDouble(); |
| 201 |
bool l = settings().value(QLatin1String("UnsharpMaskLuma")).toBool(); |
| 202 |
|
| 203 |
UnsharpMaskFilter filter(&image(), nullptr, r, a, th, l); |
| 204 |
applyFilter(&filter); |
| 205 |
break; |
| 206 |
} |
| 207 |
|
| 208 |
case SharpContainer::Refocus: |
| 209 |
{ |
| 210 |
|
| 211 |
#ifdef HAVE_EIGEN3 |
| 212 |
|
| 213 |
double radius = settings().value(QLatin1String("RefocusRadius")).toDouble(); |
| 214 |
double correlation = settings().value(QLatin1String("RefocusCorrelation")).toDouble(); |
| 215 |
double noise = settings().value(QLatin1String("RefocusNoise")).toDouble(); |
| 216 |
double gauss = settings().value(QLatin1String("RefocusGauss")).toDouble(); |
| 217 |
int matrixSize = settings().value(QLatin1String("RefocusMatrixSize")).toInt(); |
| 218 |
|
| 219 |
RefocusFilter filter(&image(), nullptr, matrixSize, radius, gauss, correlation, noise); |
| 220 |
applyFilter(&filter); |
| 221 |
|
| 222 |
#endif // HAVE_EIGEN3 |
| 223 |
|
| 224 |
break; |
| 225 |
} |
| 226 |
} |
| 227 |
|
| 228 |
return savefromDImg(); |
| 229 |
} |
| 230 |
|
| 231 |
} // namespace DigikamBqmSharpenPlugin |
| 232 |
|
| 233 |
#include "moc_sharpen.cpp" |