Changeset 1313 in 3DVCSoftware for trunk/source/Lib/TLibCommon/TComSlice.cpp


Ignore:
Timestamp:
13 Aug 2015, 17:38:13 (9 years ago)
Author:
tech
Message:

Merged 14.1-update-dev1@1312.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/Lib/TLibCommon/TComSlice.cpp

    r1196 r1313  
    1 /*  The copyright in this software is being made available under the BSD
     1/* The copyright in this software is being made available under the BSD
    22 * License, included below. This software may be subject to other third party
    33 * and contributor rights, including patent rights, and no such rights are
    4  * granted under this license. 
     4 * granted under this license.
    55 *
    6 * Copyright (c) 2010-2015, ITU/ISO/IEC
     6 * Copyright (c) 2010-2015, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    4242#include "TLibDecoder/TDecSbac.h"
    4343
     44
    4445//! \ingroup TLibCommon
    4546//! \{
    4647
    47 
    4848TComSlice::TComSlice()
    4949: m_iPPSId                        ( -1 )
    50 #if H_MV
     50, m_PicOutputFlag                 ( true )
     51#if NH_MV
    5152, m_slicePicOrderCntLsb           ( 0 )
    5253#endif
    5354, m_iPOC                          ( 0 )
    5455, m_iLastIDR                      ( 0 )
     56, m_iAssociatedIRAP               ( 0 )
     57, m_iAssociatedIRAPType           ( NAL_UNIT_INVALID )
     58, m_pRPS                          ( 0 )
     59, m_localRPS                      ( )
     60, m_rpsIdx                        ( 0 )
     61, m_RefPicListModification        ( )
    5562, m_eNalUnitType                  ( NAL_UNIT_CODED_SLICE_IDR_W_RADL )
    5663, m_eSliceType                    ( I_SLICE )
    5764, m_iSliceQp                      ( 0 )
    58 , m_dependentSliceSegmentFlag            ( false )
     65, m_dependentSliceSegmentFlag     ( false )
    5966#if ADAPTIVE_QP_SELECTION
    6067, m_iSliceQpBase                  ( 0 )
    6168#endif
    62 , m_deblockingFilterDisable        ( false )
    63 , m_deblockingFilterOverrideFlag   ( false )
    64 , m_deblockingFilterBetaOffsetDiv2 ( 0 )
    65 , m_deblockingFilterTcOffsetDiv2   ( 0 )
     69, m_ChromaQpAdjEnabled            ( false )
     70, m_deblockingFilterDisable       ( false )
     71, m_deblockingFilterOverrideFlag  ( false )
     72, m_deblockingFilterBetaOffsetDiv2( 0 )
     73, m_deblockingFilterTcOffsetDiv2  ( 0 )
    6674, m_bCheckLDC                     ( false )
    6775, m_iSliceQpDelta                 ( 0 )
    68 , m_iSliceQpDeltaCb               ( 0 )
    69 , m_iSliceQpDeltaCr               ( 0 )
    7076, m_iDepth                        ( 0 )
    7177, m_bRefenced                     ( false )
     78, m_pcVPS                         ( NULL )
    7279, m_pcSPS                         ( NULL )
    7380, m_pcPPS                         ( NULL )
    7481, m_pcPic                         ( NULL )
    75 , m_colFromL0Flag                 ( 1 )
    76 #if SETTING_NO_OUT_PIC_PRIOR
     82, m_colFromL0Flag                 ( true )
    7783, m_noOutputPriorPicsFlag         ( false )
    7884, m_noRaslOutputFlag              ( false )
    79 , m_handleCraAsBlaFlag              ( false )
    80 #endif
     85, m_handleCraAsBlaFlag            ( false )
    8186, m_colRefIdx                     ( 0 )
     87, m_maxNumMergeCand               ( 0 )
    8288, m_uiTLayer                      ( 0 )
    8389, m_bTLayerSwitchingFlag          ( false )
    84 , m_sliceMode                   ( 0 )
    85 , m_sliceArgument               ( 0 )
    86 , m_sliceCurStartCUAddr         ( 0 )
    87 , m_sliceCurEndCUAddr           ( 0 )
    88 , m_sliceIdx                    ( 0 )
    89 , m_sliceSegmentMode            ( 0 )
    90 , m_sliceSegmentArgument        ( 0 )
    91 , m_sliceSegmentCurStartCUAddr ( 0 )
    92 , m_sliceSegmentCurEndCUAddr    ( 0 )
    93 , m_nextSlice                    ( false )
    94 , m_nextSliceSegment             ( false )
    95 , m_sliceBits                   ( 0 )
    96 , m_sliceSegmentBits         ( 0 )
     90, m_sliceMode                     ( NO_SLICES )
     91, m_sliceArgument                 ( 0 )
     92, m_sliceCurStartCtuTsAddr        ( 0 )
     93, m_sliceCurEndCtuTsAddr          ( 0 )
     94, m_sliceIdx                      ( 0 )
     95, m_sliceSegmentMode              ( NO_SLICES )
     96, m_sliceSegmentArgument          ( 0 )
     97, m_sliceSegmentCurStartCtuTsAddr ( 0 )
     98, m_sliceSegmentCurEndCtuTsAddr   ( 0 )
     99, m_nextSlice                     ( false )
     100, m_nextSliceSegment              ( false )
     101, m_sliceBits                     ( 0 )
     102, m_sliceSegmentBits              ( 0 )
    97103, m_bFinalized                    ( false )
    98 , m_uiTileOffstForMultES          ( 0 )
    99 , m_puiSubstreamSizes             ( NULL )
     104, m_bTestWeightPred               ( false )
     105, m_bTestWeightBiPred             ( false )
     106, m_substreamSizes                ( )
    100107, m_cabacInitFlag                 ( false )
    101108, m_bLMvdL1Zero                   ( false )
    102 , m_numEntryPointOffsets          ( 0 )
    103109, m_temporalLayerNonReferenceFlag ( false )
     110, m_LFCrossSliceBoundaryFlag      ( false )
    104111, m_enableTMVPFlag                ( true )
    105 #if H_MV
     112, m_encCABACTableIdx              (I_SLICE)
     113#if NH_MV
    106114, m_availableForTMVPRefFlag       ( true )
    107 , m_refPicSetInterLayer0           ( NULL )
    108 , m_refPicSetInterLayer1           ( NULL )
     115, m_refPicSetInterLayer0          ( NULL )
     116, m_refPicSetInterLayer1          ( NULL )
    109117, m_layerId                       (0)
    110118, m_viewId                        (0)
    111119, m_viewIndex                     (0)
    112 #if H_3D
     120#if NH_3D
    113121, m_isDepth                       (false)
    114122#endif
     
    116124, m_pocResetFlag                  (false)
    117125#endif
    118 #if H_MV
     126#if NH_MV
    119127, m_crossLayerBlaFlag             (false)
    120128#endif
     
    122130, m_interLayerPredEnabledFlag     (false)
    123131, m_numInterLayerRefPicsMinus1    (0)
    124 #if H_MV
     132#if NH_MV
    125133, m_sliceSegmentHeaderExtensionLength (0)
    126 , m_pocResetIdc                       (0)
    127 , m_pocResetPeriodId                  (0)
    128 , m_fullPocResetFlag                  (false)
    129 , m_pocLsbVal                         (0)
    130 , m_pocMsbValPresentFlag              (false)
    131 , m_pocMsbVal                         (0)
    132 , m_pocMsbValRequiredFlag         ( false )
    133 #endif
    134 #if H_3D_IC
    135 , m_bApplyIC                      ( false )
    136 , m_icSkipParseFlag               ( false )
    137 #endif
    138 #if H_3D
    139 , m_inCmpPredFlag                 ( false )
    140 , m_numViews                        ( 0    )
    141 , m_depthToDisparityB             ( NULL )
    142 , m_depthToDisparityF             ( NULL )
    143 
     134, m_pocResetIdc                   (0)
     135, m_pocResetPeriodId              (0)
     136, m_fullPocResetFlag              (false)
     137, m_pocLsbVal                     (0)
     138, m_pocMsbValPresentFlag          (false)
     139, m_pocMsbVal                     (0)
     140, m_pocMsbValRequiredFlag         (false)
     141#endif
     142#if NH_3D_IC
     143, m_bApplyIC                      (false)
     144, m_icSkipParseFlag               (false)
     145#endif
     146#if NH_3D
     147, m_inCmpPredFlag                 (false)
     148, m_numViews                      (0)
     149, m_depthToDisparityB             (NULL)
     150, m_depthToDisparityF             (NULL)
     151#endif
     152#if NH_3D_DIS
    144153, m_bApplyDIS                     (false)
    145154#endif
    146155#endif
    147156{
    148   m_aiNumRefIdx[0] = m_aiNumRefIdx[1] = 0;
    149  
     157  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     158  {
     159    m_aiNumRefIdx[i] = 0;
     160  }
     161
     162  for (UInt component = 0; component < MAX_NUM_COMPONENT; component++)
     163  {
     164    m_lambdas            [component] = 0.0;
     165    m_iSliceChromaQpDelta[component] = 0;
     166  }
     167
    150168  initEqualRef();
    151  
    152   for (Int component = 0; component < 3; component++)
    153   {
    154     m_lambdas[component] = 0.0;
    155   }
    156  
     169
    157170  for ( Int idx = 0; idx < MAX_NUM_REF; idx++ )
    158171  {
    159172    m_list1IdxToList0Idx[idx] = -1;
    160173  }
     174
    161175  for(Int iNumCount = 0; iNumCount < MAX_NUM_REF; iNumCount++)
    162176  {
    163     m_apcRefPicList [0][iNumCount] = NULL;
    164     m_apcRefPicList [1][iNumCount] = NULL;
    165     m_aiRefPOCList  [0][iNumCount] = 0;
    166     m_aiRefPOCList  [1][iNumCount] = 0;
    167 #if H_MV
     177    for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     178    {
     179      m_apcRefPicList [i][iNumCount] = NULL;
     180      m_aiRefPOCList  [i][iNumCount] = 0;
     181    }
     182#if NH_MV
    168183    m_aiRefLayerIdList[0][iNumCount] = 0;
    169184    m_aiRefLayerIdList[1][iNumCount] = 0;
    170185#endif
    171186  }
     187
    172188  resetWpScaling();
    173189  initWpAcDcParam();
    174   m_saoEnabledFlag = false;
    175   m_saoEnabledFlagChroma = false;
    176 #if H_MV
     190
     191  for(Int ch=0; ch < MAX_NUM_CHANNEL_TYPE; ch++)
     192  {
     193    m_saoEnabledFlag[ch] = false;
     194  }
     195#if NH_MV
    177196  for (Int i = 0; i < MAX_NUM_LAYERS; i++ )
    178197  {
     
    180199  }
    181200#endif
     201#if NH_3D
    182202  m_iDefaultRefViewIdx = -1;
    183203  m_bDefaultRefViewIdxAvailableFlag = false;
    184 #if H_3D
    185204  m_ivMvPredFlag           = false;
    186205  m_ivMvScalingFlag        = false;
     
    197216  m_subPbSize              =  1 << 6;
    198217  m_mpiSubPbSize           =  1 << 6;
    199 #endif
     218
     219  m_aaiCodedOffset.resize(2);
     220  m_aaiCodedScale .resize(2);
     221  for (Int i = 0; i < 2; i++)
     222  {
     223    m_aaiCodedOffset[i].resize(MAX_NUM_LAYERS);
     224    m_aaiCodedScale [i].resize(MAX_NUM_LAYERS);
     225  }
     226 
     227#endif
     228
    200229}
    201230
    202231TComSlice::~TComSlice()
    203232{
    204   delete[] m_puiSubstreamSizes;
    205   m_puiSubstreamSizes = NULL;
    206 #if H_3D
     233#if NH_3D
    207234  for( UInt i = 0; i < m_numViews; i++ )
    208235  {
     
    230257  m_depthToDisparityB = NULL;
    231258#endif
     259
    232260}
    233261
     
    235263Void TComSlice::initSlice()
    236264{
    237   m_aiNumRefIdx[0]      = 0;
    238   m_aiNumRefIdx[1]      = 0;
    239  
    240   m_colFromL0Flag = 1;
    241  
     265  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     266  {
     267    m_aiNumRefIdx[i]      = 0;
     268  }
     269  m_colFromL0Flag = true;
     270
    242271  m_colRefIdx = 0;
    243272  initEqualRef();
     273
    244274  m_bCheckLDC = false;
    245   m_iSliceQpDeltaCb = 0;
    246   m_iSliceQpDeltaCr = 0;
    247 
    248 #if H_3D_IV_MERGE
     275
     276  for (UInt component = 0; component < MAX_NUM_COMPONENT; component++)
     277  {
     278    m_iSliceChromaQpDelta[component] = 0;
     279  }
     280#if NH_3D_IV_MERGE
    249281  m_maxNumMergeCand = MRG_MAX_NUM_CANDS_MEM;
    250282#else
     
    254286  m_bFinalized=false;
    255287
    256   m_tileByteLocation.clear();
     288  m_substreamSizes.clear();
    257289  m_cabacInitFlag        = false;
    258   m_numEntryPointOffsets = 0;
    259290  m_enableTMVPFlag = true;
    260 #if H_3D_TMVP
     291#if NH_3D_TMVP
    261292  m_aiAlterRefIdx[0]                  = -1;
    262293  m_aiAlterRefIdx[1]                  = -1;
     
    264295}
    265296
    266 Bool TComSlice::getRapPicFlag()
     297Bool TComSlice::getRapPicFlag() const
    267298{
    268299  return getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL
     
    274305}
    275306
    276 /**
    277  - allocate table to contain substream sizes to be written to the slice header.
    278  .
    279  \param uiNumSubstreams Number of substreams -- the allocation will be this value - 1.
    280  */
    281 Void  TComSlice::allocSubstreamSizes(UInt uiNumSubstreams)
    282 {
    283   delete[] m_puiSubstreamSizes;
    284   m_puiSubstreamSizes = new UInt[uiNumSubstreams > 0 ? uiNumSubstreams-1 : 0];
    285 }
    286307
    287308Void  TComSlice::sortPicList        (TComList<TComPic*>& rcListPic)
     
    289310  TComPic*    pcPicExtract;
    290311  TComPic*    pcPicInsert;
    291  
     312
    292313  TComList<TComPic*>::iterator    iterPicExtract;
    293314  TComList<TComPic*>::iterator    iterPicExtract_1;
    294315  TComList<TComPic*>::iterator    iterPicInsert;
    295  
     316
    296317  for (Int i = 1; i < (Int)(rcListPic.size()); i++)
    297318  {
    298319    iterPicExtract = rcListPic.begin();
    299     for (Int j = 0; j < i; j++) iterPicExtract++;
     320    for (Int j = 0; j < i; j++)
     321    {
     322      iterPicExtract++;
     323    }
    300324    pcPicExtract = *(iterPicExtract);
    301325    pcPicExtract->setCurrSliceIdx(0);
    302    
     326
    303327    iterPicInsert = rcListPic.begin();
    304328    while (iterPicInsert != iterPicExtract)
     
    310334        break;
    311335      }
    312      
     336
    313337      iterPicInsert++;
    314338    }
    315    
     339
    316340    iterPicExtract_1 = iterPicExtract;    iterPicExtract_1++;
    317    
     341
    318342    //  swap iterPicExtract and iterPicInsert, iterPicExtract = curr. / iterPicInsert = insertion position
    319343    rcListPic.insert (iterPicInsert, iterPicExtract, iterPicExtract_1);
     
    322346}
    323347
    324 TComPic* TComSlice::xGetRefPic (TComList<TComPic*>& rcListPic,
    325                                 Int                 poc)
    326 {
    327   TComList<TComPic*>::iterator  iterPic = rcListPic.begin(); 
     348TComPic* TComSlice::xGetRefPic (TComList<TComPic*>& rcListPic, Int poc)
     349{
     350  TComList<TComPic*>::iterator  iterPic = rcListPic.begin();
    328351  TComPic*                      pcPic = *(iterPic);
    329352  while ( iterPic != rcListPic.end() )
     
    342365TComPic* TComSlice::xGetLongTermRefPic(TComList<TComPic*>& rcListPic, Int poc, Bool pocHasMsb)
    343366{
    344   TComList<TComPic*>::iterator  iterPic = rcListPic.begin(); 
     367  TComList<TComPic*>::iterator  iterPic = rcListPic.begin();
    345368  TComPic*                      pcPic = *(iterPic);
    346369  TComPic*                      pcStPic = pcPic;
    347  
     370
    348371  Int pocCycle = 1 << getSPS()->getBitsForPOC();
    349372  if (!pocHasMsb)
     
    351374    poc = poc & (pocCycle - 1);
    352375  }
    353  
     376
    354377  while ( iterPic != rcListPic.end() )
    355378  {
     
    362385        picPoc = picPoc & (pocCycle - 1);
    363386      }
    364      
     387
    365388      if (poc == picPoc)
    366     {
    367       if(pcPic->getIsLongTerm())
    368       {
    369         return pcPic;
    370       }
    371       else
    372       {
    373         pcStPic = pcPic;
    374       }
    375       break;
    376     }
     389      {
     390        if(pcPic->getIsLongTerm())
     391        {
     392          return pcPic;
     393        }
     394        else
     395        {
     396          pcStPic = pcPic;
     397        }
     398        break;
     399      }
    377400    }
    378401
    379402    iterPic++;
    380403  }
    381  
     404
    382405  return  pcStPic;
    383406}
     
    385408Void TComSlice::setRefPOCList       ()
    386409{
    387   for (Int iDir = 0; iDir < 2; iDir++)
     410  for (Int iDir = 0; iDir < NUM_REF_PIC_LIST_01; iDir++)
    388411  {
    389412    for (Int iNumRefIdx = 0; iNumRefIdx < m_aiNumRefIdx[iDir]; iNumRefIdx++)
    390413    {
    391414      m_aiRefPOCList[iDir][iNumRefIdx] = m_apcRefPicList[iDir][iNumRefIdx]->getPOC();
    392 #if H_MV
     415#if NH_MV
    393416      m_aiRefLayerIdList[iDir][iNumRefIdx] = m_apcRefPicList[iDir][iNumRefIdx]->getLayerId();
    394417#endif
     
    415438}
    416439
    417 #if !H_MV
     440#if !NH_MV
    418441Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr )
    419442{
     
    428451    }
    429452
     453    m_aiNumRefIdx[REF_PIC_LIST_0] = getNumRefIdx(REF_PIC_LIST_0);
     454    m_aiNumRefIdx[REF_PIC_LIST_1] = getNumRefIdx(REF_PIC_LIST_1);
     455  }
     456
     457  TComPic*  pcRefPic= NULL;
     458  static const UInt MAX_NUM_NEGATIVE_PICTURES=16;
     459  TComPic*  RefPicSetStCurr0[MAX_NUM_NEGATIVE_PICTURES];
     460  TComPic*  RefPicSetStCurr1[MAX_NUM_NEGATIVE_PICTURES];
     461  TComPic*  RefPicSetLtCurr[MAX_NUM_NEGATIVE_PICTURES];
     462  UInt NumPicStCurr0 = 0;
     463  UInt NumPicStCurr1 = 0;
     464  UInt NumPicLtCurr = 0;
     465  Int i;
     466
     467  for(i=0; i < m_pRPS->getNumberOfNegativePictures(); i++)
     468  {
     469    if(m_pRPS->getUsed(i))
     470    {
     471      pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pRPS->getDeltaPOC(i));
     472      pcRefPic->setIsLongTerm(0);
     473      pcRefPic->getPicYuvRec()->extendPicBorder();
     474      RefPicSetStCurr0[NumPicStCurr0] = pcRefPic;
     475      NumPicStCurr0++;
     476      pcRefPic->setCheckLTMSBPresent(false);
     477    }
     478  }
     479
     480  for(; i < m_pRPS->getNumberOfNegativePictures()+m_pRPS->getNumberOfPositivePictures(); i++)
     481  {
     482    if(m_pRPS->getUsed(i))
     483    {
     484      pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pRPS->getDeltaPOC(i));
     485      pcRefPic->setIsLongTerm(0);
     486      pcRefPic->getPicYuvRec()->extendPicBorder();
     487      RefPicSetStCurr1[NumPicStCurr1] = pcRefPic;
     488      NumPicStCurr1++;
     489      pcRefPic->setCheckLTMSBPresent(false);
     490    }
     491  }
     492
     493  for(i = m_pRPS->getNumberOfNegativePictures()+m_pRPS->getNumberOfPositivePictures()+m_pRPS->getNumberOfLongtermPictures()-1; i > m_pRPS->getNumberOfNegativePictures()+m_pRPS->getNumberOfPositivePictures()-1 ; i--)
     494  {
     495    if(m_pRPS->getUsed(i))
     496    {
     497      pcRefPic = xGetLongTermRefPic(rcListPic, m_pRPS->getPOC(i), m_pRPS->getCheckLTMSBPresent(i));
     498      pcRefPic->setIsLongTerm(1);
     499      pcRefPic->getPicYuvRec()->extendPicBorder();
     500      RefPicSetLtCurr[NumPicLtCurr] = pcRefPic;
     501      NumPicLtCurr++;
     502    }
     503    if(pcRefPic==NULL)
     504    {
     505      pcRefPic = xGetLongTermRefPic(rcListPic, m_pRPS->getPOC(i), m_pRPS->getCheckLTMSBPresent(i));
     506    }
     507    pcRefPic->setCheckLTMSBPresent(m_pRPS->getCheckLTMSBPresent(i));
     508  }
     509
     510  // ref_pic_list_init
     511  TComPic*  rpsCurrList0[MAX_NUM_REF+1];
     512  TComPic*  rpsCurrList1[MAX_NUM_REF+1];
     513  Int numPicTotalCurr = NumPicStCurr0 + NumPicStCurr1 + NumPicLtCurr;
     514
     515  if (checkNumPocTotalCurr)
     516  {
     517    // The variable NumPocTotalCurr is derived as specified in subclause 7.4.7.2. It is a requirement of bitstream conformance that the following applies to the value of NumPocTotalCurr:
     518    // - If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0.
     519    // - Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
     520    if (getRapPicFlag())
     521    {
     522      assert(numPicTotalCurr == 0);
     523    }
     524
     525    if (m_eSliceType == I_SLICE)
     526    {
     527      ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList));
     528      ::memset( m_aiNumRefIdx,   0, sizeof ( m_aiNumRefIdx ));
     529
     530      return;
     531    }
     532
     533    assert(numPicTotalCurr > 0);
     534    // general tier and level limit:
     535    assert(numPicTotalCurr <= 8);
     536
    430537    m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0);
    431538    m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1);
     539  }
     540
     541  Int cIdx = 0;
     542  for ( i=0; i<NumPicStCurr0; i++, cIdx++)
     543  {
     544    rpsCurrList0[cIdx] = RefPicSetStCurr0[i];
     545  }
     546  for ( i=0; i<NumPicStCurr1; i++, cIdx++)
     547  {
     548    rpsCurrList0[cIdx] = RefPicSetStCurr1[i];
     549  }
     550  for ( i=0; i<NumPicLtCurr;  i++, cIdx++)
     551  {
     552    rpsCurrList0[cIdx] = RefPicSetLtCurr[i];
     553  }
     554  assert(cIdx == numPicTotalCurr);
     555
     556  if (m_eSliceType==B_SLICE)
     557  {
     558    cIdx = 0;
     559    for ( i=0; i<NumPicStCurr1; i++, cIdx++)
     560    {
     561      rpsCurrList1[cIdx] = RefPicSetStCurr1[i];
     562    }
     563    for ( i=0; i<NumPicStCurr0; i++, cIdx++)
     564    {
     565      rpsCurrList1[cIdx] = RefPicSetStCurr0[i];
     566    }
     567    for ( i=0; i<NumPicLtCurr;  i++, cIdx++)
     568    {
     569      rpsCurrList1[cIdx] = RefPicSetLtCurr[i];
     570    }
     571    assert(cIdx == numPicTotalCurr);
     572  }
     573
     574  ::memset(m_bIsUsedAsLongTerm, 0, sizeof(m_bIsUsedAsLongTerm));
     575
     576  for (Int rIdx = 0; rIdx < m_aiNumRefIdx[REF_PIC_LIST_0]; rIdx ++)
     577  {
     578    cIdx = m_RefPicListModification.getRefPicListModificationFlagL0() ? m_RefPicListModification.getRefPicSetIdxL0(rIdx) : rIdx % numPicTotalCurr;
     579    assert(cIdx >= 0 && cIdx < numPicTotalCurr);
     580    m_apcRefPicList[REF_PIC_LIST_0][rIdx] = rpsCurrList0[ cIdx ];
     581    m_bIsUsedAsLongTerm[REF_PIC_LIST_0][rIdx] = ( cIdx >= NumPicStCurr0 + NumPicStCurr1 );
     582  }
     583  if ( m_eSliceType != B_SLICE )
     584  {
     585    m_aiNumRefIdx[REF_PIC_LIST_1] = 0;
     586    ::memset( m_apcRefPicList[REF_PIC_LIST_1], 0, sizeof(m_apcRefPicList[REF_PIC_LIST_1]));
     587  }
     588  else
     589  {
     590    for (Int rIdx = 0; rIdx < m_aiNumRefIdx[REF_PIC_LIST_1]; rIdx ++)
     591    {
     592      cIdx = m_RefPicListModification.getRefPicListModificationFlagL1() ? m_RefPicListModification.getRefPicSetIdxL1(rIdx) : rIdx % numPicTotalCurr;
     593      assert(cIdx >= 0 && cIdx < numPicTotalCurr);
     594      m_apcRefPicList[REF_PIC_LIST_1][rIdx] = rpsCurrList1[ cIdx ];
     595      m_bIsUsedAsLongTerm[REF_PIC_LIST_1][rIdx] = ( cIdx >= NumPicStCurr0 + NumPicStCurr1 );
     596    }
     597  }
     598}
     599#else
     600Void TComSlice::getTempRefPicLists( TComList<TComPic*>& rcListPic, std::vector<TComPic*>& refPicSetInterLayer0, std::vector<TComPic*>& refPicSetInterLayer1,                                     
     601                                   std::vector<TComPic*> rpsCurrList[2], std::vector<Bool> usedAsLongTerm[2], Int& numPocTotalCurr, Bool checkNumPocTotalCurr )
     602{
     603  if (!checkNumPocTotalCurr)
     604  {
     605    if (m_eSliceType == I_SLICE)
     606    {     
     607      return;
     608    }   
    432609  }
    433610
     
    440617  UInt NumPocLtCurr = 0;
    441618  Int i;
    442 
    443   for(i=0; i < m_pcRPS->getNumberOfNegativePictures(); i++)
    444   {
    445     if(m_pcRPS->getUsed(i))
    446     {
    447       pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i));
     619#if NH_3D
     620  m_pocsInCurrRPSs.clear();
     621#endif
     622  for(i=0; i < m_pRPS->getNumberOfNegativePictures(); i++)
     623  {
     624    if(m_pRPS->getUsed(i))
     625    {
     626      pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pRPS->getDeltaPOC(i));
    448627      pcRefPic->setIsLongTerm(0);
    449628      pcRefPic->getPicYuvRec()->extendPicBorder();
     
    451630      NumPocStCurr0++;
    452631      pcRefPic->setCheckLTMSBPresent(false); 
    453     }
    454   }
    455 
    456   for(; i < m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures(); i++)
    457   {
    458     if(m_pcRPS->getUsed(i))
    459     {
    460       pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i));
     632#if NH_3D
     633      m_pocsInCurrRPSs.push_back( pcRefPic->getPOC() );
     634#endif
     635    }
     636  }
     637 
     638  for(; i < m_pRPS->getNumberOfNegativePictures()+m_pRPS->getNumberOfPositivePictures(); i++)
     639  {
     640    if(m_pRPS->getUsed(i))
     641    {
     642      pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pRPS->getDeltaPOC(i));
    461643      pcRefPic->setIsLongTerm(0);
    462644      pcRefPic->getPicYuvRec()->extendPicBorder();
     
    464646      NumPocStCurr1++;
    465647      pcRefPic->setCheckLTMSBPresent(false); 
    466     }
    467   }
    468 
    469   for(i = m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()+m_pcRPS->getNumberOfLongtermPictures()-1; i > m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()-1 ; i--)
    470   {
    471     if(m_pcRPS->getUsed(i))
    472     {
    473       pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i));
     648#if NH_3D
     649      m_pocsInCurrRPSs.push_back( pcRefPic->getPOC() );
     650#endif
     651    }
     652  }
     653 
     654  for(i = m_pRPS->getNumberOfNegativePictures()+m_pRPS->getNumberOfPositivePictures()+m_pRPS->getNumberOfLongtermPictures()-1; i > m_pRPS->getNumberOfNegativePictures()+m_pRPS->getNumberOfPositivePictures()-1 ; i--)
     655  {
     656    if(m_pRPS->getUsed(i))
     657    {
     658      pcRefPic = xGetLongTermRefPic(rcListPic, m_pRPS->getPOC(i), m_pRPS->getCheckLTMSBPresent(i));
    474659      pcRefPic->setIsLongTerm(1);
    475660      pcRefPic->getPicYuvRec()->extendPicBorder();
    476661      RefPicSetLtCurr[NumPocLtCurr] = pcRefPic;
    477662      NumPocLtCurr++;
     663#if NH_3D
     664      m_pocsInCurrRPSs.push_back( pcRefPic->getPOC() );
     665#endif
    478666    }
    479667    if(pcRefPic==NULL)
    480668    {
    481       pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i));
    482     }
    483     pcRefPic->setCheckLTMSBPresent(m_pcRPS->getCheckLTMSBPresent(i)); 
    484   }
    485 
    486   // ref_pic_list_init
    487   TComPic*  rpsCurrList0[MAX_NUM_REF+1];
    488   TComPic*  rpsCurrList1[MAX_NUM_REF+1];
    489   Int numPocTotalCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr;
    490   if (checkNumPocTotalCurr)
    491   {
    492     // The variable NumPocTotalCurr is derived as specified in subclause 7.4.7.2. It is a requirement of bitstream conformance that the following applies to the value of NumPocTotalCurr:
    493     // - If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0.
    494     // - Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
    495     if (getRapPicFlag())
    496     {
    497       assert(numPocTotalCurr == 0);
    498     }
    499 
    500     if (m_eSliceType == I_SLICE)
    501     {
    502       ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList));
    503       ::memset( m_aiNumRefIdx,   0, sizeof ( m_aiNumRefIdx ));
    504 
    505       return;
    506     }
    507 
    508     assert(numPocTotalCurr > 0);
    509 
    510     m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0);
    511     m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1);
    512   }
    513 
    514   Int cIdx = 0;
    515   for ( i=0; i<NumPocStCurr0; i++, cIdx++)
    516   {
    517     rpsCurrList0[cIdx] = RefPicSetStCurr0[i];
    518   }
    519   for ( i=0; i<NumPocStCurr1; i++, cIdx++)
    520   {
    521     rpsCurrList0[cIdx] = RefPicSetStCurr1[i];
    522   }
    523   for ( i=0; i<NumPocLtCurr;  i++, cIdx++)
    524   {
    525     rpsCurrList0[cIdx] = RefPicSetLtCurr[i];
    526   }
    527   assert(cIdx == numPocTotalCurr);
    528 
    529   if (m_eSliceType==B_SLICE)
    530   {
    531     cIdx = 0;
    532     for ( i=0; i<NumPocStCurr1; i++, cIdx++)
    533     {
    534       rpsCurrList1[cIdx] = RefPicSetStCurr1[i];
    535     }
    536     for ( i=0; i<NumPocStCurr0; i++, cIdx++)
    537     {
    538       rpsCurrList1[cIdx] = RefPicSetStCurr0[i];
    539     }
    540     for ( i=0; i<NumPocLtCurr;  i++, cIdx++)
    541     {
    542       rpsCurrList1[cIdx] = RefPicSetLtCurr[i];
    543     }
    544     assert(cIdx == numPocTotalCurr);
    545   }
    546 
    547   ::memset(m_bIsUsedAsLongTerm, 0, sizeof(m_bIsUsedAsLongTerm));
    548 
    549   for (Int rIdx = 0; rIdx < m_aiNumRefIdx[0]; rIdx ++)
    550   {
    551     cIdx = m_RefPicListModification.getRefPicListModificationFlagL0() ? m_RefPicListModification.getRefPicSetIdxL0(rIdx) : rIdx % numPocTotalCurr;
    552     assert(cIdx >= 0 && cIdx < numPocTotalCurr);
    553     m_apcRefPicList[0][rIdx] = rpsCurrList0[ cIdx ];
    554     m_bIsUsedAsLongTerm[0][rIdx] = ( cIdx >= NumPocStCurr0 + NumPocStCurr1 );
    555   }
    556   if ( m_eSliceType != B_SLICE )
    557   {
    558     m_aiNumRefIdx[1] = 0;
    559     ::memset( m_apcRefPicList[1], 0, sizeof(m_apcRefPicList[1]));
    560   }
    561   else
    562   {
    563     for (Int rIdx = 0; rIdx < m_aiNumRefIdx[1]; rIdx ++)
    564     {
    565       cIdx = m_RefPicListModification.getRefPicListModificationFlagL1() ? m_RefPicListModification.getRefPicSetIdxL1(rIdx) : rIdx % numPocTotalCurr;
    566       assert(cIdx >= 0 && cIdx < numPocTotalCurr);
    567       m_apcRefPicList[1][rIdx] = rpsCurrList1[ cIdx ];
    568       m_bIsUsedAsLongTerm[1][rIdx] = ( cIdx >= NumPocStCurr0 + NumPocStCurr1 );
    569     }
    570   }
    571 }
    572 
    573 #else
    574 Void TComSlice::getTempRefPicLists( TComList<TComPic*>& rcListPic, std::vector<TComPic*>& refPicSetInterLayer0, std::vector<TComPic*>& refPicSetInterLayer1,                                     
    575                                    std::vector<TComPic*> rpsCurrList[2], std::vector<Bool> usedAsLongTerm[2], Int& numPocTotalCurr, Bool checkNumPocTotalCurr )
    576 {
    577   if (!checkNumPocTotalCurr)
    578   {
    579     if (m_eSliceType == I_SLICE)
    580     {     
    581       return;
    582     }   
    583   }
    584 
    585   TComPic*  pcRefPic= NULL;
    586   TComPic*  RefPicSetStCurr0[16];
    587   TComPic*  RefPicSetStCurr1[16];
    588   TComPic*  RefPicSetLtCurr[16];
    589   UInt NumPocStCurr0 = 0;
    590   UInt NumPocStCurr1 = 0;
    591   UInt NumPocLtCurr = 0;
    592   Int i;
    593 #if H_3D
    594   m_pocsInCurrRPSs.clear();
    595 #endif
    596   for(i=0; i < m_pcRPS->getNumberOfNegativePictures(); i++)
    597   {
    598     if(m_pcRPS->getUsed(i))
    599     {
    600       pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i));
    601       pcRefPic->setIsLongTerm(0);
    602       pcRefPic->getPicYuvRec()->extendPicBorder();
    603       RefPicSetStCurr0[NumPocStCurr0] = pcRefPic;
    604       NumPocStCurr0++;
    605       pcRefPic->setCheckLTMSBPresent(false); 
    606 #if H_3D
    607       m_pocsInCurrRPSs.push_back( pcRefPic->getPOC() );
    608 #endif
    609     }
    610   }
    611  
    612   for(; i < m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures(); i++)
    613   {
    614     if(m_pcRPS->getUsed(i))
    615     {
    616       pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i));
    617       pcRefPic->setIsLongTerm(0);
    618       pcRefPic->getPicYuvRec()->extendPicBorder();
    619       RefPicSetStCurr1[NumPocStCurr1] = pcRefPic;
    620       NumPocStCurr1++;
    621       pcRefPic->setCheckLTMSBPresent(false); 
    622 #if H_3D
    623       m_pocsInCurrRPSs.push_back( pcRefPic->getPOC() );
    624 #endif
    625     }
    626   }
    627  
    628   for(i = m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()+m_pcRPS->getNumberOfLongtermPictures()-1; i > m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()-1 ; i--)
    629   {
    630     if(m_pcRPS->getUsed(i))
    631     {
    632       pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i));
    633       pcRefPic->setIsLongTerm(1);
    634       pcRefPic->getPicYuvRec()->extendPicBorder();
    635       RefPicSetLtCurr[NumPocLtCurr] = pcRefPic;
    636       NumPocLtCurr++;
    637 #if H_3D
    638       m_pocsInCurrRPSs.push_back( pcRefPic->getPOC() );
    639 #endif
    640     }
    641     if(pcRefPic==NULL)
    642     {
    643       pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i));
    644     }
    645     pcRefPic->setCheckLTMSBPresent(m_pcRPS->getCheckLTMSBPresent(i)); 
     669      pcRefPic = xGetLongTermRefPic(rcListPic, m_pRPS->getPOC(i), m_pRPS->getCheckLTMSBPresent(i));
     670    }
     671    pcRefPic->setCheckLTMSBPresent(m_pRPS->getCheckLTMSBPresent(i)); 
    646672  }
    647673
    648674  Int numPocInterCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr;
    649 #if H_3D
     675#if NH_3D
    650676  assert( numPocInterCurr == (Int) m_pocsInCurrRPSs.size() );
    651677#endif
     
    763789}
    764790#endif
    765 Int TComSlice::getNumRpsCurrTempList()
     791
     792Int TComSlice::getNumRpsCurrTempList() const
    766793{
    767794  Int numRpsCurrTempList = 0;
    768795
    769   if (m_eSliceType == I_SLICE) 
     796  if (m_eSliceType == I_SLICE)
    770797  {
    771798    return 0;
    772799  }
    773   for(UInt i=0; i < m_pcRPS->getNumberOfNegativePictures()+ m_pcRPS->getNumberOfPositivePictures() + m_pcRPS->getNumberOfLongtermPictures(); i++)
    774   {
    775     if(m_pcRPS->getUsed(i))
     800  for(UInt i=0; i < m_pRPS->getNumberOfNegativePictures()+ m_pRPS->getNumberOfPositivePictures() + m_pRPS->getNumberOfLongtermPictures(); i++)
     801  {
     802    if(m_pRPS->getUsed(i))
    776803    {
    777804      numRpsCurrTempList++;
    778805    }
    779806  }
    780 #if H_MV
     807#if NH_MV
    781808  numRpsCurrTempList = numRpsCurrTempList + getNumActiveRefLayerPics();
    782809#endif
     
    786813Void TComSlice::initEqualRef()
    787814{
    788   for (Int iDir = 0; iDir < 2; iDir++)
     815  for (Int iDir = 0; iDir < NUM_REF_PIC_LIST_01; iDir++)
    789816  {
    790817    for (Int iRefIdx1 = 0; iRefIdx1 < MAX_NUM_REF; iRefIdx1++)
     
    797824  }
    798825}
    799 #if H_3D
    800 #if H_3D_TMVP
     826#if NH_3D
     827#if NH_3D_TMVP
    801828Void TComSlice::generateAlterRefforTMVP()
    802829{
     
    820847}
    821848#endif
     849#endif
     850
     851#if NH_3D
    822852Void TComSlice::setCamparaSlice( Int** aaiScale, Int** aaiOffset )
    823853
     
    846876  Int i;
    847877  TComSlice* curSlice = pic->getSlice(curSliceIdx);
    848   Int currColRefPOC =  curSlice->getRefPOC( RefPicList(1-curSlice->getColFromL0Flag()), curSlice->getColRefIdx());
     878  Int currColRefPOC =  curSlice->getRefPOC( RefPicList(1 - curSlice->getColFromL0Flag()), curSlice->getColRefIdx());
    849879  TComSlice* preSlice;
    850880  Int preColRefPOC;
     
    854884    if(preSlice->getSliceType() != I_SLICE)
    855885    {
    856       preColRefPOC  = preSlice->getRefPOC( RefPicList(1-preSlice->getColFromL0Flag()), preSlice->getColRefIdx());
     886      preColRefPOC  = preSlice->getRefPOC( RefPicList(1 - preSlice->getColFromL0Flag()), preSlice->getColRefIdx());
    857887      if(currColRefPOC != preColRefPOC)
    858888      {
     
    868898}
    869899
    870 Void TComSlice::checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, NalUnitType& associatedIRAPType, TComList<TComPic *>& rcListPic)
     900Void TComSlice::checkCRA(const TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, NalUnitType& associatedIRAPType, TComList<TComPic *>& rcListPic)
    871901{
    872902  for(Int i = 0; i < pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures(); i++)
     
    887917      else
    888918      {
    889       assert(pReferencePictureSet->getPOC(i) >= pocCRA);
    890     }
    891   }
     919        assert(pReferencePictureSet->getPOC(i) >= pocCRA);
     920      }
     921    }
    892922  }
    893923  if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP ) // IDR picture found
     
    915945 * \param rcListPic reference to the reference picture list
    916946 * This function marks the reference pictures as "unused for reference" in the following conditions.
    917  * If the nal_unit_type is IDR/BLA/BLANT, all pictures in the reference picture list 
     947 * If the nal_unit_type is IDR/BLA/BLANT, all pictures in the reference picture list
    918948 * are marked as "unused for reference"
    919949 *    If the nal_unit_type is BLA/BLANT, set the pocCRA to the temporal reference of the current picture.
    920950 * Otherwise
    921  *    If the bRefreshPending flag is true (a deferred decoding refresh is pending) and the current 
    922  *    temporal reference is greater than the temporal reference of the latest CRA/CRANT/BLA/BLANT picture (pocCRA), 
    923  *    mark all reference pictures except the latest CRA/CRANT/BLA/BLANT picture as "unused for reference" and set 
     951 *    If the bRefreshPending flag is true (a deferred decoding refresh is pending) and the current
     952 *    temporal reference is greater than the temporal reference of the latest CRA/CRANT/BLA/BLANT picture (pocCRA),
     953 *    mark all reference pictures except the latest CRA/CRANT/BLA/BLANT picture as "unused for reference" and set
    924954 *    the bRefreshPending flag to false.
    925  *    If the nal_unit_type is CRA/CRANT, set the bRefreshPending flag to true and pocCRA to the temporal 
     955 *    If the nal_unit_type is CRA/CRANT, set the bRefreshPending flag to true and pocCRA to the temporal
    926956 *    reference of the current picture.
    927957 * Note that the current picture is already placed in the reference list and its marking is not changed.
    928958 * If the current picture has a nal_ref_idc that is not 0, it will remain marked as "used for reference".
    929959 */
    930 Void TComSlice::decodingRefreshMarking(Int& pocCRA, Bool& bRefreshPending, TComList<TComPic*>& rcListPic)
    931 {
    932   TComPic*                 rpcPic;
    933 #if !FIX1172
    934   setAssociatedIRAPPOC(pocCRA);
    935 #endif
    936   Int pocCurr = getPOC();
     960Void TComSlice::decodingRefreshMarking(Int& pocCRA, Bool& bRefreshPending, TComList<TComPic*>& rcListPic, const bool bEfficientFieldIRAPEnabled)
     961{
     962  TComPic* rpcPic;
     963  Int      pocCurr = getPOC();
    937964
    938965  if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
     
    948975      rpcPic = *(iterPic);
    949976      rpcPic->setCurrSliceIdx(0);
    950       if (rpcPic->getPOC() != pocCurr) rpcPic->getSlice(0)->setReferenced(false);
     977      if (rpcPic->getPOC() != pocCurr)
     978      {
     979        rpcPic->getSlice(0)->setReferenced(false);
     980      }
    951981      iterPic++;
    952982    }
     
    957987      pocCRA = pocCurr;
    958988    }
    959 #if EFFICIENT_FIELD_IRAP
     989    if (bEfficientFieldIRAPEnabled)
     990    {
    960991    bRefreshPending = true;
    961 #endif
     992    }
    962993  }
    963994  else // CRA or No DR
    964995  {
    965 #if EFFICIENT_FIELD_IRAP
    966     if(getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_IDR_N_LP || getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL)
     996    if(bEfficientFieldIRAPEnabled && (getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_IDR_N_LP || getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL))
    967997    {
    968998      if (bRefreshPending==true && pocCurr > m_iLastIDR) // IDR reference marking pending
     
    9831013    else
    9841014    {
    985 #endif
    986     if (bRefreshPending==true && pocCurr > pocCRA) // CRA reference marking pending
    987     {
    988       TComList<TComPic*>::iterator        iterPic       = rcListPic.begin();
    989       while (iterPic != rcListPic.end())
    990       {
    991         rpcPic = *(iterPic);
    992         if (rpcPic->getPOC() != pocCurr && rpcPic->getPOC() != pocCRA)
    993         {
    994           rpcPic->getSlice(0)->setReferenced(false);
    995         }
    996         iterPic++;
    997       }
    998       bRefreshPending = false;
    999     }
    1000 #if EFFICIENT_FIELD_IRAP
    1001     }
    1002 #endif
     1015      if (bRefreshPending==true && pocCurr > pocCRA) // CRA reference marking pending
     1016      {
     1017        TComList<TComPic*>::iterator iterPic = rcListPic.begin();
     1018        while (iterPic != rcListPic.end())
     1019        {
     1020          rpcPic = *(iterPic);
     1021          if (rpcPic->getPOC() != pocCurr && rpcPic->getPOC() != pocCRA)
     1022          {
     1023            rpcPic->getSlice(0)->setReferenced(false);
     1024          }
     1025          iterPic++;
     1026        }
     1027        bRefreshPending = false;
     1028      }
     1029    }
    10031030    if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA ) // CRA picture found
    10041031    {
    1005       bRefreshPending = true; 
     1032      bRefreshPending = true;
    10061033      pocCRA = pocCurr;
    10071034    }
     
    10171044  m_iPOC                 = pSrc->m_iPOC;
    10181045  m_eNalUnitType         = pSrc->m_eNalUnitType;
    1019 #if H_MV
     1046#if NH_MV
    10201047  m_layerId              = pSrc->m_layerId;
    10211048  // GT: Copying of several other values might be be missing here, or is above not necessary?
     
    10261053  m_iSliceQpBase         = pSrc->m_iSliceQpBase;
    10271054#endif
     1055  m_ChromaQpAdjEnabled = pSrc->m_ChromaQpAdjEnabled;
    10281056  m_deblockingFilterDisable   = pSrc->m_deblockingFilterDisable;
    10291057  m_deblockingFilterOverrideFlag = pSrc->m_deblockingFilterOverrideFlag;
    10301058  m_deblockingFilterBetaOffsetDiv2 = pSrc->m_deblockingFilterBetaOffsetDiv2;
    10311059  m_deblockingFilterTcOffsetDiv2 = pSrc->m_deblockingFilterTcOffsetDiv2;
    1032  
    1033   for (i = 0; i < 2; i++)
     1060
     1061  for (i = 0; i < NUM_REF_PIC_LIST_01; i++)
    10341062  {
    10351063    m_aiNumRefIdx[i]     = pSrc->m_aiNumRefIdx[i];
     
    10391067  {
    10401068    m_list1IdxToList0Idx[i] = pSrc->m_list1IdxToList0Idx[i];
    1041   }
     1069  }
     1070
    10421071  m_bCheckLDC             = pSrc->m_bCheckLDC;
    10431072  m_iSliceQpDelta        = pSrc->m_iSliceQpDelta;
    1044   m_iSliceQpDeltaCb      = pSrc->m_iSliceQpDeltaCb;
    1045   m_iSliceQpDeltaCr      = pSrc->m_iSliceQpDeltaCr;
    1046   for (i = 0; i < 2; i++)
     1073  for (UInt component = 0; component < MAX_NUM_COMPONENT; component++)
     1074  {
     1075    m_iSliceChromaQpDelta[component] = pSrc->m_iSliceChromaQpDelta[component];
     1076  }
     1077  for (i = 0; i < NUM_REF_PIC_LIST_01; i++)
    10471078  {
    10481079    for (j = 0; j < MAX_NUM_REF; j++)
     
    10501081      m_apcRefPicList[i][j]  = pSrc->m_apcRefPicList[i][j];
    10511082      m_aiRefPOCList[i][j]   = pSrc->m_aiRefPOCList[i][j];
    1052 #if H_MV
     1083      m_bIsUsedAsLongTerm[i][j] = pSrc->m_bIsUsedAsLongTerm[i][j];
     1084#if NH_MV
    10531085      m_aiRefLayerIdList[i][j] = pSrc->m_aiRefLayerIdList[i][j];
    10541086#endif
    10551087    }
    1056   }
    1057   for (i = 0; i < 2; i++)
    1058   {
    1059     for (j = 0; j < MAX_NUM_REF + 1; j++)
    1060     {
    1061       m_bIsUsedAsLongTerm[i][j] = pSrc->m_bIsUsedAsLongTerm[i][j];
    1062     }
     1088    m_bIsUsedAsLongTerm[i][MAX_NUM_REF] = pSrc->m_bIsUsedAsLongTerm[i][MAX_NUM_REF];
    10631089  }
    10641090  m_iDepth               = pSrc->m_iDepth;
     
    10681094
    10691095  // access channel
    1070 #if H_MV
     1096#if NH_MV
    10711097  m_pcVPS                = pSrc->m_pcVPS;
    10721098#endif
    1073   m_pcSPS                = pSrc->m_pcSPS;
    1074   m_pcPPS                = pSrc->m_pcPPS;
    1075   m_pcRPS                = pSrc->m_pcRPS;
    1076   m_iLastIDR             = pSrc->m_iLastIDR;
     1099  m_pRPS                = pSrc->m_pRPS;  m_iLastIDR             = pSrc->m_iLastIDR;
    10771100
    10781101  m_pcPic                = pSrc->m_pcPic;
     
    10801103  m_colFromL0Flag        = pSrc->m_colFromL0Flag;
    10811104  m_colRefIdx            = pSrc->m_colRefIdx;
     1105
    10821106  setLambdas(pSrc->getLambdas());
    1083   for (i = 0; i < 2; i++)
     1107
     1108  for (i = 0; i < NUM_REF_PIC_LIST_01; i++)
    10841109  {
    10851110    for (j = 0; j < MAX_NUM_REF; j++)
     
    10951120  m_bTLayerSwitchingFlag          = pSrc->m_bTLayerSwitchingFlag;
    10961121
    1097   m_sliceMode                   = pSrc->m_sliceMode;
    1098   m_sliceArgument               = pSrc->m_sliceArgument;
    1099   m_sliceCurStartCUAddr         = pSrc->m_sliceCurStartCUAddr;
    1100   m_sliceCurEndCUAddr           = pSrc->m_sliceCurEndCUAddr;
    1101   m_sliceIdx                    = pSrc->m_sliceIdx;
    1102   m_sliceSegmentMode            = pSrc->m_sliceSegmentMode;
    1103   m_sliceSegmentArgument        = pSrc->m_sliceSegmentArgument;
    1104   m_sliceSegmentCurStartCUAddr  = pSrc->m_sliceSegmentCurStartCUAddr;
    1105   m_sliceSegmentCurEndCUAddr    = pSrc->m_sliceSegmentCurEndCUAddr;
    1106   m_nextSlice                    = pSrc->m_nextSlice;
    1107   m_nextSliceSegment             = pSrc->m_nextSliceSegment;
    1108   for ( Int e=0 ; e<2 ; e++ )
    1109   {
    1110     for ( Int n=0 ; n<MAX_NUM_REF ; n++ )
    1111     {
    1112       memcpy(m_weightPredTable[e][n], pSrc->m_weightPredTable[e][n], sizeof(wpScalingParam)*3 );
    1113     }
    1114   }
    1115   m_saoEnabledFlag = pSrc->m_saoEnabledFlag;
    1116   m_saoEnabledFlagChroma = pSrc->m_saoEnabledFlagChroma;
    1117   m_cabacInitFlag                = pSrc->m_cabacInitFlag;
    1118   m_numEntryPointOffsets  = pSrc->m_numEntryPointOffsets;
    1119 
    1120   m_bLMvdL1Zero = pSrc->m_bLMvdL1Zero;
    1121   m_LFCrossSliceBoundaryFlag = pSrc->m_LFCrossSliceBoundaryFlag;
     1122  m_sliceMode                     = pSrc->m_sliceMode;
     1123  m_sliceArgument                 = pSrc->m_sliceArgument;
     1124  m_sliceCurStartCtuTsAddr        = pSrc->m_sliceCurStartCtuTsAddr;
     1125  m_sliceCurEndCtuTsAddr          = pSrc->m_sliceCurEndCtuTsAddr;
     1126  m_sliceIdx                      = pSrc->m_sliceIdx;
     1127  m_sliceSegmentMode              = pSrc->m_sliceSegmentMode;
     1128  m_sliceSegmentArgument          = pSrc->m_sliceSegmentArgument;
     1129  m_sliceSegmentCurStartCtuTsAddr = pSrc->m_sliceSegmentCurStartCtuTsAddr;
     1130  m_sliceSegmentCurEndCtuTsAddr   = pSrc->m_sliceSegmentCurEndCtuTsAddr;
     1131  m_nextSlice                     = pSrc->m_nextSlice;
     1132  m_nextSliceSegment              = pSrc->m_nextSliceSegment;
     1133
     1134  for ( UInt e=0 ; e<NUM_REF_PIC_LIST_01 ; e++ )
     1135  {
     1136    for ( UInt n=0 ; n<MAX_NUM_REF ; n++ )
     1137    {
     1138      memcpy(m_weightPredTable[e][n], pSrc->m_weightPredTable[e][n], sizeof(WPScalingParam)*MAX_NUM_COMPONENT );
     1139    }
     1140  }
     1141
     1142  for( UInt ch = 0 ; ch < MAX_NUM_CHANNEL_TYPE; ch++)
     1143  {
     1144    m_saoEnabledFlag[ch] = pSrc->m_saoEnabledFlag[ch];
     1145  }
     1146
     1147  m_cabacInitFlag                 = pSrc->m_cabacInitFlag;
     1148
     1149  m_bLMvdL1Zero                   = pSrc->m_bLMvdL1Zero;
     1150  m_LFCrossSliceBoundaryFlag      = pSrc->m_LFCrossSliceBoundaryFlag;
    11221151  m_enableTMVPFlag                = pSrc->m_enableTMVPFlag;
    11231152  m_maxNumMergeCand               = pSrc->m_maxNumMergeCand;
    1124 
    1125 #if H_MV
     1153  m_encCABACTableIdx              = pSrc->m_encCABACTableIdx;
     1154
     1155#if NH_MV
    11261156  // Additional slice header syntax elements
    11271157#if !H_MV_HLS7_GEN
     
    11371167  }
    11381168#endif
    1139 #if H_3D
     1169#if NH_3D_DIS
    11401170  m_bApplyDIS = pSrc->m_bApplyDIS;
    11411171#endif
    1142 #if H_3D_IC
     1172#if NH_3D_IC
    11431173  m_bApplyIC = pSrc->m_bApplyIC;
    11441174  m_icSkipParseFlag = pSrc->m_icSkipParseFlag;
    11451175#endif
    1146 }
    1147 
    1148 Int TComSlice::m_prevTid0POC = 0;
     1176
     1177}
     1178
    11491179
    11501180/** Function for setting the slice's temporal layer ID and corresponding temporal_layer_switching_point_flag.
    11511181 * \param uiTLayer Temporal layer ID of the current slice
    1152  * The decoder calls this function to set temporal_layer_switching_point_flag for each temporal layer based on 
    1153  * the SPS's temporal_id_nesting_flag and the parsed PPS.  Then, current slice's temporal layer ID and 
     1182 * The decoder calls this function to set temporal_layer_switching_point_flag for each temporal layer based on
     1183 * the SPS's temporal_id_nesting_flag and the parsed PPS.  Then, current slice's temporal layer ID and
    11541184 * temporal_layer_switching_point_flag is set accordingly.
    11551185 */
     
    11611191/** Function for checking if this is a switching-point
    11621192*/
    1163 Bool TComSlice::isTemporalLayerSwitchingPoint( TComList<TComPic*>& rcListPic )
     1193Bool TComSlice::isTemporalLayerSwitchingPoint(TComList<TComPic*>& rcListPic)
    11641194{
    11651195  TComPic* rpcPic;
     
    11801210}
    11811211
    1182 /** Function for checking if this is a STSA candidate 
     1212/** Function for checking if this is a STSA candidate
    11831213 */
    1184 Bool TComSlice::isStepwiseTemporalLayerSwitchingPointCandidate( TComList<TComPic*>& rcListPic )
    1185 {
    1186     TComPic* rpcPic;
    1187    
    1188     TComList<TComPic*>::iterator iterPic = rcListPic.begin();
    1189     while ( iterPic != rcListPic.end())
    1190     {
    1191         rpcPic = *(iterPic++);
    1192         if(rpcPic->getSlice(0)->isReferenced() &&  (rpcPic->getUsedByCurr()==true) && rpcPic->getPOC() != getPOC())
    1193         {
    1194             if(rpcPic->getTLayer() >= getTLayer())
    1195             {
    1196                 return false;
    1197             }
    1198         }
    1199     }
    1200     return true;
     1214Bool TComSlice::isStepwiseTemporalLayerSwitchingPointCandidate(TComList<TComPic*>& rcListPic)
     1215{
     1216  TComPic* rpcPic;
     1217
     1218  TComList<TComPic*>::iterator iterPic = rcListPic.begin();
     1219  while ( iterPic != rcListPic.end())
     1220  {
     1221    rpcPic = *(iterPic++);
     1222    if(rpcPic->getSlice(0)->isReferenced() &&  (rpcPic->getUsedByCurr()==true) && rpcPic->getPOC() != getPOC())
     1223    {
     1224      if(rpcPic->getTLayer() >= getTLayer())
     1225      {
     1226        return false;
     1227      }
     1228    }
     1229  }
     1230  return true;
    12011231}
    12021232
     
    12641294  {
    12651295    rpcPic = *(iterPic++);
    1266 #if BUGFIX_INTRAPERIOD
    12671296    if(!rpcPic->getReconMark())
    12681297    {
    12691298      continue;
    12701299    }
    1271 #endif
    12721300    if (rpcPic->getPOC() == this->getPOC())
    12731301    {
     
    12781306    // in decoding order shall precede the IRAP picture in output order.
    12791307    // (Note that any picture following in output order would be present in the DPB)
    1280 #if !SETTING_NO_OUT_PIC_PRIOR
    1281     if(rpcPic->getSlice(0)->getPicOutputFlag() == 1)
    1282 #else
    12831308    if(rpcPic->getSlice(0)->getPicOutputFlag() == 1 && !this->getNoOutputPriorPicsFlag())
    1284 #endif
    12851309    {
    12861310      if(nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP    ||
     
    13171341    // When a picture is a leading picture, it shall precede, in decoding order,
    13181342    // all trailing pictures that are associated with the same IRAP picture.
    1319     if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
    1320        nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R ||
    1321        nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
    1322        nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R)
    1323     {
    1324       if(rpcPic->getSlice(0)->getAssociatedIRAPPOC() == this->getAssociatedIRAPPOC())
    1325       {
    1326         // rpcPic is a picture that preceded the leading in decoding order since it exist in the DPB
    1327         // rpcPic would violate the constraint if it was a trailing picture
    1328         assert(rpcPic->getPOC() <= this->getAssociatedIRAPPOC());
    1329       }
    1330     }
     1343      if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
     1344         nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R ||
     1345         nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
     1346         nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R)
     1347      {
     1348        if(rpcPic->getSlice(0)->getAssociatedIRAPPOC() == this->getAssociatedIRAPPOC())
     1349        {
     1350          // rpcPic is a picture that preceded the leading in decoding order since it exist in the DPB
     1351          // rpcPic would violate the constraint if it was a trailing picture
     1352          assert(rpcPic->getPOC() <= this->getAssociatedIRAPPOC());
     1353        }
     1354      }
    13311355
    13321356    // Any RASL picture associated with a CRA or BLA picture shall precede any
     
    13341358    if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
    13351359       nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R)
    1336     { 
     1360    {
    13371361      if((this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_BLA_N_LP   ||
    13381362          this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_BLA_W_LP   ||
     
    13721396
    13731397
     1398
    13741399/** Function for applying picture marking based on the Reference Picture Set in pReferencePictureSet.
    13751400*/
    1376 Void TComSlice::applyReferencePictureSet( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet)
     1401Void TComSlice::applyReferencePictureSet( TComList<TComPic*>& rcListPic, const TComReferencePictureSet *pReferencePictureSet)
    13771402{
    13781403  TComPic* rpcPic;
     
    14141439        }
    14151440      }
    1416       else 
     1441      else
    14171442      {
    14181443        Int pocCycle = 1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC();
     
    14271452
    14281453    }
    1429 #if H_MV
     1454#if NH_MV
    14301455    if( isReference ) // Current picture is in the temporal RPS
    14311456    {
     
    14351460    // mark the picture as "unused for reference" if it is not in
    14361461    // the Reference Picture Set
    1437     if(rpcPic->getPicSym()->getSlice(0)->getPOC() != this->getPOC() && isReference == 0)   
    1438     {           
    1439       rpcPic->getSlice( 0 )->setReferenced( false );   
     1462    if(rpcPic->getPicSym()->getSlice(0)->getPOC() != this->getPOC() && isReference == 0)
     1463    {
     1464      rpcPic->getSlice( 0 )->setReferenced( false );
    14401465      rpcPic->setUsedByCurr(0);
    14411466      rpcPic->setIsLongTerm(0);
     
    14581483/** Function for applying picture marking based on the Reference Picture Set in pReferencePictureSet.
    14591484*/
    1460 #if ALLOW_RECOVERY_POINT_AS_RAP
    1461 Int TComSlice::checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool printErrors, Int pocRandomAccess, Bool bUseRecoveryPoint)
    1462 #else
    1463 Int TComSlice::checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool printErrors, Int pocRandomAccess)
    1464 #endif
    1465 {
    1466 #if ALLOW_RECOVERY_POINT_AS_RAP
     1485Int TComSlice::checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, const TComReferencePictureSet *pReferencePictureSet, Bool printErrors, Int pocRandomAccess, Bool bUseRecoveryPoint)
     1486{
    14671487  Int atLeastOneUnabledByRecoveryPoint = 0;
    14681488  Int atLeastOneFlushedByPreviousIDR = 0;
    1469 #endif
    14701489  TComPic* rpcPic;
    14711490  Int i, isAvailable;
     
    14881507        if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()) == pReferencePictureSet->getPOC(i) && rpcPic->getSlice(0)->isReferenced())
    14891508        {
    1490 #if ALLOW_RECOVERY_POINT_AS_RAP
    14911509          if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess && this->getPOC() + pReferencePictureSet->getDeltaPOC(i) < pocRandomAccess)
    14921510          {
     
    14951513          else
    14961514          {
    1497           isAvailable = 1;
    1498         }
    1499 #else
    1500           isAvailable = 1;
    1501 #endif
    1502         }
    1503       }
    1504       else
     1515            isAvailable = 1;
     1516          }
     1517        }
     1518      }
     1519      else
    15051520      {
    15061521        Int pocCycle = 1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC();
     
    15091524        if(rpcPic->getIsLongTerm() && curPoc == refPoc && rpcPic->getSlice(0)->isReferenced())
    15101525        {
    1511 #if ALLOW_RECOVERY_POINT_AS_RAP
    15121526          if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess && this->getPOC() + pReferencePictureSet->getDeltaPOC(i) < pocRandomAccess)
    15131527          {
     
    15161530          else
    15171531          {
    1518           isAvailable = 1;
    1519         }
    1520 #else
    1521           isAvailable = 1;
    1522 #endif
     1532            isAvailable = 1;
     1533          }
    15231534        }
    15241535      }
     
    15401551          refPoc = refPoc & (pocCycle - 1);
    15411552        }
    1542        
     1553
    15431554        if (rpcPic->getSlice(0)->isReferenced() && curPoc == refPoc)
    15441555        {
    1545 #if ALLOW_RECOVERY_POINT_AS_RAP
    15461556          if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess && this->getPOC() + pReferencePictureSet->getDeltaPOC(i) < pocRandomAccess)
    15471557          {
     
    15501560          else
    15511561          {
    1552           isAvailable = 1;
    1553           rpcPic->setIsLongTerm(1);
    1554           break;
    1555         }
    1556 #else
    1557           isAvailable = 1;
    1558           rpcPic->setIsLongTerm(1);
    1559           break;
    1560 #endif
     1562            isAvailable = 1;
     1563            rpcPic->setIsLongTerm(1);
     1564            break;
     1565          }
    15611566        }
    15621567      }
     
    15641569    // report that a picture is lost if it is in the Reference Picture Set
    15651570    // but not available as reference picture
    1566     if(isAvailable == 0)   
    1567     {           
     1571    if(isAvailable == 0)
     1572    {
    15681573      if (this->getPOC() + pReferencePictureSet->getDeltaPOC(i) >= pocRandomAccess)
    15691574      {
     
    15861591        }
    15871592      }
    1588 #if ALLOW_RECOVERY_POINT_AS_RAP
    15891593      else if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess)
    15901594      {
     
    15951599        atLeastOneFlushedByPreviousIDR = 1;
    15961600      }
    1597 #endif
    1598     }
    1599   } 
     1601    }
     1602  }
    16001603  // loop through all short-term pictures in the Reference Picture Set
    16011604  // to see if the picture should be kept as reference picture
     
    16111614      if(!rpcPic->getIsLongTerm() && rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i) && rpcPic->getSlice(0)->isReferenced())
    16121615      {
    1613 #if ALLOW_RECOVERY_POINT_AS_RAP
    16141616        if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess && this->getPOC() + pReferencePictureSet->getDeltaPOC(i) < pocRandomAccess)
    16151617        {
     
    16181620        else
    16191621        {
    1620         isAvailable = 1;
    1621       }
    1622 #else
    1623         isAvailable = 1;
    1624 #endif
     1622          isAvailable = 1;
     1623        }
    16251624      }
    16261625    }
    16271626    // report that a picture is lost if it is in the Reference Picture Set
    16281627    // but not available as reference picture
    1629     if(isAvailable == 0)   
    1630     {           
     1628    if(isAvailable == 0)
     1629    {
    16311630      if (this->getPOC() + pReferencePictureSet->getDeltaPOC(i) >= pocRandomAccess)
    16321631      {
     
    16491648        }
    16501649      }
    1651 #if ALLOW_RECOVERY_POINT_AS_RAP
    16521650      else if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess)
    16531651      {
    16541652        atLeastOneUnabledByRecoveryPoint = 1;
    1655     }
     1653      }
    16561654      else if(bUseRecoveryPoint && (this->getAssociatedIRAPType()==NAL_UNIT_CODED_SLICE_IDR_N_LP || this->getAssociatedIRAPType()==NAL_UNIT_CODED_SLICE_IDR_W_RADL))
    16571655      {
    16581656        atLeastOneFlushedByPreviousIDR = 1;
    1659   }   
    1660 #endif
    1661     }
    1662     }
    1663 #if ALLOW_RECOVERY_POINT_AS_RAP
     1657      }
     1658    }
     1659  }
     1660
    16641661  if(atLeastOneUnabledByRecoveryPoint || atLeastOneFlushedByPreviousIDR)
    16651662  {
    16661663    return -1;
    16671664  }   
    1668 #endif
    16691665  if(atLeastOneLost)
    16701666  {
     
    16831679/** Function for constructing an explicit Reference Picture Set out of the available pictures in a referenced Reference Picture Set
    16841680*/
    1685 #if ALLOW_RECOVERY_POINT_AS_RAP
    1686 Void TComSlice::createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool isRAP, Int pocRandomAccess, Bool bUseRecoveryPoint)
    1687 #else
    1688 Void TComSlice::createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool isRAP)
    1689 #endif
     1681Void TComSlice::createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, const TComReferencePictureSet *pReferencePictureSet, Bool isRAP, Int pocRandomAccess, Bool bUseRecoveryPoint, const Bool bEfficientFieldIRAPEnabled)
    16901682{
    16911683  TComPic* rpcPic;
     
    16941686  Int nrOfNegativePictures = 0;
    16951687  Int nrOfPositivePictures = 0;
    1696   TComReferencePictureSet* pcRPS = this->getLocalRPS();
     1688  TComReferencePictureSet* pLocalRPS = this->getLocalRPS();
     1689  (*pLocalRPS)=TComReferencePictureSet();
     1690
     1691  Bool irapIsInRPS = false; // Used when bEfficientFieldIRAPEnabled==true
    16971692
    16981693  // loop through all pictures in the Reference Picture Set
     
    17111706        // This picture exists as a reference picture
    17121707        // and should be added to the explicit Reference Picture Set
    1713         pcRPS->setDeltaPOC(k, pReferencePictureSet->getDeltaPOC(i));
    1714         pcRPS->setUsed(k, pReferencePictureSet->getUsed(i) && (!isRAP));
    1715 #if ALLOW_RECOVERY_POINT_AS_RAP
    1716         pcRPS->setUsed(k, pcRPS->getUsed(k) && !(bUseRecoveryPoint && this->getPOC() > pocRandomAccess && this->getPOC() + pReferencePictureSet->getDeltaPOC(i) < pocRandomAccess) );
    1717 #endif
    1718         if(pcRPS->getDeltaPOC(k) < 0)
     1708        pLocalRPS->setDeltaPOC(k, pReferencePictureSet->getDeltaPOC(i));
     1709        pLocalRPS->setUsed(k, pReferencePictureSet->getUsed(i) && (!isRAP));
     1710        if (bEfficientFieldIRAPEnabled)
     1711        {
     1712          pLocalRPS->setUsed(k, pLocalRPS->getUsed(k) && !(bUseRecoveryPoint && this->getPOC() > pocRandomAccess && this->getPOC() + pReferencePictureSet->getDeltaPOC(i) < pocRandomAccess) );
     1713        }
     1714
     1715        if(pLocalRPS->getDeltaPOC(k) < 0)
    17191716        {
    17201717          nrOfNegativePictures++;
     
    17221719        else
    17231720        {
     1721          if(bEfficientFieldIRAPEnabled && rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getAssociatedIRAPPOC() && this->getAssociatedIRAPPOC() == this->getPOC()+1)
     1722          {
     1723            irapIsInRPS = true;
     1724          }
    17241725          nrOfPositivePictures++;
    17251726        }
     
    17281729    }
    17291730  }
    1730 #if EFFICIENT_FIELD_IRAP
     1731
    17311732  Bool useNewRPS = false;
    17321733  // if current picture is complimentary field associated to IRAP, add the IRAP to its RPS.
    1733   if(m_pcPic->isField())
     1734  if(bEfficientFieldIRAPEnabled && m_pcPic->isField() && !irapIsInRPS)
    17341735  {
    17351736    TComList<TComPic*>::iterator iterPic = rcListPic.begin();
     
    17391740      if(rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getAssociatedIRAPPOC() && this->getAssociatedIRAPPOC() == this->getPOC()+1)
    17401741      {
    1741         pcRPS->setDeltaPOC(k, 1);
    1742         pcRPS->setUsed(k, true);
     1742        pLocalRPS->setDeltaPOC(k, 1);
     1743        pLocalRPS->setUsed(k, true);
    17431744        nrOfPositivePictures++;
    17441745        k ++;
     
    17471748    }
    17481749  }
    1749 #endif
    1750   pcRPS->setNumberOfNegativePictures(nrOfNegativePictures);
    1751   pcRPS->setNumberOfPositivePictures(nrOfPositivePictures);
    1752   pcRPS->setNumberOfPictures(nrOfNegativePictures+nrOfPositivePictures);
    1753   // This is a simplistic inter rps example. A smarter encoder will look for a better reference RPS to do the
     1750  pLocalRPS->setNumberOfNegativePictures(nrOfNegativePictures);
     1751  pLocalRPS->setNumberOfPositivePictures(nrOfPositivePictures);
     1752  pLocalRPS->setNumberOfPictures(nrOfNegativePictures+nrOfPositivePictures);
     1753  // This is a simplistic inter rps example. A smarter encoder will look for a better reference RPS to do the
    17541754  // inter RPS prediction with.  Here we just use the reference used by pReferencePictureSet.
    17551755  // If pReferencePictureSet is not inter_RPS_predicted, then inter_RPS_prediction is for the current RPS also disabled.
    1756   if (!pReferencePictureSet->getInterRPSPrediction()
    1757 #if EFFICIENT_FIELD_IRAP
    1758     || useNewRPS
    1759 #endif
    1760     )
    1761   {
    1762     pcRPS->setInterRPSPrediction(false);
    1763     pcRPS->setNumRefIdc(0);
     1756  if (!pReferencePictureSet->getInterRPSPrediction() || useNewRPS )
     1757  {
     1758    pLocalRPS->setInterRPSPrediction(false);
     1759    pLocalRPS->setNumRefIdc(0);
    17641760  }
    17651761  else
     
    17671763    Int rIdx =  this->getRPSidx() - pReferencePictureSet->getDeltaRIdxMinus1() - 1;
    17681764    Int deltaRPS = pReferencePictureSet->getDeltaRPS();
    1769     TComReferencePictureSet* pcRefRPS = this->getSPS()->getRPSList()->getReferencePictureSet(rIdx);
     1765    const TComReferencePictureSet* pcRefRPS = this->getSPS()->getRPSList()->getReferencePictureSet(rIdx);
    17701766    Int iRefPics = pcRefRPS->getNumberOfPictures();
    17711767    Int iNewIdc=0;
    1772     for(i=0; i<= iRefPics; i++) 
     1768    for(i=0; i<= iRefPics; i++)
    17731769    {
    17741770      Int deltaPOC = ((i != iRefPics)? pcRefRPS->getDeltaPOC(i) : 0);  // check if the reference abs POC is >= 0
    17751771      Int iRefIdc = 0;
    1776       for (j=0; j < pcRPS->getNumberOfPictures(); j++) // loop through the  pictures in the new RPS
    1777       {
    1778         if ( (deltaPOC + deltaRPS) == pcRPS->getDeltaPOC(j))
    1779         {
    1780           if (pcRPS->getUsed(j))
     1772      for (j=0; j < pLocalRPS->getNumberOfPictures(); j++) // loop through the  pictures in the new RPS
     1773      {
     1774        if ( (deltaPOC + deltaRPS) == pLocalRPS->getDeltaPOC(j))
     1775        {
     1776          if (pLocalRPS->getUsed(j))
    17811777          {
    17821778            iRefIdc = 1;
     
    17881784        }
    17891785      }
    1790       pcRPS->setRefIdc(i, iRefIdc);
     1786      pLocalRPS->setRefIdc(i, iRefIdc);
    17911787      iNewIdc++;
    17921788    }
    1793     pcRPS->setInterRPSPrediction(true);
    1794     pcRPS->setNumRefIdc(iNewIdc);
    1795     pcRPS->setDeltaRPS(deltaRPS);
    1796     pcRPS->setDeltaRIdxMinus1(pReferencePictureSet->getDeltaRIdxMinus1() + this->getSPS()->getRPSList()->getNumberOfReferencePictureSets() - this->getRPSidx());
    1797   }
    1798 
    1799   this->setRPS(pcRPS);
     1789    pLocalRPS->setInterRPSPrediction(true);
     1790    pLocalRPS->setNumRefIdc(iNewIdc);
     1791    pLocalRPS->setDeltaRPS(deltaRPS);
     1792    pLocalRPS->setDeltaRIdxMinus1(pReferencePictureSet->getDeltaRIdxMinus1() + this->getSPS()->getRPSList()->getNumberOfReferencePictureSets() - this->getRPSidx());
     1793  }
     1794
     1795  this->setRPS(pLocalRPS);
    18001796  this->setRPSidx(-1);
    18011797}
    18021798
    1803 /** get AC and DC values for weighted pred
    1804  * \param *wp
    1805  * \returns Void
    1806  */
    1807 Void  TComSlice::getWpAcDcParam(wpACDCParam *&wp)
     1799//! get AC and DC values for weighted pred
     1800Void  TComSlice::getWpAcDcParam(WPACDCParam *&wp)
    18081801{
    18091802  wp = m_weightACDCParam;
    18101803}
    18111804
    1812 /** init AC and DC values for weighted pred
    1813  * \returns Void
    1814  */
     1805//! init AC and DC values for weighted pred
    18151806Void  TComSlice::initWpAcDcParam()
    18161807{
    1817   for(Int iComp = 0; iComp < 3; iComp++ )
     1808  for(Int iComp = 0; iComp < MAX_NUM_COMPONENT; iComp++ )
    18181809  {
    18191810    m_weightACDCParam[iComp].iAC = 0;
     
    18221813}
    18231814
    1824 /** get WP tables for weighted pred
    1825  * \param RefPicList
    1826  * \param iRefIdx
    1827  * \param *&wpScalingParam
    1828  * \returns Void
    1829  */
    1830 Void  TComSlice::getWpScaling( RefPicList e, Int iRefIdx, wpScalingParam *&wp )
    1831 {
     1815//! get tables for weighted prediction
     1816Void  TComSlice::getWpScaling( RefPicList e, Int iRefIdx, WPScalingParam *&wp )
     1817{
     1818  assert (e<NUM_REF_PIC_LIST_01);
    18321819  wp = m_weightPredTable[e][iRefIdx];
    18331820}
    18341821
    1835 /** reset Default WP tables settings : no weight.
    1836  * \param wpScalingParam
    1837  * \returns Void
    1838  */
     1822//! reset Default WP tables settings : no weight.
    18391823Void  TComSlice::resetWpScaling()
    18401824{
    1841   for ( Int e=0 ; e<2 ; e++ )
     1825  for ( Int e=0 ; e<NUM_REF_PIC_LIST_01 ; e++ )
    18421826  {
    18431827    for ( Int i=0 ; i<MAX_NUM_REF ; i++ )
    18441828    {
    1845       for ( Int yuv=0 ; yuv<3 ; yuv++ )
    1846       {
    1847         wpScalingParam  *pwp = &(m_weightPredTable[e][i][yuv]);
     1829      for ( Int yuv=0 ; yuv<MAX_NUM_COMPONENT ; yuv++ )
     1830      {
     1831        WPScalingParam  *pwp = &(m_weightPredTable[e][i][yuv]);
    18481832        pwp->bPresentFlag      = false;
    18491833        pwp->uiLog2WeightDenom = 0;
     
    18561840}
    18571841
    1858 /** init WP table
    1859  * \returns Void
    1860  */
    1861 Void  TComSlice::initWpScaling()
    1862 {
    1863   for ( Int e=0 ; e<2 ; e++ )
     1842//! init WP table
     1843Void  TComSlice::initWpScaling(const TComSPS *sps)
     1844{
     1845  const Bool bUseHighPrecisionPredictionWeighting = sps->getSpsRangeExtension().getHighPrecisionOffsetsEnabledFlag();
     1846  for ( Int e=0 ; e<NUM_REF_PIC_LIST_01 ; e++ )
    18641847  {
    18651848    for ( Int i=0 ; i<MAX_NUM_REF ; i++ )
    18661849    {
    1867       for ( Int yuv=0 ; yuv<3 ; yuv++ )
    1868       {
    1869         wpScalingParam  *pwp = &(m_weightPredTable[e][i][yuv]);
    1870         if ( !pwp->bPresentFlag ) 
     1850      for ( Int yuv=0 ; yuv<MAX_NUM_COMPONENT ; yuv++ )
     1851      {
     1852        WPScalingParam  *pwp = &(m_weightPredTable[e][i][yuv]);
     1853        if ( !pwp->bPresentFlag )
    18711854        {
    18721855          // Inferring values not present :
     
    18751858        }
    18761859
     1860        const Int offsetScalingFactor = bUseHighPrecisionPredictionWeighting ? 1 : (1 << (sps->getBitDepth(toChannelType(ComponentID(yuv)))-8));
     1861
    18771862        pwp->w      = pwp->iWeight;
    1878         Int bitDepth = yuv ? g_bitDepthC : g_bitDepthY;
    1879         pwp->o      = pwp->iOffset << (bitDepth-8);
     1863        pwp->o      = pwp->iOffset * offsetScalingFactor; //NOTE: This value of the ".o" variable is never used - .o is set immediately before it gets used
    18801864        pwp->shift  = pwp->uiLog2WeightDenom;
    18811865        pwp->round  = (pwp->uiLog2WeightDenom>=1) ? (1 << (pwp->uiLog2WeightDenom-1)) : (0);
     
    18911875: m_VPSId                     (  0)
    18921876, m_uiMaxTLayers              (  1)
    1893 #if H_MV
     1877#if NH_MV
    18941878, m_uiMaxLayersMinus1         (  0)
    18951879#else
     
    18981882, m_bTemporalIdNestingFlag    (false)
    18991883, m_numHrdParameters          (  0)
    1900 #if H_MV
     1884#if NH_MV
    19011885, m_maxLayerId             (  0)
    19021886#else
    19031887, m_maxNuhReservedZeroLayerId (  0)
    19041888#endif
    1905 , m_hrdParameters             (NULL)
    1906 , m_hrdOpSetIdx               (NULL)
    1907 , m_cprmsPresentFlag          (NULL)
    1908 #if H_MV
    1909 , m_dpbSize                   (NULL)
    1910 , m_vpsVUI                 (  NULL )
    1911 #endif
    1912 {
    1913 #if H_MV
     1889, m_hrdParameters             ()
     1890, m_hrdOpSetIdx               ()
     1891, m_cprmsPresentFlag          ()
     1892{
     1893#if NH_MV
    19141894  m_vpsBaseLayerInternalFlag = true;
    19151895  m_vpsBaseLayerAvailableFlag = true;
     
    19221902  {
    19231903    m_numReorderPics[i] = 0;
    1924     m_uiMaxDecPicBuffering[i] = 1; 
     1904    m_uiMaxDecPicBuffering[i] = 1;
    19251905    m_uiMaxLatencyIncrease[i] = 0;
    19261906  }
    1927 #if H_MV
     1907#if NH_MV
    19281908  for (Int lsIdx = 0; lsIdx < MAX_VPS_OP_SETS_PLUS1; lsIdx++ )
    19291909  { 
     
    19881968    m_layerIdInNuh      [i] = ( i == 0 ) ? 0 : -1;
    19891969    m_numDirectRefLayers[i] = 0;
    1990 #if H_3D
     1970#if NH_3D
    19911971    m_numRefListLayers[i] = 0;
    19921972#endif
    19931973    m_vpsRepFormatIdx    [i] = 0;
    1994     m_pocLsbNotPresentFlag[i] = 0;
    1995     m_repFormat          [i] = NULL;
     1974    m_pocLsbNotPresentFlag[i] = 0;   
    19961975    m_viewIdVal          [i] = 0;
    19971976
    1998 #if H_3D
     1977#if NH_3D
    19991978    m_viewIndex         [i] = -1;
    20001979#endif
     
    20061985      m_dependencyFlag  [i][j]    = false;
    20071986      m_idDirectRefLayer[i][j]    = -1;
    2008 #if H_3D
     1987#if NH_3D
    20091988      m_idRefListLayer[i][j]    = -1;
    20101989#endif
     
    20181997      m_dimensionId[i][j] = 0;
    20191998    }
    2020 #if H_3D_ARP
    2021 #endif
    2022   }
    2023   m_vpsVUI = new TComVPSVUI;
    2024   m_dpbSize = new TComDpbSize;
    2025 
    2026 
     1999#if NH_3D_ARP
     2000#endif
     2001  } 
    20272002#endif
    20282003}
     
    20302005TComVPS::~TComVPS()
    20312006{
    2032   if( m_hrdParameters    != NULL )     delete[] m_hrdParameters;
    2033   if( m_hrdOpSetIdx      != NULL )     delete[] m_hrdOpSetIdx;
    2034   if( m_cprmsPresentFlag != NULL )     delete[] m_cprmsPresentFlag;
    2035 #if H_MV
    2036   if ( m_vpsVUI          != NULL )     delete m_vpsVUI;
    2037   if ( m_dpbSize         != NULL )     delete m_dpbSize;
    2038 
    2039   for( Int i = 0; i < MAX_NUM_LAYERS; i++ )
    2040   {
    2041     if (m_repFormat[ i ] != NULL )      delete m_repFormat[ i ];   
    2042   }
    2043 #endif
    2044 #if H_3D
    2045   deleteCamPars();
    2046 #endif
    2047 }
    2048 
    2049 #if H_MV
     2007}
     2008
     2009#if NH_MV
    20502010
    20512011Bool TComVPS::checkVPSExtensionSyntax()
     
    20662026}
    20672027
    2068 Int TComVPS::getNumScalabilityTypes()
     2028Int TComVPS::getNumScalabilityTypes() const
    20692029{
    20702030  return scalTypeToScalIdx( ScalabilityType(MAX_NUM_SCALABILITY_TYPES) );
    20712031}
    20722032
    2073 Int TComVPS::scalTypeToScalIdx( ScalabilityType scalType )
    2074 {
    2075   assert( scalType >= 0 && scalType <= MAX_NUM_SCALABILITY_TYPES );
    2076   assert( scalType == MAX_NUM_SCALABILITY_TYPES || getScalabilityMaskFlag( scalType ) );
     2033Int TComVPS::scalTypeToScalIdx( ScalabilityType scalType ) const
     2034{
     2035  assert( (Int)scalType >= 0 && (Int)scalType <= MAX_NUM_SCALABILITY_TYPES );
     2036  assert( (Int)scalType == MAX_NUM_SCALABILITY_TYPES || getScalabilityMaskFlag( scalType ) );
    20772037  Int scalIdx = 0;
    20782038  for( Int curScalType = 0; curScalType < scalType; curScalType++ )
     
    21142074    Int iNuhLId = getLayerIdInNuh( i );
    21152075    Int d = 0;
    2116 #if H_3D
     2076#if NH_3D
    21172077    Int l = 0;
    21182078#endif
     
    21272087        m_idDirectRefLayer[iNuhLId][d++] = jNuhLid;
    21282088      }
    2129 #if H_3D
     2089#if NH_3D
    21302090      if( getDirectDependencyFlag( i , j ) && ( getDepthId( iNuhLId ) == getDepthId( jNuhLid ) ))
    21312091      {
     
    21442104    }
    21452105    m_numDirectRefLayers[ iNuhLId ] = d;
    2146 #if H_3D
     2106#if NH_3D
    21472107    m_numRefListLayers[ iNuhLId ] = l;
    21482108#endif
     
    21852145{
    21862146  m_numViews = 1;
    2187 #if H_3D
    2188   AOF( m_viewOIdxList.size() == 0 );
    2189  
     2147#if NH_3D
     2148  AOF( m_viewOIdxList.size() == 0 );   
    21902149  m_viewOIdxList.push_back( 0 );       
    21912150#endif
     
    22072166      {
    22082167        m_numViews++;
    2209 #if H_3D
     2168#if NH_3D
    22102169        m_viewOIdxList.push_back( getViewOrderIdx( lId ) );       
    22112170#endif
     
    22162175
    22172176
    2218 Int TComVPS::getScalabilityId( Int layerIdInVps, ScalabilityType scalType )
     2177Int TComVPS::getScalabilityId( Int layerIdInVps, ScalabilityType scalType ) const
    22192178{
    22202179  return getScalabilityMaskFlag( scalType ) ? getDimensionId( layerIdInVps, scalTypeToScalIdx( scalType ) ) : 0;
    22212180}
    22222181
    2223 #if H_3D
    2224 Int TComVPS::getLayerIdInNuh( Int viewIndex, Bool depthFlag )
     2182#if NH_3D
     2183Int TComVPS::getLayerIdInNuh( Int viewIndex, Bool depthFlag ) const
    22252184{
    22262185  Int foundLayerIdinNuh = -1;
     
    22402199Void TComVPS::createCamPars(Int iNumViews)
    22412200{
    2242   Int i = 0, j = 0;
    2243 
    2244   m_numCp    = new Int [ iNumViews ];
    2245   m_cpRefVoi = new Int*[ iNumViews ];
    2246   m_cpInSliceSegmentHeaderFlag = new Bool[ iNumViews ];
    2247 
    2248   m_cpPresentFlag  = new Bool*[ iNumViews ];
    2249  
    2250 
    2251   m_aaaiCodedScale = new Int**[ iNumViews ];
    2252   m_aaaiCodedOffset = new Int**[ iNumViews ];
    2253   for ( i = 0; i < iNumViews ; i++ )
    2254   {
    2255     m_cpInSliceSegmentHeaderFlag[i] = false;     
    2256    
    2257     m_aaaiCodedScale[i] = new Int*[ 2 ];
    2258     m_aaaiCodedOffset[i] = new Int*[ 2 ];
    2259 
    2260     m_numCp   [i] = 0;
    2261     m_cpRefVoi[i] = new Int[ iNumViews ];
    2262     m_cpPresentFlag[i] = new Bool[ iNumViews ];
    2263     for ( j = 0; j < iNumViews; j++)
    2264     {
    2265       m_cpRefVoi[i][j] = 0;
    2266       m_cpPresentFlag[i][j] = false;
    2267     }
    2268     for ( j = 0; j < 2; j++ )
    2269     {
    2270       m_aaaiCodedScale[i][j] = new Int[ MAX_NUM_LAYERS ];
    2271       m_aaaiCodedOffset[i][j] = new Int[ MAX_NUM_LAYERS ];
     2201  m_numCp                     .resize( iNumViews );
     2202  m_cpRefVoi                  .resize( iNumViews );
     2203  m_cpInSliceSegmentHeaderFlag.resize( iNumViews );
     2204  m_cpPresentFlag             .resize( iNumViews );
     2205  m_aaaiCodedScale            .resize( iNumViews );
     2206  m_aaaiCodedOffset           .resize( iNumViews );
     2207
     2208  for ( Int i = 0; i < iNumViews ; i++ )
     2209  {
     2210    m_numCp                     [i] = 0;
     2211    m_cpRefVoi                  [i].resize( iNumViews );
     2212    m_cpInSliceSegmentHeaderFlag[i] = false;         
     2213    m_aaaiCodedScale            [i].resize( 2 );
     2214    m_aaaiCodedOffset           [i].resize( 2 );       
     2215    m_cpPresentFlag             [i].resize( iNumViews );
     2216
     2217    for ( Int j = 0; j < iNumViews; j++)
     2218    {
     2219      m_cpRefVoi             [i][j] = 0;
     2220      m_cpPresentFlag        [i][j] = false;
     2221    }
     2222
     2223    for ( Int j = 0; j < 2; j++ )
     2224    {
     2225      m_aaaiCodedScale       [i][j].resize( MAX_NUM_LAYERS );
     2226      m_aaaiCodedOffset      [i][j].resize( MAX_NUM_LAYERS );
     2227
    22722228      for ( Int k = 0; k < MAX_NUM_LAYERS; k++ )
    22732229      {
    2274         m_aaaiCodedScale[i][j][k] = 0;
     2230        m_aaaiCodedScale [i][j][k] = 0;
    22752231        m_aaaiCodedOffset[i][j][k] = 0;
    22762232      }
     
    22782234  }
    22792235}
    2280 
    2281 Void TComVPS::deleteCamPars()
    2282 {
    2283   Int iNumViews = getNumViews();
    2284   Int i = 0, j = 0;
    2285 
    2286   if ( m_numCp != NULL )
    2287   {
    2288     delete [] m_numCp;
    2289   }
    2290 
    2291   if ( m_cpRefVoi != NULL )
    2292   {
    2293     for ( i = 0; i < iNumViews ; i++ )
    2294     {
    2295       delete [] m_cpRefVoi[i];
    2296     }
    2297     delete[] m_cpRefVoi;
    2298   }
    2299 
    2300   if ( m_cpPresentFlag != NULL )
    2301   {
    2302     for ( i = 0; i < iNumViews ; i++ )
    2303     {
    2304       delete [] m_cpPresentFlag[i];
    2305     }
    2306     delete[] m_cpPresentFlag;
    2307   }
    2308 
    2309 
    2310   if ( m_cpInSliceSegmentHeaderFlag != NULL )
    2311   {
    2312     delete [] m_cpInSliceSegmentHeaderFlag;
    2313   }
    2314 
    2315 
    2316   if ( m_aaaiCodedScale != NULL )
    2317   {
    2318     for ( i = 0; i < iNumViews ; i++ )
    2319     {
    2320       for ( j = 0; j < 2; j++ )
    2321       {
    2322         delete [] m_aaaiCodedScale[i][j];
    2323       }
    2324       delete [] m_aaaiCodedScale[i];
    2325     }
    2326     delete [] m_aaaiCodedScale;
    2327   }
    2328 
    2329   if ( m_aaaiCodedOffset != NULL )
    2330   {
    2331     for ( i = 0; i < iNumViews ; i++ )
    2332     {
    2333       for ( j = 0; j < 2; j++ )
    2334       {
    2335         delete [] m_aaaiCodedOffset[i][j];
    2336       }
    2337       delete [] m_aaaiCodedOffset[i];
    2338     }
    2339     delete [] m_aaaiCodedOffset;
    2340   }
    2341 }
    2342 
    2343 
    2344 
    2345 #endif // H_3D
    2346 
    2347 
    2348 Int TComVPS::xGetDimBitOffset( Int j )
     2236#endif // NH_3D
     2237
     2238
     2239Int TComVPS::xGetDimBitOffset( Int j ) const
    23492240{
    23502241  Int dimBitOffset = 0;
     
    23632254}
    23642255
    2365 Int TComVPS::inferDimensionId( Int i, Int j )
     2256Int TComVPS::inferDimensionId( Int i, Int j ) const
    23662257{
    23672258    return ( ( getLayerIdInNuh( i ) & ( (1 << xGetDimBitOffset( j + 1 ) ) - 1) ) >> xGetDimBitOffset( j ) );
    23682259}
    23692260
    2370 Int TComVPS::inferLastDimsionIdLenMinus1()
     2261Int TComVPS::inferLastDimsionIdLenMinus1() const
    23712262{
    23722263  return ( 5 - xGetDimBitOffset( getNumScalabilityTypes() - 1 ) );
    23732264}
    23742265
    2375 Int TComVPS::getNumLayersInIdList( Int lsIdx )
     2266Int TComVPS::getNumLayersInIdList( Int lsIdx ) const
    23762267{
    23772268  assert( lsIdx >= 0 );
     
    23802271}
    23812272
    2382 Int    TComVPS::getNumOutputLayerSets()
     2273Int    TComVPS::getNumOutputLayerSets() const
    23832274{
    23842275  return getNumAddOlss() + getNumLayerSets();
     
    24272318}
    24282319
    2429 Bool TComVPS::inferOutputLayerFlag( Int i, Int j )
     2320Bool TComVPS::inferOutputLayerFlag( Int i, Int j ) const
    24302321{
    24312322  Bool outputLayerFlag;
     
    24552346}
    24562347
    2457 Int TComVPS::getMaxSubLayersInLayerSetMinus1( Int i )
     2348Int TComVPS::getMaxSubLayersInLayerSetMinus1( Int i ) const
    24582349{
    24592350  Int maxSLMinus1 = 0;
     
    24662357}
    24672358
    2468 Bool TComVPS::getAltOutputLayerFlagVar( Int i )
     2359Bool TComVPS::getAltOutputLayerFlagVar( Int i ) const
    24692360{
    24702361  // Semantics variable not syntax element !
     
    24812372
    24822373
    2483 Int TComVPS::inferProfileTierLevelIdx(Int i, Int j)
     2374Int TComVPS::inferProfileTierLevelIdx(Int i, Int j) const
    24842375{
    24852376  Bool inferZero        = ( i == 0 && j == 0 &&  getVpsBaseLayerInternalFlag() );
     
    25552446}
    25562447
    2557 Void TComVPS::printPTL()
     2448Void TComVPS::printPTL() const
    25582449{
    25592450  std::vector<Int> idx;
    25602451  std::vector<Int> num;
    2561   std::vector< std::vector<Int> > ptlInfo;
     2452  IntAry2d ptlInfo;
    25622453
    25632454  std::cout << std::right << std::setw(60) << std::setfill('-') << " " << std::setfill(' ') << std::endl << "PTLI" << std::endl;
     
    25662457  {
    25672458    std::vector<Int> curPtlInfo;
    2568     ProfileTierLevel* ptl = getPTL( i )->getGeneralPTL();
     2459    const ProfileTierLevel* ptl = getPTL( i )->getGeneralPTL();
    25692460    curPtlInfo.push_back( (Int) ptl->getProfileIdc()  );
    25702461    curPtlInfo.push_back( (Int) ptl->getTierFlag()    );
     
    25912482}
    25922483
    2593 Void TComVPS::printLayerDependencies()
     2484Void TComVPS::printLayerDependencies() const
    25942485{
    25952486  vector<Int> fullArray;
    25962487  vector<Int> range;
    25972488
    2598 #if H_3D
     2489#if NH_3D
    25992490  vector<Int> depthId;
    26002491#endif
     
    26122503    auxId         .push_back( getAuxId       ( i ) );     
    26132504    viewId        .push_back( getViewId      ( getLayerIdInNuh( i ) ) );
    2614 #if H_3D 
     2505#if NH_3D 
    26152506    depthId.push_back( getDepthId( i ) );
    26162507#endif
     
    26232514  xPrintArray( "IdRefLayer"      , getMaxLayersMinus1() + 1, m_layerIdInNuh, m_numRefLayers, m_idRefLayer, true );
    26242515  xPrintArray( "IdDirectRefLayer", getMaxLayersMinus1() + 1, m_layerIdInNuh, m_numDirectRefLayers, m_idDirectRefLayer, true );
    2625 #if H_3D
     2516#if NH_3D
    26262517  xPrintArray( "IdRefListLayer", getMaxLayersMinus1() + 1, m_layerIdInNuh, m_numRefListLayers, m_idRefListLayer, true );
    26272518#endif
     
    26302521}
    26312522
    2632 Void TComVPS::printScalabilityId()
     2523Void TComVPS::printScalabilityId() const
    26332524{
    26342525  vector<Int> layerIdxInVps;
    26352526
    2636 #if H_3D
     2527
    26372528  vector<Int> depthId;
    2638 #endif
    2639 
    26402529  vector<Int> viewOrderIndex;
    26412530  vector<Int> auxId;
     
    26472536    Int layerIdInNuh = getLayerIdInNuh( i );
    26482537    layerIdxInVps  .push_back( i );
     2538    depthId       .push_back( getDepthId     ( layerIdInNuh ) );
    26492539    viewOrderIndex.push_back( getViewIndex   ( layerIdInNuh ) );
    26502540    dependencyId  .push_back( getDependencyId( layerIdInNuh ) );
    26512541    auxId         .push_back( getAuxId       ( layerIdInNuh ) );     
    26522542    viewId        .push_back( getViewId      ( layerIdInNuh ) );
    2653 #if H_3D 
    2654     depthId       .push_back( getDepthId     ( layerIdInNuh ) );
    2655 #endif
     2543
    26562544  }
    26572545
     
    26602548  xPrintArray( "layer_id_in_nuh", getMaxLayersMinus1()+1, m_layerIdInNuh, false );     
    26612549
    2662   xPrintArray( "ViewOrderIndex", getMaxLayersMinus1()+1, viewOrderIndex, false );     
     2550  xPrintArray( "DepthLayerFlag", getMaxLayersMinus1()+1, depthId       , false );     
     2551  xPrintArray( "ViewOrderIdx"  , getMaxLayersMinus1()+1, viewOrderIndex, false );     
    26632552  xPrintArray( "DependencyId"  , getMaxLayersMinus1()+1, dependencyId  , false );     
    26642553  xPrintArray( "AuxId"         , getMaxLayersMinus1()+1, auxId         , false );     
    2665   xPrintArray( "ViewId"        , getMaxLayersMinus1()+1, viewId        , false );     
     2554  xPrintArray( "ViewIdVal"     , getMaxLayersMinus1()+1, viewId        , false );     
    26662555
    26672556  std::cout << std::endl;
    26682557}
    26692558
    2670 Void TComVPS::printLayerSets()
     2559Void TComVPS::printLayerSets() const
    26712560{
    26722561  vector<Int> fullArray;
     
    27212610}
    27222611
    2723 #if H_3D
     2612#if NH_3D
    27242613Void TComVPS::initViewCompLayer()
    27252614{
     
    27492638}
    27502639
    2751 Int TComVPS::getVoiInVps(Int viewOIdx)
     2640Int TComVPS::getVoiInVps(Int viewOIdx) const
    27522641{
    27532642  for ( Int i = 0; i < m_viewOIdxList.size(); i++ )
     
    27832672#endif
    27842673
    2785 #endif // H_MV
     2674#endif // NH_MV
    27862675
    27872676// ------------------------------------------------------------------------------------------------
    27882677// Sequence parameter set (SPS)
    27892678// ------------------------------------------------------------------------------------------------
     2679
     2680TComSPSRExt::TComSPSRExt()
     2681 : m_transformSkipRotationEnabledFlag   (false)
     2682 , m_transformSkipContextEnabledFlag    (false)
     2683// m_rdpcmEnabledFlag initialized below
     2684 , m_extendedPrecisionProcessingFlag    (false)
     2685 , m_intraSmoothingDisabledFlag         (false)
     2686 , m_highPrecisionOffsetsEnabledFlag    (false)
     2687 , m_persistentRiceAdaptationEnabledFlag(false)
     2688 , m_cabacBypassAlignmentEnabledFlag    (false)
     2689{
     2690  for (UInt signallingModeIndex = 0; signallingModeIndex < NUMBER_OF_RDPCM_SIGNALLING_MODES; signallingModeIndex++)
     2691  {
     2692    m_rdpcmEnabledFlag[signallingModeIndex] = false;
     2693  }
     2694}
    27902695
    27912696TComSPS::TComSPS()
     
    27982703, m_picHeightInLumaSamples    (288)
    27992704, m_log2MinCodingBlockSize    (  0)
    2800 , m_log2DiffMaxMinCodingBlockSize (0)
     2705, m_log2DiffMaxMinCodingBlockSize(0)
    28012706, m_uiMaxCUWidth              ( 32)
    28022707, m_uiMaxCUHeight             ( 32)
    2803 , m_uiMaxCUDepth              (  3)
     2708, m_uiMaxTotalCUDepth         (  3)
    28042709, m_bLongTermRefsPresent      (false)
    28052710, m_uiQuadtreeTULog2MaxSize   (  0)
     
    28082713, m_uiQuadtreeTUMaxDepthIntra (  0)
    28092714// Tool list
    2810 , m_usePCM                   (false)
     2715, m_usePCM                    (false)
    28112716, m_pcmLog2MaxSize            (  5)
    28122717, m_uiPCMLog2MinSize          (  7)
    2813 , m_bitDepthY                 (  8)
    2814 , m_bitDepthC                 (  8)
    2815 , m_qpBDOffsetY               (  0)
    2816 , m_qpBDOffsetC               (  0)
    2817 , m_uiPCMBitDepthLuma         (  8)
    2818 , m_uiPCMBitDepthChroma       (  8)
    28192718, m_bPCMFilterDisableFlag     (false)
    28202719, m_uiBitsForPOC              (  8)
    2821 , m_numLongTermRefPicSPS    (  0) 
     2720, m_numLongTermRefPicSPS      (  0)
    28222721, m_uiMaxTrSize               ( 32)
    2823 , m_bUseSAO                   (false) 
     2722, m_bUseSAO                   (false)
    28242723, m_bTemporalIdNestingFlag    (false)
    28252724, m_scalingListEnabledFlag    (false)
     
    28272726, m_vuiParametersPresentFlag  (false)
    28282727, m_vuiParameters             ()
    2829 #if H_MV
     2728#if NH_MV
    28302729, m_pcVPS                     ( NULL )
    28312730, m_spsInferScalingListFlag   ( false )
     
    28362735, m_interViewMvVertConstraintFlag (false)
    28372736#endif
    2838 {
     2737
     2738{
     2739  for(Int ch=0; ch<MAX_NUM_CHANNEL_TYPE; ch++)
     2740  {
     2741    m_bitDepths.recon[ch] = 8;
     2742#if O0043_BEST_EFFORT_DECODING
     2743    m_bitDepths.stream[ch] = 8;
     2744#endif
     2745    m_pcmBitDepths[ch] = 8;
     2746    m_qpBDOffset   [ch] = 0;
     2747  }
     2748
     2749
    28392750  for ( Int i = 0; i < MAX_TLAYER; i++ )
    28402751  {
     
    28432754    m_numReorderPics[i]       = 0;
    28442755  }
    2845   m_scalingList = new TComScalingList;
     2756
    28462757  ::memset(m_ltRefPicPocLsbSps, 0, sizeof(m_ltRefPicPocLsbSps));
    28472758  ::memset(m_usedByCurrPicLtSPSFlag, 0, sizeof(m_usedByCurrPicLtSPSFlag));
    2848 #if H_MV
     2759#if NH_MV
    28492760  m_spsRangeExtensionsFlag     = false;
    28502761  m_spsMultilayerExtensionFlag = false;
    2851 #if H_3D
    28522762  m_spsExtension5bits          = 0;
    28532763  m_sps3dExtensionFlag         = false;
    2854 #else
    2855   m_spsExtension6bits          = 0;
    2856 #endif
    2857 
    2858 #endif
     2764
     2765#endif
     2766
    28592767}
    28602768
    28612769TComSPS::~TComSPS()
    28622770{
    2863   delete m_scalingList;
    28642771  m_RPSList.destroy();
    28652772}
    28662773
    28672774Void  TComSPS::createRPSList( Int numRPS )
    2868 { 
     2775{
    28692776  m_RPSList.destroy();
    28702777  m_RPSList.create(numRPS);
    28712778}
    28722779
    2873 Void TComSPS::setHrdParameters( UInt frameRate, UInt numDU, UInt bitRate, Bool randomAccess )
    2874 {
    2875   if( !getVuiParametersPresentFlag() )
    2876   {
    2877     return;
    2878   }
    2879 
    2880   TComVUI *vui = getVuiParameters();
    2881   TComHRD *hrd = vui->getHrdParameters();
    2882 
    2883   TimingInfo *timingInfo = vui->getTimingInfo();
    2884   timingInfo->setTimingInfoPresentFlag( true );
    2885   switch( frameRate )
    2886   {
    2887   case 24:
    2888     timingInfo->setNumUnitsInTick( 1125000 );    timingInfo->setTimeScale    ( 27000000 );
    2889     break;
    2890   case 25:
    2891     timingInfo->setNumUnitsInTick( 1080000 );    timingInfo->setTimeScale    ( 27000000 );
    2892     break;
    2893   case 30:
    2894     timingInfo->setNumUnitsInTick( 900900 );     timingInfo->setTimeScale    ( 27000000 );
    2895     break;
    2896   case 50:
    2897     timingInfo->setNumUnitsInTick( 540000 );     timingInfo->setTimeScale    ( 27000000 );
    2898     break;
    2899   case 60:
    2900     timingInfo->setNumUnitsInTick( 450450 );     timingInfo->setTimeScale    ( 27000000 );
    2901     break;
    2902   default:
    2903     timingInfo->setNumUnitsInTick( 1001 );       timingInfo->setTimeScale    ( 60000 );
    2904     break;
    2905   }
    2906 
    2907   Bool rateCnt = ( bitRate > 0 );
    2908   hrd->setNalHrdParametersPresentFlag( rateCnt );
    2909   hrd->setVclHrdParametersPresentFlag( rateCnt );
    2910 
    2911   hrd->setSubPicCpbParamsPresentFlag( ( numDU > 1 ) );
    2912 
    2913   if( hrd->getSubPicCpbParamsPresentFlag() )
    2914   {
    2915     hrd->setTickDivisorMinus2( 100 - 2 );                          //
    2916     hrd->setDuCpbRemovalDelayLengthMinus1( 7 );                    // 8-bit precision ( plus 1 for last DU in AU )
    2917     hrd->setSubPicCpbParamsInPicTimingSEIFlag( true );
    2918     hrd->setDpbOutputDelayDuLengthMinus1( 5 + 7 );                 // With sub-clock tick factor of 100, at least 7 bits to have the same value as AU dpb delay
    2919   }
    2920   else
    2921   {
    2922     hrd->setSubPicCpbParamsInPicTimingSEIFlag( false ); 
    2923   }
    2924 
    2925   hrd->setBitRateScale( 4 );                                       // in units of 2~( 6 + 4 ) = 1,024 bps
    2926   hrd->setCpbSizeScale( 6 );                                       // in units of 2~( 4 + 4 ) = 1,024 bit
    2927   hrd->setDuCpbSizeScale( 6 );                                       // in units of 2~( 4 + 4 ) = 1,024 bit
    2928  
    2929   hrd->setInitialCpbRemovalDelayLengthMinus1(15);                  // assuming 0.5 sec, log2( 90,000 * 0.5 ) = 16-bit
    2930   if( randomAccess )
    2931   {
    2932     hrd->setCpbRemovalDelayLengthMinus1(5);                        // 32 = 2^5 (plus 1)
    2933     hrd->setDpbOutputDelayLengthMinus1 (5);                        // 32 + 3 = 2^6
    2934   }
    2935   else
    2936   {
    2937     hrd->setCpbRemovalDelayLengthMinus1(9);                        // max. 2^10
    2938     hrd->setDpbOutputDelayLengthMinus1 (9);                        // max. 2^10
    2939   }
    2940 
    2941 /*
    2942    Note: only the case of "vps_max_temporal_layers_minus1 = 0" is supported.
    2943 */
    2944   Int i, j;
    2945   UInt birateValue, cpbSizeValue;
    2946   UInt ducpbSizeValue;
    2947   UInt duBitRateValue = 0;
    2948 
    2949   for( i = 0; i < MAX_TLAYER; i ++ )
    2950   {
    2951     hrd->setFixedPicRateFlag( i, 1 );
    2952     hrd->setPicDurationInTcMinus1( i, 0 );
    2953     hrd->setLowDelayHrdFlag( i, 0 );
    2954     hrd->setCpbCntMinus1( i, 0 );
    2955 
    2956     birateValue  = bitRate;
    2957     cpbSizeValue = bitRate;                                     // 1 second
    2958     ducpbSizeValue = bitRate/numDU;
    2959     duBitRateValue = bitRate;
    2960     for( j = 0; j < ( hrd->getCpbCntMinus1( i ) + 1 ); j ++ )
    2961     {
    2962       hrd->setBitRateValueMinus1( i, j, 0, ( birateValue  - 1 ) );
    2963       hrd->setCpbSizeValueMinus1( i, j, 0, ( cpbSizeValue - 1 ) );
    2964       hrd->setDuCpbSizeValueMinus1( i, j, 0, ( ducpbSizeValue - 1 ) );
    2965       hrd->setCbrFlag( i, j, 0, ( j == 0 ) );
    2966 
    2967       hrd->setBitRateValueMinus1( i, j, 1, ( birateValue  - 1) );
    2968       hrd->setCpbSizeValueMinus1( i, j, 1, ( cpbSizeValue - 1 ) );
    2969       hrd->setDuCpbSizeValueMinus1( i, j, 1, ( ducpbSizeValue - 1 ) );
    2970       hrd->setDuBitRateValueMinus1( i, j, 1, ( duBitRateValue - 1 ) );
    2971       hrd->setCbrFlag( i, j, 1, ( j == 0 ) );
    2972     }
    2973   }
    2974 }
    29752780const Int TComSPS::m_winUnitX[]={1,2,2,1};
    29762781const Int TComSPS::m_winUnitY[]={1,2,1,1};
    29772782
     2783TComPPSRExt::TComPPSRExt()
     2784: m_log2MaxTransformSkipBlockSize      (2)
     2785, m_crossComponentPredictionEnabledFlag(false)
     2786, m_diffCuChromaQpOffsetDepth          (0)
     2787, m_chromaQpOffsetListLen              (0)
     2788// m_ChromaQpAdjTableIncludingNullEntry initialized below
     2789// m_log2SaoOffsetScale initialized below
     2790{
     2791  m_ChromaQpAdjTableIncludingNullEntry[0].u.comp.CbOffset = 0; // Array includes entry [0] for the null offset used when cu_chroma_qp_offset_flag=0. This is initialised here and never subsequently changed.
     2792  m_ChromaQpAdjTableIncludingNullEntry[0].u.comp.CrOffset = 0;
     2793  for(Int ch=0; ch<MAX_NUM_CHANNEL_TYPE; ch++)
     2794  {
     2795    m_log2SaoOffsetScale[ch] = 0;
     2796  }
     2797}
     2798
    29782799TComPPS::TComPPS()
    2979 : m_PPSId                       (0)
    2980 , m_SPSId                       (0)
    2981 , m_picInitQPMinus26            (0)
    2982 , m_useDQP                      (false)
    2983 , m_bConstrainedIntraPred       (false)
    2984 , m_bSliceChromaQpFlag          (false)
    2985 , m_pcSPS                       (NULL)
    2986 , m_uiMaxCuDQPDepth             (0)
    2987 , m_uiMinCuDQPSize              (0)
    2988 , m_chromaCbQpOffset            (0)
    2989 , m_chromaCrQpOffset            (0)
    2990 , m_numRefIdxL0DefaultActive    (1)
    2991 , m_numRefIdxL1DefaultActive    (1)
    2992 , m_TransquantBypassEnableFlag  (false)
    2993 , m_useTransformSkip             (false)
    2994 , m_dependentSliceSegmentsEnabledFlag    (false)
    2995 , m_tilesEnabledFlag               (false)
    2996 , m_entropyCodingSyncEnabledFlag   (false)
    2997 , m_loopFilterAcrossTilesEnabledFlag  (true)
    2998 , m_uniformSpacingFlag           (false)
    2999 , m_numTileColumnsMinus1         (0)
    3000 , m_numTileRowsMinus1            (0)
    3001 , m_numSubstreams               (1)
    3002 , m_signHideFlag(0)
    3003 , m_cabacInitPresentFlag        (false)
    3004 , m_encCABACTableIdx            (I_SLICE)
    3005 , m_sliceHeaderExtensionPresentFlag    (false)
    3006 , m_loopFilterAcrossSlicesEnabledFlag (false)
    3007 , m_listsModificationPresentFlag(  0)
    3008 , m_numExtraSliceHeaderBits(0)
    3009 #if H_MV
    3010 , m_ppsInferScalingListFlag(false)
    3011 , m_ppsScalingListRefLayerId(0)
    3012 , m_pocResetInfoPresentFlag(false)
    3013 #if H_3D
    3014 , m_pcDLT(NULL)
    3015 #endif
    3016 #endif
    3017 {
    3018   m_scalingList = new TComScalingList;
    3019 
    3020 #if H_MV
     2800: m_PPSId                            (0)
     2801, m_SPSId                            (0)
     2802, m_picInitQPMinus26                 (0)
     2803, m_useDQP                           (false)
     2804, m_bConstrainedIntraPred            (false)
     2805, m_bSliceChromaQpFlag               (false)
     2806, m_uiMaxCuDQPDepth                  (0)
     2807, m_chromaCbQpOffset                 (0)
     2808, m_chromaCrQpOffset                 (0)
     2809, m_numRefIdxL0DefaultActive         (1)
     2810, m_numRefIdxL1DefaultActive         (1)
     2811, m_TransquantBypassEnableFlag       (false)
     2812, m_useTransformSkip                 (false)
     2813, m_dependentSliceSegmentsEnabledFlag(false)
     2814, m_tilesEnabledFlag                 (false)
     2815, m_entropyCodingSyncEnabledFlag     (false)
     2816, m_loopFilterAcrossTilesEnabledFlag (true)
     2817, m_uniformSpacingFlag               (false)
     2818, m_numTileColumnsMinus1             (0)
     2819, m_numTileRowsMinus1                (0)
     2820, m_signHideFlag                     (false)
     2821, m_cabacInitPresentFlag             (false)
     2822, m_sliceHeaderExtensionPresentFlag  (false)
     2823, m_loopFilterAcrossSlicesEnabledFlag(false)
     2824, m_listsModificationPresentFlag     (0)
     2825, m_numExtraSliceHeaderBits          (0)
     2826#if NH_MV
     2827, m_ppsInferScalingListFlag          (false)
     2828, m_ppsScalingListRefLayerId         (0)
     2829, m_pocResetInfoPresentFlag          (false)
     2830#endif
     2831#if NH_3D_DLT
     2832, m_cDLT                             ()
     2833#endif
     2834{
     2835#if NH_MV
    30212836  m_ppsRangeExtensionsFlag     = false;
    30222837  m_ppsMultilayerExtensionFlag = false;
    3023 #if !H_3D
    3024   m_ppsExtension6bits          = 0;
    3025 #else
    30262838  m_pps3dExtensionFlag         = false;
    30272839  m_ppsExtension5bits          = 0;
    30282840#endif
    3029 #endif
     2841
    30302842}
    30312843
    30322844TComPPS::~TComPPS()
    30332845{
    3034   delete m_scalingList;
    3035 }
    3036 
    3037 #if H_3D
     2846}
     2847
     2848#if NH_3D_DLT
    30382849TComDLT::TComDLT()
    30392850: m_bDltPresentFlag(false)
     
    30412852, m_uiDepthViewBitDepth(8)
    30422853{
    3043   m_uiDepthViewBitDepth = g_bitDepthY;
    3044 
    30452854  for( Int i = 0; i < MAX_NUM_LAYERS; i++ )
    30462855  {
    30472856    m_bUseDLTFlag                 [i] = false;
    30482857    m_bInterViewDltPredEnableFlag [i] = false;
     2858    m_bDltBitMapRepFlag           [i] = false;
    30492859
    30502860    // allocate some memory and initialize with default mapping
    30512861    m_iNumDepthmapValues[i] = ((1 << m_uiDepthViewBitDepth)-1)+1;
    3052     m_iDepthValue2Idx[i]    = (Int*) xMalloc(Int, m_iNumDepthmapValues[i]);
    3053     m_iIdx2DepthValue[i]    = (Int*) xMalloc(Int, m_iNumDepthmapValues[i]);
     2862    m_iDepthValue2Idx[i]    = std::vector<Int>(m_iNumDepthmapValues[i]);
     2863    m_iIdx2DepthValue[i]    = std::vector<Int>(m_iNumDepthmapValues[i]);
     2864   
     2865    m_iDepthIdxToLayerId[i] = i;
    30542866
    30552867    //default mapping
     
    30642876TComDLT::~TComDLT()
    30652877{
    3066   for( Int i = 0; i < MAX_NUM_LAYERS; i++ )
    3067   {
    3068     if ( m_iDepthValue2Idx[i] != NULL )
    3069     {
    3070       xFree( m_iDepthValue2Idx[i] );
    3071       m_iDepthValue2Idx[i] = NULL;
    3072     }
    3073 
    3074     if ( m_iIdx2DepthValue[i] != NULL )
    3075     {
    3076       xFree( m_iIdx2DepthValue[i] );
    3077       m_iIdx2DepthValue[i] = NULL;
    3078     }
    3079   }
    3080 }
    3081 
    3082 Void TComDLT::setDepthLUTs(Int layerIdInVps, Int* idxToDepthValueTable, Int iNumDepthValues)
    3083 {
    3084   if( idxToDepthValueTable == NULL || iNumDepthValues == 0 ) // default mapping only
     2878 
     2879}
     2880
     2881Void TComDLT::setDepthLUTs(Int layerIdInVps, std::vector<Int> idxToDepthValueTable, Int iNumDepthValues)
     2882{
     2883  if( iNumDepthValues == 0 ) // default mapping only
    30852884    return;
    30862885
    30872886  // copy idx2DepthValue to internal array
    3088   memcpy(m_iIdx2DepthValue[layerIdInVps], idxToDepthValueTable, iNumDepthValues*sizeof(UInt));
    3089 
    3090   UInt uiMaxDepthValue = ((1 << g_bitDepthY)-1);
     2887  m_iIdx2DepthValue[layerIdInVps] = idxToDepthValueTable;
     2888
     2889  UInt uiMaxDepthValue = ((1 << m_uiDepthViewBitDepth)-1);
    30912890  for(Int p=0; p<=uiMaxDepthValue; p++)
    30922891  {
     
    31252924}
    31262925
    3127 Void TComDLT::getDeltaDLT( Int layerIdInVps, Int* piDLTInRef, UInt uiDLTInRefNum, Int* piDeltaDLTOut, UInt *puiDeltaDLTOutNum )
     2926Void TComDLT::getDeltaDLT( Int layerIdInVps, std::vector<Int> piDLTInRef, UInt uiDLTInRefNum, std::vector<Int>& riDeltaDLTOut, UInt&ruiDeltaDLTOutNum ) const
    31282927{
    31292928  Bool abBM0[ 256 ];
     
    31442943  }
    31452944 
    3146   *puiDeltaDLTOutNum = 0;
     2945  ruiDeltaDLTOutNum = 0;
    31472946  for( Int i = 0; i < 256; i++ )
    31482947  {
    31492948    if( abBM0[ i ] ^ abBM1[ i ] )
    31502949    {
    3151       piDeltaDLTOut[ *puiDeltaDLTOutNum ] = i;
    3152       *puiDeltaDLTOutNum = *puiDeltaDLTOutNum + 1;
    3153     }
    3154   }
    3155 }
    3156 
    3157 Void TComDLT::setDeltaDLT( Int layerIdInVps, Int* piDLTInRef, UInt uiDLTInRefNum, Int* piDeltaDLTIn, UInt uiDeltaDLTInNum )
     2950      riDeltaDLTOut[ ruiDeltaDLTOutNum++ ] = i;
     2951    }
     2952  }
     2953}
     2954
     2955Void TComDLT::setDeltaDLT( Int layerIdInVps, std::vector<Int> piDLTInRef, UInt uiDLTInRefNum, std::vector<Int> piDeltaDLTIn, UInt uiDeltaDLTInNum )
    31582956{
    31592957  Bool abBM0[ 256 ];
     
    31742972  }
    31752973 
    3176   Int aiIdx2DepthValue[256];
     2974  std::vector<Int> aiIdx2DepthValue(256, 0);
    31772975  UInt uiNumDepthValues = 0;
    3178   memset( aiIdx2DepthValue, 0, sizeof( aiIdx2DepthValue ));
     2976  std::fill(aiIdx2DepthValue.begin(), aiIdx2DepthValue.end(), 0);
    31792977 
    31802978  for( Int i = 0; i < 256; i++ )
     
    31922990#endif
    31932991
    3194 #if H_MV
    3195 Void TComSPS::inferRepFormat( TComVPS* vps, Int layerIdCurr )
     2992#if NH_MV
     2993Void TComSPS::inferRepFormat( TComVPS* vps, Int layerIdCurr, Bool encoder )
    31962994{
    31972995  if ( getMultiLayerExtSpsFlag() )
    3198   {
     2996  {    
    31992997    Int            repFormatIdx = getUpdateRepFormatFlag() ?  getSpsRepFormatIdx() : vps->getVpsRepFormatIdx( vps->getLayerIdInVps( layerIdCurr ) ) ;
    3200     TComRepFormat* repFormat    = vps->getRepFormat( repFormatIdx );
    3201     setChromaFormatIdc( repFormat->getChromaFormatVpsIdc() );         
    3202     //// ToDo: add when supported:
    3203     // setSeperateColourPlaneFlag( repFormat->getSeparateColourPlaneVpsFlag() ) ;
    3204 
    3205     setPicWidthInLumaSamples ( repFormat->getPicWidthVpsInLumaSamples()  );
    3206     setPicHeightInLumaSamples( repFormat->getPicHeightVpsInLumaSamples() );
    3207 
    3208     setBitDepthY             ( repFormat->getBitDepthVpsLumaMinus8()   + 8 );
    3209     setQpBDOffsetY           ( (Int) (6*( getBitDepthY() - 8 )) );
    3210 
    3211     setBitDepthC             ( repFormat->getBitDepthVpsChromaMinus8() + 8 );
    3212     setQpBDOffsetC           ( (Int) (6* ( getBitDepthC() -8 ) ) );
    3213     Window &spsConf    = getConformanceWindow();   
    3214 
    3215     // Scaled later
    3216     spsConf.setScaledFlag( false );
    3217     spsConf.setWindowLeftOffset  ( repFormat->getConfWinVpsLeftOffset()    );
    3218     spsConf.setWindowRightOffset ( repFormat->getConfWinVpsRightOffset()   );
    3219     spsConf.setWindowTopOffset   ( repFormat->getConfWinVpsTopOffset()     );
    3220     spsConf.setWindowBottomOffset( repFormat->getConfWinVpsBottomOffset()  );   
     2998    const TComRepFormat* repFormat    = vps->getRepFormat( repFormatIdx );
     2999
     3000    if ( encoder )
     3001    {
     3002      assert( getChromaFormatIdc() ==  (ChromaFormat) repFormat->getChromaFormatVpsIdc() );         
     3003      //// ToDo: add when supported:
     3004      // assert( getSeperateColourPlaneFlag( repFormat->getSeparateColourPlaneVpsFlag() ) ;
     3005
     3006      assert( getPicWidthInLumaSamples()  ==  repFormat->getPicWidthVpsInLumaSamples()  );
     3007      assert( getPicHeightInLumaSamples() == repFormat->getPicHeightVpsInLumaSamples() );
     3008
     3009      assert( getBitDepth              ( CHANNEL_TYPE_LUMA ) == repFormat->getBitDepthVpsLumaMinus8()   + 8 );
     3010      assert( getQpBDOffset            ( CHANNEL_TYPE_LUMA ) == (Int) (6*( getBitDepth( CHANNEL_TYPE_LUMA ) - 8 )) );
     3011
     3012      assert( getBitDepth              ( CHANNEL_TYPE_CHROMA ) == repFormat->getBitDepthVpsChromaMinus8() + 8 );
     3013      assert( getQpBDOffset            ( CHANNEL_TYPE_CHROMA ) == (Int) (6* ( getBitDepth( CHANNEL_TYPE_CHROMA ) -8 ) ) );
     3014    }
     3015    else
     3016    {
     3017      setChromaFormatIdc( (ChromaFormat) repFormat->getChromaFormatVpsIdc() );         
     3018      //// ToDo: add when supported:
     3019      // setSeperateColourPlaneFlag( repFormat->getSeparateColourPlaneVpsFlag() ) ;
     3020
     3021      setPicWidthInLumaSamples ( repFormat->getPicWidthVpsInLumaSamples()  );
     3022      setPicHeightInLumaSamples( repFormat->getPicHeightVpsInLumaSamples() );
     3023
     3024      setBitDepth              ( CHANNEL_TYPE_LUMA, repFormat->getBitDepthVpsLumaMinus8()   + 8 );
     3025      setQpBDOffset            ( CHANNEL_TYPE_LUMA, (Int) (6*( getBitDepth( CHANNEL_TYPE_LUMA ) - 8 )) );
     3026
     3027      setBitDepth              ( CHANNEL_TYPE_CHROMA, repFormat->getBitDepthVpsChromaMinus8() + 8 );
     3028      setQpBDOffset            ( CHANNEL_TYPE_CHROMA, (Int) (6* ( getBitDepth( CHANNEL_TYPE_CHROMA ) -8 ) ) );
     3029      Window &spsConf    = getConformanceWindow();   
     3030
     3031      // Scaled later
     3032      spsConf.setScaledFlag( false );
     3033      spsConf.setWindowLeftOffset  ( repFormat->getConfWinVpsLeftOffset()    );
     3034      spsConf.setWindowRightOffset ( repFormat->getConfWinVpsRightOffset()   );
     3035      spsConf.setWindowTopOffset   ( repFormat->getConfWinVpsTopOffset()     );
     3036      spsConf.setWindowBottomOffset( repFormat->getConfWinVpsBottomOffset()  );           
     3037    }
    32213038
    32223039   if ( getMultiLayerExtSpsFlag() && getUpdateRepFormatFlag() )
     
    32293046      assert( getPicHeightInLumaSamples() <= repFormat->getPicHeightVpsInLumaSamples()   );
    32303047
    3231       assert( getBitDepthY()              <= repFormat->getBitDepthVpsLumaMinus8()   + 8 );         
    3232       assert( getBitDepthC()              <= repFormat->getBitDepthVpsChromaMinus8() + 8 );
     3048      assert( getBitDepth( CHANNEL_TYPE_LUMA   )  <= repFormat->getBitDepthVpsLumaMinus8()   + 8 );         
     3049      assert( getBitDepth( CHANNEL_TYPE_CHROMA )  <= repFormat->getBitDepthVpsChromaMinus8() + 8 );
    32333050    }
    32343051  }
     
    32383055  getConformanceWindow().scaleOffsets( scal );
    32393056  getVuiParameters()->getDefaultDisplayWindow().scaleOffsets( scal );
    3240 }
    3241 
    3242 Void TComSPS::inferScalingList( TComSPS* spsSrc )
     3057
     3058  if (encoder && getMultiLayerExtSpsFlag() )
     3059  {
     3060    Int            repFormatIdx = getUpdateRepFormatFlag() ?  getSpsRepFormatIdx() : vps->getVpsRepFormatIdx( vps->getLayerIdInVps( layerIdCurr ) ) ;
     3061    const TComRepFormat* repFormat    = vps->getRepFormat( repFormatIdx );
     3062
     3063    Window &spsConf    = getConformanceWindow();   
     3064    assert( spsConf.getWindowLeftOffset  () == repFormat->getConfWinVpsLeftOffset()    );
     3065    assert( spsConf.getWindowRightOffset () == repFormat->getConfWinVpsRightOffset()   );
     3066    assert( spsConf.getWindowTopOffset   () == repFormat->getConfWinVpsTopOffset()     );
     3067    assert( spsConf.getWindowBottomOffset() == repFormat->getConfWinVpsBottomOffset()  );           
     3068  }
     3069}
     3070
     3071Void TComSPS::inferScalingList( const TComSPS* spsSrc )
    32433072{
    32443073  if ( getSpsInferScalingListFlag() )
     
    32463075    assert( spsSrc != NULL );
    32473076    assert( !spsSrc->getSpsInferScalingListFlag() );             
    3248     getScalingList()->inferFrom( spsSrc->getScalingList() );
     3077    getScalingList().inferFrom( (spsSrc->getScalingList()) );
    32493078  }
    32503079}
     
    32943123}
    32953124
    3296 Void TComSPS::checkRpsMaxNumPics( TComVPS* vps, Int currLayerId )
     3125Void TComSPS::checkRpsMaxNumPics( const TComVPS* vps, Int currLayerId ) const
    32973126{
    32983127  for (Int i = 0; i < getRPSList()->getNumberOfReferencePictureSets(); i++ )
    32993128  {
    3300     TComReferencePictureSet* rps = getRPSList()->getReferencePictureSet( i );
     3129    const TComReferencePictureSet* rps = getRPSList()->getReferencePictureSet( i );
    33013130    if ( !rps->getInterRPSPrediction() )
    33023131    {
     
    33273156}
    33283157#endif
     3158
    33293159
    33303160TComReferencePictureSet::TComReferencePictureSet()
     
    33333163, m_numberOfPositivePictures (0)
    33343164, m_numberOfLongtermPictures (0)
    3335 , m_interRPSPrediction (0) 
    3336 , m_deltaRIdxMinus1 (0)   
    3337 , m_deltaRPS (0) 
    3338 , m_numRefIdc (0) 
     3165, m_interRPSPrediction (0)
     3166, m_deltaRIdxMinus1 (0)
     3167, m_deltaRPS (0)
     3168, m_numRefIdc (0)
    33393169{
    33403170  ::memset( m_deltaPOC, 0, sizeof(m_deltaPOC) );
     
    33423172  ::memset( m_used, 0, sizeof(m_used) );
    33433173  ::memset( m_refIdc, 0, sizeof(m_refIdc) );
     3174  ::memset( m_bCheckLTMSB, 0, sizeof(m_bCheckLTMSB) );
     3175  ::memset( m_pocLSBLT, 0, sizeof(m_pocLSBLT) );
     3176  ::memset( m_deltaPOCMSBCycleLT, 0, sizeof(m_deltaPOCMSBCycleLT) );
     3177  ::memset( m_deltaPocMSBPresentFlag, 0, sizeof(m_deltaPocMSBPresentFlag) );
    33443178}
    33453179
     
    33633197}
    33643198
    3365 Int TComReferencePictureSet::getUsed(Int bufferNum)
     3199Int TComReferencePictureSet::getUsed(Int bufferNum) const
    33663200{
    33673201  return m_used[bufferNum];
    33683202}
    33693203
    3370 Int TComReferencePictureSet::getDeltaPOC(Int bufferNum)
     3204Int TComReferencePictureSet::getDeltaPOC(Int bufferNum) const
    33713205{
    33723206  return m_deltaPOC[bufferNum];
    33733207}
    33743208
    3375 Int TComReferencePictureSet::getNumberOfPictures()
     3209Int TComReferencePictureSet::getNumberOfPictures() const
    33763210{
    33773211  return m_numberOfPictures;
    33783212}
    33793213
    3380 Int TComReferencePictureSet::getPOC(Int bufferNum)
     3214Int TComReferencePictureSet::getPOC(Int bufferNum) const
    33813215{
    33823216  return m_POC[bufferNum];
     
    33883222}
    33893223
    3390 Bool TComReferencePictureSet::getCheckLTMSBPresent(Int bufferNum)
     3224Bool TComReferencePictureSet::getCheckLTMSBPresent(Int bufferNum) const
    33913225{
    33923226  return m_bCheckLTMSB[bufferNum];
     
    33983232}
    33993233
    3400 /** set the reference idc value at uiBufferNum entry to the value of iRefIdc
    3401  * \param uiBufferNum
    3402  * \param iRefIdc
    3403  * \returns Void
    3404  */
     3234//! set the reference idc value at uiBufferNum entry to the value of iRefIdc
    34053235Void TComReferencePictureSet::setRefIdc(Int bufferNum, Int refIdc)
    34063236{
     
    34083238}
    34093239
    3410 /** get the reference idc value at uiBufferNum
    3411  * \param uiBufferNum
    3412  * \returns Int
    3413  */
    3414 Int  TComReferencePictureSet::getRefIdc(Int bufferNum)
     3240//! get the reference idc value at uiBufferNum
     3241Int  TComReferencePictureSet::getRefIdc(Int bufferNum) const
    34153242{
    34163243  return m_refIdc[bufferNum];
     
    34263253  // sort in increasing order (smallest first)
    34273254  for(Int j=1; j < getNumberOfPictures(); j++)
    3428   { 
     3255  {
    34293256    Int deltaPOC = getDeltaPOC(j);
    34303257    Bool used = getUsed(j);
     
    34443271  Int numNegPics = getNumberOfNegativePictures();
    34453272  for(Int j=0, k=numNegPics-1; j < numNegPics>>1; j++, k--)
    3446   { 
     3273  {
    34473274    Int deltaPOC = getDeltaPOC(j);
    34483275    Bool used = getUsed(j);
     
    34583285 * \returns Void
    34593286 */
    3460 Void TComReferencePictureSet::printDeltaPOC()
     3287Void TComReferencePictureSet::printDeltaPOC() const
    34613288{
    34623289  printf("DeltaPOC = { ");
     
    34643291  {
    34653292    printf("%d%s ", getDeltaPOC(j), (getUsed(j)==1)?"*":"");
    3466   } 
    3467   if (getInterRPSPrediction()) 
     3293  }
     3294  if (getInterRPSPrediction())
    34683295  {
    34693296    printf("}, RefIdc = { ");
     
    34713298    {
    34723299      printf("%d ", getRefIdc(j));
    3473     } 
     3300    }
    34743301  }
    34753302  printf("}\n");
    34763303}
    3477 #if H_MV
    3478 Void TComReferencePictureSet::checkMaxNumPics( Bool vpsExtensionFlag, Int maxNumPics, Int nuhLayerId, Int spsMaxDecPicBufferingMinus1 )
     3304
     3305#if NH_MV
     3306Void TComReferencePictureSet::checkMaxNumPics( Bool vpsExtensionFlag, Int maxNumPics, Int nuhLayerId, Int spsMaxDecPicBufferingMinus1 ) const
    34793307{
    34803308  assert( getNumberOfPictures() >= 0 );
     
    34913319#endif
    34923320
    3493 TComRPSList::TComRPSList()
    3494 :m_referencePictureSets (NULL)
    3495 {
    3496 }
    3497 
    3498 TComRPSList::~TComRPSList()
    3499 {
    3500 }
    3501 
    3502 Void TComRPSList::create( Int numberOfReferencePictureSets)
    3503 {
    3504   m_numberOfReferencePictureSets = numberOfReferencePictureSets;
    3505   m_referencePictureSets = new TComReferencePictureSet[numberOfReferencePictureSets];
    3506 }
    3507 
    3508 Void TComRPSList::destroy()
    3509 {
    3510   if (m_referencePictureSets)
    3511   {
    3512     delete [] m_referencePictureSets;
    3513   }
    3514   m_numberOfReferencePictureSets = 0;
    3515   m_referencePictureSets = NULL;
    3516 }
    3517 
    3518 
    3519 
    3520 TComReferencePictureSet* TComRPSList::getReferencePictureSet(Int referencePictureSetNum)
    3521 {
    3522   return &m_referencePictureSets[referencePictureSetNum];
    3523 }
    3524 
    3525 Int TComRPSList::getNumberOfReferencePictureSets()
    3526 {
    3527   return m_numberOfReferencePictureSets;
    3528 }
    3529 
    3530 Void TComRPSList::setNumberOfReferencePictureSets(Int numberOfReferencePictureSets)
    3531 {
    3532   m_numberOfReferencePictureSets = numberOfReferencePictureSets;
    3533 }
     3321
     3322
    35343323
    35353324TComRefPicListModification::TComRefPicListModification()
    3536 : m_bRefPicListModificationFlagL0 (false)
    3537 , m_bRefPicListModificationFlagL1 (false)
     3325: m_refPicListModificationFlagL0 (false)
     3326, m_refPicListModificationFlagL1 (false)
    35383327{
    35393328  ::memset( m_RefPicSetIdxL0, 0, sizeof(m_RefPicSetIdxL0) );
     
    35473336TComScalingList::TComScalingList()
    35483337{
    3549   init();
    3550 }
    3551 TComScalingList::~TComScalingList()
    3552 {
    3553   destroy();
     3338  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
     3339  {
     3340    for(UInt listId = 0; listId < SCALING_LIST_NUM; listId++)
     3341    {
     3342      m_scalingListCoef[sizeId][listId].resize(min<Int>(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]));
     3343    }
     3344  }
    35543345}
    35553346
    35563347/** set default quantization matrix to array
    35573348*/
    3558 Void TComSlice::setDefaultScalingList()
     3349Void TComScalingList::setDefaultScalingList()
    35593350{
    35603351  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
    35613352  {
    3562     for(UInt listId=0;listId<g_scalingListNum[sizeId];listId++)
    3563     {
    3564       getScalingList()->processDefaultMatrix(sizeId, listId);
     3353    for(UInt listId=0;listId<SCALING_LIST_NUM;listId++)
     3354    {
     3355      processDefaultMatrix(sizeId, listId);
    35653356    }
    35663357  }
     
    35693360 * \returns true if use default quantization matrix in all size
    35703361*/
    3571 Bool TComSlice::checkDefaultScalingList()
     3362Bool TComScalingList::checkDefaultScalingList()
    35723363{
    35733364  UInt defaultCounter=0;
     
    35753366  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
    35763367  {
    3577     for(UInt listId=0;listId<g_scalingListNum[sizeId];listId++)
    3578     {
    3579       if( !memcmp(getScalingList()->getScalingListAddress(sizeId,listId), getScalingList()->getScalingListDefaultAddress(sizeId, listId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])) // check value of matrix
    3580      && ((sizeId < SCALING_LIST_16x16) || (getScalingList()->getScalingListDC(sizeId,listId) == 16))) // check DC value
     3368    for(UInt listId=0;listId<SCALING_LIST_NUM;listId++)
     3369    {
     3370      if( !memcmp(getScalingListAddress(sizeId,listId), getScalingListDefaultAddress(sizeId, listId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])) // check value of matrix
     3371     && ((sizeId < SCALING_LIST_16x16) || (getScalingListDC(sizeId,listId) == 16))) // check DC value
    35813372      {
    35823373        defaultCounter++;
     
    35843375    }
    35853376  }
    3586   return (defaultCounter == (SCALING_LIST_NUM * SCALING_LIST_SIZE_NUM - 4)) ? false : true; // -4 for 32x32
    3587 }
    3588 
    3589 #if H_MV
     3377
     3378  return (defaultCounter == (SCALING_LIST_NUM * SCALING_LIST_SIZE_NUM )) ? false : true;
     3379}
     3380
     3381#if NH_MV
    35903382Void TComSlice::createInterLayerReferencePictureSet( TComPicLists* ivPicLists, std::vector<TComPic*>& refPicSetInterLayer0, std::vector<TComPic*>& refPicSetInterLayer1 )
    35913383{
     
    36653457}
    36663458
    3667 TComPic* TComSlice::getPicFromRefPicSetInterLayer(Int setIdc, Int layerId )
     3459TComPic* TComSlice::getPicFromRefPicSetInterLayer(Int setIdc, Int layerId ) const
    36683460{
    36693461  assert ( setIdc == 0 || setIdc == 1);   
     
    36853477
    36863478
    3687 Int  TComSlice::getRefLayerPicFlag( Int i )
    3688 {
    3689   TComVPS* vps = getVPS();
    3690 #if H_3D
     3479Int  TComSlice::getRefLayerPicFlag( Int i ) const
     3480{
     3481  const TComVPS* vps = getVPS();
     3482#if NH_3D
    36913483  Int refLayerIdx = vps->getLayerIdInVps( vps->getIdRefListLayer( getLayerId(), i ) );
    36923484#else
     
    36993491}   
    37003492
    3701 Int TComSlice::getRefLayerPicIdc( Int j )
     3493Int TComSlice::getRefLayerPicIdc( Int j ) const
    37023494
    37033495  Int refLayerPicIdc = -1;
    37043496  Int curj = 0;
    3705 #if H_3D
     3497#if NH_3D
    37063498  for( Int i = 0;  i < getVPS()->getNumRefListLayers( getLayerId()) ; i++ )
    37073499#else
     
    37253517}
    37263518
    3727 Int  TComSlice::getNumRefLayerPics( )
     3519Int  TComSlice::getNumRefLayerPics( ) const
    37283520
    37293521  Int numRefLayerPics = 0;
    3730 #if H_3D
     3522#if NH_3D
    37313523  for( Int i = 0;  i < getVPS()->getNumRefListLayers( getLayerId()) ; i++ )
    37323524#else
     
    37413533
    37423534
    3743 Int TComSlice::getNumActiveRefLayerPics()
     3535Int TComSlice::getNumActiveRefLayerPics() const
    37443536{
    37453537  Int numActiveRefLayerPics;
     
    37573549    numActiveRefLayerPics = 0;
    37583550  }
    3759 #if H_3D
     3551#if NH_3D
    37603552  else if( getVPS()->getMaxOneActiveRefLayerFlag() || getVPS()->getNumRefListLayers( getLayerId() ) == 1 )
    37613553#else
     
    37723564}
    37733565
    3774 Int TComSlice::getRefPicLayerId( Int i )
    3775 {
    3776 #if H_3D
     3566Int TComSlice::getRefPicLayerId( Int i ) const
     3567{
     3568#if NH_3D
    37773569  return getVPS()->getIdRefListLayer( getLayerId(), getInterLayerPredLayerIdc( i ) );
    37783570#else
     
    37803572#endif
    37813573}
    3782 #if H_3D
    3783 Void TComSlice::setDefaultRefView( )
    3784 {
    3785   setDefaultRefViewIdx( -1 );
    3786   setDefaultRefViewIdxAvailableFlag( false );
     3574#if NH_3D_NBDV
     3575Void TComSlice::setDefaultRefView()
     3576{
     3577  setDefaultRefViewIdx(-1);
     3578  setDefaultRefViewIdxAvailableFlag(false);
    37873579
    37883580  Int valid = 0;
    37893581  Int DefaultRefViewIdx = -1;
    3790   for( UInt curViewIdx = 0; curViewIdx < getViewIndex() && valid == 0; curViewIdx++ )
    3791   {
    3792     for( Int iRefListId = 0; ( iRefListId < (isInterB() ? 2 : 1) ) && !isIntra() && valid == 0; iRefListId++ )
    3793     {
    3794       RefPicList eRefPicList = RefPicList( iRefListId );
    3795       Int        iNumRefPics = getNumRefIdx( eRefPicList );
    3796       for( Int i = 0; i < iNumRefPics; i++ )
     3582
     3583  for(UInt curViewIdx = 0; curViewIdx < getViewIndex() && valid == 0; curViewIdx++)
     3584  {
     3585    for(Int iRefListId = 0; (iRefListId < (isInterB() ? 2 : 1)) && !isIntra() && valid == 0; iRefListId++)
     3586    {
     3587      RefPicList eRefPicList = RefPicList(iRefListId);
     3588      Int        iNumRefPics = getNumRefIdx(eRefPicList);
     3589
     3590      for(Int i = 0; i < iNumRefPics; i++)
    37973591      {
    3798         if(getPOC() == getRefPic( eRefPicList, i )->getPOC() && curViewIdx == getRefPic( eRefPicList, i )->getViewIndex())
     3592        if(getPOC() == getRefPic(eRefPicList, i)->getPOC() && curViewIdx == getRefPic(eRefPicList, i)->getViewIndex())
    37993593        {
    38003594          valid = 1;
     
    38053599    }
    38063600  }
    3807   if( valid )
    3808   {
    3809     setDefaultRefViewIdx( DefaultRefViewIdx );
    3810     setDefaultRefViewIdxAvailableFlag( true );   
    3811   }
    3812 }
    3813 #endif
    3814 
    3815 #if H_3D_ARP
     3601
     3602  if(valid)
     3603  {
     3604    setDefaultRefViewIdx(DefaultRefViewIdx);
     3605    setDefaultRefViewIdxAvailableFlag(true);
     3606  }
     3607}
     3608#endif
     3609
     3610#if NH_3D_ARP
    38163611Void TComSlice::setARPStepNum( TComPicLists*ivPicLists )
    38173612{
     
    38613656        TComPic* picV = getIvPic( getIsDepth(), getVPS()->getViewIndex( layerIdInNuh ) );
    38623657        assert( picV != NULL );
    3863         std::vector<Int> pocsInCurrRPSsPicV = picV->getSlice(0)->getPocsInCurrRPSs();
     3658        IntAry1d pocsInCurrRPSsPicV = picV->getSlice(0)->getPocsInCurrRPSs();
    38643659        Bool refRpRefAvailFlag = false;
    38653660        for (Int idx = 0; idx < pocsInCurrRPSsPicV.size(); idx++)
     
    38833678    }
    38843679  }
    3885 }
    3886 #endif
    3887 
    3888 #if H_3D_IC
     3680  if( m_nARPStepNum > 1)
     3681  {
     3682    for(Int i = 0; i < getNumActiveRefLayerPics(); i ++ )
     3683    {
     3684      Int  iLayerId = getRefPicLayerId( i );
     3685      Int  iViewIdx =   getVPS()->getViewIndex(iLayerId);
     3686      Bool bIsDepth = ( getVPS()->getDepthId  ( iLayerId ) == 1 );
     3687      if( iViewIdx<getViewIndex() && !bIsDepth )
     3688      {
     3689        setBaseViewRefPicList( ivPicLists->getPicList( iLayerId ), iViewIdx );
     3690      }
     3691    }
     3692  }
     3693}
     3694#endif
     3695
     3696#if NH_3D_IC
    38893697// This is an encoder only function and should be moved to TEncSlice or TEncSearch!!
    38903698Void TComSlice::xSetApplyIC(Bool bUseLowLatencyICEnc)
     
    39753783    {
    39763784      // Histogram building - luminance
    3977       Int iMaxPelValue = ( 1 << g_bitDepthY );
     3785      Int iMaxPelValue = ( 1 << getSPS()->getBitDepth(CHANNEL_TYPE_LUMA) );
    39783786      Int *aiRefOrgHist = (Int *) xMalloc( Int,iMaxPelValue );
    39793787      Int *aiCurrHist   = (Int *) xMalloc( Int,iMaxPelValue );
     
    39813789      memset( aiCurrHist, 0, iMaxPelValue*sizeof(Int) );
    39823790
    3983       Int iWidth   = pcCurrPicYuv->getWidth();
    3984       Int iHeight  = pcCurrPicYuv->getHeight();
    3985 
    3986       Pel* pCurrY   = pcCurrPicYuv ->getLumaAddr();
    3987       Pel* pRefOrgY = pcRefPicYuvOrg  ->getLumaAddr();
    3988       Int iCurrStride = pcCurrPicYuv->getStride();
    3989       Int iRefStride = pcRefPicYuvOrg->getStride();
    3990 
     3791      Int iWidth   = pcCurrPicYuv->getWidth(COMPONENT_Y);
     3792      Int iHeight  = pcCurrPicYuv->getHeight(COMPONENT_Y);
     3793      Pel* pCurrY   = pcCurrPicYuv->getAddr(COMPONENT_Y);
     3794      Pel* pRefOrgY = pcRefPicYuvOrg->getAddr(COMPONENT_Y);
     3795      Int iCurrStride = pcCurrPicYuv->getStride(COMPONENT_Y);
     3796      Int iRefStride = pcRefPicYuvOrg->getStride(COMPONENT_Y);
    39913797      for ( Int y = 0; y < iHeight; y++ )
    39923798      {
     
    40253831}
    40263832#endif
    4027 #if H_3D
     3833#if NH_3D
    40283834Void TComSlice::setIvPicLists( TComPicLists* m_ivPicLists )
    40293835{
     
    40423848  setupLUT = setupLUT || getViewSynthesisPredFlag( );
    40433849
    4044 #if H_3D_NBDV_REF
     3850#if NH_3D_NBDV_REF
    40453851  setupLUT = setupLUT || getDepthRefinementFlag( );
    40463852#endif 
    40473853
    4048 #if H_3D_IV_MERGE
     3854#if NH_3D_IV_MERGE
    40493855  setupLUT = setupLUT || ( getIvMvPredFlag() && getIsDepth() );
    40503856#endif
    40513857
     3858  Int bitDepthY = getSPS()->getBitDepth(CHANNEL_TYPE_LUMA);
    40523859
    40533860  if( !setupLUT )
     3861  {
    40543862    return;
     3863  }
    40553864
    40563865  m_numViews = getVPS()->getNumViews();
     
    40613870    for ( Int i = 0; i < getVPS()->getNumViews(); i++ )
    40623871    {
    4063       m_depthToDisparityB[ i ] = new Int[ Int(1 << g_bitDepthY) ];
     3872      m_depthToDisparityB[ i ] = new Int[ Int(1 << bitDepthY) ];
    40643873    }
    40653874  }
     
    40713880    for ( Int i = 0; i < m_numViews; i++ )
    40723881    {
    4073       m_depthToDisparityF[ i ] = new Int[ Int(1 << g_bitDepthY) ];
     3882      m_depthToDisparityF[ i ] = new Int[ Int(1 << bitDepthY) ];
    40743883    }
    40753884  }
     
    40783887  assert( m_depthToDisparityF != NULL );
    40793888
    4080   TComVPS* vps = getVPS();
    4081 
    4082   Int log2Div = g_bitDepthY - 1 + vps->getCpPrecision();
     3889  const TComVPS* vps = getVPS();
     3890
     3891  Int log2Div = bitDepthY - 1 + vps->getCpPrecision();
    40833892  Int voiInVps = vps->getVoiInVps( getViewIndex() );
    40843893  Bool camParaSH = vps->getCpInSliceSegmentHeaderFlag( voiInVps ); 
    40853894
    4086   Int* codScale     = camParaSH ? m_aaiCodedScale [ 0 ] : vps->getCodedScale    ( voiInVps );
    4087   Int* codOffset    = camParaSH ? m_aaiCodedOffset[ 0 ] : vps->getCodedOffset   ( voiInVps );
    4088   Int* invCodScale  = camParaSH ? m_aaiCodedScale [ 1 ] : vps->getInvCodedScale ( voiInVps );
    4089   Int* invCodOffset = camParaSH ? m_aaiCodedOffset[ 1 ] : vps->getInvCodedOffset( voiInVps );
     3895  const IntAry1d codScale     = camParaSH ? m_aaiCodedScale [ 0 ] : vps->getCodedScale    ( voiInVps );
     3896  const IntAry1d codOffset    = camParaSH ? m_aaiCodedOffset[ 0 ] : vps->getCodedOffset   ( voiInVps );
     3897  const IntAry1d invCodScale  = camParaSH ? m_aaiCodedScale [ 1 ] : vps->getInvCodedScale ( voiInVps );
     3898  const IntAry1d invCodOffset = camParaSH ? m_aaiCodedOffset[ 1 ] : vps->getInvCodedOffset( voiInVps );
    40903899
    40913900
     
    40963905    if ( g_traceCameraParameters )
    40973906    {
    4098       std::cout << std::endl << "Cp: " << codScale   [ iInVoi ] << " " <<    codOffset[ iInVoi ] << " "
    4099                 << invCodScale[ iInVoi ] << " " << invCodOffset[ iInVoi ] << " " << log2Div;
    4100     }
    4101 #endif
    4102     for ( Int d = 0; d <= ( ( 1 << g_bitDepthY ) - 1 ); d++ )
     3907      std::cout << "Cp: " << codScale   [ iInVoi ] << " " <<    codOffset[ iInVoi ] << " "
     3908                << invCodScale[ iInVoi ] << " " << invCodOffset[ iInVoi ] << " " << log2Div << std::endl ;
     3909    }
     3910#endif
     3911    for ( Int d = 0; d <= ( ( 1 << bitDepthY ) - 1 ); d++ )
    41033912    {     
    4104       Int offset =    ( codOffset  [ iInVoi ] << g_bitDepthY ) + ( ( 1 << log2Div ) >> 1 );         
     3913      Int offset =    ( codOffset  [ iInVoi ] << bitDepthY ) + ( ( 1 << log2Div ) >> 1 );         
    41053914      m_depthToDisparityB[ iInVoi ][ d ] = ( codScale [ iInVoi ] * d + offset ) >> log2Div;
    41063915
    4107       Int invOffset = ( invCodOffset[ iInVoi ] << g_bitDepthY ) + ( ( 1 << log2Div ) >> 1 );         
     3916      Int invOffset = ( invCodOffset[ iInVoi ] << bitDepthY ) + ( ( 1 << log2Div ) >> 1 );         
    41083917      m_depthToDisparityF[ iInVoi ][ d ] = ( invCodScale[ iInVoi ] * d + invOffset ) >> log2Div;
    41093918    }
     
    41143923
    41153924
    4116 #if H_MV
    4117 Void TComSlice::checkCrossLayerBlaFlag()
     3925#if NH_MV
     3926Void TComSlice::checkCrossLayerBlaFlag() const
    41183927{
    41193928  // cross_layer_bla_flag shall be equal to 0 for pictures with nal_unit_type not equal to IDR_W_RADL or IDR_N_LP or with nuh_layer_id not equal to 0.
     
    41473956
    41483957
    4149 #if H_3D
     3958#if NH_3D
    41503959Void TComSlice::init3dToolParameters()
    41513960{
     
    41543963  Bool nRLLG0 =  ( getVPS()->getNumRefListLayers( getLayerId() ) > 0 );     
    41553964
    4156   TComSps3dExtension* sps3dExt = getSPS()->getSps3dExtension();
     3965  const TComSps3dExtension* sps3dExt = getSPS()->getSps3dExtension();
    41573966
    41583967  m_ivMvPredFlag           = sps3dExt->getIvMvPredFlag         ( depthFlag ) && nRLLG0                       ;                             
     
    41974006}
    41984007
    4199 Void TComSlice::deriveInCmpPredAndCpAvailFlag()
     4008Void TComSlice::deriveInCmpPredAndCpAvailFlag( )
    42004009{
    42014010  Int numCurCmpLIds = getIsDepth() ? 1 : getNumActiveRefLayerPics();
     
    42484057  else
    42494058  {
    4250     TComSps3dExtension* sps3dExt = getSPS()->getSps3dExtension();
     4059    const TComSps3dExtension* sps3dExt = getSPS()->getSps3dExtension();
    42514060    if( !getIsDepth() )
    42524061    {
     
    42804089#endif
    42814090
    4282 
    42834091/** get scaling matrix from RefMatrixID
    4284  * \param sizeId size index
    4285  * \param Index of input matrix
    4286  * \param Index of reference matrix
     4092 * \param sizeId    size index
     4093 * \param listId    index of input matrix
     4094 * \param refListId index of reference matrix
    42874095 */
    42884096Void TComScalingList::processRefMatrix( UInt sizeId, UInt listId , UInt refListId )
     
    42914099}
    42924100
    4293 /** parse syntax infomation
    4294  *  \param pchFile syntax infomation
    4295  *  \returns false if successful
    4296  */
     4101Void TComScalingList::checkPredMode(UInt sizeId, UInt listId)
     4102{
     4103  Int predListStep = (sizeId == SCALING_LIST_32x32? (SCALING_LIST_NUM/NUMBER_OF_PREDICTION_MODES) : 1); // if 32x32, skip over chroma entries.
     4104
     4105  for(Int predListIdx = (Int)listId ; predListIdx >= 0; predListIdx-=predListStep)
     4106  {
     4107    if( !memcmp(getScalingListAddress(sizeId,listId),((listId == predListIdx) ?
     4108      getScalingListDefaultAddress(sizeId, predListIdx): getScalingListAddress(sizeId, predListIdx)),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])) // check value of matrix
     4109     && ((sizeId < SCALING_LIST_16x16) || (getScalingListDC(sizeId,listId) == getScalingListDC(sizeId,predListIdx)))) // check DC value
     4110    {
     4111      setRefMatrixId(sizeId, listId, predListIdx);
     4112      setScalingListPredModeFlag(sizeId, listId, false);
     4113      return;
     4114    }
     4115  }
     4116  setScalingListPredModeFlag(sizeId, listId, true);
     4117}
     4118
     4119static Void outputScalingListHelp(std::ostream &os)
     4120{
     4121  os << "The scaling list file specifies all matrices and their DC values; none can be missing,\n"
     4122         "but their order is arbitrary.\n\n"
     4123         "The matrices are specified by:\n"
     4124         "<matrix name><unchecked data>\n"
     4125         "  <value>,<value>,<value>,....\n\n"
     4126         "  Line-feeds can be added arbitrarily between values, and the number of values needs to be\n"
     4127         "  at least the number of entries for the matrix (superfluous entries are ignored).\n"
     4128         "  The <unchecked data> is text on the same line as the matrix that is not checked\n"
     4129         "  except to ensure that the matrix name token is unique. It is recommended that it is ' ='\n"
     4130         "  The values in the matrices are the absolute values (0-255), not the delta values as\n"
     4131         "  exchanged between the encoder and decoder\n\n"
     4132         "The DC values (for matrix sizes larger than 8x8) are specified by:\n"
     4133         "<matrix name>_DC<unchecked data>\n"
     4134         "  <value>\n";
     4135
     4136  os << "The permitted matrix names are:\n";
     4137  for(UInt sizeIdc = 0; sizeIdc < SCALING_LIST_SIZE_NUM; sizeIdc++)
     4138  {
     4139    for(UInt listIdc = 0; listIdc < SCALING_LIST_NUM; listIdc++)
     4140    {
     4141      if ((sizeIdc!=SCALING_LIST_32x32) || (listIdc%(SCALING_LIST_NUM/NUMBER_OF_PREDICTION_MODES) == 0))
     4142      {
     4143        os << "  " << MatrixType[sizeIdc][listIdc] << '\n';
     4144      }
     4145    }
     4146  }
     4147}
     4148
     4149Void TComScalingList::outputScalingLists(std::ostream &os) const
     4150{
     4151  for(UInt sizeIdc = 0; sizeIdc < SCALING_LIST_SIZE_NUM; sizeIdc++)
     4152  {
     4153    const UInt size = min(8,4<<(sizeIdc));
     4154    for(UInt listIdc = 0; listIdc < SCALING_LIST_NUM; listIdc++)
     4155    {
     4156      if ((sizeIdc!=SCALING_LIST_32x32) || (listIdc%(SCALING_LIST_NUM/NUMBER_OF_PREDICTION_MODES) == 0))
     4157      {
     4158        const Int *src = getScalingListAddress(sizeIdc, listIdc);
     4159        os << (MatrixType[sizeIdc][listIdc]) << " =\n  ";
     4160        for(UInt y=0; y<size; y++)
     4161        {
     4162          for(UInt x=0; x<size; x++, src++)
     4163          {
     4164            os << std::setw(3) << (*src) << ", ";
     4165          }
     4166          os << (y+1<size?"\n  ":"\n");
     4167        }
     4168        if(sizeIdc > SCALING_LIST_8x8)
     4169        {
     4170          os << MatrixType_DC[sizeIdc][listIdc] << " = \n  " << std::setw(3) << getScalingListDC(sizeIdc, listIdc) << "\n";
     4171        }
     4172        os << "\n";
     4173      }
     4174    }
     4175  }
     4176}
     4177
    42974178Bool TComScalingList::xParseScalingList(Char* pchFile)
    42984179{
    4299   FILE *fp;
    4300   Char line[1024];
    4301   UInt sizeIdc,listIdc;
    4302   UInt i,size = 0;
    4303   Int *src=0,data;
    4304   Char *ret;
    4305   UInt  retval;
    4306 
    4307   if((fp = fopen(pchFile,"r")) == (FILE*)NULL)
    4308   {
    4309     printf("can't open file %s :: set Default Matrix\n",pchFile);
     4180  static const Int LINE_SIZE=1024;
     4181  FILE *fp = NULL;
     4182  Char line[LINE_SIZE];
     4183
     4184  if (pchFile == NULL)
     4185  {
     4186    fprintf(stderr, "Error: no scaling list file specified. Help on scaling lists being output\n");
     4187    outputScalingListHelp(std::cout);
     4188    std::cout << "\n\nExample scaling list file using default values:\n\n";
     4189    outputScalingLists(std::cout);
     4190    exit (1);
    43104191    return true;
    43114192  }
    4312 
    4313   for(sizeIdc = 0; sizeIdc < SCALING_LIST_SIZE_NUM; sizeIdc++)
    4314   {
    4315     size = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeIdc]);
    4316     for(listIdc = 0; listIdc < g_scalingListNum[sizeIdc]; listIdc++)
    4317     {
    4318       src = getScalingListAddress(sizeIdc, listIdc);
    4319 
    4320       fseek(fp,0,0);
    4321       do
    4322       {
    4323         ret = fgets(line, 1024, fp);
    4324         if ((ret==NULL)||(strstr(line, MatrixType[sizeIdc][listIdc])==NULL && feof(fp)))
    4325         {
    4326           printf("Error: can't read Matrix :: set Default Matrix\n");
    4327           return true;
    4328         }
    4329       }
    4330       while (strstr(line, MatrixType[sizeIdc][listIdc]) == NULL);
    4331       for (i=0; i<size; i++)
    4332       {
    4333         retval = fscanf(fp, "%d,", &data);
    4334         if (retval!=1)
    4335         {
    4336           printf("Error: can't read Matrix :: set Default Matrix\n");
    4337           return true;
    4338         }
    4339         src[i] = data;
    4340       }
    4341       //set DC value for default matrix check
    4342       setScalingListDC(sizeIdc,listIdc,src[0]);
    4343 
    4344       if(sizeIdc > SCALING_LIST_8x8)
    4345       {
    4346         fseek(fp,0,0);
    4347         do
    4348         {
    4349           ret = fgets(line, 1024, fp);
    4350           if ((ret==NULL)||(strstr(line, MatrixType_DC[sizeIdc][listIdc])==NULL && feof(fp)))
     4193  else if ((fp = fopen(pchFile,"r")) == (FILE*)NULL)
     4194  {
     4195    fprintf(stderr, "Error: cannot open scaling list file %s for reading\n",pchFile);
     4196    return true;
     4197  }
     4198
     4199  for(UInt sizeIdc = 0; sizeIdc < SCALING_LIST_SIZE_NUM; sizeIdc++)
     4200  {
     4201    const UInt size = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeIdc]);
     4202
     4203    for(UInt listIdc = 0; listIdc < SCALING_LIST_NUM; listIdc++)
     4204    {
     4205      Int * const src = getScalingListAddress(sizeIdc, listIdc);
     4206
     4207      if ((sizeIdc==SCALING_LIST_32x32) && (listIdc%(SCALING_LIST_NUM/NUMBER_OF_PREDICTION_MODES) != 0)) // derive chroma32x32 from chroma16x16
     4208      {
     4209        const Int *srcNextSmallerSize = getScalingListAddress(sizeIdc-1, listIdc);
     4210        for(UInt i=0; i<size; i++)
     4211        {
     4212          src[i] = srcNextSmallerSize[i];
     4213        }
     4214        setScalingListDC(sizeIdc,listIdc,(sizeIdc > SCALING_LIST_8x8) ? getScalingListDC(sizeIdc-1, listIdc) : src[0]);
     4215      }
     4216      else
     4217      {
     4218        {
     4219          fseek(fp, 0, SEEK_SET);
     4220          Bool bFound=false;
     4221          while ((!feof(fp)) && (!bFound))
    43514222          {
    4352             printf("Error: can't read DC :: set Default Matrix\n");
     4223            Char *ret = fgets(line, LINE_SIZE, fp);
     4224            Char *findNamePosition= ret==NULL ? NULL : strstr(line, MatrixType[sizeIdc][listIdc]);
     4225            // This could be a match against the DC string as well, so verify it isn't
     4226            if (findNamePosition!= NULL && (MatrixType_DC[sizeIdc][listIdc]==NULL || strstr(line, MatrixType_DC[sizeIdc][listIdc])==NULL))
     4227            {
     4228              bFound=true;
     4229            }
     4230          }
     4231          if (!bFound)
     4232          {
     4233            fprintf(stderr, "Error: cannot find Matrix %s from scaling list file %s\n", MatrixType[sizeIdc][listIdc], pchFile);
    43534234            return true;
    43544235          }
    43554236        }
    4356         while (strstr(line, MatrixType_DC[sizeIdc][listIdc]) == NULL);
    4357         retval = fscanf(fp, "%d,", &data);
    4358         if (retval!=1)
    4359         {
    4360           printf("Error: can't read Matrix :: set Default Matrix\n");
    4361           return true;
    4362         }
    4363         //overwrite DC value when size of matrix is larger than 16x16
    4364         setScalingListDC(sizeIdc,listIdc,data);
    4365       }
    4366     }
    4367   }
     4237        for (UInt i=0; i<size; i++)
     4238        {
     4239          Int data;
     4240          if (fscanf(fp, "%d,", &data)!=1)
     4241          {
     4242            fprintf(stderr, "Error: cannot read value #%d for Matrix %s from scaling list file %s at file position %ld\n", i, MatrixType[sizeIdc][listIdc], pchFile, ftell(fp));
     4243            return true;
     4244          }
     4245          if (data<0 || data>255)
     4246          {
     4247            fprintf(stderr, "Error: QMatrix entry #%d of value %d for Matrix %s from scaling list file %s at file position %ld is out of range (0 to 255)\n", i, data, MatrixType[sizeIdc][listIdc], pchFile, ftell(fp));
     4248            return true;
     4249          }
     4250          src[i] = data;
     4251        }
     4252
     4253        //set DC value for default matrix check
     4254        setScalingListDC(sizeIdc,listIdc,src[0]);
     4255
     4256        if(sizeIdc > SCALING_LIST_8x8)
     4257        {
     4258          {
     4259            fseek(fp, 0, SEEK_SET);
     4260            Bool bFound=false;
     4261            while ((!feof(fp)) && (!bFound))
     4262            {
     4263              Char *ret = fgets(line, LINE_SIZE, fp);
     4264              Char *findNamePosition= ret==NULL ? NULL : strstr(line, MatrixType_DC[sizeIdc][listIdc]);
     4265              if (findNamePosition!= NULL)
     4266              {
     4267                // This won't be a match against the non-DC string.
     4268                bFound=true;
     4269              }
     4270            }
     4271            if (!bFound)
     4272            {
     4273              fprintf(stderr, "Error: cannot find DC Matrix %s from scaling list file %s\n", MatrixType_DC[sizeIdc][listIdc], pchFile);
     4274              return true;
     4275            }
     4276          }
     4277          Int data;
     4278          if (fscanf(fp, "%d,", &data)!=1)
     4279          {
     4280            fprintf(stderr, "Error: cannot read DC %s from scaling list file %s at file position %ld\n", MatrixType_DC[sizeIdc][listIdc], pchFile, ftell(fp));
     4281            return true;
     4282          }
     4283          if (data<0 || data>255)
     4284          {
     4285            fprintf(stderr, "Error: DC value %d for Matrix %s from scaling list file %s at file position %ld is out of range (0 to 255)\n", data, MatrixType[sizeIdc][listIdc], pchFile, ftell(fp));
     4286            return true;
     4287          }
     4288          //overwrite DC value when size of matrix is larger than 16x16
     4289          setScalingListDC(sizeIdc,listIdc,data);
     4290        }
     4291      }
     4292    }
     4293  }
     4294//  std::cout << "\n\nRead scaling lists of:\n\n";
     4295//  outputScalingLists(std::cout);
     4296
    43684297  fclose(fp);
    43694298  return false;
    43704299}
    43714300
    4372 #if H_MV
    4373 Void TComScalingList::inferFrom( TComScalingList* srcScLi )
     4301#if NH_MV
     4302Void TComScalingList::inferFrom( const TComScalingList& srcScLi )
    43744303{
    43754304  for(Int sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
    43764305  {
    4377     for(Int listId = 0; listId <  g_scalingListNum[sizeId]; listId++)
    4378     {
    4379       setRefMatrixId  (sizeId,listId, srcScLi->getRefMatrixId  (sizeId,listId));
    4380       setScalingListDC(sizeId,listId, srcScLi->getScalingListDC(sizeId,listId));         
    4381       ::memcpy(getScalingListAddress(sizeId, listId),srcScLi->getScalingListAddress(sizeId, listId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]));
    4382     }
    4383   }
    4384 }
    4385 #endif
    4386 /** initialization process of quantization matrix array
    4387  */
    4388 Void TComScalingList::init()
    4389 {
    4390   for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
    4391   {
    4392     for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++)
    4393     {
    4394       m_scalingListCoef[sizeId][listId] = new Int [min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])];
    4395     }
    4396   }
    4397   m_scalingListCoef[SCALING_LIST_32x32][3] = m_scalingListCoef[SCALING_LIST_32x32][1]; // copy address for 32x32
    4398 }
    4399 
    4400 /** destroy quantization matrix array
    4401  */
    4402 Void TComScalingList::destroy()
    4403 {
    4404   for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
    4405   {
    4406     for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++)
    4407     {
    4408       if(m_scalingListCoef[sizeId][listId]) delete [] m_scalingListCoef[sizeId][listId];
    4409     }
    4410   }
    4411 }
    4412 
    4413 /** get default address of quantization matrix
     4306    for(Int listId = 0; listId <  SCALING_LIST_NUM; listId++)
     4307    {
     4308      setRefMatrixId  (sizeId,listId, srcScLi.getRefMatrixId  (sizeId,listId));
     4309      setScalingListDC(sizeId,listId, srcScLi.getScalingListDC(sizeId,listId));         
     4310      ::memcpy(getScalingListAddress(sizeId, listId),srcScLi.getScalingListAddress(sizeId, listId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]));
     4311    }
     4312  }
     4313}
     4314#endif
     4315
     4316
     4317/** get default address of quantization matrix
    44144318 * \param sizeId size index
    44154319 * \param listId list index
    44164320 * \returns pointer of quantization matrix
    44174321 */
    4418 Int* TComScalingList::getScalingListDefaultAddress(UInt sizeId, UInt listId)
    4419 {
    4420   Int *src = 0;
     4322const Int* TComScalingList::getScalingListDefaultAddress(UInt sizeId, UInt listId)
     4323{
     4324  const Int *src = 0;
    44214325  switch(sizeId)
    44224326  {
     
    44254329      break;
    44264330    case SCALING_LIST_8x8:
    4427       src = (listId<3) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8;
    4428       break;
    44294331    case SCALING_LIST_16x16:
    4430       src = (listId<3) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8;
    4431       break;
    44324332    case SCALING_LIST_32x32:
    4433       src = (listId<1) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8;
     4333      src = (listId < (SCALING_LIST_NUM/NUMBER_OF_PREDICTION_MODES) ) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8;
    44344334      break;
    44354335    default:
     
    44434343/** process of default matrix
    44444344 * \param sizeId size index
    4445  * \param Index of input matrix
     4345 * \param listId index of input matrix
    44464346 */
    44474347Void TComScalingList::processDefaultMatrix(UInt sizeId, UInt listId)
     
    44574357  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
    44584358  {
    4459     for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++)
     4359    for(UInt listId = 0; listId < SCALING_LIST_NUM; listId++)
    44604360    {
    44614361      //check default matrix?
     
    44734373, m_ppsMap(MAX_NUM_PPS)
    44744374, m_activeVPSId(-1)
    4475 #if !H_MV
     4375#if !NH_MV
    44764376, m_activeSPSId(-1)
    4477 , m_activePPSId(-1)
    4478 {
    4479 #else
    4480 {
     4377#endif
     4378{
     4379#if NH_MV 
    44814380  for (Int i = 0; i < MAX_NUM_LAYERS; i++ )
    4482   {
    4483     m_activeSPSId[ i ] = -1;
    4484     m_activePPSId[ i ] = -1;
     4381  {   
     4382    m_activeSPSId[i] = -1;
    44854383  }
    44864384#endif
     
    44944392//! activate a SPS from a active parameter sets SEI message
    44954393//! \returns true, if activation is successful
    4496 #if H_MV
    4497 Bool ParameterSetManager::activateSPSWithSEI(Int spsId, Int layerId )
     4394#if NH_MV
     4395//Bool ParameterSetManager::activateSPSWithSEI(Int spsId, Int layerId )
    44984396#else
    4499 Bool ParameterSetManager::activateSPSWithSEI(Int spsId)
    4500 #endif
    4501 {
    4502   TComSPS *sps = m_spsMap.getPS(spsId);
    4503   if (sps)
    4504   {
    4505     Int vpsId = sps->getVPSId();
    4506     if (m_vpsMap.getPS(vpsId))
    4507     {
    4508       m_activeVPSId = vpsId;
    4509 #if H_MV
    4510       m_activeSPSId[ layerId ] = spsId;
     4397//Bool ParameterSetManager::activateSPSWithSEI(Int spsId)
     4398#endif
     4399//{
     4400//TComSPS *sps = m_spsMap.getPS(spsId);
     4401//  if (sps)
     4402//  {
     4403//    Int vpsId = sps->getVPSId();
     4404//    TComVPS *vps = m_vpsMap.getPS(vpsId);
     4405//    if (vps)
     4406//    {
     4407#if NH_MV
     4408//      m_activeVPS = *(vps);
     4409//      m_activeSPS[ layerId ] = *(sps);
    45114410#else
    4512       m_activeSPSId = spsId;
    4513 #endif
    4514       return true;
    4515     }
    4516     else
    4517     {
    4518       printf("Warning: tried to activate SPS using an Active parameter sets SEI message. Referenced VPS does not exist.");
    4519     }
    4520   }
    4521   else
    4522   {
    4523     printf("Warning: tried to activate non-existing SPS using an Active parameter sets SEI message.");
    4524   }
    4525   return false;
    4526 }
     4411//      m_activeVPS = *(vps);
     4412//      m_activeSPS = *(sps);
     4413#endif
     4414//      return true;
     4415//    }
     4416//    else
     4417//    {
     4418//      printf("Warning: tried to activate SPS using an Active parameter sets SEI message. Referenced VPS does not exist.");
     4419//    }
     4420//  }
     4421//  else
     4422//  {
     4423//    printf("Warning: tried to activate non-existing SPS using an Active parameter sets SEI message.");
     4424//  }
     4425//  return false;
     4426//}
    45274427
    45284428//! activate a PPS and depending on isIDR parameter also SPS and VPS
    45294429//! \returns true, if activation is successful
    4530 #if H_MV
     4430#if NH_MV
    45314431Bool ParameterSetManager::activatePPS(Int ppsId, Bool isIRAP, Int layerId )
    45324432#else
     
    45384438  {
    45394439    Int spsId = pps->getSPSId();
    4540 #if H_MV
    4541     if (!isIRAP && (spsId != m_activeSPSId[ layerId ]))
     4440#if NH_MV
     4441    if (!isIRAP && (spsId != m_activeSPSId[ layerId ] ))
    45424442#else
    4543     if (!isIRAP && (spsId != m_activeSPSId))
    4544 #endif
    4545     {
    4546       printf("Warning: tried to activate PPS referring to a inactive SPS at non-IRAP.");
    4547       return false;
    4548     }
    4549 
    4550     TComSPS *sps = m_spsMap.getPS(spsId);
    4551     if (sps)
    4552     {
    4553       Int vpsId = sps->getVPSId();
    4554       if (!isIRAP && (vpsId != m_activeVPSId))
    4555       {
    4556         printf("Warning: tried to activate PPS referring to a inactive VPS at non-IRAP.");
    4557         return false;
    4558       }
    4559       if (m_vpsMap.getPS(vpsId))
    4560       {
    4561 #if H_MV
    4562         m_activePPSId[ layerId ] = ppsId;
    4563         m_activeVPSId = vpsId;
    4564         m_activeSPSId[ layerId ] = spsId;
     4443    if (!isIRAP && (spsId != m_activeSPSId ))
     4444#endif
     4445    {
     4446      printf("Warning: tried to activate PPS referring to a inactive SPS at non-IDR.");
     4447    }
     4448    else
     4449    {
     4450      TComSPS *sps = m_spsMap.getPS(spsId);
     4451      if (sps)
     4452      {
     4453        Int vpsId = sps->getVPSId();
     4454        if (!isIRAP && (vpsId != m_activeVPSId ))
     4455        {
     4456          printf("Warning: tried to activate PPS referring to a inactive VPS at non-IDR.");
     4457        }
     4458        else
     4459        {
     4460          TComVPS *vps =m_vpsMap.getPS(vpsId);
     4461          if (vps)
     4462          {
     4463            m_activeVPSId = vpsId;
     4464#if NH_MV
     4465            m_activeSPSId[layerId] = spsId;
    45654466#else
    4566         m_activePPSId = ppsId;
    4567         m_activeVPSId = vpsId;
    4568         m_activeSPSId = spsId;
    4569 #endif
    4570         return true;
     4467            m_activeSPSId = spsId;
     4468#endif
     4469            return true;
     4470          }
     4471          else
     4472          {
     4473            printf("Warning: tried to activate PPS that refers to a non-existing VPS.");
     4474          }
     4475        }
    45714476      }
    45724477      else
    45734478      {
    4574         printf("Warning: tried to activate PPS that refers to a non-existing VPS.");
    4575       }
    4576     }
    4577     else
    4578     {
    4579       printf("Warning: tried to activate a PPS that refers to a non-existing SPS.");
     4479       printf("Warning: tried to activate a PPS that refers to a non-existing SPS.");
     4480      }
    45804481    }
    45814482  }
     
    45844485    printf("Warning: tried to activate non-existing PPS.");
    45854486  }
     4487
     4488  // Failed to activate if reach here.
     4489#if NH_MV
     4490  m_activeSPSId[layerId]=-1;
     4491#else
     4492  m_activeSPSId=-1;
     4493#endif
     4494  m_activeVPSId=-1;
     4495
    45864496  return false;
    45874497}
     
    45894499ProfileTierLevel::ProfileTierLevel()
    45904500  : m_profileSpace    (0)
    4591   , m_tierFlag        (false)
    4592   , m_profileIdc      (0)
    4593   , m_levelIdc        (0)
    4594 , m_progressiveSourceFlag  (false)
    4595 , m_interlacedSourceFlag   (false)
    4596 , m_nonPackedConstraintFlag(false)
    4597 , m_frameOnlyConstraintFlag(false)
    4598 #if H_MV
     4501  , m_tierFlag        (Level::MAIN)
     4502  , m_profileIdc      (Profile::NONE)
     4503  , m_levelIdc        (Level::NONE)
     4504  , m_progressiveSourceFlag  (false)
     4505  , m_interlacedSourceFlag   (false)
     4506  , m_nonPackedConstraintFlag(false)
     4507  , m_frameOnlyConstraintFlag(false)
     4508#if NH_MV
     4509  , m_intraConstraintFlag         ( false )
     4510  , m_onePictureOnlyConstraintFlag( false )
     4511  , m_lowerBitRateConstraintFlag  ( false )
    45994512  , m_max12bitConstraintFlag      ( false )
    46004513  , m_max10bitConstraintFlag      ( false )
     
    46024515  , m_max422chromaConstraintFlag  ( false )
    46034516  , m_max420chromaConstraintFlag  ( false )
    4604   , m_maxMonochromeConstraintFlag ( false )
    4605   , m_intraConstraintFlag         ( false )
    4606   , m_onePictureOnlyConstraintFlag( false )
    4607   , m_lowerBitRateConstraintFlag  ( false )
     4517  , m_maxMonochromeConstraintFlag ( false ) 
    46084518  , m_inbldFlag                   ( false )
    46094519#endif
     
    46124522}
    46134523
    4614 #if H_MV
    4615 Bool ProfileTierLevel::getV2ConstraintsPresentFlag()
     4524#if NH_MV
     4525Bool ProfileTierLevel::getV2ConstraintsPresentFlag() const
    46164526{
    46174527  return (
     
    46214531}
    46224532
    4623 Bool ProfileTierLevel::getInbldPresentFlag()
     4533Bool ProfileTierLevel::getInbldPresentFlag() const
    46244534{
    46254535  return (
     
    46654575}
    46664576
    4667 #if H_MV
     4577Void calculateParameterSetChangedFlag(Bool &bChanged, const std::vector<UChar> *pOldData, const std::vector<UChar> &newData)
     4578{
     4579  if (!bChanged)
     4580  {
     4581    if ((pOldData==0 && pOldData!=0) || (pOldData!=0 && pOldData==0))
     4582    {
     4583      bChanged=true;
     4584    }
     4585    else if (pOldData!=0 && pOldData!=0)
     4586    {
     4587      // compare the two
     4588      if (pOldData->size() != pOldData->size())
     4589      {
     4590        bChanged=true;
     4591      }
     4592      else
     4593      {
     4594        const UChar *pNewDataArray=&(newData)[0];
     4595        const UChar *pOldDataArray=&(*pOldData)[0];
     4596        if (memcmp(pOldDataArray, pNewDataArray, pOldData->size()))
     4597        {
     4598          bChanged=true;
     4599        }
     4600      }
     4601    }
     4602  }
     4603}
     4604#if NH_MV
    46684605Void TComPTL::inferGeneralValues(Bool profilePresentFlag, Int k, TComPTL* refPTL)
    46694606{
     
    47544691
    47554692#endif
     4693
    47564694//! \}
    47574695
    4758 #if H_MV
    4759 TComVPSVUI::TComVPSVUI()
     4696#if NH_MV
     4697Void TComVPSVUI::init( Int numLayerSets, Int maxNumSubLayers, Int maxNumLayers )
    47604698{
    47614699  m_crossLayerIrapAlignedFlag = true;
    47624700  m_allLayersIdrAlignedFlag   = false;
    4763   m_bitRatePresentVpsFlag = false;
    4764   m_picRatePresentVpsFlag = false;
    4765   for ( Int i = 0; i < MAX_VPS_OP_SETS_PLUS1; i++)
    4766   {   
    4767     for ( Int j = 0; j < MAX_TLAYER; j++)
     4701  m_bitRatePresentVpsFlag     = false;
     4702  m_picRatePresentVpsFlag     = false;
     4703
     4704  m_bitRatePresentFlag          .resize(numLayerSets);
     4705  m_picRatePresentFlag          .resize(numLayerSets);
     4706  m_avgBitRate                  .resize(numLayerSets);
     4707  m_maxBitRate                  .resize(numLayerSets);
     4708  m_constantPicRateIdc          .resize(numLayerSets);
     4709  m_avgPicRate                  .resize(numLayerSets);
     4710
     4711  for ( Int i = 0; i < numLayerSets; i++)
     4712  {
     4713    m_bitRatePresentFlag          [i].resize( maxNumSubLayers);
     4714    m_picRatePresentFlag          [i].resize( maxNumSubLayers);
     4715    m_avgBitRate                  [i].resize( maxNumSubLayers);
     4716    m_maxBitRate                  [i].resize( maxNumSubLayers);
     4717    m_constantPicRateIdc          [i].resize( maxNumSubLayers);
     4718    m_avgPicRate                  [i].resize( maxNumSubLayers);
     4719    for ( Int j = 0; j < maxNumSubLayers; j++)
    47684720    {   
    47694721      m_bitRatePresentFlag          [i][j] = false;
     
    47784730  m_ilpRestrictedRefLayersFlag = false;
    47794731
    4780   for ( Int i = 0; i < MAX_NUM_LAYERS; i++)
     4732  m_tileBoundariesAlignedFlag             .resize( maxNumLayers );
     4733  m_minSpatialSegmentOffsetPlus1          .resize( maxNumLayers );
     4734  m_ctuBasedOffsetEnabledFlag             .resize( maxNumLayers );
     4735  m_minHorizontalCtuOffsetPlus1           .resize( maxNumLayers );
     4736  m_baseLayerParameterSetCompatibilityFlag.resize( maxNumLayers );
     4737
     4738  for ( Int i = 0; i < maxNumLayers; i++)
    47814739  {         
    4782     for ( Int j = 0; j < MAX_NUM_LAYERS; j++)
     4740    m_tileBoundariesAlignedFlag   [i].resize( maxNumLayers );
     4741    m_minSpatialSegmentOffsetPlus1[i].resize( maxNumLayers );
     4742    m_ctuBasedOffsetEnabledFlag   [i].resize( maxNumLayers );
     4743    m_minHorizontalCtuOffsetPlus1 [i].resize( maxNumLayers );
     4744    for ( Int j = 0; j < maxNumLayers; j++)
    47834745    {   
    47844746      m_tileBoundariesAlignedFlag   [i][j] = false;
     
    47894751    m_baseLayerParameterSetCompatibilityFlag[i] = false;
    47904752  }
    4791   for ( Int i = 0; i < MAX_NUM_VIDEO_SIGNAL_INFO; i++ )
    4792   {
    4793     m_videoSignalInfo          [i] = NULL;     
    4794   }
    4795 
    47964753  m_vpsVuiBspHrdPresentFlag = false;
    4797   m_vpsVuiBspHrdParameters  = NULL;
    4798 }
    4799 
    4800 TComVPSVUI::~TComVPSVUI()
    4801 {
    4802   for ( Int i = 0; i < MAX_NUM_VIDEO_SIGNAL_INFO; i++ )
    4803   {
    4804     if (m_videoSignalInfo[ i ] != NULL )      delete m_videoSignalInfo[ i ];   
    4805     m_videoSignalInfo    [ i ] = NULL;
    4806   }
    4807 
    4808   if ( m_vpsVuiBspHrdParameters ) delete m_vpsVuiBspHrdParameters;
    4809   m_vpsVuiBspHrdParameters = NULL;
    4810 }
    4811 
    4812 Void TComVPSVUI::inferVpsVui( Bool encoderFlag )
    4813 {
    4814   // inference of syntax elements that differ from default inference (as done in constructor), when VPS VUI is not present
    4815   if (!encoderFlag )
    4816   {
    4817     setCrossLayerIrapAlignedFlag( false );
    4818   }
    4819   else
    4820   {
    4821     assert( !getCrossLayerIrapAlignedFlag() );
    4822   }
    4823 }
    4824 
    4825 Void TComRepFormat::inferChromaAndBitDepth( TComRepFormat* prevRepFormat, Bool encoderFlag )
    4826 {
    4827   if ( !encoderFlag )
    4828   {
     4754}
     4755
     4756Void TComRepFormat::inferChromaAndBitDepth( const TComRepFormat* prevRepFormat )
     4757{
    48294758    setChromaAndBitDepthVpsPresentFlag( prevRepFormat->getChromaAndBitDepthVpsPresentFlag() );
    48304759    setSeparateColourPlaneVpsFlag     ( prevRepFormat->getSeparateColourPlaneVpsFlag     () );
    48314760    setBitDepthVpsLumaMinus8          ( prevRepFormat->getBitDepthVpsLumaMinus8          () );
    48324761    setBitDepthVpsChromaMinus8        ( prevRepFormat->getBitDepthVpsChromaMinus8        () );
    4833   }
    4834   else
    4835   {
     4762}
     4763
     4764Void TComRepFormat::checkInferChromaAndBitDepth( const TComRepFormat* prevRepFormat ) const
     4765{
    48364766    assert( getChromaAndBitDepthVpsPresentFlag() == prevRepFormat->getChromaAndBitDepthVpsPresentFlag() );
    48374767    assert( getSeparateColourPlaneVpsFlag     () == prevRepFormat->getSeparateColourPlaneVpsFlag     () );
    48384768    assert( getBitDepthVpsLumaMinus8          () == prevRepFormat->getBitDepthVpsLumaMinus8          () );
    48394769    assert( getBitDepthVpsChromaMinus8        () == prevRepFormat->getBitDepthVpsChromaMinus8        () );
    4840   }
    4841 }
    4842 
    4843 
    4844 
    4845 TComVpsVuiBspHrdParameters::~TComVpsVuiBspHrdParameters()
    4846 {
    4847   delete[] m_cprmsAddPresentFlag;
    4848   delete[] m_numSubLayerHrdMinus1;
    4849   delete[] m_hrdParameters;
    4850 
    4851   for (Int h = 0; h < m_numOls; h++)
    4852   {
    4853     if ( h > 0 )
    4854     {   
    4855       for (Int i = 0; i < getNumSignalledPartitioningSchemes(h)+1; i++)
    4856       {
    4857         for (Int t = 0; t < m_vps->getMaxSubLayersInLayerSetMinus1( m_vps->olsIdxToLsIdx(h) ) + 1; t++)
    4858         {       
    4859           for ( Int j = 0; j <= getNumBspSchedulesMinus1(h,i,j);j++ )
    4860           {
    4861             delete[] m_bspHrdIdx  [h][i][t][j];
    4862             delete[] m_bspSchedIdx[h][i][t][j];
    4863           }
    4864         }
    4865         delete[] m_numBspSchedulesMinus1[h][i];
    4866       }
    4867     }
    4868 
    4869     for (Int j = 0; j <= getNumSignalledPartitioningSchemes(h ) + 1; j++ )
    4870     {
    4871       for (Int k = 0; k <= getNumPartitionsInSchemeMinus1(h,j); k++ )
    4872       {
    4873         delete[] m_layerIncludedInPartitionFlag[h][j][k];
    4874       }       
    4875     }
    4876     delete[] m_numPartitionsInSchemeMinus1[h];       
    4877   }
    4878   delete[] m_numSignalledPartitioningSchemes;
    4879 }
    4880 
    4881 
    4882 Int TComVpsVuiBspHrdParameters::getBspHrdIdxLen(TComVPS* vps)
     4770}
     4771
     4772Int TComVpsVuiBspHrdParameters::getBspHrdIdxLen( const TComVPS* vps) const
    48834773{
    48844774  return gCeilLog2( vps->getNumHrdParameters() + getVpsNumAddHrdParams() );
    48854775}
    48864776
    4887 Void TComVpsVuiBspHrdParameters::createAfterVpsNumAddHrdParams( TComVPS* vps )
    4888 {
    4889   assert( vps == NULL );
    4890   m_vps = vps;
     4777Void TComVpsVuiBspHrdParameters::createAfterVpsNumAddHrdParams( const TComVPS* vps )
     4778{
    48914779  m_offsetHrdParamIdx = vps->getNumHrdParameters();
    48924780  m_numHrdParam       = vps->getNumHrdParameters() + getVpsNumAddHrdParams() - m_offsetHrdParamIdx;
    48934781  m_numOls            = vps->getNumOutputLayerSets();
    48944782
    4895   m_cprmsAddPresentFlag   = new Bool    [ m_numHrdParam ];
    4896   m_numSubLayerHrdMinus1  = new Int     [ m_numHrdParam ];
    4897   m_hrdParameters         = new TComHRD [ m_numHrdParam ];
    4898 
    4899   m_numSignalledPartitioningSchemes = new Int    [ m_numOls ];
    4900   m_numPartitionsInSchemeMinus1     = new Int*   [ m_numOls ];
    4901   m_numBspSchedulesMinus1           = new Int**  [ m_numOls ];
    4902   m_bspHrdIdx                       = new Int****[ m_numOls ];
    4903   m_bspSchedIdx                     = new Int****[ m_numOls ];
    4904 }
    4905 
    4906 Void TComVpsVuiBspHrdParameters::createAfterNumSignalledPartitioningSchemes( Int h )
    4907 {
    4908   m_numPartitionsInSchemeMinus1 [h]    = new Int    [ getNumSignalledPartitioningSchemes(h) ];
    4909   m_layerIncludedInPartitionFlag[h]    = new Bool** [ getNumSignalledPartitioningSchemes(h) ];   
    4910 
    4911   m_numBspSchedulesMinus1[h]           = new Int*   [ getNumSignalledPartitioningSchemes(h) + 1 ];
     4783  m_cprmsAddPresentFlag .resize( m_numHrdParam );
     4784  m_numSubLayerHrdMinus1.resize( m_numHrdParam );
     4785  m_hrdParameters       .resize( m_numHrdParam );
     4786
     4787  m_numSignalledPartitioningSchemes .resize( m_numOls );
     4788  m_numPartitionsInSchemeMinus1     .resize( m_numOls );
     4789  m_numBspSchedulesMinus1           .resize( m_numOls );
     4790  m_bspHrdIdx                       .resize( m_numOls );
     4791  m_bspSchedIdx                     .resize( m_numOls );
     4792}
     4793
     4794Void TComVpsVuiBspHrdParameters::createAfterNumSignalledPartitioningSchemes( const TComVPS* vps, Int h )
     4795{
     4796  m_numPartitionsInSchemeMinus1 [h].resize( getNumSignalledPartitioningSchemes(h) );
     4797  m_layerIncludedInPartitionFlag[h].resize( getNumSignalledPartitioningSchemes(h) );   
     4798
     4799  m_numBspSchedulesMinus1       [h].resize( getNumSignalledPartitioningSchemes(h) + 1 );
    49124800  for (Int i = 0; i < getNumSignalledPartitioningSchemes(h) + 1; i++)
    49134801  {
    4914     Int tMax = m_vps->getMaxSubLayersInLayerSetMinus1( m_vps->olsIdxToLsIdx(h) ) + 1;
    4915     m_numBspSchedulesMinus1[h][i] = new Int  [ tMax ];
    4916     m_bspHrdIdx            [h][i] = new Int**[ tMax ];
    4917     m_bspSchedIdx          [h][i] = new Int**[ tMax ];
    4918   }
    4919 }
    4920 
    4921 Void TComVpsVuiBspHrdParameters::createAfterNumPartitionsInSchemeMinus1( Int h, Int j )
    4922 {
    4923   m_layerIncludedInPartitionFlag[h][j] = new Bool*[ getNumPartitionsInSchemeMinus1(h,j)];
     4802    Int tMax = vps->getMaxSubLayersInLayerSetMinus1( m_vps->olsIdxToLsIdx(h) ) + 1;
     4803    m_numBspSchedulesMinus1[h][i].resize( tMax );
     4804    m_bspHrdIdx            [h][i].resize( tMax );
     4805    m_bspSchedIdx          [h][i].resize( tMax );
     4806  }
     4807}
     4808
     4809Void TComVpsVuiBspHrdParameters::createAfterNumPartitionsInSchemeMinus1( const TComVPS* vps, Int h, Int j )
     4810{
     4811  m_layerIncludedInPartitionFlag[h][j].resize( getNumPartitionsInSchemeMinus1(h,j));
    49244812  for( Int k = 0; k < getNumPartitionsInSchemeMinus1(h,j); k++ )
    49254813  {
    4926     m_layerIncludedInPartitionFlag[h][j][k] = new Bool[ m_vps->getNumLayersInIdList( m_vps->olsIdxToLsIdx(h))];
    4927   }
    4928 }
    4929 
    4930 Void TComVpsVuiBspHrdParameters::createAfterNumBspSchedulesMinus1( Int h, Int i, Int t )
    4931 {
    4932   m_bspSchedIdx[h][i][t] = new Int* [ getNumBspSchedulesMinus1( h, i, t ) + 1 ];
    4933   m_bspHrdIdx  [h][i][t] = new Int* [ getNumBspSchedulesMinus1( h, i, t ) + 1 ];
     4814    m_layerIncludedInPartitionFlag[h][j][k].resize( m_vps->getNumLayersInIdList( vps->olsIdxToLsIdx(h)));
     4815  }
     4816}
     4817
     4818Void TComVpsVuiBspHrdParameters::createAfterNumBspSchedulesMinus1( const TComVPS* vps, Int h, Int i, Int t )
     4819{
     4820  m_bspSchedIdx[h][i][t].resize( getNumBspSchedulesMinus1( h, i, t ) + 1 );
     4821  m_bspHrdIdx  [h][i][t].resize( getNumBspSchedulesMinus1( h, i, t ) + 1 );
    49344822  for( Int j = 0; j < getNumBspSchedulesMinus1( h, i, t ) + 1; j++ )
    49354823  {
    4936     m_bspSchedIdx[h][i][t][j] = new Int[ getNumPartitionsInSchemeMinus1( h, i ) ];
    4937     m_bspHrdIdx  [h][i][t][j] = new Int[ getNumPartitionsInSchemeMinus1( h, i ) ];
    4938   }
    4939 }
    4940 
    4941 
    4942 Void TComVUI::inferVideoSignalInfo( TComVPS* vps, Int layerIdCurr )
     4824    m_bspSchedIdx[h][i][t][j].resize( getNumPartitionsInSchemeMinus1( h, i ) );
     4825    m_bspHrdIdx  [h][i][t][j].resize( getNumPartitionsInSchemeMinus1( h, i ) );
     4826  }
     4827}
     4828
     4829
     4830Void TComVUI::inferVideoSignalInfo( const TComVPS* vps, Int layerIdCurr )
    49434831{
    49444832  if ( layerIdCurr == 0 || !vps->getVpsVuiPresentFlag() )
     
    49474835  }
    49484836
    4949   TComVPSVUI* vpsVUI = vps->getVPSVUI();
    4950   assert( vpsVUI != NULL ); 
    4951 
    4952   TComVideoSignalInfo* videoSignalInfo = vpsVUI->getVideoSignalInfo( vpsVUI->getVpsVideoSignalInfoIdx( vps->getLayerIdInVps( layerIdCurr ) ) );
     4837  const TComVPSVUI* vpsVui = vps->getVPSVUI();
     4838  assert( vpsVui != NULL ); 
     4839
     4840  const TComVideoSignalInfo* videoSignalInfo = vpsVui->getVideoSignalInfo( vpsVui->getVpsVideoSignalInfoIdx( vps->getLayerIdInVps( layerIdCurr ) ) );
    49534841  assert( videoSignalInfo != NULL );
    49544842
     
    49604848}
    49614849
    4962 TComDpbSize::TComDpbSize()
    4963 {
    4964   for (Int i = 0; i < MAX_VPS_OUTPUTLAYER_SETS; i++ )
     4850Void TComDpbSize::init( Int numOutputLayerSets, Int maxNumLayerIds, Int maxNumSubLayers ) 
     4851{
     4852  m_subLayerFlagInfoPresentFlag.resize( numOutputLayerSets );
     4853  m_subLayerDpbInfoPresentFlag .resize( numOutputLayerSets );
     4854  m_maxVpsDecPicBufferingMinus1.resize( numOutputLayerSets );
     4855  m_maxVpsNumReorderPics       .resize( numOutputLayerSets );
     4856  m_maxVpsLatencyIncreasePlus1 .resize( numOutputLayerSets );
     4857
     4858  for (Int i = 0; i < numOutputLayerSets; i++ )
    49654859  {     
    49664860    m_subLayerFlagInfoPresentFlag[i]  = false;
    49674861
    4968     for (Int j = 0; j < MAX_TLAYER; j++  )
     4862    m_subLayerDpbInfoPresentFlag [i].resize( maxNumSubLayers );
     4863    m_maxVpsDecPicBufferingMinus1[i].resize( maxNumLayerIds );
     4864    m_maxVpsNumReorderPics       [i].resize( maxNumSubLayers );
     4865    m_maxVpsLatencyIncreasePlus1 [i].resize( maxNumSubLayers );   
     4866
     4867    for (Int j = 0; j < maxNumSubLayers; j++  )
    49694868    {       
    49704869      m_subLayerDpbInfoPresentFlag [i][j] = ( j == 0) ;
    49714870      m_maxVpsNumReorderPics       [i][j] = 0;
    49724871      m_maxVpsLatencyIncreasePlus1 [i][j] = 0;
    4973 
    4974       for (Int k = 0; k < MAX_NUM_LAYER_IDS; k++ )
    4975       {
     4872    }
     4873
     4874    for (Int k = 0; k < maxNumLayerIds; k++ )
     4875    {
     4876      m_maxVpsDecPicBufferingMinus1[i][k].resize( maxNumSubLayers );
     4877      for (Int j = 0; j < maxNumSubLayers; j++  )
     4878      {       
    49764879        m_maxVpsDecPicBufferingMinus1[i][k][j] = MIN_INT;
    49774880      }
     
    49924895}
    49934896#endif
    4994 
Note: See TracChangeset for help on using the changeset viewer.