Newer
Older
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 Slice &slice, MergeCtx& mrgCtx, bool canFastExit, const int& mrgCandIdx, const uint32_t maxNumMergeCandMin1, int &cnt, const int prevCnt, bool isAvailableSubPu, unsigned subPuMvpPos
#if JVET_M0170_MRG_SHARELIST
, bool isShared
#endif
bool PU::addMergeHMVPCand(const Slice &slice, 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
, int mmvdList
)
MotionInfo miNeighbor;
bool hasPruned[MRG_MAX_NUM_CANDS];
memset(hasPruned, 0, MRG_MAX_NUM_CANDS * sizeof(bool));
if (isAvailableSubPu)
{
hasPruned[subPuMvpPos] = true;
}
int num_avai_candInLUT = ibcFlag ? (isShared ? slice.getAvailableLUTBkupIBCMrgNum() : slice.getAvailableLUTIBCMrgNum()) : (isShared ? slice.getAvailableLUTBkupMrgNum() : slice.getAvailableLUTMrgNum());
int num_avai_candInLUT = (isShared ? slice.getAvailableLUTBkupMrgNum() : slice.getAvailableLUTMrgNum());
int num_avai_candInLUT = ibcFlag ? slice.getAvailableLUTIBCMrgNum() : slice.getAvailableLUTMrgNum();
int offset = ibcFlag ? MAX_NUM_HMVP_CANDS : 0;
int num_avai_candInLUT = slice.getAvailableLUTMrgNum();
for (int mrgIdx = 1; mrgIdx <= num_avai_candInLUT; mrgIdx++)
{
miNeighbor = ibcFlag ? (isShared ? slice.getMotionInfoFromLUTBkup(num_avai_candInLUT - mrgIdx + offset) : slice.getMotionInfoFromLUTs(num_avai_candInLUT - mrgIdx + offset))
: (isShared ? slice.getMotionInfoFromLUTBkup(num_avai_candInLUT - mrgIdx) : slice.getMotionInfoFromLUTs(num_avai_candInLUT - mrgIdx));
miNeighbor = isShared ? slice.getMotionInfoFromLUTBkup(num_avai_candInLUT - mrgIdx) : slice.getMotionInfoFromLUTs(num_avai_candInLUT - mrgIdx);
miNeighbor = slice.getMotionInfoFromLUTs(num_avai_candInLUT - mrgIdx + offset);
miNeighbor = slice.getMotionInfoFromLUTs(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_M0126_HMVP_MRG_PRUNING
if (mrgIdx > 2 || !xCheckSimilarMotion(cnt, prevCnt, mrgCtx, hasPruned))
#else
if (!xCheckSimilarMotion(cnt, prevCnt, mrgCtx, hasPruned))
{
#if !JVET_L0090_PAIR_AVG
isCandInter[cnt] = true;
#endif
#if JVET_M0264_HMVP_WITH_GBIIDX
mrgCtx.GBiIdx[cnt] = (mrgCtx.interDirNeighbours[cnt] == 3) ? miNeighbor.GBiIdx : GBI_DEFAULT;
#endif
if (miNeighbor.interDir == 1 && slice.getRefPic(REF_PIC_LIST_0, miNeighbor.refIdx[0])->getPOC() == slice.getPOC())
{
#else
if (mrgCandIdx == cnt && canFastExit)
#endif
{
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;
#if JVET_M0170_MRG_SHARELIST
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);
#else
const Position posLT = pu.Y().topLeft();
const Position posRT = pu.Y().topRight();
const Position posLB = pu.Y().bottomLeft();
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
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
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;
}
#if JVET_M0126_HMVP_MRG_PRUNING
int spatialCandPos = cnt;
#endif
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
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
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
// 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;
}
int maxNumMergeCandMin1 = maxNumMergeCand - 1;
if (cnt != maxNumMergeCandMin1)
{
bool isAvailableSubPu = false;
unsigned subPuMvpPos = 0;
#if JVET_M0170_MRG_SHARELIST
bool isShared = ((pu.Y().lumaSize().width != pu.shareParentSize.width) || (pu.Y().lumaSize().height != pu.shareParentSize.height));
#endif
#if JVET_L0090_PAIR_AVG
bool bFound = addMergeHMVPCand(slice, mrgCtx, canFastExit
, mrgCandIdx
, maxNumMergeCandMin1, cnt
#if JVET_M0126_HMVP_MRG_PRUNING
, spatialCandPos
#else
, cnt
#endif
, isAvailableSubPu, subPuMvpPos
, true
#endif
#if JVET_M0170_MRG_SHARELIST
#endif
);
#else
bool bFound = addMergeHMVPCand(slice, mrgCtx, isCandInter, canFastExit
, mrgCandIdx
, maxNumMergeCandMin1, cnt, cnt, isAvailableSubPu, subPuMvpPos
);
#endif
if (bFound)
{
return;
}
}
#if JVET_L0090_PAIR_AVG
// pairwise-average candidates
const int cutoff = std::min(cnt, 4);
const int end = cutoff * (cutoff - 1) / 2;
constexpr int PRIORITY_LIST0[] = { 0, 0, 1, 0, 1, 2 };
constexpr int PRIORITY_LIST1[] = { 1, 2, 2, 3, 3, 3 };
for (int idx = 0; idx < end && cnt != maxNumMergeCand; idx++)
{
const int i = PRIORITY_LIST0[idx];
const int j = PRIORITY_LIST1[idx];
#else
if (cnt>1 && cnt <maxNumMergeCand)
{
#endif
mrgCtx.mvFieldNeighbours[cnt * 2 ].setMvField(Mv(0, 0), NOT_VALID);
mrgCtx.mvFieldNeighbours[cnt * 2 + 1].setMvField(Mv(0, 0), NOT_VALID);
#if JVET_M0193_PAIR_AVG_REDUCTION
const Mv& MvI = mrgCtx.mvFieldNeighbours[0 * 2].mv;
const Mv& MvJ = mrgCtx.mvFieldNeighbours[1 * 2].mv;
#else
const Mv& MvI = mrgCtx.mvFieldNeighbours[i * 2 ].mv;
const Mv& MvJ = mrgCtx.mvFieldNeighbours[j * 2 ].mv;
#endif
// average two MVs
Mv avgMv = MvI;
avgMv += MvJ;
mrgCtx.mrgTypeNeighbours[cnt] = MRG_TYPE_IBC;
avgMv.roundToPrecision(MV_PRECISION_INTERNAL, MV_PRECISION_INT);
avgMv.setHor(avgMv.getHor() / 2);
avgMv.setVer(avgMv.getVer() / 2);
avgMv.setHor((avgMv.getHor() / 16) << 4);
avgMv.setVer((avgMv.getVer() / 16) << 4);
mrgCtx.mvFieldNeighbours[cnt * 2 ].setMvField(avgMv, MAX_NUM_REF);
mrgCtx.interDirNeighbours[cnt] = 1;
cnt++;
}
// early termination
if (cnt == maxNumMergeCand)
{
return;
}
#endif
mrgCtx.numValidMergeCand = cnt;
}
#endif
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_M0170_MRG_SHARELIST
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);
#else

Karsten Suehring
committed
const Position posLT = pu.Y().topLeft();
const Position posRT = pu.Y().topRight();
const Position posLB = pu.Y().bottomLeft();

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

Karsten Suehring
committed
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]);
}
#else
if (mrgCandIdx == cnt && canFastExit)
#endif

Karsten Suehring
committed
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
{
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] );
}
#else
if (mrgCandIdx == cnt && canFastExit)
#endif

Karsten Suehring
committed
{
return;
}
cnt++;
}
}
// early termination
if( cnt == maxNumMergeCand )
{
return;
}
#if JVET_M0126_HMVP_MRG_PRUNING
int spatialCandPos = cnt;
#endif

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] );
}
#else
if (mrgCandIdx == cnt && canFastExit)
#endif

Karsten Suehring
committed
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
{
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

Karsten Suehring
committed
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] );
}
#else
if (mrgCandIdx == cnt && canFastExit)
#endif

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

Karsten Suehring
committed
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] );
}
#else
if (mrgCandIdx == cnt && canFastExit)
#endif

Karsten Suehring
committed
{
return;
}
cnt++;
}
}
}
// early termination
if (cnt == maxNumMergeCand)
{
return;
}
if (slice.getEnableTMVPFlag())
{
//>> MTK colocated-RightBottom
// offset the pos to be sure to "point" to the same position the uiAbsPartIdx would've pointed to
#if JVET_M0170_MRG_SHARELIST
Position posRB = pu.shareParentPos.offset(pu.shareParentSize.width-3, pu.shareParentSize.height - 3);
#else

Karsten Suehring
committed
Position posRB = pu.Y().bottomRight().offset(-3, -3);

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

Karsten Suehring
committed
Position posC1 = pu.Y().center();

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

Karsten Suehring
committed
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
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_M0170_MRG_SHARELIST
|| ( C1Avail && getColocatedMVP(pu, REF_PIC_LIST_0, posC1, cColMv, iRefIdx ));
#else

Karsten Suehring
committed
|| getColocatedMVP(pu, REF_PIC_LIST_0, posC1, cColMv, iRefIdx );

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_M0170_MRG_SHARELIST
|| (C1Avail && getColocatedMVP(pu, REF_PIC_LIST_1, posC1, cColMv, iRefIdx ) );
#else

Karsten Suehring
committed
|| getColocatedMVP(pu, REF_PIC_LIST_1, posC1, cColMv, iRefIdx );

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;
#else
if (mrgCandIdx == cnt && canFastExit)
#endif

Karsten Suehring
committed
{
return;
}
cnt++;
}
}
}
// early termination
if (cnt == maxNumMergeCand)
{
return;
}
int maxNumMergeCandMin1 = maxNumMergeCand - 1;
if (cnt != maxNumMergeCandMin1)
{
bool isAvailableSubPu = false;
unsigned subPuMvpPos = 0;
#if JVET_M0170_MRG_SHARELIST
bool isShared = ((pu.Y().lumaSize().width != pu.shareParentSize.width) || (pu.Y().lumaSize().height != pu.shareParentSize.height));
#endif
bool bFound = addMergeHMVPCand(slice, mrgCtx, canFastExit
, (mmvdList != 0 && mrgCandIdx != -1) ? (const int) mrgCandIdxIBC : mrgCandIdx
, maxNumMergeCandMin1, cnt
#if JVET_M0126_HMVP_MRG_PRUNING
, spatialCandPos
#else
, cnt
#endif
, isAvailableSubPu, subPuMvpPos
#if JVET_M0170_MRG_SHARELIST
, isShared
#endif
);
#else
bool bFound = addMergeHMVPCand(slice, mrgCtx, isCandInter, canFastExit
, (mmvdList != 0 && mrgCandIdx != -1) ? (const int)mrgCandIdxIBC : mrgCandIdx
, maxNumMergeCandMin1, cnt, cnt, isAvailableSubPu, subPuMvpPos
, mmvdList
);
#endif
if (bFound)
{
return;
}
}
Yuling Hsiao
committed
#if JVET_L0090_PAIR_AVG
// pairwise-average candidates
{
Anish Tamse
committed
#if !JVET_M0193_PAIR_AVG_REDUCTION
Yuling Hsiao
committed
const int cutoff = std::min( cnt, 4 );
const int end = cutoff * (cutoff - 1) / 2;
constexpr int PRIORITY_LIST0[] = { 0, 0, 1, 0, 1, 2 };
constexpr int PRIORITY_LIST1[] = { 1, 2, 2, 3, 3, 3 };
Anish Tamse
committed
#endif
Yuling Hsiao
committed
Anish Tamse
committed
#if JVET_M0193_PAIR_AVG_REDUCTION
#if JVET_M0483_IBC
if (cnt > 1 && cnt < maxNumMergeCand)
#else
Anish Tamse
committed
// skip when only 1 candidate is added so far or one is BV and one is MV
if( cnt > 1 && cnt < maxNumMergeCand && !(mrgCtx.mrgTypeNeighbours[0] != mrgCtx.mrgTypeNeighbours[1] && pu.cs->sps->getIBCMode()))
Anish Tamse
committed
#else
Yuling Hsiao
committed
for( int idx = 0; idx < end && cnt != maxNumMergeCand; idx++ )
Anish Tamse
committed
#endif
Yuling Hsiao
committed
{
Anish Tamse
committed
#if !JVET_M0193_PAIR_AVG_REDUCTION
Yuling Hsiao
committed
const int i = PRIORITY_LIST0[idx];
const int j = PRIORITY_LIST1[idx];
Anish Tamse
committed
#endif
Yuling Hsiao
committed
mrgCtx.mvFieldNeighbours[cnt * 2].setMvField( Mv( 0, 0 ), NOT_VALID );
mrgCtx.mvFieldNeighbours[cnt * 2 + 1].setMvField( Mv( 0, 0 ), NOT_VALID );
// calculate average MV for L0 and L1 seperately
unsigned char interDir = 0;
if (mrgCtx.mrgTypeNeighbours[i] != mrgCtx.mrgTypeNeighbours[j] && pu.cs->sps->getIBCMode())
Anish Tamse
committed
#endif
Yuling Hsiao
committed
for( int refListId = 0; refListId < (slice.isInterB() ? 2 : 1); refListId++ )
{
Anish Tamse
committed
#if JVET_M0193_PAIR_AVG_REDUCTION
const short refIdxI = mrgCtx.mvFieldNeighbours[0 * 2 + refListId].refIdx;
const short refIdxJ = mrgCtx.mvFieldNeighbours[1 * 2 + refListId].refIdx;
#else
Yuling Hsiao
committed
const short refIdxI = mrgCtx.mvFieldNeighbours[i * 2 + refListId].refIdx;
const short refIdxJ = mrgCtx.mvFieldNeighbours[j * 2 + refListId].refIdx;
Anish Tamse
committed
#endif
Yuling Hsiao
committed
// both MVs are invalid, skip
if( (refIdxI == NOT_VALID) && (refIdxJ == NOT_VALID) )
{
continue;
}
interDir += 1 << refListId;
// both MVs are valid, average these two MVs
if( (refIdxI != NOT_VALID) && (refIdxJ != NOT_VALID) )
{
Anish Tamse
committed
#if JVET_M0193_PAIR_AVG_REDUCTION
const Mv& MvI = mrgCtx.mvFieldNeighbours[0 * 2 + refListId].mv;
const Mv& MvJ = mrgCtx.mvFieldNeighbours[1 * 2 + refListId].mv;
#else
Yuling Hsiao
committed
const Mv& MvI = mrgCtx.mvFieldNeighbours[i * 2 + refListId].mv;
const Mv& MvJ = mrgCtx.mvFieldNeighbours[j * 2 + refListId].mv;
Anish Tamse
committed
#endif
Yuling Hsiao
committed
// average two MVs
Mv avgMv = MvI;
avgMv += MvJ;
#if JVET_M0265_MV_ROUNDING_CLEANUP
roundAffineMv(avgMv.hor, avgMv.ver, 1);
#else
Yuling Hsiao
committed
avgMv.setHor( avgMv.getHor() / 2 );
avgMv.setVer( avgMv.getVer() / 2 );
Anish Tamse
committed
#if JVET_M0193_PAIR_AVG_REDUCTION
if (mrgCtx.mrgTypeNeighbours[0] == MRG_TYPE_IBC && mrgCtx.mrgTypeNeighbours[1] == MRG_TYPE_IBC && pu.cs->sps->getIBCMode())
Anish Tamse
committed
#else
if (mrgCtx.mrgTypeNeighbours[i] == MRG_TYPE_IBC && mrgCtx.mrgTypeNeighbours[j] == MRG_TYPE_IBC && pu.cs->sps->getIBCMode())
Anish Tamse
committed
#endif
avgMv.setHor((avgMv.getHor() / 16) << 4);
avgMv.setVer((avgMv.getVer() / 16) << 4);
}
Yuling Hsiao
committed
mrgCtx.mvFieldNeighbours[cnt * 2 + refListId].setMvField( avgMv, refIdxI );
}
// only one MV is valid, take the only one MV
else if( refIdxI != NOT_VALID )
{
Anish Tamse
committed
#if JVET_M0193_PAIR_AVG_REDUCTION
Mv singleMv = mrgCtx.mvFieldNeighbours[0 * 2 + refListId].mv;
#else
Yuling Hsiao
committed
Mv singleMv = mrgCtx.mvFieldNeighbours[i * 2 + refListId].mv;
Anish Tamse
committed
#endif
Yuling Hsiao
committed
mrgCtx.mvFieldNeighbours[cnt * 2 + refListId].setMvField( singleMv, refIdxI );
}
else if( refIdxJ != NOT_VALID )
{