From 5576ea6c5020a8abb60b494c46bbf26924b7ebd8 Mon Sep 17 00:00:00 2001 From: Yay295 Date: Tue, 16 Apr 2024 17:20:46 -0500 Subject: [PATCH] don't use memcpy when converting BGR;15/16 --- src/libImaging/Convert.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/libImaging/Convert.c b/src/libImaging/Convert.c index 7e60a960c1b..ac42612ee72 100644 --- a/src/libImaging/Convert.c +++ b/src/libImaging/Convert.c @@ -280,24 +280,26 @@ rgb2f(UINT8 *out_, const UINT8 *in, int xsize) { } static void -rgb2bgr15(UINT8 *out_, const UINT8 *in, int xsize) { +rgb2bgr15(UINT8 *out, const UINT8 *in, int xsize) { int x; - for (x = 0; x < xsize; x++, in += 4, out_ += 2) { - UINT16 v = ((((UINT16)in[0]) << 7) & 0x7c00) + - ((((UINT16)in[1]) << 2) & 0x03e0) + - ((((UINT16)in[2]) >> 3) & 0x001f); - memcpy(out_, &v, sizeof(v)); + for (x = 0; x < xsize; x++, in += 4, out += 2) { + const UINT8 r = in[0] >> 3; + const UINT8 g = in[1] >> 3; + const UINT8 b = in[2] >> 3; + out[1] = 0x80 | (b << 2) | (g >> 3); + out[0] = (g << 5) | r; } } static void -rgb2bgr16(UINT8 *out_, const UINT8 *in, int xsize) { +rgb2bgr16(UINT8 *out, const UINT8 *in, int xsize) { int x; - for (x = 0; x < xsize; x++, in += 4, out_ += 2) { - UINT16 v = ((((UINT16)in[0]) << 8) & 0xf800) + - ((((UINT16)in[1]) << 3) & 0x07e0) + - ((((UINT16)in[2]) >> 3) & 0x001f); - memcpy(out_, &v, sizeof(v)); + for (x = 0; x < xsize; x++, in += 4, out += 2) { + const UINT8 r = in[0] >> 3; + const UINT8 g = in[1] >> 2; + const UINT8 b = in[2] >> 3; + out[1] = (b << 3) | (g >> 3); + out[0] = (g << 5) | r; } }