aboutsummaryrefslogtreecommitdiff
path: root/engines/sword25/gfx/image
diff options
context:
space:
mode:
authorMatthew Hoops2011-05-18 18:23:37 -0400
committerMatthew Hoops2011-05-18 18:23:37 -0400
commitd4c92983920cfe3b25a22d91e12c750e591b917e (patch)
treec0b63318b9ba0e67528337cfaa21515def1c3962 /engines/sword25/gfx/image
parent7e2edf16b3e2bf1d2b31999979a60802514df6cb (diff)
parentcf107e24be28c7e6db65b5c7ffed120af4a7994b (diff)
downloadscummvm-rg350-d4c92983920cfe3b25a22d91e12c750e591b917e.tar.gz
scummvm-rg350-d4c92983920cfe3b25a22d91e12c750e591b917e.tar.bz2
scummvm-rg350-d4c92983920cfe3b25a22d91e12c750e591b917e.zip
Merge remote branch 'upstream/master' into pegasus
Diffstat (limited to 'engines/sword25/gfx/image')
-rw-r--r--engines/sword25/gfx/image/art.cpp3
-rw-r--r--engines/sword25/gfx/image/art.h3
-rw-r--r--engines/sword25/gfx/image/image.h3
-rw-r--r--engines/sword25/gfx/image/pngloader.cpp67
-rw-r--r--engines/sword25/gfx/image/pngloader.h12
-rw-r--r--engines/sword25/gfx/image/renderedimage.cpp104
-rw-r--r--engines/sword25/gfx/image/renderedimage.h3
-rw-r--r--engines/sword25/gfx/image/swimage.cpp7
-rw-r--r--engines/sword25/gfx/image/swimage.h3
-rw-r--r--engines/sword25/gfx/image/vectorimage.cpp3
-rw-r--r--engines/sword25/gfx/image/vectorimage.h3
-rw-r--r--engines/sword25/gfx/image/vectorimagerenderer.cpp3
12 files changed, 117 insertions, 97 deletions
diff --git a/engines/sword25/gfx/image/art.cpp b/engines/sword25/gfx/image/art.cpp
index 69f9425a53..cd7cfb6b69 100644
--- a/engines/sword25/gfx/image/art.cpp
+++ b/engines/sword25/gfx/image/art.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/image/art.h b/engines/sword25/gfx/image/art.h
index fe3bbd4982..bfeb31cc30 100644
--- a/engines/sword25/gfx/image/art.h
+++ b/engines/sword25/gfx/image/art.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/image/image.h b/engines/sword25/gfx/image/image.h
index 7029402c4a..f1934656da 100644
--- a/engines/sword25/gfx/image/image.h
+++ b/engines/sword25/gfx/image/image.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/image/pngloader.cpp b/engines/sword25/gfx/image/pngloader.cpp
index f6c00b6968..6f370d8861 100644
--- a/engines/sword25/gfx/image/pngloader.cpp
+++ b/engines/sword25/gfx/image/pngloader.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
@@ -32,9 +29,6 @@
*
*/
-// Define to use ScummVM's PNG decoder, instead of libpng
-#define USE_INTERNAL_PNG_DECODER
-
#ifndef USE_INTERNAL_PNG_DECODER
// Disable symbol overrides so that we can use png.h
#define FORBIDDEN_SYMBOL_ALLOW_ALL
@@ -52,51 +46,6 @@
namespace Sword25 {
-/**
- * Load a NULL-terminated string from the given stream.
- */
-static Common::String loadString(Common::ReadStream &in, uint maxSize = 999) {
- Common::String result;
-
- while (!in.eos() && (result.size() < maxSize)) {
- char ch = (char)in.readByte();
- if (ch == '\0')
- break;
-
- result += ch;
- }
-
- return result;
-}
-
-/**
- * Check if the given data is a savegame, and if so, locate the
- * offset to the image data.
- * @return offset to image data if fileDataPtr contains a savegame; 0 otherwise
- */
-static uint findEmbeddedPNG(const byte *fileDataPtr, uint fileSize) {
- if (fileSize < 100)
- return 0;
- if (memcmp(fileDataPtr, "BS25SAVEGAME", 12))
- return 0;
-
- // Read in the header
- Common::MemoryReadStream stream(fileDataPtr, fileSize);
- stream.seek(0, SEEK_SET);
-
- // Read header information of savegame
- uint compressedGamedataSize;
- loadString(stream); // Marker
- loadString(stream); // Version
- loadString(stream); // Description
- Common::String gameSize = loadString(stream);
- compressedGamedataSize = atoi(gameSize.c_str());
- loadString(stream);
-
- // Return the offset of where the thumbnail starts
- return static_cast<uint>(stream.pos() + compressedGamedataSize);
-}
-
#ifndef USE_INTERNAL_PNG_DECODER
static void png_user_read_data(png_structp png_ptr, png_bytep data, png_size_t length) {
const byte **ref = (const byte **)png_get_io_ptr(png_ptr);
@@ -238,12 +187,11 @@ bool PNGLoader::doDecodeImage(const byte *fileDataPtr, uint fileSize, byte *&unc
}
bool PNGLoader::decodeImage(const byte *fileDataPtr, uint fileSize, byte *&uncompressedDataPtr, int &width, int &height, int &pitch) {
- uint pngOffset = findEmbeddedPNG(fileDataPtr, fileSize);
- return doDecodeImage(fileDataPtr + pngOffset, fileSize - pngOffset, uncompressedDataPtr, width, height, pitch);
+ return doDecodeImage(fileDataPtr, fileSize, uncompressedDataPtr, width, height, pitch);
}
-bool PNGLoader::doImageProperties(const byte *fileDataPtr, uint fileSize, int &width, int &height) {
#ifndef USE_INTERNAL_PNG_DECODER
+bool PNGLoader::doImageProperties(const byte *fileDataPtr, uint fileSize, int &width, int &height) {
// Check for valid PNG signature
if (!doIsCorrectImageFormat(fileDataPtr, fileSize))
return false;
@@ -280,17 +228,18 @@ bool PNGLoader::doImageProperties(const byte *fileDataPtr, uint fileSize, int &w
// Destroy libpng structures
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
-#else
- // We don't need to read the image properties here...
-#endif
+
return true;
}
bool PNGLoader::imageProperties(const byte *fileDataPtr, uint fileSize, int &width, int &height) {
- uint pngOffset = findEmbeddedPNG(fileDataPtr, fileSize);
- return doImageProperties(fileDataPtr + pngOffset, fileSize - pngOffset, width, height);
+ return doImageProperties(fileDataPtr, fileSize, width, height);
}
+#else
+ // We don't need to read the image properties here...
+#endif
+
} // End of namespace Sword25
diff --git a/engines/sword25/gfx/image/pngloader.h b/engines/sword25/gfx/image/pngloader.h
index e0d68ff8b9..6b5f65ff57 100644
--- a/engines/sword25/gfx/image/pngloader.h
+++ b/engines/sword25/gfx/image/pngloader.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
@@ -40,6 +37,9 @@
namespace Sword25 {
+// Define to use ScummVM's PNG decoder, instead of libpng
+#define USE_INTERNAL_PNG_DECODER
+
/**
* Class for loading PNG files, and PNG data embedded into savegames.
*
@@ -50,7 +50,9 @@ protected:
PNGLoader() {} // Protected constructor to prevent instances
static bool doDecodeImage(const byte *fileDataPtr, uint fileSize, byte *&uncompressedDataPtr, int &width, int &height, int &pitch);
+#ifndef USE_INTERNAL_PNG_DECODER
static bool doImageProperties(const byte *fileDataPtr, uint fileSize, int &width, int &height);
+#endif
public:
@@ -72,6 +74,8 @@ public:
byte *&pUncompressedData,
int &width, int &height,
int &pitch);
+
+#ifndef USE_INTERNAL_PNG_DECODER
/**
* Extract the properties of an image.
* @param[in] fileDatePtr pointer to the image data
@@ -86,6 +90,8 @@ public:
static bool imageProperties(const byte *fileDatePtr, uint fileSize,
int &width,
int &height);
+#endif
+
};
} // End of namespace Sword25
diff --git a/engines/sword25/gfx/image/renderedimage.cpp b/engines/sword25/gfx/image/renderedimage.cpp
index 806d9b27ad..23bf2623ad 100644
--- a/engines/sword25/gfx/image/renderedimage.cpp
+++ b/engines/sword25/gfx/image/renderedimage.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
@@ -36,6 +33,7 @@
// INCLUDES
// -----------------------------------------------------------------------------
+#include "common/savefile.h"
#include "sword25/package/packagemanager.h"
#include "sword25/gfx/image/pngloader.h"
#include "sword25/gfx/image/renderedimage.h"
@@ -44,10 +42,88 @@
namespace Sword25 {
+// Duplicated from kernel/persistenceservice.cpp
+static Common::String generateSavegameFilename(uint slotID) {
+ char buffer[100];
+ // NOTE: This is hardcoded to sword25
+ snprintf(buffer, 100, "%s.%.3d", "sword25", slotID);
+ return Common::String(buffer);
+}
+
// -----------------------------------------------------------------------------
// CONSTRUCTION / DESTRUCTION
// -----------------------------------------------------------------------------
+/**
+ * Load a NULL-terminated string from the given stream.
+ */
+static Common::String loadString(Common::SeekableReadStream &in, uint maxSize = 999) {
+ Common::String result;
+
+ while (!in.eos() && (result.size() < maxSize)) {
+ char ch = (char)in.readByte();
+ if (ch == '\0')
+ break;
+
+ result += ch;
+ }
+
+ return result;
+}
+
+static byte *readSavegameThumbnail(const Common::String &filename, uint &fileSize, bool &isPNG) {
+ byte *pFileData;
+ Common::SaveFileManager *sfm = g_system->getSavefileManager();
+ int slotNum = atoi(filename.c_str() + filename.size() - 3);
+ Common::InSaveFile *file = sfm->openForLoading(generateSavegameFilename(slotNum));
+
+ // Seek to the actual PNG image
+ loadString(*file); // Marker (BS25SAVEGAME)
+ loadString(*file); // Version
+ loadString(*file); // Description
+ uint32 compressedGamedataSize = atoi(loadString(*file).c_str());
+ loadString(*file); // Uncompressed game data size
+ file->skip(compressedGamedataSize); // Skip the game data and move to the thumbnail itself
+ uint32 thumbnailStart = file->pos();
+
+ fileSize = file->size() - thumbnailStart;
+
+ // Check if the thumbnail is in our own format, or a PNG file.
+ uint32 header = file->readUint32BE();
+ isPNG = (header != MKTAG('S','C','R','N'));
+ file->seek(-4, SEEK_CUR);
+
+ pFileData = new byte[fileSize];
+ file->read(pFileData, fileSize);
+ delete file;
+
+ 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),
@@ -62,22 +138,37 @@ RenderedImage::RenderedImage(const Common::String &filename, bool &result) :
// Load file
byte *pFileData;
uint fileSize;
- pFileData = pPackage->getFile(filename, &fileSize);
+
+ bool isPNG = true;
+
+ if (filename.hasPrefix("/saves")) {
+ pFileData = readSavegameThumbnail(filename, fileSize, isPNG);
+ } else {
+ pFileData = pPackage->getFile(filename, &fileSize);
+ }
+
if (!pFileData) {
error("File \"%s\" could not be loaded.", filename.c_str());
return;
}
+#ifndef USE_INTERNAL_PNG_DECODER
// Determine image properties
- int pitch;
if (!PNGLoader::imageProperties(pFileData, fileSize, _width, _height)) {
error("Could not read image properties.");
delete[] pFileData;
return;
}
+#endif
// Uncompress the image
- if (!PNGLoader::decodeImage(pFileData, fileSize, _data, _width, _height, pitch)) {
+ int pitch;
+ if (isPNG)
+ result = PNGLoader::decodeImage(pFileData, fileSize, _data, _width, _height, pitch);
+ else
+ result = decodeThumbnail(pFileData, fileSize, _data, _width, _height, pitch);
+
+ if (!result) {
error("Could not decode image.");
delete[] pFileData;
return;
@@ -88,7 +179,6 @@ RenderedImage::RenderedImage(const Common::String &filename, bool &result) :
_doCleanup = true;
- result = true;
return;
}
diff --git a/engines/sword25/gfx/image/renderedimage.h b/engines/sword25/gfx/image/renderedimage.h
index e3f23747da..f92a5b39b4 100644
--- a/engines/sword25/gfx/image/renderedimage.h
+++ b/engines/sword25/gfx/image/renderedimage.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/image/swimage.cpp b/engines/sword25/gfx/image/swimage.cpp
index 3b9b939eb3..92d47368b2 100644
--- a/engines/sword25/gfx/image/swimage.cpp
+++ b/engines/sword25/gfx/image/swimage.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
@@ -56,14 +53,16 @@ SWImage::SWImage(const Common::String &filename, bool &result) :
return;
}
+#ifndef USE_INTERNAL_PNG_DECODER
// Determine image properties
- int pitch;
if (!PNGLoader::imageProperties(pFileData, fileSize, _width, _height)) {
error("Could not read image properties.");
return;
}
+#endif
// Uncompress the image
+ int pitch;
byte *pUncompressedData;
if (!PNGLoader::decodeImage(pFileData, fileSize, pUncompressedData, _width, _height, pitch)) {
error("Could not decode image.");
diff --git a/engines/sword25/gfx/image/swimage.h b/engines/sword25/gfx/image/swimage.h
index a914c4f41f..5f348958b2 100644
--- a/engines/sword25/gfx/image/swimage.h
+++ b/engines/sword25/gfx/image/swimage.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/image/vectorimage.cpp b/engines/sword25/gfx/image/vectorimage.cpp
index 241e80bad3..9235ec2fcf 100644
--- a/engines/sword25/gfx/image/vectorimage.cpp
+++ b/engines/sword25/gfx/image/vectorimage.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/image/vectorimage.h b/engines/sword25/gfx/image/vectorimage.h
index 79a7519dda..959f251c14 100644
--- a/engines/sword25/gfx/image/vectorimage.h
+++ b/engines/sword25/gfx/image/vectorimage.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*
diff --git a/engines/sword25/gfx/image/vectorimagerenderer.cpp b/engines/sword25/gfx/image/vectorimagerenderer.cpp
index 99a47015fb..97dad3346d 100644
--- a/engines/sword25/gfx/image/vectorimagerenderer.cpp
+++ b/engines/sword25/gfx/image/vectorimagerenderer.cpp
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
/*