Skip to content

Commit 1f74704

Browse files
authored
Merge pull request #6436 from radarhere/bmp
Added ABGR BMP mask mode
2 parents 5e649c1 + ea78975 commit 1f74704

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

Tests/images/rgb32bf-abgr.bmp

31.9 KB
Binary file not shown.

Tests/test_file_bmp.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,13 @@ def test_rgba_bitfields():
129129

130130
assert_image_equal_tofile(im, "Tests/images/bmp/q/rgb32bf-xbgr.bmp")
131131

132+
# This test image has been manually hexedited
133+
# to change the bitfield compression in the header from XBGR to ABGR
134+
with Image.open("Tests/images/rgb32bf-abgr.bmp") as im:
135+
assert_image_equal_tofile(
136+
im.convert("RGB"), "Tests/images/bmp/q/rgb32bf-xbgr.bmp"
137+
)
138+
132139

133140
def test_rle8():
134141
with Image.open("Tests/images/hopper_rle8.bmp") as im:

src/PIL/BmpImagePlugin.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,17 +172,19 @@ def _bitmap(self, header=0, offset=0):
172172
SUPPORTED = {
173173
32: [
174174
(0xFF0000, 0xFF00, 0xFF, 0x0),
175-
(0xFF0000, 0xFF00, 0xFF, 0xFF000000),
175+
(0xFF000000, 0xFF0000, 0xFF00, 0x0),
176+
(0xFF000000, 0xFF0000, 0xFF00, 0xFF),
176177
(0xFF, 0xFF00, 0xFF0000, 0xFF000000),
178+
(0xFF0000, 0xFF00, 0xFF, 0xFF000000),
177179
(0x0, 0x0, 0x0, 0x0),
178-
(0xFF000000, 0xFF0000, 0xFF00, 0x0),
179180
],
180181
24: [(0xFF0000, 0xFF00, 0xFF)],
181182
16: [(0xF800, 0x7E0, 0x1F), (0x7C00, 0x3E0, 0x1F)],
182183
}
183184
MASK_MODES = {
184185
(32, (0xFF0000, 0xFF00, 0xFF, 0x0)): "BGRX",
185186
(32, (0xFF000000, 0xFF0000, 0xFF00, 0x0)): "XBGR",
187+
(32, (0xFF000000, 0xFF0000, 0xFF00, 0xFF)): "ABGR",
186188
(32, (0xFF, 0xFF00, 0xFF0000, 0xFF000000)): "RGBA",
187189
(32, (0xFF0000, 0xFF00, 0xFF, 0xFF000000)): "BGRA",
188190
(32, (0x0, 0x0, 0x0, 0x0)): "BGRA",

0 commit comments

Comments
 (0)