diff options
Diffstat (limited to 'engines/gob')
-rw-r--r-- | engines/gob/inter.h | 2 | ||||
-rw-r--r-- | engines/gob/inter_v7.cpp | 52 | ||||
-rw-r--r-- | engines/gob/surface.cpp | 124 | ||||
-rw-r--r-- | engines/gob/surface.h | 32 |
4 files changed, 46 insertions, 164 deletions
diff --git a/engines/gob/inter.h b/engines/gob/inter.h index 63bf3eb1c6..2aa837e777 100644 --- a/engines/gob/inter.h +++ b/engines/gob/inter.h @@ -693,7 +693,7 @@ protected: void o7_zeroVar(); void o7_getINIValue(); void o7_setINIValue(); - void o7_loadLBMPalette(); + void o7_loadIFFPalette(); void o7_opendBase(); void o7_closedBase(); void o7_getDBString(); diff --git a/engines/gob/inter_v7.cpp b/engines/gob/inter_v7.cpp index 6cf69ed9df..1238c23e3b 100644 --- a/engines/gob/inter_v7.cpp +++ b/engines/gob/inter_v7.cpp @@ -27,6 +27,7 @@ #include "graphics/cursorman.h" #include "graphics/wincursor.h" +#include "graphics/decoders/iff.h" #include "gob/gob.h" #include "gob/global.h" @@ -72,7 +73,7 @@ void Inter_v7::setupOpcodesDraw() { OPCODEDRAW(0x95, o7_zeroVar); OPCODEDRAW(0xA1, o7_getINIValue); OPCODEDRAW(0xA2, o7_setINIValue); - OPCODEDRAW(0xA4, o7_loadLBMPalette); + OPCODEDRAW(0xA4, o7_loadIFFPalette); OPCODEDRAW(0xC4, o7_opendBase); OPCODEDRAW(0xC5, o7_closedBase); OPCODEDRAW(0xC6, o7_getDBString); @@ -523,7 +524,7 @@ void Inter_v7::o7_setINIValue() { _inis.setValue(file, section, key, value); } -void Inter_v7::o7_loadLBMPalette() { +void Inter_v7::o7_loadIFFPalette() { Common::String file = _vm->_game->_script->evalString(); if (!file.contains('.')) file += ".LBM"; @@ -534,37 +535,46 @@ void Inter_v7::o7_loadLBMPalette() { if (startIndex > stopIndex) SWAP(startIndex, stopIndex); - Common::SeekableReadStream *lbmFile = _vm->_dataIO->getFile(file); - if (!lbmFile) { - warning("o7_loadLBMPalette(): No such file \"%s\"", file.c_str()); + Common::SeekableReadStream *iffFile = _vm->_dataIO->getFile(file); + if (!iffFile) { + warning("o7_loadIFFPalette(): No such file \"%s\"", file.c_str()); return; } - ImageType type = Surface::identifyImage(*lbmFile); - if (type != kImageTypeLBM) { - warning("o7_loadLBMPalette(): \"%s\" is no LBM", file.c_str()); + ImageType type = Surface::identifyImage(*iffFile); + if (type != kImageTypeIFF) { + warning("o7_loadIFFPalette(): \"%s\" is no IFF", file.c_str()); return; } - byte palette[768]; - - LBMLoader lbm(*lbmFile); - if (!lbm.loadPalette(palette)) { - warning("o7_loadLBMPalette(): Failed reading palette from LBM \"%s\"", file.c_str()); + Graphics::IFFDecoder decoder; + decoder.loadStream(*iffFile); + if (!decoder.getPalette() || decoder.getPaletteColorCount() != 256) { + warning("o7_loadIFFPalette(): Failed reading palette from IFF \"%s\"", file.c_str()); return; } - memset(palette , 0x00, 3); - memset(palette + 765, 0xFF, 3); - for (int i = 0; i < 768; i++) - palette[i] >>= 2; - - int16 count = stopIndex - startIndex + 1; + const byte *palette = decoder.getPalette(); startIndex *= 3; - count *= 3; + stopIndex *= 3; + + byte *dst = (byte *)_vm->_draw->_vgaPalette + startIndex; + const byte *src = palette + startIndex; + for (int i = startIndex; i <= stopIndex + 2; ++i) { + *dst++ = *src++ >> 2; + } + + if (startIndex == 0) { + dst = (byte *)_vm->_draw->_vgaPalette; + dst[0] = dst[1] = dst[2] = 0x00 >> 2; + } + + if (stopIndex == 765) { + dst = (byte *)_vm->_draw->_vgaPalette + 765; + dst[0] = dst[1] = dst[2] = 0xFF >> 2; + } - memcpy((char *)_vm->_draw->_vgaPalette + startIndex, palette + startIndex, count); _vm->_video->setFullPalette(_vm->_global->_pPaletteDesc); } diff --git a/engines/gob/surface.cpp b/engines/gob/surface.cpp index afbb7c3bae..6b65eb6ab9 100644 --- a/engines/gob/surface.cpp +++ b/engines/gob/surface.cpp @@ -26,112 +26,15 @@ #include "common/stream.h" #include "common/util.h" #include "common/frac.h" +#include "common/textconsole.h" #include "graphics/primitives.h" #include "graphics/pixelformat.h" #include "graphics/surface.h" +#include "graphics/decoders/iff.h" namespace Gob { -LBMLoader::LBMLoader(Common::SeekableReadStream &stream) : _parser(&stream), - _hasHeader(false), _palette(0), _image(0) { - -} - -bool LBMLoader::loadHeader(Graphics::BMHD &header) { - if (!readHeader()) - return false; - - header = _decoder._header; - return true; -} - -bool LBMLoader::loadPalette(byte *palette) { - assert(!_palette); - assert(palette); - - _palette = palette; - - Common::Functor1Mem<Common::IFFChunk&, bool, LBMLoader> c(this, &LBMLoader::callbackPalette); - _parser.parse(c); - - if (!_palette) - return false; - - _palette = 0; - return true; -} - -bool LBMLoader::loadImage(byte *image) { - assert(!_image); - assert(image); - - if (!readHeader()) - return false; - - _image = image; - - Common::Functor1Mem<Common::IFFChunk&, bool, LBMLoader> c(this, &LBMLoader::callbackImage); - _parser.parse(c); - - if (!_image) - return false; - - _image = 0; - return true; -} - -bool LBMLoader::callbackHeader(Common::IFFChunk &chunk) { - if (chunk._type == ID_BMHD) { - if (chunk._size == sizeof(Graphics::BMHD)) { - _decoder.loadHeader(chunk._stream); - _hasHeader = true; - } - - return true; // Stop the IFF parser - } - - return false; -} - -bool LBMLoader::callbackPalette(Common::IFFChunk &chunk) { - assert(_palette); - - if (chunk._type == ID_CMAP) { - if (chunk._size == 768) { - if (chunk._stream->read(_palette, chunk._size) != chunk._size) - _palette = 0; - } else - _palette = 0; - - return true; // Stop the IFF parser - } - - return false; -} - -bool LBMLoader::callbackImage(Common::IFFChunk &chunk) { - assert(_image); - - if (chunk._type == ID_BODY) { - _decoder.loadBitmap(Graphics::ILBMDecoder::ILBM_UNPACK_PLANES, _image, chunk._stream); - return true; - } - - return false; -} - -bool LBMLoader::readHeader() { - if (_hasHeader) - return true; - - Common::Functor1Mem<Common::IFFChunk&, bool, LBMLoader> c(this, &LBMLoader::callbackHeader); - _parser.parse(c); - - return _hasHeader; -} - - static void plotPixel(int x, int y, int color, void *data) { Surface *dest = (Surface *)data; @@ -841,8 +744,8 @@ bool Surface::loadImage(Common::SeekableReadStream &stream, ImageType type) { switch (type) { case kImageTypeTGA: return loadTGA(stream); - case kImageTypeLBM: - return loadLBM(stream); + case kImageTypeIFF: + return loadIFF(stream); case kImageTypeBRC: return loadBRC(stream); case kImageTypeBMP: @@ -871,7 +774,7 @@ ImageType Surface::identifyImage(Common::SeekableReadStream &stream) { stream.seek(startPos); if (!strncmp(buffer , "FORM", 4)) - return kImageTypeLBM; + return kImageTypeIFF; if (!strncmp(buffer + 6, "JFIF", 4)) return kImageTypeJPEG; if (!strncmp(buffer , "BRC" , 3)) @@ -904,20 +807,17 @@ bool Surface::loadTGA(Common::SeekableReadStream &stream) { return false; } -bool Surface::loadLBM(Common::SeekableReadStream &stream) { +bool Surface::loadIFF(Common::SeekableReadStream &stream) { + Graphics::IFFDecoder decoder; + decoder.loadStream(stream); - LBMLoader loader(stream); - - Graphics::BMHD header; - loader.loadHeader(header); - - if (header.depth != 8) - // Only 8bpp LBMs supported for now + if (!decoder.getSurface()) return false; - resize(header.width, header.height); + resize(decoder.getSurface()->w, decoder.getSurface()->h); + memcpy(_vidMem, decoder.getSurface()->pixels, decoder.getSurface()->w * decoder.getSurface()->h); - return loader.loadImage(_vidMem); + return true; } bool Surface::loadBRC(Common::SeekableReadStream &stream) { diff --git a/engines/gob/surface.h b/engines/gob/surface.h index 8f895a7910..8a1b502a95 100644 --- a/engines/gob/surface.h +++ b/engines/gob/surface.h @@ -26,9 +26,6 @@ #include "common/scummsys.h" #include "common/ptr.h" #include "common/rational.h" -#include "common/iff_container.h" - -#include "graphics/iff.h" namespace Common { class SeekableReadStream; @@ -39,37 +36,12 @@ namespace Gob { enum ImageType { kImageTypeNone = -1, kImageTypeTGA = 0, - kImageTypeLBM, + kImageTypeIFF, kImageTypeBRC, kImageTypeBMP, kImageTypeJPEG }; -class LBMLoader { -public: - LBMLoader(Common::SeekableReadStream &stream); - - bool loadHeader (Graphics::BMHD &header); - bool loadPalette(byte *palette); - bool loadImage (byte *image); - -private: - Common::IFFParser _parser; - - bool _hasHeader; - - Graphics::ILBMDecoder _decoder; - - byte *_palette; - byte *_image; - - bool callbackHeader (Common::IFFChunk &chunk); - bool callbackPalette(Common::IFFChunk &chunk); - bool callbackImage (Common::IFFChunk &chunk); - - bool readHeader(); -}; - /** An iterator over a surface's image data, automatically handles different color depths. */ class Pixel { public: @@ -182,7 +154,7 @@ private: uint16 dWidth, uint16 dHeight, uint16 sWidth, uint16 sHeight); bool loadTGA (Common::SeekableReadStream &stream); - bool loadLBM (Common::SeekableReadStream &stream); + bool loadIFF (Common::SeekableReadStream &stream); bool loadBRC (Common::SeekableReadStream &stream); bool loadBMP (Common::SeekableReadStream &stream); bool loadJPEG(Common::SeekableReadStream &stream); |