mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-09-24 13:07:00 +03:00
Merge 067569790b
into b7e0570cb1
This commit is contained in:
commit
734e0ac64b
|
@ -1,8 +1,13 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from io import BytesIO
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from PIL import CurImagePlugin, Image
|
from PIL import CurImagePlugin, Image
|
||||||
|
from PIL._binary import o8
|
||||||
|
from PIL._binary import o16le as o16
|
||||||
|
from PIL._binary import o32le as o32
|
||||||
|
|
||||||
TEST_FILE = "Tests/images/deerstalker.cur"
|
TEST_FILE = "Tests/images/deerstalker.cur"
|
||||||
|
|
||||||
|
@ -17,6 +22,24 @@ def test_sanity() -> None:
|
||||||
assert im.getpixel((16, 16)) == (84, 87, 86, 255)
|
assert im.getpixel((16, 16)) == (84, 87, 86, 255)
|
||||||
|
|
||||||
|
|
||||||
|
def test_largest_cursor() -> None:
|
||||||
|
magic = b"\x00\x00\x02\x00"
|
||||||
|
sizes = ((1, 1), (8, 8), (4, 4))
|
||||||
|
data = magic + o16(len(sizes))
|
||||||
|
for w, h in sizes:
|
||||||
|
image_offset = 6 + len(sizes) * 16 if (w, h) == max(sizes) else 0
|
||||||
|
data += o8(w) + o8(h) + o8(0) * 10 + o32(image_offset)
|
||||||
|
data += (
|
||||||
|
o32(12) # header size
|
||||||
|
+ o16(8) # width
|
||||||
|
+ o16(16) # height
|
||||||
|
+ o16(0) # planes
|
||||||
|
+ o16(1) # bits
|
||||||
|
)
|
||||||
|
with Image.open(BytesIO(data)) as im:
|
||||||
|
assert im.size == (8, 8)
|
||||||
|
|
||||||
|
|
||||||
def test_invalid_file() -> None:
|
def test_invalid_file() -> None:
|
||||||
invalid_file = "Tests/images/flower.jpg"
|
invalid_file = "Tests/images/flower.jpg"
|
||||||
|
|
||||||
|
@ -26,6 +49,7 @@ def test_invalid_file() -> None:
|
||||||
no_cursors_file = "Tests/images/no_cursors.cur"
|
no_cursors_file = "Tests/images/no_cursors.cur"
|
||||||
|
|
||||||
cur = CurImagePlugin.CurImageFile(TEST_FILE)
|
cur = CurImagePlugin.CurImageFile(TEST_FILE)
|
||||||
|
assert cur.fp is not None
|
||||||
cur.fp.close()
|
cur.fp.close()
|
||||||
with open(no_cursors_file, "rb") as cur.fp:
|
with open(no_cursors_file, "rb") as cur.fp:
|
||||||
with pytest.raises(TypeError):
|
with pytest.raises(TypeError):
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
#
|
#
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from . import BmpImagePlugin, Image, ImageFile
|
from . import BmpImagePlugin, Image
|
||||||
from ._binary import i16le as i16
|
from ._binary import i16le as i16
|
||||||
from ._binary import i32le as i32
|
from ._binary import i32le as i32
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ class CurImageFile(BmpImagePlugin.BmpImageFile):
|
||||||
format_description = "Windows Cursor"
|
format_description = "Windows Cursor"
|
||||||
|
|
||||||
def _open(self) -> None:
|
def _open(self) -> None:
|
||||||
|
assert self.fp is not None
|
||||||
offset = self.fp.tell()
|
offset = self.fp.tell()
|
||||||
|
|
||||||
# check magic
|
# check magic
|
||||||
|
@ -63,8 +64,7 @@ class CurImageFile(BmpImagePlugin.BmpImageFile):
|
||||||
|
|
||||||
# patch up the bitmap height
|
# patch up the bitmap height
|
||||||
self._size = self.size[0], self.size[1] // 2
|
self._size = self.size[0], self.size[1] // 2
|
||||||
d, e, o, a = self.tile[0]
|
self.tile = [self.tile[0]._replace(extents=(0, 0) + self.size)]
|
||||||
self.tile[0] = ImageFile._Tile(d, (0, 0) + self.size, o, a)
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in New Issue
Block a user