Commit 853763c5 authored by Xiang Li's avatar Xiang Li

Merge branch 'nanh/VVCSoftware_VTM-JVET-O0425/O0427/O0669-Alf-Coeff-No-Pred'

parents ff293e69 eba2625b
Pipeline #1849 passed with stage
......@@ -399,6 +399,7 @@ void AdaptiveLoopFilter::reconstructCoeff( AlfSliceParam& alfSliceParam, Channel
short* coeff = isLuma( channel ) ? alfSliceParam.lumaCoeff : alfSliceParam.chromaCoeff;
short* clipp = isLuma( channel ) ? alfSliceParam.lumaClipp : alfSliceParam.chromaClipp;
#if !JVET_O0669_REMOVE_ALF_COEFF_PRED
if( alfSliceParam.alfLumaCoeffDeltaPredictionFlag && isLuma( channel ) )
{
for( int i = 1; i < numFilters; i++ )
......@@ -409,6 +410,7 @@ void AdaptiveLoopFilter::reconstructCoeff( AlfSliceParam& alfSliceParam, Channel
}
}
}
#endif
for( int filterIdx = 0; filterIdx < numFilters; filterIdx++ )
{
......@@ -432,6 +434,7 @@ void AdaptiveLoopFilter::reconstructCoeff( AlfSliceParam& alfSliceParam, Channel
for( int classIdx = 0; classIdx < numClasses; classIdx++ )
{
int filterIdx = alfSliceParam.filterCoeffDeltaIdx[classIdx];
#if !JVET_O0669_REMOVE_ALF_COEFF_PRED
int fixedFilterIdx = alfSliceParam.fixedFilterSetIndex;
if (fixedFilterIdx > 0 && alfSliceParam.fixedFilterIdx[classIdx] > 0)
{
......@@ -441,14 +444,17 @@ void AdaptiveLoopFilter::reconstructCoeff( AlfSliceParam& alfSliceParam, Channel
{
fixedFilterIdx = -1;
}
#endif
for (int coeffIdx = 0; coeffIdx < numCoeffMinus1; ++coeffIdx)
{
m_coeffFinal[classIdx * MAX_NUM_ALF_LUMA_COEFF + coeffIdx] = coeff[filterIdx * MAX_NUM_ALF_LUMA_COEFF + coeffIdx];
#if !JVET_O0669_REMOVE_ALF_COEFF_PRED
//fixed filter
if (fixedFilterIdx >= 0)
{
m_coeffFinal[classIdx * MAX_NUM_ALF_LUMA_COEFF + coeffIdx] += m_fixedFilterSetCoeff[fixedFilterIdx][coeffIdx];
}
#endif
}
m_coeffFinal[classIdx* MAX_NUM_ALF_LUMA_COEFF + numCoeffMinus1] = factor;
m_clippFinal[classIdx* MAX_NUM_ALF_LUMA_COEFF + numCoeffMinus1] = isRdo ? 0 : m_alfClippingValues[channel][0];
......@@ -459,6 +465,7 @@ void AdaptiveLoopFilter::reconstructCoeff( AlfSliceParam& alfSliceParam, Channel
}
}
#if !JVET_O0669_REMOVE_ALF_COEFF_PRED
if(isRedo && alfSliceParam.alfLumaCoeffDeltaPredictionFlag )
{
for( int i = numFilters - 1; i > 0; i-- )
......@@ -469,6 +476,7 @@ void AdaptiveLoopFilter::reconstructCoeff( AlfSliceParam& alfSliceParam, Channel
}
}
}
#endif
}
void AdaptiveLoopFilter::create( const int picWidth, const int picHeight, const ChromaFormat format, const int maxCUWidth, const int maxCUHeight, const int maxCUDepth, const int inputBitDepth[MAX_NUM_CHANNEL_TYPE] )
......
......@@ -50,6 +50,8 @@
#include <assert.h>
#include <cassert>
#define JVET_O0669_REMOVE_ALF_COEFF_PRED 1 // JVET-O0425/O0427/O0669: remove prediction in ALF coefficients coding
#define JVET_O0655_422_CHROMA_DM_MAPPING_FIX 1 // JVET-O0655: modify chroma DM derivation table for 4:2:2 chroma format
#define JVET_O1109_UNFIY_CRS 1 // JVET-O1109: Unified CRS derivation
......@@ -1494,13 +1496,17 @@ struct AlfSliceParam
bool alfLumaCoeffFlag[MAX_NUM_ALF_CLASSES]; // alf_luma_coeff_flag[i]
int numLumaFilters; // number_of_filters_minus1 + 1
bool alfLumaCoeffDeltaFlag; // alf_luma_coeff_delta_flag
#if !JVET_O0669_REMOVE_ALF_COEFF_PRED
bool alfLumaCoeffDeltaPredictionFlag; // alf_luma_coeff_delta_prediction_flag
#endif
std::vector<AlfFilterShape>* filterShapes;
int tLayer;
bool newFilterFlag[MAX_NUM_CHANNEL_TYPE];
#if !JVET_O0669_REMOVE_ALF_COEFF_PRED
int fixedFilterPattern;
int fixedFilterIdx[MAX_NUM_ALF_CLASSES];
int fixedFilterSetIndex;
#endif
AlfSliceParam()
{
......@@ -1519,12 +1525,16 @@ struct AlfSliceParam
std::memset( alfLumaCoeffFlag, true, sizeof( alfLumaCoeffFlag ) );
numLumaFilters = 1;
alfLumaCoeffDeltaFlag = false;
#if !JVET_O0669_REMOVE_ALF_COEFF_PRED
alfLumaCoeffDeltaPredictionFlag = false;
#endif
tLayer = 0;
memset(newFilterFlag, 0, sizeof(newFilterFlag));
#if !JVET_O0669_REMOVE_ALF_COEFF_PRED
fixedFilterPattern = 0;
std::memset(fixedFilterIdx, 0, sizeof(fixedFilterIdx));
fixedFilterSetIndex = 0;;
fixedFilterSetIndex = 0;
#endif
}
const AlfSliceParam& operator = ( const AlfSliceParam& src )
......@@ -1539,13 +1549,17 @@ struct AlfSliceParam
std::memcpy( alfLumaCoeffFlag, src.alfLumaCoeffFlag, sizeof( alfLumaCoeffFlag ) );
numLumaFilters = src.numLumaFilters;
alfLumaCoeffDeltaFlag = src.alfLumaCoeffDeltaFlag;
#if !JVET_O0669_REMOVE_ALF_COEFF_PRED
alfLumaCoeffDeltaPredictionFlag = src.alfLumaCoeffDeltaPredictionFlag;
#endif
filterShapes = src.filterShapes;
tLayer = src.tLayer;
std::memcpy(newFilterFlag, src.newFilterFlag, sizeof(newFilterFlag));
#if !JVET_O0669_REMOVE_ALF_COEFF_PRED
fixedFilterPattern = src.fixedFilterPattern;
std::memcpy(fixedFilterIdx, src.fixedFilterIdx, sizeof(fixedFilterIdx));
fixedFilterSetIndex = src.fixedFilterSetIndex;
#endif
return *this;
}
};
......
......@@ -807,7 +807,7 @@ void HLSyntaxReader::parseAlfAps( APS* aps )
{
memset(param.filterCoeffDeltaIdx, 0, sizeof(param.filterCoeffDeltaIdx));
}
#if !JVET_O0669_REMOVE_ALF_COEFF_PRED
READ_FLAG(code, "fixed_filter_set_flag");
param.fixedFilterSetIndex = code;
if (param.fixedFilterSetIndex > 0)
......@@ -826,6 +826,7 @@ void HLSyntaxReader::parseAlfAps( APS* aps )
param.fixedFilterIdx[classIdx] = code;
}
}
#endif
alfFilter(param, false);
}
if (param.newFilterFlag[CHANNEL_TYPE_CHROMA])
......@@ -2657,7 +2658,7 @@ void HLSyntaxReader::alfFilter( AlfSliceParam& alfSliceParam, const bool isChrom
if( !alfSliceParam.alfLumaCoeffDeltaFlag )
{
std::memset( alfSliceParam.alfLumaCoeffFlag, true, sizeof( alfSliceParam.alfLumaCoeffFlag ) );
#if !JVET_O0669_REMOVE_ALF_COEFF_PRED
if( alfSliceParam.numLumaFilters > 1 )
{
READ_FLAG( code, "alf_luma_coeff_delta_prediction_flag" );
......@@ -2667,11 +2668,14 @@ void HLSyntaxReader::alfFilter( AlfSliceParam& alfSliceParam, const bool isChrom
{
alfSliceParam.alfLumaCoeffDeltaPredictionFlag = 0;
}
#endif
}
#if !JVET_O0669_REMOVE_ALF_COEFF_PRED
else
{
alfSliceParam.alfLumaCoeffDeltaPredictionFlag = 0;
}
#endif
}
// derive maxGolombIdx
......@@ -2743,7 +2747,7 @@ void HLSyntaxReader::alfFilter( AlfSliceParam& alfSliceParam, const bool isChrom
else
{
memcpy( recCoeff, coeff, sizeof(short) * numFilters * MAX_NUM_ALF_LUMA_COEFF );
#if !JVET_O0669_REMOVE_ALF_COEFF_PRED
if( alfSliceParam.alfLumaCoeffDeltaPredictionFlag )
{
for( int i = 1; i < numFilters; i++ )
......@@ -2754,6 +2758,7 @@ void HLSyntaxReader::alfFilter( AlfSliceParam& alfSliceParam, const bool isChrom
}
}
}
#endif
}
// Filter coefficients
......
......@@ -1107,7 +1107,11 @@ double EncAdaptiveLoopFilter::mergeFiltersAndCost( AlfSliceParam& alfSliceParam,
static double errorForce0CoeffTab[MAX_NUM_ALF_CLASSES][2];
double cost, cost0, dist, distForce0, costMin = MAX_DOUBLE;
#if JVET_O0669_REMOVE_ALF_COEFF_PRED
int coeffBits, coeffBitsForce0;
#else
int predMode = 0, bestPredMode = 0, coeffBits, coeffBitsForce0;
#endif
mergeClasses( alfShape, covFrame, covMerged, clipMerged, MAX_NUM_ALF_CLASSES, m_filterIndices );
......@@ -1116,7 +1120,11 @@ double EncAdaptiveLoopFilter::mergeFiltersAndCost( AlfSliceParam& alfSliceParam,
dist = deriveFilterCoeffs(covFrame, covMerged, clipMerged, alfShape, m_filterIndices[numFilters - 1], numFilters, errorForce0CoeffTab, alfSliceParam);
// filter coeffs are stored in m_filterCoeffSet
distForce0 = getDistForce0( alfShape, numFilters, errorForce0CoeffTab, codedVarBins );
#if JVET_O0669_REMOVE_ALF_COEFF_PRED
coeffBits = deriveFilterCoefficientsPredictionMode( alfShape, m_filterCoeffSet, m_diffFilterCoeff, numFilters );
#else
coeffBits = deriveFilterCoefficientsPredictionMode( alfShape, m_filterCoeffSet, m_diffFilterCoeff, numFilters, predMode );
#endif
coeffBitsForce0 = getCostFilterCoeffForce0( alfShape, m_filterCoeffSet, numFilters, codedVarBins );
cost = dist + m_lambda[COMPONENT_Y] * coeffBits;
......@@ -1126,7 +1134,7 @@ double EncAdaptiveLoopFilter::mergeFiltersAndCost( AlfSliceParam& alfSliceParam,
{
cost = cost0;
}
#if !JVET_O0669_REMOVE_ALF_COEFF_PRED
if (alfSliceParam.fixedFilterSetIndex > 0)
{
int len = 0;
......@@ -1138,18 +1146,25 @@ double EncAdaptiveLoopFilter::mergeFiltersAndCost( AlfSliceParam& alfSliceParam,
}
cost += m_lambda[COMPONENT_Y] * len;
}
#endif
if( cost <= costMin )
{
costMin = cost;
numFiltersBest = numFilters;
#if !JVET_O0669_REMOVE_ALF_COEFF_PRED
bestPredMode = predMode;
#endif
}
numFilters--;
}
dist = deriveFilterCoeffs( covFrame, covMerged, clipMerged, alfShape, m_filterIndices[numFiltersBest - 1], numFiltersBest, errorForce0CoeffTab, alfSliceParam );
#if JVET_O0669_REMOVE_ALF_COEFF_PRED
coeffBits = deriveFilterCoefficientsPredictionMode( alfShape, m_filterCoeffSet, m_diffFilterCoeff, numFiltersBest );
#else
coeffBits = deriveFilterCoefficientsPredictionMode( alfShape, m_filterCoeffSet, m_diffFilterCoeff, numFiltersBest, predMode );
#endif
distForce0 = getDistForce0( alfShape, numFiltersBest, errorForce0CoeffTab, codedVarBins );
coeffBitsForce0 = getCostFilterCoeffForce0( alfShape, m_filterCoeffSet, numFiltersBest, codedVarBins );
......@@ -1163,7 +1178,9 @@ double EncAdaptiveLoopFilter::mergeFiltersAndCost( AlfSliceParam& alfSliceParam,
distReturn = dist;
alfSliceParam.alfLumaCoeffDeltaFlag = 0;
uiCoeffBits = coeffBits;
#if !JVET_O0669_REMOVE_ALF_COEFF_PRED
alfSliceParam.alfLumaCoeffDeltaPredictionFlag = bestPredMode;
#endif
}
else
{
......@@ -1171,7 +1188,9 @@ double EncAdaptiveLoopFilter::mergeFiltersAndCost( AlfSliceParam& alfSliceParam,
alfSliceParam.alfLumaCoeffDeltaFlag = 1;
uiCoeffBits = coeffBitsForce0;
memcpy( alfSliceParam.alfLumaCoeffFlag, codedVarBins, sizeof( codedVarBins ) );
#if !JVET_O0669_REMOVE_ALF_COEFF_PRED
alfSliceParam.alfLumaCoeffDeltaPredictionFlag = 0;
#endif
for( int varInd = 0; varInd < numFiltersBest; varInd++ )
{
......@@ -1187,6 +1206,9 @@ double EncAdaptiveLoopFilter::mergeFiltersAndCost( AlfSliceParam& alfSliceParam,
{
for( int i = 0; i < alfShape.numCoeff; i++ )
{
#if JVET_O0669_REMOVE_ALF_COEFF_PRED
alfSliceParam.lumaCoeff[ind * MAX_NUM_ALF_LUMA_COEFF + i] = m_filterCoeffSet[ind][i];
#else
if( alfSliceParam.alfLumaCoeffDeltaPredictionFlag )
{
alfSliceParam.lumaCoeff[ind * MAX_NUM_ALF_LUMA_COEFF + i] = m_diffFilterCoeff[ind][i];
......@@ -1195,6 +1217,7 @@ double EncAdaptiveLoopFilter::mergeFiltersAndCost( AlfSliceParam& alfSliceParam,
{
alfSliceParam.lumaCoeff[ind * MAX_NUM_ALF_LUMA_COEFF + i] = m_filterCoeffSet[ind][i];
}
#endif
alfSliceParam.lumaClipp[ind * MAX_NUM_ALF_LUMA_COEFF + i] = m_filterClippSet[ind][i];
}
}
......@@ -1217,6 +1240,7 @@ int EncAdaptiveLoopFilter::getNonFilterCoeffRate( AlfSliceParam& alfSliceParam )
len += getTBlength( (int)alfSliceParam.filterCoeffDeltaIdx[i], alfSliceParam.numLumaFilters ); //filter_coeff_delta[i]
}
}
#if !JVET_O0669_REMOVE_ALF_COEFF_PRED
len++; //fixed filter set flag
if (alfSliceParam.fixedFilterSetIndex > 0)
{
......@@ -1225,6 +1249,7 @@ int EncAdaptiveLoopFilter::getNonFilterCoeffRate( AlfSliceParam& alfSliceParam )
if (alfSliceParam.fixedFilterPattern > 0)
len += MAX_NUM_ALF_CLASSES; //"fixed_filter_flag" for each class
}
#endif
return len;
}
......@@ -1371,6 +1396,11 @@ int EncAdaptiveLoopFilter::getCostFilterCoeffForce0( AlfFilterShape& alfShape, i
return len;
}
#if JVET_O0669_REMOVE_ALF_COEFF_PRED
int EncAdaptiveLoopFilter::deriveFilterCoefficientsPredictionMode( AlfFilterShape& alfShape, int **filterSet, int** filterCoeffDiff, const int numFilters )
{
return (m_alfSliceParamTemp.nonLinearFlag[CHANNEL_TYPE_LUMA] ? getCostFilterClipp(alfShape, filterSet, numFilters) : 0) + getCostFilterCoeff(alfShape, filterSet, numFilters);
#else
int EncAdaptiveLoopFilter::deriveFilterCoefficientsPredictionMode( AlfFilterShape& alfShape, int **filterSet, int** filterCoeffDiff, const int numFilters, int& predMode )
{
int ratePredMode0 = getCostFilterCoeff( alfShape, filterSet, numFilters );
......@@ -1399,6 +1429,7 @@ int EncAdaptiveLoopFilter::deriveFilterCoefficientsPredictionMode( AlfFilterShap
return ( numFilters > 1 ? 1 : 0 ) // coeff_delta_pred_mode_flag
+ rateClipp
+ ( predMode ? ratePredMode1 : ratePredMode0 ); // min_golomb_order, golomb_order_increase_flag, alf_coeff_luma_delta
#endif
}
int EncAdaptiveLoopFilter::getCostFilterCoeff( AlfFilterShape& alfShape, int **pDiffQFilterCoeffIntPP, const int numFilters )
......@@ -1646,6 +1677,7 @@ double EncAdaptiveLoopFilter::deriveFilterCoeffs( AlfCovariance* cov, AlfCovaria
double error = 0.0;
AlfCovariance& tmpCov = covMerged[MAX_NUM_ALF_CLASSES];
#if !JVET_O0669_REMOVE_ALF_COEFF_PRED
alfSliceParam.fixedFilterSetIndex = 0;
AlfCovariance& tmpCovFf = covMerged[MAX_NUM_ALF_CLASSES + 1];
double factor = 1 << (m_NUM_BITS - 1);
......@@ -1699,6 +1731,7 @@ double EncAdaptiveLoopFilter::deriveFilterCoeffs( AlfCovariance* cov, AlfCovaria
}
}
}
#endif
for( int filtIdx = 0; filtIdx < numFilters; filtIdx++ )
{
......@@ -1708,6 +1741,9 @@ double EncAdaptiveLoopFilter::deriveFilterCoeffs( AlfCovariance* cov, AlfCovaria
{
if( filterIndices[classIdx] == filtIdx )
{
#if JVET_O0669_REMOVE_ALF_COEFF_PRED
tmpCov += cov[classIdx];
#else
//adjust stat
tmpCovFf = cov[classIdx];
if (alfSliceParam.fixedFilterSetIndex > 0 && alfSliceParam.fixedFilterIdx[classIdx] > 0
......@@ -1728,6 +1764,7 @@ double EncAdaptiveLoopFilter::deriveFilterCoeffs( AlfCovariance* cov, AlfCovaria
}
}
tmpCov += tmpCovFf;
#endif
if( !found_clip )
{
found_clip = true; // clip should be at the adress of shortest one
......
......@@ -300,7 +300,11 @@ private:
double getFilterCoeffAndCost( CodingStructure& cs, double distUnfilter, ChannelType channel, bool bReCollectStat, int iShapeIdx, int& uiCoeffBits, bool onlyFilterCost = false );
double 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], AlfSliceParam& alfSliceParam);
#if JVET_O0669_REMOVE_ALF_COEFF_PRED
int deriveFilterCoefficientsPredictionMode( AlfFilterShape& alfShape, int **filterSet, int** filterCoeffDiff, const int numFilters );
#else
int deriveFilterCoefficientsPredictionMode( AlfFilterShape& alfShape, int **filterSet, int** filterCoeffDiff, const int numFilters, int& predMode );
#endif
double deriveCoeffQuant( int *filterClipp, int *filterCoeffQuant, const AlfCovariance& cov, const AlfFilterShape& shape, const int bitDepth, const bool optimizeClip );
double deriveCtbAlfEnableFlags( CodingStructure& cs, const int iShapeIdx, ChannelType channel,
#if ENABLE_QPA
......
......@@ -486,7 +486,7 @@ void HLSWriter::codeAlfAps( APS* pcAPS )
xWriteTruncBinCode((uint32_t)param.filterCoeffDeltaIdx[i], param.numLumaFilters); //filter_coeff_delta[i]
}
}
#if !JVET_O0669_REMOVE_ALF_COEFF_PRED
WRITE_FLAG(param.fixedFilterSetIndex > 0 ? 1 : 0, "fixed_filter_set_flag");
if (param.fixedFilterSetIndex > 0)
{
......@@ -504,7 +504,7 @@ void HLSWriter::codeAlfAps( APS* pcAPS )
}
}
}
#endif
alfFilter(param, false);
}
......@@ -1833,6 +1833,7 @@ void HLSWriter::alfFilter( const AlfSliceParam& alfSliceParam, const bool isChro
if( !isChroma )
{
WRITE_FLAG( alfSliceParam.alfLumaCoeffDeltaFlag, "alf_luma_coeff_delta_flag" );
#if !JVET_O0669_REMOVE_ALF_COEFF_PRED
if( !alfSliceParam.alfLumaCoeffDeltaFlag )
{
if( alfSliceParam.numLumaFilters > 1 )
......@@ -1840,6 +1841,7 @@ void HLSWriter::alfFilter( const AlfSliceParam& alfSliceParam, const bool isChro
WRITE_FLAG( alfSliceParam.alfLumaCoeffDeltaPredictionFlag, "alf_luma_coeff_delta_prediction_flag" );
}
}
#endif
}
static int bitsCoeffScan[EncAdaptiveLoopFilter::m_MAX_SCAN_VAL][EncAdaptiveLoopFilter::m_MAX_EXP_GOLOMB];
......@@ -1919,7 +1921,7 @@ void HLSWriter::alfFilter( const AlfSliceParam& alfSliceParam, const bool isChro
else
{
memcpy( recCoeff, coeff, sizeof(short) * numFilters * MAX_NUM_ALF_LUMA_COEFF );
#if !JVET_O0669_REMOVE_ALF_COEFF_PRED
if( alfSliceParam.alfLumaCoeffDeltaPredictionFlag )
{
for( int i = 1; i < numFilters; i++ )
......@@ -1930,6 +1932,7 @@ void HLSWriter::alfFilter( const AlfSliceParam& alfSliceParam, const bool isChro
}
}
}
#endif
}
// vlc for all
for( int ind = 0; ind < numFilters; ++ind )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment