1 | /* The copyright in this software is being made available under the BSD |
---|
2 | * License, included below. This software may be subject to other third party |
---|
3 | * and contributor rights, including patent rights, and no such rights are |
---|
4 | * granted under this license. |
---|
5 | * |
---|
6 | * Copyright (c) 2010-2015, ITU/ISO/IEC |
---|
7 | * All rights reserved. |
---|
8 | * |
---|
9 | * Redistribution and use in source and binary forms, with or without |
---|
10 | * modification, are permitted provided that the following conditions are met: |
---|
11 | * |
---|
12 | * * Redistributions of source code must retain the above copyright notice, |
---|
13 | * this list of conditions and the following disclaimer. |
---|
14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
15 | * this list of conditions and the following disclaimer in the documentation |
---|
16 | * and/or other materials provided with the distribution. |
---|
17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
18 | * be used to endorse or promote products derived from this software without |
---|
19 | * specific prior written permission. |
---|
20 | * |
---|
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
32 | */ |
---|
33 | |
---|
34 | /** \file TComMotionInfo.h |
---|
35 | \brief motion information handling classes (header) |
---|
36 | \todo TComMvField seems to be better to be inherited from TComMv |
---|
37 | */ |
---|
38 | |
---|
39 | #ifndef __TCOMMOTIONINFO__ |
---|
40 | #define __TCOMMOTIONINFO__ |
---|
41 | |
---|
42 | #include <memory.h> |
---|
43 | #include "CommonDef.h" |
---|
44 | #include "TComMv.h" |
---|
45 | //! \ingroup TLibCommon |
---|
46 | //! \{ |
---|
47 | |
---|
48 | // ==================================================================================================================== |
---|
49 | // Type definition |
---|
50 | // ==================================================================================================================== |
---|
51 | |
---|
52 | #if H_3D_SPIVMP |
---|
53 | class TComDataCU; |
---|
54 | #endif |
---|
55 | /// parameters for AMVP |
---|
56 | typedef struct _AMVPInfo |
---|
57 | { |
---|
58 | TComMv m_acMvCand[ AMVP_MAX_NUM_CANDS_MEM ]; ///< array of motion vector predictor candidates |
---|
59 | Int iN; ///< number of motion vector predictor candidates |
---|
60 | } AMVPInfo; |
---|
61 | |
---|
62 | #if NH_3D_NBDV |
---|
63 | typedef struct _DisCand |
---|
64 | { |
---|
65 | TComMv m_acNBDV; // DV from NBDV |
---|
66 | #if NH_3D_NBDV_REF |
---|
67 | TComMv m_acDoNBDV; // DV from DoNBDV |
---|
68 | #endif |
---|
69 | Int m_aVIdxCan; // View order index (the same with the NBDV and the DoNBDV) |
---|
70 | } DisInfo; |
---|
71 | |
---|
72 | typedef struct _IDVCand // IDV |
---|
73 | { |
---|
74 | TComMv m_acMvCand[2][ IDV_CANDS ]; |
---|
75 | Int m_aVIdxCan[2][ IDV_CANDS ]; |
---|
76 | Bool m_bAvailab[2][ IDV_CANDS ]; |
---|
77 | Bool m_bFound; |
---|
78 | } IDVInfo; |
---|
79 | #endif |
---|
80 | |
---|
81 | // ==================================================================================================================== |
---|
82 | // Class definition |
---|
83 | // ==================================================================================================================== |
---|
84 | |
---|
85 | /// class for motion vector with reference index |
---|
86 | class TComMvField |
---|
87 | { |
---|
88 | private: |
---|
89 | TComMv m_acMv; |
---|
90 | Int m_iRefIdx; |
---|
91 | |
---|
92 | public: |
---|
93 | TComMvField() : m_iRefIdx( NOT_VALID ) {} |
---|
94 | |
---|
95 | Void setMvField( TComMv const & cMv, Int iRefIdx ) |
---|
96 | { |
---|
97 | m_acMv = cMv; |
---|
98 | m_iRefIdx = iRefIdx; |
---|
99 | } |
---|
100 | |
---|
101 | Void setRefIdx( Int refIdx ) { m_iRefIdx = refIdx; } |
---|
102 | |
---|
103 | TComMv const & getMv() const { return m_acMv; } |
---|
104 | TComMv & getMv() { return m_acMv; } |
---|
105 | |
---|
106 | Int getRefIdx() const { return m_iRefIdx; } |
---|
107 | Int getHor () const { return m_acMv.getHor(); } |
---|
108 | Int getVer () const { return m_acMv.getVer(); } |
---|
109 | #if H_3D_IV_MERGE |
---|
110 | Bool operator== ( const TComMvField& rcMv ) const |
---|
111 | { |
---|
112 | return (m_acMv.getHor()==rcMv.getHor() && m_acMv.getVer()==rcMv.getVer() && m_iRefIdx == rcMv.getRefIdx()); |
---|
113 | } |
---|
114 | #endif |
---|
115 | }; |
---|
116 | |
---|
117 | /// class for motion information in one CU |
---|
118 | class TComCUMvField |
---|
119 | { |
---|
120 | private: |
---|
121 | TComMv* m_pcMv; |
---|
122 | TComMv* m_pcMvd; |
---|
123 | Char* m_piRefIdx; |
---|
124 | UInt m_uiNumPartition; |
---|
125 | AMVPInfo m_cAMVPInfo; |
---|
126 | |
---|
127 | template <typename T> |
---|
128 | Void setAll( T *p, T const & val, PartSize eCUMode, Int iPartAddr, UInt uiDepth, Int iPartIdx ); |
---|
129 | |
---|
130 | public: |
---|
131 | TComCUMvField() : m_pcMv(NULL), m_pcMvd(NULL), m_piRefIdx(NULL), m_uiNumPartition(0) {} |
---|
132 | ~TComCUMvField() {} |
---|
133 | |
---|
134 | // ------------------------------------------------------------------------------------------------------------------ |
---|
135 | // create / destroy |
---|
136 | // ------------------------------------------------------------------------------------------------------------------ |
---|
137 | |
---|
138 | Void create( UInt uiNumPartition ); |
---|
139 | Void destroy(); |
---|
140 | |
---|
141 | // ------------------------------------------------------------------------------------------------------------------ |
---|
142 | // clear / copy |
---|
143 | // ------------------------------------------------------------------------------------------------------------------ |
---|
144 | |
---|
145 | Void clearMvField(); |
---|
146 | |
---|
147 | Void copyFrom( TComCUMvField const * pcCUMvFieldSrc, Int iNumPartSrc, Int iPartAddrDst ); |
---|
148 | Void copyTo ( TComCUMvField* pcCUMvFieldDst, Int iPartAddrDst ) const; |
---|
149 | Void copyTo ( TComCUMvField* pcCUMvFieldDst, Int iPartAddrDst, UInt uiOffset, UInt uiNumPart ) const; |
---|
150 | |
---|
151 | // ------------------------------------------------------------------------------------------------------------------ |
---|
152 | // get |
---|
153 | // ------------------------------------------------------------------------------------------------------------------ |
---|
154 | |
---|
155 | TComMv const & getMv ( Int iIdx ) const { return m_pcMv [iIdx]; } |
---|
156 | TComMv const & getMvd ( Int iIdx ) const { return m_pcMvd [iIdx]; } |
---|
157 | Int getRefIdx( Int iIdx ) const { return m_piRefIdx[iIdx]; } |
---|
158 | |
---|
159 | AMVPInfo* getAMVPInfo () { return &m_cAMVPInfo; } |
---|
160 | |
---|
161 | // ------------------------------------------------------------------------------------------------------------------ |
---|
162 | // set |
---|
163 | // ------------------------------------------------------------------------------------------------------------------ |
---|
164 | |
---|
165 | Void setAllMv ( TComMv const & rcMv, PartSize eCUMode, Int iPartAddr, UInt uiDepth, Int iPartIdx=0 ); |
---|
166 | Void setAllMvd ( TComMv const & rcMvd, PartSize eCUMode, Int iPartAddr, UInt uiDepth, Int iPartIdx=0 ); |
---|
167 | Void setAllRefIdx ( Int iRefIdx, PartSize eMbMode, Int iPartAddr, UInt uiDepth, Int iPartIdx=0 ); |
---|
168 | Void setAllMvField( TComMvField const & mvField, PartSize eMbMode, Int iPartAddr, UInt uiDepth, Int iPartIdx=0 ); |
---|
169 | #if H_3D_SPIVMP |
---|
170 | Void setMvFieldSP ( TComDataCU* pcCU, UInt uiAbsPartIdx, TComMvField cMvField, Int iWidth, Int iHeight ); |
---|
171 | #endif |
---|
172 | #if H_3D_VSP |
---|
173 | Void setMv ( Int iIdx, TComMv const & rcMv ) { m_pcMv[iIdx] = rcMv; } |
---|
174 | Void setRefIdx ( Int iIdx, Int iRefIdx ) { m_piRefIdx[iIdx] = iRefIdx; } |
---|
175 | #endif |
---|
176 | |
---|
177 | Void setNumPartition( Int iNumPart ) |
---|
178 | { |
---|
179 | m_uiNumPartition = iNumPart; |
---|
180 | } |
---|
181 | |
---|
182 | Void linkToWithOffset( TComCUMvField const * src, Int offset ) |
---|
183 | { |
---|
184 | m_pcMv = src->m_pcMv + offset; |
---|
185 | m_pcMvd = src->m_pcMvd + offset; |
---|
186 | m_piRefIdx = src->m_piRefIdx + offset; |
---|
187 | } |
---|
188 | |
---|
189 | Void compress(Char* pePredMode, Int scale); |
---|
190 | }; |
---|
191 | |
---|
192 | //! \} |
---|
193 | |
---|
194 | #if H_3D_IV_MERGE |
---|
195 | class TComMotionCand |
---|
196 | { |
---|
197 | public: |
---|
198 | Bool m_bAvailable; |
---|
199 | TComMvField m_cMvField[2]; |
---|
200 | UChar m_uDir; |
---|
201 | #if H_3D_VSP |
---|
202 | Int m_iVspFlag; |
---|
203 | #endif |
---|
204 | Bool m_bSPIVMPFlag; |
---|
205 | |
---|
206 | public: |
---|
207 | TComMotionCand() |
---|
208 | { |
---|
209 | m_bAvailable = false; |
---|
210 | m_uDir = 0; |
---|
211 | #if H_3D_VSP |
---|
212 | m_iVspFlag = 0; |
---|
213 | #endif |
---|
214 | m_bSPIVMPFlag = false; |
---|
215 | } |
---|
216 | |
---|
217 | ~TComMotionCand() |
---|
218 | { |
---|
219 | |
---|
220 | } |
---|
221 | |
---|
222 | Void init() |
---|
223 | { |
---|
224 | TComMv cZeroMv; |
---|
225 | |
---|
226 | m_bAvailable = false; |
---|
227 | m_uDir = 0; |
---|
228 | #if H_3D_VSP |
---|
229 | m_iVspFlag = 0; |
---|
230 | #endif |
---|
231 | m_bSPIVMPFlag = false; |
---|
232 | m_cMvField[0].setMvField(cZeroMv, NOT_VALID); |
---|
233 | m_cMvField[1].setMvField(cZeroMv, NOT_VALID); |
---|
234 | } |
---|
235 | |
---|
236 | Void setCand(TComMvField* pcMvFieldNeighbours, UChar uhInterDirNeighbours |
---|
237 | #if H_3D_VSP |
---|
238 | , Int vspFlag |
---|
239 | #endif |
---|
240 | , Bool bSPIVMPFlag |
---|
241 | ) |
---|
242 | { |
---|
243 | m_bAvailable = true; |
---|
244 | m_cMvField[0] = pcMvFieldNeighbours[0]; |
---|
245 | m_cMvField[1] = pcMvFieldNeighbours[1]; |
---|
246 | m_uDir = uhInterDirNeighbours; |
---|
247 | #if H_3D_VSP |
---|
248 | m_iVspFlag = vspFlag; |
---|
249 | #endif |
---|
250 | m_bSPIVMPFlag = bSPIVMPFlag; |
---|
251 | } |
---|
252 | |
---|
253 | |
---|
254 | Void getCand(Int iCount, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours |
---|
255 | #if H_3D_VSP |
---|
256 | , Int* vspFlag |
---|
257 | #endif |
---|
258 | , Bool* pbSPIVMPFlag |
---|
259 | ) |
---|
260 | { |
---|
261 | pcMvFieldNeighbours[iCount<<1] = m_cMvField[0]; |
---|
262 | pcMvFieldNeighbours[(iCount<<1) + 1] = m_cMvField[1]; |
---|
263 | puhInterDirNeighbours[iCount] = m_uDir; |
---|
264 | #if H_3D_VSP |
---|
265 | vspFlag[iCount] = m_iVspFlag; |
---|
266 | #endif |
---|
267 | pbSPIVMPFlag[iCount] = m_bSPIVMPFlag; |
---|
268 | } |
---|
269 | }; |
---|
270 | #endif |
---|
271 | |
---|
272 | |
---|
273 | #endif // __TCOMMOTIONINFO__ |
---|