Skip to content

Commit

Permalink
Test DIB header size
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Apr 10, 2024
1 parent e2a5726 commit cab8ad1
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion Tests/test_file_bmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import pytest

from PIL import BmpImagePlugin, Image
from PIL import _binary, BmpImagePlugin, Image

from .helper import (
assert_image_equal,
Expand Down Expand Up @@ -128,6 +128,29 @@ def test_load_dib() -> None:
assert_image_equal_tofile(im, "Tests/images/clipboard_target.png")


@pytest.mark.parametrize(
"header_size, path",
(
(12, "g/pal8os2.bmp"),
(40, "g/pal1.bmp"),
(52, "q/rgb32h52.bmp"),
(56, "q/rgba32h56.bmp"),
(64, "q/pal8os2v2.bmp"),
(108, "g/pal8v4.bmp"),
(124, "g/pal8v5.bmp"),
),
)
def test_dib_header_size(header_size, path):
image_path = "Tests/images/bmp/" + path
with open(image_path, "rb") as fp:
data = fp.read()[14:]
assert _binary.i32le(data) == header_size

dib = io.BytesIO(data)
with Image.open(dib) as im:
im.load()


def test_save_dib(tmp_path: Path) -> None:
outfile = str(tmp_path / "temp.dib")

Expand Down

0 comments on commit cab8ad1

Please sign in to comment.