Add SDL_PIXELFORMAT_INDEX2LSB and SDL_PIXELFORMAT_INDEX2MSB

main
Cameron Cawley 2023-11-17 11:43:39 +00:00 committed by Sam Lantinga
parent fda69e5e79
commit 753bbd199e
5 changed files with 51 additions and 0 deletions

View File

@ -88,6 +88,7 @@ typedef enum
{
SDL_PIXELTYPE_UNKNOWN,
SDL_PIXELTYPE_INDEX1,
SDL_PIXELTYPE_INDEX2,
SDL_PIXELTYPE_INDEX4,
SDL_PIXELTYPE_INDEX8,
SDL_PIXELTYPE_PACKED8,
@ -166,6 +167,7 @@ typedef enum
#define SDL_ISPIXELFORMAT_INDEXED(format) \
(!SDL_ISPIXELFORMAT_FOURCC(format) && \
((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX1) || \
(SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX2) || \
(SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX4) || \
(SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX8)))
@ -208,6 +210,12 @@ typedef enum
SDL_PIXELFORMAT_INDEX1MSB =
SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX1, SDL_BITMAPORDER_1234, 0,
1, 0),
SDL_PIXELFORMAT_INDEX2LSB =
SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX2, SDL_BITMAPORDER_4321, 0,
2, 0),
SDL_PIXELFORMAT_INDEX2MSB =
SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX2, SDL_BITMAPORDER_1234, 0,
2, 0),
SDL_PIXELFORMAT_INDEX4LSB =
SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX4, SDL_BITMAPORDER_4321, 0,
4, 0),

View File

@ -908,6 +908,12 @@ static void SDLTest_PrintPixelFormat(char *text, size_t maxlen, Uint32 format)
case SDL_PIXELFORMAT_INDEX1MSB:
SDL_snprintfcat(text, maxlen, "Index1MSB");
break;
case SDL_PIXELFORMAT_INDEX2LSB:
SDL_snprintfcat(text, maxlen, "Index2LSB");
break;
case SDL_PIXELFORMAT_INDEX2MSB:
SDL_snprintfcat(text, maxlen, "Index2MSB");
break;
case SDL_PIXELFORMAT_INDEX4LSB:
SDL_snprintfcat(text, maxlen, "Index4LSB");
break;

View File

@ -89,6 +89,8 @@ const char *SDL_GetPixelFormatName(Uint32 format)
CASE(SDL_PIXELFORMAT_INDEX1LSB)
CASE(SDL_PIXELFORMAT_INDEX1MSB)
CASE(SDL_PIXELFORMAT_INDEX2LSB)
CASE(SDL_PIXELFORMAT_INDEX2MSB)
CASE(SDL_PIXELFORMAT_INDEX4LSB)
CASE(SDL_PIXELFORMAT_INDEX4MSB)
CASE(SDL_PIXELFORMAT_INDEX8)
@ -309,6 +311,9 @@ Uint32 SDL_GetPixelFormatEnumForMasks(int bpp, Uint32 Rmask, Uint32 Gmask, Uint3
case 1:
/* SDL defaults to MSB ordering */
return SDL_PIXELFORMAT_INDEX1MSB;
case 2:
/* SDL defaults to MSB ordering */
return SDL_PIXELFORMAT_INDEX2MSB;
case 4:
/* SDL defaults to MSB ordering */
return SDL_PIXELFORMAT_INDEX4MSB;

View File

@ -11,6 +11,8 @@
static const Uint32 g_AllFormats[] = {
SDL_PIXELFORMAT_INDEX1LSB,
SDL_PIXELFORMAT_INDEX1MSB,
SDL_PIXELFORMAT_INDEX2LSB,
SDL_PIXELFORMAT_INDEX2MSB,
SDL_PIXELFORMAT_INDEX4LSB,
SDL_PIXELFORMAT_INDEX4MSB,
SDL_PIXELFORMAT_INDEX8,
@ -56,6 +58,8 @@ static const int g_numAllFormats = SDL_arraysize(g_AllFormats);
static const char *g_AllFormatsVerbose[] = {
"SDL_PIXELFORMAT_INDEX1LSB",
"SDL_PIXELFORMAT_INDEX1MSB",
"SDL_PIXELFORMAT_INDEX2LSB",
"SDL_PIXELFORMAT_INDEX2MSB",
"SDL_PIXELFORMAT_INDEX4LSB",
"SDL_PIXELFORMAT_INDEX4MSB",
"SDL_PIXELFORMAT_INDEX8",

View File

@ -660,6 +660,34 @@ static int surface_testOverflow(void *arg)
surface != NULL ? "(success)" : SDL_GetError());
SDL_DestroySurface(surface);
/* SDL_PIXELFORMAT_INDEX2* needs 1 byte per 4 pixels. */
surface = SDL_CreateSurfaceFrom(buf, 12, 1, 3, SDL_PIXELFORMAT_INDEX2LSB);
SDLTest_AssertCheck(surface != NULL, "12px * 2 bits per px fits in 3 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_DestroySurface(surface);
surface = SDL_CreateSurfaceFrom(buf, 12, 1, 3, SDL_PIXELFORMAT_INDEX2MSB);
SDLTest_AssertCheck(surface != NULL, "12px * 2 bits per px fits in 3 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_DestroySurface(surface);
surface = SDL_CreateSurfaceFrom(buf, 13, 1, 3, SDL_PIXELFORMAT_INDEX2LSB);
SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp (%d)", surface ? surface->pitch : 0);
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
surface = SDL_CreateSurfaceFrom(buf, 13, 1, 3, SDL_PIXELFORMAT_INDEX2MSB);
SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
surface = SDL_CreateSurfaceFrom(buf, 13, 1, 4, SDL_PIXELFORMAT_INDEX2LSB);
SDLTest_AssertCheck(surface != NULL, "13px * 2 bits per px fits in 4 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_DestroySurface(surface);
surface = SDL_CreateSurfaceFrom(buf, 13, 1, 4, SDL_PIXELFORMAT_INDEX2MSB);
SDLTest_AssertCheck(surface != NULL, "13px * 2 bits per px fits in 4 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_DestroySurface(surface);
/* SDL_PIXELFORMAT_INDEX1* needs 1 byte per 8 pixels. */
surface = SDL_CreateSurfaceFrom(buf, 16, 1, 2, SDL_PIXELFORMAT_INDEX1LSB);
SDLTest_AssertCheck(surface != NULL, "16px * 1 bit per px fits in 2 bytes: %s",