loaders: Make it possible to load png options

We want to store some metadata in our symbolic pngs, so make it
possible to get options when loading a png, along with the texture.

Update all callers.
This commit is contained in:
Matthias Clasen 2024-04-28 15:07:25 -04:00
parent 585dadf575
commit 08d1353cde
4 changed files with 20 additions and 5 deletions

View File

@ -563,7 +563,7 @@ gdk_texture_new_from_bytes_internal (GBytes *bytes,
{ {
if (gdk_is_png (bytes)) if (gdk_is_png (bytes))
{ {
return gdk_load_png (bytes, error); return gdk_load_png (bytes, NULL, error);
} }
else if (gdk_is_jpeg (bytes)) else if (gdk_is_jpeg (bytes))
{ {

View File

@ -131,11 +131,14 @@ png_simple_warning_callback (png_structp png,
GdkTexture * GdkTexture *
gdk_load_png (GBytes *bytes, gdk_load_png (GBytes *bytes,
GHashTable *options,
GError **error) GError **error)
{ {
png_io io; png_io io;
png_struct *png = NULL; png_struct *png = NULL;
png_info *info; png_info *info;
png_textp text;
int num_texts;
guint width, height; guint width, height;
gsize i, stride; gsize i, stride;
int depth, color_type; int depth, color_type;
@ -297,6 +300,17 @@ gdk_load_png (GBytes *bytes,
texture = gdk_memory_texture_new (width, height, format, out_bytes, stride); texture = gdk_memory_texture_new (width, height, format, out_bytes, stride);
g_bytes_unref (out_bytes); g_bytes_unref (out_bytes);
if (options && png_get_text (png, info, &text, &num_texts))
{
for (i = 0; i < num_texts; i++)
{
if (text->compression != -1)
continue;
g_hash_table_insert (options, g_strdup (text->key), g_strdup (text->text));
}
}
g_free (row_pointers); g_free (row_pointers);
png_destroy_read_struct (&png, &info, NULL); png_destroy_read_struct (&png, &info, NULL);

View File

@ -23,6 +23,7 @@
#define PNG_SIGNATURE "\x89PNG" #define PNG_SIGNATURE "\x89PNG"
GdkTexture *gdk_load_png (GBytes *bytes, GdkTexture *gdk_load_png (GBytes *bytes,
GHashTable *options,
GError **error); GError **error);
GBytes *gdk_save_png (GdkTexture *texture); GBytes *gdk_save_png (GdkTexture *texture);

View File

@ -49,7 +49,7 @@ test_load_image (gconstpointer data)
/* use the internal api, we want to avoid pixbuf fallback here */ /* use the internal api, we want to avoid pixbuf fallback here */
if (g_str_has_suffix (filename, ".png")) if (g_str_has_suffix (filename, ".png"))
texture = gdk_load_png (bytes, &error); texture = gdk_load_png (bytes, NULL, &error);
else if (g_str_has_suffix (filename, ".tiff")) else if (g_str_has_suffix (filename, ".tiff"))
texture = gdk_load_tiff (bytes, &error); texture = gdk_load_tiff (bytes, &error);
else if (g_str_has_suffix (filename, ".jpeg")) else if (g_str_has_suffix (filename, ".jpeg"))