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

Last change on this file since 468 was 468, checked in by lg, 12 years ago

1.IC and full pel depth coding are integrated and is guarded by Macro H_3D_IC.

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