source: 3DVCSoftware/branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComDataCU.cpp @ 478

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

Minor clean ups.

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