source: 3DVCSoftware/branches/HTM-10.2-dev2-RWTH/source/Lib/TLibCommon/TComDataCU.cpp @ 908

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