From 983dc165d94e1905690ba26f56a0b167218c3b37 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Mon, 24 Jul 2023 20:47:30 +1000 Subject: [PATCH] Added BGR;15, BGR;16 and BGR;24 unpacking --- Tests/test_lib_pack.py | 7 +++++++ src/libImaging/Unpack.c | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/Tests/test_lib_pack.py b/Tests/test_lib_pack.py index f7812f62bd8..5b95b9db248 100644 --- a/Tests/test_lib_pack.py +++ b/Tests/test_lib_pack.py @@ -340,6 +340,13 @@ def test_RGB(self): self.assert_unpack("RGB", "G;16N", 2, (0, 1, 0), (0, 3, 0), (0, 5, 0)) self.assert_unpack("RGB", "B;16N", 2, (0, 0, 1), (0, 0, 3), (0, 0, 5)) + def test_BGR(self): + self.assert_unpack("BGR;15", "BGR;15", 3, (8, 131, 0), (24, 0, 8), (41, 131, 8)) + self.assert_unpack( + "BGR;16", "BGR;16", 3, (8, 64, 0), (24, 129, 0), (41, 194, 0) + ) + self.assert_unpack("BGR;24", "BGR;24", 3, (1, 2, 3), (4, 5, 6), (7, 8, 9)) + def test_RGBA(self): self.assert_unpack("RGBA", "LA", 2, (1, 1, 1, 2), (3, 3, 3, 4), (5, 5, 5, 6)) self.assert_unpack( diff --git a/src/libImaging/Unpack.c b/src/libImaging/Unpack.c index 206403ba6e0..b95208788dc 100644 --- a/src/libImaging/Unpack.c +++ b/src/libImaging/Unpack.c @@ -1238,6 +1238,12 @@ copy2(UINT8 *out, const UINT8 *in, int pixels) { memcpy(out, in, pixels * 2); } +static void +copy3(UINT8 *out, const UINT8 *in, int pixels) { + /* BGR;24 */ + memcpy(out, in, pixels * 3); +} + static void copy4(UINT8 *out, const UINT8 *in, int pixels) { /* RGBA, CMYK quadruples */ @@ -1590,6 +1596,10 @@ static struct { {"RGB", "G;16B", 16, band116B}, {"RGB", "B;16B", 16, band216B}, + {"BGR;15", "BGR;15", 16, copy2}, + {"BGR;16", "BGR;16", 16, copy2}, + {"BGR;24", "BGR;24", 16, copy3}, + /* true colour w. alpha */ {"RGBA", "LA", 16, unpackRGBALA}, {"RGBA", "LA;16B", 32, unpackRGBALA16B},