diff options
author | Martin Kiewitz | 2015-07-04 03:10:26 +0200 |
---|---|---|
committer | Martin Kiewitz | 2015-07-04 03:10:26 +0200 |
commit | 614162e5fc8489324e586b57db46558b4d6c26ef (patch) | |
tree | 4354775e927d6727b42c0701d1b6f736f5ed28cf | |
parent | 4fb32647adcd8abd8098127345c38065b899aa5c (diff) | |
download | scummvm-rg350-614162e5fc8489324e586b57db46558b4d6c26ef.tar.gz scummvm-rg350-614162e5fc8489324e586b57db46558b4d6c26ef.tar.bz2 scummvm-rg350-614162e5fc8489324e586b57db46558b4d6c26ef.zip |
COMMON: PKWARE data comp. lib. mask dictionary xs
added masking of dictionary offsets when copying from dictionary
issues should now all be fixed
-rw-r--r-- | common/dcl.cpp | 56 |
1 files changed, 20 insertions, 36 deletions
diff --git a/common/dcl.cpp b/common/dcl.cpp index 703544b7d9..2588fc57fd 100644 --- a/common/dcl.cpp +++ b/common/dcl.cpp @@ -338,6 +338,7 @@ bool DecompressorDCL::unpack(SeekableReadStream *sourceStream, WriteStream *targ byte dictionary[MIDI_SETUP_BUNDLE_FILE_MAXIMUM_DICTIONARY_SIZE]; uint16 dictionaryPos = 0; uint16 dictionarySize = 0; + uint16 dictionaryMask = 0; int value; uint16 tokenOffset = 0; uint16 tokenLength = 0; @@ -369,6 +370,7 @@ bool DecompressorDCL::unpack(SeekableReadStream *sourceStream, WriteStream *targ warning("DCL-INFLATE: Error: unsupported dictionary type %02x", dictionaryType); return false; } + dictionaryMask = dictionarySize - 1; while ((!targetFixedSize) || (_bytesWritten < _targetSize)) { if (getBitsLSB(1)) { // (length,distance) pair @@ -408,47 +410,29 @@ bool DecompressorDCL::unpack(SeekableReadStream *sourceStream, WriteStream *targ return false; } - 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; + uint16 dictionaryBaseIndex = (dictionaryPos - tokenOffset) & dictionaryMask; + 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]; - if (dictionaryIndex == dictionaryPos) - dictionaryIndex = dictionaryBaseIndex; - if (dictionaryNextIndex == dictionarySize) - dictionaryNextIndex = 0; + dictionaryNextIndex = (dictionaryNextIndex + 1) & dictionaryMask; + dictionaryIndex = (dictionaryIndex + 1) & dictionaryMask; - 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; - } + if (dictionaryIndex == dictionaryPos) + dictionaryIndex = dictionaryBaseIndex; + if (dictionaryNextIndex == dictionarySize) + dictionaryNextIndex = 0; + + tokenLength--; } + dictionaryPos = dictionaryNextIndex; + debug(9, "\n"); } else { // Copy byte verbatim value = (mode == DCL_ASCII_MODE) ? huffman_lookup(ascii_tree) : getByteLSB(); |