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

Last change on this file since 1417 was 655, checked in by tech, 11 years ago

Merged 8.1-Cleanup@654

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