Author: Nikita Kitaev <nikita...@gmail.com>
Date:   Sun Jul  1 18:19:30 2012 -0700

Working Cairo PNG target

---

 synfig-core/src/modules/mod_png/Makefile.am        |    2 +
 synfig-core/src/modules/mod_png/main.cpp           |    2 +
 synfig-core/src/modules/mod_png/trgt_cairo_png.cpp |  125 ++++++++++++++++++++
 synfig-core/src/modules/mod_png/trgt_cairo_png.h   |   69 +++++++++++
 synfig-core/src/synfig/target_cairo.h              |    2 +-
 5 files changed, 199 insertions(+), 1 deletions(-)

diff --git a/synfig-core/src/modules/mod_png/Makefile.am 
b/synfig-core/src/modules/mod_png/Makefile.am
index d36942d..d8c9428 100644
--- a/synfig-core/src/modules/mod_png/Makefile.am
+++ b/synfig-core/src/modules/mod_png/Makefile.am
@@ -18,6 +18,8 @@ libmod_png_la_SOURCES = \
        main.cpp \
        trgt_png.cpp \
        trgt_png.h \
+       trgt_cairo_png.cpp \
+       trgt_cairo_png.h \
        mptr_png.cpp \
        mptr_png.h
 
diff --git a/synfig-core/src/modules/mod_png/main.cpp 
b/synfig-core/src/modules/mod_png/main.cpp
index 9774d9e..8030561 100644
--- a/synfig-core/src/modules/mod_png/main.cpp
+++ b/synfig-core/src/modules/mod_png/main.cpp
@@ -36,6 +36,7 @@
 #include "png.h"
 #include <synfig/module.h>
 #include "trgt_png.h"
+#include "trgt_cairo_png.h"
 #include "mptr_png.h"
 #endif
 
@@ -51,6 +52,7 @@ MODULE_DESC_END
 
 MODULE_INVENTORY_BEGIN(mod_png)
        BEGIN_TARGETS
+               TARGET(cairo_png_trgt)
                TARGET(png_trgt)
        END_TARGETS
        BEGIN_IMPORTERS
diff --git a/synfig-core/src/modules/mod_png/trgt_cairo_png.cpp 
b/synfig-core/src/modules/mod_png/trgt_cairo_png.cpp
new file mode 100644
index 0000000..bca24ff
--- /dev/null
+++ b/synfig-core/src/modules/mod_png/trgt_cairo_png.cpp
@@ -0,0 +1,125 @@
+/* === S Y N F I G ========================================================= */
+/*!    \file trgt_png.cpp
+**     \brief png_trgt Target Module
+**
+**     $Id$
+**
+**     \legal
+**     Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
+**     Copyright (c) 2007 Chris Moore
+**
+**     This package is free software; you can redistribute it and/or
+**     modify it under the terms of the GNU General Public License as
+**     published by the Free Software Foundation; either version 2 of
+**     the License, or (at your option) any later version.
+**
+**     This package is distributed in the hope that it will be useful,
+**     but WITHOUT ANY WARRANTY; without even the implied warranty of
+**     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+**     General Public License for more details.
+**     \endlegal
+**
+** === N O T E S ===========================================================
+**
+** ========================================================================= */
+
+/* === H E A D E R S ======================================================= */
+
+#ifdef USING_PCH
+#      include "pch.h"
+#else
+#ifdef HAVE_CONFIG_H
+#      include <config.h>
+#endif
+
+#include "trgt_cairo_png.h"
+#include <ETL/stringf>
+#include <cstdio>
+#include <algorithm>
+#include <functional>
+#include <ETL/misc>
+
+#endif
+
+/* === M A C R O S ========================================================= */
+
+using namespace synfig;
+using namespace std;
+using namespace etl;
+
+/* === G L O B A L S ======================================================= */
+
+SYNFIG_TARGET_INIT(cairo_png_trgt);
+SYNFIG_TARGET_SET_NAME(cairo_png_trgt,"cairo_png");
+SYNFIG_TARGET_SET_EXT(cairo_png_trgt,"png");
+SYNFIG_TARGET_SET_VERSION(cairo_png_trgt,"0.1");
+SYNFIG_TARGET_SET_CVS_ID(cairo_png_trgt,"$Id$");
+
+/* === M E T H O D S ======================================================= */
+
+//Target *cairo_png_trgt::New(const char *filename){   return new 
cairo_png_trgt(filename);}
+
+cairo_png_trgt::cairo_png_trgt(const char *Filename,
+                                  const synfig::TargetParam&  params )
+{
+       base_filename=Filename;
+       filename=Filename;
+       sequence_separator=params.sequence_separator;
+}
+
+cairo_png_trgt::~cairo_png_trgt()
+{
+}
+
+bool
+cairo_png_trgt::set_rend_desc(RendDesc *given_desc)
+{
+       //given_desc->set_pixel_format(PixelFormat((int)PF_RGB|(int)PF_A));
+       desc=*given_desc;
+       imagecount=desc.get_frame_start();
+       if(desc.get_frame_end()-desc.get_frame_start()>0)
+               multi_image=true;
+       else
+               multi_image=false;
+       return true;
+}
+
+bool
+cairo_png_trgt::obtain_surface(cairo_surface_t *&surface)
+{
+       if(filename=="-")
+       {
+               synfig::error("Cairo PNG surface does not support writing to 
stdout");
+       }
+       else if(multi_image)
+       {
+               filename = (filename_sans_extension(base_filename) +
+                                                  sequence_separator +
+                                                  
etl::strprintf("%04d",imagecount) +
+                                                  
filename_extension(base_filename));
+       }
+       else
+       {
+               filename = base_filename;
+       }
+
+       int w=desc.get_w(), h=desc.get_h();
+       surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h);
+       return true;
+}
+
+bool
+cairo_png_trgt::put_surface(cairo_surface_t *surface, synfig::ProgressCallback 
*cb)
+{
+       if(cairo_surface_status(surface))
+       {
+               if(cb) cb->error(_("Cairo Surface bad status"));
+               return false;
+       }
+       cairo_status_t status = cairo_surface_write_to_png(surface, 
filename.c_str());
+       synfig::info(cairo_status_to_string(status));
+       imagecount++;
+
+       cairo_surface_destroy(surface);
+       return true;
+}
diff --git a/synfig-core/src/modules/mod_png/trgt_cairo_png.h 
b/synfig-core/src/modules/mod_png/trgt_cairo_png.h
new file mode 100644
index 0000000..c0648c0
--- /dev/null
+++ b/synfig-core/src/modules/mod_png/trgt_cairo_png.h
@@ -0,0 +1,69 @@
+/* === S Y N F I G ========================================================= */
+/*!    \file trgt_cairo_png.h
+**     \brief Template Header
+**
+**     $Id$
+**
+**     \legal
+**     Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
+**
+**     This package is free software; you can redistribute it and/or
+**     modify it under the terms of the GNU General Public License as
+**     published by the Free Software Foundation; either version 2 of
+**     the License, or (at your option) any later version.
+**
+**     This package is distributed in the hope that it will be useful,
+**     but WITHOUT ANY WARRANTY; without even the implied warranty of
+**     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+**     General Public License for more details.
+**     \endlegal
+**
+** === N O T E S ===========================================================
+**
+** ========================================================================= */
+
+/* === S T A R T =========================================================== */
+
+#ifndef __SYNFIG_TRGT_CAIRO_PNG_H
+#define __SYNFIG_TRGT_CAIRO_PNG_H
+
+/* === H E A D E R S ======================================================= */
+
+#include <synfig/target_cairo.h>
+#include <synfig/surface.h>
+#include <synfig/string.h>
+#include <synfig/targetparam.h>
+#include <cairo.h>
+#include <cstdio>
+
+/* === M A C R O S ========================================================= */
+
+/* === T Y P E D E F S ===================================================== */
+
+/* === C L A S S E S & S T R U C T S ======================================= */
+
+class cairo_png_trgt : public synfig::Target_Cairo
+{
+       SYNFIG_TARGET_MODULE_EXT
+private:
+       int w,h;
+
+       bool multi_image;
+       int imagecount;
+       synfig::String filename;
+       synfig::String base_filename;
+
+       synfig::String sequence_separator;
+public:
+       cairo_png_trgt(const char *filename, const synfig::TargetParam& /* 
params */);
+       virtual ~cairo_png_trgt();
+
+       virtual bool set_rend_desc(synfig::RendDesc *desc);
+
+       virtual bool obtain_surface(cairo_surface_t *&surface);
+       virtual bool put_surface(cairo_surface_t *surface, 
synfig::ProgressCallback *cb=NULL);
+};
+
+/* === E N D =============================================================== */
+
+#endif
diff --git a/synfig-core/src/synfig/target_cairo.h 
b/synfig-core/src/synfig/target_cairo.h
index 1d03518..3cb6996 100644
--- a/synfig-core/src/synfig/target_cairo.h
+++ b/synfig-core/src/synfig/target_cairo.h
@@ -64,7 +64,7 @@ public:
        //! Obtain a surface pointer based on the render method
        //! this function has to be overrrided by the derived targets 
        //! to create the proper Cairo backend surface for each target type.
-       virtual bool obtain_surface(cairo_surface_t*)=0; 
+       virtual bool obtain_surface(cairo_surface_t*&)=0; 
        
        //! Returns the number of peniding frames to render. If it is zero it
        //! stops rendering frames.


------------------------------------------------------------------------------
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