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

mthreepwood at users.sourceforge.net mthreepwood at users.sourceforge.net
Thu Nov 18 14:31:14 CET 2010


Revision: 54319
          http://scummvm.svn.sourceforge.net/scummvm/?rev=54319&view=rev
Author:   mthreepwood
Date:     2010-11-18 13:31:12 +0000 (Thu, 18 Nov 2010)

Log Message:
-----------
MOHAWK: Implement the old Mohawk bitmap format (thanks to fuzzie)

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

Modified: scummvm/trunk/engines/mohawk/bitmap.cpp
===================================================================
--- scummvm/trunk/engines/mohawk/bitmap.cpp	2010-11-18 13:17:25 UTC (rev 54318)
+++ scummvm/trunk/engines/mohawk/bitmap.cpp	2010-11-18 13:31:12 UTC (rev 54319)
@@ -687,19 +687,54 @@
 ImageData *OldMohawkBitmap::decodeImage(Common::SeekableReadStream *stream) {
 	Common::SeekableSubReadStreamEndian *endianStream = (Common::SeekableSubReadStreamEndian *)stream;
 
-	// The format part is just a guess at this point. Note that the width and height roles have been reversed!
-
-	_header.height = endianStream->readUint16() & 0x3FF;
-	_header.width = endianStream->readUint16() & 0x3FF;
-	_header.bytesPerRow = endianStream->readUint16() & 0x3FE;
+	// 12 bytes header for the image
 	_header.format = endianStream->readUint16();
+	_header.bytesPerRow = endianStream->readUint16();
+	_header.width = endianStream->readUint16();
+	_header.height = endianStream->readUint16();
+	uint16 unknown0 = endianStream->readUint16(); // TODO
+	uint16 unknown1 = endianStream->readUint16(); // TODO
 
-	debug(2, "Decoding Old Mohawk Bitmap (%dx%d, %04x Format)", _header.width, _header.height, _header.format);
+	debug(2, "Decoding Old Mohawk Bitmap (%dx%d, %d bytesPerRow, %04x Format)", _header.width, _header.height, _header.bytesPerRow, _header.format);
+	debug(2, "Unknowns %04x, %04x", unknown0, unknown1); // TODO
 
-	warning("Unhandled old Mohawk Bitmap decoding");
+	if ((_header.format & 0xf0) != kOldPackLZ)
+		error("tried to decode non-LZ encoded OldMohawkBitmap");
 
+	// 12 bytes header for the compressed data
+	uint32 uncompressedSize = endianStream->readUint32();
+	uint32 compressedSize = endianStream->readUint32();
+	uint16 posBits = endianStream->readUint16();
+	uint16 lengthBits = endianStream->readUint16();
+
+	if (compressedSize != (uint32)endianStream->size() - 24)
+		error("More bytes (%d) remaining in stream than header says there should be (%d)", endianStream->size() - 24, compressedSize);
+
+	// These two errors are really just sanity checks and should never go off
+	if (posBits != POS_BITS)
+		error("Position bits modified to %d", posBits);
+	if (lengthBits != LEN_BITS)
+		error("Length bits modified to %d", lengthBits);
+
+	_data = decompressLZ(stream, uncompressedSize);
+
+	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);
+	}
+
+	delete _data;
 	delete stream;
-	return new ImageData(NULL, NULL);
+	return new ImageData(_surface);
 }
 
 } // End of namespace Mohawk

Modified: scummvm/trunk/engines/mohawk/bitmap.h
===================================================================
--- scummvm/trunk/engines/mohawk/bitmap.h	2010-11-18 13:17:25 UTC (rev 54318)
+++ scummvm/trunk/engines/mohawk/bitmap.h	2010-11-18 13:31:12 UTC (rev 54319)
@@ -60,6 +60,11 @@
 	kFlag24_MAC = 0x1000 // 24 bit pixel data has been converted to MAC 32 bit format
 };
 
+enum OldBitmapFormat {
+	kOldPackLZ = 0x0020,
+	kOldDrawRLE8 = 0x0100
+};
+
 struct BitmapHeader {
 	uint16 width;
 	uint16 height;
@@ -99,10 +104,10 @@
 	// The actual LZ decoder
 	static Common::SeekableReadStream *decompressLZ(Common::SeekableReadStream *stream, uint32 uncompressedSize);
 
-private:
 	Common::SeekableReadStream *_data;
 	Graphics::Surface *_surface;
 
+private:
 	const char *getPackName();
 	void unpackImage();
 	const char *getDrawName();

Modified: scummvm/trunk/engines/mohawk/graphics.cpp
===================================================================
--- scummvm/trunk/engines/mohawk/graphics.cpp	2010-11-18 13:17:25 UTC (rev 54318)
+++ scummvm/trunk/engines/mohawk/graphics.cpp	2010-11-18 13:31:12 UTC (rev 54319)
@@ -759,26 +759,26 @@
 }
 
 void LBGraphics::copyImageToScreen(uint16 image, uint16 left, uint16 right) {
-	if (_vm->getGameType() == GType_LIVINGBOOKSV1) {
-		// Drawing images in the old format isn't supported (yet)
-		ImageData *imageData = _bmpDecoder->decodeImage(_vm->wrapStreamEndian(ID_BMAP, image));
-		delete imageData;
-	} else {
-		ImageData *imageData = _bmpDecoder->decodeImage(_vm->getRawData(ID_TBMP, image));
-		imageData->_palette = _palette;
-		Graphics::Surface *surface = imageData->getSurface();
-		imageData->_palette = NULL; // Unset the palette so it doesn't get deleted
-		delete imageData;
+	ImageData *imageData;
 
-		uint16 width = MIN<int>(surface->w, 640);
-		uint16 height = MIN<int>(surface->h, 480);
-		_vm->_system->copyRectToScreen((byte *)surface->pixels, surface->pitch, left, right, width, height);
-		surface->free();
-		delete surface;
+	if (_vm->getGameType() == GType_LIVINGBOOKSV1)
+		imageData = _bmpDecoder->decodeImage(_vm->wrapStreamEndian(ID_BMAP, image));
+	else
+		imageData = _bmpDecoder->decodeImage(_vm->getRawData(ID_TBMP, image));
 
-		// FIXME: Remove this and update only at certain points
-		_vm->_system->updateScreen();
-	}
+	imageData->_palette = _palette;
+	Graphics::Surface *surface = imageData->getSurface();
+	imageData->_palette = NULL; // Unset the palette so it doesn't get deleted
+	delete imageData;
+
+	uint16 width = MIN<int>(surface->w, _vm->_system->getWidth());
+	uint16 height = MIN<int>(surface->h, _vm->_system->getHeight());
+	_vm->_system->copyRectToScreen((byte *)surface->pixels, surface->pitch, left, right, width, height);
+	surface->free();
+	delete surface;
+
+	// FIXME: Remove this and update only at certain points
+	_vm->_system->updateScreen();
 }
 
 void LBGraphics::setPalette(uint16 id) {


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