mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-27 10:26:19 +03:00
Simplified is_animated
This commit is contained in:
parent
0306b80ef7
commit
d84fd20f0c
|
@ -229,11 +229,6 @@ class TestFileTiff(PillowTestCase):
|
||||||
['Tests/images/multipage-lastframe.tif', 1],
|
['Tests/images/multipage-lastframe.tif', 1],
|
||||||
['Tests/images/multipage.tiff', 3]
|
['Tests/images/multipage.tiff', 3]
|
||||||
]:
|
]:
|
||||||
# Test is_animated before n_frames
|
|
||||||
im = Image.open(path)
|
|
||||||
self.assertEqual(im.is_animated, n_frames != 1)
|
|
||||||
|
|
||||||
# Test is_animated after n_frames
|
|
||||||
im = Image.open(path)
|
im = Image.open(path)
|
||||||
self.assertEqual(im.n_frames, n_frames)
|
self.assertEqual(im.n_frames, n_frames)
|
||||||
self.assertEqual(im.is_animated, n_frames != 1)
|
self.assertEqual(im.is_animated, n_frames != 1)
|
||||||
|
|
|
@ -985,7 +985,6 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
self.__fp = self.fp
|
self.__fp = self.fp
|
||||||
self._frame_pos = []
|
self._frame_pos = []
|
||||||
self._n_frames = None
|
self._n_frames = None
|
||||||
self._is_animated = None
|
|
||||||
|
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
print("*** TiffImageFile._open ***")
|
print("*** TiffImageFile._open ***")
|
||||||
|
@ -1009,19 +1008,6 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_animated(self):
|
def is_animated(self):
|
||||||
if self._is_animated is None:
|
|
||||||
if self._n_frames is not None:
|
|
||||||
self._is_animated = self._n_frames != 1
|
|
||||||
else:
|
|
||||||
current = self.tell()
|
|
||||||
|
|
||||||
try:
|
|
||||||
self.seek(1)
|
|
||||||
self._is_animated = True
|
|
||||||
except EOFError:
|
|
||||||
self._is_animated = False
|
|
||||||
|
|
||||||
self.seek(current)
|
|
||||||
return self._is_animated
|
return self._is_animated
|
||||||
|
|
||||||
def seek(self, frame):
|
def seek(self, frame):
|
||||||
|
@ -1053,6 +1039,8 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
print("Loading tags, location: %s" % self.fp.tell())
|
print("Loading tags, location: %s" % self.fp.tell())
|
||||||
self.tag_v2.load(self.fp)
|
self.tag_v2.load(self.fp)
|
||||||
self.__next = self.tag_v2.next
|
self.__next = self.tag_v2.next
|
||||||
|
if len(self._frame_pos) == 1:
|
||||||
|
self._is_animated = self.__next != 0
|
||||||
self.__frame += 1
|
self.__frame += 1
|
||||||
self.fp.seek(self._frame_pos[frame])
|
self.fp.seek(self._frame_pos[frame])
|
||||||
self.tag_v2.load(self.fp)
|
self.tag_v2.load(self.fp)
|
||||||
|
@ -1086,7 +1074,7 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
def load_end(self):
|
def load_end(self):
|
||||||
# allow closing if we're on the first frame, there's no next
|
# allow closing if we're on the first frame, there's no next
|
||||||
# This is the ImageFile.load path only, libtiff specific below.
|
# This is the ImageFile.load path only, libtiff specific below.
|
||||||
if len(self._frame_pos) == 1 and not self.__next:
|
if not self._is_animated:
|
||||||
self._close_exclusive_fp_after_loading = True
|
self._close_exclusive_fp_after_loading = True
|
||||||
|
|
||||||
def _load_libtiff(self):
|
def _load_libtiff(self):
|
||||||
|
@ -1166,8 +1154,7 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
self.tile = []
|
self.tile = []
|
||||||
self.readonly = 0
|
self.readonly = 0
|
||||||
# libtiff closed the fp in a, we need to close self.fp, if possible
|
# libtiff closed the fp in a, we need to close self.fp, if possible
|
||||||
if self._exclusive_fp:
|
if self._exclusive_fp and not self._is_animated:
|
||||||
if len(self._frame_pos) == 1 and not self.__next:
|
|
||||||
self.fp.close()
|
self.fp.close()
|
||||||
self.fp = None # might be shared
|
self.fp = None # might be shared
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user