mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 09:56:17 +03:00
Merge pull request #3479 from radarhere/gif_extension
Allow arbitrary number of comment extension subblocks
This commit is contained in:
commit
a4fccd3dde
BIN
Tests/images/hopper_zero_comment_subblocks.gif
Normal file
BIN
Tests/images/hopper_zero_comment_subblocks.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
|
@ -435,6 +435,23 @@ class TestFileGif(PillowTestCase):
|
||||||
|
|
||||||
self.assertEqual(reread.info['comment'], im.info['comment'])
|
self.assertEqual(reread.info['comment'], im.info['comment'])
|
||||||
|
|
||||||
|
def test_comment_over_255(self):
|
||||||
|
out = self.tempfile('temp.gif')
|
||||||
|
im = Image.new('L', (100, 100), '#000')
|
||||||
|
comment = b"Test comment text"
|
||||||
|
while len(comment) < 256:
|
||||||
|
comment += comment
|
||||||
|
im.info['comment'] = comment
|
||||||
|
im.save(out)
|
||||||
|
reread = Image.open(out)
|
||||||
|
|
||||||
|
self.assertEqual(reread.info['comment'], comment)
|
||||||
|
|
||||||
|
def test_zero_comment_subblocks(self):
|
||||||
|
im = Image.open('Tests/images/hopper_zero_comment_subblocks.gif')
|
||||||
|
expected = Image.open(TEST_GIF)
|
||||||
|
self.assert_image_equal(im, expected)
|
||||||
|
|
||||||
def test_version(self):
|
def test_version(self):
|
||||||
out = self.tempfile('temp.gif')
|
out = self.tempfile('temp.gif')
|
||||||
|
|
||||||
|
|
|
@ -201,7 +201,13 @@ class GifImageFile(ImageFile.ImageFile):
|
||||||
#
|
#
|
||||||
# comment extension
|
# comment extension
|
||||||
#
|
#
|
||||||
|
while block:
|
||||||
|
if "comment" in info:
|
||||||
|
info["comment"] += block
|
||||||
|
else:
|
||||||
info["comment"] = block
|
info["comment"] = block
|
||||||
|
block = self.data()
|
||||||
|
continue
|
||||||
elif i8(s) == 255:
|
elif i8(s) == 255:
|
||||||
#
|
#
|
||||||
# application extension
|
# application extension
|
||||||
|
@ -536,12 +542,14 @@ def _write_local_header(fp, im, offset, flags):
|
||||||
o8(0))
|
o8(0))
|
||||||
|
|
||||||
if "comment" in im.encoderinfo and \
|
if "comment" in im.encoderinfo and \
|
||||||
1 <= len(im.encoderinfo["comment"]) <= 255:
|
1 <= len(im.encoderinfo["comment"]):
|
||||||
fp.write(b"!" +
|
fp.write(b"!" +
|
||||||
o8(254) + # extension intro
|
o8(254)) # extension intro
|
||||||
o8(len(im.encoderinfo["comment"])) +
|
for i in range(0, len(im.encoderinfo["comment"]), 255):
|
||||||
im.encoderinfo["comment"] +
|
subblock = im.encoderinfo["comment"][i:i+255]
|
||||||
o8(0))
|
fp.write(o8(len(subblock)) +
|
||||||
|
subblock)
|
||||||
|
fp.write(o8(0))
|
||||||
if "loop" in im.encoderinfo:
|
if "loop" in im.encoderinfo:
|
||||||
number_of_loops = im.encoderinfo["loop"]
|
number_of_loops = im.encoderinfo["loop"]
|
||||||
fp.write(b"!" +
|
fp.write(b"!" +
|
||||||
|
|
Loading…
Reference in New Issue
Block a user