ScummVM API documentation
mve_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_MVEDECODER_H
23 #define VIDEO_MVEDECODER_H
24 
25 #include "audio/audiostream.h"
26 #include "video/video_decoder.h"
27 #include "graphics/surface.h"
28 #include "common/list.h"
29 #include "common/rect.h"
30 #include "common/memstream.h"
31 
32 namespace Common {
33 class SeekableReadStream;
34 }
35 
36 namespace Graphics {
37 struct PixelFormat;
38 }
39 
40 class PaletteManager;
41 
42 namespace Video {
43 
51 class MveDecoder : public VideoDecoder {
52  bool _done;
54 
55  uint16 _packetLen;
56  uint16 _packetKind;
57 
58  Graphics::Surface _decodeSurface0;
59  Graphics::Surface _decodeSurface1;
60  Graphics::Surface _frameSurface;
61 
62  uint16 _widthInBlocks;
63  uint16 _heightInBlocks;
64 
65  uint16 _width;
66  uint16 _height;
67 
68  Common::Rational _frameRate;
69 
70  bool _trueColor;
71  Graphics::PixelFormat _pixelFormat;
72  bool _dirtyPalette;
73  uint16 _palStart;
74  uint16 _palCount;
75  byte _palette[0x300];
76 
77  uint16 _skipMapSize;
78  byte *_skipMap;
79 
80  uint16 _decodingMapSize;
81  byte *_decodingMap;
82 
83  int _frameNumber;
84  uint16 _frameSize;
85  byte *_frameData;
86 
87  int _audioTrack;
88  Audio::QueuingAudioStream *_audioStream;
89 
90  void readPacketHeader();
91  void copyBlock_8bit(Graphics::Surface &dst, Common::MemoryReadStream &s, int block);
92  void copyBlock_16bit(Graphics::Surface &dst, Common::MemoryReadStream &s, int block);
93  void copyBlock(Graphics::Surface &dst, Graphics::Surface &src, int block, int offset = 0);
94  void copyBlock(Graphics::Surface &dst, Graphics::Surface &src, int dx, int dy, int off_x, int off_y);
95 
96  void decodeFormat6();
97  void decodeFormat10();
98 
99  class MveVideoTrack : public FixedRateVideoTrack {
100  MveDecoder *_decoder;
101  public:
102  MveVideoTrack(MveDecoder *decoder);
103 
104  bool endOfTrack() const;
105 
106  uint16 getWidth() const;
107  uint16 getHeight() const;
108 
109  Graphics::PixelFormat getPixelFormat() const;
110 
111  int getCurFrame() const;
112  // int getFrameCount() const;
113 
114  const Graphics::Surface *decodeNextFrame();
115  const byte *getPalette() const;
116  bool hasDirtyPalette() const;
117 
118  protected:
119  Common::Rational getFrameRate() const;
120  };
121 
122  class MveAudioTrack : public AudioTrack {
123  MveDecoder *_decoder;
124  public:
125  MveAudioTrack(MveDecoder *decoder);
126 
127  Audio::AudioStream *getAudioStream() const;
128  };
129 
130  class MveSkipStream {
132  uint16 queue;
133  public:
134  MveSkipStream(byte *p, size_t sz)
135  : s(p, sz), queue(0x8000)
136  {}
137 
138  void reset() {
139  s.seek(0);
140  queue = 0x8000;
141  }
142 
143  bool skip() {
144  if (queue == 0x8000) {
145  queue = s.readUint16LE();
146  assert(queue != 0);
147  }
148  bool r = (queue & 0x8000) == 0;
149  queue <<= 1;
150  return r;
151  }
152  };
153 
154 public:
155  MveDecoder();
156  virtual ~MveDecoder();
157 
158  bool loadStream(Common::SeekableReadStream *stream);
159  void setAudioTrack(int track);
160  void applyPalette(PaletteManager *paletteManager);
161 
162  // const Common::List<Common::Rect> *getDirtyRects() const;
163  // void clearDirtyRects();
164  // void copyDirtyRectsToBuffer(uint8 *dst, uint pitch);
165 
166  Common::Rational getFrameRate() { return _frameRate; }
167  void readNextPacket();
168 };
169 
170 } // End of namespace Video
171 
172 #endif
uint16 readUint16LE()
Definition: stream.h:459
Definition: surface.h:67
Definition: video_decoder.h:686
Definition: pixelformat.h:138
Definition: mve_decoder.h:51
Definition: video_decoder.h:711
Definition: stream.h:745
Definition: rational.h:40
Definition: video_decoder.h:53
Definition: algorithm.h:29
Definition: formatinfo.h:28
Definition: audiostream.h:50
Definition: memstream.h:43
Definition: audiostream.h:370
bool seek(int64 offs, int whence=SEEK_SET)
Definition: avi_frames.h:36
Definition: paletteman.h:47