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 : 16/08/2016 0007 * Description : A Red-Eye tool for automatic detection and correction filter. 0008 * 0009 * SPDX-FileCopyrightText: 2016 by Omar Amin <Omar dot moh dot amin at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #include "redeyecorrection.h" 0016 0017 // Qt includes 0018 0019 #include <QLabel> 0020 #include <QWidget> 0021 0022 // KDE includes 0023 0024 #include <klocalizedstring.h> 0025 0026 // Local includes 0027 0028 #include "dimg.h" 0029 0030 namespace DigikamBqmRedEyeCorrectionPlugin 0031 { 0032 0033 RedEyeCorrection::RedEyeCorrection(QObject* const parent) 0034 : BatchTool(QLatin1String("RedEyeCorrection"), EnhanceTool, parent), 0035 m_redEyeCFilter(nullptr), 0036 m_settingsView (nullptr) 0037 { 0038 } 0039 0040 RedEyeCorrection::~RedEyeCorrection() 0041 { 0042 } 0043 0044 BatchTool* RedEyeCorrection::clone(QObject* const parent) const 0045 { 0046 return new RedEyeCorrection(parent); 0047 } 0048 0049 void RedEyeCorrection::registerSettingsWidget() 0050 { 0051 m_settingsWidget = new QWidget; 0052 m_settingsView = new RedEyeCorrectionSettings(m_settingsWidget); 0053 0054 connect(m_settingsView, SIGNAL(signalSettingsChanged()), 0055 this, SLOT(slotSettingsChanged())); 0056 0057 BatchTool::registerSettingsWidget(); 0058 } 0059 0060 BatchToolSettings RedEyeCorrection::defaultSettings() 0061 { 0062 BatchToolSettings prm; 0063 RedEyeCorrectionContainer defaultPrm = m_settingsView->defaultSettings(); 0064 0065 prm.insert(QLatin1String("redtoavgratio"), (double)defaultPrm.m_redToAvgRatio); 0066 0067 return prm; 0068 } 0069 0070 void RedEyeCorrection::slotAssignSettings2Widget() 0071 { 0072 RedEyeCorrectionContainer prm; 0073 prm.m_redToAvgRatio = settings()[QLatin1String("redtoavgratio")].toDouble(); 0074 m_settingsView->setSettings(prm); 0075 } 0076 0077 void RedEyeCorrection::slotSettingsChanged() 0078 { 0079 BatchToolSettings prm; 0080 RedEyeCorrectionContainer currentPrm = m_settingsView->settings(); 0081 0082 prm.insert(QLatin1String("redtoavgratio"), (double)currentPrm.m_redToAvgRatio); 0083 0084 BatchTool::slotSettingsChanged(prm); 0085 } 0086 0087 bool RedEyeCorrection::toolOperations() 0088 { 0089 if (!loadToDImg()) 0090 { 0091 return false; 0092 } 0093 0094 RedEyeCorrectionContainer prm; 0095 prm.m_redToAvgRatio = settings()[QLatin1String("redtoavgratio")].toDouble(); 0096 0097 m_redEyeCFilter = new RedEyeCorrectionFilter(&image(), nullptr, prm); 0098 applyFilter(m_redEyeCFilter); 0099 0100 delete m_redEyeCFilter; 0101 m_redEyeCFilter = nullptr; 0102 0103 return (savefromDImg()); 0104 } 0105 0106 void RedEyeCorrection::cancel() 0107 { 0108 if (m_redEyeCFilter) 0109 { 0110 m_redEyeCFilter->cancelFilter(); 0111 } 0112 0113 BatchTool::cancel(); 0114 } 0115 0116 } // namespace DigikamBqmRedEyeCorrectionPlugin 0117 0118 #include "moc_redeyecorrection.cpp"