2007-05-30 21:56:52 +00:00
|
|
|
/* 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.
|
2007-05-01 15:39:40 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef COMMON_IFF_CONTAINER_H
|
|
|
|
#define COMMON_IFF_CONTAINER_H
|
|
|
|
|
|
|
|
#include "common/scummsys.h"
|
|
|
|
#include "common/endian.h"
|
2009-06-12 08:51:05 +00:00
|
|
|
#include "common/func.h"
|
2007-05-01 15:39:40 +00:00
|
|
|
#include "common/stream.h"
|
2011-04-24 08:34:27 +00:00
|
|
|
#include "common/textconsole.h"
|
2007-05-01 15:39:40 +00:00
|
|
|
|
|
|
|
namespace Common {
|
|
|
|
|
|
|
|
typedef uint32 IFF_ID;
|
|
|
|
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_FORM MKTAG('F','O','R','M')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* EA IFF 85 group identifier */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_CAT MKTAG('C','A','T',' ')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* EA IFF 85 group identifier */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_LIST MKTAG('L','I','S','T')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* EA IFF 85 group identifier */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_PROP MKTAG('P','R','O','P')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* EA IFF 85 group identifier */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_END MKTAG('E','N','D',' ')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* unofficial END-of-FORM identifier (see Amiga RKM Devices Ed.3
|
|
|
|
page 376) */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_ILBM MKTAG('I','L','B','M')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* EA IFF 85 raster bitmap form */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_DEEP MKTAG('D','E','E','P')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* Chunky pixel image files (Used in TV Paint) */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_RGB8 MKTAG('R','G','B','8')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* RGB image forms, Turbo Silver (Impulse) */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_RGBN MKTAG('R','G','B','N')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* RGB image forms, Turbo Silver (Impulse) */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_PBM MKTAG('P','B','M',' ')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* 256-color chunky format (DPaint 2 ?) */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_ACBM MKTAG('A','C','B','M')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* Amiga Contiguous Bitmap (AmigaBasic) */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_8SVX MKTAG('8','S','V','X')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* Amiga 8 bits voice */
|
|
|
|
|
|
|
|
/* generic */
|
|
|
|
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_FVER MKTAG('F','V','E','R')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* AmigaOS version string */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_JUNK MKTAG('J','U','N','K')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* always ignore this chunk */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_ANNO MKTAG('A','N','N','O')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* EA IFF 85 Generic Annotation chunk */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_AUTH MKTAG('A','U','T','H')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* EA IFF 85 Generic Author chunk */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_CHRS MKTAG('C','H','R','S')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* EA IFF 85 Generic character string chunk */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_NAME MKTAG('N','A','M','E')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* EA IFF 85 Generic Name of art, music, etc. chunk */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_TEXT MKTAG('T','E','X','T')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* EA IFF 85 Generic unformatted ASCII text chunk */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_copy MKTAG('(','c',')',' ')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* EA IFF 85 Generic Copyright text chunk */
|
|
|
|
|
|
|
|
/* ILBM chunks */
|
|
|
|
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_BMHD MKTAG('B','M','H','D')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* ILBM BitmapHeader */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_CMAP MKTAG('C','M','A','P')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* ILBM 8bit RGB colormap */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_GRAB MKTAG('G','R','A','B')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* ILBM "hotspot" coordiantes */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_DEST MKTAG('D','E','S','T')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* ILBM destination image info */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_SPRT MKTAG('S','P','R','T')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* ILBM sprite identifier */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_CAMG MKTAG('C','A','M','G')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* Amiga viewportmodes */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_BODY MKTAG('B','O','D','Y')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* ILBM image data */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_CRNG MKTAG('C','R','N','G')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* color cycling */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_CCRT MKTAG('C','C','R','T')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* color cycling */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_CLUT MKTAG('C','L','U','T')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* Color Lookup Table chunk */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_DPI MKTAG('D','P','I',' ')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* Dots per inch chunk */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_DPPV MKTAG('D','P','P','V')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* DPaint perspective chunk (EA) */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_DRNG MKTAG('D','R','N','G')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* DPaint IV enhanced color cycle chunk (EA) */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_EPSF MKTAG('E','P','S','F')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* Encapsulated Postscript chunk */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_CMYK MKTAG('C','M','Y','K')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* Cyan, Magenta, Yellow, & Black color map (Soft-Logik) */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_CNAM MKTAG('C','N','A','M')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* Color naming chunk (Soft-Logik) */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_PCHG MKTAG('P','C','H','G')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* Line by line palette control information (Sebastiano Vigna) */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_PRVW MKTAG('P','R','V','W')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* A mini duplicate ILBM used for preview (Gary Bonham) */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_XBMI MKTAG('X','B','M','I')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* eXtended BitMap Information (Soft-Logik) */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_CTBL MKTAG('C','T','B','L')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* Newtek Dynamic Ham color chunk */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_DYCP MKTAG('D','Y','C','P')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* Newtek Dynamic Ham chunk */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_SHAM MKTAG('S','H','A','M')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* Sliced HAM color chunk */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_ABIT MKTAG('A','B','I','T')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* ACBM body chunk */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_DCOL MKTAG('D','C','O','L')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* unofficial direct color */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_DPPS MKTAG('D','P','P','S')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* ? */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_TINY MKTAG('T','I','N','Y')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* ? */
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_DPPV MKTAG('D','P','P','V')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* ? */
|
|
|
|
|
|
|
|
/* 8SVX chunks */
|
|
|
|
|
2011-04-12 14:53:15 +00:00
|
|
|
#define ID_VHDR MKTAG('V','H','D','R')
|
2007-05-01 15:39:40 +00:00
|
|
|
/* 8SVX Voice8Header */
|
|
|
|
|
|
|
|
|
2009-06-12 08:51:05 +00:00
|
|
|
/**
|
|
|
|
* Represents a IFF chunk available to client code.
|
|
|
|
*
|
|
|
|
* Client code must *not* deallocate _stream when done.
|
|
|
|
*/
|
|
|
|
struct IFFChunk {
|
2011-08-06 07:47:19 +00:00
|
|
|
IFF_ID _type;
|
|
|
|
uint32 _size;
|
|
|
|
ReadStream *_stream;
|
2007-05-01 15:39:40 +00:00
|
|
|
|
2011-08-06 07:47:19 +00:00
|
|
|
IFFChunk(IFF_ID type, uint32 size, ReadStream *stream) : _type(type), _size(size), _stream(stream) {
|
2009-06-12 08:51:05 +00:00
|
|
|
assert(_stream);
|
2007-05-01 15:39:40 +00:00
|
|
|
}
|
2009-06-12 08:51:05 +00:00
|
|
|
};
|
2007-05-01 15:39:40 +00:00
|
|
|
|
2009-06-12 08:51:05 +00:00
|
|
|
/**
|
|
|
|
* Parser for IFF containers.
|
|
|
|
*/
|
|
|
|
class IFFParser {
|
2008-09-14 22:28:53 +00:00
|
|
|
|
2009-06-12 08:51:05 +00:00
|
|
|
/**
|
|
|
|
* This private class implements IFF chunk navigation.
|
|
|
|
*/
|
2011-08-06 07:47:19 +00:00
|
|
|
class IFFChunkNav : public ReadStream {
|
2009-06-12 08:51:05 +00:00
|
|
|
protected:
|
2011-08-06 07:47:19 +00:00
|
|
|
ReadStream *_input;
|
2009-06-12 08:51:05 +00:00
|
|
|
uint32 _bytesRead;
|
|
|
|
public:
|
2011-08-06 07:47:19 +00:00
|
|
|
IFF_ID id;
|
2009-06-12 08:51:05 +00:00
|
|
|
uint32 size;
|
|
|
|
|
|
|
|
IFFChunkNav() : _input(0) {
|
2007-05-01 15:39:40 +00:00
|
|
|
}
|
2011-08-06 07:47:19 +00:00
|
|
|
void setInputStream(ReadStream *input) {
|
2009-06-12 08:51:05 +00:00
|
|
|
_input = input;
|
|
|
|
size = _bytesRead = 0;
|
2007-05-01 15:39:40 +00:00
|
|
|
}
|
2009-06-12 08:51:05 +00:00
|
|
|
void incBytesRead(uint32 inc) {
|
|
|
|
_bytesRead += inc;
|
|
|
|
if (_bytesRead > size) {
|
|
|
|
error("Chunk overread");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void readHeader() {
|
|
|
|
id = _input->readUint32BE();
|
|
|
|
size = _input->readUint32BE();
|
|
|
|
_bytesRead = 0;
|
|
|
|
}
|
|
|
|
bool hasReadAll() const {
|
|
|
|
return (size - _bytesRead) == 0;
|
|
|
|
}
|
|
|
|
void feed() {
|
|
|
|
if (size % 2) {
|
|
|
|
size++;
|
|
|
|
}
|
|
|
|
while (!hasReadAll()) {
|
|
|
|
readByte();
|
|
|
|
}
|
|
|
|
}
|
2011-08-06 07:47:19 +00:00
|
|
|
// ReadStream implementation
|
2009-06-12 08:51:05 +00:00
|
|
|
bool eos() const { return _input->eos(); }
|
|
|
|
bool err() const { return _input->err(); }
|
|
|
|
void clearErr() { _input->clearErr(); }
|
|
|
|
|
|
|
|
uint32 read(void *dataPtr, uint32 dataSize) {
|
|
|
|
incBytesRead(dataSize);
|
|
|
|
return _input->read(dataPtr, dataSize);
|
|
|
|
}
|
|
|
|
};
|
2007-05-01 15:39:40 +00:00
|
|
|
|
2009-06-12 09:49:38 +00:00
|
|
|
protected:
|
2009-10-08 21:28:57 +00:00
|
|
|
IFFChunkNav _formChunk; ///< The root chunk of the file.
|
|
|
|
IFFChunkNav _chunk; ///< The current chunk.
|
2007-05-01 15:39:40 +00:00
|
|
|
|
2009-06-12 09:49:38 +00:00
|
|
|
uint32 _formSize;
|
2011-08-06 07:47:19 +00:00
|
|
|
IFF_ID _formType;
|
2009-06-12 09:49:38 +00:00
|
|
|
|
2011-08-06 07:47:19 +00:00
|
|
|
ReadStream *_stream;
|
2009-06-12 08:51:05 +00:00
|
|
|
bool _disposeStream;
|
2007-05-01 15:39:40 +00:00
|
|
|
|
2011-08-06 07:47:19 +00:00
|
|
|
void setInputStream(ReadStream *stream);
|
2007-05-01 15:39:40 +00:00
|
|
|
|
2009-06-12 08:51:05 +00:00
|
|
|
public:
|
2011-08-06 07:47:19 +00:00
|
|
|
IFFParser(ReadStream *stream, bool disposeStream = false);
|
2010-11-19 17:03:07 +00:00
|
|
|
~IFFParser();
|
2009-06-12 08:51:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback type for the parser.
|
|
|
|
*/
|
2011-08-06 07:47:19 +00:00
|
|
|
typedef Functor1< IFFChunk&, bool > IFFCallback;
|
2009-06-12 08:51:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse the IFF container, invoking the callback on each chunk encountered.
|
|
|
|
* The callback can interrupt the parsing by returning 'true'.
|
|
|
|
*/
|
2010-11-19 17:03:07 +00:00
|
|
|
void parse(IFFCallback &callback);
|
2007-05-01 15:39:40 +00:00
|
|
|
};
|
|
|
|
|
2009-06-12 08:51:05 +00:00
|
|
|
|
2007-05-01 15:39:40 +00:00
|
|
|
} // namespace Common
|
|
|
|
|
|
|
|
#endif
|