digiKam
Loading...
Searching...
No Matches
distortionfxfilter.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-07-18
7 * Description : Distortion 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 Distortion algorithms copyrighted 2004-2005 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 DIGIKAM_EXPORT DistortionFXFilter : public DImgThreadedFilter
32{
33 Q_OBJECT
34
35public:
36
56
57private:
58
59 class Q_DECL_HIDDEN Args
60 {
61 public:
62
63 Args() = default;
64
65 int start = 0;
66 int stop = 0;
67 int h = 0;
68 int w = 0;
69 DImg* orgImage = nullptr;
70 DImg* destImage = nullptr;
71 double Coeff = 0.0;
72 bool AntiAlias = false;
73 int dist = 0;
74 bool Horizontal = false;
75 bool Vertical = false;
76 int Factor = 0;
77 int Amplitude = 0;
78 int Frequency = 0;
79 bool Mode = false;
80 int X = 0;
81 int Y = 0;
82 double Phase = 0.0;
83 bool WavesType = false;
84 bool FillSides = false;
85 bool Type = false;
86 int WSize = 0;
87 int HSize = 0;
88 int Random = 0;
89 };
90
91public:
92
93 explicit DistortionFXFilter(QObject* const parent = nullptr);
94 explicit DistortionFXFilter(DImg* const orgImage, QObject* const parent = nullptr, int effectType=0,
95 int level=0, int iteration=0, bool antialiasing=true);
96
97 ~DistortionFXFilter() override;
98
99 static QString FilterIdentifier()
100 {
101 return QLatin1String("digikam:DistortionFXFilter");
102 }
103
104 static QString DisplayableName();
105
106 static QList<int> SupportedVersions()
107 {
108 return QList<int>() << 1;
109 }
110
111 static int CurrentVersion()
112 {
113 return 1;
114 }
115
116 QString filterIdentifier() const override
117 {
118 return FilterIdentifier();
119 }
120
121 FilterAction filterAction() override;
122
123 void readParameters(const FilterAction& action) override;
124
125
126private:
127
128 void filterImage() override;
129
130 // Backported from ImageProcessing version 2
131 void fisheye(DImg* orgImage, DImg* destImage, double Coeff, bool AntiAlias = true);
132 void fisheyeMultithreaded(const Args& prm);
133
134 void twirl(DImg* orgImage, DImg* destImage, int dist, bool AntiAlias = true);
135 void twirlMultithreaded(const Args& prm);
136
137 void cilindrical(DImg* orgImage, DImg* destImage, double Coeff,
138 bool Horizontal, bool Vertical, bool AntiAlias = true);
139 void cilindricalMultithreaded(const Args& prm);
140
141 void multipleCorners(DImg* orgImage, DImg* destImage, int Factor, bool AntiAlias = true);
142 void multipleCornersMultithreaded(const Args& prm);
143
144 void polarCoordinates(DImg* orgImage, DImg* destImage, bool Type, bool AntiAlias = true);
145 void polarCoordinatesMultithreaded(const Args& prm);
146
147 void circularWaves(DImg* orgImage, DImg* destImage, int X, int Y, double Amplitude,
148 double Frequency, double Phase, bool WavesType, bool AntiAlias = true);
149 void circularWavesMultithreaded(const Args& prm);
150
151 // Backported from ImageProcessing version 1
152 void waves(DImg* orgImage, DImg* destImage, int Amplitude, int Frequency,
153 bool FillSides, bool Direction);
154 void wavesHorizontalMultithreaded(const Args& prm);
155 void wavesVerticalMultithreaded(const Args& prm);
156
157 void blockWaves(DImg* orgImage, DImg* destImage, int Amplitude, int Frequency, bool Mode);
158 void blockWavesMultithreaded(const Args& prm);
159
160 void tile(DImg* orgImage, DImg* destImage, int WSize, int HSize, int Random);
161 void tileMultithreaded(const Args& prm);
162
163 void setPixelFromOther(int Width, int Height, bool sixteenBit, int bytesDepth,
164 uchar* data, uchar* pResBits,
165 int w, int h, double nw, double nh, bool AntiAlias);
166
167 // Return the limit defined the max and min values.
168 inline int Lim_Max(int Now, int Up, int Max)
169 {
170 --Max;
171
172 while (Now > Max - Up)
173 {
174 --Up;
175 }
176
177 return (Up);
178 };
179
180 inline bool isInside (int Width, int Height, int X, int Y)
181 {
182 bool bIsWOk = ((X < 0) ? false : (X >= Width ) ? false : true);
183 bool bIsHOk = ((Y < 0) ? false : (Y >= Height) ? false : true);
184
185 return (bIsWOk && bIsHOk);
186 };
187
188 inline int getOffset(int Width, int X, int Y, int bytesDepth)
189 {
190 return (Y * Width * bytesDepth) + (X * bytesDepth);
191 };
192
193 inline int getOffsetAdjusted(int Width, int Height, int X, int Y, int bytesDepth)
194 {
195 X = (X < 0) ? 0 : ((X >= Width ) ? (Width - 1) : X);
196 Y = (Y < 0) ? 0 : ((Y >= Height) ? (Height - 1) : Y);
197
198 return getOffset(Width, X, Y, bytesDepth);
199 };
200
201private:
202
203 class Private;
204 Private* const d = nullptr;
205};
206
207} // namespace Digikam
Definition dimgthreadedfilter.h:31
Definition dimg.h:52
Definition distortionfxfilter.h:32
static int CurrentVersion()
Definition distortionfxfilter.h:111
static QList< int > SupportedVersions()
Definition distortionfxfilter.h:106
static QString FilterIdentifier()
Definition distortionfxfilter.h:99
QString filterIdentifier() const override
Definition distortionfxfilter.h:116
DistortionFXTypes
Definition distortionfxfilter.h:38
@ WavesVertical
Definition distortionfxfilter.h:47
@ PolarCoordinates
Definition distortionfxfilter.h:52
@ CircularWaves1
Definition distortionfxfilter.h:50
@ CircularWaves2
Definition distortionfxfilter.h:51
@ WavesHorizontal
Definition distortionfxfilter.h:46
@ BlockWaves2
Definition distortionfxfilter.h:49
@ MultipleCorners
Definition distortionfxfilter.h:45
@ CilindricalHor
Definition distortionfxfilter.h:41
@ Twirl
Definition distortionfxfilter.h:40
@ Caricature
Definition distortionfxfilter.h:44
@ BlockWaves1
Definition distortionfxfilter.h:48
@ CilindricalVert
Definition distortionfxfilter.h:42
@ CilindricalHV
Definition distortionfxfilter.h:43
@ UnpolarCoordinates
Definition distortionfxfilter.h:53
Definition filteraction.h:33
#define X
@ Width
Definition coredbfields.h:77
@ Height
Definition coredbfields.h:78
Definition datefolderview.cpp:34
Type
Definition gpsitemcontainer.h:36