Skip to content
Snippets Groups Projects
Contexts.cpp 49.9 KiB
Newer Older
  • Learn to ignore specific revisions
  • Frank Bossen's avatar
    Frank Bossen committed
        { 165, 151, 153, 154, 125, 126, 168, 155, 186, 172, 143, },
    
    
    const CtxSet ContextSetCfg::LastX[] =
    {
      ContextSetCfg::addCtxSet
      ({
    
    #if JVET_M0453_CABAC_ENGINE
        {  111, 111, 110, 111, 111, 124, 111, 111, 111,  95, 126, 126, 111, 111, 169, 154, 111, 110, 110, 123, CNU, CNU, CNU, CNU, CNU,},
        {  125, 110, 109, 111, 125, 123, 111, 111,  95, 108, 126, 126, 110,  95, 183, 154, 140, 110, 124, 137, CNU, CNU, CNU, CNU, CNU,},
        {  140, 140, 124, 111, 126, 109, 111, 126, 125, 123, 126, 127, 111, 110,  93, 141, 157, 126, 125, 182, CNU, CNU, CNU, CNU, CNU,},
        {    8,   8,   5,   5,   4,   4,   5,   4,   4,   0,   5,   4,   0,   0,   0,   1,   1,   1,   0,   8, DWS, DWS, DWS, DWS, DWS,  },
    #else
    
    Frank Bossen's avatar
    Frank Bossen committed
        { 111, 125, 124, 111, 111, 109, 111, 111, 125, 109, 140, 126, 111, 111, 139, 140, 111, 125, 95, 138, CNU, CNU, CNU, CNU, CNU, },
        { 125, 110, 109, 111, 125, 123, 111, 111, 95, 123, 140, 126, 125, 95, 169, 125, 140, 110, 124, 152, CNU, CNU, CNU, CNU, CNU, },
        { 140, 140, 124, 140, 126, 109, 140, 141, 125, 94, 111, 127, 111, 140, 93, 141, 186, 141, 125, 197, CNU, CNU, CNU, CNU, CNU, },
    
    #if JVET_M0453_CABAC_ENGINE
        {  137, 109,  62, CNU,},
        {  138, 123,  92, CNU,},
        {  138, 108,  61, CNU,},
        {    2,   4,   4, DWS,  },
    #else
    
    Frank Bossen's avatar
    Frank Bossen committed
        { 123, 109, 63, CNU, },
        { 138, 123, 92, CNU, },
        { 123, 108, 62, CNU, },
    
      }),
    };
    
    const CtxSet ContextSetCfg::LastY[] =
    {
      ContextSetCfg::addCtxSet
      ({
    
    #if JVET_M0453_CABAC_ENGINE
        {  125, 125, 139, 111, 111, 124, 111, 111, 110, 110, 140, 126, 110,  95, 155, 154, 111, 110, 124, 180, CNU, CNU, CNU, CNU, CNU,},
        {  110,  95, 109, 125, 110,  93, 125, 111, 124, 108, 140, 111,  95, 109, 153, 125, 126, 110, 109, 181, CNU, CNU, CNU, CNU, CNU,},
        {  110, 110, 109, 125, 111, 108, 111, 126,  95,  93, 111, 127, 111,  95,  47, 155, 158, 156, 140, 137, CNU, CNU, CNU, CNU, CNU,},
        {    8,   5,   8,   5,   5,   4,   5,   5,   4,   0,   5,   5,   1,   0,   0,   1,   4,   1,   0,   8, DWS, DWS, DWS, DWS, DWS,  },
    #else
    
    Frank Bossen's avatar
    Frank Bossen committed
        { 125, 110, 139, 125, 125, 109, 111, 111, 110, 109, 140, 126, 110, 110, 154, 140, 111, 125, 109, 181, CNU, CNU, CNU, CNU, CNU, },
        { 110, 95, 94, 125, 110, 123, 140, 111, 95, 123, 125, 111, 110, 95, 154, 125, 111, 95, 94, 137, CNU, CNU, CNU, CNU, CNU, },
        { 110, 110, 109, 125, 111, 123, 111, 141, 95, 108, 111, 142, 111, 95, 63, 140, 157, 141, 110, 152, CNU, CNU, CNU, CNU, CNU, },
    
    #if JVET_M0453_CABAC_ENGINE
        {  137, 109, 122, CNU,},
        {  108, 108, 136, CNU,},
        {  123, 123,  91, CNU,},
        {    2,   5,   5, DWS,  },
    #else
    
    Frank Bossen's avatar
    Frank Bossen committed
        { 108, 94, 122, CNU, },
        { 108, 93, 92, CNU, },
        { 108, 123, 77, CNU, },
    
      }),
    };
    
    
    const CtxSet ContextSetCfg::MVPIdx = ContextSetCfg::addCtxSet
    ({
    
    #if JVET_M0453_CABAC_ENGINE
      {  153,},
      { 168, },
      { CNU, },
      {   10,},
    #else
    
    Frank Bossen's avatar
    Frank Bossen committed
      { 168, },
      { 168, },
      { CNU, },
    
    #if JVET_M0444_SMVD
    const CtxSet ContextSetCfg::SmvdFlag = ContextSetCfg::addCtxSet
    ( {
      { 154, },
      { 110, },
      { CNU, },
    
    const CtxSet ContextSetCfg::SaoMergeFlag = ContextSetCfg::addCtxSet
    ({
    
    #if JVET_M0453_CABAC_ENGINE
      {   63,},
      {  244,},
      {  199,},
      {    0,},
    #else
    
    Frank Bossen's avatar
    Frank Bossen committed
      { 92, },
      { 214, },
      { 184, },
    
    });
    
    const CtxSet ContextSetCfg::SaoTypeIdx = ContextSetCfg::addCtxSet
    ({
    
    #if JVET_M0453_CABAC_ENGINE
      {   63,},
      {   95,},
      {  110,},
      {    0,},
    #else
    
    Frank Bossen's avatar
    Frank Bossen committed
      { 77, },
      { 111, },
      { 110, },
    
    Tung Nguyen's avatar
    Tung Nguyen committed
    #if !JVET_M0464_UNI_MTS
    
    const CtxSet ContextSetCfg::TransformSkipFlag = ContextSetCfg::addCtxSet
    ({
    
    #if JVET_M0453_CABAC_ENGINE
      {  154,  13,},
      {  152,  57,},
      {  139,   0,},
      {    4,   1,},
    #else
    
    Frank Bossen's avatar
    Frank Bossen committed
      { 124, 61, },
      { 138, 46, },
      { 109, 42, },
    
    Tung Nguyen's avatar
    Tung Nguyen committed
    #endif
    
    
    const CtxSet ContextSetCfg::TransquantBypassFlag = ContextSetCfg::addCtxSet
    ({
      {  154,},
      {  154,},
      {  154,},
    
    #if JVET_M0453_CABAC_ENGINE
      { DWS, }
    #endif
    
    });
    
    const CtxSet ContextSetCfg::RdpcmFlag = ContextSetCfg::addCtxSet
    ({
      {  139, 139,},
      {  139, 139,},
      {  CNU, CNU,},
    
    #if JVET_M0453_CABAC_ENGINE
      { DWS, DWS, }
    #endif
    
    });
    
    const CtxSet ContextSetCfg::RdpcmDir = ContextSetCfg::addCtxSet
    ({
      {  139, 139,},
      {  139, 139,},
      {  CNU, CNU,},
    
    #if JVET_M0453_CABAC_ENGINE
      { DWS, DWS, }
    #endif
    
    Tung Nguyen's avatar
    Tung Nguyen committed
    #if JVET_M0464_UNI_MTS
    const CtxSet ContextSetCfg::MTSIndex = ContextSetCfg::addCtxSet
    ({
    #if JVET_M0453_CABAC_ENGINE
      { CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, },
      { CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, },
      { CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, },
      { DWS, DWS, DWS, DWS, DWS, DWS, DWS, DWS, DWS, DWS, DWS, },
    #else
      { CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, },
      { CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, },
      { CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, },
    #endif
    });
    #else
    
    const CtxSet ContextSetCfg::EMTTuIndex = ContextSetCfg::addCtxSet
    ({
    
    #if JVET_M0453_CABAC_ENGINE
      {  122, 136, CNU, CNU,},
      {  151, 150, CNU, CNU,},
      {  121, 136, CNU, CNU,},
      {    9,   9, DWS, DWS,},
    #else
    
    Frank Bossen's avatar
    Frank Bossen committed
      { 153, 138, CNU, CNU, },
      { 138, 167, CNU, CNU, },
      { 167, 123, CNU, CNU, },
    
    });
    
    const CtxSet ContextSetCfg::EMTCuFlag = ContextSetCfg::addCtxSet
    ({
    
    #if JVET_M0453_CABAC_ENGINE
      {  216, 158, 172, 201, 200, CNU,},
      {  202, 158, 158, 158, 187, CNU,},
      {  CNU, CNU, 141, 171, 171, CNU,},
      {    9,   8,   9,   8,   8, DWS,},
    #else
    
    Frank Bossen's avatar
    Frank Bossen committed
      { 155, 141, 155, 155, 140, CNU, },
      { 141, 141, 141, 126, 155, CNU, },
      { CNU, CNU, 140, 155, 155, CNU, },
    
    Tung Nguyen's avatar
    Tung Nguyen committed
    #endif
    
    
    const CtxSet ContextSetCfg::CrossCompPred = ContextSetCfg::addCtxSet
    ({
      {  154, 154, 154, 154, 154, 154, 154, 154, 154, 154,},
      {  154, 154, 154, 154, 154, 154, 154, 154, 154, 154,},
      {  154, 154, 154, 154, 154, 154, 154, 154, 154, 154,},
    
    #if JVET_M0453_CABAC_ENGINE
      { DWS, DWS, DWS, DWS, DWS, DWS, DWS, DWS, DWS, DWS, }
    #endif
    
    });
    
    const CtxSet ContextSetCfg::ChromaQpAdjFlag = ContextSetCfg::addCtxSet
    ({
      {  154,},
      {  154,},
      {  154,},
    
    #if JVET_M0453_CABAC_ENGINE
      { DWS, }
    #endif
    
    });
    
    const CtxSet ContextSetCfg::ChromaQpAdjIdc = ContextSetCfg::addCtxSet
    ({
      {  154,},
      {  154,},
      {  154,},
    
    #if JVET_M0453_CABAC_ENGINE
      { DWS, }
    #endif
    
    });
    
    const CtxSet ContextSetCfg::ImvFlag = ContextSetCfg::addCtxSet
    ({
    
    #if JVET_M0453_CABAC_ENGINE
      {  227, 214, 230, 195,},
      {  213, 229, 230, 166,},
      {  CNU, CNU, CNU, CNU,},
      {    1,   4,   4,   5,},
    #else
    
    Frank Bossen's avatar
    Frank Bossen committed
      { 212, 214, 230, 182, },
      { 212, 214, 230, 182, },
      { CNU, CNU, CNU, CNU, },
    
    });
    
    const CtxSet ContextSetCfg::ctbAlfFlag =
    {
      ContextSetCfg::addCtxSet
      ( {
    
    #if JVET_M0453_CABAC_ENGINE
        {  154, 201, 203, 168, 247, 249, 168, 248, 235,},
        {  139, 186, 203, 168, 247, 249, 168, 247, 234,},
        {  219, 237, 253, 187, 234, 235, 216, 219, 250,},
        {    0,   0,   4,   0,   0,   0,   0,   0,   0,  },
    #else
    
    Frank Bossen's avatar
    Frank Bossen committed
        { 138, 141, 173, 122, 170, 203, 151, 170, 203, },
        { 153, 156, 188, 137, 185, 218, 152, 185, 218, },
        { 155, 205, 253, 168, 187, 234, 168, 187, 220, },
    
    const CtxSet ContextSetCfg::MHIntraFlag = ContextSetCfg::addCtxSet
    ({
    
    #if JVET_M0453_CABAC_ENGINE
      {  240,},
      {  197,},
      {  CNU,},
      {    1,},
    #else
    
    Frank Bossen's avatar
    Frank Bossen committed
      { 226, },
      { 227, },
      { CNU, },
    
    });
    
    const CtxSet ContextSetCfg::MHIntraPredMode = ContextSetCfg::addCtxSet
    ({
    
    #if JVET_M0453_CABAC_ENGINE
      {  156, CNU, CNU, CNU,},
      {  156, CNU, CNU, CNU,},
      {  CNU, CNU, CNU, CNU,},
      {    9, DWS, DWS, DWS,},
    #else
    
    Frank Bossen's avatar
    Frank Bossen committed
      { 155, CNU, CNU, CNU, },
      { 141, CNU, CNU, CNU, },
      { CNU, CNU, CNU, CNU, },
    
    const CtxSet ContextSetCfg::TriangleFlag = ContextSetCfg::addCtxSet
    ({
    
    #if JVET_M0453_CABAC_ENGINE
      {  149, 137, 137,},
      {  165, 151, 137,},
      {  CNU, CNU, CNU,},
      {    9,  13,  10,},
    #else
    
    Frank Bossen's avatar
    Frank Bossen committed
      { 165, 137, 153, },
      { 106, 122, 138, },
      { CNU, CNU, CNU, },
    
    });
    
    const CtxSet ContextSetCfg::TriangleIdx = ContextSetCfg::addCtxSet
    ({
    
    #if JVET_M0453_CABAC_ENGINE
      {  141,},
      {  141,},
      {  CNU,},
      {    8,},
    #else
    
    Frank Bossen's avatar
    Frank Bossen committed
      { 155, },
      { 126, },
      { CNU, },
    
    // clang-format on
    
    const unsigned ContextSetCfg::NumberOfContexts = (unsigned)ContextSetCfg::sm_InitTables[0].size();
    
    
    // combined sets
    const CtxSet ContextSetCfg::Sao = { ContextSetCfg::SaoMergeFlag, ContextSetCfg::SaoTypeIdx };
    
    
    
    template <class BinProbModel>
    CtxStore<BinProbModel>::CtxStore()
      : m_CtxBuffer ()
      , m_Ctx       ( nullptr )
    {}
    
    template <class BinProbModel>
    CtxStore<BinProbModel>::CtxStore( bool dummy )
      : m_CtxBuffer ( ContextSetCfg::NumberOfContexts )
      , m_Ctx       ( m_CtxBuffer.data() )
    {}
    
    template <class BinProbModel>
    CtxStore<BinProbModel>::CtxStore( const CtxStore<BinProbModel>& ctxStore )
      : m_CtxBuffer ( ctxStore.m_CtxBuffer )
      , m_Ctx       ( m_CtxBuffer.data() )
    {}
    
    template <class BinProbModel>
    void CtxStore<BinProbModel>::init( int qp, int initId )
    {
      const std::vector<uint8_t>& initTable = ContextSetCfg::getInitTable( initId );
      CHECK( m_CtxBuffer.size() != initTable.size(),
            "Size of init table (" << initTable.size() << ") does not match size of context buffer (" << m_CtxBuffer.size() << ")." );
    
    #if JVET_M0453_CABAC_ENGINE
      const std::vector<uint8_t> &rateInitTable = ContextSetCfg::getInitTable(NUMBER_OF_SLICE_TYPES);
      CHECK(m_CtxBuffer.size() != rateInitTable.size(),
            "Size of rate init table (" << rateInitTable.size() << ") does not match size of context buffer ("
                                        << m_CtxBuffer.size() << ").");
    #endif
    
      int clippedQP = Clip3( 0, MAX_QP, qp );
    
      for( std::size_t k = 0; k < m_CtxBuffer.size(); k++ )
      {
        m_CtxBuffer[k].init( clippedQP, initTable[k] );
    
    #if JVET_M0453_CABAC_ENGINE
        m_CtxBuffer[k].setLog2WindowSize(rateInitTable[k]);
    #endif
    
      }
    }
    
    template <class BinProbModel>
    void CtxStore<BinProbModel>::setWinSizes( const std::vector<uint8_t>& log2WindowSizes )
    {
      CHECK( m_CtxBuffer.size() != log2WindowSizes.size(),
            "Size of window size table (" << log2WindowSizes.size() << ") does not match size of context buffer (" << m_CtxBuffer.size() << ")." );
      for( std::size_t k = 0; k < m_CtxBuffer.size(); k++ )
      {
        m_CtxBuffer[k].setLog2WindowSize( log2WindowSizes[k] );
      }
    }
    
    template <class BinProbModel>
    void CtxStore<BinProbModel>::loadPStates( const std::vector<uint16_t>& probStates )
    {
      CHECK( m_CtxBuffer.size() != probStates.size(),
            "Size of prob states table (" << probStates.size() << ") does not match size of context buffer (" << m_CtxBuffer.size() << ")." );
      for( std::size_t k = 0; k < m_CtxBuffer.size(); k++ )
      {
        m_CtxBuffer[k].setState( probStates[k] );
      }
    }
    
    template <class BinProbModel>
    void CtxStore<BinProbModel>::savePStates( std::vector<uint16_t>& probStates ) const
    {
      probStates.resize( m_CtxBuffer.size(), uint16_t(0) );
      for( std::size_t k = 0; k < m_CtxBuffer.size(); k++ )
      {
        probStates[k] = m_CtxBuffer[k].getState();
      }
    }
    
    
    
    
    
    template class CtxStore<BinProbModel_Std>;
    
    
    
    
    
    Ctx::Ctx()                                  : m_BPMType( BPM_Undefined )                        {}
    Ctx::Ctx( const BinProbModel_Std*   dummy ) : m_BPMType( BPM_Std   ), m_CtxStore_Std  ( true )  {}
    
    Ctx::Ctx( const Ctx& ctx )
      : m_BPMType         ( ctx.m_BPMType )
      , m_CtxStore_Std    ( ctx.m_CtxStore_Std    )
    {
      ::memcpy( m_GRAdaptStats, ctx.m_GRAdaptStats, sizeof( unsigned ) * RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS );
    }