diff --git a/PIL/XpmImagePlugin.py b/PIL/XpmImagePlugin.py index 701a23b64..517580895 100644 --- a/PIL/XpmImagePlugin.py +++ b/PIL/XpmImagePlugin.py @@ -29,6 +29,7 @@ xpm_head = re.compile(b"\"([0-9]*) ([0-9]*) ([0-9]*) ([0-9]*)") def _accept(prefix): return prefix[:9] == b"/* XPM */" + ## # Image plugin for X11 pixel maps. @@ -86,9 +87,9 @@ class XpmImageFile(ImageFile.ImageFile): elif rgb[0:1] == b"#": # FIXME: handle colour names (see ImagePalette.py) rgb = int(rgb[1:], 16) - palette[c] = o8((rgb >> 16) & 255) +\ - o8((rgb >> 8) & 255) +\ - o8(rgb & 255) + palette[c] = (o8((rgb >> 16) & 255) + + o8((rgb >> 8) & 255) + + o8(rgb & 255)) else: # unknown colour raise ValueError("cannot read this XPM file") diff --git a/Tests/test_file_xpm.py b/Tests/test_file_xpm.py index d79f5fbda..16a811a4c 100644 --- a/Tests/test_file_xpm.py +++ b/Tests/test_file_xpm.py @@ -3,19 +3,29 @@ from helper import unittest, PillowTestCase from PIL import Image # sample ppm stream -file = "Tests/images/lena.xpm" -data = open(file, "rb").read() +TEST_FILE = "Tests/images/lena.xpm" class TestFileXpm(PillowTestCase): def test_sanity(self): - im = Image.open(file) + im = Image.open(TEST_FILE) im.load() self.assertEqual(im.mode, "P") self.assertEqual(im.size, (128, 128)) self.assertEqual(im.format, "XPM") + def test_load_read(self): + # Arrange + im = Image.open(TEST_FILE) + dummy_bytes = 1 + + # Act + data = im.load_read(dummy_bytes) + + # Assert + self.assertEqual(len(data), 16384) + if __name__ == '__main__': unittest.main()