Author: Nikita Kitaev <[email protected]>
Date: Sun Jul 1 18:19:30 2012 -0700
Cairo PNG target
Only renders transparency because Context::accelerated_render(CairoSurface, ...)
is not implemented
---
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 | 129 ++++++++++++++++++++
synfig-core/src/modules/mod_png/trgt_cairo_png.h | 72 +++++++++++
synfig-core/src/synfig/surface.h | 2 +-
synfig-core/src/synfig/target_cairo.cpp | 2 +
6 files changed, 208 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 25ffa4d..eef9a6b 100644
--- a/synfig-core/src/modules/mod_png/main.cpp
+++ b/synfig-core/src/modules/mod_png/main.cpp
@@ -35,6 +35,7 @@
#include <synfig/module.h>
#include "trgt_png.h"
+#include "trgt_cairo_png.h"
#include "mptr_png.h"
#endif
@@ -50,6 +51,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..240d0e2
--- /dev/null
+++ b/synfig-core/src/modules/mod_png/trgt_cairo_png.cpp
@@ -0,0 +1,129 @@
+/* === 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;
+ ready=false;
+ 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::start_frame(synfig::ProgressCallback *callback)
+{
+ 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;
+ }
+
+ ready=true;
+ return true;
+}
+
+synfig::CairoSurface*
+cairo_png_trgt::obtain_surface()
+{
+ int w=desc.get_w(),h=desc.get_h();
+ surface = new
synfig::CairoSurface(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h));
+ return surface;
+}
+
+void
+cairo_png_trgt::end_frame()
+{
+ if(ready)
+ {
+ cairo_surface_write_to_png(surface->get_cairo_surface(),
filename.c_str());
+ }
+
+ imagecount++;
+ ready=false;
+}
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..619dc22
--- /dev/null
+++ b/synfig-core/src/modules/mod_png/trgt_cairo_png.h
@@ -0,0 +1,72 @@
+/* === 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:
+ FILE *file;
+ int w,h;
+
+ bool multi_image,ready;
+ int imagecount;
+ synfig::String filename;
+ synfig::String base_filename;
+ synfig::CairoSurface *surface;
+
+ synfig::String sequence_separator;
+public:
+ cairo_png_trgt(const char *filename, const synfig::TargetParam& /*
params */);
+ virtual ~cairo_png_trgt();
+
+ virtual synfig::CairoSurface* obtain_surface();
+
+ virtual bool set_rend_desc(synfig::RendDesc *desc);
+ virtual bool start_frame(synfig::ProgressCallback *cb);
+ virtual void end_frame();
+};
+
+/* === E N D =============================================================== */
+
+#endif
diff --git a/synfig-core/src/synfig/surface.h b/synfig-core/src/synfig/surface.h
index 350c8a5..bde209b 100644
--- a/synfig-core/src/synfig/surface.h
+++ b/synfig-core/src/synfig/surface.h
@@ -141,7 +141,7 @@ public:
class alpha_pen;
CairoSurface():cs_(NULL) { }
- CairoSurface(cairo_surface_t *cs) { set_cairo_surface(cs); }
+ CairoSurface(cairo_surface_t *cs):cs_(NULL) { set_cairo_surface(cs); }
~CairoSurface() { if(cs_!= NULL) cairo_surface_destroy(cs_); }
diff --git a/synfig-core/src/synfig/target_cairo.cpp
b/synfig-core/src/synfig/target_cairo.cpp
index 25b0380..607ca15 100644
--- a/synfig-core/src/synfig/target_cairo.cpp
+++ b/synfig-core/src/synfig/target_cairo.cpp
@@ -186,5 +186,7 @@ Target_Cairo::add_frame(const CairoSurface *surface)
if(cairo_surface_status(cs))
return false;
cairo_surface_flush(cs);
+ start_frame();
+ end_frame();
return true;
}
------------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/synfig-devl