Newer
Older

Karsten Suehring
committed
3001
3002
3003
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
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
{
if( mi.refIdx[i] == -1 )
{
dest.mv[i] = Mv();
}
dest.refIdx[i] = mi.refIdx[i];
}
}
}
}
else
{
mb.fill( mi );
}
}
else if (pu.mergeType == MRG_TYPE_SUBPU_ATMVP)
{
CHECK(mrgCtx.subPuMvpMiBuf.area() == 0 || !mrgCtx.subPuMvpMiBuf.buf, "Buffer not initialized");
mb.copyFrom(mrgCtx.subPuMvpMiBuf);
}
else
{
if( isBipredRestriction( pu ) )
{
for( int y = 0; y < mb.height; y++ )
{
for( int x = 0; x < mb.width; x++ )
{
MotionInfo &mi = mb.at( x, y );
if( mi.interDir == 3 )
{
mi.interDir = 1;
mi.mv [1] = Mv();
mi.refIdx[1] = NOT_VALID;
}
}
}
}
}
}
void PU::applyImv( PredictionUnit& pu, MergeCtx &mrgCtx, InterPrediction *interPred )
{
if( !pu.mergeFlag )
{
if( pu.interDir != 2 /* PRED_L1 */ )
{
pu.mvd[0].changeTransPrecAmvr2Internal(pu.cu->imv);

Karsten Suehring
committed
unsigned mvp_idx = pu.mvpIdx[0];
AMVPInfo amvpInfo;

Karsten Suehring
committed
PU::fillMvpCand(pu, REF_PIC_LIST_0, pu.refIdx[0], amvpInfo);
pu.mvpNum[0] = amvpInfo.numCand;
pu.mvpIdx[0] = mvp_idx;
pu.mv [0] = amvpInfo.mvCand[mvp_idx] + pu.mvd[0];

Karsten Suehring
committed
}
if (pu.interDir != 1 /* PRED_L0 */)
{
if( !( pu.cu->cs->picHeader->getMvdL1ZeroFlag() && pu.interDir == 3 ) && pu.cu->imv )/* PRED_BI */

Karsten Suehring
committed
{
pu.mvd[1].changeTransPrecAmvr2Internal(pu.cu->imv);

Karsten Suehring
committed
}
unsigned mvp_idx = pu.mvpIdx[1];
AMVPInfo amvpInfo;
PU::fillMvpCand(pu, REF_PIC_LIST_1, pu.refIdx[1], amvpInfo);
pu.mvpNum[1] = amvpInfo.numCand;
pu.mvpIdx[1] = mvp_idx;
pu.mv [1] = amvpInfo.mvCand[mvp_idx] + pu.mvd[1];

Karsten Suehring
committed
}
}
else
{
// this function is never called for merge
THROW("unexpected");
PU::getInterMergeCandidates ( pu, mrgCtx

Karsten Suehring
committed
mrgCtx.setMergeInfo( pu, pu.mergeIdx );
}
PU::spanMotionInfo( pu, mrgCtx );
}
bool PU::isBiPredFromDifferentDirEqDistPoc(const PredictionUnit& pu)
{
if (pu.refIdx[0] >= 0 && pu.refIdx[1] >= 0)
{
if (pu.cu->slice->getRefPic(REF_PIC_LIST_0, pu.refIdx[0])->longTerm
|| pu.cu->slice->getRefPic(REF_PIC_LIST_1, pu.refIdx[1])->longTerm)
{
return false;
}
const int poc0 = pu.cu->slice->getRefPOC(REF_PIC_LIST_0, pu.refIdx[0]);
const int poc1 = pu.cu->slice->getRefPOC(REF_PIC_LIST_1, pu.refIdx[1]);
const int poc = pu.cu->slice->getPOC();
if ((poc - poc0)*(poc - poc1) < 0)
{
return true;
}
}
}
return false;
}

Karsten Suehring
committed
void PU::restrictBiPredMergeCandsOne(PredictionUnit &pu)
{
if (PU::isBipredRestriction(pu))
{
if (pu.interDir == 3)
{
pu.interDir = 1;
pu.refIdx[1] = -1;
pu.mv[1] = Mv(0, 0);
pu.cu->BcwIdx = BCW_DEFAULT;
void PU::getTriangleMergeCandidates( const PredictionUnit &pu, MergeCtx& triangleMrgCtx )
MergeCtx tmpMergeCtx;
const Slice &slice = *pu.cs->slice;
const uint32_t maxNumMergeCand = slice.getPicHeader()->getMaxNumMergeCand();
triangleMrgCtx.numValidMergeCand = 0;
for (int32_t i = 0; i < TRIANGLE_MAX_NUM_UNI_CANDS; i++)
{
triangleMrgCtx.BcwIdx[i] = BCW_DEFAULT;
triangleMrgCtx.interDirNeighbours[i] = 0;
triangleMrgCtx.mrgTypeNeighbours[i] = MRG_TYPE_DEFAULT_N;
triangleMrgCtx.mvFieldNeighbours[(i << 1)].refIdx = NOT_VALID;
triangleMrgCtx.mvFieldNeighbours[(i << 1) + 1].refIdx = NOT_VALID;
triangleMrgCtx.mvFieldNeighbours[(i << 1)].mv = Mv();
triangleMrgCtx.mvFieldNeighbours[(i << 1) + 1].mv = Mv();
triangleMrgCtx.useAltHpelIf[i] = false;
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
}
PU::getInterMergeCandidates(pu, tmpMergeCtx, 0);
for (int32_t i = 0; i < maxNumMergeCand; i++)
{
int parity = i & 1;
if (tmpMergeCtx.interDirNeighbours[i] & (0x01 + parity))
{
triangleMrgCtx.interDirNeighbours[triangleMrgCtx.numValidMergeCand] = 1 + parity;
triangleMrgCtx.mrgTypeNeighbours[triangleMrgCtx.numValidMergeCand] = MRG_TYPE_DEFAULT_N;
triangleMrgCtx.mvFieldNeighbours[(triangleMrgCtx.numValidMergeCand << 1) + !parity].mv = Mv(0, 0);
triangleMrgCtx.mvFieldNeighbours[(triangleMrgCtx.numValidMergeCand << 1) + parity].mv = tmpMergeCtx.mvFieldNeighbours[(i << 1) + parity].mv;
triangleMrgCtx.mvFieldNeighbours[(triangleMrgCtx.numValidMergeCand << 1) + !parity].refIdx = -1;
triangleMrgCtx.mvFieldNeighbours[(triangleMrgCtx.numValidMergeCand << 1) + parity].refIdx = tmpMergeCtx.mvFieldNeighbours[(i << 1) + parity].refIdx;
triangleMrgCtx.numValidMergeCand++;
if (triangleMrgCtx.numValidMergeCand == TRIANGLE_MAX_NUM_UNI_CANDS)
{
return;
}
continue;
}
if (tmpMergeCtx.interDirNeighbours[i] & (0x02 - parity))
{
triangleMrgCtx.interDirNeighbours[triangleMrgCtx.numValidMergeCand] = 2 - parity;
triangleMrgCtx.mrgTypeNeighbours[triangleMrgCtx.numValidMergeCand] = MRG_TYPE_DEFAULT_N;
triangleMrgCtx.mvFieldNeighbours[(triangleMrgCtx.numValidMergeCand << 1) + !parity].mv = tmpMergeCtx.mvFieldNeighbours[(i << 1) + !parity].mv;
triangleMrgCtx.mvFieldNeighbours[(triangleMrgCtx.numValidMergeCand << 1) + parity].mv = Mv(0, 0);
triangleMrgCtx.mvFieldNeighbours[(triangleMrgCtx.numValidMergeCand << 1) + !parity].refIdx = tmpMergeCtx.mvFieldNeighbours[(i << 1) + !parity].refIdx;
triangleMrgCtx.mvFieldNeighbours[(triangleMrgCtx.numValidMergeCand << 1) + parity].refIdx = -1;
triangleMrgCtx.numValidMergeCand++;
if (triangleMrgCtx.numValidMergeCand == TRIANGLE_MAX_NUM_UNI_CANDS)
{
return;
}
}
}
void PU::spanTriangleMotionInfo( PredictionUnit &pu, MergeCtx &triangleMrgCtx, const bool splitDir, const uint8_t candIdx0, const uint8_t candIdx1 )
pu.triangleSplitDir = splitDir;
pu.triangleMergeIdx0 = candIdx0;
pu.triangleMergeIdx1 = candIdx1;
MotionBuf mb = pu.getMotionBuf();
biMv.sliceIdx = pu.cs->slice->getIndependentSliceIdx();
if( triangleMrgCtx.interDirNeighbours[candIdx0] == 1 && triangleMrgCtx.interDirNeighbours[candIdx1] == 2 )
biMv.interDir = 3;
biMv.mv[0] = triangleMrgCtx.mvFieldNeighbours[ candIdx0 << 1 ].mv;
biMv.mv[1] = triangleMrgCtx.mvFieldNeighbours[(candIdx1 << 1) + 1].mv;
biMv.refIdx[0] = triangleMrgCtx.mvFieldNeighbours[ candIdx0 << 1 ].refIdx;
biMv.refIdx[1] = triangleMrgCtx.mvFieldNeighbours[(candIdx1 << 1) + 1].refIdx;
else if( triangleMrgCtx.interDirNeighbours[candIdx0] == 2 && triangleMrgCtx.interDirNeighbours[candIdx1] == 1 )
biMv.interDir = 3;
biMv.mv[0] = triangleMrgCtx.mvFieldNeighbours[ candIdx1 << 1 ].mv;
biMv.mv[1] = triangleMrgCtx.mvFieldNeighbours[(candIdx0 << 1) + 1].mv;
biMv.refIdx[0] = triangleMrgCtx.mvFieldNeighbours[ candIdx1 << 1 ].refIdx;
biMv.refIdx[1] = triangleMrgCtx.mvFieldNeighbours[(candIdx0 << 1) + 1].refIdx;
else if( triangleMrgCtx.interDirNeighbours[candIdx0] == 1 && triangleMrgCtx.interDirNeighbours[candIdx1] == 1 )
biMv.interDir = 1;
biMv.mv[0] = triangleMrgCtx.mvFieldNeighbours[candIdx1 << 1].mv;
biMv.mv[1] = Mv(0, 0);
biMv.refIdx[0] = triangleMrgCtx.mvFieldNeighbours[candIdx1 << 1].refIdx;
biMv.refIdx[1] = -1;
else if( triangleMrgCtx.interDirNeighbours[candIdx0] == 2 && triangleMrgCtx.interDirNeighbours[candIdx1] == 2 )
biMv.interDir = 2;
biMv.mv[0] = Mv(0, 0);
biMv.mv[1] = triangleMrgCtx.mvFieldNeighbours[(candIdx1 << 1) + 1].mv;
biMv.refIdx[0] = -1;
biMv.refIdx[1] = triangleMrgCtx.mvFieldNeighbours[(candIdx1 << 1) + 1].refIdx;
int32_t idxW = (int32_t)(floorLog2(pu.lwidth() ) - MIN_CU_LOG2);
int32_t idxH = (int32_t)(floorLog2(pu.lheight()) - MIN_CU_LOG2);
for( int32_t y = 0; y < mb.height; y++ )
{
for( int32_t x = 0; x < mb.width; x++ )
{
if( g_triangleMvStorage[splitDir][idxH][idxW][y][x] == 2 )
{
mb.at( x, y ).isInter = true;
mb.at( x, y ).interDir = biMv.interDir;
mb.at( x, y ).refIdx[0] = biMv.refIdx[0];
mb.at( x, y ).refIdx[1] = biMv.refIdx[1];
mb.at( x, y ).mv [0] = biMv.mv [0];
mb.at( x, y ).mv [1] = biMv.mv [1];
mb.at( x, y ).sliceIdx = biMv.sliceIdx;
else if( g_triangleMvStorage[splitDir][idxH][idxW][y][x] == 0 )
{
mb.at( x, y ).isInter = true;
mb.at( x, y ).interDir = triangleMrgCtx.interDirNeighbours[candIdx0];
mb.at( x, y ).refIdx[0] = triangleMrgCtx.mvFieldNeighbours[ candIdx0 << 1 ].refIdx;
mb.at( x, y ).refIdx[1] = triangleMrgCtx.mvFieldNeighbours[(candIdx0 << 1) + 1].refIdx;
mb.at( x, y ).mv [0] = triangleMrgCtx.mvFieldNeighbours[ candIdx0 << 1 ].mv;
mb.at( x, y ).mv [1] = triangleMrgCtx.mvFieldNeighbours[(candIdx0 << 1) + 1].mv;
mb.at( x, y ).sliceIdx = biMv.sliceIdx;
}
else
{
mb.at( x, y ).isInter = true;
mb.at( x, y ).interDir = triangleMrgCtx.interDirNeighbours[candIdx1];
mb.at( x, y ).refIdx[0] = triangleMrgCtx.mvFieldNeighbours[ candIdx1 << 1 ].refIdx;
mb.at( x, y ).refIdx[1] = triangleMrgCtx.mvFieldNeighbours[(candIdx1 << 1) + 1].refIdx;
mb.at( x, y ).mv [0] = triangleMrgCtx.mvFieldNeighbours[ candIdx1 << 1 ].mv;
mb.at( x, y ).mv [1] = triangleMrgCtx.mvFieldNeighbours[(candIdx1 << 1) + 1].mv;
mb.at( x, y ).sliceIdx = biMv.sliceIdx;
}
}
}
}
int32_t PU::mappingRefPic( const PredictionUnit &pu, int32_t refPicPoc, bool targetRefPicList )
{
int32_t numRefIdx = pu.cs->slice->getNumRefIdx( (RefPicList)targetRefPicList );
for( int32_t i = 0; i < numRefIdx; i++ )
{
if( pu.cs->slice->getRefPOC( (RefPicList)targetRefPicList, i ) == refPicPoc )
{
return i;
}
}
return -1;
}

Karsten Suehring
committed
bool CU::hasSubCUNonZeroMVd( const CodingUnit& cu )
{
bool bNonZeroMvd = false;
for( const auto &pu : CU::traversePUs( cu ) )
{
if( ( !pu.mergeFlag ) && ( !cu.skip ) )
{
if( pu.interDir != 2 /* PRED_L1 */ )
{
bNonZeroMvd |= pu.mvd[REF_PIC_LIST_0].getHor() != 0;
bNonZeroMvd |= pu.mvd[REF_PIC_LIST_0].getVer() != 0;
}
if( pu.interDir != 1 /* PRED_L0 */ )
{
if( !pu.cu->cs->picHeader->getMvdL1ZeroFlag() || pu.interDir != 3 /* PRED_BI */ )

Karsten Suehring
committed
{
bNonZeroMvd |= pu.mvd[REF_PIC_LIST_1].getHor() != 0;
bNonZeroMvd |= pu.mvd[REF_PIC_LIST_1].getVer() != 0;
}
}
}
}
return bNonZeroMvd;
}
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
bool CU::hasSubCUNonZeroAffineMVd( const CodingUnit& cu )
{
bool nonZeroAffineMvd = false;
if ( !cu.affine || cu.firstPU->mergeFlag )
{
return false;
}
for ( const auto &pu : CU::traversePUs( cu ) )
{
if ( ( !pu.mergeFlag ) && ( !cu.skip ) )
{
if ( pu.interDir != 2 /* PRED_L1 */ )
{
for ( int i = 0; i < ( cu.affineType == AFFINEMODEL_6PARAM ? 3 : 2 ); i++ )
{
nonZeroAffineMvd |= pu.mvdAffi[REF_PIC_LIST_0][i].getHor() != 0;
nonZeroAffineMvd |= pu.mvdAffi[REF_PIC_LIST_0][i].getVer() != 0;
}
}
if ( pu.interDir != 1 /* PRED_L0 */ )
{
if ( !pu.cu->cs->picHeader->getMvdL1ZeroFlag() || pu.interDir != 3 /* PRED_BI */ )
{
for ( int i = 0; i < ( cu.affineType == AFFINEMODEL_6PARAM ? 3 : 2 ); i++ )
{
nonZeroAffineMvd |= pu.mvdAffi[REF_PIC_LIST_1][i].getHor() != 0;
nonZeroAffineMvd |= pu.mvdAffi[REF_PIC_LIST_1][i].getVer() != 0;
}
}
}
}
}
return nonZeroAffineMvd;
}
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
3403
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
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
uint8_t CU::getSbtInfo( uint8_t idx, uint8_t pos )
{
return ( pos << 4 ) + ( idx << 0 );
}
uint8_t CU::getSbtIdx( const uint8_t sbtInfo )
{
return ( sbtInfo >> 0 ) & 0xf;
}
uint8_t CU::getSbtPos( const uint8_t sbtInfo )
{
return ( sbtInfo >> 4 ) & 0x3;
}
uint8_t CU::getSbtMode( uint8_t sbtIdx, uint8_t sbtPos )
{
uint8_t sbtMode = 0;
switch( sbtIdx )
{
case SBT_VER_HALF: sbtMode = sbtPos + SBT_VER_H0; break;
case SBT_HOR_HALF: sbtMode = sbtPos + SBT_HOR_H0; break;
case SBT_VER_QUAD: sbtMode = sbtPos + SBT_VER_Q0; break;
case SBT_HOR_QUAD: sbtMode = sbtPos + SBT_HOR_Q0; break;
default: assert( 0 );
}
assert( sbtMode < NUMBER_SBT_MODE );
return sbtMode;
}
uint8_t CU::getSbtIdxFromSbtMode( uint8_t sbtMode )
{
if( sbtMode <= SBT_VER_H1 )
return SBT_VER_HALF;
else if( sbtMode <= SBT_HOR_H1 )
return SBT_HOR_HALF;
else if( sbtMode <= SBT_VER_Q1 )
return SBT_VER_QUAD;
else if( sbtMode <= SBT_HOR_Q1 )
return SBT_HOR_QUAD;
else
{
assert( 0 );
return 0;
}
}
uint8_t CU::getSbtPosFromSbtMode( uint8_t sbtMode )
{
if( sbtMode <= SBT_VER_H1 )
return sbtMode - SBT_VER_H0;
else if( sbtMode <= SBT_HOR_H1 )
return sbtMode - SBT_HOR_H0;
else if( sbtMode <= SBT_VER_Q1 )
return sbtMode - SBT_VER_Q0;
else if( sbtMode <= SBT_HOR_Q1 )
return sbtMode - SBT_HOR_Q0;
else
{
assert( 0 );
return 0;
}
}
uint8_t CU::targetSbtAllowed( uint8_t sbtIdx, uint8_t sbtAllowed )
{
uint8_t val = 0;
switch( sbtIdx )
{
case SBT_VER_HALF: val = ( ( sbtAllowed >> SBT_VER_HALF ) & 0x1 ); break;
case SBT_HOR_HALF: val = ( ( sbtAllowed >> SBT_HOR_HALF ) & 0x1 ); break;
case SBT_VER_QUAD: val = ( ( sbtAllowed >> SBT_VER_QUAD ) & 0x1 ); break;
case SBT_HOR_QUAD: val = ( ( sbtAllowed >> SBT_HOR_QUAD ) & 0x1 ); break;
default: CHECK( 1, "unknown SBT type" );
}
return val;
}
uint8_t CU::numSbtModeRdo( uint8_t sbtAllowed )
{
uint8_t num = 0;
uint8_t sum = 0;
num = targetSbtAllowed( SBT_VER_HALF, sbtAllowed ) + targetSbtAllowed( SBT_HOR_HALF, sbtAllowed );
sum += std::min( SBT_NUM_RDO, ( num << 1 ) );
num = targetSbtAllowed( SBT_VER_QUAD, sbtAllowed ) + targetSbtAllowed( SBT_HOR_QUAD, sbtAllowed );
sum += std::min( SBT_NUM_RDO, ( num << 1 ) );
return sum;
}
bool CU::isSbtMode( const uint8_t sbtInfo )
{
uint8_t sbtIdx = getSbtIdx( sbtInfo );
return sbtIdx >= SBT_VER_HALF && sbtIdx <= SBT_HOR_QUAD;
}
bool CU::isSameSbtSize( const uint8_t sbtInfo1, const uint8_t sbtInfo2 )
{
uint8_t sbtIdx1 = getSbtIdxFromSbtMode( sbtInfo1 );
uint8_t sbtIdx2 = getSbtIdxFromSbtMode( sbtInfo2 );
if( sbtIdx1 == SBT_HOR_HALF || sbtIdx1 == SBT_VER_HALF )
return sbtIdx2 == SBT_HOR_HALF || sbtIdx2 == SBT_VER_HALF;
else if( sbtIdx1 == SBT_HOR_QUAD || sbtIdx1 == SBT_VER_QUAD )
return sbtIdx2 == SBT_HOR_QUAD || sbtIdx2 == SBT_VER_QUAD;
else
return false;
}
Adarsh Krishnan Ramasubramonian
committed
bool CU::isPredRegDiffFromTB(const CodingUnit &cu, const ComponentID compID)
{
return (compID == COMPONENT_Y)
&& (cu.ispMode == VER_INTRA_SUBPARTITIONS &&
CU::isMinWidthPredEnabledForBlkSize(cu.blocks[compID].width, cu.blocks[compID].height)
);
}
Adarsh Krishnan Ramasubramonian
committed
bool CU::isMinWidthPredEnabledForBlkSize(const int w, const int h)
{
return ((w == 8 && h > 4) || w == 4);
}
Adarsh Krishnan Ramasubramonian
committed
bool CU::isFirstTBInPredReg(const CodingUnit& cu, const ComponentID compID, const CompArea &area)
{
return (compID == COMPONENT_Y) && cu.ispMode && ((area.topLeft().x - cu.Y().topLeft().x) % PRED_REG_MIN_WIDTH == 0);
}
Adarsh Krishnan Ramasubramonian
committed
void CU::adjustPredArea(CompArea &area)
{
area.width = std::max<int>(PRED_REG_MIN_WIDTH, area.width);
}
bool CU::isBcwIdxCoded( const CodingUnit &cu )
if( cu.cs->sps->getUseBcw() == false )
CHECK(cu.BcwIdx != BCW_DEFAULT, "Error: cu.BcwIdx != BCW_DEFAULT");
if (cu.predMode == MODE_IBC)
{
return false;
}
if( cu.predMode == MODE_INTRA || cu.cs->slice->isInterP() )
{
return false;
}

Karsten Suehring
committed
if( cu.lwidth() * cu.lheight() < BCW_SIZE_CONSTRAINT )

Karsten Suehring
committed
if( !cu.firstPU->mergeFlag )
if( cu.firstPU->interDir == 3 )
{
WPScalingParam *wp0;
WPScalingParam *wp1;
int refIdx0 = cu.firstPU->refIdx[REF_PIC_LIST_0];
int refIdx1 = cu.firstPU->refIdx[REF_PIC_LIST_1];
cu.cs->slice->getWpScaling(REF_PIC_LIST_0, refIdx0, wp0);
cu.cs->slice->getWpScaling(REF_PIC_LIST_1, refIdx1, wp1);
if ((wp0[COMPONENT_Y].bPresentFlag || wp0[COMPONENT_Cb].bPresentFlag || wp0[COMPONENT_Cr].bPresentFlag
|| wp1[COMPONENT_Y].bPresentFlag || wp1[COMPONENT_Cb].bPresentFlag || wp1[COMPONENT_Cr].bPresentFlag))
{
return false;
}

Karsten Suehring
committed
uint8_t CU::getValidBcwIdx( const CodingUnit &cu )
{
if( cu.firstPU->interDir == 3 && !cu.firstPU->mergeFlag )
{
return cu.BcwIdx;
}
else if( cu.firstPU->interDir == 3 && cu.firstPU->mergeFlag && cu.firstPU->mergeType == MRG_TYPE_DEFAULT_N )
{
// This is intended to do nothing here.
}
else if( cu.firstPU->mergeFlag && cu.firstPU->mergeType == MRG_TYPE_SUBPU_ATMVP )
{
CHECK(cu.BcwIdx != BCW_DEFAULT, " cu.BcwIdx != BCW_DEFAULT ");
CHECK(cu.BcwIdx != BCW_DEFAULT, " cu.BcwIdx != BCW_DEFAULT ");
return BCW_DEFAULT;
void CU::setBcwIdx( CodingUnit &cu, uint8_t uh )
{
int8_t uhCnt = 0;
if( cu.firstPU->interDir == 3 && !cu.firstPU->mergeFlag )
{
++uhCnt;
}
else if( cu.firstPU->interDir == 3 && cu.firstPU->mergeFlag && cu.firstPU->mergeType == MRG_TYPE_DEFAULT_N )
{
// This is intended to do nothing here.
}
else if( cu.firstPU->mergeFlag && cu.firstPU->mergeType == MRG_TYPE_SUBPU_ATMVP )
{
cu.BcwIdx = BCW_DEFAULT;
cu.BcwIdx = BCW_DEFAULT;
}
CHECK(uhCnt <= 0, " uhCnt <= 0 ");
}
uint8_t CU::deriveBcwIdx( uint8_t bcwLO, uint8_t bcwL1 )
if( bcwLO == bcwL1 )
const int8_t w0 = getBcwWeight(bcwLO, REF_PIC_LIST_0);
const int8_t w1 = getBcwWeight(bcwL1, REF_PIC_LIST_1);
const int8_t th = g_BcwWeightBase >> 1;
const int8_t off = 1;
if( w0 == w1 || (w0 < (th - off) && w1 < (th - off)) || (w0 >(th + off) && w1 >(th + off)) )
{
return BCW_DEFAULT;
}
else
{
if( w0 > w1 )
{
return ( w0 >= th ? bcwLO : bcwL1 );
return ( w1 >= th ? bcwL1 : bcwLO );

Karsten Suehring
committed
bool CU::bdpcmAllowed( const CodingUnit& cu, const ComponentID compID )
{
SizeType transformSkipMaxSize = 1 << cu.cs->pps->getLog2MaxTransformSkipBlockSize();
bool bdpcmAllowed = cu.cs->sps->getBDPCMEnabled();
bdpcmAllowed &= (isLuma(compID) || cu.cs->sps->getBDPCMEnabled() == BDPCM_LUMACHROMA);
bdpcmAllowed &= CU::isIntra( cu );
if (isLuma(compID))
bdpcmAllowed &= (cu.lwidth() <= transformSkipMaxSize && cu.lheight() <= transformSkipMaxSize);
else
bdpcmAllowed &= (cu.chromaSize().width <= transformSkipMaxSize && cu.chromaSize().height <= transformSkipMaxSize);
bool CU::isMTSAllowed(const CodingUnit &cu, const ComponentID compID)
{
SizeType tsMaxSize = 1 << cu.cs->pps->getLog2MaxTransformSkipBlockSize();
const int maxSize = CU::isIntra( cu ) ? MTS_INTRA_MAX_CU_SIZE : MTS_INTER_MAX_CU_SIZE;
const int cuWidth = cu.blocks[0].lumaSize().width;
const int cuHeight = cu.blocks[0].lumaSize().height;
bool mtsAllowed = cu.chType == CHANNEL_TYPE_LUMA && compID == COMPONENT_Y;
mtsAllowed &= CU::isIntra( cu ) ? cu.cs->sps->getUseIntraMTS() : cu.cs->sps->getUseInterMTS() && CU::isInter( cu );
mtsAllowed &= cuWidth <= maxSize && cuHeight <= maxSize;
mtsAllowed &= !cu.ispMode;
mtsAllowed &= !cu.sbtInfo;
mtsAllowed &= !(cu.bdpcmMode && cuWidth <= tsMaxSize && cuHeight <= tsMaxSize);
return mtsAllowed;
}

Karsten Suehring
committed
// TU tools
bool TU::isNonTransformedResidualRotated(const TransformUnit &tu, const ComponentID &compID)
{
return tu.cs->sps->getSpsRangeExtension().getTransformSkipRotationEnabledFlag() && tu.blocks[compID].width == 4 && tu.cu->predMode == MODE_INTRA;
}
bool TU::getCbf( const TransformUnit &tu, const ComponentID &compID )
{
return getCbfAtDepth( tu, compID, tu.depth );
}
bool TU::getCbfAtDepth(const TransformUnit &tu, const ComponentID &compID, const unsigned &depth)
{
if( !tu.blocks[compID].valid() )
CHECK( tu.cbf[compID] != 0, "cbf must be 0 if the component is not available" );

Karsten Suehring
committed
return ((tu.cbf[compID] >> depth) & 1) == 1;
}
void TU::setCbfAtDepth(TransformUnit &tu, const ComponentID &compID, const unsigned &depth, const bool &cbf)
{
// first clear the CBF at the depth
tu.cbf[compID] &= ~(1 << depth);
// then set the CBF
tu.cbf[compID] |= ((cbf ? 1 : 0) << depth);
}
bool TU::isTSAllowed(const TransformUnit &tu, const ComponentID compID)
{
const int maxSize = tu.cs->pps->getLog2MaxTransformSkipBlockSize();
bool tsAllowed = tu.cs->sps->getTransformSkipEnabledFlag();
tsAllowed &= ( !tu.cu->ispMode || !isLuma(compID) );
SizeType transformSkipMaxSize = 1 << maxSize;
tsAllowed &= !(tu.cu->bdpcmMode && isLuma(compID));
tsAllowed &= !(tu.cu->bdpcmModeChroma && isChroma(compID));
tsAllowed &= tu.blocks[compID].width <= transformSkipMaxSize && tu.blocks[compID].height <= transformSkipMaxSize;
tsAllowed &= !tu.cu->sbtInfo;

Karsten Suehring
committed
int TU::getICTMode( const TransformUnit& tu, int jointCbCr )
{
if( jointCbCr < 0 )
{
jointCbCr = tu.jointCbCr;
}
return g_ictModes[ tu.cs->picHeader->getJointCbCrSignFlag() ][ jointCbCr ];

Karsten Suehring
committed
bool TU::hasCrossCompPredInfo( const TransformUnit &tu, const ComponentID &compID )
{
return (isChroma(compID) && tu.cs->pps->getPpsRangeExtension().getCrossComponentPredictionEnabledFlag() && TU::getCbf(tu, COMPONENT_Y) &&
(!CU::isIntra(*tu.cu) || PU::isChromaIntraModeCrossCheckMode(*tu.cs->getPU(tu.blocks[compID].pos(), toChannelType(compID)))));

Karsten Suehring
committed
}
bool TU::needsSqrt2Scale( const TransformUnit &tu, const ComponentID &compID )
{
const Size &size=tu.blocks[compID];
const bool isTransformSkip = (tu.mtsIdx[compID] == MTS_SKIP);
return (!isTransformSkip) && (((floorLog2(size.width) + floorLog2(size.height)) & 1) == 1);

Karsten Suehring
committed
bool TU::needsBlockSizeTrafoScale( const TransformUnit &tu, const ComponentID &compID )
{
return needsSqrt2Scale( tu, compID ) || isNonLog2BlockSize( tu.blocks[compID] );
}

Karsten Suehring
committed
TransformUnit* TU::getPrevTU( const TransformUnit &tu, const ComponentID compID )
{
TransformUnit* prevTU = tu.prev;

Karsten Suehring
committed
if( prevTU != nullptr && ( prevTU->cu != tu.cu || !prevTU->blocks[compID].valid() ) )
{
prevTU = nullptr;
}
return prevTU;
}
bool TU::getPrevTuCbfAtDepth( const TransformUnit ¤tTu, const ComponentID compID, const int trDepth )
{
const TransformUnit* prevTU = getPrevTU( currentTu, compID );
return ( prevTU != nullptr ) ? TU::getCbfAtDepth( *prevTU, compID, trDepth ) : false;
}

Karsten Suehring
committed
// other tools
uint32_t getCtuAddr( const Position& pos, const PreCalcValues& pcv )
{
return ( pos.x >> pcv.maxCUWidthLog2 ) + ( pos.y >> pcv.maxCUHeightLog2 ) * pcv.widthInCtus;
}
int getNumModesMip(const Size& block)
{
switch( getMipSizeId(block) )
{
case 0: return 16;
case 1: return 8;
case 2: return 6;
default: THROW( "Invalid mipSizeId" );
}
int getMipSizeId(const Size& block)
{
if( block.width == 4 && block.height == 4 )
{
return 0;
}
Philipp Merkle
committed
else if( block.width == 4 || block.height == 4 || (block.width == 8 && block.height == 8) )
{
return 1;
}
else
{
return 2;
}
}
bool allowLfnstWithMip(const Size& block)
{
if (block.width >= 16 && block.height >= 16)
{
return true;
}
return false;
}

Karsten Suehring
committed