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