diff options
author | stevenhoefel | 2017-01-09 09:46:51 +1100 |
---|---|---|
committer | Eugene Sandulenko | 2017-01-09 00:05:06 +0100 |
commit | 41ee83e3f02144da364b98b8f5b974087e6dac89 (patch) | |
tree | 66f2dee3ea886771e4159be756ee73b3381a4ae1 /engines/director/images.cpp | |
parent | 8c3c9df3508bdb18f0b083de93f0e88983660028 (diff) | |
download | scummvm-rg350-41ee83e3f02144da364b98b8f5b974087e6dac89.tar.gz scummvm-rg350-41ee83e3f02144da364b98b8f5b974087e6dac89.tar.bz2 scummvm-rg350-41ee83e3f02144da364b98b8f5b974087e6dac89.zip |
DIRECTOR: D4 Image Decoding, Buttons, Text, Shapes.
Diffstat (limited to 'engines/director/images.cpp')
-rw-r--r-- | engines/director/images.cpp | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/engines/director/images.cpp b/engines/director/images.cpp index 0ec84af0d3..9b55402a18 100644 --- a/engines/director/images.cpp +++ b/engines/director/images.cpp @@ -201,4 +201,122 @@ bool BITDDecoder::loadStream(Common::SeekableReadStream &stream) { return true; } +/**************************** +* BITD V4+ +****************************/ + +BITDDecoderV4::BITDDecoderV4(int w, int h) { + _surface = new Graphics::Surface(); + + // We make the surface pitch a multiple of 16. + 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]; + + _palette[0] = _palette[1] = _palette[2] = 0; + _palette[255 * 3 + 0] = _palette[255 * 3 + 1] = _palette[255 * 3 + 2] = 0xff; + + _paletteColorCount = 2; +} + +BITDDecoderV4::~BITDDecoderV4() { + destroy(); +} + +void BITDDecoderV4::destroy() { + _surface = 0; + + delete[] _palette; + _palette = 0; + _paletteColorCount = 0; +} + +void BITDDecoderV4::loadPalette(Common::SeekableReadStream &stream) { + // no op +} + +bool BITDDecoderV4::loadStream(Common::SeekableReadStream &stream) { + int x = 0, y = 0; + + // If the stream has exactly the required number of bits for this image, + // we assume it is uncompressed. + if (stream.size() * 8 == _surface->pitch * _surface->h) { + debugC(3, kDebugImages, "Skipping compression"); + for (y = 0; y < _surface->h; y++) { + 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; + } + } + + return true; + } + + Common::Array<int> pixels; + pixels.reserve(4096); + + while (!stream.eos()) { + int data = stream.readByte(); + int len = data + 1; + if ((data & 0x80) != 0) { + len = ((data ^ 0xFF) & 0xff) + 2; + data = stream.readByte(); + for (int p = 0; p < len; p++) { + pixels.push_back(data); + //*((byte *)_surface->getBasePtr(x, y)) = data; + } + //data = stream.readByte(); + } else { + for (int p = 0; p < len; p++) { + data = stream.readByte(); + pixels.push_back(data); + } + } + //if (bpp == 32 && pixels.Count % (w * 3) == 0) + // source += 2; + } + + if (pixels.size() > 0) { + //this needs to be calculated a lot earlier! + int bpp = pixels.size() / (_surface->w * _surface->h); + switch (bpp) { + case 1: + for (uint pix = 0; pix < pixels.size(); pix++) { + //this calculation is wrong.. need a demo with colours. + *((byte *)_surface->getBasePtr(x, y)) = 0xff - pixels[pix]; + x++; + if (x == _surface->w) { + y++; + x = 0; + } + } + break; + /* + case 32: + SetPixel(x, y, Color.FromArgb( + pixels[((y * dxr.nodes[c].w) * 3) + x], + pixels[(((y * dxr.nodes[c].w) * 3) + (dxr.nodes[c].w)) + x], + pixels[(((y * dxr.nodes[c].w) * 3) + (2 * dxr.nodes[c].w)) + x])); + break; + case 16: + SetPixel(x, y, Color.FromArgb( + (pixels[((y * dxr.nodes[c].w) * 2) + x] & 0x7c) << 1, + (pixels[((y * dxr.nodes[c].w) * 2) + x] & 0x03) << 6 | + (pixels[((y * dxr.nodes[c].w) * 2) + (dxr.nodes[c].w) + x] & 0xe0) >> 2, + (pixels[((y * dxr.nodes[c].w) * 2) + (dxr.nodes[c].w) + x] & 0x1f) << 3)); + break; + */ + } + } + + return true; +} + } // End of namespace Director |