diff options
author | Borja Lorente | 2016-06-21 19:17:38 +0200 |
---|---|---|
committer | Borja Lorente | 2016-08-14 18:31:44 +0200 |
commit | 27ecdea89169bf9fd2a1c0870a17c93592ff299e (patch) | |
tree | 5020dfe073e94c026bc607fc22d38c7aaaec63ef | |
parent | 15de1a2e604be9f6c6eb4100cf656deef1afe028 (diff) | |
download | scummvm-rg350-27ecdea89169bf9fd2a1c0870a17c93592ff299e.tar.gz scummvm-rg350-27ecdea89169bf9fd2a1c0870a17c93592ff299e.tar.bz2 scummvm-rg350-27ecdea89169bf9fd2a1c0870a17c93592ff299e.zip |
MACVENTURE: Add & test PPIC3 Huffman loading
-rw-r--r-- | engines/macventure/gui.cpp | 13 | ||||
-rw-r--r-- | engines/macventure/gui.h | 1 | ||||
-rw-r--r-- | engines/macventure/image.cpp | 71 | ||||
-rw-r--r-- | engines/macventure/image.h | 2 | ||||
-rw-r--r-- | engines/macventure/macventure.cpp | 1 |
5 files changed, 87 insertions, 1 deletions
diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 77e28bac4e..f0dd82d43e 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -92,12 +92,18 @@ void Gui::draw() { drawWindows(); _wm.draw(); + + drawTitle(); } void Gui::drawMenu() { _menu->draw(&_screen); } +void Gui::drawTitle() { + warning("drawTitle hasn't been tested yet"); +} + bool Gui::processEvent(Common::Event &event) { bool processed = false; if (event.type == Common::EVENT_LBUTTONDOWN) { @@ -494,7 +500,12 @@ void Gui::drawMainGameWindow() { 5, 5), kColorBlack); - } + } + + // Tests + ImageAsset testBg(3, _graphics); + testBg.blitInto(srf, border.leftOffset * 2, border.topOffset * 2, kBlitDirect); + ImageAsset testImg(428, _graphics); testImg.blitInto(srf, border.leftOffset * 2 + 10,border.topOffset * 2 + 10, kBlitBIC); } diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 3236d3bdb2..404c18e808 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -138,6 +138,7 @@ public: void draw(); void drawMenu(); + void drawTitle(); bool processEvent(Common::Event &event); void handleMenuAction(MenuAction action); void updateWindow(WindowReference winID, bool containerOpen); diff --git a/engines/macventure/image.cpp b/engines/macventure/image.cpp index 4a3064ded6..960c18dfc4 100644 --- a/engines/macventure/image.cpp +++ b/engines/macventure/image.cpp @@ -46,6 +46,20 @@ PPICHuff PPIC2Huff = { 0x09,0x0d,0x0b,0x0a,0x05 } }; +// Used to load the huffman table in PPIC3 decoding +byte loadBits[] = { + 0x08, 0x0f, 0x02, 0xff, 0x00, + 0x04, 0xff, 0x01, + 0x07, 0x09, 0x08, 0xff, 0x03, + 0x04, 0xff, 0x04, + 0x0a, 0x07, 0x0a, 0x0b, 0x06, 0xff, 0x05, + 0x06, 0x06, 0x0b, 0xff, 0x07, + 0x03, 0xff, 0x09, + 0x04, 0x03, 0x0e, 0xff, 0x0c, + 0x02, 0xff, 0x0d, + 0x01, 0xff, 0x0f, + 0xff }; + ImageAsset::ImageAsset(ObjID original, Container * container) { _id = (original * 2); _mask = (original * 2) + 1; @@ -125,7 +139,47 @@ void ImageAsset::decodePPIC2(Common::BitStream & stream, Common::Array<byte> &da } void ImageAsset::decodePPIC3(Common::BitStream & stream, Common::Array<byte> &data) { + // We need to load the huffman from the PPIC itself + PPICHuff huff; + uint16 v, bits; + uint16 load = 0; + while ((bits = loadBits[load++]) != 0xFF) { + v = stream.getBits(bits); + while ((bits = loadBits[load++]) != 0xFF) { + huff.symbols[loadBits[load++]] = v % bits; + v = (v / bits) | 0; + } + huff.symbols[loadBits[load++]] = v; + } + huff.symbols[0x10] = 0; + for (uint i = 0x10; i > 0; i--) + for (uint j = i; j <= 0x10; j++) + if (huff.symbols[j] >= huff.symbols[i - 1]) + huff.symbols[j]++; + + for (uint i = 0x10; i >= 0; i--) { + if (huff.symbols[i] == 0x10) { + huff.symbols[i] = 0xff; + break; + } + } + + bits = stream.getBits(2) + 1; + uint16 mask = 0; + for (uint i = 0; i < 0xf; i++) { + if (i) + while (!stream.getBit()) bits++; + huff.lens[i] = bits; + huff.masks[i] = mask; + mask += 1 << (16 - bits); + } + huff.masks[0xf] = mask; + while (mask&(1 << (16 - bits))) bits++; + huff.masks[0x10] = mask | (1 << (16 - bits)); + huff.lens[0xf] = bits; + huff.lens[0x10] = bits; + decodeHuffGraphic(huff, stream, data); } void ImageAsset::decodeHuffGraphic(const PPICHuff & huff, Common::BitStream & stream, Common::Array<byte> &data) { @@ -263,6 +317,10 @@ byte ImageAsset::walkHuff(const PPICHuff & huff, Common::BitStream & stream) { void ImageAsset::blitInto(Graphics::ManagedSurface *target, uint32 x, uint32 y, BlitMode mode) { debug("Blitting image %x ", _id); + if (mode == kBlitDirect) { + blitDirect(target, x, y, _imgData); + } + if (_container->getItemByteSize(_mask)) { // Has mask switch (mode) { case MacVenture::kBlitBIC: @@ -288,6 +346,19 @@ void ImageAsset::blitInto(Graphics::ManagedSurface *target, uint32 x, uint32 y, } } +void ImageAsset::blitDirect(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array<byte>& data) { + for (uint y = 0;y < _bitHeight; y++) { + uint bmpofs = y * _rowBytes; + byte pix = 0; + for (uint x = 0; x < _bitWidth; x++) { + pix = data[bmpofs + (x >> 3)] & (1 << (7 - (x & 7))); + + pix = pix ? kColorWhite : kColorBlack; + *((byte *)target->getBasePtr(ox + x, oy + y)) = pix; + } + } +} + void ImageAsset::blitBIC(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array<byte> &data) { for (uint y = 0;y < _bitHeight; y++) { uint bmpofs = y * _rowBytes; diff --git a/engines/macventure/image.h b/engines/macventure/image.h index f7ecab354c..21e544a76e 100644 --- a/engines/macventure/image.h +++ b/engines/macventure/image.h @@ -45,6 +45,7 @@ struct PPICHuff { }; enum BlitMode { + kBlitDirect = 0, kBlitBIC = 1, kBlitOR = 2, kBlitXOR = 3 @@ -68,6 +69,7 @@ private: void decodeHuffGraphic(const PPICHuff &huff, Common::BitStream &stream, Common::Array<byte> &data); byte walkHuff(const PPICHuff &huff, Common::BitStream &stream); + void blitDirect(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array<byte> &data); void blitBIC(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array<byte> &data); void blitOR(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array<byte> &data); void blitXOR(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array<byte> &data); diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index f277d242cf..e68f7d2b7a 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -76,6 +76,7 @@ Common::Error MacVentureEngine::run() { // Additional setup. debug("MacVentureEngine::init"); + _resourceManager = new Common::MacResManager(); if (!_resourceManager->open(getGameFileName())) error("Could not open %s as a resource fork", getGameFileName()); |