[gdk-pixbuf] loader: Expose the dimensions of the original image
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gdk-pixbuf] loader: Expose the dimensions of the original image
- Date: Tue, 1 May 2018 15:02:45 +0000 (UTC)
commit 3b0fa197fe3fb76ed3698155001ecc53f64b50bb
Author: Debarshi Ray <debarshir freedesktop org>
Date: Thu Apr 26 13:09:47 2018 +0200
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
gdk-pixbuf/gdk-pixbuf-loader.c | 26 +++++++++++++++++++++++++-
1 files changed, 25 insertions(+), 1 deletions(-)
---
diff --git a/gdk-pixbuf/gdk-pixbuf-loader.c b/gdk-pixbuf/gdk-pixbuf-loader.c
index aab5303..81c5afb 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,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]