source: 3DVCSoftware/branches/HTM-11.2-dev1-Samsung/source/Lib/TLibCommon/TComDataCU.cpp @ 989

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

Integration of JCT3V-I0086: Simplification of Shifted DV Candidate

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