source: 3DVCSoftware/branches/HTM-DEV-2.0-dev1-NTT/source/Lib/TLibCommon/TComDataCU.cpp @ 579

Last change on this file since 579 was 576, checked in by ntt, 12 years ago

Integration for the adoptions in E0207, E0208, and E0141 by NTT.

  • Property svn:eol-style set to native
File size: 220.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  m_dmm2DeltaEnd    = NULL;
123  m_dmm3IntraTabIdx = NULL;
124#endif
125#if H_3D_DIM_RBC
126  m_pucEdgeCode     = NULL;
127  m_pucEdgeNumber   = NULL;
128  m_pucEdgeStartPos = NULL;
129  m_pbEdgeLeftFirst = NULL;
130  m_pbEdgePartition = NULL;
131#endif
132#if H_3D_DIM_SDC
133  m_pbSDCFlag             = NULL;
134  m_apSegmentDCOffset[0]  = NULL;
135  m_apSegmentDCOffset[1]  = NULL;
136#endif
137#endif
138  m_bDecSubCu          = false;
139  m_sliceStartCU        = 0;
140  m_sliceSegmentStartCU = 0;
141#if H_3D_NBDV
142  m_pDvInfo              = NULL;
143#endif
144#if H_3D_VSP
145  m_piVSPFlag            = NULL;
146#if MTK_VSP_FIX_E0172
147  m_piVSPDir             = NULL;
148#endif
149#endif
150#if H_3D_ARP
151  m_puhARPW              = NULL;
152#endif
153#if H_3D_IC
154  m_pbICFlag             = NULL;
155#endif
156}
157
158TComDataCU::~TComDataCU()
159{
160}
161
162Void TComDataCU::create(UInt uiNumPartition, UInt uiWidth, UInt uiHeight, Bool bDecSubCu, Int unitSize
163#if ADAPTIVE_QP_SELECTION
164                        , Bool bGlobalRMARLBuffer
165#endif                                             
166                        )
167{
168  m_bDecSubCu = bDecSubCu;
169 
170  m_pcPic              = NULL;
171  m_pcSlice            = NULL;
172  m_uiNumPartition     = uiNumPartition;
173  m_unitSize = unitSize;
174 
175  if ( !bDecSubCu )
176  {
177    m_phQP               = (Char*     )xMalloc(Char,     uiNumPartition);
178    m_puhDepth           = (UChar*    )xMalloc(UChar,    uiNumPartition);
179    m_puhWidth           = (UChar*    )xMalloc(UChar,    uiNumPartition);
180    m_puhHeight          = (UChar*    )xMalloc(UChar,    uiNumPartition);
181
182    m_skipFlag           = new Bool[ uiNumPartition ];
183
184    m_pePartSize         = new Char[ uiNumPartition ];
185    memset( m_pePartSize, SIZE_NONE,uiNumPartition * sizeof( *m_pePartSize ) );
186    m_pePredMode         = new Char[ uiNumPartition ];
187    m_CUTransquantBypass = new Bool[ uiNumPartition ];
188    m_pbMergeFlag        = (Bool*  )xMalloc(Bool,   uiNumPartition);
189    m_puhMergeIndex      = (UChar* )xMalloc(UChar,  uiNumPartition);
190#if H_3D_VSP
191    m_piVSPFlag          = (Char*  )xMalloc(Char,   uiNumPartition);
192#if MTK_VSP_FIX_E0172
193    m_piVSPDir           = (Char*  )xMalloc(Char,   uiNumPartition);
194#endif
195#endif
196    m_puhLumaIntraDir    = (UChar* )xMalloc(UChar,  uiNumPartition);
197    m_puhChromaIntraDir  = (UChar* )xMalloc(UChar,  uiNumPartition);
198    m_puhInterDir        = (UChar* )xMalloc(UChar,  uiNumPartition);
199   
200    m_puhTrIdx           = (UChar* )xMalloc(UChar,  uiNumPartition);
201    m_puhTransformSkip[0] = (UChar* )xMalloc(UChar,  uiNumPartition);
202    m_puhTransformSkip[1] = (UChar* )xMalloc(UChar,  uiNumPartition);
203    m_puhTransformSkip[2] = (UChar* )xMalloc(UChar,  uiNumPartition);
204
205    m_puhCbf[0]          = (UChar* )xMalloc(UChar,  uiNumPartition);
206    m_puhCbf[1]          = (UChar* )xMalloc(UChar,  uiNumPartition);
207    m_puhCbf[2]          = (UChar* )xMalloc(UChar,  uiNumPartition);
208   
209    m_apiMVPIdx[0]       = new Char[ uiNumPartition ];
210    m_apiMVPIdx[1]       = new Char[ uiNumPartition ];
211    m_apiMVPNum[0]       = new Char[ uiNumPartition ];
212    m_apiMVPNum[1]       = new Char[ uiNumPartition ];
213    memset( m_apiMVPIdx[0], -1,uiNumPartition * sizeof( Char ) );
214    memset( m_apiMVPIdx[1], -1,uiNumPartition * sizeof( Char ) );
215   
216    m_pcTrCoeffY         = (TCoeff*)xMalloc(TCoeff, uiWidth*uiHeight);
217    m_pcTrCoeffCb        = (TCoeff*)xMalloc(TCoeff, uiWidth*uiHeight/4);
218    m_pcTrCoeffCr        = (TCoeff*)xMalloc(TCoeff, uiWidth*uiHeight/4);
219#if H_3D_NBDV
220    m_pDvInfo            = (DisInfo* )xMalloc(DisInfo,  uiNumPartition);
221#endif
222    memset( m_pcTrCoeffY, 0,uiWidth*uiHeight * sizeof( TCoeff ) );
223    memset( m_pcTrCoeffCb, 0,uiWidth*uiHeight/4 * sizeof( TCoeff ) );
224    memset( m_pcTrCoeffCr, 0,uiWidth*uiHeight/4 * sizeof( TCoeff ) );
225#if ADAPTIVE_QP_SELECTION   
226    if( bGlobalRMARLBuffer )
227    {
228      if( m_pcGlbArlCoeffY == NULL )
229      {
230        m_pcGlbArlCoeffY   = (Int*)xMalloc(Int, uiWidth*uiHeight);
231        m_pcGlbArlCoeffCb  = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
232        m_pcGlbArlCoeffCr  = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
233      }
234      m_pcArlCoeffY        = m_pcGlbArlCoeffY;
235      m_pcArlCoeffCb       = m_pcGlbArlCoeffCb;
236      m_pcArlCoeffCr       = m_pcGlbArlCoeffCr;
237      m_ArlCoeffIsAliasedAllocation = true;
238    }
239    else
240    {
241      m_pcArlCoeffY        = (Int*)xMalloc(Int, uiWidth*uiHeight);
242      m_pcArlCoeffCb       = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
243      m_pcArlCoeffCr       = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
244    }
245#endif
246   
247    m_pbIPCMFlag         = (Bool*  )xMalloc(Bool, uiNumPartition);
248    m_pcIPCMSampleY      = (Pel*   )xMalloc(Pel , uiWidth*uiHeight);
249    m_pcIPCMSampleCb     = (Pel*   )xMalloc(Pel , uiWidth*uiHeight/4);
250    m_pcIPCMSampleCr     = (Pel*   )xMalloc(Pel , uiWidth*uiHeight/4);
251
252    m_acCUMvField[0].create( uiNumPartition );
253    m_acCUMvField[1].create( uiNumPartition );
254   
255#if H_3D_ARP
256    m_puhARPW            = new UChar[ uiNumPartition];
257#endif
258#if H_3D_IC
259    m_pbICFlag           = (Bool* )xMalloc(Bool,   uiNumPartition);
260#endif
261#if H_3D_DIM
262    for( Int i = 0; i < DIM_NUM_TYPE; i++ )
263    {
264      m_dimDeltaDC[i][0] = (Pel* )xMalloc(Pel, uiNumPartition); 
265      m_dimDeltaDC[i][1] = (Pel* )xMalloc(Pel, uiNumPartition);
266    }
267#if H_3D_DIM_DMM
268    for( Int i = 0; i < DMM_NUM_TYPE; i++ )
269    {
270      m_dmmWedgeTabIdx[i]    = (UInt*)xMalloc(UInt, uiNumPartition);
271    }
272    m_dmm2DeltaEnd    = (Int* )xMalloc(Int,  uiNumPartition);
273    m_dmm3IntraTabIdx = (UInt*)xMalloc(UInt, uiNumPartition);
274#endif
275#if H_3D_DIM_RBC
276    m_pucEdgeCode     = (UChar*)xMalloc(UChar, uiNumPartition * RBC_MAX_EDGE_NUM_PER_4x4);
277    m_pucEdgeNumber   = (UChar*)xMalloc(UChar, uiNumPartition);
278    m_pucEdgeStartPos = (UChar*)xMalloc(UChar, uiNumPartition);
279    m_pbEdgeLeftFirst = (Bool*)xMalloc(Bool, uiNumPartition);
280    m_pbEdgePartition = (Bool*)xMalloc(Bool, uiNumPartition * 16);
281#endif
282#if H_3D_DIM_SDC
283    m_pbSDCFlag             = (Bool*)xMalloc(Bool, uiNumPartition);
284    m_apSegmentDCOffset[0]  = (Pel*)xMalloc(Pel, uiNumPartition);
285    m_apSegmentDCOffset[1]  = (Pel*)xMalloc(Pel, uiNumPartition);
286#endif
287#endif
288  }
289  else
290  {
291    m_acCUMvField[0].setNumPartition(uiNumPartition );
292    m_acCUMvField[1].setNumPartition(uiNumPartition );
293  }
294 
295  m_sliceStartCU        = (UInt*  )xMalloc(UInt, uiNumPartition);
296  m_sliceSegmentStartCU = (UInt*  )xMalloc(UInt, uiNumPartition);
297 
298  // create pattern memory
299  m_pcPattern            = (TComPattern*)xMalloc(TComPattern, 1);
300 
301  // create motion vector fields
302 
303  m_pcCUAboveLeft      = NULL;
304  m_pcCUAboveRight     = NULL;
305  m_pcCUAbove          = NULL;
306  m_pcCULeft           = NULL;
307 
308  m_apcCUColocated[0]  = NULL;
309  m_apcCUColocated[1]  = NULL;
310}
311
312Void TComDataCU::destroy()
313{
314  m_pcPic              = NULL;
315  m_pcSlice            = NULL;
316 
317  if ( m_pcPattern )
318  { 
319    xFree(m_pcPattern);
320    m_pcPattern = NULL;
321  }
322 
323  // encoder-side buffer free
324  if ( !m_bDecSubCu )
325  {
326    if ( m_phQP               ) { xFree(m_phQP);                m_phQP              = NULL; }
327    if ( m_puhDepth           ) { xFree(m_puhDepth);            m_puhDepth          = NULL; }
328    if ( m_puhWidth           ) { xFree(m_puhWidth);            m_puhWidth          = NULL; }
329    if ( m_puhHeight          ) { xFree(m_puhHeight);           m_puhHeight         = NULL; }
330
331    if ( m_skipFlag           ) { delete[] m_skipFlag;          m_skipFlag          = NULL; }
332
333    if ( m_pePartSize         ) { delete[] m_pePartSize;        m_pePartSize        = NULL; }
334    if ( m_pePredMode         ) { delete[] m_pePredMode;        m_pePredMode        = NULL; }
335    if ( m_CUTransquantBypass ) { delete[] m_CUTransquantBypass;m_CUTransquantBypass = NULL; }
336    if ( m_puhCbf[0]          ) { xFree(m_puhCbf[0]);           m_puhCbf[0]         = NULL; }
337    if ( m_puhCbf[1]          ) { xFree(m_puhCbf[1]);           m_puhCbf[1]         = NULL; }
338    if ( m_puhCbf[2]          ) { xFree(m_puhCbf[2]);           m_puhCbf[2]         = NULL; }
339    if ( m_puhInterDir        ) { xFree(m_puhInterDir);         m_puhInterDir       = NULL; }
340    if ( m_pbMergeFlag        ) { xFree(m_pbMergeFlag);         m_pbMergeFlag       = NULL; }
341    if ( m_puhMergeIndex      ) { xFree(m_puhMergeIndex);       m_puhMergeIndex     = NULL; }
342#if H_3D_VSP
343    if ( m_piVSPFlag          ) { xFree(m_piVSPFlag);           m_piVSPFlag         = NULL; }
344#if MTK_VSP_FIX_E0172
345    if ( m_piVSPDir           ) { xFree(m_piVSPDir  );          m_piVSPDir          = NULL; }
346#endif
347#endif
348    if ( m_puhLumaIntraDir    ) { xFree(m_puhLumaIntraDir);     m_puhLumaIntraDir   = NULL; }
349    if ( m_puhChromaIntraDir  ) { xFree(m_puhChromaIntraDir);   m_puhChromaIntraDir = NULL; }
350    if ( m_puhTrIdx           ) { xFree(m_puhTrIdx);            m_puhTrIdx          = NULL; }
351    if ( m_puhTransformSkip[0]) { xFree(m_puhTransformSkip[0]); m_puhTransformSkip[0] = NULL; }
352    if ( m_puhTransformSkip[1]) { xFree(m_puhTransformSkip[1]); m_puhTransformSkip[1] = NULL; }
353    if ( m_puhTransformSkip[2]) { xFree(m_puhTransformSkip[2]); m_puhTransformSkip[2] = NULL; }
354    if ( m_pcTrCoeffY         ) { xFree(m_pcTrCoeffY);          m_pcTrCoeffY        = NULL; }
355    if ( m_pcTrCoeffCb        ) { xFree(m_pcTrCoeffCb);         m_pcTrCoeffCb       = NULL; }
356    if ( m_pcTrCoeffCr        ) { xFree(m_pcTrCoeffCr);         m_pcTrCoeffCr       = NULL; }
357#if ADAPTIVE_QP_SELECTION
358    if (!m_ArlCoeffIsAliasedAllocation)
359    {
360      xFree(m_pcArlCoeffY); m_pcArlCoeffY = 0;
361      xFree(m_pcArlCoeffCb); m_pcArlCoeffCb = 0;
362      xFree(m_pcArlCoeffCr); m_pcArlCoeffCr = 0;
363    }
364    if ( m_pcGlbArlCoeffY     ) { xFree(m_pcGlbArlCoeffY);      m_pcGlbArlCoeffY    = NULL; }
365    if ( m_pcGlbArlCoeffCb    ) { xFree(m_pcGlbArlCoeffCb);     m_pcGlbArlCoeffCb   = NULL; }
366    if ( m_pcGlbArlCoeffCr    ) { xFree(m_pcGlbArlCoeffCr);     m_pcGlbArlCoeffCr   = NULL; }
367#endif
368    if ( m_pbIPCMFlag         ) { xFree(m_pbIPCMFlag   );       m_pbIPCMFlag        = NULL; }
369    if ( m_pcIPCMSampleY      ) { xFree(m_pcIPCMSampleY);       m_pcIPCMSampleY     = NULL; }
370    if ( m_pcIPCMSampleCb     ) { xFree(m_pcIPCMSampleCb);      m_pcIPCMSampleCb    = NULL; }
371    if ( m_pcIPCMSampleCr     ) { xFree(m_pcIPCMSampleCr);      m_pcIPCMSampleCr    = NULL; }
372    if ( m_apiMVPIdx[0]       ) { delete[] m_apiMVPIdx[0];      m_apiMVPIdx[0]      = NULL; }
373    if ( m_apiMVPIdx[1]       ) { delete[] m_apiMVPIdx[1];      m_apiMVPIdx[1]      = NULL; }
374    if ( m_apiMVPNum[0]       ) { delete[] m_apiMVPNum[0];      m_apiMVPNum[0]      = NULL; }
375    if ( m_apiMVPNum[1]       ) { delete[] m_apiMVPNum[1];      m_apiMVPNum[1]      = NULL; }
376#if H_3D_NBDV
377    if ( m_pDvInfo            ) { xFree(m_pDvInfo);             m_pDvInfo           = NULL; }
378#endif
379
380#if H_3D_ARP
381    if ( m_puhARPW            ) { delete[] m_puhARPW;           m_puhARPW           = NULL; }
382#endif
383#if H_3D_IC
384    if ( m_pbICFlag           ) { xFree(m_pbICFlag);            m_pbICFlag          = NULL; }
385#endif
386    m_acCUMvField[0].destroy();
387    m_acCUMvField[1].destroy();
388
389#if H_3D_DIM
390    for( Int i = 0; i < DIM_NUM_TYPE; i++ )
391    {
392      if ( m_dimDeltaDC[i][0] ) { xFree( m_dimDeltaDC[i][0] ); m_dimDeltaDC[i][0] = NULL; }
393      if ( m_dimDeltaDC[i][1] ) { xFree( m_dimDeltaDC[i][1] ); m_dimDeltaDC[i][1] = NULL; }
394    }
395#if H_3D_DIM_DMM
396    for( Int i = 0; i < DMM_NUM_TYPE; i++ )
397    {
398      if ( m_dmmWedgeTabIdx[i] ) { xFree( m_dmmWedgeTabIdx[i] ); m_dmmWedgeTabIdx[i] = NULL; }
399    }
400    if ( m_dmm2DeltaEnd    ) { xFree( m_dmm2DeltaEnd    ); m_dmm2DeltaEnd    = NULL; }
401    if ( m_dmm3IntraTabIdx ) { xFree( m_dmm3IntraTabIdx ); m_dmm3IntraTabIdx = NULL; }
402#endif
403#if H_3D_DIM_RBC
404    if ( m_pbEdgeLeftFirst ) { xFree( m_pbEdgeLeftFirst ); m_pbEdgeLeftFirst = NULL; }
405    if ( m_pucEdgeStartPos ) { xFree( m_pucEdgeStartPos ); m_pucEdgeStartPos = NULL; }
406    if ( m_pucEdgeNumber   ) { xFree( m_pucEdgeNumber   ); m_pucEdgeNumber   = NULL; }
407    if ( m_pucEdgeCode     ) { xFree( m_pucEdgeCode     ); m_pucEdgeCode     = NULL; }
408    if ( m_pbEdgePartition ) { xFree( m_pbEdgePartition ); m_pbEdgePartition = NULL; }
409#endif
410#if H_3D_DIM_SDC
411    if ( m_pbSDCFlag            ) { xFree(m_pbSDCFlag);             m_pbSDCFlag             = NULL; }
412    if ( m_apSegmentDCOffset[0] ) { xFree(m_apSegmentDCOffset[0]);  m_apSegmentDCOffset[0]  = NULL; }
413    if ( m_apSegmentDCOffset[1] ) { xFree(m_apSegmentDCOffset[1]);  m_apSegmentDCOffset[1]  = NULL; }
414#endif
415#endif   
416  }
417 
418  m_pcCUAboveLeft       = NULL;
419  m_pcCUAboveRight      = NULL;
420  m_pcCUAbove           = NULL;
421  m_pcCULeft            = NULL;
422 
423  m_apcCUColocated[0]   = NULL;
424  m_apcCUColocated[1]   = NULL;
425
426  if( m_sliceStartCU )
427  {
428    xFree(m_sliceStartCU);
429    m_sliceStartCU=NULL;
430  }
431  if(m_sliceSegmentStartCU )
432  {
433    xFree(m_sliceSegmentStartCU);
434    m_sliceSegmentStartCU=NULL;
435  }
436}
437
438const NDBFBlockInfo& NDBFBlockInfo::operator= (const NDBFBlockInfo& src)
439{
440  this->tileID = src.tileID;
441  this->sliceID= src.sliceID;
442  this->startSU= src.startSU;
443  this->endSU  = src.endSU;
444  this->widthSU= src.widthSU;
445  this->heightSU=src.heightSU;
446  this->posX   = src.posX;
447  this->posY   = src.posY;
448  this->width  = src.width;
449  this->height = src.height;
450  ::memcpy(this->isBorderAvailable, src.isBorderAvailable, sizeof(Bool)*((Int)NUM_SGU_BORDER));
451  this->allBordersAvailable = src.allBordersAvailable;
452
453  return *this;
454}
455
456
457// ====================================================================================================================
458// Public member functions
459// ====================================================================================================================
460
461// --------------------------------------------------------------------------------------------------------------------
462// Initialization
463// --------------------------------------------------------------------------------------------------------------------
464
465/**
466 - initialize top-level CU
467 - internal buffers are already created
468 - set values before encoding a CU
469 .
470 \param  pcPic     picture (TComPic) class pointer
471 \param  iCUAddr   CU address
472 */
473Void TComDataCU::initCU( TComPic* pcPic, UInt iCUAddr )
474{
475
476  m_pcPic              = pcPic;
477  m_pcSlice            = pcPic->getSlice(pcPic->getCurrSliceIdx());
478  m_uiCUAddr           = iCUAddr;
479  m_uiCUPelX           = ( iCUAddr % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth;
480  m_uiCUPelY           = ( iCUAddr / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight;
481  m_uiAbsIdxInLCU      = 0;
482  m_dTotalCost         = MAX_DOUBLE;
483  m_uiTotalDistortion  = 0;
484  m_uiTotalBits        = 0;
485  m_uiTotalBins        = 0;
486  m_uiNumPartition     = pcPic->getNumPartInCU();
487 
488  for(Int i=0; i<pcPic->getNumPartInCU(); i++)
489  {
490    if(pcPic->getPicSym()->getInverseCUOrderMap(iCUAddr)*pcPic->getNumPartInCU()+i>=getSlice()->getSliceCurStartCUAddr())
491    {
492      m_sliceStartCU[i]=getSlice()->getSliceCurStartCUAddr();
493    }
494    else
495    {
496      m_sliceStartCU[i]=pcPic->getCU(getAddr())->m_sliceStartCU[i];
497    }
498  }
499  for(Int i=0; i<pcPic->getNumPartInCU(); i++)
500  {
501    if(pcPic->getPicSym()->getInverseCUOrderMap(iCUAddr)*pcPic->getNumPartInCU()+i>=getSlice()->getSliceSegmentCurStartCUAddr())
502    {
503      m_sliceSegmentStartCU[i]=getSlice()->getSliceSegmentCurStartCUAddr();
504    }
505    else
506    {
507      m_sliceSegmentStartCU[i]=pcPic->getCU(getAddr())->m_sliceSegmentStartCU[i];
508    }
509  }
510
511  Int partStartIdx = getSlice()->getSliceSegmentCurStartCUAddr() - pcPic->getPicSym()->getInverseCUOrderMap(iCUAddr) * pcPic->getNumPartInCU();
512
513  Int numElements = min<Int>( partStartIdx, m_uiNumPartition );
514  for ( Int ui = 0; ui < numElements; ui++ )
515  {
516    TComDataCU * pcFrom = pcPic->getCU(getAddr());
517    m_skipFlag[ui]   = pcFrom->getSkipFlag(ui);
518    m_pePartSize[ui] = pcFrom->getPartitionSize(ui);
519    m_pePredMode[ui] = pcFrom->getPredictionMode(ui);
520    m_CUTransquantBypass[ui] = pcFrom->getCUTransquantBypass(ui);
521    m_puhDepth[ui] = pcFrom->getDepth(ui);
522#if H_3D_ARP
523    m_puhARPW   [ui] = pcFrom->getARPW( ui );
524#endif
525#if H_3D_IC
526    m_pbICFlag[ui]   =  pcFrom->m_pbICFlag[ui];
527#endif
528    m_puhWidth  [ui] = pcFrom->getWidth(ui);
529    m_puhHeight [ui] = pcFrom->getHeight(ui);
530    m_puhTrIdx  [ui] = pcFrom->getTransformIdx(ui);
531    m_puhTransformSkip[0][ui] = pcFrom->getTransformSkip(ui,TEXT_LUMA);
532    m_puhTransformSkip[1][ui] = pcFrom->getTransformSkip(ui,TEXT_CHROMA_U);
533    m_puhTransformSkip[2][ui] = pcFrom->getTransformSkip(ui,TEXT_CHROMA_V);
534    m_apiMVPIdx[0][ui] = pcFrom->m_apiMVPIdx[0][ui];;
535    m_apiMVPIdx[1][ui] = pcFrom->m_apiMVPIdx[1][ui];
536    m_apiMVPNum[0][ui] = pcFrom->m_apiMVPNum[0][ui];
537    m_apiMVPNum[1][ui] = pcFrom->m_apiMVPNum[1][ui];
538    m_phQP[ui]=pcFrom->m_phQP[ui];
539    m_pbMergeFlag[ui]=pcFrom->m_pbMergeFlag[ui];
540    m_puhMergeIndex[ui]=pcFrom->m_puhMergeIndex[ui];
541#if H_3D_VSP
542    m_piVSPFlag[ui] = pcFrom->m_piVSPFlag[ui];
543#if MTK_VSP_FIX_E0172
544    m_piVSPDir  [ui] = pcFrom->m_piVSPDir[ui];
545#endif
546#endif
547    m_puhLumaIntraDir[ui]=pcFrom->m_puhLumaIntraDir[ui];
548    m_puhChromaIntraDir[ui]=pcFrom->m_puhChromaIntraDir[ui];
549    m_puhInterDir[ui]=pcFrom->m_puhInterDir[ui];
550    m_puhCbf[0][ui]=pcFrom->m_puhCbf[0][ui];
551    m_puhCbf[1][ui]=pcFrom->m_puhCbf[1][ui];
552    m_puhCbf[2][ui]=pcFrom->m_puhCbf[2][ui];
553    m_pbIPCMFlag[ui] = pcFrom->m_pbIPCMFlag[ui];
554#if H_3D_DIM_SDC
555    m_pbSDCFlag[ui] = pcFrom->m_pbSDCFlag[ui];
556#endif
557  }
558 
559  Int firstElement = max<Int>( partStartIdx, 0 );
560  numElements = m_uiNumPartition - firstElement;
561 
562  if ( numElements > 0 )
563  {
564    memset( m_skipFlag          + firstElement, false,                    numElements * sizeof( *m_skipFlag ) );
565
566    memset( m_pePartSize        + firstElement, SIZE_NONE,                numElements * sizeof( *m_pePartSize ) );
567    memset( m_pePredMode        + firstElement, MODE_NONE,                numElements * sizeof( *m_pePredMode ) );
568    memset( m_CUTransquantBypass+ firstElement, false,                    numElements * sizeof( *m_CUTransquantBypass) );
569    memset( m_puhDepth          + firstElement, 0,                        numElements * sizeof( *m_puhDepth ) );
570    memset( m_puhTrIdx          + firstElement, 0,                        numElements * sizeof( *m_puhTrIdx ) );
571    memset( m_puhTransformSkip[0] + firstElement, 0,                      numElements * sizeof( *m_puhTransformSkip[0]) );
572    memset( m_puhTransformSkip[1] + firstElement, 0,                      numElements * sizeof( *m_puhTransformSkip[1]) );
573    memset( m_puhTransformSkip[2] + firstElement, 0,                      numElements * sizeof( *m_puhTransformSkip[2]) );
574    memset( m_puhWidth          + firstElement, g_uiMaxCUWidth,           numElements * sizeof( *m_puhWidth ) );
575    memset( m_puhHeight         + firstElement, g_uiMaxCUHeight,          numElements * sizeof( *m_puhHeight ) );
576    memset( m_apiMVPIdx[0]      + firstElement, -1,                       numElements * sizeof( *m_apiMVPIdx[0] ) );
577    memset( m_apiMVPIdx[1]      + firstElement, -1,                       numElements * sizeof( *m_apiMVPIdx[1] ) );
578    memset( m_apiMVPNum[0]      + firstElement, -1,                       numElements * sizeof( *m_apiMVPNum[0] ) );
579    memset( m_apiMVPNum[1]      + firstElement, -1,                       numElements * sizeof( *m_apiMVPNum[1] ) );
580    memset( m_phQP              + firstElement, getSlice()->getSliceQp(), numElements * sizeof( *m_phQP ) );
581    memset( m_pbMergeFlag       + firstElement, false,                    numElements * sizeof( *m_pbMergeFlag ) );
582    memset( m_puhMergeIndex     + firstElement, 0,                        numElements * sizeof( *m_puhMergeIndex ) );
583#if H_3D_VSP
584    memset( m_piVSPFlag         + firstElement, 0,                        numElements * sizeof( *m_piVSPFlag ) );
585#if MTK_VSP_FIX_E0172
586    memset( m_piVSPDir          + firstElement, 0,                        numElements * sizeof( *m_piVSPDir   ) );
587#endif
588#endif
589    memset( m_puhLumaIntraDir   + firstElement, DC_IDX,                   numElements * sizeof( *m_puhLumaIntraDir ) );
590    memset( m_puhChromaIntraDir + firstElement, 0,                        numElements * sizeof( *m_puhChromaIntraDir ) );
591    memset( m_puhInterDir       + firstElement, 0,                        numElements * sizeof( *m_puhInterDir ) );
592    memset( m_puhCbf[0]         + firstElement, 0,                        numElements * sizeof( *m_puhCbf[0] ) );
593    memset( m_puhCbf[1]         + firstElement, 0,                        numElements * sizeof( *m_puhCbf[1] ) );
594    memset( m_puhCbf[2]         + firstElement, 0,                        numElements * sizeof( *m_puhCbf[2] ) );
595    memset( m_pbIPCMFlag        + firstElement, false,                    numElements * sizeof( *m_pbIPCMFlag ) );
596#if H_3D_ARP
597    memset( m_puhARPW           + firstElement, 0,                        numElements * sizeof( UChar )         );
598#endif
599#if H_3D_IC
600    memset( m_pbICFlag          + firstElement, false,                    numElements * sizeof( *m_pbICFlag )   );
601#endif
602#if H_3D_DIM
603    for( Int i = 0; i < DIM_NUM_TYPE; i++ )
604    {
605      memset( m_dimDeltaDC[i][0] + firstElement, 0,                       numElements * sizeof( *m_dimDeltaDC[i][0] ) );
606      memset( m_dimDeltaDC[i][1] + firstElement, 0,                       numElements * sizeof( *m_dimDeltaDC[i][1] ) );
607    }
608#if H_3D_DIM_DMM
609    for( Int i = 0; i < DMM_NUM_TYPE; i++ )
610    {
611      memset( m_dmmWedgeTabIdx[i] + firstElement, 0,                      numElements * sizeof( *m_dmmWedgeTabIdx[i] ) );
612    }
613    memset( m_dmm2DeltaEnd      + firstElement, 0,                        numElements * sizeof( *m_dmm2DeltaEnd    ) );
614    memset( m_dmm3IntraTabIdx   + firstElement, 0,                        numElements * sizeof( *m_dmm3IntraTabIdx ) );
615#endif
616#if H_3D_DIM_RBC
617    memset( m_pucEdgeCode       + firstElement, 0,                        numElements * sizeof( *m_pucEdgeCode     ) * RBC_MAX_EDGE_NUM_PER_4x4 );
618    memset( m_pucEdgeNumber     + firstElement, 0,                        numElements * sizeof( *m_pucEdgeNumber   ) );
619    memset( m_pucEdgeStartPos   + firstElement, 0,                        numElements * sizeof( *m_pucEdgeStartPos ) );
620    memset( m_pbEdgeLeftFirst   + firstElement, false,                    numElements * sizeof( *m_pbEdgeLeftFirst ) );
621    memset( m_pbEdgePartition   + firstElement, false,                    numElements * sizeof( *m_pbEdgePartition ) * 16 );
622#endif
623#if H_3D_DIM_SDC
624    memset( m_pbSDCFlag             + firstElement,     0,                numElements * sizeof( *m_pbSDCFlag            ) );
625    memset( m_apSegmentDCOffset[0]  + firstElement,     0,                numElements * sizeof( *m_apSegmentDCOffset[0] ) );
626    memset( m_apSegmentDCOffset[1]  + firstElement,     0,                numElements * sizeof( *m_apSegmentDCOffset[1] ) );
627#endif
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#if MTK_VSP_FIX_E0172
761      m_piVSPDir  [ui] = 0;
762#endif
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      m_dmm2DeltaEnd    [ui] = 0;
788      m_dmm3IntraTabIdx [ui] = 0;
789#endif
790#if H_3D_DIM_SDC
791      m_pbSDCFlag           [ui] = false;
792      m_apSegmentDCOffset[0][ui] = 0;
793      m_apSegmentDCOffset[1][ui] = 0;
794#endif
795#endif
796    }
797  }
798
799  if(getPic()->getPicSym()->getInverseCUOrderMap(getAddr())*m_pcPic->getNumPartInCU()+m_uiAbsIdxInLCU >= getSlice()->getSliceSegmentCurStartCUAddr())
800  {
801    m_acCUMvField[0].clearMvField();
802    m_acCUMvField[1].clearMvField();
803    UInt uiTmp = uhWidth*uhHeight;
804   
805    memset( m_pcTrCoeffY,    0, uiTmp * sizeof( *m_pcTrCoeffY    ) );
806#if ADAPTIVE_QP_SELECTION
807    memset( m_pcArlCoeffY ,  0, uiTmp * sizeof( *m_pcArlCoeffY   ) );
808#endif
809    memset( m_pcIPCMSampleY, 0, uiTmp * sizeof( *m_pcIPCMSampleY ) );
810
811    uiTmp>>=2;
812    memset( m_pcTrCoeffCb,    0, uiTmp * sizeof( *m_pcTrCoeffCb    ) );
813    memset( m_pcTrCoeffCr,    0, uiTmp * sizeof( *m_pcTrCoeffCr    ) );
814#if ADAPTIVE_QP_SELECTION 
815    memset( m_pcArlCoeffCb,   0, uiTmp * sizeof( *m_pcArlCoeffCb   ) );
816    memset( m_pcArlCoeffCr,   0, uiTmp * sizeof( *m_pcArlCoeffCr   ) );
817#endif
818    memset( m_pcIPCMSampleCb, 0, uiTmp * sizeof( *m_pcIPCMSampleCb ) );
819    memset( m_pcIPCMSampleCr, 0, uiTmp * sizeof( *m_pcIPCMSampleCr ) );
820  }
821}
822
823
824// initialize Sub partition
825Void TComDataCU::initSubCU( TComDataCU* pcCU, UInt uiPartUnitIdx, UInt uiDepth, Int qp )
826{
827  assert( uiPartUnitIdx<4 );
828
829  UInt uiPartOffset = ( pcCU->getTotalNumPart()>>2 )*uiPartUnitIdx;
830
831  m_pcPic              = pcCU->getPic();
832  m_pcSlice            = m_pcPic->getSlice(m_pcPic->getCurrSliceIdx());
833  m_uiCUAddr           = pcCU->getAddr();
834  m_uiAbsIdxInLCU      = pcCU->getZorderIdxInCU() + uiPartOffset;
835
836  m_uiCUPelX           = pcCU->getCUPelX() + ( g_uiMaxCUWidth>>uiDepth  )*( uiPartUnitIdx &  1 );
837  m_uiCUPelY           = pcCU->getCUPelY() + ( g_uiMaxCUHeight>>uiDepth  )*( uiPartUnitIdx >> 1 );
838
839  m_dTotalCost         = MAX_DOUBLE;
840  m_uiTotalDistortion  = 0;
841  m_uiTotalBits        = 0;
842  m_uiTotalBins        = 0;
843  m_uiNumPartition     = pcCU->getTotalNumPart() >> 2;
844
845  Int iSizeInUchar = sizeof( UChar  ) * m_uiNumPartition;
846  Int iSizeInBool  = sizeof( Bool   ) * m_uiNumPartition;
847
848  Int sizeInChar = sizeof( Char  ) * m_uiNumPartition;
849  memset( m_phQP,              qp,  sizeInChar );
850
851  memset( m_pbMergeFlag,        0, iSizeInBool  );
852  memset( m_puhMergeIndex,      0, iSizeInUchar );
853#if H_3D_VSP
854  memset( m_piVSPFlag,          0, sizeof( Char  ) * m_uiNumPartition );
855#if MTK_VSP_FIX_E0172
856  memset( m_piVSPDir  ,         0, sizeInChar );
857#endif
858#endif
859  memset( m_puhLumaIntraDir,    DC_IDX, iSizeInUchar );
860  memset( m_puhChromaIntraDir,  0, iSizeInUchar );
861  memset( m_puhInterDir,        0, iSizeInUchar );
862  memset( m_puhTrIdx,           0, iSizeInUchar );
863  memset( m_puhTransformSkip[0], 0, iSizeInUchar );
864  memset( m_puhTransformSkip[1], 0, iSizeInUchar );
865  memset( m_puhTransformSkip[2], 0, iSizeInUchar );
866  memset( m_puhCbf[0],          0, iSizeInUchar );
867  memset( m_puhCbf[1],          0, iSizeInUchar );
868  memset( m_puhCbf[2],          0, iSizeInUchar );
869  memset( m_puhDepth,     uiDepth, iSizeInUchar );
870#if H_3D_NBDV
871  m_pDvInfo->bDV = false;
872#endif
873#if H_3D_ARP
874  memset( m_puhARPW,            0, iSizeInUchar  );
875#endif
876  UChar uhWidth  = g_uiMaxCUWidth  >> uiDepth;
877  UChar uhHeight = g_uiMaxCUHeight >> uiDepth;
878  memset( m_puhWidth,          uhWidth,  iSizeInUchar );
879  memset( m_puhHeight,         uhHeight, iSizeInUchar );
880  memset( m_pbIPCMFlag,        0, iSizeInBool  );
881#if H_3D_IC
882  memset( m_pbICFlag,          0, iSizeInBool  );
883#endif
884#if H_3D_DIM
885  for( Int i = 0; i < DIM_NUM_TYPE; i++ )
886  {
887    memset( m_dimDeltaDC[i][0], 0, sizeof(Pel ) * m_uiNumPartition );
888    memset( m_dimDeltaDC[i][1], 0, sizeof(Pel ) * m_uiNumPartition );
889  }
890#if H_3D_DIM_DMM
891  for( Int i = 0; i < DMM_NUM_TYPE; i++ )
892  {
893    memset( m_dmmWedgeTabIdx[i], 0, sizeof(UInt) * m_uiNumPartition );
894  }
895  memset( m_dmm2DeltaEnd   , 0, sizeof(Int ) * m_uiNumPartition );
896  memset( m_dmm3IntraTabIdx, 0, sizeof(UInt) * m_uiNumPartition );
897#endif
898#if H_3D_DIM_RBC
899  memset( m_pucEdgeCode    , 0, iSizeInUchar * RBC_MAX_EDGE_NUM_PER_4x4 );
900  memset( m_pucEdgeNumber  , 0, iSizeInUchar );
901  memset( m_pucEdgeStartPos, 0, iSizeInUchar );
902  memset( m_pbEdgeLeftFirst, 0, iSizeInBool );
903  memset( m_pbEdgePartition, 0, iSizeInBool * 16 );
904#endif
905#if H_3D_DIM_SDC
906  memset( m_pbSDCFlag,            0, sizeof(Bool) * m_uiNumPartition  );
907  memset( m_apSegmentDCOffset[0], 0, sizeof(Pel) * m_uiNumPartition   );
908  memset( m_apSegmentDCOffset[1], 0, sizeof(Pel) * m_uiNumPartition   );
909#endif
910#endif
911
912  for (UInt ui = 0; ui < m_uiNumPartition; ui++)
913  {
914    m_skipFlag[ui]   = false;
915    m_pePartSize[ui] = SIZE_NONE;
916    m_pePredMode[ui] = MODE_NONE;
917    m_CUTransquantBypass[ui] = false;
918    m_apiMVPIdx[0][ui] = -1;
919    m_apiMVPIdx[1][ui] = -1;
920    m_apiMVPNum[0][ui] = -1;
921    m_apiMVPNum[1][ui] = -1;
922    if(m_pcPic->getPicSym()->getInverseCUOrderMap(getAddr())*m_pcPic->getNumPartInCU()+m_uiAbsIdxInLCU+ui<getSlice()->getSliceSegmentCurStartCUAddr())
923    {
924      m_apiMVPIdx[0][ui] = pcCU->m_apiMVPIdx[0][uiPartOffset+ui];
925      m_apiMVPIdx[1][ui] = pcCU->m_apiMVPIdx[1][uiPartOffset+ui];;
926      m_apiMVPNum[0][ui] = pcCU->m_apiMVPNum[0][uiPartOffset+ui];;
927      m_apiMVPNum[1][ui] = pcCU->m_apiMVPNum[1][uiPartOffset+ui];;
928      m_puhDepth  [ui] = pcCU->getDepth(uiPartOffset+ui);
929      m_puhWidth  [ui] = pcCU->getWidth(uiPartOffset+ui);
930      m_puhHeight  [ui] = pcCU->getHeight(uiPartOffset+ui);
931      m_puhTrIdx  [ui] = pcCU->getTransformIdx(uiPartOffset+ui);
932      m_puhTransformSkip[0][ui] = pcCU->getTransformSkip(uiPartOffset+ui,TEXT_LUMA);
933      m_puhTransformSkip[1][ui] = pcCU->getTransformSkip(uiPartOffset+ui,TEXT_CHROMA_U);
934      m_puhTransformSkip[2][ui] = pcCU->getTransformSkip(uiPartOffset+ui,TEXT_CHROMA_V);
935      m_skipFlag[ui]   = pcCU->getSkipFlag(uiPartOffset+ui);
936      m_pePartSize[ui] = pcCU->getPartitionSize(uiPartOffset+ui);
937      m_pePredMode[ui] = pcCU->getPredictionMode(uiPartOffset+ui);
938      m_CUTransquantBypass[ui] = pcCU->getCUTransquantBypass(uiPartOffset+ui);
939      m_pbIPCMFlag[ui]=pcCU->m_pbIPCMFlag[uiPartOffset+ui];
940      m_phQP[ui] = pcCU->m_phQP[uiPartOffset+ui];
941      m_pbMergeFlag[ui]=pcCU->m_pbMergeFlag[uiPartOffset+ui];
942      m_puhMergeIndex[ui]=pcCU->m_puhMergeIndex[uiPartOffset+ui];
943#if H_3D_VSP
944      m_piVSPFlag[ui]=pcCU->m_piVSPFlag[uiPartOffset+ui];
945#if MTK_VSP_FIX_E0172
946      m_piVSPDir[ui]=pcCU->m_piVSPDir[uiPartOffset+ui];
947#endif
948#endif
949      m_puhLumaIntraDir[ui]=pcCU->m_puhLumaIntraDir[uiPartOffset+ui];
950      m_puhChromaIntraDir[ui]=pcCU->m_puhChromaIntraDir[uiPartOffset+ui];
951      m_puhInterDir[ui]=pcCU->m_puhInterDir[uiPartOffset+ui];
952      m_puhCbf[0][ui]=pcCU->m_puhCbf[0][uiPartOffset+ui];
953      m_puhCbf[1][ui]=pcCU->m_puhCbf[1][uiPartOffset+ui];
954      m_puhCbf[2][ui]=pcCU->m_puhCbf[2][uiPartOffset+ui];
955
956#if H_3D_ARP
957      m_puhARPW           [ui] = pcCU->getARPW( uiPartOffset+ui );
958#endif
959#if H_3D_IC
960      m_pbICFlag          [ui] = pcCU->m_pbICFlag[uiPartOffset+ui];
961#endif
962#if H_3D_DIM
963      for( Int i = 0; i < DIM_NUM_TYPE; i++ )
964      {
965        m_dimDeltaDC[i][0] [ui] = pcCU->m_dimDeltaDC[i][0] [uiPartOffset+ui];
966        m_dimDeltaDC[i][1] [ui] = pcCU->m_dimDeltaDC[i][1] [uiPartOffset+ui];
967      }
968#if H_3D_DIM_DMM
969      for( Int i = 0; i < DMM_NUM_TYPE; i++ )
970      {
971        m_dmmWedgeTabIdx[i] [ui] = pcCU->m_dmmWedgeTabIdx[i] [uiPartOffset+ui];
972      }
973      m_dmm2DeltaEnd    [ui] = pcCU->m_dmm2DeltaEnd   [uiPartOffset+ui];
974      m_dmm3IntraTabIdx [ui] = pcCU->m_dmm3IntraTabIdx[uiPartOffset+ui];
975#endif
976#if H_3D_DIM_SDC
977      m_pbSDCFlag           [ui] = pcCU->m_pbSDCFlag            [ uiPartOffset + ui ];
978      m_apSegmentDCOffset[0][ui] = pcCU->m_apSegmentDCOffset[0] [ uiPartOffset + ui ];
979      m_apSegmentDCOffset[1][ui] = pcCU->m_apSegmentDCOffset[1] [ uiPartOffset + ui ];
980#endif
981#endif
982    }
983  }
984  UInt uiTmp = uhWidth*uhHeight;
985  memset( m_pcTrCoeffY , 0, sizeof(TCoeff)*uiTmp );
986#if ADAPTIVE_QP_SELECTION 
987  memset( m_pcArlCoeffY , 0, sizeof(Int)*uiTmp );
988#endif
989  memset( m_pcIPCMSampleY , 0, sizeof( Pel ) * uiTmp );
990  uiTmp >>= 2;
991  memset( m_pcTrCoeffCb, 0, sizeof(TCoeff)*uiTmp );
992  memset( m_pcTrCoeffCr, 0, sizeof(TCoeff)*uiTmp );
993#if ADAPTIVE_QP_SELECTION
994  memset( m_pcArlCoeffCb, 0, sizeof(Int)*uiTmp );
995  memset( m_pcArlCoeffCr, 0, sizeof(Int)*uiTmp );
996#endif
997  memset( m_pcIPCMSampleCb , 0, sizeof( Pel ) * uiTmp );
998  memset( m_pcIPCMSampleCr , 0, sizeof( Pel ) * uiTmp );
999  m_acCUMvField[0].clearMvField();
1000  m_acCUMvField[1].clearMvField();
1001
1002  if(m_pcPic->getPicSym()->getInverseCUOrderMap(getAddr())*m_pcPic->getNumPartInCU()+m_uiAbsIdxInLCU<getSlice()->getSliceSegmentCurStartCUAddr())
1003  {
1004    // Part of this CU contains data from an older slice. Now copy in that data.
1005    UInt uiMaxCuWidth=pcCU->getSlice()->getSPS()->getMaxCUWidth();
1006    UInt uiMaxCuHeight=pcCU->getSlice()->getSPS()->getMaxCUHeight();
1007    TComDataCU * bigCU = getPic()->getCU(getAddr());
1008    Int minui = uiPartOffset;
1009    minui = -minui;
1010    pcCU->m_acCUMvField[0].copyTo(&m_acCUMvField[0],minui,uiPartOffset,m_uiNumPartition);
1011    pcCU->m_acCUMvField[1].copyTo(&m_acCUMvField[1],minui,uiPartOffset,m_uiNumPartition);
1012    UInt uiCoffOffset = uiMaxCuWidth*uiMaxCuHeight*m_uiAbsIdxInLCU/pcCU->getPic()->getNumPartInCU();
1013    uiTmp = uhWidth*uhHeight;
1014    for(Int i=0; i<uiTmp; i++)
1015    {
1016      m_pcTrCoeffY[i]=bigCU->m_pcTrCoeffY[uiCoffOffset+i];
1017#if ADAPTIVE_QP_SELECTION
1018      m_pcArlCoeffY[i]=bigCU->m_pcArlCoeffY[uiCoffOffset+i];
1019#endif
1020      m_pcIPCMSampleY[i]=bigCU->m_pcIPCMSampleY[uiCoffOffset+i];
1021    }
1022    uiTmp>>=2;
1023    uiCoffOffset>>=2;
1024    for(Int i=0; i<uiTmp; i++)
1025    {
1026      m_pcTrCoeffCr[i]=bigCU->m_pcTrCoeffCr[uiCoffOffset+i];
1027      m_pcTrCoeffCb[i]=bigCU->m_pcTrCoeffCb[uiCoffOffset+i];
1028#if ADAPTIVE_QP_SELECTION
1029      m_pcArlCoeffCr[i]=bigCU->m_pcArlCoeffCr[uiCoffOffset+i];
1030      m_pcArlCoeffCb[i]=bigCU->m_pcArlCoeffCb[uiCoffOffset+i];
1031#endif
1032      m_pcIPCMSampleCb[i]=bigCU->m_pcIPCMSampleCb[uiCoffOffset+i];
1033      m_pcIPCMSampleCr[i]=bigCU->m_pcIPCMSampleCr[uiCoffOffset+i];
1034    }
1035  }
1036
1037  m_pcCULeft        = pcCU->getCULeft();
1038  m_pcCUAbove       = pcCU->getCUAbove();
1039  m_pcCUAboveLeft   = pcCU->getCUAboveLeft();
1040  m_pcCUAboveRight  = pcCU->getCUAboveRight();
1041
1042  m_apcCUColocated[0] = pcCU->getCUColocated(REF_PIC_LIST_0);
1043  m_apcCUColocated[1] = pcCU->getCUColocated(REF_PIC_LIST_1);
1044  memcpy(m_sliceStartCU,pcCU->m_sliceStartCU+uiPartOffset,sizeof(UInt)*m_uiNumPartition);
1045  memcpy(m_sliceSegmentStartCU,pcCU->m_sliceSegmentStartCU+uiPartOffset,sizeof(UInt)*m_uiNumPartition);
1046}
1047
1048Void TComDataCU::setOutsideCUPart( UInt uiAbsPartIdx, UInt uiDepth )
1049{
1050  UInt uiNumPartition = m_uiNumPartition >> (uiDepth << 1);
1051  UInt uiSizeInUchar = sizeof( UChar  ) * uiNumPartition;
1052
1053  UChar uhWidth  = g_uiMaxCUWidth  >> uiDepth;
1054  UChar uhHeight = g_uiMaxCUHeight >> uiDepth;
1055  memset( m_puhDepth    + uiAbsPartIdx,     uiDepth,  uiSizeInUchar );
1056  memset( m_puhWidth    + uiAbsPartIdx,     uhWidth,  uiSizeInUchar );
1057  memset( m_puhHeight   + uiAbsPartIdx,     uhHeight, uiSizeInUchar );
1058}
1059
1060// --------------------------------------------------------------------------------------------------------------------
1061// Copy
1062// --------------------------------------------------------------------------------------------------------------------
1063
1064Void TComDataCU::copySubCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1065{
1066  UInt uiPart = uiAbsPartIdx;
1067 
1068  m_pcPic              = pcCU->getPic();
1069  m_pcSlice            = pcCU->getSlice();
1070  m_uiCUAddr           = pcCU->getAddr();
1071  m_uiAbsIdxInLCU      = uiAbsPartIdx;
1072 
1073  m_uiCUPelX           = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
1074  m_uiCUPelY           = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
1075 
1076  m_skipFlag=pcCU->getSkipFlag()          + uiPart;
1077
1078  m_phQP=pcCU->getQP()                    + uiPart;
1079  m_pePartSize = pcCU->getPartitionSize() + uiPart;
1080  m_pePredMode=pcCU->getPredictionMode()  + uiPart;
1081  m_CUTransquantBypass  = pcCU->getCUTransquantBypass()+uiPart;
1082 
1083#if H_3D_NBDV
1084  m_pDvInfo             = pcCU->getDvInfo()           + uiPart;
1085#endif
1086  m_pbMergeFlag         = pcCU->getMergeFlag()        + uiPart;
1087  m_puhMergeIndex       = pcCU->getMergeIndex()       + uiPart;
1088#if H_3D_VSP
1089  m_piVSPFlag           = pcCU->getVSPFlag()          + uiPart;
1090#if MTK_VSP_FIX_E0172
1091  m_piVSPDir            = pcCU->getVSPDir  ()         + uiPart;
1092#endif
1093#endif
1094
1095#if H_3D_ARP
1096  m_puhARPW             = pcCU->getARPW()             + uiPart;
1097#endif
1098#if H_3D_IC
1099  m_pbICFlag            = pcCU->getICFlag()           + uiPart;
1100#endif
1101
1102  m_puhLumaIntraDir     = pcCU->getLumaIntraDir()     + uiPart;
1103  m_puhChromaIntraDir   = pcCU->getChromaIntraDir()   + uiPart;
1104  m_puhInterDir         = pcCU->getInterDir()         + uiPart;
1105  m_puhTrIdx            = pcCU->getTransformIdx()     + uiPart;
1106  m_puhTransformSkip[0] = pcCU->getTransformSkip(TEXT_LUMA)     + uiPart;
1107  m_puhTransformSkip[1] = pcCU->getTransformSkip(TEXT_CHROMA_U) + uiPart;
1108  m_puhTransformSkip[2] = pcCU->getTransformSkip(TEXT_CHROMA_V) + uiPart;
1109
1110  m_puhCbf[0]= pcCU->getCbf(TEXT_LUMA)            + uiPart;
1111  m_puhCbf[1]= pcCU->getCbf(TEXT_CHROMA_U)        + uiPart;
1112  m_puhCbf[2]= pcCU->getCbf(TEXT_CHROMA_V)        + uiPart;
1113#if H_3D_DIM
1114  for( Int i = 0; i < DIM_NUM_TYPE; i++ )
1115  {
1116    m_dimDeltaDC[i][0] = pcCU->getDimDeltaDC( i, 0 ) + uiPart;
1117    m_dimDeltaDC[i][1] = pcCU->getDimDeltaDC( i, 1 ) + uiPart;
1118  }
1119#if H_3D_DIM_DMM
1120  for( Int i = 0; i < DMM_NUM_TYPE; i++ )
1121  {
1122    m_dmmWedgeTabIdx[i] = pcCU->getDmmWedgeTabIdx( i ) + uiPart;
1123  }
1124  m_dmm2DeltaEnd    = pcCU->getDmm2DeltaEnd()    + uiPart;
1125  m_dmm3IntraTabIdx = pcCU->getDmm3IntraTabIdx() + uiPart;
1126#endif
1127#if H_3D_DIM_RBC
1128  m_pucEdgeCode     = pcCU->getEdgeCode( uiPart );
1129  m_pucEdgeNumber   = pcCU->getEdgeNumber()      + uiPart;
1130  m_pucEdgeStartPos = pcCU->getEdgeStartPos()    + uiPart;
1131  m_pbEdgeLeftFirst = pcCU->getEdgeLeftFirst()   + uiPart;
1132  m_pbEdgePartition = pcCU->getEdgePartition( uiPart );
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  m_puhDepth=pcCU->getDepth()                     + uiPart;
1141  m_puhWidth=pcCU->getWidth()                     + uiPart;
1142  m_puhHeight=pcCU->getHeight()                   + uiPart;
1143 
1144  m_apiMVPIdx[0]=pcCU->getMVPIdx(REF_PIC_LIST_0)  + uiPart;
1145  m_apiMVPIdx[1]=pcCU->getMVPIdx(REF_PIC_LIST_1)  + uiPart;
1146  m_apiMVPNum[0]=pcCU->getMVPNum(REF_PIC_LIST_0)  + uiPart;
1147  m_apiMVPNum[1]=pcCU->getMVPNum(REF_PIC_LIST_1)  + uiPart;
1148 
1149  m_pbIPCMFlag         = pcCU->getIPCMFlag()        + uiPart;
1150
1151  m_pcCUAboveLeft      = pcCU->getCUAboveLeft();
1152  m_pcCUAboveRight     = pcCU->getCUAboveRight();
1153  m_pcCUAbove          = pcCU->getCUAbove();
1154  m_pcCULeft           = pcCU->getCULeft();
1155 
1156  m_apcCUColocated[0] = pcCU->getCUColocated(REF_PIC_LIST_0);
1157  m_apcCUColocated[1] = pcCU->getCUColocated(REF_PIC_LIST_1);
1158 
1159  UInt uiMaxCuWidth=pcCU->getSlice()->getSPS()->getMaxCUWidth();
1160  UInt uiMaxCuHeight=pcCU->getSlice()->getSPS()->getMaxCUHeight();
1161 
1162  UInt uiCoffOffset = uiMaxCuWidth*uiMaxCuHeight*uiAbsPartIdx/pcCU->getPic()->getNumPartInCU();
1163 
1164  m_pcTrCoeffY = pcCU->getCoeffY() + uiCoffOffset;
1165#if ADAPTIVE_QP_SELECTION
1166  m_pcArlCoeffY= pcCU->getArlCoeffY() + uiCoffOffset; 
1167#endif
1168  m_pcIPCMSampleY = pcCU->getPCMSampleY() + uiCoffOffset;
1169
1170  uiCoffOffset >>=2;
1171  m_pcTrCoeffCb=pcCU->getCoeffCb() + uiCoffOffset;
1172  m_pcTrCoeffCr=pcCU->getCoeffCr() + uiCoffOffset;
1173#if ADAPTIVE_QP_SELECTION 
1174  m_pcArlCoeffCb=pcCU->getArlCoeffCb() + uiCoffOffset;
1175  m_pcArlCoeffCr=pcCU->getArlCoeffCr() + uiCoffOffset;
1176#endif
1177  m_pcIPCMSampleCb = pcCU->getPCMSampleCb() + uiCoffOffset;
1178  m_pcIPCMSampleCr = pcCU->getPCMSampleCr() + uiCoffOffset;
1179
1180  m_acCUMvField[0].linkToWithOffset( pcCU->getCUMvField(REF_PIC_LIST_0), uiPart );
1181  m_acCUMvField[1].linkToWithOffset( pcCU->getCUMvField(REF_PIC_LIST_1), uiPart );
1182  memcpy(m_sliceStartCU,pcCU->m_sliceStartCU+uiPart,sizeof(UInt)*m_uiNumPartition);
1183  memcpy(m_sliceSegmentStartCU,pcCU->m_sliceSegmentStartCU+uiPart,sizeof(UInt)*m_uiNumPartition);
1184}
1185#if H_3D_NBDV
1186Void TComDataCU::copyDVInfoFrom (TComDataCU* pcCU, UInt uiAbsPartIdx)
1187{
1188  m_pDvInfo            = pcCU->getDvInfo()                + uiAbsPartIdx;
1189}
1190#endif
1191// Copy inter prediction info from the biggest CU
1192Void TComDataCU::copyInterPredInfoFrom    ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefPicList
1193#if H_3D_NBDV
1194  , Bool bNBDV
1195#endif
1196  )
1197{
1198  m_pcPic              = pcCU->getPic();
1199  m_pcSlice            = pcCU->getSlice();
1200  m_uiCUAddr           = pcCU->getAddr();
1201  m_uiAbsIdxInLCU      = uiAbsPartIdx;
1202 
1203  Int iRastPartIdx     = g_auiZscanToRaster[uiAbsPartIdx];
1204  m_uiCUPelX           = pcCU->getCUPelX() + m_pcPic->getMinCUWidth ()*( iRastPartIdx % m_pcPic->getNumPartInWidth() );
1205  m_uiCUPelY           = pcCU->getCUPelY() + m_pcPic->getMinCUHeight()*( iRastPartIdx / m_pcPic->getNumPartInWidth() );
1206 
1207  m_pcCUAboveLeft      = pcCU->getCUAboveLeft();
1208  m_pcCUAboveRight     = pcCU->getCUAboveRight();
1209  m_pcCUAbove          = pcCU->getCUAbove();
1210  m_pcCULeft           = pcCU->getCULeft();
1211 
1212  m_apcCUColocated[0]  = pcCU->getCUColocated(REF_PIC_LIST_0);
1213  m_apcCUColocated[1]  = pcCU->getCUColocated(REF_PIC_LIST_1);
1214 
1215  m_skipFlag           = pcCU->getSkipFlag ()             + uiAbsPartIdx;
1216
1217  m_pePartSize         = pcCU->getPartitionSize ()        + uiAbsPartIdx;
1218#if H_3D_NBDV
1219  if(bNBDV == true)
1220  {
1221    m_puhWidth           = pcCU->getWidth ()                + uiAbsPartIdx;
1222    m_puhHeight          = pcCU->getHeight()                + uiAbsPartIdx;
1223    m_puhDepth           = pcCU->getDepth ()                + uiAbsPartIdx;
1224  }
1225  else
1226  {
1227#endif
1228  m_pePredMode         = pcCU->getPredictionMode()        + uiAbsPartIdx;
1229  m_CUTransquantBypass = pcCU->getCUTransquantBypass()    + uiAbsPartIdx;
1230  m_puhInterDir        = pcCU->getInterDir      ()        + uiAbsPartIdx;
1231 
1232  m_puhDepth           = pcCU->getDepth ()                + uiAbsPartIdx;
1233  m_puhWidth           = pcCU->getWidth ()                + uiAbsPartIdx;
1234  m_puhHeight          = pcCU->getHeight()                + uiAbsPartIdx;
1235 
1236  m_pbMergeFlag        = pcCU->getMergeFlag()             + uiAbsPartIdx;
1237  m_puhMergeIndex      = pcCU->getMergeIndex()            + uiAbsPartIdx;
1238#if H_3D_VSP
1239  m_piVSPFlag          = pcCU->getVSPFlag()               + uiAbsPartIdx;
1240#if MTK_VSP_FIX_E0172
1241  m_piVSPDir           = pcCU->getVSPDir  ()              + uiAbsPartIdx;
1242#endif
1243#endif
1244
1245  m_apiMVPIdx[eRefPicList] = pcCU->getMVPIdx(eRefPicList) + uiAbsPartIdx;
1246  m_apiMVPNum[eRefPicList] = pcCU->getMVPNum(eRefPicList) + uiAbsPartIdx;
1247 
1248#if H_3D_ARP
1249  m_puhARPW            = pcCU->getARPW()                  + uiAbsPartIdx;
1250#endif
1251
1252  m_acCUMvField[ eRefPicList ].linkToWithOffset( pcCU->getCUMvField(eRefPicList), uiAbsPartIdx );
1253
1254  memcpy(m_sliceStartCU,pcCU->m_sliceStartCU+uiAbsPartIdx,sizeof(UInt)*m_uiNumPartition);
1255  memcpy(m_sliceSegmentStartCU,pcCU->m_sliceSegmentStartCU+uiAbsPartIdx,sizeof(UInt)*m_uiNumPartition);
1256#if H_3D_NBDV
1257  }
1258#endif
1259#if H_3D_IC
1260  m_pbICFlag           = pcCU->getICFlag()                + uiAbsPartIdx;
1261#endif
1262}
1263
1264// Copy small CU to bigger CU.
1265// One of quarter parts overwritten by predicted sub part.
1266Void TComDataCU::copyPartFrom( TComDataCU* pcCU, UInt uiPartUnitIdx, UInt uiDepth )
1267{
1268  assert( uiPartUnitIdx<4 );
1269 
1270  m_dTotalCost         += pcCU->getTotalCost();
1271  m_uiTotalDistortion  += pcCU->getTotalDistortion();
1272  m_uiTotalBits        += pcCU->getTotalBits();
1273 
1274  UInt uiOffset         = pcCU->getTotalNumPart()*uiPartUnitIdx;
1275 
1276  UInt uiNumPartition = pcCU->getTotalNumPart();
1277  Int iSizeInUchar  = sizeof( UChar ) * uiNumPartition;
1278  Int iSizeInBool   = sizeof( Bool  ) * uiNumPartition;
1279 
1280  Int sizeInChar  = sizeof( Char ) * uiNumPartition;
1281  memcpy( m_skipFlag   + uiOffset, pcCU->getSkipFlag(),       sizeof( *m_skipFlag )   * uiNumPartition );
1282  memcpy( m_phQP       + uiOffset, pcCU->getQP(),             sizeInChar                        );
1283  memcpy( m_pePartSize + uiOffset, pcCU->getPartitionSize(),  sizeof( *m_pePartSize ) * uiNumPartition );
1284  memcpy( m_pePredMode + uiOffset, pcCU->getPredictionMode(), sizeof( *m_pePredMode ) * uiNumPartition );
1285  memcpy( m_CUTransquantBypass + uiOffset, pcCU->getCUTransquantBypass(), sizeof( *m_CUTransquantBypass ) * uiNumPartition );
1286  memcpy( m_pbMergeFlag         + uiOffset, pcCU->getMergeFlag(),         iSizeInBool  );
1287  memcpy( m_puhMergeIndex       + uiOffset, pcCU->getMergeIndex(),        iSizeInUchar );
1288#if H_3D_VSP
1289  memcpy( m_piVSPFlag           + uiOffset, pcCU->getVSPFlag(),           sizeof( Char ) * uiNumPartition );
1290#if MTK_VSP_FIX_E0172
1291  memcpy( m_piVSPDir            + uiOffset, pcCU->getVSPDir  (),          sizeInChar );
1292#endif
1293#endif
1294  memcpy( m_puhLumaIntraDir     + uiOffset, pcCU->getLumaIntraDir(),      iSizeInUchar );
1295  memcpy( m_puhChromaIntraDir   + uiOffset, pcCU->getChromaIntraDir(),    iSizeInUchar );
1296  memcpy( m_puhInterDir         + uiOffset, pcCU->getInterDir(),          iSizeInUchar );
1297  memcpy( m_puhTrIdx            + uiOffset, pcCU->getTransformIdx(),      iSizeInUchar );
1298  memcpy( m_puhTransformSkip[0] + uiOffset, pcCU->getTransformSkip(TEXT_LUMA),     iSizeInUchar );
1299  memcpy( m_puhTransformSkip[1] + uiOffset, pcCU->getTransformSkip(TEXT_CHROMA_U), iSizeInUchar );
1300  memcpy( m_puhTransformSkip[2] + uiOffset, pcCU->getTransformSkip(TEXT_CHROMA_V), iSizeInUchar );
1301
1302  memcpy( m_puhCbf[0] + uiOffset, pcCU->getCbf(TEXT_LUMA)    , iSizeInUchar );
1303  memcpy( m_puhCbf[1] + uiOffset, pcCU->getCbf(TEXT_CHROMA_U), iSizeInUchar );
1304  memcpy( m_puhCbf[2] + uiOffset, pcCU->getCbf(TEXT_CHROMA_V), iSizeInUchar );
1305 
1306#if H_3D_DIM
1307  for( Int i = 0; i < DIM_NUM_TYPE; i++ )
1308  {
1309    memcpy( m_dimDeltaDC[i][0] + uiOffset, pcCU->getDimDeltaDC( i, 0 ), sizeof(Pel ) * uiNumPartition );
1310    memcpy( m_dimDeltaDC[i][1] + uiOffset, pcCU->getDimDeltaDC( i, 1 ), sizeof(Pel ) * uiNumPartition );
1311  }
1312#if H_3D_DIM_DMM
1313  for( Int i = 0; i < DMM_NUM_TYPE; i++ )
1314  {
1315    memcpy( m_dmmWedgeTabIdx[i] + uiOffset, pcCU->getDmmWedgeTabIdx( i ), sizeof(UInt) * uiNumPartition );
1316  }
1317  memcpy( m_dmm2DeltaEnd    + uiOffset, pcCU->getDmm2DeltaEnd()   , sizeof(Int ) * uiNumPartition );
1318  memcpy( m_dmm3IntraTabIdx + uiOffset, pcCU->getDmm3IntraTabIdx(), sizeof(UInt) * uiNumPartition );
1319#endif
1320#if H_3D_DIM_RBC
1321  memcpy( getEdgeCode( uiOffset ),       pcCU->getEdgeCode(0),      iSizeInUchar * RBC_MAX_EDGE_NUM_PER_4x4 );
1322  memcpy( getEdgeNumber()    + uiOffset, pcCU->getEdgeNumber(),     iSizeInUchar );
1323  memcpy( getEdgeStartPos()  + uiOffset, pcCU->getEdgeStartPos(),   iSizeInUchar );
1324  memcpy( getEdgeLeftFirst() + uiOffset, pcCU->getEdgeLeftFirst(),  iSizeInBool );
1325  memcpy( getEdgePartition( uiOffset ),  pcCU->getEdgePartition(0), iSizeInBool * 16 );
1326#endif
1327#if H_3D_DIM_SDC
1328  memcpy( m_pbSDCFlag             + uiOffset, pcCU->getSDCFlag(),             iSizeInBool  );
1329  memcpy( m_apSegmentDCOffset[0]  + uiOffset, pcCU->getSDCSegmentDCOffset(0), sizeof( Pel ) * uiNumPartition);
1330  memcpy( m_apSegmentDCOffset[1]  + uiOffset, pcCU->getSDCSegmentDCOffset(1), sizeof( Pel ) * uiNumPartition);
1331#endif
1332#endif
1333
1334  memcpy( m_puhDepth  + uiOffset, pcCU->getDepth(),  iSizeInUchar );
1335  memcpy( m_puhWidth  + uiOffset, pcCU->getWidth(),  iSizeInUchar );
1336  memcpy( m_puhHeight + uiOffset, pcCU->getHeight(), iSizeInUchar );
1337 
1338  memcpy( m_apiMVPIdx[0] + uiOffset, pcCU->getMVPIdx(REF_PIC_LIST_0), iSizeInUchar );
1339  memcpy( m_apiMVPIdx[1] + uiOffset, pcCU->getMVPIdx(REF_PIC_LIST_1), iSizeInUchar );
1340  memcpy( m_apiMVPNum[0] + uiOffset, pcCU->getMVPNum(REF_PIC_LIST_0), iSizeInUchar );
1341  memcpy( m_apiMVPNum[1] + uiOffset, pcCU->getMVPNum(REF_PIC_LIST_1), iSizeInUchar );
1342 
1343  memcpy( m_pbIPCMFlag + uiOffset, pcCU->getIPCMFlag(), iSizeInBool );
1344
1345  m_pcCUAboveLeft      = pcCU->getCUAboveLeft();
1346  m_pcCUAboveRight     = pcCU->getCUAboveRight();
1347  m_pcCUAbove          = pcCU->getCUAbove();
1348  m_pcCULeft           = pcCU->getCULeft();
1349 
1350  m_apcCUColocated[0] = pcCU->getCUColocated(REF_PIC_LIST_0);
1351  m_apcCUColocated[1] = pcCU->getCUColocated(REF_PIC_LIST_1);
1352 
1353  m_acCUMvField[0].copyFrom( pcCU->getCUMvField( REF_PIC_LIST_0 ), pcCU->getTotalNumPart(), uiOffset );
1354  m_acCUMvField[1].copyFrom( pcCU->getCUMvField( REF_PIC_LIST_1 ), pcCU->getTotalNumPart(), uiOffset );
1355 
1356  UInt uiTmp  = g_uiMaxCUWidth*g_uiMaxCUHeight >> (uiDepth<<1);
1357  UInt uiTmp2 = uiPartUnitIdx*uiTmp;
1358  memcpy( m_pcTrCoeffY  + uiTmp2, pcCU->getCoeffY(),  sizeof(TCoeff)*uiTmp );
1359#if ADAPTIVE_QP_SELECTION
1360  memcpy( m_pcArlCoeffY  + uiTmp2, pcCU->getArlCoeffY(),  sizeof(Int)*uiTmp );
1361#endif
1362  memcpy( m_pcIPCMSampleY + uiTmp2 , pcCU->getPCMSampleY(), sizeof(Pel) * uiTmp );
1363
1364  uiTmp >>= 2; uiTmp2>>= 2;
1365  memcpy( m_pcTrCoeffCb + uiTmp2, pcCU->getCoeffCb(), sizeof(TCoeff)*uiTmp );
1366  memcpy( m_pcTrCoeffCr + uiTmp2, pcCU->getCoeffCr(), sizeof(TCoeff)*uiTmp );
1367#if ADAPTIVE_QP_SELECTION
1368  memcpy( m_pcArlCoeffCb + uiTmp2, pcCU->getArlCoeffCb(), sizeof(Int)*uiTmp );
1369  memcpy( m_pcArlCoeffCr + uiTmp2, pcCU->getArlCoeffCr(), sizeof(Int)*uiTmp );
1370#endif
1371  memcpy( m_pcIPCMSampleCb + uiTmp2 , pcCU->getPCMSampleCb(), sizeof(Pel) * uiTmp );
1372  memcpy( m_pcIPCMSampleCr + uiTmp2 , pcCU->getPCMSampleCr(), sizeof(Pel) * uiTmp );
1373  m_uiTotalBins += pcCU->getTotalBins();
1374  memcpy( m_sliceStartCU        + uiOffset, pcCU->m_sliceStartCU,        sizeof( UInt ) * uiNumPartition  );
1375  memcpy( m_sliceSegmentStartCU + uiOffset, pcCU->m_sliceSegmentStartCU, sizeof( UInt ) * uiNumPartition  );
1376#if H_3D_ARP
1377  memcpy( m_puhARPW             + uiOffset, pcCU->getARPW(),              iSizeInUchar );
1378#endif
1379#if H_3D_IC
1380  memcpy( m_pbICFlag            + uiOffset, pcCU->getICFlag(),            iSizeInBool );
1381#endif
1382}
1383
1384// Copy current predicted part to a CU in picture.
1385// It is used to predict for next part
1386Void TComDataCU::copyToPic( UChar uhDepth )
1387{
1388  TComDataCU*& rpcCU = m_pcPic->getCU( m_uiCUAddr );
1389 
1390  rpcCU->getTotalCost()       = m_dTotalCost;
1391  rpcCU->getTotalDistortion() = m_uiTotalDistortion;
1392  rpcCU->getTotalBits()       = m_uiTotalBits;
1393 
1394  Int iSizeInUchar  = sizeof( UChar ) * m_uiNumPartition;
1395  Int iSizeInBool   = sizeof( Bool  ) * m_uiNumPartition;
1396 
1397  Int sizeInChar  = sizeof( Char ) * m_uiNumPartition;
1398
1399  memcpy( rpcCU->getSkipFlag() + m_uiAbsIdxInLCU, m_skipFlag, sizeof( *m_skipFlag ) * m_uiNumPartition );
1400
1401  memcpy( rpcCU->getQP() + m_uiAbsIdxInLCU, m_phQP, sizeInChar  );
1402#if H_3D_NBDV
1403  memcpy( rpcCU->getDvInfo()         + m_uiAbsIdxInLCU, m_pDvInfo,    sizeof(* m_pDvInfo)     * m_uiNumPartition );
1404#endif
1405
1406  memcpy( rpcCU->getPartitionSize()  + m_uiAbsIdxInLCU, m_pePartSize, sizeof( *m_pePartSize ) * m_uiNumPartition );
1407  memcpy( rpcCU->getPredictionMode() + m_uiAbsIdxInLCU, m_pePredMode, sizeof( *m_pePredMode ) * m_uiNumPartition );
1408  memcpy( rpcCU->getCUTransquantBypass()+ m_uiAbsIdxInLCU, m_CUTransquantBypass, sizeof( *m_CUTransquantBypass ) * m_uiNumPartition );
1409  memcpy( rpcCU->getMergeFlag()         + m_uiAbsIdxInLCU, m_pbMergeFlag,         iSizeInBool  );
1410  memcpy( rpcCU->getMergeIndex()        + m_uiAbsIdxInLCU, m_puhMergeIndex,       iSizeInUchar );
1411#if H_3D_VSP
1412  memcpy( rpcCU->getVSPFlag()           + m_uiAbsIdxInLCU, m_piVSPFlag,           sizeof( Char ) * m_uiNumPartition );
1413#if MTK_VSP_FIX_E0172
1414  memcpy( rpcCU->getVSPDir  ()          + m_uiAbsIdxInLCU, m_piVSPDir  ,          sizeInChar );
1415#endif
1416#endif
1417  memcpy( rpcCU->getLumaIntraDir()      + m_uiAbsIdxInLCU, m_puhLumaIntraDir,     iSizeInUchar );
1418  memcpy( rpcCU->getChromaIntraDir()    + m_uiAbsIdxInLCU, m_puhChromaIntraDir,   iSizeInUchar );
1419  memcpy( rpcCU->getInterDir()          + m_uiAbsIdxInLCU, m_puhInterDir,         iSizeInUchar );
1420  memcpy( rpcCU->getTransformIdx()      + m_uiAbsIdxInLCU, m_puhTrIdx,            iSizeInUchar );
1421  memcpy( rpcCU->getTransformSkip(TEXT_LUMA)     + m_uiAbsIdxInLCU, m_puhTransformSkip[0], iSizeInUchar );
1422  memcpy( rpcCU->getTransformSkip(TEXT_CHROMA_U) + m_uiAbsIdxInLCU, m_puhTransformSkip[1], iSizeInUchar );
1423  memcpy( rpcCU->getTransformSkip(TEXT_CHROMA_V) + m_uiAbsIdxInLCU, m_puhTransformSkip[2], iSizeInUchar );
1424
1425  memcpy( rpcCU->getCbf(TEXT_LUMA)     + m_uiAbsIdxInLCU, m_puhCbf[0], iSizeInUchar );
1426  memcpy( rpcCU->getCbf(TEXT_CHROMA_U) + m_uiAbsIdxInLCU, m_puhCbf[1], iSizeInUchar );
1427  memcpy( rpcCU->getCbf(TEXT_CHROMA_V) + m_uiAbsIdxInLCU, m_puhCbf[2], iSizeInUchar );
1428 
1429#if H_3D_DIM
1430  for( Int i = 0; i < DIM_NUM_TYPE; i++ )
1431  {
1432    memcpy( rpcCU->getDimDeltaDC( i, 0 ) + m_uiAbsIdxInLCU, m_dimDeltaDC[i][0], sizeof(Pel ) * m_uiNumPartition );
1433    memcpy( rpcCU->getDimDeltaDC( i, 1 ) + m_uiAbsIdxInLCU, m_dimDeltaDC[i][1], sizeof(Pel ) * m_uiNumPartition );
1434  }
1435#if H_3D_DIM_DMM
1436  for( Int i = 0; i < DMM_NUM_TYPE; i++ )
1437  {
1438    memcpy( rpcCU->getDmmWedgeTabIdx( i ) + m_uiAbsIdxInLCU, m_dmmWedgeTabIdx[i], sizeof(UInt) * m_uiNumPartition );
1439  }
1440  memcpy( rpcCU->getDmm2DeltaEnd()    + m_uiAbsIdxInLCU, m_dmm2DeltaEnd   , sizeof(Int ) * m_uiNumPartition );
1441  memcpy( rpcCU->getDmm3IntraTabIdx() + m_uiAbsIdxInLCU, m_dmm3IntraTabIdx, sizeof(UInt) * m_uiNumPartition );
1442#endif
1443#if H_3D_DIM_RBC
1444  memcpy( rpcCU->getEdgeCode( m_uiAbsIdxInLCU ),         m_pucEdgeCode,     iSizeInUchar * RBC_MAX_EDGE_NUM_PER_4x4 );
1445  memcpy( rpcCU->getEdgeNumber()      + m_uiAbsIdxInLCU, m_pucEdgeNumber,   iSizeInUchar );
1446  memcpy( rpcCU->getEdgeStartPos()    + m_uiAbsIdxInLCU, m_pucEdgeStartPos, iSizeInUchar );
1447  memcpy( rpcCU->getEdgeLeftFirst()   + m_uiAbsIdxInLCU, m_pbEdgeLeftFirst, iSizeInBool );
1448  memcpy( rpcCU->getEdgePartition( m_uiAbsIdxInLCU ),    m_pbEdgePartition, iSizeInBool * 16 );
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  memcpy( rpcCU->getDepth()  + m_uiAbsIdxInLCU, m_puhDepth,  iSizeInUchar );
1457  memcpy( rpcCU->getWidth()  + m_uiAbsIdxInLCU, m_puhWidth,  iSizeInUchar );
1458  memcpy( rpcCU->getHeight() + m_uiAbsIdxInLCU, m_puhHeight, iSizeInUchar );
1459 
1460  memcpy( rpcCU->getMVPIdx(REF_PIC_LIST_0) + m_uiAbsIdxInLCU, m_apiMVPIdx[0], iSizeInUchar );
1461  memcpy( rpcCU->getMVPIdx(REF_PIC_LIST_1) + m_uiAbsIdxInLCU, m_apiMVPIdx[1], iSizeInUchar );
1462  memcpy( rpcCU->getMVPNum(REF_PIC_LIST_0) + m_uiAbsIdxInLCU, m_apiMVPNum[0], iSizeInUchar );
1463  memcpy( rpcCU->getMVPNum(REF_PIC_LIST_1) + m_uiAbsIdxInLCU, m_apiMVPNum[1], iSizeInUchar );
1464 
1465  m_acCUMvField[0].copyTo( rpcCU->getCUMvField( REF_PIC_LIST_0 ), m_uiAbsIdxInLCU );
1466  m_acCUMvField[1].copyTo( rpcCU->getCUMvField( REF_PIC_LIST_1 ), m_uiAbsIdxInLCU );
1467 
1468  memcpy( rpcCU->getIPCMFlag() + m_uiAbsIdxInLCU, m_pbIPCMFlag,         iSizeInBool  );
1469
1470  UInt uiTmp  = (g_uiMaxCUWidth*g_uiMaxCUHeight)>>(uhDepth<<1);
1471  UInt uiTmp2 = m_uiAbsIdxInLCU*m_pcPic->getMinCUWidth()*m_pcPic->getMinCUHeight();
1472  memcpy( rpcCU->getCoeffY()  + uiTmp2, m_pcTrCoeffY,  sizeof(TCoeff)*uiTmp  );
1473#if ADAPTIVE_QP_SELECTION 
1474  memcpy( rpcCU->getArlCoeffY()  + uiTmp2, m_pcArlCoeffY,  sizeof(Int)*uiTmp  );
1475#endif
1476  memcpy( rpcCU->getPCMSampleY() + uiTmp2 , m_pcIPCMSampleY, sizeof(Pel)*uiTmp );
1477
1478  uiTmp >>= 2; uiTmp2 >>= 2;
1479  memcpy( rpcCU->getCoeffCb() + uiTmp2, m_pcTrCoeffCb, sizeof(TCoeff)*uiTmp  );
1480  memcpy( rpcCU->getCoeffCr() + uiTmp2, m_pcTrCoeffCr, sizeof(TCoeff)*uiTmp  );
1481#if ADAPTIVE_QP_SELECTION
1482  memcpy( rpcCU->getArlCoeffCb() + uiTmp2, m_pcArlCoeffCb, sizeof(Int)*uiTmp  );
1483  memcpy( rpcCU->getArlCoeffCr() + uiTmp2, m_pcArlCoeffCr, sizeof(Int)*uiTmp  );
1484#endif
1485  memcpy( rpcCU->getPCMSampleCb() + uiTmp2 , m_pcIPCMSampleCb, sizeof( Pel ) * uiTmp );
1486  memcpy( rpcCU->getPCMSampleCr() + uiTmp2 , m_pcIPCMSampleCr, sizeof( Pel ) * uiTmp );
1487  rpcCU->getTotalBins() = m_uiTotalBins;
1488  memcpy( rpcCU->m_sliceStartCU        + m_uiAbsIdxInLCU, m_sliceStartCU,        sizeof( UInt ) * m_uiNumPartition  );
1489  memcpy( rpcCU->m_sliceSegmentStartCU + m_uiAbsIdxInLCU, m_sliceSegmentStartCU, sizeof( UInt ) * m_uiNumPartition  );
1490#if H_3D_ARP
1491  memcpy( rpcCU->getARPW()             + m_uiAbsIdxInLCU, m_puhARPW,             iSizeInUchar );
1492#endif
1493#if H_3D_IC
1494  memcpy( rpcCU->getICFlag()           + m_uiAbsIdxInLCU, m_pbICFlag,            iSizeInBool );
1495#endif
1496}
1497
1498Void TComDataCU::copyToPic( UChar uhDepth, UInt uiPartIdx, UInt uiPartDepth )
1499{
1500  TComDataCU*&  rpcCU       = m_pcPic->getCU( m_uiCUAddr );
1501  UInt          uiQNumPart  = m_uiNumPartition>>(uiPartDepth<<1);
1502 
1503  UInt uiPartStart          = uiPartIdx*uiQNumPart;
1504  UInt uiPartOffset         = m_uiAbsIdxInLCU + uiPartStart;
1505 
1506  rpcCU->getTotalCost()       = m_dTotalCost;
1507  rpcCU->getTotalDistortion() = m_uiTotalDistortion;
1508  rpcCU->getTotalBits()       = m_uiTotalBits;
1509 
1510  Int iSizeInUchar  = sizeof( UChar  ) * uiQNumPart;
1511  Int iSizeInBool   = sizeof( Bool   ) * uiQNumPart;
1512 
1513  Int sizeInChar  = sizeof( Char ) * uiQNumPart;
1514  memcpy( rpcCU->getSkipFlag()       + uiPartOffset, m_skipFlag,   sizeof( *m_skipFlag )   * uiQNumPart );
1515
1516  memcpy( rpcCU->getQP() + uiPartOffset, m_phQP, sizeInChar );
1517  memcpy( rpcCU->getPartitionSize()  + uiPartOffset, m_pePartSize, sizeof( *m_pePartSize ) * uiQNumPart );
1518  memcpy( rpcCU->getPredictionMode() + uiPartOffset, m_pePredMode, sizeof( *m_pePredMode ) * uiQNumPart );
1519  memcpy( rpcCU->getCUTransquantBypass()+ uiPartOffset, m_CUTransquantBypass, sizeof( *m_CUTransquantBypass ) * uiQNumPart );
1520  memcpy( rpcCU->getMergeFlag()         + uiPartOffset, m_pbMergeFlag,         iSizeInBool  );
1521  memcpy( rpcCU->getMergeIndex()        + uiPartOffset, m_puhMergeIndex,       iSizeInUchar );
1522#if H_3D_VSP
1523  memcpy( rpcCU->getVSPFlag()           + uiPartOffset, m_piVSPFlag,           sizeof(Char) * uiQNumPart );
1524#if MTK_VSP_FIX_E0172
1525  memcpy( rpcCU->getVSPDir  ()          + uiPartOffset, m_piVSPDir  ,          sizeInChar );
1526#endif
1527#endif
1528  memcpy( rpcCU->getLumaIntraDir()      + uiPartOffset, m_puhLumaIntraDir,     iSizeInUchar );
1529  memcpy( rpcCU->getChromaIntraDir()    + uiPartOffset, m_puhChromaIntraDir,   iSizeInUchar );
1530  memcpy( rpcCU->getInterDir()          + uiPartOffset, m_puhInterDir,         iSizeInUchar );
1531  memcpy( rpcCU->getTransformIdx()      + uiPartOffset, m_puhTrIdx,            iSizeInUchar );
1532  memcpy( rpcCU->getTransformSkip(TEXT_LUMA)     + uiPartOffset, m_puhTransformSkip[0], iSizeInUchar );
1533  memcpy( rpcCU->getTransformSkip(TEXT_CHROMA_U) + uiPartOffset, m_puhTransformSkip[1], iSizeInUchar );
1534  memcpy( rpcCU->getTransformSkip(TEXT_CHROMA_V) + uiPartOffset, m_puhTransformSkip[2], iSizeInUchar );
1535  memcpy( rpcCU->getCbf(TEXT_LUMA)     + uiPartOffset, m_puhCbf[0], iSizeInUchar );
1536  memcpy( rpcCU->getCbf(TEXT_CHROMA_U) + uiPartOffset, m_puhCbf[1], iSizeInUchar );
1537  memcpy( rpcCU->getCbf(TEXT_CHROMA_V) + uiPartOffset, m_puhCbf[2], iSizeInUchar );
1538 
1539#if H_3D_DIM
1540  for( Int i = 0; i < DMM_NUM_TYPE; i++ )
1541  {
1542    memcpy( rpcCU->getDimDeltaDC( i, 0 ) + uiPartOffset, m_dimDeltaDC[i][0], sizeof(Pel ) * uiQNumPart );
1543    memcpy( rpcCU->getDimDeltaDC( i, 1 ) + uiPartOffset, m_dimDeltaDC[i][1], sizeof(Pel ) * uiQNumPart );
1544  }
1545#if H_3D_DIM_DMM
1546  for( Int i = 0; i < DMM_NUM_TYPE; i++ )
1547  {
1548    memcpy( rpcCU->getDmmWedgeTabIdx( i ) + uiPartOffset, m_dmmWedgeTabIdx[i], sizeof(UInt) * uiQNumPart );
1549  }
1550  memcpy( rpcCU->getDmm2DeltaEnd()    + uiPartOffset, m_dmm2DeltaEnd   , sizeof(Int ) * uiQNumPart );
1551  memcpy( rpcCU->getDmm3IntraTabIdx() + uiPartOffset, m_dmm3IntraTabIdx, sizeof(UInt) * uiQNumPart );
1552#endif
1553#if H_3D_DIM_RBC
1554  memcpy( rpcCU->getEdgeCode( uiPartOffset ),         m_pucEdgeCode,     iSizeInUchar * RBC_MAX_EDGE_NUM_PER_4x4 );
1555  memcpy( rpcCU->getEdgeNumber()      + uiPartOffset, m_pucEdgeNumber,   iSizeInUchar );
1556  memcpy( rpcCU->getEdgeStartPos()    + uiPartOffset, m_pucEdgeStartPos, iSizeInUchar );
1557  memcpy( rpcCU->getEdgeLeftFirst()   + uiPartOffset, m_pbEdgeLeftFirst, iSizeInBool );
1558  memcpy( rpcCU->getEdgePartition( uiPartOffset ),    m_pbEdgePartition, iSizeInBool * 16 );
1559#endif
1560#if H_3D_DIM_SDC
1561  memcpy( rpcCU->getSDCFlag()             + uiPartOffset, m_pbSDCFlag,      iSizeInBool  );
1562  memcpy( rpcCU->getSDCSegmentDCOffset(0) + uiPartOffset, m_apSegmentDCOffset[0], sizeof( Pel ) * uiQNumPart);
1563  memcpy( rpcCU->getSDCSegmentDCOffset(1) + uiPartOffset, m_apSegmentDCOffset[1], sizeof( Pel ) * uiQNumPart);
1564#endif
1565#endif
1566  memcpy( rpcCU->getDepth()  + uiPartOffset, m_puhDepth,  iSizeInUchar );
1567  memcpy( rpcCU->getWidth()  + uiPartOffset, m_puhWidth,  iSizeInUchar );
1568  memcpy( rpcCU->getHeight() + uiPartOffset, m_puhHeight, iSizeInUchar );
1569 
1570  memcpy( rpcCU->getMVPIdx(REF_PIC_LIST_0) + uiPartOffset, m_apiMVPIdx[0], iSizeInUchar );
1571  memcpy( rpcCU->getMVPIdx(REF_PIC_LIST_1) + uiPartOffset, m_apiMVPIdx[1], iSizeInUchar );
1572  memcpy( rpcCU->getMVPNum(REF_PIC_LIST_0) + uiPartOffset, m_apiMVPNum[0], iSizeInUchar );
1573  memcpy( rpcCU->getMVPNum(REF_PIC_LIST_1) + uiPartOffset, m_apiMVPNum[1], iSizeInUchar );
1574  m_acCUMvField[0].copyTo( rpcCU->getCUMvField( REF_PIC_LIST_0 ), m_uiAbsIdxInLCU, uiPartStart, uiQNumPart );
1575  m_acCUMvField[1].copyTo( rpcCU->getCUMvField( REF_PIC_LIST_1 ), m_uiAbsIdxInLCU, uiPartStart, uiQNumPart );
1576 
1577  memcpy( rpcCU->getIPCMFlag() + uiPartOffset, m_pbIPCMFlag,         iSizeInBool  );
1578
1579  UInt uiTmp  = (g_uiMaxCUWidth*g_uiMaxCUHeight)>>((uhDepth+uiPartDepth)<<1);
1580  UInt uiTmp2 = uiPartOffset*m_pcPic->getMinCUWidth()*m_pcPic->getMinCUHeight();
1581  memcpy( rpcCU->getCoeffY()  + uiTmp2, m_pcTrCoeffY,  sizeof(TCoeff)*uiTmp  );
1582#if ADAPTIVE_QP_SELECTION
1583  memcpy( rpcCU->getArlCoeffY()  + uiTmp2, m_pcArlCoeffY,  sizeof(Int)*uiTmp  );
1584#endif
1585 
1586  memcpy( rpcCU->getPCMSampleY() + uiTmp2 , m_pcIPCMSampleY, sizeof( Pel ) * uiTmp );
1587
1588  uiTmp >>= 2; uiTmp2 >>= 2;
1589  memcpy( rpcCU->getCoeffCb() + uiTmp2, m_pcTrCoeffCb, sizeof(TCoeff)*uiTmp  );
1590  memcpy( rpcCU->getCoeffCr() + uiTmp2, m_pcTrCoeffCr, sizeof(TCoeff)*uiTmp  );
1591#if ADAPTIVE_QP_SELECTION
1592  memcpy( rpcCU->getArlCoeffCb() + uiTmp2, m_pcArlCoeffCb, sizeof(Int)*uiTmp  );
1593  memcpy( rpcCU->getArlCoeffCr() + uiTmp2, m_pcArlCoeffCr, sizeof(Int)*uiTmp  );
1594#endif
1595
1596  memcpy( rpcCU->getPCMSampleCb() + uiTmp2 , m_pcIPCMSampleCb, sizeof( Pel ) * uiTmp );
1597  memcpy( rpcCU->getPCMSampleCr() + uiTmp2 , m_pcIPCMSampleCr, sizeof( Pel ) * uiTmp );
1598  rpcCU->getTotalBins() = m_uiTotalBins;
1599  memcpy( rpcCU->m_sliceStartCU        + uiPartOffset, m_sliceStartCU,        sizeof( UInt ) * uiQNumPart  );
1600  memcpy( rpcCU->m_sliceSegmentStartCU + uiPartOffset, m_sliceSegmentStartCU, sizeof( UInt ) * uiQNumPart  );
1601#if H_3D_ARP
1602  memcpy( rpcCU->getARPW()             + uiPartOffset, m_puhARPW,             iSizeInUchar );
1603#endif
1604#if H_3D_IC
1605  memcpy( rpcCU->getICFlag()           + uiPartOffset, m_pbICFlag,            iSizeInBool );
1606#endif
1607}
1608
1609// --------------------------------------------------------------------------------------------------------------------
1610// Other public functions
1611// --------------------------------------------------------------------------------------------------------------------
1612
1613TComDataCU* TComDataCU::getPULeft( UInt& uiLPartUnitIdx, 
1614                                   UInt uiCurrPartUnitIdx, 
1615                                   Bool bEnforceSliceRestriction, 
1616                                   Bool bEnforceTileRestriction )
1617{
1618  UInt uiAbsPartIdx       = g_auiZscanToRaster[uiCurrPartUnitIdx];
1619  UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[m_uiAbsIdxInLCU];
1620  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1621 
1622  if ( !RasterAddress::isZeroCol( uiAbsPartIdx, uiNumPartInCUWidth ) )
1623  {
1624    uiLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - 1 ];
1625    if ( RasterAddress::isEqualCol( uiAbsPartIdx, uiAbsZorderCUIdx, uiNumPartInCUWidth ) )
1626    {
1627      return m_pcPic->getCU( getAddr() );
1628    }
1629    else
1630    {
1631      uiLPartUnitIdx -= m_uiAbsIdxInLCU;
1632      return this;
1633    }
1634  }
1635 
1636  uiLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx + uiNumPartInCUWidth - 1 ];
1637
1638
1639  if ( (bEnforceSliceRestriction && (m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL || m_pcCULeft->getSCUAddr()+uiLPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)))
1640      ||
1641       (bEnforceTileRestriction && ( m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL || (m_pcPic->getPicSym()->getTileIdxMap( m_pcCULeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))  )  )
1642      )
1643  {
1644    return NULL;
1645  }
1646  return m_pcCULeft;
1647}
1648
1649TComDataCU* TComDataCU::getPUAbove( UInt& uiAPartUnitIdx,
1650                                    UInt uiCurrPartUnitIdx, 
1651                                    Bool bEnforceSliceRestriction, 
1652                                    Bool planarAtLCUBoundary ,
1653                                    Bool bEnforceTileRestriction )
1654{
1655  UInt uiAbsPartIdx       = g_auiZscanToRaster[uiCurrPartUnitIdx];
1656  UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[m_uiAbsIdxInLCU];
1657  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1658 
1659  if ( !RasterAddress::isZeroRow( uiAbsPartIdx, uiNumPartInCUWidth ) )
1660  {
1661    uiAPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - uiNumPartInCUWidth ];
1662    if ( RasterAddress::isEqualRow( uiAbsPartIdx, uiAbsZorderCUIdx, uiNumPartInCUWidth ) )
1663    {
1664      return m_pcPic->getCU( getAddr() );
1665    }
1666    else
1667    {
1668      uiAPartUnitIdx -= m_uiAbsIdxInLCU;
1669      return this;
1670    }
1671  }
1672
1673  if(planarAtLCUBoundary)
1674  {
1675    return NULL;
1676  }
1677 
1678  uiAPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx + m_pcPic->getNumPartInCU() - uiNumPartInCUWidth ];
1679
1680  if ( (bEnforceSliceRestriction && (m_pcCUAbove==NULL || m_pcCUAbove->getSlice()==NULL || m_pcCUAbove->getSCUAddr()+uiAPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)))
1681      ||
1682       (bEnforceTileRestriction &&(m_pcCUAbove==NULL || m_pcCUAbove->getSlice()==NULL || (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAbove->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))))
1683      )
1684  {
1685    return NULL;
1686  }
1687  return m_pcCUAbove;
1688}
1689
1690TComDataCU* TComDataCU::getPUAboveLeft( UInt& uiALPartUnitIdx, UInt uiCurrPartUnitIdx, Bool bEnforceSliceRestriction )
1691{
1692  UInt uiAbsPartIdx       = g_auiZscanToRaster[uiCurrPartUnitIdx];
1693  UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[m_uiAbsIdxInLCU];
1694  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1695 
1696  if ( !RasterAddress::isZeroCol( uiAbsPartIdx, uiNumPartInCUWidth ) )
1697  {
1698    if ( !RasterAddress::isZeroRow( uiAbsPartIdx, uiNumPartInCUWidth ) )
1699    {
1700      uiALPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - uiNumPartInCUWidth - 1 ];
1701      if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdx, uiAbsZorderCUIdx, uiNumPartInCUWidth ) )
1702      {
1703        return m_pcPic->getCU( getAddr() );
1704      }
1705      else
1706      {
1707        uiALPartUnitIdx -= m_uiAbsIdxInLCU;
1708        return this;
1709      }
1710    }
1711    uiALPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx + getPic()->getNumPartInCU() - uiNumPartInCUWidth - 1 ];
1712    if ( (bEnforceSliceRestriction && (m_pcCUAbove==NULL || m_pcCUAbove->getSlice()==NULL ||
1713       m_pcCUAbove->getSCUAddr()+uiALPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1714       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAbove->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1715       ))
1716     )
1717    {
1718      return NULL;
1719    }
1720    return m_pcCUAbove;
1721  }
1722 
1723  if ( !RasterAddress::isZeroRow( uiAbsPartIdx, uiNumPartInCUWidth ) )
1724  {
1725    uiALPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - 1 ];
1726    if ( (bEnforceSliceRestriction && (m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL || 
1727       m_pcCULeft->getSCUAddr()+uiALPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1728       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCULeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1729       ))
1730     )
1731    {
1732      return NULL;
1733    }
1734    return m_pcCULeft;
1735  }
1736 
1737  uiALPartUnitIdx = g_auiRasterToZscan[ m_pcPic->getNumPartInCU() - 1 ];
1738  if ( (bEnforceSliceRestriction && (m_pcCUAboveLeft==NULL || m_pcCUAboveLeft->getSlice()==NULL ||
1739       m_pcCUAboveLeft->getSCUAddr()+uiALPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1740       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAboveLeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1741       ))
1742     )
1743  {
1744    return NULL;
1745  }
1746  return m_pcCUAboveLeft;
1747}
1748
1749TComDataCU* TComDataCU::getPUAboveRight( UInt& uiARPartUnitIdx, UInt uiCurrPartUnitIdx, Bool bEnforceSliceRestriction )
1750{
1751  UInt uiAbsPartIdxRT     = g_auiZscanToRaster[uiCurrPartUnitIdx];
1752  UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + m_puhWidth[0] / m_pcPic->getMinCUWidth() - 1;
1753  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1754 
1755  if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxRT] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )
1756  {
1757    uiARPartUnitIdx = MAX_UINT;
1758    return NULL;
1759  }
1760 
1761  if ( RasterAddress::lessThanCol( uiAbsPartIdxRT, uiNumPartInCUWidth - 1, uiNumPartInCUWidth ) )
1762  {
1763    if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, uiNumPartInCUWidth ) )
1764    {
1765      if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxRT - uiNumPartInCUWidth + 1 ] )
1766      {
1767        uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT - uiNumPartInCUWidth + 1 ];
1768        if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxRT, uiAbsZorderCUIdx, uiNumPartInCUWidth ) )
1769        {
1770          return m_pcPic->getCU( getAddr() );
1771        }
1772        else
1773        {
1774          uiARPartUnitIdx -= m_uiAbsIdxInLCU;
1775          return this;
1776        }
1777      }
1778      uiARPartUnitIdx = MAX_UINT;
1779      return NULL;
1780    }
1781    uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT + m_pcPic->getNumPartInCU() - uiNumPartInCUWidth + 1 ];
1782    if ( (bEnforceSliceRestriction && (m_pcCUAbove==NULL || m_pcCUAbove->getSlice()==NULL ||
1783       m_pcCUAbove->getSCUAddr()+uiARPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1784       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAbove->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1785       ))
1786     )
1787    {
1788      return NULL;
1789    }
1790    return m_pcCUAbove;
1791  }
1792 
1793  if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, uiNumPartInCUWidth ) )
1794  {
1795    uiARPartUnitIdx = MAX_UINT;
1796    return NULL;
1797  }
1798 
1799  uiARPartUnitIdx = g_auiRasterToZscan[ m_pcPic->getNumPartInCU() - uiNumPartInCUWidth ];
1800  if ( (bEnforceSliceRestriction && (m_pcCUAboveRight==NULL || m_pcCUAboveRight->getSlice()==NULL ||
1801       m_pcPic->getPicSym()->getInverseCUOrderMap( m_pcCUAboveRight->getAddr()) > m_pcPic->getPicSym()->getInverseCUOrderMap( getAddr()) ||
1802       m_pcCUAboveRight->getSCUAddr()+uiARPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1803       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAboveRight->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1804       ))
1805     )
1806  {
1807    return NULL;
1808  }
1809  return m_pcCUAboveRight;
1810}
1811
1812TComDataCU* TComDataCU::getPUBelowLeft( UInt& uiBLPartUnitIdx, UInt uiCurrPartUnitIdx, Bool bEnforceSliceRestriction )
1813{
1814  UInt uiAbsPartIdxLB     = g_auiZscanToRaster[uiCurrPartUnitIdx];
1815  UInt uiAbsZorderCUIdxLB = g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + (m_puhHeight[0] / m_pcPic->getMinCUHeight() - 1)*m_pcPic->getNumPartInWidth();
1816  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1817 
1818  if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxLB] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
1819  {
1820    uiBLPartUnitIdx = MAX_UINT;
1821    return NULL;
1822  }
1823 
1824  if ( RasterAddress::lessThanRow( uiAbsPartIdxLB, m_pcPic->getNumPartInHeight() - 1, uiNumPartInCUWidth ) )
1825  {
1826    if ( !RasterAddress::isZeroCol( uiAbsPartIdxLB, uiNumPartInCUWidth ) )
1827    {
1828      if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxLB + uiNumPartInCUWidth - 1 ] )
1829      {
1830        uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + uiNumPartInCUWidth - 1 ];
1831        if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxLB, uiAbsZorderCUIdxLB, uiNumPartInCUWidth ) )
1832        {
1833          return m_pcPic->getCU( getAddr() );
1834        }
1835        else
1836        {
1837          uiBLPartUnitIdx -= m_uiAbsIdxInLCU;
1838          return this;
1839        }
1840      }
1841      uiBLPartUnitIdx = MAX_UINT;
1842      return NULL;
1843    }
1844    uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + uiNumPartInCUWidth*2 - 1 ];
1845    if ( (bEnforceSliceRestriction && (m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL || 
1846       m_pcCULeft->getSCUAddr()+uiBLPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1847       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCULeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1848       ))
1849     )
1850    {
1851      return NULL;
1852    }
1853    return m_pcCULeft;
1854  }
1855 
1856  uiBLPartUnitIdx = MAX_UINT;
1857  return NULL;
1858}
1859
1860TComDataCU* TComDataCU::getPUBelowLeftAdi(UInt& uiBLPartUnitIdx,  UInt uiCurrPartUnitIdx, UInt uiPartUnitOffset, Bool bEnforceSliceRestriction )
1861{
1862  UInt uiAbsPartIdxLB     = g_auiZscanToRaster[uiCurrPartUnitIdx];
1863  UInt uiAbsZorderCUIdxLB = g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + ((m_puhHeight[0] / m_pcPic->getMinCUHeight()) - 1)*m_pcPic->getNumPartInWidth();
1864  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1865 
1866  if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxLB] + (m_pcPic->getPicSym()->getMinCUHeight() * uiPartUnitOffset)) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples())
1867  {
1868    uiBLPartUnitIdx = MAX_UINT;
1869    return NULL;
1870  }
1871 
1872  if ( RasterAddress::lessThanRow( uiAbsPartIdxLB, m_pcPic->getNumPartInHeight() - uiPartUnitOffset, uiNumPartInCUWidth ) )
1873  {
1874    if ( !RasterAddress::isZeroCol( uiAbsPartIdxLB, uiNumPartInCUWidth ) )
1875    {
1876      if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxLB + uiPartUnitOffset * uiNumPartInCUWidth - 1 ] )
1877      {
1878        uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + uiPartUnitOffset * uiNumPartInCUWidth - 1 ];
1879        if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxLB, uiAbsZorderCUIdxLB, uiNumPartInCUWidth ) )
1880        {
1881          return m_pcPic->getCU( getAddr() );
1882        }
1883        else
1884        {
1885          uiBLPartUnitIdx -= m_uiAbsIdxInLCU;
1886          return this;
1887        }
1888      }
1889      uiBLPartUnitIdx = MAX_UINT;
1890      return NULL;
1891    }
1892    uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + (1+uiPartUnitOffset) * uiNumPartInCUWidth - 1 ];
1893    if ( (bEnforceSliceRestriction && (m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL || 
1894       m_pcCULeft->getSCUAddr()+uiBLPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1895       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCULeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1896       ))
1897     )
1898    {
1899      return NULL;
1900    }
1901    return m_pcCULeft;
1902  }
1903 
1904  uiBLPartUnitIdx = MAX_UINT;
1905  return NULL;
1906}
1907
1908TComDataCU* TComDataCU::getPUAboveRightAdi(UInt&  uiARPartUnitIdx, UInt uiCurrPartUnitIdx, UInt uiPartUnitOffset, Bool bEnforceSliceRestriction )
1909{
1910  UInt uiAbsPartIdxRT     = g_auiZscanToRaster[uiCurrPartUnitIdx];
1911  UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + (m_puhWidth[0] / m_pcPic->getMinCUWidth()) - 1;
1912  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1913 
1914  if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxRT] + (m_pcPic->getPicSym()->getMinCUHeight() * uiPartUnitOffset)) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )
1915  {
1916    uiARPartUnitIdx = MAX_UINT;
1917    return NULL;
1918  }
1919 
1920  if ( RasterAddress::lessThanCol( uiAbsPartIdxRT, uiNumPartInCUWidth - uiPartUnitOffset, uiNumPartInCUWidth ) )
1921  {
1922    if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, uiNumPartInCUWidth ) )
1923    {
1924      if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxRT - uiNumPartInCUWidth + uiPartUnitOffset ] )
1925      {
1926        uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT - uiNumPartInCUWidth + uiPartUnitOffset ];
1927        if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxRT, uiAbsZorderCUIdx, uiNumPartInCUWidth ) )
1928        {
1929          return m_pcPic->getCU( getAddr() );
1930        }
1931        else
1932        {
1933          uiARPartUnitIdx -= m_uiAbsIdxInLCU;
1934          return this;
1935        }
1936      }
1937      uiARPartUnitIdx = MAX_UINT;
1938      return NULL;
1939    }
1940    uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT + m_pcPic->getNumPartInCU() - uiNumPartInCUWidth + uiPartUnitOffset ];
1941    if ( (bEnforceSliceRestriction && (m_pcCUAbove==NULL || m_pcCUAbove->getSlice()==NULL || 
1942       m_pcCUAbove->getSCUAddr()+uiARPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1943       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAbove->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1944       ))
1945     )
1946    {
1947      return NULL;
1948    }
1949    return m_pcCUAbove;
1950  }
1951 
1952  if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, uiNumPartInCUWidth ) )
1953  {
1954    uiARPartUnitIdx = MAX_UINT;
1955    return NULL;
1956  }
1957 
1958  uiARPartUnitIdx = g_auiRasterToZscan[ m_pcPic->getNumPartInCU() - uiNumPartInCUWidth + uiPartUnitOffset-1 ];
1959  if ( (bEnforceSliceRestriction && (m_pcCUAboveRight==NULL || m_pcCUAboveRight->getSlice()==NULL ||
1960       m_pcPic->getPicSym()->getInverseCUOrderMap( m_pcCUAboveRight->getAddr()) > m_pcPic->getPicSym()->getInverseCUOrderMap( getAddr()) ||
1961       m_pcCUAboveRight->getSCUAddr()+uiARPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1962       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAboveRight->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1963       ))
1964     )
1965  {
1966    return NULL;
1967  }
1968  return m_pcCUAboveRight;
1969}
1970
1971/** Get left QpMinCu
1972*\param   uiLPartUnitIdx
1973*\param   uiCurrAbsIdxInLCU
1974*\returns TComDataCU*   point of TComDataCU of left QpMinCu
1975*/
1976TComDataCU* TComDataCU::getQpMinCuLeft( UInt& uiLPartUnitIdx, UInt uiCurrAbsIdxInLCU)
1977{
1978  UInt numPartInCUWidth = m_pcPic->getNumPartInWidth();
1979  UInt absZorderQpMinCUIdx = (uiCurrAbsIdxInLCU>>((g_uiMaxCUDepth - getSlice()->getPPS()->getMaxCuDQPDepth())<<1))<<((g_uiMaxCUDepth -getSlice()->getPPS()->getMaxCuDQPDepth())<<1);
1980  UInt absRorderQpMinCUIdx = g_auiZscanToRaster[absZorderQpMinCUIdx];
1981
1982  // check for left LCU boundary
1983  if ( RasterAddress::isZeroCol(absRorderQpMinCUIdx, numPartInCUWidth) )
1984  {
1985    return NULL;
1986  }
1987
1988  // get index of left-CU relative to top-left corner of current quantization group
1989  uiLPartUnitIdx = g_auiRasterToZscan[absRorderQpMinCUIdx - 1];
1990
1991  // return pointer to current LCU
1992  return m_pcPic->getCU( getAddr() );
1993}
1994
1995/** Get Above QpMinCu
1996*\param   aPartUnitIdx
1997*\param   currAbsIdxInLCU
1998*\returns TComDataCU*   point of TComDataCU of above QpMinCu
1999*/
2000TComDataCU* TComDataCU::getQpMinCuAbove( UInt& aPartUnitIdx, UInt currAbsIdxInLCU )
2001{
2002  UInt numPartInCUWidth = m_pcPic->getNumPartInWidth();
2003  UInt absZorderQpMinCUIdx = (currAbsIdxInLCU>>((g_uiMaxCUDepth - getSlice()->getPPS()->getMaxCuDQPDepth())<<1))<<((g_uiMaxCUDepth - getSlice()->getPPS()->getMaxCuDQPDepth())<<1);
2004  UInt absRorderQpMinCUIdx = g_auiZscanToRaster[absZorderQpMinCUIdx];
2005
2006  // check for top LCU boundary
2007  if ( RasterAddress::isZeroRow( absRorderQpMinCUIdx, numPartInCUWidth) )
2008  {
2009    return NULL;
2010  }
2011
2012  // get index of top-CU relative to top-left corner of current quantization group
2013  aPartUnitIdx = g_auiRasterToZscan[absRorderQpMinCUIdx - numPartInCUWidth];
2014
2015  // return pointer to current LCU
2016  return m_pcPic->getCU( getAddr() );
2017}
2018
2019/** Get reference QP from left QpMinCu or latest coded QP
2020*\param   uiCurrAbsIdxInLCU
2021*\returns Char   reference QP value
2022*/
2023Char TComDataCU::getRefQP( UInt uiCurrAbsIdxInLCU )
2024{
2025  UInt        lPartIdx = 0, aPartIdx = 0;
2026  TComDataCU* cULeft  = getQpMinCuLeft ( lPartIdx, m_uiAbsIdxInLCU + uiCurrAbsIdxInLCU );
2027  TComDataCU* cUAbove = getQpMinCuAbove( aPartIdx, m_uiAbsIdxInLCU + uiCurrAbsIdxInLCU );
2028  return (((cULeft? cULeft->getQP( lPartIdx ): getLastCodedQP( uiCurrAbsIdxInLCU )) + (cUAbove? cUAbove->getQP( aPartIdx ): getLastCodedQP( uiCurrAbsIdxInLCU )) + 1) >> 1);
2029}
2030
2031Int TComDataCU::getLastValidPartIdx( Int iAbsPartIdx )
2032{
2033  Int iLastValidPartIdx = iAbsPartIdx-1;
2034  while ( iLastValidPartIdx >= 0
2035       && getPredictionMode( iLastValidPartIdx ) == MODE_NONE )
2036  {
2037    UInt uiDepth = getDepth( iLastValidPartIdx );
2038    iLastValidPartIdx -= m_uiNumPartition>>(uiDepth<<1);
2039  }
2040  return iLastValidPartIdx;
2041}
2042
2043Char TComDataCU::getLastCodedQP( UInt uiAbsPartIdx )
2044{
2045  UInt uiQUPartIdxMask = ~((1<<((g_uiMaxCUDepth - getSlice()->getPPS()->getMaxCuDQPDepth())<<1))-1);
2046  Int iLastValidPartIdx = getLastValidPartIdx( uiAbsPartIdx&uiQUPartIdxMask );
2047  if ( uiAbsPartIdx < m_uiNumPartition
2048    && (getSCUAddr()+iLastValidPartIdx < getSliceStartCU(m_uiAbsIdxInLCU+uiAbsPartIdx)))
2049  {
2050    return getSlice()->getSliceQp();
2051  }
2052  else if ( iLastValidPartIdx >= 0 )
2053  {
2054    return getQP( iLastValidPartIdx );
2055  }
2056  else
2057  {
2058    if ( getZorderIdxInCU() > 0 )
2059    {
2060      return getPic()->getCU( getAddr() )->getLastCodedQP( getZorderIdxInCU() );
2061    }
2062    else if ( getPic()->getPicSym()->getInverseCUOrderMap(getAddr()) > 0
2063      && getPic()->getPicSym()->getTileIdxMap(getAddr()) == getPic()->getPicSym()->getTileIdxMap(getPic()->getPicSym()->getCUOrderMap(getPic()->getPicSym()->getInverseCUOrderMap(getAddr())-1))
2064      && !( getSlice()->getPPS()->getEntropyCodingSyncEnabledFlag() && getAddr() % getPic()->getFrameWidthInCU() == 0 ) )
2065    {
2066      return getPic()->getCU( getPic()->getPicSym()->getCUOrderMap(getPic()->getPicSym()->getInverseCUOrderMap(getAddr())-1) )->getLastCodedQP( getPic()->getNumPartInCU() );
2067    }
2068    else
2069    {
2070      return getSlice()->getSliceQp();
2071    }
2072  }
2073}
2074/** Check whether the CU is coded in lossless coding mode
2075 * \param   uiAbsPartIdx
2076 * \returns true if the CU is coded in lossless coding mode; false if otherwise
2077 */
2078Bool TComDataCU::isLosslessCoded(UInt absPartIdx)
2079{
2080  return (getSlice()->getPPS()->getTransquantBypassEnableFlag() && getCUTransquantBypass (absPartIdx));
2081}
2082
2083/** Get allowed chroma intra modes
2084*\param   uiAbsPartIdx
2085*\param   uiModeList  pointer to chroma intra modes array
2086*\returns
2087*- fill uiModeList with chroma intra modes
2088*/
2089Void TComDataCU::getAllowedChromaDir( UInt uiAbsPartIdx, UInt* uiModeList )
2090{
2091  uiModeList[0] = PLANAR_IDX;
2092  uiModeList[1] = VER_IDX;
2093  uiModeList[2] = HOR_IDX;
2094  uiModeList[3] = DC_IDX;
2095  uiModeList[4] = DM_CHROMA_IDX;
2096
2097  UInt uiLumaMode = getLumaIntraDir( uiAbsPartIdx );
2098
2099  for( Int i = 0; i < NUM_CHROMA_MODE - 1; i++ )
2100  {
2101    if( uiLumaMode == uiModeList[i] )
2102    {
2103      uiModeList[i] = 34; // VER+8 mode
2104      break;
2105    }
2106  }
2107}
2108
2109/** Get most probable intra modes
2110*\param   uiAbsPartIdx
2111*\param   uiIntraDirPred  pointer to the array for MPM storage
2112*\param   piMode          it is set with MPM mode in case both MPM are equal. It is used to restrict RD search at encode side.
2113*\returns Number of MPM
2114*/
2115Int TComDataCU::getIntraDirLumaPredictor( UInt uiAbsPartIdx, Int* uiIntraDirPred, Int* piMode  )
2116{
2117  TComDataCU* pcTempCU;
2118  UInt        uiTempPartIdx;
2119  Int         iLeftIntraDir, iAboveIntraDir;
2120  Int         uiPredNum = 0;
2121 
2122  // Get intra direction of left PU
2123  pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
2124 
2125  iLeftIntraDir  = pcTempCU ? ( pcTempCU->isIntra( uiTempPartIdx ) ? pcTempCU->getLumaIntraDir( uiTempPartIdx ) : DC_IDX ) : DC_IDX;
2126#if H_3D_DIM
2127  mapDepthModeToIntraDir( iLeftIntraDir );
2128#endif
2129 
2130  // Get intra direction of above PU
2131  pcTempCU = getPUAbove( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx, true, true );
2132 
2133  iAboveIntraDir = pcTempCU ? ( pcTempCU->isIntra( uiTempPartIdx ) ? pcTempCU->getLumaIntraDir( uiTempPartIdx ) : DC_IDX ) : DC_IDX;
2134#if H_3D_DIM
2135  mapDepthModeToIntraDir( iAboveIntraDir );
2136#endif
2137 
2138  uiPredNum = 3;
2139  if(iLeftIntraDir == iAboveIntraDir)
2140  {
2141    if( piMode )
2142    {
2143      *piMode = 1;
2144    }
2145   
2146    if (iLeftIntraDir > 1) // angular modes
2147    {
2148      uiIntraDirPred[0] = iLeftIntraDir;
2149      uiIntraDirPred[1] = ((iLeftIntraDir + 29) % 32) + 2;
2150      uiIntraDirPred[2] = ((iLeftIntraDir - 1 ) % 32) + 2;
2151    }
2152    else //non-angular
2153    {
2154      uiIntraDirPred[0] = PLANAR_IDX;
2155      uiIntraDirPred[1] = DC_IDX;
2156      uiIntraDirPred[2] = VER_IDX; 
2157    }
2158  }
2159  else
2160  {
2161    if( piMode )
2162    {
2163      *piMode = 2;
2164    }
2165    uiIntraDirPred[0] = iLeftIntraDir;
2166    uiIntraDirPred[1] = iAboveIntraDir;
2167   
2168    if (iLeftIntraDir && iAboveIntraDir ) //both modes are non-planar
2169    {
2170      uiIntraDirPred[2] = PLANAR_IDX;
2171    }
2172    else
2173    {
2174      uiIntraDirPred[2] =  (iLeftIntraDir+iAboveIntraDir)<2? VER_IDX : DC_IDX;
2175    }
2176  }
2177 
2178  return uiPredNum;
2179}
2180
2181UInt TComDataCU::getCtxSplitFlag( UInt uiAbsPartIdx, UInt uiDepth )
2182{
2183  TComDataCU* pcTempCU;
2184  UInt        uiTempPartIdx;
2185  UInt        uiCtx;
2186  // Get left split flag
2187  pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
2188  uiCtx  = ( pcTempCU ) ? ( ( pcTempCU->getDepth( uiTempPartIdx ) > uiDepth ) ? 1 : 0 ) : 0;
2189 
2190  // Get above split flag
2191  pcTempCU = getPUAbove( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
2192  uiCtx += ( pcTempCU ) ? ( ( pcTempCU->getDepth( uiTempPartIdx ) > uiDepth ) ? 1 : 0 ) : 0;
2193 
2194  return uiCtx;
2195}
2196
2197UInt TComDataCU::getCtxQtCbf( TextType eType, UInt uiTrDepth )
2198{
2199  if( eType )
2200  {
2201    return uiTrDepth;
2202  }
2203  else
2204  {
2205    const UInt uiCtx = ( uiTrDepth == 0 ? 1 : 0 );
2206    return uiCtx;
2207  }
2208}
2209
2210UInt TComDataCU::getQuadtreeTULog2MinSizeInCU( UInt absPartIdx )
2211{
2212  UInt log2CbSize = g_aucConvertToBit[getWidth( absPartIdx )] + 2;
2213  PartSize  partSize  = getPartitionSize( absPartIdx );
2214  UInt quadtreeTUMaxDepth = getPredictionMode( absPartIdx ) == MODE_INTRA ? m_pcSlice->getSPS()->getQuadtreeTUMaxDepthIntra() : m_pcSlice->getSPS()->getQuadtreeTUMaxDepthInter(); 
2215  Int intraSplitFlag = ( getPredictionMode( absPartIdx ) == MODE_INTRA && partSize == SIZE_NxN ) ? 1 : 0;
2216  Int interSplitFlag = ((quadtreeTUMaxDepth == 1) && (getPredictionMode( absPartIdx ) == MODE_INTER) && (partSize != SIZE_2Nx2N) );
2217 
2218  UInt log2MinTUSizeInCU = 0;
2219  if (log2CbSize < (m_pcSlice->getSPS()->getQuadtreeTULog2MinSize() + quadtreeTUMaxDepth - 1 + interSplitFlag + intraSplitFlag) ) 
2220  {
2221    // when fully making use of signaled TUMaxDepth + inter/intraSplitFlag, resulting luma TB size is < QuadtreeTULog2MinSize
2222    log2MinTUSizeInCU = m_pcSlice->getSPS()->getQuadtreeTULog2MinSize();
2223  }
2224  else
2225  {
2226    // when fully making use of signaled TUMaxDepth + inter/intraSplitFlag, resulting luma TB size is still >= QuadtreeTULog2MinSize
2227    log2MinTUSizeInCU = log2CbSize - ( quadtreeTUMaxDepth - 1 + interSplitFlag + intraSplitFlag); // stop when trafoDepth == hierarchy_depth = splitFlag
2228    if ( log2MinTUSizeInCU > m_pcSlice->getSPS()->getQuadtreeTULog2MaxSize())
2229    {
2230      // when fully making use of signaled TUMaxDepth + inter/intraSplitFlag, resulting luma TB size is still > QuadtreeTULog2MaxSize
2231      log2MinTUSizeInCU = m_pcSlice->getSPS()->getQuadtreeTULog2MaxSize();
2232    } 
2233  }
2234  return log2MinTUSizeInCU;
2235}
2236
2237UInt TComDataCU::getCtxSkipFlag( UInt uiAbsPartIdx )
2238{
2239  TComDataCU* pcTempCU;
2240  UInt        uiTempPartIdx;
2241  UInt        uiCtx = 0;
2242 
2243  // Get BCBP of left PU
2244  pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
2245  uiCtx    = ( pcTempCU ) ? pcTempCU->isSkipped( uiTempPartIdx ) : 0;
2246 
2247  // Get BCBP of above PU
2248  pcTempCU = getPUAbove( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
2249  uiCtx   += ( pcTempCU ) ? pcTempCU->isSkipped( uiTempPartIdx ) : 0;
2250 
2251  return uiCtx;
2252}
2253
2254#if H_3D_ARP
2255UInt TComDataCU::getCTXARPWFlag( UInt uiAbsPartIdx )
2256{
2257  TComDataCU* pcTempCU;
2258  UInt        uiTempPartIdx;
2259  UInt        uiCtx = 0;
2260 
2261  pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
2262  uiCtx    = ( pcTempCU ) ? ((pcTempCU->getARPW( uiTempPartIdx )==0)?0:1) : 0;
2263 
2264  pcTempCU = getPUAbove( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
2265  uiCtx   += ( pcTempCU ) ? ((pcTempCU->getARPW( uiTempPartIdx )==0)?0:1): 0;
2266 
2267  return uiCtx;
2268}
2269#endif
2270
2271#if H_3D_IC
2272UInt TComDataCU::getCtxICFlag( UInt uiAbsPartIdx )
2273{
2274  UInt        uiCtx = 0;
2275
2276  return uiCtx;
2277}
2278#endif
2279UInt TComDataCU::getCtxInterDir( UInt uiAbsPartIdx )
2280{
2281  return getDepth( uiAbsPartIdx );
2282}
2283
2284Void TComDataCU::setCbfSubParts( UInt uiCbfY, UInt uiCbfU, UInt uiCbfV, UInt uiAbsPartIdx, UInt uiDepth )
2285{
2286  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2287  memset( m_puhCbf[0] + uiAbsPartIdx, uiCbfY, sizeof( UChar ) * uiCurrPartNumb );
2288  memset( m_puhCbf[1] + uiAbsPartIdx, uiCbfU, sizeof( UChar ) * uiCurrPartNumb );
2289  memset( m_puhCbf[2] + uiAbsPartIdx, uiCbfV, sizeof( UChar ) * uiCurrPartNumb );
2290}
2291
2292Void TComDataCU::setCbfSubParts( UInt uiCbf, TextType eTType, UInt uiAbsPartIdx, UInt uiDepth )
2293{
2294  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2295  memset( m_puhCbf[g_aucConvertTxtTypeToIdx[eTType]] + uiAbsPartIdx, uiCbf, sizeof( UChar ) * uiCurrPartNumb );
2296}
2297
2298/** Sets a coded block flag for all sub-partitions of a partition
2299 * \param uiCbf The value of the coded block flag to be set
2300 * \param eTType
2301 * \param uiAbsPartIdx
2302 * \param uiPartIdx
2303 * \param uiDepth
2304 * \returns Void
2305 */
2306Void TComDataCU::setCbfSubParts ( UInt uiCbf, TextType eTType, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
2307{
2308  setSubPart<UChar>( uiCbf, m_puhCbf[g_aucConvertTxtTypeToIdx[eTType]], uiAbsPartIdx, uiDepth, uiPartIdx );
2309}
2310
2311Void TComDataCU::setDepthSubParts( UInt uiDepth, UInt uiAbsPartIdx )
2312{
2313  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2314  memset( m_puhDepth + uiAbsPartIdx, uiDepth, sizeof(UChar)*uiCurrPartNumb );
2315}
2316
2317Bool TComDataCU::isFirstAbsZorderIdxInDepth (UInt uiAbsPartIdx, UInt uiDepth)
2318{
2319  UInt uiPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2320  return (((m_uiAbsIdxInLCU + uiAbsPartIdx)% uiPartNumb) == 0);
2321}
2322
2323Void TComDataCU::setPartSizeSubParts( PartSize eMode, UInt uiAbsPartIdx, UInt uiDepth )
2324{
2325  assert( sizeof( *m_pePartSize) == 1 );
2326  memset( m_pePartSize + uiAbsPartIdx, eMode, m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ) );
2327}
2328
2329Void TComDataCU::setCUTransquantBypassSubParts( Bool flag, UInt uiAbsPartIdx, UInt uiDepth )
2330{
2331  memset( m_CUTransquantBypass + uiAbsPartIdx, flag, m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ) );
2332}
2333
2334Void TComDataCU::setSkipFlagSubParts( Bool skip, UInt absPartIdx, UInt depth )
2335{
2336  assert( sizeof( *m_skipFlag) == 1 );
2337  memset( m_skipFlag + absPartIdx, skip, m_pcPic->getNumPartInCU() >> ( 2 * depth ) );
2338}
2339
2340Void TComDataCU::setPredModeSubParts( PredMode eMode, UInt uiAbsPartIdx, UInt uiDepth )
2341{
2342  assert( sizeof( *m_pePredMode) == 1 );
2343  memset( m_pePredMode + uiAbsPartIdx, eMode, m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ) );
2344}
2345
2346Void TComDataCU::setQPSubCUs( Int qp, TComDataCU* pcCU, UInt absPartIdx, UInt depth, Bool &foundNonZeroCbf )
2347{
2348  UInt currPartNumb = m_pcPic->getNumPartInCU() >> (depth << 1);
2349  UInt currPartNumQ = currPartNumb >> 2;
2350
2351  if(!foundNonZeroCbf)
2352  {
2353    if(pcCU->getDepth(absPartIdx) > depth)
2354    {
2355      for ( UInt partUnitIdx = 0; partUnitIdx < 4; partUnitIdx++ )
2356      {
2357        pcCU->setQPSubCUs( qp, pcCU, absPartIdx+partUnitIdx*currPartNumQ, depth+1, foundNonZeroCbf );
2358      }
2359    }
2360    else
2361    {
2362      if(pcCU->getCbf( absPartIdx, TEXT_LUMA ) || pcCU->getCbf( absPartIdx, TEXT_CHROMA_U ) || pcCU->getCbf( absPartIdx, TEXT_CHROMA_V ) )
2363      {
2364        foundNonZeroCbf = true;
2365      }
2366      else
2367      {
2368        setQPSubParts(qp, absPartIdx, depth);
2369      }
2370    }
2371  }
2372}
2373
2374Void TComDataCU::setQPSubParts( Int qp, UInt uiAbsPartIdx, UInt uiDepth )
2375{
2376  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2377  TComSlice * pcSlice = getPic()->getSlice(getPic()->getCurrSliceIdx());
2378
2379  for(UInt uiSCUIdx = uiAbsPartIdx; uiSCUIdx < uiAbsPartIdx+uiCurrPartNumb; uiSCUIdx++)
2380  {
2381    if( m_pcPic->getCU( getAddr() )->getSliceSegmentStartCU(uiSCUIdx+getZorderIdxInCU()) == pcSlice->getSliceSegmentCurStartCUAddr() )
2382    {
2383      m_phQP[uiSCUIdx] = qp;
2384    }
2385  }
2386}
2387
2388Void TComDataCU::setLumaIntraDirSubParts( UInt uiDir, UInt uiAbsPartIdx, UInt uiDepth )
2389{
2390  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2391 
2392  memset( m_puhLumaIntraDir + uiAbsPartIdx, uiDir, sizeof(UChar)*uiCurrPartNumb );
2393}
2394
2395template<typename T>
2396Void TComDataCU::setSubPart( T uiParameter, T* puhBaseLCU, UInt uiCUAddr, UInt uiCUDepth, UInt uiPUIdx )
2397{
2398  assert( sizeof(T) == 1 ); // Using memset() works only for types of size 1
2399 
2400  UInt uiCurrPartNumQ = (m_pcPic->getNumPartInCU() >> (2 * uiCUDepth)) >> 2;
2401  switch ( m_pePartSize[ uiCUAddr ] )
2402  {
2403    case SIZE_2Nx2N:
2404      memset( puhBaseLCU + uiCUAddr, uiParameter, 4 * uiCurrPartNumQ );
2405      break;
2406    case SIZE_2NxN:
2407      memset( puhBaseLCU + uiCUAddr, uiParameter, 2 * uiCurrPartNumQ );
2408      break;
2409    case SIZE_Nx2N:
2410      memset( puhBaseLCU + uiCUAddr, uiParameter, uiCurrPartNumQ );
2411      memset( puhBaseLCU + uiCUAddr + 2 * uiCurrPartNumQ, uiParameter, uiCurrPartNumQ );
2412      break;
2413    case SIZE_NxN:
2414      memset( puhBaseLCU + uiCUAddr, uiParameter, uiCurrPartNumQ ); 
2415      break;
2416    case SIZE_2NxnU:
2417      if ( uiPUIdx == 0 )
2418      {
2419        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 1) );                     
2420        memset( puhBaseLCU + uiCUAddr + uiCurrPartNumQ, uiParameter, (uiCurrPartNumQ >> 1) );                     
2421      }
2422      else if ( uiPUIdx == 1 )
2423      {
2424        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 1) );                     
2425        memset( puhBaseLCU + uiCUAddr + uiCurrPartNumQ, uiParameter, ((uiCurrPartNumQ >> 1) + (uiCurrPartNumQ << 1)) );                     
2426      }
2427      else
2428      {
2429        assert(0);
2430      }
2431      break;
2432    case SIZE_2NxnD:
2433      if ( uiPUIdx == 0 )
2434      {
2435        memset( puhBaseLCU + uiCUAddr, uiParameter, ((uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1)) );                     
2436        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + uiCurrPartNumQ, uiParameter, (uiCurrPartNumQ >> 1) );                     
2437      }
2438      else if ( uiPUIdx == 1 )
2439      {
2440        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 1) );                     
2441        memset( puhBaseLCU + uiCUAddr + uiCurrPartNumQ, uiParameter, (uiCurrPartNumQ >> 1) );                     
2442      }
2443      else
2444      {
2445        assert(0);
2446      }
2447      break;
2448    case SIZE_nLx2N:
2449      if ( uiPUIdx == 0 )
2450      {
2451        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 2) );
2452        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) ); 
2453        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ >> 2) ); 
2454        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) ); 
2455      }
2456      else if ( uiPUIdx == 1 )
2457      {
2458        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 2) );
2459        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) ); 
2460        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ >> 2) ); 
2461        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) ); 
2462      }
2463      else
2464      {
2465        assert(0);
2466      }
2467      break;
2468    case SIZE_nRx2N:
2469      if ( uiPUIdx == 0 )
2470      {     
2471        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) );                           
2472        memset( puhBaseLCU + uiCUAddr + uiCurrPartNumQ + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );                           
2473        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) );                           
2474        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + uiCurrPartNumQ + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );                           
2475      }
2476      else if ( uiPUIdx == 1 )
2477      {
2478        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 2) );                           
2479        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );                           
2480        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ >> 2) );                           
2481        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );                         
2482      }
2483      else
2484      {
2485        assert(0);
2486      }
2487      break;
2488    default:
2489      assert( 0 );
2490  }
2491}
2492
2493#if H_3D_DIM_SDC
2494Void TComDataCU::setSDCFlagSubParts ( Bool bSDCFlag, UInt uiAbsPartIdx, UInt uiDepth )
2495{
2496  assert( sizeof( *m_pbSDCFlag) == 1 );
2497  memset( m_pbSDCFlag + uiAbsPartIdx, bSDCFlag, m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ) );
2498}
2499
2500Bool TComDataCU::getSDCAvailable( UInt uiAbsPartIdx )
2501{
2502  // check general CU information
2503  if( !getSlice()->getIsDepth() || !isIntra(uiAbsPartIdx) || getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N )
2504    return false;
2505 
2506  // check prediction mode
2507  UInt uiLumaPredMode = getLumaIntraDir( uiAbsPartIdx ); 
2508  if( uiLumaPredMode == DC_IDX || uiLumaPredMode == PLANAR_IDX || ( getDimType( uiLumaPredMode ) == DMM1_IDX && !isDimDeltaDC( uiLumaPredMode ) ) )
2509    return true;
2510 
2511  // else
2512  return false;
2513}
2514#endif
2515Void TComDataCU::setMergeFlagSubParts ( Bool bMergeFlag, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
2516{
2517  setSubPart( bMergeFlag, m_pbMergeFlag, uiAbsPartIdx, uiDepth, uiPartIdx );
2518}
2519
2520Void TComDataCU::setMergeIndexSubParts ( UInt uiMergeIndex, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
2521{
2522  setSubPart<UChar>( uiMergeIndex, m_puhMergeIndex, uiAbsPartIdx, uiDepth, uiPartIdx );
2523}
2524
2525#if H_3D_VSP
2526Void TComDataCU::setVSPFlagSubParts( Char iVSPFlag, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
2527{
2528  setSubPart<Char>( iVSPFlag, m_piVSPFlag, uiAbsPartIdx, uiDepth, uiPartIdx );
2529}
2530#if MTK_VSP_FIX_E0172
2531Void TComDataCU::setVSPDirSubParts ( Char iVSPDir, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
2532{
2533  setSubPart<Char>( iVSPDir, m_piVSPDir, uiAbsPartIdx, uiDepth, uiPartIdx );
2534}
2535#endif
2536#endif
2537Void TComDataCU::setChromIntraDirSubParts( UInt uiDir, UInt uiAbsPartIdx, UInt uiDepth )
2538{
2539  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2540 
2541  memset( m_puhChromaIntraDir + uiAbsPartIdx, uiDir, sizeof(UChar)*uiCurrPartNumb );
2542}
2543
2544Void TComDataCU::setInterDirSubParts( UInt uiDir, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
2545{
2546  setSubPart<UChar>( uiDir, m_puhInterDir, uiAbsPartIdx, uiDepth, uiPartIdx );
2547}
2548
2549Void TComDataCU::setMVPIdxSubParts( Int iMVPIdx, RefPicList eRefPicList, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
2550{
2551  setSubPart<Char>( iMVPIdx, m_apiMVPIdx[eRefPicList], uiAbsPartIdx, uiDepth, uiPartIdx );
2552}
2553
2554Void TComDataCU::setMVPNumSubParts( Int iMVPNum, RefPicList eRefPicList, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
2555{
2556  setSubPart<Char>( iMVPNum, m_apiMVPNum[eRefPicList], uiAbsPartIdx, uiDepth, uiPartIdx );
2557}
2558
2559
2560Void TComDataCU::setTrIdxSubParts( UInt uiTrIdx, UInt uiAbsPartIdx, UInt uiDepth )
2561{
2562  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2563 
2564  memset( m_puhTrIdx + uiAbsPartIdx, uiTrIdx, sizeof(UChar)*uiCurrPartNumb );
2565}
2566
2567Void TComDataCU::setTransformSkipSubParts( UInt useTransformSkipY, UInt useTransformSkipU, UInt useTransformSkipV, UInt uiAbsPartIdx, UInt uiDepth )
2568{
2569  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2570
2571  memset( m_puhTransformSkip[0] + uiAbsPartIdx, useTransformSkipY, sizeof( UChar ) * uiCurrPartNumb );
2572  memset( m_puhTransformSkip[1] + uiAbsPartIdx, useTransformSkipU, sizeof( UChar ) * uiCurrPartNumb );
2573  memset( m_puhTransformSkip[2] + uiAbsPartIdx, useTransformSkipV, sizeof( UChar ) * uiCurrPartNumb );
2574}
2575
2576Void TComDataCU::setTransformSkipSubParts( UInt useTransformSkip, TextType eType, UInt uiAbsPartIdx, UInt uiDepth)
2577{
2578  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2579
2580  memset( m_puhTransformSkip[g_aucConvertTxtTypeToIdx[eType]] + uiAbsPartIdx, useTransformSkip, sizeof( UChar ) * uiCurrPartNumb );
2581}
2582
2583Void TComDataCU::setSizeSubParts( UInt uiWidth, UInt uiHeight, UInt uiAbsPartIdx, UInt uiDepth )
2584{
2585  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2586 
2587  memset( m_puhWidth  + uiAbsPartIdx, uiWidth,  sizeof(UChar)*uiCurrPartNumb );
2588  memset( m_puhHeight + uiAbsPartIdx, uiHeight, sizeof(UChar)*uiCurrPartNumb );
2589}
2590
2591UChar TComDataCU::getNumPartInter()
2592{
2593  UChar iNumPart = 0;
2594 
2595  switch ( m_pePartSize[0] )
2596  {
2597    case SIZE_2Nx2N:    iNumPart = 1; break;
2598    case SIZE_2NxN:     iNumPart = 2; break;
2599    case SIZE_Nx2N:     iNumPart = 2; break;
2600    case SIZE_NxN:      iNumPart = 4; break;
2601    case SIZE_2NxnU:    iNumPart = 2; break;
2602    case SIZE_2NxnD:    iNumPart = 2; break;
2603    case SIZE_nLx2N:    iNumPart = 2; break;
2604    case SIZE_nRx2N:    iNumPart = 2; break;
2605    default:            assert (0);   break;
2606  }
2607 
2608  return  iNumPart;
2609}
2610
2611#if H_3D_IC
2612Void TComDataCU::getPartIndexAndSize( UInt uiPartIdx, UInt& ruiPartAddr, Int& riWidth, Int& riHeight, UInt uiAbsPartIdx, Bool bLCU)
2613{
2614  UInt uiNumPartition  = bLCU ? (getWidth(uiAbsPartIdx)*getHeight(uiAbsPartIdx) >> 4) : m_uiNumPartition;
2615  UInt  uiTmpAbsPartIdx  = bLCU ? uiAbsPartIdx : 0;
2616
2617  switch ( m_pePartSize[uiTmpAbsPartIdx] )
2618  {
2619  case SIZE_2NxN:
2620    riWidth = getWidth( uiTmpAbsPartIdx );      riHeight = getHeight( uiTmpAbsPartIdx ) >> 1; ruiPartAddr = ( uiPartIdx == 0 )? 0 : uiNumPartition >> 1;
2621    break;
2622  case SIZE_Nx2N:
2623    riWidth = getWidth( uiTmpAbsPartIdx ) >> 1; riHeight = getHeight( uiTmpAbsPartIdx );      ruiPartAddr = ( uiPartIdx == 0 )? 0 : uiNumPartition >> 2;
2624    break;
2625  case SIZE_NxN:
2626    riWidth = getWidth( uiTmpAbsPartIdx ) >> 1; riHeight = getHeight( uiTmpAbsPartIdx ) >> 1; ruiPartAddr = ( uiNumPartition >> 2 ) * uiPartIdx;
2627    break;
2628  case SIZE_2NxnU:
2629    riWidth     = getWidth( uiTmpAbsPartIdx );
2630    riHeight    = ( uiPartIdx == 0 ) ?  getHeight( uiTmpAbsPartIdx ) >> 2 : ( getHeight( uiTmpAbsPartIdx ) >> 2 ) + ( getHeight( uiTmpAbsPartIdx ) >> 1 );
2631    ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : uiNumPartition >> 3;
2632    break;
2633  case SIZE_2NxnD:
2634    riWidth     = getWidth( uiTmpAbsPartIdx );
2635    riHeight    = ( uiPartIdx == 0 ) ?  ( getHeight( uiTmpAbsPartIdx ) >> 2 ) + ( getHeight( uiTmpAbsPartIdx ) >> 1 ) : getHeight( uiTmpAbsPartIdx ) >> 2;
2636    ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : (uiNumPartition >> 1) + (uiNumPartition >> 3);
2637    break;
2638  case SIZE_nLx2N:
2639    riWidth     = ( uiPartIdx == 0 ) ? getWidth( uiTmpAbsPartIdx ) >> 2 : ( getWidth( uiTmpAbsPartIdx ) >> 2 ) + ( getWidth( uiTmpAbsPartIdx ) >> 1 );
2640    riHeight    = getHeight( uiTmpAbsPartIdx );
2641    ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : uiNumPartition >> 4;
2642    break;
2643  case SIZE_nRx2N:
2644    riWidth     = ( uiPartIdx == 0 ) ? ( getWidth( uiTmpAbsPartIdx ) >> 2 ) + ( getWidth( uiTmpAbsPartIdx ) >> 1 ) : getWidth( uiTmpAbsPartIdx ) >> 2;
2645    riHeight    = getHeight( uiTmpAbsPartIdx );
2646    ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : (uiNumPartition >> 2) + (uiNumPartition >> 4);
2647    break;
2648  default:
2649    assert ( m_pePartSize[uiTmpAbsPartIdx] == SIZE_2Nx2N ); 
2650    riWidth = getWidth( uiTmpAbsPartIdx );      riHeight = getHeight( uiTmpAbsPartIdx );      ruiPartAddr = 0;
2651    break;
2652  }
2653}
2654#else
2655Void TComDataCU::getPartIndexAndSize( UInt uiPartIdx, UInt& ruiPartAddr, Int& riWidth, Int& riHeight )
2656{
2657  switch ( m_pePartSize[0] )
2658  {
2659    case SIZE_2NxN:
2660      riWidth = getWidth(0);      riHeight = getHeight(0) >> 1; ruiPartAddr = ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 1;
2661      break;
2662    case SIZE_Nx2N:
2663      riWidth = getWidth(0) >> 1; riHeight = getHeight(0);      ruiPartAddr = ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 2;
2664      break;
2665    case SIZE_NxN:
2666      riWidth = getWidth(0) >> 1; riHeight = getHeight(0) >> 1; ruiPartAddr = ( m_uiNumPartition >> 2 ) * uiPartIdx;
2667      break;
2668    case SIZE_2NxnU:
2669      riWidth     = getWidth(0);
2670      riHeight    = ( uiPartIdx == 0 ) ?  getHeight(0) >> 2 : ( getHeight(0) >> 2 ) + ( getHeight(0) >> 1 );
2671      ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : m_uiNumPartition >> 3;
2672      break;
2673    case SIZE_2NxnD:
2674      riWidth     = getWidth(0);
2675      riHeight    = ( uiPartIdx == 0 ) ?  ( getHeight(0) >> 2 ) + ( getHeight(0) >> 1 ) : getHeight(0) >> 2;
2676      ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : (m_uiNumPartition >> 1) + (m_uiNumPartition >> 3);
2677      break;
2678    case SIZE_nLx2N:
2679      riWidth     = ( uiPartIdx == 0 ) ? getWidth(0) >> 2 : ( getWidth(0) >> 2 ) + ( getWidth(0) >> 1 );
2680      riHeight    = getHeight(0);
2681      ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : m_uiNumPartition >> 4;
2682      break;
2683    case SIZE_nRx2N:
2684      riWidth     = ( uiPartIdx == 0 ) ? ( getWidth(0) >> 2 ) + ( getWidth(0) >> 1 ) : getWidth(0) >> 2;
2685      riHeight    = getHeight(0);
2686      ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : (m_uiNumPartition >> 2) + (m_uiNumPartition >> 4);
2687      break;
2688    default:
2689      assert ( m_pePartSize[0] == SIZE_2Nx2N );
2690      riWidth = getWidth(0);      riHeight = getHeight(0);      ruiPartAddr = 0;
2691      break;
2692  }
2693}
2694#endif
2695
2696
2697Void TComDataCU::getMvField ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefPicList, TComMvField& rcMvField )
2698{
2699  if ( pcCU == NULL )  // OUT OF BOUNDARY
2700  {
2701    TComMv  cZeroMv;
2702    rcMvField.setMvField( cZeroMv, NOT_VALID );
2703    return;
2704  }
2705 
2706  TComCUMvField*  pcCUMvField = pcCU->getCUMvField( eRefPicList );
2707  rcMvField.setMvField( pcCUMvField->getMv( uiAbsPartIdx ), pcCUMvField->getRefIdx( uiAbsPartIdx ) );
2708}
2709
2710Void TComDataCU::deriveLeftRightTopIdxGeneral ( UInt uiAbsPartIdx, UInt uiPartIdx, UInt& ruiPartIdxLT, UInt& ruiPartIdxRT )
2711{
2712  ruiPartIdxLT = m_uiAbsIdxInLCU + uiAbsPartIdx;
2713  UInt uiPUWidth = 0;
2714 
2715  switch ( m_pePartSize[uiAbsPartIdx] )
2716  {
2717    case SIZE_2Nx2N: uiPUWidth = m_puhWidth[uiAbsPartIdx];  break;
2718    case SIZE_2NxN:  uiPUWidth = m_puhWidth[uiAbsPartIdx];   break;
2719    case SIZE_Nx2N:  uiPUWidth = m_puhWidth[uiAbsPartIdx]  >> 1;  break;
2720    case SIZE_NxN:   uiPUWidth = m_puhWidth[uiAbsPartIdx]  >> 1; break;
2721    case SIZE_2NxnU:   uiPUWidth = m_puhWidth[uiAbsPartIdx]; break;
2722    case SIZE_2NxnD:   uiPUWidth = m_puhWidth[uiAbsPartIdx]; break;
2723    case SIZE_nLx2N:   
2724      if ( uiPartIdx == 0 )
2725      {
2726        uiPUWidth = m_puhWidth[uiAbsPartIdx]  >> 2; 
2727      }
2728      else if ( uiPartIdx == 1 )
2729      {
2730        uiPUWidth = (m_puhWidth[uiAbsPartIdx]  >> 1) + (m_puhWidth[uiAbsPartIdx]  >> 2); 
2731      }
2732      else
2733      {
2734        assert(0);
2735      }
2736      break;
2737    case SIZE_nRx2N:   
2738      if ( uiPartIdx == 0 )
2739      {
2740        uiPUWidth = (m_puhWidth[uiAbsPartIdx]  >> 1) + (m_puhWidth[uiAbsPartIdx]  >> 2); 
2741      }
2742      else if ( uiPartIdx == 1 )
2743      {
2744        uiPUWidth = m_puhWidth[uiAbsPartIdx]  >> 2; 
2745      }
2746      else
2747      {
2748        assert(0);
2749      }
2750      break;
2751    default:
2752      assert (0);
2753      break;
2754  }
2755 
2756  ruiPartIdxRT = g_auiRasterToZscan [g_auiZscanToRaster[ ruiPartIdxLT ] + uiPUWidth / m_pcPic->getMinCUWidth() - 1 ];
2757}
2758
2759Void TComDataCU::deriveLeftBottomIdxGeneral( UInt uiAbsPartIdx, UInt uiPartIdx, UInt& ruiPartIdxLB )
2760{
2761  UInt uiPUHeight = 0;
2762  switch ( m_pePartSize[uiAbsPartIdx] )
2763  {
2764    case SIZE_2Nx2N: uiPUHeight = m_puhHeight[uiAbsPartIdx];    break;
2765    case SIZE_2NxN:  uiPUHeight = m_puhHeight[uiAbsPartIdx] >> 1;    break;
2766    case SIZE_Nx2N:  uiPUHeight = m_puhHeight[uiAbsPartIdx];  break;
2767    case SIZE_NxN:   uiPUHeight = m_puhHeight[uiAbsPartIdx] >> 1;    break;
2768    case SIZE_2NxnU: 
2769      if ( uiPartIdx == 0 )
2770      {
2771        uiPUHeight = m_puhHeight[uiAbsPartIdx] >> 2;   
2772      }
2773      else if ( uiPartIdx == 1 )
2774      {
2775        uiPUHeight = (m_puhHeight[uiAbsPartIdx] >> 1) + (m_puhHeight[uiAbsPartIdx] >> 2);   
2776      }
2777      else
2778      {
2779        assert(0);
2780      }
2781      break;
2782    case SIZE_2NxnD: 
2783      if ( uiPartIdx == 0 )
2784      {
2785        uiPUHeight = (m_puhHeight[uiAbsPartIdx] >> 1) + (m_puhHeight[uiAbsPartIdx] >> 2);   
2786      }
2787      else if ( uiPartIdx == 1 )
2788      {
2789        uiPUHeight = m_puhHeight[uiAbsPartIdx] >> 2;   
2790      }
2791      else
2792      {
2793        assert(0);
2794      }
2795      break;
2796    case SIZE_nLx2N: uiPUHeight = m_puhHeight[uiAbsPartIdx];  break;
2797    case SIZE_nRx2N: uiPUHeight = m_puhHeight[uiAbsPartIdx];  break;
2798    default:
2799      assert (0);
2800      break;
2801  }
2802 
2803  ruiPartIdxLB      = g_auiRasterToZscan [g_auiZscanToRaster[ m_uiAbsIdxInLCU + uiAbsPartIdx ] + ((uiPUHeight / m_pcPic->getMinCUHeight()) - 1)*m_pcPic->getNumPartInWidth()];
2804}
2805
2806Void TComDataCU::deriveLeftRightTopIdx ( UInt uiPartIdx, UInt& ruiPartIdxLT, UInt& ruiPartIdxRT )
2807{
2808  ruiPartIdxLT = m_uiAbsIdxInLCU;
2809  ruiPartIdxRT = g_auiRasterToZscan [g_auiZscanToRaster[ ruiPartIdxLT ] + m_puhWidth[0] / m_pcPic->getMinCUWidth() - 1 ];
2810 
2811  switch ( m_pePartSize[0] )
2812  {
2813    case SIZE_2Nx2N:                                                                                                                                break;
2814    case SIZE_2NxN:
2815      ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 1; ruiPartIdxRT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 1;
2816      break;
2817    case SIZE_Nx2N:
2818      ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 2; ruiPartIdxRT -= ( uiPartIdx == 1 )? 0 : m_uiNumPartition >> 2;
2819      break;
2820    case SIZE_NxN:
2821      ruiPartIdxLT += ( m_uiNumPartition >> 2 ) * uiPartIdx;         ruiPartIdxRT +=  ( m_uiNumPartition >> 2 ) * ( uiPartIdx - 1 );
2822      break;
2823    case SIZE_2NxnU:
2824      ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 3;
2825      ruiPartIdxRT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 3;
2826      break;
2827    case SIZE_2NxnD:
2828      ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : ( m_uiNumPartition >> 1 ) + ( m_uiNumPartition >> 3 );
2829      ruiPartIdxRT += ( uiPartIdx == 0 )? 0 : ( m_uiNumPartition >> 1 ) + ( m_uiNumPartition >> 3 );
2830      break;
2831    case SIZE_nLx2N:
2832      ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 4;
2833      ruiPartIdxRT -= ( uiPartIdx == 1 )? 0 : ( m_uiNumPartition >> 2 ) + ( m_uiNumPartition >> 4 );
2834      break;
2835    case SIZE_nRx2N:
2836      ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : ( m_uiNumPartition >> 2 ) + ( m_uiNumPartition >> 4 );
2837      ruiPartIdxRT -= ( uiPartIdx == 1 )? 0 : m_uiNumPartition >> 4;
2838      break;
2839    default:
2840      assert (0);
2841      break;
2842  }
2843 
2844}
2845
2846Void TComDataCU::deriveLeftBottomIdx( UInt  uiPartIdx,      UInt&      ruiPartIdxLB )
2847{
2848  ruiPartIdxLB      = g_auiRasterToZscan [g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + ( ((m_puhHeight[0] / m_pcPic->getMinCUHeight())>>1) - 1)*m_pcPic->getNumPartInWidth()];
2849 
2850  switch ( m_pePartSize[0] )
2851  {
2852    case SIZE_2Nx2N:
2853      ruiPartIdxLB += m_uiNumPartition >> 1;
2854      break;
2855    case SIZE_2NxN:
2856      ruiPartIdxLB += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 1;
2857      break;
2858    case SIZE_Nx2N:
2859      ruiPartIdxLB += ( uiPartIdx == 0 )? m_uiNumPartition >> 1 : (m_uiNumPartition >> 2)*3;
2860      break;
2861    case SIZE_NxN:
2862      ruiPartIdxLB += ( m_uiNumPartition >> 2 ) * uiPartIdx;
2863      break;
2864    case SIZE_2NxnU:
2865      ruiPartIdxLB += ( uiPartIdx == 0 ) ? -((Int)m_uiNumPartition >> 3) : m_uiNumPartition >> 1;
2866      break;
2867    case SIZE_2NxnD:
2868      ruiPartIdxLB += ( uiPartIdx == 0 ) ? (m_uiNumPartition >> 2) + (m_uiNumPartition >> 3): m_uiNumPartition >> 1;
2869      break;
2870    case SIZE_nLx2N:
2871      ruiPartIdxLB += ( uiPartIdx == 0 ) ? m_uiNumPartition >> 1 : (m_uiNumPartition >> 1) + (m_uiNumPartition >> 4);
2872      break;
2873    case SIZE_nRx2N:
2874      ruiPartIdxLB += ( uiPartIdx == 0 ) ? m_uiNumPartition >> 1 : (m_uiNumPartition >> 1) + (m_uiNumPartition >> 2) + (m_uiNumPartition >> 4);
2875      break;
2876    default:
2877      assert (0);
2878      break;
2879  }
2880}
2881
2882/** Derives the partition index of neighbouring bottom right block
2883 * \param [in]  eCUMode
2884 * \param [in]  uiPartIdx
2885 * \param [out] ruiPartIdxRB
2886 */
2887Void TComDataCU::deriveRightBottomIdx( UInt  uiPartIdx,      UInt&      ruiPartIdxRB )
2888{
2889  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];
2890
2891  switch ( m_pePartSize[0] )
2892  {
2893    case SIZE_2Nx2N: 
2894      ruiPartIdxRB += m_uiNumPartition >> 1;   
2895      break;
2896    case SIZE_2NxN: 
2897      ruiPartIdxRB += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 1;   
2898      break;
2899    case SIZE_Nx2N: 
2900      ruiPartIdxRB += ( uiPartIdx == 0 )? m_uiNumPartition >> 2 : (m_uiNumPartition >> 1);   
2901      break;
2902    case SIZE_NxN:   
2903      ruiPartIdxRB += ( m_uiNumPartition >> 2 ) * ( uiPartIdx - 1 );   
2904      break;
2905    case SIZE_2NxnU:
2906      ruiPartIdxRB += ( uiPartIdx == 0 ) ? -((Int)m_uiNumPartition >> 3) : m_uiNumPartition >> 1;
2907      break;
2908    case SIZE_2NxnD:
2909      ruiPartIdxRB += ( uiPartIdx == 0 ) ? (m_uiNumPartition >> 2) + (m_uiNumPartition >> 3): m_uiNumPartition >> 1;
2910      break;
2911    case SIZE_nLx2N:
2912      ruiPartIdxRB += ( uiPartIdx == 0 ) ? (m_uiNumPartition >> 3) + (m_uiNumPartition >> 4): m_uiNumPartition >> 1;
2913      break;
2914    case SIZE_nRx2N:
2915      ruiPartIdxRB += ( uiPartIdx == 0 ) ? (m_uiNumPartition >> 2) + (m_uiNumPartition >> 3) + (m_uiNumPartition >> 4) : m_uiNumPartition >> 1;
2916      break;
2917    default:
2918      assert (0);
2919      break;
2920  }
2921}
2922
2923Void TComDataCU::deriveLeftRightTopIdxAdi ( UInt& ruiPartIdxLT, UInt& ruiPartIdxRT, UInt uiPartOffset, UInt uiPartDepth )
2924{
2925  UInt uiNumPartInWidth = (m_puhWidth[0]/m_pcPic->getMinCUWidth())>>uiPartDepth;
2926  ruiPartIdxLT = m_uiAbsIdxInLCU + uiPartOffset;
2927  ruiPartIdxRT = g_auiRasterToZscan[ g_auiZscanToRaster[ ruiPartIdxLT ] + uiNumPartInWidth - 1 ];
2928}
2929
2930Void TComDataCU::deriveLeftBottomIdxAdi( UInt& ruiPartIdxLB, UInt uiPartOffset, UInt uiPartDepth )
2931{
2932  UInt uiAbsIdx;
2933  UInt uiMinCuWidth, uiWidthInMinCus;
2934 
2935  uiMinCuWidth    = getPic()->getMinCUWidth();
2936  uiWidthInMinCus = (getWidth(0)/uiMinCuWidth)>>uiPartDepth;
2937  uiAbsIdx        = getZorderIdxInCU()+uiPartOffset+(m_uiNumPartition>>(uiPartDepth<<1))-1;
2938  uiAbsIdx        = g_auiZscanToRaster[uiAbsIdx]-(uiWidthInMinCus-1);
2939  ruiPartIdxLB    = g_auiRasterToZscan[uiAbsIdx];
2940}
2941
2942Bool TComDataCU::hasEqualMotion( UInt uiAbsPartIdx, TComDataCU* pcCandCU, UInt uiCandAbsPartIdx )
2943{
2944
2945  if ( getInterDir( uiAbsPartIdx ) != pcCandCU->getInterDir( uiCandAbsPartIdx ) )
2946  {
2947    return false;
2948  }
2949
2950  for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
2951  {
2952    if ( getInterDir( uiAbsPartIdx ) & ( 1 << uiRefListIdx ) )
2953    {
2954      if ( getCUMvField( RefPicList( uiRefListIdx ) )->getMv( uiAbsPartIdx )     != pcCandCU->getCUMvField( RefPicList( uiRefListIdx ) )->getMv( uiCandAbsPartIdx ) || 
2955        getCUMvField( RefPicList( uiRefListIdx ) )->getRefIdx( uiAbsPartIdx ) != pcCandCU->getCUMvField( RefPicList( uiRefListIdx ) )->getRefIdx( uiCandAbsPartIdx ) )
2956      {
2957        return false;
2958      }
2959    }
2960  }
2961
2962  return true;
2963}
2964
2965#if H_3D_VSP
2966
2967/** Add a VSP merging candidate
2968 * \Inputs
2969 * \param uiPUIdx: PU index within a CU
2970 * \param ucVspMergePos: Specify the VSP merge candidate position
2971 * \param mrgCandIdx: Target merge candidate index. At encoder, it is set equal to -1, such that the whole merge candidate list will be constructed.
2972 * \param pDinfo: The "disparity information" derived from neighboring blocks. Type 1 MV.
2973 * \param uiCount: The next position to add VSP merge candidate
2974 *
2975 * \Outputs
2976 * \param uiCount: The next position to add merge candidate. Will be updated if VSP is successfully added
2977 * \param abCandIsInter: abCandIsInter[iCount] tells that VSP candidate is an Inter candidate, if VSP is successfully added
2978 * \param pcMvFieldNeighbours:   Return combined motion information, then stored to a global buffer
2979 *                                    1) the "disparity vector". Type 1 MV. To be used to fetch a depth block.
2980 *                                    2) the ref index /list.    Type 2 reference picture pointer, typically for texture
2981 * \param puhInterDirNeighbours: Indicate the VSP prediction direction.
2982 * \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
2983 *
2984 * \Return
2985 *   true:  if the VSP candidate is added at the target position
2986 *   false: otherwise
2987 */
2988#if MTK_VSP_FIX_E0172
2989inline Bool TComDataCU::xAddVspCand( UChar ucVspMergePos, Int mrgCandIdx, DisInfo* pDInfo, Int& iCount,
2990                                    Bool* abCandIsInter, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int* vspFlag, Int* vspDir )
2991#else
2992inline Bool TComDataCU::xAddVspCand( UChar ucVspMergePos, Int mrgCandIdx, DisInfo* pDInfo, Int& iCount,
2993                                     Bool* abCandIsInter, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int* vspFlag )
2994#endif
2995{
2996  if ( ucVspMergePos != H_3D_VSP_POSITION || 0 == m_pcSlice->getViewIndex() || !m_pcSlice->getVPS()->getViewSynthesisPredFlag( m_pcSlice->getLayerIdInVps() ) || m_pcSlice->getIsDepth() )
2997    return false;
2998
2999  Int refViewIdx = pDInfo->m_aVIdxCan;
3000  TComPic* picDepth = getSlice()->getIvPic( true, refViewIdx );
3001  if( picDepth == NULL ) // No depth reference avail
3002    return false;
3003 
3004  Bool refViewAvailFlag = false;
3005  UChar predFlag[2] = {0, 0};
3006  Int  iRefListIdX = 0;
3007  Int  iRefListIdY = 0;
3008  Int  i;
3009#if MTK_VSP_FIX_E0172
3010  Int currViewId = m_pcSlice->getViewId();
3011  Int derivedViewId = -1;
3012  Int otherViewId = -1;
3013#endif
3014  for( iRefListIdX = 0; iRefListIdX < 2 && !refViewAvailFlag; iRefListIdX++ )
3015  {
3016    RefPicList eRefPicList = RefPicList( iRefListIdX );
3017    for ( i = 0; i < m_pcSlice->getNumRefIdx(eRefPicList) && !refViewAvailFlag; i++ )
3018    {
3019      Int viewIdxRefInList = m_pcSlice->getRefPic(eRefPicList, i)->getViewIndex();
3020      if ( viewIdxRefInList == refViewIdx )
3021      {
3022        refViewAvailFlag = true;
3023        predFlag[iRefListIdX] = 1;
3024#if MTK_VSP_FIX_E0172
3025        vspDir[iCount] = iRefListIdX;
3026        derivedViewId = m_pcSlice->getRefPic(eRefPicList, i)->getViewId(); 
3027#endif
3028        iRefListIdY = 1 - iRefListIdX;
3029        pcMvFieldNeighbours[(iCount<<1)+iRefListIdX].setMvField( pDInfo->m_acDoNBDV, i );
3030#if H_3D_NBDV
3031        pcMvFieldNeighbours[(iCount<<1)+iRefListIdX].getMv().setIDVFlag (false);
3032#endif
3033      }
3034    }
3035  }
3036
3037  if (m_pcSlice->isInterB() && refViewAvailFlag)
3038  {
3039    RefPicList eRefPicList = RefPicList( iRefListIdY );
3040    refViewAvailFlag = false;
3041    for ( i = 0; i < m_pcSlice->getNumRefIdx(eRefPicList) && !refViewAvailFlag; i++ )
3042    {
3043      Int viewIdxRefInList = m_pcSlice->getRefPic(eRefPicList, i)->getViewIndex();
3044      if ( viewIdxRefInList != refViewIdx && viewIdxRefInList != m_pcSlice->getViewIndex() )
3045      {
3046        refViewAvailFlag = true;
3047        predFlag[iRefListIdY] = 1;
3048#if MTK_VSP_FIX_E0172
3049        TComMv  cMv = pDInfo->m_acDoNBDV;
3050        otherViewId = m_pcSlice->getRefPic( eRefPicList, i)->getViewId();
3051        Int iScale = xGetDistScaleFactor( currViewId, otherViewId, currViewId, derivedViewId );
3052        if ( iScale != 4096 && m_pcSlice->getVPS()->getIvMvScalingFlag() ) 
3053        {
3054          cMv = cMv.scaleMv( iScale );
3055        }
3056        else
3057        {
3058
3059          cMv = cMv;
3060        }
3061        clipMv( cMv );
3062        pcMvFieldNeighbours[(iCount<<1)+iRefListIdY].setMvField( cMv, i );
3063#else
3064        pcMvFieldNeighbours[(iCount<<1)+iRefListIdY].setMvField( pDInfo->m_acDoNBDV, i );
3065#endif
3066#if H_3D_NBDV
3067        pcMvFieldNeighbours[(iCount<<1)+iRefListIdY].getMv().setIDVFlag (false);
3068#endif
3069      }
3070    }
3071  }
3072
3073  // Set values to be returned
3074  abCandIsInter[iCount] = true;
3075  puhInterDirNeighbours[iCount] = (predFlag[0] | (predFlag[1] << 1));
3076  vspFlag[iCount] = 1;
3077
3078  if ( mrgCandIdx == iCount )
3079    return true;
3080
3081  iCount++;
3082
3083  return false;
3084}
3085
3086#endif
3087/** Constructs a list of merging candidates
3088 * \param uiAbsPartIdx
3089 * \param uiPUIdx
3090 * \param uiDepth
3091 * \param pcMvFieldNeighbours
3092 * \param puhInterDirNeighbours
3093 * \param numValidMergeCand
3094 */
3095Void TComDataCU::getInterMergeCandidates( UInt uiAbsPartIdx, UInt uiPUIdx, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours
3096#if H_3D_VSP
3097      , Int* vspFlag
3098#if MTK_VSP_FIX_E0172
3099      , Int* vspDir
3100#endif
3101#endif
3102      , Int& numValidMergeCand, Int mrgCandIdx
3103)
3104{
3105  UInt uiAbsPartAddr = m_uiAbsIdxInLCU + uiAbsPartIdx;
3106#if H_3D_IV_MERGE
3107  TComMv cZeroMv;
3108  Bool abCandIsInter[ MRG_MAX_NUM_CANDS_MEM ];
3109#else
3110  Bool abCandIsInter[ MRG_MAX_NUM_CANDS ];
3111#endif
3112  for( UInt ui = 0; ui < getSlice()->getMaxNumMergeCand(); ++ui )
3113  {
3114    abCandIsInter[ui] = false;
3115#if H_3D_IV_MERGE
3116    pcMvFieldNeighbours[ ( ui << 1 )     ].setMvField(cZeroMv, NOT_VALID);
3117    pcMvFieldNeighbours[ ( ui << 1 ) + 1 ].setMvField(cZeroMv, NOT_VALID);
3118#else
3119    pcMvFieldNeighbours[ ( ui << 1 )     ].setRefIdx(NOT_VALID);
3120    pcMvFieldNeighbours[ ( ui << 1 ) + 1 ].setRefIdx(NOT_VALID);
3121#endif
3122  }
3123  numValidMergeCand = getSlice()->getMaxNumMergeCand();
3124  // compute the location of the current PU
3125  Int xP, yP, nPSW, nPSH;
3126  this->getPartPosition(uiPUIdx, xP, yP, nPSW, nPSH);
3127
3128  Int iCount = 0;
3129
3130  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB;
3131  PartSize cCurPS = getPartitionSize( uiAbsPartIdx );
3132  deriveLeftRightTopIdxGeneral( uiAbsPartIdx, uiPUIdx, uiPartIdxLT, uiPartIdxRT );
3133  deriveLeftBottomIdxGeneral  ( uiAbsPartIdx, uiPUIdx, uiPartIdxLB );
3134#if H_3D_IV_MERGE
3135  Bool ivMvPredFlag   = getSlice()->getVPS()->getIvMvPredFlag( getSlice()->getLayerIdInVps() );
3136
3137  //===== add merge with predicted depth maps =====
3138  TComMv  acPdmMv       [4];
3139  Int     aiPdmRefIdx   [4] = {-1, -1, -1, -1};
3140  Bool    bLeftAvai         = false;
3141  Int     iPosLeftAbove[2]  = {-1, -1};
3142
3143
3144  DisInfo cDisInfo;
3145
3146  cDisInfo.bDV = getDvInfo(uiAbsPartIdx).bDV;
3147#if H_3D_NBDV_REF
3148  cDisInfo.m_acDoNBDV = getDvInfo(uiAbsPartIdx).m_acDoNBDV;
3149#endif //H_3D_NBDV_REF
3150  cDisInfo.m_acNBDV = getDvInfo(uiAbsPartIdx).m_acNBDV;
3151  cDisInfo.m_aVIdxCan = getDvInfo(uiAbsPartIdx).m_aVIdxCan;
3152
3153  if( m_pcSlice->getIsDepth())
3154  {
3155    UInt uiPartIdxCenter;
3156    xDeriveCenterIdx( uiPUIdx, uiPartIdxCenter );   
3157    TComDataCU *pcTextureCU = m_pcSlice->getTexturePic()->getCU( getAddr() );
3158 
3159    if ( pcTextureCU && !pcTextureCU->isIntra( uiPartIdxCenter ) )
3160    {
3161#if MTK_TEXTURE_MRGCAND_BUGFIX_E0182
3162      pcTextureCU->getMvField( pcTextureCU, uiPartIdxCenter, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3163      Int iValidDepRef = getPic()->isTextRefValid( REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1].getRefIdx() );
3164      if( (pcMvFieldNeighbours[iCount<<1].getRefIdx()>=0) && ( iValidDepRef >= 0 ) )
3165      {
3166        TComMv cMvPred = pcMvFieldNeighbours[iCount<<1].getMv();
3167        const TComMv cAdd( 1 << ( 2 - 1 ), 1 << ( 2 - 1 ) );
3168        cMvPred+=cAdd;
3169        cMvPred>>=2;
3170        clipMv(cMvPred);
3171        pcMvFieldNeighbours[iCount<<1].setMvField(cMvPred,iValidDepRef);
3172      }
3173
3174      if ( getSlice()->isInterB() )
3175      {
3176        pcTextureCU->getMvField( pcTextureCU, uiPartIdxCenter, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3177        iValidDepRef = getPic()->isTextRefValid( REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1].getRefIdx() );
3178        if( (pcMvFieldNeighbours[(iCount<<1)+1].getRefIdx()>=0) && ( iValidDepRef >= 0) )
3179        {
3180          TComMv cMvPred = pcMvFieldNeighbours[(iCount<<1)+1].getMv();
3181          const TComMv cAdd( 1 << ( 2 - 1 ), 1 << ( 2 - 1 ) );
3182          cMvPred+=cAdd;
3183          cMvPred>>=2;
3184          clipMv(cMvPred);
3185          pcMvFieldNeighbours[(iCount<<1)+1].setMvField(cMvPred,iValidDepRef);
3186        }
3187      }
3188
3189      puhInterDirNeighbours[iCount] = (pcMvFieldNeighbours[iCount<<1].getRefIdx()>=0)?1:0;
3190      puhInterDirNeighbours[iCount] += (pcMvFieldNeighbours[(iCount<<1)+1].getRefIdx()>=0)?2:0;
3191
3192      if( puhInterDirNeighbours[iCount] != 0 )
3193      {
3194        abCandIsInter[iCount] = true;
3195        if ( mrgCandIdx == iCount )
3196        {
3197          return;
3198        }
3199        iCount ++;
3200      }
3201#else
3202      abCandIsInter[iCount] = true;     
3203      puhInterDirNeighbours[iCount] = pcTextureCU->getInterDir( uiPartIdxCenter );
3204      if( ( puhInterDirNeighbours[iCount] & 1 ) == 1 )
3205      {
3206        pcTextureCU->getMvField( pcTextureCU, uiPartIdxCenter, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3207        TComMv cMvPred = pcMvFieldNeighbours[iCount<<1].getMv();
3208
3209#if H_3D_IC
3210        const TComMv cAdd( 1 << ( 2 - 1 ), 1 << ( 2 - 1 ) );
3211        cMvPred+=cAdd;
3212        cMvPred>>=2;
3213        clipMv(cMvPred);
3214#endif
3215        //pcMvFieldNeighbours[iCount<<1].setMvField(cMvPred,pcMvFieldNeighbours[iCount<<1].getRefIdx());
3216#if H_3D //Notes from QC: for BVSP coded blocks, the reference index shall not be equal to -1 due to the adoption of JCT3V-D0191
3217        pcMvFieldNeighbours[iCount<<1].setMvField(cMvPred,pcMvFieldNeighbours[iCount<<1].getRefIdx());
3218#endif
3219      }
3220     
3221      if ( getSlice()->isInterB() )
3222      {
3223        if( ( puhInterDirNeighbours[iCount] & 2 ) == 2 )
3224        {
3225          pcTextureCU->getMvField( pcTextureCU, uiPartIdxCenter, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3226          TComMv cMvPred = pcMvFieldNeighbours[(iCount<<1)+1].getMv();
3227#if H_3D_IC
3228          const TComMv cAdd( 1 << ( 2 - 1 ), 1 << ( 2 - 1 ) );
3229          cMvPred+=cAdd;
3230          cMvPred>>=2;
3231          clipMv(cMvPred);
3232#endif
3233          pcMvFieldNeighbours[(iCount<<1)+1].setMvField(cMvPred,pcMvFieldNeighbours[(iCount<<1)+1].getRefIdx());
3234        }
3235      }
3236#if H_3D_NBDV
3237      pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3238      pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3239#endif
3240      if ( mrgCandIdx == iCount )
3241      {
3242        return;
3243      }
3244      iCount ++;
3245#endif//Bug fix
3246    }
3247  }
3248
3249  Int iPdmDir[2] = {0, 0};
3250 
3251  if ( ivMvPredFlag )
3252  {
3253    getInterViewMergeCands(uiPUIdx, aiPdmRefIdx, acPdmMv, &cDisInfo, iPdmDir );
3254  } 
3255   
3256  Int iPdmInterDir;
3257
3258  if( iPdmDir[0] )
3259  {
3260    abCandIsInter        [ iCount ] = true;
3261    puhInterDirNeighbours[ iCount ] = iPdmDir[0];
3262    iPdmInterDir                    = iPdmDir[0];
3263
3264    if( ( iPdmInterDir & 1 ) == 1 )
3265    {
3266      pcMvFieldNeighbours[ iCount<<1    ].setMvField( acPdmMv[ 0 ], aiPdmRefIdx[ 0 ] );
3267    }
3268    if( ( iPdmInterDir & 2 ) == 2 )
3269    {
3270      pcMvFieldNeighbours[(iCount<<1)+1 ].setMvField( acPdmMv[ 1 ], aiPdmRefIdx[ 1 ] );
3271    }
3272
3273    if ( mrgCandIdx == iCount )
3274    {
3275      return;
3276    }
3277    iCount ++;
3278  } 
3279  // early termination
3280  if (iCount == getSlice()->getMaxNumMergeCand()) 
3281  {
3282    return;
3283  }
3284#endif
3285
3286  //left
3287  UInt uiLeftPartIdx = 0;
3288  TComDataCU* pcCULeft = 0;
3289  pcCULeft = getPULeft( uiLeftPartIdx, uiPartIdxLB );
3290  Bool isAvailableA1 = pcCULeft &&
3291  pcCULeft->isDiffMER(xP -1, yP+nPSH-1, xP, yP) &&
3292  !( uiPUIdx == 1 && (cCurPS == SIZE_Nx2N || cCurPS == SIZE_nLx2N || cCurPS == SIZE_nRx2N) ) &&
3293  !pcCULeft->isIntra( uiLeftPartIdx ) ;
3294  if ( isAvailableA1 )
3295  {
3296    abCandIsInter[iCount] = true;
3297    // get Inter Dir
3298    puhInterDirNeighbours[iCount] = pcCULeft->getInterDir( uiLeftPartIdx );
3299    // get Mv from Left
3300    pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3301    if ( getSlice()->isInterB() )
3302    {
3303      pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3304    }
3305#if H_3D_IV_MERGE
3306    Bool bRemoveSpa = false; //pruning to inter-view candidates
3307    Int  iCnloop    = iCount - 1;
3308    for(; iCnloop >= 0; iCnloop --)
3309    {
3310      if(puhInterDirNeighbours[iCount] == puhInterDirNeighbours[iCnloop] && pcMvFieldNeighbours[iCnloop<<1]==pcMvFieldNeighbours[(iCount<<1)] && pcMvFieldNeighbours[(iCnloop<<1)+1]==pcMvFieldNeighbours[(iCount<<1)+1])
3311      {
3312        bRemoveSpa                      = true;
3313        abCandIsInter        [ iCount ] = false;
3314
3315        //reset to the default value for MC
3316        puhInterDirNeighbours[iCount]   = 0;
3317        pcMvFieldNeighbours[iCount<<1].setMvField( cZeroMv, NOT_VALID );
3318        pcMvFieldNeighbours[(iCount<<1)+1].setMvField( cZeroMv, NOT_VALID );
3319        break;
3320      }
3321    }
3322    if(!bRemoveSpa)
3323    {
3324      bLeftAvai = true;
3325      iPosLeftAbove[0] = iCount;
3326#if H_3D_NBDV
3327      pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3328      pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3329#endif
3330#if H_3D_VSP
3331      if (pcCULeft->getVSPFlag(uiLeftPartIdx) == 1)
3332#if MTK_VSP_FIX_E0172
3333      {
3334#endif
3335        vspFlag[iCount] = 1;
3336#if MTK_VSP_FIX_E0172
3337        vspDir[iCount] = pcCULeft->getVSPDir( uiLeftPartIdx );
3338      }
3339#endif
3340#endif
3341      if ( mrgCandIdx == iCount )
3342      {
3343        return;
3344      }
3345      iCount ++;
3346    }
3347#else
3348    if ( mrgCandIdx == iCount )
3349    {
3350      return;
3351    }
3352    iCount ++;
3353#endif
3354  }
3355 
3356  // early termination
3357  if (iCount == getSlice()->getMaxNumMergeCand()) 
3358  {
3359    return;
3360  }
3361  // above
3362  UInt uiAbovePartIdx = 0;
3363  TComDataCU* pcCUAbove = 0;
3364  pcCUAbove = getPUAbove( uiAbovePartIdx, uiPartIdxRT );
3365  Bool isAvailableB1 = pcCUAbove &&
3366  pcCUAbove->isDiffMER(xP+nPSW-1, yP-1, xP, yP) &&
3367  !( uiPUIdx == 1 && (cCurPS == SIZE_2NxN || cCurPS == SIZE_2NxnU || cCurPS == SIZE_2NxnD) ) &&
3368  !pcCUAbove->isIntra( uiAbovePartIdx );
3369  if ( isAvailableB1 && (!isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAbove, uiAbovePartIdx ) ) )
3370  {
3371    abCandIsInter[iCount] = true;
3372    // get Inter Dir
3373    puhInterDirNeighbours[iCount] = pcCUAbove->getInterDir( uiAbovePartIdx );
3374    // get Mv from Left
3375    pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3376    if ( getSlice()->isInterB() )
3377    {
3378      pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3379    }
3380#if H_3D_IV_MERGE
3381    Bool bRemoveSpa = false; //pruning to inter-view candidates
3382    Int  iCnloop    = bLeftAvai? (iCount-2): (iCount-1);
3383    for(; iCnloop >= 0; iCnloop --)
3384    {
3385      if(puhInterDirNeighbours[iCount] == puhInterDirNeighbours[iCnloop] && pcMvFieldNeighbours[iCnloop<<1]==pcMvFieldNeighbours[(iCount<<1)] && pcMvFieldNeighbours[(iCnloop<<1)+1]==pcMvFieldNeighbours[(iCount<<1)+1])
3386      {
3387        bRemoveSpa                      = true;
3388        abCandIsInter        [ iCount ] = false;
3389
3390        //reset to the default value for MC
3391        puhInterDirNeighbours[iCount]   = 0;
3392
3393        pcMvFieldNeighbours[iCount<<1].setMvField( cZeroMv, NOT_VALID );
3394        pcMvFieldNeighbours[(iCount<<1)+1].setMvField( cZeroMv, NOT_VALID );
3395        break;
3396      }
3397    }
3398    if(!bRemoveSpa)
3399    {
3400      iPosLeftAbove[1] = iCount;
3401#if H_3D_NBDV
3402      pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3403      pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3404#endif
3405#if H_3D_VSP
3406      if (pcCUAbove->getVSPFlag(uiAbovePartIdx) == 1)
3407#if MTK_VSP_FIX_E0172
3408      {
3409#endif
3410        vspFlag[iCount] = 1;
3411#if MTK_VSP_FIX_E0172
3412        vspDir[iCount] = pcCUAbove->getVSPDir( uiAbovePartIdx );
3413      }
3414#endif
3415#endif
3416      if ( mrgCandIdx == iCount )
3417      {
3418        return;
3419      }
3420      iCount ++;
3421    }
3422#else
3423    if ( mrgCandIdx == iCount )
3424    {
3425      return;
3426    }
3427    iCount ++;
3428#endif
3429  }
3430  // early termination
3431  if (iCount == getSlice()->getMaxNumMergeCand()) 
3432  {
3433    return;
3434  }
3435
3436  // above right
3437  UInt uiAboveRightPartIdx = 0;
3438  TComDataCU* pcCUAboveRight = 0;
3439  pcCUAboveRight = getPUAboveRight( uiAboveRightPartIdx, uiPartIdxRT );
3440  Bool isAvailableB0 = pcCUAboveRight &&
3441  pcCUAboveRight->isDiffMER(xP+nPSW, yP-1, xP, yP) &&
3442  !pcCUAboveRight->isIntra( uiAboveRightPartIdx );
3443  if ( isAvailableB0 && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveRight, uiAboveRightPartIdx ) ) )
3444  {
3445    abCandIsInter[iCount] = true;
3446    // get Inter Dir
3447    puhInterDirNeighbours[iCount] = pcCUAboveRight->getInterDir( uiAboveRightPartIdx );
3448    // get Mv from Left
3449    pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3450    if ( getSlice()->isInterB() )
3451    {
3452      pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3453    }
3454#if H_3D_NBDV
3455    pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3456    pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3457#endif
3458#if H_3D_VSP
3459    if (pcCUAboveRight->getVSPFlag(uiAboveRightPartIdx) == 1)
3460#if MTK_VSP_FIX_E0172
3461    {
3462#endif
3463      vspFlag[iCount] = 1;
3464#if MTK_VSP_FIX_E0172
3465      vspDir[iCount] = pcCUAboveRight->getVSPDir( uiAboveRightPartIdx);
3466    }
3467#endif
3468#endif
3469    if ( mrgCandIdx == iCount )
3470    {
3471      return;
3472    }
3473    iCount ++;
3474  }
3475  // early termination
3476  if (iCount == getSlice()->getMaxNumMergeCand()) 
3477  {
3478    return;
3479  }
3480
3481#if H_3D_IV_MERGE
3482  if( iPdmDir[1] )
3483  {
3484    assert(iCount < getSlice()->getMaxNumMergeCand());
3485    abCandIsInter        [ iCount ] = true;
3486    puhInterDirNeighbours[ iCount ] = iPdmDir[1];
3487    if( ( iPdmDir[1] & 1 ) == 1 )
3488    {
3489      pcMvFieldNeighbours[ iCount<<1    ].setMvField( acPdmMv[ 2 ], aiPdmRefIdx[ 2 ] );
3490    }
3491    if( ( iPdmDir[1] & 2 ) == 2 )
3492    {
3493      pcMvFieldNeighbours[(iCount<<1)+1 ].setMvField( acPdmMv[ 3 ], aiPdmRefIdx[ 3 ] );
3494    }
3495
3496    Bool bRemoveSpa = false; //pruning to A1, B1
3497    for(Int i = 0; i < 2; i ++)
3498    {
3499      Int iCnloop = iPosLeftAbove[i];
3500      if(iCnloop == -1) 
3501        continue;
3502      if(puhInterDirNeighbours[iCount] == puhInterDirNeighbours[iCnloop] && pcMvFieldNeighbours[iCnloop<<1]==pcMvFieldNeighbours[(iCount<<1)] && pcMvFieldNeighbours[(iCnloop<<1)+1]==pcMvFieldNeighbours[(iCount<<1)+1])
3503      {
3504        bRemoveSpa                      = true;
3505        abCandIsInter        [ iCount ] = false;
3506        //reset to the default value for MC
3507        puhInterDirNeighbours[iCount]   = 0;
3508        pcMvFieldNeighbours[iCount<<1].setMvField( cZeroMv, NOT_VALID );
3509        pcMvFieldNeighbours[(iCount<<1)+1].setMvField( cZeroMv, NOT_VALID );
3510        break;
3511      }     
3512    }
3513    if(!bRemoveSpa)
3514    {
3515#if H_3D_NBDV
3516      pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3517      pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3518#endif
3519      if ( mrgCandIdx == iCount )
3520        return;
3521      iCount ++;
3522
3523      // early termination
3524      if (iCount == getSlice()->getMaxNumMergeCand()) 
3525      {
3526        return;
3527      }
3528    }
3529  } 
3530#endif
3531
3532#if H_3D_VSP
3533#if MTK_VSP_FIX_E0172
3534  if ( xAddVspCand( H_3D_VSP_POSITION, mrgCandIdx, &cDisInfo, iCount, abCandIsInter, pcMvFieldNeighbours, puhInterDirNeighbours, vspFlag, vspDir ) )
3535#else
3536  if ( xAddVspCand( H_3D_VSP_POSITION, mrgCandIdx, &cDisInfo, iCount, abCandIsInter, pcMvFieldNeighbours, puhInterDirNeighbours, vspFlag ) )
3537#endif
3538    return;
3539  // early termination
3540  if (iCount == getSlice()->getMaxNumMergeCand())
3541    return;
3542#endif
3543
3544  //left bottom
3545  UInt uiLeftBottomPartIdx = 0;
3546  TComDataCU* pcCULeftBottom = 0;
3547  pcCULeftBottom = this->getPUBelowLeft( uiLeftBottomPartIdx, uiPartIdxLB );
3548  Bool isAvailableA0 = pcCULeftBottom &&
3549  pcCULeftBottom->isDiffMER(xP-1, yP+nPSH, xP, yP) &&
3550  !pcCULeftBottom->isIntra( uiLeftBottomPartIdx ) ;
3551  if ( isAvailableA0 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCULeftBottom, uiLeftBottomPartIdx ) ) )
3552  {
3553    abCandIsInter[iCount] = true;
3554    // get Inter Dir
3555    puhInterDirNeighbours[iCount] = pcCULeftBottom->getInterDir( uiLeftBottomPartIdx );
3556    // get Mv from Left
3557    pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3558    if ( getSlice()->isInterB() )
3559    {
3560      pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3561    }
3562#if H_3D_NBDV
3563    pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3564    pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3565#endif
3566#if H_3D_VSP
3567    if (pcCULeftBottom->getVSPFlag(uiLeftBottomPartIdx) == 1)
3568#if MTK_VSP_FIX_E0172
3569    {
3570#endif
3571      vspFlag[iCount] = 1;
3572#if MTK_VSP_FIX_E0172
3573      vspDir[iCount] = pcCULeftBottom->getVSPDir( uiLeftBottomPartIdx);
3574    }
3575#endif
3576#endif
3577    if ( mrgCandIdx == iCount )
3578    {
3579      return;
3580    }
3581    iCount ++;
3582  }
3583  // early termination
3584  if (iCount == getSlice()->getMaxNumMergeCand()) 
3585  {
3586    return;
3587  }
3588  // above left
3589  if( iCount < 4 )
3590  {
3591    UInt uiAboveLeftPartIdx = 0;
3592    TComDataCU* pcCUAboveLeft = 0;
3593    pcCUAboveLeft = getPUAboveLeft( uiAboveLeftPartIdx, uiAbsPartAddr );
3594    Bool isAvailableB2 = pcCUAboveLeft &&
3595    pcCUAboveLeft->isDiffMER(xP-1, yP-1, xP, yP) &&
3596    !pcCUAboveLeft->isIntra( uiAboveLeftPartIdx );
3597    if ( isAvailableB2 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) )
3598        && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) ) )
3599    {
3600      abCandIsInter[iCount] = true;
3601      // get Inter Dir
3602      puhInterDirNeighbours[iCount] = pcCUAboveLeft->getInterDir( uiAboveLeftPartIdx );
3603      // get Mv from Left
3604      pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3605      if ( getSlice()->isInterB() )
3606      {
3607        pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3608      }
3609#if H_3D_NBDV
3610      pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3611      pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3612#endif
3613#if H_3D_VSP
3614      if (pcCUAboveLeft->getVSPFlag(uiAboveLeftPartIdx) == 1)
3615#if MTK_VSP_FIX_E0172
3616      {
3617#endif
3618        vspFlag[iCount] = 1;
3619#if MTK_VSP_FIX_E0172
3620        vspDir[iCount] = pcCUAboveLeft->getVSPDir( uiAboveLeftPartIdx);
3621      }
3622#endif
3623#endif
3624      if ( mrgCandIdx == iCount )
3625      {
3626        return;
3627      }
3628      iCount ++;
3629    }
3630  }
3631  // early termination
3632  if (iCount == getSlice()->getMaxNumMergeCand()) 
3633  {
3634    return;
3635  }
3636  if ( getSlice()->getEnableTMVPFlag())
3637  {
3638    //>> MTK colocated-RightBottom
3639    UInt uiPartIdxRB;
3640
3641    deriveRightBottomIdx( uiPUIdx, uiPartIdxRB ); 
3642
3643    UInt uiAbsPartIdxTmp = g_auiZscanToRaster[uiPartIdxRB];
3644    UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
3645
3646    TComMv cColMv;
3647    Int iRefIdx;
3648    Int uiLCUIdx = -1;
3649
3650    if      ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
3651    {
3652    }
3653    else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxTmp] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
3654    {
3655    }
3656    else
3657    {
3658      if ( ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
3659        ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
3660      {
3661        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + uiNumPartInCUWidth + 1 ];
3662        uiLCUIdx = getAddr();
3663      }
3664      else if ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
3665      {
3666        uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdxTmp + uiNumPartInCUWidth + 1) % m_pcPic->getNumPartInCU() ];
3667      }
3668      else if ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
3669      {
3670        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + 1 ];
3671        uiLCUIdx = getAddr() + 1;
3672      }
3673      else //is the right bottom corner of LCU                       
3674      {
3675        uiAbsPartAddr = 0;
3676      }
3677    }
3678   
3679   
3680    iRefIdx = 0;
3681    Bool bExistMV = false;
3682    UInt uiPartIdxCenter;
3683    UInt uiCurLCUIdx = getAddr();
3684    Int dir = 0;
3685    UInt uiArrayAddr = iCount;
3686    xDeriveCenterIdx( uiPUIdx, uiPartIdxCenter );
3687    bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_0, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx );
3688    if( bExistMV == false )
3689    {
3690      bExistMV = xGetColMVP( REF_PIC_LIST_0, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
3691    }
3692    if( bExistMV )
3693    {
3694      dir |= 1;
3695      pcMvFieldNeighbours[ 2 * uiArrayAddr ].setMvField( cColMv, iRefIdx );
3696    }
3697
3698    if ( getSlice()->isInterB() )
3699    {
3700#if H_3D_TMVP
3701      iRefIdx = 0;
3702#endif
3703      bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_1, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx);
3704      if( bExistMV == false )
3705      {
3706        bExistMV = xGetColMVP( REF_PIC_LIST_1, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
3707      }
3708      if( bExistMV )
3709      {
3710        dir |= 2;
3711        pcMvFieldNeighbours[ 2 * uiArrayAddr + 1 ].setMvField( cColMv, iRefIdx );
3712      }
3713    }
3714   
3715    if (dir != 0)
3716    {
3717      puhInterDirNeighbours[uiArrayAddr] = dir;
3718      abCandIsInter[uiArrayAddr] = true;
3719#if H_3D_NBDV
3720      pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3721      pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3722#endif
3723      if ( mrgCandIdx == iCount )
3724      {
3725        return;
3726      }
3727      iCount++;
3728    }
3729  }
3730  // early termination
3731  if (iCount == getSlice()->getMaxNumMergeCand()) 
3732  {
3733    return;
3734  }
3735  UInt uiArrayAddr = iCount;
3736  UInt uiCutoff = uiArrayAddr;
3737   
3738  if ( getSlice()->isInterB())
3739  {
3740#if H_3D_IV_MERGE
3741    UInt uiPriorityList0[20] = {0 , 1, 0, 2, 1, 2, 0, 3, 1, 3, 2, 3,    0, 4, 1, 4, 2, 4, 3, 4 };
3742    UInt uiPriorityList1[20] = {1 , 0, 2, 0, 2, 1, 3, 0, 3, 1, 3, 2,    4, 0, 4, 1, 4, 2, 4, 3 };
3743#else
3744    UInt uiPriorityList0[12] = {0 , 1, 0, 2, 1, 2, 0, 3, 1, 3, 2, 3};
3745    UInt uiPriorityList1[12] = {1 , 0, 2, 0, 2, 1, 3, 0, 3, 1, 3, 2};
3746#endif
3747
3748    for (Int idx=0; idx<uiCutoff*(uiCutoff-1) && uiArrayAddr!= getSlice()->getMaxNumMergeCand(); idx++)
3749    {
3750      Int i = uiPriorityList0[idx]; Int j = uiPriorityList1[idx];
3751#if H_3D_VSP
3752      Bool bValid = true;
3753      if ( vspFlag[i] == 1 || vspFlag[j] == 1 )
3754        bValid = false;
3755      if( !m_pcSlice->getVPS()->getViewSynthesisPredFlag( m_pcSlice->getLayerIdInVps() ) )
3756        assert(bValid == true);
3757#endif
3758#if H_3D_VSP
3759      if (abCandIsInter[i] && abCandIsInter[j] && (puhInterDirNeighbours[i]&0x1) && (puhInterDirNeighbours[j]&0x2) && bValid)
3760#else
3761      if (abCandIsInter[i] && abCandIsInter[j]&& (puhInterDirNeighbours[i]&0x1)&&(puhInterDirNeighbours[j]&0x2))
3762#endif
3763      {
3764        abCandIsInter[uiArrayAddr] = true;
3765        puhInterDirNeighbours[uiArrayAddr] = 3;
3766
3767        // get Mv from cand[i] and cand[j]
3768        pcMvFieldNeighbours[uiArrayAddr << 1].setMvField(pcMvFieldNeighbours[i<<1].getMv(), pcMvFieldNeighbours[i<<1].getRefIdx());
3769        pcMvFieldNeighbours[( uiArrayAddr << 1 ) + 1].setMvField(pcMvFieldNeighbours[(j<<1)+1].getMv(), pcMvFieldNeighbours[(j<<1)+1].getRefIdx());
3770
3771        Int iRefPOCL0 = m_pcSlice->getRefPOC( REF_PIC_LIST_0, pcMvFieldNeighbours[(uiArrayAddr<<1)].getRefIdx() );
3772        Int iRefPOCL1 = m_pcSlice->getRefPOC( REF_PIC_LIST_1, pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getRefIdx() );
3773        if (iRefPOCL0 == iRefPOCL1 && pcMvFieldNeighbours[(uiArrayAddr<<1)].getMv() == pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getMv())
3774        {
3775          abCandIsInter[uiArrayAddr] = false;
3776        }
3777        else
3778        {
3779          uiArrayAddr++;
3780        }
3781      }
3782    }
3783  }
3784  // early termination
3785  if (uiArrayAddr == getSlice()->getMaxNumMergeCand()) 
3786  {
3787    return;
3788  }
3789  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);
3790  Int r = 0;
3791  Int refcnt = 0;
3792  while (uiArrayAddr < getSlice()->getMaxNumMergeCand())
3793  {
3794    abCandIsInter[uiArrayAddr] = true;
3795    puhInterDirNeighbours[uiArrayAddr] = 1;
3796    pcMvFieldNeighbours[uiArrayAddr << 1].setMvField( TComMv(0, 0), r);
3797
3798    if ( getSlice()->isInterB() )
3799    {
3800      puhInterDirNeighbours[uiArrayAddr] = 3;
3801      pcMvFieldNeighbours[(uiArrayAddr << 1) + 1].setMvField(TComMv(0, 0), r);
3802    }
3803    uiArrayAddr++;
3804    if ( refcnt == iNumRefIdx - 1 )
3805    {
3806      r = 0;
3807    }
3808    else
3809    {
3810      ++r;
3811      ++refcnt;
3812    }
3813  }
3814
3815  numValidMergeCand = uiArrayAddr;
3816}
3817
3818/** Check whether the current PU and a spatial neighboring PU are in a same ME region.
3819 * \param xN, xN   location of the upper-left corner pixel of a neighboring PU
3820 * \param xP, yP   location of the upper-left corner pixel of the current PU
3821 * \returns Bool
3822 */
3823Bool TComDataCU::isDiffMER(Int xN, Int yN, Int xP, Int yP)
3824{
3825
3826  UInt plevel = this->getSlice()->getPPS()->getLog2ParallelMergeLevelMinus2() + 2;
3827  if ((xN>>plevel)!= (xP>>plevel))
3828  {
3829    return true;
3830  }
3831  if ((yN>>plevel)!= (yP>>plevel))
3832  {
3833    return true;
3834  }
3835  return false;
3836}
3837/** calculate the location of upper-left corner pixel and size of the current PU.
3838 * \param partIdx  PU index within a CU
3839 * \param xP, yP   location of the upper-left corner pixel of the current PU
3840 * \param PSW, nPSH    size of the curren PU
3841 * \returns Void
3842 */
3843Void TComDataCU::getPartPosition( UInt partIdx, Int& xP, Int& yP, Int& nPSW, Int& nPSH)
3844{
3845  UInt col = m_uiCUPelX;
3846  UInt row = m_uiCUPelY;
3847
3848  switch ( m_pePartSize[0] )
3849  {
3850  case SIZE_2NxN:
3851    nPSW = getWidth(0);     
3852    nPSH = getHeight(0) >> 1; 
3853    xP   = col;
3854    yP   = (partIdx ==0)? row: row + nPSH;
3855    break;
3856  case SIZE_Nx2N:
3857    nPSW = getWidth(0) >> 1; 
3858    nPSH = getHeight(0);     
3859    xP   = (partIdx ==0)? col: col + nPSW;
3860    yP   = row;
3861    break;
3862  case SIZE_NxN:
3863    nPSW = getWidth(0) >> 1; 
3864    nPSH = getHeight(0) >> 1; 
3865    xP   = col + (partIdx&0x1)*nPSW;
3866    yP   = row + (partIdx>>1)*nPSH;
3867    break;
3868  case SIZE_2NxnU:
3869    nPSW = getWidth(0);
3870    nPSH = ( partIdx == 0 ) ?  getHeight(0) >> 2 : ( getHeight(0) >> 2 ) + ( getHeight(0) >> 1 );
3871    xP   = col;
3872    yP   = (partIdx ==0)? row: row + getHeight(0) - nPSH;
3873
3874    break;
3875  case SIZE_2NxnD:
3876    nPSW = getWidth(0);
3877    nPSH = ( partIdx == 0 ) ?  ( getHeight(0) >> 2 ) + ( getHeight(0) >> 1 ) : getHeight(0) >> 2;
3878    xP   = col;
3879    yP   = (partIdx ==0)? row: row + getHeight(0) - nPSH;
3880    break;
3881  case SIZE_nLx2N:
3882    nPSW = ( partIdx == 0 ) ? getWidth(0) >> 2 : ( getWidth(0) >> 2 ) + ( getWidth(0) >> 1 );
3883    nPSH = getHeight(0);
3884    xP   = (partIdx ==0)? col: col + getWidth(0) - nPSW;
3885    yP   = row;
3886    break;
3887  case SIZE_nRx2N:
3888    nPSW = ( partIdx == 0 ) ? ( getWidth(0) >> 2 ) + ( getWidth(0) >> 1 ) : getWidth(0) >> 2;
3889    nPSH = getHeight(0);
3890    xP   = (partIdx ==0)? col: col + getWidth(0) - nPSW;
3891    yP   = row;
3892    break;
3893  default:
3894    assert ( m_pePartSize[0] == SIZE_2Nx2N );
3895    nPSW = getWidth(0);     
3896    nPSH = getHeight(0);     
3897    xP   = col ;
3898    yP   = row ;
3899
3900    break;
3901  }
3902}
3903
3904/** Constructs a list of candidates for AMVP
3905 * \param uiPartIdx
3906 * \param uiPartAddr
3907 * \param eRefPicList
3908 * \param iRefIdx
3909 * \param pInfo
3910 */
3911Void TComDataCU::fillMvpCand ( UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, Int iRefIdx, AMVPInfo* pInfo )
3912{
3913  TComMv cMvPred;
3914  Bool bAddedSmvp = false;
3915
3916  pInfo->iN = 0; 
3917  if (iRefIdx < 0)
3918  {
3919    return;
3920  }
3921 
3922  //-- Get Spatial MV
3923  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB;
3924  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
3925  Bool bAdded = false;
3926 
3927  deriveLeftRightTopIdx( uiPartIdx, uiPartIdxLT, uiPartIdxRT );
3928  deriveLeftBottomIdx( uiPartIdx, uiPartIdxLB );
3929 
3930  TComDataCU* tmpCU = NULL;
3931  UInt idx;
3932  tmpCU = getPUBelowLeft(idx, uiPartIdxLB);
3933  bAddedSmvp = (tmpCU != NULL) && (tmpCU->getPredictionMode(idx) != MODE_INTRA);
3934
3935  if (!bAddedSmvp)
3936  {
3937    tmpCU = getPULeft(idx, uiPartIdxLB);
3938    bAddedSmvp = (tmpCU != NULL) && (tmpCU->getPredictionMode(idx) != MODE_INTRA);
3939  }
3940
3941  // Left predictor search
3942  bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_BELOW_LEFT);
3943  if (!bAdded) 
3944  {
3945    bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_LEFT );
3946  }
3947 
3948  if(!bAdded)
3949  {
3950    bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_BELOW_LEFT);
3951    if (!bAdded) 
3952    {
3953      xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_LEFT );
3954    }
3955  }
3956  // Above predictor search
3957  bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE_RIGHT);
3958
3959  if (!bAdded) 
3960  {
3961    bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE);
3962  }
3963
3964  if(!bAdded)
3965  {
3966    xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLT, MD_ABOVE_LEFT);
3967  }
3968  bAdded = bAddedSmvp;
3969  if (pInfo->iN==2) bAdded = true;
3970
3971  if(!bAdded)
3972  {
3973    bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE_RIGHT);
3974    if (!bAdded) 
3975    {
3976      bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE);
3977    }
3978
3979    if(!bAdded)
3980    {
3981      xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLT, MD_ABOVE_LEFT);
3982    }
3983  }
3984 
3985  if ( pInfo->iN == 2 )
3986  {
3987    if ( pInfo->m_acMvCand[ 0 ] == pInfo->m_acMvCand[ 1 ] )
3988    {
3989      pInfo->iN = 1;
3990    }
3991  }
3992
3993  if ( getSlice()->getEnableTMVPFlag() )
3994  {
3995    // Get Temporal Motion Predictor
3996    Int iRefIdx_Col = iRefIdx;
3997    TComMv cColMv;
3998    UInt uiPartIdxRB;
3999    UInt uiAbsPartIdx; 
4000    UInt uiAbsPartAddr;
4001
4002    deriveRightBottomIdx( uiPartIdx, uiPartIdxRB );
4003    uiAbsPartAddr = m_uiAbsIdxInLCU + uiPartAddr;
4004
4005    //----  co-located RightBottom Temporal Predictor (H) ---//
4006    uiAbsPartIdx = g_auiZscanToRaster[uiPartIdxRB];
4007    Int uiLCUIdx = -1;
4008    if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdx] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
4009    {
4010    }
4011    else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdx] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
4012    {
4013    }
4014    else
4015    {
4016      if ( ( uiAbsPartIdx % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
4017        ( uiAbsPartIdx / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
4018      {
4019        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdx + uiNumPartInCUWidth + 1 ];
4020        uiLCUIdx = getAddr();
4021      }
4022      else if ( uiAbsPartIdx % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
4023      {
4024        uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdx + uiNumPartInCUWidth + 1) % m_pcPic->getNumPartInCU() ];
4025      }
4026      else if ( uiAbsPartIdx / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
4027      {
4028        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdx + 1 ];
4029        uiLCUIdx = getAddr() + 1;
4030      }
4031      else //is the right bottom corner of LCU                       
4032      {
4033        uiAbsPartAddr = 0;
4034      }
4035    }
4036    if ( uiLCUIdx >= 0 && xGetColMVP( eRefPicList, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx_Col
4037#if H_3D_TMVP
4038         , 0
4039#endif
4040    ) )
4041    {
4042      pInfo->m_acMvCand[pInfo->iN++] = cColMv;
4043    }
4044    else 
4045    {
4046      UInt uiPartIdxCenter;
4047      UInt uiCurLCUIdx = getAddr();
4048      xDeriveCenterIdx( uiPartIdx, uiPartIdxCenter );
4049      if (xGetColMVP( eRefPicList, uiCurLCUIdx, uiPartIdxCenter,  cColMv, iRefIdx_Col
4050#if H_3D_TMVP
4051         , 0
4052#endif
4053      ))
4054      {
4055        pInfo->m_acMvCand[pInfo->iN++] = cColMv;
4056      }
4057    }
4058    //----  co-located RightBottom Temporal Predictor  ---//
4059  }
4060
4061  if (pInfo->iN > AMVP_MAX_NUM_CANDS)
4062  {
4063    pInfo->iN = AMVP_MAX_NUM_CANDS;
4064  }
4065  while (pInfo->iN < AMVP_MAX_NUM_CANDS)
4066  {
4067      pInfo->m_acMvCand[pInfo->iN].set(0,0);
4068      pInfo->iN++;
4069  }
4070  return ;
4071}
4072
4073Bool TComDataCU::isBipredRestriction(UInt puIdx)
4074{
4075  Int width = 0;
4076  Int height = 0;
4077  UInt partAddr;
4078
4079  getPartIndexAndSize( puIdx, partAddr, width, height );
4080  if ( getWidth(0) == 8 && (width < 8 || height < 8) )
4081  {
4082    return true;
4083  }
4084  return false;
4085}
4086
4087Void TComDataCU::clipMv    (TComMv&  rcMv)
4088{
4089  Int  iMvShift = 2;
4090#if H_3D_IC
4091  if( getSlice()->getIsDepth() )
4092    iMvShift = 0;
4093#endif
4094  Int iOffset = 8;
4095  Int iHorMax = ( m_pcSlice->getSPS()->getPicWidthInLumaSamples() + iOffset - m_uiCUPelX - 1 ) << iMvShift;
4096  Int iHorMin = (       -(Int)g_uiMaxCUWidth - iOffset - (Int)m_uiCUPelX + 1 ) << iMvShift;
4097 
4098  Int iVerMax = ( m_pcSlice->getSPS()->getPicHeightInLumaSamples() + iOffset - m_uiCUPelY - 1 ) << iMvShift;
4099  Int iVerMin = (       -(Int)g_uiMaxCUHeight - iOffset - (Int)m_uiCUPelY + 1 ) << iMvShift;
4100 
4101  rcMv.setHor( min (iHorMax, max (iHorMin, rcMv.getHor())) );
4102  rcMv.setVer( min (iVerMax, max (iVerMin, rcMv.getVer())) );
4103}
4104
4105UInt TComDataCU::getIntraSizeIdx(UInt uiAbsPartIdx)
4106{
4107  UInt uiShift = ( m_pePartSize[uiAbsPartIdx]==SIZE_NxN ? 1 : 0 );
4108 
4109  UChar uiWidth = m_puhWidth[uiAbsPartIdx]>>uiShift;
4110  UInt  uiCnt = 0;
4111  while( uiWidth )
4112  {
4113    uiCnt++;
4114    uiWidth>>=1;
4115  }
4116  uiCnt-=2;
4117  return uiCnt > 6 ? 6 : uiCnt;
4118}
4119
4120Void TComDataCU::clearCbf( UInt uiIdx, TextType eType, UInt uiNumParts )
4121{
4122  ::memset( &m_puhCbf[g_aucConvertTxtTypeToIdx[eType]][uiIdx], 0, sizeof(UChar)*uiNumParts);
4123}
4124
4125/** Set a I_PCM flag for all sub-partitions of a partition.
4126 * \param bIpcmFlag I_PCM flag
4127 * \param uiAbsPartIdx patition index
4128 * \param uiDepth CU depth
4129 * \returns Void
4130 */
4131Void TComDataCU::setIPCMFlagSubParts  (Bool bIpcmFlag, UInt uiAbsPartIdx, UInt uiDepth)
4132{
4133  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
4134
4135  memset(m_pbIPCMFlag + uiAbsPartIdx, bIpcmFlag, sizeof(Bool)*uiCurrPartNumb );
4136}
4137
4138/** Test whether the current block is skipped
4139 * \param uiPartIdx Block index
4140 * \returns Flag indicating whether the block is skipped
4141 */
4142Bool TComDataCU::isSkipped( UInt uiPartIdx )
4143{
4144  return ( getSkipFlag( uiPartIdx ) );
4145}
4146
4147// ====================================================================================================================
4148// Protected member functions
4149// ====================================================================================================================
4150
4151Bool TComDataCU::xAddMVPCand( AMVPInfo* pInfo, RefPicList eRefPicList, Int iRefIdx, UInt uiPartUnitIdx, MVP_DIR eDir )
4152{
4153  TComDataCU* pcTmpCU = NULL;
4154  UInt uiIdx;
4155  switch( eDir )
4156  {
4157    case MD_LEFT:
4158    {
4159      pcTmpCU = getPULeft(uiIdx, uiPartUnitIdx);
4160      break;
4161    }
4162    case MD_ABOVE:
4163    {
4164      pcTmpCU = getPUAbove(uiIdx, uiPartUnitIdx );
4165      break;
4166    }
4167    case MD_ABOVE_RIGHT:
4168    {
4169      pcTmpCU = getPUAboveRight(uiIdx, uiPartUnitIdx);
4170      break;
4171    }
4172    case MD_BELOW_LEFT:
4173    {
4174      pcTmpCU = getPUBelowLeft(uiIdx, uiPartUnitIdx);
4175      break;
4176    }
4177    case MD_ABOVE_LEFT:
4178    {
4179      pcTmpCU = getPUAboveLeft(uiIdx, uiPartUnitIdx);
4180      break;
4181    }
4182    default:
4183    {
4184      break;
4185    }
4186  }
4187
4188  if ( pcTmpCU == NULL )
4189  {
4190    return false;
4191  }
4192 
4193  if ( pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) >= 0 && m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getPOC() == pcTmpCU->getSlice()->getRefPOC( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) ))
4194  {
4195    TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
4196   
4197    pInfo->m_acMvCand[ pInfo->iN++] = cMvPred;
4198    return true;
4199  }
4200
4201  RefPicList eRefPicList2nd = REF_PIC_LIST_0;
4202  if(       eRefPicList == REF_PIC_LIST_0 )
4203  {
4204    eRefPicList2nd = REF_PIC_LIST_1;
4205  }
4206  else if ( eRefPicList == REF_PIC_LIST_1)
4207  {
4208    eRefPicList2nd = REF_PIC_LIST_0;
4209  }
4210
4211
4212  Int iCurrRefPOC = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getPOC();
4213  Int iNeibRefPOC;
4214
4215
4216  if( pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) >= 0 )
4217  {
4218    iNeibRefPOC = pcTmpCU->getSlice()->getRefPOC( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) );
4219    if( iNeibRefPOC == iCurrRefPOC ) // Same Reference Frame But Diff List//
4220    {
4221      TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList2nd)->getMv(uiIdx);
4222      pInfo->m_acMvCand[ pInfo->iN++] = cMvPred;
4223      return true;
4224    }
4225  }
4226  return false;
4227}
4228
4229/**
4230 * \param pInfo
4231 * \param eRefPicList
4232 * \param iRefIdx
4233 * \param uiPartUnitIdx
4234 * \param eDir
4235 * \returns Bool
4236 */
4237Bool TComDataCU::xAddMVPCandOrder( AMVPInfo* pInfo, RefPicList eRefPicList, Int iRefIdx, UInt uiPartUnitIdx, MVP_DIR eDir )
4238{
4239  TComDataCU* pcTmpCU = NULL;
4240  UInt uiIdx;
4241  switch( eDir )
4242  {
4243  case MD_LEFT:
4244    {
4245      pcTmpCU = getPULeft(uiIdx, uiPartUnitIdx);
4246      break;
4247    }
4248  case MD_ABOVE:
4249    {
4250      pcTmpCU = getPUAbove(uiIdx, uiPartUnitIdx);
4251      break;
4252    }
4253  case MD_ABOVE_RIGHT:
4254    {
4255      pcTmpCU = getPUAboveRight(uiIdx, uiPartUnitIdx);
4256      break;
4257    }
4258  case MD_BELOW_LEFT:
4259    {
4260      pcTmpCU = getPUBelowLeft(uiIdx, uiPartUnitIdx);
4261      break;
4262    }
4263  case MD_ABOVE_LEFT:
4264    {
4265      pcTmpCU = getPUAboveLeft(uiIdx, uiPartUnitIdx);
4266      break;
4267    }
4268  default:
4269    {
4270      break;
4271    }
4272  }
4273
4274  if ( pcTmpCU == NULL ) 
4275  {
4276    return false;
4277  }
4278 
4279  RefPicList eRefPicList2nd = REF_PIC_LIST_0;
4280  if(       eRefPicList == REF_PIC_LIST_0 )
4281  {
4282    eRefPicList2nd = REF_PIC_LIST_1;
4283  }
4284  else if ( eRefPicList == REF_PIC_LIST_1)
4285  {
4286    eRefPicList2nd = REF_PIC_LIST_0;
4287  }
4288
4289  Int iCurrPOC = m_pcSlice->getPOC();
4290  Int iCurrRefPOC = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getPOC();
4291  Int iNeibPOC = iCurrPOC;
4292  Int iNeibRefPOC;
4293
4294  Bool bIsCurrRefLongTerm = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getIsLongTerm();
4295  Bool bIsNeibRefLongTerm = false;
4296  //---------------  V1 (END) ------------------//
4297  if( pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) >= 0)
4298  {
4299    iNeibRefPOC = pcTmpCU->getSlice()->getRefPOC( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) );
4300    TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
4301    TComMv rcMv;
4302
4303    bIsNeibRefLongTerm = pcTmpCU->getSlice()->getRefPic( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) )->getIsLongTerm();
4304    if ( bIsCurrRefLongTerm == bIsNeibRefLongTerm ) 
4305    {
4306    if ( bIsCurrRefLongTerm || bIsNeibRefLongTerm )
4307    {
4308      rcMv = cMvPred;
4309    }
4310    else
4311    {
4312      Int iScale = xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
4313      if ( iScale == 4096 )
4314      {
4315        rcMv = cMvPred;
4316      }
4317      else
4318      {
4319        rcMv = cMvPred.scaleMv( iScale );
4320      }
4321    }
4322    pInfo->m_acMvCand[ pInfo->iN++] = rcMv;
4323    return true;
4324    }
4325  }
4326  //---------------------- V2(END) --------------------//
4327  if( pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) >= 0)
4328  {
4329    iNeibRefPOC = pcTmpCU->getSlice()->getRefPOC( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) );
4330    TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList2nd)->getMv(uiIdx);
4331    TComMv rcMv;
4332
4333    bIsNeibRefLongTerm = pcTmpCU->getSlice()->getRefPic( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) )->getIsLongTerm();
4334    if ( bIsCurrRefLongTerm == bIsNeibRefLongTerm ) 
4335    {
4336    if ( bIsCurrRefLongTerm || bIsNeibRefLongTerm )
4337    {
4338      rcMv = cMvPred;
4339    }
4340    else
4341    {
4342      Int iScale = xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
4343      if ( iScale == 4096 )
4344      {
4345        rcMv = cMvPred;
4346      }
4347      else
4348      {
4349        rcMv = cMvPred.scaleMv( iScale );
4350      }
4351    }
4352    pInfo->m_acMvCand[ pInfo->iN++] = rcMv;
4353    return true;
4354    }
4355  }
4356  //---------------------- V3(END) --------------------//
4357  return false;
4358}
4359
4360/**
4361 * \param eRefPicList
4362 * \param uiCUAddr
4363 * \param uiPartUnitIdx
4364 * \param riRefIdx
4365 * \returns Bool
4366 */
4367Bool TComDataCU::xGetColMVP( RefPicList eRefPicList, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv, Int& riRefIdx
4368#if H_3D_TMVP
4369  , Bool bMRG
4370#endif
4371  )
4372{
4373  UInt uiAbsPartAddr = uiPartUnitIdx;
4374
4375  RefPicList  eColRefPicList;
4376  Int iColPOC, iColRefPOC, iCurrPOC, iCurrRefPOC, iScale;
4377  TComMv cColMv;
4378
4379  // use coldir.
4380#if H_MV
4381  TComPic *pColPic; 
4382  if (getSlice()->getAltCollocatedIndicationFlag() )
4383  {
4384    pColPic = getSlice()->getPicFromRefPicSetInterLayer( getSlice()->getActiveMotionPredRefLayerId( getSlice()->getCollocatedRefLayerIdx() )); 
4385  }
4386  else
4387  {
4388    pColPic = getSlice()->getRefPic( RefPicList(getSlice()->isInterB() ? 1-getSlice()->getColFromL0Flag() : 0), getSlice()->getColRefIdx()); 
4389  } 
4390#else
4391  TComPic *pColPic = getSlice()->getRefPic( RefPicList(getSlice()->isInterB() ? 1-getSlice()->getColFromL0Flag() : 0), getSlice()->getColRefIdx());
4392#endif
4393  TComDataCU *pColCU = pColPic->getCU( uiCUAddr );
4394  if(pColCU->getPic()==0||pColCU->getPartitionSize(uiPartUnitIdx)==SIZE_NONE)
4395  {
4396    return false;
4397  }
4398  iCurrPOC = m_pcSlice->getPOC();   
4399  iColPOC = pColCU->getSlice()->getPOC(); 
4400
4401  if (pColCU->isIntra(uiAbsPartAddr))
4402  {
4403    return false;
4404  }
4405  eColRefPicList = getSlice()->getCheckLDC() ? eRefPicList : RefPicList(getSlice()->getColFromL0Flag());
4406
4407  Int iColRefIdx = pColCU->getCUMvField(RefPicList(eColRefPicList))->getRefIdx(uiAbsPartAddr);
4408
4409  if (iColRefIdx < 0 )
4410  {
4411    eColRefPicList = RefPicList(1 - eColRefPicList);
4412    iColRefIdx = pColCU->getCUMvField(RefPicList(eColRefPicList))->getRefIdx(uiAbsPartAddr);
4413
4414    if (iColRefIdx < 0 )
4415    {
4416      return false;
4417    }
4418  }
4419
4420  // Scale the vector.
4421  iColRefPOC = pColCU->getSlice()->getRefPOC(eColRefPicList, iColRefIdx);
4422  cColMv = pColCU->getCUMvField(eColRefPicList)->getMv(uiAbsPartAddr);
4423
4424  iCurrRefPOC = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getPOC();
4425  Bool bIsCurrRefLongTerm = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getIsLongTerm();
4426  Bool bIsColRefLongTerm = pColCU->getSlice()->getIsUsedAsLongTerm(eColRefPicList, iColRefIdx);
4427
4428  if ( bIsCurrRefLongTerm != bIsColRefLongTerm ) 
4429  {
4430#if H_3D_TMVP
4431    Int iAlterRefIdx  = m_pcSlice->getAlterRefIdx(eRefPicList);
4432    if(bMRG && iAlterRefIdx > 0)
4433    {
4434      riRefIdx = iAlterRefIdx;
4435      bIsCurrRefLongTerm = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getIsLongTerm();
4436      iCurrRefPOC = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getPOC();
4437      assert(bIsCurrRefLongTerm == bIsColRefLongTerm);
4438    }
4439    else
4440    {
4441#endif
4442      return false;
4443#if H_3D_TMVP
4444    }
4445#endif
4446  }
4447
4448  if ( bIsCurrRefLongTerm || bIsColRefLongTerm )
4449  {
4450#if H_3D_TMVP
4451    Int iCurrViewId    = m_pcSlice->getViewIndex (); 
4452    Int iCurrRefViewId = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getViewIndex (); 
4453    Int iColViewId     = pColCU->getSlice()->getViewIndex(); 
4454    Int iColRefViewId  = pColCU->getSlice()->getRefPic( eColRefPicList, pColCU->getCUMvField(eColRefPicList)->getRefIdx(uiAbsPartAddr))->getViewIndex(); 
4455    iScale = xGetDistScaleFactor( iCurrViewId, iCurrRefViewId, iColViewId, iColRefViewId );
4456    if ( iScale != 4096 && m_pcSlice->getVPS()->getIvMvScalingFlag() ) 
4457    {
4458      rcMv = cColMv.scaleMv( iScale );
4459    }
4460    else
4461    {
4462#endif
4463       rcMv = cColMv;
4464#if H_3D_TMVP
4465    }
4466#endif
4467  }
4468  else
4469  {
4470    iScale = xGetDistScaleFactor(iCurrPOC, iCurrRefPOC, iColPOC, iColRefPOC);
4471    if ( iScale == 4096 )
4472    {
4473      rcMv = cColMv;
4474    }
4475    else
4476    {
4477      rcMv = cColMv.scaleMv( iScale );
4478    }
4479  }
4480  return true;
4481}
4482
4483UInt TComDataCU::xGetMvdBits(TComMv cMvd)
4484{
4485  return ( xGetComponentBits(cMvd.getHor()) + xGetComponentBits(cMvd.getVer()) );
4486}
4487
4488UInt TComDataCU::xGetComponentBits(Int iVal)
4489{
4490  UInt uiLength = 1;
4491  UInt uiTemp   = ( iVal <= 0) ? (-iVal<<1)+1: (iVal<<1);
4492 
4493  assert ( uiTemp );
4494 
4495  while ( 1 != uiTemp )
4496  {
4497    uiTemp >>= 1;
4498    uiLength += 2;
4499  }
4500 
4501  return uiLength;
4502}
4503
4504
4505Int TComDataCU::xGetDistScaleFactor(Int iCurrPOC, Int iCurrRefPOC, Int iColPOC, Int iColRefPOC)
4506{
4507  Int iDiffPocD = iColPOC - iColRefPOC;
4508  Int iDiffPocB = iCurrPOC - iCurrRefPOC;
4509 
4510  if( iDiffPocD == iDiffPocB )
4511  {
4512    return 4096;
4513  }
4514  else
4515  {
4516    Int iTDB      = Clip3( -128, 127, iDiffPocB );
4517    Int iTDD      = Clip3( -128, 127, iDiffPocD );
4518    Int iX        = (0x4000 + abs(iTDD/2)) / iTDD;
4519    Int iScale    = Clip3( -4096, 4095, (iTDB * iX + 32) >> 6 );
4520    return iScale;
4521  }
4522}
4523
4524/**
4525 * \param eCUMode
4526 * \param uiPartIdx
4527 * \param ruiPartIdxCenter
4528 * \returns Void
4529 */
4530Void TComDataCU::xDeriveCenterIdx( UInt uiPartIdx, UInt& ruiPartIdxCenter )
4531{
4532  UInt uiPartAddr;
4533  Int  iPartWidth;
4534  Int  iPartHeight;
4535  getPartIndexAndSize( uiPartIdx, uiPartAddr, iPartWidth, iPartHeight);
4536 
4537  ruiPartIdxCenter = m_uiAbsIdxInLCU+uiPartAddr; // partition origin.
4538  ruiPartIdxCenter = g_auiRasterToZscan[ g_auiZscanToRaster[ ruiPartIdxCenter ]
4539                                        + ( iPartHeight/m_pcPic->getMinCUHeight()  )/2*m_pcPic->getNumPartInWidth()
4540                                        + ( iPartWidth/m_pcPic->getMinCUWidth()  )/2];
4541}
4542
4543Void TComDataCU::compressMV()
4544{
4545  Int scaleFactor = 4 * AMVP_DECIMATION_FACTOR / m_unitSize;
4546  if (scaleFactor > 0)
4547  {
4548    m_acCUMvField[0].compress(m_pePredMode, scaleFactor);
4549    m_acCUMvField[1].compress(m_pePredMode, scaleFactor);   
4550  }
4551}
4552
4553UInt TComDataCU::getCoefScanIdx(UInt uiAbsPartIdx, UInt uiWidth, Bool bIsLuma, Bool bIsIntra)
4554{
4555  UInt uiCTXIdx;
4556  UInt uiScanIdx;
4557  UInt uiDirMode;
4558
4559  if ( !bIsIntra ) 
4560  {
4561    uiScanIdx = SCAN_DIAG;
4562    return uiScanIdx;
4563  }
4564
4565  switch(uiWidth)
4566  {
4567    case  2: uiCTXIdx = 6; break;
4568    case  4: uiCTXIdx = 5; break;
4569    case  8: uiCTXIdx = 4; break;
4570    case 16: uiCTXIdx = 3; break;
4571    case 32: uiCTXIdx = 2; break;
4572    case 64: uiCTXIdx = 1; break;
4573    default: uiCTXIdx = 0; break;
4574  }
4575
4576  if ( bIsLuma )
4577  {
4578    uiDirMode = getLumaIntraDir(uiAbsPartIdx);
4579#if H_3D_DIM
4580    mapDepthModeToIntraDir( uiDirMode );
4581#endif
4582    uiScanIdx = SCAN_DIAG;
4583    if (uiCTXIdx >3 && uiCTXIdx < 6) //if multiple scans supported for transform size
4584    {
4585      uiScanIdx = abs((Int) uiDirMode - VER_IDX) < 5 ? SCAN_HOR : (abs((Int)uiDirMode - HOR_IDX) < 5 ? SCAN_VER : SCAN_DIAG);
4586    }
4587  }
4588  else
4589  {
4590    uiDirMode = getChromaIntraDir(uiAbsPartIdx);
4591    if( uiDirMode == DM_CHROMA_IDX )
4592    {
4593      // get number of partitions in current CU
4594      UInt depth = getDepth(uiAbsPartIdx);
4595      UInt numParts = getPic()->getNumPartInCU() >> (2 * depth);
4596     
4597      // get luma mode from upper-left corner of current CU
4598      uiDirMode = getLumaIntraDir((uiAbsPartIdx/numParts)*numParts);
4599#if H_3D_DIM
4600      mapDepthModeToIntraDir( uiDirMode );
4601#endif
4602    }
4603    uiScanIdx = SCAN_DIAG;
4604    if (uiCTXIdx >4 && uiCTXIdx < 7) //if multiple scans supported for transform size
4605    {
4606      uiScanIdx = abs((Int) uiDirMode - VER_IDX) < 5 ? SCAN_HOR : (abs((Int)uiDirMode - HOR_IDX) < 5 ? SCAN_VER : SCAN_DIAG);
4607    }
4608  }
4609
4610  return uiScanIdx;
4611}
4612
4613UInt TComDataCU::getSCUAddr()
4614{ 
4615  return getPic()->getPicSym()->getInverseCUOrderMap(m_uiCUAddr)*(1<<(m_pcSlice->getSPS()->getMaxCUDepth()<<1))+m_uiAbsIdxInLCU; 
4616}
4617
4618/** Set neighboring blocks availabilities for non-deblocked filtering
4619 * \param numLCUInPicWidth number of LCUs in picture width
4620 * \param numLCUInPicHeight number of LCUs in picture height
4621 * \param numSUInLCUWidth number of SUs in LCU width
4622 * \param numSUInLCUHeight number of SUs in LCU height
4623 * \param picWidth picture width
4624 * \param picHeight picture height
4625 * \param bIndependentSliceBoundaryEnabled true for independent slice boundary enabled
4626 * \param bTopTileBoundary true means that top boundary coincides tile boundary
4627 * \param bDownTileBoundary true means that bottom boundary coincides tile boundary
4628 * \param bLeftTileBoundary true means that left boundary coincides tile boundary
4629 * \param bRightTileBoundary true means that right boundary coincides tile boundary
4630 * \param bIndependentTileBoundaryEnabled true for independent tile boundary enabled
4631 */
4632Void TComDataCU::setNDBFilterBlockBorderAvailability(UInt numLCUInPicWidth, UInt /*numLCUInPicHeight*/, UInt numSUInLCUWidth, UInt numSUInLCUHeight, UInt picWidth, UInt picHeight
4633                                                    ,std::vector<Bool>& LFCrossSliceBoundary
4634                                                    ,Bool bTopTileBoundary, Bool bDownTileBoundary, Bool bLeftTileBoundary, Bool bRightTileBoundary
4635                                                    ,Bool bIndependentTileBoundaryEnabled)
4636{
4637  UInt numSUInLCU = numSUInLCUWidth*numSUInLCUHeight;
4638  Int* pSliceIDMapLCU = m_piSliceSUMap;
4639  Bool onlyOneSliceInPic = ((Int)LFCrossSliceBoundary.size() == 1);
4640  UInt uiLPelX, uiTPelY;
4641  UInt width, height;
4642  Bool bPicRBoundary, bPicBBoundary, bPicTBoundary, bPicLBoundary;
4643  Bool bLCURBoundary= false, bLCUBBoundary= false, bLCUTBoundary= false, bLCULBoundary= false;
4644  Bool* pbAvailBorder;
4645  Bool* pbAvail;
4646  UInt rTLSU, rBRSU, widthSU, heightSU;
4647  UInt zRefSU;
4648  Int* pRefID;
4649  Int* pRefMapLCU;
4650  UInt rTRefSU= 0, rBRefSU= 0, rLRefSU= 0, rRRefSU= 0;
4651  Int* pRRefMapLCU= NULL;
4652  Int* pLRefMapLCU= NULL;
4653  Int* pTRefMapLCU= NULL;
4654  Int* pBRefMapLCU= NULL;
4655  Int  sliceID;
4656  UInt numSGU = (UInt)m_vNDFBlock.size();
4657
4658  for(Int i=0; i< numSGU; i++)
4659  {
4660    NDBFBlockInfo& rSGU = m_vNDFBlock[i];
4661
4662    sliceID = rSGU.sliceID;
4663    uiLPelX = rSGU.posX;
4664    uiTPelY = rSGU.posY;
4665    width   = rSGU.width;
4666    height  = rSGU.height;
4667    rTLSU     = g_auiZscanToRaster[ rSGU.startSU ];
4668    rBRSU     = g_auiZscanToRaster[ rSGU.endSU   ];
4669    widthSU   = rSGU.widthSU;
4670    heightSU  = rSGU.heightSU;
4671
4672    pbAvailBorder = rSGU.isBorderAvailable;
4673
4674    bPicTBoundary= (uiTPelY == 0                       )?(true):(false);
4675    bPicLBoundary= (uiLPelX == 0                       )?(true):(false);
4676    bPicRBoundary= (!(uiLPelX+ width < picWidth )  )?(true):(false);
4677    bPicBBoundary= (!(uiTPelY + height < picHeight))?(true):(false);
4678
4679    bLCULBoundary = (rTLSU % numSUInLCUWidth == 0)?(true):(false);
4680    bLCURBoundary = ( (rTLSU+ widthSU) % numSUInLCUWidth == 0)?(true):(false);
4681    bLCUTBoundary = ( (UInt)(rTLSU / numSUInLCUWidth)== 0)?(true):(false);
4682    bLCUBBoundary = ( (UInt)(rBRSU / numSUInLCUWidth) == (numSUInLCUHeight-1) )?(true):(false);
4683
4684    //       SGU_L
4685    pbAvail = &(pbAvailBorder[SGU_L]);
4686    if(bPicLBoundary)
4687    {
4688      *pbAvail = false;
4689    }
4690    else if (onlyOneSliceInPic)
4691    {
4692      *pbAvail = true;
4693    }
4694    else
4695    {
4696      //      bLCULBoundary = (rTLSU % uiNumSUInLCUWidth == 0)?(true):(false);
4697      if(bLCULBoundary)
4698      {
4699        rLRefSU     = rTLSU + numSUInLCUWidth -1;
4700        zRefSU      = g_auiRasterToZscan[rLRefSU];
4701        pRefMapLCU = pLRefMapLCU= (pSliceIDMapLCU - numSUInLCU);
4702      }
4703      else
4704      {
4705        zRefSU   = g_auiRasterToZscan[rTLSU - 1];
4706        pRefMapLCU  = pSliceIDMapLCU;
4707      }
4708      pRefID = pRefMapLCU + zRefSU;
4709      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
4710    }
4711
4712    //       SGU_R
4713    pbAvail = &(pbAvailBorder[SGU_R]);
4714    if(bPicRBoundary)
4715    {
4716      *pbAvail = false;
4717    }
4718    else if (onlyOneSliceInPic)
4719    {
4720      *pbAvail = true;
4721    }
4722    else
4723    {
4724      //       bLCURBoundary = ( (rTLSU+ uiWidthSU) % uiNumSUInLCUWidth == 0)?(true):(false);
4725      if(bLCURBoundary)
4726      {
4727        rRRefSU      = rTLSU + widthSU - numSUInLCUWidth;
4728        zRefSU       = g_auiRasterToZscan[rRRefSU];
4729        pRefMapLCU  = pRRefMapLCU= (pSliceIDMapLCU + numSUInLCU);
4730      }
4731      else
4732      {
4733        zRefSU       = g_auiRasterToZscan[rTLSU + widthSU];
4734        pRefMapLCU  = pSliceIDMapLCU;
4735      }
4736      pRefID = pRefMapLCU + zRefSU;
4737      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
4738    }
4739
4740    //       SGU_T
4741    pbAvail = &(pbAvailBorder[SGU_T]);
4742    if(bPicTBoundary)
4743    {
4744      *pbAvail = false;
4745    }
4746    else if (onlyOneSliceInPic)
4747    {
4748      *pbAvail = true;
4749    }
4750    else
4751    {
4752      //      bLCUTBoundary = ( (UInt)(rTLSU / uiNumSUInLCUWidth)== 0)?(true):(false);
4753      if(bLCUTBoundary)
4754      {
4755        rTRefSU      = numSUInLCU - (numSUInLCUWidth - rTLSU);
4756        zRefSU       = g_auiRasterToZscan[rTRefSU];
4757        pRefMapLCU  = pTRefMapLCU= (pSliceIDMapLCU - (numLCUInPicWidth*numSUInLCU));
4758      }
4759      else
4760      {
4761        zRefSU       = g_auiRasterToZscan[rTLSU - numSUInLCUWidth];
4762        pRefMapLCU  = pSliceIDMapLCU;
4763      }
4764      pRefID = pRefMapLCU + zRefSU;
4765      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
4766    }
4767
4768    //       SGU_B
4769    pbAvail = &(pbAvailBorder[SGU_B]);
4770    if(bPicBBoundary)
4771    {
4772      *pbAvail = false;
4773    }
4774    else if (onlyOneSliceInPic)
4775    {
4776      *pbAvail = true;
4777    }
4778    else
4779    {
4780      //      bLCUBBoundary = ( (UInt)(rBRSU / uiNumSUInLCUWidth) == (uiNumSUInLCUHeight-1) )?(true):(false);
4781      if(bLCUBBoundary)
4782      {
4783        rBRefSU      = rTLSU % numSUInLCUWidth;
4784        zRefSU       = g_auiRasterToZscan[rBRefSU];
4785        pRefMapLCU  = pBRefMapLCU= (pSliceIDMapLCU + (numLCUInPicWidth*numSUInLCU));
4786      }
4787      else
4788      {
4789        zRefSU       = g_auiRasterToZscan[rTLSU + (heightSU*numSUInLCUWidth)];
4790        pRefMapLCU  = pSliceIDMapLCU;
4791      }
4792      pRefID = pRefMapLCU + zRefSU;
4793      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
4794    }
4795
4796    //       SGU_TL
4797    pbAvail = &(pbAvailBorder[SGU_TL]);
4798    if(bPicTBoundary || bPicLBoundary)
4799    {
4800      *pbAvail = false;
4801    }
4802    else if (onlyOneSliceInPic)
4803    {
4804      *pbAvail = true;
4805    }
4806    else
4807    {
4808      if(bLCUTBoundary && bLCULBoundary)
4809      {
4810        zRefSU       = numSUInLCU -1;
4811        pRefMapLCU  = pSliceIDMapLCU - ( (numLCUInPicWidth+1)*numSUInLCU);
4812      }
4813      else if(bLCUTBoundary)
4814      {
4815        zRefSU       = g_auiRasterToZscan[ rTRefSU- 1];
4816        pRefMapLCU  = pTRefMapLCU;
4817      }
4818      else if(bLCULBoundary)
4819      {
4820        zRefSU       = g_auiRasterToZscan[ rLRefSU- numSUInLCUWidth ];
4821        pRefMapLCU  = pLRefMapLCU;
4822      }
4823      else //inside LCU
4824      {
4825        zRefSU       = g_auiRasterToZscan[ rTLSU - numSUInLCUWidth -1];
4826        pRefMapLCU  = pSliceIDMapLCU;
4827      }
4828      pRefID = pRefMapLCU + zRefSU;
4829      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
4830    }
4831
4832    //       SGU_TR
4833    pbAvail = &(pbAvailBorder[SGU_TR]);
4834    if(bPicTBoundary || bPicRBoundary)
4835    {
4836      *pbAvail = false;
4837    }
4838    else if (onlyOneSliceInPic)
4839    {
4840      *pbAvail = true;
4841    }
4842    else
4843    {
4844      if(bLCUTBoundary && bLCURBoundary)
4845      {
4846        zRefSU      = g_auiRasterToZscan[numSUInLCU - numSUInLCUWidth];
4847        pRefMapLCU  = pSliceIDMapLCU - ( (numLCUInPicWidth-1)*numSUInLCU);       
4848      }
4849      else if(bLCUTBoundary)
4850      {
4851        zRefSU       = g_auiRasterToZscan[ rTRefSU+ widthSU];
4852        pRefMapLCU  = pTRefMapLCU;
4853      }
4854      else if(bLCURBoundary)
4855      {
4856        zRefSU       = g_auiRasterToZscan[ rRRefSU- numSUInLCUWidth ];
4857        pRefMapLCU  = pRRefMapLCU;
4858      }
4859      else //inside LCU
4860      {
4861        zRefSU       = g_auiRasterToZscan[ rTLSU - numSUInLCUWidth +widthSU];
4862        pRefMapLCU  = pSliceIDMapLCU;
4863      }
4864      pRefID = pRefMapLCU + zRefSU;
4865      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
4866    }
4867
4868    //       SGU_BL
4869    pbAvail = &(pbAvailBorder[SGU_BL]);
4870    if(bPicBBoundary || bPicLBoundary)
4871    {
4872      *pbAvail = false;
4873    }
4874    else if (onlyOneSliceInPic)
4875    {
4876      *pbAvail = true;
4877    }
4878    else
4879    {
4880      if(bLCUBBoundary && bLCULBoundary)
4881      {
4882        zRefSU      = g_auiRasterToZscan[numSUInLCUWidth - 1];
4883        pRefMapLCU  = pSliceIDMapLCU + ( (numLCUInPicWidth-1)*numSUInLCU);       
4884      }
4885      else if(bLCUBBoundary)
4886      {
4887        zRefSU       = g_auiRasterToZscan[ rBRefSU - 1];
4888        pRefMapLCU  = pBRefMapLCU;
4889      }
4890      else if(bLCULBoundary)
4891      {
4892        zRefSU       = g_auiRasterToZscan[ rLRefSU+ heightSU*numSUInLCUWidth ];
4893        pRefMapLCU  = pLRefMapLCU;
4894      }
4895      else //inside LCU
4896      {
4897        zRefSU       = g_auiRasterToZscan[ rTLSU + heightSU*numSUInLCUWidth -1];
4898        pRefMapLCU  = pSliceIDMapLCU;
4899      }
4900      pRefID = pRefMapLCU + zRefSU;
4901      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
4902    }
4903
4904    //       SGU_BR
4905    pbAvail = &(pbAvailBorder[SGU_BR]);
4906    if(bPicBBoundary || bPicRBoundary)
4907    {
4908      *pbAvail = false;
4909    }
4910    else if (onlyOneSliceInPic)
4911    {
4912      *pbAvail = true;
4913    }
4914    else
4915    {
4916      if(bLCUBBoundary && bLCURBoundary)
4917      {
4918        zRefSU = 0;
4919        pRefMapLCU = pSliceIDMapLCU+ ( (numLCUInPicWidth+1)*numSUInLCU);
4920      }
4921      else if(bLCUBBoundary)
4922      {
4923        zRefSU      = g_auiRasterToZscan[ rBRefSU + widthSU];
4924        pRefMapLCU = pBRefMapLCU;
4925      }
4926      else if(bLCURBoundary)
4927      {
4928        zRefSU      = g_auiRasterToZscan[ rRRefSU + (heightSU*numSUInLCUWidth)];
4929        pRefMapLCU = pRRefMapLCU;
4930      }
4931      else //inside LCU
4932      {
4933        zRefSU      = g_auiRasterToZscan[ rTLSU + (heightSU*numSUInLCUWidth)+ widthSU];
4934        pRefMapLCU = pSliceIDMapLCU;
4935      }
4936      pRefID = pRefMapLCU + zRefSU;
4937      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
4938    }
4939
4940    if(bIndependentTileBoundaryEnabled)
4941    {
4942      //left LCU boundary
4943      if(!bPicLBoundary && bLCULBoundary)
4944      {
4945        if(bLeftTileBoundary)
4946        {
4947          pbAvailBorder[SGU_L] = pbAvailBorder[SGU_TL] = pbAvailBorder[SGU_BL] = false;
4948        }
4949      }
4950      //right LCU boundary
4951      if(!bPicRBoundary && bLCURBoundary)
4952      {
4953        if(bRightTileBoundary)
4954        {
4955          pbAvailBorder[SGU_R] = pbAvailBorder[SGU_TR] = pbAvailBorder[SGU_BR] = false;
4956        }
4957      }
4958      //top LCU boundary
4959      if(!bPicTBoundary && bLCUTBoundary)
4960      {
4961        if(bTopTileBoundary)
4962        {
4963          pbAvailBorder[SGU_T] = pbAvailBorder[SGU_TL] = pbAvailBorder[SGU_TR] = false;
4964        }
4965      }
4966      //down LCU boundary
4967      if(!bPicBBoundary && bLCUBBoundary)
4968      {
4969        if(bDownTileBoundary)
4970        {
4971          pbAvailBorder[SGU_B] = pbAvailBorder[SGU_BL] = pbAvailBorder[SGU_BR] = false;
4972        }
4973      }
4974    }
4975    rSGU.allBordersAvailable = true;
4976    for(Int b=0; b< NUM_SGU_BORDER; b++)
4977    {
4978      if(pbAvailBorder[b] == false)
4979      {
4980        rSGU.allBordersAvailable = false;
4981        break;
4982      }
4983    }
4984  }
4985}
4986
4987#if H_3D
4988Void TComDataCU::getPosInPic( UInt uiAbsPartIndex, Int& riPosX, Int& riPosY )
4989{
4990  riPosX = g_auiRasterToPelX[g_auiZscanToRaster[uiAbsPartIndex]] + getCUPelX();
4991  riPosY = g_auiRasterToPelY[g_auiZscanToRaster[uiAbsPartIndex]] + getCUPelY(); 
4992}
4993#endif
4994#if H_3D_NBDV
4995//Notes from QC:
4996//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
4997//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
4998//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
4999Bool TComDataCU::getDisMvpCandNBDV( DisInfo* pDInfo
5000#if H_3D_NBDV_REF
5001, Bool bDepthRefine
5002#endif
5003)
5004{
5005  //// ******* Init variables ******* /////
5006  // Init disparity struct for results
5007  pDInfo->bDV = false;