Debian Codegraph @

core/dplugins/editor/enhance/hotpixels/hotpixelstool.cpp

raw
1 /* ============================================================
2 *
3 * This file is a part of digiKam project
4 * https://www.digikam.org
5 *
6 * Date : 2005-03-27
7 * Description : a digiKam image tool for fixing dots produced by
8 * hot/stuck/dead pixels from a CCD.
9 *
10 * SPDX-FileCopyrightText: 2005-2026 by Gilles Caulier <caulier dot gilles at gmail dot com>
11 * SPDX-FileCopyrightText: 2005-2006 by Unai Garro <ugarro at users dot sourceforge dot net>
12 *
13 * SPDX-License-Identifier: GPL-2.0-or-later
14 *
15 * ============================================================ */
16
17 #include "hotpixelstool.h"
18
19 // Qt includes
20
21 #include <QGridLayout>
22 #include <QIcon>
23 #include <QApplication>
24 #include <QPointer>
25
26 // KDE includes
27
28 #include <klocalizedstring.h>
29 #include <ksharedconfig.h>
30 #include <kconfiggroup.h>
31
32 // Local includes
33
34 #include "dcombobox.h"
35 #include "daboutdata.h"
36 #include "dimg.h"
37 #include "dimgfiltermanager.h"
38 #include "editortooliface.h"
39 #include "editortoolsettings.h"
40 #include "hotpixelfixer.h"
41 #include "hotpixelsettings.h"
42 #include "imageiface.h"
43 #include "imageregionwidget.h"
44
45 namespace DigikamEditorHotPixelsToolPlugin
46 {
47
48 class Q_DECL_HIDDEN HotPixelsTool::Private
49 {
50 public:
51
52 Private() = default;
53
54 ImageRegionWidget* previewWidget = nullptr;
55 EditorToolSettings* gboxSettings = nullptr;
56 HotPixelSettings* hpSettings = nullptr;
57 };
58
59 // --------------------------------------------------------
60
61 HotPixelsTool::HotPixelsTool(QObject* const parent)
62 : EditorToolThreaded(parent),
63 d (new Private)
64 {
65 setObjectName(QLatin1String("hotpixels"));
66 setToolName(i18n("Hot Pixels"));
67 setToolIcon(QIcon::fromTheme(QLatin1String("hotpixels")));
68
69 // -------------------------------------------------------------
70
71 d->gboxSettings = new EditorToolSettings(nullptr);
72 d->gboxSettings->setButtons(EditorToolSettings::Default|
73 EditorToolSettings::Ok|
74 EditorToolSettings::Cancel|
75 EditorToolSettings::Try);
76
77 d->hpSettings = new HotPixelSettings(d->gboxSettings->plainPage());
78
79 // -------------------------------------------------------------
80
81 d->previewWidget = new ImageRegionWidget;
82
83 setToolSettings(d->gboxSettings);
84 setToolView(d->previewWidget);
85 setPreviewModeMask(PreviewToolBar::AllPreviewModes);
86
87 // -------------------------------------------------------------
88
89 connect(d->hpSettings, SIGNAL(signalSettingsChanged()),
90 this, SLOT(slotPreview()));
91
92 connect(d->hpSettings, SIGNAL(signalHotPixels(QPolygon)),
93 this, SLOT(slotHotPixels(QPolygon)));
94 }
95
96 HotPixelsTool::~HotPixelsTool()
97 {
98 delete d;
99 }
100
101 void HotPixelsTool::registerFilter()
102 {
103 DImgFilterManager::instance()->addGenerator(new BasicDImgFilterGenerator<HotPixelFixer>());
104 }
105
106 void HotPixelsTool::slotResetSettings()
107 {
108 d->hpSettings->resetToDefault();
109 }
110
111 void HotPixelsTool::readSettings()
112 {
113 KConfigGroup group = KSharedConfig::openConfig()->group(d->hpSettings->configGroupName());
114 d->hpSettings->readSettings(group);
115 }
116
117 void HotPixelsTool::writeSettings()
118 {
119 KConfigGroup group = KSharedConfig::openConfig()->group(d->hpSettings->configGroupName());
120 d->hpSettings->writeSettings(group);
121 }
122
123 void HotPixelsTool::preparePreview()
124 {
125 DImg image = d->previewWidget->getOriginalRegionImage();
126 HotPixelContainer prm = d->hpSettings->settings();
127
128 QList<HotPixelProps> hotPixelsRegion;
129 QRect area = d->previewWidget->getOriginalImageRegionToRender();
130
131 for (QList<HotPixelProps>::const_iterator it = prm.hotPixelsList.constBegin() ;
132 it != prm.hotPixelsList.constEnd() ; ++it)
133 {
134 HotPixelProps hp = (*it);
135
136 if (area.contains( hp.rect ))
137 {
138 hp.rect.moveTopLeft(QPoint( hp.rect.x()-area.x(), hp.rect.y()-area.y() ));
139 hotPixelsRegion.append(hp);
140 }
141 }
142
143 prm.hotPixelsList = hotPixelsRegion;
144
145 setFilter(dynamic_cast<DImgThreadedFilter*>(new HotPixelFixer(&image, this, prm)));
146 }
147
148 void HotPixelsTool::prepareFinal()
149 {
150 HotPixelContainer prm = d->hpSettings->settings();
151
152 ImageIface iface;
153 setFilter(dynamic_cast<DImgThreadedFilter*>(new HotPixelFixer(iface.original(), this, prm)));
154 }
155
156 void HotPixelsTool::setPreviewImage()
157 {
158 d->previewWidget->setPreviewImage(filter()->getTargetImage());
159 }
160
161 void HotPixelsTool::setFinalImage()
162 {
163 ImageIface iface;
164 iface.setOriginal(i18n("Hot Pixels Correction"), filter()->filterAction(), filter()->getTargetImage());
165 }
166
167 void HotPixelsTool::slotHotPixels(const QPolygon& pointList)
168 {
169 d->previewWidget->setHighLightPoints(pointList);
170 slotPreview();
171 }
172
173 } // namespace DigikamEditorHotPixelsToolPlugin
174
175 #include "moc_hotpixelstool.cpp"