[gnome-photos/wip/rishi/buffer-decoder: 1/8] Add PhotosGeglBufferCodec



commit f70eb8e753994b6c57dfa441668019c4297f4a15
Author: Debarshi Ray <debarshir gnome org>
Date:   Sun Apr 29 00:20:00 2018 +0200

    Add PhotosGeglBufferCodec
    
    https://gitlab.gnome.org/GNOME/gnome-photos/issues/63

 src/Makefile.am                |   6 +
 src/meson.build                |  17 ++-
 src/photos-gegl-buffer-codec.c | 330 +++++++++++++++++++++++++++++++++++++++++
 src/photos-gegl-buffer-codec.h |  81 ++++++++++
 src/photos-gegl.c              |  22 ++-
 src/photos-gegl.h              |   4 +-
 src/photos-marshalers.list     |   1 +
 7 files changed, 451 insertions(+), 10 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 3e984eb5..3798d4b4 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -104,6 +104,8 @@ gnome_photos_SOURCES = \
        photos-flickr-item.h \
        photos-gegl.c \
        photos-gegl.h \
+       photos-gegl-buffer-codec.c \
+       photos-gegl-buffer-codec.h \
        photos-gesture-zoom.c \
        photos-gesture-zoom.h \
        photos-glib.c \
@@ -301,6 +303,8 @@ gnome_photos_SOURCES = \
        $(NULL)
 
 gnome_photos_thumbnailer_built_sources = \
+       photos-marshalers.c \
+       photos-marshalers.h \
        photos-resources-gegl.c \
        photos-resources-gegl.h \
        photos-thumbnailer-dbus.c \
@@ -320,6 +324,8 @@ gnome_photos_thumbnailer_SOURCES = \
        photos-error.h \
        photos-gegl.c \
        photos-gegl.h \
+       photos-gegl-buffer-codec.c \
+       photos-gegl-buffer-codec.h \
        photos-glib.c \
        photos-glib.h \
        photos-jpeg-count.c \
diff --git a/src/meson.build b/src/meson.build
index 88dfc4ba..0313bcf4 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -2,6 +2,7 @@ common_sources = files(
   'photos-debug.c',
   'photos-error.c',
   'photos-gegl.c',
+  'photos-gegl-buffer-codec.c',
   'photos-glib.c',
   'photos-jpeg-count.c',
   'photos-operation-insta-curve.c',
@@ -34,6 +35,14 @@ common_sources += gnome.mkenums(
   h_template: enum + '.h.template',
 )
 
+marshal = 'photos-marshalers'
+
+common_sources += gnome.genmarshal(
+  marshal,
+  sources: marshal + '.list',
+  prefix: '_photos_marshal',
+)
+
 resource_data = files('../data/vignette.png')
 
 common_sources += gnome.compile_resources(
@@ -210,14 +219,6 @@ sources += custom_target(
   command: [photos_generate_about, '--body', artists, authors],
 )
 
-marshal = 'photos-marshalers'
-
-sources += gnome.genmarshal(
-  marshal,
-  sources: marshal + '.list',
-  prefix: '_photos_marshal',
-)
-
 resource_data = files(
   '../data/Adwaita.css',
   '../data/dnd-counter.svg',
diff --git a/src/photos-gegl-buffer-codec.c b/src/photos-gegl-buffer-codec.c
new file mode 100644
index 00000000..c15e9a03
--- /dev/null
+++ b/src/photos-gegl-buffer-codec.c
@@ -0,0 +1,330 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2018 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+/* Based on code from:
+ *   + GdkPixbuf
+ */
+
+
+#include "config.h"
+
+#include "photos-gegl-buffer-codec.h"
+#include "photos-marshalers.h"
+
+
+struct _PhotosGeglBufferCodecPrivate
+{
+  gboolean decoding;
+  gboolean used;
+  guint height;
+  guint width;
+};
+
+enum
+{
+  PROP_0,
+  PROP_BUFFER,
+  PROP_CAN_SET_SIZE,
+  PROP_HEIGHT,
+  PROP_WIDTH
+};
+
+enum
+{
+  SIZE_PREPARED,
+  LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+
+G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (PhotosGeglBufferCodec, photos_gegl_buffer_codec, G_TYPE_OBJECT);
+
+
+static void
+photos_gegl_buffer_codec_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+{
+  PhotosGeglBufferCodec *self = PHOTOS_GEGL_BUFFER_CODEC (object);
+  PhotosGeglBufferCodecPrivate *priv;
+
+  priv = photos_gegl_buffer_codec_get_instance_private (self);
+
+  switch (prop_id)
+    {
+    case PROP_HEIGHT:
+      g_value_set_uint (value, priv->height);
+      break;
+
+    case PROP_WIDTH:
+      g_value_set_uint (value, priv->width);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+
+static void
+photos_gegl_buffer_codec_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec 
*pspec)
+{
+  PhotosGeglBufferCodec *self = PHOTOS_GEGL_BUFFER_CODEC (object);
+
+  switch (prop_id)
+    {
+    case PROP_HEIGHT:
+      {
+        guint height;
+
+        height = g_value_get_uint (value);
+        photos_gegl_buffer_codec_set_height (self, height);
+        break;
+      }
+
+    case PROP_WIDTH:
+      {
+        guint width;
+
+        width = g_value_get_uint (value);
+        photos_gegl_buffer_codec_set_width (self, width);
+        break;
+      }
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+
+static void
+photos_gegl_buffer_codec_init (PhotosGeglBufferCodec *self)
+{
+}
+
+
+static void
+photos_gegl_buffer_codec_class_init (PhotosGeglBufferCodecClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+  object_class->get_property = photos_gegl_buffer_codec_get_property;
+  object_class->set_property = photos_gegl_buffer_codec_set_property;
+
+  g_object_class_install_property (object_class,
+                                   PROP_BUFFER,
+                                   g_param_spec_object ("buffer",
+                                                        "Buffer",
+                                                        "The GeglBuffer being loaded",
+                                                        GEGL_TYPE_BUFFER,
+                                                        G_PARAM_READABLE
+                                                        | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_property (object_class,
+                                   PROP_CAN_SET_SIZE,
+                                   g_param_spec_boolean ("can-set-size",
+                                                         "Can set size",
+                                                         "Whether the desired size of the GeglBuffer can be "
+                                                         "changed, or not",
+                                                         FALSE,
+                                                         G_PARAM_READABLE
+                                                         | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_property (object_class,
+                                   PROP_HEIGHT,
+                                   g_param_spec_uint ("height",
+                                                      "Height",
+                                                      "The desired height of the GeglBuffer being loaded",
+                                                      0,
+                                                      G_MAXUINT,
+                                                      0,
+                                                      G_PARAM_EXPLICIT_NOTIFY
+                                                      | G_PARAM_READWRITE
+                                                      | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_property (object_class,
+                                   PROP_WIDTH,
+                                   g_param_spec_uint ("width",
+                                                      "Width",
+                                                      "The desired width of the GeglBuffer being loaded",
+                                                      0,
+                                                      G_MAXUINT,
+                                                      0,
+                                                      G_PARAM_EXPLICIT_NOTIFY
+                                                      | G_PARAM_READWRITE
+                                                      | G_PARAM_STATIC_STRINGS));
+
+  signals[SIZE_PREPARED] = g_signal_new ("size-prepared",
+                                         G_TYPE_FROM_CLASS (class),
+                                         G_SIGNAL_RUN_LAST,
+                                         G_STRUCT_OFFSET (PhotosGeglBufferCodecClass, size_prepared),
+                                         NULL, /* accumulator */
+                                         NULL, /* accu_data */
+                                         _photos_marshal_VOID__UINT_UINT,
+                                         G_TYPE_NONE,
+                                         2,
+                                         G_TYPE_UINT,
+                                         G_TYPE_UINT);
+}
+
+
+GeglBuffer *
+photos_gegl_buffer_codec_get_buffer (PhotosGeglBufferCodec *self)
+{
+  g_return_val_if_fail (PHOTOS_IS_GEGL_BUFFER_CODEC (self), NULL);
+  return PHOTOS_GEGL_BUFFER_CODEC_GET_CLASS (self)->get_buffer (self);
+}
+
+
+gboolean
+photos_gegl_buffer_codec_get_can_set_size (PhotosGeglBufferCodec *self)
+{
+  gboolean can_set_size;
+
+  g_return_val_if_fail (PHOTOS_IS_GEGL_BUFFER_CODEC (self), FALSE);
+
+  g_object_get (self, "can-set-size", &can_set_size, NULL);
+  return can_set_size;
+}
+
+
+guint
+photos_gegl_buffer_codec_get_height (PhotosGeglBufferCodec *self)
+{
+  PhotosGeglBufferCodecPrivate *priv;
+
+  g_return_val_if_fail (PHOTOS_IS_GEGL_BUFFER_CODEC (self), 0);
+  priv = photos_gegl_buffer_codec_get_instance_private (self);
+
+  return priv->height;
+}
+
+
+guint
+photos_gegl_buffer_codec_get_width (PhotosGeglBufferCodec *self)
+{
+  PhotosGeglBufferCodecPrivate *priv;
+
+  g_return_val_if_fail (PHOTOS_IS_GEGL_BUFFER_CODEC (self), 0);
+  priv = photos_gegl_buffer_codec_get_instance_private (self);
+
+  return priv->width;
+}
+
+
+gboolean
+photos_gegl_buffer_codec_load_begin (PhotosGeglBufferCodec *self, GError **error)
+{
+  PhotosGeglBufferCodecPrivate *priv;
+  gboolean ret_val;
+
+  g_return_val_if_fail (PHOTOS_IS_GEGL_BUFFER_CODEC (self), FALSE);
+  priv = photos_gegl_buffer_codec_get_instance_private (self);
+
+  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+  g_return_val_if_fail (!priv->decoding, FALSE);
+  g_return_val_if_fail (!priv->used, FALSE);
+
+  ret_val = PHOTOS_GEGL_BUFFER_CODEC_GET_CLASS (self)->load_begin (self, error);
+
+  if (ret_val)
+    priv->decoding = TRUE;
+
+  priv->used = TRUE;
+
+  return ret_val;
+}
+
+
+gboolean
+photos_gegl_buffer_codec_load_increment (PhotosGeglBufferCodec *self,
+                                         const guchar *buf,
+                                         gsize count,
+                                         GError **error)
+{
+  PhotosGeglBufferCodecPrivate *priv;
+  gboolean ret_val;
+
+  g_return_val_if_fail (PHOTOS_IS_GEGL_BUFFER_CODEC (self), FALSE);
+  priv = photos_gegl_buffer_codec_get_instance_private (self);
+
+  g_return_val_if_fail (buf != NULL, FALSE);
+  g_return_val_if_fail (count > 0, FALSE);
+  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+  g_return_val_if_fail (priv->decoding, FALSE);
+
+  ret_val = PHOTOS_GEGL_BUFFER_CODEC_GET_CLASS (self)->load_increment (self, buf, count, error);
+  return ret_val;
+}
+
+
+gboolean
+photos_gegl_buffer_codec_load_stop (PhotosGeglBufferCodec *self, GError **error)
+{
+  PhotosGeglBufferCodecPrivate *priv;
+  gboolean ret_val;
+
+  g_return_val_if_fail (PHOTOS_IS_GEGL_BUFFER_CODEC (self), FALSE);
+  priv = photos_gegl_buffer_codec_get_instance_private (self);
+
+  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+  g_return_val_if_fail (priv->decoding, FALSE);
+
+  ret_val = PHOTOS_GEGL_BUFFER_CODEC_GET_CLASS (self)->load_stop (self, error);
+
+  priv->decoding = FALSE;
+
+  return ret_val;
+}
+
+
+void
+photos_gegl_buffer_codec_set_height (PhotosGeglBufferCodec *self, guint height)
+{
+  PhotosGeglBufferCodecPrivate *priv;
+
+  g_return_if_fail (PHOTOS_IS_GEGL_BUFFER_CODEC (self));
+  priv = photos_gegl_buffer_codec_get_instance_private (self);
+
+  g_return_if_fail (photos_gegl_buffer_codec_get_can_set_size (self));
+
+  if (priv->height != height)
+    {
+      priv->height = height;
+      g_object_notify (G_OBJECT (self), "height");
+    }
+}
+
+
+void
+photos_gegl_buffer_codec_set_width (PhotosGeglBufferCodec *self, guint width)
+{
+  PhotosGeglBufferCodecPrivate *priv;
+
+  g_return_if_fail (PHOTOS_IS_GEGL_BUFFER_CODEC (self));
+  priv = photos_gegl_buffer_codec_get_instance_private (self);
+
+  g_return_if_fail (photos_gegl_buffer_codec_get_can_set_size (self));
+
+  if (priv->width != width)
+    {
+      priv->width = width;
+      g_object_notify (G_OBJECT (self), "width");
+    }
+}
diff --git a/src/photos-gegl-buffer-codec.h b/src/photos-gegl-buffer-codec.h
new file mode 100644
index 00000000..e5341994
--- /dev/null
+++ b/src/photos-gegl-buffer-codec.h
@@ -0,0 +1,81 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2018 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+/* Based on code from:
+ *   + GdkPixbuf
+ */
+
+#ifndef PHOTOS_GEGL_BUFFER_CODEC_H
+#define PHOTOS_GEGL_BUFFER_CODEC_H
+
+#include <gegl.h>
+
+G_BEGIN_DECLS
+
+#define PHOTOS_GEGL_BUFFER_CODEC_EXTENSION_POINT_NAME "photos-gegl-buffer-codec"
+
+#define PHOTOS_TYPE_GEGL_BUFFER_CODEC (photos_gegl_buffer_codec_get_type ())
+G_DECLARE_DERIVABLE_TYPE (PhotosGeglBufferCodec, photos_gegl_buffer_codec, PHOTOS, GEGL_BUFFER_CODEC, 
GObject);
+
+typedef struct _PhotosGeglBufferCodecPrivate PhotosGeglBufferCodecPrivate;
+
+struct _PhotosGeglBufferCodecClass
+{
+  GObjectClass parent_class;
+
+  GStrv mime_types;
+
+  /* virtual methods */
+  GeglBuffer  *(*get_buffer)                (PhotosGeglBufferCodec *self);
+  gboolean     (*load_begin)                (PhotosGeglBufferCodec *self, GError **error);
+  gboolean     (*load_increment)            (PhotosGeglBufferCodec *self,
+                                             const guchar *buf,
+                                             gsize count,
+                                             GError **error);
+  gboolean     (*load_stop)                 (PhotosGeglBufferCodec *self, GError **error);
+
+  /* signals */
+  void         (*size_prepared)             (PhotosGeglBufferCodec *self, gint width, gint height);
+};
+
+GeglBuffer         *photos_gegl_buffer_codec_get_buffer                (PhotosGeglBufferCodec *self);
+
+gboolean            photos_gegl_buffer_codec_get_can_set_size          (PhotosGeglBufferCodec *self);
+
+guint               photos_gegl_buffer_codec_get_height                (PhotosGeglBufferCodec *self);
+
+guint               photos_gegl_buffer_codec_get_width                 (PhotosGeglBufferCodec *self);
+
+gboolean            photos_gegl_buffer_codec_load_begin                (PhotosGeglBufferCodec *self,
+                                                                        GError **error);
+
+gboolean            photos_gegl_buffer_codec_load_increment            (PhotosGeglBufferCodec *self,
+                                                                        const guchar *buf,
+                                                                        gsize count,
+                                                                        GError **error);
+
+gboolean            photos_gegl_buffer_codec_load_stop                 (PhotosGeglBufferCodec *self,
+                                                                        GError **error);
+
+void                photos_gegl_buffer_codec_set_height                (PhotosGeglBufferCodec *self, guint 
height);
+
+void                photos_gegl_buffer_codec_set_width                 (PhotosGeglBufferCodec *self, guint 
width);
+
+G_END_DECLS
+
+#endif /* PHOTOS_GEGL_BUFFER_CODEC_H */
diff --git a/src/photos-gegl.c b/src/photos-gegl.c
index 8b3909a8..389bbda3 100644
--- a/src/photos-gegl.c
+++ b/src/photos-gegl.c
@@ -1,6 +1,6 @@
 /*
  * Photos - access, organize and share your photos on GNOME
- * Copyright © 2013 – 2017 Red Hat, Inc.
+ * Copyright © 2013 – 2018 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
@@ -25,6 +25,7 @@
 
 #include "photos-debug.h"
 #include "photos-gegl.h"
+#include "photos-gegl-buffer-codec.h"
 #include "photos-operation-insta-curve.h"
 #include "photos-operation-insta-filter.h"
 #include "photos-operation-insta-hefe.h"
@@ -553,6 +554,8 @@ photos_gegl_ensure_builtins (void)
 {
   static gsize once_init_value = 0;
 
+  photos_gegl_ensure_extension_points ();
+
   if (g_once_init_enter (&once_init_value))
     {
       g_type_ensure (PHOTOS_TYPE_OPERATION_INSTA_CURVE);
@@ -570,6 +573,23 @@ photos_gegl_ensure_builtins (void)
 }
 
 
+void
+photos_gegl_ensure_extension_points (void)
+{
+  static gsize once_init_value = 0;
+
+  if (g_once_init_enter (&once_init_value))
+    {
+      GIOExtensionPoint *extension_point;
+
+      extension_point = g_io_extension_point_register (PHOTOS_GEGL_BUFFER_CODEC_EXTENSION_POINT_NAME);
+      g_io_extension_point_set_required_type (extension_point, PHOTOS_TYPE_GEGL_BUFFER_CODEC);
+
+      g_once_init_leave (&once_init_value, 1);
+    }
+}
+
+
 GeglBuffer *
 photos_gegl_get_buffer_from_node (GeglNode *node, const Babl *format)
 {
diff --git a/src/photos-gegl.h b/src/photos-gegl.h
index d902300b..cc675f22 100644
--- a/src/photos-gegl.h
+++ b/src/photos-gegl.h
@@ -1,6 +1,6 @@
 /*
  * Photos - access, organize and share your photos on GNOME
- * Copyright © 2013 – 2017 Red Hat, Inc.
+ * Copyright © 2013 – 2018 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
@@ -45,6 +45,8 @@ GeglBuffer      *photos_gegl_dup_buffer_from_node         (GeglNode *node, const
 
 void             photos_gegl_ensure_builtins              (void);
 
+void             photos_gegl_ensure_extension_points      (void);
+
 GeglBuffer      *photos_gegl_get_buffer_from_node         (GeglNode *node, const Babl *format);
 
 void             photos_gegl_init                         (void);
diff --git a/src/photos-marshalers.list b/src/photos-marshalers.list
index ea1cd27e..ed85ea30 100644
--- a/src/photos-marshalers.list
+++ b/src/photos-marshalers.list
@@ -3,3 +3,4 @@ VOID:DOUBLE,ENUM
 VOID:ENUM,ENUM
 VOID:INT,INT
 VOID:STRING,STRING
+VOID:UINT,UINT
\ No newline at end of file


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