From 882989f5c3a29cf560ca8cb27d09edde7fda5e7e Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Fri, 13 Nov 2015 00:03:42 +0100 Subject: SWORD25: Fix thumbnail generation and make it portable --- engines/sword25/gfx/screenshot.cpp | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) (limited to 'engines/sword25/gfx') diff --git a/engines/sword25/gfx/screenshot.cpp b/engines/sword25/gfx/screenshot.cpp index 4b4f967f29..eeaece97f2 100644 --- a/engines/sword25/gfx/screenshot.cpp +++ b/engines/sword25/gfx/screenshot.cpp @@ -40,7 +40,7 @@ namespace Sword25 { bool Screenshot::saveToFile(Graphics::Surface *data, Common::WriteStream *stream) { // Convert the RGBA data to RGB - const byte *pSrc = (const byte *)data->getPixels(); + const uint32 *pSrc = (const uint32 *)data->getPixels(); // Write our own custom header stream->writeUint32BE(MKTAG('S','C','R','N')); // SCRN, short for "Screenshot" @@ -52,11 +52,12 @@ bool Screenshot::saveToFile(Graphics::Surface *data, Common::WriteStream *stream for (uint x = 0; x < data->w; x++) { // This is only called by createThumbnail below, which // provides a fake 'surface' with LE data in it. - uint32 srcPixel = READ_LE_UINT32(pSrc); - pSrc += sizeof(uint32); - stream->writeByte((srcPixel >> 16) & 0xff); // R - stream->writeByte((srcPixel >> 8) & 0xff); // G - stream->writeByte(srcPixel & 0xff); // B + byte a, r, g, b; + + data->format.colorToARGB(*pSrc++, a, r, g, b); + stream->writeByte(r); + stream->writeByte(g); + stream->writeByte(b); } } @@ -81,30 +82,27 @@ Common::SeekableReadStream *Screenshot::createThumbnail(Graphics::Surface *data) Graphics::Surface thumbnail; thumbnail.create(200, 125, g_system->getScreenFormat()); - // Über das Zielbild iterieren und einen Pixel zur Zeit berechnen. + // Uber das Zielbild iterieren und einen Pixel zur Zeit berechnen. uint x, y; x = y = 0; - for (byte *pDest = (byte *)thumbnail.getPixels(); pDest < ((byte *)thumbnail.getBasePtr(0, thumbnail.h)); ) { + for (uint32 *pDest = (uint32 *)thumbnail.getPixels(); pDest < thumbnail.getBasePtr(0, thumbnail.h); ) { // Get an average over a 4x4 pixel block in the source image int alpha, red, green, blue; alpha = red = green = blue = 0; for (int j = 0; j < 4; ++j) { const uint32 *srcP = (const uint32 *)data->getBasePtr(x * 4, y * 4 + j + 50); for (int i = 0; i < 4; ++i) { - uint32 pixel = READ_UINT32(srcP + i); - alpha += (pixel >> 24); - red += (pixel >> 16) & 0xff; - green += (pixel >> 8) & 0xff; - blue += pixel & 0xff; + byte a, r, g, b; + data->format.colorToARGB(*(srcP + i), a, r, g, b); + alpha += a; + red += r; + green += g; + blue += b; } } - // Write target pixel - *pDest++ = blue / 16; - *pDest++ = green / 16; - *pDest++ = red / 16; - *pDest++ = alpha / 16; + *pDest++ = thumbnail.format.ARGBToColor(alpha / 16, red / 16, green / 16, blue / 16); // Move to next block ++x; -- cgit v1.2.3