aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
Diffstat (limited to 'engines')
-rw-r--r--engines/sword25/gfx/image/imgloader.cpp29
-rw-r--r--engines/sword25/gfx/image/imgloader.h19
-rw-r--r--engines/sword25/gfx/image/renderedimage.cpp13
-rw-r--r--engines/sword25/gfx/image/swimage.cpp19
-rw-r--r--engines/sword25/gfx/image/swimage.h9
5 files changed, 32 insertions, 57 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;
diff --git a/engines/sword25/gfx/image/imgloader.h b/engines/sword25/gfx/image/imgloader.h
index b932cdc903..d9cf3f4d6d 100644
--- a/engines/sword25/gfx/image/imgloader.h
+++ b/engines/sword25/gfx/image/imgloader.h
@@ -35,6 +35,10 @@
#include "sword25/kernel/common.h"
#include "sword25/gfx/graphicengine.h"
+namespace Graphics {
+struct Surface;
+} // End of namespace Graphics
+
namespace Sword25 {
/**
@@ -52,25 +56,18 @@ public:
* Decode an image.
* @param[in] fileDatePtr pointer to the image data
* @param[in] fileSize size of the image data in bytes
- * @param[out] pUncompressedData if successful, this is set to a pointer containing the decoded image data
- * @param[out] width if successful, this is set to the width of the image
- * @param[out] height if successful, this is set to the height of the image
- * @param[out] pitch if successful, this is set to the number of bytes per scanline in the image
+ * @param[out] dest if successful, surface will contain the image
+ * data (storage is allocated via create).
* @return false in case of an error
*
- * @remark The size of the output data equals pitch * height.
* @remark This function does not free the image buffer passed to it,
* it is the callers responsibility to do so.
*/
static bool decodePNGImage(const byte *pFileData, uint fileSize,
- byte *&pUncompressedData,
- int &width, int &height,
- int &pitch);
+ Graphics::Surface *dest);
static bool decodeThumbnailImage(const byte *pFileData, uint fileSize,
- byte *&pUncompressedData,
- int &width, int &height,
- int &pitch);
+ Graphics::Surface *dest);
};
} // End of namespace Sword25
diff --git a/engines/sword25/gfx/image/renderedimage.cpp b/engines/sword25/gfx/image/renderedimage.cpp
index 8c6369a790..0225787fde 100644
--- a/engines/sword25/gfx/image/renderedimage.cpp
+++ b/engines/sword25/gfx/image/renderedimage.cpp
@@ -126,19 +126,10 @@ RenderedImage::RenderedImage(const Common::String &filename, bool &result) :
}
// Uncompress the image
- int pitch;
- byte *dst;
- int w, h;
if (isPNG)
- result = ImgLoader::decodePNGImage(pFileData, fileSize, dst, w, h, pitch);
+ result = ImgLoader::decodePNGImage(pFileData, fileSize, &_surface);
else
- result = ImgLoader::decodeThumbnailImage(pFileData, fileSize, dst, w, h, pitch);
-
- _surface.w = w;
- _surface.h = h;
- _surface.pitch = w * 4;
- _surface.setPixels(dst);
- _surface.format = Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0);
+ result = ImgLoader::decodeThumbnailImage(pFileData, fileSize, &_surface);
if (!result) {
error("Could not decode image.");
diff --git a/engines/sword25/gfx/image/swimage.cpp b/engines/sword25/gfx/image/swimage.cpp
index 776f8ce8d3..7a3c95b5f9 100644
--- a/engines/sword25/gfx/image/swimage.cpp
+++ b/engines/sword25/gfx/image/swimage.cpp
@@ -35,10 +35,7 @@
namespace Sword25 {
-SWImage::SWImage(const Common::String &filename, bool &result) :
- _imageDataPtr(0),
- _width(0),
- _height(0) {
+SWImage::SWImage(const Common::String &filename, bool &result) : _image() {
result = false;
PackageManager *pPackage = Kernel::getInstance()->getPackage();
@@ -54,9 +51,7 @@ SWImage::SWImage(const Common::String &filename, bool &result) :
}
// Uncompress the image
- int pitch;
- byte *pUncompressedData;
- if (!ImgLoader::decodePNGImage(pFileData, fileSize, pUncompressedData, _width, _height, pitch)) {
+ if (!ImgLoader::decodePNGImage(pFileData, fileSize, &_image)) {
error("Could not decode image.");
return;
}
@@ -64,14 +59,12 @@ SWImage::SWImage(const Common::String &filename, bool &result) :
// Cleanup FileData
delete[] pFileData;
- _imageDataPtr = (uint *)pUncompressedData;
-
result = true;
return;
}
SWImage::~SWImage() {
- delete[] _imageDataPtr;
+ _image.free();
}
@@ -96,10 +89,10 @@ bool SWImage::setContent(const byte *pixeldata, uint size, uint offset, uint str
}
uint SWImage::getPixel(int x, int y) {
- assert(x >= 0 && x < _width);
- assert(y >= 0 && y < _height);
+ assert(x >= 0 && x < _image.w);
+ assert(y >= 0 && y < _image.h);
- return _imageDataPtr[_width * y + x];
+ return *((const uint32 *)_image.getBasePtr(0, 0));
}
} // End of namespace Sword25
diff --git a/engines/sword25/gfx/image/swimage.h b/engines/sword25/gfx/image/swimage.h
index 60978eb6cc..97c6395278 100644
--- a/engines/sword25/gfx/image/swimage.h
+++ b/engines/sword25/gfx/image/swimage.h
@@ -45,10 +45,10 @@ public:
virtual ~SWImage();
virtual int getWidth() const {
- return _width;
+ return _image.w;
}
virtual int getHeight() const {
- return _height;
+ return _image.h;
}
virtual GraphicEngine::COLOR_FORMATS getColorFormat() const {
return GraphicEngine::CF_ARGB32;
@@ -86,10 +86,7 @@ public:
return false;
}
private:
- uint *_imageDataPtr;
-
- int _width;
- int _height;
+ Graphics::Surface _image;
};
} // End of namespace Sword25