ScummVM API documentation
assets.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 MTROPOLIS_ASSETS_H
23#define MTROPOLIS_ASSETS_H
24
25#include "mtropolis/data.h"
26#include "mtropolis/runtime.h"
27#include "mtropolis/render.h"
28
29namespace MTropolis {
30
31struct AssetLoaderContext;
32struct AudioMetadata;
33struct MToonMetadata;
34class AudioPlayer;
35
36class ColorTableAsset : public Asset {
37public:
38 bool load(AssetLoaderContext &context, const Data::ColorTableAsset &data);
39 AssetType getAssetType() const override;
40
41 const ColorRGB8 *getColors() const;
42
43private:
44 ColorRGB8 _colors[256];
45};
46
48public:
50
51 bool loadFromStream(const AudioMetadata &metadata, Common::ReadStream *stream, size_t size);
52
53 const void *getData() const;
54 size_t getSize() const;
55
56 size_t getNumSamples(const AudioMetadata &metadata) const;
57
58private:
60};
61
63 enum ImageFormat {
64 kImageFormatMac,
65 kImageFormatWindows,
66 };
67
68 struct FrameDef {
69 Common::Rect rect;
70 uint32 dataOffset;
71 uint32 compressedSize;
72 uint32 decompressedSize;
73 uint16 decompressedBytesPerRow;
74 bool isKeyFrame;
75
76 FrameDef();
77 bool load(AssetLoaderContext &context, const Data::MToonAsset::FrameDef &data);
78 };
79
81 uint32 startFrame;
82 uint32 endFrame;
83
84 Common::String name;
85
87 bool load(AssetLoaderContext &context, const Data::MToonAsset::FrameRangeDef &data);
88 };
89
91
92 ImageFormat imageFormat;
93
94 Common::Rect rect;
95 Common::Point registrationPoint;
96 uint16 bitsPerPixel;
97 uint32 codecID;
98 uint32 encodingFlags;
99
102 Common::Array<uint8> codecData;
103};
104
106public:
107 CachedMToon();
108
109 bool loadFromStream(const Common::SharedPtr<MToonMetadata> &metadata, Common::ReadStream *stream, size_t size, uint hackFlags);
110
111 void optimize(Runtime *runtime);
112
113 void getOrRenderFrame(uint32 prevFrame, uint32 targetFrame, Common::SharedPtr<Graphics::ManagedSurface> &surface) const;
114 const Common::SharedPtr<MToonMetadata> &getMetadata() const;
115
116private:
117 void optimizeNonTemporal(const Graphics::PixelFormat &targetFormat);
118 void optimizeRLE(const Graphics::PixelFormat &targetFormat);
119
120 struct RleFrame {
121 RleFrame();
122
123 uint32 version;
124 uint32 width;
125 uint32 height;
126 bool isKeyframe;
130 };
131
132 static const uint32 kMToonRLECodecID = 0x2e524c45;
133 static const uint32 kMToonRLEKeyframePrefix = 0x524c4520;
134 static const uint32 kMToonRLETemporalFramePrefix = 1;
135
136 void decompressFrames(const Common::Array<uint8> &data);
137 void decompressRLEFrameToImage(size_t frameIndex, Graphics::ManagedSurface &surface);
138 void loadRLEFrames(const Common::Array<uint8> &data);
139 void decompressRLEFrame(size_t frameIndex);
140 void loadUncompressedFrame(const Common::Array<uint8> &data, size_t frameIndex);
141 void decompressQuickTimeFrame(const Common::Array<uint8> &data, size_t frameIndex);
142
143 template<class TSrcNumber, uint32 TSrcLiteralMask, uint32 TSrcTransparentSkipMask, class TDestNumber, uint32 TDestLiteralMask, uint32 TDestTransparentSkipMask>
144 void rleReformat(RleFrame &frame, const Common::Array<TSrcNumber> &srcData, const Graphics::PixelFormat &srcFormatRef, Common::Array<TDestNumber> &destData, const Graphics::PixelFormat &destFormatRef, uint hackFlags);
145
146 template<class TNumber, uint32 TLiteralMask, uint32 TTransparentRowSkipMask>
147 static bool decompressMToonRLE(const RleFrame &frame, const Common::Array<TNumber> &coefsArray, Graphics::ManagedSurface &surface, bool isBottomUp, bool isKeyFrame, uint hackFlags);
148
149 template<class TDest, class TSrc>
150 static void checkedMemCpy(Common::Array<TDest> &dest, size_t destIndex, const Common::Array<TSrc> &src, size_t srcIndex, size_t sizeBytes);
151
153 bool _isRLETemporalCompressed;
154
157
158 Graphics::PixelFormat _rleInternalFormat;
159 Graphics::PixelFormat _rleOptimizedFormat;
160
162
163 uint _hackFlags;
164};
165
167 struct CuePoint {
168 uint32 position;
169 uint32 cuePointID;
170 };
171
172 enum Encoding {
173 kEncodingUncompressed,
174 kEncodingMace3,
175 kEncodingMace6,
176 };
177
179
180 Encoding encoding;
181 uint32 durationMSec;
182 uint16 sampleRate;
183 uint8 channels;
184 uint8 bitsPerSample;
185 bool isBigEndian;
186
187 Common::Array<CuePoint> cuePoints;
188};
189
190class AudioAsset : public Asset {
191public:
192 bool load(AssetLoaderContext &context, const Data::AudioAsset &data);
193 AssetType getAssetType() const override;
194
195 size_t getStreamIndex() const;
196 const Common::SharedPtr<AudioMetadata> &getMetadata() const;
197
198 const Common::SharedPtr<CachedAudio> &loadAndCacheAudio(Runtime *runtime);
199
200private:
201 uint32 _filePosition;
202 uint32 _size;
203
204 size_t _streamIndex;
205
208};
209
210class MovieAsset : public Asset {
211public:
212 bool load(AssetLoaderContext &context, const Data::MovieAsset &data);
213 AssetType getAssetType() const override;
214
215 uint32 getMovieDataPos() const;
216 uint32 getMoovAtomPos() const;
217 uint32 getMovieDataSize() const;
218
219 const Common::String &getExtFileName() const;
220 size_t getStreamIndex() const;
221
222 void addDamagedFrame(int frame);
223 const Common::Array<int> &getDamagedFrames() const;
224
225private:
226 uint32 _movieDataPos;
227 uint32 _moovAtomPos;
228 uint32 _movieDataSize;
229
230 Common::String _extFileName;
231 size_t _streamIndex;
232
233 Common::Array<int> _damagedFrames;
234};
235
236class AVIMovieAsset : public Asset {
237public:
238 bool load(AssetLoaderContext &context, const Data::AVIMovieAsset &data);
239 AssetType getAssetType() const override;
240
241 const Common::String &getExtFileName() const;
242
243private:
244 Common::String _extFileName;
245};
246
248public:
249 CachedImage();
250
252
253 void resetSurface(ColorDepthMode colorDepth, const Common::SharedPtr<Graphics::ManagedSurface> &surface);
254
255 ColorDepthMode getOriginalColorDepth() const;
256
257private:
260
261 ColorDepthMode _colorDepth;
262};
263
264class ImageAsset : public Asset {
265public:
266 ImageAsset();
267 ~ImageAsset();
268
269 bool load(AssetLoaderContext &context, const Data::ImageAsset &data);
270 AssetType getAssetType() const override;
271
272 enum ImageFormat {
273 kImageFormatMac,
274 kImageFormatWindows,
275 };
276
277 const Common::Rect &getRect() const;
278 ColorDepthMode getColorDepth() const;
279 uint32 getFilePosition() const;
280 uint32 getSize() const;
281 size_t getStreamIndex() const;
282 ImageFormat getImageFormat() const;
283
284 const Common::SharedPtr<CachedImage> &loadAndCacheImage(Runtime *runtime);
285
286private:
287 Common::Rect _rect;
288 ColorDepthMode _colorDepth;
289 uint32 _filePosition;
290 uint32 _size;
291 size_t _streamIndex;
292 ImageFormat _imageFormat;
293
295};
296
297
298struct MToonAsset : public Asset {
299public:
300 MToonAsset();
301
302 bool load(AssetLoaderContext &context, const Data::MToonAsset &data);
303 AssetType getAssetType() const override;
304
305 const Common::SharedPtr<CachedMToon> &loadAndCacheMToon(Runtime *runtime, uint hackFlags);
306
307private:
308 uint32 _frameDataPosition;
309 uint32 _sizeOfFrameData;
310 size_t _streamIndex;
311
314};
315
316class TextAsset : public Asset {
317public:
318 TextAsset();
319
320 bool load(AssetLoaderContext &context, const Data::TextAsset &data);
321 AssetType getAssetType() const override;
322
323 bool isBitmap() const;
324 const Common::SharedPtr<Graphics::ManagedSurface> &getBitmapSurface() const;
325 const Common::String &getString() const;
326 const Common::Array<MacFormattingSpan> &getMacFormattingSpans() const;
327
328private:
329 Common::Rect _bitmapRect;
330 TextAlignment _alignment;
331 bool _isBitmap;
332
334 Common::String _stringData;
335
336 Common::Array<MacFormattingSpan> _macFormattingSpans;
337};
338
339} // End of namespace MTropolis
340
341#endif
Definition: stream.h:385
Definition: ptr.h:159
Definition: str.h:59
Definition: managed_surface.h:51
Definition: assets.h:236
Definition: runtime.h:3182
Definition: assets.h:190
Definition: assets.h:47
Definition: assets.h:247
Definition: assets.h:105
Definition: assets.h:36
Definition: assets.h:264
Definition: assets.h:210
Definition: runtime.h:1575
Definition: assets.h:316
Definition: actions.h:25
Definition: rect.h:144
Definition: rect.h:536
Definition: pixelformat.h:138
Definition: asset_factory.h:31
Definition: assets.h:167
Definition: assets.h:166
Definition: runtime.h:469
Definition: data.h:1993
Definition: data.h:2008
Definition: data.h:1937
Definition: data.h:2065
Definition: data.h:2106
Definition: data.h:1952
Definition: data.h:2229
Definition: assets.h:298
Definition: assets.h:68
Definition: assets.h:62