diff --git a/Src/gui/game_info_menu.cpp b/Src/gui/game_info_menu.cpp index a40b7d9..0110c32 100644 --- a/Src/gui/game_info_menu.cpp +++ b/Src/gui/game_info_menu.cpp @@ -58,7 +58,7 @@ public: { case 0: { - SDL_Surface *tmp = SDL_DisplayFormat(Gui::gui->screenshot); + SDL_Surface *tmp = sdl_surface_8bit_copy(Gui::gui->screenshot); this->box->gi->setScreenshot(tmp); } break; @@ -83,7 +83,7 @@ public: /* If we haven't' saved a screenshot, save it anyway */ if (!this->box->gi->screenshot) { - SDL_Surface *p = TheC64->TheDisplay->SurfaceFromC64Display(); + SDL_Surface *p = sdl_surface_8bit_copy(Gui::gui->screenshot); this->box->gi->setScreenshot(p); } diff --git a/Src/gui/save_game_menu.cpp b/Src/gui/save_game_menu.cpp index a6ea01e..eb6e11d 100644 --- a/Src/gui/save_game_menu.cpp +++ b/Src/gui/save_game_menu.cpp @@ -182,7 +182,7 @@ void SaveGameView::saveSnapshot() if (!was_paused) TheC64->Resume(); - Gui::gui->cur_gameInfo->setScreenshot(TheC64->TheDisplay->SurfaceFromC64Display()); + Gui::gui->cur_gameInfo->setScreenshot(sdl_surface_8bit_copy(Gui::gui->screenshot)); Gui::gui->saveGameInfo(Gui::gui->save_game_path, out_name); ThePrefs.Save(prefs_name); diff --git a/Src/utils.cpp b/Src/utils.cpp index 7b72d92..d561f8f 100644 --- a/Src/utils.cpp +++ b/Src/utils.cpp @@ -172,8 +172,6 @@ static int png_colortype_from_surface(SDL_Surface *surface) if (surface->format->palette) colortype |= PNG_COLOR_MASK_PALETTE; - else if (surface->format->Amask) - colortype |= PNG_COLOR_MASK_ALPHA; return colortype; } @@ -287,6 +285,39 @@ SDL_Surface *sdl_surface_from_data(void *data, size_t sz) return out; } +SDL_Surface *sdl_surface_8bit_copy(SDL_Surface *src) +{ + Uint32 rmask,gmask,bmask,amask; + SDL_Surface *out; + +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + rmask = 0xff000000; + gmask = 0x00ff0000; + bmask = 0x0000ff00; + amask = 0x000000ff; +#else + rmask = 0x000000ff; + gmask = 0x0000ff00; + bmask = 0x00ff0000; + amask = 0xff000000; +#endif + if (!src) + return NULL; + if (src->format->BitsPerPixel != 8) + return NULL; + + out = SDL_CreateRGBSurface(SDL_SWSURFACE, src->w, src->h, 8, + rmask, gmask, bmask, amask); + if (!out) + return NULL; + memcpy(out->pixels, src->pixels, src->h * src->pitch); + + SDL_SetColors(out, sdl_palette, 0, PALETTE_SIZE); + + return out; +} + + void highlight_background(SDL_Surface *where, Font *font, SDL_Surface *bg_left, SDL_Surface *bg_middle, SDL_Surface *bg_right, int x, int y, int w, int h) diff --git a/Src/utils.hh b/Src/utils.hh index e092674..ec5e55e 100644 --- a/Src/utils.hh +++ b/Src/utils.hh @@ -88,4 +88,6 @@ const char *ip_to_str(uint8_t *ip_in); const char *region_to_str(int region); +SDL_Surface *sdl_surface_8bit_copy(SDL_Surface *src); + #endif /* __UTILS_H__ */