diff options
Diffstat (limited to 'engines/sword25/gfx/image/imgloader.cpp')
-rw-r--r-- | engines/sword25/gfx/image/imgloader.cpp | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/engines/sword25/gfx/image/imgloader.cpp b/engines/sword25/gfx/image/imgloader.cpp index f299cee9d1..6ec0e7c542 100644 --- a/engines/sword25/gfx/image/imgloader.cpp +++ b/engines/sword25/gfx/image/imgloader.cpp @@ -33,11 +33,13 @@ #include "sword25/gfx/image/image.h" #include "sword25/gfx/image/imgloader.h" #include "graphics/pixelformat.h" +#include "graphics/surface.h" #include "image/png.h" namespace Sword25 { -bool ImgLoader::decodePNGImage(const byte *fileDataPtr, uint fileSize, byte *&uncompressedDataPtr, int &width, int &height, int &pitch) { +bool ImgLoader::decodePNGImage(const byte *fileDataPtr, uint fileSize, Graphics::Surface *dest) { + assert(dest); Common::MemoryReadStream *fileStr = new Common::MemoryReadStream(fileDataPtr, fileSize, DisposeAfterUse::NO); ::Image::PNGDecoder png; @@ -47,12 +49,9 @@ bool ImgLoader::decodePNGImage(const byte *fileDataPtr, uint fileSize, byte *&un const Graphics::Surface *sourceSurface = png.getSurface(); Graphics::Surface *pngSurface = sourceSurface->convertTo(Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0), png.getPalette()); - width = pngSurface->w; - height = pngSurface->h; - uncompressedDataPtr = new byte[pngSurface->pitch * pngSurface->h]; - memcpy(uncompressedDataPtr, (byte *)pngSurface->getPixels(), pngSurface->pitch * pngSurface->h); - pngSurface->free(); + dest->copyFrom(*pngSurface); + pngSurface->free(); delete pngSurface; delete fileStr; @@ -60,24 +59,22 @@ bool ImgLoader::decodePNGImage(const byte *fileDataPtr, uint fileSize, byte *&un return true; } -bool ImgLoader::decodeThumbnailImage(const byte *pFileData, uint fileSize, byte *&pUncompressedData, int &width, int &height, int &pitch) { +bool ImgLoader::decodeThumbnailImage(const byte *pFileData, uint fileSize, Graphics::Surface *dest) { + assert(dest); const byte *src = pFileData + 4; // skip header - width = READ_LE_UINT16(src); src += 2; - height = READ_LE_UINT16(src); src += 2; + uint width = READ_LE_UINT16(src); src += 2; + uint height = READ_LE_UINT16(src); src += 2; src++; // version, ignored for now - pitch = width * 4; - uint32 totalSize = pitch * height; - pUncompressedData = new byte[totalSize]; - uint32 *dst = (uint32 *)pUncompressedData; // treat as uint32, for pixelformat output - const Graphics::PixelFormat format = Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0); + dest->create(width, height, Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0)); + uint32 *dst = (uint32 *)dest->getBasePtr(0, 0); // treat as uint32, for pixelformat output byte r, g, b; - for (uint32 i = 0; i < totalSize / 4; i++) { + for (uint32 i = 0; i < width * height; i++) { r = *src++; g = *src++; b = *src++; - *dst++ = format.RGBToColor(r, g, b); + *dst++ = dest->format.RGBToColor(r, g, b); } return true; |