Gnash  0.8.11dev
Filters.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012
3 // Free Software Foundation, Inc.
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 
19 
20 #ifndef GNASH_FILTERS_H
21 #define GNASH_FILTERS_H
22 
23 #include <cstdint>
24 #include <vector>
25 #include <utility>
26 
27 namespace gnash {
28  class SWFStream;
29 }
30 
31 namespace gnash {
32 
33 // The common base class for AS display filters.
35 {
36 public:
37  virtual bool read(SWFStream& /*in*/) {
38  return true;
39  }
41  virtual ~BitmapFilter() {}
42 };
43 
44 // A bevel effect filter.
45 class BevelFilter : public BitmapFilter
46 {
47 public:
49  {
50  OUTER_BEVEL = 1,
51  INNER_BEVEL = 2,
52  FULL_BEVEL = 3
53  };
54 
55  // Fill from a SWFStream. See parser/filter_factory.cpp for the implementations.
56  virtual bool read(SWFStream& in);
57 
58  virtual ~BevelFilter() {}
59 
61  :
62  m_distance(0.0f),
63  m_angle(0.0f),
64  m_highlightColor(0),
65  m_highlightAlpha(0),
66  m_shadowColor(0),
67  m_shadowAlpha(0),
68  m_blurX(0.0f),
69  m_blurY(0.0f),
70  m_strength(0.0f),
71  m_quality(0),
72  m_type(FULL_BEVEL),
73  m_knockout(false)
74  {}
75 
76  BevelFilter(float distance, float angle, std::uint32_t hcolor,
77  std::uint8_t halpha, std::uint32_t scolor, std::uint8_t salpha,
78  float blurX, float blurY, float strength,
79  std::uint8_t quality, bevel_type type, bool knockout) :
80  m_distance(distance), m_angle(angle), m_highlightColor(hcolor),
81  m_highlightAlpha(halpha), m_shadowColor(scolor), m_shadowAlpha(salpha),
82  m_blurX(blurX), m_blurY(blurY), m_strength(strength),
83  m_quality(quality), m_type(type), m_knockout(knockout)
84  {}
85 
86  float m_distance; // Distance of the filter in pixels.
87  float m_angle; // Angle of the filter.
88  std::uint32_t m_highlightColor; // Color of the highlight.
89  std::uint8_t m_highlightAlpha; // Alpha of the highlight.
90  std::uint32_t m_shadowColor; // RGB color.
91  std::uint8_t m_shadowAlpha; // Alpha strength, as a percentage(?)
92  float m_blurX; // horizontal blur
93  float m_blurY; // vertical blur
94  float m_strength; // How strong is the filter.
95  std::uint8_t m_quality; // How many times to apply the filter.
96  bevel_type m_type; // The type of filter. (Rendered as string in AS)
97  bool m_knockout; // If true, render only the filter effect.
98 };
99 
100 // A blur effect filter.
101 class BlurFilter : public BitmapFilter
102 {
103 public:
104  // Fill from a SWFStream. See parser/filter_factory.cpp for the implementations.
105  virtual bool read(SWFStream& in);
106 
107  virtual ~BlurFilter() {}
108 
110  m_blurX(0.0f), m_blurY(0.0f), m_quality(0)
111  {}
112 
113  BlurFilter(float blurX, float blurY, std::uint8_t quality) :
114  m_blurX(blurX), m_blurY(blurY), m_quality(quality)
115  {}
116 
117  float m_blurX; // How much horizontal blur.
118  float m_blurY; // How much vertical blur.
119  std::uint8_t m_quality; // How many passes to take.
120 };
121 
122 // A color SWFMatrix effect filter.
124 {
125 public:
126  // Fill from a SWFStream. See parser/filter_factory.cpp for the implementations.
127  virtual bool read(SWFStream& in);
128 
129  virtual ~ColorMatrixFilter() {}
130 
132  m_matrix()
133  {}
134 
135  ColorMatrixFilter(std::vector<float> a_matrix) :
136  m_matrix(std::move(a_matrix))
137  {}
138 
139 protected:
140  std::vector<float> m_matrix; // The color SWFMatrix
141 };
142 
143 // A convolution effect filter.
145 {
146 public:
147  // Fill from a SWFStream. See parser/filter_factory.cpp for
148  // the implementations.
149  virtual bool read(SWFStream& in);
150 
151  virtual ~ConvolutionFilter() {}
152 
154  :
155  _matrixX(),
156  _matrixY(),
157  _matrix(),
158  _divisor(),
159  _bias(),
160  _preserveAlpha(false),
161  _clamp(false),
162  _color(),
163  _alpha()
164  {}
165 
166  ConvolutionFilter(std::uint8_t matrixX, std::uint8_t matrixY,
167  std::vector<float> _matrix, float divisor, float bias,
168  bool preserveAlpha, bool clamp, std::uint32_t color,
169  std::uint8_t alpha)
170  :
171  _matrixX(matrixX),
172  _matrixY(matrixY),
173  _matrix(std::move(_matrix)),
174  _divisor(divisor),
175  _bias(bias),
176  _preserveAlpha(preserveAlpha),
177  _clamp(clamp),
178  _color(color),
179  _alpha(alpha)
180  {}
181 
182 protected:
183  std::uint8_t _matrixX; // Number of columns
184  std::uint8_t _matrixY; // Number of rows
185  std::vector<float> _matrix; // The convolution matrix
186  float _divisor;
187  float _bias;
188  bool _preserveAlpha; // If true, don't convolute the alpha channel
189  bool _clamp; // Whether or not to clamp
190  std::uint32_t _color; // For off-image pixels
191  std::uint8_t _alpha; // For off-image pixels
192 };
193 
194 // A drop shadow effect filter.
196 {
197 public:
198  // Fill from a SWFStream. See parser/filter_factory.cpp for the implementations.
199  virtual bool read(SWFStream& in);
200 
201  virtual ~DropShadowFilter() {}
202 
204  m_distance(0.0f), m_angle(0.0f), m_color(0), m_alpha(0),
205  m_blurX(0.0f), m_blurY(0.0f), m_strength(0.0f), m_quality(0),
206  m_inner(false), m_knockout(false), m_hideObject(false)
207  {}
208 
209  DropShadowFilter(float distance, float angle, std::uint32_t color,
210  std::uint8_t alpha, float blurX, float blurY, float strength,
211  std::uint8_t quality, bool inner, bool knockout, bool hideObject) :
212  m_distance(distance), m_angle(angle), m_color(color),
213  m_alpha(alpha), m_blurX(blurX), m_blurY(blurY), m_strength(strength),
214  m_quality(quality), m_inner(inner), m_knockout(knockout),
215  m_hideObject(hideObject)
216  {}
217 
218  float m_distance; // Distance of the filter in pixels.
219  float m_angle; // Angle of the filter.
220  std::uint32_t m_color; // RGB color.
221  std::uint8_t m_alpha; // Alpha strength, as a percentage(?)
222  float m_blurX; // horizontal blur
223  float m_blurY; // vertical blur
224  float m_strength; // How strong is the filter.
225  std::uint8_t m_quality; // How many times to apply the filter.
226  bool m_inner; // Is this an inner shadow?
227  bool m_knockout; // If true, render only the filter effect.
228  bool m_hideObject; // Does this hide the object?
229 };
230 
231 
232 // A glow effect filter.
233 class GlowFilter : public BitmapFilter
234 {
235 public:
236  // Fill from a SWFStream. See parser/filter_factory.cpp for the implementations.
237  virtual bool read(SWFStream& in);
238 
239  virtual ~GlowFilter() {}
240 
242  m_color(0), m_alpha(0),
243  m_blurX(0.0f), m_blurY(0.0f), m_strength(0.0f), m_quality(0),
244  m_inner(false), m_knockout(false)
245  {}
246 
247  GlowFilter(std::uint32_t color,
248  std::uint8_t alpha, float blurX, float blurY, float strength,
249  std::uint8_t quality, bool inner, bool knockout) :
250  m_color(color),
251  m_alpha(alpha), m_blurX(blurX), m_blurY(blurY), m_strength(strength),
252  m_quality(quality), m_inner(inner), m_knockout(knockout)
253  {}
254 
255  std::uint32_t m_color; // RGB color.
256  std::uint8_t m_alpha; // Alpha strength, as a percentage(?)
257  float m_blurX; // horizontal blur
258  float m_blurY; // vertical blur
259  float m_strength; // How strong is the filter.
260  std::uint8_t m_quality; // How many times to apply the filter.
261  bool m_inner; // Is this an inner shadow?
262  bool m_knockout; // If true, render only the filter effect.
263 };
264 
265 
266 // A gradient bevel effect filter.
268 {
269 public:
271  {
272  INNER_BEVEL = 2,
273  OUTER_BEVEL = 1,
274  FULL_BEVEL = 3
275  };
276 
277  // Fill from a SWFStream. See parser/filter_factory.cpp for the implementations.
278  virtual bool read(SWFStream& in);
279 
280  virtual ~GradientBevelFilter() {}
281 
283  m_distance(0.0f), m_angle(0.0f), m_colors(), m_alphas(), m_ratios(),
284  m_blurX(0.0f), m_blurY(0.0f), m_strength(0.0f), m_quality(0),
285  m_type(INNER_BEVEL), m_knockout(false)
286  {}
287 
288  GradientBevelFilter(float distance, float angle,
289  std::vector<std::uint32_t> colors,
290  std::vector<std::uint8_t> alphas,
291  std::vector<std::uint8_t> ratios,
292  float blurX, float blurY, float strength,
293  std::uint8_t quality, glow_types type, bool knockout) :
294  m_distance(distance), m_angle(angle),
295  m_colors(std::move(colors)), m_alphas(std::move(alphas)), m_ratios(std::move(ratios)),
296  m_blurX(blurX), m_blurY(blurY), m_strength(strength),
297  m_quality(quality), m_type(type), m_knockout(knockout)
298  {}
299 
300  float m_distance; // Distance of the filter in pixels.
301  float m_angle; // Angle of the filter.
302  std::vector<std::uint32_t> m_colors; // Colors of the gradients.
303  std::vector<std::uint8_t> m_alphas; // Alphas of the gradients.
304  std::vector<std::uint8_t> m_ratios; // Ratios of the gradients.
305  float m_blurX; // horizontal blur
306  float m_blurY; // vertical blur
307  float m_strength; // How strong is the filter.
308  std::uint8_t m_quality; // How many times to apply the filter.
309  glow_types m_type; // What type of effect.
310  bool m_knockout; // If true, render only the filter effect.
311 };
312 
313 // A gradient glow effect filter.
315 {
316 public:
318  {
319  INNER_GLOW = 2,
320  OUTER_GLOW = 1,
321  FULL_GLOW = 3
322  };
323 
324  // Fill from a SWFStream. See parser/filter_factory.cpp for the implementations.
325  virtual bool read(SWFStream& in);
326 
327  virtual ~GradientGlowFilter() {}
328 
330  m_distance(0.0f), m_angle(0.0f), m_colors(), m_alphas(), m_ratios(),
331  m_blurX(0.0f), m_blurY(0.0f), m_strength(0.0f), m_quality(0),
332  m_type(INNER_GLOW), m_knockout(false)
333  {}
334 
335  GradientGlowFilter(float distance, float angle,
336  std::vector<std::uint32_t> colors,
337  std::vector<std::uint8_t> alphas,
338  std::vector<std::uint8_t> ratios,
339  float blurX, float blurY, float strength,
340  std::uint8_t quality, glow_types type, bool knockout) :
341  m_distance(distance), m_angle(angle), m_colors(std::move(colors)), m_alphas(std::move(alphas)),
342  m_ratios(std::move(ratios)), m_blurX(blurX), m_blurY(blurY), m_strength(strength),
343  m_quality(quality), m_type(type), m_knockout(knockout)
344  {}
345 
346  float m_distance; // Distance of the filter in pixels.
347  float m_angle; // Angle of the filter.
348  std::vector<std::uint32_t> m_colors; // Colors of the gradients.
349  std::vector<std::uint8_t> m_alphas; // Alphas of the gradients.
350  std::vector<std::uint8_t> m_ratios; // Ratios of the gradients.
351  float m_blurX; // horizontal blur
352  float m_blurY; // vertical blur
353  float m_strength; // How strong is the filter.
354  std::uint8_t m_quality; // How many times to apply the filter.
355  glow_types m_type; // What type of effect.
356  bool m_knockout; // If true, render only the filter effect.
357 };
358 
359 } // Namespace gnash
360 
361 #endif
std::uint32_t m_highlightColor
Definition: Filters.h:88
float m_angle
Definition: Filters.h:219
std::vector< float > m_matrix
Definition: Filters.h:140
float m_blurX
Definition: Filters.h:117
std::uint8_t m_quality
Definition: Filters.h:354
std::vector< std::uint8_t > m_alphas
Definition: Filters.h:349
std::vector< std::uint32_t > m_colors
Definition: Filters.h:348
std::uint8_t m_highlightAlpha
Definition: Filters.h:89
std::uint32_t _color
Definition: Filters.h:190
float m_distance
Definition: Filters.h:86
std::uint8_t m_quality
Definition: Filters.h:308
float m_blurY
Definition: Filters.h:258
ColorMatrixFilter()
Definition: Filters.h:131
GradientBevelFilter()
Definition: Filters.h:282
float m_angle
Definition: Filters.h:87
virtual ~GradientGlowFilter()
Definition: Filters.h:327
GlowFilter()
Definition: Filters.h:241
BevelFilter()
Definition: Filters.h:60
float m_blurY
Definition: Filters.h:352
std::uint8_t m_shadowAlpha
Definition: Filters.h:91
virtual ~ColorMatrixFilter()
Definition: Filters.h:129
std::vector< std::uint8_t > m_ratios
Definition: Filters.h:304
std::uint8_t m_quality
Definition: Filters.h:95
bool m_knockout
Definition: Filters.h:310
Definition: Filters.h:101
GlowFilter(std::uint32_t color, std::uint8_t alpha, float blurX, float blurY, float strength, std::uint8_t quality, bool inner, bool knockout)
Definition: Filters.h:247
std::uint8_t m_alpha
Definition: Filters.h:221
std::uint8_t m_quality
Definition: Filters.h:260
std::vector< std::uint8_t > m_ratios
Definition: Filters.h:350
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
float m_strength
Definition: Filters.h:353
std::vector< std::uint32_t > m_colors
Definition: Filters.h:302
float m_angle
Definition: Filters.h:347
float m_distance
Definition: Filters.h:346
ConvolutionFilter(std::uint8_t matrixX, std::uint8_t matrixY, std::vector< float > _matrix, float divisor, float bias, bool preserveAlpha, bool clamp, std::uint32_t color, std::uint8_t alpha)
Definition: Filters.h:166
virtual ~BevelFilter()
Definition: Filters.h:58
BitmapFilter()
Definition: Filters.h:40
type
Definition: GnashKey.h:329
virtual ~DropShadowFilter()
Definition: Filters.h:201
ColorMatrixFilter(std::vector< float > a_matrix)
Definition: Filters.h:135
bool m_hideObject
Definition: Filters.h:228
std::uint8_t m_alpha
Definition: Filters.h:256
Definition: GnashKey.h:152
bevel_type m_type
Definition: Filters.h:96
std::uint32_t m_color
Definition: Filters.h:220
bool _clamp
Definition: Filters.h:189
virtual ~GradientBevelFilter()
Definition: Filters.h:280
Definition: Filters.h:34
Definition: Filters.h:144
const VGfloat color[4]
Definition: testr_gtk.cpp:82
float m_blurX
Definition: Filters.h:305
virtual bool read(SWFStream &)
Definition: Filters.h:37
Definition: Filters.h:123
Definition: Filters.h:233
bevel_type
Definition: Filters.h:48
float m_strength
Definition: Filters.h:307
float m_blurX
Definition: Filters.h:222
float m_blurX
Definition: Filters.h:257
float _divisor
Definition: Filters.h:186
glow_types m_type
Definition: Filters.h:309
std::vector< float > _matrix
Definition: Filters.h:185
Definition: Filters.h:45
GradientGlowFilter(float distance, float angle, std::vector< std::uint32_t > colors, std::vector< std::uint8_t > alphas, std::vector< std::uint8_t > ratios, float blurX, float blurY, float strength, std::uint8_t quality, glow_types type, bool knockout)
Definition: Filters.h:335
virtual ~BlurFilter()
Definition: Filters.h:107
BevelFilter(float distance, float angle, std::uint32_t hcolor, std::uint8_t halpha, std::uint32_t scolor, std::uint8_t salpha, float blurX, float blurY, float strength, std::uint8_t quality, bevel_type type, bool knockout)
Definition: Filters.h:76
bool m_knockout
Definition: Filters.h:262
virtual ~ConvolutionFilter()
Definition: Filters.h:151
Definition: Filters.h:267
bool m_inner
Definition: Filters.h:261
float _bias
Definition: Filters.h:187
std::uint8_t m_quality
Definition: Filters.h:225
Definition: Filters.h:314
std::uint32_t m_shadowColor
Definition: Filters.h:90
float m_blurY
Definition: Filters.h:118
bool _preserveAlpha
Definition: Filters.h:188
glow_types m_type
Definition: Filters.h:355
bool m_knockout
Definition: Filters.h:356
float m_strength
Definition: Filters.h:259
T clamp(T i, T min, T max)
Definition: GnashNumeric.h:77
BlurFilter()
Definition: Filters.h:109
DropShadowFilter()
Definition: Filters.h:203
bool m_inner
Definition: Filters.h:226
float m_blurY
Definition: Filters.h:306
bool m_knockout
Definition: Filters.h:97
float m_strength
Definition: Filters.h:94
bool m_knockout
Definition: Filters.h:227
glow_types
Definition: Filters.h:317
float m_distance
Definition: Filters.h:300
virtual ~BitmapFilter()
Definition: Filters.h:41
float m_blurX
Definition: Filters.h:351
std::uint8_t _alpha
Definition: Filters.h:191
GradientGlowFilter()
Definition: Filters.h:329
float m_angle
Definition: Filters.h:301
ConvolutionFilter()
Definition: Filters.h:153
std::uint8_t _matrixY
Definition: Filters.h:184
std::uint8_t _matrixX
Definition: Filters.h:183
std::uint32_t m_color
Definition: Filters.h:255
float m_blurX
Definition: Filters.h:92
DropShadowFilter(float distance, float angle, std::uint32_t color, std::uint8_t alpha, float blurX, float blurY, float strength, std::uint8_t quality, bool inner, bool knockout, bool hideObject)
Definition: Filters.h:209
float m_blurY
Definition: Filters.h:93
float m_blurY
Definition: Filters.h:223
float m_distance
Definition: Filters.h:218
float m_strength
Definition: Filters.h:224
Definition: Filters.h:195
std::uint8_t m_quality
Definition: Filters.h:119
BlurFilter(float blurX, float blurY, std::uint8_t quality)
Definition: Filters.h:113
virtual ~GlowFilter()
Definition: Filters.h:239
glow_types
Definition: Filters.h:270
SWF stream wrapper class.
Definition: SWFStream.h:58
GradientBevelFilter(float distance, float angle, std::vector< std::uint32_t > colors, std::vector< std::uint8_t > alphas, std::vector< std::uint8_t > ratios, float blurX, float blurY, float strength, std::uint8_t quality, glow_types type, bool knockout)
Definition: Filters.h:288
std::vector< std::uint8_t > m_alphas
Definition: Filters.h:303