ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

iff_container.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef COMMON_IFF_CONTAINER_H
00024 #define COMMON_IFF_CONTAINER_H
00025 
00026 #include "common/scummsys.h"
00027 #include "common/endian.h"
00028 #include "common/func.h"
00029 #include "common/stream.h"
00030 #include "common/textconsole.h"
00031 
00032 namespace Common {
00033 
00034 typedef uint32 IFF_ID;
00035 
00036 #define ID_FORM     MKTAG('F','O','R','M')
00037 /* EA IFF 85 group identifier */
00038 #define ID_CAT      MKTAG('C','A','T',' ')
00039 /* EA IFF 85 group identifier */
00040 #define ID_LIST     MKTAG('L','I','S','T')
00041 /* EA IFF 85 group identifier */
00042 #define ID_PROP     MKTAG('P','R','O','P')
00043 /* EA IFF 85 group identifier */
00044 #define ID_END      MKTAG('E','N','D',' ')
00045 /* unofficial END-of-FORM identifier (see Amiga RKM Devices Ed.3
00046 page 376) */
00047 #define ID_ILBM     MKTAG('I','L','B','M')
00048 /* EA IFF 85 raster bitmap form */
00049 #define ID_DEEP     MKTAG('D','E','E','P')
00050 /* Chunky pixel image files (Used in TV Paint) */
00051 #define ID_RGB8     MKTAG('R','G','B','8')
00052 /* RGB image forms, Turbo Silver (Impulse) */
00053 #define ID_RGBN     MKTAG('R','G','B','N')
00054 /* RGB image forms, Turbo Silver (Impulse) */
00055 #define ID_PBM      MKTAG('P','B','M',' ')
00056 /* 256-color chunky format (DPaint 2 ?) */
00057 #define ID_ACBM     MKTAG('A','C','B','M')
00058 /* Amiga Contiguous Bitmap (AmigaBasic) */
00059 #define ID_8SVX     MKTAG('8','S','V','X')
00060 /* Amiga 8 bits voice */
00061 
00062 /* generic */
00063 
00064 #define ID_FVER     MKTAG('F','V','E','R')
00065 /* AmigaOS version string */
00066 #define ID_JUNK     MKTAG('J','U','N','K')
00067 /* always ignore this chunk */
00068 #define ID_ANNO     MKTAG('A','N','N','O')
00069 /* EA IFF 85 Generic Annotation chunk */
00070 #define ID_AUTH     MKTAG('A','U','T','H')
00071 /* EA IFF 85 Generic Author chunk */
00072 #define ID_CHRS     MKTAG('C','H','R','S')
00073 /* EA IFF 85 Generic character string chunk */
00074 #define ID_NAME     MKTAG('N','A','M','E')
00075 /* EA IFF 85 Generic Name of art, music, etc. chunk */
00076 #define ID_TEXT     MKTAG('T','E','X','T')
00077 /* EA IFF 85 Generic unformatted ASCII text chunk */
00078 #define ID_copy     MKTAG('(','c',')',' ')
00079 /* EA IFF 85 Generic Copyright text chunk */
00080 
00081 /* IFF chunks */
00082 
00083 #define ID_BMHD     MKTAG('B','M','H','D')
00084 /* IFF BitmapHeader */
00085 #define ID_CMAP     MKTAG('C','M','A','P')
00086 /* IFF 8bit RGB colormap */
00087 #define ID_GRAB     MKTAG('G','R','A','B')
00088 /* IFF "hotspot" coordiantes */
00089 #define ID_DEST     MKTAG('D','E','S','T')
00090 /* IFF destination image info */
00091 #define ID_SPRT     MKTAG('S','P','R','T')
00092 /* IFF sprite identifier */
00093 #define ID_CAMG     MKTAG('C','A','M','G')
00094 /* Amiga viewportmodes */
00095 #define ID_BODY     MKTAG('B','O','D','Y')
00096 /* IFF image data */
00097 #define ID_CRNG     MKTAG('C','R','N','G')
00098 /* color cycling */
00099 #define ID_CCRT     MKTAG('C','C','R','T')
00100 /* color cycling */
00101 #define ID_CLUT     MKTAG('C','L','U','T')
00102 /* Color Lookup Table chunk */
00103 #define ID_DPI      MKTAG('D','P','I',' ')
00104 /* Dots per inch chunk */
00105 #define ID_DPPV     MKTAG('D','P','P','V')
00106 /* DPaint perspective chunk (EA) */
00107 #define ID_DRNG     MKTAG('D','R','N','G')
00108 /* DPaint IV enhanced color cycle chunk (EA) */
00109 #define ID_EPSF     MKTAG('E','P','S','F')
00110 /* Encapsulated Postscript chunk */
00111 #define ID_CMYK     MKTAG('C','M','Y','K')
00112 /* Cyan, Magenta, Yellow, & Black color map (Soft-Logik) */
00113 #define ID_CNAM     MKTAG('C','N','A','M')
00114 /* Color naming chunk (Soft-Logik) */
00115 #define ID_PCHG     MKTAG('P','C','H','G')
00116 /* Line by line palette control information (Sebastiano Vigna) */
00117 #define ID_PRVW     MKTAG('P','R','V','W')
00118 /* A mini duplicate IFF used for preview (Gary Bonham) */
00119 #define ID_XBMI     MKTAG('X','B','M','I')
00120 /* eXtended BitMap Information (Soft-Logik) */
00121 #define ID_CTBL     MKTAG('C','T','B','L')
00122 /* Newtek Dynamic Ham color chunk */
00123 #define ID_DYCP     MKTAG('D','Y','C','P')
00124 /* Newtek Dynamic Ham chunk */
00125 #define ID_SHAM     MKTAG('S','H','A','M')
00126 /* Sliced HAM color chunk */
00127 #define ID_ABIT     MKTAG('A','B','I','T')
00128 /* ACBM body chunk */
00129 #define ID_DCOL     MKTAG('D','C','O','L')
00130 /* unofficial direct color */
00131 #define ID_DPPS     MKTAG('D','P','P','S')
00132 /* ? */
00133 #define ID_TINY     MKTAG('T','I','N','Y')
00134 /* ? */
00135 #define ID_DPPV     MKTAG('D','P','P','V')
00136 /* ? */
00137 
00138 /* 8SVX chunks */
00139 
00140 #define ID_VHDR     MKTAG('V','H','D','R')
00141 /* 8SVX Voice8Header */
00142 
00143 
00149 struct IFFChunk {
00150     IFF_ID      _type;
00151     uint32      _size;
00152     ReadStream *_stream;
00153 
00154     IFFChunk(IFF_ID type, uint32 size, ReadStream *stream) : _type(type), _size(size), _stream(stream) {
00155         assert(_stream);
00156     }
00157 };
00158 
00162 class IFFParser {
00163 
00167     class IFFChunkNav : public ReadStream {
00168     protected:
00169         ReadStream *_input;
00170         uint32 _bytesRead;
00171     public:
00172         IFF_ID id;
00173         uint32 size;
00174 
00175         IFFChunkNav() : _input(nullptr) {
00176         }
00177         void setInputStream(ReadStream *input) {
00178             _input = input;
00179             size = _bytesRead = 0;
00180         }
00181         void incBytesRead(uint32 inc) {
00182             _bytesRead += inc;
00183             if (_bytesRead > size) {
00184                 error("Chunk overread");
00185             }
00186         }
00187         void readHeader() {
00188             id = _input->readUint32BE();
00189             size = _input->readUint32BE();
00190             _bytesRead = 0;
00191         }
00192         bool hasReadAll() const {
00193             return (size - _bytesRead) == 0;
00194         }
00195         void feed() {
00196             if (size % 2) {
00197                 size++;
00198             }
00199             while (!hasReadAll()) {
00200                 readByte();
00201             }
00202         }
00203         // ReadStream implementation
00204         bool eos() const { return _input->eos(); }
00205         bool err() const { return _input->err(); }
00206         void clearErr() { _input->clearErr(); }
00207 
00208         uint32 read(void *dataPtr, uint32 dataSize) {
00209             incBytesRead(dataSize);
00210             return _input->read(dataPtr, dataSize);
00211         }
00212     };
00213 
00214 protected:
00215     IFFChunkNav _formChunk; 
00216     IFFChunkNav _chunk;     
00217 
00218     uint32 _formSize;
00219     IFF_ID _formType;
00220 
00221     ReadStream *_stream;
00222     bool _disposeStream;
00223 
00224     void setInputStream(ReadStream *stream);
00225 
00226 public:
00227     IFFParser(ReadStream *stream, bool disposeStream = false);
00228     ~IFFParser();
00229 
00233     typedef Functor1< IFFChunk&, bool > IFFCallback;
00234 
00239     void parse(IFFCallback &callback);
00240 };
00241 
00242 
00254 class PackBitsReadStream : public Common::ReadStream {
00255 
00256 protected:
00257     Common::ReadStream *_input;
00258 
00259 public:
00260     PackBitsReadStream(Common::ReadStream &input);
00261     ~PackBitsReadStream();
00262 
00263     virtual bool eos() const;
00264 
00265     uint32 read(void *dataPtr, uint32 dataSize);
00266 };
00267 
00268 } // namespace Common
00269 
00270 #endif


Generated on Sat May 18 2019 05:01:04 for ResidualVM by doxygen 1.7.1
curved edge   curved edge