aboutsummaryrefslogtreecommitdiff
path: root/engines/sherlock/sprite.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/sherlock/sprite.cpp')
-rw-r--r--engines/sherlock/sprite.cpp47
1 files changed, 26 insertions, 21 deletions
diff --git a/engines/sherlock/sprite.cpp b/engines/sherlock/sprite.cpp
index f686f0b27e..ee7c8e5019 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,