93 assert((block >= 0) && (block < 6));
95 return (
_cbp & (1 << (5 - block))) != 0;
99 _cbp &= ~( 1 << (5 - block));
100 _cbp |= coded << (5 - block);
113 set(2, ((left .
isSet(1) == isSet(0)) ? left.
isSet(3) : isSet(0)) ^ x.
isSet(2));
114 set(3, (( isSet(0) == isSet(1)) ? isSet(2) : isSet(1)) ^ x.
isSet(3));
121 hasACPerMacroBlock(false), hasACPrediction(false),
122 acRLERunLength(0), acRLELevelLength(0) {
127 for (
int i = 0; i < 4; i++) {
140 for (
int i = 4; i < 6; i++) {
159 dcStepSize = qScale / 2 + 6;
161 defaultPredictor = (1024 + (dcStepSize / 2)) / dcStepSize;
163 if (acQuantTop[0] && acQuantTop[1] && acQuantTop[2]) {
164 std::memset(acQuantTop[0], 0,
sizeof(
int32) * block[0].planePitch);
165 std::memset(acQuantTop[1], 0,
sizeof(
int32) * block[4].planePitch);
166 std::memset(acQuantTop[2], 0,
sizeof(
int32) * block[5].planePitch);
168 for (
uint32 x = 0; x < (block[0].planePitch / block[0].blockPitch); x++) {
169 acQuantTop[0][x * block[0].blockPitch + block[4].blockPitch] = defaultPredictor;
170 acQuantTop[0][x * block[0].blockPitch ] = defaultPredictor;
172 acQuantTop[1][x * block[4].blockPitch] = defaultPredictor;
173 acQuantTop[2][x * block[5].blockPitch] = defaultPredictor;
179 for (
int i = 0; i < 4; i++)
180 block[i].acQuantTop = acQuantTop[0] +
kBlockSize * (i & 1);
182 for (
int i = 4; i < 6; i++)
183 block[i].acQuantTop = acQuantTop[i - 3];
187 acQuantLeft[0][0] = defaultPredictor;
188 acQuantLeft[1][0] = defaultPredictor;
189 acQuantLeft[2][0] = defaultPredictor;
190 acQuantLeft[3][0] = defaultPredictor;
192 dcTopLeft[0] = defaultPredictor;
194 dcTopLeft[2] = defaultPredictor;
195 dcTopLeft[3] = defaultPredictor;
203 for (
int i = 0; i < 6; i++) {
204 block[i].refPlane += block[i].planePitch * (block[i].blockPitch - 1);
205 block[i].curPlane += block[i].planePitch * (block[i].blockPitch - 1);
212 curCBP[0].decode(cbp, cbpTopLeft, cbpTop, curCBP[-1]);
218 for (
int i = 0; i < 6; i++) {
219 block[i].refPlane += block[i].blockPitch;
220 block[i].curPlane += block[i].blockPitch;
221 block[i].acQuantTop += block[i].blockPitch;
291 for (
int i = 0; i < 2; i++) {
292 for (
int j = 0; j < 3; j++) {
301 for (
int i = 0; i < 2; i++) {
330 bool isJFrame =
false;
349 for (
int i = 0; i < 3; i++)
356 if (extraData.
size() < 4)
377 warning(
"TODO: XMVWMV2 Loop filter");
385 for (
int i = 0; i < 4; i++) {
395 for (
int i = 4; i < 6; i++) {
492 for (
int i = 0; i < 6; i++) {
530 const uint8 *zigZag = 0;
533 if (isPredictedLeft) {
550 int32 dcQuantCoeff = dcPredictor + dcDiff;
556 std::memset(acReconCoeffs, 0,
sizeof(acReconCoeffs));
558 acReconCoeffs[0] = dcQuantCoeff * ctx.
dcStepSize;
643 while (length < 6 && !end) {
674 "Overrun while deRLEing AC coefficients");
677 uint32 coeffIndex = zigZag[coeffCount];
693 acReconCoeffs[coeffIndex] = qScale2 * level + qScaleOdd;
695 acReconCoeffs[coeffIndex] = qScale2 * level - qScaleOdd;
706 if (acQuantCoeff == 0)
708 else if (acQuantCoeff > 0)
709 acReconCoeffs[i *
kBlockSize] = qScale2 * acQuantCoeff + qScaleOdd;
711 acReconCoeffs[i *
kBlockSize] = qScale2 * acQuantCoeff - qScaleOdd;
715 if (acQuantCoeff == 0)
716 acReconCoeffs[i] = 0;
717 else if (acQuantCoeff > 0)
718 acReconCoeffs[i] = qScale2 * acQuantCoeff + qScaleOdd;
720 acReconCoeffs[i] = qScale2 * acQuantCoeff - qScaleOdd;
730 for (
uint32 i = 0; i < 8; i++, dest += pitch, block += 8)
731 for (
uint32 j = 0; j < 8; j++)
732 dest[j] =
CLIP(block[j], 0, 255);
736 for (
int i = 0; i < 64; i += 8)
739 for (
int i = 0; i < 8; i++)
754 int a1 = (
W1 * b[1]) + (
W7 * b[7]);
755 int a7 = (
W7 * b[1]) - (
W1 * b[7]);
756 int a5 = (
W5 * b[5]) + (
W3 * b[3]);
757 int a3 = (
W3 * b[5]) - (
W5 * b[3]);
758 int a2 = (
W2 * b[2]) + (
W6 * b[6]);
759 int a6 = (
W6 * b[2]) - (
W2 * b[6]);
760 int a0 = (
W0 * b[0]) + (
W0 * b[4]);
761 int a4 = (
W0 * b[0]) - (
W0 * b[4]);
764 int s1 = (181 * (a1 - a5 + a7 - a3) + 128) >> 8;
765 int s2 = (181 * (a1 - a5 - a7 + a3) + 128) >> 8;
768 b[0] = (a0 + a2 + a1 + a5 + (1 << 7)) >> 8;
769 b[1] = (a4 + a6 + s1 + (1 << 7)) >> 8;
770 b[2] = (a4 - a6 + s2 + (1 << 7)) >> 8;
771 b[3] = (a0 - a2 + a7 + a3 + (1 << 7)) >> 8;
772 b[4] = (a0 - a2 - a7 - a3 + (1 << 7)) >> 8;
773 b[5] = (a4 - a6 - s2 + (1 << 7)) >> 8;
774 b[6] = (a4 + a6 - s1 + (1 << 7)) >> 8;
775 b[7] = (a0 + a2 - a1 - a5 + (1 << 7)) >> 8;
780 int a1 = ((
W1 * b[8 * 1]) + (
W7 * b[8 * 7]) + 4) >> 3;
781 int a7 = ((
W7 * b[8 * 1]) - (
W1 * b[8 * 7]) + 4) >> 3;
782 int a5 = ((
W5 * b[8 * 5]) + (
W3 * b[8 * 3]) + 4) >> 3;
783 int a3 = ((
W3 * b[8 * 5]) - (
W5 * b[8 * 3]) + 4) >> 3;
784 int a2 = ((
W2 * b[8 * 2]) + (
W6 * b[8 * 6]) + 4) >> 3;
785 int a6 = ((
W6 * b[8 * 2]) - (
W2 * b[8 * 6]) + 4) >> 3;
786 int a0 = ((
W0 * b[8 * 0]) + (
W0 * b[8 * 4]) ) >> 3;
787 int a4 = ((
W0 * b[8 * 0]) - (
W0 * b[8 * 4]) ) >> 3;
790 int s1 = (181 * (a1 - a5 + a7 - a3) + 128) >> 8;
791 int s2 = (181 * (a1 - a5 - a7 + a3) + 128) >> 8;
794 b[8 * 0] = (a0 + a2 + a1 + a5 + (1 << 13)) >> 14;
795 b[8 * 1] = (a4 + a6 + s1 + (1 << 13)) >> 14;
796 b[8 * 2] = (a4 - a6 + s2 + (1 << 13)) >> 14;
797 b[8 * 3] = (a0 - a2 + a7 + a3 + (1 << 13)) >> 14;
799 b[8 * 4] = (a0 - a2 - a7 - a3 + (1 << 13)) >> 14;
800 b[8 * 5] = (a4 - a6 - s2 + (1 << 13)) >> 14;
801 b[8 * 6] = (a4 + a6 - s1 + (1 << 13)) >> 14;
802 b[8 * 7] = (a0 + a2 - a1 - a5 + (1 << 13)) >> 14;
const uint8 * runDeltaTableLast
Table for run delta values, last run.
const WMV2ACCoefficientTable wmv2AC[2][3]
DCT AC cofficients [luma/chroma][low motion/high motion/MPEG4].
const WMV2MVTable wmv2MV[2]
Motion vectors [low/high motion].
void decodeIMacroBlock(DecodeContext &ctx)
Decode an I-Frame (intra frame) macro block.
const Common::HuffmanTable & huffman
Huffman decoder for the motion vectors.
static const uint8 kSkipTypeNone
Parameters for decoding the motion vectors.
uint32 readUint32LE()
Read an unsigned 32-bit word stored in little endian (LSB first) order from the stream and return it...
Common::ScopedPtr< Common::Huffman > _huffDC[2][2]
Huffman code for DCT DC coefficients, [luma/chroma][low/high motion].
uint32 _lumaHeight
Height of the luma portion of a decoded frame.
Common::ScopedPtr< Common::Huffman > _huffCBP[4]
Huffman codes for coded block pattern.
Luminance values range from [0, 255].
bool _hasLoopFilter
Does the video use the loop filter?
void reset(PointerType o=0)
Resets the pointer with the new value.
uint32 _height
Height of a frame.
Common::Huffman * huffDC[2]
const Common::HuffmanTable wmv2HuffmanPMB[3]
P-Frame macroblock block pattern [high/mid/low rate].
void decodePFrame(DecodeContext &ctx)
Decode a P-Frame (inter frame).
Parameters for decoding the DCT AC coefficients.
bool isSet(int block) const
static const uint32 kMacroBlockSize
Size of a macro block.
const WMV2ACCoefficientTable * parameters
Which block pattern are coded?
uint32 _lumaWidth
Width of the luma portion of a decoded frame.
void initDecodeContext(DecodeContext &ctx)
static const uint32 kEscapeCodeChroma
#define IGNORE_UNUSED_VARIABLES
void set(int block, bool coded)
Common::ScopedPtr< Common::Huffman > huffman
Exception that provides a stack of explanations.
const Common::HuffmanTable wmv2HuffmanDC[2][2]
DCT DC coefficients [luma/chroma][low/high motion].
bool _hasJFrames
Does the video have j-frames (IntraX8)?
static uint8 getTrit(Common::BitStream &bits)
Decode a "tri-state".
static const uint8 kSkipTypeCol
uint32 getSymbol(BitStream &bits) const
Return the next symbol in the bitstream.
MVDecoder _decoderMV[2]
Huffman code for the motion vectors [low/high motion].
Common::Huffman ** huffDC
Basic exceptions to throw.
uint32 lastRunIndex
Index of the last run/level pair.
int32 acQuantLeft[4][kBlockSize]
Utility templates and functions.
void decodeIBlock(DecodeContext &ctx, BlockContext &block)
Decode an I-Frame (intra frame) block.
void setQScale(int32 qS)
Set the quantizer scale and calculate the DC step size and default predictor.
static const uint32 kEscapeCodeLuma
void startMacroBlock(uint32 cbp)
Decode a Huffman'd bitstream.
virtual uint32 getBit()=0
Read a bit from the bit stream.
Common::ScopedArray< int32 > _predAC[3]
AC predictors, previous row.
void decodeIFrame(DecodeContext &ctx)
Decode an I-Frame (intra frame).
const uint8 wmv2ZigZagNormal[64]
I-Frame coefficient zig-zag scantable, normal.
uint32 _width
Width of a frame.
const uint8 * levelDeltaTableLast
Table for level delta values, last level.
XMVWMV2Codec(uint32 width, uint32 height, Common::SeekableReadStream &extraData)
const uint8 * runDeltaTable
Table for run delta values.
Context for decoding a block.
Efficient YUV to RGB conversion.
void parseExtraData(Common::SeekableReadStream &extraData)
Parse the extra data containing video encoding properties.
const uint8 * levelDeltaTable
Table for level delta values.
void warning(const char *s,...)
virtual size_t size() const =0
Obtains the total size of the stream, measured in bytes.
const Common::HuffmanTable wmv2HuffmanIMB
I-Frame macroblock block pattern.
Basic reading stream interfaces.
Common::ScopedArray< CBP > _cbp
Coded block pattern, previous row.
bool _hasACPerMacroBlock
Are the AC selected per macro block instead of per frame?
DecodeContext(Common::BitStream &b)
void decodeJFrame(DecodeContext &ctx)
Decode a J-Frame (intra X8 frame).
Common::ScopedArray< byte > _curPlanes[3]
The 3 color planes, YUV, current frame.
ACDecoder _decoderAC[2][3]
Decoders for DCT AC coefficients [luma/chroma][low motion/high motion/MPEG4].
uint32 _mbCountWidth
Width of a frame in macro blocks.
const Common::HuffmanTable & huffman
Huffman decoder for the AC coefficients.
PointerType get() const
Returns the plain pointer value.
static const uint8 kSkipTypeMPEG
An image surface, in BGRA format.
Common::ScopedArray< byte > _oldPlanes[3]
The 3 color planes, YUV, last frame.
bool _hasVarSizeTrans
Does the video have variable sized transforms?
uint32 _chromaHeight
Height of the chroma portion of a decoded frame.
Decompressing Huffman codes.
virtual void skip(size_t n)=0
Skip the specified amount of bits.
bool _hasHybridMV
Does the video have hybrid motion vectors?
void decodeFrame(Graphics::Surface &surface, Common::SeekableReadStream &dataStream)
Context for decoding a frame.
const uint8 * levelTable
Table for level values.
bool _hasMixedPelMC
Does the video have mixed pel motion compensation?
const uint8 wmv2ZigZagVertical[64]
I-Frame coefficient zig-zag scantable, vertical.
virtual uint32 getBits(size_t n)=0
Read a multi-bit value from the bit stream.
uint32 _mbCountHeight
Height of a frame in macro blocks.
const WMV2MVTable * parameters
Static data used for decoding WMV2 videos.
A template implementing a bit stream for different data memory layouts.
WMV2 video codec, XMV variant.
uint32 escapeCode
Escape code that signifies a special run level encoding.
T CLIP(T v, T amin, T amax)
static const uint32 kBlockSize
Size of a block.
void init()
Init the decoder.
static const uint8 kSkipTypeRow
Interface for a seekable & readable data stream.
const uint8 * runTable
Table for run values.
Common::ScopedPtr< Common::Huffman > huffman
uint32 _chromaWidth
Width of the chroma portion of a decoded frame.
void IDCTPut(byte *dest, int32 *block, uint32 pitch)
uint8 _sliceCount
Number of slices per frame.
const uint8 wmv2ZigZagHorizontal[64]
I-Frame coefficient zig-zag scantable, horizontal.