Newer
Older
cu.sgpm = uiBestPUMode.sgpmFlag;
if (cu.sgpm)
{
CHECK(!bestSgpmMode, "mode not same");
#if JVET_AG0152_SGPM_ITMP_IBC
pu.intraDir[CHANNEL_TYPE_LUMA] = uiBestPUMode.sgpmMode0 >= SGPM_BV_START_IDX ? 0 : uiBestPUMode.sgpmMode0;
pu.intraDir1[CHANNEL_TYPE_LUMA] = uiBestPUMode.sgpmMode1 >= SGPM_BV_START_IDX ? 0 : uiBestPUMode.sgpmMode1;
#else
pu.intraDir[CHANNEL_TYPE_LUMA] = uiBestPUMode.sgpmMode0;
pu.intraDir1[CHANNEL_TYPE_LUMA] = uiBestPUMode.sgpmMode1;
cu.sgpmSplitDir = uiBestPUMode.sgpmSplitDir;
cu.sgpmMode0 = uiBestPUMode.sgpmMode0;
cu.sgpmMode1 = uiBestPUMode.sgpmMode1;
cu.sgpmIdx = uiBestPUMode.sgpmIdx;
#if JVET_AG0152_SGPM_ITMP_IBC
cu.sgpmBv0 = uiBestPUMode.sgpmBv0;
cu.sgpmBv1 = uiBestPUMode.sgpmBv1;
#endif
#if JVET_AB0157_TMRL
cu.tmrlFlag = uiBestPUMode.mRefId >= MAX_REF_LINE_IDX;
if(cu.tmrlFlag)
{
int tmrlListIdx = uiBestPUMode.mRefId - MAX_REF_LINE_IDX;
cu.tmrlListIdx = tmrlListIdx;
pu.multiRefIdx = m_tmrlList[tmrlListIdx].multiRefIdx;
pu.intraDir[0] = m_tmrlList[tmrlListIdx].intraDir;
#if JVET_AG0058_EIP
cu.eipFlag = (uiBestPUMode.modeId >= EIP_IDX) && (uiBestPUMode.modeId < EIP_IDX + std::max(NUM_DERIVED_EIP, MAX_MERGE_EIP));
if (cu.eipFlag)
{
cu.eipMerge = uiBestPUMode.mipTrFlg;
pu.intraDir[0] = uiBestPUMode.modeId - EIP_IDX;
cu.eipModel = cu.eipMerge ? m_eipMergeModel[pu.intraDir[0]] : m_eipModel[pu.intraDir[0]];
}
#endif
#if JVET_AC0115_INTRA_TMP_DIMD_MTS_LFNST
if (cu.tmpFlag)
{
cu.intraTmpDimdMode = intraTmpDimdMode;
}
#endif
#if JVET_AC0105_DIRECTIONAL_PLANAR
cu.plIdx = bestPlMode;
if (cu.plIdx)
{
CHECK(pu.multiRefIdx > 0, "use of PL");
CHECK(cu.mipFlag, "use of PL");
CHECK(cu.dimd, "use of PL");
CHECK(cu.tmpFlag, "use of PL");
CHECK(cu.tmrlFlag, "use of PL");
CHECK(cu.sgpm, "use of PL");
CHECK(cu.timd, "use of PL");
}
#endif
if (cu.colorTransform)
{
CHECK(pu.intraDir[CHANNEL_TYPE_CHROMA] != DM_CHROMA_IDX, "chroma should use DM mode for adaptive color transform");
}

Karsten Suehring
committed
}
//===== reset context models =====
m_CABACEstimator->getCtx() = ctxStart;
return validReturn;

Karsten Suehring
committed
}
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
#if JVET_AD0120_LBCCP
void IntraSearch::fillLmPredFiltList(PredictionUnit pu, const PelUnitBuf& lmPredFilt, int &lmPredFiltIdx, std::vector<lmPredFiltModeInfo> &miLmPredFiltList)
{
const TempCtx ctxStart(m_ctxCache, m_CABACEstimator->getCtx());
const double sqrtLambdaForFirstPass = m_pcRdCost->getMotionLambda() * FRAC_BITS_SCALE;
int64_t sad = 0, sadCb = 0, satdCb = 0, sadCr = 0, satdCr = 0;
CodingStructure &cs = *(pu.cs);
DistParam distParamSadCb, distParamSatdCb;
DistParam distParamSadCr, distParamSatdCr;
m_pcRdCost->setDistParam(distParamSadCb, cs.getOrgBuf(pu.Cb()), lmPredFilt.Cb(), pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cb, false);
m_pcRdCost->setDistParam(distParamSatdCb, cs.getOrgBuf(pu.Cb()), lmPredFilt.Cb(), pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cb, true);
m_pcRdCost->setDistParam(distParamSadCr, cs.getOrgBuf(pu.Cr()), lmPredFilt.Cr(), pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cr, false);
m_pcRdCost->setDistParam(distParamSatdCr, cs.getOrgBuf(pu.Cr()), lmPredFilt.Cr(), pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cr, true);
distParamSadCb.applyWeight = false;
distParamSatdCb.applyWeight = false;
distParamSadCr.applyWeight = false;
distParamSatdCr.applyWeight = false;
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);
m_CABACEstimator->getCtx() = ctxStart;
uint64_t fracModeBits = xFracModeBitsIntra(pu, MMLM_CHROMA_IDX, CHANNEL_TYPE_CHROMA);
double cost = (double) sad + (double) fracModeBits * sqrtLambdaForFirstPass;
int cccmFlag = 0, cccmNoSubFlag = 0, glCccmFlag = 0, cccmMultiFilterIdx = 0;
#if JVET_AA0057_CCCM
cccmFlag = pu.cccmFlag;
#endif
#if JVET_AC0147_CCCM_NO_SUBSAMPLING
cccmNoSubFlag = pu.cccmNoSubFlag;
#endif
#if JVET_AC0054_GLCCCM
glCccmFlag = pu.glCccmFlag;
#endif
#if JVET_AD0202_CCCM_MDF
cccmMultiFilterIdx = pu.cccmMultiFilterIdx;
#endif
miLmPredFiltList.push_back({ lmPredFiltIdx, cccmFlag, cccmNoSubFlag, glCccmFlag, cccmMultiFilterIdx, cost });
lmPredFiltIdx++;
}
#endif
void IntraSearch::estIntraPredChromaQT( CodingUnit &cu, Partitioner &partitioner, const double maxCostAllowed
#if JVET_AD0208_IBC_ADAPT_FOR_CAM_CAPTURED_CONTENTS
, InterPrediction* pcInterPred
#endif
)

Karsten Suehring
committed
{
const ChromaFormat format = cu.chromaFormat;
const uint32_t numberValidComponents = getNumberValidComponents(format);
CodingStructure &cs = *cu.cs;
const TempCtx ctxStart ( m_ctxCache, m_CABACEstimator->getCtx() );

Karsten Suehring
committed
cs.setDecomp( cs.area.Cb(), false );
double bestCostSoFar = maxCostAllowed;
bool lumaUsesISP = !cu.isSepTree() && cu.ispMode;
#else
bool lumaUsesISP = !CS::isDualITree(*cu.cs) && cu.ispMode;
#endif
PartSplit ispType = lumaUsesISP ? CU::getISPType( cu, COMPONENT_Y ) : TU_NO_ISP;
CHECK( cu.ispMode && bestCostSoFar < 0, "bestCostSoFar must be positive!" );
#if JVET_AF0066_ENABLE_DBV_4_SINGLE_TREE
bool singleTreeLumaIntraTmp = !CS::isDualITree(*cu.cs) && cu.tmpFlag;
#endif
#if JVET_AD0120_LBCCP
int bestCCInsideFilter = 0;
#endif

Karsten Suehring
committed
auto &pu = *cu.firstPU;
{
uint32_t uiBestMode = 0;
Distortion uiBestDist = 0;
double dBestCost = MAX_DOUBLE;
#if JVET_AG0154_DECODER_DERIVED_CCP_FUSION
Distortion bestDist = ULLONG_MAX;
int decoderDerivedCcpModeBest = 0;
int bestDdNonLocalMergeFusion = 0;
#endif
#if JVET_AC0147_CCCM_NO_SUBSAMPLING
int cccmNoSubBest = 0;
#endif
#if JVET_AC0054_GLCCCM
int glCccmBest = 0;
#endif
#if JVET_AE0100_BVGCCCM
int bvgCccmBest = 0;
#endif
#if JVET_AD0202_CCCM_MDF
int cccmMultiFilterIdxBest = 0;
#endif
#if JVET_Z0050_CCLM_SLOPE
CclmOffsets bestCclmOffsets = {};
CclmOffsets satdCclmOffsetsBest[NUM_CHROMA_MODE];
int64_t satdCclmCosts [NUM_CHROMA_MODE] = { 0 };
#endif
#if JVET_AA0126_GLM
GlmIdc bestGlmIdc = {};
GlmIdc satdGlmIdcBest [NUM_CHROMA_MODE];
int64_t satdGlmCosts [NUM_CHROMA_MODE] = { 0 };
#endif
#if JVET_AC0119_LM_CHROMA_FUSION
uint8_t isChromaFusion = 0;
#else
Chia-Ming Tsai
committed
#endif
#if JVET_AD0188_CCP_MERGE
int bestNonAdjCCCM = 0;
CCPModelCandidate ccpModelBest;

Karsten Suehring
committed
//----- init mode list ----
{
int32_t uiMinMode = 0;
int32_t uiMaxMode = NUM_CHROMA_MODE;

Karsten Suehring
committed
//----- check chroma modes -----
uint32_t chromaCandModes[ NUM_CHROMA_MODE ];
PU::getIntraChromaCandModes( pu, chromaCandModes );
#if JVET_Z0050_DIMD_CHROMA_FUSION && ENABLE_DIMD
#if JVET_AC0094_REF_SAMPLES_OPT
if (!CS::isDualITree(*cu.cs))
{
const CompArea areaCb = pu.Cb();
const CompArea areaCr = pu.Cr();
const CompArea lumaArea = CompArea(COMPONENT_Y, pu.chromaFormat, areaCb.lumaPos(), recalcSize(pu.chromaFormat, CHANNEL_TYPE_CHROMA, CHANNEL_TYPE_LUMA, areaCb.size()));//needed for correct pos/size (4x4 Tus)
IntraPrediction::deriveDimdChromaMode(cs.picture->getRecoBuf(lumaArea), cs.picture->getRecoBuf(areaCb), cs.picture->getRecoBuf(areaCr), lumaArea, areaCb, areaCr, *pu.cu);
}
if (PU::getCoLocatedIntraLumaMode(*cu.firstPU) == cu.dimdChromaMode)
{
if (cu.dimdChromaMode == cu.dimdChromaModeSecond)
{
cu.dimdChromaMode = DC_IDX;
}
else
{
cu.dimdChromaMode = cu.dimdChromaModeSecond;
}
}
#else
// derive DIMD chroma mode
CompArea areaCb = pu.Cb();
CompArea areaCr = pu.Cr();
CompArea lumaArea = CompArea(COMPONENT_Y, pu.chromaFormat, areaCb.lumaPos(), recalcSize(pu.chromaFormat, CHANNEL_TYPE_CHROMA, CHANNEL_TYPE_LUMA, areaCb.size()));//needed for correct pos/size (4x4 Tus)
IntraPrediction::deriveDimdChromaMode(cs.picture->getRecoBuf(lumaArea), cs.picture->getRecoBuf(areaCb), cs.picture->getRecoBuf(areaCr), lumaArea, areaCb, areaCr, *pu.cu);
#endif
#if JVET_AC0071_DBV
if (PU::hasChromaBvFlag(pu))
{
PU::deriveChromaBv(pu);
}
else
{
uiMaxMode--;
}
#endif

Karsten Suehring
committed
// create a temporary CS
CodingStructure &saveCS = *m_pSaveCS[0];
saveCS.pcv = cs.pcv;
saveCS.picture = cs.picture;
#if JVET_Z0118_GDR
saveCS.m_pt = cs.m_pt;
#endif

Karsten Suehring
committed
saveCS.area.repositionTo( cs.area );
saveCS.clearTUs();
if( !cu.isSepTree() && cu.ispMode )
#else
if (!CS::isDualITree(cs) && cu.ispMode)
#endif
{
saveCS.clearCUs();
saveCS.clearPUs();
}

Karsten Suehring
committed
{
if( partitioner.canSplit( TU_MAX_TR_SPLIT, cs ) )
{
partitioner.splitCurrArea( TU_MAX_TR_SPLIT, cs );
do
{
cs.addTU( CS::getArea( cs, partitioner.currArea(), partitioner.chType ), partitioner.chType ).depth = partitioner.currTrDepth;
} while( partitioner.nextPart( cs ) );
partitioner.exitCurrSplit();
}
else
cs.addTU( CS::getArea( cs, partitioner.currArea(), partitioner.chType ), partitioner.chType );
}
std::vector<TransformUnit*> orgTUs;
if( lumaUsesISP )
{
CodingUnit& auxCU = saveCS.addCU( cu, partitioner.chType );
auxCU.ispMode = cu.ispMode;
saveCS.sps = cu.cs->sps;
saveCS.addPU( *cu.firstPU, partitioner.chType );
}

Karsten Suehring
committed
// create a store for the TUs
for( const auto &ptu : cs.tus )
{
// for split TUs in HEVC, add the TUs without Chroma parts for correct setting of Cbfs
if( lumaUsesISP || pu.contains( *ptu, CHANNEL_TYPE_CHROMA ) )

Karsten Suehring
committed
{
saveCS.addTU( *ptu, partitioner.chType );
orgTUs.push_back( ptu );
}
}
if( lumaUsesISP )
{
saveCS.clearCUs();
}
// SATD pre-selecting.
int satdModeList[NUM_CHROMA_MODE];
int64_t satdSortedCost[NUM_CHROMA_MODE];
for (int i = 0; i < NUM_CHROMA_MODE; i++)
{
satdSortedCost[i] = 0; // for the mode not pre-select by SATD, do RDO by default, so set the initial value 0.
satdModeList[i] = 0;
}
#if JVET_Z0050_DIMD_CHROMA_FUSION && ENABLE_DIMD
#if JVET_AC0071_DBV
bool modeIsEnable[NUM_INTRA_MODE + 3]; // use intra mode idx to check whether enable
for (int i = 0; i < NUM_INTRA_MODE + 3; i++)
{
modeIsEnable[i] = 1;
}
#else
bool modeIsEnable[NUM_INTRA_MODE + 2]; // use intra mode idx to check whether enable
for (int i = 0; i < NUM_INTRA_MODE + 2; i++)
{
modeIsEnable[i] = 1;
}
#endif
#else
#if JVET_AC0071_DBV
bool modeIsEnable[NUM_INTRA_MODE + 2]; // use intra mode idx to check whether enable
for (int i = 0; i < NUM_INTRA_MODE + 2; i++)
{
modeIsEnable[i] = 1;
}
#else
bool modeIsEnable[NUM_INTRA_MODE + 1]; // use intra mode idx to check whether enable
for (int i = 0; i < NUM_INTRA_MODE + 1; i++)
{
modeIsEnable[i] = 1;
}
DistParam distParamSad;
DistParam distParamSatd;
pu.intraDir[1] = MDLM_L_IDX; // temporary assigned, just to indicate this is a MDLM mode. for luma down-sampling operation.
initIntraPatternChType(cu, pu.Cb());
initIntraPatternChType(cu, pu.Cr());
xGetLumaRecPixels(pu, pu.Cb());
#if JVET_AA0126_GLM
if ( PU::isLMCModeEnabled( pu, LM_CHROMA_IDX ) && PU::hasGlmFlag( pu, LM_CHROMA_IDX ) )
{
#if JVET_AB0092_GLM_WITH_LUMA && JVET_AB0174_CCCM_DIV_FREE
xGlmSetLumaRefValue(pu, pu.Cb());
#endif
// Generate all GLM templates at encoder
xGetLumaRecPixelsGlmAll(pu, pu.Cb());
pu.intraDir[1] = LM_CHROMA_IDX;
xGetLumaRecPixels(pu, pu.Cb());
for ( int mode = LM_CHROMA_IDX; mode <= MMLM_T_IDX; mode++ )
{
satdGlmIdcBest[mode - LM_CHROMA_IDX].setAllZero();
#if JVET_AB0092_GLM_WITH_LUMA
CodedCUInfo& relatedCU = ((EncModeCtrlMTnoRQT *)m_modeCtrl)->getBlkInfo(partitioner.currArea());
if (PU::hasGlmFlag(pu, mode) && !relatedCU.skipGLM)
#else
for ( int comp = COMPONENT_Cb; comp <= COMPONENT_Cr; comp++ )
{
ComponentID compID = ComponentID( comp );
int idcBest = 0;
int64_t satdBest = 0;
GlmIdc& idcsBest = satdGlmIdcBest[mode - LM_CHROMA_IDX];
pu.intraDir[1] = mode;
pu.glmIdc.setAllZero();
xFindBestGlmIdcSATD(pu, compID, idcBest, satdBest );
idcsBest.setIdc(compID, 0, idcBest);
idcsBest.setIdc(compID, 1, idcBest);
#if JVET_AB0092_GLM_WITH_LUMA
idcsBest.setIdc(COMPONENT_Cr, 0, idcBest);
idcsBest.setIdc(COMPONENT_Cr, 1, idcBest);
#endif
satdGlmCosts[mode - LM_CHROMA_IDX] += satdBest; // Summing up Cb and Cr cost
}
if ( !satdGlmIdcBest[0].isActive() )
{
break;
}
}
}
}
pu.glmIdc.setAllZero();
#endif
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
#if JVET_Z0050_CCLM_SLOPE
if ( PU::isLMCModeEnabled( pu, LM_CHROMA_IDX ) && PU::hasCclmDeltaFlag( pu, LM_CHROMA_IDX ) )
{
// Fill luma reference buffer for the two-sided CCLM
pu.intraDir[1] = LM_CHROMA_IDX;
xGetLumaRecPixels(pu, pu.Cb());
for ( int mode = LM_CHROMA_IDX; mode <= MDLM_T_IDX; mode++ )
{
satdCclmOffsetsBest[mode - LM_CHROMA_IDX].setAllZero();
if ( PU::hasCclmDeltaFlag( pu, mode ) )
{
for ( int comp = COMPONENT_Cb; comp <= COMPONENT_Cr; comp++ )
{
ComponentID compID = ComponentID( comp );
int deltaBest = 0;
int64_t satdBest = 0;
CclmOffsets& offsetsBest = satdCclmOffsetsBest[mode - LM_CHROMA_IDX];
pu.intraDir[1] = mode;
pu.cclmOffsets.setAllZero();
xFindBestCclmDeltaSlopeSATD(pu, compID, 0, deltaBest, satdBest );
offsetsBest.setOffset(compID, 0, deltaBest);
#if MMLM
if ( PU::isMultiModeLM( mode ) )
{
// Set best found values for the first model to get a matching second model
pu.cclmOffsets.setOffsets(offsetsBest.cb0, offsetsBest.cr0, 0, 0);
xFindBestCclmDeltaSlopeSATD(pu, compID, 1, deltaBest, satdBest );
offsetsBest.setOffset(compID, 1, deltaBest);
}
#endif
satdCclmCosts[mode - LM_CHROMA_IDX] += satdBest; // Summing up Cb and Cr cost
}
}
}
}
pu.cclmOffsets.setAllZero();
#endif
#if JVET_AD0120_LBCCP && MMLM
std::vector<lmPredFiltModeInfo> miLmPredFiltList;
miLmPredFiltList.clear();
#if JVET_AD0188_CCP_MERGE
CCPModelCandidate ccpCandlmPredFilt[LBCCP_FILTER_MMLMNUM];
#endif
PelUnitBuf lmPredFilterStorage[LBCCP_FILTER_MMLMNUM];
const UnitArea tmpUnitArea(pu.chromaFormat, Area(0, 0, (pu.Cb().width) << getChannelTypeScaleX(CHANNEL_TYPE_CHROMA, pu.chromaFormat), (pu.Cb().height) << getChannelTypeScaleY(CHANNEL_TYPE_CHROMA, pu.chromaFormat)));
for (uint32_t i = 0; i < LBCCP_FILTER_MMLMNUM; i++)
{
lmPredFilterStorage[i] = m_lmPredFiltStorage[i].getBuf(tmpUnitArea);
#if JVET_AD0188_CCP_MERGE
ccpCandlmPredFilt[i] = {};
#endif
}
int lmPredFiltIdx = 0;
#endif
for (int idx = uiMinMode; idx <= uiMaxMode - 1; idx++)
{
int mode = chromaCandModes[idx];
satdModeList[idx] = mode;
if (PU::isLMCMode(mode) && !PU::isLMCModeEnabled(pu, mode))
{
continue;
}
if ((mode == LM_CHROMA_IDX) || (mode == PLANAR_IDX) || (mode == DM_CHROMA_IDX)
#if JVET_Z0050_DIMD_CHROMA_FUSION && ENABLE_DIMD
|| (mode == DIMD_CHROMA_IDX)
#endif
#if JVET_AC0071_DBV
|| (mode == DBV_CHROMA_IDX)
#endif
) // only pre-check regular modes and MDLM modes, not including DM, DIMD, Planar, and LM
{
continue;
}
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;
#if JVET_AD0120_LBCCP && JVET_AD0188_CCP_MERGE
pu.curCand = {};
#endif
CompArea areaCb = pu.Cb();
PelBuf orgCb = cs.getOrgBuf(areaCb);
PelBuf predCb = cs.getPredBuf(areaCb);
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 (PU::isLMCMode(mode))
{
predIntraChromaLM(COMPONENT_Cb, predCb, pu, areaCb, mode);
}
else
{
Alexey Filippov
committed
initPredIntraParams(pu, pu.Cb(), *pu.cs->sps);
predIntraAng(COMPONENT_Cb, predCb, pu);
sadCb = distParamSad.distFunc(distParamSad) * 2;
satdCb = distParamSatd.distFunc(distParamSatd);
sad += std::min(sadCb, satdCb);
CompArea areaCr = pu.Cr();
PelBuf orgCr = cs.getOrgBuf(areaCr);
PelBuf predCr = cs.getPredBuf(areaCr);
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;
if (PU::isLMCMode(mode))
{
predIntraChromaLM(COMPONENT_Cr, predCr, pu, areaCr, mode);
}
else
{
Alexey Filippov
committed
initPredIntraParams(pu, pu.Cr(), *pu.cs->sps);
predIntraAng(COMPONENT_Cr, predCr, pu);
sadCr = distParamSad.distFunc(distParamSad) * 2;
satdCr = distParamSatd.distFunc(distParamSatd);
sad += std::min(sadCr, satdCr);
#if JVET_AD0120_LBCCP && MMLM
if(mode == MMLM_CHROMA_IDX)
{
lmPredFilterStorage[lmPredFiltIdx].Cb().copyFrom(predCb);
lmPredFilterStorage[lmPredFiltIdx].Cr().copyFrom(predCr);
#if JVET_AD0188_CCP_MERGE
ccpCandlmPredFilt[lmPredFiltIdx] = pu.curCand;
#endif
}
#endif
#if JVET_AB0143_CCCM_TS
#if MMLM
#if JVET_AC0054_GLCCCM
uint32_t chromaCandCccmModes[CCCM_NUM_MODES] = { LM_CHROMA_IDX, MDLM_L_IDX, MDLM_T_IDX, MMLM_CHROMA_IDX, MMLM_L_IDX, MMLM_T_IDX
, LM_CHROMA_IDX, MDLM_L_IDX, MDLM_T_IDX, MMLM_CHROMA_IDX, MMLM_L_IDX, MMLM_T_IDX };
#else
uint32_t chromaCandCccmModes[CCCM_NUM_MODES] = { LM_CHROMA_IDX, MDLM_L_IDX, MDLM_T_IDX, MMLM_CHROMA_IDX, MMLM_L_IDX, MMLM_T_IDX };
#endif
#else
#if JVET_AC0054_GLCCCM
uint32_t chromaCandCccmModes[CCCM_NUM_MODES] = { LM_CHROMA_IDX, MDLM_L_IDX, MDLM_T_IDX
, LM_CHROMA_IDX, MDLM_L_IDX, MDLM_T_IDX };
uint32_t chromaCandCccmModes[CCCM_NUM_MODES] = { LM_CHROMA_IDX, MDLM_L_IDX, MDLM_T_IDX };
#if JVET_AD0202_CCCM_MDF
int satdCccmFilterIndex[TOTAL_NUM_CCCM_MODES];
#if JVET_AC0054_GLCCCM
int satdCccmFlagList[TOTAL_NUM_CCCM_MODES];
#endif
#else
#if JVET_AC0054_GLCCCM
int satdCccmFlagList[CCCM_NUM_MODES];
#endif
#if JVET_AC0147_CCCM_NO_SUBSAMPLING
#if JVET_AD0202_CCCM_MDF
int64_t satdCccmSortedCost[2][TOTAL_NUM_CCCM_MODES];
int satdCccmModeList[2][TOTAL_NUM_CCCM_MODES];
for (int i = 0; i < CCCM_NUM_PRED_FILTER; i++)
{
int startIdx = i * CCCM_NUM_MODES;
for (int j = 0; j < CCCM_NUM_MODES; j++)
{
int currCccmModeIdx = startIdx + j;
satdCccmSortedCost[0][currCccmModeIdx] = LLONG_MAX; // for the mode not pre-select by SATD, do RDO by default, so set the initial value 0.
satdCccmSortedCost[1][currCccmModeIdx] = LLONG_MAX; // for the mode not pre-select by SATD, do RDO by default, so set the initial value 0.
satdCccmModeList[0][currCccmModeIdx] = chromaCandCccmModes[j];
satdCccmModeList[1][currCccmModeIdx] = chromaCandCccmModes[j];
#if JVET_AC0054_GLCCCM
satdCccmFlagList[currCccmModeIdx] = j < (CCCM_NUM_MODES / 2) ? 1 : 2; // 1: cccm, 2: glCccm
#endif
satdCccmFilterIndex[currCccmModeIdx] = i;
}
}
#else
int64_t satdCccmSortedCost[2][CCCM_NUM_MODES];
int satdCccmModeList[2][CCCM_NUM_MODES];
for (int i = 0; i < CCCM_NUM_MODES; i++)
{
satdCccmSortedCost[0][i] = LLONG_MAX; // for the mode not pre-select by SATD, do RDO by default, so set the initial value 0.
satdCccmSortedCost[1][i] = LLONG_MAX; // for the mode not pre-select by SATD, do RDO by default, so set the initial value 0.
satdCccmModeList[0][i] = chromaCandCccmModes[i];
satdCccmModeList[1][i] = chromaCandCccmModes[i];
#if JVET_AC0054_GLCCCM
satdCccmFlagList[i] = i < (CCCM_NUM_MODES / 2) ? 1 : 2; // 1: cccm, 2: glCccm
#endif
int64_t bestCccmCost[2] = { LLONG_MAX, 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
#if JVET_AD0202_CCCM_MDF
bool isMultiCccmFullEnabled2 = PU::isMultiCccmWithMdf(pu, MMLM_CHROMA_IDX);
bool isMultiCccmLeftEnabled2 = PU::isMultiCccmWithMdf(pu, MMLM_L_IDX);
bool isMultiCccmTopEnabled2 = PU::isMultiCccmWithMdf(pu, MMLM_T_IDX);
#endif
const UnitArea localUnitArea(cs.area.chromaFormat, Area(0, 0, (pu.Cb().width) << 1, (pu.Cb().height) << 1));
#if JVET_AD0202_CCCM_MDF
PelUnitBuf cccmStorage[2][TOTAL_NUM_CCCM_MODES];
#else
PelUnitBuf cccmStorage[2][CCCM_NUM_MODES];
pu.cccmFlag = 1;
#if JVET_AD0202_CCCM_MDF
pu.cccmNoSubFlag = 1;
xGetLumaRecPixels(pu, pu.Cb());
pu.cccmNoSubFlag = 0;
xGetLumaRecPixels(pu, pu.Cb());
xGetLumaRecPixels(pu, pu.Cb(), 1);
xGetLumaRecPixels(pu, pu.Cb(), 2);
xGetLumaRecPixels(pu, pu.Cb(), 3);
#endif
for (int sub = 0; sub < pu.cu->slice->getSPS()->getUseCccm(); sub++)
{
pu.cccmNoSubFlag = sub;
#if !JVET_AD0202_CCCM_MDF
xGetLumaRecPixels(pu, pu.Cb());
bool isCCCMEnabled = false;
for (int idx = 0; idx < CCCM_NUM_MODES; idx++)
{
#if JVET_AC0054_GLCCCM
if (sub && idx >= CCCM_NUM_MODES / 2)
{
continue;
}
#endif
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
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
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
#if JVET_AC0054_GLCCCM
if (idx < CCCM_NUM_MODES / 2)
{
pu.glCccmFlag = 0;
}
else
{
pu.glCccmFlag = 1;
#if MMLM
isCCCMEnabled = idx == 6 ? isCccmFullEnabled
: idx == 7 ? isCccmLeftEnabled
: idx == 8 ? isCccmTopEnabled
: idx == 9 ? isMultiCccmFullEnabled
: idx == 10 ? isMultiCccmLeftEnabled : isMultiCccmTopEnabled;
pu.cccmFlag = idx == 6 ? 1
: idx == 7 ? 2
: idx == 8 ? 3
: idx == 9 ? 1
: idx == 10 ? 2 : 3;
#else
isCCCMEnabled = idx == 3 ? isCccmFullEnabled
: idx == 4 ? isCccmLeftEnabled : isCccmTopEnabled;
pu.cccmFlag = idx == 3 ? 1
: idx == 4 ? 2 : 3;
#endif
#if JVET_AD0202_CCCM_MDF
if (isCCCMEnabled)
{
if (m_skipCCCMwithMdfSATD)
{
if (m_isCccmWithMdfEnabledInRdo[4][mode] == 0)
{
continue;
}
}
}
#endif
if (isCCCMEnabled)
{
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
#if JVET_AD0202_CCCM_MDF
for (int32_t filterIdx = 0; filterIdx < CCCM_NUM_PRED_FILTER; filterIdx++)
{
if (filterIdx > 0)
{
if (sub == 1 || idx > 5)
{
continue;
}
if (m_skipCCCMwithMdfSATD)
{
if (m_isCccmWithMdfEnabledInRdo[filterIdx][mode] == 0)
{
continue;
}
}
if (mode == MMLM_CHROMA_IDX && !isMultiCccmFullEnabled2)
{
continue;
}
else if (mode == MMLM_L_IDX && !isMultiCccmLeftEnabled2)
{
continue;
}
else if (mode == MMLM_T_IDX && !isMultiCccmTopEnabled2)
{
continue;
}
}
else if (sub == 0 && idx <= 5)
{
if (m_skipCCCMwithMdfSATD)
{
if (m_isCccmWithMdfEnabledInRdo[filterIdx][mode] == 0)
{
continue;
}
}
}
pu.cccmMultiFilterIdx = filterIdx;
#endif
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
pu.intraDir[1] = mode; // temporary assigned, for SATD checking.
if ( ( sub == 1 ) && m_skipCCCMSATD )
{
if (m_isCccmNoSubModeEnabledInRdo[mode] == 0)
{
continue;
}
}
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;
#if JVET_AD0202_CCCM_MDF
const int cccmBufferIdx = filterIdx * CCCM_NUM_MODES + idx;
cccmStorage[sub][cccmBufferIdx] = m_cccmStorage[sub][cccmBufferIdx].getBuf(localUnitArea);
#else
cccmStorage[sub][idx] = m_cccmStorage[sub][idx].getBuf(localUnitArea);
CompArea areaCb = pu.Cb();
PelBuf orgCb = cs.getOrgBuf(areaCb);
CompArea areaCr = pu.Cr();
PelBuf orgCr = cs.getOrgBuf(areaCr);
#if JVET_AD0202_CCCM_MDF
m_pcRdCost->setDistParam(distParamSadCb, orgCb, cccmStorage[sub][cccmBufferIdx].Cb(), pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cb, false);
m_pcRdCost->setDistParam(distParamSatdCb, orgCb, cccmStorage[sub][cccmBufferIdx].Cb(), pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cb, true);
#else
m_pcRdCost->setDistParam(distParamSadCb, orgCb, cccmStorage[sub][idx].Cb(), pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cb, false);
m_pcRdCost->setDistParam(distParamSatdCb, orgCb, cccmStorage[sub][idx].Cb(), pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cb, true);
distParamSadCb.applyWeight = false;
distParamSatdCb.applyWeight = false;
#if JVET_AD0202_CCCM_MDF
m_pcRdCost->setDistParam(distParamSadCr, orgCr, cccmStorage[sub][cccmBufferIdx].Cr(), pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cr, false);
m_pcRdCost->setDistParam(distParamSatdCr, orgCr, cccmStorage[sub][cccmBufferIdx].Cr(), pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cr, true);
#else
m_pcRdCost->setDistParam(distParamSadCr, orgCr, cccmStorage[sub][idx].Cr(), pu.cs->sps->getBitDepth(CHANNEL_TYPE_CHROMA), COMPONENT_Cr, false);
m_pcRdCost->setDistParam(distParamSatdCr, orgCr, cccmStorage[sub][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
#if JVET_AD0202_CCCM_MDF
predIntraCCCM(pu, cccmStorage[sub][cccmBufferIdx].Cb(), cccmStorage[sub][cccmBufferIdx].Cr(), mode);
#else
predIntraCCCM(pu, cccmStorage[sub][idx].Cb(), cccmStorage[sub][idx].Cr(), mode);
Chia-Ming Tsai
committed
#if JVET_AD0188_CCP_MERGE
#if JVET_AD0202_CCCM_MDF
m_ccmParamsStorage[sub][cccmBufferIdx] = pu.curCand;
#else
m_ccmParamsStorage[sub][idx] = pu.curCand;
#endif
#endif
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);
#if JVET_AD0202_CCCM_MDF
satdCccmSortedCost[sub][cccmBufferIdx] = sad;
#else
satdCccmSortedCost[sub][idx] = sad;
if (sad < bestCccmCost[sub])
{
bestCccmCost[sub] = sad;
}
#if JVET_AD0202_CCCM_MDF
}
#endif
#if JVET_AC0054_GLCCCM
int tempGlCccmFlag = 0;
#endif
int tempCccmIdx = 0;
int64_t tempCccmCost = 0;
#if JVET_AC0054_GLCCCM
#if JVET_AD0202_CCCM_MDF
for (int i = 1; i < 7; i++)
#else
for (int i = 1; i < CCCM_NUM_MODES; i++)
#if MMLM
for (int i = 1; i < 4; i++)
#else
for (int i = 1; i < 3; i++)
#if JVET_AD0202_CCCM_MDF
for (int j = i + 1; j < VALID_NUM_CCCM_MODES; j++)
#else
for (int j = i + 1; j < CCCM_NUM_MODES; j++)
{
if (satdCccmSortedCost[0][j] < satdCccmSortedCost[0][i])
{
tempCccmIdx = satdCccmModeList[0][i];
satdCccmModeList[0][i] = satdCccmModeList[0][j];
satdCccmModeList[0][j] = tempCccmIdx;
tempCccmCost = satdCccmSortedCost[0][i];
satdCccmSortedCost[0][i] = satdCccmSortedCost[0][j];
satdCccmSortedCost[0][j] = tempCccmCost;
#if JVET_AC0054_GLCCCM
tempGlCccmFlag = satdCccmFlagList[i];
satdCccmFlagList[i] = satdCccmFlagList[j];
satdCccmFlagList[j] = tempGlCccmFlag;
#endif
#if JVET_AD0202_CCCM_MDF
tempCccmIdx = satdCccmFilterIndex[i];
satdCccmFilterIndex[i] = satdCccmFilterIndex[j];
satdCccmFilterIndex[j] = tempCccmIdx;
}
}
}
#if MMLM
bool isCccmModeEnabledInRdo[2][MMLM_T_IDX + 1] = { false };
#if !JVET_AD0202_CCCM_MDF
isCccmModeEnabledInRdo[0][satdCccmModeList[0][0]] = true;
#if JVET_AC0054_GLCCCM
bool isGlCccmModeEnabledInRdo[MMLM_T_IDX + 1] = { false };
#if !JVET_AD0202_CCCM_MDF
if (satdCccmFlagList[0] == 2)
{
isCccmModeEnabledInRdo[0][satdCccmModeList[0][0]] = false;
isGlCccmModeEnabledInRdo[satdCccmModeList[0][0]] = true;
}
#endif
#endif
#if JVET_AD0202_CCCM_MDF
bool isCccmWithMulDownSamplingEnabledInRdo[MMLM_T_IDX + 1][CCCM_NUM_PRED_FILTER] = { false };
isCccmWithMulDownSamplingEnabledInRdo[satdCccmModeList[0][0]][satdCccmFilterIndex[0]] = true;
for (int i = 1; i < 7; i++)
#else
for (int i = 1; i < 4; i++)
#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;