diff --git a/source/Lib/EncoderLib/EncAdaptiveLoopFilter.cpp b/source/Lib/EncoderLib/EncAdaptiveLoopFilter.cpp index c64f4eb330e7ae0f22863318c6daac38d143239a..f2a0ae7971872021869c4f9f5a9bfbfdf793e660 100644 --- a/source/Lib/EncoderLib/EncAdaptiveLoopFilter.cpp +++ b/source/Lib/EncoderLib/EncAdaptiveLoopFilter.cpp @@ -1494,7 +1494,13 @@ int EncAdaptiveLoopFilter::getChromaCoeffRate( AlfParam& alfParam, int altIdx ) // Filter coefficients for( int i = 0; i < alfShape.numCoeff - 1; i++ ) { - iBits += lengthGolomb( alfParam.chromaCoeff[altIdx][i], 3 ); // alf_coeff_chroma[altIdx][i] +#if JVET_Q0210_UEK_REMOVAL + iBits += lengthUvlc( abs( alfParam.chromaCoeff[ altIdx ][ i ] ) ); // alf_coeff_chroma[altIdx][i] + if( ( alfParam.chromaCoeff[ altIdx ][ i ] ) != 0 ) + iBits += 1; +#else + iBits += lengthGolomb( alfParam.chromaCoeff[ altIdx ][ i ], 3 ); // alf_coeff_chroma[altIdx][i] +#endif } #if JVET_Q0249_ALF_CHROMA_CLIPFLAG if( m_alfParamTemp.nonLinearFlag[CHANNEL_TYPE_CHROMA] ) @@ -1661,14 +1667,24 @@ int EncAdaptiveLoopFilter::getCostFilterCoeffForce0( AlfFilterShape& alfShape, i { for( int i = 0; i < alfShape.numCoeff - 1; i++ ) { - len += lengthGolomb( abs( pDiffQFilterCoeffIntPP[ind][i] ), 3 ); // alf_coeff_luma_delta[i][j] +#if JVET_Q0210_UEK_REMOVAL + len += lengthUvlc( abs( pDiffQFilterCoeffIntPP[ ind ][ i ] ) ); // alf_coeff_luma_delta[i][j] + if( ( abs( pDiffQFilterCoeffIntPP[ ind ][ i ] ) != 0 ) ) + len += 1; +#else + len += lengthGolomb( abs( pDiffQFilterCoeffIntPP[ ind ][ i ] ), 3 ); // alf_coeff_luma_delta[i][j] +#endif } } else { for (int i = 0; i < alfShape.numCoeff - 1; i++) { - len += lengthGolomb(0, 3); // alf_coeff_luma_delta[i][j] +#if JVET_Q0210_UEK_REMOVAL + len += lengthUvlc( 0 ); // alf_coeff_luma_delta[i][j] +#else + len += lengthGolomb( 0, 3 ); // alf_coeff_luma_delta[i][j] +#endif } } } @@ -1727,7 +1743,13 @@ int EncAdaptiveLoopFilter::lengthFilterCoeffs( AlfFilterShape& alfShape, const i { for( int i = 0; i < alfShape.numCoeff - 1; i++ ) { - bitCnt += lengthGolomb( abs( FilterCoeff[ind][i] ), 3 ); +#if JVET_Q0210_UEK_REMOVAL + bitCnt += lengthUvlc( abs( FilterCoeff[ ind ][ i ] ) ); + if( abs( FilterCoeff[ ind ][ i ] ) != 0 ) + bitCnt += 1; +#else + bitCnt += lengthGolomb( abs( FilterCoeff[ ind ][ i ] ), 3 ); +#endif } } return bitCnt; @@ -1743,14 +1765,24 @@ double EncAdaptiveLoopFilter::getDistForce0( AlfFilterShape& alfShape, const int bitsVarBin[ind] = 0; for( int i = 0; i < alfShape.numCoeff - 1; i++ ) { - bitsVarBin[ind] += lengthGolomb( abs( m_filterCoeffSet[ind][i] ), 3 ); +#if JVET_Q0210_UEK_REMOVAL + bitsVarBin[ ind ] += lengthUvlc( abs( m_filterCoeffSet[ ind ][ i ] ) ); + if( abs( m_filterCoeffSet[ ind ][ i ] ) != 0 ) + bitsVarBin[ ind ] += 1; +#else + bitsVarBin[ ind ] += lengthGolomb( abs( m_filterCoeffSet[ ind ][ i ] ), 3 ); +#endif } } static int zeroBitsVarBin = 0; for (int i = 0; i < alfShape.numCoeff - 1; i++) { - zeroBitsVarBin += lengthGolomb(0, 3); +#if JVET_Q0210_UEK_REMOVAL + zeroBitsVarBin += lengthUvlc( 0 ); +#else + zeroBitsVarBin += lengthGolomb( 0, 3 ); +#endif } #if JVET_Q0249_ALF_CHROMA_CLIPFLAG if( m_alfParamTemp.nonLinearFlag[CHANNEL_TYPE_LUMA] ) @@ -1805,23 +1837,25 @@ int EncAdaptiveLoopFilter::lengthUvlc( int uiCode ) return ( uiLength >> 1 ) + ( ( uiLength + 1 ) >> 1 ); } +#if !JVET_Q0210_UEK_REMOVAL int EncAdaptiveLoopFilter::lengthGolomb( int coeffVal, int k, bool signed_coeff ) { int numBins = 0; - unsigned int symbol = abs(coeffVal); - while (symbol >= (unsigned int)(1 << k)) + unsigned int symbol = abs( coeffVal ); + while( symbol >= ( unsigned int ) ( 1 << k ) ) { numBins++; symbol -= 1 << k; k++; } - numBins += ( k + 1) ; - if (signed_coeff && coeffVal != 0) + numBins += ( k + 1 ); + if( signed_coeff && coeffVal != 0 ) { numBins++; } return numBins; } +#endif double EncAdaptiveLoopFilter::deriveFilterCoeffs( AlfCovariance* cov, AlfCovariance* covMerged, int clipMerged[MAX_NUM_ALF_CLASSES][MAX_NUM_ALF_CLASSES][MAX_NUM_ALF_LUMA_COEFF], AlfFilterShape& alfShape, short* filterIndices, int numFilters, double errorTabForce0Coeff[MAX_NUM_ALF_CLASSES][2], AlfParam& alfParam ) { diff --git a/source/Lib/EncoderLib/EncAdaptiveLoopFilter.h b/source/Lib/EncoderLib/EncAdaptiveLoopFilter.h index b477b532484c5f5ad72f220007bce9d28d0b8731..2f10736366dd0dd5b41996e34ef7d130958e9a76 100644 --- a/source/Lib/EncoderLib/EncAdaptiveLoopFilter.h +++ b/source/Lib/EncoderLib/EncAdaptiveLoopFilter.h @@ -310,7 +310,9 @@ public: void initCABACEstimator( CABACEncoder* cabacEncoder, CtxCache* ctxCache, Slice* pcSlice, ParameterSetMap<APS>* apsMap ); void create( const EncCfg* encCfg, const int picWidth, const int picHeight, const ChromaFormat chromaFormatIDC, const int maxCUWidth, const int maxCUHeight, const int maxCUDepth, const int inputBitDepth[MAX_NUM_CHANNEL_TYPE], const int internalBitDepth[MAX_NUM_CHANNEL_TYPE] ); void destroy(); - static int lengthGolomb( int coeffVal, int k, bool signed_coeff=true ); +#if !JVET_Q0210_UEK_REMOVAL + static int lengthGolomb( int coeffVal, int k, bool signed_coeff = true ); +#endif void setApsIdStart( int i) { m_apsIdStart = i; } private: