ScummVM API documentation
hnm_decoder.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 VIDEO_HNM_DECODER_H
23 #define VIDEO_HNM_DECODER_H
24 
25 #include "audio/audiostream.h"
26 #include "common/rational.h"
27 #include "graphics/surface.h"
28 #include "video/video_decoder.h"
29 
30 
31 namespace Audio {
32 class APCStream;
33 }
34 
35 namespace Common {
36 class SeekableReadStream;
37 }
38 
39 namespace Image {
40 class HNM6Decoder;
41 }
42 
43 namespace Video {
44 
52 class HNMDecoder : public VideoDecoder {
53 public:
54  HNMDecoder(const Graphics::PixelFormat &format, bool loop = false, byte *initialPalette = nullptr);
55  ~HNMDecoder() override;
56  bool loadStream(Common::SeekableReadStream *stream) override;
57  void readNextPacket() override;
58  void close() override;
59 
60  void setRegularFrameDelay(uint32 regularFrameDelay) { _regularFrameDelayMs = regularFrameDelay; }
61 
62 private:
63  class HNMVideoTrack : public VideoTrack {
64  public:
65  HNMVideoTrack(uint32 frameCount, uint32 regularFrameDelayMs, uint32 audioSampleRate);
66 
67  // When _frameCount is 0, it means we are looping
68  bool endOfTrack() const override { return (_frameCount == 0) ? false : VideoTrack::endOfTrack(); }
69  int getCurFrame() const override { return _curFrame; }
70  int getFrameCount() const override { return _frameCount; }
71  uint32 getNextFrameStartTime() const override { return _nextFrameStartTime.msecs(); }
72 
73  void restart() { _lastFrameDelaySamps = 0; }
74 
75  virtual void newFrame(uint32 frameDelay) = 0;
76  virtual void decodeChunk(byte *data, uint32 size,
77  uint16 chunkType, uint16 flags) = 0;
78 
79  protected:
80  uint32 _regularFrameDelayMs;
81  uint32 _lastFrameDelaySamps;
82  Audio::Timestamp _nextFrameStartTime;
83 
84  uint32 _frameCount;
85  int _curFrame;
86  };
87 
88  class HNM45VideoTrack : public HNMVideoTrack {
89  public:
90  // When _frameCount is 0, it means we are looping
91  uint16 getWidth() const override { return _surface.w; }
92  uint16 getHeight() const override { return _surface.h; }
93  Graphics::PixelFormat getPixelFormat() const override { return _surface.format; }
94  const Graphics::Surface *decodeNextFrame() override { return &_surface; }
95  const byte *getPalette() const override { _dirtyPalette = false; return _palette; }
96  bool hasDirtyPalette() const override { return _dirtyPalette; }
97 
98  virtual void newFrame(uint32 frameDelay) override;
99 
100  protected:
101  HNM45VideoTrack(uint32 width, uint32 height, uint32 frameSize, uint32 frameCount,
102  uint32 regularFrameDelayMs, uint32 audioSampleRate,
103  const byte *initialPalette = nullptr);
104  ~HNM45VideoTrack() override;
105 
107  void decodePalette(byte *data, uint32 size);
108 
109  Graphics::Surface _surface;
110 
111  byte _palette[256 * 3];
112  mutable bool _dirtyPalette;
113 
114  byte *_frameBufferC;
115  byte *_frameBufferP;
116  };
117 
118  class HNM4VideoTrack : public HNM45VideoTrack {
119  public:
120  HNM4VideoTrack(uint32 width, uint32 height, uint32 frameSize, uint32 frameCount,
121  uint32 regularFrameDelayMs, uint32 audioSampleRate,
122  const byte *initialPalette = nullptr);
123  ~HNM4VideoTrack() override;
124 
126  void decodeChunk(byte *data, uint32 size,
127  uint16 chunkType, uint16 flags) override;
128 
129  protected:
130  /* Really decode */
131  void decodeInterframe(byte *data, uint32 size);
132  void decodeInterframeA(byte *data, uint32 size);
133  void decodeIntraframe(byte *data, uint32 size);
134  void presentFrame(uint16 flags);
135 
136  byte *_frameBufferF;
137  };
138 
139  class HNM5VideoTrack : public HNM45VideoTrack {
140  public:
141  HNM5VideoTrack(uint32 width, uint32 height, uint32 frameSize, uint32 frameCount,
142  uint32 regularFrameDelayMs, uint32 audioSampleRate,
143  const byte *initialPalette = nullptr) :
144  HNM45VideoTrack(width, height, frameSize, frameCount, regularFrameDelayMs, audioSampleRate,
145  initialPalette) {}
147  void decodeChunk(byte *data, uint32 size,
148  uint16 chunkType, uint16 flags) override;
149 
150  protected:
152  void decodeFrame(byte *data, uint32 size);
153  };
154 
155  class HNM6VideoTrack : public HNMVideoTrack {
156  public:
157  HNM6VideoTrack(uint32 width, uint32 height, uint32 frameSize, uint32 frameCount,
158  uint32 regularFrameDelayMs, uint32 audioSampleRate,
159  const Graphics::PixelFormat &format);
160  ~HNM6VideoTrack() override;
161 
162  uint16 getWidth() const override;
163  uint16 getHeight() const override;
164  Graphics::PixelFormat getPixelFormat() const override;
165  bool setOutputPixelFormat(const Graphics::PixelFormat &format) override;
166  const Graphics::Surface *decodeNextFrame() override { return _surface; }
167 
168  virtual void newFrame(uint32 frameDelay) override;
170  void decodeChunk(byte *data, uint32 size,
171  uint16 chunkType, uint16 flags) override;
172  private:
173  Image::HNM6Decoder *_decoder;
174  const Graphics::Surface *_surface;
175  };
176 
177  class HNMAudioTrack : public AudioTrack {
178  public:
179  HNMAudioTrack(Audio::Mixer::SoundType soundType) : AudioTrack(soundType) {}
180 
181  virtual uint32 decodeSound(uint16 chunkType, byte *data, uint32 size) = 0;
182  };
183 
184  class DPCMAudioTrack : public HNMAudioTrack {
185  public:
186  DPCMAudioTrack(uint16 format, uint16 bits, uint sampleRate, bool stereo,
187  Audio::Mixer::SoundType soundType);
188  ~DPCMAudioTrack() override;
189 
190  uint32 decodeSound(uint16 chunkType, byte *data, uint32 size) override;
191  protected:
192  Audio::AudioStream *getAudioStream() const override { return _audioStream; }
193  private:
194  Audio::QueuingAudioStream *_audioStream;
195  bool _gotLUT;
196  uint16 _lut[256];
197  uint16 _lastSampleL;
198  uint16 _lastSampleR;
199  uint _sampleRate;
200  bool _stereo;
201  };
202 
203  class APCAudioTrack : public HNMAudioTrack {
204  public:
205  APCAudioTrack(uint sampleRate, byte stereo,
206  Audio::Mixer::SoundType soundType);
207  ~APCAudioTrack() override;
208 
209  uint32 decodeSound(uint16 chunkType, byte *data, uint32 size) override;
210  protected:
211  Audio::AudioStream *getAudioStream() const override;
212  private:
213  Audio::APCStream *_audioStream;
214  };
215 
216  Graphics::PixelFormat _format;
217  bool _loop;
218  byte *_initialPalette;
219 
220  uint32 _regularFrameDelayMs;
221  // These two pointer are owned by VideoDecoder
222  HNMVideoTrack *_videoTrack;
223  HNMAudioTrack *_audioTrack;
224 
226  bool _alignedChunks;
227  byte *_dataBuffer;
228  uint32 _dataBufferAlloc;
229 };
230 
231 } // End of namespace Video
232 
233 #endif
Definition: surface.h:67
Definition: pixelformat.h:138
Definition: video_decoder.h:711
Definition: timestamp.h:83
Definition: stream.h:745
Definition: apc.h:34
SoundType
Definition: mixer.h:62
Definition: video_decoder.h:53
Definition: hnm_decoder.h:52
Definition: algorithm.h:29
Definition: audiostream.h:50
Definition: audiostream.h:370
Definition: avi_frames.h:36
Definition: movie_decoder.h:32
Definition: system.h:38
Definition: video_decoder.h:577
Definition: hnm.h:34