TComMotionInfo.h 6.55 KB
Newer Older
1
2
3
/* The copyright in this software is being made available under the BSD
 * License, included below. This software may be subject to other third party
 * and contributor rights, including patent rights, and no such rights are
4
 * granted under this license.
5
 *
6
 * Copyright (c) 2010-2020, ITU/ISO/IEC
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *  * Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
 *    be used to endorse or promote products derived from this software without
 *    specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 * THE POSSIBILITY OF SUCH DAMAGE.
 */
33

Heiko Schwarz's avatar
Heiko Schwarz committed
34
35
36
/** \file     TComMotionInfo.h
    \brief    motion information handling classes (header)
    \todo     TComMvField seems to be better to be inherited from TComMv
37
38
39
40
41
42
43
44
45
*/

#ifndef __TCOMMOTIONINFO__
#define __TCOMMOTIONINFO__

#include <memory.h>
#include "CommonDef.h"
#include "TComMv.h"

Frank Bossen's avatar
Frank Bossen committed
46
47
48
//! \ingroup TLibCommon
//! \{

49
50
51
52
53
54
55
// ====================================================================================================================
// Type definition
// ====================================================================================================================

/// parameters for AMVP
typedef struct _AMVPInfo
{
56
  TComMv m_acMvCand[ AMVP_MAX_NUM_CANDS ];  ///< array of motion vector predictor candidates
Heiko Schwarz's avatar
Heiko Schwarz committed
57
  Int    iN;                                ///< number of motion vector predictor candidates
58
59
60
#if MCTS_ENC_CHECK
  UInt   numSpatialMVPCandidates;
#endif
61
62
63
64
65
66
67
68
69
70
71
72
} AMVPInfo;

// ====================================================================================================================
// Class definition
// ====================================================================================================================

/// class for motion vector with reference index
class TComMvField
{
private:
  TComMv    m_acMv;
  Int       m_iRefIdx;
73

74
public:
Frank Bossen's avatar
Frank Bossen committed
75
  TComMvField() : m_iRefIdx( NOT_VALID ) {}
76

77
  Void setMvField( TComMv const & cMv, Int iRefIdx )
78
79
80
81
  {
    m_acMv    = cMv;
    m_iRefIdx = iRefIdx;
  }
82

Frank Bossen's avatar
Frank Bossen committed
83
  Void setRefIdx( Int refIdx ) { m_iRefIdx = refIdx; }
84

85
  TComMv const & getMv() const { return  m_acMv; }
Frank Bossen's avatar
Frank Bossen committed
86
  TComMv       & getMv()       { return  m_acMv; }
87

88
89
90
  Int getRefIdx() const { return  m_iRefIdx;       }
  Int getHor   () const { return  m_acMv.getHor(); }
  Int getVer   () const { return  m_acMv.getVer(); }
91
92
93
94
95
96
97
98
};

/// class for motion information in one CU
class TComCUMvField
{
private:
  TComMv*   m_pcMv;
  TComMv*   m_pcMvd;
99
  SChar*    m_piRefIdx;
100
101
  UInt      m_uiNumPartition;
  AMVPInfo  m_cAMVPInfo;
102

Frank Bossen's avatar
Frank Bossen committed
103
104
  template <typename T>
  Void setAll( T *p, T const & val, PartSize eCUMode, Int iPartAddr, UInt uiDepth, Int iPartIdx );
Frank Bossen's avatar
Frank Bossen committed
105
106
107
108
109

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

Heiko Schwarz's avatar
Heiko Schwarz committed
110
111
112
  // ------------------------------------------------------------------------------------------------------------------
  // create / destroy
  // ------------------------------------------------------------------------------------------------------------------
113

Frank Bossen's avatar
Frank Bossen committed
114
115
  Void    create( UInt uiNumPartition );
  Void    destroy();
116

Heiko Schwarz's avatar
Heiko Schwarz committed
117
118
119
  // ------------------------------------------------------------------------------------------------------------------
  // clear / copy
  // ------------------------------------------------------------------------------------------------------------------
Frank Bossen's avatar
Frank Bossen committed
120
121

  Void    clearMvField();
122

Frank Bossen's avatar
Frank Bossen committed
123
124
125
  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;
126

Heiko Schwarz's avatar
Heiko Schwarz committed
127
128
129
  // ------------------------------------------------------------------------------------------------------------------
  // get
  // ------------------------------------------------------------------------------------------------------------------
130

Frank Bossen's avatar
Frank Bossen committed
131
132
133
  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]; }
134

Heiko Schwarz's avatar
Heiko Schwarz committed
135
  AMVPInfo* getAMVPInfo () { return &m_cAMVPInfo; }
136

Heiko Schwarz's avatar
Heiko Schwarz committed
137
138
139
  // ------------------------------------------------------------------------------------------------------------------
  // set
  // ------------------------------------------------------------------------------------------------------------------
140

Frank Bossen's avatar
Frank Bossen committed
141
142
143
144
145
  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 );

Frank Bossen's avatar
Frank Bossen committed
146
147
148
149
  Void setNumPartition( Int iNumPart )
  {
    m_uiNumPartition = iNumPart;
  }
150

Frank Bossen's avatar
Frank Bossen committed
151
152
153
154
155
156
  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;
  }
157

158
159
160
#if REDUCED_ENCODER_MEMORY
  Void compress(SChar *pePredMode, const SChar* pePredModeSource, const Int scale, const TComCUMvField &source);
#else
161
  Void compress(SChar* pePredMode, Int scale);
162
#endif
163
164
};

Frank Bossen's avatar
Frank Bossen committed
165
//! \}
Frank Bossen's avatar
Frank Bossen committed
166

Frank Bossen's avatar
Frank Bossen committed
167
#endif // __TCOMMOTIONINFO__