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



commit ca7f617e08368208a229ca65b068600d4f9d20e7
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 |  84 +++++++++++
 src/photos-gegl.c              |  22 ++-
 src/photos-gegl.h              |   4 +-
 src/photos-marshalers.list     |   1 +
 7 files changed, 454 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 40843751..29c83a78 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -23,6 +23,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',
@@ -54,6 +55,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(
@@ -231,14 +240,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..0f475155
--- /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;
+  gdouble height;
+  gdouble 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_double (value, priv->height);
+      break;
+
+    case PROP_WIDTH:
+      g_value_set_double (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:
+      {
+        gdouble height;
+
+        height = g_value_get_double (value);
+        photos_gegl_buffer_codec_set_height (self, height);
+        break;
+      }
+
+    case PROP_WIDTH:
+      {
+        gdouble width;
+
+        width = g_value_get_double (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_double ("height",
+                                                        "Height",
+                                                        "The desired height of the GeglBuffer being loaded",
+                                                        -1.0,
+                                                        G_MAXDOUBLE,
+                                                        -1.0,
+                                                        G_PARAM_EXPLICIT_NOTIFY
+                                                        | G_PARAM_READWRITE
+                                                        | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_property (object_class,
+                                   PROP_WIDTH,
+                                   g_param_spec_double ("width",
+                                                        "Width",
+                                                        "The desired width of the GeglBuffer being loaded",
+                                                        -1.0,
+                                                        G_MAXDOUBLE,
+                                                        -1.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;
+}
+
+
+gdouble
+photos_gegl_buffer_codec_get_height (PhotosGeglBufferCodec *self)
+{
+  PhotosGeglBufferCodecPrivate *priv;
+
+  g_return_val_if_fail (PHOTOS_IS_GEGL_BUFFER_CODEC (self), 0.0);
+  priv = photos_gegl_buffer_codec_get_instance_private (self);
+
+  return priv->height;
+}
+
+
+gdouble
+photos_gegl_buffer_codec_get_width (PhotosGeglBufferCodec *self)
+{
+  PhotosGeglBufferCodecPrivate *priv;
+
+  g_return_val_if_fail (PHOTOS_IS_GEGL_BUFFER_CODEC (self), 0.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, gdouble 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, gdouble 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..d42524c3
--- /dev/null
+++ b/src/photos-gegl-buffer-codec.h
@@ -0,0 +1,84 @@
+/*
+ * 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>
+#include <glib-object.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);
+
+gdouble             photos_gegl_buffer_codec_get_height                (PhotosGeglBufferCodec *self);
+
+gdouble             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,
+                                                                        gdouble height);
+
+void                photos_gegl_buffer_codec_set_width                 (PhotosGeglBufferCodec *self,
+                                                                        gdouble width);
+
+G_END_DECLS
+
+#endif /* PHOTOS_GEGL_BUFFER_CODEC_H */
diff --git a/src/photos-gegl.c b/src/photos-gegl.c
index 5de85a8d..357b3375 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 5e49169c..aabc06ed 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]