source: 3DVCSoftware/branches/0.3-poznan-univ/source/Lib/TLibCommon/TComDataCU.cpp @ 41

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

Adjustment for FlexCO, and high-level syntax improvement.

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