[gnome-photos/wip/rishi/hefe: 3/5] Add insta vignette
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/hefe: 3/5] Add insta vignette
- Date: Fri, 22 Jan 2016 20:00:26 +0000 (UTC)
commit 869c41bb44290fed27360ec5ab8016cd471f1a4e
Author: Debarshi Ray <debarshir gnome org>
Date: Tue Jan 12 19:44:11 2016 +0100
Add insta vignette
src/Makefile.am | 2 +
src/photos-operation-insta-vignette.c | 234 +++++++++++++++++++++++++++++++++
src/photos-operation-insta-vignette.h | 45 +++++++
src/photos-utils.c | 2 +
4 files changed, 283 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index cf47ba1..d5ed64d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -134,6 +134,8 @@ gnome_photos_SOURCES = \
photos-operation-insta-curve.h \
photos-operation-insta-filter.c \
photos-operation-insta-filter.h \
+ photos-operation-insta-vignette.c \
+ photos-operation-insta-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-vignette.c b/src/photos-operation-insta-vignette.c
new file mode 100644
index 0000000..20053d2
--- /dev/null
+++ b/src/photos-operation-insta-vignette.c
@@ -0,0 +1,234 @@
+/*
+ * 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.
+ */
+
+/* Based on code from:
+ * + noflo-image
+ */
+
+
+#include "config.h"
+
+#include <math.h>
+
+#include <babl/babl.h>
+#include <gegl.h>
+#include <gegl-plugin.h>
+
+#include "photos-operation-insta-vignette.h"
+
+
+struct _PhotosOperationInstaVignette
+{
+ GeglOperationMeta parent_instance;
+ GeglNode *crop1;
+ GeglNode *crop2;
+ GeglNode *crop3;
+ GeglNode *gradient1;
+ GeglNode *gradient2;
+ GeglNode *gradient3;
+ GeglNode *input;
+ GeglNode *output;
+ GeglRectangle bbox;
+};
+
+struct _PhotosOperationInstaVignetteClass
+{
+ GeglOperationMetaClass parent_class;
+};
+
+
+G_DEFINE_TYPE (PhotosOperationInstaVignette, photos_operation_insta_vignette, GEGL_TYPE_OPERATION_META);
+
+
+static void
+photos_operation_insta_vignette_setup (PhotosOperationInstaVignette *self)
+{
+ gdouble height_half;
+ gdouble width_half;
+ gdouble radius;
+ gdouble radius65;
+ gdouble x;
+ gdouble y;
+
+ height_half = (gdouble) self->bbox.height / 2.0;
+ width_half = (gdouble) self->bbox.width / 2.0;
+ radius = sqrt (height_half * height_half + width_half * width_half);
+ radius65 = 0.65 * radius;
+ x = width_half + (gdouble) self->bbox.x;
+ y = height_half + (gdouble) self->bbox.y;
+ gegl_node_set (self->gradient1, "r0", radius65, "r1", radius, "x", x, "y", y, NULL);
+ gegl_node_set (self->gradient2, "r0", 0.0, "r1", radius65, "x", x, "y", y, NULL);
+ gegl_node_set (self->gradient3, "r0", radius65, "r1", radius, "x", x, "y", y, NULL);
+
+ gegl_node_set (self->crop1,
+ "height", (gdouble) self->bbox.height,
+ "width", (gdouble) self->bbox.width,
+ "x", (gdouble) self->bbox.x,
+ "y", (gdouble) self->bbox.y,
+ NULL);
+ gegl_node_set (self->crop2,
+ "height", (gdouble) self->bbox.height,
+ "width", (gdouble) self->bbox.width,
+ "x", (gdouble) self->bbox.x,
+ "y", (gdouble) self->bbox.y,
+ NULL);
+ gegl_node_set (self->crop3,
+ "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_vignette_attach (GeglOperation *operation)
+{
+ PhotosOperationInstaVignette *self = PHOTOS_OPERATION_INSTA_VIGNETTE (operation);
+ GeglColor *color_end;
+ GeglColor *color_start;
+ GeglNode *add1;
+ GeglNode *add2;
+ GeglNode *over;
+
+ self->input = gegl_node_get_output_proxy (operation->node, "input");
+ self->output = gegl_node_get_output_proxy (operation->node, "output");
+
+ color_end = gegl_color_new ("rgba(0.0, 0.0, 0.0, 0.9)");
+ color_start = gegl_color_new ("rgba(0.0, 0.0, 0.0, 0.0)");
+ self->gradient1 = gegl_node_new_child (operation->node,
+ "operation", "photos:radial-gradient",
+ "color-end", color_end,
+ "color-start", color_start,
+ NULL);
+ g_object_unref (color_end);
+ g_object_unref (color_start);
+
+ self->crop1 = gegl_node_new_child (operation->node, "operation", "gegl:crop", NULL);
+ over = gegl_node_new_child (operation->node, "operation", "gegl:over", "srgb", TRUE, NULL);
+
+ color_end = gegl_color_new ("rgba(1.0, 1.0, 1.0, 0.0)");
+ color_start = gegl_color_new ("rgba(1.0, 1.0, 1.0, 0.1)");
+ self->gradient2 = gegl_node_new_child (operation->node,
+ "operation", "photos:radial-gradient",
+ "color-end", color_end,
+ "color-start", color_start,
+ "ignore-abyss", TRUE,
+ NULL);
+ g_object_unref (color_end);
+ g_object_unref (color_start);
+
+ self->crop2 = gegl_node_new_child (operation->node, "operation", "gegl:crop", NULL);
+ add1 = gegl_node_new_child (operation->node, "operation", "photos:add", "srgb", TRUE, NULL);
+
+ color_end = gegl_color_new ("rgba(0.0, 0.0, 0.0, 0.0)");
+ color_start = gegl_color_new ("rgba(1.0, 1.0, 1.0, 0.0)");
+ self->gradient3 = gegl_node_new_child (operation->node,
+ "operation", "photos:radial-gradient",
+ "color-end", color_end,
+ "color-start", color_start,
+ "ignore-abyss", TRUE,
+ NULL);
+ g_object_unref (color_end);
+ g_object_unref (color_start);
+
+ self->crop3 = gegl_node_new_child (operation->node, "operation", "gegl:crop", NULL);
+ add2 = gegl_node_new_child (operation->node, "operation", "photos:add", "srgb", TRUE, NULL);
+
+ gegl_node_link (self->gradient1, self->crop1);
+ gegl_node_connect_to (self->crop1, "output", over, "aux");
+
+ gegl_node_link (self->gradient2, self->crop2);
+ gegl_node_connect_to (self->crop2, "output", add1, "aux");
+ gegl_node_link (self->gradient3, self->crop3);
+ gegl_node_connect_to (self->crop3, "output", add2, "aux");
+
+ gegl_node_link_many (self->input, over, add1, add2, self->output, NULL);
+
+ gegl_operation_meta_watch_nodes (operation,
+ add1,
+ add2,
+ over,
+ self->crop1,
+ self->crop2,
+ self->crop3,
+ self->gradient1,
+ self->gradient2,
+ self->gradient3,
+ NULL);
+}
+
+
+static GeglNode *
+photos_operation_insta_vignette_detect (GeglOperation *operation, gint x, gint y)
+{
+ PhotosOperationInstaVignette *self = PHOTOS_OPERATION_INSTA_VIGNETTE (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_vignette_prepare (GeglOperation *operation)
+{
+ PhotosOperationInstaVignette *self = PHOTOS_OPERATION_INSTA_VIGNETTE (operation);
+ GeglRectangle bbox;
+
+ bbox = gegl_node_get_bounding_box (self->input);
+ if (self->bbox.height != bbox.height
+ || self->bbox.width != bbox.width
+ || self->bbox.x != bbox.x
+ || self->bbox.y != bbox.y)
+ {
+ self->bbox = bbox;
+ photos_operation_insta_vignette_setup (self);
+ }
+}
+
+
+static void
+photos_operation_insta_vignette_init (PhotosOperationInstaVignette *self)
+{
+}
+
+
+static void
+photos_operation_insta_vignette_class_init (PhotosOperationInstaVignetteClass *class)
+{
+ GeglOperationClass *operation_class = GEGL_OPERATION_CLASS (class);
+
+ operation_class->opencl_support = FALSE;
+
+ operation_class->attach = photos_operation_insta_vignette_attach;
+ operation_class->detect = photos_operation_insta_vignette_detect;
+ operation_class->prepare = photos_operation_insta_vignette_prepare;
+
+ gegl_operation_class_set_keys (operation_class,
+ "name", "photos:insta-vignette",
+ "title", "Insta Vignette",
+ "description", "Apply a vignette to an image",
+ "categories", "hidden",
+ NULL);
+}
diff --git a/src/photos-operation-insta-vignette.h b/src/photos-operation-insta-vignette.h
new file mode 100644
index 0000000..661f638
--- /dev/null
+++ b/src/photos-operation-insta-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_VIGNETTE_H
+#define PHOTOS_OPERATION_INSTA_VIGNETTE_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_OPERATION_INSTA_VIGNETTE (photos_operation_insta_vignette_get_type ())
+
+#define PHOTOS_OPERATION_INSTA_VIGNETTE(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ PHOTOS_TYPE_OPERATION_INSTA_VIGNETTE, PhotosOperationInstaVignette))
+
+#define PHOTOS_IS_OPERATION_INSTA_VIGNETTE(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ PHOTOS_TYPE_OPERATION_INSTA_VIGNETTE))
+
+typedef struct _PhotosOperationInstaVignette PhotosOperationInstaVignette;
+typedef struct _PhotosOperationInstaVignetteClass PhotosOperationInstaVignetteClass;
+
+GType photos_operation_insta_vignette_get_type (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* PHOTOS_OPERATION_INSTA_VIGNETTE_H */
diff --git a/src/photos-utils.c b/src/photos-utils.c
index 4769f6d..de31bf0 100644
--- a/src/photos-utils.c
+++ b/src/photos-utils.c
@@ -45,6 +45,7 @@
#include "photos-operation-add.h"
#include "photos-operation-insta-curve.h"
#include "photos-operation-insta-filter.h"
+#include "photos-operation-insta-vignette.h"
#include "photos-operation-jpg-guess-sizes.h"
#include "photos-operation-png-guess-sizes.h"
#include "photos-operation-radial-gradient.h"
@@ -816,6 +817,7 @@ photos_utils_ensure_builtins (void)
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_INSTA_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_RADIAL_GRADIENT);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]