From 37b7615b71c3a2f44e03c47894383107850812ff Mon Sep 17 00:00:00 2001 From: Misa Date: Thu, 18 Feb 2021 22:20:11 -0800 Subject: [PATCH] Fix surface color masks This fixes the color ordering of every SDL_Surface in the game. Basically, images need to be loaded in ABGR format (except if they don't have alpha, then you use RGB? I'm not sure what's going on here), and then they will be converted to RGB/RGBA afterwards. Due to the surfaces actually being BGR/BGRA, the game used to use getRGBA/getRGB to swap the colors back around to BGRA/BGR, but I've fixed those too. --- desktop_version/src/Graphics.cpp | 4 ++-- desktop_version/src/GraphicsResources.cpp | 9 +++------ desktop_version/src/Screen.cpp | 7 ++----- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/desktop_version/src/Graphics.cpp b/desktop_version/src/Graphics.cpp index db6cef1d..874a4813 100644 --- a/desktop_version/src/Graphics.cpp +++ b/desktop_version/src/Graphics.cpp @@ -3250,12 +3250,12 @@ void Graphics::drawtele(int x, int y, int t, Uint32 c) Uint32 Graphics::getRGBA(Uint8 r, Uint8 g, Uint8 b, Uint8 a) { - return SDL_MapRGBA(backBuffer->format, b, g, r, a); + return SDL_MapRGBA(backBuffer->format, r, g, b, a); } Uint32 Graphics::getRGB(Uint8 r, Uint8 g, Uint8 b) { - return SDL_MapRGB(backBuffer->format, b, g, r); + return SDL_MapRGB(backBuffer->format, r, g, b); } Uint32 Graphics::getBGR(Uint8 r, Uint8 g, Uint8 b) diff --git a/desktop_version/src/GraphicsResources.cpp b/desktop_version/src/GraphicsResources.cpp index f16c6cb9..379cef3c 100644 --- a/desktop_version/src/GraphicsResources.cpp +++ b/desktop_version/src/GraphicsResources.cpp @@ -50,23 +50,20 @@ static SDL_Surface* LoadImage(const char *filename, bool noBlend = true, bool no } FILESYSTEM_freeMemory(&fileIn); - loadedImage = SDL_CreateRGBSurfaceFrom( + loadedImage = SDL_CreateRGBSurfaceWithFormatFrom( data, width, height, noAlpha ? 24 : 32, width * (noAlpha ? 3 : 4), - 0x000000FF, - 0x0000FF00, - 0x00FF0000, - noAlpha ? 0x00000000 : 0xFF000000 + noAlpha ? SDL_PIXELFORMAT_RGB24 : SDL_PIXELFORMAT_ABGR8888 ); if (loadedImage != NULL) { optimizedImage = SDL_ConvertSurfaceFormat( loadedImage, - SDL_PIXELFORMAT_ABGR8888, // FIXME: Format? -flibit + SDL_PIXELFORMAT_ARGB8888, 0 ); SDL_FreeSurface( loadedImage ); diff --git a/desktop_version/src/Screen.cpp b/desktop_version/src/Screen.cpp index 5fa5bf15..d6183190 100644 --- a/desktop_version/src/Screen.cpp +++ b/desktop_version/src/Screen.cpp @@ -135,16 +135,13 @@ void Screen::LoadIcon(void) FILESYSTEM_loadAssetToMemory("VVVVVV.png", &fileIn, &length, false); lodepng_decode24(&data, &width, &height, fileIn, length); FILESYSTEM_freeMemory(&fileIn); - SDL_Surface *icon = SDL_CreateRGBSurfaceFrom( + SDL_Surface *icon = SDL_CreateRGBSurfaceWithFormatFrom( data, width, height, 24, width * 3, - 0x000000FF, - 0x0000FF00, - 0x00FF0000, - 0x00000000 + SDL_PIXELFORMAT_RGB24 ); SDL_SetWindowIcon(m_window, icon); SDL_FreeSurface(icon);