DIRECTOR: Clean up padding in image decoding

This commit is contained in:
Willem Jan Palenstijn 2016-08-25 02:59:23 +02:00
parent 6890948f74
commit 866f0a6257
2 changed files with 16 additions and 14 deletions

View File

@ -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;
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(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);
}
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);
}

View File

@ -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;