From 866f0a62572c47b223efbf344602eea77797fd1b Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Thu, 25 Aug 2016 02:59:23 +0200 Subject: DIRECTOR: Clean up padding in image decoding --- engines/director/frame.cpp | 19 +++++++------------ engines/director/images.cpp | 13 ++++++++++--- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/engines/director/frame.cpp b/engines/director/frame.cpp index 078f4eba60..451a406746 100644 --- a/engines/director/frame.cpp +++ b/engines/director/frame.cpp @@ -571,18 +571,13 @@ Image::ImageDecoder *Frame::getImageFrom(uint16 spriteId) { if (!c) debugC(4, kDebugImages, "%d, %d, %d", imgId, w, h); - if (true || bc->flags & 0x20) { - int w1 = w + 16 - w % 16; - - if (pic->size() * 8 == w1 * h) { - debugC(3, kDebugImages, "Disabling compression for %d: %d x %d", imgId, w1, h); - img = new BITDDecoder(w1, h, false); - } else if (w % 16 <= 8) { - // FIXME: This shouldn't actually increase the width of the surface, probably, but only affect the decoder - img = new BITDDecoder(w + 8, h, true); - } else { - img = new BITDDecoder(w, h, true); - } + int w1 = w; + if (w % 16) + w1 += 16 - w % 16; + + if (pic->size() * 8 == w1 * h) { + debugC(3, kDebugImages, "Disabling compression for %d: %d x %d", imgId, w1, h); + img = new BITDDecoder(w, h, false); } else { img = new BITDDecoder(w, h, true); } diff --git a/engines/director/images.cpp b/engines/director/images.cpp index cd4487dd74..af35224067 100644 --- a/engines/director/images.cpp +++ b/engines/director/images.cpp @@ -106,7 +106,14 @@ bool DIBDecoder::loadStream(Common::SeekableReadStream &stream) { BITDDecoder::BITDDecoder(int w, int h, bool comp) { _surface = new Graphics::Surface(); - _surface->create(w, h, Graphics::PixelFormat::createFormatCLUT8()); + + int pitch = w; + if (w % 16) + pitch += 16 - (w % 16); + + // HACK: Create a padded surface by adjusting w after create() + _surface->create(pitch, h, Graphics::PixelFormat::createFormatCLUT8()); + _surface->w = w; _palette = new byte[256 * 3]; @@ -140,7 +147,7 @@ bool BITDDecoder::loadStream(Common::SeekableReadStream &stream) { if (!_comp) { debugC(3, kDebugImages, "Skipping compression"); for (y = 0; y < _surface->h; y++) { - for (x = 0; x < _surface->w;) { + for (x = 0; x < _surface->pitch; ) { byte color = stream.readByte(); for (int c = 0; c < 8; c++) *((byte *)_surface->getBasePtr(x++, y)) = (color & (1 << (7 - c))) ? 0 : 0xff; @@ -180,7 +187,7 @@ bool BITDDecoder::loadStream(Common::SeekableReadStream &stream) { for (int c = 0; c < 8; c++) { *((byte *)_surface->getBasePtr(x, y)) = (color & (1 << (7 - c))) ? 0 : 0xff; x++; - if (x == _surface->w) { + if (x == _surface->pitch) { y++; x = 0; break; -- cgit v1.2.3