Added L;16/B pack functions

This commit is contained in:
Eric Soroos 2017-09-29 13:39:16 +00:00
parent 6816a9d4ce
commit 7c629d7814
2 changed files with 32 additions and 0 deletions

View File

@ -38,6 +38,8 @@ class TestLibPack(PillowTestCase):
def test_L(self):
self.assert_pack("L", "L", 1, 1,2,3,4)
self.assert_pack("L", "L;16", b'\x00\xc6\x00\xaf', 198, 175)
self.assert_pack("L", "L;16B", b'\xc6\x00\xaf\x00', 198, 175)
def test_LA(self):
self.assert_pack("LA", "LA", 2, (1,2), (3,4), (5,6))
@ -221,6 +223,9 @@ class TestLibUnpack(PillowTestCase):
self.assert_unpack("L", "L;R", 1, 128, 64, 192, 32)
self.assert_unpack("L", "L;16", 2, 2, 4, 6, 8)
self.assert_unpack("L", "L;16B", 2, 1, 3, 5, 7)
self.assert_unpack("L", "L;16", b'\x00\xc6\x00\xaf', 198, 175)
self.assert_unpack("L", "L;16B", b'\xc6\x00\xaf\x00', 198, 175)
def test_LA(self):
self.assert_unpack("LA", "LA", 2, (1, 2), (3, 4), (5, 6))

View File

@ -197,6 +197,31 @@ packP2(UINT8* out, const UINT8* in, int pixels)
}
}
static void
packL16(UINT8* out, const UINT8* in, int pixels)
{
int i;
/* L -> L;16, e.g: \xff77 -> \x00\xff\x00\x77 */
for (i = 0; i < pixels; i++) {
out[0] = 0;
out[1] = in[i];
out += 2;
}
}
static void
packL16B(UINT8* out, const UINT8* in, int pixels)
{
int i;
/* L -> L;16B, e.g: \xff77 -> \xff\x00\x77\x00 */
for (i = 0; i < pixels; i++) {
out[0] = in[i];
out[1] = 0;
out += 2;
}
}
static void
packLA(UINT8* out, const UINT8* in, int pixels)
{
@ -512,6 +537,8 @@ static struct {
/* greyscale */
{"L", "L", 8, copy1},
{"L", "L;16", 16, packL16},
{"L", "L;16B", 16, packL16B},
/* greyscale w. alpha */
{"LA", "LA", 16, packLA},