digiKam
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  * Copyright (C) 2005-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
10  * Copyright (C) 2006-2010 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
11  * Copyright (C) 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  * This program is free software; you can redistribute it
17  * and/or modify it under the terms of the GNU General
18  * Public License as published by the Free Software Foundation;
19  * either version 2, or (at your option)
20  * any later version.
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU General Public License for more details.
26  *
27  * ============================================================ */
28 
29 #ifndef DIGIKAM_DISTORTION_FX_FILTER_H
30 #define DIGIKAM_DISTORTION_FX_FILTER_H
31 
32 // Local includes
33 
34 #include "digikam_export.h"
35 #include "dimgthreadedfilter.h"
36 #include "digikam_globals.h"
37 
38 namespace Digikam
39 {
40 
41 class DIGIKAM_EXPORT DistortionFXFilter : public DImgThreadedFilter
42 {
43  Q_OBJECT
44 
45 public:
46 
48  {
49  FishEye=0,
64  Tile
65  };
66 
67 private:
68 
69  struct Q_DECL_HIDDEN Args
70  {
71  explicit Args()
72  : start(0),
73  stop(0),
74  h(0),
75  w(0),
76  orgImage(nullptr),
77  destImage(nullptr),
78  Coeff(0.0),
79  AntiAlias(false),
80  dist(0),
81  Horizontal(false),
82  Vertical(false),
83  Factor(0),
84  Amplitude(0),
85  Frequency(0),
86  Mode(false),
87  X(0),
88  Y(0),
89  Phase(0.0),
90  WavesType(false),
91  FillSides(false),
92  Type(false),
93  WSize(0),
94  HSize(0),
95  Random(0)
96  {
97  }
98 
99  int start;
100  int stop;
101  int h;
102  int w;
103  DImg* orgImage;
104  DImg* destImage;
105  double Coeff;
106  bool AntiAlias;
107  int dist;
108  bool Horizontal;
109  bool Vertical;
110  int Factor;
111  int Amplitude;
112  int Frequency;
113  bool Mode;
114  int X;
115  int Y;
116  double Phase;
117  bool WavesType;
118  bool FillSides;
119  bool Type;
120  int WSize;
121  int HSize;
122  int Random;
123  };
124 
125 public:
126 
127  explicit DistortionFXFilter(QObject* const parent = nullptr);
128  explicit DistortionFXFilter(DImg* const orgImage, QObject* const parent = nullptr, int effectType=0,
129  int level=0, int iteration=0, bool antialiasing=true);
130 
131  ~DistortionFXFilter() override;
132 
133  static QString FilterIdentifier()
134  {
135  return QLatin1String("digikam:DistortionFXFilter");
136  }
137 
138  static QString DisplayableName();
139 
141  {
142  return QList<int>() << 1;
143  }
144 
145  static int CurrentVersion()
146  {
147  return 1;
148  }
149 
150  QString filterIdentifier() const override
151  {
152  return FilterIdentifier();
153  }
154 
155  FilterAction filterAction() override;
156 
157  void readParameters(const FilterAction& action) override;
158 
159 
160 private:
161 
162  void filterImage() override;
163 
164  // Backported from ImageProcessing version 2
165  void fisheye(DImg* orgImage, DImg* destImage, double Coeff, bool AntiAlias=true);
166  void fisheyeMultithreaded(const Args& prm);
167 
168  void twirl(DImg* orgImage, DImg* destImage, int dist, bool AntiAlias=true);
169  void twirlMultithreaded(const Args& prm);
170 
171  void cilindrical(DImg* orgImage, DImg* destImage, double Coeff,
172  bool Horizontal, bool Vertical, bool AntiAlias=true);
173  void cilindricalMultithreaded(const Args& prm);
174 
175  void multipleCorners(DImg* orgImage, DImg* destImage, int Factor, bool AntiAlias=true);
176  void multipleCornersMultithreaded(const Args& prm);
177 
178  void polarCoordinates(DImg* orgImage, DImg* destImage, bool Type, bool AntiAlias=true);
179  void polarCoordinatesMultithreaded(const Args& prm);
180 
181  void circularWaves(DImg* orgImage, DImg* destImage, int X, int Y, double Amplitude,
182  double Frequency, double Phase, bool WavesType, bool AntiAlias=true);
183  void circularWavesMultithreaded(const Args& prm);
184 
185  // Backported from ImageProcessing version 1
186  void waves(DImg* orgImage, DImg* destImage, int Amplitude, int Frequency,
187  bool FillSides, bool Direction);
188  void wavesHorizontalMultithreaded(const Args& prm);
189  void wavesVerticalMultithreaded(const Args& prm);
190 
191  void blockWaves(DImg* orgImage, DImg* destImage, int Amplitude, int Frequency, bool Mode);
192  void blockWavesMultithreaded(const Args& prm);
193 
194  void tile(DImg* orgImage, DImg* destImage, int WSize, int HSize, int Random);
195  void tileMultithreaded(const Args& prm);
196 
197  void setPixelFromOther(int Width, int Height, bool sixteenBit, int bytesDepth,
198  uchar* data, uchar* pResBits,
199  int w, int h, double nw, double nh, bool AntiAlias);
200 
201  // Return the limit defined the max and min values.
202  inline int Lim_Max(int Now, int Up, int Max)
203  {
204  --Max;
205 
206  while (Now > Max - Up)
207  {
208  --Up;
209  }
210 
211  return (Up);
212  };
213 
214  inline bool isInside (int Width, int Height, int X, int Y)
215  {
216  bool bIsWOk = ((X < 0) ? false : (X >= Width ) ? false : true);
217  bool bIsHOk = ((Y < 0) ? false : (Y >= Height) ? false : true);
218 
219  return (bIsWOk && bIsHOk);
220  };
221 
222  inline int getOffset(int Width, int X, int Y, int bytesDepth)
223  {
224  return (Y * Width * bytesDepth) + (X * bytesDepth);
225  };
226 
227  inline int getOffsetAdjusted(int Width, int Height, int X, int Y, int bytesDepth)
228  {
229  X = (X < 0) ? 0 : ((X >= Width ) ? (Width - 1) : X);
230  Y = (Y < 0) ? 0 : ((Y >= Height) ? (Height - 1) : Y);
231 
232  return getOffset(Width, X, Y, bytesDepth);
233  };
234 
235 private:
236 
237  class Private;
238  Private* const d;
239 };
240 
241 } // namespace Digikam
242 
243 #endif // DIGIKAM_DISTORTION_FX_FILTER_H
Definition: dimgthreadedfilter.h:41
Definition: dimg.h:62
Definition: distortionfxfilter.h:42
static int CurrentVersion()
Definition: distortionfxfilter.h:145
static QList< int > SupportedVersions()
Definition: distortionfxfilter.h:140
static QString FilterIdentifier()
Definition: distortionfxfilter.h:133
QString filterIdentifier() const override
Definition: distortionfxfilter.h:150
DistortionFXTypes
Definition: distortionfxfilter.h:48
@ WavesVertical
Definition: distortionfxfilter.h:57
@ PolarCoordinates
Definition: distortionfxfilter.h:62
@ CircularWaves1
Definition: distortionfxfilter.h:60
@ CircularWaves2
Definition: distortionfxfilter.h:61
@ WavesHorizontal
Definition: distortionfxfilter.h:56
@ BlockWaves2
Definition: distortionfxfilter.h:59
@ MultipleCorners
Definition: distortionfxfilter.h:55
@ CilindricalHor
Definition: distortionfxfilter.h:51
@ Twirl
Definition: distortionfxfilter.h:50
@ Caricature
Definition: distortionfxfilter.h:54
@ BlockWaves1
Definition: distortionfxfilter.h:58
@ CilindricalVert
Definition: distortionfxfilter.h:52
@ CilindricalHV
Definition: distortionfxfilter.h:53
@ UnpolarCoordinates
Definition: distortionfxfilter.h:63
Definition: filteraction.h:43
#define X
@ Width
Definition: coredbfields.h:87
@ Height
Definition: coredbfields.h:88
Definition: datefolderview.cpp:43
Type
Definition: gpsitemcontainer.h:45