aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/Pillow/py3/PIL/PngImagePlugin.py
diff options
context:
space:
mode:
authorAlexSm <alex@ydb.tech>2024-01-26 16:00:50 +0100
committerGitHub <noreply@github.com>2024-01-26 16:00:50 +0100
commit7ebcfd058d924bcc8c23da70e034f7415687885c (patch)
treee4f00d163c77528c1855f2d7af54a8be83fc1ccb /contrib/python/Pillow/py3/PIL/PngImagePlugin.py
parent64ca2dcd06312b9eef624054ceb5f787e11be79a (diff)
parent6d79e7793c2c462134f4b4a7d911abc7b9b0766f (diff)
downloadydb-7ebcfd058d924bcc8c23da70e034f7415687885c.tar.gz
Merge pull request #1260 from ydb-platform/mergelibs10
mergelibs10
Diffstat (limited to 'contrib/python/Pillow/py3/PIL/PngImagePlugin.py')
-rw-r--r--contrib/python/Pillow/py3/PIL/PngImagePlugin.py24
1 files changed, 16 insertions, 8 deletions
diff --git a/contrib/python/Pillow/py3/PIL/PngImagePlugin.py b/contrib/python/Pillow/py3/PIL/PngImagePlugin.py
index 5e5a8cf6a2..e4ed938801 100644
--- a/contrib/python/Pillow/py3/PIL/PngImagePlugin.py
+++ b/contrib/python/Pillow/py3/PIL/PngImagePlugin.py
@@ -30,6 +30,7 @@
#
# See the README file for information on usage and redistribution.
#
+from __future__ import annotations
import itertools
import logging
@@ -56,7 +57,7 @@ _MAGIC = b"\211PNG\r\n\032\n"
_MODES = {
# supported bits/color combinations, and corresponding modes/rawmodes
- # Greyscale
+ # Grayscale
(1, 0): ("1", "1"),
(2, 0): ("L", "L;2"),
(4, 0): ("L", "L;4"),
@@ -70,7 +71,7 @@ _MODES = {
(2, 3): ("P", "P;2"),
(4, 3): ("P", "P;4"),
(8, 3): ("P", "P"),
- # Greyscale with alpha
+ # Grayscale with alpha
(8, 4): ("LA", "LA"),
(16, 4): ("RGBA", "LA;16B"), # LA;16B->LA not yet available
# Truecolour with alpha
@@ -438,11 +439,12 @@ class PngStream(ChunkStream):
tile = [("zip", (0, 0) + self.im_size, pos, self.im_rawmode)]
self.im_tile = tile
self.im_idat = length
- raise EOFError
+ msg = "image data found"
+ raise EOFError(msg)
def chunk_IEND(self, pos, length):
- # end of PNG image
- raise EOFError
+ msg = "end of PNG image"
+ raise EOFError(msg)
def chunk_PLTE(self, pos, length):
# palette
@@ -891,7 +893,8 @@ class PngImageFile(ImageFile.ImageFile):
self.dispose_extent = self.info.get("bbox")
if not self.tile:
- raise EOFError
+ msg = "image not found in APNG frame"
+ raise EOFError(msg)
# setup frame disposal (actual disposal done when needed in the next _seek())
if self._prev_im is None and self.dispose_op == Disposal.OP_PREVIOUS:
@@ -1154,6 +1157,9 @@ def _write_multiple_frames(im, fp, chunk, rawmode, default_image, append_images)
encoderinfo["duration"] = duration
im_frames.append({"im": im_frame, "bbox": bbox, "encoderinfo": encoderinfo})
+ if len(im_frames) == 1 and not default_image:
+ return im_frames[0]["im"]
+
# animation control
chunk(
fp,
@@ -1389,8 +1395,10 @@ def _save(im, fp, filename, chunk=putchunk, save_all=False):
chunk(fp, b"eXIf", exif)
if save_all:
- _write_multiple_frames(im, fp, chunk, rawmode, default_image, append_images)
- else:
+ im = _write_multiple_frames(
+ im, fp, chunk, rawmode, default_image, append_images
+ )
+ if im:
ImageFile._save(im, _idat(fp, chunk), [("zip", (0, 0) + im.size, 0, rawmode)])
if info: