[gimp/gimp-2-6] Bug 586851 – Transparent BMP files fail to load



commit 8421cbf6613ad9386cada7017c476b09b59b95a9
Author: Massimo Valentini <sixtysix inwind it>
Date:   Wed Jul 22 18:17:00 2009 +0200

    Bug 586851 â?? Transparent BMP files fail to load
    
    If everything else fails, use gdk_pixbuf_new_from_file().

 plug-ins/file-bmp/bmp-read.c |   35 +++++++++++++++++++++++++++++++----
 1 files changed, 31 insertions(+), 4 deletions(-)
---
diff --git a/plug-ins/file-bmp/bmp-read.c b/plug-ins/file-bmp/bmp-read.c
index 3d726e2..a1ebe47 100644
--- a/plug-ins/file-bmp/bmp-read.c
+++ b/plug-ins/file-bmp/bmp-read.c
@@ -27,8 +27,10 @@
 #include <string.h>
 
 #include <glib/gstdio.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
 
 #include <libgimp/gimp.h>
+#include <libgimp/gimppixbuf.h>
 
 #include "bmp.h"
 
@@ -367,10 +369,35 @@ ReadBMP (const gchar  *name,
     }
   else
     {
-      g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
-                   _("Error reading BMP file header from '%s'"),
-                   gimp_filename_to_utf8 (filename));
-      return -1;
+      GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file(filename, NULL);
+
+      if (pixbuf)
+        {
+          gint32 layer_ID;
+
+          image_ID = gimp_image_new (gdk_pixbuf_get_width (pixbuf),
+                                     gdk_pixbuf_get_height (pixbuf),
+                                     GIMP_RGB);
+
+          layer_ID = gimp_layer_new_from_pixbuf (image_ID, _("Background"),
+                                                 pixbuf,
+                                                 100.,
+                                                 GIMP_NORMAL_MODE, 0, 0);
+          g_object_unref (pixbuf);
+
+          gimp_image_set_filename (image_ID, filename);
+          gimp_image_add_layer (image_ID, layer_ID, -1);
+
+          return image_ID;
+        }
+      else
+        {
+
+          g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+                       _("Error reading BMP file header from '%s'"),
+                       gimp_filename_to_utf8 (filename));
+          return -1;
+        }
     }
 
   /* Valid bitpdepthis 1, 4, 8, 16, 24, 32 */



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