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

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

MergeMerged tags/HTM-DEV-1.0.

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