forked from AuroraMiddleware/gtk
image: Warn when attempting to load pixdata GResources
GdkPixdata is deprecated. Warn when the application tries to load pixdata embedded resources. The application developer will have to remove the "to-pixdata" keyword from the GResource definition file. https://bugzilla.gnome.org/show_bug.cgi?id=781583
This commit is contained in:
parent
ce861bc430
commit
eb338feff9
@ -860,6 +860,36 @@ gtk_image_set_from_file (GtkImage *image,
|
||||
g_object_thaw_notify (G_OBJECT (image));
|
||||
}
|
||||
|
||||
#ifndef GDK_PIXBUF_MAGIC_NUMBER
|
||||
#define GDK_PIXBUF_MAGIC_NUMBER (0x47646b50) /* 'GdkP' */
|
||||
#endif
|
||||
|
||||
static gboolean
|
||||
resource_is_pixdata (const gchar *resource_path)
|
||||
{
|
||||
const guint8 *stream;
|
||||
guint32 magic;
|
||||
gsize data_size;
|
||||
GBytes *bytes;
|
||||
gboolean ret = FALSE;
|
||||
|
||||
bytes = g_resources_lookup_data (resource_path, 0, NULL);
|
||||
if (bytes == NULL)
|
||||
return FALSE;
|
||||
|
||||
stream = g_bytes_get_data (bytes, &data_size);
|
||||
if (data_size < sizeof(guint32))
|
||||
goto out;
|
||||
|
||||
magic = (stream[0] << 24) + (stream[1] << 16) + (stream[2] << 8) + stream[3];
|
||||
if (magic == GDK_PIXBUF_MAGIC_NUMBER)
|
||||
ret = TRUE;
|
||||
|
||||
out:
|
||||
g_bytes_unref (bytes);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_image_set_from_resource:
|
||||
* @image: a #GtkImage
|
||||
@ -873,7 +903,7 @@ gtk_image_set_from_resource (GtkImage *image,
|
||||
{
|
||||
GtkImagePrivate *priv;
|
||||
GdkPixbufAnimation *animation;
|
||||
gint scale_factor;
|
||||
gint scale_factor = 1;
|
||||
|
||||
g_return_if_fail (GTK_IS_IMAGE (image));
|
||||
|
||||
@ -889,7 +919,15 @@ gtk_image_set_from_resource (GtkImage *image,
|
||||
return;
|
||||
}
|
||||
|
||||
animation = load_scalable_with_loader (image, NULL, resource_path, &scale_factor);
|
||||
if (resource_is_pixdata (resource_path))
|
||||
{
|
||||
g_warning ("GdkPixdata format images are not supported, remove the \"to-pixdata\" option from your GResource files");
|
||||
animation = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
animation = load_scalable_with_loader (image, NULL, resource_path, &scale_factor);
|
||||
}
|
||||
|
||||
if (animation == NULL)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user