Newer
Older
#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
);
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
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
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++)
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
{
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
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
#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
);
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
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
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
#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())
{
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
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
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));
#if !JVET_AB0143_CCCM_TS
cs.picture->getRecoBuf(area).copyFrom(cs.getRecoBuf(area));
#endif
for (uint32_t j = 0; j < saveCS.tus.size(); j++)
{
saveCS.tus[j]->copyComponentFrom(*orgTUs[j], area.compID);
}
}
dBestCost = dCost;
uiBestDist = uiDist;
uiBestMode = pu.intraDir[1];
bestBDPCMMode = cu.bdpcmModeChroma;
#if JVET_Z0050_DIMD_CHROMA_FUSION
isChromaFusion = pu.isChromaFusion;
#endif
#if JVET_Z0050_CCLM_SLOPE
bestCclmOffsets = pu.cclmOffsets;
#endif
#if JVET_AA0057_CCCM
cccmModeBest = pu.cccmFlag;
#endif
#if JVET_AA0126_GLM
bestGlmIdc = pu.glmIdc;
#endif
bestCCInsideFilter = pu.ccInsideFilter;
#if JVET_AC0054_GLCCCM
glCccmBest = pu.glCccmFlag;
#endif
#if JVET_AD0202_CCCM_MDF
cccmMultiFilterIdxBest = pu.cccmMultiFilterIdx;
#endif
#if JVET_AC0147_CCCM_NO_SUBSAMPLING
cccmNoSubBest = pu.cccmNoSubFlag;
#endif
#if JVET_AD0188_CCP_MERGE
ccpModelBest = ccpCandlmPredFilt[miLmPredFiltList[idx].bufIdx];
#endif
}
}
pu.ccInsideFilter = 0;
#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
#if JVET_AD0188_CCP_MERGE
pu.curCand = {};
#endif
#endif
Chia-Ming Tsai
committed
#if JVET_AD0188_CCP_MERGE
if (PU::hasNonLocalCCP(pu))
{
pu.cccmFlag = 0;
pu.cccmNoSubFlag = 0;
pu.glCccmFlag = 0;
CCPModelCandidate candList[MAX_CCP_CAND_LIST_SIZE];
#if JVET_AG0059_CCP_MERGE_ENHANCEMENT
double orderedCCPcost[MAX_CCP_CAND_LIST_SIZE * 3];
int orderedCCPCand[MAX_CCP_CAND_LIST_SIZE * 3];
PelUnitBuf ccpCandStorage[MAX_CCP_CAND_LIST_SIZE * 3];
#else
Chia-Ming Tsai
committed
double orderedCCPcost[MAX_CCP_CAND_LIST_SIZE];
int orderedCCPCand[MAX_CCP_CAND_LIST_SIZE];
PelUnitBuf ccpCandStorage[MAX_CCP_CAND_LIST_SIZE];
#endif
Chia-Ming Tsai
committed
int numPos = PU::getCCPModelCandidateList(pu, candList);
#if JVET_AG0154_DECODER_DERIVED_CCP_FUSION
PelUnitBuf ccpFusionStorage[MAX_CCP_FUSION_NUM];
int FusionList[MAX_CCP_FUSION_NUM * 2] = { MAX_CCP_FUSION_NUM };
reorderCCPCandidates(pu, candList, numPos, FusionList);
#else
Chia-Ming Tsai
committed
reorderCCPCandidates(pu, candList, numPos);
Chia-Ming Tsai
committed
const double sqrtLambdaForFirstPass = m_pcRdCost->getMotionLambda() * FRAC_BITS_SCALE;
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
5689
5690
5691
5692
#if JVET_AG0059_CCP_MERGE_ENHANCEMENT
int fusionModeNum = PU::hasCCPMergeFusionFlag(pu) ? 2 : 0;
PelUnitBuf predCCPFusionStorage[2];
if (fusionModeNum)
{
for (int i = 0; i < 2; i++)
{
pu.ccpMergeFusionType = i;
predCCPFusionStorage[i] = m_predCCPFusionStorage[i].getBuf(localArea);
getPredForCCPMrgFusion(pu, predCCPFusionStorage[i].Cb(), predCCPFusionStorage[i].Cr());
}
}
for (int nlCCPFusionMode = 0; nlCCPFusionMode <= fusionModeNum; nlCCPFusionMode++)
{
for (int ccpMergeIdx = 0; ccpMergeIdx < numPos; ccpMergeIdx++)
{
pu.intraDir[1] = LM_CHROMA_IDX; // temporary assigned, for SATD checking.
pu.idxNonLocalCCP = ccpMergeIdx + 1;
pu.ccpMergeFusionFlag = nlCCPFusionMode > 0;
pu.ccpMergeFusionType = nlCCPFusionMode > 1;
int nonAdjCCCMCand = ccpMergeIdx + nlCCPFusionMode * numPos;
if (pu.ccpMergeFusionFlag == 0)
{
ccpCandStorage[nonAdjCCCMCand] = m_cccmStorage[0][nonAdjCCCMCand].getBuf(localUnitArea); // Borrow the CCCM storage
}
else
{
ccpCandStorage[nonAdjCCCMCand] = m_cccmStorage[1][nonAdjCCCMCand].getBuf(localUnitArea); // Borrow the CCCM storage
ccpCandStorage[nonAdjCCCMCand].Cb().copyFrom(ccpCandStorage[ccpMergeIdx].Cb());
ccpCandStorage[nonAdjCCCMCand].Cr().copyFrom(ccpCandStorage[ccpMergeIdx].Cr());
}
#else
Chia-Ming Tsai
committed
for (int nonAdjCCCMCand = 0; nonAdjCCCMCand < numPos; nonAdjCCCMCand++)
{
pu.intraDir[1] = LM_CHROMA_IDX; // temporary assigned, for SATD checking.
Chia-Ming Tsai
committed
pu.idxNonLocalCCP = nonAdjCCCMCand + 1;
ccpCandStorage[nonAdjCCCMCand] = m_cccmStorage[0][nonAdjCCCMCand].getBuf(localUnitArea); // Borrow the CCCM storage
#endif
Chia-Ming Tsai
committed
uint64_t sad = 0;
uint64_t sadCb = 0;
uint64_t satdCb = 0;
uint64_t sadCr = 0;
uint64_t satdCr = 0;
CodingStructure &cs = *(pu.cs);
CompArea areaCb = pu.Cb();
PelBuf orgCb = cs.getOrgBuf(areaCb);
PelBuf predCb = ccpCandStorage[nonAdjCCCMCand].Cb();
CompArea areaCr = pu.Cr();
PelBuf orgCr = cs.getOrgBuf(areaCr);
PelBuf predCr = ccpCandStorage[nonAdjCCCMCand].Cr();
m_pcRdCost->setDistParam(distParamSad, orgCb, predCb, pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cb, false);
m_pcRdCost->setDistParam(distParamSatd, orgCb, predCb, pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cb, true);
distParamSad.applyWeight = false;
distParamSatd.applyWeight = false;
#if JVET_AG0059_CCP_MERGE_ENHANCEMENT
if (pu.ccpMergeFusionFlag == 0)
{
#endif
Chia-Ming Tsai
committed
pu.curCand = candList[nonAdjCCCMCand];
predCCPCandidate(pu, predCb, predCr);
candList[nonAdjCCCMCand] = pu.curCand;
#if JVET_AG0059_CCP_MERGE_ENHANCEMENT
}
else
{
pu.curCand = candList[ccpMergeIdx];
xCalcCcpMrgPred(pu, COMPONENT_Cb, predCCPFusionStorage[pu.ccpMergeFusionType].Cb(), ccpCandStorage[nonAdjCCCMCand].Cb());
xCalcCcpMrgPred(pu, COMPONENT_Cr, predCCPFusionStorage[pu.ccpMergeFusionType].Cr(), ccpCandStorage[nonAdjCCCMCand].Cr());
}
#endif
Chia-Ming Tsai
committed
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
5762
5763
5764
5765
5766
5767
5768
5769
5770
sadCb = distParamSad.distFunc(distParamSad) * 2;
satdCb = distParamSatd.distFunc(distParamSatd);
sad += std::min(sadCb, satdCb);
m_pcRdCost->setDistParam(distParamSad, orgCr, predCr, pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cr, false);
m_pcRdCost->setDistParam(distParamSatd, orgCr, predCr, pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cr, true);
distParamSad.applyWeight = false;
distParamSatd.applyWeight = false;
sadCr = distParamSad.distFunc(distParamSad) * 2;
satdCr = distParamSatd.distFunc(distParamSatd);
sad += std::min(sadCr, satdCr);
m_CABACEstimator->resetBits();
m_CABACEstimator->nonLocalCCPIndex(pu);
uint64_t estbits = m_CABACEstimator->getEstFracBits();
double curCost = (double) sad + sqrtLambdaForFirstPass * (double) estbits;
orderedCCPcost[nonAdjCCCMCand] = curCost;
orderedCCPCand[nonAdjCCCMCand] = nonAdjCCCMCand;
for (int i = 0; i < nonAdjCCCMCand; i++)
{
if (curCost < orderedCCPcost[i])
{
for (int j = nonAdjCCCMCand; j > i; j--)
{
orderedCCPcost[j] = orderedCCPcost[j - 1];
orderedCCPCand[j] = orderedCCPCand[j - 1];
}
orderedCCPcost[i] = curCost;
orderedCCPCand[i] = nonAdjCCCMCand;
break;
}
}
}
#if JVET_AG0059_CCP_MERGE_ENHANCEMENT
}
#endif
Chia-Ming Tsai
committed
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
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
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
#if JVET_AG0154_DECODER_DERIVED_CCP_FUSION
if ((pu.cu->slice->getSPS()->getUseDdCcpFusion()) && (!m_skipDdCcpMergeFusionList || !(cs.slice->getSliceType() == I_SLICE)))
{
pu.idxNonLocalCCP = 1;
int numRDtestFusion = 2;
int numRDtestFusionMinusOne = numRDtestFusion - 1;
int orderedCCPFusionCand[MAX_CCP_FUSION_NUM];
int ccpfusionIdx;
double orderedCCPFusioncost[MAX_CCP_FUSION_NUM];
for (ccpfusionIdx = 0; ccpfusionIdx < MAX_CCP_FUSION_NUM; ccpfusionIdx++)
{
int ccpMergeIndex0 = FusionList[2 * ccpfusionIdx];
int ccpMergeIndex1 = FusionList[2 * ccpfusionIdx + 1];
if (ccpMergeIndex0 >= numPos || ccpMergeIndex1 >= numPos)
{
continue;
}
pu.intraDir[1] = LM_CHROMA_IDX;
pu.ddNonLocalCCPFusion = ccpfusionIdx + 1;
uint64_t sad = 0;
uint64_t sadCb = 0;
uint64_t satdCb = 0;
uint64_t sadCr = 0;
uint64_t satdCr = 0;
CodingStructure &cs = *(pu.cs);
CompArea areaCb = pu.Cb();
PelBuf orgCb = cs.getOrgBuf(areaCb);
PelBuf srcCb0 = ccpCandStorage[ccpMergeIndex0].Cb();
PelBuf srcCb1 = ccpCandStorage[ccpMergeIndex1].Cb();
CompArea areaCr = pu.Cr();
PelBuf orgCr = cs.getOrgBuf(areaCr);
PelBuf srcCr0 = ccpCandStorage[ccpMergeIndex0].Cr();
PelBuf srcCr1 = ccpCandStorage[ccpMergeIndex1].Cr();
ccpFusionStorage[ccpfusionIdx] = m_cccmStorage[0][MAX_CCP_CAND_LIST_SIZE + ccpfusionIdx].getBuf(localUnitArea); // Borrow the CCCM storage
PelBuf predCb = ccpFusionStorage[ccpfusionIdx].Cb();
PelBuf predCr = ccpFusionStorage[ccpfusionIdx].Cr();
for (int y = 0; y < areaCb.height; y++)
{
for (int x = 0; x < areaCb.width; x++)
{
predCb.at(x, y) = (srcCb0.at(x, y) + srcCb1.at(x, y) + 1) >> 1;
predCr.at(x, y) = (srcCr0.at(x, y) + srcCr1.at(x, y) + 1) >> 1;
}
}
m_pcRdCost->setDistParam(distParamSad, orgCb, predCb, pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cb, false);
m_pcRdCost->setDistParam(distParamSatd, orgCb, predCb, pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cb, true);
distParamSad.applyWeight = false;
distParamSatd.applyWeight = false;
sadCb = distParamSad.distFunc(distParamSad) * 2;
satdCb = distParamSatd.distFunc(distParamSatd);
sad += std::min(sadCb, satdCb);
m_pcRdCost->setDistParam(distParamSad, orgCr, predCr, pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cr, false);
m_pcRdCost->setDistParam(distParamSatd, orgCr, predCr, pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cr, true);
distParamSad.applyWeight = false;
distParamSatd.applyWeight = false;
sadCr = distParamSad.distFunc(distParamSad) * 2;
satdCr = distParamSatd.distFunc(distParamSatd);
sad += std::min(sadCr, satdCr);
m_CABACEstimator->resetBits();
m_CABACEstimator->nonLocalCCPIndex(pu);
uint64_t estbits = m_CABACEstimator->getEstFracBits();
double curCost = (double)sad + sqrtLambdaForFirstPass * (double)estbits;
orderedCCPFusioncost[ccpfusionIdx] = curCost;
orderedCCPFusionCand[ccpfusionIdx] = ccpfusionIdx;
int maxNumFusionModeIdxForComparison = std::min(numRDtestFusion, ccpfusionIdx);
for (int i = 0; i < maxNumFusionModeIdxForComparison; i++)
{
if (curCost < orderedCCPFusioncost[i])
{
for (int j = numRDtestFusionMinusOne; j > i; j--)
{
orderedCCPFusioncost[j] = orderedCCPFusioncost[j - 1];
orderedCCPFusionCand[j] = orderedCCPFusionCand[j - 1];
}
orderedCCPFusioncost[i] = curCost;
orderedCCPFusionCand[i] = ccpfusionIdx;
break;
}
}
}
m_numCcpMergefusionRdo = std::min(ccpfusionIdx, numRDtestFusion);
for (int i = 0; i < m_numCcpMergefusionRdo; i++)
{
m_ddccpMergeFusionCost[i] = orderedCCPFusioncost[i];
m_ddCcpMergeFusionModeIndex[i] = orderedCCPFusionCand[i];
PelBuf predCb = m_ddCcpFusionStorageTemp[i].Cb();
PelBuf predCr = m_ddCcpFusionStorageTemp[i].Cr();
predCb.copyFrom(ccpFusionStorage[m_ddCcpMergeFusionModeIndex[i]].Cb());
predCr.copyFrom(ccpFusionStorage[m_ddCcpMergeFusionModeIndex[i]].Cr());
}
m_skipDdCcpMergeFusionList = true;
pu.ddNonLocalCCPFusion = 0;
}
const int finalNumRDtestFusion = m_numCcpMergefusionRdo;
#endif
#if JVET_AG0059_CCP_MERGE_ENHANCEMENT
const int numRDtest = std::min(2, numPos) + fusionModeNum;
#else
Chia-Ming Tsai
committed
const int numRDtest = std::min(2, numPos);
#endif
Chia-Ming Tsai
committed
for (int rdIdx = 0; rdIdx < numRDtest; rdIdx++)
{
int chromaIntraMode = LM_CHROMA_IDX;
pu.cccmFlag = 0;
pu.cccmNoSubFlag = 0;
pu.glCccmFlag = 0;
int nonAdjCCCMCand = orderedCCPCand[rdIdx];
#if JVET_AG0059_CCP_MERGE_ENHANCEMENT
int nlCCPFusionMode = nonAdjCCCMCand / numPos;
int ccpMergeIdx = nonAdjCCCMCand - nlCCPFusionMode * numPos;
pu.idxNonLocalCCP = ccpMergeIdx + 1;
pu.ccpMergeFusionFlag = nlCCPFusionMode > 0;
pu.ccpMergeFusionType = nlCCPFusionMode > 1;
pu.curCand = candList[ccpMergeIdx];
#else
Chia-Ming Tsai
committed
pu.idxNonLocalCCP = nonAdjCCCMCand + 1;
pu.curCand = candList[nonAdjCCCMCand];
#endif
Chia-Ming Tsai
committed
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
// Original RD check code replicated from above
cs.setDecomp(pu.Cb(), false);
cs.dist = baseDist;
//----- restore context models -----
m_CABACEstimator->getCtx() = ctxStart;
//----- chroma coding -----
pu.intraDir[1] = chromaIntraMode;
#if JVET_AB0143_CCCM_TS
xRecurIntraChromaCodingQT(cs, partitioner, bestCostSoFar, ispType, ccpCandStorage[nonAdjCCCMCand]);
#else
xRecurIntraChromaCodingQT(cs, partitioner, bestCostSoFar, ispType);
#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
Chia-Ming Tsai
committed
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
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));
#if !JVET_AB0143_CCCM_TS
cs.picture->getRecoBuf(area).copyFrom(cs.getRecoBuf(area));
#endif
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;
#if JVET_Z0050_DIMD_CHROMA_FUSION
isChromaFusion = pu.isChromaFusion;
#endif
#if JVET_Z0050_CCLM_SLOPE
bestCclmOffsets = pu.cclmOffsets;
#endif
cccmModeBest = pu.cccmFlag;
#if JVET_AA0126_GLM
bestGlmIdc = pu.glmIdc;
#endif
#if JVET_AC0147_CCCM_NO_SUBSAMPLING
Chia-Ming Tsai
committed
cccmNoSubBest = pu.cccmNoSubFlag;
#endif
#if JVET_AC0054_GLCCCM
glCccmBest = pu.glCccmFlag;
#endif
#if JVET_AD0202_CCCM_MDF
cccmMultiFilterIdxBest = pu.cccmMultiFilterIdx;
#endif
#if JVET_AG0059_CCP_MERGE_ENHANCEMENT
bestCCInsideFilter = pu.ccInsideFilter;
bestCcpMergeFusionFlag = pu.ccpMergeFusionFlag;
bestCcpMergeFusionType = pu.ccpMergeFusionType;