summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDebarshi Ray <debarshir@freedesktop.org>2018-04-26 13:09:47 +0200
committerDebarshi Ray <debarshir@gnome.org>2018-05-01 17:02:10 +0200
commit3b0fa197fe3fb76ed3698155001ecc53f64b50bb (patch)
tree878f75fb0eff03f28b6d29b21c0da54d320f22d4
parent1ee0a9e1f3cbf9d7bfaf98312a2dfd0685ee4332 (diff)
downloadgdk-pixbuf-3b0fa197fe3fb76ed3698155001ecc53f64b50bb.tar.gz
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
-rw-r--r--gdk-pixbuf/gdk-pixbuf-loader.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/gdk-pixbuf/gdk-pixbuf-loader.c b/gdk-pixbuf/gdk-pixbuf-loader.c
index aab5303e7..81c5afb75 100644
--- a/gdk-pixbuf/gdk-pixbuf-loader.c
+++ b/gdk-pixbuf/gdk-pixbuf-loader.c
@@ -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,