Commit 17ee24b1 authored by Tangi Poirier's avatar Tangi Poirier Committed by Xiang Li

JVET-N600: AMVR flag and Triangle flag context reduction

parent 38943211
......@@ -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 )
{
......
......@@ -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);
}
......
......@@ -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
......
......@@ -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
......
......@@ -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 );
......
......@@ -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 );
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment