source: 3DVCSoftware/branches/HTM-14.1-update-dev3/source/Lib/TLibCommon/TComDataCU.cpp @ 1270

Last change on this file since 1270 was 1270, checked in by tech, 10 years ago

Merged 14.1-update-dev4-Qualcomm@1266

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