surface.h

Go to the documentation of this file.
00001 /* === S Y N F I G ========================================================= */
00021 /* ========================================================================= */
00022 
00023 /* === S T A R T =========================================================== */
00024 
00025 #ifndef __SYNFIG_SURFACE_H
00026 #define __SYNFIG_SURFACE_H
00027 
00028 /* === H E A D E R S ======================================================= */
00029 
00030 #include "color.h"
00031 #include "renddesc.h"
00032 #include <ETL/pen>
00033 #include <ETL/surface>
00034 #include <ETL/handle>
00035 
00036 /* === M A C R O S ========================================================= */
00037 
00038 /* === T Y P E D E F S ===================================================== */
00039 
00040 /* === C L A S S E S & S T R U C T S ======================================= */
00041 
00042 namespace synfig {
00043 
00044 class Target;
00045 class Target_Scanline;
00046 
00047 class ColorPrep
00048 {
00049 public:
00050     ColorAccumulator cook(Color x)const
00051     {
00052         x.set_r(x.get_r()*x.get_a());
00053         x.set_g(x.get_g()*x.get_a());
00054         x.set_b(x.get_b()*x.get_a());
00055         return x;
00056     }
00057     Color uncook(ColorAccumulator x)const
00058     {
00059         if(!x.get_a())
00060             return Color::alpha();
00061         
00062         const float a(1.0f/x.get_a());
00063         
00064         x.set_r(x.get_r()*a);
00065         x.set_g(x.get_g()*a);
00066         x.set_b(x.get_b()*a);
00067         return x;
00068     }
00069 };
00070 
00075 class Surface : public etl::surface<Color, ColorAccumulator, ColorPrep>
00076 {
00077 public:
00078     typedef Color value_type;
00079     class alpha_pen;
00080 
00081     Surface() { }
00082 
00083     Surface(const size_type::value_type &w, const size_type::value_type &h):
00084         etl::surface<Color, ColorAccumulator,ColorPrep>(w,h) { }
00085 
00086     Surface(const size_type &s):
00087         etl::surface<Color, ColorAccumulator,ColorPrep>(s) { }
00088 
00089     template <typename _pen>
00090     Surface(const _pen &_begin, const _pen &_end):
00091         etl::surface<Color, ColorAccumulator,ColorPrep>(_begin,_end) { }
00092 
00093     template <class _pen> void blit_to(_pen &pen)
00094     { return blit_to(pen,0,0, get_w(),get_h()); }
00095 
00096     template <class _pen> void
00097     blit_to(_pen& DEST_PEN, int x, int y, int w, int h)
00098     {
00099         etl::surface<Color, ColorAccumulator, ColorPrep>::blit_to(DEST_PEN,x,y,w,h);
00100     }
00101 
00102     void clear();
00103 
00104     void blit_to(alpha_pen& DEST_PEN, int x, int y, int w, int h);
00105 };  // END of class Surface
00106 
00107 #ifndef DOXYGEN_SKIP
00108 
00110 struct _BlendFunc
00111 {
00112     Color::BlendMethod blend_method;
00113 
00114     _BlendFunc(Color::BlendMethod b= Color::BLEND_COMPOSITE):blend_method(b) { }
00115 
00116     Color operator()(const Color &a,const Color &b,const Color::value_type &t)const
00117     {
00118         return Color::blend(b,a,t,blend_method);
00119     }
00120 };  // END of class _BlendFunc
00121 
00122 #endif
00123 
00133 class Surface::alpha_pen : public etl::alpha_pen< etl::generic_pen<Color, ColorAccumulator>, Color::value_type, _BlendFunc >
00134 {
00135 public:
00136     alpha_pen() { }
00137     alpha_pen(const etl::alpha_pen< etl::generic_pen<Color, ColorAccumulator>, Color::value_type, _BlendFunc > &x):
00138         etl::alpha_pen< etl::generic_pen<Color, ColorAccumulator>, Color::value_type, _BlendFunc >(x)
00139     { }
00140     
00141     alpha_pen(const etl::generic_pen<Color, ColorAccumulator>& pen, const Color::value_type &a = 1, const _BlendFunc &func = _BlendFunc()):
00142         etl::alpha_pen< etl::generic_pen<Color, ColorAccumulator>, Color::value_type, _BlendFunc >(pen,a,func)
00143     { }
00144 
00146     void set_blend_method(Color::BlendMethod method) { affine_func_.blend_method=method; }
00147 
00149     Color::BlendMethod get_blend_method()const { return affine_func_.blend_method; }
00150 };  // END of class Surface::alpha_pen
00151 
00153 etl::handle<Target_Scanline> surface_target(Surface *surface);
00154 
00155 }; // END of namespace synfig
00156 
00157 /* === E N D =============================================================== */
00158 
00159 #endif

Generated on Fri Jun 23 15:20:50 2006 for synfig by  doxygen 1.4.6