Allow for different palette entry sizes when correcting offset
This commit is contained in:
parent
93de6a78d8
commit
735d02584b
@ -238,13 +238,21 @@ def test_unsupported_bmp_bitfields_layout() -> None:
|
||||
Image.open(fp)
|
||||
|
||||
|
||||
def test_offset() -> None:
|
||||
@pytest.mark.parametrize(
|
||||
"offset, path",
|
||||
(
|
||||
(26, "pal8os2.bmp"),
|
||||
(54, "pal8.bmp"),
|
||||
),
|
||||
)
|
||||
def test_offset(offset: int, path: str) -> None:
|
||||
image_path = "Tests/images/bmp/g/" + path
|
||||
# Exclude the palette size from the pixel data offset
|
||||
with open("Tests/images/bmp/g/pal8.bmp", "rb") as fp:
|
||||
with open(image_path, "rb") as fp:
|
||||
data = fp.read()
|
||||
data = data[:10] + o32(54) + data[14:]
|
||||
data = data[:10] + o32(offset) + data[14:]
|
||||
with Image.open(io.BytesIO(data)) as im:
|
||||
assert_image_equal_tofile(im, "Tests/images/bmp/g/pal8.bmp")
|
||||
assert_image_equal_tofile(im, image_path)
|
||||
|
||||
|
||||
def test_use_raw_alpha(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
|
||||
@ -181,9 +181,10 @@ class BmpImageFile(ImageFile.ImageFile):
|
||||
assert isinstance(file_info["bits"], int)
|
||||
if not file_info.get("colors", 0):
|
||||
file_info["colors"] = 1 << file_info["bits"]
|
||||
assert isinstance(file_info["palette_padding"], int)
|
||||
assert isinstance(file_info["colors"], int)
|
||||
if offset == 14 + file_info["header_size"] and file_info["bits"] <= 8:
|
||||
offset += 4 * file_info["colors"]
|
||||
offset += file_info["palette_padding"] * file_info["colors"]
|
||||
|
||||
# ---------------------- Check bit depth for unusual unsupported values
|
||||
self._mode, raw_mode = BIT2MODE.get(file_info["bits"], ("", ""))
|
||||
@ -262,7 +263,6 @@ class BmpImageFile(ImageFile.ImageFile):
|
||||
msg = f"Unsupported BMP Palette size ({file_info['colors']})"
|
||||
raise OSError(msg)
|
||||
else:
|
||||
assert isinstance(file_info["palette_padding"], int)
|
||||
padding = file_info["palette_padding"]
|
||||
palette = read(padding * file_info["colors"])
|
||||
grayscale = True
|
||||
|
||||
Loading…
Reference in New Issue
Block a user