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

Last change on this file since 1327 was 669, checked in by zhang, 11 years ago

JCT3V-F0125

  • Property svn:eol-style set to native
File size: 239.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#if H_3D_IV_MERGE
3529 
3530  /////////////////////////////////////////////
3531  //////// TEXTURE MERGE CANDIDATE (T) ////////
3532  /////////////////////////////////////////////
3533
3534  if( m_pcSlice->getIsDepth())
3535  {
3536    UInt uiPartIdxCenter;
3537    xDeriveCenterIdx( uiPUIdx, uiPartIdxCenter );   
3538#if H_3D_FCO
3539    TComPic * pcTexturePic = m_pcSlice->getTexturePic();
3540    TComDataCU *pcTextureCU = 0;
3541    if ( pcTexturePic )
3542        pcTextureCU = pcTexturePic->getCU( getAddr() );
3543#else
3544    TComDataCU *pcTextureCU = m_pcSlice->getTexturePic()->getCU( getAddr() );
3545#endif
3546 
3547#if H_3D_FCO
3548    if ( pcTextureCU && pcTexturePic->getReconMark() && !pcTextureCU->isIntra( uiPartIdxCenter ) )
3549#else
3550    if ( pcTextureCU && !pcTextureCU->isIntra( uiPartIdxCenter ) )
3551#endif
3552    {
3553      pcTextureCU->getMvField( pcTextureCU, uiPartIdxCenter, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3554      Int iValidDepRef = getPic()->isTextRefValid( REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1].getRefIdx() );
3555      if( (pcMvFieldNeighbours[iCount<<1].getRefIdx()>=0) && ( iValidDepRef >= 0 ) )
3556      {
3557        TComMv cMvPred = pcMvFieldNeighbours[iCount<<1].getMv();
3558        const TComMv cAdd( 1 << ( 2 - 1 ), 1 << ( 2 - 1 ) );
3559        cMvPred+=cAdd;
3560        cMvPred>>=2;
3561        clipMv(cMvPred);
3562        pcMvFieldNeighbours[iCount<<1].setMvField(cMvPred,iValidDepRef);
3563      }
3564
3565      if ( getSlice()->isInterB() )
3566      {
3567        pcTextureCU->getMvField( pcTextureCU, uiPartIdxCenter, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3568        iValidDepRef = getPic()->isTextRefValid( REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1].getRefIdx() );
3569        if( (pcMvFieldNeighbours[(iCount<<1)+1].getRefIdx()>=0) && ( iValidDepRef >= 0) )
3570        {
3571          TComMv cMvPred = pcMvFieldNeighbours[(iCount<<1)+1].getMv();
3572          const TComMv cAdd( 1 << ( 2 - 1 ), 1 << ( 2 - 1 ) );
3573          cMvPred+=cAdd;
3574          cMvPred>>=2;
3575          clipMv(cMvPred);
3576          pcMvFieldNeighbours[(iCount<<1)+1].setMvField(cMvPred,iValidDepRef);
3577        }
3578      }
3579
3580      puhInterDirNeighbours[iCount] = (pcMvFieldNeighbours[iCount<<1].getRefIdx()>=0)?1:0;
3581      puhInterDirNeighbours[iCount] += (pcMvFieldNeighbours[(iCount<<1)+1].getRefIdx()>=0)?2:0;
3582
3583      if( puhInterDirNeighbours[iCount] != 0 )
3584      {
3585        abCandIsInter[iCount] = true;
3586        if ( mrgCandIdx == iCount )
3587        {
3588          return;
3589        }
3590        iCount ++;
3591      }
3592    }
3593  }
3594
3595  //////////////////////////////////
3596  //////// GET DISPARITIES  ////////
3597  //////////////////////////////////
3598
3599  DisInfo cDisInfo = getDvInfo(uiAbsPartIdx);
3600
3601  for(Int i = 0; i < MRG_MAX_NUM_CANDS_MEM; i++)
3602  {
3603    inheritedVSPDisInfo[i].m_acDvInfo = cDisInfo;
3604  }
3605
3606  /////////////////////////////////////////////////////////////////
3607  //////// DERIVE IvMC, IvMCShift,IvDCShift, IvDC  Candidates /////
3608  /////////////////////////////////////////////////////////////////
3609
3610  Int  posIvDC          = -1;
3611  Bool bLeftAvai        = false;
3612  Int  iPosLeftAbove[2] = {-1, -1};
3613
3614
3615  // { IvMCL0, IvMCL1, IvDCL0, IvDCL1, IvMCL0Shift, IvMCL1Shift, IvDCL0Shift, IvDCL1Shift }; 
3616  // An enumerator would be appropriate here!
3617  TComMv ivCandMv    [8];
3618  Int    ivCandRefIdx[8] = {-1, -1, -1, -1, -1, -1, -1, -1};
3619
3620  // { IvMC, IvDC, IvMCShift, IvDCShift }; 
3621  Int    ivCandDir   [4] = {0, 0, 0, 0};
3622
3623  Bool ivMvPredFlag   = getSlice()->getVPS()->getIvMvPredFlag( getSlice()->getLayerIdInVps() );
3624 
3625  if ( ivMvPredFlag )
3626  {
3627    getInterViewMergeCands(uiPUIdx, ivCandRefIdx, ivCandMv, &cDisInfo, ivCandDir
3628#if QC_DEPTH_IV_MRG_F0125
3629    , bIsDepth
3630#endif
3631    );
3632  } 
3633 
3634  ///////////////////////////////////////////////
3635  //////// INTER VIEW MOTION COMP(IvMC) /////////
3636  ///////////////////////////////////////////////
3637
3638  if( ivCandDir[0] )
3639  {
3640    abCandIsInter        [ iCount ] = true;
3641    puhInterDirNeighbours[ iCount ] = ivCandDir[0];   
3642
3643    if( ( ivCandDir[0] & 1 ) == 1 )
3644    {
3645      pcMvFieldNeighbours[ iCount<<1    ].setMvField( ivCandMv[ 0 ], ivCandRefIdx[ 0 ] );
3646    }
3647    if( ( ivCandDir[0] & 2 ) == 2 )
3648    {
3649      pcMvFieldNeighbours[(iCount<<1)+1 ].setMvField( ivCandMv[ 1 ], ivCandRefIdx[ 1 ] );
3650    }
3651
3652#if QC_DEPTH_IV_MRG_F0125
3653    if ( bIsDepth )
3654    {
3655      Bool bRemoveSpa = false;
3656      Int iCnloop = iCount-1;
3657      for(; iCnloop >= 0; iCnloop --)
3658      {
3659        if(puhInterDirNeighbours[iCount] == puhInterDirNeighbours[iCnloop] && pcMvFieldNeighbours[iCnloop<<1]==pcMvFieldNeighbours[(iCount<<1)] && pcMvFieldNeighbours[(iCnloop<<1)+1]==pcMvFieldNeighbours[(iCount<<1)+1])
3660        {
3661          bRemoveSpa                      = true;
3662          abCandIsInter        [ iCount ] = false;
3663
3664          puhInterDirNeighbours[iCount]   = 0;
3665          pcMvFieldNeighbours[iCount<<1].setMvField( cZeroMv, NOT_VALID );
3666          pcMvFieldNeighbours[(iCount<<1)+1].setMvField( cZeroMv, NOT_VALID );
3667          break;
3668        }
3669      }
3670      if(!bRemoveSpa)
3671      {
3672        bDepthIPMCAvai = true;
3673      }
3674    }
3675    if ( bDepthIPMCAvai || !bIsDepth )
3676    {
3677#endif
3678    if ( mrgCandIdx == iCount )
3679    {
3680      return;
3681    }
3682    iCount ++;
3683#if QC_DEPTH_IV_MRG_F0125
3684    }
3685#endif
3686  } 
3687
3688  // early termination
3689  if (iCount == getSlice()->getMaxNumMergeCand()) 
3690  {
3691    return;
3692  }
3693#endif
3694
3695#if H_3D
3696  ////////////////////////////
3697  //////// LEFT (A1) /////////
3698  ////////////////////////////
3699#endif
3700  //left
3701  UInt uiLeftPartIdx = 0;
3702  TComDataCU* pcCULeft = 0;
3703  pcCULeft = getPULeft( uiLeftPartIdx, uiPartIdxLB );
3704  Bool isAvailableA1 = pcCULeft &&
3705  pcCULeft->isDiffMER(xP -1, yP+nPSH-1, xP, yP) &&
3706  !( uiPUIdx == 1 && (cCurPS == SIZE_Nx2N || cCurPS == SIZE_nLx2N || cCurPS == SIZE_nRx2N) ) &&
3707  !pcCULeft->isIntra( uiLeftPartIdx ) ;
3708  if ( isAvailableA1 )
3709  {
3710    abCandIsInter[iCount] = true;
3711    // get Inter Dir
3712    puhInterDirNeighbours[iCount] = pcCULeft->getInterDir( uiLeftPartIdx );
3713    // get Mv from Left
3714    pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3715    if ( getSlice()->isInterB() )
3716    {
3717      pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3718    }
3719#if H_3D_IV_MERGE
3720    Bool bRemoveSpa = false; //pruning to inter-view candidates
3721#if QC_DEPTH_IV_MRG_F0125
3722    Int  iCnloop = bDepthIPMCAvai ? (iCount-2): (iCount-1);
3723#else
3724    Int  iCnloop    = iCount - 1;
3725#endif
3726    for(; iCnloop >= 0; iCnloop --)
3727    {
3728      if(puhInterDirNeighbours[iCount] == puhInterDirNeighbours[iCnloop] && pcMvFieldNeighbours[iCnloop<<1]==pcMvFieldNeighbours[(iCount<<1)] && pcMvFieldNeighbours[(iCnloop<<1)+1]==pcMvFieldNeighbours[(iCount<<1)+1])
3729      {
3730        bRemoveSpa                      = true;
3731        abCandIsInter        [ iCount ] = false;
3732
3733        //reset to the default value for MC
3734        puhInterDirNeighbours[iCount]   = 0;
3735        pcMvFieldNeighbours[iCount<<1].setMvField( cZeroMv, NOT_VALID );
3736        pcMvFieldNeighbours[(iCount<<1)+1].setMvField( cZeroMv, NOT_VALID );
3737        break;
3738      }
3739    }
3740    if(!bRemoveSpa)
3741    {
3742      bLeftAvai = true;
3743      iPosLeftAbove[0] = iCount;
3744#if H_3D_NBDV
3745      pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3746      pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3747#endif
3748#if H_3D_VSP
3749      if (pcCULeft->getVSPFlag(uiLeftPartIdx) == 1)
3750      {
3751        vspFlag[iCount] = 1;
3752        xInheritVSPDisInfo(pcCULeft,uiLeftPartIdx,iCount,inheritedVSPDisInfo);
3753      }
3754#endif
3755      if ( mrgCandIdx == iCount )
3756      {
3757        return;
3758      }
3759      iCount ++;
3760    }
3761#else // H_3D_IV_MERGE
3762    if ( mrgCandIdx == iCount )
3763    {
3764      return;
3765    }
3766    iCount ++;
3767#endif // H_3D_IV_MERGE
3768  }
3769 
3770  // early termination
3771  if (iCount == getSlice()->getMaxNumMergeCand()) 
3772  {
3773    return;
3774  }
3775#if H_3D
3776  ////////////////////////////
3777  //////// ABOVE (B1) ////////
3778  ////////////////////////////
3779#endif
3780  // above
3781  UInt uiAbovePartIdx = 0;
3782  TComDataCU* pcCUAbove = 0;
3783  pcCUAbove = getPUAbove( uiAbovePartIdx, uiPartIdxRT );
3784  Bool isAvailableB1 = pcCUAbove &&
3785  pcCUAbove->isDiffMER(xP+nPSW-1, yP-1, xP, yP) &&
3786  !( uiPUIdx == 1 && (cCurPS == SIZE_2NxN || cCurPS == SIZE_2NxnU || cCurPS == SIZE_2NxnD) ) &&
3787  !pcCUAbove->isIntra( uiAbovePartIdx );
3788  if ( isAvailableB1 && (!isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAbove, uiAbovePartIdx ) ) )
3789  {
3790    abCandIsInter[iCount] = true;
3791    // get Inter Dir
3792    puhInterDirNeighbours[iCount] = pcCUAbove->getInterDir( uiAbovePartIdx );
3793    // get Mv from Left
3794    pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3795    if ( getSlice()->isInterB() )
3796    {
3797      pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3798    }
3799#if H_3D_IV_MERGE
3800    Bool bRemoveSpa = false; //pruning to inter-view candidates
3801#if QC_DEPTH_IV_MRG_F0125
3802    Int iCnloop;
3803    if( bIsDepth )
3804      iCnloop = (bLeftAvai && bDepthIPMCAvai) ? (iCount-3) : ((bLeftAvai || bDepthIPMCAvai)  ? (iCount-2): (iCount-1));
3805    else
3806      iCnloop = bLeftAvai? (iCount-2): (iCount-1);
3807#else
3808    Int  iCnloop    = bLeftAvai? (iCount-2): (iCount-1);
3809#endif
3810    for(; iCnloop >= 0; iCnloop --)
3811    {
3812      if(puhInterDirNeighbours[iCount] == puhInterDirNeighbours[iCnloop] && pcMvFieldNeighbours[iCnloop<<1]==pcMvFieldNeighbours[(iCount<<1)] && pcMvFieldNeighbours[(iCnloop<<1)+1]==pcMvFieldNeighbours[(iCount<<1)+1])
3813      {
3814        bRemoveSpa                      = true;
3815        abCandIsInter        [ iCount ] = false;
3816
3817        //reset to the default value for MC
3818        puhInterDirNeighbours[iCount]   = 0;
3819
3820        pcMvFieldNeighbours[iCount<<1]    .setMvField( cZeroMv, NOT_VALID );
3821        pcMvFieldNeighbours[(iCount<<1)+1].setMvField( cZeroMv, NOT_VALID );
3822        break;
3823      }
3824    }
3825
3826    if(!bRemoveSpa)
3827    {
3828      iPosLeftAbove[1] = iCount;
3829#if H_3D_NBDV
3830      pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3831      pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3832#endif
3833#if H_3D_VSP
3834      if (pcCUAbove->getVSPFlag(uiAbovePartIdx) == 1)
3835      {
3836
3837        vspFlag[iCount] = 1;
3838        xInheritVSPDisInfo(pcCUAbove,uiAbovePartIdx,iCount,inheritedVSPDisInfo);
3839      }
3840#endif
3841      if ( mrgCandIdx == iCount )
3842      {
3843        return;
3844      }
3845      iCount ++;
3846    }
3847#else // H_3D_IV_MERGE
3848    if ( mrgCandIdx == iCount )
3849    {
3850      return;
3851    }
3852    iCount ++;
3853#endif // H_3D_IV_MERGE
3854  }
3855  // early termination
3856  if (iCount == getSlice()->getMaxNumMergeCand()) 
3857  {
3858    return;
3859  }
3860
3861#if H_3D
3862  //////////////////////////////////
3863  //////// ABOVE RIGHT (B0) ////////
3864  //////////////////////////////////
3865#endif
3866
3867  // above right
3868  UInt uiAboveRightPartIdx = 0;
3869  TComDataCU* pcCUAboveRight = 0;
3870  pcCUAboveRight = getPUAboveRight( uiAboveRightPartIdx, uiPartIdxRT );
3871  Bool isAvailableB0 = pcCUAboveRight &&
3872  pcCUAboveRight->isDiffMER(xP+nPSW, yP-1, xP, yP) &&
3873  !pcCUAboveRight->isIntra( uiAboveRightPartIdx );
3874  if ( isAvailableB0 && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveRight, uiAboveRightPartIdx ) ) )
3875  {
3876    abCandIsInter[iCount] = true;
3877    // get Inter Dir
3878    puhInterDirNeighbours[iCount] = pcCUAboveRight->getInterDir( uiAboveRightPartIdx );
3879    // get Mv from Left
3880    pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3881    if ( getSlice()->isInterB() )
3882    {
3883      pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3884    }
3885#if H_3D_NBDV
3886    pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3887    pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3888#endif
3889#if H_3D_VSP
3890    if (pcCUAboveRight->getVSPFlag(uiAboveRightPartIdx) == 1)
3891    {
3892      vspFlag[iCount] = 1;
3893      xInheritVSPDisInfo(pcCUAboveRight,uiAboveRightPartIdx,iCount,inheritedVSPDisInfo);
3894    }
3895#endif
3896    if ( mrgCandIdx == iCount )
3897    {
3898      return;
3899    }
3900    iCount ++;
3901  }
3902  // early termination
3903  if (iCount == getSlice()->getMaxNumMergeCand()) 
3904  {
3905    return;
3906  }
3907
3908#if H_3D_IV_MERGE
3909  /////////////////////////////////////////////
3910  //////// INTER VIEW DISP COMP (IvDC) ////////
3911  /////////////////////////////////////////////
3912
3913  if( ivCandDir[1] )
3914  {
3915    assert(iCount < getSlice()->getMaxNumMergeCand());
3916    abCandIsInter        [ iCount ] = true;
3917    puhInterDirNeighbours[ iCount ] = ivCandDir[1];
3918    if( ( ivCandDir[1] & 1 ) == 1 )
3919    {
3920      pcMvFieldNeighbours[ iCount<<1    ].setMvField( ivCandMv[ 2 ], ivCandRefIdx[ 2 ] );
3921    }
3922    if( ( ivCandDir[1] & 2 ) == 2 )
3923    {
3924      pcMvFieldNeighbours[(iCount<<1)+1 ].setMvField( ivCandMv[ 3 ], ivCandRefIdx[ 3 ] );
3925    }
3926
3927    Bool bRemoveSpa = false; //pruning to A1, B1
3928    for(Int i = 0; i < 2; i ++)
3929    {
3930      Int iCnloop = iPosLeftAbove[i];
3931      if ( iCnloop == -1 ) 
3932      {
3933        continue;
3934      }
3935      if(puhInterDirNeighbours[iCount] == puhInterDirNeighbours[iCnloop] && pcMvFieldNeighbours[iCnloop<<1]==pcMvFieldNeighbours[(iCount<<1)] && pcMvFieldNeighbours[(iCnloop<<1)+1]==pcMvFieldNeighbours[(iCount<<1)+1])
3936      {
3937        bRemoveSpa                      = true;
3938        abCandIsInter        [ iCount ] = false;
3939        //reset to the default value for MC
3940        puhInterDirNeighbours[iCount]   = 0;
3941        pcMvFieldNeighbours[iCount<<1].setMvField( cZeroMv, NOT_VALID );
3942        pcMvFieldNeighbours[(iCount<<1)+1].setMvField( cZeroMv, NOT_VALID );
3943        break;
3944      }     
3945    }
3946    if(!bRemoveSpa)
3947    {
3948#if H_3D_NBDV
3949      pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3950      pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3951#endif
3952      posIvDC  = iCount;
3953      if ( mrgCandIdx == iCount )
3954        return;
3955      iCount ++;
3956
3957      // early termination
3958      if (iCount == getSlice()->getMaxNumMergeCand()) 
3959      {
3960        return;
3961      }
3962    }
3963  } 
3964#endif // H_3D_IV_MERGE
3965
3966#if H_3D_VSP
3967  /////////////////////////////////////////////////
3968  //////// VIEW SYNTHESIS PREDICTION (VSP) ////////
3969  /////////////////////////////////////////////////
3970
3971  if ( xAddVspCand( mrgCandIdx, &cDisInfo, iCount, abCandIsInter, pcMvFieldNeighbours, puhInterDirNeighbours, vspFlag ) )
3972  {
3973    return;
3974  }
3975
3976  // early termination
3977  if (iCount == getSlice()->getMaxNumMergeCand())
3978  {
3979    return;
3980  }
3981#endif
3982#if H_3D
3983  ///////////////////////////////////
3984  //////// LEFT BOTTOM (A0) ////////
3985  ///////////////////////////////////
3986#endif
3987
3988  //left bottom
3989  UInt uiLeftBottomPartIdx = 0;
3990  TComDataCU* pcCULeftBottom = 0;
3991  pcCULeftBottom = this->getPUBelowLeft( uiLeftBottomPartIdx, uiPartIdxLB );
3992  Bool isAvailableA0 = pcCULeftBottom &&
3993  pcCULeftBottom->isDiffMER(xP-1, yP+nPSH, xP, yP) &&
3994  !pcCULeftBottom->isIntra( uiLeftBottomPartIdx ) ;
3995  if ( isAvailableA0 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCULeftBottom, uiLeftBottomPartIdx ) ) )
3996  {
3997    abCandIsInter[iCount] = true;
3998    // get Inter Dir
3999    puhInterDirNeighbours[iCount] = pcCULeftBottom->getInterDir( uiLeftBottomPartIdx );
4000    // get Mv from Left
4001    pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
4002    if ( getSlice()->isInterB() )
4003    {
4004      pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
4005    }
4006#if H_3D_NBDV
4007    pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
4008    pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
4009#endif
4010#if H_3D_VSP
4011    if (pcCULeftBottom->getVSPFlag(uiLeftBottomPartIdx) == 1)
4012    {
4013      vspFlag[iCount] = 1;
4014      xInheritVSPDisInfo(pcCULeftBottom,uiLeftBottomPartIdx,iCount,inheritedVSPDisInfo);
4015    }
4016#endif
4017    if ( mrgCandIdx == iCount )
4018    {
4019      return;
4020    }
4021    iCount ++;
4022  }
4023  // early termination
4024  if (iCount == getSlice()->getMaxNumMergeCand()) 
4025  {
4026    return;
4027  }
4028#if H_3D
4029  ///////////////////////////////////
4030  //////// LEFT ABOVE (B2) ////////
4031  ///////////////////////////////////
4032#endif
4033
4034  // above left
4035  if( iCount < 4 )
4036  {
4037    UInt uiAboveLeftPartIdx = 0;
4038    TComDataCU* pcCUAboveLeft = 0;
4039    pcCUAboveLeft = getPUAboveLeft( uiAboveLeftPartIdx, uiAbsPartAddr );
4040    Bool isAvailableB2 = pcCUAboveLeft &&
4041    pcCUAboveLeft->isDiffMER(xP-1, yP-1, xP, yP) &&
4042    !pcCUAboveLeft->isIntra( uiAboveLeftPartIdx );
4043    if ( isAvailableB2 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) )
4044        && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) ) )
4045    {
4046      abCandIsInter[iCount] = true;
4047      // get Inter Dir
4048      puhInterDirNeighbours[iCount] = pcCUAboveLeft->getInterDir( uiAboveLeftPartIdx );
4049      // get Mv from Left
4050      pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
4051      if ( getSlice()->isInterB() )
4052      {
4053        pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
4054      }
4055#if H_3D_NBDV
4056      pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
4057      pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
4058#endif
4059#if H_3D_VSP
4060      if (pcCUAboveLeft->getVSPFlag(uiAboveLeftPartIdx) == 1)
4061      {
4062        vspFlag[iCount] = 1;
4063        xInheritVSPDisInfo(pcCUAboveLeft,uiAboveLeftPartIdx,iCount,inheritedVSPDisInfo);
4064      }
4065#endif
4066      if ( mrgCandIdx == iCount )
4067      {
4068        return;
4069      }
4070      iCount ++;
4071    }
4072  }
4073  // early termination
4074  if (iCount == getSlice()->getMaxNumMergeCand()) 
4075  {
4076    return;
4077  }
4078#if H_3D_IV_MERGE
4079  ////////////////////////////////////////////////////
4080  //////// SHIFTED IV (IvMCShift + IvDCShift) ////////
4081  ////////////////////////////////////////////////////
4082
4083  if(  ivMvPredFlag  ) 
4084  {
4085    if(xAddIvMRGCand( mrgCandIdx,  iCount, abCandIsInter, pcMvFieldNeighbours, puhInterDirNeighbours, ivCandDir, ivCandMv, ivCandRefIdx, posIvDC, vspFlag))
4086    {
4087      return;
4088    }
4089    //early termination
4090    if (iCount == getSlice()->getMaxNumMergeCand()) 
4091    {
4092      return;
4093    }
4094  }
4095#endif
4096#if H_3D
4097  /////////////////////////////////
4098  //////// Collocate (COL) ////////
4099  /////////////////////////////////
4100#endif
4101  if ( getSlice()->getEnableTMVPFlag())
4102  {
4103    //>> MTK colocated-RightBottom
4104    UInt uiPartIdxRB;
4105
4106    deriveRightBottomIdx( uiPUIdx, uiPartIdxRB ); 
4107
4108    UInt uiAbsPartIdxTmp = g_auiZscanToRaster[uiPartIdxRB];
4109    UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
4110
4111    TComMv cColMv;
4112    Int iRefIdx;
4113    Int uiLCUIdx = -1;
4114
4115    if      ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
4116    {
4117    }
4118    else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxTmp] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
4119    {
4120    }
4121    else
4122    {
4123      if ( ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
4124        ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
4125      {
4126        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + uiNumPartInCUWidth + 1 ];
4127        uiLCUIdx = getAddr();
4128      }
4129      else if ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
4130      {
4131        uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdxTmp + uiNumPartInCUWidth + 1) % m_pcPic->getNumPartInCU() ];
4132      }
4133      else if ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
4134      {
4135        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + 1 ];
4136        uiLCUIdx = getAddr() + 1;
4137      }
4138      else //is the right bottom corner of LCU                       
4139      {
4140        uiAbsPartAddr = 0;
4141      }
4142    }
4143   
4144   
4145    iRefIdx = 0;
4146    Bool bExistMV = false;
4147    UInt uiPartIdxCenter;
4148    UInt uiCurLCUIdx = getAddr();
4149    Int dir = 0;
4150    UInt uiArrayAddr = iCount;
4151    xDeriveCenterIdx( uiPUIdx, uiPartIdxCenter );
4152    bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_0, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx );
4153    if( bExistMV == false )
4154    {
4155      bExistMV = xGetColMVP( REF_PIC_LIST_0, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
4156    }
4157    if( bExistMV )
4158    {
4159      dir |= 1;
4160      pcMvFieldNeighbours[ 2 * uiArrayAddr ].setMvField( cColMv, iRefIdx );
4161    }
4162
4163    if ( getSlice()->isInterB() )
4164    {
4165#if H_3D_TMVP
4166      iRefIdx = 0;
4167#endif
4168      bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_1, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx);
4169      if( bExistMV == false )
4170      {
4171        bExistMV = xGetColMVP( REF_PIC_LIST_1, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
4172      }
4173      if( bExistMV )
4174      {
4175        dir |= 2;
4176        pcMvFieldNeighbours[ 2 * uiArrayAddr + 1 ].setMvField( cColMv, iRefIdx );
4177      }
4178    }
4179   
4180    if (dir != 0)
4181    {
4182      puhInterDirNeighbours[uiArrayAddr] = dir;
4183      abCandIsInter[uiArrayAddr] = true;
4184#if H_3D_NBDV
4185      pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
4186      pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
4187#endif
4188      if ( mrgCandIdx == iCount )
4189      {
4190        return;
4191      }
4192      iCount++;
4193    }
4194  }
4195  // early termination
4196  if (iCount == getSlice()->getMaxNumMergeCand()) 
4197  {
4198    return;
4199  }
4200  UInt uiArrayAddr = iCount;
4201  UInt uiCutoff = uiArrayAddr;
4202   
4203  if ( getSlice()->isInterB())
4204  {
4205#if H_3D_IV_MERGE
4206    UInt uiPriorityList0[20] = {0 , 1, 0, 2, 1, 2, 0, 3, 1, 3, 2, 3,    0, 4, 1, 4, 2, 4, 3, 4 };
4207    UInt uiPriorityList1[20] = {1 , 0, 2, 0, 2, 1, 3, 0, 3, 1, 3, 2,    4, 0, 4, 1, 4, 2, 4, 3 };
4208#else
4209    UInt uiPriorityList0[12] = {0 , 1, 0, 2, 1, 2, 0, 3, 1, 3, 2, 3};
4210    UInt uiPriorityList1[12] = {1 , 0, 2, 0, 2, 1, 3, 0, 3, 1, 3, 2};
4211#endif
4212
4213    for (Int idx=0; idx<uiCutoff*(uiCutoff-1) && uiArrayAddr!= getSlice()->getMaxNumMergeCand(); idx++)
4214    {
4215      Int i = uiPriorityList0[idx]; Int j = uiPriorityList1[idx];
4216#if H_3D_VSP
4217      Bool bValid = true;
4218      if ( vspFlag[i] == 1 || vspFlag[j] == 1 )
4219      {
4220        bValid = false;
4221      }
4222      if( !m_pcSlice->getVPS()->getViewSynthesisPredFlag( m_pcSlice->getLayerIdInVps() ) )
4223      {
4224        assert(bValid == true);
4225      }
4226#endif
4227#if H_3D_VSP
4228      if (abCandIsInter[i] && abCandIsInter[j] && (puhInterDirNeighbours[i]&0x1) && (puhInterDirNeighbours[j]&0x2) && bValid)
4229#else
4230      if (abCandIsInter[i] && abCandIsInter[j]&& (puhInterDirNeighbours[i]&0x1)&&(puhInterDirNeighbours[j]&0x2))
4231#endif
4232      {
4233        abCandIsInter[uiArrayAddr] = true;
4234        puhInterDirNeighbours[uiArrayAddr] = 3;
4235
4236        // get Mv from cand[i] and cand[j]
4237        pcMvFieldNeighbours[uiArrayAddr << 1].setMvField(pcMvFieldNeighbours[i<<1].getMv(), pcMvFieldNeighbours[i<<1].getRefIdx());
4238        pcMvFieldNeighbours[( uiArrayAddr << 1 ) + 1].setMvField(pcMvFieldNeighbours[(j<<1)+1].getMv(), pcMvFieldNeighbours[(j<<1)+1].getRefIdx());
4239
4240        Int iRefPOCL0 = m_pcSlice->getRefPOC( REF_PIC_LIST_0, pcMvFieldNeighbours[(uiArrayAddr<<1)].getRefIdx() );
4241        Int iRefPOCL1 = m_pcSlice->getRefPOC( REF_PIC_LIST_1, pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getRefIdx() );
4242        if (iRefPOCL0 == iRefPOCL1 && pcMvFieldNeighbours[(uiArrayAddr<<1)].getMv() == pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getMv())
4243        {
4244          abCandIsInter[uiArrayAddr] = false;
4245        }
4246        else
4247        {
4248          uiArrayAddr++;
4249        }
4250      }
4251    }
4252  }
4253  // early termination
4254  if (uiArrayAddr == getSlice()->getMaxNumMergeCand()) 
4255  {
4256    return;
4257  }
4258  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);
4259  Int r = 0;
4260  Int refcnt = 0;
4261  while (uiArrayAddr < getSlice()->getMaxNumMergeCand())
4262  {
4263    abCandIsInter[uiArrayAddr] = true;
4264    puhInterDirNeighbours[uiArrayAddr] = 1;
4265    pcMvFieldNeighbours[uiArrayAddr << 1].setMvField( TComMv(0, 0), r);
4266
4267    if ( getSlice()->isInterB() )
4268    {
4269      puhInterDirNeighbours[uiArrayAddr] = 3;
4270      pcMvFieldNeighbours[(uiArrayAddr << 1) + 1].setMvField(TComMv(0, 0), r);
4271    }
4272    uiArrayAddr++;
4273    if ( refcnt == iNumRefIdx - 1 )
4274    {
4275      r = 0;
4276    }
4277    else
4278    {
4279      ++r;
4280      ++refcnt;
4281    }
4282  }
4283
4284  numValidMergeCand = uiArrayAddr;
4285}
4286#if H_3D_VSP
4287inline Void TComDataCU::xInheritVSPDisInfo(TComDataCU* pcCURef, UInt uiAbsPartIdx, Int iCount, InheritedVSPDisInfo*  inheritedVSPDisInfo)
4288{
4289  inheritedVSPDisInfo[iCount].m_acDvInfo.m_acNBDV   = pcCURef->getDvInfo(uiAbsPartIdx).m_acNBDV;
4290  inheritedVSPDisInfo[iCount].m_acDvInfo.m_aVIdxCan = pcCURef->getDvInfo(uiAbsPartIdx).m_aVIdxCan;
4291}
4292#endif
4293/** Check whether the current PU and a spatial neighboring PU are in a same ME region.
4294 * \param xN, xN   location of the upper-left corner pixel of a neighboring PU
4295 * \param xP, yP   location of the upper-left corner pixel of the current PU
4296 * \returns Bool
4297 */
4298Bool TComDataCU::isDiffMER(Int xN, Int yN, Int xP, Int yP)
4299{
4300
4301  UInt plevel = this->getSlice()->getPPS()->getLog2ParallelMergeLevelMinus2() + 2;
4302  if ((xN>>plevel)!= (xP>>plevel))
4303  {
4304    return true;
4305  }
4306  if ((yN>>plevel)!= (yP>>plevel))
4307  {
4308    return true;
4309  }
4310  return false;
4311}
4312/** calculate the location of upper-left corner pixel and size of the current PU.
4313 * \param partIdx  PU index within a CU
4314 * \param xP, yP   location of the upper-left corner pixel of the current PU
4315 * \param PSW, nPSH    size of the curren PU
4316 * \returns Void
4317 */
4318Void TComDataCU::getPartPosition( UInt partIdx, Int& xP, Int& yP, Int& nPSW, Int& nPSH)
4319{
4320  UInt col = m_uiCUPelX;
4321  UInt row = m_uiCUPelY;
4322
4323  switch ( m_pePartSize[0] )
4324  {
4325  case SIZE_2NxN:
4326    nPSW = getWidth(0);     
4327    nPSH = getHeight(0) >> 1; 
4328    xP   = col;
4329    yP   = (partIdx ==0)? row: row + nPSH;
4330    break;
4331  case SIZE_Nx2N:
4332    nPSW = getWidth(0) >> 1; 
4333    nPSH = getHeight(0);     
4334    xP   = (partIdx ==0)? col: col + nPSW;
4335    yP   = row;
4336    break;
4337  case SIZE_NxN:
4338    nPSW = getWidth(0) >> 1; 
4339    nPSH = getHeight(0) >> 1; 
4340    xP   = col + (partIdx&0x1)*nPSW;
4341    yP   = row + (partIdx>>1)*nPSH;
4342    break;
4343  case SIZE_2NxnU:
4344    nPSW = getWidth(0);
4345    nPSH = ( partIdx == 0 ) ?  getHeight(0) >> 2 : ( getHeight(0) >> 2 ) + ( getHeight(0) >> 1 );
4346    xP   = col;
4347    yP   = (partIdx ==0)? row: row + getHeight(0) - nPSH;
4348
4349    break;
4350  case SIZE_2NxnD:
4351    nPSW = getWidth(0);
4352    nPSH = ( partIdx == 0 ) ?  ( getHeight(0) >> 2 ) + ( getHeight(0) >> 1 ) : getHeight(0) >> 2;
4353    xP   = col;
4354    yP   = (partIdx ==0)? row: row + getHeight(0) - nPSH;
4355    break;
4356  case SIZE_nLx2N:
4357    nPSW = ( partIdx == 0 ) ? getWidth(0) >> 2 : ( getWidth(0) >> 2 ) + ( getWidth(0) >> 1 );
4358    nPSH = getHeight(0);
4359    xP   = (partIdx ==0)? col: col + getWidth(0) - nPSW;
4360    yP   = row;
4361    break;
4362  case SIZE_nRx2N:
4363    nPSW = ( partIdx == 0 ) ? ( getWidth(0) >> 2 ) + ( getWidth(0) >> 1 ) : getWidth(0) >> 2;
4364    nPSH = getHeight(0);
4365    xP   = (partIdx ==0)? col: col + getWidth(0) - nPSW;
4366    yP   = row;
4367    break;
4368  default:
4369    assert ( m_pePartSize[0] == SIZE_2Nx2N );
4370    nPSW = getWidth(0);     
4371    nPSH = getHeight(0);     
4372    xP   = col ;
4373    yP   = row ;
4374
4375    break;
4376  }
4377}
4378
4379/** Constructs a list of candidates for AMVP
4380 * \param uiPartIdx
4381 * \param uiPartAddr
4382 * \param eRefPicList
4383 * \param iRefIdx
4384 * \param pInfo
4385 */
4386Void TComDataCU::fillMvpCand ( UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, Int iRefIdx, AMVPInfo* pInfo )
4387{
4388  TComMv cMvPred;
4389  Bool bAddedSmvp = false;
4390
4391  pInfo->iN = 0; 
4392  if (iRefIdx < 0)
4393  {
4394    return;
4395  }
4396 
4397  //-- Get Spatial MV
4398  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB;
4399  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
4400  Bool bAdded = false;
4401 
4402  deriveLeftRightTopIdx( uiPartIdx, uiPartIdxLT, uiPartIdxRT );
4403  deriveLeftBottomIdx( uiPartIdx, uiPartIdxLB );
4404 
4405  TComDataCU* tmpCU = NULL;
4406  UInt idx;
4407  tmpCU = getPUBelowLeft(idx, uiPartIdxLB);
4408  bAddedSmvp = (tmpCU != NULL) && (tmpCU->getPredictionMode(idx) != MODE_INTRA);
4409
4410  if (!bAddedSmvp)
4411  {
4412    tmpCU = getPULeft(idx, uiPartIdxLB);
4413    bAddedSmvp = (tmpCU != NULL) && (tmpCU->getPredictionMode(idx) != MODE_INTRA);
4414  }
4415
4416  // Left predictor search
4417  bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_BELOW_LEFT);
4418  if (!bAdded) 
4419  {
4420    bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_LEFT );
4421  }
4422 
4423  if(!bAdded)
4424  {
4425    bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_BELOW_LEFT);
4426    if (!bAdded) 
4427    {
4428      xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_LEFT );
4429    }
4430  }
4431  // Above predictor search
4432  bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE_RIGHT);
4433
4434  if (!bAdded) 
4435  {
4436    bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE);
4437  }
4438
4439  if(!bAdded)
4440  {
4441    xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLT, MD_ABOVE_LEFT);
4442  }
4443  bAdded = bAddedSmvp;
4444  if (pInfo->iN==2) bAdded = true;
4445
4446  if(!bAdded)
4447  {
4448    bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE_RIGHT);
4449    if (!bAdded) 
4450    {
4451      bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE);
4452    }
4453
4454    if(!bAdded)
4455    {
4456      xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLT, MD_ABOVE_LEFT);
4457    }
4458  }
4459 
4460  if ( pInfo->iN == 2 )
4461  {
4462    if ( pInfo->m_acMvCand[ 0 ] == pInfo->m_acMvCand[ 1 ] )
4463    {
4464      pInfo->iN = 1;
4465    }
4466  }
4467
4468  if ( getSlice()->getEnableTMVPFlag() )
4469  {
4470    // Get Temporal Motion Predictor
4471    Int iRefIdx_Col = iRefIdx;
4472    TComMv cColMv;
4473    UInt uiPartIdxRB;
4474    UInt uiAbsPartIdx; 
4475    UInt uiAbsPartAddr;
4476
4477    deriveRightBottomIdx( uiPartIdx, uiPartIdxRB );
4478    uiAbsPartAddr = m_uiAbsIdxInLCU + uiPartAddr;
4479
4480    //----  co-located RightBottom Temporal Predictor (H) ---//
4481    uiAbsPartIdx = g_auiZscanToRaster[uiPartIdxRB];
4482    Int uiLCUIdx = -1;
4483    if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdx] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
4484    {
4485    }
4486    else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdx] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
4487    {
4488    }
4489    else
4490    {
4491      if ( ( uiAbsPartIdx % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
4492        ( uiAbsPartIdx / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
4493      {
4494        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdx + uiNumPartInCUWidth + 1 ];
4495        uiLCUIdx = getAddr();
4496      }
4497      else if ( uiAbsPartIdx % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
4498      {
4499        uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdx + uiNumPartInCUWidth + 1) % m_pcPic->getNumPartInCU() ];
4500      }
4501      else if ( uiAbsPartIdx / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
4502      {
4503        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdx + 1 ];
4504        uiLCUIdx = getAddr() + 1;
4505      }
4506      else //is the right bottom corner of LCU                       
4507      {
4508        uiAbsPartAddr = 0;
4509      }
4510    }
4511    if ( uiLCUIdx >= 0 && xGetColMVP( eRefPicList, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx_Col
4512#if H_3D_TMVP
4513         , 0
4514#endif
4515    ) )
4516    {
4517      pInfo->m_acMvCand[pInfo->iN++] = cColMv;
4518    }
4519    else 
4520    {
4521      UInt uiPartIdxCenter;
4522      UInt uiCurLCUIdx = getAddr();
4523      xDeriveCenterIdx( uiPartIdx, uiPartIdxCenter );
4524      if (xGetColMVP( eRefPicList, uiCurLCUIdx, uiPartIdxCenter,  cColMv, iRefIdx_Col
4525#if H_3D_TMVP
4526         , 0
4527#endif
4528      ))
4529      {
4530        pInfo->m_acMvCand[pInfo->iN++] = cColMv;
4531      }
4532    }
4533    //----  co-located RightBottom Temporal Predictor  ---//
4534  }
4535
4536  if (pInfo->iN > AMVP_MAX_NUM_CANDS)
4537  {
4538    pInfo->iN = AMVP_MAX_NUM_CANDS;
4539  }
4540  while (pInfo->iN < AMVP_MAX_NUM_CANDS)
4541  {
4542      pInfo->m_acMvCand[pInfo->iN].set(0,0);
4543      pInfo->iN++;
4544  }
4545  return ;
4546}
4547
4548Bool TComDataCU::isBipredRestriction(UInt puIdx)
4549{
4550  Int width = 0;
4551  Int height = 0;
4552  UInt partAddr;
4553
4554  getPartIndexAndSize( puIdx, partAddr, width, height );
4555  if ( getWidth(0) == 8 && (width < 8 || height < 8) )
4556  {
4557    return true;
4558  }
4559  return false;
4560}
4561
4562Void TComDataCU::clipMv    (TComMv&  rcMv)
4563{
4564  Int  iMvShift = 2;
4565#if H_3D_IC
4566  if( getSlice()->getIsDepth() )
4567    iMvShift = 0;
4568#endif
4569  Int iOffset = 8;
4570  Int iHorMax = ( m_pcSlice->getSPS()->getPicWidthInLumaSamples() + iOffset - m_uiCUPelX - 1 ) << iMvShift;
4571  Int iHorMin = (       -(Int)g_uiMaxCUWidth - iOffset - (Int)m_uiCUPelX + 1 ) << iMvShift;
4572 
4573  Int iVerMax = ( m_pcSlice->getSPS()->getPicHeightInLumaSamples() + iOffset - m_uiCUPelY - 1 ) << iMvShift;
4574  Int iVerMin = (       -(Int)g_uiMaxCUHeight - iOffset - (Int)m_uiCUPelY + 1 ) << iMvShift;
4575 
4576  rcMv.setHor( min (iHorMax, max (iHorMin, rcMv.getHor())) );
4577  rcMv.setVer( min (iVerMax, max (iVerMin, rcMv.getVer())) );
4578}
4579
4580UInt TComDataCU::getIntraSizeIdx(UInt uiAbsPartIdx)
4581{
4582  UInt uiShift = ( m_pePartSize[uiAbsPartIdx]==SIZE_NxN ? 1 : 0 );
4583 
4584  UChar uiWidth = m_puhWidth[uiAbsPartIdx]>>uiShift;
4585  UInt  uiCnt = 0;
4586  while( uiWidth )
4587  {
4588    uiCnt++;
4589    uiWidth>>=1;
4590  }
4591  uiCnt-=2;
4592  return uiCnt > 6 ? 6 : uiCnt;
4593}
4594
4595Void TComDataCU::clearCbf( UInt uiIdx, TextType eType, UInt uiNumParts )
4596{
4597  ::memset( &m_puhCbf[g_aucConvertTxtTypeToIdx[eType]][uiIdx], 0, sizeof(UChar)*uiNumParts);
4598}
4599
4600/** Set a I_PCM flag for all sub-partitions of a partition.
4601 * \param bIpcmFlag I_PCM flag
4602 * \param uiAbsPartIdx patition index
4603 * \param uiDepth CU depth
4604 * \returns Void
4605 */
4606Void TComDataCU::setIPCMFlagSubParts  (Bool bIpcmFlag, UInt uiAbsPartIdx, UInt uiDepth)
4607{
4608  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
4609
4610  memset(m_pbIPCMFlag + uiAbsPartIdx, bIpcmFlag, sizeof(Bool)*uiCurrPartNumb );
4611}
4612
4613/** Test whether the current block is skipped
4614 * \param uiPartIdx Block index
4615 * \returns Flag indicating whether the block is skipped
4616 */
4617Bool TComDataCU::isSkipped( UInt uiPartIdx )
4618{
4619  return ( getSkipFlag( uiPartIdx ) );
4620}
4621
4622// ====================================================================================================================
4623// Protected member functions
4624// ====================================================================================================================
4625
4626Bool TComDataCU::xAddMVPCand( AMVPInfo* pInfo, RefPicList eRefPicList, Int iRefIdx, UInt uiPartUnitIdx, MVP_DIR eDir )
4627{
4628  TComDataCU* pcTmpCU = NULL;
4629  UInt uiIdx;
4630  switch( eDir )
4631  {
4632    case MD_LEFT:
4633    {
4634      pcTmpCU = getPULeft(uiIdx, uiPartUnitIdx);
4635      break;
4636    }
4637    case MD_ABOVE:
4638    {
4639      pcTmpCU = getPUAbove(uiIdx, uiPartUnitIdx );
4640      break;
4641    }
4642    case MD_ABOVE_RIGHT:
4643    {
4644      pcTmpCU = getPUAboveRight(uiIdx, uiPartUnitIdx);
4645      break;
4646    }
4647    case MD_BELOW_LEFT:
4648    {
4649      pcTmpCU = getPUBelowLeft(uiIdx, uiPartUnitIdx);
4650      break;
4651    }
4652    case MD_ABOVE_LEFT:
4653    {
4654      pcTmpCU = getPUAboveLeft(uiIdx, uiPartUnitIdx);
4655      break;
4656    }
4657    default:
4658    {
4659      break;
4660    }
4661  }
4662
4663  if ( pcTmpCU == NULL )
4664  {
4665    return false;
4666  }
4667 
4668  if ( pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) >= 0 && m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getPOC() == pcTmpCU->getSlice()->getRefPOC( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) ))
4669  {
4670    TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
4671   
4672    pInfo->m_acMvCand[ pInfo->iN++] = cMvPred;
4673    return true;
4674  }
4675
4676  RefPicList eRefPicList2nd = REF_PIC_LIST_0;
4677  if(       eRefPicList == REF_PIC_LIST_0 )
4678  {
4679    eRefPicList2nd = REF_PIC_LIST_1;
4680  }
4681  else if ( eRefPicList == REF_PIC_LIST_1)
4682  {
4683    eRefPicList2nd = REF_PIC_LIST_0;
4684  }
4685
4686
4687  Int iCurrRefPOC = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getPOC();
4688  Int iNeibRefPOC;
4689
4690
4691  if( pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) >= 0 )
4692  {
4693    iNeibRefPOC = pcTmpCU->getSlice()->getRefPOC( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) );
4694    if( iNeibRefPOC == iCurrRefPOC ) // Same Reference Frame But Diff List//
4695    {
4696      TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList2nd)->getMv(uiIdx);
4697      pInfo->m_acMvCand[ pInfo->iN++] = cMvPred;
4698      return true;
4699    }
4700  }
4701  return false;
4702}
4703
4704/**
4705 * \param pInfo
4706 * \param eRefPicList
4707 * \param iRefIdx
4708 * \param uiPartUnitIdx
4709 * \param eDir
4710 * \returns Bool
4711 */
4712Bool TComDataCU::xAddMVPCandOrder( AMVPInfo* pInfo, RefPicList eRefPicList, Int iRefIdx, UInt uiPartUnitIdx, MVP_DIR eDir )
4713{
4714  TComDataCU* pcTmpCU = NULL;
4715  UInt uiIdx;
4716  switch( eDir )
4717  {
4718  case MD_LEFT:
4719    {
4720      pcTmpCU = getPULeft(uiIdx, uiPartUnitIdx);
4721      break;
4722    }
4723  case MD_ABOVE:
4724    {
4725      pcTmpCU = getPUAbove(uiIdx, uiPartUnitIdx);
4726      break;
4727    }
4728  case MD_ABOVE_RIGHT:
4729    {
4730      pcTmpCU = getPUAboveRight(uiIdx, uiPartUnitIdx);
4731      break;
4732    }
4733  case MD_BELOW_LEFT:
4734    {
4735      pcTmpCU = getPUBelowLeft(uiIdx, uiPartUnitIdx);
4736      break;
4737    }
4738  case MD_ABOVE_LEFT:
4739    {
4740      pcTmpCU = getPUAboveLeft(uiIdx, uiPartUnitIdx);
4741      break;
4742    }
4743  default:
4744    {
4745      break;
4746    }
4747  }
4748
4749  if ( pcTmpCU == NULL ) 
4750  {
4751    return false;
4752  }
4753 
4754  RefPicList eRefPicList2nd = REF_PIC_LIST_0;
4755  if(       eRefPicList == REF_PIC_LIST_0 )
4756  {
4757    eRefPicList2nd = REF_PIC_LIST_1;
4758  }
4759  else if ( eRefPicList == REF_PIC_LIST_1)
4760  {
4761    eRefPicList2nd = REF_PIC_LIST_0;
4762  }
4763
4764  Int iCurrPOC = m_pcSlice->getPOC();
4765  Int iCurrRefPOC = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getPOC();
4766  Int iNeibPOC = iCurrPOC;
4767  Int iNeibRefPOC;
4768
4769  Bool bIsCurrRefLongTerm = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getIsLongTerm();
4770  Bool bIsNeibRefLongTerm = false;
4771  //---------------  V1 (END) ------------------//
4772  if( pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) >= 0)
4773  {
4774    iNeibRefPOC = pcTmpCU->getSlice()->getRefPOC( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) );
4775    TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
4776    TComMv rcMv;
4777
4778    bIsNeibRefLongTerm = pcTmpCU->getSlice()->getRefPic( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) )->getIsLongTerm();
4779    if ( bIsCurrRefLongTerm == bIsNeibRefLongTerm ) 
4780    {
4781    if ( bIsCurrRefLongTerm || bIsNeibRefLongTerm )
4782    {
4783      rcMv = cMvPred;
4784    }
4785    else
4786    {
4787      Int iScale = xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
4788      if ( iScale == 4096 )
4789      {
4790        rcMv = cMvPred;
4791      }
4792      else
4793      {
4794        rcMv = cMvPred.scaleMv( iScale );
4795      }
4796    }
4797    pInfo->m_acMvCand[ pInfo->iN++] = rcMv;
4798    return true;
4799    }
4800  }
4801  //---------------------- V2(END) --------------------//
4802  if( pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) >= 0)
4803  {
4804    iNeibRefPOC = pcTmpCU->getSlice()->getRefPOC( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) );
4805    TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList2nd)->getMv(uiIdx);
4806    TComMv rcMv;
4807
4808    bIsNeibRefLongTerm = pcTmpCU->getSlice()->getRefPic( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) )->getIsLongTerm();
4809    if ( bIsCurrRefLongTerm == bIsNeibRefLongTerm ) 
4810    {
4811    if ( bIsCurrRefLongTerm || bIsNeibRefLongTerm )
4812    {
4813      rcMv = cMvPred;
4814    }
4815    else
4816    {
4817      Int iScale = xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
4818      if ( iScale == 4096 )
4819      {
4820        rcMv = cMvPred;
4821      }
4822      else
4823      {
4824        rcMv = cMvPred.scaleMv( iScale );
4825      }
4826    }
4827    pInfo->m_acMvCand[ pInfo->iN++] = rcMv;
4828    return true;
4829    }
4830  }
4831  //---------------------- V3(END) --------------------//
4832  return false;
4833}
4834
4835/**
4836 * \param eRefPicList
4837 * \param uiCUAddr
4838 * \param uiPartUnitIdx
4839 * \param riRefIdx
4840 * \returns Bool
4841 */
4842Bool TComDataCU::xGetColMVP( RefPicList eRefPicList, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv, Int& riRefIdx
4843#if H_3D_TMVP
4844  , Bool bMRG
4845#endif
4846  )
4847{
4848  UInt uiAbsPartAddr = uiPartUnitIdx;
4849
4850  RefPicList  eColRefPicList;
4851  Int iColPOC, iColRefPOC, iCurrPOC, iCurrRefPOC, iScale;
4852  TComMv cColMv;
4853
4854  // use coldir.
4855  TComPic *pColPic = getSlice()->getRefPic( RefPicList(getSlice()->isInterB() ? 1-getSlice()->getColFromL0Flag() : 0), getSlice()->getColRefIdx());
4856  TComDataCU *pColCU = pColPic->getCU( uiCUAddr );
4857  if(pColCU->getPic()==0||pColCU->getPartitionSize(uiPartUnitIdx)==SIZE_NONE)
4858  {
4859    return false;
4860  }
4861  iCurrPOC = m_pcSlice->getPOC();   
4862  iColPOC = pColCU->getSlice()->getPOC(); 
4863
4864  if (pColCU->isIntra(uiAbsPartAddr))
4865  {
4866    return false;
4867  }
4868  eColRefPicList = getSlice()->getCheckLDC() ? eRefPicList : RefPicList(getSlice()->getColFromL0Flag());
4869
4870  Int iColRefIdx = pColCU->getCUMvField(RefPicList(eColRefPicList))->getRefIdx(uiAbsPartAddr);
4871
4872  if (iColRefIdx < 0 )
4873  {
4874    eColRefPicList = RefPicList(1 - eColRefPicList);
4875    iColRefIdx = pColCU->getCUMvField(RefPicList(eColRefPicList))->getRefIdx(uiAbsPartAddr);
4876
4877    if (iColRefIdx < 0 )
4878    {
4879      return false;
4880    }
4881  }
4882
4883  // Scale the vector.
4884  iColRefPOC = pColCU->getSlice()->getRefPOC(eColRefPicList, iColRefIdx);
4885  cColMv = pColCU->getCUMvField(eColRefPicList)->getMv(uiAbsPartAddr);
4886
4887  iCurrRefPOC = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getPOC();
4888  Bool bIsCurrRefLongTerm = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getIsLongTerm();
4889  Bool bIsColRefLongTerm = pColCU->getSlice()->getIsUsedAsLongTerm(eColRefPicList, iColRefIdx);
4890
4891  if ( bIsCurrRefLongTerm != bIsColRefLongTerm ) 
4892  {
4893#if H_3D_TMVP
4894    Int iAlterRefIdx  = m_pcSlice->getAlterRefIdx(eRefPicList);
4895    if(bMRG && iAlterRefIdx > 0)
4896    {
4897      riRefIdx = iAlterRefIdx;
4898      bIsCurrRefLongTerm = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getIsLongTerm();
4899      iCurrRefPOC = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getPOC();
4900      assert(bIsCurrRefLongTerm == bIsColRefLongTerm);
4901    }
4902    else
4903    {
4904#endif
4905      return false;
4906#if H_3D_TMVP
4907    }
4908#endif
4909  }
4910
4911  if ( bIsCurrRefLongTerm || bIsColRefLongTerm )
4912  {
4913#if H_3D_TMVP
4914    Int iCurrViewId    = m_pcSlice->getViewIndex (); 
4915    Int iCurrRefViewId = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getViewIndex (); 
4916    Int iColViewId     = pColCU->getSlice()->getViewIndex(); 
4917    Int iColRefViewId  = pColCU->getSlice()->getRefPic( eColRefPicList, pColCU->getCUMvField(eColRefPicList)->getRefIdx(uiAbsPartAddr))->getViewIndex(); 
4918    iScale = xGetDistScaleFactor( iCurrViewId, iCurrRefViewId, iColViewId, iColRefViewId );
4919    if ( iScale != 4096 && m_pcSlice->getVPS()->getIvMvScalingFlag() ) 
4920    {
4921      rcMv = cColMv.scaleMv( iScale );
4922    }
4923    else
4924    {
4925#endif
4926       rcMv = cColMv;
4927#if H_3D_TMVP
4928    }
4929#endif
4930  }
4931  else
4932  {
4933    iScale = xGetDistScaleFactor(iCurrPOC, iCurrRefPOC, iColPOC, iColRefPOC);
4934    if ( iScale == 4096 )
4935    {
4936      rcMv = cColMv;
4937    }
4938    else
4939    {
4940      rcMv = cColMv.scaleMv( iScale );
4941    }
4942  }
4943  return true;
4944}
4945
4946UInt TComDataCU::xGetMvdBits(TComMv cMvd)
4947{
4948  return ( xGetComponentBits(cMvd.getHor()) + xGetComponentBits(cMvd.getVer()) );
4949}
4950
4951UInt TComDataCU::xGetComponentBits(Int iVal)
4952{
4953  UInt uiLength = 1;
4954  UInt uiTemp   = ( iVal <= 0) ? (-iVal<<1)+1: (iVal<<1);
4955 
4956  assert ( uiTemp );
4957 
4958  while ( 1 != uiTemp )
4959  {
4960    uiTemp >>= 1;
4961    uiLength += 2;
4962  }
4963 
4964  return uiLength;
4965}
4966
4967
4968Int TComDataCU::xGetDistScaleFactor(Int iCurrPOC, Int iCurrRefPOC, Int iColPOC, Int iColRefPOC)
4969{
4970  Int iDiffPocD = iColPOC - iColRefPOC;
4971  Int iDiffPocB = iCurrPOC - iCurrRefPOC;
4972 
4973  if( iDiffPocD == iDiffPocB )
4974  {
4975    return 4096;
4976  }
4977  else
4978  {
4979    Int iTDB      = Clip3( -128, 127, iDiffPocB );
4980    Int iTDD      = Clip3( -128, 127, iDiffPocD );
4981    Int iX        = (0x4000 + abs(iTDD/2)) / iTDD;
4982    Int iScale    = Clip3( -4096, 4095, (iTDB * iX + 32) >> 6 );
4983    return iScale;
4984  }
4985}
4986
4987/**
4988 * \param eCUMode
4989 * \param uiPartIdx
4990 * \param ruiPartIdxCenter
4991 * \returns Void
4992 */
4993Void TComDataCU::xDeriveCenterIdx( UInt uiPartIdx, UInt& ruiPartIdxCenter )
4994{
4995  UInt uiPartAddr;
4996  Int  iPartWidth;
4997  Int  iPartHeight;
4998  getPartIndexAndSize( uiPartIdx, uiPartAddr, iPartWidth, iPartHeight);
4999 
5000  ruiPartIdxCenter = m_uiAbsIdxInLCU+uiPartAddr; // partition origin.
5001  ruiPartIdxCenter = g_auiRasterToZscan[ g_auiZscanToRaster[ ruiPartIdxCenter ]
5002                                        + ( iPartHeight/m_pcPic->getMinCUHeight()  )/2*m_pcPic->getNumPartInWidth()
5003                                        + ( iPartWidth/m_pcPic->getMinCUWidth()  )/2];
5004}
5005#if H_3D
5006Void TComDataCU::compressMV(Int scale)
5007#else
5008Void TComDataCU::compressMV()
5009#endif
5010{
5011#if H_3D
5012  Int scaleFactor = (4 / scale ) * AMVP_DECIMATION_FACTOR / m_unitSize;
5013#else
5014  Int scaleFactor = 4 * AMVP_DECIMATION_FACTOR / m_unitSize;
5015#endif
5016  if (scaleFactor > 0)
5017  {
5018    m_acCUMvField[0].compress(m_pePredMode, scaleFactor);
5019    m_acCUMvField[1].compress(m_pePredMode, scaleFactor);   
5020  }
5021}
5022
5023UInt TComDataCU::getCoefScanIdx(UInt uiAbsPartIdx, UInt uiWidth, Bool bIsLuma, Bool bIsIntra)
5024{
5025  UInt uiCTXIdx;
5026  UInt uiScanIdx;
5027  UInt uiDirMode;
5028
5029  if ( !bIsIntra ) 
5030  {
5031    uiScanIdx = SCAN_DIAG;
5032    return uiScanIdx;
5033  }
5034
5035  switch(uiWidth)
5036  {
5037    case  2: uiCTXIdx = 6; break;
5038    case  4: uiCTXIdx = 5; break;
5039    case  8: uiCTXIdx = 4; break;
5040    case 16: uiCTXIdx = 3; break;
5041    case 32: uiCTXIdx = 2; break;
5042    case 64: uiCTXIdx = 1; break;
5043    default: uiCTXIdx = 0; break;
5044  }
5045
5046  if ( bIsLuma )
5047  {
5048    uiDirMode = getLumaIntraDir(uiAbsPartIdx);
5049#if H_3D_DIM
5050    mapDepthModeToIntraDir( uiDirMode );
5051#endif
5052    uiScanIdx = SCAN_DIAG;
5053    if (uiCTXIdx >3 && uiCTXIdx < 6) //if multiple scans supported for transform size
5054    {
5055      uiScanIdx = abs((Int) uiDirMode - VER_IDX) < 5 ? SCAN_HOR : (abs((Int)uiDirMode - HOR_IDX) < 5 ? SCAN_VER : SCAN_DIAG);
5056    }
5057  }
5058  else
5059  {
5060    uiDirMode = getChromaIntraDir(uiAbsPartIdx);
5061    if( uiDirMode == DM_CHROMA_IDX )
5062    {
5063      // get number of partitions in current CU
5064      UInt depth = getDepth(uiAbsPartIdx);
5065      UInt numParts = getPic()->getNumPartInCU() >> (2 * depth);
5066     
5067      // get luma mode from upper-left corner of current CU
5068      uiDirMode = getLumaIntraDir((uiAbsPartIdx/numParts)*numParts);
5069#if H_3D_DIM
5070      mapDepthModeToIntraDir( uiDirMode );
5071#endif
5072    }
5073    uiScanIdx = SCAN_DIAG;
5074    if (uiCTXIdx >4 && uiCTXIdx < 7) //if multiple scans supported for transform size
5075    {
5076      uiScanIdx = abs((Int) uiDirMode - VER_IDX) < 5 ? SCAN_HOR : (abs((Int)uiDirMode - HOR_IDX) < 5 ? SCAN_VER : SCAN_DIAG);
5077    }
5078  }
5079
5080  return uiScanIdx;
5081}
5082
5083UInt TComDataCU::getSCUAddr()
5084{ 
5085  return getPic()->getPicSym()->getInverseCUOrderMap(m_uiCUAddr)*(1<<(m_pcSlice->getSPS()->getMaxCUDepth()<<1))+m_uiAbsIdxInLCU; 
5086}
5087
5088/** Set neighboring blocks availabilities for non-deblocked filtering
5089 * \param numLCUInPicWidth number of LCUs in picture width
5090 * \param numLCUInPicHeight number of LCUs in picture height
5091 * \param numSUInLCUWidth number of SUs in LCU width
5092 * \param numSUInLCUHeight number of SUs in LCU height
5093 * \param picWidth picture width
5094 * \param picHeight picture height
5095 * \param bIndependentSliceBoundaryEnabled true for independent slice boundary enabled
5096 * \param bTopTileBoundary true means that top boundary coincides tile boundary
5097 * \param bDownTileBoundary true means that bottom boundary coincides tile boundary
5098 * \param bLeftTileBoundary true means that left boundary coincides tile boundary
5099 * \param bRightTileBoundary true means that right boundary coincides tile boundary
5100 * \param bIndependentTileBoundaryEnabled true for independent tile boundary enabled
5101 */
5102Void TComDataCU::setNDBFilterBlockBorderAvailability(UInt numLCUInPicWidth, UInt /*numLCUInPicHeight*/, UInt numSUInLCUWidth, UInt numSUInLCUHeight, UInt picWidth, UInt picHeight
5103                                                    ,std::vector<Bool>& LFCrossSliceBoundary
5104                                                    ,Bool bTopTileBoundary, Bool bDownTileBoundary, Bool bLeftTileBoundary, Bool bRightTileBoundary
5105                                                    ,Bool bIndependentTileBoundaryEnabled)
5106{
5107  UInt numSUInLCU = numSUInLCUWidth*numSUInLCUHeight;
5108  Int* pSliceIDMapLCU = m_piSliceSUMap;
5109  Bool onlyOneSliceInPic = ((Int)LFCrossSliceBoundary.size() == 1);
5110  UInt uiLPelX, uiTPelY;
5111  UInt width, height;
5112  Bool bPicRBoundary, bPicBBoundary, bPicTBoundary, bPicLBoundary;
5113  Bool bLCURBoundary= false, bLCUBBoundary= false, bLCUTBoundary= false, bLCULBoundary= false;
5114  Bool* pbAvailBorder;
5115  Bool* pbAvail;
5116  UInt rTLSU, rBRSU, widthSU, heightSU;
5117  UInt zRefSU;
5118  Int* pRefID;
5119  Int* pRefMapLCU;
5120  UInt rTRefSU= 0, rBRefSU= 0, rLRefSU= 0, rRRefSU= 0;
5121  Int* pRRefMapLCU= NULL;
5122  Int* pLRefMapLCU= NULL;
5123  Int* pTRefMapLCU= NULL;
5124  Int* pBRefMapLCU= NULL;
5125  Int  sliceID;
5126  UInt numSGU = (UInt)m_vNDFBlock.size();
5127
5128  for(Int i=0; i< numSGU; i++)
5129  {
5130    NDBFBlockInfo& rSGU = m_vNDFBlock[i];
5131
5132    sliceID = rSGU.sliceID;
5133    uiLPelX = rSGU.posX;
5134    uiTPelY = rSGU.posY;
5135    width   = rSGU.width;
5136    height  = rSGU.height;
5137    rTLSU     = g_auiZscanToRaster[ rSGU.startSU ];
5138    rBRSU     = g_auiZscanToRaster[ rSGU.endSU   ];
5139    widthSU   = rSGU.widthSU;
5140    heightSU  = rSGU.heightSU;
5141
5142    pbAvailBorder = rSGU.isBorderAvailable;
5143
5144    bPicTBoundary= (uiTPelY == 0                       )?(true):(false);
5145    bPicLBoundary= (uiLPelX == 0                       )?(true):(false);
5146    bPicRBoundary= (!(uiLPelX+ width < picWidth )  )?(true):(false);
5147    bPicBBoundary= (!(uiTPelY + height < picHeight))?(true):(false);
5148
5149    bLCULBoundary = (rTLSU % numSUInLCUWidth == 0)?(true):(false);
5150    bLCURBoundary = ( (rTLSU+ widthSU) % numSUInLCUWidth == 0)?(true):(false);
5151    bLCUTBoundary = ( (UInt)(rTLSU / numSUInLCUWidth)== 0)?(true):(false);
5152    bLCUBBoundary = ( (UInt)(rBRSU / numSUInLCUWidth) == (numSUInLCUHeight-1) )?(true):(false);
5153
5154    //       SGU_L
5155    pbAvail = &(pbAvailBorder[SGU_L]);
5156    if(bPicLBoundary)
5157    {
5158      *pbAvail = false;
5159    }
5160    else if (onlyOneSliceInPic)
5161    {
5162      *pbAvail = true;
5163    }
5164    else
5165    {
5166      //      bLCULBoundary = (rTLSU % uiNumSUInLCUWidth == 0)?(true):(false);
5167      if(bLCULBoundary)
5168      {
5169        rLRefSU     = rTLSU + numSUInLCUWidth -1;
5170        zRefSU      = g_auiRasterToZscan[rLRefSU];
5171        pRefMapLCU = pLRefMapLCU= (pSliceIDMapLCU - numSUInLCU);
5172      }
5173      else
5174      {
5175        zRefSU   = g_auiRasterToZscan[rTLSU - 1];
5176        pRefMapLCU  = pSliceIDMapLCU;
5177      }
5178      pRefID = pRefMapLCU + zRefSU;
5179      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
5180    }
5181
5182    //       SGU_R
5183    pbAvail = &(pbAvailBorder[SGU_R]);
5184    if(bPicRBoundary)
5185    {
5186      *pbAvail = false;
5187    }
5188    else if (onlyOneSliceInPic)
5189    {
5190      *pbAvail = true;
5191    }
5192    else
5193    {
5194      //       bLCURBoundary = ( (rTLSU+ uiWidthSU) % uiNumSUInLCUWidth == 0)?(true):(false);
5195      if(bLCURBoundary)
5196      {
5197        rRRefSU      = rTLSU + widthSU - numSUInLCUWidth;
5198        zRefSU       = g_auiRasterToZscan[rRRefSU];
5199        pRefMapLCU  = pRRefMapLCU= (pSliceIDMapLCU + numSUInLCU);
5200      }
5201      else
5202      {
5203        zRefSU       = g_auiRasterToZscan[rTLSU + widthSU];
5204        pRefMapLCU  = pSliceIDMapLCU;
5205      }
5206      pRefID = pRefMapLCU + zRefSU;
5207      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
5208    }
5209
5210    //       SGU_T
5211    pbAvail = &(pbAvailBorder[SGU_T]);
5212    if(bPicTBoundary)
5213    {
5214      *pbAvail = false;
5215    }
5216    else if (onlyOneSliceInPic)
5217    {
5218      *pbAvail = true;
5219    }
5220    else
5221    {
5222      //      bLCUTBoundary = ( (UInt)(rTLSU / uiNumSUInLCUWidth)== 0)?(true):(false);
5223      if(bLCUTBoundary)
5224      {
5225        rTRefSU      = numSUInLCU - (numSUInLCUWidth - rTLSU);
5226        zRefSU       = g_auiRasterToZscan[rTRefSU];
5227        pRefMapLCU  = pTRefMapLCU= (pSliceIDMapLCU - (numLCUInPicWidth*numSUInLCU));
5228      }
5229      else
5230      {
5231        zRefSU       = g_auiRasterToZscan[rTLSU - numSUInLCUWidth];
5232        pRefMapLCU  = pSliceIDMapLCU;
5233      }
5234      pRefID = pRefMapLCU + zRefSU;
5235      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
5236    }
5237
5238    //       SGU_B
5239    pbAvail = &(pbAvailBorder[SGU_B]);
5240    if(bPicBBoundary)
5241    {
5242      *pbAvail = false;
5243    }
5244    else if (onlyOneSliceInPic)
5245    {
5246      *pbAvail = true;
5247    }
5248    else
5249    {
5250      //      bLCUBBoundary = ( (UInt)(rBRSU / uiNumSUInLCUWidth) == (uiNumSUInLCUHeight-1) )?(true):(false);
5251      if(bLCUBBoundary)
5252      {
5253        rBRefSU      = rTLSU % numSUInLCUWidth;
5254        zRefSU       = g_auiRasterToZscan[rBRefSU];
5255        pRefMapLCU  = pBRefMapLCU= (pSliceIDMapLCU + (numLCUInPicWidth*numSUInLCU));
5256      }
5257      else
5258      {
5259        zRefSU       = g_auiRasterToZscan[rTLSU + (heightSU*numSUInLCUWidth)];
5260        pRefMapLCU  = pSliceIDMapLCU;
5261      }
5262      pRefID = pRefMapLCU + zRefSU;
5263      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
5264    }
5265
5266    //       SGU_TL
5267    pbAvail = &(pbAvailBorder[SGU_TL]);
5268    if(bPicTBoundary || bPicLBoundary)
5269    {
5270      *pbAvail = false;
5271    }
5272    else if (onlyOneSliceInPic)
5273    {
5274      *pbAvail = true;
5275    }
5276    else
5277    {
5278      if(bLCUTBoundary && bLCULBoundary)
5279      {
5280        zRefSU       = numSUInLCU -1;
5281        pRefMapLCU  = pSliceIDMapLCU - ( (numLCUInPicWidth+1)*numSUInLCU);
5282      }
5283      else if(bLCUTBoundary)
5284      {
5285        zRefSU       = g_auiRasterToZscan[ rTRefSU- 1];
5286        pRefMapLCU  = pTRefMapLCU;
5287      }
5288      else if(bLCULBoundary)
5289      {
5290        zRefSU       = g_auiRasterToZscan[ rLRefSU- numSUInLCUWidth ];
5291        pRefMapLCU  = pLRefMapLCU;
5292      }
5293      else //inside LCU
5294      {
5295        zRefSU       = g_auiRasterToZscan[ rTLSU - numSUInLCUWidth -1];
5296        pRefMapLCU  = pSliceIDMapLCU;
5297      }
5298      pRefID = pRefMapLCU + zRefSU;
5299      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
5300    }
5301
5302    //       SGU_TR
5303    pbAvail = &(pbAvailBorder[SGU_TR]);
5304    if(bPicTBoundary || bPicRBoundary)
5305    {
5306      *pbAvail = false;
5307    }
5308    else if (onlyOneSliceInPic)
5309    {
5310      *pbAvail = true;
5311    }
5312    else
5313    {
5314      if(bLCUTBoundary && bLCURBoundary)
5315      {
5316        zRefSU      = g_auiRasterToZscan[numSUInLCU - numSUInLCUWidth];
5317        pRefMapLCU  = pSliceIDMapLCU - ( (numLCUInPicWidth-1)*numSUInLCU);       
5318      }
5319      else if(bLCUTBoundary)
5320      {
5321        zRefSU       = g_auiRasterToZscan[ rTRefSU+ widthSU];
5322        pRefMapLCU  = pTRefMapLCU;
5323      }
5324      else if(bLCURBoundary)
5325      {
5326        zRefSU       = g_auiRasterToZscan[ rRRefSU- numSUInLCUWidth ];
5327        pRefMapLCU  = pRRefMapLCU;
5328      }
5329      else //inside LCU
5330      {
5331        zRefSU       = g_auiRasterToZscan[ rTLSU - numSUInLCUWidth +widthSU];
5332        pRefMapLCU  = pSliceIDMapLCU;
5333      }
5334      pRefID = pRefMapLCU + zRefSU;
5335      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
5336    }
5337
5338    //       SGU_BL
5339    pbAvail = &(pbAvailBorder[SGU_BL]);
5340    if(bPicBBoundary || bPicLBoundary)
5341    {
5342      *pbAvail = false;
5343    }
5344    else if (onlyOneSliceInPic)
5345    {
5346      *pbAvail = true;
5347    }
5348    else
5349    {
5350      if(bLCUBBoundary && bLCULBoundary)
5351      {
5352        zRefSU      = g_auiRasterToZscan[numSUInLCUWidth - 1];
5353        pRefMapLCU  = pSliceIDMapLCU + ( (numLCUInPicWidth-1)*numSUInLCU);       
5354      }
5355      else if(bLCUBBoundary)
5356      {
5357        zRefSU       = g_auiRasterToZscan[ rBRefSU - 1];
5358        pRefMapLCU  = pBRefMapLCU;
5359      }
5360      else if(bLCULBoundary)
5361      {
5362        zRefSU       = g_auiRasterToZscan[ rLRefSU+ heightSU*numSUInLCUWidth ];
5363        pRefMapLCU  = pLRefMapLCU;
5364      }
5365      else //inside LCU
5366      {
5367        zRefSU       = g_auiRasterToZscan[ rTLSU + heightSU*numSUInLCUWidth -1];
5368        pRefMapLCU  = pSliceIDMapLCU;
5369      }
5370      pRefID = pRefMapLCU + zRefSU;
5371      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
5372    }
5373
5374    //       SGU_BR
5375    pbAvail = &(pbAvailBorder[SGU_BR]);
5376    if(bPicBBoundary || bPicRBoundary)
5377    {
5378      *pbAvail = false;
5379    }
5380    else if (onlyOneSliceInPic)
5381    {
5382      *pbAvail = true;
5383    }
5384    else
5385    {
5386      if(bLCUBBoundary && bLCURBoundary)
5387      {
5388        zRefSU = 0;
5389        pRefMapLCU = pSliceIDMapLCU+ ( (numLCUInPicWidth+1)*numSUInLCU);
5390      }
5391      else if(bLCUBBoundary)
5392      {
5393        zRefSU      = g_auiRasterToZscan[ rBRefSU + widthSU];
5394        pRefMapLCU = pBRefMapLCU;
5395      }
5396      else if(bLCURBoundary)
5397      {
5398        zRefSU      = g_auiRasterToZscan[ rRRefSU + (heightSU*numSUInLCUWidth)];
5399        pRefMapLCU = pRRefMapLCU;
5400      }
5401      else //inside LCU
5402      {
5403        zRefSU      = g_auiRasterToZscan[ rTLSU + (heightSU*numSUInLCUWidth)+ widthSU];
5404        pRefMapLCU = pSliceIDMapLCU;
5405      }
5406      pRefID = pRefMapLCU + zRefSU;
5407      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
5408    }
5409
5410    if(bIndependentTileBoundaryEnabled)
5411    {
5412      //left LCU boundary
5413      if(!bPicLBoundary && bLCULBoundary)
5414      {
5415        if(bLeftTileBoundary)
5416        {
5417          pbAvailBorder[SGU_L] = pbAvailBorder[SGU_TL] = pbAvailBorder[SGU_BL] = false;
5418        }
5419      }
5420      //right LCU boundary
5421      if(!bPicRBoundary && bLCURBoundary)
5422      {
5423        if(bRightTileBoundary)
5424        {
5425          pbAvailBorder[SGU_R] = pbAvailBorder[SGU_TR] = pbAvailBorder[SGU_BR] = false;
5426        }
5427      }
5428      //top LCU boundary
5429      if(!bPicTBoundary && bLCUTBoundary)
5430      {
5431        if(bTopTileBoundary)
5432        {
5433          pbAvailBorder[SGU_T] = pbAvailBorder[SGU_TL] = pbAvailBorder[SGU_TR] = false;
5434        }
5435      }
5436      //down LCU boundary
5437      if(!bPicBBoundary && bLCUBBoundary)
5438      {
5439        if(bDownTileBoundary)
5440        {
5441          pbAvailBorder[SGU_B] = pbAvailBorder[SGU_BL] = pbAvailBorder[SGU_BR] = false;
5442        }
5443      }
5444    }
5445    rSGU.allBordersAvailable = true;
5446    for(Int b=0; b< NUM_SGU_BORDER; b++)
5447    {
5448      if(pbAvailBorder[b] == false)
5449      {
5450        rSGU.allBordersAvailable = false;
5451        break;
5452      }
5453    }
5454  }
5455}
5456
5457#if H_3D
5458Void TComDataCU::getPosInPic( UInt uiAbsPartIndex, Int& riPosX, Int& riPosY )
5459{
5460  riPosX = g_auiRasterToPelX[g_auiZscanToRaster[uiAbsPartIndex]] + getCUPelX();
5461  riPosY = g_auiRasterToPelY[g_auiZscanToRaster[uiAbsPartIndex]] + getCUPelY(); 
5462}
5463#endif
5464#if QC_DEPTH_IV_MRG_F0125
5465Bool TComDataCU::getDispNeighBlocks (UInt uiPartIdx, UInt uiPartAddr, DisInfo* pDisp)
5466{
5467  Pel pDepPos[3] = {0, 0, 0};
5468  assert(getPartitionSize( uiPartAddr ) == SIZE_2Nx2N);
5469  Bool bDepAvail = false;
5470  Pel *pDepth  = this->getPic()->getPicYuvRec()->getLumaAddr();
5471  Int iDepStride =  this->getPic()->getPicYuvRec()->getStride();
5472  TComMv cMv; 
5473
5474  Int xP, yP, nPSW, nPSH;
5475  this->getPartPosition(uiPartIdx, xP, yP, nPSW, nPSH);
5476
5477  if(xP != 0 && yP != 0)
5478  {
5479    pDepPos[0] = pDepth[ (yP-1) * iDepStride + (xP-1) ];
5480    bDepAvail = true;
5481  }
5482
5483  if(xP != 0)
5484  {
5485    pDepPos[1] = pDepth[ (yP+nPSH-1) * iDepStride + (xP-1) ];
5486    bDepAvail = true;
5487  }
5488
5489  if(yP != 0)
5490  {
5491    pDepPos[2] = pDepth[ (yP-1) * iDepStride + (xP+nPSW-1) ];
5492    bDepAvail = true;
5493  }
5494
5495  if (bDepAvail)
5496  {
5497    Pel pAvgDepth = (xP != 0 && yP != 0) ? ((5*pDepPos[0] + 5*pDepPos[1] + 6*pDepPos[2] + 8)>>4) : (xP == 0) ? pDepPos[2] : pDepPos[1];
5498    Int iDisp     = getSlice()->getDepthToDisparityB( 0 )[ pAvgDepth ];
5499    cMv.setHor(iDisp);
5500    cMv.setVer(0);
5501    pDisp->m_acNBDV = cMv;
5502    pDisp->m_aVIdxCan = 0;
5503    return true;
5504  }
5505  else
5506  { 
5507    cMv.setZero();
5508    pDisp->m_acNBDV = cMv;
5509    pDisp->m_aVIdxCan = 0;
5510    return false;
5511  }
5512}
5513#endif
5514#if H_3D_NBDV
5515//Notes from QC:
5516//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
5517//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
5518//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
5519Bool TComDataCU::getDisMvpCandNBDV( DisInfo* pDInfo
5520#if H_3D_NBDV_REF
5521, Bool bDepthRefine
5522#endif
5523)
5524{
5525  //// ******* Init variables ******* /////
5526  // Init disparity struct for results
5527  pDInfo->bDV = false;   
5528  // Init struct for disparities from MCP neighboring blocks
5529  IDVInfo cIDVInfo;
5530  cIDVInfo.m_bFound = false; 
5531  UInt uiPartIdx = 0;
5532  UInt uiPartAddr = 0;
5533  for (UInt iCurDvMcpCand = 0; iCurDvMcpCand < IDV_CANDS; iCurDvMcpCand++)
5534  {
5535    for (UInt iList = 0; iList < 2; iList++)
5536    {
5537      cIDVInfo.m_acMvCand[iList][iCurDvMcpCand].setZero();
5538      cIDVInfo.m_aVIdxCan[iList][iCurDvMcpCand] = 0; 
5539      cIDVInfo.m_bAvailab[iList][iCurDvMcpCand] = false; 
5540    }
5541  }
5542#if H_3D_NBDV_REF
5543  if( !m_pcSlice->getVPS()->getDepthRefinementFlag( m_pcSlice->getLayerIdInVps() ) )
5544  {
5545    bDepthRefine = false;
5546  }
5547#endif
5548  // Get Positions 
5549  PartSize eCUMode    = getPartitionSize( uiPartAddr );   
5550  assert(eCUMode == SIZE_2Nx2N);
5551  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB; 
5552
5553  deriveLeftRightTopIdxGeneral(uiPartAddr, uiPartIdx, uiPartIdxLT, uiPartIdxRT );
5554  deriveLeftBottomIdxGeneral  (uiPartAddr, uiPartIdx, uiPartIdxLB );
5555
5556  //// ******* Get disparity from temporal neighboring blocks ******* /////
5557  if ( getSlice()->getEnableTMVPFlag() )
5558  {
5559    TComMv cColMv;
5560    Int iTargetViewIdx = 0;
5561    Int iTStartViewIdx = 0;   
5562
5563    ///*** Derive center position ***
5564    UInt uiPartIdxCenter;
5565    Int  uiLCUIdx   = getAddr();
5566    xDeriveCenterIdx(uiPartIdx, uiPartIdxCenter );
5567
5568    ///*** Search temporal candidate pictures for disparity vector ***
5569    const Int iNumCandPics = getPic()->getNumDdvCandPics();
5570    for(Int curCandPic = 0; curCandPic < iNumCandPics; curCandPic++)
5571    {
5572      RefPicList eCurRefPicList   = REF_PIC_LIST_0 ;
5573      Int        curCandPicRefIdx = 0;
5574      if( curCandPic == 0 ) 
5575      { 
5576        eCurRefPicList   = RefPicList(getSlice()->isInterB() ? 1-getSlice()->getColFromL0Flag() : 0);
5577        curCandPicRefIdx = getSlice()->getColRefIdx();
5578      }
5579      else                 
5580      {
5581        eCurRefPicList   = getPic()->getRapRefList();
5582        curCandPicRefIdx = getPic()->getRapRefIdx();
5583      }
5584
5585      Bool bCheck = xGetColDisMV( curCandPic, eCurRefPicList, curCandPicRefIdx, uiLCUIdx,   uiPartIdxCenter,  cColMv, iTargetViewIdx, iTStartViewIdx );
5586
5587      if( bCheck )
5588      {
5589        clipMv(cColMv);
5590        pDInfo->m_acNBDV = cColMv;
5591        pDInfo->m_aVIdxCan  = iTargetViewIdx;
5592
5593#if H_3D_NBDV_REF
5594        TComPic* picDepth = NULL;   
5595#if H_3D_FCO_VSP_DONBDV_E0163
5596        picDepth  = getSlice()->getIvPic(true, getSlice()->getViewIndex() );
5597        if ( picDepth->getPicYuvRec() != NULL  ) 
5598        {
5599          cColMv.setZero();
5600        }
5601        else // Go back with virtual depth
5602        {
5603          picDepth = getSlice()->getIvPic( true, iTargetViewIdx );
5604        }
5605
5606        assert(picDepth != NULL);
5607#else
5608        picDepth = getSlice()->getIvPic( true, iTargetViewIdx );
5609        assert(picDepth != NULL);
5610#endif
5611        if (picDepth && bDepthRefine)
5612          estimateDVFromDM(iTargetViewIdx, uiPartIdx, picDepth, uiPartAddr, &cColMv );
5613
5614        pDInfo->m_acDoNBDV  = cColMv;
5615#endif //H_3D_NBDV_REF
5616        return true;
5617      }
5618    }
5619  } 
5620
5621  UInt uiIdx = 0;
5622  Bool        bCheckMcpDv = false;   
5623  TComDataCU* pcTmpCU     = NULL;
5624
5625  //// ******* Get disparity from left block ******* /////
5626  pcTmpCU = getPULeft(uiIdx, uiPartIdxLB, true, false);
5627  bCheckMcpDv = true; 
5628  if ( xCheckSpatialNBDV( pcTmpCU, uiIdx, pDInfo, bCheckMcpDv, &cIDVInfo, DVFROM_LEFT
5629#if H_3D_NBDV_REF
5630    , bDepthRefine
5631#endif
5632    ) )
5633    return true;
5634
5635  //// ******* Get disparity from above block ******* /////
5636  pcTmpCU = getPUAbove(uiIdx, uiPartIdxRT, true, false, true);
5637  if(pcTmpCU != NULL )
5638  {
5639    bCheckMcpDv = ( ( getAddr() - pcTmpCU->getAddr() ) == 0);
5640    if ( xCheckSpatialNBDV( pcTmpCU, uiIdx, pDInfo, bCheckMcpDv, &cIDVInfo, DVFROM_ABOVE
5641#if H_3D_NBDV_REF
5642      , bDepthRefine
5643#endif
5644      ) )
5645      return true;
5646  }
5647
5648  //// ******* Search MCP blocks ******* /////
5649  if( cIDVInfo.m_bFound ) 
5650  {
5651    for( Int curPos = 0 ; curPos < IDV_CANDS ; curPos++ ) 
5652    {
5653      for(Int iList = 0; iList < (getSlice()->isInterB() ? 2: 1); iList ++)
5654      {
5655        if( cIDVInfo.m_bAvailab[iList][curPos] )
5656        {
5657          TComMv cDispVec = cIDVInfo.m_acMvCand[iList][ curPos ];
5658          clipMv( cDispVec );
5659          pDInfo->m_acNBDV = cDispVec;
5660          pDInfo->m_aVIdxCan = cIDVInfo.m_aVIdxCan[iList][ curPos ];
5661#if H_3D_NBDV_REF
5662#if H_3D_FCO_VSP_DONBDV_E0163
5663          TComPic* picDepth  = NULL;
5664
5665          picDepth  = getSlice()->getIvPic(true, getSlice()->getViewIndex() );
5666          if ( picDepth->getPicYuvRec() != NULL ) 
5667          {
5668            cDispVec.setZero();
5669          }
5670          else // Go back with virtual depth
5671          {
5672            picDepth = getSlice()->getIvPic( true, pDInfo->m_aVIdxCan );
5673          }
5674
5675          assert(picDepth != NULL);
5676#else
5677          TComPic* picDepth = getSlice()->getIvPic( true, pDInfo->m_aVIdxCan );
5678          assert(picDepth!=NULL);
5679#endif
5680
5681          if (picDepth && bDepthRefine)
5682          {
5683            estimateDVFromDM (pDInfo->m_aVIdxCan, uiPartIdx, picDepth, uiPartAddr, &cDispVec);
5684          }
5685          pDInfo->m_acDoNBDV = cDispVec;
5686#endif
5687          return true;
5688        }
5689      }
5690    }
5691  }
5692
5693  TComMv defaultDV(0, 0);
5694  pDInfo->m_acNBDV = defaultDV;
5695
5696  Int valid = 0;
5697  Int viewIndex = 0;
5698  for( UInt uiBId = 0; uiBId < getSlice()->getViewIndex() && valid==0; uiBId++ )
5699  {
5700    UInt        uiBaseId    = uiBId;
5701    TComPic*    pcBasePic   = getSlice()->getIvPic( false, uiBaseId );
5702    for( Int iRefListId = 0; ( iRefListId < (getSlice()->isInterB()? 2:1) ) && !getSlice()->isIntra() && valid==0; iRefListId++ )
5703    {
5704      RefPicList  eRefPicListTest = RefPicList( iRefListId );
5705      Int         iNumRefPics = getSlice()->getNumRefIdx( eRefPicListTest ) ;
5706      for( Int iRefIndex = 0; iRefIndex < iNumRefPics; iRefIndex++ )
5707      { 
5708        if(pcBasePic->getPOC() == getSlice()->getRefPic( eRefPicListTest, iRefIndex )->getPOC() 
5709          && pcBasePic->getViewIndex() == getSlice()->getRefPic( eRefPicListTest, iRefIndex )->getViewIndex())
5710        {
5711          valid=1;
5712          viewIndex = uiBaseId;
5713          break;
5714        }
5715      }
5716    }
5717  }
5718  if(valid)
5719  {
5720    pDInfo->m_aVIdxCan = viewIndex;
5721#if H_3D_NBDV_REF
5722    TComPic* picDepth = NULL;
5723#if H_3D_FCO_VSP_DONBDV_E0163
5724    picDepth  = getSlice()->getIvPic(true, getSlice()->getViewIndex() );
5725    if ( picDepth->getPicYuvRec() != NULL ) 
5726    {
5727      defaultDV.setZero();
5728    }
5729    else // Go back with virtual depth
5730    {
5731      picDepth = getSlice()->getIvPic( true, viewIndex );
5732    }
5733
5734    assert(picDepth != NULL);
5735#else
5736    picDepth = getSlice()->getIvPic( true, viewIndex );
5737    assert(picDepth!=NULL);
5738#endif
5739    if (picDepth && bDepthRefine)
5740    {
5741      estimateDVFromDM(viewIndex, uiPartIdx, picDepth, uiPartAddr, &defaultDV ); // from base view
5742    }
5743    pDInfo->m_acDoNBDV = defaultDV;
5744#endif
5745  }
5746  return false; 
5747}
5748
5749#if H_3D_NBDV_REF
5750Pel TComDataCU::getMcpFromDM(TComPicYuv* pcBaseViewDepthPicYuv, TComMv* mv, Int iBlkX, Int iBlkY, Int iBlkWidth, Int iBlkHeight, Int* aiShiftLUT )
5751{
5752  Int iPictureWidth  = pcBaseViewDepthPicYuv->getWidth();
5753  Int iPictureHeight = pcBaseViewDepthPicYuv->getHeight();
5754 
5755  Int depthStartPosX = Clip3(0,   iPictureWidth - 1,  iBlkX + ((mv->getHor()+2)>>2));
5756  Int depthStartPosY = Clip3(0,   iPictureHeight - 1, iBlkY + ((mv->getVer()+2)>>2));
5757  Int depthEndPosX   = Clip3(0,   iPictureWidth - 1,  iBlkX + iBlkWidth - 1 + ((mv->getHor()+2)>>2));
5758  Int depthEndPosY   = Clip3(0,   iPictureHeight - 1, iBlkY + iBlkHeight - 1 + ((mv->getVer()+2)>>2));
5759
5760  Pel* depthTL  = pcBaseViewDepthPicYuv->getLumaAddr();
5761  Int depStride =  pcBaseViewDepthPicYuv->getStride();
5762
5763  Pel  maxDepthVal = 0;
5764  maxDepthVal = std::max( maxDepthVal, depthTL[ (depthStartPosY) * depStride + depthStartPosX ]);      // Left Top
5765  maxDepthVal = std::max( maxDepthVal, depthTL[ (depthEndPosY)   * depStride + depthStartPosX ]);      // Left Bottom
5766  maxDepthVal = std::max( maxDepthVal, depthTL[ (depthStartPosY) * depStride + depthEndPosX   ]);      // Right Top
5767  maxDepthVal = std::max( maxDepthVal, depthTL[ (depthEndPosY)   * depStride + depthEndPosX   ]);      // Right Bottom
5768
5769  return aiShiftLUT[ maxDepthVal ];
5770}
5771
5772Void TComDataCU::estimateDVFromDM(Int refViewIdx, UInt uiPartIdx, TComPic* picDepth, UInt uiPartAddr, TComMv* cMvPred )
5773{
5774  if (picDepth)
5775  {
5776    UInt uiAbsPartAddrCurrCU = m_uiAbsIdxInLCU + uiPartAddr;
5777    Int iWidth, iHeight;
5778    getPartIndexAndSize( uiPartIdx, uiPartAddr, iWidth, iHeight ); // The modified value of uiPartAddr won't be used any more
5779
5780    TComPicYuv* pcBaseViewDepthPicYuv = picDepth->getPicYuvRec();
5781    Int iBlkX = ( getAddr() % picDepth->getFrameWidthInCU() ) * g_uiMaxCUWidth  + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartAddrCurrCU ] ];
5782    Int iBlkY = ( getAddr() / picDepth->getFrameWidthInCU() ) * g_uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartAddrCurrCU ] ];
5783
5784    Int* aiShiftLUT = getSlice()->getDepthToDisparityB(refViewIdx );
5785
5786    Pel iDisp = getMcpFromDM( pcBaseViewDepthPicYuv, cMvPred, iBlkX, iBlkY, iWidth, iHeight, aiShiftLUT );
5787    cMvPred->setHor( iDisp );
5788    clipMv(*cMvPred);
5789  }
5790}
5791#endif //H_3D_NBDV_REF
5792
5793
5794Bool TComDataCU::xCheckSpatialNBDV( TComDataCU* pcTmpCU, UInt uiIdx, DisInfo* pNbDvInfo, Bool bSearchForMvpDv, IDVInfo* paIDVInfo, UInt uiMvpDvPos
5795#if H_3D_NBDV_REF
5796, Bool bDepthRefine
5797#endif
5798)
5799{
5800  if( pcTmpCU != NULL && !pcTmpCU->isIntra( uiIdx ) )
5801  {
5802    Bool bTmpIsSkipped = pcTmpCU->isSkipped( uiIdx );
5803    for(Int iList = 0; iList < (getSlice()->isInterB() ? 2: 1); iList ++)
5804    {
5805      RefPicList eRefPicList = RefPicList(iList);
5806      Int      refId = pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) ;
5807      TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
5808
5809      if( refId >= 0)
5810      {
5811        Int refViewIdx  = pcTmpCU->getSlice()->getRefPic(eRefPicList, refId)->getViewIndex();
5812        if (refViewIdx != m_pcSlice->getViewIndex()) 
5813        {
5814          clipMv(cMvPred);
5815          pNbDvInfo->m_acNBDV = cMvPred;
5816          pNbDvInfo->m_aVIdxCan = refViewIdx;
5817#if H_3D_NBDV_REF
5818          TComPic* picDepth = NULL;
5819          assert(getSlice()->getRefPic(eRefPicList, refId)->getPOC() == getSlice()->getPOC());         
5820#if H_3D_FCO_VSP_DONBDV_E0163
5821          picDepth  = getSlice()->getIvPic(true, getSlice()->getViewIndex() );
5822          if ( picDepth->getPicYuvRec() != NULL ) 
5823          {
5824            cMvPred.setZero();
5825          }
5826          else// Go back with virtual depth
5827          {
5828            picDepth = getSlice()->getIvPic (true, refViewIdx );
5829          }
5830          assert(picDepth != NULL);
5831#else
5832          picDepth   = getSlice()->getIvPic (true, refViewIdx );
5833          assert(picDepth != NULL);
5834#endif
5835          UInt uiPartIdx = 0;   //Notes from MTK: Please confirm that using 0 as partition index and partition address is correct for CU-level DoNBDV
5836          UInt uiPartAddr = 0;  //QC: confirmed
5837
5838          if (picDepth && bDepthRefine)
5839            estimateDVFromDM(refViewIdx, uiPartIdx, picDepth, uiPartAddr, &cMvPred );
5840
5841          pNbDvInfo->m_acDoNBDV = cMvPred;
5842#endif
5843          return true;
5844        }
5845        else if ( bSearchForMvpDv && cMvPred.getIDVFlag() && bTmpIsSkipped )
5846        {
5847          assert( uiMvpDvPos < IDV_CANDS );
5848          paIDVInfo->m_acMvCand[iList][ uiMvpDvPos ] = TComMv( cMvPred.getIDVHor(), cMvPred.getIDVVer() );
5849          //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.
5850          paIDVInfo->m_aVIdxCan[iList][ uiMvpDvPos ] = cMvPred.getIDVVId();
5851          paIDVInfo->m_bAvailab[iList][ uiMvpDvPos ] = true;
5852          paIDVInfo->m_bFound                        = true; 
5853        }
5854      }
5855    }
5856  }
5857  return false; 
5858}
5859 
5860Void TComDataCU::xDeriveRightBottomNbIdx(Int &riLCUIdxRBNb, Int &riPartIdxRBNb )
5861{
5862  UInt uiPartIdx = 0;
5863  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth(); 
5864  Int uiLCUIdx = getAddr();
5865
5866  UInt uiPartIdxRB;
5867  deriveRightBottomIdx(uiPartIdx, uiPartIdxRB ); 
5868  UInt uiAbsPartIdxTmp = g_auiZscanToRaster[uiPartIdxRB];
5869
5870  if (( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth() )>= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )
5871  {
5872    riLCUIdxRBNb  = -1;
5873    riPartIdxRBNb = -1;
5874  }
5875  else if(( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxTmp] + m_pcPic->getMinCUHeight() )>= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
5876  {
5877    riLCUIdxRBNb  = -1;
5878    riPartIdxRBNb = -1;
5879  }
5880  else
5881  {
5882    if ( ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
5883      ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
5884    {
5885      riPartIdxRBNb = g_auiRasterToZscan[ uiAbsPartIdxTmp + uiNumPartInCUWidth + 1 ];
5886      riLCUIdxRBNb  = uiLCUIdx; 
5887    }
5888    else if ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
5889    {
5890      riPartIdxRBNb = -1;
5891      riLCUIdxRBNb  = -1;
5892    }
5893    else if ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
5894    {
5895      riPartIdxRBNb = g_auiRasterToZscan[ uiAbsPartIdxTmp + 1 ];
5896      riLCUIdxRBNb = uiLCUIdx + 1;
5897    }
5898    else //is the right bottom corner of LCU                       
5899    {
5900      riPartIdxRBNb = -1;
5901      riLCUIdxRBNb  = -1;
5902    }
5903  }
5904}
5905
5906
5907Void TComDataCU::setDvInfoSubParts( DisInfo cDvInfo, UInt uiAbsPartIdx, UInt uiDepth )
5908{
5909  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
5910  for (UInt ui = 0; ui < uiCurrPartNumb; ui++ )
5911  {
5912    m_pDvInfo[uiAbsPartIdx + ui] = cDvInfo;
5913  }
5914}
5915#if H_3D_VSP
5916Void TComDataCU::setDvInfoSubParts( DisInfo cDvInfo, UInt uiAbsPartIdx, UInt uiPUIdx, UInt uiDepth )
5917{
5918  setSubPartT<DisInfo>( cDvInfo, m_pDvInfo, uiAbsPartIdx, uiDepth, uiPUIdx );
5919}
5920#endif
5921
5922Bool TComDataCU::xGetColDisMV( Int currCandPic, RefPicList eRefPicList, Int refidx, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv , Int & iTargetViewIdx, Int & iStartViewIdx )
5923{
5924
5925  RefPicList  eColRefPicList = REF_PIC_LIST_0;
5926  Int iColViewIdx, iColRefViewIdx;
5927  TComPic *pColPic = getSlice()->getRefPic( eRefPicList, refidx);
5928  TComDataCU *pColCU = pColPic->getCU( uiCUAddr );
5929  iColViewIdx = pColCU->getSlice()->getViewIndex();
5930  if (pColCU->getPic()==0||pColCU->getPartitionSize(uiPartUnitIdx)==SIZE_NONE||pColCU->isIntra(uiPartUnitIdx))
5931  {
5932    return false;
5933  }
5934  for (Int ilist = 0; ilist < (pColCU->getSlice()->isInterB()? 2:1); ilist++) 
5935  {
5936    if(pColCU->getSlice()->isInterB())
5937    {
5938      eColRefPicList = RefPicList(ilist);
5939    }
5940
5941    Int iColRefIdx = pColCU->getCUMvField(eColRefPicList)->getRefIdx(uiPartUnitIdx);
5942
5943    if (iColRefIdx < 0)
5944    {
5945      continue;
5946    }
5947
5948    iColRefViewIdx = pColCU->getSlice()->getRefPic(eColRefPicList, iColRefIdx)->getViewIndex();
5949
5950    if ( iColViewIdx    == iColRefViewIdx ) // temporal vector
5951    {
5952      continue;
5953    }
5954    else 
5955    {
5956      if(getPic()->isTempIVRefValid(currCandPic, ilist,  iColRefIdx))
5957      {
5958        rcMv = pColCU->getCUMvField(eColRefPicList)->getMv(uiPartUnitIdx);
5959        rcMv.setIDVFlag(0);
5960        iTargetViewIdx  = iColRefViewIdx ;
5961        iStartViewIdx   = iColViewIdx   ;
5962        return true;   
5963      }
5964    }
5965  }
5966
5967  return false;
5968}
5969#endif
5970#if  H_3D_FAST_TEXTURE_ENCODING
5971Void
5972TComDataCU::getIVNStatus       ( UInt uiPartIdx,  DisInfo* pDInfo, Bool& bIVFMerge, Int& iIVFMaxD)
5973{
5974  TComSlice*    pcSlice         = getSlice (); 
5975  Int iViewIndex = pDInfo->m_aVIdxCan;
5976  //--- get base CU/PU and check prediction mode ---
5977  TComPic*    pcBasePic   = pcSlice->getIvPic( false, iViewIndex );
5978  TComPicYuv* pcBaseRec   = pcBasePic->getPicYuvRec   ();
5979
5980  UInt          uiPartAddr;
5981  Int           iWidth;
5982  Int           iHeight;
5983  getPartIndexAndSize( uiPartIdx, uiPartAddr, iWidth, iHeight );
5984
5985  Int  iCurrPosX, iCurrPosY;
5986  pcBaseRec->getTopLeftSamplePos( getAddr(), getZorderIdxInCU() + uiPartAddr, iCurrPosX, iCurrPosY );
5987
5988  iCurrPosX  += ( ( iWidth  - 1 ) >> 1 );
5989  iCurrPosY  += ( ( iHeight - 1 ) >> 1 );
5990
5991  Bool depthRefineFlag = false; 
5992#if H_3D_NBDV_REF
5993  depthRefineFlag = m_pcSlice->getVPS()->getDepthRefinementFlag( m_pcSlice->getLayerIdInVps() ); 
5994#endif // H_3D_NBDV_REF
5995
5996  TComMv      cDv = depthRefineFlag ? pDInfo->m_acDoNBDV : pDInfo->m_acNBDV; 
5997
5998  Int         iBasePosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (cDv.getHor() + 2 ) >> 2 ) );
5999  Int         iBasePosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (cDv.getVer() + 2 ) >> 2 )); 
6000  Int         iBaseLPosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX - (iWidth >> 1) + ( (cDv.getHor() + 2 ) >> 2 ) );
6001  Int         iBaseLPosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (cDv.getVer() + 2 ) >> 2 )); 
6002  Int         iBaseRPosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + (iWidth >> 1) + 1 + ( (cDv.getHor() + 2 ) >> 2 ) );
6003  Int         iBaseRPosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (cDv.getVer() + 2 ) >> 2 )); 
6004  Int         iBaseUPosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (cDv.getHor() + 2 ) >> 2 ) );
6005  Int         iBaseUPosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY - (iHeight >> 1) + ( (cDv.getVer() + 2 ) >> 2 )); 
6006  Int         iBaseDPosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (cDv.getHor() + 2 ) >> 2 ) );
6007  Int         iBaseDPosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + (iHeight >> 1) + 1 + ( (cDv.getVer() + 2 ) >> 2 )); 
6008
6009  Int         iBaseCUAddr;
6010  Int         iBaseAbsPartIdx;
6011  Int         iBaseLCUAddr;
6012  Int         iBaseLAbsPartIdx;
6013  Int         iBaseRCUAddr;
6014  Int         iBaseRAbsPartIdx;
6015  Int         iBaseUCUAddr;
6016  Int         iBaseUAbsPartIdx;
6017  Int         iBaseDCUAddr;
6018  Int         iBaseDAbsPartIdx;
6019  pcBaseRec->getCUAddrAndPartIdx( iBasePosX , iBasePosY , iBaseCUAddr, iBaseAbsPartIdx );
6020  pcBaseRec->getCUAddrAndPartIdx( iBaseLPosX , iBaseLPosY , iBaseLCUAddr, iBaseLAbsPartIdx );
6021  pcBaseRec->getCUAddrAndPartIdx( iBaseRPosX , iBaseRPosY , iBaseRCUAddr, iBaseRAbsPartIdx );
6022  pcBaseRec->getCUAddrAndPartIdx( iBaseUPosX , iBaseUPosY , iBaseUCUAddr, iBaseUAbsPartIdx );
6023  pcBaseRec->getCUAddrAndPartIdx( iBaseDPosX , iBaseDPosY , iBaseDCUAddr, iBaseDAbsPartIdx );
6024  TComDataCU* pcBaseCU    = pcBasePic->getCU( iBaseCUAddr );
6025  TComDataCU* pcBaseLCU    = pcBasePic->getCU( iBaseLCUAddr );
6026  TComDataCU* pcBaseRCU    = pcBasePic->getCU( iBaseRCUAddr );
6027  TComDataCU* pcBaseUCU    = pcBasePic->getCU( iBaseUCUAddr );
6028  TComDataCU* pcBaseDCU    = pcBasePic->getCU( iBaseDCUAddr );
6029  bIVFMerge = pcBaseLCU->getMergeFlag( iBaseLAbsPartIdx ) && pcBaseCU->getMergeFlag( iBaseAbsPartIdx ) && pcBaseRCU->getMergeFlag( iBaseRAbsPartIdx ) && pcBaseUCU->getMergeFlag( iBaseUAbsPartIdx ) && pcBaseDCU->getMergeFlag( iBaseDAbsPartIdx );
6030  Int aiDepthL[5]; //depth level
6031  aiDepthL[0] = pcBaseCU->getDepth(iBaseAbsPartIdx);
6032  aiDepthL[1] = pcBaseLCU->getDepth(iBaseLAbsPartIdx);
6033  aiDepthL[2] = pcBaseRCU->getDepth(iBaseRAbsPartIdx);
6034  aiDepthL[3] = pcBaseUCU->getDepth(iBaseUAbsPartIdx);
6035  aiDepthL[4] = pcBaseDCU->getDepth(iBaseDAbsPartIdx);
6036  for (Int i = 0; i < 5; i++)
6037  {
6038    if (iIVFMaxD < aiDepthL[i])
6039      iIVFMaxD = aiDepthL[i];
6040  }
6041}
6042#endif
6043#if H_3D_IV_MERGE
6044Bool
6045TComDataCU::getInterViewMergeCands(UInt uiPartIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv, DisInfo* pDInfo, Int* availableMcDc
6046#if QC_DEPTH_IV_MRG_F0125
6047, Bool bIsDepth           
6048#endif
6049)
6050{
6051  TComSlice*    pcSlice = getSlice (); 
6052  Int iViewIndex        = pDInfo->m_aVIdxCan;
6053 
6054  //--- get base CU/PU and check prediction mode ---
6055#if QC_DEPTH_IV_MRG_F0125
6056  TComPic*    pcBasePic   = pcSlice->getIvPic( bIsDepth, iViewIndex );
6057#else
6058  TComPic*    pcBasePic   = pcSlice->getIvPic( false, iViewIndex );
6059#endif
6060  TComPicYuv* pcBaseRec   = pcBasePic->getPicYuvRec   ();
6061
6062  UInt          uiPartAddr;
6063  Int           iWidth;
6064  Int           iHeight;
6065  getPartIndexAndSize( uiPartIdx, uiPartAddr, iWidth, iHeight );
6066
6067  Int  iCurrPosX, iCurrPosY;
6068  pcBaseRec->getTopLeftSamplePos( getAddr(), getZorderIdxInCU() + uiPartAddr, iCurrPosX, iCurrPosY );
6069
6070#if QC_DEPTH_IV_MRG_F0125
6071  iCurrPosX  += ( iWidth  >> 1 );
6072  iCurrPosY  += ( iHeight >> 1 );
6073#else
6074  iCurrPosX  += ( ( iWidth  - 1 ) >> 1 );
6075  iCurrPosY  += ( ( iHeight - 1 ) >> 1 );
6076#endif
6077
6078  Bool depthRefineFlag = false; 
6079#if H_3D_NBDV_REF
6080  depthRefineFlag = m_pcSlice->getVPS()->getDepthRefinementFlag( m_pcSlice->getLayerIdInVps() ); 
6081#endif // H_3D_NBDV_REF
6082
6083  TComMv      cDv = depthRefineFlag ? pDInfo->m_acDoNBDV : pDInfo->m_acNBDV; 
6084 
6085  Bool abPdmAvailable[8] =  {false, false, false, false, false, false, false, false};
6086#if H_3D_NBDV
6087  for( Int i = 0; i < 8; i++)
6088  {
6089    pacPdmMv[i].setIDVFlag   (false);
6090  }
6091#endif
6092
6093  ////////////////////////////////
6094  /////// IvMC + IvMCShift ///////
6095  ////////////////////////////////
6096
6097  for(Int iLoopCan = 0; iLoopCan < 2; iLoopCan ++) 
6098  {
6099    // iLoopCan == 0 --> IvMC
6100    // iLoopCan == 1 --> IvMCShift
6101
6102    Int         iBaseCUAddr;
6103    Int         iBaseAbsPartIdx;
6104
6105    Int offsetW = (iLoopCan == 0) ? 0 : ( ((iWidth /2)*4) + 4 );
6106    Int offsetH = (iLoopCan == 0) ? 0 : ( ((iHeight/2)*4) + 4 );
6107
6108    Int         iBasePosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (cDv.getHor() + offsetW + 2 ) >> 2 ) );
6109    Int         iBasePosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (cDv.getVer() + offsetH + 2 ) >> 2 ) ); 
6110    pcBaseRec->getCUAddrAndPartIdx( iBasePosX , iBasePosY , iBaseCUAddr, iBaseAbsPartIdx );
6111
6112    TComDataCU* pcBaseCU    = pcBasePic->getCU( iBaseCUAddr );
6113    if(!( pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) == MODE_INTRA ))
6114    {
6115      // Loop reference picture list of current slice (X in spec).
6116      for( UInt uiCurrRefListId = 0; uiCurrRefListId < 2; uiCurrRefListId++ )       
6117      {
6118        RefPicList  eCurrRefPicList = RefPicList( uiCurrRefListId );
6119
6120        Bool stopLoop = false;
6121        // Loop reference picture list of candidate slice (Y in spec)
6122        for(Int iLoop = 0; iLoop < 2 && !stopLoop; ++iLoop)
6123        {
6124          RefPicList eBaseRefPicList = (iLoop ==1)? RefPicList( 1 -  uiCurrRefListId ) : RefPicList( uiCurrRefListId );
6125          TComMvField cBaseMvField;
6126          pcBaseCU->getMvField( pcBaseCU, iBaseAbsPartIdx, eBaseRefPicList, cBaseMvField );
6127          Int         iBaseRefIdx     = cBaseMvField.getRefIdx();
6128          if (iBaseRefIdx >= 0)
6129          {
6130            Int iBaseRefPOC = pcBaseCU->getSlice()->getRefPOC(eBaseRefPicList, iBaseRefIdx);
6131            if (iBaseRefPOC != pcSlice->getPOC())   
6132            {
6133              for (Int iPdmRefIdx = 0; iPdmRefIdx < pcSlice->getNumRefIdx( eCurrRefPicList ); iPdmRefIdx++)
6134              {
6135                if (iBaseRefPOC == pcSlice->getRefPOC(eCurrRefPicList, iPdmRefIdx))
6136                {
6137                  abPdmAvailable[ (uiCurrRefListId + (iLoopCan<<2)) ] = true;
6138                  TComMv cMv(cBaseMvField.getHor(), cBaseMvField.getVer());
6139#if H_3D_NBDV
6140#if QC_DEPTH_IV_MRG_F0125
6141                  if( !bIsDepth )
6142                  {
6143#endif
6144                    cMv.setIDVFlag   (true);
6145                    cMv.setIDVHor    (cDv.getHor());                 
6146                    cMv.setIDVVer    (cDv.getVer()); 
6147                    cMv.setIDVVId    (iViewIndex); 
6148#if QC_DEPTH_IV_MRG_F0125
6149                  }
6150#endif
6151#endif
6152                  clipMv( cMv );
6153                  paiPdmRefIdx  [ (uiCurrRefListId + (iLoopCan<<2)) ] = iPdmRefIdx;
6154                  pacPdmMv      [ (uiCurrRefListId + (iLoopCan<<2)) ] = cMv;
6155                  stopLoop = true;
6156                  break;
6157                }
6158              }
6159            }
6160          }
6161        }
6162      }
6163    }
6164  }
6165  for(Int iLoopCan = 0; iLoopCan < 2; iLoopCan ++)
6166  {
6167    availableMcDc[(iLoopCan << 1)] = ( abPdmAvailable[(iLoopCan<<2)] ? 1 : 0 ) + ( abPdmAvailable[1 + (iLoopCan<<2)] ? 2 : 0);
6168  }
6169 
6170 
6171  ////////////////////////////////
6172  /////// IvDC + IvDCShift ///////
6173  ////////////////////////////////
6174 
6175  for( Int iRefListId = 0; iRefListId < 2 ; iRefListId++ )
6176  {
6177    RefPicList  eRefPicListDMV       = RefPicList( iRefListId );
6178    Int         iNumRefPics       = pcSlice->getNumRefIdx( eRefPicListDMV );
6179    for( Int iPdmRefIdx = 0; iPdmRefIdx < iNumRefPics; iPdmRefIdx++ )
6180    {
6181      if(( pcSlice->getRefPOC( eRefPicListDMV, iPdmRefIdx ) == pcSlice->getPOC()) && (pcSlice->getRefPic( eRefPicListDMV, iPdmRefIdx )->getViewIndex() == pDInfo->m_aVIdxCan))
6182      {
6183        for(Int iLoopCan = 0; iLoopCan < 2; iLoopCan ++)
6184        {
6185          Int ioffsetDV = (iLoopCan == 0) ? 0 : 4;
6186          abPdmAvailable[ iRefListId + 2 + (iLoopCan<<2) ] = true;
6187          paiPdmRefIdx  [ iRefListId + 2 + (iLoopCan<<2) ] = iPdmRefIdx;
6188#if H_3D_NBDV_REF
6189          TComMv cMv = depthRefineFlag ? pDInfo->m_acDoNBDV : pDInfo->m_acNBDV; 
6190#endif
6191          cMv.setHor( cMv.getHor() + ioffsetDV );
6192#if QC_DEPTH_IV_MRG_F0125
6193          if( bIsDepth )
6194            cMv.setHor((cMv.getHor()+2)>>2); 
6195#endif
6196          cMv.setVer( 0 );
6197          clipMv( cMv );
6198          pacPdmMv      [iRefListId + 2 + (iLoopCan<<2)] = cMv;
6199        }
6200        break;
6201      }
6202    }
6203  }
6204  for(Int iLoopCan = 0; iLoopCan < 2; iLoopCan ++)
6205  {
6206    availableMcDc[1 + (iLoopCan << 1)] = ( abPdmAvailable[2 + (iLoopCan<<2)] ? 1 : 0 ) + ( abPdmAvailable[3 + (iLoopCan<<2)] ? 2 : 0 );
6207  }
6208  return false;
6209}
6210#endif
6211#if H_3D_ARP
6212Void TComDataCU::setARPWSubParts ( UChar w, UInt uiAbsPartIdx, UInt uiDepth )
6213{
6214  assert( sizeof( *m_puhARPW) == 1 );
6215  memset( m_puhARPW + uiAbsPartIdx, w, m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ) );
6216}
6217#endif
6218
6219#if H_3D_IC
6220Void TComDataCU::setICFlagSubParts( Bool bICFlag, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
6221{
6222  memset( m_pbICFlag + uiAbsPartIdx, bICFlag, (m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ))*sizeof(Bool) );
6223}
6224
6225Bool TComDataCU::isICFlagRequired( UInt uiAbsPartIdx )
6226{
6227  UInt uiPartAddr;
6228  UInt iNumbPart;
6229
6230  if( !( getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) )
6231  {
6232    return false;
6233  }
6234
6235  if( getSlice()->getIcSkipParseFlag() )
6236  {
6237    if( getMergeFlag( uiAbsPartIdx ) && getMergeIndex( uiAbsPartIdx ) == 0 )
6238    {
6239      return false;
6240    }
6241  }
6242
6243  if( getMergeFlag( uiAbsPartIdx ) )
6244  {
6245    return true;
6246  }
6247
6248
6249  Int iWidth, iHeight;
6250
6251  iNumbPart = ( getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ? 1 : ( getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ? 4 : 2 ) );
6252
6253  for(UInt i = 0; i < iNumbPart; i++)
6254  {
6255    getPartIndexAndSize( i, uiPartAddr, iWidth, iHeight, uiAbsPartIdx, true );
6256    uiPartAddr += uiAbsPartIdx;
6257
6258    for(UInt uiRefIdx = 0; uiRefIdx < 2; uiRefIdx++)
6259    {
6260      RefPicList eRefList = uiRefIdx ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
6261      Int iBestRefIdx = getCUMvField(eRefList)->getRefIdx(uiPartAddr);
6262
6263      if( ( getInterDir( uiPartAddr ) & ( uiRefIdx+1 ) ) && iBestRefIdx >= 0 && getSlice()->getViewIndex() != getSlice()->getRefPic( eRefList, iBestRefIdx )->getViewIndex() )
6264      {
6265        return true;
6266      }
6267    }
6268  }
6269
6270  return false;
6271}
6272#endif
6273#if H_3D_DIM_DMM
6274Void TComDataCU::setDmmWedgeTabIdxSubParts( UInt tabIdx, UInt dmmType, UInt uiAbsPartIdx, UInt uiDepth )
6275{
6276  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
6277  for( UInt ui = 0; ui < uiCurrPartNumb; ui++ ) { m_dmmWedgeTabIdx[dmmType][uiAbsPartIdx+ui] = tabIdx; }
6278}
6279Void  TComDataCU::setDmm3IntraTabIdxSubParts( UInt uiTIdx, UInt uiAbsPartIdx, UInt uiDepth )
6280{
6281  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
6282  for( UInt ui = 0; ui < uiCurrPartNumb; ui++ ) { m_dmm3IntraTabIdx[uiAbsPartIdx+ui] = uiTIdx; }
6283}
6284#endif
6285#if H_3D_DIM_RBC
6286Void TComDataCU::reconPartition( UInt uiAbsPartIdx, UInt uiDepth, Bool bLeft, UChar ucStartPos, UChar ucNumEdge, UChar* pucEdgeCode, Bool* pbRegion )
6287{
6288  Int iWidth;
6289  Int iHeight;
6290  if( uiDepth == 0 )
6291  {
6292    iWidth = 64;
6293    iHeight = 64;
6294  }
6295  else if( uiDepth == 1 )
6296  {
6297    iWidth = 32;
6298    iHeight = 32;
6299  }
6300  else if( uiDepth == 2 )
6301  {
6302    iWidth = 16;
6303    iHeight = 16;
6304  }
6305  else if( uiDepth == 3 )
6306  {
6307    iWidth = 8;
6308    iHeight = 8;
6309  }
6310  else // uiDepth == 4
6311  {
6312    iWidth = 4;
6313    iHeight = 4;
6314  }
6315
6316  Int iPtr = 0;
6317  Int iX, iY;
6318  Int iDir = -1;
6319  Int iDiffX = 0, iDiffY = 0;
6320
6321  // 1. Edge Code -> Vert & Horz Edges
6322  Bool*  pbEdge = (Bool*) xMalloc( Bool, 4 * iWidth * iHeight );
6323
6324  for( UInt ui = 0; ui < 4 * iWidth * iHeight; ui++ )
6325    pbEdge  [ ui ] = false;
6326
6327  // Direction : left(0), right(1), top(2), bottom(3), left-top(4), right-top(5), left-bottom(6), right-bottom(7)
6328  // Code      : 0deg(0), 45deg(1), -45deg(2), 90deg(3), -90deg(4), 135deg(5), -135deg(6)
6329  const UChar tableDir[8][7] = { { 0, 6, 4, 3, 2, 7, 5 },
6330  { 1, 5, 7, 2, 3, 4, 6 },
6331  { 2, 4, 5, 0, 1, 6, 7 },
6332  { 3, 7, 6, 1, 0, 5, 4 },
6333  { 4, 0, 2, 6, 5, 3, 1 },
6334  { 5, 2, 1, 4, 7, 0, 3 },
6335  { 6, 3, 0, 7, 4, 1, 2 },
6336  { 7, 1, 3, 5, 6, 2, 0 }};
6337
6338  UChar ucCode = pucEdgeCode[iPtr++];
6339
6340  if( !bLeft )
6341  {
6342    iX = ucStartPos;
6343    iY = 0;
6344
6345    switch(ucCode)
6346    {
6347    case 0: // bottom
6348      iDir = 3;
6349      if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
6350      break;
6351    case 2: // left-bottom
6352      iDir = 6;
6353      if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
6354      break;
6355    case 1: // right-bottom
6356      iDir = 7;
6357      if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
6358      if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
6359      break;
6360    case 4: // left
6361      iDir = 0;
6362      assert(false);
6363      break;
6364    case 3: // right
6365      iDir = 1;
6366      if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
6367      if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
6368      break;
6369    }
6370  }
6371  else
6372  {
6373    iX = 0;
6374    iY = ucStartPos;
6375
6376    switch(ucCode)
6377    {
6378    case 0: // right
6379      iDir = 1;
6380      if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
6381      break;
6382    case 1: // right-top
6383      iDir = 5;
6384      if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
6385      if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
6386      break;
6387    case 2: // right-bottom
6388      iDir = 7;
6389      if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
6390      break;
6391    case 3: // top
6392      iDir = 2;
6393      if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
6394      if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
6395      break;
6396    case 4: // bottom
6397      iDir = 3;
6398      assert(false);
6399      break;
6400    }
6401  }
6402
6403  switch( iDir )
6404  {
6405  case 0: // left
6406    iDiffX = -1;
6407    iDiffY = 0;
6408    break;
6409  case 1: // right
6410    iDiffX = +1;
6411    iDiffY = 0;
6412    break;
6413  case 2: // top
6414    iDiffX = 0;
6415    iDiffY = -1;
6416    break;
6417  case 3: // bottom
6418    iDiffX = 0;
6419    iDiffY = +1;
6420    break;
6421  case 4: // left-top
6422    iDiffX = -1;
6423    iDiffY = -1;
6424    break;
6425  case 5: // right-top
6426    iDiffX = +1;
6427    iDiffY = -1;
6428    break;
6429  case 6: // left-bottom
6430    iDiffX = -1;
6431    iDiffY = +1;
6432    break;
6433  case 7: // right-bottom
6434    iDiffX = +1;
6435    iDiffY = +1;
6436    break;
6437  }
6438
6439  iX += iDiffX;
6440  iY += iDiffY;
6441
6442  while( iPtr < ucNumEdge )
6443  {
6444    ucCode = pucEdgeCode[iPtr++];
6445
6446    Int iNewDir = tableDir[iDir][ucCode];
6447
6448    switch( iNewDir )
6449    {
6450    case 0: // left
6451      iDiffX = -1;
6452      iDiffY = 0;
6453      break;
6454    case 1: // right
6455      iDiffX = +1;
6456      iDiffY = 0;
6457      break;
6458    case 2: // top
6459      iDiffX = 0;
6460      iDiffY = -1;
6461      break;
6462    case 3: // bottom
6463      iDiffX = 0;
6464      iDiffY = +1;
6465      break;
6466    case 4: // left-top
6467      iDiffX = -1;
6468      iDiffY = -1;
6469      break;
6470    case 5: // right-top
6471      iDiffX = +1;
6472      iDiffY = -1;
6473      break;
6474    case 6: // left-bottom
6475      iDiffX = -1;
6476      iDiffY = +1;
6477      break;
6478    case 7: // right-bottom
6479      iDiffX = +1;
6480      iDiffY = +1;
6481      break;
6482    }
6483
6484    switch( iDir )
6485    {
6486    case 0: // left
6487      switch( ucCode )
6488      {
6489      case 0:
6490      case 2:
6491        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
6492        break;
6493      case 1:
6494      case 3:
6495        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
6496        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
6497        break;
6498      case 4:
6499      case 6:
6500        // no
6501        break;
6502      case 5:
6503        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
6504        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
6505        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
6506        break;
6507      }
6508      break;
6509    case 1: // right
6510      switch( ucCode )
6511      {
6512      case 0:
6513      case 2:
6514        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
6515        break;
6516      case 1:
6517      case 3:
6518        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
6519        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
6520        break;
6521      case 4:
6522      case 6:
6523        // no
6524        break;
6525      case 5:
6526        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
6527        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
6528        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
6529        break;
6530      }
6531      break;
6532    case 2: // top
6533      switch( ucCode )
6534      {
6535      case 0:
6536      case 2:
6537        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
6538        break;
6539      case 1:
6540      case 3:
6541        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
6542        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
6543        break;
6544      case 4:
6545      case 6:
6546        // no
6547        break;
6548      case 5:
6549        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
6550        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
6551        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
6552        break;
6553      }
6554      break;
6555    case 3: // bottom
6556      switch( ucCode )
6557      {
6558      case 0:
6559      case 2:
6560        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
6561        break;
6562      case 1:
6563      case 3:
6564        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
6565        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
6566        break;
6567      case 4:
6568      case 6:
6569        // no
6570        break;
6571      case 5:
6572        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
6573        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
6574        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
6575        break;
6576      }
6577      break;
6578    case 4: // left-top
6579      switch( ucCode )
6580      {
6581      case 0:
6582      case 1:
6583        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
6584        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
6585        break;
6586      case 2:
6587      case 4:
6588        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
6589        break;
6590      case 3:
6591      case 5:
6592        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
6593        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
6594        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
6595        break;
6596      case 6:
6597        // no
6598        break;
6599      }
6600      break;
6601    case 5: // right-top
6602      switch( ucCode )
6603      {
6604      case 0:
6605      case 1:
6606        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
6607        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
6608        break;
6609      case 2:
6610      case 4:
6611        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
6612        break;
6613      case 3:
6614      case 5:
6615        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
6616        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
6617        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
6618        break;
6619      case 6:
6620        // no
6621        break;
6622      }
6623      break;
6624    case 6: // left-bottom
6625      switch( ucCode )
6626      {
6627      case 0:
6628      case 1:
6629        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
6630        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
6631        break;
6632      case 2:
6633      case 4:
6634        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
6635        break;
6636      case 3:
6637      case 5:
6638        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
6639        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
6640        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
6641        break;
6642      case 6:
6643        // no
6644        break;
6645      }
6646      break;
6647    case 7: // right-bottom
6648      switch( ucCode )
6649      {
6650      case 0:
6651      case 1:
6652        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
6653        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
6654        break;
6655      case 2:
6656      case 4:
6657        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
6658        break;
6659      case 3:
6660      case 5:
6661        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
6662        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
6663        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
6664        break;
6665      case 6:
6666        // no
6667        break;
6668      }
6669      break;
6670    }
6671
6672    assert( iX >= 0 && iX <= iWidth );
6673    assert( iY >= 0 && iY <= iHeight );
6674
6675    iX += iDiffX;
6676    iY += iDiffY;
6677    iDir = iNewDir;
6678  }
6679
6680  // finalize edge chain
6681  if( iX == iWidth-1 )
6682  {
6683    if( iY == 0 )
6684    {
6685      if( iDir == 1 )
6686      {
6687        pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
6688      }
6689      else if( iDir == 5 )
6690      {
6691        pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
6692      }
6693      else
6694      {
6695        assert(false);
6696      }
6697    }
6698    else if( iY == iHeight-1 )
6699    {
6700      if( iDir == 3 )
6701      {
6702        pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
6703      }
6704      else if( iDir == 7 )
6705      {
6706        pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
6707      }
6708      else
6709      {
6710        assert(false);
6711      }
6712    }
6713    else
6714    {
6715      if( iDir == 1 )
6716      {
6717        pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
6718      }
6719      else if( iDir == 3 )
6720      {
6721        pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
6722        pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
6723      }
6724      else if( iDir == 5 )
6725      {
6726        pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
6727      }
6728      else if( iDir == 7 )
6729      {
6730        pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
6731        pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
6732      }
6733      else
6734      {
6735        assert(false);
6736      }
6737    }
6738  }
6739  else if( iX == 0 )
6740  {
6741    if( iY == 0 )
6742    {
6743      if( iDir == 2 )
6744      {
6745        pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
6746      }
6747      else if( iDir == 4 )
6748      {
6749        pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
6750      }
6751      else
6752      {
6753        assert(false);
6754      }
6755    }
6756    else if( iY == iHeight-1 )
6757    {
6758      if( iDir == 0 )
6759      {
6760        pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
6761      }
6762      else if( iDir == 6 )
6763      {
6764        pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
6765      }
6766      else
6767      {
6768        assert(false);
6769      }
6770    }
6771    else
6772    {
6773      if( iDir == 0 )
6774      {
6775        pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
6776      }
6777      else if( iDir == 2 )
6778      {
6779        pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
6780        pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
6781      }
6782      else if( iDir == 4 )
6783      {
6784        pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
6785        pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
6786      }
6787      else if( iDir == 6 )
6788      {
6789        pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
6790      }
6791      else
6792      {
6793        assert(false);
6794      }
6795    }
6796  }
6797  else if( iY == 0 )
6798  {
6799    if( iDir == 1 )
6800    {
6801      pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
6802      pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
6803    }
6804    else if( iDir == 2 )
6805    {
6806      pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
6807    }
6808    else if( iDir == 4 )
6809    {
6810      pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
6811    }
6812    else if( iDir == 5 )
6813    {
6814      pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
6815      pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
6816    }
6817    else
6818    {
6819      assert(false);
6820    }
6821  }
6822  else if( iY == iHeight-1 )
6823  {
6824    if( iDir == 0 )
6825    {
6826      pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
6827      pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
6828    }
6829    else if( iDir == 3 )
6830    {
6831      pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
6832    }
6833    else if( iDir == 6 )
6834    {
6835      pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
6836      pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
6837    }
6838    else if( iDir == 7 )
6839    {
6840      pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
6841    }
6842    else
6843    {
6844      assert(false);
6845    }
6846  }
6847  else
6848  {
6849    printf("reconPartiton: wrong termination\n");
6850    assert(false);
6851  }
6852
6853  // Reconstruct Region from Chain Code
6854  Bool* pbVisit  = (Bool*) xMalloc( Bool, iWidth * iHeight );
6855  Int*  piStack  = (Int* ) xMalloc( Int,  iWidth * iHeight );
6856
6857  for( UInt ui = 0; ui < iWidth * iHeight; ui++ )
6858  {
6859    pbRegion[ ui ] = true; // fill it as region 1 (we'll discover region 0 next)
6860    pbVisit [ ui ] = false;
6861  }
6862
6863  iPtr = 0;
6864  piStack[iPtr++] = (0 << 8) | (0);
6865  pbRegion[ 0 ] = false;
6866
6867  while(iPtr > 0)
6868  {
6869    Int iTmp = piStack[--iPtr];
6870    Int iX1, iY1;
6871    iX1 = iTmp & 0xff;
6872    iY1 = (iTmp >> 8) & 0xff;
6873
6874    pbVisit[ iX1 + iY1 * iWidth ] = true;
6875
6876    assert( iX1 >= 0 && iX1 < iWidth );
6877    assert( iY1 >= 0 && iY1 < iHeight );
6878
6879    if( iX1 > 0 && !pbEdge[ 2 * iX1 - 1 + 4 * iY1 * iWidth ] && !pbVisit[ iX1 - 1 + iY1 * iWidth ] )
6880    {
6881      piStack[iPtr++] = (iY1 << 8) | (iX1 - 1);
6882      pbRegion[ iX1 - 1 + iY1 * iWidth ] = false;
6883    }
6884    if( iX1 < iWidth - 1 && !pbEdge[ 2 * iX1 + 1 + 4 * iY1 * iWidth ] && !pbVisit[ iX1 + 1 + iY1 * iWidth ] )
6885    {
6886      piStack[iPtr++] = (iY1 << 8) | (iX1 + 1);
6887      pbRegion[ iX1 + 1 + iY1 * iWidth ] = false;
6888    }
6889    if( iY1 > 0 && !pbEdge[ 2 * iX1 + 2 * (2 * iY1 - 1) * iWidth ] && !pbVisit[ iX1 + (iY1 - 1) * iWidth ] )
6890    {
6891      piStack[iPtr++] = ((iY1 - 1) << 8) | iX1;
6892      pbRegion[ iX1 + (iY1 - 1) * iWidth ] = false;
6893    }
6894    if( iY1 < iHeight - 1 && !pbEdge[ 2 * iX1 + 2 * (2 * iY1 + 1) * iWidth ] && !pbVisit[ iX1 + (iY1 + 1) * iWidth ] )
6895    {
6896      piStack[iPtr++] = ((iY1 + 1) << 8) | iX1;
6897      pbRegion[ iX1 + (iY1 + 1) * iWidth ] = false;
6898    }
6899  }
6900
6901  xFree( pbEdge );
6902  xFree( pbVisit );
6903  xFree( piStack );
6904}
6905#endif
6906
6907
6908//! \}
Note: See TracBrowser for help on using the repository browser.