source: 3DVCSoftware/branches/HTM-DEV-2.0-dev1-QC-INTRA-MTK/source/Lib/TLibCommon/TComDataCU.cpp @ 587

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

code, simulation results and check list for JCT3V-E0126

  • Property svn:eol-style set to native
File size: 227.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-2013, ITU/ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/** \file     TComDataCU.cpp
35    \brief    CU data structure
36    \todo     not all entities are documented
37*/
38
39#include "TComDataCU.h"
40#include "TComPic.h"
41
42//! \ingroup TLibCommon
43//! \{
44
45#if ADAPTIVE_QP_SELECTION
46Int * TComDataCU::m_pcGlbArlCoeffY  = NULL;
47Int * TComDataCU::m_pcGlbArlCoeffCb = NULL;
48Int * TComDataCU::m_pcGlbArlCoeffCr = NULL;
49#endif
50
51// ====================================================================================================================
52// Constructor / destructor / create / destroy
53// ====================================================================================================================
54
55TComDataCU::TComDataCU()
56{
57  m_pcPic              = NULL;
58  m_pcSlice            = NULL;
59  m_puhDepth           = NULL;
60 
61  m_skipFlag           = NULL;
62
63  m_pePartSize         = NULL;
64  m_pePredMode         = NULL;
65  m_CUTransquantBypass = NULL;
66  m_puhWidth           = NULL;
67  m_puhHeight          = NULL;
68  m_phQP               = NULL;
69  m_pbMergeFlag        = NULL;
70  m_puhMergeIndex      = NULL;
71  m_puhLumaIntraDir    = NULL;
72  m_puhChromaIntraDir  = NULL;
73  m_puhInterDir        = NULL;
74  m_puhTrIdx           = NULL;
75  m_puhTransformSkip[0] = NULL;
76  m_puhTransformSkip[1] = NULL;
77  m_puhTransformSkip[2] = NULL;
78  m_puhCbf[0]          = NULL;
79  m_puhCbf[1]          = NULL;
80  m_puhCbf[2]          = NULL;
81  m_pcTrCoeffY         = NULL;
82  m_pcTrCoeffCb        = NULL;
83  m_pcTrCoeffCr        = NULL;
84#if ADAPTIVE_QP_SELECTION 
85  m_ArlCoeffIsAliasedAllocation = false;
86  m_pcArlCoeffY        = NULL;
87  m_pcArlCoeffCb       = NULL;
88  m_pcArlCoeffCr       = NULL;
89#endif
90 
91  m_pbIPCMFlag         = NULL;
92  m_pcIPCMSampleY      = NULL;
93  m_pcIPCMSampleCb     = NULL;
94  m_pcIPCMSampleCr     = NULL;
95
96  m_pcPattern          = NULL;
97 
98  m_pcCUAboveLeft      = NULL;
99  m_pcCUAboveRight     = NULL;
100  m_pcCUAbove          = NULL;
101  m_pcCULeft           = NULL;
102 
103  m_apcCUColocated[0]  = NULL;
104  m_apcCUColocated[1]  = NULL;
105 
106  m_apiMVPIdx[0]       = NULL;
107  m_apiMVPIdx[1]       = NULL;
108  m_apiMVPNum[0]       = NULL;
109  m_apiMVPNum[1]       = NULL;
110
111#if H_3D_DIM
112  for( Int i = 0; i < DIM_NUM_TYPE; i++ )
113  {
114    m_dimDeltaDC[i][0] = NULL; 
115    m_dimDeltaDC[i][1] = NULL;
116  }
117#if H_3D_DIM_DMM
118  for( Int i = 0; i < DMM_NUM_TYPE; i++ )
119  {
120    m_dmmWedgeTabIdx[i] = NULL;
121  }
122  m_dmm2DeltaEnd    = NULL;
123  m_dmm3IntraTabIdx = NULL;
124#endif
125#if H_3D_DIM_RBC
126  m_pucEdgeCode     = NULL;
127  m_pucEdgeNumber   = NULL;
128  m_pucEdgeStartPos = NULL;
129  m_pbEdgeLeftFirst = NULL;
130  m_pbEdgePartition = NULL;
131#endif
132#if H_3D_DIM_SDC
133  m_pbSDCFlag             = NULL;
134  m_apSegmentDCOffset[0]  = NULL;
135  m_apSegmentDCOffset[1]  = NULL;
136#endif
137#endif
138  m_bDecSubCu          = false;
139  m_sliceStartCU        = 0;
140  m_sliceSegmentStartCU = 0;
141#if H_3D_NBDV
142  m_pDvInfo              = NULL;
143#endif
144#if H_3D_VSP
145  m_piVSPFlag            = NULL;
146#if MTK_VSP_FIX_E0172
147  m_piVSPDir             = NULL;
148#endif
149#endif
150#if H_3D_ARP
151  m_puhARPW              = NULL;
152#endif
153#if H_3D_IC
154  m_pbICFlag             = NULL;
155#endif
156}
157
158TComDataCU::~TComDataCU()
159{
160}
161
162Void TComDataCU::create(UInt uiNumPartition, UInt uiWidth, UInt uiHeight, Bool bDecSubCu, Int unitSize
163#if ADAPTIVE_QP_SELECTION
164                        , Bool bGlobalRMARLBuffer
165#endif                                             
166                        )
167{
168  m_bDecSubCu = bDecSubCu;
169 
170  m_pcPic              = NULL;
171  m_pcSlice            = NULL;
172  m_uiNumPartition     = uiNumPartition;
173  m_unitSize = unitSize;
174 
175  if ( !bDecSubCu )
176  {
177    m_phQP               = (Char*     )xMalloc(Char,     uiNumPartition);
178    m_puhDepth           = (UChar*    )xMalloc(UChar,    uiNumPartition);
179    m_puhWidth           = (UChar*    )xMalloc(UChar,    uiNumPartition);
180    m_puhHeight          = (UChar*    )xMalloc(UChar,    uiNumPartition);
181
182    m_skipFlag           = new Bool[ uiNumPartition ];
183
184    m_pePartSize         = new Char[ uiNumPartition ];
185    memset( m_pePartSize, SIZE_NONE,uiNumPartition * sizeof( *m_pePartSize ) );
186    m_pePredMode         = new Char[ uiNumPartition ];
187    m_CUTransquantBypass = new Bool[ uiNumPartition ];
188    m_pbMergeFlag        = (Bool*  )xMalloc(Bool,   uiNumPartition);
189    m_puhMergeIndex      = (UChar* )xMalloc(UChar,  uiNumPartition);
190#if H_3D_VSP
191    m_piVSPFlag          = (Char*  )xMalloc(Char,   uiNumPartition);
192#if MTK_VSP_FIX_E0172
193    m_piVSPDir           = (Char*  )xMalloc(Char,   uiNumPartition);
194#endif
195#endif
196    m_puhLumaIntraDir    = (UChar* )xMalloc(UChar,  uiNumPartition);
197    m_puhChromaIntraDir  = (UChar* )xMalloc(UChar,  uiNumPartition);
198    m_puhInterDir        = (UChar* )xMalloc(UChar,  uiNumPartition);
199   
200    m_puhTrIdx           = (UChar* )xMalloc(UChar,  uiNumPartition);
201    m_puhTransformSkip[0] = (UChar* )xMalloc(UChar,  uiNumPartition);
202    m_puhTransformSkip[1] = (UChar* )xMalloc(UChar,  uiNumPartition);
203    m_puhTransformSkip[2] = (UChar* )xMalloc(UChar,  uiNumPartition);
204
205    m_puhCbf[0]          = (UChar* )xMalloc(UChar,  uiNumPartition);
206    m_puhCbf[1]          = (UChar* )xMalloc(UChar,  uiNumPartition);
207    m_puhCbf[2]          = (UChar* )xMalloc(UChar,  uiNumPartition);
208   
209    m_apiMVPIdx[0]       = new Char[ uiNumPartition ];
210    m_apiMVPIdx[1]       = new Char[ uiNumPartition ];
211    m_apiMVPNum[0]       = new Char[ uiNumPartition ];
212    m_apiMVPNum[1]       = new Char[ uiNumPartition ];
213    memset( m_apiMVPIdx[0], -1,uiNumPartition * sizeof( Char ) );
214    memset( m_apiMVPIdx[1], -1,uiNumPartition * sizeof( Char ) );
215   
216    m_pcTrCoeffY         = (TCoeff*)xMalloc(TCoeff, uiWidth*uiHeight);
217    m_pcTrCoeffCb        = (TCoeff*)xMalloc(TCoeff, uiWidth*uiHeight/4);
218    m_pcTrCoeffCr        = (TCoeff*)xMalloc(TCoeff, uiWidth*uiHeight/4);
219#if H_3D_NBDV
220    m_pDvInfo            = (DisInfo* )xMalloc(DisInfo,  uiNumPartition);
221#endif
222    memset( m_pcTrCoeffY, 0,uiWidth*uiHeight * sizeof( TCoeff ) );
223    memset( m_pcTrCoeffCb, 0,uiWidth*uiHeight/4 * sizeof( TCoeff ) );
224    memset( m_pcTrCoeffCr, 0,uiWidth*uiHeight/4 * sizeof( TCoeff ) );
225#if ADAPTIVE_QP_SELECTION   
226    if( bGlobalRMARLBuffer )
227    {
228      if( m_pcGlbArlCoeffY == NULL )
229      {
230        m_pcGlbArlCoeffY   = (Int*)xMalloc(Int, uiWidth*uiHeight);
231        m_pcGlbArlCoeffCb  = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
232        m_pcGlbArlCoeffCr  = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
233      }
234      m_pcArlCoeffY        = m_pcGlbArlCoeffY;
235      m_pcArlCoeffCb       = m_pcGlbArlCoeffCb;
236      m_pcArlCoeffCr       = m_pcGlbArlCoeffCr;
237      m_ArlCoeffIsAliasedAllocation = true;
238    }
239    else
240    {
241      m_pcArlCoeffY        = (Int*)xMalloc(Int, uiWidth*uiHeight);
242      m_pcArlCoeffCb       = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
243      m_pcArlCoeffCr       = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
244    }
245#endif
246   
247    m_pbIPCMFlag         = (Bool*  )xMalloc(Bool, uiNumPartition);
248    m_pcIPCMSampleY      = (Pel*   )xMalloc(Pel , uiWidth*uiHeight);
249    m_pcIPCMSampleCb     = (Pel*   )xMalloc(Pel , uiWidth*uiHeight/4);
250    m_pcIPCMSampleCr     = (Pel*   )xMalloc(Pel , uiWidth*uiHeight/4);
251
252    m_acCUMvField[0].create( uiNumPartition );
253    m_acCUMvField[1].create( uiNumPartition );
254   
255#if H_3D_ARP
256    m_puhARPW            = new UChar[ uiNumPartition];
257#endif
258#if H_3D_IC
259    m_pbICFlag           = (Bool* )xMalloc(Bool,   uiNumPartition);
260#endif
261#if H_3D_DIM
262    for( Int i = 0; i < DIM_NUM_TYPE; i++ )
263    {
264      m_dimDeltaDC[i][0] = (Pel* )xMalloc(Pel, uiNumPartition); 
265      m_dimDeltaDC[i][1] = (Pel* )xMalloc(Pel, uiNumPartition);
266    }
267#if H_3D_DIM_DMM
268    for( Int i = 0; i < DMM_NUM_TYPE; i++ )
269    {
270      m_dmmWedgeTabIdx[i]    = (UInt*)xMalloc(UInt, uiNumPartition);
271    }
272    m_dmm2DeltaEnd    = (Int* )xMalloc(Int,  uiNumPartition);
273    m_dmm3IntraTabIdx = (UInt*)xMalloc(UInt, uiNumPartition);
274#endif
275#if H_3D_DIM_RBC
276    m_pucEdgeCode     = (UChar*)xMalloc(UChar, uiNumPartition * RBC_MAX_EDGE_NUM_PER_4x4);
277    m_pucEdgeNumber   = (UChar*)xMalloc(UChar, uiNumPartition);
278    m_pucEdgeStartPos = (UChar*)xMalloc(UChar, uiNumPartition);
279    m_pbEdgeLeftFirst = (Bool*)xMalloc(Bool, uiNumPartition);
280    m_pbEdgePartition = (Bool*)xMalloc(Bool, uiNumPartition * 16);
281#endif
282#if H_3D_DIM_SDC
283    m_pbSDCFlag             = (Bool*)xMalloc(Bool, uiNumPartition);
284    m_apSegmentDCOffset[0]  = (Pel*)xMalloc(Pel, uiNumPartition);
285    m_apSegmentDCOffset[1]  = (Pel*)xMalloc(Pel, uiNumPartition);
286#endif
287#endif
288  }
289  else
290  {
291    m_acCUMvField[0].setNumPartition(uiNumPartition );
292    m_acCUMvField[1].setNumPartition(uiNumPartition );
293  }
294 
295  m_sliceStartCU        = (UInt*  )xMalloc(UInt, uiNumPartition);
296  m_sliceSegmentStartCU = (UInt*  )xMalloc(UInt, uiNumPartition);
297 
298  // create pattern memory
299  m_pcPattern            = (TComPattern*)xMalloc(TComPattern, 1);
300 
301  // create motion vector fields
302 
303  m_pcCUAboveLeft      = NULL;
304  m_pcCUAboveRight     = NULL;
305  m_pcCUAbove          = NULL;
306  m_pcCULeft           = NULL;
307 
308  m_apcCUColocated[0]  = NULL;
309  m_apcCUColocated[1]  = NULL;
310}
311
312Void TComDataCU::destroy()
313{
314  m_pcPic              = NULL;
315  m_pcSlice            = NULL;
316 
317  if ( m_pcPattern )
318  { 
319    xFree(m_pcPattern);
320    m_pcPattern = NULL;
321  }
322 
323  // encoder-side buffer free
324  if ( !m_bDecSubCu )
325  {
326    if ( m_phQP               ) { xFree(m_phQP);                m_phQP              = NULL; }
327    if ( m_puhDepth           ) { xFree(m_puhDepth);            m_puhDepth          = NULL; }
328    if ( m_puhWidth           ) { xFree(m_puhWidth);            m_puhWidth          = NULL; }
329    if ( m_puhHeight          ) { xFree(m_puhHeight);           m_puhHeight         = NULL; }
330
331    if ( m_skipFlag           ) { delete[] m_skipFlag;          m_skipFlag          = NULL; }
332
333    if ( m_pePartSize         ) { delete[] m_pePartSize;        m_pePartSize        = NULL; }
334    if ( m_pePredMode         ) { delete[] m_pePredMode;        m_pePredMode        = NULL; }
335    if ( m_CUTransquantBypass ) { delete[] m_CUTransquantBypass;m_CUTransquantBypass = NULL; }
336    if ( m_puhCbf[0]          ) { xFree(m_puhCbf[0]);           m_puhCbf[0]         = NULL; }
337    if ( m_puhCbf[1]          ) { xFree(m_puhCbf[1]);           m_puhCbf[1]         = NULL; }
338    if ( m_puhCbf[2]          ) { xFree(m_puhCbf[2]);           m_puhCbf[2]         = NULL; }
339    if ( m_puhInterDir        ) { xFree(m_puhInterDir);         m_puhInterDir       = NULL; }
340    if ( m_pbMergeFlag        ) { xFree(m_pbMergeFlag);         m_pbMergeFlag       = NULL; }
341    if ( m_puhMergeIndex      ) { xFree(m_puhMergeIndex);       m_puhMergeIndex     = NULL; }
342#if H_3D_VSP
343    if ( m_piVSPFlag          ) { xFree(m_piVSPFlag);           m_piVSPFlag         = NULL; }
344#if MTK_VSP_FIX_E0172
345    if ( m_piVSPDir           ) { xFree(m_piVSPDir  );          m_piVSPDir          = NULL; }
346#endif
347#endif
348    if ( m_puhLumaIntraDir    ) { xFree(m_puhLumaIntraDir);     m_puhLumaIntraDir   = NULL; }
349    if ( m_puhChromaIntraDir  ) { xFree(m_puhChromaIntraDir);   m_puhChromaIntraDir = NULL; }
350    if ( m_puhTrIdx           ) { xFree(m_puhTrIdx);            m_puhTrIdx          = NULL; }
351    if ( m_puhTransformSkip[0]) { xFree(m_puhTransformSkip[0]); m_puhTransformSkip[0] = NULL; }
352    if ( m_puhTransformSkip[1]) { xFree(m_puhTransformSkip[1]); m_puhTransformSkip[1] = NULL; }
353    if ( m_puhTransformSkip[2]) { xFree(m_puhTransformSkip[2]); m_puhTransformSkip[2] = NULL; }
354    if ( m_pcTrCoeffY         ) { xFree(m_pcTrCoeffY);          m_pcTrCoeffY        = NULL; }
355    if ( m_pcTrCoeffCb        ) { xFree(m_pcTrCoeffCb);         m_pcTrCoeffCb       = NULL; }
356    if ( m_pcTrCoeffCr        ) { xFree(m_pcTrCoeffCr);         m_pcTrCoeffCr       = NULL; }
357#if ADAPTIVE_QP_SELECTION
358    if (!m_ArlCoeffIsAliasedAllocation)
359    {
360      xFree(m_pcArlCoeffY); m_pcArlCoeffY = 0;
361      xFree(m_pcArlCoeffCb); m_pcArlCoeffCb = 0;
362      xFree(m_pcArlCoeffCr); m_pcArlCoeffCr = 0;
363    }
364    if ( m_pcGlbArlCoeffY     ) { xFree(m_pcGlbArlCoeffY);      m_pcGlbArlCoeffY    = NULL; }
365    if ( m_pcGlbArlCoeffCb    ) { xFree(m_pcGlbArlCoeffCb);     m_pcGlbArlCoeffCb   = NULL; }
366    if ( m_pcGlbArlCoeffCr    ) { xFree(m_pcGlbArlCoeffCr);     m_pcGlbArlCoeffCr   = NULL; }
367#endif
368    if ( m_pbIPCMFlag         ) { xFree(m_pbIPCMFlag   );       m_pbIPCMFlag        = NULL; }
369    if ( m_pcIPCMSampleY      ) { xFree(m_pcIPCMSampleY);       m_pcIPCMSampleY     = NULL; }
370    if ( m_pcIPCMSampleCb     ) { xFree(m_pcIPCMSampleCb);      m_pcIPCMSampleCb    = NULL; }
371    if ( m_pcIPCMSampleCr     ) { xFree(m_pcIPCMSampleCr);      m_pcIPCMSampleCr    = NULL; }
372    if ( m_apiMVPIdx[0]       ) { delete[] m_apiMVPIdx[0];      m_apiMVPIdx[0]      = NULL; }
373    if ( m_apiMVPIdx[1]       ) { delete[] m_apiMVPIdx[1];      m_apiMVPIdx[1]      = NULL; }
374    if ( m_apiMVPNum[0]       ) { delete[] m_apiMVPNum[0];      m_apiMVPNum[0]      = NULL; }
375    if ( m_apiMVPNum[1]       ) { delete[] m_apiMVPNum[1];      m_apiMVPNum[1]      = NULL; }
376#if H_3D_NBDV
377    if ( m_pDvInfo            ) { xFree(m_pDvInfo);             m_pDvInfo           = NULL; }
378#endif
379
380#if H_3D_ARP
381    if ( m_puhARPW            ) { delete[] m_puhARPW;           m_puhARPW           = NULL; }
382#endif
383#if H_3D_IC
384    if ( m_pbICFlag           ) { xFree(m_pbICFlag);            m_pbICFlag          = NULL; }
385#endif
386    m_acCUMvField[0].destroy();
387    m_acCUMvField[1].destroy();
388
389#if H_3D_DIM
390    for( Int i = 0; i < DIM_NUM_TYPE; i++ )
391    {
392      if ( m_dimDeltaDC[i][0] ) { xFree( m_dimDeltaDC[i][0] ); m_dimDeltaDC[i][0] = NULL; }
393      if ( m_dimDeltaDC[i][1] ) { xFree( m_dimDeltaDC[i][1] ); m_dimDeltaDC[i][1] = NULL; }
394    }
395#if H_3D_DIM_DMM
396    for( Int i = 0; i < DMM_NUM_TYPE; i++ )
397    {
398      if ( m_dmmWedgeTabIdx[i] ) { xFree( m_dmmWedgeTabIdx[i] ); m_dmmWedgeTabIdx[i] = NULL; }
399    }
400    if ( m_dmm2DeltaEnd    ) { xFree( m_dmm2DeltaEnd    ); m_dmm2DeltaEnd    = NULL; }
401    if ( m_dmm3IntraTabIdx ) { xFree( m_dmm3IntraTabIdx ); m_dmm3IntraTabIdx = NULL; }
402#endif
403#if H_3D_DIM_RBC
404    if ( m_pbEdgeLeftFirst ) { xFree( m_pbEdgeLeftFirst ); m_pbEdgeLeftFirst = NULL; }
405    if ( m_pucEdgeStartPos ) { xFree( m_pucEdgeStartPos ); m_pucEdgeStartPos = NULL; }
406    if ( m_pucEdgeNumber   ) { xFree( m_pucEdgeNumber   ); m_pucEdgeNumber   = NULL; }
407    if ( m_pucEdgeCode     ) { xFree( m_pucEdgeCode     ); m_pucEdgeCode     = NULL; }
408    if ( m_pbEdgePartition ) { xFree( m_pbEdgePartition ); m_pbEdgePartition = NULL; }
409#endif
410#if H_3D_DIM_SDC
411    if ( m_pbSDCFlag            ) { xFree(m_pbSDCFlag);             m_pbSDCFlag             = NULL; }
412    if ( m_apSegmentDCOffset[0] ) { xFree(m_apSegmentDCOffset[0]);  m_apSegmentDCOffset[0]  = NULL; }
413    if ( m_apSegmentDCOffset[1] ) { xFree(m_apSegmentDCOffset[1]);  m_apSegmentDCOffset[1]  = NULL; }
414#endif
415#endif   
416  }
417 
418  m_pcCUAboveLeft       = NULL;
419  m_pcCUAboveRight      = NULL;
420  m_pcCUAbove           = NULL;
421  m_pcCULeft            = NULL;
422 
423  m_apcCUColocated[0]   = NULL;
424  m_apcCUColocated[1]   = NULL;
425
426  if( m_sliceStartCU )
427  {
428    xFree(m_sliceStartCU);
429    m_sliceStartCU=NULL;
430  }
431  if(m_sliceSegmentStartCU )
432  {
433    xFree(m_sliceSegmentStartCU);
434    m_sliceSegmentStartCU=NULL;
435  }
436}
437
438const NDBFBlockInfo& NDBFBlockInfo::operator= (const NDBFBlockInfo& src)
439{
440  this->tileID = src.tileID;
441  this->sliceID= src.sliceID;
442  this->startSU= src.startSU;
443  this->endSU  = src.endSU;
444  this->widthSU= src.widthSU;
445  this->heightSU=src.heightSU;
446  this->posX   = src.posX;
447  this->posY   = src.posY;
448  this->width  = src.width;
449  this->height = src.height;
450  ::memcpy(this->isBorderAvailable, src.isBorderAvailable, sizeof(Bool)*((Int)NUM_SGU_BORDER));
451  this->allBordersAvailable = src.allBordersAvailable;
452
453  return *this;
454}
455
456
457// ====================================================================================================================
458// Public member functions
459// ====================================================================================================================
460
461// --------------------------------------------------------------------------------------------------------------------
462// Initialization
463// --------------------------------------------------------------------------------------------------------------------
464
465/**
466 - initialize top-level CU
467 - internal buffers are already created
468 - set values before encoding a CU
469 .
470 \param  pcPic     picture (TComPic) class pointer
471 \param  iCUAddr   CU address
472 */
473Void TComDataCU::initCU( TComPic* pcPic, UInt iCUAddr )
474{
475
476  m_pcPic              = pcPic;
477  m_pcSlice            = pcPic->getSlice(pcPic->getCurrSliceIdx());
478  m_uiCUAddr           = iCUAddr;
479  m_uiCUPelX           = ( iCUAddr % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth;
480  m_uiCUPelY           = ( iCUAddr / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight;
481  m_uiAbsIdxInLCU      = 0;
482  m_dTotalCost         = MAX_DOUBLE;
483  m_uiTotalDistortion  = 0;
484  m_uiTotalBits        = 0;
485  m_uiTotalBins        = 0;
486  m_uiNumPartition     = pcPic->getNumPartInCU();
487 
488  for(Int i=0; i<pcPic->getNumPartInCU(); i++)
489  {
490    if(pcPic->getPicSym()->getInverseCUOrderMap(iCUAddr)*pcPic->getNumPartInCU()+i>=getSlice()->getSliceCurStartCUAddr())
491    {
492      m_sliceStartCU[i]=getSlice()->getSliceCurStartCUAddr();
493    }
494    else
495    {
496      m_sliceStartCU[i]=pcPic->getCU(getAddr())->m_sliceStartCU[i];
497    }
498  }
499  for(Int i=0; i<pcPic->getNumPartInCU(); i++)
500  {
501    if(pcPic->getPicSym()->getInverseCUOrderMap(iCUAddr)*pcPic->getNumPartInCU()+i>=getSlice()->getSliceSegmentCurStartCUAddr())
502    {
503      m_sliceSegmentStartCU[i]=getSlice()->getSliceSegmentCurStartCUAddr();
504    }
505    else
506    {
507      m_sliceSegmentStartCU[i]=pcPic->getCU(getAddr())->m_sliceSegmentStartCU[i];
508    }
509  }
510
511  Int partStartIdx = getSlice()->getSliceSegmentCurStartCUAddr() - pcPic->getPicSym()->getInverseCUOrderMap(iCUAddr) * pcPic->getNumPartInCU();
512
513  Int numElements = min<Int>( partStartIdx, m_uiNumPartition );
514  for ( Int ui = 0; ui < numElements; ui++ )
515  {
516    TComDataCU * pcFrom = pcPic->getCU(getAddr());
517    m_skipFlag[ui]   = pcFrom->getSkipFlag(ui);
518    m_pePartSize[ui] = pcFrom->getPartitionSize(ui);
519    m_pePredMode[ui] = pcFrom->getPredictionMode(ui);
520    m_CUTransquantBypass[ui] = pcFrom->getCUTransquantBypass(ui);
521    m_puhDepth[ui] = pcFrom->getDepth(ui);
522#if H_3D_ARP
523    m_puhARPW   [ui] = pcFrom->getARPW( ui );
524#endif
525#if H_3D_IC
526    m_pbICFlag[ui]   =  pcFrom->m_pbICFlag[ui];
527#endif
528    m_puhWidth  [ui] = pcFrom->getWidth(ui);
529    m_puhHeight [ui] = pcFrom->getHeight(ui);
530    m_puhTrIdx  [ui] = pcFrom->getTransformIdx(ui);
531    m_puhTransformSkip[0][ui] = pcFrom->getTransformSkip(ui,TEXT_LUMA);
532    m_puhTransformSkip[1][ui] = pcFrom->getTransformSkip(ui,TEXT_CHROMA_U);
533    m_puhTransformSkip[2][ui] = pcFrom->getTransformSkip(ui,TEXT_CHROMA_V);
534    m_apiMVPIdx[0][ui] = pcFrom->m_apiMVPIdx[0][ui];;
535    m_apiMVPIdx[1][ui] = pcFrom->m_apiMVPIdx[1][ui];
536    m_apiMVPNum[0][ui] = pcFrom->m_apiMVPNum[0][ui];
537    m_apiMVPNum[1][ui] = pcFrom->m_apiMVPNum[1][ui];
538    m_phQP[ui]=pcFrom->m_phQP[ui];
539    m_pbMergeFlag[ui]=pcFrom->m_pbMergeFlag[ui];
540    m_puhMergeIndex[ui]=pcFrom->m_puhMergeIndex[ui];
541#if H_3D_VSP
542    m_piVSPFlag[ui] = pcFrom->m_piVSPFlag[ui];
543#if MTK_VSP_FIX_E0172
544    m_piVSPDir  [ui] = pcFrom->m_piVSPDir[ui];
545#endif
546#endif
547    m_puhLumaIntraDir[ui]=pcFrom->m_puhLumaIntraDir[ui];
548    m_puhChromaIntraDir[ui]=pcFrom->m_puhChromaIntraDir[ui];
549    m_puhInterDir[ui]=pcFrom->m_puhInterDir[ui];
550    m_puhCbf[0][ui]=pcFrom->m_puhCbf[0][ui];
551    m_puhCbf[1][ui]=pcFrom->m_puhCbf[1][ui];
552    m_puhCbf[2][ui]=pcFrom->m_puhCbf[2][ui];
553    m_pbIPCMFlag[ui] = pcFrom->m_pbIPCMFlag[ui];
554#if H_3D_DIM_SDC
555    m_pbSDCFlag[ui] = pcFrom->m_pbSDCFlag[ui];
556#endif
557  }
558 
559  Int firstElement = max<Int>( partStartIdx, 0 );
560  numElements = m_uiNumPartition - firstElement;
561 
562  if ( numElements > 0 )
563  {
564    memset( m_skipFlag          + firstElement, false,                    numElements * sizeof( *m_skipFlag ) );
565
566    memset( m_pePartSize        + firstElement, SIZE_NONE,                numElements * sizeof( *m_pePartSize ) );
567    memset( m_pePredMode        + firstElement, MODE_NONE,                numElements * sizeof( *m_pePredMode ) );
568    memset( m_CUTransquantBypass+ firstElement, false,                    numElements * sizeof( *m_CUTransquantBypass) );
569    memset( m_puhDepth          + firstElement, 0,                        numElements * sizeof( *m_puhDepth ) );
570    memset( m_puhTrIdx          + firstElement, 0,                        numElements * sizeof( *m_puhTrIdx ) );
571    memset( m_puhTransformSkip[0] + firstElement, 0,                      numElements * sizeof( *m_puhTransformSkip[0]) );
572    memset( m_puhTransformSkip[1] + firstElement, 0,                      numElements * sizeof( *m_puhTransformSkip[1]) );
573    memset( m_puhTransformSkip[2] + firstElement, 0,                      numElements * sizeof( *m_puhTransformSkip[2]) );
574    memset( m_puhWidth          + firstElement, g_uiMaxCUWidth,           numElements * sizeof( *m_puhWidth ) );
575    memset( m_puhHeight         + firstElement, g_uiMaxCUHeight,          numElements * sizeof( *m_puhHeight ) );
576    memset( m_apiMVPIdx[0]      + firstElement, -1,                       numElements * sizeof( *m_apiMVPIdx[0] ) );
577    memset( m_apiMVPIdx[1]      + firstElement, -1,                       numElements * sizeof( *m_apiMVPIdx[1] ) );
578    memset( m_apiMVPNum[0]      + firstElement, -1,                       numElements * sizeof( *m_apiMVPNum[0] ) );
579    memset( m_apiMVPNum[1]      + firstElement, -1,                       numElements * sizeof( *m_apiMVPNum[1] ) );
580    memset( m_phQP              + firstElement, getSlice()->getSliceQp(), numElements * sizeof( *m_phQP ) );
581    memset( m_pbMergeFlag       + firstElement, false,                    numElements * sizeof( *m_pbMergeFlag ) );
582    memset( m_puhMergeIndex     + firstElement, 0,                        numElements * sizeof( *m_puhMergeIndex ) );
583#if H_3D_VSP
584    memset( m_piVSPFlag         + firstElement, 0,                        numElements * sizeof( *m_piVSPFlag ) );
585#if MTK_VSP_FIX_E0172
586    memset( m_piVSPDir          + firstElement, 0,                        numElements * sizeof( *m_piVSPDir   ) );
587#endif
588#endif
589    memset( m_puhLumaIntraDir   + firstElement, DC_IDX,                   numElements * sizeof( *m_puhLumaIntraDir ) );
590    memset( m_puhChromaIntraDir + firstElement, 0,                        numElements * sizeof( *m_puhChromaIntraDir ) );
591    memset( m_puhInterDir       + firstElement, 0,                        numElements * sizeof( *m_puhInterDir ) );
592    memset( m_puhCbf[0]         + firstElement, 0,                        numElements * sizeof( *m_puhCbf[0] ) );
593    memset( m_puhCbf[1]         + firstElement, 0,                        numElements * sizeof( *m_puhCbf[1] ) );
594    memset( m_puhCbf[2]         + firstElement, 0,                        numElements * sizeof( *m_puhCbf[2] ) );
595    memset( m_pbIPCMFlag        + firstElement, false,                    numElements * sizeof( *m_pbIPCMFlag ) );
596#if H_3D_ARP
597    memset( m_puhARPW           + firstElement, 0,                        numElements * sizeof( UChar )         );
598#endif
599#if H_3D_IC
600    memset( m_pbICFlag          + firstElement, false,                    numElements * sizeof( *m_pbICFlag )   );
601#endif
602#if H_3D_DIM
603    for( Int i = 0; i < DIM_NUM_TYPE; i++ )
604    {
605      memset( m_dimDeltaDC[i][0] + firstElement, 0,                       numElements * sizeof( *m_dimDeltaDC[i][0] ) );
606      memset( m_dimDeltaDC[i][1] + firstElement, 0,                       numElements * sizeof( *m_dimDeltaDC[i][1] ) );
607    }
608#if H_3D_DIM_DMM
609    for( Int i = 0; i < DMM_NUM_TYPE; i++ )
610    {
611      memset( m_dmmWedgeTabIdx[i] + firstElement, 0,                      numElements * sizeof( *m_dmmWedgeTabIdx[i] ) );
612    }
613    memset( m_dmm2DeltaEnd      + firstElement, 0,                        numElements * sizeof( *m_dmm2DeltaEnd    ) );
614    memset( m_dmm3IntraTabIdx   + firstElement, 0,                        numElements * sizeof( *m_dmm3IntraTabIdx ) );
615#endif
616#if H_3D_DIM_RBC
617    memset( m_pucEdgeCode       + firstElement, 0,                        numElements * sizeof( *m_pucEdgeCode     ) * RBC_MAX_EDGE_NUM_PER_4x4 );
618    memset( m_pucEdgeNumber     + firstElement, 0,                        numElements * sizeof( *m_pucEdgeNumber   ) );
619    memset( m_pucEdgeStartPos   + firstElement, 0,                        numElements * sizeof( *m_pucEdgeStartPos ) );
620    memset( m_pbEdgeLeftFirst   + firstElement, false,                    numElements * sizeof( *m_pbEdgeLeftFirst ) );
621    memset( m_pbEdgePartition   + firstElement, false,                    numElements * sizeof( *m_pbEdgePartition ) * 16 );
622#endif
623#if H_3D_DIM_SDC
624    memset( m_pbSDCFlag             + firstElement,     0,                numElements * sizeof( *m_pbSDCFlag            ) );
625    memset( m_apSegmentDCOffset[0]  + firstElement,     0,                numElements * sizeof( *m_apSegmentDCOffset[0] ) );
626    memset( m_apSegmentDCOffset[1]  + firstElement,     0,                numElements * sizeof( *m_apSegmentDCOffset[1] ) );
627#endif
628#endif
629  }
630 
631  UInt uiTmp = g_uiMaxCUWidth*g_uiMaxCUHeight;
632  if ( 0 >= partStartIdx ) 
633  {
634    m_acCUMvField[0].clearMvField();
635    m_acCUMvField[1].clearMvField();
636    memset( m_pcTrCoeffY , 0, sizeof( TCoeff ) * uiTmp );
637#if ADAPTIVE_QP_SELECTION
638    memset( m_pcArlCoeffY , 0, sizeof( Int ) * uiTmp ); 
639#endif
640    memset( m_pcIPCMSampleY , 0, sizeof( Pel ) * uiTmp );
641    uiTmp  >>= 2;
642    memset( m_pcTrCoeffCb, 0, sizeof( TCoeff ) * uiTmp );
643    memset( m_pcTrCoeffCr, 0, sizeof( TCoeff ) * uiTmp );
644#if ADAPTIVE_QP_SELECTION 
645    memset( m_pcArlCoeffCb, 0, sizeof( Int ) * uiTmp );
646    memset( m_pcArlCoeffCr, 0, sizeof( Int ) * uiTmp );
647#endif
648    memset( m_pcIPCMSampleCb , 0, sizeof( Pel ) * uiTmp );
649    memset( m_pcIPCMSampleCr , 0, sizeof( Pel ) * uiTmp );
650  }
651  else 
652  {
653    TComDataCU * pcFrom = pcPic->getCU(getAddr());
654    m_acCUMvField[0].copyFrom(&pcFrom->m_acCUMvField[0],m_uiNumPartition,0);
655    m_acCUMvField[1].copyFrom(&pcFrom->m_acCUMvField[1],m_uiNumPartition,0);
656    for(Int i=0; i<uiTmp; i++)
657    {
658      m_pcTrCoeffY[i]=pcFrom->m_pcTrCoeffY[i];
659#if ADAPTIVE_QP_SELECTION
660      m_pcArlCoeffY[i]=pcFrom->m_pcArlCoeffY[i];
661#endif
662      m_pcIPCMSampleY[i]=pcFrom->m_pcIPCMSampleY[i];
663    }
664    for(Int i=0; i<(uiTmp>>2); i++)
665    {
666      m_pcTrCoeffCb[i]=pcFrom->m_pcTrCoeffCb[i];
667      m_pcTrCoeffCr[i]=pcFrom->m_pcTrCoeffCr[i];
668#if ADAPTIVE_QP_SELECTION
669      m_pcArlCoeffCb[i]=pcFrom->m_pcArlCoeffCb[i];
670      m_pcArlCoeffCr[i]=pcFrom->m_pcArlCoeffCr[i];
671#endif
672      m_pcIPCMSampleCb[i]=pcFrom->m_pcIPCMSampleCb[i];
673      m_pcIPCMSampleCr[i]=pcFrom->m_pcIPCMSampleCr[i];
674    }
675  }
676
677  // Setting neighbor CU
678  m_pcCULeft        = NULL;
679  m_pcCUAbove       = NULL;
680  m_pcCUAboveLeft   = NULL;
681  m_pcCUAboveRight  = NULL;
682
683  m_apcCUColocated[0] = NULL;
684  m_apcCUColocated[1] = NULL;
685
686  UInt uiWidthInCU = pcPic->getFrameWidthInCU();
687  if ( m_uiCUAddr % uiWidthInCU )
688  {
689    m_pcCULeft = pcPic->getCU( m_uiCUAddr - 1 );
690  }
691
692  if ( m_uiCUAddr / uiWidthInCU )
693  {
694    m_pcCUAbove = pcPic->getCU( m_uiCUAddr - uiWidthInCU );
695  }
696
697  if ( m_pcCULeft && m_pcCUAbove )
698  {
699    m_pcCUAboveLeft = pcPic->getCU( m_uiCUAddr - uiWidthInCU - 1 );
700  }
701
702  if ( m_pcCUAbove && ( (m_uiCUAddr%uiWidthInCU) < (uiWidthInCU-1) )  )
703  {
704    m_pcCUAboveRight = pcPic->getCU( m_uiCUAddr - uiWidthInCU + 1 );
705  }
706
707  if ( getSlice()->getNumRefIdx( REF_PIC_LIST_0 ) > 0 )
708  {
709    m_apcCUColocated[0] = getSlice()->getRefPic( REF_PIC_LIST_0, 0)->getCU( m_uiCUAddr );
710  }
711
712  if ( getSlice()->getNumRefIdx( REF_PIC_LIST_1 ) > 0 )
713  {
714    m_apcCUColocated[1] = getSlice()->getRefPic( REF_PIC_LIST_1, 0)->getCU( m_uiCUAddr );
715  }
716}
717
718/** initialize prediction data with enabling sub-LCU-level delta QP
719*\param  uiDepth  depth of the current CU
720*\param  qp     qp for the current CU
721*- set CU width and CU height according to depth
722*- set qp value according to input qp
723*- set last-coded qp value according to input last-coded qp
724*/
725Void TComDataCU::initEstData( UInt uiDepth, Int qp )
726{
727  m_dTotalCost         = MAX_DOUBLE;
728  m_uiTotalDistortion  = 0;
729  m_uiTotalBits        = 0;
730  m_uiTotalBins        = 0;
731
732  UChar uhWidth  = g_uiMaxCUWidth  >> uiDepth;
733  UChar uhHeight = g_uiMaxCUHeight >> uiDepth;
734
735  for (UInt ui = 0; ui < m_uiNumPartition; ui++)
736  {
737    if(getPic()->getPicSym()->getInverseCUOrderMap(getAddr())*m_pcPic->getNumPartInCU()+m_uiAbsIdxInLCU+ui >= getSlice()->getSliceSegmentCurStartCUAddr())
738    {
739      m_apiMVPIdx[0][ui] = -1;
740      m_apiMVPIdx[1][ui] = -1;
741      m_apiMVPNum[0][ui] = -1;
742      m_apiMVPNum[1][ui] = -1;
743      m_puhDepth  [ui] = uiDepth;
744      m_puhWidth  [ui] = uhWidth;
745      m_puhHeight [ui] = uhHeight;
746      m_puhTrIdx  [ui] = 0;
747      m_puhTransformSkip[0][ui] = 0;
748      m_puhTransformSkip[1][ui] = 0;
749      m_puhTransformSkip[2][ui] = 0;
750      m_skipFlag[ui]   = false;
751      m_pePartSize[ui] = SIZE_NONE;
752      m_pePredMode[ui] = MODE_NONE;
753      m_CUTransquantBypass[ui] = false;
754      m_pbIPCMFlag[ui] = 0;
755      m_phQP[ui] = qp;
756      m_pbMergeFlag[ui] = 0;
757      m_puhMergeIndex[ui] = 0;
758#if H_3D_VSP
759      m_piVSPFlag[ui] = 0;
760#if MTK_VSP_FIX_E0172
761      m_piVSPDir  [ui] = 0;
762#endif
763#endif
764      m_puhLumaIntraDir[ui] = DC_IDX;
765      m_puhChromaIntraDir[ui] = 0;
766      m_puhInterDir[ui] = 0;
767      m_puhCbf[0][ui] = 0;
768      m_puhCbf[1][ui] = 0;
769      m_puhCbf[2][ui] = 0;
770#if H_3D_ARP
771      m_puhARPW[ui] = 0;
772#endif
773#if H_3D_IC
774      m_pbICFlag[ui]  = false;
775#endif
776#if H_3D_DIM
777      for( Int i = 0; i < DIM_NUM_TYPE; i++ )
778      {
779        m_dimDeltaDC[i][0] [ui] = 0;
780        m_dimDeltaDC[i][1] [ui] = 0;
781      }
782#if H_3D_DIM_DMM
783      for( Int i = 0; i < DMM_NUM_TYPE; i++ )
784      {
785        m_dmmWedgeTabIdx[i] [ui] = 0;
786      }
787      m_dmm2DeltaEnd    [ui] = 0;
788      m_dmm3IntraTabIdx [ui] = 0;
789#endif
790#if H_3D_DIM_SDC
791      m_pbSDCFlag           [ui] = false;
792      m_apSegmentDCOffset[0][ui] = 0;
793      m_apSegmentDCOffset[1][ui] = 0;
794#endif
795#endif
796    }
797  }
798
799  if(getPic()->getPicSym()->getInverseCUOrderMap(getAddr())*m_pcPic->getNumPartInCU()+m_uiAbsIdxInLCU >= getSlice()->getSliceSegmentCurStartCUAddr())
800  {
801    m_acCUMvField[0].clearMvField();
802    m_acCUMvField[1].clearMvField();
803    UInt uiTmp = uhWidth*uhHeight;
804   
805    memset( m_pcTrCoeffY,    0, uiTmp * sizeof( *m_pcTrCoeffY    ) );
806#if ADAPTIVE_QP_SELECTION
807    memset( m_pcArlCoeffY ,  0, uiTmp * sizeof( *m_pcArlCoeffY   ) );
808#endif
809    memset( m_pcIPCMSampleY, 0, uiTmp * sizeof( *m_pcIPCMSampleY ) );
810
811    uiTmp>>=2;
812    memset( m_pcTrCoeffCb,    0, uiTmp * sizeof( *m_pcTrCoeffCb    ) );
813    memset( m_pcTrCoeffCr,    0, uiTmp * sizeof( *m_pcTrCoeffCr    ) );
814#if ADAPTIVE_QP_SELECTION 
815    memset( m_pcArlCoeffCb,   0, uiTmp * sizeof( *m_pcArlCoeffCb   ) );
816    memset( m_pcArlCoeffCr,   0, uiTmp * sizeof( *m_pcArlCoeffCr   ) );
817#endif
818    memset( m_pcIPCMSampleCb, 0, uiTmp * sizeof( *m_pcIPCMSampleCb ) );
819    memset( m_pcIPCMSampleCr, 0, uiTmp * sizeof( *m_pcIPCMSampleCr ) );
820  }
821}
822
823
824// initialize Sub partition
825Void TComDataCU::initSubCU( TComDataCU* pcCU, UInt uiPartUnitIdx, UInt uiDepth, Int qp )
826{
827  assert( uiPartUnitIdx<4 );
828
829  UInt uiPartOffset = ( pcCU->getTotalNumPart()>>2 )*uiPartUnitIdx;
830
831  m_pcPic              = pcCU->getPic();
832  m_pcSlice            = m_pcPic->getSlice(m_pcPic->getCurrSliceIdx());
833  m_uiCUAddr           = pcCU->getAddr();
834  m_uiAbsIdxInLCU      = pcCU->getZorderIdxInCU() + uiPartOffset;
835
836  m_uiCUPelX           = pcCU->getCUPelX() + ( g_uiMaxCUWidth>>uiDepth  )*( uiPartUnitIdx &  1 );
837  m_uiCUPelY           = pcCU->getCUPelY() + ( g_uiMaxCUHeight>>uiDepth  )*( uiPartUnitIdx >> 1 );
838
839  m_dTotalCost         = MAX_DOUBLE;
840  m_uiTotalDistortion  = 0;
841  m_uiTotalBits        = 0;
842  m_uiTotalBins        = 0;
843  m_uiNumPartition     = pcCU->getTotalNumPart() >> 2;
844
845  Int iSizeInUchar = sizeof( UChar  ) * m_uiNumPartition;
846  Int iSizeInBool  = sizeof( Bool   ) * m_uiNumPartition;
847
848  Int sizeInChar = sizeof( Char  ) * m_uiNumPartition;
849  memset( m_phQP,              qp,  sizeInChar );
850
851  memset( m_pbMergeFlag,        0, iSizeInBool  );
852  memset( m_puhMergeIndex,      0, iSizeInUchar );
853#if H_3D_VSP
854  memset( m_piVSPFlag,          0, sizeof( Char  ) * m_uiNumPartition );
855#if MTK_VSP_FIX_E0172
856  memset( m_piVSPDir  ,         0, sizeInChar );
857#endif
858#endif
859  memset( m_puhLumaIntraDir,    DC_IDX, iSizeInUchar );
860  memset( m_puhChromaIntraDir,  0, iSizeInUchar );
861  memset( m_puhInterDir,        0, iSizeInUchar );
862  memset( m_puhTrIdx,           0, iSizeInUchar );
863  memset( m_puhTransformSkip[0], 0, iSizeInUchar );
864  memset( m_puhTransformSkip[1], 0, iSizeInUchar );
865  memset( m_puhTransformSkip[2], 0, iSizeInUchar );
866  memset( m_puhCbf[0],          0, iSizeInUchar );
867  memset( m_puhCbf[1],          0, iSizeInUchar );
868  memset( m_puhCbf[2],          0, iSizeInUchar );
869  memset( m_puhDepth,     uiDepth, iSizeInUchar );
870#if H_3D_NBDV
871  m_pDvInfo->bDV = false;
872#endif
873#if H_3D_ARP
874  memset( m_puhARPW,            0, iSizeInUchar  );
875#endif
876  UChar uhWidth  = g_uiMaxCUWidth  >> uiDepth;
877  UChar uhHeight = g_uiMaxCUHeight >> uiDepth;
878  memset( m_puhWidth,          uhWidth,  iSizeInUchar );
879  memset( m_puhHeight,         uhHeight, iSizeInUchar );
880  memset( m_pbIPCMFlag,        0, iSizeInBool  );
881#if H_3D_IC
882  memset( m_pbICFlag,          0, iSizeInBool  );
883#endif
884#if H_3D_DIM
885  for( Int i = 0; i < DIM_NUM_TYPE; i++ )
886  {
887    memset( m_dimDeltaDC[i][0], 0, sizeof(Pel ) * m_uiNumPartition );
888    memset( m_dimDeltaDC[i][1], 0, sizeof(Pel ) * m_uiNumPartition );
889  }
890#if H_3D_DIM_DMM
891  for( Int i = 0; i < DMM_NUM_TYPE; i++ )
892  {
893    memset( m_dmmWedgeTabIdx[i], 0, sizeof(UInt) * m_uiNumPartition );
894  }
895  memset( m_dmm2DeltaEnd   , 0, sizeof(Int ) * m_uiNumPartition );
896  memset( m_dmm3IntraTabIdx, 0, sizeof(UInt) * m_uiNumPartition );
897#endif
898#if H_3D_DIM_RBC
899  memset( m_pucEdgeCode    , 0, iSizeInUchar * RBC_MAX_EDGE_NUM_PER_4x4 );
900  memset( m_pucEdgeNumber  , 0, iSizeInUchar );
901  memset( m_pucEdgeStartPos, 0, iSizeInUchar );
902  memset( m_pbEdgeLeftFirst, 0, iSizeInBool );
903  memset( m_pbEdgePartition, 0, iSizeInBool * 16 );
904#endif
905#if H_3D_DIM_SDC
906  memset( m_pbSDCFlag,            0, sizeof(Bool) * m_uiNumPartition  );
907  memset( m_apSegmentDCOffset[0], 0, sizeof(Pel) * m_uiNumPartition   );
908  memset( m_apSegmentDCOffset[1], 0, sizeof(Pel) * m_uiNumPartition   );
909#endif
910#endif
911
912  for (UInt ui = 0; ui < m_uiNumPartition; ui++)
913  {
914    m_skipFlag[ui]   = false;
915    m_pePartSize[ui] = SIZE_NONE;
916    m_pePredMode[ui] = MODE_NONE;
917    m_CUTransquantBypass[ui] = false;
918    m_apiMVPIdx[0][ui] = -1;
919    m_apiMVPIdx[1][ui] = -1;
920    m_apiMVPNum[0][ui] = -1;
921    m_apiMVPNum[1][ui] = -1;
922    if(m_pcPic->getPicSym()->getInverseCUOrderMap(getAddr())*m_pcPic->getNumPartInCU()+m_uiAbsIdxInLCU+ui<getSlice()->getSliceSegmentCurStartCUAddr())
923    {
924      m_apiMVPIdx[0][ui] = pcCU->m_apiMVPIdx[0][uiPartOffset+ui];
925      m_apiMVPIdx[1][ui] = pcCU->m_apiMVPIdx[1][uiPartOffset+ui];;
926      m_apiMVPNum[0][ui] = pcCU->m_apiMVPNum[0][uiPartOffset+ui];;
927      m_apiMVPNum[1][ui] = pcCU->m_apiMVPNum[1][uiPartOffset+ui];;
928      m_puhDepth  [ui] = pcCU->getDepth(uiPartOffset+ui);
929      m_puhWidth  [ui] = pcCU->getWidth(uiPartOffset+ui);
930      m_puhHeight  [ui] = pcCU->getHeight(uiPartOffset+ui);
931      m_puhTrIdx  [ui] = pcCU->getTransformIdx(uiPartOffset+ui);
932      m_puhTransformSkip[0][ui] = pcCU->getTransformSkip(uiPartOffset+ui,TEXT_LUMA);
933      m_puhTransformSkip[1][ui] = pcCU->getTransformSkip(uiPartOffset+ui,TEXT_CHROMA_U);
934      m_puhTransformSkip[2][ui] = pcCU->getTransformSkip(uiPartOffset+ui,TEXT_CHROMA_V);
935      m_skipFlag[ui]   = pcCU->getSkipFlag(uiPartOffset+ui);
936      m_pePartSize[ui] = pcCU->getPartitionSize(uiPartOffset+ui);
937      m_pePredMode[ui] = pcCU->getPredictionMode(uiPartOffset+ui);
938      m_CUTransquantBypass[ui] = pcCU->getCUTransquantBypass(uiPartOffset+ui);
939      m_pbIPCMFlag[ui]=pcCU->m_pbIPCMFlag[uiPartOffset+ui];
940      m_phQP[ui] = pcCU->m_phQP[uiPartOffset+ui];
941      m_pbMergeFlag[ui]=pcCU->m_pbMergeFlag[uiPartOffset+ui];
942      m_puhMergeIndex[ui]=pcCU->m_puhMergeIndex[uiPartOffset+ui];
943#if H_3D_VSP
944      m_piVSPFlag[ui]=pcCU->m_piVSPFlag[uiPartOffset+ui];
945#if MTK_VSP_FIX_E0172
946      m_piVSPDir[ui]=pcCU->m_piVSPDir[uiPartOffset+ui];
947#endif
948#endif
949      m_puhLumaIntraDir[ui]=pcCU->m_puhLumaIntraDir[uiPartOffset+ui];
950      m_puhChromaIntraDir[ui]=pcCU->m_puhChromaIntraDir[uiPartOffset+ui];
951      m_puhInterDir[ui]=pcCU->m_puhInterDir[uiPartOffset+ui];
952      m_puhCbf[0][ui]=pcCU->m_puhCbf[0][uiPartOffset+ui];
953      m_puhCbf[1][ui]=pcCU->m_puhCbf[1][uiPartOffset+ui];
954      m_puhCbf[2][ui]=pcCU->m_puhCbf[2][uiPartOffset+ui];
955
956#if H_3D_ARP
957      m_puhARPW           [ui] = pcCU->getARPW( uiPartOffset+ui );
958#endif
959#if H_3D_IC
960      m_pbICFlag          [ui] = pcCU->m_pbICFlag[uiPartOffset+ui];
961#endif
962#if H_3D_DIM
963      for( Int i = 0; i < DIM_NUM_TYPE; i++ )
964      {
965        m_dimDeltaDC[i][0] [ui] = pcCU->m_dimDeltaDC[i][0] [uiPartOffset+ui];
966        m_dimDeltaDC[i][1] [ui] = pcCU->m_dimDeltaDC[i][1] [uiPartOffset+ui];
967      }
968#if H_3D_DIM_DMM
969      for( Int i = 0; i < DMM_NUM_TYPE; i++ )
970      {
971        m_dmmWedgeTabIdx[i] [ui] = pcCU->m_dmmWedgeTabIdx[i] [uiPartOffset+ui];
972      }
973      m_dmm2DeltaEnd    [ui] = pcCU->m_dmm2DeltaEnd   [uiPartOffset+ui];
974      m_dmm3IntraTabIdx [ui] = pcCU->m_dmm3IntraTabIdx[uiPartOffset+ui];
975#endif
976#if H_3D_DIM_SDC
977      m_pbSDCFlag           [ui] = pcCU->m_pbSDCFlag            [ uiPartOffset + ui ];
978      m_apSegmentDCOffset[0][ui] = pcCU->m_apSegmentDCOffset[0] [ uiPartOffset + ui ];
979      m_apSegmentDCOffset[1][ui] = pcCU->m_apSegmentDCOffset[1] [ uiPartOffset + ui ];
980#endif
981#endif
982    }
983  }
984  UInt uiTmp = uhWidth*uhHeight;
985  memset( m_pcTrCoeffY , 0, sizeof(TCoeff)*uiTmp );
986#if ADAPTIVE_QP_SELECTION 
987  memset( m_pcArlCoeffY , 0, sizeof(Int)*uiTmp );
988#endif
989  memset( m_pcIPCMSampleY , 0, sizeof( Pel ) * uiTmp );
990  uiTmp >>= 2;
991  memset( m_pcTrCoeffCb, 0, sizeof(TCoeff)*uiTmp );
992  memset( m_pcTrCoeffCr, 0, sizeof(TCoeff)*uiTmp );
993#if ADAPTIVE_QP_SELECTION
994  memset( m_pcArlCoeffCb, 0, sizeof(Int)*uiTmp );
995  memset( m_pcArlCoeffCr, 0, sizeof(Int)*uiTmp );
996#endif
997  memset( m_pcIPCMSampleCb , 0, sizeof( Pel ) * uiTmp );
998  memset( m_pcIPCMSampleCr , 0, sizeof( Pel ) * uiTmp );
999  m_acCUMvField[0].clearMvField();
1000  m_acCUMvField[1].clearMvField();
1001
1002  if(m_pcPic->getPicSym()->getInverseCUOrderMap(getAddr())*m_pcPic->getNumPartInCU()+m_uiAbsIdxInLCU<getSlice()->getSliceSegmentCurStartCUAddr())
1003  {
1004    // Part of this CU contains data from an older slice. Now copy in that data.
1005    UInt uiMaxCuWidth=pcCU->getSlice()->getSPS()->getMaxCUWidth();
1006    UInt uiMaxCuHeight=pcCU->getSlice()->getSPS()->getMaxCUHeight();
1007    TComDataCU * bigCU = getPic()->getCU(getAddr());
1008    Int minui = uiPartOffset;
1009    minui = -minui;
1010    pcCU->m_acCUMvField[0].copyTo(&m_acCUMvField[0],minui,uiPartOffset,m_uiNumPartition);
1011    pcCU->m_acCUMvField[1].copyTo(&m_acCUMvField[1],minui,uiPartOffset,m_uiNumPartition);
1012    UInt uiCoffOffset = uiMaxCuWidth*uiMaxCuHeight*m_uiAbsIdxInLCU/pcCU->getPic()->getNumPartInCU();
1013    uiTmp = uhWidth*uhHeight;
1014    for(Int i=0; i<uiTmp; i++)
1015    {
1016      m_pcTrCoeffY[i]=bigCU->m_pcTrCoeffY[uiCoffOffset+i];
1017#if ADAPTIVE_QP_SELECTION
1018      m_pcArlCoeffY[i]=bigCU->m_pcArlCoeffY[uiCoffOffset+i];
1019#endif
1020      m_pcIPCMSampleY[i]=bigCU->m_pcIPCMSampleY[uiCoffOffset+i];
1021    }
1022    uiTmp>>=2;
1023    uiCoffOffset>>=2;
1024    for(Int i=0; i<uiTmp; i++)
1025    {
1026      m_pcTrCoeffCr[i]=bigCU->m_pcTrCoeffCr[uiCoffOffset+i];
1027      m_pcTrCoeffCb[i]=bigCU->m_pcTrCoeffCb[uiCoffOffset+i];
1028#if ADAPTIVE_QP_SELECTION
1029      m_pcArlCoeffCr[i]=bigCU->m_pcArlCoeffCr[uiCoffOffset+i];
1030      m_pcArlCoeffCb[i]=bigCU->m_pcArlCoeffCb[uiCoffOffset+i];
1031#endif
1032      m_pcIPCMSampleCb[i]=bigCU->m_pcIPCMSampleCb[uiCoffOffset+i];
1033      m_pcIPCMSampleCr[i]=bigCU->m_pcIPCMSampleCr[uiCoffOffset+i];
1034    }
1035  }
1036
1037  m_pcCULeft        = pcCU->getCULeft();
1038  m_pcCUAbove       = pcCU->getCUAbove();
1039  m_pcCUAboveLeft   = pcCU->getCUAboveLeft();
1040  m_pcCUAboveRight  = pcCU->getCUAboveRight();
1041
1042  m_apcCUColocated[0] = pcCU->getCUColocated(REF_PIC_LIST_0);
1043  m_apcCUColocated[1] = pcCU->getCUColocated(REF_PIC_LIST_1);
1044  memcpy(m_sliceStartCU,pcCU->m_sliceStartCU+uiPartOffset,sizeof(UInt)*m_uiNumPartition);
1045  memcpy(m_sliceSegmentStartCU,pcCU->m_sliceSegmentStartCU+uiPartOffset,sizeof(UInt)*m_uiNumPartition);
1046}
1047
1048Void TComDataCU::setOutsideCUPart( UInt uiAbsPartIdx, UInt uiDepth )
1049{
1050  UInt uiNumPartition = m_uiNumPartition >> (uiDepth << 1);
1051  UInt uiSizeInUchar = sizeof( UChar  ) * uiNumPartition;
1052
1053  UChar uhWidth  = g_uiMaxCUWidth  >> uiDepth;
1054  UChar uhHeight = g_uiMaxCUHeight >> uiDepth;
1055  memset( m_puhDepth    + uiAbsPartIdx,     uiDepth,  uiSizeInUchar );
1056  memset( m_puhWidth    + uiAbsPartIdx,     uhWidth,  uiSizeInUchar );
1057  memset( m_puhHeight   + uiAbsPartIdx,     uhHeight, uiSizeInUchar );
1058}
1059
1060// --------------------------------------------------------------------------------------------------------------------
1061// Copy
1062// --------------------------------------------------------------------------------------------------------------------
1063
1064Void TComDataCU::copySubCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1065{
1066  UInt uiPart = uiAbsPartIdx;
1067 
1068  m_pcPic              = pcCU->getPic();
1069  m_pcSlice            = pcCU->getSlice();
1070  m_uiCUAddr           = pcCU->getAddr();
1071  m_uiAbsIdxInLCU      = uiAbsPartIdx;
1072 
1073  m_uiCUPelX           = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
1074  m_uiCUPelY           = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
1075 
1076  m_skipFlag=pcCU->getSkipFlag()          + uiPart;
1077
1078  m_phQP=pcCU->getQP()                    + uiPart;
1079  m_pePartSize = pcCU->getPartitionSize() + uiPart;
1080  m_pePredMode=pcCU->getPredictionMode()  + uiPart;
1081  m_CUTransquantBypass  = pcCU->getCUTransquantBypass()+uiPart;
1082 
1083#if H_3D_NBDV
1084  m_pDvInfo             = pcCU->getDvInfo()           + uiPart;
1085#endif
1086  m_pbMergeFlag         = pcCU->getMergeFlag()        + uiPart;
1087  m_puhMergeIndex       = pcCU->getMergeIndex()       + uiPart;
1088#if H_3D_VSP
1089  m_piVSPFlag           = pcCU->getVSPFlag()          + uiPart;
1090#if MTK_VSP_FIX_E0172
1091  m_piVSPDir            = pcCU->getVSPDir  ()         + uiPart;
1092#endif
1093#endif
1094
1095#if H_3D_ARP
1096  m_puhARPW             = pcCU->getARPW()             + uiPart;
1097#endif
1098#if H_3D_IC
1099  m_pbICFlag            = pcCU->getICFlag()           + uiPart;
1100#endif
1101
1102  m_puhLumaIntraDir     = pcCU->getLumaIntraDir()     + uiPart;
1103  m_puhChromaIntraDir   = pcCU->getChromaIntraDir()   + uiPart;
1104  m_puhInterDir         = pcCU->getInterDir()         + uiPart;
1105  m_puhTrIdx            = pcCU->getTransformIdx()     + uiPart;
1106  m_puhTransformSkip[0] = pcCU->getTransformSkip(TEXT_LUMA)     + uiPart;
1107  m_puhTransformSkip[1] = pcCU->getTransformSkip(TEXT_CHROMA_U) + uiPart;
1108  m_puhTransformSkip[2] = pcCU->getTransformSkip(TEXT_CHROMA_V) + uiPart;
1109
1110  m_puhCbf[0]= pcCU->getCbf(TEXT_LUMA)            + uiPart;
1111  m_puhCbf[1]= pcCU->getCbf(TEXT_CHROMA_U)        + uiPart;
1112  m_puhCbf[2]= pcCU->getCbf(TEXT_CHROMA_V)        + uiPart;
1113#if H_3D_DIM
1114  for( Int i = 0; i < DIM_NUM_TYPE; i++ )
1115  {
1116    m_dimDeltaDC[i][0] = pcCU->getDimDeltaDC( i, 0 ) + uiPart;
1117    m_dimDeltaDC[i][1] = pcCU->getDimDeltaDC( i, 1 ) + uiPart;
1118  }
1119#if H_3D_DIM_DMM
1120  for( Int i = 0; i < DMM_NUM_TYPE; i++ )
1121  {
1122    m_dmmWedgeTabIdx[i] = pcCU->getDmmWedgeTabIdx( i ) + uiPart;
1123  }
1124  m_dmm2DeltaEnd    = pcCU->getDmm2DeltaEnd()    + uiPart;
1125  m_dmm3IntraTabIdx = pcCU->getDmm3IntraTabIdx() + uiPart;
1126#endif
1127#if H_3D_DIM_RBC
1128  m_pucEdgeCode     = pcCU->getEdgeCode( uiPart );
1129  m_pucEdgeNumber   = pcCU->getEdgeNumber()      + uiPart;
1130  m_pucEdgeStartPos = pcCU->getEdgeStartPos()    + uiPart;
1131  m_pbEdgeLeftFirst = pcCU->getEdgeLeftFirst()   + uiPart;
1132  m_pbEdgePartition = pcCU->getEdgePartition( uiPart );
1133#endif
1134#if H_3D_DIM_SDC
1135  m_pbSDCFlag               = pcCU->getSDCFlag()              + uiPart;
1136  m_apSegmentDCOffset[0]    = pcCU->getSDCSegmentDCOffset(0)  + uiPart;
1137  m_apSegmentDCOffset[1]    = pcCU->getSDCSegmentDCOffset(1)  + uiPart;
1138#endif
1139#endif 
1140  m_puhDepth=pcCU->getDepth()                     + uiPart;
1141  m_puhWidth=pcCU->getWidth()                     + uiPart;
1142  m_puhHeight=pcCU->getHeight()                   + uiPart;
1143 
1144  m_apiMVPIdx[0]=pcCU->getMVPIdx(REF_PIC_LIST_0)  + uiPart;
1145  m_apiMVPIdx[1]=pcCU->getMVPIdx(REF_PIC_LIST_1)  + uiPart;
1146  m_apiMVPNum[0]=pcCU->getMVPNum(REF_PIC_LIST_0)  + uiPart;
1147  m_apiMVPNum[1]=pcCU->getMVPNum(REF_PIC_LIST_1)  + uiPart;
1148 
1149  m_pbIPCMFlag         = pcCU->getIPCMFlag()        + uiPart;
1150
1151  m_pcCUAboveLeft      = pcCU->getCUAboveLeft();
1152  m_pcCUAboveRight     = pcCU->getCUAboveRight();
1153  m_pcCUAbove          = pcCU->getCUAbove();
1154  m_pcCULeft           = pcCU->getCULeft();
1155 
1156  m_apcCUColocated[0] = pcCU->getCUColocated(REF_PIC_LIST_0);
1157  m_apcCUColocated[1] = pcCU->getCUColocated(REF_PIC_LIST_1);
1158 
1159  UInt uiMaxCuWidth=pcCU->getSlice()->getSPS()->getMaxCUWidth();
1160  UInt uiMaxCuHeight=pcCU->getSlice()->getSPS()->getMaxCUHeight();
1161 
1162  UInt uiCoffOffset = uiMaxCuWidth*uiMaxCuHeight*uiAbsPartIdx/pcCU->getPic()->getNumPartInCU();
1163 
1164  m_pcTrCoeffY = pcCU->getCoeffY() + uiCoffOffset;
1165#if ADAPTIVE_QP_SELECTION
1166  m_pcArlCoeffY= pcCU->getArlCoeffY() + uiCoffOffset; 
1167#endif
1168  m_pcIPCMSampleY = pcCU->getPCMSampleY() + uiCoffOffset;
1169
1170  uiCoffOffset >>=2;
1171  m_pcTrCoeffCb=pcCU->getCoeffCb() + uiCoffOffset;
1172  m_pcTrCoeffCr=pcCU->getCoeffCr() + uiCoffOffset;
1173#if ADAPTIVE_QP_SELECTION 
1174  m_pcArlCoeffCb=pcCU->getArlCoeffCb() + uiCoffOffset;
1175  m_pcArlCoeffCr=pcCU->getArlCoeffCr() + uiCoffOffset;
1176#endif
1177  m_pcIPCMSampleCb = pcCU->getPCMSampleCb() + uiCoffOffset;
1178  m_pcIPCMSampleCr = pcCU->getPCMSampleCr() + uiCoffOffset;
1179
1180  m_acCUMvField[0].linkToWithOffset( pcCU->getCUMvField(REF_PIC_LIST_0), uiPart );
1181  m_acCUMvField[1].linkToWithOffset( pcCU->getCUMvField(REF_PIC_LIST_1), uiPart );
1182  memcpy(m_sliceStartCU,pcCU->m_sliceStartCU+uiPart,sizeof(UInt)*m_uiNumPartition);
1183  memcpy(m_sliceSegmentStartCU,pcCU->m_sliceSegmentStartCU+uiPart,sizeof(UInt)*m_uiNumPartition);
1184}
1185#if H_3D_NBDV
1186Void TComDataCU::copyDVInfoFrom (TComDataCU* pcCU, UInt uiAbsPartIdx)
1187{
1188  m_pDvInfo            = pcCU->getDvInfo()                + uiAbsPartIdx;
1189}
1190#endif
1191// Copy inter prediction info from the biggest CU
1192Void TComDataCU::copyInterPredInfoFrom    ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefPicList
1193#if H_3D_NBDV
1194  , Bool bNBDV
1195#endif
1196  )
1197{
1198  m_pcPic              = pcCU->getPic();
1199  m_pcSlice            = pcCU->getSlice();
1200  m_uiCUAddr           = pcCU->getAddr();
1201  m_uiAbsIdxInLCU      = uiAbsPartIdx;
1202 
1203  Int iRastPartIdx     = g_auiZscanToRaster[uiAbsPartIdx];
1204  m_uiCUPelX           = pcCU->getCUPelX() + m_pcPic->getMinCUWidth ()*( iRastPartIdx % m_pcPic->getNumPartInWidth() );
1205  m_uiCUPelY           = pcCU->getCUPelY() + m_pcPic->getMinCUHeight()*( iRastPartIdx / m_pcPic->getNumPartInWidth() );
1206 
1207  m_pcCUAboveLeft      = pcCU->getCUAboveLeft();
1208  m_pcCUAboveRight     = pcCU->getCUAboveRight();
1209  m_pcCUAbove          = pcCU->getCUAbove();
1210  m_pcCULeft           = pcCU->getCULeft();
1211 
1212  m_apcCUColocated[0]  = pcCU->getCUColocated(REF_PIC_LIST_0);
1213  m_apcCUColocated[1]  = pcCU->getCUColocated(REF_PIC_LIST_1);
1214 
1215  m_skipFlag           = pcCU->getSkipFlag ()             + uiAbsPartIdx;
1216
1217  m_pePartSize         = pcCU->getPartitionSize ()        + uiAbsPartIdx;
1218#if H_3D_NBDV
1219  if(bNBDV == true)
1220  {
1221    m_puhWidth           = pcCU->getWidth ()                + uiAbsPartIdx;
1222    m_puhHeight          = pcCU->getHeight()                + uiAbsPartIdx;
1223    m_puhDepth           = pcCU->getDepth ()                + uiAbsPartIdx;
1224  }
1225  else
1226  {
1227#endif
1228  m_pePredMode         = pcCU->getPredictionMode()        + uiAbsPartIdx;
1229  m_CUTransquantBypass = pcCU->getCUTransquantBypass()    + uiAbsPartIdx;
1230  m_puhInterDir        = pcCU->getInterDir      ()        + uiAbsPartIdx;
1231 
1232  m_puhDepth           = pcCU->getDepth ()                + uiAbsPartIdx;
1233  m_puhWidth           = pcCU->getWidth ()                + uiAbsPartIdx;
1234  m_puhHeight          = pcCU->getHeight()                + uiAbsPartIdx;
1235 
1236  m_pbMergeFlag        = pcCU->getMergeFlag()             + uiAbsPartIdx;
1237  m_puhMergeIndex      = pcCU->getMergeIndex()            + uiAbsPartIdx;
1238#if H_3D_VSP
1239  m_piVSPFlag          = pcCU->getVSPFlag()               + uiAbsPartIdx;
1240#if MTK_VSP_FIX_E0172
1241  m_piVSPDir           = pcCU->getVSPDir  ()              + uiAbsPartIdx;
1242#endif
1243#endif
1244
1245  m_apiMVPIdx[eRefPicList] = pcCU->getMVPIdx(eRefPicList) + uiAbsPartIdx;
1246  m_apiMVPNum[eRefPicList] = pcCU->getMVPNum(eRefPicList) + uiAbsPartIdx;
1247 
1248#if H_3D_ARP
1249  m_puhARPW            = pcCU->getARPW()                  + uiAbsPartIdx;
1250#endif
1251
1252  m_acCUMvField[ eRefPicList ].linkToWithOffset( pcCU->getCUMvField(eRefPicList), uiAbsPartIdx );
1253
1254  memcpy(m_sliceStartCU,pcCU->m_sliceStartCU+uiAbsPartIdx,sizeof(UInt)*m_uiNumPartition);
1255  memcpy(m_sliceSegmentStartCU,pcCU->m_sliceSegmentStartCU+uiAbsPartIdx,sizeof(UInt)*m_uiNumPartition);
1256#if H_3D_NBDV
1257  }
1258#endif
1259#if H_3D_IC
1260  m_pbICFlag           = pcCU->getICFlag()                + uiAbsPartIdx;
1261#endif
1262}
1263
1264// Copy small CU to bigger CU.
1265// One of quarter parts overwritten by predicted sub part.
1266Void TComDataCU::copyPartFrom( TComDataCU* pcCU, UInt uiPartUnitIdx, UInt uiDepth )
1267{
1268  assert( uiPartUnitIdx<4 );
1269 
1270  m_dTotalCost         += pcCU->getTotalCost();
1271  m_uiTotalDistortion  += pcCU->getTotalDistortion();
1272  m_uiTotalBits        += pcCU->getTotalBits();
1273 
1274  UInt uiOffset         = pcCU->getTotalNumPart()*uiPartUnitIdx;
1275 
1276  UInt uiNumPartition = pcCU->getTotalNumPart();
1277  Int iSizeInUchar  = sizeof( UChar ) * uiNumPartition;
1278  Int iSizeInBool   = sizeof( Bool  ) * uiNumPartition;
1279 
1280  Int sizeInChar  = sizeof( Char ) * uiNumPartition;
1281  memcpy( m_skipFlag   + uiOffset, pcCU->getSkipFlag(),       sizeof( *m_skipFlag )   * uiNumPartition );
1282  memcpy( m_phQP       + uiOffset, pcCU->getQP(),             sizeInChar                        );
1283  memcpy( m_pePartSize + uiOffset, pcCU->getPartitionSize(),  sizeof( *m_pePartSize ) * uiNumPartition );
1284  memcpy( m_pePredMode + uiOffset, pcCU->getPredictionMode(), sizeof( *m_pePredMode ) * uiNumPartition );
1285  memcpy( m_CUTransquantBypass + uiOffset, pcCU->getCUTransquantBypass(), sizeof( *m_CUTransquantBypass ) * uiNumPartition );
1286  memcpy( m_pbMergeFlag         + uiOffset, pcCU->getMergeFlag(),         iSizeInBool  );
1287  memcpy( m_puhMergeIndex       + uiOffset, pcCU->getMergeIndex(),        iSizeInUchar );
1288#if H_3D_VSP
1289  memcpy( m_piVSPFlag           + uiOffset, pcCU->getVSPFlag(),           sizeof( Char ) * uiNumPartition );
1290#if MTK_VSP_FIX_E0172
1291  memcpy( m_piVSPDir            + uiOffset, pcCU->getVSPDir  (),          sizeInChar );
1292#endif
1293#endif
1294  memcpy( m_puhLumaIntraDir     + uiOffset, pcCU->getLumaIntraDir(),      iSizeInUchar );
1295  memcpy( m_puhChromaIntraDir   + uiOffset, pcCU->getChromaIntraDir(),    iSizeInUchar );
1296  memcpy( m_puhInterDir         + uiOffset, pcCU->getInterDir(),          iSizeInUchar );
1297  memcpy( m_puhTrIdx            + uiOffset, pcCU->getTransformIdx(),      iSizeInUchar );
1298  memcpy( m_puhTransformSkip[0] + uiOffset, pcCU->getTransformSkip(TEXT_LUMA),     iSizeInUchar );
1299  memcpy( m_puhTransformSkip[1] + uiOffset, pcCU->getTransformSkip(TEXT_CHROMA_U), iSizeInUchar );
1300  memcpy( m_puhTransformSkip[2] + uiOffset, pcCU->getTransformSkip(TEXT_CHROMA_V), iSizeInUchar );
1301
1302  memcpy( m_puhCbf[0] + uiOffset, pcCU->getCbf(TEXT_LUMA)    , iSizeInUchar );
1303  memcpy( m_puhCbf[1] + uiOffset, pcCU->getCbf(TEXT_CHROMA_U), iSizeInUchar );
1304  memcpy( m_puhCbf[2] + uiOffset, pcCU->getCbf(TEXT_CHROMA_V), iSizeInUchar );
1305 
1306#if H_3D_DIM
1307  for( Int i = 0; i < DIM_NUM_TYPE; i++ )
1308  {
1309    memcpy( m_dimDeltaDC[i][0] + uiOffset, pcCU->getDimDeltaDC( i, 0 ), sizeof(Pel ) * uiNumPartition );
1310    memcpy( m_dimDeltaDC[i][1] + uiOffset, pcCU->getDimDeltaDC( i, 1 ), sizeof(Pel ) * uiNumPartition );
1311  }
1312#if H_3D_DIM_DMM
1313  for( Int i = 0; i < DMM_NUM_TYPE; i++ )
1314  {
1315    memcpy( m_dmmWedgeTabIdx[i] + uiOffset, pcCU->getDmmWedgeTabIdx( i ), sizeof(UInt) * uiNumPartition );
1316  }
1317  memcpy( m_dmm2DeltaEnd    + uiOffset, pcCU->getDmm2DeltaEnd()   , sizeof(Int ) * uiNumPartition );
1318  memcpy( m_dmm3IntraTabIdx + uiOffset, pcCU->getDmm3IntraTabIdx(), sizeof(UInt) * uiNumPartition );
1319#endif
1320#if H_3D_DIM_RBC
1321  memcpy( getEdgeCode( uiOffset ),       pcCU->getEdgeCode(0),      iSizeInUchar * RBC_MAX_EDGE_NUM_PER_4x4 );
1322  memcpy( getEdgeNumber()    + uiOffset, pcCU->getEdgeNumber(),     iSizeInUchar );
1323  memcpy( getEdgeStartPos()  + uiOffset, pcCU->getEdgeStartPos(),   iSizeInUchar );
1324  memcpy( getEdgeLeftFirst() + uiOffset, pcCU->getEdgeLeftFirst(),  iSizeInBool );
1325  memcpy( getEdgePartition( uiOffset ),  pcCU->getEdgePartition(0), iSizeInBool * 16 );
1326#endif
1327#if H_3D_DIM_SDC
1328  memcpy( m_pbSDCFlag             + uiOffset, pcCU->getSDCFlag(),             iSizeInBool  );
1329  memcpy( m_apSegmentDCOffset[0]  + uiOffset, pcCU->getSDCSegmentDCOffset(0), sizeof( Pel ) * uiNumPartition);
1330  memcpy( m_apSegmentDCOffset[1]  + uiOffset, pcCU->getSDCSegmentDCOffset(1), sizeof( Pel ) * uiNumPartition);
1331#endif
1332#endif
1333
1334  memcpy( m_puhDepth  + uiOffset, pcCU->getDepth(),  iSizeInUchar );
1335  memcpy( m_puhWidth  + uiOffset, pcCU->getWidth(),  iSizeInUchar );
1336  memcpy( m_puhHeight + uiOffset, pcCU->getHeight(), iSizeInUchar );
1337 
1338  memcpy( m_apiMVPIdx[0] + uiOffset, pcCU->getMVPIdx(REF_PIC_LIST_0), iSizeInUchar );
1339  memcpy( m_apiMVPIdx[1] + uiOffset, pcCU->getMVPIdx(REF_PIC_LIST_1), iSizeInUchar );
1340  memcpy( m_apiMVPNum[0] + uiOffset, pcCU->getMVPNum(REF_PIC_LIST_0), iSizeInUchar );
1341  memcpy( m_apiMVPNum[1] + uiOffset, pcCU->getMVPNum(REF_PIC_LIST_1), iSizeInUchar );
1342 
1343  memcpy( m_pbIPCMFlag + uiOffset, pcCU->getIPCMFlag(), iSizeInBool );
1344
1345  m_pcCUAboveLeft      = pcCU->getCUAboveLeft();
1346  m_pcCUAboveRight     = pcCU->getCUAboveRight();
1347  m_pcCUAbove          = pcCU->getCUAbove();
1348  m_pcCULeft           = pcCU->getCULeft();
1349 
1350  m_apcCUColocated[0] = pcCU->getCUColocated(REF_PIC_LIST_0);
1351  m_apcCUColocated[1] = pcCU->getCUColocated(REF_PIC_LIST_1);
1352 
1353  m_acCUMvField[0].copyFrom( pcCU->getCUMvField( REF_PIC_LIST_0 ), pcCU->getTotalNumPart(), uiOffset );
1354  m_acCUMvField[1].copyFrom( pcCU->getCUMvField( REF_PIC_LIST_1 ), pcCU->getTotalNumPart(), uiOffset );
1355 
1356  UInt uiTmp  = g_uiMaxCUWidth*g_uiMaxCUHeight >> (uiDepth<<1);
1357  UInt uiTmp2 = uiPartUnitIdx*uiTmp;
1358  memcpy( m_pcTrCoeffY  + uiTmp2, pcCU->getCoeffY(),  sizeof(TCoeff)*uiTmp );
1359#if ADAPTIVE_QP_SELECTION
1360  memcpy( m_pcArlCoeffY  + uiTmp2, pcCU->getArlCoeffY(),  sizeof(Int)*uiTmp );
1361#endif
1362  memcpy( m_pcIPCMSampleY + uiTmp2 , pcCU->getPCMSampleY(), sizeof(Pel) * uiTmp );
1363
1364  uiTmp >>= 2; uiTmp2>>= 2;
1365  memcpy( m_pcTrCoeffCb + uiTmp2, pcCU->getCoeffCb(), sizeof(TCoeff)*uiTmp );
1366  memcpy( m_pcTrCoeffCr + uiTmp2, pcCU->getCoeffCr(), sizeof(TCoeff)*uiTmp );
1367#if ADAPTIVE_QP_SELECTION
1368  memcpy( m_pcArlCoeffCb + uiTmp2, pcCU->getArlCoeffCb(), sizeof(Int)*uiTmp );
1369  memcpy( m_pcArlCoeffCr + uiTmp2, pcCU->getArlCoeffCr(), sizeof(Int)*uiTmp );
1370#endif
1371  memcpy( m_pcIPCMSampleCb + uiTmp2 , pcCU->getPCMSampleCb(), sizeof(Pel) * uiTmp );
1372  memcpy( m_pcIPCMSampleCr + uiTmp2 , pcCU->getPCMSampleCr(), sizeof(Pel) * uiTmp );
1373  m_uiTotalBins += pcCU->getTotalBins();
1374  memcpy( m_sliceStartCU        + uiOffset, pcCU->m_sliceStartCU,        sizeof( UInt ) * uiNumPartition  );
1375  memcpy( m_sliceSegmentStartCU + uiOffset, pcCU->m_sliceSegmentStartCU, sizeof( UInt ) * uiNumPartition  );
1376#if H_3D_ARP
1377  memcpy( m_puhARPW             + uiOffset, pcCU->getARPW(),              iSizeInUchar );
1378#endif
1379#if H_3D_IC
1380  memcpy( m_pbICFlag            + uiOffset, pcCU->getICFlag(),            iSizeInBool );
1381#endif
1382}
1383
1384// Copy current predicted part to a CU in picture.
1385// It is used to predict for next part
1386Void TComDataCU::copyToPic( UChar uhDepth )
1387{
1388  TComDataCU*& rpcCU = m_pcPic->getCU( m_uiCUAddr );
1389 
1390  rpcCU->getTotalCost()       = m_dTotalCost;
1391  rpcCU->getTotalDistortion() = m_uiTotalDistortion;
1392  rpcCU->getTotalBits()       = m_uiTotalBits;
1393 
1394  Int iSizeInUchar  = sizeof( UChar ) * m_uiNumPartition;
1395  Int iSizeInBool   = sizeof( Bool  ) * m_uiNumPartition;
1396 
1397  Int sizeInChar  = sizeof( Char ) * m_uiNumPartition;
1398
1399  memcpy( rpcCU->getSkipFlag() + m_uiAbsIdxInLCU, m_skipFlag, sizeof( *m_skipFlag ) * m_uiNumPartition );
1400
1401  memcpy( rpcCU->getQP() + m_uiAbsIdxInLCU, m_phQP, sizeInChar  );
1402#if H_3D_NBDV
1403  memcpy( rpcCU->getDvInfo()         + m_uiAbsIdxInLCU, m_pDvInfo,    sizeof(* m_pDvInfo)     * m_uiNumPartition );
1404#endif
1405
1406  memcpy( rpcCU->getPartitionSize()  + m_uiAbsIdxInLCU, m_pePartSize, sizeof( *m_pePartSize ) * m_uiNumPartition );
1407  memcpy( rpcCU->getPredictionMode() + m_uiAbsIdxInLCU, m_pePredMode, sizeof( *m_pePredMode ) * m_uiNumPartition );
1408  memcpy( rpcCU->getCUTransquantBypass()+ m_uiAbsIdxInLCU, m_CUTransquantBypass, sizeof( *m_CUTransquantBypass ) * m_uiNumPartition );
1409  memcpy( rpcCU->getMergeFlag()         + m_uiAbsIdxInLCU, m_pbMergeFlag,         iSizeInBool  );
1410  memcpy( rpcCU->getMergeIndex()        + m_uiAbsIdxInLCU, m_puhMergeIndex,       iSizeInUchar );
1411#if H_3D_VSP
1412  memcpy( rpcCU->getVSPFlag()           + m_uiAbsIdxInLCU, m_piVSPFlag,           sizeof( Char ) * m_uiNumPartition );
1413#if MTK_VSP_FIX_E0172
1414  memcpy( rpcCU->getVSPDir  ()          + m_uiAbsIdxInLCU, m_piVSPDir  ,          sizeInChar );
1415#endif
1416#endif
1417  memcpy( rpcCU->getLumaIntraDir()      + m_uiAbsIdxInLCU, m_puhLumaIntraDir,     iSizeInUchar );
1418  memcpy( rpcCU->getChromaIntraDir()    + m_uiAbsIdxInLCU, m_puhChromaIntraDir,   iSizeInUchar );
1419  memcpy( rpcCU->getInterDir()          + m_uiAbsIdxInLCU, m_puhInterDir,         iSizeInUchar );
1420  memcpy( rpcCU->getTransformIdx()      + m_uiAbsIdxInLCU, m_puhTrIdx,            iSizeInUchar );
1421  memcpy( rpcCU->getTransformSkip(TEXT_LUMA)     + m_uiAbsIdxInLCU, m_puhTransformSkip[0], iSizeInUchar );
1422  memcpy( rpcCU->getTransformSkip(TEXT_CHROMA_U) + m_uiAbsIdxInLCU, m_puhTransformSkip[1], iSizeInUchar );
1423  memcpy( rpcCU->getTransformSkip(TEXT_CHROMA_V) + m_uiAbsIdxInLCU, m_puhTransformSkip[2], iSizeInUchar );
1424
1425  memcpy( rpcCU->getCbf(TEXT_LUMA)     + m_uiAbsIdxInLCU, m_puhCbf[0], iSizeInUchar );
1426  memcpy( rpcCU->getCbf(TEXT_CHROMA_U) + m_uiAbsIdxInLCU, m_puhCbf[1], iSizeInUchar );
1427  memcpy( rpcCU->getCbf(TEXT_CHROMA_V) + m_uiAbsIdxInLCU, m_puhCbf[2], iSizeInUchar );
1428 
1429#if H_3D_DIM
1430  for( Int i = 0; i < DIM_NUM_TYPE; i++ )
1431  {
1432    memcpy( rpcCU->getDimDeltaDC( i, 0 ) + m_uiAbsIdxInLCU, m_dimDeltaDC[i][0], sizeof(Pel ) * m_uiNumPartition );
1433    memcpy( rpcCU->getDimDeltaDC( i, 1 ) + m_uiAbsIdxInLCU, m_dimDeltaDC[i][1], sizeof(Pel ) * m_uiNumPartition );
1434  }
1435#if H_3D_DIM_DMM
1436  for( Int i = 0; i < DMM_NUM_TYPE; i++ )
1437  {
1438    memcpy( rpcCU->getDmmWedgeTabIdx( i ) + m_uiAbsIdxInLCU, m_dmmWedgeTabIdx[i], sizeof(UInt) * m_uiNumPartition );
1439  }
1440  memcpy( rpcCU->getDmm2DeltaEnd()    + m_uiAbsIdxInLCU, m_dmm2DeltaEnd   , sizeof(Int ) * m_uiNumPartition );
1441  memcpy( rpcCU->getDmm3IntraTabIdx() + m_uiAbsIdxInLCU, m_dmm3IntraTabIdx, sizeof(UInt) * m_uiNumPartition );
1442#endif
1443#if H_3D_DIM_RBC
1444  memcpy( rpcCU->getEdgeCode( m_uiAbsIdxInLCU ),         m_pucEdgeCode,     iSizeInUchar * RBC_MAX_EDGE_NUM_PER_4x4 );
1445  memcpy( rpcCU->getEdgeNumber()      + m_uiAbsIdxInLCU, m_pucEdgeNumber,   iSizeInUchar );
1446  memcpy( rpcCU->getEdgeStartPos()    + m_uiAbsIdxInLCU, m_pucEdgeStartPos, iSizeInUchar );
1447  memcpy( rpcCU->getEdgeLeftFirst()   + m_uiAbsIdxInLCU, m_pbEdgeLeftFirst, iSizeInBool );
1448  memcpy( rpcCU->getEdgePartition( m_uiAbsIdxInLCU ),    m_pbEdgePartition, iSizeInBool * 16 );
1449#endif
1450#if H_3D_DIM_SDC
1451  memcpy( rpcCU->getSDCFlag()             + m_uiAbsIdxInLCU, m_pbSDCFlag,      iSizeInBool  );
1452  memcpy( rpcCU->getSDCSegmentDCOffset(0) + m_uiAbsIdxInLCU, m_apSegmentDCOffset[0], sizeof( Pel ) * m_uiNumPartition);
1453  memcpy( rpcCU->getSDCSegmentDCOffset(1) + m_uiAbsIdxInLCU, m_apSegmentDCOffset[1], sizeof( Pel ) * m_uiNumPartition);
1454#endif
1455#endif
1456  memcpy( rpcCU->getDepth()  + m_uiAbsIdxInLCU, m_puhDepth,  iSizeInUchar );
1457  memcpy( rpcCU->getWidth()  + m_uiAbsIdxInLCU, m_puhWidth,  iSizeInUchar );
1458  memcpy( rpcCU->getHeight() + m_uiAbsIdxInLCU, m_puhHeight, iSizeInUchar );
1459 
1460  memcpy( rpcCU->getMVPIdx(REF_PIC_LIST_0) + m_uiAbsIdxInLCU, m_apiMVPIdx[0], iSizeInUchar );
1461  memcpy( rpcCU->getMVPIdx(REF_PIC_LIST_1) + m_uiAbsIdxInLCU, m_apiMVPIdx[1], iSizeInUchar );
1462  memcpy( rpcCU->getMVPNum(REF_PIC_LIST_0) + m_uiAbsIdxInLCU, m_apiMVPNum[0], iSizeInUchar );
1463  memcpy( rpcCU->getMVPNum(REF_PIC_LIST_1) + m_uiAbsIdxInLCU, m_apiMVPNum[1], iSizeInUchar );
1464 
1465  m_acCUMvField[0].copyTo( rpcCU->getCUMvField( REF_PIC_LIST_0 ), m_uiAbsIdxInLCU );
1466  m_acCUMvField[1].copyTo( rpcCU->getCUMvField( REF_PIC_LIST_1 ), m_uiAbsIdxInLCU );
1467 
1468  memcpy( rpcCU->getIPCMFlag() + m_uiAbsIdxInLCU, m_pbIPCMFlag,         iSizeInBool  );
1469
1470  UInt uiTmp  = (g_uiMaxCUWidth*g_uiMaxCUHeight)>>(uhDepth<<1);
1471  UInt uiTmp2 = m_uiAbsIdxInLCU*m_pcPic->getMinCUWidth()*m_pcPic->getMinCUHeight();
1472  memcpy( rpcCU->getCoeffY()  + uiTmp2, m_pcTrCoeffY,  sizeof(TCoeff)*uiTmp  );
1473#if ADAPTIVE_QP_SELECTION 
1474  memcpy( rpcCU->getArlCoeffY()  + uiTmp2, m_pcArlCoeffY,  sizeof(Int)*uiTmp  );
1475#endif
1476  memcpy( rpcCU->getPCMSampleY() + uiTmp2 , m_pcIPCMSampleY, sizeof(Pel)*uiTmp );
1477
1478  uiTmp >>= 2; uiTmp2 >>= 2;
1479  memcpy( rpcCU->getCoeffCb() + uiTmp2, m_pcTrCoeffCb, sizeof(TCoeff)*uiTmp  );
1480  memcpy( rpcCU->getCoeffCr() + uiTmp2, m_pcTrCoeffCr, sizeof(TCoeff)*uiTmp  );
1481#if ADAPTIVE_QP_SELECTION
1482  memcpy( rpcCU->getArlCoeffCb() + uiTmp2, m_pcArlCoeffCb, sizeof(Int)*uiTmp  );
1483  memcpy( rpcCU->getArlCoeffCr() + uiTmp2, m_pcArlCoeffCr, sizeof(Int)*uiTmp  );
1484#endif
1485  memcpy( rpcCU->getPCMSampleCb() + uiTmp2 , m_pcIPCMSampleCb, sizeof( Pel ) * uiTmp );
1486  memcpy( rpcCU->getPCMSampleCr() + uiTmp2 , m_pcIPCMSampleCr, sizeof( Pel ) * uiTmp );
1487  rpcCU->getTotalBins() = m_uiTotalBins;
1488  memcpy( rpcCU->m_sliceStartCU        + m_uiAbsIdxInLCU, m_sliceStartCU,        sizeof( UInt ) * m_uiNumPartition  );
1489  memcpy( rpcCU->m_sliceSegmentStartCU + m_uiAbsIdxInLCU, m_sliceSegmentStartCU, sizeof( UInt ) * m_uiNumPartition  );
1490#if H_3D_ARP
1491  memcpy( rpcCU->getARPW()             + m_uiAbsIdxInLCU, m_puhARPW,             iSizeInUchar );
1492#endif
1493#if H_3D_IC
1494  memcpy( rpcCU->getICFlag()           + m_uiAbsIdxInLCU, m_pbICFlag,            iSizeInBool );
1495#endif
1496}
1497
1498Void TComDataCU::copyToPic( UChar uhDepth, UInt uiPartIdx, UInt uiPartDepth )
1499{
1500  TComDataCU*&  rpcCU       = m_pcPic->getCU( m_uiCUAddr );
1501  UInt          uiQNumPart  = m_uiNumPartition>>(uiPartDepth<<1);
1502 
1503  UInt uiPartStart          = uiPartIdx*uiQNumPart;
1504  UInt uiPartOffset         = m_uiAbsIdxInLCU + uiPartStart;
1505 
1506  rpcCU->getTotalCost()       = m_dTotalCost;
1507  rpcCU->getTotalDistortion() = m_uiTotalDistortion;
1508  rpcCU->getTotalBits()       = m_uiTotalBits;
1509 
1510  Int iSizeInUchar  = sizeof( UChar  ) * uiQNumPart;
1511  Int iSizeInBool   = sizeof( Bool   ) * uiQNumPart;
1512 
1513  Int sizeInChar  = sizeof( Char ) * uiQNumPart;
1514  memcpy( rpcCU->getSkipFlag()       + uiPartOffset, m_skipFlag,   sizeof( *m_skipFlag )   * uiQNumPart );
1515
1516  memcpy( rpcCU->getQP() + uiPartOffset, m_phQP, sizeInChar );
1517  memcpy( rpcCU->getPartitionSize()  + uiPartOffset, m_pePartSize, sizeof( *m_pePartSize ) * uiQNumPart );
1518  memcpy( rpcCU->getPredictionMode() + uiPartOffset, m_pePredMode, sizeof( *m_pePredMode ) * uiQNumPart );
1519  memcpy( rpcCU->getCUTransquantBypass()+ uiPartOffset, m_CUTransquantBypass, sizeof( *m_CUTransquantBypass ) * uiQNumPart );
1520  memcpy( rpcCU->getMergeFlag()         + uiPartOffset, m_pbMergeFlag,         iSizeInBool  );
1521  memcpy( rpcCU->getMergeIndex()        + uiPartOffset, m_puhMergeIndex,       iSizeInUchar );
1522#if H_3D_VSP
1523  memcpy( rpcCU->getVSPFlag()           + uiPartOffset, m_piVSPFlag,           sizeof(Char) * uiQNumPart );
1524#if MTK_VSP_FIX_E0172
1525  memcpy( rpcCU->getVSPDir  ()          + uiPartOffset, m_piVSPDir  ,          sizeInChar );
1526#endif
1527#endif
1528  memcpy( rpcCU->getLumaIntraDir()      + uiPartOffset, m_puhLumaIntraDir,     iSizeInUchar );
1529  memcpy( rpcCU->getChromaIntraDir()    + uiPartOffset, m_puhChromaIntraDir,   iSizeInUchar );
1530  memcpy( rpcCU->getInterDir()          + uiPartOffset, m_puhInterDir,         iSizeInUchar );
1531  memcpy( rpcCU->getTransformIdx()      + uiPartOffset, m_puhTrIdx,            iSizeInUchar );
1532  memcpy( rpcCU->getTransformSkip(TEXT_LUMA)     + uiPartOffset, m_puhTransformSkip[0], iSizeInUchar );
1533  memcpy( rpcCU->getTransformSkip(TEXT_CHROMA_U) + uiPartOffset, m_puhTransformSkip[1], iSizeInUchar );
1534  memcpy( rpcCU->getTransformSkip(TEXT_CHROMA_V) + uiPartOffset, m_puhTransformSkip[2], iSizeInUchar );
1535  memcpy( rpcCU->getCbf(TEXT_LUMA)     + uiPartOffset, m_puhCbf[0], iSizeInUchar );
1536  memcpy( rpcCU->getCbf(TEXT_CHROMA_U) + uiPartOffset, m_puhCbf[1], iSizeInUchar );
1537  memcpy( rpcCU->getCbf(TEXT_CHROMA_V) + uiPartOffset, m_puhCbf[2], iSizeInUchar );
1538 
1539#if H_3D_DIM
1540  for( Int i = 0; i < DMM_NUM_TYPE; i++ )
1541  {
1542    memcpy( rpcCU->getDimDeltaDC( i, 0 ) + uiPartOffset, m_dimDeltaDC[i][0], sizeof(Pel ) * uiQNumPart );
1543    memcpy( rpcCU->getDimDeltaDC( i, 1 ) + uiPartOffset, m_dimDeltaDC[i][1], sizeof(Pel ) * uiQNumPart );
1544  }
1545#if H_3D_DIM_DMM
1546  for( Int i = 0; i < DMM_NUM_TYPE; i++ )
1547  {
1548    memcpy( rpcCU->getDmmWedgeTabIdx( i ) + uiPartOffset, m_dmmWedgeTabIdx[i], sizeof(UInt) * uiQNumPart );
1549  }
1550  memcpy( rpcCU->getDmm2DeltaEnd()    + uiPartOffset, m_dmm2DeltaEnd   , sizeof(Int ) * uiQNumPart );
1551  memcpy( rpcCU->getDmm3IntraTabIdx() + uiPartOffset, m_dmm3IntraTabIdx, sizeof(UInt) * uiQNumPart );
1552#endif
1553#if H_3D_DIM_RBC
1554  memcpy( rpcCU->getEdgeCode( uiPartOffset ),         m_pucEdgeCode,     iSizeInUchar * RBC_MAX_EDGE_NUM_PER_4x4 );
1555  memcpy( rpcCU->getEdgeNumber()      + uiPartOffset, m_pucEdgeNumber,   iSizeInUchar );
1556  memcpy( rpcCU->getEdgeStartPos()    + uiPartOffset, m_pucEdgeStartPos, iSizeInUchar );
1557  memcpy( rpcCU->getEdgeLeftFirst()   + uiPartOffset, m_pbEdgeLeftFirst, iSizeInBool );
1558  memcpy( rpcCU->getEdgePartition( uiPartOffset ),    m_pbEdgePartition, iSizeInBool * 16 );
1559#endif
1560#if H_3D_DIM_SDC
1561  memcpy( rpcCU->getSDCFlag()             + uiPartOffset, m_pbSDCFlag,      iSizeInBool  );
1562  memcpy( rpcCU->getSDCSegmentDCOffset(0) + uiPartOffset, m_apSegmentDCOffset[0], sizeof( Pel ) * uiQNumPart);
1563  memcpy( rpcCU->getSDCSegmentDCOffset(1) + uiPartOffset, m_apSegmentDCOffset[1], sizeof( Pel ) * uiQNumPart);
1564#endif
1565#endif
1566  memcpy( rpcCU->getDepth()  + uiPartOffset, m_puhDepth,  iSizeInUchar );
1567  memcpy( rpcCU->getWidth()  + uiPartOffset, m_puhWidth,  iSizeInUchar );
1568  memcpy( rpcCU->getHeight() + uiPartOffset, m_puhHeight, iSizeInUchar );
1569 
1570  memcpy( rpcCU->getMVPIdx(REF_PIC_LIST_0) + uiPartOffset, m_apiMVPIdx[0], iSizeInUchar );
1571  memcpy( rpcCU->getMVPIdx(REF_PIC_LIST_1) + uiPartOffset, m_apiMVPIdx[1], iSizeInUchar );
1572  memcpy( rpcCU->getMVPNum(REF_PIC_LIST_0) + uiPartOffset, m_apiMVPNum[0], iSizeInUchar );
1573  memcpy( rpcCU->getMVPNum(REF_PIC_LIST_1) + uiPartOffset, m_apiMVPNum[1], iSizeInUchar );
1574  m_acCUMvField[0].copyTo( rpcCU->getCUMvField( REF_PIC_LIST_0 ), m_uiAbsIdxInLCU, uiPartStart, uiQNumPart );
1575  m_acCUMvField[1].copyTo( rpcCU->getCUMvField( REF_PIC_LIST_1 ), m_uiAbsIdxInLCU, uiPartStart, uiQNumPart );
1576 
1577  memcpy( rpcCU->getIPCMFlag() + uiPartOffset, m_pbIPCMFlag,         iSizeInBool  );
1578
1579  UInt uiTmp  = (g_uiMaxCUWidth*g_uiMaxCUHeight)>>((uhDepth+uiPartDepth)<<1);
1580  UInt uiTmp2 = uiPartOffset*m_pcPic->getMinCUWidth()*m_pcPic->getMinCUHeight();
1581  memcpy( rpcCU->getCoeffY()  + uiTmp2, m_pcTrCoeffY,  sizeof(TCoeff)*uiTmp  );
1582#if ADAPTIVE_QP_SELECTION
1583  memcpy( rpcCU->getArlCoeffY()  + uiTmp2, m_pcArlCoeffY,  sizeof(Int)*uiTmp  );
1584#endif
1585 
1586  memcpy( rpcCU->getPCMSampleY() + uiTmp2 , m_pcIPCMSampleY, sizeof( Pel ) * uiTmp );
1587
1588  uiTmp >>= 2; uiTmp2 >>= 2;
1589  memcpy( rpcCU->getCoeffCb() + uiTmp2, m_pcTrCoeffCb, sizeof(TCoeff)*uiTmp  );
1590  memcpy( rpcCU->getCoeffCr() + uiTmp2, m_pcTrCoeffCr, sizeof(TCoeff)*uiTmp  );
1591#if ADAPTIVE_QP_SELECTION
1592  memcpy( rpcCU->getArlCoeffCb() + uiTmp2, m_pcArlCoeffCb, sizeof(Int)*uiTmp  );
1593  memcpy( rpcCU->getArlCoeffCr() + uiTmp2, m_pcArlCoeffCr, sizeof(Int)*uiTmp  );
1594#endif
1595
1596  memcpy( rpcCU->getPCMSampleCb() + uiTmp2 , m_pcIPCMSampleCb, sizeof( Pel ) * uiTmp );
1597  memcpy( rpcCU->getPCMSampleCr() + uiTmp2 , m_pcIPCMSampleCr, sizeof( Pel ) * uiTmp );
1598  rpcCU->getTotalBins() = m_uiTotalBins;
1599  memcpy( rpcCU->m_sliceStartCU        + uiPartOffset, m_sliceStartCU,        sizeof( UInt ) * uiQNumPart  );
1600  memcpy( rpcCU->m_sliceSegmentStartCU + uiPartOffset, m_sliceSegmentStartCU, sizeof( UInt ) * uiQNumPart  );
1601#if H_3D_ARP
1602  memcpy( rpcCU->getARPW()             + uiPartOffset, m_puhARPW,             iSizeInUchar );
1603#endif
1604#if H_3D_IC
1605  memcpy( rpcCU->getICFlag()           + uiPartOffset, m_pbICFlag,            iSizeInBool );
1606#endif
1607}
1608
1609// --------------------------------------------------------------------------------------------------------------------
1610// Other public functions
1611// --------------------------------------------------------------------------------------------------------------------
1612
1613TComDataCU* TComDataCU::getPULeft( UInt& uiLPartUnitIdx, 
1614                                   UInt uiCurrPartUnitIdx, 
1615                                   Bool bEnforceSliceRestriction, 
1616                                   Bool bEnforceTileRestriction )
1617{
1618  UInt uiAbsPartIdx       = g_auiZscanToRaster[uiCurrPartUnitIdx];
1619  UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[m_uiAbsIdxInLCU];
1620  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1621 
1622  if ( !RasterAddress::isZeroCol( uiAbsPartIdx, uiNumPartInCUWidth ) )
1623  {
1624    uiLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - 1 ];
1625    if ( RasterAddress::isEqualCol( uiAbsPartIdx, uiAbsZorderCUIdx, uiNumPartInCUWidth ) )
1626    {
1627      return m_pcPic->getCU( getAddr() );
1628    }
1629    else
1630    {
1631      uiLPartUnitIdx -= m_uiAbsIdxInLCU;
1632      return this;
1633    }
1634  }
1635 
1636  uiLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx + uiNumPartInCUWidth - 1 ];
1637
1638
1639  if ( (bEnforceSliceRestriction && (m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL || m_pcCULeft->getSCUAddr()+uiLPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)))
1640      ||
1641       (bEnforceTileRestriction && ( m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL || (m_pcPic->getPicSym()->getTileIdxMap( m_pcCULeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))  )  )
1642      )
1643  {
1644    return NULL;
1645  }
1646  return m_pcCULeft;
1647}
1648
1649TComDataCU* TComDataCU::getPUAbove( UInt& uiAPartUnitIdx,
1650                                    UInt uiCurrPartUnitIdx, 
1651                                    Bool bEnforceSliceRestriction, 
1652                                    Bool planarAtLCUBoundary ,
1653                                    Bool bEnforceTileRestriction )
1654{
1655  UInt uiAbsPartIdx       = g_auiZscanToRaster[uiCurrPartUnitIdx];
1656  UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[m_uiAbsIdxInLCU];
1657  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1658 
1659  if ( !RasterAddress::isZeroRow( uiAbsPartIdx, uiNumPartInCUWidth ) )
1660  {
1661    uiAPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - uiNumPartInCUWidth ];
1662    if ( RasterAddress::isEqualRow( uiAbsPartIdx, uiAbsZorderCUIdx, uiNumPartInCUWidth ) )
1663    {
1664      return m_pcPic->getCU( getAddr() );
1665    }
1666    else
1667    {
1668      uiAPartUnitIdx -= m_uiAbsIdxInLCU;
1669      return this;
1670    }
1671  }
1672
1673  if(planarAtLCUBoundary)
1674  {
1675    return NULL;
1676  }
1677 
1678  uiAPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx + m_pcPic->getNumPartInCU() - uiNumPartInCUWidth ];
1679
1680  if ( (bEnforceSliceRestriction && (m_pcCUAbove==NULL || m_pcCUAbove->getSlice()==NULL || m_pcCUAbove->getSCUAddr()+uiAPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)))
1681      ||
1682       (bEnforceTileRestriction &&(m_pcCUAbove==NULL || m_pcCUAbove->getSlice()==NULL || (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAbove->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))))
1683      )
1684  {
1685    return NULL;
1686  }
1687  return m_pcCUAbove;
1688}
1689
1690TComDataCU* TComDataCU::getPUAboveLeft( UInt& uiALPartUnitIdx, UInt uiCurrPartUnitIdx, Bool bEnforceSliceRestriction )
1691{
1692  UInt uiAbsPartIdx       = g_auiZscanToRaster[uiCurrPartUnitIdx];
1693  UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[m_uiAbsIdxInLCU];
1694  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1695 
1696  if ( !RasterAddress::isZeroCol( uiAbsPartIdx, uiNumPartInCUWidth ) )
1697  {
1698    if ( !RasterAddress::isZeroRow( uiAbsPartIdx, uiNumPartInCUWidth ) )
1699    {
1700      uiALPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - uiNumPartInCUWidth - 1 ];
1701      if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdx, uiAbsZorderCUIdx, uiNumPartInCUWidth ) )
1702      {
1703        return m_pcPic->getCU( getAddr() );
1704      }
1705      else
1706      {
1707        uiALPartUnitIdx -= m_uiAbsIdxInLCU;
1708        return this;
1709      }
1710    }
1711    uiALPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx + getPic()->getNumPartInCU() - uiNumPartInCUWidth - 1 ];
1712    if ( (bEnforceSliceRestriction && (m_pcCUAbove==NULL || m_pcCUAbove->getSlice()==NULL ||
1713       m_pcCUAbove->getSCUAddr()+uiALPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1714       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAbove->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1715       ))
1716     )
1717    {
1718      return NULL;
1719    }
1720    return m_pcCUAbove;
1721  }
1722 
1723  if ( !RasterAddress::isZeroRow( uiAbsPartIdx, uiNumPartInCUWidth ) )
1724  {
1725    uiALPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdx - 1 ];
1726    if ( (bEnforceSliceRestriction && (m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL || 
1727       m_pcCULeft->getSCUAddr()+uiALPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1728       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCULeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1729       ))
1730     )
1731    {
1732      return NULL;
1733    }
1734    return m_pcCULeft;
1735  }
1736 
1737  uiALPartUnitIdx = g_auiRasterToZscan[ m_pcPic->getNumPartInCU() - 1 ];
1738  if ( (bEnforceSliceRestriction && (m_pcCUAboveLeft==NULL || m_pcCUAboveLeft->getSlice()==NULL ||
1739       m_pcCUAboveLeft->getSCUAddr()+uiALPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1740       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAboveLeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1741       ))
1742     )
1743  {
1744    return NULL;
1745  }
1746  return m_pcCUAboveLeft;
1747}
1748
1749TComDataCU* TComDataCU::getPUAboveRight( UInt& uiARPartUnitIdx, UInt uiCurrPartUnitIdx, Bool bEnforceSliceRestriction )
1750{
1751  UInt uiAbsPartIdxRT     = g_auiZscanToRaster[uiCurrPartUnitIdx];
1752  UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + m_puhWidth[0] / m_pcPic->getMinCUWidth() - 1;
1753  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1754 
1755  if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxRT] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )
1756  {
1757    uiARPartUnitIdx = MAX_UINT;
1758    return NULL;
1759  }
1760 
1761  if ( RasterAddress::lessThanCol( uiAbsPartIdxRT, uiNumPartInCUWidth - 1, uiNumPartInCUWidth ) )
1762  {
1763    if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, uiNumPartInCUWidth ) )
1764    {
1765      if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxRT - uiNumPartInCUWidth + 1 ] )
1766      {
1767        uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT - uiNumPartInCUWidth + 1 ];
1768        if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxRT, uiAbsZorderCUIdx, uiNumPartInCUWidth ) )
1769        {
1770          return m_pcPic->getCU( getAddr() );
1771        }
1772        else
1773        {
1774          uiARPartUnitIdx -= m_uiAbsIdxInLCU;
1775          return this;
1776        }
1777      }
1778      uiARPartUnitIdx = MAX_UINT;
1779      return NULL;
1780    }
1781    uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT + m_pcPic->getNumPartInCU() - uiNumPartInCUWidth + 1 ];
1782    if ( (bEnforceSliceRestriction && (m_pcCUAbove==NULL || m_pcCUAbove->getSlice()==NULL ||
1783       m_pcCUAbove->getSCUAddr()+uiARPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1784       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAbove->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1785       ))
1786     )
1787    {
1788      return NULL;
1789    }
1790    return m_pcCUAbove;
1791  }
1792 
1793  if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, uiNumPartInCUWidth ) )
1794  {
1795    uiARPartUnitIdx = MAX_UINT;
1796    return NULL;
1797  }
1798 
1799  uiARPartUnitIdx = g_auiRasterToZscan[ m_pcPic->getNumPartInCU() - uiNumPartInCUWidth ];
1800  if ( (bEnforceSliceRestriction && (m_pcCUAboveRight==NULL || m_pcCUAboveRight->getSlice()==NULL ||
1801       m_pcPic->getPicSym()->getInverseCUOrderMap( m_pcCUAboveRight->getAddr()) > m_pcPic->getPicSym()->getInverseCUOrderMap( getAddr()) ||
1802       m_pcCUAboveRight->getSCUAddr()+uiARPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1803       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAboveRight->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1804       ))
1805     )
1806  {
1807    return NULL;
1808  }
1809  return m_pcCUAboveRight;
1810}
1811
1812TComDataCU* TComDataCU::getPUBelowLeft( UInt& uiBLPartUnitIdx, UInt uiCurrPartUnitIdx, Bool bEnforceSliceRestriction )
1813{
1814  UInt uiAbsPartIdxLB     = g_auiZscanToRaster[uiCurrPartUnitIdx];
1815  UInt uiAbsZorderCUIdxLB = g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + (m_puhHeight[0] / m_pcPic->getMinCUHeight() - 1)*m_pcPic->getNumPartInWidth();
1816  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1817 
1818  if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxLB] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
1819  {
1820    uiBLPartUnitIdx = MAX_UINT;
1821    return NULL;
1822  }
1823 
1824  if ( RasterAddress::lessThanRow( uiAbsPartIdxLB, m_pcPic->getNumPartInHeight() - 1, uiNumPartInCUWidth ) )
1825  {
1826    if ( !RasterAddress::isZeroCol( uiAbsPartIdxLB, uiNumPartInCUWidth ) )
1827    {
1828      if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxLB + uiNumPartInCUWidth - 1 ] )
1829      {
1830        uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + uiNumPartInCUWidth - 1 ];
1831        if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxLB, uiAbsZorderCUIdxLB, uiNumPartInCUWidth ) )
1832        {
1833          return m_pcPic->getCU( getAddr() );
1834        }
1835        else
1836        {
1837          uiBLPartUnitIdx -= m_uiAbsIdxInLCU;
1838          return this;
1839        }
1840      }
1841      uiBLPartUnitIdx = MAX_UINT;
1842      return NULL;
1843    }
1844    uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + uiNumPartInCUWidth*2 - 1 ];
1845    if ( (bEnforceSliceRestriction && (m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL || 
1846       m_pcCULeft->getSCUAddr()+uiBLPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1847       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCULeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1848       ))
1849     )
1850    {
1851      return NULL;
1852    }
1853    return m_pcCULeft;
1854  }
1855 
1856  uiBLPartUnitIdx = MAX_UINT;
1857  return NULL;
1858}
1859
1860TComDataCU* TComDataCU::getPUBelowLeftAdi(UInt& uiBLPartUnitIdx,  UInt uiCurrPartUnitIdx, UInt uiPartUnitOffset, Bool bEnforceSliceRestriction )
1861{
1862  UInt uiAbsPartIdxLB     = g_auiZscanToRaster[uiCurrPartUnitIdx];
1863  UInt uiAbsZorderCUIdxLB = g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + ((m_puhHeight[0] / m_pcPic->getMinCUHeight()) - 1)*m_pcPic->getNumPartInWidth();
1864  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1865 
1866  if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxLB] + (m_pcPic->getPicSym()->getMinCUHeight() * uiPartUnitOffset)) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples())
1867  {
1868    uiBLPartUnitIdx = MAX_UINT;
1869    return NULL;
1870  }
1871 
1872  if ( RasterAddress::lessThanRow( uiAbsPartIdxLB, m_pcPic->getNumPartInHeight() - uiPartUnitOffset, uiNumPartInCUWidth ) )
1873  {
1874    if ( !RasterAddress::isZeroCol( uiAbsPartIdxLB, uiNumPartInCUWidth ) )
1875    {
1876      if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxLB + uiPartUnitOffset * uiNumPartInCUWidth - 1 ] )
1877      {
1878        uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + uiPartUnitOffset * uiNumPartInCUWidth - 1 ];
1879        if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxLB, uiAbsZorderCUIdxLB, uiNumPartInCUWidth ) )
1880        {
1881          return m_pcPic->getCU( getAddr() );
1882        }
1883        else
1884        {
1885          uiBLPartUnitIdx -= m_uiAbsIdxInLCU;
1886          return this;
1887        }
1888      }
1889      uiBLPartUnitIdx = MAX_UINT;
1890      return NULL;
1891    }
1892    uiBLPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxLB + (1+uiPartUnitOffset) * uiNumPartInCUWidth - 1 ];
1893    if ( (bEnforceSliceRestriction && (m_pcCULeft==NULL || m_pcCULeft->getSlice()==NULL || 
1894       m_pcCULeft->getSCUAddr()+uiBLPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1895       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCULeft->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1896       ))
1897     )
1898    {
1899      return NULL;
1900    }
1901    return m_pcCULeft;
1902  }
1903 
1904  uiBLPartUnitIdx = MAX_UINT;
1905  return NULL;
1906}
1907
1908TComDataCU* TComDataCU::getPUAboveRightAdi(UInt&  uiARPartUnitIdx, UInt uiCurrPartUnitIdx, UInt uiPartUnitOffset, Bool bEnforceSliceRestriction )
1909{
1910  UInt uiAbsPartIdxRT     = g_auiZscanToRaster[uiCurrPartUnitIdx];
1911  UInt uiAbsZorderCUIdx   = g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + (m_puhWidth[0] / m_pcPic->getMinCUWidth()) - 1;
1912  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
1913 
1914  if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxRT] + (m_pcPic->getPicSym()->getMinCUHeight() * uiPartUnitOffset)) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )
1915  {
1916    uiARPartUnitIdx = MAX_UINT;
1917    return NULL;
1918  }
1919 
1920  if ( RasterAddress::lessThanCol( uiAbsPartIdxRT, uiNumPartInCUWidth - uiPartUnitOffset, uiNumPartInCUWidth ) )
1921  {
1922    if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, uiNumPartInCUWidth ) )
1923    {
1924      if ( uiCurrPartUnitIdx > g_auiRasterToZscan[ uiAbsPartIdxRT - uiNumPartInCUWidth + uiPartUnitOffset ] )
1925      {
1926        uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT - uiNumPartInCUWidth + uiPartUnitOffset ];
1927        if ( RasterAddress::isEqualRowOrCol( uiAbsPartIdxRT, uiAbsZorderCUIdx, uiNumPartInCUWidth ) )
1928        {
1929          return m_pcPic->getCU( getAddr() );
1930        }
1931        else
1932        {
1933          uiARPartUnitIdx -= m_uiAbsIdxInLCU;
1934          return this;
1935        }
1936      }
1937      uiARPartUnitIdx = MAX_UINT;
1938      return NULL;
1939    }
1940    uiARPartUnitIdx = g_auiRasterToZscan[ uiAbsPartIdxRT + m_pcPic->getNumPartInCU() - uiNumPartInCUWidth + uiPartUnitOffset ];
1941    if ( (bEnforceSliceRestriction && (m_pcCUAbove==NULL || m_pcCUAbove->getSlice()==NULL || 
1942       m_pcCUAbove->getSCUAddr()+uiARPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1943       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAbove->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1944       ))
1945     )
1946    {
1947      return NULL;
1948    }
1949    return m_pcCUAbove;
1950  }
1951 
1952  if ( !RasterAddress::isZeroRow( uiAbsPartIdxRT, uiNumPartInCUWidth ) )
1953  {
1954    uiARPartUnitIdx = MAX_UINT;
1955    return NULL;
1956  }
1957 
1958  uiARPartUnitIdx = g_auiRasterToZscan[ m_pcPic->getNumPartInCU() - uiNumPartInCUWidth + uiPartUnitOffset-1 ];
1959  if ( (bEnforceSliceRestriction && (m_pcCUAboveRight==NULL || m_pcCUAboveRight->getSlice()==NULL ||
1960       m_pcPic->getPicSym()->getInverseCUOrderMap( m_pcCUAboveRight->getAddr()) > m_pcPic->getPicSym()->getInverseCUOrderMap( getAddr()) ||
1961       m_pcCUAboveRight->getSCUAddr()+uiARPartUnitIdx < m_pcPic->getCU( getAddr() )->getSliceStartCU(uiCurrPartUnitIdx)||
1962       (m_pcPic->getPicSym()->getTileIdxMap( m_pcCUAboveRight->getAddr() ) != m_pcPic->getPicSym()->getTileIdxMap(getAddr()))
1963       ))
1964     )
1965  {
1966    return NULL;
1967  }
1968  return m_pcCUAboveRight;
1969}
1970
1971/** Get left QpMinCu
1972*\param   uiLPartUnitIdx
1973*\param   uiCurrAbsIdxInLCU
1974*\returns TComDataCU*   point of TComDataCU of left QpMinCu
1975*/
1976TComDataCU* TComDataCU::getQpMinCuLeft( UInt& uiLPartUnitIdx, UInt uiCurrAbsIdxInLCU)
1977{
1978  UInt numPartInCUWidth = m_pcPic->getNumPartInWidth();
1979  UInt absZorderQpMinCUIdx = (uiCurrAbsIdxInLCU>>((g_uiMaxCUDepth - getSlice()->getPPS()->getMaxCuDQPDepth())<<1))<<((g_uiMaxCUDepth -getSlice()->getPPS()->getMaxCuDQPDepth())<<1);
1980  UInt absRorderQpMinCUIdx = g_auiZscanToRaster[absZorderQpMinCUIdx];
1981
1982  // check for left LCU boundary
1983  if ( RasterAddress::isZeroCol(absRorderQpMinCUIdx, numPartInCUWidth) )
1984  {
1985    return NULL;
1986  }
1987
1988  // get index of left-CU relative to top-left corner of current quantization group
1989  uiLPartUnitIdx = g_auiRasterToZscan[absRorderQpMinCUIdx - 1];
1990
1991  // return pointer to current LCU
1992  return m_pcPic->getCU( getAddr() );
1993}
1994
1995/** Get Above QpMinCu
1996*\param   aPartUnitIdx
1997*\param   currAbsIdxInLCU
1998*\returns TComDataCU*   point of TComDataCU of above QpMinCu
1999*/
2000TComDataCU* TComDataCU::getQpMinCuAbove( UInt& aPartUnitIdx, UInt currAbsIdxInLCU )
2001{
2002  UInt numPartInCUWidth = m_pcPic->getNumPartInWidth();
2003  UInt absZorderQpMinCUIdx = (currAbsIdxInLCU>>((g_uiMaxCUDepth - getSlice()->getPPS()->getMaxCuDQPDepth())<<1))<<((g_uiMaxCUDepth - getSlice()->getPPS()->getMaxCuDQPDepth())<<1);
2004  UInt absRorderQpMinCUIdx = g_auiZscanToRaster[absZorderQpMinCUIdx];
2005
2006  // check for top LCU boundary
2007  if ( RasterAddress::isZeroRow( absRorderQpMinCUIdx, numPartInCUWidth) )
2008  {
2009    return NULL;
2010  }
2011
2012  // get index of top-CU relative to top-left corner of current quantization group
2013  aPartUnitIdx = g_auiRasterToZscan[absRorderQpMinCUIdx - numPartInCUWidth];
2014
2015  // return pointer to current LCU
2016  return m_pcPic->getCU( getAddr() );
2017}
2018
2019/** Get reference QP from left QpMinCu or latest coded QP
2020*\param   uiCurrAbsIdxInLCU
2021*\returns Char   reference QP value
2022*/
2023Char TComDataCU::getRefQP( UInt uiCurrAbsIdxInLCU )
2024{
2025  UInt        lPartIdx = 0, aPartIdx = 0;
2026  TComDataCU* cULeft  = getQpMinCuLeft ( lPartIdx, m_uiAbsIdxInLCU + uiCurrAbsIdxInLCU );
2027  TComDataCU* cUAbove = getQpMinCuAbove( aPartIdx, m_uiAbsIdxInLCU + uiCurrAbsIdxInLCU );
2028  return (((cULeft? cULeft->getQP( lPartIdx ): getLastCodedQP( uiCurrAbsIdxInLCU )) + (cUAbove? cUAbove->getQP( aPartIdx ): getLastCodedQP( uiCurrAbsIdxInLCU )) + 1) >> 1);
2029}
2030
2031Int TComDataCU::getLastValidPartIdx( Int iAbsPartIdx )
2032{
2033  Int iLastValidPartIdx = iAbsPartIdx-1;
2034  while ( iLastValidPartIdx >= 0
2035       && getPredictionMode( iLastValidPartIdx ) == MODE_NONE )
2036  {
2037    UInt uiDepth = getDepth( iLastValidPartIdx );
2038    iLastValidPartIdx -= m_uiNumPartition>>(uiDepth<<1);
2039  }
2040  return iLastValidPartIdx;
2041}
2042
2043Char TComDataCU::getLastCodedQP( UInt uiAbsPartIdx )
2044{
2045  UInt uiQUPartIdxMask = ~((1<<((g_uiMaxCUDepth - getSlice()->getPPS()->getMaxCuDQPDepth())<<1))-1);
2046  Int iLastValidPartIdx = getLastValidPartIdx( uiAbsPartIdx&uiQUPartIdxMask );
2047  if ( uiAbsPartIdx < m_uiNumPartition
2048    && (getSCUAddr()+iLastValidPartIdx < getSliceStartCU(m_uiAbsIdxInLCU+uiAbsPartIdx)))
2049  {
2050    return getSlice()->getSliceQp();
2051  }
2052  else if ( iLastValidPartIdx >= 0 )
2053  {
2054    return getQP( iLastValidPartIdx );
2055  }
2056  else
2057  {
2058    if ( getZorderIdxInCU() > 0 )
2059    {
2060      return getPic()->getCU( getAddr() )->getLastCodedQP( getZorderIdxInCU() );
2061    }
2062    else if ( getPic()->getPicSym()->getInverseCUOrderMap(getAddr()) > 0
2063      && getPic()->getPicSym()->getTileIdxMap(getAddr()) == getPic()->getPicSym()->getTileIdxMap(getPic()->getPicSym()->getCUOrderMap(getPic()->getPicSym()->getInverseCUOrderMap(getAddr())-1))
2064      && !( getSlice()->getPPS()->getEntropyCodingSyncEnabledFlag() && getAddr() % getPic()->getFrameWidthInCU() == 0 ) )
2065    {
2066      return getPic()->getCU( getPic()->getPicSym()->getCUOrderMap(getPic()->getPicSym()->getInverseCUOrderMap(getAddr())-1) )->getLastCodedQP( getPic()->getNumPartInCU() );
2067    }
2068    else
2069    {
2070      return getSlice()->getSliceQp();
2071    }
2072  }
2073}
2074/** Check whether the CU is coded in lossless coding mode
2075 * \param   uiAbsPartIdx
2076 * \returns true if the CU is coded in lossless coding mode; false if otherwise
2077 */
2078Bool TComDataCU::isLosslessCoded(UInt absPartIdx)
2079{
2080  return (getSlice()->getPPS()->getTransquantBypassEnableFlag() && getCUTransquantBypass (absPartIdx));
2081}
2082
2083/** Get allowed chroma intra modes
2084*\param   uiAbsPartIdx
2085*\param   uiModeList  pointer to chroma intra modes array
2086*\returns
2087*- fill uiModeList with chroma intra modes
2088*/
2089Void TComDataCU::getAllowedChromaDir( UInt uiAbsPartIdx, UInt* uiModeList )
2090{
2091  uiModeList[0] = PLANAR_IDX;
2092  uiModeList[1] = VER_IDX;
2093  uiModeList[2] = HOR_IDX;
2094  uiModeList[3] = DC_IDX;
2095  uiModeList[4] = DM_CHROMA_IDX;
2096
2097  UInt uiLumaMode = getLumaIntraDir( uiAbsPartIdx );
2098
2099  for( Int i = 0; i < NUM_CHROMA_MODE - 1; i++ )
2100  {
2101    if( uiLumaMode == uiModeList[i] )
2102    {
2103      uiModeList[i] = 34; // VER+8 mode
2104      break;
2105    }
2106  }
2107}
2108
2109/** Get most probable intra modes
2110*\param   uiAbsPartIdx
2111*\param   uiIntraDirPred  pointer to the array for MPM storage
2112*\param   piMode          it is set with MPM mode in case both MPM are equal. It is used to restrict RD search at encode side.
2113*\returns Number of MPM
2114*/
2115Int TComDataCU::getIntraDirLumaPredictor( UInt uiAbsPartIdx, Int* uiIntraDirPred, Int* piMode  )
2116{
2117  TComDataCU* pcTempCU;
2118  UInt        uiTempPartIdx;
2119  Int         iLeftIntraDir, iAboveIntraDir;
2120  Int         uiPredNum = 0;
2121 
2122  // Get intra direction of left PU
2123  pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
2124 
2125  iLeftIntraDir  = pcTempCU ? ( pcTempCU->isIntra( uiTempPartIdx ) ? pcTempCU->getLumaIntraDir( uiTempPartIdx ) : DC_IDX ) : DC_IDX;
2126#if H_3D_DIM
2127  mapDepthModeToIntraDir( iLeftIntraDir );
2128#endif
2129 
2130  // Get intra direction of above PU
2131  pcTempCU = getPUAbove( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx, true, true );
2132 
2133  iAboveIntraDir = pcTempCU ? ( pcTempCU->isIntra( uiTempPartIdx ) ? pcTempCU->getLumaIntraDir( uiTempPartIdx ) : DC_IDX ) : DC_IDX;
2134#if H_3D_DIM
2135  mapDepthModeToIntraDir( iAboveIntraDir );
2136#endif
2137 
2138  uiPredNum = 3;
2139  if(iLeftIntraDir == iAboveIntraDir)
2140  {
2141    if( piMode )
2142    {
2143      *piMode = 1;
2144    }
2145   
2146    if (iLeftIntraDir > 1) // angular modes
2147    {
2148      uiIntraDirPred[0] = iLeftIntraDir;
2149      uiIntraDirPred[1] = ((iLeftIntraDir + 29) % 32) + 2;
2150      uiIntraDirPred[2] = ((iLeftIntraDir - 1 ) % 32) + 2;
2151    }
2152    else //non-angular
2153    {
2154      uiIntraDirPred[0] = PLANAR_IDX;
2155      uiIntraDirPred[1] = DC_IDX;
2156      uiIntraDirPred[2] = VER_IDX; 
2157    }
2158  }
2159  else
2160  {
2161    if( piMode )
2162    {
2163      *piMode = 2;
2164    }
2165    uiIntraDirPred[0] = iLeftIntraDir;
2166    uiIntraDirPred[1] = iAboveIntraDir;
2167   
2168    if (iLeftIntraDir && iAboveIntraDir ) //both modes are non-planar
2169    {
2170      uiIntraDirPred[2] = PLANAR_IDX;
2171    }
2172    else
2173    {
2174      uiIntraDirPred[2] =  (iLeftIntraDir+iAboveIntraDir)<2? VER_IDX : DC_IDX;
2175    }
2176  }
2177 
2178  return uiPredNum;
2179}
2180
2181UInt TComDataCU::getCtxSplitFlag( UInt uiAbsPartIdx, UInt uiDepth )
2182{
2183  TComDataCU* pcTempCU;
2184  UInt        uiTempPartIdx;
2185  UInt        uiCtx;
2186  // Get left split flag
2187  pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
2188  uiCtx  = ( pcTempCU ) ? ( ( pcTempCU->getDepth( uiTempPartIdx ) > uiDepth ) ? 1 : 0 ) : 0;
2189 
2190  // Get above split flag
2191  pcTempCU = getPUAbove( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
2192  uiCtx += ( pcTempCU ) ? ( ( pcTempCU->getDepth( uiTempPartIdx ) > uiDepth ) ? 1 : 0 ) : 0;
2193 
2194  return uiCtx;
2195}
2196
2197UInt TComDataCU::getCtxQtCbf( TextType eType, UInt uiTrDepth )
2198{
2199  if( eType )
2200  {
2201    return uiTrDepth;
2202  }
2203  else
2204  {
2205    const UInt uiCtx = ( uiTrDepth == 0 ? 1 : 0 );
2206    return uiCtx;
2207  }
2208}
2209
2210UInt TComDataCU::getQuadtreeTULog2MinSizeInCU( UInt absPartIdx )
2211{
2212  UInt log2CbSize = g_aucConvertToBit[getWidth( absPartIdx )] + 2;
2213  PartSize  partSize  = getPartitionSize( absPartIdx );
2214  UInt quadtreeTUMaxDepth = getPredictionMode( absPartIdx ) == MODE_INTRA ? m_pcSlice->getSPS()->getQuadtreeTUMaxDepthIntra() : m_pcSlice->getSPS()->getQuadtreeTUMaxDepthInter(); 
2215  Int intraSplitFlag = ( getPredictionMode( absPartIdx ) == MODE_INTRA && partSize == SIZE_NxN ) ? 1 : 0;
2216  Int interSplitFlag = ((quadtreeTUMaxDepth == 1) && (getPredictionMode( absPartIdx ) == MODE_INTER) && (partSize != SIZE_2Nx2N) );
2217 
2218  UInt log2MinTUSizeInCU = 0;
2219  if (log2CbSize < (m_pcSlice->getSPS()->getQuadtreeTULog2MinSize() + quadtreeTUMaxDepth - 1 + interSplitFlag + intraSplitFlag) ) 
2220  {
2221    // when fully making use of signaled TUMaxDepth + inter/intraSplitFlag, resulting luma TB size is < QuadtreeTULog2MinSize
2222    log2MinTUSizeInCU = m_pcSlice->getSPS()->getQuadtreeTULog2MinSize();
2223  }
2224  else
2225  {
2226    // when fully making use of signaled TUMaxDepth + inter/intraSplitFlag, resulting luma TB size is still >= QuadtreeTULog2MinSize
2227    log2MinTUSizeInCU = log2CbSize - ( quadtreeTUMaxDepth - 1 + interSplitFlag + intraSplitFlag); // stop when trafoDepth == hierarchy_depth = splitFlag
2228    if ( log2MinTUSizeInCU > m_pcSlice->getSPS()->getQuadtreeTULog2MaxSize())
2229    {
2230      // when fully making use of signaled TUMaxDepth + inter/intraSplitFlag, resulting luma TB size is still > QuadtreeTULog2MaxSize
2231      log2MinTUSizeInCU = m_pcSlice->getSPS()->getQuadtreeTULog2MaxSize();
2232    } 
2233  }
2234  return log2MinTUSizeInCU;
2235}
2236
2237UInt TComDataCU::getCtxSkipFlag( UInt uiAbsPartIdx )
2238{
2239  TComDataCU* pcTempCU;
2240  UInt        uiTempPartIdx;
2241  UInt        uiCtx = 0;
2242 
2243  // Get BCBP of left PU
2244  pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
2245  uiCtx    = ( pcTempCU ) ? pcTempCU->isSkipped( uiTempPartIdx ) : 0;
2246 
2247  // Get BCBP of above PU
2248  pcTempCU = getPUAbove( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
2249  uiCtx   += ( pcTempCU ) ? pcTempCU->isSkipped( uiTempPartIdx ) : 0;
2250 
2251  return uiCtx;
2252}
2253
2254#if H_3D_ARP
2255UInt TComDataCU::getCTXARPWFlag( UInt uiAbsPartIdx )
2256{
2257  TComDataCU* pcTempCU;
2258  UInt        uiTempPartIdx;
2259  UInt        uiCtx = 0;
2260 
2261  pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
2262  uiCtx    = ( pcTempCU ) ? ((pcTempCU->getARPW( uiTempPartIdx )==0)?0:1) : 0;
2263 
2264  pcTempCU = getPUAbove( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
2265  uiCtx   += ( pcTempCU ) ? ((pcTempCU->getARPW( uiTempPartIdx )==0)?0:1): 0;
2266 
2267  return uiCtx;
2268}
2269#endif
2270
2271#if H_3D_IC
2272UInt TComDataCU::getCtxICFlag( UInt uiAbsPartIdx )
2273{
2274  UInt        uiCtx = 0;
2275
2276  return uiCtx;
2277}
2278#endif
2279UInt TComDataCU::getCtxInterDir( UInt uiAbsPartIdx )
2280{
2281  return getDepth( uiAbsPartIdx );
2282}
2283
2284Void TComDataCU::setCbfSubParts( UInt uiCbfY, UInt uiCbfU, UInt uiCbfV, UInt uiAbsPartIdx, UInt uiDepth )
2285{
2286  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2287  memset( m_puhCbf[0] + uiAbsPartIdx, uiCbfY, sizeof( UChar ) * uiCurrPartNumb );
2288  memset( m_puhCbf[1] + uiAbsPartIdx, uiCbfU, sizeof( UChar ) * uiCurrPartNumb );
2289  memset( m_puhCbf[2] + uiAbsPartIdx, uiCbfV, sizeof( UChar ) * uiCurrPartNumb );
2290}
2291
2292Void TComDataCU::setCbfSubParts( UInt uiCbf, TextType eTType, UInt uiAbsPartIdx, UInt uiDepth )
2293{
2294  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2295  memset( m_puhCbf[g_aucConvertTxtTypeToIdx[eTType]] + uiAbsPartIdx, uiCbf, sizeof( UChar ) * uiCurrPartNumb );
2296}
2297
2298/** Sets a coded block flag for all sub-partitions of a partition
2299 * \param uiCbf The value of the coded block flag to be set
2300 * \param eTType
2301 * \param uiAbsPartIdx
2302 * \param uiPartIdx
2303 * \param uiDepth
2304 * \returns Void
2305 */
2306Void TComDataCU::setCbfSubParts ( UInt uiCbf, TextType eTType, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
2307{
2308  setSubPart<UChar>( uiCbf, m_puhCbf[g_aucConvertTxtTypeToIdx[eTType]], uiAbsPartIdx, uiDepth, uiPartIdx );
2309}
2310
2311Void TComDataCU::setDepthSubParts( UInt uiDepth, UInt uiAbsPartIdx )
2312{
2313  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2314  memset( m_puhDepth + uiAbsPartIdx, uiDepth, sizeof(UChar)*uiCurrPartNumb );
2315}
2316
2317Bool TComDataCU::isFirstAbsZorderIdxInDepth (UInt uiAbsPartIdx, UInt uiDepth)
2318{
2319  UInt uiPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2320  return (((m_uiAbsIdxInLCU + uiAbsPartIdx)% uiPartNumb) == 0);
2321}
2322
2323Void TComDataCU::setPartSizeSubParts( PartSize eMode, UInt uiAbsPartIdx, UInt uiDepth )
2324{
2325  assert( sizeof( *m_pePartSize) == 1 );
2326  memset( m_pePartSize + uiAbsPartIdx, eMode, m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ) );
2327}
2328
2329Void TComDataCU::setCUTransquantBypassSubParts( Bool flag, UInt uiAbsPartIdx, UInt uiDepth )
2330{
2331  memset( m_CUTransquantBypass + uiAbsPartIdx, flag, m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ) );
2332}
2333
2334Void TComDataCU::setSkipFlagSubParts( Bool skip, UInt absPartIdx, UInt depth )
2335{
2336  assert( sizeof( *m_skipFlag) == 1 );
2337  memset( m_skipFlag + absPartIdx, skip, m_pcPic->getNumPartInCU() >> ( 2 * depth ) );
2338}
2339
2340Void TComDataCU::setPredModeSubParts( PredMode eMode, UInt uiAbsPartIdx, UInt uiDepth )
2341{
2342  assert( sizeof( *m_pePredMode) == 1 );
2343  memset( m_pePredMode + uiAbsPartIdx, eMode, m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ) );
2344}
2345
2346Void TComDataCU::setQPSubCUs( Int qp, TComDataCU* pcCU, UInt absPartIdx, UInt depth, Bool &foundNonZeroCbf )
2347{
2348  UInt currPartNumb = m_pcPic->getNumPartInCU() >> (depth << 1);
2349  UInt currPartNumQ = currPartNumb >> 2;
2350
2351  if(!foundNonZeroCbf)
2352  {
2353    if(pcCU->getDepth(absPartIdx) > depth)
2354    {
2355      for ( UInt partUnitIdx = 0; partUnitIdx < 4; partUnitIdx++ )
2356      {
2357        pcCU->setQPSubCUs( qp, pcCU, absPartIdx+partUnitIdx*currPartNumQ, depth+1, foundNonZeroCbf );
2358      }
2359    }
2360    else
2361    {
2362      if(pcCU->getCbf( absPartIdx, TEXT_LUMA ) || pcCU->getCbf( absPartIdx, TEXT_CHROMA_U ) || pcCU->getCbf( absPartIdx, TEXT_CHROMA_V ) )
2363      {
2364        foundNonZeroCbf = true;
2365      }
2366      else
2367      {
2368        setQPSubParts(qp, absPartIdx, depth);
2369      }
2370    }
2371  }
2372}
2373
2374Void TComDataCU::setQPSubParts( Int qp, UInt uiAbsPartIdx, UInt uiDepth )
2375{
2376  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2377  TComSlice * pcSlice = getPic()->getSlice(getPic()->getCurrSliceIdx());
2378
2379  for(UInt uiSCUIdx = uiAbsPartIdx; uiSCUIdx < uiAbsPartIdx+uiCurrPartNumb; uiSCUIdx++)
2380  {
2381    if( m_pcPic->getCU( getAddr() )->getSliceSegmentStartCU(uiSCUIdx+getZorderIdxInCU()) == pcSlice->getSliceSegmentCurStartCUAddr() )
2382    {
2383      m_phQP[uiSCUIdx] = qp;
2384    }
2385  }
2386}
2387
2388Void TComDataCU::setLumaIntraDirSubParts( UInt uiDir, UInt uiAbsPartIdx, UInt uiDepth )
2389{
2390  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2391 
2392  memset( m_puhLumaIntraDir + uiAbsPartIdx, uiDir, sizeof(UChar)*uiCurrPartNumb );
2393}
2394
2395template<typename T>
2396Void TComDataCU::setSubPart( T uiParameter, T* puhBaseLCU, UInt uiCUAddr, UInt uiCUDepth, UInt uiPUIdx )
2397{
2398  assert( sizeof(T) == 1 ); // Using memset() works only for types of size 1
2399 
2400  UInt uiCurrPartNumQ = (m_pcPic->getNumPartInCU() >> (2 * uiCUDepth)) >> 2;
2401  switch ( m_pePartSize[ uiCUAddr ] )
2402  {
2403    case SIZE_2Nx2N:
2404      memset( puhBaseLCU + uiCUAddr, uiParameter, 4 * uiCurrPartNumQ );
2405      break;
2406    case SIZE_2NxN:
2407      memset( puhBaseLCU + uiCUAddr, uiParameter, 2 * uiCurrPartNumQ );
2408      break;
2409    case SIZE_Nx2N:
2410      memset( puhBaseLCU + uiCUAddr, uiParameter, uiCurrPartNumQ );
2411      memset( puhBaseLCU + uiCUAddr + 2 * uiCurrPartNumQ, uiParameter, uiCurrPartNumQ );
2412      break;
2413    case SIZE_NxN:
2414      memset( puhBaseLCU + uiCUAddr, uiParameter, uiCurrPartNumQ ); 
2415      break;
2416    case SIZE_2NxnU:
2417      if ( uiPUIdx == 0 )
2418      {
2419        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 1) );                     
2420        memset( puhBaseLCU + uiCUAddr + uiCurrPartNumQ, uiParameter, (uiCurrPartNumQ >> 1) );                     
2421      }
2422      else if ( uiPUIdx == 1 )
2423      {
2424        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 1) );                     
2425        memset( puhBaseLCU + uiCUAddr + uiCurrPartNumQ, uiParameter, ((uiCurrPartNumQ >> 1) + (uiCurrPartNumQ << 1)) );                     
2426      }
2427      else
2428      {
2429        assert(0);
2430      }
2431      break;
2432    case SIZE_2NxnD:
2433      if ( uiPUIdx == 0 )
2434      {
2435        memset( puhBaseLCU + uiCUAddr, uiParameter, ((uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1)) );                     
2436        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + uiCurrPartNumQ, uiParameter, (uiCurrPartNumQ >> 1) );                     
2437      }
2438      else if ( uiPUIdx == 1 )
2439      {
2440        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 1) );                     
2441        memset( puhBaseLCU + uiCUAddr + uiCurrPartNumQ, uiParameter, (uiCurrPartNumQ >> 1) );                     
2442      }
2443      else
2444      {
2445        assert(0);
2446      }
2447      break;
2448    case SIZE_nLx2N:
2449      if ( uiPUIdx == 0 )
2450      {
2451        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 2) );
2452        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) ); 
2453        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ >> 2) ); 
2454        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) ); 
2455      }
2456      else if ( uiPUIdx == 1 )
2457      {
2458        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 2) );
2459        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) ); 
2460        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ >> 2) ); 
2461        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) ); 
2462      }
2463      else
2464      {
2465        assert(0);
2466      }
2467      break;
2468    case SIZE_nRx2N:
2469      if ( uiPUIdx == 0 )
2470      {     
2471        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) );                           
2472        memset( puhBaseLCU + uiCUAddr + uiCurrPartNumQ + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );                           
2473        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ + (uiCurrPartNumQ >> 2)) );                           
2474        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + uiCurrPartNumQ + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );                           
2475      }
2476      else if ( uiPUIdx == 1 )
2477      {
2478        memset( puhBaseLCU + uiCUAddr, uiParameter, (uiCurrPartNumQ >> 2) );                           
2479        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );                           
2480        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1), uiParameter, (uiCurrPartNumQ >> 2) );                           
2481        memset( puhBaseLCU + uiCUAddr + (uiCurrPartNumQ << 1) + (uiCurrPartNumQ >> 1), uiParameter, (uiCurrPartNumQ >> 2) );                         
2482      }
2483      else
2484      {
2485        assert(0);
2486      }
2487      break;
2488    default:
2489      assert( 0 );
2490  }
2491}
2492
2493#if H_3D_DIM_SDC
2494Void TComDataCU::setSDCFlagSubParts ( Bool bSDCFlag, UInt uiAbsPartIdx, UInt uiDepth )
2495{
2496  assert( sizeof( *m_pbSDCFlag) == 1 );
2497  memset( m_pbSDCFlag + uiAbsPartIdx, bSDCFlag, m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ) );
2498}
2499
2500Bool TComDataCU::getSDCAvailable( UInt uiAbsPartIdx )
2501{
2502  // check general CU information
2503  if( !getSlice()->getIsDepth() || !isIntra(uiAbsPartIdx) || getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N )
2504    return false;
2505 
2506  // check prediction mode
2507  UInt uiLumaPredMode = getLumaIntraDir( uiAbsPartIdx ); 
2508  if( uiLumaPredMode == DC_IDX || uiLumaPredMode == PLANAR_IDX || ( getDimType( uiLumaPredMode ) == DMM1_IDX && !isDimDeltaDC( uiLumaPredMode ) ) )
2509    return true;
2510 
2511  // else
2512  return false;
2513}
2514#endif
2515Void TComDataCU::setMergeFlagSubParts ( Bool bMergeFlag, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
2516{
2517  setSubPart( bMergeFlag, m_pbMergeFlag, uiAbsPartIdx, uiDepth, uiPartIdx );
2518}
2519
2520Void TComDataCU::setMergeIndexSubParts ( UInt uiMergeIndex, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
2521{
2522  setSubPart<UChar>( uiMergeIndex, m_puhMergeIndex, uiAbsPartIdx, uiDepth, uiPartIdx );
2523}
2524
2525#if H_3D_VSP
2526Void TComDataCU::setVSPFlagSubParts( Char iVSPFlag, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
2527{
2528  setSubPart<Char>( iVSPFlag, m_piVSPFlag, uiAbsPartIdx, uiDepth, uiPartIdx );
2529}
2530#if MTK_VSP_FIX_E0172
2531Void TComDataCU::setVSPDirSubParts ( Char iVSPDir, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
2532{
2533  setSubPart<Char>( iVSPDir, m_piVSPDir, uiAbsPartIdx, uiDepth, uiPartIdx );
2534}
2535#endif
2536#endif
2537Void TComDataCU::setChromIntraDirSubParts( UInt uiDir, UInt uiAbsPartIdx, UInt uiDepth )
2538{
2539  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2540 
2541  memset( m_puhChromaIntraDir + uiAbsPartIdx, uiDir, sizeof(UChar)*uiCurrPartNumb );
2542}
2543
2544Void TComDataCU::setInterDirSubParts( UInt uiDir, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
2545{
2546  setSubPart<UChar>( uiDir, m_puhInterDir, uiAbsPartIdx, uiDepth, uiPartIdx );
2547}
2548
2549Void TComDataCU::setMVPIdxSubParts( Int iMVPIdx, RefPicList eRefPicList, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
2550{
2551  setSubPart<Char>( iMVPIdx, m_apiMVPIdx[eRefPicList], uiAbsPartIdx, uiDepth, uiPartIdx );
2552}
2553
2554Void TComDataCU::setMVPNumSubParts( Int iMVPNum, RefPicList eRefPicList, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
2555{
2556  setSubPart<Char>( iMVPNum, m_apiMVPNum[eRefPicList], uiAbsPartIdx, uiDepth, uiPartIdx );
2557}
2558
2559
2560Void TComDataCU::setTrIdxSubParts( UInt uiTrIdx, UInt uiAbsPartIdx, UInt uiDepth )
2561{
2562  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2563 
2564  memset( m_puhTrIdx + uiAbsPartIdx, uiTrIdx, sizeof(UChar)*uiCurrPartNumb );
2565}
2566
2567Void TComDataCU::setTransformSkipSubParts( UInt useTransformSkipY, UInt useTransformSkipU, UInt useTransformSkipV, UInt uiAbsPartIdx, UInt uiDepth )
2568{
2569  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2570
2571  memset( m_puhTransformSkip[0] + uiAbsPartIdx, useTransformSkipY, sizeof( UChar ) * uiCurrPartNumb );
2572  memset( m_puhTransformSkip[1] + uiAbsPartIdx, useTransformSkipU, sizeof( UChar ) * uiCurrPartNumb );
2573  memset( m_puhTransformSkip[2] + uiAbsPartIdx, useTransformSkipV, sizeof( UChar ) * uiCurrPartNumb );
2574}
2575
2576Void TComDataCU::setTransformSkipSubParts( UInt useTransformSkip, TextType eType, UInt uiAbsPartIdx, UInt uiDepth)
2577{
2578  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2579
2580  memset( m_puhTransformSkip[g_aucConvertTxtTypeToIdx[eType]] + uiAbsPartIdx, useTransformSkip, sizeof( UChar ) * uiCurrPartNumb );
2581}
2582
2583Void TComDataCU::setSizeSubParts( UInt uiWidth, UInt uiHeight, UInt uiAbsPartIdx, UInt uiDepth )
2584{
2585  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
2586 
2587  memset( m_puhWidth  + uiAbsPartIdx, uiWidth,  sizeof(UChar)*uiCurrPartNumb );
2588  memset( m_puhHeight + uiAbsPartIdx, uiHeight, sizeof(UChar)*uiCurrPartNumb );
2589}
2590
2591UChar TComDataCU::getNumPartInter()
2592{
2593  UChar iNumPart = 0;
2594 
2595  switch ( m_pePartSize[0] )
2596  {
2597    case SIZE_2Nx2N:    iNumPart = 1; break;
2598    case SIZE_2NxN:     iNumPart = 2; break;
2599    case SIZE_Nx2N:     iNumPart = 2; break;
2600    case SIZE_NxN:      iNumPart = 4; break;
2601    case SIZE_2NxnU:    iNumPart = 2; break;
2602    case SIZE_2NxnD:    iNumPart = 2; break;
2603    case SIZE_nLx2N:    iNumPart = 2; break;
2604    case SIZE_nRx2N:    iNumPart = 2; break;
2605    default:            assert (0);   break;
2606  }
2607 
2608  return  iNumPart;
2609}
2610
2611#if H_3D_IC
2612Void TComDataCU::getPartIndexAndSize( UInt uiPartIdx, UInt& ruiPartAddr, Int& riWidth, Int& riHeight, UInt uiAbsPartIdx, Bool bLCU)
2613{
2614  UInt uiNumPartition  = bLCU ? (getWidth(uiAbsPartIdx)*getHeight(uiAbsPartIdx) >> 4) : m_uiNumPartition;
2615  UInt  uiTmpAbsPartIdx  = bLCU ? uiAbsPartIdx : 0;
2616
2617  switch ( m_pePartSize[uiTmpAbsPartIdx] )
2618  {
2619  case SIZE_2NxN:
2620    riWidth = getWidth( uiTmpAbsPartIdx );      riHeight = getHeight( uiTmpAbsPartIdx ) >> 1; ruiPartAddr = ( uiPartIdx == 0 )? 0 : uiNumPartition >> 1;
2621    break;
2622  case SIZE_Nx2N:
2623    riWidth = getWidth( uiTmpAbsPartIdx ) >> 1; riHeight = getHeight( uiTmpAbsPartIdx );      ruiPartAddr = ( uiPartIdx == 0 )? 0 : uiNumPartition >> 2;
2624    break;
2625  case SIZE_NxN:
2626    riWidth = getWidth( uiTmpAbsPartIdx ) >> 1; riHeight = getHeight( uiTmpAbsPartIdx ) >> 1; ruiPartAddr = ( uiNumPartition >> 2 ) * uiPartIdx;
2627    break;
2628  case SIZE_2NxnU:
2629    riWidth     = getWidth( uiTmpAbsPartIdx );
2630    riHeight    = ( uiPartIdx == 0 ) ?  getHeight( uiTmpAbsPartIdx ) >> 2 : ( getHeight( uiTmpAbsPartIdx ) >> 2 ) + ( getHeight( uiTmpAbsPartIdx ) >> 1 );
2631    ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : uiNumPartition >> 3;
2632    break;
2633  case SIZE_2NxnD:
2634    riWidth     = getWidth( uiTmpAbsPartIdx );
2635    riHeight    = ( uiPartIdx == 0 ) ?  ( getHeight( uiTmpAbsPartIdx ) >> 2 ) + ( getHeight( uiTmpAbsPartIdx ) >> 1 ) : getHeight( uiTmpAbsPartIdx ) >> 2;
2636    ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : (uiNumPartition >> 1) + (uiNumPartition >> 3);
2637    break;
2638  case SIZE_nLx2N:
2639    riWidth     = ( uiPartIdx == 0 ) ? getWidth( uiTmpAbsPartIdx ) >> 2 : ( getWidth( uiTmpAbsPartIdx ) >> 2 ) + ( getWidth( uiTmpAbsPartIdx ) >> 1 );
2640    riHeight    = getHeight( uiTmpAbsPartIdx );
2641    ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : uiNumPartition >> 4;
2642    break;
2643  case SIZE_nRx2N:
2644    riWidth     = ( uiPartIdx == 0 ) ? ( getWidth( uiTmpAbsPartIdx ) >> 2 ) + ( getWidth( uiTmpAbsPartIdx ) >> 1 ) : getWidth( uiTmpAbsPartIdx ) >> 2;
2645    riHeight    = getHeight( uiTmpAbsPartIdx );
2646    ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : (uiNumPartition >> 2) + (uiNumPartition >> 4);
2647    break;
2648  default:
2649    assert ( m_pePartSize[uiTmpAbsPartIdx] == SIZE_2Nx2N ); 
2650    riWidth = getWidth( uiTmpAbsPartIdx );      riHeight = getHeight( uiTmpAbsPartIdx );      ruiPartAddr = 0;
2651    break;
2652  }
2653}
2654#else
2655Void TComDataCU::getPartIndexAndSize( UInt uiPartIdx, UInt& ruiPartAddr, Int& riWidth, Int& riHeight )
2656{
2657  switch ( m_pePartSize[0] )
2658  {
2659    case SIZE_2NxN:
2660      riWidth = getWidth(0);      riHeight = getHeight(0) >> 1; ruiPartAddr = ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 1;
2661      break;
2662    case SIZE_Nx2N:
2663      riWidth = getWidth(0) >> 1; riHeight = getHeight(0);      ruiPartAddr = ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 2;
2664      break;
2665    case SIZE_NxN:
2666      riWidth = getWidth(0) >> 1; riHeight = getHeight(0) >> 1; ruiPartAddr = ( m_uiNumPartition >> 2 ) * uiPartIdx;
2667      break;
2668    case SIZE_2NxnU:
2669      riWidth     = getWidth(0);
2670      riHeight    = ( uiPartIdx == 0 ) ?  getHeight(0) >> 2 : ( getHeight(0) >> 2 ) + ( getHeight(0) >> 1 );
2671      ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : m_uiNumPartition >> 3;
2672      break;
2673    case SIZE_2NxnD:
2674      riWidth     = getWidth(0);
2675      riHeight    = ( uiPartIdx == 0 ) ?  ( getHeight(0) >> 2 ) + ( getHeight(0) >> 1 ) : getHeight(0) >> 2;
2676      ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : (m_uiNumPartition >> 1) + (m_uiNumPartition >> 3);
2677      break;
2678    case SIZE_nLx2N:
2679      riWidth     = ( uiPartIdx == 0 ) ? getWidth(0) >> 2 : ( getWidth(0) >> 2 ) + ( getWidth(0) >> 1 );
2680      riHeight    = getHeight(0);
2681      ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : m_uiNumPartition >> 4;
2682      break;
2683    case SIZE_nRx2N:
2684      riWidth     = ( uiPartIdx == 0 ) ? ( getWidth(0) >> 2 ) + ( getWidth(0) >> 1 ) : getWidth(0) >> 2;
2685      riHeight    = getHeight(0);
2686      ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : (m_uiNumPartition >> 2) + (m_uiNumPartition >> 4);
2687      break;
2688    default:
2689      assert ( m_pePartSize[0] == SIZE_2Nx2N );
2690      riWidth = getWidth(0);      riHeight = getHeight(0);      ruiPartAddr = 0;
2691      break;
2692  }
2693}
2694#endif
2695
2696
2697Void TComDataCU::getMvField ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefPicList, TComMvField& rcMvField )
2698{
2699  if ( pcCU == NULL )  // OUT OF BOUNDARY
2700  {
2701    TComMv  cZeroMv;
2702    rcMvField.setMvField( cZeroMv, NOT_VALID );
2703    return;
2704  }
2705 
2706  TComCUMvField*  pcCUMvField = pcCU->getCUMvField( eRefPicList );
2707  rcMvField.setMvField( pcCUMvField->getMv( uiAbsPartIdx ), pcCUMvField->getRefIdx( uiAbsPartIdx ) );
2708}
2709
2710Void TComDataCU::deriveLeftRightTopIdxGeneral ( UInt uiAbsPartIdx, UInt uiPartIdx, UInt& ruiPartIdxLT, UInt& ruiPartIdxRT )
2711{
2712  ruiPartIdxLT = m_uiAbsIdxInLCU + uiAbsPartIdx;
2713  UInt uiPUWidth = 0;
2714 
2715  switch ( m_pePartSize[uiAbsPartIdx] )
2716  {
2717    case SIZE_2Nx2N: uiPUWidth = m_puhWidth[uiAbsPartIdx];  break;
2718    case SIZE_2NxN:  uiPUWidth = m_puhWidth[uiAbsPartIdx];   break;
2719    case SIZE_Nx2N:  uiPUWidth = m_puhWidth[uiAbsPartIdx]  >> 1;  break;
2720    case SIZE_NxN:   uiPUWidth = m_puhWidth[uiAbsPartIdx]  >> 1; break;
2721    case SIZE_2NxnU:   uiPUWidth = m_puhWidth[uiAbsPartIdx]; break;
2722    case SIZE_2NxnD:   uiPUWidth = m_puhWidth[uiAbsPartIdx]; break;
2723    case SIZE_nLx2N:   
2724      if ( uiPartIdx == 0 )
2725      {
2726        uiPUWidth = m_puhWidth[uiAbsPartIdx]  >> 2; 
2727      }
2728      else if ( uiPartIdx == 1 )
2729      {
2730        uiPUWidth = (m_puhWidth[uiAbsPartIdx]  >> 1) + (m_puhWidth[uiAbsPartIdx]  >> 2); 
2731      }
2732      else
2733      {
2734        assert(0);
2735      }
2736      break;
2737    case SIZE_nRx2N:   
2738      if ( uiPartIdx == 0 )
2739      {
2740        uiPUWidth = (m_puhWidth[uiAbsPartIdx]  >> 1) + (m_puhWidth[uiAbsPartIdx]  >> 2); 
2741      }
2742      else if ( uiPartIdx == 1 )
2743      {
2744        uiPUWidth = m_puhWidth[uiAbsPartIdx]  >> 2; 
2745      }
2746      else
2747      {
2748        assert(0);
2749      }
2750      break;
2751    default:
2752      assert (0);
2753      break;
2754  }
2755 
2756  ruiPartIdxRT = g_auiRasterToZscan [g_auiZscanToRaster[ ruiPartIdxLT ] + uiPUWidth / m_pcPic->getMinCUWidth() - 1 ];
2757}
2758
2759Void TComDataCU::deriveLeftBottomIdxGeneral( UInt uiAbsPartIdx, UInt uiPartIdx, UInt& ruiPartIdxLB )
2760{
2761  UInt uiPUHeight = 0;
2762  switch ( m_pePartSize[uiAbsPartIdx] )
2763  {
2764    case SIZE_2Nx2N: uiPUHeight = m_puhHeight[uiAbsPartIdx];    break;
2765    case SIZE_2NxN:  uiPUHeight = m_puhHeight[uiAbsPartIdx] >> 1;    break;
2766    case SIZE_Nx2N:  uiPUHeight = m_puhHeight[uiAbsPartIdx];  break;
2767    case SIZE_NxN:   uiPUHeight = m_puhHeight[uiAbsPartIdx] >> 1;    break;
2768    case SIZE_2NxnU: 
2769      if ( uiPartIdx == 0 )
2770      {
2771        uiPUHeight = m_puhHeight[uiAbsPartIdx] >> 2;   
2772      }
2773      else if ( uiPartIdx == 1 )
2774      {
2775        uiPUHeight = (m_puhHeight[uiAbsPartIdx] >> 1) + (m_puhHeight[uiAbsPartIdx] >> 2);   
2776      }
2777      else
2778      {
2779        assert(0);
2780      }
2781      break;
2782    case SIZE_2NxnD: 
2783      if ( uiPartIdx == 0 )
2784      {
2785        uiPUHeight = (m_puhHeight[uiAbsPartIdx] >> 1) + (m_puhHeight[uiAbsPartIdx] >> 2);   
2786      }
2787      else if ( uiPartIdx == 1 )
2788      {
2789        uiPUHeight = m_puhHeight[uiAbsPartIdx] >> 2;   
2790      }
2791      else
2792      {
2793        assert(0);
2794      }
2795      break;
2796    case SIZE_nLx2N: uiPUHeight = m_puhHeight[uiAbsPartIdx];  break;
2797    case SIZE_nRx2N: uiPUHeight = m_puhHeight[uiAbsPartIdx];  break;
2798    default:
2799      assert (0);
2800      break;
2801  }
2802 
2803  ruiPartIdxLB      = g_auiRasterToZscan [g_auiZscanToRaster[ m_uiAbsIdxInLCU + uiAbsPartIdx ] + ((uiPUHeight / m_pcPic->getMinCUHeight()) - 1)*m_pcPic->getNumPartInWidth()];
2804}
2805
2806Void TComDataCU::deriveLeftRightTopIdx ( UInt uiPartIdx, UInt& ruiPartIdxLT, UInt& ruiPartIdxRT )
2807{
2808  ruiPartIdxLT = m_uiAbsIdxInLCU;
2809  ruiPartIdxRT = g_auiRasterToZscan [g_auiZscanToRaster[ ruiPartIdxLT ] + m_puhWidth[0] / m_pcPic->getMinCUWidth() - 1 ];
2810 
2811  switch ( m_pePartSize[0] )
2812  {
2813    case SIZE_2Nx2N:                                                                                                                                break;
2814    case SIZE_2NxN:
2815      ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 1; ruiPartIdxRT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 1;
2816      break;
2817    case SIZE_Nx2N:
2818      ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 2; ruiPartIdxRT -= ( uiPartIdx == 1 )? 0 : m_uiNumPartition >> 2;
2819      break;
2820    case SIZE_NxN:
2821      ruiPartIdxLT += ( m_uiNumPartition >> 2 ) * uiPartIdx;         ruiPartIdxRT +=  ( m_uiNumPartition >> 2 ) * ( uiPartIdx - 1 );
2822      break;
2823    case SIZE_2NxnU:
2824      ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 3;
2825      ruiPartIdxRT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 3;
2826      break;
2827    case SIZE_2NxnD:
2828      ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : ( m_uiNumPartition >> 1 ) + ( m_uiNumPartition >> 3 );
2829      ruiPartIdxRT += ( uiPartIdx == 0 )? 0 : ( m_uiNumPartition >> 1 ) + ( m_uiNumPartition >> 3 );
2830      break;
2831    case SIZE_nLx2N:
2832      ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 4;
2833      ruiPartIdxRT -= ( uiPartIdx == 1 )? 0 : ( m_uiNumPartition >> 2 ) + ( m_uiNumPartition >> 4 );
2834      break;
2835    case SIZE_nRx2N:
2836      ruiPartIdxLT += ( uiPartIdx == 0 )? 0 : ( m_uiNumPartition >> 2 ) + ( m_uiNumPartition >> 4 );
2837      ruiPartIdxRT -= ( uiPartIdx == 1 )? 0 : m_uiNumPartition >> 4;
2838      break;
2839    default:
2840      assert (0);
2841      break;
2842  }
2843 
2844}
2845
2846Void TComDataCU::deriveLeftBottomIdx( UInt  uiPartIdx,      UInt&      ruiPartIdxLB )
2847{
2848  ruiPartIdxLB      = g_auiRasterToZscan [g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + ( ((m_puhHeight[0] / m_pcPic->getMinCUHeight())>>1) - 1)*m_pcPic->getNumPartInWidth()];
2849 
2850  switch ( m_pePartSize[0] )
2851  {
2852    case SIZE_2Nx2N:
2853      ruiPartIdxLB += m_uiNumPartition >> 1;
2854      break;
2855    case SIZE_2NxN:
2856      ruiPartIdxLB += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 1;
2857      break;
2858    case SIZE_Nx2N:
2859      ruiPartIdxLB += ( uiPartIdx == 0 )? m_uiNumPartition >> 1 : (m_uiNumPartition >> 2)*3;
2860      break;
2861    case SIZE_NxN:
2862      ruiPartIdxLB += ( m_uiNumPartition >> 2 ) * uiPartIdx;
2863      break;
2864    case SIZE_2NxnU:
2865      ruiPartIdxLB += ( uiPartIdx == 0 ) ? -((Int)m_uiNumPartition >> 3) : m_uiNumPartition >> 1;
2866      break;
2867    case SIZE_2NxnD:
2868      ruiPartIdxLB += ( uiPartIdx == 0 ) ? (m_uiNumPartition >> 2) + (m_uiNumPartition >> 3): m_uiNumPartition >> 1;
2869      break;
2870    case SIZE_nLx2N:
2871      ruiPartIdxLB += ( uiPartIdx == 0 ) ? m_uiNumPartition >> 1 : (m_uiNumPartition >> 1) + (m_uiNumPartition >> 4);
2872      break;
2873    case SIZE_nRx2N:
2874      ruiPartIdxLB += ( uiPartIdx == 0 ) ? m_uiNumPartition >> 1 : (m_uiNumPartition >> 1) + (m_uiNumPartition >> 2) + (m_uiNumPartition >> 4);
2875      break;
2876    default:
2877      assert (0);
2878      break;
2879  }
2880}
2881
2882/** Derives the partition index of neighbouring bottom right block
2883 * \param [in]  eCUMode
2884 * \param [in]  uiPartIdx
2885 * \param [out] ruiPartIdxRB
2886 */
2887Void TComDataCU::deriveRightBottomIdx( UInt  uiPartIdx,      UInt&      ruiPartIdxRB )
2888{
2889  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];
2890
2891  switch ( m_pePartSize[0] )
2892  {
2893    case SIZE_2Nx2N: 
2894      ruiPartIdxRB += m_uiNumPartition >> 1;   
2895      break;
2896    case SIZE_2NxN: 
2897      ruiPartIdxRB += ( uiPartIdx == 0 )? 0 : m_uiNumPartition >> 1;   
2898      break;
2899    case SIZE_Nx2N: 
2900      ruiPartIdxRB += ( uiPartIdx == 0 )? m_uiNumPartition >> 2 : (m_uiNumPartition >> 1);   
2901      break;
2902    case SIZE_NxN:   
2903      ruiPartIdxRB += ( m_uiNumPartition >> 2 ) * ( uiPartIdx - 1 );   
2904      break;
2905    case SIZE_2NxnU:
2906      ruiPartIdxRB += ( uiPartIdx == 0 ) ? -((Int)m_uiNumPartition >> 3) : m_uiNumPartition >> 1;
2907      break;
2908    case SIZE_2NxnD:
2909      ruiPartIdxRB += ( uiPartIdx == 0 ) ? (m_uiNumPartition >> 2) + (m_uiNumPartition >> 3): m_uiNumPartition >> 1;
2910      break;
2911    case SIZE_nLx2N:
2912      ruiPartIdxRB += ( uiPartIdx == 0 ) ? (m_uiNumPartition >> 3) + (m_uiNumPartition >> 4): m_uiNumPartition >> 1;
2913      break;
2914    case SIZE_nRx2N:
2915      ruiPartIdxRB += ( uiPartIdx == 0 ) ? (m_uiNumPartition >> 2) + (m_uiNumPartition >> 3) + (m_uiNumPartition >> 4) : m_uiNumPartition >> 1;
2916      break;
2917    default:
2918      assert (0);
2919      break;
2920  }
2921}
2922
2923Void TComDataCU::deriveLeftRightTopIdxAdi ( UInt& ruiPartIdxLT, UInt& ruiPartIdxRT, UInt uiPartOffset, UInt uiPartDepth )
2924{
2925  UInt uiNumPartInWidth = (m_puhWidth[0]/m_pcPic->getMinCUWidth())>>uiPartDepth;
2926  ruiPartIdxLT = m_uiAbsIdxInLCU + uiPartOffset;
2927  ruiPartIdxRT = g_auiRasterToZscan[ g_auiZscanToRaster[ ruiPartIdxLT ] + uiNumPartInWidth - 1 ];
2928}
2929
2930Void TComDataCU::deriveLeftBottomIdxAdi( UInt& ruiPartIdxLB, UInt uiPartOffset, UInt uiPartDepth )
2931{
2932  UInt uiAbsIdx;
2933  UInt uiMinCuWidth, uiWidthInMinCus;
2934 
2935  uiMinCuWidth    = getPic()->getMinCUWidth();
2936  uiWidthInMinCus = (getWidth(0)/uiMinCuWidth)>>uiPartDepth;
2937  uiAbsIdx        = getZorderIdxInCU()+uiPartOffset+(m_uiNumPartition>>(uiPartDepth<<1))-1;
2938  uiAbsIdx        = g_auiZscanToRaster[uiAbsIdx]-(uiWidthInMinCus-1);
2939  ruiPartIdxLB    = g_auiRasterToZscan[uiAbsIdx];
2940}
2941
2942Bool TComDataCU::hasEqualMotion( UInt uiAbsPartIdx, TComDataCU* pcCandCU, UInt uiCandAbsPartIdx )
2943{
2944
2945  if ( getInterDir( uiAbsPartIdx ) != pcCandCU->getInterDir( uiCandAbsPartIdx ) )
2946  {
2947    return false;
2948  }
2949
2950  for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
2951  {
2952    if ( getInterDir( uiAbsPartIdx ) & ( 1 << uiRefListIdx ) )
2953    {
2954      if ( getCUMvField( RefPicList( uiRefListIdx ) )->getMv( uiAbsPartIdx )     != pcCandCU->getCUMvField( RefPicList( uiRefListIdx ) )->getMv( uiCandAbsPartIdx ) || 
2955        getCUMvField( RefPicList( uiRefListIdx ) )->getRefIdx( uiAbsPartIdx ) != pcCandCU->getCUMvField( RefPicList( uiRefListIdx ) )->getRefIdx( uiCandAbsPartIdx ) )
2956      {
2957        return false;
2958      }
2959    }
2960  }
2961
2962  return true;
2963}
2964
2965#if H_3D_VSP
2966
2967/** Add a VSP merging candidate
2968 * \Inputs
2969 * \param uiPUIdx: PU index within a CU
2970 * \param ucVspMergePos: Specify the VSP merge candidate position
2971 * \param mrgCandIdx: Target merge candidate index. At encoder, it is set equal to -1, such that the whole merge candidate list will be constructed.
2972 * \param pDinfo: The "disparity information" derived from neighboring blocks. Type 1 MV.
2973 * \param uiCount: The next position to add VSP merge candidate
2974 *
2975 * \Outputs
2976 * \param uiCount: The next position to add merge candidate. Will be updated if VSP is successfully added
2977 * \param abCandIsInter: abCandIsInter[iCount] tells that VSP candidate is an Inter candidate, if VSP is successfully added
2978 * \param pcMvFieldNeighbours:   Return combined motion information, then stored to a global buffer
2979 *                                    1) the "disparity vector". Type 1 MV. To be used to fetch a depth block.
2980 *                                    2) the ref index /list.    Type 2 reference picture pointer, typically for texture
2981 * \param puhInterDirNeighbours: Indicate the VSP prediction direction.
2982 * \param vspFlag: vspFlag[iCount] will be set (equal to 1), if VSP is successfully added. To be used to indicate the actual position of the VSP candidate
2983 *
2984 * \Return
2985 *   true:  if the VSP candidate is added at the target position
2986 *   false: otherwise
2987 */
2988#if MTK_VSP_FIX_E0172
2989inline Bool TComDataCU::xAddVspCand( UChar ucVspMergePos, Int mrgCandIdx, DisInfo* pDInfo, Int& iCount,
2990                                    Bool* abCandIsInter, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int* vspFlag, Int* vspDir )
2991#else
2992inline Bool TComDataCU::xAddVspCand( UChar ucVspMergePos, Int mrgCandIdx, DisInfo* pDInfo, Int& iCount,
2993                                     Bool* abCandIsInter, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int* vspFlag )
2994#endif
2995{
2996  if ( ucVspMergePos != H_3D_VSP_POSITION || 0 == m_pcSlice->getViewIndex() || !m_pcSlice->getVPS()->getViewSynthesisPredFlag( m_pcSlice->getLayerIdInVps() ) || m_pcSlice->getIsDepth() )
2997    return false;
2998
2999  Int refViewIdx = pDInfo->m_aVIdxCan;
3000  TComPic* picDepth = getSlice()->getIvPic( true, refViewIdx );
3001  if( picDepth == NULL ) // No depth reference avail
3002    return false;
3003 
3004  Bool refViewAvailFlag = false;
3005  UChar predFlag[2] = {0, 0};
3006  Int  iRefListIdX = 0;
3007  Int  iRefListIdY = 0;
3008  Int  i;
3009#if MTK_VSP_FIX_E0172
3010  Int currViewId = m_pcSlice->getViewId();
3011  Int derivedViewId = -1;
3012  Int otherViewId = -1;
3013#endif
3014  for( iRefListIdX = 0; iRefListIdX < 2 && !refViewAvailFlag; iRefListIdX++ )
3015  {
3016    RefPicList eRefPicList = RefPicList( iRefListIdX );
3017    for ( i = 0; i < m_pcSlice->getNumRefIdx(eRefPicList) && !refViewAvailFlag; i++ )
3018    {
3019      Int viewIdxRefInList = m_pcSlice->getRefPic(eRefPicList, i)->getViewIndex();
3020      if ( viewIdxRefInList == refViewIdx )
3021      {
3022        refViewAvailFlag = true;
3023        predFlag[iRefListIdX] = 1;
3024#if MTK_VSP_FIX_E0172
3025        vspDir[iCount] = iRefListIdX;
3026        derivedViewId = m_pcSlice->getRefPic(eRefPicList, i)->getViewId(); 
3027#endif
3028        iRefListIdY = 1 - iRefListIdX;
3029        pcMvFieldNeighbours[(iCount<<1)+iRefListIdX].setMvField( pDInfo->m_acDoNBDV, i );
3030#if H_3D_NBDV
3031        pcMvFieldNeighbours[(iCount<<1)+iRefListIdX].getMv().setIDVFlag (false);
3032#endif
3033      }
3034    }
3035  }
3036
3037  if (m_pcSlice->isInterB() && refViewAvailFlag)
3038  {
3039    RefPicList eRefPicList = RefPicList( iRefListIdY );
3040    refViewAvailFlag = false;
3041    for ( i = 0; i < m_pcSlice->getNumRefIdx(eRefPicList) && !refViewAvailFlag; i++ )
3042    {
3043      Int viewIdxRefInList = m_pcSlice->getRefPic(eRefPicList, i)->getViewIndex();
3044      if ( viewIdxRefInList != refViewIdx && viewIdxRefInList != m_pcSlice->getViewIndex() )
3045      {
3046        refViewAvailFlag = true;
3047        predFlag[iRefListIdY] = 1;
3048#if MTK_VSP_FIX_E0172
3049        TComMv  cMv = pDInfo->m_acDoNBDV;
3050        otherViewId = m_pcSlice->getRefPic( eRefPicList, i)->getViewId();
3051        Int iScale = xGetDistScaleFactor( currViewId, otherViewId, currViewId, derivedViewId );
3052        if ( iScale != 4096 && m_pcSlice->getVPS()->getIvMvScalingFlag() ) 
3053        {
3054          cMv = cMv.scaleMv( iScale );
3055        }
3056        else
3057        {
3058
3059          cMv = cMv;
3060        }
3061        clipMv( cMv );
3062        pcMvFieldNeighbours[(iCount<<1)+iRefListIdY].setMvField( cMv, i );
3063#else
3064        pcMvFieldNeighbours[(iCount<<1)+iRefListIdY].setMvField( pDInfo->m_acDoNBDV, i );
3065#endif
3066#if H_3D_NBDV
3067        pcMvFieldNeighbours[(iCount<<1)+iRefListIdY].getMv().setIDVFlag (false);
3068#endif
3069      }
3070    }
3071  }
3072
3073  // Set values to be returned
3074  abCandIsInter[iCount] = true;
3075  puhInterDirNeighbours[iCount] = (predFlag[0] | (predFlag[1] << 1));
3076  vspFlag[iCount] = 1;
3077
3078  if ( mrgCandIdx == iCount )
3079    return true;
3080
3081  iCount++;
3082
3083  return false;
3084}
3085
3086#endif
3087
3088#if QC_INRIA_MTK_MRG_E0126
3089inline Bool TComDataCU::xAddIvMRGCand( Int mrgCandIdx, Int& iCount, Bool* abCandIsInter, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int*   iPdmDir, TComMv* acPdmMv, 
3090                                       Int* aiPdmRefIdx, Int iPosDmv, Int* vspFlag )
3091{
3092  for(Int iLoop = 0; iLoop  < 2; iLoop ++ ) 
3093  {
3094    if( iLoop == 1 )
3095    {
3096      Int iFirDispCand = -1;
3097      if (xFirstDmvAvai(iCount, pcMvFieldNeighbours, iPdmDir, iPosDmv, vspFlag, iFirDispCand))
3098      {
3099        TComMv cMv;
3100        cMv = pcMvFieldNeighbours[(iFirDispCand<<1)].getMv();
3101        cMv.setHor(cMv.getHor()+4);
3102        if(m_pcSlice->getVPS()->getViewSynthesisPredFlag(m_pcSlice->getLayerIdInVps()))
3103        {
3104          cMv.setVer(0);
3105        }
3106        clipMv( cMv );
3107        abCandIsInter[ iCount ] = true;
3108        puhInterDirNeighbours[ iCount ] = puhInterDirNeighbours[iFirDispCand];
3109        pcMvFieldNeighbours[ iCount<<1  ].setMvField(cMv, pcMvFieldNeighbours[( iFirDispCand << 1)].getRefIdx() );
3110        pcMvFieldNeighbours[ (iCount<<1)+1 ].setMvField(pcMvFieldNeighbours[(iFirDispCand << 1) + 1].getMv(), pcMvFieldNeighbours[( iFirDispCand << 1) + 1].getRefIdx() );
3111        if( mrgCandIdx == iCount ) 
3112        {
3113          return true;
3114        }
3115        iCount++;
3116        break;
3117      }
3118    }
3119    if(iPdmDir[iLoop + 2])
3120    {
3121      abCandIsInter[ iCount ] = true;
3122      puhInterDirNeighbours[ iCount ] = iPdmDir[iLoop + 2];
3123      if( ( iPdmDir[iLoop + 2] & 1 ) == 1 )
3124      {
3125        pcMvFieldNeighbours[ iCount<<1 ].setMvField( acPdmMv[ (iLoop<<1) + 4 ], aiPdmRefIdx[ (iLoop<<1) + 4 ] ); 
3126      }
3127      if( ( iPdmDir[iLoop + 2] & 2 ) == 2 )
3128      {
3129        pcMvFieldNeighbours[ (iCount<<1)+1 ].setMvField( acPdmMv[ (iLoop<<1) + 5 ], aiPdmRefIdx[ (iLoop<<1) + 5 ] );
3130      }
3131     
3132      bool bRemove = false;
3133      if(!iLoop && iPdmDir[0] > 0)
3134      {
3135        if(puhInterDirNeighbours[iCount] == puhInterDirNeighbours[0] && pcMvFieldNeighbours[0]==pcMvFieldNeighbours[(iCount<<1)] && pcMvFieldNeighbours[1]==pcMvFieldNeighbours[(iCount<<1)+1])
3136        {
3137            bRemove                      = true;
3138            abCandIsInter        [ iCount ] = false; 
3139            puhInterDirNeighbours[iCount]   = 0;
3140            TComMv  cZeroMv;
3141            pcMvFieldNeighbours[iCount<<1].setMvField( cZeroMv, NOT_VALID );
3142            pcMvFieldNeighbours[(iCount<<1)+1].setMvField( cZeroMv, NOT_VALID );
3143        }
3144      }
3145      if(!bRemove)
3146      {
3147#if H_3D_NBDV
3148        if(iLoop)
3149        {
3150          pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3151          pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3152        }
3153#endif
3154        if( mrgCandIdx == iCount )
3155        {
3156          return true;
3157        }
3158        iCount++;
3159      }
3160      break;
3161    }
3162  }
3163  return false;
3164} 
3165
3166inline Bool TComDataCU::xFirstDmvAvai( Int& iCount, TComMvField* pcMvFieldNeighbours, Int* iPdmDir, Int iPosDmv, Int* vspFlag, Int& iFirDispCand )
3167{
3168  for ( Int i = (iPdmDir[0] ? 1: 0); i < iCount; i++ )
3169  {
3170    if ( ( i == iPosDmv ) || ( vspFlag[ i ] == 1 ) )
3171    {
3172      continue;
3173    }
3174    else if((pcMvFieldNeighbours[i<<1].getRefIdx()!=-1) && (getSlice()->getViewIndex() != getSlice()->getRefPic(RefPicList(0), pcMvFieldNeighbours[i<<1].getRefIdx())->getViewIndex()))
3175    {
3176      iFirDispCand = i;
3177      return true;
3178    }
3179  }
3180 return false; 
3181}
3182                                     
3183#endif
3184/** Constructs a list of merging candidates
3185 * \param uiAbsPartIdx
3186 * \param uiPUIdx
3187 * \param uiDepth
3188 * \param pcMvFieldNeighbours
3189 * \param puhInterDirNeighbours
3190 * \param numValidMergeCand
3191 */
3192Void TComDataCU::getInterMergeCandidates( UInt uiAbsPartIdx, UInt uiPUIdx, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours
3193#if H_3D_VSP
3194      , Int* vspFlag
3195#if MTK_VSP_FIX_E0172
3196      , Int* vspDir
3197#endif
3198#endif
3199      , Int& numValidMergeCand, Int mrgCandIdx
3200)
3201{
3202  UInt uiAbsPartAddr = m_uiAbsIdxInLCU + uiAbsPartIdx;
3203#if H_3D_IV_MERGE
3204  TComMv cZeroMv;
3205  Bool abCandIsInter[ MRG_MAX_NUM_CANDS_MEM ];
3206#else
3207  Bool abCandIsInter[ MRG_MAX_NUM_CANDS ];
3208#endif
3209  for( UInt ui = 0; ui < getSlice()->getMaxNumMergeCand(); ++ui )
3210  {
3211    abCandIsInter[ui] = false;
3212#if H_3D_IV_MERGE
3213    pcMvFieldNeighbours[ ( ui << 1 )     ].setMvField(cZeroMv, NOT_VALID);
3214    pcMvFieldNeighbours[ ( ui << 1 ) + 1 ].setMvField(cZeroMv, NOT_VALID);
3215#else
3216    pcMvFieldNeighbours[ ( ui << 1 )     ].setRefIdx(NOT_VALID);
3217    pcMvFieldNeighbours[ ( ui << 1 ) + 1 ].setRefIdx(NOT_VALID);
3218#endif
3219  }
3220  numValidMergeCand = getSlice()->getMaxNumMergeCand();
3221  // compute the location of the current PU
3222  Int xP, yP, nPSW, nPSH;
3223  this->getPartPosition(uiPUIdx, xP, yP, nPSW, nPSH);
3224
3225  Int iCount = 0;
3226
3227  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB;
3228  PartSize cCurPS = getPartitionSize( uiAbsPartIdx );
3229  deriveLeftRightTopIdxGeneral( uiAbsPartIdx, uiPUIdx, uiPartIdxLT, uiPartIdxRT );
3230  deriveLeftBottomIdxGeneral  ( uiAbsPartIdx, uiPUIdx, uiPartIdxLB );
3231#if H_3D_IV_MERGE
3232  Bool ivMvPredFlag   = getSlice()->getVPS()->getIvMvPredFlag( getSlice()->getLayerIdInVps() );
3233
3234  //===== add merge with predicted depth maps =====
3235#if QC_INRIA_MTK_MRG_E0126
3236  TComMv acPdmMv         [8];
3237  Int aiPdmRefIdx        [8] = {-1, -1, -1, -1, -1, -1, -1, -1};
3238  Int iPosDmv                = -1;
3239#else
3240  TComMv  acPdmMv       [4];
3241  Int     aiPdmRefIdx   [4] = {-1, -1, -1, -1};
3242#endif
3243  Bool    bLeftAvai         = false;
3244  Int     iPosLeftAbove[2]  = {-1, -1};
3245
3246
3247  DisInfo cDisInfo;
3248
3249  cDisInfo.bDV = getDvInfo(uiAbsPartIdx).bDV;
3250#if H_3D_NBDV_REF
3251  cDisInfo.m_acDoNBDV = getDvInfo(uiAbsPartIdx).m_acDoNBDV;
3252#endif //H_3D_NBDV_REF
3253  cDisInfo.m_acNBDV = getDvInfo(uiAbsPartIdx).m_acNBDV;
3254  cDisInfo.m_aVIdxCan = getDvInfo(uiAbsPartIdx).m_aVIdxCan;
3255
3256  if( m_pcSlice->getIsDepth())
3257  {
3258    UInt uiPartIdxCenter;
3259    xDeriveCenterIdx( uiPUIdx, uiPartIdxCenter );   
3260    TComDataCU *pcTextureCU = m_pcSlice->getTexturePic()->getCU( getAddr() );
3261 
3262    if ( pcTextureCU && !pcTextureCU->isIntra( uiPartIdxCenter ) )
3263    {
3264#if MTK_TEXTURE_MRGCAND_BUGFIX_E0182
3265      pcTextureCU->getMvField( pcTextureCU, uiPartIdxCenter, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3266      Int iValidDepRef = getPic()->isTextRefValid( REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1].getRefIdx() );
3267      if( (pcMvFieldNeighbours[iCount<<1].getRefIdx()>=0) && ( iValidDepRef >= 0 ) )
3268      {
3269        TComMv cMvPred = pcMvFieldNeighbours[iCount<<1].getMv();
3270        const TComMv cAdd( 1 << ( 2 - 1 ), 1 << ( 2 - 1 ) );
3271        cMvPred+=cAdd;
3272        cMvPred>>=2;
3273        clipMv(cMvPred);
3274        pcMvFieldNeighbours[iCount<<1].setMvField(cMvPred,iValidDepRef);
3275      }
3276
3277      if ( getSlice()->isInterB() )
3278      {
3279        pcTextureCU->getMvField( pcTextureCU, uiPartIdxCenter, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3280        iValidDepRef = getPic()->isTextRefValid( REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1].getRefIdx() );
3281        if( (pcMvFieldNeighbours[(iCount<<1)+1].getRefIdx()>=0) && ( iValidDepRef >= 0) )
3282        {
3283          TComMv cMvPred = pcMvFieldNeighbours[(iCount<<1)+1].getMv();
3284          const TComMv cAdd( 1 << ( 2 - 1 ), 1 << ( 2 - 1 ) );
3285          cMvPred+=cAdd;
3286          cMvPred>>=2;
3287          clipMv(cMvPred);
3288          pcMvFieldNeighbours[(iCount<<1)+1].setMvField(cMvPred,iValidDepRef);
3289        }
3290      }
3291
3292      puhInterDirNeighbours[iCount] = (pcMvFieldNeighbours[iCount<<1].getRefIdx()>=0)?1:0;
3293      puhInterDirNeighbours[iCount] += (pcMvFieldNeighbours[(iCount<<1)+1].getRefIdx()>=0)?2:0;
3294
3295      if( puhInterDirNeighbours[iCount] != 0 )
3296      {
3297        abCandIsInter[iCount] = true;
3298        if ( mrgCandIdx == iCount )
3299        {
3300          return;
3301        }
3302        iCount ++;
3303      }
3304#else
3305      abCandIsInter[iCount] = true;     
3306      puhInterDirNeighbours[iCount] = pcTextureCU->getInterDir( uiPartIdxCenter );
3307      if( ( puhInterDirNeighbours[iCount] & 1 ) == 1 )
3308      {
3309        pcTextureCU->getMvField( pcTextureCU, uiPartIdxCenter, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3310        TComMv cMvPred = pcMvFieldNeighbours[iCount<<1].getMv();
3311
3312#if H_3D_IC
3313        const TComMv cAdd( 1 << ( 2 - 1 ), 1 << ( 2 - 1 ) );
3314        cMvPred+=cAdd;
3315        cMvPred>>=2;
3316        clipMv(cMvPred);
3317#endif
3318        //pcMvFieldNeighbours[iCount<<1].setMvField(cMvPred,pcMvFieldNeighbours[iCount<<1].getRefIdx());
3319#if H_3D //Notes from QC: for BVSP coded blocks, the reference index shall not be equal to -1 due to the adoption of JCT3V-D0191
3320        pcMvFieldNeighbours[iCount<<1].setMvField(cMvPred,pcMvFieldNeighbours[iCount<<1].getRefIdx());
3321#endif
3322      }
3323     
3324      if ( getSlice()->isInterB() )
3325      {
3326        if( ( puhInterDirNeighbours[iCount] & 2 ) == 2 )
3327        {
3328          pcTextureCU->getMvField( pcTextureCU, uiPartIdxCenter, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3329          TComMv cMvPred = pcMvFieldNeighbours[(iCount<<1)+1].getMv();
3330#if H_3D_IC
3331          const TComMv cAdd( 1 << ( 2 - 1 ), 1 << ( 2 - 1 ) );
3332          cMvPred+=cAdd;
3333          cMvPred>>=2;
3334          clipMv(cMvPred);
3335#endif
3336          pcMvFieldNeighbours[(iCount<<1)+1].setMvField(cMvPred,pcMvFieldNeighbours[(iCount<<1)+1].getRefIdx());
3337        }
3338      }
3339#if H_3D_NBDV
3340      pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3341      pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3342#endif
3343      if ( mrgCandIdx == iCount )
3344      {
3345        return;
3346      }
3347      iCount ++;
3348#endif//Bug fix
3349    }
3350  }
3351
3352#if QC_INRIA_MTK_MRG_E0126
3353  Int iPdmDir[4] = {0, 0, 0, 0};
3354#else
3355  Int iPdmDir[2] = {0, 0};
3356#endif
3357 
3358  if ( ivMvPredFlag )
3359  {
3360    getInterViewMergeCands(uiPUIdx, aiPdmRefIdx, acPdmMv, &cDisInfo, iPdmDir );
3361  } 
3362   
3363  Int iPdmInterDir;
3364
3365  if( iPdmDir[0] )
3366  {
3367    abCandIsInter        [ iCount ] = true;
3368    puhInterDirNeighbours[ iCount ] = iPdmDir[0];
3369    iPdmInterDir                    = iPdmDir[0];
3370
3371    if( ( iPdmInterDir & 1 ) == 1 )
3372    {
3373      pcMvFieldNeighbours[ iCount<<1    ].setMvField( acPdmMv[ 0 ], aiPdmRefIdx[ 0 ] );
3374    }
3375    if( ( iPdmInterDir & 2 ) == 2 )
3376    {
3377      pcMvFieldNeighbours[(iCount<<1)+1 ].setMvField( acPdmMv[ 1 ], aiPdmRefIdx[ 1 ] );
3378    }
3379
3380    if ( mrgCandIdx == iCount )
3381    {
3382      return;
3383    }
3384    iCount ++;
3385  } 
3386  // early termination
3387  if (iCount == getSlice()->getMaxNumMergeCand()) 
3388  {
3389    return;
3390  }
3391#endif
3392
3393  //left
3394  UInt uiLeftPartIdx = 0;
3395  TComDataCU* pcCULeft = 0;
3396  pcCULeft = getPULeft( uiLeftPartIdx, uiPartIdxLB );
3397  Bool isAvailableA1 = pcCULeft &&
3398  pcCULeft->isDiffMER(xP -1, yP+nPSH-1, xP, yP) &&
3399  !( uiPUIdx == 1 && (cCurPS == SIZE_Nx2N || cCurPS == SIZE_nLx2N || cCurPS == SIZE_nRx2N) ) &&
3400  !pcCULeft->isIntra( uiLeftPartIdx ) ;
3401  if ( isAvailableA1 )
3402  {
3403    abCandIsInter[iCount] = true;
3404    // get Inter Dir
3405    puhInterDirNeighbours[iCount] = pcCULeft->getInterDir( uiLeftPartIdx );
3406    // get Mv from Left
3407    pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3408    if ( getSlice()->isInterB() )
3409    {
3410      pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3411    }
3412#if H_3D_IV_MERGE
3413    Bool bRemoveSpa = false; //pruning to inter-view candidates
3414    Int  iCnloop    = iCount - 1;
3415    for(; iCnloop >= 0; iCnloop --)
3416    {
3417      if(puhInterDirNeighbours[iCount] == puhInterDirNeighbours[iCnloop] && pcMvFieldNeighbours[iCnloop<<1]==pcMvFieldNeighbours[(iCount<<1)] && pcMvFieldNeighbours[(iCnloop<<1)+1]==pcMvFieldNeighbours[(iCount<<1)+1])
3418      {
3419        bRemoveSpa                      = true;
3420        abCandIsInter        [ iCount ] = false;
3421
3422        //reset to the default value for MC
3423        puhInterDirNeighbours[iCount]   = 0;
3424        pcMvFieldNeighbours[iCount<<1].setMvField( cZeroMv, NOT_VALID );
3425        pcMvFieldNeighbours[(iCount<<1)+1].setMvField( cZeroMv, NOT_VALID );
3426        break;
3427      }
3428    }
3429    if(!bRemoveSpa)
3430    {
3431      bLeftAvai = true;
3432      iPosLeftAbove[0] = iCount;
3433#if H_3D_NBDV
3434      pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3435      pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3436#endif
3437#if H_3D_VSP
3438      if (pcCULeft->getVSPFlag(uiLeftPartIdx) == 1)
3439#if MTK_VSP_FIX_E0172
3440      {
3441#endif
3442        vspFlag[iCount] = 1;
3443#if MTK_VSP_FIX_E0172
3444        vspDir[iCount] = pcCULeft->getVSPDir( uiLeftPartIdx );
3445      }
3446#endif
3447#endif
3448      if ( mrgCandIdx == iCount )
3449      {
3450        return;
3451      }
3452      iCount ++;
3453    }
3454#else
3455    if ( mrgCandIdx == iCount )
3456    {
3457      return;
3458    }
3459    iCount ++;
3460#endif
3461  }
3462 
3463  // early termination
3464  if (iCount == getSlice()->getMaxNumMergeCand()) 
3465  {
3466    return;
3467  }
3468  // above
3469  UInt uiAbovePartIdx = 0;
3470  TComDataCU* pcCUAbove = 0;
3471  pcCUAbove = getPUAbove( uiAbovePartIdx, uiPartIdxRT );
3472  Bool isAvailableB1 = pcCUAbove &&
3473  pcCUAbove->isDiffMER(xP+nPSW-1, yP-1, xP, yP) &&
3474  !( uiPUIdx == 1 && (cCurPS == SIZE_2NxN || cCurPS == SIZE_2NxnU || cCurPS == SIZE_2NxnD) ) &&
3475  !pcCUAbove->isIntra( uiAbovePartIdx );
3476  if ( isAvailableB1 && (!isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAbove, uiAbovePartIdx ) ) )
3477  {
3478    abCandIsInter[iCount] = true;
3479    // get Inter Dir
3480    puhInterDirNeighbours[iCount] = pcCUAbove->getInterDir( uiAbovePartIdx );
3481    // get Mv from Left
3482    pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3483    if ( getSlice()->isInterB() )
3484    {
3485      pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3486    }
3487#if H_3D_IV_MERGE
3488    Bool bRemoveSpa = false; //pruning to inter-view candidates
3489    Int  iCnloop    = bLeftAvai? (iCount-2): (iCount-1);
3490    for(; iCnloop >= 0; iCnloop --)
3491    {
3492      if(puhInterDirNeighbours[iCount] == puhInterDirNeighbours[iCnloop] && pcMvFieldNeighbours[iCnloop<<1]==pcMvFieldNeighbours[(iCount<<1)] && pcMvFieldNeighbours[(iCnloop<<1)+1]==pcMvFieldNeighbours[(iCount<<1)+1])
3493      {
3494        bRemoveSpa                      = true;
3495        abCandIsInter        [ iCount ] = false;
3496
3497        //reset to the default value for MC
3498        puhInterDirNeighbours[iCount]   = 0;
3499
3500        pcMvFieldNeighbours[iCount<<1].setMvField( cZeroMv, NOT_VALID );
3501        pcMvFieldNeighbours[(iCount<<1)+1].setMvField( cZeroMv, NOT_VALID );
3502        break;
3503      }
3504    }
3505    if(!bRemoveSpa)
3506    {
3507      iPosLeftAbove[1] = iCount;
3508#if H_3D_NBDV
3509      pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3510      pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3511#endif
3512#if H_3D_VSP
3513      if (pcCUAbove->getVSPFlag(uiAbovePartIdx) == 1)
3514#if MTK_VSP_FIX_E0172
3515      {
3516#endif
3517        vspFlag[iCount] = 1;
3518#if MTK_VSP_FIX_E0172
3519        vspDir[iCount] = pcCUAbove->getVSPDir( uiAbovePartIdx );
3520      }
3521#endif
3522#endif
3523      if ( mrgCandIdx == iCount )
3524      {
3525        return;
3526      }
3527      iCount ++;
3528    }
3529#else
3530    if ( mrgCandIdx == iCount )
3531    {
3532      return;
3533    }
3534    iCount ++;
3535#endif
3536  }
3537  // early termination
3538  if (iCount == getSlice()->getMaxNumMergeCand()) 
3539  {
3540    return;
3541  }
3542
3543  // above right
3544  UInt uiAboveRightPartIdx = 0;
3545  TComDataCU* pcCUAboveRight = 0;
3546  pcCUAboveRight = getPUAboveRight( uiAboveRightPartIdx, uiPartIdxRT );
3547  Bool isAvailableB0 = pcCUAboveRight &&
3548  pcCUAboveRight->isDiffMER(xP+nPSW, yP-1, xP, yP) &&
3549  !pcCUAboveRight->isIntra( uiAboveRightPartIdx );
3550  if ( isAvailableB0 && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveRight, uiAboveRightPartIdx ) ) )
3551  {
3552    abCandIsInter[iCount] = true;
3553    // get Inter Dir
3554    puhInterDirNeighbours[iCount] = pcCUAboveRight->getInterDir( uiAboveRightPartIdx );
3555    // get Mv from Left
3556    pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3557    if ( getSlice()->isInterB() )
3558    {
3559      pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3560    }
3561#if H_3D_NBDV
3562    pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3563    pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3564#endif
3565#if H_3D_VSP
3566    if (pcCUAboveRight->getVSPFlag(uiAboveRightPartIdx) == 1)
3567#if MTK_VSP_FIX_E0172
3568    {
3569#endif
3570      vspFlag[iCount] = 1;
3571#if MTK_VSP_FIX_E0172
3572      vspDir[iCount] = pcCUAboveRight->getVSPDir( uiAboveRightPartIdx);
3573    }
3574#endif
3575#endif
3576    if ( mrgCandIdx == iCount )
3577    {
3578      return;
3579    }
3580    iCount ++;
3581  }
3582  // early termination
3583  if (iCount == getSlice()->getMaxNumMergeCand()) 
3584  {
3585    return;
3586  }
3587
3588#if H_3D_IV_MERGE
3589  if( iPdmDir[1] )
3590  {
3591    assert(iCount < getSlice()->getMaxNumMergeCand());
3592    abCandIsInter        [ iCount ] = true;
3593    puhInterDirNeighbours[ iCount ] = iPdmDir[1];
3594    if( ( iPdmDir[1] & 1 ) == 1 )
3595    {
3596      pcMvFieldNeighbours[ iCount<<1    ].setMvField( acPdmMv[ 2 ], aiPdmRefIdx[ 2 ] );
3597    }
3598    if( ( iPdmDir[1] & 2 ) == 2 )
3599    {
3600      pcMvFieldNeighbours[(iCount<<1)+1 ].setMvField( acPdmMv[ 3 ], aiPdmRefIdx[ 3 ] );
3601    }
3602
3603    Bool bRemoveSpa = false; //pruning to A1, B1
3604    for(Int i = 0; i < 2; i ++)
3605    {
3606      Int iCnloop = iPosLeftAbove[i];
3607      if(iCnloop == -1) 
3608        continue;
3609      if(puhInterDirNeighbours[iCount] == puhInterDirNeighbours[iCnloop] && pcMvFieldNeighbours[iCnloop<<1]==pcMvFieldNeighbours[(iCount<<1)] && pcMvFieldNeighbours[(iCnloop<<1)+1]==pcMvFieldNeighbours[(iCount<<1)+1])
3610      {
3611        bRemoveSpa                      = true;
3612        abCandIsInter        [ iCount ] = false;
3613        //reset to the default value for MC
3614        puhInterDirNeighbours[iCount]   = 0;
3615        pcMvFieldNeighbours[iCount<<1].setMvField( cZeroMv, NOT_VALID );
3616        pcMvFieldNeighbours[(iCount<<1)+1].setMvField( cZeroMv, NOT_VALID );
3617        break;
3618      }     
3619    }
3620    if(!bRemoveSpa)
3621    {
3622#if H_3D_NBDV
3623      pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3624      pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3625#endif
3626#if QC_INRIA_MTK_MRG_E0126
3627      iPosDmv  = iCount;
3628#endif
3629      if ( mrgCandIdx == iCount )
3630        return;
3631      iCount ++;
3632
3633      // early termination
3634      if (iCount == getSlice()->getMaxNumMergeCand()) 
3635      {
3636        return;
3637      }
3638    }
3639  } 
3640#endif
3641
3642#if H_3D_VSP
3643#if MTK_VSP_FIX_E0172
3644  if ( xAddVspCand( H_3D_VSP_POSITION, mrgCandIdx, &cDisInfo, iCount, abCandIsInter, pcMvFieldNeighbours, puhInterDirNeighbours, vspFlag, vspDir ) )
3645#else
3646  if ( xAddVspCand( H_3D_VSP_POSITION, mrgCandIdx, &cDisInfo, iCount, abCandIsInter, pcMvFieldNeighbours, puhInterDirNeighbours, vspFlag ) )
3647#endif
3648    return;
3649  // early termination
3650  if (iCount == getSlice()->getMaxNumMergeCand())
3651    return;
3652#endif
3653
3654  //left bottom
3655  UInt uiLeftBottomPartIdx = 0;
3656  TComDataCU* pcCULeftBottom = 0;
3657  pcCULeftBottom = this->getPUBelowLeft( uiLeftBottomPartIdx, uiPartIdxLB );
3658  Bool isAvailableA0 = pcCULeftBottom &&
3659  pcCULeftBottom->isDiffMER(xP-1, yP+nPSH, xP, yP) &&
3660  !pcCULeftBottom->isIntra( uiLeftBottomPartIdx ) ;
3661  if ( isAvailableA0 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCULeftBottom, uiLeftBottomPartIdx ) ) )
3662  {
3663    abCandIsInter[iCount] = true;
3664    // get Inter Dir
3665    puhInterDirNeighbours[iCount] = pcCULeftBottom->getInterDir( uiLeftBottomPartIdx );
3666    // get Mv from Left
3667    pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3668    if ( getSlice()->isInterB() )
3669    {
3670      pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3671    }
3672#if H_3D_NBDV
3673    pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3674    pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3675#endif
3676#if H_3D_VSP
3677    if (pcCULeftBottom->getVSPFlag(uiLeftBottomPartIdx) == 1)
3678#if MTK_VSP_FIX_E0172
3679    {
3680#endif
3681      vspFlag[iCount] = 1;
3682#if MTK_VSP_FIX_E0172
3683      vspDir[iCount] = pcCULeftBottom->getVSPDir( uiLeftBottomPartIdx);
3684    }
3685#endif
3686#endif
3687    if ( mrgCandIdx == iCount )
3688    {
3689      return;
3690    }
3691    iCount ++;
3692  }
3693  // early termination
3694  if (iCount == getSlice()->getMaxNumMergeCand()) 
3695  {
3696    return;
3697  }
3698  // above left
3699  if( iCount < 4 )
3700  {
3701    UInt uiAboveLeftPartIdx = 0;
3702    TComDataCU* pcCUAboveLeft = 0;
3703    pcCUAboveLeft = getPUAboveLeft( uiAboveLeftPartIdx, uiAbsPartAddr );
3704    Bool isAvailableB2 = pcCUAboveLeft &&
3705    pcCUAboveLeft->isDiffMER(xP-1, yP-1, xP, yP) &&
3706    !pcCUAboveLeft->isIntra( uiAboveLeftPartIdx );
3707    if ( isAvailableB2 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) )
3708        && ( !isAvailableB1 || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) ) )
3709    {
3710      abCandIsInter[iCount] = true;
3711      // get Inter Dir
3712      puhInterDirNeighbours[iCount] = pcCUAboveLeft->getInterDir( uiAboveLeftPartIdx );
3713      // get Mv from Left
3714      pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
3715      if ( getSlice()->isInterB() )
3716      {
3717        pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
3718      }
3719#if H_3D_NBDV
3720      pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3721      pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3722#endif
3723#if H_3D_VSP
3724      if (pcCUAboveLeft->getVSPFlag(uiAboveLeftPartIdx) == 1)
3725#if MTK_VSP_FIX_E0172
3726      {
3727#endif
3728        vspFlag[iCount] = 1;
3729#if MTK_VSP_FIX_E0172
3730        vspDir[iCount] = pcCUAboveLeft->getVSPDir( uiAboveLeftPartIdx);
3731      }
3732#endif
3733#endif
3734      if ( mrgCandIdx == iCount )
3735      {
3736        return;
3737      }
3738      iCount ++;
3739    }
3740  }
3741  // early termination
3742  if (iCount == getSlice()->getMaxNumMergeCand()) 
3743  {
3744    return;
3745  }
3746#if QC_INRIA_MTK_MRG_E0126
3747  if(  ivMvPredFlag  ) 
3748  {
3749    if(xAddIvMRGCand( mrgCandIdx,  iCount, abCandIsInter, pcMvFieldNeighbours, puhInterDirNeighbours, iPdmDir, acPdmMv, aiPdmRefIdx, iPosDmv, vspFlag))
3750    {
3751      return;
3752    }
3753    //early termination
3754    if (iCount == getSlice()->getMaxNumMergeCand()) 
3755    {
3756      return;
3757    }
3758  }
3759#endif
3760  if ( getSlice()->getEnableTMVPFlag())
3761  {
3762    //>> MTK colocated-RightBottom
3763    UInt uiPartIdxRB;
3764
3765    deriveRightBottomIdx( uiPUIdx, uiPartIdxRB ); 
3766
3767    UInt uiAbsPartIdxTmp = g_auiZscanToRaster[uiPartIdxRB];
3768    UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
3769
3770    TComMv cColMv;
3771    Int iRefIdx;
3772    Int uiLCUIdx = -1;
3773
3774    if      ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
3775    {
3776    }
3777    else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxTmp] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
3778    {
3779    }
3780    else
3781    {
3782      if ( ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
3783        ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
3784      {
3785        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + uiNumPartInCUWidth + 1 ];
3786        uiLCUIdx = getAddr();
3787      }
3788      else if ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
3789      {
3790        uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdxTmp + uiNumPartInCUWidth + 1) % m_pcPic->getNumPartInCU() ];
3791      }
3792      else if ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
3793      {
3794        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + 1 ];
3795        uiLCUIdx = getAddr() + 1;
3796      }
3797      else //is the right bottom corner of LCU                       
3798      {
3799        uiAbsPartAddr = 0;
3800      }
3801    }
3802   
3803   
3804    iRefIdx = 0;
3805    Bool bExistMV = false;
3806    UInt uiPartIdxCenter;
3807    UInt uiCurLCUIdx = getAddr();
3808    Int dir = 0;
3809    UInt uiArrayAddr = iCount;
3810    xDeriveCenterIdx( uiPUIdx, uiPartIdxCenter );
3811    bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_0, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx );
3812    if( bExistMV == false )
3813    {
3814      bExistMV = xGetColMVP( REF_PIC_LIST_0, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
3815    }
3816    if( bExistMV )
3817    {
3818      dir |= 1;
3819      pcMvFieldNeighbours[ 2 * uiArrayAddr ].setMvField( cColMv, iRefIdx );
3820    }
3821
3822    if ( getSlice()->isInterB() )
3823    {
3824#if H_3D_TMVP
3825      iRefIdx = 0;
3826#endif
3827      bExistMV = uiLCUIdx >= 0 && xGetColMVP( REF_PIC_LIST_1, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx);
3828      if( bExistMV == false )
3829      {
3830        bExistMV = xGetColMVP( REF_PIC_LIST_1, uiCurLCUIdx, uiPartIdxCenter, cColMv, iRefIdx );
3831      }
3832      if( bExistMV )
3833      {
3834        dir |= 2;
3835        pcMvFieldNeighbours[ 2 * uiArrayAddr + 1 ].setMvField( cColMv, iRefIdx );
3836      }
3837    }
3838   
3839    if (dir != 0)
3840    {
3841      puhInterDirNeighbours[uiArrayAddr] = dir;
3842      abCandIsInter[uiArrayAddr] = true;
3843#if H_3D_NBDV
3844      pcMvFieldNeighbours[iCount<<1    ].getMv().setIDVFlag (false);
3845      pcMvFieldNeighbours[(iCount<<1)+1].getMv().setIDVFlag (false);
3846#endif
3847      if ( mrgCandIdx == iCount )
3848      {
3849        return;
3850      }
3851      iCount++;
3852    }
3853  }
3854  // early termination
3855  if (iCount == getSlice()->getMaxNumMergeCand()) 
3856  {
3857    return;
3858  }
3859  UInt uiArrayAddr = iCount;
3860  UInt uiCutoff = uiArrayAddr;
3861   
3862  if ( getSlice()->isInterB())
3863  {
3864#if H_3D_IV_MERGE
3865    UInt uiPriorityList0[20] = {0 , 1, 0, 2, 1, 2, 0, 3, 1, 3, 2, 3,    0, 4, 1, 4, 2, 4, 3, 4 };
3866    UInt uiPriorityList1[20] = {1 , 0, 2, 0, 2, 1, 3, 0, 3, 1, 3, 2,    4, 0, 4, 1, 4, 2, 4, 3 };
3867#else
3868    UInt uiPriorityList0[12] = {0 , 1, 0, 2, 1, 2, 0, 3, 1, 3, 2, 3};
3869    UInt uiPriorityList1[12] = {1 , 0, 2, 0, 2, 1, 3, 0, 3, 1, 3, 2};
3870#endif
3871
3872    for (Int idx=0; idx<uiCutoff*(uiCutoff-1) && uiArrayAddr!= getSlice()->getMaxNumMergeCand(); idx++)
3873    {
3874      Int i = uiPriorityList0[idx]; Int j = uiPriorityList1[idx];
3875#if H_3D_VSP
3876      Bool bValid = true;
3877      if ( vspFlag[i] == 1 || vspFlag[j] == 1 )
3878        bValid = false;
3879      if( !m_pcSlice->getVPS()->getViewSynthesisPredFlag( m_pcSlice->getLayerIdInVps() ) )
3880        assert(bValid == true);
3881#endif
3882#if H_3D_VSP
3883      if (abCandIsInter[i] && abCandIsInter[j] && (puhInterDirNeighbours[i]&0x1) && (puhInterDirNeighbours[j]&0x2) && bValid)
3884#else
3885      if (abCandIsInter[i] && abCandIsInter[j]&& (puhInterDirNeighbours[i]&0x1)&&(puhInterDirNeighbours[j]&0x2))
3886#endif
3887      {
3888        abCandIsInter[uiArrayAddr] = true;
3889        puhInterDirNeighbours[uiArrayAddr] = 3;
3890
3891        // get Mv from cand[i] and cand[j]
3892        pcMvFieldNeighbours[uiArrayAddr << 1].setMvField(pcMvFieldNeighbours[i<<1].getMv(), pcMvFieldNeighbours[i<<1].getRefIdx());
3893        pcMvFieldNeighbours[( uiArrayAddr << 1 ) + 1].setMvField(pcMvFieldNeighbours[(j<<1)+1].getMv(), pcMvFieldNeighbours[(j<<1)+1].getRefIdx());
3894
3895        Int iRefPOCL0 = m_pcSlice->getRefPOC( REF_PIC_LIST_0, pcMvFieldNeighbours[(uiArrayAddr<<1)].getRefIdx() );
3896        Int iRefPOCL1 = m_pcSlice->getRefPOC( REF_PIC_LIST_1, pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getRefIdx() );
3897        if (iRefPOCL0 == iRefPOCL1 && pcMvFieldNeighbours[(uiArrayAddr<<1)].getMv() == pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getMv())
3898        {
3899          abCandIsInter[uiArrayAddr] = false;
3900        }
3901        else
3902        {
3903          uiArrayAddr++;
3904        }
3905      }
3906    }
3907  }
3908  // early termination
3909  if (uiArrayAddr == getSlice()->getMaxNumMergeCand()) 
3910  {
3911    return;
3912  }
3913  Int iNumRefIdx = (getSlice()->isInterB()) ? min(m_pcSlice->getNumRefIdx(REF_PIC_LIST_0), m_pcSlice->getNumRefIdx(REF_PIC_LIST_1)) : m_pcSlice->getNumRefIdx(REF_PIC_LIST_0);
3914  Int r = 0;
3915  Int refcnt = 0;
3916  while (uiArrayAddr < getSlice()->getMaxNumMergeCand())
3917  {
3918    abCandIsInter[uiArrayAddr] = true;
3919    puhInterDirNeighbours[uiArrayAddr] = 1;
3920    pcMvFieldNeighbours[uiArrayAddr << 1].setMvField( TComMv(0, 0), r);
3921
3922    if ( getSlice()->isInterB() )
3923    {
3924      puhInterDirNeighbours[uiArrayAddr] = 3;
3925      pcMvFieldNeighbours[(uiArrayAddr << 1) + 1].setMvField(TComMv(0, 0), r);
3926    }
3927    uiArrayAddr++;
3928    if ( refcnt == iNumRefIdx - 1 )
3929    {
3930      r = 0;
3931    }
3932    else
3933    {
3934      ++r;
3935      ++refcnt;
3936    }
3937  }
3938
3939  numValidMergeCand = uiArrayAddr;
3940}
3941
3942/** Check whether the current PU and a spatial neighboring PU are in a same ME region.
3943 * \param xN, xN   location of the upper-left corner pixel of a neighboring PU
3944 * \param xP, yP   location of the upper-left corner pixel of the current PU
3945 * \returns Bool
3946 */
3947Bool TComDataCU::isDiffMER(Int xN, Int yN, Int xP, Int yP)
3948{
3949
3950  UInt plevel = this->getSlice()->getPPS()->getLog2ParallelMergeLevelMinus2() + 2;
3951  if ((xN>>plevel)!= (xP>>plevel))
3952  {
3953    return true;
3954  }
3955  if ((yN>>plevel)!= (yP>>plevel))
3956  {
3957    return true;
3958  }
3959  return false;
3960}
3961/** calculate the location of upper-left corner pixel and size of the current PU.
3962 * \param partIdx  PU index within a CU
3963 * \param xP, yP   location of the upper-left corner pixel of the current PU
3964 * \param PSW, nPSH    size of the curren PU
3965 * \returns Void
3966 */
3967Void TComDataCU::getPartPosition( UInt partIdx, Int& xP, Int& yP, Int& nPSW, Int& nPSH)
3968{
3969  UInt col = m_uiCUPelX;
3970  UInt row = m_uiCUPelY;
3971
3972  switch ( m_pePartSize[0] )
3973  {
3974  case SIZE_2NxN:
3975    nPSW = getWidth(0);     
3976    nPSH = getHeight(0) >> 1; 
3977    xP   = col;
3978    yP   = (partIdx ==0)? row: row + nPSH;
3979    break;
3980  case SIZE_Nx2N:
3981    nPSW = getWidth(0) >> 1; 
3982    nPSH = getHeight(0);     
3983    xP   = (partIdx ==0)? col: col + nPSW;
3984    yP   = row;
3985    break;
3986  case SIZE_NxN:
3987    nPSW = getWidth(0) >> 1; 
3988    nPSH = getHeight(0) >> 1; 
3989    xP   = col + (partIdx&0x1)*nPSW;
3990    yP   = row + (partIdx>>1)*nPSH;
3991    break;
3992  case SIZE_2NxnU:
3993    nPSW = getWidth(0);
3994    nPSH = ( partIdx == 0 ) ?  getHeight(0) >> 2 : ( getHeight(0) >> 2 ) + ( getHeight(0) >> 1 );
3995    xP   = col;
3996    yP   = (partIdx ==0)? row: row + getHeight(0) - nPSH;
3997
3998    break;
3999  case SIZE_2NxnD:
4000    nPSW = getWidth(0);
4001    nPSH = ( partIdx == 0 ) ?  ( getHeight(0) >> 2 ) + ( getHeight(0) >> 1 ) : getHeight(0) >> 2;
4002    xP   = col;
4003    yP   = (partIdx ==0)? row: row + getHeight(0) - nPSH;
4004    break;
4005  case SIZE_nLx2N:
4006    nPSW = ( partIdx == 0 ) ? getWidth(0) >> 2 : ( getWidth(0) >> 2 ) + ( getWidth(0) >> 1 );
4007    nPSH = getHeight(0);
4008    xP   = (partIdx ==0)? col: col + getWidth(0) - nPSW;
4009    yP   = row;
4010    break;
4011  case SIZE_nRx2N:
4012    nPSW = ( partIdx == 0 ) ? ( getWidth(0) >> 2 ) + ( getWidth(0) >> 1 ) : getWidth(0) >> 2;
4013    nPSH = getHeight(0);
4014    xP   = (partIdx ==0)? col: col + getWidth(0) - nPSW;
4015    yP   = row;
4016    break;
4017  default:
4018    assert ( m_pePartSize[0] == SIZE_2Nx2N );
4019    nPSW = getWidth(0);     
4020    nPSH = getHeight(0);     
4021    xP   = col ;
4022    yP   = row ;
4023
4024    break;
4025  }
4026}
4027
4028/** Constructs a list of candidates for AMVP
4029 * \param uiPartIdx
4030 * \param uiPartAddr
4031 * \param eRefPicList
4032 * \param iRefIdx
4033 * \param pInfo
4034 */
4035Void TComDataCU::fillMvpCand ( UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, Int iRefIdx, AMVPInfo* pInfo )
4036{
4037  TComMv cMvPred;
4038  Bool bAddedSmvp = false;
4039
4040  pInfo->iN = 0; 
4041  if (iRefIdx < 0)
4042  {
4043    return;
4044  }
4045 
4046  //-- Get Spatial MV
4047  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB;
4048  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
4049  Bool bAdded = false;
4050 
4051  deriveLeftRightTopIdx( uiPartIdx, uiPartIdxLT, uiPartIdxRT );
4052  deriveLeftBottomIdx( uiPartIdx, uiPartIdxLB );
4053 
4054  TComDataCU* tmpCU = NULL;
4055  UInt idx;
4056  tmpCU = getPUBelowLeft(idx, uiPartIdxLB);
4057  bAddedSmvp = (tmpCU != NULL) && (tmpCU->getPredictionMode(idx) != MODE_INTRA);
4058
4059  if (!bAddedSmvp)
4060  {
4061    tmpCU = getPULeft(idx, uiPartIdxLB);
4062    bAddedSmvp = (tmpCU != NULL) && (tmpCU->getPredictionMode(idx) != MODE_INTRA);
4063  }
4064
4065  // Left predictor search
4066  bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_BELOW_LEFT);
4067  if (!bAdded) 
4068  {
4069    bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_LEFT );
4070  }
4071 
4072  if(!bAdded)
4073  {
4074    bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_BELOW_LEFT);
4075    if (!bAdded) 
4076    {
4077      xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_LEFT );
4078    }
4079  }
4080  // Above predictor search
4081  bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE_RIGHT);
4082
4083  if (!bAdded) 
4084  {
4085    bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE);
4086  }
4087
4088  if(!bAdded)
4089  {
4090    xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLT, MD_ABOVE_LEFT);
4091  }
4092  bAdded = bAddedSmvp;
4093  if (pInfo->iN==2) bAdded = true;
4094
4095  if(!bAdded)
4096  {
4097    bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE_RIGHT);
4098    if (!bAdded) 
4099    {
4100      bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE);
4101    }
4102
4103    if(!bAdded)
4104    {
4105      xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLT, MD_ABOVE_LEFT);
4106    }
4107  }
4108 
4109  if ( pInfo->iN == 2 )
4110  {
4111    if ( pInfo->m_acMvCand[ 0 ] == pInfo->m_acMvCand[ 1 ] )
4112    {
4113      pInfo->iN = 1;
4114    }
4115  }
4116
4117  if ( getSlice()->getEnableTMVPFlag() )
4118  {
4119    // Get Temporal Motion Predictor
4120    Int iRefIdx_Col = iRefIdx;
4121    TComMv cColMv;
4122    UInt uiPartIdxRB;
4123    UInt uiAbsPartIdx; 
4124    UInt uiAbsPartAddr;
4125
4126    deriveRightBottomIdx( uiPartIdx, uiPartIdxRB );
4127    uiAbsPartAddr = m_uiAbsIdxInLCU + uiPartAddr;
4128
4129    //----  co-located RightBottom Temporal Predictor (H) ---//
4130    uiAbsPartIdx = g_auiZscanToRaster[uiPartIdxRB];
4131    Int uiLCUIdx = -1;
4132    if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdx] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
4133    {
4134    }
4135    else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdx] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
4136    {
4137    }
4138    else
4139    {
4140      if ( ( uiAbsPartIdx % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
4141        ( uiAbsPartIdx / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
4142      {
4143        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdx + uiNumPartInCUWidth + 1 ];
4144        uiLCUIdx = getAddr();
4145      }
4146      else if ( uiAbsPartIdx % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
4147      {
4148        uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdx + uiNumPartInCUWidth + 1) % m_pcPic->getNumPartInCU() ];
4149      }
4150      else if ( uiAbsPartIdx / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
4151      {
4152        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdx + 1 ];
4153        uiLCUIdx = getAddr() + 1;
4154      }
4155      else //is the right bottom corner of LCU                       
4156      {
4157        uiAbsPartAddr = 0;
4158      }
4159    }
4160    if ( uiLCUIdx >= 0 && xGetColMVP( eRefPicList, uiLCUIdx, uiAbsPartAddr, cColMv, iRefIdx_Col
4161#if H_3D_TMVP
4162         , 0
4163#endif
4164    ) )
4165    {
4166      pInfo->m_acMvCand[pInfo->iN++] = cColMv;
4167    }
4168    else 
4169    {
4170      UInt uiPartIdxCenter;
4171      UInt uiCurLCUIdx = getAddr();
4172      xDeriveCenterIdx( uiPartIdx, uiPartIdxCenter );
4173      if (xGetColMVP( eRefPicList, uiCurLCUIdx, uiPartIdxCenter,  cColMv, iRefIdx_Col
4174#if H_3D_TMVP
4175         , 0
4176#endif
4177      ))
4178      {
4179        pInfo->m_acMvCand[pInfo->iN++] = cColMv;
4180      }
4181    }
4182    //----  co-located RightBottom Temporal Predictor  ---//
4183  }
4184
4185  if (pInfo->iN > AMVP_MAX_NUM_CANDS)
4186  {
4187    pInfo->iN = AMVP_MAX_NUM_CANDS;
4188  }
4189  while (pInfo->iN < AMVP_MAX_NUM_CANDS)
4190  {
4191      pInfo->m_acMvCand[pInfo->iN].set(0,0);
4192      pInfo->iN++;
4193  }
4194  return ;
4195}
4196
4197Bool TComDataCU::isBipredRestriction(UInt puIdx)
4198{
4199  Int width = 0;
4200  Int height = 0;
4201  UInt partAddr;
4202
4203  getPartIndexAndSize( puIdx, partAddr, width, height );
4204  if ( getWidth(0) == 8 && (width < 8 || height < 8) )
4205  {
4206    return true;
4207  }
4208  return false;
4209}
4210
4211Void TComDataCU::clipMv    (TComMv&  rcMv)
4212{
4213  Int  iMvShift = 2;
4214#if H_3D_IC
4215  if( getSlice()->getIsDepth() )
4216    iMvShift = 0;
4217#endif
4218  Int iOffset = 8;
4219  Int iHorMax = ( m_pcSlice->getSPS()->getPicWidthInLumaSamples() + iOffset - m_uiCUPelX - 1 ) << iMvShift;
4220  Int iHorMin = (       -(Int)g_uiMaxCUWidth - iOffset - (Int)m_uiCUPelX + 1 ) << iMvShift;
4221 
4222  Int iVerMax = ( m_pcSlice->getSPS()->getPicHeightInLumaSamples() + iOffset - m_uiCUPelY - 1 ) << iMvShift;
4223  Int iVerMin = (       -(Int)g_uiMaxCUHeight - iOffset - (Int)m_uiCUPelY + 1 ) << iMvShift;
4224 
4225  rcMv.setHor( min (iHorMax, max (iHorMin, rcMv.getHor())) );
4226  rcMv.setVer( min (iVerMax, max (iVerMin, rcMv.getVer())) );
4227}
4228
4229UInt TComDataCU::getIntraSizeIdx(UInt uiAbsPartIdx)
4230{
4231  UInt uiShift = ( m_pePartSize[uiAbsPartIdx]==SIZE_NxN ? 1 : 0 );
4232 
4233  UChar uiWidth = m_puhWidth[uiAbsPartIdx]>>uiShift;
4234  UInt  uiCnt = 0;
4235  while( uiWidth )
4236  {
4237    uiCnt++;
4238    uiWidth>>=1;
4239  }
4240  uiCnt-=2;
4241  return uiCnt > 6 ? 6 : uiCnt;
4242}
4243
4244Void TComDataCU::clearCbf( UInt uiIdx, TextType eType, UInt uiNumParts )
4245{
4246  ::memset( &m_puhCbf[g_aucConvertTxtTypeToIdx[eType]][uiIdx], 0, sizeof(UChar)*uiNumParts);
4247}
4248
4249/** Set a I_PCM flag for all sub-partitions of a partition.
4250 * \param bIpcmFlag I_PCM flag
4251 * \param uiAbsPartIdx patition index
4252 * \param uiDepth CU depth
4253 * \returns Void
4254 */
4255Void TComDataCU::setIPCMFlagSubParts  (Bool bIpcmFlag, UInt uiAbsPartIdx, UInt uiDepth)
4256{
4257  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
4258
4259  memset(m_pbIPCMFlag + uiAbsPartIdx, bIpcmFlag, sizeof(Bool)*uiCurrPartNumb );
4260}
4261
4262/** Test whether the current block is skipped
4263 * \param uiPartIdx Block index
4264 * \returns Flag indicating whether the block is skipped
4265 */
4266Bool TComDataCU::isSkipped( UInt uiPartIdx )
4267{
4268  return ( getSkipFlag( uiPartIdx ) );
4269}
4270
4271// ====================================================================================================================
4272// Protected member functions
4273// ====================================================================================================================
4274
4275Bool TComDataCU::xAddMVPCand( AMVPInfo* pInfo, RefPicList eRefPicList, Int iRefIdx, UInt uiPartUnitIdx, MVP_DIR eDir )
4276{
4277  TComDataCU* pcTmpCU = NULL;
4278  UInt uiIdx;
4279  switch( eDir )
4280  {
4281    case MD_LEFT:
4282    {
4283      pcTmpCU = getPULeft(uiIdx, uiPartUnitIdx);
4284      break;
4285    }
4286    case MD_ABOVE:
4287    {
4288      pcTmpCU = getPUAbove(uiIdx, uiPartUnitIdx );
4289      break;
4290    }
4291    case MD_ABOVE_RIGHT:
4292    {
4293      pcTmpCU = getPUAboveRight(uiIdx, uiPartUnitIdx);
4294      break;
4295    }
4296    case MD_BELOW_LEFT:
4297    {
4298      pcTmpCU = getPUBelowLeft(uiIdx, uiPartUnitIdx);
4299      break;
4300    }
4301    case MD_ABOVE_LEFT:
4302    {
4303      pcTmpCU = getPUAboveLeft(uiIdx, uiPartUnitIdx);
4304      break;
4305    }
4306    default:
4307    {
4308      break;
4309    }
4310  }
4311
4312  if ( pcTmpCU == NULL )
4313  {
4314    return false;
4315  }
4316 
4317  if ( pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) >= 0 && m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getPOC() == pcTmpCU->getSlice()->getRefPOC( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) ))
4318  {
4319    TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
4320   
4321    pInfo->m_acMvCand[ pInfo->iN++] = cMvPred;
4322    return true;
4323  }
4324
4325  RefPicList eRefPicList2nd = REF_PIC_LIST_0;
4326  if(       eRefPicList == REF_PIC_LIST_0 )
4327  {
4328    eRefPicList2nd = REF_PIC_LIST_1;
4329  }
4330  else if ( eRefPicList == REF_PIC_LIST_1)
4331  {
4332    eRefPicList2nd = REF_PIC_LIST_0;
4333  }
4334
4335
4336  Int iCurrRefPOC = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getPOC();
4337  Int iNeibRefPOC;
4338
4339
4340  if( pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) >= 0 )
4341  {
4342    iNeibRefPOC = pcTmpCU->getSlice()->getRefPOC( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) );
4343    if( iNeibRefPOC == iCurrRefPOC ) // Same Reference Frame But Diff List//
4344    {
4345      TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList2nd)->getMv(uiIdx);
4346      pInfo->m_acMvCand[ pInfo->iN++] = cMvPred;
4347      return true;
4348    }
4349  }
4350  return false;
4351}
4352
4353/**
4354 * \param pInfo
4355 * \param eRefPicList
4356 * \param iRefIdx
4357 * \param uiPartUnitIdx
4358 * \param eDir
4359 * \returns Bool
4360 */
4361Bool TComDataCU::xAddMVPCandOrder( AMVPInfo* pInfo, RefPicList eRefPicList, Int iRefIdx, UInt uiPartUnitIdx, MVP_DIR eDir )
4362{
4363  TComDataCU* pcTmpCU = NULL;
4364  UInt uiIdx;
4365  switch( eDir )
4366  {
4367  case MD_LEFT:
4368    {
4369      pcTmpCU = getPULeft(uiIdx, uiPartUnitIdx);
4370      break;
4371    }
4372  case MD_ABOVE:
4373    {
4374      pcTmpCU = getPUAbove(uiIdx, uiPartUnitIdx);
4375      break;
4376    }
4377  case MD_ABOVE_RIGHT:
4378    {
4379      pcTmpCU = getPUAboveRight(uiIdx, uiPartUnitIdx);
4380      break;
4381    }
4382  case MD_BELOW_LEFT:
4383    {
4384      pcTmpCU = getPUBelowLeft(uiIdx, uiPartUnitIdx);
4385      break;
4386    }
4387  case MD_ABOVE_LEFT:
4388    {
4389      pcTmpCU = getPUAboveLeft(uiIdx, uiPartUnitIdx);
4390      break;
4391    }
4392  default:
4393    {
4394      break;
4395    }
4396  }
4397
4398  if ( pcTmpCU == NULL ) 
4399  {
4400    return false;
4401  }
4402 
4403  RefPicList eRefPicList2nd = REF_PIC_LIST_0;
4404  if(       eRefPicList == REF_PIC_LIST_0 )
4405  {
4406    eRefPicList2nd = REF_PIC_LIST_1;
4407  }
4408  else if ( eRefPicList == REF_PIC_LIST_1)
4409  {
4410    eRefPicList2nd = REF_PIC_LIST_0;
4411  }
4412
4413  Int iCurrPOC = m_pcSlice->getPOC();
4414  Int iCurrRefPOC = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getPOC();
4415  Int iNeibPOC = iCurrPOC;
4416  Int iNeibRefPOC;
4417
4418  Bool bIsCurrRefLongTerm = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getIsLongTerm();
4419  Bool bIsNeibRefLongTerm = false;
4420  //---------------  V1 (END) ------------------//
4421  if( pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) >= 0)
4422  {
4423    iNeibRefPOC = pcTmpCU->getSlice()->getRefPOC( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) );
4424    TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
4425    TComMv rcMv;
4426
4427    bIsNeibRefLongTerm = pcTmpCU->getSlice()->getRefPic( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) )->getIsLongTerm();
4428    if ( bIsCurrRefLongTerm == bIsNeibRefLongTerm ) 
4429    {
4430    if ( bIsCurrRefLongTerm || bIsNeibRefLongTerm )
4431    {
4432      rcMv = cMvPred;
4433    }
4434    else
4435    {
4436      Int iScale = xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
4437      if ( iScale == 4096 )
4438      {
4439        rcMv = cMvPred;
4440      }
4441      else
4442      {
4443        rcMv = cMvPred.scaleMv( iScale );
4444      }
4445    }
4446    pInfo->m_acMvCand[ pInfo->iN++] = rcMv;
4447    return true;
4448    }
4449  }
4450  //---------------------- V2(END) --------------------//
4451  if( pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) >= 0)
4452  {
4453    iNeibRefPOC = pcTmpCU->getSlice()->getRefPOC( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) );
4454    TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList2nd)->getMv(uiIdx);
4455    TComMv rcMv;
4456
4457    bIsNeibRefLongTerm = pcTmpCU->getSlice()->getRefPic( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) )->getIsLongTerm();
4458    if ( bIsCurrRefLongTerm == bIsNeibRefLongTerm ) 
4459    {
4460    if ( bIsCurrRefLongTerm || bIsNeibRefLongTerm )
4461    {
4462      rcMv = cMvPred;
4463    }
4464    else
4465    {
4466      Int iScale = xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
4467      if ( iScale == 4096 )
4468      {
4469        rcMv = cMvPred;
4470      }
4471      else
4472      {
4473        rcMv = cMvPred.scaleMv( iScale );
4474      }
4475    }
4476    pInfo->m_acMvCand[ pInfo->iN++] = rcMv;
4477    return true;
4478    }
4479  }
4480  //---------------------- V3(END) --------------------//
4481  return false;
4482}
4483
4484/**
4485 * \param eRefPicList
4486 * \param uiCUAddr
4487 * \param uiPartUnitIdx
4488 * \param riRefIdx
4489 * \returns Bool
4490 */
4491Bool TComDataCU::xGetColMVP( RefPicList eRefPicList, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv, Int& riRefIdx
4492#if H_3D_TMVP
4493  , Bool bMRG
4494#endif
4495  )
4496{
4497  UInt uiAbsPartAddr = uiPartUnitIdx;
4498
4499  RefPicList  eColRefPicList;
4500  Int iColPOC, iColRefPOC, iCurrPOC, iCurrRefPOC, iScale;
4501  TComMv cColMv;
4502
4503  // use coldir.
4504#if H_MV
4505  TComPic *pColPic; 
4506  if (getSlice()->getAltCollocatedIndicationFlag() )
4507  {
4508    pColPic = getSlice()->getPicFromRefPicSetInterLayer( getSlice()->getActiveMotionPredRefLayerId( getSlice()->getCollocatedRefLayerIdx() )); 
4509  }
4510  else
4511  {
4512    pColPic = getSlice()->getRefPic( RefPicList(getSlice()->isInterB() ? 1-getSlice()->getColFromL0Flag() : 0), getSlice()->getColRefIdx()); 
4513  } 
4514#else
4515  TComPic *pColPic = getSlice()->getRefPic( RefPicList(getSlice()->isInterB() ? 1-getSlice()->getColFromL0Flag() : 0), getSlice()->getColRefIdx());
4516#endif
4517  TComDataCU *pColCU = pColPic->getCU( uiCUAddr );
4518  if(pColCU->getPic()==0||pColCU->getPartitionSize(uiPartUnitIdx)==SIZE_NONE)
4519  {
4520    return false;
4521  }
4522  iCurrPOC = m_pcSlice->getPOC();   
4523  iColPOC = pColCU->getSlice()->getPOC(); 
4524
4525  if (pColCU->isIntra(uiAbsPartAddr))
4526  {
4527    return false;
4528  }
4529  eColRefPicList = getSlice()->getCheckLDC() ? eRefPicList : RefPicList(getSlice()->getColFromL0Flag());
4530
4531  Int iColRefIdx = pColCU->getCUMvField(RefPicList(eColRefPicList))->getRefIdx(uiAbsPartAddr);
4532
4533  if (iColRefIdx < 0 )
4534  {
4535    eColRefPicList = RefPicList(1 - eColRefPicList);
4536    iColRefIdx = pColCU->getCUMvField(RefPicList(eColRefPicList))->getRefIdx(uiAbsPartAddr);
4537
4538    if (iColRefIdx < 0 )
4539    {
4540      return false;
4541    }
4542  }
4543
4544  // Scale the vector.
4545  iColRefPOC = pColCU->getSlice()->getRefPOC(eColRefPicList, iColRefIdx);
4546  cColMv = pColCU->getCUMvField(eColRefPicList)->getMv(uiAbsPartAddr);
4547
4548  iCurrRefPOC = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getPOC();
4549  Bool bIsCurrRefLongTerm = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getIsLongTerm();
4550  Bool bIsColRefLongTerm = pColCU->getSlice()->getIsUsedAsLongTerm(eColRefPicList, iColRefIdx);
4551
4552  if ( bIsCurrRefLongTerm != bIsColRefLongTerm ) 
4553  {
4554#if H_3D_TMVP
4555    Int iAlterRefIdx  = m_pcSlice->getAlterRefIdx(eRefPicList);
4556    if(bMRG && iAlterRefIdx > 0)
4557    {
4558      riRefIdx = iAlterRefIdx;
4559      bIsCurrRefLongTerm = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getIsLongTerm();
4560      iCurrRefPOC = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getPOC();
4561      assert(bIsCurrRefLongTerm == bIsColRefLongTerm);
4562    }
4563    else
4564    {
4565#endif
4566      return false;
4567#if H_3D_TMVP
4568    }
4569#endif
4570  }
4571
4572  if ( bIsCurrRefLongTerm || bIsColRefLongTerm )
4573  {
4574#if H_3D_TMVP
4575    Int iCurrViewId    = m_pcSlice->getViewIndex (); 
4576    Int iCurrRefViewId = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getViewIndex (); 
4577    Int iColViewId     = pColCU->getSlice()->getViewIndex(); 
4578    Int iColRefViewId  = pColCU->getSlice()->getRefPic( eColRefPicList, pColCU->getCUMvField(eColRefPicList)->getRefIdx(uiAbsPartAddr))->getViewIndex(); 
4579    iScale = xGetDistScaleFactor( iCurrViewId, iCurrRefViewId, iColViewId, iColRefViewId );
4580    if ( iScale != 4096 && m_pcSlice->getVPS()->getIvMvScalingFlag() ) 
4581    {
4582      rcMv = cColMv.scaleMv( iScale );
4583    }
4584    else
4585    {
4586#endif
4587       rcMv = cColMv;
4588#if H_3D_TMVP
4589    }
4590#endif
4591  }
4592  else
4593  {
4594    iScale = xGetDistScaleFactor(iCurrPOC, iCurrRefPOC, iColPOC, iColRefPOC);
4595    if ( iScale == 4096 )
4596    {
4597      rcMv = cColMv;
4598    }
4599    else
4600    {
4601      rcMv = cColMv.scaleMv( iScale );
4602    }
4603  }
4604  return true;
4605}
4606
4607UInt TComDataCU::xGetMvdBits(TComMv cMvd)
4608{
4609  return ( xGetComponentBits(cMvd.getHor()) + xGetComponentBits(cMvd.getVer()) );
4610}
4611
4612UInt TComDataCU::xGetComponentBits(Int iVal)
4613{
4614  UInt uiLength = 1;
4615  UInt uiTemp   = ( iVal <= 0) ? (-iVal<<1)+1: (iVal<<1);
4616 
4617  assert ( uiTemp );
4618 
4619  while ( 1 != uiTemp )
4620  {
4621    uiTemp >>= 1;
4622    uiLength += 2;
4623  }
4624 
4625  return uiLength;
4626}
4627
4628
4629Int TComDataCU::xGetDistScaleFactor(Int iCurrPOC, Int iCurrRefPOC, Int iColPOC, Int iColRefPOC)
4630{
4631  Int iDiffPocD = iColPOC - iColRefPOC;
4632  Int iDiffPocB = iCurrPOC - iCurrRefPOC;
4633 
4634  if( iDiffPocD == iDiffPocB )
4635  {
4636    return 4096;
4637  }
4638  else
4639  {
4640    Int iTDB      = Clip3( -128, 127, iDiffPocB );
4641    Int iTDD      = Clip3( -128, 127, iDiffPocD );
4642    Int iX        = (0x4000 + abs(iTDD/2)) / iTDD;
4643    Int iScale    = Clip3( -4096, 4095, (iTDB * iX + 32) >> 6 );
4644    return iScale;
4645  }
4646}
4647
4648/**
4649 * \param eCUMode
4650 * \param uiPartIdx
4651 * \param ruiPartIdxCenter
4652 * \returns Void
4653 */
4654Void TComDataCU::xDeriveCenterIdx( UInt uiPartIdx, UInt& ruiPartIdxCenter )
4655{
4656  UInt uiPartAddr;
4657  Int  iPartWidth;
4658  Int  iPartHeight;
4659  getPartIndexAndSize( uiPartIdx, uiPartAddr, iPartWidth, iPartHeight);
4660 
4661  ruiPartIdxCenter = m_uiAbsIdxInLCU+uiPartAddr; // partition origin.
4662  ruiPartIdxCenter = g_auiRasterToZscan[ g_auiZscanToRaster[ ruiPartIdxCenter ]
4663                                        + ( iPartHeight/m_pcPic->getMinCUHeight()  )/2*m_pcPic->getNumPartInWidth()
4664                                        + ( iPartWidth/m_pcPic->getMinCUWidth()  )/2];
4665}
4666
4667Void TComDataCU::compressMV()
4668{
4669  Int scaleFactor = 4 * AMVP_DECIMATION_FACTOR / m_unitSize;
4670  if (scaleFactor > 0)
4671  {
4672    m_acCUMvField[0].compress(m_pePredMode, scaleFactor);
4673    m_acCUMvField[1].compress(m_pePredMode, scaleFactor);   
4674  }
4675}
4676
4677UInt TComDataCU::getCoefScanIdx(UInt uiAbsPartIdx, UInt uiWidth, Bool bIsLuma, Bool bIsIntra)
4678{
4679  UInt uiCTXIdx;
4680  UInt uiScanIdx;
4681  UInt uiDirMode;
4682
4683  if ( !bIsIntra ) 
4684  {
4685    uiScanIdx = SCAN_DIAG;
4686    return uiScanIdx;
4687  }
4688
4689  switch(uiWidth)
4690  {
4691    case  2: uiCTXIdx = 6; break;
4692    case  4: uiCTXIdx = 5; break;
4693    case  8: uiCTXIdx = 4; break;
4694    case 16: uiCTXIdx = 3; break;
4695    case 32: uiCTXIdx = 2; break;
4696    case 64: uiCTXIdx = 1; break;
4697    default: uiCTXIdx = 0; break;
4698  }
4699
4700  if ( bIsLuma )
4701  {
4702    uiDirMode = getLumaIntraDir(uiAbsPartIdx);
4703#if H_3D_DIM
4704    mapDepthModeToIntraDir( uiDirMode );
4705#endif
4706    uiScanIdx = SCAN_DIAG;
4707    if (uiCTXIdx >3 && uiCTXIdx < 6) //if multiple scans supported for transform size
4708    {
4709      uiScanIdx = abs((Int) uiDirMode - VER_IDX) < 5 ? SCAN_HOR : (abs((Int)uiDirMode - HOR_IDX) < 5 ? SCAN_VER : SCAN_DIAG);
4710    }
4711  }
4712  else
4713  {
4714    uiDirMode = getChromaIntraDir(uiAbsPartIdx);
4715    if( uiDirMode == DM_CHROMA_IDX )
4716    {
4717      // get number of partitions in current CU
4718      UInt depth = getDepth(uiAbsPartIdx);
4719      UInt numParts = getPic()->getNumPartInCU() >> (2 * depth);
4720     
4721      // get luma mode from upper-left corner of current CU
4722      uiDirMode = getLumaIntraDir((uiAbsPartIdx/numParts)*numParts);
4723#if H_3D_DIM
4724      mapDepthModeToIntraDir( uiDirMode );
4725#endif
4726    }
4727    uiScanIdx = SCAN_DIAG;
4728    if (uiCTXIdx >4 && uiCTXIdx < 7) //if multiple scans supported for transform size
4729    {
4730      uiScanIdx = abs((Int) uiDirMode - VER_IDX) < 5 ? SCAN_HOR : (abs((Int)uiDirMode - HOR_IDX) < 5 ? SCAN_VER : SCAN_DIAG);
4731    }
4732  }
4733
4734  return uiScanIdx;
4735}
4736
4737UInt TComDataCU::getSCUAddr()
4738{ 
4739  return getPic()->getPicSym()->getInverseCUOrderMap(m_uiCUAddr)*(1<<(m_pcSlice->getSPS()->getMaxCUDepth()<<1))+m_uiAbsIdxInLCU; 
4740}
4741
4742/** Set neighboring blocks availabilities for non-deblocked filtering
4743 * \param numLCUInPicWidth number of LCUs in picture width
4744 * \param numLCUInPicHeight number of LCUs in picture height
4745 * \param numSUInLCUWidth number of SUs in LCU width
4746 * \param numSUInLCUHeight number of SUs in LCU height
4747 * \param picWidth picture width
4748 * \param picHeight picture height
4749 * \param bIndependentSliceBoundaryEnabled true for independent slice boundary enabled
4750 * \param bTopTileBoundary true means that top boundary coincides tile boundary
4751 * \param bDownTileBoundary true means that bottom boundary coincides tile boundary
4752 * \param bLeftTileBoundary true means that left boundary coincides tile boundary
4753 * \param bRightTileBoundary true means that right boundary coincides tile boundary
4754 * \param bIndependentTileBoundaryEnabled true for independent tile boundary enabled
4755 */
4756Void TComDataCU::setNDBFilterBlockBorderAvailability(UInt numLCUInPicWidth, UInt /*numLCUInPicHeight*/, UInt numSUInLCUWidth, UInt numSUInLCUHeight, UInt picWidth, UInt picHeight
4757                                                    ,std::vector<Bool>& LFCrossSliceBoundary
4758                                                    ,Bool bTopTileBoundary, Bool bDownTileBoundary, Bool bLeftTileBoundary, Bool bRightTileBoundary
4759                                                    ,Bool bIndependentTileBoundaryEnabled)
4760{
4761  UInt numSUInLCU = numSUInLCUWidth*numSUInLCUHeight;
4762  Int* pSliceIDMapLCU = m_piSliceSUMap;
4763  Bool onlyOneSliceInPic = ((Int)LFCrossSliceBoundary.size() == 1);
4764  UInt uiLPelX, uiTPelY;
4765  UInt width, height;
4766  Bool bPicRBoundary, bPicBBoundary, bPicTBoundary, bPicLBoundary;
4767  Bool bLCURBoundary= false, bLCUBBoundary= false, bLCUTBoundary= false, bLCULBoundary= false;
4768  Bool* pbAvailBorder;
4769  Bool* pbAvail;
4770  UInt rTLSU, rBRSU, widthSU, heightSU;
4771  UInt zRefSU;
4772  Int* pRefID;
4773  Int* pRefMapLCU;
4774  UInt rTRefSU= 0, rBRefSU= 0, rLRefSU= 0, rRRefSU= 0;
4775  Int* pRRefMapLCU= NULL;
4776  Int* pLRefMapLCU= NULL;
4777  Int* pTRefMapLCU= NULL;
4778  Int* pBRefMapLCU= NULL;
4779  Int  sliceID;
4780  UInt numSGU = (UInt)m_vNDFBlock.size();
4781
4782  for(Int i=0; i< numSGU; i++)
4783  {
4784    NDBFBlockInfo& rSGU = m_vNDFBlock[i];
4785
4786    sliceID = rSGU.sliceID;
4787    uiLPelX = rSGU.posX;
4788    uiTPelY = rSGU.posY;
4789    width   = rSGU.width;
4790    height  = rSGU.height;
4791    rTLSU     = g_auiZscanToRaster[ rSGU.startSU ];
4792    rBRSU     = g_auiZscanToRaster[ rSGU.endSU   ];
4793    widthSU   = rSGU.widthSU;
4794    heightSU  = rSGU.heightSU;
4795
4796    pbAvailBorder = rSGU.isBorderAvailable;
4797
4798    bPicTBoundary= (uiTPelY == 0                       )?(true):(false);
4799    bPicLBoundary= (uiLPelX == 0                       )?(true):(false);
4800    bPicRBoundary= (!(uiLPelX+ width < picWidth )  )?(true):(false);
4801    bPicBBoundary= (!(uiTPelY + height < picHeight))?(true):(false);
4802
4803    bLCULBoundary = (rTLSU % numSUInLCUWidth == 0)?(true):(false);
4804    bLCURBoundary = ( (rTLSU+ widthSU) % numSUInLCUWidth == 0)?(true):(false);
4805    bLCUTBoundary = ( (UInt)(rTLSU / numSUInLCUWidth)== 0)?(true):(false);
4806    bLCUBBoundary = ( (UInt)(rBRSU / numSUInLCUWidth) == (numSUInLCUHeight-1) )?(true):(false);
4807
4808    //       SGU_L
4809    pbAvail = &(pbAvailBorder[SGU_L]);
4810    if(bPicLBoundary)
4811    {
4812      *pbAvail = false;
4813    }
4814    else if (onlyOneSliceInPic)
4815    {
4816      *pbAvail = true;
4817    }
4818    else
4819    {
4820      //      bLCULBoundary = (rTLSU % uiNumSUInLCUWidth == 0)?(true):(false);
4821      if(bLCULBoundary)
4822      {
4823        rLRefSU     = rTLSU + numSUInLCUWidth -1;
4824        zRefSU      = g_auiRasterToZscan[rLRefSU];
4825        pRefMapLCU = pLRefMapLCU= (pSliceIDMapLCU - numSUInLCU);
4826      }
4827      else
4828      {
4829        zRefSU   = g_auiRasterToZscan[rTLSU - 1];
4830        pRefMapLCU  = pSliceIDMapLCU;
4831      }
4832      pRefID = pRefMapLCU + zRefSU;
4833      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
4834    }
4835
4836    //       SGU_R
4837    pbAvail = &(pbAvailBorder[SGU_R]);
4838    if(bPicRBoundary)
4839    {
4840      *pbAvail = false;
4841    }
4842    else if (onlyOneSliceInPic)
4843    {
4844      *pbAvail = true;
4845    }
4846    else
4847    {
4848      //       bLCURBoundary = ( (rTLSU+ uiWidthSU) % uiNumSUInLCUWidth == 0)?(true):(false);
4849      if(bLCURBoundary)
4850      {
4851        rRRefSU      = rTLSU + widthSU - numSUInLCUWidth;
4852        zRefSU       = g_auiRasterToZscan[rRRefSU];
4853        pRefMapLCU  = pRRefMapLCU= (pSliceIDMapLCU + numSUInLCU);
4854      }
4855      else
4856      {
4857        zRefSU       = g_auiRasterToZscan[rTLSU + widthSU];
4858        pRefMapLCU  = pSliceIDMapLCU;
4859      }
4860      pRefID = pRefMapLCU + zRefSU;
4861      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
4862    }
4863
4864    //       SGU_T
4865    pbAvail = &(pbAvailBorder[SGU_T]);
4866    if(bPicTBoundary)
4867    {
4868      *pbAvail = false;
4869    }
4870    else if (onlyOneSliceInPic)
4871    {
4872      *pbAvail = true;
4873    }
4874    else
4875    {
4876      //      bLCUTBoundary = ( (UInt)(rTLSU / uiNumSUInLCUWidth)== 0)?(true):(false);
4877      if(bLCUTBoundary)
4878      {
4879        rTRefSU      = numSUInLCU - (numSUInLCUWidth - rTLSU);
4880        zRefSU       = g_auiRasterToZscan[rTRefSU];
4881        pRefMapLCU  = pTRefMapLCU= (pSliceIDMapLCU - (numLCUInPicWidth*numSUInLCU));
4882      }
4883      else
4884      {
4885        zRefSU       = g_auiRasterToZscan[rTLSU - numSUInLCUWidth];
4886        pRefMapLCU  = pSliceIDMapLCU;
4887      }
4888      pRefID = pRefMapLCU + zRefSU;
4889      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
4890    }
4891
4892    //       SGU_B
4893    pbAvail = &(pbAvailBorder[SGU_B]);
4894    if(bPicBBoundary)
4895    {
4896      *pbAvail = false;
4897    }
4898    else if (onlyOneSliceInPic)
4899    {
4900      *pbAvail = true;
4901    }
4902    else
4903    {
4904      //      bLCUBBoundary = ( (UInt)(rBRSU / uiNumSUInLCUWidth) == (uiNumSUInLCUHeight-1) )?(true):(false);
4905      if(bLCUBBoundary)
4906      {
4907        rBRefSU      = rTLSU % numSUInLCUWidth;
4908        zRefSU       = g_auiRasterToZscan[rBRefSU];
4909        pRefMapLCU  = pBRefMapLCU= (pSliceIDMapLCU + (numLCUInPicWidth*numSUInLCU));
4910      }
4911      else
4912      {
4913        zRefSU       = g_auiRasterToZscan[rTLSU + (heightSU*numSUInLCUWidth)];
4914        pRefMapLCU  = pSliceIDMapLCU;
4915      }
4916      pRefID = pRefMapLCU + zRefSU;
4917      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
4918    }
4919
4920    //       SGU_TL
4921    pbAvail = &(pbAvailBorder[SGU_TL]);
4922    if(bPicTBoundary || bPicLBoundary)
4923    {
4924      *pbAvail = false;
4925    }
4926    else if (onlyOneSliceInPic)
4927    {
4928      *pbAvail = true;
4929    }
4930    else
4931    {
4932      if(bLCUTBoundary && bLCULBoundary)
4933      {
4934        zRefSU       = numSUInLCU -1;
4935        pRefMapLCU  = pSliceIDMapLCU - ( (numLCUInPicWidth+1)*numSUInLCU);
4936      }
4937      else if(bLCUTBoundary)
4938      {
4939        zRefSU       = g_auiRasterToZscan[ rTRefSU- 1];
4940        pRefMapLCU  = pTRefMapLCU;
4941      }
4942      else if(bLCULBoundary)
4943      {
4944        zRefSU       = g_auiRasterToZscan[ rLRefSU- numSUInLCUWidth ];
4945        pRefMapLCU  = pLRefMapLCU;
4946      }
4947      else //inside LCU
4948      {
4949        zRefSU       = g_auiRasterToZscan[ rTLSU - numSUInLCUWidth -1];
4950        pRefMapLCU  = pSliceIDMapLCU;
4951      }
4952      pRefID = pRefMapLCU + zRefSU;
4953      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
4954    }
4955
4956    //       SGU_TR
4957    pbAvail = &(pbAvailBorder[SGU_TR]);
4958    if(bPicTBoundary || bPicRBoundary)
4959    {
4960      *pbAvail = false;
4961    }
4962    else if (onlyOneSliceInPic)
4963    {
4964      *pbAvail = true;
4965    }
4966    else
4967    {
4968      if(bLCUTBoundary && bLCURBoundary)
4969      {
4970        zRefSU      = g_auiRasterToZscan[numSUInLCU - numSUInLCUWidth];
4971        pRefMapLCU  = pSliceIDMapLCU - ( (numLCUInPicWidth-1)*numSUInLCU);       
4972      }
4973      else if(bLCUTBoundary)
4974      {
4975        zRefSU       = g_auiRasterToZscan[ rTRefSU+ widthSU];
4976        pRefMapLCU  = pTRefMapLCU;
4977      }
4978      else if(bLCURBoundary)
4979      {
4980        zRefSU       = g_auiRasterToZscan[ rRRefSU- numSUInLCUWidth ];
4981        pRefMapLCU  = pRRefMapLCU;
4982      }
4983      else //inside LCU
4984      {
4985        zRefSU       = g_auiRasterToZscan[ rTLSU - numSUInLCUWidth +widthSU];
4986        pRefMapLCU  = pSliceIDMapLCU;
4987      }
4988      pRefID = pRefMapLCU + zRefSU;
4989      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
4990    }
4991
4992    //       SGU_BL
4993    pbAvail = &(pbAvailBorder[SGU_BL]);
4994    if(bPicBBoundary || bPicLBoundary)
4995    {
4996      *pbAvail = false;
4997    }
4998    else if (onlyOneSliceInPic)
4999    {
5000      *pbAvail = true;
5001    }
5002    else
5003    {
5004      if(bLCUBBoundary && bLCULBoundary)
5005      {
5006        zRefSU      = g_auiRasterToZscan[numSUInLCUWidth - 1];
5007        pRefMapLCU  = pSliceIDMapLCU + ( (numLCUInPicWidth-1)*numSUInLCU);       
5008      }
5009      else if(bLCUBBoundary)
5010      {
5011        zRefSU       = g_auiRasterToZscan[ rBRefSU - 1];
5012        pRefMapLCU  = pBRefMapLCU;
5013      }
5014      else if(bLCULBoundary)
5015      {
5016        zRefSU       = g_auiRasterToZscan[ rLRefSU+ heightSU*numSUInLCUWidth ];
5017        pRefMapLCU  = pLRefMapLCU;
5018      }
5019      else //inside LCU
5020      {
5021        zRefSU       = g_auiRasterToZscan[ rTLSU + heightSU*numSUInLCUWidth -1];
5022        pRefMapLCU  = pSliceIDMapLCU;
5023      }
5024      pRefID = pRefMapLCU + zRefSU;
5025      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
5026    }
5027
5028    //       SGU_BR
5029    pbAvail = &(pbAvailBorder[SGU_BR]);
5030    if(bPicBBoundary || bPicRBoundary)
5031    {
5032      *pbAvail = false;
5033    }
5034    else if (onlyOneSliceInPic)
5035    {
5036      *pbAvail = true;
5037    }
5038    else
5039    {
5040      if(bLCUBBoundary && bLCURBoundary)
5041      {
5042        zRefSU = 0;
5043        pRefMapLCU = pSliceIDMapLCU+ ( (numLCUInPicWidth+1)*numSUInLCU);
5044      }
5045      else if(bLCUBBoundary)
5046      {
5047        zRefSU      = g_auiRasterToZscan[ rBRefSU + widthSU];
5048        pRefMapLCU = pBRefMapLCU;
5049      }
5050      else if(bLCURBoundary)
5051      {
5052        zRefSU      = g_auiRasterToZscan[ rRRefSU + (heightSU*numSUInLCUWidth)];
5053        pRefMapLCU = pRRefMapLCU;
5054      }
5055      else //inside LCU
5056      {
5057        zRefSU      = g_auiRasterToZscan[ rTLSU + (heightSU*numSUInLCUWidth)+ widthSU];
5058        pRefMapLCU = pSliceIDMapLCU;
5059      }
5060      pRefID = pRefMapLCU + zRefSU;
5061      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
5062    }
5063
5064    if(bIndependentTileBoundaryEnabled)
5065    {
5066      //left LCU boundary
5067      if(!bPicLBoundary && bLCULBoundary)
5068      {
5069        if(bLeftTileBoundary)
5070        {
5071          pbAvailBorder[SGU_L] = pbAvailBorder[SGU_TL] = pbAvailBorder[SGU_BL] = false;
5072        }
5073      }
5074      //right LCU boundary
5075      if(!bPicRBoundary && bLCURBoundary)
5076      {
5077        if(bRightTileBoundary)
5078        {
5079          pbAvailBorder[SGU_R] = pbAvailBorder[SGU_TR] = pbAvailBorder[SGU_BR] = false;
5080        }
5081      }
5082      //top LCU boundary
5083      if(!bPicTBoundary && bLCUTBoundary)
5084      {
5085        if(bTopTileBoundary)
5086        {
5087          pbAvailBorder[SGU_T] = pbAvailBorder[SGU_TL] = pbAvailBorder[SGU_TR] = false;
5088        }
5089      }
5090      //down LCU boundary
5091      if(!bPicBBoundary && bLCUBBoundary)
5092      {
5093        if(bDownTileBoundary)
5094        {
5095          pbAvailBorder[SGU_B] = pbAvailBorder[SGU_BL] = pbAvailBorder[SGU_BR] = false;
5096        }
5097      }
5098    }
5099    rSGU.allBordersAvailable = true;
5100    for(Int b=0; b< NUM_SGU_BORDER; b++)
5101    {
5102      if(pbAvailBorder[b] == false)
5103      {
5104        rSGU.allBordersAvailable = false;
5105        break;
5106      }
5107    }
5108  }
5109}
5110
5111#if H_3D
5112Void TComDataCU::getPosInPic( UInt uiAbsPartIndex, Int& riPosX, Int& riPosY )
5113{
5114  riPosX = g_auiRasterToPelX[g_auiZscanToRaster[uiAbsPartIndex]] + getCUPelX();
5115  riPosY = g_auiRasterToPelY[g_auiZscanToRaster[uiAbsPartIndex]] + getCUPelY(); 
5116}
5117#endif
5118#if H_3D_NBDV
5119//Notes from QC:
5120//TBD#1: DoNBDV related contributions are just partially integrated under the marco of H_3D_NBDV_REF, remove this comment once DoNBDV and BVSP are done
5121//TBD#2: set of DvMCP values need to be done as part of inter-view motion prediction process. Remove this comment once merge related integration is done
5122//To be checked: Parallel Merge features for NBDV, related to DV_DERIVATION_PARALLEL_B0096 and LGE_IVMP_PARALLEL_MERGE_B0136 are not integrated. The need of these features due to the adoption of CU-based NBDV is not clear. We need confirmation on this, especially by proponents
5123Bool TComDataCU::getDisMvpCandNBDV( DisInfo* pDInfo
5124#if H_3D_NBDV_REF
5125, Bool bDepthRefine
5126#endif
5127)
5128{
5129  //// ******* Init variables ******* /////
5130  // Init disparity struct for results
5131  pDInfo->bDV = false;   
5132  // Init struct for disparities from MCP neighboring blocks
5133  IDVInfo cIDVInfo;
5134  cIDVInfo.m_bFound = false; 
5135  UInt uiPartIdx = 0;
5136  UInt uiPartAddr = 0;
5137  for (UInt iCurDvMcpCand = 0; iCurDvMcpCand < IDV_CANDS; iCurDvMcpCand++)
5138  {
5139    for (UInt iList = 0; iList < 2; iList++)
5140    {
5141      cIDVInfo.m_acMvCand[iList][iCurDvMcpCand].setZero();
5142      cIDVInfo.m_aVIdxCan[iList][iCurDvMcpCand] = 0; 
5143      cIDVInfo.m_bAvailab[iList][iCurDvMcpCand] = false; 
5144    }
5145  }
5146#if H_3D_NBDV_REF
5147  if( !m_pcSlice->getVPS()->getDepthRefinementFlag( m_pcSlice->getLayerIdInVps() ) )
5148  {
5149    bDepthRefine = false;
5150  }
5151#endif
5152  // Get Positions 
5153  PartSize eCUMode    = getPartitionSize( uiPartAddr );   
5154  assert(eCUMode == SIZE_2Nx2N);
5155  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB; 
5156
5157  deriveLeftRightTopIdxGeneral(uiPartAddr, uiPartIdx, uiPartIdxLT, uiPartIdxRT );
5158  deriveLeftBottomIdxGeneral  (uiPartAddr, uiPartIdx, uiPartIdxLB );
5159
5160  //// ******* Get disparity from temporal neighboring blocks ******* /////
5161  if ( getSlice()->getEnableTMVPFlag() )
5162  {
5163    TComMv cColMv;
5164    Int iTargetViewIdx = 0;
5165    Int iTStartViewIdx = 0;   
5166
5167    ///*** Derive center position ***
5168    UInt uiPartIdxCenter;
5169    Int  uiLCUIdx   = getAddr();
5170    xDeriveCenterIdx(uiPartIdx, uiPartIdxCenter );
5171
5172    ///*** Derive bottom right neighbour position ***
5173    Int iLCUIdxRBNb  = -1;   
5174    Int iPartIdxRBNb = -1;
5175    xDeriveRightBottomNbIdx(iLCUIdxRBNb, iPartIdxRBNb );
5176
5177    ///*** Search temporal candidate pictures for disparity vector ***
5178    const Int iNumCandPics = getPic()->getNumDdvCandPics();
5179    for(Int curCandPic = 0; curCandPic < iNumCandPics; curCandPic++)
5180    {
5181      RefPicList eCurRefPicList   = REF_PIC_LIST_0 ;
5182      Int        curCandPicRefIdx = 0;
5183      if( curCandPic == 0 ) 
5184      { 
5185        eCurRefPicList   = RefPicList(getSlice()->isInterB() ? 1-getSlice()->getColFromL0Flag() : 0);
5186        curCandPicRefIdx = getSlice()->getColRefIdx();
5187      }
5188      else                 
5189      {
5190        eCurRefPicList   = getPic()->getRapRefList();
5191        curCandPicRefIdx = getPic()->getRapRefIdx();
5192      }
5193
5194      // Check BR and Center       
5195      for(Int curPosition = 0; curPosition < 2; curPosition++) 
5196      {
5197        Bool bCheck = false; 
5198        if ( curPosition == 0 && iLCUIdxRBNb >= 0 )
5199#if MTK_NBDV_TN_FIX_E0172
5200          bCheck = xGetColDisMV( curCandPic, eCurRefPicList, curCandPicRefIdx, iLCUIdxRBNb, iPartIdxRBNb,  cColMv, iTargetViewIdx, iTStartViewIdx);
5201#else
5202          bCheck = xGetColDisMV( eCurRefPicList, curCandPicRefIdx, iLCUIdxRBNb, iPartIdxRBNb,  cColMv, iTargetViewIdx, iTStartViewIdx);
5203#endif
5204
5205        if (curPosition == 1 )
5206#if MTK_NBDV_TN_FIX_E0172
5207          bCheck = xGetColDisMV( curCandPic, eCurRefPicList, curCandPicRefIdx, uiLCUIdx,   uiPartIdxCenter,  cColMv, iTargetViewIdx, iTStartViewIdx );
5208#else
5209          bCheck = xGetColDisMV( eCurRefPicList, curCandPicRefIdx, uiLCUIdx,   uiPartIdxCenter,  cColMv, iTargetViewIdx, iTStartViewIdx );
5210#endif
5211
5212        if( bCheck )
5213        {
5214          clipMv(cColMv);
5215          pDInfo->m_acNBDV = cColMv;
5216          pDInfo->m_aVIdxCan  = iTargetViewIdx;
5217
5218#if H_3D_NBDV_REF
5219          TComPic* picDepth = NULL;         
5220          picDepth = getSlice()->getIvPic( true, iTargetViewIdx );
5221          assert(picDepth != NULL);
5222          if (picDepth && bDepthRefine)
5223            estimateDVFromDM(iTargetViewIdx, uiPartIdx, picDepth, uiPartAddr, &cColMv );
5224
5225          pDInfo->m_acDoNBDV  = cColMv;
5226#endif //H_3D_NBDV_REF
5227          return true;
5228        }
5229      } 
5230    }
5231  } 
5232
5233  UInt uiIdx = 0;
5234  Bool        bCheckMcpDv = false;   
5235  TComDataCU* pcTmpCU     = NULL;
5236
5237  //// ******* Get disparity from left block ******* /////
5238  pcTmpCU = getPULeft(uiIdx, uiPartIdxLB, true, false);
5239  bCheckMcpDv = true; 
5240  if ( xCheckSpatialNBDV( pcTmpCU, uiIdx, pDInfo, bCheckMcpDv, &cIDVInfo, DVFROM_LEFT
5241#if H_3D_NBDV_REF
5242  , bDepthRefine
5243#endif
5244    ) )
5245    return true;
5246
5247  //// ******* Get disparity from above block ******* /////
5248  pcTmpCU = getPUAbove(uiIdx, uiPartIdxRT, true, false, true);
5249  if(pcTmpCU != NULL )
5250  {
5251    bCheckMcpDv = ( ( getAddr() - pcTmpCU->getAddr() ) == 0);
5252    if ( xCheckSpatialNBDV( pcTmpCU, uiIdx, pDInfo, bCheckMcpDv, &cIDVInfo, DVFROM_ABOVE
5253#if H_3D_NBDV_REF
5254  , bDepthRefine
5255#endif
5256    ) )
5257      return true;
5258  }
5259
5260  //// ******* Get disparity from above right block ******* /////
5261  pcTmpCU = getPUAboveRight(uiIdx, uiPartIdxRT, true);
5262  if(pcTmpCU != NULL )
5263  {
5264    bCheckMcpDv = ( ( getAddr() - pcTmpCU->getAddr() ) == 0);
5265    if ( xCheckSpatialNBDV( pcTmpCU, uiIdx, pDInfo, bCheckMcpDv, &cIDVInfo, DVFROM_ABOVERIGHT
5266#if H_3D_NBDV_REF
5267  , bDepthRefine
5268#endif
5269    ) )
5270      return true;
5271  }
5272
5273  //// ******* Get disparity from below left block ******* /////
5274  pcTmpCU = getPUBelowLeft(uiIdx, uiPartIdxLB, true);
5275  if( pcTmpCU != NULL )
5276  {
5277    bCheckMcpDv = true; 
5278    if ( xCheckSpatialNBDV( pcTmpCU, uiIdx, pDInfo, bCheckMcpDv, &cIDVInfo, DVFROM_LEFTBELOW
5279#if H_3D_NBDV_REF
5280  , bDepthRefine
5281#endif
5282    ) )
5283      return true;
5284  }
5285
5286  //// ******* Get disparity from above left block ******* /////
5287  pcTmpCU = getPUAboveLeft(uiIdx, (m_uiAbsIdxInLCU + uiPartAddr), true);
5288  assert(uiPartIdxLT == (m_uiAbsIdxInLCU + uiPartAddr));
5289
5290  if( pcTmpCU != NULL )
5291  {
5292    bCheckMcpDv = (( getAddr() - pcTmpCU->getAddr() ) <= 1); 
5293    if ( xCheckSpatialNBDV( pcTmpCU, uiIdx, pDInfo, bCheckMcpDv, &cIDVInfo, DVFROM_ABOVELEFT
5294#if H_3D_NBDV_REF
5295  , bDepthRefine
5296#endif
5297    ) )
5298      return true;
5299  }
5300
5301  //// ******* Search MCP blocks ******* /////
5302  if( cIDVInfo.m_bFound ) 
5303  {
5304    for( Int curPos = 0 ; curPos < IDV_CANDS ; curPos++ ) 
5305    {
5306      for(Int iList = 0; iList < (getSlice()->isInterB() ? 2: 1); iList ++)
5307      {
5308        if( cIDVInfo.m_bAvailab[iList][curPos] )
5309        {
5310          TComMv cDispVec = cIDVInfo.m_acMvCand[iList][ curPos ];
5311          clipMv( cDispVec );
5312          pDInfo->m_acNBDV = cDispVec;
5313          pDInfo->m_aVIdxCan = cIDVInfo.m_aVIdxCan[iList][ curPos ];
5314#if !MTK_DVMCP_FIX_E0172
5315          assert(pDInfo->m_aVIdxCan == 0); //Notes from QC: only works for CTC
5316#endif
5317#if H_3D_NBDV_REF
5318          TComPic* picDepth = getSlice()->getIvPic( true, pDInfo->m_aVIdxCan );
5319          assert(picDepth!=NULL);
5320
5321          if (picDepth && bDepthRefine)
5322          {
5323            estimateDVFromDM (pDInfo->m_aVIdxCan, uiPartIdx, picDepth, uiPartAddr, &cDispVec);
5324          }
5325          pDInfo->m_acDoNBDV = cDispVec;
5326#endif
5327          return true;
5328        }
5329      }
5330    }
5331  }
5332
5333  TComMv defaultDV(0, 0);
5334  pDInfo->m_acNBDV = defaultDV;
5335#if NBDV_DEFAULT_VIEWIDX_BUGFIX
5336  Int valid = 0;
5337  Int viewIndex = 0;
5338  for( UInt uiBId = 0; uiBId < getSlice()->getViewIndex() && valid==0; uiBId++ )
5339  {
5340    UInt        uiBaseId    = uiBId;
5341    TComPic*    pcBasePic   = getSlice()->getIvPic( false, uiBaseId );
5342    for( Int iRefListId = 0; ( iRefListId < (getSlice()->isInterB()? 2:1) ) && !getSlice()->isIntra() && valid==0; iRefListId++ )
5343    {
5344      RefPicList  eRefPicListTest = RefPicList( iRefListId );
5345      Int         iNumRefPics = getSlice()->getNumRefIdx( eRefPicListTest ) ;
5346      for( Int iRefIndex = 0; iRefIndex < iNumRefPics; iRefIndex++ )
5347      { 
5348        if(pcBasePic->getPOC() == getSlice()->getRefPic( eRefPicListTest, iRefIndex )->getPOC() 
5349          && pcBasePic->getViewIndex() == getSlice()->getRefPic( eRefPicListTest, iRefIndex )->getViewIndex())
5350        {
5351          valid=1;
5352          viewIndex = uiBaseId;
5353          break;
5354        }
5355      }
5356    }
5357  }
5358  if(valid)
5359  {
5360    pDInfo->m_aVIdxCan = viewIndex;
5361#if H_3D_NBDV_REF
5362    TComPic* picDepth = NULL;
5363    picDepth = getSlice()->getIvPic( true, viewIndex );
5364    assert(picDepth!=NULL);
5365
5366    if (picDepth && bDepthRefine)
5367    {
5368      estimateDVFromDM(viewIndex, uiPartIdx, picDepth, uiPartAddr, &defaultDV ); // from base view
5369    }
5370    pDInfo->m_acDoNBDV = defaultDV;
5371#endif
5372  }
5373#else
5374  pDInfo->m_aVIdxCan = 0;
5375#if H_3D_NBDV_REF
5376  TComPic* picDepth = NULL;
5377  picDepth = getSlice()->getIvPic( true, 0 );
5378  assert(picDepth!=NULL);
5379
5380  if (picDepth && bDepthRefine)
5381  {
5382    estimateDVFromDM(0, uiPartIdx, picDepth, uiPartAddr, &defaultDV ); // from base view
5383  }
5384  pDInfo->m_acDoNBDV = defaultDV;
5385#endif
5386#endif
5387  return false; 
5388}
5389
5390#if H_3D_NBDV_REF
5391Pel TComDataCU::getMcpFromDM(TComPicYuv* pcBaseViewDepthPicYuv, TComMv* mv, Int iBlkX, Int iBlkY, Int iBlkWidth, Int iBlkHeight, Int* aiShiftLUT )
5392{
5393  Int iPictureWidth  = pcBaseViewDepthPicYuv->getWidth();
5394  Int iPictureHeight = pcBaseViewDepthPicYuv->getHeight();
5395 
5396#if NTT_DoNBDV_VECTOR_CLIP_E0141
5397  Int depthStartPosX = Clip3(0,   iPictureWidth - 1,  iBlkX + ((mv->getHor()+2)>>2));
5398  Int depthStartPosY = Clip3(0,   iPictureHeight - 1, iBlkY + ((mv->getVer()+2)>>2));
5399  Int depthEndPosX   = Clip3(0,   iPictureWidth - 1,  iBlkX + iBlkWidth - 1 + ((mv->getHor()+2)>>2));
5400  Int depthEndPosY   = Clip3(0,   iPictureHeight - 1, iBlkY + iBlkHeight - 1 + ((mv->getVer()+2)>>2));
5401#else
5402  Int depthStartPosX = Clip3(0,   iPictureWidth - iBlkWidth,  iBlkX + ((mv->getHor()+2)>>2));
5403  Int depthStartPosY = Clip3(0,   iPictureHeight- iBlkHeight,  iBlkY + ((mv->getVer()+2)>>2));
5404  Int depthEndPosX   = Clip3(0,   iPictureWidth - 1,  iBlkX + iBlkWidth - 1 + ((mv->getHor()+2)>>2));
5405  Int depthEndPosY   = Clip3(0,   iPictureHeight - 1,  iBlkY + iBlkHeight - 1 + ((mv->getVer()+2)>>2));
5406#endif
5407
5408  Pel* depthTL  = pcBaseViewDepthPicYuv->getLumaAddr();
5409  Int depStride =  pcBaseViewDepthPicYuv->getStride();
5410
5411  Pel  maxDepthVal = 0;
5412  maxDepthVal = std::max( maxDepthVal, depthTL[ (depthStartPosY) * depStride + depthStartPosX ]);      // Left Top
5413  maxDepthVal = std::max( maxDepthVal, depthTL[ (depthEndPosY)   * depStride + depthStartPosX ]);      // Left Bottom
5414  maxDepthVal = std::max( maxDepthVal, depthTL[ (depthStartPosY) * depStride + depthEndPosX   ]);      // Right Top
5415  maxDepthVal = std::max( maxDepthVal, depthTL[ (depthEndPosY)   * depStride + depthEndPosX   ]);      // Right Bottom
5416
5417  return aiShiftLUT[ maxDepthVal ];
5418}
5419
5420Void TComDataCU::estimateDVFromDM(Int refViewIdx, UInt uiPartIdx, TComPic* picDepth, UInt uiPartAddr, TComMv* cMvPred )
5421{
5422  if (picDepth)
5423  {
5424    UInt uiAbsPartAddrCurrCU = m_uiAbsIdxInLCU + uiPartAddr;
5425    Int iWidth, iHeight;
5426    getPartIndexAndSize( uiPartIdx, uiPartAddr, iWidth, iHeight ); // The modified value of uiPartAddr won't be used any more
5427
5428    TComPicYuv* pcBaseViewDepthPicYuv = picDepth->getPicYuvRec();
5429    Int iBlkX = ( getAddr() % picDepth->getFrameWidthInCU() ) * g_uiMaxCUWidth  + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartAddrCurrCU ] ];
5430    Int iBlkY = ( getAddr() / picDepth->getFrameWidthInCU() ) * g_uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartAddrCurrCU ] ];
5431
5432    Int* aiShiftLUT = getSlice()->getDepthToDisparityB(refViewIdx );
5433
5434    Pel iDisp = getMcpFromDM( pcBaseViewDepthPicYuv, cMvPred, iBlkX, iBlkY, iWidth, iHeight, aiShiftLUT );
5435    cMvPred->setHor( iDisp );
5436    clipMv(*cMvPred);
5437  }
5438}
5439#endif //H_3D_NBDV_REF
5440
5441
5442Bool TComDataCU::xCheckSpatialNBDV( TComDataCU* pcTmpCU, UInt uiIdx, DisInfo* pNbDvInfo, Bool bSearchForMvpDv, IDVInfo* paIDVInfo, UInt uiMvpDvPos
5443#if H_3D_NBDV_REF
5444, Bool bDepthRefine
5445#endif
5446)
5447{
5448  if( pcTmpCU != NULL && !pcTmpCU->isIntra( uiIdx ) )
5449  {
5450    Bool bTmpIsSkipped = pcTmpCU->isSkipped( uiIdx );
5451    for(Int iList = 0; iList < (getSlice()->isInterB() ? 2: 1); iList ++)
5452    {
5453      RefPicList eRefPicList = RefPicList(iList);
5454      Int      refId = pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) ;
5455      TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
5456
5457      if( refId >= 0)
5458      {
5459        Int refViewIdx  = pcTmpCU->getSlice()->getRefPic(eRefPicList, refId)->getViewIndex();
5460        if (refViewIdx != m_pcSlice->getViewIndex()) 
5461        {
5462          clipMv(cMvPred);
5463          pNbDvInfo->m_acNBDV = cMvPred;
5464          pNbDvInfo->m_aVIdxCan = refViewIdx;
5465#if H_3D_NBDV_REF
5466          TComPic* picDepth = NULL;
5467          assert(getSlice()->getRefPic(eRefPicList, refId)->getPOC() == getSlice()->getPOC());         
5468          picDepth   = getSlice()->getIvPic (true, refViewIdx );
5469          assert(picDepth != NULL);
5470
5471          UInt uiPartIdx = 0;   //Notes from MTK: Please confirm that using 0 as partition index and partition address is correct for CU-level DoNBDV
5472          UInt uiPartAddr = 0;  //QC: confirmed
5473
5474          if (picDepth && bDepthRefine)
5475            estimateDVFromDM(refViewIdx, uiPartIdx, picDepth, uiPartAddr, &cMvPred );
5476
5477          pNbDvInfo->m_acDoNBDV = cMvPred;
5478#endif
5479          return true;
5480        }
5481        else if ( bSearchForMvpDv && cMvPred.getIDVFlag() && bTmpIsSkipped )
5482        {
5483          assert( uiMvpDvPos < IDV_CANDS );
5484          paIDVInfo->m_acMvCand[iList][ uiMvpDvPos ] = TComMv( cMvPred.getIDVHor(), cMvPred.getIDVVer() );
5485          //Notes from QC: DvMCP is implemented in a way that doesnE½t carry the reference view identifier as NBDV. It only works for CTC and needs to be fixed to be aligned with other part of the NBDV design.
5486#if MTK_DVMCP_FIX_E0172
5487          paIDVInfo->m_aVIdxCan[iList][ uiMvpDvPos ] = cMvPred.getIDVVId();
5488#else 
5489          paIDVInfo->m_aVIdxCan[iList][ uiMvpDvPos ] = 0; 
5490#endif
5491          paIDVInfo->m_bAvailab[iList][ uiMvpDvPos ] = true;
5492          paIDVInfo->m_bFound                        = true; 
5493        }
5494      }
5495    }
5496  }
5497  return false; 
5498}
5499 
5500Void TComDataCU::xDeriveRightBottomNbIdx(Int &riLCUIdxRBNb, Int &riPartIdxRBNb )
5501{
5502  UInt uiPartIdx = 0;
5503  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth(); 
5504  Int uiLCUIdx = getAddr();
5505
5506  UInt uiPartIdxRB;
5507  deriveRightBottomIdx(uiPartIdx, uiPartIdxRB ); 
5508  UInt uiAbsPartIdxTmp = g_auiZscanToRaster[uiPartIdxRB];
5509
5510  if (( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth() )>= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )
5511  {
5512    riLCUIdxRBNb  = -1;
5513    riPartIdxRBNb = -1;
5514  }
5515  else if(( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxTmp] + m_pcPic->getMinCUHeight() )>= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
5516  {
5517    riLCUIdxRBNb  = -1;
5518    riPartIdxRBNb = -1;
5519  }
5520  else
5521  {
5522    if ( ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
5523      ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
5524    {
5525      riPartIdxRBNb = g_auiRasterToZscan[ uiAbsPartIdxTmp + uiNumPartInCUWidth + 1 ];
5526      riLCUIdxRBNb  = uiLCUIdx; 
5527    }
5528    else if ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
5529    {
5530      riPartIdxRBNb = -1;
5531      riLCUIdxRBNb  = -1;
5532    }
5533    else if ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
5534    {
5535      riPartIdxRBNb = g_auiRasterToZscan[ uiAbsPartIdxTmp + 1 ];
5536      riLCUIdxRBNb = uiLCUIdx + 1;
5537    }
5538    else //is the right bottom corner of LCU                       
5539    {
5540      riPartIdxRBNb = -1;
5541      riLCUIdxRBNb  = -1;
5542    }
5543  }
5544}
5545
5546
5547Void TComDataCU::setDvInfoSubParts( DisInfo cDvInfo, UInt uiAbsPartIdx, UInt uiDepth )
5548{
5549  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
5550  for (UInt ui = 0; ui < uiCurrPartNumb; ui++ )
5551  {
5552    m_pDvInfo[uiAbsPartIdx + ui] = cDvInfo;
5553  }
5554}
5555#if MTK_NBDV_TN_FIX_E0172
5556Bool TComDataCU::xGetColDisMV( Int currCandPic, RefPicList eRefPicList, Int refidx, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv , Int & iTargetViewIdx, Int & iStartViewIdx )
5557#else
5558Bool TComDataCU::xGetColDisMV( RefPicList eRefPicList, Int refidx, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv , Int & iTargetViewIdx, Int & iStartViewIdx )
5559#endif
5560{
5561
5562  RefPicList  eColRefPicList = REF_PIC_LIST_0;
5563  Int iColViewIdx, iColRefViewIdx;
5564  TComPic *pColPic = getSlice()->getRefPic( eRefPicList, refidx);
5565  TComDataCU *pColCU = pColPic->getCU( uiCUAddr );
5566  iColViewIdx = pColCU->getSlice()->getViewIndex();
5567  if (pColCU->getPic()==0||pColCU->getPartitionSize(uiPartUnitIdx)==SIZE_NONE||pColCU->isIntra(uiPartUnitIdx))
5568  {
5569    return false;
5570  }
5571  for (Int ilist = 0; ilist < (pColCU->getSlice()->isInterB()? 2:1); ilist++) 
5572  {
5573    if(pColCU->getSlice()->isInterB())
5574    {
5575        eColRefPicList = RefPicList(ilist);
5576    }
5577
5578    Int iColRefIdx = pColCU->getCUMvField(eColRefPicList)->getRefIdx(uiPartUnitIdx);
5579
5580    if (iColRefIdx < 0)
5581    {
5582      continue;
5583    }
5584
5585    iColRefViewIdx = pColCU->getSlice()->getRefPic(eColRefPicList, iColRefIdx)->getViewIndex();
5586
5587    if ( iColViewIdx    == iColRefViewIdx ) // temporal vector
5588    {
5589      continue;
5590    }
5591    else 
5592    {
5593#if MTK_NBDV_TN_FIX_E0172
5594      if(getPic()->isTempIVRefValid(currCandPic, ilist,  iColRefIdx))
5595      {
5596#endif
5597      rcMv = pColCU->getCUMvField(eColRefPicList)->getMv(uiPartUnitIdx);
5598      rcMv.setIDVFlag(0);
5599      iTargetViewIdx  = iColRefViewIdx ;
5600      iStartViewIdx   = iColViewIdx   ;
5601      return true;   
5602#if MTK_NBDV_TN_FIX_E0172
5603      }
5604#endif
5605    }
5606  }
5607
5608  return false;
5609}
5610#endif
5611#if H_3D_IV_MERGE
5612Bool
5613TComDataCU::getInterViewMergeCands(UInt uiPartIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv, DisInfo* pDInfo, Int* availableMcDc )
5614{
5615  TComSlice*    pcSlice         = getSlice (); 
5616  Int iViewIndex = pDInfo->m_aVIdxCan;
5617  //--- get base CU/PU and check prediction mode ---
5618  TComPic*    pcBasePic   = pcSlice->getIvPic( false, iViewIndex );
5619  TComPicYuv* pcBaseRec   = pcBasePic->getPicYuvRec   ();
5620
5621  UInt          uiPartAddr;
5622  Int           iWidth;
5623  Int           iHeight;
5624  getPartIndexAndSize( uiPartIdx, uiPartAddr, iWidth, iHeight );
5625
5626  Int  iCurrPosX, iCurrPosY;
5627  pcBaseRec->getTopLeftSamplePos( getAddr(), getZorderIdxInCU() + uiPartAddr, iCurrPosX, iCurrPosY );
5628
5629  iCurrPosX  += ( ( iWidth  - 1 ) >> 1 );
5630  iCurrPosY  += ( ( iHeight - 1 ) >> 1 );
5631
5632  Bool depthRefineFlag = false; 
5633#if H_3D_NBDV_REF
5634  depthRefineFlag = m_pcSlice->getVPS()->getDepthRefinementFlag( m_pcSlice->getLayerIdInVps() ); 
5635#endif // H_3D_NBDV_REF
5636
5637  TComMv      cDv = depthRefineFlag ? pDInfo->m_acDoNBDV : pDInfo->m_acNBDV; 
5638 
5639#if !QC_INRIA_MTK_MRG_E0126
5640  Int         iBasePosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (cDv.getHor() + 2 ) >> 2 ) );
5641  Int         iBasePosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (cDv.getVer() + 2 ) >> 2 )); 
5642
5643  Int         iBaseCUAddr;
5644  Int         iBaseAbsPartIdx;
5645  pcBaseRec->getCUAddrAndPartIdx( iBasePosX , iBasePosY , iBaseCUAddr, iBaseAbsPartIdx );
5646
5647  TComDataCU* pcBaseCU    = pcBasePic->getCU( iBaseCUAddr );
5648#endif
5649#if QC_INRIA_MTK_MRG_E0126
5650  Bool abPdmAvailable[8] =  {false, false, false, false, false, false, false, false};
5651#else
5652  Bool abPdmAvailable[4] = {false, false, false, false};
5653#endif
5654#if H_3D_NBDV
5655#if QC_INRIA_MTK_MRG_E0126
5656  for( Int i = 0; i < 8; i++)
5657#else
5658  for( Int i = 0; i < 4; i++)
5659#endif
5660  {
5661    pacPdmMv[i].setIDVFlag   (false);
5662  }
5663#endif
5664#if QC_INRIA_MTK_MRG_E0126
5665  for(Int iLoopCan = 0; iLoopCan < 2; iLoopCan ++)
5666  {
5667    Int         iBaseCUAddr;
5668    Int         iBaseAbsPartIdx;
5669
5670    Int offsetW = (iLoopCan == 0) ? 0 : ( ((iWidth/2)*4)  + 4 );
5671    Int offsetH = (iLoopCan == 0) ? 0 : ( ((iHeight/2)*4) + 4 );
5672   
5673    Int         iBasePosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (cDv.getHor() + offsetW + 2 ) >> 2 ) );
5674    Int         iBasePosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (cDv.getVer() + offsetH + 2 ) >> 2 ) ); 
5675    pcBaseRec->getCUAddrAndPartIdx( iBasePosX , iBasePosY , iBaseCUAddr, iBaseAbsPartIdx );
5676
5677    TComDataCU* pcBaseCU    = pcBasePic->getCU( iBaseCUAddr );
5678#endif
5679  if(!( pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) == MODE_INTRA ))
5680  {
5681    for( UInt uiCurrRefListId = 0; uiCurrRefListId < 2; uiCurrRefListId++ )
5682    {
5683      RefPicList  eCurrRefPicList = RefPicList( uiCurrRefListId );
5684
5685      Bool stopLoop = false;
5686      for(Int iLoop = 0; iLoop < 2 && !stopLoop; ++iLoop)
5687      {
5688        RefPicList eBaseRefPicList = (iLoop ==1)? RefPicList( 1 -  uiCurrRefListId ) : RefPicList( uiCurrRefListId );
5689        TComMvField cBaseMvField;
5690        pcBaseCU->getMvField( pcBaseCU, iBaseAbsPartIdx, eBaseRefPicList, cBaseMvField );
5691        Int         iBaseRefIdx     = cBaseMvField.getRefIdx();
5692        if (iBaseRefIdx >= 0)
5693        {
5694          Int iBaseRefPOC = pcBaseCU->getSlice()->getRefPOC(eBaseRefPicList, iBaseRefIdx);
5695          if (iBaseRefPOC != pcSlice->getPOC())   
5696          {
5697            for (Int iPdmRefIdx = 0; iPdmRefIdx < pcSlice->getNumRefIdx( eCurrRefPicList ); iPdmRefIdx++)
5698            {
5699              if (iBaseRefPOC == pcSlice->getRefPOC(eCurrRefPicList, iPdmRefIdx))
5700              {
5701#if QC_INRIA_MTK_MRG_E0126
5702                  abPdmAvailable[ (uiCurrRefListId + (iLoopCan<<2)) ] = true;
5703                  TComMv cMv(cBaseMvField.getHor(), cBaseMvField.getVer());
5704#if H_3D_NBDV
5705                  cMv.setIDVFlag   (true);
5706                  cMv.setIDVHor    (cDv.getHor());                 
5707                  cMv.setIDVVer    (cDv.getVer()); 
5708#if MTK_DVMCP_FIX_E0172
5709                  cMv.setIDVVId    (iViewIndex); 
5710#endif
5711#endif
5712                  clipMv( cMv );
5713                  paiPdmRefIdx  [ (uiCurrRefListId + (iLoopCan<<2)) ] = iPdmRefIdx;
5714                  pacPdmMv      [ (uiCurrRefListId + (iLoopCan<<2)) ] = cMv;
5715#else
5716                abPdmAvailable[ uiCurrRefListId ] = true;
5717                TComMv cMv(cBaseMvField.getHor(), cBaseMvField.getVer());
5718#if H_3D_NBDV
5719                cMv.setIDVFlag   (true);
5720                cMv.setIDVHor    (cDv.getHor());                 
5721                cMv.setIDVVer    (cDv.getVer()); 
5722#if MTK_DVMCP_FIX_E0172
5723                cMv.setIDVVId    (iViewIndex); 
5724#endif
5725#endif
5726                clipMv( cMv );
5727                paiPdmRefIdx  [ uiCurrRefListId ] = iPdmRefIdx;
5728                pacPdmMv      [ uiCurrRefListId ] = cMv;
5729#endif
5730                stopLoop = true;
5731                break;
5732              }
5733            }
5734          }
5735        }
5736      }
5737    }
5738  }
5739#if QC_INRIA_MTK_MRG_E0126
5740  }
5741#endif
5742#if QC_INRIA_MTK_MRG_E0126
5743  for(Int iLoopCan = 0; iLoopCan < 2; iLoopCan ++)
5744  {
5745    availableMcDc[(iLoopCan << 1)] = ( abPdmAvailable[(iLoopCan<<2)] ? 1 : 0 ) + ( abPdmAvailable[1 + (iLoopCan<<2)] ? 2 : 0);
5746  }
5747#else
5748  availableMcDc[0] = ( abPdmAvailable[0] ? 1 : 0 ) + ( abPdmAvailable[1] ? 2 : 0 );
5749#endif
5750  for( Int iRefListId = 0; iRefListId < 2 ; iRefListId++ )
5751  {
5752    RefPicList  eRefPicListDMV       = RefPicList( iRefListId );
5753    Int         iNumRefPics       = pcSlice->getNumRefIdx( eRefPicListDMV );
5754    for( Int iPdmRefIdx = 0; iPdmRefIdx < iNumRefPics; iPdmRefIdx++ )
5755    {
5756#if MTK_DIVMC_FIX_E0172
5757      if(( pcSlice->getRefPOC( eRefPicListDMV, iPdmRefIdx ) == pcSlice->getPOC()) && (pcSlice->getRefPic( eRefPicListDMV, iPdmRefIdx )->getViewIndex() == pDInfo->m_aVIdxCan))
5758#else
5759      if( pcSlice->getRefPOC( eRefPicListDMV, iPdmRefIdx ) == pcSlice->getPOC())
5760#endif
5761      {
5762#if QC_INRIA_MTK_MRG_E0126
5763        for(Int iLoopCan = 0; iLoopCan < 2; iLoopCan ++)
5764        {
5765          Int ioffsetDV = (iLoopCan == 0) ? 0 : 4;
5766          abPdmAvailable[ iRefListId + 2 + (iLoopCan<<2) ] = true;
5767          paiPdmRefIdx  [ iRefListId + 2 + (iLoopCan<<2) ] = iPdmRefIdx;
5768#if H_3D_NBDV_REF
5769          TComMv cMv = depthRefineFlag ? pDInfo->m_acDoNBDV : pDInfo->m_acNBDV; 
5770#endif
5771          cMv.setHor( cMv.getHor() + ioffsetDV );
5772          cMv.setVer( 0 );
5773          clipMv( cMv );
5774          pacPdmMv      [iRefListId + 2 + (iLoopCan<<2)] = cMv;
5775        }
5776        break;
5777#else
5778        abPdmAvailable[ iRefListId+2 ] = true;
5779        paiPdmRefIdx  [ iRefListId+2 ] = iPdmRefIdx;
5780
5781#if H_3D_NBDV_REF
5782        TComMv cMv = depthRefineFlag ? pDInfo->m_acDoNBDV : pDInfo->m_acNBDV; 
5783#endif // H_3D_NBDV_REF
5784        cMv.setVer(0);
5785        clipMv( cMv );
5786        pacPdmMv      [ iRefListId + 2] = cMv;
5787        break;
5788#endif
5789      }
5790    }
5791  }
5792#if QC_INRIA_MTK_MRG_E0126
5793  for(Int iLoopCan = 0; iLoopCan < 2; iLoopCan ++)
5794  {
5795    availableMcDc[1 + (iLoopCan << 1)] = ( abPdmAvailable[2 + (iLoopCan<<2)] ? 1 : 0 ) + ( abPdmAvailable[3 + (iLoopCan<<2)] ? 2 : 0 );
5796  }
5797#else
5798  availableMcDc[1] = ( abPdmAvailable[2] ? 1 : 0 ) + ( abPdmAvailable[3] ? 2 : 0 );
5799#endif
5800  return false;
5801}
5802#endif
5803#if H_3D_ARP
5804Void TComDataCU::setARPWSubParts ( UChar w, UInt uiAbsPartIdx, UInt uiDepth )
5805{
5806  assert( sizeof( *m_puhARPW) == 1 );
5807  memset( m_puhARPW + uiAbsPartIdx, w, m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ) );
5808}
5809#endif
5810
5811#if H_3D_IC
5812Void TComDataCU::setICFlagSubParts( Bool bICFlag, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
5813{
5814  memset( m_pbICFlag + uiAbsPartIdx, bICFlag, (m_pcPic->getNumPartInCU() >> ( 2 * uiDepth ))*sizeof(Bool) );
5815}
5816
5817Bool TComDataCU::isICFlagRequired( UInt uiAbsPartIdx )
5818{
5819  UInt uiPartAddr;
5820  UInt iNumbPart;
5821
5822  if( !( getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) )
5823  {
5824    return false;
5825  }
5826
5827  if( getSlice()->getIcSkipParseFlag() )
5828  {
5829    if( getMergeFlag( uiAbsPartIdx ) && getMergeIndex( uiAbsPartIdx ) == 0 )
5830    {
5831      return false;
5832    }
5833  }
5834
5835  if( getMergeFlag( uiAbsPartIdx ) )
5836  {
5837    return true;
5838  }
5839
5840
5841  Int iWidth, iHeight;
5842
5843  iNumbPart = ( getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ? 1 : ( getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ? 4 : 2 ) );
5844
5845  for(UInt i = 0; i < iNumbPart; i++)
5846  {
5847    getPartIndexAndSize( i, uiPartAddr, iWidth, iHeight, uiAbsPartIdx, true );
5848    uiPartAddr += uiAbsPartIdx;
5849
5850    for(UInt uiRefIdx = 0; uiRefIdx < 2; uiRefIdx++)
5851    {
5852      RefPicList eRefList = uiRefIdx ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
5853      Int iBestRefIdx = getCUMvField(eRefList)->getRefIdx(uiPartAddr);
5854
5855      if( ( getInterDir( uiPartAddr ) & ( uiRefIdx+1 ) ) && iBestRefIdx >= 0 && getSlice()->getViewIndex() != getSlice()->getRefPic( eRefList, iBestRefIdx )->getViewIndex() )
5856      {
5857        return true;
5858      }
5859    }
5860  }
5861
5862  return false;
5863}
5864#if H_3D_DIM_DMM
5865Void TComDataCU::setDmmWedgeTabIdxSubParts( UInt tabIdx, UInt dmmType, UInt uiAbsPartIdx, UInt uiDepth )
5866{
5867  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
5868  for( UInt ui = 0; ui < uiCurrPartNumb; ui++ ) { m_dmmWedgeTabIdx[dmmType][uiAbsPartIdx+ui] = tabIdx; }
5869}
5870Void  TComDataCU::setDmm2DeltaEndSubParts( Int iDelta, UInt uiAbsPartIdx, UInt uiDepth )
5871{
5872  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
5873  for( UInt ui = 0; ui < uiCurrPartNumb; ui++ ) { m_dmm2DeltaEnd[uiAbsPartIdx+ui] = iDelta; }
5874}
5875Void  TComDataCU::setDmm3IntraTabIdxSubParts( UInt uiTIdx, UInt uiAbsPartIdx, UInt uiDepth )
5876{
5877  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
5878  for( UInt ui = 0; ui < uiCurrPartNumb; ui++ ) { m_dmm3IntraTabIdx[uiAbsPartIdx+ui] = uiTIdx; }
5879}
5880#endif
5881#if H_3D_DIM_RBC
5882Void TComDataCU::reconPartition( UInt uiAbsPartIdx, UInt uiDepth, Bool bLeft, UChar ucStartPos, UChar ucNumEdge, UChar* pucEdgeCode, Bool* pbRegion )
5883{
5884  Int iWidth;
5885  Int iHeight;
5886  if( uiDepth == 0 )
5887  {
5888    iWidth = 64;
5889    iHeight = 64;
5890  }
5891  else if( uiDepth == 1 )
5892  {
5893    iWidth = 32;
5894    iHeight = 32;
5895  }
5896  else if( uiDepth == 2 )
5897  {
5898    iWidth = 16;
5899    iHeight = 16;
5900  }
5901  else if( uiDepth == 3 )
5902  {
5903    iWidth = 8;
5904    iHeight = 8;
5905  }
5906  else // uiDepth == 4
5907  {
5908    iWidth = 4;
5909    iHeight = 4;
5910  }
5911
5912  Int iPtr = 0;
5913  Int iX, iY;
5914  Int iDir = -1;
5915  Int iDiffX = 0, iDiffY = 0;
5916
5917  // 1. Edge Code -> Vert & Horz Edges
5918  Bool*  pbEdge = (Bool*) xMalloc( Bool, 4 * iWidth * iHeight );
5919
5920  for( UInt ui = 0; ui < 4 * iWidth * iHeight; ui++ )
5921    pbEdge  [ ui ] = false;
5922
5923  // Direction : left(0), right(1), top(2), bottom(3), left-top(4), right-top(5), left-bottom(6), right-bottom(7)
5924  // Code      : 0deg(0), 45deg(1), -45deg(2), 90deg(3), -90deg(4), 135deg(5), -135deg(6)
5925  const UChar tableDir[8][7] = { { 0, 6, 4, 3, 2, 7, 5 },
5926  { 1, 5, 7, 2, 3, 4, 6 },
5927  { 2, 4, 5, 0, 1, 6, 7 },
5928  { 3, 7, 6, 1, 0, 5, 4 },
5929  { 4, 0, 2, 6, 5, 3, 1 },
5930  { 5, 2, 1, 4, 7, 0, 3 },
5931  { 6, 3, 0, 7, 4, 1, 2 },
5932  { 7, 1, 3, 5, 6, 2, 0 }};
5933
5934  UChar ucCode = pucEdgeCode[iPtr++];
5935
5936  if( !bLeft )
5937  {
5938    iX = ucStartPos;
5939    iY = 0;
5940
5941    switch(ucCode)
5942    {
5943    case 0: // bottom
5944      iDir = 3;
5945      if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
5946      break;
5947    case 2: // left-bottom
5948      iDir = 6;
5949      if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
5950      break;
5951    case 1: // right-bottom
5952      iDir = 7;
5953      if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
5954      if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5955      break;
5956    case 4: // left
5957      iDir = 0;
5958      assert(false);
5959      break;
5960    case 3: // right
5961      iDir = 1;
5962      if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
5963      if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5964      break;
5965    }
5966  }
5967  else
5968  {
5969    iX = 0;
5970    iY = ucStartPos;
5971
5972    switch(ucCode)
5973    {
5974    case 0: // right
5975      iDir = 1;
5976      if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5977      break;
5978    case 1: // right-top
5979      iDir = 5;
5980      if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5981      if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
5982      break;
5983    case 2: // right-bottom
5984      iDir = 7;
5985      if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5986      break;
5987    case 3: // top
5988      iDir = 2;
5989      if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
5990      if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
5991      break;
5992    case 4: // bottom
5993      iDir = 3;
5994      assert(false);
5995      break;
5996    }
5997  }
5998
5999  switch( iDir )
6000  {
6001  case 0: // left
6002    iDiffX = -1;
6003    iDiffY = 0;
6004    break;
6005  case 1: // right
6006    iDiffX = +1;
6007    iDiffY = 0;
6008    break;
6009  case 2: // top
6010    iDiffX = 0;
6011    iDiffY = -1;
6012    break;
6013  case 3: // bottom
6014    iDiffX = 0;
6015    iDiffY = +1;
6016    break;
6017  case 4: // left-top
6018    iDiffX = -1;
6019    iDiffY = -1;
6020    break;
6021  case 5: // right-top
6022    iDiffX = +1;
6023    iDiffY = -1;
6024    break;
6025  case 6: // left-bottom
6026    iDiffX = -1;
6027    iDiffY = +1;
6028    break;
6029  case 7: // right-bottom
6030    iDiffX = +1;
6031    iDiffY = +1;
6032    break;
6033  }
6034
6035  iX += iDiffX;
6036  iY += iDiffY;
6037
6038  while( iPtr < ucNumEdge )
6039  {
6040    ucCode = pucEdgeCode[iPtr++];
6041
6042    Int iNewDir = tableDir[iDir][ucCode];
6043
6044    switch( iNewDir )
6045    {
6046    case 0: // left
6047      iDiffX = -1;
6048      iDiffY = 0;
6049      break;
6050    case 1: // right
6051      iDiffX = +1;
6052      iDiffY = 0;
6053      break;
6054    case 2: // top
6055      iDiffX = 0;
6056      iDiffY = -1;
6057      break;
6058    case 3: // bottom
6059      iDiffX = 0;
6060      iDiffY = +1;
6061      break;
6062    case 4: // left-top
6063      iDiffX = -1;
6064      iDiffY = -1;
6065      break;
6066    case 5: // right-top
6067      iDiffX = +1;
6068      iDiffY = -1;
6069      break;
6070    case 6: // left-bottom
6071      iDiffX = -1;
6072      iDiffY = +1;
6073      break;
6074    case 7: // right-bottom
6075      iDiffX = +1;
6076      iDiffY = +1;
6077      break;
6078    }
6079
6080    switch( iDir )
6081    {
6082    case 0: // left
6083      switch( ucCode )
6084      {
6085      case 0:
6086      case 2:
6087        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
6088        break;
6089      case 1:
6090      case 3:
6091        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
6092        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
6093        break;
6094      case 4:
6095      case 6:
6096        // no
6097        break;
6098      case 5:
6099        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
6100        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
6101        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
6102        break;
6103      }
6104      break;
6105    case 1: // right
6106      switch( ucCode )
6107      {
6108      case 0:
6109      case 2:
6110        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
6111        break;
6112      case 1:
6113      case 3:
6114        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
6115        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
6116        break;
6117      case 4:
6118      case 6:
6119        // no
6120        break;
6121      case 5:
6122        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
6123        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
6124        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
6125        break;
6126      }
6127      break;
6128    case 2: // top
6129      switch( ucCode )
6130      {
6131      case 0:
6132      case 2:
6133        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
6134        break;
6135      case 1:
6136      case 3:
6137        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
6138        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
6139        break;
6140      case 4:
6141      case 6:
6142        // no
6143        break;
6144      case 5:
6145        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
6146        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
6147        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
6148        break;
6149      }
6150      break;
6151    case 3: // bottom
6152      switch( ucCode )
6153      {
6154      case 0:
6155      case 2:
6156        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
6157        break;
6158      case 1:
6159      case 3:
6160        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
6161        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
6162        break;
6163      case 4:
6164      case 6:
6165        // no
6166        break;
6167      case 5:
6168        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
6169        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
6170        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
6171        break;
6172      }
6173      break;
6174    case 4: // left-top
6175      switch( ucCode )
6176      {
6177      case 0:
6178      case 1:
6179        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
6180        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
6181        break;
6182      case 2:
6183      case 4:
6184        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
6185        break;
6186      case 3:
6187      case 5:
6188        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
6189        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
6190        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
6191        break;
6192      case 6:
6193        // no
6194        break;
6195      }
6196      break;
6197    case 5: // right-top
6198      switch( ucCode )
6199      {
6200      case 0:
6201      case 1:
6202        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
6203        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
6204        break;
6205      case 2:
6206      case 4:
6207        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
6208        break;
6209      case 3:
6210      case 5:
6211        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
6212        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
6213        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
6214        break;
6215      case 6:
6216        // no
6217        break;
6218      }
6219      break;
6220    case 6: // left-bottom
6221      switch( ucCode )
6222      {
6223      case 0:
6224      case 1:
6225        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
6226        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
6227        break;
6228      case 2:
6229      case 4:
6230        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
6231        break;
6232      case 3:
6233      case 5:
6234        if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
6235        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
6236        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
6237        break;
6238      case 6:
6239        // no
6240        break;
6241      }
6242      break;
6243    case 7: // right-bottom
6244      switch( ucCode )
6245      {
6246      case 0:
6247      case 1:
6248        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
6249        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
6250        break;
6251      case 2:
6252      case 4:
6253        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
6254        break;
6255      case 3:
6256      case 5:
6257        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
6258        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
6259        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
6260        break;
6261      case 6:
6262        // no
6263        break;
6264      }
6265      break;
6266    }
6267
6268    assert( iX >= 0 && iX <= iWidth );
6269    assert( iY >= 0 && iY <= iHeight );
6270
6271    iX += iDiffX;
6272    iY += iDiffY;
6273    iDir = iNewDir;
6274  }
6275
6276  // finalize edge chain
6277  if( iX == iWidth-1 )
6278  {
6279    if( iY == 0 )
6280    {
6281      if( iDir == 1 )
6282      {
6283        pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
6284      }
6285      else if( iDir == 5 )
6286      {
6287        pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
6288      }
6289      else
6290      {
6291        assert(false);
6292      }
6293    }
6294    else if( iY == iHeight-1 )
6295    {
6296      if( iDir == 3 )
6297      {
6298        pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
6299      }
6300      else if( iDir == 7 )
6301      {
6302        pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
6303      }
6304      else
6305      {
6306        assert(false);
6307      }
6308    }
6309    else
6310    {
6311      if( iDir == 1 )
6312      {
6313        pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
6314      }
6315      else if( iDir == 3 )
6316      {
6317        pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
6318        pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
6319      }
6320      else if( iDir == 5 )
6321      {
6322        pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
6323      }
6324      else if( iDir == 7 )
6325      {
6326        pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
6327        pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
6328      }
6329      else
6330      {
6331        assert(false);
6332      }
6333    }
6334  }
6335  else if( iX == 0 )
6336  {
6337    if( iY == 0 )
6338    {
6339      if( iDir == 2 )
6340      {
6341        pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
6342      }
6343      else if( iDir == 4 )
6344      {
6345        pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
6346      }
6347      else
6348      {
6349        assert(false);
6350      }
6351    }
6352    else if( iY == iHeight-1 )
6353    {
6354      if( iDir == 0 )
6355      {
6356        pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
6357      }
6358      else if( iDir == 6 )
6359      {
6360        pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
6361      }
6362      else
6363      {
6364        assert(false);
6365      }
6366    }
6367    else
6368    {
6369      if( iDir == 0 )
6370      {
6371        pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
6372      }
6373      else if( iDir == 2 )
6374      {
6375        pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
6376        pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
6377      }
6378      else if( iDir == 4 )
6379      {
6380        pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
6381        pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
6382      }
6383      else if( iDir == 6 )
6384      {
6385        pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
6386      }
6387      else
6388      {
6389        assert(false);
6390      }
6391    }
6392  }
6393  else if( iY == 0 )
6394  {
6395    if( iDir == 1 )
6396    {
6397      pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
6398      pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
6399    }
6400    else if( iDir == 2 )
6401    {
6402      pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
6403    }
6404    else if( iDir == 4 )
6405    {
6406      pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
6407    }
6408    else if( iDir == 5 )
6409    {
6410      pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
6411      pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
6412    }
6413    else
6414    {
6415      assert(false);
6416    }
6417  }
6418  else if( iY == iHeight-1 )
6419  {
6420    if( iDir == 0 )
6421    {
6422      pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
6423      pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
6424    }
6425    else if( iDir == 3 )
6426    {
6427      pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
6428    }
6429    else if( iDir == 6 )
6430    {
6431      pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
6432      pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
6433    }
6434    else if( iDir == 7 )
6435    {
6436      pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
6437    }
6438    else
6439    {
6440      assert(false);
6441    }
6442  }
6443  else
6444  {
6445    printf("reconPartiton: wrong termination\n");
6446    assert(false);
6447  }
6448
6449  // Reconstruct Region from Chain Code
6450  Bool* pbVisit  = (Bool*) xMalloc( Bool, iWidth * iHeight );
6451  Int*  piStack  = (Int* ) xMalloc( Int,  iWidth * iHeight );
6452
6453  for( UInt ui = 0; ui < iWidth * iHeight; ui++ )
6454  {
6455    pbRegion[ ui ] = true; // fill it as region 1 (we'll discover region 0 next)
6456    pbVisit [ ui ] = false;
6457  }
6458
6459  iPtr = 0;
6460  piStack[iPtr++] = (0 << 8) | (0);
6461  pbRegion[ 0 ] = false;
6462
6463  while(iPtr > 0)
6464  {
6465    Int iTmp = piStack[--iPtr];
6466    Int iX1, iY1;
6467    iX1 = iTmp & 0xff;
6468    iY1 = (iTmp >> 8) & 0xff;
6469
6470    pbVisit[ iX1 + iY1 * iWidth ] = true;
6471
6472    assert( iX1 >= 0 && iX1 < iWidth );
6473    assert( iY1 >= 0 && iY1 < iHeight );
6474
6475    if( iX1 > 0 && !pbEdge[ 2 * iX1 - 1 + 4 * iY1 * iWidth ] && !pbVisit[ iX1 - 1 + iY1 * iWidth ] )
6476    {
6477      piStack[iPtr++] = (iY1 << 8) | (iX1 - 1);
6478      pbRegion[ iX1 - 1 + iY1 * iWidth ] = false;
6479    }
6480    if( iX1 < iWidth - 1 && !pbEdge[ 2 * iX1 + 1 + 4 * iY1 * iWidth ] && !pbVisit[ iX1 + 1 + iY1 * iWidth ] )
6481    {
6482      piStack[iPtr++] = (iY1 << 8) | (iX1 + 1);
6483      pbRegion[ iX1 + 1 + iY1 * iWidth ] = false;
6484    }
6485    if( iY1 > 0 && !pbEdge[ 2 * iX1 + 2 * (2 * iY1 - 1) * iWidth ] && !pbVisit[ iX1 + (iY1 - 1) * iWidth ] )
6486    {
6487      piStack[iPtr++] = ((iY1 - 1) << 8) | iX1;
6488      pbRegion[ iX1 + (iY1 - 1) * iWidth ] = false;
6489    }
6490    if( iY1 < iHeight - 1 && !pbEdge[ 2 * iX1 + 2 * (2 * iY1 + 1) * iWidth ] && !pbVisit[ iX1 + (iY1 + 1) * iWidth ] )
6491    {
6492      piStack[iPtr++] = ((iY1 + 1) << 8) | iX1;
6493      pbRegion[ iX1 + (iY1 + 1) * iWidth ] = false;
6494    }
6495  }
6496
6497  xFree( pbEdge );
6498  xFree( pbVisit );
6499  xFree( piStack );
6500}
6501#endif
6502#endif
6503
6504//! \}
Note: See TracBrowser for help on using the repository browser.