source: 3DVCSoftware/branches/HTM-14.0-MV-draft-3/source/Lib/TLibCommon/TComDataCU.cpp @ 1417

Last change on this file since 1417 was 1191, checked in by tech, 10 years ago

Removed 3D-HEVC.

  • Property svn:eol-style set to native
File size: 128.9 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     TComDataCU.cpp
35    \brief    CU data structure
36    \todo     not all entities are documented
37*/
38
39#include "TComDataCU.h"
40#include "TComPic.h"
41
42//! \ingroup TLibCommon
43//! \{
44
45#if ADAPTIVE_QP_SELECTION
46Int * TComDataCU::m_pcGlbArlCoeffY  = NULL;
47Int * TComDataCU::m_pcGlbArlCoeffCb = NULL;
48Int * TComDataCU::m_pcGlbArlCoeffCr = NULL;
49#endif
50
51// ====================================================================================================================
52// Constructor / destructor / create / destroy
53// ====================================================================================================================
54
55TComDataCU::TComDataCU()
56{
57  m_pcPic              = NULL;
58  m_pcSlice            = NULL;
59  m_puhDepth           = NULL;
60 
61  m_skipFlag           = NULL;
62  m_pePartSize         = NULL;
63  m_pePredMode         = NULL;
64  m_CUTransquantBypass = NULL;
65  m_puhWidth           = NULL;
66  m_puhHeight          = NULL;
67  m_phQP               = NULL;
68  m_pbMergeFlag        = NULL;
69  m_puhMergeIndex      = NULL;
70  m_puhLumaIntraDir    = NULL;
71  m_puhChromaIntraDir  = NULL;
72  m_puhInterDir        = NULL;
73  m_puhTrIdx           = NULL;
74  m_puhTransformSkip[0] = NULL;
75  m_puhTransformSkip[1] = NULL;
76  m_puhTransformSkip[2] = NULL;
77  m_puhCbf[0]          = NULL;
78  m_puhCbf[1]          = NULL;
79  m_puhCbf[2]          = NULL;
80  m_pcTrCoeffY         = NULL;
81  m_pcTrCoeffCb        = NULL;
82  m_pcTrCoeffCr        = NULL;
83#if ADAPTIVE_QP_SELECTION 
84  m_ArlCoeffIsAliasedAllocation = false;
85  m_pcArlCoeffY        = NULL;
86  m_pcArlCoeffCb       = NULL;
87  m_pcArlCoeffCr       = NULL;
88#endif
89 
90  m_pbIPCMFlag         = NULL;
91  m_pcIPCMSampleY      = NULL;
92  m_pcIPCMSampleCb     = NULL;
93  m_pcIPCMSampleCr     = NULL;
94
95  m_pcPattern          = NULL;
96 
97  m_pcCUAboveLeft      = NULL;
98  m_pcCUAboveRight     = NULL;
99  m_pcCUAbove          = NULL;
100  m_pcCULeft           = NULL;
101 
102  m_apcCUColocated[0]  = NULL;
103  m_apcCUColocated[1]  = NULL;
104 
105  m_apiMVPIdx[0]       = NULL;
106  m_apiMVPIdx[1]       = NULL;
107  m_apiMVPNum[0]       = NULL;
108  m_apiMVPNum[1]       = NULL;
109
110  m_bDecSubCu          = false;
111  m_sliceStartCU        = 0;
112  m_sliceSegmentStartCU = 0;
113
114}
115
116TComDataCU::~TComDataCU()
117{
118}
119
120Void TComDataCU::create(UInt uiNumPartition, UInt uiWidth, UInt uiHeight, Bool bDecSubCu, Int unitSize
121#if ADAPTIVE_QP_SELECTION
122                        , Bool bGlobalRMARLBuffer
123#endif                                             
124                        )
125{
126  m_bDecSubCu = bDecSubCu;
127 
128  m_pcPic              = NULL;
129  m_pcSlice            = NULL;
130  m_uiNumPartition     = uiNumPartition;
131  m_unitSize = unitSize;
132 
133  if ( !bDecSubCu )
134  {
135    m_phQP               = (Char*     )xMalloc(Char,     uiNumPartition);
136    m_puhDepth           = (UChar*    )xMalloc(UChar,    uiNumPartition);
137    m_puhWidth           = (UChar*    )xMalloc(UChar,    uiNumPartition);
138    m_puhHeight          = (UChar*    )xMalloc(UChar,    uiNumPartition);
139
140    m_skipFlag           = new Bool[ uiNumPartition ];
141    m_pePartSize         = new Char[ uiNumPartition ];
142    memset( m_pePartSize, SIZE_NONE,uiNumPartition * sizeof( *m_pePartSize ) );
143    m_pePredMode         = new Char[ uiNumPartition ];
144    m_CUTransquantBypass = new Bool[ uiNumPartition ];
145    m_pbMergeFlag        = (Bool*  )xMalloc(Bool,   uiNumPartition);
146    m_puhMergeIndex      = (UChar* )xMalloc(UChar,  uiNumPartition);
147    m_puhLumaIntraDir    = (UChar* )xMalloc(UChar,  uiNumPartition);
148    m_puhChromaIntraDir  = (UChar* )xMalloc(UChar,  uiNumPartition);
149    m_puhInterDir        = (UChar* )xMalloc(UChar,  uiNumPartition);
150   
151    m_puhTrIdx           = (UChar* )xMalloc(UChar,  uiNumPartition);
152    m_puhTransformSkip[0] = (UChar* )xMalloc(UChar,  uiNumPartition);
153    m_puhTransformSkip[1] = (UChar* )xMalloc(UChar,  uiNumPartition);
154    m_puhTransformSkip[2] = (UChar* )xMalloc(UChar,  uiNumPartition);
155
156    m_puhCbf[0]          = (UChar* )xMalloc(UChar,  uiNumPartition);
157    m_puhCbf[1]          = (UChar* )xMalloc(UChar,  uiNumPartition);
158    m_puhCbf[2]          = (UChar* )xMalloc(UChar,  uiNumPartition);
159   
160    m_apiMVPIdx[0]       = new Char[ uiNumPartition ];
161    m_apiMVPIdx[1]       = new Char[ uiNumPartition ];
162    m_apiMVPNum[0]       = new Char[ uiNumPartition ];
163    m_apiMVPNum[1]       = new Char[ uiNumPartition ];
164    memset( m_apiMVPIdx[0], -1,uiNumPartition * sizeof( Char ) );
165    memset( m_apiMVPIdx[1], -1,uiNumPartition * sizeof( Char ) );
166   
167    m_pcTrCoeffY         = (TCoeff*)xMalloc(TCoeff, uiWidth*uiHeight);
168    m_pcTrCoeffCb        = (TCoeff*)xMalloc(TCoeff, uiWidth*uiHeight/4);
169    m_pcTrCoeffCr        = (TCoeff*)xMalloc(TCoeff, uiWidth*uiHeight/4);
170    memset( m_pcTrCoeffY, 0,uiWidth*uiHeight * sizeof( TCoeff ) );
171    memset( m_pcTrCoeffCb, 0,uiWidth*uiHeight/4 * sizeof( TCoeff ) );
172    memset( m_pcTrCoeffCr, 0,uiWidth*uiHeight/4 * sizeof( TCoeff ) );
173#if ADAPTIVE_QP_SELECTION   
174    if( bGlobalRMARLBuffer )
175    {
176      if( m_pcGlbArlCoeffY == NULL )
177      {
178        m_pcGlbArlCoeffY   = (Int*)xMalloc(Int, uiWidth*uiHeight);
179        m_pcGlbArlCoeffCb  = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
180        m_pcGlbArlCoeffCr  = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
181      }
182      m_pcArlCoeffY        = m_pcGlbArlCoeffY;
183      m_pcArlCoeffCb       = m_pcGlbArlCoeffCb;
184      m_pcArlCoeffCr       = m_pcGlbArlCoeffCr;
185      m_ArlCoeffIsAliasedAllocation = true;
186    }
187    else
188    {
189      m_pcArlCoeffY        = (Int*)xMalloc(Int, uiWidth*uiHeight);
190      m_pcArlCoeffCb       = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
191      m_pcArlCoeffCr       = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
192    }
193#endif
194   
195    m_pbIPCMFlag         = (Bool*  )xMalloc(Bool, uiNumPartition);
196    m_pcIPCMSampleY      = (Pel*   )xMalloc(Pel , uiWidth*uiHeight);
197    m_pcIPCMSampleCb     = (Pel*   )xMalloc(Pel , uiWidth*uiHeight/4);
198    m_pcIPCMSampleCr     = (Pel*   )xMalloc(Pel , uiWidth*uiHeight/4);
199
200    m_acCUMvField[0].create( uiNumPartition );
201    m_acCUMvField[1].create( uiNumPartition );
202   
203  }
204  else
205  {
206    m_acCUMvField[0].setNumPartition(uiNumPartition );
207    m_acCUMvField[1].setNumPartition(uiNumPartition );
208  }
209  m_sliceStartCU        = (UInt*  )xMalloc(UInt, uiNumPartition);
210  m_sliceSegmentStartCU = (UInt*  )xMalloc(UInt, uiNumPartition);
211 
212  // create pattern memory
213  m_pcPattern            = (TComPattern*)xMalloc(TComPattern, 1);
214
215
216  // create motion vector fields
217 
218  m_pcCUAboveLeft      = NULL;
219  m_pcCUAboveRight     = NULL;
220  m_pcCUAbove          = NULL;
221  m_pcCULeft           = NULL;
222 
223  m_apcCUColocated[0]  = NULL;
224  m_apcCUColocated[1]  = NULL;
225}
226
227Void TComDataCU::destroy()
228{
229  m_pcPic              = NULL;
230  m_pcSlice            = NULL;
231 
232  if ( m_pcPattern )
233  { 
234    xFree(m_pcPattern);
235    m_pcPattern = NULL;
236  }
237 
238  // encoder-side buffer free
239  if ( !m_bDecSubCu )
240  {
241    if ( m_phQP               ) { xFree(m_phQP);                m_phQP              = NULL; }
242    if ( m_puhDepth           ) { xFree(m_puhDepth);            m_puhDepth          = NULL; }
243    if ( m_puhWidth           ) { xFree(m_puhWidth);            m_puhWidth          = NULL; }
244    if ( m_puhHeight          ) { xFree(m_puhHeight);           m_puhHeight         = NULL; }
245
246    if ( m_skipFlag           ) { delete[] m_skipFlag;          m_skipFlag          = NULL; }
247    if ( m_pePartSize         ) { delete[] m_pePartSize;        m_pePartSize        = NULL; }
248    if ( m_pePredMode         ) { delete[] m_pePredMode;        m_pePredMode        = NULL; }
249    if ( m_CUTransquantBypass ) { delete[] m_CUTransquantBypass;m_CUTransquantBypass = NULL; }
250    if ( m_puhCbf[0]          ) { xFree(m_puhCbf[0]);           m_puhCbf[0]         = NULL; }
251    if ( m_puhCbf[1]          ) { xFree(m_puhCbf[1]);           m_puhCbf[1]         = NULL; }
252    if ( m_puhCbf[2]          ) { xFree(m_puhCbf[2]);           m_puhCbf[2]         = NULL; }
253    if ( m_puhInterDir        ) { xFree(m_puhInterDir);         m_puhInterDir       = NULL; }
254    if ( m_pbMergeFlag        ) { xFree(m_pbMergeFlag);         m_pbMergeFlag       = NULL; }
255    if ( m_puhMergeIndex      ) { xFree(m_puhMergeIndex);       m_puhMergeIndex     = NULL; }
256    if ( m_puhLumaIntraDir    ) { xFree(m_puhLumaIntraDir);     m_puhLumaIntraDir   = NULL; }
257    if ( m_puhChromaIntraDir  ) { xFree(m_puhChromaIntraDir);   m_puhChromaIntraDir = NULL; }
258    if ( m_puhTrIdx           ) { xFree(m_puhTrIdx);            m_puhTrIdx          = NULL; }
259    if ( m_puhTransformSkip[0]) { xFree(m_puhTransformSkip[0]); m_puhTransformSkip[0] = NULL; }
260    if ( m_puhTransformSkip[1]) { xFree(m_puhTransformSkip[1]); m_puhTransformSkip[1] = NULL; }
261    if ( m_puhTransformSkip[2]) { xFree(m_puhTransformSkip[2]); m_puhTransformSkip[2] = NULL; }
262    if ( m_pcTrCoeffY         ) { xFree(m_pcTrCoeffY);          m_pcTrCoeffY        = NULL; }
263    if ( m_pcTrCoeffCb        ) { xFree(m_pcTrCoeffCb);         m_pcTrCoeffCb       = NULL; }
264    if ( m_pcTrCoeffCr        ) { xFree(m_pcTrCoeffCr);         m_pcTrCoeffCr       = NULL; }
265#if ADAPTIVE_QP_SELECTION
266    if (!m_ArlCoeffIsAliasedAllocation)
267    {
268      xFree(m_pcArlCoeffY); m_pcArlCoeffY = 0;
269      xFree(m_pcArlCoeffCb); m_pcArlCoeffCb = 0;
270      xFree(m_pcArlCoeffCr); m_pcArlCoeffCr = 0;
271    }
272    if ( m_pcGlbArlCoeffY     ) { xFree(m_pcGlbArlCoeffY);      m_pcGlbArlCoeffY    = NULL; }
273    if ( m_pcGlbArlCoeffCb    ) { xFree(m_pcGlbArlCoeffCb);     m_pcGlbArlCoeffCb   = NULL; }
274    if ( m_pcGlbArlCoeffCr    ) { xFree(m_pcGlbArlCoeffCr);     m_pcGlbArlCoeffCr   = NULL; }
275#endif
276    if ( m_pbIPCMFlag         ) { xFree(m_pbIPCMFlag   );       m_pbIPCMFlag        = NULL; }
277    if ( m_pcIPCMSampleY      ) { xFree(m_pcIPCMSampleY);       m_pcIPCMSampleY     = NULL; }
278    if ( m_pcIPCMSampleCb     ) { xFree(m_pcIPCMSampleCb);      m_pcIPCMSampleCb    = NULL; }
279    if ( m_pcIPCMSampleCr     ) { xFree(m_pcIPCMSampleCr);      m_pcIPCMSampleCr    = NULL; }
280    if ( m_apiMVPIdx[0]       ) { delete[] m_apiMVPIdx[0];      m_apiMVPIdx[0]      = NULL; }
281    if ( m_apiMVPIdx[1]       ) { delete[] m_apiMVPIdx[1];      m_apiMVPIdx[1]      = NULL; }
282    if ( m_apiMVPNum[0]       ) { delete[] m_apiMVPNum[0];      m_apiMVPNum[0]      = NULL; }
283    if ( m_apiMVPNum[1]       ) { delete[] m_apiMVPNum[1];      m_apiMVPNum[1]      = NULL; }
284
285
286    m_acCUMvField[0].destroy();
287    m_acCUMvField[1].destroy();
288
289  }
290  m_pcCUAboveLeft       = NULL;
291  m_pcCUAboveRight      = NULL;
292  m_pcCUAbove           = NULL;
293  m_pcCULeft            = NULL;
294 
295  m_apcCUColocated[0]   = NULL;
296  m_apcCUColocated[1]   = NULL;
297
298  if( m_sliceStartCU )
299  {
300    xFree(m_sliceStartCU);
301    m_sliceStartCU=NULL;
302  }
303  if(m_sliceSegmentStartCU )
304  {
305    xFree(m_sliceSegmentStartCU);
306    m_sliceSegmentStartCU=NULL;
307  }
308}
309
310// ====================================================================================================================
311// Public member functions
312// ====================================================================================================================
313
314// --------------------------------------------------------------------------------------------------------------------
315// Initialization
316// --------------------------------------------------------------------------------------------------------------------
317
318/**
319 - initialize top-level CU
320 - internal buffers are already created
321 - set values before encoding a CU
322 .
323 \param  pcPic     picture (TComPic) class pointer
324 \param  iCUAddr   CU address
325 */
326Void TComDataCU::initCU( TComPic* pcPic, UInt iCUAddr )
327{
328
329  m_pcPic              = pcPic;
330  m_pcSlice            = pcPic->getSlice(pcPic->getCurrSliceIdx());
331  m_uiCUAddr           = iCUAddr;
332  m_uiCUPelX           = ( iCUAddr % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth;
333  m_uiCUPelY           = ( iCUAddr / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight;
334  m_uiAbsIdxInLCU      = 0;
335  m_dTotalCost         = MAX_DOUBLE;
336  m_uiTotalDistortion  = 0;
337  m_uiTotalBits        = 0;
338  m_uiTotalBins        = 0;
339  m_uiNumPartition     = pcPic->getNumPartInCU();
340 
341  for(Int i=0; i<pcPic->getNumPartInCU(); i++)
342  {
343    if(pcPic->getPicSym()->getInverseCUOrderMap(iCUAddr)*pcPic->getNumPartInCU()+i>=getSlice()->getSliceCurStartCUAddr())
344    {
345      m_sliceStartCU[i]=getSlice()->getSliceCurStartCUAddr();
346    }
347    else
348    {
349      m_sliceStartCU[i]=pcPic->getCU(getAddr())->m_sliceStartCU[i];
350    }
351  }
352  for(Int i=0; i<pcPic->getNumPartInCU(); i++)
353  {
354    if(pcPic->getPicSym()->getInverseCUOrderMap(iCUAddr)*pcPic->getNumPartInCU()+i>=getSlice()->getSliceSegmentCurStartCUAddr())
355    {
356      m_sliceSegmentStartCU[i]=getSlice()->getSliceSegmentCurStartCUAddr();
357    }
358    else
359    {
360      m_sliceSegmentStartCU[i]=pcPic->getCU(getAddr())->m_sliceSegmentStartCU[i];
361    }
362  }
363
364  Int partStartIdx = getSlice()->getSliceSegmentCurStartCUAddr() - pcPic->getPicSym()->getInverseCUOrderMap(iCUAddr) * pcPic->getNumPartInCU();
365
366  Int numElements = min<Int>( partStartIdx, m_uiNumPartition );
367  for ( Int ui = 0; ui < numElements; ui++ )
368  {
369    TComDataCU * pcFrom = pcPic->getCU(getAddr());
370    m_skipFlag[ui]   = pcFrom->getSkipFlag(ui);
371    m_pePartSize[ui] = pcFrom->getPartitionSize(ui);
372    m_pePredMode[ui] = pcFrom->getPredictionMode(ui);
373    m_CUTransquantBypass[ui] = pcFrom->getCUTransquantBypass(ui);
374    m_puhDepth[ui] = pcFrom->getDepth(ui);
375
376    m_puhWidth  [ui] = pcFrom->getWidth(ui);
377    m_puhHeight [ui] = pcFrom->getHeight(ui);
378    m_puhTrIdx  [ui] = pcFrom->getTransformIdx(ui);
379    m_puhTransformSkip[0][ui] = pcFrom->getTransformSkip(ui,TEXT_LUMA);
380    m_puhTransformSkip[1][ui] = pcFrom->getTransformSkip(ui,TEXT_CHROMA_U);
381    m_puhTransformSkip[2][ui] = pcFrom->getTransformSkip(ui,TEXT_CHROMA_V);
382    m_apiMVPIdx[0][ui] = pcFrom->m_apiMVPIdx[0][ui];;
383    m_apiMVPIdx[1][ui] = pcFrom->m_apiMVPIdx[1][ui];
384    m_apiMVPNum[0][ui] = pcFrom->m_apiMVPNum[0][ui];
385    m_apiMVPNum[1][ui] = pcFrom->m_apiMVPNum[1][ui];
386    m_phQP[ui]=pcFrom->m_phQP[ui];
387    m_pbMergeFlag[ui]=pcFrom->m_pbMergeFlag[ui];
388    m_puhMergeIndex[ui]=pcFrom->m_puhMergeIndex[ui];
389    m_puhLumaIntraDir[ui]=pcFrom->m_puhLumaIntraDir[ui];
390    m_puhChromaIntraDir[ui]=pcFrom->m_puhChromaIntraDir[ui];
391    m_puhInterDir[ui]=pcFrom->m_puhInterDir[ui];
392    m_puhCbf[0][ui]=pcFrom->m_puhCbf[0][ui];
393    m_puhCbf[1][ui]=pcFrom->m_puhCbf[1][ui];
394    m_puhCbf[2][ui]=pcFrom->m_puhCbf[2][ui];
395    m_pbIPCMFlag[ui] = pcFrom->m_pbIPCMFlag[ui];
396  }
397 
398  Int firstElement = max<Int>( partStartIdx, 0 );
399  numElements = m_uiNumPartition - firstElement;
400 
401  if ( numElements > 0 )
402  {
403    memset( m_skipFlag          + firstElement, false,                    numElements * sizeof( *m_skipFlag ) );
404    memset( m_pePartSize        + firstElement, SIZE_NONE,                numElements * sizeof( *m_pePartSize ) );
405    memset( m_pePredMode        + firstElement, MODE_NONE,                numElements * sizeof( *m_pePredMode ) );
406    memset( m_CUTransquantBypass+ firstElement, false,                    numElements * sizeof( *m_CUTransquantBypass) );
407    memset( m_puhDepth          + firstElement, 0,                        numElements * sizeof( *m_puhDepth ) );
408    memset( m_puhTrIdx          + firstElement, 0,                        numElements * sizeof( *m_puhTrIdx ) );
409    memset( m_puhTransformSkip[0] + firstElement, 0,                      numElements * sizeof( *m_puhTransformSkip[0]) );
410    memset( m_puhTransformSkip[1] + firstElement, 0,                      numElements * sizeof( *m_puhTransformSkip[1]) );
411    memset( m_puhTransformSkip[2] + firstElement, 0,                      numElements * sizeof( *m_puhTransformSkip[2]) );
412    memset( m_puhWidth          + firstElement, g_uiMaxCUWidth,           numElements * sizeof( *m_puhWidth ) );
413    memset( m_puhHeight         + firstElement, g_uiMaxCUHeight,          numElements * sizeof( *m_puhHeight ) );
414    memset( m_apiMVPIdx[0]      + firstElement, -1,                       numElements * sizeof( *m_apiMVPIdx[0] ) );
415    memset( m_apiMVPIdx[1]      + firstElement, -1,                       numElements * sizeof( *m_apiMVPIdx[1] ) );
416    memset( m_apiMVPNum[0]      + firstElement, -1,                       numElements * sizeof( *m_apiMVPNum[0] ) );
417    memset( m_apiMVPNum[1]      + firstElement, -1,                       numElements * sizeof( *m_apiMVPNum[1] ) );
418    memset( m_phQP              + firstElement, getSlice()->getSliceQp(), numElements * sizeof( *m_phQP ) );
419    memset( m_pbMergeFlag       + firstElement, false,                    numElements * sizeof( *m_pbMergeFlag ) );
420    memset( m_puhMergeIndex     + firstElement, 0,                        numElements * sizeof( *m_puhMergeIndex ) );
421    memset( m_puhLumaIntraDir   + firstElement, DC_IDX,                   numElements * sizeof( *m_puhLumaIntraDir ) );
422    memset( m_puhChromaIntraDir + firstElement, 0,                        numElements * sizeof( *m_puhChromaIntraDir ) );
423    memset( m_puhInterDir       + firstElement, 0,                        numElements * sizeof( *m_puhInterDir ) );
424    memset( m_puhCbf[0]         + firstElement, 0,                        numElements * sizeof( *m_puhCbf[0] ) );
425    memset( m_puhCbf[1]         + firstElement, 0,                        numElements * sizeof( *m_puhCbf[1] ) );
426    memset( m_puhCbf[2]         + firstElement, 0,                        numElements * sizeof( *m_puhCbf[2] ) );
427    memset( m_pbIPCMFlag        + firstElement, false,                    numElements * sizeof( *m_pbIPCMFlag ) );
428
429
430  }
431 
432  UInt uiTmp = g_uiMaxCUWidth*g_uiMaxCUHeight;
433  if ( 0 >= partStartIdx ) 
434  {
435    m_acCUMvField[0].clearMvField();
436    m_acCUMvField[1].clearMvField();
437    memset( m_pcTrCoeffY , 0, sizeof( TCoeff ) * uiTmp );
438#if ADAPTIVE_QP_SELECTION
439    memset( m_pcArlCoeffY , 0, sizeof( Int ) * uiTmp ); 
440#endif
441    memset( m_pcIPCMSampleY , 0, sizeof( Pel ) * uiTmp );
442    uiTmp  >>= 2;
443    memset( m_pcTrCoeffCb, 0, sizeof( TCoeff ) * uiTmp );
444    memset( m_pcTrCoeffCr, 0, sizeof( TCoeff ) * uiTmp );
445#if ADAPTIVE_QP_SELECTION 
446    memset( m_pcArlCoeffCb, 0, sizeof( Int ) * uiTmp );
447    memset( m_pcArlCoeffCr, 0, sizeof( Int ) * uiTmp );
448#endif
449    memset( m_pcIPCMSampleCb , 0, sizeof( Pel ) * uiTmp );
450    memset( m_pcIPCMSampleCr , 0, sizeof( Pel ) * uiTmp );
451  }
452  else 
453  {
454    TComDataCU * pcFrom = pcPic->getCU(getAddr());
455    m_acCUMvField[0].copyFrom(&pcFrom->m_acCUMvField[0],m_uiNumPartition,0);
456    m_acCUMvField[1].copyFrom(&pcFrom->m_acCUMvField[1],m_uiNumPartition,0);
457    for(Int i=0; i<uiTmp; i++)
458    {
459      m_pcTrCoeffY[i]=pcFrom->m_pcTrCoeffY[i];
460#if ADAPTIVE_QP_SELECTION
461      m_pcArlCoeffY[i]=pcFrom->m_pcArlCoeffY[i];
462#endif
463      m_pcIPCMSampleY[i]=pcFrom->m_pcIPCMSampleY[i];
464    }
465    for(Int i=0; i<(uiTmp>>2); i++)
466    {
467      m_pcTrCoeffCb[i]=pcFrom->m_pcTrCoeffCb[i];
468      m_pcTrCoeffCr[i]=pcFrom->m_pcTrCoeffCr[i];
469#if ADAPTIVE_QP_SELECTION
470      m_pcArlCoeffCb[i]=pcFrom->m_pcArlCoeffCb[i];
471      m_pcArlCoeffCr[i]=pcFrom->m_pcArlCoeffCr[i];
472#endif
473      m_pcIPCMSampleCb[i]=pcFrom->m_pcIPCMSampleCb[i];
474      m_pcIPCMSampleCr[i]=pcFrom->m_pcIPCMSampleCr[i];
475    }
476  }
477
478  // Setting neighbor CU
479  m_pcCULeft        = NULL;
480  m_pcCUAbove       = NULL;
481  m_pcCUAboveLeft   = NULL;
482  m_pcCUAboveRight  = NULL;
483
484  m_apcCUColocated[0] = NULL;
485  m_apcCUColocated[1] = NULL;
486
487  UInt uiWidthInCU = pcPic->getFrameWidthInCU();
488  if ( m_uiCUAddr % uiWidthInCU )
489  {
490    m_pcCULeft = pcPic->getCU( m_uiCUAddr - 1 );
491  }
492
493  if ( m_uiCUAddr / uiWidthInCU )
494  {
495    m_pcCUAbove = pcPic->getCU( m_uiCUAddr - uiWidthInCU );
496  }
497
498  if ( m_pcCULeft && m_pcCUAbove )
499  {
500    m_pcCUAboveLeft = pcPic->getCU( m_uiCUAddr - uiWidthInCU - 1 );
501  }
502
503  if ( m_pcCUAbove && ( (m_uiCUAddr%uiWidthInCU) < (uiWidthInCU-1) )  )
504  {
505    m_pcCUAboveRight = pcPic->getCU( m_uiCUAddr - uiWidthInCU + 1 );
506  }
507
508  if ( getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) > 0 )
509  {
510    m_apcCUColocated[0] = getSlice()->getRefPic( REF_PIC_LIST_0, 0)->getCU( m_uiCUAddr );
511  }
512
513  if ( getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) > 0 )
514  {
515    m_apcCUColocated[1] = getSlice()->getRefPic( REF_PIC_LIST_1, 0)->getCU( m_uiCUAddr );
516  }
517}
518
519/** initialize prediction data with enabling sub-LCU-level delta QP
520*\param  uiDepth  depth of the current CU
521*\param  qp     qp for the current CU
522*- set CU width and CU height according to depth
523*- set qp value according to input qp
524*- set last-coded qp value according to input last-coded qp
525*/
526Void TComDataCU::initEstData( UInt uiDepth, Int qp, Bool bTransquantBypass )
527{
528  m_dTotalCost         = MAX_DOUBLE;
529  m_uiTotalDistortion  = 0;
530  m_uiTotalBits        = 0;
531  m_uiTotalBins        = 0;
532
533  UChar uhWidth  = g_uiMaxCUWidth  >> uiDepth;
534  UChar uhHeight = g_uiMaxCUHeight >> uiDepth;
535
536  for (UInt ui = 0; ui < m_uiNumPartition; ui++)
537  {
538    if(getPic()->getPicSym()->getInverseCUOrderMap(getAddr())*m_pcPic->getNumPartInCU()+m_uiAbsIdxInLCU+ui >= getSlice()->getSliceSegmentCurStartCUAddr())
539    {
540      m_apiMVPIdx[0][ui] = -1;
541      m_apiMVPIdx[1][ui] = -1;
542      m_apiMVPNum[0][ui] = -1;
543      m_apiMVPNum[1][ui] = -1;
544      m_puhDepth  [ui] = uiDepth;
545      m_puhWidth  [ui] = uhWidth;
546      m_puhHeight [ui] = uhHeight;
547      m_puhTrIdx  [ui] = 0;
548      m_puhTransformSkip[0][ui] = 0;
549      m_puhTransformSkip[1][ui] = 0;
550      m_puhTransformSkip[2][ui] = 0;
551      m_skipFlag[ui]   = false;
552      m_pePartSize[ui] = SIZE_NONE;
553      m_pePredMode[ui] = MODE_NONE;
554      m_CUTransquantBypass[ui] = bTransquantBypass;
555      m_pbIPCMFlag[ui] = 0;
556      m_phQP[ui] = qp;
557      m_pbMergeFlag[ui] = 0;
558      m_puhMergeIndex[ui] = 0;
559      m_puhLumaIntraDir[ui] = DC_IDX;
560      m_puhChromaIntraDir[ui] = 0;
561      m_puhInterDir[ui] = 0;
562      m_puhCbf[0][ui] = 0;
563      m_puhCbf[1][ui] = 0;
564      m_puhCbf[2][ui] = 0;
565
566
567    }
568  }
569
570  if(getPic()->getPicSym()->getInverseCUOrderMap(getAddr())*m_pcPic->getNumPartInCU()+m_uiAbsIdxInLCU >= getSlice()->getSliceSegmentCurStartCUAddr())
571  {
572    m_acCUMvField[0].clearMvField();
573    m_acCUMvField[1].clearMvField();
574    UInt uiTmp = uhWidth*uhHeight;
575   
576    memset( m_pcTrCoeffY,    0, uiTmp * sizeof( *m_pcTrCoeffY    ) );
577#if ADAPTIVE_QP_SELECTION
578    memset( m_pcArlCoeffY ,  0, uiTmp * sizeof( *m_pcArlCoeffY   ) );
579#endif
580    memset( m_pcIPCMSampleY, 0, uiTmp * sizeof( *m_pcIPCMSampleY ) );
581
582    uiTmp>>=2;
583    memset( m_pcTrCoeffCb,    0, uiTmp * sizeof( *m_pcTrCoeffCb    ) );
584    memset( m_pcTrCoeffCr,    0, uiTmp * sizeof( *m_pcTrCoeffCr    ) );
585#if ADAPTIVE_QP_SELECTION 
586    memset( m_pcArlCoeffCb,   0, uiTmp * sizeof( *m_pcArlCoeffCb   ) );
587    memset( m_pcArlCoeffCr,   0, uiTmp * sizeof( *m_pcArlCoeffCr   ) );
588#endif
589    memset( m_pcIPCMSampleCb, 0, uiTmp * sizeof( *m_pcIPCMSampleCb ) );
590    memset( m_pcIPCMSampleCr, 0, uiTmp * sizeof( *m_pcIPCMSampleCr ) );
591  }
592}
593
594
595// initialize Sub partition
596Void TComDataCU::initSubCU( TComDataCU* pcCU, UInt uiPartUnitIdx, UInt uiDepth, Int qp )
597{
598  assert( uiPartUnitIdx<4 );
599
600  UInt uiPartOffset = ( pcCU->getTotalNumPart()>>2 )*uiPartUnitIdx;
601
602  m_pcPic              = pcCU->getPic();
603  m_pcSlice            = m_pcPic->getSlice(m_pcPic->getCurrSliceIdx());
604  m_uiCUAddr           = pcCU->getAddr();
605  m_uiAbsIdxInLCU      = pcCU->getZorderIdxInCU() + uiPartOffset;
606
607  m_uiCUPelX           = pcCU->getCUPelX() + ( g_uiMaxCUWidth>>uiDepth  )*( uiPartUnitIdx &  1 );
608  m_uiCUPelY           = pcCU->getCUPelY() + ( g_uiMaxCUHeight>>uiDepth  )*( uiPartUnitIdx >> 1 );
609
610  m_dTotalCost         = MAX_DOUBLE;
611  m_uiTotalDistortion  = 0;
612  m_uiTotalBits        = 0;
613  m_uiTotalBins        = 0;
614  m_uiNumPartition     = pcCU->getTotalNumPart() >> 2;
615
616  Int iSizeInUchar = sizeof( UChar  ) * m_uiNumPartition;
617  Int iSizeInBool  = sizeof( Bool   ) * m_uiNumPartition;
618
619  Int sizeInChar = sizeof( Char  ) * m_uiNumPartition;
620  memset( m_phQP,              qp,  sizeInChar );
621
622  memset( m_pbMergeFlag,        0, iSizeInBool  );
623  memset( m_puhMergeIndex,      0, iSizeInUchar );
624  memset( m_puhLumaIntraDir,    DC_IDX, iSizeInUchar );
625  memset( m_puhChromaIntraDir,  0, iSizeInUchar );
626  memset( m_puhInterDir,        0, iSizeInUchar );
627  memset( m_puhTrIdx,           0, iSizeInUchar );
628  memset( m_puhTransformSkip[0], 0, iSizeInUchar );
629  memset( m_puhTransformSkip[1], 0, iSizeInUchar );
630  memset( m_puhTransformSkip[2], 0, iSizeInUchar );
631  memset( m_puhCbf[0],          0, iSizeInUchar );
632  memset( m_puhCbf[1],          0, iSizeInUchar );
633  memset( m_puhCbf[2],          0, iSizeInUchar );
634  memset( m_puhDepth,     uiDepth, iSizeInUchar );
635
636
637  UChar uhWidth  = g_uiMaxCUWidth  >> uiDepth;
638  UChar uhHeight = g_uiMaxCUHeight >> uiDepth;
639  memset( m_puhWidth,          uhWidth,  iSizeInUchar );
640  memset( m_puhHeight,         uhHeight, iSizeInUchar );
641  memset( m_pbIPCMFlag,        0, iSizeInBool  );
642
643  for (UInt ui = 0; ui < m_uiNumPartition; ui++)
644  {
645    m_skipFlag[ui]   = false;
646    m_pePartSize[ui] = SIZE_NONE;
647    m_pePredMode[ui] = MODE_NONE;
648    m_CUTransquantBypass[ui] = false;
649    m_apiMVPIdx[0][ui] = -1;
650    m_apiMVPIdx[1][ui] = -1;
651    m_apiMVPNum[0][ui] = -1;
652    m_apiMVPNum[1][ui] = -1;
653    if(m_pcPic->getPicSym()->getInverseCUOrderMap(getAddr())*m_pcPic->getNumPartInCU()+m_uiAbsIdxInLCU+ui<getSlice()->getSliceSegmentCurStartCUAddr())
654    {
655      m_apiMVPIdx[0][ui] = pcCU->m_apiMVPIdx[0][uiPartOffset+ui];
656      m_apiMVPIdx[1][ui] = pcCU->m_apiMVPIdx[1][uiPartOffset+ui];;
657      m_apiMVPNum[0][ui] = pcCU->m_apiMVPNum[0][uiPartOffset+ui];;
658      m_apiMVPNum[1][ui] = pcCU->m_apiMVPNum[1][uiPartOffset+ui];;
659      m_puhDepth  [ui] = pcCU->getDepth(uiPartOffset+ui);
660      m_puhWidth  [ui] = pcCU->getWidth(uiPartOffset+ui);
661      m_puhHeight  [ui] = pcCU->getHeight(uiPartOffset+ui);
662      m_puhTrIdx  [ui] = pcCU->getTransformIdx(uiPartOffset+ui);
663      m_puhTransformSkip[0][ui] = pcCU->getTransformSkip(uiPartOffset+ui,TEXT_LUMA);
664      m_puhTransformSkip[1][ui] = pcCU->getTransformSkip(uiPartOffset+ui,TEXT_CHROMA_U);
665      m_puhTransformSkip[2][ui] = pcCU->getTransformSkip(uiPartOffset+ui,TEXT_CHROMA_V);
666      m_skipFlag[ui]   = pcCU->getSkipFlag(uiPartOffset+ui);
667      m_pePartSize[ui] = pcCU->getPartitionSize(uiPartOffset+ui);
668      m_pePredMode[ui] = pcCU->getPredictionMode(uiPartOffset+ui);
669      m_CUTransquantBypass[ui] = pcCU->getCUTransquantBypass(uiPartOffset+ui);
670      m_pbIPCMFlag[ui]=pcCU->m_pbIPCMFlag[uiPartOffset+ui];
671      m_phQP[ui] = pcCU->m_phQP[uiPartOffset+ui];
672      m_pbMergeFlag[ui]=pcCU->m_pbMergeFlag[uiPartOffset+ui];
673      m_puhMergeIndex[ui]=pcCU->m_puhMergeIndex[uiPartOffset+ui];
674      m_puhLumaIntraDir[ui]=pcCU->m_puhLumaIntraDir[uiPartOffset+ui];
675      m_puhChromaIntraDir[ui]=pcCU->m_puhChromaIntraDir[uiPartOffset+ui];
676      m_puhInterDir[ui]=pcCU->m_puhInterDir[uiPartOffset+ui];
677      m_puhCbf[0][ui]=pcCU->m_puhCbf[0][uiPartOffset+ui];
678      m_puhCbf[1][ui]=pcCU->m_puhCbf[1][uiPartOffset+ui];
679      m_puhCbf[2][ui]=pcCU->m_puhCbf[2][uiPartOffset+ui];
680
681
682
683    }
684  }
685  UInt uiTmp = uhWidth*uhHeight;
686  memset( m_pcTrCoeffY , 0, sizeof(TCoeff)*uiTmp );
687#if ADAPTIVE_QP_SELECTION 
688  memset( m_pcArlCoeffY , 0, sizeof(Int)*uiTmp );
689#endif
690  memset( m_pcIPCMSampleY , 0, sizeof( Pel ) * uiTmp );
691  uiTmp >>= 2;
692  memset( m_pcTrCoeffCb, 0, sizeof(TCoeff)*uiTmp );
693  memset( m_pcTrCoeffCr, 0, sizeof(TCoeff)*uiTmp );
694#if ADAPTIVE_QP_SELECTION
695  memset( m_pcArlCoeffCb, 0, sizeof(Int)*uiTmp );
696  memset( m_pcArlCoeffCr, 0, sizeof(Int)*uiTmp );
697#endif
698  memset( m_pcIPCMSampleCb , 0, sizeof( Pel ) * uiTmp );
699  memset( m_pcIPCMSampleCr , 0, sizeof( Pel ) * uiTmp );
700  m_acCUMvField[0].clearMvField();
701  m_acCUMvField[1].clearMvField();
702
703  if(m_pcPic->getPicSym()->getInverseCUOrderMap(getAddr())*m_pcPic->getNumPartInCU()+m_uiAbsIdxInLCU<getSlice()->getSliceSegmentCurStartCUAddr())
704  {
705    // Part of this CU contains data from an older slice. Now copy in that data.
706    UInt uiMaxCuWidth=pcCU->getSlice()->getSPS()->getMaxCUWidth();
707    UInt uiMaxCuHeight=pcCU->getSlice()->getSPS()->getMaxCUHeight();
708    TComDataCU * bigCU = getPic()->getCU(getAddr());
709    Int minui = uiPartOffset;
710    minui = -minui;
711    pcCU->m_acCUMvField[0].copyTo(&m_acCUMvField[0],minui,uiPartOffset,m_uiNumPartition);
712    pcCU->m_acCUMvField[1].copyTo(&m_acCUMvField[1],minui,uiPartOffset,m_uiNumPartition);
713    UInt uiCoffOffset = uiMaxCuWidth*uiMaxCuHeight*m_uiAbsIdxInLCU/pcCU->getPic()->getNumPartInCU();
714    uiTmp = uhWidth*uhHeight;
715    for(Int i=0; i<uiTmp; i++)
716    {
717      m_pcTrCoeffY[i]=bigCU->m_pcTrCoeffY[uiCoffOffset+i];
718#if ADAPTIVE_QP_SELECTION
719      m_pcArlCoeffY[i]=bigCU->m_pcArlCoeffY[uiCoffOffset+i];
720#endif
721      m_pcIPCMSampleY[i]=bigCU->m_pcIPCMSampleY[uiCoffOffset+i];
722    }
723    uiTmp>>=2;
724    uiCoffOffset>>=2;
725    for(Int i=0; i<uiTmp; i++)
726    {
727      m_pcTrCoeffCr[i]=bigCU->m_pcTrCoeffCr[uiCoffOffset+i];
728      m_pcTrCoeffCb[i]=bigCU->m_pcTrCoeffCb[uiCoffOffset+i];
729#if ADAPTIVE_QP_SELECTION
730      m_pcArlCoeffCr[i]=bigCU->m_pcArlCoeffCr[uiCoffOffset+i];
731      m_pcArlCoeffCb[i]=bigCU->m_pcArlCoeffCb[uiCoffOffset+i];
732#endif
733      m_pcIPCMSampleCb[i]=bigCU->m_pcIPCMSampleCb[uiCoffOffset+i];
734      m_pcIPCMSampleCr[i]=bigCU->m_pcIPCMSampleCr[uiCoffOffset+i];
735    }
736  }
737
738  m_pcCULeft        = pcCU->getCULeft();
739  m_pcCUAbove       = pcCU->getCUAbove();
740  m_pcCUAboveLeft   = pcCU->getCUAboveLeft();
741  m_pcCUAboveRight  = pcCU->getCUAboveRight();
742
743  m_apcCUColocated[0] = pcCU->getCUColocated(REF_PIC_LIST_0);
744  m_apcCUColocated[1] = pcCU->getCUColocated(REF_PIC_LIST_1);
745  memcpy(m_sliceStartCU,pcCU->m_sliceStartCU+uiPartOffset,sizeof(UInt)*m_uiNumPartition);
746  memcpy(m_sliceSegmentStartCU,pcCU->m_sliceSegmentStartCU+uiPartOffset,sizeof(UInt)*m_uiNumPartition);
747}
748
749Void TComDataCU::setOutsideCUPart( UInt uiAbsPartIdx, UInt uiDepth )
750{
751  UInt uiNumPartition = m_uiNumPartition >> (uiDepth << 1);
752  UInt uiSizeInUchar = sizeof( UChar  ) * uiNumPartition;
753
754  UChar uhWidth  = g_uiMaxCUWidth  >> uiDepth;
755  UChar uhHeight = g_uiMaxCUHeight >> uiDepth;
756  memset( m_puhDepth    + uiAbsPartIdx,     uiDepth,  uiSizeInUchar );
757  memset( m_puhWidth    + uiAbsPartIdx,     uhWidth,  uiSizeInUchar );
758  memset( m_puhHeight   + uiAbsPartIdx,     uhHeight, uiSizeInUchar );
759}
760
761// --------------------------------------------------------------------------------------------------------------------
762// Copy
763// --------------------------------------------------------------------------------------------------------------------
764
765Void TComDataCU::copySubCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
766{
767  UInt uiPart = uiAbsPartIdx;
768 
769  m_pcPic              = pcCU->getPic();
770  m_pcSlice            = pcCU->getSlice();
771  m_uiCUAddr           = pcCU->getAddr();
772  m_uiAbsIdxInLCU      = uiAbsPartIdx;
773 
774  m_uiCUPelX           = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
775  m_uiCUPelY           = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
776 
777  m_skipFlag=pcCU->getSkipFlag()          + uiPart;
778  m_phQP=pcCU->getQP()                    + uiPart;
779  m_pePartSize = pcCU->getPartitionSize() + uiPart;
780  m_pePredMode=pcCU->getPredictionMode()  + uiPart;
781  m_CUTransquantBypass  = pcCU->getCUTransquantBypass()+uiPart;
782 
783  m_pbMergeFlag         = pcCU->getMergeFlag()        + uiPart;
784  m_puhMergeIndex       = pcCU->getMergeIndex()       + uiPart;
785
786
787
788  m_puhLumaIntraDir     = pcCU->getLumaIntraDir()     + uiPart;
789  m_puhChromaIntraDir   = pcCU->getChromaIntraDir()   + uiPart;
790  m_puhInterDir         = pcCU->getInterDir()         + uiPart;
791  m_puhTrIdx            = pcCU->getTransformIdx()     + uiPart;
792  m_puhTransformSkip[0] = pcCU->getTransformSkip(TEXT_LUMA)     + uiPart;
793  m_puhTransformSkip[1] = pcCU->getTransformSkip(TEXT_CHROMA_U) + uiPart;
794  m_puhTransformSkip[2] = pcCU->getTransformSkip(TEXT_CHROMA_V) + uiPart;
795
796  m_puhCbf[0]= pcCU->getCbf(TEXT_LUMA)            + uiPart;
797  m_puhCbf[1]= pcCU->getCbf(TEXT_CHROMA_U)        + uiPart;
798  m_puhCbf[2]= pcCU->getCbf(TEXT_CHROMA_V)        + uiPart;
799  m_puhDepth=pcCU->getDepth()                     + uiPart;
800  m_puhWidth=pcCU->getWidth()                     + uiPart;
801  m_puhHeight=pcCU->getHeight()                   + uiPart;
802 
803  m_apiMVPIdx[0]=pcCU->getMVPIdx(REF_PIC_LIST_0)  + uiPart;
804  m_apiMVPIdx[1]=pcCU->getMVPIdx(REF_PIC_LIST_1)  + uiPart;
805  m_apiMVPNum[0]=pcCU->getMVPNum(REF_PIC_LIST_0)  + uiPart;
806  m_apiMVPNum[1]=pcCU->getMVPNum(REF_PIC_LIST_1)  + uiPart;
807 
808  m_pbIPCMFlag         = pcCU->getIPCMFlag()        + uiPart;
809
810  m_pcCUAboveLeft      = pcCU->getCUAboveLeft();
811  m_pcCUAboveRight     = pcCU->getCUAboveRight();
812  m_pcCUAbove          = pcCU->getCUAbove();
813  m_pcCULeft           = pcCU->getCULeft();
814 
815  m_apcCUColocated[0] = pcCU->getCUColocated(REF_PIC_LIST_0);
816  m_apcCUColocated[1] = pcCU->getCUColocated(REF_PIC_LIST_1);
817 
818  UInt uiMaxCuWidth=pcCU->getSlice()->getSPS()->getMaxCUWidth();
819  UInt uiMaxCuHeight=pcCU->getSlice()->getSPS()->getMaxCUHeight();
820 
821  UInt uiCoffOffset = uiMaxCuWidth*uiMaxCuHeight*uiAbsPartIdx/pcCU->getPic()->getNumPartInCU();
822 
823  m_pcTrCoeffY = pcCU->getCoeffY() + uiCoffOffset;
824#if ADAPTIVE_QP_SELECTION
825  m_pcArlCoeffY= pcCU->getArlCoeffY() + uiCoffOffset; 
826#endif
827  m_pcIPCMSampleY = pcCU->getPCMSampleY() + uiCoffOffset;
828
829  uiCoffOffset >>=2;
830  m_pcTrCoeffCb=pcCU->getCoeffCb() + uiCoffOffset;
831  m_pcTrCoeffCr=pcCU->getCoeffCr() + uiCoffOffset;
832#if ADAPTIVE_QP_SELECTION 
833  m_pcArlCoeffCb=pcCU->getArlCoeffCb() + uiCoffOffset;
834  m_pcArlCoeffCr=pcCU->getArlCoeffCr() + uiCoffOffset;
835#endif
836  m_pcIPCMSampleCb = pcCU->getPCMSampleCb() + uiCoffOffset;
837  m_pcIPCMSampleCr = pcCU->getPCMSampleCr() + uiCoffOffset;
838
839  m_acCUMvField[0].linkToWithOffset( pcCU->getCUMvField(REF_PIC_LIST_0), uiPart );
840  m_acCUMvField[1].linkToWithOffset( pcCU->getCUMvField(REF_PIC_LIST_1), uiPart );
841  memcpy(m_sliceStartCU,pcCU->m_sliceStartCU+uiPart,sizeof(UInt)*m_uiNumPartition);
842  memcpy(m_sliceSegmentStartCU,pcCU->m_sliceSegmentStartCU+uiPart,sizeof(UInt)*m_uiNumPartition);
843}
844// Copy inter prediction info from the biggest CU
845Void TComDataCU::copyInterPredInfoFrom    ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefPicList
846  )
847{
848  m_pcPic              = pcCU->getPic();
849  m_pcSlice            = pcCU->getSlice();
850  m_uiCUAddr           = pcCU->getAddr();
851  m_uiAbsIdxInLCU      = uiAbsPartIdx;
852 
853  Int iRastPartIdx     = g_auiZscanToRaster[uiAbsPartIdx];
854  m_uiCUPelX           = pcCU->getCUPelX() + m_pcPic->getMinCUWidth ()*( iRastPartIdx % m_pcPic->getNumPartInWidth() );
855  m_uiCUPelY           = pcCU->getCUPelY() + m_pcPic->getMinCUHeight()*( iRastPartIdx / m_pcPic->getNumPartInWidth() );
856 
857  m_pcCUAboveLeft      = pcCU->getCUAboveLeft();
858  m_pcCUAboveRight     = pcCU->getCUAboveRight();
859  m_pcCUAbove          = pcCU->getCUAbove();
860  m_pcCULeft           = pcCU->getCULeft();
861 
862  m_apcCUColocated[0]  = pcCU->getCUColocated(REF_PIC_LIST_0);
863  m_apcCUColocated[1]  = pcCU->getCUColocated(REF_PIC_LIST_1);
864 
865  m_skipFlag           = pcCU->getSkipFlag ()             + uiAbsPartIdx;
866  m_pePartSize         = pcCU->getPartitionSize ()        + uiAbsPartIdx;
867  m_pePredMode         = pcCU->getPredictionMode()        + uiAbsPartIdx;
868  m_CUTransquantBypass = pcCU->getCUTransquantBypass()    + uiAbsPartIdx;
869  m_puhInterDir        = pcCU->getInterDir      ()        + uiAbsPartIdx;
870 
871  m_puhDepth           = pcCU->getDepth ()                + uiAbsPartIdx;
872  m_puhWidth           = pcCU->getWidth ()                + uiAbsPartIdx;
873  m_puhHeight          = pcCU->getHeight()                + uiAbsPartIdx;
874 
875  m_pbMergeFlag        = pcCU->getMergeFlag()             + uiAbsPartIdx;
876  m_puhMergeIndex      = pcCU->getMergeIndex()            + uiAbsPartIdx;
877
878  m_apiMVPIdx[eRefPicList] = pcCU->getMVPIdx(eRefPicList) + uiAbsPartIdx;
879  m_apiMVPNum[eRefPicList] = pcCU->getMVPNum(eRefPicList) + uiAbsPartIdx;
880 
881
882   
883
884  m_acCUMvField[ eRefPicList ].linkToWithOffset( pcCU->getCUMvField(eRefPicList), uiAbsPartIdx );
885
886  memcpy(m_sliceStartCU,pcCU->m_sliceStartCU+uiAbsPartIdx,sizeof(UInt)*m_uiNumPartition);
887  memcpy(m_sliceSegmentStartCU,pcCU->m_sliceSegmentStartCU+uiAbsPartIdx,sizeof(UInt)*m_uiNumPartition);
888}
889
890// Copy small CU to bigger CU.
891// One of quarter parts overwritten by predicted sub part.
892Void TComDataCU::copyPartFrom( TComDataCU* pcCU, UInt uiPartUnitIdx, UInt uiDepth )
893{
894  assert( uiPartUnitIdx<4 );
895 
896  m_dTotalCost         += pcCU->getTotalCost();
897  m_uiTotalDistortion  += pcCU->getTotalDistortion();
898  m_uiTotalBits        += pcCU->getTotalBits();
899 
900  UInt uiOffset         = pcCU->getTotalNumPart()*uiPartUnitIdx;
901 
902  UInt uiNumPartition = pcCU->getTotalNumPart();
903  Int iSizeInUchar  = sizeof( UChar ) * uiNumPartition;
904  Int iSizeInBool   = sizeof( Bool  ) * uiNumPartition;
905 
906  Int sizeInChar  = sizeof( Char ) * uiNumPartition;
907  memcpy( m_skipFlag   + uiOffset, pcCU->getSkipFlag(),       sizeof( *m_skipFlag )   * uiNumPartition );
908  memcpy( m_phQP       + uiOffset, pcCU->getQP(),             sizeInChar                        );
909  memcpy( m_pePartSize + uiOffset, pcCU->getPartitionSize(),  sizeof( *m_pePartSize ) * uiNumPartition );
910  memcpy( m_pePredMode + uiOffset, pcCU->getPredictionMode(), sizeof( *m_pePredMode ) * uiNumPartition );
911  memcpy( m_CUTransquantBypass + uiOffset, pcCU->getCUTransquantBypass(), sizeof( *m_CUTransquantBypass ) * uiNumPartition );
912  memcpy( m_pbMergeFlag         + uiOffset, pcCU->getMergeFlag(),         iSizeInBool  );
913  memcpy( m_puhMergeIndex       + uiOffset, pcCU->getMergeIndex(),        iSizeInUchar );
914  memcpy( m_puhLumaIntraDir     + uiOffset, pcCU->getLumaIntraDir(),      iSizeInUchar );
915  memcpy( m_puhChromaIntraDir   + uiOffset, pcCU->getChromaIntraDir(),    iSizeInUchar );
916  memcpy( m_puhInterDir         + uiOffset, pcCU->getInterDir(),          iSizeInUchar );
917  memcpy( m_puhTrIdx            + uiOffset, pcCU->getTransformIdx(),      iSizeInUchar );
918  memcpy( m_puhTransformSkip[0] + uiOffset, pcCU->getTransformSkip(TEXT_LUMA),     iSizeInUchar );
919  memcpy( m_puhTransformSkip[1] + uiOffset, pcCU->getTransformSkip(TEXT_CHROMA_U), iSizeInUchar );
920  memcpy( m_puhTransformSkip[2] + uiOffset, pcCU->getTransformSkip(TEXT_CHROMA_V), iSizeInUchar );
921
922  memcpy( m_puhCbf[0] + uiOffset, pcCU->getCbf(TEXT_LUMA)    , iSizeInUchar );
923  memcpy( m_puhCbf[1] + uiOffset, pcCU->getCbf(TEXT_CHROMA_U), iSizeInUchar );
924  memcpy( m_puhCbf[2] + uiOffset, pcCU->getCbf(TEXT_CHROMA_V), iSizeInUchar );
925
926
927
928
929  memcpy( m_puhDepth  + uiOffset, pcCU->getDepth(),  iSizeInUchar );
930  memcpy( m_puhWidth  + uiOffset, pcCU->getWidth(),  iSizeInUchar );
931  memcpy( m_puhHeight + uiOffset, pcCU->getHeight(), iSizeInUchar );
932 
933  memcpy( m_apiMVPIdx[0] + uiOffset, pcCU->getMVPIdx(REF_PIC_LIST_0), iSizeInUchar );
934  memcpy( m_apiMVPIdx[1] + uiOffset, pcCU->getMVPIdx(REF_PIC_LIST_1), iSizeInUchar );
935  memcpy( m_apiMVPNum[0] + uiOffset, pcCU->getMVPNum(REF_PIC_LIST_0), iSizeInUchar );
936  memcpy( m_apiMVPNum[1] + uiOffset, pcCU->getMVPNum(REF_PIC_LIST_1), iSizeInUchar );
937 
938  memcpy( m_pbIPCMFlag + uiOffset, pcCU->getIPCMFlag(), iSizeInBool );
939
940  m_pcCUAboveLeft      = pcCU->getCUAboveLeft();
941  m_pcCUAboveRight     = pcCU->getCUAboveRight();
942  m_pcCUAbove          = pcCU->getCUAbove();
943  m_pcCULeft           = pcCU->getCULeft();
944 
945  m_apcCUColocated[0] = pcCU->getCUColocated(REF_PIC_LIST_0);
946  m_apcCUColocated[1] = pcCU->getCUColocated(REF_PIC_LIST_1);
947 
948  m_acCUMvField[0].copyFrom( pcCU->getCUMvField( REF_PIC_LIST_0 ), pcCU->getTotalNumPart(), uiOffset );
949  m_acCUMvField[1].copyFrom( pcCU->getCUMvField( REF_PIC_LIST_1 ), pcCU->getTotalNumPart(), uiOffset );
950 
951  UInt uiTmp  = g_uiMaxCUWidth*g_uiMaxCUHeight >> (uiDepth<<1);
952  UInt uiTmp2 = uiPartUnitIdx*uiTmp;
953  memcpy( m_pcTrCoeffY  + uiTmp2, pcCU->getCoeffY(),  sizeof(TCoeff)*uiTmp );
954#if ADAPTIVE_QP_SELECTION
955  memcpy( m_pcArlCoeffY  + uiTmp2, pcCU->getArlCoeffY(),  sizeof(Int)*uiTmp );
956#endif
957  memcpy( m_pcIPCMSampleY + uiTmp2 , pcCU->getPCMSampleY(), sizeof(Pel) * uiTmp );
958
959  uiTmp >>= 2; uiTmp2>>= 2;
960  memcpy( m_pcTrCoeffCb + uiTmp2, pcCU->getCoeffCb(), sizeof(TCoeff)*uiTmp );
961  memcpy( m_pcTrCoeffCr + uiTmp2, pcCU->getCoeffCr(), sizeof(TCoeff)*uiTmp );
962#if ADAPTIVE_QP_SELECTION
963  memcpy( m_pcArlCoeffCb + uiTmp2, pcCU->getArlCoeffCb(), sizeof(Int)*uiTmp );
964  memcpy( m_pcArlCoeffCr + uiTmp2, pcCU->getArlCoeffCr(), sizeof(Int)*uiTmp );
965#endif
966  memcpy( m_pcIPCMSampleCb + uiTmp2 , pcCU->getPCMSampleCb(), sizeof(Pel) * uiTmp );
967  memcpy( m_pcIPCMSampleCr + uiTmp2 , pcCU->getPCMSampleCr(), sizeof(Pel) * uiTmp );
968  m_uiTotalBins += pcCU->getTotalBins();
969  memcpy( m_sliceStartCU        + uiOffset, pcCU->m_sliceStartCU,        sizeof( UInt ) * uiNumPartition  );
970  memcpy( m_sliceSegmentStartCU + uiOffset, pcCU->m_sliceSegmentStartCU, sizeof( UInt ) * uiNumPartition  );
971}
972
973// Copy current predicted part to a CU in picture.
974// It is used to predict for next part
975Void TComDataCU::copyToPic( UChar uhDepth )
976{
977  TComDataCU*& rpcCU = m_pcPic->getCU( m_uiCUAddr );
978 
979  rpcCU->getTotalCost()       = m_dTotalCost;
980  rpcCU->getTotalDistortion() = m_uiTotalDistortion;
981  rpcCU->getTotalBits()       = m_uiTotalBits;
982 
983  Int iSizeInUchar  = sizeof( UChar ) * m_uiNumPartition;
984  Int iSizeInBool   = sizeof( Bool  ) * m_uiNumPartition;
985 
986  Int sizeInChar  = sizeof( Char ) * m_uiNumPartition;
987
988  memcpy( rpcCU->getSkipFlag() + m_uiAbsIdxInLCU, m_skipFlag, sizeof( *m_skipFlag ) * m_uiNumPartition );
989  memcpy( rpcCU->getQP() + m_uiAbsIdxInLCU, m_phQP, sizeInChar  );
990
991
992  memcpy( rpcCU->getPartitionSize()  + m_uiAbsIdxInLCU, m_pePartSize, sizeof( *m_pePartSize ) * m_uiNumPartition );
993  memcpy( rpcCU->getPredictionMode() + m_uiAbsIdxInLCU, m_pePredMode, sizeof( *m_pePredMode ) * m_uiNumPartition );
994  memcpy( rpcCU->getCUTransquantBypass()+ m_uiAbsIdxInLCU, m_CUTransquantBypass, sizeof( *m_CUTransquantBypass ) * m_uiNumPartition );
995  memcpy( rpcCU->getMergeFlag()         + m_uiAbsIdxInLCU, m_pbMergeFlag,         iSizeInBool  );
996  memcpy( rpcCU->getMergeIndex()        + m_uiAbsIdxInLCU, m_puhMergeIndex,       iSizeInUchar );
997  memcpy( rpcCU->getLumaIntraDir()      + m_uiAbsIdxInLCU, m_puhLumaIntraDir,     iSizeInUchar );
998  memcpy( rpcCU->getChromaIntraDir()    + m_uiAbsIdxInLCU, m_puhChromaIntraDir,   iSizeInUchar );
999  memcpy( rpcCU->getInterDir()          + m_uiAbsIdxInLCU, m_puhInterDir,         iSizeInUchar );
1000  memcpy( rpcCU->getTransformIdx()      + m_uiAbsIdxInLCU, m_puhTrIdx,            iSizeInUchar );
1001  memcpy( rpcCU->getTransformSkip(TEXT_LUMA)     + m_uiAbsIdxInLCU, m_puhTransformSkip[0], iSizeInUchar );
1002  memcpy( rpcCU->getTransformSkip(TEXT_CHROMA_U) + m_uiAbsIdxInLCU, m_puhTransformSkip[1], iSizeInUchar );
1003  memcpy( rpcCU->getTransformSkip(TEXT_CHROMA_V) + m_uiAbsIdxInLCU, m_puhTransformSkip[2], iSizeInUchar );
1004
1005  memcpy( rpcCU->getCbf(TEXT_LUMA)     + m_uiAbsIdxInLCU, m_puhCbf[0], iSizeInUchar );
1006  memcpy( rpcCU->getCbf(TEXT_CHROMA_U) + m_uiAbsIdxInLCU, m_puhCbf[1], iSizeInUchar );
1007  memcpy( rpcCU->getCbf(TEXT_CHROMA_V) + m_uiAbsIdxInLCU, m_puhCbf[2], iSizeInUchar );
1008 
1009 
1010  memcpy( rpcCU->getDepth()  + m_uiAbsIdxInLCU, m_puhDepth,  iSizeInUchar );
1011  memcpy( rpcCU->getWidth()  + m_uiAbsIdxInLCU, m_puhWidth,  iSizeInUchar );
1012  memcpy( rpcCU->getHeight() + m_uiAbsIdxInLCU, m_puhHeight, iSizeInUchar );
1013 
1014  memcpy( rpcCU->getMVPIdx(REF_PIC_LIST_0) + m_uiAbsIdxInLCU, m_apiMVPIdx[0], iSizeInUchar );
1015  memcpy( rpcCU->getMVPIdx(REF_PIC_LIST_1) + m_uiAbsIdxInLCU, m_apiMVPIdx[1], iSizeInUchar );
1016  memcpy( rpcCU->getMVPNum(REF_PIC_LIST_0) + m_uiAbsIdxInLCU, m_apiMVPNum[0], iSizeInUchar );
1017  memcpy( rpcCU->getMVPNum(REF_PIC_LIST_1) + m_uiAbsIdxInLCU, m_apiMVPNum[1], iSizeInUchar );
1018 
1019  m_acCUMvField[0].copyTo( rpcCU->getCUMvField( REF_PIC_LIST_0 ), m_uiAbsIdxInLCU );
1020  m_acCUMvField[1].copyTo( rpcCU->getCUMvField( REF_PIC_LIST_1 ), m_uiAbsIdxInLCU );
1021 
1022  memcpy( rpcCU->getIPCMFlag() + m_uiAbsIdxInLCU, m_pbIPCMFlag,         iSizeInBool  );
1023
1024  UInt uiTmp  = (g_uiMaxCUWidth*g_uiMaxCUHeight)>>(uhDepth<<1);
1025  UInt uiTmp2 = m_uiAbsIdxInLCU*m_pcPic->getMinCUWidth()*m_pcPic->getMinCUHeight();
1026  memcpy( rpcCU->getCoeffY()  + uiTmp2, m_pcTrCoeffY,  sizeof(TCoeff)*uiTmp  );
1027#if ADAPTIVE_QP_SELECTION 
1028  memcpy( rpcCU->getArlCoeffY()  + uiTmp2, m_pcArlCoeffY,  sizeof(Int)*uiTmp  );
1029#endif
1030  memcpy( rpcCU->getPCMSampleY() + uiTmp2 , m_pcIPCMSampleY, sizeof(Pel)*uiTmp );
1031
1032  uiTmp >>= 2; uiTmp2 >>= 2;
1033  memcpy( rpcCU->getCoeffCb() + uiTmp2, m_pcTrCoeffCb, sizeof(TCoeff)*uiTmp  );
1034  memcpy( rpcCU->getCoeffCr() + uiTmp2, m_pcTrCoeffCr, sizeof(TCoeff)*uiTmp  );
1035#if ADAPTIVE_QP_SELECTION
1036  memcpy( rpcCU->getArlCoeffCb() + uiTmp2, m_pcArlCoeffCb, sizeof(Int)*uiTmp  );
1037  memcpy( rpcCU->getArlCoeffCr() + uiTmp2, m_pcArlCoeffCr, sizeof(Int)*uiTmp  );
1038#endif
1039  memcpy( rpcCU->getPCMSampleCb() + uiTmp2 , m_pcIPCMSampleCb, sizeof( Pel ) * uiTmp );
1040  memcpy( rpcCU->getPCMSampleCr() + uiTmp2 , m_pcIPCMSampleCr, sizeof( Pel ) * uiTmp );
1041  rpcCU->getTotalBins() = m_uiTotalBins;
1042  memcpy( rpcCU->m_sliceStartCU        + m_uiAbsIdxInLCU, m_sliceStartCU,        sizeof( UInt ) * m_uiNumPartition  );
1043  memcpy( rpcCU->m_sliceSegmentStartCU + m_uiAbsIdxInLCU, m_sliceSegmentStartCU, sizeof( UInt ) * m_uiNumPartition  );
1044}
1045
1046Void TComDataCU::copyToPic( UChar uhDepth, UInt uiPartIdx, UInt uiPartDepth )
1047{
1048  TComDataCU*&  rpcCU       = m_pcPic->getCU( m_uiCUAddr );
1049  UInt          uiQNumPart  = m_uiNumPartition>>(uiPartDepth<<1);
1050 
1051  UInt uiPartStart          = uiPartIdx*uiQNumPart;
1052  UInt uiPartOffset         = m_uiAbsIdxInLCU + uiPartStart;
1053 
1054  rpcCU->getTotalCost()       = m_dTotalCost;
1055  rpcCU->getTotalDistortion() = m_uiTotalDistortion;
1056  rpcCU->getTotalBits()       = m_uiTotalBits;
1057 
1058  Int iSizeInUchar  = sizeof( UChar  ) * uiQNumPart;
1059  Int iSizeInBool   = sizeof( Bool   ) * uiQNumPart;
1060 
1061  Int sizeInChar  = sizeof( Char ) * uiQNumPart;
1062  memcpy( rpcCU->getSkipFlag()       + uiPartOffset, m_skipFlag,   sizeof( *m_skipFlag )   * uiQNumPart );
1063  memcpy( rpcCU->getQP() + uiPartOffset, m_phQP, sizeInChar );
1064  memcpy( rpcCU->getPartitionSize()  + uiPartOffset, m_pePartSize, sizeof( *m_pePartSize ) * uiQNumPart );
1065  memcpy( rpcCU->getPredictionMode() + uiPartOffset, m_pePredMode, sizeof( *m_pePredMode ) * uiQNumPart );
1066  memcpy( rpcCU->getCUTransquantBypass()+ uiPartOffset, m_CUTransquantBypass, sizeof( *m_CUTransquantBypass ) * uiQNumPart );
1067  memcpy( rpcCU->getMergeFlag()         + uiPartOffset, m_pbMergeFlag,         iSizeInBool  );
1068  memcpy( rpcCU->getMergeIndex()        + uiPartOffset, m_puhMergeIndex,       iSizeInUchar );
1069  memcpy( rpcCU->getLumaIntraDir()      + uiPartOffset, m_puhLumaIntraDir,     iSizeInUchar );
1070  memcpy( rpcCU->getChromaIntraDir()    + uiPartOffset, m_puhChromaIntraDir,   iSizeInUchar );
1071  memcpy( rpcCU->getInterDir()          + uiPartOffset, m_puhInterDir,         iSizeInUchar );
1072  memcpy( rpcCU->getTransformIdx()      + uiPartOffset, m_puhTrIdx,            iSizeInUchar );
1073  memcpy( rpcCU->getTransformSkip(TEXT_LUMA)     + uiPartOffset, m_puhTransformSkip[0], iSizeInUchar );
1074  memcpy( rpcCU->getTransformSkip(TEXT_CHROMA_U) + uiPartOffset, m_puhTransformSkip[1], iSizeInUchar );
1075  memcpy( rpcCU->getTransformSkip(TEXT_CHROMA_V) + uiPartOffset, m_puhTransformSkip[2], iSizeInUchar );
1076  memcpy( rpcCU->getCbf(TEXT_LUMA)     + uiPartOffset, m_puhCbf[0], iSizeInUchar );
1077  memcpy( rpcCU->getCbf(TEXT_CHROMA_U) + uiPartOffset, m_puhCbf[1], iSizeInUchar );
1078  memcpy( rpcCU->getCbf(TEXT_CHROMA_V) + uiPartOffset, m_puhCbf[2], iSizeInUchar );
1079
1080
1081 
1082  memcpy( rpcCU->getDepth()  + uiPartOffset, m_puhDepth,  iSizeInUchar );
1083  memcpy( rpcCU->getWidth()  + uiPartOffset, m_puhWidth,  iSizeInUchar );
1084  memcpy( rpcCU->getHeight() + uiPartOffset, m_puhHeight, iSizeInUchar );
1085 
1086  memcpy( rpcCU->getMVPIdx(REF_PIC_LIST_0) + uiPartOffset, m_apiMVPIdx[0], iSizeInUchar );
1087  memcpy( rpcCU->getMVPIdx(REF_PIC_LIST_1) + uiPartOffset, m_apiMVPIdx[1], iSizeInUchar );
1088  memcpy( rpcCU->getMVPNum(REF_PIC_LIST_0) + uiPartOffset, m_apiMVPNum[0], iSizeInUchar );
1089  memcpy( rpcCU->getMVPNum(REF_PIC_LIST_1) + uiPartOffset, m_apiMVPNum[1], iSizeInUchar );
1090  m_acCUMvField[0].copyTo( rpcCU->getCUMvField( REF_PIC_LIST_0 ), m_uiAbsIdxInLCU, uiPartStart, uiQNumPart );
1091  m_acCUMvField[1].copyTo( rpcCU->getCUMvField( REF_PIC_LIST_1 ), m_uiAbsIdxInLCU, uiPartStart, uiQNumPart );
1092 
1093  memcpy( rpcCU->getIPCMFlag() + uiPartOffset, m_pbIPCMFlag,         iSizeInBool  );
1094
1095  UInt uiTmp  = (g_uiMaxCUWidth*g_uiMaxCUHeight)>>((uhDepth+uiPartDepth)<<1);
1096  UInt uiTmp2 = uiPartOffset*m_pcPic->getMinCUWidth()*m_pcPic->getMinCUHeight();
1097  memcpy( rpcCU->getCoeffY()  + uiTmp2, m_pcTrCoeffY,  sizeof(TCoeff)*uiTmp  );
1098#if ADAPTIVE_QP_SELECTION
1099  memcpy( rpcCU->getArlCoeffY()  + uiTmp2, m_pcArlCoeffY,  sizeof(Int)*uiTmp  );
1100#endif
1101 
1102  memcpy( rpcCU->getPCMSampleY() + uiTmp2 , m_pcIPCMSampleY, sizeof( Pel ) * uiTmp );
1103
1104  uiTmp >>= 2; uiTmp2 >>= 2;
1105  memcpy( rpcCU->getCoeffCb() + uiTmp2, m_pcTrCoeffCb, sizeof(TCoeff)*uiTmp  );
1106  memcpy( rpcCU->getCoeffCr() + uiTmp2, m_pcTrCoeffCr, sizeof(TCoeff)*uiTmp  );
1107#if ADAPTIVE_QP_SELECTION
1108  memcpy( rpcCU->getArlCoeffCb() + uiTmp2, m_pcArlCoeffCb, sizeof(Int)*uiTmp  );
1109  memcpy( rpcCU->getArlCoeffCr() + uiTmp2, m_pcArlCoeffCr, sizeof(Int)*uiTmp  );
1110#endif
1111
1112  memcpy( rpcCU->getPCMSampleCb() + uiTmp2 , m_pcIPCMSampleCb, sizeof( Pel ) * uiTmp );
1113  memcpy( rpcCU->getPCMSampleCr() + uiTmp2 , m_pcIPCMSampleCr, sizeof( Pel ) * uiTmp );
1114  rpcCU->getTotalBins() = m_uiTotalBins;
1115  memcpy( rpcCU->m_sliceStartCU        + uiPartOffset, m_sliceStartCU,        sizeof( UInt ) * uiQNumPart  );
1116  memcpy( rpcCU->m_sliceSegmentStartCU + uiPartOffset, m_sliceSegmentStartCU, sizeof( UInt ) * uiQNumPart  );
1117}
1118
1119
1120// --------------------------------------------------------------------------------------------------------------------
1121// Other public functions
1122// --------------------------------------------------------------------------------------------------------------------
1123
1124TComDataCU* TComDataCU::getPULeft( UInt& uiLPartUnitIdx, 
1125                                   UInt uiCurrPartUnitIdx, 
1126                                   Bool bEnforceSliceRestriction, 
1127                                   Bool bEnforceTileRestriction )
1128{
1129  UInt uiAbsPartIdx       = g_auiZscanToRaster[uiCurrPartUnitIdx];
1130  UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[m_uiAbsIdxInLCU];
1131  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1132 
1133  if ( !RasterAddress::isZeroCol( uiAbsPartIdx, uiNumPartInCUWidth ) )
1134  {
1135    uiLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - 1 ];
1136    if ( RasterAddress::isEqualCol( uiAbsPartIdx, uiAbsZorderCUIdx, uiNumPartInCUWidth ) )
1137    {
1138      return m_pcPic->getCU( getAddr() );
1139    }
1140    else
1141    {
1142      uiLPartUnitIdx -= m_uiAbsIdxInLCU;
1143      return this;
1144    }
1145  }
1146 
1147  uiLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx + uiNumPartInCUWidth - 1 ];
1148
1149
1150  if ( (bEnforceSliceRestriction && (m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL || m_pcCULeft->getSCUAddr()+uiLPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)))
1151      ||
1152       (bEnforceTileRestriction && ( m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL || (m_pcPic->getPicSym()->getTileIdxMap( m_pcCULeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))  )  )
1153      )
1154  {
1155    return NULL;
1156  }
1157  return m_pcCULeft;
1158}
1159
1160TComDataCU* TComDataCU::getPUAbove( UInt& uiAPartUnitIdx,
1161                                    UInt uiCurrPartUnitIdx, 
1162                                    Bool bEnforceSliceRestriction, 
1163                                    Bool planarAtLCUBoundary ,
1164                                    Bool bEnforceTileRestriction )
1165{
1166  UInt uiAbsPartIdx       = g_auiZscanToRaster[uiCurrPartUnitIdx];
1167  UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[m_uiAbsIdxInLCU];
1168  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1169 
1170  if ( !RasterAddress::isZeroRow( uiAbsPartIdx, uiNumPartInCUWidth ) )
1171  {
1172    uiAPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - uiNumPartInCUWidth ];
1173    if ( RasterAddress::isEqualRow( uiAbsPartIdx, uiAbsZorderCUIdx, uiNumPartInCUWidth ) )
1174    {
1175      return m_pcPic->getCU( getAddr() );
1176    }
1177    else
1178    {
1179      uiAPartUnitIdx -= m_uiAbsIdxInLCU;
1180      return this;
1181    }
1182  }
1183
1184  if(planarAtLCUBoundary)
1185  {
1186    return NULL;
1187  }
1188 
1189  uiAPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx + m_pcPic->getNumPartInCU() - uiNumPartInCUWidth ];
1190
1191  if ( (bEnforceSliceRestriction && (m_pcCUAbove==NULL || m_pcCUAbove->getSlice()==NULL || m_pcCUAbove->getSCUAddr()+uiAPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)))
1192      ||
1193       (bEnforceTileRestriction &&(m_pcCUAbove==NULL || m_pcCUAbove->getSlice()==NULL || (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAbove->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))))
1194      )
1195  {
1196    return NULL;
1197  }
1198  return m_pcCUAbove;
1199}
1200
1201TComDataCU* TComDataCU::getPUAboveLeft( UInt& uiALPartUnitIdx, UInt uiCurrPartUnitIdx, Bool bEnforceSliceRestriction )
1202{
1203  UInt uiAbsPartIdx       = g_auiZscanToRaster[uiCurrPartUnitIdx];
1204  UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[m_uiAbsIdxInLCU];
1205  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1206 
1207  if ( !RasterAddress::isZeroCol( uiAbsPartIdx, uiNumPartInCUWidth ) )
1208  {
1209    if ( !RasterAddress::isZeroRow( uiAbsPartIdx, uiNumPartInCUWidth ) )
1210    {
1211      uiALPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - uiNumPartInCUWidth - 1 ];
1212      if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdx, uiAbsZorderCUIdx, uiNumPartInCUWidth ) )
1213      {
1214        return m_pcPic->getCU( getAddr() );
1215      }
1216      else
1217      {
1218        uiALPartUnitIdx -= m_uiAbsIdxInLCU;
1219        return this;
1220      }
1221    }
1222    uiALPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx + getPic()->getNumPartInCU() - uiNumPartInCUWidth - 1 ];
1223    if ( (bEnforceSliceRestriction && (m_pcCUAbove==NULL || m_pcCUAbove->getSlice()==NULL ||
1224       m_pcCUAbove->getSCUAddr()+uiALPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1225       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAbove->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1226       ))
1227     )
1228    {
1229      return NULL;
1230    }
1231    return m_pcCUAbove;
1232  }
1233 
1234  if ( !RasterAddress::isZeroRow( uiAbsPartIdx, uiNumPartInCUWidth ) )
1235  {
1236    uiALPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - 1 ];
1237    if ( (bEnforceSliceRestriction && (m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL || 
1238       m_pcCULeft->getSCUAddr()+uiALPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1239       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCULeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1240       ))
1241     )
1242    {
1243      return NULL;
1244    }
1245    return m_pcCULeft;
1246  }
1247 
1248  uiALPartUnitIdx = g_auiRasterToZscan[ m_pcPic->getNumPartInCU() - 1 ];
1249  if ( (bEnforceSliceRestriction && (m_pcCUAboveLeft==NULL || m_pcCUAboveLeft->getSlice()==NULL ||
1250       m_pcCUAboveLeft->getSCUAddr()+uiALPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1251       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAboveLeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1252       ))
1253     )
1254  {
1255    return NULL;
1256  }
1257  return m_pcCUAboveLeft;
1258}
1259
1260TComDataCU* TComDataCU::getPUAboveRight( UInt& uiARPartUnitIdx, UInt uiCurrPartUnitIdx, Bool bEnforceSliceRestriction )
1261{
1262  UInt uiAbsPartIdxRT     = g_auiZscanToRaster[uiCurrPartUnitIdx];
1263  UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + m_puhWidth[0] / m_pcPic->getMinCUWidth() - 1;
1264  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1265 
1266  if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxRT] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )
1267  {
1268    uiARPartUnitIdx = MAX_UINT;
1269    return NULL;
1270  }
1271 
1272  if ( RasterAddress::lessThanCol( uiAbsPartIdxRT, uiNumPartInCUWidth - 1, uiNumPartInCUWidth ) )
1273  {
1274    if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, uiNumPartInCUWidth ) )
1275    {
1276      if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxRT - uiNumPartInCUWidth + 1 ] )
1277      {
1278        uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT - uiNumPartInCUWidth + 1 ];
1279        if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxRT, uiAbsZorderCUIdx, uiNumPartInCUWidth ) )
1280        {
1281          return m_pcPic->getCU( getAddr() );
1282        }
1283        else
1284        {
1285          uiARPartUnitIdx -= m_uiAbsIdxInLCU;
1286          return this;
1287        }
1288      }
1289      uiARPartUnitIdx = MAX_UINT;
1290      return NULL;
1291    }
1292    uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT + m_pcPic->getNumPartInCU() - uiNumPartInCUWidth + 1 ];
1293    if ( (bEnforceSliceRestriction && (m_pcCUAbove==NULL || m_pcCUAbove->getSlice()==NULL ||
1294       m_pcCUAbove->getSCUAddr()+uiARPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1295       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAbove->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1296       ))
1297     )
1298    {
1299      return NULL;
1300    }
1301    return m_pcCUAbove;
1302  }
1303 
1304  if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, uiNumPartInCUWidth ) )
1305  {
1306    uiARPartUnitIdx = MAX_UINT;
1307    return NULL;
1308  }
1309 
1310  uiARPartUnitIdx = g_auiRasterToZscan[ m_pcPic->getNumPartInCU() - uiNumPartInCUWidth ];
1311  if ( (bEnforceSliceRestriction && (m_pcCUAboveRight==NULL || m_pcCUAboveRight->getSlice()==NULL ||
1312       m_pcPic->getPicSym()->getInverseCUOrderMap( m_pcCUAboveRight->getAddr()) > m_pcPic->getPicSym()->getInverseCUOrderMap( getAddr()) ||
1313       m_pcCUAboveRight->getSCUAddr()+uiARPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1314       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAboveRight->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1315       ))
1316     )
1317  {
1318    return NULL;
1319  }
1320  return m_pcCUAboveRight;
1321}
1322
1323TComDataCU* TComDataCU::getPUBelowLeft( UInt& uiBLPartUnitIdx, UInt uiCurrPartUnitIdx, Bool bEnforceSliceRestriction )
1324{
1325  UInt uiAbsPartIdxLB     = g_auiZscanToRaster[uiCurrPartUnitIdx];
1326  UInt uiAbsZorderCUIdxLB = g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + (m_puhHeight[0] / m_pcPic->getMinCUHeight() - 1)*m_pcPic->getNumPartInWidth();
1327  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1328 
1329  if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxLB] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
1330  {
1331    uiBLPartUnitIdx = MAX_UINT;
1332    return NULL;
1333  }
1334 
1335  if ( RasterAddress::lessThanRow( uiAbsPartIdxLB, m_pcPic->getNumPartInHeight() - 1, uiNumPartInCUWidth ) )
1336  {
1337    if ( !RasterAddress::isZeroCol( uiAbsPartIdxLB, uiNumPartInCUWidth ) )
1338    {
1339      if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxLB + uiNumPartInCUWidth - 1 ] )
1340      {
1341        uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + uiNumPartInCUWidth - 1 ];
1342        if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxLB, uiAbsZorderCUIdxLB, uiNumPartInCUWidth ) )
1343        {
1344          return m_pcPic->getCU( getAddr() );
1345        }
1346        else
1347        {
1348          uiBLPartUnitIdx -= m_uiAbsIdxInLCU;
1349          return this;
1350        }
1351      }
1352      uiBLPartUnitIdx = MAX_UINT;
1353      return NULL;
1354    }
1355    uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + uiNumPartInCUWidth*2 - 1 ];
1356    if ( (bEnforceSliceRestriction && (m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL || 
1357       m_pcCULeft->getSCUAddr()+uiBLPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1358       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCULeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1359       ))
1360     )
1361    {
1362      return NULL;
1363    }
1364    return m_pcCULeft;
1365  }
1366 
1367  uiBLPartUnitIdx = MAX_UINT;
1368  return NULL;
1369}
1370
1371TComDataCU* TComDataCU::getPUBelowLeftAdi(UInt& uiBLPartUnitIdx,  UInt uiCurrPartUnitIdx, UInt uiPartUnitOffset, Bool bEnforceSliceRestriction )
1372{
1373  UInt uiAbsPartIdxLB     = g_auiZscanToRaster[uiCurrPartUnitIdx];
1374  UInt uiAbsZorderCUIdxLB = g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + ((m_puhHeight[0] / m_pcPic->getMinCUHeight()) - 1)*m_pcPic->getNumPartInWidth();
1375  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1376 
1377  if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxLB] + (m_pcPic->getPicSym()->getMinCUHeight() * uiPartUnitOffset)) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples())
1378  {
1379    uiBLPartUnitIdx = MAX_UINT;
1380    return NULL;
1381  }
1382 
1383  if ( RasterAddress::lessThanRow( uiAbsPartIdxLB, m_pcPic->getNumPartInHeight() - uiPartUnitOffset, uiNumPartInCUWidth ) )
1384  {
1385    if ( !RasterAddress::isZeroCol( uiAbsPartIdxLB, uiNumPartInCUWidth ) )
1386    {
1387      if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxLB + uiPartUnitOffset * uiNumPartInCUWidth - 1 ] )
1388      {
1389        uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + uiPartUnitOffset * uiNumPartInCUWidth - 1 ];
1390        if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxLB, uiAbsZorderCUIdxLB, uiNumPartInCUWidth ) )
1391        {
1392          return m_pcPic->getCU( getAddr() );
1393        }
1394        else
1395        {
1396          uiBLPartUnitIdx -= m_uiAbsIdxInLCU;
1397          return this;
1398        }
1399      }
1400      uiBLPartUnitIdx = MAX_UINT;
1401      return NULL;
1402    }
1403    uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + (1+uiPartUnitOffset) * uiNumPartInCUWidth - 1 ];
1404    if ( (bEnforceSliceRestriction && (m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL || 
1405       m_pcCULeft->getSCUAddr()+uiBLPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1406       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCULeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1407       ))
1408     )
1409    {
1410      return NULL;
1411    }
1412    return m_pcCULeft;
1413  }
1414 
1415  uiBLPartUnitIdx = MAX_UINT;
1416  return NULL;
1417}
1418
1419TComDataCU* TComDataCU::getPUAboveRightAdi(UInt&  uiARPartUnitIdx, UInt uiCurrPartUnitIdx, UInt uiPartUnitOffset, Bool bEnforceSliceRestriction )
1420{
1421  UInt uiAbsPartIdxRT     = g_auiZscanToRaster[uiCurrPartUnitIdx];
1422  UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + (m_puhWidth[0] / m_pcPic->getMinCUWidth()) - 1;
1423  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1424 
1425  if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxRT] + (m_pcPic->getPicSym()->getMinCUHeight() * uiPartUnitOffset)) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )
1426  {
1427    uiARPartUnitIdx = MAX_UINT;
1428    return NULL;
1429  }
1430 
1431  if ( RasterAddress::lessThanCol( uiAbsPartIdxRT, uiNumPartInCUWidth - uiPartUnitOffset, uiNumPartInCUWidth ) )
1432  {
1433    if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, uiNumPartInCUWidth ) )
1434    {
1435      if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxRT - uiNumPartInCUWidth + uiPartUnitOffset ] )
1436      {
1437        uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT - uiNumPartInCUWidth + uiPartUnitOffset ];
1438        if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxRT, uiAbsZorderCUIdx, uiNumPartInCUWidth ) )
1439        {
1440          return m_pcPic->getCU( getAddr() );
1441        }
1442        else
1443        {
1444          uiARPartUnitIdx -= m_uiAbsIdxInLCU;
1445          return this;
1446        }
1447      }
1448      uiARPartUnitIdx = MAX_UINT;
1449      return NULL;
1450    }
1451    uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT + m_pcPic->getNumPartInCU() - uiNumPartInCUWidth + uiPartUnitOffset ];
1452    if ( (bEnforceSliceRestriction && (m_pcCUAbove==NULL || m_pcCUAbove->getSlice()==NULL || 
1453       m_pcCUAbove->getSCUAddr()+uiARPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1454       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAbove->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1455       ))
1456     )
1457    {
1458      return NULL;
1459    }
1460    return m_pcCUAbove;
1461  }
1462 
1463  if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, uiNumPartInCUWidth ) )
1464  {
1465    uiARPartUnitIdx = MAX_UINT;
1466    return NULL;
1467  }
1468 
1469  uiARPartUnitIdx = g_auiRasterToZscan[ m_pcPic->getNumPartInCU() - uiNumPartInCUWidth + uiPartUnitOffset-1 ];
1470  if ( (bEnforceSliceRestriction && (m_pcCUAboveRight==NULL || m_pcCUAboveRight->getSlice()==NULL ||
1471       m_pcPic->getPicSym()->getInverseCUOrderMap( m_pcCUAboveRight->getAddr()) > m_pcPic->getPicSym()->getInverseCUOrderMap( getAddr()) ||
1472       m_pcCUAboveRight->getSCUAddr()+uiARPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1473       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAboveRight->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1474       ))
1475     )
1476  {
1477    return NULL;
1478  }
1479  return m_pcCUAboveRight;
1480}
1481
1482/** Get left QpMinCu
1483*\param   uiLPartUnitIdx
1484*\param   uiCurrAbsIdxInLCU
1485*\returns TComDataCU*   point of TComDataCU of left QpMinCu
1486*/
1487TComDataCU* TComDataCU::getQpMinCuLeft( UInt& uiLPartUnitIdx, UInt uiCurrAbsIdxInLCU)
1488{
1489  UInt numPartInCUWidth = m_pcPic->getNumPartInWidth();
1490  UInt absZorderQpMinCUIdx = (uiCurrAbsIdxInLCU>>((g_uiMaxCUDepth - getSlice()->getPPS()->getMaxCuDQPDepth())<<1))<<((g_uiMaxCUDepth -getSlice()->getPPS()->getMaxCuDQPDepth())<<1);
1491  UInt absRorderQpMinCUIdx = g_auiZscanToRaster[absZorderQpMinCUIdx];
1492
1493  // check for left LCU boundary
1494  if ( RasterAddress::isZeroCol(absRorderQpMinCUIdx, numPartInCUWidth) )
1495  {
1496    return NULL;
1497  }
1498
1499  // get index of left-CU relative to top-left corner of current quantization group
1500  uiLPartUnitIdx = g_auiRasterToZscan[absRorderQpMinCUIdx - 1];
1501
1502  // return pointer to current LCU
1503  return m_pcPic->getCU( getAddr() );
1504}
1505
1506/** Get Above QpMinCu
1507*\param   aPartUnitIdx
1508*\param   currAbsIdxInLCU
1509*\returns TComDataCU*   point of TComDataCU of above QpMinCu
1510*/
1511TComDataCU* TComDataCU::getQpMinCuAbove( UInt& aPartUnitIdx, UInt currAbsIdxInLCU )
1512{
1513  UInt numPartInCUWidth = m_pcPic->getNumPartInWidth();
1514  UInt absZorderQpMinCUIdx = (currAbsIdxInLCU>>((g_uiMaxCUDepth - getSlice()->getPPS()->getMaxCuDQPDepth())<<1))<<((g_uiMaxCUDepth - getSlice()->getPPS()->getMaxCuDQPDepth())<<1);
1515  UInt absRorderQpMinCUIdx = g_auiZscanToRaster[absZorderQpMinCUIdx];
1516
1517  // check for top LCU boundary
1518  if ( RasterAddress::isZeroRow( absRorderQpMinCUIdx, numPartInCUWidth) )
1519  {
1520    return NULL;
1521  }
1522
1523  // get index of top-CU relative to top-left corner of current quantization group
1524  aPartUnitIdx = g_auiRasterToZscan[absRorderQpMinCUIdx - numPartInCUWidth];
1525
1526  // return pointer to current LCU
1527  return m_pcPic->getCU( getAddr() );
1528}
1529
1530/** Get reference QP from left QpMinCu or latest coded QP
1531*\param   uiCurrAbsIdxInLCU
1532*\returns Char   reference QP value
1533*/
1534Char TComDataCU::getRefQP( UInt uiCurrAbsIdxInLCU )
1535{
1536  UInt        lPartIdx = 0, aPartIdx = 0;
1537  TComDataCU* cULeft  = getQpMinCuLeft ( lPartIdx, m_uiAbsIdxInLCU + uiCurrAbsIdxInLCU );
1538  TComDataCU* cUAbove = getQpMinCuAbove( aPartIdx, m_uiAbsIdxInLCU + uiCurrAbsIdxInLCU );
1539  return (((cULeft? cULeft->getQP( lPartIdx ): getLastCodedQP( uiCurrAbsIdxInLCU )) + (cUAbove? cUAbove->getQP( aPartIdx ): getLastCodedQP( uiCurrAbsIdxInLCU )) + 1) >> 1);
1540}
1541
1542Int TComDataCU::getLastValidPartIdx( Int iAbsPartIdx )
1543{
1544  Int iLastValidPartIdx = iAbsPartIdx-1;
1545  while ( iLastValidPartIdx >= 0
1546       && getPredictionMode( iLastValidPartIdx ) == MODE_NONE )
1547  {
1548    UInt uiDepth = getDepth( iLastValidPartIdx );
1549    iLastValidPartIdx -= m_uiNumPartition>>(uiDepth<<1);
1550  }
1551  return iLastValidPartIdx;
1552}
1553
1554Char TComDataCU::getLastCodedQP( UInt uiAbsPartIdx )
1555{
1556  UInt uiQUPartIdxMask = ~((1<<((g_uiMaxCUDepth - getSlice()->getPPS()->getMaxCuDQPDepth())<<1))-1);
1557  Int iLastValidPartIdx = getLastValidPartIdx( uiAbsPartIdx&uiQUPartIdxMask );
1558  if ( uiAbsPartIdx < m_uiNumPartition
1559    && (getSCUAddr()+iLastValidPartIdx < getSliceStartCU(m_uiAbsIdxInLCU+uiAbsPartIdx)))
1560  {
1561    return getSlice()->getSliceQp();
1562  }
1563  else if ( iLastValidPartIdx >= 0 )
1564  {
1565    return getQP( iLastValidPartIdx );
1566  }
1567  else
1568  {
1569    if ( getZorderIdxInCU() > 0 )
1570    {
1571      return getPic()->getCU( getAddr() )->getLastCodedQP( getZorderIdxInCU() );
1572    }
1573    else if ( getPic()->getPicSym()->getInverseCUOrderMap(getAddr()) > 0
1574      && getPic()->getPicSym()->getTileIdxMap(getAddr()) == getPic()->getPicSym()->getTileIdxMap(getPic()->getPicSym()->getCUOrderMap(getPic()->getPicSym()->getInverseCUOrderMap(getAddr())-1))
1575      && !( getSlice()->getPPS()->getEntropyCodingSyncEnabledFlag() && getAddr() % getPic()->getFrameWidthInCU() == 0 ) )
1576    {
1577      return getPic()->getCU( getPic()->getPicSym()->getCUOrderMap(getPic()->getPicSym()->getInverseCUOrderMap(getAddr())-1) )->getLastCodedQP( getPic()->getNumPartInCU() );
1578    }
1579    else
1580    {
1581      return getSlice()->getSliceQp();
1582    }
1583  }
1584}
1585/** Check whether the CU is coded in lossless coding mode
1586 * \param   uiAbsPartIdx
1587 * \returns true if the CU is coded in lossless coding mode; false if otherwise
1588 */
1589Bool TComDataCU::isLosslessCoded(UInt absPartIdx)
1590{
1591  return (getSlice()->getPPS()->getTransquantBypassEnableFlag() && getCUTransquantBypass (absPartIdx));
1592}
1593
1594/** Get allowed chroma intra modes
1595*\param   uiAbsPartIdx
1596*\param   uiModeList  pointer to chroma intra modes array
1597*\returns
1598*- fill uiModeList with chroma intra modes
1599*/
1600Void TComDataCU::getAllowedChromaDir( UInt uiAbsPartIdx, UInt* uiModeList )
1601{
1602  uiModeList[0] = PLANAR_IDX;
1603  uiModeList[1] = VER_IDX;
1604  uiModeList[2] = HOR_IDX;
1605  uiModeList[3] = DC_IDX;
1606  uiModeList[4] = DM_CHROMA_IDX;
1607
1608  UInt uiLumaMode = getLumaIntraDir( uiAbsPartIdx );
1609
1610  for( Int i = 0; i < NUM_CHROMA_MODE - 1; i++ )
1611  {
1612    if( uiLumaMode == uiModeList[i] )
1613    {
1614      uiModeList[i] = 34; // VER+8 mode
1615      break;
1616    }
1617  }
1618}
1619
1620/** Get most probable intra modes
1621*\param   uiAbsPartIdx
1622*\param   uiIntraDirPred  pointer to the array for MPM storage
1623*\param   piMode          it is set with MPM mode in case both MPM are equal. It is used to restrict RD search at encode side.
1624*\returns Number of MPM
1625*/
1626Int TComDataCU::getIntraDirLumaPredictor( UInt uiAbsPartIdx, Int* uiIntraDirPred, Int* piMode  )
1627{
1628  TComDataCU* pcTempCU;
1629  UInt        uiTempPartIdx;
1630  Int         iLeftIntraDir, iAboveIntraDir;
1631  Int         uiPredNum = 0;
1632 
1633  // Get intra direction of left PU
1634  pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
1635 
1636  iLeftIntraDir  = pcTempCU ? ( pcTempCU->isIntra( uiTempPartIdx ) ? pcTempCU->getLumaIntraDir( uiTempPartIdx ) : DC_IDX ) : DC_IDX;
1637 
1638  // Get intra direction of above PU
1639  pcTempCU = getPUAbove( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx, true, true );
1640 
1641  iAboveIntraDir = pcTempCU ? ( pcTempCU->isIntra( uiTempPartIdx ) ? pcTempCU->getLumaIntraDir( uiTempPartIdx ) : DC_IDX ) : DC_IDX;
1642 
1643  uiPredNum = 3;
1644  if(iLeftIntraDir == iAboveIntraDir)
1645  {
1646    if( piMode )
1647    {
1648      *piMode = 1;
1649    }
1650   
1651    if (iLeftIntraDir > 1) // angular modes
1652    {
1653      uiIntraDirPred[0] = iLeftIntraDir;
1654      uiIntraDirPred[1] = ((iLeftIntraDir + 29) % 32) + 2;
1655      uiIntraDirPred[2] = ((iLeftIntraDir - 1 ) % 32) + 2;
1656    }
1657    else //non-angular
1658    {
1659      uiIntraDirPred[0] = PLANAR_IDX;
1660      uiIntraDirPred[1] = DC_IDX;
1661      uiIntraDirPred[2] = VER_IDX; 
1662    }
1663  }
1664  else
1665  {
1666    if( piMode )
1667    {
1668      *piMode = 2;
1669    }
1670    uiIntraDirPred[0] = iLeftIntraDir;
1671    uiIntraDirPred[1] = iAboveIntraDir;
1672   
1673    if (iLeftIntraDir && iAboveIntraDir ) //both modes are non-planar
1674    {
1675      uiIntraDirPred[2] = PLANAR_IDX;
1676    }
1677    else
1678    {
1679      uiIntraDirPred[2] =  (iLeftIntraDir+iAboveIntraDir)<2? VER_IDX : DC_IDX;
1680    }
1681  }
1682 
1683  return uiPredNum;
1684}
1685
1686UInt TComDataCU::getCtxSplitFlag( UInt uiAbsPartIdx, UInt uiDepth )
1687{
1688  TComDataCU* pcTempCU;
1689  UInt        uiTempPartIdx;
1690  UInt        uiCtx;
1691  // Get left split flag
1692  pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
1693  uiCtx  = ( pcTempCU ) ? ( ( pcTempCU->getDepth( uiTempPartIdx ) > uiDepth ) ? 1 : 0 ) : 0;
1694 
1695  // Get above split flag
1696  pcTempCU = getPUAbove( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
1697  uiCtx += ( pcTempCU ) ? ( ( pcTempCU->getDepth( uiTempPartIdx ) > uiDepth ) ? 1 : 0 ) : 0;
1698 
1699  return uiCtx;
1700}
1701
1702UInt TComDataCU::getCtxQtCbf( TextType eType, UInt uiTrDepth )
1703{
1704  if( eType )
1705  {
1706    return uiTrDepth;
1707  }
1708  else
1709  {
1710    const UInt uiCtx = ( uiTrDepth == 0 ? 1 : 0 );
1711    return uiCtx;
1712  }
1713}
1714
1715UInt TComDataCU::getQuadtreeTULog2MinSizeInCU( UInt absPartIdx )
1716{
1717  UInt log2CbSize = g_aucConvertToBit[getWidth( absPartIdx )] + 2;
1718  PartSize  partSize  = getPartitionSize( absPartIdx );
1719  UInt quadtreeTUMaxDepth = getPredictionMode( absPartIdx ) == MODE_INTRA ? m_pcSlice->getSPS()->getQuadtreeTUMaxDepthIntra() : m_pcSlice->getSPS()->getQuadtreeTUMaxDepthInter(); 
1720  Int intraSplitFlag = ( getPredictionMode( absPartIdx ) == MODE_INTRA && partSize == SIZE_NxN ) ? 1 : 0;
1721  Int interSplitFlag = ((quadtreeTUMaxDepth == 1) && (getPredictionMode( absPartIdx ) == MODE_INTER) && (partSize != SIZE_2Nx2N) );
1722 
1723  UInt log2MinTUSizeInCU = 0;
1724  if (log2CbSize < (m_pcSlice->getSPS()->getQuadtreeTULog2MinSize() + quadtreeTUMaxDepth - 1 + interSplitFlag + intraSplitFlag) ) 
1725  {
1726    // when fully making use of signaled TUMaxDepth + inter/intraSplitFlag, resulting luma TB size is < QuadtreeTULog2MinSize
1727    log2MinTUSizeInCU = m_pcSlice->getSPS()->getQuadtreeTULog2MinSize();
1728  }
1729  else
1730  {
1731    // when fully making use of signaled TUMaxDepth + inter/intraSplitFlag, resulting luma TB size is still >= QuadtreeTULog2MinSize
1732    log2MinTUSizeInCU = log2CbSize - ( quadtreeTUMaxDepth - 1 + interSplitFlag + intraSplitFlag); // stop when trafoDepth == hierarchy_depth = splitFlag
1733    if ( log2MinTUSizeInCU > m_pcSlice->getSPS()->getQuadtreeTULog2MaxSize())
1734    {
1735      // when fully making use of signaled TUMaxDepth + inter/intraSplitFlag, resulting luma TB size is still > QuadtreeTULog2MaxSize
1736      log2MinTUSizeInCU = m_pcSlice->getSPS()->getQuadtreeTULog2MaxSize();
1737    } 
1738  }
1739  return log2MinTUSizeInCU;
1740}
1741
1742UInt TComDataCU::getCtxSkipFlag( UInt uiAbsPartIdx )
1743{
1744  TComDataCU* pcTempCU;
1745  UInt        uiTempPartIdx;
1746  UInt        uiCtx = 0;
1747 
1748  // Get BCBP of left PU
1749  pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
1750  uiCtx    = ( pcTempCU ) ? pcTempCU->isSkipped( uiTempPartIdx ) : 0;
1751 
1752  // Get BCBP of above PU
1753  pcTempCU = getPUAbove( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
1754  uiCtx   += ( pcTempCU ) ? pcTempCU->isSkipped( uiTempPartIdx ) : 0;
1755 
1756  return uiCtx;
1757}
1758
1759
1760
1761
1762UInt TComDataCU::getCtxInterDir( UInt uiAbsPartIdx )
1763{
1764  return getDepth( uiAbsPartIdx );
1765}
1766
1767Void TComDataCU::setCbfSubParts( UInt uiCbfY, UInt uiCbfU, UInt uiCbfV, UInt uiAbsPartIdx, UInt uiDepth )
1768{
1769  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
1770  memset( m_puhCbf[0] + uiAbsPartIdx, uiCbfY, sizeof( UChar ) * uiCurrPartNumb );
1771  memset( m_puhCbf[1] + uiAbsPartIdx, uiCbfU, sizeof( UChar ) * uiCurrPartNumb );
1772  memset( m_puhCbf[2] + uiAbsPartIdx, uiCbfV, sizeof( UChar ) * uiCurrPartNumb );
1773}
1774
1775Void TComDataCU::setCbfSubParts( UInt uiCbf, TextType eTType, UInt uiAbsPartIdx, UInt uiDepth )
1776{
1777
1778  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
1779  memset( m_puhCbf[g_aucConvertTxtTypeToIdx[eTType]] + uiAbsPartIdx, uiCbf, sizeof( UChar ) * uiCurrPartNumb );
1780}
1781
1782/** Sets a coded block flag for all sub-partitions of a partition
1783 * \param uiCbf The value of the coded block flag to be set
1784 * \param eTType
1785 * \param uiAbsPartIdx
1786 * \param uiPartIdx
1787 * \param uiDepth
1788 * \returns Void
1789 */
1790Void TComDataCU::setCbfSubParts ( UInt uiCbf, TextType eTType, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
1791{
1792  setSubPart<UChar>( uiCbf, m_puhCbf[g_aucConvertTxtTypeToIdx[eTType]], uiAbsPartIdx, uiDepth, uiPartIdx );
1793}
1794
1795Void TComDataCU::setDepthSubParts( UInt uiDepth, UInt uiAbsPartIdx )
1796{
1797  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
1798  memset( m_puhDepth + uiAbsPartIdx, uiDepth, sizeof(UChar)*uiCurrPartNumb );
1799}
1800
1801Bool TComDataCU::isFirstAbsZorderIdxInDepth (UInt uiAbsPartIdx, UInt uiDepth)
1802{
1803  UInt uiPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
1804  return (((m_uiAbsIdxInLCU + uiAbsPartIdx)% uiPartNumb) == 0);
1805}
1806
1807Void TComDataCU::setPartSizeSubParts( PartSize eMode, UInt uiAbsPartIdx, UInt uiDepth )
1808{
1809  assert( sizeof( *m_pePartSize) == 1 );
1810  memset( m_pePartSize + uiAbsPartIdx, eMode, m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ) );
1811}
1812
1813Void TComDataCU::setCUTransquantBypassSubParts( Bool flag, UInt uiAbsPartIdx, UInt uiDepth )
1814{
1815  memset( m_CUTransquantBypass + uiAbsPartIdx, flag, m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ) );
1816}
1817
1818Void TComDataCU::setSkipFlagSubParts( Bool skip, UInt absPartIdx, UInt depth )
1819{
1820  assert( sizeof( *m_skipFlag) == 1 );
1821  memset( m_skipFlag + absPartIdx, skip, m_pcPic->getNumPartInCU() >> ( 2 * depth ) );
1822}
1823
1824
1825Void TComDataCU::setPredModeSubParts( PredMode eMode, UInt uiAbsPartIdx, UInt uiDepth )
1826{
1827  assert( sizeof( *m_pePredMode) == 1 );
1828  memset( m_pePredMode + uiAbsPartIdx, eMode, m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ) );
1829}
1830
1831Void TComDataCU::setQPSubCUs( Int qp, TComDataCU* pcCU, UInt absPartIdx, UInt depth, Bool &foundNonZeroCbf )
1832{
1833  UInt currPartNumb = m_pcPic->getNumPartInCU() >> (depth << 1);
1834  UInt currPartNumQ = currPartNumb >> 2;
1835
1836  if(!foundNonZeroCbf)
1837  {
1838    if(pcCU->getDepth(absPartIdx) > depth)
1839    {
1840      for ( UInt partUnitIdx = 0; partUnitIdx < 4; partUnitIdx++ )
1841      {
1842        pcCU->setQPSubCUs( qp, pcCU, absPartIdx+partUnitIdx*currPartNumQ, depth+1, foundNonZeroCbf );
1843      }
1844    }
1845    else
1846    {
1847      if(pcCU->getCbf( absPartIdx, TEXT_LUMA ) || pcCU->getCbf( absPartIdx, TEXT_CHROMA_U ) || pcCU->getCbf( absPartIdx, TEXT_CHROMA_V ) )
1848      {
1849        foundNonZeroCbf = true;
1850      }
1851      else
1852      {
1853        setQPSubParts(qp, absPartIdx, depth);
1854      }
1855    }
1856  }
1857}
1858
1859Void TComDataCU::setQPSubParts( Int qp, UInt uiAbsPartIdx, UInt uiDepth )
1860{
1861  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
1862  TComSlice * pcSlice = getPic()->getSlice(getPic()->getCurrSliceIdx());
1863
1864  for(UInt uiSCUIdx = uiAbsPartIdx; uiSCUIdx < uiAbsPartIdx+uiCurrPartNumb; uiSCUIdx++)
1865  {
1866    if( m_pcPic->getCU( getAddr() )->getSliceSegmentStartCU(uiSCUIdx+getZorderIdxInCU()) == pcSlice->getSliceSegmentCurStartCUAddr() )
1867    {
1868      m_phQP[uiSCUIdx] = qp;
1869    }
1870  }
1871}
1872
1873Void TComDataCU::setLumaIntraDirSubParts( UInt uiDir, UInt uiAbsPartIdx, UInt uiDepth )
1874{
1875  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
1876 
1877  memset( m_puhLumaIntraDir + uiAbsPartIdx, uiDir, sizeof(UChar)*uiCurrPartNumb );
1878}
1879
1880template<typename T>
1881Void TComDataCU::setSubPart( T uiParameter, T* puhBaseLCU, UInt uiCUAddr, UInt uiCUDepth, UInt uiPUIdx )
1882{
1883  assert( sizeof(T) == 1 ); // Using memset() works only for types of size 1
1884 
1885  UInt uiCurrPartNumQ = (m_pcPic->getNumPartInCU() >> (2 * uiCUDepth)) >> 2;
1886  switch ( m_pePartSize[ uiCUAddr ] )
1887  {
1888    case SIZE_2Nx2N:
1889      memset( puhBaseLCU + uiCUAddr, uiParameter, 4 * uiCurrPartNumQ );
1890      break;
1891    case SIZE_2NxN:
1892      memset( puhBaseLCU + uiCUAddr, uiParameter, 2 * uiCurrPartNumQ );
1893      break;
1894    case SIZE_Nx2N:
1895      memset( puhBaseLCU + uiCUAddr, uiParameter, uiCurrPartNumQ );
1896      memset( puhBaseLCU + uiCUAddr + 2 * uiCurrPartNumQ, uiParameter, uiCurrPartNumQ );
1897      break;
1898    case SIZE_NxN:
1899      memset( puhBaseLCU + uiCUAddr, uiParameter, uiCurrPartNumQ ); 
1900      break;
1901    case SIZE_2NxnU:
1902      if ( uiPUIdx == 0 )
1903      {
1904        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 1) );                     
1905        memset( puhBaseLCU + uiCUAddr + uiCurrPartNumQ, uiParameter, (uiCurrPartNumQ >> 1) );                     
1906      }
1907      else if ( uiPUIdx == 1 )
1908      {
1909        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 1) );                     
1910        memset( puhBaseLCU + uiCUAddr + uiCurrPartNumQ, uiParameter, ((uiCurrPartNumQ >> 1) + (uiCurrPartNumQ << 1)) );                     
1911      }
1912      else
1913      {
1914        assert(0);
1915      }
1916      break;
1917    case SIZE_2NxnD:
1918      if ( uiPUIdx == 0 )
1919      {
1920        memset( puhBaseLCU + uiCUAddr, uiParameter, ((uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1)) );                     
1921        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + uiCurrPartNumQ, uiParameter, (uiCurrPartNumQ >> 1) );                     
1922      }
1923      else if ( uiPUIdx == 1 )
1924      {
1925        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 1) );                     
1926        memset( puhBaseLCU + uiCUAddr + uiCurrPartNumQ, uiParameter, (uiCurrPartNumQ >> 1) );                     
1927      }
1928      else
1929      {
1930        assert(0);
1931      }
1932      break;
1933    case SIZE_nLx2N:
1934      if ( uiPUIdx == 0 )
1935      {
1936        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 2) );
1937        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) ); 
1938        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ >> 2) ); 
1939        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) ); 
1940      }
1941      else if ( uiPUIdx == 1 )
1942      {
1943        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 2) );
1944        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) ); 
1945        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ >> 2) ); 
1946        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) ); 
1947      }
1948      else
1949      {
1950        assert(0);
1951      }
1952      break;
1953    case SIZE_nRx2N:
1954      if ( uiPUIdx == 0 )
1955      {     
1956        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) );                           
1957        memset( puhBaseLCU + uiCUAddr + uiCurrPartNumQ + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );                           
1958        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) );                           
1959        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + uiCurrPartNumQ + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );                           
1960      }
1961      else if ( uiPUIdx == 1 )
1962      {
1963        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 2) );                           
1964        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );                           
1965        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ >> 2) );                           
1966        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );                         
1967      }
1968      else
1969      {
1970        assert(0);
1971      }
1972      break;
1973    default:
1974      assert( 0 );
1975  }
1976}
1977
1978Void TComDataCU::setMergeFlagSubParts ( Bool bMergeFlag, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
1979{
1980  setSubPart( bMergeFlag, m_pbMergeFlag, uiAbsPartIdx, uiDepth, uiPartIdx );
1981}
1982
1983Void TComDataCU::setMergeIndexSubParts ( UInt uiMergeIndex, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
1984{
1985  setSubPart<UChar>( uiMergeIndex, m_puhMergeIndex, uiAbsPartIdx, uiDepth, uiPartIdx );
1986}
1987
1988
1989Void TComDataCU::setChromIntraDirSubParts( UInt uiDir, UInt uiAbsPartIdx, UInt uiDepth )
1990{
1991  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
1992 
1993  memset( m_puhChromaIntraDir + uiAbsPartIdx, uiDir, sizeof(UChar)*uiCurrPartNumb );
1994}
1995
1996Void TComDataCU::setInterDirSubParts( UInt uiDir, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
1997{
1998  setSubPart<UChar>( uiDir, m_puhInterDir, uiAbsPartIdx, uiDepth, uiPartIdx );
1999}
2000
2001Void TComDataCU::setMVPIdxSubParts( Int iMVPIdx, RefPicList eRefPicList, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
2002{
2003  setSubPart<Char>( iMVPIdx, m_apiMVPIdx[eRefPicList], uiAbsPartIdx, uiDepth, uiPartIdx );
2004}
2005
2006Void TComDataCU::setMVPNumSubParts( Int iMVPNum, RefPicList eRefPicList, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
2007{
2008  setSubPart<Char>( iMVPNum, m_apiMVPNum[eRefPicList], uiAbsPartIdx, uiDepth, uiPartIdx );
2009}
2010
2011
2012Void TComDataCU::setTrIdxSubParts( UInt uiTrIdx, UInt uiAbsPartIdx, UInt uiDepth )
2013{
2014  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2015 
2016  memset( m_puhTrIdx + uiAbsPartIdx, uiTrIdx, sizeof(UChar)*uiCurrPartNumb );
2017}
2018
2019Void TComDataCU::setTransformSkipSubParts( UInt useTransformSkipY, UInt useTransformSkipU, UInt useTransformSkipV, UInt uiAbsPartIdx, UInt uiDepth )
2020{
2021  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2022
2023  memset( m_puhTransformSkip[0] + uiAbsPartIdx, useTransformSkipY, sizeof( UChar ) * uiCurrPartNumb );
2024  memset( m_puhTransformSkip[1] + uiAbsPartIdx, useTransformSkipU, sizeof( UChar ) * uiCurrPartNumb );
2025  memset( m_puhTransformSkip[2] + uiAbsPartIdx, useTransformSkipV, sizeof( UChar ) * uiCurrPartNumb );
2026}
2027
2028Void TComDataCU::setTransformSkipSubParts( UInt useTransformSkip, TextType eType, UInt uiAbsPartIdx, UInt uiDepth)
2029{
2030  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2031
2032  memset( m_puhTransformSkip[g_aucConvertTxtTypeToIdx[eType]] + uiAbsPartIdx, useTransformSkip, sizeof( UChar ) * uiCurrPartNumb );
2033}
2034
2035Void TComDataCU::setSizeSubParts( UInt uiWidth, UInt uiHeight, UInt uiAbsPartIdx, UInt uiDepth )
2036{
2037  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2038 
2039  memset( m_puhWidth  + uiAbsPartIdx, uiWidth,  sizeof(UChar)*uiCurrPartNumb );
2040  memset( m_puhHeight + uiAbsPartIdx, uiHeight, sizeof(UChar)*uiCurrPartNumb );
2041}
2042
2043UChar TComDataCU::getNumPartitions()
2044{
2045  UChar iNumPart = 0;
2046 
2047  switch ( m_pePartSize[0] )
2048  {
2049    case SIZE_2Nx2N:    iNumPart = 1; break;
2050    case SIZE_2NxN:     iNumPart = 2; break;
2051    case SIZE_Nx2N:     iNumPart = 2; break;
2052    case SIZE_NxN:      iNumPart = 4; break;
2053    case SIZE_2NxnU:    iNumPart = 2; break;
2054    case SIZE_2NxnD:    iNumPart = 2; break;
2055    case SIZE_nLx2N:    iNumPart = 2; break;
2056    case SIZE_nRx2N:    iNumPart = 2; break;
2057    default:            assert (0);   break;
2058  }
2059 
2060  return  iNumPart;
2061}
2062
2063Void TComDataCU::getPartIndexAndSize( UInt uiPartIdx, UInt& ruiPartAddr, Int& riWidth, Int& riHeight )
2064{
2065  switch ( m_pePartSize[0] )
2066  {
2067    case SIZE_2NxN:
2068      riWidth = getWidth(0);      riHeight = getHeight(0) >> 1; ruiPartAddr = ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 1;
2069      break;
2070    case SIZE_Nx2N:
2071      riWidth = getWidth(0) >> 1; riHeight = getHeight(0);      ruiPartAddr = ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 2;
2072      break;
2073    case SIZE_NxN:
2074      riWidth = getWidth(0) >> 1; riHeight = getHeight(0) >> 1; ruiPartAddr = ( m_uiNumPartition >> 2 ) * uiPartIdx;
2075      break;
2076    case SIZE_2NxnU:
2077      riWidth     = getWidth(0);
2078      riHeight    = ( uiPartIdx == 0 ) ?  getHeight(0) >> 2 : ( getHeight(0) >> 2 ) + ( getHeight(0) >> 1 );
2079      ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : m_uiNumPartition >> 3;
2080      break;
2081    case SIZE_2NxnD:
2082      riWidth     = getWidth(0);
2083      riHeight    = ( uiPartIdx == 0 ) ?  ( getHeight(0) >> 2 ) + ( getHeight(0) >> 1 ) : getHeight(0) >> 2;
2084      ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : (m_uiNumPartition >> 1) + (m_uiNumPartition >> 3);
2085      break;
2086    case SIZE_nLx2N:
2087      riWidth     = ( uiPartIdx == 0 ) ? getWidth(0) >> 2 : ( getWidth(0) >> 2 ) + ( getWidth(0) >> 1 );
2088      riHeight    = getHeight(0);
2089      ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : m_uiNumPartition >> 4;
2090      break;
2091    case SIZE_nRx2N:
2092      riWidth     = ( uiPartIdx == 0 ) ? ( getWidth(0) >> 2 ) + ( getWidth(0) >> 1 ) : getWidth(0) >> 2;
2093      riHeight    = getHeight(0);
2094      ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : (m_uiNumPartition >> 2) + (m_uiNumPartition >> 4);
2095      break;
2096    default:
2097      assert ( m_pePartSize[0] == SIZE_2Nx2N );
2098      riWidth = getWidth(0);      riHeight = getHeight(0);      ruiPartAddr = 0;
2099      break;
2100  }
2101}
2102
2103
2104Void TComDataCU::getMvField ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefPicList, TComMvField& rcMvField )
2105{
2106  if ( pcCU == NULL )  // OUT OF BOUNDARY
2107  {
2108    TComMv  cZeroMv;
2109    rcMvField.setMvField( cZeroMv, NOT_VALID );
2110    return;
2111  }
2112 
2113  TComCUMvField*  pcCUMvField = pcCU->getCUMvField( eRefPicList );
2114  rcMvField.setMvField( pcCUMvField->getMv( uiAbsPartIdx ), pcCUMvField->getRefIdx( uiAbsPartIdx ) );
2115}
2116
2117Void TComDataCU::deriveLeftRightTopIdxGeneral ( UInt uiAbsPartIdx, UInt uiPartIdx, UInt& ruiPartIdxLT, UInt& ruiPartIdxRT )
2118{
2119  ruiPartIdxLT = m_uiAbsIdxInLCU + uiAbsPartIdx;
2120  UInt uiPUWidth = 0;
2121 
2122  switch ( m_pePartSize[uiAbsPartIdx] )
2123  {
2124    case SIZE_2Nx2N: uiPUWidth = m_puhWidth[uiAbsPartIdx];  break;
2125    case SIZE_2NxN:  uiPUWidth = m_puhWidth[uiAbsPartIdx];   break;
2126    case SIZE_Nx2N:  uiPUWidth = m_puhWidth[uiAbsPartIdx]  >> 1;  break;
2127    case SIZE_NxN:   uiPUWidth = m_puhWidth[uiAbsPartIdx]  >> 1; break;
2128    case SIZE_2NxnU:   uiPUWidth = m_puhWidth[uiAbsPartIdx]; break;
2129    case SIZE_2NxnD:   uiPUWidth = m_puhWidth[uiAbsPartIdx]; break;
2130    case SIZE_nLx2N:   
2131      if ( uiPartIdx == 0 )
2132      {
2133        uiPUWidth = m_puhWidth[uiAbsPartIdx]  >> 2; 
2134      }
2135      else if ( uiPartIdx == 1 )
2136      {
2137        uiPUWidth = (m_puhWidth[uiAbsPartIdx]  >> 1) + (m_puhWidth[uiAbsPartIdx]  >> 2); 
2138      }
2139      else
2140      {
2141        assert(0);
2142      }
2143      break;
2144    case SIZE_nRx2N:   
2145      if ( uiPartIdx == 0 )
2146      {
2147        uiPUWidth = (m_puhWidth[uiAbsPartIdx]  >> 1) + (m_puhWidth[uiAbsPartIdx]  >> 2); 
2148      }
2149      else if ( uiPartIdx == 1 )
2150      {
2151        uiPUWidth = m_puhWidth[uiAbsPartIdx]  >> 2; 
2152      }
2153      else
2154      {
2155        assert(0);
2156      }
2157      break;
2158    default:
2159      assert (0);
2160      break;
2161  }
2162 
2163  ruiPartIdxRT = g_auiRasterToZscan [g_auiZscanToRaster[ ruiPartIdxLT ] + uiPUWidth / m_pcPic->getMinCUWidth() - 1 ];
2164}
2165
2166Void TComDataCU::deriveLeftBottomIdxGeneral( UInt uiAbsPartIdx, UInt uiPartIdx, UInt& ruiPartIdxLB )
2167{
2168  UInt uiPUHeight = 0;
2169  switch ( m_pePartSize[uiAbsPartIdx] )
2170  {
2171    case SIZE_2Nx2N: uiPUHeight = m_puhHeight[uiAbsPartIdx];    break;
2172    case SIZE_2NxN:  uiPUHeight = m_puhHeight[uiAbsPartIdx] >> 1;    break;
2173    case SIZE_Nx2N:  uiPUHeight = m_puhHeight[uiAbsPartIdx];  break;
2174    case SIZE_NxN:   uiPUHeight = m_puhHeight[uiAbsPartIdx] >> 1;    break;
2175    case SIZE_2NxnU: 
2176      if ( uiPartIdx == 0 )
2177      {
2178        uiPUHeight = m_puhHeight[uiAbsPartIdx] >> 2;   
2179      }
2180      else if ( uiPartIdx == 1 )
2181      {
2182        uiPUHeight = (m_puhHeight[uiAbsPartIdx] >> 1) + (m_puhHeight[uiAbsPartIdx] >> 2);   
2183      }
2184      else
2185      {
2186        assert(0);
2187      }
2188      break;
2189    case SIZE_2NxnD: 
2190      if ( uiPartIdx == 0 )
2191      {
2192        uiPUHeight = (m_puhHeight[uiAbsPartIdx] >> 1) + (m_puhHeight[uiAbsPartIdx] >> 2);   
2193      }
2194      else if ( uiPartIdx == 1 )
2195      {
2196        uiPUHeight = m_puhHeight[uiAbsPartIdx] >> 2;   
2197      }
2198      else
2199      {
2200        assert(0);
2201      }
2202      break;
2203    case SIZE_nLx2N: uiPUHeight = m_puhHeight[uiAbsPartIdx];  break;
2204    case SIZE_nRx2N: uiPUHeight = m_puhHeight[uiAbsPartIdx];  break;
2205    default:
2206      assert (0);
2207      break;
2208  }
2209 
2210  ruiPartIdxLB      = g_auiRasterToZscan [g_auiZscanToRaster[ m_uiAbsIdxInLCU + uiAbsPartIdx ] + ((uiPUHeight / m_pcPic->getMinCUHeight()) - 1)*m_pcPic->getNumPartInWidth()];
2211}
2212
2213Void TComDataCU::deriveLeftRightTopIdx ( UInt uiPartIdx, UInt& ruiPartIdxLT, UInt& ruiPartIdxRT )
2214{
2215  ruiPartIdxLT = m_uiAbsIdxInLCU;
2216  ruiPartIdxRT = g_auiRasterToZscan [g_auiZscanToRaster[ ruiPartIdxLT ] + m_puhWidth[0] / m_pcPic->getMinCUWidth() - 1 ];
2217 
2218  switch ( m_pePartSize[0] )
2219  {
2220    case SIZE_2Nx2N:                                                                                                                                break;
2221    case SIZE_2NxN:
2222      ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 1; ruiPartIdxRT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 1;
2223      break;
2224    case SIZE_Nx2N:
2225      ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 2; ruiPartIdxRT -= ( uiPartIdx == 1 )? 0 : m_uiNumPartition >> 2;
2226      break;
2227    case SIZE_NxN:
2228      ruiPartIdxLT += ( m_uiNumPartition >> 2 ) * uiPartIdx;         ruiPartIdxRT +=  ( m_uiNumPartition >> 2 ) * ( uiPartIdx - 1 );
2229      break;
2230    case SIZE_2NxnU:
2231      ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 3;
2232      ruiPartIdxRT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 3;
2233      break;
2234    case SIZE_2NxnD:
2235      ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : ( m_uiNumPartition >> 1 ) + ( m_uiNumPartition >> 3 );
2236      ruiPartIdxRT += ( uiPartIdx == 0 )? 0 : ( m_uiNumPartition >> 1 ) + ( m_uiNumPartition >> 3 );
2237      break;
2238    case SIZE_nLx2N:
2239      ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 4;
2240      ruiPartIdxRT -= ( uiPartIdx == 1 )? 0 : ( m_uiNumPartition >> 2 ) + ( m_uiNumPartition >> 4 );
2241      break;
2242    case SIZE_nRx2N:
2243      ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : ( m_uiNumPartition >> 2 ) + ( m_uiNumPartition >> 4 );
2244      ruiPartIdxRT -= ( uiPartIdx == 1 )? 0 : m_uiNumPartition >> 4;
2245      break;
2246    default:
2247      assert (0);
2248      break;
2249  }
2250 
2251}
2252
2253Void TComDataCU::deriveLeftBottomIdx( UInt  uiPartIdx,      UInt&      ruiPartIdxLB )
2254{
2255  ruiPartIdxLB      = g_auiRasterToZscan [g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + ( ((m_puhHeight[0] / m_pcPic->getMinCUHeight())>>1) - 1)*m_pcPic->getNumPartInWidth()];
2256 
2257  switch ( m_pePartSize[0] )
2258  {
2259    case SIZE_2Nx2N:
2260      ruiPartIdxLB += m_uiNumPartition >> 1;
2261      break;
2262    case SIZE_2NxN:
2263      ruiPartIdxLB += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 1;
2264      break;
2265    case SIZE_Nx2N:
2266      ruiPartIdxLB += ( uiPartIdx == 0 )? m_uiNumPartition >> 1 : (m_uiNumPartition >> 2)*3;
2267      break;
2268    case SIZE_NxN:
2269      ruiPartIdxLB += ( m_uiNumPartition >> 2 ) * uiPartIdx;
2270      break;
2271    case SIZE_2NxnU:
2272      ruiPartIdxLB += ( uiPartIdx == 0 ) ? -((Int)m_uiNumPartition >> 3) : m_uiNumPartition >> 1;
2273      break;
2274    case SIZE_2NxnD:
2275      ruiPartIdxLB += ( uiPartIdx == 0 ) ? (m_uiNumPartition >> 2) + (m_uiNumPartition >> 3): m_uiNumPartition >> 1;
2276      break;
2277    case SIZE_nLx2N:
2278      ruiPartIdxLB += ( uiPartIdx == 0 ) ? m_uiNumPartition >> 1 : (m_uiNumPartition >> 1) + (m_uiNumPartition >> 4);
2279      break;
2280    case SIZE_nRx2N:
2281      ruiPartIdxLB += ( uiPartIdx == 0 ) ? m_uiNumPartition >> 1 : (m_uiNumPartition >> 1) + (m_uiNumPartition >> 2) + (m_uiNumPartition >> 4);
2282      break;
2283    default:
2284      assert (0);
2285      break;
2286  }
2287}
2288
2289/** Derives the partition index of neighbouring bottom right block
2290 * \param [in]  eCUMode
2291 * \param [in]  uiPartIdx
2292 * \param [out] ruiPartIdxRB
2293 */
2294Void TComDataCU::deriveRightBottomIdx( UInt  uiPartIdx,      UInt&      ruiPartIdxRB )
2295{
2296  ruiPartIdxRB      = g_auiRasterToZscan [g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + ( ((m_puhHeight[0] / m_pcPic->getMinCUHeight())>>1) - 1)*m_pcPic->getNumPartInWidth() +  m_puhWidth[0] / m_pcPic->getMinCUWidth() - 1];
2297
2298  switch ( m_pePartSize[0] )
2299  {
2300    case SIZE_2Nx2N: 
2301      ruiPartIdxRB += m_uiNumPartition >> 1;   
2302      break;
2303    case SIZE_2NxN: 
2304      ruiPartIdxRB += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 1;   
2305      break;
2306    case SIZE_Nx2N: 
2307      ruiPartIdxRB += ( uiPartIdx == 0 )? m_uiNumPartition >> 2 : (m_uiNumPartition >> 1);   
2308      break;
2309    case SIZE_NxN:   
2310      ruiPartIdxRB += ( m_uiNumPartition >> 2 ) * ( uiPartIdx - 1 );   
2311      break;
2312    case SIZE_2NxnU:
2313      ruiPartIdxRB += ( uiPartIdx == 0 ) ? -((Int)m_uiNumPartition >> 3) : m_uiNumPartition >> 1;
2314      break;
2315    case SIZE_2NxnD:
2316      ruiPartIdxRB += ( uiPartIdx == 0 ) ? (m_uiNumPartition >> 2) + (m_uiNumPartition >> 3): m_uiNumPartition >> 1;
2317      break;
2318    case SIZE_nLx2N:
2319      ruiPartIdxRB += ( uiPartIdx == 0 ) ? (m_uiNumPartition >> 3) + (m_uiNumPartition >> 4): m_uiNumPartition >> 1;
2320      break;
2321    case SIZE_nRx2N:
2322      ruiPartIdxRB += ( uiPartIdx == 0 ) ? (m_uiNumPartition >> 2) + (m_uiNumPartition >> 3) + (m_uiNumPartition >> 4) : m_uiNumPartition >> 1;
2323      break;
2324    default:
2325      assert (0);
2326      break;
2327  }
2328}
2329
2330Void TComDataCU::deriveLeftRightTopIdxAdi ( UInt& ruiPartIdxLT, UInt& ruiPartIdxRT, UInt uiPartOffset, UInt uiPartDepth )
2331{
2332  UInt uiNumPartInWidth = (m_puhWidth[0]/m_pcPic->getMinCUWidth())>>uiPartDepth;
2333  ruiPartIdxLT = m_uiAbsIdxInLCU + uiPartOffset;
2334  ruiPartIdxRT = g_auiRasterToZscan[ g_auiZscanToRaster[ ruiPartIdxLT ] + uiNumPartInWidth - 1 ];
2335}
2336
2337Void TComDataCU::deriveLeftBottomIdxAdi( UInt& ruiPartIdxLB, UInt uiPartOffset, UInt uiPartDepth )
2338{
2339  UInt uiAbsIdx;
2340  UInt uiMinCuWidth, uiWidthInMinCus;
2341 
2342  uiMinCuWidth    = getPic()->getMinCUWidth();
2343  uiWidthInMinCus = (getWidth(0)/uiMinCuWidth)>>uiPartDepth;
2344  uiAbsIdx        = getZorderIdxInCU()+uiPartOffset+(m_uiNumPartition>>(uiPartDepth<<1))-1;
2345  uiAbsIdx        = g_auiZscanToRaster[uiAbsIdx]-(uiWidthInMinCus-1);
2346  ruiPartIdxLB    = g_auiRasterToZscan[uiAbsIdx];
2347}
2348
2349Bool TComDataCU::hasEqualMotion( UInt uiAbsPartIdx, TComDataCU* pcCandCU, UInt uiCandAbsPartIdx )
2350{
2351
2352  if ( getInterDir( uiAbsPartIdx ) != pcCandCU->getInterDir( uiCandAbsPartIdx ) )
2353  {
2354    return false;
2355  }
2356
2357  for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
2358  {
2359    if ( getInterDir( uiAbsPartIdx ) & ( 1 << uiRefListIdx ) )
2360    {
2361      if ( getCUMvField( RefPicList( uiRefListIdx ) )->getMv( uiAbsPartIdx )     != pcCandCU->getCUMvField( RefPicList( uiRefListIdx ) )->getMv( uiCandAbsPartIdx ) || 
2362        getCUMvField( RefPicList( uiRefListIdx ) )->getRefIdx( uiAbsPartIdx ) != pcCandCU->getCUMvField( RefPicList( uiRefListIdx ) )->getRefIdx( uiCandAbsPartIdx ) )
2363      {
2364        return false;
2365      }
2366    }
2367  }
2368
2369  return true;
2370}
2371
2372
2373
2374
2375/** Constructs a list of merging candidates
2376 * \param uiAbsPartIdx
2377 * \param uiPUIdx
2378 * \param uiDepth
2379 * \param pcMvFieldNeighbours
2380 * \param puhInterDirNeighbours
2381 * \param numValidMergeCand
2382 */
2383Void TComDataCU::getInterMergeCandidates( UInt uiAbsPartIdx, UInt uiPUIdx, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours
2384      , Int& numValidMergeCand, Int mrgCandIdx
2385)
2386{
2387  UInt uiAbsPartAddr = m_uiAbsIdxInLCU + uiAbsPartIdx;
2388  Bool abCandIsInter[ MRG_MAX_NUM_CANDS ];
2389  for( UInt ui = 0; ui < getSlice()->getMaxNumMergeCand(); ++ui )
2390  {
2391    abCandIsInter[ui] = false;
2392    pcMvFieldNeighbours[ ( ui << 1 )     ].setRefIdx(NOT_VALID);
2393    pcMvFieldNeighbours[ ( ui << 1 ) + 1 ].setRefIdx(NOT_VALID);
2394  }
2395  numValidMergeCand = getSlice()->getMaxNumMergeCand();
2396  // compute the location of the current PU
2397  Int xP, yP, nPSW, nPSH;
2398  this->getPartPosition(uiPUIdx, xP, yP, nPSW, nPSH);
2399
2400  Int iCount = 0;
2401
2402  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB;
2403  PartSize cCurPS = getPartitionSize( uiAbsPartIdx );
2404  deriveLeftRightTopIdxGeneral( uiAbsPartIdx, uiPUIdx, uiPartIdxLT, uiPartIdxRT );
2405  deriveLeftBottomIdxGeneral  ( uiAbsPartIdx, uiPUIdx, uiPartIdxLB );
2406
2407  //left
2408  UInt uiLeftPartIdx = 0;
2409  TComDataCU* pcCULeft = 0;
2410  pcCULeft = getPULeft( uiLeftPartIdx, uiPartIdxLB );
2411  Bool isAvailableA1 = pcCULeft &&
2412  pcCULeft->isDiffMER(xP -1, yP+nPSH-1, xP, yP) &&
2413  !( uiPUIdx == 1 && (cCurPS == SIZE_Nx2N || cCurPS == SIZE_nLx2N || cCurPS == SIZE_nRx2N) ) &&
2414  !pcCULeft->isIntra( uiLeftPartIdx ) ;
2415  if ( isAvailableA1 )
2416  {
2417    abCandIsInter[iCount] = true;
2418    // get Inter Dir
2419    puhInterDirNeighbours[iCount] = pcCULeft->getInterDir( uiLeftPartIdx );
2420    // get Mv from Left
2421    pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
2422    if ( getSlice()->isInterB() )
2423    {
2424      pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
2425    }
2426    if ( mrgCandIdx == iCount )
2427    {
2428      return;
2429    }
2430    iCount ++;
2431  }
2432 
2433  // early termination
2434  if (iCount == getSlice()->getMaxNumMergeCand()) 
2435  {
2436    return;
2437  }
2438
2439  // above
2440  UInt uiAbovePartIdx = 0;
2441  TComDataCU* pcCUAbove = 0;
2442  pcCUAbove = getPUAbove( uiAbovePartIdx, uiPartIdxRT );
2443  Bool isAvailableB1 = pcCUAbove &&
2444  pcCUAbove->isDiffMER(xP+nPSW-1, yP-1, xP, yP) &&
2445  !( uiPUIdx == 1 && (cCurPS == SIZE_2NxN || cCurPS == SIZE_2NxnU || cCurPS == SIZE_2NxnD) ) &&
2446  !pcCUAbove->isIntra( uiAbovePartIdx );
2447  if ( isAvailableB1 && (!isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAbove, uiAbovePartIdx ) ) )
2448  {
2449    abCandIsInter[iCount] = true;
2450    // get Inter Dir
2451    puhInterDirNeighbours[iCount] = pcCUAbove->getInterDir( uiAbovePartIdx );
2452    // get Mv from Left
2453    pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
2454    if ( getSlice()->isInterB() )
2455    {
2456      pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
2457    }
2458
2459    if ( mrgCandIdx == iCount )
2460    {
2461      return;
2462    }
2463    iCount ++;
2464  }
2465  // early termination
2466  if (iCount == getSlice()->getMaxNumMergeCand()) 
2467  {
2468    return;
2469  }
2470
2471
2472  // above right
2473  UInt uiAboveRightPartIdx = 0;
2474  TComDataCU* pcCUAboveRight = 0;
2475  pcCUAboveRight = getPUAboveRight( uiAboveRightPartIdx, uiPartIdxRT );
2476  Bool isAvailableB0 = pcCUAboveRight &&
2477  pcCUAboveRight->isDiffMER(xP+nPSW, yP-1, xP, yP) &&
2478  !pcCUAboveRight->isIntra( uiAboveRightPartIdx );
2479  if ( isAvailableB0 && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveRight, uiAboveRightPartIdx ) ) )
2480  {
2481    abCandIsInter[iCount] = true;
2482    // get Inter Dir
2483    puhInterDirNeighbours[iCount] = pcCUAboveRight->getInterDir( uiAboveRightPartIdx );
2484    // get Mv from Left
2485    pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
2486    if ( getSlice()->isInterB() )
2487    {
2488      pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
2489    }
2490    if ( mrgCandIdx == iCount )
2491    {
2492      return;
2493    }
2494    iCount ++;
2495  }
2496  // early termination
2497  if (iCount == getSlice()->getMaxNumMergeCand()) 
2498  {
2499    return;
2500  }
2501
2502  //left bottom
2503  UInt uiLeftBottomPartIdx = 0;
2504  TComDataCU* pcCULeftBottom = 0;
2505  pcCULeftBottom = this->getPUBelowLeft( uiLeftBottomPartIdx, uiPartIdxLB );
2506  Bool isAvailableA0 = pcCULeftBottom &&
2507  pcCULeftBottom->isDiffMER(xP-1, yP+nPSH, xP, yP) &&
2508  !pcCULeftBottom->isIntra( uiLeftBottomPartIdx ) ;
2509  if ( isAvailableA0 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCULeftBottom, uiLeftBottomPartIdx ) ) )
2510  {
2511    abCandIsInter[iCount] = true;
2512    // get Inter Dir
2513    puhInterDirNeighbours[iCount] = pcCULeftBottom->getInterDir( uiLeftBottomPartIdx );
2514    // get Mv from Left
2515    pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
2516    if ( getSlice()->isInterB() )
2517    {
2518      pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
2519    }
2520
2521    if ( mrgCandIdx == iCount )
2522    {
2523      return;
2524    }
2525    iCount ++;
2526  }
2527  // early termination
2528  if (iCount == getSlice()->getMaxNumMergeCand()) 
2529  {
2530    return;
2531  }
2532
2533  // above left
2534  if( iCount < 4 )
2535  {
2536    UInt uiAboveLeftPartIdx = 0;
2537    TComDataCU* pcCUAboveLeft = 0;
2538    pcCUAboveLeft = getPUAboveLeft( uiAboveLeftPartIdx, uiAbsPartAddr );
2539    Bool isAvailableB2 = pcCUAboveLeft &&
2540    pcCUAboveLeft->isDiffMER(xP-1, yP-1, xP, yP) &&
2541    !pcCUAboveLeft->isIntra( uiAboveLeftPartIdx );
2542    if ( isAvailableB2 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) )
2543        && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) ) )
2544    {
2545      abCandIsInter[iCount] = true;
2546      // get Inter Dir
2547      puhInterDirNeighbours[iCount] = pcCUAboveLeft->getInterDir( uiAboveLeftPartIdx );
2548      // get Mv from Left
2549      pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
2550      if ( getSlice()->isInterB() )
2551      {
2552        pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
2553      }
2554      if ( mrgCandIdx == iCount )
2555      {
2556        return;
2557      }
2558      iCount ++;
2559    }
2560  }
2561  // early termination
2562  if (iCount == getSlice()->getMaxNumMergeCand()) 
2563  {
2564    return;
2565  }
2566
2567  if ( getSlice()->getEnableTMVPFlag())
2568  {
2569    //>> MTK colocated-RightBottom
2570    UInt uiPartIdxRB;
2571
2572    deriveRightBottomIdx( uiPUIdx, uiPartIdxRB ); 
2573
2574    UInt uiAbsPartIdxTmp = g_auiZscanToRaster[uiPartIdxRB];
2575    UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
2576
2577    TComMv cColMv;
2578    Int iRefIdx;
2579    Int uiLCUIdx = -1;
2580
2581    if      ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
2582    {
2583    }
2584    else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxTmp] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
2585    {
2586    }
2587    else
2588    {
2589      if ( ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
2590        ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
2591      {
2592        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + uiNumPartInCUWidth + 1 ];
2593        uiLCUIdx = getAddr();
2594      }
2595      else if ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
2596      {
2597        uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdxTmp + uiNumPartInCUWidth + 1) % m_pcPic->getNumPartInCU() ];
2598      }
2599      else if ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
2600      {
2601        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + 1 ];
2602        uiLCUIdx = getAddr() + 1;
2603      }
2604      else //is the right bottom corner of LCU                       
2605      {
2606        uiAbsPartAddr = 0;
2607      }
2608    }
2609   
2610   
2611    iRefIdx = 0;
2612    Bool bExistMV = false;
2613    UInt uiPartIdxCenter;
2614    UInt uiCurLCUIdx = getAddr();
2615    Int dir = 0;
2616    UInt uiArrayAddr = iCount;
2617    xDeriveCenterIdx( uiPUIdx, uiPartIdxCenter );
2618    bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_0, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx );
2619    if( bExistMV == false )
2620    {
2621      bExistMV = xGetColMVP( REF_PIC_LIST_0, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
2622    }
2623    if( bExistMV )
2624    {
2625      dir |= 1;
2626      pcMvFieldNeighbours[ 2 * uiArrayAddr ].setMvField( cColMv, iRefIdx );
2627    }
2628
2629    if ( getSlice()->isInterB() )
2630    {
2631      bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_1, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx);
2632      if( bExistMV == false )
2633      {
2634        bExistMV = xGetColMVP( REF_PIC_LIST_1, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
2635      }
2636      if( bExistMV )
2637      {
2638        dir |= 2;
2639        pcMvFieldNeighbours[ 2 * uiArrayAddr + 1 ].setMvField( cColMv, iRefIdx );
2640      }
2641    }
2642   
2643    if (dir != 0)
2644    {
2645      puhInterDirNeighbours[uiArrayAddr] = dir;
2646      abCandIsInter[uiArrayAddr] = true;
2647      if ( mrgCandIdx == iCount )
2648      {
2649        return;
2650      }
2651      iCount++;
2652    }
2653  }
2654  // early termination
2655  if (iCount == getSlice()->getMaxNumMergeCand()) 
2656  {
2657    return;
2658  }
2659  UInt uiArrayAddr = iCount;
2660  UInt uiCutoff = uiArrayAddr;
2661   
2662  if ( getSlice()->isInterB())
2663  {
2664    UInt uiPriorityList0[12] = {0 , 1, 0, 2, 1, 2, 0, 3, 1, 3, 2, 3};
2665    UInt uiPriorityList1[12] = {1 , 0, 2, 0, 2, 1, 3, 0, 3, 1, 3, 2};
2666
2667    for (Int idx=0; idx<uiCutoff*(uiCutoff-1) && uiArrayAddr!= getSlice()->getMaxNumMergeCand(); idx++)
2668    {
2669      Int i = uiPriorityList0[idx]; Int j = uiPriorityList1[idx];
2670      if (abCandIsInter[i] && abCandIsInter[j]&& (puhInterDirNeighbours[i]&0x1)&&(puhInterDirNeighbours[j]&0x2))
2671      {
2672        abCandIsInter[uiArrayAddr] = true;
2673        puhInterDirNeighbours[uiArrayAddr] = 3;
2674
2675        // get Mv from cand[i] and cand[j]
2676        pcMvFieldNeighbours[uiArrayAddr << 1].setMvField(pcMvFieldNeighbours[i<<1].getMv(), pcMvFieldNeighbours[i<<1].getRefIdx());
2677        pcMvFieldNeighbours[( uiArrayAddr << 1 ) + 1].setMvField(pcMvFieldNeighbours[(j<<1)+1].getMv(), pcMvFieldNeighbours[(j<<1)+1].getRefIdx());
2678
2679        Int iRefPOCL0 = m_pcSlice->getRefPOC( REF_PIC_LIST_0, pcMvFieldNeighbours[(uiArrayAddr<<1)].getRefIdx() );
2680        Int iRefPOCL1 = m_pcSlice->getRefPOC( REF_PIC_LIST_1, pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getRefIdx() );
2681        if (iRefPOCL0 == iRefPOCL1 && pcMvFieldNeighbours[(uiArrayAddr<<1)].getMv() == pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getMv())
2682        {
2683          abCandIsInter[uiArrayAddr] = false;
2684        }
2685        else
2686        {
2687          uiArrayAddr++;
2688        }
2689      }
2690    }
2691  }
2692  // early termination
2693  if (uiArrayAddr == getSlice()->getMaxNumMergeCand()) 
2694  {
2695    return;
2696  }
2697  Int iNumRefIdx = (getSlice()->isInterB()) ? min(m_pcSlice->getNumRefIdx(REF_PIC_LIST_0), m_pcSlice->getNumRefIdx(REF_PIC_LIST_1)) : m_pcSlice->getNumRefIdx(REF_PIC_LIST_0);
2698  Int r = 0;
2699  Int refcnt = 0;
2700  while (uiArrayAddr < getSlice()->getMaxNumMergeCand())
2701  {
2702    abCandIsInter[uiArrayAddr] = true;
2703    puhInterDirNeighbours[uiArrayAddr] = 1;
2704    pcMvFieldNeighbours[uiArrayAddr << 1].setMvField( TComMv(0, 0), r);
2705
2706    if ( getSlice()->isInterB() )
2707    {
2708      puhInterDirNeighbours[uiArrayAddr] = 3;
2709      pcMvFieldNeighbours[(uiArrayAddr << 1) + 1].setMvField(TComMv(0, 0), r);
2710    }
2711    uiArrayAddr++;
2712    if ( refcnt == iNumRefIdx - 1 )
2713    {
2714      r = 0;
2715    }
2716    else
2717    {
2718      ++r;
2719      ++refcnt;
2720    }
2721  }
2722
2723  numValidMergeCand = uiArrayAddr;
2724}
2725
2726/** Check whether the current PU and a spatial neighboring PU are in a same ME region.
2727 * \param xN, xN   location of the upper-left corner pixel of a neighboring PU
2728 * \param xP, yP   location of the upper-left corner pixel of the current PU
2729 * \returns Bool
2730 */
2731Bool TComDataCU::isDiffMER(Int xN, Int yN, Int xP, Int yP)
2732{
2733
2734  UInt plevel = this->getSlice()->getPPS()->getLog2ParallelMergeLevelMinus2() + 2;
2735  if ((xN>>plevel)!= (xP>>plevel))
2736  {
2737    return true;
2738  }
2739  if ((yN>>plevel)!= (yP>>plevel))
2740  {
2741    return true;
2742  }
2743  return false;
2744}
2745/** calculate the location of upper-left corner pixel and size of the current PU.
2746 * \param partIdx  PU index within a CU
2747 * \param xP, yP   location of the upper-left corner pixel of the current PU
2748 * \param PSW, nPSH    size of the curren PU
2749 * \returns Void
2750 */
2751Void TComDataCU::getPartPosition( UInt partIdx, Int& xP, Int& yP, Int& nPSW, Int& nPSH)
2752{
2753  UInt col = m_uiCUPelX;
2754  UInt row = m_uiCUPelY;
2755
2756  switch ( m_pePartSize[0] )
2757  {
2758  case SIZE_2NxN:
2759    nPSW = getWidth(0);     
2760    nPSH = getHeight(0) >> 1; 
2761    xP   = col;
2762    yP   = (partIdx ==0)? row: row + nPSH;
2763    break;
2764  case SIZE_Nx2N:
2765    nPSW = getWidth(0) >> 1; 
2766    nPSH = getHeight(0);     
2767    xP   = (partIdx ==0)? col: col + nPSW;
2768    yP   = row;
2769    break;
2770  case SIZE_NxN:
2771    nPSW = getWidth(0) >> 1; 
2772    nPSH = getHeight(0) >> 1; 
2773    xP   = col + (partIdx&0x1)*nPSW;
2774    yP   = row + (partIdx>>1)*nPSH;
2775    break;
2776  case SIZE_2NxnU:
2777    nPSW = getWidth(0);
2778    nPSH = ( partIdx == 0 ) ?  getHeight(0) >> 2 : ( getHeight(0) >> 2 ) + ( getHeight(0) >> 1 );
2779    xP   = col;
2780    yP   = (partIdx ==0)? row: row + getHeight(0) - nPSH;
2781
2782    break;
2783  case SIZE_2NxnD:
2784    nPSW = getWidth(0);
2785    nPSH = ( partIdx == 0 ) ?  ( getHeight(0) >> 2 ) + ( getHeight(0) >> 1 ) : getHeight(0) >> 2;
2786    xP   = col;
2787    yP   = (partIdx ==0)? row: row + getHeight(0) - nPSH;
2788    break;
2789  case SIZE_nLx2N:
2790    nPSW = ( partIdx == 0 ) ? getWidth(0) >> 2 : ( getWidth(0) >> 2 ) + ( getWidth(0) >> 1 );
2791    nPSH = getHeight(0);
2792    xP   = (partIdx ==0)? col: col + getWidth(0) - nPSW;
2793    yP   = row;
2794    break;
2795  case SIZE_nRx2N:
2796    nPSW = ( partIdx == 0 ) ? ( getWidth(0) >> 2 ) + ( getWidth(0) >> 1 ) : getWidth(0) >> 2;
2797    nPSH = getHeight(0);
2798    xP   = (partIdx ==0)? col: col + getWidth(0) - nPSW;
2799    yP   = row;
2800    break;
2801  default:
2802    assert ( m_pePartSize[0] == SIZE_2Nx2N );
2803    nPSW = getWidth(0);     
2804    nPSH = getHeight(0);     
2805    xP   = col ;
2806    yP   = row ;
2807
2808    break;
2809  }
2810}
2811
2812/** Constructs a list of candidates for AMVP
2813 * \param uiPartIdx
2814 * \param uiPartAddr
2815 * \param eRefPicList
2816 * \param iRefIdx
2817 * \param pInfo
2818 */
2819Void TComDataCU::fillMvpCand ( UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, Int iRefIdx, AMVPInfo* pInfo )
2820{
2821  TComMv cMvPred;
2822  Bool bAddedSmvp = false;
2823
2824  pInfo->iN = 0; 
2825  if (iRefIdx < 0)
2826  {
2827    return;
2828  }
2829 
2830  //-- Get Spatial MV
2831  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB;
2832  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
2833  Bool bAdded = false;
2834 
2835  deriveLeftRightTopIdx( uiPartIdx, uiPartIdxLT, uiPartIdxRT );
2836  deriveLeftBottomIdx( uiPartIdx, uiPartIdxLB );
2837 
2838  TComDataCU* tmpCU = NULL;
2839  UInt idx;
2840  tmpCU = getPUBelowLeft(idx, uiPartIdxLB);
2841  bAddedSmvp = (tmpCU != NULL) && (tmpCU->getPredictionMode(idx) != MODE_INTRA);
2842
2843  if (!bAddedSmvp)
2844  {
2845    tmpCU = getPULeft(idx, uiPartIdxLB);
2846    bAddedSmvp = (tmpCU != NULL) && (tmpCU->getPredictionMode(idx) != MODE_INTRA);
2847  }
2848
2849  // Left predictor search
2850  bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_BELOW_LEFT);
2851  if (!bAdded) 
2852  {
2853    bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_LEFT );
2854  }
2855 
2856  if(!bAdded)
2857  {
2858    bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_BELOW_LEFT);
2859    if (!bAdded) 
2860    {
2861      xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_LEFT );
2862    }
2863  }
2864  // Above predictor search
2865  bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE_RIGHT);
2866
2867  if (!bAdded) 
2868  {
2869    bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE);
2870  }
2871
2872  if(!bAdded)
2873  {
2874    xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLT, MD_ABOVE_LEFT);
2875  }
2876
2877  if (!bAddedSmvp)
2878  {
2879    bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE_RIGHT);
2880    if (!bAdded) 
2881    {
2882      bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE);
2883    }
2884
2885    if(!bAdded)
2886    {
2887      xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLT, MD_ABOVE_LEFT);
2888    }
2889  }
2890 
2891  if ( pInfo->iN == 2 )
2892  {
2893    if ( pInfo->m_acMvCand[ 0 ] == pInfo->m_acMvCand[ 1 ] )
2894    {
2895      pInfo->iN = 1;
2896    }
2897  }
2898
2899  if ( getSlice()->getEnableTMVPFlag() )
2900  {
2901    // Get Temporal Motion Predictor
2902    Int iRefIdx_Col = iRefIdx;
2903    TComMv cColMv;
2904    UInt uiPartIdxRB;
2905    UInt uiAbsPartIdx; 
2906    UInt uiAbsPartAddr;
2907
2908    deriveRightBottomIdx( uiPartIdx, uiPartIdxRB );
2909    uiAbsPartAddr = m_uiAbsIdxInLCU + uiPartAddr;
2910
2911    //----  co-located RightBottom Temporal Predictor (H) ---//
2912    uiAbsPartIdx = g_auiZscanToRaster[uiPartIdxRB];
2913    Int uiLCUIdx = -1;
2914    if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdx] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
2915    {
2916    }
2917    else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdx] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
2918    {
2919    }
2920    else
2921    {
2922      if ( ( uiAbsPartIdx % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
2923        ( uiAbsPartIdx / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
2924      {
2925        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdx + uiNumPartInCUWidth + 1 ];
2926        uiLCUIdx = getAddr();
2927      }
2928      else if ( uiAbsPartIdx % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
2929      {
2930        uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdx + uiNumPartInCUWidth + 1) % m_pcPic->getNumPartInCU() ];
2931      }
2932      else if ( uiAbsPartIdx / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
2933      {
2934        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdx + 1 ];
2935        uiLCUIdx = getAddr() + 1;
2936      }
2937      else //is the right bottom corner of LCU                       
2938      {
2939        uiAbsPartAddr = 0;
2940      }
2941    }
2942    if ( uiLCUIdx >= 0 && xGetColMVP( eRefPicList, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx_Col
2943    ) )
2944    {
2945      pInfo->m_acMvCand[pInfo->iN++] = cColMv;
2946    }
2947    else 
2948    {
2949      UInt uiPartIdxCenter;
2950      UInt uiCurLCUIdx = getAddr();
2951      xDeriveCenterIdx( uiPartIdx, uiPartIdxCenter );
2952      if (xGetColMVP( eRefPicList, uiCurLCUIdx, uiPartIdxCenter,  cColMv, iRefIdx_Col
2953      ))
2954      {
2955        pInfo->m_acMvCand[pInfo->iN++] = cColMv;
2956      }
2957    }
2958    //----  co-located RightBottom Temporal Predictor  ---//
2959  }
2960
2961  if (pInfo->iN > AMVP_MAX_NUM_CANDS)
2962  {
2963    pInfo->iN = AMVP_MAX_NUM_CANDS;
2964  }
2965  while (pInfo->iN < AMVP_MAX_NUM_CANDS)
2966  {
2967      pInfo->m_acMvCand[pInfo->iN].set(0,0);
2968      pInfo->iN++;
2969  }
2970  return ;
2971}
2972
2973Bool TComDataCU::isBipredRestriction(UInt puIdx)
2974{
2975  Int width = 0;
2976  Int height = 0;
2977  UInt partAddr;
2978 
2979
2980  getPartIndexAndSize( puIdx, partAddr, width, height );
2981  if ( getWidth(0) == 8 && (width < 8 || height < 8) )
2982  {
2983    return true;
2984  }
2985  return false;
2986}
2987
2988Void TComDataCU::clipMv    (TComMv&  rcMv)
2989{
2990  Int  iMvShift = 2;
2991  Int iOffset = 8;
2992  Int iHorMax = ( m_pcSlice->getSPS()->getPicWidthInLumaSamples() + iOffset - m_uiCUPelX - 1 ) << iMvShift;
2993  Int iHorMin = (       -(Int)g_uiMaxCUWidth - iOffset - (Int)m_uiCUPelX + 1 ) << iMvShift;
2994 
2995  Int iVerMax = ( m_pcSlice->getSPS()->getPicHeightInLumaSamples() + iOffset - m_uiCUPelY - 1 ) << iMvShift;
2996  Int iVerMin = (       -(Int)g_uiMaxCUHeight - iOffset - (Int)m_uiCUPelY + 1 ) << iMvShift;
2997 
2998  rcMv.setHor( min (iHorMax, max (iHorMin, rcMv.getHor())) );
2999  rcMv.setVer( min (iVerMax, max (iVerMin, rcMv.getVer())) );
3000}
3001
3002#if SONY_MV_V_CONST_C0078
3003Void TComDataCU::checkMV_V (TComMv&  rcMv,  RefPicList eRefPicList, int iRefIdx )
3004{
3005  if ( getSlice()->getSPS()->getInterViewMvVertConstraintFlag() )
3006  {
3007    if ( getSlice()->getRefPic( eRefPicList, iRefIdx )->getPOC() == getSlice()->getPOC() )
3008    {
3009        //When inter_view_mv_vert_constraint_flag is equal to 1,
3010        //the vertical component of the motion vectors used for inter-layer prediction
3011        //shall be equal to or less than 56 in units of luma samples
3012        assert ( rcMv.getVer() <= (56<<2) );
3013    }
3014  }
3015}
3016#endif
3017
3018UInt TComDataCU::getIntraSizeIdx(UInt uiAbsPartIdx)
3019{
3020  UInt uiShift = ( m_pePartSize[uiAbsPartIdx]==SIZE_NxN ? 1 : 0 );
3021 
3022  UChar uiWidth = m_puhWidth[uiAbsPartIdx]>>uiShift;
3023  UInt  uiCnt = 0;
3024  while( uiWidth )
3025  {
3026    uiCnt++;
3027    uiWidth>>=1;
3028  }
3029  uiCnt-=2;
3030  return uiCnt > 6 ? 6 : uiCnt;
3031}
3032
3033Void TComDataCU::clearCbf( UInt uiIdx, TextType eType, UInt uiNumParts )
3034{
3035  ::memset( &m_puhCbf[g_aucConvertTxtTypeToIdx[eType]][uiIdx], 0, sizeof(UChar)*uiNumParts);
3036}
3037
3038/** Set a I_PCM flag for all sub-partitions of a partition.
3039 * \param bIpcmFlag I_PCM flag
3040 * \param uiAbsPartIdx patition index
3041 * \param uiDepth CU depth
3042 * \returns Void
3043 */
3044Void TComDataCU::setIPCMFlagSubParts  (Bool bIpcmFlag, UInt uiAbsPartIdx, UInt uiDepth)
3045{
3046  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
3047
3048  memset(m_pbIPCMFlag + uiAbsPartIdx, bIpcmFlag, sizeof(Bool)*uiCurrPartNumb );
3049}
3050
3051/** Test whether the current block is skipped
3052 * \param uiPartIdx Block index
3053 * \returns Flag indicating whether the block is skipped
3054 */
3055Bool TComDataCU::isSkipped( UInt uiPartIdx )
3056{
3057  return ( getSkipFlag( uiPartIdx ) );
3058}
3059
3060
3061// ====================================================================================================================
3062// Protected member functions
3063// ====================================================================================================================
3064
3065Bool TComDataCU::xAddMVPCand( AMVPInfo* pInfo, RefPicList eRefPicList, Int iRefIdx, UInt uiPartUnitIdx, MVP_DIR eDir )
3066{
3067  TComDataCU* pcTmpCU = NULL;
3068  UInt uiIdx;
3069  switch( eDir )
3070  {
3071    case MD_LEFT:
3072    {
3073      pcTmpCU = getPULeft(uiIdx, uiPartUnitIdx);
3074      break;
3075    }
3076    case MD_ABOVE:
3077    {
3078      pcTmpCU = getPUAbove(uiIdx, uiPartUnitIdx );
3079      break;
3080    }
3081    case MD_ABOVE_RIGHT:
3082    {
3083      pcTmpCU = getPUAboveRight(uiIdx, uiPartUnitIdx);
3084      break;
3085    }
3086    case MD_BELOW_LEFT:
3087    {
3088      pcTmpCU = getPUBelowLeft(uiIdx, uiPartUnitIdx);
3089      break;
3090    }
3091    case MD_ABOVE_LEFT:
3092    {
3093      pcTmpCU = getPUAboveLeft(uiIdx, uiPartUnitIdx);
3094      break;
3095    }
3096    default:
3097    {
3098      break;
3099    }
3100  }
3101
3102  if ( pcTmpCU == NULL )
3103  {
3104    return false;
3105  }
3106 
3107  if ( pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) >= 0 && m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getPOC() == pcTmpCU->getSlice()->getRefPOC( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) ))
3108  {
3109    TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
3110   
3111    pInfo->m_acMvCand[ pInfo->iN++] = cMvPred;
3112    return true;
3113  }
3114
3115  RefPicList eRefPicList2nd = REF_PIC_LIST_0;
3116  if(       eRefPicList == REF_PIC_LIST_0 )
3117  {
3118    eRefPicList2nd = REF_PIC_LIST_1;
3119  }
3120  else if ( eRefPicList == REF_PIC_LIST_1)
3121  {
3122    eRefPicList2nd = REF_PIC_LIST_0;
3123  }
3124
3125
3126  Int iCurrRefPOC = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getPOC();
3127  Int iNeibRefPOC;
3128
3129
3130  if( pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) >= 0 )
3131  {
3132    iNeibRefPOC = pcTmpCU->getSlice()->getRefPOC( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) );
3133    if( iNeibRefPOC == iCurrRefPOC ) // Same Reference Frame But Diff List//
3134    {
3135      TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList2nd)->getMv(uiIdx);
3136      pInfo->m_acMvCand[ pInfo->iN++] = cMvPred;
3137      return true;
3138    }
3139  }
3140  return false;
3141}
3142
3143/**
3144 * \param pInfo
3145 * \param eRefPicList
3146 * \param iRefIdx
3147 * \param uiPartUnitIdx
3148 * \param eDir
3149 * \returns Bool
3150 */
3151Bool TComDataCU::xAddMVPCandOrder( AMVPInfo* pInfo, RefPicList eRefPicList, Int iRefIdx, UInt uiPartUnitIdx, MVP_DIR eDir )
3152{
3153  TComDataCU* pcTmpCU = NULL;
3154  UInt uiIdx;
3155  switch( eDir )
3156  {
3157  case MD_LEFT:
3158    {
3159      pcTmpCU = getPULeft(uiIdx, uiPartUnitIdx);
3160      break;
3161    }
3162  case MD_ABOVE:
3163    {
3164      pcTmpCU = getPUAbove(uiIdx, uiPartUnitIdx);
3165      break;
3166    }
3167  case MD_ABOVE_RIGHT:
3168    {
3169      pcTmpCU = getPUAboveRight(uiIdx, uiPartUnitIdx);
3170      break;
3171    }
3172  case MD_BELOW_LEFT:
3173    {
3174      pcTmpCU = getPUBelowLeft(uiIdx, uiPartUnitIdx);
3175      break;
3176    }
3177  case MD_ABOVE_LEFT:
3178    {
3179      pcTmpCU = getPUAboveLeft(uiIdx, uiPartUnitIdx);
3180      break;
3181    }
3182  default:
3183    {
3184      break;
3185    }
3186  }
3187
3188  if ( pcTmpCU == NULL ) 
3189  {
3190    return false;
3191  }
3192 
3193  RefPicList eRefPicList2nd = REF_PIC_LIST_0;
3194  if(       eRefPicList == REF_PIC_LIST_0 )
3195  {
3196    eRefPicList2nd = REF_PIC_LIST_1;
3197  }
3198  else if ( eRefPicList == REF_PIC_LIST_1)
3199  {
3200    eRefPicList2nd = REF_PIC_LIST_0;
3201  }
3202
3203  Int iCurrPOC = m_pcSlice->getPOC();
3204  Int iCurrRefPOC = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getPOC();
3205  Int iNeibPOC = iCurrPOC;
3206  Int iNeibRefPOC;
3207
3208  Bool bIsCurrRefLongTerm = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getIsLongTerm();
3209  Bool bIsNeibRefLongTerm = false;
3210  //---------------  V1 (END) ------------------//
3211  if( pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) >= 0)
3212  {
3213    iNeibRefPOC = pcTmpCU->getSlice()->getRefPOC( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) );
3214    TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
3215    TComMv rcMv;
3216
3217    bIsNeibRefLongTerm = pcTmpCU->getSlice()->getRefPic( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) )->getIsLongTerm();
3218    if ( bIsCurrRefLongTerm == bIsNeibRefLongTerm ) 
3219    {
3220    if ( bIsCurrRefLongTerm || bIsNeibRefLongTerm )
3221    {
3222      rcMv = cMvPred;
3223    }
3224    else
3225    {
3226      Int iScale = xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
3227      if ( iScale == 4096 )
3228      {
3229        rcMv = cMvPred;
3230      }
3231      else
3232      {
3233        rcMv = cMvPred.scaleMv( iScale );
3234      }
3235    }
3236    pInfo->m_acMvCand[ pInfo->iN++] = rcMv;
3237    return true;
3238    }
3239  }
3240  //---------------------- V2(END) --------------------//
3241  if( pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) >= 0)
3242  {
3243    iNeibRefPOC = pcTmpCU->getSlice()->getRefPOC( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) );
3244    TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList2nd)->getMv(uiIdx);
3245    TComMv rcMv;
3246
3247    bIsNeibRefLongTerm = pcTmpCU->getSlice()->getRefPic( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) )->getIsLongTerm();
3248    if ( bIsCurrRefLongTerm == bIsNeibRefLongTerm ) 
3249    {
3250    if ( bIsCurrRefLongTerm || bIsNeibRefLongTerm )
3251    {
3252      rcMv = cMvPred;
3253    }
3254    else
3255    {
3256      Int iScale = xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
3257      if ( iScale == 4096 )
3258      {
3259        rcMv = cMvPred;
3260      }
3261      else
3262      {
3263        rcMv = cMvPred.scaleMv( iScale );
3264      }
3265    }
3266    pInfo->m_acMvCand[ pInfo->iN++] = rcMv;
3267    return true;
3268    }
3269  }
3270  //---------------------- V3(END) --------------------//
3271  return false;
3272}
3273
3274/**
3275 * \param eRefPicList
3276 * \param uiCUAddr
3277 * \param uiPartUnitIdx
3278 * \param riRefIdx
3279 * \returns Bool
3280 */
3281Bool TComDataCU::xGetColMVP( RefPicList eRefPicList, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv, Int& riRefIdx
3282  )
3283{
3284  UInt uiAbsPartAddr = uiPartUnitIdx;
3285
3286  RefPicList  eColRefPicList;
3287  Int iColPOC, iColRefPOC, iCurrPOC, iCurrRefPOC, iScale;
3288  TComMv cColMv;
3289
3290  // use coldir.
3291  TComPic *pColPic = getSlice()->getRefPic( RefPicList(getSlice()->isInterB() ? 1-getSlice()->getColFromL0Flag() : 0), getSlice()->getColRefIdx());
3292  TComDataCU *pColCU = pColPic->getCU( uiCUAddr );
3293  if(pColCU->getPic()==0||pColCU->getPartitionSize(uiPartUnitIdx)==SIZE_NONE)
3294  {
3295    return false;
3296  }
3297  iCurrPOC = m_pcSlice->getPOC();   
3298  iColPOC = pColCU->getSlice()->getPOC(); 
3299
3300  if (pColCU->isIntra(uiAbsPartAddr))
3301  {
3302    return false;
3303  }
3304  eColRefPicList = getSlice()->getCheckLDC() ? eRefPicList : RefPicList(getSlice()->getColFromL0Flag());
3305
3306  Int iColRefIdx = pColCU->getCUMvField(RefPicList(eColRefPicList))->getRefIdx(uiAbsPartAddr);
3307
3308  if (iColRefIdx < 0 )
3309  {
3310    eColRefPicList = RefPicList(1 - eColRefPicList);
3311    iColRefIdx = pColCU->getCUMvField(RefPicList(eColRefPicList))->getRefIdx(uiAbsPartAddr);
3312
3313    if (iColRefIdx < 0 )
3314    {
3315      return false;
3316    }
3317  }
3318
3319  // Scale the vector.
3320  iColRefPOC = pColCU->getSlice()->getRefPOC(eColRefPicList, iColRefIdx);
3321  cColMv = pColCU->getCUMvField(eColRefPicList)->getMv(uiAbsPartAddr);
3322
3323  iCurrRefPOC = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getPOC();
3324  Bool bIsCurrRefLongTerm = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getIsLongTerm();
3325  Bool bIsColRefLongTerm = pColCU->getSlice()->getIsUsedAsLongTerm(eColRefPicList, iColRefIdx);
3326
3327  if ( bIsCurrRefLongTerm != bIsColRefLongTerm ) 
3328  {
3329      return false;
3330  }
3331
3332  if ( bIsCurrRefLongTerm || bIsColRefLongTerm ) // CY: this condition equals to both bIsCurrRefLongTerm and bIsColRefLongTerm being 1
3333  {
3334       rcMv = cColMv;
3335  }
3336  else // CY: both bIsCurrRefLongTerm and bIsColRefLongTerm are 0
3337  {
3338    iScale = xGetDistScaleFactor(iCurrPOC, iCurrRefPOC, iColPOC, iColRefPOC);
3339    if ( iScale == 4096 )
3340    {
3341      rcMv = cColMv;
3342    }
3343    else
3344    {
3345      rcMv = cColMv.scaleMv( iScale );
3346    }
3347  }
3348  return true;
3349}
3350
3351UInt TComDataCU::xGetMvdBits(TComMv cMvd)
3352{
3353  return ( xGetComponentBits(cMvd.getHor()) + xGetComponentBits(cMvd.getVer()) );
3354}
3355
3356UInt TComDataCU::xGetComponentBits(Int iVal)
3357{
3358  UInt uiLength = 1;
3359  UInt uiTemp   = ( iVal <= 0) ? (-iVal<<1)+1: (iVal<<1);
3360 
3361  assert ( uiTemp );
3362 
3363  while ( 1 != uiTemp )
3364  {
3365    uiTemp >>= 1;
3366    uiLength += 2;
3367  }
3368 
3369  return uiLength;
3370}
3371
3372
3373Int TComDataCU::xGetDistScaleFactor(Int iCurrPOC, Int iCurrRefPOC, Int iColPOC, Int iColRefPOC)
3374{
3375  Int iDiffPocD = iColPOC - iColRefPOC;
3376  Int iDiffPocB = iCurrPOC - iCurrRefPOC;
3377 
3378  if( iDiffPocD == iDiffPocB )
3379  {
3380    return 4096;
3381  }
3382  else
3383  {
3384    Int iTDB      = Clip3( -128, 127, iDiffPocB );
3385    Int iTDD      = Clip3( -128, 127, iDiffPocD );
3386    Int iX        = (0x4000 + abs(iTDD/2)) / iTDD;
3387    Int iScale    = Clip3( -4096, 4095, (iTDB * iX + 32) >> 6 );
3388    return iScale;
3389  }
3390}
3391
3392/**
3393 * \param eCUMode
3394 * \param uiPartIdx
3395 * \param ruiPartIdxCenter
3396 * \returns Void
3397 */
3398Void TComDataCU::xDeriveCenterIdx( UInt uiPartIdx, UInt& ruiPartIdxCenter )
3399{
3400  UInt uiPartAddr;
3401  Int  iPartWidth;
3402  Int  iPartHeight;
3403  getPartIndexAndSize( uiPartIdx, uiPartAddr, iPartWidth, iPartHeight);
3404 
3405  ruiPartIdxCenter = m_uiAbsIdxInLCU+uiPartAddr; // partition origin.
3406  ruiPartIdxCenter = g_auiRasterToZscan[ g_auiZscanToRaster[ ruiPartIdxCenter ]
3407                                        + ( iPartHeight/m_pcPic->getMinCUHeight()  )/2*m_pcPic->getNumPartInWidth()
3408                                        + ( iPartWidth/m_pcPic->getMinCUWidth()  )/2];
3409}
3410Void TComDataCU::compressMV()
3411{
3412  Int scaleFactor = 4 * AMVP_DECIMATION_FACTOR / m_unitSize;
3413  if (scaleFactor > 0)
3414  {
3415    m_acCUMvField[0].compress(m_pePredMode, scaleFactor);
3416    m_acCUMvField[1].compress(m_pePredMode, scaleFactor);   
3417  }
3418}
3419
3420UInt TComDataCU::getCoefScanIdx(UInt uiAbsPartIdx, UInt uiWidth, Bool bIsLuma, Bool bIsIntra)
3421{
3422  UInt uiCTXIdx;
3423  UInt uiScanIdx;
3424  UInt uiDirMode;
3425
3426  if ( !bIsIntra ) 
3427  {
3428    uiScanIdx = SCAN_DIAG;
3429    return uiScanIdx;
3430  }
3431
3432  switch(uiWidth)
3433  {
3434    case  2: uiCTXIdx = 6; break;
3435    case  4: uiCTXIdx = 5; break;
3436    case  8: uiCTXIdx = 4; break;
3437    case 16: uiCTXIdx = 3; break;
3438    case 32: uiCTXIdx = 2; break;
3439    case 64: uiCTXIdx = 1; break;
3440    default: uiCTXIdx = 0; break;
3441  }
3442
3443  if ( bIsLuma )
3444  {
3445    uiDirMode = getLumaIntraDir(uiAbsPartIdx);
3446    uiScanIdx = SCAN_DIAG;
3447    if (uiCTXIdx >3 && uiCTXIdx < 6) //if multiple scans supported for transform size
3448    {
3449      uiScanIdx = abs((Int) uiDirMode - VER_IDX) < 5 ? SCAN_HOR : (abs((Int)uiDirMode - HOR_IDX) < 5 ? SCAN_VER : SCAN_DIAG);
3450    }
3451  }
3452  else
3453  {
3454    uiDirMode = getChromaIntraDir(uiAbsPartIdx);
3455    if( uiDirMode == DM_CHROMA_IDX )
3456    {
3457      // get number of partitions in current CU
3458      UInt depth = getDepth(uiAbsPartIdx);
3459      UInt numParts = getPic()->getNumPartInCU() >> (2 * depth);
3460     
3461      // get luma mode from upper-left corner of current CU
3462      uiDirMode = getLumaIntraDir((uiAbsPartIdx/numParts)*numParts);
3463    }
3464    uiScanIdx = SCAN_DIAG;
3465    if (uiCTXIdx >4 && uiCTXIdx < 7) //if multiple scans supported for transform size
3466    {
3467      uiScanIdx = abs((Int) uiDirMode - VER_IDX) < 5 ? SCAN_HOR : (abs((Int)uiDirMode - HOR_IDX) < 5 ? SCAN_VER : SCAN_DIAG);
3468    }
3469  }
3470
3471  return uiScanIdx;
3472}
3473
3474UInt TComDataCU::getSCUAddr()
3475{ 
3476  return getPic()->getPicSym()->getInverseCUOrderMap(m_uiCUAddr)*(1<<(m_pcSlice->getSPS()->getMaxCUDepth()<<1))+m_uiAbsIdxInLCU; 
3477}
3478
3479
3480
3481
3482
3483
3484
3485
3486//! \}
Note: See TracBrowser for help on using the repository browser.