File indexing completed on 2025-01-05 03:51:42
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2004-06-06 0007 * Description : Red eyes correction tool for image editor 0008 * 0009 * SPDX-FileCopyrightText: 2004-2005 by Renchi Raju <renchi dot raju at gmail dot com> 0010 * SPDX-FileCopyrightText: 2004-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0011 * 0012 * SPDX-License-Identifier: GPL-2.0-or-later 0013 * 0014 * ============================================================ */ 0015 0016 #include "redeyetool.h" 0017 0018 // Qt includes 0019 0020 #include <QColor> 0021 #include <QFrame> 0022 #include <QGridLayout> 0023 #include <QGroupBox> 0024 #include <QHBoxLayout> 0025 #include <QLabel> 0026 #include <QPixmap> 0027 #include <QPushButton> 0028 #include <QToolButton> 0029 #include <QApplication> 0030 #include <QColorDialog> 0031 #include <QIcon> 0032 0033 // KDE includes 0034 0035 #include <kconfiggroup.h> 0036 #include <ksharedconfig.h> 0037 #include <klocalizedstring.h> 0038 0039 // Local includes 0040 0041 #include "editortoolsettings.h" 0042 #include "histogramwidget.h" 0043 #include "histogrambox.h" 0044 #include "imageiface.h" 0045 #include "redeyecorrectionfilter.h" 0046 #include "redeyecorrectionsettings.h" 0047 #include "imageregionwidget.h" 0048 0049 namespace DigikamEditorRedEyeToolPlugin 0050 { 0051 0052 class Q_DECL_HIDDEN RedEyeTool::Private 0053 { 0054 0055 public: 0056 0057 explicit Private() 0058 : settingsView (nullptr), 0059 previewWidget(nullptr), 0060 gboxSettings (nullptr) 0061 { 0062 } 0063 0064 static const QString configGroupName; 0065 static const QString configHistogramChannelEntry; 0066 static const QString configHistogramScaleEntry; 0067 0068 RedEyeCorrectionSettings* settingsView; 0069 ImageRegionWidget* previewWidget; 0070 EditorToolSettings* gboxSettings; 0071 }; 0072 0073 const QString RedEyeTool::Private::configGroupName(QLatin1String("redeye Tool")); 0074 const QString RedEyeTool::Private::configHistogramChannelEntry(QLatin1String("Histogram Channel")); 0075 const QString RedEyeTool::Private::configHistogramScaleEntry(QLatin1String("Histogram Scale")); 0076 0077 // -------------------------------------------------------- 0078 0079 RedEyeTool::RedEyeTool(QObject* const parent) 0080 : EditorToolThreaded(parent), 0081 d (new Private) 0082 { 0083 setObjectName(QLatin1String("redeye")); 0084 setToolHelp(QLatin1String("redeyecorrectiontool.anchor")); 0085 0086 d->previewWidget = new ImageRegionWidget; 0087 d->previewWidget->setToolTip(i18n("Here you can see the image selection preview with " 0088 "red eye reduction applied.")); 0089 0090 // ------------------------------------------------------------- 0091 0092 d->gboxSettings = new EditorToolSettings(nullptr); 0093 d->gboxSettings->setTools(EditorToolSettings::Histogram); 0094 d->gboxSettings->setHistogramType(LRGBC); 0095 d->gboxSettings->setButtons(EditorToolSettings::Default| 0096 EditorToolSettings::Ok| 0097 EditorToolSettings::Cancel); 0098 0099 d->settingsView = new RedEyeCorrectionSettings(d->gboxSettings->plainPage()); 0100 0101 setToolView(d->previewWidget); 0102 setPreviewModeMask(PreviewToolBar::AllPreviewModes); 0103 setToolSettings(d->gboxSettings); 0104 0105 // ------------------------------------------------------------- 0106 0107 connect(d->settingsView, SIGNAL(signalSettingsChanged()), 0108 this, SLOT(slotTimer())); 0109 } 0110 0111 RedEyeTool::~RedEyeTool() 0112 { 0113 delete d; 0114 } 0115 0116 void RedEyeTool::readSettings() 0117 { 0118 KSharedConfig::Ptr config = KSharedConfig::openConfig(); 0119 KConfigGroup group = config->group(d->configGroupName); 0120 0121 d->gboxSettings->histogramBox()->setChannel((ChannelType)group.readEntry(d->configHistogramChannelEntry, (int)LuminosityChannel)); 0122 d->gboxSettings->histogramBox()->setScale((HistogramScale)group.readEntry(d->configHistogramScaleEntry, (int)LogScaleHistogram)); 0123 d->settingsView->readSettings(group); 0124 } 0125 0126 void RedEyeTool::writeSettings() 0127 { 0128 KSharedConfig::Ptr config = KSharedConfig::openConfig(); 0129 KConfigGroup group = config->group(d->configGroupName); 0130 0131 group.writeEntry(d->configHistogramChannelEntry, (int)d->gboxSettings->histogramBox()->channel()); 0132 group.writeEntry(d->configHistogramScaleEntry, (int)d->gboxSettings->histogramBox()->scale()); 0133 d->settingsView->writeSettings(group); 0134 0135 config->sync(); 0136 } 0137 0138 void RedEyeTool::slotResetSettings() 0139 { 0140 d->settingsView->resetToDefault(); 0141 slotPreview(); 0142 } 0143 0144 void RedEyeTool::preparePreview() 0145 { 0146 RedEyeCorrectionContainer settings = d->settingsView->settings(); 0147 0148 d->gboxSettings->histogramBox()->histogram()->stopHistogramComputation(); 0149 0150 DImg original = d->previewWidget->getOriginalImage(); 0151 setFilter(new RedEyeCorrectionFilter(&original, this, settings)); 0152 } 0153 0154 void RedEyeTool::setPreviewImage() 0155 { 0156 DImg preview = filter()->getTargetImage().copy(d->previewWidget->getOriginalImageRegionToRender()); 0157 d->previewWidget->setPreviewImage(preview); 0158 0159 // Update histogram. 0160 0161 d->gboxSettings->histogramBox()->histogram()->updateData(preview.copy(), DImg(), false); 0162 } 0163 0164 void RedEyeTool::prepareFinal() 0165 { 0166 RedEyeCorrectionContainer settings = d->settingsView->settings(); 0167 0168 ImageIface iface; 0169 0170 setFilter(new RedEyeCorrectionFilter(iface.original(), this, settings)); 0171 } 0172 0173 void RedEyeTool::setFinalImage() 0174 { 0175 ImageIface iface; 0176 iface.setOriginal(i18n("Red Eyes Correction"), filter()->filterAction(), filter()->getTargetImage()); 0177 } 0178 0179 } // namespace DigikamEditorRedEyeToolPlugin 0180 0181 #include "moc_redeyetool.cpp"