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 
29 namespace MTropolis {
30 
31 struct AssetLoaderContext;
32 struct AudioMetadata;
33 struct MToonMetadata;
34 class AudioPlayer;
35 
36 class ColorTableAsset : public Asset {
37 public:
38  bool load(AssetLoaderContext &context, const Data::ColorTableAsset &data);
39  AssetType getAssetType() const override;
40 
41  const ColorRGB8 *getColors() const;
42 
43 private:
44  ColorRGB8 _colors[256];
45 };
46 
47 class CachedAudio {
48 public:
49  CachedAudio();
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 
58 private:
60 };
61 
62 struct MToonMetadata {
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 
80  struct FrameRangeDef {
81  uint32 startFrame;
82  uint32 endFrame;
83 
84  Common::String name;
85 
86  FrameRangeDef();
87  bool load(AssetLoaderContext &context, const Data::MToonAsset::FrameRangeDef &data);
88  };
89 
90  MToonMetadata();
91 
92  ImageFormat imageFormat;
93 
94  Common::Rect rect;
95  Common::Point registrationPoint;
96  uint16 bitsPerPixel;
97  uint32 codecID;
98  uint32 encodingFlags;
99 
101  Common::Array<FrameRangeDef> frameRanges;
102  Common::Array<uint8> codecData;
103 };
104 
105 class CachedMToon {
106 public:
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 
116 private:
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;
127  Common::Array<uint8> data8;
128  Common::Array<uint16> data16;
129  Common::Array<uint32> data32;
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 
152  Common::Array<RleFrame> _rleData;
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 
178  AudioMetadata();
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 
190 class AudioAsset : public Asset {
191 public:
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 
200 private:
201  uint32 _filePosition;
202  uint32 _size;
203 
204  size_t _streamIndex;
205 
206  Common::SharedPtr<CachedAudio> _audioCache;
208 };
209 
210 class MovieAsset : public Asset {
211 public:
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 
225 private:
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 
236 class AVIMovieAsset : public Asset {
237 public:
238  bool load(AssetLoaderContext &context, const Data::AVIMovieAsset &data);
239  AssetType getAssetType() const override;
240 
241  const Common::String &getExtFileName() const;
242 
243 private:
244  Common::String _extFileName;
245 };
246 
247 class CachedImage {
248 public:
249  CachedImage();
250 
251  const Common::SharedPtr<Graphics::ManagedSurface> &optimize(Runtime *runtime);
252 
253  void resetSurface(ColorDepthMode colorDepth, const Common::SharedPtr<Graphics::ManagedSurface> &surface);
254 
255  ColorDepthMode getOriginalColorDepth() const;
256 
257 private:
260 
261  ColorDepthMode _colorDepth;
262 };
263 
264 class ImageAsset : public Asset {
265 public:
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 
286 private:
287  Common::Rect _rect;
288  ColorDepthMode _colorDepth;
289  uint32 _filePosition;
290  uint32 _size;
291  size_t _streamIndex;
292  ImageFormat _imageFormat;
293 
294  Common::SharedPtr<CachedImage> _imageCache;
295 };
296 
297 
298 struct MToonAsset : public Asset {
299 public:
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 
307 private:
308  uint32 _frameDataPosition;
309  uint32 _sizeOfFrameData;
310  size_t _streamIndex;
311 
313  Common::SharedPtr<CachedMToon> _cachedMToon;
314 };
315 
316 class TextAsset : public Asset {
317 public:
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 
328 private:
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: managed_surface.h:51
Definition: assets.h:167
Definition: assets.h:68
Definition: str.h:59
Definition: runtime.h:469
Definition: assets.h:247
Definition: data.h:2093
Definition: pixelformat.h:138
Definition: data.h:1980
Definition: data.h:1924
Definition: rect.h:144
Definition: runtime.h:1594
Definition: assets.h:62
Definition: assets.h:264
Definition: runtime.h:3182
Definition: assets.h:190
Definition: rect.h:45
Definition: data.h:1939
Definition: assets.h:316
Definition: assets.h:166
Definition: assets.h:36
Definition: assets.h:47
Definition: actions.h:25
Definition: data.h:2052
Definition: stream.h:385
Definition: assets.h:236
Definition: asset_factory.h:31
Definition: ptr.h:159
Definition: data.h:2216
Definition: assets.h:105
Definition: assets.h:210
Definition: data.h:1995
Definition: assets.h:298