mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-13 02:36:17 +03:00
Add support for bitmaps with header size 52
Size 52 is the undocumented `BITMAPV2INFOHEADER`. It adds the RGB bit masks. The format is known to be supported by: - Adobe Photoshop - Popular web browsers
This commit is contained in:
parent
33a73b5266
commit
2f3281dcda
BIN
Tests/images/bmp/q/rgb32h52.bmp
Normal file
BIN
Tests/images/bmp/q/rgb32h52.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 32 KiB |
|
@ -44,6 +44,7 @@ def test_questionable() -> None:
|
||||||
"pal8os2sp.bmp",
|
"pal8os2sp.bmp",
|
||||||
"pal8rletrns.bmp",
|
"pal8rletrns.bmp",
|
||||||
"rgb32bf-xbgr.bmp",
|
"rgb32bf-xbgr.bmp",
|
||||||
|
"rgb32h52.bmp",
|
||||||
]
|
]
|
||||||
for f in get_files("q"):
|
for f in get_files("q"):
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -53,7 +53,7 @@ def _accept(prefix: bytes) -> bool:
|
||||||
|
|
||||||
|
|
||||||
def _dib_accept(prefix):
|
def _dib_accept(prefix):
|
||||||
return i32(prefix) in [12, 40, 64, 108, 124]
|
return i32(prefix) in [12, 40, 52, 64, 108, 124]
|
||||||
|
|
||||||
|
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
|
@ -95,7 +95,7 @@ class BmpImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
# --------------------------------------------- Windows Bitmap v2 to v5
|
# --------------------------------------------- Windows Bitmap v2 to v5
|
||||||
# v3, OS/2 v2, v4, v5
|
# v3, OS/2 v2, v4, v5
|
||||||
elif file_info["header_size"] in (40, 64, 108, 124):
|
elif file_info["header_size"] in (40, 52, 64, 108, 124):
|
||||||
file_info["y_flip"] = header_data[7] == 0xFF
|
file_info["y_flip"] = header_data[7] == 0xFF
|
||||||
file_info["direction"] = 1 if file_info["y_flip"] else -1
|
file_info["direction"] = 1 if file_info["y_flip"] else -1
|
||||||
file_info["width"] = i32(header_data, 0)
|
file_info["width"] = i32(header_data, 0)
|
||||||
|
@ -117,10 +117,13 @@ class BmpImageFile(ImageFile.ImageFile):
|
||||||
file_info["palette_padding"] = 4
|
file_info["palette_padding"] = 4
|
||||||
self.info["dpi"] = tuple(x / 39.3701 for x in file_info["pixels_per_meter"])
|
self.info["dpi"] = tuple(x / 39.3701 for x in file_info["pixels_per_meter"])
|
||||||
if file_info["compression"] == self.BITFIELDS:
|
if file_info["compression"] == self.BITFIELDS:
|
||||||
|
if len(header_data) >= 48:
|
||||||
|
masks = ["r_mask", "g_mask", "b_mask"]
|
||||||
if len(header_data) >= 52:
|
if len(header_data) >= 52:
|
||||||
for idx, mask in enumerate(
|
masks.append("a_mask")
|
||||||
["r_mask", "g_mask", "b_mask", "a_mask"]
|
else:
|
||||||
):
|
file_info["a_mask"] = 0x0
|
||||||
|
for idx, mask in enumerate(masks):
|
||||||
file_info[mask] = i32(header_data, 36 + idx * 4)
|
file_info[mask] = i32(header_data, 36 + idx * 4)
|
||||||
else:
|
else:
|
||||||
# 40 byte headers only have the three components in the
|
# 40 byte headers only have the three components in the
|
||||||
|
|
Loading…
Reference in New Issue
Block a user