[gnome-photos/wip/rishi/hefe: 2/3] Add insta vignette
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/hefe: 2/3] Add insta vignette
- Date: Thu, 14 Jan 2016 08:50:46 +0000 (UTC)
commit 2e9311a9213822693b42c63c11b2550354651b0b
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 | 206 +++++++++++++++++++++++++++++++++
src/photos-operation-insta-vignette.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 8731021..f21f9fe 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -132,6 +132,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..14acaad
--- /dev/null
+++ b/src/photos-operation-insta-vignette.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 <math.h>
+
+#include <babl/babl.h>
+#include <gegl.h>
+#include <gegl-plugin.h>
+
+#include "photos-operation-insta-vignette.h"
+
+
+struct _PhotosOperationInstaVignette
+{
+ GeglOperationMeta parent_instance;
+ GList *nodes;
+ 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)
+{
+ GList *l;
+ GeglColor *color_end;
+ GeglColor *color_start;
+ GeglNode *crop;
+ GeglNode *gradient;
+ GeglNode *over;
+ GeglOperation *operation = GEGL_OPERATION (self);
+ gdouble r0;
+ gdouble r1;
+ gdouble x;
+ gdouble y;
+
+ g_list_free_full (self->nodes, g_object_unref);
+ self->nodes = NULL;
+
+ 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)");
+ x = (gdouble) self->bbox.width / 2.0;
+ y = (gdouble) self->bbox.height / 2.0;
+ r1 = sqrt (x * x + y * y);
+ r0 = 0.65 * r1;
+
+ gradient = gegl_node_new_child (operation->node,
+ "operation", "photos:radial-gradient",
+ "color-end", color_end,
+ "color-start", color_start,
+ "r0", r0,
+ "r1", r1,
+ "x", x,
+ "y", y,
+ NULL);
+ self->nodes = g_list_prepend (self->nodes, gradient);
+
+ crop = gegl_node_new_child (operation->node,
+ "operation", "gegl:crop",
+ "height", self->bbox.height,
+ "width", self->bbox.width,
+ "x", 0.0,
+ "y", 0.0,
+ NULL);
+ self->nodes = g_list_prepend (self->nodes, crop);
+
+ over = gegl_node_new_child (operation->node,
+ "operation", "gegl:over",
+ "srgb", TRUE,
+ NULL);
+ self->nodes = g_list_prepend (self->nodes, over);
+
+ gegl_node_link (gradient, crop);
+ gegl_node_connect_to (crop, "output", over, "aux");
+ gegl_node_link_many (self->input, over, self->output, NULL);
+
+ for (l = self->nodes; l != NULL; l = l->next)
+ {
+ GeglNode *node = GEGL_NODE (l->data);
+ gegl_operation_meta_watch_node (operation, node);
+ }
+
+ g_object_unref (color_end);
+ g_object_unref (color_start);
+}
+
+
+static void
+photos_operation_insta_vignette_attach (GeglOperation *operation)
+{
+ PhotosOperationInstaVignette *self = PHOTOS_OPERATION_INSTA_VIGNETTE (operation);
+
+ self->input = gegl_node_get_output_proxy (operation->node, "input");
+ self->output = gegl_node_get_output_proxy (operation->node, "output");
+ photos_operation_insta_vignette_setup (self);
+}
+
+
+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);
+ const Babl *format;
+ GeglRectangle *bbox_tmp;
+ GeglRectangle bbox;
+
+ bbox_tmp = gegl_operation_source_get_bounding_box (operation, "input");
+ if (bbox_tmp == NULL)
+ return;
+
+ bbox = *bbox_tmp;
+ 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);
+ }
+
+ format = babl_format ("R'aG'aB'aA float");
+ gegl_operation_set_format (operation, "input", format);
+ gegl_operation_set_format (operation, "output", format);
+}
+
+
+static void
+photos_operation_insta_vignette_finalize (GObject *object)
+{
+ PhotosOperationInstaVignette *self = PHOTOS_OPERATION_INSTA_VIGNETTE (object);
+
+ g_list_free (self->nodes);
+
+ G_OBJECT_CLASS (photos_operation_insta_vignette_parent_class)->finalize (object);
+}
+
+
+static void
+photos_operation_insta_vignette_init (PhotosOperationInstaVignette *self)
+{
+}
+
+
+static void
+photos_operation_insta_vignette_class_init (PhotosOperationInstaVignetteClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+ GeglOperationClass *operation_class = GEGL_OPERATION_CLASS (class);
+
+ operation_class->opencl_support = FALSE;
+
+ object_class->finalize = photos_operation_insta_vignette_finalize;
+ 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 6afa818..a3bd2d2 100644
--- a/src/photos-utils.c
+++ b/src/photos-utils.c
@@ -44,6 +44,7 @@
#include "photos-media-server-item.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"
@@ -814,6 +815,7 @@ 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_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]