diff --git a/PIL/CurImagePlugin.py b/PIL/CurImagePlugin.py index 4cf2882e2..0178957ee 100644 --- a/PIL/CurImagePlugin.py +++ b/PIL/CurImagePlugin.py @@ -33,6 +33,7 @@ i32 = _binary.i32le def _accept(prefix): return prefix[:4] == b"\0\0\2\0" + ## # Image plugin for Windows Cursor files. @@ -48,7 +49,7 @@ class CurImageFile(BmpImagePlugin.BmpImageFile): # check magic s = self.fp.read(6) if not _accept(s): - raise SyntaxError("not an CUR file") + raise SyntaxError("not a CUR file") # pick the largest cursor in the file m = b"" @@ -58,14 +59,14 @@ class CurImageFile(BmpImagePlugin.BmpImageFile): m = s elif i8(s[0]) > i8(m[0]) and i8(s[1]) > i8(m[1]): m = s - #print "width", i8(s[0]) - #print "height", i8(s[1]) - #print "colors", i8(s[2]) - #print "reserved", i8(s[3]) - #print "hotspot x", i16(s[4:]) - #print "hotspot y", i16(s[6:]) - #print "bytes", i32(s[8:]) - #print "offset", i32(s[12:]) + # print "width", i8(s[0]) + # print "height", i8(s[1]) + # print "colors", i8(s[2]) + # print "reserved", i8(s[3]) + # print "hotspot x", i16(s[4:]) + # print "hotspot y", i16(s[6:]) + # print "bytes", i32(s[8:]) + # print "offset", i32(s[12:]) # load as bitmap self._bitmap(i32(m[12:]) + offset) @@ -73,7 +74,7 @@ class CurImageFile(BmpImagePlugin.BmpImageFile): # patch up the bitmap height self.size = self.size[0], self.size[1]//2 d, e, o, a = self.tile[0] - self.tile[0] = d, (0,0)+self.size, o, a + self.tile[0] = d, (0, 0)+self.size, o, a return diff --git a/PIL/DcxImagePlugin.py b/PIL/DcxImagePlugin.py index 631875e68..0940b3935 100644 --- a/PIL/DcxImagePlugin.py +++ b/PIL/DcxImagePlugin.py @@ -27,13 +27,15 @@ from PIL import Image, _binary from PIL.PcxImagePlugin import PcxImageFile -MAGIC = 0x3ADE68B1 # QUIZ: what's this value, then? +MAGIC = 0x3ADE68B1 # QUIZ: what's this value, then? i32 = _binary.i32le + def _accept(prefix): return i32(prefix) == MAGIC + ## # Image plugin for the Intel DCX format. diff --git a/Tests/images/deerstalker.cur b/Tests/images/deerstalker.cur new file mode 100644 index 000000000..16e4bfa52 Binary files /dev/null and b/Tests/images/deerstalker.cur differ diff --git a/Tests/images/lena.dcx b/Tests/images/lena.dcx new file mode 100644 index 000000000..d05370be8 Binary files /dev/null and b/Tests/images/lena.dcx differ diff --git a/Tests/test_file_cur.py b/Tests/test_file_cur.py new file mode 100644 index 000000000..54bfe84fe --- /dev/null +++ b/Tests/test_file_cur.py @@ -0,0 +1,27 @@ +from helper import unittest, PillowTestCase + +from PIL import Image, CurImagePlugin + + +class TestFileCur(PillowTestCase): + + def test_sanity(self): + # Arrange + test_file = "Tests/images/deerstalker.cur" + + # Act + im = Image.open(test_file) + + # Assert + self.assertEqual(im.size, (32, 32)) + self.assertIsInstance(im, CurImagePlugin.CurImageFile) + # Check some pixel colors to ensure image is loaded properly + self.assertEqual(im.getpixel((10, 1)), (0, 0, 0)) + self.assertEqual(im.getpixel((11, 1)), (253, 254, 254)) + self.assertEqual(im.getpixel((16, 16)), (84, 87, 86)) + + +if __name__ == '__main__': + unittest.main() + +# End of file diff --git a/Tests/test_file_dcx.py b/Tests/test_file_dcx.py new file mode 100644 index 000000000..9a6183651 --- /dev/null +++ b/Tests/test_file_dcx.py @@ -0,0 +1,45 @@ +from helper import unittest, PillowTestCase, lena + +from PIL import Image, DcxImagePlugin + +# Created with ImageMagick: convert lena.ppm lena.dcx +TEST_FILE = "Tests/images/lena.dcx" + + +class TestFileDcx(PillowTestCase): + + def test_sanity(self): + # Arrange + + # Act + im = Image.open(TEST_FILE) + + # Assert + self.assertEqual(im.size, (128, 128)) + self.assertIsInstance(im, DcxImagePlugin.DcxImageFile) + orig = lena() + self.assert_image_equal(im, orig) + + def test_tell(self): + # Arrange + im = Image.open(TEST_FILE) + + # Act + frame = im.tell() + + # Assert + self.assertEqual(frame, 0) + + def test_seek_too_far(self): + # Arrange + im = Image.open(TEST_FILE) + frame = 999 # too big on purpose + + # Act / Assert + self.assertRaises(EOFError, lambda: im.seek(frame)) + + +if __name__ == '__main__': + unittest.main() + +# End of file