[gnome-photos/wip/rishi/buffer-decoder: 5/7] Add PhotosGeglBufferCodecRaw
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/buffer-decoder: 5/7] Add PhotosGeglBufferCodecRaw
- Date: Wed, 5 Jun 2019 00:03:09 +0000 (UTC)
commit 7bd3824642629772437517b44d09d9c711fc0877
Author: Debarshi Ray <debarshir gnome org>
Date: Sat Jun 1 12:49:20 2019 +0000
Add PhotosGeglBufferCodecRaw
https://gitlab.gnome.org/GNOME/gnome-photos/issues/63
src/Makefile.am | 2 +
src/meson.build | 1 +
src/photos-gegl-buffer-codec-raw.c | 228 +++++++++++++++++++++++++++++++++++++
src/photos-gegl-buffer-codec-raw.h | 35 ++++++
src/photos-gegl.c | 2 +
5 files changed, 268 insertions(+)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 0d3f6ea8..746f2904 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -32,6 +32,8 @@ libgnome_photos_la_SOURCES = \
photos-gegl-buffer-codec-jpeg.h \
photos-gegl-buffer-codec-png.c \
photos-gegl-buffer-codec-png.h \
+ photos-gegl-buffer-codec-raw.c \
+ photos-gegl-buffer-codec-raw.h \
photos-gegl-buffer-loader.c \
photos-gegl-buffer-loader.h \
photos-gegl-buffer-loader-builder.c \
diff --git a/src/meson.build b/src/meson.build
index 5752133d..42322fc8 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -7,6 +7,7 @@ sources = files(
'photos-gegl-buffer-codec.c',
'photos-gegl-buffer-codec-jpeg.c',
'photos-gegl-buffer-codec-png.c',
+ 'photos-gegl-buffer-codec-raw.c',
'photos-gegl-buffer-loader.c',
'photos-gegl-buffer-loader-builder.c',
'photos-jpeg-count.c',
diff --git a/src/photos-gegl-buffer-codec-raw.c b/src/photos-gegl-buffer-codec-raw.c
new file mode 100644
index 00000000..fa91199a
--- /dev/null
+++ b/src/photos-gegl-buffer-codec-raw.c
@@ -0,0 +1,228 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 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/>.
+ */
+
+
+#include "config.h"
+
+#include <gegl.h>
+#include <glib.h>
+#include <glib/gi18n.h>
+
+#include "photos-error.h"
+#include "photos-gegl.h"
+#include "photos-gegl-buffer-codec-raw.h"
+
+
+struct _PhotosGeglBufferCodecRaw
+{
+ PhotosGeglBufferCodec parent_instance;
+ GQueue bytes_queue;
+ gboolean can_set_size;
+ gboolean decoding;
+};
+
+enum
+{
+ PROP_0,
+ PROP_BUFFER,
+ PROP_CAN_SET_SIZE
+};
+
+
+G_DEFINE_TYPE_WITH_CODE (PhotosGeglBufferCodecRaw, photos_gegl_buffer_codec_raw,
PHOTOS_TYPE_GEGL_BUFFER_CODEC,
+ photos_gegl_ensure_extension_points ();
+ g_io_extension_point_implement (PHOTOS_GEGL_BUFFER_CODEC_EXTENSION_POINT_NAME,
+ g_define_type_id,
+ "raw",
+ 0));
+
+
+static GeglBuffer *
+photos_gegl_buffer_codec_raw_get_buffer (PhotosGeglBufferCodec *codec)
+{
+ PhotosGeglBufferCodecRaw *self = PHOTOS_GEGL_BUFFER_CODEC_RAW (codec);
+ return NULL;
+}
+
+
+static gboolean
+photos_gegl_buffer_codec_raw_load_begin (PhotosGeglBufferCodec *codec, GError **error)
+{
+ PhotosGeglBufferCodecRaw *self = PHOTOS_GEGL_BUFFER_CODEC_RAW (codec);
+
+ g_return_val_if_fail (!self->decoding, FALSE);
+
+ self->decoding = TRUE;
+
+ out:
+ return self->decoding;
+}
+
+
+static gboolean
+photos_gegl_buffer_codec_raw_load_increment (PhotosGeglBufferCodec *codec, GBytes *bytes, GError **error)
+{
+ PhotosGeglBufferCodecRaw *self = PHOTOS_GEGL_BUFFER_CODEC_RAW (codec);
+ gsize count;
+
+ g_return_val_if_fail (self->decoding, FALSE);
+
+ count = g_bytes_get_size (bytes);
+ g_return_val_if_fail (count > 0, FALSE);
+
+ g_queue_push_tail (&self->bytes_queue, g_bytes_ref (bytes));
+ return TRUE;
+}
+
+
+static gboolean
+photos_gegl_buffer_codec_raw_load_stop (PhotosGeglBufferCodec *codec, GError **error)
+{
+ PhotosGeglBufferCodecRaw *self = PHOTOS_GEGL_BUFFER_CODEC_RAW (codec);
+ g_autoptr (GBytes) bytes_flattened = NULL;
+ gboolean ret_val = FALSE;
+
+ g_return_val_if_fail (self->decoding, FALSE);
+
+ if (g_queue_is_empty (&self->bytes_queue))
+ {
+ g_set_error (error, PHOTOS_ERROR, 0, _("Premature end-of-file encountered"));
+ goto out;
+ }
+
+ {
+ GByteArray *byte_array = NULL;
+ GList *l;
+
+ {
+ GBytes *bytes = NULL;
+
+ bytes = (GBytes *) g_queue_pop_head (&self->bytes_queue);
+ byte_array = g_bytes_unref_to_array (bytes);
+ }
+
+ for (l = self->bytes_queue.head; l != NULL; l = l->next)
+ {
+ GBytes *bytes = (GBytes *) l->data;
+ gsize count;
+ const guint8 *data;
+
+ data = (const guint8 *) g_bytes_get_data (bytes, &count);
+ g_byte_array_append (byte_array, data, (guint) count);
+ }
+
+ bytes_flattened = g_byte_array_free_to_bytes (byte_array);
+ }
+
+ ret_val = TRUE;
+
+ out:
+ self->decoding = FALSE;
+ return ret_val;
+}
+
+
+static void
+photos_gegl_buffer_codec_raw_dispose (GObject *object)
+{
+ PhotosGeglBufferCodecRaw *self = PHOTOS_GEGL_BUFFER_CODEC_RAW (object);
+
+ G_OBJECT_CLASS (photos_gegl_buffer_codec_raw_parent_class)->dispose (object);
+}
+
+
+static void
+photos_gegl_buffer_codec_raw_finalize (GObject *object)
+{
+ PhotosGeglBufferCodecRaw *self = PHOTOS_GEGL_BUFFER_CODEC_RAW (object);
+
+ g_queue_foreach (&self->bytes_queue, (GFunc) g_bytes_unref, NULL);
+
+ G_OBJECT_CLASS (photos_gegl_buffer_codec_raw_parent_class)->finalize (object);
+}
+
+
+static void
+photos_gegl_buffer_codec_raw_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+{
+ PhotosGeglBufferCodecRaw *self = PHOTOS_GEGL_BUFFER_CODEC_RAW (object);
+
+ switch (prop_id)
+ {
+ case PROP_BUFFER:
+ g_value_set_object (value, NULL);
+ break;
+
+ case PROP_CAN_SET_SIZE:
+ g_value_set_boolean (value, self->can_set_size);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+
+static void
+photos_gegl_buffer_codec_raw_init (PhotosGeglBufferCodecRaw *self)
+{
+ g_queue_init (&self->bytes_queue);
+}
+
+
+static void
+photos_gegl_buffer_codec_raw_class_init (PhotosGeglBufferCodecRawClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+ PhotosGeglBufferCodecClass *buffer_codec_class = PHOTOS_GEGL_BUFFER_CODEC_CLASS (class);
+
+ {
+ GList *content_types = NULL;
+ GList *l;
+ GPtrArray *content_types_raw = NULL;
+
+ content_types = g_content_types_get_registered ();
+ content_types_raw = g_ptr_array_new ();
+ for (l = content_types; l != NULL; l = l->next)
+ {
+ const gchar *content_type = (gchar *) l->data;
+
+ if (!g_content_type_is_a (content_type, "image/x-dcraw"))
+ continue;
+
+ g_ptr_array_add (content_types_raw, (gpointer) content_type);
+ l->data = NULL;
+ }
+
+ g_ptr_array_add (content_types_raw, NULL);
+ buffer_codec_class->mime_types = (GStrv) g_ptr_array_free (content_types_raw, FALSE);
+ g_list_free_full (content_types, g_free);
+ }
+
+ object_class->dispose = photos_gegl_buffer_codec_raw_dispose;
+ object_class->finalize = photos_gegl_buffer_codec_raw_finalize;
+ object_class->get_property = photos_gegl_buffer_codec_raw_get_property;
+ buffer_codec_class->get_buffer = photos_gegl_buffer_codec_raw_get_buffer;
+ buffer_codec_class->load_begin = photos_gegl_buffer_codec_raw_load_begin;
+ buffer_codec_class->load_increment = photos_gegl_buffer_codec_raw_load_increment;
+ buffer_codec_class->load_stop = photos_gegl_buffer_codec_raw_load_stop;
+
+ g_object_class_override_property (object_class, PROP_BUFFER, "buffer");
+ g_object_class_override_property (object_class, PROP_CAN_SET_SIZE, "can-set-size");
+}
diff --git a/src/photos-gegl-buffer-codec-raw.h b/src/photos-gegl-buffer-codec-raw.h
new file mode 100644
index 00000000..0d399f25
--- /dev/null
+++ b/src/photos-gegl-buffer-codec-raw.h
@@ -0,0 +1,35 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 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/>.
+ */
+
+#ifndef PHOTOS_GEGL_BUFFER_CODEC_RAW_H
+#define PHOTOS_GEGL_BUFFER_CODEC_RAW_H
+
+#include "photos-gegl-buffer-codec.h"
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_GEGL_BUFFER_CODEC_RAW (photos_gegl_buffer_codec_raw_get_type ())
+G_DECLARE_FINAL_TYPE (PhotosGeglBufferCodecRaw,
+ photos_gegl_buffer_codec_raw,
+ PHOTOS,
+ GEGL_BUFFER_CODEC_RAW,
+ PhotosGeglBufferCodec);
+
+G_END_DECLS
+
+#endif /* PHOTOS_GEGL_BUFFER_CODEC_RAW_H */
diff --git a/src/photos-gegl.c b/src/photos-gegl.c
index 983ceb1d..f23dc4e6 100644
--- a/src/photos-gegl.c
+++ b/src/photos-gegl.c
@@ -28,6 +28,7 @@
#include "photos-gegl-buffer-codec.h"
#include "photos-gegl-buffer-codec-jpeg.h"
#include "photos-gegl-buffer-codec-png.h"
+#include "photos-gegl-buffer-codec-raw.h"
#include "photos-operation-insta-curve.h"
#include "photos-operation-insta-filter.h"
#include "photos-operation-insta-hefe.h"
@@ -638,6 +639,7 @@ photos_gegl_ensure_builtins (void)
{
g_type_ensure (PHOTOS_TYPE_GEGL_BUFFER_CODEC_JPEG);
g_type_ensure (PHOTOS_TYPE_GEGL_BUFFER_CODEC_PNG);
+ g_type_ensure (PHOTOS_TYPE_GEGL_BUFFER_CODEC_RAW);
g_type_ensure (PHOTOS_TYPE_OPERATION_INSTA_CURVE);
g_type_ensure (PHOTOS_TYPE_OPERATION_INSTA_FILTER);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]