Added support for reading all Windows 1 formats

This commit is contained in:
Andrew Murray 2023-10-01 22:51:04 +11:00
parent 505c848c2b
commit 261a7281cc
6 changed files with 15 additions and 4 deletions

BIN
Tests/images/ico1both.ico Normal file

Binary file not shown.

Binary file not shown.

View File

@ -229,10 +229,20 @@ def test_draw_reloaded(tmp_path):
assert_image_equal_tofile(im, "Tests/images/hopper_draw.ico") assert_image_equal_tofile(im, "Tests/images/hopper_draw.ico")
def test_ico1_open(): @pytest.mark.parametrize(
with Image.open("Tests/images/ico1.ico") as im: "test_image_path",
(
"Tests/images/ico1device_independent.ico",
"Tests/images/ico1device_dependent.ico",
"Tests/images/ico1both.ico",
),
)
def test_ico1_open(test_image_path):
with Image.open(test_image_path) as im:
assert_image_equal_tofile(im, "Tests/images/ico1.png") assert_image_equal_tofile(im, "Tests/images/ico1.png")
def test_ico1_invalid_file():
with open("Tests/images/flower.jpg", "rb") as fp: with open("Tests/images/flower.jpg", "rb") as fp:
with pytest.raises(SyntaxError): with pytest.raises(SyntaxError):
IcoImagePlugin.Ico1ImageFile(fp) IcoImagePlugin.Ico1ImageFile(fp)

View File

@ -345,7 +345,8 @@ The :py:meth:`~PIL.Image.Image.save` method can take the following keyword argum
ICO1 ICO1
^^^^ ^^^^
Pillow also reads and writes device-independent Windows 1.0 icons. Pillow also reads Windows 1.0 icons in all three formats ("Device-Independent",
"Device-Dependent" and "Both"), and writes them in "Device-Independent" format.
.. versionadded:: 10.1.0 .. versionadded:: 10.1.0

View File

@ -349,7 +349,7 @@ class IcoImageFile(ImageFile.ImageFile):
def _ico1_accept(prefix): def _ico1_accept(prefix):
return prefix[:2] == b"\1\0" return prefix[0] == 1 and prefix[1] in (0, 1, 2)
class Ico1ImageFile(ImageFile.ImageFile): class Ico1ImageFile(ImageFile.ImageFile):