File indexing completed on 2025-01-05 03:51:41
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2005-03-27 0007 * Description : a digiKam image tool for fixing dots produced by 0008 * hot/stuck/dead pixels from a CCD. 0009 * 0010 * SPDX-FileCopyrightText: 2005-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0011 * SPDX-FileCopyrightText: 2005-2006 by Unai Garro <ugarro at users dot sourceforge dot net> 0012 * 0013 * SPDX-License-Identifier: GPL-2.0-or-later 0014 * 0015 * ============================================================ */ 0016 0017 #include "hotpixelstool.h" 0018 0019 // Qt includes 0020 0021 #include <QGridLayout> 0022 #include <QIcon> 0023 #include <QApplication> 0024 #include <QPointer> 0025 0026 // KDE includes 0027 0028 #include <klocalizedstring.h> 0029 #include <ksharedconfig.h> 0030 #include <kconfiggroup.h> 0031 0032 // Local includes 0033 0034 #include "dcombobox.h" 0035 #include "daboutdata.h" 0036 #include "dimg.h" 0037 #include "dimgfiltermanager.h" 0038 #include "editortooliface.h" 0039 #include "editortoolsettings.h" 0040 #include "hotpixelfixer.h" 0041 #include "hotpixelsettings.h" 0042 #include "imageiface.h" 0043 #include "imageregionwidget.h" 0044 0045 namespace DigikamEditorHotPixelsToolPlugin 0046 { 0047 0048 class Q_DECL_HIDDEN HotPixelsTool::Private 0049 { 0050 public: 0051 0052 explicit Private() 0053 : previewWidget(nullptr), 0054 gboxSettings (nullptr), 0055 hpSettings (nullptr) 0056 { 0057 } 0058 0059 ImageRegionWidget* previewWidget; 0060 EditorToolSettings* gboxSettings; 0061 HotPixelSettings* hpSettings; 0062 }; 0063 0064 // -------------------------------------------------------- 0065 0066 HotPixelsTool::HotPixelsTool(QObject* const parent) 0067 : EditorToolThreaded(parent), 0068 d (new Private) 0069 { 0070 setObjectName(QLatin1String("hotpixels")); 0071 setToolName(i18n("Hot Pixels")); 0072 setToolIcon(QIcon::fromTheme(QLatin1String("hotpixels"))); 0073 0074 // ------------------------------------------------------------- 0075 0076 d->gboxSettings = new EditorToolSettings(nullptr); 0077 d->gboxSettings->setButtons(EditorToolSettings::Default| 0078 EditorToolSettings::Ok| 0079 EditorToolSettings::Cancel| 0080 EditorToolSettings::Try); 0081 0082 d->hpSettings = new HotPixelSettings(d->gboxSettings->plainPage()); 0083 0084 // ------------------------------------------------------------- 0085 0086 d->previewWidget = new ImageRegionWidget; 0087 0088 setToolSettings(d->gboxSettings); 0089 setToolView(d->previewWidget); 0090 setPreviewModeMask(PreviewToolBar::AllPreviewModes); 0091 0092 // ------------------------------------------------------------- 0093 0094 connect(d->hpSettings, SIGNAL(signalSettingsChanged()), 0095 this, SLOT(slotPreview())); 0096 0097 connect(d->hpSettings, SIGNAL(signalHotPixels(QPolygon)), 0098 this, SLOT(slotHotPixels(QPolygon))); 0099 } 0100 0101 HotPixelsTool::~HotPixelsTool() 0102 { 0103 delete d; 0104 } 0105 0106 void HotPixelsTool::registerFilter() 0107 { 0108 DImgFilterManager::instance()->addGenerator(new BasicDImgFilterGenerator<HotPixelFixer>()); 0109 } 0110 0111 void HotPixelsTool::slotResetSettings() 0112 { 0113 d->hpSettings->resetToDefault(); 0114 } 0115 0116 void HotPixelsTool::readSettings() 0117 { 0118 KConfigGroup group = KSharedConfig::openConfig()->group(d->hpSettings->configGroupName()); 0119 d->hpSettings->readSettings(group); 0120 } 0121 0122 void HotPixelsTool::writeSettings() 0123 { 0124 KConfigGroup group = KSharedConfig::openConfig()->group(d->hpSettings->configGroupName()); 0125 d->hpSettings->writeSettings(group); 0126 } 0127 0128 void HotPixelsTool::preparePreview() 0129 { 0130 DImg image = d->previewWidget->getOriginalRegionImage(); 0131 HotPixelContainer prm = d->hpSettings->settings(); 0132 0133 QList<HotPixelProps> hotPixelsRegion; 0134 QRect area = d->previewWidget->getOriginalImageRegionToRender(); 0135 0136 for (QList<HotPixelProps>::const_iterator it = prm.hotPixelsList.constBegin() ; 0137 it != prm.hotPixelsList.constEnd() ; ++it) 0138 { 0139 HotPixelProps hp = (*it); 0140 0141 if (area.contains( hp.rect )) 0142 { 0143 hp.rect.moveTopLeft(QPoint( hp.rect.x()-area.x(), hp.rect.y()-area.y() )); 0144 hotPixelsRegion.append(hp); 0145 } 0146 } 0147 0148 prm.hotPixelsList = hotPixelsRegion; 0149 0150 setFilter(dynamic_cast<DImgThreadedFilter*>(new HotPixelFixer(&image, this, prm))); 0151 } 0152 0153 void HotPixelsTool::prepareFinal() 0154 { 0155 HotPixelContainer prm = d->hpSettings->settings(); 0156 0157 ImageIface iface; 0158 setFilter(dynamic_cast<DImgThreadedFilter*>(new HotPixelFixer(iface.original(), this, prm))); 0159 } 0160 0161 void HotPixelsTool::setPreviewImage() 0162 { 0163 d->previewWidget->setPreviewImage(filter()->getTargetImage()); 0164 } 0165 0166 void HotPixelsTool::setFinalImage() 0167 { 0168 ImageIface iface; 0169 iface.setOriginal(i18n("Hot Pixels Correction"), filter()->filterAction(), filter()->getTargetImage()); 0170 } 0171 0172 void HotPixelsTool::slotHotPixels(const QPolygon& pointList) 0173 { 0174 d->previewWidget->setHighLightPoints(pointList); 0175 slotPreview(); 0176 } 0177 0178 } // namespace DigikamEditorHotPixelsToolPlugin 0179 0180 #include "moc_hotpixelstool.cpp"