void ParseIntraMode(BitReader br, int mb_x) { int top = 4 * mb_x; // within intra_t int left = 0; // within intra_l var block = m_mb_data[mb_x]; // Note: we don't save segment map (yet), as we don't expect // to decode more than 1 keyframe. if (m_segment_hdr.UpdateMap) { // Hardcoded tree parsing block.segment_ = 0 == br.GetBit (m_proba.Segments[0]) ? (byte)br.GetBit (m_proba.Segments[1]) : (byte)(2 + br.GetBit (m_proba.Segments[2])); } else { block.segment_ = 0; // default for intra } if (m_use_skip_proba) block.skip_ = br.GetBit (m_skip_p) != 0; block.is_i4x4_ = 0 == br.GetBit (145); // decide for B_PRED first if (!block.is_i4x4_) { // Hardcoded 16x16 intra-mode decision tree. int ymode = 0 != br.GetBit (156) ? (0 != br.GetBit (128) ? TM_PRED : H_PRED) : (0 != br.GetBit (163) ? V_PRED : DC_PRED); block.imodes_[0] = (byte)ymode; for (int i = 0; i < 4; ++i) { m_intra_t[top+i] = (byte)ymode; m_intra_l[left+i] = (byte)ymode; } } else { int modes = 0; // within block.imodes_; for (int y = 0; y < 4; ++y) { int ymode = m_intra_l[left + y]; for (int x = 0; x < 4; ++x) { int prob = m_intra_t[top + x]; int i = kYModesIntra4[br.GetBit (kBModesProba[prob,ymode,0])]; while (i > 0) i = kYModesIntra4[2 * i + br.GetBit (kBModesProba[prob,ymode,i])]; ymode = -i; m_intra_t[top + x] = (byte)ymode; } Buffer.BlockCopy (m_intra_t, top, block.imodes_, modes, 4); modes += 4; m_intra_l[left + y] = (byte)ymode; } } // Hardcoded UVMode decision tree block.uvmode_ = 0 == br.GetBit (142) ? DC_PRED : 0 == br.GetBit (114) ? V_PRED : 0 != br.GetBit (183) ? TM_PRED : H_PRED; }
void ParseProba(BitReader br) { for (int t = 0; t < NumTypes; ++t) { for (int b = 0; b < NumBands; ++b) for (int c = 0; c < NumCtx; ++c) for (int p = 0; p < NumProbas; ++p) { int v = br.GetBit (CoeffsUpdateProba[t,b,c,p]) != 0 ? br.GetBits (8) : CoeffsProba0[t,b,c,p]; m_proba.Bands[t,b].Probas[c][p] = (byte)v; } for (int b = 0; b < 16 + 1; ++b) { m_proba.BandsPtr[t][b] = m_proba.Bands[t,kBands[b]]; } } m_use_skip_proba = br.GetNextBit() != 0; if (m_use_skip_proba) m_skip_p = br.GetBits (8); }
int GetCoeffs(BitReader br, BandProbas[] prob, int ctx, int[] dq, int n, short[] out_ptr, int dst) { var p = prob[n].Probas[ctx]; for (; n < 16; ++n) { if (0 == br.GetBit (p[0])) return n; // previous coeff was last non-zero coeff while (0 == br.GetBit (p[1])) // sequence of zero coeffs { p = prob[++n].Probas[0]; if (16 == n) return 16; } // non zero coeff var p_ctx = prob[n + 1].Probas; int v; if (0 == br.GetBit (p[2])) { v = 1; p = p_ctx[1]; } else { v = br.GetLargeValue (p); p = p_ctx[2]; } out_ptr[dst+kZigzag[n]] = (short)(br.GetSigned (v) * dq[n > 0 ? 1 : 0]); } return 16; }