diff --git a/Tests/images/rgb32bf-abgr.bmp b/Tests/images/rgb32bf-abgr.bmp new file mode 100644 index 00000000000..2443714cadc Binary files /dev/null and b/Tests/images/rgb32bf-abgr.bmp differ diff --git a/Tests/test_file_bmp.py b/Tests/test_file_bmp.py index 776b499e089..d58666b4476 100644 --- a/Tests/test_file_bmp.py +++ b/Tests/test_file_bmp.py @@ -129,6 +129,13 @@ def test_rgba_bitfields(): assert_image_equal_tofile(im, "Tests/images/bmp/q/rgb32bf-xbgr.bmp") + # This test image has been manually hexedited + # to change the bitfield compression in the header from XBGR to ABGR + with Image.open("Tests/images/rgb32bf-abgr.bmp") as im: + assert_image_equal_tofile( + im.convert("RGB"), "Tests/images/bmp/q/rgb32bf-xbgr.bmp" + ) + def test_rle8(): with Image.open("Tests/images/hopper_rle8.bmp") as im: diff --git a/src/PIL/BmpImagePlugin.py b/src/PIL/BmpImagePlugin.py index 5aacb10da8c..7bb73fc9388 100644 --- a/src/PIL/BmpImagePlugin.py +++ b/src/PIL/BmpImagePlugin.py @@ -172,10 +172,11 @@ def _bitmap(self, header=0, offset=0): SUPPORTED = { 32: [ (0xFF0000, 0xFF00, 0xFF, 0x0), - (0xFF0000, 0xFF00, 0xFF, 0xFF000000), + (0xFF000000, 0xFF0000, 0xFF00, 0x0), + (0xFF000000, 0xFF0000, 0xFF00, 0xFF), (0xFF, 0xFF00, 0xFF0000, 0xFF000000), + (0xFF0000, 0xFF00, 0xFF, 0xFF000000), (0x0, 0x0, 0x0, 0x0), - (0xFF000000, 0xFF0000, 0xFF00, 0x0), ], 24: [(0xFF0000, 0xFF00, 0xFF)], 16: [(0xF800, 0x7E0, 0x1F), (0x7C00, 0x3E0, 0x1F)], @@ -183,6 +184,7 @@ def _bitmap(self, header=0, offset=0): MASK_MODES = { (32, (0xFF0000, 0xFF00, 0xFF, 0x0)): "BGRX", (32, (0xFF000000, 0xFF0000, 0xFF00, 0x0)): "XBGR", + (32, (0xFF000000, 0xFF0000, 0xFF00, 0xFF)): "ABGR", (32, (0xFF, 0xFF00, 0xFF0000, 0xFF000000)): "RGBA", (32, (0xFF0000, 0xFF00, 0xFF, 0xFF000000)): "BGRA", (32, (0x0, 0x0, 0x0, 0x0)): "BGRA",