diff --git a/source/Lib/CommonLib/CommonDef.h b/source/Lib/CommonLib/CommonDef.h index 2e75a0cf63286d1fb9feacaddfefa084a5b4dd5b..d18049b69e172fa3b590fb3997ef2fa66cb0ed3e 100644 --- a/source/Lib/CommonLib/CommonDef.h +++ b/source/Lib/CommonLib/CommonDef.h @@ -445,6 +445,9 @@ static constexpr int MV_MIN = -(1 << (MV_BITS - 1)); static const int PIC_ANALYZE_CW_BINS = 32; static const int PIC_CODE_CW_BINS = 16; +#if JVET_O0272_LMCS_SIMP_INVERSE_MAPPING +static const int LMCS_SEG_SIZE = (PIC_CODE_CW_BINS << 1); +#endif static const int FP_PREC = 11; static const int CSCALE_FP_PREC = 11; #if JVET_O1109_UNFIY_CRS diff --git a/source/Lib/CommonLib/TypeDef.h b/source/Lib/CommonLib/TypeDef.h index ee3bda67deb97cc08833f49c3495aaee30b50120..ff277361404feae4e44e2972ad16e6258de1b43f 100644 --- a/source/Lib/CommonLib/TypeDef.h +++ b/source/Lib/CommonLib/TypeDef.h @@ -52,6 +52,8 @@ #define JVET_O0216_ALF_COEFF_EG3 1 // JVET-O0216/O0302/O0648: using EG3 for ALF coefficients coding +#define JVET_O0272_LMCS_SIMP_INVERSE_MAPPING 1 // JVET-O0272: LMCS simplified inverse mapping + #define JVET_O0247_ALF_CTB_CODING_REDUNDANCY_REMOVAL 1 // JVET-O0247: not signal APS index when number APS is 2 #define JVET_O0637_CHROMA_GRADIENT_LINE_SELECTION 1 // Choose line0 and line3 for gradient computation when chroma is same size as luma diff --git a/source/Lib/EncoderLib/EncReshape.cpp b/source/Lib/EncoderLib/EncReshape.cpp index 5abfc38ae4473d3251eedd4fb10abff155bf48e4..1217aea13849ae17d4a2ea4c4ae0068c6d506a98 100644 --- a/source/Lib/EncoderLib/EncReshape.cpp +++ b/source/Lib/EncoderLib/EncReshape.cpp @@ -1054,6 +1054,10 @@ void EncReshape::initLUTfromdQPModel() } #endif +#if JVET_O0272_LMCS_SIMP_INVERSE_MAPPING + adjustLmcsPivot(); +#endif + int maxAbsDeltaCW = 0, absDeltaCW = 0, deltaCW = 0; for (int i = m_sliceReshapeInfo.reshaperModelMinBinIdx; i <= m_sliceReshapeInfo.reshaperModelMaxBinIdx; i++) { @@ -1261,6 +1265,11 @@ void EncReshape::constructReshaperSDR() { m_binCW[i] = m_binCW[2 * i] + m_binCW[2 * i + 1]; } + +#if JVET_O0272_LMCS_SIMP_INVERSE_MAPPING + adjustLmcsPivot(); +#endif + m_sliceReshapeInfo.reshaperModelMinBinIdx = 0; m_sliceReshapeInfo.reshaperModelMaxBinIdx = PIC_CODE_CW_BINS - 1; for (int i = 0; i < PIC_CODE_CW_BINS; i++) @@ -1361,6 +1370,44 @@ void EncReshape::constructReshaperSDR() #endif } +#if JVET_O0272_LMCS_SIMP_INVERSE_MAPPING +void EncReshape::adjustLmcsPivot() +{ + int bdShift = m_lumaBD - 10; + int totCW = bdShift != 0 ? (bdShift > 0 ? m_reshapeLUTSize / (1 << bdShift) : m_reshapeLUTSize * (1 << (-bdShift))) : m_reshapeLUTSize; + int orgCW = totCW / PIC_CODE_CW_BINS; + int log2SegSize = g_aucLog2[LMCS_SEG_SIZE]; + m_reshapePivot[0] = 0; + for (int i = 0; i < PIC_CODE_CW_BINS; i++) + { + m_reshapePivot[i+1] = m_reshapePivot[i] + m_binCW[i]; + int segIdxCurr = (m_reshapePivot[i] >> log2SegSize); + int segIdxNext = (m_reshapePivot[i + 1] >> log2SegSize); + if ((segIdxCurr == segIdxNext) && (m_reshapePivot[i] != m_reshapePivot[i + 1]) && (m_reshapePivot[i] != (segIdxCurr << log2SegSize))) + { + int16_t adjustVal = ((segIdxCurr + 1) << log2SegSize) - m_reshapePivot[i + 1]; + m_reshapePivot[i + 1] += adjustVal; + m_binCW[i] += adjustVal; + for (int j = i + 1; j < PIC_CODE_CW_BINS; j++) + { + if (m_binCW[j] < (adjustVal + (orgCW >> 3))) + { + adjustVal -= (m_binCW[j] - (orgCW >> 3)); + m_binCW[j] = (orgCW >> 3); + } + else + { + m_binCW[j] -= adjustVal; + adjustVal = 0; + } + if (adjustVal == 0) + break; + } + } + } +} +#endif + #if ENABLE_SPLIT_PARALLELISM || ENABLE_WPP_PARALLELISM void EncReshape::copyState(const EncReshape &other) { diff --git a/source/Lib/EncoderLib/EncReshape.h b/source/Lib/EncoderLib/EncReshape.h index 6e4871866a05ae33047cd22d06befe504902211c..53bb44d423ca0dd839067aee7025ad68a3ab8a46 100644 --- a/source/Lib/EncoderLib/EncReshape.h +++ b/source/Lib/EncoderLib/EncReshape.h @@ -93,6 +93,9 @@ public: ReshapeCW * getReshapeCW() { return &m_reshapeCW; } Pel * getWeightTable() { return m_cwLumaWeight; } double getCWeight() { return m_chromaWeight; } +#if JVET_O0272_LMCS_SIMP_INVERSE_MAPPING + void adjustLmcsPivot(); +#endif #if ENABLE_SPLIT_PARALLELISM || ENABLE_WPP_PARALLELISM void copyState(const EncReshape& other);