Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
SHERLOCK: Fix loading of sprite for startup animation
  • Loading branch information
dreammaster committed Mar 16, 2015
1 parent 6cfb716 commit 02657f5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 24 deletions.
2 changes: 1 addition & 1 deletion engines/sherlock/animation.cpp
Expand Up @@ -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

Expand Down
47 changes: 26 additions & 21 deletions engines/sherlock/sprite.cpp
Expand Up @@ -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() {
Expand All @@ -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;
}

Expand All @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions engines/sherlock/sprite.h
Expand Up @@ -30,6 +30,8 @@

namespace Sherlock {

enum { RLE_ENCODED = 0x0100 };

struct SpriteFrame {
uint32 _size;
uint16 _width, _height;
Expand All @@ -41,10 +43,10 @@ struct SpriteFrame {

class Sprite: public Common::Array<SpriteFrame> {
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();
};

Expand Down

0 comments on commit 02657f5

Please sign in to comment.