mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-06 21:40:09 +03:00
Merge 14d1ac6389
into cf8f191c54
This commit is contained in:
commit
a348c448ac
|
@ -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")
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue
Block a user