aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorMax Horn2009-03-25 23:47:16 +0000
committerMax Horn2009-03-25 23:47:16 +0000
commitc592bf3300339a755b692906e7364bb6c9ed76f4 (patch)
tree639588294ea2a2d00cb7b73cd4b3c2fcdaa6f69c /engines
parentb4b0e35841e19dc3f472762c09d7e5598c3cbfe5 (diff)
downloadscummvm-rg350-c592bf3300339a755b692906e7364bb6c9ed76f4.tar.gz
scummvm-rg350-c592bf3300339a755b692906e7364bb6c9ed76f4.tar.bz2
scummvm-rg350-c592bf3300339a755b692906e7364bb6c9ed76f4.zip
SCI: Cleaned up the decompressor comments and code a little bit
svn-id: r39698
Diffstat (limited to 'engines')
-rw-r--r--engines/sci/scicore/decompressor.cpp49
-rw-r--r--engines/sci/scicore/decompressor.h75
2 files changed, 59 insertions, 65 deletions
diff --git a/engines/sci/scicore/decompressor.cpp b/engines/sci/scicore/decompressor.cpp
index fb98ded899..06eeb8fe89 100644
--- a/engines/sci/scicore/decompressor.cpp
+++ b/engines/sci/scicore/decompressor.cpp
@@ -25,9 +25,10 @@
// Resource library
-#include <common/util.h>
-#include <common/endian.h>
-#include <common/debug.h>
+#include "common/util.h"
+#include "common/endian.h"
+#include "common/debug.h"
+
#include "sci/scicore/decompressor.h"
#include "sci/sci.h"
@@ -62,16 +63,6 @@ void Decompressor::fetchBitsMSB() {
}
}
-bool Decompressor::getBitMSB() {
- // fetching more bits to _dwBits buffer
- if (_nBits == 0)
- fetchBitsMSB();
- bool b = _dwBits & 0x80000000;
- _dwBits <<= 1;
- _nBits--;
- return b;
-}
-
uint32 Decompressor::getBitsMSB(int n) {
// fetching more data to buffer if needed
if (_nBits < n)
@@ -94,16 +85,6 @@ void Decompressor::fetchBitsLSB() {
}
}
-bool Decompressor::getBitLSB() {
- // fetching more bits to _dwBits buffer
- if (_nBits == 0)
- fetchBitsLSB();
- bool b = _dwBits & 0x1;
- _dwBits >>= 1;
- _nBits--;
- return b;
-}
-
uint32 Decompressor::getBitsLSB(int n) {
// fetching more data to buffer if needed
if (_nBits < n)
@@ -147,7 +128,7 @@ int16 DecompressorHuffman::getc2() {
byte *node = _nodes;
int16 next;
while (node[1]) {
- if (getBitMSB()) {
+ if (getBitsMSB(1)) {
next = node[1] & 0x0F; // use lower 4 bits
if (next == 0)
return getByteMSB() | 0x100;
@@ -226,7 +207,7 @@ int DecompressorLZW::unpackLZW(Common::ReadStream *src, byte *dest, uint32 nPack
warning("unpackLZW: Trying to write beyond the end of array(len=%d, destctr=%d, tok_len=%d)",
_szUnpacked, _dwWrote, tokenlastlength);
for (int i = 0; _dwWrote < _szUnpacked; i++)
- putByte(dest [tokenlist[token] + i]);
+ putByte(dest[tokenlist[token] + i]);
} else
for (int i = 0; i < tokenlastlength; i++)
putByte(dest[tokenlist[token] + i]);
@@ -369,11 +350,9 @@ void DecompressorLZW::decodeRLE(byte **rledata, byte **pixeldata, byte *outbuffe
*pixeldata = pd;
}
-/*
- * Does the same this as above, only to determine the length of the compressed
- * source data.
- *
- * Yes, this is inefficient.
+/**
+ * Does the same this as decodeRLE, only to determine the length of the
+ * compressed source data.
*/
int DecompressorLZW::getRLEsize(byte *rledata, int dsize) {
int pos = 0;
@@ -641,7 +620,7 @@ int DecompressorDCL::huffman_lookup(int *tree) {
int bit;
while (!(tree[pos] & HUFFMAN_LEAF)) {
- bit = getBitLSB();
+ bit = getBitsLSB(1);
debugC(kDebugLevelDclInflate, "[%d]:%d->", pos, bit);
pos = bit ? tree[pos] & 0xFFF : tree[pos] >> BRANCH_SHIFT;
}
@@ -669,7 +648,7 @@ int DecompressorDCL::unpackDCL(byte* dest) {
warning("Unexpected length_param value %d (expected in [3,6])\n", length_param);
while (_dwWrote < _szUnpacked) {
- if (getBitLSB()) { // (length,distance) pair
+ if (getBitsLSB(1)) { // (length,distance) pair
value = huffman_lookup(length_tree);
if (value < 8)
@@ -739,8 +718,8 @@ int DecompressorLZS::unpackLZS() {
uint16 offs = 0, clen;
while (!isFinished()) {
- if (getBitMSB()) { // Compressed bytes follow
- if (getBitMSB()) { // Seven bit offset follows
+ if (getBitsMSB(1)) { // Compressed bytes follow
+ if (getBitsMSB(1)) { // Seven bit offset follows
offs = getBitsMSB(7);
if (!offs) // This is the end marker - a 7 bit offset of zero
break;
@@ -787,7 +766,7 @@ uint16 DecompressorLZS::getCompLen() {
do {
nibble = getBitsMSB(4);
clen += nibble;
- }while (nibble == 0xf);
+ } while (nibble == 0xf);
return clen;
}
}
diff --git a/engines/sci/scicore/decompressor.h b/engines/sci/scicore/decompressor.h
index eefd9387b9..bdbfd3c823 100644
--- a/engines/sci/scicore/decompressor.h
+++ b/engines/sci/scicore/decompressor.h
@@ -48,53 +48,68 @@ class Decompressor {
public:
Decompressor() {}
virtual ~Decompressor() {}
+
+
virtual int unpack(Common::ReadStream *src, byte *dest, uint32 nPacked, uint32 nUnpacked);
protected:
- //! Initialize decompressor
- /** @param src - source stream to read from
- @param dest - destination stream to write to
- @param nPacked - size of packed data
- @param nUnpacket - size of unpacked data
- @return (int) 0 on success, non-zero on error
- */
+ /**
+ * Initialize decompressor.
+ * @param src source stream to read from
+ * @param dest destination stream to write to
+ * @param nPacked size of packed data
+ * @param nUnpacket size of unpacked data
+ * @return 0 on success, non-zero on error
+ */
virtual void init(Common::ReadStream *src, byte *dest, uint32 nPacked, uint32 nUnpacked);
- //! get one bit from _src stream
- /** @return (bool) bit;
- */
- bool getBitMSB();
- bool getBitLSB();
- //! get a number of bits from _src stream
- /** @param n - number of bits to get
- @return (uint32) n-bits number
- */
+
+ /**
+ * Get a number of bits from _src stream, starting with the most
+ * significant unread bit of the current four byte block.
+ * @param n number of bits to get
+ * @return n-bits number
+ */
uint32 getBitsMSB(int n);
+
+ /**
+ * Get a number of bits from _src stream, starting with the least
+ * significant unread bit of the current four byte block.
+ * @param n number of bits to get
+ * @return n-bits number
+ */
uint32 getBitsLSB(int n);
- //! get one byte from _src stream
- /** @return (byte) byte
- */
+
+ /**
+ * Get one byte from _src stream.
+ * @return byte
+ */
byte getByteMSB();
byte getByteLSB();
void fetchBitsMSB();
void fetchBitsLSB();
- //! put byte to _dest stream
- /** @param b - byte to put
- */
+ /**
+ * Write one byte into _dest stream
+ * @param b byte to put
+ */
+
virtual void putByte(byte b);
- // Returns true if all expected data has been unpacked to _dest
- // and there is no more data in _src
+
+ /**
+ * Returns true if all expected data has been unpacked to _dest
+ * and there is no more data in _src.
+ */
bool isFinished() {
return (_dwWrote == _szUnpacked) && (_dwRead >= _szPacked);
}
- uint32 _dwBits; // bits buffer
- byte _nBits; // # of bits in buffer
- uint32 _szPacked;
- uint32 _szUnpacked;
- uint32 _dwRead; // # of bytes read from _src
- uint32 _dwWrote;
+ uint32 _dwBits; //!< bits buffer
+ byte _nBits; //!< number of unread bits in _dwBits
+ uint32 _szPacked; //!< size of the compressed data
+ uint32 _szUnpacked; //!< size of the decompressed data
+ uint32 _dwRead; //!< number of bytes read from _src
+ uint32 _dwWrote; //!< number of bytes written to _dest
Common::ReadStream *_src;
byte *_dest;
};