1. 程式人生 > >HEVC程式碼學習16:運動向量MV的資料結構

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 <typename 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);
};