diff options
author | Johannes Schickel | 2013-01-06 11:20:52 -0800 |
---|---|---|
committer | Johannes Schickel | 2013-01-06 11:20:52 -0800 |
commit | 988596b347c7508b83f30e336add33047b49dd5f (patch) | |
tree | 604678b7d9476dc1755f5ef5ff4668b7aefd3a69 /engines/parallaction | |
parent | 3e025a8c55fce06ab4dd5a615e46fa6a9b9a6fb3 (diff) | |
parent | befa207bfa3709c7292252654a5bb9384d950a02 (diff) | |
download | scummvm-rg350-988596b347c7508b83f30e336add33047b49dd5f.tar.gz scummvm-rg350-988596b347c7508b83f30e336add33047b49dd5f.tar.bz2 scummvm-rg350-988596b347c7508b83f30e336add33047b49dd5f.zip |
Merge pull request #299 from tomaz82/IFFDecoder
New IFFDecoder
Diffstat (limited to 'engines/parallaction')
-rw-r--r-- | engines/parallaction/disk.cpp | 145 | ||||
-rw-r--r-- | engines/parallaction/disk.h | 33 | ||||
-rw-r--r-- | engines/parallaction/disk_br.cpp | 48 | ||||
-rw-r--r-- | engines/parallaction/disk_ns.cpp | 57 | ||||
-rw-r--r-- | engines/parallaction/module.mk | 1 |
5 files changed, 63 insertions, 221 deletions
diff --git a/engines/parallaction/disk.cpp b/engines/parallaction/disk.cpp deleted file mode 100644 index f20e05771a..0000000000 --- a/engines/parallaction/disk.cpp +++ /dev/null @@ -1,145 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#include "common/iff_container.h" -#include "common/textconsole.h" - -#include "parallaction/disk.h" -#include "parallaction/graphics.h" - -namespace Parallaction { - -void ILBMLoader::setupBuffer(uint32 w, uint32 h) { - _intBuffer = 0; - switch (_bodyMode) { - case BODYMODE_SURFACE: - if (!_surf) { - _surf = new Graphics::Surface; - assert(_surf); - } - _surf->create(w, h, Graphics::PixelFormat::createFormatCLUT8()); - _mode = Graphics::ILBMDecoder::ILBM_UNPACK_PLANES; - _intBuffer = (byte *)_surf->pixels; - break; - - case BODYMODE_MASKBUFFER: - if (!_maskBuffer) { - _maskBuffer = new MaskBuffer; - assert(_maskBuffer); - } - _maskBuffer->create(w, h); - _mode = Graphics::ILBMDecoder::ILBM_2_PACK_PLANES; - _intBuffer = _maskBuffer->data; - break; - - case BODYMODE_PATHBUFFER: - if (!_pathBuffer) { - _pathBuffer = new PathBuffer; - assert(_pathBuffer); - } - _pathBuffer->create(w, h); - _mode = Graphics::ILBMDecoder::ILBM_1_PACK_PLANES; - _intBuffer = _pathBuffer->data; - break; - - default: - error("Invalid bodyMode '%i' for ILBMLoader", _bodyMode); - break; - } -} - -bool ILBMLoader::callback(Common::IFFChunk &chunk) { - switch (chunk._type) { - case ID_BMHD: - _decoder.loadHeader(chunk._stream); - break; - - case ID_CMAP: - if (_palette) { - chunk._stream->read(_palette, chunk._size); - } - break; - - case ID_CRNG: - if (_crng) { - PaletteFxRange *ptr = &_crng[_numCRNG]; - chunk._stream->read((byte *)ptr, chunk._size); - ptr->_timer = FROM_BE_16(ptr->_timer); - ptr->_step = FROM_BE_16(ptr->_step); - ptr->_flags = FROM_BE_16(ptr->_flags); - ++_numCRNG; - } - break; - - case ID_BODY: - setupBuffer(_decoder._header.width, _decoder._header.height); - assert(_intBuffer); - _decoder.loadBitmap(_mode, _intBuffer, chunk._stream); - return true; // stop the parser - } - - return false; -} - -void ILBMLoader::load(Common::ReadStream *in, bool disposeStream) { - Common::IFFParser parser(in, disposeStream); - Common::Functor1Mem< Common::IFFChunk&, bool, ILBMLoader > c(this, &ILBMLoader::callback); - parser.parse(c); -} - -ILBMLoader::ILBMLoader(uint32 bodyMode, byte *palette, PaletteFxRange *crng) { - _bodyMode = bodyMode; - _surf = 0; - _maskBuffer = 0; - _pathBuffer = 0; - _palette = palette; - _crng = crng; - _numCRNG = 0; -} - -ILBMLoader::ILBMLoader(Graphics::Surface *surf, byte *palette, PaletteFxRange *crng) { - _bodyMode = ILBMLoader::BODYMODE_SURFACE; - _surf = surf; - _palette = palette; - _crng = crng; - _numCRNG = 0; -} - -ILBMLoader::ILBMLoader(MaskBuffer *buffer) { - _bodyMode = ILBMLoader::BODYMODE_MASKBUFFER; - _maskBuffer = buffer; - _palette = 0; - _crng = 0; - _numCRNG = 0; -} - -ILBMLoader::ILBMLoader(PathBuffer *buffer) { - _bodyMode = ILBMLoader::BODYMODE_PATHBUFFER; - _pathBuffer = buffer; - _palette = 0; - _crng = 0; - _numCRNG = 0; -} - - - -} diff --git a/engines/parallaction/disk.h b/engines/parallaction/disk.h index d1171c3179..63e33dcfbd 100644 --- a/engines/parallaction/disk.h +++ b/engines/parallaction/disk.h @@ -28,13 +28,10 @@ #include "common/archive.h" #include "common/str.h" -#include "graphics/iff.h" - namespace Common { class FSDirectory; class ReadStream; class SeekableReadStream; -struct IFFChunk; } namespace Graphics { @@ -86,36 +83,6 @@ public: virtual PathBuffer *loadPath(const char *name, uint32 w, uint32 h) { return 0; } }; -struct PaletteFxRange; - -struct ILBMLoader { - enum { - BODYMODE_SURFACE, - BODYMODE_MASKBUFFER, - BODYMODE_PATHBUFFER - }; - uint32 _bodyMode; - Graphics::Surface *_surf; - MaskBuffer *_maskBuffer; - PathBuffer *_pathBuffer; - byte *_palette; - PaletteFxRange *_crng; - uint32 _mode; - byte* _intBuffer; - uint32 _numCRNG; - Graphics::ILBMDecoder _decoder; - - ILBMLoader(uint32 bodyMode, byte *palette = 0, PaletteFxRange *crng = 0); - ILBMLoader(Graphics::Surface *surf, byte *palette = 0, PaletteFxRange *crng = 0); - ILBMLoader(MaskBuffer *buffer); - ILBMLoader(PathBuffer *buffer); - - bool callback(Common::IFFChunk &chunk); - void setupBuffer(uint32 w, uint32 h); - void load(Common::ReadStream *in, bool disposeStream = false); -}; - - class Disk_ns : public Disk { protected: diff --git a/engines/parallaction/disk_br.cpp b/engines/parallaction/disk_br.cpp index 8988897456..efddfb9935 100644 --- a/engines/parallaction/disk_br.cpp +++ b/engines/parallaction/disk_br.cpp @@ -20,11 +20,10 @@ * */ -#include "graphics/iff.h" - #include "common/config-manager.h" #include "common/fs.h" #include "common/textconsole.h" +#include "graphics/decoders/iff.h" #include "parallaction/parallaction.h" #include "parallaction/parser.h" @@ -459,8 +458,9 @@ void AmigaDisk_br::adjustForPalette(Graphics::Surface &surf, int transparentColo void AmigaDisk_br::loadBackground(BackgroundInfo& info, const char *filename) { byte r,g,b; - byte *p; + const byte *p; Common::SeekableReadStream *stream; + Graphics::IFFDecoder decoder; uint i; stream = tryOpenFile("backs/" + Common::String(filename), ".ap"); @@ -488,15 +488,16 @@ void AmigaDisk_br::loadBackground(BackgroundInfo& info, const char *filename) { } stream = openFile("backs/" + Common::String(filename), ".bkg"); + decoder.loadStream(*stream); - byte pal[768]; - ILBMLoader loader(&info.bg, pal); - loader.load(stream, true); - + info.bg.copyFrom(*decoder.getSurface()); info.width = info.bg.w; info.height = info.bg.h; - p = pal; + // Overwrite the first color (transparent key) in the palette + p = decoder.getPalette(); + info.palette.setEntry(0, p[0] >> 2, p[1] >> 2, p[2] >> 0); + for (i = 16; i < 32; i++) { r = *p >> 2; p++; @@ -507,9 +508,6 @@ void AmigaDisk_br::loadBackground(BackgroundInfo& info, const char *filename) { info.palette.setEntry(i, r, g, b); } - // Overwrite the first color (transparent key) in the palette - info.palette.setEntry(0, pal[0] >> 2, pal[1] >> 2, pal[2] >> 0); - // background data is drawn used the upper portion of the palette adjustForPalette(info.bg); } @@ -546,10 +544,15 @@ MaskBuffer *AmigaDisk_br::loadMask(const char *name, uint32 w, uint32 h) { return 0; } - ILBMLoader loader(ILBMLoader::BODYMODE_MASKBUFFER); - loader.load(stream, true); + Graphics::IFFDecoder decoder; + decoder.setNumRelevantPlanes(2); // use only 2 first bits from each pixels + decoder.setPixelPacking(true); // pack 4 2bit pixels into 1 byte + decoder.loadStream(*stream); - MaskBuffer *buffer = loader._maskBuffer; + MaskBuffer *buffer = new MaskBuffer; + // surface width was shrunk to 1/4th of the bitmap width due to the pixel packing + buffer->create(decoder.getSurface()->w * 4, decoder.getSurface()->h); + memcpy(buffer->data, decoder.getSurface()->pixels, buffer->size); buffer->bigEndian = true; finalpass(buffer->data, buffer->size); return buffer; @@ -580,12 +583,12 @@ GfxObj* AmigaDisk_br::loadStatic(const char* name) { Common::String sName = name; Common::SeekableReadStream *stream = openFile("ras/" + sName, ".ras"); + Graphics::IFFDecoder decoder; + decoder.loadStream(*stream); - ILBMLoader loader(ILBMLoader::BODYMODE_SURFACE); - loader.load(stream, true); - - Graphics::Surface* surf = loader._surf; + Graphics::Surface *surf = new Graphics::Surface; assert(surf); + surf->copyFrom(*decoder.getSurface()); // Static pictures are drawn used the upper half of the palette: this must be // done before shadow mask is applied. This way, only really transparent pixels @@ -717,16 +720,16 @@ GfxObj* AmigaDisk_br::loadObjects(const char *name, uint8 part) { debugC(5, kDebugDisk, "AmigaDisk_br::loadObjects"); Common::SeekableReadStream *stream = openFile(name); - ILBMLoader loader(ILBMLoader::BODYMODE_SURFACE); - loader.load(stream, true); + Graphics::IFFDecoder decoder; + decoder.loadStream(*stream); uint16 max = objectsMax[part]; if (_vm->getFeatures() & GF_DEMO) max = 72; byte *data = new byte[max * 2601]; - byte *srcPtr = (byte *)loader._surf->getBasePtr(0,0); - int w = loader._surf->w; + byte *srcPtr = (byte *)decoder.getSurface()->getBasePtr(0,0); + int w = decoder.getSurface()->w; // Convert to the expected display format for (int i = 0; i < max; i++) { @@ -741,7 +744,6 @@ GfxObj* AmigaDisk_br::loadObjects(const char *name, uint8 part) { dst += 51; } } - delete loader._surf; return new GfxObj(0, new Cnv(max, 51, 51, data, true)); } diff --git a/engines/parallaction/disk_ns.cpp b/engines/parallaction/disk_ns.cpp index bad854525d..f03f16ca37 100644 --- a/engines/parallaction/disk_ns.cpp +++ b/engines/parallaction/disk_ns.cpp @@ -22,9 +22,11 @@ #include "common/config-manager.h" #include "common/fs.h" +#include "common/iff_container.h" #include "common/memstream.h" #include "common/substream.h" #include "common/textconsole.h" +#include "graphics/decoders/iff.h" #include "parallaction/parser.h" #include "parallaction/parallaction.h" @@ -312,7 +314,7 @@ void DosDisk_ns::decodeCnv(byte *data, uint16 numFrames, uint16 width, uint16 he int32 decsize = numFrames * width * height; bool packed = (stream->size() - stream->pos()) != decsize; if (packed) { - Graphics::PackBitsReadStream decoder(*stream); + Common::PackBitsReadStream decoder(*stream); decoder.read(data, decsize); } else { stream->read(data, decsize); @@ -914,17 +916,15 @@ void AmigaDisk_ns::buildMask(byte* buf) { void AmigaDisk_ns::loadBackground(BackgroundInfo& info, const char *name) { - PaletteFxRange ranges[6]; - byte pal[768]; - Common::SeekableReadStream *s = openFile(name); - ILBMLoader loader(&info.bg, pal, ranges); - loader.load(s, true); + Graphics::IFFDecoder decoder; + decoder.loadStream(*s); + info.bg.copyFrom(*decoder.getSurface()); info.width = info.bg.w; info.height = info.bg.h; - byte *p = pal; + const byte *p = decoder.getPalette(); for (uint i = 0; i < 32; i++) { byte r = *p >> 2; p++; @@ -935,8 +935,15 @@ void AmigaDisk_ns::loadBackground(BackgroundInfo& info, const char *name) { info.palette.setEntry(i, r, g, b); } - for (uint j = 0; j < 6; j++) { - info.setPaletteRange(j, ranges[j]); + const Common::Array<Graphics::IFFDecoder::PaletteRange> &paletteRanges = decoder.getPaletteRanges(); + for (uint j = 0; j < 6 && j < paletteRanges.size(); j++) { + PaletteFxRange range; + range._timer = paletteRanges[j].timer; + range._step = paletteRanges[j].step; + range._flags = paletteRanges[j].flags; + range._first = paletteRanges[j].first; + range._last = paletteRanges[j].last; + info.setPaletteRange(j, range); } } @@ -952,19 +959,25 @@ void AmigaDisk_ns::loadMask_internal(BackgroundInfo& info, const char *name) { return; // no errors if missing mask files: not every location has one } - byte pal[768]; - ILBMLoader loader(ILBMLoader::BODYMODE_MASKBUFFER, pal); - loader.load(s, true); + Graphics::IFFDecoder decoder; + decoder.setNumRelevantPlanes(2); // use only 2 first bits from each pixel + decoder.setPixelPacking(true); // pack 4 2bit pixels into 1 byte + decoder.loadStream(*s); + const byte *p = decoder.getPalette(); byte r, g, b; for (uint i = 0; i < 4; i++) { - r = pal[i*3]; - g = pal[i*3+1]; - b = pal[i*3+2]; + r = p[i*3]; + g = p[i*3+1]; + b = p[i*3+2]; info.layers[i] = (((r << 4) & 0xF00) | (g & 0xF0) | (b >> 4)) & 0xFF; } - info._mask = loader._maskBuffer; + info._mask = new MaskBuffer; + // surface width was shrunk to 1/4th of the bitmap width due to the pixel packing + info._mask->create(decoder.getSurface()->w * 4, decoder.getSurface()->h); + memcpy(info._mask->data, decoder.getSurface()->pixels, info._mask->size); + info._mask->bigEndian = true; } void AmigaDisk_ns::loadPath_internal(BackgroundInfo& info, const char *name) { @@ -977,9 +990,15 @@ void AmigaDisk_ns::loadPath_internal(BackgroundInfo& info, const char *name) { return; // no errors if missing path files: not every location has one } - ILBMLoader loader(ILBMLoader::BODYMODE_PATHBUFFER); - loader.load(s, true); - info._path = loader._pathBuffer; + Graphics::IFFDecoder decoder; + decoder.setNumRelevantPlanes(1); // use only first bit from each pixel + decoder.setPixelPacking(true); // pack 8 1bit pixels into 1 byte + decoder.loadStream(*s); + + info._path = new PathBuffer; + // surface width was shrunk to 1/8th of the bitmap width due to the pixel packing + info._path->create(decoder.getSurface()->w * 8, decoder.getSurface()->h); + memcpy(info._path->data, decoder.getSurface()->pixels, info._path->size); info._path->bigEndian = true; } diff --git a/engines/parallaction/module.mk b/engines/parallaction/module.mk index 36572a51df..f8a4e0b9a3 100644 --- a/engines/parallaction/module.mk +++ b/engines/parallaction/module.mk @@ -8,7 +8,6 @@ MODULE_OBJS := \ debug.o \ detection.o \ dialogue.o \ - disk.o \ disk_br.o \ disk_ns.o \ exec.o \ |