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 | /* ============================================================
*
* This file is a part of digiKam project
* https://www.digikam.org
*
* Date : 2010-11-10
* Description : meta-filter to apply FilterAction
*
* SPDX-FileCopyrightText: 2010-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
* SPDX-FileCopyrightText: 2010 by Martin Klapetek <martin dot klapetek at gmail dot com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* ============================================================ */
#include "filteractionfilter.h"
// Qt includes
#include <QScopedPointer>
// KDE includes
#include <klocalizedstring.h>
// Local includes
#include "digikam_debug.h"
#include "dimgbuiltinfilter.h"
#include "dimgfiltermanager.h"
namespace Digikam
{
class Q_DECL_HIDDEN FilterActionFilter::Private
{
public:
Private() = default;
bool continueOnError = false;
QList<FilterAction> actions;
QList<FilterAction> appliedActions;
QString errorMessage;
};
FilterActionFilter::FilterActionFilter(QObject* const parent)
: DImgThreadedFilter(parent),
d (new Private)
{
initFilter();
}
FilterActionFilter::~FilterActionFilter()
{
delete d;
}
void FilterActionFilter::setContinueOnError(bool cont)
{
d->continueOnError = cont;
}
void FilterActionFilter::setFilterActions(const QList<FilterAction>& actions)
{
d->actions = actions;
}
void FilterActionFilter::addFilterActions(const QList<FilterAction>& actions)
{
d->actions += actions;
}
void FilterActionFilter::setFilterAction(const FilterAction& action)
{
d->actions.clear();
d->actions << action;
}
void FilterActionFilter::addFilterAction(const FilterAction& action)
{
d->actions << action;
}
QList<FilterAction> FilterActionFilter::filterActions() const
{
return d->actions;
}
bool FilterActionFilter::isReproducible() const
{
for (const FilterAction& action : std::as_const(d->actions))<--- Consider using std::all_of or std::none_of algorithm instead of a raw loop.
{
if (
!action.isNull() &&
(action.category() != FilterAction::ReproducibleFilter)
)
{ // cppcheck-suppress useStlAlgorithm
return false;
}
}
return true;
}
bool FilterActionFilter::isComplexAction() const
{
for (const FilterAction& action : std::as_const(d->actions))<--- Consider using std::all_of or std::none_of algorithm instead of a raw loop.
{
if (
!action.isNull() &&
(action.category() != FilterAction::ReproducibleFilter) &&
(action.category() != FilterAction::ComplexFilter)
)
{ // cppcheck-suppress useStlAlgorithm
return false;
}
}
return true;
}
bool FilterActionFilter::isSupported() const
{
for (const FilterAction& action : std::as_const(d->actions))<--- Consider using std::all_of or std::none_of algorithm instead of a raw loop.
{
if (!action.isNull() && !DImgFilterManager::instance()->isSupported(action.identifier(), action.version()))
{ // cppcheck-suppress useStlAlgorithm
return false;
}
}
return true;
}
bool FilterActionFilter::completelyApplied() const
{
return (d->appliedActions.size() == d->actions.size());
}
QList<FilterAction> FilterActionFilter::appliedFilterActions() const
{
return d->appliedActions;
}
FilterAction FilterActionFilter::failedAction() const
{
if (d->appliedActions.size() >= d->actions.size())
{
return FilterAction();
}
return d->actions.at(d->appliedActions.size());
}
int FilterActionFilter::failedActionIndex() const
{
return d->appliedActions.size();
}
QString FilterActionFilter::failedActionMessage() const
{
return d->errorMessage;
}
void FilterActionFilter::filterImage()
{
d->appliedActions.clear();
d->errorMessage.clear();
const float progressIncrement = 1.0 / qMax(1, d->actions.size());
float progress = 0;
postProgress(0);
DImg img = m_orgImage;
for (const FilterAction& action : std::as_const(d->actions))
{
qCDebug(DIGIKAM_DIMG_LOG) << "Replaying action" << action.identifier();
if (action.isNull())
{
continue;
}
if (DImgBuiltinFilter::isSupported(action.identifier()))
{
DImgBuiltinFilter filter(action);
if (!filter.isValid())
{
d->errorMessage = i18n("Built-in transformation not supported");
if (d->continueOnError)
{
continue;
}
else
{
break;
}
}
filter.apply(img);
d->appliedActions << filter.filterAction();
}
else
{
QScopedPointer<DImgThreadedFilter> filter
(DImgFilterManager::instance()->createFilter(action.identifier(), action.version()));
if (!filter)
{
d->errorMessage = i18n("Filter identifier or version is not supported");
if (d->continueOnError)
{
continue;
}
else
{
break;
}
}
filter->readParameters(action);
if (!filter->parametersSuccessfullyRead())
{
d->errorMessage = filter->readParametersError(action);
if (d->continueOnError)
{
continue;
}
else
{
break;
}
}
// compute
filter->setupAndStartDirectly(img, this, (int)progress, (int)(progress + progressIncrement));
img = filter->getTargetImage();
d->appliedActions << filter->filterAction();
}
progress += progressIncrement;
postProgress((int)progress);
}
m_destImage = img;
}
} // namespace Digikam
#include "moc_filteractionfilter.cpp"
|