diff --git a/source/Lib/CommonLib/BinaryDecisionTree.cpp b/source/Lib/CommonLib/BinaryDecisionTree.cpp index 2fa1f97cc03e0b766e1b0895b02f4550ac3c7ddb..db6492688bd70ea46f6b41b511cf7d3e4597f400 100644 --- a/source/Lib/CommonLib/BinaryDecisionTree.cpp +++ b/source/Lib/CommonLib/BinaryDecisionTree.cpp @@ -38,6 +38,8 @@ #include "BinaryDecisionTree.h" #include "CommonDef.h" +#if !REMOVE_BIN_DECISION_TREE + #include <algorithm> struct DecisionTreeBuilder @@ -183,3 +185,5 @@ void DecisionTree::reduce( unsigned offset /*= 0*/, int depth /*= -1 */ ) isAvail[offset] = avail; } + +#endif diff --git a/source/Lib/CommonLib/BinaryDecisionTree.h b/source/Lib/CommonLib/BinaryDecisionTree.h index 271be4529e69cf35bf6e71f9d0bc1da5c5f39811..7ab0d6558cd9ece144e9545591a441480d742214 100644 --- a/source/Lib/CommonLib/BinaryDecisionTree.h +++ b/source/Lib/CommonLib/BinaryDecisionTree.h @@ -40,6 +40,8 @@ #include "CommonDef.h" +#if !REMOVE_BIN_DECISION_TREE + #define MAX_DEPTH_DECISION_TREE 5 #define MAX_NODES_DECISION_TREE ( 2 * ( 1 << MAX_DEPTH_DECISION_TREE ) ) @@ -92,3 +94,5 @@ DecisionTreeBuilder* decision( unsigned id, DecisionTreeBuilder* sub0, DecisionT DecisionTreeBuilder* decision( unsigned id, unsigned id0, DecisionTreeBuilder* sub1 ); #endif + +#endif diff --git a/source/Lib/CommonLib/Rom.cpp b/source/Lib/CommonLib/Rom.cpp index 5ae6612d5944d43ab9242a1f1e84a2c4214b3bea..1a2b16977b27c1efe261d226695d3aad2c3c4368 100644 --- a/source/Lib/CommonLib/Rom.cpp +++ b/source/Lib/CommonLib/Rom.cpp @@ -619,7 +619,7 @@ const uint8_t g_chroma422IntraAngleMappingTable[NUM_INTRA_MODE] = { 0, 1, 2, 2, 2, 2, 2, 2, 2, 3, 4, 6, 8, 10, 12, 13, 14, 16, 18, 20, 22, 23, 24, 26, 28, 30, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 44, 44, 45, 46, 46, 46, 47, 48, 48, 48, 49, 50, 51, 52, 52, 52, 53, 54, 54, 54, 55, 56, 56, 56, 57, 58, 59, 60, DM_CHROMA_IDX }; - +#if !REMOVE_BIN_DECISION_TREE // ==================================================================================================================== // Decision tree templates // ==================================================================================================================== @@ -635,6 +635,7 @@ const DecisionTreeTemplate g_mtSplitDTT = compile( /*0*/ DTT_SPLIT_TT_VERT, /*1*/ DTT_SPLIT_BT_VERT ) ) ) ); +#endif // ==================================================================================================================== diff --git a/source/Lib/CommonLib/Rom.h b/source/Lib/CommonLib/Rom.h index df42ecc8f5862ce7f546e1f25162ec795a075213..93494b89493c8a3dc8a2c90281a1e77d7b6c3fda 100644 --- a/source/Lib/CommonLib/Rom.h +++ b/source/Lib/CommonLib/Rom.h @@ -132,6 +132,7 @@ extern const TMatrixCoeff g_trCoreDST7P8 [TRANSFORM_NUMBER_OF_DIRECTIONS][ 8][ extern const TMatrixCoeff g_trCoreDST7P16 [TRANSFORM_NUMBER_OF_DIRECTIONS][ 16][ 16]; extern const TMatrixCoeff g_trCoreDST7P32 [TRANSFORM_NUMBER_OF_DIRECTIONS][ 32][ 32]; +#if !REMOVE_BIN_DECISION_TREE // ==================================================================================================================== // Decision tree templates // ==================================================================================================================== @@ -155,6 +156,7 @@ extern const DecisionTreeTemplate g_mtSplitDTT; // decision tree for QTBT split extern const DecisionTreeTemplate g_qtbtSplitDTT; +#endif // ==================================================================================================================== // Misc. diff --git a/source/Lib/CommonLib/TypeDef.h b/source/Lib/CommonLib/TypeDef.h index b60bfdd4e99d78688d73f37a552e30744313f8de..63a0c44fa21b99accf5d1add93df1ef9ec1b2ce6 100644 --- a/source/Lib/CommonLib/TypeDef.h +++ b/source/Lib/CommonLib/TypeDef.h @@ -50,6 +50,8 @@ #include <assert.h> #include <cassert> +#define REMOVE_BIN_DECISION_TREE 1 + // clang-format off #define JVET_M0453_CABAC_ENGINE 1 diff --git a/source/Lib/DecoderLib/CABACReader.cpp b/source/Lib/DecoderLib/CABACReader.cpp index 4105d63632773fd5d513262abe07b85c6110eb4a..aa33ec56f58b7b0d6ece49103f9ad1e26cfb3fa4 100644 --- a/source/Lib/DecoderLib/CABACReader.cpp +++ b/source/Lib/DecoderLib/CABACReader.cpp @@ -606,6 +606,50 @@ PartSplit CABACReader::split_cu_mode_mt( CodingStructure& cs, Partitioner &parti unsigned width = partitioner.currArea().lumaSize().width; unsigned height = partitioner.currArea().lumaSize().height; +#if REMOVE_BIN_DECISION_TREE + unsigned btSCtxId = width == height ? 0 : ( width > height ? 1 : 2 ); + + const bool canNo = partitioner.canSplit( CU_DONT_SPLIT, cs ); + const bool canBh = partitioner.canSplit( CU_HORZ_SPLIT, cs ); + const bool canBv = partitioner.canSplit( CU_VERT_SPLIT, cs ); + const bool canTh = partitioner.canSplit( CU_TRIH_SPLIT, cs ); + const bool canTv = partitioner.canSplit( CU_TRIV_SPLIT, cs ); + + bool isSplit = canBh || canBv || canTh || canTv; + + if( canNo && isSplit ) + { + isSplit = m_BinDecoder.decodeBin( Ctx::BTSplitFlag( ctxIdBT ) ); + } + + if( !isSplit ) + { + DTRACE( g_trace_ctx, D_SYNTAX, "split_cu_mode_mt() ctx=%d split=%d\n", ctxIdBT, mode ); + + return mode; + } + + const bool canHor = canBh || canTh; + bool isVer = canBv || canTv; + + if( isVer && canHor ) + { + isVer = m_BinDecoder.decodeBin( Ctx::BTSplitFlag( 12 + btSCtxId ) ); + } + + const bool can14 = isVer ? canTv : canTh; + bool is12 = isVer ? canBv : canBh; + + if( is12 && can14 ) + { + is12 = m_BinDecoder.decodeBin( Ctx::BTSplitFlag( 15 ) ); + } + + if ( isVer && is12 ) mode = CU_VERT_SPLIT; + else if( isVer && !is12 ) mode = CU_TRIV_SPLIT; + else if( !isVer && is12 ) mode = CU_HORZ_SPLIT; + else mode = CU_TRIH_SPLIT; +#else DecisionTree dt( g_mtSplitDTT ); dt.setAvail( DTT_SPLIT_BT_HORZ, partitioner.canSplit( CU_HORZ_SPLIT, cs ) ); @@ -626,6 +670,7 @@ PartSplit CABACReader::split_cu_mode_mt( CodingStructure& cs, Partitioner &parti mode = id == DTT_SPLIT_NO_SPLIT ? CU_DONT_SPLIT : PartSplit( id ); +#endif DTRACE( g_trace_ctx, D_SYNTAX, "split_cu_mode_mt() ctx=%d split=%d\n", ctxIdBT, mode ); return mode; @@ -2577,7 +2622,7 @@ unsigned CABACReader::exp_golomb_eqprob( unsigned count ) return symbol; } - +#if !REMOVE_BIN_DECISION_TREE unsigned CABACReader::decode_sparse_dt( DecisionTree& dt ) { dt.reduce(); @@ -2626,3 +2671,4 @@ unsigned CABACReader::decode_sparse_dt( DecisionTree& dt ) return dt.dtt.ids[offset]; } +#endif diff --git a/source/Lib/DecoderLib/CABACReader.h b/source/Lib/DecoderLib/CABACReader.h index c1e2f3e75b73c95943a748ba3c4a7dee17bfab1e..89dcf70e7512f92140791d213e573c93bfae877b 100644 --- a/source/Lib/DecoderLib/CABACReader.h +++ b/source/Lib/DecoderLib/CABACReader.h @@ -137,7 +137,9 @@ private: unsigned unary_max_symbol ( unsigned ctxId0, unsigned ctxIdN, unsigned maxSymbol ); unsigned unary_max_eqprob ( unsigned maxSymbol ); unsigned exp_golomb_eqprob ( unsigned count ); +#if !REMOVE_BIN_DECISION_TREE unsigned decode_sparse_dt ( DecisionTree& dt ); +#endif unsigned get_num_bits_read () { return m_BinDecoder.getNumBitsRead(); } void xReadTruncBinCode(uint32_t& symbol, uint32_t maxSymbol); diff --git a/source/Lib/EncoderLib/CABACWriter.cpp b/source/Lib/EncoderLib/CABACWriter.cpp index d0d937ad47e37c4e6611d65d094bfbc8605cf2e2..0141988316c1581dd6fccf66d6cefd624360a93c 100644 --- a/source/Lib/EncoderLib/CABACWriter.cpp +++ b/source/Lib/EncoderLib/CABACWriter.cpp @@ -535,6 +535,49 @@ void CABACWriter::split_cu_mode_mt(const PartSplit split, const CodingStructure& unsigned width = partitioner.currArea().lumaSize().width; unsigned height = partitioner.currArea().lumaSize().height; +#if REMOVE_BIN_DECISION_TREE + unsigned btSCtxId = width == height ? 0 : ( width > height ? 1 : 2 ); + + const bool canNo = partitioner.canSplit( CU_DONT_SPLIT, cs ); + const bool canBh = partitioner.canSplit( CU_HORZ_SPLIT, cs ); + const bool canBv = partitioner.canSplit( CU_VERT_SPLIT, cs ); + const bool canTh = partitioner.canSplit( CU_TRIH_SPLIT, cs ); + const bool canTv = partitioner.canSplit( CU_TRIV_SPLIT, cs ); + + const bool canSplit = canBh || canBv || canTh || canTv; + const bool isNo = split == CU_DONT_SPLIT; + + if( canNo && canSplit ) + { + m_BinEncoder.encodeBin( !isNo, Ctx::BTSplitFlag( ctxIdBT ) ); + } + + if( isNo ) + { + DTRACE( g_trace_ctx, D_SYNTAX, "split_cu_mode_mt() ctx=%d split=%d\n", ctxIdBT, split ); + + return; + } + + const bool canHor = canBh || canTh; + const bool canVer = canBv || canTv; + const bool isVer = split == CU_VERT_SPLIT || split == CU_TRIV_SPLIT; + + if( canVer && canHor ) + { + m_BinEncoder.encodeBin( isVer, Ctx::BTSplitFlag( 12 + btSCtxId ) ); + } + + const bool can14 = isVer ? canTv : canTh; + const bool can12 = isVer ? canBv : canBh; + const bool is12 = isVer ? ( split == CU_VERT_SPLIT ) : ( split == CU_HORZ_SPLIT ); + + + if( can12 && can14 ) + { + m_BinEncoder.encodeBin( is12, Ctx::BTSplitFlag( 15 ) ); + } +#else DecisionTree dt( g_mtSplitDTT ); dt.setAvail( DTT_SPLIT_BT_HORZ, partitioner.canSplit( CU_HORZ_SPLIT, cs ) ); @@ -553,6 +596,7 @@ void CABACWriter::split_cu_mode_mt(const PartSplit split, const CodingStructure& encode_sparse_dt( dt, split == CU_DONT_SPLIT ? ( unsigned ) DTT_SPLIT_NO_SPLIT : ( unsigned ) split ); +#endif DTRACE(g_trace_ctx, D_SYNTAX, "split_cu_mode_mt() ctx=%d split=%d\n", ctxIdBT, split); } @@ -2468,6 +2512,7 @@ void CABACWriter::exp_golomb_eqprob( unsigned symbol, unsigned count ) m_BinEncoder.encodeBinsEP( bins, numBins ); } +#if !REMOVE_BIN_DECISION_TREE void CABACWriter::encode_sparse_dt( DecisionTree& dt, unsigned toCodeId ) { // propagate the sparsity information from end-nodes to intermediate nodes @@ -2517,6 +2562,7 @@ void CABACWriter::encode_sparse_dt( DecisionTree& dt, unsigned toCodeId ) return; } +#endif void CABACWriter::codeAlfCtuEnableFlags( CodingStructure& cs, ChannelType channel, AlfSliceParam* alfParam) { if( isLuma( channel ) ) diff --git a/source/Lib/EncoderLib/CABACWriter.h b/source/Lib/EncoderLib/CABACWriter.h index 6cc2e708e3109415ffed9f7f55a30015cb3b8191..46820c7be1372b559b2d33975fb9c78c6bf04a86 100644 --- a/source/Lib/EncoderLib/CABACWriter.h +++ b/source/Lib/EncoderLib/CABACWriter.h @@ -156,7 +156,9 @@ private: void unary_max_symbol ( unsigned symbol, unsigned ctxId0, unsigned ctxIdN, unsigned maxSymbol ); void unary_max_eqprob ( unsigned symbol, unsigned maxSymbol ); void exp_golomb_eqprob ( unsigned symbol, unsigned count ); +#if !REMOVE_BIN_DECISION_TREE void encode_sparse_dt ( DecisionTree& dt, unsigned toCodeId ); +#endif // statistic unsigned get_num_written_bits() { return m_BinEncoder.getNumWrittenBits(); }