[gtk/image-loading: 2/14] Load pngs without gdk-pixbuf
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/image-loading: 2/14] Load pngs without gdk-pixbuf
- Date: Sun, 12 Sep 2021 23:36:41 +0000 (UTC)
commit 1d664e7393d9eb0ca32f3166205a569b9982bafa
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 | 42 +++++++++++++++++++++++++++++++-----------
1 file changed, 31 insertions(+), 11 deletions(-)
---
diff --git a/gdk/gdktexture.c b/gdk/gdktexture.c
index 7b055238fd..4da14d1e98 100644
--- a/gdk/gdktexture.c
+++ b/gdk/gdktexture.c
@@ -46,6 +46,7 @@
#include "gdksnapshot.h"
#include <graphene.h>
+#include "loaders/gdkpngprivate.h"
/* HACK: So we don't need to include any (not-yet-created) GSK or GTK headers */
void
@@ -383,24 +384,43 @@ GdkTexture *
gdk_texture_new_from_file (GFile *file,
GError **error)
{
- GdkTexture *texture;
- GdkPixbuf *pixbuf;
- GInputStream *stream;
+ GdkTexture *texture = NULL;
+ GBytes *bytes;
+ const char *data;
g_return_val_if_fail (G_IS_FILE (file), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
- stream = G_INPUT_STREAM (g_file_read (file, NULL, error));
- if (stream == NULL)
+ bytes = g_file_load_bytes (file, NULL, NULL, error);
+ if (!bytes)
return NULL;
- pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, error);
- g_object_unref (stream);
- if (pixbuf == NULL)
- return NULL;
+ data = g_bytes_get_data (bytes, NULL);
- texture = gdk_texture_new_for_pixbuf (pixbuf);
- g_object_unref (pixbuf);
+ if (memcmp (data, PNG_SIGNATURE, strlen (PNG_SIGNATURE)) == 0)
+ texture = gdk_load_png (bytes, error);
+ else
+ {
+ GInputStream *stream = NULL;
+ GdkPixbuf *pixbuf = NULL;
+
+ stream = G_INPUT_STREAM (g_file_read (file, NULL, error));
+ if (stream == NULL)
+ goto done;
+
+ pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, error);
+ g_object_unref (stream);
+ if (pixbuf == NULL)
+ goto done;
+
+ texture = gdk_texture_new_for_pixbuf (pixbuf);
+
+done:
+ g_object_unref (pixbuf);
+ g_clear_object (&stream);
+ }
+
+ g_bytes_unref (bytes);
return texture;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]