[gtk/image-loading: 2/18] Load pngs without gdk-pixbuf
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/image-loading: 2/18] Load pngs without gdk-pixbuf
- Date: Tue, 14 Sep 2021 11:57:19 +0000 (UTC)
commit a7c587e9f57a5137ae6a40293092d078b1a0557d
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Sep 11 16:23:53 2021 -0400
Load pngs without gdk-pixbuf
Use our own loader for pngs, which will allow
us to get e.g. 16-bit data in the future.
gdk/gdktexture.c | 39 ++++++++++++++++++++++++++++-----------
1 file changed, 28 insertions(+), 11 deletions(-)
---
diff --git a/gdk/gdktexture.c b/gdk/gdktexture.c
index 4585765980..631f4a9064 100644
--- a/gdk/gdktexture.c
+++ b/gdk/gdktexture.c
@@ -46,6 +46,7 @@
#include "gdksnapshot.h"
#include <graphene.h>
+#include "loaders/gdkpngprivate.h"
G_DEFINE_QUARK (gdk-texture-error-quark, gdk_texture_error)
@@ -423,24 +424,40 @@ GdkTexture *
gdk_texture_new_from_bytes (GBytes *bytes,
GError **error)
{
- GInputStream *stream;
- GdkPixbuf *pixbuf;
- GdkTexture *texture;
+ const char *data;
+ gsize size;
g_return_val_if_fail (bytes != NULL, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
- stream = g_memory_input_stream_new_from_bytes (bytes);
- pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, error);
- g_object_unref (stream);
+ data = g_bytes_get_data (bytes, &size);
- if (pixbuf == NULL)
- return NULL;
+ if (size > strlen (PNG_SIGNATURE) &&
+ memcmp (data, PNG_SIGNATURE, strlen (PNG_SIGNATURE)) == 0)
+ {
+ return gdk_load_png (bytes, error);
+ }
+ else
+ {
+ GInputStream *stream;
+ GdkPixbuf *pixbuf;
- texture = gdk_texture_new_for_pixbuf (pixbuf);
- g_object_unref (pixbuf);
+ stream = g_memory_input_stream_new_from_bytes (bytes);
+ pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, error);
+ g_object_unref (stream);
- return texture;
+ if (pixbuf)
+ {
+ GdkTexture *texture;
+
+ texture = gdk_texture_new_for_pixbuf (pixbuf);
+ g_object_unref (pixbuf);
+
+ return texture;
+ }
+ }
+
+ return NULL;
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]