MACVENTURE: Add graphics blitting

This commit is contained in:
Borja Lorente 2016-06-21 13:22:56 +02:00
parent 1cee6caf13
commit 15de1a2e60
6 changed files with 150 additions and 59 deletions

View file

@ -177,6 +177,8 @@ void Gui::initGUI() {
_menu->setCommandsCallback(menuCommandsCallback, this); _menu->setCommandsCallback(menuCommandsCallback, this);
_menu->calcDimensions(); _menu->calcDimensions();
loadGraphics();
if (!loadWindows()) if (!loadWindows())
error("Could not load windows"); 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() { bool Gui::loadMenus() {
// We assume that, if there are static menus, we don't need dynamic ones // We assume that, if there are static menus, we don't need dynamic ones
@ -489,6 +495,8 @@ void Gui::drawMainGameWindow() {
5), 5),
kColorBlack); kColorBlack);
} }
ImageAsset testImg(428, _graphics);
testImg.blitInto(srf, border.leftOffset * 2 + 10,border.topOffset * 2 + 10, kBlitBIC);
} }
void Gui::drawSelfWindow() { void Gui::drawSelfWindow() {

View file

@ -29,6 +29,7 @@
#include "graphics/font.h" #include "graphics/font.h"
#include "macventure/container.h"
#include "macventure/image.h" #include "macventure/image.h"
namespace MacVenture { namespace MacVenture {
@ -185,6 +186,8 @@ private: // Attributes
Common::Array<Graphics::MacWindow*> _inventoryWindows; Common::Array<Graphics::MacWindow*> _inventoryWindows;
Graphics::Menu *_menu; Graphics::Menu *_menu;
Container *_graphics;
private: // Methods private: // Methods
@ -197,6 +200,7 @@ private: // Methods
bool loadWindows(); bool loadWindows();
bool loadControls(); bool loadControls();
void loadBorder(Graphics::MacWindow * target, Common::String filename, bool active); void loadBorder(Graphics::MacWindow * target, Common::String filename, bool active);
void loadGraphics();
// Drawers // Drawers
void drawWindows(); void drawWindows();

View file

@ -46,28 +46,32 @@ PPICHuff PPIC2Huff = {
0x09,0x0d,0x0b,0x0a,0x05 } 0x09,0x0d,0x0b,0x0a,0x05 }
}; };
ImageAsset::ImageAsset(ObjID id, Container * container) { ImageAsset::ImageAsset(ObjID original, Container * container) {
_id = id; _id = (original * 2);
_mask = (original * 2) + 1;
_container = container; _container = container;
decodePPIC(); //_imgData = nullptr;
//_maskData = nullptr;
decodePPIC(_id, _imgData);
decodePPIC(_mask, _maskData);
} }
ImageAsset::~ImageAsset() { ImageAsset::~ImageAsset() {
delete _surface; //if (_imgData)
delete _mask; // delete[] _imgData;
delete[] _data;
//if (_maskData)
// delete[] _maskData;
} }
void ImageAsset::blit(Graphics::ManagedSurface * target) { void ImageAsset::decodePPIC(ObjID id, Common::Array<byte> &data) {
debug("Blitting image %x ", _id); ObjID realID = id;
} uint32 size = _container->getItemByteSize(id);
void ImageAsset::decodePPIC() {
ObjID realID = _id;
uint32 size = _container->getItemByteSize(_id);
if (size == 2 || size == 0) { if (size == 2 || size == 0) {
realID = _container->getItem(_id)->readUint16BE(); realID = _container->getItem(id)->readUint16BE();
} }
Common::BitStream32BEMSB stream(_container->getItem(realID)); Common::BitStream32BEMSB stream(_container->getItem(realID));
@ -83,46 +87,48 @@ void ImageAsset::decodePPIC() {
_bitWidth = w; _bitWidth = w;
_bitHeight = h; _bitHeight = h;
_surface = new Graphics::ManagedSurface(_rowBytes, h, Graphics::PixelFormat::createFormatCLUT8()); for (uint i = 0; i < _rowBytes * h; i++) {
_mask = new Graphics::ManagedSurface(_rowBytes, h, Graphics::PixelFormat::createFormatCLUT8()); data.push_back(0);
_data = new byte[_surface->w * _surface->h]; }
switch (mode) switch (mode)
{ {
case MacVenture::kPPIC0: case MacVenture::kPPIC0:
decodePPIC0(stream); decodePPIC0(stream, data);
break; break;
case MacVenture::kPPIC1: case MacVenture::kPPIC1:
decodePPIC1(stream); decodePPIC1(stream, data);
break; break;
case MacVenture::kPPIC2: case MacVenture::kPPIC2:
decodePPIC2(stream); decodePPIC2(stream, data);
break; break;
case MacVenture::kPPIC3: case MacVenture::kPPIC3:
decodePPIC3(stream); decodePPIC3(stream, data);
break; break;
} }
} }
void ImageAsset::decodePPIC0(Common::BitStream & stream) { void ImageAsset::decodePPIC0(Common::BitStream & stream, Common::Array<byte> &data) {
for (uint y = 0; y < _surface->h; y++) warning("Untested loading function: decode PPIC0");
for (uint x = 0; x < _surface->w; x++) uint words = _bitWidth >> 4;
*(byte*)_surface->getBasePtr(x, y) = (byte)stream.getBits(8); 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) { void ImageAsset::decodePPIC1(Common::BitStream & stream, Common::Array<byte> &data) {
decodeHuffGraphic(PPIC1Huff, stream); decodeHuffGraphic(PPIC1Huff, stream, data);
} }
void ImageAsset::decodePPIC2(Common::BitStream & stream) { void ImageAsset::decodePPIC2(Common::BitStream & stream, Common::Array<byte> &data) {
decodeHuffGraphic(PPIC2Huff, stream); 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; byte flags = 0;
_walkRepeat = 0; _walkRepeat = 0;
_walkLast = 0; _walkLast = 0;
@ -144,10 +150,10 @@ void ImageAsset::decodeHuffGraphic(const PPICHuff & huff, Common::BitStream & st
uint x = 0; uint x = 0;
for (; x < _bitWidth >> 3; x++) { for (; x < _bitWidth >> 3; x++) {
byte hi = walkHuff(huff, stream) << 4; byte hi = walkHuff(huff, stream) << 4;
_data[pos++] = walkHuff(huff, stream) | hi; data[pos++] = walkHuff(huff, stream) | hi;
} }
if (odd) { if (odd) {
_data[pos] = walkHuff(huff, stream) << 4; data[pos] = walkHuff(huff, stream) << 4;
} }
pos += blank; pos += blank;
} }
@ -176,7 +182,7 @@ void ImageAsset::decodeHuffGraphic(const PPICHuff & huff, Common::BitStream & st
if (odd) if (odd)
v >>= 4; v >>= 4;
_data[pos] |= v & 0xff; data[pos] |= v & 0xff;
pos += _rowBytes; pos += _rowBytes;
} }
} }
@ -187,16 +193,16 @@ void ImageAsset::decodeHuffGraphic(const PPICHuff & huff, Common::BitStream & st
if (flags & 2) { if (flags & 2) {
for (uint x = 0; x < _rowBytes; x++) for (uint x = 0; x < _rowBytes; x++)
{ {
_data[pos] ^= v; data[pos] ^= v;
v = _data[pos]; v = data[pos];
pos++; pos++;
} }
} }
else { else {
for (uint x = 0; x < _rowBytes; x++) { for (uint x = 0; x < _rowBytes; x++) {
uint16 val = _data[pos] ^ v; uint16 val = data[pos] ^ v;
val ^= (val >> 4) & 0xf; val ^= (val >> 4) & 0xf;
_data[pos] = val; data[pos] = val;
pos++; pos++;
v = (val << 4) & 0xff; v = (val << 4) & 0xff;
} }
@ -208,8 +214,8 @@ void ImageAsset::decodeHuffGraphic(const PPICHuff & huff, Common::BitStream & st
if (flags & 2) delta *= 2; if (flags & 2) delta *= 2;
pos = 0; pos = 0;
uint q = delta; uint q = delta;
for (uint i = 0;i < _surface->h * _rowBytes - delta;i++) { for (uint i = 0;i < _bitHeight * _rowBytes - delta;i++) {
_data[q] ^= _data[pos]; data[q] ^= data[pos];
q++; q++;
pos++; pos++;
} }
@ -255,4 +261,72 @@ byte ImageAsset::walkHuff(const PPICHuff & huff, Common::BitStream & stream) {
return val; 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 } // End of namespace MacVenture

View file

@ -44,26 +44,37 @@ struct PPICHuff {
uint8 symbols[17]; uint8 symbols[17];
}; };
enum BlitMode {
kBlitBIC = 1,
kBlitOR = 2,
kBlitXOR = 3
};
class ImageAsset { class ImageAsset {
public: public:
ImageAsset(ObjID id, Container *container); ImageAsset(ObjID original, Container *container);
~ImageAsset(); ~ImageAsset();
void blit(Graphics::ManagedSurface *target); void blitInto(Graphics::ManagedSurface *target, uint32 x, uint32 y, BlitMode mode);
private: private:
void decodePPIC(); void decodePPIC(ObjID id, Common::Array<byte> &data);
void decodePPIC0(Common::BitStream &stream); void decodePPIC0(Common::BitStream &stream, Common::Array<byte> &data);
void decodePPIC1(Common::BitStream &stream); void decodePPIC1(Common::BitStream &stream, Common::Array<byte> &data);
void decodePPIC2(Common::BitStream &stream); void decodePPIC2(Common::BitStream &stream, Common::Array<byte> &data);
void decodePPIC3(Common::BitStream &stream); 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); 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: private:
ObjID _id; ObjID _id;
ObjID _mask;
Container *_container; Container *_container;
uint16 _walkRepeat; uint16 _walkRepeat;
@ -73,10 +84,8 @@ private:
uint16 _bitWidth; uint16 _bitWidth;
uint16 _bitHeight; uint16 _bitHeight;
byte* _data; Common::Array<byte> _imgData;
Common::Array<byte> _maskData;
Graphics::ManagedSurface *_surface;
Graphics::ManagedSurface *_mask;
}; };
} // End of namespace MacVenture } // End of namespace MacVenture

View file

@ -24,14 +24,11 @@ World::World(MacVentureEngine *engine, Common::MacResManager *resMan) {
calculateObjectRelations(); calculateObjectRelations();
warning("Test functions about to happen"); warning("Test functions about to happen");
_gameGraphics = new Container("Shadowgate II/Shadow Graphic");
_gameText = new Container("Shadowgate II/Shadow Text"); _gameText = new Container("Shadowgate II/Shadow Text");
ObjID tid = (ObjID)1; ObjID tid = (ObjID)1;
TextAsset test = TextAsset(tid, _gameText, _engine->isOldText(), _engine->getDecodingHuffman()); TextAsset test = TextAsset(tid, _gameText, _engine->isOldText(), _engine->getDecodingHuffman());
ImageAsset testImg(((428 * 2) + 1), _gameGraphics);
delete saveGameRes; delete saveGameRes;
saveGameFile.close(); saveGameFile.close();
} }

View file

@ -125,7 +125,6 @@ private:
Container *_objectConstants; Container *_objectConstants;
Container *_gameText; Container *_gameText;
Container *_gameGraphics;
Common::Array<ObjID> _relations; // Parent-child relations, stored in Williams Heap format Common::Array<ObjID> _relations; // Parent-child relations, stored in Williams Heap format
}; };