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

Last change on this file since 464 was 464, checked in by zhang, 11 years ago

Implementation of ARP from QC

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