Skip to content

Commit

Permalink
Added ABGR MASK_MODE
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Jul 13, 2022
1 parent 2b9d484 commit 9f6a315
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
Binary file added Tests/images/rgb32bf-abgr.bmp
Binary file not shown.
7 changes: 7 additions & 0 deletions Tests/test_file_bmp.py
Original file line number Diff line number Diff line change
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
2 changes: 2 additions & 0 deletions src/PIL/BmpImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ def _bitmap(self, header=0, offset=0):
32: [
(0xFF0000, 0xFF00, 0xFF, 0x0),
(0xFF000000, 0xFF0000, 0xFF00, 0x0),
(0xFF000000, 0xFF0000, 0xFF00, 0xFF),
(0xFF, 0xFF00, 0xFF0000, 0xFF000000),
(0xFF0000, 0xFF00, 0xFF, 0xFF000000),
(0x0, 0x0, 0x0, 0x0),
Expand All @@ -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",
Expand Down

0 comments on commit 9f6a315

Please sign in to comment.