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

Last change on this file since 467 was 467, checked in by rwth, 13 years ago

Integration of depth intra methods in macro H_3D_DIM, including:

  • Simplified Depth Coding (SDC) in H_3D_DIM_SDC
  • Depth Lookup Table (DLT) in H_3D_DIM_DLT
  • Property svn:eol-style set to native
File size: 170.7 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license. 
5 *
6 * Copyright (c) 2010-2013, ITU/ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/** \file     TComDataCU.cpp
35    \brief    CU data structure
36    \todo     not all entities are documented
37*/
38
39#include "TComDataCU.h"
40#include "TComPic.h"
41
42//! \ingroup TLibCommon
43//! \{
44
45#if ADAPTIVE_QP_SELECTION
46Int * TComDataCU::m_pcGlbArlCoeffY  = NULL;
47Int * TComDataCU::m_pcGlbArlCoeffCb = NULL;
48Int * TComDataCU::m_pcGlbArlCoeffCr = NULL;
49#endif
50
51// ====================================================================================================================
52// Constructor / destructor / create / destroy
53// ====================================================================================================================
54
55TComDataCU::TComDataCU()
56{
57  m_pcPic              = NULL;
58  m_pcSlice            = NULL;
59  m_puhDepth           = NULL;
60 
61  m_skipFlag           = NULL;
62
63  m_pePartSize         = NULL;
64  m_pePredMode         = NULL;
65  m_CUTransquantBypass = NULL;
66  m_puhWidth           = NULL;
67  m_puhHeight          = NULL;
68  m_phQP               = NULL;
69  m_pbMergeFlag        = NULL;
70  m_puhMergeIndex      = NULL;
71  m_puhLumaIntraDir    = NULL;
72  m_puhChromaIntraDir  = NULL;
73  m_puhInterDir        = NULL;
74  m_puhTrIdx           = NULL;
75  m_puhTransformSkip[0] = NULL;
76  m_puhTransformSkip[1] = NULL;
77  m_puhTransformSkip[2] = NULL;
78  m_puhCbf[0]          = NULL;
79  m_puhCbf[1]          = NULL;
80  m_puhCbf[2]          = NULL;
81  m_pcTrCoeffY         = NULL;
82  m_pcTrCoeffCb        = NULL;
83  m_pcTrCoeffCr        = NULL;
84#if ADAPTIVE_QP_SELECTION 
85  m_ArlCoeffIsAliasedAllocation = false;
86  m_pcArlCoeffY        = NULL;
87  m_pcArlCoeffCb       = NULL;
88  m_pcArlCoeffCr       = NULL;
89#endif
90 
91  m_pbIPCMFlag         = NULL;
92  m_pcIPCMSampleY      = NULL;
93  m_pcIPCMSampleCb     = NULL;
94  m_pcIPCMSampleCr     = NULL;
95
96  m_pcPattern          = NULL;
97 
98  m_pcCUAboveLeft      = NULL;
99  m_pcCUAboveRight     = NULL;
100  m_pcCUAbove          = NULL;
101  m_pcCULeft           = NULL;
102 
103  m_apcCUColocated[0]  = NULL;
104  m_apcCUColocated[1]  = NULL;
105 
106  m_apiMVPIdx[0]       = NULL;
107  m_apiMVPIdx[1]       = NULL;
108  m_apiMVPNum[0]       = NULL;
109  m_apiMVPNum[1]       = NULL;
110
111#if H_3D_DIM
112  for( Int i = 0; i < DIM_NUM_TYPE; i++ )
113  {
114    m_dimDeltaDC[i][0] = NULL; 
115    m_dimDeltaDC[i][1] = NULL;
116  }
117#if H_3D_DIM_DMM
118  for( Int i = 0; i < DMM_NUM_TYPE; i++ )
119  {
120    m_dmmWedgeTabIdx[i] = NULL;
121  }
122  m_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}
143
144TComDataCU::~TComDataCU()
145{
146}
147
148Void TComDataCU::create(UInt uiNumPartition, UInt uiWidth, UInt uiHeight, Bool bDecSubCu, Int unitSize
149#if ADAPTIVE_QP_SELECTION
150                        , Bool bGlobalRMARLBuffer
151#endif                                             
152                        )
153{
154  m_bDecSubCu = bDecSubCu;
155 
156  m_pcPic              = NULL;
157  m_pcSlice            = NULL;
158  m_uiNumPartition     = uiNumPartition;
159  m_unitSize = unitSize;
160 
161  if ( !bDecSubCu )
162  {
163    m_phQP               = (Char*     )xMalloc(Char,     uiNumPartition);
164    m_puhDepth           = (UChar*    )xMalloc(UChar,    uiNumPartition);
165    m_puhWidth           = (UChar*    )xMalloc(UChar,    uiNumPartition);
166    m_puhHeight          = (UChar*    )xMalloc(UChar,    uiNumPartition);
167
168    m_skipFlag           = new Bool[ uiNumPartition ];
169
170    m_pePartSize         = new Char[ uiNumPartition ];
171    memset( m_pePartSize, SIZE_NONE,uiNumPartition * sizeof( *m_pePartSize ) );
172    m_pePredMode         = new Char[ uiNumPartition ];
173    m_CUTransquantBypass = new Bool[ uiNumPartition ];
174    m_pbMergeFlag        = (Bool*  )xMalloc(Bool,   uiNumPartition);
175    m_puhMergeIndex      = (UChar* )xMalloc(UChar,  uiNumPartition);
176    m_puhLumaIntraDir    = (UChar* )xMalloc(UChar,  uiNumPartition);
177    m_puhChromaIntraDir  = (UChar* )xMalloc(UChar,  uiNumPartition);
178    m_puhInterDir        = (UChar* )xMalloc(UChar,  uiNumPartition);
179   
180    m_puhTrIdx           = (UChar* )xMalloc(UChar,  uiNumPartition);
181    m_puhTransformSkip[0] = (UChar* )xMalloc(UChar,  uiNumPartition);
182    m_puhTransformSkip[1] = (UChar* )xMalloc(UChar,  uiNumPartition);
183    m_puhTransformSkip[2] = (UChar* )xMalloc(UChar,  uiNumPartition);
184
185    m_puhCbf[0]          = (UChar* )xMalloc(UChar,  uiNumPartition);
186    m_puhCbf[1]          = (UChar* )xMalloc(UChar,  uiNumPartition);
187    m_puhCbf[2]          = (UChar* )xMalloc(UChar,  uiNumPartition);
188   
189    m_apiMVPIdx[0]       = new Char[ uiNumPartition ];
190    m_apiMVPIdx[1]       = new Char[ uiNumPartition ];
191    m_apiMVPNum[0]       = new Char[ uiNumPartition ];
192    m_apiMVPNum[1]       = new Char[ uiNumPartition ];
193    memset( m_apiMVPIdx[0], -1,uiNumPartition * sizeof( Char ) );
194    memset( m_apiMVPIdx[1], -1,uiNumPartition * sizeof( Char ) );
195   
196    m_pcTrCoeffY         = (TCoeff*)xMalloc(TCoeff, uiWidth*uiHeight);
197    m_pcTrCoeffCb        = (TCoeff*)xMalloc(TCoeff, uiWidth*uiHeight/4);
198    m_pcTrCoeffCr        = (TCoeff*)xMalloc(TCoeff, uiWidth*uiHeight/4);
199    memset( m_pcTrCoeffY, 0,uiWidth*uiHeight * sizeof( TCoeff ) );
200    memset( m_pcTrCoeffCb, 0,uiWidth*uiHeight/4 * sizeof( TCoeff ) );
201    memset( m_pcTrCoeffCr, 0,uiWidth*uiHeight/4 * sizeof( TCoeff ) );
202#if ADAPTIVE_QP_SELECTION   
203    if( bGlobalRMARLBuffer )
204    {
205      if( m_pcGlbArlCoeffY == NULL )
206      {
207        m_pcGlbArlCoeffY   = (Int*)xMalloc(Int, uiWidth*uiHeight);
208        m_pcGlbArlCoeffCb  = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
209        m_pcGlbArlCoeffCr  = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
210      }
211      m_pcArlCoeffY        = m_pcGlbArlCoeffY;
212      m_pcArlCoeffCb       = m_pcGlbArlCoeffCb;
213      m_pcArlCoeffCr       = m_pcGlbArlCoeffCr;
214      m_ArlCoeffIsAliasedAllocation = true;
215    }
216    else
217    {
218      m_pcArlCoeffY        = (Int*)xMalloc(Int, uiWidth*uiHeight);
219      m_pcArlCoeffCb       = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
220      m_pcArlCoeffCr       = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
221    }
222#endif
223   
224    m_pbIPCMFlag         = (Bool*  )xMalloc(Bool, uiNumPartition);
225    m_pcIPCMSampleY      = (Pel*   )xMalloc(Pel , uiWidth*uiHeight);
226    m_pcIPCMSampleCb     = (Pel*   )xMalloc(Pel , uiWidth*uiHeight/4);
227    m_pcIPCMSampleCr     = (Pel*   )xMalloc(Pel , uiWidth*uiHeight/4);
228
229    m_acCUMvField[0].create( uiNumPartition );
230    m_acCUMvField[1].create( uiNumPartition );
231   
232#if H_3D_DIM
233    for( Int i = 0; i < DIM_NUM_TYPE; i++ )
234    {
235      m_dimDeltaDC[i][0] = (Pel* )xMalloc(Pel, uiNumPartition); 
236      m_dimDeltaDC[i][1] = (Pel* )xMalloc(Pel, uiNumPartition);
237    }
238#if H_3D_DIM_DMM
239    for( Int i = 0; i < DMM_NUM_TYPE; i++ )
240    {
241      m_dmmWedgeTabIdx[i]    = (UInt*)xMalloc(UInt, uiNumPartition);
242    }
243    m_dmm2DeltaEnd    = (Int* )xMalloc(Int,  uiNumPartition);
244    m_dmm3IntraTabIdx = (UInt*)xMalloc(UInt, uiNumPartition);
245#endif
246#if H_3D_DIM_RBC
247    m_pucEdgeCode     = (UChar*)xMalloc(UChar, uiNumPartition * RBC_MAX_EDGE_NUM_PER_4x4);
248    m_pucEdgeNumber   = (UChar*)xMalloc(UChar, uiNumPartition);
249    m_pucEdgeStartPos = (UChar*)xMalloc(UChar, uiNumPartition);
250    m_pbEdgeLeftFirst = (Bool*)xMalloc(Bool, uiNumPartition);
251    m_pbEdgePartition = (Bool*)xMalloc(Bool, uiNumPartition * 16);
252#endif
253#if H_3D_DIM_SDC
254    m_pbSDCFlag             = (Bool*)xMalloc(Bool, uiNumPartition);
255    m_apSegmentDCOffset[0]  = (Pel*)xMalloc(Pel, uiNumPartition);
256    m_apSegmentDCOffset[1]  = (Pel*)xMalloc(Pel, uiNumPartition);
257#endif
258#endif
259  }
260  else
261  {
262    m_acCUMvField[0].setNumPartition(uiNumPartition );
263    m_acCUMvField[1].setNumPartition(uiNumPartition );
264  }
265 
266  m_sliceStartCU        = (UInt*  )xMalloc(UInt, uiNumPartition);
267  m_sliceSegmentStartCU = (UInt*  )xMalloc(UInt, uiNumPartition);
268 
269  // create pattern memory
270  m_pcPattern            = (TComPattern*)xMalloc(TComPattern, 1);
271 
272  // create motion vector fields
273 
274  m_pcCUAboveLeft      = NULL;
275  m_pcCUAboveRight     = NULL;
276  m_pcCUAbove          = NULL;
277  m_pcCULeft           = NULL;
278 
279  m_apcCUColocated[0]  = NULL;
280  m_apcCUColocated[1]  = NULL;
281}
282
283Void TComDataCU::destroy()
284{
285  m_pcPic              = NULL;
286  m_pcSlice            = NULL;
287 
288  if ( m_pcPattern )
289  { 
290    xFree(m_pcPattern);
291    m_pcPattern = NULL;
292  }
293 
294  // encoder-side buffer free
295  if ( !m_bDecSubCu )
296  {
297    if ( m_phQP               ) { xFree(m_phQP);                m_phQP              = NULL; }
298    if ( m_puhDepth           ) { xFree(m_puhDepth);            m_puhDepth          = NULL; }
299    if ( m_puhWidth           ) { xFree(m_puhWidth);            m_puhWidth          = NULL; }
300    if ( m_puhHeight          ) { xFree(m_puhHeight);           m_puhHeight         = NULL; }
301
302    if ( m_skipFlag           ) { delete[] m_skipFlag;          m_skipFlag          = NULL; }
303
304    if ( m_pePartSize         ) { delete[] m_pePartSize;        m_pePartSize        = NULL; }
305    if ( m_pePredMode         ) { delete[] m_pePredMode;        m_pePredMode        = NULL; }
306    if ( m_CUTransquantBypass ) { delete[] m_CUTransquantBypass;m_CUTransquantBypass = NULL; }
307    if ( m_puhCbf[0]          ) { xFree(m_puhCbf[0]);           m_puhCbf[0]         = NULL; }
308    if ( m_puhCbf[1]          ) { xFree(m_puhCbf[1]);           m_puhCbf[1]         = NULL; }
309    if ( m_puhCbf[2]          ) { xFree(m_puhCbf[2]);           m_puhCbf[2]         = NULL; }
310    if ( m_puhInterDir        ) { xFree(m_puhInterDir);         m_puhInterDir       = NULL; }
311    if ( m_pbMergeFlag        ) { xFree(m_pbMergeFlag);         m_pbMergeFlag       = NULL; }
312    if ( m_puhMergeIndex      ) { xFree(m_puhMergeIndex);       m_puhMergeIndex     = NULL; }
313    if ( m_puhLumaIntraDir    ) { xFree(m_puhLumaIntraDir);     m_puhLumaIntraDir   = NULL; }
314    if ( m_puhChromaIntraDir  ) { xFree(m_puhChromaIntraDir);   m_puhChromaIntraDir = NULL; }
315    if ( m_puhTrIdx           ) { xFree(m_puhTrIdx);            m_puhTrIdx          = NULL; }
316    if ( m_puhTransformSkip[0]) { xFree(m_puhTransformSkip[0]); m_puhTransformSkip[0] = NULL; }
317    if ( m_puhTransformSkip[1]) { xFree(m_puhTransformSkip[1]); m_puhTransformSkip[1] = NULL; }
318    if ( m_puhTransformSkip[2]) { xFree(m_puhTransformSkip[2]); m_puhTransformSkip[2] = NULL; }
319    if ( m_pcTrCoeffY         ) { xFree(m_pcTrCoeffY);          m_pcTrCoeffY        = NULL; }
320    if ( m_pcTrCoeffCb        ) { xFree(m_pcTrCoeffCb);         m_pcTrCoeffCb       = NULL; }
321    if ( m_pcTrCoeffCr        ) { xFree(m_pcTrCoeffCr);         m_pcTrCoeffCr       = NULL; }
322#if ADAPTIVE_QP_SELECTION
323    if (!m_ArlCoeffIsAliasedAllocation)
324    {
325      xFree(m_pcArlCoeffY); m_pcArlCoeffY = 0;
326      xFree(m_pcArlCoeffCb); m_pcArlCoeffCb = 0;
327      xFree(m_pcArlCoeffCr); m_pcArlCoeffCr = 0;
328    }
329    if ( m_pcGlbArlCoeffY     ) { xFree(m_pcGlbArlCoeffY);      m_pcGlbArlCoeffY    = NULL; }
330    if ( m_pcGlbArlCoeffCb    ) { xFree(m_pcGlbArlCoeffCb);     m_pcGlbArlCoeffCb   = NULL; }
331    if ( m_pcGlbArlCoeffCr    ) { xFree(m_pcGlbArlCoeffCr);     m_pcGlbArlCoeffCr   = NULL; }
332#endif
333    if ( m_pbIPCMFlag         ) { xFree(m_pbIPCMFlag   );       m_pbIPCMFlag        = NULL; }
334    if ( m_pcIPCMSampleY      ) { xFree(m_pcIPCMSampleY);       m_pcIPCMSampleY     = NULL; }
335    if ( m_pcIPCMSampleCb     ) { xFree(m_pcIPCMSampleCb);      m_pcIPCMSampleCb    = NULL; }
336    if ( m_pcIPCMSampleCr     ) { xFree(m_pcIPCMSampleCr);      m_pcIPCMSampleCr    = NULL; }
337    if ( m_apiMVPIdx[0]       ) { delete[] m_apiMVPIdx[0];      m_apiMVPIdx[0]      = NULL; }
338    if ( m_apiMVPIdx[1]       ) { delete[] m_apiMVPIdx[1];      m_apiMVPIdx[1]      = NULL; }
339    if ( m_apiMVPNum[0]       ) { delete[] m_apiMVPNum[0];      m_apiMVPNum[0]      = NULL; }
340    if ( m_apiMVPNum[1]       ) { delete[] m_apiMVPNum[1];      m_apiMVPNum[1]      = NULL; }
341   
342    m_acCUMvField[0].destroy();
343    m_acCUMvField[1].destroy();
344   
345#if H_3D_DIM
346    for( Int i = 0; i < DIM_NUM_TYPE; i++ )
347    {
348      if ( m_dimDeltaDC[i][0] ) { xFree( m_dimDeltaDC[i][0] ); m_dimDeltaDC[i][0] = NULL; }
349      if ( m_dimDeltaDC[i][1] ) { xFree( m_dimDeltaDC[i][1] ); m_dimDeltaDC[i][1] = NULL; }
350    }
351#if H_3D_DIM_DMM
352    for( Int i = 0; i < DMM_NUM_TYPE; i++ )
353    {
354      if ( m_dmmWedgeTabIdx[i] ) { xFree( m_dmmWedgeTabIdx[i] ); m_dmmWedgeTabIdx[i] = NULL; }
355    }
356    if ( m_dmm2DeltaEnd    ) { xFree( m_dmm2DeltaEnd    ); m_dmm2DeltaEnd    = NULL; }
357    if ( m_dmm3IntraTabIdx ) { xFree( m_dmm3IntraTabIdx ); m_dmm3IntraTabIdx = NULL; }
358#endif
359#if H_3D_DIM_RBC
360    if ( m_pbEdgeLeftFirst ) { xFree( m_pbEdgeLeftFirst ); m_pbEdgeLeftFirst = NULL; }
361    if ( m_pucEdgeStartPos ) { xFree( m_pucEdgeStartPos ); m_pucEdgeStartPos = NULL; }
362    if ( m_pucEdgeNumber   ) { xFree( m_pucEdgeNumber   ); m_pucEdgeNumber   = NULL; }
363    if ( m_pucEdgeCode     ) { xFree( m_pucEdgeCode     ); m_pucEdgeCode     = NULL; }
364    if ( m_pbEdgePartition ) { xFree( m_pbEdgePartition ); m_pbEdgePartition = NULL; }
365#endif
366#if H_3D_DIM_SDC
367    if ( m_pbSDCFlag            ) { xFree(m_pbSDCFlag);             m_pbSDCFlag             = NULL; }
368    if ( m_apSegmentDCOffset[0] ) { xFree(m_apSegmentDCOffset[0]);  m_apSegmentDCOffset[0]  = NULL; }
369    if ( m_apSegmentDCOffset[1] ) { xFree(m_apSegmentDCOffset[1]);  m_apSegmentDCOffset[1]  = NULL; }
370#endif
371#endif
372  }
373 
374  m_pcCUAboveLeft       = NULL;
375  m_pcCUAboveRight      = NULL;
376  m_pcCUAbove           = NULL;
377  m_pcCULeft            = NULL;
378 
379  m_apcCUColocated[0]   = NULL;
380  m_apcCUColocated[1]   = NULL;
381
382  if( m_sliceStartCU )
383  {
384    xFree(m_sliceStartCU);
385    m_sliceStartCU=NULL;
386  }
387  if(m_sliceSegmentStartCU )
388  {
389    xFree(m_sliceSegmentStartCU);
390    m_sliceSegmentStartCU=NULL;
391  }
392}
393
394const NDBFBlockInfo& NDBFBlockInfo::operator= (const NDBFBlockInfo& src)
395{
396  this->tileID = src.tileID;
397  this->sliceID= src.sliceID;
398  this->startSU= src.startSU;
399  this->endSU  = src.endSU;
400  this->widthSU= src.widthSU;
401  this->heightSU=src.heightSU;
402  this->posX   = src.posX;
403  this->posY   = src.posY;
404  this->width  = src.width;
405  this->height = src.height;
406  ::memcpy(this->isBorderAvailable, src.isBorderAvailable, sizeof(Bool)*((Int)NUM_SGU_BORDER));
407  this->allBordersAvailable = src.allBordersAvailable;
408
409  return *this;
410}
411
412
413// ====================================================================================================================
414// Public member functions
415// ====================================================================================================================
416
417// --------------------------------------------------------------------------------------------------------------------
418// Initialization
419// --------------------------------------------------------------------------------------------------------------------
420
421/**
422 - initialize top-level CU
423 - internal buffers are already created
424 - set values before encoding a CU
425 .
426 \param  pcPic     picture (TComPic) class pointer
427 \param  iCUAddr   CU address
428 */
429Void TComDataCU::initCU( TComPic* pcPic, UInt iCUAddr )
430{
431
432  m_pcPic              = pcPic;
433  m_pcSlice            = pcPic->getSlice(pcPic->getCurrSliceIdx());
434  m_uiCUAddr           = iCUAddr;
435  m_uiCUPelX           = ( iCUAddr % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth;
436  m_uiCUPelY           = ( iCUAddr / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight;
437  m_uiAbsIdxInLCU      = 0;
438  m_dTotalCost         = MAX_DOUBLE;
439  m_uiTotalDistortion  = 0;
440  m_uiTotalBits        = 0;
441  m_uiTotalBins        = 0;
442  m_uiNumPartition     = pcPic->getNumPartInCU();
443 
444  for(Int i=0; i<pcPic->getNumPartInCU(); i++)
445  {
446    if(pcPic->getPicSym()->getInverseCUOrderMap(iCUAddr)*pcPic->getNumPartInCU()+i>=getSlice()->getSliceCurStartCUAddr())
447    {
448      m_sliceStartCU[i]=getSlice()->getSliceCurStartCUAddr();
449    }
450    else
451    {
452      m_sliceStartCU[i]=pcPic->getCU(getAddr())->m_sliceStartCU[i];
453    }
454  }
455  for(Int i=0; i<pcPic->getNumPartInCU(); i++)
456  {
457    if(pcPic->getPicSym()->getInverseCUOrderMap(iCUAddr)*pcPic->getNumPartInCU()+i>=getSlice()->getSliceSegmentCurStartCUAddr())
458    {
459      m_sliceSegmentStartCU[i]=getSlice()->getSliceSegmentCurStartCUAddr();
460    }
461    else
462    {
463      m_sliceSegmentStartCU[i]=pcPic->getCU(getAddr())->m_sliceSegmentStartCU[i];
464    }
465  }
466
467  Int partStartIdx = getSlice()->getSliceSegmentCurStartCUAddr() - pcPic->getPicSym()->getInverseCUOrderMap(iCUAddr) * pcPic->getNumPartInCU();
468
469  Int numElements = min<Int>( partStartIdx, m_uiNumPartition );
470  for ( Int ui = 0; ui < numElements; ui++ )
471  {
472    TComDataCU * pcFrom = pcPic->getCU(getAddr());
473    m_skipFlag[ui]   = pcFrom->getSkipFlag(ui);
474    m_pePartSize[ui] = pcFrom->getPartitionSize(ui);
475    m_pePredMode[ui] = pcFrom->getPredictionMode(ui);
476    m_CUTransquantBypass[ui] = pcFrom->getCUTransquantBypass(ui);
477    m_puhDepth[ui] = pcFrom->getDepth(ui);
478    m_puhWidth  [ui] = pcFrom->getWidth(ui);
479    m_puhHeight [ui] = pcFrom->getHeight(ui);
480    m_puhTrIdx  [ui] = pcFrom->getTransformIdx(ui);
481    m_puhTransformSkip[0][ui] = pcFrom->getTransformSkip(ui,TEXT_LUMA);
482    m_puhTransformSkip[1][ui] = pcFrom->getTransformSkip(ui,TEXT_CHROMA_U);
483    m_puhTransformSkip[2][ui] = pcFrom->getTransformSkip(ui,TEXT_CHROMA_V);
484    m_apiMVPIdx[0][ui] = pcFrom->m_apiMVPIdx[0][ui];;
485    m_apiMVPIdx[1][ui] = pcFrom->m_apiMVPIdx[1][ui];
486    m_apiMVPNum[0][ui] = pcFrom->m_apiMVPNum[0][ui];
487    m_apiMVPNum[1][ui] = pcFrom->m_apiMVPNum[1][ui];
488    m_phQP[ui]=pcFrom->m_phQP[ui];
489    m_pbMergeFlag[ui]=pcFrom->m_pbMergeFlag[ui];
490    m_puhMergeIndex[ui]=pcFrom->m_puhMergeIndex[ui];
491    m_puhLumaIntraDir[ui]=pcFrom->m_puhLumaIntraDir[ui];
492    m_puhChromaIntraDir[ui]=pcFrom->m_puhChromaIntraDir[ui];
493    m_puhInterDir[ui]=pcFrom->m_puhInterDir[ui];
494    m_puhCbf[0][ui]=pcFrom->m_puhCbf[0][ui];
495    m_puhCbf[1][ui]=pcFrom->m_puhCbf[1][ui];
496    m_puhCbf[2][ui]=pcFrom->m_puhCbf[2][ui];
497    m_pbIPCMFlag[ui] = pcFrom->m_pbIPCMFlag[ui];
498#if H_3D_DIM_SDC
499    m_pbSDCFlag[ui] = pcFrom->m_pbSDCFlag[ui];
500#endif
501  }
502 
503  Int firstElement = max<Int>( partStartIdx, 0 );
504  numElements = m_uiNumPartition - firstElement;
505 
506  if ( numElements > 0 )
507  {
508    memset( m_skipFlag          + firstElement, false,                    numElements * sizeof( *m_skipFlag ) );
509
510    memset( m_pePartSize        + firstElement, SIZE_NONE,                numElements * sizeof( *m_pePartSize ) );
511    memset( m_pePredMode        + firstElement, MODE_NONE,                numElements * sizeof( *m_pePredMode ) );
512    memset( m_CUTransquantBypass+ firstElement, false,                    numElements * sizeof( *m_CUTransquantBypass) );
513    memset( m_puhDepth          + firstElement, 0,                        numElements * sizeof( *m_puhDepth ) );
514    memset( m_puhTrIdx          + firstElement, 0,                        numElements * sizeof( *m_puhTrIdx ) );
515    memset( m_puhTransformSkip[0] + firstElement, 0,                      numElements * sizeof( *m_puhTransformSkip[0]) );
516    memset( m_puhTransformSkip[1] + firstElement, 0,                      numElements * sizeof( *m_puhTransformSkip[1]) );
517    memset( m_puhTransformSkip[2] + firstElement, 0,                      numElements * sizeof( *m_puhTransformSkip[2]) );
518    memset( m_puhWidth          + firstElement, g_uiMaxCUWidth,           numElements * sizeof( *m_puhWidth ) );
519    memset( m_puhHeight         + firstElement, g_uiMaxCUHeight,          numElements * sizeof( *m_puhHeight ) );
520    memset( m_apiMVPIdx[0]      + firstElement, -1,                       numElements * sizeof( *m_apiMVPIdx[0] ) );
521    memset( m_apiMVPIdx[1]      + firstElement, -1,                       numElements * sizeof( *m_apiMVPIdx[1] ) );
522    memset( m_apiMVPNum[0]      + firstElement, -1,                       numElements * sizeof( *m_apiMVPNum[0] ) );
523    memset( m_apiMVPNum[1]      + firstElement, -1,                       numElements * sizeof( *m_apiMVPNum[1] ) );
524    memset( m_phQP              + firstElement, getSlice()->getSliceQp(), numElements * sizeof( *m_phQP ) );
525    memset( m_pbMergeFlag       + firstElement, false,                    numElements * sizeof( *m_pbMergeFlag ) );
526    memset( m_puhMergeIndex     + firstElement, 0,                        numElements * sizeof( *m_puhMergeIndex ) );
527    memset( m_puhLumaIntraDir   + firstElement, DC_IDX,                   numElements * sizeof( *m_puhLumaIntraDir ) );
528    memset( m_puhChromaIntraDir + firstElement, 0,                        numElements * sizeof( *m_puhChromaIntraDir ) );
529    memset( m_puhInterDir       + firstElement, 0,                        numElements * sizeof( *m_puhInterDir ) );
530    memset( m_puhCbf[0]         + firstElement, 0,                        numElements * sizeof( *m_puhCbf[0] ) );
531    memset( m_puhCbf[1]         + firstElement, 0,                        numElements * sizeof( *m_puhCbf[1] ) );
532    memset( m_puhCbf[2]         + firstElement, 0,                        numElements * sizeof( *m_puhCbf[2] ) );
533    memset( m_pbIPCMFlag        + firstElement, false,                    numElements * sizeof( *m_pbIPCMFlag ) );
534
535#if H_3D_DIM
536    for( Int i = 0; i < DIM_NUM_TYPE; i++ )
537    {
538      memset( m_dimDeltaDC[i][0] + firstElement, 0,                       numElements * sizeof( *m_dimDeltaDC[i][0] ) );
539      memset( m_dimDeltaDC[i][1] + firstElement, 0,                       numElements * sizeof( *m_dimDeltaDC[i][1] ) );
540    }
541#if H_3D_DIM_DMM
542    for( Int i = 0; i < DMM_NUM_TYPE; i++ )
543    {
544      memset( m_dmmWedgeTabIdx[i] + firstElement, 0,                      numElements * sizeof( *m_dmmWedgeTabIdx[i] ) );
545    }
546    memset( m_dmm2DeltaEnd      + firstElement, 0,                        numElements * sizeof( *m_dmm2DeltaEnd    ) );
547    memset( m_dmm3IntraTabIdx   + firstElement, 0,                        numElements * sizeof( *m_dmm3IntraTabIdx ) );
548#endif
549#if H_3D_DIM_RBC
550    memset( m_pucEdgeCode       + firstElement, 0,                        numElements * sizeof( *m_pucEdgeCode     ) * RBC_MAX_EDGE_NUM_PER_4x4 );
551    memset( m_pucEdgeNumber     + firstElement, 0,                        numElements * sizeof( *m_pucEdgeNumber   ) );
552    memset( m_pucEdgeStartPos   + firstElement, 0,                        numElements * sizeof( *m_pucEdgeStartPos ) );
553    memset( m_pbEdgeLeftFirst   + firstElement, false,                    numElements * sizeof( *m_pbEdgeLeftFirst ) );
554    memset( m_pbEdgePartition   + firstElement, false,                    numElements * sizeof( *m_pbEdgePartition ) * 16 );
555#endif
556#if H_3D_DIM_SDC
557    memset( m_pbSDCFlag             + firstElement,     0,                numElements * sizeof( *m_pbSDCFlag            ) );
558    memset( m_apSegmentDCOffset[0]  + firstElement,     0,                numElements * sizeof( *m_apSegmentDCOffset[0] ) );
559    memset( m_apSegmentDCOffset[1]  + firstElement,     0,                numElements * sizeof( *m_apSegmentDCOffset[1] ) );
560#endif
561#endif
562  }
563 
564  UInt uiTmp = g_uiMaxCUWidth*g_uiMaxCUHeight;
565  if ( 0 >= partStartIdx ) 
566  {
567    m_acCUMvField[0].clearMvField();
568    m_acCUMvField[1].clearMvField();
569    memset( m_pcTrCoeffY , 0, sizeof( TCoeff ) * uiTmp );
570#if ADAPTIVE_QP_SELECTION
571    memset( m_pcArlCoeffY , 0, sizeof( Int ) * uiTmp ); 
572#endif
573    memset( m_pcIPCMSampleY , 0, sizeof( Pel ) * uiTmp );
574    uiTmp  >>= 2;
575    memset( m_pcTrCoeffCb, 0, sizeof( TCoeff ) * uiTmp );
576    memset( m_pcTrCoeffCr, 0, sizeof( TCoeff ) * uiTmp );
577#if ADAPTIVE_QP_SELECTION 
578    memset( m_pcArlCoeffCb, 0, sizeof( Int ) * uiTmp );
579    memset( m_pcArlCoeffCr, 0, sizeof( Int ) * uiTmp );
580#endif
581    memset( m_pcIPCMSampleCb , 0, sizeof( Pel ) * uiTmp );
582    memset( m_pcIPCMSampleCr , 0, sizeof( Pel ) * uiTmp );
583  }
584  else 
585  {
586    TComDataCU * pcFrom = pcPic->getCU(getAddr());
587    m_acCUMvField[0].copyFrom(&pcFrom->m_acCUMvField[0],m_uiNumPartition,0);
588    m_acCUMvField[1].copyFrom(&pcFrom->m_acCUMvField[1],m_uiNumPartition,0);
589    for(Int i=0; i<uiTmp; i++)
590    {
591      m_pcTrCoeffY[i]=pcFrom->m_pcTrCoeffY[i];
592#if ADAPTIVE_QP_SELECTION
593      m_pcArlCoeffY[i]=pcFrom->m_pcArlCoeffY[i];
594#endif
595      m_pcIPCMSampleY[i]=pcFrom->m_pcIPCMSampleY[i];
596    }
597    for(Int i=0; i<(uiTmp>>2); i++)
598    {
599      m_pcTrCoeffCb[i]=pcFrom->m_pcTrCoeffCb[i];
600      m_pcTrCoeffCr[i]=pcFrom->m_pcTrCoeffCr[i];
601#if ADAPTIVE_QP_SELECTION
602      m_pcArlCoeffCb[i]=pcFrom->m_pcArlCoeffCb[i];
603      m_pcArlCoeffCr[i]=pcFrom->m_pcArlCoeffCr[i];
604#endif
605      m_pcIPCMSampleCb[i]=pcFrom->m_pcIPCMSampleCb[i];
606      m_pcIPCMSampleCr[i]=pcFrom->m_pcIPCMSampleCr[i];
607    }
608  }
609
610  // Setting neighbor CU
611  m_pcCULeft        = NULL;
612  m_pcCUAbove       = NULL;
613  m_pcCUAboveLeft   = NULL;
614  m_pcCUAboveRight  = NULL;
615
616  m_apcCUColocated[0] = NULL;
617  m_apcCUColocated[1] = NULL;
618
619  UInt uiWidthInCU = pcPic->getFrameWidthInCU();
620  if ( m_uiCUAddr % uiWidthInCU )
621  {
622    m_pcCULeft = pcPic->getCU( m_uiCUAddr - 1 );
623  }
624
625  if ( m_uiCUAddr / uiWidthInCU )
626  {
627    m_pcCUAbove = pcPic->getCU( m_uiCUAddr - uiWidthInCU );
628  }
629
630  if ( m_pcCULeft && m_pcCUAbove )
631  {
632    m_pcCUAboveLeft = pcPic->getCU( m_uiCUAddr - uiWidthInCU - 1 );
633  }
634
635  if ( m_pcCUAbove && ( (m_uiCUAddr%uiWidthInCU) < (uiWidthInCU-1) )  )
636  {
637    m_pcCUAboveRight = pcPic->getCU( m_uiCUAddr - uiWidthInCU + 1 );
638  }
639
640  if ( getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) > 0 )
641  {
642    m_apcCUColocated[0] = getSlice()->getRefPic( REF_PIC_LIST_0, 0)->getCU( m_uiCUAddr );
643  }
644
645  if ( getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) > 0 )
646  {
647    m_apcCUColocated[1] = getSlice()->getRefPic( REF_PIC_LIST_1, 0)->getCU( m_uiCUAddr );
648  }
649}
650
651/** initialize prediction data with enabling sub-LCU-level delta QP
652*\param  uiDepth  depth of the current CU
653*\param  qp     qp for the current CU
654*- set CU width and CU height according to depth
655*- set qp value according to input qp
656*- set last-coded qp value according to input last-coded qp
657*/
658Void TComDataCU::initEstData( UInt uiDepth, Int qp )
659{
660  m_dTotalCost         = MAX_DOUBLE;
661  m_uiTotalDistortion  = 0;
662  m_uiTotalBits        = 0;
663  m_uiTotalBins        = 0;
664
665  UChar uhWidth  = g_uiMaxCUWidth  >> uiDepth;
666  UChar uhHeight = g_uiMaxCUHeight >> uiDepth;
667
668  for (UInt ui = 0; ui < m_uiNumPartition; ui++)
669  {
670    if(getPic()->getPicSym()->getInverseCUOrderMap(getAddr())*m_pcPic->getNumPartInCU()+m_uiAbsIdxInLCU+ui >= getSlice()->getSliceSegmentCurStartCUAddr())
671    {
672      m_apiMVPIdx[0][ui] = -1;
673      m_apiMVPIdx[1][ui] = -1;
674      m_apiMVPNum[0][ui] = -1;
675      m_apiMVPNum[1][ui] = -1;
676      m_puhDepth  [ui] = uiDepth;
677      m_puhWidth  [ui] = uhWidth;
678      m_puhHeight [ui] = uhHeight;
679      m_puhTrIdx  [ui] = 0;
680      m_puhTransformSkip[0][ui] = 0;
681      m_puhTransformSkip[1][ui] = 0;
682      m_puhTransformSkip[2][ui] = 0;
683      m_skipFlag[ui]   = false;
684      m_pePartSize[ui] = SIZE_NONE;
685      m_pePredMode[ui] = MODE_NONE;
686      m_CUTransquantBypass[ui] = false;
687      m_pbIPCMFlag[ui] = 0;
688      m_phQP[ui] = qp;
689      m_pbMergeFlag[ui] = 0;
690      m_puhMergeIndex[ui] = 0;
691      m_puhLumaIntraDir[ui] = DC_IDX;
692      m_puhChromaIntraDir[ui] = 0;
693      m_puhInterDir[ui] = 0;
694      m_puhCbf[0][ui] = 0;
695      m_puhCbf[1][ui] = 0;
696      m_puhCbf[2][ui] = 0;
697
698#if H_3D_DIM
699      for( Int i = 0; i < DIM_NUM_TYPE; i++ )
700      {
701        m_dimDeltaDC[i][0] [ui] = 0;
702        m_dimDeltaDC[i][1] [ui] = 0;
703      }
704#if H_3D_DIM_DMM
705      for( Int i = 0; i < DMM_NUM_TYPE; i++ )
706      {
707        m_dmmWedgeTabIdx[i] [ui] = 0;
708      }
709      m_dmm2DeltaEnd    [ui] = 0;
710      m_dmm3IntraTabIdx [ui] = 0;
711#endif
712#if H_3D_DIM_SDC
713      m_pbSDCFlag           [ui] = false;
714      m_apSegmentDCOffset[0][ui] = 0;
715      m_apSegmentDCOffset[1][ui] = 0;
716#endif
717#endif
718    }
719  }
720
721  UInt uiTmp = uhWidth*uhHeight;
722
723  if(getPic()->getPicSym()->getInverseCUOrderMap(getAddr())*m_pcPic->getNumPartInCU()+m_uiAbsIdxInLCU >= getSlice()->getSliceSegmentCurStartCUAddr())
724  {
725    m_acCUMvField[0].clearMvField();
726    m_acCUMvField[1].clearMvField();
727    uiTmp = uhWidth*uhHeight;
728   
729    memset( m_pcTrCoeffY,    0, uiTmp * sizeof( *m_pcTrCoeffY    ) );
730#if ADAPTIVE_QP_SELECTION
731    memset( m_pcArlCoeffY ,  0, uiTmp * sizeof( *m_pcArlCoeffY   ) );
732#endif
733    memset( m_pcIPCMSampleY, 0, uiTmp * sizeof( *m_pcIPCMSampleY ) );
734
735    uiTmp>>=2;
736    memset( m_pcTrCoeffCb,    0, uiTmp * sizeof( *m_pcTrCoeffCb    ) );
737    memset( m_pcTrCoeffCr,    0, uiTmp * sizeof( *m_pcTrCoeffCr    ) );
738#if ADAPTIVE_QP_SELECTION 
739    memset( m_pcArlCoeffCb,   0, uiTmp * sizeof( *m_pcArlCoeffCb   ) );
740    memset( m_pcArlCoeffCr,   0, uiTmp * sizeof( *m_pcArlCoeffCr   ) );
741#endif
742    memset( m_pcIPCMSampleCb, 0, uiTmp * sizeof( *m_pcIPCMSampleCb ) );
743    memset( m_pcIPCMSampleCr, 0, uiTmp * sizeof( *m_pcIPCMSampleCr ) );
744  }
745}
746
747
748// initialize Sub partition
749Void TComDataCU::initSubCU( TComDataCU* pcCU, UInt uiPartUnitIdx, UInt uiDepth, Int qp )
750{
751  assert( uiPartUnitIdx<4 );
752
753  UInt uiPartOffset = ( pcCU->getTotalNumPart()>>2 )*uiPartUnitIdx;
754
755  m_pcPic              = pcCU->getPic();
756  m_pcSlice            = m_pcPic->getSlice(m_pcPic->getCurrSliceIdx());
757  m_uiCUAddr           = pcCU->getAddr();
758  m_uiAbsIdxInLCU      = pcCU->getZorderIdxInCU() + uiPartOffset;
759
760  m_uiCUPelX           = pcCU->getCUPelX() + ( g_uiMaxCUWidth>>uiDepth  )*( uiPartUnitIdx &  1 );
761  m_uiCUPelY           = pcCU->getCUPelY() + ( g_uiMaxCUHeight>>uiDepth  )*( uiPartUnitIdx >> 1 );
762
763  m_dTotalCost         = MAX_DOUBLE;
764  m_uiTotalDistortion  = 0;
765  m_uiTotalBits        = 0;
766  m_uiTotalBins        = 0;
767  m_uiNumPartition     = pcCU->getTotalNumPart() >> 2;
768
769  Int iSizeInUchar = sizeof( UChar  ) * m_uiNumPartition;
770  Int iSizeInBool  = sizeof( Bool   ) * m_uiNumPartition;
771
772  Int sizeInChar = sizeof( Char  ) * m_uiNumPartition;
773  memset( m_phQP,              qp,  sizeInChar );
774
775  memset( m_pbMergeFlag,        0, iSizeInBool  );
776  memset( m_puhMergeIndex,      0, iSizeInUchar );
777  memset( m_puhLumaIntraDir,    DC_IDX, iSizeInUchar );
778  memset( m_puhChromaIntraDir,  0, iSizeInUchar );
779  memset( m_puhInterDir,        0, iSizeInUchar );
780  memset( m_puhTrIdx,           0, iSizeInUchar );
781  memset( m_puhTransformSkip[0], 0, iSizeInUchar );
782  memset( m_puhTransformSkip[1], 0, iSizeInUchar );
783  memset( m_puhTransformSkip[2], 0, iSizeInUchar );
784  memset( m_puhCbf[0],          0, iSizeInUchar );
785  memset( m_puhCbf[1],          0, iSizeInUchar );
786  memset( m_puhCbf[2],          0, iSizeInUchar );
787  memset( m_puhDepth,     uiDepth, iSizeInUchar );
788
789  UChar uhWidth  = g_uiMaxCUWidth  >> uiDepth;
790  UChar uhHeight = g_uiMaxCUHeight >> uiDepth;
791  memset( m_puhWidth,          uhWidth,  iSizeInUchar );
792  memset( m_puhHeight,         uhHeight, iSizeInUchar );
793  memset( m_pbIPCMFlag,        0, iSizeInBool  );
794 
795#if H_3D_DIM
796  for( Int i = 0; i < DIM_NUM_TYPE; i++ )
797  {
798    memset( m_dimDeltaDC[i][0], 0, sizeof(Pel ) * m_uiNumPartition );
799    memset( m_dimDeltaDC[i][1], 0, sizeof(Pel ) * m_uiNumPartition );
800  }
801#if H_3D_DIM_DMM
802  for( Int i = 0; i < DMM_NUM_TYPE; i++ )
803  {
804    memset( m_dmmWedgeTabIdx[i], 0, sizeof(UInt) * m_uiNumPartition );
805  }
806  memset( m_dmm2DeltaEnd   , 0, sizeof(Int ) * m_uiNumPartition );
807  memset( m_dmm3IntraTabIdx, 0, sizeof(UInt) * m_uiNumPartition );
808#endif
809#if H_3D_DIM_RBC
810  memset( m_pucEdgeCode    , 0, iSizeInUchar * RBC_MAX_EDGE_NUM_PER_4x4 );
811  memset( m_pucEdgeNumber  , 0, iSizeInUchar );
812  memset( m_pucEdgeStartPos, 0, iSizeInUchar );
813  memset( m_pbEdgeLeftFirst, 0, iSizeInBool );
814  memset( m_pbEdgePartition, 0, iSizeInBool * 16 );
815#endif
816#if H_3D_DIM_SDC
817  memset( m_pbSDCFlag,            0, sizeof(Bool) * m_uiNumPartition  );
818  memset( m_apSegmentDCOffset[0], 0, sizeof(Pel) * m_uiNumPartition   );
819  memset( m_apSegmentDCOffset[1], 0, sizeof(Pel) * m_uiNumPartition   );
820#endif
821#endif
822 
823  for (UInt ui = 0; ui < m_uiNumPartition; ui++)
824  {
825    m_skipFlag[ui]   = false;
826    m_pePartSize[ui] = SIZE_NONE;
827    m_pePredMode[ui] = MODE_NONE;
828    m_CUTransquantBypass[ui] = false;
829    m_apiMVPIdx[0][ui] = -1;
830    m_apiMVPIdx[1][ui] = -1;
831    m_apiMVPNum[0][ui] = -1;
832    m_apiMVPNum[1][ui] = -1;
833    if(m_pcPic->getPicSym()->getInverseCUOrderMap(getAddr())*m_pcPic->getNumPartInCU()+m_uiAbsIdxInLCU+ui<getSlice()->getSliceSegmentCurStartCUAddr())
834    {
835      m_apiMVPIdx[0][ui] = pcCU->m_apiMVPIdx[0][uiPartOffset+ui];
836      m_apiMVPIdx[1][ui] = pcCU->m_apiMVPIdx[1][uiPartOffset+ui];;
837      m_apiMVPNum[0][ui] = pcCU->m_apiMVPNum[0][uiPartOffset+ui];;
838      m_apiMVPNum[1][ui] = pcCU->m_apiMVPNum[1][uiPartOffset+ui];;
839      m_puhDepth  [ui] = pcCU->getDepth(uiPartOffset+ui);
840      m_puhWidth  [ui] = pcCU->getWidth(uiPartOffset+ui);
841      m_puhHeight  [ui] = pcCU->getHeight(uiPartOffset+ui);
842      m_puhTrIdx  [ui] = pcCU->getTransformIdx(uiPartOffset+ui);
843      m_puhTransformSkip[0][ui] = pcCU->getTransformSkip(uiPartOffset+ui,TEXT_LUMA);
844      m_puhTransformSkip[1][ui] = pcCU->getTransformSkip(uiPartOffset+ui,TEXT_CHROMA_U);
845      m_puhTransformSkip[2][ui] = pcCU->getTransformSkip(uiPartOffset+ui,TEXT_CHROMA_V);
846      m_skipFlag[ui]   = pcCU->getSkipFlag(uiPartOffset+ui);
847      m_pePartSize[ui] = pcCU->getPartitionSize(uiPartOffset+ui);
848      m_pePredMode[ui] = pcCU->getPredictionMode(uiPartOffset+ui);
849      m_CUTransquantBypass[ui] = pcCU->getCUTransquantBypass(uiPartOffset+ui);
850      m_pbIPCMFlag[ui]=pcCU->m_pbIPCMFlag[uiPartOffset+ui];
851      m_phQP[ui] = pcCU->m_phQP[uiPartOffset+ui];
852      m_pbMergeFlag[ui]=pcCU->m_pbMergeFlag[uiPartOffset+ui];
853      m_puhMergeIndex[ui]=pcCU->m_puhMergeIndex[uiPartOffset+ui];
854      m_puhLumaIntraDir[ui]=pcCU->m_puhLumaIntraDir[uiPartOffset+ui];
855      m_puhChromaIntraDir[ui]=pcCU->m_puhChromaIntraDir[uiPartOffset+ui];
856      m_puhInterDir[ui]=pcCU->m_puhInterDir[uiPartOffset+ui];
857      m_puhCbf[0][ui]=pcCU->m_puhCbf[0][uiPartOffset+ui];
858      m_puhCbf[1][ui]=pcCU->m_puhCbf[1][uiPartOffset+ui];
859      m_puhCbf[2][ui]=pcCU->m_puhCbf[2][uiPartOffset+ui];
860
861#if H_3D_DIM
862      for( Int i = 0; i < DIM_NUM_TYPE; i++ )
863      {
864        m_dimDeltaDC[i][0] [ui] = pcCU->m_dimDeltaDC[i][0] [uiPartOffset+ui];
865        m_dimDeltaDC[i][1] [ui] = pcCU->m_dimDeltaDC[i][1] [uiPartOffset+ui];
866      }
867#if H_3D_DIM_DMM
868      for( Int i = 0; i < DMM_NUM_TYPE; i++ )
869      {
870        m_dmmWedgeTabIdx[i] [ui] = pcCU->m_dmmWedgeTabIdx[i] [uiPartOffset+ui];
871      }
872      m_dmm2DeltaEnd    [ui] = pcCU->m_dmm2DeltaEnd   [uiPartOffset+ui];
873      m_dmm3IntraTabIdx [ui] = pcCU->m_dmm3IntraTabIdx[uiPartOffset+ui];
874#endif
875#if H_3D_DIM_SDC
876      m_pbSDCFlag           [ui] = pcCU->m_pbSDCFlag            [ uiPartOffset + ui ];
877      m_apSegmentDCOffset[0][ui] = pcCU->m_apSegmentDCOffset[0] [ uiPartOffset + ui ];
878      m_apSegmentDCOffset[1][ui] = pcCU->m_apSegmentDCOffset[1] [ uiPartOffset + ui ];
879#endif
880#endif
881    }
882  }
883  UInt uiTmp = uhWidth*uhHeight;
884  memset( m_pcTrCoeffY , 0, sizeof(TCoeff)*uiTmp );
885#if ADAPTIVE_QP_SELECTION 
886  memset( m_pcArlCoeffY , 0, sizeof(Int)*uiTmp );
887#endif
888  memset( m_pcIPCMSampleY , 0, sizeof( Pel ) * uiTmp );
889  uiTmp >>= 2;
890  memset( m_pcTrCoeffCb, 0, sizeof(TCoeff)*uiTmp );
891  memset( m_pcTrCoeffCr, 0, sizeof(TCoeff)*uiTmp );
892#if ADAPTIVE_QP_SELECTION
893  memset( m_pcArlCoeffCb, 0, sizeof(Int)*uiTmp );
894  memset( m_pcArlCoeffCr, 0, sizeof(Int)*uiTmp );
895#endif
896  memset( m_pcIPCMSampleCb , 0, sizeof( Pel ) * uiTmp );
897  memset( m_pcIPCMSampleCr , 0, sizeof( Pel ) * uiTmp );
898  m_acCUMvField[0].clearMvField();
899  m_acCUMvField[1].clearMvField();
900
901  if(m_pcPic->getPicSym()->getInverseCUOrderMap(getAddr())*m_pcPic->getNumPartInCU()+m_uiAbsIdxInLCU<getSlice()->getSliceSegmentCurStartCUAddr())
902  {
903    // Part of this CU contains data from an older slice. Now copy in that data.
904    UInt uiMaxCuWidth=pcCU->getSlice()->getSPS()->getMaxCUWidth();
905    UInt uiMaxCuHeight=pcCU->getSlice()->getSPS()->getMaxCUHeight();
906    TComDataCU * bigCU = getPic()->getCU(getAddr());
907    Int minui = uiPartOffset;
908    minui = -minui;
909    pcCU->m_acCUMvField[0].copyTo(&m_acCUMvField[0],minui,uiPartOffset,m_uiNumPartition);
910    pcCU->m_acCUMvField[1].copyTo(&m_acCUMvField[1],minui,uiPartOffset,m_uiNumPartition);
911    UInt uiCoffOffset = uiMaxCuWidth*uiMaxCuHeight*m_uiAbsIdxInLCU/pcCU->getPic()->getNumPartInCU();
912    uiTmp = uhWidth*uhHeight;
913    for(Int i=0; i<uiTmp; i++)
914    {
915      m_pcTrCoeffY[i]=bigCU->m_pcTrCoeffY[uiCoffOffset+i];
916#if ADAPTIVE_QP_SELECTION
917      m_pcArlCoeffY[i]=bigCU->m_pcArlCoeffY[uiCoffOffset+i];
918#endif
919      m_pcIPCMSampleY[i]=bigCU->m_pcIPCMSampleY[uiCoffOffset+i];
920    }
921    uiTmp>>=2;
922    uiCoffOffset>>=2;
923    for(Int i=0; i<uiTmp; i++)
924    {
925      m_pcTrCoeffCr[i]=bigCU->m_pcTrCoeffCr[uiCoffOffset+i];
926      m_pcTrCoeffCb[i]=bigCU->m_pcTrCoeffCb[uiCoffOffset+i];
927#if ADAPTIVE_QP_SELECTION
928      m_pcArlCoeffCr[i]=bigCU->m_pcArlCoeffCr[uiCoffOffset+i];
929      m_pcArlCoeffCb[i]=bigCU->m_pcArlCoeffCb[uiCoffOffset+i];
930#endif
931      m_pcIPCMSampleCb[i]=bigCU->m_pcIPCMSampleCb[uiCoffOffset+i];
932      m_pcIPCMSampleCr[i]=bigCU->m_pcIPCMSampleCr[uiCoffOffset+i];
933    }
934  }
935
936  m_pcCULeft        = pcCU->getCULeft();
937  m_pcCUAbove       = pcCU->getCUAbove();
938  m_pcCUAboveLeft   = pcCU->getCUAboveLeft();
939  m_pcCUAboveRight  = pcCU->getCUAboveRight();
940
941  m_apcCUColocated[0] = pcCU->getCUColocated(REF_PIC_LIST_0);
942  m_apcCUColocated[1] = pcCU->getCUColocated(REF_PIC_LIST_1);
943  memcpy(m_sliceStartCU,pcCU->m_sliceStartCU+uiPartOffset,sizeof(UInt)*m_uiNumPartition);
944  memcpy(m_sliceSegmentStartCU,pcCU->m_sliceSegmentStartCU+uiPartOffset,sizeof(UInt)*m_uiNumPartition);
945}
946
947Void TComDataCU::setOutsideCUPart( UInt uiAbsPartIdx, UInt uiDepth )
948{
949  UInt uiNumPartition = m_uiNumPartition >> (uiDepth << 1);
950  UInt uiSizeInUchar = sizeof( UChar  ) * uiNumPartition;
951
952  UChar uhWidth  = g_uiMaxCUWidth  >> uiDepth;
953  UChar uhHeight = g_uiMaxCUHeight >> uiDepth;
954  memset( m_puhDepth    + uiAbsPartIdx,     uiDepth,  uiSizeInUchar );
955  memset( m_puhWidth    + uiAbsPartIdx,     uhWidth,  uiSizeInUchar );
956  memset( m_puhHeight   + uiAbsPartIdx,     uhHeight, uiSizeInUchar );
957}
958
959// --------------------------------------------------------------------------------------------------------------------
960// Copy
961// --------------------------------------------------------------------------------------------------------------------
962
963Void TComDataCU::copySubCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
964{
965  UInt uiPart = uiAbsPartIdx;
966 
967  m_pcPic              = pcCU->getPic();
968  m_pcSlice            = pcCU->getSlice();
969  m_uiCUAddr           = pcCU->getAddr();
970  m_uiAbsIdxInLCU      = uiAbsPartIdx;
971 
972  m_uiCUPelX           = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
973  m_uiCUPelY           = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
974 
975  UInt uiWidth         = g_uiMaxCUWidth  >> uiDepth;
976  UInt uiHeight        = g_uiMaxCUHeight >> uiDepth;
977 
978  m_skipFlag=pcCU->getSkipFlag()          + uiPart;
979
980  m_phQP=pcCU->getQP()                    + uiPart;
981  m_pePartSize = pcCU->getPartitionSize() + uiPart;
982  m_pePredMode=pcCU->getPredictionMode()  + uiPart;
983  m_CUTransquantBypass  = pcCU->getCUTransquantBypass()+uiPart;
984 
985  m_pbMergeFlag         = pcCU->getMergeFlag()        + uiPart;
986  m_puhMergeIndex       = pcCU->getMergeIndex()       + uiPart;
987
988  m_puhLumaIntraDir     = pcCU->getLumaIntraDir()     + uiPart;
989  m_puhChromaIntraDir   = pcCU->getChromaIntraDir()   + uiPart;
990  m_puhInterDir         = pcCU->getInterDir()         + uiPart;
991  m_puhTrIdx            = pcCU->getTransformIdx()     + uiPart;
992  m_puhTransformSkip[0] = pcCU->getTransformSkip(TEXT_LUMA)     + uiPart;
993  m_puhTransformSkip[1] = pcCU->getTransformSkip(TEXT_CHROMA_U) + uiPart;
994  m_puhTransformSkip[2] = pcCU->getTransformSkip(TEXT_CHROMA_V) + uiPart;
995
996  m_puhCbf[0]= pcCU->getCbf(TEXT_LUMA)            + uiPart;
997  m_puhCbf[1]= pcCU->getCbf(TEXT_CHROMA_U)        + uiPart;
998  m_puhCbf[2]= pcCU->getCbf(TEXT_CHROMA_V)        + uiPart;
999 
1000#if H_3D_DIM
1001  for( Int i = 0; i < DIM_NUM_TYPE; i++ )
1002  {
1003    m_dimDeltaDC[i][0] = pcCU->getDimDeltaDC( i, 0 ) + uiPart;
1004    m_dimDeltaDC[i][1] = pcCU->getDimDeltaDC( i, 1 ) + uiPart;
1005  }
1006#if H_3D_DIM_DMM
1007  for( Int i = 0; i < DMM_NUM_TYPE; i++ )
1008  {
1009    m_dmmWedgeTabIdx[i] = pcCU->getDmmWedgeTabIdx( i ) + uiPart;
1010  }
1011  m_dmm2DeltaEnd    = pcCU->getDmm2DeltaEnd()    + uiPart;
1012  m_dmm3IntraTabIdx = pcCU->getDmm3IntraTabIdx() + uiPart;
1013#endif
1014#if H_3D_DIM_RBC
1015  m_pucEdgeCode     = pcCU->getEdgeCode( uiPart );
1016  m_pucEdgeNumber   = pcCU->getEdgeNumber()      + uiPart;
1017  m_pucEdgeStartPos = pcCU->getEdgeStartPos()    + uiPart;
1018  m_pbEdgeLeftFirst = pcCU->getEdgeLeftFirst()   + uiPart;
1019  m_pbEdgePartition = pcCU->getEdgePartition( uiPart );
1020#endif
1021#if H_3D_DIM_SDC
1022  m_pbSDCFlag               = pcCU->getSDCFlag()              + uiPart;
1023  m_apSegmentDCOffset[0]    = pcCU->getSDCSegmentDCOffset(0)  + uiPart;
1024  m_apSegmentDCOffset[1]    = pcCU->getSDCSegmentDCOffset(1)  + uiPart;
1025#endif
1026#endif
1027
1028  m_puhDepth=pcCU->getDepth()                     + uiPart;
1029  m_puhWidth=pcCU->getWidth()                     + uiPart;
1030  m_puhHeight=pcCU->getHeight()                   + uiPart;
1031 
1032  m_apiMVPIdx[0]=pcCU->getMVPIdx(REF_PIC_LIST_0)  + uiPart;
1033  m_apiMVPIdx[1]=pcCU->getMVPIdx(REF_PIC_LIST_1)  + uiPart;
1034  m_apiMVPNum[0]=pcCU->getMVPNum(REF_PIC_LIST_0)  + uiPart;
1035  m_apiMVPNum[1]=pcCU->getMVPNum(REF_PIC_LIST_1)  + uiPart;
1036 
1037  m_pbIPCMFlag         = pcCU->getIPCMFlag()        + uiPart;
1038
1039  m_pcCUAboveLeft      = pcCU->getCUAboveLeft();
1040  m_pcCUAboveRight     = pcCU->getCUAboveRight();
1041  m_pcCUAbove          = pcCU->getCUAbove();
1042  m_pcCULeft           = pcCU->getCULeft();
1043 
1044  m_apcCUColocated[0] = pcCU->getCUColocated(REF_PIC_LIST_0);
1045  m_apcCUColocated[1] = pcCU->getCUColocated(REF_PIC_LIST_1);
1046 
1047  UInt uiTmp = uiWidth*uiHeight;
1048  UInt uiMaxCuWidth=pcCU->getSlice()->getSPS()->getMaxCUWidth();
1049  UInt uiMaxCuHeight=pcCU->getSlice()->getSPS()->getMaxCUHeight();
1050 
1051  UInt uiCoffOffset = uiMaxCuWidth*uiMaxCuHeight*uiAbsPartIdx/pcCU->getPic()->getNumPartInCU();
1052 
1053  m_pcTrCoeffY = pcCU->getCoeffY() + uiCoffOffset;
1054#if ADAPTIVE_QP_SELECTION
1055  m_pcArlCoeffY= pcCU->getArlCoeffY() + uiCoffOffset; 
1056#endif
1057  m_pcIPCMSampleY = pcCU->getPCMSampleY() + uiCoffOffset;
1058
1059  uiTmp >>= 2;
1060  uiCoffOffset >>=2;
1061  m_pcTrCoeffCb=pcCU->getCoeffCb() + uiCoffOffset;
1062  m_pcTrCoeffCr=pcCU->getCoeffCr() + uiCoffOffset;
1063#if ADAPTIVE_QP_SELECTION 
1064  m_pcArlCoeffCb=pcCU->getArlCoeffCb() + uiCoffOffset;
1065  m_pcArlCoeffCr=pcCU->getArlCoeffCr() + uiCoffOffset;
1066#endif
1067  m_pcIPCMSampleCb = pcCU->getPCMSampleCb() + uiCoffOffset;
1068  m_pcIPCMSampleCr = pcCU->getPCMSampleCr() + uiCoffOffset;
1069
1070  m_acCUMvField[0].linkToWithOffset( pcCU->getCUMvField(REF_PIC_LIST_0), uiPart );
1071  m_acCUMvField[1].linkToWithOffset( pcCU->getCUMvField(REF_PIC_LIST_1), uiPart );
1072  memcpy(m_sliceStartCU,pcCU->m_sliceStartCU+uiPart,sizeof(UInt)*m_uiNumPartition);
1073  memcpy(m_sliceSegmentStartCU,pcCU->m_sliceSegmentStartCU+uiPart,sizeof(UInt)*m_uiNumPartition);
1074}
1075
1076// Copy inter prediction info from the biggest CU
1077Void TComDataCU::copyInterPredInfoFrom    ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefPicList )
1078{
1079  m_pcPic              = pcCU->getPic();
1080  m_pcSlice            = pcCU->getSlice();
1081  m_uiCUAddr           = pcCU->getAddr();
1082  m_uiAbsIdxInLCU      = uiAbsPartIdx;
1083 
1084  Int iRastPartIdx     = g_auiZscanToRaster[uiAbsPartIdx];
1085  m_uiCUPelX           = pcCU->getCUPelX() + m_pcPic->getMinCUWidth ()*( iRastPartIdx % m_pcPic->getNumPartInWidth() );
1086  m_uiCUPelY           = pcCU->getCUPelY() + m_pcPic->getMinCUHeight()*( iRastPartIdx / m_pcPic->getNumPartInWidth() );
1087 
1088  m_pcCUAboveLeft      = pcCU->getCUAboveLeft();
1089  m_pcCUAboveRight     = pcCU->getCUAboveRight();
1090  m_pcCUAbove          = pcCU->getCUAbove();
1091  m_pcCULeft           = pcCU->getCULeft();
1092 
1093  m_apcCUColocated[0]  = pcCU->getCUColocated(REF_PIC_LIST_0);
1094  m_apcCUColocated[1]  = pcCU->getCUColocated(REF_PIC_LIST_1);
1095 
1096  m_skipFlag           = pcCU->getSkipFlag ()             + uiAbsPartIdx;
1097
1098  m_pePartSize         = pcCU->getPartitionSize ()        + uiAbsPartIdx;
1099  m_pePredMode         = pcCU->getPredictionMode()        + uiAbsPartIdx;
1100  m_CUTransquantBypass = pcCU->getCUTransquantBypass()    + uiAbsPartIdx;
1101  m_puhInterDir        = pcCU->getInterDir      ()        + uiAbsPartIdx;
1102 
1103  m_puhDepth           = pcCU->getDepth ()                + uiAbsPartIdx;
1104  m_puhWidth           = pcCU->getWidth ()                + uiAbsPartIdx;
1105  m_puhHeight          = pcCU->getHeight()                + uiAbsPartIdx;
1106 
1107  m_pbMergeFlag        = pcCU->getMergeFlag()             + uiAbsPartIdx;
1108  m_puhMergeIndex      = pcCU->getMergeIndex()            + uiAbsPartIdx;
1109
1110  m_apiMVPIdx[eRefPicList] = pcCU->getMVPIdx(eRefPicList) + uiAbsPartIdx;
1111  m_apiMVPNum[eRefPicList] = pcCU->getMVPNum(eRefPicList) + uiAbsPartIdx;
1112 
1113  m_acCUMvField[ eRefPicList ].linkToWithOffset( pcCU->getCUMvField(eRefPicList), uiAbsPartIdx );
1114
1115  memcpy(m_sliceStartCU,pcCU->m_sliceStartCU+uiAbsPartIdx,sizeof(UInt)*m_uiNumPartition);
1116  memcpy(m_sliceSegmentStartCU,pcCU->m_sliceSegmentStartCU+uiAbsPartIdx,sizeof(UInt)*m_uiNumPartition);
1117}
1118
1119// Copy small CU to bigger CU.
1120// One of quarter parts overwritten by predicted sub part.
1121Void TComDataCU::copyPartFrom( TComDataCU* pcCU, UInt uiPartUnitIdx, UInt uiDepth )
1122{
1123  assert( uiPartUnitIdx<4 );
1124 
1125  m_dTotalCost         += pcCU->getTotalCost();
1126  m_uiTotalDistortion  += pcCU->getTotalDistortion();
1127  m_uiTotalBits        += pcCU->getTotalBits();
1128 
1129  UInt uiOffset         = pcCU->getTotalNumPart()*uiPartUnitIdx;
1130 
1131  UInt uiNumPartition = pcCU->getTotalNumPart();
1132  Int iSizeInUchar  = sizeof( UChar ) * uiNumPartition;
1133  Int iSizeInBool   = sizeof( Bool  ) * uiNumPartition;
1134 
1135  Int sizeInChar  = sizeof( Char ) * uiNumPartition;
1136  memcpy( m_skipFlag   + uiOffset, pcCU->getSkipFlag(),       sizeof( *m_skipFlag )   * uiNumPartition );
1137  memcpy( m_phQP       + uiOffset, pcCU->getQP(),             sizeInChar                        );
1138  memcpy( m_pePartSize + uiOffset, pcCU->getPartitionSize(),  sizeof( *m_pePartSize ) * uiNumPartition );
1139  memcpy( m_pePredMode + uiOffset, pcCU->getPredictionMode(), sizeof( *m_pePredMode ) * uiNumPartition );
1140  memcpy( m_CUTransquantBypass + uiOffset, pcCU->getCUTransquantBypass(), sizeof( *m_CUTransquantBypass ) * uiNumPartition );
1141  memcpy( m_pbMergeFlag         + uiOffset, pcCU->getMergeFlag(),         iSizeInBool  );
1142  memcpy( m_puhMergeIndex       + uiOffset, pcCU->getMergeIndex(),        iSizeInUchar );
1143  memcpy( m_puhLumaIntraDir     + uiOffset, pcCU->getLumaIntraDir(),      iSizeInUchar );
1144  memcpy( m_puhChromaIntraDir   + uiOffset, pcCU->getChromaIntraDir(),    iSizeInUchar );
1145  memcpy( m_puhInterDir         + uiOffset, pcCU->getInterDir(),          iSizeInUchar );
1146  memcpy( m_puhTrIdx            + uiOffset, pcCU->getTransformIdx(),      iSizeInUchar );
1147  memcpy( m_puhTransformSkip[0] + uiOffset, pcCU->getTransformSkip(TEXT_LUMA),     iSizeInUchar );
1148  memcpy( m_puhTransformSkip[1] + uiOffset, pcCU->getTransformSkip(TEXT_CHROMA_U), iSizeInUchar );
1149  memcpy( m_puhTransformSkip[2] + uiOffset, pcCU->getTransformSkip(TEXT_CHROMA_V), iSizeInUchar );
1150
1151  memcpy( m_puhCbf[0] + uiOffset, pcCU->getCbf(TEXT_LUMA)    , iSizeInUchar );
1152  memcpy( m_puhCbf[1] + uiOffset, pcCU->getCbf(TEXT_CHROMA_U), iSizeInUchar );
1153  memcpy( m_puhCbf[2] + uiOffset, pcCU->getCbf(TEXT_CHROMA_V), iSizeInUchar );
1154 
1155#if H_3D_DIM
1156  for( Int i = 0; i < DIM_NUM_TYPE; i++ )
1157  {
1158    memcpy( m_dimDeltaDC[i][0] + uiOffset, pcCU->getDimDeltaDC( i, 0 ), sizeof(Pel ) * uiNumPartition );
1159    memcpy( m_dimDeltaDC[i][1] + uiOffset, pcCU->getDimDeltaDC( i, 1 ), sizeof(Pel ) * uiNumPartition );
1160  }
1161#if H_3D_DIM_DMM
1162  for( Int i = 0; i < DMM_NUM_TYPE; i++ )
1163  {
1164    memcpy( m_dmmWedgeTabIdx[i] + uiOffset, pcCU->getDmmWedgeTabIdx( i ), sizeof(UInt) * uiNumPartition );
1165  }
1166  memcpy( m_dmm2DeltaEnd    + uiOffset, pcCU->getDmm2DeltaEnd()   , sizeof(Int ) * uiNumPartition );
1167  memcpy( m_dmm3IntraTabIdx + uiOffset, pcCU->getDmm3IntraTabIdx(), sizeof(UInt) * uiNumPartition );
1168#endif
1169#if H_3D_DIM_RBC
1170  memcpy( getEdgeCode( uiOffset ),       pcCU->getEdgeCode(0),      iSizeInUchar * RBC_MAX_EDGE_NUM_PER_4x4 );
1171  memcpy( getEdgeNumber()    + uiOffset, pcCU->getEdgeNumber(),     iSizeInUchar );
1172  memcpy( getEdgeStartPos()  + uiOffset, pcCU->getEdgeStartPos(),   iSizeInUchar );
1173  memcpy( getEdgeLeftFirst() + uiOffset, pcCU->getEdgeLeftFirst(),  iSizeInBool );
1174  memcpy( getEdgePartition( uiOffset ),  pcCU->getEdgePartition(0), iSizeInBool * 16 );
1175#endif
1176#if H_3D_DIM_SDC
1177  memcpy( m_pbSDCFlag             + uiOffset, pcCU->getSDCFlag(),             iSizeInBool  );
1178  memcpy( m_apSegmentDCOffset[0]  + uiOffset, pcCU->getSDCSegmentDCOffset(0), sizeof( Pel ) * uiNumPartition);
1179  memcpy( m_apSegmentDCOffset[1]  + uiOffset, pcCU->getSDCSegmentDCOffset(1), sizeof( Pel ) * uiNumPartition);
1180#endif
1181#endif
1182
1183  memcpy( m_puhDepth  + uiOffset, pcCU->getDepth(),  iSizeInUchar );
1184  memcpy( m_puhWidth  + uiOffset, pcCU->getWidth(),  iSizeInUchar );
1185  memcpy( m_puhHeight + uiOffset, pcCU->getHeight(), iSizeInUchar );
1186 
1187  memcpy( m_apiMVPIdx[0] + uiOffset, pcCU->getMVPIdx(REF_PIC_LIST_0), iSizeInUchar );
1188  memcpy( m_apiMVPIdx[1] + uiOffset, pcCU->getMVPIdx(REF_PIC_LIST_1), iSizeInUchar );
1189  memcpy( m_apiMVPNum[0] + uiOffset, pcCU->getMVPNum(REF_PIC_LIST_0), iSizeInUchar );
1190  memcpy( m_apiMVPNum[1] + uiOffset, pcCU->getMVPNum(REF_PIC_LIST_1), iSizeInUchar );
1191 
1192  memcpy( m_pbIPCMFlag + uiOffset, pcCU->getIPCMFlag(), iSizeInBool );
1193
1194  m_pcCUAboveLeft      = pcCU->getCUAboveLeft();
1195  m_pcCUAboveRight     = pcCU->getCUAboveRight();
1196  m_pcCUAbove          = pcCU->getCUAbove();
1197  m_pcCULeft           = pcCU->getCULeft();
1198 
1199  m_apcCUColocated[0] = pcCU->getCUColocated(REF_PIC_LIST_0);
1200  m_apcCUColocated[1] = pcCU->getCUColocated(REF_PIC_LIST_1);
1201 
1202  m_acCUMvField[0].copyFrom( pcCU->getCUMvField( REF_PIC_LIST_0 ), pcCU->getTotalNumPart(), uiOffset );
1203  m_acCUMvField[1].copyFrom( pcCU->getCUMvField( REF_PIC_LIST_1 ), pcCU->getTotalNumPart(), uiOffset );
1204 
1205  UInt uiTmp  = g_uiMaxCUWidth*g_uiMaxCUHeight >> (uiDepth<<1);
1206  UInt uiTmp2 = uiPartUnitIdx*uiTmp;
1207  memcpy( m_pcTrCoeffY  + uiTmp2, pcCU->getCoeffY(),  sizeof(TCoeff)*uiTmp );
1208#if ADAPTIVE_QP_SELECTION
1209  memcpy( m_pcArlCoeffY  + uiTmp2, pcCU->getArlCoeffY(),  sizeof(Int)*uiTmp );
1210#endif
1211  memcpy( m_pcIPCMSampleY + uiTmp2 , pcCU->getPCMSampleY(), sizeof(Pel) * uiTmp );
1212
1213  uiTmp >>= 2; uiTmp2>>= 2;
1214  memcpy( m_pcTrCoeffCb + uiTmp2, pcCU->getCoeffCb(), sizeof(TCoeff)*uiTmp );
1215  memcpy( m_pcTrCoeffCr + uiTmp2, pcCU->getCoeffCr(), sizeof(TCoeff)*uiTmp );
1216#if ADAPTIVE_QP_SELECTION
1217  memcpy( m_pcArlCoeffCb + uiTmp2, pcCU->getArlCoeffCb(), sizeof(Int)*uiTmp );
1218  memcpy( m_pcArlCoeffCr + uiTmp2, pcCU->getArlCoeffCr(), sizeof(Int)*uiTmp );
1219#endif
1220  memcpy( m_pcIPCMSampleCb + uiTmp2 , pcCU->getPCMSampleCb(), sizeof(Pel) * uiTmp );
1221  memcpy( m_pcIPCMSampleCr + uiTmp2 , pcCU->getPCMSampleCr(), sizeof(Pel) * uiTmp );
1222  m_uiTotalBins += pcCU->getTotalBins();
1223  memcpy( m_sliceStartCU        + uiOffset, pcCU->m_sliceStartCU,        sizeof( UInt ) * uiNumPartition  );
1224  memcpy( m_sliceSegmentStartCU + uiOffset, pcCU->m_sliceSegmentStartCU, sizeof( UInt ) * uiNumPartition  );
1225}
1226
1227// Copy current predicted part to a CU in picture.
1228// It is used to predict for next part
1229Void TComDataCU::copyToPic( UChar uhDepth )
1230{
1231  TComDataCU*& rpcCU = m_pcPic->getCU( m_uiCUAddr );
1232 
1233  rpcCU->getTotalCost()       = m_dTotalCost;
1234  rpcCU->getTotalDistortion() = m_uiTotalDistortion;
1235  rpcCU->getTotalBits()       = m_uiTotalBits;
1236 
1237  Int iSizeInUchar  = sizeof( UChar ) * m_uiNumPartition;
1238  Int iSizeInBool   = sizeof( Bool  ) * m_uiNumPartition;
1239 
1240  Int sizeInChar  = sizeof( Char ) * m_uiNumPartition;
1241
1242  memcpy( rpcCU->getSkipFlag() + m_uiAbsIdxInLCU, m_skipFlag, sizeof( *m_skipFlag ) * m_uiNumPartition );
1243
1244  memcpy( rpcCU->getQP() + m_uiAbsIdxInLCU, m_phQP, sizeInChar  );
1245
1246  memcpy( rpcCU->getPartitionSize()  + m_uiAbsIdxInLCU, m_pePartSize, sizeof( *m_pePartSize ) * m_uiNumPartition );
1247  memcpy( rpcCU->getPredictionMode() + m_uiAbsIdxInLCU, m_pePredMode, sizeof( *m_pePredMode ) * m_uiNumPartition );
1248  memcpy( rpcCU->getCUTransquantBypass()+ m_uiAbsIdxInLCU, m_CUTransquantBypass, sizeof( *m_CUTransquantBypass ) * m_uiNumPartition );
1249  memcpy( rpcCU->getMergeFlag()         + m_uiAbsIdxInLCU, m_pbMergeFlag,         iSizeInBool  );
1250  memcpy( rpcCU->getMergeIndex()        + m_uiAbsIdxInLCU, m_puhMergeIndex,       iSizeInUchar );
1251  memcpy( rpcCU->getLumaIntraDir()      + m_uiAbsIdxInLCU, m_puhLumaIntraDir,     iSizeInUchar );
1252  memcpy( rpcCU->getChromaIntraDir()    + m_uiAbsIdxInLCU, m_puhChromaIntraDir,   iSizeInUchar );
1253  memcpy( rpcCU->getInterDir()          + m_uiAbsIdxInLCU, m_puhInterDir,         iSizeInUchar );
1254  memcpy( rpcCU->getTransformIdx()      + m_uiAbsIdxInLCU, m_puhTrIdx,            iSizeInUchar );
1255  memcpy( rpcCU->getTransformSkip(TEXT_LUMA)     + m_uiAbsIdxInLCU, m_puhTransformSkip[0], iSizeInUchar );
1256  memcpy( rpcCU->getTransformSkip(TEXT_CHROMA_U) + m_uiAbsIdxInLCU, m_puhTransformSkip[1], iSizeInUchar );
1257  memcpy( rpcCU->getTransformSkip(TEXT_CHROMA_V) + m_uiAbsIdxInLCU, m_puhTransformSkip[2], iSizeInUchar );
1258
1259  memcpy( rpcCU->getCbf(TEXT_LUMA)     + m_uiAbsIdxInLCU, m_puhCbf[0], iSizeInUchar );
1260  memcpy( rpcCU->getCbf(TEXT_CHROMA_U) + m_uiAbsIdxInLCU, m_puhCbf[1], iSizeInUchar );
1261  memcpy( rpcCU->getCbf(TEXT_CHROMA_V) + m_uiAbsIdxInLCU, m_puhCbf[2], iSizeInUchar );
1262 
1263#if H_3D_DIM
1264  for( Int i = 0; i < DIM_NUM_TYPE; i++ )
1265  {
1266    memcpy( rpcCU->getDimDeltaDC( i, 0 ) + m_uiAbsIdxInLCU, m_dimDeltaDC[i][0], sizeof(Pel ) * m_uiNumPartition );
1267    memcpy( rpcCU->getDimDeltaDC( i, 1 ) + m_uiAbsIdxInLCU, m_dimDeltaDC[i][1], sizeof(Pel ) * m_uiNumPartition );
1268  }
1269#if H_3D_DIM_DMM
1270  for( Int i = 0; i < DMM_NUM_TYPE; i++ )
1271  {
1272    memcpy( rpcCU->getDmmWedgeTabIdx( i ) + m_uiAbsIdxInLCU, m_dmmWedgeTabIdx[i], sizeof(UInt) * m_uiNumPartition );
1273  }
1274  memcpy( rpcCU->getDmm2DeltaEnd()    + m_uiAbsIdxInLCU, m_dmm2DeltaEnd   , sizeof(Int ) * m_uiNumPartition );
1275  memcpy( rpcCU->getDmm3IntraTabIdx() + m_uiAbsIdxInLCU, m_dmm3IntraTabIdx, sizeof(UInt) * m_uiNumPartition );
1276#endif
1277#if H_3D_DIM_RBC
1278  memcpy( rpcCU->getEdgeCode( m_uiAbsIdxInLCU ),         m_pucEdgeCode,     iSizeInUchar * RBC_MAX_EDGE_NUM_PER_4x4 );
1279  memcpy( rpcCU->getEdgeNumber()      + m_uiAbsIdxInLCU, m_pucEdgeNumber,   iSizeInUchar );
1280  memcpy( rpcCU->getEdgeStartPos()    + m_uiAbsIdxInLCU, m_pucEdgeStartPos, iSizeInUchar );
1281  memcpy( rpcCU->getEdgeLeftFirst()   + m_uiAbsIdxInLCU, m_pbEdgeLeftFirst, iSizeInBool );
1282  memcpy( rpcCU->getEdgePartition( m_uiAbsIdxInLCU ),    m_pbEdgePartition, iSizeInBool * 16 );
1283#endif
1284#if H_3D_DIM_SDC
1285  memcpy( rpcCU->getSDCFlag()             + m_uiAbsIdxInLCU, m_pbSDCFlag,      iSizeInBool  );
1286  memcpy( rpcCU->getSDCSegmentDCOffset(0) + m_uiAbsIdxInLCU, m_apSegmentDCOffset[0], sizeof( Pel ) * m_uiNumPartition);
1287  memcpy( rpcCU->getSDCSegmentDCOffset(1) + m_uiAbsIdxInLCU, m_apSegmentDCOffset[1], sizeof( Pel ) * m_uiNumPartition);
1288#endif
1289#endif
1290
1291  memcpy( rpcCU->getDepth()  + m_uiAbsIdxInLCU, m_puhDepth,  iSizeInUchar );
1292  memcpy( rpcCU->getWidth()  + m_uiAbsIdxInLCU, m_puhWidth,  iSizeInUchar );
1293  memcpy( rpcCU->getHeight() + m_uiAbsIdxInLCU, m_puhHeight, iSizeInUchar );
1294 
1295  memcpy( rpcCU->getMVPIdx(REF_PIC_LIST_0) + m_uiAbsIdxInLCU, m_apiMVPIdx[0], iSizeInUchar );
1296  memcpy( rpcCU->getMVPIdx(REF_PIC_LIST_1) + m_uiAbsIdxInLCU, m_apiMVPIdx[1], iSizeInUchar );
1297  memcpy( rpcCU->getMVPNum(REF_PIC_LIST_0) + m_uiAbsIdxInLCU, m_apiMVPNum[0], iSizeInUchar );
1298  memcpy( rpcCU->getMVPNum(REF_PIC_LIST_1) + m_uiAbsIdxInLCU, m_apiMVPNum[1], iSizeInUchar );
1299 
1300  m_acCUMvField[0].copyTo( rpcCU->getCUMvField( REF_PIC_LIST_0 ), m_uiAbsIdxInLCU );
1301  m_acCUMvField[1].copyTo( rpcCU->getCUMvField( REF_PIC_LIST_1 ), m_uiAbsIdxInLCU );
1302 
1303  memcpy( rpcCU->getIPCMFlag() + m_uiAbsIdxInLCU, m_pbIPCMFlag,         iSizeInBool  );
1304
1305  UInt uiTmp  = (g_uiMaxCUWidth*g_uiMaxCUHeight)>>(uhDepth<<1);
1306  UInt uiTmp2 = m_uiAbsIdxInLCU*m_pcPic->getMinCUWidth()*m_pcPic->getMinCUHeight();
1307  memcpy( rpcCU->getCoeffY()  + uiTmp2, m_pcTrCoeffY,  sizeof(TCoeff)*uiTmp  );
1308#if ADAPTIVE_QP_SELECTION 
1309  memcpy( rpcCU->getArlCoeffY()  + uiTmp2, m_pcArlCoeffY,  sizeof(Int)*uiTmp  );
1310#endif
1311  memcpy( rpcCU->getPCMSampleY() + uiTmp2 , m_pcIPCMSampleY, sizeof(Pel)*uiTmp );
1312
1313  uiTmp >>= 2; uiTmp2 >>= 2;
1314  memcpy( rpcCU->getCoeffCb() + uiTmp2, m_pcTrCoeffCb, sizeof(TCoeff)*uiTmp  );
1315  memcpy( rpcCU->getCoeffCr() + uiTmp2, m_pcTrCoeffCr, sizeof(TCoeff)*uiTmp  );
1316#if ADAPTIVE_QP_SELECTION
1317  memcpy( rpcCU->getArlCoeffCb() + uiTmp2, m_pcArlCoeffCb, sizeof(Int)*uiTmp  );
1318  memcpy( rpcCU->getArlCoeffCr() + uiTmp2, m_pcArlCoeffCr, sizeof(Int)*uiTmp  );
1319#endif
1320  memcpy( rpcCU->getPCMSampleCb() + uiTmp2 , m_pcIPCMSampleCb, sizeof( Pel ) * uiTmp );
1321  memcpy( rpcCU->getPCMSampleCr() + uiTmp2 , m_pcIPCMSampleCr, sizeof( Pel ) * uiTmp );
1322  rpcCU->getTotalBins() = m_uiTotalBins;
1323  memcpy( rpcCU->m_sliceStartCU        + m_uiAbsIdxInLCU, m_sliceStartCU,        sizeof( UInt ) * m_uiNumPartition  );
1324  memcpy( rpcCU->m_sliceSegmentStartCU + m_uiAbsIdxInLCU, m_sliceSegmentStartCU, sizeof( UInt ) * m_uiNumPartition  );
1325}
1326
1327Void TComDataCU::copyToPic( UChar uhDepth, UInt uiPartIdx, UInt uiPartDepth )
1328{
1329  TComDataCU*&  rpcCU       = m_pcPic->getCU( m_uiCUAddr );
1330  UInt          uiQNumPart  = m_uiNumPartition>>(uiPartDepth<<1);
1331 
1332  UInt uiPartStart          = uiPartIdx*uiQNumPart;
1333  UInt uiPartOffset         = m_uiAbsIdxInLCU + uiPartStart;
1334 
1335  rpcCU->getTotalCost()       = m_dTotalCost;
1336  rpcCU->getTotalDistortion() = m_uiTotalDistortion;
1337  rpcCU->getTotalBits()       = m_uiTotalBits;
1338 
1339  Int iSizeInUchar  = sizeof( UChar  ) * uiQNumPart;
1340  Int iSizeInBool   = sizeof( Bool   ) * uiQNumPart;
1341 
1342  Int sizeInChar  = sizeof( Char ) * uiQNumPart;
1343  memcpy( rpcCU->getSkipFlag()       + uiPartOffset, m_skipFlag,   sizeof( *m_skipFlag )   * uiQNumPart );
1344
1345  memcpy( rpcCU->getQP() + uiPartOffset, m_phQP, sizeInChar );
1346  memcpy( rpcCU->getPartitionSize()  + uiPartOffset, m_pePartSize, sizeof( *m_pePartSize ) * uiQNumPart );
1347  memcpy( rpcCU->getPredictionMode() + uiPartOffset, m_pePredMode, sizeof( *m_pePredMode ) * uiQNumPart );
1348  memcpy( rpcCU->getCUTransquantBypass()+ uiPartOffset, m_CUTransquantBypass, sizeof( *m_CUTransquantBypass ) * uiQNumPart );
1349  memcpy( rpcCU->getMergeFlag()         + uiPartOffset, m_pbMergeFlag,         iSizeInBool  );
1350  memcpy( rpcCU->getMergeIndex()        + uiPartOffset, m_puhMergeIndex,       iSizeInUchar );
1351  memcpy( rpcCU->getLumaIntraDir()      + uiPartOffset, m_puhLumaIntraDir,     iSizeInUchar );
1352  memcpy( rpcCU->getChromaIntraDir()    + uiPartOffset, m_puhChromaIntraDir,   iSizeInUchar );
1353  memcpy( rpcCU->getInterDir()          + uiPartOffset, m_puhInterDir,         iSizeInUchar );
1354  memcpy( rpcCU->getTransformIdx()      + uiPartOffset, m_puhTrIdx,            iSizeInUchar );
1355  memcpy( rpcCU->getTransformSkip(TEXT_LUMA)     + uiPartOffset, m_puhTransformSkip[0], iSizeInUchar );
1356  memcpy( rpcCU->getTransformSkip(TEXT_CHROMA_U) + uiPartOffset, m_puhTransformSkip[1], iSizeInUchar );
1357  memcpy( rpcCU->getTransformSkip(TEXT_CHROMA_V) + uiPartOffset, m_puhTransformSkip[2], iSizeInUchar );
1358  memcpy( rpcCU->getCbf(TEXT_LUMA)     + uiPartOffset, m_puhCbf[0], iSizeInUchar );
1359  memcpy( rpcCU->getCbf(TEXT_CHROMA_U) + uiPartOffset, m_puhCbf[1], iSizeInUchar );
1360  memcpy( rpcCU->getCbf(TEXT_CHROMA_V) + uiPartOffset, m_puhCbf[2], iSizeInUchar );
1361 
1362#if H_3D_DIM
1363  for( Int i = 0; i < DMM_NUM_TYPE; i++ )
1364  {
1365    memcpy( rpcCU->getDimDeltaDC( i, 0 ) + uiPartOffset, m_dimDeltaDC[i][0], sizeof(Pel ) * uiQNumPart );
1366    memcpy( rpcCU->getDimDeltaDC( i, 1 ) + uiPartOffset, m_dimDeltaDC[i][1], sizeof(Pel ) * uiQNumPart );
1367  }
1368#if H_3D_DIM_DMM
1369  for( Int i = 0; i < DMM_NUM_TYPE; i++ )
1370  {
1371    memcpy( rpcCU->getDmmWedgeTabIdx( i ) + uiPartOffset, m_dmmWedgeTabIdx[i], sizeof(UInt) * uiQNumPart );
1372  }
1373  memcpy( rpcCU->getDmm2DeltaEnd()    + uiPartOffset, m_dmm2DeltaEnd   , sizeof(Int ) * uiQNumPart );
1374  memcpy( rpcCU->getDmm3IntraTabIdx() + uiPartOffset, m_dmm3IntraTabIdx, sizeof(UInt) * uiQNumPart );
1375#endif
1376#if H_3D_DIM_RBC
1377  memcpy( rpcCU->getEdgeCode( uiPartOffset ),         m_pucEdgeCode,     iSizeInUchar * RBC_MAX_EDGE_NUM_PER_4x4 );
1378  memcpy( rpcCU->getEdgeNumber()      + uiPartOffset, m_pucEdgeNumber,   iSizeInUchar );
1379  memcpy( rpcCU->getEdgeStartPos()    + uiPartOffset, m_pucEdgeStartPos, iSizeInUchar );
1380  memcpy( rpcCU->getEdgeLeftFirst()   + uiPartOffset, m_pbEdgeLeftFirst, iSizeInBool );
1381  memcpy( rpcCU->getEdgePartition( uiPartOffset ),    m_pbEdgePartition, iSizeInBool * 16 );
1382#endif
1383#if H_3D_DIM_SDC
1384  memcpy( rpcCU->getSDCFlag()             + uiPartOffset, m_pbSDCFlag,      iSizeInBool  );
1385  memcpy( rpcCU->getSDCSegmentDCOffset(0) + uiPartOffset, m_apSegmentDCOffset[0], sizeof( Pel ) * uiQNumPart);
1386  memcpy( rpcCU->getSDCSegmentDCOffset(1) + uiPartOffset, m_apSegmentDCOffset[1], sizeof( Pel ) * uiQNumPart);
1387#endif
1388#endif
1389
1390  memcpy( rpcCU->getDepth()  + uiPartOffset, m_puhDepth,  iSizeInUchar );
1391  memcpy( rpcCU->getWidth()  + uiPartOffset, m_puhWidth,  iSizeInUchar );
1392  memcpy( rpcCU->getHeight() + uiPartOffset, m_puhHeight, iSizeInUchar );
1393 
1394  memcpy( rpcCU->getMVPIdx(REF_PIC_LIST_0) + uiPartOffset, m_apiMVPIdx[0], iSizeInUchar );
1395  memcpy( rpcCU->getMVPIdx(REF_PIC_LIST_1) + uiPartOffset, m_apiMVPIdx[1], iSizeInUchar );
1396  memcpy( rpcCU->getMVPNum(REF_PIC_LIST_0) + uiPartOffset, m_apiMVPNum[0], iSizeInUchar );
1397  memcpy( rpcCU->getMVPNum(REF_PIC_LIST_1) + uiPartOffset, m_apiMVPNum[1], iSizeInUchar );
1398  m_acCUMvField[0].copyTo( rpcCU->getCUMvField( REF_PIC_LIST_0 ), m_uiAbsIdxInLCU, uiPartStart, uiQNumPart );
1399  m_acCUMvField[1].copyTo( rpcCU->getCUMvField( REF_PIC_LIST_1 ), m_uiAbsIdxInLCU, uiPartStart, uiQNumPart );
1400 
1401  memcpy( rpcCU->getIPCMFlag() + uiPartOffset, m_pbIPCMFlag,         iSizeInBool  );
1402
1403  UInt uiTmp  = (g_uiMaxCUWidth*g_uiMaxCUHeight)>>((uhDepth+uiPartDepth)<<1);
1404  UInt uiTmp2 = uiPartOffset*m_pcPic->getMinCUWidth()*m_pcPic->getMinCUHeight();
1405  memcpy( rpcCU->getCoeffY()  + uiTmp2, m_pcTrCoeffY,  sizeof(TCoeff)*uiTmp  );
1406#if ADAPTIVE_QP_SELECTION
1407  memcpy( rpcCU->getArlCoeffY()  + uiTmp2, m_pcArlCoeffY,  sizeof(Int)*uiTmp  );
1408#endif
1409 
1410  memcpy( rpcCU->getPCMSampleY() + uiTmp2 , m_pcIPCMSampleY, sizeof( Pel ) * uiTmp );
1411
1412  uiTmp >>= 2; uiTmp2 >>= 2;
1413  memcpy( rpcCU->getCoeffCb() + uiTmp2, m_pcTrCoeffCb, sizeof(TCoeff)*uiTmp  );
1414  memcpy( rpcCU->getCoeffCr() + uiTmp2, m_pcTrCoeffCr, sizeof(TCoeff)*uiTmp  );
1415#if ADAPTIVE_QP_SELECTION
1416  memcpy( rpcCU->getArlCoeffCb() + uiTmp2, m_pcArlCoeffCb, sizeof(Int)*uiTmp  );
1417  memcpy( rpcCU->getArlCoeffCr() + uiTmp2, m_pcArlCoeffCr, sizeof(Int)*uiTmp  );
1418#endif
1419
1420  memcpy( rpcCU->getPCMSampleCb() + uiTmp2 , m_pcIPCMSampleCb, sizeof( Pel ) * uiTmp );
1421  memcpy( rpcCU->getPCMSampleCr() + uiTmp2 , m_pcIPCMSampleCr, sizeof( Pel ) * uiTmp );
1422  rpcCU->getTotalBins() = m_uiTotalBins;
1423  memcpy( rpcCU->m_sliceStartCU        + uiPartOffset, m_sliceStartCU,        sizeof( UInt ) * uiQNumPart  );
1424  memcpy( rpcCU->m_sliceSegmentStartCU + uiPartOffset, m_sliceSegmentStartCU, sizeof( UInt ) * uiQNumPart  );
1425}
1426
1427// --------------------------------------------------------------------------------------------------------------------
1428// Other public functions
1429// --------------------------------------------------------------------------------------------------------------------
1430
1431TComDataCU* TComDataCU::getPULeft( UInt& uiLPartUnitIdx, 
1432                                   UInt uiCurrPartUnitIdx, 
1433                                   Bool bEnforceSliceRestriction, 
1434                                   Bool bEnforceTileRestriction )
1435{
1436  UInt uiAbsPartIdx       = g_auiZscanToRaster[uiCurrPartUnitIdx];
1437  UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[m_uiAbsIdxInLCU];
1438  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1439 
1440  if ( !RasterAddress::isZeroCol( uiAbsPartIdx, uiNumPartInCUWidth ) )
1441  {
1442    uiLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - 1 ];
1443    if ( RasterAddress::isEqualCol( uiAbsPartIdx, uiAbsZorderCUIdx, uiNumPartInCUWidth ) )
1444    {
1445      return m_pcPic->getCU( getAddr() );
1446    }
1447    else
1448    {
1449      uiLPartUnitIdx -= m_uiAbsIdxInLCU;
1450      return this;
1451    }
1452  }
1453 
1454  uiLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx + uiNumPartInCUWidth - 1 ];
1455
1456
1457  if ( (bEnforceSliceRestriction && (m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL || m_pcCULeft->getSCUAddr()+uiLPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)))
1458      ||
1459       (bEnforceTileRestriction && ( m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL || (m_pcPic->getPicSym()->getTileIdxMap( m_pcCULeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))  )  )
1460      )
1461  {
1462    return NULL;
1463  }
1464  return m_pcCULeft;
1465}
1466
1467TComDataCU* TComDataCU::getPUAbove( UInt& uiAPartUnitIdx,
1468                                    UInt uiCurrPartUnitIdx, 
1469                                    Bool bEnforceSliceRestriction, 
1470                                    Bool planarAtLCUBoundary ,
1471                                    Bool bEnforceTileRestriction )
1472{
1473  UInt uiAbsPartIdx       = g_auiZscanToRaster[uiCurrPartUnitIdx];
1474  UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[m_uiAbsIdxInLCU];
1475  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1476 
1477  if ( !RasterAddress::isZeroRow( uiAbsPartIdx, uiNumPartInCUWidth ) )
1478  {
1479    uiAPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - uiNumPartInCUWidth ];
1480    if ( RasterAddress::isEqualRow( uiAbsPartIdx, uiAbsZorderCUIdx, uiNumPartInCUWidth ) )
1481    {
1482      return m_pcPic->getCU( getAddr() );
1483    }
1484    else
1485    {
1486      uiAPartUnitIdx -= m_uiAbsIdxInLCU;
1487      return this;
1488    }
1489  }
1490
1491  if(planarAtLCUBoundary)
1492  {
1493    return NULL;
1494  }
1495 
1496  uiAPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx + m_pcPic->getNumPartInCU() - uiNumPartInCUWidth ];
1497
1498  if ( (bEnforceSliceRestriction && (m_pcCUAbove==NULL || m_pcCUAbove->getSlice()==NULL || m_pcCUAbove->getSCUAddr()+uiAPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)))
1499      ||
1500       (bEnforceTileRestriction &&(m_pcCUAbove==NULL || m_pcCUAbove->getSlice()==NULL || (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAbove->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))))
1501      )
1502  {
1503    return NULL;
1504  }
1505  return m_pcCUAbove;
1506}
1507
1508TComDataCU* TComDataCU::getPUAboveLeft( UInt& uiALPartUnitIdx, UInt uiCurrPartUnitIdx, Bool bEnforceSliceRestriction )
1509{
1510  UInt uiAbsPartIdx       = g_auiZscanToRaster[uiCurrPartUnitIdx];
1511  UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[m_uiAbsIdxInLCU];
1512  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1513 
1514  if ( !RasterAddress::isZeroCol( uiAbsPartIdx, uiNumPartInCUWidth ) )
1515  {
1516    if ( !RasterAddress::isZeroRow( uiAbsPartIdx, uiNumPartInCUWidth ) )
1517    {
1518      uiALPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - uiNumPartInCUWidth - 1 ];
1519      if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdx, uiAbsZorderCUIdx, uiNumPartInCUWidth ) )
1520      {
1521        return m_pcPic->getCU( getAddr() );
1522      }
1523      else
1524      {
1525        uiALPartUnitIdx -= m_uiAbsIdxInLCU;
1526        return this;
1527      }
1528    }
1529    uiALPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx + getPic()->getNumPartInCU() - uiNumPartInCUWidth - 1 ];
1530    if ( (bEnforceSliceRestriction && (m_pcCUAbove==NULL || m_pcCUAbove->getSlice()==NULL ||
1531       m_pcCUAbove->getSCUAddr()+uiALPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1532       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAbove->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1533       ))
1534     )
1535    {
1536      return NULL;
1537    }
1538    return m_pcCUAbove;
1539  }
1540 
1541  if ( !RasterAddress::isZeroRow( uiAbsPartIdx, uiNumPartInCUWidth ) )
1542  {
1543    uiALPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - 1 ];
1544    if ( (bEnforceSliceRestriction && (m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL || 
1545       m_pcCULeft->getSCUAddr()+uiALPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1546       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCULeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1547       ))
1548     )
1549    {
1550      return NULL;
1551    }
1552    return m_pcCULeft;
1553  }
1554 
1555  uiALPartUnitIdx = g_auiRasterToZscan[ m_pcPic->getNumPartInCU() - 1 ];
1556  if ( (bEnforceSliceRestriction && (m_pcCUAboveLeft==NULL || m_pcCUAboveLeft->getSlice()==NULL ||
1557       m_pcCUAboveLeft->getSCUAddr()+uiALPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1558       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAboveLeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1559       ))
1560     )
1561  {
1562    return NULL;
1563  }
1564  return m_pcCUAboveLeft;
1565}
1566
1567TComDataCU* TComDataCU::getPUAboveRight( UInt& uiARPartUnitIdx, UInt uiCurrPartUnitIdx, Bool bEnforceSliceRestriction )
1568{
1569  UInt uiAbsPartIdxRT     = g_auiZscanToRaster[uiCurrPartUnitIdx];
1570  UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + m_puhWidth[0] / m_pcPic->getMinCUWidth() - 1;
1571  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1572 
1573  if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxRT] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )
1574  {
1575    uiARPartUnitIdx = MAX_UINT;
1576    return NULL;
1577  }
1578 
1579  if ( RasterAddress::lessThanCol( uiAbsPartIdxRT, uiNumPartInCUWidth - 1, uiNumPartInCUWidth ) )
1580  {
1581    if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, uiNumPartInCUWidth ) )
1582    {
1583      if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxRT - uiNumPartInCUWidth + 1 ] )
1584      {
1585        uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT - uiNumPartInCUWidth + 1 ];
1586        if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxRT, uiAbsZorderCUIdx, uiNumPartInCUWidth ) )
1587        {
1588          return m_pcPic->getCU( getAddr() );
1589        }
1590        else
1591        {
1592          uiARPartUnitIdx -= m_uiAbsIdxInLCU;
1593          return this;
1594        }
1595      }
1596      uiARPartUnitIdx = MAX_UINT;
1597      return NULL;
1598    }
1599    uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT + m_pcPic->getNumPartInCU() - uiNumPartInCUWidth + 1 ];
1600    if ( (bEnforceSliceRestriction && (m_pcCUAbove==NULL || m_pcCUAbove->getSlice()==NULL ||
1601       m_pcCUAbove->getSCUAddr()+uiARPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1602       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAbove->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1603       ))
1604     )
1605    {
1606      return NULL;
1607    }
1608    return m_pcCUAbove;
1609  }
1610 
1611  if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, uiNumPartInCUWidth ) )
1612  {
1613    uiARPartUnitIdx = MAX_UINT;
1614    return NULL;
1615  }
1616 
1617  uiARPartUnitIdx = g_auiRasterToZscan[ m_pcPic->getNumPartInCU() - uiNumPartInCUWidth ];
1618  if ( (bEnforceSliceRestriction && (m_pcCUAboveRight==NULL || m_pcCUAboveRight->getSlice()==NULL ||
1619       m_pcPic->getPicSym()->getInverseCUOrderMap( m_pcCUAboveRight->getAddr()) > m_pcPic->getPicSym()->getInverseCUOrderMap( getAddr()) ||
1620       m_pcCUAboveRight->getSCUAddr()+uiARPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1621       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAboveRight->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1622       ))
1623     )
1624  {
1625    return NULL;
1626  }
1627  return m_pcCUAboveRight;
1628}
1629
1630TComDataCU* TComDataCU::getPUBelowLeft( UInt& uiBLPartUnitIdx, UInt uiCurrPartUnitIdx, Bool bEnforceSliceRestriction )
1631{
1632  UInt uiAbsPartIdxLB     = g_auiZscanToRaster[uiCurrPartUnitIdx];
1633  UInt uiAbsZorderCUIdxLB = g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + (m_puhHeight[0] / m_pcPic->getMinCUHeight() - 1)*m_pcPic->getNumPartInWidth();
1634  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1635 
1636  if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxLB] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
1637  {
1638    uiBLPartUnitIdx = MAX_UINT;
1639    return NULL;
1640  }
1641 
1642  if ( RasterAddress::lessThanRow( uiAbsPartIdxLB, m_pcPic->getNumPartInHeight() - 1, uiNumPartInCUWidth ) )
1643  {
1644    if ( !RasterAddress::isZeroCol( uiAbsPartIdxLB, uiNumPartInCUWidth ) )
1645    {
1646      if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxLB + uiNumPartInCUWidth - 1 ] )
1647      {
1648        uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + uiNumPartInCUWidth - 1 ];
1649        if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxLB, uiAbsZorderCUIdxLB, uiNumPartInCUWidth ) )
1650        {
1651          return m_pcPic->getCU( getAddr() );
1652        }
1653        else
1654        {
1655          uiBLPartUnitIdx -= m_uiAbsIdxInLCU;
1656          return this;
1657        }
1658      }
1659      uiBLPartUnitIdx = MAX_UINT;
1660      return NULL;
1661    }
1662    uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + uiNumPartInCUWidth*2 - 1 ];
1663    if ( (bEnforceSliceRestriction && (m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL || 
1664       m_pcCULeft->getSCUAddr()+uiBLPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1665       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCULeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1666       ))
1667     )
1668    {
1669      return NULL;
1670    }
1671    return m_pcCULeft;
1672  }
1673 
1674  uiBLPartUnitIdx = MAX_UINT;
1675  return NULL;
1676}
1677
1678TComDataCU* TComDataCU::getPUBelowLeftAdi(UInt& uiBLPartUnitIdx,  UInt uiCurrPartUnitIdx, UInt uiPartUnitOffset, Bool bEnforceSliceRestriction )
1679{
1680  UInt uiAbsPartIdxLB     = g_auiZscanToRaster[uiCurrPartUnitIdx];
1681  UInt uiAbsZorderCUIdxLB = g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + ((m_puhHeight[0] / m_pcPic->getMinCUHeight()) - 1)*m_pcPic->getNumPartInWidth();
1682  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1683 
1684  if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxLB] + (m_pcPic->getPicSym()->getMinCUHeight() * uiPartUnitOffset)) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples())
1685  {
1686    uiBLPartUnitIdx = MAX_UINT;
1687    return NULL;
1688  }
1689 
1690  if ( RasterAddress::lessThanRow( uiAbsPartIdxLB, m_pcPic->getNumPartInHeight() - uiPartUnitOffset, uiNumPartInCUWidth ) )
1691  {
1692    if ( !RasterAddress::isZeroCol( uiAbsPartIdxLB, uiNumPartInCUWidth ) )
1693    {
1694      if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxLB + uiPartUnitOffset * uiNumPartInCUWidth - 1 ] )
1695      {
1696        uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + uiPartUnitOffset * uiNumPartInCUWidth - 1 ];
1697        if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxLB, uiAbsZorderCUIdxLB, uiNumPartInCUWidth ) )
1698        {
1699          return m_pcPic->getCU( getAddr() );
1700        }
1701        else
1702        {
1703          uiBLPartUnitIdx -= m_uiAbsIdxInLCU;
1704          return this;
1705        }
1706      }
1707      uiBLPartUnitIdx = MAX_UINT;
1708      return NULL;
1709    }
1710    uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + (1+uiPartUnitOffset) * uiNumPartInCUWidth - 1 ];
1711    if ( (bEnforceSliceRestriction && (m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL || 
1712       m_pcCULeft->getSCUAddr()+uiBLPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1713       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCULeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1714       ))
1715     )
1716    {
1717      return NULL;
1718    }
1719    return m_pcCULeft;
1720  }
1721 
1722  uiBLPartUnitIdx = MAX_UINT;
1723  return NULL;
1724}
1725
1726TComDataCU* TComDataCU::getPUAboveRightAdi(UInt&  uiARPartUnitIdx, UInt uiCurrPartUnitIdx, UInt uiPartUnitOffset, 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->getPicSym()->getMinCUHeight() * uiPartUnitOffset)) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )
1733  {
1734    uiARPartUnitIdx = MAX_UINT;
1735    return NULL;
1736  }
1737 
1738  if ( RasterAddress::lessThanCol( uiAbsPartIdxRT, uiNumPartInCUWidth - uiPartUnitOffset, uiNumPartInCUWidth ) )
1739  {
1740    if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, uiNumPartInCUWidth ) )
1741    {
1742      if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxRT - uiNumPartInCUWidth + uiPartUnitOffset ] )
1743      {
1744        uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT - uiNumPartInCUWidth + uiPartUnitOffset ];
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 + uiPartUnitOffset ];
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 + uiPartUnitOffset-1 ];
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
1789/** Get left QpMinCu
1790*\param   uiLPartUnitIdx
1791*\param   uiCurrAbsIdxInLCU
1792*\returns TComDataCU*   point of TComDataCU of left QpMinCu
1793*/
1794TComDataCU* TComDataCU::getQpMinCuLeft( UInt& uiLPartUnitIdx, UInt uiCurrAbsIdxInLCU)
1795{
1796  UInt numPartInCUWidth = m_pcPic->getNumPartInWidth();
1797  UInt absZorderQpMinCUIdx = (uiCurrAbsIdxInLCU>>((g_uiMaxCUDepth - getSlice()->getPPS()->getMaxCuDQPDepth())<<1))<<((g_uiMaxCUDepth -getSlice()->getPPS()->getMaxCuDQPDepth())<<1);
1798  UInt absRorderQpMinCUIdx = g_auiZscanToRaster[absZorderQpMinCUIdx];
1799
1800  // check for left LCU boundary
1801  if ( RasterAddress::isZeroCol(absRorderQpMinCUIdx, numPartInCUWidth) )
1802  {
1803    return NULL;
1804  }
1805
1806  // get index of left-CU relative to top-left corner of current quantization group
1807  uiLPartUnitIdx = g_auiRasterToZscan[absRorderQpMinCUIdx - 1];
1808
1809  // return pointer to current LCU
1810  return m_pcPic->getCU( getAddr() );
1811}
1812
1813/** Get Above QpMinCu
1814*\param   aPartUnitIdx
1815*\param   currAbsIdxInLCU
1816*\returns TComDataCU*   point of TComDataCU of above QpMinCu
1817*/
1818TComDataCU* TComDataCU::getQpMinCuAbove( UInt& aPartUnitIdx, UInt currAbsIdxInLCU )
1819{
1820  UInt numPartInCUWidth = m_pcPic->getNumPartInWidth();
1821  UInt absZorderQpMinCUIdx = (currAbsIdxInLCU>>((g_uiMaxCUDepth - getSlice()->getPPS()->getMaxCuDQPDepth())<<1))<<((g_uiMaxCUDepth - getSlice()->getPPS()->getMaxCuDQPDepth())<<1);
1822  UInt absRorderQpMinCUIdx = g_auiZscanToRaster[absZorderQpMinCUIdx];
1823
1824  // check for top LCU boundary
1825  if ( RasterAddress::isZeroRow( absRorderQpMinCUIdx, numPartInCUWidth) )
1826  {
1827    return NULL;
1828  }
1829
1830  // get index of top-CU relative to top-left corner of current quantization group
1831  aPartUnitIdx = g_auiRasterToZscan[absRorderQpMinCUIdx - numPartInCUWidth];
1832
1833  // return pointer to current LCU
1834  return m_pcPic->getCU( getAddr() );
1835}
1836
1837/** Get reference QP from left QpMinCu or latest coded QP
1838*\param   uiCurrAbsIdxInLCU
1839*\returns Char   reference QP value
1840*/
1841Char TComDataCU::getRefQP( UInt uiCurrAbsIdxInLCU )
1842{
1843  UInt        lPartIdx = 0, aPartIdx = 0;
1844  TComDataCU* cULeft  = getQpMinCuLeft ( lPartIdx, m_uiAbsIdxInLCU + uiCurrAbsIdxInLCU );
1845  TComDataCU* cUAbove = getQpMinCuAbove( aPartIdx, m_uiAbsIdxInLCU + uiCurrAbsIdxInLCU );
1846  return (((cULeft? cULeft->getQP( lPartIdx ): getLastCodedQP( uiCurrAbsIdxInLCU )) + (cUAbove? cUAbove->getQP( aPartIdx ): getLastCodedQP( uiCurrAbsIdxInLCU )) + 1) >> 1);
1847}
1848
1849Int TComDataCU::getLastValidPartIdx( Int iAbsPartIdx )
1850{
1851  Int iLastValidPartIdx = iAbsPartIdx-1;
1852  while ( iLastValidPartIdx >= 0
1853       && getPredictionMode( iLastValidPartIdx ) == MODE_NONE )
1854  {
1855    UInt uiDepth = getDepth( iLastValidPartIdx );
1856    iLastValidPartIdx -= m_uiNumPartition>>(uiDepth<<1);
1857  }
1858  return iLastValidPartIdx;
1859}
1860
1861Char TComDataCU::getLastCodedQP( UInt uiAbsPartIdx )
1862{
1863  UInt uiQUPartIdxMask = ~((1<<((g_uiMaxCUDepth - getSlice()->getPPS()->getMaxCuDQPDepth())<<1))-1);
1864  Int iLastValidPartIdx = getLastValidPartIdx( uiAbsPartIdx&uiQUPartIdxMask );
1865  if ( uiAbsPartIdx < m_uiNumPartition
1866    && (getSCUAddr()+iLastValidPartIdx < getSliceStartCU(m_uiAbsIdxInLCU+uiAbsPartIdx)))
1867  {
1868    return getSlice()->getSliceQp();
1869  }
1870  else
1871  if ( iLastValidPartIdx >= 0 )
1872  {
1873    return getQP( iLastValidPartIdx );
1874  }
1875  else
1876  {
1877    if ( getZorderIdxInCU() > 0 )
1878    {
1879      return getPic()->getCU( getAddr() )->getLastCodedQP( getZorderIdxInCU() );
1880    }
1881    else if ( getPic()->getPicSym()->getInverseCUOrderMap(getAddr()) > 0
1882      && getPic()->getPicSym()->getTileIdxMap(getAddr()) == getPic()->getPicSym()->getTileIdxMap(getPic()->getPicSym()->getCUOrderMap(getPic()->getPicSym()->getInverseCUOrderMap(getAddr())-1))
1883      && !( getSlice()->getPPS()->getEntropyCodingSyncEnabledFlag() && getAddr() % getPic()->getFrameWidthInCU() == 0 ) )
1884    {
1885      return getPic()->getCU( getPic()->getPicSym()->getCUOrderMap(getPic()->getPicSym()->getInverseCUOrderMap(getAddr())-1) )->getLastCodedQP( getPic()->getNumPartInCU() );
1886    }
1887    else
1888    {
1889      return getSlice()->getSliceQp();
1890    }
1891  }
1892}
1893/** Check whether the CU is coded in lossless coding mode
1894 * \param   uiAbsPartIdx
1895 * \returns true if the CU is coded in lossless coding mode; false if otherwise
1896 */
1897Bool TComDataCU::isLosslessCoded(UInt absPartIdx)
1898{
1899  return (getSlice()->getPPS()->getTransquantBypassEnableFlag() && getCUTransquantBypass (absPartIdx));
1900}
1901
1902/** Get allowed chroma intra modes
1903*\param   uiAbsPartIdx
1904*\param   uiModeList  pointer to chroma intra modes array
1905*\returns
1906*- fill uiModeList with chroma intra modes
1907*/
1908Void TComDataCU::getAllowedChromaDir( UInt uiAbsPartIdx, UInt* uiModeList )
1909{
1910  uiModeList[0] = PLANAR_IDX;
1911  uiModeList[1] = VER_IDX;
1912  uiModeList[2] = HOR_IDX;
1913  uiModeList[3] = DC_IDX;
1914  uiModeList[4] = DM_CHROMA_IDX;
1915
1916  UInt uiLumaMode = getLumaIntraDir( uiAbsPartIdx );
1917
1918  for( Int i = 0; i < NUM_CHROMA_MODE - 1; i++ )
1919  {
1920    if( uiLumaMode == uiModeList[i] )
1921    {
1922      uiModeList[i] = 34; // VER+8 mode
1923      break;
1924    }
1925  }
1926}
1927
1928/** Get most probable intra modes
1929*\param   uiAbsPartIdx
1930*\param   uiIntraDirPred  pointer to the array for MPM storage
1931*\param   piMode          it is set with MPM mode in case both MPM are equal. It is used to restrict RD search at encode side.
1932*\returns Number of MPM
1933*/
1934Int TComDataCU::getIntraDirLumaPredictor( UInt uiAbsPartIdx, Int* uiIntraDirPred, Int* piMode  )
1935{
1936  TComDataCU* pcTempCU;
1937  UInt        uiTempPartIdx;
1938  Int         iLeftIntraDir, iAboveIntraDir;
1939  Int         uiPredNum = 0;
1940 
1941  // Get intra direction of left PU
1942  pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
1943 
1944  iLeftIntraDir  = pcTempCU ? ( pcTempCU->isIntra( uiTempPartIdx ) ? pcTempCU->getLumaIntraDir( uiTempPartIdx ) : DC_IDX ) : DC_IDX;
1945#if H_3D_DIM
1946  mapDepthModeToIntraDir( iLeftIntraDir );
1947#endif
1948 
1949  // Get intra direction of above PU
1950  pcTempCU = getPUAbove( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx, true, true );
1951 
1952  iAboveIntraDir = pcTempCU ? ( pcTempCU->isIntra( uiTempPartIdx ) ? pcTempCU->getLumaIntraDir( uiTempPartIdx ) : DC_IDX ) : DC_IDX;
1953#if H_3D_DIM
1954  mapDepthModeToIntraDir( iAboveIntraDir );
1955#endif
1956 
1957  uiPredNum = 3;
1958  if(iLeftIntraDir == iAboveIntraDir)
1959  {
1960    if( piMode )
1961    {
1962      *piMode = 1;
1963    }
1964   
1965    if (iLeftIntraDir > 1) // angular modes
1966    {
1967      uiIntraDirPred[0] = iLeftIntraDir;
1968      uiIntraDirPred[1] = ((iLeftIntraDir + 29) % 32) + 2;
1969      uiIntraDirPred[2] = ((iLeftIntraDir - 1 ) % 32) + 2;
1970    }
1971    else //non-angular
1972    {
1973      uiIntraDirPred[0] = PLANAR_IDX;
1974      uiIntraDirPred[1] = DC_IDX;
1975      uiIntraDirPred[2] = VER_IDX; 
1976    }
1977  }
1978  else
1979  {
1980    if( piMode )
1981    {
1982      *piMode = 2;
1983    }
1984    uiIntraDirPred[0] = iLeftIntraDir;
1985    uiIntraDirPred[1] = iAboveIntraDir;
1986   
1987    if (iLeftIntraDir && iAboveIntraDir ) //both modes are non-planar
1988    {
1989      uiIntraDirPred[2] = PLANAR_IDX;
1990    }
1991    else
1992    {
1993      uiIntraDirPred[2] =  (iLeftIntraDir+iAboveIntraDir)<2? VER_IDX : DC_IDX;
1994    }
1995  }
1996 
1997  return uiPredNum;
1998}
1999
2000UInt TComDataCU::getCtxSplitFlag( UInt uiAbsPartIdx, UInt uiDepth )
2001{
2002  TComDataCU* pcTempCU;
2003  UInt        uiTempPartIdx;
2004  UInt        uiCtx;
2005  // Get left split flag
2006  pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
2007  uiCtx  = ( pcTempCU ) ? ( ( pcTempCU->getDepth( uiTempPartIdx ) > uiDepth ) ? 1 : 0 ) : 0;
2008 
2009  // Get above split flag
2010  pcTempCU = getPUAbove( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
2011  uiCtx += ( pcTempCU ) ? ( ( pcTempCU->getDepth( uiTempPartIdx ) > uiDepth ) ? 1 : 0 ) : 0;
2012 
2013  return uiCtx;
2014}
2015
2016UInt TComDataCU::getCtxQtCbf( TextType eType, UInt uiTrDepth )
2017{
2018  if( eType )
2019  {
2020    return uiTrDepth;
2021  }
2022  else
2023  {
2024    const UInt uiCtx = ( uiTrDepth == 0 ? 1 : 0 );
2025    return uiCtx;
2026  }
2027}
2028
2029UInt TComDataCU::getQuadtreeTULog2MinSizeInCU( UInt absPartIdx )
2030{
2031  UInt log2CbSize = g_aucConvertToBit[getWidth( absPartIdx )] + 2;
2032  PartSize  partSize  = getPartitionSize( absPartIdx );
2033  UInt quadtreeTUMaxDepth = getPredictionMode( absPartIdx ) == MODE_INTRA ? m_pcSlice->getSPS()->getQuadtreeTUMaxDepthIntra() : m_pcSlice->getSPS()->getQuadtreeTUMaxDepthInter(); 
2034  Int intraSplitFlag = ( getPredictionMode( absPartIdx ) == MODE_INTRA && partSize == SIZE_NxN ) ? 1 : 0;
2035  Int interSplitFlag = ((quadtreeTUMaxDepth == 1) && (getPredictionMode( absPartIdx ) == MODE_INTER) && (partSize != SIZE_2Nx2N) );
2036 
2037  UInt log2MinTUSizeInCU = 0;
2038  if (log2CbSize < (m_pcSlice->getSPS()->getQuadtreeTULog2MinSize() + quadtreeTUMaxDepth - 1 + interSplitFlag + intraSplitFlag) ) 
2039  {
2040    // when fully making use of signaled TUMaxDepth + inter/intraSplitFlag, resulting luma TB size is < QuadtreeTULog2MinSize
2041    log2MinTUSizeInCU = m_pcSlice->getSPS()->getQuadtreeTULog2MinSize();
2042  }
2043  else
2044  {
2045    // when fully making use of signaled TUMaxDepth + inter/intraSplitFlag, resulting luma TB size is still >= QuadtreeTULog2MinSize
2046    log2MinTUSizeInCU = log2CbSize - ( quadtreeTUMaxDepth - 1 + interSplitFlag + intraSplitFlag); // stop when trafoDepth == hierarchy_depth = splitFlag
2047    if ( log2MinTUSizeInCU > m_pcSlice->getSPS()->getQuadtreeTULog2MaxSize())
2048    {
2049      // when fully making use of signaled TUMaxDepth + inter/intraSplitFlag, resulting luma TB size is still > QuadtreeTULog2MaxSize
2050      log2MinTUSizeInCU = m_pcSlice->getSPS()->getQuadtreeTULog2MaxSize();
2051    } 
2052  }
2053  return log2MinTUSizeInCU;
2054}
2055
2056UInt TComDataCU::getCtxSkipFlag( UInt uiAbsPartIdx )
2057{
2058  TComDataCU* pcTempCU;
2059  UInt        uiTempPartIdx;
2060  UInt        uiCtx = 0;
2061 
2062  // Get BCBP of left PU
2063  pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
2064  uiCtx    = ( pcTempCU ) ? pcTempCU->isSkipped( uiTempPartIdx ) : 0;
2065 
2066  // Get BCBP of above PU
2067  pcTempCU = getPUAbove( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
2068  uiCtx   += ( pcTempCU ) ? pcTempCU->isSkipped( uiTempPartIdx ) : 0;
2069 
2070  return uiCtx;
2071}
2072
2073UInt TComDataCU::getCtxInterDir( UInt uiAbsPartIdx )
2074{
2075  return getDepth( uiAbsPartIdx );
2076}
2077
2078Void TComDataCU::setCbfSubParts( UInt uiCbfY, UInt uiCbfU, UInt uiCbfV, UInt uiAbsPartIdx, UInt uiDepth )
2079{
2080  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2081  memset( m_puhCbf[0] + uiAbsPartIdx, uiCbfY, sizeof( UChar ) * uiCurrPartNumb );
2082  memset( m_puhCbf[1] + uiAbsPartIdx, uiCbfU, sizeof( UChar ) * uiCurrPartNumb );
2083  memset( m_puhCbf[2] + uiAbsPartIdx, uiCbfV, sizeof( UChar ) * uiCurrPartNumb );
2084}
2085
2086Void TComDataCU::setCbfSubParts( UInt uiCbf, TextType eTType, UInt uiAbsPartIdx, UInt uiDepth )
2087{
2088  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2089  memset( m_puhCbf[g_aucConvertTxtTypeToIdx[eTType]] + uiAbsPartIdx, uiCbf, sizeof( UChar ) * uiCurrPartNumb );
2090}
2091
2092/** Sets a coded block flag for all sub-partitions of a partition
2093 * \param uiCbf The value of the coded block flag to be set
2094 * \param eTType
2095 * \param uiAbsPartIdx
2096 * \param uiPartIdx
2097 * \param uiDepth
2098 * \returns Void
2099 */
2100Void TComDataCU::setCbfSubParts ( UInt uiCbf, TextType eTType, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
2101{
2102  setSubPart<UChar>( uiCbf, m_puhCbf[g_aucConvertTxtTypeToIdx[eTType]], uiAbsPartIdx, uiDepth, uiPartIdx );
2103}
2104
2105Void TComDataCU::setDepthSubParts( UInt uiDepth, UInt uiAbsPartIdx )
2106{
2107  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2108  memset( m_puhDepth + uiAbsPartIdx, uiDepth, sizeof(UChar)*uiCurrPartNumb );
2109}
2110
2111Bool TComDataCU::isFirstAbsZorderIdxInDepth (UInt uiAbsPartIdx, UInt uiDepth)
2112{
2113  UInt uiPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2114  return (((m_uiAbsIdxInLCU + uiAbsPartIdx)% uiPartNumb) == 0);
2115}
2116
2117Void TComDataCU::setPartSizeSubParts( PartSize eMode, UInt uiAbsPartIdx, UInt uiDepth )
2118{
2119  assert( sizeof( *m_pePartSize) == 1 );
2120  memset( m_pePartSize + uiAbsPartIdx, eMode, m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ) );
2121}
2122
2123Void TComDataCU::setCUTransquantBypassSubParts( Bool flag, UInt uiAbsPartIdx, UInt uiDepth )
2124{
2125  memset( m_CUTransquantBypass + uiAbsPartIdx, flag, m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ) );
2126}
2127
2128Void TComDataCU::setSkipFlagSubParts( Bool skip, UInt absPartIdx, UInt depth )
2129{
2130  assert( sizeof( *m_skipFlag) == 1 );
2131  memset( m_skipFlag + absPartIdx, skip, m_pcPic->getNumPartInCU() >> ( 2 * depth ) );
2132}
2133
2134Void TComDataCU::setPredModeSubParts( PredMode eMode, UInt uiAbsPartIdx, UInt uiDepth )
2135{
2136  assert( sizeof( *m_pePredMode) == 1 );
2137  memset( m_pePredMode + uiAbsPartIdx, eMode, m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ) );
2138}
2139
2140Void TComDataCU::setQPSubCUs( Int qp, TComDataCU* pcCU, UInt absPartIdx, UInt depth, Bool &foundNonZeroCbf )
2141{
2142  UInt currPartNumb = m_pcPic->getNumPartInCU() >> (depth << 1);
2143  UInt currPartNumQ = currPartNumb >> 2;
2144
2145  if(!foundNonZeroCbf)
2146  {
2147    if(pcCU->getDepth(absPartIdx) > depth)
2148    {
2149      for ( UInt partUnitIdx = 0; partUnitIdx < 4; partUnitIdx++ )
2150      {
2151        pcCU->setQPSubCUs( qp, pcCU, absPartIdx+partUnitIdx*currPartNumQ, depth+1, foundNonZeroCbf );
2152      }
2153    }
2154    else
2155    {
2156      if(pcCU->getCbf( absPartIdx, TEXT_LUMA ) || pcCU->getCbf( absPartIdx, TEXT_CHROMA_U ) || pcCU->getCbf( absPartIdx, TEXT_CHROMA_V ) )
2157      {
2158        foundNonZeroCbf = true;
2159      }
2160      else
2161      {
2162        setQPSubParts(qp, absPartIdx, depth);
2163      }
2164    }
2165  }
2166}
2167
2168Void TComDataCU::setQPSubParts( Int qp, UInt uiAbsPartIdx, UInt uiDepth )
2169{
2170  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2171  TComSlice * pcSlice = getPic()->getSlice(getPic()->getCurrSliceIdx());
2172
2173  for(UInt uiSCUIdx = uiAbsPartIdx; uiSCUIdx < uiAbsPartIdx+uiCurrPartNumb; uiSCUIdx++)
2174  {
2175    if( m_pcPic->getCU( getAddr() )->getSliceSegmentStartCU(uiSCUIdx+getZorderIdxInCU()) == pcSlice->getSliceSegmentCurStartCUAddr() )
2176    {
2177      m_phQP[uiSCUIdx] = qp;
2178    }
2179  }
2180}
2181
2182Void TComDataCU::setLumaIntraDirSubParts( UInt uiDir, UInt uiAbsPartIdx, UInt uiDepth )
2183{
2184  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2185 
2186  memset( m_puhLumaIntraDir + uiAbsPartIdx, uiDir, sizeof(UChar)*uiCurrPartNumb );
2187}
2188
2189template<typename T>
2190Void TComDataCU::setSubPart( T uiParameter, T* puhBaseLCU, UInt uiCUAddr, UInt uiCUDepth, UInt uiPUIdx )
2191{
2192  assert( sizeof(T) == 1 ); // Using memset() works only for types of size 1
2193 
2194  UInt uiCurrPartNumQ = (m_pcPic->getNumPartInCU() >> (2 * uiCUDepth)) >> 2;
2195  switch ( m_pePartSize[ uiCUAddr ] )
2196  {
2197    case SIZE_2Nx2N:
2198      memset( puhBaseLCU + uiCUAddr, uiParameter, 4 * uiCurrPartNumQ );
2199      break;
2200    case SIZE_2NxN:
2201      memset( puhBaseLCU + uiCUAddr, uiParameter, 2 * uiCurrPartNumQ );
2202      break;
2203    case SIZE_Nx2N:
2204      memset( puhBaseLCU + uiCUAddr, uiParameter, uiCurrPartNumQ );
2205      memset( puhBaseLCU + uiCUAddr + 2 * uiCurrPartNumQ, uiParameter, uiCurrPartNumQ );
2206      break;
2207    case SIZE_NxN:
2208      memset( puhBaseLCU + uiCUAddr, uiParameter, uiCurrPartNumQ ); 
2209      break;
2210    case SIZE_2NxnU:
2211      if ( uiPUIdx == 0 )
2212      {
2213        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 1) );                     
2214        memset( puhBaseLCU + uiCUAddr + uiCurrPartNumQ, uiParameter, (uiCurrPartNumQ >> 1) );                     
2215      }
2216      else if ( uiPUIdx == 1 )
2217      {
2218        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 1) );                     
2219        memset( puhBaseLCU + uiCUAddr + uiCurrPartNumQ, uiParameter, ((uiCurrPartNumQ >> 1) + (uiCurrPartNumQ << 1)) );                     
2220      }
2221      else
2222      {
2223        assert(0);
2224      }
2225      break;
2226    case SIZE_2NxnD:
2227      if ( uiPUIdx == 0 )
2228      {
2229        memset( puhBaseLCU + uiCUAddr, uiParameter, ((uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1)) );                     
2230        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + uiCurrPartNumQ, uiParameter, (uiCurrPartNumQ >> 1) );                     
2231      }
2232      else if ( uiPUIdx == 1 )
2233      {
2234        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 1) );                     
2235        memset( puhBaseLCU + uiCUAddr + uiCurrPartNumQ, uiParameter, (uiCurrPartNumQ >> 1) );                     
2236      }
2237      else
2238      {
2239        assert(0);
2240      }
2241      break;
2242    case SIZE_nLx2N:
2243      if ( uiPUIdx == 0 )
2244      {
2245        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 2) );
2246        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) ); 
2247        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ >> 2) ); 
2248        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) ); 
2249      }
2250      else if ( uiPUIdx == 1 )
2251      {
2252        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 2) );
2253        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) ); 
2254        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ >> 2) ); 
2255        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) ); 
2256      }
2257      else
2258      {
2259        assert(0);
2260      }
2261      break;
2262    case SIZE_nRx2N:
2263      if ( uiPUIdx == 0 )
2264      {     
2265        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) );                           
2266        memset( puhBaseLCU + uiCUAddr + uiCurrPartNumQ + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );                           
2267        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) );                           
2268        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + uiCurrPartNumQ + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );                           
2269      }
2270      else if ( uiPUIdx == 1 )
2271      {
2272        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 2) );                           
2273        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );                           
2274        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ >> 2) );                           
2275        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );                         
2276      }
2277      else
2278      {
2279        assert(0);
2280      }
2281      break;
2282    default:
2283      assert( 0 );
2284  }
2285}
2286
2287#if H_3D_DIM_SDC
2288Void TComDataCU::setSDCFlagSubParts ( Bool bSDCFlag, UInt uiAbsPartIdx, UInt uiDepth )
2289{
2290  assert( sizeof( *m_pbSDCFlag) == 1 );
2291  memset( m_pbSDCFlag + uiAbsPartIdx, bSDCFlag, m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ) );
2292}
2293
2294Bool TComDataCU::getSDCAvailable( UInt uiAbsPartIdx )
2295{
2296  // check general CU information
2297  if( !getSlice()->getIsDepth() || !isIntra(uiAbsPartIdx) || getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N )
2298    return false;
2299 
2300  // check prediction mode
2301  UInt uiLumaPredMode = getLumaIntraDir( uiAbsPartIdx ); 
2302  if( uiLumaPredMode == DC_IDX || uiLumaPredMode == PLANAR_IDX || ( getDimType( uiLumaPredMode ) == DMM1_IDX && !isDimDeltaDC( uiLumaPredMode ) ) )
2303    return true;
2304 
2305  // else
2306  return false;
2307}
2308#endif
2309
2310Void TComDataCU::setMergeFlagSubParts ( Bool bMergeFlag, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
2311{
2312  setSubPart( bMergeFlag, m_pbMergeFlag, uiAbsPartIdx, uiDepth, uiPartIdx );
2313}
2314
2315Void TComDataCU::setMergeIndexSubParts ( UInt uiMergeIndex, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
2316{
2317  setSubPart<UChar>( uiMergeIndex, m_puhMergeIndex, uiAbsPartIdx, uiDepth, uiPartIdx );
2318}
2319
2320Void TComDataCU::setChromIntraDirSubParts( UInt uiDir, UInt uiAbsPartIdx, UInt uiDepth )
2321{
2322  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2323 
2324  memset( m_puhChromaIntraDir + uiAbsPartIdx, uiDir, sizeof(UChar)*uiCurrPartNumb );
2325}
2326
2327Void TComDataCU::setInterDirSubParts( UInt uiDir, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
2328{
2329  setSubPart<UChar>( uiDir, m_puhInterDir, uiAbsPartIdx, uiDepth, uiPartIdx );
2330}
2331
2332Void TComDataCU::setMVPIdxSubParts( Int iMVPIdx, RefPicList eRefPicList, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
2333{
2334  setSubPart<Char>( iMVPIdx, m_apiMVPIdx[eRefPicList], uiAbsPartIdx, uiDepth, uiPartIdx );
2335}
2336
2337Void TComDataCU::setMVPNumSubParts( Int iMVPNum, RefPicList eRefPicList, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
2338{
2339  setSubPart<Char>( iMVPNum, m_apiMVPNum[eRefPicList], uiAbsPartIdx, uiDepth, uiPartIdx );
2340}
2341
2342
2343Void TComDataCU::setTrIdxSubParts( UInt uiTrIdx, UInt uiAbsPartIdx, UInt uiDepth )
2344{
2345  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2346 
2347  memset( m_puhTrIdx + uiAbsPartIdx, uiTrIdx, sizeof(UChar)*uiCurrPartNumb );
2348}
2349
2350Void TComDataCU::setTransformSkipSubParts( UInt useTransformSkipY, UInt useTransformSkipU, UInt useTransformSkipV, UInt uiAbsPartIdx, UInt uiDepth )
2351{
2352  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2353
2354  memset( m_puhTransformSkip[0] + uiAbsPartIdx, useTransformSkipY, sizeof( UChar ) * uiCurrPartNumb );
2355  memset( m_puhTransformSkip[1] + uiAbsPartIdx, useTransformSkipU, sizeof( UChar ) * uiCurrPartNumb );
2356  memset( m_puhTransformSkip[2] + uiAbsPartIdx, useTransformSkipV, sizeof( UChar ) * uiCurrPartNumb );
2357}
2358
2359Void TComDataCU::setTransformSkipSubParts( UInt useTransformSkip, TextType eType, UInt uiAbsPartIdx, UInt uiDepth)
2360{
2361  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2362
2363  memset( m_puhTransformSkip[g_aucConvertTxtTypeToIdx[eType]] + uiAbsPartIdx, useTransformSkip, sizeof( UChar ) * uiCurrPartNumb );
2364}
2365
2366Void TComDataCU::setSizeSubParts( UInt uiWidth, UInt uiHeight, UInt uiAbsPartIdx, UInt uiDepth )
2367{
2368  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2369 
2370  memset( m_puhWidth  + uiAbsPartIdx, uiWidth,  sizeof(UChar)*uiCurrPartNumb );
2371  memset( m_puhHeight + uiAbsPartIdx, uiHeight, sizeof(UChar)*uiCurrPartNumb );
2372}
2373
2374UChar TComDataCU::getNumPartInter()
2375{
2376  UChar iNumPart = 0;
2377 
2378  switch ( m_pePartSize[0] )
2379  {
2380    case SIZE_2Nx2N:    iNumPart = 1; break;
2381    case SIZE_2NxN:     iNumPart = 2; break;
2382    case SIZE_Nx2N:     iNumPart = 2; break;
2383    case SIZE_NxN:      iNumPart = 4; break;
2384    case SIZE_2NxnU:    iNumPart = 2; break;
2385    case SIZE_2NxnD:    iNumPart = 2; break;
2386    case SIZE_nLx2N:    iNumPart = 2; break;
2387    case SIZE_nRx2N:    iNumPart = 2; break;
2388    default:            assert (0);   break;
2389  }
2390 
2391  return  iNumPart;
2392}
2393
2394Void TComDataCU::getPartIndexAndSize( UInt uiPartIdx, UInt& ruiPartAddr, Int& riWidth, Int& riHeight )
2395{
2396  switch ( m_pePartSize[0] )
2397  {
2398    case SIZE_2NxN:
2399      riWidth = getWidth(0);      riHeight = getHeight(0) >> 1; ruiPartAddr = ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 1;
2400      break;
2401    case SIZE_Nx2N:
2402      riWidth = getWidth(0) >> 1; riHeight = getHeight(0);      ruiPartAddr = ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 2;
2403      break;
2404    case SIZE_NxN:
2405      riWidth = getWidth(0) >> 1; riHeight = getHeight(0) >> 1; ruiPartAddr = ( m_uiNumPartition >> 2 ) * uiPartIdx;
2406      break;
2407    case SIZE_2NxnU:
2408      riWidth     = getWidth(0);
2409      riHeight    = ( uiPartIdx == 0 ) ?  getHeight(0) >> 2 : ( getHeight(0) >> 2 ) + ( getHeight(0) >> 1 );
2410      ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : m_uiNumPartition >> 3;
2411      break;
2412    case SIZE_2NxnD:
2413      riWidth     = getWidth(0);
2414      riHeight    = ( uiPartIdx == 0 ) ?  ( getHeight(0) >> 2 ) + ( getHeight(0) >> 1 ) : getHeight(0) >> 2;
2415      ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : (m_uiNumPartition >> 1) + (m_uiNumPartition >> 3);
2416      break;
2417    case SIZE_nLx2N:
2418      riWidth     = ( uiPartIdx == 0 ) ? getWidth(0) >> 2 : ( getWidth(0) >> 2 ) + ( getWidth(0) >> 1 );
2419      riHeight    = getHeight(0);
2420      ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : m_uiNumPartition >> 4;
2421      break;
2422    case SIZE_nRx2N:
2423      riWidth     = ( uiPartIdx == 0 ) ? ( getWidth(0) >> 2 ) + ( getWidth(0) >> 1 ) : getWidth(0) >> 2;
2424      riHeight    = getHeight(0);
2425      ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : (m_uiNumPartition >> 2) + (m_uiNumPartition >> 4);
2426      break;
2427    default:
2428      assert ( m_pePartSize[0] == SIZE_2Nx2N );
2429      riWidth = getWidth(0);      riHeight = getHeight(0);      ruiPartAddr = 0;
2430      break;
2431  }
2432}
2433
2434
2435Void TComDataCU::getMvField ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefPicList, TComMvField& rcMvField )
2436{
2437  if ( pcCU == NULL )  // OUT OF BOUNDARY
2438  {
2439    TComMv  cZeroMv;
2440    rcMvField.setMvField( cZeroMv, NOT_VALID );
2441    return;
2442  }
2443 
2444  TComCUMvField*  pcCUMvField = pcCU->getCUMvField( eRefPicList );
2445  rcMvField.setMvField( pcCUMvField->getMv( uiAbsPartIdx ), pcCUMvField->getRefIdx( uiAbsPartIdx ) );
2446}
2447
2448Void TComDataCU::deriveLeftRightTopIdxGeneral ( UInt uiAbsPartIdx, UInt uiPartIdx, UInt& ruiPartIdxLT, UInt& ruiPartIdxRT )
2449{
2450  ruiPartIdxLT = m_uiAbsIdxInLCU + uiAbsPartIdx;
2451  UInt uiPUWidth = 0;
2452 
2453  switch ( m_pePartSize[uiAbsPartIdx] )
2454  {
2455    case SIZE_2Nx2N: uiPUWidth = m_puhWidth[uiAbsPartIdx];  break;
2456    case SIZE_2NxN:  uiPUWidth = m_puhWidth[uiAbsPartIdx];   break;
2457    case SIZE_Nx2N:  uiPUWidth = m_puhWidth[uiAbsPartIdx]  >> 1;  break;
2458    case SIZE_NxN:   uiPUWidth = m_puhWidth[uiAbsPartIdx]  >> 1; break;
2459    case SIZE_2NxnU:   uiPUWidth = m_puhWidth[uiAbsPartIdx]; break;
2460    case SIZE_2NxnD:   uiPUWidth = m_puhWidth[uiAbsPartIdx]; break;
2461    case SIZE_nLx2N:   
2462      if ( uiPartIdx == 0 )
2463      {
2464        uiPUWidth = m_puhWidth[uiAbsPartIdx]  >> 2; 
2465      }
2466      else if ( uiPartIdx == 1 )
2467      {
2468        uiPUWidth = (m_puhWidth[uiAbsPartIdx]  >> 1) + (m_puhWidth[uiAbsPartIdx]  >> 2); 
2469      }
2470      else
2471      {
2472        assert(0);
2473      }
2474      break;
2475    case SIZE_nRx2N:   
2476      if ( uiPartIdx == 0 )
2477      {
2478        uiPUWidth = (m_puhWidth[uiAbsPartIdx]  >> 1) + (m_puhWidth[uiAbsPartIdx]  >> 2); 
2479      }
2480      else if ( uiPartIdx == 1 )
2481      {
2482        uiPUWidth = m_puhWidth[uiAbsPartIdx]  >> 2; 
2483      }
2484      else
2485      {
2486        assert(0);
2487      }
2488      break;
2489    default:
2490      assert (0);
2491      break;
2492  }
2493 
2494  ruiPartIdxRT = g_auiRasterToZscan [g_auiZscanToRaster[ ruiPartIdxLT ] + uiPUWidth / m_pcPic->getMinCUWidth() - 1 ];
2495}
2496
2497Void TComDataCU::deriveLeftBottomIdxGeneral( UInt uiAbsPartIdx, UInt uiPartIdx, UInt& ruiPartIdxLB )
2498{
2499  UInt uiPUHeight = 0;
2500  switch ( m_pePartSize[uiAbsPartIdx] )
2501  {
2502    case SIZE_2Nx2N: uiPUHeight = m_puhHeight[uiAbsPartIdx];    break;
2503    case SIZE_2NxN:  uiPUHeight = m_puhHeight[uiAbsPartIdx] >> 1;    break;
2504    case SIZE_Nx2N:  uiPUHeight = m_puhHeight[uiAbsPartIdx];  break;
2505    case SIZE_NxN:   uiPUHeight = m_puhHeight[uiAbsPartIdx] >> 1;    break;
2506    case SIZE_2NxnU: 
2507      if ( uiPartIdx == 0 )
2508      {
2509        uiPUHeight = m_puhHeight[uiAbsPartIdx] >> 2;   
2510      }
2511      else if ( uiPartIdx == 1 )
2512      {
2513        uiPUHeight = (m_puhHeight[uiAbsPartIdx] >> 1) + (m_puhHeight[uiAbsPartIdx] >> 2);   
2514      }
2515      else
2516      {
2517        assert(0);
2518      }
2519      break;
2520    case SIZE_2NxnD: 
2521      if ( uiPartIdx == 0 )
2522      {
2523        uiPUHeight = (m_puhHeight[uiAbsPartIdx] >> 1) + (m_puhHeight[uiAbsPartIdx] >> 2);   
2524      }
2525      else if ( uiPartIdx == 1 )
2526      {
2527        uiPUHeight = m_puhHeight[uiAbsPartIdx] >> 2;   
2528      }
2529      else
2530      {
2531        assert(0);
2532      }
2533      break;
2534    case SIZE_nLx2N: uiPUHeight = m_puhHeight[uiAbsPartIdx];  break;
2535    case SIZE_nRx2N: uiPUHeight = m_puhHeight[uiAbsPartIdx];  break;
2536    default:
2537      assert (0);
2538      break;
2539  }
2540 
2541  ruiPartIdxLB      = g_auiRasterToZscan [g_auiZscanToRaster[ m_uiAbsIdxInLCU + uiAbsPartIdx ] + ((uiPUHeight / m_pcPic->getMinCUHeight()) - 1)*m_pcPic->getNumPartInWidth()];
2542}
2543
2544Void TComDataCU::deriveLeftRightTopIdx ( UInt uiPartIdx, UInt& ruiPartIdxLT, UInt& ruiPartIdxRT )
2545{
2546  ruiPartIdxLT = m_uiAbsIdxInLCU;
2547  ruiPartIdxRT = g_auiRasterToZscan [g_auiZscanToRaster[ ruiPartIdxLT ] + m_puhWidth[0] / m_pcPic->getMinCUWidth() - 1 ];
2548 
2549  switch ( m_pePartSize[0] )
2550  {
2551    case SIZE_2Nx2N:                                                                                                                                break;
2552    case SIZE_2NxN:
2553      ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 1; ruiPartIdxRT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 1;
2554      break;
2555    case SIZE_Nx2N:
2556      ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 2; ruiPartIdxRT -= ( uiPartIdx == 1 )? 0 : m_uiNumPartition >> 2;
2557      break;
2558    case SIZE_NxN:
2559      ruiPartIdxLT += ( m_uiNumPartition >> 2 ) * uiPartIdx;         ruiPartIdxRT +=  ( m_uiNumPartition >> 2 ) * ( uiPartIdx - 1 );
2560      break;
2561    case SIZE_2NxnU:
2562      ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 3;
2563      ruiPartIdxRT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 3;
2564      break;
2565    case SIZE_2NxnD:
2566      ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : ( m_uiNumPartition >> 1 ) + ( m_uiNumPartition >> 3 );
2567      ruiPartIdxRT += ( uiPartIdx == 0 )? 0 : ( m_uiNumPartition >> 1 ) + ( m_uiNumPartition >> 3 );
2568      break;
2569    case SIZE_nLx2N:
2570      ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 4;
2571      ruiPartIdxRT -= ( uiPartIdx == 1 )? 0 : ( m_uiNumPartition >> 2 ) + ( m_uiNumPartition >> 4 );
2572      break;
2573    case SIZE_nRx2N:
2574      ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : ( m_uiNumPartition >> 2 ) + ( m_uiNumPartition >> 4 );
2575      ruiPartIdxRT -= ( uiPartIdx == 1 )? 0 : m_uiNumPartition >> 4;
2576      break;
2577    default:
2578      assert (0);
2579      break;
2580  }
2581 
2582}
2583
2584Void TComDataCU::deriveLeftBottomIdx( UInt  uiPartIdx,      UInt&      ruiPartIdxLB )
2585{
2586  ruiPartIdxLB      = g_auiRasterToZscan [g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + ( ((m_puhHeight[0] / m_pcPic->getMinCUHeight())>>1) - 1)*m_pcPic->getNumPartInWidth()];
2587 
2588  switch ( m_pePartSize[0] )
2589  {
2590    case SIZE_2Nx2N:
2591      ruiPartIdxLB += m_uiNumPartition >> 1;
2592      break;
2593    case SIZE_2NxN:
2594      ruiPartIdxLB += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 1;
2595      break;
2596    case SIZE_Nx2N:
2597      ruiPartIdxLB += ( uiPartIdx == 0 )? m_uiNumPartition >> 1 : (m_uiNumPartition >> 2)*3;
2598      break;
2599    case SIZE_NxN:
2600      ruiPartIdxLB += ( m_uiNumPartition >> 2 ) * uiPartIdx;
2601      break;
2602    case SIZE_2NxnU:
2603      ruiPartIdxLB += ( uiPartIdx == 0 ) ? -((Int)m_uiNumPartition >> 3) : m_uiNumPartition >> 1;
2604      break;
2605    case SIZE_2NxnD:
2606      ruiPartIdxLB += ( uiPartIdx == 0 ) ? (m_uiNumPartition >> 2) + (m_uiNumPartition >> 3): m_uiNumPartition >> 1;
2607      break;
2608    case SIZE_nLx2N:
2609      ruiPartIdxLB += ( uiPartIdx == 0 ) ? m_uiNumPartition >> 1 : (m_uiNumPartition >> 1) + (m_uiNumPartition >> 4);
2610      break;
2611    case SIZE_nRx2N:
2612      ruiPartIdxLB += ( uiPartIdx == 0 ) ? m_uiNumPartition >> 1 : (m_uiNumPartition >> 1) + (m_uiNumPartition >> 2) + (m_uiNumPartition >> 4);
2613      break;
2614    default:
2615      assert (0);
2616      break;
2617  }
2618}
2619
2620/** Derives the partition index of neighbouring bottom right block
2621 * \param [in]  eCUMode
2622 * \param [in]  uiPartIdx
2623 * \param [out] ruiPartIdxRB
2624 */
2625Void TComDataCU::deriveRightBottomIdx( UInt  uiPartIdx,      UInt&      ruiPartIdxRB )
2626{
2627  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];
2628
2629  switch ( m_pePartSize[0] )
2630  {
2631    case SIZE_2Nx2N: 
2632      ruiPartIdxRB += m_uiNumPartition >> 1;   
2633      break;
2634    case SIZE_2NxN: 
2635      ruiPartIdxRB += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 1;   
2636      break;
2637    case SIZE_Nx2N: 
2638      ruiPartIdxRB += ( uiPartIdx == 0 )? m_uiNumPartition >> 2 : (m_uiNumPartition >> 1);   
2639      break;
2640    case SIZE_NxN:   
2641      ruiPartIdxRB += ( m_uiNumPartition >> 2 ) * ( uiPartIdx - 1 );   
2642      break;
2643    case SIZE_2NxnU:
2644      ruiPartIdxRB += ( uiPartIdx == 0 ) ? -((Int)m_uiNumPartition >> 3) : m_uiNumPartition >> 1;
2645      break;
2646    case SIZE_2NxnD:
2647      ruiPartIdxRB += ( uiPartIdx == 0 ) ? (m_uiNumPartition >> 2) + (m_uiNumPartition >> 3): m_uiNumPartition >> 1;
2648      break;
2649    case SIZE_nLx2N:
2650      ruiPartIdxRB += ( uiPartIdx == 0 ) ? (m_uiNumPartition >> 3) + (m_uiNumPartition >> 4): m_uiNumPartition >> 1;
2651      break;
2652    case SIZE_nRx2N:
2653      ruiPartIdxRB += ( uiPartIdx == 0 ) ? (m_uiNumPartition >> 2) + (m_uiNumPartition >> 3) + (m_uiNumPartition >> 4) : m_uiNumPartition >> 1;
2654      break;
2655    default:
2656      assert (0);
2657      break;
2658  }
2659}
2660
2661Void TComDataCU::deriveLeftRightTopIdxAdi ( UInt& ruiPartIdxLT, UInt& ruiPartIdxRT, UInt uiPartOffset, UInt uiPartDepth )
2662{
2663  UInt uiNumPartInWidth = (m_puhWidth[0]/m_pcPic->getMinCUWidth())>>uiPartDepth;
2664  ruiPartIdxLT = m_uiAbsIdxInLCU + uiPartOffset;
2665  ruiPartIdxRT = g_auiRasterToZscan[ g_auiZscanToRaster[ ruiPartIdxLT ] + uiNumPartInWidth - 1 ];
2666}
2667
2668Void TComDataCU::deriveLeftBottomIdxAdi( UInt& ruiPartIdxLB, UInt uiPartOffset, UInt uiPartDepth )
2669{
2670  UInt uiAbsIdx;
2671  UInt uiMinCuWidth, uiWidthInMinCus;
2672 
2673  uiMinCuWidth    = getPic()->getMinCUWidth();
2674  uiWidthInMinCus = (getWidth(0)/uiMinCuWidth)>>uiPartDepth;
2675  uiAbsIdx        = getZorderIdxInCU()+uiPartOffset+(m_uiNumPartition>>(uiPartDepth<<1))-1;
2676  uiAbsIdx        = g_auiZscanToRaster[uiAbsIdx]-(uiWidthInMinCus-1);
2677  ruiPartIdxLB    = g_auiRasterToZscan[uiAbsIdx];
2678}
2679
2680Bool TComDataCU::hasEqualMotion( UInt uiAbsPartIdx, TComDataCU* pcCandCU, UInt uiCandAbsPartIdx )
2681{
2682
2683  if ( getInterDir( uiAbsPartIdx ) != pcCandCU->getInterDir( uiCandAbsPartIdx ) )
2684  {
2685    return false;
2686  }
2687
2688  for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
2689  {
2690    if ( getInterDir( uiAbsPartIdx ) & ( 1 << uiRefListIdx ) )
2691    {
2692      if ( getCUMvField( RefPicList( uiRefListIdx ) )->getMv( uiAbsPartIdx )     != pcCandCU->getCUMvField( RefPicList( uiRefListIdx ) )->getMv( uiCandAbsPartIdx ) || 
2693        getCUMvField( RefPicList( uiRefListIdx ) )->getRefIdx( uiAbsPartIdx ) != pcCandCU->getCUMvField( RefPicList( uiRefListIdx ) )->getRefIdx( uiCandAbsPartIdx ) )
2694      {
2695        return false;
2696      }
2697    }
2698  }
2699
2700  return true;
2701}
2702
2703/** Constructs a list of merging candidates
2704 * \param uiAbsPartIdx
2705 * \param uiPUIdx
2706 * \param uiDepth
2707 * \param pcMvFieldNeighbours
2708 * \param puhInterDirNeighbours
2709 * \param numValidMergeCand
2710 */
2711Void TComDataCU::getInterMergeCandidates( UInt uiAbsPartIdx, UInt uiPUIdx, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int& numValidMergeCand, Int mrgCandIdx )
2712{
2713  UInt uiAbsPartAddr = m_uiAbsIdxInLCU + uiAbsPartIdx;
2714  Bool abCandIsInter[ MRG_MAX_NUM_CANDS ];
2715  for( UInt ui = 0; ui < getSlice()->getMaxNumMergeCand(); ++ui )
2716  {
2717    abCandIsInter[ui] = false;
2718    pcMvFieldNeighbours[ ( ui << 1 )     ].setRefIdx(NOT_VALID);
2719    pcMvFieldNeighbours[ ( ui << 1 ) + 1 ].setRefIdx(NOT_VALID);
2720  }
2721  numValidMergeCand = getSlice()->getMaxNumMergeCand();
2722  // compute the location of the current PU
2723  Int xP, yP, nPSW, nPSH;
2724  this->getPartPosition(uiPUIdx, xP, yP, nPSW, nPSH);
2725
2726  Int iCount = 0;
2727
2728  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB;
2729  PartSize cCurPS = getPartitionSize( uiAbsPartIdx );
2730  deriveLeftRightTopIdxGeneral( uiAbsPartIdx, uiPUIdx, uiPartIdxLT, uiPartIdxRT );
2731  deriveLeftBottomIdxGeneral  ( uiAbsPartIdx, uiPUIdx, uiPartIdxLB );
2732
2733  //left
2734  UInt uiLeftPartIdx = 0;
2735  TComDataCU* pcCULeft = 0;
2736  pcCULeft = getPULeft( uiLeftPartIdx, uiPartIdxLB );
2737  Bool isAvailableA1 = pcCULeft &&
2738  pcCULeft->isDiffMER(xP -1, yP+nPSH-1, xP, yP) &&
2739  !( uiPUIdx == 1 && (cCurPS == SIZE_Nx2N || cCurPS == SIZE_nLx2N || cCurPS == SIZE_nRx2N) ) &&
2740  !pcCULeft->isIntra( uiLeftPartIdx ) ;
2741  if ( isAvailableA1 )
2742  {
2743    abCandIsInter[iCount] = true;
2744    // get Inter Dir
2745    puhInterDirNeighbours[iCount] = pcCULeft->getInterDir( uiLeftPartIdx );
2746    // get Mv from Left
2747    pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
2748    if ( getSlice()->isInterB() )
2749    {
2750      pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
2751    }
2752    if ( mrgCandIdx == iCount )
2753    {
2754      return;
2755    }
2756    iCount ++;
2757  }
2758 
2759  // early termination
2760  if (iCount == getSlice()->getMaxNumMergeCand()) 
2761  {
2762    return;
2763  }
2764  // above
2765  UInt uiAbovePartIdx = 0;
2766  TComDataCU* pcCUAbove = 0;
2767  pcCUAbove = getPUAbove( uiAbovePartIdx, uiPartIdxRT );
2768  Bool isAvailableB1 = pcCUAbove &&
2769  pcCUAbove->isDiffMER(xP+nPSW-1, yP-1, xP, yP) &&
2770  !( uiPUIdx == 1 && (cCurPS == SIZE_2NxN || cCurPS == SIZE_2NxnU || cCurPS == SIZE_2NxnD) ) &&
2771  !pcCUAbove->isIntra( uiAbovePartIdx );
2772  if ( isAvailableB1 && (!isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAbove, uiAbovePartIdx ) ) )
2773  {
2774    abCandIsInter[iCount] = true;
2775    // get Inter Dir
2776    puhInterDirNeighbours[iCount] = pcCUAbove->getInterDir( uiAbovePartIdx );
2777    // get Mv from Left
2778    pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
2779    if ( getSlice()->isInterB() )
2780    {
2781      pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
2782    }
2783    if ( mrgCandIdx == iCount )
2784    {
2785      return;
2786    }
2787    iCount ++;
2788  }
2789  // early termination
2790  if (iCount == getSlice()->getMaxNumMergeCand()) 
2791  {
2792    return;
2793  }
2794
2795  // above right
2796  UInt uiAboveRightPartIdx = 0;
2797  TComDataCU* pcCUAboveRight = 0;
2798  pcCUAboveRight = getPUAboveRight( uiAboveRightPartIdx, uiPartIdxRT );
2799  Bool isAvailableB0 = pcCUAboveRight &&
2800  pcCUAboveRight->isDiffMER(xP+nPSW, yP-1, xP, yP) &&
2801  !pcCUAboveRight->isIntra( uiAboveRightPartIdx );
2802  if ( isAvailableB0 && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveRight, uiAboveRightPartIdx ) ) )
2803  {
2804    abCandIsInter[iCount] = true;
2805    // get Inter Dir
2806    puhInterDirNeighbours[iCount] = pcCUAboveRight->getInterDir( uiAboveRightPartIdx );
2807    // get Mv from Left
2808    pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
2809    if ( getSlice()->isInterB() )
2810    {
2811      pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
2812    }
2813    if ( mrgCandIdx == iCount )
2814    {
2815      return;
2816    }
2817    iCount ++;
2818  }
2819  // early termination
2820  if (iCount == getSlice()->getMaxNumMergeCand()) 
2821  {
2822    return;
2823  }
2824
2825  //left bottom
2826  UInt uiLeftBottomPartIdx = 0;
2827  TComDataCU* pcCULeftBottom = 0;
2828  pcCULeftBottom = this->getPUBelowLeft( uiLeftBottomPartIdx, uiPartIdxLB );
2829  Bool isAvailableA0 = pcCULeftBottom &&
2830  pcCULeftBottom->isDiffMER(xP-1, yP+nPSH, xP, yP) &&
2831  !pcCULeftBottom->isIntra( uiLeftBottomPartIdx ) ;
2832  if ( isAvailableA0 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCULeftBottom, uiLeftBottomPartIdx ) ) )
2833  {
2834    abCandIsInter[iCount] = true;
2835    // get Inter Dir
2836    puhInterDirNeighbours[iCount] = pcCULeftBottom->getInterDir( uiLeftBottomPartIdx );
2837    // get Mv from Left
2838    pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
2839    if ( getSlice()->isInterB() )
2840    {
2841      pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
2842    }
2843    if ( mrgCandIdx == iCount )
2844    {
2845      return;
2846    }
2847    iCount ++;
2848  }
2849  // early termination
2850  if (iCount == getSlice()->getMaxNumMergeCand()) 
2851  {
2852    return;
2853  }
2854  // above left
2855  if( iCount < 4 )
2856  {
2857    UInt uiAboveLeftPartIdx = 0;
2858    TComDataCU* pcCUAboveLeft = 0;
2859    pcCUAboveLeft = getPUAboveLeft( uiAboveLeftPartIdx, uiAbsPartAddr );
2860    Bool isAvailableB2 = pcCUAboveLeft &&
2861    pcCUAboveLeft->isDiffMER(xP-1, yP-1, xP, yP) &&
2862    !pcCUAboveLeft->isIntra( uiAboveLeftPartIdx );
2863    if ( isAvailableB2 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) )
2864        && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) ) )
2865    {
2866      abCandIsInter[iCount] = true;
2867      // get Inter Dir
2868      puhInterDirNeighbours[iCount] = pcCUAboveLeft->getInterDir( uiAboveLeftPartIdx );
2869      // get Mv from Left
2870      pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
2871      if ( getSlice()->isInterB() )
2872      {
2873        pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
2874      }
2875      if ( mrgCandIdx == iCount )
2876      {
2877        return;
2878      }
2879      iCount ++;
2880    }
2881  }
2882  // early termination
2883  if (iCount == getSlice()->getMaxNumMergeCand()) 
2884  {
2885    return;
2886  }
2887  if ( getSlice()->getEnableTMVPFlag())
2888  {
2889    //>> MTK colocated-RightBottom
2890    UInt uiPartIdxRB;
2891    Int uiLCUIdx = getAddr();
2892
2893    deriveRightBottomIdx( uiPUIdx, uiPartIdxRB ); 
2894
2895    UInt uiAbsPartIdxTmp = g_auiZscanToRaster[uiPartIdxRB];
2896    UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
2897
2898    TComMv cColMv;
2899    Int iRefIdx;
2900
2901    if      ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
2902    {
2903      uiLCUIdx = -1;
2904    }
2905    else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxTmp] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
2906    {
2907      uiLCUIdx = -1;
2908    }
2909    else
2910    {
2911      if ( ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
2912        ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
2913      {
2914        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + uiNumPartInCUWidth + 1 ];
2915        uiLCUIdx = getAddr();
2916      }
2917      else if ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
2918      {
2919        uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdxTmp + uiNumPartInCUWidth + 1) % m_pcPic->getNumPartInCU() ];
2920        uiLCUIdx = -1 ; 
2921      }
2922      else if ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
2923      {
2924        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + 1 ];
2925        uiLCUIdx = getAddr() + 1;
2926      }
2927      else //is the right bottom corner of LCU                       
2928      {
2929        uiAbsPartAddr = 0;
2930        uiLCUIdx = -1 ; 
2931      }
2932    }
2933   
2934   
2935    iRefIdx = 0;
2936    Bool bExistMV = false;
2937    UInt uiPartIdxCenter;
2938    UInt uiCurLCUIdx = getAddr();
2939    Int dir = 0;
2940    UInt uiArrayAddr = iCount;
2941    xDeriveCenterIdx( uiPUIdx, uiPartIdxCenter );
2942    bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_0, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx );
2943    if( bExistMV == false )
2944    {
2945      bExistMV = xGetColMVP( REF_PIC_LIST_0, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
2946    }
2947    if( bExistMV )
2948    {
2949      dir |= 1;
2950      pcMvFieldNeighbours[ 2 * uiArrayAddr ].setMvField( cColMv, iRefIdx );
2951    }
2952   
2953    if ( getSlice()->isInterB() )
2954    {
2955      bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_1, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx);
2956      if( bExistMV == false )
2957      {
2958        bExistMV = xGetColMVP( REF_PIC_LIST_1, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
2959      }
2960      if( bExistMV )
2961      {
2962        dir |= 2;
2963        pcMvFieldNeighbours[ 2 * uiArrayAddr + 1 ].setMvField( cColMv, iRefIdx );
2964      }
2965    }
2966   
2967    if (dir != 0)
2968    {
2969      puhInterDirNeighbours[uiArrayAddr] = dir;
2970      abCandIsInter[uiArrayAddr] = true;
2971
2972      if ( mrgCandIdx == iCount )
2973      {
2974        return;
2975      }
2976      iCount++;
2977    }
2978  }
2979  // early termination
2980  if (iCount == getSlice()->getMaxNumMergeCand()) 
2981  {
2982    return;
2983  }
2984  UInt uiArrayAddr = iCount;
2985  UInt uiCutoff = uiArrayAddr;
2986   
2987  if ( getSlice()->isInterB())
2988  {
2989    UInt uiPriorityList0[12] = {0 , 1, 0, 2, 1, 2, 0, 3, 1, 3, 2, 3};
2990    UInt uiPriorityList1[12] = {1 , 0, 2, 0, 2, 1, 3, 0, 3, 1, 3, 2};
2991
2992    for (Int idx=0; idx<uiCutoff*(uiCutoff-1) && uiArrayAddr!= getSlice()->getMaxNumMergeCand(); idx++)
2993    {
2994      Int i = uiPriorityList0[idx]; Int j = uiPriorityList1[idx];
2995      if (abCandIsInter[i] && abCandIsInter[j]&& (puhInterDirNeighbours[i]&0x1)&&(puhInterDirNeighbours[j]&0x2))
2996      {
2997        abCandIsInter[uiArrayAddr] = true;
2998        puhInterDirNeighbours[uiArrayAddr] = 3;
2999
3000        // get Mv from cand[i] and cand[j]
3001        pcMvFieldNeighbours[uiArrayAddr << 1].setMvField(pcMvFieldNeighbours[i<<1].getMv(), pcMvFieldNeighbours[i<<1].getRefIdx());
3002        pcMvFieldNeighbours[( uiArrayAddr << 1 ) + 1].setMvField(pcMvFieldNeighbours[(j<<1)+1].getMv(), pcMvFieldNeighbours[(j<<1)+1].getRefIdx());
3003
3004        Int iRefPOCL0 = m_pcSlice->getRefPOC( REF_PIC_LIST_0, pcMvFieldNeighbours[(uiArrayAddr<<1)].getRefIdx() );
3005        Int iRefPOCL1 = m_pcSlice->getRefPOC( REF_PIC_LIST_1, pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getRefIdx() );
3006        if (iRefPOCL0 == iRefPOCL1 && pcMvFieldNeighbours[(uiArrayAddr<<1)].getMv() == pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getMv())
3007        {
3008          abCandIsInter[uiArrayAddr] = false;
3009        }
3010        else
3011        {
3012          uiArrayAddr++;
3013        }
3014      }
3015    }
3016  }
3017  // early termination
3018  if (uiArrayAddr == getSlice()->getMaxNumMergeCand()) 
3019  {
3020    return;
3021  }
3022  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);
3023  Int r = 0;
3024  Int refcnt = 0;
3025  while (uiArrayAddr < getSlice()->getMaxNumMergeCand())
3026  {
3027    abCandIsInter[uiArrayAddr] = true;
3028    puhInterDirNeighbours[uiArrayAddr] = 1;
3029    pcMvFieldNeighbours[uiArrayAddr << 1].setMvField( TComMv(0, 0), r);
3030
3031    if ( getSlice()->isInterB() )
3032    {
3033      puhInterDirNeighbours[uiArrayAddr] = 3;
3034      pcMvFieldNeighbours[(uiArrayAddr << 1) + 1].setMvField(TComMv(0, 0), r);
3035    }
3036    uiArrayAddr++;
3037    if ( refcnt == iNumRefIdx - 1 )
3038    {
3039      r = 0;
3040    }
3041    else
3042    {
3043      ++r;
3044      ++refcnt;
3045    }
3046  }
3047
3048  numValidMergeCand = uiArrayAddr;
3049}
3050
3051/** Check whether the current PU and a spatial neighboring PU are in a same ME region.
3052 * \param xN, xN   location of the upper-left corner pixel of a neighboring PU
3053 * \param xP, yP   location of the upper-left corner pixel of the current PU
3054 * \returns Bool
3055 */
3056Bool TComDataCU::isDiffMER(Int xN, Int yN, Int xP, Int yP)
3057{
3058
3059  UInt plevel = this->getSlice()->getPPS()->getLog2ParallelMergeLevelMinus2() + 2;
3060  if ((xN>>plevel)!= (xP>>plevel))
3061  {
3062    return true;
3063  }
3064  if ((yN>>plevel)!= (yP>>plevel))
3065  {
3066    return true;
3067  }
3068  return false;
3069}
3070/** calculate the location of upper-left corner pixel and size of the current PU.
3071 * \param partIdx  PU index within a CU
3072 * \param xP, yP   location of the upper-left corner pixel of the current PU
3073 * \param PSW, nPSH    size of the curren PU
3074 * \returns Void
3075 */
3076Void TComDataCU::getPartPosition( UInt partIdx, Int& xP, Int& yP, Int& nPSW, Int& nPSH)
3077{
3078  UInt col = m_uiCUPelX;
3079  UInt row = m_uiCUPelY;
3080
3081  switch ( m_pePartSize[0] )
3082  {
3083  case SIZE_2NxN:
3084    nPSW = getWidth(0);     
3085    nPSH = getHeight(0) >> 1; 
3086    xP   = col;
3087    yP   = (partIdx ==0)? row: row + nPSH;
3088    break;
3089  case SIZE_Nx2N:
3090    nPSW = getWidth(0) >> 1; 
3091    nPSH = getHeight(0);     
3092    xP   = (partIdx ==0)? col: col + nPSW;
3093    yP   = row;
3094    break;
3095  case SIZE_NxN:
3096    nPSW = getWidth(0) >> 1; 
3097    nPSH = getHeight(0) >> 1; 
3098    xP   = col + (partIdx&0x1)*nPSW;
3099    yP   = row + (partIdx>>1)*nPSH;
3100    break;
3101  case SIZE_2NxnU:
3102    nPSW = getWidth(0);
3103    nPSH = ( partIdx == 0 ) ?  getHeight(0) >> 2 : ( getHeight(0) >> 2 ) + ( getHeight(0) >> 1 );
3104    xP   = col;
3105    yP   = (partIdx ==0)? row: row + getHeight(0) - nPSH;
3106
3107    break;
3108  case SIZE_2NxnD:
3109    nPSW = getWidth(0);
3110    nPSH = ( partIdx == 0 ) ?  ( getHeight(0) >> 2 ) + ( getHeight(0) >> 1 ) : getHeight(0) >> 2;
3111    xP   = col;
3112    yP   = (partIdx ==0)? row: row + getHeight(0) - nPSH;
3113    break;
3114  case SIZE_nLx2N:
3115    nPSW = ( partIdx == 0 ) ? getWidth(0) >> 2 : ( getWidth(0) >> 2 ) + ( getWidth(0) >> 1 );
3116    nPSH = getHeight(0);
3117    xP   = (partIdx ==0)? col: col + getWidth(0) - nPSW;
3118    yP   = row;
3119    break;
3120  case SIZE_nRx2N:
3121    nPSW = ( partIdx == 0 ) ? ( getWidth(0) >> 2 ) + ( getWidth(0) >> 1 ) : getWidth(0) >> 2;
3122    nPSH = getHeight(0);
3123    xP   = (partIdx ==0)? col: col + getWidth(0) - nPSW;
3124    yP   = row;
3125    break;
3126  default:
3127    assert ( m_pePartSize[0] == SIZE_2Nx2N );
3128    nPSW = getWidth(0);     
3129    nPSH = getHeight(0);     
3130    xP   = col ;
3131    yP   = row ;
3132
3133    break;
3134  }
3135}
3136
3137/** Constructs a list of candidates for AMVP
3138 * \param uiPartIdx
3139 * \param uiPartAddr
3140 * \param eRefPicList
3141 * \param iRefIdx
3142 * \param pInfo
3143 */
3144Void TComDataCU::fillMvpCand ( UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, Int iRefIdx, AMVPInfo* pInfo )
3145{
3146  TComMv cMvPred;
3147  Bool bAddedSmvp = false;
3148
3149  pInfo->iN = 0; 
3150  if (iRefIdx < 0)
3151  {
3152    return;
3153  }
3154 
3155  //-- Get Spatial MV
3156  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB;
3157  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
3158  Bool bAdded = false;
3159 
3160  deriveLeftRightTopIdx( uiPartIdx, uiPartIdxLT, uiPartIdxRT );
3161  deriveLeftBottomIdx( uiPartIdx, uiPartIdxLB );
3162 
3163  TComDataCU* tmpCU = NULL;
3164  UInt idx;
3165  tmpCU = getPUBelowLeft(idx, uiPartIdxLB);
3166  bAddedSmvp = (tmpCU != NULL) && (tmpCU->getPredictionMode(idx) != MODE_INTRA);
3167
3168  if (!bAddedSmvp)
3169  {
3170    tmpCU = getPULeft(idx, uiPartIdxLB);
3171    bAddedSmvp = (tmpCU != NULL) && (tmpCU->getPredictionMode(idx) != MODE_INTRA);
3172  }
3173
3174  // Left predictor search
3175  bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_BELOW_LEFT);
3176  if (!bAdded) 
3177  {
3178    bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_LEFT );
3179  }
3180 
3181  if(!bAdded)
3182  {
3183    bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_BELOW_LEFT);
3184    if (!bAdded) 
3185    {
3186      bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_LEFT );
3187    }
3188  }
3189  // Above predictor search
3190  bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE_RIGHT);
3191
3192  if (!bAdded) 
3193  {
3194    bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE);
3195  }
3196
3197  if(!bAdded)
3198  {
3199    bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLT, MD_ABOVE_LEFT);
3200  }
3201  bAdded = bAddedSmvp;
3202  if (pInfo->iN==2) bAdded = true;
3203
3204  if(!bAdded)
3205  {
3206    bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE_RIGHT);
3207    if (!bAdded) 
3208    {
3209      bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE);
3210    }
3211
3212    if(!bAdded)
3213    {
3214      bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLT, MD_ABOVE_LEFT);
3215    }
3216  }
3217 
3218  if ( pInfo->iN == 2 )
3219  {
3220    if ( pInfo->m_acMvCand[ 0 ] == pInfo->m_acMvCand[ 1 ] )
3221    {
3222      pInfo->iN = 1;
3223    }
3224  }
3225
3226  if ( getSlice()->getEnableTMVPFlag() )
3227  {
3228    // Get Temporal Motion Predictor
3229    Int iRefIdx_Col = iRefIdx;
3230    TComMv cColMv;
3231    UInt uiPartIdxRB;
3232    UInt uiAbsPartIdx; 
3233    UInt uiAbsPartAddr;
3234    Int uiLCUIdx = getAddr();
3235
3236    deriveRightBottomIdx( uiPartIdx, uiPartIdxRB );
3237    uiAbsPartAddr = m_uiAbsIdxInLCU + uiPartAddr;
3238
3239    //----  co-located RightBottom Temporal Predictor (H) ---//
3240    uiAbsPartIdx = g_auiZscanToRaster[uiPartIdxRB];
3241    if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdx] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
3242    {
3243      uiLCUIdx = -1;
3244    }
3245    else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdx] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
3246    {
3247      uiLCUIdx = -1;
3248    }
3249    else
3250    {
3251      if ( ( uiAbsPartIdx % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
3252        ( uiAbsPartIdx / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
3253      {
3254        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdx + uiNumPartInCUWidth + 1 ];
3255        uiLCUIdx = getAddr();
3256      }
3257      else if ( uiAbsPartIdx % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
3258      {
3259        uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdx + uiNumPartInCUWidth + 1) % m_pcPic->getNumPartInCU() ];
3260        uiLCUIdx      = -1 ; 
3261      }
3262      else if ( uiAbsPartIdx / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
3263      {
3264        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdx + 1 ];
3265        uiLCUIdx = getAddr() + 1;
3266      }
3267      else //is the right bottom corner of LCU                       
3268      {
3269        uiAbsPartAddr = 0;
3270        uiLCUIdx      = -1 ; 
3271      }
3272    }
3273    if ( uiLCUIdx >= 0 && xGetColMVP( eRefPicList, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx_Col ) )
3274    {
3275      pInfo->m_acMvCand[pInfo->iN++] = cColMv;
3276    }
3277    else 
3278    {
3279      UInt uiPartIdxCenter;
3280      UInt uiCurLCUIdx = getAddr();
3281      xDeriveCenterIdx( uiPartIdx, uiPartIdxCenter );
3282      if (xGetColMVP( eRefPicList, uiCurLCUIdx, uiPartIdxCenter,  cColMv, iRefIdx_Col ))
3283      {
3284        pInfo->m_acMvCand[pInfo->iN++] = cColMv;
3285      }
3286    }
3287    //----  co-located RightBottom Temporal Predictor  ---//
3288  }
3289
3290  if (pInfo->iN > AMVP_MAX_NUM_CANDS)
3291  {
3292    pInfo->iN = AMVP_MAX_NUM_CANDS;
3293  }
3294  while (pInfo->iN < AMVP_MAX_NUM_CANDS)
3295  {
3296      pInfo->m_acMvCand[pInfo->iN].set(0,0);
3297      pInfo->iN++;
3298  }
3299  return ;
3300}
3301
3302Bool TComDataCU::isBipredRestriction(UInt puIdx)
3303{
3304  Int width = 0;
3305  Int height = 0;
3306  UInt partAddr;
3307
3308  getPartIndexAndSize( puIdx, partAddr, width, height );
3309  if ( getWidth(0) == 8 && (width < 8 || height < 8) )
3310  {
3311    return true;
3312  }
3313  return false;
3314}
3315
3316Void TComDataCU::clipMv    (TComMv&  rcMv)
3317{
3318  Int  iMvShift = 2;
3319  Int iOffset = 8;
3320  Int iHorMax = ( m_pcSlice->getSPS()->getPicWidthInLumaSamples() + iOffset - m_uiCUPelX - 1 ) << iMvShift;
3321  Int iHorMin = (       -(Int)g_uiMaxCUWidth - iOffset - (Int)m_uiCUPelX + 1 ) << iMvShift;
3322 
3323  Int iVerMax = ( m_pcSlice->getSPS()->getPicHeightInLumaSamples() + iOffset - m_uiCUPelY - 1 ) << iMvShift;
3324  Int iVerMin = (       -(Int)g_uiMaxCUHeight - iOffset - (Int)m_uiCUPelY + 1 ) << iMvShift;
3325 
3326  rcMv.setHor( min (iHorMax, max (iHorMin, rcMv.getHor())) );
3327  rcMv.setVer( min (iVerMax, max (iVerMin, rcMv.getVer())) );
3328}
3329
3330UInt TComDataCU::getIntraSizeIdx(UInt uiAbsPartIdx)
3331{
3332  UInt uiShift = ( (m_puhTrIdx[uiAbsPartIdx]==0) && (m_pePartSize[uiAbsPartIdx]==SIZE_NxN) ) ? m_puhTrIdx[uiAbsPartIdx]+1 : m_puhTrIdx[uiAbsPartIdx];
3333  uiShift = ( m_pePartSize[uiAbsPartIdx]==SIZE_NxN ? 1 : 0 );
3334 
3335  UChar uiWidth = m_puhWidth[uiAbsPartIdx]>>uiShift;
3336  UInt  uiCnt = 0;
3337  while( uiWidth )
3338  {
3339    uiCnt++;
3340    uiWidth>>=1;
3341  }
3342  uiCnt-=2;
3343  return uiCnt > 6 ? 6 : uiCnt;
3344}
3345
3346Void TComDataCU::clearCbf( UInt uiIdx, TextType eType, UInt uiNumParts )
3347{
3348  ::memset( &m_puhCbf[g_aucConvertTxtTypeToIdx[eType]][uiIdx], 0, sizeof(UChar)*uiNumParts);
3349}
3350
3351/** Set a I_PCM flag for all sub-partitions of a partition.
3352 * \param bIpcmFlag I_PCM flag
3353 * \param uiAbsPartIdx patition index
3354 * \param uiDepth CU depth
3355 * \returns Void
3356 */
3357Void TComDataCU::setIPCMFlagSubParts  (Bool bIpcmFlag, UInt uiAbsPartIdx, UInt uiDepth)
3358{
3359  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
3360
3361  memset(m_pbIPCMFlag + uiAbsPartIdx, bIpcmFlag, sizeof(Bool)*uiCurrPartNumb );
3362}
3363
3364/** Test whether the current block is skipped
3365 * \param uiPartIdx Block index
3366 * \returns Flag indicating whether the block is skipped
3367 */
3368Bool TComDataCU::isSkipped( UInt uiPartIdx )
3369{
3370  return ( getSkipFlag( uiPartIdx ) );
3371}
3372
3373// ====================================================================================================================
3374// Protected member functions
3375// ====================================================================================================================
3376
3377Bool TComDataCU::xAddMVPCand( AMVPInfo* pInfo, RefPicList eRefPicList, Int iRefIdx, UInt uiPartUnitIdx, MVP_DIR eDir )
3378{
3379  TComDataCU* pcTmpCU = NULL;
3380  UInt uiIdx;
3381  switch( eDir )
3382  {
3383    case MD_LEFT:
3384    {
3385      pcTmpCU = getPULeft(uiIdx, uiPartUnitIdx);
3386      break;
3387    }
3388    case MD_ABOVE:
3389    {
3390      pcTmpCU = getPUAbove(uiIdx, uiPartUnitIdx );
3391      break;
3392    }
3393    case MD_ABOVE_RIGHT:
3394    {
3395      pcTmpCU = getPUAboveRight(uiIdx, uiPartUnitIdx);
3396      break;
3397    }
3398    case MD_BELOW_LEFT:
3399    {
3400      pcTmpCU = getPUBelowLeft(uiIdx, uiPartUnitIdx);
3401      break;
3402    }
3403    case MD_ABOVE_LEFT:
3404    {
3405      pcTmpCU = getPUAboveLeft(uiIdx, uiPartUnitIdx);
3406      break;
3407    }
3408    default:
3409    {
3410      break;
3411    }
3412  }
3413
3414  if ( pcTmpCU == NULL )
3415  {
3416    return false;
3417  }
3418 
3419#if L0363_MVP_POC
3420  if ( pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) >= 0 && m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getPOC() == pcTmpCU->getSlice()->getRefPOC( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) ))
3421#else
3422  if ( m_pcSlice->isEqualRef(eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx), iRefIdx) )
3423#endif
3424  {
3425    TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
3426   
3427    pInfo->m_acMvCand[ pInfo->iN++] = cMvPred;
3428    return true;
3429  }
3430
3431  RefPicList eRefPicList2nd = REF_PIC_LIST_0;
3432  if(       eRefPicList == REF_PIC_LIST_0 )
3433  {
3434    eRefPicList2nd = REF_PIC_LIST_1;
3435  }
3436  else if ( eRefPicList == REF_PIC_LIST_1)
3437  {
3438    eRefPicList2nd = REF_PIC_LIST_0;
3439  }
3440
3441
3442  Int iCurrRefPOC = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getPOC();
3443  Int iNeibRefPOC;
3444
3445
3446  if( pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) >= 0 )
3447  {
3448    iNeibRefPOC = pcTmpCU->getSlice()->getRefPOC( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) );
3449    if( iNeibRefPOC == iCurrRefPOC ) // Same Reference Frame But Diff List//
3450    {
3451      TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList2nd)->getMv(uiIdx);
3452      pInfo->m_acMvCand[ pInfo->iN++] = cMvPred;
3453      return true;
3454    }
3455  }
3456  return false;
3457}
3458
3459/**
3460 * \param pInfo
3461 * \param eRefPicList
3462 * \param iRefIdx
3463 * \param uiPartUnitIdx
3464 * \param eDir
3465 * \returns Bool
3466 */
3467Bool TComDataCU::xAddMVPCandOrder( AMVPInfo* pInfo, RefPicList eRefPicList, Int iRefIdx, UInt uiPartUnitIdx, MVP_DIR eDir )
3468{
3469  TComDataCU* pcTmpCU = NULL;
3470  UInt uiIdx;
3471  switch( eDir )
3472  {
3473  case MD_LEFT:
3474    {
3475      pcTmpCU = getPULeft(uiIdx, uiPartUnitIdx);
3476      break;
3477    }
3478  case MD_ABOVE:
3479    {
3480      pcTmpCU = getPUAbove(uiIdx, uiPartUnitIdx);
3481      break;
3482    }
3483  case MD_ABOVE_RIGHT:
3484    {
3485      pcTmpCU = getPUAboveRight(uiIdx, uiPartUnitIdx);
3486      break;
3487    }
3488  case MD_BELOW_LEFT:
3489    {
3490      pcTmpCU = getPUBelowLeft(uiIdx, uiPartUnitIdx);
3491      break;
3492    }
3493  case MD_ABOVE_LEFT:
3494    {
3495      pcTmpCU = getPUAboveLeft(uiIdx, uiPartUnitIdx);
3496      break;
3497    }
3498  default:
3499    {
3500      break;
3501    }
3502  }
3503
3504  if ( pcTmpCU == NULL ) 
3505  {
3506    return false;
3507  }
3508 
3509  RefPicList eRefPicList2nd = REF_PIC_LIST_0;
3510  if(       eRefPicList == REF_PIC_LIST_0 )
3511  {
3512    eRefPicList2nd = REF_PIC_LIST_1;
3513  }
3514  else if ( eRefPicList == REF_PIC_LIST_1)
3515  {
3516    eRefPicList2nd = REF_PIC_LIST_0;
3517  }
3518
3519  Int iCurrPOC = m_pcSlice->getPOC();
3520  Int iCurrRefPOC = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getPOC();
3521  Int iNeibPOC = iCurrPOC;
3522  Int iNeibRefPOC;
3523
3524  Bool bIsCurrRefLongTerm = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getIsLongTerm();
3525  Bool bIsNeibRefLongTerm = false;
3526  //---------------  V1 (END) ------------------//
3527  if( pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) >= 0)
3528  {
3529    iNeibRefPOC = pcTmpCU->getSlice()->getRefPOC( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) );
3530    TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
3531    TComMv rcMv;
3532
3533    bIsNeibRefLongTerm = pcTmpCU->getSlice()->getRefPic( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) )->getIsLongTerm();
3534    if ( bIsCurrRefLongTerm == bIsNeibRefLongTerm ) 
3535    {
3536    if ( bIsCurrRefLongTerm || bIsNeibRefLongTerm )
3537    {
3538      rcMv = cMvPred;
3539    }
3540    else
3541    {
3542      Int iScale = xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
3543      if ( iScale == 4096 )
3544      {
3545        rcMv = cMvPred;
3546      }
3547      else
3548      {
3549        rcMv = cMvPred.scaleMv( iScale );
3550      }
3551    }
3552    pInfo->m_acMvCand[ pInfo->iN++] = rcMv;
3553    return true;
3554    }
3555  }
3556  //---------------------- V2(END) --------------------//
3557  if( pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) >= 0)
3558  {
3559    iNeibRefPOC = pcTmpCU->getSlice()->getRefPOC( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) );
3560    TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList2nd)->getMv(uiIdx);
3561    TComMv rcMv;
3562
3563    bIsNeibRefLongTerm = pcTmpCU->getSlice()->getRefPic( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) )->getIsLongTerm();
3564    if ( bIsCurrRefLongTerm == bIsNeibRefLongTerm ) 
3565    {
3566    if ( bIsCurrRefLongTerm || bIsNeibRefLongTerm )
3567    {
3568      rcMv = cMvPred;
3569    }
3570    else
3571    {
3572      Int iScale = xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
3573      if ( iScale == 4096 )
3574      {
3575        rcMv = cMvPred;
3576      }
3577      else
3578      {
3579        rcMv = cMvPred.scaleMv( iScale );
3580      }
3581    }
3582    pInfo->m_acMvCand[ pInfo->iN++] = rcMv;
3583    return true;
3584    }
3585  }
3586  //---------------------- V3(END) --------------------//
3587  return false;
3588}
3589
3590/**
3591 * \param eRefPicList
3592 * \param uiCUAddr
3593 * \param uiPartUnitIdx
3594 * \param riRefIdx
3595 * \returns Bool
3596 */
3597Bool TComDataCU::xGetColMVP( RefPicList eRefPicList, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv, Int& riRefIdx )
3598{
3599  UInt uiAbsPartAddr = uiPartUnitIdx;
3600
3601  RefPicList  eColRefPicList;
3602  Int iColPOC, iColRefPOC, iCurrPOC, iCurrRefPOC, iScale;
3603  TComMv cColMv;
3604
3605  // use coldir.
3606  TComPic *pColPic = getSlice()->getRefPic( RefPicList(getSlice()->isInterB() ? 1-getSlice()->getColFromL0Flag() : 0), getSlice()->getColRefIdx());
3607  TComDataCU *pColCU = pColPic->getCU( uiCUAddr );
3608  if(pColCU->getPic()==0||pColCU->getPartitionSize(uiPartUnitIdx)==SIZE_NONE)
3609  {
3610    return false;
3611  }
3612  iCurrPOC = m_pcSlice->getPOC();   
3613  iCurrRefPOC = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getPOC();
3614  iColPOC = pColCU->getSlice()->getPOC(); 
3615
3616  if (pColCU->isIntra(uiAbsPartAddr))
3617  {
3618    return false;
3619  }
3620  eColRefPicList = getSlice()->getCheckLDC() ? eRefPicList : RefPicList(getSlice()->getColFromL0Flag());
3621
3622  Int iColRefIdx = pColCU->getCUMvField(RefPicList(eColRefPicList))->getRefIdx(uiAbsPartAddr);
3623
3624  if (iColRefIdx < 0 )
3625  {
3626    eColRefPicList = RefPicList(1 - eColRefPicList);
3627    iColRefIdx = pColCU->getCUMvField(RefPicList(eColRefPicList))->getRefIdx(uiAbsPartAddr);
3628
3629    if (iColRefIdx < 0 )
3630    {
3631      return false;
3632    }
3633  }
3634
3635  // Scale the vector.
3636  iColRefPOC = pColCU->getSlice()->getRefPOC(eColRefPicList, iColRefIdx);
3637  cColMv = pColCU->getCUMvField(eColRefPicList)->getMv(uiAbsPartAddr);
3638
3639  iCurrRefPOC = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getPOC();
3640  Bool bIsCurrRefLongTerm = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getIsLongTerm();
3641  Bool bIsColRefLongTerm = pColCU->getSlice()->getIsUsedAsLongTerm(eColRefPicList, iColRefIdx);
3642
3643  if ( bIsCurrRefLongTerm != bIsColRefLongTerm ) 
3644  {
3645    return false;
3646  }
3647
3648  if ( bIsCurrRefLongTerm || bIsColRefLongTerm )
3649  {
3650    rcMv = cColMv;
3651  }
3652  else
3653  {
3654    iScale = xGetDistScaleFactor(iCurrPOC, iCurrRefPOC, iColPOC, iColRefPOC);
3655    if ( iScale == 4096 )
3656    {
3657      rcMv = cColMv;
3658    }
3659    else
3660    {
3661      rcMv = cColMv.scaleMv( iScale );
3662    }
3663  }
3664  return true;
3665}
3666
3667UInt TComDataCU::xGetMvdBits(TComMv cMvd)
3668{
3669  return ( xGetComponentBits(cMvd.getHor()) + xGetComponentBits(cMvd.getVer()) );
3670}
3671
3672UInt TComDataCU::xGetComponentBits(Int iVal)
3673{
3674  UInt uiLength = 1;
3675  UInt uiTemp   = ( iVal <= 0) ? (-iVal<<1)+1: (iVal<<1);
3676 
3677  assert ( uiTemp );
3678 
3679  while ( 1 != uiTemp )
3680  {
3681    uiTemp >>= 1;
3682    uiLength += 2;
3683  }
3684 
3685  return uiLength;
3686}
3687
3688
3689Int TComDataCU::xGetDistScaleFactor(Int iCurrPOC, Int iCurrRefPOC, Int iColPOC, Int iColRefPOC)
3690{
3691  Int iDiffPocD = iColPOC - iColRefPOC;
3692  Int iDiffPocB = iCurrPOC - iCurrRefPOC;
3693 
3694  if( iDiffPocD == iDiffPocB )
3695  {
3696    return 4096;
3697  }
3698  else
3699  {
3700    Int iTDB      = Clip3( -128, 127, iDiffPocB );
3701    Int iTDD      = Clip3( -128, 127, iDiffPocD );
3702    Int iX        = (0x4000 + abs(iTDD/2)) / iTDD;
3703    Int iScale    = Clip3( -4096, 4095, (iTDB * iX + 32) >> 6 );
3704    return iScale;
3705  }
3706}
3707
3708/**
3709 * \param eCUMode
3710 * \param uiPartIdx
3711 * \param ruiPartIdxCenter
3712 * \returns Void
3713 */
3714Void TComDataCU::xDeriveCenterIdx( UInt uiPartIdx, UInt& ruiPartIdxCenter )
3715{
3716  UInt uiPartAddr;
3717  Int  iPartWidth;
3718  Int  iPartHeight;
3719  getPartIndexAndSize( uiPartIdx, uiPartAddr, iPartWidth, iPartHeight);
3720 
3721  ruiPartIdxCenter = m_uiAbsIdxInLCU+uiPartAddr; // partition origin.
3722  ruiPartIdxCenter = g_auiRasterToZscan[ g_auiZscanToRaster[ ruiPartIdxCenter ]
3723                                        + ( iPartHeight/m_pcPic->getMinCUHeight()  )/2*m_pcPic->getNumPartInWidth()
3724                                        + ( iPartWidth/m_pcPic->getMinCUWidth()  )/2];
3725}
3726
3727Void TComDataCU::compressMV()
3728{
3729  Int scaleFactor = 4 * AMVP_DECIMATION_FACTOR / m_unitSize;
3730  if (scaleFactor > 0)
3731  {
3732    m_acCUMvField[0].compress(m_pePredMode, scaleFactor);
3733    m_acCUMvField[1].compress(m_pePredMode, scaleFactor);   
3734  }
3735}
3736
3737UInt TComDataCU::getCoefScanIdx(UInt uiAbsPartIdx, UInt uiWidth, Bool bIsLuma, Bool bIsIntra)
3738{
3739  UInt uiCTXIdx;
3740  UInt uiScanIdx;
3741  UInt uiDirMode;
3742
3743  if ( !bIsIntra ) 
3744  {
3745    uiScanIdx = SCAN_DIAG;
3746    return uiScanIdx;
3747  }
3748
3749  switch(uiWidth)
3750  {
3751    case  2: uiCTXIdx = 6; break;
3752    case  4: uiCTXIdx = 5; break;
3753    case  8: uiCTXIdx = 4; break;
3754    case 16: uiCTXIdx = 3; break;
3755    case 32: uiCTXIdx = 2; break;
3756    case 64: uiCTXIdx = 1; break;
3757    default: uiCTXIdx = 0; break;
3758  }
3759
3760  if ( bIsLuma )
3761  {
3762    uiDirMode = getLumaIntraDir(uiAbsPartIdx);
3763#if H_3D_DIM
3764    mapDepthModeToIntraDir( uiDirMode );
3765#endif
3766    uiScanIdx = SCAN_DIAG;
3767    if (uiCTXIdx >3 && uiCTXIdx < 6) //if multiple scans supported for transform size
3768    {
3769      uiScanIdx = abs((Int) uiDirMode - VER_IDX) < 5 ? SCAN_HOR : (abs((Int)uiDirMode - HOR_IDX) < 5 ? SCAN_VER : SCAN_DIAG);
3770    }
3771  }
3772  else
3773  {
3774    uiDirMode = getChromaIntraDir(uiAbsPartIdx);
3775    if( uiDirMode == DM_CHROMA_IDX )
3776    {
3777      // get number of partitions in current CU
3778      UInt depth = getDepth(uiAbsPartIdx);
3779      UInt numParts = getPic()->getNumPartInCU() >> (2 * depth);
3780     
3781      // get luma mode from upper-left corner of current CU
3782      uiDirMode = getLumaIntraDir((uiAbsPartIdx/numParts)*numParts);
3783#if H_3D_DIM
3784      mapDepthModeToIntraDir( uiDirMode );
3785#endif
3786    }
3787    uiScanIdx = SCAN_DIAG;
3788    if (uiCTXIdx >4 && uiCTXIdx < 7) //if multiple scans supported for transform size
3789    {
3790      uiScanIdx = abs((Int) uiDirMode - VER_IDX) < 5 ? SCAN_HOR : (abs((Int)uiDirMode - HOR_IDX) < 5 ? SCAN_VER : SCAN_DIAG);
3791    }
3792  }
3793
3794  return uiScanIdx;
3795}
3796
3797UInt TComDataCU::getSCUAddr()
3798{ 
3799  return getPic()->getPicSym()->getInverseCUOrderMap(m_uiCUAddr)*(1<<(m_pcSlice->getSPS()->getMaxCUDepth()<<1))+m_uiAbsIdxInLCU; 
3800}
3801
3802/** Set neighboring blocks availabilities for non-deblocked filtering
3803 * \param numLCUInPicWidth number of LCUs in picture width
3804 * \param numLCUInPicHeight number of LCUs in picture height
3805 * \param numSUInLCUWidth number of SUs in LCU width
3806 * \param numSUInLCUHeight number of SUs in LCU height
3807 * \param picWidth picture width
3808 * \param picHeight picture height
3809 * \param bIndependentSliceBoundaryEnabled true for independent slice boundary enabled
3810 * \param bTopTileBoundary true means that top boundary coincides tile boundary
3811 * \param bDownTileBoundary true means that bottom boundary coincides tile boundary
3812 * \param bLeftTileBoundary true means that left boundary coincides tile boundary
3813 * \param bRightTileBoundary true means that right boundary coincides tile boundary
3814 * \param bIndependentTileBoundaryEnabled true for independent tile boundary enabled
3815 */
3816Void TComDataCU::setNDBFilterBlockBorderAvailability(UInt numLCUInPicWidth, UInt /*numLCUInPicHeight*/, UInt numSUInLCUWidth, UInt numSUInLCUHeight, UInt picWidth, UInt picHeight
3817                                                    ,std::vector<Bool>& LFCrossSliceBoundary
3818                                                    ,Bool bTopTileBoundary, Bool bDownTileBoundary, Bool bLeftTileBoundary, Bool bRightTileBoundary
3819                                                    ,Bool bIndependentTileBoundaryEnabled)
3820{
3821  UInt numSUInLCU = numSUInLCUWidth*numSUInLCUHeight;
3822  Int* pSliceIDMapLCU = m_piSliceSUMap;
3823  Bool onlyOneSliceInPic = ((Int)LFCrossSliceBoundary.size() == 1);
3824  UInt uiLPelX, uiTPelY;
3825  UInt width, height;
3826  Bool bPicRBoundary, bPicBBoundary, bPicTBoundary, bPicLBoundary;
3827  Bool bLCURBoundary= false, bLCUBBoundary= false, bLCUTBoundary= false, bLCULBoundary= false;
3828  Bool* pbAvailBorder;
3829  Bool* pbAvail;
3830  UInt rTLSU, rBRSU, widthSU, heightSU;
3831  UInt zRefSU;
3832  Int* pRefID;
3833  Int* pRefMapLCU;
3834  UInt rTRefSU= 0, rBRefSU= 0, rLRefSU= 0, rRRefSU= 0;
3835  Int* pRRefMapLCU= NULL;
3836  Int* pLRefMapLCU= NULL;
3837  Int* pTRefMapLCU= NULL;
3838  Int* pBRefMapLCU= NULL;
3839  Int  sliceID;
3840  UInt numSGU = (UInt)m_vNDFBlock.size();
3841
3842  for(Int i=0; i< numSGU; i++)
3843  {
3844    NDBFBlockInfo& rSGU = m_vNDFBlock[i];
3845
3846    sliceID = rSGU.sliceID;
3847    uiLPelX = rSGU.posX;
3848    uiTPelY = rSGU.posY;
3849    width   = rSGU.width;
3850    height  = rSGU.height;
3851    rTLSU     = g_auiZscanToRaster[ rSGU.startSU ];
3852    rBRSU     = g_auiZscanToRaster[ rSGU.endSU   ];
3853    widthSU   = rSGU.widthSU;
3854    heightSU  = rSGU.heightSU;
3855
3856    pbAvailBorder = rSGU.isBorderAvailable;
3857
3858    bPicTBoundary= (uiTPelY == 0                       )?(true):(false);
3859    bPicLBoundary= (uiLPelX == 0                       )?(true):(false);
3860    bPicRBoundary= (!(uiLPelX+ width < picWidth )  )?(true):(false);
3861    bPicBBoundary= (!(uiTPelY + height < picHeight))?(true):(false);
3862
3863    bLCULBoundary = (rTLSU % numSUInLCUWidth == 0)?(true):(false);
3864    bLCURBoundary = ( (rTLSU+ widthSU) % numSUInLCUWidth == 0)?(true):(false);
3865    bLCUTBoundary = ( (UInt)(rTLSU / numSUInLCUWidth)== 0)?(true):(false);
3866    bLCUBBoundary = ( (UInt)(rBRSU / numSUInLCUWidth) == (numSUInLCUHeight-1) )?(true):(false);
3867
3868    //       SGU_L
3869    pbAvail = &(pbAvailBorder[SGU_L]);
3870    if(bPicLBoundary)
3871    {
3872      *pbAvail = false;
3873    }
3874    else if (onlyOneSliceInPic)
3875    {
3876      *pbAvail = true;
3877    }
3878    else
3879    {
3880      //      bLCULBoundary = (rTLSU % uiNumSUInLCUWidth == 0)?(true):(false);
3881      if(bLCULBoundary)
3882      {
3883        rLRefSU     = rTLSU + numSUInLCUWidth -1;
3884        zRefSU      = g_auiRasterToZscan[rLRefSU];
3885        pRefMapLCU = pLRefMapLCU= (pSliceIDMapLCU - numSUInLCU);
3886      }
3887      else
3888      {
3889        zRefSU   = g_auiRasterToZscan[rTLSU - 1];
3890        pRefMapLCU  = pSliceIDMapLCU;
3891      }
3892      pRefID = pRefMapLCU + zRefSU;
3893      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
3894    }
3895
3896    //       SGU_R
3897    pbAvail = &(pbAvailBorder[SGU_R]);
3898    if(bPicRBoundary)
3899    {
3900      *pbAvail = false;
3901    }
3902    else if (onlyOneSliceInPic)
3903    {
3904      *pbAvail = true;
3905    }
3906    else
3907    {
3908      //       bLCURBoundary = ( (rTLSU+ uiWidthSU) % uiNumSUInLCUWidth == 0)?(true):(false);
3909      if(bLCURBoundary)
3910      {
3911        rRRefSU      = rTLSU + widthSU - numSUInLCUWidth;
3912        zRefSU       = g_auiRasterToZscan[rRRefSU];
3913        pRefMapLCU  = pRRefMapLCU= (pSliceIDMapLCU + numSUInLCU);
3914      }
3915      else
3916      {
3917        zRefSU       = g_auiRasterToZscan[rTLSU + widthSU];
3918        pRefMapLCU  = pSliceIDMapLCU;
3919      }
3920      pRefID = pRefMapLCU + zRefSU;
3921      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
3922    }
3923
3924    //       SGU_T
3925    pbAvail = &(pbAvailBorder[SGU_T]);
3926    if(bPicTBoundary)
3927    {
3928      *pbAvail = false;
3929    }
3930    else if (onlyOneSliceInPic)
3931    {
3932      *pbAvail = true;
3933    }
3934    else
3935    {
3936      //      bLCUTBoundary = ( (UInt)(rTLSU / uiNumSUInLCUWidth)== 0)?(true):(false);
3937      if(bLCUTBoundary)
3938      {
3939        rTRefSU      = numSUInLCU - (numSUInLCUWidth - rTLSU);
3940        zRefSU       = g_auiRasterToZscan[rTRefSU];
3941        pRefMapLCU  = pTRefMapLCU= (pSliceIDMapLCU - (numLCUInPicWidth*numSUInLCU));
3942      }
3943      else
3944      {
3945        zRefSU       = g_auiRasterToZscan[rTLSU - numSUInLCUWidth];
3946        pRefMapLCU  = pSliceIDMapLCU;
3947      }
3948      pRefID = pRefMapLCU + zRefSU;
3949      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
3950    }
3951
3952    //       SGU_B
3953    pbAvail = &(pbAvailBorder[SGU_B]);
3954    if(bPicBBoundary)
3955    {
3956      *pbAvail = false;
3957    }
3958    else if (onlyOneSliceInPic)
3959    {
3960      *pbAvail = true;
3961    }
3962    else
3963    {
3964      //      bLCUBBoundary = ( (UInt)(rBRSU / uiNumSUInLCUWidth) == (uiNumSUInLCUHeight-1) )?(true):(false);
3965      if(bLCUBBoundary)
3966      {
3967        rBRefSU      = rTLSU % numSUInLCUWidth;
3968        zRefSU       = g_auiRasterToZscan[rBRefSU];
3969        pRefMapLCU  = pBRefMapLCU= (pSliceIDMapLCU + (numLCUInPicWidth*numSUInLCU));
3970      }
3971      else
3972      {
3973        zRefSU       = g_auiRasterToZscan[rTLSU + (heightSU*numSUInLCUWidth)];
3974        pRefMapLCU  = pSliceIDMapLCU;
3975      }
3976      pRefID = pRefMapLCU + zRefSU;
3977      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
3978    }
3979
3980    //       SGU_TL
3981    pbAvail = &(pbAvailBorder[SGU_TL]);
3982    if(bPicTBoundary || bPicLBoundary)
3983    {
3984      *pbAvail = false;
3985    }
3986    else if (onlyOneSliceInPic)
3987    {
3988      *pbAvail = true;
3989    }
3990    else
3991    {
3992      if(bLCUTBoundary && bLCULBoundary)
3993      {
3994        zRefSU       = numSUInLCU -1;
3995        pRefMapLCU  = pSliceIDMapLCU - ( (numLCUInPicWidth+1)*numSUInLCU);
3996      }
3997      else if(bLCUTBoundary)
3998      {
3999        zRefSU       = g_auiRasterToZscan[ rTRefSU- 1];
4000        pRefMapLCU  = pTRefMapLCU;
4001      }
4002      else if(bLCULBoundary)
4003      {
4004        zRefSU       = g_auiRasterToZscan[ rLRefSU- numSUInLCUWidth ];
4005        pRefMapLCU  = pLRefMapLCU;
4006      }
4007      else //inside LCU
4008      {
4009        zRefSU       = g_auiRasterToZscan[ rTLSU - numSUInLCUWidth -1];
4010        pRefMapLCU  = pSliceIDMapLCU;
4011      }
4012      pRefID = pRefMapLCU + zRefSU;
4013      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
4014    }
4015
4016    //       SGU_TR
4017    pbAvail = &(pbAvailBorder[SGU_TR]);
4018    if(bPicTBoundary || bPicRBoundary)
4019    {
4020      *pbAvail = false;
4021    }
4022    else if (onlyOneSliceInPic)
4023    {
4024      *pbAvail = true;
4025    }
4026    else
4027    {
4028      if(bLCUTBoundary && bLCURBoundary)
4029      {
4030        zRefSU      = g_auiRasterToZscan[numSUInLCU - numSUInLCUWidth];
4031        pRefMapLCU  = pSliceIDMapLCU - ( (numLCUInPicWidth-1)*numSUInLCU);       
4032      }
4033      else if(bLCUTBoundary)
4034      {
4035        zRefSU       = g_auiRasterToZscan[ rTRefSU+ widthSU];
4036        pRefMapLCU  = pTRefMapLCU;
4037      }
4038      else if(bLCURBoundary)
4039      {
4040        zRefSU       = g_auiRasterToZscan[ rRRefSU- numSUInLCUWidth ];
4041        pRefMapLCU  = pRRefMapLCU;
4042      }
4043      else //inside LCU
4044      {
4045        zRefSU       = g_auiRasterToZscan[ rTLSU - numSUInLCUWidth +widthSU];
4046        pRefMapLCU  = pSliceIDMapLCU;
4047      }
4048      pRefID = pRefMapLCU + zRefSU;
4049      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
4050    }
4051
4052    //       SGU_BL
4053    pbAvail = &(pbAvailBorder[SGU_BL]);
4054    if(bPicBBoundary || bPicLBoundary)
4055    {
4056      *pbAvail = false;
4057    }
4058    else if (onlyOneSliceInPic)
4059    {
4060      *pbAvail = true;
4061    }
4062    else
4063    {
4064      if(bLCUBBoundary && bLCULBoundary)
4065      {
4066        zRefSU      = g_auiRasterToZscan[numSUInLCUWidth - 1];
4067        pRefMapLCU  = pSliceIDMapLCU + ( (numLCUInPicWidth-1)*numSUInLCU);       
4068      }
4069      else if(bLCUBBoundary)
4070      {
4071        zRefSU       = g_auiRasterToZscan[ rBRefSU - 1];
4072        pRefMapLCU  = pBRefMapLCU;
4073      }
4074      else if(bLCULBoundary)
4075      {
4076        zRefSU       = g_auiRasterToZscan[ rLRefSU+ heightSU*numSUInLCUWidth ];
4077        pRefMapLCU  = pLRefMapLCU;
4078      }
4079      else //inside LCU
4080      {
4081        zRefSU       = g_auiRasterToZscan[ rTLSU + heightSU*numSUInLCUWidth -1];
4082        pRefMapLCU  = pSliceIDMapLCU;
4083      }
4084      pRefID = pRefMapLCU + zRefSU;
4085      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
4086    }
4087
4088    //       SGU_BR
4089    pbAvail = &(pbAvailBorder[SGU_BR]);
4090    if(bPicBBoundary || bPicRBoundary)
4091    {
4092      *pbAvail = false;
4093    }
4094    else if (onlyOneSliceInPic)
4095    {
4096      *pbAvail = true;
4097    }
4098    else
4099    {
4100      if(bLCUBBoundary && bLCURBoundary)
4101      {
4102        zRefSU = 0;
4103        pRefMapLCU = pSliceIDMapLCU+ ( (numLCUInPicWidth+1)*numSUInLCU);
4104      }
4105      else if(bLCUBBoundary)
4106      {
4107        zRefSU      = g_auiRasterToZscan[ rBRefSU + widthSU];
4108        pRefMapLCU = pBRefMapLCU;
4109      }
4110      else if(bLCURBoundary)
4111      {
4112        zRefSU      = g_auiRasterToZscan[ rRRefSU + (heightSU*numSUInLCUWidth)];
4113        pRefMapLCU = pRRefMapLCU;
4114      }
4115      else //inside LCU
4116      {
4117        zRefSU      = g_auiRasterToZscan[ rTLSU + (heightSU*numSUInLCUWidth)+ widthSU];
4118        pRefMapLCU = pSliceIDMapLCU;
4119      }
4120      pRefID = pRefMapLCU + zRefSU;
4121      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
4122    }
4123
4124    if(bIndependentTileBoundaryEnabled)
4125    {
4126      //left LCU boundary
4127      if(!bPicLBoundary && bLCULBoundary)
4128      {
4129        if(bLeftTileBoundary)
4130        {
4131          pbAvailBorder[SGU_L] = pbAvailBorder[SGU_TL] = pbAvailBorder[SGU_BL] = false;
4132        }
4133      }
4134      //right LCU boundary
4135      if(!bPicRBoundary && bLCURBoundary)
4136      {
4137        if(bRightTileBoundary)
4138        {
4139          pbAvailBorder[SGU_R] = pbAvailBorder[SGU_TR] = pbAvailBorder[SGU_BR] = false;
4140        }
4141      }
4142      //top LCU boundary
4143      if(!bPicTBoundary && bLCUTBoundary)
4144      {
4145        if(bTopTileBoundary)
4146        {
4147          pbAvailBorder[SGU_T] = pbAvailBorder[SGU_TL] = pbAvailBorder[SGU_TR] = false;
4148        }
4149      }
4150      //down LCU boundary
4151      if(!bPicBBoundary && bLCUBBoundary)
4152      {
4153        if(bDownTileBoundary)
4154        {
4155          pbAvailBorder[SGU_B] = pbAvailBorder[SGU_BL] = pbAvailBorder[SGU_BR] = false;
4156        }
4157      }
4158    }
4159    rSGU.allBordersAvailable = true;
4160    for(Int b=0; b< NUM_SGU_BORDER; b++)
4161    {
4162      if(pbAvailBorder[b] == false)
4163      {
4164        rSGU.allBordersAvailable = false;
4165        break;
4166      }
4167    }
4168  }
4169}
4170
4171#if H_3D
4172Void TComDataCU::getPosInPic( UInt uiAbsPartIndex, Int& riPosX, Int& riPosY )
4173{
4174  riPosX = g_auiRasterToPelX[g_auiZscanToRaster[uiAbsPartIndex]] + getCUPelX();
4175  riPosY = g_auiRasterToPelY[g_auiZscanToRaster[uiAbsPartIndex]] + getCUPelY(); 
4176}
4177#if H_3D_DIM_DMM
4178Void TComDataCU::setDmmWedgeTabIdxSubParts( UInt tabIdx, UInt dmmType, UInt uiAbsPartIdx, UInt uiDepth )
4179{
4180  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
4181  for( UInt ui = 0; ui < uiCurrPartNumb; ui++ ) { m_dmmWedgeTabIdx[dmmType][uiAbsPartIdx+ui] = tabIdx; }
4182}
4183Void  TComDataCU::setDmm2DeltaEndSubParts( Int iDelta, UInt uiAbsPartIdx, UInt uiDepth )
4184{
4185  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
4186  for( UInt ui = 0; ui < uiCurrPartNumb; ui++ ) { m_dmm2DeltaEnd[uiAbsPartIdx+ui] = iDelta; }
4187}
4188Void  TComDataCU::setDmm3IntraTabIdxSubParts( UInt uiTIdx, UInt uiAbsPartIdx, UInt uiDepth )
4189{
4190  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
4191  for( UInt ui = 0; ui < uiCurrPartNumb; ui++ ) { m_dmm3IntraTabIdx[uiAbsPartIdx+ui] = uiTIdx; }
4192}
4193#endif
4194#if H_3D_DIM_RBC
4195Void TComDataCU::reconPartition( UInt uiAbsPartIdx, UInt uiDepth, Bool bLeft, UChar ucStartPos, UChar ucNumEdge, UChar* pucEdgeCode, Bool* pbRegion )
4196{
4197  Int iWidth;
4198  Int iHeight;
4199  if( uiDepth == 0 )
4200  {
4201    iWidth = 64;
4202    iHeight = 64;
4203  }
4204  else if( uiDepth == 1 )
4205  {
4206    iWidth = 32;
4207    iHeight = 32;
4208  }
4209  else if( uiDepth == 2 )
4210  {
4211    iWidth = 16;
4212    iHeight = 16;
4213  }
4214  else if( uiDepth == 3 )
4215  {
4216    iWidth = 8;
4217    iHeight = 8;
4218  }
4219  else // uiDepth == 4
4220  {
4221    iWidth = 4;
4222    iHeight = 4;
4223  }
4224
4225  Int iPtr = 0;
4226  Int iX, iY;
4227  Int iDir = -1;
4228  Int iDiffX = 0, iDiffY = 0;
4229
4230  // 1. Edge Code -> Vert & Horz Edges
4231  Bool*  pbEdge = (Bool*) xMalloc( Bool, 4 * iWidth * iHeight );
4232
4233  for( UInt ui = 0; ui < 4 * iWidth * iHeight; ui++ )
4234    pbEdge  [ ui ] = false;
4235
4236  // Direction : left(0), right(1), top(2), bottom(3), left-top(4), right-top(5), left-bottom(6), right-bottom(7)
4237  // Code      : 0deg(0), 45deg(1), -45deg(2), 90deg(3), -90deg(4), 135deg(5), -135deg(6)
4238  const UChar tableDir[8][7] = { { 0, 6, 4, 3, 2, 7, 5 },
4239  { 1, 5, 7, 2, 3, 4, 6 },
4240  { 2, 4, 5, 0, 1, 6, 7 },
4241  { 3, 7, 6, 1, 0, 5, 4 },
4242  { 4, 0, 2, 6, 5, 3, 1 },
4243  { 5, 2, 1, 4, 7, 0, 3 },
4244  { 6, 3, 0, 7, 4, 1, 2 },
4245  { 7, 1, 3, 5, 6, 2, 0 }};
4246
4247  UChar ucCode = pucEdgeCode[iPtr++];
4248
4249  if( !bLeft )
4250  {
4251    iX = ucStartPos;
4252    iY = 0;
4253
4254    switch(ucCode)
4255    {
4256    case 0: // bottom
4257      iDir = 3;
4258      if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
4259      break;
4260    case 2: // left-bottom
4261      iDir = 6;
4262      if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
4263      break;
4264    case 1: // right-bottom
4265      iDir = 7;
4266      if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
4267      if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
4268      break;
4269    case 4: // left
4270      iDir = 0;
4271      assert(false);
4272      break;
4273    case 3: // right
4274      iDir = 1;
4275      if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
4276      if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
4277      break;
4278    }
4279  }
4280  else
4281  {
4282    iX = 0;
4283    iY = ucStartPos;
4284
4285    switch(ucCode)
4286    {
4287    case 0: // right
4288      iDir = 1;
4289      if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
4290      break;
4291    case 1: // right-top
4292      iDir = 5;
4293      if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
4294      if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
4295      break;
4296    case 2: // right-bottom
4297      iDir = 7;
4298      if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
4299      break;
4300    case 3: // top
4301      iDir = 2;
4302      if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
4303      if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
4304      break;
4305    case 4: // bottom
4306      iDir = 3;
4307      assert(false);
4308      break;
4309    }
4310  }
4311
4312  switch( iDir )
4313  {
4314  case 0: // left
4315    iDiffX = -1;
4316    iDiffY = 0;
4317    break;
4318  case 1: // right
4319    iDiffX = +1;
4320    iDiffY = 0;
4321    break;
4322  case 2: // top
4323    iDiffX = 0;
4324    iDiffY = -1;
4325    break;
4326  case 3: // bottom
4327    iDiffX = 0;
4328    iDiffY = +1;
4329    break;
4330  case 4: // left-top
4331    iDiffX = -1;
4332    iDiffY = -1;
4333    break;
4334  case 5: // right-top
4335    iDiffX = +1;
4336    iDiffY = -1;
4337    break;
4338  case 6: // left-bottom
4339    iDiffX = -1;
4340    iDiffY = +1;
4341    break;
4342  case 7: // right-bottom
4343    iDiffX = +1;
4344    iDiffY = +1;
4345    break;
4346  }
4347
4348  iX += iDiffX;
4349  iY += iDiffY;
4350
4351  while( iPtr < ucNumEdge )
4352  {
4353    ucCode = pucEdgeCode[iPtr++];
4354
4355    Int iNewDir = tableDir[iDir][ucCode];
4356
4357    switch( iNewDir )
4358    {
4359    case 0: // left
4360      iDiffX = -1;
4361      iDiffY = 0;
4362      break;
4363    case 1: // right
4364      iDiffX = +1;
4365      iDiffY = 0;
4366      break;
4367    case 2: // top
4368      iDiffX = 0;
4369      iDiffY = -1;
4370      break;
4371    case 3: // bottom
4372      iDiffX = 0;
4373      iDiffY = +1;
4374      break;
4375    case 4: // left-top
4376      iDiffX = -1;
4377      iDiffY = -1;
4378      break;
4379    case 5: // right-top
4380      iDiffX = +1;
4381      iDiffY = -1;
4382      break;
4383    case 6: // left-bottom
4384      iDiffX = -1;
4385      iDiffY = +1;
4386      break;
4387    case 7: // right-bottom
4388      iDiffX = +1;
4389      iDiffY = +1;
4390      break;
4391    }
4392
4393    switch( iDir )
4394    {
4395    case 0: // left
4396      switch( ucCode )
4397      {
4398      case 0:
4399      case 2:
4400        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
4401        break;
4402      case 1:
4403      case 3:
4404        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
4405        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
4406        break;
4407      case 4:
4408      case 6:
4409        // no
4410        break;
4411      case 5:
4412        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
4413        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
4414        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
4415        break;
4416      }
4417      break;
4418    case 1: // right
4419      switch( ucCode )
4420      {
4421      case 0:
4422      case 2:
4423        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
4424        break;
4425      case 1:
4426      case 3:
4427        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
4428        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
4429        break;
4430      case 4:
4431      case 6:
4432        // no
4433        break;
4434      case 5:
4435        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
4436        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
4437        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
4438        break;
4439      }
4440      break;
4441    case 2: // top
4442      switch( ucCode )
4443      {
4444      case 0:
4445      case 2:
4446        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
4447        break;
4448      case 1:
4449      case 3:
4450        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
4451        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
4452        break;
4453      case 4:
4454      case 6:
4455        // no
4456        break;
4457      case 5:
4458        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
4459        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
4460        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
4461        break;
4462      }
4463      break;
4464    case 3: // bottom
4465      switch( ucCode )
4466      {
4467      case 0:
4468      case 2:
4469        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
4470        break;
4471      case 1:
4472      case 3:
4473        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
4474        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
4475        break;
4476      case 4:
4477      case 6:
4478        // no
4479        break;
4480      case 5:
4481        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
4482        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
4483        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
4484        break;
4485      }
4486      break;
4487    case 4: // left-top
4488      switch( ucCode )
4489      {
4490      case 0:
4491      case 1:
4492        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
4493        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
4494        break;
4495      case 2:
4496      case 4:
4497        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
4498        break;
4499      case 3:
4500      case 5:
4501        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
4502        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
4503        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
4504        break;
4505      case 6:
4506        // no
4507        break;
4508      }
4509      break;
4510    case 5: // right-top
4511      switch( ucCode )
4512      {
4513      case 0:
4514      case 1:
4515        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
4516        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
4517        break;
4518      case 2:
4519      case 4:
4520        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
4521        break;
4522      case 3:
4523      case 5:
4524        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
4525        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
4526        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
4527        break;
4528      case 6:
4529        // no
4530        break;
4531      }
4532      break;
4533    case 6: // left-bottom
4534      switch( ucCode )
4535      {
4536      case 0:
4537      case 1:
4538        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
4539        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
4540        break;
4541      case 2:
4542      case 4:
4543        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
4544        break;
4545      case 3:
4546      case 5:
4547        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
4548        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
4549        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
4550        break;
4551      case 6:
4552        // no
4553        break;
4554      }
4555      break;
4556    case 7: // right-bottom
4557      switch( ucCode )
4558      {
4559      case 0:
4560      case 1:
4561        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
4562        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
4563        break;
4564      case 2:
4565      case 4:
4566        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
4567        break;
4568      case 3:
4569      case 5:
4570        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
4571        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
4572        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
4573        break;
4574      case 6:
4575        // no
4576        break;
4577      }
4578      break;
4579    }
4580
4581    assert( iX >= 0 && iX <= iWidth );
4582    assert( iY >= 0 && iY <= iHeight );
4583
4584    iX += iDiffX;
4585    iY += iDiffY;
4586    iDir = iNewDir;
4587  }
4588
4589  // finalize edge chain
4590  if( iX == iWidth-1 )
4591  {
4592    if( iY == 0 )
4593    {
4594      if( iDir == 1 )
4595      {
4596        pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
4597      }
4598      else if( iDir == 5 )
4599      {
4600        pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
4601      }
4602      else
4603      {
4604        assert(false);
4605      }
4606    }
4607    else if( iY == iHeight-1 )
4608    {
4609      if( iDir == 3 )
4610      {
4611        pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
4612      }
4613      else if( iDir == 7 )
4614      {
4615        pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
4616      }
4617      else
4618      {
4619        assert(false);
4620      }
4621    }
4622    else
4623    {
4624      if( iDir == 1 )
4625      {
4626        pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
4627      }
4628      else if( iDir == 3 )
4629      {
4630        pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
4631        pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
4632      }
4633      else if( iDir == 5 )
4634      {
4635        pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
4636      }
4637      else if( iDir == 7 )
4638      {
4639        pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
4640        pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
4641      }
4642      else
4643      {
4644        assert(false);
4645      }
4646    }
4647  }
4648  else if( iX == 0 )
4649  {
4650    if( iY == 0 )
4651    {
4652      if( iDir == 2 )
4653      {
4654        pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
4655      }
4656      else if( iDir == 4 )
4657      {
4658        pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
4659      }
4660      else
4661      {
4662        assert(false);
4663      }
4664    }
4665    else if( iY == iHeight-1 )
4666    {
4667      if( iDir == 0 )
4668      {
4669        pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
4670      }
4671      else if( iDir == 6 )
4672      {
4673        pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
4674      }
4675      else
4676      {
4677        assert(false);
4678      }
4679    }
4680    else
4681    {
4682      if( iDir == 0 )
4683      {
4684        pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
4685      }
4686      else if( iDir == 2 )
4687      {
4688        pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
4689        pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
4690      }
4691      else if( iDir == 4 )
4692      {
4693        pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
4694        pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
4695      }
4696      else if( iDir == 6 )
4697      {
4698        pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
4699      }
4700      else
4701      {
4702        assert(false);
4703      }
4704    }
4705  }
4706  else if( iY == 0 )
4707  {
4708    if( iDir == 1 )
4709    {
4710      pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
4711      pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
4712    }
4713    else if( iDir == 2 )
4714    {
4715      pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
4716    }
4717    else if( iDir == 4 )
4718    {
4719      pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
4720    }
4721    else if( iDir == 5 )
4722    {
4723      pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
4724      pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
4725    }
4726    else
4727    {
4728      assert(false);
4729    }
4730  }
4731  else if( iY == iHeight-1 )
4732  {
4733    if( iDir == 0 )
4734    {
4735      pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
4736      pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
4737    }
4738    else if( iDir == 3 )
4739    {
4740      pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
4741    }
4742    else if( iDir == 6 )
4743    {
4744      pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
4745      pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
4746    }
4747    else if( iDir == 7 )
4748    {
4749      pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
4750    }
4751    else
4752    {
4753      assert(false);
4754    }
4755  }
4756  else
4757  {
4758    printf("reconPartiton: wrong termination\n");
4759    assert(false);
4760  }
4761
4762  // Reconstruct Region from Chain Code
4763  Bool* pbVisit  = (Bool*) xMalloc( Bool, iWidth * iHeight );
4764  Int*  piStack  = (Int* ) xMalloc( Int,  iWidth * iHeight );
4765
4766  for( UInt ui = 0; ui < iWidth * iHeight; ui++ )
4767  {
4768    pbRegion[ ui ] = true; // fill it as region 1 (we'll discover region 0 next)
4769    pbVisit [ ui ] = false;
4770  }
4771
4772  iPtr = 0;
4773  piStack[iPtr++] = (0 << 8) | (0);
4774  pbRegion[ 0 ] = false;
4775
4776  while(iPtr > 0)
4777  {
4778    Int iTmp = piStack[--iPtr];
4779    Int iX1, iY1;
4780    iX1 = iTmp & 0xff;
4781    iY1 = (iTmp >> 8) & 0xff;
4782
4783    pbVisit[ iX1 + iY1 * iWidth ] = true;
4784
4785    assert( iX1 >= 0 && iX1 < iWidth );
4786    assert( iY1 >= 0 && iY1 < iHeight );
4787
4788    if( iX1 > 0 && !pbEdge[ 2 * iX1 - 1 + 4 * iY1 * iWidth ] && !pbVisit[ iX1 - 1 + iY1 * iWidth ] )
4789    {
4790      piStack[iPtr++] = (iY1 << 8) | (iX1 - 1);
4791      pbRegion[ iX1 - 1 + iY1 * iWidth ] = false;
4792    }
4793    if( iX1 < iWidth - 1 && !pbEdge[ 2 * iX1 + 1 + 4 * iY1 * iWidth ] && !pbVisit[ iX1 + 1 + iY1 * iWidth ] )
4794    {
4795      piStack[iPtr++] = (iY1 << 8) | (iX1 + 1);
4796      pbRegion[ iX1 + 1 + iY1 * iWidth ] = false;
4797    }
4798    if( iY1 > 0 && !pbEdge[ 2 * iX1 + 2 * (2 * iY1 - 1) * iWidth ] && !pbVisit[ iX1 + (iY1 - 1) * iWidth ] )
4799    {
4800      piStack[iPtr++] = ((iY1 - 1) << 8) | iX1;
4801      pbRegion[ iX1 + (iY1 - 1) * iWidth ] = false;
4802    }
4803    if( iY1 < iHeight - 1 && !pbEdge[ 2 * iX1 + 2 * (2 * iY1 + 1) * iWidth ] && !pbVisit[ iX1 + (iY1 + 1) * iWidth ] )
4804    {
4805      piStack[iPtr++] = ((iY1 + 1) << 8) | iX1;
4806      pbRegion[ iX1 + (iY1 + 1) * iWidth ] = false;
4807    }
4808  }
4809
4810  xFree( pbEdge );
4811  xFree( pbVisit );
4812  xFree( piStack );
4813}
4814#endif
4815#endif
4816
4817//! \}
Note: See TracBrowser for help on using the repository browser.