[Scummvm-cvs-logs] scummvm master -> 4fb32647adcd8abd8098127345c38065b899aa5c

m-kiewitz m_kiewitz at users.sourceforge.net
Sat Jul 4 02:53:00 CEST 2015


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:
4fb32647ad COMMON: PKWARE data comp. library fix


Commit: 4fb32647adcd8abd8098127345c38065b899aa5c
    https://github.com/scummvm/scummvm/commit/4fb32647adcd8abd8098127345c38065b899aa5c
Author: Martin Kiewitz (m_kiewitz at users.sourceforge.net)
Date: 2015-07-04T02:52:56+02:00

Commit Message:
COMMON: PKWARE data comp. library fix

add old length+offset code for now, so that the graphical issues
in SCI don't occur anymore. Will investigate more tomorrow.

Changed paths:
    common/dcl.cpp



diff --git a/common/dcl.cpp b/common/dcl.cpp
index 2d75c9b..703544b 100644
--- a/common/dcl.cpp
+++ b/common/dcl.cpp
@@ -30,7 +30,7 @@ namespace Common {
 
 class DecompressorDCL {
 public:
-	bool unpack(SeekableReadStream *sourceStream, WriteStream *targetStream, uint32 targetSize, bool targetFixedSize);
+	bool unpack(SeekableReadStream *sourceStream, WriteStream *targetStream, uint32 targetSize, bool targetFixedSize, byte *targetPtr);
 
 protected:
 	/**
@@ -334,7 +334,7 @@ int DecompressorDCL::huffman_lookup(const int *tree) {
 
 #define MIDI_SETUP_BUNDLE_FILE_MAXIMUM_DICTIONARY_SIZE 4096
 
-bool DecompressorDCL::unpack(SeekableReadStream *sourceStream, WriteStream *targetStream, uint32 targetSize, bool targetFixedSize) {
+bool DecompressorDCL::unpack(SeekableReadStream *sourceStream, WriteStream *targetStream, uint32 targetSize, bool targetFixedSize, byte *targetPtr) {
 	byte   dictionary[MIDI_SETUP_BUNDLE_FILE_MAXIMUM_DICTIONARY_SIZE];
 	uint16 dictionaryPos = 0;
 	uint16 dictionarySize = 0;
@@ -408,27 +408,47 @@ bool DecompressorDCL::unpack(SeekableReadStream *sourceStream, WriteStream *targ
 				return false;
 			}
 
-			uint16 dictionaryBaseIndex = (dictionaryPos - tokenOffset) & (dictionarySize - 1);
-			uint16 dictionaryIndex = dictionaryBaseIndex;
-			uint16 dictionaryNextIndex = dictionaryPos;
+			if (!targetPtr) {
+				// FIXME: there is some issue in this code that causes some graphics glitches in SCI
+				// will figure this out tomorrow. For now the old code is called for those cases and
+				// that makes it work.
+				uint16 dictionaryBaseIndex = (dictionaryPos - tokenOffset) & (dictionarySize - 1);
+				uint16 dictionaryIndex = dictionaryBaseIndex;
+				uint16 dictionaryNextIndex = dictionaryPos;
 
-			while (tokenLength) {
-				// Write byte from dictionary
-				putByte(dictionary[dictionaryIndex]);
-				debug(9, "\33[32;31m%02x\33[37;37m ", dictionary[dictionaryIndex]);
+				while (tokenLength) {
+					// Write byte from dictionary
+					putByte(dictionary[dictionaryIndex]);
+					debug(9, "\33[32;31m%02x\33[37;37m ", dictionary[dictionaryIndex]);
 
-				dictionary[dictionaryNextIndex] = dictionary[dictionaryIndex];
-				dictionaryNextIndex++; dictionaryIndex++;
+					dictionary[dictionaryNextIndex] = dictionary[dictionaryIndex];
+					dictionaryNextIndex++; dictionaryIndex++;
 
-				if (dictionaryIndex == dictionaryPos)
-					dictionaryIndex = dictionaryBaseIndex;
-				if (dictionaryNextIndex == dictionarySize)
-					dictionaryNextIndex = 0;
+					if (dictionaryIndex == dictionaryPos)
+						dictionaryIndex = dictionaryBaseIndex;
+					if (dictionaryNextIndex == dictionarySize)
+						dictionaryNextIndex = 0;
 
-				tokenLength--;
+					tokenLength--;
+				}
+				dictionaryPos = dictionaryNextIndex;
+				debug(9, "\n");
+			} else {
+				while (tokenLength) {
+					uint32 copy_length = (tokenLength > tokenOffset) ? tokenOffset : tokenLength;
+					assert(tokenLength >= copy_length);
+					uint32 pos = _bytesWritten - tokenOffset;
+					for (uint32 i = 0; i < copy_length; i++)
+						putByte(targetPtr[pos + i]);
+
+					for (uint32 i = 0; i < copy_length; i++)
+						debug(9, "\33[32;31m%02x\33[37;37m ", targetPtr[pos + i]);
+					debug(9, "\n");
+
+					tokenLength -= copy_length;
+					tokenOffset += copy_length;
+				}
 			}
-			dictionaryPos = dictionaryNextIndex;
-			debug(9, "\n");
 
 		} else { // Copy byte verbatim
 			value = (mode == DCL_ASCII_MODE) ? huffman_lookup(ascii_tree) : getByteLSB();
@@ -467,7 +487,7 @@ bool decompressDCL(ReadStream *src, byte *dest, uint32 packedSize, uint32 unpack
 	Common::MemoryReadStream  *sourceStream = new MemoryReadStream(sourceBufferPtr, packedSize, DisposeAfterUse::NO);
 	Common::MemoryWriteStream *targetStream = new MemoryWriteStream(dest, unpackedSize);
 
-	success = dcl.unpack(sourceStream, targetStream, unpackedSize, true);
+	success = dcl.unpack(sourceStream, targetStream, unpackedSize, true, dest);
 	delete sourceStream;
 	delete targetStream;
 	return success;
@@ -485,7 +505,7 @@ SeekableReadStream *decompressDCL(SeekableReadStream *sourceStream, uint32 packe
 
 	targetStream = new MemoryWriteStream(targetPtr, unpackedSize);
 
-	success = dcl.unpack(sourceStream, targetStream, unpackedSize, true);
+	success = dcl.unpack(sourceStream, targetStream, unpackedSize, true, targetPtr);
 	delete targetStream;
 
 	if (!success) {
@@ -503,7 +523,7 @@ SeekableReadStream *decompressDCL(SeekableReadStream *sourceStream) {
 
 	targetStream = new MemoryWriteStreamDynamic(DisposeAfterUse::NO);
 
-	if (dcl.unpack(sourceStream, targetStream, 0, false)) {
+	if (dcl.unpack(sourceStream, targetStream, 0, false, nullptr)) {
 		byte *targetPtr = targetStream->getData();
 		uint32 unpackedSize = targetStream->size();
 		delete targetStream;






More information about the Scummvm-git-logs mailing list