Author: Carlos Lopez <genet...@gmail.com>
Date:   Tue Jun 19 16:43:32 2012 +0200

Complete definition of CairoSurface.

---

 synfig-core/src/synfig/surface.cpp |   45 ++++++++++++++++++++++++++++++++++++
 synfig-core/src/synfig/surface.h   |   22 +++++++++++++++--
 2 files changed, 64 insertions(+), 3 deletions(-)

diff --git a/synfig-core/src/synfig/surface.cpp 
b/synfig-core/src/synfig/surface.cpp
index 471b85a..193e75f 100644
--- a/synfig-core/src/synfig/surface.cpp
+++ b/synfig-core/src/synfig/surface.cpp
@@ -238,3 +238,48 @@ synfig::Surface::blit_to(alpha_pen& pen, int x, int y, int 
w, int h)
        etl::surface<Color, ColorAccumulator, ColorPrep>::blit_to(pen,x,y,w,h);
 }
 
+void
+synfig::CairoSurface::blit_to(alpha_pen& pen, int x, int y, int w, int h)
+{
+       static const float epsilon(0.00001);
+       const float alpha(pen.get_alpha());
+       if(     pen.get_blend_method()==Color::BLEND_STRAIGHT && 
fabs(alpha-1.0f)<epsilon )
+       {
+               if(x>=get_w() || y>=get_w())
+                       return;
+               
+               //clip source origin
+               if(x<0)
+               {
+                       w+=x;   //decrease
+                       x=0;
+               }
+               
+               if(y<0)
+               {
+                       h+=y;   //decrease
+                       y=0;
+               }
+               
+               //clip width against dest width
+               w = min((long)w,(long)(pen.end_x()-pen.x()));
+               h = min((long)h,(long)(pen.end_y()-pen.y()));
+               
+               //clip width against src width
+               w = min(w,get_w()-x);
+               h = min(h,get_h()-y);
+               
+               if(w<=0 || h<=0)
+                       return;
+               
+               for(int i=0;i<h;i++)
+               {
+                       char* 
src(static_cast<char*>(static_cast<void*>(operator[](y)+x))+i*get_w()*sizeof(Color));
+                       char* 
dest(static_cast<char*>(static_cast<void*>(pen.x()))+i*pen.get_width()*sizeof(Color));
+                       memcpy(dest,src,w*sizeof(Color));
+               }
+               return;
+       }
+       else
+               etl::surface<CairoColor, CairoColor, 
CairoColorPrep>::blit_to(pen,x,y,w,h);
+}
diff --git a/synfig-core/src/synfig/surface.h b/synfig-core/src/synfig/surface.h
index a1da7b0..5528375 100644
--- a/synfig-core/src/synfig/surface.h
+++ b/synfig-core/src/synfig/surface.h
@@ -130,10 +130,26 @@ public:
        class alpha_pen;
        
        CairoSurface() { }
-               
-       void clear();
+       CairoSurface(const size_type::value_type &w, const 
size_type::value_type &h):
+       etl::surface<CairoColor, CairoColor,CairoColorPrep>(w,h) { }
+
+       CairoSurface(const size_type &s):
+       etl::surface<CairoColor, CairoColor, CairoColorPrep>(s) { }
+       
+       template <typename _pen>
+       CairoSurface(const _pen &_begin, const _pen &_end):
+       etl::surface<CairoColor, CairoColor, CairoColorPrep>(_begin,_end) { }
        
-       void set_wh(int w, int h, int pitch=0);
+       template <class _pen> void blit_to(_pen &pen)
+       { return blit_to(pen,0,0, get_w(),get_h()); }
+       
+       template <class _pen> void
+       blit_to(_pen& DEST_PEN, int x, int y, int w, int h)
+       { etl::surface<CairoColor, CairoColor, 
CairoColorPrep>::blit_to(DEST_PEN,x,y,w,h);
+       }
+       // TODO: Define set_wh
+       //void set_wh(int w, int h, int pitch=0);
+       void blit_to(alpha_pen& DEST_PEN, int x, int y, int w, int h);
        
 };     // END of class Surface
 


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Synfig-devl mailing list
Synfig-devl@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/synfig-devl

Reply via email to