source: 3DVCSoftware/branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComDataCU.cpp @ 542

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

Further removal of unused macros.

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