Author: Carlos Lopez <genet...@gmail.com>
Date:   Wed Feb 27 18:32:27 2013 +0100

New target2cairo_image class to render to render to image buffer (ARGB32)

---

 synfig-core/src/synfig/surface.cpp |   50 ++++++++++++++++++++++++++++++++++++
 synfig-core/src/synfig/surface.h   |    2 +
 2 files changed, 52 insertions(+), 0 deletions(-)

diff --git a/synfig-core/src/synfig/surface.cpp 
b/synfig-core/src/synfig/surface.cpp
index b24fc96..9d1ff92 100644
--- a/synfig-core/src/synfig/surface.cpp
+++ b/synfig-core/src/synfig/surface.cpp
@@ -50,7 +50,49 @@ using namespace etl;
 /* === M A C R O S ========================================================= */
 
 /* === G L O B A L S ======================================================= */
+class target2cairo_image: public synfig::Target_Cairo
+{
+public:
+       cairo_surface_t** image;
+       target2cairo_image(cairo_surface_t ** s);
+       virtual ~target2cairo_image();
+       virtual bool set_rend_desc(synfig::RendDesc *newdesc);
+       virtual bool obtain_surface(cairo_surface_t*& s);
+};
+
+target2cairo_image::target2cairo_image(cairo_surface_t ** s):image(s)
+{
+}
+
+target2cairo_image::~target2cairo_image()
+{
+}
+
+bool
+target2cairo_image::set_rend_desc(synfig::RendDesc *newdesc)
+{
+       assert(newdesc);
+       desc=*newdesc;
+       return synfig::Target_Cairo::set_rend_desc(newdesc);
+}
+
+bool
+target2cairo_image::obtain_surface(cairo_surface_t*& s)
+{
+       int sw=cairo_image_surface_get_width(*image);
+       int sh=cairo_image_surface_get_height(*image);
+       int w=desc.get_w(), h=desc.get_h();
+       
+       if(sw!=w || sh!=w)
+       {
+               cairo_surface_destroy(*image);
+               *image = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h);
+       }
+       s=cairo_surface_reference(*image);
+       return true;
+}
 
+////
 class target2surface : public synfig::Target_Scanline
 {
 public:
@@ -126,6 +168,14 @@ synfig::surface_target(Surface *surface)
        return Target_Scanline::Handle(new target2surface(surface));
 }
 
+
+Target_Cairo::Handle
+synfig::cairo_image_target(cairo_surface_t **surface)
+{
+       return Target_Cairo::Handle(new target2cairo_image(surface));
+}
+
+
 void
 synfig::Surface::clear()
 {
diff --git a/synfig-core/src/synfig/surface.h b/synfig-core/src/synfig/surface.h
index 70b38a0..66800f0 100644
--- a/synfig-core/src/synfig/surface.h
+++ b/synfig-core/src/synfig/surface.h
@@ -266,6 +266,8 @@ public:
 
 //! Creates a target that will render to \a surface
 etl::handle<Target_Scanline> surface_target(Surface *surface);
+//!Creates a target that will render to a cairo_surface_t image surface
+etl::handle<Target_Cairo> cairo_image_target(cairo_surface_t** surface);
 
 }; // END of namespace synfig
 


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
Synfig-devl mailing list
Synfig-devl@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/synfig-devl

Reply via email to