[frogr] Implement workaround to load images when GdkPixbufLoader fails to do so



commit 4e48c5e666205c1793abe6bf4294f03933ebe10a
Author: Mario Sanchez Prada <msanchez gnome org>
Date:   Tue Dec 26 21:13:20 2017 +0100

    Implement workaround to load images when GdkPixbufLoader fails to do so
    
    There seems to be an obscure bug in gdk-pixbuf that causes to fail loading
    images into GdkPixbuf instances when using GdkPixbufLoader, even though
    the same images load just fine with gdk_pixbuf_new_from_file().
    
    I've investigated this a bit in gdk-pixbuf but couldn't find the problem
    myself so, considering that this bug has been reported a while ago already
    and that it's very annoying (specially when uploading certain pictures taken
    with mobile phones), I've decided to push this workaround for frogr hoping
    that this will get fixed in gdk-pixbuf, which I'll file a bug about it.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=768639

 src/frogr-details-dialog.c |   14 +++++++++++---
 src/frogr-file-loader.c    |    6 +++++-
 src/frogr-util.c           |   16 +++++++++++++---
 src/frogr-util.h           |    2 +-
 4 files changed, 30 insertions(+), 8 deletions(-)
---
diff --git a/src/frogr-details-dialog.c b/src/frogr-details-dialog.c
index dba679e..2df560d 100644
--- a/src/frogr-details-dialog.c
+++ b/src/frogr-details-dialog.c
@@ -513,10 +513,18 @@ _load_picture_from_disk_cb (GObject *object,
 
       picture = FROGR_PICTURE (self->pictures->data);
       if (frogr_picture_is_video (picture))
-        pixbuf = frogr_util_get_pixbuf_for_video_file (file, PICTURE_WIDTH, PICTURE_HEIGHT, &error);
+        {
+          pixbuf = frogr_util_get_pixbuf_for_video_file (file, PICTURE_WIDTH, PICTURE_HEIGHT, &error);
+        }
       else
-        pixbuf = frogr_util_get_pixbuf_from_image_contents ((const guchar *)contents, length,
-                                                            PICTURE_WIDTH, PICTURE_HEIGHT, &error);
+        {
+          gchar *path = NULL;
+
+          path = g_file_get_path (file);
+          pixbuf = frogr_util_get_pixbuf_from_image_contents ((const guchar *)contents, length,
+                                                              PICTURE_WIDTH, PICTURE_HEIGHT, path, &error);
+          g_free (path);
+        }
 
       if (pixbuf)
         {
diff --git a/src/frogr-file-loader.c b/src/frogr-file-loader.c
index 5eacbae..742135d 100644
--- a/src/frogr-file-loader.c
+++ b/src/frogr-file-loader.c
@@ -355,10 +355,14 @@ _try_get_pixbuf_for_image (FrogrFileLoader *self,
                           gsize length)
 {
   GdkPixbuf *pixbuf = NULL;
+  gchar *path = NULL;
   GError *error = NULL;
 
+  path = g_file_get_path (file);
   pixbuf = frogr_util_get_pixbuf_from_image_contents ((const guchar *)contents, length,
-                                                     IV_THUMB_WIDTH, IV_THUMB_HEIGHT, &error);
+                                                     IV_THUMB_WIDTH, IV_THUMB_HEIGHT, path, &error);
+  g_free (path);
+
   if (error)
     {
       gchar *file_name = NULL;
diff --git a/src/frogr-util.c b/src/frogr-util.c
index 87ff79b..127516e 100644
--- a/src/frogr-util.c
+++ b/src/frogr-util.c
@@ -300,7 +300,7 @@ _get_corrected_pixbuf (GdkPixbuf *pixbuf, gint max_width, gint max_height)
 }
 
 static GdkPixbuf *
-_get_pixbuf_from_image_contents (const guchar *contents, gsize length, GError **out_error)
+_get_pixbuf_from_image_contents (const guchar *contents, gsize length, const gchar *filepath, GError 
**out_error)
 {
   GdkPixbufLoader *pixbuf_loader = NULL;
   GdkPixbuf *pixbuf = NULL;
@@ -316,6 +316,16 @@ _get_pixbuf_from_image_contents (const guchar *contents, gsize length, GError **
       pixbuf = gdk_pixbuf_loader_get_pixbuf (pixbuf_loader);
     }
 
+  /* Silly workaround to deal with what seems to be an obscure problem in
+   * GdkPixbufLoader. See https://bugzilla.gnome.org/show_bug.cgi?id=768639 */
+  if (error && filepath)
+    {
+      g_warning ("Not able to read image from %s: %s. Trying fallback...", filepath, error->message);
+      g_clear_error (&error);
+
+      pixbuf = gdk_pixbuf_new_from_file (filepath, &error);
+    }
+
   if (error)
     {
       DEBUG ("Error loading pixbuf: %s", error->message);
@@ -496,11 +506,11 @@ frogr_util_get_pixbuf_for_video_file (GFile *file, gint max_width, gint max_heig
 }
 
 GdkPixbuf *
-frogr_util_get_pixbuf_from_image_contents (const guchar *contents, gsize length, gint max_width, gint 
max_height, GError **error)
+frogr_util_get_pixbuf_from_image_contents (const guchar *contents, gsize length, gint max_width, gint 
max_height, const gchar *filepath, GError **error)
 {
   GdkPixbuf *pixbuf = NULL;
 
-  pixbuf = _get_pixbuf_from_image_contents (contents, length, error);
+  pixbuf = _get_pixbuf_from_image_contents (contents, length, filepath, error);
   if (pixbuf)
     {
       GdkPixbuf *c_pixbuf = NULL;
diff --git a/src/frogr-util.h b/src/frogr-util.h
index d27ac51..3d559f3 100644
--- a/src/frogr-util.h
+++ b/src/frogr-util.h
@@ -41,7 +41,7 @@ void frogr_util_show_error_dialog (GtkWindow *parent, const gchar *message);
 
 GdkPixbuf *frogr_util_get_pixbuf_for_video_file (GFile *file, gint max_width, gint max_height, GError 
**error);
 
-GdkPixbuf *frogr_util_get_pixbuf_from_image_contents (const guchar *contents, gsize length, gint max_width, 
gint max_height, GError **error);
+GdkPixbuf *frogr_util_get_pixbuf_from_image_contents (const guchar *contents, gsize length, gint max_width, 
gint max_height, const gchar *path, GError **error);
 
 gchar *frogr_util_get_datasize_string (gulong datasize);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]