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