Newer
Older

Karsten Suehring
committed
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
{
// copy motion buffer
MotionBuf ownMB = getMotionBuf();
CMotionBuf subMB = other.getMotionBuf();
ownMB.copyFrom( subMB );
motionLut = other.motionLut;

Karsten Suehring
committed
1029
1030
1031
1032
1033
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
}
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);
}
// 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 );
}

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
{
getMotionBuf() .memset( 0 );
}
fracBits = 0;
dist = 0;
cost = MAX_DOUBLE;
lumaCost = MAX_DOUBLE;

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
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
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
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 );
// 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)
const bool wavefrontsEnabled = curCu.slice->getPPS()->getEntropyCodingSyncEnabledFlag();
int ctuSizeBit = g_aucLog2[curCu.cs->sps->getMaxCUWidth()];
Tomohiro Ikai
committed
int xNbY = pos.x << getChannelTypeScaleX( _chType, curCu.chromaFormat );
int xCurr = curCu.blocks[_chType].x << getChannelTypeScaleX( _chType, curCu.chromaFormat );
bool addCheck = (wavefrontsEnabled && (xNbY >> ctuSizeBit) >= (xCurr >> ctuSizeBit) + 1 ) ? false : true;
if( cu && CU::isSameSliceAndTile( *cu, curCu ) && ( cu->cs != curCu.cs || cu->idx <= curCu.idx ) && addCheck)

Karsten Suehring
committed
{
return cu;
}
else
{
return nullptr;
}
}
const CodingUnit* CodingStructure::getCURestricted( const Position &pos, const Position curPos, const unsigned curSliceIdx, const unsigned curTileIdx, const ChannelType _chType ) const

Karsten Suehring
committed
{
const CodingUnit* cu = getCU( pos, _chType );
Tomohiro Ikai
committed
const bool wavefrontsEnabled = this->slice->getPPS()->getEntropyCodingSyncEnabledFlag();
int ctuSizeBit = g_aucLog2[this->sps->getMaxCUWidth()];
int xNbY = pos.x << getChannelTypeScaleX( _chType, this->area.chromaFormat );
int xCurr = curPos.x << getChannelTypeScaleX( _chType, this->area.chromaFormat );
bool addCheck = (wavefrontsEnabled && (xNbY >> ctuSizeBit) >= (xCurr >> ctuSizeBit) + 1 ) ? false : true;
return ( cu && cu->slice->getIndependentSliceIdx() == curSliceIdx && cu->tileIdx == curTileIdx && addCheck ) ? cu : nullptr;

Karsten Suehring
committed
}
const PredictionUnit* CodingStructure::getPURestricted( const Position &pos, const PredictionUnit& curPu, const ChannelType _chType ) const
{
const PredictionUnit* pu = getPU( pos, _chType );
// 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)
const bool wavefrontsEnabled = curPu.cu->slice->getPPS()->getEntropyCodingSyncEnabledFlag();
int ctuSizeBit = g_aucLog2[curPu.cs->sps->getMaxCUWidth()];
int xNbY = pos.x << getChannelTypeScaleX( _chType, curPu.chromaFormat );
int xCurr = curPu.blocks[_chType].x << getChannelTypeScaleX( _chType, curPu.chromaFormat );
bool addCheck = (wavefrontsEnabled && (xNbY >> ctuSizeBit) >= (xCurr >> ctuSizeBit) + 1 ) ? false : true;
if( pu && CU::isSameSliceAndTile( *pu->cu, *curPu.cu ) && ( pu->cs != curPu.cs || pu->idx <= curPu.idx ) && addCheck )

Karsten Suehring
committed
{
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 );
// 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)
const bool wavefrontsEnabled = curTu.cu->slice->getPPS()->getEntropyCodingSyncEnabledFlag();
int ctuSizeBit = g_aucLog2[curTu.cs->sps->getMaxCUWidth()];
int xNbY = pos.x << getChannelTypeScaleX( _chType, curTu.chromaFormat );
int xCurr = curTu.blocks[_chType].x << getChannelTypeScaleX( _chType, curTu.chromaFormat );
bool addCheck = (wavefrontsEnabled && (xNbY >> ctuSizeBit) >= (xCurr >> ctuSizeBit) + 1 ) ? false : true;
if( tu && CU::isSameSliceAndTile( *tu->cu, *curTu.cu ) && ( tu->cs != curTu.cs || tu->idx <= curTu.idx ) && addCheck )

Karsten Suehring
committed
{
return tu;
}
else
{
return nullptr;
}
}
#if !JVET_O0258_REMOVE_CHROMA_IBC_FOR_DUALTREE
IbcLumaCoverage CodingStructure::getIbcLumaCoverage(const CompArea& chromaArea) const
{
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)