source: 3DVCSoftware/branches/HTM-16.0-MV-draft-5/source/Lib/TLibCommon/TComMotionInfo.cpp

Last change on this file was 1390, checked in by tech, 9 years ago

Removed 3D.

  • Property svn:eol-style set to native
File size: 11.1 KB
Line 
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.cpp
35    \brief    motion information handling classes
36*/
37
38#include <memory.h>
39#include "TComMotionInfo.h"
40#include "assert.h"
41#include <stdlib.h>
42#if NH_MV
43#include <iomanip>
44#endif
45//! \ingroup TLibCommon
46//! \{
47
48// ====================================================================================================================
49// Public member functions
50// ====================================================================================================================
51
52// --------------------------------------------------------------------------------------------------------------------
53// Create / destroy
54// --------------------------------------------------------------------------------------------------------------------
55
56Void TComCUMvField::create( UInt uiNumPartition )
57{
58  assert(m_pcMv     == NULL);
59  assert(m_pcMvd    == NULL);
60  assert(m_piRefIdx == NULL);
61
62  m_pcMv     = new TComMv[ uiNumPartition ];
63  m_pcMvd    = new TComMv[ uiNumPartition ];
64  m_piRefIdx = new SChar [ uiNumPartition ];
65
66  m_uiNumPartition = uiNumPartition;
67}
68
69Void TComCUMvField::destroy()
70{
71  assert(m_pcMv     != NULL);
72  assert(m_pcMvd    != NULL);
73  assert(m_piRefIdx != NULL);
74
75  delete[] m_pcMv;
76  delete[] m_pcMvd;
77  delete[] m_piRefIdx;
78
79  m_pcMv     = NULL;
80  m_pcMvd    = NULL;
81  m_piRefIdx = NULL;
82
83  m_uiNumPartition = 0;
84}
85
86// --------------------------------------------------------------------------------------------------------------------
87// Clear / copy
88// --------------------------------------------------------------------------------------------------------------------
89
90Void TComCUMvField::clearMvField()
91{
92  for ( Int i = 0; i < m_uiNumPartition; i++ )
93  {
94    m_pcMv [ i ].setZero();
95    m_pcMvd[ i ].setZero();
96  }
97  assert( sizeof( *m_piRefIdx ) == 1 );
98  memset( m_piRefIdx, NOT_VALID, m_uiNumPartition * sizeof( *m_piRefIdx ) );
99}
100
101Void TComCUMvField::copyFrom( TComCUMvField const * pcCUMvFieldSrc, Int iNumPartSrc, Int iPartAddrDst )
102{
103  Int iSizeInTComMv = sizeof( TComMv ) * iNumPartSrc;
104
105  memcpy( m_pcMv     + iPartAddrDst, pcCUMvFieldSrc->m_pcMv,     iSizeInTComMv );
106  memcpy( m_pcMvd    + iPartAddrDst, pcCUMvFieldSrc->m_pcMvd,    iSizeInTComMv );
107  memcpy( m_piRefIdx + iPartAddrDst, pcCUMvFieldSrc->m_piRefIdx, sizeof( *m_piRefIdx ) * iNumPartSrc );
108}
109
110Void TComCUMvField::copyTo( TComCUMvField* pcCUMvFieldDst, Int iPartAddrDst ) const
111{
112  copyTo( pcCUMvFieldDst, iPartAddrDst, 0, m_uiNumPartition );
113}
114
115Void TComCUMvField::copyTo( TComCUMvField* pcCUMvFieldDst, Int iPartAddrDst, UInt uiOffset, UInt uiNumPart ) const
116{
117  Int iSizeInTComMv = sizeof( TComMv ) * uiNumPart;
118  Int iOffset = uiOffset + iPartAddrDst;
119
120  memcpy( pcCUMvFieldDst->m_pcMv     + iOffset, m_pcMv     + uiOffset, iSizeInTComMv );
121  memcpy( pcCUMvFieldDst->m_pcMvd    + iOffset, m_pcMvd    + uiOffset, iSizeInTComMv );
122  memcpy( pcCUMvFieldDst->m_piRefIdx + iOffset, m_piRefIdx + uiOffset, sizeof( *m_piRefIdx ) * uiNumPart );
123}
124
125// --------------------------------------------------------------------------------------------------------------------
126// Set
127// --------------------------------------------------------------------------------------------------------------------
128
129template <typename T>
130Void TComCUMvField::setAll( T *p, T const & val, PartSize eCUMode, Int iPartAddr, UInt uiDepth, Int iPartIdx  )
131{
132  Int i;
133  p += iPartAddr;
134  Int numElements = m_uiNumPartition >> ( 2 * uiDepth );
135
136  switch( eCUMode )
137  {
138    case SIZE_2Nx2N:
139      for ( i = 0; i < numElements; i++ )
140      {
141        p[ i ] = val;
142      }
143      break;
144
145    case SIZE_2NxN:
146      numElements >>= 1;
147      for ( i = 0; i < numElements; i++ )
148      {
149        p[ i ] = val;
150      }
151      break;
152
153    case SIZE_Nx2N:
154      numElements >>= 2;
155      for ( i = 0; i < numElements; i++ )
156      {
157        p[ i                   ] = val;
158        p[ i + 2 * numElements ] = val;
159      }
160      break;
161
162    case SIZE_NxN:
163      numElements >>= 2;
164      for ( i = 0; i < numElements; i++)
165      {
166        p[ i ] = val;
167      }
168      break;
169    case SIZE_2NxnU:
170    {
171      Int iCurrPartNumQ = numElements>>2;
172      if( iPartIdx == 0 )
173      {
174        T *pT  = p;
175        T *pT2 = p + iCurrPartNumQ;
176        for (i = 0; i < (iCurrPartNumQ>>1); i++)
177        {
178          pT [i] = val;
179          pT2[i] = val;
180        }
181      }
182      else
183      {
184        T *pT  = p;
185        for (i = 0; i < (iCurrPartNumQ>>1); i++)
186        {
187          pT[i] = val;
188        }
189
190        pT = p + iCurrPartNumQ;
191        for (i = 0; i < ( (iCurrPartNumQ>>1) + (iCurrPartNumQ<<1) ); i++)
192        {
193          pT[i] = val;
194        }
195      }
196      break;
197    }
198  case SIZE_2NxnD:
199    {
200      Int iCurrPartNumQ = numElements>>2;
201      if( iPartIdx == 0 )
202      {
203        T *pT  = p;
204        for (i = 0; i < ( (iCurrPartNumQ>>1) + (iCurrPartNumQ<<1) ); i++)
205        {
206          pT[i] = val;
207        }
208        pT = p + ( numElements - iCurrPartNumQ );
209        for (i = 0; i < (iCurrPartNumQ>>1); i++)
210        {
211          pT[i] = val;
212        }
213      }
214      else
215      {
216        T *pT  = p;
217        T *pT2 = p + iCurrPartNumQ;
218        for (i = 0; i < (iCurrPartNumQ>>1); i++)
219        {
220          pT [i] = val;
221          pT2[i] = val;
222        }
223      }
224      break;
225    }
226  case SIZE_nLx2N:
227    {
228      Int iCurrPartNumQ = numElements>>2;
229      if( iPartIdx == 0 )
230      {
231        T *pT  = p;
232        T *pT2 = p + (iCurrPartNumQ<<1);
233        T *pT3 = p + (iCurrPartNumQ>>1);
234        T *pT4 = p + (iCurrPartNumQ<<1) + (iCurrPartNumQ>>1);
235
236        for (i = 0; i < (iCurrPartNumQ>>2); i++)
237        {
238          pT [i] = val;
239          pT2[i] = val;
240          pT3[i] = val;
241          pT4[i] = val;
242        }
243      }
244      else
245      {
246        T *pT  = p;
247        T *pT2 = p + (iCurrPartNumQ<<1);
248        for (i = 0; i < (iCurrPartNumQ>>2); i++)
249        {
250          pT [i] = val;
251          pT2[i] = val;
252        }
253
254        pT  = p + (iCurrPartNumQ>>1);
255        pT2 = p + (iCurrPartNumQ<<1) + (iCurrPartNumQ>>1);
256        for (i = 0; i < ( (iCurrPartNumQ>>2) + iCurrPartNumQ ); i++)
257        {
258          pT [i] = val;
259          pT2[i] = val;
260        }
261      }
262      break;
263    }
264  case SIZE_nRx2N:
265    {
266      Int iCurrPartNumQ = numElements>>2;
267      if( iPartIdx == 0 )
268      {
269        T *pT  = p;
270        T *pT2 = p + (iCurrPartNumQ<<1);
271        for (i = 0; i < ( (iCurrPartNumQ>>2) + iCurrPartNumQ ); i++)
272        {
273          pT [i] = val;
274          pT2[i] = val;
275        }
276
277        pT  = p + iCurrPartNumQ + (iCurrPartNumQ>>1);
278        pT2 = p + numElements - iCurrPartNumQ + (iCurrPartNumQ>>1);
279        for (i = 0; i < (iCurrPartNumQ>>2); i++)
280        {
281          pT [i] = val;
282          pT2[i] = val;
283        }
284      }
285      else
286      {
287        T *pT  = p;
288        T *pT2 = p + (iCurrPartNumQ>>1);
289        T *pT3 = p + (iCurrPartNumQ<<1);
290        T *pT4 = p + (iCurrPartNumQ<<1) + (iCurrPartNumQ>>1);
291        for (i = 0; i < (iCurrPartNumQ>>2); i++)
292        {
293          pT [i] = val;
294          pT2[i] = val;
295          pT3[i] = val;
296          pT4[i] = val;
297        }
298      }
299      break;
300    }
301    default:
302      assert(0);
303      break;
304  }
305}
306
307Void TComCUMvField::setAllMv( TComMv const & mv, PartSize eCUMode, Int iPartAddr, UInt uiDepth, Int iPartIdx )
308{
309  setAll(m_pcMv, mv, eCUMode, iPartAddr, uiDepth, iPartIdx);
310}
311
312Void TComCUMvField::setAllMvd( TComMv const & mvd, PartSize eCUMode, Int iPartAddr, UInt uiDepth, Int iPartIdx )
313{
314  setAll(m_pcMvd, mvd, eCUMode, iPartAddr, uiDepth, iPartIdx);
315}
316
317Void TComCUMvField::setAllRefIdx ( Int iRefIdx, PartSize eCUMode, Int iPartAddr, UInt uiDepth, Int iPartIdx )
318{
319  setAll(m_piRefIdx, static_cast<SChar>(iRefIdx), eCUMode, iPartAddr, uiDepth, iPartIdx);
320}
321
322Void TComCUMvField::setAllMvField( TComMvField const & mvField, PartSize eCUMode, Int iPartAddr, UInt uiDepth, Int iPartIdx )
323{
324  setAllMv    ( mvField.getMv(),     eCUMode, iPartAddr, uiDepth, iPartIdx );
325  setAllRefIdx( mvField.getRefIdx(), eCUMode, iPartAddr, uiDepth, iPartIdx );
326}
327
328
329/**Subsampling of the stored prediction mode, reference index and motion vector
330 * \param pePredMode Pointer to prediction modes
331 * \param scale      Factor by which to subsample motion information
332 */
333Void TComCUMvField::compress(SChar* pePredMode, Int scale)
334{
335  Int N = scale * scale;
336  assert( N > 0 && N <= m_uiNumPartition);
337
338  for ( Int uiPartIdx = 0; uiPartIdx < m_uiNumPartition; uiPartIdx += N )
339  {
340    TComMv cMv(0,0);
341    Int iRefIdx = 0;
342
343    cMv = m_pcMv[ uiPartIdx ];
344    PredMode predMode = static_cast<PredMode>( pePredMode[ uiPartIdx ] );
345    iRefIdx = m_piRefIdx[ uiPartIdx ];
346    for ( Int i = 0; i < N; i++ )
347    {
348      m_pcMv[ uiPartIdx + i ] = cMv;
349      pePredMode[ uiPartIdx + i ] = predMode;
350      m_piRefIdx[ uiPartIdx + i ] = iRefIdx;
351    }
352  }
353}
354
355#if NH_MV
356Void TComCUMvField::print(SChar* pePredMode)
357{
358  for ( Int uiPartIdx = 0; uiPartIdx < m_uiNumPartition; uiPartIdx += 1 )
359  {
360    PredMode predMode = static_cast<PredMode>( pePredMode[ uiPartIdx ] );
361
362    if ( predMode == MODE_INTRA)
363    {
364      std::cout << std::setfill(' ') << "(" 
365        << std::setw(3) <<  "   "    << ","
366        << std::setw(3) <<  "   "    << ","
367        << std::setw(3) <<  "   "    << ")";
368    }
369    else
370    {
371      ;
372      std::cout << std::setfill(' ') << "(" 
373        << std::setw(3) <<  (Int) m_piRefIdx[ uiPartIdx ]        << ","
374        << std::setw(3) <<  m_pcMv[ uiPartIdx ].getHor()   << ","
375        << std::setw(3) <<  m_pcMv[ uiPartIdx ].getVer()   << ")";
376    }   
377  }
378}
379
380#endif
381//! \}
Note: See TracBrowser for help on using the repository browser.