diff --git a/source/Lib/CommonLib/TypeDef.h b/source/Lib/CommonLib/TypeDef.h index 03030a64c15f583fe41a8f7ec0a11e3496add319..93dd3053726c3bea6ef88d5692f5c25b40546d17 100644 --- a/source/Lib/CommonLib/TypeDef.h +++ b/source/Lib/CommonLib/TypeDef.h @@ -235,6 +235,8 @@ #define JVET_O0610_CFG 1 // config default change for "Adopt to mandate the presence of AU delimiter for each AU", config parameter should be removed later +#define JVET_O0491_HLS_CLEANUP 1 + #define JVET_O0376_SPS_JOINTCBCR_FLAG 1 // JVET-O0376: add the JointCbCr control flag in SPS #define JVET_O0472_LFNST_SIGNALLING_LAST_SCAN_POS 1 // JVET-O0472: LFNST index signalling depends on the position of last significant coefficient diff --git a/source/Lib/DecoderLib/VLCReader.cpp b/source/Lib/DecoderLib/VLCReader.cpp index 43ec52ffbf19a27a395b469152dbac374e1c5a00..e3d99d15dab112cb84a554820d1af57f18404736 100644 --- a/source/Lib/DecoderLib/VLCReader.cpp +++ b/source/Lib/DecoderLib/VLCReader.cpp @@ -823,13 +823,24 @@ void HLSyntaxReader::parseAlfAps( APS* aps ) #else param.nonLinearFlag[CHANNEL_TYPE_LUMA] = code ? true : false; #endif +#if JVET_O0491_HLS_CLEANUP + READ_UVLC(code, "alf_luma_num_filters_signalled_minus1"); +#else xReadTruncBinCode(code, MAX_NUM_ALF_CLASSES); //number_of_filters_minus1 +#endif param.numLumaFilters = code + 1; if (param.numLumaFilters > 1) { +#if JVET_O0491_HLS_CLEANUP + const int length = (int)ceil(log2(param.numLumaFilters)); +#endif for (int i = 0; i < MAX_NUM_ALF_CLASSES; i++) { +#if JVET_O0491_HLS_CLEANUP + READ_CODE(length, code, "alf_luma_coeff_delta_idx"); +#else xReadTruncBinCode(code, param.numLumaFilters); +#endif param.filterCoeffDeltaIdx[i] = code; } } @@ -1911,7 +1922,11 @@ void HLSyntaxReader::parseSliceHeader (Slice* pcSlice, ParameterSetManager *para if (bChroma) { #endif +#if JVET_O0491_HLS_CLEANUP + READ_CODE(2, uiCode, "slice_alf_chroma_idc"); alfChromaIdc = uiCode; +#else alfChromaIdc = truncatedUnaryEqProb(3); //alf_chroma_idc +#endif #if JVET_O0616_400_CHROMA_SUPPORT } else @@ -2999,6 +3014,7 @@ void HLSyntaxReader::alfFilter( AlfParam& alfParam, const bool isChroma ) } } +#if !JVET_O0491_HLS_CLEANUP int HLSyntaxReader::truncatedUnaryEqProb( const int maxSymbol ) { for( int k = 0; k < maxSymbol; k++ ) @@ -3057,6 +3073,7 @@ void HLSyntaxReader::xReadTruncBinCode( uint32_t& ruiSymbol, const int uiMaxSymb ruiSymbol -= ( uiVal - b ); } } +#endif //! \} diff --git a/source/Lib/DecoderLib/VLCReader.h b/source/Lib/DecoderLib/VLCReader.h index 9f50ab02772a4f908e718ec2211851f42fbc0dbf..fb11bd8807581378a177a768b5f79241caccff38 100644 --- a/source/Lib/DecoderLib/VLCReader.h +++ b/source/Lib/DecoderLib/VLCReader.h @@ -172,8 +172,10 @@ public: #endif private: +#if !JVET_O0491_HLS_CLEANUP int truncatedUnaryEqProb( const int maxSymbol ); void xReadTruncBinCode( uint32_t& ruiSymbol, const int uiMaxSymbol ); +#endif int alfGolombDecode( const int k, const bool signed_val=true ); protected: diff --git a/source/Lib/EncoderLib/EncAdaptiveLoopFilter.cpp b/source/Lib/EncoderLib/EncAdaptiveLoopFilter.cpp index 2f6037cbb70d69c2fb554f4d672df85668fad650..8b99806708dbc164b57cfe7907eec98abb574df5 100644 --- a/source/Lib/EncoderLib/EncAdaptiveLoopFilter.cpp +++ b/source/Lib/EncoderLib/EncAdaptiveLoopFilter.cpp @@ -966,8 +966,12 @@ double EncAdaptiveLoopFilter::deriveCtbAlfEnableFlags( CodingStructure& cs, cons if( isChroma( channel ) ) { setEnableFlag(m_alfParamTemp, channel, m_ctuEnableFlag); +#if !JVET_O0491_HLS_CLEANUP const int alfChromaIdc = m_alfParamTemp.enabledFlag[COMPONENT_Cb] * 2 + m_alfParamTemp.enabledFlag[COMPONENT_Cr]; cost += lengthTruncatedUnary(alfChromaIdc, 3) * m_lambda[channel]; +#else + cost += 2 * m_lambda[channel]; // slice_alf_chroma_idc u(2) +#endif } return cost; @@ -1161,7 +1165,9 @@ double EncAdaptiveLoopFilter::getFilterCoeffAndCost( CodingStructure& cs, double double dist = distUnfilter; uiCoeffBits = 0; +#if !JVET_O0491_HLS_CLEANUP int uiSliceFlag = 0; +#endif AlfFilterShape& alfFilterShape = m_alfParamTemp.filterShapes[channel][iShapeIdx]; //get filter coeff if( isLuma( channel ) ) @@ -1185,8 +1191,10 @@ double EncAdaptiveLoopFilter::getFilterCoeffAndCost( CodingStructure& cs, double std::fill_n(m_filterClippSet[0], MAX_NUM_ALF_CHROMA_COEFF, m_alfParamTemp.nonLinearFlag[channel] ? AlfNumClippingValues[CHANNEL_TYPE_CHROMA] / 2 : 0); dist += m_alfCovarianceFrame[channel][iShapeIdx][0].pixAcc + deriveCoeffQuant( m_filterClippSet[0], m_filterCoeffSet[0], m_alfCovarianceFrame[channel][iShapeIdx][0], alfFilterShape, m_NUM_BITS, m_alfParamTemp.nonLinearFlag[channel] ); #endif +#if !JVET_O0491_HLS_CLEANUP //setEnableFlag( m_alfParamTemp, channel, m_ctuEnableFlag ); const int alfChromaIdc = m_alfParamTemp.enabledFlag[COMPONENT_Cb] * 2 + m_alfParamTemp.enabledFlag[COMPONENT_Cr]; +#endif #if JVET_O0090_ALF_CHROMA_FILTER_ALTERNATIVES_CTB for( int altIdx = 0; altIdx < m_alfParamTemp.numAlternativesChroma; ++altIdx ) { @@ -1224,8 +1232,10 @@ double EncAdaptiveLoopFilter::getFilterCoeffAndCost( CodingStructure& cs, double } uiCoeffBits += lengthUvlc( m_alfParamTemp.numAlternativesChroma-1 ); uiCoeffBits += m_alfParamTemp.numAlternativesChroma; // non-linear flags +#if !JVET_O0491_HLS_CLEANUP uiSliceFlag = lengthTruncatedUnary(alfChromaIdc, 3) - lengthTruncatedUnary( 0, 3 ); // rate already put on Luma +#endif #else for( int i = 0; i < MAX_NUM_ALF_CHROMA_COEFF; i++ ) { @@ -1240,7 +1250,11 @@ double EncAdaptiveLoopFilter::getFilterCoeffAndCost( CodingStructure& cs, double { return dist + m_lambda[channel] * uiCoeffBits; } +#if !JVET_O0491_HLS_CLEANUP double rate = uiCoeffBits + uiSliceFlag; +#else + double rate = uiCoeffBits; +#endif m_CABACEstimator->resetBits(); m_CABACEstimator->codeAlfCtuEnableFlags( cs, channel, &m_alfParamTemp); #if JVET_O0090_ALF_CHROMA_FILTER_ALTERNATIVES_CTB @@ -1421,7 +1435,11 @@ double EncAdaptiveLoopFilter::getUnfilteredDistortion( AlfCovariance* cov, Chann } else { +#if !JVET_O0491_HLS_CLEANUP dist = getUnfilteredDistortion( cov, 1 ) + lengthTruncatedUnary( 0, 3 ) * m_lambda[COMPONENT_Cb]; +#else + dist = getUnfilteredDistortion( cov, 1 ) + 2 * m_lambda[COMPONENT_Cb]; // slice_alf_chroma_idc u(2) +#endif } return dist; } @@ -1579,14 +1597,26 @@ double EncAdaptiveLoopFilter::mergeFiltersAndCost( AlfParam& alfParam, AlfFilter int EncAdaptiveLoopFilter::getNonFilterCoeffRate( AlfParam& alfParam ) { int len = 1 // alf_coefficients_delta_flag +#if !JVET_O0491_HLS_CLEANUP + lengthTruncatedUnary( 0, 3 ) // chroma_idc = 0, it is signalled when ALF is enabled for luma + getTBlength( alfParam.numLumaFilters - 1, MAX_NUM_ALF_CLASSES ); //numLumaFilters +#else + + 2 // slice_alf_chroma_idc u(2) + + lengthUvlc (alfParam.numLumaFilters - 1); // alf_luma_num_filters_signalled_minus1 ue(v) +#endif if( alfParam.numLumaFilters > 1 ) { +#if JVET_O0491_HLS_CLEANUP + const int coeffLength = (int)ceil(log2(alfParam.numLumaFilters)); +#endif for( int i = 0; i < MAX_NUM_ALF_CLASSES; i++ ) { +#if !JVET_O0491_HLS_CLEANUP len += getTBlength( (int)alfParam.filterCoeffDeltaIdx[i], alfParam.numLumaFilters ); //filter_coeff_delta[i] +#else + len += coeffLength; // alf_luma_coeff_delta_idx u(v) +#endif } } #if !JVET_O0669_REMOVE_ALF_COEFF_PRED @@ -1602,6 +1632,7 @@ int EncAdaptiveLoopFilter::getNonFilterCoeffRate( AlfParam& alfParam ) return len; } +#if !JVET_O0491_HLS_CLEANUP int EncAdaptiveLoopFilter::lengthTruncatedUnary( int symbol, int maxSymbol ) { if( maxSymbol == 0 ) @@ -1657,6 +1688,7 @@ int EncAdaptiveLoopFilter::getTBlength( int uiSymbol, const int uiMaxSymbol ) return uiThresh + 1; } } +#endif int EncAdaptiveLoopFilter::getCostFilterCoeffForce0( AlfFilterShape& alfShape, int **pDiffQFilterCoeffIntPP, const int numFilters, bool* codedVarBins ) { @@ -3537,9 +3569,13 @@ void EncAdaptiveLoopFilter::alfEncoderCtb(CodingStructure& cs, AlfParam& alfPar } //chroma idc setEnableFlag(m_alfParamTemp, CHANNEL_TYPE_CHROMA, m_ctuEnableFlag); +#if !JVET_O0491_HLS_CLEANUP const int alfChromaIdc = m_alfParamTemp.enabledFlag[COMPONENT_Cb] * 2 + m_alfParamTemp.enabledFlag[COMPONENT_Cr]; +#endif #if JVET_O0090_ALF_CHROMA_FILTER_ALTERNATIVES_CTB +#if !JVET_O0491_HLS_CLEANUP curCost += (lengthTruncatedUnary(alfChromaIdc, 3) - lengthTruncatedUnary(0, 3)) * m_lambda[CHANNEL_TYPE_CHROMA]; +#endif #else curCost += lengthTruncatedUnary(alfChromaIdc, 3) * m_lambda[CHANNEL_TYPE_CHROMA]; #endif diff --git a/source/Lib/EncoderLib/EncAdaptiveLoopFilter.h b/source/Lib/EncoderLib/EncAdaptiveLoopFilter.h index ffe5913604727b773b2a2115b4ce9da93d1905d2..0f80c5a502bfe9b9a42e0de6da987230e2af9e10 100644 --- a/source/Lib/EncoderLib/EncAdaptiveLoopFilter.h +++ b/source/Lib/EncoderLib/EncAdaptiveLoopFilter.h @@ -336,10 +336,14 @@ private: void roundFiltCoeff( int *filterCoeffQuant, double *filterCoeff, const int numCoeff, const int factor ); double getDistCoeffForce0( bool* codedVarBins, double errorForce0CoeffTab[MAX_NUM_ALF_CLASSES][2], int* bitsVarBin, const int numFilters ); +#if !JVET_O0491_HLS_CLEANUP int lengthTruncatedUnary( int symbol, int maxSymbol ); +#endif int lengthUvlc( int uiCode ); int getNonFilterCoeffRate( AlfParam& alfParam ); +#if !JVET_O0491_HLS_CLEANUP int getTBlength( int uiSymbol, const int uiMaxSymbol ); +#endif int getCostFilterCoeffForce0( AlfFilterShape& alfShape, int **pDiffQFilterCoeffIntPP, const int numFilters, bool* codedVarBins ); int getCostFilterCoeff( AlfFilterShape& alfShape, int **pDiffQFilterCoeffIntPP, const int numFilters ); diff --git a/source/Lib/EncoderLib/VLCWriter.cpp b/source/Lib/EncoderLib/VLCWriter.cpp index a2042418f128378eb9b83ed1a3db3bed4653d314..f1b518c78d50b628956d73ec6f73ba34e3e05685 100644 --- a/source/Lib/EncoderLib/VLCWriter.cpp +++ b/source/Lib/EncoderLib/VLCWriter.cpp @@ -511,12 +511,23 @@ void HLSWriter::codeAlfAps( APS* pcAPS ) WRITE_FLAG( param.nonLinearFlag[CHANNEL_TYPE_LUMA], "alf_luma_clip" ); #endif +#if JVET_O0491_HLS_CLEANUP + WRITE_UVLC(param.numLumaFilters - 1, "alf_luma_num_filters_signalled_minus1"); +#else xWriteTruncBinCode(param.numLumaFilters - 1, MAX_NUM_ALF_CLASSES); //number_of_filters_minus1 +#endif if (param.numLumaFilters > 1) { +#if JVET_O0491_HLS_CLEANUP + const int length = (int)ceil(log2( param.numLumaFilters)); +#endif for (int i = 0; i < MAX_NUM_ALF_CLASSES; i++) { +#if JVET_O0491_HLS_CLEANUP + WRITE_CODE(param.filterCoeffDeltaIdx[i], length, "alf_luma_coeff_delta_idx" ); +#else xWriteTruncBinCode((uint32_t)param.filterCoeffDeltaIdx[i], param.numLumaFilters); //filter_coeff_delta[i] +#endif } } #if !JVET_O0669_REMOVE_ALF_COEFF_PRED @@ -1348,7 +1359,11 @@ void HLSWriter::codeSliceHeader ( Slice* pcSlice ) if (chromaEnabled) { #endif +#if JVET_O0491_HLS_CLEANUP + WRITE_CODE(alfChromaIdc, 2, "slice_alf_chroma_idc"); +#else truncatedUnaryEqProb(alfChromaIdc, 3); // alf_chroma_idc +#endif #if JVET_O0616_400_CHROMA_SUPPORT } #endif @@ -2159,6 +2174,7 @@ void HLSWriter::alfFilter( const AlfParam& alfParam, const bool isChroma ) } } +#if !JVET_O0491_HLS_CLEANUP void HLSWriter::xWriteTruncBinCode( uint32_t uiSymbol, const int uiMaxSymbol ) { int uiThresh; @@ -2222,5 +2238,6 @@ void HLSWriter::truncatedUnaryEqProb( int symbol, const int maxSymbol ) CHECK( !( numBins <= 32 ), "Unspecified error" ); xWriteCode( bins, numBins ); } +#endif //! \} diff --git a/source/Lib/EncoderLib/VLCWriter.h b/source/Lib/EncoderLib/VLCWriter.h index b8faebb299fd7c72cf94f47a90f057c99647136b..65e6fb49ee8040c58a8a39238f33b654ef3c8635 100644 --- a/source/Lib/EncoderLib/VLCWriter.h +++ b/source/Lib/EncoderLib/VLCWriter.h @@ -148,10 +148,11 @@ public: #endif private: - void xWriteTruncBinCode( uint32_t uiSymbol, const int uiMaxSymbol ); void alfGolombEncode( const int coeff, const int k, const bool signed_coeff=true ); +#if !JVET_O0491_HLS_CLEANUP + void xWriteTruncBinCode( uint32_t uiSymbol, const int uiMaxSymbol ); void truncatedUnaryEqProb( int symbol, int maxSymbol ); - +#endif void codeReshaper ( const SliceReshapeInfo& pSliceReshaperInfo, const SPS* pcSPS, const bool isIntra); };