1 | |
---|
2 | |
---|
3 | /** \file TComMotionInfo.cpp |
---|
4 | \brief motion information handling classes |
---|
5 | */ |
---|
6 | |
---|
7 | #include <memory.h> |
---|
8 | #include "TComMotionInfo.h" |
---|
9 | #include "assert.h" |
---|
10 | #include <stdlib.h> |
---|
11 | |
---|
12 | // ==================================================================================================================== |
---|
13 | // Public member functions |
---|
14 | // ==================================================================================================================== |
---|
15 | |
---|
16 | // -------------------------------------------------------------------------------------------------------------------- |
---|
17 | // Create / destroy |
---|
18 | // -------------------------------------------------------------------------------------------------------------------- |
---|
19 | |
---|
20 | Void TComCUMvField::create( UInt uiNumPartition ) |
---|
21 | { |
---|
22 | m_pcMv = ( TComMv* )xMalloc( TComMv, uiNumPartition ); |
---|
23 | m_pcMvd = ( TComMv* )xMalloc( TComMv, uiNumPartition ); |
---|
24 | m_piRefIdx = ( Int* )xMalloc( Int, uiNumPartition ); |
---|
25 | |
---|
26 | m_uiNumPartition = uiNumPartition; |
---|
27 | } |
---|
28 | |
---|
29 | Void TComCUMvField::destroy() |
---|
30 | { |
---|
31 | if( m_pcMv ) |
---|
32 | { |
---|
33 | xFree( m_pcMv ); m_pcMv = NULL; |
---|
34 | } |
---|
35 | if( m_pcMvd ) |
---|
36 | { |
---|
37 | xFree( m_pcMvd ); m_pcMvd = NULL; |
---|
38 | } |
---|
39 | if( m_piRefIdx ) |
---|
40 | { |
---|
41 | xFree( m_piRefIdx ); m_piRefIdx = NULL; |
---|
42 | } |
---|
43 | } |
---|
44 | |
---|
45 | // -------------------------------------------------------------------------------------------------------------------- |
---|
46 | // Clear / copy |
---|
47 | // -------------------------------------------------------------------------------------------------------------------- |
---|
48 | |
---|
49 | Void TComCUMvField::clearMv( Int iPartAddr, UInt uiDepth ) |
---|
50 | { |
---|
51 | Int iNumPartition = m_uiNumPartition >> (uiDepth<<1); |
---|
52 | |
---|
53 | for ( Int i = iNumPartition - 1; i >= 0; i-- ) |
---|
54 | { |
---|
55 | m_pcMv[ i ].setZero(); |
---|
56 | } |
---|
57 | } |
---|
58 | |
---|
59 | Void TComCUMvField::clearMvd( Int iPartAddr, UInt uiDepth ) |
---|
60 | { |
---|
61 | Int iNumPartition = m_uiNumPartition >> (uiDepth<<1); |
---|
62 | |
---|
63 | for ( Int i = iNumPartition - 1; i >= 0; i-- ) |
---|
64 | { |
---|
65 | m_pcMvd[ i ].setZero(); |
---|
66 | } |
---|
67 | } |
---|
68 | |
---|
69 | Void TComCUMvField::clearMvField() |
---|
70 | { |
---|
71 | for ( Int i = m_uiNumPartition - 1; i >= 0; i-- ) |
---|
72 | { |
---|
73 | m_pcMv [ i ].setZero(); |
---|
74 | m_pcMvd [ i ].setZero(); |
---|
75 | m_piRefIdx[ i ] = NOT_VALID; |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|
79 | Void TComCUMvField::copyFrom( TComCUMvField* pcCUMvFieldSrc, Int iNumPartSrc, Int iPartAddrDst ) |
---|
80 | { |
---|
81 | Int iSizeInTComMv = sizeof( TComMv ) * iNumPartSrc; |
---|
82 | |
---|
83 | memcpy( m_pcMv + iPartAddrDst, pcCUMvFieldSrc->getMv(), iSizeInTComMv ); |
---|
84 | memcpy( m_pcMvd + iPartAddrDst, pcCUMvFieldSrc->getMvd(), iSizeInTComMv ); |
---|
85 | memcpy( m_piRefIdx + iPartAddrDst, pcCUMvFieldSrc->getRefIdx(), sizeof( Int ) * iNumPartSrc ); |
---|
86 | } |
---|
87 | |
---|
88 | Void TComCUMvField::copyTo( TComCUMvField* pcCUMvFieldDst, Int iPartAddrDst ) |
---|
89 | { |
---|
90 | Int iSizeInTComMv = sizeof( TComMv ) * m_uiNumPartition; |
---|
91 | |
---|
92 | memcpy( pcCUMvFieldDst->getMv() + iPartAddrDst, m_pcMv, iSizeInTComMv ); |
---|
93 | memcpy( pcCUMvFieldDst->getMvd() + iPartAddrDst, m_pcMvd, iSizeInTComMv ); |
---|
94 | memcpy( pcCUMvFieldDst->getRefIdx() + iPartAddrDst, m_piRefIdx, sizeof( Int ) * m_uiNumPartition ); |
---|
95 | } |
---|
96 | |
---|
97 | Void TComCUMvField::copyTo( TComCUMvField* pcCUMvFieldDst, Int iPartAddrDst, UInt uiOffset, UInt uiNumPart ) |
---|
98 | { |
---|
99 | Int iSizeInTComMv = sizeof( TComMv ) * uiNumPart; |
---|
100 | Int iOffset = uiOffset + iPartAddrDst; |
---|
101 | |
---|
102 | memcpy( pcCUMvFieldDst->getMv() + iOffset, m_pcMv + uiOffset, iSizeInTComMv ); |
---|
103 | memcpy( pcCUMvFieldDst->getMvd() + iOffset, m_pcMvd + uiOffset, iSizeInTComMv ); |
---|
104 | memcpy( pcCUMvFieldDst->getRefIdx() + iOffset, m_piRefIdx + uiOffset, sizeof( Int ) * uiNumPart ); |
---|
105 | } |
---|
106 | |
---|
107 | Void TComCUMvField::copyMvTo( TComCUMvField* pcCUMvFieldDst, Int iPartAddrDst ) |
---|
108 | { |
---|
109 | memcpy( pcCUMvFieldDst->getMv() + iPartAddrDst, m_pcMv, sizeof( TComMv ) * m_uiNumPartition ); |
---|
110 | } |
---|
111 | |
---|
112 | // -------------------------------------------------------------------------------------------------------------------- |
---|
113 | // Set |
---|
114 | // -------------------------------------------------------------------------------------------------------------------- |
---|
115 | |
---|
116 | Void TComCUMvField::setAllMv( TComMv& rcMv, PartSize eCUMode, Int iPartAddr, Int iPartIdx, UInt uiDepth ) |
---|
117 | { |
---|
118 | Int i; |
---|
119 | TComMv* pcMv = m_pcMv + iPartAddr; |
---|
120 | register TComMv cMv = rcMv; |
---|
121 | Int iNumPartition = m_uiNumPartition >> (uiDepth<<1); |
---|
122 | |
---|
123 | switch( eCUMode ) |
---|
124 | { |
---|
125 | case SIZE_2Nx2N: |
---|
126 | for ( i = iNumPartition - 1; i >= 0; i-- ) |
---|
127 | { |
---|
128 | pcMv[ i ] = cMv; |
---|
129 | } |
---|
130 | break; |
---|
131 | case SIZE_2NxN: |
---|
132 | for ( i = ( iNumPartition >> 1 ) - 1; i >= 0; i-- ) |
---|
133 | { |
---|
134 | pcMv[ i ] = cMv; |
---|
135 | } |
---|
136 | break; |
---|
137 | case SIZE_Nx2N: |
---|
138 | { |
---|
139 | UInt uiOffset = iNumPartition >> 1; |
---|
140 | for ( i = ( iNumPartition >> 2 ) - 1; i >= 0; i-- ) |
---|
141 | { |
---|
142 | pcMv[ i ] = cMv; |
---|
143 | pcMv[ i + uiOffset ] = cMv; |
---|
144 | } |
---|
145 | break; |
---|
146 | } |
---|
147 | case SIZE_NxN: |
---|
148 | for ( i = ( iNumPartition >> 2 ) - 1; i >= 0; i-- ) |
---|
149 | { |
---|
150 | pcMv[ i ] = cMv; |
---|
151 | } |
---|
152 | break; |
---|
153 | default: |
---|
154 | assert(0); |
---|
155 | break; |
---|
156 | } |
---|
157 | } |
---|
158 | |
---|
159 | Void TComCUMvField::setAllMvd( TComMv& rcMvd, PartSize eCUMode, Int iPartAddr, Int iPartIdx, UInt uiDepth ) |
---|
160 | { |
---|
161 | Int i; |
---|
162 | TComMv* pcMvd = m_pcMvd + iPartAddr; |
---|
163 | register TComMv cMvd = rcMvd; |
---|
164 | Int iNumPartition = m_uiNumPartition >> (uiDepth<<1); |
---|
165 | |
---|
166 | switch( eCUMode ) |
---|
167 | { |
---|
168 | case SIZE_2Nx2N: |
---|
169 | for ( i = iNumPartition - 1; i >= 0; i-- ) |
---|
170 | { |
---|
171 | pcMvd[ i ] = cMvd; |
---|
172 | } |
---|
173 | break; |
---|
174 | case SIZE_2NxN: |
---|
175 | for ( i = ( iNumPartition >> 1 ) - 1; i >= 0; i-- ) |
---|
176 | { |
---|
177 | pcMvd[ i ] = cMvd; |
---|
178 | } |
---|
179 | break; |
---|
180 | case SIZE_Nx2N: |
---|
181 | { |
---|
182 | UInt uiOffset = iNumPartition >> 1; |
---|
183 | for ( i = ( iNumPartition >> 2 ) - 1; i >= 0; i-- ) |
---|
184 | { |
---|
185 | pcMvd[ i ] = cMvd; |
---|
186 | pcMvd[ i + uiOffset ] = cMvd; |
---|
187 | } |
---|
188 | break; |
---|
189 | } |
---|
190 | case SIZE_NxN: |
---|
191 | for ( i = ( iNumPartition >> 2 ) - 1; i >= 0; i-- ) |
---|
192 | { |
---|
193 | pcMvd[ i ] = cMvd; |
---|
194 | } |
---|
195 | break; |
---|
196 | default: |
---|
197 | assert(0); |
---|
198 | break; |
---|
199 | } |
---|
200 | } |
---|
201 | |
---|
202 | Void TComCUMvField::setAllRefIdx ( Int iRefIdx, PartSize eCUMode, Int iPartAddr, Int iPartIdx, UInt uiDepth ) |
---|
203 | { |
---|
204 | Int i; |
---|
205 | Int* piRefIdx = m_piRefIdx + iPartAddr; |
---|
206 | Int iNumPartition = m_uiNumPartition >> (uiDepth<<1); |
---|
207 | |
---|
208 | switch( eCUMode ) |
---|
209 | { |
---|
210 | case SIZE_2Nx2N: |
---|
211 | for ( i = iNumPartition - 1; i >= 0; i-- ) |
---|
212 | { |
---|
213 | piRefIdx[ i ] = iRefIdx; |
---|
214 | } |
---|
215 | break; |
---|
216 | case SIZE_2NxN: |
---|
217 | for ( i = ( iNumPartition >> 1 ) - 1; i >= 0; i-- ) |
---|
218 | { |
---|
219 | piRefIdx[ i ] = iRefIdx; |
---|
220 | } |
---|
221 | break; |
---|
222 | case SIZE_Nx2N: |
---|
223 | { |
---|
224 | UInt uiOffset = iNumPartition >> 1; |
---|
225 | for ( i = ( iNumPartition >> 2 ) - 1; i >= 0; i-- ) |
---|
226 | { |
---|
227 | piRefIdx[ i ] = iRefIdx; |
---|
228 | piRefIdx[ i + uiOffset ] = iRefIdx; |
---|
229 | } |
---|
230 | break; |
---|
231 | } |
---|
232 | case SIZE_NxN: |
---|
233 | for ( i = ( iNumPartition >> 2 ) - 1; i >= 0; i-- ) |
---|
234 | { |
---|
235 | piRefIdx[ i ] = iRefIdx; |
---|
236 | } |
---|
237 | break; |
---|
238 | default: |
---|
239 | assert(0); |
---|
240 | break; |
---|
241 | } |
---|
242 | } |
---|
243 | |
---|
244 | Void TComCUMvField::setAllMvField ( TComMv& rcMv, Int iRefIdx, PartSize eCUMode, Int iPartAddr, Int iPartIdx, UInt uiDepth ) |
---|
245 | { |
---|
246 | setAllMv( rcMv, eCUMode, iPartAddr, iPartIdx, uiDepth); |
---|
247 | setAllRefIdx(iRefIdx, eCUMode,iPartAddr,iPartIdx,uiDepth); |
---|
248 | return; |
---|
249 | } |
---|
250 | |
---|
251 | #if AMVP_BUFFERCOMPRESS |
---|
252 | /**Subsampling of the stored prediction mode, reference index and motion vector |
---|
253 | * \param pePredMode |
---|
254 | * \returns Void |
---|
255 | */ |
---|
256 | Void TComCUMvField::compress(PredMode* pePredMode,UChar* puhInterDir) |
---|
257 | { |
---|
258 | Int N = AMVP_DECIMATION_FACTOR; |
---|
259 | for ( Int uiPartIdx = 0; uiPartIdx <m_uiNumPartition; uiPartIdx+=(N*N) ) |
---|
260 | { |
---|
261 | Int jj = uiPartIdx+N*N; |
---|
262 | |
---|
263 | TComMv cMv(0,0); |
---|
264 | #if MV_COMPRESS_MODE_REFIDX |
---|
265 | PredMode predMode = MODE_INTRA; |
---|
266 | Int iRefIdx = 0; |
---|
267 | const UChar uhInterDir = puhInterDir[ uiPartIdx ]; |
---|
268 | |
---|
269 | cMv = m_pcMv[ uiPartIdx ]; |
---|
270 | predMode = pePredMode[ uiPartIdx ]; |
---|
271 | iRefIdx = m_piRefIdx[ uiPartIdx ]; |
---|
272 | #else |
---|
273 | if (pePredMode[uiPartIdx]!=MODE_INTRA) cMv = m_pcMv[ uiPartIdx ]; |
---|
274 | #endif |
---|
275 | for ( Int i = jj-1; i >= uiPartIdx; i-- ) |
---|
276 | { |
---|
277 | m_pcMv[ i ] = cMv; |
---|
278 | #if MV_COMPRESS_MODE_REFIDX |
---|
279 | pePredMode[ i ] = predMode; |
---|
280 | m_piRefIdx[ i ] = iRefIdx; |
---|
281 | puhInterDir[ i ] = uhInterDir; |
---|
282 | #endif |
---|
283 | } |
---|
284 | } |
---|
285 | } |
---|
286 | #endif |
---|