source: 3DVCSoftware/branches/HTM-8.2-dev2-LG/source/Lib/TLibCommon/TComDataCU.cpp @ 1417

Last change on this file since 1417 was 690, checked in by lg, 11 years ago

Integration of "Removal of redundancy on VSP, ARP and IC"
FJCT3V-F0104
MACRO "LGE_SHARP_VSP_INHERIT_F0104"

By Taesup Kim (taesup.kim@…)

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