From 8598f05b473be7ed6b41c72c3ad690d003e2ef8c Mon Sep 17 00:00:00 2001 From: Cameron Cawley Date: Sat, 17 Sep 2022 21:45:08 +0100 Subject: [PATCH] Support loading 2bpp .bmp files --- src/video/SDL_bmp.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/video/SDL_bmp.c b/src/video/SDL_bmp.c index cb220440a4..d52d6e84e4 100644 --- a/src/video/SDL_bmp.c +++ b/src/video/SDL_bmp.c @@ -328,15 +328,15 @@ SDL_LoadBMP_RW(SDL_RWops * src, int freesrc) goto done; } - /* Expand 1 and 4 bit bitmaps to 8 bits per pixel */ + /* Expand 1, 2 and 4 bit bitmaps to 8 bits per pixel */ switch (biBitCount) { case 1: + case 2: case 4: ExpandBMP = biBitCount; biBitCount = 8; break; case 0: - case 2: case 3: case 5: case 6: @@ -473,6 +473,10 @@ SDL_LoadBMP_RW(SDL_RWops * src, int freesrc) bmpPitch = (biWidth + 7) >> 3; pad = (((bmpPitch) % 4) ? (4 - ((bmpPitch) % 4)) : 0); break; + case 2: + bmpPitch = (biWidth + 3) >> 2; + pad = (((bmpPitch) % 4) ? (4 - ((bmpPitch) % 4)) : 0); + break; case 4: bmpPitch = (biWidth + 1) >> 1; pad = (((bmpPitch) % 4) ? (4 - ((bmpPitch) % 4)) : 0); @@ -489,6 +493,7 @@ SDL_LoadBMP_RW(SDL_RWops * src, int freesrc) while (bits >= top && bits < end) { switch (ExpandBMP) { case 1: + case 2: case 4:{ Uint8 pixel = 0; int shift = (8 - ExpandBMP);