[gnome-photos/wip/rishi/multiply] Add a filter for the SVG blend operation multiply
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/multiply] Add a filter for the SVG blend operation multiply
- Date: Wed, 21 Jun 2017 15:20:35 +0000 (UTC)
commit b47d369569ccd0286c2f35c7c527d6932f36cd83
Author: Debarshi Ray <debarshir gnome org>
Date: Wed Jun 21 17:19:56 2017 +0200
Add a filter for the SVG blend operation multiply
src/Makefile.am | 4 +
src/photos-operation-svg-multiply.c | 287 +++++++++++++++++++++++++++++++++++
src/photos-operation-svg-multiply.h | 39 +++++
3 files changed, 330 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 62a6940..b0649b6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -166,6 +166,8 @@ gnome_photos_SOURCES = \
photos-operation-png-guess-sizes.h \
photos-operation-saturation.c \
photos-operation-saturation.h \
+ photos-operation-svg-multiply.c \
+ photos-operation-svg-multiply.h \
photos-organize-collection-dialog.c \
photos-organize-collection-dialog.h \
photos-organize-collection-model.c \
@@ -332,6 +334,8 @@ gnome_photos_thumbnailer_SOURCES = \
photos-operation-png-guess-sizes.h \
photos-operation-saturation.c \
photos-operation-saturation.h \
+ photos-operation-svg-multiply.c \
+ photos-operation-svg-multiply.h \
photos-pipeline.c \
photos-pipeline.h \
photos-pixbuf.c \
diff --git a/src/photos-operation-svg-multiply.c b/src/photos-operation-svg-multiply.c
new file mode 100644
index 0000000..79da55c
--- /dev/null
+++ b/src/photos-operation-svg-multiply.c
@@ -0,0 +1,287 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2017 Red Hat, Inc.
+ *
+ * This program 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 program 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+
+#include "config.h"
+
+#include <babl/babl.h>
+#include <gegl.h>
+
+#include "photos-operation-svg-multiply.h"
+
+
+typedef void (*PhotosOperationProcessFunc) (GeglOperation *,
+ void *,
+ void *,
+ void *,
+ glong,
+ const GeglRectangle *,
+ gint);
+
+struct _PhotosOperationSvgMultiply
+{
+ GeglOperationPointComposer parent_instance;
+ PhotosOperationProcessFunc process;
+ gboolean srgb;
+};
+
+enum
+{
+ PROP_0,
+ PROP_SRGB
+};
+
+
+G_DEFINE_TYPE (PhotosOperationSvgMultiply, photos_operation_svg_multiply,
GEGL_TYPE_OPERATION_POINT_COMPOSER);
+
+
+static void
+photos_operation_svg_multiply_process_lab (GeglOperation *operation,
+ void *in_buf,
+ void *out_buf,
+ glong n_pixels,
+ const GeglRectangle *roi,
+ gint level)
+{
+ PhotosOperationSvgMultiply *self = PHOTOS_OPERATION_SVG_MULTIPLY (operation);
+ gfloat *in = in_buf;
+ gfloat *out = out_buf;
+ glong i;
+
+ for (i = 0; i < n_pixels; i++)
+ {
+ out[0] = in[0];
+ out[1] = in[1] * self->scale;
+ out[2] = in[2] * self->scale;
+
+ in += 3;
+ out += 3;
+ }
+}
+
+
+static void
+photos_operation_svg_multiply_process_lab_alpha (GeglOperation *operation,
+ void *in_buf,
+ void *out_buf,
+ glong n_pixels,
+ const GeglRectangle *roi,
+ gint level)
+{
+ PhotosOperationSvgMultiply *self = PHOTOS_OPERATION_SVG_MULTIPLY (operation);
+ gfloat *in = in_buf;
+ gfloat *out = out_buf;
+ glong i;
+
+ for (i = 0; i < n_pixels; i++)
+ {
+ out[0] = in[0];
+ out[1] = in[1] * self->scale;
+ out[2] = in[2] * self->scale;
+ out[3] = in[3];
+
+ in += 4;
+ out += 4;
+ }
+}
+
+
+static void
+photos_operation_svg_multiply_process_lch (GeglOperation *operation,
+ void *in_buf,
+ void *out_buf,
+ glong n_pixels,
+ const GeglRectangle *roi,
+ gint level)
+{
+ PhotosOperationSvgMultiply *self = PHOTOS_OPERATION_SVG_MULTIPLY (operation);
+ gfloat *in = in_buf;
+ gfloat *out = out_buf;
+ glong i;
+
+ for (i = 0; i < n_pixels; i++)
+ {
+ out[0] = in[0];
+ out[1] = in[1] * self->scale;
+ out[2] = in[2];
+
+ in += 3;
+ out += 3;
+ }
+}
+
+
+static void
+photos_operation_svg_multiply_process_lch_alpha (GeglOperation *operation,
+ void *in_buf,
+ void *out_buf,
+ glong n_pixels,
+ const GeglRectangle *roi,
+ gint level)
+{
+ PhotosOperationSvgMultiply *self = PHOTOS_OPERATION_SVG_MULTIPLY (operation);
+ gfloat *in = in_buf;
+ gfloat *out = out_buf;
+ glong i;
+
+ for (i = 0; i < n_pixels; i++)
+ {
+ out[0] = in[0];
+ out[1] = in[1] * self->scale;
+ out[2] = in[2];
+ out[3] = in[3];
+
+ in += 4;
+ out += 4;
+ }
+}
+
+
+static void
+photos_operation_svg_multiply_prepare (GeglOperation *operation)
+{
+ PhotosOperationSvgMultiply *self = PHOTOS_OPERATION_SVG_MULTIPLY (operation);
+ const Babl *format;
+ const Babl *input_format;
+
+ input_format = gegl_operation_get_source_format (operation, "input");
+ if (input_format == NULL)
+ return;
+
+ if (babl_format_has_alpha (input_format))
+ {
+ model_lch = babl_model ("CIE LCH(ab) alpha");
+ if (model_input == model_lch)
+ {
+ format = babl_format ("CIE LCH(ab) alpha float");
+ self->process = photos_operation_svg_multiply_process_lch_alpha;
+ }
+ else
+ {
+ format = babl_format ("CIE Lab alpha float");
+ self->process = photos_operation_svg_multiply_process_lab_alpha;
+ }
+ }
+ else
+ {
+ model_lch = babl_model ("CIE LCH(ab)");
+ if (model_input == model_lch)
+ {
+ format = babl_format ("CIE LCH(ab) float");
+ self->process = photos_operation_svg_multiply_process_lch;
+ }
+ else
+ {
+ format = babl_format ("CIE Lab float");
+ self->process = photos_operation_svg_multiply_process_lab;
+ }
+ }
+
+ gegl_operation_set_format (operation, "input", format);
+ gegl_operation_set_format (operation, "output", format);
+}
+
+
+static gboolean
+photos_operation_svg_multiply_process (GeglOperation *operation,
+ void *in_buf,
+ void *out_buf,
+ glong n_pixels,
+ const GeglRectangle *roi,
+ gint level)
+{
+ PhotosOperationSvgMultiply *self = PHOTOS_OPERATION_SVG_MULTIPLY (operation);
+
+ self->process (operation, in_buf, out_buf, n_pixels, roi, level);
+ return TRUE;
+}
+
+
+static void
+photos_operation_svg_multiply_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+{
+ PhotosOperationSvgMultiply *self = PHOTOS_OPERATION_SVG_MULTIPLY (object);
+
+ switch (prop_id)
+ {
+ case PROP_SCALE:
+ g_value_set_double (value, (gdouble) self->scale);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+
+static void
+photos_operation_svg_multiply_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec
*pspec)
+{
+ PhotosOperationSvgMultiply *self = PHOTOS_OPERATION_SVG_MULTIPLY (object);
+
+ switch (prop_id)
+ {
+ case PROP_SCALE:
+ self->scale = (gfloat) g_value_get_double (value);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+
+static void
+photos_operation_svg_multiply_init (PhotosOperationSvgMultiply *self)
+{
+}
+
+
+static void
+photos_operation_svg_multiply_class_init (PhotosOperationSvgMultiplyClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+ GeglOperationClass *operation_class = GEGL_OPERATION_CLASS (class);
+ GeglOperationPointFilterClass *point_filter_class = GEGL_OPERATION_POINT_FILTER_CLASS (class);
+
+ operation_class->opencl_support = FALSE;
+
+ object_class->get_property = photos_operation_svg_multiply_get_property;
+ object_class->set_property = photos_operation_svg_multiply_set_property;
+ operation_class->prepare = photos_operation_svg_multiply_prepare;
+ point_filter_class->process = photos_operation_svg_multiply_process;
+
+ g_object_class_install_property (object_class,
+ PROP_SRGB,
+ g_param_spec_boolean ("srgb",
+ "sRGB",
+ "Use sRGB gamma instead of linear",
+ FALSE,
+ G_PARAM_CONSTRUCT | G_PARAM_READWRITE));
+
+ gegl_operation_class_set_keys (operation_class,
+ "name", "photos:svg-multiply",
+ "title", "SVG Multiply",
+ "description", "SVG blend operation multiply",
+ "categories", "compositors:svgfilter",
+ NULL);
+}
diff --git a/src/photos-operation-svg-multiply.h b/src/photos-operation-svg-multiply.h
new file mode 100644
index 0000000..0aa0357
--- /dev/null
+++ b/src/photos-operation-svg-multiply.h
@@ -0,0 +1,39 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2017 Red Hat, Inc.
+ *
+ * This program 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 program 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef PHOTOS_OPERATION_SVG_MULTIPLY_H
+#define PHOTOS_OPERATION_SVG_MULTIPLY_H
+
+#include <gegl-plugin.h>
+
+#include "photos-gegl.h"
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_OPERATION_SVG_MULTIPLY (photos_operation_svg_multiply_get_type ())
+G_DECLARE_FINAL_TYPE (PhotosOperationSvgMultiply,
+ photos_operation_svg_multiply,
+ PHOTOS,
+ OPERATION_SVG_MULTIPLY,
+ GeglOperationPointComposer);
+
+G_END_DECLS
+
+#endif /* PHOTOS_OPERATION_SVG_MULTIPLY_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]