From 00cec60c35b1c0a7579706851432bef3c553ff9b Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 29 Jul 2023 21:05:33 +1000 Subject: [PATCH 1/2] Added CMYK to RGB unpacker --- Tests/test_lib_pack.py | 4 ++++ src/libImaging/Unpack.c | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/Tests/test_lib_pack.py b/Tests/test_lib_pack.py index f7812f62bd8..963d35b067e 100644 --- a/Tests/test_lib_pack.py +++ b/Tests/test_lib_pack.py @@ -340,6 +340,10 @@ 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)) + self.assert_unpack( + "RGB", "CMYK", 4, (250, 249, 248), (242, 241, 240), (234, 233, 233) + ) + 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..6e86e723297 100644 --- a/src/libImaging/Unpack.c +++ b/src/libImaging/Unpack.c @@ -813,6 +813,20 @@ ImagingUnpackXBGR(UINT8 *_out, const UINT8 *in, int pixels) { } } +static void +cmyk2rgb(UINT8 *_out, const UINT8 *in, int pixels) { + int i, nk, tmp; + for (i = 0; i < pixels; i++) { + nk = 255 - in[3]; + _out[0] = CLIP8(nk - MULDIV255(in[0], nk, tmp)); + _out[1] = CLIP8(nk - MULDIV255(in[1], nk, tmp)); + _out[2] = CLIP8(nk - MULDIV255(in[2], nk, tmp)); + _out[3] = 255; + _out += 4; + in += 4; + } +} + /* Unpack to "RGBA" image */ static void @@ -1589,6 +1603,7 @@ static struct { {"RGB", "R;16B", 16, band016B}, {"RGB", "G;16B", 16, band116B}, {"RGB", "B;16B", 16, band216B}, + {"RGB", "CMYK", 32, cmyk2rgb}, /* true colour w. alpha */ {"RGBA", "LA", 16, unpackRGBALA}, From b8c30655cc190d9e3fe7d36745b87c31be1708fb Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 6 Oct 2023 16:05:03 +1100 Subject: [PATCH 2/2] Include CMYK to RGB convert as unpacker --- src/libImaging/Convert.c | 2 +- src/libImaging/Convert.h | 2 ++ src/libImaging/Unpack.c | 15 +-------------- 3 files changed, 4 insertions(+), 15 deletions(-) create mode 100644 src/libImaging/Convert.h diff --git a/src/libImaging/Convert.c b/src/libImaging/Convert.c index 7677a81f72f..b08519d3045 100644 --- a/src/libImaging/Convert.c +++ b/src/libImaging/Convert.c @@ -564,7 +564,7 @@ rgb2cmyk(UINT8 *out, const UINT8 *in, int xsize) { } } -static void +void cmyk2rgb(UINT8 *out, const UINT8 *in, int xsize) { int x, nk, tmp; for (x = 0; x < xsize; x++) { diff --git a/src/libImaging/Convert.h b/src/libImaging/Convert.h new file mode 100644 index 00000000000..e688e301836 --- /dev/null +++ b/src/libImaging/Convert.h @@ -0,0 +1,2 @@ +extern void +cmyk2rgb(UINT8 *out, const UINT8 *in, int xsize); diff --git a/src/libImaging/Unpack.c b/src/libImaging/Unpack.c index 6e86e723297..bef4bea6642 100644 --- a/src/libImaging/Unpack.c +++ b/src/libImaging/Unpack.c @@ -31,6 +31,7 @@ */ #include "Imaging.h" +#include "Convert.h" #define R 0 #define G 1 @@ -813,20 +814,6 @@ ImagingUnpackXBGR(UINT8 *_out, const UINT8 *in, int pixels) { } } -static void -cmyk2rgb(UINT8 *_out, const UINT8 *in, int pixels) { - int i, nk, tmp; - for (i = 0; i < pixels; i++) { - nk = 255 - in[3]; - _out[0] = CLIP8(nk - MULDIV255(in[0], nk, tmp)); - _out[1] = CLIP8(nk - MULDIV255(in[1], nk, tmp)); - _out[2] = CLIP8(nk - MULDIV255(in[2], nk, tmp)); - _out[3] = 255; - _out += 4; - in += 4; - } -} - /* Unpack to "RGBA" image */ static void