source: 3DVCSoftware/trunk/source/Lib/TLibCommon/TComDataCU.cpp @ 1133

Last change on this file since 1133 was 1133, checked in by tech, 10 years ago

Merged 13.0-dev0@1132

  • Cleanup
  • TICKET083_IVPFLAG_FIX
  • Property svn:eol-style set to native
File size: 248.1 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 (iPUHeight + iPUWidth == 12)
4112            {
4113              if (puhInterDirSP[iPartition] == 3)
4114              {
4115                puhInterDirSP[iPartition] = 1;
4116                pcMvFieldSP[2*iPartition + 1].setMvField(TComMv(0,0), -1);
4117              }
4118            }
4119
4120            iPartition ++;
4121          }
4122        }
4123#if H_3D
4124      }
4125#endif
4126#if H_3D_FCO
4127    }
4128#endif
4129    if( tmpDir != 0 )
4130    {
4131      Int iCnloop = 0;
4132      for(iCnloop = 0; iCnloop < 2; iCnloop ++)
4133      {
4134        if ( !m_mergCands[MRG_A1+iCnloop].m_bAvailable )  // prunning to A1, B1
4135        {
4136          continue;
4137        }
4138        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])
4139        {
4140          m_mergCands[MRG_A1+iCnloop].m_bAvailable = false;
4141          break;
4142        }     
4143      }
4144      m_mergCands[MRG_T].setCand( tmpMV, tmpDir, false, bSPIVMPFlag);
4145
4146      if ( mrgCandIdx == iCount )
4147      {
4148        return;
4149      }
4150      iCount ++;
4151    }
4152  }
4153  /////////////////////////////////////////////////////////////////
4154  //////// DERIVE IvMC, IvMCShift,IvDCShift, IvDC  Candidates /////
4155  /////////////////////////////////////////////////////////////////
4156
4157  // { IvMCL0, IvMCL1, IvDCL0, IvDCL1, IvMCL0Shift, IvMCL1Shift, IvDCL0Shift, IvDCL1Shift }; 
4158  // An enumerator would be appropriate here!
4159  TComMv ivCandMv    [8];
4160  Int    ivCandRefIdx[8] = {-1, -1, -1, -1, -1, -1, -1, -1};
4161
4162  // { IvMC, IvDC, IvMCShift, IvDCShift }; 
4163  Int    ivCandDir   [4] = {0, 0, 0, 0};
4164
4165  Bool ivMvPredFlag   = getSlice()->getIvMvPredFlag();
4166
4167  ivMvPredFlag &= (nPSW + nPSH > 12);
4168  if ( ivMvPredFlag && cDisInfo.m_aVIdxCan!=-1)
4169  {
4170    getInterViewMergeCands(uiPUIdx, ivCandRefIdx, ivCandMv, &cDisInfo, ivCandDir , bIsDepth, pcMvFieldSP, puhInterDirSP, bICFlag );
4171  } 
4172
4173  ///////////////////////////////////////////////
4174  //////// INTER VIEW MOTION COMP(IvMC) /////////
4175  ///////////////////////////////////////////////
4176  if( getSlice()->getIsDepth() )
4177  {
4178    ivCandDir[1] = ivCandDir[2] = ivCandDir[3] = 0;
4179  }
4180
4181  if( ivCandDir[0] )
4182  {
4183    tmpMV[0].setMvField( cZeroMv, NOT_VALID );
4184    tmpMV[1].setMvField( cZeroMv, NOT_VALID );
4185
4186    if( ( ivCandDir[0] & 1 ) == 1 )
4187    {
4188      tmpMV[0].setMvField( ivCandMv[ 0 ], ivCandRefIdx[ 0 ] );
4189    }
4190    if( ( ivCandDir[0] & 2 ) == 2 )
4191    {
4192      tmpMV[1].setMvField( ivCandMv[ 1 ], ivCandRefIdx[ 1 ] );
4193    }
4194
4195    Bool bRemoveSpa = false; //pruning
4196
4197    if (!bIsDepth)
4198    {
4199      for(Int i = 0; i < 2; i ++)
4200      {
4201        if ( !m_mergCands[MRG_A1 + i].m_bAvailable ) // prunning to A1, B1
4202        {
4203          continue;
4204        }
4205        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])
4206        {
4207          m_mergCands[MRG_A1+i].m_bAvailable = false;
4208          break;
4209        }     
4210      }
4211    }
4212    if (bIsDepth)
4213    {
4214      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])
4215      {
4216        bRemoveSpa                      = true;
4217      }
4218    }
4219    if (!bRemoveSpa)
4220    {
4221      Bool SPIVMPFlag = false;
4222      if(!m_pcSlice->getIsDepth())
4223      {
4224        SPIVMPFlag = true;
4225      }
4226#if H_3D_DBBP
4227      SPIVMPFlag &= !bDBBPFlag;
4228#endif
4229
4230      m_mergCands[MRG_IVMC].setCand( tmpMV, ivCandDir[0], false, SPIVMPFlag);
4231
4232      if ( mrgCandIdx == iCount )
4233      {
4234        return;
4235      }
4236      iCount ++;
4237    }
4238  } 
4239
4240  // early termination
4241  if (iCount == getSlice()->getMaxNumMergeCand()) 
4242  {
4243    return;
4244  }
4245#endif
4246
4247#if H_3D
4248  iCount += m_mergCands[MRG_A1].m_bAvailable + m_mergCands[MRG_B1].m_bAvailable;
4249#else
4250  //left
4251  UInt uiLeftPartIdx = 0;
4252  TComDataCU* pcCULeft = 0;
4253  pcCULeft = getPULeft( uiLeftPartIdx, uiPartIdxLB );
4254  Bool isAvailableA1 = pcCULeft &&
4255    pcCULeft->isDiffMER(xP -1, yP+nPSH-1, xP, yP) &&
4256    !( uiPUIdx == 1 && (cCurPS == SIZE_Nx2N || cCurPS == SIZE_nLx2N || cCurPS == SIZE_nRx2N) ) &&
4257    !pcCULeft->isIntra( uiLeftPartIdx ) ;
4258  if ( isAvailableA1 )
4259  {
4260    abCandIsInter[iCount] = true;
4261    // get Inter Dir
4262    puhInterDirNeighbours[iCount] = pcCULeft->getInterDir( uiLeftPartIdx );
4263    // get Mv from Left
4264    pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
4265    if ( getSlice()->isInterB() )
4266    {
4267      pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
4268    }
4269
4270    if ( mrgCandIdx == iCount )
4271    {
4272      return;
4273    }
4274    iCount ++;
4275  }
4276
4277  // early termination
4278  if (iCount == getSlice()->getMaxNumMergeCand()) 
4279  {
4280    return;
4281  }
4282
4283  // above
4284  UInt uiAbovePartIdx = 0;
4285  TComDataCU* pcCUAbove = 0;
4286  pcCUAbove = getPUAbove( uiAbovePartIdx, uiPartIdxRT );
4287  Bool isAvailableB1 = pcCUAbove &&
4288    pcCUAbove->isDiffMER(xP+nPSW-1, yP-1, xP, yP) &&
4289    !( uiPUIdx == 1 && (cCurPS == SIZE_2NxN || cCurPS == SIZE_2NxnU || cCurPS == SIZE_2NxnD) ) &&
4290    !pcCUAbove->isIntra( uiAbovePartIdx );
4291  if ( isAvailableB1 && (!isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAbove, uiAbovePartIdx ) ) )
4292  {
4293    abCandIsInter[iCount] = true;
4294    // get Inter Dir
4295    puhInterDirNeighbours[iCount] = pcCUAbove->getInterDir( uiAbovePartIdx );
4296    // get Mv from Left
4297    pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
4298    if ( getSlice()->isInterB() )
4299    {
4300      pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
4301    }
4302
4303    if ( mrgCandIdx == iCount )
4304    {
4305      return;
4306    }
4307    iCount ++;
4308  }
4309  // early termination
4310  if (iCount == getSlice()->getMaxNumMergeCand()) 
4311  {
4312    return;
4313  }
4314
4315  // above right
4316  UInt uiAboveRightPartIdx = 0;
4317  TComDataCU* pcCUAboveRight = 0;
4318  pcCUAboveRight = getPUAboveRight( uiAboveRightPartIdx, uiPartIdxRT );
4319  Bool isAvailableB0 = pcCUAboveRight &&
4320    pcCUAboveRight->isDiffMER(xP+nPSW, yP-1, xP, yP) &&
4321    !pcCUAboveRight->isIntra( uiAboveRightPartIdx );
4322  if ( isAvailableB0 && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveRight, uiAboveRightPartIdx ) ) )
4323  {
4324    abCandIsInter[iCount] = true;
4325    // get Inter Dir
4326    puhInterDirNeighbours[iCount] = pcCUAboveRight->getInterDir( uiAboveRightPartIdx );
4327    // get Mv from Left
4328    pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
4329    if ( getSlice()->isInterB() )
4330    {
4331      pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
4332    }
4333
4334    if ( mrgCandIdx == iCount )
4335    {
4336      return;
4337    }
4338    iCount ++;
4339  }
4340  // early termination
4341  if (iCount == getSlice()->getMaxNumMergeCand()) 
4342  {
4343    return;
4344  }
4345#endif
4346
4347
4348#if H_3D_VSP
4349  /////////////////////////////////////////////////
4350  //////// VIEW SYNTHESIS PREDICTION (VSP) ////////
4351  /////////////////////////////////////////////////
4352  if (iCount<getSlice()->getMaxNumMergeCand())
4353  {
4354    if (
4355      (!getAvailableFlagA1() || !(pcCULeft->getVSPFlag(uiLeftPartIdx) != 0)) &&
4356#if H_3D_IC
4357      !bICFlag &&
4358#endif
4359#if H_3D_ARP
4360      !bARPFlag &&
4361#endif
4362#if H_3D
4363      (nPSW + nPSH > 12) &&
4364#endif
4365#if H_3D_DBBP
4366      !bDBBPFlag &&
4367#endif
4368      xAddVspCand( mrgCandIdx, &cDisInfo, iCount ) )
4369    {
4370      return;
4371    }
4372
4373    // early termination
4374    if (iCount == getSlice()->getMaxNumMergeCand())
4375    {
4376      return;
4377    }
4378#endif
4379#if H_3D_VSP
4380  }
4381#endif
4382
4383#if H_3D
4384  iCount += m_mergCands[MRG_B0].m_bAvailable;
4385#endif
4386
4387
4388#if H_3D_IV_MERGE
4389  /////////////////////////////////////////////
4390  //////// INTER VIEW DISP COMP (IvDC) ////////
4391  /////////////////////////////////////////////
4392  if( ivCandDir[1] && iCount < getSlice()->getMaxNumMergeCand() && !getSlice()->getIsDepth() )
4393  {
4394    assert(iCount < getSlice()->getMaxNumMergeCand());
4395
4396    tmpMV[0].setMvField( cZeroMv, NOT_VALID );
4397    tmpMV[1].setMvField( cZeroMv, NOT_VALID );
4398    if( ( ivCandDir[1] & 1 ) == 1 )
4399    {
4400      tmpMV[0].setMvField( ivCandMv[ 2 ], ivCandRefIdx[ 2 ] );
4401    }
4402    if( ( ivCandDir[1] & 2 ) == 2 )
4403    {
4404      tmpMV[1].setMvField( ivCandMv[ 3 ], ivCandRefIdx[ 3 ] );
4405    }
4406
4407    Bool bRemoveSpa = false; //pruning to A1, B1
4408    for(Int i = 0; i < 2; i ++)
4409    {
4410      if ( !m_mergCands[MRG_A1+i].m_bAvailable ) 
4411      {
4412        continue;
4413      }
4414      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])
4415      {
4416        bRemoveSpa                      = true;
4417        break;
4418      }     
4419    }
4420    if(!bRemoveSpa)
4421    {
4422#if H_3D_NBDV
4423      tmpMV[0].getMv().setIDVFlag (false);
4424      tmpMV[1].getMv().setIDVFlag (false);
4425#endif
4426      m_mergCands[MRG_IVDC].setCand( tmpMV, ivCandDir[1], false, false);
4427
4428      if ( mrgCandIdx == iCount )
4429        return;
4430      iCount ++;
4431
4432      // early termination
4433      if (iCount == getSlice()->getMaxNumMergeCand()) 
4434      {
4435        return;
4436      }
4437    }
4438  } 
4439#endif // H_3D_IV_MERGE
4440
4441
4442#if H_3D
4443  iCount += m_mergCands[MRG_A0].m_bAvailable + m_mergCands[MRG_B2].m_bAvailable;
4444#else
4445  //left bottom
4446  UInt uiLeftBottomPartIdx = 0;
4447  TComDataCU* pcCULeftBottom = 0;
4448  pcCULeftBottom = this->getPUBelowLeft( uiLeftBottomPartIdx, uiPartIdxLB );
4449  Bool isAvailableA0 = pcCULeftBottom &&
4450  pcCULeftBottom->isDiffMER(xP-1, yP+nPSH, xP, yP) &&
4451  !pcCULeftBottom->isIntra( uiLeftBottomPartIdx ) ;
4452  if ( isAvailableA0 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCULeftBottom, uiLeftBottomPartIdx ) ) )
4453  {
4454    abCandIsInter[iCount] = true;
4455    // get Inter Dir
4456    puhInterDirNeighbours[iCount] = pcCULeftBottom->getInterDir( uiLeftBottomPartIdx );
4457    // get Mv from Left
4458    pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
4459    if ( getSlice()->isInterB() )
4460    {
4461      pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
4462    }
4463    if ( mrgCandIdx == iCount )
4464    {
4465      return;
4466    }
4467    iCount ++;
4468  }
4469  // early termination
4470  if (iCount == getSlice()->getMaxNumMergeCand()) 
4471  {
4472    return;
4473  }
4474
4475  // above left
4476  if( iCount < 4 )
4477  {
4478    UInt uiAboveLeftPartIdx = 0;
4479    TComDataCU* pcCUAboveLeft = 0;
4480    pcCUAboveLeft = getPUAboveLeft( uiAboveLeftPartIdx, uiAbsPartAddr );
4481    Bool isAvailableB2 = pcCUAboveLeft &&
4482    pcCUAboveLeft->isDiffMER(xP-1, yP-1, xP, yP) &&
4483    !pcCUAboveLeft->isIntra( uiAboveLeftPartIdx );
4484    if ( isAvailableB2 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) )
4485        && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) ) )
4486    {
4487      abCandIsInter[iCount] = true;
4488      // get Inter Dir
4489      puhInterDirNeighbours[iCount] = pcCUAboveLeft->getInterDir( uiAboveLeftPartIdx );
4490      // get Mv from Left
4491      pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
4492      if ( getSlice()->isInterB() )
4493      {
4494        pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
4495      }
4496      if ( mrgCandIdx == iCount )
4497      {
4498        return;
4499      }
4500      iCount ++;
4501    }
4502  }
4503  // early termination
4504  if (iCount == getSlice()->getMaxNumMergeCand()) 
4505  {
4506    return;
4507  }
4508#endif
4509
4510
4511#if H_3D_IV_MERGE
4512  ////////////////////////////////////////////////////
4513  //////// SHIFTED IV (IvMCShift + IvDCShift) ////////
4514  ////////////////////////////////////////////////////
4515  if(  ivMvPredFlag && iCount < getSlice()->getMaxNumMergeCand() && !getSlice()->getIsDepth() ) 
4516  {
4517    if(xAddIvMRGCand( mrgCandIdx,  iCount, ivCandDir, ivCandMv, ivCandRefIdx ) )
4518    {
4519      return;
4520    }
4521    //early termination
4522    if (iCount == getSlice()->getMaxNumMergeCand()) 
4523    {
4524      return;
4525    }
4526  }
4527#endif
4528#if !H_3D
4529  if ( getSlice()->getEnableTMVPFlag())
4530  {
4531    //>> MTK colocated-RightBottom
4532    UInt uiPartIdxRB;
4533
4534    deriveRightBottomIdx( uiPUIdx, uiPartIdxRB ); 
4535
4536    UInt uiAbsPartIdxTmp = g_auiZscanToRaster[uiPartIdxRB];
4537    UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
4538
4539    TComMv cColMv;
4540    Int iRefIdx;
4541    Int uiLCUIdx = -1;
4542
4543    if      ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
4544    {
4545    }
4546    else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxTmp] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
4547    {
4548    }
4549    else
4550    {
4551      if ( ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
4552        ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
4553      {
4554        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + uiNumPartInCUWidth + 1 ];
4555        uiLCUIdx = getAddr();
4556      }
4557      else if ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
4558      {
4559        uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdxTmp + uiNumPartInCUWidth + 1) % m_pcPic->getNumPartInCU() ];
4560      }
4561      else if ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
4562      {
4563        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + 1 ];
4564        uiLCUIdx = getAddr() + 1;
4565      }
4566      else //is the right bottom corner of LCU                       
4567      {
4568        uiAbsPartAddr = 0;
4569      }
4570    }
4571   
4572   
4573    iRefIdx = 0;
4574    Bool bExistMV = false;
4575    UInt uiPartIdxCenter;
4576    UInt uiCurLCUIdx = getAddr();
4577    Int dir = 0;
4578    UInt uiArrayAddr = iCount;
4579    xDeriveCenterIdx( uiPUIdx, uiPartIdxCenter );
4580    bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_0, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx );
4581    if( bExistMV == false )
4582    {
4583      bExistMV = xGetColMVP( REF_PIC_LIST_0, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
4584    }
4585    if( bExistMV )
4586    {
4587      dir |= 1;
4588      pcMvFieldNeighbours[ 2 * uiArrayAddr ].setMvField( cColMv, iRefIdx );
4589    }
4590
4591    if ( getSlice()->isInterB() )
4592    {
4593      bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_1, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx);
4594      if( bExistMV == false )
4595      {
4596        bExistMV = xGetColMVP( REF_PIC_LIST_1, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
4597      }
4598      if( bExistMV )
4599      {
4600        dir |= 2;
4601        pcMvFieldNeighbours[ 2 * uiArrayAddr + 1 ].setMvField( cColMv, iRefIdx );
4602      }
4603    }
4604   
4605    if (dir != 0)
4606    {
4607      puhInterDirNeighbours[uiArrayAddr] = dir;
4608      abCandIsInter[uiArrayAddr] = true;
4609      if ( mrgCandIdx == iCount )
4610      {
4611        return;
4612      }
4613      iCount++;
4614    }
4615  }
4616  // early termination 
4617  if (iCount == getSlice()->getMaxNumMergeCand()) 
4618  {
4619    return;
4620  }
4621  UInt uiArrayAddr = iCount;
4622  UInt uiCutoff = uiArrayAddr;
4623   
4624  if ( getSlice()->isInterB())
4625  {
4626    UInt uiPriorityList0[12] = {0 , 1, 0, 2, 1, 2, 0, 3, 1, 3, 2, 3};
4627    UInt uiPriorityList1[12] = {1 , 0, 2, 0, 2, 1, 3, 0, 3, 1, 3, 2};
4628
4629    for (Int idx=0; idx<uiCutoff*(uiCutoff-1) && uiArrayAddr!= getSlice()->getMaxNumMergeCand(); idx++)
4630    {
4631      Int i = uiPriorityList0[idx]; Int j = uiPriorityList1[idx];
4632      if (abCandIsInter[i] && abCandIsInter[j]&& (puhInterDirNeighbours[i]&0x1)&&(puhInterDirNeighbours[j]&0x2))
4633      {
4634        abCandIsInter[uiArrayAddr] = true;
4635        puhInterDirNeighbours[uiArrayAddr] = 3;
4636
4637        // get Mv from cand[i] and cand[j]
4638        pcMvFieldNeighbours[uiArrayAddr << 1].setMvField(pcMvFieldNeighbours[i<<1].getMv(), pcMvFieldNeighbours[i<<1].getRefIdx());
4639        pcMvFieldNeighbours[( uiArrayAddr << 1 ) + 1].setMvField(pcMvFieldNeighbours[(j<<1)+1].getMv(), pcMvFieldNeighbours[(j<<1)+1].getRefIdx());
4640
4641        Int iRefPOCL0 = m_pcSlice->getRefPOC( REF_PIC_LIST_0, pcMvFieldNeighbours[(uiArrayAddr<<1)].getRefIdx() );
4642        Int iRefPOCL1 = m_pcSlice->getRefPOC( REF_PIC_LIST_1, pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getRefIdx() );
4643        if (iRefPOCL0 == iRefPOCL1 && pcMvFieldNeighbours[(uiArrayAddr<<1)].getMv() == pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getMv())
4644        {
4645          abCandIsInter[uiArrayAddr] = false;
4646        }
4647        else
4648        {
4649          uiArrayAddr++;
4650        }
4651      }
4652    }
4653  }
4654  // early termination
4655  if (uiArrayAddr == getSlice()->getMaxNumMergeCand()) 
4656  {
4657    return;
4658  }
4659  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);
4660  Int r = 0;
4661  Int refcnt = 0;
4662  while (uiArrayAddr < getSlice()->getMaxNumMergeCand())
4663  {
4664    abCandIsInter[uiArrayAddr] = true;
4665    puhInterDirNeighbours[uiArrayAddr] = 1;
4666    pcMvFieldNeighbours[uiArrayAddr << 1].setMvField( TComMv(0, 0), r);
4667
4668    if ( getSlice()->isInterB() )
4669    {
4670      puhInterDirNeighbours[uiArrayAddr] = 3;
4671      pcMvFieldNeighbours[(uiArrayAddr << 1) + 1].setMvField(TComMv(0, 0), r);
4672    }
4673    uiArrayAddr++;
4674    if ( refcnt == iNumRefIdx - 1 )
4675    {
4676      r = 0;
4677    }
4678    else
4679    {
4680      ++r;
4681      ++refcnt;
4682    }
4683  }
4684
4685  numValidMergeCand = uiArrayAddr;
4686#endif
4687}
4688#else
4689
4690/** Constructs a list of merging candidates
4691 * \param uiAbsPartIdx
4692 * \param uiPUIdx
4693 * \param uiDepth
4694 * \param pcMvFieldNeighbours
4695 * \param puhInterDirNeighbours
4696 * \param numValidMergeCand
4697 */
4698Void TComDataCU::getInterMergeCandidates( UInt uiAbsPartIdx, UInt uiPUIdx, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours
4699      , Int& numValidMergeCand, Int mrgCandIdx
4700)
4701{
4702  UInt uiAbsPartAddr = m_uiAbsIdxInLCU + uiAbsPartIdx;
4703  Bool abCandIsInter[ MRG_MAX_NUM_CANDS ];
4704  for( UInt ui = 0; ui < getSlice()->getMaxNumMergeCand(); ++ui )
4705  {
4706    abCandIsInter[ui] = false;
4707    pcMvFieldNeighbours[ ( ui << 1 )     ].setRefIdx(NOT_VALID);
4708    pcMvFieldNeighbours[ ( ui << 1 ) + 1 ].setRefIdx(NOT_VALID);
4709  }
4710  numValidMergeCand = getSlice()->getMaxNumMergeCand();
4711  // compute the location of the current PU
4712  Int xP, yP, nPSW, nPSH;
4713  this->getPartPosition(uiPUIdx, xP, yP, nPSW, nPSH);
4714
4715  Int iCount = 0;
4716
4717  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB;
4718  PartSize cCurPS = getPartitionSize( uiAbsPartIdx );
4719  deriveLeftRightTopIdxGeneral( uiAbsPartIdx, uiPUIdx, uiPartIdxLT, uiPartIdxRT );
4720  deriveLeftBottomIdxGeneral  ( uiAbsPartIdx, uiPUIdx, uiPartIdxLB );
4721
4722  //left
4723  UInt uiLeftPartIdx = 0;
4724  TComDataCU* pcCULeft = 0;
4725  pcCULeft = getPULeft( uiLeftPartIdx, uiPartIdxLB );
4726  Bool isAvailableA1 = pcCULeft &&
4727  pcCULeft->isDiffMER(xP -1, yP+nPSH-1, xP, yP) &&
4728  !( uiPUIdx == 1 && (cCurPS == SIZE_Nx2N || cCurPS == SIZE_nLx2N || cCurPS == SIZE_nRx2N) ) &&
4729  !pcCULeft->isIntra( uiLeftPartIdx ) ;
4730  if ( isAvailableA1 )
4731  {
4732    abCandIsInter[iCount] = true;
4733    // get Inter Dir
4734    puhInterDirNeighbours[iCount] = pcCULeft->getInterDir( uiLeftPartIdx );
4735    // get Mv from Left
4736    pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
4737    if ( getSlice()->isInterB() )
4738    {
4739      pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
4740    }
4741    if ( mrgCandIdx == iCount )
4742    {
4743      return;
4744    }
4745    iCount ++;
4746  }
4747 
4748  // early termination
4749  if (iCount == getSlice()->getMaxNumMergeCand()) 
4750  {
4751    return;
4752  }
4753
4754  // above
4755  UInt uiAbovePartIdx = 0;
4756  TComDataCU* pcCUAbove = 0;
4757  pcCUAbove = getPUAbove( uiAbovePartIdx, uiPartIdxRT );
4758  Bool isAvailableB1 = pcCUAbove &&
4759  pcCUAbove->isDiffMER(xP+nPSW-1, yP-1, xP, yP) &&
4760  !( uiPUIdx == 1 && (cCurPS == SIZE_2NxN || cCurPS == SIZE_2NxnU || cCurPS == SIZE_2NxnD) ) &&
4761  !pcCUAbove->isIntra( uiAbovePartIdx );
4762  if ( isAvailableB1 && (!isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAbove, uiAbovePartIdx ) ) )
4763  {
4764    abCandIsInter[iCount] = true;
4765    // get Inter Dir
4766    puhInterDirNeighbours[iCount] = pcCUAbove->getInterDir( uiAbovePartIdx );
4767    // get Mv from Left
4768    pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
4769    if ( getSlice()->isInterB() )
4770    {
4771      pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
4772    }
4773
4774    if ( mrgCandIdx == iCount )
4775    {
4776      return;
4777    }
4778    iCount ++;
4779  }
4780  // early termination
4781  if (iCount == getSlice()->getMaxNumMergeCand()) 
4782  {
4783    return;
4784  }
4785
4786
4787  // above right
4788  UInt uiAboveRightPartIdx = 0;
4789  TComDataCU* pcCUAboveRight = 0;
4790  pcCUAboveRight = getPUAboveRight( uiAboveRightPartIdx, uiPartIdxRT );
4791  Bool isAvailableB0 = pcCUAboveRight &&
4792  pcCUAboveRight->isDiffMER(xP+nPSW, yP-1, xP, yP) &&
4793  !pcCUAboveRight->isIntra( uiAboveRightPartIdx );
4794  if ( isAvailableB0 && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveRight, uiAboveRightPartIdx ) ) )
4795  {
4796    abCandIsInter[iCount] = true;
4797    // get Inter Dir
4798    puhInterDirNeighbours[iCount] = pcCUAboveRight->getInterDir( uiAboveRightPartIdx );
4799    // get Mv from Left
4800    pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
4801    if ( getSlice()->isInterB() )
4802    {
4803      pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
4804    }
4805    if ( mrgCandIdx == iCount )
4806    {
4807      return;
4808    }
4809    iCount ++;
4810  }
4811  // early termination
4812  if (iCount == getSlice()->getMaxNumMergeCand()) 
4813  {
4814    return;
4815  }
4816
4817  //left bottom
4818  UInt uiLeftBottomPartIdx = 0;
4819  TComDataCU* pcCULeftBottom = 0;
4820  pcCULeftBottom = this->getPUBelowLeft( uiLeftBottomPartIdx, uiPartIdxLB );
4821  Bool isAvailableA0 = pcCULeftBottom &&
4822  pcCULeftBottom->isDiffMER(xP-1, yP+nPSH, xP, yP) &&
4823  !pcCULeftBottom->isIntra( uiLeftBottomPartIdx ) ;
4824  if ( isAvailableA0 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCULeftBottom, uiLeftBottomPartIdx ) ) )
4825  {
4826    abCandIsInter[iCount] = true;
4827    // get Inter Dir
4828    puhInterDirNeighbours[iCount] = pcCULeftBottom->getInterDir( uiLeftBottomPartIdx );
4829    // get Mv from Left
4830    pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
4831    if ( getSlice()->isInterB() )
4832    {
4833      pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
4834    }
4835
4836    if ( mrgCandIdx == iCount )
4837    {
4838      return;
4839    }
4840    iCount ++;
4841  }
4842  // early termination
4843  if (iCount == getSlice()->getMaxNumMergeCand()) 
4844  {
4845    return;
4846  }
4847
4848  // above left
4849  if( iCount < 4 )
4850  {
4851    UInt uiAboveLeftPartIdx = 0;
4852    TComDataCU* pcCUAboveLeft = 0;
4853    pcCUAboveLeft = getPUAboveLeft( uiAboveLeftPartIdx, uiAbsPartAddr );
4854    Bool isAvailableB2 = pcCUAboveLeft &&
4855    pcCUAboveLeft->isDiffMER(xP-1, yP-1, xP, yP) &&
4856    !pcCUAboveLeft->isIntra( uiAboveLeftPartIdx );
4857    if ( isAvailableB2 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) )
4858        && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) ) )
4859    {
4860      abCandIsInter[iCount] = true;
4861      // get Inter Dir
4862      puhInterDirNeighbours[iCount] = pcCUAboveLeft->getInterDir( uiAboveLeftPartIdx );
4863      // get Mv from Left
4864      pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
4865      if ( getSlice()->isInterB() )
4866      {
4867        pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
4868      }
4869      if ( mrgCandIdx == iCount )
4870      {
4871        return;
4872      }
4873      iCount ++;
4874    }
4875  }
4876  // early termination
4877  if (iCount == getSlice()->getMaxNumMergeCand()) 
4878  {
4879    return;
4880  }
4881
4882  if ( getSlice()->getEnableTMVPFlag())
4883  {
4884    //>> MTK colocated-RightBottom
4885    UInt uiPartIdxRB;
4886
4887    deriveRightBottomIdx( uiPUIdx, uiPartIdxRB ); 
4888
4889    UInt uiAbsPartIdxTmp = g_auiZscanToRaster[uiPartIdxRB];
4890    UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
4891
4892    TComMv cColMv;
4893    Int iRefIdx;
4894    Int uiLCUIdx = -1;
4895
4896    if      ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
4897    {
4898    }
4899    else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxTmp] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
4900    {
4901    }
4902    else
4903    {
4904      if ( ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
4905        ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
4906      {
4907        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + uiNumPartInCUWidth + 1 ];
4908        uiLCUIdx = getAddr();
4909      }
4910      else if ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
4911      {
4912        uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdxTmp + uiNumPartInCUWidth + 1) % m_pcPic->getNumPartInCU() ];
4913      }
4914      else if ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
4915      {
4916        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + 1 ];
4917        uiLCUIdx = getAddr() + 1;
4918      }
4919      else //is the right bottom corner of LCU                       
4920      {
4921        uiAbsPartAddr = 0;
4922      }
4923    }
4924   
4925   
4926    iRefIdx = 0;
4927    Bool bExistMV = false;
4928    UInt uiPartIdxCenter;
4929    UInt uiCurLCUIdx = getAddr();
4930    Int dir = 0;
4931    UInt uiArrayAddr = iCount;
4932    xDeriveCenterIdx( uiPUIdx, uiPartIdxCenter );
4933    bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_0, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx );
4934    if( bExistMV == false )
4935    {
4936      bExistMV = xGetColMVP( REF_PIC_LIST_0, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
4937    }
4938    if( bExistMV )
4939    {
4940      dir |= 1;
4941      pcMvFieldNeighbours[ 2 * uiArrayAddr ].setMvField( cColMv, iRefIdx );
4942    }
4943
4944    if ( getSlice()->isInterB() )
4945    {
4946      bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_1, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx);
4947      if( bExistMV == false )
4948      {
4949        bExistMV = xGetColMVP( REF_PIC_LIST_1, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
4950      }
4951      if( bExistMV )
4952      {
4953        dir |= 2;
4954        pcMvFieldNeighbours[ 2 * uiArrayAddr + 1 ].setMvField( cColMv, iRefIdx );
4955      }
4956    }
4957   
4958    if (dir != 0)
4959    {
4960      puhInterDirNeighbours[uiArrayAddr] = dir;
4961      abCandIsInter[uiArrayAddr] = true;
4962      if ( mrgCandIdx == iCount )
4963      {
4964        return;
4965      }
4966      iCount++;
4967    }
4968  }
4969  // early termination
4970  if (iCount == getSlice()->getMaxNumMergeCand()) 
4971  {
4972    return;
4973  }
4974  UInt uiArrayAddr = iCount;
4975  UInt uiCutoff = uiArrayAddr;
4976   
4977  if ( getSlice()->isInterB())
4978  {
4979    UInt uiPriorityList0[12] = {0 , 1, 0, 2, 1, 2, 0, 3, 1, 3, 2, 3};
4980    UInt uiPriorityList1[12] = {1 , 0, 2, 0, 2, 1, 3, 0, 3, 1, 3, 2};
4981
4982    for (Int idx=0; idx<uiCutoff*(uiCutoff-1) && uiArrayAddr!= getSlice()->getMaxNumMergeCand(); idx++)
4983    {
4984      Int i = uiPriorityList0[idx]; Int j = uiPriorityList1[idx];
4985      if (abCandIsInter[i] && abCandIsInter[j]&& (puhInterDirNeighbours[i]&0x1)&&(puhInterDirNeighbours[j]&0x2))
4986      {
4987        abCandIsInter[uiArrayAddr] = true;
4988        puhInterDirNeighbours[uiArrayAddr] = 3;
4989
4990        // get Mv from cand[i] and cand[j]
4991        pcMvFieldNeighbours[uiArrayAddr << 1].setMvField(pcMvFieldNeighbours[i<<1].getMv(), pcMvFieldNeighbours[i<<1].getRefIdx());
4992        pcMvFieldNeighbours[( uiArrayAddr << 1 ) + 1].setMvField(pcMvFieldNeighbours[(j<<1)+1].getMv(), pcMvFieldNeighbours[(j<<1)+1].getRefIdx());
4993
4994        Int iRefPOCL0 = m_pcSlice->getRefPOC( REF_PIC_LIST_0, pcMvFieldNeighbours[(uiArrayAddr<<1)].getRefIdx() );
4995        Int iRefPOCL1 = m_pcSlice->getRefPOC( REF_PIC_LIST_1, pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getRefIdx() );
4996        if (iRefPOCL0 == iRefPOCL1 && pcMvFieldNeighbours[(uiArrayAddr<<1)].getMv() == pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getMv())
4997        {
4998          abCandIsInter[uiArrayAddr] = false;
4999        }
5000        else
5001        {
5002          uiArrayAddr++;
5003        }
5004      }
5005    }
5006  }
5007  // early termination
5008  if (uiArrayAddr == getSlice()->getMaxNumMergeCand()) 
5009  {
5010    return;
5011  }
5012  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);
5013  Int r = 0;
5014  Int refcnt = 0;
5015  while (uiArrayAddr < getSlice()->getMaxNumMergeCand())
5016  {
5017    abCandIsInter[uiArrayAddr] = true;
5018    puhInterDirNeighbours[uiArrayAddr] = 1;
5019    pcMvFieldNeighbours[uiArrayAddr << 1].setMvField( TComMv(0, 0), r);
5020
5021    if ( getSlice()->isInterB() )
5022    {
5023      puhInterDirNeighbours[uiArrayAddr] = 3;
5024      pcMvFieldNeighbours[(uiArrayAddr << 1) + 1].setMvField(TComMv(0, 0), r);
5025    }
5026    uiArrayAddr++;
5027    if ( refcnt == iNumRefIdx - 1 )
5028    {
5029      r = 0;
5030    }
5031    else
5032    {
5033      ++r;
5034      ++refcnt;
5035    }
5036  }
5037
5038  numValidMergeCand = uiArrayAddr;
5039}
5040#endif
5041
5042/** Check whether the current PU and a spatial neighboring PU are in a same ME region.
5043 * \param xN, xN   location of the upper-left corner pixel of a neighboring PU
5044 * \param xP, yP   location of the upper-left corner pixel of the current PU
5045 * \returns Bool
5046 */
5047Bool TComDataCU::isDiffMER(Int xN, Int yN, Int xP, Int yP)
5048{
5049
5050  UInt plevel = this->getSlice()->getPPS()->getLog2ParallelMergeLevelMinus2() + 2;
5051  if ((xN>>plevel)!= (xP>>plevel))
5052  {
5053    return true;
5054  }
5055  if ((yN>>plevel)!= (yP>>plevel))
5056  {
5057    return true;
5058  }
5059  return false;
5060}
5061/** calculate the location of upper-left corner pixel and size of the current PU.
5062 * \param partIdx  PU index within a CU
5063 * \param xP, yP   location of the upper-left corner pixel of the current PU
5064 * \param PSW, nPSH    size of the curren PU
5065 * \returns Void
5066 */
5067Void TComDataCU::getPartPosition( UInt partIdx, Int& xP, Int& yP, Int& nPSW, Int& nPSH)
5068{
5069  UInt col = m_uiCUPelX;
5070  UInt row = m_uiCUPelY;
5071
5072  switch ( m_pePartSize[0] )
5073  {
5074  case SIZE_2NxN:
5075    nPSW = getWidth(0);     
5076    nPSH = getHeight(0) >> 1; 
5077    xP   = col;
5078    yP   = (partIdx ==0)? row: row + nPSH;
5079    break;
5080  case SIZE_Nx2N:
5081    nPSW = getWidth(0) >> 1; 
5082    nPSH = getHeight(0);     
5083    xP   = (partIdx ==0)? col: col + nPSW;
5084    yP   = row;
5085    break;
5086  case SIZE_NxN:
5087    nPSW = getWidth(0) >> 1; 
5088    nPSH = getHeight(0) >> 1; 
5089    xP   = col + (partIdx&0x1)*nPSW;
5090    yP   = row + (partIdx>>1)*nPSH;
5091    break;
5092  case SIZE_2NxnU:
5093    nPSW = getWidth(0);
5094    nPSH = ( partIdx == 0 ) ?  getHeight(0) >> 2 : ( getHeight(0) >> 2 ) + ( getHeight(0) >> 1 );
5095    xP   = col;
5096    yP   = (partIdx ==0)? row: row + getHeight(0) - nPSH;
5097
5098    break;
5099  case SIZE_2NxnD:
5100    nPSW = getWidth(0);
5101    nPSH = ( partIdx == 0 ) ?  ( getHeight(0) >> 2 ) + ( getHeight(0) >> 1 ) : getHeight(0) >> 2;
5102    xP   = col;
5103    yP   = (partIdx ==0)? row: row + getHeight(0) - nPSH;
5104    break;
5105  case SIZE_nLx2N:
5106    nPSW = ( partIdx == 0 ) ? getWidth(0) >> 2 : ( getWidth(0) >> 2 ) + ( getWidth(0) >> 1 );
5107    nPSH = getHeight(0);
5108    xP   = (partIdx ==0)? col: col + getWidth(0) - nPSW;
5109    yP   = row;
5110    break;
5111  case SIZE_nRx2N:
5112    nPSW = ( partIdx == 0 ) ? ( getWidth(0) >> 2 ) + ( getWidth(0) >> 1 ) : getWidth(0) >> 2;
5113    nPSH = getHeight(0);
5114    xP   = (partIdx ==0)? col: col + getWidth(0) - nPSW;
5115    yP   = row;
5116    break;
5117  default:
5118    assert ( m_pePartSize[0] == SIZE_2Nx2N );
5119    nPSW = getWidth(0);     
5120    nPSH = getHeight(0);     
5121    xP   = col ;
5122    yP   = row ;
5123
5124    break;
5125  }
5126}
5127
5128/** Constructs a list of candidates for AMVP
5129 * \param uiPartIdx
5130 * \param uiPartAddr
5131 * \param eRefPicList
5132 * \param iRefIdx
5133 * \param pInfo
5134 */
5135Void TComDataCU::fillMvpCand ( UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, Int iRefIdx, AMVPInfo* pInfo )
5136{
5137  TComMv cMvPred;
5138  Bool bAddedSmvp = false;
5139
5140  pInfo->iN = 0; 
5141  if (iRefIdx < 0)
5142  {
5143    return;
5144  }
5145 
5146  //-- Get Spatial MV
5147  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB;
5148  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
5149  Bool bAdded = false;
5150 
5151  deriveLeftRightTopIdx( uiPartIdx, uiPartIdxLT, uiPartIdxRT );
5152  deriveLeftBottomIdx( uiPartIdx, uiPartIdxLB );
5153 
5154  TComDataCU* tmpCU = NULL;
5155  UInt idx;
5156  tmpCU = getPUBelowLeft(idx, uiPartIdxLB);
5157  bAddedSmvp = (tmpCU != NULL) && (tmpCU->getPredictionMode(idx) != MODE_INTRA);
5158
5159  if (!bAddedSmvp)
5160  {
5161    tmpCU = getPULeft(idx, uiPartIdxLB);
5162    bAddedSmvp = (tmpCU != NULL) && (tmpCU->getPredictionMode(idx) != MODE_INTRA);
5163  }
5164
5165  // Left predictor search
5166  bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_BELOW_LEFT);
5167  if (!bAdded) 
5168  {
5169    bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_LEFT );
5170  }
5171 
5172  if(!bAdded)
5173  {
5174    bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_BELOW_LEFT);
5175    if (!bAdded) 
5176    {
5177      xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_LEFT );
5178    }
5179  }
5180  // Above predictor search
5181  bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE_RIGHT);
5182
5183  if (!bAdded) 
5184  {
5185    bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE);
5186  }
5187
5188  if(!bAdded)
5189  {
5190    xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLT, MD_ABOVE_LEFT);
5191  }
5192
5193  if (!bAddedSmvp)
5194  {
5195    bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE_RIGHT);
5196    if (!bAdded) 
5197    {
5198      bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE);
5199    }
5200
5201    if(!bAdded)
5202    {
5203      xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLT, MD_ABOVE_LEFT);
5204    }
5205  }
5206 
5207  if ( pInfo->iN == 2 )
5208  {
5209    if ( pInfo->m_acMvCand[ 0 ] == pInfo->m_acMvCand[ 1 ] )
5210    {
5211      pInfo->iN = 1;
5212    }
5213  }
5214
5215  if ( getSlice()->getEnableTMVPFlag() )
5216  {
5217    // Get Temporal Motion Predictor
5218    Int iRefIdx_Col = iRefIdx;
5219    TComMv cColMv;
5220    UInt uiPartIdxRB;
5221    UInt uiAbsPartIdx; 
5222    UInt uiAbsPartAddr;
5223
5224    deriveRightBottomIdx( uiPartIdx, uiPartIdxRB );
5225    uiAbsPartAddr = m_uiAbsIdxInLCU + uiPartAddr;
5226
5227    //----  co-located RightBottom Temporal Predictor (H) ---//
5228    uiAbsPartIdx = g_auiZscanToRaster[uiPartIdxRB];
5229    Int uiLCUIdx = -1;
5230    if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdx] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
5231    {
5232    }
5233    else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdx] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
5234    {
5235    }
5236    else
5237    {
5238      if ( ( uiAbsPartIdx % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
5239        ( uiAbsPartIdx / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
5240      {
5241        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdx + uiNumPartInCUWidth + 1 ];
5242        uiLCUIdx = getAddr();
5243      }
5244      else if ( uiAbsPartIdx % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
5245      {
5246        uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdx + uiNumPartInCUWidth + 1) % m_pcPic->getNumPartInCU() ];
5247      }
5248      else if ( uiAbsPartIdx / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
5249      {
5250        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdx + 1 ];
5251        uiLCUIdx = getAddr() + 1;
5252      }
5253      else //is the right bottom corner of LCU                       
5254      {
5255        uiAbsPartAddr = 0;
5256      }
5257    }
5258    if ( uiLCUIdx >= 0 && xGetColMVP( eRefPicList, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx_Col
5259#if H_3D_TMVP
5260         , 0
5261#endif
5262    ) )
5263    {
5264      pInfo->m_acMvCand[pInfo->iN++] = cColMv;
5265    }
5266    else 
5267    {
5268      UInt uiPartIdxCenter;
5269      UInt uiCurLCUIdx = getAddr();
5270      xDeriveCenterIdx( uiPartIdx, uiPartIdxCenter );
5271      if (xGetColMVP( eRefPicList, uiCurLCUIdx, uiPartIdxCenter,  cColMv, iRefIdx_Col
5272#if H_3D_TMVP
5273         , 0
5274#endif
5275      ))
5276      {
5277        pInfo->m_acMvCand[pInfo->iN++] = cColMv;
5278      }
5279    }
5280    //----  co-located RightBottom Temporal Predictor  ---//
5281  }
5282
5283  if (pInfo->iN > AMVP_MAX_NUM_CANDS)
5284  {
5285    pInfo->iN = AMVP_MAX_NUM_CANDS;
5286  }
5287  while (pInfo->iN < AMVP_MAX_NUM_CANDS)
5288  {
5289      pInfo->m_acMvCand[pInfo->iN].set(0,0);
5290      pInfo->iN++;
5291  }
5292  return ;
5293}
5294
5295Bool TComDataCU::isBipredRestriction(UInt puIdx)
5296{
5297  Int width = 0;
5298  Int height = 0;
5299  UInt partAddr;
5300 
5301#if H_3D_DBBP
5302  if( getDBBPFlag(0) )
5303  {
5304    return true;
5305  }
5306#endif
5307
5308  getPartIndexAndSize( puIdx, partAddr, width, height );
5309  if ( getWidth(0) == 8 && (width < 8 || height < 8) )
5310  {
5311    return true;
5312  }
5313  return false;
5314}
5315
5316Void TComDataCU::clipMv    (TComMv&  rcMv)
5317{
5318  Int  iMvShift = 2;
5319#if H_3D_IC
5320  if( getSlice()->getIsDepth() )
5321    iMvShift = 0;
5322#endif
5323  Int iOffset = 8;
5324  Int iHorMax = ( m_pcSlice->getSPS()->getPicWidthInLumaSamples() + iOffset - m_uiCUPelX - 1 ) << iMvShift;
5325  Int iHorMin = (       -(Int)g_uiMaxCUWidth - iOffset - (Int)m_uiCUPelX + 1 ) << iMvShift;
5326 
5327  Int iVerMax = ( m_pcSlice->getSPS()->getPicHeightInLumaSamples() + iOffset - m_uiCUPelY - 1 ) << iMvShift;
5328  Int iVerMin = (       -(Int)g_uiMaxCUHeight - iOffset - (Int)m_uiCUPelY + 1 ) << iMvShift;
5329 
5330  rcMv.setHor( min (iHorMax, max (iHorMin, rcMv.getHor())) );
5331  rcMv.setVer( min (iVerMax, max (iVerMin, rcMv.getVer())) );
5332}
5333
5334UInt TComDataCU::getIntraSizeIdx(UInt uiAbsPartIdx)
5335{
5336  UInt uiShift = ( m_pePartSize[uiAbsPartIdx]==SIZE_NxN ? 1 : 0 );
5337 
5338  UChar uiWidth = m_puhWidth[uiAbsPartIdx]>>uiShift;
5339  UInt  uiCnt = 0;
5340  while( uiWidth )
5341  {
5342    uiCnt++;
5343    uiWidth>>=1;
5344  }
5345  uiCnt-=2;
5346  return uiCnt > 6 ? 6 : uiCnt;
5347}
5348
5349Void TComDataCU::clearCbf( UInt uiIdx, TextType eType, UInt uiNumParts )
5350{
5351  ::memset( &m_puhCbf[g_aucConvertTxtTypeToIdx[eType]][uiIdx], 0, sizeof(UChar)*uiNumParts);
5352}
5353
5354/** Set a I_PCM flag for all sub-partitions of a partition.
5355 * \param bIpcmFlag I_PCM flag
5356 * \param uiAbsPartIdx patition index
5357 * \param uiDepth CU depth
5358 * \returns Void
5359 */
5360Void TComDataCU::setIPCMFlagSubParts  (Bool bIpcmFlag, UInt uiAbsPartIdx, UInt uiDepth)
5361{
5362  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
5363
5364  memset(m_pbIPCMFlag + uiAbsPartIdx, bIpcmFlag, sizeof(Bool)*uiCurrPartNumb );
5365}
5366
5367/** Test whether the current block is skipped
5368 * \param uiPartIdx Block index
5369 * \returns Flag indicating whether the block is skipped
5370 */
5371Bool TComDataCU::isSkipped( UInt uiPartIdx )
5372{
5373  return ( getSkipFlag( uiPartIdx ) );
5374}
5375
5376#if H_3D_IC
5377Bool TComDataCU::isIC( UInt uiPartIdx )
5378{
5379    if ( m_pcSlice->isIntra () )
5380    {
5381        return false;
5382    }
5383    return ( ( getSkipFlag(uiPartIdx) || getPredictionMode(uiPartIdx) == MODE_INTER) && getICFlag( uiPartIdx ) && isICFlagRequired( uiPartIdx ) );
5384}
5385#endif
5386
5387// ====================================================================================================================
5388// Protected member functions
5389// ====================================================================================================================
5390
5391Bool TComDataCU::xAddMVPCand( AMVPInfo* pInfo, RefPicList eRefPicList, Int iRefIdx, UInt uiPartUnitIdx, MVP_DIR eDir )
5392{
5393  TComDataCU* pcTmpCU = NULL;
5394  UInt uiIdx;
5395  switch( eDir )
5396  {
5397    case MD_LEFT:
5398    {
5399      pcTmpCU = getPULeft(uiIdx, uiPartUnitIdx);
5400      break;
5401    }
5402    case MD_ABOVE:
5403    {
5404      pcTmpCU = getPUAbove(uiIdx, uiPartUnitIdx );
5405      break;
5406    }
5407    case MD_ABOVE_RIGHT:
5408    {
5409      pcTmpCU = getPUAboveRight(uiIdx, uiPartUnitIdx);
5410      break;
5411    }
5412    case MD_BELOW_LEFT:
5413    {
5414      pcTmpCU = getPUBelowLeft(uiIdx, uiPartUnitIdx);
5415      break;
5416    }
5417    case MD_ABOVE_LEFT:
5418    {
5419      pcTmpCU = getPUAboveLeft(uiIdx, uiPartUnitIdx);
5420      break;
5421    }
5422    default:
5423    {
5424      break;
5425    }
5426  }
5427
5428  if ( pcTmpCU == NULL )
5429  {
5430    return false;
5431  }
5432 
5433  if ( pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) >= 0 && m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getPOC() == pcTmpCU->getSlice()->getRefPOC( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) ))
5434  {
5435    TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
5436   
5437    pInfo->m_acMvCand[ pInfo->iN++] = cMvPred;
5438    return true;
5439  }
5440
5441  RefPicList eRefPicList2nd = REF_PIC_LIST_0;
5442  if(       eRefPicList == REF_PIC_LIST_0 )
5443  {
5444    eRefPicList2nd = REF_PIC_LIST_1;
5445  }
5446  else if ( eRefPicList == REF_PIC_LIST_1)
5447  {
5448    eRefPicList2nd = REF_PIC_LIST_0;
5449  }
5450
5451
5452  Int iCurrRefPOC = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getPOC();
5453  Int iNeibRefPOC;
5454
5455
5456  if( pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) >= 0 )
5457  {
5458    iNeibRefPOC = pcTmpCU->getSlice()->getRefPOC( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) );
5459    if( iNeibRefPOC == iCurrRefPOC ) // Same Reference Frame But Diff List//
5460    {
5461      TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList2nd)->getMv(uiIdx);
5462      pInfo->m_acMvCand[ pInfo->iN++] = cMvPred;
5463      return true;
5464    }
5465  }
5466  return false;
5467}
5468
5469/**
5470 * \param pInfo
5471 * \param eRefPicList
5472 * \param iRefIdx
5473 * \param uiPartUnitIdx
5474 * \param eDir
5475 * \returns Bool
5476 */
5477Bool TComDataCU::xAddMVPCandOrder( AMVPInfo* pInfo, RefPicList eRefPicList, Int iRefIdx, UInt uiPartUnitIdx, MVP_DIR eDir )
5478{
5479  TComDataCU* pcTmpCU = NULL;
5480  UInt uiIdx;
5481  switch( eDir )
5482  {
5483  case MD_LEFT:
5484    {
5485      pcTmpCU = getPULeft(uiIdx, uiPartUnitIdx);
5486      break;
5487    }
5488  case MD_ABOVE:
5489    {
5490      pcTmpCU = getPUAbove(uiIdx, uiPartUnitIdx);
5491      break;
5492    }
5493  case MD_ABOVE_RIGHT:
5494    {
5495      pcTmpCU = getPUAboveRight(uiIdx, uiPartUnitIdx);
5496      break;
5497    }
5498  case MD_BELOW_LEFT:
5499    {
5500      pcTmpCU = getPUBelowLeft(uiIdx, uiPartUnitIdx);
5501      break;
5502    }
5503  case MD_ABOVE_LEFT:
5504    {
5505      pcTmpCU = getPUAboveLeft(uiIdx, uiPartUnitIdx);
5506      break;
5507    }
5508  default:
5509    {
5510      break;
5511    }
5512  }
5513
5514  if ( pcTmpCU == NULL ) 
5515  {
5516    return false;
5517  }
5518 
5519  RefPicList eRefPicList2nd = REF_PIC_LIST_0;
5520  if(       eRefPicList == REF_PIC_LIST_0 )
5521  {
5522    eRefPicList2nd = REF_PIC_LIST_1;
5523  }
5524  else if ( eRefPicList == REF_PIC_LIST_1)
5525  {
5526    eRefPicList2nd = REF_PIC_LIST_0;
5527  }
5528
5529  Int iCurrPOC = m_pcSlice->getPOC();
5530  Int iCurrRefPOC = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getPOC();
5531  Int iNeibPOC = iCurrPOC;
5532  Int iNeibRefPOC;
5533
5534  Bool bIsCurrRefLongTerm = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getIsLongTerm();
5535  Bool bIsNeibRefLongTerm = false;
5536  //---------------  V1 (END) ------------------//
5537  if( pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) >= 0)
5538  {
5539    iNeibRefPOC = pcTmpCU->getSlice()->getRefPOC( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) );
5540    TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
5541    TComMv rcMv;
5542
5543    bIsNeibRefLongTerm = pcTmpCU->getSlice()->getRefPic( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) )->getIsLongTerm();
5544    if ( bIsCurrRefLongTerm == bIsNeibRefLongTerm ) 
5545    {
5546    if ( bIsCurrRefLongTerm || bIsNeibRefLongTerm )
5547    {
5548      rcMv = cMvPred;
5549    }
5550    else
5551    {
5552      Int iScale = xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
5553      if ( iScale == 4096 )
5554      {
5555        rcMv = cMvPred;
5556      }
5557      else
5558      {
5559        rcMv = cMvPred.scaleMv( iScale );
5560      }
5561    }
5562    pInfo->m_acMvCand[ pInfo->iN++] = rcMv;
5563    return true;
5564    }
5565  }
5566  //---------------------- V2(END) --------------------//
5567  if( pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) >= 0)
5568  {
5569    iNeibRefPOC = pcTmpCU->getSlice()->getRefPOC( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) );
5570    TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList2nd)->getMv(uiIdx);
5571    TComMv rcMv;
5572
5573    bIsNeibRefLongTerm = pcTmpCU->getSlice()->getRefPic( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) )->getIsLongTerm();
5574    if ( bIsCurrRefLongTerm == bIsNeibRefLongTerm ) 
5575    {
5576    if ( bIsCurrRefLongTerm || bIsNeibRefLongTerm )
5577    {
5578      rcMv = cMvPred;
5579    }
5580    else
5581    {
5582      Int iScale = xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
5583      if ( iScale == 4096 )
5584      {
5585        rcMv = cMvPred;
5586      }
5587      else
5588      {
5589        rcMv = cMvPred.scaleMv( iScale );
5590      }
5591    }
5592    pInfo->m_acMvCand[ pInfo->iN++] = rcMv;
5593    return true;
5594    }
5595  }
5596  //---------------------- V3(END) --------------------//
5597  return false;
5598}
5599
5600/**
5601 * \param eRefPicList
5602 * \param uiCUAddr
5603 * \param uiPartUnitIdx
5604 * \param riRefIdx
5605 * \returns Bool
5606 */
5607Bool TComDataCU::xGetColMVP( RefPicList eRefPicList, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv, Int& riRefIdx
5608#if H_3D_TMVP
5609  , Bool bMRG
5610#endif
5611  )
5612{
5613  UInt uiAbsPartAddr = uiPartUnitIdx;
5614
5615  RefPicList  eColRefPicList;
5616  Int iColPOC, iColRefPOC, iCurrPOC, iCurrRefPOC, iScale;
5617  TComMv cColMv;
5618
5619  // use coldir.
5620  TComPic *pColPic = getSlice()->getRefPic( RefPicList(getSlice()->isInterB() ? 1-getSlice()->getColFromL0Flag() : 0), getSlice()->getColRefIdx());
5621  TComDataCU *pColCU = pColPic->getCU( uiCUAddr );
5622  if(pColCU->getPic()==0||pColCU->getPartitionSize(uiPartUnitIdx)==SIZE_NONE)
5623  {
5624    return false;
5625  }
5626  iCurrPOC = m_pcSlice->getPOC();   
5627  iColPOC = pColCU->getSlice()->getPOC(); 
5628
5629  if (pColCU->isIntra(uiAbsPartAddr))
5630  {
5631    return false;
5632  }
5633  eColRefPicList = getSlice()->getCheckLDC() ? eRefPicList : RefPicList(getSlice()->getColFromL0Flag());
5634
5635  Int iColRefIdx = pColCU->getCUMvField(RefPicList(eColRefPicList))->getRefIdx(uiAbsPartAddr);
5636
5637  if (iColRefIdx < 0 )
5638  {
5639    eColRefPicList = RefPicList(1 - eColRefPicList);
5640    iColRefIdx = pColCU->getCUMvField(RefPicList(eColRefPicList))->getRefIdx(uiAbsPartAddr);
5641
5642    if (iColRefIdx < 0 )
5643    {
5644      return false;
5645    }
5646  }
5647
5648  // Scale the vector.
5649  iColRefPOC = pColCU->getSlice()->getRefPOC(eColRefPicList, iColRefIdx);
5650  cColMv = pColCU->getCUMvField(eColRefPicList)->getMv(uiAbsPartAddr);
5651
5652  iCurrRefPOC = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getPOC();
5653  Bool bIsCurrRefLongTerm = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getIsLongTerm();
5654  Bool bIsColRefLongTerm = pColCU->getSlice()->getIsUsedAsLongTerm(eColRefPicList, iColRefIdx);
5655
5656  if ( bIsCurrRefLongTerm != bIsColRefLongTerm ) 
5657  {
5658#if H_3D_TMVP
5659    Int iAlterRefIdx  = m_pcSlice->getAlterRefIdx(eRefPicList);
5660    if(bMRG && iAlterRefIdx > 0)
5661    {
5662      riRefIdx = iAlterRefIdx;
5663      bIsCurrRefLongTerm = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getIsLongTerm();
5664      iCurrRefPOC = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getPOC();
5665      assert(bIsCurrRefLongTerm == bIsColRefLongTerm);
5666    }
5667    else
5668    {
5669#endif
5670      return false;
5671#if H_3D_TMVP
5672    }
5673#endif
5674  }
5675
5676  if ( bIsCurrRefLongTerm || bIsColRefLongTerm )
5677  {
5678#if H_3D_TMVP
5679    Int iCurrViewId    = m_pcSlice->getViewIndex (); 
5680    Int iCurrRefViewId = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getViewIndex (); 
5681    Int iColViewId     = pColCU->getSlice()->getViewIndex(); 
5682    Int iColRefViewId  = pColCU->getSlice()->getRefPic( eColRefPicList, pColCU->getCUMvField(eColRefPicList)->getRefIdx(uiAbsPartAddr))->getViewIndex(); 
5683    iScale = xGetDistScaleFactor( iCurrViewId, iCurrRefViewId, iColViewId, iColRefViewId );
5684
5685    if ( iScale != 4096 && m_pcSlice->getIvMvScalingFlag( ) )
5686    {
5687      rcMv = cColMv.scaleMv( iScale );
5688    }
5689    else
5690    {
5691#endif
5692       rcMv = cColMv;
5693#if H_3D_TMVP
5694    }
5695#endif
5696  }
5697  else
5698  {
5699    iScale = xGetDistScaleFactor(iCurrPOC, iCurrRefPOC, iColPOC, iColRefPOC);
5700    if ( iScale == 4096 )
5701    {
5702      rcMv = cColMv;
5703    }
5704    else
5705    {
5706      rcMv = cColMv.scaleMv( iScale );
5707    }
5708  }
5709  return true;
5710}
5711
5712UInt TComDataCU::xGetMvdBits(TComMv cMvd)
5713{
5714  return ( xGetComponentBits(cMvd.getHor()) + xGetComponentBits(cMvd.getVer()) );
5715}
5716
5717UInt TComDataCU::xGetComponentBits(Int iVal)
5718{
5719  UInt uiLength = 1;
5720  UInt uiTemp   = ( iVal <= 0) ? (-iVal<<1)+1: (iVal<<1);
5721 
5722  assert ( uiTemp );
5723 
5724  while ( 1 != uiTemp )
5725  {
5726    uiTemp >>= 1;
5727    uiLength += 2;
5728  }
5729 
5730  return uiLength;
5731}
5732
5733
5734Int TComDataCU::xGetDistScaleFactor(Int iCurrPOC, Int iCurrRefPOC, Int iColPOC, Int iColRefPOC)
5735{
5736  Int iDiffPocD = iColPOC - iColRefPOC;
5737  Int iDiffPocB = iCurrPOC - iCurrRefPOC;
5738 
5739  if( iDiffPocD == iDiffPocB )
5740  {
5741    return 4096;
5742  }
5743  else
5744  {
5745    Int iTDB      = Clip3( -128, 127, iDiffPocB );
5746    Int iTDD      = Clip3( -128, 127, iDiffPocD );
5747    Int iX        = (0x4000 + abs(iTDD/2)) / iTDD;
5748    Int iScale    = Clip3( -4096, 4095, (iTDB * iX + 32) >> 6 );
5749    return iScale;
5750  }
5751}
5752
5753/**
5754 * \param eCUMode
5755 * \param uiPartIdx
5756 * \param ruiPartIdxCenter
5757 * \returns Void
5758 */
5759Void TComDataCU::xDeriveCenterIdx( UInt uiPartIdx, UInt& ruiPartIdxCenter )
5760{
5761  UInt uiPartAddr;
5762  Int  iPartWidth;
5763  Int  iPartHeight;
5764  getPartIndexAndSize( uiPartIdx, uiPartAddr, iPartWidth, iPartHeight);
5765 
5766  ruiPartIdxCenter = m_uiAbsIdxInLCU+uiPartAddr; // partition origin.
5767  ruiPartIdxCenter = g_auiRasterToZscan[ g_auiZscanToRaster[ ruiPartIdxCenter ]
5768                                        + ( iPartHeight/m_pcPic->getMinCUHeight()  )/2*m_pcPic->getNumPartInWidth()
5769                                        + ( iPartWidth/m_pcPic->getMinCUWidth()  )/2];
5770}
5771#if H_3D
5772Void TComDataCU::compressMV(Int scale)
5773#else
5774Void TComDataCU::compressMV()
5775#endif
5776{
5777#if H_3D
5778  Int scaleFactor = (4 / scale ) * AMVP_DECIMATION_FACTOR / m_unitSize;
5779#else
5780  Int scaleFactor = 4 * AMVP_DECIMATION_FACTOR / m_unitSize;
5781#endif
5782  if (scaleFactor > 0)
5783  {
5784    m_acCUMvField[0].compress(m_pePredMode, scaleFactor);
5785    m_acCUMvField[1].compress(m_pePredMode, scaleFactor);   
5786  }
5787}
5788
5789UInt TComDataCU::getCoefScanIdx(UInt uiAbsPartIdx, UInt uiWidth, Bool bIsLuma, Bool bIsIntra)
5790{
5791  UInt uiCTXIdx;
5792  UInt uiScanIdx;
5793  UInt uiDirMode;
5794
5795  if ( !bIsIntra ) 
5796  {
5797    uiScanIdx = SCAN_DIAG;
5798    return uiScanIdx;
5799  }
5800
5801  switch(uiWidth)
5802  {
5803    case  2: uiCTXIdx = 6; break;
5804    case  4: uiCTXIdx = 5; break;
5805    case  8: uiCTXIdx = 4; break;
5806    case 16: uiCTXIdx = 3; break;
5807    case 32: uiCTXIdx = 2; break;
5808    case 64: uiCTXIdx = 1; break;
5809    default: uiCTXIdx = 0; break;
5810  }
5811
5812  if ( bIsLuma )
5813  {
5814    uiDirMode = getLumaIntraDir(uiAbsPartIdx);
5815#if H_3D_DIM
5816    mapDepthModeToIntraDir( uiDirMode );
5817#endif
5818    uiScanIdx = SCAN_DIAG;
5819    if (uiCTXIdx >3 && uiCTXIdx < 6) //if multiple scans supported for transform size
5820    {
5821      uiScanIdx = abs((Int) uiDirMode - VER_IDX) < 5 ? SCAN_HOR : (abs((Int)uiDirMode - HOR_IDX) < 5 ? SCAN_VER : SCAN_DIAG);
5822    }
5823  }
5824  else
5825  {
5826    uiDirMode = getChromaIntraDir(uiAbsPartIdx);
5827    if( uiDirMode == DM_CHROMA_IDX )
5828    {
5829      // get number of partitions in current CU
5830      UInt depth = getDepth(uiAbsPartIdx);
5831      UInt numParts = getPic()->getNumPartInCU() >> (2 * depth);
5832     
5833      // get luma mode from upper-left corner of current CU
5834      uiDirMode = getLumaIntraDir((uiAbsPartIdx/numParts)*numParts);
5835#if H_3D_DIM
5836      mapDepthModeToIntraDir( uiDirMode );
5837#endif
5838    }
5839    uiScanIdx = SCAN_DIAG;
5840    if (uiCTXIdx >4 && uiCTXIdx < 7) //if multiple scans supported for transform size
5841    {
5842      uiScanIdx = abs((Int) uiDirMode - VER_IDX) < 5 ? SCAN_HOR : (abs((Int)uiDirMode - HOR_IDX) < 5 ? SCAN_VER : SCAN_DIAG);
5843    }
5844  }
5845
5846  return uiScanIdx;
5847}
5848
5849UInt TComDataCU::getSCUAddr()
5850{ 
5851  return getPic()->getPicSym()->getInverseCUOrderMap(m_uiCUAddr)*(1<<(m_pcSlice->getSPS()->getMaxCUDepth()<<1))+m_uiAbsIdxInLCU; 
5852}
5853
5854#if H_3D
5855Void TComDataCU::getPosInPic( UInt uiAbsPartIndex, Int& riPosX, Int& riPosY )
5856{
5857  riPosX = g_auiRasterToPelX[g_auiZscanToRaster[uiAbsPartIndex]] + getCUPelX();
5858  riPosY = g_auiRasterToPelY[g_auiZscanToRaster[uiAbsPartIndex]] + getCUPelY(); 
5859}
5860#endif
5861#if H_3D_IV_MERGE
5862Bool TComDataCU::getDispforDepth (UInt uiPartIdx, UInt uiPartAddr, DisInfo* pDisp)
5863{
5864
5865  assert(getPartitionSize( uiPartAddr ) == SIZE_2Nx2N);
5866
5867  TComMv cMv; 
5868  if ( getSlice()->getDefaultRefViewIdxAvailableFlag() )
5869  {
5870      Int iViewIdx = getSlice()->getDefaultRefViewIdx();
5871      pDisp->m_aVIdxCan = iViewIdx;
5872      Int iDisp     = getSlice()->getDepthToDisparityB( iViewIdx )[ (Int64) (1 << ( getSlice()->getSPS()->getBitDepthY() - 1 )) ];
5873
5874      cMv.setHor(iDisp);
5875      cMv.setVer(0);
5876      pDisp->m_acNBDV = cMv;
5877      pDisp->m_aVIdxCan = iViewIdx;
5878
5879      return true;
5880  }
5881  return false;
5882}
5883#endif
5884
5885#if H_3D_SINGLE_DEPTH
5886Bool TComDataCU::getNeighDepth (UInt uiPartIdx, UInt uiPartAddr, Pel* pNeighDepth, Int index)
5887{
5888
5889  Bool bDepAvail = false;
5890  Pel *pDepth  = this->getPic()->getPicYuvRec()->getLumaAddr();
5891  Int iDepStride =  this->getPic()->getPicYuvRec()->getStride();
5892
5893  Int xP, yP, nPSW, nPSH;
5894  this->getPartPosition(uiPartIdx, xP, yP, nPSW, nPSH);
5895  UInt PicHeight=this->getPic()->getPicYuvRec()->getHeight();
5896  UInt PicWidth=this->getPic()->getPicYuvRec()->getWidth();
5897  switch(index)
5898  {
5899  case 0: // Mid Left
5900    if( ( xP != 0 ) && ( ( yP + ( nPSH >> 1 ) ) < PicHeight ) )
5901    {
5902      *pNeighDepth = pDepth[ (yP+(nPSH>>1)) * iDepStride + (xP-1) ];
5903      bDepAvail = true;
5904    }
5905    break;
5906  case 1: // Mid Above
5907    if( ( yP != 0 ) && ( ( xP + ( nPSW >> 1 ) ) < PicWidth ) )
5908    {
5909      *pNeighDepth = pDepth[ (yP-1) * iDepStride + (xP + (nPSW>>1)) ];
5910      bDepAvail = true;
5911    }
5912    break;
5913  default:
5914      break;
5915  }
5916  return bDepAvail;
5917}
5918
5919#endif
5920#if H_3D_NBDV
5921//Notes from QC:
5922//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
5923//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
5924//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
5925Bool TComDataCU::getDisMvpCandNBDV( DisInfo* pDInfo
5926#if H_3D_NBDV_REF
5927, Bool bDepthRefine
5928#endif
5929)
5930{
5931  //// ******* Init variables ******* /////
5932  // Init disparity struct for results
5933  pDInfo->bDV = false;   
5934  pDInfo->m_aVIdxCan = -1;
5935
5936  // Init struct for disparities from MCP neighboring blocks
5937  IDVInfo cIDVInfo;
5938  cIDVInfo.m_bFound = false; 
5939  UInt uiPartIdx = 0;
5940  UInt uiPartAddr = 0;
5941  for (UInt iCurDvMcpCand = 0; iCurDvMcpCand < IDV_CANDS; iCurDvMcpCand++)
5942  {
5943    for (UInt iList = 0; iList < 2; iList++)
5944    {
5945      cIDVInfo.m_acMvCand[iList][iCurDvMcpCand].setZero();
5946      cIDVInfo.m_aVIdxCan[iList][iCurDvMcpCand] = 0; 
5947      cIDVInfo.m_bAvailab[iList][iCurDvMcpCand] = false; 
5948    }
5949  }
5950#if H_3D_NBDV_REF
5951  if( !m_pcSlice->getDepthRefinementFlag( ) )
5952  {
5953    bDepthRefine = false;
5954  }
5955#endif
5956  // Get Positions 
5957  PartSize eCUMode    = getPartitionSize( uiPartAddr );   
5958  assert(eCUMode == SIZE_2Nx2N);
5959  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB; 
5960
5961  deriveLeftRightTopIdxGeneral(uiPartAddr, uiPartIdx, uiPartIdxLT, uiPartIdxRT );
5962  deriveLeftBottomIdxGeneral  (uiPartAddr, uiPartIdx, uiPartIdxLB );
5963
5964  //// ******* Get disparity from temporal neighboring blocks ******* /////
5965  if ( getSlice()->getEnableTMVPFlag() )
5966  {
5967    TComMv cColMv;
5968    Int iTargetViewIdx = 0;
5969    Int iTStartViewIdx = 0;   
5970
5971    ///*** Derive center position ***
5972    UInt uiPartIdxCenter;
5973    Int  uiLCUIdx   = getAddr();
5974    xDeriveCenterIdx(uiPartIdx, uiPartIdxCenter );
5975
5976    ///*** Search temporal candidate pictures for disparity vector ***
5977    const Int iNumCandPics = getPic()->getNumDdvCandPics();
5978    for(Int curCandPic = 0; curCandPic < iNumCandPics; curCandPic++)
5979    {
5980      RefPicList eCurRefPicList   = REF_PIC_LIST_0 ;
5981      Int        curCandPicRefIdx = 0;
5982      if( curCandPic == 0 ) 
5983      { 
5984        eCurRefPicList   = RefPicList(getSlice()->isInterB() ? 1-getSlice()->getColFromL0Flag() : 0);
5985        curCandPicRefIdx = getSlice()->getColRefIdx();
5986      }
5987      else                 
5988      {
5989        eCurRefPicList   = getPic()->getRapRefList();
5990        curCandPicRefIdx = getPic()->getRapRefIdx();
5991      }
5992
5993      Bool bCheck = xGetColDisMV( curCandPic, eCurRefPicList, curCandPicRefIdx, uiLCUIdx,   uiPartIdxCenter,  cColMv, iTargetViewIdx, iTStartViewIdx );
5994
5995      if( bCheck )
5996      {
5997#if !(NTT_BUG_FIX_TK54)
5998        clipMv(cColMv);
5999#endif
6000        pDInfo->m_acNBDV = cColMv;
6001        pDInfo->m_aVIdxCan  = iTargetViewIdx;
6002
6003#if H_3D_NBDV_REF
6004        TComPic* picDepth = NULL;   
6005#if H_3D_FCO_VSP_DONBDV_E0163
6006        picDepth  = getSlice()->getIvPic(true, getSlice()->getViewIndex() );
6007        if ( picDepth->getPicYuvRec() != NULL  ) 
6008        {
6009          cColMv.setZero();
6010        }
6011        else // Go back with virtual depth
6012        {
6013          picDepth = getSlice()->getIvPic( true, iTargetViewIdx );
6014        }
6015
6016        assert(picDepth != NULL);
6017#else
6018        picDepth = getSlice()->getIvPic( true, iTargetViewIdx );
6019#if !BUG_FIX_TK65
6020        assert(picDepth != NULL);
6021#endif
6022#endif
6023        if (picDepth && bDepthRefine)
6024          estimateDVFromDM(iTargetViewIdx, uiPartIdx, picDepth, uiPartAddr, &cColMv );
6025
6026        pDInfo->m_acDoNBDV  = cColMv;
6027#endif //H_3D_NBDV_REF
6028        return true;
6029      }
6030    }
6031  } 
6032
6033  UInt uiIdx = 0;
6034  Bool        bCheckMcpDv = false;   
6035  TComDataCU* pcTmpCU     = NULL;
6036
6037  //// ******* Get disparity from left block ******* /////
6038  pcTmpCU = getPULeft(uiIdx, uiPartIdxLB, true, false);
6039  bCheckMcpDv = true; 
6040  if ( xCheckSpatialNBDV( pcTmpCU, uiIdx, pDInfo, bCheckMcpDv, &cIDVInfo, DVFROM_LEFT
6041#if H_3D_NBDV_REF
6042    , bDepthRefine
6043#endif
6044    ) )
6045    return true;
6046
6047  //// ******* Get disparity from above block ******* /////
6048  pcTmpCU = getPUAbove(uiIdx, uiPartIdxRT, true, false, true);
6049  if(pcTmpCU != NULL )
6050  {
6051    bCheckMcpDv = ( ( getAddr() - pcTmpCU->getAddr() ) == 0);
6052    if ( xCheckSpatialNBDV( pcTmpCU, uiIdx, pDInfo, bCheckMcpDv, &cIDVInfo, DVFROM_ABOVE
6053#if H_3D_NBDV_REF
6054      , bDepthRefine
6055#endif
6056      ) )
6057      return true;
6058  }
6059
6060  //// ******* Search MCP blocks ******* /////
6061  if( cIDVInfo.m_bFound ) 
6062  {
6063    for( Int curPos = 0 ; curPos < IDV_CANDS ; curPos++ ) 
6064    {
6065      for(Int iList = 0; iList < (getSlice()->isInterB() ? 2: 1); iList ++)
6066      {
6067        if( cIDVInfo.m_bAvailab[iList][curPos] )
6068        {
6069          TComMv cDispVec = cIDVInfo.m_acMvCand[iList][ curPos ];
6070#if !(NTT_BUG_FIX_TK54)
6071          clipMv( cDispVec );
6072#endif
6073          pDInfo->m_acNBDV = cDispVec;
6074          pDInfo->m_aVIdxCan = cIDVInfo.m_aVIdxCan[iList][ curPos ];
6075#if H_3D_NBDV_REF
6076#if H_3D_FCO_VSP_DONBDV_E0163
6077          TComPic* picDepth  = NULL;
6078
6079          picDepth  = getSlice()->getIvPic(true, getSlice()->getViewIndex() );
6080          if ( picDepth->getPicYuvRec() != NULL ) 
6081          {
6082            cDispVec.setZero();
6083          }
6084          else // Go back with virtual depth
6085          {
6086            picDepth = getSlice()->getIvPic( true, pDInfo->m_aVIdxCan );
6087          }
6088
6089          assert(picDepth != NULL);
6090#else
6091          TComPic* picDepth = getSlice()->getIvPic( true, pDInfo->m_aVIdxCan );
6092#if !BUG_FIX_TK65
6093          assert(picDepth!=NULL);
6094#endif
6095#endif
6096
6097          if (picDepth && bDepthRefine)
6098          {
6099            estimateDVFromDM (pDInfo->m_aVIdxCan, uiPartIdx, picDepth, uiPartAddr, &cDispVec);
6100          }
6101          pDInfo->m_acDoNBDV = cDispVec;
6102#endif
6103          return true;
6104        }
6105      }
6106    }
6107  }
6108
6109  TComMv defaultDV(0, 0);
6110  pDInfo->m_acNBDV = defaultDV;
6111
6112  if (getSlice()->getDefaultRefViewIdxAvailableFlag())
6113  {
6114      pDInfo->m_aVIdxCan = getSlice()->getDefaultRefViewIdx();
6115
6116#if H_3D_NBDV_REF
6117          TComPic* picDepth = NULL;
6118#if H_3D_FCO_VSP_DONBDV_E0163
6119          picDepth  = getSlice()->getIvPic(true, getSlice()->getViewIndex() );
6120      if ( picDepth->getPicYuvRec() != NULL ) 
6121      {
6122          defaultDV.setZero();
6123      }
6124      else // Go back with virtual depth
6125      {
6126          picDepth = getSlice()->getIvPic( true, getSlice()->getDefaultRefViewIdx());
6127      }
6128
6129      assert(picDepth != NULL);
6130#else
6131          picDepth = getSlice()->getIvPic( true, getSlice()->getDefaultRefViewIdx());
6132#endif
6133      if (picDepth && bDepthRefine)
6134      {
6135          estimateDVFromDM(getSlice()->getDefaultRefViewIdx(), uiPartIdx, picDepth, uiPartAddr, &defaultDV ); // from base view
6136      }
6137      pDInfo->m_acDoNBDV = defaultDV;
6138#endif
6139      return true;
6140  }
6141  return false; 
6142}
6143
6144#if H_3D_NBDV_REF
6145Pel TComDataCU::getMcpFromDM(TComPicYuv* pcBaseViewDepthPicYuv, TComMv* mv, Int iBlkX, Int iBlkY, Int iBlkWidth, Int iBlkHeight, Int* aiShiftLUT )
6146{
6147  Int iPictureWidth  = pcBaseViewDepthPicYuv->getWidth();
6148  Int iPictureHeight = pcBaseViewDepthPicYuv->getHeight();
6149 
6150  Int depthStartPosX = Clip3(0,   iPictureWidth - 1,  iBlkX + ((mv->getHor()+2)>>2));
6151  Int depthStartPosY = Clip3(0,   iPictureHeight - 1, iBlkY + ((mv->getVer()+2)>>2));
6152  Int depthEndPosX   = Clip3(0,   iPictureWidth - 1,  iBlkX + iBlkWidth - 1 + ((mv->getHor()+2)>>2));
6153  Int depthEndPosY   = Clip3(0,   iPictureHeight - 1, iBlkY + iBlkHeight - 1 + ((mv->getVer()+2)>>2));
6154
6155  Pel* depthTL  = pcBaseViewDepthPicYuv->getLumaAddr();
6156  Int depStride =  pcBaseViewDepthPicYuv->getStride();
6157
6158  Pel  maxDepthVal = 0;
6159  maxDepthVal = std::max( maxDepthVal, depthTL[ (depthStartPosY) * depStride + depthStartPosX ]);      // Left Top
6160  maxDepthVal = std::max( maxDepthVal, depthTL[ (depthEndPosY)   * depStride + depthStartPosX ]);      // Left Bottom
6161  maxDepthVal = std::max( maxDepthVal, depthTL[ (depthStartPosY) * depStride + depthEndPosX   ]);      // Right Top
6162  maxDepthVal = std::max( maxDepthVal, depthTL[ (depthEndPosY)   * depStride + depthEndPosX   ]);      // Right Bottom
6163
6164  return aiShiftLUT[ maxDepthVal ];
6165}
6166
6167Void TComDataCU::estimateDVFromDM(Int refViewIdx, UInt uiPartIdx, TComPic* picDepth, UInt uiPartAddr, TComMv* cMvPred )
6168{
6169  if (picDepth)
6170  {
6171    UInt uiAbsPartAddrCurrCU = m_uiAbsIdxInLCU + uiPartAddr;
6172    Int iWidth, iHeight;
6173    getPartIndexAndSize( uiPartIdx, uiPartAddr, iWidth, iHeight ); // The modified value of uiPartAddr won't be used any more
6174
6175    TComPicYuv* pcBaseViewDepthPicYuv = picDepth->getPicYuvRec();
6176    Int iBlkX = ( getAddr() % picDepth->getFrameWidthInCU() ) * g_uiMaxCUWidth  + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartAddrCurrCU ] ];
6177    Int iBlkY = ( getAddr() / picDepth->getFrameWidthInCU() ) * g_uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartAddrCurrCU ] ];
6178
6179    Int* aiShiftLUT = getSlice()->getDepthToDisparityB(refViewIdx );
6180
6181    Pel iDisp = getMcpFromDM( pcBaseViewDepthPicYuv, cMvPred, iBlkX, iBlkY, iWidth, iHeight, aiShiftLUT );
6182    cMvPred->setHor( iDisp );
6183#if !(NTT_BUG_FIX_TK54)
6184    clipMv(*cMvPred);
6185#endif
6186  }
6187}
6188#endif //H_3D_NBDV_REF
6189
6190
6191Bool TComDataCU::xCheckSpatialNBDV( TComDataCU* pcTmpCU, UInt uiIdx, DisInfo* pNbDvInfo, Bool bSearchForMvpDv, IDVInfo* paIDVInfo, UInt uiMvpDvPos
6192#if H_3D_NBDV_REF
6193, Bool bDepthRefine
6194#endif
6195)
6196{
6197  if( pcTmpCU != NULL && !pcTmpCU->isIntra( uiIdx ) )
6198  {
6199    Bool bTmpIsSkipped = pcTmpCU->isSkipped( uiIdx );
6200    for(Int iList = 0; iList < (getSlice()->isInterB() ? 2: 1); iList ++)
6201    {
6202      RefPicList eRefPicList = RefPicList(iList);
6203      Int      refId = pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) ;
6204      TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
6205
6206      if( refId >= 0)
6207      {
6208        Int refViewIdx  = pcTmpCU->getSlice()->getRefPic(eRefPicList, refId)->getViewIndex();
6209        if (refViewIdx != m_pcSlice->getViewIndex()) 
6210        {
6211#if !(NTT_BUG_FIX_TK54)
6212          clipMv(cMvPred);
6213#endif
6214          pNbDvInfo->m_acNBDV = cMvPred;
6215          pNbDvInfo->m_aVIdxCan = refViewIdx;
6216#if H_3D_NBDV_REF
6217          TComPic* picDepth = NULL;
6218          assert(getSlice()->getRefPic(eRefPicList, refId)->getPOC() == getSlice()->getPOC());         
6219#if H_3D_FCO_VSP_DONBDV_E0163
6220          picDepth  = getSlice()->getIvPic(true, getSlice()->getViewIndex() );
6221          if ( picDepth->getPicYuvRec() != NULL ) 
6222          {
6223            cMvPred.setZero();
6224          }
6225          else// Go back with virtual depth
6226          {
6227            picDepth = getSlice()->getIvPic (true, refViewIdx );
6228          }
6229          assert(picDepth != NULL);
6230#else
6231          picDepth   = getSlice()->getIvPic (true, refViewIdx );
6232#if !BUG_FIX_TK65
6233          assert(picDepth != NULL);
6234#endif
6235#endif
6236          UInt uiPartIdx = 0;   //Notes from MTK: Please confirm that using 0 as partition index and partition address is correct for CU-level DoNBDV
6237          UInt uiPartAddr = 0;  //QC: confirmed
6238
6239          if (picDepth && bDepthRefine)
6240            estimateDVFromDM(refViewIdx, uiPartIdx, picDepth, uiPartAddr, &cMvPred );
6241
6242          pNbDvInfo->m_acDoNBDV = cMvPred;
6243#endif
6244          return true;
6245        }
6246        else if ( bSearchForMvpDv && cMvPred.getIDVFlag() && bTmpIsSkipped )
6247        {
6248          assert( uiMvpDvPos < IDV_CANDS );
6249          paIDVInfo->m_acMvCand[iList][ uiMvpDvPos ] = TComMv( cMvPred.getIDVHor(), cMvPred.getIDVVer() );
6250          //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.
6251          paIDVInfo->m_aVIdxCan[iList][ uiMvpDvPos ] = cMvPred.getIDVVId();
6252          paIDVInfo->m_bAvailab[iList][ uiMvpDvPos ] = true;
6253          paIDVInfo->m_bFound                        = true; 
6254        }
6255      }
6256    }
6257  }
6258  return false; 
6259}
6260 
6261Void TComDataCU::xDeriveRightBottomNbIdx(Int &riLCUIdxRBNb, Int &riPartIdxRBNb )
6262{
6263  UInt uiPartIdx = 0;
6264  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth(); 
6265  Int uiLCUIdx = getAddr();
6266
6267  UInt uiPartIdxRB;
6268  deriveRightBottomIdx(uiPartIdx, uiPartIdxRB ); 
6269  UInt uiAbsPartIdxTmp = g_auiZscanToRaster[uiPartIdxRB];
6270
6271  if (( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth() )>= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )
6272  {
6273    riLCUIdxRBNb  = -1;
6274    riPartIdxRBNb = -1;
6275  }
6276  else if(( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxTmp] + m_pcPic->getMinCUHeight() )>= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
6277  {
6278    riLCUIdxRBNb  = -1;
6279    riPartIdxRBNb = -1;
6280  }
6281  else
6282  {
6283    if ( ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
6284      ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
6285    {
6286      riPartIdxRBNb = g_auiRasterToZscan[ uiAbsPartIdxTmp + uiNumPartInCUWidth + 1 ];
6287      riLCUIdxRBNb  = uiLCUIdx; 
6288    }
6289    else if ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
6290    {
6291      riPartIdxRBNb = -1;
6292      riLCUIdxRBNb  = -1;
6293    }
6294    else if ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
6295    {
6296      riPartIdxRBNb = g_auiRasterToZscan[ uiAbsPartIdxTmp + 1 ];
6297      riLCUIdxRBNb = uiLCUIdx + 1;
6298    }
6299    else //is the right bottom corner of LCU                       
6300    {
6301      riPartIdxRBNb = -1;
6302      riLCUIdxRBNb  = -1;
6303    }
6304  }
6305}
6306
6307
6308Void TComDataCU::setDvInfoSubParts( DisInfo cDvInfo, UInt uiAbsPartIdx, UInt uiDepth )
6309{
6310  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
6311  for (UInt ui = 0; ui < uiCurrPartNumb; ui++ )
6312  {
6313    m_pDvInfo[uiAbsPartIdx + ui] = cDvInfo;
6314  }
6315}
6316#if H_3D_VSP
6317Void TComDataCU::setDvInfoSubParts( DisInfo cDvInfo, UInt uiAbsPartIdx, UInt uiPUIdx, UInt uiDepth )
6318{
6319  setSubPartT<DisInfo>( cDvInfo, m_pDvInfo, uiAbsPartIdx, uiDepth, uiPUIdx );
6320}
6321#endif
6322
6323Bool TComDataCU::xGetColDisMV( Int currCandPic, RefPicList eRefPicList, Int refidx, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv , Int & iTargetViewIdx, Int & iStartViewIdx )
6324{
6325
6326  RefPicList  eColRefPicList = REF_PIC_LIST_0;
6327  Int iColViewIdx, iColRefViewIdx;
6328  TComPic *pColPic = getSlice()->getRefPic( eRefPicList, refidx);
6329  TComDataCU *pColCU = pColPic->getCU( uiCUAddr );
6330  iColViewIdx = pColCU->getSlice()->getViewIndex();
6331  if (pColCU->getPic()==0||pColCU->getPartitionSize(uiPartUnitIdx)==SIZE_NONE||pColCU->isIntra(uiPartUnitIdx))
6332  {
6333    return false;
6334  }
6335  for (Int ilist = 0; ilist < (pColCU->getSlice()->isInterB()? 2:1); ilist++) 
6336  {
6337    if(pColCU->getSlice()->isInterB())
6338    {
6339      eColRefPicList = RefPicList(ilist);
6340    }
6341
6342    Int iColRefIdx = pColCU->getCUMvField(eColRefPicList)->getRefIdx(uiPartUnitIdx);
6343
6344    if (iColRefIdx < 0)
6345    {
6346      continue;
6347    }
6348
6349    iColRefViewIdx = pColCU->getSlice()->getRefPic(eColRefPicList, iColRefIdx)->getViewIndex();
6350
6351    if ( iColViewIdx    == iColRefViewIdx ) // temporal vector
6352    {
6353      continue;
6354    }
6355    else 
6356    {
6357      if(getPic()->isTempIVRefValid(currCandPic, ilist,  iColRefIdx))
6358      {
6359        rcMv = pColCU->getCUMvField(eColRefPicList)->getMv(uiPartUnitIdx);
6360        rcMv.setIDVFlag(0);
6361        iTargetViewIdx  = iColRefViewIdx ;
6362        iStartViewIdx   = iColViewIdx   ;
6363        return true;   
6364      }
6365    }
6366  }
6367
6368  return false;
6369}
6370#endif
6371#if  H_3D_FAST_TEXTURE_ENCODING
6372Void
6373TComDataCU::getIVNStatus       ( UInt uiPartIdx,  DisInfo* pDInfo, Bool& bIVFMerge, Int& iIVFMaxD)
6374{
6375  TComSlice*    pcSlice         = getSlice (); 
6376  Int iViewIndex = pDInfo->m_aVIdxCan;
6377  //--- get base CU/PU and check prediction mode ---
6378  TComPic*    pcBasePic   = pcSlice->getIvPic( false, iViewIndex );
6379  TComPicYuv* pcBaseRec   = pcBasePic->getPicYuvRec   ();
6380
6381  UInt          uiPartAddr;
6382  Int           iWidth;
6383  Int           iHeight;
6384  getPartIndexAndSize( uiPartIdx, uiPartAddr, iWidth, iHeight );
6385
6386  Int  iCurrPosX, iCurrPosY;
6387  pcBaseRec->getTopLeftSamplePos( getAddr(), getZorderIdxInCU() + uiPartAddr, iCurrPosX, iCurrPosY );
6388
6389  iCurrPosX  += ( ( iWidth  - 1 ) >> 1 );
6390  iCurrPosY  += ( ( iHeight - 1 ) >> 1 );
6391
6392  Bool depthRefineFlag = false; 
6393#if H_3D_NBDV_REF
6394  depthRefineFlag = m_pcSlice->getDepthRefinementFlag( ); 
6395#endif // H_3D_NBDV_REF
6396
6397  TComMv      cDv = depthRefineFlag ? pDInfo->m_acDoNBDV : pDInfo->m_acNBDV; 
6398  if( depthRefineFlag )
6399  {
6400    cDv.setVer(0);
6401  }
6402
6403  Int         iBasePosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (cDv.getHor() + 2 ) >> 2 ) );
6404  Int         iBasePosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (cDv.getVer() + 2 ) >> 2 )); 
6405  Int         iBaseLPosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX - (iWidth >> 1) + ( (cDv.getHor() + 2 ) >> 2 ) );
6406  Int         iBaseLPosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (cDv.getVer() + 2 ) >> 2 )); 
6407  Int         iBaseRPosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + (iWidth >> 1) + 1 + ( (cDv.getHor() + 2 ) >> 2 ) );
6408  Int         iBaseRPosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (cDv.getVer() + 2 ) >> 2 )); 
6409  Int         iBaseUPosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (cDv.getHor() + 2 ) >> 2 ) );
6410  Int         iBaseUPosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY - (iHeight >> 1) + ( (cDv.getVer() + 2 ) >> 2 )); 
6411  Int         iBaseDPosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (cDv.getHor() + 2 ) >> 2 ) );
6412  Int         iBaseDPosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + (iHeight >> 1) + 1 + ( (cDv.getVer() + 2 ) >> 2 )); 
6413
6414  Int         iBaseCUAddr;
6415  Int         iBaseAbsPartIdx;
6416  Int         iBaseLCUAddr;
6417  Int         iBaseLAbsPartIdx;
6418  Int         iBaseRCUAddr;
6419  Int         iBaseRAbsPartIdx;
6420  Int         iBaseUCUAddr;
6421  Int         iBaseUAbsPartIdx;
6422  Int         iBaseDCUAddr;
6423  Int         iBaseDAbsPartIdx;
6424  pcBaseRec->getCUAddrAndPartIdx( iBasePosX , iBasePosY , iBaseCUAddr, iBaseAbsPartIdx );
6425  pcBaseRec->getCUAddrAndPartIdx( iBaseLPosX , iBaseLPosY , iBaseLCUAddr, iBaseLAbsPartIdx );
6426  pcBaseRec->getCUAddrAndPartIdx( iBaseRPosX , iBaseRPosY , iBaseRCUAddr, iBaseRAbsPartIdx );
6427  pcBaseRec->getCUAddrAndPartIdx( iBaseUPosX , iBaseUPosY , iBaseUCUAddr, iBaseUAbsPartIdx );
6428  pcBaseRec->getCUAddrAndPartIdx( iBaseDPosX , iBaseDPosY , iBaseDCUAddr, iBaseDAbsPartIdx );
6429  TComDataCU* pcBaseCU    = pcBasePic->getCU( iBaseCUAddr );
6430  TComDataCU* pcBaseLCU    = pcBasePic->getCU( iBaseLCUAddr );
6431  TComDataCU* pcBaseRCU    = pcBasePic->getCU( iBaseRCUAddr );
6432  TComDataCU* pcBaseUCU    = pcBasePic->getCU( iBaseUCUAddr );
6433  TComDataCU* pcBaseDCU    = pcBasePic->getCU( iBaseDCUAddr );
6434  bIVFMerge = pcBaseLCU->getMergeFlag( iBaseLAbsPartIdx ) && pcBaseCU->getMergeFlag( iBaseAbsPartIdx ) && pcBaseRCU->getMergeFlag( iBaseRAbsPartIdx ) && pcBaseUCU->getMergeFlag( iBaseUAbsPartIdx ) && pcBaseDCU->getMergeFlag( iBaseDAbsPartIdx );
6435  Int aiDepthL[5]; //depth level
6436  aiDepthL[0] = pcBaseCU->getDepth(iBaseAbsPartIdx);
6437  aiDepthL[1] = pcBaseLCU->getDepth(iBaseLAbsPartIdx);
6438  aiDepthL[2] = pcBaseRCU->getDepth(iBaseRAbsPartIdx);
6439  aiDepthL[3] = pcBaseUCU->getDepth(iBaseUAbsPartIdx);
6440  aiDepthL[4] = pcBaseDCU->getDepth(iBaseDAbsPartIdx);
6441  for (Int i = 0; i < 5; i++)
6442  {
6443    if (iIVFMaxD < aiDepthL[i])
6444      iIVFMaxD = aiDepthL[i];
6445  }
6446}
6447#endif
6448
6449#if H_3D_SPIVMP
6450Void TComDataCU::getSPPara(Int iPUWidth, Int iPUHeight, Int& iNumSP, Int& iNumSPInOneLine, Int& iSPWidth, Int& iSPHeight)
6451{
6452  Int iSubPUSize = ( getSlice()->getIsDepth() ? getSlice()->getMpiSubPbSize() : getSlice()->getSubPbSize() );
6453
6454  iNumSPInOneLine = iPUWidth/iSubPUSize;
6455  Int iNumSPInOneColumn = iPUHeight/iSubPUSize;
6456  iNumSPInOneLine = (iPUHeight % iSubPUSize != 0 || iPUWidth % iSubPUSize != 0 ) ? 1 : iNumSPInOneLine;
6457  iNumSPInOneColumn = (iPUHeight % iSubPUSize != 0  || iPUWidth % iSubPUSize != 0 ) ? 1 : iNumSPInOneColumn;
6458  iNumSP = iNumSPInOneLine * iNumSPInOneColumn;
6459
6460  iSPWidth = iNumSPInOneLine == 1 ? iPUWidth: iSubPUSize; 
6461  iSPHeight = iNumSPInOneColumn == 1 ? iPUHeight: iSubPUSize; 
6462}
6463
6464Void TComDataCU::getSPAbsPartIdx(UInt uiBaseAbsPartIdx, Int iWidth, Int iHeight, Int iPartIdx, Int iNumPartLine, UInt& ruiPartAddr )
6465{
6466  uiBaseAbsPartIdx += m_uiAbsIdxInLCU;
6467  Int iBasePelX = g_auiRasterToPelX[g_auiZscanToRaster[uiBaseAbsPartIdx]];
6468  Int iBasePelY = g_auiRasterToPelY[g_auiZscanToRaster[uiBaseAbsPartIdx]];
6469  Int iCurrPelX = iBasePelX + iPartIdx%iNumPartLine * iWidth;
6470  Int iCurrPelY = iBasePelY + iPartIdx/iNumPartLine * iHeight;
6471  Int iCurrRaster = iCurrPelY / getPic()->getMinCUHeight() * getPic()->getNumPartInWidth() + iCurrPelX/getPic()->getMinCUWidth();
6472  ruiPartAddr = g_auiRasterToZscan[iCurrRaster];
6473  ruiPartAddr -= m_uiAbsIdxInLCU; 
6474}
6475
6476Void TComDataCU::setInterDirSP( UInt uiDir, UInt uiAbsPartIdx, Int iWidth, Int iHeight )
6477{
6478  uiAbsPartIdx += getZorderIdxInCU();
6479  Int iStartPelX = g_auiRasterToPelX[g_auiZscanToRaster[uiAbsPartIdx]];
6480  Int iStartPelY = g_auiRasterToPelY[g_auiZscanToRaster[uiAbsPartIdx]];
6481  Int iEndPelX = iStartPelX + iWidth;
6482  Int iEndPelY = iStartPelY + iHeight;
6483
6484  Int iCurrRaster, uiPartAddr;
6485
6486  for (Int i=iStartPelY; i<iEndPelY; i+=getPic()->getMinCUHeight())
6487  {
6488    for (Int j=iStartPelX; j < iEndPelX; j += getPic()->getMinCUWidth())
6489    {
6490      iCurrRaster = i / getPic()->getMinCUHeight() * getPic()->getNumPartInWidth() + j/getPic()->getMinCUWidth();
6491      uiPartAddr = g_auiRasterToZscan[iCurrRaster];
6492      uiPartAddr -= getZorderIdxInCU(); 
6493
6494      m_puhInterDir[uiPartAddr] = uiDir;
6495    }
6496  }
6497}
6498#endif
6499
6500#if H_3D_IV_MERGE
6501Bool
6502TComDataCU::getInterViewMergeCands(UInt uiPartIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv, DisInfo* pDInfo, Int* availableMcDc , Bool bIsDepth           
6503#if H_3D_SPIVMP
6504, TComMvField* pcMvFieldSP, UChar* puhInterDirSP
6505#endif
6506, Bool bICFlag
6507)
6508{
6509  TComSlice*    pcSlice = getSlice (); 
6510  Int iViewIndex        = pDInfo->m_aVIdxCan;
6511
6512  //--- get base CU/PU and check prediction mode ---
6513  TComPic*    pcBasePic   = pcSlice->getIvPic( bIsDepth, iViewIndex );
6514  TComPicYuv* pcBaseRec   = pcBasePic->getPicYuvRec   ();
6515
6516  UInt          uiPartAddr;
6517  Int           iWidth;
6518  Int           iHeight;
6519  getPartIndexAndSize( uiPartIdx, uiPartAddr, iWidth, iHeight );
6520
6521  Int  iCurrPosX, iCurrPosY;
6522  pcBaseRec->getTopLeftSamplePos( getAddr(), getZorderIdxInCU() + uiPartAddr, iCurrPosX, iCurrPosY );
6523
6524#if !H_3D_SPIVMP
6525  iCurrPosX  += ( iWidth  >> 1 );
6526  iCurrPosY  += ( iHeight >> 1 );
6527#endif
6528
6529  Bool depthRefineFlag = false; 
6530#if H_3D_NBDV_REF
6531  depthRefineFlag = m_pcSlice->getDepthRefinementFlag( ); 
6532#endif // H_3D_NBDV_REF
6533
6534  TComMv      cDv = depthRefineFlag ? pDInfo->m_acDoNBDV : pDInfo->m_acNBDV; 
6535  if( depthRefineFlag )
6536  {
6537    cDv.setVer(0);
6538  }
6539
6540  Bool abPdmAvailable[8] =  {false, false, false, false, false, false, false, false};
6541#if H_3D_NBDV
6542  for( Int i = 0; i < 8; i++)
6543  {
6544    pacPdmMv[i].setIDVFlag   (false);
6545  }
6546#endif
6547
6548  if(!bICFlag)
6549  {
6550
6551#if H_3D_SPIVMP
6552    ////////////////////////////////
6553    //////////sub-PU IvMC///////////
6554    ////////////////////////////////
6555    if(!m_pcSlice->getIsDepth())
6556    {
6557      if (!getDBBPFlag(0))
6558      {
6559        Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight;
6560        getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight);
6561
6562        for (Int i=0; i<iNumSP; i++)
6563        {
6564          puhInterDirSP[i] = 0;
6565          pcMvFieldSP[2*i].getMv().set(0, 0);
6566          pcMvFieldSP[2*i+1].getMv().set(0,0);
6567          pcMvFieldSP[2*i].setRefIdx(-1);
6568          pcMvFieldSP[2*i+1].setRefIdx(-1);
6569        }
6570
6571        Int         iBaseCUAddr;
6572        Int         iBaseAbsPartIdx;
6573        TComDataCU* pcBaseCU;
6574        Int iPartition = 0;
6575
6576        Int iDelX = iSPWidth/2;
6577        Int iDelY = iSPHeight/2;
6578
6579        Int         iCenterPosX = iCurrPosX + ( ( iWidth /  iSPWidth ) >> 1 )  * iSPWidth + ( iSPWidth >> 1 );
6580        Int         iCenterPosY = iCurrPosY + ( ( iHeight /  iSPHeight ) >> 1 )  * iSPHeight + (iSPHeight >> 1);
6581        Int         iRefCenterCUAddr, iRefCenterAbsPartIdx;
6582
6583        if(iWidth == iSPWidth && iHeight == iSPHeight)
6584        {
6585          iCenterPosX = iCurrPosX + (iWidth >> 1);
6586          iCenterPosY = iCurrPosY + (iHeight >> 1);
6587        }
6588
6589        Int iRefCenterPosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCenterPosX + ( (cDv.getHor() + 2 ) >> 2 ) );
6590        Int iRefCenterPosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCenterPosY + ( (cDv.getVer() + 2 ) >> 2 ) ); 
6591
6592        pcBaseRec->getCUAddrAndPartIdx( iRefCenterPosX , iRefCenterPosY , iRefCenterCUAddr, iRefCenterAbsPartIdx );
6593        TComDataCU* pcDefaultCU    = pcBasePic->getCU( iRefCenterCUAddr );
6594        if(!( pcDefaultCU->getPredictionMode( iRefCenterAbsPartIdx ) == MODE_INTRA ))
6595        {
6596          for( UInt uiCurrRefListId = 0; uiCurrRefListId < 2; uiCurrRefListId++ )       
6597          {
6598            RefPicList  eCurrRefPicList = RefPicList( uiCurrRefListId );
6599            Bool stopLoop = false;
6600            for(Int iLoop = 0; iLoop < 2 && !stopLoop; ++iLoop)
6601            {
6602              RefPicList eDefaultRefPicList = (iLoop ==1)? RefPicList( 1 -  uiCurrRefListId ) : RefPicList( uiCurrRefListId );
6603              TComMvField cDefaultMvField;
6604              pcDefaultCU->getMvField( pcDefaultCU, iRefCenterAbsPartIdx, eDefaultRefPicList, cDefaultMvField );
6605              Int         iDefaultRefIdx     = cDefaultMvField.getRefIdx();
6606              if (iDefaultRefIdx >= 0)
6607              {
6608                Int iDefaultRefPOC = pcDefaultCU->getSlice()->getRefPOC(eDefaultRefPicList, iDefaultRefIdx);
6609                if (iDefaultRefPOC != pcSlice->getPOC())   
6610                {
6611                  for (Int iPdmRefIdx = 0; iPdmRefIdx < pcSlice->getNumRefIdx( eCurrRefPicList ); iPdmRefIdx++)
6612                  {
6613                    if (iDefaultRefPOC == pcSlice->getRefPOC(eCurrRefPicList, iPdmRefIdx))
6614                    {
6615                      abPdmAvailable[ uiCurrRefListId ] = true;
6616                      TComMv cMv(cDefaultMvField.getHor(), cDefaultMvField.getVer());
6617#if H_3D_NBDV
6618#if H_3D_IV_MERGE
6619                      if( !bIsDepth )
6620                      {
6621#endif
6622                        cMv.setIDVFlag   (true);
6623                        cMv.setIDVHor    (cDv.getHor());                 
6624                        cMv.setIDVVer    (cDv.getVer()); 
6625                        cMv.setIDVVId    (iViewIndex); 
6626#if H_3D_IV_MERGE
6627                      }
6628#endif
6629#endif
6630#if !(NTT_BUG_FIX_TK54)
6631                      clipMv( cMv );
6632#endif
6633                      paiPdmRefIdx  [ uiCurrRefListId ] = iPdmRefIdx;
6634                      pacPdmMv      [ uiCurrRefListId ] = cMv;
6635                      stopLoop = true;
6636                      break;
6637                    }
6638                  }
6639                }
6640              }
6641            }
6642          }
6643        }
6644        availableMcDc[0] = ( abPdmAvailable[0]? 1 : 0) + (abPdmAvailable[1]? 2 : 0);
6645
6646        if(availableMcDc[0])
6647        {
6648
6649          Int         iBasePosX, iBasePosY;
6650          for (Int i=iCurrPosY; i < iCurrPosY + iHeight; i += iSPHeight)
6651          {
6652            for (Int j = iCurrPosX; j < iCurrPosX + iWidth; j += iSPWidth)
6653            {
6654              iBasePosX   = Clip3( 0, pcBaseRec->getWidth () - 1, j + iDelX + ( (cDv.getHor() + 2 ) >> 2 ));
6655              iBasePosY   = Clip3( 0, pcBaseRec->getHeight() - 1, i + iDelY + ( (cDv.getVer() + 2 ) >> 2 )); 
6656
6657              pcBaseRec->getCUAddrAndPartIdx( iBasePosX , iBasePosY, iBaseCUAddr, iBaseAbsPartIdx );
6658              pcBaseCU    = pcBasePic->getCU( iBaseCUAddr );
6659              if(!( pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) == MODE_INTRA ))
6660              {
6661                for( UInt uiCurrRefListId = 0; uiCurrRefListId < 2; uiCurrRefListId++ )
6662                {
6663                  RefPicList  eCurrRefPicList = RefPicList( uiCurrRefListId );
6664                  Bool bLoop_stop = false;
6665                  for(Int iLoop = 0; iLoop < 2 && !bLoop_stop; ++iLoop)
6666                  {
6667                    RefPicList eBaseRefPicList = (iLoop ==1)? RefPicList( 1 -  uiCurrRefListId ) : RefPicList( uiCurrRefListId );
6668                    TComMvField cBaseMvField;
6669                    pcBaseCU->getMvField( pcBaseCU, iBaseAbsPartIdx, eBaseRefPicList, cBaseMvField );
6670                    Int         iBaseRefIdx     = cBaseMvField.getRefIdx();
6671                    if (iBaseRefIdx >= 0)
6672                    {
6673                      Int iBaseRefPOC = pcBaseCU->getSlice()->getRefPOC(eBaseRefPicList, iBaseRefIdx);
6674                      if (iBaseRefPOC != pcSlice->getPOC())   
6675                      {
6676                        for (Int iPdmRefIdx = 0; iPdmRefIdx < pcSlice->getNumRefIdx( eCurrRefPicList ); iPdmRefIdx++)
6677                        {
6678                          if (iBaseRefPOC == pcSlice->getRefPOC(eCurrRefPicList, iPdmRefIdx))
6679                          {
6680                            abPdmAvailable[ uiCurrRefListId ] = true;
6681                            TComMv cMv(cBaseMvField.getHor(), cBaseMvField.getVer());
6682
6683                            if( !bIsDepth )
6684                            {
6685                              cMv.setIDVFlag   (true);
6686                              cMv.setIDVHor    (cDv.getHor());                 
6687                              cMv.setIDVVer    (cDv.getVer()); 
6688                              cMv.setIDVVId    (iViewIndex); 
6689                            }
6690
6691#if !(NTT_BUG_FIX_TK54)
6692                            clipMv( cMv );
6693#endif
6694                            bLoop_stop = true;
6695
6696                            pcMvFieldSP[2*iPartition + uiCurrRefListId].setMvField(cMv, iPdmRefIdx);
6697                            break;
6698                          }
6699                        }
6700                      }
6701                    }
6702                  }
6703                }
6704              }
6705
6706              puhInterDirSP[iPartition] = (pcMvFieldSP[2*iPartition].getRefIdx()!=-1 ? 1: 0) + (pcMvFieldSP[2*iPartition+1].getRefIdx()!=-1 ? 2: 0);
6707              if (puhInterDirSP[iPartition] == 0)
6708              {
6709                puhInterDirSP[iPartition] = availableMcDc[0];
6710                pcMvFieldSP[2*iPartition].setMvField(pacPdmMv[0], paiPdmRefIdx[0]);
6711                pcMvFieldSP[2*iPartition + 1].setMvField(pacPdmMv[1], paiPdmRefIdx[1]);
6712
6713              }
6714              if (iSPHeight + iSPWidth == 12)
6715              {
6716                if (puhInterDirSP[iPartition] == 3)
6717                {
6718                  puhInterDirSP[iPartition] = 1;
6719                  pcMvFieldSP[2*iPartition + 1].setMvField(TComMv(0,0), -1);
6720                }
6721              }
6722              iPartition ++;
6723            }
6724          }
6725        }
6726      }
6727
6728      iCurrPosX  += ( iWidth  >> 1 );
6729      iCurrPosY  += ( iHeight >> 1 );
6730    }
6731#endif
6732
6733    ////////////////////////////////
6734    /////// IvMC + IvMCShift ///////
6735    ////////////////////////////////
6736
6737#if H_3D_SPIVMP
6738    if(m_pcSlice->getIsDepth())
6739    {
6740      iCurrPosX  += ( iWidth  >> 1 );
6741      iCurrPosY  += ( iHeight >> 1 );
6742    }
6743    for(Int iLoopCan = ( (m_pcSlice->getIsDepth() || getDBBPFlag(0)) ? 0 : 1 ); iLoopCan < ( 2 - m_pcSlice->getIsDepth() ); iLoopCan ++) 
6744#else
6745    for(Int iLoopCan = 0; iLoopCan < 2; iLoopCan ++)
6746#endif
6747    {
6748      // iLoopCan == 0 --> IvMC
6749      // iLoopCan == 1 --> IvMCShift
6750
6751      Int         iBaseCUAddr;
6752      Int         iBaseAbsPartIdx;
6753
6754      Int offsetW = (iLoopCan == 0) ? 0 : ( ((iWidth /2)*4) + 4 );
6755      Int offsetH = (iLoopCan == 0) ? 0 : ( ((iHeight/2)*4) + 4 );
6756
6757      Int         iBasePosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (cDv.getHor() + offsetW + 2 ) >> 2 ) );
6758      Int         iBasePosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (cDv.getVer() + offsetH + 2 ) >> 2 ) ); 
6759      pcBaseRec->getCUAddrAndPartIdx( iBasePosX , iBasePosY , iBaseCUAddr, iBaseAbsPartIdx );
6760
6761      TComDataCU* pcBaseCU    = pcBasePic->getCU( iBaseCUAddr );
6762      if(!( pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) == MODE_INTRA ))
6763      {
6764        // Loop reference picture list of current slice (X in spec).
6765        for( UInt uiCurrRefListId = 0; uiCurrRefListId < 2; uiCurrRefListId++ )       
6766        {
6767          RefPicList  eCurrRefPicList = RefPicList( uiCurrRefListId );
6768
6769          Bool stopLoop = false;
6770          // Loop reference picture list of candidate slice (Y in spec)
6771          for(Int iLoop = 0; iLoop < 2 && !stopLoop; ++iLoop)
6772          {
6773            RefPicList eBaseRefPicList = (iLoop ==1)? RefPicList( 1 -  uiCurrRefListId ) : RefPicList( uiCurrRefListId );
6774            TComMvField cBaseMvField;
6775            pcBaseCU->getMvField( pcBaseCU, iBaseAbsPartIdx, eBaseRefPicList, cBaseMvField );
6776            Int         iBaseRefIdx     = cBaseMvField.getRefIdx();
6777            if (iBaseRefIdx >= 0)
6778            {
6779              Int iBaseRefPOC = pcBaseCU->getSlice()->getRefPOC(eBaseRefPicList, iBaseRefIdx);
6780              if (iBaseRefPOC != pcSlice->getPOC())   
6781              {
6782                for (Int iPdmRefIdx = 0; iPdmRefIdx < pcSlice->getNumRefIdx( eCurrRefPicList ); iPdmRefIdx++)
6783                {
6784                  if (iBaseRefPOC == pcSlice->getRefPOC(eCurrRefPicList, iPdmRefIdx))
6785                  {
6786                    abPdmAvailable[ (uiCurrRefListId + (iLoopCan<<2)) ] = true;
6787                    TComMv cMv(cBaseMvField.getHor(), cBaseMvField.getVer());
6788#if H_3D_NBDV
6789#if H_3D_IV_MERGE
6790                    if( !bIsDepth )
6791                    {
6792#endif
6793                      cMv.setIDVFlag   (true);
6794                      cMv.setIDVHor    (cDv.getHor());                 
6795                      cMv.setIDVVer    (cDv.getVer()); 
6796                      cMv.setIDVVId    (iViewIndex); 
6797#if H_3D_IV_MERGE
6798                    }
6799#endif
6800#endif
6801#if !(NTT_BUG_FIX_TK54)
6802                    clipMv( cMv );
6803#endif
6804                    paiPdmRefIdx  [ (uiCurrRefListId + (iLoopCan<<2)) ] = iPdmRefIdx;
6805                    pacPdmMv      [ (uiCurrRefListId + (iLoopCan<<2)) ] = cMv;
6806                    stopLoop = true;
6807                    break;
6808                  }
6809                }
6810              }
6811            }
6812          }
6813        }
6814      }
6815    }
6816#if H_3D_SPIVMP
6817    for(Int iLoopCan = ( (m_pcSlice->getIsDepth() || getDBBPFlag(0)) ? 0 : 1 ); iLoopCan < ( 2 - m_pcSlice->getIsDepth() ); iLoopCan ++)
6818#else
6819    for(Int iLoopCan = 0; iLoopCan < 2; iLoopCan ++)
6820#endif
6821    {
6822      availableMcDc[(iLoopCan << 1)] = ( abPdmAvailable[(iLoopCan<<2)] ? 1 : 0 ) + ( abPdmAvailable[1 + (iLoopCan<<2)] ? 2 : 0);
6823    }
6824
6825  }
6826
6827  ////////////////////////////////
6828  /////// IvDC + IvDCShift ///////
6829  ////////////////////////////////
6830
6831  if( !getSlice()->getIsDepth() )
6832  {
6833    for( Int iRefListId = 0; iRefListId < 2 ; iRefListId++ )
6834    {
6835      RefPicList  eRefPicListDMV       = RefPicList( iRefListId );
6836      Int         iNumRefPics       = pcSlice->getNumRefIdx( eRefPicListDMV );
6837      for( Int iPdmRefIdx = 0; iPdmRefIdx < iNumRefPics; iPdmRefIdx++ )
6838      {
6839        if(( pcSlice->getRefPOC( eRefPicListDMV, iPdmRefIdx ) == pcSlice->getPOC()) && (pcSlice->getRefPic( eRefPicListDMV, iPdmRefIdx )->getViewIndex() == pDInfo->m_aVIdxCan))
6840        {
6841          for(Int iLoopCan = 0; iLoopCan < 2; iLoopCan ++)
6842          {
6843            Int ioffsetDV = (iLoopCan == 0) ? 0 : 4;
6844            abPdmAvailable[ iRefListId + 2 + (iLoopCan<<2) ] = true;
6845            paiPdmRefIdx  [ iRefListId + 2 + (iLoopCan<<2) ] = iPdmRefIdx;
6846#if H_3D_NBDV_REF
6847            TComMv cMv = depthRefineFlag ? pDInfo->m_acDoNBDV : pDInfo->m_acNBDV; 
6848#endif
6849            cMv.setHor( cMv.getHor() + ioffsetDV );
6850#if H_3D_IV_MERGE
6851            if( bIsDepth )
6852            {
6853              cMv.setHor((cMv.getHor()+2)>>2); 
6854            }
6855#endif
6856            cMv.setVer( 0 );
6857#if !(NTT_BUG_FIX_TK54)
6858            clipMv( cMv );
6859#endif
6860            pacPdmMv      [iRefListId + 2 + (iLoopCan<<2)] = cMv;
6861          }
6862          break;
6863        }
6864      }
6865    }
6866    for(Int iLoopCan = 0; iLoopCan < 2; iLoopCan ++)
6867    {
6868      availableMcDc[1 + (iLoopCan << 1)] = ( abPdmAvailable[2 + (iLoopCan<<2)] ? 1 : 0 ) + ( abPdmAvailable[3 + (iLoopCan<<2)] ? 2 : 0 );
6869    }
6870  }
6871  return false;
6872}
6873#endif
6874#if H_3D_ARP
6875Void TComDataCU::setARPWSubParts ( UChar w, UInt uiAbsPartIdx, UInt uiDepth )
6876{
6877  assert( sizeof( *m_puhARPW) == 1 );
6878  memset( m_puhARPW + uiAbsPartIdx, w, m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ) );
6879}
6880#endif
6881
6882#if H_3D_IC
6883Void TComDataCU::setICFlagSubParts( Bool bICFlag, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
6884{
6885  memset( m_pbICFlag + uiAbsPartIdx, bICFlag, (m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ))*sizeof(Bool) );
6886}
6887
6888Bool TComDataCU::isICFlagRequired( UInt uiAbsPartIdx )
6889{
6890  UInt uiPartAddr;
6891  UInt iNumbPart;
6892
6893  if( !( getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) )
6894  {
6895    return false;
6896  }
6897
6898  if( getSlice()->getIcSkipParseFlag() )
6899  {
6900    if( getMergeFlag( uiAbsPartIdx ) && getMergeIndex( uiAbsPartIdx ) == 0 )
6901    {
6902      return false;
6903    }
6904  }
6905
6906  if( getMergeFlag( uiAbsPartIdx ) )
6907  {
6908    return true;
6909  }
6910
6911
6912  Int iWidth, iHeight;
6913
6914  iNumbPart = ( getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ? 1 : ( getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ? 4 : 2 ) );
6915
6916  for(UInt i = 0; i < iNumbPart; i++)
6917  {
6918    getPartIndexAndSize( i, uiPartAddr, iWidth, iHeight, uiAbsPartIdx, true );
6919    uiPartAddr += uiAbsPartIdx;
6920
6921    for(UInt uiRefIdx = 0; uiRefIdx < 2; uiRefIdx++)
6922    {
6923      RefPicList eRefList = uiRefIdx ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
6924      Int iBestRefIdx = getCUMvField(eRefList)->getRefIdx(uiPartAddr);
6925
6926      if( ( getInterDir( uiPartAddr ) & ( uiRefIdx+1 ) ) && iBestRefIdx >= 0 && getSlice()->getViewIndex() != getSlice()->getRefPic( eRefList, iBestRefIdx )->getViewIndex() )
6927      {
6928        return true;
6929      }
6930    }
6931  }
6932
6933  return false;
6934}
6935#endif
6936#if H_3D_DIM_DMM
6937Void TComDataCU::setDmmWedgeTabIdxSubParts( UInt tabIdx, UInt dmmType, UInt uiAbsPartIdx, UInt uiDepth )
6938{
6939  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
6940  for( UInt ui = 0; ui < uiCurrPartNumb; ui++ ) { m_dmmWedgeTabIdx[dmmType][uiAbsPartIdx+ui] = tabIdx; }
6941}
6942#endif
6943
6944#if H_3D_VSP
6945Void TComDataCU::setMvFieldPUForVSP( TComDataCU* pcCU, UInt partAddr, Int width, Int height, RefPicList eRefPicList, Int iRefIdx, Int &vspSize )
6946{
6947  // Get depth reference
6948  Int depthRefViewIdx = pcCU->getDvInfo(partAddr).m_aVIdxCan;
6949 
6950#if H_3D_FCO_VSP_DONBDV_E0163
6951  TComPic* pRefPicBaseDepth = 0;
6952  Bool     bIsCurrDepthCoded = false;
6953  pRefPicBaseDepth  = pcCU->getSlice()->getIvPic( true, pcCU->getSlice()->getViewIndex() );
6954  if ( pRefPicBaseDepth->getPicYuvRec() != NULL  ) 
6955  {
6956    bIsCurrDepthCoded = true;
6957  }
6958  else 
6959  {
6960    pRefPicBaseDepth = pcCU->getSlice()->getIvPic (true, depthRefViewIdx );
6961  }
6962#else
6963  TComPic* pRefPicBaseDepth = pcCU->getSlice()->getIvPic (true, depthRefViewIdx );
6964#endif
6965  assert(pRefPicBaseDepth != NULL);
6966  TComPicYuv* pcBaseViewDepthPicYuv = pRefPicBaseDepth->getPicYuvRec();
6967  assert(pcBaseViewDepthPicYuv != NULL);
6968  pcBaseViewDepthPicYuv->extendPicBorder();
6969
6970  // Get texture reference
6971  assert(iRefIdx >= 0);
6972  TComPic* pRefPicBaseTxt = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx );
6973  TComPicYuv* pcBaseViewTxtPicYuv = pRefPicBaseTxt->getPicYuvRec();
6974  assert(pcBaseViewTxtPicYuv != NULL);
6975
6976  // Initialize LUT according to the reference viewIdx
6977  Int txtRefViewIdx = pRefPicBaseTxt->getViewIndex();
6978  Int* pShiftLUT    = pcCU->getSlice()->getDepthToDisparityB( txtRefViewIdx );
6979  assert( txtRefViewIdx < pcCU->getSlice()->getViewIndex() );
6980
6981  // prepare Dv to access depth map or reference view
6982  TComMv cDv  = pcCU->getDvInfo(partAddr).m_acNBDV;
6983  pcCU->clipMv(cDv);
6984
6985#if H_3D_FCO_VSP_DONBDV_E0163
6986  if ( bIsCurrDepthCoded )
6987  {
6988      cDv.setZero();
6989  }
6990#endif
6991
6992  // fetch virtual depth map & convert depth to motion vector, which are stored in the motion memory
6993  xSetMvFieldForVSP( pcCU, pcBaseViewDepthPicYuv, &cDv, partAddr, width, height, pShiftLUT, eRefPicList, iRefIdx, pcCU->getSlice()->getIsDepth(), vspSize );
6994}
6995
6996Void TComDataCU::xSetMvFieldForVSP( TComDataCU *cu, TComPicYuv *picRefDepth, TComMv *dv, UInt partAddr, Int width, Int height, Int *shiftLUT, RefPicList refPicList, Int refIdx, Bool isDepth, Int &vspSize )
6997{
6998  TComCUMvField *cuMvField = cu->getCUMvField( refPicList );
6999  Int partAddrRasterSubPULine  = g_auiZscanToRaster[ partAddr ];
7000  Int numPartsLine    = cu->getPic()->getNumPartInWidth();
7001
7002  Int nTxtPerMvInfoX = 4; // cu->getPic()->getMinCUWidth();
7003  Int nTxtPerMvInfoY = 4; // cu->getPic()->getMinCUHeight();
7004
7005  Int refDepStride = picRefDepth->getStride();
7006
7007  TComMv tmpMv(0, 0);
7008  tmpMv.setIDVFlag(false);
7009
7010  Int refDepOffset  = ( (dv->getHor()+2) >> 2 ) + ( (dv->getVer()+2) >> 2 ) * refDepStride;
7011  Pel *refDepth     = picRefDepth->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refDepOffset;
7012
7013  if ((height % 8))
7014  {
7015    vspSize = 1; // 8x4
7016  }
7017  else if ((width % 8))
7018  {
7019    vspSize = 0; // 4x8
7020  }
7021  else
7022  {
7023    Bool ULvsBR, URvsBL;
7024    ULvsBR = refDepth[0]       < refDepth[refDepStride * (height-1) + width-1];
7025    URvsBL = refDepth[width-1] < refDepth[refDepStride * (height-1)];
7026    vspSize = ( ULvsBR ^ URvsBL ) ? 0 : 1;
7027  }
7028 
7029  Int subBlockW, subBlockH;
7030  if (vspSize)
7031  {
7032    subBlockW = 8;
7033    subBlockH = 4;
7034  }
7035  else
7036  {
7037    subBlockW = 4;
7038    subBlockH = 8;
7039  }
7040 
7041  Int numPartsInSubPUW = subBlockW / nTxtPerMvInfoX;
7042  Int numPartsInSubPUH = subBlockH / nTxtPerMvInfoY * numPartsLine;
7043
7044  for( Int y=0; y<height; y+=subBlockH, partAddrRasterSubPULine+=numPartsInSubPUH )
7045  {
7046    Pel *refDepthTmp[4];
7047    refDepthTmp[0] = refDepth + refDepStride * y;
7048    refDepthTmp[1] = refDepthTmp[0] + subBlockW - 1;
7049    refDepthTmp[2] = refDepthTmp[0] + refDepStride * (subBlockH - 1);
7050    refDepthTmp[3] = refDepthTmp[2] + subBlockW - 1;
7051
7052    Int partAddrRasterSubPU = partAddrRasterSubPULine;
7053    for( Int x=0; x<width; x+=subBlockW, partAddrRasterSubPU+=numPartsInSubPUW )
7054    {
7055      Pel  maxDepthVal;
7056      maxDepthVal = refDepthTmp[0][x];
7057      maxDepthVal = std::max( maxDepthVal, refDepthTmp[1][x]);
7058      maxDepthVal = std::max( maxDepthVal, refDepthTmp[2][x]);
7059      maxDepthVal = std::max( maxDepthVal, refDepthTmp[3][x]);
7060      tmpMv.setHor( (Short) shiftLUT[ maxDepthVal ] );
7061
7062      Int partAddrRasterPartLine = partAddrRasterSubPU;
7063      for( Int sY=0; sY<numPartsInSubPUH; sY+=numPartsLine, partAddrRasterPartLine += numPartsLine )
7064      {
7065        Int partAddrRasterPart = partAddrRasterPartLine;
7066        for( Int sX=0; sX<numPartsInSubPUW; sX+=1, partAddrRasterPart++ )
7067        {
7068          cuMvField->setMv    ( g_auiRasterToZscan[ partAddrRasterPart ], tmpMv );
7069          cuMvField->setRefIdx( g_auiRasterToZscan[ partAddrRasterPart ], refIdx );
7070        }
7071      }
7072    }
7073  }
7074
7075  vspSize = (vspSize<<2)+1;
7076
7077}
7078#endif
7079
7080//! \}
Note: See TracBrowser for help on using the repository browser.