Newer
Older

Karsten Suehring
committed
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
{
continue;
}
// add an analogue CU into own CU store
const UnitArea &cuPatch = *pcu;
CodingUnit &cu = addCU(cuPatch, chType);
// copy the CU info from subPatch
cu = *pcu;
}
// copy the PUs over
for (const auto &ppu : other.pus)
{
if( !dualITreeArea.contains( *ppu ) )
{
continue;
}
// add an analogue PU into own PU store
const UnitArea &puPatch = *ppu;
PredictionUnit &pu = addPU(puPatch, chType);
// copy the PU info from subPatch
pu = *ppu;
}
if (!other.slice->isIntra() || other.slice->getSPS()->getIBCFlag())

Karsten Suehring
committed
if( !other.slice->isIntra() )

Karsten Suehring
committed
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
{
// copy motion buffer
MotionBuf ownMB = getMotionBuf();
CMotionBuf subMB = other.getMotionBuf();
ownMB.copyFrom( subMB );
}
if( copyTUs )
{
// copy the TUs over
for( const auto &ptu : other.tus )
{
if( !dualITreeArea.contains( *ptu ) )
{
continue;
}
// add an analogue TU into own TU store
const UnitArea &tuPatch = *ptu;
TransformUnit &tu = addTU( tuPatch, chType );
// copy the TU info from subPatch
tu = *ptu;
}
}
if( copyRecoBuf )
{
CPelUnitBuf recoBuf = other.getRecoBuf( area );
if( parent )
{
// copy data to self for neighbors
getRecoBuf( area ).copyFrom( recoBuf );
}
// copy data to picture
picture->getRecoBuf( area ).copyFrom( recoBuf );
Tobias Hinz
committed
if (other.pcv->isEncoder)
Tobias Hinz
committed
CPelUnitBuf predBuf = other.getPredBuf(area);
if (parent)
{
getPredBuf(area).copyFrom(predBuf);
}
picture->getPredBuf(area).copyFrom(predBuf);
}
#endif
#if JVET_M0055_DEBUG_CTU
// required for DebugCTU
int numCh = ::getNumberValidChannels( area.chromaFormat );
for( int i = 0; i < numCh; i++ )
{
const size_t _area = unitScale[i].scaleArea( area.blocks[i].area() );
memcpy( m_isDecomp[i], other.m_isDecomp[i], sizeof( *m_isDecomp[0] ) * _area );
}
#endif

Karsten Suehring
committed
}
}
void CodingStructure::initStructData( const int &QP, const bool &_isLosses, const bool &skipMotBuf )
{
clearPUs();
clearTUs();
clearCUs();
Adam Wieckowski
committed
if( QP < MAX_INT )

Karsten Suehring
committed
{
currQP[0] = currQP[1] = QP;
isLossless = _isLosses;
}
if (!skipMotBuf && (!parent || ((!slice->isIntra() || slice->getSPS()->getIBCFlag()) && !m_isTuEnc)))

Karsten Suehring
committed
if( !skipMotBuf && ( !parent || ( ( slice->getSliceType() != I_SLICE ) && !m_isTuEnc ) ) )

Karsten Suehring
committed
{
getMotionBuf() .memset( 0 );
}
fracBits = 0;
dist = 0;
cost = MAX_DOUBLE;
#if JVET_M0102_INTRA_SUBPARTITIONS
lumaCost = MAX_DOUBLE;
#endif
#if JVET_M0428_ENC_DB_OPT
costDbOffset = 0;
useDbCost = false;

Karsten Suehring
committed
interHad = std::numeric_limits<Distortion>::max();
}
void CodingStructure::clearTUs()
{
int numCh = ::getNumberValidChannels( area.chromaFormat );
for( int i = 0; i < numCh; i++ )
{
size_t _area = ( area.blocks[i].area() >> unitScale[i].area );
memset( m_isDecomp[i], false, sizeof( *m_isDecomp[0] ) * _area );
memset( m_tuIdx [i], 0, sizeof( *m_tuIdx [0] ) * _area );
}
numCh = getNumberValidComponents( area.chromaFormat );

Karsten Suehring
committed
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
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
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
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
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
for( int i = 0; i < numCh; i++ )
{
m_offsets[i] = 0;
}
for( auto &pcu : cus )
{
pcu->firstTU = pcu->lastTU = nullptr;
}
m_tuCache.cache( tus );
m_numTUs = 0;
}
void CodingStructure::clearPUs()
{
int numCh = ::getNumberValidChannels( area.chromaFormat );
for( int i = 0; i < numCh; i++ )
{
memset( m_puIdx[i], 0, sizeof( *m_puIdx[0] ) * unitScale[i].scaleArea( area.blocks[i].area() ) );
}
m_puCache.cache( pus );
m_numPUs = 0;
for( auto &pcu : cus )
{
pcu->firstPU = pcu->lastPU = nullptr;
}
}
void CodingStructure::clearCUs()
{
int numCh = ::getNumberValidChannels( area.chromaFormat );
for( int i = 0; i < numCh; i++ )
{
memset( m_cuIdx[i], 0, sizeof( *m_cuIdx[0] ) * unitScale[i].scaleArea( area.blocks[i].area() ) );
}
m_cuCache.cache( cus );
m_numCUs = 0;
}
MotionBuf CodingStructure::getMotionBuf( const Area& _area )
{
const CompArea& _luma = area.Y();
CHECKD( !_luma.contains( _area ), "Trying to access motion information outside of this coding structure" );
const Area miArea = g_miScaling.scale( _area );
const Area selfArea = g_miScaling.scale( _luma );
return MotionBuf( m_motionBuf + rsAddr( miArea.pos(), selfArea.pos(), selfArea.width ), selfArea.width, miArea.size() );
}
const CMotionBuf CodingStructure::getMotionBuf( const Area& _area ) const
{
const CompArea& _luma = area.Y();
CHECKD( !_luma.contains( _area ), "Trying to access motion information outside of this coding structure" );
const Area miArea = g_miScaling.scale( _area );
const Area selfArea = g_miScaling.scale( _luma );
return MotionBuf( m_motionBuf + rsAddr( miArea.pos(), selfArea.pos(), selfArea.width ), selfArea.width, miArea.size() );
}
MotionInfo& CodingStructure::getMotionInfo( const Position& pos )
{
CHECKD( !area.Y().contains( pos ), "Trying to access motion information outside of this coding structure" );
//return getMotionBuf().at( g_miScaling.scale( pos - area.lumaPos() ) );
// bypass the motion buf calling and get the value directly
const unsigned stride = g_miScaling.scaleHor( area.lumaSize().width );
const Position miPos = g_miScaling.scale( pos - area.lumaPos() );
return *( m_motionBuf + miPos.y * stride + miPos.x );
}
const MotionInfo& CodingStructure::getMotionInfo( const Position& pos ) const
{
CHECKD( !area.Y().contains( pos ), "Trying to access motion information outside of this coding structure" );
//return getMotionBuf().at( g_miScaling.scale( pos - area.lumaPos() ) );
// bypass the motion buf calling and get the value directly
const unsigned stride = g_miScaling.scaleHor( area.lumaSize().width );
const Position miPos = g_miScaling.scale( pos - area.lumaPos() );
return *( m_motionBuf + miPos.y * stride + miPos.x );
}
// data accessors
PelBuf CodingStructure::getPredBuf(const CompArea &blk) { return getBuf(blk, PIC_PREDICTION); }
const CPelBuf CodingStructure::getPredBuf(const CompArea &blk) const { return getBuf(blk, PIC_PREDICTION); }
PelUnitBuf CodingStructure::getPredBuf(const UnitArea &unit) { return getBuf(unit, PIC_PREDICTION); }
const CPelUnitBuf CodingStructure::getPredBuf(const UnitArea &unit) const { return getBuf(unit, PIC_PREDICTION); }
PelBuf CodingStructure::getResiBuf(const CompArea &blk) { return getBuf(blk, PIC_RESIDUAL); }
const CPelBuf CodingStructure::getResiBuf(const CompArea &blk) const { return getBuf(blk, PIC_RESIDUAL); }
PelUnitBuf CodingStructure::getResiBuf(const UnitArea &unit) { return getBuf(unit, PIC_RESIDUAL); }
const CPelUnitBuf CodingStructure::getResiBuf(const UnitArea &unit) const { return getBuf(unit, PIC_RESIDUAL); }
PelBuf CodingStructure::getRecoBuf(const CompArea &blk) { return getBuf(blk, PIC_RECONSTRUCTION); }
const CPelBuf CodingStructure::getRecoBuf(const CompArea &blk) const { return getBuf(blk, PIC_RECONSTRUCTION); }
PelUnitBuf CodingStructure::getRecoBuf(const UnitArea &unit) { return getBuf(unit, PIC_RECONSTRUCTION); }
const CPelUnitBuf CodingStructure::getRecoBuf(const UnitArea &unit) const { return getBuf(unit, PIC_RECONSTRUCTION); }
PelBuf CodingStructure::getOrgResiBuf(const CompArea &blk) { return getBuf(blk, PIC_ORG_RESI); }
const CPelBuf CodingStructure::getOrgResiBuf(const CompArea &blk) const { return getBuf(blk, PIC_ORG_RESI); }
PelUnitBuf CodingStructure::getOrgResiBuf(const UnitArea &unit) { return getBuf(unit, PIC_ORG_RESI); }
const CPelUnitBuf CodingStructure::getOrgResiBuf(const UnitArea &unit) const { return getBuf(unit, PIC_ORG_RESI); }
PelBuf CodingStructure::getOrgBuf(const CompArea &blk) { return getBuf(blk, PIC_ORIGINAL); }
const CPelBuf CodingStructure::getOrgBuf(const CompArea &blk) const { return getBuf(blk, PIC_ORIGINAL); }
PelUnitBuf CodingStructure::getOrgBuf(const UnitArea &unit) { return getBuf(unit, PIC_ORIGINAL); }
const CPelUnitBuf CodingStructure::getOrgBuf(const UnitArea &unit) const { return getBuf(unit, PIC_ORIGINAL); }
PelBuf CodingStructure::getOrgBuf(const ComponentID &compID) { return picture->getBuf(area.blocks[compID], PIC_ORIGINAL); }
const CPelBuf CodingStructure::getOrgBuf(const ComponentID &compID)const { return picture->getBuf(area.blocks[compID], PIC_ORIGINAL); }
PelUnitBuf CodingStructure::getOrgBuf() { return picture->getBuf(area, PIC_ORIGINAL); }
const CPelUnitBuf CodingStructure::getOrgBuf() const { return picture->getBuf(area, PIC_ORIGINAL); }
PelBuf CodingStructure::getBuf( const CompArea &blk, const PictureType &type )
{
if (!blk.valid())
{
return PelBuf();
}
if (type == PIC_ORIGINAL)
{
return picture->getBuf(blk, type);
}
const ComponentID compID = blk.compID;
PelStorage* buf = type == PIC_PREDICTION ? &m_pred : ( type == PIC_RESIDUAL ? &m_resi : ( type == PIC_RECONSTRUCTION ? &m_reco : ( type == PIC_ORG_RESI ? &m_orgr : nullptr ) ) );
CHECK( !buf, "Unknown buffer requested" );
CHECKD( !area.blocks[compID].contains( blk ), "Buffer not contained in self requested" );
CompArea cFinal = blk;
cFinal.relativeTo( area.blocks[compID] );
#if !KEEP_PRED_AND_RESI_SIGNALS
if( !parent && ( type == PIC_RESIDUAL || type == PIC_PREDICTION ) )
{
cFinal.x &= ( pcv->maxCUWidthMask >> getComponentScaleX( blk.compID, blk.chromaFormat ) );
cFinal.y &= ( pcv->maxCUHeightMask >> getComponentScaleY( blk.compID, blk.chromaFormat ) );
}
#endif
return buf->getBuf( cFinal );
}
const CPelBuf CodingStructure::getBuf( const CompArea &blk, const PictureType &type ) const
{
if (!blk.valid())
{
return PelBuf();
}
if (type == PIC_ORIGINAL)
{
return picture->getBuf(blk, type);
}
const ComponentID compID = blk.compID;
const PelStorage* buf = type == PIC_PREDICTION ? &m_pred : ( type == PIC_RESIDUAL ? &m_resi : ( type == PIC_RECONSTRUCTION ? &m_reco : ( type == PIC_ORG_RESI ? &m_orgr : nullptr ) ) );
CHECK( !buf, "Unknown buffer requested" );
CHECKD( !area.blocks[compID].contains( blk ), "Buffer not contained in self requested" );
CompArea cFinal = blk;
cFinal.relativeTo( area.blocks[compID] );
#if !KEEP_PRED_AND_RESI_SIGNALS
if( !parent && ( type == PIC_RESIDUAL || type == PIC_PREDICTION ) )
{
cFinal.x &= ( pcv->maxCUWidthMask >> getComponentScaleX( blk.compID, blk.chromaFormat ) );
cFinal.y &= ( pcv->maxCUHeightMask >> getComponentScaleY( blk.compID, blk.chromaFormat ) );
}
#endif
return buf->getBuf( cFinal );
}
PelUnitBuf CodingStructure::getBuf( const UnitArea &unit, const PictureType &type )
{
// no parent fetching for buffers
if( area.chromaFormat == CHROMA_400 )
{
return PelUnitBuf( area.chromaFormat, getBuf( unit.Y(), type ) );
}
else
{
return PelUnitBuf( area.chromaFormat, getBuf( unit.Y(), type ), getBuf( unit.Cb(), type ), getBuf( unit.Cr(), type ) );
}
}
const CPelUnitBuf CodingStructure::getBuf( const UnitArea &unit, const PictureType &type ) const
{
// no parent fetching for buffers
if( area.chromaFormat == CHROMA_400 )
{
return CPelUnitBuf( area.chromaFormat, getBuf( unit.Y(), type ) );
}
else
{
return CPelUnitBuf( area.chromaFormat, getBuf( unit.Y(), type ), getBuf( unit.Cb(), type ), getBuf( unit.Cr(), type ) );
}
}
const CodingUnit* CodingStructure::getCURestricted( const Position &pos, const CodingUnit& curCu, const ChannelType _chType ) const
{
const CodingUnit* cu = getCU( pos, _chType );
#if HEVC_TILES_WPP
// exists same slice and tile cu precedes curCu in encoding order
// (thus, is either from parent CS in RD-search or its index is lower)
if( cu && CU::isSameSliceAndTile( *cu, curCu ) && ( cu->cs != curCu.cs || cu->idx <= curCu.idx ) )
#else
// exists same slice cu precedes curCu in encoding order
// (thus, is either from parent CS in RD-search or its index is lower)
if(cu && CU::isSameSlice(*cu, curCu) && (cu->cs != curCu.cs || cu->idx <= curCu.idx))
#endif
{
return cu;
}
else
{
return nullptr;
}
}
#if HEVC_TILES_WPP
const CodingUnit* CodingStructure::getCURestricted( const Position &pos, const unsigned curSliceIdx, const unsigned curTileIdx, const ChannelType _chType ) const
{
const CodingUnit* cu = getCU( pos, _chType );
return ( cu && cu->slice->getIndependentSliceIdx() == curSliceIdx && cu->tileIdx == curTileIdx ) ? cu : nullptr;
}
#else
const CodingUnit* CodingStructure::getCURestricted(const Position &pos, const unsigned curSliceIdx, const ChannelType _chType) const
{
const CodingUnit* cu = getCU(pos, _chType);
return (cu && cu->slice->getIndependentSliceIdx() == curSliceIdx ) ? cu : nullptr;
}
#endif
const PredictionUnit* CodingStructure::getPURestricted( const Position &pos, const PredictionUnit& curPu, const ChannelType _chType ) const
{
const PredictionUnit* pu = getPU( pos, _chType );
#if HEVC_TILES_WPP
// exists same slice and tile pu precedes curPu in encoding order
// (thus, is either from parent CS in RD-search or its index is lower)
if( pu && CU::isSameSliceAndTile( *pu->cu, *curPu.cu ) && ( pu->cs != curPu.cs || pu->idx <= curPu.idx ) )
#else
// exists same slice pu precedes curPu in encoding order
// (thus, is either from parent CS in RD-search or its index is lower)
if(pu && CU::isSameSlice(*pu->cu, *curPu.cu) && (pu->cs != curPu.cs || pu->idx <= curPu.idx))
#endif
{
return pu;
}
else
{
return nullptr;
}
}
const TransformUnit* CodingStructure::getTURestricted( const Position &pos, const TransformUnit& curTu, const ChannelType _chType ) const
{
const TransformUnit* tu = getTU( pos, _chType );
#if HEVC_TILES_WPP
// exists same slice and tile tu precedes curTu in encoding order
// (thus, is either from parent CS in RD-search or its index is lower)
if( tu && CU::isSameSliceAndTile( *tu->cu, *curTu.cu ) && ( tu->cs != curTu.cs || tu->idx <= curTu.idx ) )
#else
// exists same slice tu precedes curTu in encoding order
// (thus, is either from parent CS in RD-search or its index is lower)
if(tu && CU::isSameSlice(*tu->cu, *curTu.cu) && (tu->cs != curTu.cs || tu->idx <= curTu.idx))
#endif
{
return tu;
}
else
{
return nullptr;
}
}
IbcLumaCoverage CodingStructure::getIbcLumaCoverage(const CompArea& chromaArea) const
{
CHECK(chType != CHANNEL_TYPE_CHROMA, "Error");
const unsigned int unitAreaSubBlock = MIN_PU_SIZE * MIN_PU_SIZE;
CompArea lumaArea = CompArea(COMPONENT_Y, chromaArea.chromaFormat, chromaArea.lumaPos(), recalcSize(chromaArea.chromaFormat, CHANNEL_TYPE_CHROMA, CHANNEL_TYPE_LUMA, chromaArea.size()));
lumaArea = clipArea(lumaArea, picture->block(COMPONENT_Y));
const unsigned int fullArea = lumaArea.area();
for (SizeType y = 0; y < lumaArea.height; y += MIN_PU_SIZE)
{
for (SizeType x = 0; x < lumaArea.width; x += MIN_PU_SIZE)
{
Position pos = lumaArea.offset(x, y);
if (picture->cs->getMotionInfo(pos).isInter) // need to change if inter slice allows dualtree
{
IbcLumaCoverage coverage = IBC_LUMA_COVERAGE_FULL;
if (ibcArea == 0)