2019-03-05 18:28:12 +00:00
|
|
|
/* 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.
|
|
|
|
*
|
2021-12-26 17:47:58 +00:00
|
|
|
* 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.
|
2019-03-05 18:28:12 +00:00
|
|
|
*
|
|
|
|
* 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
|
2021-12-26 17:47:58 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2019-03-05 18:28:12 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2021-04-06 17:09:03 +00:00
|
|
|
#ifndef VIDEO_HNM_DECODER_H
|
|
|
|
#define VIDEO_HNM_DECODER_H
|
2019-03-05 18:28:12 +00:00
|
|
|
|
2022-08-29 16:34:25 +00:00
|
|
|
#include "audio/audiostream.h"
|
2019-03-05 18:28:12 +00:00
|
|
|
#include "common/rational.h"
|
|
|
|
#include "graphics/surface.h"
|
2022-08-29 16:34:25 +00:00
|
|
|
#include "video/video_decoder.h"
|
|
|
|
|
|
|
|
|
|
|
|
namespace Audio {
|
|
|
|
class APCStream;
|
|
|
|
}
|
2019-03-05 18:28:12 +00:00
|
|
|
|
|
|
|
namespace Common {
|
|
|
|
class SeekableReadStream;
|
|
|
|
}
|
|
|
|
|
2022-08-29 16:34:25 +00:00
|
|
|
namespace Image {
|
|
|
|
class HNM6Decoder;
|
|
|
|
}
|
|
|
|
|
2019-03-05 18:28:12 +00:00
|
|
|
namespace Video {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decoder for HNM videos.
|
|
|
|
*
|
|
|
|
* Video decoder used in engines:
|
2021-04-07 00:24:49 +00:00
|
|
|
* - cryo
|
2019-03-05 18:28:12 +00:00
|
|
|
* - cryomni3d
|
|
|
|
*/
|
|
|
|
class HNMDecoder : public VideoDecoder {
|
|
|
|
public:
|
2022-08-29 16:34:25 +00:00
|
|
|
HNMDecoder(const Graphics::PixelFormat &format, bool loop = false, byte *initialPalette = nullptr);
|
2020-02-09 11:05:28 +00:00
|
|
|
~HNMDecoder() override;
|
|
|
|
bool loadStream(Common::SeekableReadStream *stream) override;
|
|
|
|
void readNextPacket() override;
|
|
|
|
void close() override;
|
2019-03-05 18:28:12 +00:00
|
|
|
|
2022-01-12 07:50:40 +00:00
|
|
|
void setRegularFrameDelay(uint32 regularFrameDelay) { _regularFrameDelayMs = regularFrameDelay; }
|
2019-03-05 18:28:12 +00:00
|
|
|
|
|
|
|
private:
|
2022-01-08 10:58:03 +00:00
|
|
|
class HNMVideoTrack : public VideoTrack {
|
2019-03-05 18:28:12 +00:00
|
|
|
public:
|
2022-01-12 07:50:40 +00:00
|
|
|
HNMVideoTrack(uint32 frameCount, uint32 regularFrameDelayMs, uint32 audioSampleRate);
|
2019-03-05 18:28:12 +00:00
|
|
|
|
|
|
|
// When _frameCount is 0, it means we are looping
|
2020-02-09 11:05:28 +00:00
|
|
|
bool endOfTrack() const override { return (_frameCount == 0) ? false : VideoTrack::endOfTrack(); }
|
|
|
|
int getCurFrame() const override { return _curFrame; }
|
|
|
|
int getFrameCount() const override { return _frameCount; }
|
2022-01-12 07:50:40 +00:00
|
|
|
uint32 getNextFrameStartTime() const override { return _nextFrameStartTime.msecs(); }
|
2019-03-05 18:28:12 +00:00
|
|
|
|
2022-01-12 07:50:40 +00:00
|
|
|
void restart() { _lastFrameDelaySamps = 0; }
|
2019-03-05 18:28:12 +00:00
|
|
|
|
2022-08-29 16:34:25 +00:00
|
|
|
virtual void newFrame(uint32 frameDelay) = 0;
|
2022-01-09 10:50:27 +00:00
|
|
|
virtual void decodeChunk(byte *data, uint32 size,
|
2022-01-08 10:58:03 +00:00
|
|
|
uint16 chunkType, uint16 flags) = 0;
|
2019-03-05 18:28:12 +00:00
|
|
|
|
2022-01-08 10:58:03 +00:00
|
|
|
protected:
|
2022-01-12 07:50:40 +00:00
|
|
|
uint32 _regularFrameDelayMs;
|
|
|
|
uint32 _lastFrameDelaySamps;
|
|
|
|
Audio::Timestamp _nextFrameStartTime;
|
2019-03-05 18:28:12 +00:00
|
|
|
|
|
|
|
uint32 _frameCount;
|
|
|
|
int _curFrame;
|
2022-01-08 10:58:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class HNM45VideoTrack : public HNMVideoTrack {
|
|
|
|
public:
|
|
|
|
// When _frameCount is 0, it means we are looping
|
|
|
|
uint16 getWidth() const override { return _surface.w; }
|
|
|
|
uint16 getHeight() const override { return _surface.h; }
|
|
|
|
Graphics::PixelFormat getPixelFormat() const override { return _surface.format; }
|
|
|
|
const Graphics::Surface *decodeNextFrame() override { return &_surface; }
|
|
|
|
const byte *getPalette() const override { _dirtyPalette = false; return _palette; }
|
|
|
|
bool hasDirtyPalette() const override { return _dirtyPalette; }
|
|
|
|
|
2022-08-29 16:34:25 +00:00
|
|
|
virtual void newFrame(uint32 frameDelay) override;
|
|
|
|
|
2022-01-08 10:58:03 +00:00
|
|
|
protected:
|
|
|
|
HNM45VideoTrack(uint32 width, uint32 height, uint32 frameSize, uint32 frameCount,
|
2022-01-12 07:50:40 +00:00
|
|
|
uint32 regularFrameDelayMs, uint32 audioSampleRate,
|
|
|
|
const byte *initialPalette = nullptr);
|
2022-01-08 10:58:03 +00:00
|
|
|
~HNM45VideoTrack() override;
|
|
|
|
|
|
|
|
/** Decode a video chunk. */
|
2022-01-09 10:50:27 +00:00
|
|
|
void decodePalette(byte *data, uint32 size);
|
2022-01-08 10:58:03 +00:00
|
|
|
|
|
|
|
Graphics::Surface _surface;
|
2019-03-05 18:28:12 +00:00
|
|
|
|
|
|
|
byte _palette[256 * 3];
|
|
|
|
mutable bool _dirtyPalette;
|
|
|
|
|
|
|
|
byte *_frameBufferC;
|
|
|
|
byte *_frameBufferP;
|
|
|
|
};
|
|
|
|
|
2022-01-08 10:58:03 +00:00
|
|
|
class HNM4VideoTrack : public HNM45VideoTrack {
|
|
|
|
public:
|
|
|
|
HNM4VideoTrack(uint32 width, uint32 height, uint32 frameSize, uint32 frameCount,
|
2022-01-12 07:50:40 +00:00
|
|
|
uint32 regularFrameDelayMs, uint32 audioSampleRate,
|
|
|
|
const byte *initialPalette = nullptr);
|
2022-01-08 10:58:03 +00:00
|
|
|
~HNM4VideoTrack() override;
|
|
|
|
|
|
|
|
/** Decode a video chunk. */
|
2022-01-09 10:50:27 +00:00
|
|
|
void decodeChunk(byte *data, uint32 size,
|
2022-01-08 10:58:03 +00:00
|
|
|
uint16 chunkType, uint16 flags) override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/* Really decode */
|
2022-01-09 10:50:27 +00:00
|
|
|
void decodeInterframe(byte *data, uint32 size);
|
|
|
|
void decodeInterframeA(byte *data, uint32 size);
|
|
|
|
void decodeIntraframe(byte *data, uint32 size);
|
2022-01-08 10:58:03 +00:00
|
|
|
void presentFrame(uint16 flags);
|
|
|
|
|
|
|
|
byte *_frameBufferF;
|
|
|
|
};
|
|
|
|
|
|
|
|
class HNM5VideoTrack : public HNM45VideoTrack {
|
|
|
|
public:
|
|
|
|
HNM5VideoTrack(uint32 width, uint32 height, uint32 frameSize, uint32 frameCount,
|
2022-01-12 07:50:40 +00:00
|
|
|
uint32 regularFrameDelayMs, uint32 audioSampleRate,
|
|
|
|
const byte *initialPalette = nullptr) :
|
|
|
|
HNM45VideoTrack(width, height, frameSize, frameCount, regularFrameDelayMs, audioSampleRate,
|
|
|
|
initialPalette) {}
|
2022-01-08 10:58:03 +00:00
|
|
|
/** Decode a video chunk. */
|
2022-01-09 10:50:27 +00:00
|
|
|
void decodeChunk(byte *data, uint32 size,
|
2022-01-08 10:58:03 +00:00
|
|
|
uint16 chunkType, uint16 flags) override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/** Really decode */
|
2022-01-09 10:50:27 +00:00
|
|
|
void decodeFrame(byte *data, uint32 size);
|
2022-01-08 10:58:03 +00:00
|
|
|
};
|
|
|
|
|
2022-08-29 16:34:25 +00:00
|
|
|
class HNM6VideoTrack : public HNMVideoTrack {
|
|
|
|
public:
|
|
|
|
HNM6VideoTrack(uint32 width, uint32 height, uint32 frameSize, uint32 frameCount,
|
|
|
|
uint32 regularFrameDelayMs, uint32 audioSampleRate,
|
|
|
|
const Graphics::PixelFormat &format);
|
|
|
|
~HNM6VideoTrack() override;
|
|
|
|
|
|
|
|
uint16 getWidth() const override;
|
|
|
|
uint16 getHeight() const override;
|
|
|
|
Graphics::PixelFormat getPixelFormat() const override;
|
2023-02-23 00:14:01 +00:00
|
|
|
bool setOutputPixelFormat(const Graphics::PixelFormat &format) override;
|
2022-08-29 16:34:25 +00:00
|
|
|
const Graphics::Surface *decodeNextFrame() override { return _surface; }
|
|
|
|
|
|
|
|
virtual void newFrame(uint32 frameDelay) override;
|
|
|
|
/** Decode a video chunk. */
|
|
|
|
void decodeChunk(byte *data, uint32 size,
|
|
|
|
uint16 chunkType, uint16 flags) override;
|
|
|
|
private:
|
|
|
|
Image::HNM6Decoder *_decoder;
|
|
|
|
const Graphics::Surface *_surface;
|
|
|
|
};
|
|
|
|
|
|
|
|
class HNMAudioTrack : public AudioTrack {
|
|
|
|
public:
|
|
|
|
HNMAudioTrack(Audio::Mixer::SoundType soundType) : AudioTrack(soundType) {}
|
|
|
|
|
|
|
|
virtual uint32 decodeSound(uint16 chunkType, byte *data, uint32 size) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DPCMAudioTrack : public HNMAudioTrack {
|
2019-03-05 18:28:12 +00:00
|
|
|
public:
|
2021-10-04 11:47:28 +00:00
|
|
|
DPCMAudioTrack(uint16 format, uint16 bits, uint sampleRate, bool stereo,
|
2019-03-05 18:28:12 +00:00
|
|
|
Audio::Mixer::SoundType soundType);
|
2020-02-09 11:05:28 +00:00
|
|
|
~DPCMAudioTrack() override;
|
2019-03-05 18:28:12 +00:00
|
|
|
|
2022-08-29 16:34:25 +00:00
|
|
|
uint32 decodeSound(uint16 chunkType, byte *data, uint32 size) override;
|
2019-03-05 18:28:12 +00:00
|
|
|
protected:
|
2020-02-09 11:05:28 +00:00
|
|
|
Audio::AudioStream *getAudioStream() const override { return _audioStream; }
|
2019-03-05 18:28:12 +00:00
|
|
|
private:
|
|
|
|
Audio::QueuingAudioStream *_audioStream;
|
|
|
|
bool _gotLUT;
|
|
|
|
uint16 _lut[256];
|
2022-01-08 20:49:19 +00:00
|
|
|
uint16 _lastSampleL;
|
|
|
|
uint16 _lastSampleR;
|
2021-10-04 11:47:28 +00:00
|
|
|
uint _sampleRate;
|
|
|
|
bool _stereo;
|
2019-03-05 18:28:12 +00:00
|
|
|
};
|
|
|
|
|
2022-08-29 16:34:25 +00:00
|
|
|
class APCAudioTrack : public HNMAudioTrack {
|
|
|
|
public:
|
|
|
|
APCAudioTrack(uint sampleRate, byte stereo,
|
|
|
|
Audio::Mixer::SoundType soundType);
|
|
|
|
~APCAudioTrack() override;
|
|
|
|
|
|
|
|
uint32 decodeSound(uint16 chunkType, byte *data, uint32 size) override;
|
|
|
|
protected:
|
|
|
|
Audio::AudioStream *getAudioStream() const override;
|
|
|
|
private:
|
|
|
|
Audio::APCStream *_audioStream;
|
|
|
|
};
|
|
|
|
|
|
|
|
Graphics::PixelFormat _format;
|
2019-03-05 18:28:12 +00:00
|
|
|
bool _loop;
|
2019-05-20 18:49:01 +00:00
|
|
|
byte *_initialPalette;
|
2019-03-05 18:28:12 +00:00
|
|
|
|
2022-01-12 07:50:40 +00:00
|
|
|
uint32 _regularFrameDelayMs;
|
2019-03-05 18:28:12 +00:00
|
|
|
// These two pointer are owned by VideoDecoder
|
2022-01-08 10:58:03 +00:00
|
|
|
HNMVideoTrack *_videoTrack;
|
2022-08-29 16:34:25 +00:00
|
|
|
HNMAudioTrack *_audioTrack;
|
2019-03-05 18:28:12 +00:00
|
|
|
|
|
|
|
Common::SeekableReadStream *_stream;
|
2022-08-29 16:34:25 +00:00
|
|
|
bool _alignedChunks;
|
2022-01-09 10:50:27 +00:00
|
|
|
byte *_dataBuffer;
|
|
|
|
uint32 _dataBufferAlloc;
|
2019-03-05 18:28:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // End of namespace Video
|
|
|
|
|
|
|
|
#endif
|