HEVCコード学習16:動きベクトルMVのデータ構造


今日はMVのデータ構造を勉強して、MVの記憶、処理などの各種操作をさらに理解します.
TCom Mv
まず基本的な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;
TCom Mv Field
TCom MvFieldはインデックス付きのMV情報で、基本MVとインデックスが格納されています.MVとインデックスに対する操作関数が含まれています.TCom DataCUでは、GtMvFieldを定義し、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    
};
TComCUMv Field
TComCUMv FieldはCUのMV情報であり、より多くの情報を持つ.TCom DataCUにm_が定義されている.CUのMV情報を格納するためのacCUMv Field[NUM_REFUPICULIST_01].getCUMv Field関数も定義されており、m_を取得するために使用されています.acCUMv Field
/// class for motion information in one CU
//CU MV  
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);
};