Enabled seeking in MPO files.

Note to self: either put the offset in the load_seek() definition or
the tile definition, not both.
This commit is contained in:
Eric W. Brown 2014-07-23 11:27:46 -04:00
parent 6605bf22e5
commit 832e11bed5
2 changed files with 22 additions and 1 deletions

View File

@ -49,14 +49,21 @@ class MpoImageFile(JpegImagePlugin.JpegImageFile):
self.__fp.seek(self.__mpoffsets[0]) # get ready to read first frame
self.__frame = 0
self.offset = 0
# for now we can only handle reading and individual frame extraction
self.readonly = 1
def load_seek(self, pos):
self.__fp.seek(pos)
def seek(self, frame):
if frame < 0 or frame >= self.__framecount:
raise EOFError("no more images in MPO file")
else:
self.fp = self.__fp
self.fp.seek(self.__mpoffsets[frame])
self.offset = self.__mpoffsets[frame]
self.tile = [
("jpeg", (0, 0) + self.size, self.offset, (self.mode, ""))
]
self.__frame = frame
def tell(self):

View File

@ -73,6 +73,20 @@ class TestFileMpo(PillowTestCase):
# and this one, too
im.seek(0)
self.assertEqual(im.tell(), 0)
def test_image_grab(self):
for test_file in test_files:
im = Image.open(test_file)
self.assertEqual(im.tell(), 0)
im0 = im.tobytes()
im.seek(1)
self.assertEqual(im.tell(), 1)
im1 = im.tobytes()
im.seek(0)
self.assertEqual(im.tell(), 0)
im0 = im.tobytes()
self.assertEqual(im0, im02)
self.assertNotEqual(im0, im1)
if __name__ == '__main__':