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