Skip to content

Commit

Permalink
Merge pull request #6436 from radarhere/bmp
Browse files Browse the repository at this point in the history
Added ABGR BMP mask mode
  • Loading branch information
hugovk committed Jul 15, 2022
2 parents 5e649c1 + ea78975 commit 1f74704
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
Binary file added Tests/images/rgb32bf-abgr.bmp
Binary file not shown.
7 changes: 7 additions & 0 deletions Tests/test_file_bmp.py
Expand Up @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions src/PIL/BmpImagePlugin.py
Expand Up @@ -172,17 +172,19 @@ 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)],
}
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",
Expand Down

0 comments on commit 1f74704

Please sign in to comment.