[gimp] plug-ins: allow loading of BMP images with incorrect BI_BITFIELDS compression.



commit e55e0782451ba7a2cd6d9eb7429b7ba05db838f7
Author: Jacob Boerema <jgboerema gmail com>
Date:   Thu Jan 7 18:01:12 2021 -0500

    plug-ins: allow loading of BMP images with incorrect BI_BITFIELDS compression.
    
    GIMP was exporting certain BMP images with 1, 4, 8 and 24 bpp
    with an incorrectly set value of BI_BITFIELDS for compression,
    see issue #6144.
    
    According to the specification this is not supported but testing
    shows that many image viewers and editors load these
    images correctly.
    Since allowing these unsupported values for bpp does not
    seem to have any negative side effects and is easy to
    implement let's add this.

 plug-ins/file-bmp/bmp-load.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
---
diff --git a/plug-ins/file-bmp/bmp-load.c b/plug-ins/file-bmp/bmp-load.c
index a4653340c6..df8f26c048 100644
--- a/plug-ins/file-bmp/bmp-load.c
+++ b/plug-ins/file-bmp/bmp-load.c
@@ -667,11 +667,9 @@ ReadImage (FILE                 *fd,
   GimpImageType      image_type;
   guint32            px32;
 
-  if (! (compression == BI_RGB ||
+  if (! (compression == BI_RGB || compression == BI_BITFIELDS ||
       (bpp == 8 && compression == BI_RLE8) ||
-      (bpp == 4 && compression == BI_RLE4) ||
-      (bpp == 16 && compression == BI_BITFIELDS) ||
-      (bpp == 32 && compression == BI_BITFIELDS)))
+      (bpp == 4 && compression == BI_RLE4)))
     {
       g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                    "%s",
@@ -697,6 +695,8 @@ ReadImage (FILE                 *fd,
           image_type = GIMP_RGB_IMAGE;
           channels = 3;
         }
+      if (bpp == 24 && compression == BI_BITFIELDS)
+        g_printerr ("Loading BMP with invalid combination of 24 bpp and BI_BITFIELDS compression.\n");
       break;
 
     case 8:
@@ -712,6 +712,9 @@ ReadImage (FILE                 *fd,
           base_type = GIMP_INDEXED;
           image_type = GIMP_INDEXED_IMAGE;
         }
+      if (compression == BI_BITFIELDS)
+        g_printerr ("Loading BMP with invalid combination of %d bpp and BI_BITFIELDS compression.\n",
+                    bpp);
 
       channels = 1;
       break;
@@ -844,7 +847,7 @@ ReadImage (FILE                 *fd,
     case 4:
     case 1:
       {
-        if (compression == 0)
+        if (compression == BI_RGB || compression == BI_BITFIELDS)
           /* no compression */
           {
             while (ReadOK (fd, &v, 1))


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