Skip to content

Commit

Permalink
don't use memcpy when converting BGR;15/16
Browse files Browse the repository at this point in the history
  • Loading branch information
Yay295 committed Apr 16, 2024
1 parent 02911c7 commit 5576ea6
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/libImaging/Convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down

0 comments on commit 5576ea6

Please sign in to comment.