mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +03:00
If we can't read a file due to unsupported compression, raise an error
This commit is contained in:
parent
bc34bda2b8
commit
fef3ceb2c0
|
@ -45,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])
|
||||
|
@ -61,7 +61,7 @@ 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:])
|
||||
|
@ -76,8 +76,7 @@ class SgiImageFile(ImageFile.ImageFile):
|
|||
("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
|
||||
|
@ -87,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")
|
||||
|
||||
# End of file
|
||||
|
|
|
@ -5,44 +5,32 @@ from PIL import Image
|
|||
|
||||
class TestFileSgi(PillowTestCase):
|
||||
|
||||
def sanity(self, filename, expected_mode, expected_size=(128, 128)):
|
||||
# Act
|
||||
im = Image.open(filename)
|
||||
|
||||
# Assert
|
||||
self.assertEqual(im.mode, expected_mode)
|
||||
self.assertEqual(im.size, expected_size)
|
||||
|
||||
def test_rgb(self):
|
||||
# Arrange
|
||||
# Created with ImageMagick then renamed:
|
||||
# convert lena.ppm lena.sgi
|
||||
test_file = "Tests/images/lena.rgb"
|
||||
expected_mode = "RGB"
|
||||
|
||||
# Act / Assert
|
||||
self.sanity(test_file, expected_mode)
|
||||
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"
|
||||
expected_mode = "L"
|
||||
|
||||
# Act / Assert
|
||||
self.sanity(test_file, expected_mode)
|
||||
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"
|
||||
expected_mode = "RGBA"
|
||||
expected_size = (200, 150)
|
||||
|
||||
# Act / Assert
|
||||
self.sanity(test_file, expected_mode, expected_size)
|
||||
self.assertRaises(ValueError, lambda: Image.open(test_file))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in New Issue
Block a user