From aba2fd95c6acf576ba58d06bb44aae8374102644 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 11 Jul 2024 17:19:42 -0700 Subject: [PATCH] Allocate a palette for indexed surfaces Fixes https://github.com/libsdl-org/SDL_ttf/issues/368 --- src/SDL_ttf.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/SDL_ttf.c b/src/SDL_ttf.c index 67bd804f..f66d5d0b 100644 --- a/src/SDL_ttf.c +++ b/src/SDL_ttf.c @@ -1444,6 +1444,9 @@ static SDL_Surface *AllocateAlignedPixels(size_t width, size_t height, SDL_Pixel SDL_aligned_free(pixels); return NULL; } + if (SDL_ISPIXELFORMAT_INDEXED(format)) { + SDL_SetSurfacePalette(textbuf, SDL_CreatePalette(1 << SDL_BITSPERPIXEL(format))); + } /* Let SDL handle the memory allocation */ textbuf->flags &= ~SDL_SURFACE_PREALLOCATED;