source: SHVCSoftware/trunk/source/Lib/TLibCommon/TComDataCU.cpp @ 19

Last change on this file since 19 was 12, checked in by seregin, 12 years ago

BUGFIX_925: integrated fix for the ticket #925

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