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