Commit 6178ac75 authored by Yan Zhang's avatar Yan Zhang

1/16-pel motion vector storage

Motion vecotrs are always stored with 1/16-pel precision and the
following strategies are followed:

1. Motion vector data in the buffer are always stored in high precision.
2. Motion vector used for motion compensation are always in high
precision.
3. Motion vector difference data are always in low precision.
4. Encoder side motion estimation always use low precision.
5. Motion vector bits calculation are always performed in low precision.
6. Candidates of motion vector prediction list are always in low
precision.
parent ad6f5903
......@@ -769,7 +769,11 @@ void MergeCtx::setMergeInfo( PredictionUnit& pu, int candIdx )
{
pu.cu->ibc = true;
pu.bv = pu.mv[REF_PIC_LIST_0];
#if REMOVE_MV_ADAPT_PREC
pu.bv >>= (2 + VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE);
#else
pu.bv >>= 2; // used for only integer resolution
#endif
}
#endif
#if JEM_TOOLS
......
......@@ -995,7 +995,11 @@ void InterPrediction::xPredInterBlk ( const ComponentID& compID, const Predictio
int iAddPrecShift = 0;
if( _mv.highPrec )
#if REMOVE_MV_ADAPT_PREC
if (pu.cs->sps->getSpsNext().getUseHighPrecMv())
#else
if (_mv.highPrec)
#endif
{
CHECKD( !pu.cs->sps->getSpsNext().getUseHighPrecMv(), "Found a high-precision motion vector, but the high-precision MV extension is disabled!" );
......@@ -1019,7 +1023,11 @@ void InterPrediction::xPredInterBlk ( const ComponentID& compID, const Predictio
int iAddPrecShift = 0;
#if REMOVE_MV_ADAPT_PREC
if (pu.cs->sps->getSpsNext().getUseHighPrecMv())
#else
if (_mv.highPrec)
#endif
{
CHECKD(!pu.cs->sps->getSpsNext().getUseHighPrecMv(), "Found a high-precision motion vector, but the high-precision MV extension is disabled!");
......@@ -1245,10 +1253,11 @@ void InterPrediction::xPredAffineBlk( const ComponentID& compID, const Predictio
Mv mvLT =_mv[0];
Mv mvRT =_mv[1];
Mv mvLB =_mv[2];
#if !REMOVE_MV_ADAPT_PREC
mvLT.setHighPrec();
mvRT.setHighPrec();
mvLB.setHighPrec();
#endif
// get affine sub-block width and height
const int width = pu.Y().width;
......@@ -1418,7 +1427,11 @@ void InterPrediction::xGetLICParams( const CodingUnit& cu,
int& scale,
int& offset )
{
#if REMOVE_MV_ADAPT_PREC
const int lumaShift = 2 + VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE;
#else
const int lumaShift = ( mv.highPrec ? 2 + VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE : 2 );
#endif
const int horShift = ( lumaShift + ::getComponentScaleX(compID, cu.chromaFormat) );
const int verShift = ( lumaShift + ::getComponentScaleY(compID, cu.chromaFormat) );
const int horIntMv = ( mv.getHor() + ( ( 1 << horShift ) >> 1 ) ) >> horShift;
......@@ -1446,7 +1459,11 @@ void InterPrediction::xGetLICParams( const CodingUnit& cu,
// above
if( cuAbove )
{
Mv subPelMv ( horIntMv << horShift, verIntMv << verShift, mv.highPrec );
#if REMOVE_MV_ADAPT_PREC
Mv subPelMv(horIntMv << horShift, verIntMv << verShift);
#else
Mv subPelMv(horIntMv << horShift, verIntMv << verShift, mv.highPrec);
#endif
clipMv ( subPelMv, cuAbove->lumaPos(), *cu.cs->sps );
const int hOff = ( subPelMv.getHor() >> horShift );
const int vOff = ( subPelMv.getVer() >> verShift ) - 1;
......@@ -1470,7 +1487,11 @@ void InterPrediction::xGetLICParams( const CodingUnit& cu,
// left
if( cuLeft )
{
Mv subPelMv ( horIntMv << horShift, verIntMv << verShift, mv.highPrec );
#if REMOVE_MV_ADAPT_PREC
Mv subPelMv(horIntMv << horShift, verIntMv << verShift);
#else
Mv subPelMv(horIntMv << horShift, verIntMv << verShift, mv.highPrec);
#endif
clipMv ( subPelMv, cuLeft->lumaPos(), *cu.cs->sps );
const int hOff = ( subPelMv.getHor() >> horShift ) - 1;
const int vOff = ( subPelMv.getVer() >> verShift );
......@@ -3607,10 +3628,12 @@ uint32_t InterPrediction::xFrucRefineMvSearch ( MvField* pBestMvField, RefPicLis
Mv mvOffset = pSearchOffset[nDirect];
mvOffset <<= nSearchStepShift;
MvField mvCand = mvCurCenter;
#if !REMOVE_MV_ADAPT_PREC
if( mvCand.mv.highPrec && !mvOffset.highPrec )
{
mvOffset.highPrec = true;
}
#endif
mvCand.mv += mvOffset;
#if DISTORTION_TYPE_BUGFIX
Distortion uiCost = (Distortion) xFrucGetMvCost(
......@@ -4029,7 +4052,11 @@ void InterPrediction::xPredInterLines( const PredictionUnit& pu, const Picture*
int iAddPrecShift = 0;
if( _mv.highPrec )
#if REMOVE_MV_ADAPT_PREC
if (pu.cs->sps->getSpsNext().getUseHighPrecMv())
#else
if (_mv.highPrec)
#endif
{
CHECK( !pu.cs->sps->getSpsNext().getUseHighPrecMv(), "Found a high-precision motion vector, but the high-precision MV extension is disabled!" );
......@@ -4083,7 +4110,11 @@ void InterPrediction::xFillPredBlckAndBorder( const PredictionUnit& pu, RefPicLi
const Picture* refPic = pu.cu->slice->getRefPic(eRefPicList, iRefIdx);
#if REMOVE_MV_ADAPT_PREC
const int nMVUnit = 2 + VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE;
#else
const int nMVUnit = 2;
#endif
int dstStride = MAX_CU_SIZE + DMVR_INTME_RANGE*2;
......@@ -4169,11 +4200,13 @@ void InterPrediction::xBIPMVRefine( PredictionUnit& pu, RefPicList eRefPicList,
Mv mvOffset = pSearchOffset[nDirect];
mvOffset <<= nSearchStepShift;
if( pu.cu->slice->getSPS()->getSpsNext().getUseHighPrecMv() )
#if !REMOVE_MV_ADAPT_PREC
if (pu.cu->slice->getSPS()->getSpsNext().getUseHighPrecMv())
{
CHECK( !cMvOrg.highPrec, "wrong" );
CHECK(!cMvOrg.highPrec, "wrong");
mvOffset.highPrec = true;
}
#endif
Mv cMvTemp = cMvCtr;
cMvTemp += mvOffset;
......@@ -4296,7 +4329,11 @@ void InterPrediction::xBIPMVRefine(PredictionUnit& pu, uint32_t nSearchStepShift
const int32_t refStride = m_cYuvPredTempL0.Y().stride;
for (SAD_POINT_INDEX nIdx = SAD_POINT_INDEX::BOTTOM; nIdx <= SAD_POINT_INDEX::TOP_LEFT; ++nIdx)
{
#if REMOVE_MV_ADAPT_PREC
Mv cMvDL0(m_pSearchOffset[nIdx]);
#else
Mv cMvDL0(m_pSearchOffset[nIdx], cMvOrgL0.highPrec);
#endif
const Pel *pRefL0 = m_cYuvPredTempL0.Y().bufAt(cMvDL0.getHor() + (cDistParam.MVDL0.getHor() >> nSearchStepShift), cMvDL0.getVer() + (cDistParam.MVDL0.getVer() >> nSearchStepShift));
const Mv cMvDL1(-cMvDL0);
const Pel* pRefL1 = m_cYuvPredTempL1.Y().bufAt(cMvDL1.getHor() + (cDistParam.MVDL1.getHor() >> nSearchStepShift), cMvDL1.getVer() + (cDistParam.MVDL1.getVer() >> nSearchStepShift));
......@@ -4408,7 +4445,11 @@ void InterPrediction::xBIPMVRefine(PredictionUnit& pu, uint32_t nSearchStepShift
const int32_t refStride = m_HalfPelFilteredBuffL0[0][1].Y().stride;
for (SAD_POINT_INDEX nIdx = SAD_POINT_INDEX::BOTTOM; nIdx <= SAD_POINT_INDEX::LEFT; ++nIdx)
{
Mv cMvDL0(m_pSearchOffset[nIdx], cMvOrgL0.highPrec);
#if REMOVE_MV_ADAPT_PREC
Mv cMvDL0(m_pSearchOffset[nIdx]);
#else
Mv cMvDL0(m_pSearchOffset[nIdx], cMvOrgL0.highPrec);
#endif
Mv cMvDL1(-cMvDL0);
const Pel *pRefL0 = m_filteredBlock[cMvDL0.getAbsHor()][cMvDL0.getAbsVer()][COMPONENT_Y];
const Pel *pRefL1 = m_filteredBlockL1[cMvDL1.getAbsHor()][cMvDL1.getAbsVer()];
......@@ -4496,7 +4537,11 @@ void InterPrediction::xGenerateFracPixel(PredictionUnit& pu, uint32_t nSearchSte
const uint32_t bufferWidth = restAlign ? cuWidth : cuWidth + alignSize;
const uint32_t bufferHeight = cuHeight + 1;
//(0,-/+1)
#if REMOVE_MV_ADAPT_PREC
Mv cMvL0(cMvOrgL0 + Mv(0, -1 << nSearchStepShift));
#else
Mv cMvL0(cMvOrgL0 + Mv(0, -1 << nSearchStepShift, cMvOrgL0.highPrec));
#endif
m_HalfPelFilteredBuffL0[0][1] = PelUnitBuf(pu.chromaFormat, PelBuf(m_filteredBlock[0][1][COMPONENT_Y], bufferStride, bufferWidth, bufferHeight));
clipMv(cMvL0, pu.cu->lumaPos(), *pu.cu->slice->getSPS());
xPredInterBlk(COMPONENT_Y, pu, pu.cu->slice->getRefPic(REF_PIC_LIST_0, pu.refIdx[REF_PIC_LIST_0]), cMvL0
......@@ -4506,7 +4551,11 @@ void InterPrediction::xGenerateFracPixel(PredictionUnit& pu, uint32_t nSearchSte
, cuWidth
, cuHeight + 1
);
#if REMOVE_MV_ADAPT_PREC
Mv cMvL1(cMvOrgL1 + Mv(0, -1 << nSearchStepShift));
#else
Mv cMvL1(cMvOrgL1 + Mv(0, -1 << nSearchStepShift, cMvOrgL1.highPrec));
#endif
m_HalfPelFilteredBuffL1[0][1] = PelUnitBuf(pu.chromaFormat, PelBuf(m_filteredBlockL1[0][1], bufferStride, bufferWidth, bufferHeight));
clipMv(cMvL1, pu.cu->lumaPos(), *pu.cu->slice->getSPS());
xPredInterBlk(COMPONENT_Y, pu, pu.cu->slice->getRefPic(REF_PIC_LIST_1, pu.refIdx[REF_PIC_LIST_1]), cMvL1
......@@ -4517,7 +4566,11 @@ void InterPrediction::xGenerateFracPixel(PredictionUnit& pu, uint32_t nSearchSte
, cuHeight + 1
);
//(-/+1,0)
#if REMOVE_MV_ADAPT_PREC
cMvL0 = cMvOrgL0 + Mv(-1 << nSearchStepShift, 0);
#else
cMvL0 = cMvOrgL0 + Mv(-1 << nSearchStepShift, 0, cMvOrgL0.highPrec);
#endif
m_HalfPelFilteredBuffL0[1][0] = PelUnitBuf(pu.chromaFormat, PelBuf(m_filteredBlock[1][0][COMPONENT_Y], bufferStride, bufferWidth, bufferHeight));
clipMv(cMvL0, pu.cu->lumaPos(), *pu.cu->slice->getSPS());
xPredInterBlk(COMPONENT_Y, pu, pu.cu->slice->getRefPic(REF_PIC_LIST_0, pu.refIdx[REF_PIC_LIST_0]), cMvL0
......@@ -4527,7 +4580,11 @@ void InterPrediction::xGenerateFracPixel(PredictionUnit& pu, uint32_t nSearchSte
, bufferWidth
, cuHeight
);
#if REMOVE_MV_ADAPT_PREC
cMvL1 = cMvOrgL1 + Mv(-1 << nSearchStepShift, 0);
#else
cMvL1 = cMvOrgL1 + Mv(-1 << nSearchStepShift, 0, cMvOrgL1.highPrec);
#endif
m_HalfPelFilteredBuffL1[1][0] = PelUnitBuf(pu.chromaFormat, PelBuf(m_filteredBlockL1[1][0], bufferStride, bufferWidth, bufferHeight));
clipMv(cMvL1, pu.cu->lumaPos(), *pu.cu->slice->getSPS());
xPredInterBlk(COMPONENT_Y, pu, pu.cu->slice->getRefPic(REF_PIC_LIST_1, pu.refIdx[REF_PIC_LIST_1]), cMvL1
......@@ -4557,8 +4614,10 @@ void InterPrediction::xProcessDMVR( PredictionUnit& pu, PelUnitBuf &pcYuvDst, co
if( pu.cu->slice->getSPS()->getSpsNext().getUseHighPrecMv() )
{
searchStepShift += 2;
#if !REMOVE_MV_ADAPT_PREC
pu.mv[0].setHighPrec();
pu.mv[1].setHighPrec();
#endif
}
#if !DMVR_JVET_K0217
#if JVET_K0248_GBI
......@@ -4635,9 +4694,17 @@ void InterPrediction::xProcessDMVR( PredictionUnit& pu, PelUnitBuf &pcYuvDst, co
DistParam cDistParam;
MRSADtype minCost = std::numeric_limits<MRSADtype>::max();
#if REMOVE_MV_ADAPT_PREC
const Mv mvBlkExt(m_searchRange << searchStepShift);
#else
const Mv mvBlkExt(m_searchRange << searchStepShift, pu.mv[REF_PIC_LIST_0].highPrec);
#endif
const SizeType MC_extension = m_searchRange << 1;
#if REMOVE_MV_ADAPT_PREC
const Mv searchOffsetMv(-(int32_t)(m_searchRange << searchStepShift));
#else
const Mv searchOffsetMv(-(int32_t)(m_searchRange << searchStepShift), pu.mv[REF_PIC_LIST_0].highPrec);
#endif
const uint32_t dstStride = MAX_CU_SIZE + m_bufferWidthExtSize;
m_cYuvPredTempL0 = PelUnitBuf(pu.chromaFormat, PelBuf(m_cYuvPredTempDMVRL0, dstStride, cuSize.width + MC_extension, cuSize.height + MC_extension));
......
......@@ -508,10 +508,12 @@ unsigned LoopFilter::xGetBoundaryStrengthSingle ( const CodingUnit& cu, const De
#if JEM_TOOLS || JVET_K0346 || JVET_K_AFFINE
if( cu.cs->sps->getSpsNext().getUseHighPrecMv() )
{
#if !REMOVE_MV_ADAPT_PREC
mvP0.setHighPrec();
mvP1.setHighPrec();
mvQ0.setHighPrec();
mvQ1.setHighPrec();
#endif
nThreshold = 4 << VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE;
}
#endif
......@@ -571,8 +573,10 @@ unsigned LoopFilter::xGetBoundaryStrengthSingle ( const CodingUnit& cu, const De
#if JEM_TOOLS || JVET_K0346 || JVET_K_AFFINE
if( cu.cs->sps->getSpsNext().getUseHighPrecMv() )
{
#if !REMOVE_MV_ADAPT_PREC
mvP0.setHighPrec();
mvQ0.setHighPrec();
#endif
nThreshold = 4 << VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE;
}
#endif
......
......@@ -44,7 +44,9 @@
void roundMV( Mv & rMV, unsigned imvShift )
{
CHECK( imvShift == 0, "roundMV called for imvShift=0" );
if( rMV.highPrec ) imvShift += VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE;
#if !REMOVE_MV_ADAPT_PREC
if (rMV.highPrec) imvShift += VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE;
#endif
int offset = 1 << ( imvShift - 1 );
rMV.setHor( ( ( rMV.getHor() + offset ) >> imvShift ) << imvShift );
......@@ -63,10 +65,16 @@ void roundAffineMv( int& mvx, int& mvy, int nShift )
void clipMv( Mv& rcMv, const Position& pos, const SPS& sps )
{
#if JEM_TOOLS || JVET_K0346 || JVET_K_AFFINE
#if (JEM_TOOLS || JVET_K0346 || JVET_K_AFFINE) && !REMOVE_MV_ADAPT_PREC
int iMvShift = 2 + ( rcMv.highPrec ? VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE : 0 );
#else
int iMvShift = 2;
#endif
#if REMOVE_MV_ADAPT_PREC
if (sps.getSpsNext().getUseHighPrecMv())
{
iMvShift += VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE;
}
#endif
int iOffset = 8;
int iHorMax = ( sps.getPicWidthInLumaSamples() + iOffset - ( int ) pos.x - 1 ) << iMvShift;
......
......@@ -53,7 +53,7 @@ class Mv
public:
int hor; ///< horizontal component of motion vector
int ver; ///< vertical component of motion vector
#if JEM_TOOLS || JVET_K0346 || JVET_K_AFFINE
#if (JEM_TOOLS || JVET_K0346 || JVET_K_AFFINE) && !REMOVE_MV_ADAPT_PREC
bool highPrec;///< true if the vector is high precision
#endif
......@@ -61,7 +61,7 @@ public:
// constructors
// ------------------------------------------------------------------------------------------------------------------
#if JEM_TOOLS || JVET_K0346 || JVET_K_AFFINE
#if (JEM_TOOLS || JVET_K0346 || JVET_K_AFFINE) && !REMOVE_MV_ADAPT_PREC
Mv( ) : hor( 0 ), ver( 0 ), highPrec( false ) {}
Mv( int iHor, int iVer, bool _highPrec = false ) : hor( iHor ), ver( iVer ), highPrec( _highPrec ) {}
#if DMVR_JVET_K0217
......@@ -80,9 +80,33 @@ public:
return (hor == 0 && ver == 0);
}
#endif
#else
#if JEM_TOOLS
#if REMOVE_MV_ADAPT_PREC && DMVR_JVET_K0217
Mv() : hor(0), ver(0) {}
Mv(int iHor, int iVer) : hor(iHor), ver(iVer) {}
// explicit Mv(const Mv &newMv) : hor(newMv.hor), ver(newMv.ver) {} // use default copy constructor
explicit Mv(int iHorAndiVer) : hor(iHorAndiVer), ver(iHorAndiVer) {}
Mv operator << (int i)
{
return Mv(hor << i, ver << i);
}
Mv operator - (void)
{
return Mv(-hor, -ver);
}
bool IsZero(void)
{
return (hor == 0 && ver == 0);
}
#else
Mv() : hor(0), ver(0) {}
Mv(int iHor, int iVer) : hor(iHor), ver(iVer) {}
#endif
#else
Mv( ) : hor( 0 ), ver( 0 ) {}
Mv( int iHor, int iVer ) : hor( iHor ), ver( iVer ) {}
#endif
#endif
// ------------------------------------------------------------------------------------------------------------------
......@@ -109,7 +133,7 @@ public:
const Mv& operator += (const Mv& _rcMv)
{
#if JEM_TOOLS || JVET_K0346 || JVET_K_AFFINE
#if (JEM_TOOLS || JVET_K0346 || JVET_K_AFFINE) && !REMOVE_MV_ADAPT_PREC
if( highPrec == _rcMv.highPrec )
{
hor += _rcMv.hor;
......@@ -120,7 +144,7 @@ public:
{
Mv rcMv = _rcMv;
#if JEM_TOOLS || JVET_K0346 || JVET_K_AFFINE
#if (JEM_TOOLS || JVET_K0346 || JVET_K_AFFINE) && !REMOVE_MV_ADAPT_PREC
if( highPrec && !rcMv.highPrec ) rcMv.setHighPrec();
if( !highPrec && rcMv.highPrec ) setHighPrec();
#endif
......@@ -132,7 +156,7 @@ public:
const Mv& operator-= (const Mv& _rcMv)
{
#if JEM_TOOLS || JVET_K0346 || JVET_K_AFFINE
#if (JEM_TOOLS || JVET_K0346 || JVET_K_AFFINE) && !REMOVE_MV_ADAPT_PREC
if( highPrec == _rcMv.highPrec )
{
hor -= _rcMv.hor;
......@@ -143,7 +167,7 @@ public:
{
Mv rcMv = _rcMv;
#if JEM_TOOLS || JVET_K0346 || JVET_K_AFFINE
#if (JEM_TOOLS || JVET_K0346 || JVET_K_AFFINE) && !REMOVE_MV_ADAPT_PREC
if( highPrec && !rcMv.highPrec ) rcMv.setHighPrec();
if( !highPrec && rcMv.highPrec ) setHighPrec();
#endif
......@@ -182,7 +206,7 @@ public:
const Mv operator - ( const Mv& rcMv ) const
{
#if JEM_TOOLS || JVET_K0346 || JVET_K_AFFINE
#if (JEM_TOOLS || JVET_K0346 || JVET_K_AFFINE) && !REMOVE_MV_ADAPT_PREC
if( rcMv.highPrec == highPrec )
{
return Mv( hor - rcMv.hor, ver - rcMv.ver, highPrec );
......@@ -201,7 +225,7 @@ public:
const Mv operator + ( const Mv& rcMv ) const
{
#if JEM_TOOLS || JVET_K0346 || JVET_K_AFFINE
#if (JEM_TOOLS || JVET_K0346 || JVET_K_AFFINE) && !REMOVE_MV_ADAPT_PREC
if( rcMv.highPrec == highPrec )
{
return Mv( hor + rcMv.hor, ver + rcMv.ver, highPrec );
......@@ -220,7 +244,7 @@ public:
bool operator== ( const Mv& rcMv ) const
{
#if JEM_TOOLS || JVET_K0346 || JVET_K_AFFINE
#if (JEM_TOOLS || JVET_K0346 || JVET_K_AFFINE) && !REMOVE_MV_ADAPT_PREC
if( rcMv.highPrec == highPrec )
{
return ( hor == rcMv.hor && ver == rcMv.ver );
......@@ -247,7 +271,7 @@ public:
{
const int mvx = Clip3( -32768, 32767, (iScale * getHor() + 127 + (iScale * getHor() < 0)) >> 8 );
const int mvy = Clip3( -32768, 32767, (iScale * getVer() + 127 + (iScale * getVer() < 0)) >> 8 );
#if JEM_TOOLS || JVET_K0346 || JVET_K_AFFINE
#if (JEM_TOOLS || JVET_K0346 || JVET_K_AFFINE) && !REMOVE_MV_ADAPT_PREC
return Mv( mvx, mvy, highPrec );
#else
return Mv( mvx, mvy );
......@@ -257,27 +281,40 @@ public:
#if JEM_TOOLS || JVET_K0346 || JVET_K_AFFINE
void roundMV2SignalPrecision()
{
#if REMOVE_MV_ADAPT_PREC
setLowPrec();
setHighPrec();
#else
const bool isHP = highPrec;
setLowPrec();
if( isHP ) setHighPrec();
#endif
}
void setLowPrec()
{
if( !highPrec ) return;
#if !REMOVE_MV_ADAPT_PREC
if (!highPrec) return;
#endif
const int nShift = VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE;
const int nOffset = 1 << ( nShift - 1 );
hor = hor >= 0 ? ( hor + nOffset ) >> nShift : -( ( -hor + nOffset ) >> nShift );
ver = ver >= 0 ? ( ver + nOffset ) >> nShift : -( ( -ver + nOffset ) >> nShift );
#if !REMOVE_MV_ADAPT_PREC
highPrec = false;
#endif
}
void setHighPrec()
{
if( highPrec ) return;
#if !REMOVE_MV_ADAPT_PREC
if (highPrec) return;
#endif
hor = hor >= 0 ? ( hor ) << VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE : -( ( -hor ) << VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE );
ver = ver >= 0 ? ( ver ) << VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE : -( ( -ver ) << VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE );
#if !REMOVE_MV_ADAPT_PREC
highPrec = true;
#endif
}
#endif
};// END CLASS DEFINITION MV
......
......@@ -187,7 +187,7 @@ public:
void setPredictor ( const Mv& rcMv )
{
m_mvPredictor = rcMv;
#if JEM_TOOLS || JVET_K0346 || JVET_K_AFFINE
#if (JEM_TOOLS || JVET_K0346 || JVET_K_AFFINE) && !REMOVE_MV_ADAPT_PREC
if( m_mvPredictor.highPrec )
{
m_mvPredictor = Mv( m_mvPredictor.hor >> VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE, m_mvPredictor.ver >> VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE, false );
......
......@@ -128,6 +128,8 @@
#define JVET_K0357_AMVR 1 // Adaptive motion vector resolution separated from JEM_TOOLS macro
#define REMOVE_MV_ADAPT_PREC 1 // remove the high precision flag in the MV class
#if JVET_K0485_BIO
#define JVET_K0485_BIO_EXTEND_SIZE 1
#endif
......
......@@ -2004,7 +2004,7 @@ bool PU::getColocatedMVP(const PredictionUnit &pu, const RefPicList &eRefPicList
}
else
{
#if JEM_TOOLS || JVET_K0346 || JVET_K_AFFINE
#if (JEM_TOOLS || JVET_K0346 || JVET_K_AFFINE) && !REMOVE_MV_ADAPT_PREC
if( pu.cs->sps->getSpsNext().getUseHighPrecMv() )
{
// allow extended precision for temporal scaling
......@@ -2238,6 +2238,12 @@ void PU::fillMvpCand(PredictionUnit &pu, const RefPicList &eRefPicList, const in
if( pu.cu->imv != 0)
{
unsigned imvShift = pu.cu->imv << 1;
#if REMOVE_MV_ADAPT_PREC
if (pu.cs->sps->getSpsNext().getUseHighPrecMv())
{
imvShift += VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE;
}
#endif
for( int i = 0; i < pInfo->numCand; i++ )
{
roundMV( pInfo->mvCand[i], imvShift );
......@@ -2330,7 +2336,7 @@ void PU::fillMvpCand(PredictionUnit &pu, const RefPicList &eRefPicList, const in
while (pInfo->numCand < AMVP_MAX_NUM_CANDS)
{
#if JEM_TOOLS || JVET_K0346 || JVET_K_AFFINE
#if (JEM_TOOLS || JVET_K0346 || JVET_K_AFFINE) && !REMOVE_MV_ADAPT_PREC
const bool prec = pInfo->mvCand[pInfo->numCand].highPrec;
pInfo->mvCand[pInfo->numCand] = Mv( 0, 0, prec );
#else
......@@ -2343,7 +2349,11 @@ void PU::fillMvpCand(PredictionUnit &pu, const RefPicList &eRefPicList, const in
{
for( Mv &mv : pInfo->mvCand )
{
if( mv.highPrec ) mv.setLowPrec();
#if REMOVE_MV_ADAPT_PREC
mv.setLowPrec();
#else
if (mv.highPrec) mv.setLowPrec();
#endif
}
}
#if JVET_K0357_AMVR
......@@ -2356,7 +2366,7 @@ void PU::fillMvpCand(PredictionUnit &pu, const RefPicList &eRefPicList, const in
}
}
#endif
#if !JEM_TOOLS && JVET_K0346 || JVET_K_AFFINE
#if (!JEM_TOOLS && JVET_K0346 || JVET_K_AFFINE) && !REMOVE_MV_ADAPT_PREC
if (pu.cs->sps->getSpsNext().getUseHighPrecMv())
{
for (Mv &mv : pInfo->mvCand)
......@@ -2460,13 +2470,21 @@ void PU::xInheritedAffineMv( const PredictionUnit &pu, const PredictionUnit* puN
horTmp = iMvScaleHor + iDMvHorX * (posCurX - posNeiX) + iDMvVerX * (posCurY - posNeiY);
verTmp = iMvScaleVer + iDMvHorY * (posCurX - posNeiX) + iDMvVerY * (posCurY - posNeiY);
roundAffineMv( horTmp, verTmp, shift );
rcMv[0] = Mv( horTmp, verTmp, true );
#if REMOVE_MV_ADAPT_PREC
rcMv[0] = Mv(horTmp, verTmp);
#else
rcMv[0] = Mv(horTmp, verTmp, true);
#endif
// v1
horTmp = iMvScaleHor + iDMvHorX * (posCurX + curW - posNeiX) + iDMvVerX * (posCurY - posNeiY);
verTmp = iMvScaleVer + iDMvHorY * (posCurX + curW - posNeiX) + iDMvVerY * (posCurY - posNeiY);
roundAffineMv( horTmp, verTmp, shift );
rcMv[1] = Mv( horTmp, verTmp, true );
#if REMOVE_MV_ADAPT_PREC
rcMv[1] = Mv(horTmp, verTmp);
#else
rcMv[1] = Mv(horTmp, verTmp, true);
#endif
// v2
#if JVET_K0337_AFFINE_6PARA
......@@ -2475,7 +2493,11 @@ void PU::xInheritedAffineMv( const PredictionUnit &pu, const PredictionUnit* puN
horTmp = iMvScaleHor + iDMvHorX * (posCurX - posNeiX) + iDMvVerX * (posCurY + curH - posNeiY);
verTmp = iMvScaleVer + iDMvHorY * (posCurX - posNeiX) + iDMvVerY * (posCurY + curH - posNeiY);
roundAffineMv( horTmp, verTmp, shift );
rcMv[2] = Mv( horTmp, verTmp, true );
#if REMOVE_MV_ADAPT_PREC
rcMv[2] = Mv(horTmp, verTmp);
#else
rcMv[2] = Mv(horTmp, verTmp, true);
#endif
}
#endif
#else
......@@ -2486,10 +2508,12 @@ void PU::xInheritedAffineMv( const PredictionUnit &pu, const PredictionUnit* puN
rcMv[2].hor = int( rcMv[0].hor + 1.0 * (mvLB.hor - mvLT.hor) * curH / neiH );
rcMv[2].ver = int( rcMv[0].ver + 1.0 * (mvLB.ver - mvLT.ver) * curH / neiH );
#if !REMOVE_MV_ADAPT_PREC
rcMv[0].highPrec = true;
rcMv[1].highPrec = true;
rcMv[2].highPrec = true;
#endif
#endif
}
#if !JVET_K0337_AFFINE_MVP_IMPROVE
......@@ -2503,8 +2527,10 @@ bool isValidAffineCandidate( const PredictionUnit &pu, Mv cMv0, Mv cMv1, Mv cMv2
if ( deltaHor == zeroMv )
return false;
#if !REMOVE_MV_ADAPT_PREC
deltaHor.setHighPrec();
deltaVer.setHighPrec();
#endif
// S/8, but the Mv is 4 precision, so change to S/2
int width = pu.Y().width;
......@@ -2583,6 +2609,14 @@ void PU::fillAffineMvpCand(PredictionUnit &pu, const RefPicList &eRefPicList, co
if ( affiAMVPInfo.numCand >= AMVP_MAX_NUM_CANDS )
{
#if REMOVE_MV_ADAPT_PREC
for (int i = 0; i < affiAMVPInfo.numCand; i++)
{
affiAMVPInfo.mvCandLT[i].setLowPrec();
affiAMVPInfo.mvCandRT[i].setLowPrec();
affiAMVPInfo.mvCandLB[i].setLowPrec();
}
#endif
return;
}
......@@ -2636,9 +2670,11 @@ void PU::fillAffineMvpCand(PredictionUnit &pu, const RefPicList &eRefPicList, co
outputAffineMv[1] = amvpInfo1.mvCand[0];
outputAffineMv[2] = amvpInfo2.mvCand[0];
#if !REMOVE_MV_ADAPT_PREC
outputAffineMv[0].setHighPrec();
outputAffineMv[1].setHighPrec();
outputAffineMv[2].setHighPrec();
#endif
outputAffineMv[0].roundMV2SignalPrecision();
outputAffineMv[1].roundMV2SignalPrecision();
......@@ -2744,18 +2780,20 @@ void PU::fillAffineMvpCand(PredictionUnit &pu, const RefPicList &eRefPicList, co
}
}
for ( int i = 0; i < amvpInfo0.numCand; i++ )
#if !REMOVE_MV_ADAPT_PREC
for (int i = 0; i < amvpInfo0.numCand; i++)
{
amvpInfo0.mvCand[i].setHighPrec();
}
for ( int i = 0; i < amvpInfo1.numCand; i++ )
for (int i = 0; i < amvpInfo1.numCand; i++)
{
amvpInfo1.mvCand[i].setHighPrec();
}
for ( int i = 0; i < amvpInfo2.numCand; i++ )
for (int i = 0; i < amvpInfo2.numCand; i++)
{
amvpInfo2.mvCand[i].setHighPrec();
}
#endif
// Check Valid Candidates and Sort through DV
int