2014-09-05 14:03:56 +04:00
|
|
|
from helper import unittest, PillowTestCase, hopper
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-08-27 01:16:01 +04:00
|
|
|
from PIL import Image, ImageSequence, TiffImagePlugin
|
2012-10-16 00:26:38 +04:00
|
|
|
|
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
class TestImageSequence(PillowTestCase):
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
def test_sanity(self):
|
2013-07-01 02:42:19 +04:00
|
|
|
|
2015-04-24 11:24:52 +03:00
|
|
|
test_file = self.tempfile("temp.im")
|
2013-07-01 02:42:19 +04:00
|
|
|
|
2014-09-05 14:03:56 +04:00
|
|
|
im = hopper("RGB")
|
2015-04-24 11:24:52 +03:00
|
|
|
im.save(test_file)
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
seq = ImageSequence.Iterator(im)
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
index = 0
|
|
|
|
for frame in seq:
|
|
|
|
self.assert_image_equal(im, frame)
|
|
|
|
self.assertEqual(im.tell(), index)
|
2014-06-23 14:39:27 +04:00
|
|
|
index += 1
|
2014-06-10 13:10:47 +04:00
|
|
|
|
|
|
|
self.assertEqual(index, 1)
|
|
|
|
|
2015-07-03 08:03:25 +03:00
|
|
|
self.assertRaises(AttributeError, lambda: ImageSequence.Iterator(0))
|
|
|
|
|
2014-08-27 02:30:03 +04:00
|
|
|
def _test_multipage_tiff(self, dbg=False):
|
2014-08-27 01:16:01 +04:00
|
|
|
im = Image.open('Tests/images/multipage.tiff')
|
|
|
|
for index, frame in enumerate(ImageSequence.Iterator(im)):
|
|
|
|
frame.load()
|
|
|
|
self.assertEqual(index, im.tell())
|
|
|
|
frame.convert('RGB')
|
2014-09-05 14:03:56 +04:00
|
|
|
|
2014-08-27 01:16:01 +04:00
|
|
|
def test_tiff(self):
|
2015-04-24 02:26:52 +03:00
|
|
|
# self._test_multipage_tiff(True)
|
2014-08-27 02:30:03 +04:00
|
|
|
self._test_multipage_tiff(False)
|
2014-08-27 01:16:01 +04:00
|
|
|
|
|
|
|
def test_libtiff(self):
|
|
|
|
codecs = dir(Image.core)
|
2014-09-05 14:03:56 +04:00
|
|
|
|
2014-08-27 01:16:01 +04:00
|
|
|
if "libtiff_encoder" not in codecs or "libtiff_decoder" not in codecs:
|
|
|
|
self.skipTest("tiff support not available")
|
|
|
|
|
|
|
|
TiffImagePlugin.READ_LIBTIFF = True
|
2015-04-24 02:26:52 +03:00
|
|
|
# self._test_multipage_tiff(True)
|
2014-08-27 02:30:03 +04:00
|
|
|
self._test_multipage_tiff(False)
|
2014-08-27 01:16:01 +04:00
|
|
|
TiffImagePlugin.READ_LIBTIFF = False
|
2014-09-05 14:03:56 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|
|
|
|
|
|
|
|
# End of file
|