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

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

Merged branch/9.2-dev0@722.

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