From 1e16d576ca4798bd1fac640330c5e2faf176658a Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sun, 24 Oct 2010 01:31:30 +0000 Subject: SWORD25: Merge B25SLoader into PNGLoader svn-id: r53754 --- engines/sword25/gfx/image/b25sloader.cpp | 110 ------------------------------ engines/sword25/gfx/image/b25sloader.h | 54 --------------- engines/sword25/gfx/image/imageloader.cpp | 2 - engines/sword25/gfx/image/pngloader.cpp | 56 +++++++++++++-- engines/sword25/gfx/image/pngloader.h | 1 - engines/sword25/module.mk | 1 - 6 files changed, 52 insertions(+), 172 deletions(-) delete mode 100644 engines/sword25/gfx/image/b25sloader.cpp delete mode 100644 engines/sword25/gfx/image/b25sloader.h diff --git a/engines/sword25/gfx/image/b25sloader.cpp b/engines/sword25/gfx/image/b25sloader.cpp deleted file mode 100644 index 01bb9b39a0..0000000000 --- a/engines/sword25/gfx/image/b25sloader.cpp +++ /dev/null @@ -1,110 +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. - * - * $URL$ - * $Id$ - * - */ - -/* - * 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 "sword25/gfx/image/b25sloader.h" -#include "sword25/gfx/image/pngloader.h" - -namespace Sword25 { - -#define BS_LOG_PREFIX "B25SLOADER" - -namespace { -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; -} - -uint findEmbeddedPNG(const byte *fileDataPtr, uint fileSize) { - assert(fileSize >= 100); - if (memcmp(fileDataPtr, "BS25SAVEGAME", 12)) - return 0; - - // Read in the header - Common::MemoryReadStream stream(fileDataPtr, fileSize); - stream.seek(0, SEEK_SET); - - // Headerinformationen der Spielstandes einlesen. - 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(stream.pos() + compressedGamedataSize); -} -} - -bool B25SLoader::isCorrectImageFormat(const byte *fileDataPtr, uint fileSize) { - // PNG innerhalb des Spielstandes finden und den Methodenaufruf zu BS_PNGLoader weiterreichen. - uint pngOffset = findEmbeddedPNG(fileDataPtr, fileSize); - if (pngOffset > 0) { - return PNGLoader::doIsCorrectImageFormat(fileDataPtr + pngOffset, fileSize - pngOffset); - } - - return false; -} - -bool B25SLoader::decodeImage(const byte *fileDataPtr, uint fileSize, GraphicEngine::COLOR_FORMATS colorFormat, byte *&uncompressedDataPtr, int &width, int &height, int &pitch) { - // PNG innerhalb des Spielstandes finden und den Methodenaufruf zu BS_PNGLoader weiterreichen. - uint pngOffset = findEmbeddedPNG(fileDataPtr, fileSize); - if (pngOffset > 0) { - return PNGLoader::doDecodeImage(fileDataPtr + pngOffset, fileSize - pngOffset, colorFormat, uncompressedDataPtr, width, height, pitch); - } - - return false; -} - -bool B25SLoader::imageProperties(const byte *fileDataPtr, uint fileSize, GraphicEngine::COLOR_FORMATS &colorFormat, int &width, int &height) { - // PNG innerhalb des Spielstandes finden und den Methodenaufruf zu BS_PNGLoader weiterreichen. - uint pngOffset = findEmbeddedPNG(fileDataPtr, fileSize); - if (pngOffset > 0) { - return PNGLoader::doImageProperties(fileDataPtr + pngOffset, fileSize - pngOffset, colorFormat, width, height); - } - - return false; -} - -} // End of namespace Sword25 diff --git a/engines/sword25/gfx/image/b25sloader.h b/engines/sword25/gfx/image/b25sloader.h deleted file mode 100644 index 32cc7a9ffa..0000000000 --- a/engines/sword25/gfx/image/b25sloader.h +++ /dev/null @@ -1,54 +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. - * - * $URL$ - * $Id$ - * - */ - -/* - * 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_B25SLOADER_H -#define SWORD25_B25SLOADER_H - -#include "sword25/kernel/common.h" -#include "sword25/gfx/image/imageloader.h" - -namespace Sword25 { - -class B25SLoader : public ImageLoader { - friend class ImageLoaderManager; -protected: - virtual bool isCorrectImageFormat(const byte *fileDataPtr, uint fileSize); - virtual bool decodeImage(const byte *fileDataPtr, uint fileSize, GraphicEngine::COLOR_FORMATS colorFormat, byte *&uncompressedDataPtr, int &width, int &height, int &pitch); - virtual bool imageProperties(const byte *fileDataPtr, uint fileSize, GraphicEngine::COLOR_FORMATS &colorFormat, int &width, int &height); - -}; - -} // End of namespace Sword25 - -#endif diff --git a/engines/sword25/gfx/image/imageloader.cpp b/engines/sword25/gfx/image/imageloader.cpp index 1405a87998..850507842e 100644 --- a/engines/sword25/gfx/image/imageloader.cpp +++ b/engines/sword25/gfx/image/imageloader.cpp @@ -35,7 +35,6 @@ #include "sword25/gfx/image/imageloader.h" #include "sword25/gfx/image/pngloader.h" -#include "sword25/gfx/image/b25sloader.h" DECLARE_SINGLETON(Sword25::ImageLoaderManager) @@ -80,7 +79,6 @@ bool ImageLoaderManager::extractImageProperties(const byte *pFileData, uint file ImageLoaderManager::ImageLoaderManager() { _imageLoaderList.push_back(new PNGLoader()); - _imageLoaderList.push_back(new B25SLoader()); } ImageLoaderManager::~ImageLoaderManager() { diff --git a/engines/sword25/gfx/image/pngloader.cpp b/engines/sword25/gfx/image/pngloader.cpp index a61036311f..49b2ab3d9c 100644 --- a/engines/sword25/gfx/image/pngloader.cpp +++ b/engines/sword25/gfx/image/pngloader.cpp @@ -40,7 +40,52 @@ namespace Sword25 { #define BS_LOG_PREFIX "PNGLOADER" -PNGLoader::PNGLoader() { + +namespace { + +/** + * 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) { + assert(fileSize >= 100); + if (memcmp(fileDataPtr, "BS25SAVEGAME", 12)) + return 0; + + // Read in the header + Common::MemoryReadStream stream(fileDataPtr, fileSize); + stream.seek(0, SEEK_SET); + + // Headerinformationen der Spielstandes einlesen. + 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(stream.pos() + compressedGamedataSize); +} } static void png_user_read_data(png_structp png_ptr, png_bytep data, png_size_t length) { @@ -194,7 +239,8 @@ bool PNGLoader::doDecodeImage(const byte *fileDataPtr, uint fileSize, GraphicEn } bool PNGLoader::decodeImage(const byte *fileDataPtr, uint fileSize, GraphicEngine::COLOR_FORMATS colorFormat, byte *&uncompressedDataPtr, int &width, int &height, int &pitch) { - return doDecodeImage(fileDataPtr, fileSize, colorFormat, uncompressedDataPtr, width, height, pitch); + uint pngOffset = findEmbeddedPNG(fileDataPtr, fileSize); + return doDecodeImage(fileDataPtr + pngOffset, fileSize - pngOffset, colorFormat, uncompressedDataPtr, width, height, pitch); } bool PNGLoader::doImageProperties(const byte *fileDataPtr, uint fileSize, GraphicEngine::COLOR_FORMATS &colorFormat, int &width, int &height) { @@ -242,7 +288,8 @@ bool PNGLoader::doImageProperties(const byte *fileDataPtr, uint fileSize, Graphi } bool PNGLoader::imageProperties(const byte *fileDataPtr, uint fileSize, GraphicEngine::COLOR_FORMATS &colorFormat, int &width, int &height) { - return doImageProperties(fileDataPtr, fileSize, colorFormat, width, height); + uint pngOffset = findEmbeddedPNG(fileDataPtr, fileSize); + return doImageProperties(fileDataPtr + pngOffset, fileSize - pngOffset, colorFormat, width, height); } bool PNGLoader::doIsCorrectImageFormat(const byte *fileDataPtr, uint fileSize) { @@ -253,7 +300,8 @@ bool PNGLoader::doIsCorrectImageFormat(const byte *fileDataPtr, uint fileSize) { } bool PNGLoader::isCorrectImageFormat(const byte *fileDataPtr, uint fileSize) { - return doIsCorrectImageFormat(fileDataPtr, fileSize); + uint pngOffset = findEmbeddedPNG(fileDataPtr, fileSize); + return doIsCorrectImageFormat(fileDataPtr + pngOffset, fileSize - pngOffset); } } // End of namespace Sword25 diff --git a/engines/sword25/gfx/image/pngloader.h b/engines/sword25/gfx/image/pngloader.h index dba87a713e..aa01060463 100644 --- a/engines/sword25/gfx/image/pngloader.h +++ b/engines/sword25/gfx/image/pngloader.h @@ -60,7 +60,6 @@ public: static bool doImageProperties(const byte *fileDataPtr, uint fileSize, GraphicEngine::COLOR_FORMATS &colorFormat, int &width, int &height); protected: - PNGLoader(); bool decodeImage(const byte *pFileData, uint fileSize, GraphicEngine::COLOR_FORMATS colorFormat, byte *&pUncompressedData, diff --git a/engines/sword25/module.mk b/engines/sword25/module.mk index 63ccfc5a3c..a651170c5e 100644 --- a/engines/sword25/module.mk +++ b/engines/sword25/module.mk @@ -26,7 +26,6 @@ MODULE_OBJS := \ gfx/text.o \ gfx/timedrenderobject.o \ gfx/image/art.o \ - gfx/image/b25sloader.o \ gfx/image/imageloader.o \ gfx/image/pngloader.o \ gfx/image/renderedimage.o \ -- cgit v1.2.3