Merge pull request #1 from radarhere/patch-2

Handle APNG chunks
This commit is contained in:
pirate486743186 2018-12-27 07:35:51 +01:00 committed by GitHub
commit 0f379a2450
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 12 deletions

View File

@ -6,6 +6,12 @@ from io import BytesIO
import zlib
import sys
try:
from PIL import _webp
HAVE_WEBP = True
except ImportError:
HAVE_WEBP = False
codecs = dir(Image.core)
@ -335,18 +341,6 @@ class TestFilePng(PillowTestCase):
im.load()
self.assertRaises(RuntimeError, im.verify)
def test_apng_load_verify(self):
# Check open/load/verify exception (@PIL150)
TEST_APNG_FILE = "Tests/images/iss634.apng"
im = Image.open(TEST_APNG_FILE)
# Assert that there is no unclosed file warning
self.assert_warning(None, im.verify)
im = Image.open(TEST_APNG_FILE)
im.load()
self.assertRaises(RuntimeError, im.verify)
def test_verify_struct_error(self):
# Check open/load/verify exception (#1755)
@ -569,6 +563,13 @@ class TestFilePng(PillowTestCase):
chunks = PngImagePlugin.getchunks(im)
self.assertEqual(len(chunks), 3)
@unittest.skipUnless(HAVE_WEBP and _webp.HAVE_WEBPANIM,
"WebP support not installed with animation")
def test_apng(self):
im = Image.open("Tests/images/iss634.apng")
expected = Image.open("Tests/images/iss634.webp")
self.assert_image_similar(im, expected, 0.23)
@unittest.skipIf(sys.platform.startswith('win32'), "requires Unix or macOS")
class TestTruncatedPngPLeaks(PillowLeakTestCase):

View File

@ -526,6 +526,19 @@ class PngStream(ChunkStream):
return s
# APNG chunks
def chunk_acTL(self, pos, length):
s = ImageFile._safe_read(self.fp, length)
return s
def chunk_fcTL(self, pos, length):
s = ImageFile._safe_read(self.fp, length)
return s
def chunk_fdAT(self, pos, length):
s = ImageFile._safe_read(self.fp, length)
return s
# --------------------------------------------------------------------
# PNG reader
@ -871,3 +884,4 @@ Image.register_save(PngImageFile.format, _save)
Image.register_extensions(PngImageFile.format, [".png", ".apng"])
Image.register_mime(PngImageFile.format, "image/png")
Image.register_mime(PngImageFile.format, "image/apng")