digiKam
raindropfilter.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 : Raindrop 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  * This program is free software; you can redistribute it
14  * and/or modify it under the terms of the GNU General
15  * Public License as published by the Free Software Foundation;
16  * either version 2, or (at your option)
17  * any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * ============================================================ */
25 
26 #ifndef DIGIKAM_RAIN_DROP_FILTER_H
27 #define DIGIKAM_RAIN_DROP_FILTER_H
28 
29 // Local includes
30 
31 #include "digikam_export.h"
32 #include "dimgthreadedfilter.h"
33 #include "digikam_globals.h"
34 #include "randomnumbergenerator.h"
35 
36 class QRect;
37 
38 namespace Digikam
39 {
40 
41 class DIGIKAM_EXPORT RainDropFilter : public DImgThreadedFilter
42 {
43  Q_OBJECT
44 
45 private:
46 
47  struct Q_DECL_HIDDEN Args
48  {
49  explicit Args()
50  : start(0),
51  stop(0),
52  orgImage(nullptr),
53  destImage(nullptr),
54  MinDropSize(0),
55  MaxDropSize(0),
56  Coeff(0),
57  bLimitRange(false),
58  pStatusBits(nullptr)
59  {
60  }
61 
62  uint start;
63  uint stop;
64  DImg* orgImage;
65  DImg* destImage;
66  int MinDropSize;
67  int MaxDropSize;
68  int Coeff;
69  bool bLimitRange;
70  uchar* pStatusBits;
71  };
72 
73 public:
74 
75  explicit RainDropFilter(QObject* const parent = nullptr);
76  explicit RainDropFilter(DImg* const orgImage,
77  QObject* const parent = nullptr,
78  int drop=80,
79  int amount=150,
80  int coeff=30,
81  const QRect& selection=QRect(0, 0, 0, 0));
82  ~RainDropFilter() override;
83 
84  static QString FilterIdentifier()
85  {
86  return QLatin1String("digikam:RainDropFilter");
87  }
88 
89  static QString DisplayableName();
90 
92  {
93  return QList<int>() << 1;
94  }
95 
96  static int CurrentVersion()
97  {
98  return 1;
99  }
100 
101  QString filterIdentifier() const override
102  {
103  return FilterIdentifier();
104  }
105 
106  FilterAction filterAction() override;
107 
108  void readParameters(const FilterAction& action) override;
109 
110 private:
111 
112  void filterImage() override;
113 
114  void rainDropsImage(DImg* const orgImage, DImg* const destImage, int MinDropSize, int MaxDropSize,
115  int Amount, int Coeff, bool bLimitRange, int progressMin, int progressMax);
116 
117  void rainDropsImageMultithreaded(const Args& prm);
118 
119  bool CreateRainDrop(uchar* const pBits, int Width, int Height, bool sixteenBit, int bytesDepth,
120  uchar* const pResBits, uchar* const pStatusBits,
121  int X, int Y, int DropSize, double Coeff, bool bLimitRange);
122 
123  bool CanBeDropped(int Width, int Height, uchar* const pStatusBits, int X, int Y, int DropSize, bool bLimitRange);
124 
125  bool SetDropStatusBits(int Width, int Height, uchar* const pStatusBits, int X, int Y, int DropSize);
126 
132  inline int limitValues8(int ColorValue);
133 
134  inline int limitValues16(int ColorValue);
135 
136  inline bool isInside (int Width, int Height, int X, int Y);
137 
138  inline int pixelOffset(int Width, int X, int Y, int bytesDepth);
139 
140 private:
141 
142  class Private;
143  Private* const d;
144 };
145 
146 } // namespace Digikam
147 
148 #endif // DIGIKAM_RAIN_DROP_FILTER_H
Definition: dimgthreadedfilter.h:41
Definition: dimg.h:62
Definition: filteraction.h:43
Definition: raindropfilter.h:42
static int CurrentVersion()
Definition: raindropfilter.h:96
QString filterIdentifier() const override
Definition: raindropfilter.h:101
static QList< int > SupportedVersions()
Definition: raindropfilter.h:91
static QString FilterIdentifier()
Definition: raindropfilter.h:84
#define X
@ Width
Definition: coredbfields.h:87
@ Height
Definition: coredbfields.h:88
Definition: datefolderview.cpp:43