[gdk-pixbuf] Avoid a discrepancy in file recognition
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gdk-pixbuf] Avoid a discrepancy in file recognition
- Date: Thu, 19 Dec 2013 05:32:53 +0000 (UTC)
commit 496d8e39a6eec38ab0b6493736488418ec2d7000
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Dec 19 00:26:24 2013 -0500
Avoid a discrepancy in file recognition
We are using a loader to implement some of the APIs that
are taking a filename, such as gdk_pixbuf_new_from_file_at_scale.
But the loader does not have the filename, so it can't use it
when determining the image type. This makes a difference for
types such as xbm, which have no good magic in the mime database.
Fix this by introducing a private API that lets us pass the
filename on to the loader.
gdk-pixbuf/gdk-pixbuf-io.c | 4 ++--
gdk-pixbuf/gdk-pixbuf-loader.c | 19 ++++++++++++++++++-
gdk-pixbuf/gdk-pixbuf-private.h | 3 +++
3 files changed, 23 insertions(+), 3 deletions(-)
---
diff --git a/gdk-pixbuf/gdk-pixbuf-io.c b/gdk-pixbuf/gdk-pixbuf-io.c
index 0ef83b4..0cb6ed3 100644
--- a/gdk-pixbuf/gdk-pixbuf-io.c
+++ b/gdk-pixbuf/gdk-pixbuf-io.c
@@ -1351,7 +1351,7 @@ gdk_pixbuf_new_from_file_at_scale (const char *filename,
return NULL;
}
- loader = gdk_pixbuf_loader_new ();
+ loader = _gdk_pixbuf_loader_new_with_filename (filename);
info.width = width;
info.height = height;
@@ -1909,7 +1909,7 @@ gdk_pixbuf_get_file_info (const gchar *filename,
if (!f)
return NULL;
- loader = gdk_pixbuf_loader_new ();
+ loader = _gdk_pixbuf_loader_new_with_filename (filename);
info.format = NULL;
info.width = -1;
diff --git a/gdk-pixbuf/gdk-pixbuf-loader.c b/gdk-pixbuf/gdk-pixbuf-loader.c
index 5cf3f74..a567de3 100644
--- a/gdk-pixbuf/gdk-pixbuf-loader.c
+++ b/gdk-pixbuf/gdk-pixbuf-loader.c
@@ -123,10 +123,12 @@ typedef struct
gint height;
gboolean size_fixed;
gboolean needs_scale;
+ gchar *filename;
} GdkPixbufLoaderPrivate;
G_DEFINE_TYPE (GdkPixbufLoader, gdk_pixbuf_loader, G_TYPE_OBJECT)
+
static void
gdk_pixbuf_loader_class_init (GdkPixbufLoaderClass *class)
{
@@ -250,6 +252,8 @@ gdk_pixbuf_loader_finalize (GObject *object)
if (priv->animation)
g_object_unref (priv->animation);
+ g_free (priv->filename);
+
g_free (priv);
G_OBJECT_CLASS (gdk_pixbuf_loader_parent_class)->finalize (object);
@@ -412,7 +416,7 @@ gdk_pixbuf_loader_load_module (GdkPixbufLoader *loader,
{
priv->image_module = _gdk_pixbuf_get_module (priv->header_buf,
priv->header_buf_offset,
- NULL,
+ priv->filename,
error);
}
@@ -702,6 +706,19 @@ gdk_pixbuf_loader_new_with_mime_type (const char *mime_type,
return retval;
}
+GdkPixbufLoader *
+_gdk_pixbuf_loader_new_with_filename (const char *filename)
+{
+ GdkPixbufLoader *retval;
+ GdkPixbufLoaderPrivate *priv;
+
+ retval = g_object_new (GDK_TYPE_PIXBUF_LOADER, NULL);
+ priv = retval->priv;
+ priv->filename = g_strdup (filename);
+
+ return retval;
+}
+
/**
* gdk_pixbuf_loader_get_pixbuf:
* @loader: A pixbuf loader.
diff --git a/gdk-pixbuf/gdk-pixbuf-private.h b/gdk-pixbuf/gdk-pixbuf-private.h
index 444ff37..8f51307 100644
--- a/gdk-pixbuf/gdk-pixbuf-private.h
+++ b/gdk-pixbuf/gdk-pixbuf-private.h
@@ -32,6 +32,7 @@
#include <glib-object.h>
#include "gdk-pixbuf-core.h"
+#include "gdk-pixbuf-loader.h"
#include "gdk-pixbuf-io.h"
#include "gdk-pixbuf-i18n.h"
@@ -99,9 +100,11 @@ GdkPixbuf *_gdk_pixbuf_generic_image_load (GdkPixbufModule *image_module,
GdkPixbufFormat *_gdk_pixbuf_get_format (GdkPixbufModule *image_module);
+
#endif /* GDK_PIXBUF_ENABLE_BACKEND */
GdkPixbuf * _gdk_pixbuf_new_from_resource_try_mmap (const char *resource_path);
+GdkPixbufLoader *_gdk_pixbuf_loader_new_with_filename (const char *filename);
#endif /* GDK_PIXBUF_PRIVATE_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]