[gnome-photos/wip/rishi/hefe2: 1/2] Add Instagram Hefe



commit 8e6c50973cc47c8033cb71e95c648fb8a64d0c19
Author: Debarshi Ray <debarshir gnome org>
Date:   Tue Jan 12 18:34:51 2016 +0100

    Add Instagram Hefe
    
    The filter is implemented by a hidden meta-operation called
    photos:insta-hefe, which in turn uses photos:insta-hefe-curve,
    photos:insta-hefe-vignette and svg:multiply.
    
    Based on:
    http://www.coreyhoard.com/mirror/CH_Rev_Eng_Hefe_wDataset.zip

 data/Makefile.am                           |    1 +
 data/vignette.png                          |  Bin 0 -> 132064 bytes
 src/Makefile.am                            |    6 +
 src/photos-operation-insta-common.h        |    3 +-
 src/photos-operation-insta-curve.c         |    1 +
 src/photos-operation-insta-filter.c        |    7 +
 src/photos-operation-insta-hefe-curve.c    |  116 +++++++++++
 src/photos-operation-insta-hefe-curve.h    |   45 +++++
 src/photos-operation-insta-hefe-vignette.c |  286 ++++++++++++++++++++++++++++
 src/photos-operation-insta-hefe-vignette.h |   45 +++++
 src/photos-operation-insta-hefe.c          |  134 +++++++++++++
 src/photos-operation-insta-hefe.h          |   45 +++++
 src/photos-utils.c                         |    6 +
 src/photos.gresource.xml                   |    1 +
 14 files changed, 695 insertions(+), 1 deletions(-)
---
diff --git a/data/Makefile.am b/data/Makefile.am
index 2fee0d3..f017816 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -35,6 +35,7 @@ EXTRA_DIST = \
        sidebar-radio-selected.svg \
        sidebar-radio-selected-prelight.svg \
        thumbnail-frame.png \
+       vignette.png \
        $(NULL)
 
 CLEANFILES = \
diff --git a/data/vignette.png b/data/vignette.png
new file mode 100644
index 0000000..3826975
Binary files /dev/null and b/data/vignette.png differ
diff --git a/src/Makefile.am b/src/Makefile.am
index a5c5b1a..de7a67a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -132,6 +132,12 @@ gnome_photos_SOURCES = \
        photos-operation-insta-curve.h \
        photos-operation-insta-filter.c \
        photos-operation-insta-filter.h \
+       photos-operation-insta-hefe.c \
+       photos-operation-insta-hefe.h \
+       photos-operation-insta-hefe-curve.c \
+       photos-operation-insta-hefe-curve.h \
+       photos-operation-insta-hefe-vignette.c \
+       photos-operation-insta-hefe-vignette.h \
        photos-operation-jpg-guess-sizes.c \
        photos-operation-jpg-guess-sizes.h \
        photos-operation-png-guess-sizes.c \
diff --git a/src/photos-operation-insta-common.h b/src/photos-operation-insta-common.h
index c9af905..93e1205 100644
--- a/src/photos-operation-insta-common.h
+++ b/src/photos-operation-insta-common.h
@@ -1,6 +1,6 @@
 /*
  * Photos - access, organize and share your photos on GNOME
- * Copyright © 2015 Red Hat, Inc.
+ * Copyright © 2015, 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
@@ -30,6 +30,7 @@ typedef enum
   PHOTOS_OPERATION_INSTA_PRESET_BRANNAN,
   PHOTOS_OPERATION_INSTA_PRESET_GOTHAM,
   PHOTOS_OPERATION_INSTA_PRESET_GRAY,
+  PHOTOS_OPERATION_INSTA_PRESET_HEFE,
   PHOTOS_OPERATION_INSTA_PRESET_NASHVILLE
 } PhotosOperationInstaPreset;
 
diff --git a/src/photos-operation-insta-curve.c b/src/photos-operation-insta-curve.c
index e80ad23..fc03da4 100644
--- a/src/photos-operation-insta-curve.c
+++ b/src/photos-operation-insta-curve.c
@@ -668,6 +668,7 @@ photos_operation_insta_curve_prepare (GeglOperation *operation)
 
     case PHOTOS_OPERATION_INSTA_PRESET_NONE:
     case PHOTOS_OPERATION_INSTA_PRESET_GRAY:
+    case PHOTOS_OPERATION_INSTA_PRESET_HEFE:
     default:
       g_assert_not_reached ();
     }
diff --git a/src/photos-operation-insta-filter.c b/src/photos-operation-insta-filter.c
index 79276af..2f60b76 100644
--- a/src/photos-operation-insta-filter.c
+++ b/src/photos-operation-insta-filter.c
@@ -111,6 +111,13 @@ photos_operation_insta_filter_setup (PhotosOperationInstaFilter *self)
       self->nodes = g_list_prepend (self->nodes, node);
       break;
 
+    case PHOTOS_OPERATION_INSTA_PRESET_HEFE:
+      node = gegl_node_new_child (operation->node,
+                                  "operation", "photos:insta-hefe",
+                                  NULL);
+      self->nodes = g_list_prepend (self->nodes, node);
+      break;
+
     case PHOTOS_OPERATION_INSTA_PRESET_NASHVILLE:
       node = gegl_node_new_child (operation->node,
                                   "operation", "photos:insta-curve",
diff --git a/src/photos-operation-insta-hefe-curve.c b/src/photos-operation-insta-hefe-curve.c
new file mode 100644
index 0000000..4016770
--- /dev/null
+++ b/src/photos-operation-insta-hefe-curve.c
@@ -0,0 +1,116 @@
+/*
+ * 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-insta-hefe-curve.h"
+
+
+struct _PhotosOperationInstaHefeCurve
+{
+  GeglOperationPointFilter parent_instance;
+};
+
+struct _PhotosOperationInstaHefeCurveClass
+{
+  GeglOperationPointFilterClass parent_class;
+};
+
+
+G_DEFINE_TYPE (PhotosOperationInstaHefeCurve, photos_operation_insta_hefe_curve, 
GEGL_TYPE_OPERATION_POINT_FILTER);
+
+
+static void
+photos_operation_insta_hefe_curve_prepare (GeglOperation *operation)
+{
+  const Babl *format;
+
+  format = babl_format ("R'G'B'A float");
+  gegl_operation_set_format (operation, "input", format);
+  gegl_operation_set_format (operation, "output", format);
+}
+
+
+static gboolean
+photos_operation_insta_hefe_curve_process (GeglOperation *operation,
+                                           void *in_buf,
+                                           void *out_buf,
+                                           glong n_pixels,
+                                           const GeglRectangle *roi,
+                                           gint level)
+{
+  gfloat *in = in_buf;
+  gfloat *out = out_buf;
+  glong i;
+
+  for (i = 0; i < n_pixels; i++)
+    {
+      const float b = in[2];
+      const float b2 = b * b;
+      const float b3 = b2 * b;
+      const float g = in[1];
+      const float g2 = g * g;
+      const float g3 = g2 * g;
+      const float r = in[0];
+      const float r2 = r * r;
+      const float r3 = r2 * r;
+
+      out[0] = -13.47f * r3 * r3 + 41.23f * r3 * r2 - 45.04f * r2 * r2 + 19.17 * r3 - 1.492f * r2 + 0.5954f 
* r;
+      out[1] = -12.28f * g3 * g3 + 41.09f * g3 * g2 - 50.52f * g2 * g2 + 26.03 * g3 - 3.916f * g2 + 0.58f * 
g;
+      out[2] = -1.066f * b3 * b3 + 9.679f * b3 * b2 - 19.09f * b2 * b2 + 12.92 * b3 - 1.835f * b2 + 0.3487f 
* b;
+      out[3] = in[3];
+
+      in += 4;
+      out += 4;
+    }
+
+  return TRUE;
+}
+
+
+static void
+photos_operation_insta_hefe_curve_init (PhotosOperationInstaHefeCurve *self)
+{
+}
+
+
+static void
+photos_operation_insta_hefe_curve_class_init (PhotosOperationInstaHefeCurveClass *class)
+{
+  GeglOperationClass *operation_class = GEGL_OPERATION_CLASS (class);
+  GeglOperationPointFilterClass *point_filter_class = GEGL_OPERATION_POINT_FILTER_CLASS (class);
+
+  operation_class->opencl_support = FALSE;
+
+  operation_class->prepare = photos_operation_insta_hefe_curve_prepare;
+  point_filter_class->process = photos_operation_insta_hefe_curve_process;
+
+  gegl_operation_class_set_keys (operation_class,
+                                 "name", "photos:insta-hefe-curve",
+                                 "title", "Insta Hefe Curve",
+                                 "description", "Apply the Hefe curve to an image",
+                                 "categories", "hidden",
+                                 NULL);
+}
diff --git a/src/photos-operation-insta-hefe-curve.h b/src/photos-operation-insta-hefe-curve.h
new file mode 100644
index 0000000..2ee0be6
--- /dev/null
+++ b/src/photos-operation-insta-hefe-curve.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_INSTA_HEFE_CURVE_H
+#define PHOTOS_OPERATION_INSTA_HEFE_CURVE_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_OPERATION_INSTA_HEFE_CURVE (photos_operation_insta_hefe_curve_get_type ())
+
+#define PHOTOS_OPERATION_INSTA_HEFE_CURVE(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+   PHOTOS_TYPE_OPERATION_INSTA_HEFE_CURVE, PhotosOperationInstaHefeCurve))
+
+#define PHOTOS_IS_OPERATION_INSTA_HEFE_CURVE(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+   PHOTOS_TYPE_OPERATION_INSTA_HEFE_CURVE))
+
+typedef struct _PhotosOperationInstaHefeCurve      PhotosOperationInstaHefeCurve;
+typedef struct _PhotosOperationInstaHefeCurveClass PhotosOperationInstaHefeCurveClass;
+
+GType            photos_operation_insta_hefe_curve_get_type       (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* PHOTOS_OPERATION_INSTA_HEFE_CURVE_H */
diff --git a/src/photos-operation-insta-hefe-vignette.c b/src/photos-operation-insta-hefe-vignette.c
new file mode 100644
index 0000000..20c718b
--- /dev/null
+++ b/src/photos-operation-insta-hefe-vignette.c
@@ -0,0 +1,286 @@
+/*
+ * 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 <gdk-pixbuf/gdk-pixbuf.h>
+#include <gegl.h>
+#include <gegl-plugin.h>
+
+#include "photos-operation-insta-hefe-vignette.h"
+
+
+struct _PhotosOperationInstaHefeVignette
+{
+  GeglOperationPointRender parent_instance;
+  gdouble height;
+  gdouble height_ratio;
+  gdouble width;
+  gdouble width_ratio;
+  gdouble x;
+  gdouble y;
+};
+
+struct _PhotosOperationInstaHefeVignetteClass
+{
+  GeglOperationPointRenderClass parent_class;
+};
+
+enum
+{
+  PROP_0,
+  PROP_HEIGHT,
+  PROP_WIDTH,
+  PROP_X,
+  PROP_Y
+};
+
+
+G_DEFINE_TYPE (PhotosOperationInstaHefeVignette,
+               photos_operation_insta_hefe_vignette,
+               GEGL_TYPE_OPERATION_POINT_RENDER);
+
+
+static GdkPixbuf *vignette;
+static guchar *vignette_pixels;
+static gint vignette_height;
+static gint vignette_rowstride;
+static gint vignette_width;
+
+
+static void
+photos_operation_insta_hefe_vignette_get_rgb (PhotosOperationInstaHefeVignette *self,
+                                              gint x,
+                                              gint y,
+                                              guint8 *out_r,
+                                              guint8 *out_g,
+                                              guint8 *out_b)
+{
+  gint pixbuf_x;
+  gint pixbuf_y;
+  guchar *pixel;
+
+  pixbuf_x = (gint) (((gdouble) x - self->x) * self->width_ratio + 0.5);
+  pixbuf_y = (gint) (((gdouble) y - self->y) * self->height_ratio + 0.5);
+  pixel = vignette_pixels + (vignette_rowstride * pixbuf_y) + 3 * pixbuf_x;
+
+  /* We don't want optional out parameters because that will
+   * introduce if branches in this hot path.
+  */
+  *out_r = (guint8) pixel[0];
+  *out_g = (guint8) pixel[1];
+  *out_b = (guint8) pixel[2];
+}
+
+
+static GeglRectangle
+photos_operation_insta_hefe_vignette_get_bounding_box (GeglOperation *operation)
+{
+  PhotosOperationInstaHefeVignette *self = PHOTOS_OPERATION_INSTA_HEFE_VIGNETTE (operation);
+  GeglRectangle bbox;
+
+  gegl_rectangle_set (&bbox, (gint) self->x, (gint) self->y, (gint) self->width, (gint) self->height);
+  return bbox;
+}
+
+
+static void
+photos_operation_insta_hefe_vignette_prepare (GeglOperation *operation)
+{
+  const Babl* format;
+
+  format = babl_format ("R'G'B'A u8");
+  gegl_operation_set_format (operation, "output", format);
+}
+
+
+static gboolean
+photos_operation_insta_hefe_vignette_process (GeglOperation *operation,
+                                              void *out_buf,
+                                              glong n_pixels,
+                                              const GeglRectangle *roi,
+                                              gint level)
+{
+  PhotosOperationInstaHefeVignette *self = PHOTOS_OPERATION_INSTA_HEFE_VIGNETTE (operation);
+  const gint x1 = roi->x + roi->width;
+  const gint y1 = roi->y + roi->height;
+  gint x;
+  gint y;
+  guint8 *out = out_buf;
+
+  for (y = roi->y; y < y1; y++)
+    {
+      for (x = roi->x; x < x1; x++)
+        {
+          photos_operation_insta_hefe_vignette_get_rgb (self, x, y, &out[0], &out[1], &out[2]);
+          out[3] = 255;
+          out += 4;
+        }
+    }
+
+  return TRUE;
+}
+
+
+static void
+photos_operation_insta_hefe_vignette_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec 
*pspec)
+{
+  PhotosOperationInstaHefeVignette *self = PHOTOS_OPERATION_INSTA_HEFE_VIGNETTE (object);
+
+  switch (prop_id)
+    {
+    case PROP_HEIGHT:
+      g_value_set_double (value, self->height);
+      break;
+
+    case PROP_WIDTH:
+      g_value_set_double (value, self->width);
+      break;
+
+    case PROP_X:
+      g_value_set_double (value, self->x);
+      break;
+
+    case PROP_Y:
+      g_value_set_double (value, self->y);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+
+static void
+photos_operation_insta_hefe_vignette_set_property (GObject *object, guint prop_id, const GValue *value, 
GParamSpec *pspec)
+{
+  PhotosOperationInstaHefeVignette *self = PHOTOS_OPERATION_INSTA_HEFE_VIGNETTE (object);
+
+  switch (prop_id)
+    {
+    case PROP_HEIGHT:
+      self->height = g_value_get_double (value);
+      self->height_ratio = vignette_height / self->height;
+      break;
+
+    case PROP_WIDTH:
+      self->width = g_value_get_double (value);
+      self->width_ratio = vignette_width / self->width;
+      break;
+
+    case PROP_X:
+      self->x = g_value_get_double (value);
+      break;
+
+    case PROP_Y:
+      self->y = g_value_get_double (value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+
+static void
+photos_operation_insta_hefe_vignette_init (PhotosOperationInstaHefeVignette *self)
+{
+  if (vignette == NULL)
+    {
+      GError *error;
+
+      error = NULL;
+      vignette = gdk_pixbuf_new_from_resource ("/org/gnome/Photos/vignette.png", &error);
+      g_assert_no_error (error);
+
+      vignette_pixels = gdk_pixbuf_get_pixels (vignette);
+      vignette_rowstride = gdk_pixbuf_get_rowstride (vignette);
+      vignette_height = gdk_pixbuf_get_height (vignette);
+      vignette_width = gdk_pixbuf_get_width (vignette);
+    }
+}
+
+
+static void
+photos_operation_insta_hefe_vignette_class_init (PhotosOperationInstaHefeVignetteClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+  GeglOperationClass *operation_class = GEGL_OPERATION_CLASS (class);
+  GeglOperationPointRenderClass *point_render_class = GEGL_OPERATION_POINT_RENDER_CLASS (class);
+
+  operation_class->opencl_support = FALSE;
+
+  object_class->get_property = photos_operation_insta_hefe_vignette_get_property;
+  object_class->set_property = photos_operation_insta_hefe_vignette_set_property;
+  operation_class->get_bounding_box = photos_operation_insta_hefe_vignette_get_bounding_box;
+  operation_class->prepare = photos_operation_insta_hefe_vignette_prepare;
+  point_render_class->process = photos_operation_insta_hefe_vignette_process;
+
+  g_object_class_install_property (object_class,
+                                   PROP_HEIGHT,
+                                   g_param_spec_double ("height",
+                                                        "Height",
+                                                        "Vertical extent",
+                                                        0.0,
+                                                        G_MAXDOUBLE,
+                                                        10.0,
+                                                        G_PARAM_CONSTRUCT | G_PARAM_READWRITE));
+
+  g_object_class_install_property (object_class,
+                                   PROP_WIDTH,
+                                   g_param_spec_double ("width",
+                                                        "Width",
+                                                        "Horizontal extent",
+                                                        0.0,
+                                                        G_MAXDOUBLE,
+                                                        10.0,
+                                                        G_PARAM_CONSTRUCT | G_PARAM_READWRITE));
+
+  g_object_class_install_property (object_class,
+                                   PROP_X,
+                                   g_param_spec_double ("x",
+                                                        "X",
+                                                        "Horizontal position",
+                                                        0.0,
+                                                        G_MAXDOUBLE,
+                                                        0.0,
+                                                        G_PARAM_CONSTRUCT | G_PARAM_READWRITE));
+
+  g_object_class_install_property (object_class,
+                                   PROP_Y,
+                                   g_param_spec_double ("y",
+                                                        "Y",
+                                                        "Vertical position",
+                                                        0.0,
+                                                        G_MAXDOUBLE,
+                                                        0.0,
+                                                        G_PARAM_CONSTRUCT | G_PARAM_READWRITE));
+
+  gegl_operation_class_set_keys (operation_class,
+                                 "name", "photos:insta-hefe-vignette",
+                                 "title", "Insta Hefe Vignette",
+                                 "description", "Apply the Hefe vignette to an image",
+                                 "categories", "hidden",
+                                 NULL);
+}
diff --git a/src/photos-operation-insta-hefe-vignette.h b/src/photos-operation-insta-hefe-vignette.h
new file mode 100644
index 0000000..e8c6299
--- /dev/null
+++ b/src/photos-operation-insta-hefe-vignette.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_INSTA_HEFE_VIGNETTE_H
+#define PHOTOS_OPERATION_INSTA_HEFE_VIGNETTE_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_OPERATION_INSTA_HEFE_VIGNETTE (photos_operation_insta_hefe_vignette_get_type ())
+
+#define PHOTOS_OPERATION_INSTA_HEFE_VIGNETTE(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+   PHOTOS_TYPE_OPERATION_INSTA_HEFE_VIGNETTE, PhotosOperationInstaHefeVignette))
+
+#define PHOTOS_IS_OPERATION_INSTA_HEFE_VIGNETTE(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+   PHOTOS_TYPE_OPERATION_INSTA_HEFE_VIGNETTE))
+
+typedef struct _PhotosOperationInstaHefeVignette      PhotosOperationInstaHefeVignette;
+typedef struct _PhotosOperationInstaHefeVignetteClass PhotosOperationInstaHefeVignetteClass;
+
+GType            photos_operation_insta_hefe_vignette_get_type       (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* PHOTOS_OPERATION_INSTA_HEFE_VIGNETTE_H */
diff --git a/src/photos-operation-insta-hefe.c b/src/photos-operation-insta-hefe.c
new file mode 100644
index 0000000..b424a1c
--- /dev/null
+++ b/src/photos-operation-insta-hefe.c
@@ -0,0 +1,134 @@
+/*
+ * 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-insta-hefe.h"
+
+
+struct _PhotosOperationInstaHefe
+{
+  GeglOperationMeta parent_instance;
+  GeglNode *vignette;
+  GeglNode *input;
+  GeglNode *output;
+  GeglRectangle bbox;
+};
+
+struct _PhotosOperationInstaHefeClass
+{
+  GeglOperationMetaClass parent_class;
+};
+
+
+G_DEFINE_TYPE (PhotosOperationInstaHefe, photos_operation_insta_hefe, GEGL_TYPE_OPERATION_META);
+
+
+static void
+photos_operation_insta_hefe_setup (PhotosOperationInstaHefe *self)
+{
+  gegl_node_set (self->vignette,
+                 "height", (gdouble) self->bbox.height,
+                 "width", (gdouble) self->bbox.width,
+                 "x", (gdouble) self->bbox.x,
+                 "y", (gdouble) self->bbox.y,
+                 NULL);
+}
+
+
+static void
+photos_operation_insta_hefe_attach (GeglOperation *operation)
+{
+  PhotosOperationInstaHefe *self = PHOTOS_OPERATION_INSTA_HEFE (operation);
+  GeglNode *curve;
+  GeglNode *multiply;
+
+  self->input = gegl_node_get_output_proxy (operation->node, "input");
+  self->output = gegl_node_get_output_proxy (operation->node, "output");
+
+  curve = gegl_node_new_child (operation->node, "operation", "photos:insta-hefe-curve", NULL);
+  multiply = gegl_node_new_child (operation->node, "operation", "svg:multiply", "srgb", TRUE, NULL);
+  self->vignette = gegl_node_new_child (operation->node, "operation", "photos:insta-hefe-vignette", NULL);
+
+  gegl_node_connect_to (self->vignette, "output", multiply, "aux");
+  gegl_node_link_many (self->input, multiply, curve, self->output, NULL);
+
+  gegl_operation_meta_watch_nodes (operation, curve, multiply, self->vignette, NULL);
+}
+
+
+static GeglNode *
+photos_operation_insta_hefe_detect (GeglOperation *operation, gint x, gint y)
+{
+  PhotosOperationInstaHefe *self = PHOTOS_OPERATION_INSTA_HEFE (operation);
+  GeglRectangle bounds;
+
+  bounds = gegl_node_get_bounding_box (self->output);
+  if (x >= bounds.x && y >= bounds.y && x < bounds.x + bounds.width && y < bounds.y + bounds.height)
+    return operation->node;
+
+  return NULL;
+}
+
+
+static void
+photos_operation_insta_hefe_prepare (GeglOperation *operation)
+{
+  PhotosOperationInstaHefe *self = PHOTOS_OPERATION_INSTA_HEFE (operation);
+  GeglRectangle bbox;
+
+  bbox = gegl_node_get_bounding_box (self->input);
+  if (!gegl_rectangle_equal (&self->bbox, &bbox))
+    {
+      self->bbox = bbox;
+      photos_operation_insta_hefe_setup (self);
+    }
+}
+
+
+static void
+photos_operation_insta_hefe_init (PhotosOperationInstaHefe *self)
+{
+}
+
+
+static void
+photos_operation_insta_hefe_class_init (PhotosOperationInstaHefeClass *class)
+{
+  GeglOperationClass *operation_class = GEGL_OPERATION_CLASS (class);
+
+  operation_class->opencl_support = FALSE;
+
+  operation_class->attach = photos_operation_insta_hefe_attach;
+  operation_class->detect = photos_operation_insta_hefe_detect;
+  operation_class->prepare = photos_operation_insta_hefe_prepare;
+
+  gegl_operation_class_set_keys (operation_class,
+                                 "name", "photos:insta-hefe",
+                                 "title", "Insta Hefe",
+                                 "description", "Apply the Hefe filter to an image",
+                                 "categories", "hidden",
+                                 NULL);
+}
diff --git a/src/photos-operation-insta-hefe.h b/src/photos-operation-insta-hefe.h
new file mode 100644
index 0000000..05a4109
--- /dev/null
+++ b/src/photos-operation-insta-hefe.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_INSTA_HEFE_H
+#define PHOTOS_OPERATION_INSTA_HEFE_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_OPERATION_INSTA_HEFE (photos_operation_insta_hefe_get_type ())
+
+#define PHOTOS_OPERATION_INSTA_HEFE(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+   PHOTOS_TYPE_OPERATION_INSTA_HEFE, PhotosOperationInstaHefe))
+
+#define PHOTOS_IS_OPERATION_INSTA_HEFE(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+   PHOTOS_TYPE_OPERATION_INSTA_HEFE))
+
+typedef struct _PhotosOperationInstaHefe      PhotosOperationInstaHefe;
+typedef struct _PhotosOperationInstaHefeClass PhotosOperationInstaHefeClass;
+
+GType            photos_operation_insta_hefe_get_type       (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* PHOTOS_OPERATION_INSTA_HEFE_H */
diff --git a/src/photos-utils.c b/src/photos-utils.c
index 47ca3e1..d440afc 100644
--- a/src/photos-utils.c
+++ b/src/photos-utils.c
@@ -44,6 +44,9 @@
 #include "photos-media-server-item.h"
 #include "photos-operation-insta-curve.h"
 #include "photos-operation-insta-filter.h"
+#include "photos-operation-insta-hefe.h"
+#include "photos-operation-insta-hefe-curve.h"
+#include "photos-operation-insta-hefe-vignette.h"
 #include "photos-operation-jpg-guess-sizes.h"
 #include "photos-operation-png-guess-sizes.h"
 #include "photos-operation-saturation.h"
@@ -813,6 +816,9 @@ photos_utils_ensure_builtins (void)
 
       g_type_ensure (PHOTOS_TYPE_OPERATION_INSTA_CURVE);
       g_type_ensure (PHOTOS_TYPE_OPERATION_INSTA_FILTER);
+      g_type_ensure (PHOTOS_TYPE_OPERATION_INSTA_HEFE);
+      g_type_ensure (PHOTOS_TYPE_OPERATION_INSTA_HEFE_CURVE);
+      g_type_ensure (PHOTOS_TYPE_OPERATION_INSTA_HEFE_VIGNETTE);
       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);
diff --git a/src/photos.gresource.xml b/src/photos.gresource.xml
index 54daa09..8669a0c 100644
--- a/src/photos.gresource.xml
+++ b/src/photos.gresource.xml
@@ -13,6 +13,7 @@
     <file alias="sidebar-radio-selected.svg" 
preprocess="to-pixdata">../data/sidebar-radio-selected.svg</file>
     <file alias="sidebar-radio-selected-prelight.svg" 
preprocess="to-pixdata">../data/sidebar-radio-selected-prelight.svg</file>
     <file alias="thumbnail-frame.png" preprocess="to-pixdata">../data/thumbnail-frame.png</file>
+    <file alias="vignette.png" preprocess="to-pixdata">../data/vignette.png</file>
   </gresource>
 
   <gresource prefix="/org/gnome/Photos/gtk">


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