private void GetCodedBlockPattern()
        {
            _codedBlockPattern = new CodedBlockPattern(_mbStateA.CodedBlockPattern, _mbStateB.CodedBlockPattern);

            for (uint binIdx = 0; binIdx < 4; binIdx++)
            {
                uint ctxIdx = 73 + (_codedBlockPattern.GetCtxIdxInc(binIdx) ^ 3);
                if (_arithmeticDecoder.DecodeDecision(ctxIdx) == 1)
                {
                    _codedBlockPattern.SetCodedBlockPatternBit(binIdx);
                }
            }
            if (_sequenceState.IsChromaSubsampling)
            {
                uint ctxIdxBinIdx4 = 77 + _codedBlockPattern.GetCtxIdxInc(4);
                if (_arithmeticDecoder.DecodeDecision(ctxIdxBinIdx4) == 1)
                {
                    uint ctxIdxBinIdx5 = 77 + (4 + _codedBlockPattern.GetCtxIdxInc(5));
                    _codedBlockPattern.SetCodedBlockPatternBit(4U + _arithmeticDecoder.DecodeDecision(ctxIdxBinIdx5));
                }
            }
        }
        private void MacroBlockLayer()
        {
            IMacroblockType macroBlockType = GetMacroblockType();

#if DEBUG
            H264Debug.WriteLine("{0}: mb_type={1}", CurrentMbIndex, macroBlockType);
#endif
            if (macroBlockType.IsIPcm)
            {
                _reader.GetPcmSamples();

                InitializeCabac();

                _currMbState = MacroblockState.Pcm;
            }
            else
            {
                bool transform8X8ModeFlagSet = false;
                if (macroBlockType.NumMbPart == 4)
                {
                    // Note: Only inter-coded blocks can have mb parts, in particular,
                    //       we are not currently decoding an intra-coded block!
                    SubMacroBlockPrediction();

                    if (HasSubMbPartSizeLessThan8X8())
                    {
                        transform8X8ModeFlagSet = true;                         // Transform 8x8 mode is not possible!
                    }
                }
                else
                {
                    if (_pictureState.Transform8X8ModeFlag && macroBlockType.IsI_NxN)
                    {
                        GetTransformSize8X8Flag();

                        transform8X8ModeFlagSet = true;
                    }

                    MacroBlockPrediction(macroBlockType);
                }

                if (macroBlockType.IsIntra16X16)
                {
                    _codedBlockPattern = new CodedBlockPattern(macroBlockType.CodedBlockPattern);
                }
                else
                {
                    GetCodedBlockPattern();

                    if (_pictureState.Transform8X8ModeFlag && !transform8X8ModeFlagSet &&
                        _codedBlockPattern.IsLumaResidualPresent &&
                        (!macroBlockType.IsDirect || _sequenceState.Direct8X8InferenceFlag))
                    {
                        GetTransformSize8X8Flag();
                    }
                }

                _currMbState.CodedBlockPattern = _codedBlockPattern.Bits;

                if (_codedBlockPattern.IsResidualPresent || macroBlockType.IsIntra16X16)
                {
                    GetMbQpDelta();                     // mb_qp_delta
                    Residual(macroBlockType, 0, 15);
                }
            }
        }