mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
Merge pull request #3705 from radarhere/bmp
Add support for BMP RGBA bitfield compression
This commit is contained in:
commit
b3587f0fb7
BIN
Tests/images/rgb32bf-rgba.bmp
Normal file
BIN
Tests/images/rgb32bf-rgba.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 32 KiB |
|
@ -90,3 +90,15 @@ class TestFileBmp(PillowTestCase):
|
|||
self.assertEqual(reloaded.format, "DIB")
|
||||
self.assertEqual(reloaded.get_format_mimetype(), "image/bmp")
|
||||
self.assert_image_equal(im, reloaded)
|
||||
|
||||
def test_rgba_bitfields(self):
|
||||
# This test image has been manually hexedited
|
||||
# to change the bitfield compression in the header from XBGR to RGBA
|
||||
im = Image.open("Tests/images/rgb32bf-rgba.bmp")
|
||||
|
||||
# So before the comparing the image, swap the channels
|
||||
b, g, r = im.split()[1:]
|
||||
im = Image.merge("RGB", (r, g, b))
|
||||
|
||||
target = Image.open("Tests/images/bmp/q/rgb32bf-xbgr.bmp")
|
||||
self.assert_image_equal(im, target)
|
||||
|
|
|
@ -180,6 +180,7 @@ class BmpImageFile(ImageFile.ImageFile):
|
|||
SUPPORTED = {
|
||||
32: [(0xff0000, 0xff00, 0xff, 0x0),
|
||||
(0xff0000, 0xff00, 0xff, 0xff000000),
|
||||
(0xff, 0xff00, 0xff0000, 0xff000000),
|
||||
(0x0, 0x0, 0x0, 0x0),
|
||||
(0xff000000, 0xff0000, 0xff00, 0x0)],
|
||||
24: [(0xff0000, 0xff00, 0xff)],
|
||||
|
@ -188,6 +189,7 @@ class BmpImageFile(ImageFile.ImageFile):
|
|||
MASK_MODES = {
|
||||
(32, (0xff0000, 0xff00, 0xff, 0x0)): "BGRX",
|
||||
(32, (0xff000000, 0xff0000, 0xff00, 0x0)): "XBGR",
|
||||
(32, (0xff, 0xff00, 0xff0000, 0xff000000)): "RGBA",
|
||||
(32, (0xff0000, 0xff00, 0xff, 0xff000000)): "BGRA",
|
||||
(32, (0x0, 0x0, 0x0, 0x0)): "BGRA",
|
||||
(24, (0xff0000, 0xff00, 0xff)): "BGR",
|
||||
|
@ -200,7 +202,7 @@ class BmpImageFile(ImageFile.ImageFile):
|
|||
raw_mode = MASK_MODES[
|
||||
(file_info["bits"], file_info["rgba_mask"])
|
||||
]
|
||||
self.mode = "RGBA" if raw_mode in ("BGRA",) else self.mode
|
||||
self.mode = "RGBA" if "A" in raw_mode else self.mode
|
||||
elif (file_info['bits'] in (24, 16) and
|
||||
file_info['rgb_mask'] in SUPPORTED[file_info['bits']]):
|
||||
raw_mode = MASK_MODES[
|
||||
|
|
Loading…
Reference in New Issue
Block a user