mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-27 01:34:24 +03:00
Added _min_frame property
This commit is contained in:
parent
f61b70aa8f
commit
c8b65f4efd
|
@ -78,6 +78,8 @@ class ImageFile(Image.Image):
|
||||||
def __init__(self, fp=None, filename=None):
|
def __init__(self, fp=None, filename=None):
|
||||||
Image.Image.__init__(self)
|
Image.Image.__init__(self)
|
||||||
|
|
||||||
|
self._min_frame = 0
|
||||||
|
|
||||||
self.tile = None
|
self.tile = None
|
||||||
self.readonly = 1 # until we know better
|
self.readonly = 1 # until we know better
|
||||||
|
|
||||||
|
@ -276,11 +278,11 @@ class ImageFile(Image.Image):
|
||||||
# pass
|
# pass
|
||||||
|
|
||||||
def _seek_check(self, frame):
|
def _seek_check(self, frame):
|
||||||
if (frame < 0 or
|
if (frame < self._min_frame or
|
||||||
# Only check upper limit on frames if additional seek operations
|
# Only check upper limit on frames if additional seek operations
|
||||||
# are not required to do so
|
# are not required to do so
|
||||||
(not (hasattr(self, "_n_frames") and self._n_frames is None) and
|
(not (hasattr(self, "_n_frames") and self._n_frames is None) and
|
||||||
frame >= self.n_frames)):
|
frame >= self.n_frames+self._min_frame)):
|
||||||
raise EOFError("attempt to seek outside sequence")
|
raise EOFError("attempt to seek outside sequence")
|
||||||
|
|
||||||
return self.tell() != frame
|
return self.tell() != frame
|
||||||
|
|
|
@ -124,7 +124,8 @@ class PsdImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
# keep the file open
|
# keep the file open
|
||||||
self._fp = self.fp
|
self._fp = self.fp
|
||||||
self.frame = 0
|
self.frame = 1
|
||||||
|
self._min_frame = 1
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def n_frames(self):
|
def n_frames(self):
|
||||||
|
@ -140,8 +141,6 @@ class PsdImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
# seek to given layer (1..max)
|
# seek to given layer (1..max)
|
||||||
try:
|
try:
|
||||||
if layer == 0:
|
|
||||||
raise IndexError
|
|
||||||
name, mode, bbox, tile = self.layers[layer-1]
|
name, mode, bbox, tile = self.layers[layer-1]
|
||||||
self.mode = mode
|
self.mode = mode
|
||||||
self.tile = tile
|
self.tile = tile
|
||||||
|
|
|
@ -34,26 +34,23 @@ class TestImagePsd(PillowTestCase):
|
||||||
|
|
||||||
def test_eoferror(self):
|
def test_eoferror(self):
|
||||||
im = Image.open(test_file)
|
im = Image.open(test_file)
|
||||||
|
|
||||||
n_frames = im.n_frames
|
|
||||||
while True:
|
|
||||||
n_frames -= 1
|
|
||||||
try:
|
|
||||||
# PSD seek index starts at 1 rather than 0
|
# PSD seek index starts at 1 rather than 0
|
||||||
im.seek(n_frames+1)
|
n_frames = im.n_frames+1
|
||||||
break
|
|
||||||
except EOFError:
|
# Test seeking past the last frame
|
||||||
|
self.assertRaises(EOFError, im.seek, n_frames)
|
||||||
self.assertLess(im.tell(), n_frames)
|
self.assertLess(im.tell(), n_frames)
|
||||||
|
|
||||||
|
# Test that seeking to the last frame does not raise an error
|
||||||
|
im.seek(n_frames-1)
|
||||||
|
|
||||||
def test_seek_tell(self):
|
def test_seek_tell(self):
|
||||||
im = Image.open(test_file)
|
im = Image.open(test_file)
|
||||||
|
|
||||||
layer_number = im.tell()
|
layer_number = im.tell()
|
||||||
self.assertEqual(layer_number, 0)
|
self.assertEqual(layer_number, 1)
|
||||||
|
|
||||||
im.seek(0)
|
self.assertRaises(EOFError, im.seek, 0)
|
||||||
layer_number = im.tell()
|
|
||||||
self.assertEqual(layer_number, 0)
|
|
||||||
|
|
||||||
im.seek(1)
|
im.seek(1)
|
||||||
layer_number = im.tell()
|
layer_number = im.tell()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user