Gnash  0.8.10
Filters.h
Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012
00003 //   Free Software Foundation, Inc.
00004 // 
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 3 of the License, or
00008 // (at your option) any later version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 
00019 
00020 #ifndef GNASH_FILTERS_H
00021 #define GNASH_FILTERS_H
00022 
00023 #include <boost/cstdint.hpp> 
00024 #include <vector>
00025 
00026 namespace gnash {
00027     class SWFStream;
00028 }
00029 
00030 namespace gnash {
00031 
00032 // The common base class for AS display filters.
00033 class BitmapFilter
00034 {
00035 public:
00036     virtual bool read(SWFStream& /*in*/) {
00037         return true;
00038     }
00039     BitmapFilter() {}
00040     virtual ~BitmapFilter() {}
00041 };
00042 
00043 // A bevel effect filter.
00044 class BevelFilter : public BitmapFilter
00045 {
00046 public:
00047     enum bevel_type
00048     {
00049         OUTER_BEVEL = 1,
00050         INNER_BEVEL = 2,
00051         FULL_BEVEL = 3
00052     };
00053 
00054     // Fill from a SWFStream. See parser/filter_factory.cpp for the implementations.
00055     virtual bool read(SWFStream& in);
00056 
00057     virtual ~BevelFilter() {}
00058 
00059     BevelFilter()
00060         : 
00061         m_distance(0.0f),
00062         m_angle(0.0f),
00063         m_highlightColor(0),
00064         m_highlightAlpha(0),
00065         m_shadowColor(0),
00066         m_shadowAlpha(0),
00067         m_blurX(0.0f),
00068         m_blurY(0.0f),
00069         m_strength(0.0f),
00070         m_quality(0),
00071         m_type(FULL_BEVEL),
00072         m_knockout(false)
00073     {}
00074 
00075     BevelFilter(float distance, float angle, boost::uint32_t hcolor,
00076         boost::uint8_t halpha, boost::uint32_t scolor, boost::uint8_t salpha,
00077         float blurX, float blurY, float strength,
00078         boost::uint8_t quality, bevel_type type, bool knockout) :
00079         m_distance(distance), m_angle(angle), m_highlightColor(hcolor),
00080         m_highlightAlpha(halpha), m_shadowColor(scolor), m_shadowAlpha(salpha),
00081         m_blurX(blurX), m_blurY(blurY), m_strength(strength),
00082         m_quality(quality), m_type(type), m_knockout(knockout)
00083     {}
00084 
00085     float m_distance; // Distance of the filter in pixels.
00086     float m_angle; // Angle of the filter.
00087     boost::uint32_t m_highlightColor; // Color of the highlight.
00088     boost::uint8_t m_highlightAlpha; // Alpha of the highlight.
00089     boost::uint32_t m_shadowColor; // RGB color.
00090     boost::uint8_t m_shadowAlpha; // Alpha strength, as a percentage(?)
00091     float m_blurX; // horizontal blur
00092     float m_blurY; // vertical blur
00093     float m_strength; // How strong is the filter.
00094     boost::uint8_t m_quality; // How many times to apply the filter.
00095     bevel_type m_type; // The type of filter. (Rendered as string in AS)
00096     bool m_knockout; // If true, render only the filter effect.
00097 };
00098 
00099 // A blur effect filter.
00100 class BlurFilter : public BitmapFilter
00101 {
00102 public:
00103     // Fill from a SWFStream. See parser/filter_factory.cpp for the implementations.
00104     virtual bool read(SWFStream& in);
00105 
00106     virtual ~BlurFilter() {}
00107 
00108     BlurFilter() : 
00109         m_blurX(0.0f), m_blurY(0.0f), m_quality(0)
00110     {}
00111 
00112     BlurFilter(float blurX, float blurY, boost::uint8_t quality) :
00113         m_blurX(blurX), m_blurY(blurY), m_quality(quality)
00114     {}
00115 
00116     float m_blurX; // How much horizontal blur.
00117     float m_blurY; // How much vertical blur.
00118     boost::uint8_t m_quality; // How many passes to take.
00119 };
00120 
00121 // A color SWFMatrix effect filter.
00122 class ColorMatrixFilter : public BitmapFilter
00123 {
00124 public:
00125     // Fill from a SWFStream. See parser/filter_factory.cpp for the implementations.
00126     virtual bool read(SWFStream& in);
00127 
00128     virtual ~ColorMatrixFilter() {}
00129 
00130     ColorMatrixFilter() : 
00131         m_matrix()
00132     {}
00133 
00134     ColorMatrixFilter(std::vector<float> a_matrix) :
00135         m_matrix(a_matrix)
00136     {}
00137 
00138 protected:
00139     std::vector<float> m_matrix; // The color SWFMatrix
00140 };
00141 
00142 // A convolution effect filter.
00143 class ConvolutionFilter : public BitmapFilter
00144 {
00145 public:
00146     // Fill from a SWFStream. See parser/filter_factory.cpp for
00147     // the implementations.
00148     virtual bool read(SWFStream& in);
00149 
00150     virtual ~ConvolutionFilter() {}
00151 
00152     ConvolutionFilter()
00153         :
00154         _matrixX(),
00155         _matrixY(),
00156         _matrix(),
00157         _divisor(),
00158         _bias(),
00159         _preserveAlpha(false),
00160         _clamp(false),
00161         _color(),
00162         _alpha()
00163     {}
00164 
00165     ConvolutionFilter(boost::uint8_t matrixX, boost::uint8_t matrixY, 
00166         const std::vector<float>& _matrix, float divisor, float bias,
00167         bool preserveAlpha, bool clamp, boost::uint32_t color,
00168         boost::uint8_t alpha)
00169         :
00170         _matrixX(matrixX),
00171         _matrixY(matrixY),
00172         _matrix(_matrix),
00173         _divisor(divisor),
00174         _bias(bias),
00175         _preserveAlpha(preserveAlpha),
00176         _clamp(clamp),
00177         _color(color),
00178         _alpha(alpha)
00179     {}
00180 
00181 protected:
00182     boost::uint8_t _matrixX; // Number of columns
00183     boost::uint8_t _matrixY; // Number of rows
00184     std::vector<float> _matrix; // The convolution matrix
00185     float _divisor;
00186     float _bias;
00187     bool _preserveAlpha; // If true, don't convolute the alpha channel
00188     bool _clamp; // Whether or not to clamp
00189     boost::uint32_t _color; // For off-image pixels
00190     boost::uint8_t _alpha; // For off-image pixels
00191 };
00192 
00193 // A drop shadow effect filter.
00194 class DropShadowFilter : public BitmapFilter
00195 {
00196 public:
00197     // Fill from a SWFStream. See parser/filter_factory.cpp for the implementations.
00198     virtual bool read(SWFStream& in);
00199 
00200     virtual ~DropShadowFilter() {}
00201 
00202     DropShadowFilter() : 
00203         m_distance(0.0f), m_angle(0.0f), m_color(0), m_alpha(0),
00204         m_blurX(0.0f), m_blurY(0.0f),  m_strength(0.0f), m_quality(0),
00205         m_inner(false), m_knockout(false), m_hideObject(false)
00206     {}
00207 
00208     DropShadowFilter(float distance, float angle, boost::uint32_t color,
00209         boost::uint8_t alpha, float blurX, float blurY, float strength,
00210         boost::uint8_t quality, bool inner, bool knockout, bool hideObject) :
00211         m_distance(distance), m_angle(angle), m_color(color),
00212         m_alpha(alpha), m_blurX(blurX), m_blurY(blurY), m_strength(strength),
00213         m_quality(quality), m_inner(inner), m_knockout(knockout),
00214         m_hideObject(hideObject)
00215     {}
00216 
00217     float m_distance; // Distance of the filter in pixels.
00218     float m_angle; // Angle of the filter.
00219     boost::uint32_t m_color; // RGB color.
00220     boost::uint8_t m_alpha; // Alpha strength, as a percentage(?)
00221     float m_blurX; // horizontal blur
00222     float m_blurY; // vertical blur
00223     float m_strength; // How strong is the filter.
00224     boost::uint8_t m_quality; // How many times to apply the filter.
00225     bool m_inner; // Is this an inner shadow?
00226     bool m_knockout; // If true, render only the filter effect.
00227     bool m_hideObject; // Does this hide the object?
00228 };
00229 
00230 
00231 // A glow effect filter.
00232 class GlowFilter : public BitmapFilter
00233 {
00234 public:
00235     // Fill from a SWFStream. See parser/filter_factory.cpp for the implementations.
00236     virtual bool read(SWFStream& in);
00237 
00238     virtual ~GlowFilter() {}
00239 
00240     GlowFilter() : 
00241         m_color(0), m_alpha(0),
00242         m_blurX(0.0f), m_blurY(0.0f),  m_strength(0.0f), m_quality(0),
00243         m_inner(false), m_knockout(false)
00244     {}
00245 
00246     GlowFilter(boost::uint32_t color,
00247         boost::uint8_t alpha, float blurX, float blurY, float strength,
00248         boost::uint8_t quality, bool inner, bool knockout) :
00249         m_color(color),
00250         m_alpha(alpha), m_blurX(blurX), m_blurY(blurY), m_strength(strength),
00251         m_quality(quality), m_inner(inner), m_knockout(knockout)
00252     {}
00253 
00254     boost::uint32_t m_color; // RGB color.
00255     boost::uint8_t m_alpha; // Alpha strength, as a percentage(?)
00256     float m_blurX; // horizontal blur
00257     float m_blurY; // vertical blur
00258     float m_strength; // How strong is the filter.
00259     boost::uint8_t m_quality; // How many times to apply the filter.
00260     bool m_inner; // Is this an inner shadow?
00261     bool m_knockout; // If true, render only the filter effect.
00262 };
00263 
00264 
00265 // A gradient bevel effect filter.
00266 class GradientBevelFilter : public BitmapFilter
00267 {
00268 public:
00269     enum glow_types
00270     {
00271         INNER_BEVEL = 2,
00272         OUTER_BEVEL = 1,
00273         FULL_BEVEL = 3
00274     };
00275 
00276     // Fill from a SWFStream. See parser/filter_factory.cpp for the implementations.
00277     virtual bool read(SWFStream& in);
00278 
00279     virtual ~GradientBevelFilter() {}
00280 
00281     GradientBevelFilter() : 
00282         m_distance(0.0f), m_angle(0.0f), m_colors(), m_alphas(), m_ratios(),
00283         m_blurX(0.0f), m_blurY(0.0f),  m_strength(0.0f), m_quality(0),
00284         m_type(INNER_BEVEL), m_knockout(false)
00285     {}
00286 
00287     GradientBevelFilter(float distance, float angle,
00288         std::vector<boost::uint32_t> colors,
00289         std::vector<boost::uint8_t> alphas,
00290         std::vector<boost::uint8_t> ratios,
00291         float blurX, float blurY, float strength,
00292         boost::uint8_t quality, glow_types type, bool knockout) :
00293         m_distance(distance), m_angle(angle),
00294         m_colors(colors), m_alphas(alphas), m_ratios(ratios),
00295         m_blurX(blurX), m_blurY(blurY), m_strength(strength),
00296         m_quality(quality), m_type(type), m_knockout(knockout)
00297     {}
00298 
00299     float m_distance; // Distance of the filter in pixels.
00300     float m_angle; // Angle of the filter.
00301     std::vector<boost::uint32_t> m_colors; // Colors of the gradients.
00302     std::vector<boost::uint8_t> m_alphas; // Alphas of the gradients.
00303     std::vector<boost::uint8_t> m_ratios; // Ratios of the gradients.
00304     float m_blurX; // horizontal blur
00305     float m_blurY; // vertical blur
00306     float m_strength; // How strong is the filter.
00307     boost::uint8_t m_quality; // How many times to apply the filter.
00308     glow_types m_type; // What type of effect.
00309     bool m_knockout; // If true, render only the filter effect.
00310 };
00311 
00312 // A gradient glow effect filter.
00313 class GradientGlowFilter : public BitmapFilter
00314 {
00315 public:
00316     enum glow_types
00317     {
00318         INNER_GLOW = 2,
00319         OUTER_GLOW = 1,
00320         FULL_GLOW = 3
00321     };
00322 
00323     // Fill from a SWFStream. See parser/filter_factory.cpp for the implementations.
00324     virtual bool read(SWFStream& in);
00325 
00326     virtual ~GradientGlowFilter() {}
00327 
00328     GradientGlowFilter() : 
00329         m_distance(0.0f), m_angle(0.0f), m_colors(), m_alphas(), m_ratios(),
00330         m_blurX(0.0f), m_blurY(0.0f),  m_strength(0.0f), m_quality(0),
00331         m_type(INNER_GLOW), m_knockout(false)
00332     {}
00333 
00334     GradientGlowFilter(float distance, float angle,
00335         std::vector<boost::uint32_t> colors,
00336         std::vector<boost::uint8_t> alphas,
00337         std::vector<boost::uint8_t> ratios,
00338         float blurX, float blurY, float strength,
00339         boost::uint8_t quality, glow_types type, bool knockout) :
00340         m_distance(distance), m_angle(angle), m_colors(colors), m_alphas(alphas),
00341         m_ratios(ratios), m_blurX(blurX), m_blurY(blurY), m_strength(strength),
00342         m_quality(quality), m_type(type), m_knockout(knockout)
00343     {}
00344 
00345     float m_distance; // Distance of the filter in pixels.
00346     float m_angle; // Angle of the filter.
00347     std::vector<boost::uint32_t> m_colors; // Colors of the gradients.
00348     std::vector<boost::uint8_t> m_alphas; // Alphas of the gradients.
00349     std::vector<boost::uint8_t> m_ratios; // Ratios of the gradients.
00350     float m_blurX; // horizontal blur
00351     float m_blurY; // vertical blur
00352     float m_strength; // How strong is the filter.
00353     boost::uint8_t m_quality; // How many times to apply the filter.
00354     glow_types m_type; // What type of effect.
00355     bool m_knockout; // If true, render only the filter effect.
00356 };
00357 
00358 } // Namespace gnash
00359 
00360 #endif