diff --git a/source/Lib/CommonLib/ContextModelling.h b/source/Lib/CommonLib/ContextModelling.h index 4fb7a2ae9ec8e33eed35b3d3e46cefdebd969478..297e5c078df4b8fe78c6ea5e3080a0f006963de8 100644 --- a/source/Lib/CommonLib/ContextModelling.h +++ b/source/Lib/CommonLib/ContextModelling.h @@ -228,31 +228,17 @@ public: } } - unsigned templateAbsCompare(TCoeff sum) + static unsigned templateAbsCompare(TCoeff sum) { - int rangeIdx = 0; - if (sum < g_riceT[0]) + for (int rangeIdx = 0; rangeIdx < g_riceThreshold.size(); rangeIdx++) { - rangeIdx = 0; - } - else if (sum < g_riceT[1]) - { - rangeIdx = 1; - } - else if (sum < g_riceT[2]) - { - rangeIdx = 2; - } - else if (sum < g_riceT[3]) - { - rangeIdx = 3; - } - else - { - rangeIdx = 4; + if (sum < g_riceThreshold[rangeIdx]) + { + return g_riceShift[rangeIdx]; + } } - return g_riceShift[rangeIdx]; + return g_riceShift[g_riceThreshold.size()]; } unsigned templateAbsSumExt(int scanPos, const TCoeff* coeff, int baseLevel) @@ -304,7 +290,7 @@ public: sum += m_histValue; } - int currentShift = templateAbsCompare(sum); + const int currentShift = templateAbsCompare(sum); sum = sum >> currentShift; if (baseLevel == 0) { diff --git a/source/Lib/CommonLib/DepQuant.cpp b/source/Lib/CommonLib/DepQuant.cpp index d3ef12a61bda2c7500cda72e8fa67460b1638b8d..244608e0c88546e48899ca85b8ffabcf603bb1bc 100644 --- a/source/Lib/CommonLib/DepQuant.cpp +++ b/source/Lib/CommonLib/DepQuant.cpp @@ -1071,32 +1071,6 @@ namespace DQIntern unsigned effHeight; }; - unsigned templateAbsCompare(TCoeff sum) - { - int rangeIdx = 0; - if (sum < g_riceT[0]) - { - rangeIdx = 0; - } - else if (sum < g_riceT[1]) - { - rangeIdx = 1; - } - else if (sum < g_riceT[2]) - { - rangeIdx = 2; - } - else if (sum < g_riceT[3]) - { - rangeIdx = 3; - } - else - { - rangeIdx = 4; - } - return g_riceShift[rangeIdx]; - } - State::State( const RateEstimator& rateEst, CommonCtx& commonCtx, const int stateId ) : m_sbbFracBits { { 0, 0 } } , m_stateId ( stateId ) @@ -1215,7 +1189,7 @@ namespace DQIntern #undef UPDATE if (extRiceFlag) { - unsigned currentShift = templateAbsCompare(sumAbs); + unsigned currentShift = CoeffCodingContext::templateAbsCompare(sumAbs); sumAbs = sumAbs >> currentShift; int sumAll = std::max(std::min(31, (int)sumAbs - (int)baseLevel), 0); m_goRicePar = g_goRiceParsCoeff[sumAll]; @@ -1264,7 +1238,7 @@ namespace DQIntern #undef UPDATE if (extRiceFlag) { - unsigned currentShift = templateAbsCompare(sumAbs); + unsigned currentShift = CoeffCodingContext::templateAbsCompare(sumAbs); sumAbs = sumAbs >> currentShift; sumAbs = std::min<TCoeff>(31, sumAbs); m_goRicePar = g_goRiceParsCoeff[sumAbs]; diff --git a/source/Lib/CommonLib/Rom.cpp b/source/Lib/CommonLib/Rom.cpp index 2a321e379ec01830b3f189d8bd8d7a27d27dcdce..19b9bff90c5f67320d06c8c95ffc84b2c5f93676 100644 --- a/source/Lib/CommonLib/Rom.cpp +++ b/source/Lib/CommonLib/Rom.cpp @@ -522,8 +522,10 @@ UnitScale g_miScaling( MIN_CU_LOG2, MIN_CU_LOG2 ); // ==================================================================================================================== // Scanning order & context model mapping // ==================================================================================================================== -int g_riceT[4] = { 32,128, 512, 2048 }; -int g_riceShift[5] = { 0, 2, 4, 6, 8 }; +const std::array<TCoeff, 4> g_riceThreshold = { 32, 128, 512, 2048 }; + +const std::array<uint8_t, g_riceThreshold.size() + 1> g_riceShift = { 0, 2, 4, 6, 8 }; + // scanning order table EnumArray<ScanElement *[MAX_CU_SIZE / 2 + 1][MAX_CU_SIZE / 2 + 1], CoeffScanType> g_scanOrder[SCAN_NUMBER_OF_GROUP_TYPES]; ScanElement g_coefTopLeftDiagScan8x8[ MAX_CU_SIZE / 2 + 1 ][ 64 ]; diff --git a/source/Lib/CommonLib/Rom.h b/source/Lib/CommonLib/Rom.h index 366181a486a954a6090a5bbb344ea21cbd6de85f..b61149d9897c62d75ca8bb0a3194cc7c0f0a0038 100644 --- a/source/Lib/CommonLib/Rom.h +++ b/source/Lib/CommonLib/Rom.h @@ -87,8 +87,10 @@ static const int g_transformMatrixShift[TRANSFORM_NUMBER_OF_DIRECTIONS] = { 6, // ==================================================================================================================== // Scanning order & context mapping table // ==================================================================================================================== -extern int g_riceT[4]; -extern int g_riceShift[5]; +extern const std::array<TCoeff, 4> g_riceThreshold; + +extern const std::array<uint8_t, g_riceThreshold.size() + 1> g_riceShift; + extern const uint32_t g_groupIdx[MAX_TB_SIZEY]; extern const uint32_t g_minInGroup[LAST_SIGNIFICANT_GROUPS]; extern const uint32_t g_goRiceParsCoeff[32];