mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-12 10:16:17 +03:00
Merge pull request #8476 from radarhere/jpeg_state
This commit is contained in:
commit
510c84ad03
|
@ -74,6 +74,17 @@ def test_pickle_image(
|
|||
helper_pickle_file(tmp_path, protocol, test_file, test_mode)
|
||||
|
||||
|
||||
def test_pickle_jpeg() -> None:
|
||||
# Arrange
|
||||
with Image.open("Tests/images/hopper.jpg") as image:
|
||||
# Act: roundtrip
|
||||
unpickled_image = pickle.loads(pickle.dumps(image))
|
||||
|
||||
# Assert
|
||||
assert len(unpickled_image.layer) == 3
|
||||
assert unpickled_image.layers == 3
|
||||
|
||||
|
||||
def test_pickle_la_mode_with_palette(tmp_path: Path) -> None:
|
||||
# Arrange
|
||||
filename = str(tmp_path / "temp.pkl")
|
||||
|
|
|
@ -754,7 +754,7 @@ class Image:
|
|||
|
||||
def __setstate__(self, state: list[Any]) -> None:
|
||||
Image.__init__(self)
|
||||
info, mode, size, palette, data = state
|
||||
info, mode, size, palette, data = state[:5]
|
||||
self.info = info
|
||||
self._mode = mode
|
||||
self._size = size
|
||||
|
|
|
@ -395,6 +395,13 @@ class JpegImageFile(ImageFile.ImageFile):
|
|||
return getattr(self, "_" + name)
|
||||
raise AttributeError(name)
|
||||
|
||||
def __getstate__(self) -> list[Any]:
|
||||
return super().__getstate__() + [self.layers, self.layer]
|
||||
|
||||
def __setstate__(self, state: list[Any]) -> None:
|
||||
super().__setstate__(state)
|
||||
self.layers, self.layer = state[5:]
|
||||
|
||||
def load_read(self, read_bytes: int) -> bytes:
|
||||
"""
|
||||
internal: read more image data
|
||||
|
|
Loading…
Reference in New Issue
Block a user