Author: Carlos Lopez <[email protected]>
Date: Sun Sep 30 19:25:44 2012 +0200
Cairo operators: initial version of convenient functions to make painting
operations in Cairo emulating Synfig's blending methods. Straight doesn't work
yet.
---
synfig-core/src/synfig/Makefile.am | 2 +
synfig-core/src/synfig/cairo_operators.cpp | 97 ++++++++++++++++++++++++++++
synfig-core/src/synfig/cairo_operators.h | 45 +++++++++++++
3 files changed, 144 insertions(+), 0 deletions(-)
diff --git a/synfig-core/src/synfig/Makefile.am
b/synfig-core/src/synfig/Makefile.am
index c16f4f4..92fa656 100644
--- a/synfig-core/src/synfig/Makefile.am
+++ b/synfig-core/src/synfig/Makefile.am
@@ -210,6 +210,7 @@ SYNFIGHEADERS = \
version.h \
activepoint.h \
blur.h \
+ cairo_operators.h \
canvas.h \
color.h \
context.h \
@@ -246,6 +247,7 @@ SYNFIGHEADERS = \
SYNFIGSOURCES = \
activepoint.cpp \
blur.cpp \
+ cairo_operators.cpp \
canvas.cpp \
color.cpp \
context.cpp \
diff --git a/synfig-core/src/synfig/cairo_operators.cpp
b/synfig-core/src/synfig/cairo_operators.cpp
new file mode 100644
index 0000000..033963a
--- /dev/null
+++ b/synfig-core/src/synfig/cairo_operators.cpp
@@ -0,0 +1,97 @@
+/* === S Y N F I G ========================================================= */
+/*! \file template.cpp
+ ** \brief Template File
+ **
+ ** $Id$
+ **
+ ** \legal
+ ** Copyright (c) 2012 Carlos López
+ **
+ ** 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
+ */
+/* ========================================================================= */
+
+/* === H E A D E R S ======================================================= */
+
+#ifdef USING_PCH
+# include "pch.h"
+#else
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "cairo_operators.h"
+
+
+#endif
+
+/* === U S I N G =========================================================== */
+
+using namespace std;
+using namespace etl;
+using namespace synfig;
+
+/* === M A C R O S ========================================================= */
+
+/* === G L O B A L S ======================================================= */
+
+/* === P R O C E D U R E S ================================================= */
+
+void cairo_paint_with_alpha_operator(cairo_t* acr, float alpha,
Color::BlendMethod method, int w, int h)
+{
+ cairo_t* cr=cairo_reference(acr);
+ switch (method)
+ {
+ case Color::BLEND_COMPOSITE:
+ {
+ cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
+ cairo_paint_with_alpha(cr, alpha);
+ break;
+ }
+ case Color::BLEND_STRAIGHT:
+ {
+ cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
+ cairo_paint_with_alpha(cr, alpha);
+ break;
+ }
+ case Color::BLEND_BEHIND:
+ {
+ cairo_set_operator(cr, CAIRO_OPERATOR_DEST_OVER);
+ cairo_paint_with_alpha(cr, alpha);
+ break;
+ }
+ case Color::BLEND_ONTO:
+ {
+ cairo_set_operator(cr, CAIRO_OPERATOR_ATOP);
+ cairo_paint_with_alpha(cr, alpha);
+ break;
+ }
+ case Color::BLEND_ALPHA_OVER:
+ {
+ cairo_set_operator(cr, CAIRO_OPERATOR_DEST_OUT);
+ cairo_paint_with_alpha(cr, alpha);
+ break;
+ }
+ default:
+ {
+ cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
+ cairo_paint_with_alpha(cr, alpha);
+ break;
+ }
+ }
+ cairo_destroy(cr);
+}
+
+
+/* === M E T H O D S ======================================================= */
+
+/* === E N T R Y P O I N T ================================================= */
diff --git a/synfig-core/src/synfig/cairo_operators.h
b/synfig-core/src/synfig/cairo_operators.h
new file mode 100644
index 0000000..8eea43e
--- /dev/null
+++ b/synfig-core/src/synfig/cairo_operators.h
@@ -0,0 +1,45 @@
+/* === S Y N F I G ========================================================= */
+/*! \file cairo_operators.h
+ ** \brief Helper functions that use Cairo operators to do Synfig blending
+ **
+ ** $Id$
+ **
+ ** \legal
+ ** Copyright (c) 2012 Carlos López
+ **
+ ** 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
+ */
+/* ========================================================================= */
+
+/* === S T A R T =========================================================== */
+
+#ifndef __SYNFIG_CAIRO_OPERATORS_H
+#define __SYNFIG_CAIRO_OPERATORS_H
+
+/* === H E A D E R S ======================================================= */
+#include "color.h"
+#include "cairo.h"
+#include "cairomm/cairomm.h"
+
+/* === 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 ======================================= */
+void cairo_paint_with_alpha_operator(cairo_t* cr, float alpha,
synfig::Color::BlendMethod method, int w, int h);
+//void cairo_paint_operator(cairo_t* cr, Color::BlendMethod method);
+//void cairo_stroke_operator(cairo_t* cr, Color::BlendMethod method);
+//void cairo_fill_operator(cairo_t* cr, Color::BlendMethod method);
+//void cairo_mask_operator(cairo_t* cr, cairo_pattern_t* pattern,
Color::BlendMethod method);
+/* === E N D =============================================================== */
+
+#endif
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://ad.doubleclick.net/clk;258768047;13503038;j?
http://info.appdynamics.com/FreeJavaPerformanceDownload.html
_______________________________________________
Synfig-devl mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/synfig-devl