[gnome-photos/wip/edit: 2/4] Add PhotosPipeline



commit 220ef08f7ab31d2c1ef79f25a3c7607ef6ac1ccb
Author: Debarshi Ray <debarshir gnome org>
Date:   Sun Feb 2 21:51:18 2014 +0100

    Add PhotosPipeline

 src/Makefile.am       |    2 +
 src/photos-pipeline.c |  167 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/photos-pipeline.h |   78 +++++++++++++++++++++++
 3 files changed, 247 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 1de9a80..ebf2b8a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -145,6 +145,8 @@ gnome_photos_SOURCES = \
        photos-organize-collection-view.h \
        photos-overview-searchbar.c \
        photos-overview-searchbar.h \
+       photos-pipeline.c \
+       photos-pipeline.h \
        photos-preview-model.c \
        photos-preview-model.h \
        photos-preview-nav-buttons.c \
diff --git a/src/photos-pipeline.c b/src/photos-pipeline.c
new file mode 100644
index 0000000..82b8767
--- /dev/null
+++ b/src/photos-pipeline.c
@@ -0,0 +1,167 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2014 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 "photos-pipeline.h"
+
+
+struct _PhotosPipelinePrivate
+{
+  GeglNode *graph;
+  GeglNode *nop;
+  GeglNode *render;
+  GeglNode *translate;
+  PhotosBaseItem *item;
+};
+
+enum
+{
+  PROP_0,
+  PROP_ITEM
+};
+
+
+G_DEFINE_TYPE_WITH_PRIVATE (PhotosPipeline, photos_pipeline, G_TYPE_OBJECT);
+
+
+static void
+photos_pipeline_dispose (GObject *object)
+{
+  PhotosPipeline *self = PHOTOS_PIPELINE (object);
+  PhotosPipelinePrivate *priv = self->priv;
+
+  g_clear_object (&priv->graph);
+
+  G_OBJECT_CLASS (photos_pipeline_parent_class)->dispose (object);
+}
+
+
+static void
+photos_pipeline_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+{
+  PhotosPipeline *self = PHOTOS_PIPELINE (object);
+  PhotosPipelinePrivate *priv = self->priv;
+
+  switch (prop_id)
+    {
+    case PROP_ITEM:
+      priv->item = PHOTOS_BASE_ITEM (g_value_get_object (value)); /* self is owned by item */
+      g_object_add_weak_pointer (G_OBJECT (priv->item), (gpointer *) &priv->item);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+
+static void
+photos_pipeline_init (PhotosPipeline *self)
+{
+  PhotosPipelinePrivate *priv;
+  GeglNode *input;
+  GeglNode *output;
+
+  self->priv = photos_pipeline_get_instance_private (self);
+  priv = self->priv;
+
+  priv->graph = gegl_node_new ();
+  input = gegl_node_get_input_proxy (priv->graph, "input");
+  output = gegl_node_get_output_proxy (priv->graph, "output");
+
+  priv->nop = gegl_node_new_child (priv->graph, "operation", "gegl:nop", NULL);
+  priv->render = priv->nop;
+
+  priv->translate = gegl_node_new_child (priv->graph, "operation", "gegl:translate", "x", 0.0, "y", 0.0, 
NULL);
+
+  gegl_node_link_many (input, priv->render, priv->translate, output, NULL);
+}
+
+
+static void
+photos_pipeline_class_init (PhotosPipelineClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+  object_class->dispose = photos_pipeline_dispose;
+  object_class->set_property = photos_pipeline_set_property;
+
+  g_object_class_install_property (object_class,
+                                   PROP_ITEM,
+                                   g_param_spec_object ("item",
+                                                        "PhotosBaseItem object",
+                                                        "The item being processed by this pipeline.",
+                                                        PHOTOS_TYPE_BASE_ITEM,
+                                                        G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
+}
+
+
+PhotosPipeline *
+photos_pipeline_new (PhotosBaseItem *item)
+{
+  return g_object_new (PHOTOS_TYPE_PIPELINE, "item", item, NULL);
+}
+
+
+void
+photos_pipeline_add_operation (PhotosPipeline *self, PhotosOperation *operation)
+{
+  PhotosPipelinePrivate *priv = self->priv;
+  GeglNode *node;
+  GeglNode *output;
+  GeglRectangle bbox;
+  double x = 0.0;
+  double y = 0.0;
+
+  g_return_if_fail (priv->item != NULL);
+
+  node = photos_operation_get_node (operation);
+  bbox = photos_base_item_get_bbox (priv->item);
+
+  gegl_node_disconnect (priv->translate, "input");
+
+  gegl_node_link (priv->render, node);
+  priv->render = node;
+
+  bbox = gegl_node_get_bounding_box (priv->render);
+  if (bbox.x != 0)
+    x = 0.0 - bbox.x;
+  if (bbox.y != 0)
+    y = 0.0 - bbox.y;
+
+  gegl_node_set (priv->translate, "origin-x", 0.0, "origin-y", 0.0, "x", x, "y", y, NULL);
+  gegl_node_link (priv->render, priv->translate);
+
+  output = gegl_node_get_output_proxy (priv->graph, "output");
+  gegl_node_process (output);
+
+  gegl_node_add_child (priv->graph, node);
+  g_object_unref (node);
+}
+
+
+GeglNode *
+photos_pipeline_get_graph (PhotosPipeline *self)
+{
+  return self->priv->graph;
+}
diff --git a/src/photos-pipeline.h b/src/photos-pipeline.h
new file mode 100644
index 0000000..75d3f09
--- /dev/null
+++ b/src/photos-pipeline.h
@@ -0,0 +1,78 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2014 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_PIPELINE_H
+#define PHOTOS_PIPELINE_H
+
+#include <gegl.h>
+
+#include "photos-base-item.h"
+#include "photos-operation.h"
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_PIPELINE (photos_pipeline_get_type ())
+
+#define PHOTOS_PIPELINE(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+   PHOTOS_TYPE_PIPELINE, PhotosPipeline))
+
+#define PHOTOS_PIPELINE_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST ((klass), \
+   PHOTOS_TYPE_PIPELINE, PhotosPipelineClass))
+
+#define PHOTOS_IS_PIPELINE(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+   PHOTOS_TYPE_PIPELINE))
+
+#define PHOTOS_IS_PIPELINE_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+   PHOTOS_TYPE_PIPELINE))
+
+#define PHOTOS_PIPELINE_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+   PHOTOS_TYPE_PIPELINE, PhotosPipelineClass))
+
+typedef struct _PhotosPipeline        PhotosPipeline;
+typedef struct _PhotosPipelineClass   PhotosPipelineClass;
+typedef struct _PhotosPipelinePrivate PhotosPipelinePrivate;
+
+struct _PhotosPipeline
+{
+  GObject parent_instance;
+  PhotosPipelinePrivate *priv;
+};
+
+struct _PhotosPipelineClass
+{
+  GObjectClass parent_class;
+};
+
+GType                  photos_pipeline_get_type               (void) G_GNUC_CONST;
+
+PhotosPipeline        *photos_pipeline_new                    (PhotosBaseItem *item);
+
+void                   photos_pipeline_add_operation          (PhotosPipeline *self, PhotosOperation 
*operation);
+
+GeglNode              *photos_pipeline_get_graph              (PhotosPipeline *self);
+
+G_END_DECLS
+
+#endif /* PHOTOS_PIPELINE_H */


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