[Scummvm-cvs-logs] SF.net SVN: scummvm:[39698] scummvm/trunk/engines/sci/scicore

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Thu Mar 26 00:47:17 CET 2009


Revision: 39698
          http://scummvm.svn.sourceforge.net/scummvm/?rev=39698&view=rev
Author:   fingolfin
Date:     2009-03-25 23:47:16 +0000 (Wed, 25 Mar 2009)

Log Message:
-----------
SCI: Cleaned up the decompressor comments and code a little bit

Modified Paths:
--------------
    scummvm/trunk/engines/sci/scicore/decompressor.cpp
    scummvm/trunk/engines/sci/scicore/decompressor.h

Modified: scummvm/trunk/engines/sci/scicore/decompressor.cpp
===================================================================
--- scummvm/trunk/engines/sci/scicore/decompressor.cpp	2009-03-25 23:26:24 UTC (rev 39697)
+++ scummvm/trunk/engines/sci/scicore/decompressor.cpp	2009-03-25 23:47:16 UTC (rev 39698)
@@ -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 @@
 	}
 }
 
-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 @@
 	}
 }
 
-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 @@
 	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 @@
 					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 @@
 	*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 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 @@
 		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 @@
 	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 @@
 			do {
 				nibble = getBitsMSB(4);
 				clen += nibble;
-			}while (nibble == 0xf);
+			} while (nibble == 0xf);
 			return clen;
 		}
 	}

Modified: scummvm/trunk/engines/sci/scicore/decompressor.h
===================================================================
--- scummvm/trunk/engines/sci/scicore/decompressor.h	2009-03-25 23:26:24 UTC (rev 39697)
+++ scummvm/trunk/engines/sci/scicore/decompressor.h	2009-03-25 23:47:16 UTC (rev 39698)
@@ -48,53 +48,68 @@
 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;
 };


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list