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

Last change on this file since 1282 was 1282, checked in by tech, 9 years ago

Fixed pruning.

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