[Scummvm-cvs-logs] scummvm master -> 62c026d3b6a17ab3e7634cf3d4e5b63bbf0aa7eb
bluegr
md5 at scummvm.org
Thu May 26 11:31:39 CEST 2011
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
62c026d3b6 SWORD25: Merged the PNG and thumbnail decoding code into a common class
Commit: 62c026d3b6a17ab3e7634cf3d4e5b63bbf0aa7eb
https://github.com/scummvm/scummvm/commit/62c026d3b6a17ab3e7634cf3d4e5b63bbf0aa7eb
Author: md5 (md5 at scummvm.org)
Date: 2011-05-26T02:29:51-07:00
Commit Message:
SWORD25: Merged the PNG and thumbnail decoding code into a common class
Changed paths:
A engines/sword25/gfx/image/imgloader.cpp
A engines/sword25/gfx/image/imgloader.h
R engines/sword25/gfx/image/pngloader.cpp
R engines/sword25/gfx/image/pngloader.h
engines/sword25/gfx/image/renderedimage.cpp
engines/sword25/gfx/image/swimage.cpp
diff --git a/engines/sword25/gfx/image/imgloader.cpp b/engines/sword25/gfx/image/imgloader.cpp
new file mode 100644
index 0000000..1df0fba
--- /dev/null
+++ b/engines/sword25/gfx/image/imgloader.cpp
@@ -0,0 +1,85 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+/*
+ * This code is based on Broken Sword 2.5 engine
+ *
+ * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
+ *
+ * Licensed under GNU GPL v2
+ *
+ */
+
+#include "common/memstream.h"
+#include "sword25/gfx/image/image.h"
+#include "sword25/gfx/image/imgloader.h"
+#include "graphics/pixelformat.h"
+#include "graphics/png.h"
+
+namespace Sword25 {
+
+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
+ error("Error while reading PNG image");
+
+ Graphics::PixelFormat format = Graphics::PixelFormat(4, 8, 8, 8, 8, 16, 8, 0, 24);
+ Graphics::Surface *pngSurface = png->getSurface(format);
+
+ width = pngSurface->w;
+ height = pngSurface->h;
+ uncompressedDataPtr = new byte[pngSurface->pitch * pngSurface->h];
+ memcpy(uncompressedDataPtr, (byte *)pngSurface->pixels, pngSurface->pitch * pngSurface->h);
+ pngSurface->free();
+
+ delete pngSurface;
+ delete png;
+
+ // Signal success
+ 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/imgloader.h b/engines/sword25/gfx/image/imgloader.h
new file mode 100644
index 0000000..735ab92
--- /dev/null
+++ b/engines/sword25/gfx/image/imgloader.h
@@ -0,0 +1,78 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+/*
+ * This code is based on Broken Sword 2.5 engine
+ *
+ * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
+ *
+ * Licensed under GNU GPL v2
+ *
+ */
+
+#ifndef SWORD25_IMGLOADER_H
+#define SWORD25_IMGLOADER_H
+
+#include "sword25/kernel/common.h"
+#include "sword25/gfx/graphicengine.h"
+
+namespace Sword25 {
+
+/**
+ * Class for loading PNG files, and PNG data embedded into savegames.
+ *
+ * Originally written by Malte Thiesen.
+ */
+class ImgLoader {
+protected:
+ ImgLoader() {} // Protected constructor to prevent instances
+
+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
+ * @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);
+
+ static bool decodeThumbnailImage(const byte *pFileData, uint fileSize,
+ byte *&pUncompressedData,
+ int &width, int &height,
+ int &pitch);
+};
+
+} // End of namespace Sword25
+
+#endif
diff --git a/engines/sword25/gfx/image/pngloader.cpp b/engines/sword25/gfx/image/pngloader.cpp
deleted file mode 100644
index 9219940..0000000
--- a/engines/sword25/gfx/image/pngloader.cpp
+++ /dev/null
@@ -1,62 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-/*
- * This code is based on Broken Sword 2.5 engine
- *
- * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
- *
- * Licensed under GNU GPL v2
- *
- */
-
-#include "common/memstream.h"
-#include "sword25/gfx/image/image.h"
-#include "sword25/gfx/image/pngloader.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) {
- 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
- error("Error while reading PNG image");
-
- Graphics::PixelFormat format = Graphics::PixelFormat(4, 8, 8, 8, 8, 16, 8, 0, 24);
- Graphics::Surface *pngSurface = png->getSurface(format);
-
- width = pngSurface->w;
- height = pngSurface->h;
- uncompressedDataPtr = new byte[pngSurface->pitch * pngSurface->h];
- memcpy(uncompressedDataPtr, (byte *)pngSurface->pixels, pngSurface->pitch * pngSurface->h);
- pngSurface->free();
-
- delete pngSurface;
- delete png;
-
- // Signal success
- return true;
-}
-
-} // End of namespace Sword25
diff --git a/engines/sword25/gfx/image/pngloader.h b/engines/sword25/gfx/image/pngloader.h
deleted file mode 100644
index 3f90931..0000000
--- a/engines/sword25/gfx/image/pngloader.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-/*
- * This code is based on Broken Sword 2.5 engine
- *
- * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
- *
- * Licensed under GNU GPL v2
- *
- */
-
-#ifndef SWORD25_PNGLOADER2_H
-#define SWORD25_PNGLOADER2_H
-
-#include "sword25/kernel/common.h"
-#include "sword25/gfx/graphicengine.h"
-
-namespace Sword25 {
-
-/**
- * Class for loading PNG files, and PNG data embedded into savegames.
- *
- * Originally written by Malte Thiesen.
- */
-class PNGLoader {
-protected:
- PNGLoader() {} // Protected constructor to prevent instances
-
-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
- * @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 decodeImage(const byte *pFileData, uint fileSize,
- byte *&pUncompressedData,
- int &width, int &height,
- int &pitch);
-};
-
-} // End of namespace Sword25
-
-#endif
diff --git a/engines/sword25/gfx/image/renderedimage.cpp b/engines/sword25/gfx/image/renderedimage.cpp
index 476d293..a9c9de4 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 0978eb5..0b9cc11 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;
}
More information about the Scummvm-git-logs
mailing list