/* 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 . * */ #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 _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 frames; Common::Array frameRanges; Common::Array codecData; }; class CachedMToon { public: CachedMToon(); bool loadFromStream(const Common::SharedPtr &metadata, Common::ReadStream *stream, size_t size, uint hackFlags); void optimize(Runtime *runtime); void getOrRenderFrame(uint32 prevFrame, uint32 targetFrame, Common::SharedPtr &surface) const; const Common::SharedPtr &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 data8; Common::Array data16; Common::Array data32; }; static const uint32 kMToonRLECodecID = 0x2e524c45; static const uint32 kMToonRLEKeyframePrefix = 0x524c4520; static const uint32 kMToonRLETemporalFramePrefix = 1; void decompressFrames(const Common::Array &data); void decompressRLEFrameToImage(size_t frameIndex, Graphics::ManagedSurface &surface); void loadRLEFrames(const Common::Array &data); void decompressRLEFrame(size_t frameIndex); void loadUncompressedFrame(const Common::Array &data, size_t frameIndex); void decompressQuickTimeFrame(const Common::Array &data, size_t frameIndex); template void rleReformat(RleFrame &frame, const Common::Array &srcData, const Graphics::PixelFormat &srcFormatRef, Common::Array &destData, const Graphics::PixelFormat &destFormatRef, uint hackFlags); template static bool decompressMToonRLE(const RleFrame &frame, const Common::Array &coefsArray, Graphics::ManagedSurface &surface, bool isBottomUp, bool isKeyFrame, uint hackFlags); template static void checkedMemCpy(Common::Array &dest, size_t destIndex, const Common::Array &src, size_t srcIndex, size_t sizeBytes); Common::Array _rleData; bool _isRLETemporalCompressed; Common::Array > _decompressedFrames; Common::Array > _optimizedFrames; Graphics::PixelFormat _rleInternalFormat; Graphics::PixelFormat _rleOptimizedFormat; Common::SharedPtr _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 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 &getMetadata() const; const Common::SharedPtr &loadAndCacheAudio(Runtime *runtime); private: uint32 _filePosition; uint32 _size; size_t _streamIndex; Common::SharedPtr _audioCache; Common::SharedPtr _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 &getDamagedFrames() const; private: uint32 _movieDataPos; uint32 _moovAtomPos; uint32 _movieDataSize; Common::String _extFileName; size_t _streamIndex; Common::Array _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 &optimize(Runtime *runtime); void resetSurface(ColorDepthMode colorDepth, const Common::SharedPtr &surface); ColorDepthMode getOriginalColorDepth() const; private: Common::SharedPtr _surface; Common::SharedPtr _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 &loadAndCacheImage(Runtime *runtime); private: Common::Rect _rect; ColorDepthMode _colorDepth; uint32 _filePosition; uint32 _size; size_t _streamIndex; ImageFormat _imageFormat; Common::SharedPtr _imageCache; }; struct MToonAsset : public Asset { public: MToonAsset(); bool load(AssetLoaderContext &context, const Data::MToonAsset &data); AssetType getAssetType() const override; const Common::SharedPtr &loadAndCacheMToon(Runtime *runtime, uint hackFlags); private: uint32 _frameDataPosition; uint32 _sizeOfFrameData; size_t _streamIndex; Common::SharedPtr _metadata; Common::SharedPtr _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 &getBitmapSurface() const; const Common::String &getString() const; const Common::Array &getMacFormattingSpans() const; private: Common::Rect _bitmapRect; TextAlignment _alignment; bool _isBitmap; Common::SharedPtr _bitmapData; Common::String _stringData; Common::Array _macFormattingSpans; }; } // End of namespace MTropolis #endif