digiKam
Loading...
Searching...
No Matches
blurfxfilter.h
Go to the documentation of this file.
1/* ============================================================
2 *
3 * This file is a part of digiKam project
4 * https://www.digikam.org
5 *
6 * Date : 2005-05-25
7 * Description : Blur FX threaded image filter.
8 *
9 * SPDX-FileCopyrightText: 2005-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
10 * SPDX-FileCopyrightText: 2006-2010 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
11 * SPDX-FileCopyrightText: 2010 by Martin Klapetek <martin dot klapetek at gmail dot com>
12 *
13 * Original Blur algorithms copyrighted 2004 by
14 * Pieter Z. Voloshyn <pieter dot voloshyn at gmail dot com>.
15 *
16 * SPDX-License-Identifier: GPL-2.0-or-later
17 *
18 * ============================================================ */
19
20#pragma once
21
22// Local includes
23
24#include "digikam_export.h"
25#include "dimgthreadedfilter.h"
26#include "digikam_globals.h"
27
28namespace Digikam
29{
30
31class RandomNumberGenerator;
32
33class DIGIKAM_EXPORT BlurFXFilter : public DImgThreadedFilter
34{
35 Q_OBJECT
36
37public:
38
52
53private:
54
55 struct Q_DECL_HIDDEN Args
56 {
57 explicit Args()
58 : start (0),
59 stop (0),
60 h (0),
61 w (0),
62 orgImage (nullptr),
63 destImage (nullptr),
64 X (0),
65 Y (0),
66 Distance (0),
67 nCount (0),
68 lpXArray (nullptr),
69 lpYArray (nullptr),
70 BlendRadius (0),
71 bInversed (0),
72 layer1 (nullptr),
73 layer2 (nullptr),
74 layer3 (nullptr),
75 layer4 (nullptr),
76 SizeW (0),
77 SizeH (0),
78 StrengthRange(0),
79 Radius (0),
80 Kernel (nullptr),
81 arrMult (nullptr),
82 pBlur (nullptr)
83 {
84 }
85
86 uint start;
87 uint stop;
88 uint h;
89 uint w;
90 DImg* orgImage;
91 DImg* destImage;
92 int X;
93 int Y;
94 int Distance;
95
96 int nCount;
97 int* lpXArray;
98 int* lpYArray;
99
100 int BlendRadius;
101 bool bInversed;
102
103 uchar* layer1;
104 uchar* layer2;
105 uchar* layer3;
106 uchar* layer4;
107
108 int SizeW;
109 int SizeH;
110
111 int StrengthRange;
112 int Radius;
113 int* Kernel;
114 int** arrMult;
115 uchar* pBlur;
116 };
117
118public:
119
120 explicit BlurFXFilter(QObject* const parent = nullptr);
121 explicit BlurFXFilter(DImg* const orgImage,
122 QObject* const parent = nullptr,
123 int blurFXType = ZoomBlur,
124 int distance = 100,
125 int level = 45);
126 ~BlurFXFilter() override;
127
128 static QString FilterIdentifier()
129 {
130 return QLatin1String("digikam:BlurFXFilter");
131 }
132
133 static QString DisplayableName();
134
135 static QList<int> SupportedVersions()
136 {
137 return QList<int>() << 1;
138 }
139
140 static int CurrentVersion()
141 {
142 return 1;
143 }
144
145 QString filterIdentifier() const override
146 {
147 return FilterIdentifier();
148 }
149
150 FilterAction filterAction() override;
151
152 void readParameters(const FilterAction& action) override;
153
154private:
155
156 void filterImage() override;
157
158 // Backported from ImageProcessing version 1
159 void softenerBlur(DImg* const orgImage, DImg* const destImage);
160 void softenerBlurMultithreaded(const Args& prm);
161
162 void shakeBlur(DImg* const orgImage, DImg* const destImage, int Distance);
163 void shakeBlurStage1Multithreaded(const Args& prm);
164 void shakeBlurStage2Multithreaded(const Args& prm);
165
166 void frostGlass(DImg* const orgImage, DImg* const destImage, int Frost);
167
168 // Backported from ImageProcessing version 2
169 void zoomBlur(DImg* const orgImage, DImg* const destImage, int X, int Y, int Distance, const QRect& pArea=QRect());
170 void zoomBlurMultithreaded(const Args& prm);
171
172 void radialBlur(DImg* const orgImage, DImg* const destImage, int X, int Y, int Distance, const QRect& pArea=QRect());
173 void radialBlurMultithreaded(const Args& prm);
174
175 void focusBlur(DImg* const orgImage, DImg* const destImage, int X, int Y, int BlurRadius, int BlendRadius,
176 bool bInversed=false, const QRect& pArea=QRect());
177 void focusBlurMultithreaded(const Args& prm);
178
179 void farBlur(DImg* const orgImage, DImg* const destImage, int Distance);
180
181 void motionBlur(DImg* const orgImage, DImg* const destImage, int Distance, double Angle=0.0);
182 void motionBlurMultithreaded(const Args& prm);
183
184 void smartBlur(DImg* const orgImage, DImg* const destImage, int Radius, int Strength);
185 void smartBlurStage1Multithreaded(const Args& prm);
186 void smartBlurStage2Multithreaded(const Args& prm);
187
188 void mosaic(DImg* const orgImage, DImg* const destImage, int SizeW, int SizeH);
189 void mosaicMultithreaded(const Args& prm);
190
191private:
192
193 void MakeConvolution(DImg* const orgImage, DImg* const destImage, int Radius, int Kernel[]);
194 void MakeConvolutionStage1Multithreaded(const Args& prm);
195 void MakeConvolutionStage2Multithreaded(const Args& prm);
196
197 DColor RandomColor(uchar* const Bits, int Width, int Height, bool sixteenBit, int bytesDepth,
198 int X, int Y, int Radius,
199 int alpha, RandomNumberGenerator& generator, int range, uchar* const IntensityCount,
200 uint* const AverageColorR, uint* const AverageColorG, uint* const AverageColorB);
201
202 // Return the limit defined the max and min values.
203 inline int Lim_Max(int Now, int Up, int Max)
204 {
205 --Max;
206
207 while (Now > Max - Up)
208 {
209 --Up;
210 }
211
212 return (Up);
213 };
214
215 // Return the luminance (Y) component of YIQ color model.
216 inline int GetIntensity (int R, int G, int B)
217 {
218 return (int)(R * 0.3 + G * 0.59 + B * 0.11);
219 };
220
221 // function to allocate a 2d array
222 inline int** Alloc2DArray (int Columns, int Rows)
223 {
224 // We declare our future 2d array to be returned
225 // and we alloc the main pointer with Columns
226 int** lpcArray = new int*[Columns];
227
228 for (int i = 0 ; i < Columns ; ++i)
229 {
230 lpcArray[i] = new int[Rows];
231 }
232
233 return (lpcArray);
234 }
235
236 // Function to deallocates the 2d array previously created
237 inline void Free2DArray (int** lpcArray, int Columns)
238 {
239 // loop to deallocate the columns
240 for (int i = 0 ; i < Columns ; ++i)
241 {
242 delete [] lpcArray[i];
243 }
244
245 // now, we delete the main pointer
246 delete [] lpcArray;
247 }
248
249 inline bool IsInside (int Width, int Height, int X, int Y)
250 {
251 bool bIsWOk = ((X < 0) ? false : (X >= Width ) ? false : true);
252 bool bIsHOk = ((Y < 0) ? false : (Y >= Height) ? false : true);
253
254 return (bIsWOk && bIsHOk);
255 };
256
257 inline int GetOffset(int Width, int X, int Y, int bytesDepth)
258 {
259 return (Y * Width * bytesDepth) + (X * bytesDepth);
260 };
261
262 inline int GetOffsetAdjusted(int Width, int Height, int X, int Y, int bytesDepth)
263 {
264 X = (X < 0) ? 0 : ((X >= Width ) ? (Width - 1) : X);
265 Y = (Y < 0) ? 0 : ((Y >= Height) ? (Height - 1) : Y);
266
267 return GetOffset(Width, X, Y, bytesDepth);
268 };
269
270 inline bool IsColorInsideTheRange (int cR, int cG, int cB,
271 int nR, int nG, int nB,
272 int Range)
273 {
274 if ((nR >= (cR - Range)) && (nR <= (cR + Range)))
275 {
276 if ((nG >= (cG - Range)) && (nG <= (cG + Range)))
277 {
278 if ((nB >= (cB - Range)) && (nB <= (cB + Range)))
279 {
280 return true;
281 }
282 }
283 }
284
285 return false;
286 };
287
288private:
289
290 class Private;
291 Private* const d = nullptr;
292};
293
294} // namespace Digikam
Definition blurfxfilter.h:34
static QList< int > SupportedVersions()
Definition blurfxfilter.h:135
QString filterIdentifier() const override
Definition blurfxfilter.h:145
static int CurrentVersion()
Definition blurfxfilter.h:140
BlurFXFilterTypes
Definition blurfxfilter.h:40
@ ShakeBlur
Definition blurfxfilter.h:46
@ SoftenerBlur
Definition blurfxfilter.h:45
@ MotionBlur
Definition blurfxfilter.h:44
@ SmartBlur
Definition blurfxfilter.h:48
@ FarBlur
Definition blurfxfilter.h:43
@ RadialBlur
Definition blurfxfilter.h:42
@ FocusBlur
Definition blurfxfilter.h:47
@ FrostGlass
Definition blurfxfilter.h:49
static QString FilterIdentifier()
Definition blurfxfilter.h:128
Definition dcolor.h:33
Definition dimgthreadedfilter.h:31
Definition dimg.h:52
Definition filteraction.h:33
Definition randomnumbergenerator.h:54
#define X
@ Width
Definition coredbfields.h:77
@ Height
Definition coredbfields.h:78
Definition datefolderview.cpp:34