ScummVM API documentation
iff_container.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef COMMON_IFF_CONTAINER_H
23 #define COMMON_IFF_CONTAINER_H
24 
25 #include "common/scummsys.h"
26 #include "common/endian.h"
27 #include "common/func.h"
28 #include "common/stream.h"
29 #include "common/textconsole.h"
30 
31 namespace Common {
32 
43 typedef uint32 IFF_ID;
44 
45 #define ID_FORM MKTAG('F','O','R','M')
46 /* EA IFF 85 group identifier */
47 #define ID_CAT MKTAG('C','A','T',' ')
48 /* EA IFF 85 group identifier */
49 #define ID_LIST MKTAG('L','I','S','T')
50 /* EA IFF 85 group identifier */
51 #define ID_PROP MKTAG('P','R','O','P')
52 /* EA IFF 85 group identifier */
53 #define ID_END MKTAG('E','N','D',' ')
54 /* unofficial END-of-FORM identifier (see Amiga RKM Devices Ed.3
55 page 376) */
56 #define ID_ILBM MKTAG('I','L','B','M')
57 /* EA IFF 85 raster bitmap form */
58 #define ID_DEEP MKTAG('D','E','E','P')
59 /* Chunky pixel image files (Used in TV Paint) */
60 #define ID_RGB8 MKTAG('R','G','B','8')
61 /* RGB image forms, Turbo Silver (Impulse) */
62 #define ID_RGBN MKTAG('R','G','B','N')
63 /* RGB image forms, Turbo Silver (Impulse) */
64 #define ID_PBM MKTAG('P','B','M',' ')
65 /* 256-color chunky format (DPaint 2 ?) */
66 #define ID_ACBM MKTAG('A','C','B','M')
67 /* Amiga Contiguous Bitmap (AmigaBasic) */
68 #define ID_8SVX MKTAG('8','S','V','X')
69 /* Amiga 8 bits voice */
70 #define ID_DATA MKTAG('D','A','T','A')
71 /* Replaces FORM in Nancy Drew IFFs */
72 
73 /* generic */
74 
75 #define ID_FVER MKTAG('F','V','E','R')
76 /* AmigaOS version string */
77 #define ID_JUNK MKTAG('J','U','N','K')
78 /* always ignore this chunk */
79 #define ID_ANNO MKTAG('A','N','N','O')
80 /* EA IFF 85 Generic Annotation chunk */
81 #define ID_AUTH MKTAG('A','U','T','H')
82 /* EA IFF 85 Generic Author chunk */
83 #define ID_CHRS MKTAG('C','H','R','S')
84 /* EA IFF 85 Generic character string chunk */
85 #define ID_NAME MKTAG('N','A','M','E')
86 /* EA IFF 85 Generic Name of art, music, etc. chunk */
87 #define ID_TEXT MKTAG('T','E','X','T')
88 /* EA IFF 85 Generic unformatted ASCII text chunk */
89 #define ID_copy MKTAG('(','c',')',' ')
90 /* EA IFF 85 Generic Copyright text chunk */
91 
92 /* IFF chunks */
93 
94 #define ID_BMHD MKTAG('B','M','H','D')
95 /* IFF BitmapHeader */
96 #define ID_CMAP MKTAG('C','M','A','P')
97 /* IFF 8bit RGB colormap */
98 #define ID_GRAB MKTAG('G','R','A','B')
99 /* IFF "hotspot" coordiantes */
100 #define ID_DEST MKTAG('D','E','S','T')
101 /* IFF destination image info */
102 #define ID_SPRT MKTAG('S','P','R','T')
103 /* IFF sprite identifier */
104 #define ID_CAMG MKTAG('C','A','M','G')
105 /* Amiga viewportmodes */
106 #define ID_BODY MKTAG('B','O','D','Y')
107 /* IFF image data */
108 #define ID_CRNG MKTAG('C','R','N','G')
109 /* color cycling */
110 #define ID_CCRT MKTAG('C','C','R','T')
111 /* color cycling */
112 #define ID_CLUT MKTAG('C','L','U','T')
113 /* Color Lookup Table chunk */
114 #define ID_DPI MKTAG('D','P','I',' ')
115 /* Dots per inch chunk */
116 #define ID_DPPV MKTAG('D','P','P','V')
117 /* DPaint perspective chunk (EA) */
118 #define ID_DRNG MKTAG('D','R','N','G')
119 /* DPaint IV enhanced color cycle chunk (EA) */
120 #define ID_EPSF MKTAG('E','P','S','F')
121 /* Encapsulated Postscript chunk */
122 #define ID_CMYK MKTAG('C','M','Y','K')
123 /* Cyan, Magenta, Yellow, & Black color map (Soft-Logik) */
124 #define ID_CNAM MKTAG('C','N','A','M')
125 /* Color naming chunk (Soft-Logik) */
126 #define ID_PCHG MKTAG('P','C','H','G')
127 /* Line by line palette control information (Sebastiano Vigna) */
128 #define ID_PRVW MKTAG('P','R','V','W')
129 /* A mini duplicate IFF used for preview (Gary Bonham) */
130 #define ID_XBMI MKTAG('X','B','M','I')
131 /* eXtended BitMap Information (Soft-Logik) */
132 #define ID_CTBL MKTAG('C','T','B','L')
133 /* Newtek Dynamic Ham color chunk */
134 #define ID_DYCP MKTAG('D','Y','C','P')
135 /* Newtek Dynamic Ham chunk */
136 #define ID_SHAM MKTAG('S','H','A','M')
137 /* Sliced HAM color chunk */
138 #define ID_ABIT MKTAG('A','B','I','T')
139 /* ACBM body chunk */
140 #define ID_DCOL MKTAG('D','C','O','L')
141 /* unofficial direct color */
142 #define ID_DPPS MKTAG('D','P','P','S')
143 /* ? */
144 #define ID_TINY MKTAG('T','I','N','Y')
145 /* ? */
146 #define ID_DPPV MKTAG('D','P','P','V')
147 /* ? */
148 
149 /* 8SVX chunks */
150 
151 #define ID_VHDR MKTAG('V','H','D','R')
152 /* 8SVX Voice8Header */
153 
154 
160 struct IFFChunk {
161  IFF_ID _type;
162  uint32 _size;
163  ReadStream *_stream;
164 
165  IFFChunk(IFF_ID type, uint32 size, ReadStream *stream) : _type(type), _size(size), _stream(stream) {
166  assert(_stream);
167  }
168 };
169 
173 class IFFParser {
174 
178  class IFFChunkNav : public ReadStream {
179  protected:
180  ReadStream *_input;
181  uint32 _bytesRead;
182  public:
183  IFF_ID id;
184  uint32 size;
185 
186  IFFChunkNav() : _input(nullptr) {
187  }
188  void setInputStream(ReadStream *input) {
189  _input = input;
190  size = _bytesRead = 0;
191  }
192  void incBytesRead(uint32 inc) {
193  _bytesRead += inc;
194  if (_bytesRead > size) {
195  error("Chunk overread");
196  }
197  }
198  void readHeader() {
199  id = _input->readUint32BE();
200  size = _input->readUint32BE();
201  _bytesRead = 0;
202  }
203  bool hasReadAll() const {
204  return (size - _bytesRead) == 0;
205  }
206  void feed() {
207  if (size % 2) {
208  size++;
209  }
210  while (!hasReadAll()) {
211  readByte();
212  }
213  }
214  // ReadStream implementation
215  bool eos() const { return _input->eos(); }
216  bool err() const { return _input->err(); }
217  void clearErr() { _input->clearErr(); }
218 
219  uint32 read(void *dataPtr, uint32 dataSize) {
220  incBytesRead(dataSize);
221  return _input->read(dataPtr, dataSize);
222  }
223  };
224 
225 protected:
226  IFFChunkNav _formChunk;
227  IFFChunkNav _chunk;
228 
229  uint32 _formSize;
230  IFF_ID _formType;
231  IFF_ID _formHeaderID;
232 
233  ReadStream *_stream;
234  bool _disposeStream;
235 
236  void setInputStream(ReadStream *stream);
237 
238 public:
239  IFFParser(ReadStream *stream, bool disposeStream = false, IFF_ID formHeaderID = ID_FORM);
240  ~IFFParser();
241 
246 
251  void parse(IFFCallback &callback);
252 };
253 
254 
267 
268 protected:
269  Common::ReadStream *_input;
270 
271 public:
274 
275  virtual bool eos() const;
276 
277  uint32 read(void *dataPtr, uint32 dataSize);
278 };
279 
282 } // namespace Common
283 
284 #endif
virtual bool err() const
Definition: stream.h:61
virtual void clearErr()
Definition: stream.h:71
virtual bool eos() const =0
IFFChunkNav _formChunk
The root chunk of the file.
Definition: iff_container.h:226
Definition: iff_container.h:173
Definition: algorithm.h:29
Functor1< IFFChunk &, bool > IFFCallback
Definition: iff_container.h:245
Definition: func.h:437
void NORETURN_PRE error(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
uint32 readUint32BE()
Definition: stream.h:515
Definition: stream.h:385
Definition: iff_container.h:160
IFFChunkNav _chunk
The current chunk.
Definition: iff_container.h:227
Definition: iff_container.h:266
virtual uint32 read(void *dataPtr, uint32 dataSize)=0