Skip to content

Commit 5576ea6

Browse files
committed
don't use memcpy when converting BGR;15/16
1 parent 02911c7 commit 5576ea6

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/libImaging/Convert.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -280,24 +280,26 @@ rgb2f(UINT8 *out_, const UINT8 *in, int xsize) {
280280
}
281281

282282
static void
283-
rgb2bgr15(UINT8 *out_, const UINT8 *in, int xsize) {
283+
rgb2bgr15(UINT8 *out, const UINT8 *in, int xsize) {
284284
int x;
285-
for (x = 0; x < xsize; x++, in += 4, out_ += 2) {
286-
UINT16 v = ((((UINT16)in[0]) << 7) & 0x7c00) +
287-
((((UINT16)in[1]) << 2) & 0x03e0) +
288-
((((UINT16)in[2]) >> 3) & 0x001f);
289-
memcpy(out_, &v, sizeof(v));
285+
for (x = 0; x < xsize; x++, in += 4, out += 2) {
286+
const UINT8 r = in[0] >> 3;
287+
const UINT8 g = in[1] >> 3;
288+
const UINT8 b = in[2] >> 3;
289+
out[1] = 0x80 | (b << 2) | (g >> 3);
290+
out[0] = (g << 5) | r;
290291
}
291292
}
292293

293294
static void
294-
rgb2bgr16(UINT8 *out_, const UINT8 *in, int xsize) {
295+
rgb2bgr16(UINT8 *out, const UINT8 *in, int xsize) {
295296
int x;
296-
for (x = 0; x < xsize; x++, in += 4, out_ += 2) {
297-
UINT16 v = ((((UINT16)in[0]) << 8) & 0xf800) +
298-
((((UINT16)in[1]) << 3) & 0x07e0) +
299-
((((UINT16)in[2]) >> 3) & 0x001f);
300-
memcpy(out_, &v, sizeof(v));
297+
for (x = 0; x < xsize; x++, in += 4, out += 2) {
298+
const UINT8 r = in[0] >> 3;
299+
const UINT8 g = in[1] >> 2;
300+
const UINT8 b = in[2] >> 3;
301+
out[1] = (b << 3) | (g >> 3);
302+
out[0] = (g << 5) | r;
301303
}
302304
}
303305

0 commit comments

Comments
 (0)