Commit 5f68dfee authored by Xiang Li's avatar Xiang Li

Explicitly changing MV precision

parent a86ab09c
......@@ -637,9 +637,7 @@ void InterPrediction::xPredInterBlk ( const ComponentID& compID, const Predictio
const ChromaFormat chFmt = pu.chromaFormat;
const bool rndRes = !bi;
int iAddPrecShift = 0;
iAddPrecShift = VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE;
int iAddPrecShift = VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE;
int shiftHor = 2 + iAddPrecShift + ::getComponentScaleX(compID, chFmt);
int shiftVer = 2 + iAddPrecShift + ::getComponentScaleY(compID, chFmt);
......
......@@ -485,8 +485,7 @@ unsigned LoopFilter::xGetBoundaryStrengthSingle ( const CodingUnit& cu, const De
if( 0 <= miQ.refIdx[0] ) { mvQ0 = miQ.mv[0]; }
if( 0 <= miQ.refIdx[1] ) { mvQ1 = miQ.mv[1]; }
int nThreshold = 4;
nThreshold = 4 << VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE;
int nThreshold = 4 << VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE;
unsigned uiBs = 0;
//th can be optimized
......@@ -539,8 +538,7 @@ unsigned LoopFilter::xGetBoundaryStrengthSingle ( const CodingUnit& cu, const De
Mv mvP0 = miP.mv[0];
Mv mvQ0 = miQ.mv[0];
int nThreshold = 4;
nThreshold = 4 << VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE;
int nThreshold = 4 << VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE;
return ( ( abs( mvQ0.getHor() - mvP0.getHor() ) >= nThreshold ) || ( abs( mvQ0.getVer() - mvP0.getVer() ) >= nThreshold ) ) ? 1 : 0;
}
......
......@@ -40,18 +40,7 @@
#include "Common.h"
#include "Slice.h"
void roundMV( Mv & rMV, unsigned imvShift )
{
CHECK( imvShift == 0, "roundMV called for imvShift=0" );
int offset = 1 << ( imvShift - 1 );
#if JVET_L0377_AMVR_ROUNDING_ALIGN
rMV.setHor(rMV.getHor() >= 0 ? ((rMV.getHor() + offset) >> imvShift) << imvShift : -(((-rMV.getHor() + offset) >> imvShift)) << imvShift);
rMV.setVer(rMV.getVer() >= 0 ? ((rMV.getVer() + offset) >> imvShift) << imvShift : -(((-rMV.getVer() + offset) >> imvShift)) << imvShift);
#else
rMV.setHor( ( ( rMV.getHor() + offset ) >> imvShift ) << imvShift );
rMV.setVer( ( ( rMV.getVer() + offset ) >> imvShift ) << imvShift );
#endif
}
const MvPrecision Mv::m_dstMvPrecision[3] = { MV_PRECISION_QUARTER, MV_PRECISION_INT, MV_PRECISION_4PEL };
void roundAffineMv( int& mvx, int& mvy, int nShift )
{
......@@ -66,8 +55,7 @@ void clipMv( Mv& rcMv, const Position& pos,
#endif
const SPS& sps )
{
int iMvShift = 2;
iMvShift += VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE;
int iMvShift = 2 + VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE;
int iOffset = 8;
int iHorMax = ( sps.getPicWidthInLumaSamples() + iOffset - ( int ) pos.x - 1 ) << iMvShift;
int iHorMin = ( -( int ) sps.getMaxCUWidth() - iOffset - ( int ) pos.x + 1 ) << iMvShift;
......
......@@ -47,9 +47,20 @@
// Class definition
// ====================================================================================================================
enum MvPrecision
{
MV_PRECISION_4PEL = 0, // 4-pel
MV_PRECISION_INT = 2, // 1-pel, shift 2 bits from 4-pel
MV_PRECISION_QUARTER = 4, // 1/4-pel (the precision of regular MV difference signaling), shift 4 bits from 4-pel
MV_PRECISION_INTERNAL = 6, // 1/16-pel (the precision of internal MV), shift 6 bits from 4-pel
};
/// basic motion vector class
class Mv
{
private:
static const MvPrecision m_dstMvPrecision[3];
public:
int hor; ///< horizontal component of motion vector
int ver; ///< vertical component of motion vector
......@@ -159,16 +170,40 @@ public:
return Mv( mvx, mvy );
}
void roundMV2SignalPrecision()
void changePrecision(const MvPrecision& src, const MvPrecision& dst)
{
const int shift = (int)dst - (int)src;
if (shift >= 0)
{
*this <<= shift;
}
else
{
const int rightShift = -shift;
const int nOffset = 1 << (rightShift - 1);
hor = hor >= 0 ? (hor + nOffset) >> rightShift : -((-hor + nOffset) >> rightShift);
ver = ver >= 0 ? (ver + nOffset) >> rightShift : -((-ver + nOffset) >> rightShift);
}
}
void changePrecisionAmvr(const int amvr, const MvPrecision& dst)
{
changePrecision(m_dstMvPrecision[amvr], dst);
}
void roundToPrecision(const MvPrecision& src, const MvPrecision& dst)
{
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);
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);
changePrecision(src, dst);
changePrecision(dst, src);
}
void roundToAmvrSignalPrecision(const MvPrecision& src, const int amvr)
{
static const MvPrecision dstMvPrecision[3] = { MV_PRECISION_QUARTER, MV_PRECISION_INT, MV_PRECISION_4PEL };
roundToPrecision(src, dstMvPrecision[amvr]);
}
};// END CLASS DEFINITION MV
#if JVET_L0293_CPR
namespace std
{
......@@ -182,7 +217,6 @@ namespace std
};
};
#endif
void roundMV( Mv& rcMv, unsigned imvShift );
void clipMv ( Mv& rcMv, const struct Position& pos,
#if JVET_L0231_WRAPAROUND
const struct Size& size,
......
This diff is collapsed.
......@@ -656,18 +656,15 @@ void DecCu::xDeriveCUMV( CodingUnit &cu )
Mv mvLT = affineAMVPInfo.mvCandLT[mvp_idx] + pu.mvdAffi[eRefList][0];
Mv mvRT = affineAMVPInfo.mvCandRT[mvp_idx] + pu.mvdAffi[eRefList][1];
mvRT += pu.mvdAffi[eRefList][0];
mvLT.hor = mvLT.hor << VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE;
mvLT.ver = mvLT.ver << VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE;
mvRT.hor = mvRT.hor << VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE;
mvRT.ver = mvRT.ver << VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE;
mvLT.changePrecision(MV_PRECISION_QUARTER, MV_PRECISION_INTERNAL);
mvRT.changePrecision(MV_PRECISION_QUARTER, MV_PRECISION_INTERNAL);
Mv mvLB;
if ( cu.affineType == AFFINEMODEL_6PARAM )
{
mvLB = affineAMVPInfo.mvCandLB[mvp_idx] + pu.mvdAffi[eRefList][2];
mvLB += pu.mvdAffi[eRefList][0];
mvLB.hor = mvLB.hor << VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE;
mvLB.ver = mvLB.ver << VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE;
mvLB.changePrecision(MV_PRECISION_QUARTER, MV_PRECISION_INTERNAL);
}
PU::setAllAffineMv( pu, mvLT, mvRT, mvLB, eRefList );
}
......@@ -691,15 +688,13 @@ void DecCu::xDeriveCUMV( CodingUnit &cu )
#if REUSE_CU_RESULTS
if (!cu.cs->pcv->isEncoder)
#endif
mvd <<= 2;
mvd.changePrecision(MV_PRECISION_INT, MV_PRECISION_QUARTER);
}
pu.mv [eRefList] = amvpInfo.mvCand[pu.mvpIdx[eRefList]] + mvd;
#else
pu.mv [eRefList] = amvpInfo.mvCand[pu.mvpIdx [eRefList]] + pu.mvd[eRefList];
#endif
pu.mv[eRefList].hor = pu.mv[eRefList].hor << VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE;
pu.mv[eRefList].ver = pu.mv[eRefList].ver << VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE;
pu.mv[eRefList].changePrecision(MV_PRECISION_QUARTER, MV_PRECISION_INTERNAL);
}
}
}
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment