From 8ae17b481a8f0a0c7d78e975a32e9e6df055b8df Mon Sep 17 00:00:00 2001 From: Cameron Cawley Date: Fri, 1 Mar 2019 00:15:43 +0000 Subject: IMAGE: Move bitmap writing code out of OpenGLGraphicsManager --- image/bmp.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'image/bmp.cpp') diff --git a/image/bmp.cpp b/image/bmp.cpp index 28eb049035..ce2b099797 100644 --- a/image/bmp.cpp +++ b/image/bmp.cpp @@ -132,4 +132,59 @@ bool BitmapDecoder::loadStream(Common::SeekableReadStream &stream) { return true; } +bool writeBMP(Common::WriteStream &out, const Graphics::Surface &input, const bool bottomUp) { + const Graphics::PixelFormat requiredFormat_3byte(3, 8, 8, 8, 0, 0, 8, 16, 0); + + Graphics::Surface *tmp = NULL; + const Graphics::Surface *surface; + + if (input.format == requiredFormat_3byte) { + surface = &input; + } else { + surface = tmp = input.convertTo(requiredFormat_3byte); + } + + int dstPitch = surface->w * 3; + int extraDataLength = (dstPitch % 4) ? 4 - (dstPitch % 4) : 0; + int padding = 0; + + out.writeByte('B'); + out.writeByte('M'); + out.writeUint32LE(surface->h * dstPitch + 54); + out.writeUint32LE(0); + out.writeUint32LE(54); + out.writeUint32LE(40); + out.writeUint32LE(surface->w); + out.writeUint32LE(surface->h); + out.writeUint16LE(1); + out.writeUint16LE(24); + out.writeUint32LE(0); + out.writeUint32LE(0); + out.writeUint32LE(0); + out.writeUint32LE(0); + out.writeUint32LE(0); + 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); + } + } + + // free tmp surface + if (tmp) { + tmp->free(); + delete tmp; + } + + return true; +} + } // End of namespace Image -- cgit v1.2.3