From 02657f5a91bba15c7d494f71d0c975ece7178861 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Mon, 16 Mar 2015 00:02:45 -0400 Subject: [PATCH] SHERLOCK: Fix loading of sprite for startup animation --- engines/sherlock/animation.cpp | 2 +- engines/sherlock/sprite.cpp | 47 +++++++++++++++++++--------------- engines/sherlock/sprite.h | 6 +++-- 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/engines/sherlock/animation.cpp b/engines/sherlock/animation.cpp index 3da0201a6170..4111f6f88f7c 100644 --- a/engines/sherlock/animation.cpp +++ b/engines/sherlock/animation.cpp @@ -91,7 +91,7 @@ void Animation::playPrologue(const Common::String &filename, int minDelay, int f // Load initial image Common::String vdaName = baseName + ".vda"; Common::SeekableReadStream *vdaStream = _vm->_res->load(vdaName); - Sprite sprite(*vdaStream); + Sprite sprite(*vdaStream, true); // TODO diff --git a/engines/sherlock/sprite.cpp b/engines/sherlock/sprite.cpp index f686f0b27e03..ee7c8e501963 100644 --- a/engines/sherlock/sprite.cpp +++ b/engines/sherlock/sprite.cpp @@ -25,8 +25,8 @@ namespace Sherlock { -Sprite::Sprite(Common::SeekableReadStream &stream) { - load(stream); +Sprite::Sprite(Common::SeekableReadStream &stream, bool skipPal) { + load(stream, skipPal); } Sprite::~Sprite() { @@ -37,22 +37,26 @@ Sprite::~Sprite() { /** * Load the data of the sprite */ -void Sprite::load(Common::SeekableReadStream &stream) { - while (!stream.eos()) { +void Sprite::load(Common::SeekableReadStream &stream, bool skipPal) { + while (stream.pos() < stream.size()) { SpriteFrame frame; - frame._width = stream.readUint16LE() + 1; frame._height = stream.readUint16LE() + 1; frame._flags = stream.readUint16LE(); stream.readUint16LE(); + if (skipPal) + frame._flags = 0; + if (frame._flags & 0xFF) { + // Nibble packed frame data frame._size = (frame._width * frame._height) / 2; - } else if (frame._flags & 0x0100) { + } else if (frame._flags & RLE_ENCODED) { // this size includes the header size, which we subtract frame._size = stream.readUint16LE() - 11; frame._rleMarker = stream.readByte(); } else { + // Uncompressed data frame._size = frame._width * frame._height; } @@ -74,24 +78,25 @@ void Sprite::decompressFrame(SpriteFrame &frame, const byte *src) { if (frame._flags & 0xFF) { debug("TODO: Sprite::decompressFrame() 4-bits/pixel\n"); - } else if (frame._flags & 0x0100) { + } else if (frame._flags & RLE_ENCODED) { + // RLE encoded byte *dst = (byte *)frame._frame.getPixels(); - for (uint16 h = 0; h < frame._height; ++h) { - int16 w = frame._width; - while (w > 0) { - if (*src == frame._rleMarker) { - byte rleColor = src[1]; - byte rleCount = src[2]; - src += 3; - w -= rleCount; - while (rleCount--) - *dst++ = rleColor; - } else { - *dst++ = *src++; - w--; - } + + int size = frame._width * frame._height; + while (size > 0) { + if (*src == frame._rleMarker) { + byte rleColor = src[1]; + byte rleCount = src[2]; + src += 3; + size -= rleCount; + while (rleCount--) + *dst++ = rleColor; + } else { + *dst++ = *src++; + --size; } } + assert(size == 0); } else { // Uncompressed frame Common::copy(src, src + frame._width * frame._height, diff --git a/engines/sherlock/sprite.h b/engines/sherlock/sprite.h index 1f81cf807170..17566c81bdb7 100644 --- a/engines/sherlock/sprite.h +++ b/engines/sherlock/sprite.h @@ -30,6 +30,8 @@ namespace Sherlock { +enum { RLE_ENCODED = 0x0100 }; + struct SpriteFrame { uint32 _size; uint16 _width, _height; @@ -41,10 +43,10 @@ struct SpriteFrame { class Sprite: public Common::Array { private: - void load(Common::SeekableReadStream &stream); + void load(Common::SeekableReadStream &stream, bool skipPal); void decompressFrame(SpriteFrame &frame, const byte *src); public: - Sprite(Common::SeekableReadStream &stream); + Sprite(Common::SeekableReadStream &stream, bool skipPal = false); ~Sprite(); };