source: 3DVCSoftware/branches/HTM-13.1-dev2-Sharp/source/Lib/TLibCommon/TComDataCU.cpp @ 1142

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

Integration of K0044 part2

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