diff options
author | md5 | 2011-05-26 12:29:51 +0300 |
---|---|---|
committer | md5 | 2011-05-26 12:29:51 +0300 |
commit | 62c026d3b6a17ab3e7634cf3d4e5b63bbf0aa7eb (patch) | |
tree | eedcb53d6c996a5d91fd996b70a3039a02d6e4e8 | |
parent | a654115f1a9a1497ee7d73a3c861e4f37ab1e081 (diff) | |
download | scummvm-rg350-62c026d3b6a17ab3e7634cf3d4e5b63bbf0aa7eb.tar.gz scummvm-rg350-62c026d3b6a17ab3e7634cf3d4e5b63bbf0aa7eb.tar.bz2 scummvm-rg350-62c026d3b6a17ab3e7634cf3d4e5b63bbf0aa7eb.zip |
SWORD25: Merged the PNG and thumbnail decoding code into a common class
-rw-r--r-- | engines/sword25/gfx/image/imgloader.cpp (renamed from engines/sword25/gfx/image/pngloader.cpp) | 27 | ||||
-rw-r--r-- | engines/sword25/gfx/image/imgloader.h (renamed from engines/sword25/gfx/image/pngloader.h) | 15 | ||||
-rw-r--r-- | engines/sword25/gfx/image/renderedimage.cpp | 30 | ||||
-rw-r--r-- | engines/sword25/gfx/image/swimage.cpp | 4 |
4 files changed, 40 insertions, 36 deletions
diff --git a/engines/sword25/gfx/image/pngloader.cpp b/engines/sword25/gfx/image/imgloader.cpp index 921994052f..1df0fba70c 100644 --- a/engines/sword25/gfx/image/pngloader.cpp +++ b/engines/sword25/gfx/image/imgloader.cpp @@ -31,13 +31,13 @@ #include "common/memstream.h" #include "sword25/gfx/image/image.h" -#include "sword25/gfx/image/pngloader.h" +#include "sword25/gfx/image/imgloader.h" #include "graphics/pixelformat.h" #include "graphics/png.h" namespace Sword25 { -bool PNGLoader::decodeImage(const byte *fileDataPtr, uint fileSize, byte *&uncompressedDataPtr, int &width, int &height, int &pitch) { +bool ImgLoader::decodePNGImage(const byte *fileDataPtr, uint fileSize, byte *&uncompressedDataPtr, int &width, int &height, int &pitch) { Common::MemoryReadStream *fileStr = new Common::MemoryReadStream(fileDataPtr, fileSize, DisposeAfterUse::NO); Graphics::PNG *png = new Graphics::PNG(); if (!png->read(fileStr)) // the fileStr pointer, and thus pFileData will be deleted after this is done @@ -59,4 +59,27 @@ bool PNGLoader::decodeImage(const byte *fileDataPtr, uint fileSize, byte *&uncom return true; } +bool ImgLoader::decodeThumbnailImage(const byte *pFileData, uint fileSize, byte *&pUncompressedData, int &width, int &height, int &pitch) { + const byte *src = pFileData + 4; // skip header + width = READ_LE_UINT16(src); src += 2; + 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, 16, 8, 0, 24); + byte r, g, b; + + for (uint32 i = 0; i < totalSize / 4; i++) { + r = *src++; + g = *src++; + b = *src++; + *dst++ = format.RGBToColor(r, g, b); + } + + return true; +} + } // End of namespace Sword25 diff --git a/engines/sword25/gfx/image/pngloader.h b/engines/sword25/gfx/image/imgloader.h index 3f909315ab..735ab9203c 100644 --- a/engines/sword25/gfx/image/pngloader.h +++ b/engines/sword25/gfx/image/imgloader.h @@ -29,8 +29,8 @@ * */ -#ifndef SWORD25_PNGLOADER2_H -#define SWORD25_PNGLOADER2_H +#ifndef SWORD25_IMGLOADER_H +#define SWORD25_IMGLOADER_H #include "sword25/kernel/common.h" #include "sword25/gfx/graphicengine.h" @@ -42,9 +42,9 @@ namespace Sword25 { * * Originally written by Malte Thiesen. */ -class PNGLoader { +class ImgLoader { protected: - PNGLoader() {} // Protected constructor to prevent instances + ImgLoader() {} // Protected constructor to prevent instances public: @@ -62,7 +62,12 @@ public: * @remark This function does not free the image buffer passed to it, * it is the callers responsibility to do so. */ - static bool decodeImage(const byte *pFileData, uint fileSize, + static bool decodePNGImage(const byte *pFileData, uint fileSize, + byte *&pUncompressedData, + int &width, int &height, + int &pitch); + + static bool decodeThumbnailImage(const byte *pFileData, uint fileSize, byte *&pUncompressedData, int &width, int &height, int &pitch); diff --git a/engines/sword25/gfx/image/renderedimage.cpp b/engines/sword25/gfx/image/renderedimage.cpp index 476d293779..a9c9de4f0c 100644 --- a/engines/sword25/gfx/image/renderedimage.cpp +++ b/engines/sword25/gfx/image/renderedimage.cpp @@ -35,7 +35,7 @@ #include "common/savefile.h" #include "sword25/package/packagemanager.h" -#include "sword25/gfx/image/pngloader.h" +#include "sword25/gfx/image/imgloader.h" #include "sword25/gfx/image/renderedimage.h" #include "common/system.h" @@ -93,30 +93,6 @@ static byte *readSavegameThumbnail(const Common::String &filename, uint &fileSiz return pFileData; } -// TODO: Move this method into a more generic image loading class, together with the PNG reading code -static bool decodeThumbnail(const byte *pFileData, uint fileSize, byte *&pUncompressedData, int &width, int &height, int &pitch) { - const byte *src = pFileData + 4; // skip header - width = READ_LE_UINT16(src); src += 2; - 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, 16, 8, 0, 24); - byte r, g, b; - - for (uint32 i = 0; i < totalSize / 4; i++) { - r = *src++; - g = *src++; - b = *src++; - *dst++ = format.RGBToColor(r, g, b); - } - - return true; -} - RenderedImage::RenderedImage(const Common::String &filename, bool &result) : _data(0), _width(0), @@ -148,9 +124,9 @@ RenderedImage::RenderedImage(const Common::String &filename, bool &result) : // Uncompress the image int pitch; if (isPNG) - result = PNGLoader::decodeImage(pFileData, fileSize, _data, _width, _height, pitch); + result = ImgLoader::decodePNGImage(pFileData, fileSize, _data, _width, _height, pitch); else - result = decodeThumbnail(pFileData, fileSize, _data, _width, _height, pitch); + result = ImgLoader::decodeThumbnailImage(pFileData, fileSize, _data, _width, _height, pitch); if (!result) { error("Could not decode image."); diff --git a/engines/sword25/gfx/image/swimage.cpp b/engines/sword25/gfx/image/swimage.cpp index 0978eb5ac1..0b9cc11df2 100644 --- a/engines/sword25/gfx/image/swimage.cpp +++ b/engines/sword25/gfx/image/swimage.cpp @@ -30,7 +30,7 @@ */ #include "sword25/package/packagemanager.h" -#include "sword25/gfx/image/pngloader.h" +#include "sword25/gfx/image/imgloader.h" #include "sword25/gfx/image/swimage.h" namespace Sword25 { @@ -56,7 +56,7 @@ SWImage::SWImage(const Common::String &filename, bool &result) : // Uncompress the image int pitch; byte *pUncompressedData; - if (!PNGLoader::decodeImage(pFileData, fileSize, pUncompressedData, _width, _height, pitch)) { + if (!ImgLoader::decodePNGImage(pFileData, fileSize, pUncompressedData, _width, _height, pitch)) { error("Could not decode image."); return; } |