[Scummvm-cvs-logs] scummvm master -> 6dabb5c414de8931c989a8fe5b0ac3eef3b67ac0

lordhoto lordhoto at gmail.com
Mon Dec 14 05:17:40 CET 2015


This automated email contains information about 7 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
f7683083e2 GRAPHICS: Use tabs for indentation.
74321fcd22 SWORD25: Let ImgLoader write into Graphics::Surface.
184ae49302 SWORD25: Plug memory leak in RenderedImage.
cb8e611e33 SWORD25: Fix uninitialized variable usage.
40421f1854 SWORD25: Cleanup.
69220505b6 GRAPHICS: Add function to query TransparentSurface's builtin PixelFormat.
6dabb5c414 SWORD25: Call requested pixel format by its correct name.


Commit: f7683083e2f47d9608f7ef3c4babfa56cb55bae0
    https://github.com/scummvm/scummvm/commit/f7683083e2f47d9608f7ef3c4babfa56cb55bae0
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2015-12-14T02:26:11+01:00

Commit Message:
GRAPHICS: Use tabs for indentation.

Changed paths:
    graphics/transparent_surface.h



diff --git a/graphics/transparent_surface.h b/graphics/transparent_surface.h
index efb2814..4a23522 100644
--- a/graphics/transparent_surface.h
+++ b/graphics/transparent_surface.h
@@ -50,22 +50,22 @@ namespace Graphics {
  @brief The possible flipping parameters for the blit method.
  */
 enum FLIP_FLAGS {
-    /// The image will not be flipped.
-    FLIP_NONE = 0,
-    /// The image will be flipped at the horizontal axis.
-    FLIP_H = 1,
-    /// The image will be flipped at the vertical axis.
-    FLIP_V = 2,
-    /// The image will be flipped at the horizontal and vertical axis.
-    FLIP_HV = FLIP_H | FLIP_V,
-    /// The image will be flipped at the horizontal and vertical axis.
-    FLIP_VH = FLIP_H | FLIP_V
+	/// The image will not be flipped.
+	FLIP_NONE = 0,
+	/// The image will be flipped at the horizontal axis.
+	FLIP_H = 1,
+	/// The image will be flipped at the vertical axis.
+	FLIP_V = 2,
+	/// The image will be flipped at the horizontal and vertical axis.
+	FLIP_HV = FLIP_H | FLIP_V,
+	/// The image will be flipped at the horizontal and vertical axis.
+	FLIP_VH = FLIP_H | FLIP_V
 };
 
 enum AlphaType {
-    ALPHA_OPAQUE = 0,
-    ALPHA_BINARY = 1,
-    ALPHA_FULL = 2
+	ALPHA_OPAQUE = 0,
+	ALPHA_BINARY = 1,
+	ALPHA_FULL = 2
 };
 
 /**


Commit: 74321fcd22e6bb6598abfefc9a52de87a422ee7a
    https://github.com/scummvm/scummvm/commit/74321fcd22e6bb6598abfefc9a52de87a422ee7a
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2015-12-14T05:08:05+01:00

Commit Message:
SWORD25: Let ImgLoader write into Graphics::Surface.

Changed paths:
    engines/sword25/gfx/image/imgloader.cpp
    engines/sword25/gfx/image/imgloader.h
    engines/sword25/gfx/image/renderedimage.cpp
    engines/sword25/gfx/image/swimage.cpp
    engines/sword25/gfx/image/swimage.h



diff --git a/engines/sword25/gfx/image/imgloader.cpp b/engines/sword25/gfx/image/imgloader.cpp
index f299cee..6ec0e7c 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 b932cdc..d9cf3f4 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 8c6369a..0225787 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 776f8ce..7a3c95b 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 60978eb..97c6395 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


Commit: 184ae49302792a924856ae051f1a96078f0723a1
    https://github.com/scummvm/scummvm/commit/184ae49302792a924856ae051f1a96078f0723a1
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2015-12-14T05:08:05+01:00

Commit Message:
SWORD25: Plug memory leak in RenderedImage.

Changed paths:
    engines/sword25/gfx/image/renderedimage.cpp
    engines/sword25/gfx/image/renderedimage.h



diff --git a/engines/sword25/gfx/image/renderedimage.cpp b/engines/sword25/gfx/image/renderedimage.cpp
index 0225787..8d90d1f 100644
--- a/engines/sword25/gfx/image/renderedimage.cpp
+++ b/engines/sword25/gfx/image/renderedimage.cpp
@@ -178,6 +178,9 @@ RenderedImage::RenderedImage() : _isTransparent(true) {
 // -----------------------------------------------------------------------------
 
 RenderedImage::~RenderedImage() {
+	if (_doCleanup) {
+		_surface.free();
+	}
 }
 
 // -----------------------------------------------------------------------------
diff --git a/engines/sword25/gfx/image/renderedimage.h b/engines/sword25/gfx/image/renderedimage.h
index 5b65a27..e4d573f 100644
--- a/engines/sword25/gfx/image/renderedimage.h
+++ b/engines/sword25/gfx/image/renderedimage.h
@@ -44,6 +44,9 @@
 namespace Sword25 {
 
 class RenderedImage : public Image {
+private:
+	RenderedImage(const RenderedImage &) : _doCleanup(false) {}
+	RenderedImage &operator=(const RenderedImage &) { return *this; }
 public:
 	RenderedImage(const Common::String &filename, bool &result);
 


Commit: cb8e611e3373d8a87c931855916cf079eaad55dc
    https://github.com/scummvm/scummvm/commit/cb8e611e3373d8a87c931855916cf079eaad55dc
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2015-12-14T05:08:05+01:00

Commit Message:
SWORD25: Fix uninitialized variable usage.

When using the constructor of Panel which directly calls unpersist _color was
uninitialized. However, unpersit uses setColor which assumes _color is
initialized properly. Caused valgrind warnings when loading.

Changed paths:
    engines/sword25/gfx/panel.cpp



diff --git a/engines/sword25/gfx/panel.cpp b/engines/sword25/gfx/panel.cpp
index 9699db7..2b71854 100644
--- a/engines/sword25/gfx/panel.cpp
+++ b/engines/sword25/gfx/panel.cpp
@@ -62,7 +62,7 @@ Panel::Panel(RenderObjectPtr<RenderObject> parentPtr, int width, int height, uin
 }
 
 Panel::Panel(InputPersistenceBlock &reader, RenderObjectPtr<RenderObject> parentPtr, uint handle) :
-	RenderObject(parentPtr, RenderObject::TYPE_PANEL, handle) {
+	RenderObject(parentPtr, RenderObject::TYPE_PANEL, handle), _color(0) {
 	_initSuccess = unpersist(reader);
 }
 


Commit: 40421f1854a157703c3c8faddc1b622c39ecce4c
    https://github.com/scummvm/scummvm/commit/40421f1854a157703c3c8faddc1b622c39ecce4c
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2015-12-14T05:08:05+01:00

Commit Message:
SWORD25: Cleanup.

Changed paths:
    engines/sword25/gfx/image/vectorimage.cpp



diff --git a/engines/sword25/gfx/image/vectorimage.cpp b/engines/sword25/gfx/image/vectorimage.cpp
index 756d063..a678fdc 100644
--- a/engines/sword25/gfx/image/vectorimage.cpp
+++ b/engines/sword25/gfx/image/vectorimage.cpp
@@ -311,8 +311,7 @@ VectorImage::~VectorImage() {
 			if (_elements[j].getPathInfo(i).getVec())
 				free(_elements[j].getPathInfo(i).getVec());
 
-	if (_pixelData)
-		free(_pixelData);
+	free(_pixelData);
 }
 
 


Commit: 69220505b6109227984f0d5de97180e989d1adce
    https://github.com/scummvm/scummvm/commit/69220505b6109227984f0d5de97180e989d1adce
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2015-12-14T05:16:12+01:00

Commit Message:
GRAPHICS: Add function to query TransparentSurface's builtin PixelFormat.

Changed paths:
    graphics/transparent_surface.h



diff --git a/graphics/transparent_surface.h b/graphics/transparent_surface.h
index 4a23522..0cd7d5b 100644
--- a/graphics/transparent_surface.h
+++ b/graphics/transparent_surface.h
@@ -75,6 +75,18 @@ struct TransparentSurface : public Graphics::Surface {
 	TransparentSurface();
 	TransparentSurface(const Graphics::Surface &surf, bool copyData = false);
 
+	/**
+	 * Returns the pixel format all operations of TransparentSurface support.
+	 *
+	 * Unlike Surface TransparentSurface only works with a fixed pixel format.
+	 * This format can be queried using this static function.
+	 *
+	 * @return Supported pixel format.
+	 */
+	static PixelFormat getSupportedPixelFormat() {
+		return PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0);
+	}
+
 	void setColorKey(char r, char g, char b);
 	void disableColorKey();
 


Commit: 6dabb5c414de8931c989a8fe5b0ac3eef3b67ac0
    https://github.com/scummvm/scummvm/commit/6dabb5c414de8931c989a8fe5b0ac3eef3b67ac0
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2015-12-14T05:16:12+01:00

Commit Message:
SWORD25: Call requested pixel format by its correct name.

Changed paths:
    engines/sword25/sword25.cpp



diff --git a/engines/sword25/sword25.cpp b/engines/sword25/sword25.cpp
index 76142c2..5223481 100644
--- a/engines/sword25/sword25.cpp
+++ b/engines/sword25/sword25.cpp
@@ -95,7 +95,7 @@ Common::Error Sword25Engine::run() {
 }
 
 Common::Error Sword25Engine::appStart() {
-	// Initialize the graphics mode to ARGB8888
+	// Initialize the graphics mode to RGBA8888
 	Graphics::PixelFormat format = Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0);
 	initGraphics(800, 600, true, &format);
 	if (format != g_system->getScreenFormat())






More information about the Scummvm-git-logs mailing list