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

Last change on this file since 566 was 566, checked in by mediatek-htm, 11 years ago

Integration of JCT3V-E0172. The MACRO is "MTK_RVS_BUGFIX_E0172".

By Na Zhang (na.zhang@…)

  • Property svn:eol-style set to native
File size: 217.2 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license. 
5 *
6 * Copyright (c) 2010-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      abCandIsInter[iCount] = true;     
3162      puhInterDirNeighbours[iCount] = pcTextureCU->getInterDir( uiPartIdxCenter );
3163      if( ( puhInterDirNeighbours[iCount] & 1 ) == 1 )
3164      {
3165        pcTextureCU->getMvField( pcTextureCU, uiPartIdxCenter, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3166        TComMv cMvPred = pcMvFieldNeighbours[iCount<<1].getMv();
3167
3168#if H_3D_IC
3169        const TComMv cAdd( 1 << ( 2 - 1 ), 1 << ( 2 - 1 ) );
3170        cMvPred+=cAdd;
3171        cMvPred>>=2;
3172        clipMv(cMvPred);
3173#endif
3174        //pcMvFieldNeighbours[iCount<<1].setMvField(cMvPred,pcMvFieldNeighbours[iCount<<1].getRefIdx());
3175#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
3176        pcMvFieldNeighbours[iCount<<1].setMvField(cMvPred,pcMvFieldNeighbours[iCount<<1].getRefIdx());
3177#endif
3178      }
3179     
3180      if ( getSlice()->isInterB() )
3181      {
3182        if( ( puhInterDirNeighbours[iCount] & 2 ) == 2 )
3183        {
3184          pcTextureCU->getMvField( pcTextureCU, uiPartIdxCenter, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3185          TComMv cMvPred = pcMvFieldNeighbours[(iCount<<1)+1].getMv();
3186#if H_3D_IC
3187          const TComMv cAdd( 1 << ( 2 - 1 ), 1 << ( 2 - 1 ) );
3188          cMvPred+=cAdd;
3189          cMvPred>>=2;
3190          clipMv(cMvPred);
3191#endif
3192          pcMvFieldNeighbours[(iCount<<1)+1].setMvField(cMvPred,pcMvFieldNeighbours[(iCount<<1)+1].getRefIdx());
3193        }
3194      }
3195#if H_3D_NBDV
3196      pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3197      pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3198#endif
3199      if ( mrgCandIdx == iCount )
3200      {
3201        return;
3202      }
3203      iCount ++;
3204    }
3205  }
3206
3207  Int iPdmDir[2] = {0, 0};
3208 
3209  if ( ivMvPredFlag )
3210  {
3211    getInterViewMergeCands(uiPUIdx, aiPdmRefIdx, acPdmMv, &cDisInfo, iPdmDir );
3212  } 
3213   
3214  Int iPdmInterDir;
3215
3216  if( iPdmDir[0] )
3217  {
3218    abCandIsInter        [ iCount ] = true;
3219    puhInterDirNeighbours[ iCount ] = iPdmDir[0];
3220    iPdmInterDir                    = iPdmDir[0];
3221
3222    if( ( iPdmInterDir & 1 ) == 1 )
3223    {
3224      pcMvFieldNeighbours[ iCount<<1    ].setMvField( acPdmMv[ 0 ], aiPdmRefIdx[ 0 ] );
3225    }
3226    if( ( iPdmInterDir & 2 ) == 2 )
3227    {
3228      pcMvFieldNeighbours[(iCount<<1)+1 ].setMvField( acPdmMv[ 1 ], aiPdmRefIdx[ 1 ] );
3229    }
3230
3231    if ( mrgCandIdx == iCount )
3232    {
3233      return;
3234    }
3235    iCount ++;
3236  } 
3237  // early termination
3238  if (iCount == getSlice()->getMaxNumMergeCand()) 
3239  {
3240    return;
3241  }
3242#endif
3243
3244  //left
3245  UInt uiLeftPartIdx = 0;
3246  TComDataCU* pcCULeft = 0;
3247  pcCULeft = getPULeft( uiLeftPartIdx, uiPartIdxLB );
3248  Bool isAvailableA1 = pcCULeft &&
3249  pcCULeft->isDiffMER(xP -1, yP+nPSH-1, xP, yP) &&
3250  !( uiPUIdx == 1 && (cCurPS == SIZE_Nx2N || cCurPS == SIZE_nLx2N || cCurPS == SIZE_nRx2N) ) &&
3251  !pcCULeft->isIntra( uiLeftPartIdx ) ;
3252  if ( isAvailableA1 )
3253  {
3254    abCandIsInter[iCount] = true;
3255    // get Inter Dir
3256    puhInterDirNeighbours[iCount] = pcCULeft->getInterDir( uiLeftPartIdx );
3257    // get Mv from Left
3258    pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3259    if ( getSlice()->isInterB() )
3260    {
3261      pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3262    }
3263#if H_3D_IV_MERGE
3264    Bool bRemoveSpa = false; //pruning to inter-view candidates
3265    Int  iCnloop    = iCount - 1;
3266    for(; iCnloop >= 0; iCnloop --)
3267    {
3268      if(puhInterDirNeighbours[iCount] == puhInterDirNeighbours[iCnloop] && pcMvFieldNeighbours[iCnloop<<1]==pcMvFieldNeighbours[(iCount<<1)] && pcMvFieldNeighbours[(iCnloop<<1)+1]==pcMvFieldNeighbours[(iCount<<1)+1])
3269      {
3270        bRemoveSpa                      = true;
3271        abCandIsInter        [ iCount ] = false;
3272
3273        //reset to the default value for MC
3274        puhInterDirNeighbours[iCount]   = 0;
3275        pcMvFieldNeighbours[iCount<<1].setMvField( cZeroMv, NOT_VALID );
3276        pcMvFieldNeighbours[(iCount<<1)+1].setMvField( cZeroMv, NOT_VALID );
3277        break;
3278      }
3279    }
3280    if(!bRemoveSpa)
3281    {
3282      bLeftAvai = true;
3283      iPosLeftAbove[0] = iCount;
3284#if H_3D_NBDV
3285      pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3286      pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3287#endif
3288#if H_3D_VSP
3289      if (pcCULeft->getVSPFlag(uiLeftPartIdx) == 1)
3290#if MTK_VSP_FIX_E0172
3291      {
3292#endif
3293        vspFlag[iCount] = 1;
3294#if MTK_VSP_FIX_E0172
3295        vspDir[iCount] = pcCULeft->getVSPDir( uiLeftPartIdx );
3296      }
3297#endif
3298#endif
3299      if ( mrgCandIdx == iCount )
3300      {
3301        return;
3302      }
3303      iCount ++;
3304    }
3305#else
3306    if ( mrgCandIdx == iCount )
3307    {
3308      return;
3309    }
3310    iCount ++;
3311#endif
3312  }
3313 
3314  // early termination
3315  if (iCount == getSlice()->getMaxNumMergeCand()) 
3316  {
3317    return;
3318  }
3319  // above
3320  UInt uiAbovePartIdx = 0;
3321  TComDataCU* pcCUAbove = 0;
3322  pcCUAbove = getPUAbove( uiAbovePartIdx, uiPartIdxRT );
3323  Bool isAvailableB1 = pcCUAbove &&
3324  pcCUAbove->isDiffMER(xP+nPSW-1, yP-1, xP, yP) &&
3325  !( uiPUIdx == 1 && (cCurPS == SIZE_2NxN || cCurPS == SIZE_2NxnU || cCurPS == SIZE_2NxnD) ) &&
3326  !pcCUAbove->isIntra( uiAbovePartIdx );
3327  if ( isAvailableB1 && (!isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAbove, uiAbovePartIdx ) ) )
3328  {
3329    abCandIsInter[iCount] = true;
3330    // get Inter Dir
3331    puhInterDirNeighbours[iCount] = pcCUAbove->getInterDir( uiAbovePartIdx );
3332    // get Mv from Left
3333    pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3334    if ( getSlice()->isInterB() )
3335    {
3336      pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3337    }
3338#if H_3D_IV_MERGE
3339    Bool bRemoveSpa = false; //pruning to inter-view candidates
3340    Int  iCnloop    = bLeftAvai? (iCount-2): (iCount-1);
3341    for(; iCnloop >= 0; iCnloop --)
3342    {
3343      if(puhInterDirNeighbours[iCount] == puhInterDirNeighbours[iCnloop] && pcMvFieldNeighbours[iCnloop<<1]==pcMvFieldNeighbours[(iCount<<1)] && pcMvFieldNeighbours[(iCnloop<<1)+1]==pcMvFieldNeighbours[(iCount<<1)+1])
3344      {
3345        bRemoveSpa                      = true;
3346        abCandIsInter        [ iCount ] = false;
3347
3348        //reset to the default value for MC
3349        puhInterDirNeighbours[iCount]   = 0;
3350
3351        pcMvFieldNeighbours[iCount<<1].setMvField( cZeroMv, NOT_VALID );
3352        pcMvFieldNeighbours[(iCount<<1)+1].setMvField( cZeroMv, NOT_VALID );
3353        break;
3354      }
3355    }
3356    if(!bRemoveSpa)
3357    {
3358      iPosLeftAbove[1] = iCount;
3359#if H_3D_NBDV
3360      pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3361      pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3362#endif
3363#if H_3D_VSP
3364      if (pcCUAbove->getVSPFlag(uiAbovePartIdx) == 1)
3365#if MTK_VSP_FIX_E0172
3366      {
3367#endif
3368        vspFlag[iCount] = 1;
3369#if MTK_VSP_FIX_E0172
3370        vspDir[iCount] = pcCUAbove->getVSPDir( uiAbovePartIdx );
3371      }
3372#endif
3373#endif
3374      if ( mrgCandIdx == iCount )
3375      {
3376        return;
3377      }
3378      iCount ++;
3379    }
3380#else
3381    if ( mrgCandIdx == iCount )
3382    {
3383      return;
3384    }
3385    iCount ++;
3386#endif
3387  }
3388  // early termination
3389  if (iCount == getSlice()->getMaxNumMergeCand()) 
3390  {
3391    return;
3392  }
3393
3394  // above right
3395  UInt uiAboveRightPartIdx = 0;
3396  TComDataCU* pcCUAboveRight = 0;
3397  pcCUAboveRight = getPUAboveRight( uiAboveRightPartIdx, uiPartIdxRT );
3398  Bool isAvailableB0 = pcCUAboveRight &&
3399  pcCUAboveRight->isDiffMER(xP+nPSW, yP-1, xP, yP) &&
3400  !pcCUAboveRight->isIntra( uiAboveRightPartIdx );
3401  if ( isAvailableB0 && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveRight, uiAboveRightPartIdx ) ) )
3402  {
3403    abCandIsInter[iCount] = true;
3404    // get Inter Dir
3405    puhInterDirNeighbours[iCount] = pcCUAboveRight->getInterDir( uiAboveRightPartIdx );
3406    // get Mv from Left
3407    pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3408    if ( getSlice()->isInterB() )
3409    {
3410      pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3411    }
3412#if H_3D_NBDV
3413    pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3414    pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3415#endif
3416#if H_3D_VSP
3417    if (pcCUAboveRight->getVSPFlag(uiAboveRightPartIdx) == 1)
3418#if MTK_VSP_FIX_E0172
3419    {
3420#endif
3421      vspFlag[iCount] = 1;
3422#if MTK_VSP_FIX_E0172
3423      vspDir[iCount] = pcCUAboveRight->getVSPDir( uiAboveRightPartIdx);
3424    }
3425#endif
3426#endif
3427    if ( mrgCandIdx == iCount )
3428    {
3429      return;
3430    }
3431    iCount ++;
3432  }
3433  // early termination
3434  if (iCount == getSlice()->getMaxNumMergeCand()) 
3435  {
3436    return;
3437  }
3438
3439#if H_3D_IV_MERGE
3440  if( iPdmDir[1] )
3441  {
3442    assert(iCount < getSlice()->getMaxNumMergeCand());
3443    abCandIsInter        [ iCount ] = true;
3444    puhInterDirNeighbours[ iCount ] = iPdmDir[1];
3445    if( ( iPdmDir[1] & 1 ) == 1 )
3446    {
3447      pcMvFieldNeighbours[ iCount<<1    ].setMvField( acPdmMv[ 2 ], aiPdmRefIdx[ 2 ] );
3448    }
3449    if( ( iPdmDir[1] & 2 ) == 2 )
3450    {
3451      pcMvFieldNeighbours[(iCount<<1)+1 ].setMvField( acPdmMv[ 3 ], aiPdmRefIdx[ 3 ] );
3452    }
3453
3454    Bool bRemoveSpa = false; //pruning to A1, B1
3455    for(Int i = 0; i < 2; i ++)
3456    {
3457      Int iCnloop = iPosLeftAbove[i];
3458      if(iCnloop == -1) 
3459        continue;
3460      if(puhInterDirNeighbours[iCount] == puhInterDirNeighbours[iCnloop] && pcMvFieldNeighbours[iCnloop<<1]==pcMvFieldNeighbours[(iCount<<1)] && pcMvFieldNeighbours[(iCnloop<<1)+1]==pcMvFieldNeighbours[(iCount<<1)+1])
3461      {
3462        bRemoveSpa                      = true;
3463        abCandIsInter        [ iCount ] = false;
3464        //reset to the default value for MC
3465        puhInterDirNeighbours[iCount]   = 0;
3466        pcMvFieldNeighbours[iCount<<1].setMvField( cZeroMv, NOT_VALID );
3467        pcMvFieldNeighbours[(iCount<<1)+1].setMvField( cZeroMv, NOT_VALID );
3468        break;
3469      }     
3470    }
3471    if(!bRemoveSpa)
3472    {
3473#if H_3D_NBDV
3474      pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3475      pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3476#endif
3477      if ( mrgCandIdx == iCount )
3478        return;
3479      iCount ++;
3480
3481      // early termination
3482      if (iCount == getSlice()->getMaxNumMergeCand()) 
3483      {
3484        return;
3485      }
3486    }
3487  } 
3488#endif
3489
3490#if H_3D_VSP
3491#if MTK_VSP_FIX_E0172
3492  if ( xAddVspCand( H_3D_VSP_POSITION, mrgCandIdx, &cDisInfo, iCount, abCandIsInter, pcMvFieldNeighbours, puhInterDirNeighbours, vspFlag, vspDir ) )
3493#else
3494  if ( xAddVspCand( H_3D_VSP_POSITION, mrgCandIdx, &cDisInfo, iCount, abCandIsInter, pcMvFieldNeighbours, puhInterDirNeighbours, vspFlag ) )
3495#endif
3496    return;
3497  // early termination
3498  if (iCount == getSlice()->getMaxNumMergeCand())
3499    return;
3500#endif
3501
3502  //left bottom
3503  UInt uiLeftBottomPartIdx = 0;
3504  TComDataCU* pcCULeftBottom = 0;
3505  pcCULeftBottom = this->getPUBelowLeft( uiLeftBottomPartIdx, uiPartIdxLB );
3506  Bool isAvailableA0 = pcCULeftBottom &&
3507  pcCULeftBottom->isDiffMER(xP-1, yP+nPSH, xP, yP) &&
3508  !pcCULeftBottom->isIntra( uiLeftBottomPartIdx ) ;
3509  if ( isAvailableA0 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCULeftBottom, uiLeftBottomPartIdx ) ) )
3510  {
3511    abCandIsInter[iCount] = true;
3512    // get Inter Dir
3513    puhInterDirNeighbours[iCount] = pcCULeftBottom->getInterDir( uiLeftBottomPartIdx );
3514    // get Mv from Left
3515    pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3516    if ( getSlice()->isInterB() )
3517    {
3518      pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3519    }
3520#if H_3D_NBDV
3521    pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3522    pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3523#endif
3524#if H_3D_VSP
3525    if (pcCULeftBottom->getVSPFlag(uiLeftBottomPartIdx) == 1)
3526#if MTK_VSP_FIX_E0172
3527    {
3528#endif
3529      vspFlag[iCount] = 1;
3530#if MTK_VSP_FIX_E0172
3531      vspDir[iCount] = pcCULeftBottom->getVSPDir( uiLeftBottomPartIdx);
3532    }
3533#endif
3534#endif
3535    if ( mrgCandIdx == iCount )
3536    {
3537      return;
3538    }
3539    iCount ++;
3540  }
3541  // early termination
3542  if (iCount == getSlice()->getMaxNumMergeCand()) 
3543  {
3544    return;
3545  }
3546  // above left
3547  if( iCount < 4 )
3548  {
3549    UInt uiAboveLeftPartIdx = 0;
3550    TComDataCU* pcCUAboveLeft = 0;
3551    pcCUAboveLeft = getPUAboveLeft( uiAboveLeftPartIdx, uiAbsPartAddr );
3552    Bool isAvailableB2 = pcCUAboveLeft &&
3553    pcCUAboveLeft->isDiffMER(xP-1, yP-1, xP, yP) &&
3554    !pcCUAboveLeft->isIntra( uiAboveLeftPartIdx );
3555    if ( isAvailableB2 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) )
3556        && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) ) )
3557    {
3558      abCandIsInter[iCount] = true;
3559      // get Inter Dir
3560      puhInterDirNeighbours[iCount] = pcCUAboveLeft->getInterDir( uiAboveLeftPartIdx );
3561      // get Mv from Left
3562      pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3563      if ( getSlice()->isInterB() )
3564      {
3565        pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3566      }
3567#if H_3D_NBDV
3568      pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3569      pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3570#endif
3571#if H_3D_VSP
3572      if (pcCUAboveLeft->getVSPFlag(uiAboveLeftPartIdx) == 1)
3573#if MTK_VSP_FIX_E0172
3574      {
3575#endif
3576        vspFlag[iCount] = 1;
3577#if MTK_VSP_FIX_E0172
3578        vspDir[iCount] = pcCUAboveLeft->getVSPDir( uiAboveLeftPartIdx);
3579      }
3580#endif
3581#endif
3582      if ( mrgCandIdx == iCount )
3583      {
3584        return;
3585      }
3586      iCount ++;
3587    }
3588  }
3589  // early termination
3590  if (iCount == getSlice()->getMaxNumMergeCand()) 
3591  {
3592    return;
3593  }
3594  if ( getSlice()->getEnableTMVPFlag())
3595  {
3596    //>> MTK colocated-RightBottom
3597    UInt uiPartIdxRB;
3598
3599    deriveRightBottomIdx( uiPUIdx, uiPartIdxRB ); 
3600
3601    UInt uiAbsPartIdxTmp = g_auiZscanToRaster[uiPartIdxRB];
3602    UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
3603
3604    TComMv cColMv;
3605    Int iRefIdx;
3606    Int uiLCUIdx = -1;
3607
3608    if      ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
3609    {
3610    }
3611    else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxTmp] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
3612    {
3613    }
3614    else
3615    {
3616      if ( ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
3617        ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
3618      {
3619        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + uiNumPartInCUWidth + 1 ];
3620        uiLCUIdx = getAddr();
3621      }
3622      else if ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
3623      {
3624        uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdxTmp + uiNumPartInCUWidth + 1) % m_pcPic->getNumPartInCU() ];
3625      }
3626      else if ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
3627      {
3628        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + 1 ];
3629        uiLCUIdx = getAddr() + 1;
3630      }
3631      else //is the right bottom corner of LCU                       
3632      {
3633        uiAbsPartAddr = 0;
3634      }
3635    }
3636   
3637   
3638    iRefIdx = 0;
3639    Bool bExistMV = false;
3640    UInt uiPartIdxCenter;
3641    UInt uiCurLCUIdx = getAddr();
3642    Int dir = 0;
3643    UInt uiArrayAddr = iCount;
3644    xDeriveCenterIdx( uiPUIdx, uiPartIdxCenter );
3645    bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_0, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx );
3646    if( bExistMV == false )
3647    {
3648      bExistMV = xGetColMVP( REF_PIC_LIST_0, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
3649    }
3650    if( bExistMV )
3651    {
3652      dir |= 1;
3653      pcMvFieldNeighbours[ 2 * uiArrayAddr ].setMvField( cColMv, iRefIdx );
3654    }
3655
3656    if ( getSlice()->isInterB() )
3657    {
3658#if H_3D_TMVP
3659      iRefIdx = 0;
3660#endif
3661      bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_1, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx);
3662      if( bExistMV == false )
3663      {
3664        bExistMV = xGetColMVP( REF_PIC_LIST_1, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
3665      }
3666      if( bExistMV )
3667      {
3668        dir |= 2;
3669        pcMvFieldNeighbours[ 2 * uiArrayAddr + 1 ].setMvField( cColMv, iRefIdx );
3670      }
3671    }
3672   
3673    if (dir != 0)
3674    {
3675      puhInterDirNeighbours[uiArrayAddr] = dir;
3676      abCandIsInter[uiArrayAddr] = true;
3677#if H_3D_NBDV
3678      pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3679      pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3680#endif
3681      if ( mrgCandIdx == iCount )
3682      {
3683        return;
3684      }
3685      iCount++;
3686    }
3687  }
3688  // early termination
3689  if (iCount == getSlice()->getMaxNumMergeCand()) 
3690  {
3691    return;
3692  }
3693  UInt uiArrayAddr = iCount;
3694  UInt uiCutoff = uiArrayAddr;
3695   
3696  if ( getSlice()->isInterB())
3697  {
3698#if H_3D_IV_MERGE
3699    UInt uiPriorityList0[20] = {0 , 1, 0, 2, 1, 2, 0, 3, 1, 3, 2, 3,    0, 4, 1, 4, 2, 4, 3, 4 };
3700    UInt uiPriorityList1[20] = {1 , 0, 2, 0, 2, 1, 3, 0, 3, 1, 3, 2,    4, 0, 4, 1, 4, 2, 4, 3 };
3701#else
3702    UInt uiPriorityList0[12] = {0 , 1, 0, 2, 1, 2, 0, 3, 1, 3, 2, 3};
3703    UInt uiPriorityList1[12] = {1 , 0, 2, 0, 2, 1, 3, 0, 3, 1, 3, 2};
3704#endif
3705
3706    for (Int idx=0; idx<uiCutoff*(uiCutoff-1) && uiArrayAddr!= getSlice()->getMaxNumMergeCand(); idx++)
3707    {
3708      Int i = uiPriorityList0[idx]; Int j = uiPriorityList1[idx];
3709#if H_3D_VSP
3710      Bool bValid = true;
3711      if ( vspFlag[i] == 1 || vspFlag[j] == 1 )
3712        bValid = false;
3713      if( !m_pcSlice->getVPS()->getViewSynthesisPredFlag( m_pcSlice->getLayerIdInVps() ) )
3714        assert(bValid == true);
3715#endif
3716#if H_3D_VSP
3717      if (abCandIsInter[i] && abCandIsInter[j] && (puhInterDirNeighbours[i]&0x1) && (puhInterDirNeighbours[j]&0x2) && bValid)
3718#else
3719      if (abCandIsInter[i] && abCandIsInter[j]&& (puhInterDirNeighbours[i]&0x1)&&(puhInterDirNeighbours[j]&0x2))
3720#endif
3721      {
3722        abCandIsInter[uiArrayAddr] = true;
3723        puhInterDirNeighbours[uiArrayAddr] = 3;
3724
3725        // get Mv from cand[i] and cand[j]
3726        pcMvFieldNeighbours[uiArrayAddr << 1].setMvField(pcMvFieldNeighbours[i<<1].getMv(), pcMvFieldNeighbours[i<<1].getRefIdx());
3727        pcMvFieldNeighbours[( uiArrayAddr << 1 ) + 1].setMvField(pcMvFieldNeighbours[(j<<1)+1].getMv(), pcMvFieldNeighbours[(j<<1)+1].getRefIdx());
3728
3729        Int iRefPOCL0 = m_pcSlice->getRefPOC( REF_PIC_LIST_0, pcMvFieldNeighbours[(uiArrayAddr<<1)].getRefIdx() );
3730        Int iRefPOCL1 = m_pcSlice->getRefPOC( REF_PIC_LIST_1, pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getRefIdx() );
3731        if (iRefPOCL0 == iRefPOCL1 && pcMvFieldNeighbours[(uiArrayAddr<<1)].getMv() == pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getMv())
3732        {
3733          abCandIsInter[uiArrayAddr] = false;
3734        }
3735        else
3736        {
3737          uiArrayAddr++;
3738        }
3739      }
3740    }
3741  }
3742  // early termination
3743  if (uiArrayAddr == getSlice()->getMaxNumMergeCand()) 
3744  {
3745    return;
3746  }
3747  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);
3748  Int r = 0;
3749  Int refcnt = 0;
3750  while (uiArrayAddr < getSlice()->getMaxNumMergeCand())
3751  {
3752    abCandIsInter[uiArrayAddr] = true;
3753    puhInterDirNeighbours[uiArrayAddr] = 1;
3754    pcMvFieldNeighbours[uiArrayAddr << 1].setMvField( TComMv(0, 0), r);
3755
3756    if ( getSlice()->isInterB() )
3757    {
3758      puhInterDirNeighbours[uiArrayAddr] = 3;
3759      pcMvFieldNeighbours[(uiArrayAddr << 1) + 1].setMvField(TComMv(0, 0), r);
3760    }
3761    uiArrayAddr++;
3762    if ( refcnt == iNumRefIdx - 1 )
3763    {
3764      r = 0;
3765    }
3766    else
3767    {
3768      ++r;
3769      ++refcnt;
3770    }
3771  }
3772
3773  numValidMergeCand = uiArrayAddr;
3774}
3775
3776/** Check whether the current PU and a spatial neighboring PU are in a same ME region.
3777 * \param xN, xN   location of the upper-left corner pixel of a neighboring PU
3778 * \param xP, yP   location of the upper-left corner pixel of the current PU
3779 * \returns Bool
3780 */
3781Bool TComDataCU::isDiffMER(Int xN, Int yN, Int xP, Int yP)
3782{
3783
3784  UInt plevel = this->getSlice()->getPPS()->getLog2ParallelMergeLevelMinus2() + 2;
3785  if ((xN>>plevel)!= (xP>>plevel))
3786  {
3787    return true;
3788  }
3789  if ((yN>>plevel)!= (yP>>plevel))
3790  {
3791    return true;
3792  }
3793  return false;
3794}
3795/** calculate the location of upper-left corner pixel and size of the current PU.
3796 * \param partIdx  PU index within a CU
3797 * \param xP, yP   location of the upper-left corner pixel of the current PU
3798 * \param PSW, nPSH    size of the curren PU
3799 * \returns Void
3800 */
3801Void TComDataCU::getPartPosition( UInt partIdx, Int& xP, Int& yP, Int& nPSW, Int& nPSH)
3802{
3803  UInt col = m_uiCUPelX;
3804  UInt row = m_uiCUPelY;
3805
3806  switch ( m_pePartSize[0] )
3807  {
3808  case SIZE_2NxN:
3809    nPSW = getWidth(0);     
3810    nPSH = getHeight(0) >> 1; 
3811    xP   = col;
3812    yP   = (partIdx ==0)? row: row + nPSH;
3813    break;
3814  case SIZE_Nx2N:
3815    nPSW = getWidth(0) >> 1; 
3816    nPSH = getHeight(0);     
3817    xP   = (partIdx ==0)? col: col + nPSW;
3818    yP   = row;
3819    break;
3820  case SIZE_NxN:
3821    nPSW = getWidth(0) >> 1; 
3822    nPSH = getHeight(0) >> 1; 
3823    xP   = col + (partIdx&0x1)*nPSW;
3824    yP   = row + (partIdx>>1)*nPSH;
3825    break;
3826  case SIZE_2NxnU:
3827    nPSW = getWidth(0);
3828    nPSH = ( partIdx == 0 ) ?  getHeight(0) >> 2 : ( getHeight(0) >> 2 ) + ( getHeight(0) >> 1 );
3829    xP   = col;
3830    yP   = (partIdx ==0)? row: row + getHeight(0) - nPSH;
3831
3832    break;
3833  case SIZE_2NxnD:
3834    nPSW = getWidth(0);
3835    nPSH = ( partIdx == 0 ) ?  ( getHeight(0) >> 2 ) + ( getHeight(0) >> 1 ) : getHeight(0) >> 2;
3836    xP   = col;
3837    yP   = (partIdx ==0)? row: row + getHeight(0) - nPSH;
3838    break;
3839  case SIZE_nLx2N:
3840    nPSW = ( partIdx == 0 ) ? getWidth(0) >> 2 : ( getWidth(0) >> 2 ) + ( getWidth(0) >> 1 );
3841    nPSH = getHeight(0);
3842    xP   = (partIdx ==0)? col: col + getWidth(0) - nPSW;
3843    yP   = row;
3844    break;
3845  case SIZE_nRx2N:
3846    nPSW = ( partIdx == 0 ) ? ( getWidth(0) >> 2 ) + ( getWidth(0) >> 1 ) : getWidth(0) >> 2;
3847    nPSH = getHeight(0);
3848    xP   = (partIdx ==0)? col: col + getWidth(0) - nPSW;
3849    yP   = row;
3850    break;
3851  default:
3852    assert ( m_pePartSize[0] == SIZE_2Nx2N );
3853    nPSW = getWidth(0);     
3854    nPSH = getHeight(0);     
3855    xP   = col ;
3856    yP   = row ;
3857
3858    break;
3859  }
3860}
3861
3862/** Constructs a list of candidates for AMVP
3863 * \param uiPartIdx
3864 * \param uiPartAddr
3865 * \param eRefPicList
3866 * \param iRefIdx
3867 * \param pInfo
3868 */
3869Void TComDataCU::fillMvpCand ( UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, Int iRefIdx, AMVPInfo* pInfo )
3870{
3871  TComMv cMvPred;
3872  Bool bAddedSmvp = false;
3873
3874  pInfo->iN = 0; 
3875  if (iRefIdx < 0)
3876  {
3877    return;
3878  }
3879 
3880  //-- Get Spatial MV
3881  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB;
3882  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
3883  Bool bAdded = false;
3884 
3885  deriveLeftRightTopIdx( uiPartIdx, uiPartIdxLT, uiPartIdxRT );
3886  deriveLeftBottomIdx( uiPartIdx, uiPartIdxLB );
3887 
3888  TComDataCU* tmpCU = NULL;
3889  UInt idx;
3890  tmpCU = getPUBelowLeft(idx, uiPartIdxLB);
3891  bAddedSmvp = (tmpCU != NULL) && (tmpCU->getPredictionMode(idx) != MODE_INTRA);
3892
3893  if (!bAddedSmvp)
3894  {
3895    tmpCU = getPULeft(idx, uiPartIdxLB);
3896    bAddedSmvp = (tmpCU != NULL) && (tmpCU->getPredictionMode(idx) != MODE_INTRA);
3897  }
3898
3899  // Left predictor search
3900  bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_BELOW_LEFT);
3901  if (!bAdded) 
3902  {
3903    bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_LEFT );
3904  }
3905 
3906  if(!bAdded)
3907  {
3908    bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_BELOW_LEFT);
3909    if (!bAdded) 
3910    {
3911      xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_LEFT );
3912    }
3913  }
3914  // Above predictor search
3915  bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE_RIGHT);
3916
3917  if (!bAdded) 
3918  {
3919    bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE);
3920  }
3921
3922  if(!bAdded)
3923  {
3924    xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLT, MD_ABOVE_LEFT);
3925  }
3926  bAdded = bAddedSmvp;
3927  if (pInfo->iN==2) bAdded = true;
3928
3929  if(!bAdded)
3930  {
3931    bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE_RIGHT);
3932    if (!bAdded) 
3933    {
3934      bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE);
3935    }
3936
3937    if(!bAdded)
3938    {
3939      xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLT, MD_ABOVE_LEFT);
3940    }
3941  }
3942 
3943  if ( pInfo->iN == 2 )
3944  {
3945    if ( pInfo->m_acMvCand[ 0 ] == pInfo->m_acMvCand[ 1 ] )
3946    {
3947      pInfo->iN = 1;
3948    }
3949  }
3950
3951  if ( getSlice()->getEnableTMVPFlag() )
3952  {
3953    // Get Temporal Motion Predictor
3954    Int iRefIdx_Col = iRefIdx;
3955    TComMv cColMv;
3956    UInt uiPartIdxRB;
3957    UInt uiAbsPartIdx; 
3958    UInt uiAbsPartAddr;
3959
3960    deriveRightBottomIdx( uiPartIdx, uiPartIdxRB );
3961    uiAbsPartAddr = m_uiAbsIdxInLCU + uiPartAddr;
3962
3963    //----  co-located RightBottom Temporal Predictor (H) ---//
3964    uiAbsPartIdx = g_auiZscanToRaster[uiPartIdxRB];
3965    Int uiLCUIdx = -1;
3966    if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdx] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
3967    {
3968    }
3969    else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdx] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
3970    {
3971    }
3972    else
3973    {
3974      if ( ( uiAbsPartIdx % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
3975        ( uiAbsPartIdx / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
3976      {
3977        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdx + uiNumPartInCUWidth + 1 ];
3978        uiLCUIdx = getAddr();
3979      }
3980      else if ( uiAbsPartIdx % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
3981      {
3982        uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdx + uiNumPartInCUWidth + 1) % m_pcPic->getNumPartInCU() ];
3983      }
3984      else if ( uiAbsPartIdx / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
3985      {
3986        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdx + 1 ];
3987        uiLCUIdx = getAddr() + 1;
3988      }
3989      else //is the right bottom corner of LCU                       
3990      {
3991        uiAbsPartAddr = 0;
3992      }
3993    }
3994    if ( uiLCUIdx >= 0 && xGetColMVP( eRefPicList, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx_Col
3995#if H_3D_TMVP
3996         , 0
3997#endif
3998    ) )
3999    {
4000      pInfo->m_acMvCand[pInfo->iN++] = cColMv;
4001    }
4002    else 
4003    {
4004      UInt uiPartIdxCenter;
4005      UInt uiCurLCUIdx = getAddr();
4006      xDeriveCenterIdx( uiPartIdx, uiPartIdxCenter );
4007      if (xGetColMVP( eRefPicList, uiCurLCUIdx, uiPartIdxCenter,  cColMv, iRefIdx_Col
4008#if H_3D_TMVP
4009         , 0
4010#endif
4011      ))
4012      {
4013        pInfo->m_acMvCand[pInfo->iN++] = cColMv;
4014      }
4015    }
4016    //----  co-located RightBottom Temporal Predictor  ---//
4017  }
4018
4019  if (pInfo->iN > AMVP_MAX_NUM_CANDS)
4020  {
4021    pInfo->iN = AMVP_MAX_NUM_CANDS;
4022  }
4023  while (pInfo->iN < AMVP_MAX_NUM_CANDS)
4024  {
4025      pInfo->m_acMvCand[pInfo->iN].set(0,0);
4026      pInfo->iN++;
4027  }
4028  return ;
4029}
4030
4031Bool TComDataCU::isBipredRestriction(UInt puIdx)
4032{
4033  Int width = 0;
4034  Int height = 0;
4035  UInt partAddr;
4036
4037  getPartIndexAndSize( puIdx, partAddr, width, height );
4038  if ( getWidth(0) == 8 && (width < 8 || height < 8) )
4039  {
4040    return true;
4041  }
4042  return false;
4043}
4044
4045Void TComDataCU::clipMv    (TComMv&  rcMv)
4046{
4047  Int  iMvShift = 2;
4048#if H_3D_IC
4049  if( getSlice()->getIsDepth() )
4050    iMvShift = 0;
4051#endif
4052  Int iOffset = 8;
4053  Int iHorMax = ( m_pcSlice->getSPS()->getPicWidthInLumaSamples() + iOffset - m_uiCUPelX - 1 ) << iMvShift;
4054  Int iHorMin = (       -(Int)g_uiMaxCUWidth - iOffset - (Int)m_uiCUPelX + 1 ) << iMvShift;
4055 
4056  Int iVerMax = ( m_pcSlice->getSPS()->getPicHeightInLumaSamples() + iOffset - m_uiCUPelY - 1 ) << iMvShift;
4057  Int iVerMin = (       -(Int)g_uiMaxCUHeight - iOffset - (Int)m_uiCUPelY + 1 ) << iMvShift;
4058 
4059  rcMv.setHor( min (iHorMax, max (iHorMin, rcMv.getHor())) );
4060  rcMv.setVer( min (iVerMax, max (iVerMin, rcMv.getVer())) );
4061}
4062
4063UInt TComDataCU::getIntraSizeIdx(UInt uiAbsPartIdx)
4064{
4065  UInt uiShift = ( m_pePartSize[uiAbsPartIdx]==SIZE_NxN ? 1 : 0 );
4066 
4067  UChar uiWidth = m_puhWidth[uiAbsPartIdx]>>uiShift;
4068  UInt  uiCnt = 0;
4069  while( uiWidth )
4070  {
4071    uiCnt++;
4072    uiWidth>>=1;
4073  }
4074  uiCnt-=2;
4075  return uiCnt > 6 ? 6 : uiCnt;
4076}
4077
4078Void TComDataCU::clearCbf( UInt uiIdx, TextType eType, UInt uiNumParts )
4079{
4080  ::memset( &m_puhCbf[g_aucConvertTxtTypeToIdx[eType]][uiIdx], 0, sizeof(UChar)*uiNumParts);
4081}
4082
4083/** Set a I_PCM flag for all sub-partitions of a partition.
4084 * \param bIpcmFlag I_PCM flag
4085 * \param uiAbsPartIdx patition index
4086 * \param uiDepth CU depth
4087 * \returns Void
4088 */
4089Void TComDataCU::setIPCMFlagSubParts  (Bool bIpcmFlag, UInt uiAbsPartIdx, UInt uiDepth)
4090{
4091  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
4092
4093  memset(m_pbIPCMFlag + uiAbsPartIdx, bIpcmFlag, sizeof(Bool)*uiCurrPartNumb );
4094}
4095
4096/** Test whether the current block is skipped
4097 * \param uiPartIdx Block index
4098 * \returns Flag indicating whether the block is skipped
4099 */
4100Bool TComDataCU::isSkipped( UInt uiPartIdx )
4101{
4102  return ( getSkipFlag( uiPartIdx ) );
4103}
4104
4105// ====================================================================================================================
4106// Protected member functions
4107// ====================================================================================================================
4108
4109Bool TComDataCU::xAddMVPCand( AMVPInfo* pInfo, RefPicList eRefPicList, Int iRefIdx, UInt uiPartUnitIdx, MVP_DIR eDir )
4110{
4111  TComDataCU* pcTmpCU = NULL;
4112  UInt uiIdx;
4113  switch( eDir )
4114  {
4115    case MD_LEFT:
4116    {
4117      pcTmpCU = getPULeft(uiIdx, uiPartUnitIdx);
4118      break;
4119    }
4120    case MD_ABOVE:
4121    {
4122      pcTmpCU = getPUAbove(uiIdx, uiPartUnitIdx );
4123      break;
4124    }
4125    case MD_ABOVE_RIGHT:
4126    {
4127      pcTmpCU = getPUAboveRight(uiIdx, uiPartUnitIdx);
4128      break;
4129    }
4130    case MD_BELOW_LEFT:
4131    {
4132      pcTmpCU = getPUBelowLeft(uiIdx, uiPartUnitIdx);
4133      break;
4134    }
4135    case MD_ABOVE_LEFT:
4136    {
4137      pcTmpCU = getPUAboveLeft(uiIdx, uiPartUnitIdx);
4138      break;
4139    }
4140    default:
4141    {
4142      break;
4143    }
4144  }
4145
4146  if ( pcTmpCU == NULL )
4147  {
4148    return false;
4149  }
4150 
4151  if ( pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) >= 0 && m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getPOC() == pcTmpCU->getSlice()->getRefPOC( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) ))
4152  {
4153    TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
4154   
4155    pInfo->m_acMvCand[ pInfo->iN++] = cMvPred;
4156    return true;
4157  }
4158
4159  RefPicList eRefPicList2nd = REF_PIC_LIST_0;
4160  if(       eRefPicList == REF_PIC_LIST_0 )
4161  {
4162    eRefPicList2nd = REF_PIC_LIST_1;
4163  }
4164  else if ( eRefPicList == REF_PIC_LIST_1)
4165  {
4166    eRefPicList2nd = REF_PIC_LIST_0;
4167  }
4168
4169
4170  Int iCurrRefPOC = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getPOC();
4171  Int iNeibRefPOC;
4172
4173
4174  if( pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) >= 0 )
4175  {
4176    iNeibRefPOC = pcTmpCU->getSlice()->getRefPOC( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) );
4177    if( iNeibRefPOC == iCurrRefPOC ) // Same Reference Frame But Diff List//
4178    {
4179      TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList2nd)->getMv(uiIdx);
4180      pInfo->m_acMvCand[ pInfo->iN++] = cMvPred;
4181      return true;
4182    }
4183  }
4184  return false;
4185}
4186
4187/**
4188 * \param pInfo
4189 * \param eRefPicList
4190 * \param iRefIdx
4191 * \param uiPartUnitIdx
4192 * \param eDir
4193 * \returns Bool
4194 */
4195Bool TComDataCU::xAddMVPCandOrder( AMVPInfo* pInfo, RefPicList eRefPicList, Int iRefIdx, UInt uiPartUnitIdx, MVP_DIR eDir )
4196{
4197  TComDataCU* pcTmpCU = NULL;
4198  UInt uiIdx;
4199  switch( eDir )
4200  {
4201  case MD_LEFT:
4202    {
4203      pcTmpCU = getPULeft(uiIdx, uiPartUnitIdx);
4204      break;
4205    }
4206  case MD_ABOVE:
4207    {
4208      pcTmpCU = getPUAbove(uiIdx, uiPartUnitIdx);
4209      break;
4210    }
4211  case MD_ABOVE_RIGHT:
4212    {
4213      pcTmpCU = getPUAboveRight(uiIdx, uiPartUnitIdx);
4214      break;
4215    }
4216  case MD_BELOW_LEFT:
4217    {
4218      pcTmpCU = getPUBelowLeft(uiIdx, uiPartUnitIdx);
4219      break;
4220    }
4221  case MD_ABOVE_LEFT:
4222    {
4223      pcTmpCU = getPUAboveLeft(uiIdx, uiPartUnitIdx);
4224      break;
4225    }
4226  default:
4227    {
4228      break;
4229    }
4230  }
4231
4232  if ( pcTmpCU == NULL ) 
4233  {
4234    return false;
4235  }
4236 
4237  RefPicList eRefPicList2nd = REF_PIC_LIST_0;
4238  if(       eRefPicList == REF_PIC_LIST_0 )
4239  {
4240    eRefPicList2nd = REF_PIC_LIST_1;
4241  }
4242  else if ( eRefPicList == REF_PIC_LIST_1)
4243  {
4244    eRefPicList2nd = REF_PIC_LIST_0;
4245  }
4246
4247  Int iCurrPOC = m_pcSlice->getPOC();
4248  Int iCurrRefPOC = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getPOC();
4249  Int iNeibPOC = iCurrPOC;
4250  Int iNeibRefPOC;
4251
4252  Bool bIsCurrRefLongTerm = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getIsLongTerm();
4253  Bool bIsNeibRefLongTerm = false;
4254  //---------------  V1 (END) ------------------//
4255  if( pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) >= 0)
4256  {
4257    iNeibRefPOC = pcTmpCU->getSlice()->getRefPOC( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) );
4258    TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
4259    TComMv rcMv;
4260
4261    bIsNeibRefLongTerm = pcTmpCU->getSlice()->getRefPic( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) )->getIsLongTerm();
4262    if ( bIsCurrRefLongTerm == bIsNeibRefLongTerm ) 
4263    {
4264    if ( bIsCurrRefLongTerm || bIsNeibRefLongTerm )
4265    {
4266      rcMv = cMvPred;
4267    }
4268    else
4269    {
4270      Int iScale = xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
4271      if ( iScale == 4096 )
4272      {
4273        rcMv = cMvPred;
4274      }
4275      else
4276      {
4277        rcMv = cMvPred.scaleMv( iScale );
4278      }
4279    }
4280    pInfo->m_acMvCand[ pInfo->iN++] = rcMv;
4281    return true;
4282    }
4283  }
4284  //---------------------- V2(END) --------------------//
4285  if( pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) >= 0)
4286  {
4287    iNeibRefPOC = pcTmpCU->getSlice()->getRefPOC( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) );
4288    TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList2nd)->getMv(uiIdx);
4289    TComMv rcMv;
4290
4291    bIsNeibRefLongTerm = pcTmpCU->getSlice()->getRefPic( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) )->getIsLongTerm();
4292    if ( bIsCurrRefLongTerm == bIsNeibRefLongTerm ) 
4293    {
4294    if ( bIsCurrRefLongTerm || bIsNeibRefLongTerm )
4295    {
4296      rcMv = cMvPred;
4297    }
4298    else
4299    {
4300      Int iScale = xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
4301      if ( iScale == 4096 )
4302      {
4303        rcMv = cMvPred;
4304      }
4305      else
4306      {
4307        rcMv = cMvPred.scaleMv( iScale );
4308      }
4309    }
4310    pInfo->m_acMvCand[ pInfo->iN++] = rcMv;
4311    return true;
4312    }
4313  }
4314  //---------------------- V3(END) --------------------//
4315  return false;
4316}
4317
4318/**
4319 * \param eRefPicList
4320 * \param uiCUAddr
4321 * \param uiPartUnitIdx
4322 * \param riRefIdx
4323 * \returns Bool
4324 */
4325Bool TComDataCU::xGetColMVP( RefPicList eRefPicList, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv, Int& riRefIdx
4326#if H_3D_TMVP
4327  , Bool bMRG
4328#endif
4329  )
4330{
4331  UInt uiAbsPartAddr = uiPartUnitIdx;
4332
4333  RefPicList  eColRefPicList;
4334  Int iColPOC, iColRefPOC, iCurrPOC, iCurrRefPOC, iScale;
4335  TComMv cColMv;
4336
4337  // use coldir.
4338#if H_MV
4339  TComPic *pColPic; 
4340  if (getSlice()->getAltCollocatedIndicationFlag() )
4341  {
4342    pColPic = getSlice()->getPicFromRefPicSetInterLayer( getSlice()->getActiveMotionPredRefLayerId( getSlice()->getCollocatedRefLayerIdx() )); 
4343  }
4344  else
4345  {
4346    pColPic = getSlice()->getRefPic( RefPicList(getSlice()->isInterB() ? 1-getSlice()->getColFromL0Flag() : 0), getSlice()->getColRefIdx()); 
4347  } 
4348#else
4349  TComPic *pColPic = getSlice()->getRefPic( RefPicList(getSlice()->isInterB() ? 1-getSlice()->getColFromL0Flag() : 0), getSlice()->getColRefIdx());
4350#endif
4351  TComDataCU *pColCU = pColPic->getCU( uiCUAddr );
4352  if(pColCU->getPic()==0||pColCU->getPartitionSize(uiPartUnitIdx)==SIZE_NONE)
4353  {
4354    return false;
4355  }
4356  iCurrPOC = m_pcSlice->getPOC();   
4357  iColPOC = pColCU->getSlice()->getPOC(); 
4358
4359  if (pColCU->isIntra(uiAbsPartAddr))
4360  {
4361    return false;
4362  }
4363  eColRefPicList = getSlice()->getCheckLDC() ? eRefPicList : RefPicList(getSlice()->getColFromL0Flag());
4364
4365  Int iColRefIdx = pColCU->getCUMvField(RefPicList(eColRefPicList))->getRefIdx(uiAbsPartAddr);
4366
4367  if (iColRefIdx < 0 )
4368  {
4369    eColRefPicList = RefPicList(1 - eColRefPicList);
4370    iColRefIdx = pColCU->getCUMvField(RefPicList(eColRefPicList))->getRefIdx(uiAbsPartAddr);
4371
4372    if (iColRefIdx < 0 )
4373    {
4374      return false;
4375    }
4376  }
4377
4378  // Scale the vector.
4379  iColRefPOC = pColCU->getSlice()->getRefPOC(eColRefPicList, iColRefIdx);
4380  cColMv = pColCU->getCUMvField(eColRefPicList)->getMv(uiAbsPartAddr);
4381
4382  iCurrRefPOC = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getPOC();
4383  Bool bIsCurrRefLongTerm = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getIsLongTerm();
4384  Bool bIsColRefLongTerm = pColCU->getSlice()->getIsUsedAsLongTerm(eColRefPicList, iColRefIdx);
4385
4386  if ( bIsCurrRefLongTerm != bIsColRefLongTerm ) 
4387  {
4388#if H_3D_TMVP
4389    Int iAlterRefIdx  = m_pcSlice->getAlterRefIdx(eRefPicList);
4390    if(bMRG && iAlterRefIdx > 0)
4391    {
4392      riRefIdx = iAlterRefIdx;
4393      bIsCurrRefLongTerm = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getIsLongTerm();
4394      iCurrRefPOC = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getPOC();
4395      assert(bIsCurrRefLongTerm == bIsColRefLongTerm);
4396    }
4397    else
4398    {
4399#endif
4400      return false;
4401#if H_3D_TMVP
4402    }
4403#endif
4404  }
4405
4406  if ( bIsCurrRefLongTerm || bIsColRefLongTerm )
4407  {
4408#if H_3D_TMVP
4409    Int iCurrViewId    = m_pcSlice->getViewIndex (); 
4410    Int iCurrRefViewId = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getViewIndex (); 
4411    Int iColViewId     = pColCU->getSlice()->getViewIndex(); 
4412    Int iColRefViewId  = pColCU->getSlice()->getRefPic( eColRefPicList, pColCU->getCUMvField(eColRefPicList)->getRefIdx(uiAbsPartAddr))->getViewIndex(); 
4413    iScale = xGetDistScaleFactor( iCurrViewId, iCurrRefViewId, iColViewId, iColRefViewId );
4414    if ( iScale != 4096 && m_pcSlice->getVPS()->getIvMvScalingFlag() ) 
4415    {
4416      rcMv = cColMv.scaleMv( iScale );
4417    }
4418    else
4419    {
4420#endif
4421       rcMv = cColMv;
4422#if H_3D_TMVP
4423    }
4424#endif
4425  }
4426  else
4427  {
4428    iScale = xGetDistScaleFactor(iCurrPOC, iCurrRefPOC, iColPOC, iColRefPOC);
4429    if ( iScale == 4096 )
4430    {
4431      rcMv = cColMv;
4432    }
4433    else
4434    {
4435      rcMv = cColMv.scaleMv( iScale );
4436    }
4437  }
4438  return true;
4439}
4440
4441UInt TComDataCU::xGetMvdBits(TComMv cMvd)
4442{
4443  return ( xGetComponentBits(cMvd.getHor()) + xGetComponentBits(cMvd.getVer()) );
4444}
4445
4446UInt TComDataCU::xGetComponentBits(Int iVal)
4447{
4448  UInt uiLength = 1;
4449  UInt uiTemp   = ( iVal <= 0) ? (-iVal<<1)+1: (iVal<<1);
4450 
4451  assert ( uiTemp );
4452 
4453  while ( 1 != uiTemp )
4454  {
4455    uiTemp >>= 1;
4456    uiLength += 2;
4457  }
4458 
4459  return uiLength;
4460}
4461
4462
4463Int TComDataCU::xGetDistScaleFactor(Int iCurrPOC, Int iCurrRefPOC, Int iColPOC, Int iColRefPOC)
4464{
4465  Int iDiffPocD = iColPOC - iColRefPOC;
4466  Int iDiffPocB = iCurrPOC - iCurrRefPOC;
4467 
4468  if( iDiffPocD == iDiffPocB )
4469  {
4470    return 4096;
4471  }
4472  else
4473  {
4474    Int iTDB      = Clip3( -128, 127, iDiffPocB );
4475    Int iTDD      = Clip3( -128, 127, iDiffPocD );
4476    Int iX        = (0x4000 + abs(iTDD/2)) / iTDD;
4477    Int iScale    = Clip3( -4096, 4095, (iTDB * iX + 32) >> 6 );
4478    return iScale;
4479  }
4480}
4481
4482/**
4483 * \param eCUMode
4484 * \param uiPartIdx
4485 * \param ruiPartIdxCenter
4486 * \returns Void
4487 */
4488Void TComDataCU::xDeriveCenterIdx( UInt uiPartIdx, UInt& ruiPartIdxCenter )
4489{
4490  UInt uiPartAddr;
4491  Int  iPartWidth;
4492  Int  iPartHeight;
4493  getPartIndexAndSize( uiPartIdx, uiPartAddr, iPartWidth, iPartHeight);
4494 
4495  ruiPartIdxCenter = m_uiAbsIdxInLCU+uiPartAddr; // partition origin.
4496  ruiPartIdxCenter = g_auiRasterToZscan[ g_auiZscanToRaster[ ruiPartIdxCenter ]
4497                                        + ( iPartHeight/m_pcPic->getMinCUHeight()  )/2*m_pcPic->getNumPartInWidth()
4498                                        + ( iPartWidth/m_pcPic->getMinCUWidth()  )/2];
4499}
4500
4501Void TComDataCU::compressMV()
4502{
4503  Int scaleFactor = 4 * AMVP_DECIMATION_FACTOR / m_unitSize;
4504  if (scaleFactor > 0)
4505  {
4506    m_acCUMvField[0].compress(m_pePredMode, scaleFactor);
4507    m_acCUMvField[1].compress(m_pePredMode, scaleFactor);   
4508  }
4509}
4510
4511UInt TComDataCU::getCoefScanIdx(UInt uiAbsPartIdx, UInt uiWidth, Bool bIsLuma, Bool bIsIntra)
4512{
4513  UInt uiCTXIdx;
4514  UInt uiScanIdx;
4515  UInt uiDirMode;
4516
4517  if ( !bIsIntra ) 
4518  {
4519    uiScanIdx = SCAN_DIAG;
4520    return uiScanIdx;
4521  }
4522
4523  switch(uiWidth)
4524  {
4525    case  2: uiCTXIdx = 6; break;
4526    case  4: uiCTXIdx = 5; break;
4527    case  8: uiCTXIdx = 4; break;
4528    case 16: uiCTXIdx = 3; break;
4529    case 32: uiCTXIdx = 2; break;
4530    case 64: uiCTXIdx = 1; break;
4531    default: uiCTXIdx = 0; break;
4532  }
4533
4534  if ( bIsLuma )
4535  {
4536    uiDirMode = getLumaIntraDir(uiAbsPartIdx);
4537#if H_3D_DIM
4538    mapDepthModeToIntraDir( uiDirMode );
4539#endif
4540    uiScanIdx = SCAN_DIAG;
4541    if (uiCTXIdx >3 && uiCTXIdx < 6) //if multiple scans supported for transform size
4542    {
4543      uiScanIdx = abs((Int) uiDirMode - VER_IDX) < 5 ? SCAN_HOR : (abs((Int)uiDirMode - HOR_IDX) < 5 ? SCAN_VER : SCAN_DIAG);
4544    }
4545  }
4546  else
4547  {
4548    uiDirMode = getChromaIntraDir(uiAbsPartIdx);
4549    if( uiDirMode == DM_CHROMA_IDX )
4550    {
4551      // get number of partitions in current CU
4552      UInt depth = getDepth(uiAbsPartIdx);
4553      UInt numParts = getPic()->getNumPartInCU() >> (2 * depth);
4554     
4555      // get luma mode from upper-left corner of current CU
4556      uiDirMode = getLumaIntraDir((uiAbsPartIdx/numParts)*numParts);
4557#if H_3D_DIM
4558      mapDepthModeToIntraDir( uiDirMode );
4559#endif
4560    }
4561    uiScanIdx = SCAN_DIAG;
4562    if (uiCTXIdx >4 && uiCTXIdx < 7) //if multiple scans supported for transform size
4563    {
4564      uiScanIdx = abs((Int) uiDirMode - VER_IDX) < 5 ? SCAN_HOR : (abs((Int)uiDirMode - HOR_IDX) < 5 ? SCAN_VER : SCAN_DIAG);
4565    }
4566  }
4567
4568  return uiScanIdx;
4569}
4570
4571UInt TComDataCU::getSCUAddr()
4572{ 
4573  return getPic()->getPicSym()->getInverseCUOrderMap(m_uiCUAddr)*(1<<(m_pcSlice->getSPS()->getMaxCUDepth()<<1))+m_uiAbsIdxInLCU; 
4574}
4575
4576/** Set neighboring blocks availabilities for non-deblocked filtering
4577 * \param numLCUInPicWidth number of LCUs in picture width
4578 * \param numLCUInPicHeight number of LCUs in picture height
4579 * \param numSUInLCUWidth number of SUs in LCU width
4580 * \param numSUInLCUHeight number of SUs in LCU height
4581 * \param picWidth picture width
4582 * \param picHeight picture height
4583 * \param bIndependentSliceBoundaryEnabled true for independent slice boundary enabled
4584 * \param bTopTileBoundary true means that top boundary coincides tile boundary
4585 * \param bDownTileBoundary true means that bottom boundary coincides tile boundary
4586 * \param bLeftTileBoundary true means that left boundary coincides tile boundary
4587 * \param bRightTileBoundary true means that right boundary coincides tile boundary
4588 * \param bIndependentTileBoundaryEnabled true for independent tile boundary enabled
4589 */
4590Void TComDataCU::setNDBFilterBlockBorderAvailability(UInt numLCUInPicWidth, UInt /*numLCUInPicHeight*/, UInt numSUInLCUWidth, UInt numSUInLCUHeight, UInt picWidth, UInt picHeight
4591                                                    ,std::vector<Bool>& LFCrossSliceBoundary
4592                                                    ,Bool bTopTileBoundary, Bool bDownTileBoundary, Bool bLeftTileBoundary, Bool bRightTileBoundary
4593                                                    ,Bool bIndependentTileBoundaryEnabled)
4594{
4595  UInt numSUInLCU = numSUInLCUWidth*numSUInLCUHeight;
4596  Int* pSliceIDMapLCU = m_piSliceSUMap;
4597  Bool onlyOneSliceInPic = ((Int)LFCrossSliceBoundary.size() == 1);
4598  UInt uiLPelX, uiTPelY;
4599  UInt width, height;
4600  Bool bPicRBoundary, bPicBBoundary, bPicTBoundary, bPicLBoundary;
4601  Bool bLCURBoundary= false, bLCUBBoundary= false, bLCUTBoundary= false, bLCULBoundary= false;
4602  Bool* pbAvailBorder;
4603  Bool* pbAvail;
4604  UInt rTLSU, rBRSU, widthSU, heightSU;
4605  UInt zRefSU;
4606  Int* pRefID;
4607  Int* pRefMapLCU;
4608  UInt rTRefSU= 0, rBRefSU= 0, rLRefSU= 0, rRRefSU= 0;
4609  Int* pRRefMapLCU= NULL;
4610  Int* pLRefMapLCU= NULL;
4611  Int* pTRefMapLCU= NULL;
4612  Int* pBRefMapLCU= NULL;
4613  Int  sliceID;
4614  UInt numSGU = (UInt)m_vNDFBlock.size();
4615
4616  for(Int i=0; i< numSGU; i++)
4617  {
4618    NDBFBlockInfo& rSGU = m_vNDFBlock[i];
4619
4620    sliceID = rSGU.sliceID;
4621    uiLPelX = rSGU.posX;
4622    uiTPelY = rSGU.posY;
4623    width   = rSGU.width;
4624    height  = rSGU.height;
4625    rTLSU     = g_auiZscanToRaster[ rSGU.startSU ];
4626    rBRSU     = g_auiZscanToRaster[ rSGU.endSU   ];
4627    widthSU   = rSGU.widthSU;
4628    heightSU  = rSGU.heightSU;
4629
4630    pbAvailBorder = rSGU.isBorderAvailable;
4631
4632    bPicTBoundary= (uiTPelY == 0                       )?(true):(false);
4633    bPicLBoundary= (uiLPelX == 0                       )?(true):(false);
4634    bPicRBoundary= (!(uiLPelX+ width < picWidth )  )?(true):(false);
4635    bPicBBoundary= (!(uiTPelY + height < picHeight))?(true):(false);
4636
4637    bLCULBoundary = (rTLSU % numSUInLCUWidth == 0)?(true):(false);
4638    bLCURBoundary = ( (rTLSU+ widthSU) % numSUInLCUWidth == 0)?(true):(false);
4639    bLCUTBoundary = ( (UInt)(rTLSU / numSUInLCUWidth)== 0)?(true):(false);
4640    bLCUBBoundary = ( (UInt)(rBRSU / numSUInLCUWidth) == (numSUInLCUHeight-1) )?(true):(false);
4641
4642    //       SGU_L
4643    pbAvail = &(pbAvailBorder[SGU_L]);
4644    if(bPicLBoundary)
4645    {
4646      *pbAvail = false;
4647    }
4648    else if (onlyOneSliceInPic)
4649    {
4650      *pbAvail = true;
4651    }
4652    else
4653    {
4654      //      bLCULBoundary = (rTLSU % uiNumSUInLCUWidth == 0)?(true):(false);
4655      if(bLCULBoundary)
4656      {
4657        rLRefSU     = rTLSU + numSUInLCUWidth -1;
4658        zRefSU      = g_auiRasterToZscan[rLRefSU];
4659        pRefMapLCU = pLRefMapLCU= (pSliceIDMapLCU - numSUInLCU);
4660      }
4661      else
4662      {
4663        zRefSU   = g_auiRasterToZscan[rTLSU - 1];
4664        pRefMapLCU  = pSliceIDMapLCU;
4665      }
4666      pRefID = pRefMapLCU + zRefSU;
4667      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
4668    }
4669
4670    //       SGU_R
4671    pbAvail = &(pbAvailBorder[SGU_R]);
4672    if(bPicRBoundary)
4673    {
4674      *pbAvail = false;
4675    }
4676    else if (onlyOneSliceInPic)
4677    {
4678      *pbAvail = true;
4679    }
4680    else
4681    {
4682      //       bLCURBoundary = ( (rTLSU+ uiWidthSU) % uiNumSUInLCUWidth == 0)?(true):(false);
4683      if(bLCURBoundary)
4684      {
4685        rRRefSU      = rTLSU + widthSU - numSUInLCUWidth;
4686        zRefSU       = g_auiRasterToZscan[rRRefSU];
4687        pRefMapLCU  = pRRefMapLCU= (pSliceIDMapLCU + numSUInLCU);
4688      }
4689      else
4690      {
4691        zRefSU       = g_auiRasterToZscan[rTLSU + widthSU];
4692        pRefMapLCU  = pSliceIDMapLCU;
4693      }
4694      pRefID = pRefMapLCU + zRefSU;
4695      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
4696    }
4697
4698    //       SGU_T
4699    pbAvail = &(pbAvailBorder[SGU_T]);
4700    if(bPicTBoundary)
4701    {
4702      *pbAvail = false;
4703    }
4704    else if (onlyOneSliceInPic)
4705    {
4706      *pbAvail = true;
4707    }
4708    else
4709    {
4710      //      bLCUTBoundary = ( (UInt)(rTLSU / uiNumSUInLCUWidth)== 0)?(true):(false);
4711      if(bLCUTBoundary)
4712      {
4713        rTRefSU      = numSUInLCU - (numSUInLCUWidth - rTLSU);
4714        zRefSU       = g_auiRasterToZscan[rTRefSU];
4715        pRefMapLCU  = pTRefMapLCU= (pSliceIDMapLCU - (numLCUInPicWidth*numSUInLCU));
4716      }
4717      else
4718      {
4719        zRefSU       = g_auiRasterToZscan[rTLSU - numSUInLCUWidth];
4720        pRefMapLCU  = pSliceIDMapLCU;
4721      }
4722      pRefID = pRefMapLCU + zRefSU;
4723      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
4724    }
4725
4726    //       SGU_B
4727    pbAvail = &(pbAvailBorder[SGU_B]);
4728    if(bPicBBoundary)
4729    {
4730      *pbAvail = false;
4731    }
4732    else if (onlyOneSliceInPic)
4733    {
4734      *pbAvail = true;
4735    }
4736    else
4737    {
4738      //      bLCUBBoundary = ( (UInt)(rBRSU / uiNumSUInLCUWidth) == (uiNumSUInLCUHeight-1) )?(true):(false);
4739      if(bLCUBBoundary)
4740      {
4741        rBRefSU      = rTLSU % numSUInLCUWidth;
4742        zRefSU       = g_auiRasterToZscan[rBRefSU];
4743        pRefMapLCU  = pBRefMapLCU= (pSliceIDMapLCU + (numLCUInPicWidth*numSUInLCU));
4744      }
4745      else
4746      {
4747        zRefSU       = g_auiRasterToZscan[rTLSU + (heightSU*numSUInLCUWidth)];
4748        pRefMapLCU  = pSliceIDMapLCU;
4749      }
4750      pRefID = pRefMapLCU + zRefSU;
4751      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
4752    }
4753
4754    //       SGU_TL
4755    pbAvail = &(pbAvailBorder[SGU_TL]);
4756    if(bPicTBoundary || bPicLBoundary)
4757    {
4758      *pbAvail = false;
4759    }
4760    else if (onlyOneSliceInPic)
4761    {
4762      *pbAvail = true;
4763    }
4764    else
4765    {
4766      if(bLCUTBoundary && bLCULBoundary)
4767      {
4768        zRefSU       = numSUInLCU -1;
4769        pRefMapLCU  = pSliceIDMapLCU - ( (numLCUInPicWidth+1)*numSUInLCU);
4770      }
4771      else if(bLCUTBoundary)
4772      {
4773        zRefSU       = g_auiRasterToZscan[ rTRefSU- 1];
4774        pRefMapLCU  = pTRefMapLCU;
4775      }
4776      else if(bLCULBoundary)
4777      {
4778        zRefSU       = g_auiRasterToZscan[ rLRefSU- numSUInLCUWidth ];
4779        pRefMapLCU  = pLRefMapLCU;
4780      }
4781      else //inside LCU
4782      {
4783        zRefSU       = g_auiRasterToZscan[ rTLSU - numSUInLCUWidth -1];
4784        pRefMapLCU  = pSliceIDMapLCU;
4785      }
4786      pRefID = pRefMapLCU + zRefSU;
4787      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
4788    }
4789
4790    //       SGU_TR
4791    pbAvail = &(pbAvailBorder[SGU_TR]);
4792    if(bPicTBoundary || bPicRBoundary)
4793    {
4794      *pbAvail = false;
4795    }
4796    else if (onlyOneSliceInPic)
4797    {
4798      *pbAvail = true;
4799    }
4800    else
4801    {
4802      if(bLCUTBoundary && bLCURBoundary)
4803      {
4804        zRefSU      = g_auiRasterToZscan[numSUInLCU - numSUInLCUWidth];
4805        pRefMapLCU  = pSliceIDMapLCU - ( (numLCUInPicWidth-1)*numSUInLCU);       
4806      }
4807      else if(bLCUTBoundary)
4808      {
4809        zRefSU       = g_auiRasterToZscan[ rTRefSU+ widthSU];
4810        pRefMapLCU  = pTRefMapLCU;
4811      }
4812      else if(bLCURBoundary)
4813      {
4814        zRefSU       = g_auiRasterToZscan[ rRRefSU- numSUInLCUWidth ];
4815        pRefMapLCU  = pRRefMapLCU;
4816      }
4817      else //inside LCU
4818      {
4819        zRefSU       = g_auiRasterToZscan[ rTLSU - numSUInLCUWidth +widthSU];
4820        pRefMapLCU  = pSliceIDMapLCU;
4821      }
4822      pRefID = pRefMapLCU + zRefSU;
4823      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
4824    }
4825
4826    //       SGU_BL
4827    pbAvail = &(pbAvailBorder[SGU_BL]);
4828    if(bPicBBoundary || bPicLBoundary)
4829    {
4830      *pbAvail = false;
4831    }
4832    else if (onlyOneSliceInPic)
4833    {
4834      *pbAvail = true;
4835    }
4836    else
4837    {
4838      if(bLCUBBoundary && bLCULBoundary)
4839      {
4840        zRefSU      = g_auiRasterToZscan[numSUInLCUWidth - 1];
4841        pRefMapLCU  = pSliceIDMapLCU + ( (numLCUInPicWidth-1)*numSUInLCU);       
4842      }
4843      else if(bLCUBBoundary)
4844      {
4845        zRefSU       = g_auiRasterToZscan[ rBRefSU - 1];
4846        pRefMapLCU  = pBRefMapLCU;
4847      }
4848      else if(bLCULBoundary)
4849      {
4850        zRefSU       = g_auiRasterToZscan[ rLRefSU+ heightSU*numSUInLCUWidth ];
4851        pRefMapLCU  = pLRefMapLCU;
4852      }
4853      else //inside LCU
4854      {
4855        zRefSU       = g_auiRasterToZscan[ rTLSU + heightSU*numSUInLCUWidth -1];
4856        pRefMapLCU  = pSliceIDMapLCU;
4857      }
4858      pRefID = pRefMapLCU + zRefSU;
4859      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
4860    }
4861
4862    //       SGU_BR
4863    pbAvail = &(pbAvailBorder[SGU_BR]);
4864    if(bPicBBoundary || bPicRBoundary)
4865    {
4866      *pbAvail = false;
4867    }
4868    else if (onlyOneSliceInPic)
4869    {
4870      *pbAvail = true;
4871    }
4872    else
4873    {
4874      if(bLCUBBoundary && bLCURBoundary)
4875      {
4876        zRefSU = 0;
4877        pRefMapLCU = pSliceIDMapLCU+ ( (numLCUInPicWidth+1)*numSUInLCU);
4878      }
4879      else if(bLCUBBoundary)
4880      {
4881        zRefSU      = g_auiRasterToZscan[ rBRefSU + widthSU];
4882        pRefMapLCU = pBRefMapLCU;
4883      }
4884      else if(bLCURBoundary)
4885      {
4886        zRefSU      = g_auiRasterToZscan[ rRRefSU + (heightSU*numSUInLCUWidth)];
4887        pRefMapLCU = pRRefMapLCU;
4888      }
4889      else //inside LCU
4890      {
4891        zRefSU      = g_auiRasterToZscan[ rTLSU + (heightSU*numSUInLCUWidth)+ widthSU];
4892        pRefMapLCU = pSliceIDMapLCU;
4893      }
4894      pRefID = pRefMapLCU + zRefSU;
4895      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
4896    }
4897
4898    if(bIndependentTileBoundaryEnabled)
4899    {
4900      //left LCU boundary
4901      if(!bPicLBoundary && bLCULBoundary)
4902      {
4903        if(bLeftTileBoundary)
4904        {
4905          pbAvailBorder[SGU_L] = pbAvailBorder[SGU_TL] = pbAvailBorder[SGU_BL] = false;
4906        }
4907      }
4908      //right LCU boundary
4909      if(!bPicRBoundary && bLCURBoundary)
4910      {
4911        if(bRightTileBoundary)
4912        {
4913          pbAvailBorder[SGU_R] = pbAvailBorder[SGU_TR] = pbAvailBorder[SGU_BR] = false;
4914        }
4915      }
4916      //top LCU boundary
4917      if(!bPicTBoundary && bLCUTBoundary)
4918      {
4919        if(bTopTileBoundary)
4920        {
4921          pbAvailBorder[SGU_T] = pbAvailBorder[SGU_TL] = pbAvailBorder[SGU_TR] = false;
4922        }
4923      }
4924      //down LCU boundary
4925      if(!bPicBBoundary && bLCUBBoundary)
4926      {
4927        if(bDownTileBoundary)
4928        {
4929          pbAvailBorder[SGU_B] = pbAvailBorder[SGU_BL] = pbAvailBorder[SGU_BR] = false;
4930        }
4931      }
4932    }
4933    rSGU.allBordersAvailable = true;
4934    for(Int b=0; b< NUM_SGU_BORDER; b++)
4935    {
4936      if(pbAvailBorder[b] == false)
4937      {
4938        rSGU.allBordersAvailable = false;
4939        break;
4940      }
4941    }
4942  }
4943}
4944
4945#if H_3D
4946Void TComDataCU::getPosInPic( UInt uiAbsPartIndex, Int& riPosX, Int& riPosY )
4947{
4948  riPosX = g_auiRasterToPelX[g_auiZscanToRaster[uiAbsPartIndex]] + getCUPelX();
4949  riPosY = g_auiRasterToPelY[g_auiZscanToRaster[uiAbsPartIndex]] + getCUPelY(); 
4950}
4951#endif
4952#if H_3D_NBDV
4953//Notes from QC:
4954//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
4955//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
4956//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
4957Bool TComDataCU::getDisMvpCandNBDV( DisInfo* pDInfo
4958#if H_3D_NBDV_REF
4959, Bool bDepthRefine
4960#endif
4961)
4962{
4963  //// ******* Init variables ******* /////
4964  // Init disparity struct for results
4965  pDInfo->bDV = false;   
4966  // Init struct for disparities from MCP neighboring blocks
4967  IDVInfo cIDVInfo;
4968  cIDVInfo.m_bFound = false; 
4969  UInt uiPartIdx = 0;
4970  UInt uiPartAddr = 0;
4971  for (UInt iCurDvMcpCand = 0; iCurDvMcpCand < IDV_CANDS; iCurDvMcpCand++)
4972  {
4973    for (UInt iList = 0; iList < 2; iList++)
4974    {
4975      cIDVInfo.m_acMvCand[iList][iCurDvMcpCand].setZero();
4976      cIDVInfo.m_aVIdxCan[iList][iCurDvMcpCand] = 0; 
4977      cIDVInfo.m_bAvailab[iList][iCurDvMcpCand] = false; 
4978    }
4979  }
4980#if H_3D_NBDV_REF
4981  if( !m_pcSlice->getVPS()->getDepthRefinementFlag( m_pcSlice->getLayerIdInVps() ) )
4982  {
4983    bDepthRefine = false;
4984  }
4985#endif
4986  // Get Positions 
4987  PartSize eCUMode    = getPartitionSize( uiPartAddr );   
4988  assert(eCUMode == SIZE_2Nx2N);
4989  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB; 
4990
4991  deriveLeftRightTopIdxGeneral(uiPartAddr, uiPartIdx, uiPartIdxLT, uiPartIdxRT );
4992  deriveLeftBottomIdxGeneral  (uiPartAddr, uiPartIdx, uiPartIdxLB );
4993
4994  //// ******* Get disparity from temporal neighboring blocks ******* /////
4995  if ( getSlice()->getEnableTMVPFlag() )
4996  {
4997    TComMv cColMv;
4998    Int iTargetViewIdx = 0;
4999    Int iTStartViewIdx = 0;   
5000
5001    ///*** Derive center position ***
5002    UInt uiPartIdxCenter;
5003    Int  uiLCUIdx   = getAddr();
5004    xDeriveCenterIdx(uiPartIdx, uiPartIdxCenter );
5005
5006    ///*** Derive bottom right neighbour position ***
5007    Int iLCUIdxRBNb  = -1;   
5008    Int iPartIdxRBNb = -1;
5009    xDeriveRightBottomNbIdx(iLCUIdxRBNb, iPartIdxRBNb );
5010
5011    ///*** Search temporal candidate pictures for disparity vector ***
5012    const Int iNumCandPics = getPic()->getNumDdvCandPics();
5013    for(Int curCandPic = 0; curCandPic < iNumCandPics; curCandPic++)
5014    {
5015      RefPicList eCurRefPicList   = REF_PIC_LIST_0 ;
5016      Int        curCandPicRefIdx = 0;
5017      if( curCandPic == 0 ) 
5018      { 
5019        eCurRefPicList   = RefPicList(getSlice()->isInterB() ? 1-getSlice()->getColFromL0Flag() : 0);
5020        curCandPicRefIdx = getSlice()->getColRefIdx();
5021      }
5022      else                 
5023      {
5024        eCurRefPicList   = getPic()->getRapRefList();
5025        curCandPicRefIdx = getPic()->getRapRefIdx();
5026      }
5027
5028      // Check BR and Center       
5029      for(Int curPosition = 0; curPosition < 2; curPosition++) 
5030      {
5031        Bool bCheck = false; 
5032        if ( curPosition == 0 && iLCUIdxRBNb >= 0 )
5033#if MTK_NBDV_TN_FIX_E0172
5034          bCheck = xGetColDisMV( curCandPic, eCurRefPicList, curCandPicRefIdx, iLCUIdxRBNb, iPartIdxRBNb,  cColMv, iTargetViewIdx, iTStartViewIdx);
5035#else
5036          bCheck = xGetColDisMV( eCurRefPicList, curCandPicRefIdx, iLCUIdxRBNb, iPartIdxRBNb,  cColMv, iTargetViewIdx, iTStartViewIdx);
5037#endif
5038
5039        if (curPosition == 1 )
5040#if MTK_NBDV_TN_FIX_E0172
5041          bCheck = xGetColDisMV( curCandPic, eCurRefPicList, curCandPicRefIdx, uiLCUIdx,   uiPartIdxCenter,  cColMv, iTargetViewIdx, iTStartViewIdx );
5042#else
5043          bCheck = xGetColDisMV( eCurRefPicList, curCandPicRefIdx, uiLCUIdx,   uiPartIdxCenter,  cColMv, iTargetViewIdx, iTStartViewIdx );
5044#endif
5045
5046        if( bCheck )
5047        {
5048          clipMv(cColMv);
5049          pDInfo->m_acNBDV = cColMv;
5050          pDInfo->m_aVIdxCan  = iTargetViewIdx;
5051
5052#if H_3D_NBDV_REF
5053          TComPic* picDepth = NULL;         
5054          picDepth = getSlice()->getIvPic( true, iTargetViewIdx );
5055          assert(picDepth != NULL);
5056          if (picDepth && bDepthRefine)
5057            estimateDVFromDM(iTargetViewIdx, uiPartIdx, picDepth, uiPartAddr, &cColMv );
5058
5059          pDInfo->m_acDoNBDV  = cColMv;
5060#endif //H_3D_NBDV_REF
5061          return true;
5062        }
5063      } 
5064    }
5065  } 
5066
5067  UInt uiIdx = 0;
5068  Bool        bCheckMcpDv = false;   
5069  TComDataCU* pcTmpCU     = NULL;
5070
5071  //// ******* Get disparity from left block ******* /////
5072  pcTmpCU = getPULeft(uiIdx, uiPartIdxLB, true, false);
5073  bCheckMcpDv = true; 
5074  if ( xCheckSpatialNBDV( pcTmpCU, uiIdx, pDInfo, bCheckMcpDv, &cIDVInfo, DVFROM_LEFT
5075#if H_3D_NBDV_REF
5076  , bDepthRefine
5077#endif
5078    ) )
5079    return true;
5080
5081  //// ******* Get disparity from above block ******* /////
5082  pcTmpCU = getPUAbove(uiIdx, uiPartIdxRT, true, false, true);
5083  if(pcTmpCU != NULL )
5084  {
5085    bCheckMcpDv = ( ( getAddr() - pcTmpCU->getAddr() ) == 0);
5086    if ( xCheckSpatialNBDV( pcTmpCU, uiIdx, pDInfo, bCheckMcpDv, &cIDVInfo, DVFROM_ABOVE
5087#if H_3D_NBDV_REF
5088  , bDepthRefine
5089#endif
5090    ) )
5091      return true;
5092  }
5093
5094  //// ******* Get disparity from above right block ******* /////
5095  pcTmpCU = getPUAboveRight(uiIdx, uiPartIdxRT, true);
5096  if(pcTmpCU != NULL )
5097  {
5098    bCheckMcpDv = ( ( getAddr() - pcTmpCU->getAddr() ) == 0);
5099    if ( xCheckSpatialNBDV( pcTmpCU, uiIdx, pDInfo, bCheckMcpDv, &cIDVInfo, DVFROM_ABOVERIGHT
5100#if H_3D_NBDV_REF
5101  , bDepthRefine
5102#endif
5103    ) )
5104      return true;
5105  }
5106
5107  //// ******* Get disparity from below left block ******* /////
5108  pcTmpCU = getPUBelowLeft(uiIdx, uiPartIdxLB, true);
5109  if( pcTmpCU != NULL )
5110  {
5111    bCheckMcpDv = true; 
5112    if ( xCheckSpatialNBDV( pcTmpCU, uiIdx, pDInfo, bCheckMcpDv, &cIDVInfo, DVFROM_LEFTBELOW
5113#if H_3D_NBDV_REF
5114  , bDepthRefine
5115#endif
5116    ) )
5117      return true;
5118  }
5119
5120  //// ******* Get disparity from above left block ******* /////
5121  pcTmpCU = getPUAboveLeft(uiIdx, (m_uiAbsIdxInLCU + uiPartAddr), true);
5122  assert(uiPartIdxLT == (m_uiAbsIdxInLCU + uiPartAddr));
5123
5124  if( pcTmpCU != NULL )
5125  {
5126    bCheckMcpDv = (( getAddr() - pcTmpCU->getAddr() ) <= 1); 
5127    if ( xCheckSpatialNBDV( pcTmpCU, uiIdx, pDInfo, bCheckMcpDv, &cIDVInfo, DVFROM_ABOVELEFT
5128#if H_3D_NBDV_REF
5129  , bDepthRefine
5130#endif
5131    ) )
5132      return true;
5133  }
5134
5135  //// ******* Search MCP blocks ******* /////
5136  if( cIDVInfo.m_bFound ) 
5137  {
5138    for( Int curPos = 0 ; curPos < IDV_CANDS ; curPos++ ) 
5139    {
5140      for(Int iList = 0; iList < (getSlice()->isInterB() ? 2: 1); iList ++)
5141      {
5142        if( cIDVInfo.m_bAvailab[iList][curPos] )
5143        {
5144          TComMv cDispVec = cIDVInfo.m_acMvCand[iList][ curPos ];
5145          clipMv( cDispVec );
5146          pDInfo->m_acNBDV = cDispVec;
5147          pDInfo->m_aVIdxCan = cIDVInfo.m_aVIdxCan[iList][ curPos ];
5148#if !MTK_DVMCP_FIX_E0172
5149          assert(pDInfo->m_aVIdxCan == 0); //Notes from QC: only works for CTC
5150#endif
5151#if H_3D_NBDV_REF
5152          TComPic* picDepth = getSlice()->getIvPic( true, pDInfo->m_aVIdxCan );
5153          assert(picDepth!=NULL);
5154
5155          if (picDepth && bDepthRefine)
5156          {
5157            estimateDVFromDM (pDInfo->m_aVIdxCan, uiPartIdx, picDepth, uiPartAddr, &cDispVec);
5158          }
5159          pDInfo->m_acDoNBDV = cDispVec;
5160#endif
5161          return true;
5162        }
5163      }
5164    }
5165  }
5166
5167  TComMv defaultDV(0, 0);
5168  pDInfo->m_acNBDV = defaultDV;
5169  pDInfo->m_aVIdxCan = 0;
5170#if H_3D_NBDV_REF
5171  TComPic* picDepth = NULL;
5172  picDepth = getSlice()->getIvPic( true, 0 );
5173  assert(picDepth!=NULL);
5174
5175  if (picDepth && bDepthRefine)
5176  {
5177    estimateDVFromDM(0, uiPartIdx, picDepth, uiPartAddr, &defaultDV ); // from base view
5178  }
5179  pDInfo->m_acDoNBDV = defaultDV;
5180#endif
5181
5182  return false; 
5183}
5184
5185#if H_3D_NBDV_REF
5186Pel TComDataCU::getMcpFromDM(TComPicYuv* pcBaseViewDepthPicYuv, TComMv* mv, Int iBlkX, Int iBlkY, Int iBlkWidth, Int iBlkHeight, Int* aiShiftLUT )
5187{
5188  Int iPictureWidth  = pcBaseViewDepthPicYuv->getWidth();
5189  Int iPictureHeight = pcBaseViewDepthPicYuv->getHeight();
5190
5191  Int depthStartPosX = Clip3(0,   iPictureWidth - iBlkWidth,  iBlkX + ((mv->getHor()+2)>>2));
5192  Int depthStartPosY = Clip3(0,   iPictureHeight- iBlkHeight,  iBlkY + ((mv->getVer()+2)>>2));
5193  Int depthEndPosX   = Clip3(0,   iPictureWidth - 1,  iBlkX + iBlkWidth - 1 + ((mv->getHor()+2)>>2));
5194  Int depthEndPosY   = Clip3(0,   iPictureHeight - 1,  iBlkY + iBlkHeight - 1 + ((mv->getVer()+2)>>2));
5195
5196  Pel* depthTL  = pcBaseViewDepthPicYuv->getLumaAddr();
5197  Int depStride =  pcBaseViewDepthPicYuv->getStride();
5198
5199  Pel  maxDepthVal = 0;
5200  maxDepthVal = std::max( maxDepthVal, depthTL[ (depthStartPosY) * depStride + depthStartPosX ]);      // Left Top
5201  maxDepthVal = std::max( maxDepthVal, depthTL[ (depthEndPosY)   * depStride + depthStartPosX ]);      // Left Bottom
5202  maxDepthVal = std::max( maxDepthVal, depthTL[ (depthStartPosY) * depStride + depthEndPosX   ]);      // Right Top
5203  maxDepthVal = std::max( maxDepthVal, depthTL[ (depthEndPosY)   * depStride + depthEndPosX   ]);      // Right Bottom
5204
5205  return aiShiftLUT[ maxDepthVal ];
5206}
5207
5208Void TComDataCU::estimateDVFromDM(Int refViewIdx, UInt uiPartIdx, TComPic* picDepth, UInt uiPartAddr, TComMv* cMvPred )
5209{
5210  if (picDepth)
5211  {
5212    UInt uiAbsPartAddrCurrCU = m_uiAbsIdxInLCU + uiPartAddr;
5213    Int iWidth, iHeight;
5214    getPartIndexAndSize( uiPartIdx, uiPartAddr, iWidth, iHeight ); // The modified value of uiPartAddr won't be used any more
5215
5216    TComPicYuv* pcBaseViewDepthPicYuv = picDepth->getPicYuvRec();
5217    Int iBlkX = ( getAddr() % picDepth->getFrameWidthInCU() ) * g_uiMaxCUWidth  + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartAddrCurrCU ] ];
5218    Int iBlkY = ( getAddr() / picDepth->getFrameWidthInCU() ) * g_uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartAddrCurrCU ] ];
5219
5220    Int* aiShiftLUT = getSlice()->getDepthToDisparityB(refViewIdx );
5221
5222    Pel iDisp = getMcpFromDM( pcBaseViewDepthPicYuv, cMvPred, iBlkX, iBlkY, iWidth, iHeight, aiShiftLUT );
5223    cMvPred->setHor( iDisp );
5224    clipMv(*cMvPred);
5225  }
5226}
5227#endif //H_3D_NBDV_REF
5228
5229
5230Bool TComDataCU::xCheckSpatialNBDV( TComDataCU* pcTmpCU, UInt uiIdx, DisInfo* pNbDvInfo, Bool bSearchForMvpDv, IDVInfo* paIDVInfo, UInt uiMvpDvPos
5231#if H_3D_NBDV_REF
5232, Bool bDepthRefine
5233#endif
5234)
5235{
5236  if( pcTmpCU != NULL && !pcTmpCU->isIntra( uiIdx ) )
5237  {
5238    Bool bTmpIsSkipped = pcTmpCU->isSkipped( uiIdx );
5239    for(Int iList = 0; iList < (getSlice()->isInterB() ? 2: 1); iList ++)
5240    {
5241      RefPicList eRefPicList = RefPicList(iList);
5242      Int      refId = pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) ;
5243      TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
5244
5245      if( refId >= 0)
5246      {
5247        Int refViewIdx  = pcTmpCU->getSlice()->getRefPic(eRefPicList, refId)->getViewIndex();
5248        if (refViewIdx != m_pcSlice->getViewIndex()) 
5249        {
5250          clipMv(cMvPred);
5251          pNbDvInfo->m_acNBDV = cMvPred;
5252          pNbDvInfo->m_aVIdxCan = refViewIdx;
5253#if H_3D_NBDV_REF
5254          TComPic* picDepth = NULL;
5255          assert(getSlice()->getRefPic(eRefPicList, refId)->getPOC() == getSlice()->getPOC());         
5256          picDepth   = getSlice()->getIvPic (true, refViewIdx );
5257          assert(picDepth != NULL);
5258
5259          UInt uiPartIdx = 0;   //Notes from MTK: Please confirm that using 0 as partition index and partition address is correct for CU-level DoNBDV
5260          UInt uiPartAddr = 0;  //QC: confirmed
5261
5262          if (picDepth && bDepthRefine)
5263            estimateDVFromDM(refViewIdx, uiPartIdx, picDepth, uiPartAddr, &cMvPred );
5264
5265          pNbDvInfo->m_acDoNBDV = cMvPred;
5266#endif
5267          return true;
5268        }
5269        else if ( bSearchForMvpDv && cMvPred.getIDVFlag() && bTmpIsSkipped )
5270        {
5271          assert( uiMvpDvPos < IDV_CANDS );
5272          paIDVInfo->m_acMvCand[iList][ uiMvpDvPos ] = TComMv( cMvPred.getIDVHor(), cMvPred.getIDVVer() );
5273          //Notes from QC: DvMCP is implemented in a way that doesn�t carry the reference view identifier as NBDV. It only works for CTC and needs to be fixed to be aligned with other part of the NBDV design.
5274#if MTK_DVMCP_FIX_E0172
5275          paIDVInfo->m_aVIdxCan[iList][ uiMvpDvPos ] = cMvPred.getIDVVId();
5276#else 
5277          paIDVInfo->m_aVIdxCan[iList][ uiMvpDvPos ] = 0; 
5278#endif
5279          paIDVInfo->m_bAvailab[iList][ uiMvpDvPos ] = true;
5280          paIDVInfo->m_bFound                        = true; 
5281        }
5282      }
5283    }
5284  }
5285  return false; 
5286}
5287 
5288Void TComDataCU::xDeriveRightBottomNbIdx(Int &riLCUIdxRBNb, Int &riPartIdxRBNb )
5289{
5290  UInt uiPartIdx = 0;
5291  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth(); 
5292  Int uiLCUIdx = getAddr();
5293
5294  UInt uiPartIdxRB;
5295  deriveRightBottomIdx(uiPartIdx, uiPartIdxRB ); 
5296  UInt uiAbsPartIdxTmp = g_auiZscanToRaster[uiPartIdxRB];
5297
5298  if (( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth() )>= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )
5299  {
5300    riLCUIdxRBNb  = -1;
5301    riPartIdxRBNb = -1;
5302  }
5303  else if(( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxTmp] + m_pcPic->getMinCUHeight() )>= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
5304  {
5305    riLCUIdxRBNb  = -1;
5306    riPartIdxRBNb = -1;
5307  }
5308  else
5309  {
5310    if ( ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
5311      ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
5312    {
5313      riPartIdxRBNb = g_auiRasterToZscan[ uiAbsPartIdxTmp + uiNumPartInCUWidth + 1 ];
5314      riLCUIdxRBNb  = uiLCUIdx; 
5315    }
5316    else if ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
5317    {
5318      riPartIdxRBNb = -1;
5319      riLCUIdxRBNb  = -1;
5320    }
5321    else if ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
5322    {
5323      riPartIdxRBNb = g_auiRasterToZscan[ uiAbsPartIdxTmp + 1 ];
5324      riLCUIdxRBNb = uiLCUIdx + 1;
5325    }
5326    else //is the right bottom corner of LCU                       
5327    {
5328      riPartIdxRBNb = -1;
5329      riLCUIdxRBNb  = -1;
5330    }
5331  }
5332}
5333
5334
5335Void TComDataCU::setDvInfoSubParts( DisInfo cDvInfo, UInt uiAbsPartIdx, UInt uiDepth )
5336{
5337  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
5338  for (UInt ui = 0; ui < uiCurrPartNumb; ui++ )
5339  {
5340    m_pDvInfo[uiAbsPartIdx + ui] = cDvInfo;
5341  }
5342}
5343#if MTK_NBDV_TN_FIX_E0172
5344Bool TComDataCU::xGetColDisMV( Int currCandPic, RefPicList eRefPicList, Int refidx, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv , Int & iTargetViewIdx, Int & iStartViewIdx )
5345#else
5346Bool TComDataCU::xGetColDisMV( RefPicList eRefPicList, Int refidx, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv , Int & iTargetViewIdx, Int & iStartViewIdx )
5347#endif
5348{
5349
5350  RefPicList  eColRefPicList = REF_PIC_LIST_0;
5351  Int iColViewIdx, iColRefViewIdx;
5352  TComPic *pColPic = getSlice()->getRefPic( eRefPicList, refidx);
5353  TComDataCU *pColCU = pColPic->getCU( uiCUAddr );
5354  iColViewIdx = pColCU->getSlice()->getViewIndex();
5355  if (pColCU->getPic()==0||pColCU->getPartitionSize(uiPartUnitIdx)==SIZE_NONE||pColCU->isIntra(uiPartUnitIdx))
5356  {
5357    return false;
5358  }
5359  for (Int ilist = 0; ilist < (pColCU->getSlice()->isInterB()? 2:1); ilist++) 
5360  {
5361    if(pColCU->getSlice()->isInterB())
5362    {
5363        eColRefPicList = RefPicList(ilist);
5364    }
5365
5366    Int iColRefIdx = pColCU->getCUMvField(eColRefPicList)->getRefIdx(uiPartUnitIdx);
5367
5368    if (iColRefIdx < 0)
5369    {
5370      continue;
5371    }
5372
5373    iColRefViewIdx = pColCU->getSlice()->getRefPic(eColRefPicList, iColRefIdx)->getViewIndex();
5374
5375    if ( iColViewIdx    == iColRefViewIdx ) // temporal vector
5376    {
5377      continue;
5378    }
5379    else 
5380    {
5381#if MTK_NBDV_TN_FIX_E0172
5382      if(getPic()->isTempIVRefValid(currCandPic, ilist,  iColRefIdx))
5383      {
5384#endif
5385      rcMv = pColCU->getCUMvField(eColRefPicList)->getMv(uiPartUnitIdx);
5386      rcMv.setIDVFlag(0);
5387      iTargetViewIdx  = iColRefViewIdx ;
5388      iStartViewIdx   = iColViewIdx   ;
5389      return true;   
5390#if MTK_NBDV_TN_FIX_E0172
5391      }
5392#endif
5393    }
5394  }
5395
5396  return false;
5397}
5398#endif
5399#if H_3D_IV_MERGE
5400Bool
5401TComDataCU::getInterViewMergeCands(UInt uiPartIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv, DisInfo* pDInfo, Int* availableMcDc )
5402{
5403  TComSlice*    pcSlice         = getSlice (); 
5404  Int iViewIndex = pDInfo->m_aVIdxCan;
5405  //--- get base CU/PU and check prediction mode ---
5406  TComPic*    pcBasePic   = pcSlice->getIvPic( false, iViewIndex );
5407  TComPicYuv* pcBaseRec   = pcBasePic->getPicYuvRec   ();
5408
5409  UInt          uiPartAddr;
5410  Int           iWidth;
5411  Int           iHeight;
5412  getPartIndexAndSize( uiPartIdx, uiPartAddr, iWidth, iHeight );
5413
5414  Int  iCurrPosX, iCurrPosY;
5415  pcBaseRec->getTopLeftSamplePos( getAddr(), getZorderIdxInCU() + uiPartAddr, iCurrPosX, iCurrPosY );
5416
5417  iCurrPosX  += ( ( iWidth  - 1 ) >> 1 );
5418  iCurrPosY  += ( ( iHeight - 1 ) >> 1 );
5419
5420  Bool depthRefineFlag = false; 
5421#if H_3D_NBDV_REF
5422  depthRefineFlag = m_pcSlice->getVPS()->getDepthRefinementFlag( m_pcSlice->getLayerIdInVps() ); 
5423#endif // H_3D_NBDV_REF
5424
5425  TComMv      cDv = depthRefineFlag ? pDInfo->m_acDoNBDV : pDInfo->m_acNBDV; 
5426 
5427  Int         iBasePosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (cDv.getHor() + 2 ) >> 2 ) );
5428  Int         iBasePosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (cDv.getVer() + 2 ) >> 2 )); 
5429
5430  Int         iBaseCUAddr;
5431  Int         iBaseAbsPartIdx;
5432  pcBaseRec->getCUAddrAndPartIdx( iBasePosX , iBasePosY , iBaseCUAddr, iBaseAbsPartIdx );
5433
5434  TComDataCU* pcBaseCU    = pcBasePic->getCU( iBaseCUAddr );
5435
5436  Bool abPdmAvailable[4] = {false, false, false, false};
5437#if H_3D_NBDV
5438  for( Int i = 0; i < 4; i++)
5439  {
5440    pacPdmMv[i].setIDVFlag   (false);
5441  }
5442#endif
5443  if(!( pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) == MODE_INTRA ))
5444  {
5445    for( UInt uiCurrRefListId = 0; uiCurrRefListId < 2; uiCurrRefListId++ )
5446    {
5447      RefPicList  eCurrRefPicList = RefPicList( uiCurrRefListId );
5448
5449      Bool stopLoop = false;
5450      for(Int iLoop = 0; iLoop < 2 && !stopLoop; ++iLoop)
5451      {
5452        RefPicList eBaseRefPicList = (iLoop ==1)? RefPicList( 1 -  uiCurrRefListId ) : RefPicList( uiCurrRefListId );
5453        TComMvField cBaseMvField;
5454        pcBaseCU->getMvField( pcBaseCU, iBaseAbsPartIdx, eBaseRefPicList, cBaseMvField );
5455        Int         iBaseRefIdx     = cBaseMvField.getRefIdx();
5456        if (iBaseRefIdx >= 0)
5457        {
5458          Int iBaseRefPOC = pcBaseCU->getSlice()->getRefPOC(eBaseRefPicList, iBaseRefIdx);
5459          if (iBaseRefPOC != pcSlice->getPOC())   
5460          {
5461            for (Int iPdmRefIdx = 0; iPdmRefIdx < pcSlice->getNumRefIdx( eCurrRefPicList ); iPdmRefIdx++)
5462            {
5463              if (iBaseRefPOC == pcSlice->getRefPOC(eCurrRefPicList, iPdmRefIdx))
5464              {
5465                abPdmAvailable[ uiCurrRefListId ] = true;
5466                TComMv cMv(cBaseMvField.getHor(), cBaseMvField.getVer());
5467#if H_3D_NBDV
5468                cMv.setIDVFlag   (true);
5469                cMv.setIDVHor    (cDv.getHor());                 
5470                cMv.setIDVVer    (cDv.getVer()); 
5471#if MTK_DVMCP_FIX_E0172
5472                cMv.setIDVVId    (iViewIndex); 
5473#endif
5474#endif
5475                clipMv( cMv );
5476                paiPdmRefIdx  [ uiCurrRefListId ] = iPdmRefIdx;
5477                pacPdmMv      [ uiCurrRefListId ] = cMv;
5478                stopLoop = true;
5479                break;
5480              }
5481            }
5482          }
5483        }
5484      }
5485    }
5486  }
5487  availableMcDc[0] = ( abPdmAvailable[0] ? 1 : 0 ) + ( abPdmAvailable[1] ? 2 : 0 );
5488  for( Int iRefListId = 0; iRefListId < 2 ; iRefListId++ )
5489  {
5490    RefPicList  eRefPicListDMV       = RefPicList( iRefListId );
5491    Int         iNumRefPics       = pcSlice->getNumRefIdx( eRefPicListDMV );
5492    for( Int iPdmRefIdx = 0; iPdmRefIdx < iNumRefPics; iPdmRefIdx++ )
5493    {
5494#if MTK_DIVMC_FIX_E0172
5495      if(( pcSlice->getRefPOC( eRefPicListDMV, iPdmRefIdx ) == pcSlice->getPOC()) && (pcSlice->getRefPic( eRefPicListDMV, iPdmRefIdx )->getViewIndex() == pDInfo->m_aVIdxCan))
5496#else
5497      if( pcSlice->getRefPOC( eRefPicListDMV, iPdmRefIdx ) == pcSlice->getPOC())
5498#endif
5499      {
5500        abPdmAvailable[ iRefListId+2 ] = true;
5501        paiPdmRefIdx  [ iRefListId+2 ] = iPdmRefIdx;
5502
5503#if H_3D_NBDV_REF
5504        TComMv cMv = depthRefineFlag ? pDInfo->m_acDoNBDV : pDInfo->m_acNBDV; 
5505#endif // H_3D_NBDV_REF
5506        cMv.setVer(0);
5507        clipMv( cMv );
5508        pacPdmMv      [ iRefListId + 2] = cMv;
5509        break;
5510      }
5511    }
5512  }
5513  availableMcDc[1] = ( abPdmAvailable[2] ? 1 : 0 ) + ( abPdmAvailable[3] ? 2 : 0 );
5514  return false;
5515}
5516#endif
5517#if H_3D_ARP
5518Void TComDataCU::setARPWSubParts ( UChar w, UInt uiAbsPartIdx, UInt uiDepth )
5519{
5520  assert( sizeof( *m_puhARPW) == 1 );
5521  memset( m_puhARPW + uiAbsPartIdx, w, m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ) );
5522}
5523#endif
5524
5525#if H_3D_IC
5526Void TComDataCU::setICFlagSubParts( Bool bICFlag, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
5527{
5528  memset( m_pbICFlag + uiAbsPartIdx, bICFlag, (m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ))*sizeof(Bool) );
5529}
5530
5531Bool TComDataCU::isICFlagRequired( UInt uiAbsPartIdx )
5532{
5533  UInt uiPartAddr;
5534  UInt iNumbPart;
5535
5536  if( !( getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) )
5537  {
5538    return false;
5539  }
5540
5541  if( getSlice()->getIcSkipParseFlag() )
5542  {
5543    if( getMergeFlag( uiAbsPartIdx ) && getMergeIndex( uiAbsPartIdx ) == 0 )
5544    {
5545      return false;
5546    }
5547  }
5548
5549  if( getMergeFlag( uiAbsPartIdx ) )
5550  {
5551    return true;
5552  }
5553
5554
5555  Int iWidth, iHeight;
5556
5557  iNumbPart = ( getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ? 1 : ( getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ? 4 : 2 ) );
5558
5559  for(UInt i = 0; i < iNumbPart; i++)
5560  {
5561    getPartIndexAndSize( i, uiPartAddr, iWidth, iHeight, uiAbsPartIdx, true );
5562    uiPartAddr += uiAbsPartIdx;
5563
5564    for(UInt uiRefIdx = 0; uiRefIdx < 2; uiRefIdx++)
5565    {
5566      RefPicList eRefList = uiRefIdx ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
5567      Int iBestRefIdx = getCUMvField(eRefList)->getRefIdx(uiPartAddr);
5568
5569      if( ( getInterDir( uiPartAddr ) & ( uiRefIdx+1 ) ) && iBestRefIdx >= 0 && getSlice()->getViewIndex() != getSlice()->getRefPic( eRefList, iBestRefIdx )->getViewIndex() )
5570      {
5571        return true;
5572      }
5573    }
5574  }
5575
5576  return false;
5577}
5578#if H_3D_DIM_DMM
5579Void TComDataCU::setDmmWedgeTabIdxSubParts( UInt tabIdx, UInt dmmType, UInt uiAbsPartIdx, UInt uiDepth )
5580{
5581  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
5582  for( UInt ui = 0; ui < uiCurrPartNumb; ui++ ) { m_dmmWedgeTabIdx[dmmType][uiAbsPartIdx+ui] = tabIdx; }
5583}
5584Void  TComDataCU::setDmm2DeltaEndSubParts( Int iDelta, UInt uiAbsPartIdx, UInt uiDepth )
5585{
5586  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
5587  for( UInt ui = 0; ui < uiCurrPartNumb; ui++ ) { m_dmm2DeltaEnd[uiAbsPartIdx+ui] = iDelta; }
5588}
5589Void  TComDataCU::setDmm3IntraTabIdxSubParts( UInt uiTIdx, UInt uiAbsPartIdx, UInt uiDepth )
5590{
5591  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
5592  for( UInt ui = 0; ui < uiCurrPartNumb; ui++ ) { m_dmm3IntraTabIdx[uiAbsPartIdx+ui] = uiTIdx; }
5593}
5594#endif
5595#if H_3D_DIM_RBC
5596Void TComDataCU::reconPartition( UInt uiAbsPartIdx, UInt uiDepth, Bool bLeft, UChar ucStartPos, UChar ucNumEdge, UChar* pucEdgeCode, Bool* pbRegion )
5597{
5598  Int iWidth;
5599  Int iHeight;
5600  if( uiDepth == 0 )
5601  {
5602    iWidth = 64;
5603    iHeight = 64;
5604  }
5605  else if( uiDepth == 1 )
5606  {
5607    iWidth = 32;
5608    iHeight = 32;
5609  }
5610  else if( uiDepth == 2 )
5611  {
5612    iWidth = 16;
5613    iHeight = 16;
5614  }
5615  else if( uiDepth == 3 )
5616  {
5617    iWidth = 8;
5618    iHeight = 8;
5619  }
5620  else // uiDepth == 4
5621  {
5622    iWidth = 4;
5623    iHeight = 4;
5624  }
5625
5626  Int iPtr = 0;
5627  Int iX, iY;
5628  Int iDir = -1;
5629  Int iDiffX = 0, iDiffY = 0;
5630
5631  // 1. Edge Code -> Vert & Horz Edges
5632  Bool*  pbEdge = (Bool*) xMalloc( Bool, 4 * iWidth * iHeight );
5633
5634  for( UInt ui = 0; ui < 4 * iWidth * iHeight; ui++ )
5635    pbEdge  [ ui ] = false;
5636
5637  // Direction : left(0), right(1), top(2), bottom(3), left-top(4), right-top(5), left-bottom(6), right-bottom(7)
5638  // Code      : 0deg(0), 45deg(1), -45deg(2), 90deg(3), -90deg(4), 135deg(5), -135deg(6)
5639  const UChar tableDir[8][7] = { { 0, 6, 4, 3, 2, 7, 5 },
5640  { 1, 5, 7, 2, 3, 4, 6 },
5641  { 2, 4, 5, 0, 1, 6, 7 },
5642  { 3, 7, 6, 1, 0, 5, 4 },
5643  { 4, 0, 2, 6, 5, 3, 1 },
5644  { 5, 2, 1, 4, 7, 0, 3 },
5645  { 6, 3, 0, 7, 4, 1, 2 },
5646  { 7, 1, 3, 5, 6, 2, 0 }};
5647
5648  UChar ucCode = pucEdgeCode[iPtr++];
5649
5650  if( !bLeft )
5651  {
5652    iX = ucStartPos;
5653    iY = 0;
5654
5655    switch(ucCode)
5656    {
5657    case 0: // bottom
5658      iDir = 3;
5659      if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
5660      break;
5661    case 2: // left-bottom
5662      iDir = 6;
5663      if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
5664      break;
5665    case 1: // right-bottom
5666      iDir = 7;
5667      if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
5668      if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5669      break;
5670    case 4: // left
5671      iDir = 0;
5672      assert(false);
5673      break;
5674    case 3: // right
5675      iDir = 1;
5676      if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
5677      if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5678      break;
5679    }
5680  }
5681  else
5682  {
5683    iX = 0;
5684    iY = ucStartPos;
5685
5686    switch(ucCode)
5687    {
5688    case 0: // right
5689      iDir = 1;
5690      if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5691      break;
5692    case 1: // right-top
5693      iDir = 5;
5694      if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5695      if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
5696      break;
5697    case 2: // right-bottom
5698      iDir = 7;
5699      if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5700      break;
5701    case 3: // top
5702      iDir = 2;
5703      if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5704      if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
5705      break;
5706    case 4: // bottom
5707      iDir = 3;
5708      assert(false);
5709      break;
5710    }
5711  }
5712
5713  switch( iDir )
5714  {
5715  case 0: // left
5716    iDiffX = -1;
5717    iDiffY = 0;
5718    break;
5719  case 1: // right
5720    iDiffX = +1;
5721    iDiffY = 0;
5722    break;
5723  case 2: // top
5724    iDiffX = 0;
5725    iDiffY = -1;
5726    break;
5727  case 3: // bottom
5728    iDiffX = 0;
5729    iDiffY = +1;
5730    break;
5731  case 4: // left-top
5732    iDiffX = -1;
5733    iDiffY = -1;
5734    break;
5735  case 5: // right-top
5736    iDiffX = +1;
5737    iDiffY = -1;
5738    break;
5739  case 6: // left-bottom
5740    iDiffX = -1;
5741    iDiffY = +1;
5742    break;
5743  case 7: // right-bottom
5744    iDiffX = +1;
5745    iDiffY = +1;
5746    break;
5747  }
5748
5749  iX += iDiffX;
5750  iY += iDiffY;
5751
5752  while( iPtr < ucNumEdge )
5753  {
5754    ucCode = pucEdgeCode[iPtr++];
5755
5756    Int iNewDir = tableDir[iDir][ucCode];
5757
5758    switch( iNewDir )
5759    {
5760    case 0: // left
5761      iDiffX = -1;
5762      iDiffY = 0;
5763      break;
5764    case 1: // right
5765      iDiffX = +1;
5766      iDiffY = 0;
5767      break;
5768    case 2: // top
5769      iDiffX = 0;
5770      iDiffY = -1;
5771      break;
5772    case 3: // bottom
5773      iDiffX = 0;
5774      iDiffY = +1;
5775      break;
5776    case 4: // left-top
5777      iDiffX = -1;
5778      iDiffY = -1;
5779      break;
5780    case 5: // right-top
5781      iDiffX = +1;
5782      iDiffY = -1;
5783      break;
5784    case 6: // left-bottom
5785      iDiffX = -1;
5786      iDiffY = +1;
5787      break;
5788    case 7: // right-bottom
5789      iDiffX = +1;
5790      iDiffY = +1;
5791      break;
5792    }
5793
5794    switch( iDir )
5795    {
5796    case 0: // left
5797      switch( ucCode )
5798      {
5799      case 0:
5800      case 2:
5801        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
5802        break;
5803      case 1:
5804      case 3:
5805        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
5806        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
5807        break;
5808      case 4:
5809      case 6:
5810        // no
5811        break;
5812      case 5:
5813        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
5814        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5815        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
5816        break;
5817      }
5818      break;
5819    case 1: // right
5820      switch( ucCode )
5821      {
5822      case 0:
5823      case 2:
5824        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5825        break;
5826      case 1:
5827      case 3:
5828        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5829        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
5830        break;
5831      case 4:
5832      case 6:
5833        // no
5834        break;
5835      case 5:
5836        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
5837        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5838        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
5839        break;
5840      }
5841      break;
5842    case 2: // top
5843      switch( ucCode )
5844      {
5845      case 0:
5846      case 2:
5847        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
5848        break;
5849      case 1:
5850      case 3:
5851        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
5852        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
5853        break;
5854      case 4:
5855      case 6:
5856        // no
5857        break;
5858      case 5:
5859        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
5860        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
5861        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
5862        break;
5863      }
5864      break;
5865    case 3: // bottom
5866      switch( ucCode )
5867      {
5868      case 0:
5869      case 2:
5870        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
5871        break;
5872      case 1:
5873      case 3:
5874        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
5875        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5876        break;
5877      case 4:
5878      case 6:
5879        // no
5880        break;
5881      case 5:
5882        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
5883        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
5884        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5885        break;
5886      }
5887      break;
5888    case 4: // left-top
5889      switch( ucCode )
5890      {
5891      case 0:
5892      case 1:
5893        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
5894        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
5895        break;
5896      case 2:
5897      case 4:
5898        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
5899        break;
5900      case 3:
5901      case 5:
5902        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
5903        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
5904        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
5905        break;
5906      case 6:
5907        // no
5908        break;
5909      }
5910      break;
5911    case 5: // right-top
5912      switch( ucCode )
5913      {
5914      case 0:
5915      case 1:
5916        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5917        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
5918        break;
5919      case 2:
5920      case 4:
5921        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5922        break;
5923      case 3:
5924      case 5:
5925        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
5926        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5927        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
5928        break;
5929      case 6:
5930        // no
5931        break;
5932      }
5933      break;
5934    case 6: // left-bottom
5935      switch( ucCode )
5936      {
5937      case 0:
5938      case 1:
5939        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
5940        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
5941        break;
5942      case 2:
5943      case 4:
5944        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
5945        break;
5946      case 3:
5947      case 5:
5948        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
5949        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
5950        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5951        break;
5952      case 6:
5953        // no
5954        break;
5955      }
5956      break;
5957    case 7: // right-bottom
5958      switch( ucCode )
5959      {
5960      case 0:
5961      case 1:
5962        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5963        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
5964        break;
5965      case 2:
5966      case 4:
5967        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
5968        break;
5969      case 3:
5970      case 5:
5971        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
5972        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
5973        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5974        break;
5975      case 6:
5976        // no
5977        break;
5978      }
5979      break;
5980    }
5981
5982    assert( iX >= 0 && iX <= iWidth );
5983    assert( iY >= 0 && iY <= iHeight );
5984
5985    iX += iDiffX;
5986    iY += iDiffY;
5987    iDir = iNewDir;
5988  }
5989
5990  // finalize edge chain
5991  if( iX == iWidth-1 )
5992  {
5993    if( iY == 0 )
5994    {
5995      if( iDir == 1 )
5996      {
5997        pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
5998      }
5999      else if( iDir == 5 )
6000      {
6001        pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
6002      }
6003      else
6004      {
6005        assert(false);
6006      }
6007    }
6008    else if( iY == iHeight-1 )
6009    {
6010      if( iDir == 3 )
6011      {
6012        pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
6013      }
6014      else if( iDir == 7 )
6015      {
6016        pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
6017      }
6018      else
6019      {
6020        assert(false);
6021      }
6022    }
6023    else
6024    {
6025      if( iDir == 1 )
6026      {
6027        pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
6028      }
6029      else if( iDir == 3 )
6030      {
6031        pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
6032        pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
6033      }
6034      else if( iDir == 5 )
6035      {
6036        pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
6037      }
6038      else if( iDir == 7 )
6039      {
6040        pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
6041        pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
6042      }
6043      else
6044      {
6045        assert(false);
6046      }
6047    }
6048  }
6049  else if( iX == 0 )
6050  {
6051    if( iY == 0 )
6052    {
6053      if( iDir == 2 )
6054      {
6055        pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
6056      }
6057      else if( iDir == 4 )
6058      {
6059        pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
6060      }
6061      else
6062      {
6063        assert(false);
6064      }
6065    }
6066    else if( iY == iHeight-1 )
6067    {
6068      if( iDir == 0 )
6069      {
6070        pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
6071      }
6072      else if( iDir == 6 )
6073      {
6074        pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
6075      }
6076      else
6077      {
6078        assert(false);
6079      }
6080    }
6081    else
6082    {
6083      if( iDir == 0 )
6084      {
6085        pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
6086      }
6087      else if( iDir == 2 )
6088      {
6089        pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
6090        pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
6091      }
6092      else if( iDir == 4 )
6093      {
6094        pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
6095        pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
6096      }
6097      else if( iDir == 6 )
6098      {
6099        pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
6100      }
6101      else
6102      {
6103        assert(false);
6104      }
6105    }
6106  }
6107  else if( iY == 0 )
6108  {
6109    if( iDir == 1 )
6110    {
6111      pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
6112      pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
6113    }
6114    else if( iDir == 2 )
6115    {
6116      pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
6117    }
6118    else if( iDir == 4 )
6119    {
6120      pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
6121    }
6122    else if( iDir == 5 )
6123    {
6124      pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
6125      pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
6126    }
6127    else
6128    {
6129      assert(false);
6130    }
6131  }
6132  else if( iY == iHeight-1 )
6133  {
6134    if( iDir == 0 )
6135    {
6136      pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
6137      pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
6138    }
6139    else if( iDir == 3 )
6140    {
6141      pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
6142    }
6143    else if( iDir == 6 )
6144    {
6145      pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
6146      pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
6147    }
6148    else if( iDir == 7 )
6149    {
6150      pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
6151    }
6152    else
6153    {
6154      assert(false);
6155    }
6156  }
6157  else
6158  {
6159    printf("reconPartiton: wrong termination\n");
6160    assert(false);
6161  }
6162
6163  // Reconstruct Region from Chain Code
6164  Bool* pbVisit  = (Bool*) xMalloc( Bool, iWidth * iHeight );
6165  Int*  piStack  = (Int* ) xMalloc( Int,  iWidth * iHeight );
6166
6167  for( UInt ui = 0; ui < iWidth * iHeight; ui++ )
6168  {
6169    pbRegion[ ui ] = true; // fill it as region 1 (we'll discover region 0 next)
6170    pbVisit [ ui ] = false;
6171  }
6172
6173  iPtr = 0;
6174  piStack[iPtr++] = (0 << 8) | (0);
6175  pbRegion[ 0 ] = false;
6176
6177  while(iPtr > 0)
6178  {
6179    Int iTmp = piStack[--iPtr];
6180    Int iX1, iY1;
6181    iX1 = iTmp & 0xff;
6182    iY1 = (iTmp >> 8) & 0xff;
6183
6184    pbVisit[ iX1 + iY1 * iWidth ] = true;
6185
6186    assert( iX1 >= 0 && iX1 < iWidth );
6187    assert( iY1 >= 0 && iY1 < iHeight );
6188
6189    if( iX1 > 0 && !pbEdge[ 2 * iX1 - 1 + 4 * iY1 * iWidth ] && !pbVisit[ iX1 - 1 + iY1 * iWidth ] )
6190    {
6191      piStack[iPtr++] = (iY1 << 8) | (iX1 - 1);
6192      pbRegion[ iX1 - 1 + iY1 * iWidth ] = false;
6193    }
6194    if( iX1 < iWidth - 1 && !pbEdge[ 2 * iX1 + 1 + 4 * iY1 * iWidth ] && !pbVisit[ iX1 + 1 + iY1 * iWidth ] )
6195    {
6196      piStack[iPtr++] = (iY1 << 8) | (iX1 + 1);
6197      pbRegion[ iX1 + 1 + iY1 * iWidth ] = false;
6198    }
6199    if( iY1 > 0 && !pbEdge[ 2 * iX1 + 2 * (2 * iY1 - 1) * iWidth ] && !pbVisit[ iX1 + (iY1 - 1) * iWidth ] )
6200    {
6201      piStack[iPtr++] = ((iY1 - 1) << 8) | iX1;
6202      pbRegion[ iX1 + (iY1 - 1) * iWidth ] = false;
6203    }
6204    if( iY1 < iHeight - 1 && !pbEdge[ 2 * iX1 + 2 * (2 * iY1 + 1) * iWidth ] && !pbVisit[ iX1 + (iY1 + 1) * iWidth ] )
6205    {
6206      piStack[iPtr++] = ((iY1 + 1) << 8) | iX1;
6207      pbRegion[ iX1 + (iY1 + 1) * iWidth ] = false;
6208    }
6209  }
6210
6211  xFree( pbEdge );
6212  xFree( pbVisit );
6213  xFree( piStack );
6214}
6215#endif
6216#endif
6217
6218//! \}
Note: See TracBrowser for help on using the repository browser.