source: 3DVCSoftware/branches/HTM-11.2-dev3-Sharp/source/Lib/TLibCommon/TComMotionInfo.cpp @ 997

Last change on this file since 997 was 872, checked in by tech, 11 years ago

Merged HTM-10.0-dev0@871. (MV-HEVC 7 HLS)

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