source: 3DVCSoftware/branches/HTM-10.1-dev0/source/Lib/TLibCommon/TComDataCU.cpp @ 880

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

Cleanups part 5.

  • Property svn:eol-style set to native
File size: 256.0 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 MTK_DDD_G0063
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 MTK_DDD_G0063
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 MTK_DDD_G0063
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 MTK_DDD_G0063
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 MTK_DDD_G0063
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 MTK_DDD_G0063
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 MTK_DDD_G0063
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 MTK_DDD_G0063
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 MTK_DDD_G0063
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 MTK_DDD_G0063
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 MTK_DDD_G0063
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 MTK_DDD_G0063
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 MTK_DDD_G0063
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 MTK_DDD_G0063
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        clipMv( cMv );
3337
3338        rightShiftMergeCandList( pcMvFieldNeighbours, puhInterDirNeighbours, vspFlag, inheritedVSPDisInfo, iCount, (5-iCount), iCount3DV);
3339
3340        abCandIsInter        [ iCount ] = true;
3341        puhInterDirNeighbours[ iCount ] = puhInterDirNeighbours[iFirDispCand];
3342        pcMvFieldNeighbours  [ iCount << 1      ].setMvField(cMv, pcMvFieldNeighbours[( iFirDispCand << 1)].getRefIdx() );
3343        pcMvFieldNeighbours  [(iCount << 1) + 1 ].setMvField(pcMvFieldNeighbours[(iFirDispCand << 1) + 1].getMv(), pcMvFieldNeighbours[( iFirDispCand << 1) + 1].getRefIdx() );
3344       
3345        if( mrgCandIdx == iCount ) 
3346        {
3347          return true;
3348        }
3349
3350        iCount++;
3351        break;
3352      }
3353    }
3354
3355    /// iLoop = 0 --> IvMCShift
3356    /// iLoop = 1 --> IvDCShift  (Derived from IvDC)
3357    if(ivCandDir[iLoop + 2])
3358    {
3359      TComMvField tmpMV[2];
3360      UChar tmpDir = ivCandDir[iLoop + 2];
3361      if( ( ivCandDir[iLoop + 2] & 1 ) == 1 )
3362      {
3363        tmpMV[0].setMvField( ivCandMv[ (iLoop<<1) + 4 ], ivCandRefIdx[ (iLoop<<1) + 4 ] ); 
3364      }
3365      if( ( ivCandDir[iLoop + 2] & 2 ) == 2 )
3366      {
3367        tmpMV[1].setMvField( ivCandMv[ (iLoop<<1) + 5 ], ivCandRefIdx[ (iLoop<<1) + 5 ] );
3368      }
3369     
3370      // Prune IvMC vs. IvMcShift
3371      Bool bRemove = false;     
3372      if( !iLoop && ivCandDir[0] > 0)
3373      {
3374        if(tmpDir == puhInterDirNeighbours[0] && pcMvFieldNeighbours[0]==tmpMV[0] && pcMvFieldNeighbours[1]==tmpMV[1])
3375        {
3376            bRemove                         = true;
3377        }
3378      }
3379      if(!bRemove)
3380      {
3381        rightShiftMergeCandList( pcMvFieldNeighbours, puhInterDirNeighbours, vspFlag, inheritedVSPDisInfo, iCount, (5-iCount), iCount3DV);
3382
3383        abCandIsInter[ iCount ] = true;
3384        puhInterDirNeighbours[ iCount ] = ivCandDir[iLoop + 2];
3385        if( ( ivCandDir[iLoop + 2] & 1 ) == 1 )
3386        {
3387          pcMvFieldNeighbours[ iCount<<1 ].setMvField( ivCandMv[ (iLoop<<1) + 4 ], ivCandRefIdx[ (iLoop<<1) + 4 ] ); 
3388        }
3389        if( ( ivCandDir[iLoop + 2] & 2 ) == 2 )
3390        {
3391          pcMvFieldNeighbours[ (iCount<<1)+1 ].setMvField( ivCandMv[ (iLoop<<1) + 5 ], ivCandRefIdx[ (iLoop<<1) + 5 ] );
3392        }
3393#if H_3D_NBDV
3394        if(iLoop) // For IvMcShift candidate
3395        {
3396          pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3397          pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3398        }
3399#endif
3400        if( mrgCandIdx == iCount )
3401        {
3402          return true;
3403        }
3404        iCount++;
3405      }
3406      break;
3407    }
3408  }
3409  return false;
3410} 
3411
3412inline Bool TComDataCU::xGetPosFirstAvailDmvCand( Int iCount, TComMvField* pcMvFieldNeighbours, Int* ivCandDir, Int posIvDC, Int* vspFlag, Int& posFirstAvailDmvCand )
3413{
3414  // ivCandDir[0] == true --> IvMC is available and excluded in loop over merge list.
3415  for ( Int currListPos = (ivCandDir[0] ? 1 : 0); currListPos < iCount; currListPos++ )
3416  {
3417    if ( ( currListPos == posIvDC ) || ( vspFlag[ currListPos ] != 0 ) )
3418    {
3419      continue;
3420    }
3421    else if((pcMvFieldNeighbours[currListPos<<1].getRefIdx() != -1 ) && (getSlice()->getViewIndex() != getSlice()->getRefPic(RefPicList(0), pcMvFieldNeighbours[currListPos<<1].getRefIdx())->getViewIndex()))
3422    {
3423      posFirstAvailDmvCand = currListPos;
3424      return true;
3425    }
3426  }
3427 return false; 
3428}
3429                                     
3430#endif
3431
3432#if H_3D
3433Void TComDataCU::rightShiftMergeCandList( TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int* iVSPIndexTrue, InheritedVSPDisInfo*  inheritedVSPDisInfo, UInt start, UInt num, Int &iCount3DV)
3434{
3435  iCount3DV++;
3436  for (int i=num; i>0; i--)
3437  {
3438    pcMvFieldNeighbours[(start+i)<<1].setMvField(pcMvFieldNeighbours[(start+i-1)<<1].getMv(), pcMvFieldNeighbours[(start+i-1)<<1].getRefIdx());
3439    pcMvFieldNeighbours[((start+i)<<1)+1].setMvField(pcMvFieldNeighbours[((start+i-1)<<1)+1].getMv(), pcMvFieldNeighbours[((start+i-1)<<1)+1].getRefIdx());
3440    puhInterDirNeighbours[start+i] = puhInterDirNeighbours[start+i-1];
3441    iVSPIndexTrue[start+i] = iVSPIndexTrue[start+i-1];
3442    inheritedVSPDisInfo[start+i].m_acDvInfo   = inheritedVSPDisInfo[start+i-1].m_acDvInfo;
3443  }
3444  TComMv  cZeroMv;
3445  pcMvFieldNeighbours[start<<1].setMvField( cZeroMv, NOT_VALID );
3446  pcMvFieldNeighbours[(start<<1)+1].setMvField( cZeroMv, NOT_VALID );
3447  puhInterDirNeighbours[start] = 0;
3448  iVSPIndexTrue[start] = 0;
3449  inheritedVSPDisInfo[start].m_acDvInfo = m_cDefaultDisInfo;
3450
3451  return;
3452}
3453
3454/** Constructs a list of merging candidates
3455 * \param uiAbsPartIdx
3456 * \param uiPUIdx
3457 * \param uiDepth
3458 * \param pcMvFieldNeighbours
3459 * \param puhInterDirNeighbours
3460 * \param numValidMergeCand
3461 */
3462// HM 12.0 based merge candidate list construction
3463
3464Void TComDataCU::getInterMergeCandidates( UInt uiAbsPartIdx, UInt uiPUIdx, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int& numValidMergeCand, Int mrgCandIdx )
3465{
3466
3467  UInt uiAbsPartAddr = m_uiAbsIdxInLCU + uiAbsPartIdx;
3468  Bool abCandIsInter[ MRG_MAX_NUM_CANDS_MEM ];
3469  TComMv cZeroMv;
3470  for( UInt ui = 0; ui < getSlice()->getMaxNumMergeCand(); ++ui )
3471  {
3472    abCandIsInter[ui] = false;
3473    pcMvFieldNeighbours[ ( ui << 1 )     ].setMvField(cZeroMv, NOT_VALID);
3474    pcMvFieldNeighbours[ ( ui << 1 ) + 1 ].setMvField(cZeroMv, NOT_VALID);
3475  }
3476  numValidMergeCand = getSlice()->getMaxNumMergeCand();
3477  // compute the location of the current PU
3478  Int xP, yP, nPSW, nPSH;
3479  this->getPartPosition(uiPUIdx, xP, yP, nPSW, nPSH);
3480
3481  Int iCount = 0;
3482
3483  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB;
3484  PartSize cCurPS = getPartitionSize( uiAbsPartIdx );
3485  deriveLeftRightTopIdxGeneral( uiAbsPartIdx, uiPUIdx, uiPartIdxLT, uiPartIdxRT );
3486  deriveLeftBottomIdxGeneral  ( uiAbsPartIdx, uiPUIdx, uiPartIdxLB );
3487
3488  //left
3489  UInt uiLeftPartIdx = 0;
3490  TComDataCU* pcCULeft = 0;
3491  pcCULeft = getPULeft( uiLeftPartIdx, uiPartIdxLB );
3492  Bool isAvailableA1 = pcCULeft &&
3493    pcCULeft->isDiffMER(xP -1, yP+nPSH-1, xP, yP) &&
3494    !( uiPUIdx == 1 && (cCurPS == SIZE_Nx2N || cCurPS == SIZE_nLx2N || cCurPS == SIZE_nRx2N) ) &&
3495    !pcCULeft->isIntra( uiLeftPartIdx ) ;
3496  if ( isAvailableA1 )
3497  {
3498    m_bAvailableFlagA1 = 1;
3499    abCandIsInter[iCount] = true;
3500    // get Inter Dir
3501    puhInterDirNeighbours[iCount] = pcCULeft->getInterDir( uiLeftPartIdx );
3502    // get Mv from Left
3503    pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3504    if ( getSlice()->isInterB() )
3505    {
3506      pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3507    }
3508
3509    iCount ++;
3510  }
3511 
3512  // early termination
3513  if (iCount == getSlice()->getMaxNumMergeCand()) 
3514  {
3515    return;
3516  }
3517  // above
3518  UInt uiAbovePartIdx = 0;
3519  TComDataCU* pcCUAbove = 0;
3520  pcCUAbove = getPUAbove( uiAbovePartIdx, uiPartIdxRT );
3521  Bool isAvailableB1 = pcCUAbove &&
3522  pcCUAbove->isDiffMER(xP+nPSW-1, yP-1, xP, yP) &&
3523  !( uiPUIdx == 1 && (cCurPS == SIZE_2NxN || cCurPS == SIZE_2NxnU || cCurPS == SIZE_2NxnD) ) &&
3524  !pcCUAbove->isIntra( uiAbovePartIdx );
3525  if ( isAvailableB1 && (!isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAbove, uiAbovePartIdx ) ) )
3526  {
3527    m_bAvailableFlagB1 = 1;
3528    abCandIsInter[iCount] = true;
3529    // get Inter Dir
3530    puhInterDirNeighbours[iCount] = pcCUAbove->getInterDir( uiAbovePartIdx );
3531    // get Mv from Left
3532    pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3533    if ( getSlice()->isInterB() )
3534    {
3535      pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3536    }
3537    if ( mrgCandIdx == iCount )
3538    {
3539      return;
3540    }
3541    iCount ++;
3542  }
3543  // early termination
3544  if (iCount == getSlice()->getMaxNumMergeCand()) 
3545  {
3546    return;
3547  }
3548
3549  // above right
3550  UInt uiAboveRightPartIdx = 0;
3551  TComDataCU* pcCUAboveRight = 0;
3552  pcCUAboveRight = getPUAboveRight( uiAboveRightPartIdx, uiPartIdxRT );
3553  Bool isAvailableB0 = pcCUAboveRight &&
3554  pcCUAboveRight->isDiffMER(xP+nPSW, yP-1, xP, yP) &&
3555  !pcCUAboveRight->isIntra( uiAboveRightPartIdx );
3556  if ( isAvailableB0 && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveRight, uiAboveRightPartIdx ) ) )
3557  {
3558    m_bAvailableFlagB0 = 1;
3559    abCandIsInter[iCount] = true;
3560    // get Inter Dir
3561    puhInterDirNeighbours[iCount] = pcCUAboveRight->getInterDir( uiAboveRightPartIdx );
3562    // get Mv from Left
3563    pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3564    if ( getSlice()->isInterB() )
3565    {
3566      pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3567    }
3568    if ( mrgCandIdx == iCount )
3569    {
3570      return;
3571    }
3572    iCount ++;
3573  }
3574  // early termination
3575  if (iCount == getSlice()->getMaxNumMergeCand()) 
3576  {
3577    return;
3578  }
3579
3580  //left bottom
3581  UInt uiLeftBottomPartIdx = 0;
3582  TComDataCU* pcCULeftBottom = 0;
3583  pcCULeftBottom = this->getPUBelowLeft( uiLeftBottomPartIdx, uiPartIdxLB );
3584  Bool isAvailableA0 = pcCULeftBottom &&
3585  pcCULeftBottom->isDiffMER(xP-1, yP+nPSH, xP, yP) &&
3586  !pcCULeftBottom->isIntra( uiLeftBottomPartIdx ) ;
3587  if ( isAvailableA0 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCULeftBottom, uiLeftBottomPartIdx ) ) )
3588  {
3589    m_bAvailableFlagA0 = 1;
3590    abCandIsInter[iCount] = true;
3591    // get Inter Dir
3592    puhInterDirNeighbours[iCount] = pcCULeftBottom->getInterDir( uiLeftBottomPartIdx );
3593    // get Mv from Left
3594    pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3595    if ( getSlice()->isInterB() )
3596    {
3597      pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3598    }
3599    if ( mrgCandIdx == iCount )
3600    {
3601      return;
3602    }
3603    iCount ++;
3604  }
3605  // early termination
3606  if (iCount == getSlice()->getMaxNumMergeCand()) 
3607  {
3608    return;
3609  }
3610  // above left
3611  if( iCount < 4 )
3612  {
3613    UInt uiAboveLeftPartIdx = 0;
3614    TComDataCU* pcCUAboveLeft = 0;
3615    pcCUAboveLeft = getPUAboveLeft( uiAboveLeftPartIdx, uiAbsPartAddr );
3616    Bool isAvailableB2 = pcCUAboveLeft &&
3617    pcCUAboveLeft->isDiffMER(xP-1, yP-1, xP, yP) &&
3618    !pcCUAboveLeft->isIntra( uiAboveLeftPartIdx );
3619    if ( isAvailableB2 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) )
3620        && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) ) )
3621    {
3622      m_bAvailableFlagB2 = 1;
3623      abCandIsInter[iCount] = true;
3624      // get Inter Dir
3625      puhInterDirNeighbours[iCount] = pcCUAboveLeft->getInterDir( uiAboveLeftPartIdx );
3626      // get Mv from Left
3627      pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3628      if ( getSlice()->isInterB() )
3629      {
3630        pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3631      }
3632      if ( mrgCandIdx == iCount )
3633      {
3634        return;
3635      }
3636      iCount ++;
3637    }
3638  }
3639  // early termination
3640  if (iCount == getSlice()->getMaxNumMergeCand()) 
3641  {
3642    return;
3643  }
3644  if ( getSlice()->getEnableTMVPFlag())
3645  {
3646    //>> MTK colocated-RightBottom
3647    UInt uiPartIdxRB;
3648
3649    deriveRightBottomIdx( uiPUIdx, uiPartIdxRB ); 
3650
3651    UInt uiAbsPartIdxTmp = g_auiZscanToRaster[uiPartIdxRB];
3652    UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
3653
3654    TComMv cColMv;
3655    Int iRefIdx;
3656    Int uiLCUIdx = -1;
3657
3658    if      ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
3659    {
3660    }
3661    else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxTmp] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
3662    {
3663    }
3664    else
3665    {
3666      if ( ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
3667        ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
3668      {
3669        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + uiNumPartInCUWidth + 1 ];
3670        uiLCUIdx = getAddr();
3671      }
3672      else if ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
3673      {
3674        uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdxTmp + uiNumPartInCUWidth + 1) % m_pcPic->getNumPartInCU() ];
3675      }
3676      else if ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
3677      {
3678        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + 1 ];
3679        uiLCUIdx = getAddr() + 1;
3680      }
3681      else //is the right bottom corner of LCU                       
3682      {
3683        uiAbsPartAddr = 0;
3684      }
3685    }
3686
3687    iRefIdx = 0;
3688    Bool bExistMV = false;
3689    UInt uiPartIdxCenter;
3690    UInt uiCurLCUIdx = getAddr();
3691    Int dir = 0;
3692    UInt uiArrayAddr = iCount;
3693    xDeriveCenterIdx( uiPUIdx, uiPartIdxCenter );
3694    bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_0, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx );
3695    if( bExistMV == false )
3696    {
3697      bExistMV = xGetColMVP( REF_PIC_LIST_0, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
3698    }
3699    if( bExistMV )
3700    {
3701      dir |= 1;
3702      pcMvFieldNeighbours[ 2 * uiArrayAddr ].setMvField( cColMv, iRefIdx );
3703    }
3704
3705    if ( getSlice()->isInterB() )
3706    {
3707#if H_3D_TMVP
3708      iRefIdx = 0;
3709#endif
3710      bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_1, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx);
3711      if( bExistMV == false )
3712      {
3713        bExistMV = xGetColMVP( REF_PIC_LIST_1, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
3714      }
3715      if( bExistMV )
3716      {
3717        dir |= 2;
3718        pcMvFieldNeighbours[ 2 * uiArrayAddr + 1 ].setMvField( cColMv, iRefIdx );
3719      }
3720    }
3721
3722    if (dir != 0)
3723    {
3724      puhInterDirNeighbours[uiArrayAddr] = dir;
3725      abCandIsInter[uiArrayAddr] = true;
3726#if H_3D_NBDV
3727      pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3728      pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3729#endif
3730      if ( mrgCandIdx == iCount )
3731      {
3732        return;
3733      }
3734      iCount++;
3735    }
3736  }
3737  // early termination
3738  if (iCount == getSlice()->getMaxNumMergeCand()) 
3739  {
3740    return;
3741  }
3742  UInt uiArrayAddr = iCount;
3743  UInt uiCutoff = uiArrayAddr;
3744 
3745  if ( getSlice()->isInterB() && iCount<5)  // JCT3V-F0129 by Qualcomm
3746  {
3747    UInt uiPriorityList0[12] = {0 , 1, 0, 2, 1, 2, 0, 3, 1, 3, 2, 3};
3748    UInt uiPriorityList1[12] = {1 , 0, 2, 0, 2, 1, 3, 0, 3, 1, 3, 2};
3749
3750    for (Int idx=0; idx<uiCutoff*(uiCutoff-1) && uiArrayAddr!= getSlice()->getMaxNumMergeCand(); idx++)
3751    {
3752      Int i = uiPriorityList0[idx]; Int j = uiPriorityList1[idx];
3753      if (abCandIsInter[i] && abCandIsInter[j]&& (puhInterDirNeighbours[i]&0x1)&&(puhInterDirNeighbours[j]&0x2))
3754      {
3755        abCandIsInter[uiArrayAddr] = true;
3756        puhInterDirNeighbours[uiArrayAddr] = 3;
3757
3758        // get Mv from cand[i] and cand[j]
3759        pcMvFieldNeighbours[uiArrayAddr << 1].setMvField(pcMvFieldNeighbours[i<<1].getMv(), pcMvFieldNeighbours[i<<1].getRefIdx());
3760        pcMvFieldNeighbours[( uiArrayAddr << 1 ) + 1].setMvField(pcMvFieldNeighbours[(j<<1)+1].getMv(), pcMvFieldNeighbours[(j<<1)+1].getRefIdx());
3761
3762        Int iRefPOCL0 = m_pcSlice->getRefPOC( REF_PIC_LIST_0, pcMvFieldNeighbours[(uiArrayAddr<<1)].getRefIdx() );
3763        Int iRefPOCL1 = m_pcSlice->getRefPOC( REF_PIC_LIST_1, pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getRefIdx() );
3764        if (iRefPOCL0 == iRefPOCL1 && pcMvFieldNeighbours[(uiArrayAddr<<1)].getMv() == pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getMv())
3765        {
3766          abCandIsInter[uiArrayAddr] = false;
3767        }
3768        else
3769        {
3770          uiArrayAddr++;
3771        }
3772      }
3773    }
3774  }
3775  // early termination
3776  if (uiArrayAddr == getSlice()->getMaxNumMergeCand()) 
3777  {
3778    return;
3779  }
3780 
3781  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);
3782  Int r = 0;
3783  Int refcnt = 0;
3784  while (uiArrayAddr < getSlice()->getMaxNumMergeCand())
3785  {
3786    abCandIsInter[uiArrayAddr] = true;
3787    puhInterDirNeighbours[uiArrayAddr] = 1;
3788    pcMvFieldNeighbours[uiArrayAddr << 1].setMvField( TComMv(0, 0), r);
3789
3790    if ( getSlice()->isInterB() )
3791    {
3792      puhInterDirNeighbours[uiArrayAddr] = 3;
3793      pcMvFieldNeighbours[(uiArrayAddr << 1) + 1].setMvField(TComMv(0, 0), r);
3794    }
3795    uiArrayAddr++;
3796    if ( refcnt == iNumRefIdx - 1 )
3797    {
3798      r = 0;
3799    }
3800    else
3801    {
3802      ++r;
3803      ++refcnt;
3804    }
3805  }
3806 
3807  numValidMergeCand = uiArrayAddr;
3808}
3809
3810
3811
3812/** Constructs a list of merging candidates
3813 * \param uiAbsPartIdx
3814 * \param uiPUIdx
3815 * \param uiDepth
3816 * \param pcMvFieldNeighbours
3817 * \param puhInterDirNeighbours
3818 * \param numValidMergeCand
3819 */
3820#if H_3D
3821Void TComDataCU::xGetInterMergeCandidates( UInt uiAbsPartIdx, UInt uiPUIdx, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours
3822#else
3823Void TComDataCU::getInterMergeCandidates( UInt uiAbsPartIdx, UInt uiPUIdx, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours
3824#endif
3825#if H_3D_VSP
3826      , Int* vspFlag
3827      , InheritedVSPDisInfo*  inheritedVSPDisInfo
3828#endif
3829#if H_3D_SPIVMP
3830      , Bool* pbSPIVMPFlag, TComMvField* pcMvFieldSP, UChar* puhInterDirSP
3831#endif
3832      , Int& numValidMergeCand, Int mrgCandIdx
3833)
3834{
3835  UInt uiAbsPartAddr = m_uiAbsIdxInLCU + uiAbsPartIdx;
3836#if H_3D_IV_MERGE
3837  ////////////////////////////
3838  //////// INIT LISTS ////////
3839  ////////////////////////////
3840  TComMv cZeroMv;
3841  Bool abCandIsInter[ MRG_MAX_NUM_CANDS_MEM ];
3842#else
3843  Bool abCandIsInter[ MRG_MAX_NUM_CANDS ];
3844#endif
3845#if H_3D
3846  TComMvField tmpMV[2];
3847  UChar tmpDir;
3848
3849#if MTK_DDD_G0063
3850  m_iUseDDDCandIdx = -1;
3851#endif
3852
3853  //////////////////////////////////
3854  //////// GET DISPARITIES  ////////
3855  //////////////////////////////////
3856  DisInfo cDisInfo = getDvInfo(uiAbsPartIdx);
3857  for(Int i = 0; i < MRG_MAX_NUM_CANDS_MEM; i++)
3858  {
3859    inheritedVSPDisInfo[i].m_acDvInfo = cDisInfo;   // To prevent run-time error, this code must be executed always for merging process.
3860  }
3861  m_cDefaultDisInfo = cDisInfo;
3862
3863  if (!( getSlice()->getIsDepth() || getSlice()->getViewIndex()>0))  // current slice is not both dependent view or depth
3864  {
3865    return;
3866  }
3867#else
3868  for( UInt ui = 0; ui < getSlice()->getMaxNumMergeCand(); ++ui )
3869  {
3870    abCandIsInter[ui] = false;
3871    pcMvFieldNeighbours[ ( ui << 1 )     ].setRefIdx(NOT_VALID);
3872    pcMvFieldNeighbours[ ( ui << 1 ) + 1 ].setRefIdx(NOT_VALID);
3873  }
3874#endif
3875
3876  numValidMergeCand = getSlice()->getMaxNumMergeCand();
3877#if H_3D
3878  //////////////////////////////////
3879  //////// DERIVE LOCATIONS ////////
3880  //////////////////////////////////
3881#endif
3882  // compute the location of the current PU
3883  Int xP, yP, nPSW, nPSH;
3884  this->getPartPosition(uiPUIdx, xP, yP, nPSW, nPSH);
3885
3886  Int iCount = 0;
3887
3888  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB;
3889#if !H_3D
3890  PartSize cCurPS = getPartitionSize( uiAbsPartIdx );
3891#endif
3892  deriveLeftRightTopIdxGeneral( uiAbsPartIdx, uiPUIdx, uiPartIdxLT, uiPartIdxRT );
3893  deriveLeftBottomIdxGeneral  ( uiAbsPartIdx, uiPUIdx, uiPartIdxLB );
3894#if H_3D
3895  Bool bMPIFlag   = getSlice()->getVPS()->getMPIFlag( getSlice()->getLayerIdInVps() );
3896  Bool bIsDepth = getSlice()->getIsDepth();
3897#endif
3898
3899#if H_3D_IC
3900  Bool bICFlag = getICFlag(uiAbsPartIdx);
3901#endif
3902#if H_3D_ARP
3903  Bool bARPFlag = getARPW(uiAbsPartIdx)>0 ? true : false;
3904#endif
3905#if H_3D_DBBP
3906  Bool bDBBPFlag = getDBBPFlag(uiAbsPartIdx);
3907#endif
3908
3909#if H_3D
3910  Int  iPosLeftAbove[2] = {-1, -1};
3911
3912  Int iCountHEVC = 0;
3913  Int iCount3DV = 0;
3914  Int numA1B1B0 = 0;
3915  Int numA0B2 = 0;
3916
3917#if H_3D_NBDV
3918  for(Int i = 0; i < MRG_MAX_NUM_CANDS_MEM; i++) 
3919  {
3920    pcMvFieldNeighbours[i<<1    ].getMv().setIDVFlag (false);
3921    pcMvFieldNeighbours[(i<<1)+1].getMv().setIDVFlag (false);
3922  }
3923#endif
3924
3925  //left
3926  UInt uiLeftPartIdx = 0;
3927  TComDataCU* pcCULeft = 0;
3928  pcCULeft = getPULeft( uiLeftPartIdx, uiPartIdxLB ); 
3929  if (getAvailableFlagA1())
3930  {
3931    iPosLeftAbove[0] = numA1B1B0;
3932#if H_3D_VSP
3933    if (pcCULeft->getVSPFlag(uiLeftPartIdx) != 0
3934#if H_3D_IC
3935      && !bICFlag
3936#endif
3937#if H_3D_ARP
3938      && !bARPFlag
3939#endif
3940      )
3941    {
3942      vspFlag[numA1B1B0] = 1;
3943    }
3944#endif
3945    numA1B1B0++;
3946  }
3947
3948  // above
3949  UInt uiAbovePartIdx = 0;
3950  TComDataCU* pcCUAbove = 0;
3951  pcCUAbove = getPUAbove( uiAbovePartIdx, uiPartIdxRT );
3952  if ( getAvailableFlagB1())
3953  {
3954    iPosLeftAbove[1] = numA1B1B0;
3955#if H_3D_VSP
3956    if ( ( ( getAddr() - pcCUAbove->getAddr() ) == 0) && (pcCUAbove->getVSPFlag(uiAbovePartIdx) != 0) 
3957#if H_3D_IC
3958      && !bICFlag
3959#endif
3960#if H_3D_ARP
3961      && !bARPFlag
3962#endif
3963      )
3964    {
3965      vspFlag[numA1B1B0] = 1;
3966    }
3967#endif
3968
3969    numA1B1B0++;
3970  }
3971
3972  // above right
3973  UInt uiAboveRightPartIdx = 0;
3974  TComDataCU* pcCUAboveRight = 0;
3975  pcCUAboveRight = getPUAboveRight( uiAboveRightPartIdx, uiPartIdxRT );
3976  if ( getAvailableFlagB0())
3977  {
3978#if H_3D_VSP
3979    if ( ( ( getAddr() - pcCUAboveRight->getAddr() ) == 0) && (pcCUAboveRight->getVSPFlag(uiAboveRightPartIdx) != 0) 
3980#if H_3D_IC
3981      && !bICFlag
3982#endif
3983#if H_3D_ARP
3984      && !bARPFlag
3985#endif
3986      )
3987    {
3988      vspFlag[numA1B1B0] = 1;
3989    }
3990#endif
3991    numA1B1B0++;
3992  }
3993 
3994  // left bottom
3995  UInt uiLeftBottomPartIdx = 0;
3996  TComDataCU* pcCULeftBottom = getPUBelowLeft( uiLeftBottomPartIdx, uiPartIdxLB );
3997  if ( getAvailableFlagA0())
3998  {
3999#if H_3D_VSP
4000    if (pcCULeftBottom->getVSPFlag(uiLeftBottomPartIdx) != 0
4001#if H_3D_IC
4002      && !bICFlag
4003#endif
4004#if H_3D_ARP
4005      && !bARPFlag
4006#endif
4007      )
4008    {
4009      vspFlag[numA1B1B0] = 1;
4010    }
4011#endif
4012    iCountHEVC++;
4013    numA0B2++;
4014  }
4015 
4016  // above left
4017  UInt uiAboveLeftPartIdx = 0;
4018  TComDataCU* pcCUAboveLeft = 0;
4019  pcCUAboveLeft = getPUAboveLeft( uiAboveLeftPartIdx, uiAbsPartAddr );
4020  if (getAvailableFlagB2())
4021  {
4022#if H_3D_VSP
4023    if ( ( ( getAddr() - pcCUAboveLeft->getAddr() ) == 0) && (pcCUAboveLeft->getVSPFlag(uiAboveLeftPartIdx) != 0) 
4024#if H_3D_IC
4025      && !bICFlag
4026#endif
4027#if H_3D_ARP
4028      && !bARPFlag
4029#endif
4030      )
4031    {
4032      vspFlag[numA1B1B0+iCountHEVC] = 1;
4033    }
4034#endif
4035    iCountHEVC++;
4036    numA0B2++;
4037  }
4038
4039  iCountHEVC = numValidMergeCand;
4040#endif
4041
4042
4043#if H_3D_IV_MERGE
4044
4045  /////////////////////////////////////////////
4046  //////// TEXTURE MERGE CANDIDATE (T) ////////
4047  /////////////////////////////////////////////
4048
4049  if( bMPIFlag)
4050  {
4051    tmpMV[0].setMvField( cZeroMv, NOT_VALID );
4052    tmpMV[1].setMvField( cZeroMv, NOT_VALID );
4053    tmpDir        =  0;
4054
4055    TComPic * pcTexPic = m_pcSlice->getTexturePic();
4056#if H_3D_FCO
4057    if (pcTexturePic->getReconMark())
4058    {
4059#endif   
4060      TComPicYuv*   pcTexRec = pcTexPic->getPicYuvRec  ();
4061      UInt          uiPartAddr;
4062      Int           iWidth, iHeight;
4063      Int           iCurrPosX, iCurrPosY;
4064
4065      this->getPartIndexAndSize( uiPUIdx, uiPartAddr, iWidth, iHeight );
4066      pcTexRec->getTopLeftSamplePos( this->getAddr(), this->getZorderIdxInCU() + uiPartAddr, iCurrPosX, iCurrPosY );
4067
4068      Int iPUWidth, iPUHeight, iNumPart, iNumPartLine;
4069      this->getSPPara(iWidth, iHeight, iNumPart, iNumPartLine, iPUWidth, iPUHeight);
4070
4071      for (Int i=0; i<iNumPart; i++)
4072      {
4073        puhInterDirSP[i] = 0;
4074        pcMvFieldSP[2*i].getMv().set(0, 0);
4075        pcMvFieldSP[2*i+1].getMv().set(0, 0);
4076        pcMvFieldSP[2*i].setRefIdx(-1);
4077        pcMvFieldSP[2*i+1].setRefIdx(-1);
4078      }
4079
4080      Int         iTexCUAddr;
4081      Int         iTexAbsPartIdx;
4082      TComDataCU* pcTexCU;
4083      Int iPartition = 0;
4084      Int iInterDirSaved = 0;
4085      TComMvField cMvFieldSaved[2];
4086
4087      Int iOffsetX = iPUWidth/2;;
4088      Int iOffsetY = iPUHeight/2;
4089
4090      Int         iTexPosX, iTexPosY;
4091      const TComMv cMvRounding( 1 << ( 2 - 1 ), 1 << ( 2 - 1 ) );
4092      for (Int i=iCurrPosY; i < iCurrPosY + iHeight; i += iPUHeight)
4093      {
4094        for (Int j = iCurrPosX; j < iCurrPosX + iWidth; j += iPUWidth)
4095        {
4096          iTexPosX     = j + iOffsetX;
4097          iTexPosY     = i + iOffsetY; 
4098          pcTexRec->getCUAddrAndPartIdx( iTexPosX, iTexPosY, iTexCUAddr, iTexAbsPartIdx );
4099          pcTexCU  = pcTexPic->getCU( iTexCUAddr );
4100
4101          if( pcTexCU && !pcTexCU->isIntra(iTexAbsPartIdx) )
4102          {
4103            for( UInt uiCurrRefListId = 0; uiCurrRefListId < 2; uiCurrRefListId++ )
4104            {
4105              RefPicList  eCurrRefPicList = RefPicList( uiCurrRefListId );
4106              TComMvField cTexMvField;
4107              pcTexCU->getMvField( pcTexCU, iTexAbsPartIdx, eCurrRefPicList, cTexMvField );
4108              Int iValidDepRef = getPic()->isTextRefValid( eCurrRefPicList, cTexMvField.getRefIdx() );
4109              if( (cTexMvField.getRefIdx()>=0) && ( iValidDepRef >= 0 ) )
4110              {
4111                TComMv cMv = cTexMvField.getMv() + cMvRounding;
4112                cMv >>=2;
4113                this->clipMv( cMv );
4114                pcMvFieldSP[2*iPartition + uiCurrRefListId].setMvField(cMv, iValidDepRef);
4115              }
4116            }
4117          }
4118          puhInterDirSP[iPartition] = (pcMvFieldSP[2*iPartition].getRefIdx()!=-1 ? 1: 0) + (pcMvFieldSP[2*iPartition+1].getRefIdx()!=-1 ? 2: 0);
4119          if (puhInterDirSP[iPartition] == 0)
4120          {
4121            if (iInterDirSaved != 0)
4122            {
4123              puhInterDirSP[iPartition] = iInterDirSaved;
4124              pcMvFieldSP[2*iPartition] = cMvFieldSaved[0];
4125              pcMvFieldSP[2*iPartition + 1] = cMvFieldSaved[1];
4126            }
4127          }
4128          else
4129          {
4130            if (iInterDirSaved ==0)
4131            {
4132              pbSPIVMPFlag[iCount] = true;
4133              tmpDir = puhInterDirSP[iPartition];
4134              tmpMV[0] = pcMvFieldSP[2*iPartition];
4135              tmpMV[1] = pcMvFieldSP[2*iPartition+1];
4136
4137              if (iPartition != 0)
4138              {
4139                for (Int iPart = iPartition-1; iPart >= 0; iPart--)
4140                {
4141                  puhInterDirSP[iPart] = puhInterDirSP[iPartition];
4142                  pcMvFieldSP[2*iPart] = pcMvFieldSP[2*iPartition];
4143                  pcMvFieldSP[2*iPart + 1] = pcMvFieldSP[2*iPartition + 1];
4144                }
4145              }
4146            }
4147            iInterDirSaved = puhInterDirSP[iPartition];
4148            cMvFieldSaved[0] = pcMvFieldSP[2*iPartition];
4149            cMvFieldSaved[1] = pcMvFieldSP[2*iPartition + 1];
4150          }
4151          iPartition ++;
4152        }
4153      }
4154#if H_3D_FCO
4155    }
4156#endif
4157    if( tmpDir != 0 )
4158    {
4159      Int iCnloop = 0;
4160      Bool bRemoveSpa = false; //pruning
4161
4162      for(Int i = 0; i < 2; i ++)
4163      {
4164        iCnloop = iPosLeftAbove[i];
4165        if ( iCnloop == -1 ) 
4166        {
4167          continue;
4168        }
4169        if(tmpDir == puhInterDirNeighbours[iCnloop] && tmpMV[0]==pcMvFieldNeighbours[(iCnloop<<1)] && tmpMV[1]==pcMvFieldNeighbours[(iCnloop<<1)+1])
4170        {
4171          bRemoveSpa                      = true;
4172          break;
4173        }     
4174      }
4175
4176      if (!bRemoveSpa)
4177      {
4178        rightShiftMergeCandList( pcMvFieldNeighbours, puhInterDirNeighbours, vspFlag, inheritedVSPDisInfo, iCount, 5-iCount, iCount3DV);
4179      }
4180      else
4181      {
4182        rightShiftMergeCandList( pcMvFieldNeighbours, puhInterDirNeighbours, vspFlag, inheritedVSPDisInfo, iCount, (iCnloop-iCount), iCount3DV);
4183        if (iCnloop<numA1B1B0)
4184        {
4185          numA1B1B0--;
4186        }
4187        iCountHEVC--;
4188
4189        if (iPosLeftAbove[0] != -1)
4190        {
4191          if (iCnloop == iPosLeftAbove[0])
4192          {
4193            iPosLeftAbove[0] = -1;
4194          }
4195          else
4196          {
4197            iPosLeftAbove[0]++;
4198          }
4199        }
4200        if (iPosLeftAbove[1] != -1)
4201        {
4202          if (iCnloop == iPosLeftAbove[1])
4203          {
4204            iPosLeftAbove[1] = -1;
4205          }
4206          else
4207          {
4208            if (iCnloop > iPosLeftAbove[1])
4209            {
4210              iPosLeftAbove[1]++;
4211            }
4212          }
4213        }
4214      }
4215      pcMvFieldNeighbours[iCount<<1].setMvField(tmpMV[0].getMv(), tmpMV[0].getRefIdx());
4216      pcMvFieldNeighbours[(iCount<<1)+1].setMvField(tmpMV[1].getMv(), tmpMV[1].getRefIdx());
4217
4218      puhInterDirNeighbours[iCount] = tmpDir;
4219
4220      if ( mrgCandIdx == iCount )
4221      {
4222        return;
4223      }
4224      iCount ++;
4225    }
4226  }
4227#if MTK_DDD_G0063
4228  if( m_pcSlice->getIsDepth() && m_pcSlice->getViewIndex() != 0  && bMPIFlag )
4229  {
4230      UInt uiPartIdx;
4231      TComDataCU *pcTextureCU = m_pcSlice->getTexturePic()->getCU( getAddr() );
4232      TComSlice *pcTextureSlice = pcTextureCU->getSlice(); 
4233
4234
4235      tmpMV[0].setMvField( cZeroMv, NOT_VALID );
4236      tmpMV[1].setMvField( cZeroMv, NOT_VALID );
4237      tmpDir = 0;
4238
4239      xDeriveCenterIdx( uiPUIdx, uiPartIdx); 
4240
4241      if ( pcTextureCU && !pcTextureCU->isIntra( uiPartIdx ) )
4242      {
4243
4244          TComMvField cMVField;
4245#if !HTM10RC1_FIX
4246          UChar ucInterDir = pcTextureCU->getInterDir( uiPartIdx );
4247#endif
4248          Int iDV = 0;
4249          Int iViewIdx = 0;
4250#if !HTM10RC1_FIX
4251          if( ucInterDir & 1 )
4252          {
4253#endif
4254              pcTextureCU->getMvField( pcTextureCU, uiPartIdx, REF_PIC_LIST_0, cMVField );
4255#if HTM10RC1_FIX
4256              if( cMVField.getRefIdx() >= 0 )
4257              {
4258#endif
4259              if( pcTextureSlice->getRefPOC( REF_PIC_LIST_0, cMVField.getRefIdx()) == pcTextureSlice->getPOC() )
4260              {
4261                  iViewIdx = pcTextureSlice->getRefPic( REF_PIC_LIST_0, cMVField.getRefIdx())->getViewIndex();
4262                  iDV = cMVField.getHor();
4263
4264
4265                  Int iValidDepRef = getPic()->isTextRefValid( REF_PIC_LIST_0, cMVField.getRefIdx() );
4266
4267                  if( iValidDepRef >= 0 )
4268                  {
4269                      const TComMv cAdd( 2, 2 );
4270                      cMVField.getMv() += cAdd;
4271                      cMVField.getMv() >>= 2;
4272                      clipMv( cMVField.getMv() );
4273                      tmpMV[ 0 ].setMvField( cMVField.getMv(), iValidDepRef );
4274                      tmpDir = 1;
4275                  }
4276              }
4277          }
4278
4279#if !HTM10RC1_FIX
4280          if( !tmpDir && ( ucInterDir & 2 ))
4281          {
4282#endif
4283              pcTextureCU->getMvField( pcTextureCU, uiPartIdx, REF_PIC_LIST_1, cMVField );
4284
4285#if HTM10RC1_FIX
4286              if( !tmpDir && cMVField.getRefIdx() >= 0 )
4287              {
4288#endif
4289              if( pcTextureSlice->getRefPOC( REF_PIC_LIST_1, cMVField.getRefIdx()) == pcTextureSlice->getPOC() )
4290              {
4291                  iViewIdx = pcTextureSlice->getRefPic( REF_PIC_LIST_1, cMVField.getRefIdx())->getViewIndex();
4292                  iDV = cMVField.getHor();
4293
4294                  Int iValidDepRef = getPic()->isTextRefValid( REF_PIC_LIST_1, cMVField.getRefIdx() );
4295
4296                  if( iValidDepRef >= 0 )
4297                  {
4298                      const TComMv cAdd( 2, 2 );
4299                      cMVField.getMv() += cAdd;
4300                      cMVField.getMv() >>= 2;
4301                      clipMv( cMVField.getMv() );
4302                      tmpMV[ 1 ].setMvField( cMVField.getMv(), iValidDepRef );
4303                      tmpDir = 2;
4304                  }
4305              }
4306          }
4307          if( tmpDir != 0 )
4308          {
4309              rightShiftMergeCandList( pcMvFieldNeighbours, puhInterDirNeighbours, vspFlag, inheritedVSPDisInfo, iCount, 5-iCount, iCount3DV);
4310              m_ucDDTmpDepth = m_pcSlice->getDepthFromDV( iDV,  iViewIdx );
4311              m_iUseDDDCandIdx = iCount;
4312
4313              if( tmpDir == 1 )
4314              {
4315                  pcMvFieldNeighbours[ iCount << 1 ] = tmpMV[ 0 ];
4316              }
4317              else if( tmpDir == 2  )
4318              {
4319                  pcMvFieldNeighbours[( iCount << 1 ) + 1 ] = tmpMV[ 1 ];
4320              }
4321
4322              abCandIsInter        [ iCount ] = true;
4323              puhInterDirNeighbours[ iCount ] = tmpDir;
4324
4325              if ( mrgCandIdx == iCount )
4326              {
4327                  return;
4328              }
4329              iCount ++;
4330
4331              Int iLeftAboveAvail = 0;
4332              if( iPosLeftAbove[ 0 ] != -1 )
4333              {
4334                  iPosLeftAbove[ 0 ] = iCount;
4335                  iLeftAboveAvail = 1;
4336              }
4337              if( iPosLeftAbove[ 1 ] != -1 )
4338              {
4339                  iPosLeftAbove[ 1 ] = iCount + iLeftAboveAvail;
4340              }
4341
4342          }
4343      }     
4344
4345  }
4346#endif
4347  /////////////////////////////////////////////////////////////////
4348  //////// DERIVE IvMC, IvMCShift,IvDCShift, IvDC  Candidates /////
4349  /////////////////////////////////////////////////////////////////
4350
4351  Int  posIvDC          = -1;
4352
4353  // { IvMCL0, IvMCL1, IvDCL0, IvDCL1, IvMCL0Shift, IvMCL1Shift, IvDCL0Shift, IvDCL1Shift }; 
4354  // An enumerator would be appropriate here!
4355  TComMv ivCandMv    [8];
4356  Int    ivCandRefIdx[8] = {-1, -1, -1, -1, -1, -1, -1, -1};
4357
4358  // { IvMC, IvDC, IvMCShift, IvDCShift }; 
4359  Int    ivCandDir   [4] = {0, 0, 0, 0};
4360
4361  Bool ivMvPredFlag   = getSlice()->getVPS()->getIvMvPredFlag( getSlice()->getLayerIdInVps() );
4362
4363  if ( ivMvPredFlag && cDisInfo.m_aVIdxCan!=-1)
4364  {
4365    getInterViewMergeCands(uiPUIdx, ivCandRefIdx, ivCandMv, &cDisInfo, ivCandDir , bIsDepth, pcMvFieldSP, puhInterDirSP );
4366  } 
4367
4368  ///////////////////////////////////////////////
4369  //////// INTER VIEW MOTION COMP(IvMC) /////////
4370  ///////////////////////////////////////////////
4371  if( getSlice()->getIsDepth() )
4372  {
4373    ivCandDir[1] = ivCandDir[2] = ivCandDir[3] = 0;
4374  }
4375
4376  if( ivCandDir[0] )
4377  {
4378    tmpMV[0].setMvField( cZeroMv, NOT_VALID );
4379    tmpMV[1].setMvField( cZeroMv, NOT_VALID );
4380
4381    if( ( ivCandDir[0] & 1 ) == 1 )
4382    {
4383      tmpMV[0].setMvField( ivCandMv[ 0 ], ivCandRefIdx[ 0 ] );
4384    }
4385    if( ( ivCandDir[0] & 2 ) == 2 )
4386    {
4387      tmpMV[1].setMvField( ivCandMv[ 1 ], ivCandRefIdx[ 1 ] );
4388    }
4389
4390    Bool bRemoveSpa = false; //pruning
4391    Bool bIvMC = false;
4392    Int iCnloop=0;
4393
4394    if (!bIsDepth)
4395    {
4396      for(Int i = 0; i < 2; i ++)
4397      {
4398        iCnloop = iPosLeftAbove[i];
4399        if ( iCnloop == -1 ) 
4400        {
4401          continue;
4402        }
4403        if(ivCandDir[0] == puhInterDirNeighbours[iCnloop] && tmpMV[0]==pcMvFieldNeighbours[(iCnloop<<1)] && tmpMV[1]==pcMvFieldNeighbours[(iCnloop<<1)+1])
4404        {
4405          bRemoveSpa                      = true;
4406          break;
4407        }     
4408      }
4409    }
4410    if (bIsDepth)
4411    {
4412      iCnloop = iCount-1;
4413      for(; iCnloop >= 0; iCnloop --)
4414      {
4415#if MTK_DDD_G0063
4416          if( iCnloop == m_iUseDDDCandIdx )
4417          {
4418              continue;
4419          }
4420#endif
4421        if(ivCandDir[0] == puhInterDirNeighbours[iCnloop] && pcMvFieldNeighbours[iCnloop<<1]==tmpMV[0] && pcMvFieldNeighbours[(iCnloop<<1)+1]==tmpMV[1])  // F0125 compatible with F0093
4422        {
4423          bRemoveSpa                      = true;
4424          break;
4425        }
4426      }
4427    }
4428
4429    if (!bRemoveSpa)
4430    {
4431      bIvMC = true;
4432      rightShiftMergeCandList( pcMvFieldNeighbours, puhInterDirNeighbours, vspFlag, inheritedVSPDisInfo, iCount, (5-iCount), iCount3DV);
4433
4434      if (iPosLeftAbove[0] != -1)
4435      {
4436        iPosLeftAbove[0]++;
4437      }
4438      if (iPosLeftAbove[1] != -1)
4439      {
4440        iPosLeftAbove[1]++;
4441      }
4442    }
4443    else if (bRemoveSpa && !bIsDepth)
4444    {
4445      bIvMC = true;
4446      rightShiftMergeCandList( pcMvFieldNeighbours, puhInterDirNeighbours, vspFlag, inheritedVSPDisInfo, iCount, (iCnloop-iCount), iCount3DV);
4447
4448      if (iCnloop<numA1B1B0)
4449      {
4450        numA1B1B0--;
4451      }
4452      iCountHEVC--;
4453
4454      if (iPosLeftAbove[0] != -1)
4455      {
4456        if (iCnloop == iPosLeftAbove[0])
4457        {
4458          iPosLeftAbove[0] = -1;
4459        }
4460        else
4461        {
4462          iPosLeftAbove[0]++;
4463        }
4464      }
4465      if (iPosLeftAbove[1] != -1)
4466      {
4467        if (iCnloop == iPosLeftAbove[1])
4468        {
4469          iPosLeftAbove[1] = -1;
4470        }
4471        else
4472        {
4473          if (iCnloop > iPosLeftAbove[1])
4474          {
4475            iPosLeftAbove[1]++;
4476          }
4477        }
4478      }
4479    }
4480
4481    if (bIvMC)
4482    {
4483      if(!m_pcSlice->getIsDepth() && getPartitionSize(0) == SIZE_2Nx2N )
4484      {
4485          pbSPIVMPFlag[iCount] = true;
4486      }
4487#if H_3D_DBBP
4488      pbSPIVMPFlag[iCount] &= !bDBBPFlag;
4489#endif
4490      if( ( ivCandDir[0] & 1 ) == 1 )
4491      {
4492        pcMvFieldNeighbours[iCount<<1].setMvField( ivCandMv[ 0 ], ivCandRefIdx[ 0 ] );
4493      }
4494      if( ( ivCandDir[0] & 2 ) == 2 )
4495      {
4496        pcMvFieldNeighbours[(iCount<<1)+1].setMvField( ivCandMv[ 1 ], ivCandRefIdx[ 1 ] );
4497      }
4498
4499      puhInterDirNeighbours[ iCount ] = ivCandDir[0];
4500
4501      if ( mrgCandIdx == iCount )
4502      {
4503        return;
4504      }
4505      iCount ++;
4506    }
4507  } 
4508
4509  // early termination
4510  if (iCount == getSlice()->getMaxNumMergeCand()) 
4511  {
4512    return;
4513  }
4514#endif
4515
4516#if H_3D
4517  iCount += numA1B1B0;
4518#else
4519  //left
4520  UInt uiLeftPartIdx = 0;
4521  TComDataCU* pcCULeft = 0;
4522  pcCULeft = getPULeft( uiLeftPartIdx, uiPartIdxLB );
4523  Bool isAvailableA1 = pcCULeft &&
4524    pcCULeft->isDiffMER(xP -1, yP+nPSH-1, xP, yP) &&
4525    !( uiPUIdx == 1 && (cCurPS == SIZE_Nx2N || cCurPS == SIZE_nLx2N || cCurPS == SIZE_nRx2N) ) &&
4526    !pcCULeft->isIntra( uiLeftPartIdx ) ;
4527  if ( isAvailableA1 )
4528  {
4529    abCandIsInter[iCount] = true;
4530    // get Inter Dir
4531    puhInterDirNeighbours[iCount] = pcCULeft->getInterDir( uiLeftPartIdx );
4532    // get Mv from Left
4533    pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
4534    if ( getSlice()->isInterB() )
4535    {
4536      pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
4537    }
4538
4539    if ( mrgCandIdx == iCount )
4540    {
4541      return;
4542    }
4543    iCount ++;
4544  }
4545
4546  // early termination
4547  if (iCount == getSlice()->getMaxNumMergeCand()) 
4548  {
4549    return;
4550  }
4551
4552  // above
4553  UInt uiAbovePartIdx = 0;
4554  TComDataCU* pcCUAbove = 0;
4555  pcCUAbove = getPUAbove( uiAbovePartIdx, uiPartIdxRT );
4556  Bool isAvailableB1 = pcCUAbove &&
4557    pcCUAbove->isDiffMER(xP+nPSW-1, yP-1, xP, yP) &&
4558    !( uiPUIdx == 1 && (cCurPS == SIZE_2NxN || cCurPS == SIZE_2NxnU || cCurPS == SIZE_2NxnD) ) &&
4559    !pcCUAbove->isIntra( uiAbovePartIdx );
4560  if ( isAvailableB1 && (!isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAbove, uiAbovePartIdx ) ) )
4561  {
4562    abCandIsInter[iCount] = true;
4563    // get Inter Dir
4564    puhInterDirNeighbours[iCount] = pcCUAbove->getInterDir( uiAbovePartIdx );
4565    // get Mv from Left
4566    pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
4567    if ( getSlice()->isInterB() )
4568    {
4569      pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
4570    }
4571
4572    if ( mrgCandIdx == iCount )
4573    {
4574      return;
4575    }
4576    iCount ++;
4577  }
4578  // early termination
4579  if (iCount == getSlice()->getMaxNumMergeCand()) 
4580  {
4581    return;
4582  }
4583
4584  // above right
4585  UInt uiAboveRightPartIdx = 0;
4586  TComDataCU* pcCUAboveRight = 0;
4587  pcCUAboveRight = getPUAboveRight( uiAboveRightPartIdx, uiPartIdxRT );
4588  Bool isAvailableB0 = pcCUAboveRight &&
4589    pcCUAboveRight->isDiffMER(xP+nPSW, yP-1, xP, yP) &&
4590    !pcCUAboveRight->isIntra( uiAboveRightPartIdx );
4591  if ( isAvailableB0 && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveRight, uiAboveRightPartIdx ) ) )
4592  {
4593    abCandIsInter[iCount] = true;
4594    // get Inter Dir
4595    puhInterDirNeighbours[iCount] = pcCUAboveRight->getInterDir( uiAboveRightPartIdx );
4596    // get Mv from Left
4597    pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
4598    if ( getSlice()->isInterB() )
4599    {
4600      pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
4601    }
4602
4603    if ( mrgCandIdx == iCount )
4604    {
4605      return;
4606    }
4607    iCount ++;
4608  }
4609  // early termination
4610  if (iCount == getSlice()->getMaxNumMergeCand()) 
4611  {
4612    return;
4613  }
4614#endif
4615
4616#if MTK_DDD_G0063
4617  // early termination
4618  if ( iCount >= getSlice()->getMaxNumMergeCand()) 
4619  {
4620      return;
4621  }
4622#endif
4623
4624#if H_3D_IV_MERGE
4625  /////////////////////////////////////////////
4626  //////// INTER VIEW DISP COMP (IvDC) ////////
4627  /////////////////////////////////////////////
4628  if( ivCandDir[1] && iCount < getSlice()->getMaxNumMergeCand() && !getSlice()->getIsDepth() )
4629  {
4630    assert(iCount < getSlice()->getMaxNumMergeCand());
4631
4632    tmpMV[0].setMvField( cZeroMv, NOT_VALID );
4633    tmpMV[1].setMvField( cZeroMv, NOT_VALID );
4634    if( ( ivCandDir[1] & 1 ) == 1 )
4635    {
4636      tmpMV[0].setMvField( ivCandMv[ 2 ], ivCandRefIdx[ 2 ] );
4637    }
4638    if( ( ivCandDir[1] & 2 ) == 2 )
4639    {
4640      tmpMV[1].setMvField( ivCandMv[ 3 ], ivCandRefIdx[ 3 ] );
4641    }
4642
4643    Bool bRemoveSpa = false; //pruning to A1, B1
4644    for(Int i = 0; i < 2; i ++)
4645    {
4646      Int iCnloop = iPosLeftAbove[i];
4647      if ( iCnloop == -1 ) 
4648      {
4649        continue;
4650      }
4651      if(puhInterDirNeighbours[iCount] == puhInterDirNeighbours[iCnloop] && pcMvFieldNeighbours[iCnloop<<1]==pcMvFieldNeighbours[(iCount<<1)] && pcMvFieldNeighbours[(iCnloop<<1)+1]==pcMvFieldNeighbours[(iCount<<1)+1])
4652      {
4653        bRemoveSpa                      = true;
4654        break;
4655      }     
4656    }
4657    if(!bRemoveSpa)
4658    {
4659      rightShiftMergeCandList( pcMvFieldNeighbours, puhInterDirNeighbours, vspFlag, inheritedVSPDisInfo, iCount, (5-iCount), iCount3DV);
4660      puhInterDirNeighbours[ iCount ] = ivCandDir[1];
4661      if( ( ivCandDir[1] & 1 ) == 1 )
4662      {
4663        pcMvFieldNeighbours[ iCount<<1    ].setMvField( ivCandMv[ 2 ], ivCandRefIdx[ 2 ] );
4664      }
4665      if( ( ivCandDir[1] & 2 ) == 2 )
4666      {
4667        pcMvFieldNeighbours[(iCount<<1)+1 ].setMvField( ivCandMv[ 3 ], ivCandRefIdx[ 3 ] );
4668      }
4669#if H_3D_NBDV
4670      pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
4671      pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
4672#endif
4673      posIvDC  = iCount;
4674      if ( mrgCandIdx == iCount )
4675        return;
4676      iCount ++;
4677
4678      // early termination
4679      if (iCount == getSlice()->getMaxNumMergeCand()) 
4680      {
4681        return;
4682      }
4683    }
4684  } 
4685#endif // H_3D_IV_MERGE
4686
4687#if H_3D_VSP
4688  /////////////////////////////////////////////////
4689  //////// VIEW SYNTHESIS PREDICTION (VSP) ////////
4690  /////////////////////////////////////////////////
4691  if (iCount<getSlice()->getMaxNumMergeCand())
4692  {
4693
4694  if (
4695#if H_3D_IC
4696      !bICFlag &&
4697#endif
4698#if H_3D_ARP
4699      !bARPFlag &&
4700#endif
4701      xAddVspCand( mrgCandIdx, &cDisInfo, iCount, abCandIsInter, pcMvFieldNeighbours, puhInterDirNeighbours, vspFlag, iCount3DV, inheritedVSPDisInfo ) )
4702  {
4703    return;
4704  }
4705
4706  // early termination
4707  if (iCount == getSlice()->getMaxNumMergeCand())
4708  {
4709    return;
4710  }
4711#endif
4712#if H_3D
4713  }
4714#endif
4715
4716#if H_3D
4717  iCount += numA0B2;
4718#else
4719  //left bottom
4720  UInt uiLeftBottomPartIdx = 0;
4721  TComDataCU* pcCULeftBottom = 0;
4722  pcCULeftBottom = this->getPUBelowLeft( uiLeftBottomPartIdx, uiPartIdxLB );
4723  Bool isAvailableA0 = pcCULeftBottom &&
4724  pcCULeftBottom->isDiffMER(xP-1, yP+nPSH, xP, yP) &&
4725  !pcCULeftBottom->isIntra( uiLeftBottomPartIdx ) ;
4726  if ( isAvailableA0 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCULeftBottom, uiLeftBottomPartIdx ) ) )
4727  {
4728    abCandIsInter[iCount] = true;
4729    // get Inter Dir
4730    puhInterDirNeighbours[iCount] = pcCULeftBottom->getInterDir( uiLeftBottomPartIdx );
4731    // get Mv from Left
4732    pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
4733    if ( getSlice()->isInterB() )
4734    {
4735      pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
4736    }
4737    if ( mrgCandIdx == iCount )
4738    {
4739      return;
4740    }
4741    iCount ++;
4742  }
4743  // early termination
4744  if (iCount == getSlice()->getMaxNumMergeCand()) 
4745  {
4746    return;
4747  }
4748
4749  // above left
4750  if( iCount < 4 )
4751  {
4752    UInt uiAboveLeftPartIdx = 0;
4753    TComDataCU* pcCUAboveLeft = 0;
4754    pcCUAboveLeft = getPUAboveLeft( uiAboveLeftPartIdx, uiAbsPartAddr );
4755    Bool isAvailableB2 = pcCUAboveLeft &&
4756    pcCUAboveLeft->isDiffMER(xP-1, yP-1, xP, yP) &&
4757    !pcCUAboveLeft->isIntra( uiAboveLeftPartIdx );
4758    if ( isAvailableB2 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) )
4759        && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) ) )
4760    {
4761      abCandIsInter[iCount] = true;
4762      // get Inter Dir
4763      puhInterDirNeighbours[iCount] = pcCUAboveLeft->getInterDir( uiAboveLeftPartIdx );
4764      // get Mv from Left
4765      pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
4766      if ( getSlice()->isInterB() )
4767      {
4768        pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
4769      }
4770      if ( mrgCandIdx == iCount )
4771      {
4772        return;
4773      }
4774      iCount ++;
4775    }
4776  }
4777  // early termination
4778  if (iCount == getSlice()->getMaxNumMergeCand()) 
4779  {
4780    return;
4781  }
4782#endif
4783
4784
4785#if H_3D_IV_MERGE
4786  ////////////////////////////////////////////////////
4787  //////// SHIFTED IV (IvMCShift + IvDCShift) ////////
4788  ////////////////////////////////////////////////////
4789  if(  ivMvPredFlag && iCount < getSlice()->getMaxNumMergeCand() && !getSlice()->getIsDepth() ) 
4790  {
4791    if(xAddIvMRGCand( mrgCandIdx,  iCount, abCandIsInter, pcMvFieldNeighbours, puhInterDirNeighbours, ivCandDir, ivCandMv, ivCandRefIdx, posIvDC, vspFlag, iCount3DV, inheritedVSPDisInfo ) )
4792    {
4793      return;
4794    }
4795    //early termination
4796    if (iCount == getSlice()->getMaxNumMergeCand()) 
4797    {
4798      return;
4799    }
4800  }
4801#endif
4802
4803#if H_3D
4804  if (iCountHEVC + iCount3DV > getSlice()->getMaxNumMergeCand())
4805  {
4806    iCount = getSlice()->getMaxNumMergeCand();
4807  }
4808  else
4809  {
4810    iCount = iCountHEVC + iCount3DV;
4811  }
4812  numValidMergeCand = iCount;
4813#else
4814  if ( getSlice()->getEnableTMVPFlag())
4815  {
4816    //>> MTK colocated-RightBottom
4817    UInt uiPartIdxRB;
4818
4819    deriveRightBottomIdx( uiPUIdx, uiPartIdxRB ); 
4820
4821    UInt uiAbsPartIdxTmp = g_auiZscanToRaster[uiPartIdxRB];
4822    UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
4823
4824    TComMv cColMv;
4825    Int iRefIdx;
4826    Int uiLCUIdx = -1;
4827
4828    if      ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
4829    {
4830    }
4831    else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxTmp] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
4832    {
4833    }
4834    else
4835    {
4836      if ( ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
4837        ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
4838      {
4839        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + uiNumPartInCUWidth + 1 ];
4840        uiLCUIdx = getAddr();
4841      }
4842      else if ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
4843      {
4844        uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdxTmp + uiNumPartInCUWidth + 1) % m_pcPic->getNumPartInCU() ];
4845      }
4846      else if ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
4847      {
4848        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + 1 ];
4849        uiLCUIdx = getAddr() + 1;
4850      }
4851      else //is the right bottom corner of LCU                       
4852      {
4853        uiAbsPartAddr = 0;
4854      }
4855    }
4856   
4857   
4858    iRefIdx = 0;
4859    Bool bExistMV = false;
4860    UInt uiPartIdxCenter;
4861    UInt uiCurLCUIdx = getAddr();
4862    Int dir = 0;
4863    UInt uiArrayAddr = iCount;
4864    xDeriveCenterIdx( uiPUIdx, uiPartIdxCenter );
4865    bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_0, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx );
4866    if( bExistMV == false )
4867    {
4868      bExistMV = xGetColMVP( REF_PIC_LIST_0, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
4869    }
4870    if( bExistMV )
4871    {
4872      dir |= 1;
4873      pcMvFieldNeighbours[ 2 * uiArrayAddr ].setMvField( cColMv, iRefIdx );
4874    }
4875
4876    if ( getSlice()->isInterB() )
4877    {
4878      bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_1, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx);
4879      if( bExistMV == false )
4880      {
4881        bExistMV = xGetColMVP( REF_PIC_LIST_1, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
4882      }
4883      if( bExistMV )
4884      {
4885        dir |= 2;
4886        pcMvFieldNeighbours[ 2 * uiArrayAddr + 1 ].setMvField( cColMv, iRefIdx );
4887      }
4888    }
4889   
4890    if (dir != 0)
4891    {
4892      puhInterDirNeighbours[uiArrayAddr] = dir;
4893      abCandIsInter[uiArrayAddr] = true;
4894      if ( mrgCandIdx == iCount )
4895      {
4896        return;
4897      }
4898      iCount++;
4899    }
4900  }
4901  // early termination
4902  if (iCount == getSlice()->getMaxNumMergeCand()) 
4903  {
4904    return;
4905  }
4906  UInt uiArrayAddr = iCount;
4907  UInt uiCutoff = uiArrayAddr;
4908   
4909  if ( getSlice()->isInterB())
4910  {
4911    UInt uiPriorityList0[12] = {0 , 1, 0, 2, 1, 2, 0, 3, 1, 3, 2, 3};
4912    UInt uiPriorityList1[12] = {1 , 0, 2, 0, 2, 1, 3, 0, 3, 1, 3, 2};
4913
4914    for (Int idx=0; idx<uiCutoff*(uiCutoff-1) && uiArrayAddr!= getSlice()->getMaxNumMergeCand(); idx++)
4915    {
4916      Int i = uiPriorityList0[idx]; Int j = uiPriorityList1[idx];
4917      if (abCandIsInter[i] && abCandIsInter[j]&& (puhInterDirNeighbours[i]&0x1)&&(puhInterDirNeighbours[j]&0x2))
4918      {
4919        abCandIsInter[uiArrayAddr] = true;
4920        puhInterDirNeighbours[uiArrayAddr] = 3;
4921
4922        // get Mv from cand[i] and cand[j]
4923        pcMvFieldNeighbours[uiArrayAddr << 1].setMvField(pcMvFieldNeighbours[i<<1].getMv(), pcMvFieldNeighbours[i<<1].getRefIdx());
4924        pcMvFieldNeighbours[( uiArrayAddr << 1 ) + 1].setMvField(pcMvFieldNeighbours[(j<<1)+1].getMv(), pcMvFieldNeighbours[(j<<1)+1].getRefIdx());
4925
4926        Int iRefPOCL0 = m_pcSlice->getRefPOC( REF_PIC_LIST_0, pcMvFieldNeighbours[(uiArrayAddr<<1)].getRefIdx() );
4927        Int iRefPOCL1 = m_pcSlice->getRefPOC( REF_PIC_LIST_1, pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getRefIdx() );
4928        if (iRefPOCL0 == iRefPOCL1 && pcMvFieldNeighbours[(uiArrayAddr<<1)].getMv() == pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getMv())
4929        {
4930          abCandIsInter[uiArrayAddr] = false;
4931        }
4932        else
4933        {
4934          uiArrayAddr++;
4935        }
4936      }
4937    }
4938  }
4939  // early termination
4940  if (uiArrayAddr == getSlice()->getMaxNumMergeCand()) 
4941  {
4942    return;
4943  }
4944  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);
4945  Int r = 0;
4946  Int refcnt = 0;
4947  while (uiArrayAddr < getSlice()->getMaxNumMergeCand())
4948  {
4949    abCandIsInter[uiArrayAddr] = true;
4950    puhInterDirNeighbours[uiArrayAddr] = 1;
4951    pcMvFieldNeighbours[uiArrayAddr << 1].setMvField( TComMv(0, 0), r);
4952
4953    if ( getSlice()->isInterB() )
4954    {
4955      puhInterDirNeighbours[uiArrayAddr] = 3;
4956      pcMvFieldNeighbours[(uiArrayAddr << 1) + 1].setMvField(TComMv(0, 0), r);
4957    }
4958    uiArrayAddr++;
4959    if ( refcnt == iNumRefIdx - 1 )
4960    {
4961      r = 0;
4962    }
4963    else
4964    {
4965      ++r;
4966      ++refcnt;
4967    }
4968  }
4969
4970  numValidMergeCand = uiArrayAddr;
4971#endif
4972}
4973#else
4974
4975/** Constructs a list of merging candidates
4976 * \param uiAbsPartIdx
4977 * \param uiPUIdx
4978 * \param uiDepth
4979 * \param pcMvFieldNeighbours
4980 * \param puhInterDirNeighbours
4981 * \param numValidMergeCand
4982 */
4983Void TComDataCU::getInterMergeCandidates( UInt uiAbsPartIdx, UInt uiPUIdx, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours
4984      , Int& numValidMergeCand, Int mrgCandIdx
4985)
4986{
4987  UInt uiAbsPartAddr = m_uiAbsIdxInLCU + uiAbsPartIdx;
4988  Bool abCandIsInter[ MRG_MAX_NUM_CANDS ];
4989  for( UInt ui = 0; ui < getSlice()->getMaxNumMergeCand(); ++ui )
4990  {
4991    abCandIsInter[ui] = false;
4992    pcMvFieldNeighbours[ ( ui << 1 )     ].setRefIdx(NOT_VALID);
4993    pcMvFieldNeighbours[ ( ui << 1 ) + 1 ].setRefIdx(NOT_VALID);
4994  }
4995  numValidMergeCand = getSlice()->getMaxNumMergeCand();
4996  // compute the location of the current PU
4997  Int xP, yP, nPSW, nPSH;
4998  this->getPartPosition(uiPUIdx, xP, yP, nPSW, nPSH);
4999
5000  Int iCount = 0;
5001
5002  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB;
5003  PartSize cCurPS = getPartitionSize( uiAbsPartIdx );
5004  deriveLeftRightTopIdxGeneral( uiAbsPartIdx, uiPUIdx, uiPartIdxLT, uiPartIdxRT );
5005  deriveLeftBottomIdxGeneral  ( uiAbsPartIdx, uiPUIdx, uiPartIdxLB );
5006
5007  //left
5008  UInt uiLeftPartIdx = 0;
5009  TComDataCU* pcCULeft = 0;
5010  pcCULeft = getPULeft( uiLeftPartIdx, uiPartIdxLB );
5011  Bool isAvailableA1 = pcCULeft &&
5012  pcCULeft->isDiffMER(xP -1, yP+nPSH-1, xP, yP) &&
5013  !( uiPUIdx == 1 && (cCurPS == SIZE_Nx2N || cCurPS == SIZE_nLx2N || cCurPS == SIZE_nRx2N) ) &&
5014  !pcCULeft->isIntra( uiLeftPartIdx ) ;
5015  if ( isAvailableA1 )
5016  {
5017    abCandIsInter[iCount] = true;
5018    // get Inter Dir
5019    puhInterDirNeighbours[iCount] = pcCULeft->getInterDir( uiLeftPartIdx );
5020    // get Mv from Left
5021    pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
5022    if ( getSlice()->isInterB() )
5023    {
5024      pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
5025    }
5026    if ( mrgCandIdx == iCount )
5027    {
5028      return;
5029    }
5030    iCount ++;
5031  }
5032 
5033  // early termination
5034  if (iCount == getSlice()->getMaxNumMergeCand()) 
5035  {
5036    return;
5037  }
5038
5039  // above
5040  UInt uiAbovePartIdx = 0;
5041  TComDataCU* pcCUAbove = 0;
5042  pcCUAbove = getPUAbove( uiAbovePartIdx, uiPartIdxRT );
5043  Bool isAvailableB1 = pcCUAbove &&
5044  pcCUAbove->isDiffMER(xP+nPSW-1, yP-1, xP, yP) &&
5045  !( uiPUIdx == 1 && (cCurPS == SIZE_2NxN || cCurPS == SIZE_2NxnU || cCurPS == SIZE_2NxnD) ) &&
5046  !pcCUAbove->isIntra( uiAbovePartIdx );
5047  if ( isAvailableB1 && (!isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAbove, uiAbovePartIdx ) ) )
5048  {
5049    abCandIsInter[iCount] = true;
5050    // get Inter Dir
5051    puhInterDirNeighbours[iCount] = pcCUAbove->getInterDir( uiAbovePartIdx );
5052    // get Mv from Left
5053    pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
5054    if ( getSlice()->isInterB() )
5055    {
5056      pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
5057    }
5058
5059    if ( mrgCandIdx == iCount )
5060    {
5061      return;
5062    }
5063    iCount ++;
5064  }
5065  // early termination
5066  if (iCount == getSlice()->getMaxNumMergeCand()) 
5067  {
5068    return;
5069  }
5070
5071
5072  // above right
5073  UInt uiAboveRightPartIdx = 0;
5074  TComDataCU* pcCUAboveRight = 0;
5075  pcCUAboveRight = getPUAboveRight( uiAboveRightPartIdx, uiPartIdxRT );
5076  Bool isAvailableB0 = pcCUAboveRight &&
5077  pcCUAboveRight->isDiffMER(xP+nPSW, yP-1, xP, yP) &&
5078  !pcCUAboveRight->isIntra( uiAboveRightPartIdx );
5079  if ( isAvailableB0 && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveRight, uiAboveRightPartIdx ) ) )
5080  {
5081    abCandIsInter[iCount] = true;
5082    // get Inter Dir
5083    puhInterDirNeighbours[iCount] = pcCUAboveRight->getInterDir( uiAboveRightPartIdx );
5084    // get Mv from Left
5085    pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
5086    if ( getSlice()->isInterB() )
5087    {
5088      pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
5089    }
5090    if ( mrgCandIdx == iCount )
5091    {
5092      return;
5093    }
5094    iCount ++;
5095  }
5096  // early termination
5097  if (iCount == getSlice()->getMaxNumMergeCand()) 
5098  {
5099    return;
5100  }
5101
5102  //left bottom
5103  UInt uiLeftBottomPartIdx = 0;
5104  TComDataCU* pcCULeftBottom = 0;
5105  pcCULeftBottom = this->getPUBelowLeft( uiLeftBottomPartIdx, uiPartIdxLB );
5106  Bool isAvailableA0 = pcCULeftBottom &&
5107  pcCULeftBottom->isDiffMER(xP-1, yP+nPSH, xP, yP) &&
5108  !pcCULeftBottom->isIntra( uiLeftBottomPartIdx ) ;
5109  if ( isAvailableA0 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCULeftBottom, uiLeftBottomPartIdx ) ) )
5110  {
5111    abCandIsInter[iCount] = true;
5112    // get Inter Dir
5113    puhInterDirNeighbours[iCount] = pcCULeftBottom->getInterDir( uiLeftBottomPartIdx );
5114    // get Mv from Left
5115    pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
5116    if ( getSlice()->isInterB() )
5117    {
5118      pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
5119    }
5120
5121    if ( mrgCandIdx == iCount )
5122    {
5123      return;
5124    }
5125    iCount ++;
5126  }
5127  // early termination
5128  if (iCount == getSlice()->getMaxNumMergeCand()) 
5129  {
5130    return;
5131  }
5132
5133  // above left
5134  if( iCount < 4 )
5135  {
5136    UInt uiAboveLeftPartIdx = 0;
5137    TComDataCU* pcCUAboveLeft = 0;
5138    pcCUAboveLeft = getPUAboveLeft( uiAboveLeftPartIdx, uiAbsPartAddr );
5139    Bool isAvailableB2 = pcCUAboveLeft &&
5140    pcCUAboveLeft->isDiffMER(xP-1, yP-1, xP, yP) &&
5141    !pcCUAboveLeft->isIntra( uiAboveLeftPartIdx );
5142    if ( isAvailableB2 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) )
5143        && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) ) )
5144    {
5145      abCandIsInter[iCount] = true;
5146      // get Inter Dir
5147      puhInterDirNeighbours[iCount] = pcCUAboveLeft->getInterDir( uiAboveLeftPartIdx );
5148      // get Mv from Left
5149      pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
5150      if ( getSlice()->isInterB() )
5151      {
5152        pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
5153      }
5154      if ( mrgCandIdx == iCount )
5155      {
5156        return;
5157      }
5158      iCount ++;
5159    }
5160  }
5161  // early termination
5162  if (iCount == getSlice()->getMaxNumMergeCand()) 
5163  {
5164    return;
5165  }
5166
5167  if ( getSlice()->getEnableTMVPFlag())
5168  {
5169    //>> MTK colocated-RightBottom
5170    UInt uiPartIdxRB;
5171
5172    deriveRightBottomIdx( uiPUIdx, uiPartIdxRB ); 
5173
5174    UInt uiAbsPartIdxTmp = g_auiZscanToRaster[uiPartIdxRB];
5175    UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
5176
5177    TComMv cColMv;
5178    Int iRefIdx;
5179    Int uiLCUIdx = -1;
5180
5181    if      ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
5182    {
5183    }
5184    else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxTmp] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
5185    {
5186    }
5187    else
5188    {
5189      if ( ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
5190        ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
5191      {
5192        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + uiNumPartInCUWidth + 1 ];
5193        uiLCUIdx = getAddr();
5194      }
5195      else if ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
5196      {
5197        uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdxTmp + uiNumPartInCUWidth + 1) % m_pcPic->getNumPartInCU() ];
5198      }
5199      else if ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
5200      {
5201        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + 1 ];
5202        uiLCUIdx = getAddr() + 1;
5203      }
5204      else //is the right bottom corner of LCU                       
5205      {
5206        uiAbsPartAddr = 0;
5207      }
5208    }
5209   
5210   
5211    iRefIdx = 0;
5212    Bool bExistMV = false;
5213    UInt uiPartIdxCenter;
5214    UInt uiCurLCUIdx = getAddr();
5215    Int dir = 0;
5216    UInt uiArrayAddr = iCount;
5217    xDeriveCenterIdx( uiPUIdx, uiPartIdxCenter );
5218    bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_0, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx );
5219    if( bExistMV == false )
5220    {
5221      bExistMV = xGetColMVP( REF_PIC_LIST_0, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
5222    }
5223    if( bExistMV )
5224    {
5225      dir |= 1;
5226      pcMvFieldNeighbours[ 2 * uiArrayAddr ].setMvField( cColMv, iRefIdx );
5227    }
5228
5229    if ( getSlice()->isInterB() )
5230    {
5231      bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_1, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx);
5232      if( bExistMV == false )
5233      {
5234        bExistMV = xGetColMVP( REF_PIC_LIST_1, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
5235      }
5236      if( bExistMV )
5237      {
5238        dir |= 2;
5239        pcMvFieldNeighbours[ 2 * uiArrayAddr + 1 ].setMvField( cColMv, iRefIdx );
5240      }
5241    }
5242   
5243    if (dir != 0)
5244    {
5245      puhInterDirNeighbours[uiArrayAddr] = dir;
5246      abCandIsInter[uiArrayAddr] = true;
5247      if ( mrgCandIdx == iCount )
5248      {
5249        return;
5250      }
5251      iCount++;
5252    }
5253  }
5254  // early termination
5255  if (iCount == getSlice()->getMaxNumMergeCand()) 
5256  {
5257    return;
5258  }
5259  UInt uiArrayAddr = iCount;
5260  UInt uiCutoff = uiArrayAddr;
5261   
5262  if ( getSlice()->isInterB())
5263  {
5264    UInt uiPriorityList0[12] = {0 , 1, 0, 2, 1, 2, 0, 3, 1, 3, 2, 3};
5265    UInt uiPriorityList1[12] = {1 , 0, 2, 0, 2, 1, 3, 0, 3, 1, 3, 2};
5266
5267    for (Int idx=0; idx<uiCutoff*(uiCutoff-1) && uiArrayAddr!= getSlice()->getMaxNumMergeCand(); idx++)
5268    {
5269      Int i = uiPriorityList0[idx]; Int j = uiPriorityList1[idx];
5270      if (abCandIsInter[i] && abCandIsInter[j]&& (puhInterDirNeighbours[i]&0x1)&&(puhInterDirNeighbours[j]&0x2))
5271      {
5272        abCandIsInter[uiArrayAddr] = true;
5273        puhInterDirNeighbours[uiArrayAddr] = 3;
5274
5275        // get Mv from cand[i] and cand[j]
5276        pcMvFieldNeighbours[uiArrayAddr << 1].setMvField(pcMvFieldNeighbours[i<<1].getMv(), pcMvFieldNeighbours[i<<1].getRefIdx());
5277        pcMvFieldNeighbours[( uiArrayAddr << 1 ) + 1].setMvField(pcMvFieldNeighbours[(j<<1)+1].getMv(), pcMvFieldNeighbours[(j<<1)+1].getRefIdx());
5278
5279        Int iRefPOCL0 = m_pcSlice->getRefPOC( REF_PIC_LIST_0, pcMvFieldNeighbours[(uiArrayAddr<<1)].getRefIdx() );
5280        Int iRefPOCL1 = m_pcSlice->getRefPOC( REF_PIC_LIST_1, pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getRefIdx() );
5281        if (iRefPOCL0 == iRefPOCL1 && pcMvFieldNeighbours[(uiArrayAddr<<1)].getMv() == pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getMv())
5282        {
5283          abCandIsInter[uiArrayAddr] = false;
5284        }
5285        else
5286        {
5287          uiArrayAddr++;
5288        }
5289      }
5290    }
5291  }
5292  // early termination
5293  if (uiArrayAddr == getSlice()->getMaxNumMergeCand()) 
5294  {
5295    return;
5296  }
5297  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);
5298  Int r = 0;
5299  Int refcnt = 0;
5300  while (uiArrayAddr < getSlice()->getMaxNumMergeCand())
5301  {
5302    abCandIsInter[uiArrayAddr] = true;
5303    puhInterDirNeighbours[uiArrayAddr] = 1;
5304    pcMvFieldNeighbours[uiArrayAddr << 1].setMvField( TComMv(0, 0), r);
5305
5306    if ( getSlice()->isInterB() )
5307    {
5308      puhInterDirNeighbours[uiArrayAddr] = 3;
5309      pcMvFieldNeighbours[(uiArrayAddr << 1) + 1].setMvField(TComMv(0, 0), r);
5310    }
5311    uiArrayAddr++;
5312    if ( refcnt == iNumRefIdx - 1 )
5313    {
5314      r = 0;
5315    }
5316    else
5317    {
5318      ++r;
5319      ++refcnt;
5320    }
5321  }
5322
5323  numValidMergeCand = uiArrayAddr;
5324}
5325#endif
5326
5327
5328#if H_3D_VSP
5329inline Void TComDataCU::xInheritVSPDisInfo(TComDataCU* pcCURef, UInt uiAbsPartIdx, Int iCount, InheritedVSPDisInfo*  inheritedVSPDisInfo)
5330{
5331  inheritedVSPDisInfo[iCount].m_acDvInfo.m_acNBDV   = pcCURef->getDvInfo(uiAbsPartIdx).m_acNBDV;
5332  inheritedVSPDisInfo[iCount].m_acDvInfo.m_aVIdxCan = pcCURef->getDvInfo(uiAbsPartIdx).m_aVIdxCan;
5333}
5334#endif
5335/** Check whether the current PU and a spatial neighboring PU are in a same ME region.
5336 * \param xN, xN   location of the upper-left corner pixel of a neighboring PU
5337 * \param xP, yP   location of the upper-left corner pixel of the current PU
5338 * \returns Bool
5339 */
5340Bool TComDataCU::isDiffMER(Int xN, Int yN, Int xP, Int yP)
5341{
5342
5343  UInt plevel = this->getSlice()->getPPS()->getLog2ParallelMergeLevelMinus2() + 2;
5344  if ((xN>>plevel)!= (xP>>plevel))
5345  {
5346    return true;
5347  }
5348  if ((yN>>plevel)!= (yP>>plevel))
5349  {
5350    return true;
5351  }
5352  return false;
5353}
5354/** calculate the location of upper-left corner pixel and size of the current PU.
5355 * \param partIdx  PU index within a CU
5356 * \param xP, yP   location of the upper-left corner pixel of the current PU
5357 * \param PSW, nPSH    size of the curren PU
5358 * \returns Void
5359 */
5360Void TComDataCU::getPartPosition( UInt partIdx, Int& xP, Int& yP, Int& nPSW, Int& nPSH)
5361{
5362  UInt col = m_uiCUPelX;
5363  UInt row = m_uiCUPelY;
5364
5365  switch ( m_pePartSize[0] )
5366  {
5367  case SIZE_2NxN:
5368    nPSW = getWidth(0);     
5369    nPSH = getHeight(0) >> 1; 
5370    xP   = col;
5371    yP   = (partIdx ==0)? row: row + nPSH;
5372    break;
5373  case SIZE_Nx2N:
5374    nPSW = getWidth(0) >> 1; 
5375    nPSH = getHeight(0);     
5376    xP   = (partIdx ==0)? col: col + nPSW;
5377    yP   = row;
5378    break;
5379  case SIZE_NxN:
5380    nPSW = getWidth(0) >> 1; 
5381    nPSH = getHeight(0) >> 1; 
5382    xP   = col + (partIdx&0x1)*nPSW;
5383    yP   = row + (partIdx>>1)*nPSH;
5384    break;
5385  case SIZE_2NxnU:
5386    nPSW = getWidth(0);
5387    nPSH = ( partIdx == 0 ) ?  getHeight(0) >> 2 : ( getHeight(0) >> 2 ) + ( getHeight(0) >> 1 );
5388    xP   = col;
5389    yP   = (partIdx ==0)? row: row + getHeight(0) - nPSH;
5390
5391    break;
5392  case SIZE_2NxnD:
5393    nPSW = getWidth(0);
5394    nPSH = ( partIdx == 0 ) ?  ( getHeight(0) >> 2 ) + ( getHeight(0) >> 1 ) : getHeight(0) >> 2;
5395    xP   = col;
5396    yP   = (partIdx ==0)? row: row + getHeight(0) - nPSH;
5397    break;
5398  case SIZE_nLx2N:
5399    nPSW = ( partIdx == 0 ) ? getWidth(0) >> 2 : ( getWidth(0) >> 2 ) + ( getWidth(0) >> 1 );
5400    nPSH = getHeight(0);
5401    xP   = (partIdx ==0)? col: col + getWidth(0) - nPSW;
5402    yP   = row;
5403    break;
5404  case SIZE_nRx2N:
5405    nPSW = ( partIdx == 0 ) ? ( getWidth(0) >> 2 ) + ( getWidth(0) >> 1 ) : getWidth(0) >> 2;
5406    nPSH = getHeight(0);
5407    xP   = (partIdx ==0)? col: col + getWidth(0) - nPSW;
5408    yP   = row;
5409    break;
5410  default:
5411    assert ( m_pePartSize[0] == SIZE_2Nx2N );
5412    nPSW = getWidth(0);     
5413    nPSH = getHeight(0);     
5414    xP   = col ;
5415    yP   = row ;
5416
5417    break;
5418  }
5419}
5420
5421/** Constructs a list of candidates for AMVP
5422 * \param uiPartIdx
5423 * \param uiPartAddr
5424 * \param eRefPicList
5425 * \param iRefIdx
5426 * \param pInfo
5427 */
5428Void TComDataCU::fillMvpCand ( UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, Int iRefIdx, AMVPInfo* pInfo )
5429{
5430  TComMv cMvPred;
5431  Bool bAddedSmvp = false;
5432
5433  pInfo->iN = 0; 
5434  if (iRefIdx < 0)
5435  {
5436    return;
5437  }
5438 
5439  //-- Get Spatial MV
5440  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB;
5441  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
5442  Bool bAdded = false;
5443 
5444  deriveLeftRightTopIdx( uiPartIdx, uiPartIdxLT, uiPartIdxRT );
5445  deriveLeftBottomIdx( uiPartIdx, uiPartIdxLB );
5446 
5447  TComDataCU* tmpCU = NULL;
5448  UInt idx;
5449  tmpCU = getPUBelowLeft(idx, uiPartIdxLB);
5450  bAddedSmvp = (tmpCU != NULL) && (tmpCU->getPredictionMode(idx) != MODE_INTRA);
5451
5452  if (!bAddedSmvp)
5453  {
5454    tmpCU = getPULeft(idx, uiPartIdxLB);
5455    bAddedSmvp = (tmpCU != NULL) && (tmpCU->getPredictionMode(idx) != MODE_INTRA);
5456  }
5457
5458  // Left predictor search
5459  bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_BELOW_LEFT);
5460  if (!bAdded) 
5461  {
5462    bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_LEFT );
5463  }
5464 
5465  if(!bAdded)
5466  {
5467    bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_BELOW_LEFT);
5468    if (!bAdded) 
5469    {
5470      xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_LEFT );
5471    }
5472  }
5473  // Above predictor search
5474  bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE_RIGHT);
5475
5476  if (!bAdded) 
5477  {
5478    bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE);
5479  }
5480
5481  if(!bAdded)
5482  {
5483    xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLT, MD_ABOVE_LEFT);
5484  }
5485
5486  if (!bAddedSmvp)
5487  {
5488    bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE_RIGHT);
5489    if (!bAdded) 
5490    {
5491      bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE);
5492    }
5493
5494    if(!bAdded)
5495    {
5496      xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLT, MD_ABOVE_LEFT);
5497    }
5498  }
5499 
5500  if ( pInfo->iN == 2 )
5501  {
5502    if ( pInfo->m_acMvCand[ 0 ] == pInfo->m_acMvCand[ 1 ] )
5503    {
5504      pInfo->iN = 1;
5505    }
5506  }
5507
5508  if ( getSlice()->getEnableTMVPFlag() )
5509  {
5510    // Get Temporal Motion Predictor
5511    Int iRefIdx_Col = iRefIdx;
5512    TComMv cColMv;
5513    UInt uiPartIdxRB;
5514    UInt uiAbsPartIdx; 
5515    UInt uiAbsPartAddr;
5516
5517    deriveRightBottomIdx( uiPartIdx, uiPartIdxRB );
5518    uiAbsPartAddr = m_uiAbsIdxInLCU + uiPartAddr;
5519
5520    //----  co-located RightBottom Temporal Predictor (H) ---//
5521    uiAbsPartIdx = g_auiZscanToRaster[uiPartIdxRB];
5522    Int uiLCUIdx = -1;
5523    if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdx] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
5524    {
5525    }
5526    else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdx] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
5527    {
5528    }
5529    else
5530    {
5531      if ( ( uiAbsPartIdx % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
5532        ( uiAbsPartIdx / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
5533      {
5534        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdx + uiNumPartInCUWidth + 1 ];
5535        uiLCUIdx = getAddr();
5536      }
5537      else if ( uiAbsPartIdx % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
5538      {
5539        uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdx + uiNumPartInCUWidth + 1) % m_pcPic->getNumPartInCU() ];
5540      }
5541      else if ( uiAbsPartIdx / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
5542      {
5543        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdx + 1 ];
5544        uiLCUIdx = getAddr() + 1;
5545      }
5546      else //is the right bottom corner of LCU                       
5547      {
5548        uiAbsPartAddr = 0;
5549      }
5550    }
5551    if ( uiLCUIdx >= 0 && xGetColMVP( eRefPicList, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx_Col
5552#if H_3D_TMVP
5553         , 0
5554#endif
5555    ) )
5556    {
5557      pInfo->m_acMvCand[pInfo->iN++] = cColMv;
5558    }
5559    else 
5560    {
5561      UInt uiPartIdxCenter;
5562      UInt uiCurLCUIdx = getAddr();
5563      xDeriveCenterIdx( uiPartIdx, uiPartIdxCenter );
5564      if (xGetColMVP( eRefPicList, uiCurLCUIdx, uiPartIdxCenter,  cColMv, iRefIdx_Col
5565#if H_3D_TMVP
5566         , 0
5567#endif
5568      ))
5569      {
5570        pInfo->m_acMvCand[pInfo->iN++] = cColMv;
5571      }
5572    }
5573    //----  co-located RightBottom Temporal Predictor  ---//
5574  }
5575
5576  if (pInfo->iN > AMVP_MAX_NUM_CANDS)
5577  {
5578    pInfo->iN = AMVP_MAX_NUM_CANDS;
5579  }
5580  while (pInfo->iN < AMVP_MAX_NUM_CANDS)
5581  {
5582      pInfo->m_acMvCand[pInfo->iN].set(0,0);
5583      pInfo->iN++;
5584  }
5585  return ;
5586}
5587
5588Bool TComDataCU::isBipredRestriction(UInt puIdx)
5589{
5590  Int width = 0;
5591  Int height = 0;
5592  UInt partAddr;
5593 
5594#if H_3D_DBBP
5595  if( getDBBPFlag(0) )
5596  {
5597    return true;
5598  }
5599#endif
5600
5601  getPartIndexAndSize( puIdx, partAddr, width, height );
5602  if ( getWidth(0) == 8 && (width < 8 || height < 8) )
5603  {
5604    return true;
5605  }
5606  return false;
5607}
5608
5609Void TComDataCU::clipMv    (TComMv&  rcMv)
5610{
5611  Int  iMvShift = 2;
5612#if H_3D_IC
5613  if( getSlice()->getIsDepth() )
5614    iMvShift = 0;
5615#endif
5616  Int iOffset = 8;
5617  Int iHorMax = ( m_pcSlice->getSPS()->getPicWidthInLumaSamples() + iOffset - m_uiCUPelX - 1 ) << iMvShift;
5618  Int iHorMin = (       -(Int)g_uiMaxCUWidth - iOffset - (Int)m_uiCUPelX + 1 ) << iMvShift;
5619 
5620  Int iVerMax = ( m_pcSlice->getSPS()->getPicHeightInLumaSamples() + iOffset - m_uiCUPelY - 1 ) << iMvShift;
5621  Int iVerMin = (       -(Int)g_uiMaxCUHeight - iOffset - (Int)m_uiCUPelY + 1 ) << iMvShift;
5622 
5623  rcMv.setHor( min (iHorMax, max (iHorMin, rcMv.getHor())) );
5624  rcMv.setVer( min (iVerMax, max (iVerMin, rcMv.getVer())) );
5625}
5626
5627UInt TComDataCU::getIntraSizeIdx(UInt uiAbsPartIdx)
5628{
5629  UInt uiShift = ( m_pePartSize[uiAbsPartIdx]==SIZE_NxN ? 1 : 0 );
5630 
5631  UChar uiWidth = m_puhWidth[uiAbsPartIdx]>>uiShift;
5632  UInt  uiCnt = 0;
5633  while( uiWidth )
5634  {
5635    uiCnt++;
5636    uiWidth>>=1;
5637  }
5638  uiCnt-=2;
5639  return uiCnt > 6 ? 6 : uiCnt;
5640}
5641
5642Void TComDataCU::clearCbf( UInt uiIdx, TextType eType, UInt uiNumParts )
5643{
5644  ::memset( &m_puhCbf[g_aucConvertTxtTypeToIdx[eType]][uiIdx], 0, sizeof(UChar)*uiNumParts);
5645}
5646
5647/** Set a I_PCM flag for all sub-partitions of a partition.
5648 * \param bIpcmFlag I_PCM flag
5649 * \param uiAbsPartIdx patition index
5650 * \param uiDepth CU depth
5651 * \returns Void
5652 */
5653Void TComDataCU::setIPCMFlagSubParts  (Bool bIpcmFlag, UInt uiAbsPartIdx, UInt uiDepth)
5654{
5655  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
5656
5657  memset(m_pbIPCMFlag + uiAbsPartIdx, bIpcmFlag, sizeof(Bool)*uiCurrPartNumb );
5658}
5659
5660/** Test whether the current block is skipped
5661 * \param uiPartIdx Block index
5662 * \returns Flag indicating whether the block is skipped
5663 */
5664Bool TComDataCU::isSkipped( UInt uiPartIdx )
5665{
5666  return ( getSkipFlag( uiPartIdx ) );
5667}
5668
5669#if H_3D_IC
5670Bool TComDataCU::isIC( UInt uiPartIdx )
5671{
5672    if ( m_pcSlice->isIntra () )
5673    {
5674        return false;
5675    }
5676    return ( ( getSkipFlag(uiPartIdx) || getPredictionMode(uiPartIdx) == MODE_INTER) && getICFlag( uiPartIdx ) && isICFlagRequired( uiPartIdx ) );
5677}
5678#endif
5679
5680// ====================================================================================================================
5681// Protected member functions
5682// ====================================================================================================================
5683
5684Bool TComDataCU::xAddMVPCand( AMVPInfo* pInfo, RefPicList eRefPicList, Int iRefIdx, UInt uiPartUnitIdx, MVP_DIR eDir )
5685{
5686  TComDataCU* pcTmpCU = NULL;
5687  UInt uiIdx;
5688  switch( eDir )
5689  {
5690    case MD_LEFT:
5691    {
5692      pcTmpCU = getPULeft(uiIdx, uiPartUnitIdx);
5693      break;
5694    }
5695    case MD_ABOVE:
5696    {
5697      pcTmpCU = getPUAbove(uiIdx, uiPartUnitIdx );
5698      break;
5699    }
5700    case MD_ABOVE_RIGHT:
5701    {
5702      pcTmpCU = getPUAboveRight(uiIdx, uiPartUnitIdx);
5703      break;
5704    }
5705    case MD_BELOW_LEFT:
5706    {
5707      pcTmpCU = getPUBelowLeft(uiIdx, uiPartUnitIdx);
5708      break;
5709    }
5710    case MD_ABOVE_LEFT:
5711    {
5712      pcTmpCU = getPUAboveLeft(uiIdx, uiPartUnitIdx);
5713      break;
5714    }
5715    default:
5716    {
5717      break;
5718    }
5719  }
5720
5721  if ( pcTmpCU == NULL )
5722  {
5723    return false;
5724  }
5725 
5726  if ( pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) >= 0 && m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getPOC() == pcTmpCU->getSlice()->getRefPOC( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) ))
5727  {
5728    TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
5729   
5730    pInfo->m_acMvCand[ pInfo->iN++] = cMvPred;
5731    return true;
5732  }
5733
5734  RefPicList eRefPicList2nd = REF_PIC_LIST_0;
5735  if(       eRefPicList == REF_PIC_LIST_0 )
5736  {
5737    eRefPicList2nd = REF_PIC_LIST_1;
5738  }
5739  else if ( eRefPicList == REF_PIC_LIST_1)
5740  {
5741    eRefPicList2nd = REF_PIC_LIST_0;
5742  }
5743
5744
5745  Int iCurrRefPOC = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getPOC();
5746  Int iNeibRefPOC;
5747
5748
5749  if( pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) >= 0 )
5750  {
5751    iNeibRefPOC = pcTmpCU->getSlice()->getRefPOC( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) );
5752    if( iNeibRefPOC == iCurrRefPOC ) // Same Reference Frame But Diff List//
5753    {
5754      TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList2nd)->getMv(uiIdx);
5755      pInfo->m_acMvCand[ pInfo->iN++] = cMvPred;
5756      return true;
5757    }
5758  }
5759  return false;
5760}
5761
5762/**
5763 * \param pInfo
5764 * \param eRefPicList
5765 * \param iRefIdx
5766 * \param uiPartUnitIdx
5767 * \param eDir
5768 * \returns Bool
5769 */
5770Bool TComDataCU::xAddMVPCandOrder( AMVPInfo* pInfo, RefPicList eRefPicList, Int iRefIdx, UInt uiPartUnitIdx, MVP_DIR eDir )
5771{
5772  TComDataCU* pcTmpCU = NULL;
5773  UInt uiIdx;
5774  switch( eDir )
5775  {
5776  case MD_LEFT:
5777    {
5778      pcTmpCU = getPULeft(uiIdx, uiPartUnitIdx);
5779      break;
5780    }
5781  case MD_ABOVE:
5782    {
5783      pcTmpCU = getPUAbove(uiIdx, uiPartUnitIdx);
5784      break;
5785    }
5786  case MD_ABOVE_RIGHT:
5787    {
5788      pcTmpCU = getPUAboveRight(uiIdx, uiPartUnitIdx);
5789      break;
5790    }
5791  case MD_BELOW_LEFT:
5792    {
5793      pcTmpCU = getPUBelowLeft(uiIdx, uiPartUnitIdx);
5794      break;
5795    }
5796  case MD_ABOVE_LEFT:
5797    {
5798      pcTmpCU = getPUAboveLeft(uiIdx, uiPartUnitIdx);
5799      break;
5800    }
5801  default:
5802    {
5803      break;
5804    }
5805  }
5806
5807  if ( pcTmpCU == NULL ) 
5808  {
5809    return false;
5810  }
5811 
5812  RefPicList eRefPicList2nd = REF_PIC_LIST_0;
5813  if(       eRefPicList == REF_PIC_LIST_0 )
5814  {
5815    eRefPicList2nd = REF_PIC_LIST_1;
5816  }
5817  else if ( eRefPicList == REF_PIC_LIST_1)
5818  {
5819    eRefPicList2nd = REF_PIC_LIST_0;
5820  }
5821
5822  Int iCurrPOC = m_pcSlice->getPOC();
5823  Int iCurrRefPOC = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getPOC();
5824  Int iNeibPOC = iCurrPOC;
5825  Int iNeibRefPOC;
5826
5827  Bool bIsCurrRefLongTerm = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getIsLongTerm();
5828  Bool bIsNeibRefLongTerm = false;
5829  //---------------  V1 (END) ------------------//
5830  if( pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) >= 0)
5831  {
5832    iNeibRefPOC = pcTmpCU->getSlice()->getRefPOC( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) );
5833    TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
5834    TComMv rcMv;
5835
5836    bIsNeibRefLongTerm = pcTmpCU->getSlice()->getRefPic( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) )->getIsLongTerm();
5837    if ( bIsCurrRefLongTerm == bIsNeibRefLongTerm ) 
5838    {
5839    if ( bIsCurrRefLongTerm || bIsNeibRefLongTerm )
5840    {
5841      rcMv = cMvPred;
5842    }
5843    else
5844    {
5845      Int iScale = xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
5846      if ( iScale == 4096 )
5847      {
5848        rcMv = cMvPred;
5849      }
5850      else
5851      {
5852        rcMv = cMvPred.scaleMv( iScale );
5853      }
5854    }
5855    pInfo->m_acMvCand[ pInfo->iN++] = rcMv;
5856    return true;
5857    }
5858  }
5859  //---------------------- V2(END) --------------------//
5860  if( pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) >= 0)
5861  {
5862    iNeibRefPOC = pcTmpCU->getSlice()->getRefPOC( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) );
5863    TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList2nd)->getMv(uiIdx);
5864    TComMv rcMv;
5865
5866    bIsNeibRefLongTerm = pcTmpCU->getSlice()->getRefPic( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) )->getIsLongTerm();
5867    if ( bIsCurrRefLongTerm == bIsNeibRefLongTerm ) 
5868    {
5869    if ( bIsCurrRefLongTerm || bIsNeibRefLongTerm )
5870    {
5871      rcMv = cMvPred;
5872    }
5873    else
5874    {
5875      Int iScale = xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
5876      if ( iScale == 4096 )
5877      {
5878        rcMv = cMvPred;
5879      }
5880      else
5881      {
5882        rcMv = cMvPred.scaleMv( iScale );
5883      }
5884    }
5885    pInfo->m_acMvCand[ pInfo->iN++] = rcMv;
5886    return true;
5887    }
5888  }
5889  //---------------------- V3(END) --------------------//
5890  return false;
5891}
5892
5893/**
5894 * \param eRefPicList
5895 * \param uiCUAddr
5896 * \param uiPartUnitIdx
5897 * \param riRefIdx
5898 * \returns Bool
5899 */
5900Bool TComDataCU::xGetColMVP( RefPicList eRefPicList, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv, Int& riRefIdx
5901#if H_3D_TMVP
5902  , Bool bMRG
5903#endif
5904  )
5905{
5906  UInt uiAbsPartAddr = uiPartUnitIdx;
5907
5908  RefPicList  eColRefPicList;
5909  Int iColPOC, iColRefPOC, iCurrPOC, iCurrRefPOC, iScale;
5910  TComMv cColMv;
5911
5912  // use coldir.
5913  TComPic *pColPic = getSlice()->getRefPic( RefPicList(getSlice()->isInterB() ? 1-getSlice()->getColFromL0Flag() : 0), getSlice()->getColRefIdx());
5914  TComDataCU *pColCU = pColPic->getCU( uiCUAddr );
5915  if(pColCU->getPic()==0||pColCU->getPartitionSize(uiPartUnitIdx)==SIZE_NONE)
5916  {
5917    return false;
5918  }
5919  iCurrPOC = m_pcSlice->getPOC();   
5920  iColPOC = pColCU->getSlice()->getPOC(); 
5921
5922  if (pColCU->isIntra(uiAbsPartAddr))
5923  {
5924    return false;
5925  }
5926  eColRefPicList = getSlice()->getCheckLDC() ? eRefPicList : RefPicList(getSlice()->getColFromL0Flag());
5927
5928  Int iColRefIdx = pColCU->getCUMvField(RefPicList(eColRefPicList))->getRefIdx(uiAbsPartAddr);
5929
5930  if (iColRefIdx < 0 )
5931  {
5932    eColRefPicList = RefPicList(1 - eColRefPicList);
5933    iColRefIdx = pColCU->getCUMvField(RefPicList(eColRefPicList))->getRefIdx(uiAbsPartAddr);
5934
5935    if (iColRefIdx < 0 )
5936    {
5937      return false;
5938    }
5939  }
5940
5941  // Scale the vector.
5942  iColRefPOC = pColCU->getSlice()->getRefPOC(eColRefPicList, iColRefIdx);
5943  cColMv = pColCU->getCUMvField(eColRefPicList)->getMv(uiAbsPartAddr);
5944
5945  iCurrRefPOC = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getPOC();
5946  Bool bIsCurrRefLongTerm = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getIsLongTerm();
5947  Bool bIsColRefLongTerm = pColCU->getSlice()->getIsUsedAsLongTerm(eColRefPicList, iColRefIdx);
5948
5949  if ( bIsCurrRefLongTerm != bIsColRefLongTerm ) 
5950  {
5951#if H_3D_TMVP
5952    Int iAlterRefIdx  = m_pcSlice->getAlterRefIdx(eRefPicList);
5953    if(bMRG && iAlterRefIdx > 0)
5954    {
5955      riRefIdx = iAlterRefIdx;
5956      bIsCurrRefLongTerm = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getIsLongTerm();
5957      iCurrRefPOC = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getPOC();
5958      assert(bIsCurrRefLongTerm == bIsColRefLongTerm);
5959    }
5960    else
5961    {
5962#endif
5963      return false;
5964#if H_3D_TMVP
5965    }
5966#endif
5967  }
5968
5969  if ( bIsCurrRefLongTerm || bIsColRefLongTerm )
5970  {
5971#if H_3D_TMVP
5972    Int iCurrViewId    = m_pcSlice->getViewIndex (); 
5973    Int iCurrRefViewId = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getViewIndex (); 
5974    Int iColViewId     = pColCU->getSlice()->getViewIndex(); 
5975    Int iColRefViewId  = pColCU->getSlice()->getRefPic( eColRefPicList, pColCU->getCUMvField(eColRefPicList)->getRefIdx(uiAbsPartAddr))->getViewIndex(); 
5976    iScale = xGetDistScaleFactor( iCurrViewId, iCurrRefViewId, iColViewId, iColRefViewId );
5977    if ( iScale != 4096 && m_pcSlice->getVPS()->getIvMvScalingFlag() ) 
5978    {
5979      rcMv = cColMv.scaleMv( iScale );
5980    }
5981    else
5982    {
5983#endif
5984       rcMv = cColMv;
5985#if H_3D_TMVP
5986    }
5987#endif
5988  }
5989  else
5990  {
5991    iScale = xGetDistScaleFactor(iCurrPOC, iCurrRefPOC, iColPOC, iColRefPOC);
5992    if ( iScale == 4096 )
5993    {
5994      rcMv = cColMv;
5995    }
5996    else
5997    {
5998      rcMv = cColMv.scaleMv( iScale );
5999    }
6000  }
6001  return true;
6002}
6003
6004UInt TComDataCU::xGetMvdBits(TComMv cMvd)
6005{
6006  return ( xGetComponentBits(cMvd.getHor()) + xGetComponentBits(cMvd.getVer()) );
6007}
6008
6009UInt TComDataCU::xGetComponentBits(Int iVal)
6010{
6011  UInt uiLength = 1;
6012  UInt uiTemp   = ( iVal <= 0) ? (-iVal<<1)+1: (iVal<<1);
6013 
6014  assert ( uiTemp );
6015 
6016  while ( 1 != uiTemp )
6017  {
6018    uiTemp >>= 1;
6019    uiLength += 2;
6020  }
6021 
6022  return uiLength;
6023}
6024
6025
6026Int TComDataCU::xGetDistScaleFactor(Int iCurrPOC, Int iCurrRefPOC, Int iColPOC, Int iColRefPOC)
6027{
6028  Int iDiffPocD = iColPOC - iColRefPOC;
6029  Int iDiffPocB = iCurrPOC - iCurrRefPOC;
6030 
6031  if( iDiffPocD == iDiffPocB )
6032  {
6033    return 4096;
6034  }
6035  else
6036  {
6037    Int iTDB      = Clip3( -128, 127, iDiffPocB );
6038    Int iTDD      = Clip3( -128, 127, iDiffPocD );
6039    Int iX        = (0x4000 + abs(iTDD/2)) / iTDD;
6040    Int iScale    = Clip3( -4096, 4095, (iTDB * iX + 32) >> 6 );
6041    return iScale;
6042  }
6043}
6044
6045/**
6046 * \param eCUMode
6047 * \param uiPartIdx
6048 * \param ruiPartIdxCenter
6049 * \returns Void
6050 */
6051Void TComDataCU::xDeriveCenterIdx( UInt uiPartIdx, UInt& ruiPartIdxCenter )
6052{
6053  UInt uiPartAddr;
6054  Int  iPartWidth;
6055  Int  iPartHeight;
6056  getPartIndexAndSize( uiPartIdx, uiPartAddr, iPartWidth, iPartHeight);
6057 
6058  ruiPartIdxCenter = m_uiAbsIdxInLCU+uiPartAddr; // partition origin.
6059  ruiPartIdxCenter = g_auiRasterToZscan[ g_auiZscanToRaster[ ruiPartIdxCenter ]
6060                                        + ( iPartHeight/m_pcPic->getMinCUHeight()  )/2*m_pcPic->getNumPartInWidth()
6061                                        + ( iPartWidth/m_pcPic->getMinCUWidth()  )/2];
6062}
6063#if H_3D
6064Void TComDataCU::compressMV(Int scale)
6065#else
6066Void TComDataCU::compressMV()
6067#endif
6068{
6069#if H_3D
6070  Int scaleFactor = (4 / scale ) * AMVP_DECIMATION_FACTOR / m_unitSize;
6071#else
6072  Int scaleFactor = 4 * AMVP_DECIMATION_FACTOR / m_unitSize;
6073#endif
6074  if (scaleFactor > 0)
6075  {
6076    m_acCUMvField[0].compress(m_pePredMode, scaleFactor);
6077    m_acCUMvField[1].compress(m_pePredMode, scaleFactor);   
6078  }
6079}
6080
6081UInt TComDataCU::getCoefScanIdx(UInt uiAbsPartIdx, UInt uiWidth, Bool bIsLuma, Bool bIsIntra)
6082{
6083  UInt uiCTXIdx;
6084  UInt uiScanIdx;
6085  UInt uiDirMode;
6086
6087  if ( !bIsIntra ) 
6088  {
6089    uiScanIdx = SCAN_DIAG;
6090    return uiScanIdx;
6091  }
6092
6093  switch(uiWidth)
6094  {
6095    case  2: uiCTXIdx = 6; break;
6096    case  4: uiCTXIdx = 5; break;
6097    case  8: uiCTXIdx = 4; break;
6098    case 16: uiCTXIdx = 3; break;
6099    case 32: uiCTXIdx = 2; break;
6100    case 64: uiCTXIdx = 1; break;
6101    default: uiCTXIdx = 0; break;
6102  }
6103
6104  if ( bIsLuma )
6105  {
6106    uiDirMode = getLumaIntraDir(uiAbsPartIdx);
6107#if H_3D_DIM
6108    mapDepthModeToIntraDir( uiDirMode );
6109#endif
6110    uiScanIdx = SCAN_DIAG;
6111    if (uiCTXIdx >3 && uiCTXIdx < 6) //if multiple scans supported for transform size
6112    {
6113      uiScanIdx = abs((Int) uiDirMode - VER_IDX) < 5 ? SCAN_HOR : (abs((Int)uiDirMode - HOR_IDX) < 5 ? SCAN_VER : SCAN_DIAG);
6114    }
6115  }
6116  else
6117  {
6118    uiDirMode = getChromaIntraDir(uiAbsPartIdx);
6119    if( uiDirMode == DM_CHROMA_IDX )
6120    {
6121      // get number of partitions in current CU
6122      UInt depth = getDepth(uiAbsPartIdx);
6123      UInt numParts = getPic()->getNumPartInCU() >> (2 * depth);
6124     
6125      // get luma mode from upper-left corner of current CU
6126      uiDirMode = getLumaIntraDir((uiAbsPartIdx/numParts)*numParts);
6127#if H_3D_DIM
6128      mapDepthModeToIntraDir( uiDirMode );
6129#endif
6130    }
6131    uiScanIdx = SCAN_DIAG;
6132    if (uiCTXIdx >4 && uiCTXIdx < 7) //if multiple scans supported for transform size
6133    {
6134      uiScanIdx = abs((Int) uiDirMode - VER_IDX) < 5 ? SCAN_HOR : (abs((Int)uiDirMode - HOR_IDX) < 5 ? SCAN_VER : SCAN_DIAG);
6135    }
6136  }
6137
6138  return uiScanIdx;
6139}
6140
6141UInt TComDataCU::getSCUAddr()
6142{ 
6143  return getPic()->getPicSym()->getInverseCUOrderMap(m_uiCUAddr)*(1<<(m_pcSlice->getSPS()->getMaxCUDepth()<<1))+m_uiAbsIdxInLCU; 
6144}
6145
6146#if H_3D
6147Void TComDataCU::getPosInPic( UInt uiAbsPartIndex, Int& riPosX, Int& riPosY )
6148{
6149  riPosX = g_auiRasterToPelX[g_auiZscanToRaster[uiAbsPartIndex]] + getCUPelX();
6150  riPosY = g_auiRasterToPelY[g_auiZscanToRaster[uiAbsPartIndex]] + getCUPelY(); 
6151}
6152#endif
6153#if H_3D_IV_MERGE
6154Bool TComDataCU::getDispforDepth (UInt uiPartIdx, UInt uiPartAddr, DisInfo* pDisp)
6155{
6156
6157  assert(getPartitionSize( uiPartAddr ) == SIZE_2Nx2N);
6158
6159  TComMv cMv; 
6160  Int iDisp     = getSlice()->getDepthToDisparityB( 0 )[ 128 ];
6161  cMv.setHor(iDisp);
6162  cMv.setVer(0);
6163  pDisp->m_acNBDV = cMv;
6164  pDisp->m_aVIdxCan = 0;
6165
6166  return true;
6167}
6168#endif
6169#if H_3D_NBDV
6170//Notes from QC:
6171//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
6172//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
6173//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
6174Bool TComDataCU::getDisMvpCandNBDV( DisInfo* pDInfo
6175#if H_3D_NBDV_REF
6176, Bool bDepthRefine
6177#endif
6178)
6179{
6180  //// ******* Init variables ******* /////
6181  // Init disparity struct for results
6182  pDInfo->bDV = false;   
6183  pDInfo->m_aVIdxCan = -1;
6184
6185  // Init struct for disparities from MCP neighboring blocks
6186  IDVInfo cIDVInfo;
6187  cIDVInfo.m_bFound = false; 
6188  UInt uiPartIdx = 0;
6189  UInt uiPartAddr = 0;
6190  for (UInt iCurDvMcpCand = 0; iCurDvMcpCand < IDV_CANDS; iCurDvMcpCand++)
6191  {
6192    for (UInt iList = 0; iList < 2; iList++)
6193    {
6194      cIDVInfo.m_acMvCand[iList][iCurDvMcpCand].setZero();
6195      cIDVInfo.m_aVIdxCan[iList][iCurDvMcpCand] = 0; 
6196      cIDVInfo.m_bAvailab[iList][iCurDvMcpCand] = false; 
6197    }
6198  }
6199#if H_3D_NBDV_REF
6200  if( !m_pcSlice->getVPS()->getDepthRefinementFlag( m_pcSlice->getLayerIdInVps() ) )
6201  {
6202    bDepthRefine = false;
6203  }
6204#endif
6205  // Get Positions 
6206  PartSize eCUMode    = getPartitionSize( uiPartAddr );   
6207  assert(eCUMode == SIZE_2Nx2N);
6208  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB; 
6209
6210  deriveLeftRightTopIdxGeneral(uiPartAddr, uiPartIdx, uiPartIdxLT, uiPartIdxRT );
6211  deriveLeftBottomIdxGeneral  (uiPartAddr, uiPartIdx, uiPartIdxLB );
6212
6213  //// ******* Get disparity from temporal neighboring blocks ******* /////
6214  if ( getSlice()->getEnableTMVPFlag() )
6215  {
6216    TComMv cColMv;
6217    Int iTargetViewIdx = 0;
6218    Int iTStartViewIdx = 0;   
6219
6220    ///*** Derive center position ***
6221    UInt uiPartIdxCenter;
6222    Int  uiLCUIdx   = getAddr();
6223    xDeriveCenterIdx(uiPartIdx, uiPartIdxCenter );
6224
6225    ///*** Search temporal candidate pictures for disparity vector ***
6226    const Int iNumCandPics = getPic()->getNumDdvCandPics();
6227    for(Int curCandPic = 0; curCandPic < iNumCandPics; curCandPic++)
6228    {
6229      RefPicList eCurRefPicList   = REF_PIC_LIST_0 ;
6230      Int        curCandPicRefIdx = 0;
6231      if( curCandPic == 0 ) 
6232      { 
6233        eCurRefPicList   = RefPicList(getSlice()->isInterB() ? 1-getSlice()->getColFromL0Flag() : 0);
6234        curCandPicRefIdx = getSlice()->getColRefIdx();
6235      }
6236      else                 
6237      {
6238        eCurRefPicList   = getPic()->getRapRefList();
6239        curCandPicRefIdx = getPic()->getRapRefIdx();
6240      }
6241
6242      Bool bCheck = xGetColDisMV( curCandPic, eCurRefPicList, curCandPicRefIdx, uiLCUIdx,   uiPartIdxCenter,  cColMv, iTargetViewIdx, iTStartViewIdx );
6243
6244      if( bCheck )
6245      {
6246        clipMv(cColMv);
6247        pDInfo->m_acNBDV = cColMv;
6248        pDInfo->m_aVIdxCan  = iTargetViewIdx;
6249
6250#if H_3D_NBDV_REF
6251        TComPic* picDepth = NULL;   
6252#if H_3D_FCO_VSP_DONBDV_E0163
6253        picDepth  = getSlice()->getIvPic(true, getSlice()->getViewIndex() );
6254        if ( picDepth->getPicYuvRec() != NULL  ) 
6255        {
6256          cColMv.setZero();
6257        }
6258        else // Go back with virtual depth
6259        {
6260          picDepth = getSlice()->getIvPic( true, iTargetViewIdx );
6261        }
6262
6263        assert(picDepth != NULL);
6264#else
6265        picDepth = getSlice()->getIvPic( true, iTargetViewIdx );
6266        assert(picDepth != NULL);
6267#endif
6268        if (picDepth && bDepthRefine)
6269          estimateDVFromDM(iTargetViewIdx, uiPartIdx, picDepth, uiPartAddr, &cColMv );
6270
6271        pDInfo->m_acDoNBDV  = cColMv;
6272#endif //H_3D_NBDV_REF
6273        return true;
6274      }
6275    }
6276  } 
6277
6278  UInt uiIdx = 0;
6279  Bool        bCheckMcpDv = false;   
6280  TComDataCU* pcTmpCU     = NULL;
6281
6282  //// ******* Get disparity from left block ******* /////
6283  pcTmpCU = getPULeft(uiIdx, uiPartIdxLB, true, false);
6284  bCheckMcpDv = true; 
6285  if ( xCheckSpatialNBDV( pcTmpCU, uiIdx, pDInfo, bCheckMcpDv, &cIDVInfo, DVFROM_LEFT
6286#if H_3D_NBDV_REF
6287    , bDepthRefine
6288#endif
6289    ) )
6290    return true;
6291
6292  //// ******* Get disparity from above block ******* /////
6293  pcTmpCU = getPUAbove(uiIdx, uiPartIdxRT, true, false, true);
6294  if(pcTmpCU != NULL )
6295  {
6296    bCheckMcpDv = ( ( getAddr() - pcTmpCU->getAddr() ) == 0);
6297    if ( xCheckSpatialNBDV( pcTmpCU, uiIdx, pDInfo, bCheckMcpDv, &cIDVInfo, DVFROM_ABOVE
6298#if H_3D_NBDV_REF
6299      , bDepthRefine
6300#endif
6301      ) )
6302      return true;
6303  }
6304
6305  //// ******* Search MCP blocks ******* /////
6306  if( cIDVInfo.m_bFound ) 
6307  {
6308    for( Int curPos = 0 ; curPos < IDV_CANDS ; curPos++ ) 
6309    {
6310      for(Int iList = 0; iList < (getSlice()->isInterB() ? 2: 1); iList ++)
6311      {
6312        if( cIDVInfo.m_bAvailab[iList][curPos] )
6313        {
6314          TComMv cDispVec = cIDVInfo.m_acMvCand[iList][ curPos ];
6315          clipMv( cDispVec );
6316          pDInfo->m_acNBDV = cDispVec;
6317          pDInfo->m_aVIdxCan = cIDVInfo.m_aVIdxCan[iList][ curPos ];
6318#if H_3D_NBDV_REF
6319#if H_3D_FCO_VSP_DONBDV_E0163
6320          TComPic* picDepth  = NULL;
6321
6322          picDepth  = getSlice()->getIvPic(true, getSlice()->getViewIndex() );
6323          if ( picDepth->getPicYuvRec() != NULL ) 
6324          {
6325            cDispVec.setZero();
6326          }
6327          else // Go back with virtual depth
6328          {
6329            picDepth = getSlice()->getIvPic( true, pDInfo->m_aVIdxCan );
6330          }
6331
6332          assert(picDepth != NULL);
6333#else
6334          TComPic* picDepth = getSlice()->getIvPic( true, pDInfo->m_aVIdxCan );
6335          assert(picDepth!=NULL);
6336#endif
6337
6338          if (picDepth && bDepthRefine)
6339          {
6340            estimateDVFromDM (pDInfo->m_aVIdxCan, uiPartIdx, picDepth, uiPartAddr, &cDispVec);
6341          }
6342          pDInfo->m_acDoNBDV = cDispVec;
6343#endif
6344          return true;
6345        }
6346      }
6347    }
6348  }
6349
6350  TComMv defaultDV(0, 0);
6351  pDInfo->m_acNBDV = defaultDV;
6352
6353  Int valid = 0;
6354  Int viewIndex = 0;
6355  for( UInt uiBId = 0; uiBId < getSlice()->getViewIndex() && valid==0; uiBId++ )
6356  {
6357    UInt        uiBaseId    = uiBId;
6358    TComPic*    pcBasePic   = getSlice()->getIvPic( false, uiBaseId );
6359    for( Int iRefListId = 0; ( iRefListId < (getSlice()->isInterB()? 2:1) ) && !getSlice()->isIntra() && valid==0; iRefListId++ )
6360    {
6361      RefPicList  eRefPicListTest = RefPicList( iRefListId );
6362      Int         iNumRefPics = getSlice()->getNumRefIdx( eRefPicListTest ) ;
6363      for( Int iRefIndex = 0; iRefIndex < iNumRefPics; iRefIndex++ )
6364      { 
6365        if(pcBasePic->getPOC() == getSlice()->getRefPic( eRefPicListTest, iRefIndex )->getPOC() 
6366          && pcBasePic->getViewIndex() == getSlice()->getRefPic( eRefPicListTest, iRefIndex )->getViewIndex())
6367        {
6368          valid=1;
6369          viewIndex = uiBaseId;
6370          break;
6371        }
6372      }
6373    }
6374  }
6375  if(valid)
6376  {
6377    pDInfo->m_aVIdxCan = viewIndex;
6378#if H_3D_NBDV_REF
6379    TComPic* picDepth = NULL;
6380#if H_3D_FCO_VSP_DONBDV_E0163
6381    picDepth  = getSlice()->getIvPic(true, getSlice()->getViewIndex() );
6382    if ( picDepth->getPicYuvRec() != NULL ) 
6383    {
6384      defaultDV.setZero();
6385    }
6386    else // Go back with virtual depth
6387    {
6388      picDepth = getSlice()->getIvPic( true, viewIndex );
6389    }
6390
6391    assert(picDepth != NULL);
6392#else
6393    picDepth = getSlice()->getIvPic( true, viewIndex );
6394    assert(picDepth!=NULL);
6395#endif
6396    if (picDepth && bDepthRefine)
6397    {
6398      estimateDVFromDM(viewIndex, uiPartIdx, picDepth, uiPartAddr, &defaultDV ); // from base view
6399    }
6400    pDInfo->m_acDoNBDV = defaultDV;
6401#endif
6402  }
6403  return false; 
6404}
6405
6406#if H_3D_NBDV_REF
6407Pel TComDataCU::getMcpFromDM(TComPicYuv* pcBaseViewDepthPicYuv, TComMv* mv, Int iBlkX, Int iBlkY, Int iBlkWidth, Int iBlkHeight, Int* aiShiftLUT )
6408{
6409  Int iPictureWidth  = pcBaseViewDepthPicYuv->getWidth();
6410  Int iPictureHeight = pcBaseViewDepthPicYuv->getHeight();
6411 
6412  Int depthStartPosX = Clip3(0,   iPictureWidth - 1,  iBlkX + ((mv->getHor()+2)>>2));
6413  Int depthStartPosY = Clip3(0,   iPictureHeight - 1, iBlkY + ((mv->getVer()+2)>>2));
6414  Int depthEndPosX   = Clip3(0,   iPictureWidth - 1,  iBlkX + iBlkWidth - 1 + ((mv->getHor()+2)>>2));
6415  Int depthEndPosY   = Clip3(0,   iPictureHeight - 1, iBlkY + iBlkHeight - 1 + ((mv->getVer()+2)>>2));
6416
6417  Pel* depthTL  = pcBaseViewDepthPicYuv->getLumaAddr();
6418  Int depStride =  pcBaseViewDepthPicYuv->getStride();
6419
6420  Pel  maxDepthVal = 0;
6421  maxDepthVal = std::max( maxDepthVal, depthTL[ (depthStartPosY) * depStride + depthStartPosX ]);      // Left Top
6422  maxDepthVal = std::max( maxDepthVal, depthTL[ (depthEndPosY)   * depStride + depthStartPosX ]);      // Left Bottom
6423  maxDepthVal = std::max( maxDepthVal, depthTL[ (depthStartPosY) * depStride + depthEndPosX   ]);      // Right Top
6424  maxDepthVal = std::max( maxDepthVal, depthTL[ (depthEndPosY)   * depStride + depthEndPosX   ]);      // Right Bottom
6425
6426  return aiShiftLUT[ maxDepthVal ];
6427}
6428
6429Void TComDataCU::estimateDVFromDM(Int refViewIdx, UInt uiPartIdx, TComPic* picDepth, UInt uiPartAddr, TComMv* cMvPred )
6430{
6431  if (picDepth)
6432  {
6433    UInt uiAbsPartAddrCurrCU = m_uiAbsIdxInLCU + uiPartAddr;
6434    Int iWidth, iHeight;
6435    getPartIndexAndSize( uiPartIdx, uiPartAddr, iWidth, iHeight ); // The modified value of uiPartAddr won't be used any more
6436
6437    TComPicYuv* pcBaseViewDepthPicYuv = picDepth->getPicYuvRec();
6438    Int iBlkX = ( getAddr() % picDepth->getFrameWidthInCU() ) * g_uiMaxCUWidth  + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartAddrCurrCU ] ];
6439    Int iBlkY = ( getAddr() / picDepth->getFrameWidthInCU() ) * g_uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartAddrCurrCU ] ];
6440
6441    Int* aiShiftLUT = getSlice()->getDepthToDisparityB(refViewIdx );
6442
6443    Pel iDisp = getMcpFromDM( pcBaseViewDepthPicYuv, cMvPred, iBlkX, iBlkY, iWidth, iHeight, aiShiftLUT );
6444    cMvPred->setHor( iDisp );
6445    clipMv(*cMvPred);
6446  }
6447}
6448#endif //H_3D_NBDV_REF
6449
6450
6451Bool TComDataCU::xCheckSpatialNBDV( TComDataCU* pcTmpCU, UInt uiIdx, DisInfo* pNbDvInfo, Bool bSearchForMvpDv, IDVInfo* paIDVInfo, UInt uiMvpDvPos
6452#if H_3D_NBDV_REF
6453, Bool bDepthRefine
6454#endif
6455)
6456{
6457  if( pcTmpCU != NULL && !pcTmpCU->isIntra( uiIdx ) )
6458  {
6459    Bool bTmpIsSkipped = pcTmpCU->isSkipped( uiIdx );
6460    for(Int iList = 0; iList < (getSlice()->isInterB() ? 2: 1); iList ++)
6461    {
6462      RefPicList eRefPicList = RefPicList(iList);
6463      Int      refId = pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) ;
6464      TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
6465
6466      if( refId >= 0)
6467      {
6468        Int refViewIdx  = pcTmpCU->getSlice()->getRefPic(eRefPicList, refId)->getViewIndex();
6469        if (refViewIdx != m_pcSlice->getViewIndex()) 
6470        {
6471          clipMv(cMvPred);
6472          pNbDvInfo->m_acNBDV = cMvPred;
6473          pNbDvInfo->m_aVIdxCan = refViewIdx;
6474#if H_3D_NBDV_REF
6475          TComPic* picDepth = NULL;
6476          assert(getSlice()->getRefPic(eRefPicList, refId)->getPOC() == getSlice()->getPOC());         
6477#if H_3D_FCO_VSP_DONBDV_E0163
6478          picDepth  = getSlice()->getIvPic(true, getSlice()->getViewIndex() );
6479          if ( picDepth->getPicYuvRec() != NULL ) 
6480          {
6481            cMvPred.setZero();
6482          }
6483          else// Go back with virtual depth
6484          {
6485            picDepth = getSlice()->getIvPic (true, refViewIdx );
6486          }
6487          assert(picDepth != NULL);
6488#else
6489          picDepth   = getSlice()->getIvPic (true, refViewIdx );
6490          assert(picDepth != NULL);
6491#endif
6492          UInt uiPartIdx = 0;   //Notes from MTK: Please confirm that using 0 as partition index and partition address is correct for CU-level DoNBDV
6493          UInt uiPartAddr = 0;  //QC: confirmed
6494
6495          if (picDepth && bDepthRefine)
6496            estimateDVFromDM(refViewIdx, uiPartIdx, picDepth, uiPartAddr, &cMvPred );
6497
6498          pNbDvInfo->m_acDoNBDV = cMvPred;
6499#endif
6500          return true;
6501        }
6502        else if ( bSearchForMvpDv && cMvPred.getIDVFlag() && bTmpIsSkipped )
6503        {
6504          assert( uiMvpDvPos < IDV_CANDS );
6505          paIDVInfo->m_acMvCand[iList][ uiMvpDvPos ] = TComMv( cMvPred.getIDVHor(), cMvPred.getIDVVer() );
6506          //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.
6507          paIDVInfo->m_aVIdxCan[iList][ uiMvpDvPos ] = cMvPred.getIDVVId();
6508          paIDVInfo->m_bAvailab[iList][ uiMvpDvPos ] = true;
6509          paIDVInfo->m_bFound                        = true; 
6510        }
6511      }
6512    }
6513  }
6514  return false; 
6515}
6516 
6517Void TComDataCU::xDeriveRightBottomNbIdx(Int &riLCUIdxRBNb, Int &riPartIdxRBNb )
6518{
6519  UInt uiPartIdx = 0;
6520  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth(); 
6521  Int uiLCUIdx = getAddr();
6522
6523  UInt uiPartIdxRB;
6524  deriveRightBottomIdx(uiPartIdx, uiPartIdxRB ); 
6525  UInt uiAbsPartIdxTmp = g_auiZscanToRaster[uiPartIdxRB];
6526
6527  if (( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth() )>= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )
6528  {
6529    riLCUIdxRBNb  = -1;
6530    riPartIdxRBNb = -1;
6531  }
6532  else if(( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxTmp] + m_pcPic->getMinCUHeight() )>= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
6533  {
6534    riLCUIdxRBNb  = -1;
6535    riPartIdxRBNb = -1;
6536  }
6537  else
6538  {
6539    if ( ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
6540      ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
6541    {
6542      riPartIdxRBNb = g_auiRasterToZscan[ uiAbsPartIdxTmp + uiNumPartInCUWidth + 1 ];
6543      riLCUIdxRBNb  = uiLCUIdx; 
6544    }
6545    else if ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
6546    {
6547      riPartIdxRBNb = -1;
6548      riLCUIdxRBNb  = -1;
6549    }
6550    else if ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
6551    {
6552      riPartIdxRBNb = g_auiRasterToZscan[ uiAbsPartIdxTmp + 1 ];
6553      riLCUIdxRBNb = uiLCUIdx + 1;
6554    }
6555    else //is the right bottom corner of LCU                       
6556    {
6557      riPartIdxRBNb = -1;
6558      riLCUIdxRBNb  = -1;
6559    }
6560  }
6561}
6562
6563
6564Void TComDataCU::setDvInfoSubParts( DisInfo cDvInfo, UInt uiAbsPartIdx, UInt uiDepth )
6565{
6566  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
6567  for (UInt ui = 0; ui < uiCurrPartNumb; ui++ )
6568  {
6569    m_pDvInfo[uiAbsPartIdx + ui] = cDvInfo;
6570  }
6571}
6572#if H_3D_VSP
6573Void TComDataCU::setDvInfoSubParts( DisInfo cDvInfo, UInt uiAbsPartIdx, UInt uiPUIdx, UInt uiDepth )
6574{
6575  setSubPartT<DisInfo>( cDvInfo, m_pDvInfo, uiAbsPartIdx, uiDepth, uiPUIdx );
6576}
6577#endif
6578
6579Bool TComDataCU::xGetColDisMV( Int currCandPic, RefPicList eRefPicList, Int refidx, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv , Int & iTargetViewIdx, Int & iStartViewIdx )
6580{
6581
6582  RefPicList  eColRefPicList = REF_PIC_LIST_0;
6583  Int iColViewIdx, iColRefViewIdx;
6584  TComPic *pColPic = getSlice()->getRefPic( eRefPicList, refidx);
6585  TComDataCU *pColCU = pColPic->getCU( uiCUAddr );
6586  iColViewIdx = pColCU->getSlice()->getViewIndex();
6587  if (pColCU->getPic()==0||pColCU->getPartitionSize(uiPartUnitIdx)==SIZE_NONE||pColCU->isIntra(uiPartUnitIdx))
6588  {
6589    return false;
6590  }
6591  for (Int ilist = 0; ilist < (pColCU->getSlice()->isInterB()? 2:1); ilist++) 
6592  {
6593    if(pColCU->getSlice()->isInterB())
6594    {
6595      eColRefPicList = RefPicList(ilist);
6596    }
6597
6598    Int iColRefIdx = pColCU->getCUMvField(eColRefPicList)->getRefIdx(uiPartUnitIdx);
6599
6600    if (iColRefIdx < 0)
6601    {
6602      continue;
6603    }
6604
6605    iColRefViewIdx = pColCU->getSlice()->getRefPic(eColRefPicList, iColRefIdx)->getViewIndex();
6606
6607    if ( iColViewIdx    == iColRefViewIdx ) // temporal vector
6608    {
6609      continue;
6610    }
6611    else 
6612    {
6613      if(getPic()->isTempIVRefValid(currCandPic, ilist,  iColRefIdx))
6614      {
6615        rcMv = pColCU->getCUMvField(eColRefPicList)->getMv(uiPartUnitIdx);
6616        rcMv.setIDVFlag(0);
6617        iTargetViewIdx  = iColRefViewIdx ;
6618        iStartViewIdx   = iColViewIdx   ;
6619        return true;   
6620      }
6621    }
6622  }
6623
6624  return false;
6625}
6626#endif
6627#if  H_3D_FAST_TEXTURE_ENCODING
6628Void
6629TComDataCU::getIVNStatus       ( UInt uiPartIdx,  DisInfo* pDInfo, Bool& bIVFMerge, Int& iIVFMaxD)
6630{
6631  TComSlice*    pcSlice         = getSlice (); 
6632  Int iViewIndex = pDInfo->m_aVIdxCan;
6633  //--- get base CU/PU and check prediction mode ---
6634  TComPic*    pcBasePic   = pcSlice->getIvPic( false, iViewIndex );
6635  TComPicYuv* pcBaseRec   = pcBasePic->getPicYuvRec   ();
6636
6637  UInt          uiPartAddr;
6638  Int           iWidth;
6639  Int           iHeight;
6640  getPartIndexAndSize( uiPartIdx, uiPartAddr, iWidth, iHeight );
6641
6642  Int  iCurrPosX, iCurrPosY;
6643  pcBaseRec->getTopLeftSamplePos( getAddr(), getZorderIdxInCU() + uiPartAddr, iCurrPosX, iCurrPosY );
6644
6645  iCurrPosX  += ( ( iWidth  - 1 ) >> 1 );
6646  iCurrPosY  += ( ( iHeight - 1 ) >> 1 );
6647
6648  Bool depthRefineFlag = false; 
6649#if H_3D_NBDV_REF
6650  depthRefineFlag = m_pcSlice->getVPS()->getDepthRefinementFlag( m_pcSlice->getLayerIdInVps() ); 
6651#endif // H_3D_NBDV_REF
6652
6653  TComMv      cDv = depthRefineFlag ? pDInfo->m_acDoNBDV : pDInfo->m_acNBDV; 
6654
6655  Int         iBasePosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (cDv.getHor() + 2 ) >> 2 ) );
6656  Int         iBasePosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (cDv.getVer() + 2 ) >> 2 )); 
6657  Int         iBaseLPosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX - (iWidth >> 1) + ( (cDv.getHor() + 2 ) >> 2 ) );
6658  Int         iBaseLPosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (cDv.getVer() + 2 ) >> 2 )); 
6659  Int         iBaseRPosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + (iWidth >> 1) + 1 + ( (cDv.getHor() + 2 ) >> 2 ) );
6660  Int         iBaseRPosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (cDv.getVer() + 2 ) >> 2 )); 
6661  Int         iBaseUPosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (cDv.getHor() + 2 ) >> 2 ) );
6662  Int         iBaseUPosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY - (iHeight >> 1) + ( (cDv.getVer() + 2 ) >> 2 )); 
6663  Int         iBaseDPosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (cDv.getHor() + 2 ) >> 2 ) );
6664  Int         iBaseDPosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + (iHeight >> 1) + 1 + ( (cDv.getVer() + 2 ) >> 2 )); 
6665
6666  Int         iBaseCUAddr;
6667  Int         iBaseAbsPartIdx;
6668  Int         iBaseLCUAddr;
6669  Int         iBaseLAbsPartIdx;
6670  Int         iBaseRCUAddr;
6671  Int         iBaseRAbsPartIdx;
6672  Int         iBaseUCUAddr;
6673  Int         iBaseUAbsPartIdx;
6674  Int         iBaseDCUAddr;
6675  Int         iBaseDAbsPartIdx;
6676  pcBaseRec->getCUAddrAndPartIdx( iBasePosX , iBasePosY , iBaseCUAddr, iBaseAbsPartIdx );
6677  pcBaseRec->getCUAddrAndPartIdx( iBaseLPosX , iBaseLPosY , iBaseLCUAddr, iBaseLAbsPartIdx );
6678  pcBaseRec->getCUAddrAndPartIdx( iBaseRPosX , iBaseRPosY , iBaseRCUAddr, iBaseRAbsPartIdx );
6679  pcBaseRec->getCUAddrAndPartIdx( iBaseUPosX , iBaseUPosY , iBaseUCUAddr, iBaseUAbsPartIdx );
6680  pcBaseRec->getCUAddrAndPartIdx( iBaseDPosX , iBaseDPosY , iBaseDCUAddr, iBaseDAbsPartIdx );
6681  TComDataCU* pcBaseCU    = pcBasePic->getCU( iBaseCUAddr );
6682  TComDataCU* pcBaseLCU    = pcBasePic->getCU( iBaseLCUAddr );
6683  TComDataCU* pcBaseRCU    = pcBasePic->getCU( iBaseRCUAddr );
6684  TComDataCU* pcBaseUCU    = pcBasePic->getCU( iBaseUCUAddr );
6685  TComDataCU* pcBaseDCU    = pcBasePic->getCU( iBaseDCUAddr );
6686  bIVFMerge = pcBaseLCU->getMergeFlag( iBaseLAbsPartIdx ) && pcBaseCU->getMergeFlag( iBaseAbsPartIdx ) && pcBaseRCU->getMergeFlag( iBaseRAbsPartIdx ) && pcBaseUCU->getMergeFlag( iBaseUAbsPartIdx ) && pcBaseDCU->getMergeFlag( iBaseDAbsPartIdx );
6687  Int aiDepthL[5]; //depth level
6688  aiDepthL[0] = pcBaseCU->getDepth(iBaseAbsPartIdx);
6689  aiDepthL[1] = pcBaseLCU->getDepth(iBaseLAbsPartIdx);
6690  aiDepthL[2] = pcBaseRCU->getDepth(iBaseRAbsPartIdx);
6691  aiDepthL[3] = pcBaseUCU->getDepth(iBaseUAbsPartIdx);
6692  aiDepthL[4] = pcBaseDCU->getDepth(iBaseDAbsPartIdx);
6693  for (Int i = 0; i < 5; i++)
6694  {
6695    if (iIVFMaxD < aiDepthL[i])
6696      iIVFMaxD = aiDepthL[i];
6697  }
6698}
6699#endif
6700
6701#if H_3D_SPIVMP
6702Void TComDataCU::getSPPara(Int iPUWidth, Int iPUHeight, Int& iNumSP, Int& iNumSPInOneLine, Int& iSPWidth, Int& iSPHeight)
6703{
6704  Int iSubPUSize = 1<<getSlice()->getVPS()->getSubPULog2Size(getSlice()->getLayerId());
6705  if( getSlice()->getIsDepth() )
6706  {
6707    iSubPUSize = 1 << getSlice()->getVPS()->getSubPUMPILog2Size();
6708  }
6709
6710  iNumSPInOneLine = iPUWidth/iSubPUSize;
6711  iNumSPInOneLine = iNumSPInOneLine < 1 ? 1: iNumSPInOneLine;
6712  Int iNumSPInOneColumn = iPUHeight/iSubPUSize;
6713  iNumSPInOneColumn = iNumSPInOneColumn < 1 ? 1: iNumSPInOneColumn;
6714  iNumSP = iNumSPInOneLine * iNumSPInOneColumn;
6715
6716  iSPWidth = iNumSPInOneLine == 1 ? iPUWidth: iSubPUSize; 
6717  iSPHeight = iNumSPInOneColumn == 1 ? iPUHeight: iSubPUSize; 
6718}
6719
6720Void TComDataCU::getSPAbsPartIdx(UInt uiBaseAbsPartIdx, Int iWidth, Int iHeight, Int iPartIdx, Int iNumPartLine, UInt& ruiPartAddr )
6721{
6722  uiBaseAbsPartIdx += m_uiAbsIdxInLCU;
6723  Int iBasePelX = g_auiRasterToPelX[g_auiZscanToRaster[uiBaseAbsPartIdx]];
6724  Int iBasePelY = g_auiRasterToPelY[g_auiZscanToRaster[uiBaseAbsPartIdx]];
6725  Int iCurrPelX = iBasePelX + iPartIdx%iNumPartLine * iWidth;
6726  Int iCurrPelY = iBasePelY + iPartIdx/iNumPartLine * iHeight;
6727  Int iCurrRaster = iCurrPelY / getPic()->getMinCUHeight() * getPic()->getNumPartInWidth() + iCurrPelX/getPic()->getMinCUWidth();
6728  ruiPartAddr = g_auiRasterToZscan[iCurrRaster];
6729  ruiPartAddr -= m_uiAbsIdxInLCU; 
6730}
6731
6732Void TComDataCU::setInterDirSP( UInt uiDir, UInt uiAbsPartIdx, Int iWidth, Int iHeight )
6733{
6734  uiAbsPartIdx += getZorderIdxInCU();
6735  Int iStartPelX = g_auiRasterToPelX[g_auiZscanToRaster[uiAbsPartIdx]];
6736  Int iStartPelY = g_auiRasterToPelY[g_auiZscanToRaster[uiAbsPartIdx]];
6737  Int iEndPelX = iStartPelX + iWidth;
6738  Int iEndPelY = iStartPelY + iHeight;
6739
6740  Int iCurrRaster, uiPartAddr;
6741
6742  for (Int i=iStartPelY; i<iEndPelY; i+=getPic()->getMinCUHeight())
6743  {
6744    for (Int j=iStartPelX; j < iEndPelX; j += getPic()->getMinCUWidth())
6745    {
6746      iCurrRaster = i / getPic()->getMinCUHeight() * getPic()->getNumPartInWidth() + j/getPic()->getMinCUWidth();
6747      uiPartAddr = g_auiRasterToZscan[iCurrRaster];
6748      uiPartAddr -= getZorderIdxInCU(); 
6749
6750      m_puhInterDir[uiPartAddr] = uiDir;
6751    }
6752  }
6753}
6754#endif
6755
6756#if H_3D_IV_MERGE
6757Bool
6758TComDataCU::getInterViewMergeCands(UInt uiPartIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv, DisInfo* pDInfo, Int* availableMcDc , Bool bIsDepth           
6759#if H_3D_SPIVMP
6760, TComMvField* pcMvFieldSP, UChar* puhInterDirSP
6761#endif
6762)
6763{
6764  TComSlice*    pcSlice = getSlice (); 
6765  Int iViewIndex        = pDInfo->m_aVIdxCan;
6766
6767  //--- get base CU/PU and check prediction mode ---
6768  TComPic*    pcBasePic   = pcSlice->getIvPic( bIsDepth, iViewIndex );
6769  TComPicYuv* pcBaseRec   = pcBasePic->getPicYuvRec   ();
6770
6771  UInt          uiPartAddr;
6772  Int           iWidth;
6773  Int           iHeight;
6774  getPartIndexAndSize( uiPartIdx, uiPartAddr, iWidth, iHeight );
6775
6776  Int  iCurrPosX, iCurrPosY;
6777  pcBaseRec->getTopLeftSamplePos( getAddr(), getZorderIdxInCU() + uiPartAddr, iCurrPosX, iCurrPosY );
6778
6779#if !H_3D_SPIVMP
6780  iCurrPosX  += ( iWidth  >> 1 );
6781  iCurrPosY  += ( iHeight >> 1 );
6782#endif
6783
6784  Bool depthRefineFlag = false; 
6785#if H_3D_NBDV_REF
6786  depthRefineFlag = m_pcSlice->getVPS()->getDepthRefinementFlag( m_pcSlice->getLayerIdInVps() ); 
6787#endif // H_3D_NBDV_REF
6788
6789  TComMv      cDv = depthRefineFlag ? pDInfo->m_acDoNBDV : pDInfo->m_acNBDV; 
6790
6791  Bool abPdmAvailable[8] =  {false, false, false, false, false, false, false, false};
6792#if H_3D_NBDV
6793  for( Int i = 0; i < 8; i++)
6794  {
6795    pacPdmMv[i].setIDVFlag   (false);
6796  }
6797#endif
6798
6799#if H_3D_SPIVMP
6800  ////////////////////////////////
6801  //////////sub-PU IvMC///////////
6802  ////////////////////////////////
6803  if(!m_pcSlice->getIsDepth())
6804  {
6805    if( getPartitionSize(0) == SIZE_2Nx2N )
6806    {
6807      Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight;
6808      getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight);
6809
6810      for (Int i=0; i<iNumSP; i++)
6811      {
6812        puhInterDirSP[i] = 0;
6813        pcMvFieldSP[2*i].getMv().set(0, 0);
6814        pcMvFieldSP[2*i+1].getMv().set(0,0);
6815        pcMvFieldSP[2*i].setRefIdx(-1);
6816        pcMvFieldSP[2*i+1].setRefIdx(-1);
6817      }
6818
6819      Int         iBaseCUAddr;
6820      Int         iBaseAbsPartIdx;
6821      TComDataCU* pcBaseCU;
6822      Int iPartition = 0;
6823
6824      Int iDelX = iSPWidth/2;
6825      Int iDelY = iSPHeight/2;
6826
6827      Int         iCenterPosX = iCurrPosX + ( ( iWidth /  iSPWidth ) >> 1 )  * iSPWidth + ( iSPWidth >> 1 );
6828      Int         iCenterPosY = iCurrPosY + ( ( iHeight /  iSPHeight ) >> 1 )  * iSPHeight + (iSPHeight >> 1);
6829      Int         iRefCenterCUAddr, iRefCenterAbsPartIdx;
6830
6831      if(iWidth == iSPWidth && iHeight == iSPHeight)
6832      {
6833        iCenterPosX = iCurrPosX + (iWidth >> 1);
6834        iCenterPosY = iCurrPosY + (iHeight >> 1);
6835      }
6836
6837      Int iRefCenterPosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCenterPosX + ( (cDv.getHor() + 2 ) >> 2 ) );
6838      Int iRefCenterPosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCenterPosY + ( (cDv.getVer() + 2 ) >> 2 ) ); 
6839
6840      pcBaseRec->getCUAddrAndPartIdx( iRefCenterPosX , iRefCenterPosY , iRefCenterCUAddr, iRefCenterAbsPartIdx );
6841      TComDataCU* pcDefaultCU    = pcBasePic->getCU( iRefCenterCUAddr );
6842      if(!( pcDefaultCU->getPredictionMode( iRefCenterAbsPartIdx ) == MODE_INTRA ))
6843      {
6844        for( UInt uiCurrRefListId = 0; uiCurrRefListId < 2; uiCurrRefListId++ )       
6845        {
6846          RefPicList  eCurrRefPicList = RefPicList( uiCurrRefListId );
6847          Bool stopLoop = false;
6848          for(Int iLoop = 0; iLoop < 2 && !stopLoop; ++iLoop)
6849          {
6850            RefPicList eDefaultRefPicList = (iLoop ==1)? RefPicList( 1 -  uiCurrRefListId ) : RefPicList( uiCurrRefListId );
6851            TComMvField cDefaultMvField;
6852            pcDefaultCU->getMvField( pcDefaultCU, iRefCenterAbsPartIdx, eDefaultRefPicList, cDefaultMvField );
6853            Int         iDefaultRefIdx     = cDefaultMvField.getRefIdx();
6854            if (iDefaultRefIdx >= 0)
6855            {
6856              Int iDefaultRefPOC = pcDefaultCU->getSlice()->getRefPOC(eDefaultRefPicList, iDefaultRefIdx);
6857              if (iDefaultRefPOC != pcSlice->getPOC())   
6858              {
6859                for (Int iPdmRefIdx = 0; iPdmRefIdx < pcSlice->getNumRefIdx( eCurrRefPicList ); iPdmRefIdx++)
6860                {
6861                  if (iDefaultRefPOC == pcSlice->getRefPOC(eCurrRefPicList, iPdmRefIdx))
6862                  {
6863                    abPdmAvailable[ uiCurrRefListId ] = true;
6864                    TComMv cMv(cDefaultMvField.getHor(), cDefaultMvField.getVer());
6865#if H_3D_NBDV
6866#if H_3D_IV_MERGE
6867                    if( !bIsDepth )
6868                    {
6869#endif
6870                      cMv.setIDVFlag   (true);
6871                      cMv.setIDVHor    (cDv.getHor());                 
6872                      cMv.setIDVVer    (cDv.getVer()); 
6873                      cMv.setIDVVId    (iViewIndex); 
6874#if H_3D_IV_MERGE
6875                    }
6876#endif
6877#endif
6878                    clipMv( cMv );
6879                    paiPdmRefIdx  [ uiCurrRefListId ] = iPdmRefIdx;
6880                    pacPdmMv      [ uiCurrRefListId ] = cMv;
6881                    stopLoop = true;
6882                    break;
6883                  }
6884                }
6885              }
6886            }
6887          }
6888        }
6889      }
6890      availableMcDc[0] = ( abPdmAvailable[0]? 1 : 0) + (abPdmAvailable[1]? 2 : 0);
6891
6892      if(availableMcDc[0])
6893      {
6894
6895        Int         iBasePosX, iBasePosY;
6896        for (Int i=iCurrPosY; i < iCurrPosY + iHeight; i += iSPHeight)
6897        {
6898          for (Int j = iCurrPosX; j < iCurrPosX + iWidth; j += iSPWidth)
6899          {
6900            iBasePosX   = Clip3( 0, pcBaseRec->getWidth () - 1, j + iDelX + ( (cDv.getHor() + 2 ) >> 2 ));
6901            iBasePosY   = Clip3( 0, pcBaseRec->getHeight() - 1, i + iDelY + ( (cDv.getVer() + 2 ) >> 2 )); 
6902
6903            pcBaseRec->getCUAddrAndPartIdx( iBasePosX , iBasePosY, iBaseCUAddr, iBaseAbsPartIdx );
6904            pcBaseCU    = pcBasePic->getCU( iBaseCUAddr );
6905            if(!( pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) == MODE_INTRA ))
6906            {
6907              for( UInt uiCurrRefListId = 0; uiCurrRefListId < 2; uiCurrRefListId++ )
6908              {
6909                RefPicList  eCurrRefPicList = RefPicList( uiCurrRefListId );
6910                Bool bLoop_stop = false;
6911                for(Int iLoop = 0; iLoop < 2 && !bLoop_stop; ++iLoop)
6912                {
6913                  RefPicList eBaseRefPicList = (iLoop ==1)? RefPicList( 1 -  uiCurrRefListId ) : RefPicList( uiCurrRefListId );
6914                  TComMvField cBaseMvField;
6915                  pcBaseCU->getMvField( pcBaseCU, iBaseAbsPartIdx, eBaseRefPicList, cBaseMvField );
6916                  Int         iBaseRefIdx     = cBaseMvField.getRefIdx();
6917                  if (iBaseRefIdx >= 0)
6918                  {
6919                    Int iBaseRefPOC = pcBaseCU->getSlice()->getRefPOC(eBaseRefPicList, iBaseRefIdx);
6920                    if (iBaseRefPOC != pcSlice->getPOC())   
6921                    {
6922                      for (Int iPdmRefIdx = 0; iPdmRefIdx < pcSlice->getNumRefIdx( eCurrRefPicList ); iPdmRefIdx++)
6923                      {
6924                        if (iBaseRefPOC == pcSlice->getRefPOC(eCurrRefPicList, iPdmRefIdx))
6925                        {
6926                          abPdmAvailable[ uiCurrRefListId ] = true;
6927                          TComMv cMv(cBaseMvField.getHor(), cBaseMvField.getVer());
6928
6929                          if( !bIsDepth )
6930                          {
6931                            cMv.setIDVFlag   (true);
6932                            cMv.setIDVHor    (cDv.getHor());                 
6933                            cMv.setIDVVer    (cDv.getVer()); 
6934                            cMv.setIDVVId    (iViewIndex); 
6935                          }
6936
6937                          clipMv( cMv );
6938                          bLoop_stop = true;
6939
6940                          pcMvFieldSP[2*iPartition + uiCurrRefListId].setMvField(cMv, iPdmRefIdx);
6941                          break;
6942                        }
6943                      }
6944                    }
6945                  }
6946                }
6947              }
6948            }
6949
6950            puhInterDirSP[iPartition] = (pcMvFieldSP[2*iPartition].getRefIdx()!=-1 ? 1: 0) + (pcMvFieldSP[2*iPartition+1].getRefIdx()!=-1 ? 2: 0);
6951            if (puhInterDirSP[iPartition] == 0)
6952            {
6953              puhInterDirSP[iPartition] = availableMcDc[0];
6954              pcMvFieldSP[2*iPartition].setMvField(pacPdmMv[0], paiPdmRefIdx[0]);
6955              pcMvFieldSP[2*iPartition + 1].setMvField(pacPdmMv[1], paiPdmRefIdx[1]);
6956
6957            }
6958            iPartition ++;
6959          }
6960        }
6961      }
6962    }
6963
6964    iCurrPosX  += ( iWidth  >> 1 );
6965    iCurrPosY  += ( iHeight >> 1 );
6966  }
6967#endif
6968
6969  ////////////////////////////////
6970  /////// IvMC + IvMCShift ///////
6971  ////////////////////////////////
6972
6973#if H_3D_SPIVMP
6974  if(m_pcSlice->getIsDepth())
6975  {
6976    iCurrPosX  += ( iWidth  >> 1 );
6977    iCurrPosY  += ( iHeight >> 1 );
6978  }
6979  for(Int iLoopCan = ( (m_pcSlice->getIsDepth() || getPartitionSize(uiPartAddr) != SIZE_2Nx2N) ? 0 : 1 ); iLoopCan < ( 2 - m_pcSlice->getIsDepth() ); iLoopCan ++) 
6980#else
6981  for(Int iLoopCan = 0; iLoopCan < 2; iLoopCan ++)
6982#endif
6983  {
6984    // iLoopCan == 0 --> IvMC
6985    // iLoopCan == 1 --> IvMCShift
6986
6987    Int         iBaseCUAddr;
6988    Int         iBaseAbsPartIdx;
6989
6990    Int offsetW = (iLoopCan == 0) ? 0 : ( ((iWidth /2)*4) + 4 );
6991    Int offsetH = (iLoopCan == 0) ? 0 : ( ((iHeight/2)*4) + 4 );
6992
6993    Int         iBasePosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (cDv.getHor() + offsetW + 2 ) >> 2 ) );
6994    Int         iBasePosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (cDv.getVer() + offsetH + 2 ) >> 2 ) ); 
6995    pcBaseRec->getCUAddrAndPartIdx( iBasePosX , iBasePosY , iBaseCUAddr, iBaseAbsPartIdx );
6996
6997    TComDataCU* pcBaseCU    = pcBasePic->getCU( iBaseCUAddr );
6998    if(!( pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) == MODE_INTRA ))
6999    {
7000      // Loop reference picture list of current slice (X in spec).
7001      for( UInt uiCurrRefListId = 0; uiCurrRefListId < 2; uiCurrRefListId++ )       
7002      {
7003        RefPicList  eCurrRefPicList = RefPicList( uiCurrRefListId );
7004
7005        Bool stopLoop = false;
7006        // Loop reference picture list of candidate slice (Y in spec)
7007        for(Int iLoop = 0; iLoop < 2 && !stopLoop; ++iLoop)
7008        {
7009          RefPicList eBaseRefPicList = (iLoop ==1)? RefPicList( 1 -  uiCurrRefListId ) : RefPicList( uiCurrRefListId );
7010          TComMvField cBaseMvField;
7011          pcBaseCU->getMvField( pcBaseCU, iBaseAbsPartIdx, eBaseRefPicList, cBaseMvField );
7012          Int         iBaseRefIdx     = cBaseMvField.getRefIdx();
7013          if (iBaseRefIdx >= 0)
7014          {
7015            Int iBaseRefPOC = pcBaseCU->getSlice()->getRefPOC(eBaseRefPicList, iBaseRefIdx);
7016            if (iBaseRefPOC != pcSlice->getPOC())   
7017            {
7018              for (Int iPdmRefIdx = 0; iPdmRefIdx < pcSlice->getNumRefIdx( eCurrRefPicList ); iPdmRefIdx++)
7019              {
7020                if (iBaseRefPOC == pcSlice->getRefPOC(eCurrRefPicList, iPdmRefIdx))
7021                {
7022                  abPdmAvailable[ (uiCurrRefListId + (iLoopCan<<2)) ] = true;
7023                  TComMv cMv(cBaseMvField.getHor(), cBaseMvField.getVer());
7024#if H_3D_NBDV
7025#if H_3D_IV_MERGE
7026                  if( !bIsDepth )
7027                  {
7028#endif
7029                    cMv.setIDVFlag   (true);
7030                    cMv.setIDVHor    (cDv.getHor());                 
7031                    cMv.setIDVVer    (cDv.getVer()); 
7032                    cMv.setIDVVId    (iViewIndex); 
7033#if H_3D_IV_MERGE
7034                  }
7035#endif
7036#endif
7037                  clipMv( cMv );
7038                  paiPdmRefIdx  [ (uiCurrRefListId + (iLoopCan<<2)) ] = iPdmRefIdx;
7039                  pacPdmMv      [ (uiCurrRefListId + (iLoopCan<<2)) ] = cMv;
7040                  stopLoop = true;
7041                  break;
7042                }
7043              }
7044            }
7045          }
7046        }
7047      }
7048    }
7049  }
7050#if H_3D_SPIVMP
7051  for(Int iLoopCan = ( 1 - m_pcSlice->getIsDepth() ); iLoopCan < ( 2 - m_pcSlice->getIsDepth() ); iLoopCan ++) 
7052#else
7053  for(Int iLoopCan = 0; iLoopCan < 2; iLoopCan ++)
7054#endif
7055  {
7056    availableMcDc[(iLoopCan << 1)] = ( abPdmAvailable[(iLoopCan<<2)] ? 1 : 0 ) + ( abPdmAvailable[1 + (iLoopCan<<2)] ? 2 : 0);
7057  }
7058
7059
7060  ////////////////////////////////
7061  /////// IvDC + IvDCShift ///////
7062  ////////////////////////////////
7063
7064  if( !getSlice()->getIsDepth() )
7065  {
7066    for( Int iRefListId = 0; iRefListId < 2 ; iRefListId++ )
7067    {
7068      RefPicList  eRefPicListDMV       = RefPicList( iRefListId );
7069      Int         iNumRefPics       = pcSlice->getNumRefIdx( eRefPicListDMV );
7070      for( Int iPdmRefIdx = 0; iPdmRefIdx < iNumRefPics; iPdmRefIdx++ )
7071      {
7072        if(( pcSlice->getRefPOC( eRefPicListDMV, iPdmRefIdx ) == pcSlice->getPOC()) && (pcSlice->getRefPic( eRefPicListDMV, iPdmRefIdx )->getViewIndex() == pDInfo->m_aVIdxCan))
7073        {
7074          for(Int iLoopCan = 0; iLoopCan < 2; iLoopCan ++)
7075          {
7076            Int ioffsetDV = (iLoopCan == 0) ? 0 : 4;
7077            abPdmAvailable[ iRefListId + 2 + (iLoopCan<<2) ] = true;
7078            paiPdmRefIdx  [ iRefListId + 2 + (iLoopCan<<2) ] = iPdmRefIdx;
7079#if H_3D_NBDV_REF
7080            TComMv cMv = depthRefineFlag ? pDInfo->m_acDoNBDV : pDInfo->m_acNBDV; 
7081#endif
7082            cMv.setHor( cMv.getHor() + ioffsetDV );
7083#if H_3D_IV_MERGE
7084            if( bIsDepth )
7085            {
7086              cMv.setHor((cMv.getHor()+2)>>2); 
7087            }
7088#endif
7089            cMv.setVer( 0 );
7090            clipMv( cMv );
7091            pacPdmMv      [iRefListId + 2 + (iLoopCan<<2)] = cMv;
7092          }
7093          break;
7094        }
7095      }
7096    }
7097    for(Int iLoopCan = 0; iLoopCan < 2; iLoopCan ++)
7098    {
7099      availableMcDc[1 + (iLoopCan << 1)] = ( abPdmAvailable[2 + (iLoopCan<<2)] ? 1 : 0 ) + ( abPdmAvailable[3 + (iLoopCan<<2)] ? 2 : 0 );
7100    }
7101  }
7102  return false;
7103}
7104#endif
7105#if H_3D_ARP
7106Void TComDataCU::setARPWSubParts ( UChar w, UInt uiAbsPartIdx, UInt uiDepth )
7107{
7108  assert( sizeof( *m_puhARPW) == 1 );
7109  memset( m_puhARPW + uiAbsPartIdx, w, m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ) );
7110}
7111#endif
7112
7113#if H_3D_IC
7114Void TComDataCU::setICFlagSubParts( Bool bICFlag, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
7115{
7116  memset( m_pbICFlag + uiAbsPartIdx, bICFlag, (m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ))*sizeof(Bool) );
7117}
7118
7119Bool TComDataCU::isICFlagRequired( UInt uiAbsPartIdx )
7120{
7121  UInt uiPartAddr;
7122  UInt iNumbPart;
7123
7124  if( !( getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) )
7125  {
7126    return false;
7127  }
7128
7129  if( getSlice()->getIcSkipParseFlag() )
7130  {
7131    if( getMergeFlag( uiAbsPartIdx ) && getMergeIndex( uiAbsPartIdx ) == 0 )
7132    {
7133      return false;
7134    }
7135  }
7136
7137  if( getMergeFlag( uiAbsPartIdx ) )
7138  {
7139    return true;
7140  }
7141
7142
7143  Int iWidth, iHeight;
7144
7145  iNumbPart = ( getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ? 1 : ( getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ? 4 : 2 ) );
7146
7147  for(UInt i = 0; i < iNumbPart; i++)
7148  {
7149    getPartIndexAndSize( i, uiPartAddr, iWidth, iHeight, uiAbsPartIdx, true );
7150    uiPartAddr += uiAbsPartIdx;
7151
7152    for(UInt uiRefIdx = 0; uiRefIdx < 2; uiRefIdx++)
7153    {
7154      RefPicList eRefList = uiRefIdx ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
7155      Int iBestRefIdx = getCUMvField(eRefList)->getRefIdx(uiPartAddr);
7156
7157      if( ( getInterDir( uiPartAddr ) & ( uiRefIdx+1 ) ) && iBestRefIdx >= 0 && getSlice()->getViewIndex() != getSlice()->getRefPic( eRefList, iBestRefIdx )->getViewIndex() )
7158      {
7159        return true;
7160      }
7161    }
7162  }
7163
7164  return false;
7165}
7166#endif
7167#if H_3D_DIM_DMM
7168Void TComDataCU::setDmmWedgeTabIdxSubParts( UInt tabIdx, UInt dmmType, UInt uiAbsPartIdx, UInt uiDepth )
7169{
7170  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
7171  for( UInt ui = 0; ui < uiCurrPartNumb; ui++ ) { m_dmmWedgeTabIdx[dmmType][uiAbsPartIdx+ui] = tabIdx; }
7172}
7173#endif
7174
7175#if H_3D_VSP
7176Void TComDataCU::setMvFieldPUForVSP( TComDataCU* pcCU, UInt partAddr, Int width, Int height, RefPicList eRefPicList, Int iRefIdx, Int &vspSize )
7177{
7178  // Get depth reference
7179  Int depthRefViewIdx = pcCU->getDvInfo(partAddr).m_aVIdxCan;
7180 
7181#if H_3D_FCO_VSP_DONBDV_E0163
7182  TComPic* pRefPicBaseDepth = 0;
7183  Bool     bIsCurrDepthCoded = false;
7184  pRefPicBaseDepth  = pcCU->getSlice()->getIvPic( true, pcCU->getSlice()->getViewIndex() );
7185  if ( pRefPicBaseDepth->getPicYuvRec() != NULL  ) 
7186  {
7187    bIsCurrDepthCoded = true;
7188  }
7189  else 
7190  {
7191    pRefPicBaseDepth = pcCU->getSlice()->getIvPic (true, depthRefViewIdx );
7192  }
7193#else
7194  TComPic* pRefPicBaseDepth = pcCU->getSlice()->getIvPic (true, depthRefViewIdx );
7195#endif
7196  assert(pRefPicBaseDepth != NULL);
7197  TComPicYuv* pcBaseViewDepthPicYuv = pRefPicBaseDepth->getPicYuvRec();
7198  assert(pcBaseViewDepthPicYuv != NULL);
7199  pcBaseViewDepthPicYuv->extendPicBorder();
7200
7201  // Get texture reference
7202  assert(iRefIdx >= 0);
7203  TComPic* pRefPicBaseTxt = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx );
7204  TComPicYuv* pcBaseViewTxtPicYuv = pRefPicBaseTxt->getPicYuvRec();
7205  assert(pcBaseViewTxtPicYuv != NULL);
7206
7207  // Initialize LUT according to the reference viewIdx
7208  Int txtRefViewIdx = pRefPicBaseTxt->getViewIndex();
7209  Int* pShiftLUT    = pcCU->getSlice()->getDepthToDisparityB( txtRefViewIdx );
7210  assert( txtRefViewIdx < pcCU->getSlice()->getViewIndex() );
7211
7212  // prepare Dv to access depth map or reference view
7213  TComMv cDv  = pcCU->getDvInfo(partAddr).m_acNBDV;
7214  pcCU->clipMv(cDv);
7215
7216#if H_3D_FCO_VSP_DONBDV_E0163
7217  if ( bIsCurrDepthCoded )
7218  {
7219      cDv.setZero();
7220  }
7221#endif
7222
7223  // fetch virtual depth map & convert depth to motion vector, which are stored in the motion memory
7224  xSetMvFieldForVSP( pcCU, pcBaseViewDepthPicYuv, &cDv, partAddr, width, height, pShiftLUT, eRefPicList, iRefIdx, pcCU->getSlice()->getIsDepth(), vspSize );
7225}
7226
7227Void TComDataCU::xSetMvFieldForVSP( TComDataCU *cu, TComPicYuv *picRefDepth, TComMv *dv, UInt partAddr, Int width, Int height, Int *shiftLUT, RefPicList refPicList, Int refIdx, Bool isDepth, Int &vspSize )
7228{
7229  TComCUMvField *cuMvField = cu->getCUMvField( refPicList );
7230  Int partAddrRasterSubPULine  = g_auiZscanToRaster[ partAddr ];
7231  Int numPartsLine    = cu->getPic()->getNumPartInWidth();
7232
7233  Int nTxtPerMvInfoX = 4; // cu->getPic()->getMinCUWidth();
7234  Int nTxtPerMvInfoY = 4; // cu->getPic()->getMinCUHeight();
7235
7236  Int refDepStride = picRefDepth->getStride();
7237
7238  TComMv tmpMv(0, 0);
7239  tmpMv.setIDVFlag(false);
7240
7241  Int refDepOffset  = ( (dv->getHor()+2) >> 2 ) + ( (dv->getVer()+2) >> 2 ) * refDepStride;
7242  Pel *refDepth     = picRefDepth->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refDepOffset;
7243
7244  if ((height % 8))
7245  {
7246    vspSize = 1; // 8x4
7247  }
7248  else if ((width % 8))
7249  {
7250    vspSize = 0; // 4x8
7251  }
7252  else
7253  {
7254    Bool ULvsBR, URvsBL;
7255    ULvsBR = refDepth[0]       < refDepth[refDepStride * (height-1) + width-1];
7256    URvsBL = refDepth[width-1] < refDepth[refDepStride * (height-1)];
7257    vspSize = ( ULvsBR ^ URvsBL ) ? 0 : 1;
7258  }
7259 
7260  Int subBlockW, subBlockH;
7261  if (vspSize)
7262  {
7263    subBlockW = 8;
7264    subBlockH = 4;
7265  }
7266  else
7267  {
7268    subBlockW = 4;
7269    subBlockH = 8;
7270  }
7271 
7272  Int numPartsInSubPUW = subBlockW / nTxtPerMvInfoX;
7273  Int numPartsInSubPUH = subBlockH / nTxtPerMvInfoY * numPartsLine;
7274
7275  for( Int y=0; y<height; y+=subBlockH, partAddrRasterSubPULine+=numPartsInSubPUH )
7276  {
7277    Pel *refDepthTmp[4];
7278    refDepthTmp[0] = refDepth + refDepStride * y;
7279    refDepthTmp[1] = refDepthTmp[0] + subBlockW - 1;
7280    refDepthTmp[2] = refDepthTmp[0] + refDepStride * (subBlockH - 1);
7281    refDepthTmp[3] = refDepthTmp[2] + subBlockW - 1;
7282
7283    Int partAddrRasterSubPU = partAddrRasterSubPULine;
7284    for( Int x=0; x<width; x+=subBlockW, partAddrRasterSubPU+=numPartsInSubPUW )
7285    {
7286      Pel  maxDepthVal;
7287      maxDepthVal = refDepthTmp[0][x];
7288      maxDepthVal = std::max( maxDepthVal, refDepthTmp[1][x]);
7289      maxDepthVal = std::max( maxDepthVal, refDepthTmp[2][x]);
7290      maxDepthVal = std::max( maxDepthVal, refDepthTmp[3][x]);
7291      tmpMv.setHor( (Short) shiftLUT[ maxDepthVal ] );
7292
7293      Int partAddrRasterPartLine = partAddrRasterSubPU;
7294      for( Int sY=0; sY<numPartsInSubPUH; sY+=numPartsLine, partAddrRasterPartLine += numPartsLine )
7295      {
7296        Int partAddrRasterPart = partAddrRasterPartLine;
7297        for( Int sX=0; sX<numPartsInSubPUW; sX+=1, partAddrRasterPart++ )
7298        {
7299          cuMvField->setMv    ( g_auiRasterToZscan[ partAddrRasterPart ], tmpMv );
7300          cuMvField->setRefIdx( g_auiRasterToZscan[ partAddrRasterPart ], refIdx );
7301        }
7302      }
7303    }
7304  }
7305
7306  vspSize = (vspSize<<2)+1;
7307
7308}
7309#endif
7310
7311//! \}
Note: See TracBrowser for help on using the repository browser.