Commit 3b0fa197 authored by Debarshi Ray's avatar Debarshi Ray Committed by Debarshi Ray

loader: Expose the dimensions of the original image

Currently, it's not possible to get the dimensions of the original
image from a scaled GdkPixbuf. This is problematic for thumbnailers
because they want to embed the original dimensions into the resulting
thumbnail file. The only way to get this information is to either
decode the full-resolution image and then downscale it, even when the
decoder supports downscaling on-the-fly; or to re-implement large
chunks of code to avoid decoding the full-resolution image and
retain the original dimensions.

Exposing the original dimensions as options simplifies the thumbnailer
without affecting performance.

https://bugzilla.gnome.org/show_bug.cgi?id=778517
parent 1ee0a9e1
......@@ -104,6 +104,8 @@ typedef struct
gint header_buf_offset;
GdkPixbufModule *image_module;
gpointer context;
gint original_width;
gint original_height;
gint width;
gint height;
gboolean size_fixed;
......@@ -216,6 +218,8 @@ gdk_pixbuf_loader_init (GdkPixbufLoader *loader)
GdkPixbufLoaderPrivate *priv;
priv = g_new0 (GdkPixbufLoaderPrivate, 1);
priv->original_width = -1;
priv->original_height = -1;
priv->width = -1;
priv->height = -1;
......@@ -284,6 +288,9 @@ gdk_pixbuf_loader_size_func (gint *width, gint *height, gpointer loader)
{
GdkPixbufLoaderPrivate *priv = GDK_PIXBUF_LOADER (loader)->priv;
priv->original_width = *width;
priv->original_height = *height;
/* allow calling gdk_pixbuf_loader_set_size() before the signal */
if (priv->width == -1 && priv->height == -1)
{
......@@ -327,8 +334,25 @@ gdk_pixbuf_loader_prepare (GdkPixbuf *pixbuf,
if (anim)
g_object_ref (anim);
else
else {
if (priv->original_width > 0) {
char *original_width_str = NULL;
original_width_str = g_strdup_printf ("%d", priv->original_width);
gdk_pixbuf_set_option (pixbuf, "original-width", original_width_str);
g_free (original_width_str);
}
if (priv->original_height > 0) {
char *original_height_str = NULL;
original_height_str = g_strdup_printf ("%d", priv->original_height);
gdk_pixbuf_set_option (pixbuf, "original-height", original_height_str);
g_free (original_height_str);
}
anim = gdk_pixbuf_non_anim_new (pixbuf);
}
if (priv->needs_scale && width != 0 && height != 0) {
priv->animation = GDK_PIXBUF_ANIMATION (_gdk_pixbuf_scaled_anim_new (anim,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment