Skip to content

Commit 0a27069

Browse files
madebricculus
authored andcommitted
The pixel data of a BMP need to be swapped
1 parent 181b502 commit 0a27069

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

dirksimple.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ static uint16_t readui16le(const uint8_t **pptr)
242242
return retval;
243243
}
244244

245+
static uint32_t swap32(uint32_t v) {
246+
return v << 24 | (v << 8 & 0xff0000) | (v >> 8 & 0xff00) | (v >> 24);
247+
}
248+
245249
static uint8_t *loadbmp_from_memory(const char *fname, const uint8_t *buf, int buflen, int *_w, int *_h)
246250
{
247251
const uint8_t *ptr = buf;
@@ -300,6 +304,9 @@ static uint8_t *loadbmp_from_memory(const char *fname, const uint8_t *buf, int b
300304
uint8_t *dst = pixels;
301305
for (int y = 0; y < bmpheight; y++) {
302306
memcpy(dst, src, rowlen);
307+
for (int x = 0; x < bmpwidth; x++) {
308+
*(uint32_t*)&dst[4*x] = swap32(*(uint32_t*)&dst[4*x]);
309+
}
303310
dst += rowlen;
304311
src -= rowlen;
305312
}

0 commit comments

Comments
 (0)