1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284 | /* ============================================================
*
* This file is a part of digiKam project
* https://www.digikam.org
*
* Date : 2020-08-05)
* Description : HotPixel settings view.
*
* SPDX-FileCopyrightText: 2020-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* ============================================================ */
#include "hotpixelsettings.h"
// Qt includes
#include <QGridLayout>
#include <QLabel>
#include <QString>
#include <QIcon>
#include <QTextStream>
#include <QPushButton>
#include <QApplication>
#include <QStyle>
#include <QPointer>
#include <QMessageBox>
// KDE includes
#include <kconfiggroup.h>
#include <klocalizedstring.h>
// Local includes
#include "digikam_debug.h"
#include "hotpixelfixer.h"
#include "dcombobox.h"
#include "imagedialog.h"
#include "blackframelistview.h"
#include "blackframelistviewitem.h"
namespace Digikam
{
class Q_DECL_HIDDEN HotPixelSettings::Private
{
public:
Private() = default;
static const QString configGroupName;
static const QString configAllBlackFrameFilesEntry;
static const QString configCurrentBlackFrameFileEntry;
static const QString configHotPixelsListEntry;
static const QString configFilterMethodEntry;
QPushButton* blackFrameButton = nullptr;
DComboBox* filterMethodCombo = nullptr;
BlackFrameListView* blackFrameListView = nullptr;
QList<HotPixelProps> hotPixelsList;
QUrl currentBlackFrameUrl;
QList<QUrl> allBlackFrameUrls;
};
const QString HotPixelSettings::Private::configGroupName(QLatin1String("hotpixels Tool"));
const QString HotPixelSettings::Private::configAllBlackFrameFilesEntry(QLatin1String("All Black Frame Files"));
const QString HotPixelSettings::Private::configCurrentBlackFrameFileEntry(QLatin1String("Current Black Frame File"));
const QString HotPixelSettings::Private::configHotPixelsListEntry(QLatin1String("Hot Pixels List"));
const QString HotPixelSettings::Private::configFilterMethodEntry(QLatin1String("Filter Method"));
// --------------------------------------------------------
HotPixelSettings::HotPixelSettings(QWidget* const parent)
: QWidget(parent),
d (new Private)
{
const int spacing = qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing),
QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing));
QGridLayout* const grid = new QGridLayout(parent);
QLabel* const filterMethodLabel = new QLabel(i18n("Filter:"), this);
d->filterMethodCombo = new DComboBox(this);
d->filterMethodCombo->addItem(i18nc("average filter mode", "Average"));
d->filterMethodCombo->addItem(i18nc("linear filter mode", "Linear"));
d->filterMethodCombo->addItem(i18nc("quadratic filter mode", "Quadratic"));
d->filterMethodCombo->addItem(i18nc("cubic filter mode", "Cubic"));
d->filterMethodCombo->setDefaultIndex(HotPixelContainer::QUADRATIC_INTERPOLATION);
d->blackFrameButton = new QPushButton(i18n("Black Frame..."), this);
d->blackFrameButton->setIcon(QIcon::fromTheme(QLatin1String("document-open")));
d->blackFrameButton->setWhatsThis(i18n("<p>Use this button to add a new black frame file which will "
"be used by the hot pixels removal filter.</p>"
"<p>The Black Frame subtraction method is the most accurate "
"\"Hot Pixels\" and \"Stuck Pixels\" removal. First you have to "
"create a \"Black Frame\" as a reference. This is easy to do. "
"When you finish taking your long exposure shots, put a lens cap "
"on the camera and take one \"dark\" image with the same exposure "
"time as the images before. This image will be all dark, but with "
"close examination you will see that it has the Hot and Stuck Pixels "
"(colored dots). These are positioned at the same places as on your "
"previous shots. This tool will parse black frame, detect hot pixels, "
"and create a list of positions where image must be corrected to "
"eliminate wrong colors in these pixels.</p>"));
d->blackFrameListView = new BlackFrameListView(this);
// -------------------------------------------------------------
grid->addWidget(filterMethodLabel, 0, 0, 1, 1);
grid->addWidget(d->filterMethodCombo, 0, 1, 1, 1);
grid->addWidget(d->blackFrameButton, 0, 2, 1, 1);
grid->addWidget(d->blackFrameListView, 1, 0, 2, 3);
grid->setRowStretch(2, 10);
grid->setContentsMargins(spacing, spacing, spacing, spacing);
grid->setSpacing(spacing);
// -------------------------------------------------------------
connect(d->blackFrameButton, SIGNAL(clicked()),
this, SLOT(slotAddBlackFrame()));
connect(d->blackFrameListView, SIGNAL(signalBlackFrameSelected(QList<HotPixelProps>,QUrl)),
this, SLOT(slotBlackFrameSelected(QList<HotPixelProps>,QUrl)));
connect(d->blackFrameListView, SIGNAL(signalBlackFrameRemoved(QUrl)),
this, SLOT(slotBlackFrameRemoved(QUrl)));
connect(d->blackFrameListView, SIGNAL(signalClearBlackFrameList()),
this, SLOT(slotClearBlackFrameList()));
}
HotPixelSettings::~HotPixelSettings()
{
delete d;
}
QString HotPixelSettings::configGroupName() const
{
return d->configGroupName;
}
HotPixelContainer HotPixelSettings::settings() const
{
HotPixelContainer prm;
prm.blackFrameUrl = d->currentBlackFrameUrl;
prm.hotPixelsList = d->hotPixelsList;
prm.filterMethod = (HotPixelContainer::InterpolationMethod)d->filterMethodCombo->currentIndex();
return prm;
}
void HotPixelSettings::setSettings(const HotPixelContainer& settings)
{
blockSignals(true);
d->currentBlackFrameUrl = settings.blackFrameUrl;
d->hotPixelsList = settings.hotPixelsList;
d->filterMethodCombo->setCurrentIndex(settings.filterMethod);
blockSignals(false);
}
void HotPixelSettings::resetToDefault()
{
blockSignals(true);
d->currentBlackFrameUrl = QUrl();
d->hotPixelsList = QList<HotPixelProps>();
d->filterMethodCombo->slotReset();
blockSignals(false);
}
HotPixelContainer HotPixelSettings::defaultSettings() const
{
return HotPixelContainer();
}
void HotPixelSettings::readSettings(KConfigGroup& group)<--- Parameter 'group' can be declared as reference to const
{
d->allBlackFrameUrls = group.readEntry(d->configAllBlackFrameFilesEntry, QList<QUrl>());
HotPixelContainer prm;
HotPixelContainer defaultPrm = defaultSettings();
prm.blackFrameUrl = group.readEntry(d->configCurrentBlackFrameFileEntry,
defaultPrm.blackFrameUrl);
QStringList hplst = group.readEntry(d->configHotPixelsListEntry, QStringList());
prm.hotPixelsList = HotPixelProps::fromStringList(hplst);
prm.filterMethod = (HotPixelContainer::InterpolationMethod)group.readEntry(d->configFilterMethodEntry, (int)defaultPrm.filterMethod);
setSettings(prm);
Q_FOREACH (const QUrl& url, d->allBlackFrameUrls)
{
if (url.isValid() && !d->blackFrameListView->contains(url))
{
loadBlackFrame(url, (url == d->currentBlackFrameUrl));
}
}
}
void HotPixelSettings::writeSettings(KConfigGroup& group)
{
group.writeEntry(d->configAllBlackFrameFilesEntry, d->allBlackFrameUrls);
HotPixelContainer prm = settings();
group.writeEntry(d->configCurrentBlackFrameFileEntry, prm.blackFrameUrl);
QStringList hplst = HotPixelProps::toStringList(prm.hotPixelsList);
group.writeEntry(d->configHotPixelsListEntry, hplst);
group.writeEntry(d->configFilterMethodEntry, (int)prm.filterMethod);
}
void HotPixelSettings::slotAddBlackFrame()
{
QUrl url = ImageDialog::getImageURL(qApp->activeWindow(), d->currentBlackFrameUrl, i18n("Select Black Frame Image"));
if (!url.isEmpty())
{
if (d->blackFrameListView->contains(url))
{
QMessageBox::information(this, i18nc("@title:window", "Black Frame Parser"),
i18n("This black frame image is already present in the list of parsed items."));
return;
}
// Load the selected file and insert into the list.
d->allBlackFrameUrls << url;
d->currentBlackFrameUrl = url;
loadBlackFrame(url, true);
}
}
void HotPixelSettings::loadBlackFrame(const QUrl& url, bool selected)
{
QPointer<BlackFrameListViewItem> item = new BlackFrameListViewItem(d->blackFrameListView, url);
if (selected)
{
d->blackFrameListView->setCurrentItem(item);
}
}
void HotPixelSettings::slotBlackFrameSelected(const QList<HotPixelProps>& hpList, const QUrl& url)
{
if (d->blackFrameListView->isSelected(url))
{
d->currentBlackFrameUrl = url;
d->hotPixelsList = hpList;
int i = 0;
QPolygon pointList(d->hotPixelsList.size());
QList <HotPixelProps>::const_iterator it;
for (it = d->hotPixelsList.constBegin() ; it != d->hotPixelsList.constEnd() ; ++it, ++i)
{
pointList.setPoint(i, (*it).rect.center());
}
Q_EMIT signalHotPixels(pointList);
}
}
void HotPixelSettings::slotBlackFrameRemoved(const QUrl& url)
{
d->allBlackFrameUrls.removeAll(url);
d->currentBlackFrameUrl = d->blackFrameListView->currentUrl();
}
void HotPixelSettings::slotClearBlackFrameList()
{
d->allBlackFrameUrls.clear();
d->currentBlackFrameUrl = QUrl();
}
} // namespace Digikam
#include "moc_hotpixelsettings.cpp"
|