source: 3DVCSoftware/branches/HTM-DEV-2.0-dev2-LG/source/Lib/TLibCommon/TComDataCU.cpp

Last change on this file was 591, checked in by lg, 11 years ago

Three bug fixed.

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