File indexing completed on 2025-01-19 03:50:55

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2020-08-07
0007  * Description : Hot Pixels Fixer batch tool.
0008  *
0009  * SPDX-FileCopyrightText: 2020-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 "hotpixels.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 "hotpixelcontainer.h"
0029 #include "hotpixelfixer.h"
0030 #include "hotpixelprops.h"
0031 
0032 namespace DigikamBqmHotPixelsPlugin
0033 {
0034 
0035 HotPixels::HotPixels(QObject* const parent)
0036     : BatchTool(QLatin1String("HotPixels"), EnhanceTool, parent),
0037       m_settingsView(nullptr)
0038 {
0039 }
0040 
0041 HotPixels::~HotPixels()
0042 {
0043 }
0044 
0045 BatchTool* HotPixels::clone(QObject* const parent) const
0046 {
0047     return new HotPixels(parent);
0048 }
0049 
0050 void HotPixels::registerSettingsWidget()
0051 {
0052     m_settingsWidget = new QWidget;
0053     m_settingsView   = new HotPixelSettings(m_settingsWidget);
0054 
0055     connect(m_settingsView, SIGNAL(signalSettingsChanged()),
0056             this, SLOT(slotSettingsChanged()));
0057 
0058     BatchTool::registerSettingsWidget();
0059 }
0060 
0061 BatchToolSettings HotPixels::defaultSettings()
0062 {
0063     BatchToolSettings prm;
0064     HotPixelContainer defaultPrm = m_settingsView->defaultSettings();
0065 
0066     prm.insert(QLatin1String("BlackFrameUrl"), defaultPrm.blackFrameUrl);
0067     prm.insert(QLatin1String("HotPixelsList"), HotPixelProps::toStringList(defaultPrm.hotPixelsList));
0068     prm.insert(QLatin1String("FilterMethod"),  (int)defaultPrm.filterMethod);
0069 
0070     return prm;
0071 }
0072 
0073 void HotPixels::slotAssignSettings2Widget()
0074 {
0075     HotPixelContainer prm;
0076     prm.blackFrameUrl = settings()[QLatin1String("BlackFrameUrl")].toUrl();
0077     prm.hotPixelsList = HotPixelProps::fromStringList(settings()[QLatin1String("HotPixelsList")].toStringList());
0078     prm.filterMethod  = (HotPixelContainer::InterpolationMethod)settings()[QLatin1String("FilterMethod")].toInt();
0079     m_settingsView->setSettings(prm);
0080 }
0081 
0082 void HotPixels::slotSettingsChanged()
0083 {
0084     BatchToolSettings prm;
0085     HotPixelContainer currentPrm = m_settingsView->settings();
0086 
0087     prm.insert(QLatin1String("BlackFrameUrl"), currentPrm.blackFrameUrl);
0088     prm.insert(QLatin1String("HotPixelsList"), HotPixelProps::toStringList(currentPrm.hotPixelsList));
0089     prm.insert(QLatin1String("FilterMethod"),  (int)currentPrm.filterMethod);
0090 
0091     BatchTool::slotSettingsChanged(prm);
0092 }
0093 
0094 bool HotPixels::toolOperations()
0095 {
0096     if (!loadToDImg())
0097     {
0098         return false;
0099     }
0100 
0101     HotPixelContainer prm;
0102 
0103     prm.blackFrameUrl = settings()[QLatin1String("BlackFrameUrl")].toUrl();
0104     prm.hotPixelsList = HotPixelProps::fromStringList(settings()[QLatin1String("HotPixelsList")].toStringList());
0105     prm.filterMethod  = (HotPixelContainer::InterpolationMethod)settings()[QLatin1String("FilterMethod")].toInt();
0106 
0107     HotPixelFixer hpf(&image(), nullptr, prm);
0108     applyFilter(&hpf);
0109 
0110     return (savefromDImg());
0111 }
0112 
0113 } // namespace DigikamBqmHotPixelsPlugin
0114 
0115 #include "moc_hotpixels.cpp"