source: 3DVCSoftware/branches/0.2-poznan-univ/source/Lib/TLibCommon/TComDataCU.cpp @ 11

Last change on this file since 11 was 11, checked in by poznan-univ, 13 years ago

Poznan disocclusion coding - CU Skip

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