From 4377a0d995cd0486c809020e11625f86aff6259d Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 30 Aug 2019 23:10:26 -0700 Subject: XEEN: Workaround black pixels when rendering transparent Shades --- engines/xeen/sprites.cpp | 30 ++++++++++++++++++++++-------- engines/xeen/sprites.h | 2 ++ 2 files changed, 24 insertions(+), 8 deletions(-) (limited to 'engines/xeen') diff --git a/engines/xeen/sprites.cpp b/engines/xeen/sprites.cpp index 76bd74285b..4ac53835d5 100644 --- a/engines/xeen/sprites.cpp +++ b/engines/xeen/sprites.cpp @@ -446,17 +446,31 @@ const uint16 DRAWER3_OFFSET[4] = { 1, 2, 4, 8 }; SpriteDrawer3::SpriteDrawer3(byte *data, size_t filesize, int index) : SpriteDrawer(data, filesize) { _offset = DRAWER3_OFFSET[index]; _mask = DRAWER3_MASK[index]; + + g_system->getPaletteManager()->grabPalette(_palette, 0, PALETTE_COUNT); + _hasPalette = false; + for (byte *pal = _palette; pal < _palette + PALETTE_SIZE && !_hasPalette; ++pal) + _hasPalette = *pal != 0; } void SpriteDrawer3::drawPixel(byte *dest, byte pixel) { - byte level = (pixel & _mask) - _offset + (*dest & 0xf); - - if (level >= 0x80) { - *dest &= 0xf0; - } else if (level <= 0xf) { - *dest = (*dest & 0xf0) | level; - } else { - *dest |= 0xf; + // WORKAROUND: This is slightly different then the original: + // 1) The original has bunches of black pixels appearing. This does index increments to avoid such pixels + // 2) It also prevents any pixels being drawn in the single initial frame until the palette is set + if (_hasPalette) { + byte level = (pixel & _mask) - _offset + (*dest & 0xf); + + if (level >= 0x80) { + *dest &= 0xf0; + } else if (level <= 0xf) { + *dest = (*dest & 0xf0) | level; + } else { + *dest |= 0xf; + } + + // + while (*dest < 0xff && !_palette[*dest * 3] && !_palette[*dest * 3 + 1] && !_palette[*dest * 3 + 2]) + ++*dest; } } diff --git a/engines/xeen/sprites.h b/engines/xeen/sprites.h index f2619c81b6..5a245885c4 100644 --- a/engines/xeen/sprites.h +++ b/engines/xeen/sprites.h @@ -224,6 +224,8 @@ public: class SpriteDrawer3 : public SpriteDrawer { private: uint16 _offset, _mask; + byte _palette[256 * 3]; + bool _hasPalette; private: /** * Output a pixel -- cgit v1.2.3