[lasem] svg: feColorMatrix boilerplate
- From: Emmanuel Pacaud <emmanuel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [lasem] svg: feColorMatrix boilerplate
- Date: Fri, 31 Jul 2015 22:32:33 +0000 (UTC)
commit f68f46bf03a3be38778671b5a3e85d3c0f7f6f1a
Author: Emmanuel Pacaud <emmanuel gnome org>
Date: Sat Aug 1 00:32:03 2015 +0200
svg: feColorMatrix boilerplate
src/Makefile.am | 1 +
src/lsmsvgattributes.h | 10 ++++
src/lsmsvgdocument.c | 3 +
src/lsmsvgenums.c | 23 ++++++++
src/lsmsvgenums.h | 11 ++++
src/lsmsvgfiltercolormatrix.c | 115 +++++++++++++++++++++++++++++++++++++++++
src/lsmsvgfiltercolormatrix.h | 58 +++++++++++++++++++++
src/lsmsvgtraits.c | 89 +++++++++++++++++++++++++++++++
src/lsmsvgtraits.h | 7 +++
src/lsmsvgtypes.h | 1 +
src/lsmsvgview.c | 24 +++++++++
src/lsmsvgview.h | 3 +
12 files changed, 345 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index bbfb1c0..9b2f9e7 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -134,6 +134,7 @@ LASEM_SVG_SRCS = \
lsmsvgfilterelement.c \
lsmsvgfilterprimitive.c \
lsmsvgfilterblend.c \
+ lsmsvgfiltercolormatrix.c \
lsmsvgfiltercomposite.c \
lsmsvgfilterflood.c \
lsmsvgfiltergaussianblur.c \
diff --git a/src/lsmsvgattributes.h b/src/lsmsvgattributes.h
index 9ddd92d..a9c2cfb 100644
--- a/src/lsmsvgattributes.h
+++ b/src/lsmsvgattributes.h
@@ -50,6 +50,11 @@ typedef struct {
typedef struct {
LsmAttribute base;
+ LsmSvgVector value;
+} LsmSvgVectorAttribute;
+
+typedef struct {
+ LsmAttribute base;
LsmSvgDashArray *value;
} LsmSvgDashArrayAttribute;
@@ -110,6 +115,11 @@ typedef struct {
typedef struct {
LsmAttribute base;
+ LsmSvgColorFilterType value;
+} LsmSvgColorFilterTypeAttribute;
+
+typedef struct {
+ LsmAttribute base;
LsmSvgAngle value;
} LsmSvgAngleAttribute;
diff --git a/src/lsmsvgdocument.c b/src/lsmsvgdocument.c
index aa2f925..f9e4879 100644
--- a/src/lsmsvgdocument.c
+++ b/src/lsmsvgdocument.c
@@ -37,6 +37,7 @@
#include <lsmsvgfiltermerge.h>
#include <lsmsvgfiltermergenode.h>
#include <lsmsvgfilterspecularlighting.h>
+#include <lsmsvgfiltercolormatrix.h>
#include <lsmsvgfiltertile.h>
#include <lsmsvggelement.h>
#include <lsmsvgimageelement.h>
@@ -166,6 +167,8 @@ _create_element (LsmDomDocument *document, const char *tag_name)
node = lsm_svg_filter_offset_new ();
else if (strcmp (tag_name, "feSpecularLighting") == 0)
node = lsm_svg_filter_specular_lighting_new ();
+ else if (strcmp (tag_name, "feColorMatrix") == 0)
+ node = lsm_svg_filter_color_matrix_new ();
else if (strcmp (tag_name, "feTile") == 0)
node = lsm_svg_filter_tile_new ();
diff --git a/src/lsmsvgenums.c b/src/lsmsvgenums.c
index 6144c0c..8844383 100644
--- a/src/lsmsvgenums.c
+++ b/src/lsmsvgenums.c
@@ -542,3 +542,26 @@ lsm_svg_writing_mode_from_string (const char *string)
G_N_ELEMENTS (lsm_svg_writing_mode_strings));
}
+static const char *lsm_svg_color_filter_type_strings[] = {
+ "matrix",
+ "saturate",
+ "hueRotate",
+ "luminanceToAlpha"
+};
+
+const char *
+lsm_svg_color_filter_type_to_string (LsmSvgColorFilterType color_filter_type)
+{
+ if (color_filter_type < 0 || color_filter_type > LSM_SVG_COLOR_FILTER_TYPE_LUMINANCE_TO_ALPHA)
+ return NULL;
+
+ return lsm_svg_color_filter_type_strings[color_filter_type];
+}
+
+LsmSvgColorFilterType
+lsm_svg_color_filter_type_from_string (const char *string)
+{
+ return lsm_enum_value_from_string (string, lsm_svg_color_filter_type_strings,
+ G_N_ELEMENTS (lsm_svg_color_filter_type_strings));
+}
+
diff --git a/src/lsmsvgenums.h b/src/lsmsvgenums.h
index 867eb06..34c2248 100644
--- a/src/lsmsvgenums.h
+++ b/src/lsmsvgenums.h
@@ -352,6 +352,17 @@ typedef enum {
const char * lsm_svg_writing_mode_to_string (LsmSvgWritingMode writing_mode);
LsmSvgWritingMode lsm_svg_writing_mode_from_string (const char *string);
+typedef enum {
+ LSM_SVG_COLOR_FILTER_TYPE_ERROR = -1,
+ LSM_SVG_COLOR_FILTER_TYPE_MATRIX,
+ LSM_SVG_COLOR_FILTER_TYPE_SATURATE,
+ LSM_SVG_COLOR_FILTER_TYPE_HUE_ROTATE,
+ LSM_SVG_COLOR_FILTER_TYPE_LUMINANCE_TO_ALPHA
+} LsmSvgColorFilterType;
+
+const char * lsm_svg_color_filter_type_to_string (LsmSvgColorFilterType type);
+LsmSvgColorFilterType lsm_svg_color_filter_type_from_string (const char *string);
+
G_END_DECLS
#endif
diff --git a/src/lsmsvgfiltercolormatrix.c b/src/lsmsvgfiltercolormatrix.c
new file mode 100644
index 0000000..11b92ce
--- /dev/null
+++ b/src/lsmsvgfiltercolormatrix.c
@@ -0,0 +1,115 @@
+/* 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 <lsmsvgfiltercolormatrix.h>
+#include <lsmsvgview.h>
+
+static GObjectClass *parent_class;
+
+/* GdomNode implementation */
+
+static const char *
+lsm_svg_filter_color_matrix_get_node_name (LsmDomNode *node)
+{
+ return "feColorMatrix";
+}
+
+/* LsmSvgElement implementation */
+
+static void
+lsm_svg_filter_color_matrix_apply (LsmSvgFilterPrimitive *self, LsmSvgView *view,
+ const char *input, const char *output, const LsmBox *subregion)
+{
+ LsmSvgFilterColorMatrix *color_matrix = LSM_SVG_FILTER_COLOR_MATRIX (self);
+
+ lsm_svg_view_apply_color_matrix (view, input, output, subregion,
+ color_matrix->type.value,
+ color_matrix->values.value.n_values,
+ color_matrix->values.value.values);
+}
+
+/* LsmSvgFilterColorMatrix implementation */
+
+static const LsmSvgColorFilterType color_filter_type_default = LSM_SVG_COLOR_FILTER_TYPE_MATRIX;
+static const LsmSvgVector values_default = { .n_values = 0, .values = NULL};
+
+LsmDomNode *
+lsm_svg_filter_color_matrix_new (void)
+{
+ return g_object_new (LSM_TYPE_SVG_FILTER_COLOR_MATRIX, NULL);
+}
+
+static void
+lsm_svg_filter_color_matrix_init (LsmSvgFilterColorMatrix *self)
+{
+ self->type.value = color_filter_type_default;
+ self->values.value = values_default;
+}
+
+static void
+lsm_svg_filter_color_matrix_finalize (GObject *object)
+{
+ parent_class->finalize (object);
+}
+
+/* LsmSvgFilterColorMatrix class */
+
+static const LsmAttributeInfos lsm_svg_filter_color_matrix_attribute_infos[] = {
+ {
+ .name = "type",
+ .attribute_offset = offsetof (LsmSvgFilterColorMatrix, type),
+ .trait_class = &lsm_svg_color_filter_type_trait_class,
+ .trait_default = &color_filter_type_default
+ },
+ {
+ .name = "values",
+ .attribute_offset = offsetof (LsmSvgFilterColorMatrix, values),
+ .trait_class = &lsm_svg_vector_trait_class,
+ .trait_default = &values_default
+ }
+};
+
+static void
+lsm_svg_filter_color_matrix_class_init (LsmSvgFilterColorMatrixClass *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_color_matrix_finalize;
+
+ d_node_class->get_node_name = lsm_svg_filter_color_matrix_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_color_matrix_attribute_infos),
+ lsm_svg_filter_color_matrix_attribute_infos);
+
+ f_primitive_class->apply = lsm_svg_filter_color_matrix_apply;
+}
+
+G_DEFINE_TYPE (LsmSvgFilterColorMatrix, lsm_svg_filter_color_matrix, LSM_TYPE_SVG_FILTER_PRIMITIVE)
diff --git a/src/lsmsvgfiltercolormatrix.h b/src/lsmsvgfiltercolormatrix.h
new file mode 100644
index 0000000..be762b3
--- /dev/null
+++ b/src/lsmsvgfiltercolormatrix.h
@@ -0,0 +1,58 @@
+/* Lasem
+ *
+ * Copyright © 2015 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_COLOR_MATRIX_H
+#define LSM_SVG_FILTER_COLOR_MATRIX_H
+
+#include <lsmsvgtypes.h>
+#include <lsmsvgfilterprimitive.h>
+
+G_BEGIN_DECLS
+
+#define LSM_TYPE_SVG_FILTER_COLOR_MATRIX (lsm_svg_filter_color_matrix_get_type ())
+#define LSM_SVG_FILTER_COLOR_MATRIX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
LSM_TYPE_SVG_FILTER_COLOR_MATRIX, LsmSvgFilterColorMatrix))
+#define LSM_SVG_FILTER_COLOR_MATRIX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
LSM_TYPE_SVG_FILTER_COLOR_MATRIX, LsmSvgFilterColorMatrixClass))
+#define LSM_IS_SVG_FILTER_COLOR_MATRIX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
LSM_TYPE_SVG_FILTER_COLOR_MATRIX))
+#define LSM_IS_SVG_FILTER_COLOR_MATRIX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
LSM_TYPE_SVG_FILTER_COLOR_MATRIX))
+#define LSM_SVG_FILTER_COLOR_MATRIX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj),
LSM_TYPE_SVG_FILTER_COLOR_MATRIX, LsmSvgFilterColorMatrixClass))
+
+typedef struct _LsmSvgFilterColorMatrixClass LsmSvgFilterColorMatrixClass;
+
+struct _LsmSvgFilterColorMatrix {
+ LsmSvgFilterPrimitive base;
+
+ LsmSvgColorFilterTypeAttribute type;
+ LsmSvgVectorAttribute values;
+};
+
+struct _LsmSvgFilterColorMatrixClass {
+ LsmSvgFilterPrimitiveClass element_class;
+};
+
+GType lsm_svg_filter_color_matrix_get_type (void);
+
+LsmDomNode * lsm_svg_filter_color_matrix_new (void);
+
+G_END_DECLS
+
+#endif
diff --git a/src/lsmsvgtraits.c b/src/lsmsvgtraits.c
index fe4b2d7..3f99941 100644
--- a/src/lsmsvgtraits.c
+++ b/src/lsmsvgtraits.c
@@ -104,6 +104,71 @@ const LsmTraitClass lsm_svg_enable_background_trait_class = {
};
static gboolean
+lsm_svg_vector_trait_from_string (LsmTrait *abstract_trait, char *string)
+{
+ LsmSvgVector *vector = (LsmSvgVector *) abstract_trait;
+ unsigned int n_values = 1;
+ gboolean success = FALSE;
+ char *iter = (char *) string;
+
+ g_free (vector->values);
+ vector->n_values = 0;
+ vector->values = NULL;
+
+ while (*iter != '\0') {
+ if (*iter == ',' ||
+ *iter == ' ') {
+ n_values++;
+ do {
+ iter++;
+ } while (*iter == ',' ||
+ *iter == ' ');
+ } else
+ iter++;
+ }
+
+ vector->values = g_new (double, n_values);
+ vector->n_values = n_values;
+
+ iter = (char *)string;
+ n_values = lsm_str_parse_double_list (&iter, vector->n_values, vector->values);
+ success = n_values != vector->n_values;
+
+ if (!success) {
+ g_free (vector->values);
+ vector->values = NULL;
+ vector->n_values = 0;
+ }
+
+ return TRUE;
+}
+
+static char *
+lsm_svg_vector_trait_to_string (LsmTrait *abstract_trait)
+{
+ g_assert_not_reached ();
+
+ return NULL;
+}
+
+static void
+lsm_svg_vector_trait_finalize (LsmTrait *abstract_trait)
+{
+ LsmSvgVector *svg_vector = (LsmSvgVector *) abstract_trait;
+
+ g_free (svg_vector->values);
+ svg_vector->n_values = 0;
+ svg_vector->values = NULL;
+}
+
+const LsmTraitClass lsm_svg_vector_trait_class = {
+ .size = sizeof (LsmSvgVector),
+ .from_string = lsm_svg_vector_trait_from_string,
+ .to_string = lsm_svg_vector_trait_to_string,
+ .finalize = lsm_svg_vector_trait_finalize
+};
+
+static gboolean
lsm_svg_length_trait_from_string (LsmTrait *abstract_trait, char *string)
{
LsmSvgLength *svg_length = (LsmSvgLength *) abstract_trait;
@@ -936,6 +1001,30 @@ const LsmTraitClass lsm_svg_color_trait_class = {
};
static gboolean
+lsm_svg_color_filter_type_trait_from_string (LsmTrait *abstract_trait, char *string)
+{
+ LsmSvgColorFilterType *trait = (LsmSvgColorFilterType *) abstract_trait;
+
+ *trait = lsm_svg_color_filter_type_from_string (string);
+
+ return *trait >= 0;
+}
+
+static char *
+lsm_svg_color_filter_type_trait_to_string (LsmTrait *abstract_trait)
+{
+ LsmSvgColorFilterType *trait = (LsmSvgColorFilterType *) abstract_trait;
+
+ return g_strdup (lsm_svg_color_filter_type_to_string (*trait));
+}
+
+const LsmTraitClass lsm_svg_color_filter_type_trait_class = {
+ .size = sizeof (LsmSvgColorFilterType),
+ .from_string = lsm_svg_color_filter_type_trait_from_string,
+ .to_string = lsm_svg_color_filter_type_trait_to_string
+};
+
+static gboolean
lsm_svg_marker_units_trait_from_string (LsmTrait *abstract_trait, char *string)
{
LsmSvgMarkerUnits *trait = (LsmSvgMarkerUnits *) abstract_trait;
diff --git a/src/lsmsvgtraits.h b/src/lsmsvgtraits.h
index 62be70d..64f16aa 100644
--- a/src/lsmsvgtraits.h
+++ b/src/lsmsvgtraits.h
@@ -31,6 +31,11 @@
G_BEGIN_DECLS
typedef struct {
+ unsigned int n_values;
+ double *values;
+} LsmSvgVector;
+
+typedef struct {
LsmSvgAngleType type;
double angle;
} LsmSvgAngle;
@@ -76,6 +81,7 @@ extern const LsmTraitClass lsm_svg_angle_trait_class;
extern const LsmTraitClass lsm_svg_blending_mode_trait_class;
extern const LsmTraitClass lsm_svg_enable_background_trait_class;
extern const LsmTraitClass lsm_svg_color_trait_class;
+extern const LsmTraitClass lsm_svg_color_filter_type_trait_class;
extern const LsmTraitClass lsm_svg_comp_op_trait_class;
extern const LsmTraitClass lsm_svg_dash_array_trait_class;
extern const LsmTraitClass lsm_svg_display_trait_class;
@@ -90,6 +96,7 @@ extern const LsmTraitClass lsm_svg_line_cap_trait_class;
extern const LsmTraitClass lsm_svg_marker_units_trait_class;
extern const LsmTraitClass lsm_svg_matrix_trait_class;
extern const LsmTraitClass lsm_svg_one_or_two_double_trait_class;
+extern const LsmTraitClass lsm_svg_vector_trait_class;
extern const LsmTraitClass lsm_svg_overflow_trait_class;
extern const LsmTraitClass lsm_svg_paint_trait_class;
extern const LsmTraitClass lsm_svg_pattern_units_trait_class;
diff --git a/src/lsmsvgtypes.h b/src/lsmsvgtypes.h
index 9451f9b..62ef995 100644
--- a/src/lsmsvgtypes.h
+++ b/src/lsmsvgtypes.h
@@ -47,6 +47,7 @@ typedef struct _LsmSvgEllipseElement LsmSvgEllipseElement;
typedef struct _LsmSvgFilterElement LsmSvgFilterElement;
typedef struct _LsmSvgFilterPrimitive LsmSvgFilterPrimitive;
typedef struct _LsmSvgFilterBlend LsmSvgFilterBlend;
+typedef struct _LsmSvgFilterColorMatrix LsmSvgFilterColorMatrix;
typedef struct _LsmSvgFilterComposite LsmSvgFilterComposite;
typedef struct _LsmSvgFilterFlood LsmSvgFilterFlood;
typedef struct _LsmSvgFilterGaussianBlur LsmSvgFilterGaussianBlur;
diff --git a/src/lsmsvgview.c b/src/lsmsvgview.c
index e9d9985..275c600 100644
--- a/src/lsmsvgview.c
+++ b/src/lsmsvgview.c
@@ -2179,6 +2179,30 @@ lsm_svg_view_apply_offset (LsmSvgView *view, const char *input, const char *outp
}
void
+lsm_svg_view_apply_color_matrix (LsmSvgView *view, const char *input, const char *output,
+ const LsmBox *subregion, LsmSvgColorFilterType type,
+ unsigned int n_values, const double *values)
+{
+ LsmSvgFilterSurface *input_surface;
+ LsmSvgFilterSurface *output_surface;
+ LsmBox subregion_px;
+
+ g_return_if_fail (LSM_IS_SVG_VIEW (view));
+
+ input_surface = _get_filter_surface (view, input);
+
+ if (input_surface == NULL) {
+ lsm_debug_render ("[SvgView::apply_offset] Input '%s' not found", input);
+ return;
+ }
+
+ lsm_cairo_box_user_to_device (view->dom_view.cairo, &subregion_px, subregion);
+ output_surface = _create_filter_surface (view, output, input_surface, &subregion_px);
+
+ lsm_svg_filter_surface_offset (input_surface, output_surface, 0, 0);
+}
+
+void
lsm_svg_view_apply_merge (LsmSvgView *view, const char *input, const char *output, const LsmBox *subregion)
{
LsmSvgFilterSurface *input_surface;
diff --git a/src/lsmsvgview.h b/src/lsmsvgview.h
index df27365..575c166 100644
--- a/src/lsmsvgview.h
+++ b/src/lsmsvgview.h
@@ -172,6 +172,9 @@ void lsm_svg_view_apply_gaussian_blur (LsmSvgView *view, const char
*input, co
double std_x, double std_y);
void lsm_svg_view_apply_offset (LsmSvgView *view, const char *input, const char
*output, const LsmBox *subregion,
double dx, double dy);
+void lsm_svg_view_apply_color_matrix (LsmSvgView *view, const char *input, const char
*output,
+ const LsmBox *subregion, LsmSvgColorFilterType type,
+ unsigned int n_values, const double *values);
void lsm_svg_view_apply_merge (LsmSvgView *view, const char *input, const char
*output, const LsmBox *subregion);
void lsm_svg_view_apply_tile (LsmSvgView *view, const char *input, const char
*output, const LsmBox *subregion);
[
Date Prev][
Date Next] [
Thread Prev][Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]