From c5e67d8e3b2865887c253e69d8a69f81ee587e09 Mon Sep 17 00:00:00 2001 From: rlliao <ruling.liao@sg.panasonic.com> Date: Fri, 2 Nov 2018 21:02:20 +0800 Subject: [PATCH] rename variables and functions code optimization of triangle weighting process --- source/App/EncoderApp/EncAppCfg.cpp | 2 +- source/Lib/CommonLib/InterPrediction.cpp | 697 +++-------------------- source/Lib/CommonLib/InterPrediction.h | 10 +- source/Lib/CommonLib/Rom.cpp | 34 +- source/Lib/CommonLib/Rom.h | 14 +- source/Lib/CommonLib/UnitTools.cpp | 462 +++++++-------- source/Lib/CommonLib/UnitTools.h | 8 +- source/Lib/DecoderLib/DecCu.cpp | 12 +- source/Lib/DecoderLib/DecCu.h | 2 +- source/Lib/EncoderLib/EncCu.cpp | 131 +++-- source/Lib/EncoderLib/EncCu.h | 2 +- 11 files changed, 415 insertions(+), 959 deletions(-) diff --git a/source/App/EncoderApp/EncAppCfg.cpp b/source/App/EncoderApp/EncAppCfg.cpp index 14ea3f1e3..2e93ea509 100644 --- a/source/App/EncoderApp/EncAppCfg.cpp +++ b/source/App/EncoderApp/EncAppCfg.cpp @@ -870,7 +870,7 @@ bool EncAppCfg::parseCfg( int argc, char* argv[] ) ("MHIntra", m_MHIntra, false, "Enable MHIntra mode") #endif #if JVET_L0124_L0208_TRIANGLE - ("Triangle", m_Triangle, false, "Enable triangular shape motion vector prediction (0:off, 1:on) [default: on]") + ("Triangle", m_Triangle, false, "Enable triangular shape motion vector prediction (0:off, 1:on)") #endif // ADD_NEW_TOOL : (encoder app) add parsing parameters here diff --git a/source/Lib/CommonLib/InterPrediction.cpp b/source/Lib/CommonLib/InterPrediction.cpp index 410cf1eee..f39850696 100644 --- a/source/Lib/CommonLib/InterPrediction.cpp +++ b/source/Lib/CommonLib/InterPrediction.cpp @@ -121,7 +121,7 @@ void InterPrediction::destroy() } #if JVET_L0124_L0208_TRIANGLE - m_tmpTriangleBuf.destroy(); + m_triangleBuf.destroy(); #endif #if JVET_L0265_AFF_MINIMUM4X4 @@ -180,7 +180,7 @@ void InterPrediction::init( RdCost* pcRdCost, ChromaFormat chromaFormatIDC ) } #if JVET_L0124_L0208_TRIANGLE - m_tmpTriangleBuf.create(UnitArea(chromaFormatIDC, Area(0, 0, MAX_CU_SIZE, MAX_CU_SIZE))); + m_triangleBuf.create(UnitArea(chromaFormatIDC, Area(0, 0, MAX_CU_SIZE, MAX_CU_SIZE))); #endif m_iRefListIdx = -1; @@ -1178,660 +1178,113 @@ int InterPrediction::rightShiftMSB(int numer, int denom) #endif #if JVET_L0124_L0208_TRIANGLE -void InterPrediction::motionCompensation4Triangle( CodingUnit &cu, MergeCtx &TriangleMrgCtx, const bool SplitDir, const uint8_t CandIdx0, const uint8_t CandIdx1 ) +void InterPrediction::motionCompensation4Triangle( CodingUnit &cu, MergeCtx &triangleMrgCtx, const bool splitDir, const uint8_t candIdx0, const uint8_t candIdx1 ) { for( auto &pu : CU::traversePUs( cu ) ) { const UnitArea localUnitArea( cu.cs->area.chromaFormat, Area( 0, 0, pu.lwidth(), pu.lheight() ) ); - PelUnitBuf tmpTriangleBuf = m_tmpTriangleBuf.getBuf( localUnitArea ); + PelUnitBuf tmpTriangleBuf = m_triangleBuf.getBuf( localUnitArea ); PelUnitBuf predBuf = cu.cs->getPredBuf( pu ); - TriangleMrgCtx.setMergeInfo( pu, CandIdx0 ); + triangleMrgCtx.setMergeInfo( pu, candIdx0 ); PU::spanMotionInfo( pu ); motionCompensation( pu, tmpTriangleBuf ); - TriangleMrgCtx.setMergeInfo( pu, CandIdx1 ); + triangleMrgCtx.setMergeInfo( pu, candIdx1 ); PU::spanMotionInfo( pu ); motionCompensation( pu, predBuf ); - TriangleWeighting( pu, PU::isTriangleEhancedWeight(pu, TriangleMrgCtx, CandIdx0, CandIdx1), SplitDir, MAX_NUM_CHANNEL_TYPE, predBuf, tmpTriangleBuf, predBuf ); + weightedTriangleBlk( pu, PU::getTriangleWeights(pu, triangleMrgCtx, candIdx0, candIdx1), splitDir, MAX_NUM_CHANNEL_TYPE, predBuf, tmpTriangleBuf, predBuf ); } } -void InterPrediction::TriangleWeighting( PredictionUnit &pu, bool ehanced, const bool SplitDir, int32_t channel, PelUnitBuf& PredDst, PelUnitBuf& PredSrc0, PelUnitBuf& PredSrc1 ) +void InterPrediction::weightedTriangleBlk( PredictionUnit &pu, bool weights, const bool splitDir, int32_t channel, PelUnitBuf& predDst, PelUnitBuf& predSrc0, PelUnitBuf& predSrc1 ) { - const uint32_t WidthY = pu.lumaSize() .width; - const uint32_t HeightY = pu.lumaSize() .height; - const uint32_t WidthUV = pu.chromaSize().width; - const uint32_t HeightUV = pu.chromaSize().height; - - Pel* DstY = PredDst .get(COMPONENT_Y).buf; - Pel* Src0Y = PredSrc0.get(COMPONENT_Y).buf; - Pel* Src1Y = PredSrc1.get(COMPONENT_Y).buf; - Pel* DstU = PredDst .get(COMPONENT_Cb).buf; - Pel* Src0U = PredSrc0.get(COMPONENT_Cb).buf; - Pel* Src1U = PredSrc1.get(COMPONENT_Cb).buf; - Pel* DstV = PredDst .get(COMPONENT_Cr).buf; - Pel* Src0V = PredSrc0.get(COMPONENT_Cr).buf; - Pel* Src1V = PredSrc1.get(COMPONENT_Cr).buf; - - int strideY = PredDst .get(COMPONENT_Y).stride - WidthY; - int stride0Y = PredSrc0.get(COMPONENT_Y).stride - WidthY; - int stride1Y = PredSrc1.get(COMPONENT_Y).stride - WidthY; - int strideU = PredDst .get(COMPONENT_Cb).stride - WidthUV; - int stride0U = PredSrc0.get(COMPONENT_Cb).stride - WidthUV; - int stride1U = PredSrc1.get(COMPONENT_Cb).stride - WidthUV; - - const bool format = PredDst.chromaFormat == CHROMA_444 ? 0 : 1; - - const int32_t BlendLengthY = g_TriangleWeightLengthLuma[ehanced]; - const int32_t BlendLengthUV = g_TriangleWeightLengthChroma[format][ehanced]; - - const char log2WeightBase = 3; - const ClpRng clipRngY = pu.cu->slice->clpRngs().comp[0]; - const ClpRng clipRngU = pu.cu->slice->clpRngs().comp[1]; - const ClpRng clipRngV = pu.cu->slice->clpRngs().comp[2]; - const int clipbdY = clipRngY.bd; - const int clipbdU = clipRngU.bd; - const int clipbdV = clipRngV.bd; - const int shiftNumY = std::max<int>(2, (IF_INTERNAL_PREC - clipbdY)) + log2WeightBase; - const int offsetY = (1 << (shiftNumY - 1)) + (IF_INTERNAL_OFFS << log2WeightBase); - const int shiftNumU = std::max<int>(2, (IF_INTERNAL_PREC - clipbdU)) + log2WeightBase; - const int offsetU = (1 << (shiftNumU - 1)) + (IF_INTERNAL_OFFS << log2WeightBase); - const int shiftNumV = std::max<int>(2, (IF_INTERNAL_PREC - clipbdV)) + log2WeightBase; - const int offsetV = (1 << (shiftNumV - 1)) + (IF_INTERNAL_OFFS << log2WeightBase); - - const int shiftDefault = std::max<int>(2, (IF_INTERNAL_PREC - clipbdY)); - const int offsetDefault = (1<<(shiftDefault-1)) + IF_INTERNAL_OFFS; - - const Pel* TmpPelWeighted; - - if( channel == CHANNEL_TYPE_LUMA || channel == MAX_NUM_CHANNEL_TYPE ) + if( channel == CHANNEL_TYPE_LUMA ) { - if( SplitDir == TRIANGLE_DIR_135 && WidthY == HeightY ) - { - int32_t BlendStart = 0 - (BlendLengthY >> 1); - int32_t BlendEnd = 0 + (BlendLengthY >> 1); - for( int32_t y = 0; y < HeightY; y++ ) - { - int32_t x = 0; - for( x = 0; x < BlendStart; x++ ) - { - *DstY++ = ClipPel( rightShift( *Src1Y++ + offsetDefault, shiftDefault ), clipRngY ); - } - Src0Y += x; - - int32_t TmpBlendStart = std::max( (int32_t)0, BlendStart ); - int32_t TmpBlendEnd = std::min( BlendEnd, (int32_t)(WidthY - 1) ); - TmpPelWeighted = g_TrianglePelWeightedLuma[SplitDir][ehanced]; - if( BlendStart < 0 ) - { - TmpPelWeighted += abs( BlendStart ); - } - for( x = TmpBlendStart; x <= TmpBlendEnd; x++ ) - { - *DstY++ = ClipPel( rightShift( ((*TmpPelWeighted)*(*Src0Y++) + ((8 - (*TmpPelWeighted)) * (*Src1Y++)) + offsetY), shiftNumY ), clipRngY ); - TmpPelWeighted++; - } - - for( x = BlendEnd + 1; x < WidthY; x++ ) - { - *DstY++ = ClipPel( rightShift( *Src0Y++ + offsetDefault, shiftDefault ), clipRngY ); - Src1Y++; - } - - BlendStart++; - BlendEnd++; - - DstY += strideY; - Src0Y += stride0Y; - Src1Y += stride1Y; - } - } - else if( SplitDir == TRIANGLE_DIR_135 && WidthY > HeightY ) - { - int32_t RatioWH = WidthY / HeightY; - int32_t BlendStart = 0 - (BlendLengthY >> 1) * RatioWH; - int32_t BlendEnd = BlendStart + BlendLengthY * RatioWH - 1; - for( int32_t y = 0; y < HeightY; y++ ) - { - int32_t x = 0; - for( x = 0; x < BlendStart; x++ ) - { - *DstY++ = ClipPel( rightShift( *Src1Y++ + offsetDefault, shiftDefault ), clipRngY ); - } - Src0Y += x; - - int32_t TmpBlendStart = std::max((int32_t)0, BlendStart); - int32_t TmpBlendEnd = std::min(BlendEnd, (int32_t)(WidthY - 1) ); - TmpPelWeighted = g_TrianglePelWeightedLuma[SplitDir][ehanced]; - if( BlendStart < 0 ) - { - TmpPelWeighted += abs(BlendStart) / RatioWH; - } - for( x = TmpBlendStart; x <= TmpBlendEnd; x += RatioWH ) - { - for( int32_t Cnt = 0; Cnt < RatioWH; Cnt++ ) - { - *DstY++ = ClipPel( rightShift( ((*TmpPelWeighted)*(*Src0Y++) + ((8 - (*TmpPelWeighted)) * (*Src1Y++)) + offsetY), shiftNumY ), clipRngY ); - } - TmpPelWeighted++; - } - - for( x = BlendEnd + 1; x < WidthY; x++ ) - { - *DstY++ = ClipPel( rightShift( *Src0Y++ + offsetDefault, shiftDefault ), clipRngY ); - Src1Y++; - } - - BlendStart += RatioWH; - BlendEnd += RatioWH; - - DstY += strideY; - Src0Y += stride0Y; - Src1Y += stride1Y; - } - } - else if( SplitDir == TRIANGLE_DIR_135 && WidthY < HeightY ) - { - int32_t RatioHW = HeightY / WidthY; - int32_t BlendStart = 0 - (BlendLengthY >> 1); - int32_t BlendEnd = BlendStart + BlendLengthY - 1; - int32_t Cnt = RatioHW; - for( int32_t y = 0; y < HeightY; y++ ) - { - int32_t x = 0; - for( x = 0; x < BlendStart; x++ ) - { - *DstY++ = ClipPel( rightShift( *Src1Y++ + offsetDefault, shiftDefault ), clipRngY ); - } - Src0Y += x; - - int32_t TmpBlendStart = std::max((int32_t)0, BlendStart); - int32_t TmpBlendEnd = std::min(BlendEnd, (int32_t)(WidthY - 1)); - TmpPelWeighted = g_TrianglePelWeightedLuma[SplitDir][ehanced]; - if( BlendStart < 0 ) - { - TmpPelWeighted += abs(BlendStart); - } - for( x = TmpBlendStart; x <= TmpBlendEnd; x++ ) - { - *DstY++ = ClipPel( rightShift( ((*TmpPelWeighted)*(*Src0Y++) + ((8 - (*TmpPelWeighted)) * (*Src1Y++)) + offsetY), shiftNumY ), clipRngY ); - TmpPelWeighted++; - } - - for( x = BlendEnd + 1; x < WidthY; x++ ) - { - *DstY++ = ClipPel( rightShift( *Src0Y++ + offsetDefault, shiftDefault ), clipRngY ); - Src1Y++; - } - - Cnt--; - if( Cnt <= 0 ) - { - BlendStart++; - BlendEnd++; - Cnt = RatioHW; - } - - DstY += strideY; - Src0Y += stride0Y; - Src1Y += stride1Y; - } - } - else if( SplitDir == TRIANGLE_DIR_45 && WidthY == HeightY ) - { - int32_t BlendStart = (WidthY - 1) - (BlendLengthY >> 1); - int32_t BlendEnd = (WidthY - 1) + (BlendLengthY >> 1); - for( int32_t y = 0; y < HeightY; y++ ) - { - int32_t x = 0; - for( x = 0; x < BlendStart; x++ ) - { - *DstY++ = ClipPel( rightShift( *Src0Y++ + offsetDefault, shiftDefault ), clipRngY ); - } - Src1Y += x; - - int32_t TmpBlendStart = std::max((int32_t)0, BlendStart); - int32_t TmpBlendEnd = std::min(BlendEnd, (int32_t)(WidthY - 1)); - TmpPelWeighted = g_TrianglePelWeightedLuma[SplitDir][ehanced]; - if( BlendStart < 0 ) - { - TmpPelWeighted += abs(BlendStart); - } - for( x = TmpBlendStart; x <= TmpBlendEnd; x++ ) - { - *DstY++ = ClipPel( rightShift( ((*TmpPelWeighted)*(*Src0Y++) + ((8 - (*TmpPelWeighted)) * (*Src1Y++)) + offsetY), shiftNumY ), clipRngY ); - TmpPelWeighted++; - } - - for( x = BlendEnd + 1; x < WidthY; x++ ) - { - *DstY++ = ClipPel( rightShift( *Src1Y++ + offsetDefault, shiftDefault ), clipRngY ); - Src0Y++; - } - - BlendStart--; - BlendEnd--; - - DstY += strideY; - Src0Y += stride0Y; - Src1Y += stride1Y; - } - } - else if( SplitDir == TRIANGLE_DIR_45 && WidthY > HeightY ) - { - int32_t RatioWH = WidthY / HeightY; - int32_t BlendStart = WidthY - ((BlendLengthY + 1) >> 1) * RatioWH; - int32_t BlendEnd = BlendStart + BlendLengthY * RatioWH - 1; - for( int32_t y = 0; y < HeightY; y++ ) - { - int32_t x = 0; - for( x = 0; x < BlendStart; x++ ) - { - *DstY++ = ClipPel( rightShift( *Src0Y++ + offsetDefault, shiftDefault ), clipRngY ); - } - Src1Y += x; - - int32_t TmpBlendStart = std::max((int32_t)0, BlendStart); - int32_t TmpBlendEnd = std::min(BlendEnd, (int32_t)(WidthY - 1)); - TmpPelWeighted = g_TrianglePelWeightedLuma[SplitDir][ehanced]; - if( BlendStart < 0 ) - { - TmpPelWeighted += abs(BlendStart) / RatioWH; - } - for( x = TmpBlendStart; x <= TmpBlendEnd; x += RatioWH ) - { - for( int32_t Cnt = 0; Cnt < RatioWH; Cnt++ ) - { - *DstY++ = ClipPel( rightShift( ((*TmpPelWeighted)*(*Src0Y++) + ((8 - (*TmpPelWeighted)) * (*Src1Y++)) + offsetY), shiftNumY ), clipRngY ); - } - TmpPelWeighted++; - } - - for( x = BlendEnd + 1; x < WidthY; x++ ) - { - *DstY++ = ClipPel( rightShift( *Src1Y++ + offsetDefault, shiftDefault ), clipRngY ); - Src0Y++; - } - - BlendStart -= RatioWH; - BlendEnd -= RatioWH; - - DstY += strideY; - Src0Y += stride0Y; - Src1Y += stride1Y; - } - } - else if( SplitDir == TRIANGLE_DIR_45 && WidthY < HeightY ) - { - int32_t RatioHW = HeightY / WidthY; - int32_t BlendStart = WidthY - ((BlendLengthY + 1) >> 1); - int32_t BlendEnd = BlendStart + BlendLengthY - 1; - int32_t Cnt = RatioHW; - for( int32_t y = 0; y < HeightY; y++ ) - { - int32_t x = 0; - for( x = 0; x < BlendStart; x++ ) - { - *DstY++ = ClipPel( rightShift( *Src0Y++ + offsetDefault, shiftDefault ), clipRngY ); - } - Src1Y += x; - - int32_t TmpBlendStart = std::max((int32_t)0, BlendStart); - int32_t TmpBlendEnd = std::min(BlendEnd, (int32_t)(WidthY - 1)); - TmpPelWeighted = g_TrianglePelWeightedLuma[SplitDir][ehanced]; - if( BlendStart < 0 ) - { - TmpPelWeighted += abs(BlendStart); - } - for( x = TmpBlendStart; x <= TmpBlendEnd; x++ ) - { - *DstY++ = ClipPel( rightShift( ((*TmpPelWeighted)*(*Src0Y++) + ((8 - (*TmpPelWeighted)) * (*Src1Y++)) + offsetY), shiftNumY ), clipRngY ); - TmpPelWeighted++; - } - - for( x = BlendEnd + 1; x < WidthY; x++ ) - { - *DstY++ = ClipPel( rightShift( *Src1Y++ + offsetDefault, shiftDefault ), clipRngY ); - Src0Y++; - } - - Cnt--; - if( Cnt <= 0 ) - { - BlendStart--; - BlendEnd--; - Cnt = RatioHW; - } - - DstY += strideY; - Src0Y += stride0Y; - Src1Y += stride1Y; - } - } - else - { - assert(0); - } + xWeightedTriangleBlk( pu, pu.lumaSize().width, pu.lumaSize().height, COMPONENT_Y, splitDir, weights, predDst, predSrc0, predSrc1 ); } + else if( channel == CHANNEL_TYPE_CHROMA ) + { + xWeightedTriangleBlk( pu, pu.chromaSize().width, pu.chromaSize().height, COMPONENT_Cb, splitDir, weights, predDst, predSrc0, predSrc1 ); + xWeightedTriangleBlk( pu, pu.chromaSize().width, pu.chromaSize().height, COMPONENT_Cr, splitDir, weights, predDst, predSrc0, predSrc1 ); + } + else + { + xWeightedTriangleBlk( pu, pu.lumaSize().width, pu.lumaSize().height, COMPONENT_Y, splitDir, weights, predDst, predSrc0, predSrc1 ); + xWeightedTriangleBlk( pu, pu.chromaSize().width, pu.chromaSize().height, COMPONENT_Cb, splitDir, weights, predDst, predSrc0, predSrc1 ); + xWeightedTriangleBlk( pu, pu.chromaSize().width, pu.chromaSize().height, COMPONENT_Cr, splitDir, weights, predDst, predSrc0, predSrc1 ); + } +} - if( channel == CHANNEL_TYPE_CHROMA || channel == MAX_NUM_CHANNEL_TYPE ) +void InterPrediction::xWeightedTriangleBlk( const PredictionUnit &pu, const uint32_t width, const uint32_t height, const ComponentID compIdx, const bool splitDir, const bool weights, PelUnitBuf& predDst, PelUnitBuf& predSrc0, PelUnitBuf& predSrc1 ) +{ + Pel* dst = predDst .get(compIdx).buf; + Pel* src0 = predSrc0.get(compIdx).buf; + Pel* src1 = predSrc1.get(compIdx).buf; + int32_t strideDst = predDst .get(compIdx).stride - width; + int32_t strideSrc0 = predSrc0.get(compIdx).stride - width; + int32_t strideSrc1 = predSrc1.get(compIdx).stride - width; + + const char log2WeightBase = 3; + const ClpRng clipRng = pu.cu->slice->clpRngs().comp[compIdx]; + const int32_t clipbd = clipRng.bd; + const int32_t shiftDefault = std::max<int>(2, (IF_INTERNAL_PREC - clipbd)); + const int32_t offsetDefault = (1<<(shiftDefault-1)) + IF_INTERNAL_OFFS; + const int32_t shiftWeighted = std::max<int>(2, (IF_INTERNAL_PREC - clipbd)) + log2WeightBase; + const int32_t offsetWeighted = (1 << (shiftWeighted - 1)) + (IF_INTERNAL_OFFS << log2WeightBase); + + const int32_t ratioWH = (width > height) ? (width / height) : 1; + const int32_t ratioHW = (width > height) ? 1 : (height / width); + const Pel* pelWeighted = (compIdx == COMPONENT_Y) ? g_trianglePelWeightedLuma[splitDir][weights] : g_trianglePelWeightedChroma[predDst.chromaFormat == CHROMA_444 ? 0 : 1][splitDir][weights]; + const int32_t weightedLength = (compIdx == COMPONENT_Y) ? g_triangleWeightLengthLuma[weights] : g_triangleWeightLengthChroma[predDst.chromaFormat == CHROMA_444 ? 0 : 1][weights]; + int32_t weightedStartPos = ( splitDir == 0 ) ? ( 0 - (weightedLength >> 1) * ratioWH ) : ( width - ((weightedLength + 1) >> 1) * ratioWH ); + int32_t weightedEndPos = weightedStartPos + weightedLength * ratioWH - 1; + int32_t weightedPosoffset =( splitDir == 0 ) ? ratioWH : -ratioWH; + + const Pel* tmpPelWeighted; + int32_t x, y, tmpX, tmpY, tmpWeightedStart, tmpWeightedEnd; + + for( y = 0; y < height; y+= ratioHW ) { - if( SplitDir == TRIANGLE_DIR_135 && WidthY == HeightY ) + for( tmpY = ratioHW; tmpY > 0; tmpY-- ) { - int32_t BlendStart = 0 - (BlendLengthUV >> 1); - int32_t BlendEnd = 0 + (BlendLengthUV >> 1); - for( int32_t y = 0; y < HeightUV; y++ ) + for( x = 0; x < weightedStartPos; x++ ) { - int x = 0; - for( x = 0; x < BlendStart; x++ ) - { - *DstU++ = ClipPel( rightShift( *Src1U++ + offsetDefault, shiftDefault ), clipRngU ); - *DstV++ = ClipPel( rightShift( *Src1V++ + offsetDefault, shiftDefault ), clipRngV ); - } - Src0U += x; - Src0V += x; - - int32_t TmpBlendStart = std::max((int32_t)0, BlendStart); - int32_t TmpBlendEnd = std::min(BlendEnd, (int32_t)(WidthUV - 1)); - TmpPelWeighted = g_TrianglePelWeightedChroma[format][SplitDir][ehanced]; - if( BlendStart < 0 ) - { - TmpPelWeighted += abs(BlendStart); - } - for( x = TmpBlendStart; x <= TmpBlendEnd; x++ ) - { - *DstU++ = ClipPel( rightShift( ((*TmpPelWeighted)*(*Src0U++) + ((8 - (*TmpPelWeighted)) * (*Src1U++)) + offsetU), shiftNumU ), clipRngU ); - *DstV++ = ClipPel( rightShift( ((*TmpPelWeighted)*(*Src0V++) + ((8 - (*TmpPelWeighted)) * (*Src1V++)) + offsetV), shiftNumV ), clipRngV ); - TmpPelWeighted++; - } - - for( x = BlendEnd + 1; x < WidthUV; x++ ) - { - *DstU++ = ClipPel( rightShift( *Src0U++ + offsetDefault, shiftDefault ), clipRngU ); - *DstV++ = ClipPel( rightShift( *Src0V++ + offsetDefault, shiftDefault ), clipRngV ); - Src1U++; - Src1V++; - } - - BlendStart++; - BlendEnd++; - - DstU += strideU; - Src0U += stride0U; - Src1U += stride1U; - DstV += strideU; - Src0V += stride0U; - Src1V += stride1U; + *dst++ = ClipPel( rightShift( (splitDir == 0 ? *src1 : *src0) + offsetDefault, shiftDefault), clipRng ); + src0++; + src1++; } - } - else if( SplitDir == TRIANGLE_DIR_135 && WidthY > HeightY ) - { - int32_t RatioWH = WidthY / HeightY; - int32_t BlendStart = 0 - (BlendLengthUV >> 1) * RatioWH; - int32_t BlendEnd = BlendStart + BlendLengthUV * RatioWH - 1; - for( int32_t y = 0; y < HeightUV; y++ ) - { - int32_t x = 0; - for( x = 0; x < BlendStart; x++ ) - { - *DstU++ = ClipPel( rightShift( *Src1U++ + offsetDefault, shiftDefault ), clipRngU ); - *DstV++ = ClipPel( rightShift( *Src1V++ + offsetDefault, shiftDefault ), clipRngV ); - } - Src0U += x; - Src0V += x; - int32_t TmpBlendStart = std::max((int32_t)0, BlendStart); - int32_t TmpBlendEnd = std::min(BlendEnd, (int32_t)(WidthUV - 1)); - TmpPelWeighted = g_TrianglePelWeightedChroma[format][SplitDir][ehanced]; - if( BlendStart < 0 ) - { - TmpPelWeighted += abs(BlendStart) / RatioWH; - } - for( x = TmpBlendStart; x <= TmpBlendEnd; x += RatioWH ) - { - for( int32_t Cnt = 0; Cnt < RatioWH; Cnt++ ) - { - *DstU++ = ClipPel( rightShift( ((*TmpPelWeighted)*(*Src0U++) + ((8 - (*TmpPelWeighted)) * (*Src1U++)) + offsetU), shiftNumU ), clipRngU ); - *DstV++ = ClipPel( rightShift( ((*TmpPelWeighted)*(*Src0V++) + ((8 - (*TmpPelWeighted)) * (*Src1V++)) + offsetV), shiftNumV ), clipRngV ); - } - TmpPelWeighted++; - } - - for( x = BlendEnd + 1; x < WidthUV; x++ ) - { - *DstU++ = ClipPel( rightShift( *Src0U++ + offsetDefault, shiftDefault ), clipRngU ); - *DstV++ = ClipPel( rightShift( *Src0V++ + offsetDefault, shiftDefault ), clipRngV ); - Src1U++; - Src1V++; - } - - BlendStart += RatioWH; - BlendEnd += RatioWH; - - DstU += strideU; - Src0U += stride0U; - Src1U += stride1U; - DstV += strideU; - Src0V += stride0U; - Src1V += stride1U; - } - } - else if( SplitDir == TRIANGLE_DIR_135 && WidthY < HeightY ) - { - int32_t RatioHW = HeightY / WidthY; - int32_t Cnt = RatioHW; - int32_t BlendStart = 0 - (BlendLengthUV >> 1); - int32_t BlendEnd = BlendStart + BlendLengthUV - 1; - for( int32_t y = 0; y < HeightUV; y++ ) + tmpWeightedStart = std::max((int32_t)0, weightedStartPos); + tmpWeightedEnd = std::min(weightedEndPos, (int32_t)(width - 1)); + tmpPelWeighted = pelWeighted; + if( weightedStartPos < 0 ) { - int32_t x = 0; - for( x = 0; x < BlendStart; x++ ) - { - *DstU++ = ClipPel( rightShift( *Src1U++ + offsetDefault, shiftDefault ), clipRngU ); - *DstV++ = ClipPel( rightShift( *Src1V++ + offsetDefault, shiftDefault ), clipRngV ); - } - Src0U += x; - Src0V += x; - - int32_t TmpBlendStart = std::max((int32_t)0, BlendStart); - int32_t TmpBlendEnd = std::min(BlendEnd, (int32_t)(WidthUV - 1)); - TmpPelWeighted = g_TrianglePelWeightedChroma[format][SplitDir][ehanced]; - if( BlendStart < 0 ) - { - TmpPelWeighted += abs(BlendStart); - } - for( x = TmpBlendStart; x <= TmpBlendEnd; x++ ) - { - *DstU++ = ClipPel( rightShift( ((*TmpPelWeighted)*(*Src0U++) + ((8 - (*TmpPelWeighted)) * (*Src1U++)) + offsetU), shiftNumU ), clipRngU ); - *DstV++ = ClipPel( rightShift( ((*TmpPelWeighted)*(*Src0V++) + ((8 - (*TmpPelWeighted)) * (*Src1V++)) + offsetV), shiftNumV ), clipRngV ); - TmpPelWeighted++; - } - - for( x = BlendEnd + 1; x < WidthUV; x++ ) - { - *DstU++ = ClipPel( rightShift( *Src0U++ + offsetDefault, shiftDefault ), clipRngU ); - *DstV++ = ClipPel( rightShift( *Src0V++ + offsetDefault, shiftDefault ), clipRngV ); - Src1U++; - Src1V++; - } - - Cnt--; - if( Cnt <= 0 ) - { - BlendStart++; - BlendEnd++; - Cnt = RatioHW; - } - - DstU += strideU; - Src0U += stride0U; - Src1U += stride1U; - DstV += strideU; - Src0V += stride0U; - Src1V += stride1U; + tmpPelWeighted += abs(weightedStartPos) / ratioWH; } - } - else if( SplitDir == TRIANGLE_DIR_45 && WidthY == HeightY ) - { - int32_t BlendStart = (WidthUV - 1) - (BlendLengthUV >> 1); - int32_t BlendEnd = (WidthUV - 1) + (BlendLengthUV >> 1); - for( int32_t y = 0; y < HeightUV; y++ ) + for( x = tmpWeightedStart; x <= tmpWeightedEnd; x+= ratioWH ) { - int32_t x = 0; - for( x = 0; x < BlendStart; x++ ) - { - *DstU++ = ClipPel( rightShift( *Src0U++ + offsetDefault, shiftDefault ), clipRngU ); - *DstV++ = ClipPel( rightShift( *Src0V++ + offsetDefault, shiftDefault ), clipRngV ); - } - Src1U += x; - Src1V += x; - - int32_t TmpBlendStart = std::max((int32_t)0, BlendStart); - int32_t TmpBlendEnd = std::min(BlendEnd, (int32_t)(WidthUV - 1)); - TmpPelWeighted = g_TrianglePelWeightedChroma[format][SplitDir][ehanced]; - if( BlendStart < 0 ) - { - TmpPelWeighted += abs(BlendStart); - } - for( x = TmpBlendStart; x <= TmpBlendEnd; x++ ) - { - *DstU++ = ClipPel( rightShift(((*TmpPelWeighted)*(*Src0U++) + ((8 - (*TmpPelWeighted)) * (*Src1U++)) + offsetU), shiftNumU ), clipRngU ); - *DstV++ = ClipPel( rightShift(((*TmpPelWeighted)*(*Src0V++) + ((8 - (*TmpPelWeighted)) * (*Src1V++)) + offsetV), shiftNumV ), clipRngV ); - TmpPelWeighted++; - } - - for( x = BlendEnd + 1; x < WidthUV; x++ ) + for( tmpX = ratioWH; tmpX > 0; tmpX-- ) { - *DstU++ = ClipPel( rightShift( *Src1U++ + offsetDefault, shiftDefault ), clipRngU ); - *DstV++ = ClipPel( rightShift( *Src1V++ + offsetDefault, shiftDefault ), clipRngV ); - Src0U++; - Src0V++; + *dst++ = ClipPel( rightShift( ((*tmpPelWeighted)*(*src0++) + ((8 - (*tmpPelWeighted)) * (*src1++)) + offsetWeighted), shiftWeighted ), clipRng ); } - - BlendStart--; - BlendEnd--; - - DstU += strideU; - Src0U += stride0U; - Src1U += stride1U; - DstV += strideU; - Src0V += stride0U; - Src1V += stride1U; + tmpPelWeighted++; } - } - else if( SplitDir == TRIANGLE_DIR_45 && WidthY > HeightY ) - { - int32_t RatioWH = WidthY / HeightY; - int32_t BlendStart = WidthUV - ((BlendLengthUV + 1) >> 1) * RatioWH; - int32_t BlendEnd = BlendStart + BlendLengthUV * RatioWH - 1; - for( int32_t y = 0; y < HeightUV; y++ ) - { - int32_t x = 0; - for( x = 0; x < BlendStart; x++ ) - { - *DstU++ = ClipPel( rightShift( *Src0U++ + offsetDefault, shiftDefault ), clipRngU ); - *DstV++ = ClipPel( rightShift( *Src0V++ + offsetDefault, shiftDefault ), clipRngV ); - } - Src1U += x; - Src1V += x; - - int32_t TmpBlendStart = std::max((int32_t)0, BlendStart); - int32_t TmpBlendEnd = std::min(BlendEnd, (int32_t)(WidthUV - 1)); - TmpPelWeighted = g_TrianglePelWeightedChroma[format][SplitDir][ehanced]; - if( BlendStart < 0 ) - { - TmpPelWeighted += abs(BlendStart) / RatioWH; - } - for( x = TmpBlendStart; x <= TmpBlendEnd; x += RatioWH ) - { - for( int32_t Cnt = 0; Cnt < RatioWH; Cnt++ ) - { - *DstU++ = ClipPel( rightShift(((*TmpPelWeighted)*(*Src0U++) + ((8 - (*TmpPelWeighted)) * (*Src1U++)) + offsetU), shiftNumU ), clipRngU ); - *DstV++ = ClipPel( rightShift(((*TmpPelWeighted)*(*Src0V++) + ((8 - (*TmpPelWeighted)) * (*Src1V++)) + offsetV), shiftNumV ), clipRngV ); - } - TmpPelWeighted++; - } - for( x = BlendEnd + 1; x < WidthUV; x++ ) - { - *DstU++ = ClipPel( rightShift( *Src1U++ + offsetDefault, shiftDefault ), clipRngU ); - *DstV++ = ClipPel( rightShift( *Src1V++ + offsetDefault, shiftDefault ), clipRngV ); - Src0U++; - Src0V++; - } - - BlendStart -= RatioWH; - BlendEnd -= RatioWH; - - DstU += strideU; - Src0U += stride0U; - Src1U += stride1U; - DstV += strideU; - Src0V += stride0U; - Src1V += stride1U; - } - } - else if( SplitDir == TRIANGLE_DIR_45 && WidthY < HeightY ) - { - int32_t RatioHW = HeightY / WidthY; - int32_t BlendStart = WidthUV - ((BlendLengthUV + 1) >> 1); - int32_t BlendEnd = BlendStart + BlendLengthUV - 1; - int32_t Cnt = RatioHW; - for( int32_t y = 0; y < HeightUV; y++ ) + for( x = weightedEndPos + 1; x < width; x++ ) { - int32_t x = 0; - for( x = 0; x < BlendStart; x++ ) - { - *DstU++ = ClipPel( rightShift( *Src0U++ + offsetDefault, shiftDefault ), clipRngU ); - *DstV++ = ClipPel( rightShift( *Src0V++ + offsetDefault, shiftDefault ), clipRngV ); - } - Src1U += x; - Src1V += x; - - int32_t TmpBlendStart = std::max((int32_t)0, BlendStart); - int32_t TmpBlendEnd = std::min(BlendEnd, (int32_t)(WidthUV - 1)); - TmpPelWeighted = g_TrianglePelWeightedChroma[format][SplitDir][ehanced]; - if( BlendStart < 0 ) - { - TmpPelWeighted += abs(BlendStart); - } - for( x = TmpBlendStart; x <= TmpBlendEnd; x++ ) - { - *DstU++ = ClipPel( rightShift(((*TmpPelWeighted)*(*Src0U++) + ((8 - (*TmpPelWeighted)) * (*Src1U++)) + offsetU), shiftNumU ), clipRngU ); - *DstV++ = ClipPel( rightShift(((*TmpPelWeighted)*(*Src0V++) + ((8 - (*TmpPelWeighted)) * (*Src1V++)) + offsetV), shiftNumV ), clipRngV ); - TmpPelWeighted++; - } - - for( x = BlendEnd + 1; x < WidthUV; x++ ) - { - *DstU++ = ClipPel( rightShift( *Src1U++ + offsetDefault, shiftDefault ), clipRngU ); - *DstV++ = ClipPel( rightShift( *Src1V++ + offsetDefault, shiftDefault ), clipRngV ); - Src0U++; - Src0V++; - } - - Cnt--; - if( Cnt <= 0 ) - { - BlendStart--; - BlendEnd--; - Cnt = RatioHW; - } - - DstU += strideU; - Src0U += stride0U; - Src1U += stride1U; - DstV += strideU; - Src0V += stride0U; - Src1V += stride1U; + *dst++ = ClipPel( rightShift( (splitDir == 0 ? *src0 : *src1) + offsetDefault, shiftDefault ), clipRng ); + src0++; + src1++; } + + dst += strideDst; + src0 += strideSrc0; + src1 += strideSrc1; } - else - { - assert(0); - } + weightedStartPos += weightedPosoffset; + weightedEndPos += weightedPosoffset; } } #endif diff --git a/source/Lib/CommonLib/InterPrediction.h b/source/Lib/CommonLib/InterPrediction.h index 4f13cb9c8..0f61defe0 100644 --- a/source/Lib/CommonLib/InterPrediction.h +++ b/source/Lib/CommonLib/InterPrediction.h @@ -92,7 +92,7 @@ protected: int m_iRefListIdx; #if JVET_L0124_L0208_TRIANGLE - PelStorage m_tmpTriangleBuf; + PelStorage m_triangleBuf; #endif #if JVET_L0265_AFF_MINIMUM4X4 Mv* m_storedMv; @@ -130,6 +130,10 @@ protected: #endif void xPredAffineBlk( const ComponentID& compID, const PredictionUnit& pu, const Picture* refPic, const Mv* _mv, PelUnitBuf& dstPic, const bool& bi, const ClpRng& clpRng ); +#if JVET_L0124_L0208_TRIANGLE + void xWeightedTriangleBlk ( const PredictionUnit &pu, const uint32_t width, const uint32_t height, const ComponentID compIdx, const bool splitDir, const bool weights, PelUnitBuf& predDst, PelUnitBuf& predSrc0, PelUnitBuf& predSrc1 ); +#endif + static bool xCheckIdenticalMotion( const PredictionUnit& pu ); void xSubPuMC(PredictionUnit& pu, PelUnitBuf& predBuf, const RefPicList &eRefPicList = REF_PIC_LIST_X); @@ -153,8 +157,8 @@ public: ); #if JVET_L0124_L0208_TRIANGLE - void motionCompensation4Triangle( CodingUnit &cu, MergeCtx &TriangleMrgCtx, const bool SplitDir, const uint8_t CandIdx0, const uint8_t CandIdx1 ); - void TriangleWeighting ( PredictionUnit &pu, bool ehanced, const bool SplitDir, int32_t channel, PelUnitBuf& PredDst, PelUnitBuf& PredSrc0, PelUnitBuf& PredSrc1 ); + void motionCompensation4Triangle( CodingUnit &cu, MergeCtx &triangleMrgCtx, const bool splitDir, const uint8_t candIdx0, const uint8_t candIdx1 ); + void weightedTriangleBlk ( PredictionUnit &pu, bool weights, const bool splitDir, int32_t channel, PelUnitBuf& predDst, PelUnitBuf& predSrc0, PelUnitBuf& predSrc1 ); #endif #if JVET_J0090_MEMORY_BANDWITH_MEASURE diff --git a/source/Lib/CommonLib/Rom.cpp b/source/Lib/CommonLib/Rom.cpp index 1ff35211c..2c25d72c1 100644 --- a/source/Lib/CommonLib/Rom.cpp +++ b/source/Lib/CommonLib/Rom.cpp @@ -530,23 +530,23 @@ void initROM() } #if JVET_L0124_L0208_TRIANGLE - for( int IdxH = MAX_CU_DEPTH - MIN_CU_LOG2; IdxH >= 0; --IdxH ) + for( int idxH = MAX_CU_DEPTH - MIN_CU_LOG2; idxH >= 0; --idxH ) { - for( int IdxW = MAX_CU_DEPTH - MIN_CU_LOG2; IdxW >= 0; --IdxW ) + for( int idxW = MAX_CU_DEPTH - MIN_CU_LOG2; idxW >= 0; --idxW ) { - int numW = 1 << IdxW; - int numH = 1 << IdxH; - int ratioW = std::max( 0, IdxW - IdxH ); - int ratioH = std::max( 0, IdxH - IdxW ); + int numW = 1 << idxW; + int numH = 1 << idxH; + int ratioW = std::max( 0, idxW - idxH ); + int ratioH = std::max( 0, idxH - idxW ); int sum = std::max( (numW >> ratioW), (numH >> ratioH) ) - 1; for( int y = 0; y < numH; y++ ) { - int IdxY = y >> ratioH; + int idxY = y >> ratioH; for( int x = 0; x < numW; x++ ) { - int IdxX = x >> ratioW; - g_TriangleMvStorage[TRIANGLE_DIR_135][IdxH][IdxW][y][x] = (IdxX == IdxY) ? 2 : (IdxX > IdxY ? 0 : 1); - g_TriangleMvStorage[TRIANGLE_DIR_45][IdxH][IdxW][y][x] = (IdxX + IdxY == sum) ? 2 : (IdxX + IdxY > sum ? 1 : 0); + int idxX = x >> ratioW; + g_triangleMvStorage[TRIANGLE_DIR_135][idxH][idxW][y][x] = (idxX == idxY) ? 2 : (idxX > idxY ? 0 : 1); + g_triangleMvStorage[TRIANGLE_DIR_45][idxH][idxW][y][x] = (idxX + idxY == sum) ? 2 : (idxX + idxY > sum ? 1 : 0); } } } @@ -908,7 +908,7 @@ const uint8_t g_NonMPM[257] = { 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8 }; #if JVET_L0124_L0208_TRIANGLE -const Pel g_TrianglePelWeightedLuma[TRIANGLE_DIR_NUM][2][7] = +const Pel g_trianglePelWeightedLuma[TRIANGLE_DIR_NUM][2][7] = { { // TRIANGLE_DIR_135 { 1, 2, 4, 6, 7, 0, 0 }, @@ -919,7 +919,7 @@ const Pel g_TrianglePelWeightedLuma[TRIANGLE_DIR_NUM][2][7] = { 7, 6, 5, 4, 3, 2, 1 } } }; -const Pel g_TrianglePelWeightedChroma[2][TRIANGLE_DIR_NUM][2][7] = +const Pel g_trianglePelWeightedChroma[2][TRIANGLE_DIR_NUM][2][7] = { { // 444 format { // TRIANGLE_DIR_135 @@ -943,12 +943,12 @@ const Pel g_TrianglePelWeightedChroma[2][TRIANGLE_DIR_NUM][2][7] = } }; -const uint8_t g_TriangleWeightLengthLuma[2] = { 5, 7 }; -const uint8_t g_TriangleWeightLengthChroma[2][2] = { { 5, 7 }, { 3, 3 } }; +const uint8_t g_triangleWeightLengthLuma[2] = { 5, 7 }; +const uint8_t g_triangleWeightLengthChroma[2][2] = { { 5, 7 }, { 3, 3 } }; - uint8_t g_TriangleMvStorage[TRIANGLE_DIR_NUM][MAX_CU_DEPTH - MIN_CU_LOG2 + 1][MAX_CU_DEPTH - MIN_CU_LOG2 + 1][MAX_CU_SIZE >> MIN_CU_LOG2][MAX_CU_SIZE >> MIN_CU_LOG2]; + uint8_t g_triangleMvStorage[TRIANGLE_DIR_NUM][MAX_CU_DEPTH - MIN_CU_LOG2 + 1][MAX_CU_DEPTH - MIN_CU_LOG2 + 1][MAX_CU_SIZE >> MIN_CU_LOG2][MAX_CU_SIZE >> MIN_CU_LOG2]; -const uint8_t g_TriangleCombination[TRIANGLE_MAX_NUM_CANDS][3] = +const uint8_t g_triangleCombination[TRIANGLE_MAX_NUM_CANDS][3] = { { 0, 1, 0 }, { 1, 0, 1 }, { 1, 0, 2 }, { 0, 0, 1 }, { 0, 2, 0 }, { 1, 0, 3 }, { 1, 0, 4 }, { 1, 1, 0 }, { 0, 3, 0 }, { 0, 4, 0 }, @@ -960,7 +960,7 @@ const uint8_t g_TriangleCombination[TRIANGLE_MAX_NUM_CANDS][3] = { 0, 3, 1 }, { 0, 2, 4 }, { 1, 2, 4 }, { 0, 4, 2 }, { 0, 3, 4 }, }; -const uint8_t g_TriangleIdxBins[TRIANGLE_MAX_NUM_CANDS] = +const uint8_t g_triangleIdxBins[TRIANGLE_MAX_NUM_CANDS] = { 2, 2, 4, 4, 4, 4, 6, 6, 6, 6, 6, 6, 6, 6, 8, 8, 8, 8, 8, 8, diff --git a/source/Lib/CommonLib/Rom.h b/source/Lib/CommonLib/Rom.h index 56e2f392e..825126095 100644 --- a/source/Lib/CommonLib/Rom.h +++ b/source/Lib/CommonLib/Rom.h @@ -271,13 +271,13 @@ constexpr uint8_t g_tbMax[257] = { 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, //! \} #if JVET_L0124_L0208_TRIANGLE -extern const Pel g_TrianglePelWeightedLuma[TRIANGLE_DIR_NUM][2][7]; -extern const Pel g_TrianglePelWeightedChroma[2][TRIANGLE_DIR_NUM][2][7]; -extern const uint8_t g_TriangleWeightLengthLuma[2]; -extern const uint8_t g_TriangleWeightLengthChroma[2][2]; -extern uint8_t g_TriangleMvStorage[TRIANGLE_DIR_NUM][MAX_CU_DEPTH - MIN_CU_LOG2 + 1][MAX_CU_DEPTH - MIN_CU_LOG2 + 1][MAX_CU_SIZE >> MIN_CU_LOG2][MAX_CU_SIZE >> MIN_CU_LOG2]; -extern const uint8_t g_TriangleCombination[TRIANGLE_MAX_NUM_CANDS][3]; -extern const uint8_t g_TriangleIdxBins[TRIANGLE_MAX_NUM_CANDS]; +extern const Pel g_trianglePelWeightedLuma[TRIANGLE_DIR_NUM][2][7]; +extern const Pel g_trianglePelWeightedChroma[2][TRIANGLE_DIR_NUM][2][7]; +extern const uint8_t g_triangleWeightLengthLuma[2]; +extern const uint8_t g_triangleWeightLengthChroma[2][2]; +extern uint8_t g_triangleMvStorage[TRIANGLE_DIR_NUM][MAX_CU_DEPTH - MIN_CU_LOG2 + 1][MAX_CU_DEPTH - MIN_CU_LOG2 + 1][MAX_CU_SIZE >> MIN_CU_LOG2][MAX_CU_SIZE >> MIN_CU_LOG2]; +extern const uint8_t g_triangleCombination[TRIANGLE_MAX_NUM_CANDS][3]; +extern const uint8_t g_triangleIdxBins[TRIANGLE_MAX_NUM_CANDS]; #endif #endif //__TCOMROM__ diff --git a/source/Lib/CommonLib/UnitTools.cpp b/source/Lib/CommonLib/UnitTools.cpp index f7bb9c977..4fc47bc93 100644 --- a/source/Lib/CommonLib/UnitTools.cpp +++ b/source/Lib/CommonLib/UnitTools.cpp @@ -3974,25 +3974,25 @@ void PU::restrictBiPredMergeCands( const PredictionUnit &pu, MergeCtx& mergeCtx } #if JVET_L0124_L0208_TRIANGLE -void PU::getTriangleMergeCandidates( const PredictionUnit &pu, MergeCtx& TriangleMrgCtx ) +void PU::getTriangleMergeCandidates( const PredictionUnit &pu, MergeCtx& triangleMrgCtx ) { const CodingStructure &cs = *pu.cs; const Slice &slice = *pu.cs->slice; const int32_t maxNumMergeCand = TRIANGLE_MAX_NUM_UNI_CANDS; - TriangleMrgCtx.numValidMergeCand = 0; + triangleMrgCtx.numValidMergeCand = 0; for( int32_t i = 0; i < maxNumMergeCand; i++ ) { - 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.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(); } - MotionInfo Candidate[TRIANGLE_MAX_NUM_CANDS_MEM]; - int32_t CandCount = 0; + MotionInfo candidate[TRIANGLE_MAX_NUM_CANDS_MEM]; + int32_t candCount = 0; const Position posLT = pu.Y().topLeft(); const Position posRT = pu.Y().topRight(); @@ -4006,13 +4006,13 @@ void PU::getTriangleMergeCandidates( const PredictionUnit &pu, MergeCtx& Triangl if( isAvailableA1 ) { miLeft = puLeft->getMotionInfo( posLB.offset(-1, 0) ); - Candidate[CandCount].isInter = true; - Candidate[CandCount].interDir = miLeft.interDir; - Candidate[CandCount].mv[0] = miLeft.mv[0]; - Candidate[CandCount].mv[1] = miLeft.mv[1]; - Candidate[CandCount].refIdx[0] = miLeft.refIdx[0]; - Candidate[CandCount].refIdx[1] = miLeft.refIdx[1]; - CandCount++; + candidate[candCount].isInter = true; + candidate[candCount].interDir = miLeft.interDir; + candidate[candCount].mv[0] = miLeft.mv[0]; + candidate[candCount].mv[1] = miLeft.mv[1]; + candidate[candCount].refIdx[0] = miLeft.refIdx[0]; + candidate[candCount].refIdx[1] = miLeft.refIdx[1]; + candCount++; } // above @@ -4024,13 +4024,13 @@ void PU::getTriangleMergeCandidates( const PredictionUnit &pu, MergeCtx& Triangl if( !isAvailableA1 || ( miAbove != miLeft ) ) { - Candidate[CandCount].isInter = true; - Candidate[CandCount].interDir = miAbove.interDir; - Candidate[CandCount].mv[0] = miAbove.mv[0]; - Candidate[CandCount].mv[1] = miAbove.mv[1]; - Candidate[CandCount].refIdx[0] = miAbove.refIdx[0]; - Candidate[CandCount].refIdx[1] = miAbove.refIdx[1]; - CandCount++; + candidate[candCount].isInter = true; + candidate[candCount].interDir = miAbove.interDir; + candidate[candCount].mv[0] = miAbove.mv[0]; + candidate[candCount].mv[1] = miAbove.mv[1]; + candidate[candCount].refIdx[0] = miAbove.refIdx[0]; + candidate[candCount].refIdx[1] = miAbove.refIdx[1]; + candCount++; } } @@ -4044,13 +4044,13 @@ void PU::getTriangleMergeCandidates( const PredictionUnit &pu, MergeCtx& Triangl if( ( !isAvailableB1 || ( miAbove != miAboveRight ) ) && ( !isAvailableA1 || ( miLeft != miAboveRight ) ) ) { - Candidate[CandCount].isInter = true; - Candidate[CandCount].interDir = miAboveRight.interDir; - Candidate[CandCount].mv[0] = miAboveRight.mv[0]; - Candidate[CandCount].mv[1] = miAboveRight.mv[1]; - Candidate[CandCount].refIdx[0] = miAboveRight.refIdx[0]; - Candidate[CandCount].refIdx[1] = miAboveRight.refIdx[1]; - CandCount++; + candidate[candCount].isInter = true; + candidate[candCount].interDir = miAboveRight.interDir; + candidate[candCount].mv[0] = miAboveRight.mv[0]; + candidate[candCount].mv[1] = miAboveRight.mv[1]; + candidate[candCount].refIdx[0] = miAboveRight.refIdx[0]; + candidate[candCount].refIdx[1] = miAboveRight.refIdx[1]; + candCount++; } } @@ -4063,13 +4063,13 @@ void PU::getTriangleMergeCandidates( const PredictionUnit &pu, MergeCtx& Triangl if( ( !isAvailableA1 || ( miBelowLeft != miLeft ) ) && ( !isAvailableB1 || ( miBelowLeft != miAbove ) ) && ( !isAvailableB0 || ( miBelowLeft != miAboveRight ) ) ) { - Candidate[CandCount].isInter = true; - Candidate[CandCount].interDir = miBelowLeft.interDir; - Candidate[CandCount].mv[0] = miBelowLeft.mv[0]; - Candidate[CandCount].mv[1] = miBelowLeft.mv[1]; - Candidate[CandCount].refIdx[0] = miBelowLeft.refIdx[0]; - Candidate[CandCount].refIdx[1] = miBelowLeft.refIdx[1]; - CandCount++; + candidate[candCount].isInter = true; + candidate[candCount].interDir = miBelowLeft.interDir; + candidate[candCount].mv[0] = miBelowLeft.mv[0]; + candidate[candCount].mv[1] = miBelowLeft.mv[1]; + candidate[candCount].refIdx[0] = miBelowLeft.refIdx[0]; + candidate[candCount].refIdx[1] = miBelowLeft.refIdx[1]; + candCount++; } } @@ -4083,13 +4083,13 @@ void PU::getTriangleMergeCandidates( const PredictionUnit &pu, MergeCtx& Triangl if( ( !isAvailableA1 || ( miLeft != miAboveLeft ) ) && ( !isAvailableB1 || ( miAbove != miAboveLeft ) ) && ( !isAvailableA0 || ( miBelowLeft != miAboveLeft ) ) && ( !isAvailableB0 || ( miAboveRight != miAboveLeft ) ) ) { - Candidate[CandCount].isInter = true; - Candidate[CandCount].interDir = miAboveLeft.interDir; - Candidate[CandCount].mv[0] = miAboveLeft.mv[0]; - Candidate[CandCount].mv[1] = miAboveLeft.mv[1]; - Candidate[CandCount].refIdx[0] = miAboveLeft.refIdx[0]; - Candidate[CandCount].refIdx[1] = miAboveLeft.refIdx[1]; - CandCount++; + candidate[candCount].isInter = true; + candidate[candCount].interDir = miAboveLeft.interDir; + candidate[candCount].mv[0] = miAboveLeft.mv[0]; + candidate[candCount].mv[1] = miAboveLeft.mv[1]; + candidate[candCount].refIdx[0] = miAboveLeft.refIdx[0]; + candidate[candCount].refIdx[1] = miAboveLeft.refIdx[1]; + candCount++; } } @@ -4101,7 +4101,7 @@ void PU::getTriangleMergeCandidates( const PredictionUnit &pu, MergeCtx& Triangl Position posC0; Position posC1 = pu.Y().center(); - bool C0Avail = false; + bool isAvailableC0 = false; if (((posRB.x + pcv.minCUWidth) < pcv.lumaWidth) && ((posRB.y + pcv.minCUHeight) < pcv.lumaHeight)) { @@ -4111,7 +4111,7 @@ void PU::getTriangleMergeCandidates( const PredictionUnit &pu, MergeCtx& Triangl ( posInCtu.y + 4 < pcv.maxCUHeight ) ) // is not at the last row of CTU { posC0 = posRB.offset( 4, 4 ); - C0Avail = true; + isAvailableC0 = true; } else if( posInCtu.x + 4 < pcv.maxCUWidth ) // is not at the last column of CTU But is last row of CTU { @@ -4121,7 +4121,7 @@ void PU::getTriangleMergeCandidates( const PredictionUnit &pu, MergeCtx& Triangl 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; + isAvailableC0 = true; } else //is the right bottom corner of CTU { @@ -4132,144 +4132,144 @@ void PU::getTriangleMergeCandidates( const PredictionUnit &pu, MergeCtx& Triangl // C0 Mv cColMv; - int32_t RefIdx = 0; - bool ExistMV = ( C0Avail && getColocatedMVP( pu, REF_PIC_LIST_0, posC0, cColMv, RefIdx ) ); - MotionInfo MvTemporal; - MvTemporal.interDir = 0; - if( ExistMV ) + int32_t refIdx = 0; + bool existMV = ( isAvailableC0 && getColocatedMVP( pu, REF_PIC_LIST_0, posC0, cColMv, refIdx ) ); + MotionInfo temporalMv; + temporalMv.interDir = 0; + if( existMV ) { - MvTemporal.isInter = true; - MvTemporal.interDir |= 1; - MvTemporal.mv[0] = cColMv; - MvTemporal.refIdx[0] = RefIdx; + temporalMv.isInter = true; + temporalMv.interDir |= 1; + temporalMv.mv[0] = cColMv; + temporalMv.refIdx[0] = refIdx; } - ExistMV = ( C0Avail && getColocatedMVP( pu, REF_PIC_LIST_1, posC0, cColMv, RefIdx ) ); - if( ExistMV ) + existMV = ( isAvailableC0 && getColocatedMVP( pu, REF_PIC_LIST_1, posC0, cColMv, refIdx ) ); + if( existMV ) { - MvTemporal.interDir |= 2; - MvTemporal.mv[1] = cColMv; - MvTemporal.refIdx[1] = RefIdx; + temporalMv.interDir |= 2; + temporalMv.mv[1] = cColMv; + temporalMv.refIdx[1] = refIdx; } - if( MvTemporal.interDir != 0 ) + if( temporalMv.interDir != 0 ) { - Candidate[CandCount].isInter = true; - Candidate[CandCount].interDir = MvTemporal.interDir; - Candidate[CandCount].mv[0] = MvTemporal.mv[0]; - Candidate[CandCount].mv[1] = MvTemporal.mv[1]; - Candidate[CandCount].refIdx[0] = MvTemporal.refIdx[0]; - Candidate[CandCount].refIdx[1] = MvTemporal.refIdx[1]; - CandCount++; + candidate[candCount].isInter = true; + candidate[candCount].interDir = temporalMv.interDir; + candidate[candCount].mv[0] = temporalMv.mv[0]; + candidate[candCount].mv[1] = temporalMv.mv[1]; + candidate[candCount].refIdx[0] = temporalMv.refIdx[0]; + candidate[candCount].refIdx[1] = temporalMv.refIdx[1]; + candCount++; } // C1 - MvTemporal.interDir = 0; - ExistMV = getColocatedMVP(pu, REF_PIC_LIST_0, posC1, cColMv, RefIdx ); - if( ExistMV ) + temporalMv.interDir = 0; + existMV = getColocatedMVP(pu, REF_PIC_LIST_0, posC1, cColMv, refIdx ); + if( existMV ) { - MvTemporal.isInter = true; - MvTemporal.interDir |= 1; - MvTemporal.mv[0] = cColMv; - MvTemporal.refIdx[0] = RefIdx; + temporalMv.isInter = true; + temporalMv.interDir |= 1; + temporalMv.mv[0] = cColMv; + temporalMv.refIdx[0] = refIdx; } - ExistMV = getColocatedMVP(pu, REF_PIC_LIST_1, posC1, cColMv, RefIdx ); - if( ExistMV ) + existMV = getColocatedMVP(pu, REF_PIC_LIST_1, posC1, cColMv, refIdx ); + if( existMV ) { - MvTemporal.interDir |= 2; - MvTemporal.mv[1] = cColMv; - MvTemporal.refIdx[1] = RefIdx; + temporalMv.interDir |= 2; + temporalMv.mv[1] = cColMv; + temporalMv.refIdx[1] = refIdx; } - if( MvTemporal.interDir != 0 ) + if( temporalMv.interDir != 0 ) { - Candidate[CandCount].isInter = true; - Candidate[CandCount].interDir = MvTemporal.interDir; - Candidate[CandCount].mv[0] = MvTemporal.mv[0]; - Candidate[CandCount].mv[1] = MvTemporal.mv[1]; - Candidate[CandCount].refIdx[0] = MvTemporal.refIdx[0]; - Candidate[CandCount].refIdx[1] = MvTemporal.refIdx[1]; - CandCount++; + candidate[candCount].isInter = true; + candidate[candCount].interDir = temporalMv.interDir; + candidate[candCount].mv[0] = temporalMv.mv[0]; + candidate[candCount].mv[1] = temporalMv.mv[1]; + candidate[candCount].refIdx[0] = temporalMv.refIdx[0]; + candidate[candCount].refIdx[1] = temporalMv.refIdx[1]; + candCount++; } - } // if( slice.getEnableTMVPFlag() ) + } - // uni-pred - for( int32_t i = 0; i < CandCount; i++ ) + // put uni-prediction candidate to the triangle candidate list + for( int32_t i = 0; i < candCount; i++ ) { - if( Candidate[i].interDir != 3 ) - { - TriangleMrgCtx.interDirNeighbours[TriangleMrgCtx.numValidMergeCand] = Candidate[i].interDir; - TriangleMrgCtx.mrgTypeNeighbours [TriangleMrgCtx.numValidMergeCand] = MRG_TYPE_DEFAULT_N; - TriangleMrgCtx.mvFieldNeighbours [(TriangleMrgCtx.numValidMergeCand << 1) ].mv = Candidate[i].mv[0]; - TriangleMrgCtx.mvFieldNeighbours [(TriangleMrgCtx.numValidMergeCand << 1) + 1].mv = Candidate[i].mv[1]; - TriangleMrgCtx.mvFieldNeighbours [(TriangleMrgCtx.numValidMergeCand << 1) ].refIdx = Candidate[i].refIdx[0]; - TriangleMrgCtx.mvFieldNeighbours [(TriangleMrgCtx.numValidMergeCand << 1) + 1].refIdx = Candidate[i].refIdx[1]; - TriangleMrgCtx.numValidMergeCand += isUniqueTriangleCandidates(pu, TriangleMrgCtx); - if( TriangleMrgCtx.numValidMergeCand == TRIANGLE_MAX_NUM_UNI_CANDS ) + if( candidate[i].interDir != 3 ) + { + triangleMrgCtx.interDirNeighbours[triangleMrgCtx.numValidMergeCand] = candidate[i].interDir; + triangleMrgCtx.mrgTypeNeighbours [triangleMrgCtx.numValidMergeCand] = MRG_TYPE_DEFAULT_N; + triangleMrgCtx.mvFieldNeighbours [(triangleMrgCtx.numValidMergeCand << 1) ].mv = candidate[i].mv[0]; + triangleMrgCtx.mvFieldNeighbours [(triangleMrgCtx.numValidMergeCand << 1) + 1].mv = candidate[i].mv[1]; + triangleMrgCtx.mvFieldNeighbours [(triangleMrgCtx.numValidMergeCand << 1) ].refIdx = candidate[i].refIdx[0]; + triangleMrgCtx.mvFieldNeighbours [(triangleMrgCtx.numValidMergeCand << 1) + 1].refIdx = candidate[i].refIdx[1]; + triangleMrgCtx.numValidMergeCand += isUniqueTriangleCandidates(pu, triangleMrgCtx); + if( triangleMrgCtx.numValidMergeCand == TRIANGLE_MAX_NUM_UNI_CANDS ) { return; } } } - // L0 of bi-pred - for( int32_t i = 0; i < CandCount; i++ ) + // put L0 mv of bi-prediction candidate to the triangle candidate list + for( int32_t i = 0; i < candCount; i++ ) { - if( Candidate[i].interDir == 3 ) + if( candidate[i].interDir == 3 ) { - TriangleMrgCtx.interDirNeighbours[TriangleMrgCtx.numValidMergeCand] = 1; - TriangleMrgCtx.mrgTypeNeighbours [TriangleMrgCtx.numValidMergeCand] = MRG_TYPE_DEFAULT_N; - TriangleMrgCtx.mvFieldNeighbours [(TriangleMrgCtx.numValidMergeCand << 1) ].mv = Candidate[i].mv[0]; - TriangleMrgCtx.mvFieldNeighbours [(TriangleMrgCtx.numValidMergeCand << 1) + 1].mv = Mv(0, 0); - TriangleMrgCtx.mvFieldNeighbours [(TriangleMrgCtx.numValidMergeCand << 1) ].refIdx = Candidate[i].refIdx[0]; - TriangleMrgCtx.mvFieldNeighbours [(TriangleMrgCtx.numValidMergeCand << 1) + 1].refIdx = -1; - TriangleMrgCtx.numValidMergeCand += isUniqueTriangleCandidates(pu, TriangleMrgCtx); - if( TriangleMrgCtx.numValidMergeCand == TRIANGLE_MAX_NUM_UNI_CANDS ) + triangleMrgCtx.interDirNeighbours[triangleMrgCtx.numValidMergeCand] = 1; + triangleMrgCtx.mrgTypeNeighbours [triangleMrgCtx.numValidMergeCand] = MRG_TYPE_DEFAULT_N; + triangleMrgCtx.mvFieldNeighbours [(triangleMrgCtx.numValidMergeCand << 1) ].mv = candidate[i].mv[0]; + triangleMrgCtx.mvFieldNeighbours [(triangleMrgCtx.numValidMergeCand << 1) + 1].mv = Mv(0, 0); + triangleMrgCtx.mvFieldNeighbours [(triangleMrgCtx.numValidMergeCand << 1) ].refIdx = candidate[i].refIdx[0]; + triangleMrgCtx.mvFieldNeighbours [(triangleMrgCtx.numValidMergeCand << 1) + 1].refIdx = -1; + triangleMrgCtx.numValidMergeCand += isUniqueTriangleCandidates(pu, triangleMrgCtx); + if( triangleMrgCtx.numValidMergeCand == TRIANGLE_MAX_NUM_UNI_CANDS ) { return; } } } - // L1 of bi-pred - for( int32_t i = 0; i < CandCount; i++ ) + // put L1 mv of bi-prediction candidate to the triangle candidate list + for( int32_t i = 0; i < candCount; i++ ) { - if( Candidate[i].interDir == 3 ) + if( candidate[i].interDir == 3 ) { - TriangleMrgCtx.interDirNeighbours[TriangleMrgCtx.numValidMergeCand] = 2; - TriangleMrgCtx.mrgTypeNeighbours [TriangleMrgCtx.numValidMergeCand] = MRG_TYPE_DEFAULT_N; - TriangleMrgCtx.mvFieldNeighbours [(TriangleMrgCtx.numValidMergeCand << 1) ].mv = Mv(0, 0); - TriangleMrgCtx.mvFieldNeighbours [(TriangleMrgCtx.numValidMergeCand << 1) + 1].mv = Candidate[i].mv[1]; - TriangleMrgCtx.mvFieldNeighbours [(TriangleMrgCtx.numValidMergeCand << 1) ].refIdx = -1; - TriangleMrgCtx.mvFieldNeighbours [(TriangleMrgCtx.numValidMergeCand << 1) + 1].refIdx = Candidate[i].refIdx[1]; - TriangleMrgCtx.numValidMergeCand += isUniqueTriangleCandidates(pu, TriangleMrgCtx); - if( TriangleMrgCtx.numValidMergeCand == TRIANGLE_MAX_NUM_UNI_CANDS ) + triangleMrgCtx.interDirNeighbours[triangleMrgCtx.numValidMergeCand] = 2; + triangleMrgCtx.mrgTypeNeighbours [triangleMrgCtx.numValidMergeCand] = MRG_TYPE_DEFAULT_N; + triangleMrgCtx.mvFieldNeighbours [(triangleMrgCtx.numValidMergeCand << 1) ].mv = Mv(0, 0); + triangleMrgCtx.mvFieldNeighbours [(triangleMrgCtx.numValidMergeCand << 1) + 1].mv = candidate[i].mv[1]; + triangleMrgCtx.mvFieldNeighbours [(triangleMrgCtx.numValidMergeCand << 1) ].refIdx = -1; + triangleMrgCtx.mvFieldNeighbours [(triangleMrgCtx.numValidMergeCand << 1) + 1].refIdx = candidate[i].refIdx[1]; + triangleMrgCtx.numValidMergeCand += isUniqueTriangleCandidates(pu, triangleMrgCtx); + if( triangleMrgCtx.numValidMergeCand == TRIANGLE_MAX_NUM_UNI_CANDS ) { return; } } } - // averaging two uni-pred of bi-pred - for( int32_t i = 0; i < CandCount; i++ ) + // put average of L0 and L1 mvs of bi-prediction candidate to the triangle candidate list + for( int32_t i = 0; i < candCount; i++ ) { - if( Candidate[i].interDir == 3 ) + if( candidate[i].interDir == 3 ) { - int32_t currPOC = slice.getPOC(); - int32_t L0RefPOC = slice.getRefPOC(REF_PIC_LIST_0, Candidate[i].refIdx[0]); - int32_t L1RefPOC = slice.getRefPOC(REF_PIC_LIST_1, Candidate[i].refIdx[1]); - Mv aveMv = Candidate[i].mv[1]; - aveMv = aveMv.scaleMv( xGetDistScaleFactor( currPOC, L0RefPOC, currPOC, L1RefPOC ) ); // scaling to L0 - aveMv.setHor( ( aveMv.getHor() + Candidate[i].mv[0].getHor() + 1 ) >> 1 ); - aveMv.setVer( ( aveMv.getVer() + Candidate[i].mv[0].getVer() + 1 ) >> 1 ); + int32_t curPicPoc = slice.getPOC(); + int32_t refPicPocL0 = slice.getRefPOC(REF_PIC_LIST_0, candidate[i].refIdx[0]); + int32_t refPicPocL1 = slice.getRefPOC(REF_PIC_LIST_1, candidate[i].refIdx[1]); + Mv aveMv = candidate[i].mv[1]; + aveMv = aveMv.scaleMv( xGetDistScaleFactor( curPicPoc, refPicPocL0, curPicPoc, refPicPocL1 ) ); // scaling to L0 + aveMv.setHor( ( aveMv.getHor() + candidate[i].mv[0].getHor() + 1 ) >> 1 ); + aveMv.setVer( ( aveMv.getVer() + candidate[i].mv[0].getVer() + 1 ) >> 1 ); - TriangleMrgCtx.interDirNeighbours[TriangleMrgCtx.numValidMergeCand] = 1; - TriangleMrgCtx.mrgTypeNeighbours [TriangleMrgCtx.numValidMergeCand] = MRG_TYPE_DEFAULT_N; - TriangleMrgCtx.mvFieldNeighbours [(TriangleMrgCtx.numValidMergeCand << 1) ].mv = aveMv; - TriangleMrgCtx.mvFieldNeighbours [(TriangleMrgCtx.numValidMergeCand << 1) + 1].mv = Mv(0, 0); - TriangleMrgCtx.mvFieldNeighbours [(TriangleMrgCtx.numValidMergeCand << 1) ].refIdx = Candidate[i].refIdx[0]; - TriangleMrgCtx.mvFieldNeighbours [(TriangleMrgCtx.numValidMergeCand << 1) + 1].refIdx = -1; - TriangleMrgCtx.numValidMergeCand += isUniqueTriangleCandidates(pu, TriangleMrgCtx); - if( TriangleMrgCtx.numValidMergeCand == TRIANGLE_MAX_NUM_UNI_CANDS ) + triangleMrgCtx.interDirNeighbours[triangleMrgCtx.numValidMergeCand] = 1; + triangleMrgCtx.mrgTypeNeighbours [triangleMrgCtx.numValidMergeCand] = MRG_TYPE_DEFAULT_N; + triangleMrgCtx.mvFieldNeighbours [(triangleMrgCtx.numValidMergeCand << 1) ].mv = aveMv; + triangleMrgCtx.mvFieldNeighbours [(triangleMrgCtx.numValidMergeCand << 1) + 1].mv = Mv(0, 0); + triangleMrgCtx.mvFieldNeighbours [(triangleMrgCtx.numValidMergeCand << 1) ].refIdx = candidate[i].refIdx[0]; + triangleMrgCtx.mvFieldNeighbours [(triangleMrgCtx.numValidMergeCand << 1) + 1].refIdx = -1; + triangleMrgCtx.numValidMergeCand += isUniqueTriangleCandidates(pu, triangleMrgCtx); + if( triangleMrgCtx.numValidMergeCand == TRIANGLE_MAX_NUM_UNI_CANDS ) { return; } @@ -4277,40 +4277,40 @@ void PU::getTriangleMergeCandidates( const PredictionUnit &pu, MergeCtx& Triangl } // fill with Mv(0, 0) - int32_t NumRefIdx = std::min( slice.getNumRefIdx(REF_PIC_LIST_0), slice.getNumRefIdx(REF_PIC_LIST_1) ); - int32_t Cnt = 0; - while( TriangleMrgCtx.numValidMergeCand < TRIANGLE_MAX_NUM_UNI_CANDS ) + int32_t numRefIdx = std::min( slice.getNumRefIdx(REF_PIC_LIST_0), slice.getNumRefIdx(REF_PIC_LIST_1) ); + int32_t cnt = 0; + while( triangleMrgCtx.numValidMergeCand < TRIANGLE_MAX_NUM_UNI_CANDS ) { - if( Cnt < NumRefIdx ) + if( cnt < numRefIdx ) { - TriangleMrgCtx.interDirNeighbours[TriangleMrgCtx.numValidMergeCand] = 1; - TriangleMrgCtx.mvFieldNeighbours[TriangleMrgCtx.numValidMergeCand << 1].setMvField(Mv(0, 0), Cnt); - TriangleMrgCtx.numValidMergeCand++; + triangleMrgCtx.interDirNeighbours[triangleMrgCtx.numValidMergeCand] = 1; + triangleMrgCtx.mvFieldNeighbours[triangleMrgCtx.numValidMergeCand << 1].setMvField(Mv(0, 0), cnt); + triangleMrgCtx.numValidMergeCand++; - if( TriangleMrgCtx.numValidMergeCand == TRIANGLE_MAX_NUM_UNI_CANDS ) + if( triangleMrgCtx.numValidMergeCand == TRIANGLE_MAX_NUM_UNI_CANDS ) { return; } - TriangleMrgCtx.interDirNeighbours[TriangleMrgCtx.numValidMergeCand] = 2; - TriangleMrgCtx.mvFieldNeighbours [(TriangleMrgCtx.numValidMergeCand << 1) + 1 ].setMvField(Mv(0, 0), Cnt); - TriangleMrgCtx.numValidMergeCand++; + triangleMrgCtx.interDirNeighbours[triangleMrgCtx.numValidMergeCand] = 2; + triangleMrgCtx.mvFieldNeighbours [(triangleMrgCtx.numValidMergeCand << 1) + 1 ].setMvField(Mv(0, 0), cnt); + triangleMrgCtx.numValidMergeCand++; - Cnt = (Cnt + 1) % NumRefIdx; + cnt = (cnt + 1) % numRefIdx; } } } -bool PU::isUniqueTriangleCandidates( const PredictionUnit &pu, MergeCtx& TriangleMrgCtx ) +bool PU::isUniqueTriangleCandidates( const PredictionUnit &pu, MergeCtx& triangleMrgCtx ) { - int newCand = TriangleMrgCtx.numValidMergeCand; + int newCand = triangleMrgCtx.numValidMergeCand; for( int32_t i = 0; i < newCand; i++ ) { - int32_t predFlagCur = TriangleMrgCtx.interDirNeighbours[i] == 1 ? 0 : 1; - int32_t predFlagNew = TriangleMrgCtx.interDirNeighbours[newCand] == 1 ? 0 : 1; - int32_t refPicPocCur = pu.cs->slice->getRefPOC( (RefPicList)predFlagCur, TriangleMrgCtx.mvFieldNeighbours[(i << 1) + predFlagCur].refIdx ); - int32_t refPicPocNew = pu.cs->slice->getRefPOC( (RefPicList)predFlagNew, TriangleMrgCtx.mvFieldNeighbours[(newCand << 1) + predFlagNew].refIdx); - if( refPicPocCur == refPicPocNew && TriangleMrgCtx.mvFieldNeighbours[(i << 1) + predFlagCur].mv == TriangleMrgCtx.mvFieldNeighbours[(newCand << 1) + predFlagNew].mv ) + int32_t predFlagCur = triangleMrgCtx.interDirNeighbours[i] == 1 ? 0 : 1; + int32_t predFlagNew = triangleMrgCtx.interDirNeighbours[newCand] == 1 ? 0 : 1; + int32_t refPicPocCur = pu.cs->slice->getRefPOC( (RefPicList)predFlagCur, triangleMrgCtx.mvFieldNeighbours[(i << 1) + predFlagCur].refIdx ); + int32_t refPicPocNew = pu.cs->slice->getRefPOC( (RefPicList)predFlagNew, triangleMrgCtx.mvFieldNeighbours[(newCand << 1) + predFlagNew].refIdx); + if( refPicPocCur == refPicPocNew && triangleMrgCtx.mvFieldNeighbours[(i << 1) + predFlagCur].mv == triangleMrgCtx.mvFieldNeighbours[(newCand << 1) + predFlagNew].mv ) { return false; } @@ -4318,14 +4318,14 @@ bool PU::isUniqueTriangleCandidates( const PredictionUnit &pu, MergeCtx& Triangl return true; } -bool PU::isTriangleEhancedWeight( const PredictionUnit& pu, MergeCtx &TriangleMrgCtx, const uint8_t CandIdx0, const uint8_t CandIdx1 ) +bool PU::getTriangleWeights( const PredictionUnit& pu, MergeCtx &triangleMrgCtx, const uint8_t candIdx0, const uint8_t candIdx1 ) { - RefPicList RefPicListCand0 = TriangleMrgCtx.interDirNeighbours[CandIdx0] == 1 ? REF_PIC_LIST_0 : REF_PIC_LIST_1; - RefPicList RefPicListCand1 = TriangleMrgCtx.interDirNeighbours[CandIdx1] == 1 ? REF_PIC_LIST_0 : REF_PIC_LIST_1; - int32_t RefPicPoc0 = pu.cs->slice->getRefPOC( RefPicListCand0, TriangleMrgCtx.mvFieldNeighbours[ (CandIdx0 << 1) + RefPicListCand0 ].refIdx ); - int32_t RefPicPoc1 = pu.cs->slice->getRefPOC( RefPicListCand1, TriangleMrgCtx.mvFieldNeighbours[ (CandIdx1 << 1) + RefPicListCand1 ].refIdx ); + RefPicList refPicListCand0 = triangleMrgCtx.interDirNeighbours[candIdx0] == 1 ? REF_PIC_LIST_0 : REF_PIC_LIST_1; + RefPicList refPicListCand1 = triangleMrgCtx.interDirNeighbours[candIdx1] == 1 ? REF_PIC_LIST_0 : REF_PIC_LIST_1; + int32_t refPicPoc0 = pu.cs->slice->getRefPOC( refPicListCand0, triangleMrgCtx.mvFieldNeighbours[ (candIdx0 << 1) + refPicListCand0 ].refIdx ); + int32_t refPicPoc1 = pu.cs->slice->getRefPOC( refPicListCand1, triangleMrgCtx.mvFieldNeighbours[ (candIdx1 << 1) + refPicListCand1 ].refIdx ); - if( RefPicPoc0 != RefPicPoc1 ) + if( refPicPoc0 != refPicPoc1 ) { // different reference picture return true; @@ -4333,9 +4333,9 @@ bool PU::isTriangleEhancedWeight( const PredictionUnit& pu, MergeCtx &TriangleMr // same reference picture, but mv difference is larger than 16 pel int32_t threshold = 16 << 4; - Mv DiffMv = TriangleMrgCtx.mvFieldNeighbours[(CandIdx0 << 1) + RefPicListCand0].mv - TriangleMrgCtx.mvFieldNeighbours[(CandIdx1 << 1) + RefPicListCand1].mv; + Mv diffMv = triangleMrgCtx.mvFieldNeighbours[(candIdx0 << 1) + refPicListCand0].mv - triangleMrgCtx.mvFieldNeighbours[(candIdx1 << 1) + refPicListCand1].mv; - if( DiffMv.getAbsHor() > threshold || DiffMv.getAbsVer() > threshold ) + if( diffMv.getAbsHor() > threshold || diffMv.getAbsVer() > threshold ) { return true; } @@ -4343,105 +4343,105 @@ bool PU::isTriangleEhancedWeight( const PredictionUnit& pu, MergeCtx &TriangleMr return false; } -void PU::spanTriangleMotionInfo( PredictionUnit &pu, MergeCtx &TriangleMrgCtx, const uint8_t MergeIdx, const bool SplitDir, const uint8_t CandIdx0, const uint8_t CandIdx1 ) +void PU::spanTriangleMotionInfo( PredictionUnit &pu, MergeCtx &triangleMrgCtx, const uint8_t mergeIdx, const bool splitDir, const uint8_t candIdx0, const uint8_t candIdx1 ) { - pu.mergeIdx = MergeIdx; + pu.mergeIdx = mergeIdx; MotionBuf mb = pu.getMotionBuf(); - MotionInfo BiMv; - BiMv.isInter = true; + MotionInfo biMv; + biMv.isInter = true; - if( TriangleMrgCtx.interDirNeighbours[CandIdx0] == 1 && TriangleMrgCtx.interDirNeighbours[CandIdx1] == 2 ) + 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; + 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 ) + 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; + 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 ) + else if( triangleMrgCtx.interDirNeighbours[candIdx0] == 1 && triangleMrgCtx.interDirNeighbours[candIdx1] == 1 ) { - int32_t refIdx = mappingRefPic( pu, pu.cs->slice->getRefPOC( REF_PIC_LIST_0, TriangleMrgCtx.mvFieldNeighbours[CandIdx1 << 1].refIdx ), REF_PIC_LIST_1 ); + int32_t refIdx = mappingRefPic( pu, pu.cs->slice->getRefPOC( REF_PIC_LIST_0, triangleMrgCtx.mvFieldNeighbours[candIdx1 << 1].refIdx ), REF_PIC_LIST_1 ); if( refIdx != -1 ) { - BiMv.interDir = 3; - BiMv.mv[0] = TriangleMrgCtx.mvFieldNeighbours[CandIdx0 << 1].mv; - BiMv.mv[1] = TriangleMrgCtx.mvFieldNeighbours[CandIdx1 << 1].mv; - BiMv.refIdx[0] = TriangleMrgCtx.mvFieldNeighbours[CandIdx0 << 1].refIdx; - BiMv.refIdx[1] = refIdx; + biMv.interDir = 3; + biMv.mv[0] = triangleMrgCtx.mvFieldNeighbours[candIdx0 << 1].mv; + biMv.mv[1] = triangleMrgCtx.mvFieldNeighbours[candIdx1 << 1].mv; + biMv.refIdx[0] = triangleMrgCtx.mvFieldNeighbours[candIdx0 << 1].refIdx; + biMv.refIdx[1] = refIdx; } else { - refIdx = mappingRefPic( pu, pu.cs->slice->getRefPOC( REF_PIC_LIST_0, TriangleMrgCtx.mvFieldNeighbours[CandIdx0 << 1].refIdx), REF_PIC_LIST_1 ); - BiMv.interDir = ( refIdx != -1 ) ? 3 : 1; - BiMv.mv[0] = ( refIdx != -1 ) ? TriangleMrgCtx.mvFieldNeighbours[CandIdx1 << 1].mv : TriangleMrgCtx.mvFieldNeighbours[CandIdx0 << 1].mv; - BiMv.mv[1] = ( refIdx != -1 ) ? TriangleMrgCtx.mvFieldNeighbours[CandIdx0 << 1].mv : Mv(0, 0); - BiMv.refIdx[0] = ( refIdx != -1 ) ? TriangleMrgCtx.mvFieldNeighbours[CandIdx1 << 1].refIdx : TriangleMrgCtx.mvFieldNeighbours[CandIdx0 << 1].refIdx; - BiMv.refIdx[1] = ( refIdx != -1 ) ? refIdx : -1; + refIdx = mappingRefPic( pu, pu.cs->slice->getRefPOC( REF_PIC_LIST_0, triangleMrgCtx.mvFieldNeighbours[candIdx0 << 1].refIdx), REF_PIC_LIST_1 ); + biMv.interDir = ( refIdx != -1 ) ? 3 : 1; + biMv.mv[0] = ( refIdx != -1 ) ? triangleMrgCtx.mvFieldNeighbours[candIdx1 << 1].mv : triangleMrgCtx.mvFieldNeighbours[candIdx0 << 1].mv; + biMv.mv[1] = ( refIdx != -1 ) ? triangleMrgCtx.mvFieldNeighbours[candIdx0 << 1].mv : Mv(0, 0); + biMv.refIdx[0] = ( refIdx != -1 ) ? triangleMrgCtx.mvFieldNeighbours[candIdx1 << 1].refIdx : triangleMrgCtx.mvFieldNeighbours[candIdx0 << 1].refIdx; + biMv.refIdx[1] = ( refIdx != -1 ) ? refIdx : -1; } } - else if( TriangleMrgCtx.interDirNeighbours[CandIdx0] == 2 && TriangleMrgCtx.interDirNeighbours[CandIdx1] == 2 ) + else if( triangleMrgCtx.interDirNeighbours[candIdx0] == 2 && triangleMrgCtx.interDirNeighbours[candIdx1] == 2 ) { - int32_t refIdx = mappingRefPic( pu, pu.cs->slice->getRefPOC( REF_PIC_LIST_1, TriangleMrgCtx.mvFieldNeighbours[(CandIdx1 << 1) + 1].refIdx ), REF_PIC_LIST_0 ); + int32_t refIdx = mappingRefPic( pu, pu.cs->slice->getRefPOC( REF_PIC_LIST_1, triangleMrgCtx.mvFieldNeighbours[(candIdx1 << 1) + 1].refIdx ), REF_PIC_LIST_0 ); if( refIdx != -1 ) { - BiMv.interDir = 3; - BiMv.mv[0] = TriangleMrgCtx.mvFieldNeighbours[(CandIdx1 << 1) + 1].mv; - BiMv.mv[1] = TriangleMrgCtx.mvFieldNeighbours[(CandIdx0 << 1) + 1].mv; - BiMv.refIdx[0] = refIdx; - BiMv.refIdx[1] = TriangleMrgCtx.mvFieldNeighbours[(CandIdx0 << 1) + 1].refIdx; + biMv.interDir = 3; + biMv.mv[0] = triangleMrgCtx.mvFieldNeighbours[(candIdx1 << 1) + 1].mv; + biMv.mv[1] = triangleMrgCtx.mvFieldNeighbours[(candIdx0 << 1) + 1].mv; + biMv.refIdx[0] = refIdx; + biMv.refIdx[1] = triangleMrgCtx.mvFieldNeighbours[(candIdx0 << 1) + 1].refIdx; } else { - refIdx = mappingRefPic( pu, pu.cs->slice->getRefPOC( REF_PIC_LIST_1, TriangleMrgCtx.mvFieldNeighbours[(CandIdx0 << 1) + 1].refIdx ), REF_PIC_LIST_0 ); - BiMv.interDir = ( refIdx != -1 ) ? 3 : 2; - BiMv.mv[0] = ( refIdx != -1 ) ? TriangleMrgCtx.mvFieldNeighbours[(CandIdx0 << 1) + 1].mv : Mv(0, 0); - BiMv.mv[1] = ( refIdx != -1 ) ? TriangleMrgCtx.mvFieldNeighbours[(CandIdx1 << 1) + 1].mv : TriangleMrgCtx.mvFieldNeighbours[(CandIdx0 << 1) + 1].mv; - BiMv.refIdx[0] = ( refIdx != -1 ) ? refIdx : -1; - BiMv.refIdx[1] = ( refIdx != -1 ) ? TriangleMrgCtx.mvFieldNeighbours[(CandIdx1 << 1) + 1].refIdx : TriangleMrgCtx.mvFieldNeighbours[(CandIdx0 << 1) + 1].refIdx; + refIdx = mappingRefPic( pu, pu.cs->slice->getRefPOC( REF_PIC_LIST_1, triangleMrgCtx.mvFieldNeighbours[(candIdx0 << 1) + 1].refIdx ), REF_PIC_LIST_0 ); + biMv.interDir = ( refIdx != -1 ) ? 3 : 2; + biMv.mv[0] = ( refIdx != -1 ) ? triangleMrgCtx.mvFieldNeighbours[(candIdx0 << 1) + 1].mv : Mv(0, 0); + biMv.mv[1] = ( refIdx != -1 ) ? triangleMrgCtx.mvFieldNeighbours[(candIdx1 << 1) + 1].mv : triangleMrgCtx.mvFieldNeighbours[(candIdx0 << 1) + 1].mv; + biMv.refIdx[0] = ( refIdx != -1 ) ? refIdx : -1; + biMv.refIdx[1] = ( refIdx != -1 ) ? triangleMrgCtx.mvFieldNeighbours[(candIdx1 << 1) + 1].refIdx : triangleMrgCtx.mvFieldNeighbours[(candIdx0 << 1) + 1].refIdx; } } - int32_t IdxW = (int32_t)g_aucLog2[pu.lwidth() ] - MIN_CU_LOG2; - int32_t IdxH = (int32_t)g_aucLog2[pu.lheight()] - MIN_CU_LOG2; + int32_t idxW = (int32_t)(g_aucLog2[pu.lwidth() ] - MIN_CU_LOG2); + int32_t idxH = (int32_t)(g_aucLog2[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 ) + 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 ).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]; } - else if( g_TriangleMvStorage[SplitDir][IdxH][IdxW][y][x] == 0 ) + 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 ).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; } 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 ).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; } } } diff --git a/source/Lib/CommonLib/UnitTools.h b/source/Lib/CommonLib/UnitTools.h index 445c86de6..2b5175497 100644 --- a/source/Lib/CommonLib/UnitTools.h +++ b/source/Lib/CommonLib/UnitTools.h @@ -174,10 +174,10 @@ namespace PU int getNarrowShape (const int width, const int height); #endif #if JVET_L0124_L0208_TRIANGLE - void getTriangleMergeCandidates (const PredictionUnit &pu, MergeCtx& TriangleMrgCtx); - bool isUniqueTriangleCandidates (const PredictionUnit &pu, MergeCtx& TriangleMrgCtx); - bool isTriangleEhancedWeight (const PredictionUnit &pu, MergeCtx &TriangleMrgCtx, const uint8_t CandIdx0, const uint8_t CandIdx1); - void spanTriangleMotionInfo ( PredictionUnit &pu, MergeCtx &TriangleMrgCtx, const uint8_t MergeIdx, const bool SplitDir, const uint8_t CandIdx0, const uint8_t CandIdx1); + void getTriangleMergeCandidates (const PredictionUnit &pu, MergeCtx &triangleMrgCtx); + bool isUniqueTriangleCandidates (const PredictionUnit &pu, MergeCtx &triangleMrgCtx); + bool getTriangleWeights (const PredictionUnit &pu, MergeCtx &triangleMrgCtx, const uint8_t candIdx0, const uint8_t candIdx1); + void spanTriangleMotionInfo ( PredictionUnit &pu, MergeCtx &triangleMrgCtx, const uint8_t mergeIdx, const bool splitDir, const uint8_t candIdx0, const uint8_t candIdx1); int32_t mappingRefPic (const PredictionUnit &pu, int32_t refPicPoc, bool targetRefPicList); #endif } diff --git a/source/Lib/DecoderLib/DecCu.cpp b/source/Lib/DecoderLib/DecCu.cpp index 2ea919792..f1ccaae1b 100644 --- a/source/Lib/DecoderLib/DecCu.cpp +++ b/source/Lib/DecoderLib/DecCu.cpp @@ -318,11 +318,11 @@ void DecCu::xReconInter(CodingUnit &cu) if( cu.triangle ) { const uint8_t mergeIdx = cu.firstPU->mergeIdx; - const bool SplitDir = g_TriangleCombination[mergeIdx][0]; - const uint8_t CandIdx0 = g_TriangleCombination[mergeIdx][1]; - const uint8_t CandIdx1 = g_TriangleCombination[mergeIdx][2]; - m_pcInterPred->motionCompensation4Triangle( cu, m_TriangleMrgCtx, SplitDir, CandIdx0, CandIdx1 ); - PU::spanTriangleMotionInfo( *cu.firstPU, m_TriangleMrgCtx, mergeIdx, SplitDir, CandIdx0, CandIdx1 ); + const bool splitDir = g_triangleCombination[mergeIdx][0]; + const uint8_t candIdx0 = g_triangleCombination[mergeIdx][1]; + const uint8_t candIdx1 = g_triangleCombination[mergeIdx][2]; + m_pcInterPred->motionCompensation4Triangle( cu, m_triangleMrgCtx, splitDir, candIdx0, candIdx1 ); + PU::spanTriangleMotionInfo( *cu.firstPU, m_triangleMrgCtx, mergeIdx, splitDir, candIdx0, candIdx1 ); } else { @@ -505,7 +505,7 @@ void DecCu::xDeriveCUMV( CodingUnit &cu ) #if JVET_L0124_L0208_TRIANGLE if( pu.cu->triangle ) { - PU::getTriangleMergeCandidates( pu, m_TriangleMrgCtx ); + PU::getTriangleMergeCandidates( pu, m_triangleMrgCtx ); } else { diff --git a/source/Lib/DecoderLib/DecCu.h b/source/Lib/DecoderLib/DecCu.h index 4e98da082..3a9f46d90 100644 --- a/source/Lib/DecoderLib/DecCu.h +++ b/source/Lib/DecoderLib/DecCu.h @@ -94,7 +94,7 @@ private: MotionInfo m_SubPuMiBuf[(MAX_CU_SIZE * MAX_CU_SIZE) >> (MIN_CU_LOG2 << 1)]; #if JVET_L0124_L0208_TRIANGLE - MergeCtx m_TriangleMrgCtx; + MergeCtx m_triangleMrgCtx; #endif }; diff --git a/source/Lib/EncoderLib/EncCu.cpp b/source/Lib/EncoderLib/EncCu.cpp index 2572d4cc6..44a87cc3e 100644 --- a/source/Lib/EncoderLib/EncCu.cpp +++ b/source/Lib/EncoderLib/EncCu.cpp @@ -200,7 +200,7 @@ void EncCu::create( EncCfg* encCfg ) #if JVET_L0124_L0208_TRIANGLE for( unsigned ui = 0; ui < TRIANGLE_MAX_NUM_CANDS; ui++ ) { - m_acTriangleWeightBuffer[ui].create( chromaFormat, Area( 0, 0, uiMaxWidth, uiMaxHeight ) ); + m_acTriangleWeightedBuffer[ui].create( chromaFormat, Area( 0, 0, uiMaxWidth, uiMaxHeight ) ); } #endif @@ -310,7 +310,7 @@ void EncCu::destroy() #if JVET_L0124_L0208_TRIANGLE for( unsigned ui = 0; ui < TRIANGLE_MAX_NUM_CANDS; ui++ ) { - m_acTriangleWeightBuffer[ui].destroy(); + m_acTriangleWeightedBuffer[ui].destroy(); } #endif } @@ -2378,19 +2378,19 @@ void EncCu::xCheckRDCostMergeTriangle2Nx2N( CodingStructure *&tempCS, CodingStru tempCS->initStructData( encTestMode.qp, encTestMode.lossless ); - bool TrianglecandHasNoResidual[TRIANGLE_MAX_NUM_CANDS]; - for( int MergeCand = 0; MergeCand < TRIANGLE_MAX_NUM_CANDS; MergeCand++ ) + bool trianglecandHasNoResidual[TRIANGLE_MAX_NUM_CANDS]; + for( int mergeCand = 0; mergeCand < TRIANGLE_MAX_NUM_CANDS; mergeCand++ ) { - TrianglecandHasNoResidual[MergeCand] = false; + trianglecandHasNoResidual[mergeCand] = false; } bool bestIsSkip = m_pcEncCfg->getUseFastDecisionForMerge() ? bestCS->getCU( partitioner.chType )->rootCbf == 0 : false; - uint8_t NumTriangleCandidate = TRIANGLE_MAX_NUM_CANDS; - uint8_t TriangleNumMrgSATDCand = TRIANGLE_MAX_NUM_SATD_CANDS; - PelUnitBuf acTriangleBuffer[TRIANGLE_MAX_NUM_UNI_CANDS]; - PelUnitBuf acTriangleWeightBuffer[TRIANGLE_MAX_NUM_CANDS]; - static_vector<uint8_t, TRIANGLE_MAX_NUM_CANDS> TriangleRdModeList; - static_vector<double, TRIANGLE_MAX_NUM_CANDS> TrianglecandCostList; + uint8_t numTriangleCandidate = TRIANGLE_MAX_NUM_CANDS; + uint8_t triangleNumMrgSATDCand = TRIANGLE_MAX_NUM_SATD_CANDS; + PelUnitBuf triangleBuffer[TRIANGLE_MAX_NUM_UNI_CANDS]; + PelUnitBuf triangleWeightedBuffer[TRIANGLE_MAX_NUM_CANDS]; + static_vector<uint8_t, TRIANGLE_MAX_NUM_CANDS> triangleRdModeList; + static_vector<double, TRIANGLE_MAX_NUM_CANDS> tianglecandCostList; if( auto blkCache = dynamic_cast< CacheBlkInfoCtrl* >( m_modeCtrl ) ) { @@ -2398,14 +2398,14 @@ void EncCu::xCheckRDCostMergeTriangle2Nx2N( CodingStructure *&tempCS, CodingStru } DistParam distParam; - const bool UseHadamard = !encTestMode.lossless; - m_pcRdCost->setDistParam( distParam, tempCS->getOrgBuf().Y(), m_acMergeBuffer[0].Y(), sps.getBitDepth( CHANNEL_TYPE_LUMA ), COMPONENT_Y, UseHadamard ); + const bool useHadamard = !encTestMode.lossless; + m_pcRdCost->setDistParam( distParam, tempCS->getOrgBuf().Y(), m_acMergeBuffer[0].Y(), sps.getBitDepth( CHANNEL_TYPE_LUMA ), COMPONENT_Y, useHadamard ); const UnitArea localUnitArea( tempCS->area.chromaFormat, Area( 0, 0, tempCS->area.Y().width, tempCS->area.Y().height) ); const double sqrtLambdaForFirstPass = m_pcRdCost->getMotionLambda(encTestMode.lossless); - MergeCtx TriangleMrgCtx; + MergeCtx triangleMrgCtx; { CodingUnit cu( tempCS->area ); cu.cs = tempCS; @@ -2425,24 +2425,24 @@ void EncCu::xCheckRDCostMergeTriangle2Nx2N( CodingStructure *&tempCS, CodingStru pu.cs = tempCS; - PU::getTriangleMergeCandidates( pu, TriangleMrgCtx ); - for( uint8_t MergeCand = 0; MergeCand < TRIANGLE_MAX_NUM_UNI_CANDS; MergeCand++ ) + PU::getTriangleMergeCandidates( pu, triangleMrgCtx ); + for( uint8_t mergeCand = 0; mergeCand < TRIANGLE_MAX_NUM_UNI_CANDS; mergeCand++ ) { - acTriangleBuffer[MergeCand] = m_acMergeBuffer[MergeCand].getBuf(localUnitArea); - TriangleMrgCtx.setMergeInfo( pu, MergeCand ); - PU::spanMotionInfo( pu, TriangleMrgCtx ); + triangleBuffer[mergeCand] = m_acMergeBuffer[mergeCand].getBuf(localUnitArea); + triangleMrgCtx.setMergeInfo( pu, mergeCand ); + PU::spanMotionInfo( pu, triangleMrgCtx ); - m_pcInterSearch->motionCompensation( pu, acTriangleBuffer[MergeCand] ); + m_pcInterSearch->motionCompensation( pu, triangleBuffer[mergeCand] ); } } - bool TempBufSet = bestIsSkip ? false : true; - TriangleNumMrgSATDCand = bestIsSkip ? TRIANGLE_MAX_NUM_CANDS : TRIANGLE_MAX_NUM_SATD_CANDS; + bool tempBufSet = bestIsSkip ? false : true; + triangleNumMrgSATDCand = bestIsSkip ? TRIANGLE_MAX_NUM_CANDS : TRIANGLE_MAX_NUM_SATD_CANDS; if( bestIsSkip ) { for( uint8_t i = 0; i < TRIANGLE_MAX_NUM_CANDS; i++ ) { - TriangleRdModeList.push_back(i); + triangleRdModeList.push_back(i); } } else @@ -2467,63 +2467,62 @@ void EncCu::xCheckRDCostMergeTriangle2Nx2N( CodingStructure *&tempCS, CodingStru PredictionUnit &pu = tempCS->addPU( cu, partitioner.chType ); - int32_t Ratio = abs(g_aucLog2[cu.lwidth()] - g_aucLog2[cu.lheight()]); - if( Ratio >= 2 ) + if( abs(g_aucLog2[cu.lwidth()] - g_aucLog2[cu.lheight()]) >= 2 ) { - NumTriangleCandidate = 30; + numTriangleCandidate = 30; } else { - NumTriangleCandidate = TRIANGLE_MAX_NUM_CANDS; + numTriangleCandidate = TRIANGLE_MAX_NUM_CANDS; } - for( uint8_t MergeCand = 0; MergeCand < NumTriangleCandidate; MergeCand++ ) + for( uint8_t mergeCand = 0; mergeCand < numTriangleCandidate; mergeCand++ ) { - bool SplitDir = g_TriangleCombination[MergeCand][0]; - uint8_t CandIdx0 = g_TriangleCombination[MergeCand][1]; - uint8_t CandIdx1 = g_TriangleCombination[MergeCand][2]; + bool splitDir = g_triangleCombination[mergeCand][0]; + uint8_t candIdx0 = g_triangleCombination[mergeCand][1]; + uint8_t candIdx1 = g_triangleCombination[mergeCand][2]; - pu.mergeIdx = MergeCand; + pu.mergeIdx = mergeCand; pu.mergeFlag = true; - acTriangleWeightBuffer[MergeCand] = m_acTriangleWeightBuffer[MergeCand].getBuf( localUnitArea ); - acTriangleBuffer[CandIdx0] = m_acMergeBuffer[CandIdx0].getBuf( localUnitArea ); - acTriangleBuffer[CandIdx1] = m_acMergeBuffer[CandIdx1].getBuf( localUnitArea ); + triangleWeightedBuffer[mergeCand] = m_acTriangleWeightedBuffer[mergeCand].getBuf( localUnitArea ); + triangleBuffer[candIdx0] = m_acMergeBuffer[candIdx0].getBuf( localUnitArea ); + triangleBuffer[candIdx1] = m_acMergeBuffer[candIdx1].getBuf( localUnitArea ); - m_pcInterSearch->TriangleWeighting( pu, PU::isTriangleEhancedWeight(pu, TriangleMrgCtx, CandIdx0, CandIdx1), SplitDir, CHANNEL_TYPE_LUMA, acTriangleWeightBuffer[MergeCand], acTriangleBuffer[CandIdx0], acTriangleBuffer[CandIdx1] ); + m_pcInterSearch->weightedTriangleBlk( pu, PU::getTriangleWeights(pu, triangleMrgCtx, candIdx0, candIdx1), splitDir, CHANNEL_TYPE_LUMA, triangleWeightedBuffer[mergeCand], triangleBuffer[candIdx0], triangleBuffer[candIdx1] ); - distParam.cur = acTriangleWeightBuffer[MergeCand].Y(); + distParam.cur = triangleWeightedBuffer[mergeCand].Y(); Distortion uiSad = distParam.distFunc( distParam ); - uint32_t uiBitsCand = g_TriangleIdxBins[MergeCand]; + uint32_t uiBitsCand = g_triangleIdxBins[mergeCand]; double cost = (double)uiSad + (double)uiBitsCand * sqrtLambdaForFirstPass; - updateCandList( MergeCand, cost, TriangleRdModeList, TrianglecandCostList, TriangleNumMrgSATDCand ); + updateCandList( mergeCand, cost, triangleRdModeList, tianglecandCostList, triangleNumMrgSATDCand ); } // limit number of candidates using SATD-costs - for( uint8_t i = 0; i < TriangleNumMrgSATDCand; i++ ) + for( uint8_t i = 0; i < triangleNumMrgSATDCand; i++ ) { - if( TrianglecandCostList[i] > MRG_FAST_RATIO * TrianglecandCostList[0] || TrianglecandCostList[i] > getMergeBestSATDCost() ) + if( tianglecandCostList[i] > MRG_FAST_RATIO * tianglecandCostList[0] || tianglecandCostList[i] > getMergeBestSATDCost() ) { - TriangleNumMrgSATDCand = i; + triangleNumMrgSATDCand = i; break; } } // perform chroma weighting process - for( uint8_t i = 0; i < TriangleNumMrgSATDCand; i++ ) + for( uint8_t i = 0; i < triangleNumMrgSATDCand; i++ ) { - uint8_t MergeCand = TriangleRdModeList[i]; - bool SplitDir = g_TriangleCombination[MergeCand][0]; - uint8_t CandIdx0 = g_TriangleCombination[MergeCand][1]; - uint8_t CandIdx1 = g_TriangleCombination[MergeCand][2]; + uint8_t mergeCand = triangleRdModeList[i]; + bool splitDir = g_triangleCombination[mergeCand][0]; + uint8_t candIdx0 = g_triangleCombination[mergeCand][1]; + uint8_t candIdx1 = g_triangleCombination[mergeCand][2]; - pu.mergeIdx = MergeCand; + pu.mergeIdx = mergeCand; pu.mergeFlag = true; - m_pcInterSearch->TriangleWeighting( pu, PU::isTriangleEhancedWeight(pu, TriangleMrgCtx, CandIdx0, CandIdx1), SplitDir, CHANNEL_TYPE_CHROMA, acTriangleWeightBuffer[MergeCand], acTriangleBuffer[CandIdx0], acTriangleBuffer[CandIdx1] ); + m_pcInterSearch->weightedTriangleBlk( pu, PU::getTriangleWeights(pu, triangleMrgCtx, candIdx0, candIdx1), splitDir, CHANNEL_TYPE_CHROMA, triangleWeightedBuffer[mergeCand], triangleBuffer[candIdx0], triangleBuffer[candIdx1] ); } tempCS->initStructData( encTestMode.qp, encTestMode.lossless ); @@ -2531,21 +2530,21 @@ void EncCu::xCheckRDCostMergeTriangle2Nx2N( CodingStructure *&tempCS, CodingStru { const uint8_t iteration = encTestMode.lossless ? 1 : 2; - for( uint8_t NoResidualPass = 0; NoResidualPass < iteration; NoResidualPass++ ) + for( uint8_t noResidualPass = 0; noResidualPass < iteration; noResidualPass++ ) { - for( uint8_t MrgHADIdx = 0; MrgHADIdx < TriangleNumMrgSATDCand; MrgHADIdx++ ) + for( uint8_t mrgHADIdx = 0; mrgHADIdx < triangleNumMrgSATDCand; mrgHADIdx++ ) { - uint8_t MergeCand = TriangleRdModeList[MrgHADIdx]; + uint8_t mergeCand = triangleRdModeList[mrgHADIdx]; - if ( ( (NoResidualPass != 0) && TrianglecandHasNoResidual[MergeCand] ) - || ( (NoResidualPass == 0) && bestIsSkip ) ) + if ( ( (noResidualPass != 0) && trianglecandHasNoResidual[mergeCand] ) + || ( (noResidualPass == 0) && bestIsSkip ) ) { continue; } - bool SplitDir = g_TriangleCombination[MergeCand][0]; - uint8_t CandIdx0 = g_TriangleCombination[MergeCand][1]; - uint8_t CandIdx1 = g_TriangleCombination[MergeCand][2]; + bool splitDir = g_triangleCombination[mergeCand][0]; + uint8_t candIdx0 = g_triangleCombination[mergeCand][1]; + uint8_t candIdx1 = g_triangleCombination[mergeCand][2]; CodingUnit &cu = tempCS->addCU(tempCS->area, partitioner.chType); @@ -2566,31 +2565,31 @@ void EncCu::xCheckRDCostMergeTriangle2Nx2N( CodingStructure *&tempCS, CodingStru #endif PredictionUnit &pu = tempCS->addPU(cu, partitioner.chType); - pu.mergeIdx = MergeCand; + pu.mergeIdx = mergeCand; pu.mergeFlag = true; - PU::spanTriangleMotionInfo(pu, TriangleMrgCtx, MergeCand, SplitDir, CandIdx0, CandIdx1 ); + PU::spanTriangleMotionInfo(pu, triangleMrgCtx, mergeCand, splitDir, candIdx0, candIdx1 ); - if( TempBufSet ) + if( tempBufSet ) { - tempCS->getPredBuf().copyFrom( acTriangleWeightBuffer[MergeCand] ); + tempCS->getPredBuf().copyFrom( triangleWeightedBuffer[mergeCand] ); } else { - acTriangleBuffer[CandIdx0] = m_acMergeBuffer[CandIdx0].getBuf( localUnitArea ); - acTriangleBuffer[CandIdx1] = m_acMergeBuffer[CandIdx1].getBuf( localUnitArea ); + triangleBuffer[candIdx0] = m_acMergeBuffer[candIdx0].getBuf( localUnitArea ); + triangleBuffer[candIdx1] = m_acMergeBuffer[candIdx1].getBuf( localUnitArea ); PelUnitBuf predBuf = tempCS->getPredBuf(); - m_pcInterSearch->TriangleWeighting( pu, PU::isTriangleEhancedWeight(pu, TriangleMrgCtx, CandIdx0, CandIdx1), SplitDir, MAX_NUM_CHANNEL_TYPE, predBuf, acTriangleBuffer[CandIdx0], acTriangleBuffer[CandIdx1] ); + m_pcInterSearch->weightedTriangleBlk( pu, PU::getTriangleWeights(pu, triangleMrgCtx, candIdx0, candIdx1), splitDir, MAX_NUM_CHANNEL_TYPE, predBuf, triangleBuffer[candIdx0], triangleBuffer[candIdx1] ); } - xEncodeInterResidual( tempCS, bestCS, partitioner, encTestMode, NoResidualPass, NULL, true, ( (NoResidualPass == 0 ) ? &TrianglecandHasNoResidual[MergeCand] : NULL ) ); + xEncodeInterResidual( tempCS, bestCS, partitioner, encTestMode, noResidualPass, NULL, true, ( (noResidualPass == 0 ) ? &trianglecandHasNoResidual[mergeCand] : NULL ) ); if (m_pcEncCfg->getUseFastDecisionForMerge() && !bestIsSkip) { bestIsSkip = bestCS->getCU(partitioner.chType)->rootCbf == 0; } tempCS->initStructData(encTestMode.qp, encTestMode.lossless); - }// end loop MrgHADIdx + }// end loop mrgHADIdx } } } diff --git a/source/Lib/EncoderLib/EncCu.h b/source/Lib/EncoderLib/EncCu.h index 60e254f22..a85ecdf41 100644 --- a/source/Lib/EncoderLib/EncCu.h +++ b/source/Lib/EncoderLib/EncCu.h @@ -121,7 +121,7 @@ private: PelStorage m_acMergeBuffer[MRG_MAX_NUM_CANDS]; #endif #if JVET_L0124_L0208_TRIANGLE - PelStorage m_acTriangleWeightBuffer[TRIANGLE_MAX_NUM_CANDS]; // to store weighted prediction pixles + PelStorage m_acTriangleWeightedBuffer[TRIANGLE_MAX_NUM_CANDS]; // to store weighted prediction pixles double m_mergeBestSATDCost; #endif MotionInfo m_SubPuMiBuf [( MAX_CU_SIZE * MAX_CU_SIZE ) >> ( MIN_CU_LOG2 << 1 )]; -- GitLab