2019-01-13 20:00:12 +03:00
|
|
|
from .helper import unittest, PillowTestCase, hopper
|
2014-01-21 01:05:30 +04:00
|
|
|
|
|
|
|
from PIL import Image
|
|
|
|
|
|
|
|
try:
|
|
|
|
from PIL import _webp
|
2017-09-28 05:28:43 +03:00
|
|
|
HAVE_WEBP = True
|
2015-05-27 02:15:45 +03:00
|
|
|
except ImportError:
|
2017-09-28 05:28:43 +03:00
|
|
|
HAVE_WEBP = False
|
2014-01-21 01:05:30 +04:00
|
|
|
|
2017-10-02 01:23:18 +03:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
class TestFileWebpLossless(PillowTestCase):
|
2014-01-21 01:05:30 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
def setUp(self):
|
2017-09-28 05:28:43 +03:00
|
|
|
if not HAVE_WEBP:
|
2014-06-10 13:10:47 +04:00
|
|
|
self.skipTest('WebP support not installed')
|
2017-09-28 05:28:43 +03:00
|
|
|
return
|
2014-01-21 01:05:30 +04:00
|
|
|
|
2018-10-02 11:55:28 +03:00
|
|
|
if _webp.WebPDecoderVersion() < 0x0200:
|
2014-06-10 13:10:47 +04:00
|
|
|
self.skipTest('lossless not included')
|
2014-01-21 01:05:30 +04:00
|
|
|
|
2018-08-04 00:21:47 +03:00
|
|
|
self.rgb_mode = "RGB"
|
2017-09-28 05:28:43 +03:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
def test_write_lossless_rgb(self):
|
|
|
|
temp_file = self.tempfile("temp.webp")
|
2014-01-21 01:05:30 +04:00
|
|
|
|
2017-09-28 05:28:43 +03:00
|
|
|
hopper(self.rgb_mode).save(temp_file, lossless=True)
|
2014-01-21 01:05:30 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
image = Image.open(temp_file)
|
|
|
|
image.load()
|
2014-01-21 01:05:30 +04:00
|
|
|
|
2017-09-28 05:28:43 +03:00
|
|
|
self.assertEqual(image.mode, self.rgb_mode)
|
2014-06-10 13:10:47 +04:00
|
|
|
self.assertEqual(image.size, (128, 128))
|
|
|
|
self.assertEqual(image.format, "WEBP")
|
|
|
|
image.load()
|
|
|
|
image.getdata()
|
2014-01-21 01:05:30 +04:00
|
|
|
|
2017-09-28 05:28:43 +03:00
|
|
|
self.assert_image_equal(image, hopper(self.rgb_mode))
|
2014-01-21 01:05:30 +04:00
|
|
|
|
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|