mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-10 19:56:47 +03:00
Second part of pack tests
This commit is contained in:
parent
ebb10e8e1a
commit
f43b9f396f
|
@ -9,32 +9,9 @@ X = 255
|
|||
|
||||
|
||||
class TestLibPack(PillowTestCase):
|
||||
def test_pack(self):
|
||||
|
||||
def pack(mode, rawmode, in_data=(1, 2, 3, 4)):
|
||||
if len(mode) == 1:
|
||||
im = Image.new(mode, (1, 1), in_data[0])
|
||||
else:
|
||||
im = Image.new(mode, (1, 1), in_data[:len(mode)])
|
||||
|
||||
if py3:
|
||||
return list(im.tobytes("raw", rawmode))
|
||||
else:
|
||||
return [ord(c) for c in im.tobytes("raw", rawmode)]
|
||||
|
||||
order = 1 if Image._ENDIAN == '<' else -1
|
||||
|
||||
|
||||
self.assertEqual(pack("I", "I"), [1, 0, 0, 0][::order])
|
||||
|
||||
self.assertEqual(pack("F", "F"), [0, 0, 128, 63][::order])
|
||||
|
||||
self.assertEqual(pack("CMYK", "CMYK"), [1, 2, 3, 4])
|
||||
self.assertEqual(pack("YCbCr", "YCbCr"), [1, 2, 3])
|
||||
|
||||
def assert_pack(self, mode, rawmode, data, *pixels):
|
||||
"""
|
||||
data - eather raw bytes with data or just number of bytes in rawmode.
|
||||
data - either raw bytes with data or just number of bytes in rawmode.
|
||||
"""
|
||||
im = Image.new(mode, (len(pixels), 1))
|
||||
for x, pixel in enumerate(pixels):
|
||||
|
@ -134,11 +111,74 @@ class TestLibPack(PillowTestCase):
|
|||
self.assert_pack("RGBX", "B", 1, (6,7,1,9), (6,7,2,0), (6,7,3,9))
|
||||
self.assert_pack("RGBX", "X", 1, (6,7,0,1), (6,7,0,2), (0,7,0,3))
|
||||
|
||||
def test_CMYK(self):
|
||||
self.assert_pack("CMYK", "CMYK", 4, (1,2,3,4), (5,6,7,8), (9,10,11,12))
|
||||
self.assert_pack("CMYK", "CMYK;I", 4,
|
||||
(254,253,252,251), (250,249,248,247), (246,245,244,243))
|
||||
self.assert_pack("CMYK", "CMYK;L", 4,
|
||||
(1,4,7,10), (2,5,8,11), (3,6,9,12))
|
||||
self.assert_pack("CMYK", "K", 1, (6,7,0,1), (6,7,0,2), (0,7,0,3))
|
||||
|
||||
def test_YCbCr(self):
|
||||
self.assert_pack("YCbCr", "YCbCr", 3, (1,2,3), (4,5,6), (7,8,9))
|
||||
self.assert_pack("YCbCr", "YCbCr;L", 3, (1,4,7), (2,5,8), (3,6,9))
|
||||
self.assert_pack("YCbCr", "YCbCrX",
|
||||
'\x01\x02\x03\xff\x05\x06\x07\xff\t\n\x0b\xff',
|
||||
(1,2,3), (5,6,7), (9,10,11))
|
||||
self.assert_pack("YCbCr", "YCbCrK",
|
||||
'\x01\x02\x03\xff\x05\x06\x07\xff\t\n\x0b\xff',
|
||||
(1,2,3), (5,6,7), (9,10,11))
|
||||
self.assert_pack("YCbCr", "Y", 1, (1,0,8,9), (2,0,8,9), (3,0,8,0))
|
||||
self.assert_pack("YCbCr", "Cb", 1, (6,1,8,9), (6,2,8,9), (6,3,8,9))
|
||||
self.assert_pack("YCbCr", "Cr", 1, (6,7,1,9), (6,7,2,0), (6,7,3,9))
|
||||
|
||||
def test_LAB(self):
|
||||
self.assert_pack("LAB", "LAB", 3,
|
||||
(1,130,131), (4,133,134), (7,136,137))
|
||||
self.assert_pack("LAB", "L", 1, (1,9,9), (2,9,9), (3,9,9))
|
||||
self.assert_pack("LAB", "A", 1, (9,1,9), (9,2,9), (9,3,9))
|
||||
self.assert_pack("LAB", "B", 1, (9,9,1), (9,9,2), (9,9,3))
|
||||
|
||||
def test_HSV(self):
|
||||
self.assert_pack("HSV", "HSV", 3, (1,2,3), (4,5,6), (7,8,9))
|
||||
self.assert_pack("HSV", "H", 1, (1,9,9), (2,9,9), (3,9,9))
|
||||
self.assert_pack("HSV", "S", 1, (9,1,9), (9,2,9), (9,3,9))
|
||||
self.assert_pack("HSV", "V", 1, (9,9,1), (9,9,2), (9,9,3))
|
||||
|
||||
def test_I(self):
|
||||
self.assert_pack("I", "I", 4, 0x04030201, 0x08070605)
|
||||
self.assert_pack("I", "I;16B", 2, 0x0102, 0x0304)
|
||||
self.assert_pack("I", "I;32S",
|
||||
b'\x83\x00\x00\x01\x01\x00\x00\x83',
|
||||
0x01000083, -2097151999)
|
||||
|
||||
if sys.byteorder == 'little':
|
||||
self.assert_pack("I", "I;32NS",
|
||||
b'\x83\x00\x00\x01\x01\x00\x00\x83',
|
||||
0x01000083, -2097151999)
|
||||
else:
|
||||
self.assert_pack("I", "I;32NS",
|
||||
b'\x83\x00\x00\x01\x01\x00\x00\x83',
|
||||
-2097151999, 0x01000083)
|
||||
|
||||
def test_F_float(self):
|
||||
self.assert_pack("F", "F", 4,
|
||||
1.539989614439558e-36, 4.063216068939723e-34)
|
||||
self.assert_pack("F", "F;32F", 4,
|
||||
1.539989614439558e-36, 4.063216068939723e-34)
|
||||
|
||||
if sys.byteorder == 'little':
|
||||
self.assert_pack("F", "F;32NF", 4,
|
||||
1.539989614439558e-36, 4.063216068939723e-34)
|
||||
else:
|
||||
self.assert_pack("F", "F;32NF", 4,
|
||||
2.387939260590663e-38, 6.301941157072183e-36)
|
||||
|
||||
|
||||
class TestLibUnpack(PillowTestCase):
|
||||
def assert_unpack(self, mode, rawmode, data, *pixels):
|
||||
"""
|
||||
data - eather raw bytes with data or just number of bytes in rawmode.
|
||||
data - either raw bytes with data or just number of bytes in rawmode.
|
||||
"""
|
||||
if isinstance(data, (int)):
|
||||
data_len = data * len(pixels)
|
||||
|
|
|
@ -599,13 +599,13 @@ static struct {
|
|||
{"HSV", "V", 8, band2},
|
||||
|
||||
/* integer */
|
||||
{"I", "I", 32, copy4},
|
||||
{"I", "I", 32, packI32S},
|
||||
{"I", "I;16B", 16, packI16B},
|
||||
{"I", "I;32S", 32, packI32S},
|
||||
{"I", "I;32NS", 32, copy4},
|
||||
|
||||
/* floating point */
|
||||
{"F", "F", 32, copy4},
|
||||
{"F", "F", 32, packI32S},
|
||||
{"F", "F;32F", 32, packI32S},
|
||||
{"F", "F;32NF", 32, copy4},
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user