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

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

Integration of JCT3V-I0100: vps_extension2 and slice_segment_header clean-up

  • Property svn:eol-style set to native
File size: 254.5 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license. 
5 *
6* Copyright (c) 2010-2014, ITU/ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/** \file     TComDataCU.cpp
35    \brief    CU data structure
36    \todo     not all entities are documented
37*/
38
39#include "TComDataCU.h"
40#include "TComPic.h"
41
42//! \ingroup TLibCommon
43//! \{
44
45#if ADAPTIVE_QP_SELECTION
46Int * TComDataCU::m_pcGlbArlCoeffY  = NULL;
47Int * TComDataCU::m_pcGlbArlCoeffCb = NULL;
48Int * TComDataCU::m_pcGlbArlCoeffCr = NULL;
49#endif
50
51// ====================================================================================================================
52// Constructor / destructor / create / destroy
53// ====================================================================================================================
54
55TComDataCU::TComDataCU()
56{
57  m_pcPic              = NULL;
58  m_pcSlice            = NULL;
59  m_puhDepth           = NULL;
60 
61  m_skipFlag           = NULL;
62
63  m_pePartSize         = NULL;
64  m_pePredMode         = NULL;
65  m_CUTransquantBypass = NULL;
66  m_puhWidth           = NULL;
67  m_puhHeight          = NULL;
68  m_phQP               = NULL;
69  m_pbMergeFlag        = NULL;
70  m_puhMergeIndex      = NULL;
71  m_puhLumaIntraDir    = NULL;
72  m_puhChromaIntraDir  = NULL;
73  m_puhInterDir        = NULL;
74  m_puhTrIdx           = NULL;
75  m_puhTransformSkip[0] = NULL;
76  m_puhTransformSkip[1] = NULL;
77  m_puhTransformSkip[2] = NULL;
78  m_puhCbf[0]          = NULL;
79  m_puhCbf[1]          = NULL;
80  m_puhCbf[2]          = NULL;
81  m_pcTrCoeffY         = NULL;
82  m_pcTrCoeffCb        = NULL;
83  m_pcTrCoeffCr        = NULL;
84#if ADAPTIVE_QP_SELECTION 
85  m_ArlCoeffIsAliasedAllocation = false;
86  m_pcArlCoeffY        = NULL;
87  m_pcArlCoeffCb       = NULL;
88  m_pcArlCoeffCr       = NULL;
89#endif
90 
91  m_pbIPCMFlag         = NULL;
92  m_pcIPCMSampleY      = NULL;
93  m_pcIPCMSampleCb     = NULL;
94  m_pcIPCMSampleCr     = NULL;
95
96  m_pcPattern          = NULL;
97 
98  m_pcCUAboveLeft      = NULL;
99  m_pcCUAboveRight     = NULL;
100  m_pcCUAbove          = NULL;
101  m_pcCULeft           = NULL;
102 
103  m_apcCUColocated[0]  = NULL;
104  m_apcCUColocated[1]  = NULL;
105 
106  m_apiMVPIdx[0]       = NULL;
107  m_apiMVPIdx[1]       = NULL;
108  m_apiMVPNum[0]       = NULL;
109  m_apiMVPNum[1]       = NULL;
110
111#if H_3D_DIM
112  for( Int i = 0; i < DIM_NUM_TYPE; i++ )
113  {
114    m_dimDeltaDC[i][0] = NULL; 
115    m_dimDeltaDC[i][1] = NULL;
116  }
117#if H_3D_DIM_DMM
118  for( Int i = 0; i < DMM_NUM_TYPE; i++ )
119  {
120    m_dmmWedgeTabIdx[i] = NULL;
121  }
122#endif
123#if H_3D_DIM_SDC
124  m_pbSDCFlag             = NULL;
125  m_apSegmentDCOffset[0]  = NULL;
126  m_apSegmentDCOffset[1]  = NULL;
127#endif
128#endif
129  m_bDecSubCu          = false;
130  m_sliceStartCU        = 0;
131  m_sliceSegmentStartCU = 0;
132#if H_3D_NBDV
133  m_pDvInfo              = NULL;
134#endif
135#if H_3D_VSP
136  m_piVSPFlag            = NULL;
137#endif
138#if H_3D_SPIVMP
139  m_pbSPIVMPFlag         = NULL;
140#endif
141#if H_3D_ARP
142  m_puhARPW              = NULL;
143#endif
144#if H_3D_IC
145  m_pbICFlag             = NULL;
146#endif
147#if H_3D_INTER_SDC
148#endif
149#if H_3D_DBBP
150  m_pbDBBPFlag         = NULL;
151#endif
152
153#if H_3D_DDD
154  m_pucDisparityDerivedDepth = NULL;
155  m_pbUseDDD = NULL;
156#endif
157}
158
159TComDataCU::~TComDataCU()
160{
161}
162
163Void TComDataCU::create(UInt uiNumPartition, UInt uiWidth, UInt uiHeight, Bool bDecSubCu, Int unitSize
164#if ADAPTIVE_QP_SELECTION
165                        , Bool bGlobalRMARLBuffer
166#endif                                             
167                        )
168{
169  m_bDecSubCu = bDecSubCu;
170 
171  m_pcPic              = NULL;
172  m_pcSlice            = NULL;
173  m_uiNumPartition     = uiNumPartition;
174  m_unitSize = unitSize;
175 
176  if ( !bDecSubCu )
177  {
178    m_phQP               = (Char*     )xMalloc(Char,     uiNumPartition);
179    m_puhDepth           = (UChar*    )xMalloc(UChar,    uiNumPartition);
180    m_puhWidth           = (UChar*    )xMalloc(UChar,    uiNumPartition);
181    m_puhHeight          = (UChar*    )xMalloc(UChar,    uiNumPartition);
182
183    m_skipFlag           = new Bool[ uiNumPartition ];
184
185    m_pePartSize         = new Char[ uiNumPartition ];
186    memset( m_pePartSize, SIZE_NONE,uiNumPartition * sizeof( *m_pePartSize ) );
187    m_pePredMode         = new Char[ uiNumPartition ];
188    m_CUTransquantBypass = new Bool[ uiNumPartition ];
189    m_pbMergeFlag        = (Bool*  )xMalloc(Bool,   uiNumPartition);
190    m_puhMergeIndex      = (UChar* )xMalloc(UChar,  uiNumPartition);
191#if H_3D_VSP
192    m_piVSPFlag          = (Char*  )xMalloc(Char,   uiNumPartition);
193#endif
194#if H_3D_SPIVMP
195    m_pbSPIVMPFlag       = (Bool*  )xMalloc(Bool,   uiNumPartition);
196#endif
197    m_puhLumaIntraDir    = (UChar* )xMalloc(UChar,  uiNumPartition);
198    m_puhChromaIntraDir  = (UChar* )xMalloc(UChar,  uiNumPartition);
199    m_puhInterDir        = (UChar* )xMalloc(UChar,  uiNumPartition);
200   
201    m_puhTrIdx           = (UChar* )xMalloc(UChar,  uiNumPartition);
202    m_puhTransformSkip[0] = (UChar* )xMalloc(UChar,  uiNumPartition);
203    m_puhTransformSkip[1] = (UChar* )xMalloc(UChar,  uiNumPartition);
204    m_puhTransformSkip[2] = (UChar* )xMalloc(UChar,  uiNumPartition);
205
206    m_puhCbf[0]          = (UChar* )xMalloc(UChar,  uiNumPartition);
207    m_puhCbf[1]          = (UChar* )xMalloc(UChar,  uiNumPartition);
208    m_puhCbf[2]          = (UChar* )xMalloc(UChar,  uiNumPartition);
209   
210    m_apiMVPIdx[0]       = new Char[ uiNumPartition ];
211    m_apiMVPIdx[1]       = new Char[ uiNumPartition ];
212    m_apiMVPNum[0]       = new Char[ uiNumPartition ];
213    m_apiMVPNum[1]       = new Char[ uiNumPartition ];
214    memset( m_apiMVPIdx[0], -1,uiNumPartition * sizeof( Char ) );
215    memset( m_apiMVPIdx[1], -1,uiNumPartition * sizeof( Char ) );
216   
217    m_pcTrCoeffY         = (TCoeff*)xMalloc(TCoeff, uiWidth*uiHeight);
218    m_pcTrCoeffCb        = (TCoeff*)xMalloc(TCoeff, uiWidth*uiHeight/4);
219    m_pcTrCoeffCr        = (TCoeff*)xMalloc(TCoeff, uiWidth*uiHeight/4);
220#if H_3D_NBDV
221    m_pDvInfo            = (DisInfo* )xMalloc(DisInfo,  uiNumPartition);
222#endif
223    memset( m_pcTrCoeffY, 0,uiWidth*uiHeight * sizeof( TCoeff ) );
224    memset( m_pcTrCoeffCb, 0,uiWidth*uiHeight/4 * sizeof( TCoeff ) );
225    memset( m_pcTrCoeffCr, 0,uiWidth*uiHeight/4 * sizeof( TCoeff ) );
226#if ADAPTIVE_QP_SELECTION   
227    if( bGlobalRMARLBuffer )
228    {
229      if( m_pcGlbArlCoeffY == NULL )
230      {
231        m_pcGlbArlCoeffY   = (Int*)xMalloc(Int, uiWidth*uiHeight);
232        m_pcGlbArlCoeffCb  = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
233        m_pcGlbArlCoeffCr  = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
234      }
235      m_pcArlCoeffY        = m_pcGlbArlCoeffY;
236      m_pcArlCoeffCb       = m_pcGlbArlCoeffCb;
237      m_pcArlCoeffCr       = m_pcGlbArlCoeffCr;
238      m_ArlCoeffIsAliasedAllocation = true;
239    }
240    else
241    {
242      m_pcArlCoeffY        = (Int*)xMalloc(Int, uiWidth*uiHeight);
243      m_pcArlCoeffCb       = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
244      m_pcArlCoeffCr       = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
245    }
246#endif
247   
248    m_pbIPCMFlag         = (Bool*  )xMalloc(Bool, uiNumPartition);
249    m_pcIPCMSampleY      = (Pel*   )xMalloc(Pel , uiWidth*uiHeight);
250    m_pcIPCMSampleCb     = (Pel*   )xMalloc(Pel , uiWidth*uiHeight/4);
251    m_pcIPCMSampleCr     = (Pel*   )xMalloc(Pel , uiWidth*uiHeight/4);
252
253    m_acCUMvField[0].create( uiNumPartition );
254    m_acCUMvField[1].create( uiNumPartition );
255   
256#if H_3D_ARP
257    m_puhARPW            = new UChar[ uiNumPartition];
258#endif
259#if H_3D_IC
260    m_pbICFlag           = (Bool* )xMalloc(Bool,   uiNumPartition);
261#endif
262#if H_3D_DIM
263    for( Int i = 0; i < DIM_NUM_TYPE; i++ )
264    {
265      m_dimDeltaDC[i][0] = (Pel* )xMalloc(Pel, uiNumPartition); 
266      m_dimDeltaDC[i][1] = (Pel* )xMalloc(Pel, uiNumPartition);
267    }
268#if H_3D_DIM_DMM
269    for( Int i = 0; i < DMM_NUM_TYPE; i++ )
270    {
271      m_dmmWedgeTabIdx[i]    = (UInt*)xMalloc(UInt, uiNumPartition);
272    }
273#endif
274#if H_3D_DIM_SDC
275    m_pbSDCFlag             = (Bool*)xMalloc(Bool, uiNumPartition);
276    m_apSegmentDCOffset[0]  = (Pel*)xMalloc(Pel, uiNumPartition);
277    m_apSegmentDCOffset[1]  = (Pel*)xMalloc(Pel, uiNumPartition);
278#endif
279#endif
280#if H_3D_DBBP
281    m_pbDBBPFlag         = (Bool*  )xMalloc(Bool,   uiNumPartition);
282#endif
283  }
284  else
285  {
286    m_acCUMvField[0].setNumPartition(uiNumPartition );
287    m_acCUMvField[1].setNumPartition(uiNumPartition );
288  }
289  m_sliceStartCU        = (UInt*  )xMalloc(UInt, uiNumPartition);
290  m_sliceSegmentStartCU = (UInt*  )xMalloc(UInt, uiNumPartition);
291 
292  // create pattern memory
293  m_pcPattern            = (TComPattern*)xMalloc(TComPattern, 1);
294 
295#if H_3D_DDD
296  m_pucDisparityDerivedDepth         = (UChar*  )xMalloc( UChar,  uiNumPartition);
297  m_pbUseDDD                         = (Bool*  ) xMalloc( Bool,   uiNumPartition);
298#endif
299
300  // create motion vector fields
301 
302  m_pcCUAboveLeft      = NULL;
303  m_pcCUAboveRight     = NULL;
304  m_pcCUAbove          = NULL;
305  m_pcCULeft           = NULL;
306 
307  m_apcCUColocated[0]  = NULL;
308  m_apcCUColocated[1]  = NULL;
309}
310
311Void TComDataCU::destroy()
312{
313  m_pcPic              = NULL;
314  m_pcSlice            = NULL;
315 
316  if ( m_pcPattern )
317  { 
318    xFree(m_pcPattern);
319    m_pcPattern = NULL;
320  }
321 
322  // encoder-side buffer free
323  if ( !m_bDecSubCu )
324  {
325    if ( m_phQP               ) { xFree(m_phQP);                m_phQP              = NULL; }
326    if ( m_puhDepth           ) { xFree(m_puhDepth);            m_puhDepth          = NULL; }
327    if ( m_puhWidth           ) { xFree(m_puhWidth);            m_puhWidth          = NULL; }
328    if ( m_puhHeight          ) { xFree(m_puhHeight);           m_puhHeight         = NULL; }
329
330    if ( m_skipFlag           ) { delete[] m_skipFlag;          m_skipFlag          = NULL; }
331
332    if ( m_pePartSize         ) { delete[] m_pePartSize;        m_pePartSize        = NULL; }
333    if ( m_pePredMode         ) { delete[] m_pePredMode;        m_pePredMode        = NULL; }
334    if ( m_CUTransquantBypass ) { delete[] m_CUTransquantBypass;m_CUTransquantBypass = NULL; }
335    if ( m_puhCbf[0]          ) { xFree(m_puhCbf[0]);           m_puhCbf[0]         = NULL; }
336    if ( m_puhCbf[1]          ) { xFree(m_puhCbf[1]);           m_puhCbf[1]         = NULL; }
337    if ( m_puhCbf[2]          ) { xFree(m_puhCbf[2]);           m_puhCbf[2]         = NULL; }
338    if ( m_puhInterDir        ) { xFree(m_puhInterDir);         m_puhInterDir       = NULL; }
339    if ( m_pbMergeFlag        ) { xFree(m_pbMergeFlag);         m_pbMergeFlag       = NULL; }
340    if ( m_puhMergeIndex      ) { xFree(m_puhMergeIndex);       m_puhMergeIndex     = NULL; }
341#if H_3D_VSP
342    if ( m_piVSPFlag          ) { xFree(m_piVSPFlag);           m_piVSPFlag         = NULL; }
343#endif
344#if H_3D_SPIVMP
345    if ( m_pbSPIVMPFlag       ) { xFree(m_pbSPIVMPFlag);           m_pbSPIVMPFlag         = NULL; }
346#endif
347    if ( m_puhLumaIntraDir    ) { xFree(m_puhLumaIntraDir);     m_puhLumaIntraDir   = NULL; }
348    if ( m_puhChromaIntraDir  ) { xFree(m_puhChromaIntraDir);   m_puhChromaIntraDir = NULL; }
349    if ( m_puhTrIdx           ) { xFree(m_puhTrIdx);            m_puhTrIdx          = NULL; }
350    if ( m_puhTransformSkip[0]) { xFree(m_puhTransformSkip[0]); m_puhTransformSkip[0] = NULL; }
351    if ( m_puhTransformSkip[1]) { xFree(m_puhTransformSkip[1]); m_puhTransformSkip[1] = NULL; }
352    if ( m_puhTransformSkip[2]) { xFree(m_puhTransformSkip[2]); m_puhTransformSkip[2] = NULL; }
353    if ( m_pcTrCoeffY         ) { xFree(m_pcTrCoeffY);          m_pcTrCoeffY        = NULL; }
354    if ( m_pcTrCoeffCb        ) { xFree(m_pcTrCoeffCb);         m_pcTrCoeffCb       = NULL; }
355    if ( m_pcTrCoeffCr        ) { xFree(m_pcTrCoeffCr);         m_pcTrCoeffCr       = NULL; }
356#if ADAPTIVE_QP_SELECTION
357    if (!m_ArlCoeffIsAliasedAllocation)
358    {
359      xFree(m_pcArlCoeffY); m_pcArlCoeffY = 0;
360      xFree(m_pcArlCoeffCb); m_pcArlCoeffCb = 0;
361      xFree(m_pcArlCoeffCr); m_pcArlCoeffCr = 0;
362    }
363    if ( m_pcGlbArlCoeffY     ) { xFree(m_pcGlbArlCoeffY);      m_pcGlbArlCoeffY    = NULL; }
364    if ( m_pcGlbArlCoeffCb    ) { xFree(m_pcGlbArlCoeffCb);     m_pcGlbArlCoeffCb   = NULL; }
365    if ( m_pcGlbArlCoeffCr    ) { xFree(m_pcGlbArlCoeffCr);     m_pcGlbArlCoeffCr   = NULL; }
366#endif
367    if ( m_pbIPCMFlag         ) { xFree(m_pbIPCMFlag   );       m_pbIPCMFlag        = NULL; }
368    if ( m_pcIPCMSampleY      ) { xFree(m_pcIPCMSampleY);       m_pcIPCMSampleY     = NULL; }
369    if ( m_pcIPCMSampleCb     ) { xFree(m_pcIPCMSampleCb);      m_pcIPCMSampleCb    = NULL; }
370    if ( m_pcIPCMSampleCr     ) { xFree(m_pcIPCMSampleCr);      m_pcIPCMSampleCr    = NULL; }
371    if ( m_apiMVPIdx[0]       ) { delete[] m_apiMVPIdx[0];      m_apiMVPIdx[0]      = NULL; }
372    if ( m_apiMVPIdx[1]       ) { delete[] m_apiMVPIdx[1];      m_apiMVPIdx[1]      = NULL; }
373    if ( m_apiMVPNum[0]       ) { delete[] m_apiMVPNum[0];      m_apiMVPNum[0]      = NULL; }
374    if ( m_apiMVPNum[1]       ) { delete[] m_apiMVPNum[1];      m_apiMVPNum[1]      = NULL; }
375#if H_3D_NBDV
376    if ( m_pDvInfo            ) { xFree(m_pDvInfo);             m_pDvInfo           = NULL; }
377#endif
378
379#if H_3D_DDD
380    if ( m_pucDisparityDerivedDepth ) { xFree(m_pucDisparityDerivedDepth);          m_pucDisparityDerivedDepth        = NULL; }
381    if ( m_pbUseDDD                 ) { xFree(m_pbUseDDD);                          m_pbUseDDD                        = NULL; }
382#endif
383
384#if H_3D_ARP
385    if ( m_puhARPW            ) { delete[] m_puhARPW;           m_puhARPW           = NULL; }
386#endif
387#if H_3D_IC
388    if ( m_pbICFlag           ) { xFree(m_pbICFlag);            m_pbICFlag          = NULL; }
389#endif
390    m_acCUMvField[0].destroy();
391    m_acCUMvField[1].destroy();
392
393#if H_3D_DIM
394    for( Int i = 0; i < DIM_NUM_TYPE; i++ )
395    {
396      if ( m_dimDeltaDC[i][0] ) { xFree( m_dimDeltaDC[i][0] ); m_dimDeltaDC[i][0] = NULL; }
397      if ( m_dimDeltaDC[i][1] ) { xFree( m_dimDeltaDC[i][1] ); m_dimDeltaDC[i][1] = NULL; }
398    }
399#if H_3D_DIM_DMM
400    for( Int i = 0; i < DMM_NUM_TYPE; i++ )
401    {
402      if ( m_dmmWedgeTabIdx[i] ) { xFree( m_dmmWedgeTabIdx[i] ); m_dmmWedgeTabIdx[i] = NULL; }
403    }
404#endif
405#if H_3D_DIM_SDC
406    if ( m_pbSDCFlag            ) { xFree(m_pbSDCFlag);             m_pbSDCFlag             = NULL; }
407    if ( m_apSegmentDCOffset[0] ) { xFree(m_apSegmentDCOffset[0]);  m_apSegmentDCOffset[0]  = NULL; }
408    if ( m_apSegmentDCOffset[1] ) { xFree(m_apSegmentDCOffset[1]);  m_apSegmentDCOffset[1]  = NULL; }
409#endif   
410#endif   
411#if H_3D_DBBP
412    if ( m_pbDBBPFlag         ) { xFree(m_pbDBBPFlag);          m_pbDBBPFlag        = NULL; }
413#endif
414  }
415  m_pcCUAboveLeft       = NULL;
416  m_pcCUAboveRight      = NULL;
417  m_pcCUAbove           = NULL;
418  m_pcCULeft            = NULL;
419 
420  m_apcCUColocated[0]   = NULL;
421  m_apcCUColocated[1]   = NULL;
422
423  if( m_sliceStartCU )
424  {
425    xFree(m_sliceStartCU);
426    m_sliceStartCU=NULL;
427  }
428  if(m_sliceSegmentStartCU )
429  {
430    xFree(m_sliceSegmentStartCU);
431    m_sliceSegmentStartCU=NULL;
432  }
433}
434
435// ====================================================================================================================
436// Public member functions
437// ====================================================================================================================
438
439// --------------------------------------------------------------------------------------------------------------------
440// Initialization
441// --------------------------------------------------------------------------------------------------------------------
442
443/**
444 - initialize top-level CU
445 - internal buffers are already created
446 - set values before encoding a CU
447 .
448 \param  pcPic     picture (TComPic) class pointer
449 \param  iCUAddr   CU address
450 */
451Void TComDataCU::initCU( TComPic* pcPic, UInt iCUAddr )
452{
453
454  m_pcPic              = pcPic;
455  m_pcSlice            = pcPic->getSlice(pcPic->getCurrSliceIdx());
456  m_uiCUAddr           = iCUAddr;
457  m_uiCUPelX           = ( iCUAddr % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth;
458  m_uiCUPelY           = ( iCUAddr / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight;
459  m_uiAbsIdxInLCU      = 0;
460  m_dTotalCost         = MAX_DOUBLE;
461  m_uiTotalDistortion  = 0;
462  m_uiTotalBits        = 0;
463  m_uiTotalBins        = 0;
464  m_uiNumPartition     = pcPic->getNumPartInCU();
465 
466  for(Int i=0; i<pcPic->getNumPartInCU(); i++)
467  {
468    if(pcPic->getPicSym()->getInverseCUOrderMap(iCUAddr)*pcPic->getNumPartInCU()+i>=getSlice()->getSliceCurStartCUAddr())
469    {
470      m_sliceStartCU[i]=getSlice()->getSliceCurStartCUAddr();
471    }
472    else
473    {
474      m_sliceStartCU[i]=pcPic->getCU(getAddr())->m_sliceStartCU[i];
475    }
476  }
477  for(Int i=0; i<pcPic->getNumPartInCU(); i++)
478  {
479    if(pcPic->getPicSym()->getInverseCUOrderMap(iCUAddr)*pcPic->getNumPartInCU()+i>=getSlice()->getSliceSegmentCurStartCUAddr())
480    {
481      m_sliceSegmentStartCU[i]=getSlice()->getSliceSegmentCurStartCUAddr();
482    }
483    else
484    {
485      m_sliceSegmentStartCU[i]=pcPic->getCU(getAddr())->m_sliceSegmentStartCU[i];
486    }
487  }
488
489  Int partStartIdx = getSlice()->getSliceSegmentCurStartCUAddr() - pcPic->getPicSym()->getInverseCUOrderMap(iCUAddr) * pcPic->getNumPartInCU();
490
491  Int numElements = min<Int>( partStartIdx, m_uiNumPartition );
492  for ( Int ui = 0; ui < numElements; ui++ )
493  {
494    TComDataCU * pcFrom = pcPic->getCU(getAddr());
495    m_skipFlag[ui]   = pcFrom->getSkipFlag(ui);
496    m_pePartSize[ui] = pcFrom->getPartitionSize(ui);
497    m_pePredMode[ui] = pcFrom->getPredictionMode(ui);
498    m_CUTransquantBypass[ui] = pcFrom->getCUTransquantBypass(ui);
499    m_puhDepth[ui] = pcFrom->getDepth(ui);
500#if H_3D_ARP
501    m_puhARPW   [ui] = pcFrom->getARPW( ui );
502#endif
503#if H_3D_IC
504    m_pbICFlag[ui]   =  pcFrom->m_pbICFlag[ui];
505#endif
506
507#if H_3D_DDD
508    m_pucDisparityDerivedDepth[ui] = pcFrom->m_pucDisparityDerivedDepth[ui];
509    m_pbUseDDD[ui] = pcFrom->m_pbUseDDD[ui];
510#endif
511
512    m_puhWidth  [ui] = pcFrom->getWidth(ui);
513    m_puhHeight [ui] = pcFrom->getHeight(ui);
514    m_puhTrIdx  [ui] = pcFrom->getTransformIdx(ui);
515    m_puhTransformSkip[0][ui] = pcFrom->getTransformSkip(ui,TEXT_LUMA);
516    m_puhTransformSkip[1][ui] = pcFrom->getTransformSkip(ui,TEXT_CHROMA_U);
517    m_puhTransformSkip[2][ui] = pcFrom->getTransformSkip(ui,TEXT_CHROMA_V);
518    m_apiMVPIdx[0][ui] = pcFrom->m_apiMVPIdx[0][ui];;
519    m_apiMVPIdx[1][ui] = pcFrom->m_apiMVPIdx[1][ui];
520    m_apiMVPNum[0][ui] = pcFrom->m_apiMVPNum[0][ui];
521    m_apiMVPNum[1][ui] = pcFrom->m_apiMVPNum[1][ui];
522    m_phQP[ui]=pcFrom->m_phQP[ui];
523    m_pbMergeFlag[ui]=pcFrom->m_pbMergeFlag[ui];
524    m_puhMergeIndex[ui]=pcFrom->m_puhMergeIndex[ui];
525#if H_3D_VSP
526    m_piVSPFlag[ui] = pcFrom->m_piVSPFlag[ui];
527#endif
528#if H_3D_SPIVMP
529    m_pbSPIVMPFlag[ui] = pcFrom->m_pbSPIVMPFlag[ui];
530#endif
531    m_puhLumaIntraDir[ui]=pcFrom->m_puhLumaIntraDir[ui];
532    m_puhChromaIntraDir[ui]=pcFrom->m_puhChromaIntraDir[ui];
533    m_puhInterDir[ui]=pcFrom->m_puhInterDir[ui];
534    m_puhCbf[0][ui]=pcFrom->m_puhCbf[0][ui];
535    m_puhCbf[1][ui]=pcFrom->m_puhCbf[1][ui];
536    m_puhCbf[2][ui]=pcFrom->m_puhCbf[2][ui];
537    m_pbIPCMFlag[ui] = pcFrom->m_pbIPCMFlag[ui];
538#if H_3D_DIM_SDC
539    m_pbSDCFlag[ui] = pcFrom->m_pbSDCFlag[ui];
540#endif
541#if H_3D_DBBP
542    m_pbDBBPFlag[ui] = pcFrom->m_pbDBBPFlag[ui];
543#endif
544  }
545 
546  Int firstElement = max<Int>( partStartIdx, 0 );
547  numElements = m_uiNumPartition - firstElement;
548 
549  if ( numElements > 0 )
550  {
551    memset( m_skipFlag          + firstElement, false,                    numElements * sizeof( *m_skipFlag ) );
552
553    memset( m_pePartSize        + firstElement, SIZE_NONE,                numElements * sizeof( *m_pePartSize ) );
554    memset( m_pePredMode        + firstElement, MODE_NONE,                numElements * sizeof( *m_pePredMode ) );
555    memset( m_CUTransquantBypass+ firstElement, false,                    numElements * sizeof( *m_CUTransquantBypass) );
556    memset( m_puhDepth          + firstElement, 0,                        numElements * sizeof( *m_puhDepth ) );
557    memset( m_puhTrIdx          + firstElement, 0,                        numElements * sizeof( *m_puhTrIdx ) );
558    memset( m_puhTransformSkip[0] + firstElement, 0,                      numElements * sizeof( *m_puhTransformSkip[0]) );
559    memset( m_puhTransformSkip[1] + firstElement, 0,                      numElements * sizeof( *m_puhTransformSkip[1]) );
560    memset( m_puhTransformSkip[2] + firstElement, 0,                      numElements * sizeof( *m_puhTransformSkip[2]) );
561    memset( m_puhWidth          + firstElement, g_uiMaxCUWidth,           numElements * sizeof( *m_puhWidth ) );
562    memset( m_puhHeight         + firstElement, g_uiMaxCUHeight,          numElements * sizeof( *m_puhHeight ) );
563    memset( m_apiMVPIdx[0]      + firstElement, -1,                       numElements * sizeof( *m_apiMVPIdx[0] ) );
564    memset( m_apiMVPIdx[1]      + firstElement, -1,                       numElements * sizeof( *m_apiMVPIdx[1] ) );
565    memset( m_apiMVPNum[0]      + firstElement, -1,                       numElements * sizeof( *m_apiMVPNum[0] ) );
566    memset( m_apiMVPNum[1]      + firstElement, -1,                       numElements * sizeof( *m_apiMVPNum[1] ) );
567    memset( m_phQP              + firstElement, getSlice()->getSliceQp(), numElements * sizeof( *m_phQP ) );
568    memset( m_pbMergeFlag       + firstElement, false,                    numElements * sizeof( *m_pbMergeFlag ) );
569    memset( m_puhMergeIndex     + firstElement, 0,                        numElements * sizeof( *m_puhMergeIndex ) );
570#if H_3D_VSP
571    memset( m_piVSPFlag         + firstElement, 0,                        numElements * sizeof( *m_piVSPFlag ) );
572#endif
573#if H_3D_SPIVMP
574    memset( m_pbSPIVMPFlag      + firstElement, 0,                        numElements * sizeof( *m_pbSPIVMPFlag ) );
575#endif
576    memset( m_puhLumaIntraDir   + firstElement, DC_IDX,                   numElements * sizeof( *m_puhLumaIntraDir ) );
577    memset( m_puhChromaIntraDir + firstElement, 0,                        numElements * sizeof( *m_puhChromaIntraDir ) );
578    memset( m_puhInterDir       + firstElement, 0,                        numElements * sizeof( *m_puhInterDir ) );
579    memset( m_puhCbf[0]         + firstElement, 0,                        numElements * sizeof( *m_puhCbf[0] ) );
580    memset( m_puhCbf[1]         + firstElement, 0,                        numElements * sizeof( *m_puhCbf[1] ) );
581    memset( m_puhCbf[2]         + firstElement, 0,                        numElements * sizeof( *m_puhCbf[2] ) );
582    memset( m_pbIPCMFlag        + firstElement, false,                    numElements * sizeof( *m_pbIPCMFlag ) );
583#if H_3D_ARP
584    memset( m_puhARPW           + firstElement, 0,                        numElements * sizeof( UChar )         );
585#endif
586#if H_3D_IC
587    memset( m_pbICFlag          + firstElement, false,                    numElements * sizeof( *m_pbICFlag )   );
588#endif
589
590#if H_3D_DDD
591    memset( m_pucDisparityDerivedDepth        + firstElement, 0,           numElements * sizeof( *m_pucDisparityDerivedDepth ) );
592    memset( m_pbUseDDD                        + firstElement, 0,           numElements * sizeof( *m_pbUseDDD ) );
593#endif
594
595#if H_3D_DIM
596    for( Int i = 0; i < DIM_NUM_TYPE; i++ )
597    {
598      memset( m_dimDeltaDC[i][0] + firstElement, 0,                       numElements * sizeof( *m_dimDeltaDC[i][0] ) );
599      memset( m_dimDeltaDC[i][1] + firstElement, 0,                       numElements * sizeof( *m_dimDeltaDC[i][1] ) );
600    }
601#if H_3D_DIM_DMM
602    for( Int i = 0; i < DMM_NUM_TYPE; i++ )
603    {
604      memset( m_dmmWedgeTabIdx[i] + firstElement, 0,                      numElements * sizeof( *m_dmmWedgeTabIdx[i] ) );
605    }
606#endif
607#if H_3D_DIM_SDC
608    memset( m_pbSDCFlag             + firstElement,     0,                numElements * sizeof( *m_pbSDCFlag            ) );
609    memset( m_apSegmentDCOffset[0]  + firstElement,     0,                numElements * sizeof( *m_apSegmentDCOffset[0] ) );
610    memset( m_apSegmentDCOffset[1]  + firstElement,     0,                numElements * sizeof( *m_apSegmentDCOffset[1] ) );
611#endif
612    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    // IvDcShift (Derived from spatial Iv neighboring blocks)
3313    if( iLoop == 1 )
3314    {
3315      Int iFirDispCand = -1;
3316      TComMvField mvIvDcShift[2];
3317      UChar dirIvDcShift;
3318
3319      if (xGetPosFirstAvailDmvCand(MRG_IVSHIFT, iFirDispCand))
3320      {
3321        TComMv cMv;
3322        cMv = m_mergCands[iFirDispCand].m_cMvField[0].getMv();
3323        cMv.setHor(cMv.getHor()+4);
3324        if(m_pcSlice->getVPS()->getViewSynthesisPredFlag(m_pcSlice->getLayerIdInVps()))
3325        {
3326          cMv.setVer(0);
3327        }
3328#if !(NTT_BUG_FIX_TK54)
3329        clipMv( cMv );
3330#endif
3331
3332        dirIvDcShift = m_mergCands[iFirDispCand].m_uDir;
3333        mvIvDcShift[0].setMvField(cMv, m_mergCands[iFirDispCand].m_cMvField[0].getRefIdx() );
3334        mvIvDcShift[1].setMvField(m_mergCands[iFirDispCand].m_cMvField[1].getMv(), m_mergCands[iFirDispCand].m_cMvField[1].getRefIdx() );
3335        m_mergCands[MRG_IVSHIFT].setCand(mvIvDcShift, dirIvDcShift, false, false);
3336       
3337        if( mrgCandIdx == iCount ) 
3338        {
3339          return true;
3340        }
3341        iCount++;
3342        break;
3343      }
3344    }
3345
3346    /// iLoop = 0 --> IvMCShift
3347    /// iLoop = 1 --> IvDCShift  (Derived from IvDC)
3348    if(ivCandDir[iLoop + 2])
3349    {
3350      TComMvField tmpMV[2];
3351      UChar tmpDir = ivCandDir[iLoop + 2];
3352      if( ( ivCandDir[iLoop + 2] & 1 ) == 1 )
3353      {
3354        tmpMV[0].setMvField( ivCandMv[ (iLoop<<1) + 4 ], ivCandRefIdx[ (iLoop<<1) + 4 ] ); 
3355      }
3356      if( ( ivCandDir[iLoop + 2] & 2 ) == 2 )
3357      {
3358        tmpMV[1].setMvField( ivCandMv[ (iLoop<<1) + 5 ], ivCandRefIdx[ (iLoop<<1) + 5 ] );
3359      }
3360     
3361      // Prune IvMC vs. IvMcShift
3362      Bool bRemove = false;     
3363      if( !iLoop && ivCandDir[0] > 0)
3364      {
3365        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])
3366        {
3367            bRemove                         = true;
3368        }
3369      }
3370      if(!bRemove)
3371      {
3372#if H_3D_NBDV
3373        if(iLoop) // For IvMcShift candidate
3374        {
3375          tmpMV[0].getMv().setIDVFlag (false);
3376          tmpMV[1].getMv().setIDVFlag (false);
3377        }
3378#endif
3379        m_mergCands[MRG_IVSHIFT].setCand(tmpMV, tmpDir, false, false);
3380        if( mrgCandIdx == iCount )
3381        {
3382          return true;
3383        }
3384        iCount++;
3385      }
3386      break;
3387    }
3388  }
3389  return false;
3390} 
3391
3392inline Bool TComDataCU::xGetPosFirstAvailDmvCand(Int iCount, Int& posFirstAvailDmvCand )
3393{
3394  for ( Int currListPos = 0; currListPos < iCount; currListPos++ )
3395  {
3396    if ( !m_mergCands[currListPos].m_bAvailable || ( currListPos == MRG_IVMC ) || ( currListPos == MRG_IVDC ) || ( m_mergCands[currListPos].m_iVspFlag != 0 ))
3397    {
3398      continue;
3399    }
3400    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()))
3401    {
3402      posFirstAvailDmvCand = currListPos;
3403      return true;
3404    }
3405  }
3406  return false; 
3407}
3408                                     
3409#endif
3410
3411#if H_3D
3412Void TComDataCU::buildMCL(TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours
3413#if H_3D_VSP
3414  , Int* vspFlag
3415#endif
3416#if H_3D_SPIVMP
3417  , Bool* pbSPIVMPFlag
3418#endif
3419  , Int& numValidMergeCand
3420  )
3421{
3422  if (!( getSlice()->getIsDepth() || getSlice()->getViewIndex()>0))  // for only dependent texture
3423  {
3424    return;
3425  }
3426
3427  Int iCount = 0;
3428  TComMv cZeroMv;
3429
3430  // init temporal list
3431  TComMvField extMergeCandList[MRG_MAX_NUM_CANDS_MEM << 1];
3432  UChar uhInterDirNeighboursExt[MRG_MAX_NUM_CANDS_MEM];
3433  for( UInt ui = 0; ui < getSlice()->getMaxNumMergeCand(); ++ui )
3434  {
3435    uhInterDirNeighboursExt[ui] = puhInterDirNeighbours[ui];
3436    extMergeCandList[ui<<1].setMvField(cZeroMv, NOT_VALID);
3437    extMergeCandList[(ui<<1)+1].setMvField(cZeroMv, NOT_VALID);
3438    vspFlag[ui] = 0;
3439  }
3440
3441  // add candidates to temporal list
3442  // insert MPI ... IvShift candidate
3443  for (Int i=0; i<=MRG_IVSHIFT; i++)
3444  {
3445    if (m_mergCands[i].m_bAvailable)
3446    {
3447      m_mergCands[i].getCand(iCount, extMergeCandList, uhInterDirNeighboursExt, vspFlag, pbSPIVMPFlag);
3448      iCount++;
3449      if (iCount >= getSlice()->getMaxNumMergeCand())
3450        break;
3451    }
3452  }
3453
3454  // insert remaining base candidates
3455  while (iCount < getSlice()->getMaxNumMergeCand() && m_baseListidc < getSlice()->getMaxNumMergeCand())
3456  {
3457    uhInterDirNeighboursExt[iCount] = puhInterDirNeighbours[m_baseListidc];
3458    extMergeCandList[iCount<<1].setMvField(pcMvFieldNeighbours[m_baseListidc<<1].getMv(), pcMvFieldNeighbours[m_baseListidc<<1].getRefIdx());
3459    if ( getSlice()->isInterB() )
3460    {
3461      extMergeCandList[(iCount<<1)+1].setMvField(pcMvFieldNeighbours[(m_baseListidc<<1)+1].getMv(), pcMvFieldNeighbours[(m_baseListidc<<1)+1].getRefIdx());
3462    }
3463    m_baseListidc++;
3464    iCount++;
3465  }
3466
3467  for( UInt ui = 0; ui < getSlice()->getMaxNumMergeCand(); ui++ )
3468  {
3469    puhInterDirNeighbours[ui] = 0;
3470    pcMvFieldNeighbours[ui<<1].setMvField(cZeroMv, NOT_VALID);
3471    pcMvFieldNeighbours[(ui<<1)+1].setMvField(cZeroMv, NOT_VALID);
3472  }
3473  // copy extMergeCandList to output
3474  for( UInt ui = 0; ui < getSlice()->getMaxNumMergeCand(); ui++ )
3475  {
3476    puhInterDirNeighbours[ui] = uhInterDirNeighboursExt[ui];
3477    pcMvFieldNeighbours[ui<<1].setMvField(extMergeCandList[ui<<1].getMv(), extMergeCandList[ui<<1].getRefIdx());
3478    if ( getSlice()->isInterB() )
3479      pcMvFieldNeighbours[(ui<<1)+1].setMvField(extMergeCandList[(ui<<1)+1].getMv(), extMergeCandList[(ui<<1)+1].getRefIdx());
3480  }
3481  numValidMergeCand = iCount;
3482  assert(iCount == getSlice()->getMaxNumMergeCand());
3483}
3484
3485/** Constructs a list of merging candidates
3486 * \param uiAbsPartIdx
3487 * \param uiPUIdx
3488 * \param uiDepth
3489 * \param pcMvFieldNeighbours
3490 * \param puhInterDirNeighbours
3491 * \param numValidMergeCand
3492 */
3493// HM 12.0 based merge candidate list construction
3494
3495Void TComDataCU::getInterMergeCandidates( UInt uiAbsPartIdx, UInt uiPUIdx, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int& numValidMergeCand, Int mrgCandIdx )
3496{
3497
3498  UInt uiAbsPartAddr = m_uiAbsIdxInLCU + uiAbsPartIdx;
3499  Bool abCandIsInter[ MRG_MAX_NUM_CANDS_MEM ];
3500  TComMv cZeroMv;
3501  for( UInt ui = 0; ui < getSlice()->getMaxNumMergeCand(); ++ui )
3502  {
3503    abCandIsInter[ui] = false;
3504    pcMvFieldNeighbours[ ( ui << 1 )     ].setMvField(cZeroMv, NOT_VALID);
3505    pcMvFieldNeighbours[ ( ui << 1 ) + 1 ].setMvField(cZeroMv, NOT_VALID);
3506  }
3507  numValidMergeCand = getSlice()->getMaxNumMergeCand();
3508  // compute the location of the current PU
3509  Int xP, yP, nPSW, nPSH;
3510  this->getPartPosition(uiPUIdx, xP, yP, nPSW, nPSH);
3511
3512  Int iCount = 0;
3513
3514  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB;
3515  PartSize cCurPS = getPartitionSize( uiAbsPartIdx );
3516  deriveLeftRightTopIdxGeneral( uiAbsPartIdx, uiPUIdx, uiPartIdxLT, uiPartIdxRT );
3517  deriveLeftBottomIdxGeneral  ( uiAbsPartIdx, uiPUIdx, uiPartIdxLB );
3518
3519  //left
3520  UInt uiLeftPartIdx = 0;
3521  TComDataCU* pcCULeft = 0;
3522  pcCULeft = getPULeft( uiLeftPartIdx, uiPartIdxLB );
3523  Bool isAvailableA1 = pcCULeft &&
3524    pcCULeft->isDiffMER(xP -1, yP+nPSH-1, xP, yP) &&
3525    !( uiPUIdx == 1 && (cCurPS == SIZE_Nx2N || cCurPS == SIZE_nLx2N || cCurPS == SIZE_nRx2N) ) &&
3526    !pcCULeft->isIntra( uiLeftPartIdx ) ;
3527  if ( isAvailableA1 )
3528  {
3529    m_bAvailableFlagA1 = 1;
3530    abCandIsInter[iCount] = true;
3531    // get Inter Dir
3532    puhInterDirNeighbours[iCount] = pcCULeft->getInterDir( uiLeftPartIdx );
3533    // get Mv from Left
3534    pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3535    if ( getSlice()->isInterB() )
3536    {
3537      pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3538    }
3539
3540    iCount ++;
3541  }
3542 
3543  // early termination
3544  if (iCount == getSlice()->getMaxNumMergeCand()) 
3545  {
3546    return;
3547  }
3548  // above
3549  UInt uiAbovePartIdx = 0;
3550  TComDataCU* pcCUAbove = 0;
3551  pcCUAbove = getPUAbove( uiAbovePartIdx, uiPartIdxRT );
3552  Bool isAvailableB1 = pcCUAbove &&
3553  pcCUAbove->isDiffMER(xP+nPSW-1, yP-1, xP, yP) &&
3554  !( uiPUIdx == 1 && (cCurPS == SIZE_2NxN || cCurPS == SIZE_2NxnU || cCurPS == SIZE_2NxnD) ) &&
3555  !pcCUAbove->isIntra( uiAbovePartIdx );
3556  if ( isAvailableB1 && (!isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAbove, uiAbovePartIdx ) ) )
3557  {
3558    m_bAvailableFlagB1 = 1;
3559    abCandIsInter[iCount] = true;
3560    // get Inter Dir
3561    puhInterDirNeighbours[iCount] = pcCUAbove->getInterDir( uiAbovePartIdx );
3562    // get Mv from Left
3563    pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3564    if ( getSlice()->isInterB() )
3565    {
3566      pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3567    }
3568    if ( mrgCandIdx == iCount )
3569    {
3570      return;
3571    }
3572    iCount ++;
3573  }
3574  // early termination
3575  if (iCount == getSlice()->getMaxNumMergeCand()) 
3576  {
3577    return;
3578  }
3579
3580  // above right
3581  UInt uiAboveRightPartIdx = 0;
3582  TComDataCU* pcCUAboveRight = 0;
3583  pcCUAboveRight = getPUAboveRight( uiAboveRightPartIdx, uiPartIdxRT );
3584  Bool isAvailableB0 = pcCUAboveRight &&
3585  pcCUAboveRight->isDiffMER(xP+nPSW, yP-1, xP, yP) &&
3586  !pcCUAboveRight->isIntra( uiAboveRightPartIdx );
3587  if ( isAvailableB0 && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveRight, uiAboveRightPartIdx ) ) )
3588  {
3589    m_bAvailableFlagB0 = 1;
3590    abCandIsInter[iCount] = true;
3591    // get Inter Dir
3592    puhInterDirNeighbours[iCount] = pcCUAboveRight->getInterDir( uiAboveRightPartIdx );
3593    // get Mv from Left
3594    pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3595    if ( getSlice()->isInterB() )
3596    {
3597      pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3598    }
3599    if ( mrgCandIdx == iCount )
3600    {
3601      return;
3602    }
3603    iCount ++;
3604  }
3605  // early termination
3606  if (iCount == getSlice()->getMaxNumMergeCand()) 
3607  {
3608    return;
3609  }
3610
3611  //left bottom
3612  UInt uiLeftBottomPartIdx = 0;
3613  TComDataCU* pcCULeftBottom = 0;
3614  pcCULeftBottom = this->getPUBelowLeft( uiLeftBottomPartIdx, uiPartIdxLB );
3615  Bool isAvailableA0 = pcCULeftBottom &&
3616  pcCULeftBottom->isDiffMER(xP-1, yP+nPSH, xP, yP) &&
3617  !pcCULeftBottom->isIntra( uiLeftBottomPartIdx ) ;
3618  if ( isAvailableA0 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCULeftBottom, uiLeftBottomPartIdx ) ) )
3619  {
3620    m_bAvailableFlagA0 = 1;
3621    abCandIsInter[iCount] = true;
3622    // get Inter Dir
3623    puhInterDirNeighbours[iCount] = pcCULeftBottom->getInterDir( uiLeftBottomPartIdx );
3624    // get Mv from Left
3625    pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3626    if ( getSlice()->isInterB() )
3627    {
3628      pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3629    }
3630    if ( mrgCandIdx == iCount )
3631    {
3632      return;
3633    }
3634    iCount ++;
3635  }
3636  // early termination
3637  if (iCount == getSlice()->getMaxNumMergeCand()) 
3638  {
3639    return;
3640  }
3641  // above left
3642  if( iCount < 4 )
3643  {
3644    UInt uiAboveLeftPartIdx = 0;
3645    TComDataCU* pcCUAboveLeft = 0;
3646    pcCUAboveLeft = getPUAboveLeft( uiAboveLeftPartIdx, uiAbsPartAddr );
3647    Bool isAvailableB2 = pcCUAboveLeft &&
3648    pcCUAboveLeft->isDiffMER(xP-1, yP-1, xP, yP) &&
3649    !pcCUAboveLeft->isIntra( uiAboveLeftPartIdx );
3650    if ( isAvailableB2 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) )
3651        && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) ) )
3652    {
3653      m_bAvailableFlagB2 = 1;
3654      abCandIsInter[iCount] = true;
3655      // get Inter Dir
3656      puhInterDirNeighbours[iCount] = pcCUAboveLeft->getInterDir( uiAboveLeftPartIdx );
3657      // get Mv from Left
3658      pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3659      if ( getSlice()->isInterB() )
3660      {
3661        pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3662      }
3663      if ( mrgCandIdx == iCount )
3664      {
3665        return;
3666      }
3667      iCount ++;
3668    }
3669  }
3670  // early termination
3671  if (iCount == getSlice()->getMaxNumMergeCand()) 
3672  {
3673    return;
3674  }
3675  if ( getSlice()->getEnableTMVPFlag())
3676  {
3677    //>> MTK colocated-RightBottom
3678    UInt uiPartIdxRB;
3679
3680    deriveRightBottomIdx( uiPUIdx, uiPartIdxRB ); 
3681
3682    UInt uiAbsPartIdxTmp = g_auiZscanToRaster[uiPartIdxRB];
3683    UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
3684
3685    TComMv cColMv;
3686    Int iRefIdx;
3687    Int uiLCUIdx = -1;
3688
3689    if      ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
3690    {
3691    }
3692    else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxTmp] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
3693    {
3694    }
3695    else
3696    {
3697      if ( ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
3698        ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
3699      {
3700        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + uiNumPartInCUWidth + 1 ];
3701        uiLCUIdx = getAddr();
3702      }
3703      else if ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
3704      {
3705        uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdxTmp + uiNumPartInCUWidth + 1) % m_pcPic->getNumPartInCU() ];
3706      }
3707      else if ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
3708      {
3709        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + 1 ];
3710        uiLCUIdx = getAddr() + 1;
3711      }
3712      else //is the right bottom corner of LCU                       
3713      {
3714        uiAbsPartAddr = 0;
3715      }
3716    }
3717
3718    iRefIdx = 0;
3719    Bool bExistMV = false;
3720    UInt uiPartIdxCenter;
3721    UInt uiCurLCUIdx = getAddr();
3722    Int dir = 0;
3723    UInt uiArrayAddr = iCount;
3724    xDeriveCenterIdx( uiPUIdx, uiPartIdxCenter );
3725    bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_0, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx );
3726    if( bExistMV == false )
3727    {
3728      bExistMV = xGetColMVP( REF_PIC_LIST_0, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
3729    }
3730    if( bExistMV )
3731    {
3732      dir |= 1;
3733      pcMvFieldNeighbours[ 2 * uiArrayAddr ].setMvField( cColMv, iRefIdx );
3734    }
3735
3736    if ( getSlice()->isInterB() )
3737    {
3738#if H_3D_TMVP
3739      iRefIdx = 0;
3740#endif
3741      bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_1, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx);
3742      if( bExistMV == false )
3743      {
3744        bExistMV = xGetColMVP( REF_PIC_LIST_1, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
3745      }
3746      if( bExistMV )
3747      {
3748        dir |= 2;
3749        pcMvFieldNeighbours[ 2 * uiArrayAddr + 1 ].setMvField( cColMv, iRefIdx );
3750      }
3751    }
3752
3753    if (dir != 0)
3754    {
3755      puhInterDirNeighbours[uiArrayAddr] = dir;
3756      abCandIsInter[uiArrayAddr] = true;
3757#if H_3D_NBDV
3758      pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3759      pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3760#endif
3761      if ( mrgCandIdx == iCount )
3762      {
3763        return;
3764      }
3765      iCount++;
3766    }
3767  }
3768  // early termination
3769  if (iCount == getSlice()->getMaxNumMergeCand()) 
3770  {
3771    return;
3772  }
3773  UInt uiArrayAddr = iCount;
3774  UInt uiCutoff = uiArrayAddr;
3775 
3776  if ( getSlice()->isInterB() && iCount<5)  // JCT3V-F0129 by Qualcomm
3777  {
3778    UInt uiPriorityList0[12] = {0 , 1, 0, 2, 1, 2, 0, 3, 1, 3, 2, 3};
3779    UInt uiPriorityList1[12] = {1 , 0, 2, 0, 2, 1, 3, 0, 3, 1, 3, 2};
3780
3781    for (Int idx=0; idx<uiCutoff*(uiCutoff-1) && uiArrayAddr!= getSlice()->getMaxNumMergeCand(); idx++)
3782    {
3783      Int i = uiPriorityList0[idx]; Int j = uiPriorityList1[idx];
3784      if (abCandIsInter[i] && abCandIsInter[j]&& (puhInterDirNeighbours[i]&0x1)&&(puhInterDirNeighbours[j]&0x2))
3785      {
3786        abCandIsInter[uiArrayAddr] = true;
3787        puhInterDirNeighbours[uiArrayAddr] = 3;
3788
3789        // get Mv from cand[i] and cand[j]
3790        pcMvFieldNeighbours[uiArrayAddr << 1].setMvField(pcMvFieldNeighbours[i<<1].getMv(), pcMvFieldNeighbours[i<<1].getRefIdx());
3791        pcMvFieldNeighbours[( uiArrayAddr << 1 ) + 1].setMvField(pcMvFieldNeighbours[(j<<1)+1].getMv(), pcMvFieldNeighbours[(j<<1)+1].getRefIdx());
3792
3793        Int iRefPOCL0 = m_pcSlice->getRefPOC( REF_PIC_LIST_0, pcMvFieldNeighbours[(uiArrayAddr<<1)].getRefIdx() );
3794        Int iRefPOCL1 = m_pcSlice->getRefPOC( REF_PIC_LIST_1, pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getRefIdx() );
3795        if (iRefPOCL0 == iRefPOCL1 && pcMvFieldNeighbours[(uiArrayAddr<<1)].getMv() == pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getMv())
3796        {
3797          abCandIsInter[uiArrayAddr] = false;
3798        }
3799        else
3800        {
3801          uiArrayAddr++;
3802        }
3803      }
3804    }
3805  }
3806  // early termination
3807  if (uiArrayAddr == getSlice()->getMaxNumMergeCand()) 
3808  {
3809    return;
3810  }
3811 
3812  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);
3813  Int r = 0;
3814  Int refcnt = 0;
3815  while (uiArrayAddr < getSlice()->getMaxNumMergeCand())
3816  {
3817    abCandIsInter[uiArrayAddr] = true;
3818    puhInterDirNeighbours[uiArrayAddr] = 1;
3819    pcMvFieldNeighbours[uiArrayAddr << 1].setMvField( TComMv(0, 0), r);
3820
3821    if ( getSlice()->isInterB() )
3822    {
3823      puhInterDirNeighbours[uiArrayAddr] = 3;
3824      pcMvFieldNeighbours[(uiArrayAddr << 1) + 1].setMvField(TComMv(0, 0), r);
3825    }
3826    uiArrayAddr++;
3827    if ( refcnt == iNumRefIdx - 1 )
3828    {
3829      r = 0;
3830    }
3831    else
3832    {
3833      ++r;
3834      ++refcnt;
3835    }
3836  }
3837 
3838  numValidMergeCand = uiArrayAddr;
3839}
3840
3841
3842
3843/** Constructs a list of merging candidates
3844 * \param uiAbsPartIdx
3845 * \param uiPUIdx
3846 * \param uiDepth
3847 * \param pcMvFieldNeighbours
3848 * \param puhInterDirNeighbours
3849 * \param numValidMergeCand
3850 */
3851#if H_3D
3852Void TComDataCU::xGetInterMergeCandidates( UInt uiAbsPartIdx, UInt uiPUIdx, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours
3853#else
3854Void TComDataCU::getInterMergeCandidates( UInt uiAbsPartIdx, UInt uiPUIdx, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours
3855#endif
3856#if H_3D_VSP
3857      , InheritedVSPDisInfo*  inheritedVSPDisInfo
3858#endif
3859#if H_3D_SPIVMP
3860      , TComMvField* pcMvFieldSP, UChar* puhInterDirSP
3861#endif
3862      , Int& numValidMergeCand, Int mrgCandIdx
3863)
3864{
3865  UInt uiAbsPartAddr = m_uiAbsIdxInLCU + uiAbsPartIdx;
3866#if H_3D_IV_MERGE
3867  ////////////////////////////
3868  //////// INIT LISTS ////////
3869  ////////////////////////////
3870  TComMv cZeroMv;
3871#else
3872  Bool abCandIsInter[ MRG_MAX_NUM_CANDS ];
3873#endif
3874#if H_3D
3875  TComMvField tmpMV[2];
3876  UChar tmpDir;
3877
3878#if H_3D_DDD
3879  m_iUseDDDCandIdx = -1;
3880#endif
3881
3882  //////////////////////////////////
3883  //////// GET DISPARITIES  ////////
3884  //////////////////////////////////
3885  DisInfo cDisInfo = getDvInfo(uiAbsPartIdx);
3886  for(Int i = 0; i < MRG_MAX_NUM_CANDS_MEM; i++)
3887  {
3888    inheritedVSPDisInfo[i].m_acDvInfo = cDisInfo;   // To prevent run-time error, this code must be executed always for merging process.
3889  }
3890  m_cDefaultDisInfo = cDisInfo;
3891
3892  if (!( getSlice()->getIsDepth() || getSlice()->getViewIndex()>0))  // current slice is not both dependent view or depth
3893  {
3894    return;
3895  }
3896#else
3897  for( UInt ui = 0; ui < getSlice()->getMaxNumMergeCand(); ++ui )
3898  {
3899    abCandIsInter[ui] = false;
3900    pcMvFieldNeighbours[ ( ui << 1 )     ].setRefIdx(NOT_VALID);
3901    pcMvFieldNeighbours[ ( ui << 1 ) + 1 ].setRefIdx(NOT_VALID);
3902  }
3903#endif
3904
3905  numValidMergeCand = getSlice()->getMaxNumMergeCand();
3906#if H_3D
3907  //////////////////////////////////
3908  //////// DERIVE LOCATIONS ////////
3909  //////////////////////////////////
3910#endif
3911  // compute the location of the current PU
3912  Int xP, yP, nPSW, nPSH;
3913  this->getPartPosition(uiPUIdx, xP, yP, nPSW, nPSH);
3914
3915  Int iCount = 0;
3916
3917  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB;
3918#if !H_3D
3919  PartSize cCurPS = getPartitionSize( uiAbsPartIdx );
3920#endif
3921  deriveLeftRightTopIdxGeneral( uiAbsPartIdx, uiPUIdx, uiPartIdxLT, uiPartIdxRT );
3922  deriveLeftBottomIdxGeneral  ( uiAbsPartIdx, uiPUIdx, uiPartIdxLB );
3923#if H_3D
3924  Bool bMPIFlag   = getSlice()->getVPS()->getMPIFlag( getSlice()->getLayerIdInVps() );
3925  Bool bIsDepth = getSlice()->getIsDepth();
3926#endif
3927
3928#if H_3D_IC
3929  Bool bICFlag = getICFlag(uiAbsPartIdx);
3930#endif
3931#if H_3D_ARP
3932  Bool bARPFlag = getARPW(uiAbsPartIdx)>0 ? true : false;
3933#endif
3934#if H_3D_DBBP
3935  Bool bDBBPFlag = getDBBPFlag(uiAbsPartIdx);
3936  assert(bDBBPFlag == getDBBPFlag(0)); 
3937#endif
3938
3939#if H_3D
3940#if H_3D_NBDV
3941  for(Int i = 0; i < MRG_MAX_NUM_CANDS_MEM; i++) 
3942  {
3943    pcMvFieldNeighbours[i<<1    ].getMv().setIDVFlag (false);
3944    pcMvFieldNeighbours[(i<<1)+1].getMv().setIDVFlag (false);
3945  }
3946#endif
3947  // Clean version for MCL construction align with WD
3948  // init mergCands list
3949  for (Int i = 0; i<MRG_IVSHIFT+1; i++)
3950  {
3951    m_mergCands[i].init();
3952  }
3953
3954  m_baseListidc = 0;
3955
3956  //left
3957  UInt uiLeftPartIdx = 0;
3958  TComDataCU* pcCULeft = 0;
3959  pcCULeft = getPULeft( uiLeftPartIdx, uiPartIdxLB ); 
3960
3961  if (getAvailableFlagA1())
3962  {
3963    m_mergCands[MRG_A1].setCand( &pcMvFieldNeighbours[m_baseListidc<<1], puhInterDirNeighbours[m_baseListidc]
3964#if H_3D_VSP
3965    , 
3966      (pcCULeft->getVSPFlag(uiLeftPartIdx) != 0
3967#if H_3D_IC
3968      && !bICFlag
3969#endif
3970#if H_3D_ARP
3971      && !bARPFlag
3972#endif
3973#if H_3D_DBBP
3974      && !bDBBPFlag
3975#endif
3976      )
3977#endif
3978      , false
3979      ); 
3980    m_baseListidc++;
3981  }
3982
3983  // above
3984  UInt uiAbovePartIdx = 0;
3985  TComDataCU* pcCUAbove = 0;
3986  pcCUAbove = getPUAbove( uiAbovePartIdx, uiPartIdxRT );
3987
3988  if (getAvailableFlagB1())
3989  {
3990    m_mergCands[MRG_B1].setCand( &pcMvFieldNeighbours[m_baseListidc<<1], puhInterDirNeighbours[m_baseListidc]
3991#if H_3D_VSP
3992    ,
3993      ( ( ( getAddr() - pcCUAbove->getAddr() ) == 0) && (pcCUAbove->getVSPFlag(uiAbovePartIdx) != 0) 
3994#if H_3D_IC
3995      && !bICFlag
3996#endif
3997#if H_3D_ARP
3998      && !bARPFlag
3999#endif
4000#if H_3D_DBBP
4001      && !bDBBPFlag
4002#endif
4003      )
4004#endif
4005      , false
4006      ); 
4007    m_baseListidc++;
4008  }
4009
4010  // above right
4011  UInt uiAboveRightPartIdx = 0;
4012  TComDataCU* pcCUAboveRight = 0;
4013  pcCUAboveRight = getPUAboveRight( uiAboveRightPartIdx, uiPartIdxRT );
4014
4015  if (getAvailableFlagB0())
4016  {
4017    m_mergCands[MRG_B0].setCand( &pcMvFieldNeighbours[m_baseListidc<<1], puhInterDirNeighbours[m_baseListidc]
4018#if H_3D_VSP
4019    ,
4020      ( ( ( getAddr() - pcCUAboveRight->getAddr() ) == 0) && (pcCUAboveRight->getVSPFlag(uiAboveRightPartIdx) != 0) 
4021#if H_3D_IC
4022      && !bICFlag
4023#endif
4024#if H_3D_ARP
4025      && !bARPFlag
4026#endif
4027#if H_3D_DBBP
4028      && !bDBBPFlag
4029#endif
4030      )
4031#endif
4032      , false
4033      ); 
4034    m_baseListidc++;
4035  }
4036
4037  // left bottom
4038  UInt uiLeftBottomPartIdx = 0;
4039  TComDataCU* pcCULeftBottom = getPUBelowLeft( uiLeftBottomPartIdx, uiPartIdxLB );
4040
4041  if (getAvailableFlagA0())
4042  {
4043    m_mergCands[MRG_A0].setCand( &pcMvFieldNeighbours[m_baseListidc<<1], puhInterDirNeighbours[m_baseListidc]
4044#if H_3D_VSP
4045    ,
4046      (pcCULeftBottom->getVSPFlag(uiLeftBottomPartIdx) != 0
4047#if H_3D_IC
4048      && !bICFlag
4049#endif
4050#if H_3D_ARP
4051      && !bARPFlag
4052#endif
4053#if H_3D_DBBP
4054      && !bDBBPFlag
4055#endif
4056      )
4057#endif
4058      , false
4059      ); 
4060    m_baseListidc++;
4061  }
4062
4063  // above left
4064  UInt uiAboveLeftPartIdx = 0;
4065  TComDataCU* pcCUAboveLeft = 0;
4066  pcCUAboveLeft = getPUAboveLeft( uiAboveLeftPartIdx, uiAbsPartAddr );
4067
4068  if (getAvailableFlagB2())
4069  {
4070    m_mergCands[MRG_B2].setCand( &pcMvFieldNeighbours[m_baseListidc<<1], puhInterDirNeighbours[m_baseListidc]
4071#if H_3D_VSP
4072    ,
4073      ( ( ( getAddr() - pcCUAboveLeft->getAddr() ) == 0) && (pcCUAboveLeft->getVSPFlag(uiAboveLeftPartIdx) != 0) 
4074#if H_3D_IC
4075      && !bICFlag
4076#endif
4077#if H_3D_ARP
4078      && !bARPFlag
4079#endif
4080#if H_3D_DBBP
4081      && !bDBBPFlag
4082#endif
4083      )
4084#endif
4085      , false
4086      ); 
4087    m_baseListidc++;
4088  }
4089
4090#endif
4091
4092
4093#if H_3D_IV_MERGE
4094
4095  /////////////////////////////////////////////
4096  //////// TEXTURE MERGE CANDIDATE (T) ////////
4097  /////////////////////////////////////////////
4098
4099  bMPIFlag &= (nPSW + nPSH > 12);
4100  if( bMPIFlag)
4101  {
4102    tmpMV[0].setMvField( cZeroMv, NOT_VALID );
4103    tmpMV[1].setMvField( cZeroMv, NOT_VALID );
4104    tmpDir        =  0;
4105
4106    Bool bSPIVMPFlag = false;
4107
4108    TComPic * pcTexPic = m_pcSlice->getTexturePic();
4109#if H_3D_FCO
4110    if (pcTexturePic->getReconMark())
4111    {
4112#endif   
4113      TComPicYuv*   pcTexRec = pcTexPic->getPicYuvRec  ();
4114      UInt          uiPartAddr;
4115      Int           iWidth, iHeight;
4116      Int           iCurrPosX, iCurrPosY;
4117
4118      this->getPartIndexAndSize( uiPUIdx, uiPartAddr, iWidth, iHeight );
4119      pcTexRec->getTopLeftSamplePos( this->getAddr(), this->getZorderIdxInCU() + uiPartAddr, iCurrPosX, iCurrPosY );
4120
4121      Int iPUWidth, iPUHeight, iNumPart, iNumPartLine;
4122      this->getSPPara(iWidth, iHeight, iNumPart, iNumPartLine, iPUWidth, iPUHeight);
4123
4124      for (Int i=0; i<iNumPart; i++)
4125      {
4126        puhInterDirSP[i] = 0;
4127        pcMvFieldSP[2*i].getMv().set(0, 0);
4128        pcMvFieldSP[2*i+1].getMv().set(0, 0);
4129        pcMvFieldSP[2*i].setRefIdx(-1);
4130        pcMvFieldSP[2*i+1].setRefIdx(-1);
4131      }
4132
4133      Int         iTexCUAddr;
4134      Int         iTexAbsPartIdx;
4135      TComDataCU* pcTexCU;
4136      Int iPartition = 0;
4137      Int iInterDirSaved = 0;
4138      TComMvField cMvFieldSaved[2];
4139
4140      Int iOffsetX = iPUWidth/2;;
4141      Int iOffsetY = iPUHeight/2;
4142
4143      Int         iTexPosX, iTexPosY;
4144      const TComMv cMvRounding( 1 << ( 2 - 1 ), 1 << ( 2 - 1 ) );
4145     
4146      Int         iCenterPosX = iCurrPosX + ( ( iWidth /  iPUWidth ) >> 1 )  * iPUWidth + ( iPUWidth >> 1 );
4147      Int         iCenterPosY = iCurrPosY + ( ( iHeight /  iPUHeight ) >> 1 )  * iPUHeight + (iPUHeight >> 1);
4148      Int         iTexCenterCUAddr, iTexCenterAbsPartIdx;
4149
4150      if(iWidth == iPUWidth && iHeight == iPUHeight)
4151      {
4152          iCenterPosX = iCurrPosX + (iWidth >> 1);
4153          iCenterPosY = iCurrPosY + (iHeight >> 1);
4154      }
4155
4156      // derivation of center motion parameters from the collocated texture CU
4157
4158      pcTexRec->getCUAddrAndPartIdx( iCenterPosX , iCenterPosY , iTexCenterCUAddr, iTexCenterAbsPartIdx );
4159      TComDataCU* pcDefaultCU    = pcTexPic->getCU( iTexCenterCUAddr );
4160
4161      if( pcDefaultCU->getPredictionMode( iTexCenterAbsPartIdx ) != MODE_INTRA )
4162      {
4163        for( UInt uiCurrRefListId = 0; uiCurrRefListId < 2; uiCurrRefListId++ )
4164        {
4165          RefPicList  eCurrRefPicList = RefPicList( uiCurrRefListId );
4166
4167          TComMvField cDefaultMvField;
4168          pcDefaultCU->getMvField( pcDefaultCU, iTexCenterAbsPartIdx, eCurrRefPicList, cDefaultMvField );
4169          Int         iDefaultRefIdx     = cDefaultMvField.getRefIdx();
4170          if (iDefaultRefIdx >= 0)
4171          {
4172            Int iDefaultRefPOC = pcDefaultCU->getSlice()->getRefPOC(eCurrRefPicList, iDefaultRefIdx);
4173            for (Int iRefPicList = 0; iRefPicList < m_pcSlice->getNumRefIdx( eCurrRefPicList ); iRefPicList++)
4174            {
4175              if (iDefaultRefPOC == m_pcSlice->getRefPOC(eCurrRefPicList, iRefPicList))
4176              {
4177                bSPIVMPFlag = true;
4178                TComMv cMv = cDefaultMvField.getMv() + cMvRounding;
4179                cMv >>= 2;
4180                clipMv( cMv );
4181                cMvFieldSaved[eCurrRefPicList].setMvField(cMv, iRefPicList) ;
4182                break;
4183              }
4184            }
4185          }
4186        }
4187      }
4188      if ( bSPIVMPFlag == true )
4189      {   
4190          iInterDirSaved = (cMvFieldSaved[0].getRefIdx()!=-1 ? 1: 0) + (cMvFieldSaved[1].getRefIdx()!=-1 ? 2: 0);
4191          tmpDir = iInterDirSaved;
4192          tmpMV[0] = cMvFieldSaved[0];
4193          tmpMV[1] = cMvFieldSaved[1];
4194      }
4195
4196      if ( iInterDirSaved != 0 )
4197      {
4198        for (Int i=iCurrPosY; i < iCurrPosY + iHeight; i += iPUHeight)
4199        {
4200          for (Int j = iCurrPosX; j < iCurrPosX + iWidth; j += iPUWidth)
4201          {
4202            iTexPosX     = j + iOffsetX;
4203            iTexPosY     = i + iOffsetY; 
4204            pcTexRec->getCUAddrAndPartIdx( iTexPosX, iTexPosY, iTexCUAddr, iTexAbsPartIdx );
4205            pcTexCU  = pcTexPic->getCU( iTexCUAddr );
4206
4207            if( pcTexCU && !pcTexCU->isIntra(iTexAbsPartIdx) )
4208            {
4209              for( UInt uiCurrRefListId = 0; uiCurrRefListId < 2; uiCurrRefListId++ )
4210              {
4211                RefPicList  eCurrRefPicList = RefPicList( uiCurrRefListId );
4212                TComMvField cTexMvField;
4213                pcTexCU->getMvField( pcTexCU, iTexAbsPartIdx, eCurrRefPicList, cTexMvField );
4214                Int iValidDepRef = getPic()->isTextRefValid( eCurrRefPicList, cTexMvField.getRefIdx() );
4215                if( (cTexMvField.getRefIdx()>=0) && ( iValidDepRef >= 0 ) )
4216                {
4217                  TComMv cMv = cTexMvField.getMv() + cMvRounding;
4218                  cMv >>=2;         
4219#if !(NTT_BUG_FIX_TK54)
4220                  this->clipMv( cMv );
4221#endif
4222                  pcMvFieldSP[2*iPartition + uiCurrRefListId].setMvField(cMv, iValidDepRef);
4223                }
4224              }
4225            }
4226            puhInterDirSP[iPartition] = (pcMvFieldSP[2*iPartition].getRefIdx()!=-1 ? 1: 0) + (pcMvFieldSP[2*iPartition+1].getRefIdx()!=-1 ? 2: 0);
4227            if (puhInterDirSP[iPartition] == 0)
4228            {
4229              if (iInterDirSaved != 0)
4230              {
4231                puhInterDirSP[iPartition] = iInterDirSaved;
4232                pcMvFieldSP[2*iPartition] = cMvFieldSaved[0];
4233                pcMvFieldSP[2*iPartition + 1] = cMvFieldSaved[1];
4234              }
4235            }
4236            if (iPUHeight + iPUWidth == 12)
4237            {
4238              if (puhInterDirSP[iPartition] == 3)
4239              {
4240                puhInterDirSP[iPartition] = 1;
4241                pcMvFieldSP[2*iPartition + 1].setMvField(TComMv(0,0), -1);
4242              }
4243            }
4244
4245            iPartition ++;
4246          }
4247        }
4248#if H_3D
4249      }
4250#endif
4251#if H_3D_FCO
4252    }
4253#endif
4254    if( tmpDir != 0 )
4255    {
4256      Int iCnloop = 0;
4257      for(iCnloop = 0; iCnloop < 2; iCnloop ++)
4258      {
4259        if ( !m_mergCands[MRG_A1+iCnloop].m_bAvailable )  // prunning to A1, B1
4260        {
4261          continue;
4262        }
4263        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])
4264        {
4265          m_mergCands[MRG_A1+iCnloop].m_bAvailable = false;
4266          break;
4267        }     
4268      }
4269      m_mergCands[MRG_T].setCand( tmpMV, tmpDir, false, bSPIVMPFlag);
4270
4271      if ( mrgCandIdx == iCount )
4272      {
4273        return;
4274      }
4275      iCount ++;
4276    }
4277  }
4278#if H_3D_DDD
4279  if( m_pcSlice->getIsDepth() && m_pcSlice->getViewIndex() != 0  && bMPIFlag )
4280  {
4281    UInt uiPartIdx;
4282    TComDataCU *pcTextureCU = m_pcSlice->getTexturePic()->getCU( getAddr() );
4283    TComSlice *pcTextureSlice = pcTextureCU->getSlice(); 
4284
4285
4286    tmpMV[0].setMvField( cZeroMv, NOT_VALID );
4287    tmpMV[1].setMvField( cZeroMv, NOT_VALID );
4288    tmpDir = 0;
4289
4290    xDeriveCenterIdx( uiPUIdx, uiPartIdx); 
4291
4292    if ( pcTextureCU && !pcTextureCU->isIntra( uiPartIdx ) )
4293    {
4294
4295      TComMvField cMVField;
4296      Int iDV = 0;
4297      Int iViewIdx = 0;
4298      pcTextureCU->getMvField( pcTextureCU, uiPartIdx, REF_PIC_LIST_0, cMVField );
4299      if( cMVField.getRefIdx() >= 0 )
4300      {
4301        if( pcTextureSlice->getRefPOC( REF_PIC_LIST_0, cMVField.getRefIdx()) == pcTextureSlice->getPOC() )
4302        {
4303          iViewIdx = pcTextureSlice->getRefPic( REF_PIC_LIST_0, cMVField.getRefIdx())->getViewIndex();
4304          iDV = cMVField.getHor();
4305
4306
4307          Int iValidDepRef = getPic()->isTextRefValid( REF_PIC_LIST_0, cMVField.getRefIdx() );
4308
4309          if( iValidDepRef >= 0 )
4310          {
4311            const TComMv cAdd( 2, 2 );
4312            cMVField.getMv() += cAdd;
4313            cMVField.getMv() >>= 2;
4314#if !(NTT_BUG_FIX_TK54)
4315            clipMv( cMVField.getMv() );
4316#endif
4317            tmpMV[ 0 ].setMvField( cMVField.getMv(), iValidDepRef );
4318            tmpDir = 1;
4319          }
4320        }
4321      }
4322
4323      pcTextureCU->getMvField( pcTextureCU, uiPartIdx, REF_PIC_LIST_1, cMVField );
4324
4325      if( !tmpDir && cMVField.getRefIdx() >= 0 )
4326      {
4327        if( pcTextureSlice->getRefPOC( REF_PIC_LIST_1, cMVField.getRefIdx()) == pcTextureSlice->getPOC() )
4328        {
4329          iViewIdx = pcTextureSlice->getRefPic( REF_PIC_LIST_1, cMVField.getRefIdx())->getViewIndex();
4330          iDV = cMVField.getHor();
4331
4332          Int iValidDepRef = getPic()->isTextRefValid( REF_PIC_LIST_1, cMVField.getRefIdx() );
4333
4334          if( iValidDepRef >= 0 )
4335          {
4336            const TComMv cAdd( 2, 2 );
4337            cMVField.getMv() += cAdd;
4338            cMVField.getMv() >>= 2;
4339#if !(NTT_BUG_FIX_TK54)
4340            clipMv( cMVField.getMv() );
4341#endif
4342            tmpMV[ 1 ].setMvField( cMVField.getMv(), iValidDepRef );
4343            tmpDir = 2;
4344          }
4345        }
4346      }
4347      if( tmpDir != 0 )
4348      {
4349        m_ucDDTmpDepth = m_pcSlice->getDepthFromDV( iDV,  iViewIdx );
4350        m_iUseDDDCandIdx = iCount;
4351
4352        m_mergCands[MRG_D].setCand( tmpMV, tmpDir, false, false);
4353        if ( mrgCandIdx == iCount )
4354        {
4355          return;
4356        }
4357        iCount ++;
4358      }
4359    }
4360  }
4361#endif
4362  /////////////////////////////////////////////////////////////////
4363  //////// DERIVE IvMC, IvMCShift,IvDCShift, IvDC  Candidates /////
4364  /////////////////////////////////////////////////////////////////
4365
4366  // { IvMCL0, IvMCL1, IvDCL0, IvDCL1, IvMCL0Shift, IvMCL1Shift, IvDCL0Shift, IvDCL1Shift }; 
4367  // An enumerator would be appropriate here!
4368  TComMv ivCandMv    [8];
4369  Int    ivCandRefIdx[8] = {-1, -1, -1, -1, -1, -1, -1, -1};
4370
4371  // { IvMC, IvDC, IvMCShift, IvDCShift }; 
4372  Int    ivCandDir   [4] = {0, 0, 0, 0};
4373
4374  Bool ivMvPredFlag   = getSlice()->getVPS()->getIvMvPredFlag( getSlice()->getLayerIdInVps() );
4375
4376  ivMvPredFlag &= (nPSW + nPSH > 12);
4377  if ( ivMvPredFlag && cDisInfo.m_aVIdxCan!=-1)
4378  {
4379    getInterViewMergeCands(uiPUIdx, ivCandRefIdx, ivCandMv, &cDisInfo, ivCandDir , bIsDepth, pcMvFieldSP, puhInterDirSP, bICFlag );
4380  } 
4381
4382  ///////////////////////////////////////////////
4383  //////// INTER VIEW MOTION COMP(IvMC) /////////
4384  ///////////////////////////////////////////////
4385  if( getSlice()->getIsDepth() )
4386  {
4387    ivCandDir[1] = ivCandDir[2] = ivCandDir[3] = 0;
4388  }
4389
4390  if( ivCandDir[0] )
4391  {
4392    tmpMV[0].setMvField( cZeroMv, NOT_VALID );
4393    tmpMV[1].setMvField( cZeroMv, NOT_VALID );
4394
4395    if( ( ivCandDir[0] & 1 ) == 1 )
4396    {
4397      tmpMV[0].setMvField( ivCandMv[ 0 ], ivCandRefIdx[ 0 ] );
4398    }
4399    if( ( ivCandDir[0] & 2 ) == 2 )
4400    {
4401      tmpMV[1].setMvField( ivCandMv[ 1 ], ivCandRefIdx[ 1 ] );
4402    }
4403
4404    Bool bRemoveSpa = false; //pruning
4405
4406    if (!bIsDepth)
4407    {
4408      for(Int i = 0; i < 2; i ++)
4409      {
4410        if ( !m_mergCands[MRG_A1 + i].m_bAvailable ) // prunning to A1, B1
4411        {
4412          continue;
4413        }
4414        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])
4415        {
4416          m_mergCands[MRG_A1+i].m_bAvailable = false;
4417          break;
4418        }     
4419      }
4420    }
4421    if (bIsDepth)
4422    {
4423      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])
4424      {
4425        bRemoveSpa                      = true;
4426      }
4427    }
4428    if (!bRemoveSpa)
4429    {
4430      Bool SPIVMPFlag = false;
4431      if(!m_pcSlice->getIsDepth())
4432      {
4433        SPIVMPFlag = true;
4434      }
4435#if H_3D_DBBP
4436      SPIVMPFlag &= !bDBBPFlag;
4437#endif
4438
4439      m_mergCands[MRG_IVMC].setCand( tmpMV, ivCandDir[0], false, SPIVMPFlag);
4440
4441      if ( mrgCandIdx == iCount )
4442      {
4443        return;
4444      }
4445      iCount ++;
4446    }
4447  } 
4448
4449  // early termination
4450  if (iCount == getSlice()->getMaxNumMergeCand()) 
4451  {
4452    return;
4453  }
4454#endif
4455
4456#if H_3D
4457  iCount += m_mergCands[MRG_A1].m_bAvailable + m_mergCands[MRG_B1].m_bAvailable + m_mergCands[MRG_B0].m_bAvailable;
4458#else
4459  //left
4460  UInt uiLeftPartIdx = 0;
4461  TComDataCU* pcCULeft = 0;
4462  pcCULeft = getPULeft( uiLeftPartIdx, uiPartIdxLB );
4463  Bool isAvailableA1 = pcCULeft &&
4464    pcCULeft->isDiffMER(xP -1, yP+nPSH-1, xP, yP) &&
4465    !( uiPUIdx == 1 && (cCurPS == SIZE_Nx2N || cCurPS == SIZE_nLx2N || cCurPS == SIZE_nRx2N) ) &&
4466    !pcCULeft->isIntra( uiLeftPartIdx ) ;
4467  if ( isAvailableA1 )
4468  {
4469    abCandIsInter[iCount] = true;
4470    // get Inter Dir
4471    puhInterDirNeighbours[iCount] = pcCULeft->getInterDir( uiLeftPartIdx );
4472    // get Mv from Left
4473    pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
4474    if ( getSlice()->isInterB() )
4475    {
4476      pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
4477    }
4478
4479    if ( mrgCandIdx == iCount )
4480    {
4481      return;
4482    }
4483    iCount ++;
4484  }
4485
4486  // early termination
4487  if (iCount == getSlice()->getMaxNumMergeCand()) 
4488  {
4489    return;
4490  }
4491
4492  // above
4493  UInt uiAbovePartIdx = 0;
4494  TComDataCU* pcCUAbove = 0;
4495  pcCUAbove = getPUAbove( uiAbovePartIdx, uiPartIdxRT );
4496  Bool isAvailableB1 = pcCUAbove &&
4497    pcCUAbove->isDiffMER(xP+nPSW-1, yP-1, xP, yP) &&
4498    !( uiPUIdx == 1 && (cCurPS == SIZE_2NxN || cCurPS == SIZE_2NxnU || cCurPS == SIZE_2NxnD) ) &&
4499    !pcCUAbove->isIntra( uiAbovePartIdx );
4500  if ( isAvailableB1 && (!isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAbove, uiAbovePartIdx ) ) )
4501  {
4502    abCandIsInter[iCount] = true;
4503    // get Inter Dir
4504    puhInterDirNeighbours[iCount] = pcCUAbove->getInterDir( uiAbovePartIdx );
4505    // get Mv from Left
4506    pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
4507    if ( getSlice()->isInterB() )
4508    {
4509      pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
4510    }
4511
4512    if ( mrgCandIdx == iCount )
4513    {
4514      return;
4515    }
4516    iCount ++;
4517  }
4518  // early termination
4519  if (iCount == getSlice()->getMaxNumMergeCand()) 
4520  {
4521    return;
4522  }
4523
4524  // above right
4525  UInt uiAboveRightPartIdx = 0;
4526  TComDataCU* pcCUAboveRight = 0;
4527  pcCUAboveRight = getPUAboveRight( uiAboveRightPartIdx, uiPartIdxRT );
4528  Bool isAvailableB0 = pcCUAboveRight &&
4529    pcCUAboveRight->isDiffMER(xP+nPSW, yP-1, xP, yP) &&
4530    !pcCUAboveRight->isIntra( uiAboveRightPartIdx );
4531  if ( isAvailableB0 && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveRight, uiAboveRightPartIdx ) ) )
4532  {
4533    abCandIsInter[iCount] = true;
4534    // get Inter Dir
4535    puhInterDirNeighbours[iCount] = pcCUAboveRight->getInterDir( uiAboveRightPartIdx );
4536    // get Mv from Left
4537    pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
4538    if ( getSlice()->isInterB() )
4539    {
4540      pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
4541    }
4542
4543    if ( mrgCandIdx == iCount )
4544    {
4545      return;
4546    }
4547    iCount ++;
4548  }
4549  // early termination
4550  if (iCount == getSlice()->getMaxNumMergeCand()) 
4551  {
4552    return;
4553  }
4554#endif
4555
4556#if H_3D_DDD
4557  // early termination
4558  if ( iCount >= getSlice()->getMaxNumMergeCand()) 
4559  {
4560      return;
4561  }
4562#endif
4563
4564#if H_3D_IV_MERGE
4565  /////////////////////////////////////////////
4566  //////// INTER VIEW DISP COMP (IvDC) ////////
4567  /////////////////////////////////////////////
4568  if( ivCandDir[1] && iCount < getSlice()->getMaxNumMergeCand() && !getSlice()->getIsDepth() )
4569  {
4570    assert(iCount < getSlice()->getMaxNumMergeCand());
4571
4572    tmpMV[0].setMvField( cZeroMv, NOT_VALID );
4573    tmpMV[1].setMvField( cZeroMv, NOT_VALID );
4574    if( ( ivCandDir[1] & 1 ) == 1 )
4575    {
4576      tmpMV[0].setMvField( ivCandMv[ 2 ], ivCandRefIdx[ 2 ] );
4577    }
4578    if( ( ivCandDir[1] & 2 ) == 2 )
4579    {
4580      tmpMV[1].setMvField( ivCandMv[ 3 ], ivCandRefIdx[ 3 ] );
4581    }
4582
4583    Bool bRemoveSpa = false; //pruning to A1, B1
4584    for(Int i = 0; i < 2; i ++)
4585    {
4586      if ( !m_mergCands[MRG_A1+i].m_bAvailable ) 
4587      {
4588        continue;
4589      }
4590      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])
4591      {
4592        bRemoveSpa                      = true;
4593        break;
4594      }     
4595    }
4596    if(!bRemoveSpa)
4597    {
4598#if H_3D_NBDV
4599      tmpMV[0].getMv().setIDVFlag (false);
4600      tmpMV[1].getMv().setIDVFlag (false);
4601#endif
4602      m_mergCands[MRG_IVDC].setCand( tmpMV, ivCandDir[1], false, false);
4603
4604      if ( mrgCandIdx == iCount )
4605        return;
4606      iCount ++;
4607
4608      // early termination
4609      if (iCount == getSlice()->getMaxNumMergeCand()) 
4610      {
4611        return;
4612      }
4613    }
4614  } 
4615#endif // H_3D_IV_MERGE
4616
4617#if H_3D_VSP
4618  /////////////////////////////////////////////////
4619  //////// VIEW SYNTHESIS PREDICTION (VSP) ////////
4620  /////////////////////////////////////////////////
4621  if (iCount<getSlice()->getMaxNumMergeCand())
4622  {
4623
4624  if (
4625#if H_3D_IC
4626      !bICFlag &&
4627#endif
4628#if H_3D_ARP
4629      !bARPFlag &&
4630#endif
4631#if H_3D
4632      (nPSW + nPSH > 12) &&
4633#endif
4634#if H_3D_DBBP
4635      !bDBBPFlag &&
4636#endif
4637      xAddVspCand( mrgCandIdx, &cDisInfo, iCount ) )
4638  {
4639    return;
4640  }
4641
4642  // early termination
4643  if (iCount == getSlice()->getMaxNumMergeCand())
4644  {
4645    return;
4646  }
4647#endif
4648#if H_3D
4649  }
4650#endif
4651
4652#if H_3D
4653  iCount += m_mergCands[MRG_A0].m_bAvailable + m_mergCands[MRG_B2].m_bAvailable;
4654#else
4655  //left bottom
4656  UInt uiLeftBottomPartIdx = 0;
4657  TComDataCU* pcCULeftBottom = 0;
4658  pcCULeftBottom = this->getPUBelowLeft( uiLeftBottomPartIdx, uiPartIdxLB );
4659  Bool isAvailableA0 = pcCULeftBottom &&
4660  pcCULeftBottom->isDiffMER(xP-1, yP+nPSH, xP, yP) &&
4661  !pcCULeftBottom->isIntra( uiLeftBottomPartIdx ) ;
4662  if ( isAvailableA0 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCULeftBottom, uiLeftBottomPartIdx ) ) )
4663  {
4664    abCandIsInter[iCount] = true;
4665    // get Inter Dir
4666    puhInterDirNeighbours[iCount] = pcCULeftBottom->getInterDir( uiLeftBottomPartIdx );
4667    // get Mv from Left
4668    pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
4669    if ( getSlice()->isInterB() )
4670    {
4671      pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
4672    }
4673    if ( mrgCandIdx == iCount )
4674    {
4675      return;
4676    }
4677    iCount ++;
4678  }
4679  // early termination
4680  if (iCount == getSlice()->getMaxNumMergeCand()) 
4681  {
4682    return;
4683  }
4684
4685  // above left
4686  if( iCount < 4 )
4687  {
4688    UInt uiAboveLeftPartIdx = 0;
4689    TComDataCU* pcCUAboveLeft = 0;
4690    pcCUAboveLeft = getPUAboveLeft( uiAboveLeftPartIdx, uiAbsPartAddr );
4691    Bool isAvailableB2 = pcCUAboveLeft &&
4692    pcCUAboveLeft->isDiffMER(xP-1, yP-1, xP, yP) &&
4693    !pcCUAboveLeft->isIntra( uiAboveLeftPartIdx );
4694    if ( isAvailableB2 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) )
4695        && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) ) )
4696    {
4697      abCandIsInter[iCount] = true;
4698      // get Inter Dir
4699      puhInterDirNeighbours[iCount] = pcCUAboveLeft->getInterDir( uiAboveLeftPartIdx );
4700      // get Mv from Left
4701      pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
4702      if ( getSlice()->isInterB() )
4703      {
4704        pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
4705      }
4706      if ( mrgCandIdx == iCount )
4707      {
4708        return;
4709      }
4710      iCount ++;
4711    }
4712  }
4713  // early termination
4714  if (iCount == getSlice()->getMaxNumMergeCand()) 
4715  {
4716    return;
4717  }
4718#endif
4719
4720
4721#if H_3D_IV_MERGE
4722  ////////////////////////////////////////////////////
4723  //////// SHIFTED IV (IvMCShift + IvDCShift) ////////
4724  ////////////////////////////////////////////////////
4725  if(  ivMvPredFlag && iCount < getSlice()->getMaxNumMergeCand() && !getSlice()->getIsDepth() ) 
4726  {
4727    if(xAddIvMRGCand( mrgCandIdx,  iCount, ivCandDir, ivCandMv, ivCandRefIdx ) )
4728    {
4729      return;
4730    }
4731    //early termination
4732    if (iCount == getSlice()->getMaxNumMergeCand()) 
4733    {
4734      return;
4735    }
4736  }
4737#endif
4738#if !H_3D
4739  if ( getSlice()->getEnableTMVPFlag())
4740  {
4741    //>> MTK colocated-RightBottom
4742    UInt uiPartIdxRB;
4743
4744    deriveRightBottomIdx( uiPUIdx, uiPartIdxRB ); 
4745
4746    UInt uiAbsPartIdxTmp = g_auiZscanToRaster[uiPartIdxRB];
4747    UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
4748
4749    TComMv cColMv;
4750    Int iRefIdx;
4751    Int uiLCUIdx = -1;
4752
4753    if      ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
4754    {
4755    }
4756    else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxTmp] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
4757    {
4758    }
4759    else
4760    {
4761      if ( ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
4762        ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
4763      {
4764        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + uiNumPartInCUWidth + 1 ];
4765        uiLCUIdx = getAddr();
4766      }
4767      else if ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
4768      {
4769        uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdxTmp + uiNumPartInCUWidth + 1) % m_pcPic->getNumPartInCU() ];
4770      }
4771      else if ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
4772      {
4773        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + 1 ];
4774        uiLCUIdx = getAddr() + 1;
4775      }
4776      else //is the right bottom corner of LCU                       
4777      {
4778        uiAbsPartAddr = 0;
4779      }
4780    }
4781   
4782   
4783    iRefIdx = 0;
4784    Bool bExistMV = false;
4785    UInt uiPartIdxCenter;
4786    UInt uiCurLCUIdx = getAddr();
4787    Int dir = 0;
4788    UInt uiArrayAddr = iCount;
4789    xDeriveCenterIdx( uiPUIdx, uiPartIdxCenter );
4790    bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_0, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx );
4791    if( bExistMV == false )
4792    {
4793      bExistMV = xGetColMVP( REF_PIC_LIST_0, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
4794    }
4795    if( bExistMV )
4796    {
4797      dir |= 1;
4798      pcMvFieldNeighbours[ 2 * uiArrayAddr ].setMvField( cColMv, iRefIdx );
4799    }
4800
4801    if ( getSlice()->isInterB() )
4802    {
4803      bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_1, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx);
4804      if( bExistMV == false )
4805      {
4806        bExistMV = xGetColMVP( REF_PIC_LIST_1, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
4807      }
4808      if( bExistMV )
4809      {
4810        dir |= 2;
4811        pcMvFieldNeighbours[ 2 * uiArrayAddr + 1 ].setMvField( cColMv, iRefIdx );
4812      }
4813    }
4814   
4815    if (dir != 0)
4816    {
4817      puhInterDirNeighbours[uiArrayAddr] = dir;
4818      abCandIsInter[uiArrayAddr] = true;
4819      if ( mrgCandIdx == iCount )
4820      {
4821        return;
4822      }
4823      iCount++;
4824    }
4825  }
4826  // early termination 
4827  if (iCount == getSlice()->getMaxNumMergeCand()) 
4828  {
4829    return;
4830  }
4831  UInt uiArrayAddr = iCount;
4832  UInt uiCutoff = uiArrayAddr;
4833   
4834  if ( getSlice()->isInterB())
4835  {
4836    UInt uiPriorityList0[12] = {0 , 1, 0, 2, 1, 2, 0, 3, 1, 3, 2, 3};
4837    UInt uiPriorityList1[12] = {1 , 0, 2, 0, 2, 1, 3, 0, 3, 1, 3, 2};
4838
4839    for (Int idx=0; idx<uiCutoff*(uiCutoff-1) && uiArrayAddr!= getSlice()->getMaxNumMergeCand(); idx++)
4840    {
4841      Int i = uiPriorityList0[idx]; Int j = uiPriorityList1[idx];
4842      if (abCandIsInter[i] && abCandIsInter[j]&& (puhInterDirNeighbours[i]&0x1)&&(puhInterDirNeighbours[j]&0x2))
4843      {
4844        abCandIsInter[uiArrayAddr] = true;
4845        puhInterDirNeighbours[uiArrayAddr] = 3;
4846
4847        // get Mv from cand[i] and cand[j]
4848        pcMvFieldNeighbours[uiArrayAddr << 1].setMvField(pcMvFieldNeighbours[i<<1].getMv(), pcMvFieldNeighbours[i<<1].getRefIdx());
4849        pcMvFieldNeighbours[( uiArrayAddr << 1 ) + 1].setMvField(pcMvFieldNeighbours[(j<<1)+1].getMv(), pcMvFieldNeighbours[(j<<1)+1].getRefIdx());
4850
4851        Int iRefPOCL0 = m_pcSlice->getRefPOC( REF_PIC_LIST_0, pcMvFieldNeighbours[(uiArrayAddr<<1)].getRefIdx() );
4852        Int iRefPOCL1 = m_pcSlice->getRefPOC( REF_PIC_LIST_1, pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getRefIdx() );
4853        if (iRefPOCL0 == iRefPOCL1 && pcMvFieldNeighbours[(uiArrayAddr<<1)].getMv() == pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getMv())
4854        {
4855          abCandIsInter[uiArrayAddr] = false;
4856        }
4857        else
4858        {
4859          uiArrayAddr++;
4860        }
4861      }
4862    }
4863  }
4864  // early termination
4865  if (uiArrayAddr == getSlice()->getMaxNumMergeCand()) 
4866  {
4867    return;
4868  }
4869  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);
4870  Int r = 0;
4871  Int refcnt = 0;
4872  while (uiArrayAddr < getSlice()->getMaxNumMergeCand())
4873  {
4874    abCandIsInter[uiArrayAddr] = true;
4875    puhInterDirNeighbours[uiArrayAddr] = 1;
4876    pcMvFieldNeighbours[uiArrayAddr << 1].setMvField( TComMv(0, 0), r);
4877
4878    if ( getSlice()->isInterB() )
4879    {
4880      puhInterDirNeighbours[uiArrayAddr] = 3;
4881      pcMvFieldNeighbours[(uiArrayAddr << 1) + 1].setMvField(TComMv(0, 0), r);
4882    }
4883    uiArrayAddr++;
4884    if ( refcnt == iNumRefIdx - 1 )
4885    {
4886      r = 0;
4887    }
4888    else
4889    {
4890      ++r;
4891      ++refcnt;
4892    }
4893  }
4894
4895  numValidMergeCand = uiArrayAddr;
4896#endif
4897}
4898#else
4899
4900/** Constructs a list of merging candidates
4901 * \param uiAbsPartIdx
4902 * \param uiPUIdx
4903 * \param uiDepth
4904 * \param pcMvFieldNeighbours
4905 * \param puhInterDirNeighbours
4906 * \param numValidMergeCand
4907 */
4908Void TComDataCU::getInterMergeCandidates( UInt uiAbsPartIdx, UInt uiPUIdx, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours
4909      , Int& numValidMergeCand, Int mrgCandIdx
4910)
4911{
4912  UInt uiAbsPartAddr = m_uiAbsIdxInLCU + uiAbsPartIdx;
4913  Bool abCandIsInter[ MRG_MAX_NUM_CANDS ];
4914  for( UInt ui = 0; ui < getSlice()->getMaxNumMergeCand(); ++ui )
4915  {
4916    abCandIsInter[ui] = false;
4917    pcMvFieldNeighbours[ ( ui << 1 )     ].setRefIdx(NOT_VALID);
4918    pcMvFieldNeighbours[ ( ui << 1 ) + 1 ].setRefIdx(NOT_VALID);
4919  }
4920  numValidMergeCand = getSlice()->getMaxNumMergeCand();
4921  // compute the location of the current PU
4922  Int xP, yP, nPSW, nPSH;
4923  this->getPartPosition(uiPUIdx, xP, yP, nPSW, nPSH);
4924
4925  Int iCount = 0;
4926
4927  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB;
4928  PartSize cCurPS = getPartitionSize( uiAbsPartIdx );
4929  deriveLeftRightTopIdxGeneral( uiAbsPartIdx, uiPUIdx, uiPartIdxLT, uiPartIdxRT );
4930  deriveLeftBottomIdxGeneral  ( uiAbsPartIdx, uiPUIdx, uiPartIdxLB );
4931
4932  //left
4933  UInt uiLeftPartIdx = 0;
4934  TComDataCU* pcCULeft = 0;
4935  pcCULeft = getPULeft( uiLeftPartIdx, uiPartIdxLB );
4936  Bool isAvailableA1 = pcCULeft &&
4937  pcCULeft->isDiffMER(xP -1, yP+nPSH-1, xP, yP) &&
4938  !( uiPUIdx == 1 && (cCurPS == SIZE_Nx2N || cCurPS == SIZE_nLx2N || cCurPS == SIZE_nRx2N) ) &&
4939  !pcCULeft->isIntra( uiLeftPartIdx ) ;
4940  if ( isAvailableA1 )
4941  {
4942    abCandIsInter[iCount] = true;
4943    // get Inter Dir
4944    puhInterDirNeighbours[iCount] = pcCULeft->getInterDir( uiLeftPartIdx );
4945    // get Mv from Left
4946    pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
4947    if ( getSlice()->isInterB() )
4948    {
4949      pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
4950    }
4951    if ( mrgCandIdx == iCount )
4952    {
4953      return;
4954    }
4955    iCount ++;
4956  }
4957 
4958  // early termination
4959  if (iCount == getSlice()->getMaxNumMergeCand()) 
4960  {
4961    return;
4962  }
4963
4964  // above
4965  UInt uiAbovePartIdx = 0;
4966  TComDataCU* pcCUAbove = 0;
4967  pcCUAbove = getPUAbove( uiAbovePartIdx, uiPartIdxRT );
4968  Bool isAvailableB1 = pcCUAbove &&
4969  pcCUAbove->isDiffMER(xP+nPSW-1, yP-1, xP, yP) &&
4970  !( uiPUIdx == 1 && (cCurPS == SIZE_2NxN || cCurPS == SIZE_2NxnU || cCurPS == SIZE_2NxnD) ) &&
4971  !pcCUAbove->isIntra( uiAbovePartIdx );
4972  if ( isAvailableB1 && (!isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAbove, uiAbovePartIdx ) ) )
4973  {
4974    abCandIsInter[iCount] = true;
4975    // get Inter Dir
4976    puhInterDirNeighbours[iCount] = pcCUAbove->getInterDir( uiAbovePartIdx );
4977    // get Mv from Left
4978    pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
4979    if ( getSlice()->isInterB() )
4980    {
4981      pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
4982    }
4983
4984    if ( mrgCandIdx == iCount )
4985    {
4986      return;
4987    }
4988    iCount ++;
4989  }
4990  // early termination
4991  if (iCount == getSlice()->getMaxNumMergeCand()) 
4992  {
4993    return;
4994  }
4995
4996
4997  // above right
4998  UInt uiAboveRightPartIdx = 0;
4999  TComDataCU* pcCUAboveRight = 0;
5000  pcCUAboveRight = getPUAboveRight( uiAboveRightPartIdx, uiPartIdxRT );
5001  Bool isAvailableB0 = pcCUAboveRight &&
5002  pcCUAboveRight->isDiffMER(xP+nPSW, yP-1, xP, yP) &&
5003  !pcCUAboveRight->isIntra( uiAboveRightPartIdx );
5004  if ( isAvailableB0 && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveRight, uiAboveRightPartIdx ) ) )
5005  {
5006    abCandIsInter[iCount] = true;
5007    // get Inter Dir
5008    puhInterDirNeighbours[iCount] = pcCUAboveRight->getInterDir( uiAboveRightPartIdx );
5009    // get Mv from Left
5010    pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
5011    if ( getSlice()->isInterB() )
5012    {
5013      pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
5014    }
5015    if ( mrgCandIdx == iCount )
5016    {
5017      return;
5018    }
5019    iCount ++;
5020  }
5021  // early termination
5022  if (iCount == getSlice()->getMaxNumMergeCand()) 
5023  {
5024    return;
5025  }
5026
5027  //left bottom
5028  UInt uiLeftBottomPartIdx = 0;
5029  TComDataCU* pcCULeftBottom = 0;
5030  pcCULeftBottom = this->getPUBelowLeft( uiLeftBottomPartIdx, uiPartIdxLB );
5031  Bool isAvailableA0 = pcCULeftBottom &&
5032  pcCULeftBottom->isDiffMER(xP-1, yP+nPSH, xP, yP) &&
5033  !pcCULeftBottom->isIntra( uiLeftBottomPartIdx ) ;
5034  if ( isAvailableA0 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCULeftBottom, uiLeftBottomPartIdx ) ) )
5035  {
5036    abCandIsInter[iCount] = true;
5037    // get Inter Dir
5038    puhInterDirNeighbours[iCount] = pcCULeftBottom->getInterDir( uiLeftBottomPartIdx );
5039    // get Mv from Left
5040    pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
5041    if ( getSlice()->isInterB() )
5042    {
5043      pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
5044    }
5045
5046    if ( mrgCandIdx == iCount )
5047    {
5048      return;
5049    }
5050    iCount ++;
5051  }
5052  // early termination
5053  if (iCount == getSlice()->getMaxNumMergeCand()) 
5054  {
5055    return;
5056  }
5057
5058  // above left
5059  if( iCount < 4 )
5060  {
5061    UInt uiAboveLeftPartIdx = 0;
5062    TComDataCU* pcCUAboveLeft = 0;
5063    pcCUAboveLeft = getPUAboveLeft( uiAboveLeftPartIdx, uiAbsPartAddr );
5064    Bool isAvailableB2 = pcCUAboveLeft &&
5065    pcCUAboveLeft->isDiffMER(xP-1, yP-1, xP, yP) &&
5066    !pcCUAboveLeft->isIntra( uiAboveLeftPartIdx );
5067    if ( isAvailableB2 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) )
5068        && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) ) )
5069    {
5070      abCandIsInter[iCount] = true;
5071      // get Inter Dir
5072      puhInterDirNeighbours[iCount] = pcCUAboveLeft->getInterDir( uiAboveLeftPartIdx );
5073      // get Mv from Left
5074      pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
5075      if ( getSlice()->isInterB() )
5076      {
5077        pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
5078      }
5079      if ( mrgCandIdx == iCount )
5080      {
5081        return;
5082      }
5083      iCount ++;
5084    }
5085  }
5086  // early termination
5087  if (iCount == getSlice()->getMaxNumMergeCand()) 
5088  {
5089    return;
5090  }
5091
5092  if ( getSlice()->getEnableTMVPFlag())
5093  {
5094    //>> MTK colocated-RightBottom
5095    UInt uiPartIdxRB;
5096
5097    deriveRightBottomIdx( uiPUIdx, uiPartIdxRB ); 
5098
5099    UInt uiAbsPartIdxTmp = g_auiZscanToRaster[uiPartIdxRB];
5100    UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
5101
5102    TComMv cColMv;
5103    Int iRefIdx;
5104    Int uiLCUIdx = -1;
5105
5106    if      ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
5107    {
5108    }
5109    else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxTmp] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
5110    {
5111    }
5112    else
5113    {
5114      if ( ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
5115        ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
5116      {
5117        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + uiNumPartInCUWidth + 1 ];
5118        uiLCUIdx = getAddr();
5119      }
5120      else if ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
5121      {
5122        uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdxTmp + uiNumPartInCUWidth + 1) % m_pcPic->getNumPartInCU() ];
5123      }
5124      else if ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
5125      {
5126        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + 1 ];
5127        uiLCUIdx = getAddr() + 1;
5128      }
5129      else //is the right bottom corner of LCU                       
5130      {
5131        uiAbsPartAddr = 0;
5132      }
5133    }
5134   
5135   
5136    iRefIdx = 0;
5137    Bool bExistMV = false;
5138    UInt uiPartIdxCenter;
5139    UInt uiCurLCUIdx = getAddr();
5140    Int dir = 0;
5141    UInt uiArrayAddr = iCount;
5142    xDeriveCenterIdx( uiPUIdx, uiPartIdxCenter );
5143    bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_0, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx );
5144    if( bExistMV == false )
5145    {
5146      bExistMV = xGetColMVP( REF_PIC_LIST_0, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
5147    }
5148    if( bExistMV )
5149    {
5150      dir |= 1;
5151      pcMvFieldNeighbours[ 2 * uiArrayAddr ].setMvField( cColMv, iRefIdx );
5152    }
5153
5154    if ( getSlice()->isInterB() )
5155    {
5156      bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_1, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx);
5157      if( bExistMV == false )
5158      {
5159        bExistMV = xGetColMVP( REF_PIC_LIST_1, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
5160      }
5161      if( bExistMV )
5162      {
5163        dir |= 2;
5164        pcMvFieldNeighbours[ 2 * uiArrayAddr + 1 ].setMvField( cColMv, iRefIdx );
5165      }
5166    }
5167   
5168    if (dir != 0)
5169    {
5170      puhInterDirNeighbours[uiArrayAddr] = dir;
5171      abCandIsInter[uiArrayAddr] = true;
5172      if ( mrgCandIdx == iCount )
5173      {
5174        return;
5175      }
5176      iCount++;
5177    }
5178  }
5179  // early termination
5180  if (iCount == getSlice()->getMaxNumMergeCand()) 
5181  {
5182    return;
5183  }
5184  UInt uiArrayAddr = iCount;
5185  UInt uiCutoff = uiArrayAddr;
5186   
5187  if ( getSlice()->isInterB())
5188  {
5189    UInt uiPriorityList0[12] = {0 , 1, 0, 2, 1, 2, 0, 3, 1, 3, 2, 3};
5190    UInt uiPriorityList1[12] = {1 , 0, 2, 0, 2, 1, 3, 0, 3, 1, 3, 2};
5191
5192    for (Int idx=0; idx<uiCutoff*(uiCutoff-1) && uiArrayAddr!= getSlice()->getMaxNumMergeCand(); idx++)
5193    {
5194      Int i = uiPriorityList0[idx]; Int j = uiPriorityList1[idx];
5195      if (abCandIsInter[i] && abCandIsInter[j]&& (puhInterDirNeighbours[i]&0x1)&&(puhInterDirNeighbours[j]&0x2))
5196      {
5197        abCandIsInter[uiArrayAddr] = true;
5198        puhInterDirNeighbours[uiArrayAddr] = 3;
5199
5200        // get Mv from cand[i] and cand[j]
5201        pcMvFieldNeighbours[uiArrayAddr << 1].setMvField(pcMvFieldNeighbours[i<<1].getMv(), pcMvFieldNeighbours[i<<1].getRefIdx());
5202        pcMvFieldNeighbours[( uiArrayAddr << 1 ) + 1].setMvField(pcMvFieldNeighbours[(j<<1)+1].getMv(), pcMvFieldNeighbours[(j<<1)+1].getRefIdx());
5203
5204        Int iRefPOCL0 = m_pcSlice->getRefPOC( REF_PIC_LIST_0, pcMvFieldNeighbours[(uiArrayAddr<<1)].getRefIdx() );
5205        Int iRefPOCL1 = m_pcSlice->getRefPOC( REF_PIC_LIST_1, pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getRefIdx() );
5206        if (iRefPOCL0 == iRefPOCL1 && pcMvFieldNeighbours[(uiArrayAddr<<1)].getMv() == pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getMv())
5207        {
5208          abCandIsInter[uiArrayAddr] = false;
5209        }
5210        else
5211        {
5212          uiArrayAddr++;
5213        }
5214      }
5215    }
5216  }
5217  // early termination
5218  if (uiArrayAddr == getSlice()->getMaxNumMergeCand()) 
5219  {
5220    return;
5221  }
5222  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);
5223  Int r = 0;
5224  Int refcnt = 0;
5225  while (uiArrayAddr < getSlice()->getMaxNumMergeCand())
5226  {
5227    abCandIsInter[uiArrayAddr] = true;
5228    puhInterDirNeighbours[uiArrayAddr] = 1;
5229    pcMvFieldNeighbours[uiArrayAddr << 1].setMvField( TComMv(0, 0), r);
5230
5231    if ( getSlice()->isInterB() )
5232    {
5233      puhInterDirNeighbours[uiArrayAddr] = 3;
5234      pcMvFieldNeighbours[(uiArrayAddr << 1) + 1].setMvField(TComMv(0, 0), r);
5235    }
5236    uiArrayAddr++;
5237    if ( refcnt == iNumRefIdx - 1 )
5238    {
5239      r = 0;
5240    }
5241    else
5242    {
5243      ++r;
5244      ++refcnt;
5245    }
5246  }
5247
5248  numValidMergeCand = uiArrayAddr;
5249}
5250#endif
5251
5252
5253#if H_3D_VSP
5254inline Void TComDataCU::xInheritVSPDisInfo(TComDataCU* pcCURef, UInt uiAbsPartIdx, Int iCount, InheritedVSPDisInfo*  inheritedVSPDisInfo)
5255{
5256  inheritedVSPDisInfo[iCount].m_acDvInfo.m_acNBDV   = pcCURef->getDvInfo(uiAbsPartIdx).m_acNBDV;
5257  inheritedVSPDisInfo[iCount].m_acDvInfo.m_aVIdxCan = pcCURef->getDvInfo(uiAbsPartIdx).m_aVIdxCan;
5258}
5259#endif
5260/** Check whether the current PU and a spatial neighboring PU are in a same ME region.
5261 * \param xN, xN   location of the upper-left corner pixel of a neighboring PU
5262 * \param xP, yP   location of the upper-left corner pixel of the current PU
5263 * \returns Bool
5264 */
5265Bool TComDataCU::isDiffMER(Int xN, Int yN, Int xP, Int yP)
5266{
5267
5268  UInt plevel = this->getSlice()->getPPS()->getLog2ParallelMergeLevelMinus2() + 2;
5269  if ((xN>>plevel)!= (xP>>plevel))
5270  {
5271    return true;
5272  }
5273  if ((yN>>plevel)!= (yP>>plevel))
5274  {
5275    return true;
5276  }
5277  return false;
5278}
5279/** calculate the location of upper-left corner pixel and size of the current PU.
5280 * \param partIdx  PU index within a CU
5281 * \param xP, yP   location of the upper-left corner pixel of the current PU
5282 * \param PSW, nPSH    size of the curren PU
5283 * \returns Void
5284 */
5285Void TComDataCU::getPartPosition( UInt partIdx, Int& xP, Int& yP, Int& nPSW, Int& nPSH)
5286{
5287  UInt col = m_uiCUPelX;
5288  UInt row = m_uiCUPelY;
5289
5290  switch ( m_pePartSize[0] )
5291  {
5292  case SIZE_2NxN:
5293    nPSW = getWidth(0);     
5294    nPSH = getHeight(0) >> 1; 
5295    xP   = col;
5296    yP   = (partIdx ==0)? row: row + nPSH;
5297    break;
5298  case SIZE_Nx2N:
5299    nPSW = getWidth(0) >> 1; 
5300    nPSH = getHeight(0);     
5301    xP   = (partIdx ==0)? col: col + nPSW;
5302    yP   = row;
5303    break;
5304  case SIZE_NxN:
5305    nPSW = getWidth(0) >> 1; 
5306    nPSH = getHeight(0) >> 1; 
5307    xP   = col + (partIdx&0x1)*nPSW;
5308    yP   = row + (partIdx>>1)*nPSH;
5309    break;
5310  case SIZE_2NxnU:
5311    nPSW = getWidth(0);
5312    nPSH = ( partIdx == 0 ) ?  getHeight(0) >> 2 : ( getHeight(0) >> 2 ) + ( getHeight(0) >> 1 );
5313    xP   = col;
5314    yP   = (partIdx ==0)? row: row + getHeight(0) - nPSH;
5315
5316    break;
5317  case SIZE_2NxnD:
5318    nPSW = getWidth(0);
5319    nPSH = ( partIdx == 0 ) ?  ( getHeight(0) >> 2 ) + ( getHeight(0) >> 1 ) : getHeight(0) >> 2;
5320    xP   = col;
5321    yP   = (partIdx ==0)? row: row + getHeight(0) - nPSH;
5322    break;
5323  case SIZE_nLx2N:
5324    nPSW = ( partIdx == 0 ) ? getWidth(0) >> 2 : ( getWidth(0) >> 2 ) + ( getWidth(0) >> 1 );
5325    nPSH = getHeight(0);
5326    xP   = (partIdx ==0)? col: col + getWidth(0) - nPSW;
5327    yP   = row;
5328    break;
5329  case SIZE_nRx2N:
5330    nPSW = ( partIdx == 0 ) ? ( getWidth(0) >> 2 ) + ( getWidth(0) >> 1 ) : getWidth(0) >> 2;
5331    nPSH = getHeight(0);
5332    xP   = (partIdx ==0)? col: col + getWidth(0) - nPSW;
5333    yP   = row;
5334    break;
5335  default:
5336    assert ( m_pePartSize[0] == SIZE_2Nx2N );
5337    nPSW = getWidth(0);     
5338    nPSH = getHeight(0);     
5339    xP   = col ;
5340    yP   = row ;
5341
5342    break;
5343  }
5344}
5345
5346/** Constructs a list of candidates for AMVP
5347 * \param uiPartIdx
5348 * \param uiPartAddr
5349 * \param eRefPicList
5350 * \param iRefIdx
5351 * \param pInfo
5352 */
5353Void TComDataCU::fillMvpCand ( UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, Int iRefIdx, AMVPInfo* pInfo )
5354{
5355  TComMv cMvPred;
5356  Bool bAddedSmvp = false;
5357
5358  pInfo->iN = 0; 
5359  if (iRefIdx < 0)
5360  {
5361    return;
5362  }
5363 
5364  //-- Get Spatial MV
5365  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB;
5366  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
5367  Bool bAdded = false;
5368 
5369  deriveLeftRightTopIdx( uiPartIdx, uiPartIdxLT, uiPartIdxRT );
5370  deriveLeftBottomIdx( uiPartIdx, uiPartIdxLB );
5371 
5372  TComDataCU* tmpCU = NULL;
5373  UInt idx;
5374  tmpCU = getPUBelowLeft(idx, uiPartIdxLB);
5375  bAddedSmvp = (tmpCU != NULL) && (tmpCU->getPredictionMode(idx) != MODE_INTRA);
5376
5377  if (!bAddedSmvp)
5378  {
5379    tmpCU = getPULeft(idx, uiPartIdxLB);
5380    bAddedSmvp = (tmpCU != NULL) && (tmpCU->getPredictionMode(idx) != MODE_INTRA);
5381  }
5382
5383  // Left predictor search
5384  bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_BELOW_LEFT);
5385  if (!bAdded) 
5386  {
5387    bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_LEFT );
5388  }
5389 
5390  if(!bAdded)
5391  {
5392    bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_BELOW_LEFT);
5393    if (!bAdded) 
5394    {
5395      xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_LEFT );
5396    }
5397  }
5398  // Above predictor search
5399  bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE_RIGHT);
5400
5401  if (!bAdded) 
5402  {
5403    bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE);
5404  }
5405
5406  if(!bAdded)
5407  {
5408    xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLT, MD_ABOVE_LEFT);
5409  }
5410
5411  if (!bAddedSmvp)
5412  {
5413    bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE_RIGHT);
5414    if (!bAdded) 
5415    {
5416      bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE);
5417    }
5418
5419    if(!bAdded)
5420    {
5421      xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLT, MD_ABOVE_LEFT);
5422    }
5423  }
5424 
5425  if ( pInfo->iN == 2 )
5426  {
5427    if ( pInfo->m_acMvCand[ 0 ] == pInfo->m_acMvCand[ 1 ] )
5428    {
5429      pInfo->iN = 1;
5430    }
5431  }
5432
5433  if ( getSlice()->getEnableTMVPFlag() )
5434  {
5435    // Get Temporal Motion Predictor
5436    Int iRefIdx_Col = iRefIdx;
5437    TComMv cColMv;
5438    UInt uiPartIdxRB;
5439    UInt uiAbsPartIdx; 
5440    UInt uiAbsPartAddr;
5441
5442    deriveRightBottomIdx( uiPartIdx, uiPartIdxRB );
5443    uiAbsPartAddr = m_uiAbsIdxInLCU + uiPartAddr;
5444
5445    //----  co-located RightBottom Temporal Predictor (H) ---//
5446    uiAbsPartIdx = g_auiZscanToRaster[uiPartIdxRB];
5447    Int uiLCUIdx = -1;
5448    if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdx] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
5449    {
5450    }
5451    else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdx] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
5452    {
5453    }
5454    else
5455    {
5456      if ( ( uiAbsPartIdx % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
5457        ( uiAbsPartIdx / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
5458      {
5459        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdx + uiNumPartInCUWidth + 1 ];
5460        uiLCUIdx = getAddr();
5461      }
5462      else if ( uiAbsPartIdx % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
5463      {
5464        uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdx + uiNumPartInCUWidth + 1) % m_pcPic->getNumPartInCU() ];
5465      }
5466      else if ( uiAbsPartIdx / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
5467      {
5468        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdx + 1 ];
5469        uiLCUIdx = getAddr() + 1;
5470      }
5471      else //is the right bottom corner of LCU                       
5472      {
5473        uiAbsPartAddr = 0;
5474      }
5475    }
5476    if ( uiLCUIdx >= 0 && xGetColMVP( eRefPicList, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx_Col
5477#if H_3D_TMVP
5478         , 0
5479#endif
5480    ) )
5481    {
5482      pInfo->m_acMvCand[pInfo->iN++] = cColMv;
5483    }
5484    else 
5485    {
5486      UInt uiPartIdxCenter;
5487      UInt uiCurLCUIdx = getAddr();
5488      xDeriveCenterIdx( uiPartIdx, uiPartIdxCenter );
5489      if (xGetColMVP( eRefPicList, uiCurLCUIdx, uiPartIdxCenter,  cColMv, iRefIdx_Col
5490#if H_3D_TMVP
5491         , 0
5492#endif
5493      ))
5494      {
5495        pInfo->m_acMvCand[pInfo->iN++] = cColMv;
5496      }
5497    }
5498    //----  co-located RightBottom Temporal Predictor  ---//
5499  }
5500
5501  if (pInfo->iN > AMVP_MAX_NUM_CANDS)
5502  {
5503    pInfo->iN = AMVP_MAX_NUM_CANDS;
5504  }
5505  while (pInfo->iN < AMVP_MAX_NUM_CANDS)
5506  {
5507      pInfo->m_acMvCand[pInfo->iN].set(0,0);
5508      pInfo->iN++;
5509  }
5510  return ;
5511}
5512
5513Bool TComDataCU::isBipredRestriction(UInt puIdx)
5514{
5515  Int width = 0;
5516  Int height = 0;
5517  UInt partAddr;
5518 
5519#if H_3D_DBBP
5520  if( getDBBPFlag(0) )
5521  {
5522    return true;
5523  }
5524#endif
5525
5526  getPartIndexAndSize( puIdx, partAddr, width, height );
5527  if ( getWidth(0) == 8 && (width < 8 || height < 8) )
5528  {
5529    return true;
5530  }
5531  return false;
5532}
5533
5534Void TComDataCU::clipMv    (TComMv&  rcMv)
5535{
5536  Int  iMvShift = 2;
5537#if H_3D_IC
5538  if( getSlice()->getIsDepth() )
5539    iMvShift = 0;
5540#endif
5541  Int iOffset = 8;
5542  Int iHorMax = ( m_pcSlice->getSPS()->getPicWidthInLumaSamples() + iOffset - m_uiCUPelX - 1 ) << iMvShift;
5543  Int iHorMin = (       -(Int)g_uiMaxCUWidth - iOffset - (Int)m_uiCUPelX + 1 ) << iMvShift;
5544 
5545  Int iVerMax = ( m_pcSlice->getSPS()->getPicHeightInLumaSamples() + iOffset - m_uiCUPelY - 1 ) << iMvShift;
5546  Int iVerMin = (       -(Int)g_uiMaxCUHeight - iOffset - (Int)m_uiCUPelY + 1 ) << iMvShift;
5547 
5548  rcMv.setHor( min (iHorMax, max (iHorMin, rcMv.getHor())) );
5549  rcMv.setVer( min (iVerMax, max (iVerMin, rcMv.getVer())) );
5550}
5551
5552UInt TComDataCU::getIntraSizeIdx(UInt uiAbsPartIdx)
5553{
5554  UInt uiShift = ( m_pePartSize[uiAbsPartIdx]==SIZE_NxN ? 1 : 0 );
5555 
5556  UChar uiWidth = m_puhWidth[uiAbsPartIdx]>>uiShift;
5557  UInt  uiCnt = 0;
5558  while( uiWidth )
5559  {
5560    uiCnt++;
5561    uiWidth>>=1;
5562  }
5563  uiCnt-=2;
5564  return uiCnt > 6 ? 6 : uiCnt;
5565}
5566
5567Void TComDataCU::clearCbf( UInt uiIdx, TextType eType, UInt uiNumParts )
5568{
5569  ::memset( &m_puhCbf[g_aucConvertTxtTypeToIdx[eType]][uiIdx], 0, sizeof(UChar)*uiNumParts);
5570}
5571
5572/** Set a I_PCM flag for all sub-partitions of a partition.
5573 * \param bIpcmFlag I_PCM flag
5574 * \param uiAbsPartIdx patition index
5575 * \param uiDepth CU depth
5576 * \returns Void
5577 */
5578Void TComDataCU::setIPCMFlagSubParts  (Bool bIpcmFlag, UInt uiAbsPartIdx, UInt uiDepth)
5579{
5580  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
5581
5582  memset(m_pbIPCMFlag + uiAbsPartIdx, bIpcmFlag, sizeof(Bool)*uiCurrPartNumb );
5583}
5584
5585/** Test whether the current block is skipped
5586 * \param uiPartIdx Block index
5587 * \returns Flag indicating whether the block is skipped
5588 */
5589Bool TComDataCU::isSkipped( UInt uiPartIdx )
5590{
5591  return ( getSkipFlag( uiPartIdx ) );
5592}
5593
5594#if H_3D_IC
5595Bool TComDataCU::isIC( UInt uiPartIdx )
5596{
5597    if ( m_pcSlice->isIntra () )
5598    {
5599        return false;
5600    }
5601    return ( ( getSkipFlag(uiPartIdx) || getPredictionMode(uiPartIdx) == MODE_INTER) && getICFlag( uiPartIdx ) && isICFlagRequired( uiPartIdx ) );
5602}
5603#endif
5604
5605// ====================================================================================================================
5606// Protected member functions
5607// ====================================================================================================================
5608
5609Bool TComDataCU::xAddMVPCand( AMVPInfo* pInfo, RefPicList eRefPicList, Int iRefIdx, UInt uiPartUnitIdx, MVP_DIR eDir )
5610{
5611  TComDataCU* pcTmpCU = NULL;
5612  UInt uiIdx;
5613  switch( eDir )
5614  {
5615    case MD_LEFT:
5616    {
5617      pcTmpCU = getPULeft(uiIdx, uiPartUnitIdx);
5618      break;
5619    }
5620    case MD_ABOVE:
5621    {
5622      pcTmpCU = getPUAbove(uiIdx, uiPartUnitIdx );
5623      break;
5624    }
5625    case MD_ABOVE_RIGHT:
5626    {
5627      pcTmpCU = getPUAboveRight(uiIdx, uiPartUnitIdx);
5628      break;
5629    }
5630    case MD_BELOW_LEFT:
5631    {
5632      pcTmpCU = getPUBelowLeft(uiIdx, uiPartUnitIdx);
5633      break;
5634    }
5635    case MD_ABOVE_LEFT:
5636    {
5637      pcTmpCU = getPUAboveLeft(uiIdx, uiPartUnitIdx);
5638      break;
5639    }
5640    default:
5641    {
5642      break;
5643    }
5644  }
5645
5646  if ( pcTmpCU == NULL )
5647  {
5648    return false;
5649  }
5650 
5651  if ( pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) >= 0 && m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getPOC() == pcTmpCU->getSlice()->getRefPOC( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) ))
5652  {
5653    TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
5654   
5655    pInfo->m_acMvCand[ pInfo->iN++] = cMvPred;
5656    return true;
5657  }
5658
5659  RefPicList eRefPicList2nd = REF_PIC_LIST_0;
5660  if(       eRefPicList == REF_PIC_LIST_0 )
5661  {
5662    eRefPicList2nd = REF_PIC_LIST_1;
5663  }
5664  else if ( eRefPicList == REF_PIC_LIST_1)
5665  {
5666    eRefPicList2nd = REF_PIC_LIST_0;
5667  }
5668
5669
5670  Int iCurrRefPOC = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getPOC();
5671  Int iNeibRefPOC;
5672
5673
5674  if( pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) >= 0 )
5675  {
5676    iNeibRefPOC = pcTmpCU->getSlice()->getRefPOC( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) );
5677    if( iNeibRefPOC == iCurrRefPOC ) // Same Reference Frame But Diff List//
5678    {
5679      TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList2nd)->getMv(uiIdx);
5680      pInfo->m_acMvCand[ pInfo->iN++] = cMvPred;
5681      return true;
5682    }
5683  }
5684  return false;
5685}
5686
5687/**
5688 * \param pInfo
5689 * \param eRefPicList
5690 * \param iRefIdx
5691 * \param uiPartUnitIdx
5692 * \param eDir
5693 * \returns Bool
5694 */
5695Bool TComDataCU::xAddMVPCandOrder( AMVPInfo* pInfo, RefPicList eRefPicList, Int iRefIdx, UInt uiPartUnitIdx, MVP_DIR eDir )
5696{
5697  TComDataCU* pcTmpCU = NULL;
5698  UInt uiIdx;
5699  switch( eDir )
5700  {
5701  case MD_LEFT:
5702    {
5703      pcTmpCU = getPULeft(uiIdx, uiPartUnitIdx);
5704      break;
5705    }
5706  case MD_ABOVE:
5707    {
5708      pcTmpCU = getPUAbove(uiIdx, uiPartUnitIdx);
5709      break;
5710    }
5711  case MD_ABOVE_RIGHT:
5712    {
5713      pcTmpCU = getPUAboveRight(uiIdx, uiPartUnitIdx);
5714      break;
5715    }
5716  case MD_BELOW_LEFT:
5717    {
5718      pcTmpCU = getPUBelowLeft(uiIdx, uiPartUnitIdx);
5719      break;
5720    }
5721  case MD_ABOVE_LEFT:
5722    {
5723      pcTmpCU = getPUAboveLeft(uiIdx, uiPartUnitIdx);
5724      break;
5725    }
5726  default:
5727    {
5728      break;
5729    }
5730  }
5731
5732  if ( pcTmpCU == NULL ) 
5733  {
5734    return false;
5735  }
5736 
5737  RefPicList eRefPicList2nd = REF_PIC_LIST_0;
5738  if(       eRefPicList == REF_PIC_LIST_0 )
5739  {
5740    eRefPicList2nd = REF_PIC_LIST_1;
5741  }
5742  else if ( eRefPicList == REF_PIC_LIST_1)
5743  {
5744    eRefPicList2nd = REF_PIC_LIST_0;
5745  }
5746
5747  Int iCurrPOC = m_pcSlice->getPOC();
5748  Int iCurrRefPOC = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getPOC();
5749  Int iNeibPOC = iCurrPOC;
5750  Int iNeibRefPOC;
5751
5752  Bool bIsCurrRefLongTerm = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getIsLongTerm();
5753  Bool bIsNeibRefLongTerm = false;
5754  //---------------  V1 (END) ------------------//
5755  if( pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) >= 0)
5756  {
5757    iNeibRefPOC = pcTmpCU->getSlice()->getRefPOC( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) );
5758    TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
5759    TComMv rcMv;
5760
5761    bIsNeibRefLongTerm = pcTmpCU->getSlice()->getRefPic( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) )->getIsLongTerm();
5762    if ( bIsCurrRefLongTerm == bIsNeibRefLongTerm ) 
5763    {
5764    if ( bIsCurrRefLongTerm || bIsNeibRefLongTerm )
5765    {
5766      rcMv = cMvPred;
5767    }
5768    else
5769    {
5770      Int iScale = xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
5771      if ( iScale == 4096 )
5772      {
5773        rcMv = cMvPred;
5774      }
5775      else
5776      {
5777        rcMv = cMvPred.scaleMv( iScale );
5778      }
5779    }
5780    pInfo->m_acMvCand[ pInfo->iN++] = rcMv;
5781    return true;
5782    }
5783  }
5784  //---------------------- V2(END) --------------------//
5785  if( pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) >= 0)
5786  {
5787    iNeibRefPOC = pcTmpCU->getSlice()->getRefPOC( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) );
5788    TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList2nd)->getMv(uiIdx);
5789    TComMv rcMv;
5790
5791    bIsNeibRefLongTerm = pcTmpCU->getSlice()->getRefPic( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) )->getIsLongTerm();
5792    if ( bIsCurrRefLongTerm == bIsNeibRefLongTerm ) 
5793    {
5794    if ( bIsCurrRefLongTerm || bIsNeibRefLongTerm )
5795    {
5796      rcMv = cMvPred;
5797    }
5798    else
5799    {
5800      Int iScale = xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
5801      if ( iScale == 4096 )
5802      {
5803        rcMv = cMvPred;
5804      }
5805      else
5806      {
5807        rcMv = cMvPred.scaleMv( iScale );
5808      }
5809    }
5810    pInfo->m_acMvCand[ pInfo->iN++] = rcMv;
5811    return true;
5812    }
5813  }
5814  //---------------------- V3(END) --------------------//
5815  return false;
5816}
5817
5818/**
5819 * \param eRefPicList
5820 * \param uiCUAddr
5821 * \param uiPartUnitIdx
5822 * \param riRefIdx
5823 * \returns Bool
5824 */
5825Bool TComDataCU::xGetColMVP( RefPicList eRefPicList, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv, Int& riRefIdx
5826#if H_3D_TMVP
5827  , Bool bMRG
5828#endif
5829  )
5830{
5831  UInt uiAbsPartAddr = uiPartUnitIdx;
5832
5833  RefPicList  eColRefPicList;
5834  Int iColPOC, iColRefPOC, iCurrPOC, iCurrRefPOC, iScale;
5835  TComMv cColMv;
5836
5837  // use coldir.
5838  TComPic *pColPic = getSlice()->getRefPic( RefPicList(getSlice()->isInterB() ? 1-getSlice()->getColFromL0Flag() : 0), getSlice()->getColRefIdx());
5839  TComDataCU *pColCU = pColPic->getCU( uiCUAddr );
5840  if(pColCU->getPic()==0||pColCU->getPartitionSize(uiPartUnitIdx)==SIZE_NONE)
5841  {
5842    return false;
5843  }
5844  iCurrPOC = m_pcSlice->getPOC();   
5845  iColPOC = pColCU->getSlice()->getPOC(); 
5846
5847  if (pColCU->isIntra(uiAbsPartAddr))
5848  {
5849    return false;
5850  }
5851  eColRefPicList = getSlice()->getCheckLDC() ? eRefPicList : RefPicList(getSlice()->getColFromL0Flag());
5852
5853  Int iColRefIdx = pColCU->getCUMvField(RefPicList(eColRefPicList))->getRefIdx(uiAbsPartAddr);
5854
5855  if (iColRefIdx < 0 )
5856  {
5857    eColRefPicList = RefPicList(1 - eColRefPicList);
5858    iColRefIdx = pColCU->getCUMvField(RefPicList(eColRefPicList))->getRefIdx(uiAbsPartAddr);
5859
5860    if (iColRefIdx < 0 )
5861    {
5862      return false;
5863    }
5864  }
5865
5866  // Scale the vector.
5867  iColRefPOC = pColCU->getSlice()->getRefPOC(eColRefPicList, iColRefIdx);
5868  cColMv = pColCU->getCUMvField(eColRefPicList)->getMv(uiAbsPartAddr);
5869
5870  iCurrRefPOC = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getPOC();
5871  Bool bIsCurrRefLongTerm = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getIsLongTerm();
5872  Bool bIsColRefLongTerm = pColCU->getSlice()->getIsUsedAsLongTerm(eColRefPicList, iColRefIdx);
5873
5874  if ( bIsCurrRefLongTerm != bIsColRefLongTerm ) 
5875  {
5876#if H_3D_TMVP
5877    Int iAlterRefIdx  = m_pcSlice->getAlterRefIdx(eRefPicList);
5878    if(bMRG && iAlterRefIdx > 0)
5879    {
5880      riRefIdx = iAlterRefIdx;
5881      bIsCurrRefLongTerm = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getIsLongTerm();
5882      iCurrRefPOC = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getPOC();
5883      assert(bIsCurrRefLongTerm == bIsColRefLongTerm);
5884    }
5885    else
5886    {
5887#endif
5888      return false;
5889#if H_3D_TMVP
5890    }
5891#endif
5892  }
5893
5894  if ( bIsCurrRefLongTerm || bIsColRefLongTerm )
5895  {
5896#if H_3D_TMVP
5897    Int iCurrViewId    = m_pcSlice->getViewIndex (); 
5898    Int iCurrRefViewId = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getViewIndex (); 
5899    Int iColViewId     = pColCU->getSlice()->getViewIndex(); 
5900    Int iColRefViewId  = pColCU->getSlice()->getRefPic( eColRefPicList, pColCU->getCUMvField(eColRefPicList)->getRefIdx(uiAbsPartAddr))->getViewIndex(); 
5901    iScale = xGetDistScaleFactor( iCurrViewId, iCurrRefViewId, iColViewId, iColRefViewId );
5902#if SEC_HLS_CLEANUP_I0100
5903    if ( iScale != 4096 && m_pcSlice->getVPS()->getIvMvScalingFlag(getSlice()->getLayerIdInVps()) ) 
5904#else
5905    if ( iScale != 4096 && m_pcSlice->getVPS()->getIvMvScalingFlag() ) 
5906#endif
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#if MTK_I0099_VPS_EX2
6657    iSubPUSize = 1<<getSlice()->getVPS()->getSubPUMPILog2Size(getSlice()->getLayerId());
6658#else
6659    iSubPUSize = 1 << getSlice()->getVPS()->getSubPUMPILog2Size();
6660#endif
6661  }
6662
6663  iNumSPInOneLine = iPUWidth/iSubPUSize;
6664  iNumSPInOneLine = iNumSPInOneLine < 1 ? 1: iNumSPInOneLine;
6665  Int iNumSPInOneColumn = iPUHeight/iSubPUSize;
6666  iNumSPInOneColumn = iNumSPInOneColumn < 1 ? 1: iNumSPInOneColumn;
6667  iNumSP = iNumSPInOneLine * iNumSPInOneColumn;
6668
6669  iSPWidth = iNumSPInOneLine == 1 ? iPUWidth: iSubPUSize; 
6670  iSPHeight = iNumSPInOneColumn == 1 ? iPUHeight: iSubPUSize; 
6671}
6672
6673Void TComDataCU::getSPAbsPartIdx(UInt uiBaseAbsPartIdx, Int iWidth, Int iHeight, Int iPartIdx, Int iNumPartLine, UInt& ruiPartAddr )
6674{
6675  uiBaseAbsPartIdx += m_uiAbsIdxInLCU;
6676  Int iBasePelX = g_auiRasterToPelX[g_auiZscanToRaster[uiBaseAbsPartIdx]];
6677  Int iBasePelY = g_auiRasterToPelY[g_auiZscanToRaster[uiBaseAbsPartIdx]];
6678  Int iCurrPelX = iBasePelX + iPartIdx%iNumPartLine * iWidth;
6679  Int iCurrPelY = iBasePelY + iPartIdx/iNumPartLine * iHeight;
6680  Int iCurrRaster = iCurrPelY / getPic()->getMinCUHeight() * getPic()->getNumPartInWidth() + iCurrPelX/getPic()->getMinCUWidth();
6681  ruiPartAddr = g_auiRasterToZscan[iCurrRaster];
6682  ruiPartAddr -= m_uiAbsIdxInLCU; 
6683}
6684
6685Void TComDataCU::setInterDirSP( UInt uiDir, UInt uiAbsPartIdx, Int iWidth, Int iHeight )
6686{
6687  uiAbsPartIdx += getZorderIdxInCU();
6688  Int iStartPelX = g_auiRasterToPelX[g_auiZscanToRaster[uiAbsPartIdx]];
6689  Int iStartPelY = g_auiRasterToPelY[g_auiZscanToRaster[uiAbsPartIdx]];
6690  Int iEndPelX = iStartPelX + iWidth;
6691  Int iEndPelY = iStartPelY + iHeight;
6692
6693  Int iCurrRaster, uiPartAddr;
6694
6695  for (Int i=iStartPelY; i<iEndPelY; i+=getPic()->getMinCUHeight())
6696  {
6697    for (Int j=iStartPelX; j < iEndPelX; j += getPic()->getMinCUWidth())
6698    {
6699      iCurrRaster = i / getPic()->getMinCUHeight() * getPic()->getNumPartInWidth() + j/getPic()->getMinCUWidth();
6700      uiPartAddr = g_auiRasterToZscan[iCurrRaster];
6701      uiPartAddr -= getZorderIdxInCU(); 
6702
6703      m_puhInterDir[uiPartAddr] = uiDir;
6704    }
6705  }
6706}
6707#endif
6708
6709#if H_3D_IV_MERGE
6710Bool
6711TComDataCU::getInterViewMergeCands(UInt uiPartIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv, DisInfo* pDInfo, Int* availableMcDc , Bool bIsDepth           
6712#if H_3D_SPIVMP
6713, TComMvField* pcMvFieldSP, UChar* puhInterDirSP
6714#endif
6715, Bool bICFlag
6716)
6717{
6718  TComSlice*    pcSlice = getSlice (); 
6719  Int iViewIndex        = pDInfo->m_aVIdxCan;
6720
6721  //--- get base CU/PU and check prediction mode ---
6722  TComPic*    pcBasePic   = pcSlice->getIvPic( bIsDepth, iViewIndex );
6723  TComPicYuv* pcBaseRec   = pcBasePic->getPicYuvRec   ();
6724
6725  UInt          uiPartAddr;
6726  Int           iWidth;
6727  Int           iHeight;
6728  getPartIndexAndSize( uiPartIdx, uiPartAddr, iWidth, iHeight );
6729
6730  Int  iCurrPosX, iCurrPosY;
6731  pcBaseRec->getTopLeftSamplePos( getAddr(), getZorderIdxInCU() + uiPartAddr, iCurrPosX, iCurrPosY );
6732
6733#if !H_3D_SPIVMP
6734  iCurrPosX  += ( iWidth  >> 1 );
6735  iCurrPosY  += ( iHeight >> 1 );
6736#endif
6737
6738  Bool depthRefineFlag = false; 
6739#if H_3D_NBDV_REF
6740  depthRefineFlag = m_pcSlice->getVPS()->getDepthRefinementFlag( m_pcSlice->getLayerIdInVps() ); 
6741#endif // H_3D_NBDV_REF
6742
6743  TComMv      cDv = depthRefineFlag ? pDInfo->m_acDoNBDV : pDInfo->m_acNBDV; 
6744  if( depthRefineFlag )
6745  {
6746    cDv.setVer(0);
6747  }
6748
6749  Bool abPdmAvailable[8] =  {false, false, false, false, false, false, false, false};
6750#if H_3D_NBDV
6751  for( Int i = 0; i < 8; i++)
6752  {
6753    pacPdmMv[i].setIDVFlag   (false);
6754  }
6755#endif
6756
6757  if(!bICFlag)
6758  {
6759
6760#if H_3D_SPIVMP
6761    ////////////////////////////////
6762    //////////sub-PU IvMC///////////
6763    ////////////////////////////////
6764    if(!m_pcSlice->getIsDepth())
6765    {
6766      if (!getDBBPFlag(0))
6767      {
6768        Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight;
6769        getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight);
6770
6771        for (Int i=0; i<iNumSP; i++)
6772        {
6773          puhInterDirSP[i] = 0;
6774          pcMvFieldSP[2*i].getMv().set(0, 0);
6775          pcMvFieldSP[2*i+1].getMv().set(0,0);
6776          pcMvFieldSP[2*i].setRefIdx(-1);
6777          pcMvFieldSP[2*i+1].setRefIdx(-1);
6778        }
6779
6780        Int         iBaseCUAddr;
6781        Int         iBaseAbsPartIdx;
6782        TComDataCU* pcBaseCU;
6783        Int iPartition = 0;
6784
6785        Int iDelX = iSPWidth/2;
6786        Int iDelY = iSPHeight/2;
6787
6788        Int         iCenterPosX = iCurrPosX + ( ( iWidth /  iSPWidth ) >> 1 )  * iSPWidth + ( iSPWidth >> 1 );
6789        Int         iCenterPosY = iCurrPosY + ( ( iHeight /  iSPHeight ) >> 1 )  * iSPHeight + (iSPHeight >> 1);
6790        Int         iRefCenterCUAddr, iRefCenterAbsPartIdx;
6791
6792        if(iWidth == iSPWidth && iHeight == iSPHeight)
6793        {
6794          iCenterPosX = iCurrPosX + (iWidth >> 1);
6795          iCenterPosY = iCurrPosY + (iHeight >> 1);
6796        }
6797
6798        Int iRefCenterPosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCenterPosX + ( (cDv.getHor() + 2 ) >> 2 ) );
6799        Int iRefCenterPosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCenterPosY + ( (cDv.getVer() + 2 ) >> 2 ) ); 
6800
6801        pcBaseRec->getCUAddrAndPartIdx( iRefCenterPosX , iRefCenterPosY , iRefCenterCUAddr, iRefCenterAbsPartIdx );
6802        TComDataCU* pcDefaultCU    = pcBasePic->getCU( iRefCenterCUAddr );
6803        if(!( pcDefaultCU->getPredictionMode( iRefCenterAbsPartIdx ) == MODE_INTRA ))
6804        {
6805          for( UInt uiCurrRefListId = 0; uiCurrRefListId < 2; uiCurrRefListId++ )       
6806          {
6807            RefPicList  eCurrRefPicList = RefPicList( uiCurrRefListId );
6808            Bool stopLoop = false;
6809            for(Int iLoop = 0; iLoop < 2 && !stopLoop; ++iLoop)
6810            {
6811              RefPicList eDefaultRefPicList = (iLoop ==1)? RefPicList( 1 -  uiCurrRefListId ) : RefPicList( uiCurrRefListId );
6812              TComMvField cDefaultMvField;
6813              pcDefaultCU->getMvField( pcDefaultCU, iRefCenterAbsPartIdx, eDefaultRefPicList, cDefaultMvField );
6814              Int         iDefaultRefIdx     = cDefaultMvField.getRefIdx();
6815              if (iDefaultRefIdx >= 0)
6816              {
6817                Int iDefaultRefPOC = pcDefaultCU->getSlice()->getRefPOC(eDefaultRefPicList, iDefaultRefIdx);
6818                if (iDefaultRefPOC != pcSlice->getPOC())   
6819                {
6820                  for (Int iPdmRefIdx = 0; iPdmRefIdx < pcSlice->getNumRefIdx( eCurrRefPicList ); iPdmRefIdx++)
6821                  {
6822                    if (iDefaultRefPOC == pcSlice->getRefPOC(eCurrRefPicList, iPdmRefIdx))
6823                    {
6824                      abPdmAvailable[ uiCurrRefListId ] = true;
6825                      TComMv cMv(cDefaultMvField.getHor(), cDefaultMvField.getVer());
6826#if H_3D_NBDV
6827#if H_3D_IV_MERGE
6828                      if( !bIsDepth )
6829                      {
6830#endif
6831                        cMv.setIDVFlag   (true);
6832                        cMv.setIDVHor    (cDv.getHor());                 
6833                        cMv.setIDVVer    (cDv.getVer()); 
6834                        cMv.setIDVVId    (iViewIndex); 
6835#if H_3D_IV_MERGE
6836                      }
6837#endif
6838#endif
6839#if !(NTT_BUG_FIX_TK54)
6840                      clipMv( cMv );
6841#endif
6842                      paiPdmRefIdx  [ uiCurrRefListId ] = iPdmRefIdx;
6843                      pacPdmMv      [ uiCurrRefListId ] = cMv;
6844                      stopLoop = true;
6845                      break;
6846                    }
6847                  }
6848                }
6849              }
6850            }
6851          }
6852        }
6853        availableMcDc[0] = ( abPdmAvailable[0]? 1 : 0) + (abPdmAvailable[1]? 2 : 0);
6854
6855        if(availableMcDc[0])
6856        {
6857
6858          Int         iBasePosX, iBasePosY;
6859          for (Int i=iCurrPosY; i < iCurrPosY + iHeight; i += iSPHeight)
6860          {
6861            for (Int j = iCurrPosX; j < iCurrPosX + iWidth; j += iSPWidth)
6862            {
6863              iBasePosX   = Clip3( 0, pcBaseRec->getWidth () - 1, j + iDelX + ( (cDv.getHor() + 2 ) >> 2 ));
6864              iBasePosY   = Clip3( 0, pcBaseRec->getHeight() - 1, i + iDelY + ( (cDv.getVer() + 2 ) >> 2 )); 
6865
6866              pcBaseRec->getCUAddrAndPartIdx( iBasePosX , iBasePosY, iBaseCUAddr, iBaseAbsPartIdx );
6867              pcBaseCU    = pcBasePic->getCU( iBaseCUAddr );
6868              if(!( pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) == MODE_INTRA ))
6869              {
6870                for( UInt uiCurrRefListId = 0; uiCurrRefListId < 2; uiCurrRefListId++ )
6871                {
6872                  RefPicList  eCurrRefPicList = RefPicList( uiCurrRefListId );
6873                  Bool bLoop_stop = false;
6874                  for(Int iLoop = 0; iLoop < 2 && !bLoop_stop; ++iLoop)
6875                  {
6876                    RefPicList eBaseRefPicList = (iLoop ==1)? RefPicList( 1 -  uiCurrRefListId ) : RefPicList( uiCurrRefListId );
6877                    TComMvField cBaseMvField;
6878                    pcBaseCU->getMvField( pcBaseCU, iBaseAbsPartIdx, eBaseRefPicList, cBaseMvField );
6879                    Int         iBaseRefIdx     = cBaseMvField.getRefIdx();
6880                    if (iBaseRefIdx >= 0)
6881                    {
6882                      Int iBaseRefPOC = pcBaseCU->getSlice()->getRefPOC(eBaseRefPicList, iBaseRefIdx);
6883                      if (iBaseRefPOC != pcSlice->getPOC())   
6884                      {
6885                        for (Int iPdmRefIdx = 0; iPdmRefIdx < pcSlice->getNumRefIdx( eCurrRefPicList ); iPdmRefIdx++)
6886                        {
6887                          if (iBaseRefPOC == pcSlice->getRefPOC(eCurrRefPicList, iPdmRefIdx))
6888                          {
6889                            abPdmAvailable[ uiCurrRefListId ] = true;
6890                            TComMv cMv(cBaseMvField.getHor(), cBaseMvField.getVer());
6891
6892                            if( !bIsDepth )
6893                            {
6894                              cMv.setIDVFlag   (true);
6895                              cMv.setIDVHor    (cDv.getHor());                 
6896                              cMv.setIDVVer    (cDv.getVer()); 
6897                              cMv.setIDVVId    (iViewIndex); 
6898                            }
6899
6900#if !(NTT_BUG_FIX_TK54)
6901                            clipMv( cMv );
6902#endif
6903                            bLoop_stop = true;
6904
6905                            pcMvFieldSP[2*iPartition + uiCurrRefListId].setMvField(cMv, iPdmRefIdx);
6906                            break;
6907                          }
6908                        }
6909                      }
6910                    }
6911                  }
6912                }
6913              }
6914
6915              puhInterDirSP[iPartition] = (pcMvFieldSP[2*iPartition].getRefIdx()!=-1 ? 1: 0) + (pcMvFieldSP[2*iPartition+1].getRefIdx()!=-1 ? 2: 0);
6916              if (puhInterDirSP[iPartition] == 0)
6917              {
6918                puhInterDirSP[iPartition] = availableMcDc[0];
6919                pcMvFieldSP[2*iPartition].setMvField(pacPdmMv[0], paiPdmRefIdx[0]);
6920                pcMvFieldSP[2*iPartition + 1].setMvField(pacPdmMv[1], paiPdmRefIdx[1]);
6921
6922              }
6923              if (iSPHeight + iSPWidth == 12)
6924              {
6925                if (puhInterDirSP[iPartition] == 3)
6926                {
6927                  puhInterDirSP[iPartition] = 1;
6928                  pcMvFieldSP[2*iPartition + 1].setMvField(TComMv(0,0), -1);
6929                }
6930              }
6931              iPartition ++;
6932            }
6933          }
6934        }
6935      }
6936
6937      iCurrPosX  += ( iWidth  >> 1 );
6938      iCurrPosY  += ( iHeight >> 1 );
6939    }
6940#endif
6941
6942    ////////////////////////////////
6943    /////// IvMC + IvMCShift ///////
6944    ////////////////////////////////
6945
6946#if H_3D_SPIVMP
6947    if(m_pcSlice->getIsDepth())
6948    {
6949      iCurrPosX  += ( iWidth  >> 1 );
6950      iCurrPosY  += ( iHeight >> 1 );
6951    }
6952    for(Int iLoopCan = ( (m_pcSlice->getIsDepth() || getDBBPFlag(0)) ? 0 : 1 ); iLoopCan < ( 2 - m_pcSlice->getIsDepth() ); iLoopCan ++) 
6953#else
6954    for(Int iLoopCan = 0; iLoopCan < 2; iLoopCan ++)
6955#endif
6956    {
6957      // iLoopCan == 0 --> IvMC
6958      // iLoopCan == 1 --> IvMCShift
6959
6960      Int         iBaseCUAddr;
6961      Int         iBaseAbsPartIdx;
6962
6963      Int offsetW = (iLoopCan == 0) ? 0 : ( ((iWidth /2)*4) + 4 );
6964      Int offsetH = (iLoopCan == 0) ? 0 : ( ((iHeight/2)*4) + 4 );
6965
6966      Int         iBasePosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (cDv.getHor() + offsetW + 2 ) >> 2 ) );
6967      Int         iBasePosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (cDv.getVer() + offsetH + 2 ) >> 2 ) ); 
6968      pcBaseRec->getCUAddrAndPartIdx( iBasePosX , iBasePosY , iBaseCUAddr, iBaseAbsPartIdx );
6969
6970      TComDataCU* pcBaseCU    = pcBasePic->getCU( iBaseCUAddr );
6971      if(!( pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) == MODE_INTRA ))
6972      {
6973        // Loop reference picture list of current slice (X in spec).
6974        for( UInt uiCurrRefListId = 0; uiCurrRefListId < 2; uiCurrRefListId++ )       
6975        {
6976          RefPicList  eCurrRefPicList = RefPicList( uiCurrRefListId );
6977
6978          Bool stopLoop = false;
6979          // Loop reference picture list of candidate slice (Y in spec)
6980          for(Int iLoop = 0; iLoop < 2 && !stopLoop; ++iLoop)
6981          {
6982            RefPicList eBaseRefPicList = (iLoop ==1)? RefPicList( 1 -  uiCurrRefListId ) : RefPicList( uiCurrRefListId );
6983            TComMvField cBaseMvField;
6984            pcBaseCU->getMvField( pcBaseCU, iBaseAbsPartIdx, eBaseRefPicList, cBaseMvField );
6985            Int         iBaseRefIdx     = cBaseMvField.getRefIdx();
6986            if (iBaseRefIdx >= 0)
6987            {
6988              Int iBaseRefPOC = pcBaseCU->getSlice()->getRefPOC(eBaseRefPicList, iBaseRefIdx);
6989              if (iBaseRefPOC != pcSlice->getPOC())   
6990              {
6991                for (Int iPdmRefIdx = 0; iPdmRefIdx < pcSlice->getNumRefIdx( eCurrRefPicList ); iPdmRefIdx++)
6992                {
6993                  if (iBaseRefPOC == pcSlice->getRefPOC(eCurrRefPicList, iPdmRefIdx))
6994                  {
6995                    abPdmAvailable[ (uiCurrRefListId + (iLoopCan<<2)) ] = true;
6996                    TComMv cMv(cBaseMvField.getHor(), cBaseMvField.getVer());
6997#if H_3D_NBDV
6998#if H_3D_IV_MERGE
6999                    if( !bIsDepth )
7000                    {
7001#endif
7002                      cMv.setIDVFlag   (true);
7003                      cMv.setIDVHor    (cDv.getHor());                 
7004                      cMv.setIDVVer    (cDv.getVer()); 
7005                      cMv.setIDVVId    (iViewIndex); 
7006#if H_3D_IV_MERGE
7007                    }
7008#endif
7009#endif
7010#if !(NTT_BUG_FIX_TK54)
7011                    clipMv( cMv );
7012#endif
7013                    paiPdmRefIdx  [ (uiCurrRefListId + (iLoopCan<<2)) ] = iPdmRefIdx;
7014                    pacPdmMv      [ (uiCurrRefListId + (iLoopCan<<2)) ] = cMv;
7015                    stopLoop = true;
7016                    break;
7017                  }
7018                }
7019              }
7020            }
7021          }
7022        }
7023      }
7024    }
7025#if H_3D_SPIVMP
7026    for(Int iLoopCan = ( (m_pcSlice->getIsDepth() || getDBBPFlag(0)) ? 0 : 1 ); iLoopCan < ( 2 - m_pcSlice->getIsDepth() ); iLoopCan ++)
7027#else
7028    for(Int iLoopCan = 0; iLoopCan < 2; iLoopCan ++)
7029#endif
7030    {
7031      availableMcDc[(iLoopCan << 1)] = ( abPdmAvailable[(iLoopCan<<2)] ? 1 : 0 ) + ( abPdmAvailable[1 + (iLoopCan<<2)] ? 2 : 0);
7032    }
7033
7034  }
7035
7036  ////////////////////////////////
7037  /////// IvDC + IvDCShift ///////
7038  ////////////////////////////////
7039
7040  if( !getSlice()->getIsDepth() )
7041  {
7042    for( Int iRefListId = 0; iRefListId < 2 ; iRefListId++ )
7043    {
7044      RefPicList  eRefPicListDMV       = RefPicList( iRefListId );
7045      Int         iNumRefPics       = pcSlice->getNumRefIdx( eRefPicListDMV );
7046      for( Int iPdmRefIdx = 0; iPdmRefIdx < iNumRefPics; iPdmRefIdx++ )
7047      {
7048        if(( pcSlice->getRefPOC( eRefPicListDMV, iPdmRefIdx ) == pcSlice->getPOC()) && (pcSlice->getRefPic( eRefPicListDMV, iPdmRefIdx )->getViewIndex() == pDInfo->m_aVIdxCan))
7049        {
7050          for(Int iLoopCan = 0; iLoopCan < 2; iLoopCan ++)
7051          {
7052            Int ioffsetDV = (iLoopCan == 0) ? 0 : 4;
7053            abPdmAvailable[ iRefListId + 2 + (iLoopCan<<2) ] = true;
7054            paiPdmRefIdx  [ iRefListId + 2 + (iLoopCan<<2) ] = iPdmRefIdx;
7055#if H_3D_NBDV_REF
7056            TComMv cMv = depthRefineFlag ? pDInfo->m_acDoNBDV : pDInfo->m_acNBDV; 
7057#endif
7058            cMv.setHor( cMv.getHor() + ioffsetDV );
7059#if H_3D_IV_MERGE
7060            if( bIsDepth )
7061            {
7062              cMv.setHor((cMv.getHor()+2)>>2); 
7063            }
7064#endif
7065            cMv.setVer( 0 );
7066#if !(NTT_BUG_FIX_TK54)
7067            clipMv( cMv );
7068#endif
7069            pacPdmMv      [iRefListId + 2 + (iLoopCan<<2)] = cMv;
7070          }
7071          break;
7072        }
7073      }
7074    }
7075    for(Int iLoopCan = 0; iLoopCan < 2; iLoopCan ++)
7076    {
7077      availableMcDc[1 + (iLoopCan << 1)] = ( abPdmAvailable[2 + (iLoopCan<<2)] ? 1 : 0 ) + ( abPdmAvailable[3 + (iLoopCan<<2)] ? 2 : 0 );
7078    }
7079  }
7080  return false;
7081}
7082#endif
7083#if H_3D_ARP
7084Void TComDataCU::setARPWSubParts ( UChar w, UInt uiAbsPartIdx, UInt uiDepth )
7085{
7086  assert( sizeof( *m_puhARPW) == 1 );
7087  memset( m_puhARPW + uiAbsPartIdx, w, m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ) );
7088}
7089#endif
7090
7091#if H_3D_IC
7092Void TComDataCU::setICFlagSubParts( Bool bICFlag, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
7093{
7094  memset( m_pbICFlag + uiAbsPartIdx, bICFlag, (m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ))*sizeof(Bool) );
7095}
7096
7097Bool TComDataCU::isICFlagRequired( UInt uiAbsPartIdx )
7098{
7099  UInt uiPartAddr;
7100  UInt iNumbPart;
7101
7102  if( !( getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) )
7103  {
7104    return false;
7105  }
7106
7107  if( getSlice()->getIcSkipParseFlag() )
7108  {
7109    if( getMergeFlag( uiAbsPartIdx ) && getMergeIndex( uiAbsPartIdx ) == 0 )
7110    {
7111      return false;
7112    }
7113  }
7114
7115  if( getMergeFlag( uiAbsPartIdx ) )
7116  {
7117    return true;
7118  }
7119
7120
7121  Int iWidth, iHeight;
7122
7123  iNumbPart = ( getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ? 1 : ( getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ? 4 : 2 ) );
7124
7125  for(UInt i = 0; i < iNumbPart; i++)
7126  {
7127    getPartIndexAndSize( i, uiPartAddr, iWidth, iHeight, uiAbsPartIdx, true );
7128    uiPartAddr += uiAbsPartIdx;
7129
7130    for(UInt uiRefIdx = 0; uiRefIdx < 2; uiRefIdx++)
7131    {
7132      RefPicList eRefList = uiRefIdx ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
7133      Int iBestRefIdx = getCUMvField(eRefList)->getRefIdx(uiPartAddr);
7134
7135      if( ( getInterDir( uiPartAddr ) & ( uiRefIdx+1 ) ) && iBestRefIdx >= 0 && getSlice()->getViewIndex() != getSlice()->getRefPic( eRefList, iBestRefIdx )->getViewIndex() )
7136      {
7137        return true;
7138      }
7139    }
7140  }
7141
7142  return false;
7143}
7144#endif
7145#if H_3D_DIM_DMM
7146Void TComDataCU::setDmmWedgeTabIdxSubParts( UInt tabIdx, UInt dmmType, UInt uiAbsPartIdx, UInt uiDepth )
7147{
7148  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
7149  for( UInt ui = 0; ui < uiCurrPartNumb; ui++ ) { m_dmmWedgeTabIdx[dmmType][uiAbsPartIdx+ui] = tabIdx; }
7150}
7151#endif
7152
7153#if H_3D_VSP
7154Void TComDataCU::setMvFieldPUForVSP( TComDataCU* pcCU, UInt partAddr, Int width, Int height, RefPicList eRefPicList, Int iRefIdx, Int &vspSize )
7155{
7156  // Get depth reference
7157  Int depthRefViewIdx = pcCU->getDvInfo(partAddr).m_aVIdxCan;
7158 
7159#if H_3D_FCO_VSP_DONBDV_E0163
7160  TComPic* pRefPicBaseDepth = 0;
7161  Bool     bIsCurrDepthCoded = false;
7162  pRefPicBaseDepth  = pcCU->getSlice()->getIvPic( true, pcCU->getSlice()->getViewIndex() );
7163  if ( pRefPicBaseDepth->getPicYuvRec() != NULL  ) 
7164  {
7165    bIsCurrDepthCoded = true;
7166  }
7167  else 
7168  {
7169    pRefPicBaseDepth = pcCU->getSlice()->getIvPic (true, depthRefViewIdx );
7170  }
7171#else
7172  TComPic* pRefPicBaseDepth = pcCU->getSlice()->getIvPic (true, depthRefViewIdx );
7173#endif
7174  assert(pRefPicBaseDepth != NULL);
7175  TComPicYuv* pcBaseViewDepthPicYuv = pRefPicBaseDepth->getPicYuvRec();
7176  assert(pcBaseViewDepthPicYuv != NULL);
7177  pcBaseViewDepthPicYuv->extendPicBorder();
7178
7179  // Get texture reference
7180  assert(iRefIdx >= 0);
7181  TComPic* pRefPicBaseTxt = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx );
7182  TComPicYuv* pcBaseViewTxtPicYuv = pRefPicBaseTxt->getPicYuvRec();
7183  assert(pcBaseViewTxtPicYuv != NULL);
7184
7185  // Initialize LUT according to the reference viewIdx
7186  Int txtRefViewIdx = pRefPicBaseTxt->getViewIndex();
7187  Int* pShiftLUT    = pcCU->getSlice()->getDepthToDisparityB( txtRefViewIdx );
7188  assert( txtRefViewIdx < pcCU->getSlice()->getViewIndex() );
7189
7190  // prepare Dv to access depth map or reference view
7191  TComMv cDv  = pcCU->getDvInfo(partAddr).m_acNBDV;
7192  pcCU->clipMv(cDv);
7193
7194#if H_3D_FCO_VSP_DONBDV_E0163
7195  if ( bIsCurrDepthCoded )
7196  {
7197      cDv.setZero();
7198  }
7199#endif
7200
7201  // fetch virtual depth map & convert depth to motion vector, which are stored in the motion memory
7202  xSetMvFieldForVSP( pcCU, pcBaseViewDepthPicYuv, &cDv, partAddr, width, height, pShiftLUT, eRefPicList, iRefIdx, pcCU->getSlice()->getIsDepth(), vspSize );
7203}
7204
7205Void TComDataCU::xSetMvFieldForVSP( TComDataCU *cu, TComPicYuv *picRefDepth, TComMv *dv, UInt partAddr, Int width, Int height, Int *shiftLUT, RefPicList refPicList, Int refIdx, Bool isDepth, Int &vspSize )
7206{
7207  TComCUMvField *cuMvField = cu->getCUMvField( refPicList );
7208  Int partAddrRasterSubPULine  = g_auiZscanToRaster[ partAddr ];
7209  Int numPartsLine    = cu->getPic()->getNumPartInWidth();
7210
7211  Int nTxtPerMvInfoX = 4; // cu->getPic()->getMinCUWidth();
7212  Int nTxtPerMvInfoY = 4; // cu->getPic()->getMinCUHeight();
7213
7214  Int refDepStride = picRefDepth->getStride();
7215
7216  TComMv tmpMv(0, 0);
7217  tmpMv.setIDVFlag(false);
7218
7219  Int refDepOffset  = ( (dv->getHor()+2) >> 2 ) + ( (dv->getVer()+2) >> 2 ) * refDepStride;
7220  Pel *refDepth     = picRefDepth->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refDepOffset;
7221
7222  if ((height % 8))
7223  {
7224    vspSize = 1; // 8x4
7225  }
7226  else if ((width % 8))
7227  {
7228    vspSize = 0; // 4x8
7229  }
7230  else
7231  {
7232    Bool ULvsBR, URvsBL;
7233    ULvsBR = refDepth[0]       < refDepth[refDepStride * (height-1) + width-1];
7234    URvsBL = refDepth[width-1] < refDepth[refDepStride * (height-1)];
7235    vspSize = ( ULvsBR ^ URvsBL ) ? 0 : 1;
7236  }
7237 
7238  Int subBlockW, subBlockH;
7239  if (vspSize)
7240  {
7241    subBlockW = 8;
7242    subBlockH = 4;
7243  }
7244  else
7245  {
7246    subBlockW = 4;
7247    subBlockH = 8;
7248  }
7249 
7250  Int numPartsInSubPUW = subBlockW / nTxtPerMvInfoX;
7251  Int numPartsInSubPUH = subBlockH / nTxtPerMvInfoY * numPartsLine;
7252
7253  for( Int y=0; y<height; y+=subBlockH, partAddrRasterSubPULine+=numPartsInSubPUH )
7254  {
7255    Pel *refDepthTmp[4];
7256    refDepthTmp[0] = refDepth + refDepStride * y;
7257    refDepthTmp[1] = refDepthTmp[0] + subBlockW - 1;
7258    refDepthTmp[2] = refDepthTmp[0] + refDepStride * (subBlockH - 1);
7259    refDepthTmp[3] = refDepthTmp[2] + subBlockW - 1;
7260
7261    Int partAddrRasterSubPU = partAddrRasterSubPULine;
7262    for( Int x=0; x<width; x+=subBlockW, partAddrRasterSubPU+=numPartsInSubPUW )
7263    {
7264      Pel  maxDepthVal;
7265      maxDepthVal = refDepthTmp[0][x];
7266      maxDepthVal = std::max( maxDepthVal, refDepthTmp[1][x]);
7267      maxDepthVal = std::max( maxDepthVal, refDepthTmp[2][x]);
7268      maxDepthVal = std::max( maxDepthVal, refDepthTmp[3][x]);
7269      tmpMv.setHor( (Short) shiftLUT[ maxDepthVal ] );
7270
7271      Int partAddrRasterPartLine = partAddrRasterSubPU;
7272      for( Int sY=0; sY<numPartsInSubPUH; sY+=numPartsLine, partAddrRasterPartLine += numPartsLine )
7273      {
7274        Int partAddrRasterPart = partAddrRasterPartLine;
7275        for( Int sX=0; sX<numPartsInSubPUW; sX+=1, partAddrRasterPart++ )
7276        {
7277          cuMvField->setMv    ( g_auiRasterToZscan[ partAddrRasterPart ], tmpMv );
7278          cuMvField->setRefIdx( g_auiRasterToZscan[ partAddrRasterPart ], refIdx );
7279        }
7280      }
7281    }
7282  }
7283
7284  vspSize = (vspSize<<2)+1;
7285
7286}
7287#endif
7288
7289//! \}
Note: See TracBrowser for help on using the repository browser.