Newer
Older
continue;
}
#endif
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
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
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
#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
}
#endif
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
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
3124
if (isCCCMEnabled)
{
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;
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);
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;
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;
predIntraCCCM(pu, cccmStorage[sub][idx].Cb(), cccmStorage[sub][idx].Cr(), mode);
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[sub][idx] = sad;
if (sad < bestCccmCost[sub])
{
bestCccmCost[sub] = sad;
}
}
}
}
#if JVET_AC0054_GLCCCM
int tempGlCccmFlag = 0;
#endif
int tempCccmIdx = 0;
int64_t tempCccmCost = 0;
#if JVET_AC0054_GLCCCM
for (int i = 1; i < CCCM_NUM_MODES; i++)
#else
#if MMLM
for (int i = 1; i < 4; i++)
#else
for (int i = 1; i < 3; i++)
#endif
{
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 MMLM
bool isCccmModeEnabledInRdo[2][MMLM_T_IDX + 1] = { false };
isCccmModeEnabledInRdo[0][satdCccmModeList[0][0]] = true;
#if JVET_AC0054_GLCCCM
bool isGlCccmModeEnabledInRdo[MMLM_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 < 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
{
isCccmModeEnabledInRdo[0][satdCccmModeList[0][i]] = true;
}
#else
isCccmModeEnabledInRdo[0][satdCccmModeList[0][i]] = true;
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
}
if (pu.cu->slice->getSPS()->getUseCccm() == 2)
{
if (bestCccmCost[1] < bestCccmCost[0])
{
#if MMLM
for (int i = 0; i < 4; i++)
#else
for (int i = 0; i < 3; i++)
#endif
{
if (isCccmModeEnabledInRdo[0][satdCccmModeList[0][i]] && (satdCccmSortedCost[0][i] >= 1.2 * bestCccmCost[1]))
{
isCccmModeEnabledInRdo[0][satdCccmModeList[0][i]] = false;
}
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_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 (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
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++)
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
{
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;
predIntraCCCM(pu, cccmStorage[idx].Cb(), cccmStorage[idx].Cr(), mode);
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
{
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
{
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
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
// 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 (satdSortedCost[uiMaxMode - 1 - reducedModeNumber] > bestCccmCost[0] && satdCccmFlagList[uiMaxMode - 1 - reducedModeNumber] != 2)
#else
if (satdSortedCost[uiMaxMode - 1 - reducedModeNumber] > bestCccmCost[0])
{
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 ((satdCccmSortedCost[0][i] > satdSortedCost[uiMaxMode - 1 - reducedModeNumber]) && (isCccmModeEnabledInRdo[0][satdCccmModeList[0][i]]) && satdCccmFlagList[uiMaxMode - 1 - reducedModeNumber] != 2)
#else
if ((satdCccmSortedCost[0][i] > satdSortedCost[uiMaxMode - 1 - reducedModeNumber]) && (isCccmModeEnabledInRdo[0][satdCccmModeList[0][i]]))
{
isCccmModeEnabledInRdo[0][satdCccmModeList[0][i]] = false;
break;
}
}
}
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
#endif
#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);
}
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( 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;

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
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
}
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
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
3717
3718
3719
3720
3721
3722
3723
3724
#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( 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;
}
if ( chromaIntraMode == LM_CHROMA_IDX && !bestGlmIdc.isActive() )
{
break;
}
}
}
}
pu.glmIdc.setAllZero();
#endif
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
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
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
#if JVET_AC0119_LM_CHROMA_FUSION
uint32_t uiFusionModeNum = 2;
#if MMLM
uiFusionModeNum += 1;
#endif
bool fusionModeIsEnable[6] = { false };
int32_t fusionModeMap[6][2];
Distortion satdChromaFusionCost[6];
int satdChromaFusionModeList[6];
for (int i = 0; i < 6; i++)
{
satdChromaFusionCost[i] = MAX_UINT64; // for the mode not pre-select by SATD, do RDO by default, so set the initial value 0.
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());
fusionStorage[uiMode * uiFusionModeNum].Cb().copyFrom(predStorage[uiMode].Cb());
fusionStorage[uiMode * uiFusionModeNum].Cr().copyFrom(predStorage[uiMode].Cr());
for (int32_t fusionMode = 0; fusionMode < uiFusionModeNum; fusionMode++)
{
pu.intraDir[1] = chromaIntraMode;
pu.isChromaFusion = fusionMode + 1;
int idx = uiMode * uiFusionModeNum + fusionMode;
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])
{
tempIdx = satdChromaFusionModeList[i];
satdChromaFusionModeList[i] = satdChromaFusionModeList[j];
satdChromaFusionModeList[j] = tempIdx;
tempCost = satdChromaFusionCost[i];
satdChromaFusionCost[i] = satdChromaFusionCost[j];
satdChromaFusionCost[j] = tempCost;
}
}
}
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])
break;
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]
#endif
);
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;
#if !JVET_AC0119_LM_CHROMA_FUSION
#if JVET_AC0119_LM_CHROMA_FUSION
pu.isChromaFusion = 0;
#else
pu.isChromaFusion = 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
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
#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( 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 ) );