Newer
Older
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;
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 (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( 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
);
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
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( 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_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;
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
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 (!xCflmCreateChromaPred(pu, COMPONENT_Cb, predStorage[uiMode].Cb()) ||
!xCflmCreateChromaPred(pu, COMPONENT_Cr, predStorage[uiMode].Cr()))
{
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() );
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
geneChromaFusionPred(COMPONENT_Cb, fusionStorage[idx].Cb(), pu);
geneChromaFusionPred(COMPONENT_Cr, fusionStorage[idx].Cr(), pu);
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 (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_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
);
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
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( 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;
bestCclmOffsets = pu.cclmOffsets;
#if JVET_Z0050_DIMD_CHROMA_FUSION
isChromaFusion = pu.isChromaFusion;
#endif
#if JVET_AA0126_GLM
bestGlmIdc = pu.glmIdc;
Chia-Ming Tsai
committed
#endif
#if JVET_AD0188_CCP_MERGE
ccpModelBest = pu.curCand;
#endif
}
}
}
}
pu.cclmOffsets.setAllZero();
Chia-Ming Tsai
committed
#if JVET_AD0188_CCP_MERGE
pu.curCand = {};
#endif
#if JVET_AB0143_CCCM_TS
int chromaIntraModeInCCCM = LM_CHROMA_IDX;
#if JVET_AC0147_CCCM_NO_SUBSAMPLING
bool isCCCMEnabled = isCccmFullEnabled;
#else
isCCCMEnabled = isCccmFullEnabled;
for (int32_t uiMode = 0; uiMode < CCCM_NUM_MODES; uiMode++)
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
{
if (uiMode == 1)
{
chromaIntraModeInCCCM = MDLM_L_IDX;
isCCCMEnabled = isCccmLeftEnabled;
pu.cccmFlag = 2;
}
else if (uiMode == 2)
{
chromaIntraModeInCCCM = MDLM_T_IDX;
isCCCMEnabled = isCccmTopEnabled;
pu.cccmFlag = 3;
}
#if MMLM
else if (uiMode == 3)
{
chromaIntraModeInCCCM = MMLM_CHROMA_IDX;
isCCCMEnabled = isMultiCccmFullEnabled;
pu.cccmFlag = 1;
}
else if (uiMode == 4)
{
chromaIntraModeInCCCM = MMLM_L_IDX;
isCCCMEnabled = isMultiCccmLeftEnabled;
pu.cccmFlag = 2;
}
else if (uiMode == 5)
{
chromaIntraModeInCCCM = MMLM_T_IDX;
isCCCMEnabled = isMultiCccmTopEnabled;
pu.cccmFlag = 3;
}
#endif
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
#if JVET_AC0054_GLCCCM
pu.glCccmFlag = 0;
if (uiMode >= CCCM_NUM_MODES / 2)
{
pu.glCccmFlag = 1;
#if MMLM
chromaIntraModeInCCCM = uiMode == 6 ? LM_CHROMA_IDX
: uiMode == 7 ? MDLM_L_IDX
: uiMode == 8 ? MDLM_T_IDX
: uiMode == 9 ? MMLM_CHROMA_IDX
: uiMode == 10 ? MMLM_L_IDX : MMLM_T_IDX;
isCCCMEnabled = uiMode == 6 ? isCccmFullEnabled
: uiMode == 7 ? isCccmLeftEnabled
: uiMode == 8 ? isCccmTopEnabled
: uiMode == 9 ? isMultiCccmFullEnabled
: uiMode == 10 ? isMultiCccmLeftEnabled : isMultiCccmTopEnabled;
pu.cccmFlag = uiMode == 6 ? 1
: uiMode == 7 ? 2
: uiMode == 8 ? 3
: uiMode == 9 ? 1
: uiMode == 10 ? 2 : 3;
#else
chromaIntraModeInCCCM = uiMode == 3 ? LM_CHROMA_IDX
: uiMode == 4 ? MDLM_L_IDX : MDLM_T_IDX;
isCCCMEnabled = uiMode == 3 ? isCccmFullEnabled
: uiMode == 4 ? isCccmLeftEnabled : isCccmTopEnabled;
pu.cccmFlag = uiMode == 3 ? 1
: uiMode == 4 ? 2 : 3;
#endif
if (!isGlCccmModeEnabledInRdo[chromaIntraModeInCCCM])
{
continue;
}
}
#if !JVET_AD0202_CCCM_MDF
#endif // JVET_AC0054_GLCCCM
#if !JVET_AD0202_CCCM_MDF
#if JVET_AC0147_CCCM_NO_SUBSAMPLING
if (!isCccmModeEnabledInRdo[0][chromaIntraModeInCCCM] && !isCccmModeEnabledInRdo[1][chromaIntraModeInCCCM])
if (!isCccmModeEnabledInRdo[chromaIntraModeInCCCM])
{
continue;
}
#if JVET_AC0054_GLCCCM
if (isCCCMEnabled)
{
#else
#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::cccmSingleModeAvail(pu, chromaIntraMode) || PU::cccmMultiModeAvail(pu, chromaIntraMode) )
{
pu.cccmFlag = 1;
#if JVET_AC0147_CCCM_NO_SUBSAMPLING
for (int sub = 0; sub < pu.cu->slice->getSPS()->getUseCccm(); sub++)
{
#if JVET_AD0202_CCCM_MDF
for (int32_t filterIdx = 0; filterIdx < CCCM_NUM_PRED_FILTER; filterIdx++)
{
if (filterIdx > 0 && (sub == 1 || uiMode > 5))
{
continue;
}
pu.cccmMultiFilterIdx = filterIdx;
Chia-Ming Tsai
committed
#if JVET_AD0188_CCP_MERGE
pu.curCand = {};
#endif
pu.cccmNoSubFlag = sub;
#if JVET_AC0054_GLCCCM
if (sub && ((uiMode >= CCCM_NUM_MODES / 2) || pu.glCccmFlag))
{
continue;
}
#if JVET_AD0202_CCCM_MDF
else if (sub == 0 && uiMode < 6)
{
if (!isCccmWithMulDownSamplingEnabledInRdo[chromaIntraModeInCCCM][filterIdx])
{
continue;
}
}
else if (sub)
#else
{
if (!isCccmModeEnabledInRdo[sub][chromaIntraModeInCCCM])
{
continue;
}
}
#else // else of JVET_AC0054_GLCCCM
if (!isCccmModeEnabledInRdo[sub][chromaIntraModeInCCCM])
{
continue;
}
#endif // end of JVET_AC0054_GLCCCM
// Original RD check code replicated from above
cs.setDecomp( pu.Cb(), false );
cs.dist = baseDist;
//----- restore context models -----
m_CABACEstimator->getCtx() = ctxStart;
//----- chroma coding -----
#if JVET_AB0143_CCCM_TS
pu.intraDir[1] = chromaIntraModeInCCCM;
#if JVET_AC0147_CCCM_NO_SUBSAMPLING
#if JVET_AD0202_CCCM_MDF
const int cccmBufferIdx = filterIdx * CCCM_NUM_MODES + uiMode;
Chia-Ming Tsai
committed
#endif
#if JVET_AD0188_CCP_MERGE
if (pu.cs->slice->isIntra())
Chia-Ming Tsai
committed
{
#if JVET_AD0202_CCCM_MDF
pu.curCand = m_ccmParamsStorage[sub][cccmBufferIdx];
#else
pu.curCand = m_ccmParamsStorage[sub][uiMode];
#endif
}
#endif
#if JVET_AD0202_CCCM_MDF
xRecurIntraChromaCodingQT(cs, partitioner, bestCostSoFar, ispType, cccmStorage[sub][cccmBufferIdx]
#if JVET_AD0208_IBC_ADAPT_FOR_CAM_CAPTURED_CONTENTS
, pcInterPred
#endif
);
xRecurIntraChromaCodingQT(cs, partitioner, bestCostSoFar, ispType, cccmStorage[sub][uiMode]
#if JVET_AD0208_IBC_ADAPT_FOR_CAM_CAPTURED_CONTENTS
, pcInterPred
#endif
);
xRecurIntraChromaCodingQT(cs, partitioner, bestCostSoFar, ispType, cccmStorage[uiMode]
#if JVET_AD0208_IBC_ADAPT_FOR_CAM_CAPTURED_CONTENTS
, pcInterPred
#endif
);
xRecurIntraChromaCodingQT( cs, partitioner, bestCostSoFar, ispType
#if JVET_AD0208_IBC_ADAPT_FOR_CAM_CAPTURED_CONTENTS && JVET_AC0119_LM_CHROMA_FUSION
, UnitBuf<Pel>()
#endif
#if JVET_AD0208_IBC_ADAPT_FOR_CAM_CAPTURED_CONTENTS
, pcInterPred
#endif
);
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
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( 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;
#if JVET_AB0143_CCCM_TS
uiBestMode = chromaIntraModeInCCCM;
#else
bestBDPCMMode = cu.bdpcmModeChroma;
#if JVET_Z0050_DIMD_CHROMA_FUSION
isChromaFusion = pu.isChromaFusion;
#endif
#if JVET_Z0050_CCLM_SLOPE
bestCclmOffsets = pu.cclmOffsets;
#endif
cccmModeBest = pu.cccmFlag;
#endif
#if JVET_AC0054_GLCCCM
glCccmBest = pu.glCccmFlag;
#endif
#if JVET_AD0202_CCCM_MDF
cccmMultiFilterIdxBest = pu.cccmMultiFilterIdx;
#endif
Chia-Ming Tsai
committed
#if JVET_AD0188_CCP_MERGE
ccpModelBest = pu.curCand;
#endif
#if JVET_AC0147_CCCM_NO_SUBSAMPLING
cccmNoSubBest = pu.cccmNoSubFlag;
}
#endif
#if JVET_AD0202_CCCM_MDF
}
#if JVET_AD0202_CCCM_MDF
pu.cccmMultiFilterIdx = 0;
#endif
Chia-Ming Tsai
committed
#if JVET_AD0188_CCP_MERGE
pu.curCand = {};
#endif
#endif
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
#if JVET_AD0120_LBCCP && MMLM
pu.intraDir[1] = MMLM_CHROMA_IDX;
pu.ccInsideFilter = 1;
if (pu.cs->sps->getUseLMChroma())
{
#if JVET_AA0057_CCCM
pu.cccmFlag = 0;
#endif
#if JVET_AC0147_CCCM_NO_SUBSAMPLING
pu.cccmNoSubFlag = 0;
#endif
#if JVET_AC0054_GLCCCM
pu.glCccmFlag = 0;
#endif
#if JVET_AD0202_CCCM_MDF
pu.cccmMultiFilterIdx = 0;
#endif
filterPredInside(COMPONENT_Cb, lmPredFilterStorage[lmPredFiltIdx].Cb(), pu);
filterPredInside(COMPONENT_Cr, lmPredFilterStorage[lmPredFiltIdx].Cr(), pu);
fillLmPredFiltList(pu, lmPredFilterStorage[lmPredFiltIdx], lmPredFiltIdx, miLmPredFiltList);
#if JVET_AA0057_CCCM
if (isMultiCccmFullEnabled)
{
pu.cccmFlag = 1;
int idxStart = lmPredFiltIdx;
#if JVET_AD0202_CCCM_MDF
int idxEnd = lmPredFiltIdx + (isMultiCccmFullEnabled2 ? CCCM_NUM_PRED_FILTER : 1);
#else
int idxEnd = lmPredFiltIdx + 1;
#endif
for (int i = idxStart; i < idxEnd; i++)
{
#if JVET_AD0202_CCCM_MDF
pu.cccmMultiFilterIdx = i - idxStart;
#endif
#if JVET_AD0188_CCP_MERGE
pu.curCand = {};
#endif
predIntraCCCM(pu, lmPredFilterStorage[lmPredFiltIdx].Cb(), lmPredFilterStorage[lmPredFiltIdx].Cr(), pu.intraDir[1]);
#if JVET_AD0188_CCP_MERGE
ccpCandlmPredFilt[lmPredFiltIdx] = pu.curCand;
#endif
fillLmPredFiltList(pu, lmPredFilterStorage[lmPredFiltIdx], lmPredFiltIdx, miLmPredFiltList);
}
#if JVET_AD0202_CCCM_MDF
pu.cccmMultiFilterIdx = 0;
#endif
#if JVET_AC0054_GLCCCM
pu.glCccmFlag = 1;
#if JVET_AD0188_CCP_MERGE
pu.curCand = {};
#endif
predIntraCCCM(pu, lmPredFilterStorage[lmPredFiltIdx].Cb(), lmPredFilterStorage[lmPredFiltIdx].Cr(), pu.intraDir[1]);
#if JVET_AD0188_CCP_MERGE
ccpCandlmPredFilt[lmPredFiltIdx] = pu.curCand;
#endif
fillLmPredFiltList(pu, lmPredFilterStorage[lmPredFiltIdx], lmPredFiltIdx, miLmPredFiltList);
pu.glCccmFlag = 0;
#endif
#if JVET_AC0147_CCCM_NO_SUBSAMPLING
if (pu.cu->slice->getSPS()->getUseCccm() > 1)
{
pu.cccmNoSubFlag = 1;
#if JVET_AD0188_CCP_MERGE
pu.curCand = {};
#endif
predIntraCCCM(pu, lmPredFilterStorage[lmPredFiltIdx].Cb(), lmPredFilterStorage[lmPredFiltIdx].Cr(), pu.intraDir[1]);
#if JVET_AD0188_CCP_MERGE
ccpCandlmPredFilt[lmPredFiltIdx] = pu.curCand;
#endif
fillLmPredFiltList(pu, lmPredFilterStorage[lmPredFiltIdx], lmPredFiltIdx, miLmPredFiltList);
pu.cccmNoSubFlag = 0;
}
#endif
std::stable_sort(miLmPredFiltList.begin(), miLmPredFiltList.end(), [](const lmPredFiltModeInfo &l, const lmPredFiltModeInfo &r) { return l.cost < r.cost; });
}
#endif
}
int numLmPredFilterRdo = std::min(1, lmPredFiltIdx);
if (lmPredFiltIdx > 2 && miLmPredFiltList[2].cost != miLmPredFiltList[1].cost && miLmPredFiltList[2].cost < 1.5 * miLmPredFiltList[1].cost)
{
numLmPredFilterRdo += 1;
}
for (int idx = 0; idx < numLmPredFilterRdo; idx++)
{
#if JVET_AA0057_CCCM
pu.cccmFlag = miLmPredFiltList[idx].isCccm;
#endif
#if JVET_AC0147_CCCM_NO_SUBSAMPLING
pu.cccmNoSubFlag = miLmPredFiltList[idx].isCccmNoSub;
#endif
#if JVET_AC0054_GLCCCM
pu.glCccmFlag = miLmPredFiltList[idx].isGlcccm;
#endif
#if JVET_AD0202_CCCM_MDF
pu.cccmMultiFilterIdx = miLmPredFiltList[idx].cccmMdfIdx;
#endif
// Original RD check code replicated from above
cs.setDecomp(pu.Cb(), false);
cs.dist = baseDist;
//----- restore context models -----
m_CABACEstimator->getCtx() = ctxStart;
//----- chroma coding -----
xRecurIntraChromaCodingQT(cs, partitioner, bestCostSoFar, ispType, lmPredFilterStorage[miLmPredFiltList[idx].bufIdx]);
if (lumaUsesISP && cs.dist == MAX_UINT)
{
continue;
}
if (cs.sps->getTransformSkipEnabledFlag())
{