source: 3DVCSoftware/branches/HTM-DEV-2.0-dev3-Samsung/source/Lib/TLibCommon/TComDataCU.cpp

Last change on this file was 554, checked in by samsung-htm, 11 years ago

Integration of E0146

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