source: 3DVCSoftware/branches/HTM-10.2-dev0/source/Lib/TLibCommon/TComDataCU.cpp @ 888

Last change on this file since 888 was 888, checked in by ntt, 10 years ago

bug fix for ticket#54

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