[lasem] svg_filter: add support for feComposite.



commit bdf6ac5fac095ea9ee3440b90593e9fc7f63743e
Author: Emmanuel Pacaud <emmanuel gnome org>
Date:   Sun Oct 14 19:33:53 2012 +0200

    svg_filter: add support for feComposite.

 docs/reference/lasem/Makefile.am |    1 +
 src/Makefile.am                  |    2 +
 src/lsmcairo.c                   |   16 +++++-
 src/lsmsvgdocument.c             |    3 +
 src/lsmsvgenums.c                |    7 ++-
 src/lsmsvgenums.h                |    7 ++-
 src/lsmsvgfiltercomposite.c      |  110 ++++++++++++++++++++++++++++++++++++++
 src/lsmsvgfiltercomposite.h      |   58 ++++++++++++++++++++
 src/lsmsvgtypes.h                |    1 +
 9 files changed, 201 insertions(+), 4 deletions(-)
---
diff --git a/docs/reference/lasem/Makefile.am b/docs/reference/lasem/Makefile.am
index 5acc841..8ee57c9 100644
--- a/docs/reference/lasem/Makefile.am
+++ b/docs/reference/lasem/Makefile.am
@@ -148,6 +148,7 @@ IGNORE_HFILES=\
 	lsmsvgfilterelement.h			\
 	lsmsvgfilterprimitive.h			\
 	lsmsvgfilterblend.h			\
+	lsmsvgfiltercomposite.h			\
 	lsmsvgfilterflood.h			\
 	lsmsvgfiltergaussianblur.h		\
 	lsmsvgfilteroffset.h
diff --git a/src/Makefile.am b/src/Makefile.am
index 1ab507f..835299b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -127,6 +127,7 @@ LASEM_SVG_SRCS =				\
 	lsmsvgfilterelement.c			\
 	lsmsvgfilterprimitive.c			\
 	lsmsvgfilterblend.c			\
+	lsmsvgfiltercomposite.c			\
 	lsmsvgfilterflood.c			\
 	lsmsvgfiltergaussianblur.c		\
 	lsmsvgfilteroffset.c
@@ -235,6 +236,7 @@ LASEM_SVG_HDRS =				\
 	lsmsvgfilterelement.h			\
 	lsmsvgfilterprimitive.h			\
 	lsmsvgfilterblend.h			\
+	lsmsvgfiltercomposite.h			\
 	lsmsvgfilterflood.h			\
 	lsmsvgfiltergaussianblur.h		\
 	lsmsvgfilteroffset.h
diff --git a/src/lsmcairo.c b/src/lsmcairo.c
index 4504b98..21c074c 100644
--- a/src/lsmcairo.c
+++ b/src/lsmcairo.c
@@ -335,6 +335,18 @@ lsm_filter_surface_blend (LsmFilterSurface *input_1,
 		case LSM_SVG_BLENDING_MODE_LIGHTEN:
 			op = CAIRO_OPERATOR_LIGHTEN;
 			break;
+		case LSM_SVG_BLENDING_MODE_IN:
+			op = CAIRO_OPERATOR_IN;
+			break;
+		case LSM_SVG_BLENDING_MODE_OUT:
+			op = CAIRO_OPERATOR_OUT;
+			break;
+		case LSM_SVG_BLENDING_MODE_ATOP:
+			op = CAIRO_OPERATOR_ATOP;
+			break;
+		case LSM_SVG_BLENDING_MODE_XOR:
+			op = CAIRO_OPERATOR_XOR;
+			break;
 		default:
 			op = CAIRO_OPERATOR_OVER;
 			break;
@@ -342,10 +354,10 @@ lsm_filter_surface_blend (LsmFilterSurface *input_1,
 
 	cairo = cairo_create (output->surface);
 
-	cairo_set_source_surface (cairo, input_1->surface, 0, 0);
+	cairo_set_source_surface (cairo, input_2->surface, 0, 0);
 	cairo_paint (cairo);
 
-	cairo_set_source_surface (cairo, input_2->surface, 0, 0);
+	cairo_set_source_surface (cairo, input_1->surface, 0, 0);
 	cairo_set_operator (cairo, op);
 	cairo_paint (cairo);
 
diff --git a/src/lsmsvgdocument.c b/src/lsmsvgdocument.c
index 979476f..f81f559 100644
--- a/src/lsmsvgdocument.c
+++ b/src/lsmsvgdocument.c
@@ -47,6 +47,7 @@
 #include <lsmsvgmaskelement.h>
 #include <lsmsvgfilterelement.h>
 #include <lsmsvgfilterblend.h>
+#include <lsmsvgfiltercomposite.h>
 #include <lsmsvgfilterflood.h>
 #include <lsmsvgfiltergaussianblur.h>
 #include <lsmsvgfilteroffset.h>
@@ -139,6 +140,8 @@ _create_element (LsmDomDocument *document, const char *tag_name)
 		node = lsm_svg_filter_element_new ();
 	else if (strcmp (tag_name, "feBlend") == 0)
 		node = lsm_svg_filter_blend_new ();
+	else if (strcmp (tag_name, "feComposite") == 0)
+		node = lsm_svg_filter_composite_new ();
 	else if (strcmp (tag_name, "feFlood") == 0)
 		node = lsm_svg_filter_flood_new ();
 	else if (strcmp (tag_name, "feGaussianBlur") == 0)
diff --git a/src/lsmsvgenums.c b/src/lsmsvgenums.c
index 95c8b69..b6307a7 100644
--- a/src/lsmsvgenums.c
+++ b/src/lsmsvgenums.c
@@ -30,7 +30,12 @@ static const char *lsm_svg_blending_mode_strings[] = {
 	"multiply",
 	"screen",
 	"darken",
-	"lighten"
+	"lighten",
+	"over",
+	"in",
+	"out",
+	"atop",
+	"xor"
 };
 
 const char *
diff --git a/src/lsmsvgenums.h b/src/lsmsvgenums.h
index 003c0e5..0a94487 100644
--- a/src/lsmsvgenums.h
+++ b/src/lsmsvgenums.h
@@ -41,7 +41,12 @@ typedef enum {
 	LSM_SVG_BLENDING_MODE_MULTIPLY,
 	LSM_SVG_BLENDING_MODE_SCREEN,
 	LSM_SVG_BLENDING_MODE_DARKEN,
-	LSM_SVG_BLENDING_MODE_LIGHTEN
+	LSM_SVG_BLENDING_MODE_LIGHTEN,
+	LSM_SVG_BLENDING_MODE_OVER,
+	LSM_SVG_BLENDING_MODE_IN,
+	LSM_SVG_BLENDING_MODE_OUT,
+	LSM_SVG_BLENDING_MODE_ATOP,
+	LSM_SVG_BLENDING_MODE_XOR
 } LsmSvgBlendingMode;
 
 const char * 		lsm_svg_blending_mode_to_string 	(LsmSvgBlendingMode blending_mode);
diff --git a/src/lsmsvgfiltercomposite.c b/src/lsmsvgfiltercomposite.c
new file mode 100644
index 0000000..1730ae8
--- /dev/null
+++ b/src/lsmsvgfiltercomposite.c
@@ -0,0 +1,110 @@
+/* Lasem
+ * 
+ * Copyright  2012 Emmanuel Pacaud
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author:
+ * 	Emmanuel Pacaud <emmanuel gnome org>
+ */
+
+#include <lsmsvgfiltercomposite.h>
+#include <lsmsvgview.h>
+
+static GObjectClass *parent_class;
+
+/* GdomNode implementation */
+
+static const char *
+lsm_svg_filter_composite_get_node_name (LsmDomNode *node)
+{
+	return "feComposite";
+}
+
+/* LsmSvgElement implementation */
+
+static void
+lsm_svg_filter_composite_apply  (LsmSvgFilterPrimitive *self, LsmSvgView *view,
+				     const char *input, const char *output,
+				     double x, double y, double w, double h)
+{
+	LsmSvgFilterComposite *composite = LSM_SVG_FILTER_COMPOSITE (self);
+
+	lsm_svg_view_apply_blend (view, input, composite->in2.value, output, composite->op.value);
+}
+
+/* LsmSvgFilterComposite implementation */
+
+static LsmSvgBlendingMode op_default = LSM_SVG_BLENDING_MODE_OVER;
+
+LsmDomNode *
+lsm_svg_filter_composite_new (void)
+{
+	return g_object_new (LSM_TYPE_SVG_FILTER_COMPOSITE, NULL);
+}
+
+static void
+lsm_svg_filter_composite_init (LsmSvgFilterComposite *self)
+{
+	self->op.value = op_default;
+}
+
+static void
+lsm_svg_filter_composite_finalize (GObject *object)
+{
+	parent_class->finalize (object);
+}
+
+/* LsmSvgFilterComposite class */
+
+static const LsmAttributeInfos lsm_svg_filter_composite_attribute_infos[] = {
+	{
+		.name = "in2",
+		.attribute_offset = offsetof (LsmSvgFilterComposite, in2),
+		.trait_class = &lsm_null_trait_class
+	},
+	{
+		.name = "operator",
+		.attribute_offset = offsetof (LsmSvgFilterComposite, op),
+		.trait_class = &lsm_svg_blending_mode_trait_class,
+		.trait_default = &op_default
+	}
+};
+
+static void
+lsm_svg_filter_composite_class_init (LsmSvgFilterCompositeClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	LsmDomNodeClass *d_node_class = LSM_DOM_NODE_CLASS (klass);
+	LsmSvgElementClass *s_element_class = LSM_SVG_ELEMENT_CLASS (klass);
+	LsmSvgFilterPrimitiveClass *f_primitive_class = LSM_SVG_FILTER_PRIMITIVE_CLASS (klass);
+
+	parent_class = g_type_class_peek_parent (klass);
+
+	object_class->finalize = lsm_svg_filter_composite_finalize;
+
+	d_node_class->get_node_name = lsm_svg_filter_composite_get_node_name;
+
+	s_element_class->attribute_manager = lsm_attribute_manager_duplicate (s_element_class->attribute_manager);
+
+	lsm_attribute_manager_add_attributes (s_element_class->attribute_manager,
+					      G_N_ELEMENTS (lsm_svg_filter_composite_attribute_infos),
+					      lsm_svg_filter_composite_attribute_infos);
+
+	f_primitive_class->apply = lsm_svg_filter_composite_apply;
+}
+
+G_DEFINE_TYPE (LsmSvgFilterComposite, lsm_svg_filter_composite, LSM_TYPE_SVG_FILTER_PRIMITIVE)
diff --git a/src/lsmsvgfiltercomposite.h b/src/lsmsvgfiltercomposite.h
new file mode 100644
index 0000000..0278132
--- /dev/null
+++ b/src/lsmsvgfiltercomposite.h
@@ -0,0 +1,58 @@
+/* Lasem
+ *
+ * Copyright  2012 Emmanuel Pacaud
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author:
+ * 	Emmanuel Pacaud <emmanuel gnome org>
+ */
+
+#ifndef LSM_SVG_FILTER_COMPOSITE_H
+#define LSM_SVG_FILTER_COMPOSITE_H
+
+#include <lsmsvgtypes.h>
+#include <lsmsvgfilterprimitive.h>
+
+G_BEGIN_DECLS
+
+#define LSM_TYPE_SVG_FILTER_COMPOSITE             (lsm_svg_filter_composite_get_type ())
+#define LSM_SVG_FILTER_COMPOSITE(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), LSM_TYPE_SVG_FILTER_COMPOSITE, LsmSvgFilterComposite))
+#define LSM_SVG_FILTER_COMPOSITE_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), LSM_TYPE_SVG_FILTER_COMPOSITE, LsmSvgFilterCompositeClass))
+#define LSM_IS_SVG_FILTER_COMPOSITE(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LSM_TYPE_SVG_FILTER_COMPOSITE))
+#define LSM_IS_SVG_FILTER_COMPOSITE_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), LSM_TYPE_SVG_FILTER_COMPOSITE))
+#define LSM_SVG_FILTER_COMPOSITE_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj), LSM_TYPE_SVG_FILTER_COMPOSITE, LsmSvgFilterCompositeClass))
+
+typedef struct _LsmSvgFilterCompositeClass LsmSvgFilterCompositeClass;
+
+struct _LsmSvgFilterComposite {
+	LsmSvgFilterPrimitive base;
+
+	LsmAttribute in2;
+	LsmSvgBlendingModeAttribute op;
+};
+
+struct _LsmSvgFilterCompositeClass {
+	LsmSvgFilterPrimitiveClass  element_class;
+};
+
+GType lsm_svg_filter_composite_get_type (void);
+
+LsmDomNode * 	lsm_svg_filter_composite_new 		(void);
+
+G_END_DECLS
+
+#endif
diff --git a/src/lsmsvgtypes.h b/src/lsmsvgtypes.h
index d1432bc..30dba1c 100644
--- a/src/lsmsvgtypes.h
+++ b/src/lsmsvgtypes.h
@@ -58,6 +58,7 @@ typedef struct _LsmSvgMaskElement LsmSvgMaskElement;
 typedef struct _LsmSvgFilterElement LsmSvgFilterElement;
 typedef struct _LsmSvgFilterPrimitive LsmSvgFilterPrimitive;
 typedef struct _LsmSvgFilterBlend LsmSvgFilterBlend;
+typedef struct _LsmSvgFilterComposite LsmSvgFilterComposite;
 typedef struct _LsmSvgFilterFlood LsmSvgFilterFlood;
 typedef struct _LsmSvgFilterGaussianBlur LsmSvgFilterGaussianBlur;
 typedef struct _LsmSvgFilterOffset LsmSvgFilterOffset;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]