source: SHVCSoftware/branches/SHM-2.1-dev/source/Lib/TLibCommon/TComDataCU.cpp @ 244

Last change on this file since 244 was 212, checked in by canon, 12 years ago

integration M0115 - Fast Intra Decision - cfg parameter: FIS (off by default)
edouard.francois@…

File size: 158.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-2013, 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
63  m_pePartSize         = NULL;
64  m_pePredMode         = NULL;
65  m_CUTransquantBypass = NULL;
66  m_puhWidth           = NULL;
67  m_puhHeight          = NULL;
68  m_phQP               = NULL;
69  m_pbMergeFlag        = NULL;
70  m_puhMergeIndex      = NULL;
71  m_puhLumaIntraDir    = NULL;
72  m_puhChromaIntraDir  = NULL;
73  m_puhInterDir        = NULL;
74  m_puhTrIdx           = NULL;
75  m_puhTransformSkip[0] = NULL;
76  m_puhTransformSkip[1] = NULL;
77  m_puhTransformSkip[2] = NULL;
78  m_puhCbf[0]          = NULL;
79  m_puhCbf[1]          = NULL;
80  m_puhCbf[2]          = NULL;
81  m_pcTrCoeffY         = NULL;
82  m_pcTrCoeffCb        = NULL;
83  m_pcTrCoeffCr        = NULL;
84#if ADAPTIVE_QP_SELECTION 
85  m_ArlCoeffIsAliasedAllocation = false;
86  m_pcArlCoeffY        = NULL;
87  m_pcArlCoeffCb       = NULL;
88  m_pcArlCoeffCr       = NULL;
89#endif
90 
91  m_pbIPCMFlag         = NULL;
92  m_pcIPCMSampleY      = NULL;
93  m_pcIPCMSampleCb     = NULL;
94  m_pcIPCMSampleCr     = NULL;
95
96  m_pcPattern          = NULL;
97 
98  m_pcCUAboveLeft      = NULL;
99  m_pcCUAboveRight     = NULL;
100  m_pcCUAbove          = NULL;
101  m_pcCULeft           = NULL;
102 
103  m_apcCUColocated[0]  = NULL;
104  m_apcCUColocated[1]  = NULL;
105 
106  m_apiMVPIdx[0]       = NULL;
107  m_apiMVPIdx[1]       = NULL;
108  m_apiMVPNum[0]       = NULL;
109  m_apiMVPNum[1]       = NULL;
110
111  m_bDecSubCu          = false;
112  m_sliceStartCU        = 0;
113  m_sliceSegmentStartCU = 0;
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
142    m_pePartSize         = new Char[ uiNumPartition ];
143    memset( m_pePartSize, SIZE_NONE,uiNumPartition * sizeof( *m_pePartSize ) );
144    m_pePredMode         = new Char[ uiNumPartition ];
145    m_CUTransquantBypass = new Bool[ uiNumPartition ];
146    m_pbMergeFlag        = (Bool*  )xMalloc(Bool,   uiNumPartition);
147    m_puhMergeIndex      = (UChar* )xMalloc(UChar,  uiNumPartition);
148    m_puhLumaIntraDir    = (UChar* )xMalloc(UChar,  uiNumPartition);
149    m_puhChromaIntraDir  = (UChar* )xMalloc(UChar,  uiNumPartition);
150    m_puhInterDir        = (UChar* )xMalloc(UChar,  uiNumPartition);
151   
152    m_puhTrIdx           = (UChar* )xMalloc(UChar,  uiNumPartition);
153    m_puhTransformSkip[0] = (UChar* )xMalloc(UChar,  uiNumPartition);
154    m_puhTransformSkip[1] = (UChar* )xMalloc(UChar,  uiNumPartition);
155    m_puhTransformSkip[2] = (UChar* )xMalloc(UChar,  uiNumPartition);
156
157    m_puhCbf[0]          = (UChar* )xMalloc(UChar,  uiNumPartition);
158    m_puhCbf[1]          = (UChar* )xMalloc(UChar,  uiNumPartition);
159    m_puhCbf[2]          = (UChar* )xMalloc(UChar,  uiNumPartition);
160   
161    m_apiMVPIdx[0]       = new Char[ uiNumPartition ];
162    m_apiMVPIdx[1]       = new Char[ uiNumPartition ];
163    m_apiMVPNum[0]       = new Char[ uiNumPartition ];
164    m_apiMVPNum[1]       = new Char[ uiNumPartition ];
165    memset( m_apiMVPIdx[0], -1,uiNumPartition * sizeof( Char ) );
166    memset( m_apiMVPIdx[1], -1,uiNumPartition * sizeof( Char ) );
167   
168    m_pcTrCoeffY         = (TCoeff*)xMalloc(TCoeff, uiWidth*uiHeight);
169    m_pcTrCoeffCb        = (TCoeff*)xMalloc(TCoeff, uiWidth*uiHeight/4);
170    m_pcTrCoeffCr        = (TCoeff*)xMalloc(TCoeff, uiWidth*uiHeight/4);
171    memset( m_pcTrCoeffY, 0,uiWidth*uiHeight * sizeof( TCoeff ) );
172    memset( m_pcTrCoeffCb, 0,uiWidth*uiHeight/4 * sizeof( TCoeff ) );
173    memset( m_pcTrCoeffCr, 0,uiWidth*uiHeight/4 * sizeof( TCoeff ) );
174#if ADAPTIVE_QP_SELECTION   
175    if( bGlobalRMARLBuffer )
176    {
177      if( m_pcGlbArlCoeffY == NULL )
178      {
179        m_pcGlbArlCoeffY   = (Int*)xMalloc(Int, uiWidth*uiHeight);
180        m_pcGlbArlCoeffCb  = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
181        m_pcGlbArlCoeffCr  = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
182      }
183      m_pcArlCoeffY        = m_pcGlbArlCoeffY;
184      m_pcArlCoeffCb       = m_pcGlbArlCoeffCb;
185      m_pcArlCoeffCr       = m_pcGlbArlCoeffCr;
186      m_ArlCoeffIsAliasedAllocation = true;
187    }
188    else
189    {
190      m_pcArlCoeffY        = (Int*)xMalloc(Int, uiWidth*uiHeight);
191      m_pcArlCoeffCb       = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
192      m_pcArlCoeffCr       = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
193    }
194#endif
195   
196    m_pbIPCMFlag         = (Bool*  )xMalloc(Bool, uiNumPartition);
197    m_pcIPCMSampleY      = (Pel*   )xMalloc(Pel , uiWidth*uiHeight);
198    m_pcIPCMSampleCb     = (Pel*   )xMalloc(Pel , uiWidth*uiHeight/4);
199    m_pcIPCMSampleCr     = (Pel*   )xMalloc(Pel , uiWidth*uiHeight/4);
200
201    m_acCUMvField[0].create( uiNumPartition );
202    m_acCUMvField[1].create( uiNumPartition );
203   
204  }
205  else
206  {
207    m_acCUMvField[0].setNumPartition(uiNumPartition );
208    m_acCUMvField[1].setNumPartition(uiNumPartition );
209  }
210 
211  m_sliceStartCU        = (UInt*  )xMalloc(UInt, uiNumPartition);
212  m_sliceSegmentStartCU = (UInt*  )xMalloc(UInt, uiNumPartition);
213 
214  // create pattern memory
215  m_pcPattern            = (TComPattern*)xMalloc(TComPattern, 1);
216 
217  // create motion vector fields
218 
219  m_pcCUAboveLeft      = NULL;
220  m_pcCUAboveRight     = NULL;
221  m_pcCUAbove          = NULL;
222  m_pcCULeft           = NULL;
223 
224  m_apcCUColocated[0]  = NULL;
225  m_apcCUColocated[1]  = NULL;
226}
227
228Void TComDataCU::destroy()
229{
230  m_pcPic              = NULL;
231  m_pcSlice            = NULL;
232 
233  if ( m_pcPattern )
234  { 
235    xFree(m_pcPattern);
236    m_pcPattern = NULL;
237  }
238 
239  // encoder-side buffer free
240  if ( !m_bDecSubCu )
241  {
242    if ( m_phQP               ) { xFree(m_phQP);                m_phQP              = NULL; }
243    if ( m_puhDepth           ) { xFree(m_puhDepth);            m_puhDepth          = NULL; }
244    if ( m_puhWidth           ) { xFree(m_puhWidth);            m_puhWidth          = NULL; }
245    if ( m_puhHeight          ) { xFree(m_puhHeight);           m_puhHeight         = NULL; }
246
247    if ( m_skipFlag           ) { delete[] m_skipFlag;          m_skipFlag          = NULL; }
248
249    if ( m_pePartSize         ) { delete[] m_pePartSize;        m_pePartSize        = NULL; }
250    if ( m_pePredMode         ) { delete[] m_pePredMode;        m_pePredMode        = NULL; }
251    if ( m_CUTransquantBypass ) { delete[] m_CUTransquantBypass;m_CUTransquantBypass = NULL; }
252    if ( m_puhCbf[0]          ) { xFree(m_puhCbf[0]);           m_puhCbf[0]         = NULL; }
253    if ( m_puhCbf[1]          ) { xFree(m_puhCbf[1]);           m_puhCbf[1]         = NULL; }
254    if ( m_puhCbf[2]          ) { xFree(m_puhCbf[2]);           m_puhCbf[2]         = NULL; }
255    if ( m_puhInterDir        ) { xFree(m_puhInterDir);         m_puhInterDir       = NULL; }
256    if ( m_pbMergeFlag        ) { xFree(m_pbMergeFlag);         m_pbMergeFlag       = NULL; }
257    if ( m_puhMergeIndex      ) { xFree(m_puhMergeIndex);       m_puhMergeIndex     = NULL; }
258    if ( m_puhLumaIntraDir    ) { xFree(m_puhLumaIntraDir);     m_puhLumaIntraDir   = NULL; }
259    if ( m_puhChromaIntraDir  ) { xFree(m_puhChromaIntraDir);   m_puhChromaIntraDir = NULL; }
260    if ( m_puhTrIdx           ) { xFree(m_puhTrIdx);            m_puhTrIdx          = NULL; }
261    if ( m_puhTransformSkip[0]) { xFree(m_puhTransformSkip[0]); m_puhTransformSkip[0] = NULL; }
262    if ( m_puhTransformSkip[1]) { xFree(m_puhTransformSkip[1]); m_puhTransformSkip[1] = NULL; }
263    if ( m_puhTransformSkip[2]) { xFree(m_puhTransformSkip[2]); m_puhTransformSkip[2] = NULL; }
264    if ( m_pcTrCoeffY         ) { xFree(m_pcTrCoeffY);          m_pcTrCoeffY        = NULL; }
265    if ( m_pcTrCoeffCb        ) { xFree(m_pcTrCoeffCb);         m_pcTrCoeffCb       = NULL; }
266    if ( m_pcTrCoeffCr        ) { xFree(m_pcTrCoeffCr);         m_pcTrCoeffCr       = NULL; }
267#if ADAPTIVE_QP_SELECTION
268    if (!m_ArlCoeffIsAliasedAllocation)
269    {
270      xFree(m_pcArlCoeffY); m_pcArlCoeffY = 0;
271      xFree(m_pcArlCoeffCb); m_pcArlCoeffCb = 0;
272      xFree(m_pcArlCoeffCr); m_pcArlCoeffCr = 0;
273    }
274    if ( m_pcGlbArlCoeffY     ) { xFree(m_pcGlbArlCoeffY);      m_pcGlbArlCoeffY    = NULL; }
275    if ( m_pcGlbArlCoeffCb    ) { xFree(m_pcGlbArlCoeffCb);     m_pcGlbArlCoeffCb   = NULL; }
276    if ( m_pcGlbArlCoeffCr    ) { xFree(m_pcGlbArlCoeffCr);     m_pcGlbArlCoeffCr   = NULL; }
277#endif
278    if ( m_pbIPCMFlag         ) { xFree(m_pbIPCMFlag   );       m_pbIPCMFlag        = NULL; }
279    if ( m_pcIPCMSampleY      ) { xFree(m_pcIPCMSampleY);       m_pcIPCMSampleY     = NULL; }
280    if ( m_pcIPCMSampleCb     ) { xFree(m_pcIPCMSampleCb);      m_pcIPCMSampleCb    = NULL; }
281    if ( m_pcIPCMSampleCr     ) { xFree(m_pcIPCMSampleCr);      m_pcIPCMSampleCr    = NULL; }
282    if ( m_apiMVPIdx[0]       ) { delete[] m_apiMVPIdx[0];      m_apiMVPIdx[0]      = NULL; }
283    if ( m_apiMVPIdx[1]       ) { delete[] m_apiMVPIdx[1];      m_apiMVPIdx[1]      = NULL; }
284    if ( m_apiMVPNum[0]       ) { delete[] m_apiMVPNum[0];      m_apiMVPNum[0]      = NULL; }
285    if ( m_apiMVPNum[1]       ) { delete[] m_apiMVPNum[1];      m_apiMVPNum[1]      = NULL; }
286   
287    m_acCUMvField[0].destroy();
288    m_acCUMvField[1].destroy();
289   
290  }
291 
292  m_pcCUAboveLeft       = NULL;
293  m_pcCUAboveRight      = NULL;
294  m_pcCUAbove           = NULL;
295  m_pcCULeft            = NULL;
296 
297  m_apcCUColocated[0]   = NULL;
298  m_apcCUColocated[1]   = NULL;
299
300  if( m_sliceStartCU )
301  {
302    xFree(m_sliceStartCU);
303    m_sliceStartCU=NULL;
304  }
305  if(m_sliceSegmentStartCU )
306  {
307    xFree(m_sliceSegmentStartCU);
308    m_sliceSegmentStartCU=NULL;
309  }
310}
311
312const NDBFBlockInfo& NDBFBlockInfo::operator= (const NDBFBlockInfo& src)
313{
314  this->tileID = src.tileID;
315  this->sliceID= src.sliceID;
316  this->startSU= src.startSU;
317  this->endSU  = src.endSU;
318  this->widthSU= src.widthSU;
319  this->heightSU=src.heightSU;
320  this->posX   = src.posX;
321  this->posY   = src.posY;
322  this->width  = src.width;
323  this->height = src.height;
324  ::memcpy(this->isBorderAvailable, src.isBorderAvailable, sizeof(Bool)*((Int)NUM_SGU_BORDER));
325  this->allBordersAvailable = src.allBordersAvailable;
326
327  return *this;
328}
329
330
331// ====================================================================================================================
332// Public member functions
333// ====================================================================================================================
334
335// --------------------------------------------------------------------------------------------------------------------
336// Initialization
337// --------------------------------------------------------------------------------------------------------------------
338
339/**
340 - initialize top-level CU
341 - internal buffers are already created
342 - set values before encoding a CU
343 .
344 \param  pcPic     picture (TComPic) class pointer
345 \param  iCUAddr   CU address
346 */
347Void TComDataCU::initCU( TComPic* pcPic, UInt iCUAddr )
348{
349
350  m_pcPic              = pcPic;
351  m_pcSlice            = pcPic->getSlice(pcPic->getCurrSliceIdx());
352  m_uiCUAddr           = iCUAddr;
353  m_uiCUPelX           = ( iCUAddr % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth;
354  m_uiCUPelY           = ( iCUAddr / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight;
355  m_uiAbsIdxInLCU      = 0;
356  m_dTotalCost         = MAX_DOUBLE;
357  m_uiTotalDistortion  = 0;
358  m_uiTotalBits        = 0;
359  m_uiTotalBins        = 0;
360  m_uiNumPartition     = pcPic->getNumPartInCU();
361
362#if SVC_EXTENSION
363  m_layerId           = pcPic->getLayerId();
364#endif
365 
366  for(Int i=0; i<pcPic->getNumPartInCU(); i++)
367  {
368    if(pcPic->getPicSym()->getInverseCUOrderMap(iCUAddr)*pcPic->getNumPartInCU()+i>=getSlice()->getSliceCurStartCUAddr())
369    {
370      m_sliceStartCU[i]=getSlice()->getSliceCurStartCUAddr();
371    }
372    else
373    {
374      m_sliceStartCU[i]=pcPic->getCU(getAddr())->m_sliceStartCU[i];
375    }
376  }
377  for(Int i=0; i<pcPic->getNumPartInCU(); i++)
378  {
379    if(pcPic->getPicSym()->getInverseCUOrderMap(iCUAddr)*pcPic->getNumPartInCU()+i>=getSlice()->getSliceSegmentCurStartCUAddr())
380    {
381      m_sliceSegmentStartCU[i]=getSlice()->getSliceSegmentCurStartCUAddr();
382    }
383    else
384    {
385      m_sliceSegmentStartCU[i]=pcPic->getCU(getAddr())->m_sliceSegmentStartCU[i];
386    }
387  }
388
389  Int partStartIdx = getSlice()->getSliceSegmentCurStartCUAddr() - pcPic->getPicSym()->getInverseCUOrderMap(iCUAddr) * pcPic->getNumPartInCU();
390
391  Int numElements = min<Int>( partStartIdx, m_uiNumPartition );
392  for ( Int ui = 0; ui < numElements; ui++ )
393  {
394    TComDataCU * pcFrom = pcPic->getCU(getAddr());
395    m_skipFlag[ui]   = pcFrom->getSkipFlag(ui);
396    m_pePartSize[ui] = pcFrom->getPartitionSize(ui);
397    m_pePredMode[ui] = pcFrom->getPredictionMode(ui);
398    m_CUTransquantBypass[ui] = pcFrom->getCUTransquantBypass(ui);
399    m_puhDepth[ui] = pcFrom->getDepth(ui);
400    m_puhWidth  [ui] = pcFrom->getWidth(ui);
401    m_puhHeight [ui] = pcFrom->getHeight(ui);
402    m_puhTrIdx  [ui] = pcFrom->getTransformIdx(ui);
403    m_puhTransformSkip[0][ui] = pcFrom->getTransformSkip(ui,TEXT_LUMA);
404    m_puhTransformSkip[1][ui] = pcFrom->getTransformSkip(ui,TEXT_CHROMA_U);
405    m_puhTransformSkip[2][ui] = pcFrom->getTransformSkip(ui,TEXT_CHROMA_V);
406    m_apiMVPIdx[0][ui] = pcFrom->m_apiMVPIdx[0][ui];;
407    m_apiMVPIdx[1][ui] = pcFrom->m_apiMVPIdx[1][ui];
408    m_apiMVPNum[0][ui] = pcFrom->m_apiMVPNum[0][ui];
409    m_apiMVPNum[1][ui] = pcFrom->m_apiMVPNum[1][ui];
410    m_phQP[ui]=pcFrom->m_phQP[ui];
411    m_pbMergeFlag[ui]=pcFrom->m_pbMergeFlag[ui];
412    m_puhMergeIndex[ui]=pcFrom->m_puhMergeIndex[ui];
413    m_puhLumaIntraDir[ui]=pcFrom->m_puhLumaIntraDir[ui];
414    m_puhChromaIntraDir[ui]=pcFrom->m_puhChromaIntraDir[ui];
415    m_puhInterDir[ui]=pcFrom->m_puhInterDir[ui];
416    m_puhCbf[0][ui]=pcFrom->m_puhCbf[0][ui];
417    m_puhCbf[1][ui]=pcFrom->m_puhCbf[1][ui];
418    m_puhCbf[2][ui]=pcFrom->m_puhCbf[2][ui];
419    m_pbIPCMFlag[ui] = pcFrom->m_pbIPCMFlag[ui];
420  }
421 
422  Int firstElement = max<Int>( partStartIdx, 0 );
423  numElements = m_uiNumPartition - firstElement;
424 
425  if ( numElements > 0 )
426  {
427    memset( m_skipFlag          + firstElement, false,                    numElements * sizeof( *m_skipFlag ) );
428
429    memset( m_pePartSize        + firstElement, SIZE_NONE,                numElements * sizeof( *m_pePartSize ) );
430    memset( m_pePredMode        + firstElement, MODE_NONE,                numElements * sizeof( *m_pePredMode ) );
431    memset( m_CUTransquantBypass+ firstElement, false,                    numElements * sizeof( *m_CUTransquantBypass) );
432    memset( m_puhDepth          + firstElement, 0,                        numElements * sizeof( *m_puhDepth ) );
433    memset( m_puhTrIdx          + firstElement, 0,                        numElements * sizeof( *m_puhTrIdx ) );
434    memset( m_puhTransformSkip[0] + firstElement, 0,                      numElements * sizeof( *m_puhTransformSkip[0]) );
435    memset( m_puhTransformSkip[1] + firstElement, 0,                      numElements * sizeof( *m_puhTransformSkip[1]) );
436    memset( m_puhTransformSkip[2] + firstElement, 0,                      numElements * sizeof( *m_puhTransformSkip[2]) );
437    memset( m_puhWidth          + firstElement, g_uiMaxCUWidth,           numElements * sizeof( *m_puhWidth ) );
438    memset( m_puhHeight         + firstElement, g_uiMaxCUHeight,          numElements * sizeof( *m_puhHeight ) );
439    memset( m_apiMVPIdx[0]      + firstElement, -1,                       numElements * sizeof( *m_apiMVPIdx[0] ) );
440    memset( m_apiMVPIdx[1]      + firstElement, -1,                       numElements * sizeof( *m_apiMVPIdx[1] ) );
441    memset( m_apiMVPNum[0]      + firstElement, -1,                       numElements * sizeof( *m_apiMVPNum[0] ) );
442    memset( m_apiMVPNum[1]      + firstElement, -1,                       numElements * sizeof( *m_apiMVPNum[1] ) );
443    memset( m_phQP              + firstElement, getSlice()->getSliceQp(), numElements * sizeof( *m_phQP ) );
444    memset( m_pbMergeFlag       + firstElement, false,                    numElements * sizeof( *m_pbMergeFlag ) );
445    memset( m_puhMergeIndex     + firstElement, 0,                        numElements * sizeof( *m_puhMergeIndex ) );
446    memset( m_puhLumaIntraDir   + firstElement, DC_IDX,                   numElements * sizeof( *m_puhLumaIntraDir ) );
447    memset( m_puhChromaIntraDir + firstElement, 0,                        numElements * sizeof( *m_puhChromaIntraDir ) );
448    memset( m_puhInterDir       + firstElement, 0,                        numElements * sizeof( *m_puhInterDir ) );
449    memset( m_puhCbf[0]         + firstElement, 0,                        numElements * sizeof( *m_puhCbf[0] ) );
450    memset( m_puhCbf[1]         + firstElement, 0,                        numElements * sizeof( *m_puhCbf[1] ) );
451    memset( m_puhCbf[2]         + firstElement, 0,                        numElements * sizeof( *m_puhCbf[2] ) );
452    memset( m_pbIPCMFlag        + firstElement, false,                    numElements * sizeof( *m_pbIPCMFlag ) );
453  }
454 
455  UInt uiTmp = g_uiMaxCUWidth*g_uiMaxCUHeight;
456  if ( 0 >= partStartIdx ) 
457  {
458    m_acCUMvField[0].clearMvField();
459    m_acCUMvField[1].clearMvField();
460    memset( m_pcTrCoeffY , 0, sizeof( TCoeff ) * uiTmp );
461#if ADAPTIVE_QP_SELECTION
462    memset( m_pcArlCoeffY , 0, sizeof( Int ) * uiTmp ); 
463#endif
464    memset( m_pcIPCMSampleY , 0, sizeof( Pel ) * uiTmp );
465    uiTmp  >>= 2;
466    memset( m_pcTrCoeffCb, 0, sizeof( TCoeff ) * uiTmp );
467    memset( m_pcTrCoeffCr, 0, sizeof( TCoeff ) * uiTmp );
468#if ADAPTIVE_QP_SELECTION 
469    memset( m_pcArlCoeffCb, 0, sizeof( Int ) * uiTmp );
470    memset( m_pcArlCoeffCr, 0, sizeof( Int ) * uiTmp );
471#endif
472    memset( m_pcIPCMSampleCb , 0, sizeof( Pel ) * uiTmp );
473    memset( m_pcIPCMSampleCr , 0, sizeof( Pel ) * uiTmp );
474  }
475  else 
476  {
477    TComDataCU * pcFrom = pcPic->getCU(getAddr());
478    m_acCUMvField[0].copyFrom(&pcFrom->m_acCUMvField[0],m_uiNumPartition,0);
479    m_acCUMvField[1].copyFrom(&pcFrom->m_acCUMvField[1],m_uiNumPartition,0);
480    for(Int i=0; i<uiTmp; i++)
481    {
482      m_pcTrCoeffY[i]=pcFrom->m_pcTrCoeffY[i];
483#if ADAPTIVE_QP_SELECTION
484      m_pcArlCoeffY[i]=pcFrom->m_pcArlCoeffY[i];
485#endif
486      m_pcIPCMSampleY[i]=pcFrom->m_pcIPCMSampleY[i];
487    }
488    for(Int i=0; i<(uiTmp>>2); i++)
489    {
490      m_pcTrCoeffCb[i]=pcFrom->m_pcTrCoeffCb[i];
491      m_pcTrCoeffCr[i]=pcFrom->m_pcTrCoeffCr[i];
492#if ADAPTIVE_QP_SELECTION
493      m_pcArlCoeffCb[i]=pcFrom->m_pcArlCoeffCb[i];
494      m_pcArlCoeffCr[i]=pcFrom->m_pcArlCoeffCr[i];
495#endif
496      m_pcIPCMSampleCb[i]=pcFrom->m_pcIPCMSampleCb[i];
497      m_pcIPCMSampleCr[i]=pcFrom->m_pcIPCMSampleCr[i];
498    }
499  }
500
501  // Setting neighbor CU
502  m_pcCULeft        = NULL;
503  m_pcCUAbove       = NULL;
504  m_pcCUAboveLeft   = NULL;
505  m_pcCUAboveRight  = NULL;
506
507  m_apcCUColocated[0] = NULL;
508  m_apcCUColocated[1] = NULL;
509
510  UInt uiWidthInCU = pcPic->getFrameWidthInCU();
511  if ( m_uiCUAddr % uiWidthInCU )
512  {
513    m_pcCULeft = pcPic->getCU( m_uiCUAddr - 1 );
514  }
515
516  if ( m_uiCUAddr / uiWidthInCU )
517  {
518    m_pcCUAbove = pcPic->getCU( m_uiCUAddr - uiWidthInCU );
519  }
520
521  if ( m_pcCULeft && m_pcCUAbove )
522  {
523    m_pcCUAboveLeft = pcPic->getCU( m_uiCUAddr - uiWidthInCU - 1 );
524  }
525
526  if ( m_pcCUAbove && ( (m_uiCUAddr%uiWidthInCU) < (uiWidthInCU-1) )  )
527  {
528    m_pcCUAboveRight = pcPic->getCU( m_uiCUAddr - uiWidthInCU + 1 );
529  }
530
531  if ( getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) > 0 )
532  {
533    m_apcCUColocated[0] = getSlice()->getRefPic( REF_PIC_LIST_0, 0)->getCU( m_uiCUAddr );
534  }
535
536  if ( getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) > 0 )
537  {
538    m_apcCUColocated[1] = getSlice()->getRefPic( REF_PIC_LIST_1, 0)->getCU( m_uiCUAddr );
539  }
540}
541
542/** initialize prediction data with enabling sub-LCU-level delta QP
543*\param  uiDepth  depth of the current CU
544*\param  qp     qp for the current CU
545*- set CU width and CU height according to depth
546*- set qp value according to input qp
547*- set last-coded qp value according to input last-coded qp
548*/
549Void TComDataCU::initEstData( UInt uiDepth, Int qp )
550{
551  m_dTotalCost         = MAX_DOUBLE;
552  m_uiTotalDistortion  = 0;
553  m_uiTotalBits        = 0;
554  m_uiTotalBins        = 0;
555
556  UChar uhWidth  = g_uiMaxCUWidth  >> uiDepth;
557  UChar uhHeight = g_uiMaxCUHeight >> uiDepth;
558
559  for (UInt ui = 0; ui < m_uiNumPartition; ui++)
560  {
561    if(getPic()->getPicSym()->getInverseCUOrderMap(getAddr())*m_pcPic->getNumPartInCU()+m_uiAbsIdxInLCU+ui >= getSlice()->getSliceSegmentCurStartCUAddr())
562    {
563      m_apiMVPIdx[0][ui] = -1;
564      m_apiMVPIdx[1][ui] = -1;
565      m_apiMVPNum[0][ui] = -1;
566      m_apiMVPNum[1][ui] = -1;
567      m_puhDepth  [ui] = uiDepth;
568      m_puhWidth  [ui] = uhWidth;
569      m_puhHeight [ui] = uhHeight;
570      m_puhTrIdx  [ui] = 0;
571      m_puhTransformSkip[0][ui] = 0;
572      m_puhTransformSkip[1][ui] = 0;
573      m_puhTransformSkip[2][ui] = 0;
574      m_skipFlag[ui]   = false;
575      m_pePartSize[ui] = SIZE_NONE;
576      m_pePredMode[ui] = MODE_NONE;
577      m_CUTransquantBypass[ui] = false;
578      m_pbIPCMFlag[ui] = 0;
579      m_phQP[ui] = qp;
580      m_pbMergeFlag[ui] = 0;
581      m_puhMergeIndex[ui] = 0;
582      m_puhLumaIntraDir[ui] = DC_IDX;
583      m_puhChromaIntraDir[ui] = 0;
584      m_puhInterDir[ui] = 0;
585      m_puhCbf[0][ui] = 0;
586      m_puhCbf[1][ui] = 0;
587      m_puhCbf[2][ui] = 0;
588    }
589  }
590
591  UInt uiTmp = uhWidth*uhHeight;
592
593  if(getPic()->getPicSym()->getInverseCUOrderMap(getAddr())*m_pcPic->getNumPartInCU()+m_uiAbsIdxInLCU >= getSlice()->getSliceSegmentCurStartCUAddr())
594  {
595    m_acCUMvField[0].clearMvField();
596    m_acCUMvField[1].clearMvField();
597    uiTmp = uhWidth*uhHeight;
598   
599    memset( m_pcTrCoeffY,    0, uiTmp * sizeof( *m_pcTrCoeffY    ) );
600#if ADAPTIVE_QP_SELECTION
601    memset( m_pcArlCoeffY ,  0, uiTmp * sizeof( *m_pcArlCoeffY   ) );
602#endif
603    memset( m_pcIPCMSampleY, 0, uiTmp * sizeof( *m_pcIPCMSampleY ) );
604
605    uiTmp>>=2;
606    memset( m_pcTrCoeffCb,    0, uiTmp * sizeof( *m_pcTrCoeffCb    ) );
607    memset( m_pcTrCoeffCr,    0, uiTmp * sizeof( *m_pcTrCoeffCr    ) );
608#if ADAPTIVE_QP_SELECTION 
609    memset( m_pcArlCoeffCb,   0, uiTmp * sizeof( *m_pcArlCoeffCb   ) );
610    memset( m_pcArlCoeffCr,   0, uiTmp * sizeof( *m_pcArlCoeffCr   ) );
611#endif
612    memset( m_pcIPCMSampleCb, 0, uiTmp * sizeof( *m_pcIPCMSampleCb ) );
613    memset( m_pcIPCMSampleCr, 0, uiTmp * sizeof( *m_pcIPCMSampleCr ) );
614  }
615}
616
617
618// initialize Sub partition
619Void TComDataCU::initSubCU( TComDataCU* pcCU, UInt uiPartUnitIdx, UInt uiDepth, Int qp )
620{
621  assert( uiPartUnitIdx<4 );
622
623  UInt uiPartOffset = ( pcCU->getTotalNumPart()>>2 )*uiPartUnitIdx;
624
625  m_pcPic              = pcCU->getPic();
626  m_pcSlice            = m_pcPic->getSlice(m_pcPic->getCurrSliceIdx());
627  m_uiCUAddr           = pcCU->getAddr();
628  m_uiAbsIdxInLCU      = pcCU->getZorderIdxInCU() + uiPartOffset;
629
630  m_uiCUPelX           = pcCU->getCUPelX() + ( g_uiMaxCUWidth>>uiDepth  )*( uiPartUnitIdx &  1 );
631  m_uiCUPelY           = pcCU->getCUPelY() + ( g_uiMaxCUHeight>>uiDepth  )*( uiPartUnitIdx >> 1 );
632
633  m_dTotalCost         = MAX_DOUBLE;
634  m_uiTotalDistortion  = 0;
635  m_uiTotalBits        = 0;
636  m_uiTotalBins        = 0;
637  m_uiNumPartition     = pcCU->getTotalNumPart() >> 2;
638
639  Int iSizeInUchar = sizeof( UChar  ) * m_uiNumPartition;
640  Int iSizeInBool  = sizeof( Bool   ) * m_uiNumPartition;
641
642  Int sizeInChar = sizeof( Char  ) * m_uiNumPartition;
643  memset( m_phQP,              qp,  sizeInChar );
644
645  memset( m_pbMergeFlag,        0, iSizeInBool  );
646  memset( m_puhMergeIndex,      0, iSizeInUchar );
647  memset( m_puhLumaIntraDir,    DC_IDX, iSizeInUchar );
648  memset( m_puhChromaIntraDir,  0, iSizeInUchar );
649  memset( m_puhInterDir,        0, iSizeInUchar );
650  memset( m_puhTrIdx,           0, iSizeInUchar );
651  memset( m_puhTransformSkip[0], 0, iSizeInUchar );
652  memset( m_puhTransformSkip[1], 0, iSizeInUchar );
653  memset( m_puhTransformSkip[2], 0, iSizeInUchar );
654  memset( m_puhCbf[0],          0, iSizeInUchar );
655  memset( m_puhCbf[1],          0, iSizeInUchar );
656  memset( m_puhCbf[2],          0, iSizeInUchar );
657  memset( m_puhDepth,     uiDepth, iSizeInUchar );
658
659  UChar uhWidth  = g_uiMaxCUWidth  >> uiDepth;
660  UChar uhHeight = g_uiMaxCUHeight >> uiDepth;
661  memset( m_puhWidth,          uhWidth,  iSizeInUchar );
662  memset( m_puhHeight,         uhHeight, iSizeInUchar );
663  memset( m_pbIPCMFlag,        0, iSizeInBool  );
664  for (UInt ui = 0; ui < m_uiNumPartition; ui++)
665  {
666    m_skipFlag[ui]   = false;
667    m_pePartSize[ui] = SIZE_NONE;
668    m_pePredMode[ui] = MODE_NONE;
669    m_CUTransquantBypass[ui] = false;
670    m_apiMVPIdx[0][ui] = -1;
671    m_apiMVPIdx[1][ui] = -1;
672    m_apiMVPNum[0][ui] = -1;
673    m_apiMVPNum[1][ui] = -1;
674    if(m_pcPic->getPicSym()->getInverseCUOrderMap(getAddr())*m_pcPic->getNumPartInCU()+m_uiAbsIdxInLCU+ui<getSlice()->getSliceSegmentCurStartCUAddr())
675    {
676      m_apiMVPIdx[0][ui] = pcCU->m_apiMVPIdx[0][uiPartOffset+ui];
677      m_apiMVPIdx[1][ui] = pcCU->m_apiMVPIdx[1][uiPartOffset+ui];;
678      m_apiMVPNum[0][ui] = pcCU->m_apiMVPNum[0][uiPartOffset+ui];;
679      m_apiMVPNum[1][ui] = pcCU->m_apiMVPNum[1][uiPartOffset+ui];;
680      m_puhDepth  [ui] = pcCU->getDepth(uiPartOffset+ui);
681      m_puhWidth  [ui] = pcCU->getWidth(uiPartOffset+ui);
682      m_puhHeight  [ui] = pcCU->getHeight(uiPartOffset+ui);
683      m_puhTrIdx  [ui] = pcCU->getTransformIdx(uiPartOffset+ui);
684      m_puhTransformSkip[0][ui] = pcCU->getTransformSkip(uiPartOffset+ui,TEXT_LUMA);
685      m_puhTransformSkip[1][ui] = pcCU->getTransformSkip(uiPartOffset+ui,TEXT_CHROMA_U);
686      m_puhTransformSkip[2][ui] = pcCU->getTransformSkip(uiPartOffset+ui,TEXT_CHROMA_V);
687      m_skipFlag[ui]   = pcCU->getSkipFlag(uiPartOffset+ui);
688      m_pePartSize[ui] = pcCU->getPartitionSize(uiPartOffset+ui);
689      m_pePredMode[ui] = pcCU->getPredictionMode(uiPartOffset+ui);
690      m_CUTransquantBypass[ui] = pcCU->getCUTransquantBypass(uiPartOffset+ui);
691      m_pbIPCMFlag[ui]=pcCU->m_pbIPCMFlag[uiPartOffset+ui];
692      m_phQP[ui] = pcCU->m_phQP[uiPartOffset+ui];
693      m_pbMergeFlag[ui]=pcCU->m_pbMergeFlag[uiPartOffset+ui];
694      m_puhMergeIndex[ui]=pcCU->m_puhMergeIndex[uiPartOffset+ui];
695      m_puhLumaIntraDir[ui]=pcCU->m_puhLumaIntraDir[uiPartOffset+ui];
696      m_puhChromaIntraDir[ui]=pcCU->m_puhChromaIntraDir[uiPartOffset+ui];
697      m_puhInterDir[ui]=pcCU->m_puhInterDir[uiPartOffset+ui];
698      m_puhCbf[0][ui]=pcCU->m_puhCbf[0][uiPartOffset+ui];
699      m_puhCbf[1][ui]=pcCU->m_puhCbf[1][uiPartOffset+ui];
700      m_puhCbf[2][ui]=pcCU->m_puhCbf[2][uiPartOffset+ui];
701
702    }
703  }
704  UInt uiTmp = uhWidth*uhHeight;
705  memset( m_pcTrCoeffY , 0, sizeof(TCoeff)*uiTmp );
706#if ADAPTIVE_QP_SELECTION 
707  memset( m_pcArlCoeffY , 0, sizeof(Int)*uiTmp );
708#endif
709  memset( m_pcIPCMSampleY , 0, sizeof( Pel ) * uiTmp );
710  uiTmp >>= 2;
711  memset( m_pcTrCoeffCb, 0, sizeof(TCoeff)*uiTmp );
712  memset( m_pcTrCoeffCr, 0, sizeof(TCoeff)*uiTmp );
713#if ADAPTIVE_QP_SELECTION
714  memset( m_pcArlCoeffCb, 0, sizeof(Int)*uiTmp );
715  memset( m_pcArlCoeffCr, 0, sizeof(Int)*uiTmp );
716#endif
717  memset( m_pcIPCMSampleCb , 0, sizeof( Pel ) * uiTmp );
718  memset( m_pcIPCMSampleCr , 0, sizeof( Pel ) * uiTmp );
719  m_acCUMvField[0].clearMvField();
720  m_acCUMvField[1].clearMvField();
721
722  if(m_pcPic->getPicSym()->getInverseCUOrderMap(getAddr())*m_pcPic->getNumPartInCU()+m_uiAbsIdxInLCU<getSlice()->getSliceSegmentCurStartCUAddr())
723  {
724    // Part of this CU contains data from an older slice. Now copy in that data.
725    UInt uiMaxCuWidth=pcCU->getSlice()->getSPS()->getMaxCUWidth();
726    UInt uiMaxCuHeight=pcCU->getSlice()->getSPS()->getMaxCUHeight();
727    TComDataCU * bigCU = getPic()->getCU(getAddr());
728    Int minui = uiPartOffset;
729    minui = -minui;
730    pcCU->m_acCUMvField[0].copyTo(&m_acCUMvField[0],minui,uiPartOffset,m_uiNumPartition);
731    pcCU->m_acCUMvField[1].copyTo(&m_acCUMvField[1],minui,uiPartOffset,m_uiNumPartition);
732    UInt uiCoffOffset = uiMaxCuWidth*uiMaxCuHeight*m_uiAbsIdxInLCU/pcCU->getPic()->getNumPartInCU();
733    uiTmp = uhWidth*uhHeight;
734    for(Int i=0; i<uiTmp; i++)
735    {
736      m_pcTrCoeffY[i]=bigCU->m_pcTrCoeffY[uiCoffOffset+i];
737#if ADAPTIVE_QP_SELECTION
738      m_pcArlCoeffY[i]=bigCU->m_pcArlCoeffY[uiCoffOffset+i];
739#endif
740      m_pcIPCMSampleY[i]=bigCU->m_pcIPCMSampleY[uiCoffOffset+i];
741    }
742    uiTmp>>=2;
743    uiCoffOffset>>=2;
744    for(Int i=0; i<uiTmp; i++)
745    {
746      m_pcTrCoeffCr[i]=bigCU->m_pcTrCoeffCr[uiCoffOffset+i];
747      m_pcTrCoeffCb[i]=bigCU->m_pcTrCoeffCb[uiCoffOffset+i];
748#if ADAPTIVE_QP_SELECTION
749      m_pcArlCoeffCr[i]=bigCU->m_pcArlCoeffCr[uiCoffOffset+i];
750      m_pcArlCoeffCb[i]=bigCU->m_pcArlCoeffCb[uiCoffOffset+i];
751#endif
752      m_pcIPCMSampleCb[i]=bigCU->m_pcIPCMSampleCb[uiCoffOffset+i];
753      m_pcIPCMSampleCr[i]=bigCU->m_pcIPCMSampleCr[uiCoffOffset+i];
754    }
755  }
756
757  m_pcCULeft        = pcCU->getCULeft();
758  m_pcCUAbove       = pcCU->getCUAbove();
759  m_pcCUAboveLeft   = pcCU->getCUAboveLeft();
760  m_pcCUAboveRight  = pcCU->getCUAboveRight();
761
762  m_apcCUColocated[0] = pcCU->getCUColocated(REF_PIC_LIST_0);
763  m_apcCUColocated[1] = pcCU->getCUColocated(REF_PIC_LIST_1);
764  memcpy(m_sliceStartCU,pcCU->m_sliceStartCU+uiPartOffset,sizeof(UInt)*m_uiNumPartition);
765  memcpy(m_sliceSegmentStartCU,pcCU->m_sliceSegmentStartCU+uiPartOffset,sizeof(UInt)*m_uiNumPartition);
766}
767
768Void TComDataCU::setOutsideCUPart( UInt uiAbsPartIdx, UInt uiDepth )
769{
770  UInt uiNumPartition = m_uiNumPartition >> (uiDepth << 1);
771  UInt uiSizeInUchar = sizeof( UChar  ) * uiNumPartition;
772
773  UChar uhWidth  = g_uiMaxCUWidth  >> uiDepth;
774  UChar uhHeight = g_uiMaxCUHeight >> uiDepth;
775  memset( m_puhDepth    + uiAbsPartIdx,     uiDepth,  uiSizeInUchar );
776  memset( m_puhWidth    + uiAbsPartIdx,     uhWidth,  uiSizeInUchar );
777  memset( m_puhHeight   + uiAbsPartIdx,     uhHeight, uiSizeInUchar );
778}
779
780// --------------------------------------------------------------------------------------------------------------------
781// Copy
782// --------------------------------------------------------------------------------------------------------------------
783
784Void TComDataCU::copySubCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
785{
786  UInt uiPart = uiAbsPartIdx;
787 
788  m_pcPic              = pcCU->getPic();
789  m_pcSlice            = pcCU->getSlice();
790  m_uiCUAddr           = pcCU->getAddr();
791  m_uiAbsIdxInLCU      = uiAbsPartIdx;
792 
793  m_uiCUPelX           = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
794  m_uiCUPelY           = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
795 
796  UInt uiWidth         = g_uiMaxCUWidth  >> uiDepth;
797  UInt uiHeight        = g_uiMaxCUHeight >> uiDepth;
798 
799  m_skipFlag=pcCU->getSkipFlag()          + uiPart;
800
801  m_phQP=pcCU->getQP()                    + uiPart;
802  m_pePartSize = pcCU->getPartitionSize() + uiPart;
803  m_pePredMode=pcCU->getPredictionMode()  + uiPart;
804  m_CUTransquantBypass  = pcCU->getCUTransquantBypass()+uiPart;
805 
806  m_pbMergeFlag         = pcCU->getMergeFlag()        + uiPart;
807  m_puhMergeIndex       = pcCU->getMergeIndex()       + uiPart;
808
809  m_puhLumaIntraDir     = pcCU->getLumaIntraDir()     + uiPart;
810  m_puhChromaIntraDir   = pcCU->getChromaIntraDir()   + uiPart;
811  m_puhInterDir         = pcCU->getInterDir()         + uiPart;
812  m_puhTrIdx            = pcCU->getTransformIdx()     + uiPart;
813  m_puhTransformSkip[0] = pcCU->getTransformSkip(TEXT_LUMA)     + uiPart;
814  m_puhTransformSkip[1] = pcCU->getTransformSkip(TEXT_CHROMA_U) + uiPart;
815  m_puhTransformSkip[2] = pcCU->getTransformSkip(TEXT_CHROMA_V) + uiPart;
816
817  m_puhCbf[0]= pcCU->getCbf(TEXT_LUMA)            + uiPart;
818  m_puhCbf[1]= pcCU->getCbf(TEXT_CHROMA_U)        + uiPart;
819  m_puhCbf[2]= pcCU->getCbf(TEXT_CHROMA_V)        + uiPart;
820 
821  m_puhDepth=pcCU->getDepth()                     + uiPart;
822  m_puhWidth=pcCU->getWidth()                     + uiPart;
823  m_puhHeight=pcCU->getHeight()                   + uiPart;
824 
825  m_apiMVPIdx[0]=pcCU->getMVPIdx(REF_PIC_LIST_0)  + uiPart;
826  m_apiMVPIdx[1]=pcCU->getMVPIdx(REF_PIC_LIST_1)  + uiPart;
827  m_apiMVPNum[0]=pcCU->getMVPNum(REF_PIC_LIST_0)  + uiPart;
828  m_apiMVPNum[1]=pcCU->getMVPNum(REF_PIC_LIST_1)  + uiPart;
829 
830  m_pbIPCMFlag         = pcCU->getIPCMFlag()        + uiPart;
831
832  m_pcCUAboveLeft      = pcCU->getCUAboveLeft();
833  m_pcCUAboveRight     = pcCU->getCUAboveRight();
834  m_pcCUAbove          = pcCU->getCUAbove();
835  m_pcCULeft           = pcCU->getCULeft();
836 
837  m_apcCUColocated[0] = pcCU->getCUColocated(REF_PIC_LIST_0);
838  m_apcCUColocated[1] = pcCU->getCUColocated(REF_PIC_LIST_1);
839 
840  UInt uiTmp = uiWidth*uiHeight;
841  UInt uiMaxCuWidth=pcCU->getSlice()->getSPS()->getMaxCUWidth();
842  UInt uiMaxCuHeight=pcCU->getSlice()->getSPS()->getMaxCUHeight();
843 
844  UInt uiCoffOffset = uiMaxCuWidth*uiMaxCuHeight*uiAbsPartIdx/pcCU->getPic()->getNumPartInCU();
845 
846  m_pcTrCoeffY = pcCU->getCoeffY() + uiCoffOffset;
847#if ADAPTIVE_QP_SELECTION
848  m_pcArlCoeffY= pcCU->getArlCoeffY() + uiCoffOffset; 
849#endif
850  m_pcIPCMSampleY = pcCU->getPCMSampleY() + uiCoffOffset;
851
852  uiTmp >>= 2;
853  uiCoffOffset >>=2;
854  m_pcTrCoeffCb=pcCU->getCoeffCb() + uiCoffOffset;
855  m_pcTrCoeffCr=pcCU->getCoeffCr() + uiCoffOffset;
856#if ADAPTIVE_QP_SELECTION 
857  m_pcArlCoeffCb=pcCU->getArlCoeffCb() + uiCoffOffset;
858  m_pcArlCoeffCr=pcCU->getArlCoeffCr() + uiCoffOffset;
859#endif
860  m_pcIPCMSampleCb = pcCU->getPCMSampleCb() + uiCoffOffset;
861  m_pcIPCMSampleCr = pcCU->getPCMSampleCr() + uiCoffOffset;
862
863  m_acCUMvField[0].linkToWithOffset( pcCU->getCUMvField(REF_PIC_LIST_0), uiPart );
864  m_acCUMvField[1].linkToWithOffset( pcCU->getCUMvField(REF_PIC_LIST_1), uiPart );
865  memcpy(m_sliceStartCU,pcCU->m_sliceStartCU+uiPart,sizeof(UInt)*m_uiNumPartition);
866  memcpy(m_sliceSegmentStartCU,pcCU->m_sliceSegmentStartCU+uiPart,sizeof(UInt)*m_uiNumPartition);
867}
868
869// Copy inter prediction info from the biggest CU
870Void TComDataCU::copyInterPredInfoFrom    ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefPicList )
871{
872  m_pcPic              = pcCU->getPic();
873  m_pcSlice            = pcCU->getSlice();
874  m_uiCUAddr           = pcCU->getAddr();
875  m_uiAbsIdxInLCU      = uiAbsPartIdx;
876 
877  Int iRastPartIdx     = g_auiZscanToRaster[uiAbsPartIdx];
878  m_uiCUPelX           = pcCU->getCUPelX() + m_pcPic->getMinCUWidth ()*( iRastPartIdx % m_pcPic->getNumPartInWidth() );
879  m_uiCUPelY           = pcCU->getCUPelY() + m_pcPic->getMinCUHeight()*( iRastPartIdx / m_pcPic->getNumPartInWidth() );
880 
881  m_pcCUAboveLeft      = pcCU->getCUAboveLeft();
882  m_pcCUAboveRight     = pcCU->getCUAboveRight();
883  m_pcCUAbove          = pcCU->getCUAbove();
884  m_pcCULeft           = pcCU->getCULeft();
885 
886  m_apcCUColocated[0]  = pcCU->getCUColocated(REF_PIC_LIST_0);
887  m_apcCUColocated[1]  = pcCU->getCUColocated(REF_PIC_LIST_1);
888 
889  m_skipFlag           = pcCU->getSkipFlag ()             + uiAbsPartIdx;
890
891  m_pePartSize         = pcCU->getPartitionSize ()        + uiAbsPartIdx;
892  m_pePredMode         = pcCU->getPredictionMode()        + uiAbsPartIdx;
893  m_CUTransquantBypass = pcCU->getCUTransquantBypass()    + uiAbsPartIdx;
894  m_puhInterDir        = pcCU->getInterDir      ()        + uiAbsPartIdx;
895 
896  m_puhDepth           = pcCU->getDepth ()                + uiAbsPartIdx;
897  m_puhWidth           = pcCU->getWidth ()                + uiAbsPartIdx;
898  m_puhHeight          = pcCU->getHeight()                + uiAbsPartIdx;
899 
900  m_pbMergeFlag        = pcCU->getMergeFlag()             + uiAbsPartIdx;
901  m_puhMergeIndex      = pcCU->getMergeIndex()            + uiAbsPartIdx;
902
903  m_apiMVPIdx[eRefPicList] = pcCU->getMVPIdx(eRefPicList) + uiAbsPartIdx;
904  m_apiMVPNum[eRefPicList] = pcCU->getMVPNum(eRefPicList) + uiAbsPartIdx;
905 
906  m_acCUMvField[ eRefPicList ].linkToWithOffset( pcCU->getCUMvField(eRefPicList), uiAbsPartIdx );
907
908  memcpy(m_sliceStartCU,pcCU->m_sliceStartCU+uiAbsPartIdx,sizeof(UInt)*m_uiNumPartition);
909  memcpy(m_sliceSegmentStartCU,pcCU->m_sliceSegmentStartCU+uiAbsPartIdx,sizeof(UInt)*m_uiNumPartition);
910}
911
912// Copy small CU to bigger CU.
913// One of quarter parts overwritten by predicted sub part.
914Void TComDataCU::copyPartFrom( TComDataCU* pcCU, UInt uiPartUnitIdx, UInt uiDepth )
915{
916  assert( uiPartUnitIdx<4 );
917 
918  m_dTotalCost         += pcCU->getTotalCost();
919  m_uiTotalDistortion  += pcCU->getTotalDistortion();
920  m_uiTotalBits        += pcCU->getTotalBits();
921 
922  UInt uiOffset         = pcCU->getTotalNumPart()*uiPartUnitIdx;
923 
924  UInt uiNumPartition = pcCU->getTotalNumPart();
925  Int iSizeInUchar  = sizeof( UChar ) * uiNumPartition;
926  Int iSizeInBool   = sizeof( Bool  ) * uiNumPartition;
927 
928  Int sizeInChar  = sizeof( Char ) * uiNumPartition;
929  memcpy( m_skipFlag   + uiOffset, pcCU->getSkipFlag(),       sizeof( *m_skipFlag )   * uiNumPartition );
930  memcpy( m_phQP       + uiOffset, pcCU->getQP(),             sizeInChar                        );
931  memcpy( m_pePartSize + uiOffset, pcCU->getPartitionSize(),  sizeof( *m_pePartSize ) * uiNumPartition );
932  memcpy( m_pePredMode + uiOffset, pcCU->getPredictionMode(), sizeof( *m_pePredMode ) * uiNumPartition );
933  memcpy( m_CUTransquantBypass + uiOffset, pcCU->getCUTransquantBypass(), sizeof( *m_CUTransquantBypass ) * uiNumPartition );
934  memcpy( m_pbMergeFlag         + uiOffset, pcCU->getMergeFlag(),         iSizeInBool  );
935  memcpy( m_puhMergeIndex       + uiOffset, pcCU->getMergeIndex(),        iSizeInUchar );
936  memcpy( m_puhLumaIntraDir     + uiOffset, pcCU->getLumaIntraDir(),      iSizeInUchar );
937  memcpy( m_puhChromaIntraDir   + uiOffset, pcCU->getChromaIntraDir(),    iSizeInUchar );
938  memcpy( m_puhInterDir         + uiOffset, pcCU->getInterDir(),          iSizeInUchar );
939  memcpy( m_puhTrIdx            + uiOffset, pcCU->getTransformIdx(),      iSizeInUchar );
940  memcpy( m_puhTransformSkip[0] + uiOffset, pcCU->getTransformSkip(TEXT_LUMA),     iSizeInUchar );
941  memcpy( m_puhTransformSkip[1] + uiOffset, pcCU->getTransformSkip(TEXT_CHROMA_U), iSizeInUchar );
942  memcpy( m_puhTransformSkip[2] + uiOffset, pcCU->getTransformSkip(TEXT_CHROMA_V), iSizeInUchar );
943
944  memcpy( m_puhCbf[0] + uiOffset, pcCU->getCbf(TEXT_LUMA)    , iSizeInUchar );
945  memcpy( m_puhCbf[1] + uiOffset, pcCU->getCbf(TEXT_CHROMA_U), iSizeInUchar );
946  memcpy( m_puhCbf[2] + uiOffset, pcCU->getCbf(TEXT_CHROMA_V), iSizeInUchar );
947 
948  memcpy( m_puhDepth  + uiOffset, pcCU->getDepth(),  iSizeInUchar );
949  memcpy( m_puhWidth  + uiOffset, pcCU->getWidth(),  iSizeInUchar );
950  memcpy( m_puhHeight + uiOffset, pcCU->getHeight(), iSizeInUchar );
951 
952  memcpy( m_apiMVPIdx[0] + uiOffset, pcCU->getMVPIdx(REF_PIC_LIST_0), iSizeInUchar );
953  memcpy( m_apiMVPIdx[1] + uiOffset, pcCU->getMVPIdx(REF_PIC_LIST_1), iSizeInUchar );
954  memcpy( m_apiMVPNum[0] + uiOffset, pcCU->getMVPNum(REF_PIC_LIST_0), iSizeInUchar );
955  memcpy( m_apiMVPNum[1] + uiOffset, pcCU->getMVPNum(REF_PIC_LIST_1), iSizeInUchar );
956 
957  memcpy( m_pbIPCMFlag + uiOffset, pcCU->getIPCMFlag(), iSizeInBool );
958
959  m_pcCUAboveLeft      = pcCU->getCUAboveLeft();
960  m_pcCUAboveRight     = pcCU->getCUAboveRight();
961  m_pcCUAbove          = pcCU->getCUAbove();
962  m_pcCULeft           = pcCU->getCULeft();
963 
964  m_apcCUColocated[0] = pcCU->getCUColocated(REF_PIC_LIST_0);
965  m_apcCUColocated[1] = pcCU->getCUColocated(REF_PIC_LIST_1);
966 
967  m_acCUMvField[0].copyFrom( pcCU->getCUMvField( REF_PIC_LIST_0 ), pcCU->getTotalNumPart(), uiOffset );
968  m_acCUMvField[1].copyFrom( pcCU->getCUMvField( REF_PIC_LIST_1 ), pcCU->getTotalNumPart(), uiOffset );
969 
970  UInt uiTmp  = g_uiMaxCUWidth*g_uiMaxCUHeight >> (uiDepth<<1);
971  UInt uiTmp2 = uiPartUnitIdx*uiTmp;
972  memcpy( m_pcTrCoeffY  + uiTmp2, pcCU->getCoeffY(),  sizeof(TCoeff)*uiTmp );
973#if ADAPTIVE_QP_SELECTION
974  memcpy( m_pcArlCoeffY  + uiTmp2, pcCU->getArlCoeffY(),  sizeof(Int)*uiTmp );
975#endif
976  memcpy( m_pcIPCMSampleY + uiTmp2 , pcCU->getPCMSampleY(), sizeof(Pel) * uiTmp );
977
978  uiTmp >>= 2; uiTmp2>>= 2;
979  memcpy( m_pcTrCoeffCb + uiTmp2, pcCU->getCoeffCb(), sizeof(TCoeff)*uiTmp );
980  memcpy( m_pcTrCoeffCr + uiTmp2, pcCU->getCoeffCr(), sizeof(TCoeff)*uiTmp );
981#if ADAPTIVE_QP_SELECTION
982  memcpy( m_pcArlCoeffCb + uiTmp2, pcCU->getArlCoeffCb(), sizeof(Int)*uiTmp );
983  memcpy( m_pcArlCoeffCr + uiTmp2, pcCU->getArlCoeffCr(), sizeof(Int)*uiTmp );
984#endif
985  memcpy( m_pcIPCMSampleCb + uiTmp2 , pcCU->getPCMSampleCb(), sizeof(Pel) * uiTmp );
986  memcpy( m_pcIPCMSampleCr + uiTmp2 , pcCU->getPCMSampleCr(), sizeof(Pel) * uiTmp );
987  m_uiTotalBins += pcCU->getTotalBins();
988  memcpy( m_sliceStartCU        + uiOffset, pcCU->m_sliceStartCU,        sizeof( UInt ) * uiNumPartition  );
989  memcpy( m_sliceSegmentStartCU + uiOffset, pcCU->m_sliceSegmentStartCU, sizeof( UInt ) * uiNumPartition  );
990}
991
992// Copy current predicted part to a CU in picture.
993// It is used to predict for next part
994Void TComDataCU::copyToPic( UChar uhDepth )
995{
996  TComDataCU*& rpcCU = m_pcPic->getCU( m_uiCUAddr );
997 
998  rpcCU->getTotalCost()       = m_dTotalCost;
999  rpcCU->getTotalDistortion() = m_uiTotalDistortion;
1000  rpcCU->getTotalBits()       = m_uiTotalBits;
1001 
1002  Int iSizeInUchar  = sizeof( UChar ) * m_uiNumPartition;
1003  Int iSizeInBool   = sizeof( Bool  ) * m_uiNumPartition;
1004 
1005  Int sizeInChar  = sizeof( Char ) * m_uiNumPartition;
1006
1007  memcpy( rpcCU->getSkipFlag() + m_uiAbsIdxInLCU, m_skipFlag, sizeof( *m_skipFlag ) * m_uiNumPartition );
1008
1009  memcpy( rpcCU->getQP() + m_uiAbsIdxInLCU, m_phQP, sizeInChar  );
1010
1011  memcpy( rpcCU->getPartitionSize()  + m_uiAbsIdxInLCU, m_pePartSize, sizeof( *m_pePartSize ) * m_uiNumPartition );
1012  memcpy( rpcCU->getPredictionMode() + m_uiAbsIdxInLCU, m_pePredMode, sizeof( *m_pePredMode ) * m_uiNumPartition );
1013  memcpy( rpcCU->getCUTransquantBypass()+ m_uiAbsIdxInLCU, m_CUTransquantBypass, sizeof( *m_CUTransquantBypass ) * m_uiNumPartition );
1014  memcpy( rpcCU->getMergeFlag()         + m_uiAbsIdxInLCU, m_pbMergeFlag,         iSizeInBool  );
1015  memcpy( rpcCU->getMergeIndex()        + m_uiAbsIdxInLCU, m_puhMergeIndex,       iSizeInUchar );
1016  memcpy( rpcCU->getLumaIntraDir()      + m_uiAbsIdxInLCU, m_puhLumaIntraDir,     iSizeInUchar );
1017  memcpy( rpcCU->getChromaIntraDir()    + m_uiAbsIdxInLCU, m_puhChromaIntraDir,   iSizeInUchar );
1018  memcpy( rpcCU->getInterDir()          + m_uiAbsIdxInLCU, m_puhInterDir,         iSizeInUchar );
1019  memcpy( rpcCU->getTransformIdx()      + m_uiAbsIdxInLCU, m_puhTrIdx,            iSizeInUchar );
1020  memcpy( rpcCU->getTransformSkip(TEXT_LUMA)     + m_uiAbsIdxInLCU, m_puhTransformSkip[0], iSizeInUchar );
1021  memcpy( rpcCU->getTransformSkip(TEXT_CHROMA_U) + m_uiAbsIdxInLCU, m_puhTransformSkip[1], iSizeInUchar );
1022  memcpy( rpcCU->getTransformSkip(TEXT_CHROMA_V) + m_uiAbsIdxInLCU, m_puhTransformSkip[2], iSizeInUchar );
1023
1024  memcpy( rpcCU->getCbf(TEXT_LUMA)     + m_uiAbsIdxInLCU, m_puhCbf[0], iSizeInUchar );
1025  memcpy( rpcCU->getCbf(TEXT_CHROMA_U) + m_uiAbsIdxInLCU, m_puhCbf[1], iSizeInUchar );
1026  memcpy( rpcCU->getCbf(TEXT_CHROMA_V) + m_uiAbsIdxInLCU, m_puhCbf[2], iSizeInUchar );
1027 
1028  memcpy( rpcCU->getDepth()  + m_uiAbsIdxInLCU, m_puhDepth,  iSizeInUchar );
1029  memcpy( rpcCU->getWidth()  + m_uiAbsIdxInLCU, m_puhWidth,  iSizeInUchar );
1030  memcpy( rpcCU->getHeight() + m_uiAbsIdxInLCU, m_puhHeight, iSizeInUchar );
1031 
1032  memcpy( rpcCU->getMVPIdx(REF_PIC_LIST_0) + m_uiAbsIdxInLCU, m_apiMVPIdx[0], iSizeInUchar );
1033  memcpy( rpcCU->getMVPIdx(REF_PIC_LIST_1) + m_uiAbsIdxInLCU, m_apiMVPIdx[1], iSizeInUchar );
1034  memcpy( rpcCU->getMVPNum(REF_PIC_LIST_0) + m_uiAbsIdxInLCU, m_apiMVPNum[0], iSizeInUchar );
1035  memcpy( rpcCU->getMVPNum(REF_PIC_LIST_1) + m_uiAbsIdxInLCU, m_apiMVPNum[1], iSizeInUchar );
1036 
1037  m_acCUMvField[0].copyTo( rpcCU->getCUMvField( REF_PIC_LIST_0 ), m_uiAbsIdxInLCU );
1038  m_acCUMvField[1].copyTo( rpcCU->getCUMvField( REF_PIC_LIST_1 ), m_uiAbsIdxInLCU );
1039 
1040  memcpy( rpcCU->getIPCMFlag() + m_uiAbsIdxInLCU, m_pbIPCMFlag,         iSizeInBool  );
1041
1042  UInt uiTmp  = (g_uiMaxCUWidth*g_uiMaxCUHeight)>>(uhDepth<<1);
1043  UInt uiTmp2 = m_uiAbsIdxInLCU*m_pcPic->getMinCUWidth()*m_pcPic->getMinCUHeight();
1044  memcpy( rpcCU->getCoeffY()  + uiTmp2, m_pcTrCoeffY,  sizeof(TCoeff)*uiTmp  );
1045#if ADAPTIVE_QP_SELECTION 
1046  memcpy( rpcCU->getArlCoeffY()  + uiTmp2, m_pcArlCoeffY,  sizeof(Int)*uiTmp  );
1047#endif
1048  memcpy( rpcCU->getPCMSampleY() + uiTmp2 , m_pcIPCMSampleY, sizeof(Pel)*uiTmp );
1049
1050  uiTmp >>= 2; uiTmp2 >>= 2;
1051  memcpy( rpcCU->getCoeffCb() + uiTmp2, m_pcTrCoeffCb, sizeof(TCoeff)*uiTmp  );
1052  memcpy( rpcCU->getCoeffCr() + uiTmp2, m_pcTrCoeffCr, sizeof(TCoeff)*uiTmp  );
1053#if ADAPTIVE_QP_SELECTION
1054  memcpy( rpcCU->getArlCoeffCb() + uiTmp2, m_pcArlCoeffCb, sizeof(Int)*uiTmp  );
1055  memcpy( rpcCU->getArlCoeffCr() + uiTmp2, m_pcArlCoeffCr, sizeof(Int)*uiTmp  );
1056#endif
1057  memcpy( rpcCU->getPCMSampleCb() + uiTmp2 , m_pcIPCMSampleCb, sizeof( Pel ) * uiTmp );
1058  memcpy( rpcCU->getPCMSampleCr() + uiTmp2 , m_pcIPCMSampleCr, sizeof( Pel ) * uiTmp );
1059  rpcCU->getTotalBins() = m_uiTotalBins;
1060  memcpy( rpcCU->m_sliceStartCU        + m_uiAbsIdxInLCU, m_sliceStartCU,        sizeof( UInt ) * m_uiNumPartition  );
1061  memcpy( rpcCU->m_sliceSegmentStartCU + m_uiAbsIdxInLCU, m_sliceSegmentStartCU, sizeof( UInt ) * m_uiNumPartition  );
1062}
1063
1064Void TComDataCU::copyToPic( UChar uhDepth, UInt uiPartIdx, UInt uiPartDepth )
1065{
1066  TComDataCU*&  rpcCU       = m_pcPic->getCU( m_uiCUAddr );
1067  UInt          uiQNumPart  = m_uiNumPartition>>(uiPartDepth<<1);
1068 
1069  UInt uiPartStart          = uiPartIdx*uiQNumPart;
1070  UInt uiPartOffset         = m_uiAbsIdxInLCU + uiPartStart;
1071 
1072  rpcCU->getTotalCost()       = m_dTotalCost;
1073  rpcCU->getTotalDistortion() = m_uiTotalDistortion;
1074  rpcCU->getTotalBits()       = m_uiTotalBits;
1075 
1076  Int iSizeInUchar  = sizeof( UChar  ) * uiQNumPart;
1077  Int iSizeInBool   = sizeof( Bool   ) * uiQNumPart;
1078 
1079  Int sizeInChar  = sizeof( Char ) * uiQNumPart;
1080  memcpy( rpcCU->getSkipFlag()       + uiPartOffset, m_skipFlag,   sizeof( *m_skipFlag )   * uiQNumPart );
1081
1082  memcpy( rpcCU->getQP() + uiPartOffset, m_phQP, sizeInChar );
1083  memcpy( rpcCU->getPartitionSize()  + uiPartOffset, m_pePartSize, sizeof( *m_pePartSize ) * uiQNumPart );
1084  memcpy( rpcCU->getPredictionMode() + uiPartOffset, m_pePredMode, sizeof( *m_pePredMode ) * uiQNumPart );
1085  memcpy( rpcCU->getCUTransquantBypass()+ uiPartOffset, m_CUTransquantBypass, sizeof( *m_CUTransquantBypass ) * uiQNumPart );
1086  memcpy( rpcCU->getMergeFlag()         + uiPartOffset, m_pbMergeFlag,         iSizeInBool  );
1087  memcpy( rpcCU->getMergeIndex()        + uiPartOffset, m_puhMergeIndex,       iSizeInUchar );
1088  memcpy( rpcCU->getLumaIntraDir()      + uiPartOffset, m_puhLumaIntraDir,     iSizeInUchar );
1089  memcpy( rpcCU->getChromaIntraDir()    + uiPartOffset, m_puhChromaIntraDir,   iSizeInUchar );
1090  memcpy( rpcCU->getInterDir()          + uiPartOffset, m_puhInterDir,         iSizeInUchar );
1091  memcpy( rpcCU->getTransformIdx()      + uiPartOffset, m_puhTrIdx,            iSizeInUchar );
1092  memcpy( rpcCU->getTransformSkip(TEXT_LUMA)     + uiPartOffset, m_puhTransformSkip[0], iSizeInUchar );
1093  memcpy( rpcCU->getTransformSkip(TEXT_CHROMA_U) + uiPartOffset, m_puhTransformSkip[1], iSizeInUchar );
1094  memcpy( rpcCU->getTransformSkip(TEXT_CHROMA_V) + uiPartOffset, m_puhTransformSkip[2], iSizeInUchar );
1095  memcpy( rpcCU->getCbf(TEXT_LUMA)     + uiPartOffset, m_puhCbf[0], iSizeInUchar );
1096  memcpy( rpcCU->getCbf(TEXT_CHROMA_U) + uiPartOffset, m_puhCbf[1], iSizeInUchar );
1097  memcpy( rpcCU->getCbf(TEXT_CHROMA_V) + uiPartOffset, m_puhCbf[2], iSizeInUchar );
1098 
1099  memcpy( rpcCU->getDepth()  + uiPartOffset, m_puhDepth,  iSizeInUchar );
1100  memcpy( rpcCU->getWidth()  + uiPartOffset, m_puhWidth,  iSizeInUchar );
1101  memcpy( rpcCU->getHeight() + uiPartOffset, m_puhHeight, iSizeInUchar );
1102 
1103  memcpy( rpcCU->getMVPIdx(REF_PIC_LIST_0) + uiPartOffset, m_apiMVPIdx[0], iSizeInUchar );
1104  memcpy( rpcCU->getMVPIdx(REF_PIC_LIST_1) + uiPartOffset, m_apiMVPIdx[1], iSizeInUchar );
1105  memcpy( rpcCU->getMVPNum(REF_PIC_LIST_0) + uiPartOffset, m_apiMVPNum[0], iSizeInUchar );
1106  memcpy( rpcCU->getMVPNum(REF_PIC_LIST_1) + uiPartOffset, m_apiMVPNum[1], iSizeInUchar );
1107  m_acCUMvField[0].copyTo( rpcCU->getCUMvField( REF_PIC_LIST_0 ), m_uiAbsIdxInLCU, uiPartStart, uiQNumPart );
1108  m_acCUMvField[1].copyTo( rpcCU->getCUMvField( REF_PIC_LIST_1 ), m_uiAbsIdxInLCU, uiPartStart, uiQNumPart );
1109 
1110  memcpy( rpcCU->getIPCMFlag() + uiPartOffset, m_pbIPCMFlag,         iSizeInBool  );
1111
1112  UInt uiTmp  = (g_uiMaxCUWidth*g_uiMaxCUHeight)>>((uhDepth+uiPartDepth)<<1);
1113  UInt uiTmp2 = uiPartOffset*m_pcPic->getMinCUWidth()*m_pcPic->getMinCUHeight();
1114  memcpy( rpcCU->getCoeffY()  + uiTmp2, m_pcTrCoeffY,  sizeof(TCoeff)*uiTmp  );
1115#if ADAPTIVE_QP_SELECTION
1116  memcpy( rpcCU->getArlCoeffY()  + uiTmp2, m_pcArlCoeffY,  sizeof(Int)*uiTmp  );
1117#endif
1118 
1119  memcpy( rpcCU->getPCMSampleY() + uiTmp2 , m_pcIPCMSampleY, sizeof( Pel ) * uiTmp );
1120
1121  uiTmp >>= 2; uiTmp2 >>= 2;
1122  memcpy( rpcCU->getCoeffCb() + uiTmp2, m_pcTrCoeffCb, sizeof(TCoeff)*uiTmp  );
1123  memcpy( rpcCU->getCoeffCr() + uiTmp2, m_pcTrCoeffCr, sizeof(TCoeff)*uiTmp  );
1124#if ADAPTIVE_QP_SELECTION
1125  memcpy( rpcCU->getArlCoeffCb() + uiTmp2, m_pcArlCoeffCb, sizeof(Int)*uiTmp  );
1126  memcpy( rpcCU->getArlCoeffCr() + uiTmp2, m_pcArlCoeffCr, sizeof(Int)*uiTmp  );
1127#endif
1128
1129  memcpy( rpcCU->getPCMSampleCb() + uiTmp2 , m_pcIPCMSampleCb, sizeof( Pel ) * uiTmp );
1130  memcpy( rpcCU->getPCMSampleCr() + uiTmp2 , m_pcIPCMSampleCr, sizeof( Pel ) * uiTmp );
1131  rpcCU->getTotalBins() = m_uiTotalBins;
1132  memcpy( rpcCU->m_sliceStartCU        + uiPartOffset, m_sliceStartCU,        sizeof( UInt ) * uiQNumPart  );
1133  memcpy( rpcCU->m_sliceSegmentStartCU + uiPartOffset, m_sliceSegmentStartCU, sizeof( UInt ) * uiQNumPart  );
1134}
1135
1136// --------------------------------------------------------------------------------------------------------------------
1137// Other public functions
1138// --------------------------------------------------------------------------------------------------------------------
1139
1140TComDataCU* TComDataCU::getPULeft( UInt& uiLPartUnitIdx, 
1141                                   UInt uiCurrPartUnitIdx, 
1142                                   Bool bEnforceSliceRestriction, 
1143                                   Bool bEnforceTileRestriction )
1144{
1145  UInt uiAbsPartIdx       = g_auiZscanToRaster[uiCurrPartUnitIdx];
1146  UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[m_uiAbsIdxInLCU];
1147  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1148 
1149  if ( !RasterAddress::isZeroCol( uiAbsPartIdx, uiNumPartInCUWidth ) )
1150  {
1151    uiLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - 1 ];
1152    if ( RasterAddress::isEqualCol( uiAbsPartIdx, uiAbsZorderCUIdx, uiNumPartInCUWidth ) )
1153    {
1154      return m_pcPic->getCU( getAddr() );
1155    }
1156    else
1157    {
1158      uiLPartUnitIdx -= m_uiAbsIdxInLCU;
1159      return this;
1160    }
1161  }
1162 
1163  uiLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx + uiNumPartInCUWidth - 1 ];
1164
1165
1166  if ( (bEnforceSliceRestriction && (m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL || m_pcCULeft->getSCUAddr()+uiLPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)))
1167      ||
1168       (bEnforceTileRestriction && ( m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL || (m_pcPic->getPicSym()->getTileIdxMap( m_pcCULeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))  )  )
1169      )
1170  {
1171    return NULL;
1172  }
1173  return m_pcCULeft;
1174}
1175
1176TComDataCU* TComDataCU::getPUAbove( UInt& uiAPartUnitIdx,
1177                                    UInt uiCurrPartUnitIdx, 
1178                                    Bool bEnforceSliceRestriction, 
1179                                    Bool planarAtLCUBoundary ,
1180                                    Bool bEnforceTileRestriction )
1181{
1182  UInt uiAbsPartIdx       = g_auiZscanToRaster[uiCurrPartUnitIdx];
1183  UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[m_uiAbsIdxInLCU];
1184  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1185 
1186  if ( !RasterAddress::isZeroRow( uiAbsPartIdx, uiNumPartInCUWidth ) )
1187  {
1188    uiAPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - uiNumPartInCUWidth ];
1189    if ( RasterAddress::isEqualRow( uiAbsPartIdx, uiAbsZorderCUIdx, uiNumPartInCUWidth ) )
1190    {
1191      return m_pcPic->getCU( getAddr() );
1192    }
1193    else
1194    {
1195      uiAPartUnitIdx -= m_uiAbsIdxInLCU;
1196      return this;
1197    }
1198  }
1199
1200  if(planarAtLCUBoundary)
1201  {
1202    return NULL;
1203  }
1204 
1205  uiAPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx + m_pcPic->getNumPartInCU() - uiNumPartInCUWidth ];
1206
1207  if ( (bEnforceSliceRestriction && (m_pcCUAbove==NULL || m_pcCUAbove->getSlice()==NULL || m_pcCUAbove->getSCUAddr()+uiAPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)))
1208      ||
1209       (bEnforceTileRestriction &&(m_pcCUAbove==NULL || m_pcCUAbove->getSlice()==NULL || (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAbove->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))))
1210      )
1211  {
1212    return NULL;
1213  }
1214  return m_pcCUAbove;
1215}
1216
1217TComDataCU* TComDataCU::getPUAboveLeft( UInt& uiALPartUnitIdx, UInt uiCurrPartUnitIdx, Bool bEnforceSliceRestriction )
1218{
1219  UInt uiAbsPartIdx       = g_auiZscanToRaster[uiCurrPartUnitIdx];
1220  UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[m_uiAbsIdxInLCU];
1221  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1222 
1223  if ( !RasterAddress::isZeroCol( uiAbsPartIdx, uiNumPartInCUWidth ) )
1224  {
1225    if ( !RasterAddress::isZeroRow( uiAbsPartIdx, uiNumPartInCUWidth ) )
1226    {
1227      uiALPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - uiNumPartInCUWidth - 1 ];
1228      if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdx, uiAbsZorderCUIdx, uiNumPartInCUWidth ) )
1229      {
1230        return m_pcPic->getCU( getAddr() );
1231      }
1232      else
1233      {
1234        uiALPartUnitIdx -= m_uiAbsIdxInLCU;
1235        return this;
1236      }
1237    }
1238    uiALPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx + getPic()->getNumPartInCU() - uiNumPartInCUWidth - 1 ];
1239    if ( (bEnforceSliceRestriction && (m_pcCUAbove==NULL || m_pcCUAbove->getSlice()==NULL ||
1240       m_pcCUAbove->getSCUAddr()+uiALPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1241       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAbove->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1242       ))
1243     )
1244    {
1245      return NULL;
1246    }
1247    return m_pcCUAbove;
1248  }
1249 
1250  if ( !RasterAddress::isZeroRow( uiAbsPartIdx, uiNumPartInCUWidth ) )
1251  {
1252    uiALPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - 1 ];
1253    if ( (bEnforceSliceRestriction && (m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL || 
1254       m_pcCULeft->getSCUAddr()+uiALPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1255       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCULeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1256       ))
1257     )
1258    {
1259      return NULL;
1260    }
1261    return m_pcCULeft;
1262  }
1263 
1264  uiALPartUnitIdx = g_auiRasterToZscan[ m_pcPic->getNumPartInCU() - 1 ];
1265  if ( (bEnforceSliceRestriction && (m_pcCUAboveLeft==NULL || m_pcCUAboveLeft->getSlice()==NULL ||
1266       m_pcCUAboveLeft->getSCUAddr()+uiALPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1267       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAboveLeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1268       ))
1269     )
1270  {
1271    return NULL;
1272  }
1273  return m_pcCUAboveLeft;
1274}
1275
1276TComDataCU* TComDataCU::getPUAboveRight( UInt& uiARPartUnitIdx, UInt uiCurrPartUnitIdx, Bool bEnforceSliceRestriction )
1277{
1278  UInt uiAbsPartIdxRT     = g_auiZscanToRaster[uiCurrPartUnitIdx];
1279  UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + m_puhWidth[0] / m_pcPic->getMinCUWidth() - 1;
1280  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1281 
1282  if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxRT] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )
1283  {
1284    uiARPartUnitIdx = MAX_UINT;
1285    return NULL;
1286  }
1287 
1288  if ( RasterAddress::lessThanCol( uiAbsPartIdxRT, uiNumPartInCUWidth - 1, uiNumPartInCUWidth ) )
1289  {
1290    if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, uiNumPartInCUWidth ) )
1291    {
1292      if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxRT - uiNumPartInCUWidth + 1 ] )
1293      {
1294        uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT - uiNumPartInCUWidth + 1 ];
1295        if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxRT, uiAbsZorderCUIdx, uiNumPartInCUWidth ) )
1296        {
1297          return m_pcPic->getCU( getAddr() );
1298        }
1299        else
1300        {
1301          uiARPartUnitIdx -= m_uiAbsIdxInLCU;
1302          return this;
1303        }
1304      }
1305      uiARPartUnitIdx = MAX_UINT;
1306      return NULL;
1307    }
1308    uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT + m_pcPic->getNumPartInCU() - uiNumPartInCUWidth + 1 ];
1309    if ( (bEnforceSliceRestriction && (m_pcCUAbove==NULL || m_pcCUAbove->getSlice()==NULL ||
1310       m_pcCUAbove->getSCUAddr()+uiARPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1311       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAbove->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1312       ))
1313     )
1314    {
1315      return NULL;
1316    }
1317    return m_pcCUAbove;
1318  }
1319 
1320  if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, uiNumPartInCUWidth ) )
1321  {
1322    uiARPartUnitIdx = MAX_UINT;
1323    return NULL;
1324  }
1325 
1326  uiARPartUnitIdx = g_auiRasterToZscan[ m_pcPic->getNumPartInCU() - uiNumPartInCUWidth ];
1327  if ( (bEnforceSliceRestriction && (m_pcCUAboveRight==NULL || m_pcCUAboveRight->getSlice()==NULL ||
1328       m_pcPic->getPicSym()->getInverseCUOrderMap( m_pcCUAboveRight->getAddr()) > m_pcPic->getPicSym()->getInverseCUOrderMap( getAddr()) ||
1329       m_pcCUAboveRight->getSCUAddr()+uiARPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1330       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAboveRight->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1331       ))
1332     )
1333  {
1334    return NULL;
1335  }
1336  return m_pcCUAboveRight;
1337}
1338
1339TComDataCU* TComDataCU::getPUBelowLeft( UInt& uiBLPartUnitIdx, UInt uiCurrPartUnitIdx, Bool bEnforceSliceRestriction )
1340{
1341  UInt uiAbsPartIdxLB     = g_auiZscanToRaster[uiCurrPartUnitIdx];
1342  UInt uiAbsZorderCUIdxLB = g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + (m_puhHeight[0] / m_pcPic->getMinCUHeight() - 1)*m_pcPic->getNumPartInWidth();
1343  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1344 
1345  if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxLB] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
1346  {
1347    uiBLPartUnitIdx = MAX_UINT;
1348    return NULL;
1349  }
1350 
1351  if ( RasterAddress::lessThanRow( uiAbsPartIdxLB, m_pcPic->getNumPartInHeight() - 1, uiNumPartInCUWidth ) )
1352  {
1353    if ( !RasterAddress::isZeroCol( uiAbsPartIdxLB, uiNumPartInCUWidth ) )
1354    {
1355      if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxLB + uiNumPartInCUWidth - 1 ] )
1356      {
1357        uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + uiNumPartInCUWidth - 1 ];
1358        if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxLB, uiAbsZorderCUIdxLB, uiNumPartInCUWidth ) )
1359        {
1360          return m_pcPic->getCU( getAddr() );
1361        }
1362        else
1363        {
1364          uiBLPartUnitIdx -= m_uiAbsIdxInLCU;
1365          return this;
1366        }
1367      }
1368      uiBLPartUnitIdx = MAX_UINT;
1369      return NULL;
1370    }
1371    uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + uiNumPartInCUWidth*2 - 1 ];
1372    if ( (bEnforceSliceRestriction && (m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL || 
1373       m_pcCULeft->getSCUAddr()+uiBLPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1374       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCULeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1375       ))
1376     )
1377    {
1378      return NULL;
1379    }
1380    return m_pcCULeft;
1381  }
1382 
1383  uiBLPartUnitIdx = MAX_UINT;
1384  return NULL;
1385}
1386
1387TComDataCU* TComDataCU::getPUBelowLeftAdi(UInt& uiBLPartUnitIdx,  UInt uiCurrPartUnitIdx, UInt uiPartUnitOffset, Bool bEnforceSliceRestriction )
1388{
1389  UInt uiAbsPartIdxLB     = g_auiZscanToRaster[uiCurrPartUnitIdx];
1390  UInt uiAbsZorderCUIdxLB = g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + ((m_puhHeight[0] / m_pcPic->getMinCUHeight()) - 1)*m_pcPic->getNumPartInWidth();
1391  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1392 
1393  if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxLB] + (m_pcPic->getPicSym()->getMinCUHeight() * uiPartUnitOffset)) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples())
1394  {
1395    uiBLPartUnitIdx = MAX_UINT;
1396    return NULL;
1397  }
1398 
1399  if ( RasterAddress::lessThanRow( uiAbsPartIdxLB, m_pcPic->getNumPartInHeight() - uiPartUnitOffset, uiNumPartInCUWidth ) )
1400  {
1401    if ( !RasterAddress::isZeroCol( uiAbsPartIdxLB, uiNumPartInCUWidth ) )
1402    {
1403      if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxLB + uiPartUnitOffset * uiNumPartInCUWidth - 1 ] )
1404      {
1405        uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + uiPartUnitOffset * uiNumPartInCUWidth - 1 ];
1406        if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxLB, uiAbsZorderCUIdxLB, uiNumPartInCUWidth ) )
1407        {
1408          return m_pcPic->getCU( getAddr() );
1409        }
1410        else
1411        {
1412          uiBLPartUnitIdx -= m_uiAbsIdxInLCU;
1413          return this;
1414        }
1415      }
1416      uiBLPartUnitIdx = MAX_UINT;
1417      return NULL;
1418    }
1419    uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + (1+uiPartUnitOffset) * uiNumPartInCUWidth - 1 ];
1420    if ( (bEnforceSliceRestriction && (m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL || 
1421       m_pcCULeft->getSCUAddr()+uiBLPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1422       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCULeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1423       ))
1424     )
1425    {
1426      return NULL;
1427    }
1428    return m_pcCULeft;
1429  }
1430 
1431  uiBLPartUnitIdx = MAX_UINT;
1432  return NULL;
1433}
1434
1435TComDataCU* TComDataCU::getPUAboveRightAdi(UInt&  uiARPartUnitIdx, UInt uiCurrPartUnitIdx, UInt uiPartUnitOffset, Bool bEnforceSliceRestriction )
1436{
1437  UInt uiAbsPartIdxRT     = g_auiZscanToRaster[uiCurrPartUnitIdx];
1438  UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + (m_puhWidth[0] / m_pcPic->getMinCUWidth()) - 1;
1439  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1440 
1441  if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxRT] + (m_pcPic->getPicSym()->getMinCUHeight() * uiPartUnitOffset)) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )
1442  {
1443    uiARPartUnitIdx = MAX_UINT;
1444    return NULL;
1445  }
1446 
1447  if ( RasterAddress::lessThanCol( uiAbsPartIdxRT, uiNumPartInCUWidth - uiPartUnitOffset, uiNumPartInCUWidth ) )
1448  {
1449    if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, uiNumPartInCUWidth ) )
1450    {
1451      if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxRT - uiNumPartInCUWidth + uiPartUnitOffset ] )
1452      {
1453        uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT - uiNumPartInCUWidth + uiPartUnitOffset ];
1454        if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxRT, uiAbsZorderCUIdx, uiNumPartInCUWidth ) )
1455        {
1456          return m_pcPic->getCU( getAddr() );
1457        }
1458        else
1459        {
1460          uiARPartUnitIdx -= m_uiAbsIdxInLCU;
1461          return this;
1462        }
1463      }
1464      uiARPartUnitIdx = MAX_UINT;
1465      return NULL;
1466    }
1467    uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT + m_pcPic->getNumPartInCU() - uiNumPartInCUWidth + uiPartUnitOffset ];
1468    if ( (bEnforceSliceRestriction && (m_pcCUAbove==NULL || m_pcCUAbove->getSlice()==NULL || 
1469       m_pcCUAbove->getSCUAddr()+uiARPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1470       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAbove->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1471       ))
1472     )
1473    {
1474      return NULL;
1475    }
1476    return m_pcCUAbove;
1477  }
1478 
1479  if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, uiNumPartInCUWidth ) )
1480  {
1481    uiARPartUnitIdx = MAX_UINT;
1482    return NULL;
1483  }
1484 
1485  uiARPartUnitIdx = g_auiRasterToZscan[ m_pcPic->getNumPartInCU() - uiNumPartInCUWidth + uiPartUnitOffset-1 ];
1486  if ( (bEnforceSliceRestriction && (m_pcCUAboveRight==NULL || m_pcCUAboveRight->getSlice()==NULL ||
1487       m_pcPic->getPicSym()->getInverseCUOrderMap( m_pcCUAboveRight->getAddr()) > m_pcPic->getPicSym()->getInverseCUOrderMap( getAddr()) ||
1488       m_pcCUAboveRight->getSCUAddr()+uiARPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1489       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAboveRight->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1490       ))
1491     )
1492  {
1493    return NULL;
1494  }
1495  return m_pcCUAboveRight;
1496}
1497
1498/** Get left QpMinCu
1499*\param   uiLPartUnitIdx
1500*\param   uiCurrAbsIdxInLCU
1501*\returns TComDataCU*   point of TComDataCU of left QpMinCu
1502*/
1503TComDataCU* TComDataCU::getQpMinCuLeft( UInt& uiLPartUnitIdx, UInt uiCurrAbsIdxInLCU)
1504{
1505  UInt numPartInCUWidth = m_pcPic->getNumPartInWidth();
1506  UInt absZorderQpMinCUIdx = (uiCurrAbsIdxInLCU>>((g_uiMaxCUDepth - getSlice()->getPPS()->getMaxCuDQPDepth())<<1))<<((g_uiMaxCUDepth -getSlice()->getPPS()->getMaxCuDQPDepth())<<1);
1507  UInt absRorderQpMinCUIdx = g_auiZscanToRaster[absZorderQpMinCUIdx];
1508
1509  // check for left LCU boundary
1510  if ( RasterAddress::isZeroCol(absRorderQpMinCUIdx, numPartInCUWidth) )
1511  {
1512    return NULL;
1513  }
1514
1515  // get index of left-CU relative to top-left corner of current quantization group
1516  uiLPartUnitIdx = g_auiRasterToZscan[absRorderQpMinCUIdx - 1];
1517
1518  // return pointer to current LCU
1519  return m_pcPic->getCU( getAddr() );
1520}
1521
1522/** Get Above QpMinCu
1523*\param   aPartUnitIdx
1524*\param   currAbsIdxInLCU
1525*\returns TComDataCU*   point of TComDataCU of above QpMinCu
1526*/
1527TComDataCU* TComDataCU::getQpMinCuAbove( UInt& aPartUnitIdx, UInt currAbsIdxInLCU )
1528{
1529  UInt numPartInCUWidth = m_pcPic->getNumPartInWidth();
1530  UInt absZorderQpMinCUIdx = (currAbsIdxInLCU>>((g_uiMaxCUDepth - getSlice()->getPPS()->getMaxCuDQPDepth())<<1))<<((g_uiMaxCUDepth - getSlice()->getPPS()->getMaxCuDQPDepth())<<1);
1531  UInt absRorderQpMinCUIdx = g_auiZscanToRaster[absZorderQpMinCUIdx];
1532
1533  // check for top LCU boundary
1534  if ( RasterAddress::isZeroRow( absRorderQpMinCUIdx, numPartInCUWidth) )
1535  {
1536    return NULL;
1537  }
1538
1539  // get index of top-CU relative to top-left corner of current quantization group
1540  aPartUnitIdx = g_auiRasterToZscan[absRorderQpMinCUIdx - numPartInCUWidth];
1541
1542  // return pointer to current LCU
1543  return m_pcPic->getCU( getAddr() );
1544}
1545
1546/** Get reference QP from left QpMinCu or latest coded QP
1547*\param   uiCurrAbsIdxInLCU
1548*\returns Char   reference QP value
1549*/
1550Char TComDataCU::getRefQP( UInt uiCurrAbsIdxInLCU )
1551{
1552  UInt        lPartIdx = 0, aPartIdx = 0;
1553  TComDataCU* cULeft  = getQpMinCuLeft ( lPartIdx, m_uiAbsIdxInLCU + uiCurrAbsIdxInLCU );
1554  TComDataCU* cUAbove = getQpMinCuAbove( aPartIdx, m_uiAbsIdxInLCU + uiCurrAbsIdxInLCU );
1555  return (((cULeft? cULeft->getQP( lPartIdx ): getLastCodedQP( uiCurrAbsIdxInLCU )) + (cUAbove? cUAbove->getQP( aPartIdx ): getLastCodedQP( uiCurrAbsIdxInLCU )) + 1) >> 1);
1556}
1557
1558Int TComDataCU::getLastValidPartIdx( Int iAbsPartIdx )
1559{
1560  Int iLastValidPartIdx = iAbsPartIdx-1;
1561  while ( iLastValidPartIdx >= 0
1562       && getPredictionMode( iLastValidPartIdx ) == MODE_NONE )
1563  {
1564    UInt uiDepth = getDepth( iLastValidPartIdx );
1565    iLastValidPartIdx -= m_uiNumPartition>>(uiDepth<<1);
1566  }
1567  return iLastValidPartIdx;
1568}
1569
1570Char TComDataCU::getLastCodedQP( UInt uiAbsPartIdx )
1571{
1572  UInt uiQUPartIdxMask = ~((1<<((g_uiMaxCUDepth - getSlice()->getPPS()->getMaxCuDQPDepth())<<1))-1);
1573  Int iLastValidPartIdx = getLastValidPartIdx( uiAbsPartIdx&uiQUPartIdxMask );
1574  if ( uiAbsPartIdx < m_uiNumPartition
1575    && (getSCUAddr()+iLastValidPartIdx < getSliceStartCU(m_uiAbsIdxInLCU+uiAbsPartIdx)))
1576  {
1577    return getSlice()->getSliceQp();
1578  }
1579  else
1580  if ( iLastValidPartIdx >= 0 )
1581  {
1582    return getQP( iLastValidPartIdx );
1583  }
1584  else
1585  {
1586    if ( getZorderIdxInCU() > 0 )
1587    {
1588      return getPic()->getCU( getAddr() )->getLastCodedQP( getZorderIdxInCU() );
1589    }
1590    else if ( getPic()->getPicSym()->getInverseCUOrderMap(getAddr()) > 0
1591      && getPic()->getPicSym()->getTileIdxMap(getAddr()) == getPic()->getPicSym()->getTileIdxMap(getPic()->getPicSym()->getCUOrderMap(getPic()->getPicSym()->getInverseCUOrderMap(getAddr())-1))
1592      && !( getSlice()->getPPS()->getEntropyCodingSyncEnabledFlag() && getAddr() % getPic()->getFrameWidthInCU() == 0 ) )
1593    {
1594      return getPic()->getCU( getPic()->getPicSym()->getCUOrderMap(getPic()->getPicSym()->getInverseCUOrderMap(getAddr())-1) )->getLastCodedQP( getPic()->getNumPartInCU() );
1595    }
1596    else
1597    {
1598      return getSlice()->getSliceQp();
1599    }
1600  }
1601}
1602/** Check whether the CU is coded in lossless coding mode
1603 * \param   uiAbsPartIdx
1604 * \returns true if the CU is coded in lossless coding mode; false if otherwise
1605 */
1606Bool TComDataCU::isLosslessCoded(UInt absPartIdx)
1607{
1608  return (getSlice()->getPPS()->getTransquantBypassEnableFlag() && getCUTransquantBypass (absPartIdx));
1609}
1610
1611/** Get allowed chroma intra modes
1612*\param   uiAbsPartIdx
1613*\param   uiModeList  pointer to chroma intra modes array
1614*\returns
1615*- fill uiModeList with chroma intra modes
1616*/
1617Void TComDataCU::getAllowedChromaDir( UInt uiAbsPartIdx, UInt* uiModeList )
1618{
1619  uiModeList[0] = PLANAR_IDX;
1620  uiModeList[1] = VER_IDX;
1621  uiModeList[2] = HOR_IDX;
1622  uiModeList[3] = DC_IDX;
1623  uiModeList[4] = DM_CHROMA_IDX;
1624
1625  UInt uiLumaMode = getLumaIntraDir( uiAbsPartIdx );
1626
1627  for( Int i = 0; i < NUM_CHROMA_MODE - 1; i++ )
1628  {
1629    if( uiLumaMode == uiModeList[i] )
1630    {
1631      uiModeList[i] = 34; // VER+8 mode
1632      break;
1633    }
1634  }
1635}
1636
1637/** Get most probable intra modes
1638*\param   uiAbsPartIdx
1639*\param   uiIntraDirPred  pointer to the array for MPM storage
1640*\param   piMode          it is set with MPM mode in case both MPM are equal. It is used to restrict RD search at encode side.
1641*\returns Number of MPM
1642*/
1643Int TComDataCU::getIntraDirLumaPredictor( UInt uiAbsPartIdx, Int* uiIntraDirPred, Int* piMode  )
1644{
1645  TComDataCU* pcTempCU;
1646  UInt        uiTempPartIdx;
1647  Int         iLeftIntraDir, iAboveIntraDir;
1648  Int         uiPredNum = 0;
1649
1650  // Get intra direction of left PU
1651  pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
1652 
1653#if INTRA_BL
1654  iLeftIntraDir  = pcTempCU ? ( pcTempCU->isIntra( uiTempPartIdx ) && ( !pcTempCU->isIntraBL( uiTempPartIdx ) ) ? pcTempCU->getLumaIntraDir( uiTempPartIdx ) : DC_IDX ) : DC_IDX;
1655#else
1656  iLeftIntraDir  = pcTempCU ? ( pcTempCU->isIntra( uiTempPartIdx ) ? pcTempCU->getLumaIntraDir( uiTempPartIdx ) : DC_IDX ) : DC_IDX;
1657#endif
1658 
1659  // Get intra direction of above PU
1660  pcTempCU = getPUAbove( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx, true, true );
1661 
1662#if INTRA_BL
1663  iAboveIntraDir = pcTempCU ? ( pcTempCU->isIntra( uiTempPartIdx ) && ( !pcTempCU->isIntraBL( uiTempPartIdx ) ) ? pcTempCU->getLumaIntraDir( uiTempPartIdx ) : DC_IDX ) : DC_IDX;
1664#else
1665  iAboveIntraDir = pcTempCU ? ( pcTempCU->isIntra( uiTempPartIdx ) ? pcTempCU->getLumaIntraDir( uiTempPartIdx ) : DC_IDX ) : DC_IDX;
1666#endif
1667 
1668#if SVC_BL_CAND_INTRA
1669  if(m_layerId > 0)
1670  {
1671    UInt uiCUAddrBase, uiAbsPartAddrBase;
1672    pcTempCU = getBaseColCU( uiAbsPartIdx, uiCUAddrBase, uiAbsPartAddrBase );
1673
1674    if(pcTempCU->getPredictionMode( uiAbsPartAddrBase ) == MODE_INTRA )
1675    {
1676      Int iColBaseDir = pcTempCU->getLumaIntraDir( uiAbsPartAddrBase );
1677      if( iColBaseDir != iAboveIntraDir && iColBaseDir != iLeftIntraDir && iAboveIntraDir != iLeftIntraDir)
1678      {
1679        uiIntraDirPred[0] = iColBaseDir;
1680        uiIntraDirPred[1] = iLeftIntraDir;
1681        uiIntraDirPred[2] = iAboveIntraDir;
1682        if( piMode )
1683        {
1684          *piMode = 2;
1685        }
1686        uiPredNum = 3;
1687        return uiPredNum;
1688      }
1689      else 
1690      {
1691        iAboveIntraDir = (iColBaseDir == iLeftIntraDir) ? iAboveIntraDir : iLeftIntraDir;
1692        iLeftIntraDir  = iColBaseDir;
1693      }
1694    }
1695  }
1696#endif
1697 
1698  uiPredNum = 3;
1699  if(iLeftIntraDir == iAboveIntraDir)
1700  {
1701    if( piMode )
1702    {
1703      *piMode = 1;
1704    }
1705   
1706    if (iLeftIntraDir > 1) // angular modes
1707    {
1708      uiIntraDirPred[0] = iLeftIntraDir;
1709      uiIntraDirPred[1] = ((iLeftIntraDir + 29) % 32) + 2;
1710      uiIntraDirPred[2] = ((iLeftIntraDir - 1 ) % 32) + 2;
1711    }
1712    else //non-angular
1713    {
1714      uiIntraDirPred[0] = PLANAR_IDX;
1715      uiIntraDirPred[1] = DC_IDX;
1716      uiIntraDirPred[2] = VER_IDX; 
1717    }
1718  }
1719  else
1720  {
1721    if( piMode )
1722    {
1723      *piMode = 2;
1724    }
1725    uiIntraDirPred[0] = iLeftIntraDir;
1726    uiIntraDirPred[1] = iAboveIntraDir;
1727   
1728    if (iLeftIntraDir && iAboveIntraDir ) //both modes are non-planar
1729    {
1730      uiIntraDirPred[2] = PLANAR_IDX;
1731    }
1732    else
1733    {
1734      uiIntraDirPred[2] =  (iLeftIntraDir+iAboveIntraDir)<2? VER_IDX : DC_IDX;
1735    }
1736  }
1737 
1738  return uiPredNum;
1739}
1740
1741
1742#if FAST_INTRA_SHVC
1743/** generate limited set of remaining modes
1744*\param   uiAbsPartIdx
1745*\param   uiIntraDirPred  pointer to the array for MPM storage
1746*\returns Number of intra coding modes (nb of remaining modes + 3 MPMs)
1747*/
1748Int TComDataCU::reduceSetOfIntraModes( UInt uiAbsPartIdx, Int* uiIntraDirPred, Int &fullSetOfModes )
1749{
1750  // check BL mode
1751  UInt          uiCUAddrBase, uiAbsPartAddrBase;
1752  TComDataCU*   pcTempCU = getBaseColCU( uiAbsPartIdx, uiCUAddrBase, uiAbsPartAddrBase );
1753
1754  if( pcTempCU->getPredictionMode( uiAbsPartAddrBase ) != MODE_INTRA )
1755    return( NUM_INTRA_MODE-1 );
1756
1757  // compute set of enabled modes g_reducedSetIntraModes[...]
1758  Int authorizedMode[NUM_INTRA_MODE-1]={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
1759  Int nbModes;
1760  for (nbModes=0; nbModes<3; nbModes++)  // add 3 MPMs 1st
1761  {
1762    g_reducedSetIntraModes[nbModes] = uiIntraDirPred[nbModes];
1763    authorizedMode[ uiIntraDirPred[nbModes] ] = 0;
1764  }
1765
1766  Int iColBaseDir = pcTempCU->getLumaIntraDir( uiAbsPartAddrBase );
1767  if ( authorizedMode[iColBaseDir] )  //possibly add BL mode
1768  {
1769    g_reducedSetIntraModes[nbModes++] = iColBaseDir;
1770    authorizedMode[ iColBaseDir ] = 0;
1771  }
1772
1773  Int iRefMode = ( iColBaseDir > 1 ) ? iColBaseDir : uiIntraDirPred[0];
1774  if ( iRefMode > 1 )    //add neighboring modes of refMode
1775  {
1776    UInt Left  = iRefMode;
1777    UInt Right = iRefMode;
1778    while ( nbModes < NB_REMAIN_MODES+3 )
1779    {
1780      Left = ((Left + 29) % 32) + 2;
1781      Right = ((Right - 1 ) % 32) + 2;
1782      if ( authorizedMode[Left] )   g_reducedSetIntraModes[nbModes++] = Left;
1783      if ( authorizedMode[Right] )  g_reducedSetIntraModes[nbModes++] = Right;
1784    }
1785  }
1786  else      //add pre-defined modes
1787  {
1788    Int  idx = 0;
1789    while ( nbModes < NB_REMAIN_MODES+3 )
1790    {
1791      UInt mode = g_predefSetIntraModes[idx++];
1792      if ( authorizedMode[mode] )   g_reducedSetIntraModes[nbModes++] = mode;
1793    }
1794  }
1795
1796  fullSetOfModes = 0;
1797  return ( nbModes );
1798}
1799#endif
1800
1801
1802UInt TComDataCU::getCtxSplitFlag( UInt uiAbsPartIdx, UInt uiDepth )
1803{
1804  TComDataCU* pcTempCU;
1805  UInt        uiTempPartIdx;
1806  UInt        uiCtx;
1807  // Get left split flag
1808  pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
1809  uiCtx  = ( pcTempCU ) ? ( ( pcTempCU->getDepth( uiTempPartIdx ) > uiDepth ) ? 1 : 0 ) : 0;
1810 
1811  // Get above split flag
1812  pcTempCU = getPUAbove( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
1813  uiCtx += ( pcTempCU ) ? ( ( pcTempCU->getDepth( uiTempPartIdx ) > uiDepth ) ? 1 : 0 ) : 0;
1814 
1815  return uiCtx;
1816}
1817
1818UInt TComDataCU::getCtxQtCbf( TextType eType, UInt uiTrDepth )
1819{
1820  if( eType )
1821  {
1822    return uiTrDepth;
1823  }
1824  else
1825  {
1826    const UInt uiCtx = ( uiTrDepth == 0 ? 1 : 0 );
1827    return uiCtx;
1828  }
1829}
1830
1831UInt TComDataCU::getQuadtreeTULog2MinSizeInCU( UInt absPartIdx )
1832{
1833  UInt log2CbSize = g_aucConvertToBit[getWidth( absPartIdx )] + 2;
1834  PartSize  partSize  = getPartitionSize( absPartIdx );
1835#if INTRA_BL
1836  UInt quadtreeTUMaxDepth = isIntra( absPartIdx ) ? m_pcSlice->getSPS()->getQuadtreeTUMaxDepthIntra() : m_pcSlice->getSPS()->getQuadtreeTUMaxDepthInter(); 
1837#else
1838  UInt quadtreeTUMaxDepth = getPredictionMode( absPartIdx ) == MODE_INTRA ? m_pcSlice->getSPS()->getQuadtreeTUMaxDepthIntra() : m_pcSlice->getSPS()->getQuadtreeTUMaxDepthInter(); 
1839#endif
1840  Int intraSplitFlag = ( getPredictionMode( absPartIdx ) == MODE_INTRA && partSize == SIZE_NxN ) ? 1 : 0;
1841  Int interSplitFlag = ((quadtreeTUMaxDepth == 1) && (getPredictionMode( absPartIdx ) == MODE_INTER) && (partSize != SIZE_2Nx2N) );
1842 
1843  UInt log2MinTUSizeInCU = 0;
1844  if (log2CbSize < (m_pcSlice->getSPS()->getQuadtreeTULog2MinSize() + quadtreeTUMaxDepth - 1 + interSplitFlag + intraSplitFlag) ) 
1845  {
1846    // when fully making use of signaled TUMaxDepth + inter/intraSplitFlag, resulting luma TB size is < QuadtreeTULog2MinSize
1847    log2MinTUSizeInCU = m_pcSlice->getSPS()->getQuadtreeTULog2MinSize();
1848  }
1849  else
1850  {
1851    // when fully making use of signaled TUMaxDepth + inter/intraSplitFlag, resulting luma TB size is still >= QuadtreeTULog2MinSize
1852    log2MinTUSizeInCU = log2CbSize - ( quadtreeTUMaxDepth - 1 + interSplitFlag + intraSplitFlag); // stop when trafoDepth == hierarchy_depth = splitFlag
1853    if ( log2MinTUSizeInCU > m_pcSlice->getSPS()->getQuadtreeTULog2MaxSize())
1854    {
1855      // when fully making use of signaled TUMaxDepth + inter/intraSplitFlag, resulting luma TB size is still > QuadtreeTULog2MaxSize
1856      log2MinTUSizeInCU = m_pcSlice->getSPS()->getQuadtreeTULog2MaxSize();
1857    } 
1858  }
1859  return log2MinTUSizeInCU;
1860}
1861
1862#if INTRA_BL
1863UInt TComDataCU::getCtxIntraBLFlag( UInt uiAbsPartIdx )
1864{
1865#if INTRA_BL_CTX_CHANGE
1866  Int cuDepth = getDepth(uiAbsPartIdx);
1867  Int maxCuDepth = g_uiMaxCUDepth - g_uiAddCUDepth;
1868  UInt uiCtx = (maxCuDepth==3 && cuDepth > 0) ? (cuDepth - 1) : cuDepth;
1869  return uiCtx;
1870#else
1871  TComDataCU* pcTempCU;
1872  UInt        uiTempPartIdx;
1873  UInt        uiCtx = 0;
1874 
1875  // Get BCBP of left PU
1876#if DEPENDENT_SLICES
1877  Bool bDepSliceRestriction = ( !m_pcSlice->getPPS()->getDependentSliceEnabledFlag());
1878  pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx, true, bDepSliceRestriction );
1879#else
1880  pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
1881#endif 
1882  uiCtx    = ( pcTempCU ) ? pcTempCU->isIntraBL( uiTempPartIdx ) : 0;
1883 
1884  // Get BCBP of above PU
1885#if DEPENDENT_SLICES
1886  pcTempCU = getPUAbove( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx, true, bDepSliceRestriction );
1887#else
1888  pcTempCU = getPUAbove( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
1889#endif 
1890  uiCtx   += ( pcTempCU ) ? pcTempCU->isIntraBL( uiTempPartIdx ) : 0;
1891 
1892  return uiCtx;
1893#endif
1894}
1895#endif
1896
1897#if REF_IDX_ME_ZEROMV
1898Bool TComDataCU::xCheckZeroMVILRMerge(UChar uhInterDir, TComMvField& cMvFieldL0, TComMvField& cMvFieldL1)
1899{
1900  Bool checkZeroMVILR = true;
1901
1902  if(uhInterDir&0x1)  //list0
1903  {
1904    Int refIdxL0 = cMvFieldL0.getRefIdx();
1905    if(getSlice()->getRefPic(REF_PIC_LIST_0, refIdxL0)->isILR(m_layerId))
1906    {
1907      checkZeroMVILR &= (cMvFieldL0.getHor() == 0 && cMvFieldL0.getVer() == 0);
1908    }
1909  }
1910  if(uhInterDir&0x2)  //list1
1911  {
1912    Int refIdxL1  = cMvFieldL1.getRefIdx();
1913    if(getSlice()->getRefPic(REF_PIC_LIST_1, refIdxL1)->isILR(m_layerId))
1914    {
1915      checkZeroMVILR &= (cMvFieldL1.getHor() == 0 && cMvFieldL1.getVer() == 0);
1916    }
1917  }
1918
1919  return checkZeroMVILR;
1920}
1921
1922Bool TComDataCU::xCheckZeroMVILRMvdL1Zero(Int iRefList, Int iRefIdx, Int MvpIdx)
1923{
1924  RefPicList eRefPicList = iRefList > 0? REF_PIC_LIST_1: REF_PIC_LIST_0;
1925  assert(eRefPicList == REF_PIC_LIST_1);
1926
1927  Bool checkZeroMVILR = true;
1928
1929  if(getSlice()->getRefPic(eRefPicList, iRefIdx)->isILR(m_layerId))
1930  {
1931    AMVPInfo* pcAMVPInfo = getCUMvField(eRefPicList)->getAMVPInfo();
1932    TComMv    cMv        = pcAMVPInfo->m_acMvCand[MvpIdx];
1933    checkZeroMVILR &= (cMv.getHor() == 0 && cMv.getVer() == 0);
1934  }
1935
1936  return checkZeroMVILR;
1937}
1938#endif
1939
1940UInt TComDataCU::getCtxSkipFlag( UInt uiAbsPartIdx )
1941{
1942  TComDataCU* pcTempCU;
1943  UInt        uiTempPartIdx;
1944  UInt        uiCtx = 0;
1945 
1946  // Get BCBP of left PU
1947  pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
1948  uiCtx    = ( pcTempCU ) ? pcTempCU->isSkipped( uiTempPartIdx ) : 0;
1949 
1950  // Get BCBP of above PU
1951  pcTempCU = getPUAbove( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
1952  uiCtx   += ( pcTempCU ) ? pcTempCU->isSkipped( uiTempPartIdx ) : 0;
1953 
1954  return uiCtx;
1955}
1956
1957UInt TComDataCU::getCtxInterDir( UInt uiAbsPartIdx )
1958{
1959  return getDepth( uiAbsPartIdx );
1960}
1961
1962Void TComDataCU::setCbfSubParts( UInt uiCbfY, UInt uiCbfU, UInt uiCbfV, UInt uiAbsPartIdx, UInt uiDepth )
1963{
1964  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
1965  memset( m_puhCbf[0] + uiAbsPartIdx, uiCbfY, sizeof( UChar ) * uiCurrPartNumb );
1966  memset( m_puhCbf[1] + uiAbsPartIdx, uiCbfU, sizeof( UChar ) * uiCurrPartNumb );
1967  memset( m_puhCbf[2] + uiAbsPartIdx, uiCbfV, sizeof( UChar ) * uiCurrPartNumb );
1968}
1969
1970Void TComDataCU::setCbfSubParts( UInt uiCbf, TextType eTType, UInt uiAbsPartIdx, UInt uiDepth )
1971{
1972  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
1973  memset( m_puhCbf[g_aucConvertTxtTypeToIdx[eTType]] + uiAbsPartIdx, uiCbf, sizeof( UChar ) * uiCurrPartNumb );
1974}
1975
1976/** Sets a coded block flag for all sub-partitions of a partition
1977 * \param uiCbf The value of the coded block flag to be set
1978 * \param eTType
1979 * \param uiAbsPartIdx
1980 * \param uiPartIdx
1981 * \param uiDepth
1982 * \returns Void
1983 */
1984Void TComDataCU::setCbfSubParts ( UInt uiCbf, TextType eTType, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
1985{
1986  setSubPart<UChar>( uiCbf, m_puhCbf[g_aucConvertTxtTypeToIdx[eTType]], uiAbsPartIdx, uiDepth, uiPartIdx );
1987}
1988
1989Void TComDataCU::setDepthSubParts( UInt uiDepth, UInt uiAbsPartIdx )
1990{
1991  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
1992  memset( m_puhDepth + uiAbsPartIdx, uiDepth, sizeof(UChar)*uiCurrPartNumb );
1993}
1994
1995Bool TComDataCU::isFirstAbsZorderIdxInDepth (UInt uiAbsPartIdx, UInt uiDepth)
1996{
1997  UInt uiPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
1998  return (((m_uiAbsIdxInLCU + uiAbsPartIdx)% uiPartNumb) == 0);
1999}
2000
2001Void TComDataCU::setPartSizeSubParts( PartSize eMode, UInt uiAbsPartIdx, UInt uiDepth )
2002{
2003  assert( sizeof( *m_pePartSize) == 1 );
2004  memset( m_pePartSize + uiAbsPartIdx, eMode, m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ) );
2005}
2006
2007Void TComDataCU::setCUTransquantBypassSubParts( Bool flag, UInt uiAbsPartIdx, UInt uiDepth )
2008{
2009  memset( m_CUTransquantBypass + uiAbsPartIdx, flag, m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ) );
2010}
2011
2012Void TComDataCU::setSkipFlagSubParts( Bool skip, UInt absPartIdx, UInt depth )
2013{
2014  assert( sizeof( *m_skipFlag) == 1 );
2015  memset( m_skipFlag + absPartIdx, skip, m_pcPic->getNumPartInCU() >> ( 2 * depth ) );
2016}
2017
2018Void TComDataCU::setPredModeSubParts( PredMode eMode, UInt uiAbsPartIdx, UInt uiDepth )
2019{
2020  assert( sizeof( *m_pePredMode) == 1 );
2021  memset( m_pePredMode + uiAbsPartIdx, eMode, m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ) );
2022}
2023
2024Void TComDataCU::setQPSubCUs( Int qp, TComDataCU* pcCU, UInt absPartIdx, UInt depth, Bool &foundNonZeroCbf )
2025{
2026  UInt currPartNumb = m_pcPic->getNumPartInCU() >> (depth << 1);
2027  UInt currPartNumQ = currPartNumb >> 2;
2028
2029  if(!foundNonZeroCbf)
2030  {
2031    if(pcCU->getDepth(absPartIdx) > depth)
2032    {
2033      for ( UInt partUnitIdx = 0; partUnitIdx < 4; partUnitIdx++ )
2034      {
2035        pcCU->setQPSubCUs( qp, pcCU, absPartIdx+partUnitIdx*currPartNumQ, depth+1, foundNonZeroCbf );
2036      }
2037    }
2038    else
2039    {
2040      if(pcCU->getCbf( absPartIdx, TEXT_LUMA ) || pcCU->getCbf( absPartIdx, TEXT_CHROMA_U ) || pcCU->getCbf( absPartIdx, TEXT_CHROMA_V ) )
2041      {
2042        foundNonZeroCbf = true;
2043      }
2044      else
2045      {
2046        setQPSubParts(qp, absPartIdx, depth);
2047      }
2048    }
2049  }
2050}
2051
2052Void TComDataCU::setQPSubParts( Int qp, UInt uiAbsPartIdx, UInt uiDepth )
2053{
2054  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2055  TComSlice * pcSlice = getPic()->getSlice(getPic()->getCurrSliceIdx());
2056
2057  for(UInt uiSCUIdx = uiAbsPartIdx; uiSCUIdx < uiAbsPartIdx+uiCurrPartNumb; uiSCUIdx++)
2058  {
2059    if( m_pcPic->getCU( getAddr() )->getSliceSegmentStartCU(uiSCUIdx+getZorderIdxInCU()) == pcSlice->getSliceSegmentCurStartCUAddr() )
2060    {
2061      m_phQP[uiSCUIdx] = qp;
2062    }
2063  }
2064}
2065
2066Void TComDataCU::setLumaIntraDirSubParts( UInt uiDir, UInt uiAbsPartIdx, UInt uiDepth )
2067{
2068  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2069 
2070  memset( m_puhLumaIntraDir + uiAbsPartIdx, uiDir, sizeof(UChar)*uiCurrPartNumb );
2071}
2072
2073template<typename T>
2074Void TComDataCU::setSubPart( T uiParameter, T* puhBaseLCU, UInt uiCUAddr, UInt uiCUDepth, UInt uiPUIdx )
2075{
2076  assert( sizeof(T) == 1 ); // Using memset() works only for types of size 1
2077 
2078  UInt uiCurrPartNumQ = (m_pcPic->getNumPartInCU() >> (2 * uiCUDepth)) >> 2;
2079  switch ( m_pePartSize[ uiCUAddr ] )
2080  {
2081    case SIZE_2Nx2N:
2082      memset( puhBaseLCU + uiCUAddr, uiParameter, 4 * uiCurrPartNumQ );
2083      break;
2084    case SIZE_2NxN:
2085      memset( puhBaseLCU + uiCUAddr, uiParameter, 2 * uiCurrPartNumQ );
2086      break;
2087    case SIZE_Nx2N:
2088      memset( puhBaseLCU + uiCUAddr, uiParameter, uiCurrPartNumQ );
2089      memset( puhBaseLCU + uiCUAddr + 2 * uiCurrPartNumQ, uiParameter, uiCurrPartNumQ );
2090      break;
2091    case SIZE_NxN:
2092      memset( puhBaseLCU + uiCUAddr, uiParameter, uiCurrPartNumQ ); 
2093      break;
2094    case SIZE_2NxnU:
2095      if ( uiPUIdx == 0 )
2096      {
2097        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 1) );                     
2098        memset( puhBaseLCU + uiCUAddr + uiCurrPartNumQ, uiParameter, (uiCurrPartNumQ >> 1) );                     
2099      }
2100      else if ( uiPUIdx == 1 )
2101      {
2102        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 1) );                     
2103        memset( puhBaseLCU + uiCUAddr + uiCurrPartNumQ, uiParameter, ((uiCurrPartNumQ >> 1) + (uiCurrPartNumQ << 1)) );                     
2104      }
2105      else
2106      {
2107        assert(0);
2108      }
2109      break;
2110    case SIZE_2NxnD:
2111      if ( uiPUIdx == 0 )
2112      {
2113        memset( puhBaseLCU + uiCUAddr, uiParameter, ((uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1)) );                     
2114        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + uiCurrPartNumQ, uiParameter, (uiCurrPartNumQ >> 1) );                     
2115      }
2116      else if ( uiPUIdx == 1 )
2117      {
2118        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 1) );                     
2119        memset( puhBaseLCU + uiCUAddr + uiCurrPartNumQ, uiParameter, (uiCurrPartNumQ >> 1) );                     
2120      }
2121      else
2122      {
2123        assert(0);
2124      }
2125      break;
2126    case SIZE_nLx2N:
2127      if ( uiPUIdx == 0 )
2128      {
2129        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 2) );
2130        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) ); 
2131        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ >> 2) ); 
2132        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) ); 
2133      }
2134      else if ( uiPUIdx == 1 )
2135      {
2136        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 2) );
2137        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) ); 
2138        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ >> 2) ); 
2139        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) ); 
2140      }
2141      else
2142      {
2143        assert(0);
2144      }
2145      break;
2146    case SIZE_nRx2N:
2147      if ( uiPUIdx == 0 )
2148      {     
2149        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) );                           
2150        memset( puhBaseLCU + uiCUAddr + uiCurrPartNumQ + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );                           
2151        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) );                           
2152        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + uiCurrPartNumQ + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );                           
2153      }
2154      else if ( uiPUIdx == 1 )
2155      {
2156        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 2) );                           
2157        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );                           
2158        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ >> 2) );                           
2159        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );                         
2160      }
2161      else
2162      {
2163        assert(0);
2164      }
2165      break;
2166    default:
2167      assert( 0 );
2168  }
2169}
2170
2171Void TComDataCU::setMergeFlagSubParts ( Bool bMergeFlag, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
2172{
2173  setSubPart( bMergeFlag, m_pbMergeFlag, uiAbsPartIdx, uiDepth, uiPartIdx );
2174}
2175
2176Void TComDataCU::setMergeIndexSubParts ( UInt uiMergeIndex, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
2177{
2178  setSubPart<UChar>( uiMergeIndex, m_puhMergeIndex, uiAbsPartIdx, uiDepth, uiPartIdx );
2179}
2180
2181Void TComDataCU::setChromIntraDirSubParts( UInt uiDir, UInt uiAbsPartIdx, UInt uiDepth )
2182{
2183  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2184 
2185  memset( m_puhChromaIntraDir + uiAbsPartIdx, uiDir, sizeof(UChar)*uiCurrPartNumb );
2186}
2187
2188Void TComDataCU::setInterDirSubParts( UInt uiDir, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
2189{
2190  setSubPart<UChar>( uiDir, m_puhInterDir, uiAbsPartIdx, uiDepth, uiPartIdx );
2191}
2192
2193Void TComDataCU::setMVPIdxSubParts( Int iMVPIdx, RefPicList eRefPicList, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
2194{
2195  setSubPart<Char>( iMVPIdx, m_apiMVPIdx[eRefPicList], uiAbsPartIdx, uiDepth, uiPartIdx );
2196}
2197
2198Void TComDataCU::setMVPNumSubParts( Int iMVPNum, RefPicList eRefPicList, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
2199{
2200  setSubPart<Char>( iMVPNum, m_apiMVPNum[eRefPicList], uiAbsPartIdx, uiDepth, uiPartIdx );
2201}
2202
2203
2204Void TComDataCU::setTrIdxSubParts( UInt uiTrIdx, UInt uiAbsPartIdx, UInt uiDepth )
2205{
2206  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2207 
2208  memset( m_puhTrIdx + uiAbsPartIdx, uiTrIdx, sizeof(UChar)*uiCurrPartNumb );
2209}
2210
2211Void TComDataCU::setTransformSkipSubParts( UInt useTransformSkipY, UInt useTransformSkipU, UInt useTransformSkipV, UInt uiAbsPartIdx, UInt uiDepth )
2212{
2213  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2214
2215  memset( m_puhTransformSkip[0] + uiAbsPartIdx, useTransformSkipY, sizeof( UChar ) * uiCurrPartNumb );
2216  memset( m_puhTransformSkip[1] + uiAbsPartIdx, useTransformSkipU, sizeof( UChar ) * uiCurrPartNumb );
2217  memset( m_puhTransformSkip[2] + uiAbsPartIdx, useTransformSkipV, sizeof( UChar ) * uiCurrPartNumb );
2218}
2219
2220Void TComDataCU::setTransformSkipSubParts( UInt useTransformSkip, TextType eType, UInt uiAbsPartIdx, UInt uiDepth)
2221{
2222  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2223
2224  memset( m_puhTransformSkip[g_aucConvertTxtTypeToIdx[eType]] + uiAbsPartIdx, useTransformSkip, sizeof( UChar ) * uiCurrPartNumb );
2225}
2226
2227Void TComDataCU::setSizeSubParts( UInt uiWidth, UInt uiHeight, UInt uiAbsPartIdx, UInt uiDepth )
2228{
2229  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2230 
2231  memset( m_puhWidth  + uiAbsPartIdx, uiWidth,  sizeof(UChar)*uiCurrPartNumb );
2232  memset( m_puhHeight + uiAbsPartIdx, uiHeight, sizeof(UChar)*uiCurrPartNumb );
2233}
2234
2235UChar TComDataCU::getNumPartInter()
2236{
2237  UChar iNumPart = 0;
2238 
2239  switch ( m_pePartSize[0] )
2240  {
2241    case SIZE_2Nx2N:    iNumPart = 1; break;
2242    case SIZE_2NxN:     iNumPart = 2; break;
2243    case SIZE_Nx2N:     iNumPart = 2; break;
2244    case SIZE_NxN:      iNumPart = 4; break;
2245    case SIZE_2NxnU:    iNumPart = 2; break;
2246    case SIZE_2NxnD:    iNumPart = 2; break;
2247    case SIZE_nLx2N:    iNumPart = 2; break;
2248    case SIZE_nRx2N:    iNumPart = 2; break;
2249    default:            assert (0);   break;
2250  }
2251 
2252  return  iNumPart;
2253}
2254
2255Void TComDataCU::getPartIndexAndSize( UInt uiPartIdx, UInt& ruiPartAddr, Int& riWidth, Int& riHeight )
2256{
2257  switch ( m_pePartSize[0] )
2258  {
2259    case SIZE_2NxN:
2260      riWidth = getWidth(0);      riHeight = getHeight(0) >> 1; ruiPartAddr = ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 1;
2261      break;
2262    case SIZE_Nx2N:
2263      riWidth = getWidth(0) >> 1; riHeight = getHeight(0);      ruiPartAddr = ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 2;
2264      break;
2265    case SIZE_NxN:
2266      riWidth = getWidth(0) >> 1; riHeight = getHeight(0) >> 1; ruiPartAddr = ( m_uiNumPartition >> 2 ) * uiPartIdx;
2267      break;
2268    case SIZE_2NxnU:
2269      riWidth     = getWidth(0);
2270      riHeight    = ( uiPartIdx == 0 ) ?  getHeight(0) >> 2 : ( getHeight(0) >> 2 ) + ( getHeight(0) >> 1 );
2271      ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : m_uiNumPartition >> 3;
2272      break;
2273    case SIZE_2NxnD:
2274      riWidth     = getWidth(0);
2275      riHeight    = ( uiPartIdx == 0 ) ?  ( getHeight(0) >> 2 ) + ( getHeight(0) >> 1 ) : getHeight(0) >> 2;
2276      ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : (m_uiNumPartition >> 1) + (m_uiNumPartition >> 3);
2277      break;
2278    case SIZE_nLx2N:
2279      riWidth     = ( uiPartIdx == 0 ) ? getWidth(0) >> 2 : ( getWidth(0) >> 2 ) + ( getWidth(0) >> 1 );
2280      riHeight    = getHeight(0);
2281      ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : m_uiNumPartition >> 4;
2282      break;
2283    case SIZE_nRx2N:
2284      riWidth     = ( uiPartIdx == 0 ) ? ( getWidth(0) >> 2 ) + ( getWidth(0) >> 1 ) : getWidth(0) >> 2;
2285      riHeight    = getHeight(0);
2286      ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : (m_uiNumPartition >> 2) + (m_uiNumPartition >> 4);
2287      break;
2288    default:
2289      assert ( m_pePartSize[0] == SIZE_2Nx2N );
2290      riWidth = getWidth(0);      riHeight = getHeight(0);      ruiPartAddr = 0;
2291      break;
2292  }
2293}
2294
2295
2296Void TComDataCU::getMvField ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefPicList, TComMvField& rcMvField )
2297{
2298  if ( pcCU == NULL )  // OUT OF BOUNDARY
2299  {
2300    TComMv  cZeroMv;
2301    rcMvField.setMvField( cZeroMv, NOT_VALID );
2302    return;
2303  }
2304 
2305  TComCUMvField*  pcCUMvField = pcCU->getCUMvField( eRefPicList );
2306  rcMvField.setMvField( pcCUMvField->getMv( uiAbsPartIdx ), pcCUMvField->getRefIdx( uiAbsPartIdx ) );
2307}
2308
2309Void TComDataCU::deriveLeftRightTopIdxGeneral ( UInt uiAbsPartIdx, UInt uiPartIdx, UInt& ruiPartIdxLT, UInt& ruiPartIdxRT )
2310{
2311  ruiPartIdxLT = m_uiAbsIdxInLCU + uiAbsPartIdx;
2312  UInt uiPUWidth = 0;
2313 
2314  switch ( m_pePartSize[uiAbsPartIdx] )
2315  {
2316    case SIZE_2Nx2N: uiPUWidth = m_puhWidth[uiAbsPartIdx];  break;
2317    case SIZE_2NxN:  uiPUWidth = m_puhWidth[uiAbsPartIdx];   break;
2318    case SIZE_Nx2N:  uiPUWidth = m_puhWidth[uiAbsPartIdx]  >> 1;  break;
2319    case SIZE_NxN:   uiPUWidth = m_puhWidth[uiAbsPartIdx]  >> 1; break;
2320    case SIZE_2NxnU:   uiPUWidth = m_puhWidth[uiAbsPartIdx]; break;
2321    case SIZE_2NxnD:   uiPUWidth = m_puhWidth[uiAbsPartIdx]; break;
2322    case SIZE_nLx2N:   
2323      if ( uiPartIdx == 0 )
2324      {
2325        uiPUWidth = m_puhWidth[uiAbsPartIdx]  >> 2; 
2326      }
2327      else if ( uiPartIdx == 1 )
2328      {
2329        uiPUWidth = (m_puhWidth[uiAbsPartIdx]  >> 1) + (m_puhWidth[uiAbsPartIdx]  >> 2); 
2330      }
2331      else
2332      {
2333        assert(0);
2334      }
2335      break;
2336    case SIZE_nRx2N:   
2337      if ( uiPartIdx == 0 )
2338      {
2339        uiPUWidth = (m_puhWidth[uiAbsPartIdx]  >> 1) + (m_puhWidth[uiAbsPartIdx]  >> 2); 
2340      }
2341      else if ( uiPartIdx == 1 )
2342      {
2343        uiPUWidth = m_puhWidth[uiAbsPartIdx]  >> 2; 
2344      }
2345      else
2346      {
2347        assert(0);
2348      }
2349      break;
2350    default:
2351      assert (0);
2352      break;
2353  }
2354 
2355  ruiPartIdxRT = g_auiRasterToZscan [g_auiZscanToRaster[ ruiPartIdxLT ] + uiPUWidth / m_pcPic->getMinCUWidth() - 1 ];
2356}
2357
2358Void TComDataCU::deriveLeftBottomIdxGeneral( UInt uiAbsPartIdx, UInt uiPartIdx, UInt& ruiPartIdxLB )
2359{
2360  UInt uiPUHeight = 0;
2361  switch ( m_pePartSize[uiAbsPartIdx] )
2362  {
2363    case SIZE_2Nx2N: uiPUHeight = m_puhHeight[uiAbsPartIdx];    break;
2364    case SIZE_2NxN:  uiPUHeight = m_puhHeight[uiAbsPartIdx] >> 1;    break;
2365    case SIZE_Nx2N:  uiPUHeight = m_puhHeight[uiAbsPartIdx];  break;
2366    case SIZE_NxN:   uiPUHeight = m_puhHeight[uiAbsPartIdx] >> 1;    break;
2367    case SIZE_2NxnU: 
2368      if ( uiPartIdx == 0 )
2369      {
2370        uiPUHeight = m_puhHeight[uiAbsPartIdx] >> 2;   
2371      }
2372      else if ( uiPartIdx == 1 )
2373      {
2374        uiPUHeight = (m_puhHeight[uiAbsPartIdx] >> 1) + (m_puhHeight[uiAbsPartIdx] >> 2);   
2375      }
2376      else
2377      {
2378        assert(0);
2379      }
2380      break;
2381    case SIZE_2NxnD: 
2382      if ( uiPartIdx == 0 )
2383      {
2384        uiPUHeight = (m_puhHeight[uiAbsPartIdx] >> 1) + (m_puhHeight[uiAbsPartIdx] >> 2);   
2385      }
2386      else if ( uiPartIdx == 1 )
2387      {
2388        uiPUHeight = m_puhHeight[uiAbsPartIdx] >> 2;   
2389      }
2390      else
2391      {
2392        assert(0);
2393      }
2394      break;
2395    case SIZE_nLx2N: uiPUHeight = m_puhHeight[uiAbsPartIdx];  break;
2396    case SIZE_nRx2N: uiPUHeight = m_puhHeight[uiAbsPartIdx];  break;
2397    default:
2398      assert (0);
2399      break;
2400  }
2401 
2402  ruiPartIdxLB      = g_auiRasterToZscan [g_auiZscanToRaster[ m_uiAbsIdxInLCU + uiAbsPartIdx ] + ((uiPUHeight / m_pcPic->getMinCUHeight()) - 1)*m_pcPic->getNumPartInWidth()];
2403}
2404
2405Void TComDataCU::deriveLeftRightTopIdx ( UInt uiPartIdx, UInt& ruiPartIdxLT, UInt& ruiPartIdxRT )
2406{
2407  ruiPartIdxLT = m_uiAbsIdxInLCU;
2408  ruiPartIdxRT = g_auiRasterToZscan [g_auiZscanToRaster[ ruiPartIdxLT ] + m_puhWidth[0] / m_pcPic->getMinCUWidth() - 1 ];
2409 
2410  switch ( m_pePartSize[0] )
2411  {
2412    case SIZE_2Nx2N:                                                                                                                                break;
2413    case SIZE_2NxN:
2414      ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 1; ruiPartIdxRT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 1;
2415      break;
2416    case SIZE_Nx2N:
2417      ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 2; ruiPartIdxRT -= ( uiPartIdx == 1 )? 0 : m_uiNumPartition >> 2;
2418      break;
2419    case SIZE_NxN:
2420      ruiPartIdxLT += ( m_uiNumPartition >> 2 ) * uiPartIdx;         ruiPartIdxRT +=  ( m_uiNumPartition >> 2 ) * ( uiPartIdx - 1 );
2421      break;
2422    case SIZE_2NxnU:
2423      ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 3;
2424      ruiPartIdxRT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 3;
2425      break;
2426    case SIZE_2NxnD:
2427      ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : ( m_uiNumPartition >> 1 ) + ( m_uiNumPartition >> 3 );
2428      ruiPartIdxRT += ( uiPartIdx == 0 )? 0 : ( m_uiNumPartition >> 1 ) + ( m_uiNumPartition >> 3 );
2429      break;
2430    case SIZE_nLx2N:
2431      ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 4;
2432      ruiPartIdxRT -= ( uiPartIdx == 1 )? 0 : ( m_uiNumPartition >> 2 ) + ( m_uiNumPartition >> 4 );
2433      break;
2434    case SIZE_nRx2N:
2435      ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : ( m_uiNumPartition >> 2 ) + ( m_uiNumPartition >> 4 );
2436      ruiPartIdxRT -= ( uiPartIdx == 1 )? 0 : m_uiNumPartition >> 4;
2437      break;
2438    default:
2439      assert (0);
2440      break;
2441  }
2442 
2443}
2444
2445Void TComDataCU::deriveLeftBottomIdx( UInt  uiPartIdx,      UInt&      ruiPartIdxLB )
2446{
2447  ruiPartIdxLB      = g_auiRasterToZscan [g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + ( ((m_puhHeight[0] / m_pcPic->getMinCUHeight())>>1) - 1)*m_pcPic->getNumPartInWidth()];
2448 
2449  switch ( m_pePartSize[0] )
2450  {
2451    case SIZE_2Nx2N:
2452      ruiPartIdxLB += m_uiNumPartition >> 1;
2453      break;
2454    case SIZE_2NxN:
2455      ruiPartIdxLB += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 1;
2456      break;
2457    case SIZE_Nx2N:
2458      ruiPartIdxLB += ( uiPartIdx == 0 )? m_uiNumPartition >> 1 : (m_uiNumPartition >> 2)*3;
2459      break;
2460    case SIZE_NxN:
2461      ruiPartIdxLB += ( m_uiNumPartition >> 2 ) * uiPartIdx;
2462      break;
2463    case SIZE_2NxnU:
2464      ruiPartIdxLB += ( uiPartIdx == 0 ) ? -((Int)m_uiNumPartition >> 3) : m_uiNumPartition >> 1;
2465      break;
2466    case SIZE_2NxnD:
2467      ruiPartIdxLB += ( uiPartIdx == 0 ) ? (m_uiNumPartition >> 2) + (m_uiNumPartition >> 3): m_uiNumPartition >> 1;
2468      break;
2469    case SIZE_nLx2N:
2470      ruiPartIdxLB += ( uiPartIdx == 0 ) ? m_uiNumPartition >> 1 : (m_uiNumPartition >> 1) + (m_uiNumPartition >> 4);
2471      break;
2472    case SIZE_nRx2N:
2473      ruiPartIdxLB += ( uiPartIdx == 0 ) ? m_uiNumPartition >> 1 : (m_uiNumPartition >> 1) + (m_uiNumPartition >> 2) + (m_uiNumPartition >> 4);
2474      break;
2475    default:
2476      assert (0);
2477      break;
2478  }
2479}
2480
2481/** Derives the partition index of neighbouring bottom right block
2482 * \param [in]  eCUMode
2483 * \param [in]  uiPartIdx
2484 * \param [out] ruiPartIdxRB
2485 */
2486Void TComDataCU::deriveRightBottomIdx( UInt  uiPartIdx,      UInt&      ruiPartIdxRB )
2487{
2488  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];
2489
2490  switch ( m_pePartSize[0] )
2491  {
2492    case SIZE_2Nx2N: 
2493      ruiPartIdxRB += m_uiNumPartition >> 1;   
2494      break;
2495    case SIZE_2NxN: 
2496      ruiPartIdxRB += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 1;   
2497      break;
2498    case SIZE_Nx2N: 
2499      ruiPartIdxRB += ( uiPartIdx == 0 )? m_uiNumPartition >> 2 : (m_uiNumPartition >> 1);   
2500      break;
2501    case SIZE_NxN:   
2502      ruiPartIdxRB += ( m_uiNumPartition >> 2 ) * ( uiPartIdx - 1 );   
2503      break;
2504    case SIZE_2NxnU:
2505      ruiPartIdxRB += ( uiPartIdx == 0 ) ? -((Int)m_uiNumPartition >> 3) : m_uiNumPartition >> 1;
2506      break;
2507    case SIZE_2NxnD:
2508      ruiPartIdxRB += ( uiPartIdx == 0 ) ? (m_uiNumPartition >> 2) + (m_uiNumPartition >> 3): m_uiNumPartition >> 1;
2509      break;
2510    case SIZE_nLx2N:
2511      ruiPartIdxRB += ( uiPartIdx == 0 ) ? (m_uiNumPartition >> 3) + (m_uiNumPartition >> 4): m_uiNumPartition >> 1;
2512      break;
2513    case SIZE_nRx2N:
2514      ruiPartIdxRB += ( uiPartIdx == 0 ) ? (m_uiNumPartition >> 2) + (m_uiNumPartition >> 3) + (m_uiNumPartition >> 4) : m_uiNumPartition >> 1;
2515      break;
2516    default:
2517      assert (0);
2518      break;
2519  }
2520}
2521
2522Void TComDataCU::deriveLeftRightTopIdxAdi ( UInt& ruiPartIdxLT, UInt& ruiPartIdxRT, UInt uiPartOffset, UInt uiPartDepth )
2523{
2524  UInt uiNumPartInWidth = (m_puhWidth[0]/m_pcPic->getMinCUWidth())>>uiPartDepth;
2525  ruiPartIdxLT = m_uiAbsIdxInLCU + uiPartOffset;
2526  ruiPartIdxRT = g_auiRasterToZscan[ g_auiZscanToRaster[ ruiPartIdxLT ] + uiNumPartInWidth - 1 ];
2527}
2528
2529Void TComDataCU::deriveLeftBottomIdxAdi( UInt& ruiPartIdxLB, UInt uiPartOffset, UInt uiPartDepth )
2530{
2531  UInt uiAbsIdx;
2532  UInt uiMinCuWidth, uiWidthInMinCus;
2533 
2534  uiMinCuWidth    = getPic()->getMinCUWidth();
2535  uiWidthInMinCus = (getWidth(0)/uiMinCuWidth)>>uiPartDepth;
2536  uiAbsIdx        = getZorderIdxInCU()+uiPartOffset+(m_uiNumPartition>>(uiPartDepth<<1))-1;
2537  uiAbsIdx        = g_auiZscanToRaster[uiAbsIdx]-(uiWidthInMinCus-1);
2538  ruiPartIdxLB    = g_auiRasterToZscan[uiAbsIdx];
2539}
2540
2541Bool TComDataCU::hasEqualMotion( UInt uiAbsPartIdx, TComDataCU* pcCandCU, UInt uiCandAbsPartIdx )
2542{
2543
2544  if ( getInterDir( uiAbsPartIdx ) != pcCandCU->getInterDir( uiCandAbsPartIdx ) )
2545  {
2546    return false;
2547  }
2548
2549  for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
2550  {
2551    if ( getInterDir( uiAbsPartIdx ) & ( 1 << uiRefListIdx ) )
2552    {
2553      if ( getCUMvField( RefPicList( uiRefListIdx ) )->getMv( uiAbsPartIdx )     != pcCandCU->getCUMvField( RefPicList( uiRefListIdx ) )->getMv( uiCandAbsPartIdx ) || 
2554        getCUMvField( RefPicList( uiRefListIdx ) )->getRefIdx( uiAbsPartIdx ) != pcCandCU->getCUMvField( RefPicList( uiRefListIdx ) )->getRefIdx( uiCandAbsPartIdx ) )
2555      {
2556        return false;
2557      }
2558    }
2559  }
2560
2561  return true;
2562}
2563
2564/** Constructs a list of merging candidates
2565 * \param uiAbsPartIdx
2566 * \param uiPUIdx
2567 * \param uiDepth
2568 * \param pcMvFieldNeighbours
2569 * \param puhInterDirNeighbours
2570 * \param numValidMergeCand
2571 */
2572Void TComDataCU::getInterMergeCandidates( UInt uiAbsPartIdx, UInt uiPUIdx, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int& numValidMergeCand, Int mrgCandIdx )
2573{
2574  UInt uiAbsPartAddr = m_uiAbsIdxInLCU + uiAbsPartIdx;
2575  Bool abCandIsInter[ MRG_MAX_NUM_CANDS ];
2576  for( UInt ui = 0; ui < getSlice()->getMaxNumMergeCand(); ++ui )
2577  {
2578    abCandIsInter[ui] = false;
2579    pcMvFieldNeighbours[ ( ui << 1 )     ].setRefIdx(NOT_VALID);
2580    pcMvFieldNeighbours[ ( ui << 1 ) + 1 ].setRefIdx(NOT_VALID);
2581  }
2582  numValidMergeCand = getSlice()->getMaxNumMergeCand();
2583  // compute the location of the current PU
2584  Int xP, yP, nPSW, nPSH;
2585  this->getPartPosition(uiPUIdx, xP, yP, nPSW, nPSH);
2586
2587  Int iCount = 0;
2588
2589  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB;
2590  PartSize cCurPS = getPartitionSize( uiAbsPartIdx );
2591  deriveLeftRightTopIdxGeneral( uiAbsPartIdx, uiPUIdx, uiPartIdxLT, uiPartIdxRT );
2592  deriveLeftBottomIdxGeneral  ( uiAbsPartIdx, uiPUIdx, uiPartIdxLB );
2593#if SVC_MVP
2594  // BL collocated
2595  TComDataCU *pcColCU = NULL;
2596  UInt uiCUAddrBase = 0, uiAbsPartAddrBase = 0;
2597#if AVC_BASE
2598  if( !this->getSlice()->getVPS()->getAvcBaseLayerFlag() || AVC_SYNTAX )
2599#endif
2600  {
2601    TComMvField cMvFieldBaseColCU[2];
2602    if(m_layerId) 
2603    {
2604      pcColCU = getBaseColCU( xP + nPSW/2, yP + nPSH/2, uiCUAddrBase, uiAbsPartAddrBase );
2605
2606#if INTRA_BL
2607      if( pcColCU && pcColCU->isIntraBL( uiAbsPartAddrBase ) )
2608      {
2609        pcColCU = NULL;
2610      }
2611#endif
2612
2613      if(pcColCU && !pcColCU->isIntra( uiAbsPartAddrBase ) )
2614      {
2615        abCandIsInter[iCount] = true;
2616
2617        // get interDir
2618        puhInterDirNeighbours[iCount] = pcColCU->getInterDir( uiAbsPartAddrBase );
2619
2620        pcMvFieldNeighbours[(iCount << 1)].setMvField( TComMv(0,0), -1);
2621        pcMvFieldNeighbours[(iCount << 1) + 1].setMvField( TComMv(0,0), -1);
2622
2623        if( puhInterDirNeighbours[iCount] & 1 )
2624        {
2625          pcColCU->getMvField( pcColCU, uiAbsPartAddrBase, REF_PIC_LIST_0, cMvFieldBaseColCU[0]);
2626          scaleBaseMV( pcMvFieldNeighbours[iCount<<1], cMvFieldBaseColCU[0] );
2627        }
2628
2629        if ( getSlice()->isInterB() && puhInterDirNeighbours[iCount] & 2 )
2630        {
2631          pcColCU->getMvField( pcColCU, uiAbsPartAddrBase, REF_PIC_LIST_1, cMvFieldBaseColCU[1] );
2632          scaleBaseMV( pcMvFieldNeighbours[(iCount<<1)+1], cMvFieldBaseColCU[1] );
2633        }
2634
2635        if( puhInterDirNeighbours[iCount] > 0 )
2636        {
2637          if ( mrgCandIdx == iCount )
2638          {
2639            return;
2640          }
2641          iCount ++;
2642        }
2643      }
2644    }
2645  }
2646#endif
2647
2648  //left
2649  UInt uiLeftPartIdx = 0;
2650  TComDataCU* pcCULeft = 0;
2651  pcCULeft = getPULeft( uiLeftPartIdx, uiPartIdxLB );
2652#if INTRA_BL
2653  if( pcCULeft && pcCULeft->isIntraBL( uiLeftPartIdx ) )
2654  {
2655    pcCULeft = NULL;
2656  }
2657#endif
2658  Bool isAvailableA1 = pcCULeft &&
2659  pcCULeft->isDiffMER(xP -1, yP+nPSH-1, xP, yP) &&
2660#if SVC_MVP
2661  ( !pcColCU || pcColCU->isIntra( uiAbsPartAddrBase ) || !pcCULeft->hasEqualMotion( uiLeftPartIdx, puhInterDirNeighbours[0], &pcMvFieldNeighbours[0])) &&
2662#endif
2663  !( uiPUIdx == 1 && (cCurPS == SIZE_Nx2N || cCurPS == SIZE_nLx2N || cCurPS == SIZE_nRx2N) ) &&
2664  !pcCULeft->isIntra( uiLeftPartIdx ) ;
2665  if ( isAvailableA1 )
2666  {
2667    abCandIsInter[iCount] = true;
2668    // get Inter Dir
2669    puhInterDirNeighbours[iCount] = pcCULeft->getInterDir( uiLeftPartIdx );
2670    // get Mv from Left
2671    pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
2672    if ( getSlice()->isInterB() )
2673    {
2674      pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
2675    }
2676    if ( mrgCandIdx == iCount )
2677    {
2678      return;
2679    }
2680    iCount ++;
2681  }
2682 
2683  // early termination
2684  if (iCount == getSlice()->getMaxNumMergeCand()) 
2685  {
2686    return;
2687  }
2688  // above
2689  UInt uiAbovePartIdx = 0;
2690  TComDataCU* pcCUAbove = 0;
2691  pcCUAbove = getPUAbove( uiAbovePartIdx, uiPartIdxRT );
2692#if INTRA_BL
2693  if( pcCUAbove && pcCUAbove->isIntraBL( uiAbovePartIdx ) )
2694  {
2695    pcCUAbove = NULL;
2696  }
2697#endif
2698  Bool isAvailableB1 = pcCUAbove &&
2699#if SVC_MVP
2700  ( !pcColCU || pcColCU->isIntra( uiAbsPartAddrBase ) || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, puhInterDirNeighbours[0], &pcMvFieldNeighbours[0] )) &&
2701#endif
2702  pcCUAbove->isDiffMER(xP+nPSW-1, yP-1, xP, yP) &&
2703  !( uiPUIdx == 1 && (cCurPS == SIZE_2NxN || cCurPS == SIZE_2NxnU || cCurPS == SIZE_2NxnD) ) &&
2704  !pcCUAbove->isIntra( uiAbovePartIdx );
2705  if ( isAvailableB1 && (!isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAbove, uiAbovePartIdx ) ) )
2706  {
2707    abCandIsInter[iCount] = true;
2708    // get Inter Dir
2709    puhInterDirNeighbours[iCount] = pcCUAbove->getInterDir( uiAbovePartIdx );
2710    // get Mv from Left
2711    pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
2712    if ( getSlice()->isInterB() )
2713    {
2714      pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
2715    }
2716    if ( mrgCandIdx == iCount )
2717    {
2718      return;
2719    }
2720    iCount ++;
2721  }
2722  // early termination
2723  if (iCount == getSlice()->getMaxNumMergeCand()) 
2724  {
2725    return;
2726  }
2727
2728  // above right
2729  UInt uiAboveRightPartIdx = 0;
2730  TComDataCU* pcCUAboveRight = 0;
2731  pcCUAboveRight = getPUAboveRight( uiAboveRightPartIdx, uiPartIdxRT );
2732#if INTRA_BL
2733  if( pcCUAboveRight && pcCUAboveRight->isIntraBL( uiAboveRightPartIdx ) )
2734  {
2735    pcCUAboveRight = NULL;
2736  }
2737#endif
2738  Bool isAvailableB0 = pcCUAboveRight &&
2739#if SVC_MVP && !IL_MRG_SIMPLIFIED_PRUNING
2740  ( !pcColCU || pcColCU->isIntra( uiAbsPartAddrBase ) || !pcCUAboveRight->hasEqualMotion( uiAboveRightPartIdx, puhInterDirNeighbours[0], &pcMvFieldNeighbours[0] )) &&
2741#endif
2742  pcCUAboveRight->isDiffMER(xP+nPSW, yP-1, xP, yP) &&
2743  !pcCUAboveRight->isIntra( uiAboveRightPartIdx );
2744  if ( isAvailableB0 && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveRight, uiAboveRightPartIdx ) ) )
2745  {
2746    abCandIsInter[iCount] = true;
2747    // get Inter Dir
2748    puhInterDirNeighbours[iCount] = pcCUAboveRight->getInterDir( uiAboveRightPartIdx );
2749    // get Mv from Left
2750    pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
2751    if ( getSlice()->isInterB() )
2752    {
2753      pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
2754    }
2755    if ( mrgCandIdx == iCount )
2756    {
2757      return;
2758    }
2759    iCount ++;
2760  }
2761  // early termination
2762  if (iCount == getSlice()->getMaxNumMergeCand()) 
2763  {
2764    return;
2765  }
2766
2767  //left bottom
2768#if SVC_MVP
2769  if( iCount < 4 )
2770  {
2771#endif
2772  UInt uiLeftBottomPartIdx = 0;
2773  TComDataCU* pcCULeftBottom = 0;
2774  pcCULeftBottom = this->getPUBelowLeft( uiLeftBottomPartIdx, uiPartIdxLB );
2775#if INTRA_BL
2776  if( pcCULeftBottom && pcCULeftBottom->isIntraBL( uiLeftBottomPartIdx ) )
2777  {
2778    pcCULeftBottom = NULL;
2779  }
2780#endif
2781  Bool isAvailableA0 = pcCULeftBottom &&
2782  pcCULeftBottom->isDiffMER(xP-1, yP+nPSH, xP, yP) &&
2783#if SVC_MVP && !IL_MRG_SIMPLIFIED_PRUNING
2784  ( !pcColCU || pcColCU->isIntra( uiAbsPartAddrBase ) || !pcCULeftBottom->hasEqualMotion( uiLeftBottomPartIdx, puhInterDirNeighbours[0], &pcMvFieldNeighbours[0])) &&
2785#endif
2786  !pcCULeftBottom->isIntra( uiLeftBottomPartIdx ) ;
2787  if ( isAvailableA0 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCULeftBottom, uiLeftBottomPartIdx ) ) )
2788  {
2789    abCandIsInter[iCount] = true;
2790    // get Inter Dir
2791    puhInterDirNeighbours[iCount] = pcCULeftBottom->getInterDir( uiLeftBottomPartIdx );
2792    // get Mv from Left
2793    pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
2794    if ( getSlice()->isInterB() )
2795    {
2796      pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
2797    }
2798    if ( mrgCandIdx == iCount )
2799    {
2800      return;
2801    }
2802    iCount ++;
2803  }
2804  // early termination
2805  if (iCount == getSlice()->getMaxNumMergeCand()) 
2806  {
2807    return;
2808  }
2809#if SVC_MVP
2810  }
2811#endif
2812
2813  // above left
2814  if( iCount < 4 )
2815  {
2816    UInt uiAboveLeftPartIdx = 0;
2817    TComDataCU* pcCUAboveLeft = 0;
2818    pcCUAboveLeft = getPUAboveLeft( uiAboveLeftPartIdx, uiAbsPartAddr );
2819#if INTRA_BL
2820    if( pcCUAboveLeft && pcCUAboveLeft->isIntraBL( uiAboveLeftPartIdx ) )
2821    {
2822      pcCUAboveLeft = NULL;
2823    }
2824#endif
2825    Bool isAvailableB2 = pcCUAboveLeft &&
2826    pcCUAboveLeft->isDiffMER(xP-1, yP-1, xP, yP) &&
2827#if SVC_MVP && !IL_MRG_SIMPLIFIED_PRUNING
2828    ( !pcColCU || pcColCU->isIntra( uiAbsPartAddrBase ) || !pcCUAboveLeft->hasEqualMotion( uiAboveLeftPartIdx, puhInterDirNeighbours[0], &pcMvFieldNeighbours[0] )) &&
2829#endif
2830    !pcCUAboveLeft->isIntra( uiAboveLeftPartIdx );
2831    if ( isAvailableB2 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) )
2832        && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) ) )
2833    {
2834      abCandIsInter[iCount] = true;
2835      // get Inter Dir
2836      puhInterDirNeighbours[iCount] = pcCUAboveLeft->getInterDir( uiAboveLeftPartIdx );
2837      // get Mv from Left
2838      pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
2839      if ( getSlice()->isInterB() )
2840      {
2841        pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
2842      }
2843      if ( mrgCandIdx == iCount )
2844      {
2845        return;
2846      }
2847      iCount ++;
2848    }
2849  }
2850  // early termination
2851  if (iCount == getSlice()->getMaxNumMergeCand()) 
2852  {
2853    return;
2854  }
2855  if ( getSlice()->getEnableTMVPFlag())
2856  {
2857    //>> MTK colocated-RightBottom
2858    UInt uiPartIdxRB;
2859    Int uiLCUIdx = getAddr();
2860
2861    deriveRightBottomIdx( uiPUIdx, uiPartIdxRB ); 
2862
2863    UInt uiAbsPartIdxTmp = g_auiZscanToRaster[uiPartIdxRB];
2864    UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
2865
2866    TComMv cColMv;
2867    Int iRefIdx;
2868
2869    if      ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
2870    {
2871      uiLCUIdx = -1;
2872    }
2873    else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxTmp] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
2874    {
2875      uiLCUIdx = -1;
2876    }
2877    else
2878    {
2879      if ( ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
2880        ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
2881      {
2882        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + uiNumPartInCUWidth + 1 ];
2883        uiLCUIdx = getAddr();
2884      }
2885      else if ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
2886      {
2887        uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdxTmp + uiNumPartInCUWidth + 1) % m_pcPic->getNumPartInCU() ];
2888        uiLCUIdx = -1 ; 
2889      }
2890      else if ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
2891      {
2892        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + 1 ];
2893        uiLCUIdx = getAddr() + 1;
2894      }
2895      else //is the right bottom corner of LCU                       
2896      {
2897        uiAbsPartAddr = 0;
2898        uiLCUIdx = -1 ; 
2899      }
2900    }
2901   
2902   
2903    iRefIdx = 0;
2904    Bool bExistMV = false;
2905    UInt uiPartIdxCenter;
2906    UInt uiCurLCUIdx = getAddr();
2907    Int dir = 0;
2908    UInt uiArrayAddr = iCount;
2909    xDeriveCenterIdx( uiPUIdx, uiPartIdxCenter );
2910    bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_0, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx );
2911    if( bExistMV == false )
2912    {
2913      bExistMV = xGetColMVP( REF_PIC_LIST_0, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
2914    }
2915    if( bExistMV )
2916    {
2917      dir |= 1;
2918      pcMvFieldNeighbours[ 2 * uiArrayAddr ].setMvField( cColMv, iRefIdx );
2919    }
2920   
2921    if ( getSlice()->isInterB() )
2922    {
2923      bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_1, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx);
2924      if( bExistMV == false )
2925      {
2926        bExistMV = xGetColMVP( REF_PIC_LIST_1, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
2927      }
2928      if( bExistMV )
2929      {
2930        dir |= 2;
2931        pcMvFieldNeighbours[ 2 * uiArrayAddr + 1 ].setMvField( cColMv, iRefIdx );
2932      }
2933    }
2934   
2935    if (dir != 0)
2936    {
2937      puhInterDirNeighbours[uiArrayAddr] = dir;
2938      abCandIsInter[uiArrayAddr] = true;
2939
2940      if ( mrgCandIdx == iCount )
2941      {
2942        return;
2943      }
2944      iCount++;
2945    }
2946  }
2947  // early termination
2948  if (iCount == getSlice()->getMaxNumMergeCand()) 
2949  {
2950    return;
2951  }
2952  UInt uiArrayAddr = iCount;
2953  UInt uiCutoff = uiArrayAddr;
2954   
2955  if ( getSlice()->isInterB())
2956  {
2957    UInt uiPriorityList0[12] = {0 , 1, 0, 2, 1, 2, 0, 3, 1, 3, 2, 3};
2958    UInt uiPriorityList1[12] = {1 , 0, 2, 0, 2, 1, 3, 0, 3, 1, 3, 2};
2959
2960    for (Int idx=0; idx<uiCutoff*(uiCutoff-1) && uiArrayAddr!= getSlice()->getMaxNumMergeCand(); idx++)
2961    {
2962      Int i = uiPriorityList0[idx]; Int j = uiPriorityList1[idx];
2963      if (abCandIsInter[i] && abCandIsInter[j]&& (puhInterDirNeighbours[i]&0x1)&&(puhInterDirNeighbours[j]&0x2))
2964      {
2965        abCandIsInter[uiArrayAddr] = true;
2966        puhInterDirNeighbours[uiArrayAddr] = 3;
2967
2968        // get Mv from cand[i] and cand[j]
2969        pcMvFieldNeighbours[uiArrayAddr << 1].setMvField(pcMvFieldNeighbours[i<<1].getMv(), pcMvFieldNeighbours[i<<1].getRefIdx());
2970        pcMvFieldNeighbours[( uiArrayAddr << 1 ) + 1].setMvField(pcMvFieldNeighbours[(j<<1)+1].getMv(), pcMvFieldNeighbours[(j<<1)+1].getRefIdx());
2971
2972        Int iRefPOCL0 = m_pcSlice->getRefPOC( REF_PIC_LIST_0, pcMvFieldNeighbours[(uiArrayAddr<<1)].getRefIdx() );
2973        Int iRefPOCL1 = m_pcSlice->getRefPOC( REF_PIC_LIST_1, pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getRefIdx() );
2974        if (iRefPOCL0 == iRefPOCL1 && pcMvFieldNeighbours[(uiArrayAddr<<1)].getMv() == pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getMv())
2975        {
2976          abCandIsInter[uiArrayAddr] = false;
2977        }
2978        else
2979        {
2980          uiArrayAddr++;
2981        }
2982      }
2983    }
2984  }
2985  // early termination
2986  if (uiArrayAddr == getSlice()->getMaxNumMergeCand()) 
2987  {
2988    return;
2989  }
2990  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);
2991  Int r = 0;
2992  Int refcnt = 0;
2993  while (uiArrayAddr < getSlice()->getMaxNumMergeCand())
2994  {
2995    abCandIsInter[uiArrayAddr] = true;
2996    puhInterDirNeighbours[uiArrayAddr] = 1;
2997    pcMvFieldNeighbours[uiArrayAddr << 1].setMvField( TComMv(0, 0), r);
2998
2999    if ( getSlice()->isInterB() )
3000    {
3001      puhInterDirNeighbours[uiArrayAddr] = 3;
3002      pcMvFieldNeighbours[(uiArrayAddr << 1) + 1].setMvField(TComMv(0, 0), r);
3003    }
3004    uiArrayAddr++;
3005    if ( refcnt == iNumRefIdx - 1 )
3006    {
3007      r = 0;
3008    }
3009    else
3010    {
3011      ++r;
3012      ++refcnt;
3013    }
3014  }
3015
3016  numValidMergeCand = uiArrayAddr;
3017}
3018
3019/** Check whether the current PU and a spatial neighboring PU are in a same ME region.
3020 * \param xN, xN   location of the upper-left corner pixel of a neighboring PU
3021 * \param xP, yP   location of the upper-left corner pixel of the current PU
3022 * \returns Bool
3023 */
3024Bool TComDataCU::isDiffMER(Int xN, Int yN, Int xP, Int yP)
3025{
3026
3027  UInt plevel = this->getSlice()->getPPS()->getLog2ParallelMergeLevelMinus2() + 2;
3028  if ((xN>>plevel)!= (xP>>plevel))
3029  {
3030    return true;
3031  }
3032  if ((yN>>plevel)!= (yP>>plevel))
3033  {
3034    return true;
3035  }
3036  return false;
3037}
3038/** calculate the location of upper-left corner pixel and size of the current PU.
3039 * \param partIdx  PU index within a CU
3040 * \param xP, yP   location of the upper-left corner pixel of the current PU
3041 * \param PSW, nPSH    size of the curren PU
3042 * \returns Void
3043 */
3044Void TComDataCU::getPartPosition( UInt partIdx, Int& xP, Int& yP, Int& nPSW, Int& nPSH)
3045{
3046  UInt col = m_uiCUPelX;
3047  UInt row = m_uiCUPelY;
3048
3049  switch ( m_pePartSize[0] )
3050  {
3051  case SIZE_2NxN:
3052    nPSW = getWidth(0);     
3053    nPSH = getHeight(0) >> 1; 
3054    xP   = col;
3055    yP   = (partIdx ==0)? row: row + nPSH;
3056    break;
3057  case SIZE_Nx2N:
3058    nPSW = getWidth(0) >> 1; 
3059    nPSH = getHeight(0);     
3060    xP   = (partIdx ==0)? col: col + nPSW;
3061    yP   = row;
3062    break;
3063  case SIZE_NxN:
3064    nPSW = getWidth(0) >> 1; 
3065    nPSH = getHeight(0) >> 1; 
3066    xP   = col + (partIdx&0x1)*nPSW;
3067    yP   = row + (partIdx>>1)*nPSH;
3068    break;
3069  case SIZE_2NxnU:
3070    nPSW = getWidth(0);
3071    nPSH = ( partIdx == 0 ) ?  getHeight(0) >> 2 : ( getHeight(0) >> 2 ) + ( getHeight(0) >> 1 );
3072    xP   = col;
3073    yP   = (partIdx ==0)? row: row + getHeight(0) - nPSH;
3074
3075    break;
3076  case SIZE_2NxnD:
3077    nPSW = getWidth(0);
3078    nPSH = ( partIdx == 0 ) ?  ( getHeight(0) >> 2 ) + ( getHeight(0) >> 1 ) : getHeight(0) >> 2;
3079    xP   = col;
3080    yP   = (partIdx ==0)? row: row + getHeight(0) - nPSH;
3081    break;
3082  case SIZE_nLx2N:
3083    nPSW = ( partIdx == 0 ) ? getWidth(0) >> 2 : ( getWidth(0) >> 2 ) + ( getWidth(0) >> 1 );
3084    nPSH = getHeight(0);
3085    xP   = (partIdx ==0)? col: col + getWidth(0) - nPSW;
3086    yP   = row;
3087    break;
3088  case SIZE_nRx2N:
3089    nPSW = ( partIdx == 0 ) ? ( getWidth(0) >> 2 ) + ( getWidth(0) >> 1 ) : getWidth(0) >> 2;
3090    nPSH = getHeight(0);
3091    xP   = (partIdx ==0)? col: col + getWidth(0) - nPSW;
3092    yP   = row;
3093    break;
3094  default:
3095    assert ( m_pePartSize[0] == SIZE_2Nx2N );
3096    nPSW = getWidth(0);     
3097    nPSH = getHeight(0);     
3098    xP   = col ;
3099    yP   = row ;
3100
3101    break;
3102  }
3103}
3104
3105/** Constructs a list of candidates for AMVP
3106 * \param uiPartIdx
3107 * \param uiPartAddr
3108 * \param eRefPicList
3109 * \param iRefIdx
3110 * \param pInfo
3111 */
3112Void TComDataCU::fillMvpCand ( UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, Int iRefIdx, AMVPInfo* pInfo )
3113{
3114  TComMv cMvPred;
3115  Bool bAddedSmvp = false;
3116
3117  pInfo->iN = 0; 
3118  if (iRefIdx < 0)
3119  {
3120    return;
3121  }
3122 
3123  //-- Get Spatial MV
3124  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB;
3125  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
3126  Bool bAdded = false;
3127 
3128  deriveLeftRightTopIdx( uiPartIdx, uiPartIdxLT, uiPartIdxRT );
3129  deriveLeftBottomIdx( uiPartIdx, uiPartIdxLB );
3130 
3131  TComDataCU* tmpCU = NULL;
3132  UInt idx;
3133  tmpCU = getPUBelowLeft(idx, uiPartIdxLB);
3134#if INTRA_BL
3135  bAddedSmvp = (tmpCU != NULL) && (!tmpCU->isIntra(idx));
3136#else
3137  bAddedSmvp = (tmpCU != NULL) && (tmpCU->getPredictionMode(idx) != MODE_INTRA);
3138#endif
3139
3140  if (!bAddedSmvp)
3141  {
3142    tmpCU = getPULeft(idx, uiPartIdxLB);
3143#if INTRA_BL
3144    bAddedSmvp = (tmpCU != NULL) && (!tmpCU->isIntra(idx));
3145#else
3146    bAddedSmvp = (tmpCU != NULL) && (tmpCU->getPredictionMode(idx) != MODE_INTRA);
3147#endif
3148  }
3149
3150  // Left predictor search
3151  bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_BELOW_LEFT);
3152  if (!bAdded) 
3153  {
3154    bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_LEFT );
3155  }
3156 
3157  if(!bAdded)
3158  {
3159    bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_BELOW_LEFT);
3160    if (!bAdded) 
3161    {
3162      bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_LEFT );
3163    }
3164  }
3165  // Above predictor search
3166  bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE_RIGHT);
3167
3168  if (!bAdded) 
3169  {
3170    bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE);
3171  }
3172
3173  if(!bAdded)
3174  {
3175    bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLT, MD_ABOVE_LEFT);
3176  }
3177  bAdded = bAddedSmvp;
3178  if (pInfo->iN==2) bAdded = true;
3179
3180  if(!bAdded)
3181  {
3182    bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE_RIGHT);
3183    if (!bAdded) 
3184    {
3185      bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE);
3186    }
3187
3188    if(!bAdded)
3189    {
3190      bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLT, MD_ABOVE_LEFT);
3191    }
3192  }
3193 
3194  if ( pInfo->iN == 2 )
3195  {
3196    if ( pInfo->m_acMvCand[ 0 ] == pInfo->m_acMvCand[ 1 ] )
3197    {
3198      pInfo->iN = 1;
3199    }
3200  }
3201
3202  if ( getSlice()->getEnableTMVPFlag() )
3203  {
3204    // Get Temporal Motion Predictor
3205    Int iRefIdx_Col = iRefIdx;
3206    TComMv cColMv;
3207    UInt uiPartIdxRB;
3208    UInt uiAbsPartIdx; 
3209    UInt uiAbsPartAddr;
3210    Int uiLCUIdx = getAddr();
3211
3212    deriveRightBottomIdx( uiPartIdx, uiPartIdxRB );
3213    uiAbsPartAddr = m_uiAbsIdxInLCU + uiPartAddr;
3214
3215    //----  co-located RightBottom Temporal Predictor (H) ---//
3216    uiAbsPartIdx = g_auiZscanToRaster[uiPartIdxRB];
3217    if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdx] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
3218    {
3219      uiLCUIdx = -1;
3220    }
3221    else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdx] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
3222    {
3223      uiLCUIdx = -1;
3224    }
3225    else
3226    {
3227      if ( ( uiAbsPartIdx % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
3228        ( uiAbsPartIdx / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
3229      {
3230        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdx + uiNumPartInCUWidth + 1 ];
3231        uiLCUIdx = getAddr();
3232      }
3233      else if ( uiAbsPartIdx % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
3234      {
3235        uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdx + uiNumPartInCUWidth + 1) % m_pcPic->getNumPartInCU() ];
3236        uiLCUIdx      = -1 ; 
3237      }
3238      else if ( uiAbsPartIdx / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
3239      {
3240        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdx + 1 ];
3241        uiLCUIdx = getAddr() + 1;
3242      }
3243      else //is the right bottom corner of LCU                       
3244      {
3245        uiAbsPartAddr = 0;
3246        uiLCUIdx      = -1 ; 
3247      }
3248    }
3249    if ( uiLCUIdx >= 0 && xGetColMVP( eRefPicList, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx_Col ) )
3250    {
3251      pInfo->m_acMvCand[pInfo->iN++] = cColMv;
3252    }
3253    else 
3254    {
3255      UInt uiPartIdxCenter;
3256      UInt uiCurLCUIdx = getAddr();
3257      xDeriveCenterIdx( uiPartIdx, uiPartIdxCenter );
3258      if (xGetColMVP( eRefPicList, uiCurLCUIdx, uiPartIdxCenter,  cColMv, iRefIdx_Col ))
3259      {
3260        pInfo->m_acMvCand[pInfo->iN++] = cColMv;
3261      }
3262    }
3263    //----  co-located RightBottom Temporal Predictor  ---//
3264  }
3265
3266  if (pInfo->iN > AMVP_MAX_NUM_CANDS)
3267  {
3268    pInfo->iN = AMVP_MAX_NUM_CANDS;
3269  }
3270  while (pInfo->iN < AMVP_MAX_NUM_CANDS)
3271  {
3272      pInfo->m_acMvCand[pInfo->iN].set(0,0);
3273      pInfo->iN++;
3274  }
3275  return ;
3276}
3277
3278Bool TComDataCU::isBipredRestriction(UInt puIdx)
3279{
3280  Int width = 0;
3281  Int height = 0;
3282  UInt partAddr;
3283
3284  getPartIndexAndSize( puIdx, partAddr, width, height );
3285  if ( getWidth(0) == 8 && (width < 8 || height < 8) )
3286  {
3287    return true;
3288  }
3289  return false;
3290}
3291
3292Void TComDataCU::clipMv    (TComMv&  rcMv)
3293{
3294  Int  iMvShift = 2;
3295  Int iOffset = 8;
3296  Int iHorMax = ( m_pcSlice->getSPS()->getPicWidthInLumaSamples() + iOffset - m_uiCUPelX - 1 ) << iMvShift;
3297  Int iHorMin = (       -(Int)g_uiMaxCUWidth - iOffset - (Int)m_uiCUPelX + 1 ) << iMvShift;
3298 
3299  Int iVerMax = ( m_pcSlice->getSPS()->getPicHeightInLumaSamples() + iOffset - m_uiCUPelY - 1 ) << iMvShift;
3300  Int iVerMin = (       -(Int)g_uiMaxCUHeight - iOffset - (Int)m_uiCUPelY + 1 ) << iMvShift;
3301 
3302  rcMv.setHor( min (iHorMax, max (iHorMin, rcMv.getHor())) );
3303  rcMv.setVer( min (iVerMax, max (iVerMin, rcMv.getVer())) );
3304}
3305
3306UInt TComDataCU::getIntraSizeIdx(UInt uiAbsPartIdx)
3307{
3308  UInt uiShift = ( (m_puhTrIdx[uiAbsPartIdx]==0) && (m_pePartSize[uiAbsPartIdx]==SIZE_NxN) ) ? m_puhTrIdx[uiAbsPartIdx]+1 : m_puhTrIdx[uiAbsPartIdx];
3309  uiShift = ( m_pePartSize[uiAbsPartIdx]==SIZE_NxN ? 1 : 0 );
3310 
3311  UChar uiWidth = m_puhWidth[uiAbsPartIdx]>>uiShift;
3312  UInt  uiCnt = 0;
3313  while( uiWidth )
3314  {
3315    uiCnt++;
3316    uiWidth>>=1;
3317  }
3318  uiCnt-=2;
3319  return uiCnt > 6 ? 6 : uiCnt;
3320}
3321
3322Void TComDataCU::clearCbf( UInt uiIdx, TextType eType, UInt uiNumParts )
3323{
3324  ::memset( &m_puhCbf[g_aucConvertTxtTypeToIdx[eType]][uiIdx], 0, sizeof(UChar)*uiNumParts);
3325}
3326
3327/** Set a I_PCM flag for all sub-partitions of a partition.
3328 * \param bIpcmFlag I_PCM flag
3329 * \param uiAbsPartIdx patition index
3330 * \param uiDepth CU depth
3331 * \returns Void
3332 */
3333Void TComDataCU::setIPCMFlagSubParts  (Bool bIpcmFlag, UInt uiAbsPartIdx, UInt uiDepth)
3334{
3335  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
3336
3337  memset(m_pbIPCMFlag + uiAbsPartIdx, bIpcmFlag, sizeof(Bool)*uiCurrPartNumb );
3338}
3339
3340/** Test whether the current block is skipped
3341 * \param uiPartIdx Block index
3342 * \returns Flag indicating whether the block is skipped
3343 */
3344Bool TComDataCU::isSkipped( UInt uiPartIdx )
3345{
3346  return ( getSkipFlag( uiPartIdx ) );
3347}
3348
3349// ====================================================================================================================
3350// Protected member functions
3351// ====================================================================================================================
3352
3353Bool TComDataCU::xAddMVPCand( AMVPInfo* pInfo, RefPicList eRefPicList, Int iRefIdx, UInt uiPartUnitIdx, MVP_DIR eDir )
3354{
3355  TComDataCU* pcTmpCU = NULL;
3356  UInt uiIdx;
3357  switch( eDir )
3358  {
3359    case MD_LEFT:
3360    {
3361      pcTmpCU = getPULeft(uiIdx, uiPartUnitIdx);
3362      break;
3363    }
3364    case MD_ABOVE:
3365    {
3366      pcTmpCU = getPUAbove(uiIdx, uiPartUnitIdx );
3367      break;
3368    }
3369    case MD_ABOVE_RIGHT:
3370    {
3371      pcTmpCU = getPUAboveRight(uiIdx, uiPartUnitIdx);
3372      break;
3373    }
3374    case MD_BELOW_LEFT:
3375    {
3376      pcTmpCU = getPUBelowLeft(uiIdx, uiPartUnitIdx);
3377      break;
3378    }
3379    case MD_ABOVE_LEFT:
3380    {
3381      pcTmpCU = getPUAboveLeft(uiIdx, uiPartUnitIdx);
3382      break;
3383    }
3384    default:
3385    {
3386      break;
3387    }
3388  }
3389
3390  if ( pcTmpCU == NULL )
3391  {
3392    return false;
3393  }
3394 
3395#if L0363_MVP_POC
3396  if ( pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) >= 0 && m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getPOC() == pcTmpCU->getSlice()->getRefPOC( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) ))
3397#else
3398  if ( m_pcSlice->isEqualRef(eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx), iRefIdx) )
3399#endif
3400  {
3401    TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
3402   
3403    pInfo->m_acMvCand[ pInfo->iN++] = cMvPred;
3404    return true;
3405  }
3406
3407  RefPicList eRefPicList2nd = REF_PIC_LIST_0;
3408  if(       eRefPicList == REF_PIC_LIST_0 )
3409  {
3410    eRefPicList2nd = REF_PIC_LIST_1;
3411  }
3412  else if ( eRefPicList == REF_PIC_LIST_1)
3413  {
3414    eRefPicList2nd = REF_PIC_LIST_0;
3415  }
3416
3417
3418  Int iCurrRefPOC = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getPOC();
3419  Int iNeibRefPOC;
3420
3421
3422  if( pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) >= 0 )
3423  {
3424    iNeibRefPOC = pcTmpCU->getSlice()->getRefPOC( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) );
3425    if( iNeibRefPOC == iCurrRefPOC ) // Same Reference Frame But Diff List//
3426    {
3427      TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList2nd)->getMv(uiIdx);
3428      pInfo->m_acMvCand[ pInfo->iN++] = cMvPred;
3429      return true;
3430    }
3431  }
3432  return false;
3433}
3434
3435/**
3436 * \param pInfo
3437 * \param eRefPicList
3438 * \param iRefIdx
3439 * \param uiPartUnitIdx
3440 * \param eDir
3441 * \returns Bool
3442 */
3443Bool TComDataCU::xAddMVPCandOrder( AMVPInfo* pInfo, RefPicList eRefPicList, Int iRefIdx, UInt uiPartUnitIdx, MVP_DIR eDir )
3444{
3445  TComDataCU* pcTmpCU = NULL;
3446  UInt uiIdx;
3447  switch( eDir )
3448  {
3449  case MD_LEFT:
3450    {
3451      pcTmpCU = getPULeft(uiIdx, uiPartUnitIdx);
3452      break;
3453    }
3454  case MD_ABOVE:
3455    {
3456      pcTmpCU = getPUAbove(uiIdx, uiPartUnitIdx);
3457      break;
3458    }
3459  case MD_ABOVE_RIGHT:
3460    {
3461      pcTmpCU = getPUAboveRight(uiIdx, uiPartUnitIdx);
3462      break;
3463    }
3464  case MD_BELOW_LEFT:
3465    {
3466      pcTmpCU = getPUBelowLeft(uiIdx, uiPartUnitIdx);
3467      break;
3468    }
3469  case MD_ABOVE_LEFT:
3470    {
3471      pcTmpCU = getPUAboveLeft(uiIdx, uiPartUnitIdx);
3472      break;
3473    }
3474  default:
3475    {
3476      break;
3477    }
3478  }
3479
3480  if ( pcTmpCU == NULL ) 
3481  {
3482    return false;
3483  }
3484 
3485  RefPicList eRefPicList2nd = REF_PIC_LIST_0;
3486  if(       eRefPicList == REF_PIC_LIST_0 )
3487  {
3488    eRefPicList2nd = REF_PIC_LIST_1;
3489  }
3490  else if ( eRefPicList == REF_PIC_LIST_1)
3491  {
3492    eRefPicList2nd = REF_PIC_LIST_0;
3493  }
3494
3495  Int iCurrPOC = m_pcSlice->getPOC();
3496  Int iCurrRefPOC = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getPOC();
3497  Int iNeibPOC = iCurrPOC;
3498  Int iNeibRefPOC;
3499
3500  Bool bIsCurrRefLongTerm = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getIsLongTerm();
3501  Bool bIsNeibRefLongTerm = false;
3502  //---------------  V1 (END) ------------------//
3503  if( pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) >= 0)
3504  {
3505    iNeibRefPOC = pcTmpCU->getSlice()->getRefPOC( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) );
3506    TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
3507    TComMv rcMv;
3508
3509    bIsNeibRefLongTerm = pcTmpCU->getSlice()->getRefPic( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) )->getIsLongTerm();
3510    if ( bIsCurrRefLongTerm == bIsNeibRefLongTerm ) 
3511    {
3512    if ( bIsCurrRefLongTerm || bIsNeibRefLongTerm )
3513    {
3514      rcMv = cMvPred;
3515    }
3516    else
3517    {
3518      Int iScale = xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
3519      if ( iScale == 4096 )
3520      {
3521        rcMv = cMvPred;
3522      }
3523      else
3524      {
3525        rcMv = cMvPred.scaleMv( iScale );
3526      }
3527    }
3528    pInfo->m_acMvCand[ pInfo->iN++] = rcMv;
3529    return true;
3530    }
3531  }
3532  //---------------------- V2(END) --------------------//
3533  if( pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) >= 0)
3534  {
3535    iNeibRefPOC = pcTmpCU->getSlice()->getRefPOC( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) );
3536    TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList2nd)->getMv(uiIdx);
3537    TComMv rcMv;
3538
3539    bIsNeibRefLongTerm = pcTmpCU->getSlice()->getRefPic( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) )->getIsLongTerm();
3540    if ( bIsCurrRefLongTerm == bIsNeibRefLongTerm ) 
3541    {
3542    if ( bIsCurrRefLongTerm || bIsNeibRefLongTerm )
3543    {
3544      rcMv = cMvPred;
3545    }
3546    else
3547    {
3548      Int iScale = xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
3549      if ( iScale == 4096 )
3550      {
3551        rcMv = cMvPred;
3552      }
3553      else
3554      {
3555        rcMv = cMvPred.scaleMv( iScale );
3556      }
3557    }
3558    pInfo->m_acMvCand[ pInfo->iN++] = rcMv;
3559    return true;
3560    }
3561  }
3562  //---------------------- V3(END) --------------------//
3563  return false;
3564}
3565
3566/**
3567 * \param eRefPicList
3568 * \param uiCUAddr
3569 * \param uiPartUnitIdx
3570 * \param riRefIdx
3571 * \returns Bool
3572 */
3573Bool TComDataCU::xGetColMVP( RefPicList eRefPicList, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv, Int& riRefIdx )
3574{
3575  UInt uiAbsPartAddr = uiPartUnitIdx;
3576
3577  RefPicList  eColRefPicList;
3578  Int iColPOC, iColRefPOC, iCurrPOC, iCurrRefPOC, iScale;
3579  TComMv cColMv;
3580
3581  // use coldir.
3582  TComPic *pColPic = getSlice()->getRefPic( RefPicList(getSlice()->isInterB() ? 1-getSlice()->getColFromL0Flag() : 0), getSlice()->getColRefIdx());
3583  TComDataCU *pColCU = pColPic->getCU( uiCUAddr );
3584  if(pColCU->getPic()==0||pColCU->getPartitionSize(uiPartUnitIdx)==SIZE_NONE)
3585  {
3586    return false;
3587  }
3588  iCurrPOC = m_pcSlice->getPOC();   
3589  iCurrRefPOC = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getPOC();
3590  iColPOC = pColCU->getSlice()->getPOC(); 
3591
3592  if (pColCU->isIntra(uiAbsPartAddr))
3593  {
3594    return false;
3595  }
3596  eColRefPicList = getSlice()->getCheckLDC() ? eRefPicList : RefPicList(getSlice()->getColFromL0Flag());
3597
3598  Int iColRefIdx = pColCU->getCUMvField(RefPicList(eColRefPicList))->getRefIdx(uiAbsPartAddr);
3599
3600  if (iColRefIdx < 0 )
3601  {
3602    eColRefPicList = RefPicList(1 - eColRefPicList);
3603    iColRefIdx = pColCU->getCUMvField(RefPicList(eColRefPicList))->getRefIdx(uiAbsPartAddr);
3604
3605    if (iColRefIdx < 0 )
3606    {
3607      return false;
3608    }
3609  }
3610
3611  // Scale the vector.
3612  iColRefPOC = pColCU->getSlice()->getRefPOC(eColRefPicList, iColRefIdx);
3613  cColMv = pColCU->getCUMvField(eColRefPicList)->getMv(uiAbsPartAddr);
3614
3615  iCurrRefPOC = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getPOC();
3616  Bool bIsCurrRefLongTerm = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getIsLongTerm();
3617  Bool bIsColRefLongTerm = pColCU->getSlice()->getIsUsedAsLongTerm(eColRefPicList, iColRefIdx);
3618
3619  if ( bIsCurrRefLongTerm != bIsColRefLongTerm ) 
3620  {
3621    return false;
3622  }
3623
3624  if ( bIsCurrRefLongTerm || bIsColRefLongTerm )
3625  {
3626    rcMv = cColMv;
3627  }
3628  else
3629  {
3630    iScale = xGetDistScaleFactor(iCurrPOC, iCurrRefPOC, iColPOC, iColRefPOC);
3631    if ( iScale == 4096 )
3632    {
3633      rcMv = cColMv;
3634    }
3635    else
3636    {
3637      rcMv = cColMv.scaleMv( iScale );
3638    }
3639  }
3640  return true;
3641}
3642
3643UInt TComDataCU::xGetMvdBits(TComMv cMvd)
3644{
3645  return ( xGetComponentBits(cMvd.getHor()) + xGetComponentBits(cMvd.getVer()) );
3646}
3647
3648UInt TComDataCU::xGetComponentBits(Int iVal)
3649{
3650  UInt uiLength = 1;
3651  UInt uiTemp   = ( iVal <= 0) ? (-iVal<<1)+1: (iVal<<1);
3652 
3653  assert ( uiTemp );
3654 
3655  while ( 1 != uiTemp )
3656  {
3657    uiTemp >>= 1;
3658    uiLength += 2;
3659  }
3660 
3661  return uiLength;
3662}
3663
3664
3665Int TComDataCU::xGetDistScaleFactor(Int iCurrPOC, Int iCurrRefPOC, Int iColPOC, Int iColRefPOC)
3666{
3667  Int iDiffPocD = iColPOC - iColRefPOC;
3668  Int iDiffPocB = iCurrPOC - iCurrRefPOC;
3669 
3670  if( iDiffPocD == iDiffPocB )
3671  {
3672    return 4096;
3673  }
3674  else
3675  {
3676    Int iTDB      = Clip3( -128, 127, iDiffPocB );
3677    Int iTDD      = Clip3( -128, 127, iDiffPocD );
3678    Int iX        = (0x4000 + abs(iTDD/2)) / iTDD;
3679    Int iScale    = Clip3( -4096, 4095, (iTDB * iX + 32) >> 6 );
3680    return iScale;
3681  }
3682}
3683
3684/**
3685 * \param eCUMode
3686 * \param uiPartIdx
3687 * \param ruiPartIdxCenter
3688 * \returns Void
3689 */
3690Void TComDataCU::xDeriveCenterIdx( UInt uiPartIdx, UInt& ruiPartIdxCenter )
3691{
3692  UInt uiPartAddr;
3693  Int  iPartWidth;
3694  Int  iPartHeight;
3695  getPartIndexAndSize( uiPartIdx, uiPartAddr, iPartWidth, iPartHeight);
3696 
3697  ruiPartIdxCenter = m_uiAbsIdxInLCU+uiPartAddr; // partition origin.
3698  ruiPartIdxCenter = g_auiRasterToZscan[ g_auiZscanToRaster[ ruiPartIdxCenter ]
3699                                        + ( iPartHeight/m_pcPic->getMinCUHeight()  )/2*m_pcPic->getNumPartInWidth()
3700                                        + ( iPartWidth/m_pcPic->getMinCUWidth()  )/2];
3701}
3702
3703Void TComDataCU::compressMV()
3704{
3705  Int scaleFactor = 4 * AMVP_DECIMATION_FACTOR / m_unitSize;
3706  if (scaleFactor > 0)
3707  {
3708#if SVC_MVP
3709    m_acCUMvField[0].compress(m_pePredMode, m_puhInterDir, scaleFactor);
3710    m_acCUMvField[1].compress(m_pePredMode, m_puhInterDir, scaleFactor);   
3711#else
3712    m_acCUMvField[0].compress(m_pePredMode, scaleFactor);
3713    m_acCUMvField[1].compress(m_pePredMode, scaleFactor);   
3714#endif
3715  }
3716}
3717
3718UInt TComDataCU::getCoefScanIdx(UInt uiAbsPartIdx, UInt uiWidth, Bool bIsLuma, Bool bIsIntra)
3719{
3720  UInt uiCTXIdx;
3721  UInt uiScanIdx;
3722  UInt uiDirMode;
3723
3724  if ( !bIsIntra ) 
3725  {
3726    uiScanIdx = SCAN_DIAG;
3727    return uiScanIdx;
3728  }
3729
3730  switch(uiWidth)
3731  {
3732    case  2: uiCTXIdx = 6; break;
3733    case  4: uiCTXIdx = 5; break;
3734    case  8: uiCTXIdx = 4; break;
3735    case 16: uiCTXIdx = 3; break;
3736    case 32: uiCTXIdx = 2; break;
3737    case 64: uiCTXIdx = 1; break;
3738    default: uiCTXIdx = 0; break;
3739  }
3740
3741  if ( bIsLuma )
3742  {
3743    uiDirMode = getLumaIntraDir(uiAbsPartIdx);
3744    uiScanIdx = SCAN_DIAG;
3745    if (uiCTXIdx >3 && uiCTXIdx < 6) //if multiple scans supported for transform size
3746    {
3747      uiScanIdx = abs((Int) uiDirMode - VER_IDX) < 5 ? SCAN_HOR : (abs((Int)uiDirMode - HOR_IDX) < 5 ? SCAN_VER : SCAN_DIAG);
3748    }
3749  }
3750  else
3751  {
3752    uiDirMode = getChromaIntraDir(uiAbsPartIdx);
3753    if( uiDirMode == DM_CHROMA_IDX )
3754    {
3755      // get number of partitions in current CU
3756      UInt depth = getDepth(uiAbsPartIdx);
3757      UInt numParts = getPic()->getNumPartInCU() >> (2 * depth);
3758     
3759      // get luma mode from upper-left corner of current CU
3760      uiDirMode = getLumaIntraDir((uiAbsPartIdx/numParts)*numParts);
3761    }
3762    uiScanIdx = SCAN_DIAG;
3763    if (uiCTXIdx >4 && uiCTXIdx < 7) //if multiple scans supported for transform size
3764    {
3765      uiScanIdx = abs((Int) uiDirMode - VER_IDX) < 5 ? SCAN_HOR : (abs((Int)uiDirMode - HOR_IDX) < 5 ? SCAN_VER : SCAN_DIAG);
3766    }
3767  }
3768
3769  return uiScanIdx;
3770}
3771
3772UInt TComDataCU::getSCUAddr()
3773{ 
3774  return getPic()->getPicSym()->getInverseCUOrderMap(m_uiCUAddr)*(1<<(m_pcSlice->getSPS()->getMaxCUDepth()<<1))+m_uiAbsIdxInLCU; 
3775}
3776
3777/** Set neighboring blocks availabilities for non-deblocked filtering
3778 * \param numLCUInPicWidth number of LCUs in picture width
3779 * \param numLCUInPicHeight number of LCUs in picture height
3780 * \param numSUInLCUWidth number of SUs in LCU width
3781 * \param numSUInLCUHeight number of SUs in LCU height
3782 * \param picWidth picture width
3783 * \param picHeight picture height
3784 * \param bIndependentSliceBoundaryEnabled true for independent slice boundary enabled
3785 * \param bTopTileBoundary true means that top boundary coincides tile boundary
3786 * \param bDownTileBoundary true means that bottom boundary coincides tile boundary
3787 * \param bLeftTileBoundary true means that left boundary coincides tile boundary
3788 * \param bRightTileBoundary true means that right boundary coincides tile boundary
3789 * \param bIndependentTileBoundaryEnabled true for independent tile boundary enabled
3790 */
3791Void TComDataCU::setNDBFilterBlockBorderAvailability(UInt numLCUInPicWidth, UInt /*numLCUInPicHeight*/, UInt numSUInLCUWidth, UInt numSUInLCUHeight, UInt picWidth, UInt picHeight
3792                                                    ,std::vector<Bool>& LFCrossSliceBoundary
3793                                                    ,Bool bTopTileBoundary, Bool bDownTileBoundary, Bool bLeftTileBoundary, Bool bRightTileBoundary
3794                                                    ,Bool bIndependentTileBoundaryEnabled)
3795{
3796  UInt numSUInLCU = numSUInLCUWidth*numSUInLCUHeight;
3797  Int* pSliceIDMapLCU = m_piSliceSUMap;
3798  Bool onlyOneSliceInPic = ((Int)LFCrossSliceBoundary.size() == 1);
3799  UInt uiLPelX, uiTPelY;
3800  UInt width, height;
3801  Bool bPicRBoundary, bPicBBoundary, bPicTBoundary, bPicLBoundary;
3802  Bool bLCURBoundary= false, bLCUBBoundary= false, bLCUTBoundary= false, bLCULBoundary= false;
3803  Bool* pbAvailBorder;
3804  Bool* pbAvail;
3805  UInt rTLSU, rBRSU, widthSU, heightSU;
3806  UInt zRefSU;
3807  Int* pRefID;
3808  Int* pRefMapLCU;
3809  UInt rTRefSU= 0, rBRefSU= 0, rLRefSU= 0, rRRefSU= 0;
3810  Int* pRRefMapLCU= NULL;
3811  Int* pLRefMapLCU= NULL;
3812  Int* pTRefMapLCU= NULL;
3813  Int* pBRefMapLCU= NULL;
3814  Int  sliceID;
3815  UInt numSGU = (UInt)m_vNDFBlock.size();
3816
3817  for(Int i=0; i< numSGU; i++)
3818  {
3819    NDBFBlockInfo& rSGU = m_vNDFBlock[i];
3820
3821    sliceID = rSGU.sliceID;
3822    uiLPelX = rSGU.posX;
3823    uiTPelY = rSGU.posY;
3824    width   = rSGU.width;
3825    height  = rSGU.height;
3826    rTLSU     = g_auiZscanToRaster[ rSGU.startSU ];
3827    rBRSU     = g_auiZscanToRaster[ rSGU.endSU   ];
3828    widthSU   = rSGU.widthSU;
3829    heightSU  = rSGU.heightSU;
3830
3831    pbAvailBorder = rSGU.isBorderAvailable;
3832
3833    bPicTBoundary= (uiTPelY == 0                       )?(true):(false);
3834    bPicLBoundary= (uiLPelX == 0                       )?(true):(false);
3835    bPicRBoundary= (!(uiLPelX+ width < picWidth )  )?(true):(false);
3836    bPicBBoundary= (!(uiTPelY + height < picHeight))?(true):(false);
3837
3838    bLCULBoundary = (rTLSU % numSUInLCUWidth == 0)?(true):(false);
3839    bLCURBoundary = ( (rTLSU+ widthSU) % numSUInLCUWidth == 0)?(true):(false);
3840    bLCUTBoundary = ( (UInt)(rTLSU / numSUInLCUWidth)== 0)?(true):(false);
3841    bLCUBBoundary = ( (UInt)(rBRSU / numSUInLCUWidth) == (numSUInLCUHeight-1) )?(true):(false);
3842
3843    //       SGU_L
3844    pbAvail = &(pbAvailBorder[SGU_L]);
3845    if(bPicLBoundary)
3846    {
3847      *pbAvail = false;
3848    }
3849    else if (onlyOneSliceInPic)
3850    {
3851      *pbAvail = true;
3852    }
3853    else
3854    {
3855      //      bLCULBoundary = (rTLSU % uiNumSUInLCUWidth == 0)?(true):(false);
3856      if(bLCULBoundary)
3857      {
3858        rLRefSU     = rTLSU + numSUInLCUWidth -1;
3859        zRefSU      = g_auiRasterToZscan[rLRefSU];
3860        pRefMapLCU = pLRefMapLCU= (pSliceIDMapLCU - numSUInLCU);
3861      }
3862      else
3863      {
3864        zRefSU   = g_auiRasterToZscan[rTLSU - 1];
3865        pRefMapLCU  = pSliceIDMapLCU;
3866      }
3867      pRefID = pRefMapLCU + zRefSU;
3868      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
3869    }
3870
3871    //       SGU_R
3872    pbAvail = &(pbAvailBorder[SGU_R]);
3873    if(bPicRBoundary)
3874    {
3875      *pbAvail = false;
3876    }
3877    else if (onlyOneSliceInPic)
3878    {
3879      *pbAvail = true;
3880    }
3881    else
3882    {
3883      //       bLCURBoundary = ( (rTLSU+ uiWidthSU) % uiNumSUInLCUWidth == 0)?(true):(false);
3884      if(bLCURBoundary)
3885      {
3886        rRRefSU      = rTLSU + widthSU - numSUInLCUWidth;
3887        zRefSU       = g_auiRasterToZscan[rRRefSU];
3888        pRefMapLCU  = pRRefMapLCU= (pSliceIDMapLCU + numSUInLCU);
3889      }
3890      else
3891      {
3892        zRefSU       = g_auiRasterToZscan[rTLSU + widthSU];
3893        pRefMapLCU  = pSliceIDMapLCU;
3894      }
3895      pRefID = pRefMapLCU + zRefSU;
3896      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
3897    }
3898
3899    //       SGU_T
3900    pbAvail = &(pbAvailBorder[SGU_T]);
3901    if(bPicTBoundary)
3902    {
3903      *pbAvail = false;
3904    }
3905    else if (onlyOneSliceInPic)
3906    {
3907      *pbAvail = true;
3908    }
3909    else
3910    {
3911      //      bLCUTBoundary = ( (UInt)(rTLSU / uiNumSUInLCUWidth)== 0)?(true):(false);
3912      if(bLCUTBoundary)
3913      {
3914        rTRefSU      = numSUInLCU - (numSUInLCUWidth - rTLSU);
3915        zRefSU       = g_auiRasterToZscan[rTRefSU];
3916        pRefMapLCU  = pTRefMapLCU= (pSliceIDMapLCU - (numLCUInPicWidth*numSUInLCU));
3917      }
3918      else
3919      {
3920        zRefSU       = g_auiRasterToZscan[rTLSU - numSUInLCUWidth];
3921        pRefMapLCU  = pSliceIDMapLCU;
3922      }
3923      pRefID = pRefMapLCU + zRefSU;
3924      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
3925    }
3926
3927    //       SGU_B
3928    pbAvail = &(pbAvailBorder[SGU_B]);
3929    if(bPicBBoundary)
3930    {
3931      *pbAvail = false;
3932    }
3933    else if (onlyOneSliceInPic)
3934    {
3935      *pbAvail = true;
3936    }
3937    else
3938    {
3939      //      bLCUBBoundary = ( (UInt)(rBRSU / uiNumSUInLCUWidth) == (uiNumSUInLCUHeight-1) )?(true):(false);
3940      if(bLCUBBoundary)
3941      {
3942        rBRefSU      = rTLSU % numSUInLCUWidth;
3943        zRefSU       = g_auiRasterToZscan[rBRefSU];
3944        pRefMapLCU  = pBRefMapLCU= (pSliceIDMapLCU + (numLCUInPicWidth*numSUInLCU));
3945      }
3946      else
3947      {
3948        zRefSU       = g_auiRasterToZscan[rTLSU + (heightSU*numSUInLCUWidth)];
3949        pRefMapLCU  = pSliceIDMapLCU;
3950      }
3951      pRefID = pRefMapLCU + zRefSU;
3952      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
3953    }
3954
3955    //       SGU_TL
3956    pbAvail = &(pbAvailBorder[SGU_TL]);
3957    if(bPicTBoundary || bPicLBoundary)
3958    {
3959      *pbAvail = false;
3960    }
3961    else if (onlyOneSliceInPic)
3962    {
3963      *pbAvail = true;
3964    }
3965    else
3966    {
3967      if(bLCUTBoundary && bLCULBoundary)
3968      {
3969        zRefSU       = numSUInLCU -1;
3970        pRefMapLCU  = pSliceIDMapLCU - ( (numLCUInPicWidth+1)*numSUInLCU);
3971      }
3972      else if(bLCUTBoundary)
3973      {
3974        zRefSU       = g_auiRasterToZscan[ rTRefSU- 1];
3975        pRefMapLCU  = pTRefMapLCU;
3976      }
3977      else if(bLCULBoundary)
3978      {
3979        zRefSU       = g_auiRasterToZscan[ rLRefSU- numSUInLCUWidth ];
3980        pRefMapLCU  = pLRefMapLCU;
3981      }
3982      else //inside LCU
3983      {
3984        zRefSU       = g_auiRasterToZscan[ rTLSU - numSUInLCUWidth -1];
3985        pRefMapLCU  = pSliceIDMapLCU;
3986      }
3987      pRefID = pRefMapLCU + zRefSU;
3988      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
3989    }
3990
3991    //       SGU_TR
3992    pbAvail = &(pbAvailBorder[SGU_TR]);
3993    if(bPicTBoundary || bPicRBoundary)
3994    {
3995      *pbAvail = false;
3996    }
3997    else if (onlyOneSliceInPic)
3998    {
3999      *pbAvail = true;
4000    }
4001    else
4002    {
4003      if(bLCUTBoundary && bLCURBoundary)
4004      {
4005        zRefSU      = g_auiRasterToZscan[numSUInLCU - numSUInLCUWidth];
4006        pRefMapLCU  = pSliceIDMapLCU - ( (numLCUInPicWidth-1)*numSUInLCU);       
4007      }
4008      else if(bLCUTBoundary)
4009      {
4010        zRefSU       = g_auiRasterToZscan[ rTRefSU+ widthSU];
4011        pRefMapLCU  = pTRefMapLCU;
4012      }
4013      else if(bLCURBoundary)
4014      {
4015        zRefSU       = g_auiRasterToZscan[ rRRefSU- numSUInLCUWidth ];
4016        pRefMapLCU  = pRRefMapLCU;
4017      }
4018      else //inside LCU
4019      {
4020        zRefSU       = g_auiRasterToZscan[ rTLSU - numSUInLCUWidth +widthSU];
4021        pRefMapLCU  = pSliceIDMapLCU;
4022      }
4023      pRefID = pRefMapLCU + zRefSU;
4024      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
4025    }
4026
4027    //       SGU_BL
4028    pbAvail = &(pbAvailBorder[SGU_BL]);
4029    if(bPicBBoundary || bPicLBoundary)
4030    {
4031      *pbAvail = false;
4032    }
4033    else if (onlyOneSliceInPic)
4034    {
4035      *pbAvail = true;
4036    }
4037    else
4038    {
4039      if(bLCUBBoundary && bLCULBoundary)
4040      {
4041        zRefSU      = g_auiRasterToZscan[numSUInLCUWidth - 1];
4042        pRefMapLCU  = pSliceIDMapLCU + ( (numLCUInPicWidth-1)*numSUInLCU);       
4043      }
4044      else if(bLCUBBoundary)
4045      {
4046        zRefSU       = g_auiRasterToZscan[ rBRefSU - 1];
4047        pRefMapLCU  = pBRefMapLCU;
4048      }
4049      else if(bLCULBoundary)
4050      {
4051        zRefSU       = g_auiRasterToZscan[ rLRefSU+ heightSU*numSUInLCUWidth ];
4052        pRefMapLCU  = pLRefMapLCU;
4053      }
4054      else //inside LCU
4055      {
4056        zRefSU       = g_auiRasterToZscan[ rTLSU + heightSU*numSUInLCUWidth -1];
4057        pRefMapLCU  = pSliceIDMapLCU;
4058      }
4059      pRefID = pRefMapLCU + zRefSU;
4060      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
4061    }
4062
4063    //       SGU_BR
4064    pbAvail = &(pbAvailBorder[SGU_BR]);
4065    if(bPicBBoundary || bPicRBoundary)
4066    {
4067      *pbAvail = false;
4068    }
4069    else if (onlyOneSliceInPic)
4070    {
4071      *pbAvail = true;
4072    }
4073    else
4074    {
4075      if(bLCUBBoundary && bLCURBoundary)
4076      {
4077        zRefSU = 0;
4078        pRefMapLCU = pSliceIDMapLCU+ ( (numLCUInPicWidth+1)*numSUInLCU);
4079      }
4080      else if(bLCUBBoundary)
4081      {
4082        zRefSU      = g_auiRasterToZscan[ rBRefSU + widthSU];
4083        pRefMapLCU = pBRefMapLCU;
4084      }
4085      else if(bLCURBoundary)
4086      {
4087        zRefSU      = g_auiRasterToZscan[ rRRefSU + (heightSU*numSUInLCUWidth)];
4088        pRefMapLCU = pRRefMapLCU;
4089      }
4090      else //inside LCU
4091      {
4092        zRefSU      = g_auiRasterToZscan[ rTLSU + (heightSU*numSUInLCUWidth)+ widthSU];
4093        pRefMapLCU = pSliceIDMapLCU;
4094      }
4095      pRefID = pRefMapLCU + zRefSU;
4096      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
4097    }
4098
4099    if(bIndependentTileBoundaryEnabled)
4100    {
4101      //left LCU boundary
4102      if(!bPicLBoundary && bLCULBoundary)
4103      {
4104        if(bLeftTileBoundary)
4105        {
4106          pbAvailBorder[SGU_L] = pbAvailBorder[SGU_TL] = pbAvailBorder[SGU_BL] = false;
4107        }
4108      }
4109      //right LCU boundary
4110      if(!bPicRBoundary && bLCURBoundary)
4111      {
4112        if(bRightTileBoundary)
4113        {
4114          pbAvailBorder[SGU_R] = pbAvailBorder[SGU_TR] = pbAvailBorder[SGU_BR] = false;
4115        }
4116      }
4117      //top LCU boundary
4118      if(!bPicTBoundary && bLCUTBoundary)
4119      {
4120        if(bTopTileBoundary)
4121        {
4122          pbAvailBorder[SGU_T] = pbAvailBorder[SGU_TL] = pbAvailBorder[SGU_TR] = false;
4123        }
4124      }
4125      //down LCU boundary
4126      if(!bPicBBoundary && bLCUBBoundary)
4127      {
4128        if(bDownTileBoundary)
4129        {
4130          pbAvailBorder[SGU_B] = pbAvailBorder[SGU_BL] = pbAvailBorder[SGU_BR] = false;
4131        }
4132      }
4133    }
4134    rSGU.allBordersAvailable = true;
4135    for(Int b=0; b< NUM_SGU_BORDER; b++)
4136    {
4137      if(pbAvailBorder[b] == false)
4138      {
4139        rSGU.allBordersAvailable = false;
4140        break;
4141      }
4142    }
4143  }
4144}
4145
4146#if INTRA_BL && !NO_RESIDUAL_FLAG_FOR_BLPRED
4147Void TComDataCU::getBaseLumaBlk ( UInt uiWidth, UInt uiHeight, UInt uiAbsPartIdx, Pel* piPred, UInt uiStride )
4148{
4149  TComPicYuv* pcBaseRec = getSlice()->getFullPelBaseRec();
4150  UInt uiStrideBase = pcBaseRec->getStride();
4151  Pel* piBase = pcBaseRec->getLumaAddr( getAddr(), getZorderIdxInCU() + uiAbsPartIdx );
4152 
4153  for ( UInt y = 0; y < uiHeight; y ++ )
4154  {
4155    memcpy( piPred + y * uiStride, piBase + y * uiStrideBase, uiWidth * sizeof( Pel ) );
4156  }
4157}
4158
4159Void TComDataCU::getBaseChromaBlk ( UInt uiWidth, UInt uiHeight, UInt uiAbsPartIdx, Pel* piPred, UInt uiStride, UInt uiChromaId )
4160{
4161  TComPicYuv* pcBaseRec = getSlice()->getFullPelBaseRec();
4162
4163  UInt uiStrideBase = pcBaseRec->getCStride();
4164  Pel* piBase;
4165 
4166  if( uiChromaId == 0 )
4167  {
4168    piBase = pcBaseRec->getCbAddr( getAddr(), getZorderIdxInCU() + uiAbsPartIdx );
4169  }
4170  else
4171  {
4172    piBase = pcBaseRec->getCrAddr( getAddr(), getZorderIdxInCU() + uiAbsPartIdx );
4173  }
4174 
4175  for ( UInt y = 0; y < uiHeight; y ++ )
4176  {
4177    memcpy( piPred + y * uiStride, piBase + y * uiStrideBase, uiWidth * sizeof( Pel ) );
4178  }
4179}
4180
4181#endif
4182
4183#if SVC_COL_BLK
4184TComDataCU*  TComDataCU::getBaseColCU( UInt uiCuAbsPartIdx, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase )
4185{
4186#if 1 // it should provide identical resutls
4187  UInt uiPelX = getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiCuAbsPartIdx] ];
4188  UInt uiPelY = getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiCuAbsPartIdx] ];
4189
4190  return getBaseColCU( uiPelX, uiPelY, uiCUAddrBase, uiAbsPartIdxBase );
4191#else
4192  TComPic* cBaseColPic = m_pcSlice->getBaseColPic();
4193
4194#if SVC_UPSAMPLING
4195  Int widthBL   = cBaseColPic->getPicYuvRec()->getWidth () - cBaseColPic->getPicYuvRec()->getPicCropLeftOffset() - cBaseColPic->getPicYuvRec()->getPicCropRightOffset();
4196  Int heightBL  = cBaseColPic->getPicYuvRec()->getHeight() - cBaseColPic->getPicYuvRec()->getPicCropTopOffset() - cBaseColPic->getPicYuvRec()->getPicCropBottomOffset();
4197
4198  Int widthEL   = m_pcPic->getPicYuvRec()->getWidth() - m_pcPic->getPicYuvRec()->getPicCropLeftOffset() - m_pcPic->getPicYuvRec()->getPicCropRightOffset();
4199  Int heightEL  = m_pcPic->getPicYuvRec()->getHeight() - m_pcPic->getPicYuvRec()->getPicCropTopOffset() - m_pcPic->getPicYuvRec()->getPicCropBottomOffset();
4200#else
4201  Int widthBL   = cBaseColPic->getPicYuvRec()->getWidth();
4202  Int heightBL  = cBaseColPic->getPicYuvRec()->getHeight();
4203
4204  Int widthEL   = m_pcPic->getPicYuvRec()->getWidth();
4205  Int heightEL  = m_pcPic->getPicYuvRec()->getHeight();
4206#endif
4207
4208  if (widthBL == widthEL && heightEL == heightBL)
4209  {
4210    uiAbsPartIdxBase = uiCuAbsPartIdx + m_uiAbsIdxInLCU;
4211    uiCUAddrBase = m_uiCUAddr;
4212  }
4213  else
4214  {
4215    UInt uiMinUnitSize = m_pcPic->getMinCUWidth();
4216    UInt uiRasterAddr  = g_auiZscanToRaster[uiCuAbsPartIdx];
4217    UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
4218
4219    Int iEX = m_uiCUPelX + uiMinUnitSize*(uiRasterAddr%uiNumPartInCUWidth);
4220    Int iEY = m_uiCUPelY + uiMinUnitSize*(uiRasterAddr/uiNumPartInCUWidth);
4221
4222    Int iBX = (iEX*widthBL + widthEL/2)/widthEL;
4223    Int iBY = (iEY*heightBL+ heightEL/2)/heightEL;
4224
4225    uiCUAddrBase = (iBY/g_uiMaxCUHeight)*cBaseColPic->getFrameWidthInCU() + (iBX/g_uiMaxCUWidth);
4226
4227    assert(uiCUAddrBase < cBaseColPic->getNumCUsInFrame());
4228   
4229    UInt uiRasterAddrBase = (iBY - (iBY/g_uiMaxCUHeight)*g_uiMaxCUHeight)/uiMinUnitSize*cBaseColPic->getNumPartInWidth()
4230                          + (iBX - (iBX/g_uiMaxCUWidth)*g_uiMaxCUWidth)/uiMinUnitSize;
4231
4232    uiAbsPartIdxBase = g_auiRasterToZscan[uiRasterAddrBase];
4233  }
4234
4235  return cBaseColPic->getCU(uiCUAddrBase);
4236#endif
4237}
4238
4239TComDataCU*  TComDataCU::getBaseColCU( UInt uiPelX, UInt uiPelY, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase )
4240{
4241  TComPic* cBaseColPic = m_pcSlice->getBaseColPic();
4242
4243#if !SIMPLIFIED_MV_POS_SCALING
4244#if SVC_UPSAMPLING && !ILP_DECODED_PICTURE
4245  const Window &confBL = cBaseColPic->getPicYuvRec()->getConformanceWindow();
4246  const Window &confEL = m_pcPic->getPicYuvRec()->getConformanceWindow();
4247
4248  Int widthBL   = m_pcSlice->getBaseColPic()->getPicYuvRec()->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
4249  Int heightBL  = m_pcSlice->getBaseColPic()->getPicYuvRec()->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
4250
4251  Int widthEL   = m_pcPic->getPicYuvRec()->getWidth() - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset();
4252  Int heightEL  = m_pcPic->getPicYuvRec()->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset();
4253#else
4254  Int widthBL   = cBaseColPic->getPicYuvRec()->getWidth();
4255  Int heightBL  = cBaseColPic->getPicYuvRec()->getHeight();
4256
4257  Int widthEL   = m_pcPic->getPicYuvRec()->getWidth();
4258  Int heightEL  = m_pcPic->getPicYuvRec()->getHeight();
4259#endif
4260#endif
4261
4262  uiPelX = (UInt)Clip3<UInt>(0, m_pcPic->getPicYuvRec()->getWidth() - 1, uiPelX);
4263  uiPelY = (UInt)Clip3<UInt>(0, m_pcPic->getPicYuvRec()->getHeight() - 1, uiPelY);
4264
4265  UInt uiMinUnitSize = m_pcPic->getMinCUWidth();
4266
4267#if SIMPLIFIED_MV_POS_SCALING
4268#if SCALED_REF_LAYER_OFFSETS
4269  Int leftStartL = this->getSlice()->getSPS()->getScaledRefLayerWindow().getWindowLeftOffset();
4270  Int topStartL  = this->getSlice()->getSPS()->getScaledRefLayerWindow().getWindowTopOffset();
4271  Int iBX = ((uiPelX - leftStartL)*g_posScalingFactor[m_layerId][0] + (1<<15)) >> 16;
4272  Int iBY = ((uiPelY - topStartL )*g_posScalingFactor[m_layerId][1] + (1<<15)) >> 16;
4273#else
4274  Int iBX = (uiPelX*g_posScalingFactor[m_layerId][0] + (1<<15)) >> 16;
4275  Int iBY = (uiPelY*g_posScalingFactor[m_layerId][1] + (1<<15)) >> 16;
4276#endif
4277#else
4278  Int iBX = (uiPelX*widthBL + widthEL/2)/widthEL;
4279  Int iBY = (uiPelY*heightBL+ heightEL/2)/heightEL;
4280#endif
4281
4282#if SCALED_REF_LAYER_OFFSETS
4283  if ( iBX >= cBaseColPic->getPicYuvRec()->getWidth() || iBY >= cBaseColPic->getPicYuvRec()->getHeight() ||
4284       iBX < 0                                        || iBY < 0                                           )
4285#else
4286  if ( iBX >= cBaseColPic->getPicYuvRec()->getWidth() || iBY >= cBaseColPic->getPicYuvRec()->getHeight())
4287#endif
4288  {
4289    return NULL;
4290  }
4291
4292#if AVC_SYNTAX && !ILP_DECODED_PICTURE
4293#if !ILP_DECODED_PICTURE
4294  const Window &confBL = cBaseColPic->getPicYuvRec()->getConformanceWindow();
4295  const Window &confEL = m_pcPic->getPicYuvRec()->getConformanceWindow();
4296
4297  Int widthBL   = m_pcSlice->getBaseColPic()->getPicYuvRec()->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
4298  Int heightBL  = m_pcSlice->getBaseColPic()->getPicYuvRec()->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
4299#endif
4300  if( iBX >= widthBL || iBY >= heightBL ) //outside of the reference layer cropped picture
4301  {
4302    return NULL;
4303  }
4304#endif
4305
4306  uiCUAddrBase = (iBY/g_uiMaxCUHeight)*cBaseColPic->getFrameWidthInCU() + (iBX/g_uiMaxCUWidth);
4307
4308  assert(uiCUAddrBase < cBaseColPic->getNumCUsInFrame());
4309
4310  UInt uiRasterAddrBase = (iBY - (iBY/g_uiMaxCUHeight)*g_uiMaxCUHeight)/uiMinUnitSize*cBaseColPic->getNumPartInWidth()
4311    + (iBX - (iBX/g_uiMaxCUWidth)*g_uiMaxCUWidth)/uiMinUnitSize;
4312
4313  uiAbsPartIdxBase = g_auiRasterToZscan[uiRasterAddrBase];
4314
4315  return cBaseColPic->getCU(uiCUAddrBase);
4316}
4317
4318Void TComDataCU::scaleBaseMV( TComMvField& rcMvFieldEnhance, TComMvField& rcMvFieldBase )
4319{
4320  TComMvField cMvFieldBase;
4321  TComMv cMv;
4322#if SIMPLIFIED_MV_POS_SCALING
4323  cMv = rcMvFieldBase.getMv().scaleMv( g_mvScalingFactor[m_layerId][0], g_mvScalingFactor[m_layerId][1] );
4324#else
4325  const Window &confBL = m_pcSlice->getBaseColPic()->getPicYuvRec()->getConformanceWindow();
4326  const Window &confEL = m_pcPic->getPicYuvRec()->getConformanceWindow();
4327
4328  Int widthBL   = m_pcSlice->getBaseColPic()->getPicYuvRec()->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
4329  Int heightBL  = m_pcSlice->getBaseColPic()->getPicYuvRec()->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
4330
4331  Int widthEL   = m_pcPic->getPicYuvRec()->getWidth() - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset();
4332  Int heightEL  = m_pcPic->getPicYuvRec()->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset();
4333
4334  Int iMvX = (rcMvFieldBase.getHor()*widthEL + (widthBL/2 -1) * (rcMvFieldBase.getHor() > 0 ? 1: -1) )/widthBL;
4335  Int iMvY = (rcMvFieldBase.getVer()*heightEL + (heightBL/2 -1) * (rcMvFieldBase.getVer() > 0 ? 1: -1) )/heightBL;
4336
4337  cMv.set(iMvX, iMvY);
4338#endif
4339
4340  rcMvFieldEnhance.setMvField( cMv, rcMvFieldBase.getRefIdx() );
4341}
4342#endif
4343
4344#if SVC_MVP
4345Bool TComDataCU::hasEqualMotion( UInt uiAbsPartIdx, UChar uchInterDir, TComMvField* pcMvField  )
4346{
4347  if ( getInterDir( uiAbsPartIdx ) != uchInterDir )
4348  {
4349    return false;
4350  }
4351
4352  for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
4353  {
4354    if ( getInterDir( uiAbsPartIdx ) & ( 1 << uiRefListIdx ) )
4355    {
4356      if ( getCUMvField( RefPicList( uiRefListIdx ) )->getMv( uiAbsPartIdx )  != pcMvField[uiRefListIdx].getMv() || 
4357        getCUMvField( RefPicList( uiRefListIdx ) )->getRefIdx( uiAbsPartIdx ) != pcMvField[uiRefListIdx].getRefIdx() )
4358      {
4359        return false;
4360      }
4361    }
4362  }
4363
4364  return true;
4365}
4366#endif
4367
4368//! \}
Note: See TracBrowser for help on using the repository browser.