File indexing completed on 2025-01-05 03:51:40

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2004-12-25
0007  * Description : a digiKam image tool to reduce
0008  *               vignetting on an image.
0009  *
0010  * SPDX-FileCopyrightText: 2004-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0011  * SPDX-FileCopyrightText: 2010      by Julien Narboux <julien at narboux dot fr>
0012  *
0013  * SPDX-License-Identifier: GPL-2.0-or-later
0014  *
0015  * ============================================================ */
0016 
0017 #include "antivignettingtool.h"
0018 
0019 // Qt includes
0020 
0021 #include <QGridLayout>
0022 #include <QImage>
0023 #include <QLabel>
0024 #include <QPainter>
0025 #include <QPen>
0026 #include <QPixmap>
0027 #include <QIcon>
0028 
0029 // KDE includes
0030 
0031 #include <kconfiggroup.h>
0032 #include <klocalizedstring.h>
0033 #include <ksharedconfig.h>
0034 
0035 // Local includes
0036 
0037 #include "dnuminput.h"
0038 #include "antivignettingfilter.h"
0039 #include "antivignettingsettings.h"
0040 #include "editortoolsettings.h"
0041 #include "imageiface.h"
0042 #include "imageguidewidget.h"
0043 
0044 namespace DigikamEditorAntivignettingToolPlugin
0045 {
0046 
0047 class Q_DECL_HIDDEN AntiVignettingTool::Private
0048 {
0049 public:
0050 
0051     explicit Private()
0052       : configGroupName(QLatin1String("antivignetting Tool")),
0053         settingsView   (nullptr),
0054         previewWidget  (nullptr),
0055         gboxSettings   (nullptr)
0056     {
0057     }
0058 
0059     const QString           configGroupName;
0060 
0061     AntiVignettingSettings* settingsView;
0062     ImageGuideWidget*       previewWidget;
0063     EditorToolSettings*     gboxSettings;
0064 };
0065 
0066 AntiVignettingTool::AntiVignettingTool(QObject* const parent)
0067     : EditorToolThreaded(parent),
0068       d                 (new Private)
0069 {
0070     setObjectName(QLatin1String("antivignetting"));
0071     setToolName(i18n("Vignetting Correction"));
0072     setToolIcon(QIcon::fromTheme(QLatin1String("antivignetting")));
0073 
0074     d->previewWidget = new ImageGuideWidget(nullptr, false, ImageGuideWidget::HVGuideMode);
0075     setToolView(d->previewWidget);
0076     setPreviewModeMask(PreviewToolBar::UnSplitPreviewModes);
0077 
0078     // -------------------------------------------------------------
0079 
0080     d->gboxSettings = new EditorToolSettings(nullptr);
0081     d->gboxSettings->setButtons(EditorToolSettings::Default|
0082                                 EditorToolSettings::Ok|
0083                                 EditorToolSettings::Cancel|
0084                                 EditorToolSettings::Try);
0085 
0086     // -------------------------------------------------------------
0087 
0088     d->settingsView = new AntiVignettingSettings(d->gboxSettings->plainPage());
0089     setToolSettings(d->gboxSettings);
0090 
0091     // -------------------------------------------------------------
0092 
0093     connect(d->settingsView, SIGNAL(signalSettingsChanged()),
0094             this, SLOT(slotTimer()));
0095 }
0096 
0097 AntiVignettingTool::~AntiVignettingTool()
0098 {
0099     delete d;
0100 }
0101 
0102 void AntiVignettingTool::readSettings()
0103 {
0104     KSharedConfig::Ptr config = KSharedConfig::openConfig();
0105     KConfigGroup group        = config->group(d->configGroupName);
0106 
0107     d->settingsView->readSettings(group);
0108     slotPreview();
0109 }
0110 
0111 void AntiVignettingTool::writeSettings()
0112 {
0113     KSharedConfig::Ptr config = KSharedConfig::openConfig();
0114     KConfigGroup group        = config->group(d->configGroupName);
0115 
0116     d->settingsView->writeSettings(group);
0117     group.sync();
0118 }
0119 
0120 void AntiVignettingTool::slotResetSettings()
0121 {
0122     d->settingsView->resetToDefault();
0123     slotPreview();
0124 }
0125 
0126 void AntiVignettingTool::preparePreview()
0127 {
0128     AntiVignettingContainer settings = d->settingsView->settings();
0129 
0130     ImageIface* const iface = d->previewWidget->imageIface();
0131     int previewWidth        = iface->previewSize().width();
0132     int previewHeight       = iface->previewSize().height();
0133     DImg imTemp             = iface->original()->smoothScale(previewWidth, previewHeight, Qt::KeepAspectRatio);
0134 
0135     setFilter(new AntiVignettingFilter(&imTemp, this, settings));
0136 }
0137 
0138 void AntiVignettingTool::prepareFinal()
0139 {
0140     AntiVignettingContainer settings = d->settingsView->settings();
0141 
0142     ImageIface iface;
0143     setFilter(new AntiVignettingFilter(iface.original(), this, settings));
0144 }
0145 
0146 void AntiVignettingTool::setPreviewImage()
0147 {
0148     ImageIface* const iface = d->previewWidget->imageIface();
0149     DImg preview            = filter()->getTargetImage().smoothScale(iface->previewSize());
0150     iface->setPreview(preview);
0151     d->previewWidget->updatePreview();
0152 }
0153 
0154 void AntiVignettingTool::setFinalImage()
0155 {
0156     ImageIface* const iface = d->previewWidget->imageIface();
0157     DImg finalImage         = filter()->getTargetImage();
0158 
0159     iface->setOriginal(i18n("Vignetting Correction"), filter()->filterAction(), finalImage);
0160 }
0161 
0162 } // namespace DigikamEditorAntivignettingToolPlugin
0163 
0164 #include "moc_antivignettingtool.cpp"