aboutsummaryrefslogtreecommitdiff
path: root/engines/mads/sprites.cpp
diff options
context:
space:
mode:
authorPaul Gilbert2014-06-01 09:10:49 -0400
committerPaul Gilbert2014-06-01 09:10:49 -0400
commit7ab00631dd09fc9822b41b81fb53e06aeac0d5e4 (patch)
treed085c15b3c36059c0b350a6b36c6d92799305178 /engines/mads/sprites.cpp
parent01e61a2837cdf1f5acbe160ecd9f7b4410b45693 (diff)
downloadscummvm-rg350-7ab00631dd09fc9822b41b81fb53e06aeac0d5e4.tar.gz
scummvm-rg350-7ab00631dd09fc9822b41b81fb53e06aeac0d5e4.tar.bz2
scummvm-rg350-7ab00631dd09fc9822b41b81fb53e06aeac0d5e4.zip
MADS: Add enum for sprite asset loading flags
Diffstat (limited to 'engines/mads/sprites.cpp')
-rw-r--r--engines/mads/sprites.cpp26
1 files changed, 21 insertions, 5 deletions
diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp
index 4f5d50db4f..acbb22077f 100644
--- a/engines/mads/sprites.cpp
+++ b/engines/mads/sprites.cpp
@@ -36,8 +36,6 @@ enum {
kMarker = 2
};
-#define TRANSPARENT_COLOR_INDEX 0xFF
-
class DepthEntry {
public:
int depth;
@@ -61,7 +59,7 @@ MSprite::MSprite()
MSprite::MSprite(Common::SeekableReadStream *source, const Common::Array<RGB6> &palette,
const Common::Rect &bounds)
: MSurface(bounds.width(), bounds.height()),
- _offset(Common::Point(bounds.left, bounds.top)) {
+ _offset(Common::Point(bounds.left, bounds.top)), _transparencyIndex(0xFF) {
// Load the sprite data
loadSprite(source, palette);
}
@@ -123,16 +121,34 @@ void MSprite::loadSprite(Common::SeekableReadStream *source,
}
}
+ // Do a first post-sprite generation loop to find a pixel that the sprite
+ // will not use to designate as the transparency
+ bool colorUsed[PALETTE_COUNT];
+ Common::fill(&colorUsed[0], &colorUsed[PALETTE_COUNT], false);
+ for (outp = getData(); spriteSize > 0; --spriteSize, ++outp) {
+ if (*outp != transIndex)
+ colorUsed[palette[*outp]._palIndex] = true;
+ }
+
+ _transparencyIndex = PALETTE_COUNT - 1;
+ while (_transparencyIndex >= 0 && colorUsed[_transparencyIndex])
+ --_transparencyIndex;
+ assert(_transparencyIndex >= 0);
+
// Do a final iteration over the sprite to convert it's pixels to
// the final positions in the main palette
+ spriteSize = this->w * this->h;
for (outp = getData(); spriteSize > 0; --spriteSize, ++outp) {
- if (*outp != transIndex)
+ if (*outp != transIndex) {
*outp = palette[*outp]._palIndex;
+ } else {
+ *outp = _transparencyIndex;
+ }
}
}
byte MSprite::getTransparencyIndex() const {
- return TRANSPARENT_COLOR_INDEX;
+ return _transparencyIndex;
}
/*------------------------------------------------------------------------*/