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        : 2010-03-09
0007  * Description : LDR tonemapper batch tool.
0008  *
0009  * SPDX-FileCopyrightText: 2010-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 "localcontrast.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 "localcontrastfilter.h"
0029 #include "localcontrastcontainer.h"
0030 
0031 namespace DigikamBqmLocalContrastPlugin
0032 {
0033 
0034 LocalContrast::LocalContrast(QObject* const parent)
0035     : BatchTool(QLatin1String("LocalContrast"), EnhanceTool, parent),
0036       m_settingsView(nullptr)
0037 {
0038 }
0039 
0040 LocalContrast::~LocalContrast()
0041 {
0042 }
0043 
0044 BatchTool* LocalContrast::clone(QObject* const parent) const
0045 {
0046     return new LocalContrast(parent);
0047 }
0048 
0049 void LocalContrast::registerSettingsWidget()
0050 {
0051     m_settingsWidget = new QWidget;
0052     m_settingsView   = new LocalContrastSettings(m_settingsWidget);
0053 
0054     connect(m_settingsView, SIGNAL(signalSettingsChanged()),
0055             this, SLOT(slotSettingsChanged()));
0056 
0057     BatchTool::registerSettingsWidget();
0058 }
0059 
0060 BatchToolSettings LocalContrast::defaultSettings()
0061 {
0062     BatchToolSettings prm;
0063     LocalContrastContainer defaultPrm = m_settingsView->defaultSettings();
0064 
0065     prm.insert(QLatin1String("stretchContrast"), defaultPrm.stretchContrast);
0066     prm.insert(QLatin1String("lowSaturation"),   defaultPrm.lowSaturation);
0067     prm.insert(QLatin1String("highSaturation"),  defaultPrm.highSaturation);
0068     prm.insert(QLatin1String("functionId"),      defaultPrm.functionId);
0069 
0070     prm.insert(QLatin1String("stage1Enabled"),   defaultPrm.stage[0].enabled);
0071     prm.insert(QLatin1String("stage1Power"),     defaultPrm.stage[0].power);
0072     prm.insert(QLatin1String("stage1Blur"),      defaultPrm.stage[0].blur);
0073 
0074     prm.insert(QLatin1String("stage2Enabled"),   defaultPrm.stage[1].enabled);
0075     prm.insert(QLatin1String("stage2Power"),     defaultPrm.stage[1].power);
0076     prm.insert(QLatin1String("stage2Blur"),      defaultPrm.stage[1].blur);
0077 
0078     prm.insert(QLatin1String("stage3Enabled"),   defaultPrm.stage[2].enabled);
0079     prm.insert(QLatin1String("stage3Power"),     defaultPrm.stage[2].power);
0080     prm.insert(QLatin1String("stage3Blur"),      defaultPrm.stage[2].blur);
0081 
0082     prm.insert(QLatin1String("stage4Enabled"),   defaultPrm.stage[3].enabled);
0083     prm.insert(QLatin1String("stage4Power"),     defaultPrm.stage[3].power);
0084     prm.insert(QLatin1String("stage4Blur"),      defaultPrm.stage[3].blur);
0085 
0086     return prm;
0087 }
0088 
0089 void LocalContrast::slotAssignSettings2Widget()
0090 {
0091     LocalContrastContainer prm;
0092 
0093     prm.stretchContrast = settings()[QLatin1String("stretchContrast")].toBool();
0094     prm.lowSaturation   = settings()[QLatin1String("lowSaturation")].toInt();
0095     prm.highSaturation  = settings()[QLatin1String("highSaturation")].toInt();
0096     prm.functionId      = settings()[QLatin1String("functionId")].toInt();
0097 
0098     prm.stage[0].enabled = settings()[QLatin1String("stage1Enabled")].toBool();
0099     prm.stage[0].power   = settings()[QLatin1String("stage1Power")].toDouble();
0100     prm.stage[0].blur    = settings()[QLatin1String("stage1Blur")].toDouble();
0101 
0102     prm.stage[1].enabled = settings()[QLatin1String("stage2Enabled")].toBool();
0103     prm.stage[1].power   = settings()[QLatin1String("stage2Power")].toDouble();
0104     prm.stage[1].blur    = settings()[QLatin1String("stage2Blur")].toDouble();
0105 
0106     prm.stage[2].enabled = settings()[QLatin1String("stage3Enabled")].toBool();
0107     prm.stage[2].power   = settings()[QLatin1String("stage3Power")].toDouble();
0108     prm.stage[2].blur    = settings()[QLatin1String("stage3Blur")].toDouble();
0109 
0110     prm.stage[3].enabled = settings()[QLatin1String("stage4Enabled")].toBool();
0111     prm.stage[3].power   = settings()[QLatin1String("stage4Power")].toDouble();
0112     prm.stage[3].blur    = settings()[QLatin1String("stage4Blur")].toDouble();
0113 
0114     m_settingsView->setSettings(prm);
0115 }
0116 
0117 void LocalContrast::slotSettingsChanged()
0118 {
0119     BatchToolSettings prm;
0120     LocalContrastContainer currentPrm = m_settingsView->settings();
0121 
0122     prm.insert(QLatin1String("stretchContrast"), currentPrm.stretchContrast);
0123     prm.insert(QLatin1String("lowSaturation"),   currentPrm.lowSaturation);
0124     prm.insert(QLatin1String("highSaturation"),  currentPrm.highSaturation);
0125     prm.insert(QLatin1String("functionId"),      currentPrm.functionId);
0126 
0127     prm.insert(QLatin1String("stage1Enabled"),   currentPrm.stage[0].enabled);
0128     prm.insert(QLatin1String("stage1Power"),     currentPrm.stage[0].power);
0129     prm.insert(QLatin1String("stage1Blur"),      currentPrm.stage[0].blur);
0130 
0131     prm.insert(QLatin1String("stage2Enabled"),   currentPrm.stage[1].enabled);
0132     prm.insert(QLatin1String("stage2Power"),     currentPrm.stage[1].power);
0133     prm.insert(QLatin1String("stage2Blur"),      currentPrm.stage[1].blur);
0134 
0135     prm.insert(QLatin1String("stage3Enabled"),   currentPrm.stage[2].enabled);
0136     prm.insert(QLatin1String("stage3Power"),     currentPrm.stage[2].power);
0137     prm.insert(QLatin1String("stage3Blur"),      currentPrm.stage[2].blur);
0138 
0139     prm.insert(QLatin1String("stage4Enabled"),   currentPrm.stage[3].enabled);
0140     prm.insert(QLatin1String("stage4Power"),     currentPrm.stage[3].power);
0141     prm.insert(QLatin1String("stage4Blur"),      currentPrm.stage[3].blur);
0142 
0143     BatchTool::slotSettingsChanged(prm);
0144 }
0145 
0146 bool LocalContrast::toolOperations()
0147 {
0148     if (!loadToDImg())
0149     {
0150         return false;
0151     }
0152 
0153     LocalContrastContainer prm;
0154 
0155     prm.stretchContrast = settings()[QLatin1String("stretchContrast")].toBool();
0156     prm.lowSaturation   = settings()[QLatin1String("lowSaturation")].toInt();
0157     prm.highSaturation  = settings()[QLatin1String("highSaturation")].toInt();
0158     prm.functionId      = settings()[QLatin1String("functionId")].toInt();
0159 
0160     prm.stage[0].enabled = settings()[QLatin1String("stage1Enabled")].toBool();
0161     prm.stage[0].power   = settings()[QLatin1String("stage1Power")].toDouble();
0162     prm.stage[0].blur    = settings()[QLatin1String("stage1Blur")].toDouble();
0163 
0164     prm.stage[1].enabled = settings()[QLatin1String("stage2Enabled")].toBool();
0165     prm.stage[1].power   = settings()[QLatin1String("stage2Power")].toDouble();
0166     prm.stage[1].blur    = settings()[QLatin1String("stage2Blur")].toDouble();
0167 
0168     prm.stage[2].enabled = settings()[QLatin1String("stage3Enabled")].toBool();
0169     prm.stage[2].power   = settings()[QLatin1String("stage3Power")].toDouble();
0170     prm.stage[2].blur    = settings()[QLatin1String("stage3Blur")].toDouble();
0171 
0172     prm.stage[3].enabled = settings()[QLatin1String("stage4Enabled")].toBool();
0173     prm.stage[3].power   = settings()[QLatin1String("stage4Power")].toDouble();
0174     prm.stage[3].blur    = settings()[QLatin1String("stage4Blur")].toDouble();
0175 
0176     LocalContrastFilter lc(&image(), nullptr, prm);
0177     applyFilter(&lc);
0178 
0179     return (savefromDImg());
0180 }
0181 
0182 } // namespace DigikamBqmLocalContrastPlugin
0183 
0184 #include "moc_localcontrast.cpp"