[gnome-photos/wip/rishi/buffer-decoder: 3/12] Add PhotosGeglBufferCodec



commit 89f762ee24bd27656e536a5af7a7e633d2e29214
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                |  20 ++-
 src/photos-gegl-buffer-codec.c | 326 +++++++++++++++++++++++++++++++++++++++++
 src/photos-gegl-buffer-codec.h |  80 ++++++++++
 src/photos-gegl.c              |  20 +++
 src/photos-gegl.h              |   2 +
 src/photos-marshalers.list     |   1 +
 7 files changed, 445 insertions(+), 10 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 5c63c717..3f63ad24 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -7,6 +7,8 @@ libexec_PROGRAMS = gnome-photos-thumbnailer
 libgnome_photos_la_built_sources = \
        photos-enums-gegl.c \
        photos-enums-gegl.h \
+       photos-marshalers.c \
+       photos-marshalers.h \
        photos-resources-gegl.c \
        photos-resources-gegl.h \
        photos-thumbnailer-dbus.c \
@@ -24,6 +26,8 @@ libgnome_photos_la_SOURCES = \
        photos-error.h \
        photos-gegl.c \
        photos-gegl.h \
+       photos-gegl-buffer-codec.c \
+       photos-gegl-buffer-codec.h \
        photos-jpeg-count.c \
        photos-jpeg-count.h \
        photos-operation-insta-common.h \
@@ -95,8 +99,6 @@ gnome_photos_built_sources = \
        photos-dleyna-renderer-push-host.h \
        photos-gom-miner.c \
        photos-gom-miner.h \
-       photos-marshalers.c \
-       photos-marshalers.h \
        photos-mpris-player.c \
        photos-mpris-player.h \
        photos-resources.c \
diff --git a/src/meson.build b/src/meson.build
index a4f25576..fedc9fd0 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -4,6 +4,7 @@ sources = files(
   'photos-debug.c',
   'photos-error.c',
   'photos-gegl.c',
+  'photos-gegl-buffer-codec.c',
   'photos-jpeg-count.c',
   'photos-operation-insta-curve.c',
   'photos-operation-insta-filter.c',
@@ -52,6 +53,17 @@ libgnome_photos_built_sources_enums = gnome.mkenums(
 libgnome_photos_built_headers += libgnome_photos_built_sources_enums[1]
 sources += libgnome_photos_built_sources_enums
 
+marshal = 'photos-marshalers'
+
+libgnome_photos_built_sources_marshalers = gnome.genmarshal(
+  marshal,
+  sources: marshal + '.list',
+  prefix: '_photos_marshal',
+)
+
+libgnome_photos_built_headers += libgnome_photos_built_sources_marshalers[1]
+sources += libgnome_photos_built_sources_marshalers
+
 resource_data = files('../data/vignette.png')
 
 libgnome_photos_built_sources_resources = gnome.compile_resources(
@@ -255,14 +267,6 @@ sources += gnome.mkenums(
   h_template: enum + '.h.template',
 )
 
-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..595d807d
--- /dev/null
+++ b/src/photos-gegl-buffer-codec.c
@@ -0,0 +1,326 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2018 – 2019 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, GBytes *bytes, 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 (bytes != NULL, 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, bytes, 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..c4ce1c51
--- /dev/null
+++ b/src/photos-gegl-buffer-codec.h
@@ -0,0 +1,80 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2018 – 2019 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, GBytes *bytes, 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,
+                                                                        GBytes *bytes,
+                                                                        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 30e36927..7be479a0 100644
--- a/src/photos-gegl.c
+++ b/src/photos-gegl.c
@@ -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"
@@ -629,6 +630,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);
@@ -646,6 +649,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 a2b05215..db0c1ff7 100644
--- a/src/photos-gegl.h
+++ b/src/photos-gegl.h
@@ -49,6 +49,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 47396eec..f627a97d 100644
--- a/src/photos-marshalers.list
+++ b/src/photos-marshalers.list
@@ -4,3 +4,4 @@ VOID:ENUM,ENUM
 VOID:INT,INT
 VOID:STRING,ENUM
 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]