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

Last change on this file since 1255 was 1255, checked in by ntt, 10 years ago

Reactivation of VSP

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