Newer
Older

Karsten Suehring
committed
void PU::getIntraChromaCandModes( const PredictionUnit &pu, unsigned modeList[NUM_CHROMA_MODE] )
{
{
modeList[ 0 ] = PLANAR_IDX;
modeList[ 1 ] = VER_IDX;
modeList[ 2 ] = HOR_IDX;
modeList[ 3 ] = DC_IDX;
modeList[4] = LM_CHROMA_IDX;
modeList[5] = MDLM_L_IDX;
modeList[6] = MDLM_T_IDX;
modeList[7] = DM_CHROMA_IDX;

Karsten Suehring
committed
Position topLeftPos = pu.blocks[pu.chType].lumaPos();
Position refPos = topLeftPos.offset( pu.blocks[pu.chType].lumaSize().width >> 1, pu.blocks[pu.chType].lumaSize().height >> 1 );
const PredictionUnit *lumaPU = CS::isDualITree( *pu.cs ) ? pu.cs->picture->cs->getPU( refPos, CHANNEL_TYPE_LUMA ) : &pu;
#if JVET_N0217_MATRIX_INTRAPRED
const uint32_t lumaMode = PU::getIntraDirLuma( *lumaPU );
#else

Karsten Suehring
committed
const uint32_t lumaMode = lumaPU->intraDir[CHANNEL_TYPE_LUMA];

Karsten Suehring
committed
for( int i = 0; i < 4; i++ )
{
if( lumaMode == modeList[i] )
{
modeList[i] = VDIA_IDX;
break;
}
}
}
}
bool PU::isLMCMode(unsigned mode)
{
return (mode >= LM_CHROMA_IDX && mode <= MDLM_T_IDX);

Karsten Suehring
committed
}
bool PU::isLMCModeEnabled(const PredictionUnit &pu, unsigned mode)
{
if ( pu.cs->sps->getUseLMChroma() )

Karsten Suehring
committed
{
return true;
}
return false;
}
int PU::getLMSymbolList(const PredictionUnit &pu, int *pModeList)
{
int iIdx = 0;
pModeList[ iIdx++ ] = LM_CHROMA_IDX;
pModeList[ iIdx++ ] = -1;
pModeList[iIdx++] = MDLM_L_IDX;
pModeList[iIdx++] = MDLM_T_IDX;

Karsten Suehring
committed
return iIdx;
}
bool PU::isChromaIntraModeCrossCheckMode( const PredictionUnit &pu )
{
return pu.intraDir[CHANNEL_TYPE_CHROMA] == DM_CHROMA_IDX;
}
int PU::getMHIntraMPMs(const PredictionUnit &pu, unsigned* mpm, const ChannelType &channelType /*= CHANNEL_TYPE_LUMA*/, const bool isChromaMDMS /*= false*/, const unsigned startIdx /*= 0*/)
{
const int numMPMs = 3; // Multi-hypothesis intra uses only 3 MPM
{
int numCand = -1;
uint32_t leftIntraDir = DC_IDX, aboveIntraDir = DC_IDX;
const CompArea& area = pu.block(getFirstComponentOfChannel(channelType));
const Position& pos = area.pos();
// Get intra direction of left PU
const PredictionUnit *puLeft = pu.cs->getPURestricted(pos.offset(-1, 0), pu, channelType);
if (puLeft && (CU::isIntra(*puLeft->cu) || puLeft->mhIntraFlag))
{
leftIntraDir = puLeft->intraDir[channelType];
if (isChroma(channelType) && leftIntraDir == DM_CHROMA_IDX)
{
leftIntraDir = puLeft->intraDir[0];
}
}
// Get intra direction of above PU
const PredictionUnit* puAbove = pu.cs->getPURestricted(pos.offset(0, -1), pu, channelType);
if (puAbove && (CU::isIntra(*puAbove->cu) || puAbove->mhIntraFlag) && CU::isSameCtu(*pu.cu, *puAbove->cu))
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
{
aboveIntraDir = puAbove->intraDir[channelType];
if (isChroma(channelType) && aboveIntraDir == DM_CHROMA_IDX)
{
aboveIntraDir = puAbove->intraDir[0];
}
}
CHECK(2 >= numMPMs, "Invalid number of most probable modes");
uint32_t leftIntraDir2 = leftIntraDir;
uint32_t aboveIntraDir2 = aboveIntraDir;
leftIntraDir2 = (leftIntraDir2 > DC_IDX) ? ((leftIntraDir2 <= DIA_IDX) ? HOR_IDX : VER_IDX) : leftIntraDir2;
aboveIntraDir2 = (aboveIntraDir2 > DC_IDX) ? ((aboveIntraDir2 <= DIA_IDX) ? HOR_IDX : VER_IDX) : aboveIntraDir2;
if (leftIntraDir2 == aboveIntraDir2)
{
numCand = 1;
if (leftIntraDir2 > DC_IDX) // angular modes
{
mpm[0] = leftIntraDir2;
mpm[1] = PLANAR_IDX;
mpm[2] = DC_IDX;
}
else //non-angular
{
mpm[0] = PLANAR_IDX;
mpm[1] = DC_IDX;
mpm[2] = VER_IDX;
}
}
else
{
numCand = 2;
mpm[0] = leftIntraDir2;
mpm[1] = aboveIntraDir2;
if (leftIntraDir2 && aboveIntraDir2) //both modes are non-planar
{
mpm[2] = PLANAR_IDX;
}
else
{
mpm[2] = (leftIntraDir2 + aboveIntraDir2) < 2 ? VER_IDX : DC_IDX;
}
}
int narrowCase = getNarrowShape(pu.lwidth(), pu.lheight());
if (narrowCase > 0)
{
bool isMPM[NUM_LUMA_MODE];
for (int idx = 0; idx < NUM_LUMA_MODE; idx++)
{
isMPM[idx] = false;
}
for (int idx = 0; idx < numMPMs; idx++)
{
isMPM[mpm[idx]] = true;
}
if (narrowCase == 1 && isMPM[HOR_IDX])
{
for (int idx = 0; idx < numMPMs; idx++)
{
if (mpm[idx] == HOR_IDX)
{
if (!isMPM[PLANAR_IDX])
mpm[idx] = PLANAR_IDX;
else if (!isMPM[DC_IDX])
mpm[idx] = DC_IDX;
else if (!isMPM[VER_IDX])
mpm[idx] = VER_IDX;
break;
}
}
}
if (narrowCase == 2 && isMPM[VER_IDX])
{
for (int idx = 0; idx < numMPMs; idx++)
{
if (mpm[idx] == VER_IDX)
{
if (!isMPM[PLANAR_IDX])
mpm[idx] = PLANAR_IDX;
else if (!isMPM[DC_IDX])
mpm[idx] = DC_IDX;
else if (!isMPM[HOR_IDX])
mpm[idx] = HOR_IDX;
break;
}
}
}
}
CHECK(numCand == 0, "No candidates found");
CHECK(mpm[0] == mpm[1] || mpm[0] == mpm[2] || mpm[2] == mpm[1], "redundant MPM");
return numCand;
}
}
int PU::getNarrowShape(const int width, const int height)
{
int longSide = (width > height) ? width : height;
int shortSide = (width > height) ? height : width;
if (longSide > (2 * shortSide))
{
if (longSide == width)
return 1;
else
return 2;
}
else
{
return 0;
}
}

Karsten Suehring
committed
uint32_t PU::getFinalIntraMode( const PredictionUnit &pu, const ChannelType &chType )
{
uint32_t uiIntraMode = pu.intraDir[chType];
if( uiIntraMode == DM_CHROMA_IDX && !isLuma( chType ) )
{
Position topLeftPos = pu.blocks[pu.chType].lumaPos();
Position refPos = topLeftPos.offset( pu.blocks[pu.chType].lumaSize().width >> 1, pu.blocks[pu.chType].lumaSize().height >> 1 );
const PredictionUnit &lumaPU = CS::isDualITree( *pu.cs ) ? *pu.cs->picture->cs->getPU( refPos, CHANNEL_TYPE_LUMA ) : *pu.cs->getPU( topLeftPos, CHANNEL_TYPE_LUMA );
#if JVET_N0217_MATRIX_INTRAPRED
uiIntraMode = PU::getIntraDirLuma( lumaPU );
#else

Karsten Suehring
committed
uiIntraMode = lumaPU.intraDir[0];

Karsten Suehring
committed
}
#if JVET_N0671_CHROMA_FORMAT_422
if( pu.chromaFormat == CHROMA_422 && !isLuma( chType ) && uiIntraMode < NUM_LUMA_MODE ) // map directional, planar and dc
#else

Karsten Suehring
committed
if( pu.chromaFormat == CHROMA_422 && !isLuma( chType ) )
#endif //JVET_N0671_CHROMA_FORMAT_422

Karsten Suehring
committed
{
uiIntraMode = g_chroma422IntraAngleMappingTable[uiIntraMode];
}
return uiIntraMode;
}
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
#if JVET_N0193_LFNST
int PU::getWideAngIntraMode( const TransformUnit &tu, const uint32_t dirMode, const ComponentID compID )
{
if( dirMode < 2 )
{
return ( int ) dirMode;
}
CodingStructure& cs = *tu.cs;
const CompArea& area = tu.blocks[ compID ];
PelBuf pred = cs.getPredBuf( area );
int width = int( pred.width );
int height = int( pred.height );
int modeShift[ ] = { 0, 6, 10, 12, 14, 15 };
int deltaSize = abs( g_aucLog2[ width ] - g_aucLog2[ height ] );
int predMode = dirMode;
if( width > height && dirMode < 2 + modeShift[ deltaSize ] )
{
predMode += ( VDIA_IDX - 1 );
}
else if( height > width && predMode > VDIA_IDX - modeShift[ deltaSize ] )
{
predMode -= ( VDIA_IDX + 1 );
}
return predMode;
}
#endif
bool PU::xCheckSimilarMotion(const int mergeCandIndex, const int prevCnt, const MergeCtx mergeCandList, bool hasPruned[MRG_MAX_NUM_CANDS])
{
for (uint32_t ui = 0; ui < prevCnt; ui++)
{
if (hasPruned[ui])
{
continue;
}
if (mergeCandList.interDirNeighbours[ui] == mergeCandList.interDirNeighbours[mergeCandIndex])
{
if (mergeCandList.interDirNeighbours[ui] == 3)
{
int offset0 = (ui * 2);
int offset1 = (mergeCandIndex * 2);
if (mergeCandList.mvFieldNeighbours[offset0].refIdx == mergeCandList.mvFieldNeighbours[offset1].refIdx &&
mergeCandList.mvFieldNeighbours[offset0 + 1].refIdx == mergeCandList.mvFieldNeighbours[offset1 + 1].refIdx &&
mergeCandList.mvFieldNeighbours[offset0].mv == mergeCandList.mvFieldNeighbours[offset1].mv &&
mergeCandList.mvFieldNeighbours[offset0 + 1].mv == mergeCandList.mvFieldNeighbours[offset1 + 1].mv
)
{
hasPruned[ui] = true;
return true;
}
}
else
{
int offset0 = (ui * 2) + mergeCandList.interDirNeighbours[ui] - 1;
int offset1 = (mergeCandIndex * 2) + mergeCandList.interDirNeighbours[ui] - 1;
if (mergeCandList.mvFieldNeighbours[offset0].refIdx == mergeCandList.mvFieldNeighbours[offset1].refIdx &&
mergeCandList.mvFieldNeighbours[offset0].mv == mergeCandList.mvFieldNeighbours[offset1].mv
)
{
hasPruned[ui] = true;
return true;
}
}
}
}

Karsten Suehring
committed
bool PU::addMergeHMVPCand(const CodingStructure &cs, MergeCtx& mrgCtx, bool canFastExit, const int& mrgCandIdx, const uint32_t maxNumMergeCandMin1, int &cnt, const int prevCnt, bool isAvailableSubPu, unsigned subPuMvpPos
bool PU::addMergeHMVPCand(const CodingStructure &cs, MergeCtx& mrgCtx, bool isCandInter[MRG_MAX_NUM_CANDS], bool canFastExit, const int& mrgCandIdx, const uint32_t maxNumMergeCandMin1, int &cnt, const int prevCnt, bool isAvailableSubPu, unsigned subPuMvpPos
const Slice& slice = *cs.slice;
MotionInfo miNeighbor;
bool hasPruned[MRG_MAX_NUM_CANDS];
memset(hasPruned, 0, MRG_MAX_NUM_CANDS * sizeof(bool));
if (isAvailableSubPu)
{
hasPruned[subPuMvpPos] = true;
}
#if JVET_N0266_SMALL_BLOCKS
auto &lut = ibcFlag ? ( isShared ? cs.motionLut.lutShareIbc : cs.motionLut.lutIbc ) : cs.motionLut.lut;
#else
auto &lut = ibcFlag ? ( isShared ? cs.motionLut.lutShareIbc : cs.motionLut.lutIbc ) : ( isShared ? cs.motionLut.lutShare : cs.motionLut.lut );
#endif
int num_avai_candInLUT = (int) lut.size();
for (int mrgIdx = 1; mrgIdx <= num_avai_candInLUT; mrgIdx++)
{
miNeighbor = lut[num_avai_candInLUT - mrgIdx];
mrgCtx.interDirNeighbours[cnt] = miNeighbor.interDir;
mrgCtx.mvFieldNeighbours[cnt << 1].setMvField(miNeighbor.mv[0], miNeighbor.refIdx[0]);
if (slice.isInterB())
{
mrgCtx.mvFieldNeighbours[(cnt << 1) + 1].setMvField(miNeighbor.mv[1], miNeighbor.refIdx[1]);
}
#if JVET_N0843_BVP_SIMPLIFICATION
if (mrgIdx > 2 || (mrgIdx > 1 && ibcFlag) || !xCheckSimilarMotion(cnt, prevCnt, mrgCtx, hasPruned))
#else
if (mrgIdx > 2 || !xCheckSimilarMotion(cnt, prevCnt, mrgCtx, hasPruned))
{
#if !JVET_L0090_PAIR_AVG
isCandInter[cnt] = true;
#endif
mrgCtx.GBiIdx[cnt] = (mrgCtx.interDirNeighbours[cnt] == 3) ? miNeighbor.GBiIdx : GBI_DEFAULT;
{
return true;
}
cnt ++;
if (cnt == maxNumMergeCandMin1)
{
break;
}
}
}
return false;
}
void PU::getIBCMergeCandidates(const PredictionUnit &pu, MergeCtx& mrgCtx, const int& mrgCandIdx)
{
const CodingStructure &cs = *pu.cs;
const Slice &slice = *pu.cs->slice;
const uint32_t maxNumMergeCand = slice.getMaxNumMergeCand();
const bool canFastExit = pu.cs->pps->getLog2ParallelMergeLevelMinus2() == 0;
for (uint32_t ui = 0; ui < maxNumMergeCand; ++ui)
{
mrgCtx.GBiIdx[ui] = GBI_DEFAULT;
mrgCtx.interDirNeighbours[ui] = 0;
mrgCtx.mrgTypeNeighbours[ui] = MRG_TYPE_IBC;
mrgCtx.mvFieldNeighbours[ui * 2].refIdx = NOT_VALID;
mrgCtx.mvFieldNeighbours[ui * 2 + 1].refIdx = NOT_VALID;
}
mrgCtx.numValidMergeCand = maxNumMergeCand;
// compute the location of the current PU
int cnt = 0;
const Position posLT = pu.shareParentPos;
const Position posRT = pu.shareParentPos.offset(pu.shareParentSize.width - 1, 0);
const Position posLB = pu.shareParentPos.offset(0, pu.shareParentSize.height - 1);
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
MotionInfo miAbove, miLeft, miAboveLeft, miAboveRight, miBelowLeft;
//left
const PredictionUnit* puLeft = cs.getPURestricted(posLB.offset(-1, 0), pu, pu.chType);
const bool isAvailableA1 = puLeft && isDiffMER(pu, *puLeft) && pu.cu != puLeft->cu && CU::isIBC(*puLeft->cu);
if (isAvailableA1)
{
miLeft = puLeft->getMotionInfo(posLB.offset(-1, 0));
// get Inter Dir
mrgCtx.interDirNeighbours[cnt] = miLeft.interDir;
// get Mv from Left
mrgCtx.mvFieldNeighbours[cnt << 1].setMvField(miLeft.mv[0], miLeft.refIdx[0]);
if (mrgCandIdx == cnt && canFastExit)
{
return;
}
cnt++;
}
// early termination
if (cnt == maxNumMergeCand)
{
return;
}
// above
const PredictionUnit *puAbove = cs.getPURestricted(posRT.offset(0, -1), pu, pu.chType);
bool isAvailableB1 = puAbove && isDiffMER(pu, *puAbove) && pu.cu != puAbove->cu && CU::isIBC(*puAbove->cu);
if (isAvailableB1)
{
miAbove = puAbove->getMotionInfo(posRT.offset(0, -1));
if (!isAvailableA1 || (miAbove != miLeft))
{
// get Inter Dir
mrgCtx.interDirNeighbours[cnt] = miAbove.interDir;
// get Mv from Above
mrgCtx.mvFieldNeighbours[cnt << 1].setMvField(miAbove.mv[0], miAbove.refIdx[0]);
if (mrgCandIdx == cnt && canFastExit)
{
return;
}
cnt++;
}
}
// early termination
if (cnt == maxNumMergeCand)
{
return;
}
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
// above right
const PredictionUnit *puAboveRight = cs.getPURestricted(posRT.offset(1, -1), pu, pu.chType);
bool isAvailableB0 = puAboveRight && isDiffMER(pu, *puAboveRight) && CU::isIBC(*puAboveRight->cu);
if (isAvailableB0)
{
miAboveRight = puAboveRight->getMotionInfo(posRT.offset(1, -1));
#if HM_JEM_MERGE_CANDS
if ((!isAvailableB1 || (miAbove != miAboveRight)) && (!isAvailableA1 || (miLeft != miAboveRight)))
#else
if (!isAvailableB1 || (miAbove != miAboveRight))
#endif
{
// get Inter Dir
mrgCtx.interDirNeighbours[cnt] = miAboveRight.interDir;
// get Mv from Above-right
mrgCtx.mvFieldNeighbours[cnt << 1].setMvField(miAboveRight.mv[0], miAboveRight.refIdx[0]);
if (mrgCandIdx == cnt && canFastExit)
{
return;
}
cnt++;
}
}
// early termination
if (cnt == maxNumMergeCand)
{
return;
}
//left bottom
const PredictionUnit *puLeftBottom = cs.getPURestricted(posLB.offset(-1, 1), pu, pu.chType);
bool isAvailableA0 = puLeftBottom && isDiffMER(pu, *puLeftBottom) && CU::isIBC(*puLeftBottom->cu);
if (isAvailableA0)
{
miBelowLeft = puLeftBottom->getMotionInfo(posLB.offset(-1, 1));
#if HM_JEM_MERGE_CANDS
if ((!isAvailableA1 || (miBelowLeft != miLeft)) && (!isAvailableB1 || (miBelowLeft != miAbove)) && (!isAvailableB0 || (miBelowLeft != miAboveRight)))
#else
if (!isAvailableA1 || (miBelowLeft != miLeft))
#endif
{
// get Inter Dir
mrgCtx.interDirNeighbours[cnt] = miBelowLeft.interDir;
mrgCtx.mvFieldNeighbours[cnt << 1].setMvField(miBelowLeft.mv[0], miBelowLeft.refIdx[0]);
if (mrgCandIdx == cnt && canFastExit)
{
return;
}
cnt++;
}
}
// early termination
if (cnt == maxNumMergeCand)
{
return;
}
// above left
if (cnt < 4)
{
const PredictionUnit *puAboveLeft = cs.getPURestricted(posLT.offset(-1, -1), pu, pu.chType);
bool isAvailableB2 = puAboveLeft && isDiffMER(pu, *puAboveLeft) && CU::isIBC(*puAboveLeft->cu);
if (isAvailableB2)
{
miAboveLeft = puAboveLeft->getMotionInfo(posLT.offset(-1, -1));
#if HM_JEM_MERGE_CANDS
if ((!isAvailableA1 || (miLeft != miAboveLeft)) && (!isAvailableB1 || (miAbove != miAboveLeft)) && (!isAvailableA0 || (miBelowLeft != miAboveLeft)) && (!isAvailableB0 || (miAboveRight != miAboveLeft)))
#else
if ((!isAvailableA1 || (miLeft != miAboveLeft)) && (!isAvailableB1 || (miAbove != miAboveLeft)))
#endif
{
// get Inter Dir
mrgCtx.interDirNeighbours[cnt] = miAboveLeft.interDir;
mrgCtx.mvFieldNeighbours[cnt << 1].setMvField(miAboveLeft.mv[0], miAboveLeft.refIdx[0]);
if (mrgCandIdx == cnt && canFastExit)
{
return;
}
cnt++;
}
}
}
// early termination
if (cnt == maxNumMergeCand)
{
return;
}
#if JVET_N0843_BVP_SIMPLIFICATION
int maxNumMergeCandMin1 = maxNumMergeCand;
#else
if (cnt != maxNumMergeCandMin1)
{
bool isAvailableSubPu = false;
unsigned subPuMvpPos = 0;
bool isShared = ((pu.Y().lumaSize().width != pu.shareParentSize.width) || (pu.Y().lumaSize().height != pu.shareParentSize.height));
bool bFound = addMergeHMVPCand(cs, mrgCtx, canFastExit
, maxNumMergeCandMin1, cnt
, spatialCandPos
, isAvailableSubPu, subPuMvpPos
);
#else
bool bFound = addMergeHMVPCand(slice, mrgCtx, isCandInter, canFastExit
, mrgCandIdx
, maxNumMergeCandMin1, cnt, cnt, isAvailableSubPu, subPuMvpPos
);
#endif
if (bFound)
{
return;
}
}
#if JVET_L0090_PAIR_AVG && JVET_N0843_BVP_SIMPLIFICATION==0
if (cnt>1 && cnt <maxNumMergeCand)
{
mrgCtx.mvFieldNeighbours[cnt * 2 ].setMvField(Mv(0, 0), NOT_VALID);
mrgCtx.mvFieldNeighbours[cnt * 2 + 1].setMvField(Mv(0, 0), NOT_VALID);
const Mv& MvI = mrgCtx.mvFieldNeighbours[0 * 2].mv;
const Mv& MvJ = mrgCtx.mvFieldNeighbours[1 * 2].mv;
// average two MVs
Mv avgMv = MvI;
avgMv += MvJ;
mrgCtx.mrgTypeNeighbours[cnt] = MRG_TYPE_IBC;
roundAffineMv(avgMv.hor, avgMv.ver, 1);
avgMv.roundToPrecision(MV_PRECISION_INTERNAL, MV_PRECISION_INT);
mrgCtx.mvFieldNeighbours[cnt * 2 ].setMvField(avgMv, MAX_NUM_REF);
mrgCtx.interDirNeighbours[cnt] = 1;
cnt++;
}
// early termination
if (cnt == maxNumMergeCand)
{
return;
}
#endif
#if JVET_N0317_ADD_ZERO_BV
while (cnt < maxNumMergeCand)
{
mrgCtx.mvFieldNeighbours[cnt * 2].setMvField(Mv(0, 0), MAX_NUM_REF);
mrgCtx.interDirNeighbours[cnt] = 1;
cnt++;
if (mrgCandIdx == cnt && canFastExit)
{
return;
}
}
#endif
mrgCtx.numValidMergeCand = cnt;
}
void PU::getInterMergeCandidates( const PredictionUnit &pu, MergeCtx& mrgCtx,
int mmvdList,
const int& mrgCandIdx )

Karsten Suehring
committed
{
const CodingStructure &cs = *pu.cs;
const Slice &slice = *pu.cs->slice;
const uint32_t maxNumMergeCand = slice.getMaxNumMergeCand();
const bool canFastExit = pu.cs->pps->getLog2ParallelMergeLevelMinus2() == 0;
Yuling Hsiao
committed
#if !JVET_L0090_PAIR_AVG
// this variable is unused if remove HEVC combined candidates

Karsten Suehring
committed
bool isCandInter[MRG_MAX_NUM_CANDS];
Yuling Hsiao
committed
#endif

Karsten Suehring
committed
for (uint32_t ui = 0; ui < maxNumMergeCand; ++ui)
{
Yuling Hsiao
committed
#if !JVET_L0090_PAIR_AVG

Karsten Suehring
committed
isCandInter[ui] = false;
mrgCtx.GBiIdx[ui] = GBI_DEFAULT;

Karsten Suehring
committed
mrgCtx.interDirNeighbours[ui] = 0;
mrgCtx.mrgTypeNeighbours [ui] = MRG_TYPE_DEFAULT_N;
mrgCtx.mvFieldNeighbours[(ui << 1) ].refIdx = NOT_VALID;
mrgCtx.mvFieldNeighbours[(ui << 1) + 1].refIdx = NOT_VALID;
}
mrgCtx.numValidMergeCand = maxNumMergeCand;
// compute the location of the current PU
int cnt = 0;
#if JVET_N0266_SMALL_BLOCKS
const Position posLT = pu.Y().topLeft();
const Position posRT = pu.Y().topRight();
const Position posLB = pu.Y().bottomLeft();
#else
const Position posLT = pu.shareParentPos;
const Position posRT = pu.shareParentPos.offset(pu.shareParentSize.width - 1, 0);
const Position posLB = pu.shareParentPos.offset(0, pu.shareParentSize.height - 1);
#endif

Karsten Suehring
committed
MotionInfo miAbove, miLeft, miAboveLeft, miAboveRight, miBelowLeft;
//left
const PredictionUnit* puLeft = cs.getPURestricted( posLB.offset( -1, 0 ), pu, pu.chType );
const bool isAvailableA1 = puLeft && isDiffMER( pu, *puLeft ) && pu.cu != puLeft->cu && CU::isInter( *puLeft->cu );
if( isAvailableA1 )
{
miLeft = puLeft->getMotionInfo( posLB.offset(-1, 0) );
Yuling Hsiao
committed
#if !JVET_L0090_PAIR_AVG

Karsten Suehring
committed
isCandInter[cnt] = true;
Yuling Hsiao
committed
#endif

Karsten Suehring
committed
// get Inter Dir
mrgCtx.interDirNeighbours[cnt] = miLeft.interDir;
mrgCtx.GBiIdx[cnt] = (mrgCtx.interDirNeighbours[cnt] == 3) ? puLeft->cu->GBiIdx : GBI_DEFAULT;

Karsten Suehring
committed
// get Mv from Left
mrgCtx.mvFieldNeighbours[cnt << 1].setMvField(miLeft.mv[0], miLeft.refIdx[0]);
if (slice.isInterB())
{
mrgCtx.mvFieldNeighbours[(cnt << 1) + 1].setMvField(miLeft.mv[1], miLeft.refIdx[1]);
}

Karsten Suehring
committed
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
{
return;
}
cnt++;
}
// early termination
if (cnt == maxNumMergeCand)
{
return;
}
// above
const PredictionUnit *puAbove = cs.getPURestricted( posRT.offset( 0, -1 ), pu, pu.chType );
bool isAvailableB1 = puAbove && isDiffMER( pu, *puAbove ) && pu.cu != puAbove->cu && CU::isInter( *puAbove->cu );
if( isAvailableB1 )
{
miAbove = puAbove->getMotionInfo( posRT.offset( 0, -1 ) );
if( !isAvailableA1 || ( miAbove != miLeft ) )
{
Yuling Hsiao
committed
#if !JVET_L0090_PAIR_AVG

Karsten Suehring
committed
isCandInter[cnt] = true;
Yuling Hsiao
committed
#endif

Karsten Suehring
committed
// get Inter Dir
mrgCtx.interDirNeighbours[cnt] = miAbove.interDir;
// get Mv from Above
mrgCtx.GBiIdx[cnt] = (mrgCtx.interDirNeighbours[cnt] == 3) ? puAbove->cu->GBiIdx : GBI_DEFAULT;

Christian Helmrich
committed
mrgCtx.mvFieldNeighbours[cnt << 1].setMvField( miAbove.mv[0], miAbove.refIdx[0] );

Karsten Suehring
committed
if( slice.isInterB() )
{
mrgCtx.mvFieldNeighbours[( cnt << 1 ) + 1].setMvField( miAbove.mv[1], miAbove.refIdx[1] );
}

Karsten Suehring
committed
{
return;
}
cnt++;
}
}
// early termination
if( cnt == maxNumMergeCand )
{
return;
}

Karsten Suehring
committed
// above right
const PredictionUnit *puAboveRight = cs.getPURestricted( posRT.offset( 1, -1 ), pu, pu.chType );
bool isAvailableB0 = puAboveRight && isDiffMER( pu, *puAboveRight ) && CU::isInter( *puAboveRight->cu );
if( isAvailableB0 )
{
miAboveRight = puAboveRight->getMotionInfo( posRT.offset( 1, -1 ) );
#if HM_JEM_MERGE_CANDS
if( ( !isAvailableB1 || ( miAbove != miAboveRight ) ) && ( !isAvailableA1 || ( miLeft != miAboveRight ) ) )
#else
if( !isAvailableB1 || ( miAbove != miAboveRight ) )
#endif
{
Yuling Hsiao
committed
#if !JVET_L0090_PAIR_AVG

Karsten Suehring
committed
isCandInter[cnt] = true;
Yuling Hsiao
committed
#endif

Karsten Suehring
committed
// get Inter Dir
mrgCtx.interDirNeighbours[cnt] = miAboveRight.interDir;
// get Mv from Above-right
mrgCtx.GBiIdx[cnt] = (mrgCtx.interDirNeighbours[cnt] == 3) ? puAboveRight->cu->GBiIdx : GBI_DEFAULT;

Christian Helmrich
committed
mrgCtx.mvFieldNeighbours[cnt << 1].setMvField( miAboveRight.mv[0], miAboveRight.refIdx[0] );

Karsten Suehring
committed
if( slice.isInterB() )
{
mrgCtx.mvFieldNeighbours[( cnt << 1 ) + 1].setMvField( miAboveRight.mv[1], miAboveRight.refIdx[1] );
}

Karsten Suehring
committed
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
{
return;
}
cnt++;
}
}
// early termination
if( cnt == maxNumMergeCand )
{
return;
}
//left bottom
const PredictionUnit *puLeftBottom = cs.getPURestricted( posLB.offset( -1, 1 ), pu, pu.chType );
bool isAvailableA0 = puLeftBottom && isDiffMER( pu, *puLeftBottom ) && CU::isInter( *puLeftBottom->cu );
if( isAvailableA0 )
{
miBelowLeft = puLeftBottom->getMotionInfo( posLB.offset( -1, 1 ) );
#if HM_JEM_MERGE_CANDS
if( ( !isAvailableA1 || ( miBelowLeft != miLeft ) ) && ( !isAvailableB1 || ( miBelowLeft != miAbove ) ) && ( !isAvailableB0 || ( miBelowLeft != miAboveRight ) ) )
#else
if( !isAvailableA1 || ( miBelowLeft != miLeft ) )
#endif
{
Yuling Hsiao
committed
#if !JVET_L0090_PAIR_AVG

Karsten Suehring
committed
isCandInter[cnt] = true;
Yuling Hsiao
committed
#endif

Karsten Suehring
committed
// get Inter Dir
mrgCtx.interDirNeighbours[cnt] = miBelowLeft.interDir;
mrgCtx.GBiIdx[cnt] = (mrgCtx.interDirNeighbours[cnt] == 3) ? puLeftBottom->cu->GBiIdx : GBI_DEFAULT;

Karsten Suehring
committed
// get Mv from Bottom-Left
mrgCtx.mvFieldNeighbours[cnt << 1].setMvField( miBelowLeft.mv[0], miBelowLeft.refIdx[0] );
if( slice.isInterB() )
{
mrgCtx.mvFieldNeighbours[( cnt << 1 ) + 1].setMvField( miBelowLeft.mv[1], miBelowLeft.refIdx[1] );
}

Karsten Suehring
committed
{
return;
}
cnt++;
}
}
// early termination
if( cnt == maxNumMergeCand )
{
return;
}
// above left
if ( cnt < 4 )

Karsten Suehring
committed
{
const PredictionUnit *puAboveLeft = cs.getPURestricted( posLT.offset( -1, -1 ), pu, pu.chType );
bool isAvailableB2 = puAboveLeft && isDiffMER( pu, *puAboveLeft ) && CU::isInter( *puAboveLeft->cu );
if( isAvailableB2 )
{
miAboveLeft = puAboveLeft->getMotionInfo( posLT.offset( -1, -1 ) );
#if HM_JEM_MERGE_CANDS
if( ( !isAvailableA1 || ( miLeft != miAboveLeft ) ) && ( !isAvailableB1 || ( miAbove != miAboveLeft ) ) && ( !isAvailableA0 || ( miBelowLeft != miAboveLeft ) ) && ( !isAvailableB0 || ( miAboveRight != miAboveLeft ) ) )
#else
if( ( !isAvailableA1 || ( miLeft != miAboveLeft ) ) && ( !isAvailableB1 || ( miAbove != miAboveLeft ) ) )
#endif
{
Yuling Hsiao
committed
#if !JVET_L0090_PAIR_AVG

Karsten Suehring
committed
isCandInter[cnt] = true;
Yuling Hsiao
committed
#endif

Karsten Suehring
committed
// get Inter Dir
mrgCtx.interDirNeighbours[cnt] = miAboveLeft.interDir;
mrgCtx.GBiIdx[cnt] = (mrgCtx.interDirNeighbours[cnt] == 3) ? puAboveLeft->cu->GBiIdx : GBI_DEFAULT;

Karsten Suehring
committed
// get Mv from Above-Left
mrgCtx.mvFieldNeighbours[cnt << 1].setMvField( miAboveLeft.mv[0], miAboveLeft.refIdx[0] );
if( slice.isInterB() )
{
mrgCtx.mvFieldNeighbours[( cnt << 1 ) + 1].setMvField( miAboveLeft.mv[1], miAboveLeft.refIdx[1] );
}

Karsten Suehring
committed
{
return;
}
cnt++;
}
}
}
// early termination
if (cnt == maxNumMergeCand)
{
return;
}
#if JVET_N0213_TMVP_REMOVAL
if (slice.getEnableTMVPFlag() && (pu.lumaSize().width + pu.lumaSize().height > 12))
#else

Karsten Suehring
committed
if (slice.getEnableTMVPFlag())

Karsten Suehring
committed
{
//>> MTK colocated-RightBottom
// offset the pos to be sure to "point" to the same position the uiAbsPartIdx would've pointed to
#if JVET_N0266_SMALL_BLOCKS
Position posRB = pu.Y().bottomRight().offset( -3, -3 );
#else
Position posRB = pu.shareParentPos.offset(pu.shareParentSize.width-3, pu.shareParentSize.height - 3);
#endif

Karsten Suehring
committed
const PreCalcValues& pcv = *cs.pcv;
Position posC0;
#if JVET_N0266_SMALL_BLOCKS
Position posC1 = pu.Y().center();
#else
Position posC1 = pu.shareParentPos.offset((pu.shareParentSize.width/2), (pu.shareParentSize.height/2));
#endif

Karsten Suehring
committed
bool C0Avail = false;
#if !JVET_N0266_SMALL_BLOCKS
bool C1Avail = (posC1.x < pcv.lumaWidth) && (posC1.y < pcv.lumaHeight);
#endif

Karsten Suehring
committed
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
if (((posRB.x + pcv.minCUWidth) < pcv.lumaWidth) && ((posRB.y + pcv.minCUHeight) < pcv.lumaHeight))
{
{
Position posInCtu( posRB.x & pcv.maxCUWidthMask, posRB.y & pcv.maxCUHeightMask );
if( ( posInCtu.x + 4 < pcv.maxCUWidth ) && // is not at the last column of CTU
( posInCtu.y + 4 < pcv.maxCUHeight ) ) // is not at the last row of CTU
{
posC0 = posRB.offset( 4, 4 );
C0Avail = true;
}
else if( posInCtu.x + 4 < pcv.maxCUWidth ) // is not at the last column of CTU But is last row of CTU
{
posC0 = posRB.offset( 4, 4 );
// in the reference the CTU address is not set - thus probably resulting in no using this C0 possibility
}
else if( posInCtu.y + 4 < pcv.maxCUHeight ) // is not at the last row of CTU But is last column of CTU
{
posC0 = posRB.offset( 4, 4 );
C0Avail = true;
}
else //is the right bottom corner of CTU
{
posC0 = posRB.offset( 4, 4 );
// same as for last column but not last row
}
}
}
Mv cColMv;
int iRefIdx = 0;
int dir = 0;
unsigned uiArrayAddr = cnt;
bool bExistMV = ( C0Avail && getColocatedMVP(pu, REF_PIC_LIST_0, posC0, cColMv, iRefIdx ) )
#if JVET_N0266_SMALL_BLOCKS
|| getColocatedMVP( pu, REF_PIC_LIST_0, posC1, cColMv, iRefIdx );
#else
|| ( C1Avail && getColocatedMVP(pu, REF_PIC_LIST_0, posC1, cColMv, iRefIdx ));
#endif

Karsten Suehring
committed
if (bExistMV)
{
dir |= 1;
mrgCtx.mvFieldNeighbours[2 * uiArrayAddr].setMvField(cColMv, iRefIdx);
}
if (slice.isInterB())
{
bExistMV = ( C0Avail && getColocatedMVP(pu, REF_PIC_LIST_1, posC0, cColMv, iRefIdx ) )
#if JVET_N0266_SMALL_BLOCKS
|| getColocatedMVP( pu, REF_PIC_LIST_1, posC1, cColMv, iRefIdx );
#else
|| (C1Avail && getColocatedMVP(pu, REF_PIC_LIST_1, posC1, cColMv, iRefIdx ) );
#endif

Karsten Suehring
committed
if (bExistMV)
{
dir |= 2;
mrgCtx.mvFieldNeighbours[2 * uiArrayAddr + 1].setMvField(cColMv, iRefIdx);
}
}
if( dir != 0 )
{
bool addTMvp = true;

Karsten Suehring
committed
#if HM_JEM_MERGE_CANDS
int iSpanCand = cnt;

Karsten Suehring
committed
for( int i = 0; i < iSpanCand; i++ )
{
if( mrgCtx.interDirNeighbours[ i ] == dir &&
mrgCtx.mvFieldNeighbours [ i << 1 ] == mrgCtx.mvFieldNeighbours[ uiArrayAddr << 1 ] &&
mrgCtx.mvFieldNeighbours [( i << 1 ) + 1] == mrgCtx.mvFieldNeighbours[( uiArrayAddr << 1 ) + 1] )
{
addTMvp = false;
}
}
#endif
if( addTMvp )
{
mrgCtx.interDirNeighbours[uiArrayAddr] = dir;
Yuling Hsiao
committed
#if !JVET_L0090_PAIR_AVG

Karsten Suehring
committed
isCandInter [uiArrayAddr] = true;
Yuling Hsiao
committed
#endif
mrgCtx.GBiIdx[uiArrayAddr] = GBI_DEFAULT;

Karsten Suehring
committed
{
return;
}
cnt++;