HEVC代码学习16:运动矢量MV的数据结构

今天学习MV的数据结构,进一步理解MV的存储、处理等各种操作。

TComMv

先来看基本的MV类TComMv。可以看到MV是以水平分量m_iHor和垂直分量m_iVer的形式存储的,类中包含了设置、获取、加减、比较等函数。

class TComMv
{
private:
  //MV水平和垂直分量
  Short m_iHor;     ///< horizontal component of motion vector
  Short m_iVer;     ///< vertical component of motion vector

public:

  // ------------------------------------------------------------------------------------------------------------------
  // constructors
  // ------------------------------------------------------------------------------------------------------------------

  TComMv() :
  m_iHor(0),
  m_iVer(0)
  {
  }

  TComMv( Short iHor, Short iVer ) :
  m_iHor(iHor),
  m_iVer(iVer)
  {
  }

  // ------------------------------------------------------------------------------------------------------------------
  // set
  // ------------------------------------------------------------------------------------------------------------------
  Void  set       ( Short iHor, Short iVer)     { m_iHor = iHor;  m_iVer = iVer;            }

  Void  setHor    ( Short i )                   { m_iHor = i;                               }
  Void  setVer    ( Short i )                   { m_iVer = i;                               }
  Void  setZero   ()                            { m_iHor = m_iVer = 0;        }

  // ------------------------------------------------------------------------------------------------------------------
  // get
  // ------------------------------------------------------------------------------------------------------------------

  Int   getHor    () const { return m_iHor;          }
  Int   getVer    () const { return m_iVer;          }
  Int   getAbsHor () const { return abs( m_iHor );   }
  Int   getAbsVer () const { return abs( m_iVer );   }

  // ------------------------------------------------------------------------------------------------------------------
  // operations
  // ------------------------------------------------------------------------------------------------------------------

  const TComMv& operator += (const TComMv& rcMv)
  {
    m_iHor += rcMv.m_iHor;
    m_iVer += rcMv.m_iVer;
    return  *this;
  }

  const TComMv& operator-= (const TComMv& rcMv)
  {
    m_iHor -= rcMv.m_iHor;
    m_iVer -= rcMv.m_iVer;
    return  *this;
  }

  const TComMv& operator>>= (const Int i)
  {
    m_iHor >>= i;
    m_iVer >>= i;
    return  *this;
  }

  const TComMv& operator<<= (const Int i)
  {
    m_iHor <<= i;
    m_iVer <<= i;
    return  *this;
  }

  const TComMv operator - ( const TComMv& rcMv ) const
  {
    return TComMv( m_iHor - rcMv.m_iHor, m_iVer - rcMv.m_iVer );
  }

  const TComMv operator + ( const TComMv& rcMv ) const
  {
    return TComMv( m_iHor + rcMv.m_iHor, m_iVer + rcMv.m_iVer );
  }

  Bool operator== ( const TComMv& rcMv ) const
  {
    return (m_iHor==rcMv.m_iHor && m_iVer==rcMv.m_iVer);
  }

  Bool operator!= ( const TComMv& rcMv ) const
  {
    return (m_iHor!=rcMv.m_iHor || m_iVer!=rcMv.m_iVer);
  }

  const TComMv scaleMv( Int iScale ) const
  {
    Int mvx = Clip3( -32768, 32767, (iScale * getHor() + 127 + (iScale * getHor() < 0)) >> 8 );
    Int mvy = Clip3( -32768, 32767, (iScale * getVer() + 127 + (iScale * getVer() < 0)) >> 8 );
    return TComMv( mvx, mvy );
  }
};// END CLASS DEFINITION TComMV

//! \}

AMVPInfo

用于AMVP信息,包括运动矢量候选列表及数量。

//AMVP参数信息
/// parameters for AMVP
typedef struct _AMVPInfo
{
  TComMv m_acMvCand[ AMVP_MAX_NUM_CANDS_MEM ];  ///< array of motion vector predictor candidates    运动矢量候选列表
  Int    iN;                                ///< number of motion vector predictor candidates       运动矢量候选数量
} AMVPInfo;

TComMvField

TComMvField是带索引的MV信息,里面存储了基本MV加索引,包含了对MV和索引的操作函数。
在TComDataCU中定义了getMvField,用于获取该CU的带索引的MV信息。

/// class for motion vector with reference index
class TComMvField
{
private:
  TComMv    m_acMv;     //MV信息
  Int       m_iRefIdx;  //索引

public:
  TComMvField() : m_iRefIdx( NOT_VALID ) {}

  Void setMvField( TComMv const & cMv, Int iRefIdx )    //设置MV和索引
  {
    m_acMv    = cMv;
    m_iRefIdx = iRefIdx;
  }

  Void setRefIdx( Int refIdx ) { m_iRefIdx = refIdx; }      //设置索引

  TComMv const & getMv() const { return  m_acMv; }      //获取MV
  TComMv       & getMv()       { return  m_acMv; }

  Int getRefIdx() const { return  m_iRefIdx;       }    //获取索引
  Int getHor   () const { return  m_acMv.getHor(); }    //获取MV水平分量
  Int getVer   () const { return  m_acMv.getVer(); }    //获取MV垂直分量
};

TComCUMvField

TComCUMvField是CU的MV信息,带有更多的信息。
在TComDataCU中定义了m_acCUMvField[NUM_REF_PIC_LIST_01],用于存储CU的MV信息。还定义了 getCUMvField函数,用于获取m_acCUMvField。

/// class for motion information in one CU
//CUMV信息
class TComCUMvField
{
private:
  TComMv*   m_pcMv;     //MV
  TComMv*   m_pcMvd;    //MVD
  Char*     m_piRefIdx;     //索引
  UInt      m_uiNumPartition;   //分块
  AMVPInfo  m_cAMVPInfo;    //AMVP信息

  template T>
  Void setAll( T *p, T const & val, PartSize eCUMode, Int iPartAddr, UInt uiDepth, Int iPartIdx );

public:
  TComCUMvField() : m_pcMv(NULL), m_pcMvd(NULL), m_piRefIdx(NULL), m_uiNumPartition(0) {}
  ~TComCUMvField() {}

  // ------------------------------------------------------------------------------------------------------------------
  // create / destroy
  // ------------------------------------------------------------------------------------------------------------------

  Void    create( UInt uiNumPartition );
  Void    destroy();

  // ------------------------------------------------------------------------------------------------------------------
  // clear / copy
  // ------------------------------------------------------------------------------------------------------------------

  Void    clearMvField();       //清理MV

  //复制
  Void    copyFrom( TComCUMvField const * pcCUMvFieldSrc, Int iNumPartSrc, Int iPartAddrDst );
  Void    copyTo  ( TComCUMvField* pcCUMvFieldDst, Int iPartAddrDst ) const;
  Void    copyTo  ( TComCUMvField* pcCUMvFieldDst, Int iPartAddrDst, UInt uiOffset, UInt uiNumPart ) const;

  // ------------------------------------------------------------------------------------------------------------------
  // get
  // ------------------------------------------------------------------------------------------------------------------
  //获取
  TComMv const & getMv    ( Int iIdx ) const { return  m_pcMv    [iIdx]; }
  TComMv const & getMvd   ( Int iIdx ) const { return  m_pcMvd   [iIdx]; }
  Int            getRefIdx( Int iIdx ) const { return  m_piRefIdx[iIdx]; }

  AMVPInfo* getAMVPInfo () { return &m_cAMVPInfo; }

  // ------------------------------------------------------------------------------------------------------------------
  // set
  // ------------------------------------------------------------------------------------------------------------------
  //设置
  Void    setAllMv     ( TComMv const & rcMv,         PartSize eCUMode, Int iPartAddr, UInt uiDepth, Int iPartIdx=0 );
  Void    setAllMvd    ( TComMv const & rcMvd,        PartSize eCUMode, Int iPartAddr, UInt uiDepth, Int iPartIdx=0 );
  Void    setAllRefIdx ( Int iRefIdx,                 PartSize eMbMode, Int iPartAddr, UInt uiDepth, Int iPartIdx=0 );
  Void    setAllMvField( TComMvField const & mvField, PartSize eMbMode, Int iPartAddr, UInt uiDepth, Int iPartIdx=0 );

  Void setNumPartition( Int iNumPart )
  {
    m_uiNumPartition = iNumPart;
  }

  Void linkToWithOffset( TComCUMvField const * src, Int offset )
  {
    m_pcMv     = src->m_pcMv     + offset;
    m_pcMvd    = src->m_pcMvd    + offset;
    m_piRefIdx = src->m_piRefIdx + offset;
  }

  //压缩
  Void compress(Char* pePredMode, Int scale);
};

你可能感兴趣的:(HEVC,HM,HEVC代码学习)