diff --git a/Tests/test_lib_pack.py b/Tests/test_lib_pack.py index af7eae935..979806cae 100644 --- a/Tests/test_lib_pack.py +++ b/Tests/test_lib_pack.py @@ -444,6 +444,8 @@ class TestLibUnpack: self.assert_unpack("RGBA", "RGBA;4B", 2, (17, 0, 34, 0), (51, 0, 68, 0)) self.assert_unpack("RGBA", "RGBA;16L", 8, (2, 4, 6, 8), (10, 12, 14, 16)) self.assert_unpack("RGBA", "RGBA;16B", 8, (1, 3, 5, 7), (9, 11, 13, 15)) + self.assert_unpack("RGBA", "BGRA;16L", 8, (6, 4, 2, 8), (14, 12, 10, 16)) + self.assert_unpack("RGBA", "BGRA;16B", 8, (5, 3, 1, 7), (13, 11, 9, 15)) self.assert_unpack( "RGBA", "BGRA", 4, (3, 2, 1, 4), (7, 6, 5, 8), (11, 10, 9, 12) ) diff --git a/src/libImaging/Unpack.c b/src/libImaging/Unpack.c index fc7568a2c..e426ed74f 100644 --- a/src/libImaging/Unpack.c +++ b/src/libImaging/Unpack.c @@ -705,7 +705,7 @@ ImagingUnpackBGR15(UINT8 *out, const UINT8 *in, int pixels) { void ImagingUnpackBGRA15(UINT8 *out, const UINT8 *in, int pixels) { int i, pixel; - /* RGB, reversed bytes, 5/5/5/1 bits per pixel */ + /* RGB, rearranged channels, 5/5/5/1 bits per pixel */ for (i = 0; i < pixels; i++) { pixel = in[0] + (in[1] << 8); out[B] = (pixel & 31) * 255 / 31; @@ -1056,7 +1056,7 @@ unpackABGR(UINT8 *_out, const UINT8 *in, int pixels) { static void unpackBGRA(UINT8 *_out, const UINT8 *in, int pixels) { int i; - /* RGBA, reversed bytes */ + /* RGBA, rearranged channels */ for (i = 0; i < pixels; i++) { UINT32 iv = MAKE_UINT32(in[2], in[1], in[0], in[3]); memcpy(_out, &iv, sizeof(iv)); @@ -1065,6 +1065,30 @@ unpackBGRA(UINT8 *_out, const UINT8 *in, int pixels) { } } +static void +unpackBGRA16L(UINT8 *_out, const UINT8 *in, int pixels) { + int i; + /* 16-bit RGBA, little-endian order, rearranged channels */ + for (i = 0; i < pixels; i++) { + UINT32 iv = MAKE_UINT32(in[5], in[3], in[1], in[7]); + memcpy(_out, &iv, sizeof(iv)); + in += 8; + _out += 4; + } +} + +static void +unpackBGRA16B(UINT8 *_out, const UINT8 *in, int pixels) { + int i; + /* 16-bit RGBA, big-endian order, rearranged channels */ + for (i = 0; i < pixels; i++) { + UINT32 iv = MAKE_UINT32(in[4], in[2], in[0], in[6]); + memcpy(_out, &iv, sizeof(iv)); + in += 8; + _out += 4; + } +} + /* Unpack to "CMYK" image */ static void @@ -1574,6 +1598,8 @@ static struct { {"RGBA", "RGBA;16L", 64, unpackRGBA16L}, {"RGBA", "RGBA;16B", 64, unpackRGBA16B}, {"RGBA", "BGRA", 32, unpackBGRA}, + {"RGBA", "BGRA;16L", 64, unpackBGRA16L}, + {"RGBA", "BGRA;16B", 64, unpackBGRA16B}, {"RGBA", "ARGB", 32, unpackARGB}, {"RGBA", "ABGR", 32, unpackABGR}, {"RGBA", "YCCA;P", 32, ImagingUnpackYCCA},