mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 09:26:16 +03:00
Merge pull request #8351 from radarhere/type_hint
This commit is contained in:
commit
6377321625
|
@ -1392,7 +1392,9 @@ def test_lzw_bits() -> None:
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
def test_extents(test_file, loading_strategy) -> None:
|
def test_extents(
|
||||||
|
test_file: str, loading_strategy: GifImagePlugin.LoadingStrategy
|
||||||
|
) -> None:
|
||||||
GifImagePlugin.LOADING_STRATEGY = loading_strategy
|
GifImagePlugin.LOADING_STRATEGY = loading_strategy
|
||||||
try:
|
try:
|
||||||
with Image.open("Tests/images/" + test_file) as im:
|
with Image.open("Tests/images/" + test_file) as im:
|
||||||
|
|
|
@ -370,21 +370,27 @@ class PngInfo:
|
||||||
# PNG image stream (IHDR/IEND)
|
# PNG image stream (IHDR/IEND)
|
||||||
|
|
||||||
|
|
||||||
|
class _RewindState(NamedTuple):
|
||||||
|
info: dict[str | tuple[int, int], Any]
|
||||||
|
tile: list[ImageFile._Tile]
|
||||||
|
seq_num: int | None
|
||||||
|
|
||||||
|
|
||||||
class PngStream(ChunkStream):
|
class PngStream(ChunkStream):
|
||||||
def __init__(self, fp):
|
def __init__(self, fp: IO[bytes]) -> None:
|
||||||
super().__init__(fp)
|
super().__init__(fp)
|
||||||
|
|
||||||
# local copies of Image attributes
|
# local copies of Image attributes
|
||||||
self.im_info = {}
|
self.im_info: dict[str | tuple[int, int], Any] = {}
|
||||||
self.im_text = {}
|
self.im_text: dict[str, str | iTXt] = {}
|
||||||
self.im_size = (0, 0)
|
self.im_size = (0, 0)
|
||||||
self.im_mode = None
|
self.im_mode = ""
|
||||||
self.im_tile = None
|
self.im_tile: list[ImageFile._Tile] = []
|
||||||
self.im_palette = None
|
self.im_palette: tuple[str, bytes] | None = None
|
||||||
self.im_custom_mimetype = None
|
self.im_custom_mimetype: str | None = None
|
||||||
self.im_n_frames = None
|
self.im_n_frames: int | None = None
|
||||||
self._seq_num = None
|
self._seq_num: int | None = None
|
||||||
self.rewind_state = None
|
self.rewind_state = _RewindState({}, [], None)
|
||||||
|
|
||||||
self.text_memory = 0
|
self.text_memory = 0
|
||||||
|
|
||||||
|
@ -398,16 +404,16 @@ class PngStream(ChunkStream):
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
|
|
||||||
def save_rewind(self) -> None:
|
def save_rewind(self) -> None:
|
||||||
self.rewind_state = {
|
self.rewind_state = _RewindState(
|
||||||
"info": self.im_info.copy(),
|
self.im_info.copy(),
|
||||||
"tile": self.im_tile,
|
self.im_tile,
|
||||||
"seq_num": self._seq_num,
|
self._seq_num,
|
||||||
}
|
)
|
||||||
|
|
||||||
def rewind(self) -> None:
|
def rewind(self) -> None:
|
||||||
self.im_info = self.rewind_state["info"].copy()
|
self.im_info = self.rewind_state.info.copy()
|
||||||
self.im_tile = self.rewind_state["tile"]
|
self.im_tile = self.rewind_state.tile
|
||||||
self._seq_num = self.rewind_state["seq_num"]
|
self._seq_num = self.rewind_state.seq_num
|
||||||
|
|
||||||
def chunk_iCCP(self, pos: int, length: int) -> bytes:
|
def chunk_iCCP(self, pos: int, length: int) -> bytes:
|
||||||
# ICC profile
|
# ICC profile
|
||||||
|
@ -461,11 +467,11 @@ class PngStream(ChunkStream):
|
||||||
def chunk_IDAT(self, pos: int, length: int) -> NoReturn:
|
def chunk_IDAT(self, pos: int, length: int) -> NoReturn:
|
||||||
# image data
|
# image data
|
||||||
if "bbox" in self.im_info:
|
if "bbox" in self.im_info:
|
||||||
tile = [("zip", self.im_info["bbox"], pos, self.im_rawmode)]
|
tile = [ImageFile._Tile("zip", self.im_info["bbox"], pos, self.im_rawmode)]
|
||||||
else:
|
else:
|
||||||
if self.im_n_frames is not None:
|
if self.im_n_frames is not None:
|
||||||
self.im_info["default_image"] = True
|
self.im_info["default_image"] = True
|
||||||
tile = [("zip", (0, 0) + self.im_size, pos, self.im_rawmode)]
|
tile = [ImageFile._Tile("zip", (0, 0) + self.im_size, pos, self.im_rawmode)]
|
||||||
self.im_tile = tile
|
self.im_tile = tile
|
||||||
self.im_idat = length
|
self.im_idat = length
|
||||||
msg = "image data found"
|
msg = "image data found"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user