2015-07-03 08:03:25 +03:00
|
|
|
from PIL import Image, SgiImagePlugin
|
2014-07-16 22:28:17 +04:00
|
|
|
|
2019-07-06 23:40:53 +03:00
|
|
|
from .helper import PillowTestCase, hopper
|
|
|
|
|
2014-07-16 22:28:17 +04:00
|
|
|
|
|
|
|
class TestFileSgi(PillowTestCase):
|
|
|
|
def test_rgb(self):
|
|
|
|
# Created with ImageMagick then renamed:
|
2016-12-31 01:20:46 +03:00
|
|
|
# convert hopper.ppm -compress None sgi:hopper.rgb
|
2014-09-04 11:31:16 +04:00
|
|
|
test_file = "Tests/images/hopper.rgb"
|
2014-07-16 22:28:17 +04:00
|
|
|
|
2019-11-25 23:03:23 +03:00
|
|
|
with Image.open(test_file) as im:
|
|
|
|
self.assert_image_equal(im, hopper())
|
|
|
|
self.assertEqual(im.get_format_mimetype(), "image/rgb")
|
2014-07-16 22:28:17 +04:00
|
|
|
|
2017-07-29 00:12:46 +03:00
|
|
|
def test_rgb16(self):
|
|
|
|
test_file = "Tests/images/hopper16.rgb"
|
|
|
|
|
2019-11-25 23:03:23 +03:00
|
|
|
with Image.open(test_file) as im:
|
|
|
|
self.assert_image_equal(im, hopper())
|
2017-07-29 00:12:46 +03:00
|
|
|
|
2014-07-16 22:28:17 +04:00
|
|
|
def test_l(self):
|
2016-12-31 01:20:46 +03:00
|
|
|
# Created with ImageMagick
|
|
|
|
# convert hopper.ppm -monochrome -compress None sgi:hopper.bw
|
2014-09-04 11:31:16 +04:00
|
|
|
test_file = "Tests/images/hopper.bw"
|
2014-07-16 22:28:17 +04:00
|
|
|
|
2019-11-25 23:03:23 +03:00
|
|
|
with Image.open(test_file) as im:
|
|
|
|
self.assert_image_similar(im, hopper("L"), 2)
|
|
|
|
self.assertEqual(im.get_format_mimetype(), "image/sgi")
|
2014-07-16 22:28:17 +04:00
|
|
|
|
|
|
|
def test_rgba(self):
|
|
|
|
# Created with ImageMagick:
|
2016-12-31 01:20:46 +03:00
|
|
|
# convert transparent.png -compress None transparent.sgi
|
2014-07-16 22:28:17 +04:00
|
|
|
test_file = "Tests/images/transparent.sgi"
|
2017-04-20 14:14:23 +03:00
|
|
|
|
2019-11-25 23:03:23 +03:00
|
|
|
with Image.open(test_file) as im:
|
|
|
|
with Image.open("Tests/images/transparent.png") as target:
|
|
|
|
self.assert_image_equal(im, target)
|
|
|
|
self.assertEqual(im.get_format_mimetype(), "image/sgi")
|
2016-12-31 01:20:46 +03:00
|
|
|
|
|
|
|
def test_rle(self):
|
2017-07-22 10:34:06 +03:00
|
|
|
# Created with ImageMagick:
|
2016-12-31 01:20:46 +03:00
|
|
|
# convert hopper.ppm hopper.sgi
|
|
|
|
test_file = "Tests/images/hopper.sgi"
|
|
|
|
|
2019-11-25 23:03:23 +03:00
|
|
|
with Image.open(test_file) as im:
|
|
|
|
with Image.open("Tests/images/hopper.rgb") as target:
|
|
|
|
self.assert_image_equal(im, target)
|
2017-07-29 00:12:46 +03:00
|
|
|
|
|
|
|
def test_rle16(self):
|
|
|
|
test_file = "Tests/images/tv16.sgi"
|
|
|
|
|
2019-11-25 23:03:23 +03:00
|
|
|
with Image.open(test_file) as im:
|
|
|
|
with Image.open("Tests/images/tv.rgb") as target:
|
|
|
|
self.assert_image_equal(im, target)
|
2014-07-16 22:28:17 +04:00
|
|
|
|
2015-07-03 08:03:25 +03:00
|
|
|
def test_invalid_file(self):
|
2015-07-03 09:22:56 +03:00
|
|
|
invalid_file = "Tests/images/flower.jpg"
|
|
|
|
|
2019-06-13 18:54:11 +03:00
|
|
|
self.assertRaises(ValueError, SgiImagePlugin.SgiImageFile, invalid_file)
|
2015-07-03 08:03:25 +03:00
|
|
|
|
2016-12-31 01:31:35 +03:00
|
|
|
def test_write(self):
|
|
|
|
def roundtrip(img):
|
2019-06-13 18:54:11 +03:00
|
|
|
out = self.tempfile("temp.sgi")
|
|
|
|
img.save(out, format="sgi")
|
2019-11-25 23:03:23 +03:00
|
|
|
with Image.open(out) as reloaded:
|
|
|
|
self.assert_image_equal(img, reloaded)
|
2016-12-31 01:31:35 +03:00
|
|
|
|
2019-06-13 18:54:11 +03:00
|
|
|
for mode in ("L", "RGB", "RGBA"):
|
2016-12-31 01:31:35 +03:00
|
|
|
roundtrip(hopper(mode))
|
|
|
|
|
2017-08-07 14:57:59 +03:00
|
|
|
# Test 1 dimension for an L mode image
|
2019-06-13 18:54:11 +03:00
|
|
|
roundtrip(Image.new("L", (10, 1)))
|
2017-08-07 14:57:59 +03:00
|
|
|
|
2017-09-29 13:39:43 +03:00
|
|
|
def test_write16(self):
|
|
|
|
test_file = "Tests/images/hopper16.rgb"
|
|
|
|
|
2019-11-25 23:03:23 +03:00
|
|
|
with Image.open(test_file) as im:
|
|
|
|
out = self.tempfile("temp.sgi")
|
|
|
|
im.save(out, format="sgi", bpc=2)
|
2017-09-29 13:39:43 +03:00
|
|
|
|
2019-11-25 23:03:23 +03:00
|
|
|
with Image.open(out) as reloaded:
|
|
|
|
self.assert_image_equal(im, reloaded)
|
2018-01-27 09:07:24 +03:00
|
|
|
|
2017-08-07 12:21:54 +03:00
|
|
|
def test_unsupported_mode(self):
|
2019-06-13 18:54:11 +03:00
|
|
|
im = hopper("LA")
|
|
|
|
out = self.tempfile("temp.sgi")
|
2017-08-07 12:21:54 +03:00
|
|
|
|
2019-06-13 18:54:11 +03:00
|
|
|
self.assertRaises(ValueError, im.save, out, format="sgi")
|