mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-28 19:06:18 +03:00
Use frame count from FLI header
This commit is contained in:
parent
5f5ac09158
commit
25e467a756
|
@ -38,7 +38,7 @@ class FliImageFile(ImageFile.ImageFile):
|
||||||
format = "FLI"
|
format = "FLI"
|
||||||
format_description = "Autodesk FLI/FLC Animation"
|
format_description = "Autodesk FLI/FLC Animation"
|
||||||
_close_exclusive_fp_after_loading = False
|
_close_exclusive_fp_after_loading = False
|
||||||
|
|
||||||
def _open(self):
|
def _open(self):
|
||||||
|
|
||||||
# HEAD
|
# HEAD
|
||||||
|
@ -49,6 +49,9 @@ class FliImageFile(ImageFile.ImageFile):
|
||||||
s[20:22] == b"\x00\x00"): # reserved
|
s[20:22] == b"\x00\x00"): # reserved
|
||||||
raise SyntaxError("not an FLI/FLC file")
|
raise SyntaxError("not an FLI/FLC file")
|
||||||
|
|
||||||
|
# frames
|
||||||
|
self.__framecount = i16(s[6:8])
|
||||||
|
|
||||||
# image characteristics
|
# image characteristics
|
||||||
self.mode = "P"
|
self.mode = "P"
|
||||||
self.size = i16(s[8:10]), i16(s[10:12])
|
self.size = i16(s[8:10]), i16(s[10:12])
|
||||||
|
@ -86,8 +89,6 @@ class FliImageFile(ImageFile.ImageFile):
|
||||||
self.__frame = -1
|
self.__frame = -1
|
||||||
self.__fp = self.fp
|
self.__fp = self.fp
|
||||||
self.__rewind = self.fp.tell()
|
self.__rewind = self.fp.tell()
|
||||||
self._n_frames = None
|
|
||||||
self._is_animated = None
|
|
||||||
self.seek(0)
|
self.seek(0)
|
||||||
|
|
||||||
def _palette(self, palette, shift):
|
def _palette(self, palette, shift):
|
||||||
|
@ -110,43 +111,22 @@ class FliImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def n_frames(self):
|
def n_frames(self):
|
||||||
if self._n_frames is None:
|
return self.__framecount
|
||||||
current = self.tell()
|
|
||||||
try:
|
|
||||||
while True:
|
|
||||||
self.seek(self.tell() + 1)
|
|
||||||
except EOFError:
|
|
||||||
self._n_frames = self.tell() + 1
|
|
||||||
self.seek(current)
|
|
||||||
return self._n_frames
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_animated(self):
|
def is_animated(self):
|
||||||
if self._is_animated is None:
|
return self.__framecount > 1
|
||||||
current = self.tell()
|
|
||||||
|
|
||||||
try:
|
|
||||||
self.seek(1)
|
|
||||||
self._is_animated = True
|
|
||||||
except EOFError:
|
|
||||||
self._is_animated = False
|
|
||||||
|
|
||||||
self.seek(current)
|
|
||||||
return self._is_animated
|
|
||||||
|
|
||||||
def seek(self, frame):
|
def seek(self, frame):
|
||||||
if frame == self.__frame:
|
if frame == self.__frame:
|
||||||
return
|
return
|
||||||
if frame < self.__frame:
|
if frame < self.__frame:
|
||||||
self._seek(0)
|
self._seek(0)
|
||||||
|
if frame >= self.__framecount:
|
||||||
|
raise EOFError("no more images in FLI file")
|
||||||
|
|
||||||
last_frame = self.__frame
|
|
||||||
for f in range(self.__frame + 1, frame + 1):
|
for f in range(self.__frame + 1, frame + 1):
|
||||||
try:
|
self._seek(f)
|
||||||
self._seek(f)
|
|
||||||
except EOFError:
|
|
||||||
self.seek(last_frame)
|
|
||||||
raise EOFError("no more images in FLI file")
|
|
||||||
|
|
||||||
def _seek(self, frame):
|
def _seek(self, frame):
|
||||||
if frame == 0:
|
if frame == 0:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user