Newer
Older
#else
bool isCccmModeEnabledInRdo[MDLM_T_IDX + 1] = { false };
isCccmModeEnabledInRdo[satdCccmModeList[0]] = true;
#if JVET_AC0054_GLCCCM
bool isGlCccmModeEnabledInRdo[MDLM_T_IDX + 1] = { false };
if (satdCccmFlagList[0] == 2)
{
isCccmModeEnabledInRdo[0][satdCccmModeList[0][0]] = false;
isGlCccmModeEnabledInRdo[satdCccmModeList[0][0]] = true;
}
#endif
for (int i = 1; i < 3; i++)
#endif
{
if (satdCccmSortedCost[0][i] >= 1.15 * bestCccmCost[0])
{
break;
}
#if JVET_AC0054_GLCCCM
if (satdCccmFlagList[i] == 2)
{
isGlCccmModeEnabledInRdo[satdCccmModeList[0][i]] = true;
}
else
{
#if JVET_AD0202_CCCM_MDF
isCccmWithMulDownSamplingEnabledInRdo[satdCccmModeList[0][i]][satdCccmFilterIndex[i]] = true;
#else
isCccmModeEnabledInRdo[0][satdCccmModeList[0][i]] = true;
isCccmModeEnabledInRdo[0][satdCccmModeList[0][i]] = true;
#if JVET_AD0202_CCCM_MDF
if (m_skipCCCMwithMdfSATD == false)
{
m_skipCCCMwithMdfSATD = true;
for (int i = LM_CHROMA_IDX; i <= MMLM_T_IDX; i++)
{
m_isCccmWithMdfEnabledInRdo[4][i] = isGlCccmModeEnabledInRdo[i] ? 1 : 0;
for (int j = 0; j < 4; j++)
{
m_isCccmWithMdfEnabledInRdo[j][i] = isCccmWithMulDownSamplingEnabledInRdo[i][j] ? 1 : 0;
}
}
}
#endif
if (pu.cu->slice->getSPS()->getUseCccm() == 2)
{
if (bestCccmCost[1] < bestCccmCost[0])
{
#if MMLM
#if JVET_AD0202_CCCM_MDF
for (int i = 1; i < 7; i++)
#else
for (int i = 0; i < 4; i++)
#else
for (int i = 0; i < 3; i++)
#endif
{
#if JVET_AD0202_CCCM_MDF
if (isCccmWithMulDownSamplingEnabledInRdo[satdCccmModeList[0][i]][satdCccmFilterIndex[i]] && (satdCccmSortedCost[0][i] >= 1.2 * bestCccmCost[1]))
{
isCccmWithMulDownSamplingEnabledInRdo[satdCccmModeList[0][i]][satdCccmFilterIndex[i]] = false;
}
#else
if (isCccmModeEnabledInRdo[0][satdCccmModeList[0][i]] && (satdCccmSortedCost[0][i] >= 1.2 * bestCccmCost[1]))
{
isCccmModeEnabledInRdo[0][satdCccmModeList[0][i]] = false;
}
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
else
{
bestCccmCost[0] = satdCccmSortedCost[0][i];
}
}
}
else
{
bestCccmCost[1] = bestCccmCost[0];
}
tempCccmIdx = 0;
tempCccmCost = 0;
for (int i = 1; i < 2; i++)
{
for (int j = i + 1; j < 6; j++)
{
if (satdCccmSortedCost[1][j] < satdCccmSortedCost[1][i])
{
tempCccmIdx = satdCccmModeList[1][i];
satdCccmModeList[1][i] = satdCccmModeList[1][j];
satdCccmModeList[1][j] = tempCccmIdx;
tempCccmCost = satdCccmSortedCost[1][i];
satdCccmSortedCost[1][i] = satdCccmSortedCost[1][j];
satdCccmSortedCost[1][j] = tempCccmCost;
}
}
}
isCccmModeEnabledInRdo[1][satdCccmModeList[1][0]] = true;
for (int i = 1; i < 2; i++)
{
if (satdCccmSortedCost[1][i] >= CCCM_NO_SUB_WEIGHT * bestCccmCost[1])
{
#if !JVET_AD0202_CCCM_MDF
#if JVET_AC0054_GLCCCM
if (satdCccmSortedCost[1][i - 1] > bestCccmCost[0] && satdCccmFlagList[0] != 2)
#else
if (satdCccmSortedCost[1][i - 1] > bestCccmCost[0])
{
bestCccmCost[0] = satdCccmSortedCost[1][i - 1];
}
bestCccmCost[1] = satdCccmSortedCost[1][i - 1];
break;
}
isCccmModeEnabledInRdo[1][satdCccmModeList[1][i]] = true;
}
#if JVET_AD0202_CCCM_MDF
bestCccmCost[1] = (isCccmModeEnabledInRdo[1][satdCccmModeList[1][1]] && satdCccmSortedCost[1][0] < satdCccmSortedCost[1][1]) ? satdCccmSortedCost[1][1] : satdCccmSortedCost[1][0];
bestCccmCost[0] = (bestCccmCost[1] > bestCccmCost[0]) ? bestCccmCost[1] : bestCccmCost[0];
bestCccmCost[0] = (satdCccmSortedCost[0][0] > bestCccmCost[0]) ? satdCccmSortedCost[0][0] : bestCccmCost[0];
#endif
if (m_skipCCCMSATD == false)
{
m_skipCCCMSATD = true;
for (int i = 0; i < (MMLM_T_IDX + 1); i++)
{
m_isCccmNoSubModeEnabledInRdo[i] = isCccmModeEnabledInRdo[1][i];
}
}
}
pu.cccmFlag = 0;
pu.cccmNoSubFlag = 0;
#if JVET_AC0054_GLCCCM
pu.glCccmFlag = 0;
#endif
#if JVET_AD0202_CCCM_MDF
pu.cccmMultiFilterIdx = 0;
#endif
int64_t satdCccmSortedCost[CCCM_NUM_MODES];
int satdCccmModeList[CCCM_NUM_MODES];
for (int i = 0; i < CCCM_NUM_MODES; i++)
{
satdCccmSortedCost[i] = LLONG_MAX; // for the mode not pre-select by SATD, do RDO by default, so set the initial value 0.
satdCccmModeList[i] = chromaCandCccmModes[i];
}
int64_t bestCccmCost = LLONG_MAX;
bool isCccmFullEnabled = PU::cccmSingleModeAvail(pu, LM_CHROMA_IDX);
bool isCccmLeftEnabled = PU::isLeftCccmMode(pu, MDLM_L_IDX);
bool isCccmTopEnabled = PU::isTopCccmMode(pu, MDLM_T_IDX);
#if MMLM
bool isMultiCccmFullEnabled = PU::cccmMultiModeAvail(pu, MMLM_CHROMA_IDX);
bool isMultiCccmLeftEnabled = PU::cccmMultiModeAvail(pu, MMLM_L_IDX);
bool isMultiCccmTopEnabled = PU::cccmMultiModeAvail(pu, MMLM_T_IDX);
#endif
const UnitArea localUnitArea(cs.area.chromaFormat, Area(0, 0, (pu.Cb().width) << 1, (pu.Cb().height) << 1));
pu.cccmFlag = 1;
xGetLumaRecPixels(pu, pu.Cb());
bool isCCCMEnabled = false;
for (int idx = 0; idx < CCCM_NUM_MODES; idx++)
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
{
int mode = chromaCandCccmModes[idx];
if (idx == 0)
{
isCCCMEnabled = isCccmFullEnabled;
pu.cccmFlag = 1;
}
else if (idx == 1)
{
isCCCMEnabled = isCccmLeftEnabled;
pu.cccmFlag = 2;
}
else if (idx == 2)
{
isCCCMEnabled = isCccmTopEnabled;
pu.cccmFlag = 3;
}
#if MMLM
else if (idx == 3)
{
isCCCMEnabled = isMultiCccmFullEnabled;
pu.cccmFlag = 1;
}
else if (idx == 4)
{
isCCCMEnabled = isMultiCccmLeftEnabled;
pu.cccmFlag = 2;
}
else if (idx == 5)
{
isCCCMEnabled = isMultiCccmTopEnabled;
pu.cccmFlag = 3;
}
#endif
if (isCCCMEnabled)
{
pu.intraDir[1] = mode; // temporary assigned, for SATD checking.
int64_t sad = 0;
int64_t sadCb = 0;
int64_t satdCb = 0;
int64_t sadCr = 0;
int64_t satdCr = 0;
CodingStructure& cs = *(pu.cs);
DistParam distParamSadCb;
DistParam distParamSatdCb;
DistParam distParamSadCr;
DistParam distParamSatdCr;
cccmStorage[idx] = m_cccmStorage[idx].getBuf(localUnitArea);
CompArea areaCb = pu.Cb();
PelBuf orgCb = cs.getOrgBuf(areaCb);
CompArea areaCr = pu.Cr();
PelBuf orgCr = cs.getOrgBuf(areaCr);
m_pcRdCost->setDistParam(distParamSadCb, orgCb, cccmStorage[idx].Cb(), pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cb, false);
m_pcRdCost->setDistParam(distParamSatdCb, orgCb, cccmStorage[idx].Cb(), pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cb, true);
distParamSadCb.applyWeight = false;
distParamSatdCb.applyWeight = false;
m_pcRdCost->setDistParam(distParamSadCr, orgCr, cccmStorage[idx].Cr(), pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cr, false);
m_pcRdCost->setDistParam(distParamSatdCr, orgCr, cccmStorage[idx].Cr(), pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cr, true);
distParamSadCr.applyWeight = false;
distParamSatdCr.applyWeight = false;
Chia-Ming Tsai
committed
#if JVET_AD0188_CCP_MERGE
pu.curCand = {};
#endif
predIntraCCCM(pu, cccmStorage[idx].Cb(), cccmStorage[idx].Cr(), mode);
Chia-Ming Tsai
committed
#if JVET_AD0188_CCP_MERGE
m_ccmParamsStorage[idx] = pu.curCand;
#endif
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
sadCb = distParamSadCb.distFunc(distParamSadCb) * 2;
satdCb = distParamSatdCb.distFunc(distParamSatdCb);
sad += std::min(sadCb, satdCb);
sadCr = distParamSadCr.distFunc(distParamSadCr) * 2;
satdCr = distParamSatdCr.distFunc(distParamSatdCr);
sad += std::min(sadCr, satdCr);
satdCccmSortedCost[idx] = sad;
if (sad < bestCccmCost)
{
bestCccmCost = sad;
}
}
}
int tempCccmIdx = 0;
int64_t tempCccmCost = 0;
#if MMLM
for (int i = 1; i < 4; i++)
#else
for (int i = 1; i < 3; i++)
#endif
{
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
{
if (satdCccmSortedCost[j] < satdCccmSortedCost[i])
{
tempCccmIdx = satdCccmModeList[i];
satdCccmModeList[i] = satdCccmModeList[j];
satdCccmModeList[j] = tempCccmIdx;
tempCccmCost = satdCccmSortedCost[i];
satdCccmSortedCost[i] = satdCccmSortedCost[j];
satdCccmSortedCost[j] = tempCccmCost;
}
}
}
#if MMLM
bool isCccmModeEnabledInRdo[MMLM_T_IDX + 1] = { false };
isCccmModeEnabledInRdo[satdCccmModeList[0]] = true;
for (int i = 1; i < 4; i++)
#else
bool isCccmModeEnabledInRdo[MDLM_T_IDX + 1] = { false };
isCccmModeEnabledInRdo[satdCccmModeList[0]] = true;
for (int i = 1; i < 3; i++)
#endif
{
if (satdCccmSortedCost[i] >= 1.15 * bestCccmCost)
{
break;
}
isCccmModeEnabledInRdo[satdCccmModeList[i]] = true;
}
pu.cccmFlag = 0;
#endif
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
// sort the mode based on the cost from small to large.
int tempIdx = 0;
int64_t tempCost = 0;
for (int i = uiMinMode; i <= uiMaxMode - 1; i++)
{
for (int j = i + 1; j <= uiMaxMode - 1; j++)
{
if (satdSortedCost[j] < satdSortedCost[i])
{
tempIdx = satdModeList[i];
satdModeList[i] = satdModeList[j];
satdModeList[j] = tempIdx;
tempCost = satdSortedCost[i];
satdSortedCost[i] = satdSortedCost[j];
satdSortedCost[j] = tempCost;
}
}
}
int reducedModeNumber = 2; // reduce the number of chroma modes
#if MMLM
reducedModeNumber += 3; // Match number of RDs with the anchor
#endif
for (int i = 0; i < reducedModeNumber; i++)
{
modeIsEnable[satdModeList[uiMaxMode - 1 - i]] = 0; // disable the last reducedModeNumber modes
}
#if JVET_AC0147_CCCM_NO_SUBSAMPLING
if (pu.cu->slice->getSPS()->getUseCccm() == 2)
{
#if JVET_AC0054_GLCCCM
#if JVET_AD0202_CCCM_MDF
int32_t lastModeIdx = uiMaxMode - 1 - reducedModeNumber; ;
if (satdSortedCost[lastModeIdx] > bestCccmCost[0])
#else
if (satdSortedCost[uiMaxMode - 1 - reducedModeNumber] > bestCccmCost[0] && satdCccmFlagList[uiMaxMode - 1 - reducedModeNumber] != 2)
if (satdSortedCost[uiMaxMode - 1 - reducedModeNumber] > bestCccmCost[0])
#if JVET_AD0202_CCCM_MDF
{
modeIsEnable[satdModeList[lastModeIdx]] = 0; // disable the last reducedModeNumber modes
}
else if (satdSortedCost[lastModeIdx] < bestCccmCost[0])
{
for (int i = 6; i > 0; i--)
#else
{
modeIsEnable[satdModeList[uiMaxMode - 1 - reducedModeNumber]] = 0; // disable the last reducedModeNumber modes
}
else if (satdSortedCost[uiMaxMode - 1 - reducedModeNumber] < bestCccmCost[0])
{
for (int i = 3; i > 0; i--)
#if JVET_AC0054_GLCCCM
#if JVET_AD0202_CCCM_MDF
if ((satdCccmSortedCost[0][i] > satdSortedCost[lastModeIdx]) && isCccmWithMulDownSamplingEnabledInRdo[satdCccmModeList[0][i]][satdCccmFilterIndex[i]])
#else
if ((satdCccmSortedCost[0][i] > satdSortedCost[uiMaxMode - 1 - reducedModeNumber]) && (isCccmModeEnabledInRdo[0][satdCccmModeList[0][i]]) && satdCccmFlagList[uiMaxMode - 1 - reducedModeNumber] != 2)
if ((satdCccmSortedCost[0][i] > satdSortedCost[uiMaxMode - 1 - reducedModeNumber]) && (isCccmModeEnabledInRdo[0][satdCccmModeList[0][i]]))
#if JVET_AD0202_CCCM_MDF
isCccmWithMulDownSamplingEnabledInRdo[satdCccmModeList[0][i]][satdCccmFilterIndex[i]] = false;
#else
isCccmModeEnabledInRdo[0][satdCccmModeList[0][i]] = false;
break;
}
}
}
#if JVET_AD0202_CCCM_MDF
if (satdSortedCost[lastModeIdx] < bestCccmCost[1])
{
if ((satdCccmSortedCost[1][1] > satdSortedCost[lastModeIdx]) && (isCccmModeEnabledInRdo[1][satdCccmModeList[1][1]]))
#else
if (satdSortedCost[uiMaxMode - 1 - reducedModeNumber] < bestCccmCost[1])
{
if ((satdCccmSortedCost[1][1] > satdSortedCost[uiMaxMode - 1 - reducedModeNumber]) && (isCccmModeEnabledInRdo[1][satdCccmModeList[1][1]]))
{
isCccmModeEnabledInRdo[1][satdCccmModeList[1][1]] = false;
}
}
}
#endif

Karsten Suehring
committed
// save the dist
Distortion baseDist = cs.dist;
bool testBDPCM = true;
testBDPCM = testBDPCM && CU::bdpcmAllowed(cu, COMPONENT_Cb) && cu.ispMode == 0 && cu.mtsFlag == 0 && cu.lfnstIdx == 0;
#if JVET_Z0050_DIMD_CHROMA_FUSION
double dBestNonLmCost = MAX_DOUBLE;
#if JVET_AC0119_LM_CHROMA_FUSION
int bestNonLmMode = -1;
#else
#if ENABLE_DIMD
int bestNonLmMode = (cu.slice->getSPS()->getUseDimd()) ? DIMD_CHROMA_IDX : DM_CHROMA_IDX;
#else
int bestNonLmMode = DM_CHROMA_IDX;
#endif
Chia-Ming Tsai
committed
#if JVET_AD0188_CCP_MERGE
pu.curCand = {};
#endif
#if JVET_AC0119_LM_CHROMA_FUSION
int secondNonLmMode = -1;
double dSecondNonLmCost = MAX_DOUBLE;
PelUnitBuf predStorage[2], fusionStorage[6];
const UnitArea localArea(cs.area.chromaFormat, Area(0, 0, (pu.Cb().width) << 1, (pu.Cb().height) << 1));
for (uint32_t i = 0; i < 2; i++)
{
predStorage[i] = m_predStorage[i].getBuf(localArea);
}
for (uint32_t i = 0; i < 6; i++)
{
fusionStorage[i] = m_fusionStorage[i].getBuf(localArea);
}
#endif
#if JVET_AF0066_ENABLE_DBV_4_SINGLE_TREE
if (singleTreeLumaIntraTmp)
{
modeIsEnable[DBV_CHROMA_IDX] = 1;
}
for (int32_t uiMode = uiMinMode - (2 * int(testBDPCM)); uiMode < uiMaxMode; uiMode++)

Karsten Suehring
committed
{
if (uiMode < 0)
{
cu.bdpcmModeChroma = -uiMode;
#if JVET_AH0136_CHROMA_REORDERING
chromaIntraMode = cu.bdpcmModeChroma == 2 ? VER_IDX : HOR_IDX;
#else
chromaIntraMode = cu.bdpcmModeChroma == 2 ? chromaCandModes[1] : chromaCandModes[2];
chromaIntraMode = chromaCandModes[uiMode];

Karsten Suehring
committed
cu.bdpcmModeChroma = 0;
if( PU::isLMCMode( chromaIntraMode ) && ! PU::isLMCModeEnabled( pu, chromaIntraMode ) )
{
continue;
}
if (!modeIsEnable[chromaIntraMode] && PU::isLMCModeEnabled(pu, chromaIntraMode)) // when CCLM is disable, then MDLM is disable. not use satd checking
{
continue;
}
#if JVET_Z0050_DIMD_CHROMA_FUSION && ENABLE_DIMD
if (chromaIntraMode == DIMD_CHROMA_IDX && !cu.slice->getSPS()->getUseDimd()) // when DIMD is disable, then DIMD_CHROMA is disable.
{
continue;
}
#endif
#if JVET_AC0071_DBV
#if JVET_AH0136_CHROMA_REORDERING
if (PU::isDbvMode(chromaIntraMode) && !PU::hasChromaBvFlag(pu))
#else
if (chromaIntraMode == DBV_CHROMA_IDX && !PU::hasChromaBvFlag(pu))
{
continue;
}

Karsten Suehring
committed
cs.setDecomp( pu.Cb(), false );
cs.dist = baseDist;
//----- restore context models -----
m_CABACEstimator->getCtx() = ctxStart;
//----- chroma coding -----
pu.intraDir[1] = chromaIntraMode;
xRecurIntraChromaCodingQT( cs, partitioner, bestCostSoFar, ispType
#if JVET_AD0208_IBC_ADAPT_FOR_CAM_CAPTURED_CONTENTS && (JVET_AB0143_CCCM_TS || JVET_AC0119_LM_CHROMA_FUSION)
, UnitBuf<Pel>()
#endif
#if JVET_AD0208_IBC_ADAPT_FOR_CAM_CAPTURED_CONTENTS
, pcInterPred
#endif
);
if( lumaUsesISP && cs.dist == MAX_UINT )
{
continue;
}

Karsten Suehring
committed
if (cs.sps->getTransformSkipEnabledFlag())

Karsten Suehring
committed
{
m_CABACEstimator->getCtx() = ctxStart;
}
uint64_t fracBits = xGetIntraFracBitsQT( cs, partitioner, false, true, -1, ispType );

Karsten Suehring
committed
Distortion uiDist = cs.dist;
double dCost = m_pcRdCost->calcRdCost( fracBits, uiDist - baseDist );
//----- compare -----
if( dCost < dBestCost )
{
#if JVET_AG0154_DECODER_DERIVED_CCP_FUSION
if (uiDist < bestDist)
{
bestDist = uiDist;
}
#endif
if( lumaUsesISP && dCost < bestCostSoFar )
{
bestCostSoFar = dCost;
}

Karsten Suehring
committed
for( uint32_t i = getFirstComponentOfChannel( CHANNEL_TYPE_CHROMA ); i < numberValidComponents; i++ )
{
const CompArea &area = pu.blocks[i];
saveCS.getRecoBuf ( area ).copyFrom( cs.getRecoBuf ( area ) );
#if KEEP_PRED_AND_RESI_SIGNALS
saveCS.getPredBuf ( area ).copyFrom( cs.getPredBuf ( area ) );
saveCS.getResiBuf ( area ).copyFrom( cs.getResiBuf ( area ) );
#endif
saveCS.getPredBuf ( area ).copyFrom( cs.getPredBuf (area ) );
cs.picture->getPredBuf( area ).copyFrom( cs.getPredBuf (area ) );
#if JVET_Z0118_GDR
cs.updateReconMotIPM(area);
#else

Karsten Suehring
committed
cs.picture->getRecoBuf( area ).copyFrom( cs.getRecoBuf( area ) );

Karsten Suehring
committed
for( uint32_t j = 0; j < saveCS.tus.size(); j++ )
{
saveCS.tus[j]->copyComponentFrom( *orgTUs[j], area.compID );
}
}
dBestCost = dCost;
uiBestDist = uiDist;
uiBestMode = chromaIntraMode;
bestBDPCMMode = cu.bdpcmModeChroma;
Chia-Ming Tsai
committed
#if JVET_AD0188_CCP_MERGE
if (PU::isLMCMode(chromaIntraMode))
{
ccpModelBest = pu.curCand;
}
else
{
ccpModelBest.type = CCP_TYPE_NONE;
}
#endif

Karsten Suehring
committed
}
#if JVET_AC0119_LM_CHROMA_FUSION
bool findBestNonLm = !PU::isLMCMode(chromaIntraMode) && !cu.bdpcmModeChroma && PU::hasChromaFusionFlag(pu, chromaIntraMode);
#else
bool findBestNonLm = !PU::isLMCMode(chromaIntraMode) && !cu.bdpcmModeChroma && pu.cs->slice->isIntra();
if (findBestNonLm && dCost < dBestNonLmCost)
{
#if JVET_AC0119_LM_CHROMA_FUSION
if (bestNonLmMode != -1)
{
predStorage[1].Cb().copyFrom(predStorage[0].Cb());
predStorage[1].Cr().copyFrom(predStorage[0].Cr());
secondNonLmMode = bestNonLmMode;
dSecondNonLmCost = dBestNonLmCost;
}
predStorage[0].Cb().copyFrom(cs.getPredBuf(pu.Cb()));
predStorage[0].Cr().copyFrom(cs.getPredBuf(pu.Cr()));
#endif
bestNonLmMode = chromaIntraMode;
dBestNonLmCost = dCost;
}
#if JVET_AC0119_LM_CHROMA_FUSION
else if (findBestNonLm && dCost < dSecondNonLmCost)
{
predStorage[1].Cb().copyFrom(cs.getPredBuf(pu.Cb()));
predStorage[1].Cr().copyFrom(cs.getPredBuf(pu.Cr()));
secondNonLmMode = chromaIntraMode;
dSecondNonLmCost = dCost;
}
#endif

Karsten Suehring
committed
}
Chia-Ming Tsai
committed
#if JVET_AD0188_CCP_MERGE
pu.curCand = {};
#endif

Karsten Suehring
committed
#if JVET_AA0126_GLM
for (int32_t uiMode = 0; uiMode < NUM_LMC_MODE; uiMode++)
{
int chromaIntraMode = LM_CHROMA_IDX + uiMode;
if ( PU::isLMCModeEnabled( pu, chromaIntraMode ) && PU::hasGlmFlag( pu, chromaIntraMode ) )
{
if ( satdGlmIdcBest[chromaIntraMode - LM_CHROMA_IDX].isActive() )
{
pu.intraDir[1] = chromaIntraMode;
pu.glmIdc = satdGlmIdcBest[chromaIntraMode - LM_CHROMA_IDX];
// RD search replicated from above
cs.setDecomp( pu.Cb(), false );
cs.dist = baseDist;
//----- restore context models -----
m_CABACEstimator->getCtx() = ctxStart;
xRecurIntraChromaCodingQT( cs, partitioner, bestCostSoFar, ispType
#if JVET_AD0208_IBC_ADAPT_FOR_CAM_CAPTURED_CONTENTS && (JVET_AB0143_CCCM_TS || JVET_AC0119_LM_CHROMA_FUSION)
, UnitBuf<Pel>()
#endif
#if JVET_AD0208_IBC_ADAPT_FOR_CAM_CAPTURED_CONTENTS
, pcInterPred
#endif
);
if( lumaUsesISP && cs.dist == MAX_UINT )
{
continue;
}
if (cs.sps->getTransformSkipEnabledFlag())
{
m_CABACEstimator->getCtx() = ctxStart;
}
uint64_t fracBits = xGetIntraFracBitsQT( cs, partitioner, false, true, -1, ispType );
Distortion uiDist = cs.dist;
double dCost = m_pcRdCost->calcRdCost( fracBits, uiDist - baseDist );
//----- compare -----
if( dCost < dBestCost )
{
#if JVET_AG0154_DECODER_DERIVED_CCP_FUSION
if (uiDist < bestDist)
{
bestDist = uiDist;
}
#endif
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
if( lumaUsesISP && dCost < bestCostSoFar )
{
bestCostSoFar = dCost;
}
for( uint32_t i = getFirstComponentOfChannel( CHANNEL_TYPE_CHROMA ); i < numberValidComponents; i++ )
{
const CompArea &area = pu.blocks[i];
saveCS.getRecoBuf ( area ).copyFrom( cs.getRecoBuf ( area ) );
#if KEEP_PRED_AND_RESI_SIGNALS
saveCS.getPredBuf ( area ).copyFrom( cs.getPredBuf ( area ) );
saveCS.getResiBuf ( area ).copyFrom( cs.getResiBuf ( area ) );
#endif
saveCS.getPredBuf ( area ).copyFrom( cs.getPredBuf (area ) );
cs.picture->getPredBuf( area ).copyFrom( cs.getPredBuf (area ) );
cs.picture->getRecoBuf( area ).copyFrom( cs.getRecoBuf( area ) );
for( uint32_t j = 0; j < saveCS.tus.size(); j++ )
{
saveCS.tus[j]->copyComponentFrom( *orgTUs[j], area.compID );
}
}
dBestCost = dCost;
uiBestDist = uiDist;
uiBestMode = chromaIntraMode;
bestBDPCMMode = cu.bdpcmModeChroma;
bestGlmIdc = pu.glmIdc;
Chia-Ming Tsai
committed
#if JVET_AD0188_CCP_MERGE
ccpModelBest = pu.curCand;
ccpModelBest.glmIdc = pu.glmIdc.cb0;
#endif
if ( chromaIntraMode == LM_CHROMA_IDX && !bestGlmIdc.isActive() )
{
break;
}
Chia-Ming Tsai
committed
#if JVET_AD0188_CCP_MERGE
pu.curCand = {};
#endif
#if JVET_AH0136_CHROMA_REORDERING
cs.setDecomp(pu.Cb(), false);
#endif
#if JVET_AC0119_LM_CHROMA_FUSION
uint32_t uiFusionModeNum = 2;
#if MMLM
uiFusionModeNum += 1;
#endif
int32_t fusionModeMap[6][2];
Distortion satdChromaFusionCost[6];
int satdChromaFusionModeList[6];
for (int i = 0; i < 6; i++)
{
fusionModeIsEnable[i] = false;
fusionModeMap[i][0] = fusionModeMap[i][1] = 0;
satdChromaFusionCost[i] = MAX_UINT64;
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
satdChromaFusionModeList[i] = i;
}
Distortion sad = 0;
Distortion sadCb = 0, satdCb = 0;
Distortion sadCr = 0, satdCr = 0;
CodingStructure& cs = *(pu.cs);
DistParam distParamSadCb, distParamSatdCb;
DistParam distParamSadCr, distParamSatdCr;
m_pcRdCost->setDistParam(distParamSadCb, cs.getOrgBuf(pu.Cb()), fusionStorage[0].Cb(), pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cb, false);
m_pcRdCost->setDistParam(distParamSatdCb, cs.getOrgBuf(pu.Cb()), fusionStorage[0].Cb(), pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cb, true);
m_pcRdCost->setDistParam(distParamSadCr, cs.getOrgBuf(pu.Cr()), fusionStorage[0].Cr(), pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cr, false);
m_pcRdCost->setDistParam(distParamSatdCr, cs.getOrgBuf(pu.Cr()), fusionStorage[0].Cr(), pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cr, true);
distParamSadCb.applyWeight = false;
distParamSatdCb.applyWeight = false;
distParamSadCr.applyWeight = false;
distParamSatdCr.applyWeight = false;
xCflmCreateLumaRef(pu, pu.Cb());
for (int32_t uiMode = 0; uiMode < 2; uiMode++)
{
int chromaIntraMode = (uiMode == 0) ? bestNonLmMode : secondNonLmMode;
if (chromaIntraMode == -1)
{
continue;
}
if (PU::hasChromaFusionFlag(pu, chromaIntraMode))
{
pu.intraDir[1] = chromaIntraMode;
#if JVET_AH0136_CHROMA_REORDERING && JVET_AC0071_DBV
if (cu.cs->sps->getUseChromaReordering() && PU::isDbvMode(pu.intraDir[1]) && CS::isDualITree(cs))
{
pu.bv = cu.bvs[pu.intraDir[1] - DBV_CHROMA_IDX];
pu.mv[0] = cu.mvs[pu.intraDir[1] - DBV_CHROMA_IDX];
pu.cu->rribcFlipType = cu.rribcTypes[pu.intraDir[1] - DBV_CHROMA_IDX];
}
#endif
if (!xCflmCreateChromaPred(pu, COMPONENT_Cb, predStorage[uiMode].Cb()
#if JVET_AH0136_CHROMA_REORDERING
, pcInterPred
#endif
) ||
!xCflmCreateChromaPred(pu, COMPONENT_Cr, predStorage[uiMode].Cr()
#if JVET_AH0136_CHROMA_REORDERING
, pcInterPred
#endif
))
{
break;
}
initIntraPatternChType(cu, pu.Cb());
initIntraPatternChType(cu, pu.Cr());
for (int32_t fusionMode = 0; fusionMode < uiFusionModeNum; fusionMode++)
{
pu.intraDir[1] = chromaIntraMode;
pu.isChromaFusion = fusionMode + 1;
int idx = uiMode * uiFusionModeNum + fusionMode;
fusionStorage[idx].Cb().copyFrom( predStorage[uiMode].Cb() );
fusionStorage[idx].Cr().copyFrom( predStorage[uiMode].Cr() );
geneChromaFusionPred(COMPONENT_Cb, fusionStorage[idx].Cb(), pu
#if JVET_AH0136_CHROMA_REORDERING
, pcInterPred
#endif
);
geneChromaFusionPred(COMPONENT_Cr, fusionStorage[idx].Cr(), pu
#if JVET_AH0136_CHROMA_REORDERING
, pcInterPred
#endif
);
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
distParamSadCb.cur = fusionStorage[idx].Cb();
distParamSatdCb.cur = fusionStorage[idx].Cb();
distParamSadCr.cur = fusionStorage[idx].Cr();
distParamSatdCr.cur = fusionStorage[idx].Cr();
sadCb = distParamSadCb.distFunc(distParamSadCb) * 2;
satdCb = distParamSatdCb.distFunc(distParamSatdCb);
sad = std::min(sadCb, satdCb);
sadCr = distParamSadCr.distFunc(distParamSadCr) * 2;
satdCr = distParamSatdCr.distFunc(distParamSatdCr);
sad += std::min(sadCr, satdCr);
fusionModeMap[idx][0] = chromaIntraMode;
fusionModeMap[idx][1] = fusionMode + 1;
satdChromaFusionCost[idx] = sad;
fusionModeIsEnable[idx] = true;
}
}
}
for (int i = 0; i < 3; i++)
{
for (int j = i + 1; j < 6; j++)
{
if (satdChromaFusionCost[j] < satdChromaFusionCost[i])
{
std::swap( satdChromaFusionModeList[i], satdChromaFusionModeList[j] );
std::swap( satdChromaFusionCost[i], satdChromaFusionCost[j] );
}
}
}
for (int i = 0; i < 3; i++)
{
fusionModeIsEnable[satdChromaFusionModeList[6 - 1 - i]] = false;
}
#endif
#if JVET_AC0119_LM_CHROMA_FUSION
for (int32_t lstIdx = 0; lstIdx < 6; lstIdx++)
{
int iModedx = satdChromaFusionModeList[lstIdx];
if( !fusionModeIsEnable[iModedx] )
{
int chromaIntraMode = fusionModeMap[iModedx][0];
pu.isChromaFusion = fusionModeMap[iModedx][1];
#else
for (int32_t uiMode = 0; uiMode < 1; uiMode++)
{
int chromaIntraMode = bestNonLmMode;
#if ENABLE_DIMD
if (!pu.cs->slice->isIntra() && cu.slice->getSPS()->getUseDimd())
chromaIntraMode = DIMD_CHROMA_IDX;
#endif
if (PU::hasChromaFusionFlag(pu, chromaIntraMode))
cs.setDecomp(pu.Cb(), false);
cs.dist = baseDist;
//----- restore context models -----
m_CABACEstimator->getCtx() = ctxStart;
//----- chroma coding -----
pu.intraDir[1] = chromaIntraMode;
xRecurIntraChromaCodingQT(cs, partitioner, bestCostSoFar, ispType
#if JVET_AC0119_LM_CHROMA_FUSION
, fusionStorage[iModedx]
#elif JVET_AD0208_IBC_ADAPT_FOR_CAM_CAPTURED_CONTENTS && (JVET_AB0143_CCCM_TS && !JVET_AC0119_LM_CHROMA_FUSION)
, UnitBuf<Pel>()
#endif
#if JVET_AD0208_IBC_ADAPT_FOR_CAM_CAPTURED_CONTENTS
, pcInterPred
if (lumaUsesISP && cs.dist == MAX_UINT)
if (cs.sps->getTransformSkipEnabledFlag())
m_CABACEstimator->getCtx() = ctxStart;
}
uint64_t fracBits = xGetIntraFracBitsQT(cs, partitioner, false, true, -1, ispType);
Distortion uiDist = cs.dist;
double dCost = m_pcRdCost->calcRdCost(fracBits, uiDist - baseDist);
if (dCost < dBestCost)
{
#if JVET_AG0154_DECODER_DERIVED_CCP_FUSION
if (uiDist < bestDist)
{
bestDist = uiDist;
}
#endif
if (lumaUsesISP && dCost < bestCostSoFar)
for (uint32_t i = getFirstComponentOfChannel(CHANNEL_TYPE_CHROMA); i < numberValidComponents; i++)
{
const CompArea &area = pu.blocks[i];
saveCS.getRecoBuf(area).copyFrom(cs.getRecoBuf(area));
saveCS.getPredBuf(area).copyFrom(cs.getPredBuf(area));
saveCS.getResiBuf(area).copyFrom(cs.getResiBuf(area));
saveCS.getPredBuf(area).copyFrom(cs.getPredBuf(area));
cs.picture->getPredBuf(area).copyFrom(cs.getPredBuf(area));
cs.picture->getRecoBuf(area).copyFrom(cs.getRecoBuf(area));
for (uint32_t j = 0; j < saveCS.tus.size(); j++)
{
saveCS.tus[j]->copyComponentFrom(*orgTUs[j], area.compID);
}
}
dBestCost = dCost;
uiBestDist = uiDist;
uiBestMode = chromaIntraMode;
bestBDPCMMode = cu.bdpcmModeChroma;
isChromaFusion = pu.isChromaFusion;
Chia-Ming Tsai
committed
#endif
#if JVET_AD0188_CCP_MERGE
if (isChromaFusion == 1)
{
ccpModelBest = pu.curCand;
}
else
{
ccpModelBest.type = CCP_TYPE_NONE;
}
#if !JVET_AC0119_LM_CHROMA_FUSION
#if JVET_AC0119_LM_CHROMA_FUSION
pu.isChromaFusion = 0;
#else
pu.isChromaFusion = false;
#endif
Chia-Ming Tsai
committed
#if JVET_AD0188_CCP_MERGE
pu.curCand = {};
#endif
#if JVET_AH0136_CHROMA_REORDERING
cs.setDecomp(pu.Cb(), false);
#endif
#if JVET_Z0050_CCLM_SLOPE
#if MMLM
for (int32_t uiMode = 0; uiMode < 2; uiMode++)
{
int chromaIntraMode = uiMode ? MMLM_CHROMA_IDX : LM_CHROMA_IDX;
#else
for (int32_t uiMode = 0; uiMode < 1; uiMode++)
{
int chromaIntraMode = LM_CHROMA_IDX;
#endif
if ( PU::isLMCModeEnabled( pu, chromaIntraMode ) && PU::hasCclmDeltaFlag( pu, chromaIntraMode ) )
{
if ( satdCclmOffsetsBest[chromaIntraMode - LM_CHROMA_IDX].isActive() )
{
pu.intraDir[1] = chromaIntraMode;
pu.cclmOffsets = satdCclmOffsetsBest[chromaIntraMode - LM_CHROMA_IDX];
#if JVET_Z0050_DIMD_CHROMA_FUSION
#if JVET_AC0119_LM_CHROMA_FUSION
pu.isChromaFusion = 0;
#else
#endif
// RD search replicated from above
cs.setDecomp( pu.Cb(), false );
cs.dist = baseDist;
//----- restore context models -----
m_CABACEstimator->getCtx() = ctxStart;
xRecurIntraChromaCodingQT( cs, partitioner, bestCostSoFar, ispType
#if JVET_AD0208_IBC_ADAPT_FOR_CAM_CAPTURED_CONTENTS && (JVET_AB0143_CCCM_TS || JVET_AC0119_LM_CHROMA_FUSION)
, UnitBuf<Pel>()
#endif
#if JVET_AD0208_IBC_ADAPT_FOR_CAM_CAPTURED_CONTENTS
, pcInterPred
#endif
);