mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-10 19:56:47 +03:00
Merge pull request #803 from hugovk/SgiImagePlugin
Sanity tests for SgiImagePlugin.py
This commit is contained in:
commit
bf2014ece6
|
@ -31,6 +31,7 @@ i32 = _binary.i32be
|
|||
def _accept(prefix):
|
||||
return i16(prefix) == 474
|
||||
|
||||
|
||||
##
|
||||
# Image plugin for SGI images.
|
||||
|
||||
|
@ -44,7 +45,7 @@ class SgiImageFile(ImageFile.ImageFile):
|
|||
# HEAD
|
||||
s = self.fp.read(512)
|
||||
if i16(s) != 474:
|
||||
raise SyntaxError("not an SGI image file")
|
||||
raise ValueError("Not an SGI image file")
|
||||
|
||||
# relevant header entries
|
||||
compression = i8(s[2])
|
||||
|
@ -60,22 +61,22 @@ class SgiImageFile(ImageFile.ImageFile):
|
|||
elif layout == (1, 3, 4):
|
||||
self.mode = "RGBA"
|
||||
else:
|
||||
raise SyntaxError("unsupported SGI image mode")
|
||||
raise ValueError("Unsupported SGI image mode")
|
||||
|
||||
# size
|
||||
self.size = i16(s[6:]), i16(s[8:])
|
||||
|
||||
|
||||
# decoder info
|
||||
if compression == 0:
|
||||
offset = 512
|
||||
pagesize = self.size[0]*self.size[1]*layout[0]
|
||||
self.tile = []
|
||||
for layer in self.mode:
|
||||
self.tile.append(("raw", (0,0)+self.size, offset, (layer,0,-1)))
|
||||
self.tile.append(
|
||||
("raw", (0, 0)+self.size, offset, (layer, 0, -1)))
|
||||
offset = offset + pagesize
|
||||
elif compression == 1:
|
||||
self.tile = [("sgi_rle", (0,0)+self.size, 512, (self.mode, 0, -1))]
|
||||
raise ValueError("SGI RLE encoding not supported")
|
||||
|
||||
#
|
||||
# registry
|
||||
|
@ -85,5 +86,6 @@ Image.register_open("SGI", SgiImageFile, _accept)
|
|||
Image.register_extension("SGI", ".bw")
|
||||
Image.register_extension("SGI", ".rgb")
|
||||
Image.register_extension("SGI", ".rgba")
|
||||
Image.register_extension("SGI", ".sgi")
|
||||
|
||||
Image.register_extension("SGI", ".sgi") # really?
|
||||
# End of file
|
||||
|
|
BIN
Tests/images/lena.bw
Normal file
BIN
Tests/images/lena.bw
Normal file
Binary file not shown.
BIN
Tests/images/lena.rgb
Normal file
BIN
Tests/images/lena.rgb
Normal file
Binary file not shown.
BIN
Tests/images/transparent.sgi
Normal file
BIN
Tests/images/transparent.sgi
Normal file
Binary file not shown.
39
Tests/test_file_sgi.py
Normal file
39
Tests/test_file_sgi.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
from helper import unittest, PillowTestCase
|
||||
|
||||
from PIL import Image
|
||||
|
||||
|
||||
class TestFileSgi(PillowTestCase):
|
||||
|
||||
def test_rgb(self):
|
||||
# Arrange
|
||||
# Created with ImageMagick then renamed:
|
||||
# convert lena.ppm lena.sgi
|
||||
test_file = "Tests/images/lena.rgb"
|
||||
|
||||
# Act / Assert
|
||||
self.assertRaises(ValueError, lambda: Image.open(test_file))
|
||||
|
||||
def test_l(self):
|
||||
# Arrange
|
||||
# Created with ImageMagick then renamed:
|
||||
# convert lena.ppm -monochrome lena.sgi
|
||||
test_file = "Tests/images/lena.bw"
|
||||
|
||||
# Act / Assert
|
||||
self.assertRaises(ValueError, lambda: Image.open(test_file))
|
||||
|
||||
def test_rgba(self):
|
||||
# Arrange
|
||||
# Created with ImageMagick:
|
||||
# convert transparent.png transparent.sgi
|
||||
test_file = "Tests/images/transparent.sgi"
|
||||
|
||||
# Act / Assert
|
||||
self.assertRaises(ValueError, lambda: Image.open(test_file))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
# End of file
|
Loading…
Reference in New Issue
Block a user