[Scummvm-cvs-logs] SF.net SVN: scummvm:[54338] scummvm/trunk/engines/mohawk

mthreepwood at users.sourceforge.net mthreepwood at users.sourceforge.net
Thu Nov 18 20:06:38 CET 2010


Revision: 54338
          http://scummvm.svn.sourceforge.net/scummvm/?rev=54338&view=rev
Author:   mthreepwood
Date:     2010-11-18 19:06:38 +0000 (Thu, 18 Nov 2010)

Log Message:
-----------
MOHAWK: Cleanup bitmap surface and pack/draw function handling

Modified Paths:
--------------
    scummvm/trunk/engines/mohawk/bitmap.cpp
    scummvm/trunk/engines/mohawk/bitmap.h

Modified: scummvm/trunk/engines/mohawk/bitmap.cpp
===================================================================
--- scummvm/trunk/engines/mohawk/bitmap.cpp	2010-11-18 18:17:00 UTC (rev 54337)
+++ scummvm/trunk/engines/mohawk/bitmap.cpp	2010-11-18 19:06:38 UTC (rev 54338)
@@ -36,6 +36,22 @@
 #define DRAW_COMPRESSION (_header.format & kDrawMASK)
 
 MohawkBitmap::MohawkBitmap() {
+	static const PackFunction packTable[] = {
+		{ kPackNone, "Raw", &MohawkBitmap::unpackRaw },
+		{ kPackLZ, "LZ", &MohawkBitmap::unpackLZ },
+		{ kPackRiven, "Riven", &MohawkBitmap::unpackRiven }
+	};
+
+	_packTable = packTable;
+	_packTableSize = ARRAYSIZE(packTable);
+
+	static const DrawFunction drawTable[] = {
+		{ kDrawRaw, "Raw", &MohawkBitmap::drawRaw },
+		{ kDrawRLE8, "RLE8", &MohawkBitmap::drawRLE8 }
+	};
+
+	_drawTable = drawTable;
+	_drawTableSize = ARRAYSIZE(drawTable);
 }
 
 MohawkBitmap::~MohawkBitmap() {
@@ -72,14 +88,14 @@
 		}
 	}
 
-	_surface = new Graphics::Surface();
-	_surface->create(_header.width, _header.height, getBitsPerPixel() >> 3);
+	Graphics::Surface *surface = new Graphics::Surface();
+	surface->create(_header.width, _header.height, getBitsPerPixel() >> 3);
 
 	unpackImage();
-	drawImage();
+	drawImage(surface);
 	delete _data;
 
-	return new ImageData(_surface, _header.colorTable.palette);
+	return new ImageData(surface, _header.colorTable.palette);
 }
 
 byte MohawkBitmap::getBitsPerPixel() {
@@ -101,54 +117,36 @@
 	return 0;
 }
 
-struct CompressionInfo {
-	uint16 flag;
-	const char *name;
-	void (MohawkBitmap::*func)();
-};
-
-static const CompressionInfo packTable[] = {
-	{ kPackNone, "Raw", &MohawkBitmap::unpackRaw },
-	{ kPackLZ, "LZ", &MohawkBitmap::unpackLZ },
-	{ kPackLZ1, "LZ1", &MohawkBitmap::unpackLZ1 },
-	{ kPackRiven, "Riven", &MohawkBitmap::unpackRiven }
-};
-
 const char *MohawkBitmap::getPackName() {
-	for (uint32 i = 0; i < ARRAYSIZE(packTable); i++)
-		if (PACK_COMPRESSION == packTable[i].flag)
-			return packTable[i].name;
+	for (int i = 0; i < _packTableSize; i++)
+		if (PACK_COMPRESSION == _packTable[i].flag)
+			return _packTable[i].name;
 
 	return "Unknown";
 }
 
 void MohawkBitmap::unpackImage() {
-	for (uint32 i = 0; i < ARRAYSIZE(packTable); i++)
-		if (PACK_COMPRESSION == packTable[i].flag) {
-			(this->*packTable[i].func)();
+	for (int i = 0; i < _packTableSize; i++)
+		if (PACK_COMPRESSION == _packTable[i].flag) {
+			(this->*_packTable[i].func)();
 			return;
 		}
 
 	warning("Unknown Pack Compression");
 }
 
-static const CompressionInfo drawTable[] = {
-	{ kDrawRaw, "Raw", &MohawkBitmap::drawRaw },
-	{ kDrawRLE8, "RLE8", &MohawkBitmap::drawRLE8 }
-};
-
 const char *MohawkBitmap::getDrawName() {
-	for (uint32 i = 0; i < ARRAYSIZE(drawTable); i++)
-		if (DRAW_COMPRESSION == drawTable[i].flag)
-			return drawTable[i].name;
+	for (int i = 0; i < _drawTableSize; i++)
+		if (DRAW_COMPRESSION == _drawTable[i].flag)
+			return _drawTable[i].name;
 
 	return "Unknown";
 }
 
-void MohawkBitmap::drawImage() {
-	for (uint32 i = 0; i < ARRAYSIZE(drawTable); i++)
-		if (DRAW_COMPRESSION == drawTable[i].flag) {
-			(this->*drawTable[i].func)();
+void MohawkBitmap::drawImage(Graphics::Surface *surface) {
+	for (int i = 0; i < _drawTableSize; i++)
+		if (DRAW_COMPRESSION == _drawTable[i].flag) {
+			(this->*_drawTable[i].func)(surface);
 			return;
 		}
 
@@ -265,14 +263,6 @@
 }
 
 //////////////////////////////////////////
-// LZ Unpacker
-//////////////////////////////////////////
-
-void MohawkBitmap::unpackLZ1() {
-	error("STUB: unpackLZ1()");
-}
-
-//////////////////////////////////////////
 // Riven Unpacker
 //////////////////////////////////////////
 
@@ -526,9 +516,11 @@
 // Raw Drawer
 //////////////////////////////////////////
 
-void MohawkBitmap::drawRaw() {
+void MohawkBitmap::drawRaw(Graphics::Surface *surface) {
+	assert(surface);
+
 	for (uint16 y = 0; y < _header.height; y++) {
-		_data->read((byte *)_surface->pixels + y * _header.width, _header.width);
+		_data->read((byte *)surface->pixels + y * _header.width, _header.width);
 		_data->skip(_header.bytesPerRow - _header.width);
 	}
 }
@@ -537,14 +529,16 @@
 // RLE8 Drawer
 //////////////////////////////////////////
 
-void MohawkBitmap::drawRLE8() {
+void MohawkBitmap::drawRLE8(Graphics::Surface *surface) {
 	// A very simple RLE8 scheme is used as a secondary compression on
 	// most images in non-Riven tBMP's.
 
+	assert(surface);
+
 	for (uint16 i = 0; i < _header.height; i++) {
 		uint16 rowByteCount = _data->readUint16BE();
 		int32 startPos = _data->pos();
-		byte *dst = (byte *)_surface->pixels + i * _header.width;
+		byte *dst = (byte *)surface->pixels + i * _header.width;
 		int16 remaining = _header.width;
 
 		// HACK: It seems only the bottom 9 bits are valid for images
@@ -712,20 +706,17 @@
 	if (endianStream->pos() != endianStream->size())
 		error("OldMohawkBitmap decompression failed");
 
-	_surface = new Graphics::Surface();
-	if ((_header.format & 0xf00) == kOldDrawRLE8) {
-		_surface->create(_header.width, _header.height, 1);
-		drawRLE8();
-	} else {
-		assert(uncompressedSize >= (uint32)_header.bytesPerRow * _header.height);
-		_surface->create(_header.bytesPerRow, _header.height, 1);
-		_surface->w = _header.width;
-		_data->read(_surface->pixels, _header.bytesPerRow * _header.height);
-	}
+	Graphics::Surface *surface = new Graphics::Surface();
+	surface->create(_header.width, _header.height, 1);
 
+	if ((_header.format & 0xf00) == kOldDrawRLE8)
+		drawRLE8(surface);
+	else
+		drawRaw(surface);
+
 	delete _data;
 	delete stream;
-	return new ImageData(_surface);
+	return new ImageData(surface);
 }
 
 } // End of namespace Mohawk

Modified: scummvm/trunk/engines/mohawk/bitmap.h
===================================================================
--- scummvm/trunk/engines/mohawk/bitmap.h	2010-11-18 18:17:00 UTC (rev 54337)
+++ scummvm/trunk/engines/mohawk/bitmap.h	2010-11-18 19:06:38 UTC (rev 54338)
@@ -86,16 +86,6 @@
 
 	virtual ImageData *decodeImage(Common::SeekableReadStream *stream);
 
-	// Unpack Functions
-	void unpackRaw();
-	void unpackLZ();
-	void unpackLZ1();
-	void unpackRiven();
-
-	// Draw Functions
-	void drawRaw();
-	void drawRLE8();
-
 protected:
 	BitmapHeader _header;
 	byte getBitsPerPixel();
@@ -103,14 +93,44 @@
 	// The actual LZ decoder
 	static Common::SeekableReadStream *decompressLZ(Common::SeekableReadStream *stream, uint32 uncompressedSize);
 
+	// The current data stream
 	Common::SeekableReadStream *_data;
-	Graphics::Surface *_surface;
 
+	// Draw Functions
+	void drawRaw(Graphics::Surface *surface);
+	void drawRLE8(Graphics::Surface *surface);
+
 private:
+	// Unpack Functions
+	void unpackRaw();
+	void unpackLZ();
+	void unpackRiven();
+
+	// An unpacker
+	struct PackFunction {
+		uint16 flag;
+		const char *name;
+		void (MohawkBitmap::*func)();
+	};
+
+	// A drawer
+	struct DrawFunction {
+		uint16 flag;
+		const char *name;
+		void (MohawkBitmap::*func)(Graphics::Surface *surface);
+	};
+
+	// Unpack/Draw maps
+	const PackFunction *_packTable;
+	int _packTableSize;
+	const DrawFunction *_drawTable;
+	int _drawTableSize;
+
+	// Unpack/Draw helpers
 	const char *getPackName();
 	void unpackImage();
 	const char *getDrawName();
-	void drawImage();
+	void drawImage(Graphics::Surface *surface);
 
 	// Riven Decoding
 	void handleRivenSubcommandStream(byte count, byte *&dst);


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