From b5b3177c68b0a96a250dc700f950d48f8232b3e0 Mon Sep 17 00:00:00 2001 From: Sevan Janiyan Date: Mon, 15 May 2023 03:08:59 +0100 Subject: [PATCH] Switch to using SDL_CreateRGBSurface() SDL_CreateRGBSurfaceWithFormat() was introduced in SDL 2.0.5 whereas SDL_CreateRGBSurface() is available since SDL 2.0. This allows uxn to run on legacy systems where it's not possible to reach SDL 2.0.5 but prior versions are, such as Mac OS X Tiger. --- src/uxnemu.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/uxnemu.c b/src/uxnemu.c index 35206a5..716e05c 100644 --- a/src/uxnemu.c +++ b/src/uxnemu.c @@ -273,12 +273,23 @@ static void capture_screen(void) { const Uint32 format = SDL_PIXELFORMAT_RGB24; +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + /* SDL_PIXELFORMAT_RGB24 */ + Uint32 Rmask = 0x000000FF; + Uint32 Gmask = 0x0000FF00; + Uint32 Bmask = 0x00FF0000; +#else + /* SDL_PIXELFORMAT_BGR24 */ + Uint32 Rmask = 0x00FF0000; + Uint32 Gmask = 0x0000FF00; + Uint32 Bmask = 0x000000FF; +#endif time_t t = time(NULL); char fname[64]; int w, h; SDL_Surface *surface; SDL_GetRendererOutputSize(gRenderer, &w, &h); - surface = SDL_CreateRGBSurfaceWithFormat(0, w, h, 24, format); + surface = SDL_CreateRGBSurface(0, w, h, 24, Rmask, Gmask, Bmask, 0); SDL_RenderReadPixels(gRenderer, NULL, format, surface->pixels, surface->pitch); strftime(fname, sizeof(fname), "screenshot-%Y%m%d-%H%M%S.bmp", localtime(&t)); SDL_SaveBMP(surface, fname); -- 2.45.2