mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-13 10:46:16 +03:00
Changed GIF seek to remove previous info items
This commit is contained in:
parent
5af867df4a
commit
fbc121d678
|
@ -134,13 +134,15 @@ class TestFileGif(PillowTestCase):
|
|||
# Multiframe image
|
||||
im = Image.open("Tests/images/dispose_bgnd.gif")
|
||||
|
||||
info = im.info.copy()
|
||||
|
||||
out = self.tempfile('temp.gif')
|
||||
im.save(out, save_all=True)
|
||||
reread = Image.open(out)
|
||||
|
||||
for header in important_headers:
|
||||
self.assertEqual(
|
||||
im.info[header],
|
||||
info[header],
|
||||
reread.info[header]
|
||||
)
|
||||
|
||||
|
@ -207,6 +209,15 @@ class TestFileGif(PillowTestCase):
|
|||
except EOFError:
|
||||
self.assertEqual(framecount, 5)
|
||||
|
||||
def test_seek_info(self):
|
||||
im = Image.open("Tests/images/iss634.gif")
|
||||
info = im.info.copy()
|
||||
|
||||
im.seek(1)
|
||||
im.seek(0)
|
||||
|
||||
self.assertEqual(im.info, info)
|
||||
|
||||
def test_n_frames(self):
|
||||
for path, n_frames in [
|
||||
[TEST_GIF, 1],
|
||||
|
|
|
@ -166,6 +166,7 @@ class GifImageFile(ImageFile.ImageFile):
|
|||
from copy import copy
|
||||
self.palette = copy(self.global_palette)
|
||||
|
||||
info = {}
|
||||
while True:
|
||||
|
||||
s = self.fp.read(1)
|
||||
|
@ -184,8 +185,8 @@ class GifImageFile(ImageFile.ImageFile):
|
|||
#
|
||||
flags = i8(block[0])
|
||||
if flags & 1:
|
||||
self.info["transparency"] = i8(block[3])
|
||||
self.info["duration"] = i16(block[1:3]) * 10
|
||||
info["transparency"] = i8(block[3])
|
||||
info["duration"] = i16(block[1:3]) * 10
|
||||
|
||||
# disposal method - find the value of bits 4 - 6
|
||||
dispose_bits = 0b00011100 & flags
|
||||
|
@ -200,16 +201,16 @@ class GifImageFile(ImageFile.ImageFile):
|
|||
#
|
||||
# comment extension
|
||||
#
|
||||
self.info["comment"] = block
|
||||
info["comment"] = block
|
||||
elif i8(s) == 255:
|
||||
#
|
||||
# application extension
|
||||
#
|
||||
self.info["extension"] = block, self.fp.tell()
|
||||
info["extension"] = block, self.fp.tell()
|
||||
if block[:11] == b"NETSCAPE2.0":
|
||||
block = self.data()
|
||||
if len(block) >= 3 and i8(block[0]) == 1:
|
||||
self.info["loop"] = i16(block[1:3])
|
||||
info["loop"] = i16(block[1:3])
|
||||
while self.data():
|
||||
pass
|
||||
|
||||
|
@ -268,6 +269,12 @@ class GifImageFile(ImageFile.ImageFile):
|
|||
# self.__fp = None
|
||||
raise EOFError
|
||||
|
||||
for k in ["transparency", "duration", "comment", "extension", "loop"]:
|
||||
if k in info:
|
||||
self.info[k] = info[k]
|
||||
elif k in self.info:
|
||||
del self.info[k]
|
||||
|
||||
self.mode = "L"
|
||||
if self.palette:
|
||||
self.mode = "P"
|
||||
|
|
Loading…
Reference in New Issue
Block a user