From 37d75d5eb3cdfd3e4de02f6d9cc3ebc7bf8f285e Mon Sep 17 00:00:00 2001 From: Jacob Boerema Date: Thu, 7 Jan 2021 18:01:12 -0500 Subject: [PATCH] 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. (cherry picked from commit e55e0782451ba7a2cd6d9eb7429b7ba05db838f7) --- 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 4115b9a5c6..e79b9006b2 100644 --- a/plug-ins/file-bmp/bmp-load.c +++ b/plug-ins/file-bmp/bmp-load.c @@ -664,11 +664,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", @@ -694,6 +692,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: @@ -709,6 +709,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; @@ -841,7 +844,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))