source: 3DVCSoftware/branches/HTM-DEV-2.0-dev2-LG/source/Lib/TLibCommon/TComDataCU.cpp @ 568

Last change on this file since 568 was 564, checked in by mediatek-htm, 12 years ago

Integration of JCT3V-E0170 for motion data storage reduction.
The MACRO is "MTK_SONY_PROGRESSIVE_MV_COMPRESSION_E0170".

By Yi-Wen Chen (yiwen.chen@…)

  • Property svn:eol-style set to native
File size: 217.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//! \ingroup TLibCommon
43//! \{
44
45#if ADAPTIVE_QP_SELECTION
46Int * TComDataCU::m_pcGlbArlCoeffY  = NULL;
47Int * TComDataCU::m_pcGlbArlCoeffCb = NULL;
48Int * TComDataCU::m_pcGlbArlCoeffCr = NULL;
49#endif
50
51// ====================================================================================================================
52// Constructor / destructor / create / destroy
53// ====================================================================================================================
54
55TComDataCU::TComDataCU()
56{
57  m_pcPic              = NULL;
58  m_pcSlice            = NULL;
59  m_puhDepth           = NULL;
60 
61  m_skipFlag           = NULL;
62
63  m_pePartSize         = NULL;
64  m_pePredMode         = NULL;
65  m_CUTransquantBypass = NULL;
66  m_puhWidth           = NULL;
67  m_puhHeight          = NULL;
68  m_phQP               = NULL;
69  m_pbMergeFlag        = NULL;
70  m_puhMergeIndex      = NULL;
71  m_puhLumaIntraDir    = NULL;
72  m_puhChromaIntraDir  = NULL;
73  m_puhInterDir        = NULL;
74  m_puhTrIdx           = NULL;
75  m_puhTransformSkip[0] = NULL;
76  m_puhTransformSkip[1] = NULL;
77  m_puhTransformSkip[2] = NULL;
78  m_puhCbf[0]          = NULL;
79  m_puhCbf[1]          = NULL;
80  m_puhCbf[2]          = NULL;
81  m_pcTrCoeffY         = NULL;
82  m_pcTrCoeffCb        = NULL;
83  m_pcTrCoeffCr        = NULL;
84#if ADAPTIVE_QP_SELECTION 
85  m_ArlCoeffIsAliasedAllocation = false;
86  m_pcArlCoeffY        = NULL;
87  m_pcArlCoeffCb       = NULL;
88  m_pcArlCoeffCr       = NULL;
89#endif
90 
91  m_pbIPCMFlag         = NULL;
92  m_pcIPCMSampleY      = NULL;
93  m_pcIPCMSampleCb     = NULL;
94  m_pcIPCMSampleCr     = NULL;
95
96  m_pcPattern          = NULL;
97 
98  m_pcCUAboveLeft      = NULL;
99  m_pcCUAboveRight     = NULL;
100  m_pcCUAbove          = NULL;
101  m_pcCULeft           = NULL;
102 
103  m_apcCUColocated[0]  = NULL;
104  m_apcCUColocated[1]  = NULL;
105 
106  m_apiMVPIdx[0]       = NULL;
107  m_apiMVPIdx[1]       = NULL;
108  m_apiMVPNum[0]       = NULL;
109  m_apiMVPNum[1]       = NULL;
110
111#if H_3D_DIM
112  for( Int i = 0; i < DIM_NUM_TYPE; i++ )
113  {
114    m_dimDeltaDC[i][0] = NULL; 
115    m_dimDeltaDC[i][1] = NULL;
116  }
117#if H_3D_DIM_DMM
118  for( Int i = 0; i < DMM_NUM_TYPE; i++ )
119  {
120    m_dmmWedgeTabIdx[i] = NULL;
121  }
122  m_dmm2DeltaEnd    = NULL;
123  m_dmm3IntraTabIdx = NULL;
124#endif
125#if H_3D_DIM_RBC
126  m_pucEdgeCode     = NULL;
127  m_pucEdgeNumber   = NULL;
128  m_pucEdgeStartPos = NULL;
129  m_pbEdgeLeftFirst = NULL;
130  m_pbEdgePartition = NULL;
131#endif
132#if H_3D_DIM_SDC
133  m_pbSDCFlag             = NULL;
134  m_apSegmentDCOffset[0]  = NULL;
135  m_apSegmentDCOffset[1]  = NULL;
136#endif
137#endif
138  m_bDecSubCu          = false;
139  m_sliceStartCU        = 0;
140  m_sliceSegmentStartCU = 0;
141#if H_3D_NBDV
142  m_pDvInfo              = NULL;
143#endif
144#if H_3D_VSP
145  m_piVSPFlag            = NULL;
146#endif
147#if H_3D_ARP
148  m_puhARPW              = NULL;
149#endif
150#if H_3D_IC
151  m_pbICFlag             = NULL;
152#endif
153}
154
155TComDataCU::~TComDataCU()
156{
157}
158
159Void TComDataCU::create(UInt uiNumPartition, UInt uiWidth, UInt uiHeight, Bool bDecSubCu, Int unitSize
160#if ADAPTIVE_QP_SELECTION
161                        , Bool bGlobalRMARLBuffer
162#endif                                             
163                        )
164{
165  m_bDecSubCu = bDecSubCu;
166 
167  m_pcPic              = NULL;
168  m_pcSlice            = NULL;
169  m_uiNumPartition     = uiNumPartition;
170  m_unitSize = unitSize;
171 
172  if ( !bDecSubCu )
173  {
174    m_phQP               = (Char*     )xMalloc(Char,     uiNumPartition);
175    m_puhDepth           = (UChar*    )xMalloc(UChar,    uiNumPartition);
176    m_puhWidth           = (UChar*    )xMalloc(UChar,    uiNumPartition);
177    m_puhHeight          = (UChar*    )xMalloc(UChar,    uiNumPartition);
178
179    m_skipFlag           = new Bool[ uiNumPartition ];
180
181    m_pePartSize         = new Char[ uiNumPartition ];
182    memset( m_pePartSize, SIZE_NONE,uiNumPartition * sizeof( *m_pePartSize ) );
183    m_pePredMode         = new Char[ uiNumPartition ];
184    m_CUTransquantBypass = new Bool[ uiNumPartition ];
185    m_pbMergeFlag        = (Bool*  )xMalloc(Bool,   uiNumPartition);
186    m_puhMergeIndex      = (UChar* )xMalloc(UChar,  uiNumPartition);
187#if H_3D_VSP
188    m_piVSPFlag          = (Char*  )xMalloc(Char,   uiNumPartition);
189#endif
190    m_puhLumaIntraDir    = (UChar* )xMalloc(UChar,  uiNumPartition);
191    m_puhChromaIntraDir  = (UChar* )xMalloc(UChar,  uiNumPartition);
192    m_puhInterDir        = (UChar* )xMalloc(UChar,  uiNumPartition);
193   
194    m_puhTrIdx           = (UChar* )xMalloc(UChar,  uiNumPartition);
195    m_puhTransformSkip[0] = (UChar* )xMalloc(UChar,  uiNumPartition);
196    m_puhTransformSkip[1] = (UChar* )xMalloc(UChar,  uiNumPartition);
197    m_puhTransformSkip[2] = (UChar* )xMalloc(UChar,  uiNumPartition);
198
199    m_puhCbf[0]          = (UChar* )xMalloc(UChar,  uiNumPartition);
200    m_puhCbf[1]          = (UChar* )xMalloc(UChar,  uiNumPartition);
201    m_puhCbf[2]          = (UChar* )xMalloc(UChar,  uiNumPartition);
202   
203    m_apiMVPIdx[0]       = new Char[ uiNumPartition ];
204    m_apiMVPIdx[1]       = new Char[ uiNumPartition ];
205    m_apiMVPNum[0]       = new Char[ uiNumPartition ];
206    m_apiMVPNum[1]       = new Char[ uiNumPartition ];
207    memset( m_apiMVPIdx[0], -1,uiNumPartition * sizeof( Char ) );
208    memset( m_apiMVPIdx[1], -1,uiNumPartition * sizeof( Char ) );
209   
210    m_pcTrCoeffY         = (TCoeff*)xMalloc(TCoeff, uiWidth*uiHeight);
211    m_pcTrCoeffCb        = (TCoeff*)xMalloc(TCoeff, uiWidth*uiHeight/4);
212    m_pcTrCoeffCr        = (TCoeff*)xMalloc(TCoeff, uiWidth*uiHeight/4);
213#if H_3D_NBDV
214    m_pDvInfo            = (DisInfo* )xMalloc(DisInfo,  uiNumPartition);
215#endif
216    memset( m_pcTrCoeffY, 0,uiWidth*uiHeight * sizeof( TCoeff ) );
217    memset( m_pcTrCoeffCb, 0,uiWidth*uiHeight/4 * sizeof( TCoeff ) );
218    memset( m_pcTrCoeffCr, 0,uiWidth*uiHeight/4 * sizeof( TCoeff ) );
219#if ADAPTIVE_QP_SELECTION   
220    if( bGlobalRMARLBuffer )
221    {
222      if( m_pcGlbArlCoeffY == NULL )
223      {
224        m_pcGlbArlCoeffY   = (Int*)xMalloc(Int, uiWidth*uiHeight);
225        m_pcGlbArlCoeffCb  = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
226        m_pcGlbArlCoeffCr  = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
227      }
228      m_pcArlCoeffY        = m_pcGlbArlCoeffY;
229      m_pcArlCoeffCb       = m_pcGlbArlCoeffCb;
230      m_pcArlCoeffCr       = m_pcGlbArlCoeffCr;
231      m_ArlCoeffIsAliasedAllocation = true;
232    }
233    else
234    {
235      m_pcArlCoeffY        = (Int*)xMalloc(Int, uiWidth*uiHeight);
236      m_pcArlCoeffCb       = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
237      m_pcArlCoeffCr       = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
238    }
239#endif
240   
241    m_pbIPCMFlag         = (Bool*  )xMalloc(Bool, uiNumPartition);
242    m_pcIPCMSampleY      = (Pel*   )xMalloc(Pel , uiWidth*uiHeight);
243    m_pcIPCMSampleCb     = (Pel*   )xMalloc(Pel , uiWidth*uiHeight/4);
244    m_pcIPCMSampleCr     = (Pel*   )xMalloc(Pel , uiWidth*uiHeight/4);
245
246    m_acCUMvField[0].create( uiNumPartition );
247    m_acCUMvField[1].create( uiNumPartition );
248   
249#if H_3D_ARP
250    m_puhARPW            = new UChar[ uiNumPartition];
251#endif
252#if H_3D_IC
253    m_pbICFlag           = (Bool* )xMalloc(Bool,   uiNumPartition);
254#endif
255#if H_3D_DIM
256    for( Int i = 0; i < DIM_NUM_TYPE; i++ )
257    {
258      m_dimDeltaDC[i][0] = (Pel* )xMalloc(Pel, uiNumPartition); 
259      m_dimDeltaDC[i][1] = (Pel* )xMalloc(Pel, uiNumPartition);
260    }
261#if H_3D_DIM_DMM
262    for( Int i = 0; i < DMM_NUM_TYPE; i++ )
263    {
264      m_dmmWedgeTabIdx[i]    = (UInt*)xMalloc(UInt, uiNumPartition);
265    }
266    m_dmm2DeltaEnd    = (Int* )xMalloc(Int,  uiNumPartition);
267    m_dmm3IntraTabIdx = (UInt*)xMalloc(UInt, uiNumPartition);
268#endif
269#if H_3D_DIM_RBC
270    m_pucEdgeCode     = (UChar*)xMalloc(UChar, uiNumPartition * RBC_MAX_EDGE_NUM_PER_4x4);
271    m_pucEdgeNumber   = (UChar*)xMalloc(UChar, uiNumPartition);
272    m_pucEdgeStartPos = (UChar*)xMalloc(UChar, uiNumPartition);
273    m_pbEdgeLeftFirst = (Bool*)xMalloc(Bool, uiNumPartition);
274    m_pbEdgePartition = (Bool*)xMalloc(Bool, uiNumPartition * 16);
275#endif
276#if H_3D_DIM_SDC
277    m_pbSDCFlag             = (Bool*)xMalloc(Bool, uiNumPartition);
278    m_apSegmentDCOffset[0]  = (Pel*)xMalloc(Pel, uiNumPartition);
279    m_apSegmentDCOffset[1]  = (Pel*)xMalloc(Pel, uiNumPartition);
280#endif
281#endif
282  }
283  else
284  {
285    m_acCUMvField[0].setNumPartition(uiNumPartition );
286    m_acCUMvField[1].setNumPartition(uiNumPartition );
287  }
288 
289  m_sliceStartCU        = (UInt*  )xMalloc(UInt, uiNumPartition);
290  m_sliceSegmentStartCU = (UInt*  )xMalloc(UInt, uiNumPartition);
291 
292  // create pattern memory
293  m_pcPattern            = (TComPattern*)xMalloc(TComPattern, 1);
294 
295  // create motion vector fields
296 
297  m_pcCUAboveLeft      = NULL;
298  m_pcCUAboveRight     = NULL;
299  m_pcCUAbove          = NULL;
300  m_pcCULeft           = NULL;
301 
302  m_apcCUColocated[0]  = NULL;
303  m_apcCUColocated[1]  = NULL;
304}
305
306Void TComDataCU::destroy()
307{
308  m_pcPic              = NULL;
309  m_pcSlice            = NULL;
310 
311  if ( m_pcPattern )
312  { 
313    xFree(m_pcPattern);
314    m_pcPattern = NULL;
315  }
316 
317  // encoder-side buffer free
318  if ( !m_bDecSubCu )
319  {
320    if ( m_phQP               ) { xFree(m_phQP);                m_phQP              = NULL; }
321    if ( m_puhDepth           ) { xFree(m_puhDepth);            m_puhDepth          = NULL; }
322    if ( m_puhWidth           ) { xFree(m_puhWidth);            m_puhWidth          = NULL; }
323    if ( m_puhHeight          ) { xFree(m_puhHeight);           m_puhHeight         = NULL; }
324
325    if ( m_skipFlag           ) { delete[] m_skipFlag;          m_skipFlag          = NULL; }
326
327    if ( m_pePartSize         ) { delete[] m_pePartSize;        m_pePartSize        = NULL; }
328    if ( m_pePredMode         ) { delete[] m_pePredMode;        m_pePredMode        = NULL; }
329    if ( m_CUTransquantBypass ) { delete[] m_CUTransquantBypass;m_CUTransquantBypass = NULL; }
330    if ( m_puhCbf[0]          ) { xFree(m_puhCbf[0]);           m_puhCbf[0]         = NULL; }
331    if ( m_puhCbf[1]          ) { xFree(m_puhCbf[1]);           m_puhCbf[1]         = NULL; }
332    if ( m_puhCbf[2]          ) { xFree(m_puhCbf[2]);           m_puhCbf[2]         = NULL; }
333    if ( m_puhInterDir        ) { xFree(m_puhInterDir);         m_puhInterDir       = NULL; }
334    if ( m_pbMergeFlag        ) { xFree(m_pbMergeFlag);         m_pbMergeFlag       = NULL; }
335    if ( m_puhMergeIndex      ) { xFree(m_puhMergeIndex);       m_puhMergeIndex     = NULL; }
336#if H_3D_VSP
337    if ( m_piVSPFlag          ) { xFree(m_piVSPFlag);           m_piVSPFlag         = NULL; }
338#endif
339    if ( m_puhLumaIntraDir    ) { xFree(m_puhLumaIntraDir);     m_puhLumaIntraDir   = NULL; }
340    if ( m_puhChromaIntraDir  ) { xFree(m_puhChromaIntraDir);   m_puhChromaIntraDir = NULL; }
341    if ( m_puhTrIdx           ) { xFree(m_puhTrIdx);            m_puhTrIdx          = NULL; }
342    if ( m_puhTransformSkip[0]) { xFree(m_puhTransformSkip[0]); m_puhTransformSkip[0] = NULL; }
343    if ( m_puhTransformSkip[1]) { xFree(m_puhTransformSkip[1]); m_puhTransformSkip[1] = NULL; }
344    if ( m_puhTransformSkip[2]) { xFree(m_puhTransformSkip[2]); m_puhTransformSkip[2] = NULL; }
345    if ( m_pcTrCoeffY         ) { xFree(m_pcTrCoeffY);          m_pcTrCoeffY        = NULL; }
346    if ( m_pcTrCoeffCb        ) { xFree(m_pcTrCoeffCb);         m_pcTrCoeffCb       = NULL; }
347    if ( m_pcTrCoeffCr        ) { xFree(m_pcTrCoeffCr);         m_pcTrCoeffCr       = NULL; }
348#if ADAPTIVE_QP_SELECTION
349    if (!m_ArlCoeffIsAliasedAllocation)
350    {
351      xFree(m_pcArlCoeffY); m_pcArlCoeffY = 0;
352      xFree(m_pcArlCoeffCb); m_pcArlCoeffCb = 0;
353      xFree(m_pcArlCoeffCr); m_pcArlCoeffCr = 0;
354    }
355    if ( m_pcGlbArlCoeffY     ) { xFree(m_pcGlbArlCoeffY);      m_pcGlbArlCoeffY    = NULL; }
356    if ( m_pcGlbArlCoeffCb    ) { xFree(m_pcGlbArlCoeffCb);     m_pcGlbArlCoeffCb   = NULL; }
357    if ( m_pcGlbArlCoeffCr    ) { xFree(m_pcGlbArlCoeffCr);     m_pcGlbArlCoeffCr   = NULL; }
358#endif
359    if ( m_pbIPCMFlag         ) { xFree(m_pbIPCMFlag   );       m_pbIPCMFlag        = NULL; }
360    if ( m_pcIPCMSampleY      ) { xFree(m_pcIPCMSampleY);       m_pcIPCMSampleY     = NULL; }
361    if ( m_pcIPCMSampleCb     ) { xFree(m_pcIPCMSampleCb);      m_pcIPCMSampleCb    = NULL; }
362    if ( m_pcIPCMSampleCr     ) { xFree(m_pcIPCMSampleCr);      m_pcIPCMSampleCr    = NULL; }
363    if ( m_apiMVPIdx[0]       ) { delete[] m_apiMVPIdx[0];      m_apiMVPIdx[0]      = NULL; }
364    if ( m_apiMVPIdx[1]       ) { delete[] m_apiMVPIdx[1];      m_apiMVPIdx[1]      = NULL; }
365    if ( m_apiMVPNum[0]       ) { delete[] m_apiMVPNum[0];      m_apiMVPNum[0]      = NULL; }
366    if ( m_apiMVPNum[1]       ) { delete[] m_apiMVPNum[1];      m_apiMVPNum[1]      = NULL; }
367#if H_3D_NBDV
368    if ( m_pDvInfo            ) { xFree(m_pDvInfo);             m_pDvInfo           = NULL; }
369#endif
370
371#if H_3D_ARP
372    if ( m_puhARPW            ) { delete[] m_puhARPW;           m_puhARPW           = NULL; }
373#endif
374#if H_3D_IC
375    if ( m_pbICFlag           ) { xFree(m_pbICFlag);            m_pbICFlag          = NULL; }
376#endif
377    m_acCUMvField[0].destroy();
378    m_acCUMvField[1].destroy();
379
380#if H_3D_DIM
381    for( Int i = 0; i < DIM_NUM_TYPE; i++ )
382    {
383      if ( m_dimDeltaDC[i][0] ) { xFree( m_dimDeltaDC[i][0] ); m_dimDeltaDC[i][0] = NULL; }
384      if ( m_dimDeltaDC[i][1] ) { xFree( m_dimDeltaDC[i][1] ); m_dimDeltaDC[i][1] = NULL; }
385    }
386#if H_3D_DIM_DMM
387    for( Int i = 0; i < DMM_NUM_TYPE; i++ )
388    {
389      if ( m_dmmWedgeTabIdx[i] ) { xFree( m_dmmWedgeTabIdx[i] ); m_dmmWedgeTabIdx[i] = NULL; }
390    }
391    if ( m_dmm2DeltaEnd    ) { xFree( m_dmm2DeltaEnd    ); m_dmm2DeltaEnd    = NULL; }
392    if ( m_dmm3IntraTabIdx ) { xFree( m_dmm3IntraTabIdx ); m_dmm3IntraTabIdx = NULL; }
393#endif
394#if H_3D_DIM_RBC
395    if ( m_pbEdgeLeftFirst ) { xFree( m_pbEdgeLeftFirst ); m_pbEdgeLeftFirst = NULL; }
396    if ( m_pucEdgeStartPos ) { xFree( m_pucEdgeStartPos ); m_pucEdgeStartPos = NULL; }
397    if ( m_pucEdgeNumber   ) { xFree( m_pucEdgeNumber   ); m_pucEdgeNumber   = NULL; }
398    if ( m_pucEdgeCode     ) { xFree( m_pucEdgeCode     ); m_pucEdgeCode     = NULL; }
399    if ( m_pbEdgePartition ) { xFree( m_pbEdgePartition ); m_pbEdgePartition = NULL; }
400#endif
401#if H_3D_DIM_SDC
402    if ( m_pbSDCFlag            ) { xFree(m_pbSDCFlag);             m_pbSDCFlag             = NULL; }
403    if ( m_apSegmentDCOffset[0] ) { xFree(m_apSegmentDCOffset[0]);  m_apSegmentDCOffset[0]  = NULL; }
404    if ( m_apSegmentDCOffset[1] ) { xFree(m_apSegmentDCOffset[1]);  m_apSegmentDCOffset[1]  = NULL; }
405#endif
406#endif   
407  }
408 
409  m_pcCUAboveLeft       = NULL;
410  m_pcCUAboveRight      = NULL;
411  m_pcCUAbove           = NULL;
412  m_pcCULeft            = NULL;
413 
414  m_apcCUColocated[0]   = NULL;
415  m_apcCUColocated[1]   = NULL;
416
417  if( m_sliceStartCU )
418  {
419    xFree(m_sliceStartCU);
420    m_sliceStartCU=NULL;
421  }
422  if(m_sliceSegmentStartCU )
423  {
424    xFree(m_sliceSegmentStartCU);
425    m_sliceSegmentStartCU=NULL;
426  }
427}
428
429const NDBFBlockInfo& NDBFBlockInfo::operator= (const NDBFBlockInfo& src)
430{
431  this->tileID = src.tileID;
432  this->sliceID= src.sliceID;
433  this->startSU= src.startSU;
434  this->endSU  = src.endSU;
435  this->widthSU= src.widthSU;
436  this->heightSU=src.heightSU;
437  this->posX   = src.posX;
438  this->posY   = src.posY;
439  this->width  = src.width;
440  this->height = src.height;
441  ::memcpy(this->isBorderAvailable, src.isBorderAvailable, sizeof(Bool)*((Int)NUM_SGU_BORDER));
442  this->allBordersAvailable = src.allBordersAvailable;
443
444  return *this;
445}
446
447
448// ====================================================================================================================
449// Public member functions
450// ====================================================================================================================
451
452// --------------------------------------------------------------------------------------------------------------------
453// Initialization
454// --------------------------------------------------------------------------------------------------------------------
455
456/**
457 - initialize top-level CU
458 - internal buffers are already created
459 - set values before encoding a CU
460 .
461 \param  pcPic     picture (TComPic) class pointer
462 \param  iCUAddr   CU address
463 */
464Void TComDataCU::initCU( TComPic* pcPic, UInt iCUAddr )
465{
466
467  m_pcPic              = pcPic;
468  m_pcSlice            = pcPic->getSlice(pcPic->getCurrSliceIdx());
469  m_uiCUAddr           = iCUAddr;
470  m_uiCUPelX           = ( iCUAddr % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth;
471  m_uiCUPelY           = ( iCUAddr / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight;
472  m_uiAbsIdxInLCU      = 0;
473  m_dTotalCost         = MAX_DOUBLE;
474  m_uiTotalDistortion  = 0;
475  m_uiTotalBits        = 0;
476  m_uiTotalBins        = 0;
477  m_uiNumPartition     = pcPic->getNumPartInCU();
478 
479  for(Int i=0; i<pcPic->getNumPartInCU(); i++)
480  {
481    if(pcPic->getPicSym()->getInverseCUOrderMap(iCUAddr)*pcPic->getNumPartInCU()+i>=getSlice()->getSliceCurStartCUAddr())
482    {
483      m_sliceStartCU[i]=getSlice()->getSliceCurStartCUAddr();
484    }
485    else
486    {
487      m_sliceStartCU[i]=pcPic->getCU(getAddr())->m_sliceStartCU[i];
488    }
489  }
490  for(Int i=0; i<pcPic->getNumPartInCU(); i++)
491  {
492    if(pcPic->getPicSym()->getInverseCUOrderMap(iCUAddr)*pcPic->getNumPartInCU()+i>=getSlice()->getSliceSegmentCurStartCUAddr())
493    {
494      m_sliceSegmentStartCU[i]=getSlice()->getSliceSegmentCurStartCUAddr();
495    }
496    else
497    {
498      m_sliceSegmentStartCU[i]=pcPic->getCU(getAddr())->m_sliceSegmentStartCU[i];
499    }
500  }
501
502  Int partStartIdx = getSlice()->getSliceSegmentCurStartCUAddr() - pcPic->getPicSym()->getInverseCUOrderMap(iCUAddr) * pcPic->getNumPartInCU();
503
504  Int numElements = min<Int>( partStartIdx, m_uiNumPartition );
505  for ( Int ui = 0; ui < numElements; ui++ )
506  {
507    TComDataCU * pcFrom = pcPic->getCU(getAddr());
508    m_skipFlag[ui]   = pcFrom->getSkipFlag(ui);
509    m_pePartSize[ui] = pcFrom->getPartitionSize(ui);
510    m_pePredMode[ui] = pcFrom->getPredictionMode(ui);
511    m_CUTransquantBypass[ui] = pcFrom->getCUTransquantBypass(ui);
512    m_puhDepth[ui] = pcFrom->getDepth(ui);
513#if H_3D_ARP
514    m_puhARPW   [ui] = pcFrom->getARPW( ui );
515#endif
516#if H_3D_IC
517    m_pbICFlag[ui]   =  pcFrom->m_pbICFlag[ui];
518#endif
519    m_puhWidth  [ui] = pcFrom->getWidth(ui);
520    m_puhHeight [ui] = pcFrom->getHeight(ui);
521    m_puhTrIdx  [ui] = pcFrom->getTransformIdx(ui);
522    m_puhTransformSkip[0][ui] = pcFrom->getTransformSkip(ui,TEXT_LUMA);
523    m_puhTransformSkip[1][ui] = pcFrom->getTransformSkip(ui,TEXT_CHROMA_U);
524    m_puhTransformSkip[2][ui] = pcFrom->getTransformSkip(ui,TEXT_CHROMA_V);
525    m_apiMVPIdx[0][ui] = pcFrom->m_apiMVPIdx[0][ui];;
526    m_apiMVPIdx[1][ui] = pcFrom->m_apiMVPIdx[1][ui];
527    m_apiMVPNum[0][ui] = pcFrom->m_apiMVPNum[0][ui];
528    m_apiMVPNum[1][ui] = pcFrom->m_apiMVPNum[1][ui];
529    m_phQP[ui]=pcFrom->m_phQP[ui];
530    m_pbMergeFlag[ui]=pcFrom->m_pbMergeFlag[ui];
531    m_puhMergeIndex[ui]=pcFrom->m_puhMergeIndex[ui];
532#if H_3D_VSP
533    m_piVSPFlag[ui] = pcFrom->m_piVSPFlag[ui];
534#endif
535    m_puhLumaIntraDir[ui]=pcFrom->m_puhLumaIntraDir[ui];
536    m_puhChromaIntraDir[ui]=pcFrom->m_puhChromaIntraDir[ui];
537    m_puhInterDir[ui]=pcFrom->m_puhInterDir[ui];
538    m_puhCbf[0][ui]=pcFrom->m_puhCbf[0][ui];
539    m_puhCbf[1][ui]=pcFrom->m_puhCbf[1][ui];
540    m_puhCbf[2][ui]=pcFrom->m_puhCbf[2][ui];
541    m_pbIPCMFlag[ui] = pcFrom->m_pbIPCMFlag[ui];
542#if H_3D_DIM_SDC
543    m_pbSDCFlag[ui] = pcFrom->m_pbSDCFlag[ui];
544#endif
545  }
546 
547  Int firstElement = max<Int>( partStartIdx, 0 );
548  numElements = m_uiNumPartition - firstElement;
549 
550  if ( numElements > 0 )
551  {
552    memset( m_skipFlag          + firstElement, false,                    numElements * sizeof( *m_skipFlag ) );
553
554    memset( m_pePartSize        + firstElement, SIZE_NONE,                numElements * sizeof( *m_pePartSize ) );
555    memset( m_pePredMode        + firstElement, MODE_NONE,                numElements * sizeof( *m_pePredMode ) );
556    memset( m_CUTransquantBypass+ firstElement, false,                    numElements * sizeof( *m_CUTransquantBypass) );
557    memset( m_puhDepth          + firstElement, 0,                        numElements * sizeof( *m_puhDepth ) );
558    memset( m_puhTrIdx          + firstElement, 0,                        numElements * sizeof( *m_puhTrIdx ) );
559    memset( m_puhTransformSkip[0] + firstElement, 0,                      numElements * sizeof( *m_puhTransformSkip[0]) );
560    memset( m_puhTransformSkip[1] + firstElement, 0,                      numElements * sizeof( *m_puhTransformSkip[1]) );
561    memset( m_puhTransformSkip[2] + firstElement, 0,                      numElements * sizeof( *m_puhTransformSkip[2]) );
562    memset( m_puhWidth          + firstElement, g_uiMaxCUWidth,           numElements * sizeof( *m_puhWidth ) );
563    memset( m_puhHeight         + firstElement, g_uiMaxCUHeight,          numElements * sizeof( *m_puhHeight ) );
564    memset( m_apiMVPIdx[0]      + firstElement, -1,                       numElements * sizeof( *m_apiMVPIdx[0] ) );
565    memset( m_apiMVPIdx[1]      + firstElement, -1,                       numElements * sizeof( *m_apiMVPIdx[1] ) );
566    memset( m_apiMVPNum[0]      + firstElement, -1,                       numElements * sizeof( *m_apiMVPNum[0] ) );
567    memset( m_apiMVPNum[1]      + firstElement, -1,                       numElements * sizeof( *m_apiMVPNum[1] ) );
568    memset( m_phQP              + firstElement, getSlice()->getSliceQp(), numElements * sizeof( *m_phQP ) );
569    memset( m_pbMergeFlag       + firstElement, false,                    numElements * sizeof( *m_pbMergeFlag ) );
570    memset( m_puhMergeIndex     + firstElement, 0,                        numElements * sizeof( *m_puhMergeIndex ) );
571#if H_3D_VSP
572    memset( m_piVSPFlag         + firstElement, 0,                        numElements * sizeof( *m_piVSPFlag ) );
573#endif
574    memset( m_puhLumaIntraDir   + firstElement, DC_IDX,                   numElements * sizeof( *m_puhLumaIntraDir ) );
575    memset( m_puhChromaIntraDir + firstElement, 0,                        numElements * sizeof( *m_puhChromaIntraDir ) );
576    memset( m_puhInterDir       + firstElement, 0,                        numElements * sizeof( *m_puhInterDir ) );
577    memset( m_puhCbf[0]         + firstElement, 0,                        numElements * sizeof( *m_puhCbf[0] ) );
578    memset( m_puhCbf[1]         + firstElement, 0,                        numElements * sizeof( *m_puhCbf[1] ) );
579    memset( m_puhCbf[2]         + firstElement, 0,                        numElements * sizeof( *m_puhCbf[2] ) );
580    memset( m_pbIPCMFlag        + firstElement, false,                    numElements * sizeof( *m_pbIPCMFlag ) );
581#if H_3D_ARP
582    memset( m_puhARPW           + firstElement, 0,                        numElements * sizeof( UChar )         );
583#endif
584#if H_3D_IC
585    memset( m_pbICFlag          + firstElement, false,                    numElements * sizeof( *m_pbICFlag )   );
586#endif
587#if H_3D_DIM
588    for( Int i = 0; i < DIM_NUM_TYPE; i++ )
589    {
590      memset( m_dimDeltaDC[i][0] + firstElement, 0,                       numElements * sizeof( *m_dimDeltaDC[i][0] ) );
591      memset( m_dimDeltaDC[i][1] + firstElement, 0,                       numElements * sizeof( *m_dimDeltaDC[i][1] ) );
592    }
593#if H_3D_DIM_DMM
594    for( Int i = 0; i < DMM_NUM_TYPE; i++ )
595    {
596      memset( m_dmmWedgeTabIdx[i] + firstElement, 0,                      numElements * sizeof( *m_dmmWedgeTabIdx[i] ) );
597    }
598    memset( m_dmm2DeltaEnd      + firstElement, 0,                        numElements * sizeof( *m_dmm2DeltaEnd    ) );
599    memset( m_dmm3IntraTabIdx   + firstElement, 0,                        numElements * sizeof( *m_dmm3IntraTabIdx ) );
600#endif
601#if H_3D_DIM_RBC
602    memset( m_pucEdgeCode       + firstElement, 0,                        numElements * sizeof( *m_pucEdgeCode     ) * RBC_MAX_EDGE_NUM_PER_4x4 );
603    memset( m_pucEdgeNumber     + firstElement, 0,                        numElements * sizeof( *m_pucEdgeNumber   ) );
604    memset( m_pucEdgeStartPos   + firstElement, 0,                        numElements * sizeof( *m_pucEdgeStartPos ) );
605    memset( m_pbEdgeLeftFirst   + firstElement, false,                    numElements * sizeof( *m_pbEdgeLeftFirst ) );
606    memset( m_pbEdgePartition   + firstElement, false,                    numElements * sizeof( *m_pbEdgePartition ) * 16 );
607#endif
608#if H_3D_DIM_SDC
609    memset( m_pbSDCFlag             + firstElement,     0,                numElements * sizeof( *m_pbSDCFlag            ) );
610    memset( m_apSegmentDCOffset[0]  + firstElement,     0,                numElements * sizeof( *m_apSegmentDCOffset[0] ) );
611    memset( m_apSegmentDCOffset[1]  + firstElement,     0,                numElements * sizeof( *m_apSegmentDCOffset[1] ) );
612#endif
613#endif
614  }
615 
616  UInt uiTmp = g_uiMaxCUWidth*g_uiMaxCUHeight;
617  if ( 0 >= partStartIdx ) 
618  {
619    m_acCUMvField[0].clearMvField();
620    m_acCUMvField[1].clearMvField();
621    memset( m_pcTrCoeffY , 0, sizeof( TCoeff ) * uiTmp );
622#if ADAPTIVE_QP_SELECTION
623    memset( m_pcArlCoeffY , 0, sizeof( Int ) * uiTmp ); 
624#endif
625    memset( m_pcIPCMSampleY , 0, sizeof( Pel ) * uiTmp );
626    uiTmp  >>= 2;
627    memset( m_pcTrCoeffCb, 0, sizeof( TCoeff ) * uiTmp );
628    memset( m_pcTrCoeffCr, 0, sizeof( TCoeff ) * uiTmp );
629#if ADAPTIVE_QP_SELECTION 
630    memset( m_pcArlCoeffCb, 0, sizeof( Int ) * uiTmp );
631    memset( m_pcArlCoeffCr, 0, sizeof( Int ) * uiTmp );
632#endif
633    memset( m_pcIPCMSampleCb , 0, sizeof( Pel ) * uiTmp );
634    memset( m_pcIPCMSampleCr , 0, sizeof( Pel ) * uiTmp );
635  }
636  else 
637  {
638    TComDataCU * pcFrom = pcPic->getCU(getAddr());
639    m_acCUMvField[0].copyFrom(&pcFrom->m_acCUMvField[0],m_uiNumPartition,0);
640    m_acCUMvField[1].copyFrom(&pcFrom->m_acCUMvField[1],m_uiNumPartition,0);
641    for(Int i=0; i<uiTmp; i++)
642    {
643      m_pcTrCoeffY[i]=pcFrom->m_pcTrCoeffY[i];
644#if ADAPTIVE_QP_SELECTION
645      m_pcArlCoeffY[i]=pcFrom->m_pcArlCoeffY[i];
646#endif
647      m_pcIPCMSampleY[i]=pcFrom->m_pcIPCMSampleY[i];
648    }
649    for(Int i=0; i<(uiTmp>>2); i++)
650    {
651      m_pcTrCoeffCb[i]=pcFrom->m_pcTrCoeffCb[i];
652      m_pcTrCoeffCr[i]=pcFrom->m_pcTrCoeffCr[i];
653#if ADAPTIVE_QP_SELECTION
654      m_pcArlCoeffCb[i]=pcFrom->m_pcArlCoeffCb[i];
655      m_pcArlCoeffCr[i]=pcFrom->m_pcArlCoeffCr[i];
656#endif
657      m_pcIPCMSampleCb[i]=pcFrom->m_pcIPCMSampleCb[i];
658      m_pcIPCMSampleCr[i]=pcFrom->m_pcIPCMSampleCr[i];
659    }
660  }
661
662  // Setting neighbor CU
663  m_pcCULeft        = NULL;
664  m_pcCUAbove       = NULL;
665  m_pcCUAboveLeft   = NULL;
666  m_pcCUAboveRight  = NULL;
667
668  m_apcCUColocated[0] = NULL;
669  m_apcCUColocated[1] = NULL;
670
671  UInt uiWidthInCU = pcPic->getFrameWidthInCU();
672  if ( m_uiCUAddr % uiWidthInCU )
673  {
674    m_pcCULeft = pcPic->getCU( m_uiCUAddr - 1 );
675  }
676
677  if ( m_uiCUAddr / uiWidthInCU )
678  {
679    m_pcCUAbove = pcPic->getCU( m_uiCUAddr - uiWidthInCU );
680  }
681
682  if ( m_pcCULeft && m_pcCUAbove )
683  {
684    m_pcCUAboveLeft = pcPic->getCU( m_uiCUAddr - uiWidthInCU - 1 );
685  }
686
687  if ( m_pcCUAbove && ( (m_uiCUAddr%uiWidthInCU) < (uiWidthInCU-1) )  )
688  {
689    m_pcCUAboveRight = pcPic->getCU( m_uiCUAddr - uiWidthInCU + 1 );
690  }
691
692  if ( getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) > 0 )
693  {
694    m_apcCUColocated[0] = getSlice()->getRefPic( REF_PIC_LIST_0, 0)->getCU( m_uiCUAddr );
695  }
696
697  if ( getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) > 0 )
698  {
699    m_apcCUColocated[1] = getSlice()->getRefPic( REF_PIC_LIST_1, 0)->getCU( m_uiCUAddr );
700  }
701}
702
703/** initialize prediction data with enabling sub-LCU-level delta QP
704*\param  uiDepth  depth of the current CU
705*\param  qp     qp for the current CU
706*- set CU width and CU height according to depth
707*- set qp value according to input qp
708*- set last-coded qp value according to input last-coded qp
709*/
710Void TComDataCU::initEstData( UInt uiDepth, Int qp )
711{
712  m_dTotalCost         = MAX_DOUBLE;
713  m_uiTotalDistortion  = 0;
714  m_uiTotalBits        = 0;
715  m_uiTotalBins        = 0;
716
717  UChar uhWidth  = g_uiMaxCUWidth  >> uiDepth;
718  UChar uhHeight = g_uiMaxCUHeight >> uiDepth;
719
720  for (UInt ui = 0; ui < m_uiNumPartition; ui++)
721  {
722    if(getPic()->getPicSym()->getInverseCUOrderMap(getAddr())*m_pcPic->getNumPartInCU()+m_uiAbsIdxInLCU+ui >= getSlice()->getSliceSegmentCurStartCUAddr())
723    {
724      m_apiMVPIdx[0][ui] = -1;
725      m_apiMVPIdx[1][ui] = -1;
726      m_apiMVPNum[0][ui] = -1;
727      m_apiMVPNum[1][ui] = -1;
728      m_puhDepth  [ui] = uiDepth;
729      m_puhWidth  [ui] = uhWidth;
730      m_puhHeight [ui] = uhHeight;
731      m_puhTrIdx  [ui] = 0;
732      m_puhTransformSkip[0][ui] = 0;
733      m_puhTransformSkip[1][ui] = 0;
734      m_puhTransformSkip[2][ui] = 0;
735      m_skipFlag[ui]   = false;
736      m_pePartSize[ui] = SIZE_NONE;
737      m_pePredMode[ui] = MODE_NONE;
738      m_CUTransquantBypass[ui] = false;
739      m_pbIPCMFlag[ui] = 0;
740      m_phQP[ui] = qp;
741      m_pbMergeFlag[ui] = 0;
742      m_puhMergeIndex[ui] = 0;
743#if H_3D_VSP
744      m_piVSPFlag[ui] = 0;
745#endif
746      m_puhLumaIntraDir[ui] = DC_IDX;
747      m_puhChromaIntraDir[ui] = 0;
748      m_puhInterDir[ui] = 0;
749      m_puhCbf[0][ui] = 0;
750      m_puhCbf[1][ui] = 0;
751      m_puhCbf[2][ui] = 0;
752#if H_3D_ARP
753      m_puhARPW[ui] = 0;
754#endif
755#if H_3D_IC
756      m_pbICFlag[ui]  = false;
757#endif
758#if H_3D_DIM
759      for( Int i = 0; i < DIM_NUM_TYPE; i++ )
760      {
761        m_dimDeltaDC[i][0] [ui] = 0;
762        m_dimDeltaDC[i][1] [ui] = 0;
763      }
764#if H_3D_DIM_DMM
765      for( Int i = 0; i < DMM_NUM_TYPE; i++ )
766      {
767        m_dmmWedgeTabIdx[i] [ui] = 0;
768      }
769      m_dmm2DeltaEnd    [ui] = 0;
770      m_dmm3IntraTabIdx [ui] = 0;
771#endif
772#if H_3D_DIM_SDC
773      m_pbSDCFlag           [ui] = false;
774      m_apSegmentDCOffset[0][ui] = 0;
775      m_apSegmentDCOffset[1][ui] = 0;
776#endif
777#endif
778    }
779  }
780
781  if(getPic()->getPicSym()->getInverseCUOrderMap(getAddr())*m_pcPic->getNumPartInCU()+m_uiAbsIdxInLCU >= getSlice()->getSliceSegmentCurStartCUAddr())
782  {
783    m_acCUMvField[0].clearMvField();
784    m_acCUMvField[1].clearMvField();
785    UInt uiTmp = uhWidth*uhHeight;
786   
787    memset( m_pcTrCoeffY,    0, uiTmp * sizeof( *m_pcTrCoeffY    ) );
788#if ADAPTIVE_QP_SELECTION
789    memset( m_pcArlCoeffY ,  0, uiTmp * sizeof( *m_pcArlCoeffY   ) );
790#endif
791    memset( m_pcIPCMSampleY, 0, uiTmp * sizeof( *m_pcIPCMSampleY ) );
792
793    uiTmp>>=2;
794    memset( m_pcTrCoeffCb,    0, uiTmp * sizeof( *m_pcTrCoeffCb    ) );
795    memset( m_pcTrCoeffCr,    0, uiTmp * sizeof( *m_pcTrCoeffCr    ) );
796#if ADAPTIVE_QP_SELECTION 
797    memset( m_pcArlCoeffCb,   0, uiTmp * sizeof( *m_pcArlCoeffCb   ) );
798    memset( m_pcArlCoeffCr,   0, uiTmp * sizeof( *m_pcArlCoeffCr   ) );
799#endif
800    memset( m_pcIPCMSampleCb, 0, uiTmp * sizeof( *m_pcIPCMSampleCb ) );
801    memset( m_pcIPCMSampleCr, 0, uiTmp * sizeof( *m_pcIPCMSampleCr ) );
802  }
803}
804
805
806// initialize Sub partition
807Void TComDataCU::initSubCU( TComDataCU* pcCU, UInt uiPartUnitIdx, UInt uiDepth, Int qp )
808{
809  assert( uiPartUnitIdx<4 );
810
811  UInt uiPartOffset = ( pcCU->getTotalNumPart()>>2 )*uiPartUnitIdx;
812
813  m_pcPic              = pcCU->getPic();
814  m_pcSlice            = m_pcPic->getSlice(m_pcPic->getCurrSliceIdx());
815  m_uiCUAddr           = pcCU->getAddr();
816  m_uiAbsIdxInLCU      = pcCU->getZorderIdxInCU() + uiPartOffset;
817
818  m_uiCUPelX           = pcCU->getCUPelX() + ( g_uiMaxCUWidth>>uiDepth  )*( uiPartUnitIdx &  1 );
819  m_uiCUPelY           = pcCU->getCUPelY() + ( g_uiMaxCUHeight>>uiDepth  )*( uiPartUnitIdx >> 1 );
820
821  m_dTotalCost         = MAX_DOUBLE;
822  m_uiTotalDistortion  = 0;
823  m_uiTotalBits        = 0;
824  m_uiTotalBins        = 0;
825  m_uiNumPartition     = pcCU->getTotalNumPart() >> 2;
826
827  Int iSizeInUchar = sizeof( UChar  ) * m_uiNumPartition;
828  Int iSizeInBool  = sizeof( Bool   ) * m_uiNumPartition;
829
830  Int sizeInChar = sizeof( Char  ) * m_uiNumPartition;
831  memset( m_phQP,              qp,  sizeInChar );
832
833  memset( m_pbMergeFlag,        0, iSizeInBool  );
834  memset( m_puhMergeIndex,      0, iSizeInUchar );
835#if H_3D_VSP
836  memset( m_piVSPFlag,          0, sizeof( Char  ) * m_uiNumPartition );
837#endif
838  memset( m_puhLumaIntraDir,    DC_IDX, iSizeInUchar );
839  memset( m_puhChromaIntraDir,  0, iSizeInUchar );
840  memset( m_puhInterDir,        0, iSizeInUchar );
841  memset( m_puhTrIdx,           0, iSizeInUchar );
842  memset( m_puhTransformSkip[0], 0, iSizeInUchar );
843  memset( m_puhTransformSkip[1], 0, iSizeInUchar );
844  memset( m_puhTransformSkip[2], 0, iSizeInUchar );
845  memset( m_puhCbf[0],          0, iSizeInUchar );
846  memset( m_puhCbf[1],          0, iSizeInUchar );
847  memset( m_puhCbf[2],          0, iSizeInUchar );
848  memset( m_puhDepth,     uiDepth, iSizeInUchar );
849#if H_3D_NBDV
850  m_pDvInfo->bDV = false;
851#endif
852#if H_3D_ARP
853  memset( m_puhARPW,            0, iSizeInUchar  );
854#endif
855  UChar uhWidth  = g_uiMaxCUWidth  >> uiDepth;
856  UChar uhHeight = g_uiMaxCUHeight >> uiDepth;
857  memset( m_puhWidth,          uhWidth,  iSizeInUchar );
858  memset( m_puhHeight,         uhHeight, iSizeInUchar );
859  memset( m_pbIPCMFlag,        0, iSizeInBool  );
860#if H_3D_IC
861  memset( m_pbICFlag,          0, iSizeInBool  );
862#endif
863#if H_3D_DIM
864  for( Int i = 0; i < DIM_NUM_TYPE; i++ )
865  {
866    memset( m_dimDeltaDC[i][0], 0, sizeof(Pel ) * m_uiNumPartition );
867    memset( m_dimDeltaDC[i][1], 0, sizeof(Pel ) * m_uiNumPartition );
868  }
869#if H_3D_DIM_DMM
870  for( Int i = 0; i < DMM_NUM_TYPE; i++ )
871  {
872    memset( m_dmmWedgeTabIdx[i], 0, sizeof(UInt) * m_uiNumPartition );
873  }
874  memset( m_dmm2DeltaEnd   , 0, sizeof(Int ) * m_uiNumPartition );
875  memset( m_dmm3IntraTabIdx, 0, sizeof(UInt) * m_uiNumPartition );
876#endif
877#if H_3D_DIM_RBC
878  memset( m_pucEdgeCode    , 0, iSizeInUchar * RBC_MAX_EDGE_NUM_PER_4x4 );
879  memset( m_pucEdgeNumber  , 0, iSizeInUchar );
880  memset( m_pucEdgeStartPos, 0, iSizeInUchar );
881  memset( m_pbEdgeLeftFirst, 0, iSizeInBool );
882  memset( m_pbEdgePartition, 0, iSizeInBool * 16 );
883#endif
884#if H_3D_DIM_SDC
885  memset( m_pbSDCFlag,            0, sizeof(Bool) * m_uiNumPartition  );
886  memset( m_apSegmentDCOffset[0], 0, sizeof(Pel) * m_uiNumPartition   );
887  memset( m_apSegmentDCOffset[1], 0, sizeof(Pel) * m_uiNumPartition   );
888#endif
889#endif
890
891  for (UInt ui = 0; ui < m_uiNumPartition; ui++)
892  {
893    m_skipFlag[ui]   = false;
894    m_pePartSize[ui] = SIZE_NONE;
895    m_pePredMode[ui] = MODE_NONE;
896    m_CUTransquantBypass[ui] = false;
897    m_apiMVPIdx[0][ui] = -1;
898    m_apiMVPIdx[1][ui] = -1;
899    m_apiMVPNum[0][ui] = -1;
900    m_apiMVPNum[1][ui] = -1;
901    if(m_pcPic->getPicSym()->getInverseCUOrderMap(getAddr())*m_pcPic->getNumPartInCU()+m_uiAbsIdxInLCU+ui<getSlice()->getSliceSegmentCurStartCUAddr())
902    {
903      m_apiMVPIdx[0][ui] = pcCU->m_apiMVPIdx[0][uiPartOffset+ui];
904      m_apiMVPIdx[1][ui] = pcCU->m_apiMVPIdx[1][uiPartOffset+ui];;
905      m_apiMVPNum[0][ui] = pcCU->m_apiMVPNum[0][uiPartOffset+ui];;
906      m_apiMVPNum[1][ui] = pcCU->m_apiMVPNum[1][uiPartOffset+ui];;
907      m_puhDepth  [ui] = pcCU->getDepth(uiPartOffset+ui);
908      m_puhWidth  [ui] = pcCU->getWidth(uiPartOffset+ui);
909      m_puhHeight  [ui] = pcCU->getHeight(uiPartOffset+ui);
910      m_puhTrIdx  [ui] = pcCU->getTransformIdx(uiPartOffset+ui);
911      m_puhTransformSkip[0][ui] = pcCU->getTransformSkip(uiPartOffset+ui,TEXT_LUMA);
912      m_puhTransformSkip[1][ui] = pcCU->getTransformSkip(uiPartOffset+ui,TEXT_CHROMA_U);
913      m_puhTransformSkip[2][ui] = pcCU->getTransformSkip(uiPartOffset+ui,TEXT_CHROMA_V);
914      m_skipFlag[ui]   = pcCU->getSkipFlag(uiPartOffset+ui);
915      m_pePartSize[ui] = pcCU->getPartitionSize(uiPartOffset+ui);
916      m_pePredMode[ui] = pcCU->getPredictionMode(uiPartOffset+ui);
917      m_CUTransquantBypass[ui] = pcCU->getCUTransquantBypass(uiPartOffset+ui);
918      m_pbIPCMFlag[ui]=pcCU->m_pbIPCMFlag[uiPartOffset+ui];
919      m_phQP[ui] = pcCU->m_phQP[uiPartOffset+ui];
920      m_pbMergeFlag[ui]=pcCU->m_pbMergeFlag[uiPartOffset+ui];
921      m_puhMergeIndex[ui]=pcCU->m_puhMergeIndex[uiPartOffset+ui];
922#if H_3D_VSP
923      m_piVSPFlag[ui]=pcCU->m_piVSPFlag[uiPartOffset+ui];
924#endif
925      m_puhLumaIntraDir[ui]=pcCU->m_puhLumaIntraDir[uiPartOffset+ui];
926      m_puhChromaIntraDir[ui]=pcCU->m_puhChromaIntraDir[uiPartOffset+ui];
927      m_puhInterDir[ui]=pcCU->m_puhInterDir[uiPartOffset+ui];
928      m_puhCbf[0][ui]=pcCU->m_puhCbf[0][uiPartOffset+ui];
929      m_puhCbf[1][ui]=pcCU->m_puhCbf[1][uiPartOffset+ui];
930      m_puhCbf[2][ui]=pcCU->m_puhCbf[2][uiPartOffset+ui];
931
932#if H_3D_ARP
933      m_puhARPW           [ui] = pcCU->getARPW( uiPartOffset+ui );
934#endif
935#if H_3D_IC
936      m_pbICFlag          [ui] = pcCU->m_pbICFlag[uiPartOffset+ui];
937#endif
938#if H_3D_DIM
939      for( Int i = 0; i < DIM_NUM_TYPE; i++ )
940      {
941        m_dimDeltaDC[i][0] [ui] = pcCU->m_dimDeltaDC[i][0] [uiPartOffset+ui];
942        m_dimDeltaDC[i][1] [ui] = pcCU->m_dimDeltaDC[i][1] [uiPartOffset+ui];
943      }
944#if H_3D_DIM_DMM
945      for( Int i = 0; i < DMM_NUM_TYPE; i++ )
946      {
947        m_dmmWedgeTabIdx[i] [ui] = pcCU->m_dmmWedgeTabIdx[i] [uiPartOffset+ui];
948      }
949      m_dmm2DeltaEnd    [ui] = pcCU->m_dmm2DeltaEnd   [uiPartOffset+ui];
950      m_dmm3IntraTabIdx [ui] = pcCU->m_dmm3IntraTabIdx[uiPartOffset+ui];
951#endif
952#if H_3D_DIM_SDC
953      m_pbSDCFlag           [ui] = pcCU->m_pbSDCFlag            [ uiPartOffset + ui ];
954      m_apSegmentDCOffset[0][ui] = pcCU->m_apSegmentDCOffset[0] [ uiPartOffset + ui ];
955      m_apSegmentDCOffset[1][ui] = pcCU->m_apSegmentDCOffset[1] [ uiPartOffset + ui ];
956#endif
957#endif
958    }
959  }
960  UInt uiTmp = uhWidth*uhHeight;
961  memset( m_pcTrCoeffY , 0, sizeof(TCoeff)*uiTmp );
962#if ADAPTIVE_QP_SELECTION 
963  memset( m_pcArlCoeffY , 0, sizeof(Int)*uiTmp );
964#endif
965  memset( m_pcIPCMSampleY , 0, sizeof( Pel ) * uiTmp );
966  uiTmp >>= 2;
967  memset( m_pcTrCoeffCb, 0, sizeof(TCoeff)*uiTmp );
968  memset( m_pcTrCoeffCr, 0, sizeof(TCoeff)*uiTmp );
969#if ADAPTIVE_QP_SELECTION
970  memset( m_pcArlCoeffCb, 0, sizeof(Int)*uiTmp );
971  memset( m_pcArlCoeffCr, 0, sizeof(Int)*uiTmp );
972#endif
973  memset( m_pcIPCMSampleCb , 0, sizeof( Pel ) * uiTmp );
974  memset( m_pcIPCMSampleCr , 0, sizeof( Pel ) * uiTmp );
975  m_acCUMvField[0].clearMvField();
976  m_acCUMvField[1].clearMvField();
977
978  if(m_pcPic->getPicSym()->getInverseCUOrderMap(getAddr())*m_pcPic->getNumPartInCU()+m_uiAbsIdxInLCU<getSlice()->getSliceSegmentCurStartCUAddr())
979  {
980    // Part of this CU contains data from an older slice. Now copy in that data.
981    UInt uiMaxCuWidth=pcCU->getSlice()->getSPS()->getMaxCUWidth();
982    UInt uiMaxCuHeight=pcCU->getSlice()->getSPS()->getMaxCUHeight();
983    TComDataCU * bigCU = getPic()->getCU(getAddr());
984    Int minui = uiPartOffset;
985    minui = -minui;
986    pcCU->m_acCUMvField[0].copyTo(&m_acCUMvField[0],minui,uiPartOffset,m_uiNumPartition);
987    pcCU->m_acCUMvField[1].copyTo(&m_acCUMvField[1],minui,uiPartOffset,m_uiNumPartition);
988    UInt uiCoffOffset = uiMaxCuWidth*uiMaxCuHeight*m_uiAbsIdxInLCU/pcCU->getPic()->getNumPartInCU();
989    uiTmp = uhWidth*uhHeight;
990    for(Int i=0; i<uiTmp; i++)
991    {
992      m_pcTrCoeffY[i]=bigCU->m_pcTrCoeffY[uiCoffOffset+i];
993#if ADAPTIVE_QP_SELECTION
994      m_pcArlCoeffY[i]=bigCU->m_pcArlCoeffY[uiCoffOffset+i];
995#endif
996      m_pcIPCMSampleY[i]=bigCU->m_pcIPCMSampleY[uiCoffOffset+i];
997    }
998    uiTmp>>=2;
999    uiCoffOffset>>=2;
1000    for(Int i=0; i<uiTmp; i++)
1001    {
1002      m_pcTrCoeffCr[i]=bigCU->m_pcTrCoeffCr[uiCoffOffset+i];
1003      m_pcTrCoeffCb[i]=bigCU->m_pcTrCoeffCb[uiCoffOffset+i];
1004#if ADAPTIVE_QP_SELECTION
1005      m_pcArlCoeffCr[i]=bigCU->m_pcArlCoeffCr[uiCoffOffset+i];
1006      m_pcArlCoeffCb[i]=bigCU->m_pcArlCoeffCb[uiCoffOffset+i];
1007#endif
1008      m_pcIPCMSampleCb[i]=bigCU->m_pcIPCMSampleCb[uiCoffOffset+i];
1009      m_pcIPCMSampleCr[i]=bigCU->m_pcIPCMSampleCr[uiCoffOffset+i];
1010    }
1011  }
1012
1013  m_pcCULeft        = pcCU->getCULeft();
1014  m_pcCUAbove       = pcCU->getCUAbove();
1015  m_pcCUAboveLeft   = pcCU->getCUAboveLeft();
1016  m_pcCUAboveRight  = pcCU->getCUAboveRight();
1017
1018  m_apcCUColocated[0] = pcCU->getCUColocated(REF_PIC_LIST_0);
1019  m_apcCUColocated[1] = pcCU->getCUColocated(REF_PIC_LIST_1);
1020  memcpy(m_sliceStartCU,pcCU->m_sliceStartCU+uiPartOffset,sizeof(UInt)*m_uiNumPartition);
1021  memcpy(m_sliceSegmentStartCU,pcCU->m_sliceSegmentStartCU+uiPartOffset,sizeof(UInt)*m_uiNumPartition);
1022}
1023
1024Void TComDataCU::setOutsideCUPart( UInt uiAbsPartIdx, UInt uiDepth )
1025{
1026  UInt uiNumPartition = m_uiNumPartition >> (uiDepth << 1);
1027  UInt uiSizeInUchar = sizeof( UChar  ) * uiNumPartition;
1028
1029  UChar uhWidth  = g_uiMaxCUWidth  >> uiDepth;
1030  UChar uhHeight = g_uiMaxCUHeight >> uiDepth;
1031  memset( m_puhDepth    + uiAbsPartIdx,     uiDepth,  uiSizeInUchar );
1032  memset( m_puhWidth    + uiAbsPartIdx,     uhWidth,  uiSizeInUchar );
1033  memset( m_puhHeight   + uiAbsPartIdx,     uhHeight, uiSizeInUchar );
1034}
1035
1036// --------------------------------------------------------------------------------------------------------------------
1037// Copy
1038// --------------------------------------------------------------------------------------------------------------------
1039
1040Void TComDataCU::copySubCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1041{
1042  UInt uiPart = uiAbsPartIdx;
1043 
1044  m_pcPic              = pcCU->getPic();
1045  m_pcSlice            = pcCU->getSlice();
1046  m_uiCUAddr           = pcCU->getAddr();
1047  m_uiAbsIdxInLCU      = uiAbsPartIdx;
1048 
1049  m_uiCUPelX           = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
1050  m_uiCUPelY           = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
1051 
1052  m_skipFlag=pcCU->getSkipFlag()          + uiPart;
1053
1054  m_phQP=pcCU->getQP()                    + uiPart;
1055  m_pePartSize = pcCU->getPartitionSize() + uiPart;
1056  m_pePredMode=pcCU->getPredictionMode()  + uiPart;
1057  m_CUTransquantBypass  = pcCU->getCUTransquantBypass()+uiPart;
1058 
1059#if H_3D_NBDV
1060  m_pDvInfo             = pcCU->getDvInfo()           + uiPart;
1061#endif
1062  m_pbMergeFlag         = pcCU->getMergeFlag()        + uiPart;
1063  m_puhMergeIndex       = pcCU->getMergeIndex()       + uiPart;
1064#if H_3D_VSP
1065  m_piVSPFlag           = pcCU->getVSPFlag()          + uiPart;
1066#endif
1067
1068#if H_3D_ARP
1069  m_puhARPW             = pcCU->getARPW()             + uiPart;
1070#endif
1071#if H_3D_IC
1072  m_pbICFlag            = pcCU->getICFlag()           + uiPart;
1073#endif
1074
1075  m_puhLumaIntraDir     = pcCU->getLumaIntraDir()     + uiPart;
1076  m_puhChromaIntraDir   = pcCU->getChromaIntraDir()   + uiPart;
1077  m_puhInterDir         = pcCU->getInterDir()         + uiPart;
1078  m_puhTrIdx            = pcCU->getTransformIdx()     + uiPart;
1079  m_puhTransformSkip[0] = pcCU->getTransformSkip(TEXT_LUMA)     + uiPart;
1080  m_puhTransformSkip[1] = pcCU->getTransformSkip(TEXT_CHROMA_U) + uiPart;
1081  m_puhTransformSkip[2] = pcCU->getTransformSkip(TEXT_CHROMA_V) + uiPart;
1082
1083  m_puhCbf[0]= pcCU->getCbf(TEXT_LUMA)            + uiPart;
1084  m_puhCbf[1]= pcCU->getCbf(TEXT_CHROMA_U)        + uiPart;
1085  m_puhCbf[2]= pcCU->getCbf(TEXT_CHROMA_V)        + uiPart;
1086#if H_3D_DIM
1087  for( Int i = 0; i < DIM_NUM_TYPE; i++ )
1088  {
1089    m_dimDeltaDC[i][0] = pcCU->getDimDeltaDC( i, 0 ) + uiPart;
1090    m_dimDeltaDC[i][1] = pcCU->getDimDeltaDC( i, 1 ) + uiPart;
1091  }
1092#if H_3D_DIM_DMM
1093  for( Int i = 0; i < DMM_NUM_TYPE; i++ )
1094  {
1095    m_dmmWedgeTabIdx[i] = pcCU->getDmmWedgeTabIdx( i ) + uiPart;
1096  }
1097  m_dmm2DeltaEnd    = pcCU->getDmm2DeltaEnd()    + uiPart;
1098  m_dmm3IntraTabIdx = pcCU->getDmm3IntraTabIdx() + uiPart;
1099#endif
1100#if H_3D_DIM_RBC
1101  m_pucEdgeCode     = pcCU->getEdgeCode( uiPart );
1102  m_pucEdgeNumber   = pcCU->getEdgeNumber()      + uiPart;
1103  m_pucEdgeStartPos = pcCU->getEdgeStartPos()    + uiPart;
1104  m_pbEdgeLeftFirst = pcCU->getEdgeLeftFirst()   + uiPart;
1105  m_pbEdgePartition = pcCU->getEdgePartition( uiPart );
1106#endif
1107#if H_3D_DIM_SDC
1108  m_pbSDCFlag               = pcCU->getSDCFlag()              + uiPart;
1109  m_apSegmentDCOffset[0]    = pcCU->getSDCSegmentDCOffset(0)  + uiPart;
1110  m_apSegmentDCOffset[1]    = pcCU->getSDCSegmentDCOffset(1)  + uiPart;
1111#endif
1112#endif 
1113  m_puhDepth=pcCU->getDepth()                     + uiPart;
1114  m_puhWidth=pcCU->getWidth()                     + uiPart;
1115  m_puhHeight=pcCU->getHeight()                   + uiPart;
1116 
1117  m_apiMVPIdx[0]=pcCU->getMVPIdx(REF_PIC_LIST_0)  + uiPart;
1118  m_apiMVPIdx[1]=pcCU->getMVPIdx(REF_PIC_LIST_1)  + uiPart;
1119  m_apiMVPNum[0]=pcCU->getMVPNum(REF_PIC_LIST_0)  + uiPart;
1120  m_apiMVPNum[1]=pcCU->getMVPNum(REF_PIC_LIST_1)  + uiPart;
1121 
1122  m_pbIPCMFlag         = pcCU->getIPCMFlag()        + uiPart;
1123
1124  m_pcCUAboveLeft      = pcCU->getCUAboveLeft();
1125  m_pcCUAboveRight     = pcCU->getCUAboveRight();
1126  m_pcCUAbove          = pcCU->getCUAbove();
1127  m_pcCULeft           = pcCU->getCULeft();
1128 
1129  m_apcCUColocated[0] = pcCU->getCUColocated(REF_PIC_LIST_0);
1130  m_apcCUColocated[1] = pcCU->getCUColocated(REF_PIC_LIST_1);
1131 
1132  UInt uiMaxCuWidth=pcCU->getSlice()->getSPS()->getMaxCUWidth();
1133  UInt uiMaxCuHeight=pcCU->getSlice()->getSPS()->getMaxCUHeight();
1134 
1135  UInt uiCoffOffset = uiMaxCuWidth*uiMaxCuHeight*uiAbsPartIdx/pcCU->getPic()->getNumPartInCU();
1136 
1137  m_pcTrCoeffY = pcCU->getCoeffY() + uiCoffOffset;
1138#if ADAPTIVE_QP_SELECTION
1139  m_pcArlCoeffY= pcCU->getArlCoeffY() + uiCoffOffset; 
1140#endif
1141  m_pcIPCMSampleY = pcCU->getPCMSampleY() + uiCoffOffset;
1142
1143  uiCoffOffset >>=2;
1144  m_pcTrCoeffCb=pcCU->getCoeffCb() + uiCoffOffset;
1145  m_pcTrCoeffCr=pcCU->getCoeffCr() + uiCoffOffset;
1146#if ADAPTIVE_QP_SELECTION 
1147  m_pcArlCoeffCb=pcCU->getArlCoeffCb() + uiCoffOffset;
1148  m_pcArlCoeffCr=pcCU->getArlCoeffCr() + uiCoffOffset;
1149#endif
1150  m_pcIPCMSampleCb = pcCU->getPCMSampleCb() + uiCoffOffset;
1151  m_pcIPCMSampleCr = pcCU->getPCMSampleCr() + uiCoffOffset;
1152
1153  m_acCUMvField[0].linkToWithOffset( pcCU->getCUMvField(REF_PIC_LIST_0), uiPart );
1154  m_acCUMvField[1].linkToWithOffset( pcCU->getCUMvField(REF_PIC_LIST_1), uiPart );
1155  memcpy(m_sliceStartCU,pcCU->m_sliceStartCU+uiPart,sizeof(UInt)*m_uiNumPartition);
1156  memcpy(m_sliceSegmentStartCU,pcCU->m_sliceSegmentStartCU+uiPart,sizeof(UInt)*m_uiNumPartition);
1157}
1158#if H_3D_NBDV
1159Void TComDataCU::copyDVInfoFrom (TComDataCU* pcCU, UInt uiAbsPartIdx)
1160{
1161  m_pDvInfo            = pcCU->getDvInfo()                + uiAbsPartIdx;
1162}
1163#endif
1164// Copy inter prediction info from the biggest CU
1165Void TComDataCU::copyInterPredInfoFrom    ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefPicList
1166#if H_3D_NBDV
1167  , Bool bNBDV
1168#endif
1169  )
1170{
1171  m_pcPic              = pcCU->getPic();
1172  m_pcSlice            = pcCU->getSlice();
1173  m_uiCUAddr           = pcCU->getAddr();
1174  m_uiAbsIdxInLCU      = uiAbsPartIdx;
1175 
1176  Int iRastPartIdx     = g_auiZscanToRaster[uiAbsPartIdx];
1177  m_uiCUPelX           = pcCU->getCUPelX() + m_pcPic->getMinCUWidth ()*( iRastPartIdx % m_pcPic->getNumPartInWidth() );
1178  m_uiCUPelY           = pcCU->getCUPelY() + m_pcPic->getMinCUHeight()*( iRastPartIdx / m_pcPic->getNumPartInWidth() );
1179 
1180  m_pcCUAboveLeft      = pcCU->getCUAboveLeft();
1181  m_pcCUAboveRight     = pcCU->getCUAboveRight();
1182  m_pcCUAbove          = pcCU->getCUAbove();
1183  m_pcCULeft           = pcCU->getCULeft();
1184 
1185  m_apcCUColocated[0]  = pcCU->getCUColocated(REF_PIC_LIST_0);
1186  m_apcCUColocated[1]  = pcCU->getCUColocated(REF_PIC_LIST_1);
1187 
1188  m_skipFlag           = pcCU->getSkipFlag ()             + uiAbsPartIdx;
1189
1190  m_pePartSize         = pcCU->getPartitionSize ()        + uiAbsPartIdx;
1191#if H_3D_NBDV
1192  if(bNBDV == true)
1193  {
1194    m_puhWidth           = pcCU->getWidth ()                + uiAbsPartIdx;
1195    m_puhHeight          = pcCU->getHeight()                + uiAbsPartIdx;
1196    m_puhDepth           = pcCU->getDepth ()                + uiAbsPartIdx;
1197  }
1198  else
1199  {
1200#endif
1201  m_pePredMode         = pcCU->getPredictionMode()        + uiAbsPartIdx;
1202  m_CUTransquantBypass = pcCU->getCUTransquantBypass()    + uiAbsPartIdx;
1203  m_puhInterDir        = pcCU->getInterDir      ()        + uiAbsPartIdx;
1204 
1205  m_puhDepth           = pcCU->getDepth ()                + uiAbsPartIdx;
1206  m_puhWidth           = pcCU->getWidth ()                + uiAbsPartIdx;
1207  m_puhHeight          = pcCU->getHeight()                + uiAbsPartIdx;
1208 
1209  m_pbMergeFlag        = pcCU->getMergeFlag()             + uiAbsPartIdx;
1210  m_puhMergeIndex      = pcCU->getMergeIndex()            + uiAbsPartIdx;
1211#if H_3D_VSP
1212  m_piVSPFlag          = pcCU->getVSPFlag()               + uiAbsPartIdx;
1213#endif
1214
1215  m_apiMVPIdx[eRefPicList] = pcCU->getMVPIdx(eRefPicList) + uiAbsPartIdx;
1216  m_apiMVPNum[eRefPicList] = pcCU->getMVPNum(eRefPicList) + uiAbsPartIdx;
1217 
1218#if H_3D_ARP
1219  m_puhARPW            = pcCU->getARPW()                  + uiAbsPartIdx;
1220#endif
1221
1222  m_acCUMvField[ eRefPicList ].linkToWithOffset( pcCU->getCUMvField(eRefPicList), uiAbsPartIdx );
1223
1224  memcpy(m_sliceStartCU,pcCU->m_sliceStartCU+uiAbsPartIdx,sizeof(UInt)*m_uiNumPartition);
1225  memcpy(m_sliceSegmentStartCU,pcCU->m_sliceSegmentStartCU+uiAbsPartIdx,sizeof(UInt)*m_uiNumPartition);
1226#if H_3D_NBDV
1227  }
1228#endif
1229#if H_3D_IC
1230  m_pbICFlag           = pcCU->getICFlag()                + uiAbsPartIdx;
1231#endif
1232}
1233
1234// Copy small CU to bigger CU.
1235// One of quarter parts overwritten by predicted sub part.
1236Void TComDataCU::copyPartFrom( TComDataCU* pcCU, UInt uiPartUnitIdx, UInt uiDepth )
1237{
1238  assert( uiPartUnitIdx<4 );
1239 
1240  m_dTotalCost         += pcCU->getTotalCost();
1241  m_uiTotalDistortion  += pcCU->getTotalDistortion();
1242  m_uiTotalBits        += pcCU->getTotalBits();
1243 
1244  UInt uiOffset         = pcCU->getTotalNumPart()*uiPartUnitIdx;
1245 
1246  UInt uiNumPartition = pcCU->getTotalNumPart();
1247  Int iSizeInUchar  = sizeof( UChar ) * uiNumPartition;
1248  Int iSizeInBool   = sizeof( Bool  ) * uiNumPartition;
1249 
1250  Int sizeInChar  = sizeof( Char ) * uiNumPartition;
1251  memcpy( m_skipFlag   + uiOffset, pcCU->getSkipFlag(),       sizeof( *m_skipFlag )   * uiNumPartition );
1252  memcpy( m_phQP       + uiOffset, pcCU->getQP(),             sizeInChar                        );
1253  memcpy( m_pePartSize + uiOffset, pcCU->getPartitionSize(),  sizeof( *m_pePartSize ) * uiNumPartition );
1254  memcpy( m_pePredMode + uiOffset, pcCU->getPredictionMode(), sizeof( *m_pePredMode ) * uiNumPartition );
1255  memcpy( m_CUTransquantBypass + uiOffset, pcCU->getCUTransquantBypass(), sizeof( *m_CUTransquantBypass ) * uiNumPartition );
1256  memcpy( m_pbMergeFlag         + uiOffset, pcCU->getMergeFlag(),         iSizeInBool  );
1257  memcpy( m_puhMergeIndex       + uiOffset, pcCU->getMergeIndex(),        iSizeInUchar );
1258#if H_3D_VSP
1259  memcpy( m_piVSPFlag           + uiOffset, pcCU->getVSPFlag(),           sizeof( Char ) * uiNumPartition );
1260#endif
1261  memcpy( m_puhLumaIntraDir     + uiOffset, pcCU->getLumaIntraDir(),      iSizeInUchar );
1262  memcpy( m_puhChromaIntraDir   + uiOffset, pcCU->getChromaIntraDir(),    iSizeInUchar );
1263  memcpy( m_puhInterDir         + uiOffset, pcCU->getInterDir(),          iSizeInUchar );
1264  memcpy( m_puhTrIdx            + uiOffset, pcCU->getTransformIdx(),      iSizeInUchar );
1265  memcpy( m_puhTransformSkip[0] + uiOffset, pcCU->getTransformSkip(TEXT_LUMA),     iSizeInUchar );
1266  memcpy( m_puhTransformSkip[1] + uiOffset, pcCU->getTransformSkip(TEXT_CHROMA_U), iSizeInUchar );
1267  memcpy( m_puhTransformSkip[2] + uiOffset, pcCU->getTransformSkip(TEXT_CHROMA_V), iSizeInUchar );
1268
1269  memcpy( m_puhCbf[0] + uiOffset, pcCU->getCbf(TEXT_LUMA)    , iSizeInUchar );
1270  memcpy( m_puhCbf[1] + uiOffset, pcCU->getCbf(TEXT_CHROMA_U), iSizeInUchar );
1271  memcpy( m_puhCbf[2] + uiOffset, pcCU->getCbf(TEXT_CHROMA_V), iSizeInUchar );
1272 
1273#if H_3D_DIM
1274  for( Int i = 0; i < DIM_NUM_TYPE; i++ )
1275  {
1276    memcpy( m_dimDeltaDC[i][0] + uiOffset, pcCU->getDimDeltaDC( i, 0 ), sizeof(Pel ) * uiNumPartition );
1277    memcpy( m_dimDeltaDC[i][1] + uiOffset, pcCU->getDimDeltaDC( i, 1 ), sizeof(Pel ) * uiNumPartition );
1278  }
1279#if H_3D_DIM_DMM
1280  for( Int i = 0; i < DMM_NUM_TYPE; i++ )
1281  {
1282    memcpy( m_dmmWedgeTabIdx[i] + uiOffset, pcCU->getDmmWedgeTabIdx( i ), sizeof(UInt) * uiNumPartition );
1283  }
1284  memcpy( m_dmm2DeltaEnd    + uiOffset, pcCU->getDmm2DeltaEnd()   , sizeof(Int ) * uiNumPartition );
1285  memcpy( m_dmm3IntraTabIdx + uiOffset, pcCU->getDmm3IntraTabIdx(), sizeof(UInt) * uiNumPartition );
1286#endif
1287#if H_3D_DIM_RBC
1288  memcpy( getEdgeCode( uiOffset ),       pcCU->getEdgeCode(0),      iSizeInUchar * RBC_MAX_EDGE_NUM_PER_4x4 );
1289  memcpy( getEdgeNumber()    + uiOffset, pcCU->getEdgeNumber(),     iSizeInUchar );
1290  memcpy( getEdgeStartPos()  + uiOffset, pcCU->getEdgeStartPos(),   iSizeInUchar );
1291  memcpy( getEdgeLeftFirst() + uiOffset, pcCU->getEdgeLeftFirst(),  iSizeInBool );
1292  memcpy( getEdgePartition( uiOffset ),  pcCU->getEdgePartition(0), iSizeInBool * 16 );
1293#endif
1294#if H_3D_DIM_SDC
1295  memcpy( m_pbSDCFlag             + uiOffset, pcCU->getSDCFlag(),             iSizeInBool  );
1296  memcpy( m_apSegmentDCOffset[0]  + uiOffset, pcCU->getSDCSegmentDCOffset(0), sizeof( Pel ) * uiNumPartition);
1297  memcpy( m_apSegmentDCOffset[1]  + uiOffset, pcCU->getSDCSegmentDCOffset(1), sizeof( Pel ) * uiNumPartition);
1298#endif
1299#endif
1300
1301  memcpy( m_puhDepth  + uiOffset, pcCU->getDepth(),  iSizeInUchar );
1302  memcpy( m_puhWidth  + uiOffset, pcCU->getWidth(),  iSizeInUchar );
1303  memcpy( m_puhHeight + uiOffset, pcCU->getHeight(), iSizeInUchar );
1304 
1305  memcpy( m_apiMVPIdx[0] + uiOffset, pcCU->getMVPIdx(REF_PIC_LIST_0), iSizeInUchar );
1306  memcpy( m_apiMVPIdx[1] + uiOffset, pcCU->getMVPIdx(REF_PIC_LIST_1), iSizeInUchar );
1307  memcpy( m_apiMVPNum[0] + uiOffset, pcCU->getMVPNum(REF_PIC_LIST_0), iSizeInUchar );
1308  memcpy( m_apiMVPNum[1] + uiOffset, pcCU->getMVPNum(REF_PIC_LIST_1), iSizeInUchar );
1309 
1310  memcpy( m_pbIPCMFlag + uiOffset, pcCU->getIPCMFlag(), iSizeInBool );
1311
1312  m_pcCUAboveLeft      = pcCU->getCUAboveLeft();
1313  m_pcCUAboveRight     = pcCU->getCUAboveRight();
1314  m_pcCUAbove          = pcCU->getCUAbove();
1315  m_pcCULeft           = pcCU->getCULeft();
1316 
1317  m_apcCUColocated[0] = pcCU->getCUColocated(REF_PIC_LIST_0);
1318  m_apcCUColocated[1] = pcCU->getCUColocated(REF_PIC_LIST_1);
1319 
1320  m_acCUMvField[0].copyFrom( pcCU->getCUMvField( REF_PIC_LIST_0 ), pcCU->getTotalNumPart(), uiOffset );
1321  m_acCUMvField[1].copyFrom( pcCU->getCUMvField( REF_PIC_LIST_1 ), pcCU->getTotalNumPart(), uiOffset );
1322 
1323  UInt uiTmp  = g_uiMaxCUWidth*g_uiMaxCUHeight >> (uiDepth<<1);
1324  UInt uiTmp2 = uiPartUnitIdx*uiTmp;
1325  memcpy( m_pcTrCoeffY  + uiTmp2, pcCU->getCoeffY(),  sizeof(TCoeff)*uiTmp );
1326#if ADAPTIVE_QP_SELECTION
1327  memcpy( m_pcArlCoeffY  + uiTmp2, pcCU->getArlCoeffY(),  sizeof(Int)*uiTmp );
1328#endif
1329  memcpy( m_pcIPCMSampleY + uiTmp2 , pcCU->getPCMSampleY(), sizeof(Pel) * uiTmp );
1330
1331  uiTmp >>= 2; uiTmp2>>= 2;
1332  memcpy( m_pcTrCoeffCb + uiTmp2, pcCU->getCoeffCb(), sizeof(TCoeff)*uiTmp );
1333  memcpy( m_pcTrCoeffCr + uiTmp2, pcCU->getCoeffCr(), sizeof(TCoeff)*uiTmp );
1334#if ADAPTIVE_QP_SELECTION
1335  memcpy( m_pcArlCoeffCb + uiTmp2, pcCU->getArlCoeffCb(), sizeof(Int)*uiTmp );
1336  memcpy( m_pcArlCoeffCr + uiTmp2, pcCU->getArlCoeffCr(), sizeof(Int)*uiTmp );
1337#endif
1338  memcpy( m_pcIPCMSampleCb + uiTmp2 , pcCU->getPCMSampleCb(), sizeof(Pel) * uiTmp );
1339  memcpy( m_pcIPCMSampleCr + uiTmp2 , pcCU->getPCMSampleCr(), sizeof(Pel) * uiTmp );
1340  m_uiTotalBins += pcCU->getTotalBins();
1341  memcpy( m_sliceStartCU        + uiOffset, pcCU->m_sliceStartCU,        sizeof( UInt ) * uiNumPartition  );
1342  memcpy( m_sliceSegmentStartCU + uiOffset, pcCU->m_sliceSegmentStartCU, sizeof( UInt ) * uiNumPartition  );
1343#if H_3D_ARP
1344  memcpy( m_puhARPW             + uiOffset, pcCU->getARPW(),              iSizeInUchar );
1345#endif
1346#if H_3D_IC
1347  memcpy( m_pbICFlag            + uiOffset, pcCU->getICFlag(),            iSizeInBool );
1348#endif
1349}
1350
1351// Copy current predicted part to a CU in picture.
1352// It is used to predict for next part
1353Void TComDataCU::copyToPic( UChar uhDepth )
1354{
1355  TComDataCU*& rpcCU = m_pcPic->getCU( m_uiCUAddr );
1356 
1357  rpcCU->getTotalCost()       = m_dTotalCost;
1358  rpcCU->getTotalDistortion() = m_uiTotalDistortion;
1359  rpcCU->getTotalBits()       = m_uiTotalBits;
1360 
1361  Int iSizeInUchar  = sizeof( UChar ) * m_uiNumPartition;
1362  Int iSizeInBool   = sizeof( Bool  ) * m_uiNumPartition;
1363 
1364  Int sizeInChar  = sizeof( Char ) * m_uiNumPartition;
1365
1366  memcpy( rpcCU->getSkipFlag() + m_uiAbsIdxInLCU, m_skipFlag, sizeof( *m_skipFlag ) * m_uiNumPartition );
1367
1368  memcpy( rpcCU->getQP() + m_uiAbsIdxInLCU, m_phQP, sizeInChar  );
1369#if H_3D_NBDV
1370  memcpy( rpcCU->getDvInfo()         + m_uiAbsIdxInLCU, m_pDvInfo,    sizeof(* m_pDvInfo)     * m_uiNumPartition );
1371#endif
1372
1373  memcpy( rpcCU->getPartitionSize()  + m_uiAbsIdxInLCU, m_pePartSize, sizeof( *m_pePartSize ) * m_uiNumPartition );
1374  memcpy( rpcCU->getPredictionMode() + m_uiAbsIdxInLCU, m_pePredMode, sizeof( *m_pePredMode ) * m_uiNumPartition );
1375  memcpy( rpcCU->getCUTransquantBypass()+ m_uiAbsIdxInLCU, m_CUTransquantBypass, sizeof( *m_CUTransquantBypass ) * m_uiNumPartition );
1376  memcpy( rpcCU->getMergeFlag()         + m_uiAbsIdxInLCU, m_pbMergeFlag,         iSizeInBool  );
1377  memcpy( rpcCU->getMergeIndex()        + m_uiAbsIdxInLCU, m_puhMergeIndex,       iSizeInUchar );
1378#if H_3D_VSP
1379  memcpy( rpcCU->getVSPFlag()           + m_uiAbsIdxInLCU, m_piVSPFlag,           sizeof( Char ) * m_uiNumPartition );
1380#endif
1381  memcpy( rpcCU->getLumaIntraDir()      + m_uiAbsIdxInLCU, m_puhLumaIntraDir,     iSizeInUchar );
1382  memcpy( rpcCU->getChromaIntraDir()    + m_uiAbsIdxInLCU, m_puhChromaIntraDir,   iSizeInUchar );
1383  memcpy( rpcCU->getInterDir()          + m_uiAbsIdxInLCU, m_puhInterDir,         iSizeInUchar );
1384  memcpy( rpcCU->getTransformIdx()      + m_uiAbsIdxInLCU, m_puhTrIdx,            iSizeInUchar );
1385  memcpy( rpcCU->getTransformSkip(TEXT_LUMA)     + m_uiAbsIdxInLCU, m_puhTransformSkip[0], iSizeInUchar );
1386  memcpy( rpcCU->getTransformSkip(TEXT_CHROMA_U) + m_uiAbsIdxInLCU, m_puhTransformSkip[1], iSizeInUchar );
1387  memcpy( rpcCU->getTransformSkip(TEXT_CHROMA_V) + m_uiAbsIdxInLCU, m_puhTransformSkip[2], iSizeInUchar );
1388
1389  memcpy( rpcCU->getCbf(TEXT_LUMA)     + m_uiAbsIdxInLCU, m_puhCbf[0], iSizeInUchar );
1390  memcpy( rpcCU->getCbf(TEXT_CHROMA_U) + m_uiAbsIdxInLCU, m_puhCbf[1], iSizeInUchar );
1391  memcpy( rpcCU->getCbf(TEXT_CHROMA_V) + m_uiAbsIdxInLCU, m_puhCbf[2], iSizeInUchar );
1392 
1393#if H_3D_DIM
1394  for( Int i = 0; i < DIM_NUM_TYPE; i++ )
1395  {
1396    memcpy( rpcCU->getDimDeltaDC( i, 0 ) + m_uiAbsIdxInLCU, m_dimDeltaDC[i][0], sizeof(Pel ) * m_uiNumPartition );
1397    memcpy( rpcCU->getDimDeltaDC( i, 1 ) + m_uiAbsIdxInLCU, m_dimDeltaDC[i][1], sizeof(Pel ) * m_uiNumPartition );
1398  }
1399#if H_3D_DIM_DMM
1400  for( Int i = 0; i < DMM_NUM_TYPE; i++ )
1401  {
1402    memcpy( rpcCU->getDmmWedgeTabIdx( i ) + m_uiAbsIdxInLCU, m_dmmWedgeTabIdx[i], sizeof(UInt) * m_uiNumPartition );
1403  }
1404  memcpy( rpcCU->getDmm2DeltaEnd()    + m_uiAbsIdxInLCU, m_dmm2DeltaEnd   , sizeof(Int ) * m_uiNumPartition );
1405  memcpy( rpcCU->getDmm3IntraTabIdx() + m_uiAbsIdxInLCU, m_dmm3IntraTabIdx, sizeof(UInt) * m_uiNumPartition );
1406#endif
1407#if H_3D_DIM_RBC
1408  memcpy( rpcCU->getEdgeCode( m_uiAbsIdxInLCU ),         m_pucEdgeCode,     iSizeInUchar * RBC_MAX_EDGE_NUM_PER_4x4 );
1409  memcpy( rpcCU->getEdgeNumber()      + m_uiAbsIdxInLCU, m_pucEdgeNumber,   iSizeInUchar );
1410  memcpy( rpcCU->getEdgeStartPos()    + m_uiAbsIdxInLCU, m_pucEdgeStartPos, iSizeInUchar );
1411  memcpy( rpcCU->getEdgeLeftFirst()   + m_uiAbsIdxInLCU, m_pbEdgeLeftFirst, iSizeInBool );
1412  memcpy( rpcCU->getEdgePartition( m_uiAbsIdxInLCU ),    m_pbEdgePartition, iSizeInBool * 16 );
1413#endif
1414#if H_3D_DIM_SDC
1415  memcpy( rpcCU->getSDCFlag()             + m_uiAbsIdxInLCU, m_pbSDCFlag,      iSizeInBool  );
1416  memcpy( rpcCU->getSDCSegmentDCOffset(0) + m_uiAbsIdxInLCU, m_apSegmentDCOffset[0], sizeof( Pel ) * m_uiNumPartition);
1417  memcpy( rpcCU->getSDCSegmentDCOffset(1) + m_uiAbsIdxInLCU, m_apSegmentDCOffset[1], sizeof( Pel ) * m_uiNumPartition);
1418#endif
1419#endif
1420  memcpy( rpcCU->getDepth()  + m_uiAbsIdxInLCU, m_puhDepth,  iSizeInUchar );
1421  memcpy( rpcCU->getWidth()  + m_uiAbsIdxInLCU, m_puhWidth,  iSizeInUchar );
1422  memcpy( rpcCU->getHeight() + m_uiAbsIdxInLCU, m_puhHeight, iSizeInUchar );
1423 
1424  memcpy( rpcCU->getMVPIdx(REF_PIC_LIST_0) + m_uiAbsIdxInLCU, m_apiMVPIdx[0], iSizeInUchar );
1425  memcpy( rpcCU->getMVPIdx(REF_PIC_LIST_1) + m_uiAbsIdxInLCU, m_apiMVPIdx[1], iSizeInUchar );
1426  memcpy( rpcCU->getMVPNum(REF_PIC_LIST_0) + m_uiAbsIdxInLCU, m_apiMVPNum[0], iSizeInUchar );
1427  memcpy( rpcCU->getMVPNum(REF_PIC_LIST_1) + m_uiAbsIdxInLCU, m_apiMVPNum[1], iSizeInUchar );
1428 
1429  m_acCUMvField[0].copyTo( rpcCU->getCUMvField( REF_PIC_LIST_0 ), m_uiAbsIdxInLCU );
1430  m_acCUMvField[1].copyTo( rpcCU->getCUMvField( REF_PIC_LIST_1 ), m_uiAbsIdxInLCU );
1431 
1432  memcpy( rpcCU->getIPCMFlag() + m_uiAbsIdxInLCU, m_pbIPCMFlag,         iSizeInBool  );
1433
1434  UInt uiTmp  = (g_uiMaxCUWidth*g_uiMaxCUHeight)>>(uhDepth<<1);
1435  UInt uiTmp2 = m_uiAbsIdxInLCU*m_pcPic->getMinCUWidth()*m_pcPic->getMinCUHeight();
1436  memcpy( rpcCU->getCoeffY()  + uiTmp2, m_pcTrCoeffY,  sizeof(TCoeff)*uiTmp  );
1437#if ADAPTIVE_QP_SELECTION 
1438  memcpy( rpcCU->getArlCoeffY()  + uiTmp2, m_pcArlCoeffY,  sizeof(Int)*uiTmp  );
1439#endif
1440  memcpy( rpcCU->getPCMSampleY() + uiTmp2 , m_pcIPCMSampleY, sizeof(Pel)*uiTmp );
1441
1442  uiTmp >>= 2; uiTmp2 >>= 2;
1443  memcpy( rpcCU->getCoeffCb() + uiTmp2, m_pcTrCoeffCb, sizeof(TCoeff)*uiTmp  );
1444  memcpy( rpcCU->getCoeffCr() + uiTmp2, m_pcTrCoeffCr, sizeof(TCoeff)*uiTmp  );
1445#if ADAPTIVE_QP_SELECTION
1446  memcpy( rpcCU->getArlCoeffCb() + uiTmp2, m_pcArlCoeffCb, sizeof(Int)*uiTmp  );
1447  memcpy( rpcCU->getArlCoeffCr() + uiTmp2, m_pcArlCoeffCr, sizeof(Int)*uiTmp  );
1448#endif
1449  memcpy( rpcCU->getPCMSampleCb() + uiTmp2 , m_pcIPCMSampleCb, sizeof( Pel ) * uiTmp );
1450  memcpy( rpcCU->getPCMSampleCr() + uiTmp2 , m_pcIPCMSampleCr, sizeof( Pel ) * uiTmp );
1451  rpcCU->getTotalBins() = m_uiTotalBins;
1452  memcpy( rpcCU->m_sliceStartCU        + m_uiAbsIdxInLCU, m_sliceStartCU,        sizeof( UInt ) * m_uiNumPartition  );
1453  memcpy( rpcCU->m_sliceSegmentStartCU + m_uiAbsIdxInLCU, m_sliceSegmentStartCU, sizeof( UInt ) * m_uiNumPartition  );
1454#if H_3D_ARP
1455  memcpy( rpcCU->getARPW()             + m_uiAbsIdxInLCU, m_puhARPW,             iSizeInUchar );
1456#endif
1457#if H_3D_IC
1458  memcpy( rpcCU->getICFlag()           + m_uiAbsIdxInLCU, m_pbICFlag,            iSizeInBool );
1459#endif
1460}
1461
1462Void TComDataCU::copyToPic( UChar uhDepth, UInt uiPartIdx, UInt uiPartDepth )
1463{
1464  TComDataCU*&  rpcCU       = m_pcPic->getCU( m_uiCUAddr );
1465  UInt          uiQNumPart  = m_uiNumPartition>>(uiPartDepth<<1);
1466 
1467  UInt uiPartStart          = uiPartIdx*uiQNumPart;
1468  UInt uiPartOffset         = m_uiAbsIdxInLCU + uiPartStart;
1469 
1470  rpcCU->getTotalCost()       = m_dTotalCost;
1471  rpcCU->getTotalDistortion() = m_uiTotalDistortion;
1472  rpcCU->getTotalBits()       = m_uiTotalBits;
1473 
1474  Int iSizeInUchar  = sizeof( UChar  ) * uiQNumPart;
1475  Int iSizeInBool   = sizeof( Bool   ) * uiQNumPart;
1476 
1477  Int sizeInChar  = sizeof( Char ) * uiQNumPart;
1478  memcpy( rpcCU->getSkipFlag()       + uiPartOffset, m_skipFlag,   sizeof( *m_skipFlag )   * uiQNumPart );
1479
1480  memcpy( rpcCU->getQP() + uiPartOffset, m_phQP, sizeInChar );
1481  memcpy( rpcCU->getPartitionSize()  + uiPartOffset, m_pePartSize, sizeof( *m_pePartSize ) * uiQNumPart );
1482  memcpy( rpcCU->getPredictionMode() + uiPartOffset, m_pePredMode, sizeof( *m_pePredMode ) * uiQNumPart );
1483  memcpy( rpcCU->getCUTransquantBypass()+ uiPartOffset, m_CUTransquantBypass, sizeof( *m_CUTransquantBypass ) * uiQNumPart );
1484  memcpy( rpcCU->getMergeFlag()         + uiPartOffset, m_pbMergeFlag,         iSizeInBool  );
1485  memcpy( rpcCU->getMergeIndex()        + uiPartOffset, m_puhMergeIndex,       iSizeInUchar );
1486#if H_3D_VSP
1487  memcpy( rpcCU->getVSPFlag()           + uiPartOffset, m_piVSPFlag,           sizeof(Char) * uiQNumPart );
1488#endif
1489  memcpy( rpcCU->getLumaIntraDir()      + uiPartOffset, m_puhLumaIntraDir,     iSizeInUchar );
1490  memcpy( rpcCU->getChromaIntraDir()    + uiPartOffset, m_puhChromaIntraDir,   iSizeInUchar );
1491  memcpy( rpcCU->getInterDir()          + uiPartOffset, m_puhInterDir,         iSizeInUchar );
1492  memcpy( rpcCU->getTransformIdx()      + uiPartOffset, m_puhTrIdx,            iSizeInUchar );
1493  memcpy( rpcCU->getTransformSkip(TEXT_LUMA)     + uiPartOffset, m_puhTransformSkip[0], iSizeInUchar );
1494  memcpy( rpcCU->getTransformSkip(TEXT_CHROMA_U) + uiPartOffset, m_puhTransformSkip[1], iSizeInUchar );
1495  memcpy( rpcCU->getTransformSkip(TEXT_CHROMA_V) + uiPartOffset, m_puhTransformSkip[2], iSizeInUchar );
1496  memcpy( rpcCU->getCbf(TEXT_LUMA)     + uiPartOffset, m_puhCbf[0], iSizeInUchar );
1497  memcpy( rpcCU->getCbf(TEXT_CHROMA_U) + uiPartOffset, m_puhCbf[1], iSizeInUchar );
1498  memcpy( rpcCU->getCbf(TEXT_CHROMA_V) + uiPartOffset, m_puhCbf[2], iSizeInUchar );
1499 
1500#if H_3D_DIM
1501  for( Int i = 0; i < DMM_NUM_TYPE; i++ )
1502  {
1503    memcpy( rpcCU->getDimDeltaDC( i, 0 ) + uiPartOffset, m_dimDeltaDC[i][0], sizeof(Pel ) * uiQNumPart );
1504    memcpy( rpcCU->getDimDeltaDC( i, 1 ) + uiPartOffset, m_dimDeltaDC[i][1], sizeof(Pel ) * uiQNumPart );
1505  }
1506#if H_3D_DIM_DMM
1507  for( Int i = 0; i < DMM_NUM_TYPE; i++ )
1508  {
1509    memcpy( rpcCU->getDmmWedgeTabIdx( i ) + uiPartOffset, m_dmmWedgeTabIdx[i], sizeof(UInt) * uiQNumPart );
1510  }
1511  memcpy( rpcCU->getDmm2DeltaEnd()    + uiPartOffset, m_dmm2DeltaEnd   , sizeof(Int ) * uiQNumPart );
1512  memcpy( rpcCU->getDmm3IntraTabIdx() + uiPartOffset, m_dmm3IntraTabIdx, sizeof(UInt) * uiQNumPart );
1513#endif
1514#if H_3D_DIM_RBC
1515  memcpy( rpcCU->getEdgeCode( uiPartOffset ),         m_pucEdgeCode,     iSizeInUchar * RBC_MAX_EDGE_NUM_PER_4x4 );
1516  memcpy( rpcCU->getEdgeNumber()      + uiPartOffset, m_pucEdgeNumber,   iSizeInUchar );
1517  memcpy( rpcCU->getEdgeStartPos()    + uiPartOffset, m_pucEdgeStartPos, iSizeInUchar );
1518  memcpy( rpcCU->getEdgeLeftFirst()   + uiPartOffset, m_pbEdgeLeftFirst, iSizeInBool );
1519  memcpy( rpcCU->getEdgePartition( uiPartOffset ),    m_pbEdgePartition, iSizeInBool * 16 );
1520#endif
1521#if H_3D_DIM_SDC
1522  memcpy( rpcCU->getSDCFlag()             + uiPartOffset, m_pbSDCFlag,      iSizeInBool  );
1523  memcpy( rpcCU->getSDCSegmentDCOffset(0) + uiPartOffset, m_apSegmentDCOffset[0], sizeof( Pel ) * uiQNumPart);
1524  memcpy( rpcCU->getSDCSegmentDCOffset(1) + uiPartOffset, m_apSegmentDCOffset[1], sizeof( Pel ) * uiQNumPart);
1525#endif
1526#endif
1527  memcpy( rpcCU->getDepth()  + uiPartOffset, m_puhDepth,  iSizeInUchar );
1528  memcpy( rpcCU->getWidth()  + uiPartOffset, m_puhWidth,  iSizeInUchar );
1529  memcpy( rpcCU->getHeight() + uiPartOffset, m_puhHeight, iSizeInUchar );
1530 
1531  memcpy( rpcCU->getMVPIdx(REF_PIC_LIST_0) + uiPartOffset, m_apiMVPIdx[0], iSizeInUchar );
1532  memcpy( rpcCU->getMVPIdx(REF_PIC_LIST_1) + uiPartOffset, m_apiMVPIdx[1], iSizeInUchar );
1533  memcpy( rpcCU->getMVPNum(REF_PIC_LIST_0) + uiPartOffset, m_apiMVPNum[0], iSizeInUchar );
1534  memcpy( rpcCU->getMVPNum(REF_PIC_LIST_1) + uiPartOffset, m_apiMVPNum[1], iSizeInUchar );
1535  m_acCUMvField[0].copyTo( rpcCU->getCUMvField( REF_PIC_LIST_0 ), m_uiAbsIdxInLCU, uiPartStart, uiQNumPart );
1536  m_acCUMvField[1].copyTo( rpcCU->getCUMvField( REF_PIC_LIST_1 ), m_uiAbsIdxInLCU, uiPartStart, uiQNumPart );
1537 
1538  memcpy( rpcCU->getIPCMFlag() + uiPartOffset, m_pbIPCMFlag,         iSizeInBool  );
1539
1540  UInt uiTmp  = (g_uiMaxCUWidth*g_uiMaxCUHeight)>>((uhDepth+uiPartDepth)<<1);
1541  UInt uiTmp2 = uiPartOffset*m_pcPic->getMinCUWidth()*m_pcPic->getMinCUHeight();
1542  memcpy( rpcCU->getCoeffY()  + uiTmp2, m_pcTrCoeffY,  sizeof(TCoeff)*uiTmp  );
1543#if ADAPTIVE_QP_SELECTION
1544  memcpy( rpcCU->getArlCoeffY()  + uiTmp2, m_pcArlCoeffY,  sizeof(Int)*uiTmp  );
1545#endif
1546 
1547  memcpy( rpcCU->getPCMSampleY() + uiTmp2 , m_pcIPCMSampleY, sizeof( Pel ) * uiTmp );
1548
1549  uiTmp >>= 2; uiTmp2 >>= 2;
1550  memcpy( rpcCU->getCoeffCb() + uiTmp2, m_pcTrCoeffCb, sizeof(TCoeff)*uiTmp  );
1551  memcpy( rpcCU->getCoeffCr() + uiTmp2, m_pcTrCoeffCr, sizeof(TCoeff)*uiTmp  );
1552#if ADAPTIVE_QP_SELECTION
1553  memcpy( rpcCU->getArlCoeffCb() + uiTmp2, m_pcArlCoeffCb, sizeof(Int)*uiTmp  );
1554  memcpy( rpcCU->getArlCoeffCr() + uiTmp2, m_pcArlCoeffCr, sizeof(Int)*uiTmp  );
1555#endif
1556
1557  memcpy( rpcCU->getPCMSampleCb() + uiTmp2 , m_pcIPCMSampleCb, sizeof( Pel ) * uiTmp );
1558  memcpy( rpcCU->getPCMSampleCr() + uiTmp2 , m_pcIPCMSampleCr, sizeof( Pel ) * uiTmp );
1559  rpcCU->getTotalBins() = m_uiTotalBins;
1560  memcpy( rpcCU->m_sliceStartCU        + uiPartOffset, m_sliceStartCU,        sizeof( UInt ) * uiQNumPart  );
1561  memcpy( rpcCU->m_sliceSegmentStartCU + uiPartOffset, m_sliceSegmentStartCU, sizeof( UInt ) * uiQNumPart  );
1562#if H_3D_ARP
1563  memcpy( rpcCU->getARPW()             + uiPartOffset, m_puhARPW,             iSizeInUchar );
1564#endif
1565#if H_3D_IC
1566  memcpy( rpcCU->getICFlag()           + uiPartOffset, m_pbICFlag,            iSizeInBool );
1567#endif
1568}
1569
1570// --------------------------------------------------------------------------------------------------------------------
1571// Other public functions
1572// --------------------------------------------------------------------------------------------------------------------
1573
1574TComDataCU* TComDataCU::getPULeft( UInt& uiLPartUnitIdx, 
1575                                   UInt uiCurrPartUnitIdx, 
1576                                   Bool bEnforceSliceRestriction, 
1577                                   Bool bEnforceTileRestriction )
1578{
1579  UInt uiAbsPartIdx       = g_auiZscanToRaster[uiCurrPartUnitIdx];
1580  UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[m_uiAbsIdxInLCU];
1581  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1582 
1583  if ( !RasterAddress::isZeroCol( uiAbsPartIdx, uiNumPartInCUWidth ) )
1584  {
1585    uiLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - 1 ];
1586    if ( RasterAddress::isEqualCol( uiAbsPartIdx, uiAbsZorderCUIdx, uiNumPartInCUWidth ) )
1587    {
1588      return m_pcPic->getCU( getAddr() );
1589    }
1590    else
1591    {
1592      uiLPartUnitIdx -= m_uiAbsIdxInLCU;
1593      return this;
1594    }
1595  }
1596 
1597  uiLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx + uiNumPartInCUWidth - 1 ];
1598
1599
1600  if ( (bEnforceSliceRestriction && (m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL || m_pcCULeft->getSCUAddr()+uiLPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)))
1601      ||
1602       (bEnforceTileRestriction && ( m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL || (m_pcPic->getPicSym()->getTileIdxMap( m_pcCULeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))  )  )
1603      )
1604  {
1605    return NULL;
1606  }
1607  return m_pcCULeft;
1608}
1609
1610TComDataCU* TComDataCU::getPUAbove( UInt& uiAPartUnitIdx,
1611                                    UInt uiCurrPartUnitIdx, 
1612                                    Bool bEnforceSliceRestriction, 
1613                                    Bool planarAtLCUBoundary ,
1614                                    Bool bEnforceTileRestriction )
1615{
1616  UInt uiAbsPartIdx       = g_auiZscanToRaster[uiCurrPartUnitIdx];
1617  UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[m_uiAbsIdxInLCU];
1618  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1619 
1620  if ( !RasterAddress::isZeroRow( uiAbsPartIdx, uiNumPartInCUWidth ) )
1621  {
1622    uiAPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - uiNumPartInCUWidth ];
1623    if ( RasterAddress::isEqualRow( uiAbsPartIdx, uiAbsZorderCUIdx, uiNumPartInCUWidth ) )
1624    {
1625      return m_pcPic->getCU( getAddr() );
1626    }
1627    else
1628    {
1629      uiAPartUnitIdx -= m_uiAbsIdxInLCU;
1630      return this;
1631    }
1632  }
1633
1634  if(planarAtLCUBoundary)
1635  {
1636    return NULL;
1637  }
1638 
1639  uiAPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx + m_pcPic->getNumPartInCU() - uiNumPartInCUWidth ];
1640
1641  if ( (bEnforceSliceRestriction && (m_pcCUAbove==NULL || m_pcCUAbove->getSlice()==NULL || m_pcCUAbove->getSCUAddr()+uiAPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)))
1642      ||
1643       (bEnforceTileRestriction &&(m_pcCUAbove==NULL || m_pcCUAbove->getSlice()==NULL || (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAbove->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))))
1644      )
1645  {
1646    return NULL;
1647  }
1648  return m_pcCUAbove;
1649}
1650
1651TComDataCU* TComDataCU::getPUAboveLeft( UInt& uiALPartUnitIdx, UInt uiCurrPartUnitIdx, Bool bEnforceSliceRestriction )
1652{
1653  UInt uiAbsPartIdx       = g_auiZscanToRaster[uiCurrPartUnitIdx];
1654  UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[m_uiAbsIdxInLCU];
1655  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1656 
1657  if ( !RasterAddress::isZeroCol( uiAbsPartIdx, uiNumPartInCUWidth ) )
1658  {
1659    if ( !RasterAddress::isZeroRow( uiAbsPartIdx, uiNumPartInCUWidth ) )
1660    {
1661      uiALPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - uiNumPartInCUWidth - 1 ];
1662      if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdx, uiAbsZorderCUIdx, uiNumPartInCUWidth ) )
1663      {
1664        return m_pcPic->getCU( getAddr() );
1665      }
1666      else
1667      {
1668        uiALPartUnitIdx -= m_uiAbsIdxInLCU;
1669        return this;
1670      }
1671    }
1672    uiALPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx + getPic()->getNumPartInCU() - uiNumPartInCUWidth - 1 ];
1673    if ( (bEnforceSliceRestriction && (m_pcCUAbove==NULL || m_pcCUAbove->getSlice()==NULL ||
1674       m_pcCUAbove->getSCUAddr()+uiALPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1675       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAbove->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1676       ))
1677     )
1678    {
1679      return NULL;
1680    }
1681    return m_pcCUAbove;
1682  }
1683 
1684  if ( !RasterAddress::isZeroRow( uiAbsPartIdx, uiNumPartInCUWidth ) )
1685  {
1686    uiALPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - 1 ];
1687    if ( (bEnforceSliceRestriction && (m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL || 
1688       m_pcCULeft->getSCUAddr()+uiALPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1689       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCULeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1690       ))
1691     )
1692    {
1693      return NULL;
1694    }
1695    return m_pcCULeft;
1696  }
1697 
1698  uiALPartUnitIdx = g_auiRasterToZscan[ m_pcPic->getNumPartInCU() - 1 ];
1699  if ( (bEnforceSliceRestriction && (m_pcCUAboveLeft==NULL || m_pcCUAboveLeft->getSlice()==NULL ||
1700       m_pcCUAboveLeft->getSCUAddr()+uiALPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1701       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAboveLeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1702       ))
1703     )
1704  {
1705    return NULL;
1706  }
1707  return m_pcCUAboveLeft;
1708}
1709
1710TComDataCU* TComDataCU::getPUAboveRight( UInt& uiARPartUnitIdx, UInt uiCurrPartUnitIdx, Bool bEnforceSliceRestriction )
1711{
1712  UInt uiAbsPartIdxRT     = g_auiZscanToRaster[uiCurrPartUnitIdx];
1713  UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + m_puhWidth[0] / m_pcPic->getMinCUWidth() - 1;
1714  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1715 
1716  if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxRT] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )
1717  {
1718    uiARPartUnitIdx = MAX_UINT;
1719    return NULL;
1720  }
1721 
1722  if ( RasterAddress::lessThanCol( uiAbsPartIdxRT, uiNumPartInCUWidth - 1, uiNumPartInCUWidth ) )
1723  {
1724    if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, uiNumPartInCUWidth ) )
1725    {
1726      if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxRT - uiNumPartInCUWidth + 1 ] )
1727      {
1728        uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT - uiNumPartInCUWidth + 1 ];
1729        if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxRT, uiAbsZorderCUIdx, uiNumPartInCUWidth ) )
1730        {
1731          return m_pcPic->getCU( getAddr() );
1732        }
1733        else
1734        {
1735          uiARPartUnitIdx -= m_uiAbsIdxInLCU;
1736          return this;
1737        }
1738      }
1739      uiARPartUnitIdx = MAX_UINT;
1740      return NULL;
1741    }
1742    uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT + m_pcPic->getNumPartInCU() - uiNumPartInCUWidth + 1 ];
1743    if ( (bEnforceSliceRestriction && (m_pcCUAbove==NULL || m_pcCUAbove->getSlice()==NULL ||
1744       m_pcCUAbove->getSCUAddr()+uiARPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1745       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAbove->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1746       ))
1747     )
1748    {
1749      return NULL;
1750    }
1751    return m_pcCUAbove;
1752  }
1753 
1754  if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, uiNumPartInCUWidth ) )
1755  {
1756    uiARPartUnitIdx = MAX_UINT;
1757    return NULL;
1758  }
1759 
1760  uiARPartUnitIdx = g_auiRasterToZscan[ m_pcPic->getNumPartInCU() - uiNumPartInCUWidth ];
1761  if ( (bEnforceSliceRestriction && (m_pcCUAboveRight==NULL || m_pcCUAboveRight->getSlice()==NULL ||
1762       m_pcPic->getPicSym()->getInverseCUOrderMap( m_pcCUAboveRight->getAddr()) > m_pcPic->getPicSym()->getInverseCUOrderMap( getAddr()) ||
1763       m_pcCUAboveRight->getSCUAddr()+uiARPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1764       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAboveRight->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1765       ))
1766     )
1767  {
1768    return NULL;
1769  }
1770  return m_pcCUAboveRight;
1771}
1772
1773TComDataCU* TComDataCU::getPUBelowLeft( UInt& uiBLPartUnitIdx, UInt uiCurrPartUnitIdx, Bool bEnforceSliceRestriction )
1774{
1775  UInt uiAbsPartIdxLB     = g_auiZscanToRaster[uiCurrPartUnitIdx];
1776  UInt uiAbsZorderCUIdxLB = g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + (m_puhHeight[0] / m_pcPic->getMinCUHeight() - 1)*m_pcPic->getNumPartInWidth();
1777  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1778 
1779  if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxLB] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
1780  {
1781    uiBLPartUnitIdx = MAX_UINT;
1782    return NULL;
1783  }
1784 
1785  if ( RasterAddress::lessThanRow( uiAbsPartIdxLB, m_pcPic->getNumPartInHeight() - 1, uiNumPartInCUWidth ) )
1786  {
1787    if ( !RasterAddress::isZeroCol( uiAbsPartIdxLB, uiNumPartInCUWidth ) )
1788    {
1789      if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxLB + uiNumPartInCUWidth - 1 ] )
1790      {
1791        uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + uiNumPartInCUWidth - 1 ];
1792        if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxLB, uiAbsZorderCUIdxLB, uiNumPartInCUWidth ) )
1793        {
1794          return m_pcPic->getCU( getAddr() );
1795        }
1796        else
1797        {
1798          uiBLPartUnitIdx -= m_uiAbsIdxInLCU;
1799          return this;
1800        }
1801      }
1802      uiBLPartUnitIdx = MAX_UINT;
1803      return NULL;
1804    }
1805    uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + uiNumPartInCUWidth*2 - 1 ];
1806    if ( (bEnforceSliceRestriction && (m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL || 
1807       m_pcCULeft->getSCUAddr()+uiBLPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1808       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCULeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1809       ))
1810     )
1811    {
1812      return NULL;
1813    }
1814    return m_pcCULeft;
1815  }
1816 
1817  uiBLPartUnitIdx = MAX_UINT;
1818  return NULL;
1819}
1820
1821TComDataCU* TComDataCU::getPUBelowLeftAdi(UInt& uiBLPartUnitIdx,  UInt uiCurrPartUnitIdx, UInt uiPartUnitOffset, Bool bEnforceSliceRestriction )
1822{
1823  UInt uiAbsPartIdxLB     = g_auiZscanToRaster[uiCurrPartUnitIdx];
1824  UInt uiAbsZorderCUIdxLB = g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + ((m_puhHeight[0] / m_pcPic->getMinCUHeight()) - 1)*m_pcPic->getNumPartInWidth();
1825  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1826 
1827  if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxLB] + (m_pcPic->getPicSym()->getMinCUHeight() * uiPartUnitOffset)) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples())
1828  {
1829    uiBLPartUnitIdx = MAX_UINT;
1830    return NULL;
1831  }
1832 
1833  if ( RasterAddress::lessThanRow( uiAbsPartIdxLB, m_pcPic->getNumPartInHeight() - uiPartUnitOffset, uiNumPartInCUWidth ) )
1834  {
1835    if ( !RasterAddress::isZeroCol( uiAbsPartIdxLB, uiNumPartInCUWidth ) )
1836    {
1837      if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxLB + uiPartUnitOffset * uiNumPartInCUWidth - 1 ] )
1838      {
1839        uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + uiPartUnitOffset * uiNumPartInCUWidth - 1 ];
1840        if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxLB, uiAbsZorderCUIdxLB, uiNumPartInCUWidth ) )
1841        {
1842          return m_pcPic->getCU( getAddr() );
1843        }
1844        else
1845        {
1846          uiBLPartUnitIdx -= m_uiAbsIdxInLCU;
1847          return this;
1848        }
1849      }
1850      uiBLPartUnitIdx = MAX_UINT;
1851      return NULL;
1852    }
1853    uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + (1+uiPartUnitOffset) * uiNumPartInCUWidth - 1 ];
1854    if ( (bEnforceSliceRestriction && (m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL || 
1855       m_pcCULeft->getSCUAddr()+uiBLPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1856       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCULeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1857       ))
1858     )
1859    {
1860      return NULL;
1861    }
1862    return m_pcCULeft;
1863  }
1864 
1865  uiBLPartUnitIdx = MAX_UINT;
1866  return NULL;
1867}
1868
1869TComDataCU* TComDataCU::getPUAboveRightAdi(UInt&  uiARPartUnitIdx, UInt uiCurrPartUnitIdx, UInt uiPartUnitOffset, Bool bEnforceSliceRestriction )
1870{
1871  UInt uiAbsPartIdxRT     = g_auiZscanToRaster[uiCurrPartUnitIdx];
1872  UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + (m_puhWidth[0] / m_pcPic->getMinCUWidth()) - 1;
1873  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1874 
1875  if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxRT] + (m_pcPic->getPicSym()->getMinCUHeight() * uiPartUnitOffset)) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )
1876  {
1877    uiARPartUnitIdx = MAX_UINT;
1878    return NULL;
1879  }
1880 
1881  if ( RasterAddress::lessThanCol( uiAbsPartIdxRT, uiNumPartInCUWidth - uiPartUnitOffset, uiNumPartInCUWidth ) )
1882  {
1883    if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, uiNumPartInCUWidth ) )
1884    {
1885      if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxRT - uiNumPartInCUWidth + uiPartUnitOffset ] )
1886      {
1887        uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT - uiNumPartInCUWidth + uiPartUnitOffset ];
1888        if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxRT, uiAbsZorderCUIdx, uiNumPartInCUWidth ) )
1889        {
1890          return m_pcPic->getCU( getAddr() );
1891        }
1892        else
1893        {
1894          uiARPartUnitIdx -= m_uiAbsIdxInLCU;
1895          return this;
1896        }
1897      }
1898      uiARPartUnitIdx = MAX_UINT;
1899      return NULL;
1900    }
1901    uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT + m_pcPic->getNumPartInCU() - uiNumPartInCUWidth + uiPartUnitOffset ];
1902    if ( (bEnforceSliceRestriction && (m_pcCUAbove==NULL || m_pcCUAbove->getSlice()==NULL || 
1903       m_pcCUAbove->getSCUAddr()+uiARPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1904       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAbove->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1905       ))
1906     )
1907    {
1908      return NULL;
1909    }
1910    return m_pcCUAbove;
1911  }
1912 
1913  if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, uiNumPartInCUWidth ) )
1914  {
1915    uiARPartUnitIdx = MAX_UINT;
1916    return NULL;
1917  }
1918 
1919  uiARPartUnitIdx = g_auiRasterToZscan[ m_pcPic->getNumPartInCU() - uiNumPartInCUWidth + uiPartUnitOffset-1 ];
1920  if ( (bEnforceSliceRestriction && (m_pcCUAboveRight==NULL || m_pcCUAboveRight->getSlice()==NULL ||
1921       m_pcPic->getPicSym()->getInverseCUOrderMap( m_pcCUAboveRight->getAddr()) > m_pcPic->getPicSym()->getInverseCUOrderMap( getAddr()) ||
1922       m_pcCUAboveRight->getSCUAddr()+uiARPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1923       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAboveRight->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1924       ))
1925     )
1926  {
1927    return NULL;
1928  }
1929  return m_pcCUAboveRight;
1930}
1931
1932/** Get left QpMinCu
1933*\param   uiLPartUnitIdx
1934*\param   uiCurrAbsIdxInLCU
1935*\returns TComDataCU*   point of TComDataCU of left QpMinCu
1936*/
1937TComDataCU* TComDataCU::getQpMinCuLeft( UInt& uiLPartUnitIdx, UInt uiCurrAbsIdxInLCU)
1938{
1939  UInt numPartInCUWidth = m_pcPic->getNumPartInWidth();
1940  UInt absZorderQpMinCUIdx = (uiCurrAbsIdxInLCU>>((g_uiMaxCUDepth - getSlice()->getPPS()->getMaxCuDQPDepth())<<1))<<((g_uiMaxCUDepth -getSlice()->getPPS()->getMaxCuDQPDepth())<<1);
1941  UInt absRorderQpMinCUIdx = g_auiZscanToRaster[absZorderQpMinCUIdx];
1942
1943  // check for left LCU boundary
1944  if ( RasterAddress::isZeroCol(absRorderQpMinCUIdx, numPartInCUWidth) )
1945  {
1946    return NULL;
1947  }
1948
1949  // get index of left-CU relative to top-left corner of current quantization group
1950  uiLPartUnitIdx = g_auiRasterToZscan[absRorderQpMinCUIdx - 1];
1951
1952  // return pointer to current LCU
1953  return m_pcPic->getCU( getAddr() );
1954}
1955
1956/** Get Above QpMinCu
1957*\param   aPartUnitIdx
1958*\param   currAbsIdxInLCU
1959*\returns TComDataCU*   point of TComDataCU of above QpMinCu
1960*/
1961TComDataCU* TComDataCU::getQpMinCuAbove( UInt& aPartUnitIdx, UInt currAbsIdxInLCU )
1962{
1963  UInt numPartInCUWidth = m_pcPic->getNumPartInWidth();
1964  UInt absZorderQpMinCUIdx = (currAbsIdxInLCU>>((g_uiMaxCUDepth - getSlice()->getPPS()->getMaxCuDQPDepth())<<1))<<((g_uiMaxCUDepth - getSlice()->getPPS()->getMaxCuDQPDepth())<<1);
1965  UInt absRorderQpMinCUIdx = g_auiZscanToRaster[absZorderQpMinCUIdx];
1966
1967  // check for top LCU boundary
1968  if ( RasterAddress::isZeroRow( absRorderQpMinCUIdx, numPartInCUWidth) )
1969  {
1970    return NULL;
1971  }
1972
1973  // get index of top-CU relative to top-left corner of current quantization group
1974  aPartUnitIdx = g_auiRasterToZscan[absRorderQpMinCUIdx - numPartInCUWidth];
1975
1976  // return pointer to current LCU
1977  return m_pcPic->getCU( getAddr() );
1978}
1979
1980/** Get reference QP from left QpMinCu or latest coded QP
1981*\param   uiCurrAbsIdxInLCU
1982*\returns Char   reference QP value
1983*/
1984Char TComDataCU::getRefQP( UInt uiCurrAbsIdxInLCU )
1985{
1986  UInt        lPartIdx = 0, aPartIdx = 0;
1987  TComDataCU* cULeft  = getQpMinCuLeft ( lPartIdx, m_uiAbsIdxInLCU + uiCurrAbsIdxInLCU );
1988  TComDataCU* cUAbove = getQpMinCuAbove( aPartIdx, m_uiAbsIdxInLCU + uiCurrAbsIdxInLCU );
1989  return (((cULeft? cULeft->getQP( lPartIdx ): getLastCodedQP( uiCurrAbsIdxInLCU )) + (cUAbove? cUAbove->getQP( aPartIdx ): getLastCodedQP( uiCurrAbsIdxInLCU )) + 1) >> 1);
1990}
1991
1992Int TComDataCU::getLastValidPartIdx( Int iAbsPartIdx )
1993{
1994  Int iLastValidPartIdx = iAbsPartIdx-1;
1995  while ( iLastValidPartIdx >= 0
1996       && getPredictionMode( iLastValidPartIdx ) == MODE_NONE )
1997  {
1998    UInt uiDepth = getDepth( iLastValidPartIdx );
1999    iLastValidPartIdx -= m_uiNumPartition>>(uiDepth<<1);
2000  }
2001  return iLastValidPartIdx;
2002}
2003
2004Char TComDataCU::getLastCodedQP( UInt uiAbsPartIdx )
2005{
2006  UInt uiQUPartIdxMask = ~((1<<((g_uiMaxCUDepth - getSlice()->getPPS()->getMaxCuDQPDepth())<<1))-1);
2007  Int iLastValidPartIdx = getLastValidPartIdx( uiAbsPartIdx&uiQUPartIdxMask );
2008  if ( uiAbsPartIdx < m_uiNumPartition
2009    && (getSCUAddr()+iLastValidPartIdx < getSliceStartCU(m_uiAbsIdxInLCU+uiAbsPartIdx)))
2010  {
2011    return getSlice()->getSliceQp();
2012  }
2013  else if ( iLastValidPartIdx >= 0 )
2014  {
2015    return getQP( iLastValidPartIdx );
2016  }
2017  else
2018  {
2019    if ( getZorderIdxInCU() > 0 )
2020    {
2021      return getPic()->getCU( getAddr() )->getLastCodedQP( getZorderIdxInCU() );
2022    }
2023    else if ( getPic()->getPicSym()->getInverseCUOrderMap(getAddr()) > 0
2024      && getPic()->getPicSym()->getTileIdxMap(getAddr()) == getPic()->getPicSym()->getTileIdxMap(getPic()->getPicSym()->getCUOrderMap(getPic()->getPicSym()->getInverseCUOrderMap(getAddr())-1))
2025      && !( getSlice()->getPPS()->getEntropyCodingSyncEnabledFlag() && getAddr() % getPic()->getFrameWidthInCU() == 0 ) )
2026    {
2027      return getPic()->getCU( getPic()->getPicSym()->getCUOrderMap(getPic()->getPicSym()->getInverseCUOrderMap(getAddr())-1) )->getLastCodedQP( getPic()->getNumPartInCU() );
2028    }
2029    else
2030    {
2031      return getSlice()->getSliceQp();
2032    }
2033  }
2034}
2035/** Check whether the CU is coded in lossless coding mode
2036 * \param   uiAbsPartIdx
2037 * \returns true if the CU is coded in lossless coding mode; false if otherwise
2038 */
2039Bool TComDataCU::isLosslessCoded(UInt absPartIdx)
2040{
2041  return (getSlice()->getPPS()->getTransquantBypassEnableFlag() && getCUTransquantBypass (absPartIdx));
2042}
2043
2044/** Get allowed chroma intra modes
2045*\param   uiAbsPartIdx
2046*\param   uiModeList  pointer to chroma intra modes array
2047*\returns
2048*- fill uiModeList with chroma intra modes
2049*/
2050Void TComDataCU::getAllowedChromaDir( UInt uiAbsPartIdx, UInt* uiModeList )
2051{
2052  uiModeList[0] = PLANAR_IDX;
2053  uiModeList[1] = VER_IDX;
2054  uiModeList[2] = HOR_IDX;
2055  uiModeList[3] = DC_IDX;
2056  uiModeList[4] = DM_CHROMA_IDX;
2057
2058  UInt uiLumaMode = getLumaIntraDir( uiAbsPartIdx );
2059
2060  for( Int i = 0; i < NUM_CHROMA_MODE - 1; i++ )
2061  {
2062    if( uiLumaMode == uiModeList[i] )
2063    {
2064      uiModeList[i] = 34; // VER+8 mode
2065      break;
2066    }
2067  }
2068}
2069
2070/** Get most probable intra modes
2071*\param   uiAbsPartIdx
2072*\param   uiIntraDirPred  pointer to the array for MPM storage
2073*\param   piMode          it is set with MPM mode in case both MPM are equal. It is used to restrict RD search at encode side.
2074*\returns Number of MPM
2075*/
2076Int TComDataCU::getIntraDirLumaPredictor( UInt uiAbsPartIdx, Int* uiIntraDirPred, Int* piMode  )
2077{
2078  TComDataCU* pcTempCU;
2079  UInt        uiTempPartIdx;
2080  Int         iLeftIntraDir, iAboveIntraDir;
2081  Int         uiPredNum = 0;
2082 
2083  // Get intra direction of left PU
2084  pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
2085 
2086  iLeftIntraDir  = pcTempCU ? ( pcTempCU->isIntra( uiTempPartIdx ) ? pcTempCU->getLumaIntraDir( uiTempPartIdx ) : DC_IDX ) : DC_IDX;
2087#if H_3D_DIM
2088  mapDepthModeToIntraDir( iLeftIntraDir );
2089#endif
2090 
2091  // Get intra direction of above PU
2092  pcTempCU = getPUAbove( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx, true, true );
2093 
2094  iAboveIntraDir = pcTempCU ? ( pcTempCU->isIntra( uiTempPartIdx ) ? pcTempCU->getLumaIntraDir( uiTempPartIdx ) : DC_IDX ) : DC_IDX;
2095#if H_3D_DIM
2096  mapDepthModeToIntraDir( iAboveIntraDir );
2097#endif
2098 
2099  uiPredNum = 3;
2100  if(iLeftIntraDir == iAboveIntraDir)
2101  {
2102    if( piMode )
2103    {
2104      *piMode = 1;
2105    }
2106   
2107    if (iLeftIntraDir > 1) // angular modes
2108    {
2109      uiIntraDirPred[0] = iLeftIntraDir;
2110      uiIntraDirPred[1] = ((iLeftIntraDir + 29) % 32) + 2;
2111      uiIntraDirPred[2] = ((iLeftIntraDir - 1 ) % 32) + 2;
2112    }
2113    else //non-angular
2114    {
2115      uiIntraDirPred[0] = PLANAR_IDX;
2116      uiIntraDirPred[1] = DC_IDX;
2117      uiIntraDirPred[2] = VER_IDX; 
2118    }
2119  }
2120  else
2121  {
2122    if( piMode )
2123    {
2124      *piMode = 2;
2125    }
2126    uiIntraDirPred[0] = iLeftIntraDir;
2127    uiIntraDirPred[1] = iAboveIntraDir;
2128   
2129    if (iLeftIntraDir && iAboveIntraDir ) //both modes are non-planar
2130    {
2131      uiIntraDirPred[2] = PLANAR_IDX;
2132    }
2133    else
2134    {
2135      uiIntraDirPred[2] =  (iLeftIntraDir+iAboveIntraDir)<2? VER_IDX : DC_IDX;
2136    }
2137  }
2138 
2139  return uiPredNum;
2140}
2141
2142UInt TComDataCU::getCtxSplitFlag( UInt uiAbsPartIdx, UInt uiDepth )
2143{
2144  TComDataCU* pcTempCU;
2145  UInt        uiTempPartIdx;
2146  UInt        uiCtx;
2147  // Get left split flag
2148  pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
2149  uiCtx  = ( pcTempCU ) ? ( ( pcTempCU->getDepth( uiTempPartIdx ) > uiDepth ) ? 1 : 0 ) : 0;
2150 
2151  // Get above split flag
2152  pcTempCU = getPUAbove( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
2153  uiCtx += ( pcTempCU ) ? ( ( pcTempCU->getDepth( uiTempPartIdx ) > uiDepth ) ? 1 : 0 ) : 0;
2154 
2155  return uiCtx;
2156}
2157
2158UInt TComDataCU::getCtxQtCbf( TextType eType, UInt uiTrDepth )
2159{
2160  if( eType )
2161  {
2162    return uiTrDepth;
2163  }
2164  else
2165  {
2166    const UInt uiCtx = ( uiTrDepth == 0 ? 1 : 0 );
2167    return uiCtx;
2168  }
2169}
2170
2171UInt TComDataCU::getQuadtreeTULog2MinSizeInCU( UInt absPartIdx )
2172{
2173  UInt log2CbSize = g_aucConvertToBit[getWidth( absPartIdx )] + 2;
2174  PartSize  partSize  = getPartitionSize( absPartIdx );
2175  UInt quadtreeTUMaxDepth = getPredictionMode( absPartIdx ) == MODE_INTRA ? m_pcSlice->getSPS()->getQuadtreeTUMaxDepthIntra() : m_pcSlice->getSPS()->getQuadtreeTUMaxDepthInter(); 
2176  Int intraSplitFlag = ( getPredictionMode( absPartIdx ) == MODE_INTRA && partSize == SIZE_NxN ) ? 1 : 0;
2177  Int interSplitFlag = ((quadtreeTUMaxDepth == 1) && (getPredictionMode( absPartIdx ) == MODE_INTER) && (partSize != SIZE_2Nx2N) );
2178 
2179  UInt log2MinTUSizeInCU = 0;
2180  if (log2CbSize < (m_pcSlice->getSPS()->getQuadtreeTULog2MinSize() + quadtreeTUMaxDepth - 1 + interSplitFlag + intraSplitFlag) ) 
2181  {
2182    // when fully making use of signaled TUMaxDepth + inter/intraSplitFlag, resulting luma TB size is < QuadtreeTULog2MinSize
2183    log2MinTUSizeInCU = m_pcSlice->getSPS()->getQuadtreeTULog2MinSize();
2184  }
2185  else
2186  {
2187    // when fully making use of signaled TUMaxDepth + inter/intraSplitFlag, resulting luma TB size is still >= QuadtreeTULog2MinSize
2188    log2MinTUSizeInCU = log2CbSize - ( quadtreeTUMaxDepth - 1 + interSplitFlag + intraSplitFlag); // stop when trafoDepth == hierarchy_depth = splitFlag
2189    if ( log2MinTUSizeInCU > m_pcSlice->getSPS()->getQuadtreeTULog2MaxSize())
2190    {
2191      // when fully making use of signaled TUMaxDepth + inter/intraSplitFlag, resulting luma TB size is still > QuadtreeTULog2MaxSize
2192      log2MinTUSizeInCU = m_pcSlice->getSPS()->getQuadtreeTULog2MaxSize();
2193    } 
2194  }
2195  return log2MinTUSizeInCU;
2196}
2197
2198UInt TComDataCU::getCtxSkipFlag( UInt uiAbsPartIdx )
2199{
2200  TComDataCU* pcTempCU;
2201  UInt        uiTempPartIdx;
2202  UInt        uiCtx = 0;
2203 
2204  // Get BCBP of left PU
2205  pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
2206  uiCtx    = ( pcTempCU ) ? pcTempCU->isSkipped( uiTempPartIdx ) : 0;
2207 
2208  // Get BCBP of above PU
2209  pcTempCU = getPUAbove( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
2210  uiCtx   += ( pcTempCU ) ? pcTempCU->isSkipped( uiTempPartIdx ) : 0;
2211 
2212  return uiCtx;
2213}
2214
2215#if H_3D_ARP
2216UInt TComDataCU::getCTXARPWFlag( UInt uiAbsPartIdx )
2217{
2218  TComDataCU* pcTempCU;
2219  UInt        uiTempPartIdx;
2220  UInt        uiCtx = 0;
2221 
2222  pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
2223  uiCtx    = ( pcTempCU ) ? ((pcTempCU->getARPW( uiTempPartIdx )==0)?0:1) : 0;
2224 
2225  pcTempCU = getPUAbove( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
2226  uiCtx   += ( pcTempCU ) ? ((pcTempCU->getARPW( uiTempPartIdx )==0)?0:1): 0;
2227 
2228  return uiCtx;
2229}
2230#endif
2231
2232#if H_3D_IC
2233UInt TComDataCU::getCtxICFlag( UInt uiAbsPartIdx )
2234{
2235  UInt        uiCtx = 0;
2236
2237  return uiCtx;
2238}
2239#endif
2240UInt TComDataCU::getCtxInterDir( UInt uiAbsPartIdx )
2241{
2242  return getDepth( uiAbsPartIdx );
2243}
2244
2245Void TComDataCU::setCbfSubParts( UInt uiCbfY, UInt uiCbfU, UInt uiCbfV, UInt uiAbsPartIdx, UInt uiDepth )
2246{
2247  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2248  memset( m_puhCbf[0] + uiAbsPartIdx, uiCbfY, sizeof( UChar ) * uiCurrPartNumb );
2249  memset( m_puhCbf[1] + uiAbsPartIdx, uiCbfU, sizeof( UChar ) * uiCurrPartNumb );
2250  memset( m_puhCbf[2] + uiAbsPartIdx, uiCbfV, sizeof( UChar ) * uiCurrPartNumb );
2251}
2252
2253Void TComDataCU::setCbfSubParts( UInt uiCbf, TextType eTType, UInt uiAbsPartIdx, UInt uiDepth )
2254{
2255  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2256  memset( m_puhCbf[g_aucConvertTxtTypeToIdx[eTType]] + uiAbsPartIdx, uiCbf, sizeof( UChar ) * uiCurrPartNumb );
2257}
2258
2259/** Sets a coded block flag for all sub-partitions of a partition
2260 * \param uiCbf The value of the coded block flag to be set
2261 * \param eTType
2262 * \param uiAbsPartIdx
2263 * \param uiPartIdx
2264 * \param uiDepth
2265 * \returns Void
2266 */
2267Void TComDataCU::setCbfSubParts ( UInt uiCbf, TextType eTType, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
2268{
2269  setSubPart<UChar>( uiCbf, m_puhCbf[g_aucConvertTxtTypeToIdx[eTType]], uiAbsPartIdx, uiDepth, uiPartIdx );
2270}
2271
2272Void TComDataCU::setDepthSubParts( UInt uiDepth, UInt uiAbsPartIdx )
2273{
2274  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2275  memset( m_puhDepth + uiAbsPartIdx, uiDepth, sizeof(UChar)*uiCurrPartNumb );
2276}
2277
2278Bool TComDataCU::isFirstAbsZorderIdxInDepth (UInt uiAbsPartIdx, UInt uiDepth)
2279{
2280  UInt uiPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2281  return (((m_uiAbsIdxInLCU + uiAbsPartIdx)% uiPartNumb) == 0);
2282}
2283
2284Void TComDataCU::setPartSizeSubParts( PartSize eMode, UInt uiAbsPartIdx, UInt uiDepth )
2285{
2286  assert( sizeof( *m_pePartSize) == 1 );
2287  memset( m_pePartSize + uiAbsPartIdx, eMode, m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ) );
2288}
2289
2290Void TComDataCU::setCUTransquantBypassSubParts( Bool flag, UInt uiAbsPartIdx, UInt uiDepth )
2291{
2292  memset( m_CUTransquantBypass + uiAbsPartIdx, flag, m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ) );
2293}
2294
2295Void TComDataCU::setSkipFlagSubParts( Bool skip, UInt absPartIdx, UInt depth )
2296{
2297  assert( sizeof( *m_skipFlag) == 1 );
2298  memset( m_skipFlag + absPartIdx, skip, m_pcPic->getNumPartInCU() >> ( 2 * depth ) );
2299}
2300
2301Void TComDataCU::setPredModeSubParts( PredMode eMode, UInt uiAbsPartIdx, UInt uiDepth )
2302{
2303  assert( sizeof( *m_pePredMode) == 1 );
2304  memset( m_pePredMode + uiAbsPartIdx, eMode, m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ) );
2305}
2306
2307Void TComDataCU::setQPSubCUs( Int qp, TComDataCU* pcCU, UInt absPartIdx, UInt depth, Bool &foundNonZeroCbf )
2308{
2309  UInt currPartNumb = m_pcPic->getNumPartInCU() >> (depth << 1);
2310  UInt currPartNumQ = currPartNumb >> 2;
2311
2312  if(!foundNonZeroCbf)
2313  {
2314    if(pcCU->getDepth(absPartIdx) > depth)
2315    {
2316      for ( UInt partUnitIdx = 0; partUnitIdx < 4; partUnitIdx++ )
2317      {
2318        pcCU->setQPSubCUs( qp, pcCU, absPartIdx+partUnitIdx*currPartNumQ, depth+1, foundNonZeroCbf );
2319      }
2320    }
2321    else
2322    {
2323      if(pcCU->getCbf( absPartIdx, TEXT_LUMA ) || pcCU->getCbf( absPartIdx, TEXT_CHROMA_U ) || pcCU->getCbf( absPartIdx, TEXT_CHROMA_V ) )
2324      {
2325        foundNonZeroCbf = true;
2326      }
2327      else
2328      {
2329        setQPSubParts(qp, absPartIdx, depth);
2330      }
2331    }
2332  }
2333}
2334
2335Void TComDataCU::setQPSubParts( Int qp, UInt uiAbsPartIdx, UInt uiDepth )
2336{
2337  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2338  TComSlice * pcSlice = getPic()->getSlice(getPic()->getCurrSliceIdx());
2339
2340  for(UInt uiSCUIdx = uiAbsPartIdx; uiSCUIdx < uiAbsPartIdx+uiCurrPartNumb; uiSCUIdx++)
2341  {
2342    if( m_pcPic->getCU( getAddr() )->getSliceSegmentStartCU(uiSCUIdx+getZorderIdxInCU()) == pcSlice->getSliceSegmentCurStartCUAddr() )
2343    {
2344      m_phQP[uiSCUIdx] = qp;
2345    }
2346  }
2347}
2348
2349Void TComDataCU::setLumaIntraDirSubParts( UInt uiDir, UInt uiAbsPartIdx, UInt uiDepth )
2350{
2351  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2352 
2353  memset( m_puhLumaIntraDir + uiAbsPartIdx, uiDir, sizeof(UChar)*uiCurrPartNumb );
2354}
2355
2356template<typename T>
2357Void TComDataCU::setSubPart( T uiParameter, T* puhBaseLCU, UInt uiCUAddr, UInt uiCUDepth, UInt uiPUIdx )
2358{
2359  assert( sizeof(T) == 1 ); // Using memset() works only for types of size 1
2360 
2361  UInt uiCurrPartNumQ = (m_pcPic->getNumPartInCU() >> (2 * uiCUDepth)) >> 2;
2362  switch ( m_pePartSize[ uiCUAddr ] )
2363  {
2364    case SIZE_2Nx2N:
2365      memset( puhBaseLCU + uiCUAddr, uiParameter, 4 * uiCurrPartNumQ );
2366      break;
2367    case SIZE_2NxN:
2368      memset( puhBaseLCU + uiCUAddr, uiParameter, 2 * uiCurrPartNumQ );
2369      break;
2370    case SIZE_Nx2N:
2371      memset( puhBaseLCU + uiCUAddr, uiParameter, uiCurrPartNumQ );
2372      memset( puhBaseLCU + uiCUAddr + 2 * uiCurrPartNumQ, uiParameter, uiCurrPartNumQ );
2373      break;
2374    case SIZE_NxN:
2375      memset( puhBaseLCU + uiCUAddr, uiParameter, uiCurrPartNumQ ); 
2376      break;
2377    case SIZE_2NxnU:
2378      if ( uiPUIdx == 0 )
2379      {
2380        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 1) );                     
2381        memset( puhBaseLCU + uiCUAddr + uiCurrPartNumQ, uiParameter, (uiCurrPartNumQ >> 1) );                     
2382      }
2383      else if ( uiPUIdx == 1 )
2384      {
2385        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 1) );                     
2386        memset( puhBaseLCU + uiCUAddr + uiCurrPartNumQ, uiParameter, ((uiCurrPartNumQ >> 1) + (uiCurrPartNumQ << 1)) );                     
2387      }
2388      else
2389      {
2390        assert(0);
2391      }
2392      break;
2393    case SIZE_2NxnD:
2394      if ( uiPUIdx == 0 )
2395      {
2396        memset( puhBaseLCU + uiCUAddr, uiParameter, ((uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1)) );                     
2397        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + uiCurrPartNumQ, uiParameter, (uiCurrPartNumQ >> 1) );                     
2398      }
2399      else if ( uiPUIdx == 1 )
2400      {
2401        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 1) );                     
2402        memset( puhBaseLCU + uiCUAddr + uiCurrPartNumQ, uiParameter, (uiCurrPartNumQ >> 1) );                     
2403      }
2404      else
2405      {
2406        assert(0);
2407      }
2408      break;
2409    case SIZE_nLx2N:
2410      if ( uiPUIdx == 0 )
2411      {
2412        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 2) );
2413        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) ); 
2414        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ >> 2) ); 
2415        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) ); 
2416      }
2417      else if ( uiPUIdx == 1 )
2418      {
2419        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 2) );
2420        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) ); 
2421        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ >> 2) ); 
2422        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) ); 
2423      }
2424      else
2425      {
2426        assert(0);
2427      }
2428      break;
2429    case SIZE_nRx2N:
2430      if ( uiPUIdx == 0 )
2431      {     
2432        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) );                           
2433        memset( puhBaseLCU + uiCUAddr + uiCurrPartNumQ + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );                           
2434        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) );                           
2435        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + uiCurrPartNumQ + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );                           
2436      }
2437      else if ( uiPUIdx == 1 )
2438      {
2439        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 2) );                           
2440        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );                           
2441        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ >> 2) );                           
2442        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );                         
2443      }
2444      else
2445      {
2446        assert(0);
2447      }
2448      break;
2449    default:
2450      assert( 0 );
2451  }
2452}
2453
2454#if H_3D_DIM_SDC
2455Void TComDataCU::setSDCFlagSubParts ( Bool bSDCFlag, UInt uiAbsPartIdx, UInt uiDepth )
2456{
2457  assert( sizeof( *m_pbSDCFlag) == 1 );
2458  memset( m_pbSDCFlag + uiAbsPartIdx, bSDCFlag, m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ) );
2459}
2460
2461Bool TComDataCU::getSDCAvailable( UInt uiAbsPartIdx )
2462{
2463  // check general CU information
2464  if( !getSlice()->getIsDepth() || !isIntra(uiAbsPartIdx) || getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N )
2465    return false;
2466 
2467  // check prediction mode
2468  UInt uiLumaPredMode = getLumaIntraDir( uiAbsPartIdx ); 
2469  if( uiLumaPredMode == DC_IDX || uiLumaPredMode == PLANAR_IDX || ( getDimType( uiLumaPredMode ) == DMM1_IDX && !isDimDeltaDC( uiLumaPredMode ) ) )
2470    return true;
2471 
2472  // else
2473  return false;
2474}
2475#endif
2476Void TComDataCU::setMergeFlagSubParts ( Bool bMergeFlag, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
2477{
2478  setSubPart( bMergeFlag, m_pbMergeFlag, uiAbsPartIdx, uiDepth, uiPartIdx );
2479}
2480
2481Void TComDataCU::setMergeIndexSubParts ( UInt uiMergeIndex, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
2482{
2483  setSubPart<UChar>( uiMergeIndex, m_puhMergeIndex, uiAbsPartIdx, uiDepth, uiPartIdx );
2484}
2485
2486#if H_3D_VSP
2487Void TComDataCU::setVSPFlagSubParts( Char iVSPFlag, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
2488{
2489  setSubPart<Char>( iVSPFlag, m_piVSPFlag, uiAbsPartIdx, uiDepth, uiPartIdx );
2490}
2491#endif
2492Void TComDataCU::setChromIntraDirSubParts( UInt uiDir, UInt uiAbsPartIdx, UInt uiDepth )
2493{
2494  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2495 
2496  memset( m_puhChromaIntraDir + uiAbsPartIdx, uiDir, sizeof(UChar)*uiCurrPartNumb );
2497}
2498
2499Void TComDataCU::setInterDirSubParts( UInt uiDir, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
2500{
2501  setSubPart<UChar>( uiDir, m_puhInterDir, uiAbsPartIdx, uiDepth, uiPartIdx );
2502}
2503
2504Void TComDataCU::setMVPIdxSubParts( Int iMVPIdx, RefPicList eRefPicList, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
2505{
2506  setSubPart<Char>( iMVPIdx, m_apiMVPIdx[eRefPicList], uiAbsPartIdx, uiDepth, uiPartIdx );
2507}
2508
2509Void TComDataCU::setMVPNumSubParts( Int iMVPNum, RefPicList eRefPicList, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
2510{
2511  setSubPart<Char>( iMVPNum, m_apiMVPNum[eRefPicList], uiAbsPartIdx, uiDepth, uiPartIdx );
2512}
2513
2514
2515Void TComDataCU::setTrIdxSubParts( UInt uiTrIdx, UInt uiAbsPartIdx, UInt uiDepth )
2516{
2517  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2518 
2519  memset( m_puhTrIdx + uiAbsPartIdx, uiTrIdx, sizeof(UChar)*uiCurrPartNumb );
2520}
2521
2522Void TComDataCU::setTransformSkipSubParts( UInt useTransformSkipY, UInt useTransformSkipU, UInt useTransformSkipV, UInt uiAbsPartIdx, UInt uiDepth )
2523{
2524  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2525
2526  memset( m_puhTransformSkip[0] + uiAbsPartIdx, useTransformSkipY, sizeof( UChar ) * uiCurrPartNumb );
2527  memset( m_puhTransformSkip[1] + uiAbsPartIdx, useTransformSkipU, sizeof( UChar ) * uiCurrPartNumb );
2528  memset( m_puhTransformSkip[2] + uiAbsPartIdx, useTransformSkipV, sizeof( UChar ) * uiCurrPartNumb );
2529}
2530
2531Void TComDataCU::setTransformSkipSubParts( UInt useTransformSkip, TextType eType, UInt uiAbsPartIdx, UInt uiDepth)
2532{
2533  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2534
2535  memset( m_puhTransformSkip[g_aucConvertTxtTypeToIdx[eType]] + uiAbsPartIdx, useTransformSkip, sizeof( UChar ) * uiCurrPartNumb );
2536}
2537
2538Void TComDataCU::setSizeSubParts( UInt uiWidth, UInt uiHeight, UInt uiAbsPartIdx, UInt uiDepth )
2539{
2540  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2541 
2542  memset( m_puhWidth  + uiAbsPartIdx, uiWidth,  sizeof(UChar)*uiCurrPartNumb );
2543  memset( m_puhHeight + uiAbsPartIdx, uiHeight, sizeof(UChar)*uiCurrPartNumb );
2544}
2545
2546UChar TComDataCU::getNumPartInter()
2547{
2548  UChar iNumPart = 0;
2549 
2550  switch ( m_pePartSize[0] )
2551  {
2552    case SIZE_2Nx2N:    iNumPart = 1; break;
2553    case SIZE_2NxN:     iNumPart = 2; break;
2554    case SIZE_Nx2N:     iNumPart = 2; break;
2555    case SIZE_NxN:      iNumPart = 4; break;
2556    case SIZE_2NxnU:    iNumPart = 2; break;
2557    case SIZE_2NxnD:    iNumPart = 2; break;
2558    case SIZE_nLx2N:    iNumPart = 2; break;
2559    case SIZE_nRx2N:    iNumPart = 2; break;
2560    default:            assert (0);   break;
2561  }
2562 
2563  return  iNumPart;
2564}
2565
2566#if H_3D_IC
2567Void TComDataCU::getPartIndexAndSize( UInt uiPartIdx, UInt& ruiPartAddr, Int& riWidth, Int& riHeight, UInt uiAbsPartIdx, Bool bLCU)
2568{
2569  UInt uiNumPartition  = bLCU ? (getWidth(uiAbsPartIdx)*getHeight(uiAbsPartIdx) >> 4) : m_uiNumPartition;
2570  UInt  uiTmpAbsPartIdx  = bLCU ? uiAbsPartIdx : 0;
2571
2572  switch ( m_pePartSize[uiTmpAbsPartIdx] )
2573  {
2574  case SIZE_2NxN:
2575    riWidth = getWidth( uiTmpAbsPartIdx );      riHeight = getHeight( uiTmpAbsPartIdx ) >> 1; ruiPartAddr = ( uiPartIdx == 0 )? 0 : uiNumPartition >> 1;
2576    break;
2577  case SIZE_Nx2N:
2578    riWidth = getWidth( uiTmpAbsPartIdx ) >> 1; riHeight = getHeight( uiTmpAbsPartIdx );      ruiPartAddr = ( uiPartIdx == 0 )? 0 : uiNumPartition >> 2;
2579    break;
2580  case SIZE_NxN:
2581    riWidth = getWidth( uiTmpAbsPartIdx ) >> 1; riHeight = getHeight( uiTmpAbsPartIdx ) >> 1; ruiPartAddr = ( uiNumPartition >> 2 ) * uiPartIdx;
2582    break;
2583  case SIZE_2NxnU:
2584    riWidth     = getWidth( uiTmpAbsPartIdx );
2585    riHeight    = ( uiPartIdx == 0 ) ?  getHeight( uiTmpAbsPartIdx ) >> 2 : ( getHeight( uiTmpAbsPartIdx ) >> 2 ) + ( getHeight( uiTmpAbsPartIdx ) >> 1 );
2586    ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : uiNumPartition >> 3;
2587    break;
2588  case SIZE_2NxnD:
2589    riWidth     = getWidth( uiTmpAbsPartIdx );
2590    riHeight    = ( uiPartIdx == 0 ) ?  ( getHeight( uiTmpAbsPartIdx ) >> 2 ) + ( getHeight( uiTmpAbsPartIdx ) >> 1 ) : getHeight( uiTmpAbsPartIdx ) >> 2;
2591    ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : (uiNumPartition >> 1) + (uiNumPartition >> 3);
2592    break;
2593  case SIZE_nLx2N:
2594    riWidth     = ( uiPartIdx == 0 ) ? getWidth( uiTmpAbsPartIdx ) >> 2 : ( getWidth( uiTmpAbsPartIdx ) >> 2 ) + ( getWidth( uiTmpAbsPartIdx ) >> 1 );
2595    riHeight    = getHeight( uiTmpAbsPartIdx );
2596    ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : uiNumPartition >> 4;
2597    break;
2598  case SIZE_nRx2N:
2599    riWidth     = ( uiPartIdx == 0 ) ? ( getWidth( uiTmpAbsPartIdx ) >> 2 ) + ( getWidth( uiTmpAbsPartIdx ) >> 1 ) : getWidth( uiTmpAbsPartIdx ) >> 2;
2600    riHeight    = getHeight( uiTmpAbsPartIdx );
2601    ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : (uiNumPartition >> 2) + (uiNumPartition >> 4);
2602    break;
2603  default:
2604    assert ( m_pePartSize[uiTmpAbsPartIdx] == SIZE_2Nx2N ); 
2605    riWidth = getWidth( uiTmpAbsPartIdx );      riHeight = getHeight( uiTmpAbsPartIdx );      ruiPartAddr = 0;
2606    break;
2607  }
2608}
2609#else
2610Void TComDataCU::getPartIndexAndSize( UInt uiPartIdx, UInt& ruiPartAddr, Int& riWidth, Int& riHeight )
2611{
2612  switch ( m_pePartSize[0] )
2613  {
2614    case SIZE_2NxN:
2615      riWidth = getWidth(0);      riHeight = getHeight(0) >> 1; ruiPartAddr = ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 1;
2616      break;
2617    case SIZE_Nx2N:
2618      riWidth = getWidth(0) >> 1; riHeight = getHeight(0);      ruiPartAddr = ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 2;
2619      break;
2620    case SIZE_NxN:
2621      riWidth = getWidth(0) >> 1; riHeight = getHeight(0) >> 1; ruiPartAddr = ( m_uiNumPartition >> 2 ) * uiPartIdx;
2622      break;
2623    case SIZE_2NxnU:
2624      riWidth     = getWidth(0);
2625      riHeight    = ( uiPartIdx == 0 ) ?  getHeight(0) >> 2 : ( getHeight(0) >> 2 ) + ( getHeight(0) >> 1 );
2626      ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : m_uiNumPartition >> 3;
2627      break;
2628    case SIZE_2NxnD:
2629      riWidth     = getWidth(0);
2630      riHeight    = ( uiPartIdx == 0 ) ?  ( getHeight(0) >> 2 ) + ( getHeight(0) >> 1 ) : getHeight(0) >> 2;
2631      ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : (m_uiNumPartition >> 1) + (m_uiNumPartition >> 3);
2632      break;
2633    case SIZE_nLx2N:
2634      riWidth     = ( uiPartIdx == 0 ) ? getWidth(0) >> 2 : ( getWidth(0) >> 2 ) + ( getWidth(0) >> 1 );
2635      riHeight    = getHeight(0);
2636      ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : m_uiNumPartition >> 4;
2637      break;
2638    case SIZE_nRx2N:
2639      riWidth     = ( uiPartIdx == 0 ) ? ( getWidth(0) >> 2 ) + ( getWidth(0) >> 1 ) : getWidth(0) >> 2;
2640      riHeight    = getHeight(0);
2641      ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : (m_uiNumPartition >> 2) + (m_uiNumPartition >> 4);
2642      break;
2643    default:
2644      assert ( m_pePartSize[0] == SIZE_2Nx2N );
2645      riWidth = getWidth(0);      riHeight = getHeight(0);      ruiPartAddr = 0;
2646      break;
2647  }
2648}
2649#endif
2650
2651
2652Void TComDataCU::getMvField ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefPicList, TComMvField& rcMvField )
2653{
2654  if ( pcCU == NULL )  // OUT OF BOUNDARY
2655  {
2656    TComMv  cZeroMv;
2657    rcMvField.setMvField( cZeroMv, NOT_VALID );
2658    return;
2659  }
2660 
2661  TComCUMvField*  pcCUMvField = pcCU->getCUMvField( eRefPicList );
2662  rcMvField.setMvField( pcCUMvField->getMv( uiAbsPartIdx ), pcCUMvField->getRefIdx( uiAbsPartIdx ) );
2663}
2664
2665Void TComDataCU::deriveLeftRightTopIdxGeneral ( UInt uiAbsPartIdx, UInt uiPartIdx, UInt& ruiPartIdxLT, UInt& ruiPartIdxRT )
2666{
2667  ruiPartIdxLT = m_uiAbsIdxInLCU + uiAbsPartIdx;
2668  UInt uiPUWidth = 0;
2669 
2670  switch ( m_pePartSize[uiAbsPartIdx] )
2671  {
2672    case SIZE_2Nx2N: uiPUWidth = m_puhWidth[uiAbsPartIdx];  break;
2673    case SIZE_2NxN:  uiPUWidth = m_puhWidth[uiAbsPartIdx];   break;
2674    case SIZE_Nx2N:  uiPUWidth = m_puhWidth[uiAbsPartIdx]  >> 1;  break;
2675    case SIZE_NxN:   uiPUWidth = m_puhWidth[uiAbsPartIdx]  >> 1; break;
2676    case SIZE_2NxnU:   uiPUWidth = m_puhWidth[uiAbsPartIdx]; break;
2677    case SIZE_2NxnD:   uiPUWidth = m_puhWidth[uiAbsPartIdx]; break;
2678    case SIZE_nLx2N:   
2679      if ( uiPartIdx == 0 )
2680      {
2681        uiPUWidth = m_puhWidth[uiAbsPartIdx]  >> 2; 
2682      }
2683      else if ( uiPartIdx == 1 )
2684      {
2685        uiPUWidth = (m_puhWidth[uiAbsPartIdx]  >> 1) + (m_puhWidth[uiAbsPartIdx]  >> 2); 
2686      }
2687      else
2688      {
2689        assert(0);
2690      }
2691      break;
2692    case SIZE_nRx2N:   
2693      if ( uiPartIdx == 0 )
2694      {
2695        uiPUWidth = (m_puhWidth[uiAbsPartIdx]  >> 1) + (m_puhWidth[uiAbsPartIdx]  >> 2); 
2696      }
2697      else if ( uiPartIdx == 1 )
2698      {
2699        uiPUWidth = m_puhWidth[uiAbsPartIdx]  >> 2; 
2700      }
2701      else
2702      {
2703        assert(0);
2704      }
2705      break;
2706    default:
2707      assert (0);
2708      break;
2709  }
2710 
2711  ruiPartIdxRT = g_auiRasterToZscan [g_auiZscanToRaster[ ruiPartIdxLT ] + uiPUWidth / m_pcPic->getMinCUWidth() - 1 ];
2712}
2713
2714Void TComDataCU::deriveLeftBottomIdxGeneral( UInt uiAbsPartIdx, UInt uiPartIdx, UInt& ruiPartIdxLB )
2715{
2716  UInt uiPUHeight = 0;
2717  switch ( m_pePartSize[uiAbsPartIdx] )
2718  {
2719    case SIZE_2Nx2N: uiPUHeight = m_puhHeight[uiAbsPartIdx];    break;
2720    case SIZE_2NxN:  uiPUHeight = m_puhHeight[uiAbsPartIdx] >> 1;    break;
2721    case SIZE_Nx2N:  uiPUHeight = m_puhHeight[uiAbsPartIdx];  break;
2722    case SIZE_NxN:   uiPUHeight = m_puhHeight[uiAbsPartIdx] >> 1;    break;
2723    case SIZE_2NxnU: 
2724      if ( uiPartIdx == 0 )
2725      {
2726        uiPUHeight = m_puhHeight[uiAbsPartIdx] >> 2;   
2727      }
2728      else if ( uiPartIdx == 1 )
2729      {
2730        uiPUHeight = (m_puhHeight[uiAbsPartIdx] >> 1) + (m_puhHeight[uiAbsPartIdx] >> 2);   
2731      }
2732      else
2733      {
2734        assert(0);
2735      }
2736      break;
2737    case SIZE_2NxnD: 
2738      if ( uiPartIdx == 0 )
2739      {
2740        uiPUHeight = (m_puhHeight[uiAbsPartIdx] >> 1) + (m_puhHeight[uiAbsPartIdx] >> 2);   
2741      }
2742      else if ( uiPartIdx == 1 )
2743      {
2744        uiPUHeight = m_puhHeight[uiAbsPartIdx] >> 2;   
2745      }
2746      else
2747      {
2748        assert(0);
2749      }
2750      break;
2751    case SIZE_nLx2N: uiPUHeight = m_puhHeight[uiAbsPartIdx];  break;
2752    case SIZE_nRx2N: uiPUHeight = m_puhHeight[uiAbsPartIdx];  break;
2753    default:
2754      assert (0);
2755      break;
2756  }
2757 
2758  ruiPartIdxLB      = g_auiRasterToZscan [g_auiZscanToRaster[ m_uiAbsIdxInLCU + uiAbsPartIdx ] + ((uiPUHeight / m_pcPic->getMinCUHeight()) - 1)*m_pcPic->getNumPartInWidth()];
2759}
2760
2761Void TComDataCU::deriveLeftRightTopIdx ( UInt uiPartIdx, UInt& ruiPartIdxLT, UInt& ruiPartIdxRT )
2762{
2763  ruiPartIdxLT = m_uiAbsIdxInLCU;
2764  ruiPartIdxRT = g_auiRasterToZscan [g_auiZscanToRaster[ ruiPartIdxLT ] + m_puhWidth[0] / m_pcPic->getMinCUWidth() - 1 ];
2765 
2766  switch ( m_pePartSize[0] )
2767  {
2768    case SIZE_2Nx2N:                                                                                                                                break;
2769    case SIZE_2NxN:
2770      ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 1; ruiPartIdxRT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 1;
2771      break;
2772    case SIZE_Nx2N:
2773      ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 2; ruiPartIdxRT -= ( uiPartIdx == 1 )? 0 : m_uiNumPartition >> 2;
2774      break;
2775    case SIZE_NxN:
2776      ruiPartIdxLT += ( m_uiNumPartition >> 2 ) * uiPartIdx;         ruiPartIdxRT +=  ( m_uiNumPartition >> 2 ) * ( uiPartIdx - 1 );
2777      break;
2778    case SIZE_2NxnU:
2779      ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 3;
2780      ruiPartIdxRT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 3;
2781      break;
2782    case SIZE_2NxnD:
2783      ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : ( m_uiNumPartition >> 1 ) + ( m_uiNumPartition >> 3 );
2784      ruiPartIdxRT += ( uiPartIdx == 0 )? 0 : ( m_uiNumPartition >> 1 ) + ( m_uiNumPartition >> 3 );
2785      break;
2786    case SIZE_nLx2N:
2787      ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 4;
2788      ruiPartIdxRT -= ( uiPartIdx == 1 )? 0 : ( m_uiNumPartition >> 2 ) + ( m_uiNumPartition >> 4 );
2789      break;
2790    case SIZE_nRx2N:
2791      ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : ( m_uiNumPartition >> 2 ) + ( m_uiNumPartition >> 4 );
2792      ruiPartIdxRT -= ( uiPartIdx == 1 )? 0 : m_uiNumPartition >> 4;
2793      break;
2794    default:
2795      assert (0);
2796      break;
2797  }
2798 
2799}
2800
2801Void TComDataCU::deriveLeftBottomIdx( UInt  uiPartIdx,      UInt&      ruiPartIdxLB )
2802{
2803  ruiPartIdxLB      = g_auiRasterToZscan [g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + ( ((m_puhHeight[0] / m_pcPic->getMinCUHeight())>>1) - 1)*m_pcPic->getNumPartInWidth()];
2804 
2805  switch ( m_pePartSize[0] )
2806  {
2807    case SIZE_2Nx2N:
2808      ruiPartIdxLB += m_uiNumPartition >> 1;
2809      break;
2810    case SIZE_2NxN:
2811      ruiPartIdxLB += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 1;
2812      break;
2813    case SIZE_Nx2N:
2814      ruiPartIdxLB += ( uiPartIdx == 0 )? m_uiNumPartition >> 1 : (m_uiNumPartition >> 2)*3;
2815      break;
2816    case SIZE_NxN:
2817      ruiPartIdxLB += ( m_uiNumPartition >> 2 ) * uiPartIdx;
2818      break;
2819    case SIZE_2NxnU:
2820      ruiPartIdxLB += ( uiPartIdx == 0 ) ? -((Int)m_uiNumPartition >> 3) : m_uiNumPartition >> 1;
2821      break;
2822    case SIZE_2NxnD:
2823      ruiPartIdxLB += ( uiPartIdx == 0 ) ? (m_uiNumPartition >> 2) + (m_uiNumPartition >> 3): m_uiNumPartition >> 1;
2824      break;
2825    case SIZE_nLx2N:
2826      ruiPartIdxLB += ( uiPartIdx == 0 ) ? m_uiNumPartition >> 1 : (m_uiNumPartition >> 1) + (m_uiNumPartition >> 4);
2827      break;
2828    case SIZE_nRx2N:
2829      ruiPartIdxLB += ( uiPartIdx == 0 ) ? m_uiNumPartition >> 1 : (m_uiNumPartition >> 1) + (m_uiNumPartition >> 2) + (m_uiNumPartition >> 4);
2830      break;
2831    default:
2832      assert (0);
2833      break;
2834  }
2835}
2836
2837/** Derives the partition index of neighbouring bottom right block
2838 * \param [in]  eCUMode
2839 * \param [in]  uiPartIdx
2840 * \param [out] ruiPartIdxRB
2841 */
2842Void TComDataCU::deriveRightBottomIdx( UInt  uiPartIdx,      UInt&      ruiPartIdxRB )
2843{
2844  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];
2845
2846  switch ( m_pePartSize[0] )
2847  {
2848    case SIZE_2Nx2N: 
2849      ruiPartIdxRB += m_uiNumPartition >> 1;   
2850      break;
2851    case SIZE_2NxN: 
2852      ruiPartIdxRB += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 1;   
2853      break;
2854    case SIZE_Nx2N: 
2855      ruiPartIdxRB += ( uiPartIdx == 0 )? m_uiNumPartition >> 2 : (m_uiNumPartition >> 1);   
2856      break;
2857    case SIZE_NxN:   
2858      ruiPartIdxRB += ( m_uiNumPartition >> 2 ) * ( uiPartIdx - 1 );   
2859      break;
2860    case SIZE_2NxnU:
2861      ruiPartIdxRB += ( uiPartIdx == 0 ) ? -((Int)m_uiNumPartition >> 3) : m_uiNumPartition >> 1;
2862      break;
2863    case SIZE_2NxnD:
2864      ruiPartIdxRB += ( uiPartIdx == 0 ) ? (m_uiNumPartition >> 2) + (m_uiNumPartition >> 3): m_uiNumPartition >> 1;
2865      break;
2866    case SIZE_nLx2N:
2867      ruiPartIdxRB += ( uiPartIdx == 0 ) ? (m_uiNumPartition >> 3) + (m_uiNumPartition >> 4): m_uiNumPartition >> 1;
2868      break;
2869    case SIZE_nRx2N:
2870      ruiPartIdxRB += ( uiPartIdx == 0 ) ? (m_uiNumPartition >> 2) + (m_uiNumPartition >> 3) + (m_uiNumPartition >> 4) : m_uiNumPartition >> 1;
2871      break;
2872    default:
2873      assert (0);
2874      break;
2875  }
2876}
2877
2878Void TComDataCU::deriveLeftRightTopIdxAdi ( UInt& ruiPartIdxLT, UInt& ruiPartIdxRT, UInt uiPartOffset, UInt uiPartDepth )
2879{
2880  UInt uiNumPartInWidth = (m_puhWidth[0]/m_pcPic->getMinCUWidth())>>uiPartDepth;
2881  ruiPartIdxLT = m_uiAbsIdxInLCU + uiPartOffset;
2882  ruiPartIdxRT = g_auiRasterToZscan[ g_auiZscanToRaster[ ruiPartIdxLT ] + uiNumPartInWidth - 1 ];
2883}
2884
2885Void TComDataCU::deriveLeftBottomIdxAdi( UInt& ruiPartIdxLB, UInt uiPartOffset, UInt uiPartDepth )
2886{
2887  UInt uiAbsIdx;
2888  UInt uiMinCuWidth, uiWidthInMinCus;
2889 
2890  uiMinCuWidth    = getPic()->getMinCUWidth();
2891  uiWidthInMinCus = (getWidth(0)/uiMinCuWidth)>>uiPartDepth;
2892  uiAbsIdx        = getZorderIdxInCU()+uiPartOffset+(m_uiNumPartition>>(uiPartDepth<<1))-1;
2893  uiAbsIdx        = g_auiZscanToRaster[uiAbsIdx]-(uiWidthInMinCus-1);
2894  ruiPartIdxLB    = g_auiRasterToZscan[uiAbsIdx];
2895}
2896
2897Bool TComDataCU::hasEqualMotion( UInt uiAbsPartIdx, TComDataCU* pcCandCU, UInt uiCandAbsPartIdx )
2898{
2899
2900  if ( getInterDir( uiAbsPartIdx ) != pcCandCU->getInterDir( uiCandAbsPartIdx ) )
2901  {
2902    return false;
2903  }
2904
2905  for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
2906  {
2907    if ( getInterDir( uiAbsPartIdx ) & ( 1 << uiRefListIdx ) )
2908    {
2909      if ( getCUMvField( RefPicList( uiRefListIdx ) )->getMv( uiAbsPartIdx )     != pcCandCU->getCUMvField( RefPicList( uiRefListIdx ) )->getMv( uiCandAbsPartIdx ) || 
2910        getCUMvField( RefPicList( uiRefListIdx ) )->getRefIdx( uiAbsPartIdx ) != pcCandCU->getCUMvField( RefPicList( uiRefListIdx ) )->getRefIdx( uiCandAbsPartIdx ) )
2911      {
2912        return false;
2913      }
2914    }
2915  }
2916
2917  return true;
2918}
2919
2920#if H_3D_VSP
2921
2922/** Add a VSP merging candidate
2923 * \Inputs
2924 * \param uiPUIdx: PU index within a CU
2925 * \param ucVspMergePos: Specify the VSP merge candidate position
2926 * \param mrgCandIdx: Target merge candidate index. At encoder, it is set equal to -1, such that the whole merge candidate list will be constructed.
2927 * \param pDinfo: The "disparity information" derived from neighboring blocks. Type 1 MV.
2928 * \param uiCount: The next position to add VSP merge candidate
2929 *
2930 * \Outputs
2931 * \param uiCount: The next position to add merge candidate. Will be updated if VSP is successfully added
2932 * \param abCandIsInter: abCandIsInter[iCount] tells that VSP candidate is an Inter candidate, if VSP is successfully added
2933 * \param pcMvFieldNeighbours:   Return combined motion information, then stored to a global buffer
2934 *                                    1) the "disparity vector". Type 1 MV. To be used to fetch a depth block.
2935 *                                    2) the ref index /list.    Type 2 reference picture pointer, typically for texture
2936 * \param puhInterDirNeighbours: Indicate the VSP prediction direction.
2937 * \param vspFlag: vspFlag[iCount] will be set (equal to 1), if VSP is successfully added. To be used to indicate the actual position of the VSP candidate
2938 *
2939 * \Return
2940 *   true:  if the VSP candidate is added at the target position
2941 *   false: otherwise
2942 */
2943inline Bool TComDataCU::xAddVspCand( UChar ucVspMergePos, Int mrgCandIdx, DisInfo* pDInfo, Int& iCount,
2944                                     Bool* abCandIsInter, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int* vspFlag )
2945{
2946  if ( ucVspMergePos != H_3D_VSP_POSITION || 0 == m_pcSlice->getViewIndex() || !m_pcSlice->getVPS()->getViewSynthesisPredFlag( m_pcSlice->getLayerIdInVps() ) || m_pcSlice->getIsDepth() )
2947    return false;
2948
2949  Int refViewIdx = pDInfo->m_aVIdxCan;
2950  TComPic* picDepth = getSlice()->getIvPic( true, refViewIdx );
2951  if( picDepth == NULL ) // No depth reference avail
2952    return false;
2953 
2954  Bool refViewAvailFlag = false;
2955  UChar predFlag[2] = {0, 0};
2956  Int  iRefListIdX = 0;
2957  Int  iRefListIdY = 0;
2958  Int  i;
2959
2960  for( iRefListIdX = 0; iRefListIdX < 2 && !refViewAvailFlag; iRefListIdX++ )
2961  {
2962    RefPicList eRefPicList = RefPicList( iRefListIdX );
2963    for ( i = 0; i < m_pcSlice->getNumRefIdx(eRefPicList) && !refViewAvailFlag; i++ )
2964    {
2965      Int viewIdxRefInList = m_pcSlice->getRefPic(eRefPicList, i)->getViewIndex();
2966      if ( viewIdxRefInList == refViewIdx )
2967      {
2968        refViewAvailFlag = true;
2969        predFlag[iRefListIdX] = 1;
2970        iRefListIdY = 1 - iRefListIdX;
2971        pcMvFieldNeighbours[(iCount<<1)+iRefListIdX].setMvField( pDInfo->m_acDoNBDV, i );
2972#if H_3D_NBDV
2973        pcMvFieldNeighbours[(iCount<<1)+iRefListIdX].getMv().setIDVFlag (false);
2974#endif
2975      }
2976    }
2977  }
2978
2979  if (m_pcSlice->isInterB() && refViewAvailFlag)
2980  {
2981    RefPicList eRefPicList = RefPicList( iRefListIdY );
2982    refViewAvailFlag = false;
2983    for ( i = 0; i < m_pcSlice->getNumRefIdx(eRefPicList) && !refViewAvailFlag; i++ )
2984    {
2985      Int viewIdxRefInList = m_pcSlice->getRefPic(eRefPicList, i)->getViewIndex();
2986      if ( viewIdxRefInList != refViewIdx && viewIdxRefInList != m_pcSlice->getViewIndex() )
2987      {
2988        refViewAvailFlag = true;
2989        predFlag[iRefListIdY] = 1;
2990        pcMvFieldNeighbours[(iCount<<1)+iRefListIdY].setMvField( pDInfo->m_acDoNBDV, i );
2991#if H_3D_NBDV
2992        pcMvFieldNeighbours[(iCount<<1)+iRefListIdY].getMv().setIDVFlag (false);
2993#endif
2994      }
2995    }
2996  }
2997
2998  // Set values to be returned
2999  abCandIsInter[iCount] = true;
3000  puhInterDirNeighbours[iCount] = (predFlag[0] | (predFlag[1] << 1));
3001  vspFlag[iCount] = 1;
3002
3003  if ( mrgCandIdx == iCount )
3004    return true;
3005
3006  iCount++;
3007
3008  return false;
3009}
3010
3011#endif
3012/** Constructs a list of merging candidates
3013 * \param uiAbsPartIdx
3014 * \param uiPUIdx
3015 * \param uiDepth
3016 * \param pcMvFieldNeighbours
3017 * \param puhInterDirNeighbours
3018 * \param numValidMergeCand
3019 */
3020Void TComDataCU::getInterMergeCandidates( UInt uiAbsPartIdx, UInt uiPUIdx, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours
3021#if H_3D_VSP
3022      , Int* vspFlag
3023#endif
3024      , Int& numValidMergeCand, Int mrgCandIdx
3025)
3026{
3027  UInt uiAbsPartAddr = m_uiAbsIdxInLCU + uiAbsPartIdx;
3028#if H_3D_IV_MERGE
3029  TComMv cZeroMv;
3030  Bool abCandIsInter[ MRG_MAX_NUM_CANDS_MEM ];
3031#else
3032  Bool abCandIsInter[ MRG_MAX_NUM_CANDS ];
3033#endif
3034  for( UInt ui = 0; ui < getSlice()->getMaxNumMergeCand(); ++ui )
3035  {
3036    abCandIsInter[ui] = false;
3037#if H_3D_IV_MERGE
3038    pcMvFieldNeighbours[ ( ui << 1 )     ].setMvField(cZeroMv, NOT_VALID);
3039    pcMvFieldNeighbours[ ( ui << 1 ) + 1 ].setMvField(cZeroMv, NOT_VALID);
3040#else
3041    pcMvFieldNeighbours[ ( ui << 1 )     ].setRefIdx(NOT_VALID);
3042    pcMvFieldNeighbours[ ( ui << 1 ) + 1 ].setRefIdx(NOT_VALID);
3043#endif
3044  }
3045  numValidMergeCand = getSlice()->getMaxNumMergeCand();
3046  // compute the location of the current PU
3047  Int xP, yP, nPSW, nPSH;
3048  this->getPartPosition(uiPUIdx, xP, yP, nPSW, nPSH);
3049
3050  Int iCount = 0;
3051
3052  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB;
3053  PartSize cCurPS = getPartitionSize( uiAbsPartIdx );
3054  deriveLeftRightTopIdxGeneral( uiAbsPartIdx, uiPUIdx, uiPartIdxLT, uiPartIdxRT );
3055  deriveLeftBottomIdxGeneral  ( uiAbsPartIdx, uiPUIdx, uiPartIdxLB );
3056#if H_3D_IV_MERGE
3057  Bool ivMvPredFlag   = getSlice()->getVPS()->getIvMvPredFlag( getSlice()->getLayerIdInVps() );
3058
3059  //===== add merge with predicted depth maps =====
3060  TComMv  acPdmMv       [4];
3061  Int     aiPdmRefIdx   [4] = {-1, -1, -1, -1};
3062  Bool    bLeftAvai         = false;
3063  Int     iPosLeftAbove[2]  = {-1, -1};
3064
3065
3066  DisInfo cDisInfo;
3067
3068  cDisInfo.bDV = getDvInfo(uiAbsPartIdx).bDV;
3069#if H_3D_NBDV_REF
3070  cDisInfo.m_acDoNBDV = getDvInfo(uiAbsPartIdx).m_acDoNBDV;
3071#endif //H_3D_NBDV_REF
3072  cDisInfo.m_acNBDV = getDvInfo(uiAbsPartIdx).m_acNBDV;
3073  cDisInfo.m_aVIdxCan = getDvInfo(uiAbsPartIdx).m_aVIdxCan;
3074
3075  if( m_pcSlice->getIsDepth())
3076  {
3077    UInt uiPartIdxCenter;
3078    xDeriveCenterIdx( uiPUIdx, uiPartIdxCenter );   
3079    TComDataCU *pcTextureCU = m_pcSlice->getTexturePic()->getCU( getAddr() );
3080 
3081    if ( pcTextureCU && !pcTextureCU->isIntra( uiPartIdxCenter ) )
3082    {
3083      abCandIsInter[iCount] = true;     
3084      puhInterDirNeighbours[iCount] = pcTextureCU->getInterDir( uiPartIdxCenter );
3085#if MTK_SONY_PROGRESSIVE_MV_COMPRESSION_E0170
3086      pcTextureCU->getMvField( pcTextureCU, uiPartIdxCenter, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3087      if (pcMvFieldNeighbours[iCount<<1].getRefIdx()>=0)
3088#else
3089      if( ( puhInterDirNeighbours[iCount] & 1 ) == 1 )
3090#endif
3091      {
3092#if !MTK_SONY_PROGRESSIVE_MV_COMPRESSION_E0170
3093        pcTextureCU->getMvField( pcTextureCU, uiPartIdxCenter, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3094#endif
3095        TComMv cMvPred = pcMvFieldNeighbours[iCount<<1].getMv();
3096
3097#if H_3D_IC
3098        const TComMv cAdd( 1 << ( 2 - 1 ), 1 << ( 2 - 1 ) );
3099        cMvPred+=cAdd;
3100        cMvPred>>=2;
3101        clipMv(cMvPred);
3102#endif
3103        //pcMvFieldNeighbours[iCount<<1].setMvField(cMvPred,pcMvFieldNeighbours[iCount<<1].getRefIdx());
3104#if H_3D //Notes from QC: for BVSP coded blocks, the reference index shall not be equal to -1 due to the adoption of JCT3V-D0191
3105        pcMvFieldNeighbours[iCount<<1].setMvField(cMvPred,pcMvFieldNeighbours[iCount<<1].getRefIdx());
3106#endif
3107      }
3108     
3109      if ( getSlice()->isInterB() )
3110      {
3111#if MTK_SONY_PROGRESSIVE_MV_COMPRESSION_E0170
3112        pcTextureCU->getMvField( pcTextureCU, uiPartIdxCenter, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3113        if (pcMvFieldNeighbours[(iCount<<1)+1].getRefIdx()>=0)
3114#else
3115        if( ( puhInterDirNeighbours[iCount] & 2 ) == 2 )
3116#endif
3117        {
3118#if !MTK_SONY_PROGRESSIVE_MV_COMPRESSION_E0170
3119          pcTextureCU->getMvField( pcTextureCU, uiPartIdxCenter, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3120#endif
3121          TComMv cMvPred = pcMvFieldNeighbours[(iCount<<1)+1].getMv();
3122#if H_3D_IC
3123          const TComMv cAdd( 1 << ( 2 - 1 ), 1 << ( 2 - 1 ) );
3124          cMvPred+=cAdd;
3125          cMvPred>>=2;
3126          clipMv(cMvPred);
3127#endif
3128          pcMvFieldNeighbours[(iCount<<1)+1].setMvField(cMvPred,pcMvFieldNeighbours[(iCount<<1)+1].getRefIdx());
3129        }
3130      }
3131#if MTK_SONY_PROGRESSIVE_MV_COMPRESSION_E0170
3132      puhInterDirNeighbours[iCount] = (pcMvFieldNeighbours[iCount<<1].getRefIdx()>=0)?1:0;
3133      puhInterDirNeighbours[iCount] += (pcMvFieldNeighbours[(iCount<<1)+1].getRefIdx()>=0)?2:0;
3134#endif
3135#if H_3D_NBDV
3136      pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3137      pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3138#endif
3139      if ( mrgCandIdx == iCount )
3140      {
3141        return;
3142      }
3143      iCount ++;
3144    }
3145  }
3146
3147  Int iPdmDir[2] = {0, 0};
3148 
3149  if ( ivMvPredFlag )
3150  {
3151    getInterViewMergeCands(uiPUIdx, aiPdmRefIdx, acPdmMv, &cDisInfo, iPdmDir );
3152  } 
3153   
3154  Int iPdmInterDir;
3155
3156  if( iPdmDir[0] )
3157  {
3158    abCandIsInter        [ iCount ] = true;
3159    puhInterDirNeighbours[ iCount ] = iPdmDir[0];
3160    iPdmInterDir                    = iPdmDir[0];
3161
3162    if( ( iPdmInterDir & 1 ) == 1 )
3163    {
3164      pcMvFieldNeighbours[ iCount<<1    ].setMvField( acPdmMv[ 0 ], aiPdmRefIdx[ 0 ] );
3165    }
3166    if( ( iPdmInterDir & 2 ) == 2 )
3167    {
3168      pcMvFieldNeighbours[(iCount<<1)+1 ].setMvField( acPdmMv[ 1 ], aiPdmRefIdx[ 1 ] );
3169    }
3170
3171    if ( mrgCandIdx == iCount )
3172    {
3173      return;
3174    }
3175    iCount ++;
3176  } 
3177  // early termination
3178  if (iCount == getSlice()->getMaxNumMergeCand()) 
3179  {
3180    return;
3181  }
3182#endif
3183
3184  //left
3185  UInt uiLeftPartIdx = 0;
3186  TComDataCU* pcCULeft = 0;
3187  pcCULeft = getPULeft( uiLeftPartIdx, uiPartIdxLB );
3188  Bool isAvailableA1 = pcCULeft &&
3189  pcCULeft->isDiffMER(xP -1, yP+nPSH-1, xP, yP) &&
3190  !( uiPUIdx == 1 && (cCurPS == SIZE_Nx2N || cCurPS == SIZE_nLx2N || cCurPS == SIZE_nRx2N) ) &&
3191  !pcCULeft->isIntra( uiLeftPartIdx ) ;
3192  if ( isAvailableA1 )
3193  {
3194    abCandIsInter[iCount] = true;
3195    // get Inter Dir
3196    puhInterDirNeighbours[iCount] = pcCULeft->getInterDir( uiLeftPartIdx );
3197    // get Mv from Left
3198    pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3199    if ( getSlice()->isInterB() )
3200    {
3201      pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3202    }
3203#if H_3D_IV_MERGE
3204    Bool bRemoveSpa = false; //pruning to inter-view candidates
3205    Int  iCnloop    = iCount - 1;
3206    for(; iCnloop >= 0; iCnloop --)
3207    {
3208      if(puhInterDirNeighbours[iCount] == puhInterDirNeighbours[iCnloop] && pcMvFieldNeighbours[iCnloop<<1]==pcMvFieldNeighbours[(iCount<<1)] && pcMvFieldNeighbours[(iCnloop<<1)+1]==pcMvFieldNeighbours[(iCount<<1)+1])
3209      {
3210        bRemoveSpa                      = true;
3211        abCandIsInter        [ iCount ] = false;
3212
3213        //reset to the default value for MC
3214        puhInterDirNeighbours[iCount]   = 0;
3215        pcMvFieldNeighbours[iCount<<1].setMvField( cZeroMv, NOT_VALID );
3216        pcMvFieldNeighbours[(iCount<<1)+1].setMvField( cZeroMv, NOT_VALID );
3217        break;
3218      }
3219    }
3220    if(!bRemoveSpa)
3221    {
3222      bLeftAvai = true;
3223      iPosLeftAbove[0] = iCount;
3224#if H_3D_NBDV
3225      pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3226      pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3227#endif
3228#if H_3D_VSP
3229      if (pcCULeft->getVSPFlag(uiLeftPartIdx) == 1)
3230        vspFlag[iCount] = 1;
3231#endif
3232      if ( mrgCandIdx == iCount )
3233      {
3234        return;
3235      }
3236      iCount ++;
3237    }
3238#else
3239    if ( mrgCandIdx == iCount )
3240    {
3241      return;
3242    }
3243    iCount ++;
3244#endif
3245  }
3246 
3247  // early termination
3248  if (iCount == getSlice()->getMaxNumMergeCand()) 
3249  {
3250    return;
3251  }
3252  // above
3253  UInt uiAbovePartIdx = 0;
3254  TComDataCU* pcCUAbove = 0;
3255  pcCUAbove = getPUAbove( uiAbovePartIdx, uiPartIdxRT );
3256  Bool isAvailableB1 = pcCUAbove &&
3257  pcCUAbove->isDiffMER(xP+nPSW-1, yP-1, xP, yP) &&
3258  !( uiPUIdx == 1 && (cCurPS == SIZE_2NxN || cCurPS == SIZE_2NxnU || cCurPS == SIZE_2NxnD) ) &&
3259  !pcCUAbove->isIntra( uiAbovePartIdx );
3260  if ( isAvailableB1 && (!isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAbove, uiAbovePartIdx ) ) )
3261  {
3262    abCandIsInter[iCount] = true;
3263    // get Inter Dir
3264    puhInterDirNeighbours[iCount] = pcCUAbove->getInterDir( uiAbovePartIdx );
3265    // get Mv from Left
3266    pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3267    if ( getSlice()->isInterB() )
3268    {
3269      pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3270    }
3271#if H_3D_IV_MERGE
3272    Bool bRemoveSpa = false; //pruning to inter-view candidates
3273    Int  iCnloop    = bLeftAvai? (iCount-2): (iCount-1);
3274    for(; iCnloop >= 0; iCnloop --)
3275    {
3276      if(puhInterDirNeighbours[iCount] == puhInterDirNeighbours[iCnloop] && pcMvFieldNeighbours[iCnloop<<1]==pcMvFieldNeighbours[(iCount<<1)] && pcMvFieldNeighbours[(iCnloop<<1)+1]==pcMvFieldNeighbours[(iCount<<1)+1])
3277      {
3278        bRemoveSpa                      = true;
3279        abCandIsInter        [ iCount ] = false;
3280
3281        //reset to the default value for MC
3282        puhInterDirNeighbours[iCount]   = 0;
3283
3284        pcMvFieldNeighbours[iCount<<1].setMvField( cZeroMv, NOT_VALID );
3285        pcMvFieldNeighbours[(iCount<<1)+1].setMvField( cZeroMv, NOT_VALID );
3286        break;
3287      }
3288    }
3289    if(!bRemoveSpa)
3290    {
3291      iPosLeftAbove[1] = iCount;
3292#if H_3D_NBDV
3293      pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3294      pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3295#endif
3296#if H_3D_VSP
3297      if (pcCUAbove->getVSPFlag(uiAbovePartIdx) == 1)
3298        vspFlag[iCount] = 1;
3299#endif
3300      if ( mrgCandIdx == iCount )
3301      {
3302        return;
3303      }
3304      iCount ++;
3305    }
3306#else
3307    if ( mrgCandIdx == iCount )
3308    {
3309      return;
3310    }
3311    iCount ++;
3312#endif
3313  }
3314  // early termination
3315  if (iCount == getSlice()->getMaxNumMergeCand()) 
3316  {
3317    return;
3318  }
3319
3320  // above right
3321  UInt uiAboveRightPartIdx = 0;
3322  TComDataCU* pcCUAboveRight = 0;
3323  pcCUAboveRight = getPUAboveRight( uiAboveRightPartIdx, uiPartIdxRT );
3324  Bool isAvailableB0 = pcCUAboveRight &&
3325  pcCUAboveRight->isDiffMER(xP+nPSW, yP-1, xP, yP) &&
3326  !pcCUAboveRight->isIntra( uiAboveRightPartIdx );
3327  if ( isAvailableB0 && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveRight, uiAboveRightPartIdx ) ) )
3328  {
3329    abCandIsInter[iCount] = true;
3330    // get Inter Dir
3331    puhInterDirNeighbours[iCount] = pcCUAboveRight->getInterDir( uiAboveRightPartIdx );
3332    // get Mv from Left
3333    pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3334    if ( getSlice()->isInterB() )
3335    {
3336      pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3337    }
3338#if H_3D_NBDV
3339    pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3340    pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3341#endif
3342#if H_3D_VSP
3343    if (pcCUAboveRight->getVSPFlag(uiAboveRightPartIdx) == 1)
3344      vspFlag[iCount] = 1;
3345#endif
3346    if ( mrgCandIdx == iCount )
3347    {
3348      return;
3349    }
3350    iCount ++;
3351  }
3352  // early termination
3353  if (iCount == getSlice()->getMaxNumMergeCand()) 
3354  {
3355    return;
3356  }
3357
3358#if H_3D_IV_MERGE
3359  if( iPdmDir[1] )
3360  {
3361    assert(iCount < getSlice()->getMaxNumMergeCand());
3362    abCandIsInter        [ iCount ] = true;
3363    puhInterDirNeighbours[ iCount ] = iPdmDir[1];
3364    if( ( iPdmDir[1] & 1 ) == 1 )
3365    {
3366      pcMvFieldNeighbours[ iCount<<1    ].setMvField( acPdmMv[ 2 ], aiPdmRefIdx[ 2 ] );
3367    }
3368    if( ( iPdmDir[1] & 2 ) == 2 )
3369    {
3370      pcMvFieldNeighbours[(iCount<<1)+1 ].setMvField( acPdmMv[ 3 ], aiPdmRefIdx[ 3 ] );
3371    }
3372
3373    Bool bRemoveSpa = false; //pruning to A1, B1
3374    for(Int i = 0; i < 2; i ++)
3375    {
3376      Int iCnloop = iPosLeftAbove[i];
3377      if(iCnloop == -1) 
3378        continue;
3379      if(puhInterDirNeighbours[iCount] == puhInterDirNeighbours[iCnloop] && pcMvFieldNeighbours[iCnloop<<1]==pcMvFieldNeighbours[(iCount<<1)] && pcMvFieldNeighbours[(iCnloop<<1)+1]==pcMvFieldNeighbours[(iCount<<1)+1])
3380      {
3381        bRemoveSpa                      = true;
3382        abCandIsInter        [ iCount ] = false;
3383        //reset to the default value for MC
3384        puhInterDirNeighbours[iCount]   = 0;
3385        pcMvFieldNeighbours[iCount<<1].setMvField( cZeroMv, NOT_VALID );
3386        pcMvFieldNeighbours[(iCount<<1)+1].setMvField( cZeroMv, NOT_VALID );
3387        break;
3388      }     
3389    }
3390    if(!bRemoveSpa)
3391    {
3392#if H_3D_NBDV
3393      pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3394      pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3395#endif
3396      if ( mrgCandIdx == iCount )
3397        return;
3398      iCount ++;
3399
3400      // early termination
3401      if (iCount == getSlice()->getMaxNumMergeCand()) 
3402      {
3403        return;
3404      }
3405    }
3406  } 
3407#endif
3408
3409#if H_3D_VSP
3410  if ( xAddVspCand( H_3D_VSP_POSITION, mrgCandIdx, &cDisInfo, iCount, abCandIsInter, pcMvFieldNeighbours, puhInterDirNeighbours, vspFlag ) )
3411    return;
3412  // early termination
3413  if (iCount == getSlice()->getMaxNumMergeCand())
3414    return;
3415#endif
3416
3417  //left bottom
3418  UInt uiLeftBottomPartIdx = 0;
3419  TComDataCU* pcCULeftBottom = 0;
3420  pcCULeftBottom = this->getPUBelowLeft( uiLeftBottomPartIdx, uiPartIdxLB );
3421  Bool isAvailableA0 = pcCULeftBottom &&
3422  pcCULeftBottom->isDiffMER(xP-1, yP+nPSH, xP, yP) &&
3423  !pcCULeftBottom->isIntra( uiLeftBottomPartIdx ) ;
3424  if ( isAvailableA0 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCULeftBottom, uiLeftBottomPartIdx ) ) )
3425  {
3426    abCandIsInter[iCount] = true;
3427    // get Inter Dir
3428    puhInterDirNeighbours[iCount] = pcCULeftBottom->getInterDir( uiLeftBottomPartIdx );
3429    // get Mv from Left
3430    pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3431    if ( getSlice()->isInterB() )
3432    {
3433      pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3434    }
3435#if H_3D_NBDV
3436    pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3437    pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3438#endif
3439#if H_3D_VSP
3440    if (pcCULeftBottom->getVSPFlag(uiLeftBottomPartIdx) == 1)
3441      vspFlag[iCount] = 1;
3442#endif
3443    if ( mrgCandIdx == iCount )
3444    {
3445      return;
3446    }
3447    iCount ++;
3448  }
3449  // early termination
3450  if (iCount == getSlice()->getMaxNumMergeCand()) 
3451  {
3452    return;
3453  }
3454  // above left
3455  if( iCount < 4 )
3456  {
3457    UInt uiAboveLeftPartIdx = 0;
3458    TComDataCU* pcCUAboveLeft = 0;
3459    pcCUAboveLeft = getPUAboveLeft( uiAboveLeftPartIdx, uiAbsPartAddr );
3460    Bool isAvailableB2 = pcCUAboveLeft &&
3461    pcCUAboveLeft->isDiffMER(xP-1, yP-1, xP, yP) &&
3462    !pcCUAboveLeft->isIntra( uiAboveLeftPartIdx );
3463    if ( isAvailableB2 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) )
3464        && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) ) )
3465    {
3466      abCandIsInter[iCount] = true;
3467      // get Inter Dir
3468      puhInterDirNeighbours[iCount] = pcCUAboveLeft->getInterDir( uiAboveLeftPartIdx );
3469      // get Mv from Left
3470      pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3471      if ( getSlice()->isInterB() )
3472      {
3473        pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3474      }
3475#if H_3D_NBDV
3476      pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3477      pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3478#endif
3479#if H_3D_VSP
3480      if (pcCUAboveLeft->getVSPFlag(uiAboveLeftPartIdx) == 1)
3481        vspFlag[iCount] = 1;
3482#endif
3483      if ( mrgCandIdx == iCount )
3484      {
3485        return;
3486      }
3487      iCount ++;
3488    }
3489  }
3490  // early termination
3491  if (iCount == getSlice()->getMaxNumMergeCand()) 
3492  {
3493    return;
3494  }
3495  if ( getSlice()->getEnableTMVPFlag())
3496  {
3497    //>> MTK colocated-RightBottom
3498    UInt uiPartIdxRB;
3499
3500    deriveRightBottomIdx( uiPUIdx, uiPartIdxRB ); 
3501
3502    UInt uiAbsPartIdxTmp = g_auiZscanToRaster[uiPartIdxRB];
3503    UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
3504
3505    TComMv cColMv;
3506    Int iRefIdx;
3507    Int uiLCUIdx = -1;
3508
3509    if      ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
3510    {
3511    }
3512    else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxTmp] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
3513    {
3514    }
3515    else
3516    {
3517      if ( ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
3518        ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
3519      {
3520        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + uiNumPartInCUWidth + 1 ];
3521        uiLCUIdx = getAddr();
3522      }
3523      else if ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
3524      {
3525        uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdxTmp + uiNumPartInCUWidth + 1) % m_pcPic->getNumPartInCU() ];
3526      }
3527      else if ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
3528      {
3529        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + 1 ];
3530        uiLCUIdx = getAddr() + 1;
3531      }
3532      else //is the right bottom corner of LCU                       
3533      {
3534        uiAbsPartAddr = 0;
3535      }
3536    }
3537   
3538   
3539    iRefIdx = 0;
3540    Bool bExistMV = false;
3541    UInt uiPartIdxCenter;
3542    UInt uiCurLCUIdx = getAddr();
3543    Int dir = 0;
3544    UInt uiArrayAddr = iCount;
3545    xDeriveCenterIdx( uiPUIdx, uiPartIdxCenter );
3546    bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_0, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx );
3547    if( bExistMV == false )
3548    {
3549      bExistMV = xGetColMVP( REF_PIC_LIST_0, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
3550    }
3551    if( bExistMV )
3552    {
3553      dir |= 1;
3554      pcMvFieldNeighbours[ 2 * uiArrayAddr ].setMvField( cColMv, iRefIdx );
3555    }
3556
3557    if ( getSlice()->isInterB() )
3558    {
3559#if H_3D_TMVP
3560      iRefIdx = 0;
3561#endif
3562      bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_1, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx);
3563      if( bExistMV == false )
3564      {
3565        bExistMV = xGetColMVP( REF_PIC_LIST_1, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
3566      }
3567      if( bExistMV )
3568      {
3569        dir |= 2;
3570        pcMvFieldNeighbours[ 2 * uiArrayAddr + 1 ].setMvField( cColMv, iRefIdx );
3571      }
3572    }
3573   
3574    if (dir != 0)
3575    {
3576      puhInterDirNeighbours[uiArrayAddr] = dir;
3577      abCandIsInter[uiArrayAddr] = true;
3578#if H_3D_NBDV
3579      pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3580      pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3581#endif
3582      if ( mrgCandIdx == iCount )
3583      {
3584        return;
3585      }
3586      iCount++;
3587    }
3588  }
3589  // early termination
3590  if (iCount == getSlice()->getMaxNumMergeCand()) 
3591  {
3592    return;
3593  }
3594  UInt uiArrayAddr = iCount;
3595  UInt uiCutoff = uiArrayAddr;
3596   
3597  if ( getSlice()->isInterB())
3598  {
3599#if H_3D_IV_MERGE
3600    UInt uiPriorityList0[20] = {0 , 1, 0, 2, 1, 2, 0, 3, 1, 3, 2, 3,    0, 4, 1, 4, 2, 4, 3, 4 };
3601    UInt uiPriorityList1[20] = {1 , 0, 2, 0, 2, 1, 3, 0, 3, 1, 3, 2,    4, 0, 4, 1, 4, 2, 4, 3 };
3602#else
3603    UInt uiPriorityList0[12] = {0 , 1, 0, 2, 1, 2, 0, 3, 1, 3, 2, 3};
3604    UInt uiPriorityList1[12] = {1 , 0, 2, 0, 2, 1, 3, 0, 3, 1, 3, 2};
3605#endif
3606
3607    for (Int idx=0; idx<uiCutoff*(uiCutoff-1) && uiArrayAddr!= getSlice()->getMaxNumMergeCand(); idx++)
3608    {
3609      Int i = uiPriorityList0[idx]; Int j = uiPriorityList1[idx];
3610#if H_3D_VSP
3611      Bool bValid = true;
3612      if ( vspFlag[i] == 1 || vspFlag[j] == 1 )
3613        bValid = false;
3614      if( !m_pcSlice->getVPS()->getViewSynthesisPredFlag( m_pcSlice->getLayerIdInVps() ) )
3615        assert(bValid == true);
3616#endif
3617#if H_3D_VSP
3618      if (abCandIsInter[i] && abCandIsInter[j] && (puhInterDirNeighbours[i]&0x1) && (puhInterDirNeighbours[j]&0x2) && bValid)
3619#else
3620      if (abCandIsInter[i] && abCandIsInter[j]&& (puhInterDirNeighbours[i]&0x1)&&(puhInterDirNeighbours[j]&0x2))
3621#endif
3622      {
3623        abCandIsInter[uiArrayAddr] = true;
3624        puhInterDirNeighbours[uiArrayAddr] = 3;
3625
3626        // get Mv from cand[i] and cand[j]
3627        pcMvFieldNeighbours[uiArrayAddr << 1].setMvField(pcMvFieldNeighbours[i<<1].getMv(), pcMvFieldNeighbours[i<<1].getRefIdx());
3628        pcMvFieldNeighbours[( uiArrayAddr << 1 ) + 1].setMvField(pcMvFieldNeighbours[(j<<1)+1].getMv(), pcMvFieldNeighbours[(j<<1)+1].getRefIdx());
3629
3630        Int iRefPOCL0 = m_pcSlice->getRefPOC( REF_PIC_LIST_0, pcMvFieldNeighbours[(uiArrayAddr<<1)].getRefIdx() );
3631        Int iRefPOCL1 = m_pcSlice->getRefPOC( REF_PIC_LIST_1, pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getRefIdx() );
3632        if (iRefPOCL0 == iRefPOCL1 && pcMvFieldNeighbours[(uiArrayAddr<<1)].getMv() == pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getMv())
3633        {
3634          abCandIsInter[uiArrayAddr] = false;
3635        }
3636        else
3637        {
3638          uiArrayAddr++;
3639        }
3640      }
3641    }
3642  }
3643  // early termination
3644  if (uiArrayAddr == getSlice()->getMaxNumMergeCand()) 
3645  {
3646    return;
3647  }
3648  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);
3649  Int r = 0;
3650  Int refcnt = 0;
3651  while (uiArrayAddr < getSlice()->getMaxNumMergeCand())
3652  {
3653    abCandIsInter[uiArrayAddr] = true;
3654    puhInterDirNeighbours[uiArrayAddr] = 1;
3655    pcMvFieldNeighbours[uiArrayAddr << 1].setMvField( TComMv(0, 0), r);
3656
3657    if ( getSlice()->isInterB() )
3658    {
3659      puhInterDirNeighbours[uiArrayAddr] = 3;
3660      pcMvFieldNeighbours[(uiArrayAddr << 1) + 1].setMvField(TComMv(0, 0), r);
3661    }
3662    uiArrayAddr++;
3663    if ( refcnt == iNumRefIdx - 1 )
3664    {
3665      r = 0;
3666    }
3667    else
3668    {
3669      ++r;
3670      ++refcnt;
3671    }
3672  }
3673
3674  numValidMergeCand = uiArrayAddr;
3675}
3676
3677/** Check whether the current PU and a spatial neighboring PU are in a same ME region.
3678 * \param xN, xN   location of the upper-left corner pixel of a neighboring PU
3679 * \param xP, yP   location of the upper-left corner pixel of the current PU
3680 * \returns Bool
3681 */
3682Bool TComDataCU::isDiffMER(Int xN, Int yN, Int xP, Int yP)
3683{
3684
3685  UInt plevel = this->getSlice()->getPPS()->getLog2ParallelMergeLevelMinus2() + 2;
3686  if ((xN>>plevel)!= (xP>>plevel))
3687  {
3688    return true;
3689  }
3690  if ((yN>>plevel)!= (yP>>plevel))
3691  {
3692    return true;
3693  }
3694  return false;
3695}
3696/** calculate the location of upper-left corner pixel and size of the current PU.
3697 * \param partIdx  PU index within a CU
3698 * \param xP, yP   location of the upper-left corner pixel of the current PU
3699 * \param PSW, nPSH    size of the curren PU
3700 * \returns Void
3701 */
3702Void TComDataCU::getPartPosition( UInt partIdx, Int& xP, Int& yP, Int& nPSW, Int& nPSH)
3703{
3704  UInt col = m_uiCUPelX;
3705  UInt row = m_uiCUPelY;
3706
3707  switch ( m_pePartSize[0] )
3708  {
3709  case SIZE_2NxN:
3710    nPSW = getWidth(0);     
3711    nPSH = getHeight(0) >> 1; 
3712    xP   = col;
3713    yP   = (partIdx ==0)? row: row + nPSH;
3714    break;
3715  case SIZE_Nx2N:
3716    nPSW = getWidth(0) >> 1; 
3717    nPSH = getHeight(0);     
3718    xP   = (partIdx ==0)? col: col + nPSW;
3719    yP   = row;
3720    break;
3721  case SIZE_NxN:
3722    nPSW = getWidth(0) >> 1; 
3723    nPSH = getHeight(0) >> 1; 
3724    xP   = col + (partIdx&0x1)*nPSW;
3725    yP   = row + (partIdx>>1)*nPSH;
3726    break;
3727  case SIZE_2NxnU:
3728    nPSW = getWidth(0);
3729    nPSH = ( partIdx == 0 ) ?  getHeight(0) >> 2 : ( getHeight(0) >> 2 ) + ( getHeight(0) >> 1 );
3730    xP   = col;
3731    yP   = (partIdx ==0)? row: row + getHeight(0) - nPSH;
3732
3733    break;
3734  case SIZE_2NxnD:
3735    nPSW = getWidth(0);
3736    nPSH = ( partIdx == 0 ) ?  ( getHeight(0) >> 2 ) + ( getHeight(0) >> 1 ) : getHeight(0) >> 2;
3737    xP   = col;
3738    yP   = (partIdx ==0)? row: row + getHeight(0) - nPSH;
3739    break;
3740  case SIZE_nLx2N:
3741    nPSW = ( partIdx == 0 ) ? getWidth(0) >> 2 : ( getWidth(0) >> 2 ) + ( getWidth(0) >> 1 );
3742    nPSH = getHeight(0);
3743    xP   = (partIdx ==0)? col: col + getWidth(0) - nPSW;
3744    yP   = row;
3745    break;
3746  case SIZE_nRx2N:
3747    nPSW = ( partIdx == 0 ) ? ( getWidth(0) >> 2 ) + ( getWidth(0) >> 1 ) : getWidth(0) >> 2;
3748    nPSH = getHeight(0);
3749    xP   = (partIdx ==0)? col: col + getWidth(0) - nPSW;
3750    yP   = row;
3751    break;
3752  default:
3753    assert ( m_pePartSize[0] == SIZE_2Nx2N );
3754    nPSW = getWidth(0);     
3755    nPSH = getHeight(0);     
3756    xP   = col ;
3757    yP   = row ;
3758
3759    break;
3760  }
3761}
3762
3763/** Constructs a list of candidates for AMVP
3764 * \param uiPartIdx
3765 * \param uiPartAddr
3766 * \param eRefPicList
3767 * \param iRefIdx
3768 * \param pInfo
3769 */
3770Void TComDataCU::fillMvpCand ( UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, Int iRefIdx, AMVPInfo* pInfo )
3771{
3772  TComMv cMvPred;
3773  Bool bAddedSmvp = false;
3774
3775  pInfo->iN = 0; 
3776  if (iRefIdx < 0)
3777  {
3778    return;
3779  }
3780 
3781  //-- Get Spatial MV
3782  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB;
3783  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
3784  Bool bAdded = false;
3785 
3786  deriveLeftRightTopIdx( uiPartIdx, uiPartIdxLT, uiPartIdxRT );
3787  deriveLeftBottomIdx( uiPartIdx, uiPartIdxLB );
3788 
3789  TComDataCU* tmpCU = NULL;
3790  UInt idx;
3791  tmpCU = getPUBelowLeft(idx, uiPartIdxLB);
3792  bAddedSmvp = (tmpCU != NULL) && (tmpCU->getPredictionMode(idx) != MODE_INTRA);
3793
3794  if (!bAddedSmvp)
3795  {
3796    tmpCU = getPULeft(idx, uiPartIdxLB);
3797    bAddedSmvp = (tmpCU != NULL) && (tmpCU->getPredictionMode(idx) != MODE_INTRA);
3798  }
3799
3800  // Left predictor search
3801  bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_BELOW_LEFT);
3802  if (!bAdded) 
3803  {
3804    bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_LEFT );
3805  }
3806 
3807  if(!bAdded)
3808  {
3809    bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_BELOW_LEFT);
3810    if (!bAdded) 
3811    {
3812      xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_LEFT );
3813    }
3814  }
3815  // Above predictor search
3816  bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE_RIGHT);
3817
3818  if (!bAdded) 
3819  {
3820    bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE);
3821  }
3822
3823  if(!bAdded)
3824  {
3825    xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLT, MD_ABOVE_LEFT);
3826  }
3827  bAdded = bAddedSmvp;
3828  if (pInfo->iN==2) bAdded = true;
3829
3830  if(!bAdded)
3831  {
3832    bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE_RIGHT);
3833    if (!bAdded) 
3834    {
3835      bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE);
3836    }
3837
3838    if(!bAdded)
3839    {
3840      xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLT, MD_ABOVE_LEFT);
3841    }
3842  }
3843 
3844  if ( pInfo->iN == 2 )
3845  {
3846    if ( pInfo->m_acMvCand[ 0 ] == pInfo->m_acMvCand[ 1 ] )
3847    {
3848      pInfo->iN = 1;
3849    }
3850  }
3851
3852  if ( getSlice()->getEnableTMVPFlag() )
3853  {
3854    // Get Temporal Motion Predictor
3855    Int iRefIdx_Col = iRefIdx;
3856    TComMv cColMv;
3857    UInt uiPartIdxRB;
3858    UInt uiAbsPartIdx; 
3859    UInt uiAbsPartAddr;
3860
3861    deriveRightBottomIdx( uiPartIdx, uiPartIdxRB );
3862    uiAbsPartAddr = m_uiAbsIdxInLCU + uiPartAddr;
3863
3864    //----  co-located RightBottom Temporal Predictor (H) ---//
3865    uiAbsPartIdx = g_auiZscanToRaster[uiPartIdxRB];
3866    Int uiLCUIdx = -1;
3867    if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdx] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
3868    {
3869    }
3870    else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdx] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
3871    {
3872    }
3873    else
3874    {
3875      if ( ( uiAbsPartIdx % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
3876        ( uiAbsPartIdx / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
3877      {
3878        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdx + uiNumPartInCUWidth + 1 ];
3879        uiLCUIdx = getAddr();
3880      }
3881      else if ( uiAbsPartIdx % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
3882      {
3883        uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdx + uiNumPartInCUWidth + 1) % m_pcPic->getNumPartInCU() ];
3884      }
3885      else if ( uiAbsPartIdx / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
3886      {
3887        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdx + 1 ];
3888        uiLCUIdx = getAddr() + 1;
3889      }
3890      else //is the right bottom corner of LCU                       
3891      {
3892        uiAbsPartAddr = 0;
3893      }
3894    }
3895    if ( uiLCUIdx >= 0 && xGetColMVP( eRefPicList, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx_Col
3896#if H_3D_TMVP
3897         , 0
3898#endif
3899    ) )
3900    {
3901      pInfo->m_acMvCand[pInfo->iN++] = cColMv;
3902    }
3903    else 
3904    {
3905      UInt uiPartIdxCenter;
3906      UInt uiCurLCUIdx = getAddr();
3907      xDeriveCenterIdx( uiPartIdx, uiPartIdxCenter );
3908      if (xGetColMVP( eRefPicList, uiCurLCUIdx, uiPartIdxCenter,  cColMv, iRefIdx_Col
3909#if H_3D_TMVP
3910         , 0
3911#endif
3912      ))
3913      {
3914        pInfo->m_acMvCand[pInfo->iN++] = cColMv;
3915      }
3916    }
3917    //----  co-located RightBottom Temporal Predictor  ---//
3918  }
3919
3920  if (pInfo->iN > AMVP_MAX_NUM_CANDS)
3921  {
3922    pInfo->iN = AMVP_MAX_NUM_CANDS;
3923  }
3924  while (pInfo->iN < AMVP_MAX_NUM_CANDS)
3925  {
3926      pInfo->m_acMvCand[pInfo->iN].set(0,0);
3927      pInfo->iN++;
3928  }
3929  return ;
3930}
3931
3932Bool TComDataCU::isBipredRestriction(UInt puIdx)
3933{
3934  Int width = 0;
3935  Int height = 0;
3936  UInt partAddr;
3937
3938  getPartIndexAndSize( puIdx, partAddr, width, height );
3939  if ( getWidth(0) == 8 && (width < 8 || height < 8) )
3940  {
3941    return true;
3942  }
3943  return false;
3944}
3945
3946Void TComDataCU::clipMv    (TComMv&  rcMv)
3947{
3948  Int  iMvShift = 2;
3949#if H_3D_IC
3950  if( getSlice()->getIsDepth() )
3951    iMvShift = 0;
3952#endif
3953  Int iOffset = 8;
3954  Int iHorMax = ( m_pcSlice->getSPS()->getPicWidthInLumaSamples() + iOffset - m_uiCUPelX - 1 ) << iMvShift;
3955  Int iHorMin = (       -(Int)g_uiMaxCUWidth - iOffset - (Int)m_uiCUPelX + 1 ) << iMvShift;
3956 
3957  Int iVerMax = ( m_pcSlice->getSPS()->getPicHeightInLumaSamples() + iOffset - m_uiCUPelY - 1 ) << iMvShift;
3958  Int iVerMin = (       -(Int)g_uiMaxCUHeight - iOffset - (Int)m_uiCUPelY + 1 ) << iMvShift;
3959 
3960  rcMv.setHor( min (iHorMax, max (iHorMin, rcMv.getHor())) );
3961  rcMv.setVer( min (iVerMax, max (iVerMin, rcMv.getVer())) );
3962}
3963
3964UInt TComDataCU::getIntraSizeIdx(UInt uiAbsPartIdx)
3965{
3966  UInt uiShift = ( m_pePartSize[uiAbsPartIdx]==SIZE_NxN ? 1 : 0 );
3967 
3968  UChar uiWidth = m_puhWidth[uiAbsPartIdx]>>uiShift;
3969  UInt  uiCnt = 0;
3970  while( uiWidth )
3971  {
3972    uiCnt++;
3973    uiWidth>>=1;
3974  }
3975  uiCnt-=2;
3976  return uiCnt > 6 ? 6 : uiCnt;
3977}
3978
3979Void TComDataCU::clearCbf( UInt uiIdx, TextType eType, UInt uiNumParts )
3980{
3981  ::memset( &m_puhCbf[g_aucConvertTxtTypeToIdx[eType]][uiIdx], 0, sizeof(UChar)*uiNumParts);
3982}
3983
3984/** Set a I_PCM flag for all sub-partitions of a partition.
3985 * \param bIpcmFlag I_PCM flag
3986 * \param uiAbsPartIdx patition index
3987 * \param uiDepth CU depth
3988 * \returns Void
3989 */
3990Void TComDataCU::setIPCMFlagSubParts  (Bool bIpcmFlag, UInt uiAbsPartIdx, UInt uiDepth)
3991{
3992  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
3993
3994  memset(m_pbIPCMFlag + uiAbsPartIdx, bIpcmFlag, sizeof(Bool)*uiCurrPartNumb );
3995}
3996
3997/** Test whether the current block is skipped
3998 * \param uiPartIdx Block index
3999 * \returns Flag indicating whether the block is skipped
4000 */
4001Bool TComDataCU::isSkipped( UInt uiPartIdx )
4002{
4003  return ( getSkipFlag( uiPartIdx ) );
4004}
4005
4006// ====================================================================================================================
4007// Protected member functions
4008// ====================================================================================================================
4009
4010Bool TComDataCU::xAddMVPCand( AMVPInfo* pInfo, RefPicList eRefPicList, Int iRefIdx, UInt uiPartUnitIdx, MVP_DIR eDir )
4011{
4012  TComDataCU* pcTmpCU = NULL;
4013  UInt uiIdx;
4014  switch( eDir )
4015  {
4016    case MD_LEFT:
4017    {
4018      pcTmpCU = getPULeft(uiIdx, uiPartUnitIdx);
4019      break;
4020    }
4021    case MD_ABOVE:
4022    {
4023      pcTmpCU = getPUAbove(uiIdx, uiPartUnitIdx );
4024      break;
4025    }
4026    case MD_ABOVE_RIGHT:
4027    {
4028      pcTmpCU = getPUAboveRight(uiIdx, uiPartUnitIdx);
4029      break;
4030    }
4031    case MD_BELOW_LEFT:
4032    {
4033      pcTmpCU = getPUBelowLeft(uiIdx, uiPartUnitIdx);
4034      break;
4035    }
4036    case MD_ABOVE_LEFT:
4037    {
4038      pcTmpCU = getPUAboveLeft(uiIdx, uiPartUnitIdx);
4039      break;
4040    }
4041    default:
4042    {
4043      break;
4044    }
4045  }
4046
4047  if ( pcTmpCU == NULL )
4048  {
4049    return false;
4050  }
4051 
4052  if ( pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) >= 0 && m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getPOC() == pcTmpCU->getSlice()->getRefPOC( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) ))
4053  {
4054    TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
4055   
4056    pInfo->m_acMvCand[ pInfo->iN++] = cMvPred;
4057    return true;
4058  }
4059
4060  RefPicList eRefPicList2nd = REF_PIC_LIST_0;
4061  if(       eRefPicList == REF_PIC_LIST_0 )
4062  {
4063    eRefPicList2nd = REF_PIC_LIST_1;
4064  }
4065  else if ( eRefPicList == REF_PIC_LIST_1)
4066  {
4067    eRefPicList2nd = REF_PIC_LIST_0;
4068  }
4069
4070
4071  Int iCurrRefPOC = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getPOC();
4072  Int iNeibRefPOC;
4073
4074
4075  if( pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) >= 0 )
4076  {
4077    iNeibRefPOC = pcTmpCU->getSlice()->getRefPOC( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) );
4078    if( iNeibRefPOC == iCurrRefPOC ) // Same Reference Frame But Diff List//
4079    {
4080      TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList2nd)->getMv(uiIdx);
4081      pInfo->m_acMvCand[ pInfo->iN++] = cMvPred;
4082      return true;
4083    }
4084  }
4085  return false;
4086}
4087
4088/**
4089 * \param pInfo
4090 * \param eRefPicList
4091 * \param iRefIdx
4092 * \param uiPartUnitIdx
4093 * \param eDir
4094 * \returns Bool
4095 */
4096Bool TComDataCU::xAddMVPCandOrder( AMVPInfo* pInfo, RefPicList eRefPicList, Int iRefIdx, UInt uiPartUnitIdx, MVP_DIR eDir )
4097{
4098  TComDataCU* pcTmpCU = NULL;
4099  UInt uiIdx;
4100  switch( eDir )
4101  {
4102  case MD_LEFT:
4103    {
4104      pcTmpCU = getPULeft(uiIdx, uiPartUnitIdx);
4105      break;
4106    }
4107  case MD_ABOVE:
4108    {
4109      pcTmpCU = getPUAbove(uiIdx, uiPartUnitIdx);
4110      break;
4111    }
4112  case MD_ABOVE_RIGHT:
4113    {
4114      pcTmpCU = getPUAboveRight(uiIdx, uiPartUnitIdx);
4115      break;
4116    }
4117  case MD_BELOW_LEFT:
4118    {
4119      pcTmpCU = getPUBelowLeft(uiIdx, uiPartUnitIdx);
4120      break;
4121    }
4122  case MD_ABOVE_LEFT:
4123    {
4124      pcTmpCU = getPUAboveLeft(uiIdx, uiPartUnitIdx);
4125      break;
4126    }
4127  default:
4128    {
4129      break;
4130    }
4131  }
4132
4133  if ( pcTmpCU == NULL ) 
4134  {
4135    return false;
4136  }
4137 
4138  RefPicList eRefPicList2nd = REF_PIC_LIST_0;
4139  if(       eRefPicList == REF_PIC_LIST_0 )
4140  {
4141    eRefPicList2nd = REF_PIC_LIST_1;
4142  }
4143  else if ( eRefPicList == REF_PIC_LIST_1)
4144  {
4145    eRefPicList2nd = REF_PIC_LIST_0;
4146  }
4147
4148  Int iCurrPOC = m_pcSlice->getPOC();
4149  Int iCurrRefPOC = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getPOC();
4150  Int iNeibPOC = iCurrPOC;
4151  Int iNeibRefPOC;
4152
4153  Bool bIsCurrRefLongTerm = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getIsLongTerm();
4154  Bool bIsNeibRefLongTerm = false;
4155  //---------------  V1 (END) ------------------//
4156  if( pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) >= 0)
4157  {
4158    iNeibRefPOC = pcTmpCU->getSlice()->getRefPOC( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) );
4159    TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
4160    TComMv rcMv;
4161
4162    bIsNeibRefLongTerm = pcTmpCU->getSlice()->getRefPic( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) )->getIsLongTerm();
4163    if ( bIsCurrRefLongTerm == bIsNeibRefLongTerm ) 
4164    {
4165    if ( bIsCurrRefLongTerm || bIsNeibRefLongTerm )
4166    {
4167      rcMv = cMvPred;
4168    }
4169    else
4170    {
4171      Int iScale = xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
4172      if ( iScale == 4096 )
4173      {
4174        rcMv = cMvPred;
4175      }
4176      else
4177      {
4178        rcMv = cMvPred.scaleMv( iScale );
4179      }
4180    }
4181    pInfo->m_acMvCand[ pInfo->iN++] = rcMv;
4182    return true;
4183    }
4184  }
4185  //---------------------- V2(END) --------------------//
4186  if( pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) >= 0)
4187  {
4188    iNeibRefPOC = pcTmpCU->getSlice()->getRefPOC( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) );
4189    TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList2nd)->getMv(uiIdx);
4190    TComMv rcMv;
4191
4192    bIsNeibRefLongTerm = pcTmpCU->getSlice()->getRefPic( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) )->getIsLongTerm();
4193    if ( bIsCurrRefLongTerm == bIsNeibRefLongTerm ) 
4194    {
4195    if ( bIsCurrRefLongTerm || bIsNeibRefLongTerm )
4196    {
4197      rcMv = cMvPred;
4198    }
4199    else
4200    {
4201      Int iScale = xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
4202      if ( iScale == 4096 )
4203      {
4204        rcMv = cMvPred;
4205      }
4206      else
4207      {
4208        rcMv = cMvPred.scaleMv( iScale );
4209      }
4210    }
4211    pInfo->m_acMvCand[ pInfo->iN++] = rcMv;
4212    return true;
4213    }
4214  }
4215  //---------------------- V3(END) --------------------//
4216  return false;
4217}
4218
4219/**
4220 * \param eRefPicList
4221 * \param uiCUAddr
4222 * \param uiPartUnitIdx
4223 * \param riRefIdx
4224 * \returns Bool
4225 */
4226Bool TComDataCU::xGetColMVP( RefPicList eRefPicList, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv, Int& riRefIdx
4227#if H_3D_TMVP
4228  , Bool bMRG
4229#endif
4230  )
4231{
4232  UInt uiAbsPartAddr = uiPartUnitIdx;
4233
4234  RefPicList  eColRefPicList;
4235  Int iColPOC, iColRefPOC, iCurrPOC, iCurrRefPOC, iScale;
4236  TComMv cColMv;
4237
4238  // use coldir.
4239#if H_MV
4240  TComPic *pColPic; 
4241  if (getSlice()->getAltCollocatedIndicationFlag() )
4242  {
4243    pColPic = getSlice()->getPicFromRefPicSetInterLayer( getSlice()->getActiveMotionPredRefLayerId( getSlice()->getCollocatedRefLayerIdx() )); 
4244  }
4245  else
4246  {
4247    pColPic = getSlice()->getRefPic( RefPicList(getSlice()->isInterB() ? 1-getSlice()->getColFromL0Flag() : 0), getSlice()->getColRefIdx()); 
4248  } 
4249#else
4250  TComPic *pColPic = getSlice()->getRefPic( RefPicList(getSlice()->isInterB() ? 1-getSlice()->getColFromL0Flag() : 0), getSlice()->getColRefIdx());
4251#endif
4252  TComDataCU *pColCU = pColPic->getCU( uiCUAddr );
4253  if(pColCU->getPic()==0||pColCU->getPartitionSize(uiPartUnitIdx)==SIZE_NONE)
4254  {
4255    return false;
4256  }
4257  iCurrPOC = m_pcSlice->getPOC();   
4258  iColPOC = pColCU->getSlice()->getPOC(); 
4259
4260  if (pColCU->isIntra(uiAbsPartAddr))
4261  {
4262    return false;
4263  }
4264  eColRefPicList = getSlice()->getCheckLDC() ? eRefPicList : RefPicList(getSlice()->getColFromL0Flag());
4265
4266  Int iColRefIdx = pColCU->getCUMvField(RefPicList(eColRefPicList))->getRefIdx(uiAbsPartAddr);
4267
4268  if (iColRefIdx < 0 )
4269  {
4270    eColRefPicList = RefPicList(1 - eColRefPicList);
4271    iColRefIdx = pColCU->getCUMvField(RefPicList(eColRefPicList))->getRefIdx(uiAbsPartAddr);
4272
4273    if (iColRefIdx < 0 )
4274    {
4275      return false;
4276    }
4277  }
4278
4279  // Scale the vector.
4280  iColRefPOC = pColCU->getSlice()->getRefPOC(eColRefPicList, iColRefIdx);
4281  cColMv = pColCU->getCUMvField(eColRefPicList)->getMv(uiAbsPartAddr);
4282
4283  iCurrRefPOC = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getPOC();
4284  Bool bIsCurrRefLongTerm = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getIsLongTerm();
4285  Bool bIsColRefLongTerm = pColCU->getSlice()->getIsUsedAsLongTerm(eColRefPicList, iColRefIdx);
4286
4287  if ( bIsCurrRefLongTerm != bIsColRefLongTerm ) 
4288  {
4289#if H_3D_TMVP
4290    Int iAlterRefIdx  = m_pcSlice->getAlterRefIdx(eRefPicList);
4291    if(bMRG && iAlterRefIdx > 0)
4292    {
4293      riRefIdx = iAlterRefIdx;
4294      bIsCurrRefLongTerm = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getIsLongTerm();
4295      iCurrRefPOC = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getPOC();
4296      assert(bIsCurrRefLongTerm == bIsColRefLongTerm);
4297    }
4298    else
4299    {
4300#endif
4301      return false;
4302#if H_3D_TMVP
4303    }
4304#endif
4305  }
4306
4307  if ( bIsCurrRefLongTerm || bIsColRefLongTerm )
4308  {
4309#if H_3D_TMVP
4310    Int iCurrViewId    = m_pcSlice->getViewIndex (); 
4311    Int iCurrRefViewId = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getViewIndex (); 
4312    Int iColViewId     = pColCU->getSlice()->getViewIndex(); 
4313    Int iColRefViewId  = pColCU->getSlice()->getRefPic( eColRefPicList, pColCU->getCUMvField(eColRefPicList)->getRefIdx(uiAbsPartAddr))->getViewIndex(); 
4314    iScale = xGetDistScaleFactor( iCurrViewId, iCurrRefViewId, iColViewId, iColRefViewId );
4315    if ( iScale != 4096 && m_pcSlice->getVPS()->getIvMvScalingFlag() ) 
4316    {
4317      rcMv = cColMv.scaleMv( iScale );
4318    }
4319    else
4320    {
4321#endif
4322       rcMv = cColMv;
4323#if H_3D_TMVP
4324    }
4325#endif
4326  }
4327  else
4328  {
4329    iScale = xGetDistScaleFactor(iCurrPOC, iCurrRefPOC, iColPOC, iColRefPOC);
4330    if ( iScale == 4096 )
4331    {
4332      rcMv = cColMv;
4333    }
4334    else
4335    {
4336      rcMv = cColMv.scaleMv( iScale );
4337    }
4338  }
4339  return true;
4340}
4341
4342UInt TComDataCU::xGetMvdBits(TComMv cMvd)
4343{
4344  return ( xGetComponentBits(cMvd.getHor()) + xGetComponentBits(cMvd.getVer()) );
4345}
4346
4347UInt TComDataCU::xGetComponentBits(Int iVal)
4348{
4349  UInt uiLength = 1;
4350  UInt uiTemp   = ( iVal <= 0) ? (-iVal<<1)+1: (iVal<<1);
4351 
4352  assert ( uiTemp );
4353 
4354  while ( 1 != uiTemp )
4355  {
4356    uiTemp >>= 1;
4357    uiLength += 2;
4358  }
4359 
4360  return uiLength;
4361}
4362
4363
4364Int TComDataCU::xGetDistScaleFactor(Int iCurrPOC, Int iCurrRefPOC, Int iColPOC, Int iColRefPOC)
4365{
4366  Int iDiffPocD = iColPOC - iColRefPOC;
4367  Int iDiffPocB = iCurrPOC - iCurrRefPOC;
4368 
4369  if( iDiffPocD == iDiffPocB )
4370  {
4371    return 4096;
4372  }
4373  else
4374  {
4375    Int iTDB      = Clip3( -128, 127, iDiffPocB );
4376    Int iTDD      = Clip3( -128, 127, iDiffPocD );
4377    Int iX        = (0x4000 + abs(iTDD/2)) / iTDD;
4378    Int iScale    = Clip3( -4096, 4095, (iTDB * iX + 32) >> 6 );
4379    return iScale;
4380  }
4381}
4382
4383/**
4384 * \param eCUMode
4385 * \param uiPartIdx
4386 * \param ruiPartIdxCenter
4387 * \returns Void
4388 */
4389Void TComDataCU::xDeriveCenterIdx( UInt uiPartIdx, UInt& ruiPartIdxCenter )
4390{
4391  UInt uiPartAddr;
4392  Int  iPartWidth;
4393  Int  iPartHeight;
4394  getPartIndexAndSize( uiPartIdx, uiPartAddr, iPartWidth, iPartHeight);
4395 
4396  ruiPartIdxCenter = m_uiAbsIdxInLCU+uiPartAddr; // partition origin.
4397  ruiPartIdxCenter = g_auiRasterToZscan[ g_auiZscanToRaster[ ruiPartIdxCenter ]
4398                                        + ( iPartHeight/m_pcPic->getMinCUHeight()  )/2*m_pcPic->getNumPartInWidth()
4399                                        + ( iPartWidth/m_pcPic->getMinCUWidth()  )/2];
4400}
4401#if MTK_SONY_PROGRESSIVE_MV_COMPRESSION_E0170
4402Void TComDataCU::compressMV(int scale)
4403#else
4404Void TComDataCU::compressMV()
4405#endif
4406{
4407#if MTK_SONY_PROGRESSIVE_MV_COMPRESSION_E0170
4408  Int scaleFactor = (4 / scale ) * AMVP_DECIMATION_FACTOR / m_unitSize;
4409#else
4410  Int scaleFactor = 4 * AMVP_DECIMATION_FACTOR / m_unitSize;
4411#endif
4412  if (scaleFactor > 0)
4413  {
4414    m_acCUMvField[0].compress(m_pePredMode, scaleFactor);
4415    m_acCUMvField[1].compress(m_pePredMode, scaleFactor);   
4416  }
4417}
4418
4419UInt TComDataCU::getCoefScanIdx(UInt uiAbsPartIdx, UInt uiWidth, Bool bIsLuma, Bool bIsIntra)
4420{
4421  UInt uiCTXIdx;
4422  UInt uiScanIdx;
4423  UInt uiDirMode;
4424
4425  if ( !bIsIntra ) 
4426  {
4427    uiScanIdx = SCAN_DIAG;
4428    return uiScanIdx;
4429  }
4430
4431  switch(uiWidth)
4432  {
4433    case  2: uiCTXIdx = 6; break;
4434    case  4: uiCTXIdx = 5; break;
4435    case  8: uiCTXIdx = 4; break;
4436    case 16: uiCTXIdx = 3; break;
4437    case 32: uiCTXIdx = 2; break;
4438    case 64: uiCTXIdx = 1; break;
4439    default: uiCTXIdx = 0; break;
4440  }
4441
4442  if ( bIsLuma )
4443  {
4444    uiDirMode = getLumaIntraDir(uiAbsPartIdx);
4445#if H_3D_DIM
4446    mapDepthModeToIntraDir( uiDirMode );
4447#endif
4448    uiScanIdx = SCAN_DIAG;
4449    if (uiCTXIdx >3 && uiCTXIdx < 6) //if multiple scans supported for transform size
4450    {
4451      uiScanIdx = abs((Int) uiDirMode - VER_IDX) < 5 ? SCAN_HOR : (abs((Int)uiDirMode - HOR_IDX) < 5 ? SCAN_VER : SCAN_DIAG);
4452    }
4453  }
4454  else
4455  {
4456    uiDirMode = getChromaIntraDir(uiAbsPartIdx);
4457    if( uiDirMode == DM_CHROMA_IDX )
4458    {
4459      // get number of partitions in current CU
4460      UInt depth = getDepth(uiAbsPartIdx);
4461      UInt numParts = getPic()->getNumPartInCU() >> (2 * depth);
4462     
4463      // get luma mode from upper-left corner of current CU
4464      uiDirMode = getLumaIntraDir((uiAbsPartIdx/numParts)*numParts);
4465#if H_3D_DIM
4466      mapDepthModeToIntraDir( uiDirMode );
4467#endif
4468    }
4469    uiScanIdx = SCAN_DIAG;
4470    if (uiCTXIdx >4 && uiCTXIdx < 7) //if multiple scans supported for transform size
4471    {
4472      uiScanIdx = abs((Int) uiDirMode - VER_IDX) < 5 ? SCAN_HOR : (abs((Int)uiDirMode - HOR_IDX) < 5 ? SCAN_VER : SCAN_DIAG);
4473    }
4474  }
4475
4476  return uiScanIdx;
4477}
4478
4479UInt TComDataCU::getSCUAddr()
4480{ 
4481  return getPic()->getPicSym()->getInverseCUOrderMap(m_uiCUAddr)*(1<<(m_pcSlice->getSPS()->getMaxCUDepth()<<1))+m_uiAbsIdxInLCU; 
4482}
4483
4484/** Set neighboring blocks availabilities for non-deblocked filtering
4485 * \param numLCUInPicWidth number of LCUs in picture width
4486 * \param numLCUInPicHeight number of LCUs in picture height
4487 * \param numSUInLCUWidth number of SUs in LCU width
4488 * \param numSUInLCUHeight number of SUs in LCU height
4489 * \param picWidth picture width
4490 * \param picHeight picture height
4491 * \param bIndependentSliceBoundaryEnabled true for independent slice boundary enabled
4492 * \param bTopTileBoundary true means that top boundary coincides tile boundary
4493 * \param bDownTileBoundary true means that bottom boundary coincides tile boundary
4494 * \param bLeftTileBoundary true means that left boundary coincides tile boundary
4495 * \param bRightTileBoundary true means that right boundary coincides tile boundary
4496 * \param bIndependentTileBoundaryEnabled true for independent tile boundary enabled
4497 */
4498Void TComDataCU::setNDBFilterBlockBorderAvailability(UInt numLCUInPicWidth, UInt /*numLCUInPicHeight*/, UInt numSUInLCUWidth, UInt numSUInLCUHeight, UInt picWidth, UInt picHeight
4499                                                    ,std::vector<Bool>& LFCrossSliceBoundary
4500                                                    ,Bool bTopTileBoundary, Bool bDownTileBoundary, Bool bLeftTileBoundary, Bool bRightTileBoundary
4501                                                    ,Bool bIndependentTileBoundaryEnabled)
4502{
4503  UInt numSUInLCU = numSUInLCUWidth*numSUInLCUHeight;
4504  Int* pSliceIDMapLCU = m_piSliceSUMap;
4505  Bool onlyOneSliceInPic = ((Int)LFCrossSliceBoundary.size() == 1);
4506  UInt uiLPelX, uiTPelY;
4507  UInt width, height;
4508  Bool bPicRBoundary, bPicBBoundary, bPicTBoundary, bPicLBoundary;
4509  Bool bLCURBoundary= false, bLCUBBoundary= false, bLCUTBoundary= false, bLCULBoundary= false;
4510  Bool* pbAvailBorder;
4511  Bool* pbAvail;
4512  UInt rTLSU, rBRSU, widthSU, heightSU;
4513  UInt zRefSU;
4514  Int* pRefID;
4515  Int* pRefMapLCU;
4516  UInt rTRefSU= 0, rBRefSU= 0, rLRefSU= 0, rRRefSU= 0;
4517  Int* pRRefMapLCU= NULL;
4518  Int* pLRefMapLCU= NULL;
4519  Int* pTRefMapLCU= NULL;
4520  Int* pBRefMapLCU= NULL;
4521  Int  sliceID;
4522  UInt numSGU = (UInt)m_vNDFBlock.size();
4523
4524  for(Int i=0; i< numSGU; i++)
4525  {
4526    NDBFBlockInfo& rSGU = m_vNDFBlock[i];
4527
4528    sliceID = rSGU.sliceID;
4529    uiLPelX = rSGU.posX;
4530    uiTPelY = rSGU.posY;
4531    width   = rSGU.width;
4532    height  = rSGU.height;
4533    rTLSU     = g_auiZscanToRaster[ rSGU.startSU ];
4534    rBRSU     = g_auiZscanToRaster[ rSGU.endSU   ];
4535    widthSU   = rSGU.widthSU;
4536    heightSU  = rSGU.heightSU;
4537
4538    pbAvailBorder = rSGU.isBorderAvailable;
4539
4540    bPicTBoundary= (uiTPelY == 0                       )?(true):(false);
4541    bPicLBoundary= (uiLPelX == 0                       )?(true):(false);
4542    bPicRBoundary= (!(uiLPelX+ width < picWidth )  )?(true):(false);
4543    bPicBBoundary= (!(uiTPelY + height < picHeight))?(true):(false);
4544
4545    bLCULBoundary = (rTLSU % numSUInLCUWidth == 0)?(true):(false);
4546    bLCURBoundary = ( (rTLSU+ widthSU) % numSUInLCUWidth == 0)?(true):(false);
4547    bLCUTBoundary = ( (UInt)(rTLSU / numSUInLCUWidth)== 0)?(true):(false);
4548    bLCUBBoundary = ( (UInt)(rBRSU / numSUInLCUWidth) == (numSUInLCUHeight-1) )?(true):(false);
4549
4550    //       SGU_L
4551    pbAvail = &(pbAvailBorder[SGU_L]);
4552    if(bPicLBoundary)
4553    {
4554      *pbAvail = false;
4555    }
4556    else if (onlyOneSliceInPic)
4557    {
4558      *pbAvail = true;
4559    }
4560    else
4561    {
4562      //      bLCULBoundary = (rTLSU % uiNumSUInLCUWidth == 0)?(true):(false);
4563      if(bLCULBoundary)
4564      {
4565        rLRefSU     = rTLSU + numSUInLCUWidth -1;
4566        zRefSU      = g_auiRasterToZscan[rLRefSU];
4567        pRefMapLCU = pLRefMapLCU= (pSliceIDMapLCU - numSUInLCU);
4568      }
4569      else
4570      {
4571        zRefSU   = g_auiRasterToZscan[rTLSU - 1];
4572        pRefMapLCU  = pSliceIDMapLCU;
4573      }
4574      pRefID = pRefMapLCU + zRefSU;
4575      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
4576    }
4577
4578    //       SGU_R
4579    pbAvail = &(pbAvailBorder[SGU_R]);
4580    if(bPicRBoundary)
4581    {
4582      *pbAvail = false;
4583    }
4584    else if (onlyOneSliceInPic)
4585    {
4586      *pbAvail = true;
4587    }
4588    else
4589    {
4590      //       bLCURBoundary = ( (rTLSU+ uiWidthSU) % uiNumSUInLCUWidth == 0)?(true):(false);
4591      if(bLCURBoundary)
4592      {
4593        rRRefSU      = rTLSU + widthSU - numSUInLCUWidth;
4594        zRefSU       = g_auiRasterToZscan[rRRefSU];
4595        pRefMapLCU  = pRRefMapLCU= (pSliceIDMapLCU + numSUInLCU);
4596      }
4597      else
4598      {
4599        zRefSU       = g_auiRasterToZscan[rTLSU + widthSU];
4600        pRefMapLCU  = pSliceIDMapLCU;
4601      }
4602      pRefID = pRefMapLCU + zRefSU;
4603      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
4604    }
4605
4606    //       SGU_T
4607    pbAvail = &(pbAvailBorder[SGU_T]);
4608    if(bPicTBoundary)
4609    {
4610      *pbAvail = false;
4611    }
4612    else if (onlyOneSliceInPic)
4613    {
4614      *pbAvail = true;
4615    }
4616    else
4617    {
4618      //      bLCUTBoundary = ( (UInt)(rTLSU / uiNumSUInLCUWidth)== 0)?(true):(false);
4619      if(bLCUTBoundary)
4620      {
4621        rTRefSU      = numSUInLCU - (numSUInLCUWidth - rTLSU);
4622        zRefSU       = g_auiRasterToZscan[rTRefSU];
4623        pRefMapLCU  = pTRefMapLCU= (pSliceIDMapLCU - (numLCUInPicWidth*numSUInLCU));
4624      }
4625      else
4626      {
4627        zRefSU       = g_auiRasterToZscan[rTLSU - numSUInLCUWidth];
4628        pRefMapLCU  = pSliceIDMapLCU;
4629      }
4630      pRefID = pRefMapLCU + zRefSU;
4631      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
4632    }
4633
4634    //       SGU_B
4635    pbAvail = &(pbAvailBorder[SGU_B]);
4636    if(bPicBBoundary)
4637    {
4638      *pbAvail = false;
4639    }
4640    else if (onlyOneSliceInPic)
4641    {
4642      *pbAvail = true;
4643    }
4644    else
4645    {
4646      //      bLCUBBoundary = ( (UInt)(rBRSU / uiNumSUInLCUWidth) == (uiNumSUInLCUHeight-1) )?(true):(false);
4647      if(bLCUBBoundary)
4648      {
4649        rBRefSU      = rTLSU % numSUInLCUWidth;
4650        zRefSU       = g_auiRasterToZscan[rBRefSU];
4651        pRefMapLCU  = pBRefMapLCU= (pSliceIDMapLCU + (numLCUInPicWidth*numSUInLCU));
4652      }
4653      else
4654      {
4655        zRefSU       = g_auiRasterToZscan[rTLSU + (heightSU*numSUInLCUWidth)];
4656        pRefMapLCU  = pSliceIDMapLCU;
4657      }
4658      pRefID = pRefMapLCU + zRefSU;
4659      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
4660    }
4661
4662    //       SGU_TL
4663    pbAvail = &(pbAvailBorder[SGU_TL]);
4664    if(bPicTBoundary || bPicLBoundary)
4665    {
4666      *pbAvail = false;
4667    }
4668    else if (onlyOneSliceInPic)
4669    {
4670      *pbAvail = true;
4671    }
4672    else
4673    {
4674      if(bLCUTBoundary && bLCULBoundary)
4675      {
4676        zRefSU       = numSUInLCU -1;
4677        pRefMapLCU  = pSliceIDMapLCU - ( (numLCUInPicWidth+1)*numSUInLCU);
4678      }
4679      else if(bLCUTBoundary)
4680      {
4681        zRefSU       = g_auiRasterToZscan[ rTRefSU- 1];
4682        pRefMapLCU  = pTRefMapLCU;
4683      }
4684      else if(bLCULBoundary)
4685      {
4686        zRefSU       = g_auiRasterToZscan[ rLRefSU- numSUInLCUWidth ];
4687        pRefMapLCU  = pLRefMapLCU;
4688      }
4689      else //inside LCU
4690      {
4691        zRefSU       = g_auiRasterToZscan[ rTLSU - numSUInLCUWidth -1];
4692        pRefMapLCU  = pSliceIDMapLCU;
4693      }
4694      pRefID = pRefMapLCU + zRefSU;
4695      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
4696    }
4697
4698    //       SGU_TR
4699    pbAvail = &(pbAvailBorder[SGU_TR]);
4700    if(bPicTBoundary || bPicRBoundary)
4701    {
4702      *pbAvail = false;
4703    }
4704    else if (onlyOneSliceInPic)
4705    {
4706      *pbAvail = true;
4707    }
4708    else
4709    {
4710      if(bLCUTBoundary && bLCURBoundary)
4711      {
4712        zRefSU      = g_auiRasterToZscan[numSUInLCU - numSUInLCUWidth];
4713        pRefMapLCU  = pSliceIDMapLCU - ( (numLCUInPicWidth-1)*numSUInLCU);       
4714      }
4715      else if(bLCUTBoundary)
4716      {
4717        zRefSU       = g_auiRasterToZscan[ rTRefSU+ widthSU];
4718        pRefMapLCU  = pTRefMapLCU;
4719      }
4720      else if(bLCURBoundary)
4721      {
4722        zRefSU       = g_auiRasterToZscan[ rRRefSU- numSUInLCUWidth ];
4723        pRefMapLCU  = pRRefMapLCU;
4724      }
4725      else //inside LCU
4726      {
4727        zRefSU       = g_auiRasterToZscan[ rTLSU - numSUInLCUWidth +widthSU];
4728        pRefMapLCU  = pSliceIDMapLCU;
4729      }
4730      pRefID = pRefMapLCU + zRefSU;
4731      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
4732    }
4733
4734    //       SGU_BL
4735    pbAvail = &(pbAvailBorder[SGU_BL]);
4736    if(bPicBBoundary || bPicLBoundary)
4737    {
4738      *pbAvail = false;
4739    }
4740    else if (onlyOneSliceInPic)
4741    {
4742      *pbAvail = true;
4743    }
4744    else
4745    {
4746      if(bLCUBBoundary && bLCULBoundary)
4747      {
4748        zRefSU      = g_auiRasterToZscan[numSUInLCUWidth - 1];
4749        pRefMapLCU  = pSliceIDMapLCU + ( (numLCUInPicWidth-1)*numSUInLCU);       
4750      }
4751      else if(bLCUBBoundary)
4752      {
4753        zRefSU       = g_auiRasterToZscan[ rBRefSU - 1];
4754        pRefMapLCU  = pBRefMapLCU;
4755      }
4756      else if(bLCULBoundary)
4757      {
4758        zRefSU       = g_auiRasterToZscan[ rLRefSU+ heightSU*numSUInLCUWidth ];
4759        pRefMapLCU  = pLRefMapLCU;
4760      }
4761      else //inside LCU
4762      {
4763        zRefSU       = g_auiRasterToZscan[ rTLSU + heightSU*numSUInLCUWidth -1];
4764        pRefMapLCU  = pSliceIDMapLCU;
4765      }
4766      pRefID = pRefMapLCU + zRefSU;
4767      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
4768    }
4769
4770    //       SGU_BR
4771    pbAvail = &(pbAvailBorder[SGU_BR]);
4772    if(bPicBBoundary || bPicRBoundary)
4773    {
4774      *pbAvail = false;
4775    }
4776    else if (onlyOneSliceInPic)
4777    {
4778      *pbAvail = true;
4779    }
4780    else
4781    {
4782      if(bLCUBBoundary && bLCURBoundary)
4783      {
4784        zRefSU = 0;
4785        pRefMapLCU = pSliceIDMapLCU+ ( (numLCUInPicWidth+1)*numSUInLCU);
4786      }
4787      else if(bLCUBBoundary)
4788      {
4789        zRefSU      = g_auiRasterToZscan[ rBRefSU + widthSU];
4790        pRefMapLCU = pBRefMapLCU;
4791      }
4792      else if(bLCURBoundary)
4793      {
4794        zRefSU      = g_auiRasterToZscan[ rRRefSU + (heightSU*numSUInLCUWidth)];
4795        pRefMapLCU = pRRefMapLCU;
4796      }
4797      else //inside LCU
4798      {
4799        zRefSU      = g_auiRasterToZscan[ rTLSU + (heightSU*numSUInLCUWidth)+ widthSU];
4800        pRefMapLCU = pSliceIDMapLCU;
4801      }
4802      pRefID = pRefMapLCU + zRefSU;
4803      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
4804    }
4805
4806    if(bIndependentTileBoundaryEnabled)
4807    {
4808      //left LCU boundary
4809      if(!bPicLBoundary && bLCULBoundary)
4810      {
4811        if(bLeftTileBoundary)
4812        {
4813          pbAvailBorder[SGU_L] = pbAvailBorder[SGU_TL] = pbAvailBorder[SGU_BL] = false;
4814        }
4815      }
4816      //right LCU boundary
4817      if(!bPicRBoundary && bLCURBoundary)
4818      {
4819        if(bRightTileBoundary)
4820        {
4821          pbAvailBorder[SGU_R] = pbAvailBorder[SGU_TR] = pbAvailBorder[SGU_BR] = false;
4822        }
4823      }
4824      //top LCU boundary
4825      if(!bPicTBoundary && bLCUTBoundary)
4826      {
4827        if(bTopTileBoundary)
4828        {
4829          pbAvailBorder[SGU_T] = pbAvailBorder[SGU_TL] = pbAvailBorder[SGU_TR] = false;
4830        }
4831      }
4832      //down LCU boundary
4833      if(!bPicBBoundary && bLCUBBoundary)
4834      {
4835        if(bDownTileBoundary)
4836        {
4837          pbAvailBorder[SGU_B] = pbAvailBorder[SGU_BL] = pbAvailBorder[SGU_BR] = false;
4838        }
4839      }
4840    }
4841    rSGU.allBordersAvailable = true;
4842    for(Int b=0; b< NUM_SGU_BORDER; b++)
4843    {
4844      if(pbAvailBorder[b] == false)
4845      {
4846        rSGU.allBordersAvailable = false;
4847        break;
4848      }
4849    }
4850  }
4851}
4852
4853#if H_3D
4854Void TComDataCU::getPosInPic( UInt uiAbsPartIndex, Int& riPosX, Int& riPosY )
4855{
4856  riPosX = g_auiRasterToPelX[g_auiZscanToRaster[uiAbsPartIndex]] + getCUPelX();
4857  riPosY = g_auiRasterToPelY[g_auiZscanToRaster[uiAbsPartIndex]] + getCUPelY(); 
4858}
4859#endif
4860#if H_3D_NBDV
4861//Notes from QC:
4862//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
4863//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
4864//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
4865Bool TComDataCU::getDisMvpCandNBDV( DisInfo* pDInfo
4866#if H_3D_NBDV_REF
4867, Bool bDepthRefine
4868#endif
4869)
4870{
4871  //// ******* Init variables ******* /////
4872  // Init disparity struct for results
4873  pDInfo->bDV = false;   
4874  // Init struct for disparities from MCP neighboring blocks
4875  IDVInfo cIDVInfo;
4876  cIDVInfo.m_bFound = false; 
4877  UInt uiPartIdx = 0;
4878  UInt uiPartAddr = 0;
4879  for (UInt iCurDvMcpCand = 0; iCurDvMcpCand < IDV_CANDS; iCurDvMcpCand++)
4880  {
4881    for (UInt iList = 0; iList < 2; iList++)
4882    {
4883      cIDVInfo.m_acMvCand[iList][iCurDvMcpCand].setZero();
4884      cIDVInfo.m_aVIdxCan[iList][iCurDvMcpCand] = 0; 
4885      cIDVInfo.m_bAvailab[iList][iCurDvMcpCand] = false; 
4886    }
4887  }
4888#if H_3D_NBDV_REF
4889  if( !m_pcSlice->getVPS()->getDepthRefinementFlag( m_pcSlice->getLayerIdInVps() ) )
4890  {
4891    bDepthRefine = false;
4892  }
4893#endif
4894  // Get Positions 
4895  PartSize eCUMode    = getPartitionSize( uiPartAddr );   
4896  assert(eCUMode == SIZE_2Nx2N);
4897  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB; 
4898
4899  deriveLeftRightTopIdxGeneral(uiPartAddr, uiPartIdx, uiPartIdxLT, uiPartIdxRT );
4900  deriveLeftBottomIdxGeneral  (uiPartAddr, uiPartIdx, uiPartIdxLB );
4901
4902  //// ******* Get disparity from temporal neighboring blocks ******* /////
4903  if ( getSlice()->getEnableTMVPFlag() )
4904  {
4905    TComMv cColMv;
4906    Int iTargetViewIdx = 0;
4907    Int iTStartViewIdx = 0;   
4908
4909    ///*** Derive center position ***
4910    UInt uiPartIdxCenter;
4911    Int  uiLCUIdx   = getAddr();
4912    xDeriveCenterIdx(uiPartIdx, uiPartIdxCenter );
4913
4914    ///*** Derive bottom right neighbour position ***
4915    Int iLCUIdxRBNb  = -1;   
4916    Int iPartIdxRBNb = -1;
4917    xDeriveRightBottomNbIdx(iLCUIdxRBNb, iPartIdxRBNb );
4918
4919    ///*** Search temporal candidate pictures for disparity vector ***
4920    const Int iNumCandPics = getPic()->getNumDdvCandPics();
4921    for(Int curCandPic = 0; curCandPic < iNumCandPics; curCandPic++)
4922    {
4923      RefPicList eCurRefPicList   = REF_PIC_LIST_0 ;
4924      Int        curCandPicRefIdx = 0;
4925      if( curCandPic == 0 ) 
4926      { 
4927        eCurRefPicList   = RefPicList(getSlice()->isInterB() ? 1-getSlice()->getColFromL0Flag() : 0);
4928        curCandPicRefIdx = getSlice()->getColRefIdx();
4929      }
4930      else                 
4931      {
4932        eCurRefPicList   = getPic()->getRapRefList();
4933        curCandPicRefIdx = getPic()->getRapRefIdx();
4934      }
4935
4936      // Check BR and Center       
4937      for(Int curPosition = 0; curPosition < 2; curPosition++) 
4938      {
4939        Bool bCheck = false; 
4940        if ( curPosition == 0 && iLCUIdxRBNb >= 0 )
4941          bCheck = xGetColDisMV( eCurRefPicList, curCandPicRefIdx, iLCUIdxRBNb, iPartIdxRBNb,  cColMv, iTargetViewIdx, iTStartViewIdx);
4942
4943        if (curPosition == 1 )
4944          bCheck = xGetColDisMV( eCurRefPicList, curCandPicRefIdx, uiLCUIdx,   uiPartIdxCenter,  cColMv, iTargetViewIdx, iTStartViewIdx );
4945
4946        if( bCheck )
4947        {
4948          clipMv(cColMv);
4949          pDInfo->m_acNBDV = cColMv;
4950          pDInfo->m_aVIdxCan  = iTargetViewIdx;
4951
4952#if H_3D_NBDV_REF
4953          TComPic* picDepth = NULL;         
4954          picDepth = getSlice()->getIvPic( true, iTargetViewIdx );
4955          assert(picDepth != NULL);
4956          if (picDepth && bDepthRefine)
4957            estimateDVFromDM(iTargetViewIdx, uiPartIdx, picDepth, uiPartAddr, &cColMv );
4958
4959          pDInfo->m_acDoNBDV  = cColMv;
4960#endif //H_3D_NBDV_REF
4961          return true;
4962        }
4963      } 
4964    }
4965  } 
4966
4967  UInt uiIdx = 0;
4968  Bool        bCheckMcpDv = false;   
4969  TComDataCU* pcTmpCU     = NULL;
4970
4971  //// ******* Get disparity from left block ******* /////
4972  pcTmpCU = getPULeft(uiIdx, uiPartIdxLB, true, false);
4973  bCheckMcpDv = true; 
4974  if ( xCheckSpatialNBDV( pcTmpCU, uiIdx, pDInfo, bCheckMcpDv, &cIDVInfo, DVFROM_LEFT
4975#if H_3D_NBDV_REF
4976  , bDepthRefine
4977#endif
4978    ) )
4979    return true;
4980
4981  //// ******* Get disparity from above block ******* /////
4982  pcTmpCU = getPUAbove(uiIdx, uiPartIdxRT, true, false, true);
4983  if(pcTmpCU != NULL )
4984  {
4985    bCheckMcpDv = ( ( getAddr() - pcTmpCU->getAddr() ) == 0);
4986    if ( xCheckSpatialNBDV( pcTmpCU, uiIdx, pDInfo, bCheckMcpDv, &cIDVInfo, DVFROM_ABOVE
4987#if H_3D_NBDV_REF
4988  , bDepthRefine
4989#endif
4990    ) )
4991      return true;
4992  }
4993
4994  //// ******* Get disparity from above right block ******* /////
4995  pcTmpCU = getPUAboveRight(uiIdx, uiPartIdxRT, true);
4996  if(pcTmpCU != NULL )
4997  {
4998    bCheckMcpDv = ( ( getAddr() - pcTmpCU->getAddr() ) == 0);
4999    if ( xCheckSpatialNBDV( pcTmpCU, uiIdx, pDInfo, bCheckMcpDv, &cIDVInfo, DVFROM_ABOVERIGHT
5000#if H_3D_NBDV_REF
5001  , bDepthRefine
5002#endif
5003    ) )
5004      return true;
5005  }
5006
5007  //// ******* Get disparity from below left block ******* /////
5008  pcTmpCU = getPUBelowLeft(uiIdx, uiPartIdxLB, true);
5009  if( pcTmpCU != NULL )
5010  {
5011    bCheckMcpDv = true; 
5012    if ( xCheckSpatialNBDV( pcTmpCU, uiIdx, pDInfo, bCheckMcpDv, &cIDVInfo, DVFROM_LEFTBELOW
5013#if H_3D_NBDV_REF
5014  , bDepthRefine
5015#endif
5016    ) )
5017      return true;
5018  }
5019
5020  //// ******* Get disparity from above left block ******* /////
5021  pcTmpCU = getPUAboveLeft(uiIdx, (m_uiAbsIdxInLCU + uiPartAddr), true);
5022  assert(uiPartIdxLT == (m_uiAbsIdxInLCU + uiPartAddr));
5023
5024  if( pcTmpCU != NULL )
5025  {
5026    bCheckMcpDv = (( getAddr() - pcTmpCU->getAddr() ) <= 1); 
5027    if ( xCheckSpatialNBDV( pcTmpCU, uiIdx, pDInfo, bCheckMcpDv, &cIDVInfo, DVFROM_ABOVELEFT
5028#if H_3D_NBDV_REF
5029  , bDepthRefine
5030#endif
5031    ) )
5032      return true;
5033  }
5034
5035  //// ******* Search MCP blocks ******* /////
5036  if( cIDVInfo.m_bFound ) 
5037  {
5038    for( Int curPos = 0 ; curPos < IDV_CANDS ; curPos++ ) 
5039    {
5040      for(Int iList = 0; iList < (getSlice()->isInterB() ? 2: 1); iList ++)
5041      {
5042        if( cIDVInfo.m_bAvailab[iList][curPos] )
5043        {
5044          TComMv cDispVec = cIDVInfo.m_acMvCand[iList][ curPos ];
5045          clipMv( cDispVec );
5046          pDInfo->m_acNBDV = cDispVec;
5047          pDInfo->m_aVIdxCan = cIDVInfo.m_aVIdxCan[iList][ curPos ];
5048          assert(pDInfo->m_aVIdxCan == 0); //Notes from QC: only works for CTC
5049#if H_3D_NBDV_REF
5050          TComPic* picDepth = getSlice()->getIvPic( true, pDInfo->m_aVIdxCan );
5051          assert(picDepth!=NULL);
5052
5053          if (picDepth && bDepthRefine)
5054          {
5055            estimateDVFromDM (pDInfo->m_aVIdxCan, uiPartIdx, picDepth, uiPartAddr, &cDispVec);
5056          }
5057          pDInfo->m_acDoNBDV = cDispVec;
5058#endif
5059          return true;
5060        }
5061      }
5062    }
5063  }
5064
5065  TComMv defaultDV(0, 0);
5066  pDInfo->m_acNBDV = defaultDV;
5067  pDInfo->m_aVIdxCan = 0;
5068#if H_3D_NBDV_REF
5069  TComPic* picDepth = NULL;
5070  picDepth = getSlice()->getIvPic( true, 0 );
5071  assert(picDepth!=NULL);
5072
5073  if (picDepth && bDepthRefine)
5074  {
5075    estimateDVFromDM(0, uiPartIdx, picDepth, uiPartAddr, &defaultDV ); // from base view
5076  }
5077  pDInfo->m_acDoNBDV = defaultDV;
5078#endif
5079
5080  return false; 
5081}
5082
5083#if H_3D_NBDV_REF
5084Pel TComDataCU::getMcpFromDM(TComPicYuv* pcBaseViewDepthPicYuv, TComMv* mv, Int iBlkX, Int iBlkY, Int iBlkWidth, Int iBlkHeight, Int* aiShiftLUT )
5085{
5086  Int iPictureWidth  = pcBaseViewDepthPicYuv->getWidth();
5087  Int iPictureHeight = pcBaseViewDepthPicYuv->getHeight();
5088
5089  Int depthStartPosX = Clip3(0,   iPictureWidth - iBlkWidth,  iBlkX + ((mv->getHor()+2)>>2));
5090  Int depthStartPosY = Clip3(0,   iPictureHeight- iBlkHeight,  iBlkY + ((mv->getVer()+2)>>2));
5091  Int depthEndPosX   = Clip3(0,   iPictureWidth - 1,  iBlkX + iBlkWidth - 1 + ((mv->getHor()+2)>>2));
5092  Int depthEndPosY   = Clip3(0,   iPictureHeight - 1,  iBlkY + iBlkHeight - 1 + ((mv->getVer()+2)>>2));
5093
5094  Pel* depthTL  = pcBaseViewDepthPicYuv->getLumaAddr();
5095  Int depStride =  pcBaseViewDepthPicYuv->getStride();
5096
5097  Pel  maxDepthVal = 0;
5098  maxDepthVal = std::max( maxDepthVal, depthTL[ (depthStartPosY) * depStride + depthStartPosX ]);      // Left Top
5099  maxDepthVal = std::max( maxDepthVal, depthTL[ (depthEndPosY)   * depStride + depthStartPosX ]);      // Left Bottom
5100  maxDepthVal = std::max( maxDepthVal, depthTL[ (depthStartPosY) * depStride + depthEndPosX   ]);      // Right Top
5101  maxDepthVal = std::max( maxDepthVal, depthTL[ (depthEndPosY)   * depStride + depthEndPosX   ]);      // Right Bottom
5102
5103  return aiShiftLUT[ maxDepthVal ];
5104}
5105
5106Void TComDataCU::estimateDVFromDM(Int refViewIdx, UInt uiPartIdx, TComPic* picDepth, UInt uiPartAddr, TComMv* cMvPred )
5107{
5108  if (picDepth)
5109  {
5110    UInt uiAbsPartAddrCurrCU = m_uiAbsIdxInLCU + uiPartAddr;
5111    Int iWidth, iHeight;
5112    getPartIndexAndSize( uiPartIdx, uiPartAddr, iWidth, iHeight ); // The modified value of uiPartAddr won't be used any more
5113
5114    TComPicYuv* pcBaseViewDepthPicYuv = picDepth->getPicYuvRec();
5115    Int iBlkX = ( getAddr() % picDepth->getFrameWidthInCU() ) * g_uiMaxCUWidth  + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartAddrCurrCU ] ];
5116    Int iBlkY = ( getAddr() / picDepth->getFrameWidthInCU() ) * g_uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartAddrCurrCU ] ];
5117
5118    Int* aiShiftLUT = getSlice()->getDepthToDisparityB(refViewIdx );
5119
5120    Pel iDisp = getMcpFromDM( pcBaseViewDepthPicYuv, cMvPred, iBlkX, iBlkY, iWidth, iHeight, aiShiftLUT );
5121    cMvPred->setHor( iDisp );
5122    clipMv(*cMvPred);
5123  }
5124}
5125#endif //H_3D_NBDV_REF
5126
5127
5128Bool TComDataCU::xCheckSpatialNBDV( TComDataCU* pcTmpCU, UInt uiIdx, DisInfo* pNbDvInfo, Bool bSearchForMvpDv, IDVInfo* paIDVInfo, UInt uiMvpDvPos
5129#if H_3D_NBDV_REF
5130, Bool bDepthRefine
5131#endif
5132)
5133{
5134  if( pcTmpCU != NULL && !pcTmpCU->isIntra( uiIdx ) )
5135  {
5136    Bool bTmpIsSkipped = pcTmpCU->isSkipped( uiIdx );
5137    for(Int iList = 0; iList < (getSlice()->isInterB() ? 2: 1); iList ++)
5138    {
5139      RefPicList eRefPicList = RefPicList(iList);
5140      Int      refId = pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) ;
5141      TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
5142
5143      if( refId >= 0)
5144      {
5145        Int refViewIdx  = pcTmpCU->getSlice()->getRefPic(eRefPicList, refId)->getViewIndex();
5146        if (refViewIdx != m_pcSlice->getViewIndex()) 
5147        {
5148          clipMv(cMvPred);
5149          pNbDvInfo->m_acNBDV = cMvPred;
5150          pNbDvInfo->m_aVIdxCan = refViewIdx;
5151#if H_3D_NBDV_REF
5152          TComPic* picDepth = NULL;
5153          assert(getSlice()->getRefPic(eRefPicList, refId)->getPOC() == getSlice()->getPOC());         
5154          picDepth   = getSlice()->getIvPic (true, refViewIdx );
5155          assert(picDepth != NULL);
5156
5157          UInt uiPartIdx = 0;   //Notes from MTK: Please confirm that using 0 as partition index and partition address is correct for CU-level DoNBDV
5158          UInt uiPartAddr = 0;  //QC: confirmed
5159
5160          if (picDepth && bDepthRefine)
5161            estimateDVFromDM(refViewIdx, uiPartIdx, picDepth, uiPartAddr, &cMvPred );
5162
5163          pNbDvInfo->m_acDoNBDV = cMvPred;
5164#endif
5165          return true;
5166        }
5167        else if ( bSearchForMvpDv && cMvPred.getIDVFlag() && bTmpIsSkipped )
5168        {
5169          assert( uiMvpDvPos < IDV_CANDS );
5170          paIDVInfo->m_acMvCand[iList][ uiMvpDvPos ] = TComMv( cMvPred.getIDVHor(), cMvPred.getIDVVer() );
5171          //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.
5172          paIDVInfo->m_aVIdxCan[iList][ uiMvpDvPos ] = 0; 
5173          paIDVInfo->m_bAvailab[iList][ uiMvpDvPos ] = true;
5174          paIDVInfo->m_bFound                        = true; 
5175        }
5176      }
5177    }
5178  }
5179  return false; 
5180}
5181 
5182Void TComDataCU::xDeriveRightBottomNbIdx(Int &riLCUIdxRBNb, Int &riPartIdxRBNb )
5183{
5184  UInt uiPartIdx = 0;
5185  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth(); 
5186  Int uiLCUIdx = getAddr();
5187
5188  UInt uiPartIdxRB;
5189  deriveRightBottomIdx(uiPartIdx, uiPartIdxRB ); 
5190  UInt uiAbsPartIdxTmp = g_auiZscanToRaster[uiPartIdxRB];
5191
5192  if (( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth() )>= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )
5193  {
5194    riLCUIdxRBNb  = -1;
5195    riPartIdxRBNb = -1;
5196  }
5197  else if(( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxTmp] + m_pcPic->getMinCUHeight() )>= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
5198  {
5199    riLCUIdxRBNb  = -1;
5200    riPartIdxRBNb = -1;
5201  }
5202  else
5203  {
5204    if ( ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
5205      ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
5206    {
5207      riPartIdxRBNb = g_auiRasterToZscan[ uiAbsPartIdxTmp + uiNumPartInCUWidth + 1 ];
5208      riLCUIdxRBNb  = uiLCUIdx; 
5209    }
5210    else if ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
5211    {
5212      riPartIdxRBNb = -1;
5213      riLCUIdxRBNb  = -1;
5214    }
5215    else if ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
5216    {
5217      riPartIdxRBNb = g_auiRasterToZscan[ uiAbsPartIdxTmp + 1 ];
5218      riLCUIdxRBNb = uiLCUIdx + 1;
5219    }
5220    else //is the right bottom corner of LCU                       
5221    {
5222      riPartIdxRBNb = -1;
5223      riLCUIdxRBNb  = -1;
5224    }
5225  }
5226}
5227
5228
5229Void TComDataCU::setDvInfoSubParts( DisInfo cDvInfo, UInt uiAbsPartIdx, UInt uiDepth )
5230{
5231  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
5232  for (UInt ui = 0; ui < uiCurrPartNumb; ui++ )
5233  {
5234    m_pDvInfo[uiAbsPartIdx + ui] = cDvInfo;
5235  }
5236}
5237
5238Bool TComDataCU::xGetColDisMV( RefPicList eRefPicList, Int refidx, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv , Int & iTargetViewIdx, Int & iStartViewIdx )
5239{
5240
5241  RefPicList  eColRefPicList = REF_PIC_LIST_0;
5242  Int iColViewIdx, iColRefViewIdx;
5243  TComPic *pColPic = getSlice()->getRefPic( eRefPicList, refidx);
5244  TComDataCU *pColCU = pColPic->getCU( uiCUAddr );
5245  iColViewIdx = pColCU->getSlice()->getViewIndex();
5246  if (pColCU->getPic()==0||pColCU->getPartitionSize(uiPartUnitIdx)==SIZE_NONE||pColCU->isIntra(uiPartUnitIdx))
5247  {
5248    return false;
5249  }
5250  for (Int ilist = 0; ilist < (pColCU->getSlice()->isInterB()? 2:1); ilist++) 
5251  {
5252    if(pColCU->getSlice()->isInterB())
5253    {
5254        eColRefPicList = RefPicList(ilist);
5255    }
5256
5257    Int iColRefIdx = pColCU->getCUMvField(eColRefPicList)->getRefIdx(uiPartUnitIdx);
5258
5259    if (iColRefIdx < 0)
5260    {
5261      continue;
5262    }
5263
5264    iColRefViewIdx = pColCU->getSlice()->getRefPic(eColRefPicList, iColRefIdx)->getViewIndex();
5265
5266    if ( iColViewIdx    == iColRefViewIdx ) // temporal vector
5267    {
5268      continue;
5269    }
5270    else 
5271    {
5272      rcMv = pColCU->getCUMvField(eColRefPicList)->getMv(uiPartUnitIdx);
5273      rcMv.setIDVFlag(0);
5274      iTargetViewIdx  = iColRefViewIdx ;
5275      iStartViewIdx   = iColViewIdx   ;
5276      return true;   
5277    }
5278  }
5279
5280  return false;
5281}
5282#endif
5283#if  MTK_FAST_TEXTURE_ENCODING_E0173
5284Void
5285TComDataCU::getIVNStatus       ( UInt uiPartIdx,  DisInfo* pDInfo, Bool& bIVFMerge, Int& iIVFMaxD)
5286{
5287  TComSlice*    pcSlice         = getSlice (); 
5288  Int iViewIndex = pDInfo->m_aVIdxCan;
5289  //--- get base CU/PU and check prediction mode ---
5290  TComPic*    pcBasePic   = pcSlice->getIvPic( false, iViewIndex );
5291  TComPicYuv* pcBaseRec   = pcBasePic->getPicYuvRec   ();
5292
5293  UInt          uiPartAddr;
5294  Int           iWidth;
5295  Int           iHeight;
5296  getPartIndexAndSize( uiPartIdx, uiPartAddr, iWidth, iHeight );
5297
5298  Int  iCurrPosX, iCurrPosY;
5299  pcBaseRec->getTopLeftSamplePos( getAddr(), getZorderIdxInCU() + uiPartAddr, iCurrPosX, iCurrPosY );
5300
5301  iCurrPosX  += ( ( iWidth  - 1 ) >> 1 );
5302  iCurrPosY  += ( ( iHeight - 1 ) >> 1 );
5303
5304  Bool depthRefineFlag = false; 
5305#if H_3D_NBDV_REF
5306  depthRefineFlag = m_pcSlice->getVPS()->getDepthRefinementFlag( m_pcSlice->getLayerIdInVps() ); 
5307#endif // H_3D_NBDV_REF
5308
5309  TComMv      cDv = depthRefineFlag ? pDInfo->m_acDoNBDV : pDInfo->m_acNBDV; 
5310
5311  Int         iBasePosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (cDv.getHor() + 2 ) >> 2 ) );
5312  Int         iBasePosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (cDv.getVer() + 2 ) >> 2 )); 
5313  Int         iBaseLPosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX - (iWidth >> 1) + ( (cDv.getHor() + 2 ) >> 2 ) );
5314  Int         iBaseLPosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (cDv.getVer() + 2 ) >> 2 )); 
5315  Int         iBaseRPosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + (iWidth >> 1) + 1 + ( (cDv.getHor() + 2 ) >> 2 ) );
5316  Int         iBaseRPosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (cDv.getVer() + 2 ) >> 2 )); 
5317  Int         iBaseUPosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (cDv.getHor() + 2 ) >> 2 ) );
5318  Int         iBaseUPosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY - (iHeight >> 1) + ( (cDv.getVer() + 2 ) >> 2 )); 
5319  Int         iBaseDPosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (cDv.getHor() + 2 ) >> 2 ) );
5320  Int         iBaseDPosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + (iHeight >> 1) + 1 + ( (cDv.getVer() + 2 ) >> 2 )); 
5321
5322  Int         iBaseCUAddr;
5323  Int         iBaseAbsPartIdx;
5324  Int         iBaseLCUAddr;
5325  Int         iBaseLAbsPartIdx;
5326  Int         iBaseRCUAddr;
5327  Int         iBaseRAbsPartIdx;
5328  Int         iBaseUCUAddr;
5329  Int         iBaseUAbsPartIdx;
5330  Int         iBaseDCUAddr;
5331  Int         iBaseDAbsPartIdx;
5332  pcBaseRec->getCUAddrAndPartIdx( iBasePosX , iBasePosY , iBaseCUAddr, iBaseAbsPartIdx );
5333  pcBaseRec->getCUAddrAndPartIdx( iBaseLPosX , iBaseLPosY , iBaseLCUAddr, iBaseLAbsPartIdx );
5334  pcBaseRec->getCUAddrAndPartIdx( iBaseRPosX , iBaseRPosY , iBaseRCUAddr, iBaseRAbsPartIdx );
5335  pcBaseRec->getCUAddrAndPartIdx( iBaseUPosX , iBaseUPosY , iBaseUCUAddr, iBaseUAbsPartIdx );
5336  pcBaseRec->getCUAddrAndPartIdx( iBaseDPosX , iBaseDPosY , iBaseDCUAddr, iBaseDAbsPartIdx );
5337  TComDataCU* pcBaseCU    = pcBasePic->getCU( iBaseCUAddr );
5338  TComDataCU* pcBaseLCU    = pcBasePic->getCU( iBaseLCUAddr );
5339  TComDataCU* pcBaseRCU    = pcBasePic->getCU( iBaseRCUAddr );
5340  TComDataCU* pcBaseUCU    = pcBasePic->getCU( iBaseUCUAddr );
5341  TComDataCU* pcBaseDCU    = pcBasePic->getCU( iBaseDCUAddr );
5342  bIVFMerge = pcBaseLCU->getMergeFlag( iBaseLAbsPartIdx ) && pcBaseCU->getMergeFlag( iBaseAbsPartIdx ) && pcBaseRCU->getMergeFlag( iBaseRAbsPartIdx ) && pcBaseUCU->getMergeFlag( iBaseUAbsPartIdx ) && pcBaseDCU->getMergeFlag( iBaseDAbsPartIdx );
5343  Int aiDepthL[5]; //depth level
5344  aiDepthL[0] = pcBaseCU->getDepth(iBaseAbsPartIdx);
5345  aiDepthL[1] = pcBaseLCU->getDepth(iBaseLAbsPartIdx);
5346  aiDepthL[2] = pcBaseRCU->getDepth(iBaseRAbsPartIdx);
5347  aiDepthL[3] = pcBaseUCU->getDepth(iBaseUAbsPartIdx);
5348  aiDepthL[4] = pcBaseDCU->getDepth(iBaseDAbsPartIdx);
5349  for (Int i = 0; i < 5; i++)
5350  {
5351    if (iIVFMaxD < aiDepthL[i])
5352      iIVFMaxD = aiDepthL[i];
5353  }
5354}
5355#endif
5356#if H_3D_IV_MERGE
5357Bool
5358TComDataCU::getInterViewMergeCands(UInt uiPartIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv, DisInfo* pDInfo, Int* availableMcDc )
5359{
5360  TComSlice*    pcSlice         = getSlice (); 
5361  Int iViewIndex = pDInfo->m_aVIdxCan;
5362  //--- get base CU/PU and check prediction mode ---
5363  TComPic*    pcBasePic   = pcSlice->getIvPic( false, iViewIndex );
5364  TComPicYuv* pcBaseRec   = pcBasePic->getPicYuvRec   ();
5365
5366  UInt          uiPartAddr;
5367  Int           iWidth;
5368  Int           iHeight;
5369  getPartIndexAndSize( uiPartIdx, uiPartAddr, iWidth, iHeight );
5370
5371  Int  iCurrPosX, iCurrPosY;
5372  pcBaseRec->getTopLeftSamplePos( getAddr(), getZorderIdxInCU() + uiPartAddr, iCurrPosX, iCurrPosY );
5373
5374  iCurrPosX  += ( ( iWidth  - 1 ) >> 1 );
5375  iCurrPosY  += ( ( iHeight - 1 ) >> 1 );
5376
5377  Bool depthRefineFlag = false; 
5378#if H_3D_NBDV_REF
5379  depthRefineFlag = m_pcSlice->getVPS()->getDepthRefinementFlag( m_pcSlice->getLayerIdInVps() ); 
5380#endif // H_3D_NBDV_REF
5381
5382  TComMv      cDv = depthRefineFlag ? pDInfo->m_acDoNBDV : pDInfo->m_acNBDV; 
5383 
5384  Int         iBasePosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (cDv.getHor() + 2 ) >> 2 ) );
5385  Int         iBasePosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (cDv.getVer() + 2 ) >> 2 )); 
5386
5387  Int         iBaseCUAddr;
5388  Int         iBaseAbsPartIdx;
5389  pcBaseRec->getCUAddrAndPartIdx( iBasePosX , iBasePosY , iBaseCUAddr, iBaseAbsPartIdx );
5390
5391  TComDataCU* pcBaseCU    = pcBasePic->getCU( iBaseCUAddr );
5392
5393  Bool abPdmAvailable[4] = {false, false, false, false};
5394#if H_3D_NBDV
5395  for( Int i = 0; i < 4; i++)
5396  {
5397    pacPdmMv[i].setIDVFlag   (false);
5398  }
5399#endif
5400  if(!( pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) == MODE_INTRA ))
5401  {
5402    for( UInt uiCurrRefListId = 0; uiCurrRefListId < 2; uiCurrRefListId++ )
5403    {
5404      RefPicList  eCurrRefPicList = RefPicList( uiCurrRefListId );
5405
5406      Bool stopLoop = false;
5407      for(Int iLoop = 0; iLoop < 2 && !stopLoop; ++iLoop)
5408      {
5409        RefPicList eBaseRefPicList = (iLoop ==1)? RefPicList( 1 -  uiCurrRefListId ) : RefPicList( uiCurrRefListId );
5410        TComMvField cBaseMvField;
5411        pcBaseCU->getMvField( pcBaseCU, iBaseAbsPartIdx, eBaseRefPicList, cBaseMvField );
5412        Int         iBaseRefIdx     = cBaseMvField.getRefIdx();
5413        if (iBaseRefIdx >= 0)
5414        {
5415          Int iBaseRefPOC = pcBaseCU->getSlice()->getRefPOC(eBaseRefPicList, iBaseRefIdx);
5416          if (iBaseRefPOC != pcSlice->getPOC())   
5417          {
5418            for (Int iPdmRefIdx = 0; iPdmRefIdx < pcSlice->getNumRefIdx( eCurrRefPicList ); iPdmRefIdx++)
5419            {
5420              if (iBaseRefPOC == pcSlice->getRefPOC(eCurrRefPicList, iPdmRefIdx))
5421              {
5422                abPdmAvailable[ uiCurrRefListId ] = true;
5423                TComMv cMv(cBaseMvField.getHor(), cBaseMvField.getVer());
5424#if H_3D_NBDV
5425                cMv.setIDVFlag   (true);
5426                cMv.setIDVHor    (cDv.getHor());                 
5427                cMv.setIDVVer    (cDv.getVer()); 
5428#endif
5429                clipMv( cMv );
5430                paiPdmRefIdx  [ uiCurrRefListId ] = iPdmRefIdx;
5431                pacPdmMv      [ uiCurrRefListId ] = cMv;
5432                stopLoop = true;
5433                break;
5434              }
5435            }
5436          }
5437        }
5438      }
5439    }
5440  }
5441  availableMcDc[0] = ( abPdmAvailable[0] ? 1 : 0 ) + ( abPdmAvailable[1] ? 2 : 0 );
5442  for( Int iRefListId = 0; iRefListId < 2 ; iRefListId++ )
5443  {
5444    RefPicList  eRefPicListDMV       = RefPicList( iRefListId );
5445    Int         iNumRefPics       = pcSlice->getNumRefIdx( eRefPicListDMV );
5446    for( Int iPdmRefIdx = 0; iPdmRefIdx < iNumRefPics; iPdmRefIdx++ )
5447    {
5448      if( pcSlice->getRefPOC( eRefPicListDMV, iPdmRefIdx ) == pcSlice->getPOC())
5449      {
5450        abPdmAvailable[ iRefListId+2 ] = true;
5451        paiPdmRefIdx  [ iRefListId+2 ] = iPdmRefIdx;
5452
5453#if H_3D_NBDV_REF
5454        TComMv cMv = depthRefineFlag ? pDInfo->m_acDoNBDV : pDInfo->m_acNBDV; 
5455#endif // H_3D_NBDV_REF
5456        cMv.setVer(0);
5457        clipMv( cMv );
5458        pacPdmMv      [ iRefListId + 2] = cMv;
5459        break;
5460      }
5461    }
5462  }
5463  availableMcDc[1] = ( abPdmAvailable[2] ? 1 : 0 ) + ( abPdmAvailable[3] ? 2 : 0 );
5464  return false;
5465}
5466#endif
5467#if H_3D_ARP
5468Void TComDataCU::setARPWSubParts ( UChar w, UInt uiAbsPartIdx, UInt uiDepth )
5469{
5470  assert( sizeof( *m_puhARPW) == 1 );
5471  memset( m_puhARPW + uiAbsPartIdx, w, m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ) );
5472}
5473#endif
5474
5475#if H_3D_IC
5476Void TComDataCU::setICFlagSubParts( Bool bICFlag, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
5477{
5478  memset( m_pbICFlag + uiAbsPartIdx, bICFlag, (m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ))*sizeof(Bool) );
5479}
5480
5481Bool TComDataCU::isICFlagRequired( UInt uiAbsPartIdx )
5482{
5483  UInt uiPartAddr;
5484  UInt iNumbPart;
5485
5486  if( !( getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) )
5487  {
5488    return false;
5489  }
5490
5491  if( getSlice()->getIcSkipParseFlag() )
5492  {
5493    if( getMergeFlag( uiAbsPartIdx ) && getMergeIndex( uiAbsPartIdx ) == 0 )
5494    {
5495      return false;
5496    }
5497  }
5498
5499  if( getMergeFlag( uiAbsPartIdx ) )
5500  {
5501    return true;
5502  }
5503
5504
5505  Int iWidth, iHeight;
5506
5507  iNumbPart = ( getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ? 1 : ( getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ? 4 : 2 ) );
5508
5509  for(UInt i = 0; i < iNumbPart; i++)
5510  {
5511    getPartIndexAndSize( i, uiPartAddr, iWidth, iHeight, uiAbsPartIdx, true );
5512    uiPartAddr += uiAbsPartIdx;
5513
5514    for(UInt uiRefIdx = 0; uiRefIdx < 2; uiRefIdx++)
5515    {
5516      RefPicList eRefList = uiRefIdx ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
5517      Int iBestRefIdx = getCUMvField(eRefList)->getRefIdx(uiPartAddr);
5518
5519      if( ( getInterDir( uiPartAddr ) & ( uiRefIdx+1 ) ) && iBestRefIdx >= 0 && getSlice()->getViewIndex() != getSlice()->getRefPic( eRefList, iBestRefIdx )->getViewIndex() )
5520      {
5521        return true;
5522      }
5523    }
5524  }
5525
5526  return false;
5527}
5528#if H_3D_DIM_DMM
5529Void TComDataCU::setDmmWedgeTabIdxSubParts( UInt tabIdx, UInt dmmType, UInt uiAbsPartIdx, UInt uiDepth )
5530{
5531  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
5532  for( UInt ui = 0; ui < uiCurrPartNumb; ui++ ) { m_dmmWedgeTabIdx[dmmType][uiAbsPartIdx+ui] = tabIdx; }
5533}
5534Void  TComDataCU::setDmm2DeltaEndSubParts( Int iDelta, UInt uiAbsPartIdx, UInt uiDepth )
5535{
5536  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
5537  for( UInt ui = 0; ui < uiCurrPartNumb; ui++ ) { m_dmm2DeltaEnd[uiAbsPartIdx+ui] = iDelta; }
5538}
5539Void  TComDataCU::setDmm3IntraTabIdxSubParts( UInt uiTIdx, UInt uiAbsPartIdx, UInt uiDepth )
5540{
5541  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
5542  for( UInt ui = 0; ui < uiCurrPartNumb; ui++ ) { m_dmm3IntraTabIdx[uiAbsPartIdx+ui] = uiTIdx; }
5543}
5544#endif
5545#if H_3D_DIM_RBC
5546Void TComDataCU::reconPartition( UInt uiAbsPartIdx, UInt uiDepth, Bool bLeft, UChar ucStartPos, UChar ucNumEdge, UChar* pucEdgeCode, Bool* pbRegion )
5547{
5548  Int iWidth;
5549  Int iHeight;
5550  if( uiDepth == 0 )
5551  {
5552    iWidth = 64;
5553    iHeight = 64;
5554  }
5555  else if( uiDepth == 1 )
5556  {
5557    iWidth = 32;
5558    iHeight = 32;
5559  }
5560  else if( uiDepth == 2 )
5561  {
5562    iWidth = 16;
5563    iHeight = 16;
5564  }
5565  else if( uiDepth == 3 )
5566  {
5567    iWidth = 8;
5568    iHeight = 8;
5569  }
5570  else // uiDepth == 4
5571  {
5572    iWidth = 4;
5573    iHeight = 4;
5574  }
5575
5576  Int iPtr = 0;
5577  Int iX, iY;
5578  Int iDir = -1;
5579  Int iDiffX = 0, iDiffY = 0;
5580
5581  // 1. Edge Code -> Vert & Horz Edges
5582  Bool*  pbEdge = (Bool*) xMalloc( Bool, 4 * iWidth * iHeight );
5583
5584  for( UInt ui = 0; ui < 4 * iWidth * iHeight; ui++ )
5585    pbEdge  [ ui ] = false;
5586
5587  // Direction : left(0), right(1), top(2), bottom(3), left-top(4), right-top(5), left-bottom(6), right-bottom(7)
5588  // Code      : 0deg(0), 45deg(1), -45deg(2), 90deg(3), -90deg(4), 135deg(5), -135deg(6)
5589  const UChar tableDir[8][7] = { { 0, 6, 4, 3, 2, 7, 5 },
5590  { 1, 5, 7, 2, 3, 4, 6 },
5591  { 2, 4, 5, 0, 1, 6, 7 },
5592  { 3, 7, 6, 1, 0, 5, 4 },
5593  { 4, 0, 2, 6, 5, 3, 1 },
5594  { 5, 2, 1, 4, 7, 0, 3 },
5595  { 6, 3, 0, 7, 4, 1, 2 },
5596  { 7, 1, 3, 5, 6, 2, 0 }};
5597
5598  UChar ucCode = pucEdgeCode[iPtr++];
5599
5600  if( !bLeft )
5601  {
5602    iX = ucStartPos;
5603    iY = 0;
5604
5605    switch(ucCode)
5606    {
5607    case 0: // bottom
5608      iDir = 3;
5609      if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
5610      break;
5611    case 2: // left-bottom
5612      iDir = 6;
5613      if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
5614      break;
5615    case 1: // right-bottom
5616      iDir = 7;
5617      if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
5618      if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5619      break;
5620    case 4: // left
5621      iDir = 0;
5622      assert(false);
5623      break;
5624    case 3: // right
5625      iDir = 1;
5626      if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
5627      if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5628      break;
5629    }
5630  }
5631  else
5632  {
5633    iX = 0;
5634    iY = ucStartPos;
5635
5636    switch(ucCode)
5637    {
5638    case 0: // right
5639      iDir = 1;
5640      if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5641      break;
5642    case 1: // right-top
5643      iDir = 5;
5644      if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5645      if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
5646      break;
5647    case 2: // right-bottom
5648      iDir = 7;
5649      if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5650      break;
5651    case 3: // top
5652      iDir = 2;
5653      if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5654      if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
5655      break;
5656    case 4: // bottom
5657      iDir = 3;
5658      assert(false);
5659      break;
5660    }
5661  }
5662
5663  switch( iDir )
5664  {
5665  case 0: // left
5666    iDiffX = -1;
5667    iDiffY = 0;
5668    break;
5669  case 1: // right
5670    iDiffX = +1;
5671    iDiffY = 0;
5672    break;
5673  case 2: // top
5674    iDiffX = 0;
5675    iDiffY = -1;
5676    break;
5677  case 3: // bottom
5678    iDiffX = 0;
5679    iDiffY = +1;
5680    break;
5681  case 4: // left-top
5682    iDiffX = -1;
5683    iDiffY = -1;
5684    break;
5685  case 5: // right-top
5686    iDiffX = +1;
5687    iDiffY = -1;
5688    break;
5689  case 6: // left-bottom
5690    iDiffX = -1;
5691    iDiffY = +1;
5692    break;
5693  case 7: // right-bottom
5694    iDiffX = +1;
5695    iDiffY = +1;
5696    break;
5697  }
5698
5699  iX += iDiffX;
5700  iY += iDiffY;
5701
5702  while( iPtr < ucNumEdge )
5703  {
5704    ucCode = pucEdgeCode[iPtr++];
5705
5706    Int iNewDir = tableDir[iDir][ucCode];
5707
5708    switch( iNewDir )
5709    {
5710    case 0: // left
5711      iDiffX = -1;
5712      iDiffY = 0;
5713      break;
5714    case 1: // right
5715      iDiffX = +1;
5716      iDiffY = 0;
5717      break;
5718    case 2: // top
5719      iDiffX = 0;
5720      iDiffY = -1;
5721      break;
5722    case 3: // bottom
5723      iDiffX = 0;
5724      iDiffY = +1;
5725      break;
5726    case 4: // left-top
5727      iDiffX = -1;
5728      iDiffY = -1;
5729      break;
5730    case 5: // right-top
5731      iDiffX = +1;
5732      iDiffY = -1;
5733      break;
5734    case 6: // left-bottom
5735      iDiffX = -1;
5736      iDiffY = +1;
5737      break;
5738    case 7: // right-bottom
5739      iDiffX = +1;
5740      iDiffY = +1;
5741      break;
5742    }
5743
5744    switch( iDir )
5745    {
5746    case 0: // left
5747      switch( ucCode )
5748      {
5749      case 0:
5750      case 2:
5751        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
5752        break;
5753      case 1:
5754      case 3:
5755        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
5756        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
5757        break;
5758      case 4:
5759      case 6:
5760        // no
5761        break;
5762      case 5:
5763        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
5764        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5765        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
5766        break;
5767      }
5768      break;
5769    case 1: // right
5770      switch( ucCode )
5771      {
5772      case 0:
5773      case 2:
5774        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5775        break;
5776      case 1:
5777      case 3:
5778        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5779        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
5780        break;
5781      case 4:
5782      case 6:
5783        // no
5784        break;
5785      case 5:
5786        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
5787        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5788        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
5789        break;
5790      }
5791      break;
5792    case 2: // top
5793      switch( ucCode )
5794      {
5795      case 0:
5796      case 2:
5797        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
5798        break;
5799      case 1:
5800      case 3:
5801        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
5802        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
5803        break;
5804      case 4:
5805      case 6:
5806        // no
5807        break;
5808      case 5:
5809        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
5810        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
5811        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
5812        break;
5813      }
5814      break;
5815    case 3: // bottom
5816      switch( ucCode )
5817      {
5818      case 0:
5819      case 2:
5820        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
5821        break;
5822      case 1:
5823      case 3:
5824        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
5825        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5826        break;
5827      case 4:
5828      case 6:
5829        // no
5830        break;
5831      case 5:
5832        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
5833        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
5834        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5835        break;
5836      }
5837      break;
5838    case 4: // left-top
5839      switch( ucCode )
5840      {
5841      case 0:
5842      case 1:
5843        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
5844        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
5845        break;
5846      case 2:
5847      case 4:
5848        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
5849        break;
5850      case 3:
5851      case 5:
5852        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
5853        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
5854        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
5855        break;
5856      case 6:
5857        // no
5858        break;
5859      }
5860      break;
5861    case 5: // right-top
5862      switch( ucCode )
5863      {
5864      case 0:
5865      case 1:
5866        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5867        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
5868        break;
5869      case 2:
5870      case 4:
5871        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5872        break;
5873      case 3:
5874      case 5:
5875        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
5876        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5877        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
5878        break;
5879      case 6:
5880        // no
5881        break;
5882      }
5883      break;
5884    case 6: // left-bottom
5885      switch( ucCode )
5886      {
5887      case 0:
5888      case 1:
5889        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
5890        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
5891        break;
5892      case 2:
5893      case 4:
5894        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
5895        break;
5896      case 3:
5897      case 5:
5898        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
5899        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
5900        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5901        break;
5902      case 6:
5903        // no
5904        break;
5905      }
5906      break;
5907    case 7: // right-bottom
5908      switch( ucCode )
5909      {
5910      case 0:
5911      case 1:
5912        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5913        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
5914        break;
5915      case 2:
5916      case 4:
5917        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
5918        break;
5919      case 3:
5920      case 5:
5921        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
5922        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
5923        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5924        break;
5925      case 6:
5926        // no
5927        break;
5928      }
5929      break;
5930    }
5931
5932    assert( iX >= 0 && iX <= iWidth );
5933    assert( iY >= 0 && iY <= iHeight );
5934
5935    iX += iDiffX;
5936    iY += iDiffY;
5937    iDir = iNewDir;
5938  }
5939
5940  // finalize edge chain
5941  if( iX == iWidth-1 )
5942  {
5943    if( iY == 0 )
5944    {
5945      if( iDir == 1 )
5946      {
5947        pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
5948      }
5949      else if( iDir == 5 )
5950      {
5951        pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
5952      }
5953      else
5954      {
5955        assert(false);
5956      }
5957    }
5958    else if( iY == iHeight-1 )
5959    {
5960      if( iDir == 3 )
5961      {
5962        pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
5963      }
5964      else if( iDir == 7 )
5965      {
5966        pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
5967      }
5968      else
5969      {
5970        assert(false);
5971      }
5972    }
5973    else
5974    {
5975      if( iDir == 1 )
5976      {
5977        pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
5978      }
5979      else if( iDir == 3 )
5980      {
5981        pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
5982        pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
5983      }
5984      else if( iDir == 5 )
5985      {
5986        pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
5987      }
5988      else if( iDir == 7 )
5989      {
5990        pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
5991        pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
5992      }
5993      else
5994      {
5995        assert(false);
5996      }
5997    }
5998  }
5999  else if( iX == 0 )
6000  {
6001    if( iY == 0 )
6002    {
6003      if( iDir == 2 )
6004      {
6005        pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
6006      }
6007      else if( iDir == 4 )
6008      {
6009        pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
6010      }
6011      else
6012      {
6013        assert(false);
6014      }
6015    }
6016    else if( iY == iHeight-1 )
6017    {
6018      if( iDir == 0 )
6019      {
6020        pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
6021      }
6022      else if( iDir == 6 )
6023      {
6024        pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
6025      }
6026      else
6027      {
6028        assert(false);
6029      }
6030    }
6031    else
6032    {
6033      if( iDir == 0 )
6034      {
6035        pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
6036      }
6037      else if( iDir == 2 )
6038      {
6039        pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
6040        pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
6041      }
6042      else if( iDir == 4 )
6043      {
6044        pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
6045        pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
6046      }
6047      else if( iDir == 6 )
6048      {
6049        pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
6050      }
6051      else
6052      {
6053        assert(false);
6054      }
6055    }
6056  }
6057  else if( iY == 0 )
6058  {
6059    if( iDir == 1 )
6060    {
6061      pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
6062      pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
6063    }
6064    else if( iDir == 2 )
6065    {
6066      pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
6067    }
6068    else if( iDir == 4 )
6069    {
6070      pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
6071    }
6072    else if( iDir == 5 )
6073    {
6074      pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
6075      pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
6076    }
6077    else
6078    {
6079      assert(false);
6080    }
6081  }
6082  else if( iY == iHeight-1 )
6083  {
6084    if( iDir == 0 )
6085    {
6086      pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
6087      pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
6088    }
6089    else if( iDir == 3 )
6090    {
6091      pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
6092    }
6093    else if( iDir == 6 )
6094    {
6095      pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
6096      pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
6097    }
6098    else if( iDir == 7 )
6099    {
6100      pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
6101    }
6102    else
6103    {
6104      assert(false);
6105    }
6106  }
6107  else
6108  {
6109    printf("reconPartiton: wrong termination\n");
6110    assert(false);
6111  }
6112
6113  // Reconstruct Region from Chain Code
6114  Bool* pbVisit  = (Bool*) xMalloc( Bool, iWidth * iHeight );
6115  Int*  piStack  = (Int* ) xMalloc( Int,  iWidth * iHeight );
6116
6117  for( UInt ui = 0; ui < iWidth * iHeight; ui++ )
6118  {
6119    pbRegion[ ui ] = true; // fill it as region 1 (we'll discover region 0 next)
6120    pbVisit [ ui ] = false;
6121  }
6122
6123  iPtr = 0;
6124  piStack[iPtr++] = (0 << 8) | (0);
6125  pbRegion[ 0 ] = false;
6126
6127  while(iPtr > 0)
6128  {
6129    Int iTmp = piStack[--iPtr];
6130    Int iX1, iY1;
6131    iX1 = iTmp & 0xff;
6132    iY1 = (iTmp >> 8) & 0xff;
6133
6134    pbVisit[ iX1 + iY1 * iWidth ] = true;
6135
6136    assert( iX1 >= 0 && iX1 < iWidth );
6137    assert( iY1 >= 0 && iY1 < iHeight );
6138
6139    if( iX1 > 0 && !pbEdge[ 2 * iX1 - 1 + 4 * iY1 * iWidth ] && !pbVisit[ iX1 - 1 + iY1 * iWidth ] )
6140    {
6141      piStack[iPtr++] = (iY1 << 8) | (iX1 - 1);
6142      pbRegion[ iX1 - 1 + iY1 * iWidth ] = false;
6143    }
6144    if( iX1 < iWidth - 1 && !pbEdge[ 2 * iX1 + 1 + 4 * iY1 * iWidth ] && !pbVisit[ iX1 + 1 + iY1 * iWidth ] )
6145    {
6146      piStack[iPtr++] = (iY1 << 8) | (iX1 + 1);
6147      pbRegion[ iX1 + 1 + iY1 * iWidth ] = false;
6148    }
6149    if( iY1 > 0 && !pbEdge[ 2 * iX1 + 2 * (2 * iY1 - 1) * iWidth ] && !pbVisit[ iX1 + (iY1 - 1) * iWidth ] )
6150    {
6151      piStack[iPtr++] = ((iY1 - 1) << 8) | iX1;
6152      pbRegion[ iX1 + (iY1 - 1) * iWidth ] = false;
6153    }
6154    if( iY1 < iHeight - 1 && !pbEdge[ 2 * iX1 + 2 * (2 * iY1 + 1) * iWidth ] && !pbVisit[ iX1 + (iY1 + 1) * iWidth ] )
6155    {
6156      piStack[iPtr++] = ((iY1 + 1) << 8) | iX1;
6157      pbRegion[ iX1 + (iY1 + 1) * iWidth ] = false;
6158    }
6159  }
6160
6161  xFree( pbEdge );
6162  xFree( pbVisit );
6163  xFree( piStack );
6164}
6165#endif
6166#endif
6167
6168//! \}
Note: See TracBrowser for help on using the repository browser.