[Scummvm-cvs-logs] scummvm master -> 2400c77d9153e9746f6b4070154e3d571a98e11a

dreammaster dreammaster at scummvm.org
Mon May 26 23:45:47 CEST 2014


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:
2400c77d91 MADS: Better handle resource index decompression flags like original


Commit: 2400c77d9153e9746f6b4070154e3d571a98e11a
    https://github.com/scummvm/scummvm/commit/2400c77d9153e9746f6b4070154e3d571a98e11a
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2014-05-26T17:44:00-04:00

Commit Message:
MADS: Better handle resource index decompression flags like original

Changed paths:
    engines/mads/compression.cpp
    engines/mads/compression.h



diff --git a/engines/mads/compression.cpp b/engines/mads/compression.cpp
index de893e7..2284f17 100644
--- a/engines/mads/compression.cpp
+++ b/engines/mads/compression.cpp
@@ -65,24 +65,31 @@ void MadsPack::initialise(Common::SeekableReadStream *stream) {
 
 	for (int i = 0; i < _count; ++i, header += 10) {
 		// Get header data
-		_items[i].hash = READ_LE_UINT16(header);
-		_items[i].size = READ_LE_UINT32(header + 2);
-		_items[i].compressedSize = READ_LE_UINT32(header + 6);
+		_items[i]._type = (CompressionType)*header;
+		_items[i]._priority = *(header + 1);
+		_items[i]._size = READ_LE_UINT32(header + 2);
+		_items[i]._compressedSize = READ_LE_UINT32(header + 6);
 
-		byte *sourceData = new byte[_items[i].compressedSize];
-		stream->read(sourceData, _items[i].compressedSize);
+		byte *sourceData = new byte[_items[i]._compressedSize];
+		stream->read(sourceData, _items[i]._compressedSize);
 
-		if (_items[i].size == _items[i].compressedSize &&
-				!FabDecompressor::isCompressed(sourceData)) {
+		switch (_items[i]._type) {
+		case COMPRESS_NONE:
 			// Entry isn't compressed
-			_items[i].data = sourceData;
-		} else {
+			_items[i]._data = sourceData;
+			break;
+
+		case COMPRESS_FAB:
 			// Decompress the entry
-			_items[i].data = new byte[_items[i].size];
+			_items[i]._data = new byte[_items[i]._size];
 
 			FabDecompressor fab;
-			fab.decompress(sourceData, _items[i].compressedSize, _items[i].data, _items[i].size);
+			fab.decompress(sourceData, _items[i]._compressedSize, _items[i]._data, _items[i]._size);
 			delete[] sourceData;
+			break;
+
+		default:
+			error("Unknown compression type encountered");
 		}
 	}
 
@@ -92,16 +99,12 @@ void MadsPack::initialise(Common::SeekableReadStream *stream) {
 
 MadsPack::~MadsPack() {
 	for (int i = 0; i < _count; ++i)
-		delete[] _items[i].data;
+		delete[] _items[i]._data;
 	delete[] _items;
 }
 
 //--------------------------------------------------------------------------
 
-bool FabDecompressor::isCompressed(const byte *srcData) {
-	return strncmp((const char *)srcData, "FAB", 3) == 0;
-}
-
 void FabDecompressor::decompress(const byte *srcData, int srcSize, byte *destData, int destSize) {
 	byte copyLen, copyOfsShift, copyOfsMask, copyLenMask;
 	unsigned long copyOfs;
diff --git a/engines/mads/compression.h b/engines/mads/compression.h
index 43a966f..e6eca42 100644
--- a/engines/mads/compression.h
+++ b/engines/mads/compression.h
@@ -32,12 +32,15 @@
 
 namespace MADS {
 
+enum CompressionType { COMPRESS_NONE = 0, COMPRESS_FAB = 1 };
+
 struct MadsPackEntry {
 public:
-	uint16 hash;
-	uint32 size;
-	uint32 compressedSize;
-	byte *data;
+	CompressionType _type;
+	byte _priority;
+	uint32 _size;
+	uint32 _compressedSize;
+	byte *_data;
 };
 
 class MadsPack {
@@ -63,7 +66,7 @@ public:
 	}
 	Common::MemoryReadStream *getItemStream(int index) {
 		assert(index < _count);
-		return new Common::MemoryReadStream(_items[index].data, _items[index].size,
+		return new Common::MemoryReadStream(_items[index]._data, _items[index]._size,
 			DisposeAfterUse::NO);
 	}
 	int getDataOffset() const { return _dataOffset; }
@@ -79,8 +82,6 @@ private:
 	int getBit();
 public:
 	void decompress(const byte *srcData, int srcSize, byte *destData, int destSize);
-
-	static bool isCompressed(const byte *srcData);
 };
 
 } // End of namespace MADS






More information about the Scummvm-git-logs mailing list