mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-14 13:50:13 +00:00
SWORD25: Merge B25SLoader into PNGLoader
svn-id: r53754
This commit is contained in:
parent
85e3ddc309
commit
1e16d576ca
@ -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<uint>(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
|
@ -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
|
@ -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() {
|
||||
|
@ -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<uint>(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
|
||||
|
@ -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,
|
||||
|
@ -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 \
|
||||
|
Loading…
Reference in New Issue
Block a user