aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2014-03-15 11:12:31 -0400
committerPaul Gilbert2014-03-15 11:12:31 -0400
commitd2bbdd255a43915267bac8dce6998c8f843979da (patch)
treeedb28bd2c87a1ad2daa79d9286627e8fc8acea56
parentc9661ca88cbe3554a455c320fe7bcdcb203823a5 (diff)
downloadscummvm-rg350-d2bbdd255a43915267bac8dce6998c8f843979da.tar.gz
scummvm-rg350-d2bbdd255a43915267bac8dce6998c8f843979da.tar.bz2
scummvm-rg350-d2bbdd255a43915267bac8dce6998c8f843979da.zip
MADS: Implement palette shifting for loaded sprites
-rw-r--r--engines/mads/assets.cpp24
-rw-r--r--engines/mads/palette.cpp15
-rw-r--r--engines/mads/palette.h8
-rw-r--r--engines/mads/sprites.cpp25
-rw-r--r--engines/mads/sprites.h6
5 files changed, 36 insertions, 42 deletions
diff --git a/engines/mads/assets.cpp b/engines/mads/assets.cpp
index 1c958adfce..136a3fffd6 100644
--- a/engines/mads/assets.cpp
+++ b/engines/mads/assets.cpp
@@ -73,10 +73,20 @@ void SpriteAsset::load(Common::SeekableReadStream *stream, int flags) {
delete spriteStream;
// Get the palette data
- spriteStream = sprite.getItemStream(2);
- _vm->_palette->decodePalette(spriteStream, flags);
+ Common::SeekableReadStream *palStream = sprite.getItemStream(2);
+ Common::Array<RGB6> palette;
- delete spriteStream;
+ int numColors = palStream->readUint16LE();
+ assert(numColors <= 252);
+
+ // Load in the palette
+ palette.resize(numColors);
+ for (int i = 0; i < numColors; ++i)
+ palette[i].load(palStream);
+
+ // Process the palette data
+ _vm->_palette->_paletteUsage.process(palette, flags);
+ delete palStream;
spriteStream = sprite.getItemStream(1);
Common::SeekableReadStream *spriteDataStream = sprite.getItemStream(3);
@@ -103,9 +113,7 @@ void SpriteAsset::load(Common::SeekableReadStream *stream, int flags) {
if (_mode == 0) {
// Create a frame and decompress the raw pixel data
uint32 currPos = (uint32)spriteDataStream->pos();
- frame._frame = new MSprite(spriteDataStream,
- Common::Point(frame._bounds.left, frame._bounds.top),
- frame._bounds.width(), frame._bounds.height(), false);
+ frame._frame = new MSprite(spriteDataStream, palette, frame._bounds);
assert((uint32)spriteDataStream->pos() == (currPos + frameSize));
}
@@ -130,9 +138,7 @@ void SpriteAsset::load(Common::SeekableReadStream *stream, int flags) {
// Load the frames
Common::MemoryReadStream *rs = new Common::MemoryReadStream(destData, frameSizes[curFrame]);
- _frames[curFrame]._frame = new MSprite(rs,
- Common::Point(_frames[curFrame]._bounds.left, _frames[curFrame]._bounds.top),
- _frames[curFrame]._bounds.width(), _frames[curFrame]._bounds.height(), false);
+ _frames[curFrame]._frame = new MSprite(rs, palette, _frames[curFrame]._bounds);
delete rs;
delete[] srcData;
diff --git a/engines/mads/palette.cpp b/engines/mads/palette.cpp
index 9f6e3c77ae..8f803d109f 100644
--- a/engines/mads/palette.cpp
+++ b/engines/mads/palette.cpp
@@ -497,21 +497,6 @@ void Palette::processLists(int count, byte *pal1, byte *pal2) {
} while (continueFlag);
}
-
-void Palette::decodePalette(Common::SeekableReadStream *palStream, uint flags) {
- int numColors = palStream->readUint16LE();
- assert(numColors <= 252);
-
- // Load in the palette
- Common::Array<RGB6> palette;
- palette.resize(numColors);
- for (int i = 0; i < numColors; ++i)
- palette[i].load(palStream);
-
- // Process the palette data
- _paletteUsage.process(palette, flags);
-}
-
void Palette::setSystemPalette() {
byte palData[4 * 3];
palData[0 * 3] = palData[0 * 3 + 1] = palData[0 * 3 + 2] = 0;
diff --git a/engines/mads/palette.h b/engines/mads/palette.h
index 1a540755d7..5a563a5aa5 100644
--- a/engines/mads/palette.h
+++ b/engines/mads/palette.h
@@ -32,8 +32,7 @@ class MADSEngine;
#define PALETTE_USAGE_COUNT 4
-//#define VGA_COLOR_TRANS(x) (((((int)(x)) + 1) << 2) - 1)
-#define VGA_COLOR_TRANS(x) (x)
+#define VGA_COLOR_TRANS(x) (((((int)(x)) + 1) << 2) - 1)
struct RGB4 {
byte r;
@@ -188,11 +187,6 @@ public:
uint8 palIndexFromRgb(byte r, byte g, byte b, byte *paletteData = nullptr);
/**
- * Decodes a palette and loads it into the main palette
- */
- void decodePalette(Common::SeekableReadStream *palStream, uint flags);
-
- /**
* Sets a small set of system/core colors needed by the game
*/
void setSystemPalette();
diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp
index 78743e6a87..1b65442b4c 100644
--- a/engines/mads/sprites.cpp
+++ b/engines/mads/sprites.cpp
@@ -58,25 +58,27 @@ MSprite::MSprite(): MSurface() {
_encoding = 0;
}
-MSprite::MSprite(Common::SeekableReadStream *source, const Common::Point &offset,
- int widthVal, int heightVal, bool decodeRle, uint8 encodingVal)
- : MSurface(widthVal, heightVal),
- _encoding(encodingVal), _offset(offset) {
-
+MSprite::MSprite(Common::SeekableReadStream *source, const Common::Array<RGB6> &palette,
+ const Common::Rect &bounds):
+ MSurface(bounds.width(), bounds.height()),
+ _encoding(0), _offset(Common::Point(bounds.left, bounds.top)) {
// Load the sprite data
- loadSprite(source);
+ loadSprite(source, palette);
}
MSprite::~MSprite() {
}
-void MSprite::loadSprite(Common::SeekableReadStream *source) {
+void MSprite::loadSprite(Common::SeekableReadStream *source,
+ const Common::Array<RGB6> &palette) {
byte *outp, *lineStart;
bool newLine = false;
outp = getData();
lineStart = getData();
- Common::fill(outp, outp + this->w * this->h, getTransparencyIndex());
+ int spriteSize = this->w * this->h;
+ byte transIndex = getTransparencyIndex();
+ Common::fill(outp, outp + spriteSize, transIndex);
for (;;) {
byte cmd1, cmd2, count, pixel;
@@ -120,6 +122,13 @@ void MSprite::loadSprite(Common::SeekableReadStream *source) {
}
}
}
+
+ // Do a final iteration over the sprite to convert it's pixels to
+ // the final positions in the main palette
+ for (outp = getData(); spriteSize > 0; --spriteSize, ++outp) {
+ if (*outp != transIndex)
+ *outp = palette[*outp]._palIndex;
+ }
}
byte MSprite::getTransparencyIndex() const {
diff --git a/engines/mads/sprites.h b/engines/mads/sprites.h
index bf19be1afe..e0e91dc974 100644
--- a/engines/mads/sprites.h
+++ b/engines/mads/sprites.h
@@ -103,11 +103,11 @@ struct SpriteFrameHeader {
class MSprite: public MSurface {
private:
- void loadSprite(Common::SeekableReadStream *source);
+ void loadSprite(Common::SeekableReadStream *source, const Common::Array<RGB6> &palette);
public:
MSprite();
- MSprite(Common::SeekableReadStream *source, const Common::Point &offset,
- int widthVal, int heightVal, bool decodeRle = true, uint8 encodingVal = 0);
+ MSprite(Common::SeekableReadStream *source, const Common::Array<RGB6> &palette,
+ const Common::Rect &bounds);
virtual ~MSprite();
Common::Point _offset;