xoreos  0.0.5
xmvwmv2.h
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos 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 xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 /* Based on the WMV2 implementation in FFmpeg (<https://ffmpeg.org/)>,
26  * which is released under the terms of version 2 or later of the GNU
27  * Lesser General Public License.
28  *
29  * The original copyright notes in the file libavcodec/wmv2dec.c reads as follows:
30  *
31  * Copyright (c) 2002 The FFmpeg Project
32  *
33  * This file is part of FFmpeg.
34  *
35  * FFmpeg is free software; you can redistribute it and/or
36  * modify it under the terms of the GNU Lesser General Public
37  * License as published by the Free Software Foundation; either
38  * version 2.1 of the License, or (at your option) any later version.
39  *
40  * FFmpeg is distributed in the hope that it will be useful,
41  * but WITHOUT ANY WARRANTY; without even the implied warranty of
42  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
43  * Lesser General Public License for more details.
44  *
45  * You should have received a copy of the GNU Lesser General Public
46  * License along with FFmpeg; if not, write to the Free Software
47  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
48  */
49 
50 #ifndef VIDEO_CODECS_XMVWMV2_H
51 #define VIDEO_CODECS_XMVWMV2_H
52 
53 #include "src/common/types.h"
54 #include "src/common/scopedptr.h"
55 
56 #include "src/video/codecs/codec.h"
57 
58 namespace Common {
59  class BitStream;
60  class Huffman;
61 }
62 
63 namespace Video {
64 
65 struct WMV2ACCoefficientTable;
66 struct WMV2MVTable;
67 
68 class XMVWMV2Codec : public Codec {
69 public:
70  XMVWMV2Codec(uint32 width, uint32 height, Common::SeekableReadStream &extraData);
71  ~XMVWMV2Codec();
72 
73  void decodeFrame(Graphics::Surface &surface, Common::SeekableReadStream &dataStream);
74 
75 private:
76  static const uint32 kMacroBlockSize = 16;
77  static const uint32 kBlockSize = 8;
78 
80  class CBP {
81  public:
82  CBP(uint32 cbp = 0);
83 
84  void clear();
85 
86  bool empty() const;
87  bool isSet(int block) const;
88 
89  void set(int block, bool coded);
90 
91  void decode(uint32 cbp);
92  void decode(uint32 cbp, const CBP &topLeft, const CBP &top, const CBP &left);
93 
94  private:
96  };
97 
99  struct ACDecoder {
102  };
103 
105  struct MVDecoder {
108  };
109 
111  struct BlockContext {
112  const byte *refPlane;
114 
117 
119 
122 
124 
126 
129  };
130 
132  struct DecodeContext {
134 
138 
141 
143 
146 
149 
152 
155 
158 
160 
161 
163 
165  void setQScale(int32 qS);
166 
167  void startRow();
168  void finishRow();
169 
170  void startMacroBlock(uint32 cbp);
171  void finishMacroBlock();
172  };
173 
174 
175  // Dimensions
176 
179 
182 
185 
188 
189  // Color planes
190 
193 
194  // Decoder flags
195 
199  bool _hasJFrames;
202 
204 
205  // CBP
206 
209 
210  // DCT DC coefficients
211 
214 
215  // DCT AC coefficients
216 
218 
221 
222  // Motion vectors
223 
226 
228 
229 
231  void init();
232 
235 
236  void initDecodeContext(DecodeContext &ctx);
237 
238  // Frame type decoders
239 
241  void decodeIFrame(DecodeContext &ctx);
243  void decodeJFrame(DecodeContext &ctx);
245  void decodePFrame(DecodeContext &ctx);
246 
247  // Block decoders
248 
250  void decodeIMacroBlock(DecodeContext &ctx);
251 
253  void decodeIBlock(DecodeContext &ctx, BlockContext &block);
254 
256  static uint8 getTrit(Common::BitStream &bits);
257 
258  // IDCT
259 
260  void IDCTPut(byte *dest, int32 *block, uint32 pitch);
261  void IDCT(int32 *block);
262  void IDCTRow(int32 *b);
263  void IDCTCol(int32 *b);
264 };
265 
266 } // End of namespace Video
267 
268 #endif // VIDEO_CODECS_XMVWMV2_H
void decodeIMacroBlock(DecodeContext &ctx)
Decode an I-Frame (intra frame) macro block.
Definition: xmvwmv2.cpp:487
Parameters for decoding the motion vectors.
Definition: wmv2data.h:80
Common::ScopedPtr< Common::Huffman > _huffDC[2][2]
Huffman code for DCT DC coefficients, [luma/chroma][low/high motion].
Definition: xmvwmv2.h:213
Definition: 2dafile.h:39
uint32 _lumaHeight
Height of the luma portion of a decoded frame.
Definition: xmvwmv2.h:181
Common::ScopedPtr< Common::Huffman > _huffCBP[4]
Huffman codes for coded block pattern.
Definition: xmvwmv2.h:208
bool _hasLoopFilter
Does the video use the loop filter?
Definition: xmvwmv2.h:197
uint32 _height
Height of a frame.
Definition: xmvwmv2.h:178
Common::Huffman * huffDC[2]
Definition: xmvwmv2.h:145
uint8_t uint8
Definition: types.h:200
void decodePFrame(DecodeContext &ctx)
Decode a P-Frame (inter frame).
Definition: xmvwmv2.cpp:480
Parameters for decoding the DCT AC coefficients.
Definition: wmv2data.h:59
bool isSet(int block) const
Definition: xmvwmv2.cpp:92
static const uint32 kMacroBlockSize
Size of a macro block.
Definition: xmvwmv2.h:76
const WMV2ACCoefficientTable * parameters
Definition: xmvwmv2.h:101
Which block pattern are coded?
Definition: xmvwmv2.h:80
uint32 _lumaWidth
Width of the luma portion of a decoded frame.
Definition: xmvwmv2.h:180
Video codec base class.
void initDecodeContext(DecodeContext &ctx)
Definition: xmvwmv2.cpp:380
bool empty() const
Definition: xmvwmv2.cpp:88
Common::ScopedPtr< Common::Huffman > huffman
Definition: xmvwmv2.h:106
A simple scoped smart pointer template.
bool _hasJFrames
Does the video have j-frames (IntraX8)?
Definition: xmvwmv2.h:199
static uint8 getTrit(Common::BitStream &bits)
Decode a "tri-state".
Definition: xmvwmv2.cpp:805
MVDecoder _decoderMV[2]
Huffman code for the motion vectors [low/high motion].
Definition: xmvwmv2.h:225
Common::Huffman ** huffDC
Definition: xmvwmv2.h:121
int32 acQuantLeft[4][kBlockSize]
Definition: xmvwmv2.h:140
Common::BitStream & bits
Definition: xmvwmv2.h:133
void decodeIBlock(DecodeContext &ctx, BlockContext &block)
Decode an I-Frame (intra frame) block.
Definition: xmvwmv2.cpp:507
void setQScale(int32 qS)
Set the quantizer scale and calculate the DC step size and default predictor.
Definition: xmvwmv2.cpp:154
void IDCT(int32 *block)
Definition: xmvwmv2.cpp:735
void startMacroBlock(uint32 cbp)
Definition: xmvwmv2.cpp:209
Decode a Huffman&#39;d bitstream.
Definition: huffman.h:47
Common::ScopedArray< int32 > _predAC[3]
AC predictors, previous row.
Definition: xmvwmv2.h:217
void decodeIFrame(DecodeContext &ctx)
Decode an I-Frame (intra frame).
Definition: xmvwmv2.cpp:409
uint32 _width
Width of a frame.
Definition: xmvwmv2.h:177
XMVWMV2Codec(uint32 width, uint32 height, Common::SeekableReadStream &extraData)
Definition: xmvwmv2.cpp:228
Low-level type definitions to handle fixed width types portably.
Context for decoding a block.
Definition: xmvwmv2.h:111
CBP(uint32 cbp=0)
Definition: xmvwmv2.cpp:80
void parseExtraData(Common::SeekableReadStream &extraData)
Parse the extra data containing video encoding properties.
Definition: xmvwmv2.cpp:355
Common::ScopedArray< CBP > _cbp
Coded block pattern, previous row.
Definition: xmvwmv2.h:207
bool _hasACPerMacroBlock
Are the AC selected per macro block instead of per frame?
Definition: xmvwmv2.h:201
DecodeContext(Common::BitStream &b)
Definition: xmvwmv2.cpp:120
void decodeJFrame(DecodeContext &ctx)
Decode a J-Frame (intra X8 frame).
Definition: xmvwmv2.cpp:471
Common::ScopedArray< byte > _curPlanes[3]
The 3 color planes, YUV, current frame.
Definition: xmvwmv2.h:191
ACDecoder _decoderAC[2][3]
Decoders for DCT AC coefficients [luma/chroma][low motion/high motion/MPEG4].
Definition: xmvwmv2.h:220
uint32 _mbCountWidth
Width of a frame in macro blocks.
Definition: xmvwmv2.h:186
void decode(uint32 cbp)
Definition: xmvwmv2.cpp:103
Common::ScopedArray< byte > _oldPlanes[3]
The 3 color planes, YUV, last frame.
Definition: xmvwmv2.h:192
bool _hasVarSizeTrans
Does the video have variable sized transforms?
Definition: xmvwmv2.h:198
uint32 _chromaHeight
Height of the chroma portion of a decoded frame.
Definition: xmvwmv2.h:184
bool _hasHybridMV
Does the video have hybrid motion vectors?
Definition: xmvwmv2.h:200
uint32_t uint32
Definition: types.h:204
void decodeFrame(Graphics::Surface &surface, Common::SeekableReadStream &dataStream)
Definition: xmvwmv2.cpp:309
Decoder for motion vectors.
Definition: xmvwmv2.h:105
Context for decoding a frame.
Definition: xmvwmv2.h:132
void IDCTCol(int32 *b)
Definition: xmvwmv2.cpp:778
bool _hasMixedPelMC
Does the video have mixed pel motion compensation?
Definition: xmvwmv2.h:196
Decoders for DCT AC coefficients.
Definition: xmvwmv2.h:99
uint32 _mbCountHeight
Height of a frame in macro blocks.
Definition: xmvwmv2.h:187
const WMV2MVTable * parameters
Definition: xmvwmv2.h:107
void IDCTRow(int32 *b)
Definition: xmvwmv2.cpp:752
static const uint32 kBlockSize
Size of a block.
Definition: xmvwmv2.h:77
void init()
Init the decoder.
Definition: xmvwmv2.cpp:240
uint32 _currentFrame
Definition: xmvwmv2.h:227
Interface for a seekable & readable data stream.
Definition: readstream.h:265
Common::ScopedPtr< Common::Huffman > huffman
Definition: xmvwmv2.h:100
uint32 _chromaWidth
Width of the chroma portion of a decoded frame.
Definition: xmvwmv2.h:183
A bit stream.
Definition: bitstream.h:40
uint8 byte
Definition: types.h:209
void IDCTPut(byte *dest, int32 *block, uint32 pitch)
Definition: xmvwmv2.cpp:727
int32_t int32
Definition: types.h:203
uint8 _sliceCount
Number of slices per frame.
Definition: xmvwmv2.h:203