Skip to content

Commit cbf5ca8

Browse files
committed
skip unecessary format conversion on load
1 parent 4dfefb8 commit cbf5ca8

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

Source/Managers/ActivityMan.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ bool ActivityMan::SaveCurrentGame(const std::string& fileName) {
206206

207207
SDL_Palette* palette = ContentFile::DefaultPaletteToSDL();
208208
SDL_SetSurfacePalette(image, palette);
209+
SDL_SetSurfaceColorKey(image, false, 0);
209210

210211
bool result = IMG_SavePNG_IO(image, stream, false);
211212
SDL_FlushIO(stream);
@@ -310,11 +311,16 @@ bool ActivityMan::LoadAndLaunchGame(const std::string& fileName) {
310311
SDL_Surface* image = stream ? IMG_LoadPNG_IO(stream) : nullptr;
311312
SDL_CloseIO(stream);
312313

314+
int bitDepth = SDL_GetPixelFormatDetails(image->format)->bits_per_pixel;
313315
SDL_Palette* palette = ContentFile::DefaultPaletteToSDL();
314-
SDL_Surface* newImage = SDL_ConvertSurfaceAndColorspace(image, SDL_PIXELFORMAT_INDEX8, palette, SDL_COLORSPACE_UNKNOWN, 0);
316+
if (bitDepth != 8) {
317+
SDL_Surface* newImage = SDL_ConvertSurfaceAndColorspace(image, SDL_PIXELFORMAT_INDEX8, palette, SDL_COLORSPACE_UNKNOWN, 0);
318+
SDL_DestroySurface(image);
319+
image = newImage;
320+
} else {
321+
SDL_SetSurfacePalette(image, palette);
322+
}
315323
SDL_DestroyPalette(palette);
316-
SDL_DestroySurface(image);
317-
image = newImage;
318324

319325
free(buffer);
320326
return image;

0 commit comments

Comments
 (0)