OPENGL: Ensure surfaces created by saveScreenshot are the right way up

This commit is contained in:
Cameron Cawley 2019-12-19 21:22:42 +00:00 committed by Filippos Karapetis
parent ba035ac532
commit d289fa5f98
5 changed files with 13 additions and 30 deletions

View file

@ -1323,10 +1323,12 @@ bool OpenGLGraphicsManager::saveScreenshot(const Common::String &filename) const
#endif
Graphics::Surface data;
data.init(width, height, lineSize, &pixels.front(), format);
data.flipVertical(Common::Rect(width, height));
#ifdef USE_PNG
return Image::writePNG(out, data, true);
return Image::writePNG(out, data);
#else
return Image::writeBMP(out, data, true);
return Image::writeBMP(out, data);
#endif
}

View file

@ -132,7 +132,7 @@ bool BitmapDecoder::loadStream(Common::SeekableReadStream &stream) {
return true;
}
bool writeBMP(Common::WriteStream &out, const Graphics::Surface &input, const bool bottomUp) {
bool writeBMP(Common::WriteStream &out, const Graphics::Surface &input) {
#ifdef SCUMM_LITTLE_ENDIAN
const Graphics::PixelFormat requiredFormat_3byte(3, 8, 8, 8, 0, 16, 8, 0, 0);
#else
@ -170,16 +170,9 @@ bool writeBMP(Common::WriteStream &out, const Graphics::Surface &input, const bo
out.writeUint32LE(0);
if (bottomUp) {
for (uint y = 0; y < surface->h; ++y) {
out.write((const void *)surface->getBasePtr(0, y), dstPitch);
out.write(&padding, extraDataLength);
}
} else {
for (uint y = surface->h; y-- > 0;) {
out.write((const void *)surface->getBasePtr(0, y), dstPitch);
out.write(&padding, extraDataLength);
}
for (uint y = surface->h; y-- > 0;) {
out.write((const void *)surface->getBasePtr(0, y), dstPitch);
out.write(&padding, extraDataLength);
}
// free tmp surface

View file

@ -69,11 +69,8 @@ private:
/**
* Outputs an uncompressed BMP stream of the given input surface.
*
* @param bottomUp Flip the vertical axis so pixel data is drawn from the
* bottom up, instead of from the top down.
*/
bool writeBMP(Common::WriteStream &out, const Graphics::Surface &input, const bool bottomUp = false);
bool writeBMP(Common::WriteStream &out, const Graphics::Surface &input);
} // End of namespace Image

View file

@ -255,7 +255,7 @@ bool PNGDecoder::loadStream(Common::SeekableReadStream &stream) {
#endif
}
bool writePNG(Common::WriteStream &out, const Graphics::Surface &input, const bool bottomUp) {
bool writePNG(Common::WriteStream &out, const Graphics::Surface &input) {
#ifdef USE_PNG
#ifdef SCUMM_LITTLE_ENDIAN
const Graphics::PixelFormat requiredFormat_3byte(3, 8, 8, 8, 0, 0, 8, 16, 0);
@ -300,14 +300,8 @@ bool writePNG(Common::WriteStream &out, const Graphics::Surface &input, const bo
Common::Array<const uint8 *> rows;
rows.reserve(surface->h);
if (bottomUp) {
for (uint y = surface->h; y-- > 0;) {
rows.push_back((const uint8 *)surface->getBasePtr(0, y));
}
} else {
for (uint y = 0; y < surface->h; ++y) {
rows.push_back((const uint8 *)surface->getBasePtr(0, y));
}
for (uint y = 0; y < surface->h; ++y) {
rows.push_back((const uint8 *)surface->getBasePtr(0, y));
}
png_set_rows(pngPtr, infoPtr, const_cast<uint8 **>(&rows.front()));

View file

@ -78,11 +78,8 @@ private:
/**
* Outputs a compressed PNG stream of the given input surface.
*
* @param bottomUp Flip the vertical axis so pixel data is drawn from the
* bottom up, instead of from the top down.
*/
bool writePNG(Common::WriteStream &out, const Graphics::Surface &input, const bool bottomUp = false);
bool writePNG(Common::WriteStream &out, const Graphics::Surface &input);
} // End of namespace Image