diff --git a/source/Lib/CommonLib/ContextModelling.cpp b/source/Lib/CommonLib/ContextModelling.cpp index 78bffa319e3d0baa3d06e0c967e61b1d484bf399..74eaf6d23dc1cfede034569c4cc3e071241dd71a 100644 --- a/source/Lib/CommonLib/ContextModelling.cpp +++ b/source/Lib/CommonLib/ContextModelling.cpp @@ -300,6 +300,7 @@ unsigned DeriveCtx::CtxSkipFlag( const CodingUnit& cu ) } +#if !JVET_N600_AMVR_TPM_CTX_REDUCTION unsigned DeriveCtx::CtxIMVFlag( const CodingUnit& cu ) { const CodingStructure *cs = cu.cs; @@ -329,6 +330,7 @@ unsigned DeriveCtx::CtxTriangleFlag( const CodingUnit& cu ) return ctxId; } +#endif unsigned DeriveCtx::CtxPredModeFlag( const CodingUnit& cu ) { diff --git a/source/Lib/CommonLib/ContextModelling.h b/source/Lib/CommonLib/ContextModelling.h index ea58093d5ba0b6ec9b246dfa93f22fb8dbc7754a..5a6e6967c3d3bce45687cf08069ca82cb0178028 100644 --- a/source/Lib/CommonLib/ContextModelling.h +++ b/source/Lib/CommonLib/ContextModelling.h @@ -294,9 +294,13 @@ void CtxSplit ( const CodingStructure& cs, Partitioner& partitioner, uns unsigned CtxQtCbf ( const ComponentID compID, const unsigned trDepth, const bool prevCbCbf = false, const int ispIdx = 0 ); unsigned CtxInterDir ( const PredictionUnit& pu ); unsigned CtxSkipFlag ( const CodingUnit& cu ); +#if !JVET_N600_AMVR_TPM_CTX_REDUCTION unsigned CtxIMVFlag ( const CodingUnit& cu ); +#endif unsigned CtxAffineFlag( const CodingUnit& cu ); +#if !JVET_N600_AMVR_TPM_CTX_REDUCTION unsigned CtxTriangleFlag( const CodingUnit& cu ); +#endif unsigned CtxPredModeFlag( const CodingUnit& cu ); unsigned CtxIBCFlag(const CodingUnit& cu); } diff --git a/source/Lib/CommonLib/Contexts.cpp b/source/Lib/CommonLib/Contexts.cpp index 176ed1468ebbd5cb365762996537950b77d738a0..f5b508b785e978f9f1e199a0184d7a32a3bef3de 100644 --- a/source/Lib/CommonLib/Contexts.cpp +++ b/source/Lib/CommonLib/Contexts.cpp @@ -724,10 +724,17 @@ const CtxSet ContextSetCfg::ChromaQpAdjIdc = ContextSetCfg::addCtxSet const CtxSet ContextSetCfg::ImvFlag = ContextSetCfg::addCtxSet ({ +#if JVET_N600_AMVR_TPM_CTX_REDUCTION + { 212, 180, 183, 242, }, + { 213, 166, 198, 244, }, + { CNU, 152, CNU, CNU, }, + { 1, 5, 1, 0, }, +#else { 212, 199, 215, 180, 183, 242, }, { 213, 229, 244, 166, 198, 244, }, { CNU, CNU, CNU, 152, CNU, CNU, }, { 1, 4, 4, 5, 1, 0, }, +#endif }); const CtxSet ContextSetCfg::ctbAlfFlag = @@ -759,10 +766,17 @@ const CtxSet ContextSetCfg::MHIntraPredMode = ContextSetCfg::addCtxSet const CtxSet ContextSetCfg::TriangleFlag = ContextSetCfg::addCtxSet ({ +#if JVET_N600_AMVR_TPM_CTX_REDUCTION + { 149, }, + { 151, }, + { CNU, }, + { 8, }, +#else { 149, 123, 123, }, { 151, 152, 138, }, { CNU, CNU, CNU, }, { 8, 12, 9, }, +#endif }); const CtxSet ContextSetCfg::TriangleIdx = ContextSetCfg::addCtxSet diff --git a/source/Lib/CommonLib/TypeDef.h b/source/Lib/CommonLib/TypeDef.h index a387b883c045734f48ab23da5a481e411811e3d5..0e5083fa02e5597adc95421284f1ddf75ee92f67 100644 --- a/source/Lib/CommonLib/TypeDef.h +++ b/source/Lib/CommonLib/TypeDef.h @@ -50,6 +50,8 @@ #include <assert.h> #include <cassert> +#define JVET_N600_AMVR_TPM_CTX_REDUCTION 1 + #define JVET_N0334_MVCLIPPING 1 // prevention of MV stroage overflow and alignment with spec of MV/CPMV modular for AMVP mode #define JVET_N0481_BCW_CONSTRUCTED_AFFINE 1 diff --git a/source/Lib/DecoderLib/CABACReader.cpp b/source/Lib/DecoderLib/CABACReader.cpp index f0187574390a21f87fba85890b35790fb97353d5..ccc13a375b9e5b454d314d74b2a2583ce519fddc 100644 --- a/source/Lib/DecoderLib/CABACReader.cpp +++ b/source/Lib/DecoderLib/CABACReader.cpp @@ -801,17 +801,29 @@ void CABACReader::imv_mode( CodingUnit& cu, MergeCtx& mrgCtx ) const SPS *sps = cu.cs->sps; unsigned value = 0; +#if !JVET_N600_AMVR_TPM_CTX_REDUCTION unsigned ctxId = DeriveCtx::CtxIMVFlag( cu ); +#endif if (CU::isIBC(cu)) value = 1; else +#if JVET_N600_AMVR_TPM_CTX_REDUCTION + value = m_BinDecoder.decodeBin( Ctx::ImvFlag( 0 ) ); + DTRACE( g_trace_ctx, D_SYNTAX, "imv_mode() value=%d ctx=%d\n", value, 0 ); +#else value = m_BinDecoder.decodeBin( Ctx::ImvFlag( ctxId ) ); DTRACE( g_trace_ctx, D_SYNTAX, "imv_mode() value=%d ctx=%d\n", value, ctxId ); +#endif if( sps->getAMVREnabledFlag() && value ) { +#if JVET_N600_AMVR_TPM_CTX_REDUCTION + value = m_BinDecoder.decodeBin( Ctx::ImvFlag( 1 ) ); + DTRACE( g_trace_ctx, D_SYNTAX, "imv_mode() value=%d ctx=%d\n", value, 1 ); +#else value = m_BinDecoder.decodeBin( Ctx::ImvFlag( 3 ) ); DTRACE( g_trace_ctx, D_SYNTAX, "imv_mode() value=%d ctx=%d\n", value, 3 ); +#endif value++; } @@ -836,13 +848,23 @@ void CABACReader::affine_amvr_mode( CodingUnit& cu, MergeCtx& mrgCtx ) } unsigned value = 0; +#if JVET_N600_AMVR_TPM_CTX_REDUCTION + value = m_BinDecoder.decodeBin( Ctx::ImvFlag( 2 ) ); + DTRACE( g_trace_ctx, D_SYNTAX, "affine_amvr_mode() value=%d ctx=%d\n", value, 2 ); +#else value = m_BinDecoder.decodeBin( Ctx::ImvFlag( 4 ) ); DTRACE( g_trace_ctx, D_SYNTAX, "affine_amvr_mode() value=%d ctx=%d\n", value, 4 ); +#endif if( value ) { +#if JVET_N600_AMVR_TPM_CTX_REDUCTION + value = m_BinDecoder.decodeBin( Ctx::ImvFlag( 3 ) ); + DTRACE( g_trace_ctx, D_SYNTAX, "affine_amvr_mode() value=%d ctx=%d\n", value, 3 ); +#else value = m_BinDecoder.decodeBin( Ctx::ImvFlag( 5 ) ); DTRACE( g_trace_ctx, D_SYNTAX, "affine_amvr_mode() value=%d ctx=%d\n", value, 5 ); +#endif value++; } @@ -1934,8 +1956,12 @@ void CABACReader::triangle_mode( CodingUnit& cu ) return; } +#if JVET_N600_AMVR_TPM_CTX_REDUCTION + cu.triangle = m_BinDecoder.decodeBin( Ctx::TriangleFlag(0) ); +#else unsigned flag_idx = DeriveCtx::CtxTriangleFlag( cu ); cu.triangle = m_BinDecoder.decodeBin( Ctx::TriangleFlag(flag_idx) ); +#endif DTRACE( g_trace_ctx, D_SYNTAX, "triangle_mode() triangle_mode=%d pos=(%d,%d) size: %dx%d\n", cu.triangle, cu.Y().x, cu.Y().y, cu.lumaSize().width, cu.lumaSize().height ); diff --git a/source/Lib/EncoderLib/CABACWriter.cpp b/source/Lib/EncoderLib/CABACWriter.cpp index e3b090dc22c174e6dd6ed0d2617d5039a9839a55..be2085b92978bfe93a19e651a2f1f7e236010481 100644 --- a/source/Lib/EncoderLib/CABACWriter.cpp +++ b/source/Lib/EncoderLib/CABACWriter.cpp @@ -1465,15 +1465,27 @@ void CABACWriter::imv_mode( const CodingUnit& cu ) return; } +#if !JVET_N600_AMVR_TPM_CTX_REDUCTION unsigned ctxId = DeriveCtx::CtxIMVFlag( cu ); +#endif if (CU::isIBC(cu) == false) +#if JVET_N600_AMVR_TPM_CTX_REDUCTION + m_BinEncoder.encodeBin( (cu.imv > 0), Ctx::ImvFlag( 0 ) ); + DTRACE( g_trace_ctx, D_SYNTAX, "imv_mode() value=%d ctx=%d\n", (cu.imv > 0), 0 ); +#else m_BinEncoder.encodeBin( ( cu.imv > 0 ), Ctx::ImvFlag( ctxId ) ); DTRACE( g_trace_ctx, D_SYNTAX, "imv_mode() value=%d ctx=%d\n", (cu.imv > 0), ctxId ); +#endif if( sps->getAMVREnabledFlag() && cu.imv > 0 ) { +#if JVET_N600_AMVR_TPM_CTX_REDUCTION + m_BinEncoder.encodeBin( (cu.imv > 1), Ctx::ImvFlag( 1 ) ); + DTRACE( g_trace_ctx, D_SYNTAX, "imv_mode() value=%d ctx=%d\n", (cu.imv > 1), 1 ); +#else m_BinEncoder.encodeBin( ( cu.imv > 1 ), Ctx::ImvFlag( 3 ) ); DTRACE( g_trace_ctx, D_SYNTAX, "imv_mode() value=%d ctx=%d\n", ( cu.imv > 1 ), 3 ); +#endif } DTRACE( g_trace_ctx, D_SYNTAX, "imv_mode() IMVFlag=%d\n", cu.imv ); @@ -1493,13 +1505,23 @@ void CABACWriter::affine_amvr_mode( const CodingUnit& cu ) return; } +#if JVET_N600_AMVR_TPM_CTX_REDUCTION + m_BinEncoder.encodeBin( (cu.imv > 0), Ctx::ImvFlag( 2 ) ); + DTRACE( g_trace_ctx, D_SYNTAX, "affine_amvr_mode() value=%d ctx=%d\n", (cu.imv > 0), 2 ); +#else m_BinEncoder.encodeBin( ( cu.imv > 0 ), Ctx::ImvFlag( 4 ) ); DTRACE( g_trace_ctx, D_SYNTAX, "affine_amvr_mode() value=%d ctx=%d\n", ( cu.imv > 0 ), 4 ); +#endif if( cu.imv > 0 ) { +#if JVET_N600_AMVR_TPM_CTX_REDUCTION + m_BinEncoder.encodeBin( (cu.imv > 1), Ctx::ImvFlag( 3 ) ); + DTRACE( g_trace_ctx, D_SYNTAX, "affine_amvr_mode() value=%d ctx=%d\n", (cu.imv > 1), 3 ); +#else m_BinEncoder.encodeBin( ( cu.imv > 1 ), Ctx::ImvFlag( 5 ) ); DTRACE( g_trace_ctx, D_SYNTAX, "affine_amvr_mode() value=%d ctx=%d\n", ( cu.imv > 1 ), 5 ); +#endif } DTRACE( g_trace_ctx, D_SYNTAX, "affine_amvr_mode() IMVFlag=%d\n", cu.imv ); } @@ -1839,9 +1861,13 @@ void CABACWriter::triangle_mode( const CodingUnit& cu ) return; } +#if JVET_N600_AMVR_TPM_CTX_REDUCTION + m_BinEncoder.encodeBin( cu.triangle, Ctx::TriangleFlag(0) ); +#else unsigned flag_idx = DeriveCtx::CtxTriangleFlag( cu ); m_BinEncoder.encodeBin( cu.triangle, Ctx::TriangleFlag(flag_idx) ); +#endif DTRACE( g_trace_ctx, D_SYNTAX, "triangle_mode() triangle_mode=%d pos=(%d,%d) size: %dx%d\n", cu.triangle, cu.Y().x, cu.Y().y, cu.lumaSize().width, cu.lumaSize().height ); }