SURFACESDL: Fix crash when saving screenshots in paletted screen modes
This commit is contained in:
parent
08375cafdf
commit
ce9d324a72
3 changed files with 24 additions and 5 deletions
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue