[gnome-photos] Add a saturation filter



commit 37020eef03b97a2fa3bf6f8ed873504c8018f3ff
Author: Debarshi Ray <debarshir gnome org>
Date:   Thu Jan 7 15:55:19 2016 +0100

    Add a saturation filter

 src/Makefile.am                   |    2 +
 src/photos-operation-saturation.c |  206 +++++++++++++++++++++++++++++++++++++
 src/photos-operation-saturation.h |   45 ++++++++
 src/photos-utils.c                |    2 +
 4 files changed, 255 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 1bd1fd3..e53b0f3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -136,6 +136,8 @@ gnome_photos_SOURCES = \
        photos-operation-jpg-guess-sizes.h \
        photos-operation-png-guess-sizes.c \
        photos-operation-png-guess-sizes.h \
+       photos-operation-saturation.c \
+       photos-operation-saturation.h \
        photos-organize-collection-dialog.c \
        photos-organize-collection-dialog.h \
        photos-organize-collection-model.c \
diff --git a/src/photos-operation-saturation.c b/src/photos-operation-saturation.c
new file mode 100644
index 0000000..b0949bb
--- /dev/null
+++ b/src/photos-operation-saturation.c
@@ -0,0 +1,206 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2016 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 <gegl-plugin.h>
+
+#include "photos-operation-saturation.h"
+
+
+struct _PhotosOperationSaturation
+{
+  GeglOperationPointFilter parent_instance;
+  gfloat scale;
+};
+
+struct _PhotosOperationSaturationClass
+{
+  GeglOperationPointFilterClass parent_class;
+};
+
+enum
+{
+  PROP_0,
+  PROP_SCALE
+};
+
+
+G_DEFINE_TYPE (PhotosOperationSaturation, photos_operation_saturation, GEGL_TYPE_OPERATION_POINT_FILTER);
+
+
+static gboolean
+photos_operation_saturation_process (GeglOperation *operation,
+                                     void *in_buf,
+                                     void *out_buf,
+                                     glong n_pixels,
+                                     const GeglRectangle *roi,
+                                     gint level)
+{
+  PhotosOperationSaturation *self = PHOTOS_OPERATION_SATURATION (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;
+    }
+
+  return TRUE;
+}
+
+
+static gboolean
+photos_operation_saturation_process_alpha (GeglOperation *operation,
+                                           void *in_buf,
+                                           void *out_buf,
+                                           glong n_pixels,
+                                           const GeglRectangle *roi,
+                                           gint level)
+{
+  PhotosOperationSaturation *self = PHOTOS_OPERATION_SATURATION (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;
+    }
+
+  return TRUE;
+}
+
+
+static void
+photos_operation_saturation_prepare (GeglOperation *operation)
+{
+  GeglOperationPointFilterClass *point_filter_class = GEGL_OPERATION_POINT_FILTER_GET_CLASS (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))
+    {
+      format = babl_format ("CIE LCH(ab) alpha float");
+      point_filter_class->process = photos_operation_saturation_process_alpha;
+    }
+  else
+    {
+      format = babl_format ("CIE LCH(ab) float");
+      point_filter_class->process = photos_operation_saturation_process;
+    }
+
+  gegl_operation_set_format (operation, "input", format);
+  gegl_operation_set_format (operation, "output", format);
+}
+
+
+static void
+photos_operation_saturation_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+{
+  PhotosOperationSaturation *self = PHOTOS_OPERATION_SATURATION (object);
+
+  switch (prop_id)
+    {
+    case PROP_SCALE:
+      g_value_set_float (value, self->scale);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+
+static void
+photos_operation_saturation_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec 
*pspec)
+{
+  PhotosOperationSaturation *self = PHOTOS_OPERATION_SATURATION (object);
+
+  switch (prop_id)
+    {
+    case PROP_SCALE:
+      self->scale = g_value_get_float (value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+
+static void
+photos_operation_saturation_init (PhotosOperationSaturation *self)
+{
+}
+
+
+static void
+photos_operation_saturation_class_init (PhotosOperationSaturationClass *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_saturation_get_property;
+  object_class->set_property = photos_operation_saturation_set_property;
+  operation_class->prepare = photos_operation_saturation_prepare;
+  point_filter_class->process = NULL; /* will be assigned in prepare */
+
+  g_object_class_install_property (object_class,
+                                   PROP_SCALE,
+                                   g_param_spec_float ("scale",
+                                                       "Scale",
+                                                       "Strength of effect",
+                                                       0.0,
+                                                       2.0,
+                                                       1.0,
+                                                       G_PARAM_CONSTRUCT | G_PARAM_READWRITE));
+
+  gegl_operation_class_set_keys (operation_class,
+                                 "name", "photos:saturation",
+                                 "title", "Saturation",
+                                 "description", "Changes the saturation",
+                                 "categories", "color",
+                                 NULL);
+}
diff --git a/src/photos-operation-saturation.h b/src/photos-operation-saturation.h
new file mode 100644
index 0000000..2ac147d
--- /dev/null
+++ b/src/photos-operation-saturation.h
@@ -0,0 +1,45 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2016 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_SATURATION_H
+#define PHOTOS_OPERATION_SATURATION_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_OPERATION_SATURATION (photos_operation_saturation_get_type ())
+
+#define PHOTOS_OPERATION_SATURATION(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+   PHOTOS_TYPE_OPERATION_SATURATION, PhotosOperationSaturation))
+
+#define PHOTOS_IS_OPERATION_SATURATION(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+   PHOTOS_TYPE_OPERATION_SATURATION))
+
+typedef struct _PhotosOperationSaturation      PhotosOperationSaturation;
+typedef struct _PhotosOperationSaturationClass PhotosOperationSaturationClass;
+
+GType            photos_operation_saturation_get_type       (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* PHOTOS_OPERATION_SATURATION_H */
diff --git a/src/photos-utils.c b/src/photos-utils.c
index 16b3e33..47ca3e1 100644
--- a/src/photos-utils.c
+++ b/src/photos-utils.c
@@ -46,6 +46,7 @@
 #include "photos-operation-insta-filter.h"
 #include "photos-operation-jpg-guess-sizes.h"
 #include "photos-operation-png-guess-sizes.h"
+#include "photos-operation-saturation.h"
 #include "photos-query.h"
 #include "photos-source.h"
 #include "photos-tool.h"
@@ -814,6 +815,7 @@ photos_utils_ensure_builtins (void)
       g_type_ensure (PHOTOS_TYPE_OPERATION_INSTA_FILTER);
       g_type_ensure (PHOTOS_TYPE_OPERATION_JPG_GUESS_SIZES);
       g_type_ensure (PHOTOS_TYPE_OPERATION_PNG_GUESS_SIZES);
+      g_type_ensure (PHOTOS_TYPE_OPERATION_SATURATION);
 
       g_type_ensure (PHOTOS_TYPE_TOOL_COLORS);
       g_type_ensure (PHOTOS_TYPE_TOOL_CROP);


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