diff options
author | Tomas Jakobsson | 2012-12-30 19:34:43 +0100 |
---|---|---|
committer | Tomas Jakobsson | 2013-01-06 20:04:50 +0100 |
commit | befa207bfa3709c7292252654a5bb9384d950a02 (patch) | |
tree | 4b5cce2436edf5d78f40a6e73d758747efe6d38a /graphics | |
parent | fe10773ac3533e301931586c93eb0b2a5bb7cf80 (diff) | |
download | scummvm-rg350-befa207bfa3709c7292252654a5bb9384d950a02.tar.gz scummvm-rg350-befa207bfa3709c7292252654a5bb9384d950a02.tar.bz2 scummvm-rg350-befa207bfa3709c7292252654a5bb9384d950a02.zip |
GRAPHICS: Delete iff.cpp and iff.h since all ILBM and PBM decoding is handled by IFFDecoder now
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/iff.cpp | 289 | ||||
-rw-r--r-- | graphics/iff.h | 137 | ||||
-rw-r--r-- | graphics/module.mk | 1 |
3 files changed, 0 insertions, 427 deletions
diff --git a/graphics/iff.cpp b/graphics/iff.cpp deleted file mode 100644 index 395d8d803b..0000000000 --- a/graphics/iff.cpp +++ /dev/null @@ -1,289 +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 "graphics/iff.h" -#include "graphics/surface.h" - -#include "common/endian.h" -#include "common/func.h" -#include "common/iff_container.h" -#include "common/textconsole.h" -#include "common/util.h" - -namespace Graphics { - -void BMHD::load(Common::ReadStream *stream) { - assert(stream); - stream->read(this, sizeof(BMHD)); - width = FROM_BE_16(width); - height = FROM_BE_16(height); - x = FROM_BE_16(x); - y = FROM_BE_16(y); - transparentColor = FROM_BE_16(transparentColor); - pageWidth = FROM_BE_16(pageWidth); - pageHeight = FROM_BE_16(pageHeight); -} - - -void ILBMDecoder::loadHeader(Common::ReadStream *stream) { - _header.load(stream); -} - -void ILBMDecoder::loadBitmap(uint32 mode, byte *buffer, Common::ReadStream *stream, uint32 outPitch) { - assert(stream); - uint32 numPlanes = MIN(mode & ILBM_UNPACK_PLANES, (uint32)_header.depth); - assert(numPlanes >= 1 && numPlanes <= 8 && numPlanes != 7); - - bool packPixels = (mode & ILBM_PACK_PLANES) != 0; - if (numPlanes != 1 && numPlanes != 2 && numPlanes != 4) { - packPixels = false; - } - - if (outPitch == 0) - outPitch = _header.width; - if (packPixels) { - outPitch /= (8 / numPlanes); - } - byte *out = buffer; - - switch (_header.pack) { - case 0: { // non-compressed bitmap - // setup a buffer to hold enough data to build a line in the output - uint32 scanlineWidth = ((_header.width + 15) / 16) << 1; - byte *scanline = new byte[scanlineWidth * _header.depth]; - - for (uint i = 0; i < _header.height; ++i) { - byte *s = scanline; - for (uint32 j = 0; j < _header.depth; ++j) { - stream->read(s, scanlineWidth); - s += scanlineWidth; - } - - planarToChunky(out, outPitch, scanline, scanlineWidth, numPlanes, packPixels); - out += outPitch; - } - - delete[] scanline; - break; - } - - case 1: { // PackBits compressed bitmap - Graphics::PackBitsReadStream packStream(*stream); - - // setup a buffer to hold enough data to build a line in the output - uint32 scanlineWidth = ((_header.width + 15) / 16) << 1; - byte *scanline = new byte[scanlineWidth * _header.depth]; - - for (uint i = 0; i < _header.height; ++i) { - byte *s = scanline; - for (uint32 j = 0; j < _header.depth; ++j) { - packStream.read(s, scanlineWidth); - s += scanlineWidth; - } - - planarToChunky(out, outPitch, scanline, scanlineWidth, numPlanes, packPixels); - out += outPitch; - } - - delete[] scanline; - break; - } - - default: - // implement other compression types here! - error("only uncompressed and RLE compressed ILBM files are supported"); - break; - } -} - -void ILBMDecoder::planarToChunky(byte *out, uint32 outPitch, byte *in, uint32 inWidth, uint32 nPlanes, bool packPlanes) { - byte pix, ofs, bit; - byte *s; - - uint32 pixels = outPitch; - if (packPlanes) { - pixels *= (8 / nPlanes); - } - - for (uint32 x = 0; x < pixels; ++x) { - - pix = 0; - ofs = x >> 3; - bit = 0x80 >> (x & 7); - - // first build a pixel by scanning all the usable planes in the input - s = in; - for (uint32 plane = 0; plane < nPlanes; ++plane) { - if (s[ofs] & bit) { - pix |= (1 << plane); - } - s += inWidth; - } - - - // then output the pixel according to the requested packing - if (!packPlanes) { - out[x] = pix; - } else if (nPlanes == 1) { - out[x / 8] |= (pix << (x & 7)); - } else if (nPlanes == 2) { - out[x / 4] |= (pix << ((x & 3) << 1)); - } else if (nPlanes == 4) { - out[x / 2] |= (pix << ((x & 1) << 2)); - } - } - -} - - -// handles PBM subtype of IFF FORM files -// -struct PBMDecoder { - /** - * PBM header data, necessary for loadBitmap() - */ - Graphics::BMHD _header; - - /** - * Fills the _header member from the given stream. - */ - void loadHeader(Common::ReadStream *stream); - - /** - * Loads and unpacks the PBM bitmap data from the stream into the buffer. - * The functions assumes the buffer is large enough to contain all data. - */ - void loadBitmap(byte *buffer, Common::ReadStream *stream); -}; - -void PBMDecoder::loadHeader(Common::ReadStream *stream) { - _header.load(stream); -} - - -void PBMDecoder::loadBitmap(byte *buffer, Common::ReadStream *stream) { - uint32 outSize = _header.width * _header.height; - - switch (_header.pack) { - case 0: - stream->read(buffer, outSize); - break; - - case 1: { - PackBitsReadStream packStream(*stream); - packStream.read(buffer, outSize); - break; - } - } -} - - -struct PBMLoader { - PBMDecoder _decoder; - Surface *_surface; - byte *_colors; - - void load(Common::ReadStream &input, Surface &surface, byte *&colors) { - _surface = &surface; - _colors = colors; - Common::IFFParser parser(&input); - Common::Functor1Mem<Common::IFFChunk &, bool, PBMLoader> c(this, &PBMLoader::callback); - parser.parse(c); - } - - bool callback(Common::IFFChunk &chunk) { - switch (chunk._type) { - case ID_BMHD: - _decoder.loadHeader(chunk._stream); - break; - - case ID_CMAP: - if (_colors) { - chunk._stream->read(_colors, chunk._size); - } - break; - - case ID_BODY: - if (_surface) { - _surface->create(_decoder._header.width, _decoder._header.height, PixelFormat::createFormatCLUT8()); - _decoder.loadBitmap((byte *)_surface->pixels, chunk._stream); - } - return true; // stop the parser - } - - return false; - } -}; - -void decodePBM(Common::ReadStream &input, Surface &surface, byte *colors) { - PBMLoader loader; - loader.load(input, surface, colors); -} - - - - -PackBitsReadStream::PackBitsReadStream(Common::ReadStream &input) : _input(&input) { -} - -PackBitsReadStream::~PackBitsReadStream() { -} - -bool PackBitsReadStream::eos() const { - return _input->eos(); -} - -uint32 PackBitsReadStream::read(void *dataPtr, uint32 dataSize) { - byte *out = (byte *)dataPtr; - uint32 left = dataSize; - - uint32 lenR = 0, lenW = 0; - while (left > 0 && !_input->eos()) { - lenR = _input->readByte(); - - if (lenR == 128) { - // no-op - lenW = 0; - } else if (lenR <= 127) { - // literal run - lenR++; - lenW = MIN(lenR, left); - for (uint32 j = 0; j < lenW; j++) { - *out++ = _input->readByte(); - } - for (; lenR > lenW; lenR--) { - _input->readByte(); - } - } else { // len > 128 - // expand run - lenW = MIN((256 - lenR) + 1, left); - byte val = _input->readByte(); - memset(out, val, lenW); - out += lenW; - } - - left -= lenW; - } - - return dataSize - left; -} - -} // End of namespace Graphics diff --git a/graphics/iff.h b/graphics/iff.h deleted file mode 100644 index 651867fa52..0000000000 --- a/graphics/iff.h +++ /dev/null @@ -1,137 +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. - */ - -/* - * Bitmap decoder used in engines: - * - parallaction - * - saga - */ - -#ifndef GRAPHICS_IFF_H -#define GRAPHICS_IFF_H - -#include "common/stream.h" - -namespace Graphics { - -struct Surface; - - -struct BMHD { - uint16 width, height; - uint16 x, y; - byte depth; - byte masking; - byte pack; - byte flags; - uint16 transparentColor; - byte xAspect, yAspect; - uint16 pageWidth, pageHeight; - - BMHD() { - memset(this, 0, sizeof(*this)); - } - - void load(Common::ReadStream *stream); -}; - - -struct ILBMDecoder { - /** - * ILBM header data, necessary for loadBitmap() - */ - Graphics::BMHD _header; - - /** - * Available decoding modes for loadBitmap(). - */ - enum { - ILBM_UNPACK_PLANES = 0xFF, ///< Decode all bitplanes, and map 1 pixel to 1 byte. - ILBM_PACK_PLANES = 0x100, ///< Request unpacking, used as a mask with below options. - - ILBM_1_PLANES = 1, ///< Decode only the first bitplane, don't pack. - ILBM_1_PACK_PLANES = ILBM_1_PLANES | ILBM_PACK_PLANES, ///< Decode only the first bitplane, pack 8 pixels in 1 byte. - ILBM_2_PLANES = 2, ///< Decode first 2 bitplanes, don't pack. - ILBM_2_PACK_PLANES = ILBM_2_PLANES | ILBM_PACK_PLANES, ///< Decode first 2 bitplanes, pack 4 pixels in 1 byte. - ILBM_3_PLANES = 3, ///< Decode first 3 bitplanes, don't pack. - ILBM_4_PLANES = 4, ///< Decode first 4 bitplanes, don't pack. - ILBM_4_PACK_PLANES = ILBM_4_PLANES | ILBM_PACK_PLANES, ///< Decode first 4 bitplanes, pack 2 pixels in 1 byte. - ILBM_5_PLANES = 5, ///< Decode first 5 bitplanes, don't pack. - ILBM_8_PLANES = 8 ///< Decode all 8 bitplanes. - }; - - /** - * Fills the _header member from the given stream. - */ - void loadHeader(Common::ReadStream *stream); - - /** - * Loads and unpacks the ILBM bitmap data from the stream into the buffer. - * The functions assumes the buffer is large enough to contain all data. - * The caller controls how data should be packed by choosing mode from - * the enum above. - */ - void loadBitmap(uint32 mode, byte *buffer, Common::ReadStream *stream, uint32 outPitch = 0); - - /** - * Converts from bitplanar to chunky representation. Intended for internal - * usage, but you can be (ab)use it from client code if you know what you - * are doing. - */ - void planarToChunky(byte *out, uint32 width, byte *in, uint32 planeWidth, uint32 nPlanes, bool packPlanes); -}; - - - -/** - * Handles PBM subtype of IFF FORM files - */ -void decodePBM(Common::ReadStream &input, Surface &surface, byte *colors); - - -/** - * Decode a given PackBits encoded stream. - * - * PackBits is an RLE compression algorithm introduced by Apple. It is also - * used to encode ILBM and PBM subtypes of IFF files, and some flavors of - * TIFF. - * - * As there is no compression across row boundaries in the above formats, - * read() will extract a *new* line on each call, discarding any alignment - * or padding. - */ -class PackBitsReadStream : public Common::ReadStream { - -protected: - Common::ReadStream *_input; - -public: - PackBitsReadStream(Common::ReadStream &input); - ~PackBitsReadStream(); - - virtual bool eos() const; - - uint32 read(void *dataPtr, uint32 dataSize); -}; - -} // End of namespace Graphics - -#endif diff --git a/graphics/module.mk b/graphics/module.mk index 4e4428daac..8b63435905 100644 --- a/graphics/module.mk +++ b/graphics/module.mk @@ -11,7 +11,6 @@ MODULE_OBJS := \ fonts/newfont.o \ fonts/ttf.o \ fonts/winfont.o \ - iff.o \ maccursor.o \ primitives.o \ scaler.o \ |