1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-22 17:49:43 +01:00

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.
This commit is contained in:
Misa 2021-02-18 22:20:11 -08:00
parent 2c0d6920e8
commit 37b7615b71
3 changed files with 7 additions and 13 deletions

View file

@ -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) 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) 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) Uint32 Graphics::getBGR(Uint8 r, Uint8 g, Uint8 b)

View file

@ -50,23 +50,20 @@ static SDL_Surface* LoadImage(const char *filename, bool noBlend = true, bool no
} }
FILESYSTEM_freeMemory(&fileIn); FILESYSTEM_freeMemory(&fileIn);
loadedImage = SDL_CreateRGBSurfaceFrom( loadedImage = SDL_CreateRGBSurfaceWithFormatFrom(
data, data,
width, width,
height, height,
noAlpha ? 24 : 32, noAlpha ? 24 : 32,
width * (noAlpha ? 3 : 4), width * (noAlpha ? 3 : 4),
0x000000FF, noAlpha ? SDL_PIXELFORMAT_RGB24 : SDL_PIXELFORMAT_ABGR8888
0x0000FF00,
0x00FF0000,
noAlpha ? 0x00000000 : 0xFF000000
); );
if (loadedImage != NULL) if (loadedImage != NULL)
{ {
optimizedImage = SDL_ConvertSurfaceFormat( optimizedImage = SDL_ConvertSurfaceFormat(
loadedImage, loadedImage,
SDL_PIXELFORMAT_ABGR8888, // FIXME: Format? -flibit SDL_PIXELFORMAT_ARGB8888,
0 0
); );
SDL_FreeSurface( loadedImage ); SDL_FreeSurface( loadedImage );

View file

@ -135,16 +135,13 @@ void Screen::LoadIcon(void)
FILESYSTEM_loadAssetToMemory("VVVVVV.png", &fileIn, &length, false); FILESYSTEM_loadAssetToMemory("VVVVVV.png", &fileIn, &length, false);
lodepng_decode24(&data, &width, &height, fileIn, length); lodepng_decode24(&data, &width, &height, fileIn, length);
FILESYSTEM_freeMemory(&fileIn); FILESYSTEM_freeMemory(&fileIn);
SDL_Surface *icon = SDL_CreateRGBSurfaceFrom( SDL_Surface *icon = SDL_CreateRGBSurfaceWithFormatFrom(
data, data,
width, width,
height, height,
24, 24,
width * 3, width * 3,
0x000000FF, SDL_PIXELFORMAT_RGB24
0x0000FF00,
0x00FF0000,
0x00000000
); );
SDL_SetWindowIcon(m_window, icon); SDL_SetWindowIcon(m_window, icon);
SDL_FreeSurface(icon); SDL_FreeSurface(icon);