diff options
author | Borja Lorente | 2016-06-21 13:22:56 +0200 |
---|---|---|
committer | Borja Lorente | 2016-08-14 18:31:43 +0200 |
commit | 15de1a2e604be9f6c6eb4100cf656deef1afe028 (patch) | |
tree | 454c13c9e50296a469a3f057d3806016f074d0f2 | |
parent | 1cee6caf13fdc44cacd50c7382bb7e967589f683 (diff) | |
download | scummvm-rg350-15de1a2e604be9f6c6eb4100cf656deef1afe028.tar.gz scummvm-rg350-15de1a2e604be9f6c6eb4100cf656deef1afe028.tar.bz2 scummvm-rg350-15de1a2e604be9f6c6eb4100cf656deef1afe028.zip |
MACVENTURE: Add graphics blitting
-rw-r--r-- | engines/macventure/gui.cpp | 10 | ||||
-rw-r--r-- | engines/macventure/gui.h | 4 | ||||
-rw-r--r-- | engines/macventure/image.cpp | 154 | ||||
-rw-r--r-- | engines/macventure/image.h | 33 | ||||
-rw-r--r-- | engines/macventure/world.cpp | 5 | ||||
-rw-r--r-- | engines/macventure/world.h | 1 |
6 files changed, 149 insertions, 58 deletions
diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 725ce38268..77e28bac4e 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -177,6 +177,8 @@ void Gui::initGUI() { _menu->setCommandsCallback(menuCommandsCallback, this); _menu->calcDimensions(); + loadGraphics(); + if (!loadWindows()) error("Could not load windows"); @@ -275,6 +277,10 @@ void Gui::loadBorder(Graphics::MacWindow * target, Common::String filename, bool } } +void Gui::loadGraphics() { + _graphics = new Container("Shadowgate II/Shadow Graphic"); +} + bool Gui::loadMenus() { // We assume that, if there are static menus, we don't need dynamic ones @@ -488,7 +494,9 @@ void Gui::drawMainGameWindow() { 5, 5), kColorBlack); - } + } + ImageAsset testImg(428, _graphics); + testImg.blitInto(srf, border.leftOffset * 2 + 10,border.topOffset * 2 + 10, kBlitBIC); } void Gui::drawSelfWindow() { diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 8c964aea93..3236d3bdb2 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -29,6 +29,7 @@ #include "graphics/font.h" +#include "macventure/container.h" #include "macventure/image.h" namespace MacVenture { @@ -185,6 +186,8 @@ private: // Attributes Common::Array<Graphics::MacWindow*> _inventoryWindows; Graphics::Menu *_menu; + Container *_graphics; + private: // Methods @@ -197,6 +200,7 @@ private: // Methods bool loadWindows(); bool loadControls(); void loadBorder(Graphics::MacWindow * target, Common::String filename, bool active); + void loadGraphics(); // Drawers void drawWindows(); diff --git a/engines/macventure/image.cpp b/engines/macventure/image.cpp index c1fb7d0ef6..4a3064ded6 100644 --- a/engines/macventure/image.cpp +++ b/engines/macventure/image.cpp @@ -46,28 +46,32 @@ PPICHuff PPIC2Huff = { 0x09,0x0d,0x0b,0x0a,0x05 } }; -ImageAsset::ImageAsset(ObjID id, Container * container) { - _id = id; - _container = container; +ImageAsset::ImageAsset(ObjID original, Container * container) { + _id = (original * 2); + _mask = (original * 2) + 1; - decodePPIC(); + _container = container; + + //_imgData = nullptr; + //_maskData = nullptr; + + decodePPIC(_id, _imgData); + decodePPIC(_mask, _maskData); } ImageAsset::~ImageAsset() { - delete _surface; - delete _mask; - delete[] _data; -} + //if (_imgData) + // delete[] _imgData; -void ImageAsset::blit(Graphics::ManagedSurface * target) { - debug("Blitting image %x ", _id); + //if (_maskData) + // delete[] _maskData; } -void ImageAsset::decodePPIC() { - ObjID realID = _id; - uint32 size = _container->getItemByteSize(_id); +void ImageAsset::decodePPIC(ObjID id, Common::Array<byte> &data) { + ObjID realID = id; + uint32 size = _container->getItemByteSize(id); if (size == 2 || size == 0) { - realID = _container->getItem(_id)->readUint16BE(); + realID = _container->getItem(id)->readUint16BE(); } Common::BitStream32BEMSB stream(_container->getItem(realID)); @@ -83,46 +87,48 @@ void ImageAsset::decodePPIC() { _bitWidth = w; _bitHeight = h; - _surface = new Graphics::ManagedSurface(_rowBytes, h, Graphics::PixelFormat::createFormatCLUT8()); - _mask = new Graphics::ManagedSurface(_rowBytes, h, Graphics::PixelFormat::createFormatCLUT8()); - _data = new byte[_surface->w * _surface->h]; + for (uint i = 0; i < _rowBytes * h; i++) { + data.push_back(0); + } switch (mode) { case MacVenture::kPPIC0: - decodePPIC0(stream); + decodePPIC0(stream, data); break; case MacVenture::kPPIC1: - decodePPIC1(stream); + decodePPIC1(stream, data); break; case MacVenture::kPPIC2: - decodePPIC2(stream); + decodePPIC2(stream, data); break; case MacVenture::kPPIC3: - decodePPIC3(stream); + decodePPIC3(stream, data); break; } } -void ImageAsset::decodePPIC0(Common::BitStream & stream) { - for (uint y = 0; y < _surface->h; y++) - for (uint x = 0; x < _surface->w; x++) - *(byte*)_surface->getBasePtr(x, y) = (byte)stream.getBits(8); +void ImageAsset::decodePPIC0(Common::BitStream & stream, Common::Array<byte> &data) { + warning("Untested loading function: decode PPIC0"); + uint words = _bitWidth >> 4; + for (uint y = 0; y <_bitHeight; y++) + for (uint x = 0; x < words; x++) + data[y * words + x] = (byte)stream.getBits(8); } -void ImageAsset::decodePPIC1(Common::BitStream & stream) { - decodeHuffGraphic(PPIC1Huff, stream); +void ImageAsset::decodePPIC1(Common::BitStream & stream, Common::Array<byte> &data) { + decodeHuffGraphic(PPIC1Huff, stream, data); } -void ImageAsset::decodePPIC2(Common::BitStream & stream) { - decodeHuffGraphic(PPIC2Huff, stream); +void ImageAsset::decodePPIC2(Common::BitStream & stream, Common::Array<byte> &data) { + decodeHuffGraphic(PPIC2Huff, stream, data); } -void ImageAsset::decodePPIC3(Common::BitStream & stream) { +void ImageAsset::decodePPIC3(Common::BitStream & stream, Common::Array<byte> &data) { } -void ImageAsset::decodeHuffGraphic(const PPICHuff & huff, Common::BitStream & stream) { +void ImageAsset::decodeHuffGraphic(const PPICHuff & huff, Common::BitStream & stream, Common::Array<byte> &data) { byte flags = 0; _walkRepeat = 0; _walkLast = 0; @@ -144,10 +150,10 @@ void ImageAsset::decodeHuffGraphic(const PPICHuff & huff, Common::BitStream & st uint x = 0; for (; x < _bitWidth >> 3; x++) { byte hi = walkHuff(huff, stream) << 4; - _data[pos++] = walkHuff(huff, stream) | hi; + data[pos++] = walkHuff(huff, stream) | hi; } if (odd) { - _data[pos] = walkHuff(huff, stream) << 4; + data[pos] = walkHuff(huff, stream) << 4; } pos += blank; } @@ -176,7 +182,7 @@ void ImageAsset::decodeHuffGraphic(const PPICHuff & huff, Common::BitStream & st if (odd) v >>= 4; - _data[pos] |= v & 0xff; + data[pos] |= v & 0xff; pos += _rowBytes; } } @@ -187,16 +193,16 @@ void ImageAsset::decodeHuffGraphic(const PPICHuff & huff, Common::BitStream & st if (flags & 2) { for (uint x = 0; x < _rowBytes; x++) { - _data[pos] ^= v; - v = _data[pos]; + data[pos] ^= v; + v = data[pos]; pos++; } } else { for (uint x = 0; x < _rowBytes; x++) { - uint16 val = _data[pos] ^ v; + uint16 val = data[pos] ^ v; val ^= (val >> 4) & 0xf; - _data[pos] = val; + data[pos] = val; pos++; v = (val << 4) & 0xff; } @@ -208,8 +214,8 @@ void ImageAsset::decodeHuffGraphic(const PPICHuff & huff, Common::BitStream & st if (flags & 2) delta *= 2; pos = 0; uint q = delta; - for (uint i = 0;i < _surface->h * _rowBytes - delta;i++) { - _data[q] ^= _data[pos]; + for (uint i = 0;i < _bitHeight * _rowBytes - delta;i++) { + data[q] ^= data[pos]; q++; pos++; } @@ -255,4 +261,72 @@ byte ImageAsset::walkHuff(const PPICHuff & huff, Common::BitStream & stream) { return val; } +void ImageAsset::blitInto(Graphics::ManagedSurface *target, uint32 x, uint32 y, BlitMode mode) { + debug("Blitting image %x ", _id); + if (_container->getItemByteSize(_mask)) { // Has mask + switch (mode) { + case MacVenture::kBlitBIC: + blitBIC(target, x, y, _maskData); + break; + case MacVenture::kBlitOR: + blitOR(target, x, y, _maskData); + break; + } + } + else if (_container->getItemByteSize(_id)) { + switch (mode) { + case MacVenture::kBlitBIC: + target->fillRect(Common::Rect(x, y, x + _bitWidth, y + _bitHeight * 2), kColorWhite); + break; + case MacVenture::kBlitOR: + target->fillRect(Common::Rect(x, y, x + _bitWidth, y + _bitHeight * 2), kColorBlack); + break; + } + } + if (_container->getItemByteSize(_id) && mode > 0) { + blitXOR(target, x, y, _maskData); + } +} + +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; + byte pix = 0; + for (uint x = 0; x < _bitWidth; x++) { + pix = data[bmpofs + (x >> 3)] & (1 << (7 - (x & 7))); + + if (pix) *((byte *)target->getBasePtr(ox + x, oy + y)) = kColorWhite; + } + } +} + +void ImageAsset::blitOR(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))); + + if (pix) *((byte *)target->getBasePtr(ox + x, oy + y)) = kColorBlack; + } + } +} + +void ImageAsset::blitXOR(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))); + + if (pix) { // We need to xor + byte p = *((byte *)target->getBasePtr(ox + x, oy + y)); + if (p == kColorWhite) p = kColorBlack; + else p = kColorWhite; + *((byte *)target->getBasePtr(ox + x, oy + y)) = p; + } + } + } +} + } // End of namespace MacVenture diff --git a/engines/macventure/image.h b/engines/macventure/image.h index 847b757788..f7ecab354c 100644 --- a/engines/macventure/image.h +++ b/engines/macventure/image.h @@ -44,26 +44,37 @@ struct PPICHuff { uint8 symbols[17]; }; +enum BlitMode { + kBlitBIC = 1, + kBlitOR = 2, + kBlitXOR = 3 +}; + class ImageAsset { public: - ImageAsset(ObjID id, Container *container); + ImageAsset(ObjID original, Container *container); ~ImageAsset(); - void blit(Graphics::ManagedSurface *target); + void blitInto(Graphics::ManagedSurface *target, uint32 x, uint32 y, BlitMode mode); private: - void decodePPIC(); + void decodePPIC(ObjID id, Common::Array<byte> &data); - void decodePPIC0(Common::BitStream &stream); - void decodePPIC1(Common::BitStream &stream); - void decodePPIC2(Common::BitStream &stream); - void decodePPIC3(Common::BitStream &stream); + void decodePPIC0(Common::BitStream &stream, Common::Array<byte> &data); + void decodePPIC1(Common::BitStream &stream, Common::Array<byte> &data); + void decodePPIC2(Common::BitStream &stream, Common::Array<byte> &data); + void decodePPIC3(Common::BitStream &stream, Common::Array<byte> &data); - void decodeHuffGraphic(const PPICHuff &huff, Common::BitStream &stream); + void decodeHuffGraphic(const PPICHuff &huff, Common::BitStream &stream, Common::Array<byte> &data); byte walkHuff(const PPICHuff &huff, Common::BitStream &stream); + 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); + private: ObjID _id; + ObjID _mask; Container *_container; uint16 _walkRepeat; @@ -73,10 +84,8 @@ private: uint16 _bitWidth; uint16 _bitHeight; - byte* _data; - - Graphics::ManagedSurface *_surface; - Graphics::ManagedSurface *_mask; + Common::Array<byte> _imgData; + Common::Array<byte> _maskData; }; } // End of namespace MacVenture diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index 36e9e21158..7a93773386 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -24,14 +24,11 @@ World::World(MacVentureEngine *engine, Common::MacResManager *resMan) { calculateObjectRelations(); warning("Test functions about to happen"); - _gameGraphics = new Container("Shadowgate II/Shadow Graphic"); _gameText = new Container("Shadowgate II/Shadow Text"); ObjID tid = (ObjID)1; TextAsset test = TextAsset(tid, _gameText, _engine->isOldText(), _engine->getDecodingHuffman()); - - ImageAsset testImg(((428 * 2) + 1), _gameGraphics); - + delete saveGameRes; saveGameFile.close(); } diff --git a/engines/macventure/world.h b/engines/macventure/world.h index 8afa75c83c..f42dd3a816 100644 --- a/engines/macventure/world.h +++ b/engines/macventure/world.h @@ -125,7 +125,6 @@ private: Container *_objectConstants; Container *_gameText; - Container *_gameGraphics; Common::Array<ObjID> _relations; // Parent-child relations, stored in Williams Heap format }; |