[gnome-photos/wip/rishi/hefe: 2/5] add



commit 9f151f4e067e16a4dd1b6aaa2edc0586fd755144
Author: Debarshi Ray <debarshir gnome org>
Date:   Fri Jan 22 12:32:22 2016 +0100

    add

 src/Makefile.am            |    2 +
 src/photos-operation-add.c |  206 ++++++++++++++++++++++++++++++++++++++++++++
 src/photos-operation-add.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 b625543..cf47ba1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -127,6 +127,8 @@ gnome_photos_SOURCES = \
        photos-offset-overview-controller.h \
        photos-offset-search-controller.c \
        photos-offset-search-controller.h \
+       photos-operation-add.c \
+       photos-operation-add.h \
        photos-operation-insta-common.h \
        photos-operation-insta-curve.c \
        photos-operation-insta-curve.h \
diff --git a/src/photos-operation-add.c b/src/photos-operation-add.c
new file mode 100644
index 0000000..8dcf2d7
--- /dev/null
+++ b/src/photos-operation-add.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-add.h"
+
+
+struct _PhotosOperationAdd
+{
+  GeglOperationPointComposer parent_instance;
+  gboolean srgb;
+  gfloat value;
+};
+
+struct _PhotosOperationAddClass
+{
+  GeglOperationPointComposerClass parent_class;
+};
+
+enum
+{
+  PROP_0,
+  PROP_SRGB,
+  PROP_VALUE
+};
+
+
+G_DEFINE_TYPE (PhotosOperationAdd, photos_operation_add, GEGL_TYPE_OPERATION_POINT_COMPOSER);
+
+
+static void
+photos_operation_add_prepare (GeglOperation *operation)
+{
+  PhotosOperationAdd *self = PHOTOS_OPERATION_ADD (operation);
+  const Babl *format;
+
+  if (self->srgb)
+    format = babl_format ("R'aG'aB'aA float");
+  else
+    format = babl_format ("RaGaBaA float");
+
+  gegl_operation_set_format (operation, "aux", format);
+  gegl_operation_set_format (operation, "input", format);
+  gegl_operation_set_format (operation, "output", format);
+}
+
+
+static gboolean
+photos_operation_add_process (GeglOperation *operation,
+                              void *in_buf,
+                              void *aux_buf,
+                              void *out_buf,
+                              glong n_pixels,
+                              const GeglRectangle *roi,
+                              gint level)
+{
+  PhotosOperationAdd *self = PHOTOS_OPERATION_ADD (operation);
+  gfloat *aux = aux_buf;
+  gfloat *in = in_buf;
+  gfloat *out = out_buf;
+  glong i;
+
+  if (aux == NULL)
+    {
+      for (i = 0; i < n_pixels; i++)
+        {
+          out[0] = self->value + in[0];
+          out[1] = self->value + in[1];
+          out[2] = self->value + in[2];
+          out[3] = in[3];
+
+          in += 4;
+          out += 4;
+        }
+    }
+  else
+    {
+      for (i = 0; i < n_pixels; i++)
+        {
+          out[0] = aux[0] + in[0];
+          out[1] = aux[1] + in[1];
+          out[2] = aux[2] + in[2];
+          out[3] = aux[3] + in[3];
+
+          aux += 4;
+          in += 4;
+          out += 4;
+        }
+    }
+
+  return TRUE;
+}
+
+
+static void
+photos_operation_add_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+{
+  PhotosOperationAdd *self = PHOTOS_OPERATION_ADD (object);
+
+  switch (prop_id)
+    {
+    case PROP_SRGB:
+      g_value_set_boolean (value, self->srgb);
+      break;
+
+    case PROP_VALUE:
+      g_value_set_double (value, (gdouble) self->value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+
+static void
+photos_operation_add_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+{
+  PhotosOperationAdd *self = PHOTOS_OPERATION_ADD (object);
+
+  switch (prop_id)
+    {
+    case PROP_SRGB:
+      self->srgb = g_value_get_boolean (value);
+      break;
+
+    case PROP_VALUE:
+      self->value = (gfloat) g_value_get_double (value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+
+static void
+photos_operation_add_init (PhotosOperationAdd *self)
+{
+}
+
+
+static void
+photos_operation_add_class_init (PhotosOperationAddClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+  GeglOperationClass *operation_class = GEGL_OPERATION_CLASS (class);
+  GeglOperationPointComposerClass *point_composer_class = GEGL_OPERATION_POINT_COMPOSER_CLASS (class);
+
+  operation_class->opencl_support = FALSE;
+
+  object_class->get_property = photos_operation_add_get_property;
+  object_class->set_property = photos_operation_add_set_property;
+  operation_class->prepare = photos_operation_add_prepare;
+  point_composer_class->process = photos_operation_add_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));
+
+  g_object_class_install_property (object_class,
+                                   PROP_VALUE,
+                                   g_param_spec_double ("value",
+                                                        "Value",
+                                                        "Global value used if aux doesn't contain data",
+                                                        -1.0,
+                                                        1.0,
+                                                        0.0,
+                                                        G_PARAM_CONSTRUCT | G_PARAM_READWRITE));
+
+  gegl_operation_class_set_keys (operation_class,
+                                 "name", "photos:add",
+                                 "title", "Add",
+                                 "description", "Porter Duff operation add (d = cA + cB)",
+                                 "categories", "compositors:porter-duff",
+                                 NULL);
+}
diff --git a/src/photos-operation-add.h b/src/photos-operation-add.h
new file mode 100644
index 0000000..bdc31e5
--- /dev/null
+++ b/src/photos-operation-add.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_ADD_H
+#define PHOTOS_OPERATION_ADD_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_OPERATION_ADD (photos_operation_add_get_type ())
+
+#define PHOTOS_OPERATION_ADD(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+   PHOTOS_TYPE_OPERATION_ADD, PhotosOperationAdd))
+
+#define PHOTOS_IS_OPERATION_ADD(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+   PHOTOS_TYPE_OPERATION_ADD))
+
+typedef struct _PhotosOperationAdd      PhotosOperationAdd;
+typedef struct _PhotosOperationAddClass PhotosOperationAddClass;
+
+GType            photos_operation_add_get_type       (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* PHOTOS_OPERATION_ADD_H */
diff --git a/src/photos-utils.c b/src/photos-utils.c
index 6afa818..4769f6d 100644
--- a/src/photos-utils.c
+++ b/src/photos-utils.c
@@ -42,6 +42,7 @@
 #include "photos-google-item.h"
 #include "photos-local-item.h"
 #include "photos-media-server-item.h"
+#include "photos-operation-add.h"
 #include "photos-operation-insta-curve.h"
 #include "photos-operation-insta-filter.h"
 #include "photos-operation-jpg-guess-sizes.h"
@@ -812,6 +813,7 @@ photos_utils_ensure_builtins (void)
       g_type_ensure (PHOTOS_TYPE_LOCAL_ITEM);
       g_type_ensure (PHOTOS_TYPE_MEDIA_SERVER_ITEM);
 
+      g_type_ensure (PHOTOS_TYPE_OPERATION_ADD);
       g_type_ensure (PHOTOS_TYPE_OPERATION_INSTA_CURVE);
       g_type_ensure (PHOTOS_TYPE_OPERATION_INSTA_FILTER);
       g_type_ensure (PHOTOS_TYPE_OPERATION_JPG_GUESS_SIZES);


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