ASPiK SDK
cbitmapfilter.h
1 // This file is part of VSTGUI. It is subject to the license terms
2 // in the LICENSE file found in the top-level directory of this
3 // distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
4 
5 #ifndef __cbitmapfilter__
6 #define __cbitmapfilter__
7 
8 #include "vstguifwd.h"
9 #include <vector>
10 #include <string>
11 #include <map>
12 
13 namespace VSTGUI {
14 
15 namespace BitmapFilter {
16 
17 //----------------------------------------------------------------------------------------------------
20 //----------------------------------------------------------------------------------------------------
21 class Property
22 {
23 public:
24  enum Type {
25  kUnknown = 0,
26  kInteger,
27  kFloat,
28  kObject,
29  kRect,
30  kPoint,
31  kColor,
32  kTransformMatrix
33  };
34 
35  Property (Type type = kUnknown);
36  Property (int32_t intValue);
37  Property (double floatValue);
38  Property (IReference* objectValue);
39  Property (const CRect& rectValue);
40  Property (const CPoint& pointValue);
41  Property (const CColor& colorValue);
42  Property (const CGraphicsTransform& transformValue);
43  Property (const Property& p);
44  Property (Property&& p) noexcept;
45  ~Property () noexcept;
46 
47  Type getType () const { return type; }
48 
49  int32_t getInteger () const;
50  double getFloat () const;
51  IReference* getObject () const;
52  const CRect& getRect () const;
53  const CPoint& getPoint () const;
54  const CColor& getColor () const;
55  const CGraphicsTransform& getTransform () const;
56 
57  Property& operator=(const Property& p);
58  Property& operator=(Property&& p) noexcept;
59 
60 //----------------------------------------------------------------------------------------------------
61 private:
62  template<typename T> void assign (T value);
63  Type type;
64  void* value;
65 };
66 
67 //----------------------------------------------------------------------------------------------------
70 //----------------------------------------------------------------------------------------------------
72 {
73 public:
74  virtual bool run (bool replaceInputBitmap = false) = 0;
75 
76  virtual UTF8StringPtr getDescription () const = 0;
77  virtual bool setProperty (IdStringPtr name, const Property& property) = 0;
78  virtual bool setProperty (IdStringPtr name, Property&& property) = 0;
79  virtual const Property& getProperty (IdStringPtr name) const = 0;
80 
81  virtual uint32_t getNumProperties () const = 0;
82  virtual IdStringPtr getPropertyName (uint32_t index) const = 0;
83  virtual Property::Type getPropertyType (uint32_t index) const = 0;
84  virtual Property::Type getPropertyType (IdStringPtr name) const = 0;
85 
86  using CreateFunction = IFilter* (*) (IdStringPtr name);
87 };
88 
89 //----------------------------------------------------------------------------------------------------
93 //----------------------------------------------------------------------------------------------------
94 class Factory
95 {
96 public:
97  static Factory& getInstance ();
98 
99  uint32_t getNumFilters () const;
100  IdStringPtr getFilterName (uint32_t index) const;
101 
102  IFilter* createFilter (IdStringPtr name) const;
103 
104  bool registerFilter (IdStringPtr name, IFilter::CreateFunction createFunction);
105  bool unregisterFilter (IdStringPtr name, IFilter::CreateFunction createFunction);
106 protected:
107  using FilterMap = std::map<std::string, IFilter::CreateFunction>;
108  FilterMap filters;
109 };
110 
112 namespace Standard {
113 
123  static const IdStringPtr kBoxBlur = "Box Blur";
124 
133  static const IdStringPtr kGrayscale = "Grayscale";
134 
145  static const IdStringPtr kReplaceColor = "Replace Color";
146 
158  static const IdStringPtr kSetColor = "Set Color";
159 
170  static const IdStringPtr kScaleBilinear = "Scale Biliniear";
171 
182  static const IdStringPtr kScaleLinear = "Scale Linear";
183 
185  namespace Property {
186 
187  static const IdStringPtr kInputBitmap = "InputBitmap";
188  static const IdStringPtr kOutputBitmap = "OutputBitmap";
189  static const IdStringPtr kRadius = "Radius";
190  static const IdStringPtr kInputColor = "InputColor";
191  static const IdStringPtr kOutputColor = "OutputColor";
192  static const IdStringPtr kOutputRect = "OutputRect";
193  static const IdStringPtr kIgnoreAlphaColorValue = "IgnoreAlphaColorValue";
194 
195  } // namespace Property
196 
197 } // namespace Standard
198 
199 //----------------------------------------------------------------------------------------------------
202 //----------------------------------------------------------------------------------------------------
203 class FilterBase : public IFilter
204 {
205 protected:
206  FilterBase (UTF8StringPtr description);
207 
208  bool registerProperty (IdStringPtr name, const Property& defaultProperty);
209  CBitmap* getInputBitmap () const;
210 
211  UTF8StringPtr getDescription () const override;
212  bool setProperty (IdStringPtr name, const Property& property) override;
213  bool setProperty (IdStringPtr name, Property&& property) override;
214  const Property& getProperty (IdStringPtr name) const override;
215 
216  uint32_t getNumProperties () const override;
217  IdStringPtr getPropertyName (uint32_t index) const override;
218  Property::Type getPropertyType (uint32_t index) const override;
219  Property::Type getPropertyType (IdStringPtr name) const override;
220 
221 private:
222  using PropertyMap = std::map<std::string, Property>;
223  std::string description;
224  PropertyMap properties;
225 };
226 
227 } // namespace BitmapFilter
228 
229 } // namespace
230 
231 #endif // __cbitmapfilter__
Bitmap Filter Factory.
Definition: cbitmapfilter.h:94
Rect structure.
Definition: crect.h:17
RGBA Color structure.
Definition: ccolor.h:15
Filter Interface.
Definition: cbitmapfilter.h:71
A Base Class for Implementing Bitmap Filters.
Definition: cbitmapfilter.h:203
Filter Property.
Definition: cbitmapfilter.h:21
Encapsulates various platform depended kinds of bitmaps.
Definition: cbitmap.h:21
Definition: customcontrols.cpp:8
Definition: vstguibase.h:247
Definition: vstguibase.h:238
Graphics Transform Matrix.
Definition: cgraphicstransform.h:23
Point structure.
Definition: cpoint.h:17