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