diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp index 34d7f0dfe48..2cef8199205 100644 --- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp +++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp @@ -1486,11 +1486,30 @@ bool SurfaceSdlGraphicsManager::saveScreenshot(const Common::String &filename) c Graphics::PixelFormat format = convertSDLPixelFormat(_hwScreen->format); Graphics::Surface data; data.init(_hwScreen->w, _hwScreen->h, _hwScreen->pitch, _hwScreen->pixels, format); + + bool success; + + SDL_Palette *sdlPalette = _hwScreen->format->palette; + if (sdlPalette) { + byte palette[256 * 3]; + for (int i = 0; i < sdlPalette->ncolors; i++) { + palette[(i * 3) + 0] = sdlPalette->colors[i].r; + palette[(i * 3) + 1] = sdlPalette->colors[i].g; + palette[(i * 3) + 2] = sdlPalette->colors[i].b; + } + #ifdef USE_PNG - const bool success = Image::writePNG(out, data); + success = Image::writePNG(out, data, palette); #else - const bool success = Image::writeBMP(out, data); + success = Image::writeBMP(out, data, palette); #endif + } else { +#ifdef USE_PNG + success = Image::writePNG(out, data); +#else + success = Image::writeBMP(out, data); +#endif + } SDL_UnlockSurface(_hwScreen); diff --git a/image/bmp.cpp b/image/bmp.cpp index 113bb63bf86..476a9b24e68 100644 --- a/image/bmp.cpp +++ b/image/bmp.cpp @@ -153,7 +153,7 @@ bool BitmapDecoder::loadStream(Common::SeekableReadStream &stream) { return true; } -bool writeBMP(Common::WriteStream &out, const Graphics::Surface &input) { +bool writeBMP(Common::WriteStream &out, const Graphics::Surface &input, const byte *palette) { #ifdef SCUMM_LITTLE_ENDIAN const Graphics::PixelFormat requiredFormat_3byte(3, 8, 8, 8, 0, 16, 8, 0, 0); #else @@ -166,7 +166,7 @@ bool writeBMP(Common::WriteStream &out, const Graphics::Surface &input) { if (input.format == requiredFormat_3byte) { surface = &input; } else { - surface = tmp = input.convertTo(requiredFormat_3byte); + surface = tmp = input.convertTo(requiredFormat_3byte, palette); } int dstPitch = surface->w * 3; diff --git a/image/bmp.h b/image/bmp.h index 9c8bd3a7938..d73a58f31a8 100644 --- a/image/bmp.h +++ b/image/bmp.h @@ -86,7 +86,7 @@ private: /** * Outputs an uncompressed BMP stream of the given input surface. */ -bool writeBMP(Common::WriteStream &out, const Graphics::Surface &input); +bool writeBMP(Common::WriteStream &out, const Graphics::Surface &input, const byte *palette = nullptr); /** @} */ } // End of namespace Image