Changeset 1313 in 3DVCSoftware for trunk/source/Lib/TLibDecoder/TDecCAVLC.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/TLibDecoder/TDecCAVLC.cpp

    r1196 r1313  
    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*
    66* Copyright (c) 2010-2015, ITU/ISO/IEC
     
    3939#include "SEIread.h"
    4040#include "TDecSlice.h"
    41 #if H_3D
     41#include "TLibCommon/TComChromaFormat.h"
     42#if RExt__DECODER_DEBUG_BIT_STATISTICS
     43#include "TLibCommon/TComCodingStatistics.h"
     44#endif
     45#if NH_MV
    4246#include "TDecTop.h"
    4347#endif
     48
    4449//! \ingroup TLibDecoder
    4550//! \{
    4651
    4752#if ENC_DEC_TRACE
    48 
    49 Void  xTraceSPSHeader (TComSPS *pSPS)
    50 {
    51 #if H_MV_ENC_DEC_TRAC
    52   if ( g_disableHLSTrace )
    53   {
    54     return;
    55   }
    56   // To avoid mismatches
    57   fprintf( g_hTrace, "=========== Sequence Parameter Set LayerId: %d ===========\n", pSPS->getLayerId() );
    58 #else
    59   fprintf( g_hTrace, "=========== Sequence Parameter Set ID: %d ===========\n", pSPS->getSPSId() );
    60 #endif
    61 }
    62 
    63 Void  xTracePPSHeader (TComPPS *pPPS)
    64 {
    65 #if H_MV_ENC_DEC_TRAC
    66   if ( g_disableHLSTrace )
    67   {
    68     return;
    69   }
    70   fprintf( g_hTrace, "=========== Picture Parameter Set LayerId: %d ===========\n", pPPS->getLayerId() );
    71 #else
    72   fprintf( g_hTrace, "=========== Picture Parameter Set ID: %d ===========\n", pPPS->getPPSId() );
    73 #endif
    74 }
    75 
    76 Void  xTraceSliceHeader (TComSlice *pSlice)
    77 {
    78 #if H_MV_ENC_DEC_TRAC
    79   if ( g_disableHLSTrace )
    80   {
    81     return;
    82   }
    83 #endif
    84   fprintf( g_hTrace, "=========== Slice ===========\n");
    85 }
    86 
    87 #endif
    88 
     53#if !H_MV_ENC_DEC_TRAC
     54Void  xTraceVPSHeader ()
     55{
     56  fprintf( g_hTrace, "=========== Video Parameter Set     ===========\n" );
     57}
     58
     59Void  xTraceSPSHeader ()
     60{
     61  fprintf( g_hTrace, "=========== Sequence Parameter Set  ===========\n" );
     62}
     63
     64Void  xTracePPSHeader ()
     65{
     66  fprintf( g_hTrace, "=========== Picture Parameter Set  ===========\n");
     67}
     68#endif
     69#endif
    8970// ====================================================================================================================
    9071// Constructor / destructor / create / destroy
     
    9778TDecCavlc::~TDecCavlc()
    9879{
     80
    9981}
    10082
     
    10385// ====================================================================================================================
    10486
    105 void TDecCavlc::parseShortTermRefPicSet( TComSPS* sps, TComReferencePictureSet* rps, Int idx )
     87Void TDecCavlc::parseShortTermRefPicSet( TComSPS* sps, TComReferencePictureSet* rps, Int idx )
    10688{
    10789  UInt code;
     
    11799  }
    118100
    119   if (interRPSPred) 
     101  if (interRPSPred)
    120102  {
    121103    UInt bit;
     
    138120    for(Int j=0 ; j <= rpsRef->getNumberOfPictures(); j++)
    139121    {
    140       READ_CODE(1, bit, "used_by_curr_pic_flag" ); //first bit is "1" if Idc is 1 
     122      READ_CODE(1, bit, "used_by_curr_pic_flag" ); //first bit is "1" if Idc is 1
    141123      Int refIdc = bit;
    142       if (refIdc == 0) 
     124      if (refIdc == 0)
    143125      {
    144126        READ_CODE(1, bit, "use_delta_flag" ); //second bit is "1" if Idc is 2, "0" otherwise.
     
    155137          k0++;
    156138        }
    157         else 
     139        else
    158140        {
    159141          k1++;
    160142        }
    161143        k++;
    162       } 
    163       rps->setRefIdc(j,refIdc); 
    164     }
    165     rps->setNumRefIdc(rpsRef->getNumberOfPictures()+1); 
     144      }
     145      rps->setRefIdc(j,refIdc);
     146    }
     147    rps->setNumRefIdc(rpsRef->getNumberOfPictures()+1);
    166148    rps->setNumberOfPictures(k);
    167149    rps->setNumberOfNegativePictures(k0);
     
    199181}
    200182
    201 #if H_3D
    202 Void TDecCavlc::parsePPS(TComPPS* pcPPS, TComVPS* pcVPS )
     183Void TDecCavlc::parsePPS(TComPPS* pcPPS)
     184{
     185#if ENC_DEC_TRACE
     186#if H_MV_ENC_DEC_TRAC
     187  tracePSHeader( "PPS", pcPPS->getLayerId() );
    203188#else
    204 Void TDecCavlc::parsePPS(TComPPS* pcPPS)
    205 #endif
    206 {
    207 #if ENC_DEC_TRACE 
    208   xTracePPSHeader (pcPPS);
     189  xTracePPSHeader ();
     190#endif
    209191#endif
    210192  UInt  uiCode;
     
    215197  assert(uiCode <= 63);
    216198  pcPPS->setPPSId (uiCode);
    217  
     199
    218200  READ_UVLC( uiCode, "pps_seq_parameter_set_id");
    219201  assert(uiCode <= 15);
    220202  pcPPS->setSPSId (uiCode);
    221  
     203
    222204  READ_FLAG( uiCode, "dependent_slice_segments_enabled_flag"    );    pcPPS->setDependentSliceSegmentsEnabledFlag   ( uiCode == 1 );
     205
    223206  READ_FLAG( uiCode, "output_flag_present_flag" );                    pcPPS->setOutputFlagPresentFlag( uiCode==1 );
    224207
    225208  READ_CODE(3, uiCode, "num_extra_slice_header_bits");                pcPPS->setNumExtraSliceHeaderBits(uiCode);
     209
    226210  READ_FLAG ( uiCode, "sign_data_hiding_flag" ); pcPPS->setSignHideFlag( uiCode );
    227211
     
    231215  assert(uiCode <= 14);
    232216  pcPPS->setNumRefIdxL0DefaultActive(uiCode+1);
    233  
     217
    234218  READ_UVLC(uiCode, "num_ref_idx_l1_default_active_minus1");
    235219  assert(uiCode <= 14);
    236220  pcPPS->setNumRefIdxL1DefaultActive(uiCode+1);
    237  
     221
    238222  READ_SVLC(iCode, "init_qp_minus26" );                            pcPPS->setPicInitQPMinus26(iCode);
    239223  READ_FLAG( uiCode, "constrained_intra_pred_flag" );              pcPPS->setConstrainedIntraPred( uiCode ? true : false );
    240   READ_FLAG( uiCode, "transform_skip_enabled_flag" );               
    241   pcPPS->setUseTransformSkip ( uiCode ? true : false ); 
     224  READ_FLAG( uiCode, "transform_skip_enabled_flag" );
     225  pcPPS->setUseTransformSkip ( uiCode ? true : false );
    242226
    243227  READ_FLAG( uiCode, "cu_qp_delta_enabled_flag" );            pcPPS->setUseDQP( uiCode ? true : false );
     
    252236  }
    253237  READ_SVLC( iCode, "pps_cb_qp_offset");
    254   pcPPS->setChromaCbQpOffset(iCode);
    255   assert( pcPPS->getChromaCbQpOffset() >= -12 );
    256   assert( pcPPS->getChromaCbQpOffset() <=  12 );
     238  pcPPS->setQpOffset(COMPONENT_Cb, iCode);
     239  assert( pcPPS->getQpOffset(COMPONENT_Cb) >= -12 );
     240  assert( pcPPS->getQpOffset(COMPONENT_Cb) <=  12 );
    257241
    258242  READ_SVLC( iCode, "pps_cr_qp_offset");
    259   pcPPS->setChromaCrQpOffset(iCode);
    260   assert( pcPPS->getChromaCrQpOffset() >= -12 );
    261   assert( pcPPS->getChromaCrQpOffset() <=  12 );
     243  pcPPS->setQpOffset(COMPONENT_Cr, iCode);
     244  assert( pcPPS->getQpOffset(COMPONENT_Cr) >= -12 );
     245  assert( pcPPS->getQpOffset(COMPONENT_Cr) <=  12 );
     246
     247  assert(MAX_NUM_COMPONENT<=3);
    262248
    263249  READ_FLAG( uiCode, "pps_slice_chroma_qp_offsets_present_flag" );
     
    273259  READ_FLAG( uiCode, "tiles_enabled_flag"               );    pcPPS->setTilesEnabledFlag            ( uiCode == 1 );
    274260  READ_FLAG( uiCode, "entropy_coding_sync_enabled_flag" );    pcPPS->setEntropyCodingSyncEnabledFlag( uiCode == 1 );
    275  
     261
    276262  if( pcPPS->getTilesEnabledFlag() )
    277263  {
     
    280266    READ_FLAG ( uiCode, "uniform_spacing_flag" );                   pcPPS->setTileUniformSpacingFlag( uiCode == 1 );
    281267
    282     if( !pcPPS->getTileUniformSpacingFlag())
    283     {
    284       std::vector<Int> columnWidth(pcPPS->getNumTileColumnsMinus1());
    285       for(UInt i=0; i<pcPPS->getNumTileColumnsMinus1(); i++)
    286       {
    287         READ_UVLC( uiCode, "column_width_minus1" ); 
    288         columnWidth[i] = uiCode+1;
    289       }
    290       pcPPS->setTileColumnWidth(columnWidth);
    291 
    292       std::vector<Int> rowHeight (pcPPS->getTileNumRowsMinus1());
    293       for(UInt i=0; i<pcPPS->getTileNumRowsMinus1(); i++)
    294       {
    295         READ_UVLC( uiCode, "row_height_minus1" );
    296         rowHeight[i] = uiCode + 1;
    297       }
    298       pcPPS->setTileRowHeight(rowHeight);
    299     }
    300 
    301     if(pcPPS->getNumTileColumnsMinus1() !=0 || pcPPS->getTileNumRowsMinus1() !=0)
     268    const UInt tileColumnsMinus1 = pcPPS->getNumTileColumnsMinus1();
     269    const UInt tileRowsMinus1    = pcPPS->getNumTileRowsMinus1();
     270 
     271    if ( !pcPPS->getTileUniformSpacingFlag())
     272    {
     273      if (tileColumnsMinus1 > 0)
     274      {
     275        std::vector<Int> columnWidth(tileColumnsMinus1);
     276        for(UInt i = 0; i < tileColumnsMinus1; i++)
     277        {
     278          READ_UVLC( uiCode, "column_width_minus1" ); 
     279          columnWidth[i] = uiCode+1;
     280        }
     281        pcPPS->setTileColumnWidth(columnWidth);
     282      }
     283
     284      if (tileRowsMinus1 > 0)
     285      {
     286        std::vector<Int> rowHeight (tileRowsMinus1);
     287        for(UInt i = 0; i < tileRowsMinus1; i++)
     288        {
     289          READ_UVLC( uiCode, "row_height_minus1" );
     290          rowHeight[i] = uiCode + 1;
     291        }
     292        pcPPS->setTileRowHeight(rowHeight);
     293      }
     294    }
     295
     296    if ((tileColumnsMinus1 + tileRowsMinus1) != 0)
    302297    {
    303298      READ_FLAG ( uiCode, "loop_filter_across_tiles_enabled_flag" );   pcPPS->setLoopFilterAcrossTilesEnabledFlag( uiCode ? true : false );
    304299    }
    305300  }
    306   READ_FLAG( uiCode, "loop_filter_across_slices_enabled_flag" );       pcPPS->setLoopFilterAcrossSlicesEnabledFlag( uiCode ? true : false );
     301  READ_FLAG( uiCode, "pps_loop_filter_across_slices_enabled_flag" );   pcPPS->setLoopFilterAcrossSlicesEnabledFlag( uiCode ? true : false );
    307302  READ_FLAG( uiCode, "deblocking_filter_control_present_flag" );       pcPPS->setDeblockingFilterControlPresentFlag( uiCode ? true : false );
    308303  if(pcPPS->getDeblockingFilterControlPresentFlag())
     
    319314  if(pcPPS->getScalingListPresentFlag ())
    320315  {
    321     parseScalingList( pcPPS->getScalingList() );
    322   }
     316    parseScalingList( &(pcPPS->getScalingList()) );
     317  }
     318
    323319  READ_FLAG( uiCode, "lists_modification_present_flag");
    324320  pcPPS->setListsModificationPresentFlag(uiCode);
     
    329325  READ_FLAG( uiCode, "slice_segment_header_extension_present_flag");
    330326  pcPPS->setSliceHeaderExtensionPresentFlag(uiCode);
    331  
    332 #if H_MV
     327
    333328  READ_FLAG( uiCode, "pps_extension_present_flag");
    334 #else
    335   READ_FLAG( uiCode, "pps_extension_flag");
    336 #endif
    337329  if (uiCode)
    338330  {
    339 
    340 #if H_MV
     331#if NH_MV
    341332    READ_FLAG( uiCode, "pps_range_extensions_flag" ); pcPPS->setPpsRangeExtensionsFlag( uiCode == 1 );
    342333    READ_FLAG( uiCode, "pps_multilayer_extension_flag" ); pcPPS->setPpsMultilayerExtensionFlag( uiCode == 1 );
    343 #if !H_3D
    344     READ_CODE( 6, uiCode, "pps_extension_6bits" ); pcPPS->setPpsExtension6bits( uiCode );
    345 #else
    346334    READ_FLAG( uiCode, "pps_3d_extension_flag" ); pcPPS->setPps3dExtensionFlag( uiCode == 1 );
    347335    READ_CODE( 5, uiCode, "pps_extension_5bits" ); pcPPS->setPpsExtension5bits( uiCode );
    348 #endif
    349336    if ( pcPPS->getPpsRangeExtensionsFlag() )
    350337    {
    351       assert(0);
    352     }
     338      TComPPSRExt &ppsRangeExtension = pcPPS->getPpsRangeExtension();     
     339
     340      if (pcPPS->getUseTransformSkip())
     341      {
     342        READ_UVLC( uiCode, "log2_max_transform_skip_block_size_minus2");
     343        ppsRangeExtension.setLog2MaxTransformSkipBlockSize(uiCode+2);
     344      }
     345
     346      READ_FLAG( uiCode, "cross_component_prediction_enabled_flag");
     347      ppsRangeExtension.setCrossComponentPredictionEnabledFlag(uiCode != 0);
     348
     349      READ_FLAG( uiCode, "chroma_qp_offset_list_enabled_flag");
     350      if (uiCode == 0)
     351      {
     352        ppsRangeExtension.clearChromaQpOffsetList();
     353        ppsRangeExtension.setDiffCuChromaQpOffsetDepth(0);
     354      }
     355      else
     356      {
     357        READ_UVLC(uiCode, "diff_cu_chroma_qp_offset_depth"); ppsRangeExtension.setDiffCuChromaQpOffsetDepth(uiCode);
     358        UInt tableSizeMinus1 = 0;
     359        READ_UVLC(tableSizeMinus1, "chroma_qp_offset_list_len_minus1");
     360        assert(tableSizeMinus1 < MAX_QP_OFFSET_LIST_SIZE);
     361
     362        for (Int cuChromaQpOffsetIdx = 0; cuChromaQpOffsetIdx <= (tableSizeMinus1); cuChromaQpOffsetIdx++)
     363        {
     364          Int cbOffset;
     365          Int crOffset;
     366          READ_SVLC(cbOffset, "cb_qp_offset_list[i]");
     367          assert(cbOffset >= -12 && cbOffset <= 12);
     368          READ_SVLC(crOffset, "cr_qp_offset_list[i]");
     369          assert(crOffset >= -12 && crOffset <= 12);
     370          // table uses +1 for index (see comment inside the function)
     371          ppsRangeExtension.setChromaQpOffsetListEntry(cuChromaQpOffsetIdx+1, cbOffset, crOffset);
     372        }
     373        assert(ppsRangeExtension.getChromaQpOffsetListLen() == tableSizeMinus1 + 1);
     374      }
     375
     376      READ_UVLC( uiCode, "log2_sao_offset_scale_luma");
     377      ppsRangeExtension.setLog2SaoOffsetScale(CHANNEL_TYPE_LUMA, uiCode);
     378      READ_UVLC( uiCode, "log2_sao_offset_scale_chroma");
     379      ppsRangeExtension.setLog2SaoOffsetScale(CHANNEL_TYPE_CHROMA, uiCode);    }
    353380
    354381    if ( pcPPS->getPpsMultilayerExtensionFlag() )
    355382    {
    356       parsePPSMultilayerExtension( pcPPS );
    357     }
    358 #if !H_3D
    359     if ( pcPPS->getPpsExtension6bits() )
    360     {
    361 #else
     383      parsePpsMultilayerExtension( pcPPS );
     384    }
     385
    362386    if ( pcPPS->getPps3dExtensionFlag() )
    363387    {
    364       parsePPSExtension( pcPPS, pcVPS );
    365     }
     388#if NH_3D
     389      parsePps3dExtension( pcPPS );
     390#endif
     391    }
     392#if NH_3D
    366393    if ( pcPPS->getPpsExtension5bits() )
    367     {
    368 #endif
    369 
    370 #endif
    371 
     394#else
     395    if ( pcPPS->getPpsExtension5bits() || pcPPS->getPps3dExtensionFlag() )
     396#endif
     397    {
    372398      while ( xMoreRbspData() )
    373399      {
    374400        READ_FLAG( uiCode, "pps_extension_data_flag");
    375401      }
    376 #if H_MV
    377     }
    378 #endif
    379   }
    380 }
    381 
    382 
    383 #if H_3D
    384 Void TDecCavlc::parsePPSExtension( TComPPS* pcPPS, TComVPS* pcVPS )
    385 {
    386   //Ed.(GT): pcVPS should not be used here. Needs to be fixed.
    387   UInt uiCode = 0;
    388   TComDLT* pcDLT = new TComDLT;
    389 
    390   READ_FLAG(uiCode, "dlt_present_flag");
    391   pcDLT->setDltPresentFlag( (uiCode == 1) ? true : false );
    392 
    393   if ( pcDLT->getDltPresentFlag() )
    394   {
    395     READ_CODE(6, uiCode, "pps_depth_layers_minus1");
    396     pcDLT->setNumDepthViews( uiCode );
    397 
    398     READ_CODE(4, uiCode, "pps_bit_depth_for_depth_views_minus8");
    399     pcDLT->setDepthViewBitDepth( (uiCode+8) );
    400 
    401     for( Int i = 0; i <= pcVPS->getMaxLayersMinus1(); i++ )
    402     {
    403       if ( i != 0 )
    404       {
    405         if( pcVPS->getDepthId( i ) == 1 )
    406         {
    407           READ_FLAG(uiCode, "dlt_flag[i]");
    408           pcDLT->setUseDLTFlag(i, (uiCode == 1) ? true : false);
    409 
    410           if ( pcDLT->getUseDLTFlag( i ) )
    411           {
    412             Bool bDltBitMapRepFlag    = false;
    413             UInt uiMaxDiff            = 0xffffffff;
    414             UInt uiMinDiff            = 0;
    415             UInt uiCodeLength         = 0;
    416 
    417             READ_FLAG(uiCode, "inter_view_dlt_pred_enable_flag[ i ]");
    418 
    419             if( uiCode )
     402    }
     403
     404#else
     405#if ENC_DEC_TRACE || RExt__DECODER_DEBUG_BIT_STATISTICS
     406    static const char *syntaxStrings[]={ "pps_range_extension_flag",
     407                                         "pps_multilayer_extension_flag",
     408                                         "pps_extension_6bits[0]",
     409                                         "pps_extension_6bits[1]",
     410                                         "pps_extension_6bits[2]",
     411                                         "pps_extension_6bits[3]",
     412                                         "pps_extension_6bits[4]",
     413                                         "pps_extension_6bits[5]" };
     414#endif
     415
     416    Bool pps_extension_flags[NUM_PPS_EXTENSION_FLAGS];
     417    for(Int i=0; i<NUM_PPS_EXTENSION_FLAGS; i++)
     418    {
     419      READ_FLAG( uiCode, syntaxStrings[i] );
     420      pps_extension_flags[i] = uiCode!=0;
     421    }
     422
     423    Bool bSkipTrailingExtensionBits=false;
     424    for(Int i=0; i<NUM_PPS_EXTENSION_FLAGS; i++) // loop used so that the order is determined by the enum.
     425    {
     426      if (pps_extension_flags[i])
     427      {
     428        switch (PPSExtensionFlagIndex(i))
     429        {
     430          case PPS_EXT__REXT:
    420431            {
    421                 assert( pcDLT->getUseDLTFlag( 1 ));
     432              TComPPSRExt &ppsRangeExtension = pcPPS->getPpsRangeExtension();
     433            assert(!bSkipTrailingExtensionBits);
     434
     435            if (pcPPS->getUseTransformSkip())
     436            {
     437              READ_UVLC( uiCode, "log2_max_transform_skip_block_size_minus2");
     438                ppsRangeExtension.setLog2MaxTransformSkipBlockSize(uiCode+2);
    422439            }
    423             pcDLT->setInterViewDltPredEnableFlag( i, (uiCode == 1) ? true : false );
    424 
    425             if ( pcDLT->getInterViewDltPredEnableFlag( i ) == false )
     440
     441            READ_FLAG( uiCode, "cross_component_prediction_enabled_flag");
     442              ppsRangeExtension.setCrossComponentPredictionEnabledFlag(uiCode != 0);
     443
     444            READ_FLAG( uiCode, "chroma_qp_offset_list_enabled_flag");
     445            if (uiCode == 0)
    426446            {
    427               READ_FLAG(uiCode, "dlt_bit_map_rep_flag[ layerId ]");
    428               bDltBitMapRepFlag = (uiCode == 1) ? true : false;
     447                ppsRangeExtension.clearChromaQpOffsetList();
     448                ppsRangeExtension.setDiffCuChromaQpOffsetDepth(0);
    429449            }
    430450            else
    431451            {
    432               bDltBitMapRepFlag = false;
     452                READ_UVLC(uiCode, "diff_cu_chroma_qp_offset_depth"); ppsRangeExtension.setDiffCuChromaQpOffsetDepth(uiCode);
     453              UInt tableSizeMinus1 = 0;
     454              READ_UVLC(tableSizeMinus1, "chroma_qp_offset_list_len_minus1");
     455              assert(tableSizeMinus1 < MAX_QP_OFFSET_LIST_SIZE);
     456
     457              for (Int cuChromaQpOffsetIdx = 0; cuChromaQpOffsetIdx <= (tableSizeMinus1); cuChromaQpOffsetIdx++)
     458              {
     459                Int cbOffset;
     460                Int crOffset;
     461                READ_SVLC(cbOffset, "cb_qp_offset_list[i]");
     462                assert(cbOffset >= -12 && cbOffset <= 12);
     463                READ_SVLC(crOffset, "cr_qp_offset_list[i]");
     464                assert(crOffset >= -12 && crOffset <= 12);
     465                // table uses +1 for index (see comment inside the function)
     466                  ppsRangeExtension.setChromaQpOffsetListEntry(cuChromaQpOffsetIdx+1, cbOffset, crOffset);
     467              }
     468                assert(ppsRangeExtension.getChromaQpOffsetListLen() == tableSizeMinus1 + 1);
     469            }
     470
     471            READ_UVLC( uiCode, "log2_sao_offset_scale_luma");
     472              ppsRangeExtension.setLog2SaoOffsetScale(CHANNEL_TYPE_LUMA, uiCode);
     473            READ_UVLC( uiCode, "log2_sao_offset_scale_chroma");
     474              ppsRangeExtension.setLog2SaoOffsetScale(CHANNEL_TYPE_CHROMA, uiCode);
     475            }
     476            break;
     477          default:
     478            bSkipTrailingExtensionBits=true;
     479            break;
     480        }
     481      }
     482    }
     483    if (bSkipTrailingExtensionBits)
     484    {
     485      while ( xMoreRbspData() )
     486      {
     487        READ_FLAG( uiCode, "pps_extension_data_flag");
     488      }
     489    }
     490#endif
     491  }
     492  xReadRbspTrailingBits();
     493}
     494
     495#if NH_3D
     496Void TDecCavlc::parsePps3dExtension( TComPPS* pcPPS )
     497{
     498#if NH_3D_DLT
     499  UInt uiCode = 0;
     500  //
     501  TComDLT* pcDLT = pcPPS->getDLT();
     502
     503  READ_FLAG(uiCode, "dlts_present_flag");
     504  pcDLT->setDltPresentFlag( (uiCode == 1) ? true : false );
     505
     506  if ( pcDLT->getDltPresentFlag() )
     507  {
     508    READ_CODE(6, uiCode, "pps_depth_layers_minus1");
     509#if NH_3D_VER141_DEC_COMP_FLAG
     510    pcDLT->setNumDepthViews( uiCode );
     511#else
     512    pcDLT->setNumDepthViews( uiCode+1 );
     513#endif
     514   
     515    READ_CODE(4, uiCode, "pps_bit_depth_for_depth_layers_minus8");
     516    pcDLT->setDepthViewBitDepth( (uiCode+8) );
     517   
     518#if NH_3D_DLT_FIX
     519    for( Int i = 0; i <= pcDLT->getNumDepthViews()-1; i++ )
     520#else
     521    for( Int i = 0; i <= pcDLT->getNumDepthViews(); i++ )
     522#endif
     523    {
     524      Int layerId = pcDLT->getDepthIdxToLayerId(i);
     525     
     526      READ_FLAG(uiCode, "dlt_flag[i]");
     527      pcDLT->setUseDLTFlag(layerId, (uiCode == 1) ? true : false);
     528     
     529      if ( pcDLT->getUseDLTFlag( layerId ) )
     530      {
     531        Bool bDltBitMapRepFlag    = false;
     532        UInt uiMaxDiff            = MAX_INT;
     533        UInt uiMinDiff            = 0;
     534        UInt uiCodeLength         = 0;
     535       
     536        READ_FLAG(uiCode, "dlt_pred_flag[i]");
     537       
     538        if( uiCode )
     539        {
     540          assert( pcDLT->getUseDLTFlag( 1 ));
     541        }
     542        pcDLT->setInterViewDltPredEnableFlag( layerId, (uiCode == 1) ? true : false );
     543       
     544        if ( pcDLT->getInterViewDltPredEnableFlag( layerId ) == false )
     545        {
     546          READ_FLAG(uiCode, "dlt_val_flags_present_flag[i]");
     547          bDltBitMapRepFlag = (uiCode == 1) ? true : false;
     548        }
     549        else
     550        {
     551          bDltBitMapRepFlag = false;
     552        }
     553       
     554        UInt uiNumDepthValues = 0;
     555        std::vector<Int> aiIdx2DepthValue(256, 0);
     556       
     557        // Bit map
     558        if ( bDltBitMapRepFlag )
     559        {
     560          for (UInt d=0; d<256; d++)
     561          {
     562            READ_FLAG(uiCode, "dlt_value_flag[i][j]");
     563            if (uiCode == 1)
     564            {
     565              aiIdx2DepthValue[uiNumDepthValues] = d;
     566              uiNumDepthValues++;
     567            }
     568          }
     569        }
     570        // Diff Coding
     571        else
     572        {
     573          READ_CODE(8, uiNumDepthValues, "num_val_delta_dlt");   // num_entry
     574         
     575          {
     576            // The condition if( pcVPS->getNumDepthValues(i) > 0 ) is always true since for Single-view Diff Coding, there is at least one depth value in depth component.
     577           
     578            if (uiNumDepthValues > 1)
     579            {
     580              READ_CODE(8, uiCode, "max_diff");
     581              uiMaxDiff = uiCode;
     582            }
     583            else
     584            {
     585              uiMaxDiff = 0;           // when there is only one value in DLT
    433586            }
    434587           
    435             UInt uiNumDepthValues = 0;
    436             Int  aiIdx2DepthValue[256];
    437 
    438             // Bit map
    439             if ( bDltBitMapRepFlag )
     588            if (uiNumDepthValues > 2)
    440589            {
    441               for (UInt d=0; d<256; d++)
     590              uiCodeLength = (UInt) gCeilLog2(uiMaxDiff + 1);
     591              READ_CODE(uiCodeLength, uiCode, "min_diff_minus1");
     592              uiMinDiff = uiCode + 1;
     593            }
     594            else
     595            {
     596              uiMinDiff = uiMaxDiff;   // when there are only one or two values in DLT
     597            }
     598           
     599            READ_CODE(8, uiCode, "delta_dlt_val0");   // entry0
     600            aiIdx2DepthValue[0] = uiCode;
     601           
     602            if (uiMaxDiff == uiMinDiff)
     603            {
     604              for (UInt d=1; d<uiNumDepthValues; d++)
    442605              {
    443                 READ_FLAG(uiCode, "dlt_bit_map_flag[ layerId ][ j ]");
    444                 if (uiCode == 1)
    445                 {
    446                   aiIdx2DepthValue[uiNumDepthValues] = d;
    447                   uiNumDepthValues++;
    448                 }
     606                aiIdx2DepthValue[d] = aiIdx2DepthValue[d-1] + uiMinDiff + 0;
    449607              }
    450608            }
    451             // Diff Coding
    452609            else
    453610            {
    454               READ_CODE(8, uiNumDepthValues, "num_depth_values_in_dlt[i]");   // num_entry
    455 
     611              uiCodeLength = (UInt) gCeilLog2(uiMaxDiff - uiMinDiff + 1);
     612              for (UInt d=1; d<uiNumDepthValues; d++)
    456613              {
    457                 // The condition if( pcVPS->getNumDepthValues(i) > 0 ) is always true since for Single-view Diff Coding, there is at least one depth value in depth component.
    458 
    459                 if (uiNumDepthValues > 1)
    460                 {
    461                   READ_CODE(8, uiCode, "max_diff[ layerId ]");
    462                   uiMaxDiff = uiCode;
    463                 }
    464                 else
    465                 {
    466                   uiMaxDiff = 0;           // when there is only one value in DLT
    467                 }
    468 
    469                 if (uiNumDepthValues > 2)
    470                 {
    471                   uiCodeLength = (UInt) ceil(Log2(uiMaxDiff + 1));
    472                   READ_CODE(uiCodeLength, uiCode, "min_diff_minus1[ layerId ]");
    473                   uiMinDiff = uiCode + 1;
    474                 }
    475                 else
    476                 {
    477                   uiMinDiff = uiMaxDiff;   // when there are only one or two values in DLT
    478                 }
    479 
    480                 READ_CODE(8, uiCode, "dlt_depth_value0[layerId]");   // entry0
    481                 aiIdx2DepthValue[0] = uiCode;
    482 
    483                 if (uiMaxDiff == uiMinDiff)
    484                 {
    485                   for (UInt d=1; d<uiNumDepthValues; d++)
    486                   {
    487                     aiIdx2DepthValue[d] = aiIdx2DepthValue[d-1] + uiMinDiff + 0;
    488                   }
    489                 }
    490                 else
    491                 {
    492                   uiCodeLength = (UInt) ceil(Log2(uiMaxDiff - uiMinDiff + 1));
    493                   for (UInt d=1; d<uiNumDepthValues; d++)
    494                   {
    495                     READ_CODE(uiCodeLength, uiCode, "dlt_depth_value_diff_minus_min[ layerId ][ j ]");
    496                     aiIdx2DepthValue[d] = aiIdx2DepthValue[d-1] + uiMinDiff + uiCode;
    497                   }
    498                 }
    499 
     614                READ_CODE(uiCodeLength, uiCode, "delta_val_diff_minus_min[k]");
     615                aiIdx2DepthValue[d] = aiIdx2DepthValue[d-1] + uiMinDiff + uiCode;
    500616              }
    501617            }
    502618           
    503             if( pcDLT->getInterViewDltPredEnableFlag( i ) )
    504             {
    505               // interpret decoded values as delta DLT
    506               AOF( pcVPS->getDepthId( 1 ) == 1 );
    507               AOF( i > 1 );
    508               // assumes ref layer id to be 1
    509               Int* piRefDLT = pcDLT->idx2DepthValue( 1 );
    510               UInt uiRefNum = pcDLT->getNumDepthValues( 1 );
    511               pcDLT->setDeltaDLT(i, piRefDLT, uiRefNum, aiIdx2DepthValue, uiNumDepthValues);
    512             }
    513             else
    514             {
    515               // store final DLT
    516               pcDLT->setDepthLUTs(i, aiIdx2DepthValue, uiNumDepthValues);
    517             }
    518 
    519619          }
    520620        }
    521       }
    522     }
    523   }
    524 
    525   pcPPS->setDLT( pcDLT );
    526 }
    527 #endif
     621       
     622        if( pcDLT->getInterViewDltPredEnableFlag( layerId ) )
     623        {
     624          // interpret decoded values as delta DLT
     625          AOF( layerId > 1 );
     626          // assumes ref layer id to be 1
     627          std::vector<Int> viRefDLT = pcDLT->idx2DepthValue( 1 );
     628          UInt uiRefNum = pcDLT->getNumDepthValues( 1 );
     629          pcDLT->setDeltaDLT(layerId, viRefDLT, uiRefNum, aiIdx2DepthValue, uiNumDepthValues);
     630        }
     631        else
     632        {
     633          // store final DLT
     634          pcDLT->setDepthLUTs(layerId, aiIdx2DepthValue, uiNumDepthValues);
     635        }
     636      }
     637    }
     638  }
     639#endif
     640}
     641#endif
     642
    528643
    529644Void  TDecCavlc::parseVUI(TComVUI* pcVUI, TComSPS *pcSPS)
     
    541656    {
    542657      READ_CODE(16, uiCode, "sar_width");                             pcVUI->setSarWidth(uiCode);
    543       READ_CODE(16, uiCode, "sar_height");                            pcVUI->setSarHeight(uiCode);
     658      READ_CODE(16, uiCode, "sar_height");                              pcVUI->setSarHeight(uiCode);
    544659    }
    545660  }
     
    552667
    553668  READ_FLAG(     uiCode, "video_signal_type_present_flag");           pcVUI->setVideoSignalTypePresentFlag(uiCode);
    554 #if H_MV
     669#if NH_MV
    555670  assert( pcSPS->getLayerId() == 0 || !pcVUI->getVideoSignalTypePresentFlag() );
    556671#endif
     
    564679      READ_CODE(8, uiCode, "colour_primaries");                       pcVUI->setColourPrimaries(uiCode);
    565680      READ_CODE(8, uiCode, "transfer_characteristics");               pcVUI->setTransferCharacteristics(uiCode);
    566       READ_CODE(8, uiCode, "matrix_coefficients");                    pcVUI->setMatrixCoefficients(uiCode);
     681      READ_CODE(8, uiCode, "matrix_coeffs");                          pcVUI->setMatrixCoefficients(uiCode);
    567682    }
    568683  }
     
    585700  {
    586701    Window &defDisp = pcVUI->getDefaultDisplayWindow();
    587 #if H_MV
     702#if NH_MV
    588703    defDisp.setScaledFlag( false );
    589704    READ_UVLC(   uiCode, "def_disp_win_left_offset" );                defDisp.setWindowLeftOffset  ( uiCode );
     
    598713#endif
    599714  }
     715
    600716  TimingInfo *timingInfo = pcVUI->getTimingInfo();
    601717  READ_FLAG(       uiCode, "vui_timing_info_present_flag");         timingInfo->setTimingInfoPresentFlag      (uiCode ? true : false);
     
    609725      READ_UVLC(   uiCode, "vui_num_ticks_poc_diff_one_minus1");    timingInfo->setNumTicksPocDiffOneMinus1   (uiCode);
    610726    }
    611   READ_FLAG(     uiCode, "hrd_parameters_present_flag");              pcVUI->setHrdParametersPresentFlag(uiCode);
    612   if( pcVUI->getHrdParametersPresentFlag() )
    613   {
    614     parseHrdParameters( pcVUI->getHrdParameters(), 1, pcSPS->getMaxTLayers() - 1 );
    615   }
    616   }
     727
     728    READ_FLAG(     uiCode, "vui_hrd_parameters_present_flag");        pcVUI->setHrdParametersPresentFlag(uiCode);
     729    if( pcVUI->getHrdParametersPresentFlag() )
     730    {
     731      parseHrdParameters( pcVUI->getHrdParameters(), 1, pcSPS->getMaxTLayers() - 1 );
     732    }
     733  }
     734
    617735  READ_FLAG(     uiCode, "bitstream_restriction_flag");               pcVUI->setBitstreamRestrictionFlag(uiCode);
    618736  if (pcVUI->getBitstreamRestrictionFlag())
     
    621739    READ_FLAG(   uiCode, "motion_vectors_over_pic_boundaries_flag");  pcVUI->setMotionVectorsOverPicBoundariesFlag(uiCode);
    622740    READ_FLAG(   uiCode, "restricted_ref_pic_lists_flag");            pcVUI->setRestrictedRefPicListsFlag(uiCode);
    623     READ_UVLC( uiCode, "min_spatial_segmentation_idc");            pcVUI->setMinSpatialSegmentationIdc(uiCode);
     741    READ_UVLC(   uiCode, "min_spatial_segmentation_idc");             pcVUI->setMinSpatialSegmentationIdc(uiCode);
    624742    assert(uiCode < 4096);
    625743    READ_UVLC(   uiCode, "max_bytes_per_pic_denom" );                 pcVUI->setMaxBytesPerPicDenom(uiCode);
    626     READ_UVLC(   uiCode, "max_bits_per_mincu_denom" );                pcVUI->setMaxBitsPerMinCuDenom(uiCode);
     744    READ_UVLC(   uiCode, "max_bits_per_min_cu_denom" );               pcVUI->setMaxBitsPerMinCuDenom(uiCode);
    627745    READ_UVLC(   uiCode, "log2_max_mv_length_horizontal" );           pcVUI->setLog2MaxMvLengthHorizontal(uiCode);
    628746    READ_UVLC(   uiCode, "log2_max_mv_length_vertical" );             pcVUI->setLog2MaxMvLengthVertical(uiCode);
     
    639757    if( hrd->getNalHrdParametersPresentFlag() || hrd->getVclHrdParametersPresentFlag() )
    640758    {
    641       READ_FLAG( uiCode, "sub_pic_cpb_params_present_flag" );         hrd->setSubPicCpbParamsPresentFlag( uiCode == 1 ? true : false );
     759      READ_FLAG( uiCode, "sub_pic_hrd_params_present_flag" );         hrd->setSubPicCpbParamsPresentFlag( uiCode == 1 ? true : false );
    642760      if( hrd->getSubPicCpbParamsPresentFlag() )
    643761      {
    644762        READ_CODE( 8, uiCode, "tick_divisor_minus2" );                hrd->setTickDivisorMinus2( uiCode );
    645         READ_CODE( 5, uiCode, "du_cpb_removal_delay_length_minus1" ); hrd->setDuCpbRemovalDelayLengthMinus1( uiCode );
     763        READ_CODE( 5, uiCode, "du_cpb_removal_delay_increment_length_minus1" ); hrd->setDuCpbRemovalDelayLengthMinus1( uiCode );
    646764        READ_FLAG( uiCode, "sub_pic_cpb_params_in_pic_timing_sei_flag" ); hrd->setSubPicCpbParamsInPicTimingSEIFlag( uiCode == 1 ? true : false );
    647765        READ_CODE( 5, uiCode, "dpb_output_delay_du_length_minus1"  ); hrd->setDpbOutputDelayDuLengthMinus1( uiCode );
     
    670788      hrd->setFixedPicRateWithinCvsFlag( i, true );
    671789    }
     790
    672791    hrd->setLowDelayHrdFlag( i, 0 ); // Infered to be 0 when not present
    673792    hrd->setCpbCntMinus1   ( i, 0 ); // Infered to be 0 when not present
     793
    674794    if( hrd->getFixedPicRateWithinCvsFlag( i ) )
    675795    {
     
    677797    }
    678798    else
    679     {     
     799    {
    680800      READ_FLAG( uiCode, "low_delay_hrd_flag" );                      hrd->setLowDelayHrdFlag( i, uiCode == 1 ? true : false  );
    681801    }
    682802    if (!hrd->getLowDelayHrdFlag( i ))
    683803    {
    684       READ_UVLC( uiCode, "cpb_cnt_minus1" );                          hrd->setCpbCntMinus1( i, uiCode );     
    685     }
     804      READ_UVLC( uiCode, "cpb_cnt_minus1" );                          hrd->setCpbCntMinus1( i, uiCode );
     805    }
     806
    686807    for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
    687808    {
     
    707828Void TDecCavlc::parseSPS(TComSPS* pcSPS)
    708829{
    709 #if ENC_DEC_TRACE 
    710   xTraceSPSHeader (pcSPS);
     830#if ENC_DEC_TRACE
     831#if H_MV_ENC_DEC_TRAC
     832  tracePSHeader( "SPS", pcSPS->getLayerId() );
     833#else
     834  xTraceSPSHeader ();
     835#endif
    711836#endif
    712837
     
    714839  READ_CODE( 4,  uiCode, "sps_video_parameter_set_id");          pcSPS->setVPSId        ( uiCode );
    715840
    716 #if H_MV
     841#if NH_MV
    717842  if ( pcSPS->getLayerId() == 0 )
    718843  {
    719844#endif
    720     READ_CODE( 3,  uiCode, "sps_max_sub_layers_minus1" );          pcSPS->setMaxTLayers   ( uiCode+1 );
    721     assert(uiCode <= 6);
    722 #if H_MV
     845  READ_CODE( 3,  uiCode, "sps_max_sub_layers_minus1" );          pcSPS->setMaxTLayers   ( uiCode+1 );
     846  assert(uiCode <= 6);
     847#if NH_MV
    723848  }
    724849  else
     
    731856#endif
    732857
    733     READ_FLAG( uiCode, "sps_temporal_id_nesting_flag" );               pcSPS->setTemporalIdNestingFlag ( uiCode > 0 ? true : false );
    734     if ( pcSPS->getMaxTLayers() == 1 )
    735     {
    736       // sps_temporal_id_nesting_flag must be 1 when sps_max_sub_layers_minus1 is 0
    737       assert( uiCode == 1 );
    738     }
    739 
    740     parsePTL(pcSPS->getPTL(), 1, pcSPS->getMaxTLayers() - 1);
    741 #if H_MV
     858  READ_FLAG( uiCode, "sps_temporal_id_nesting_flag" );           pcSPS->setTemporalIdNestingFlag ( uiCode > 0 ? true : false );
     859  if ( pcSPS->getMaxTLayers() == 1 )
     860  {
     861    // sps_temporal_id_nesting_flag must be 1 when sps_max_sub_layers_minus1 is 0
     862    assert( uiCode == 1 );
     863  }
     864
     865  parsePTL(pcSPS->getPTL(), 1, pcSPS->getMaxTLayers() - 1);
     866#if NH_MV
    742867    pcSPS->getPTL()->inferGeneralValues ( true, 0, NULL );
    743868    pcSPS->getPTL()->inferSubLayerValues( pcSPS->getMaxTLayers() - 1, 0, NULL );
     
    746871  READ_UVLC(     uiCode, "sps_seq_parameter_set_id" );           pcSPS->setSPSId( uiCode );
    747872  assert(uiCode <= 15);
    748 #if H_MV
     873#if NH_MV
    749874  if ( pcSPS->getMultiLayerExtSpsFlag() )
    750875  {
     
    758883  {
    759884#endif
    760     READ_UVLC(     uiCode, "chroma_format_idc" );                  pcSPS->setChromaFormatIdc( uiCode );
    761     assert(uiCode <= 3);
    762     // in the first version we only support chroma_format_idc equal to 1 (4:2:0), so separate_colour_plane_flag cannot appear in the bitstream
    763 #if !H_3D_DISABLE_CHROMA
    764     assert (uiCode == 1);
    765 #endif
    766     if( uiCode == 3 )
    767     {
    768       READ_FLAG(     uiCode, "separate_colour_plane_flag");        assert(uiCode == 0);
    769     }
    770 
    771     READ_UVLC (    uiCode, "pic_width_in_luma_samples" );          pcSPS->setPicWidthInLumaSamples ( uiCode    );
    772     READ_UVLC (    uiCode, "pic_height_in_luma_samples" );         pcSPS->setPicHeightInLumaSamples( uiCode    );
     885
     886  READ_UVLC(     uiCode, "chroma_format_idc" );                  pcSPS->setChromaFormatIdc( ChromaFormat(uiCode) );
     887  assert(uiCode <= 3);
     888  if( pcSPS->getChromaFormatIdc() == CHROMA_444 )
     889  {
     890    READ_FLAG(     uiCode, "separate_colour_plane_flag");        assert(uiCode == 0);
     891  }
     892
     893  READ_UVLC (    uiCode, "pic_width_in_luma_samples" );          pcSPS->setPicWidthInLumaSamples ( uiCode    );
     894  READ_UVLC (    uiCode, "pic_height_in_luma_samples" );         pcSPS->setPicHeightInLumaSamples( uiCode    );
    773895  READ_FLAG(     uiCode, "conformance_window_flag");
    774896  if (uiCode != 0)
    775897  {
    776898    Window &conf = pcSPS->getConformanceWindow();
    777 #if H_MV
     899#if NH_MV
    778900    // Needs to be scaled later, when ChromaFormatIdc is known.
    779901    conf.setScaledFlag( false );
     
    791913  }
    792914
    793 #if H_MV
     915#if NH_MV
    794916  if ( !pcSPS->getMultiLayerExtSpsFlag() )
    795917  {
    796918#endif
    797     READ_UVLC(     uiCode, "bit_depth_luma_minus8" );
    798     assert(uiCode <= 6);
    799     pcSPS->setBitDepthY( uiCode + 8 );
    800     pcSPS->setQpBDOffsetY( (Int) (6*uiCode) );
    801 
    802     READ_UVLC( uiCode,    "bit_depth_chroma_minus8" );
    803     assert(uiCode <= 6);
    804     pcSPS->setBitDepthC( uiCode + 8 );
    805     pcSPS->setQpBDOffsetC( (Int) (6*uiCode) );
    806 #if H_MV
     919
     920  READ_UVLC(     uiCode, "bit_depth_luma_minus8" );
     921#if O0043_BEST_EFFORT_DECODING
     922  pcSPS->setStreamBitDepth(CHANNEL_TYPE_LUMA, 8 + uiCode);
     923  const UInt forceDecodeBitDepth = pcSPS->getForceDecodeBitDepth();
     924  if (forceDecodeBitDepth != 0)
     925  {
     926    uiCode = forceDecodeBitDepth - 8;
     927  }
     928#endif
     929  assert(uiCode <= 8);
     930  pcSPS->setBitDepth(CHANNEL_TYPE_LUMA, 8 + uiCode);
     931
     932#if O0043_BEST_EFFORT_DECODING
     933  pcSPS->setQpBDOffset(CHANNEL_TYPE_LUMA, (Int) (6*(pcSPS->getStreamBitDepth(CHANNEL_TYPE_LUMA)-8)) );
     934#else
     935  pcSPS->setQpBDOffset(CHANNEL_TYPE_LUMA, (Int) (6*uiCode) );
     936#endif
     937
     938  READ_UVLC( uiCode,    "bit_depth_chroma_minus8" );
     939#if O0043_BEST_EFFORT_DECODING
     940  pcSPS->setStreamBitDepth(CHANNEL_TYPE_CHROMA, 8 + uiCode);
     941  if (forceDecodeBitDepth != 0)
     942  {
     943    uiCode = forceDecodeBitDepth - 8;
     944  }
     945#endif
     946  assert(uiCode <= 8);
     947  pcSPS->setBitDepth(CHANNEL_TYPE_CHROMA, 8 + uiCode);
     948#if O0043_BEST_EFFORT_DECODING
     949  pcSPS->setQpBDOffset(CHANNEL_TYPE_CHROMA,  (Int) (6*(pcSPS->getStreamBitDepth(CHANNEL_TYPE_CHROMA)-8)) );
     950#else
     951  pcSPS->setQpBDOffset(CHANNEL_TYPE_CHROMA,  (Int) (6*uiCode) );
     952#endif
     953#if NH_MV
    807954  }
    808955#endif
     
    811958  assert(uiCode <= 12);
    812959
    813 #if H_MV
     960#if NH_MV
    814961  if ( !pcSPS->getMultiLayerExtSpsFlag())
    815962  { 
    816963#endif
    817     UInt subLayerOrderingInfoPresentFlag;
    818     READ_FLAG(subLayerOrderingInfoPresentFlag, "sps_sub_layer_ordering_info_present_flag");
    819 
    820     for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++)
    821     {
    822       READ_UVLC ( uiCode, "sps_max_dec_pic_buffering_minus1[i]");
    823       pcSPS->setMaxDecPicBuffering( uiCode + 1, i);
    824       READ_UVLC ( uiCode, "sps_num_reorder_pics[i]" );
    825       pcSPS->setNumReorderPics(uiCode, i);
    826       READ_UVLC ( uiCode, "sps_max_latency_increase_plus1[i]");
    827       pcSPS->setMaxLatencyIncrease( uiCode, i );
    828 
    829       if (!subLayerOrderingInfoPresentFlag)
    830       {
    831         for (i++; i <= pcSPS->getMaxTLayers()-1; i++)
    832         {
    833           pcSPS->setMaxDecPicBuffering(pcSPS->getMaxDecPicBuffering(0), i);
    834           pcSPS->setNumReorderPics(pcSPS->getNumReorderPics(0), i);
    835           pcSPS->setMaxLatencyIncrease(pcSPS->getMaxLatencyIncrease(0), i);
    836         }
    837         break;
    838       }
    839     }
    840 #if H_MV
    841   }
    842 #endif
    843 
    844   READ_UVLC( uiCode, "log2_min_coding_block_size_minus3" );
     964  UInt subLayerOrderingInfoPresentFlag;
     965  READ_FLAG(subLayerOrderingInfoPresentFlag, "sps_sub_layer_ordering_info_present_flag");
     966
     967  for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++)
     968  {
     969    READ_UVLC ( uiCode, "sps_max_dec_pic_buffering_minus1[i]");
     970    pcSPS->setMaxDecPicBuffering( uiCode + 1, i);
     971    READ_UVLC ( uiCode, "sps_max_num_reorder_pics[i]" );
     972    pcSPS->setNumReorderPics(uiCode, i);
     973    READ_UVLC ( uiCode, "sps_max_latency_increase_plus1[i]");
     974    pcSPS->setMaxLatencyIncrease( uiCode, i );
     975
     976    if (!subLayerOrderingInfoPresentFlag)
     977    {
     978      for (i++; i <= pcSPS->getMaxTLayers()-1; i++)
     979      {
     980        pcSPS->setMaxDecPicBuffering(pcSPS->getMaxDecPicBuffering(0), i);
     981        pcSPS->setNumReorderPics(pcSPS->getNumReorderPics(0), i);
     982        pcSPS->setMaxLatencyIncrease(pcSPS->getMaxLatencyIncrease(0), i);
     983      }
     984      break;
     985    }
     986  }
     987#if NH_MV
     988  }
     989#endif
     990
     991  READ_UVLC( uiCode, "log2_min_luma_coding_block_size_minus3" );
    845992  Int log2MinCUSize = uiCode + 3;
    846993  pcSPS->setLog2MinCodingBlockSize(log2MinCUSize);
    847   READ_UVLC( uiCode, "log2_diff_max_min_coding_block_size" );
     994  READ_UVLC( uiCode, "log2_diff_max_min_luma_coding_block_size" );
    848995  pcSPS->setLog2DiffMaxMinCodingBlockSize(uiCode);
    849 
     996 
    850997  if (pcSPS->getPTL()->getGeneralPTL()->getLevelIdc() >= Level::LEVEL5)
    851998  {
    852999    assert(log2MinCUSize + pcSPS->getLog2DiffMaxMinCodingBlockSize() >= 5);
    8531000  }
    854 
     1001 
    8551002  Int maxCUDepthDelta = uiCode;
    856   pcSPS->setMaxCUWidth  ( 1<<(log2MinCUSize + maxCUDepthDelta) ); 
     1003  pcSPS->setMaxCUWidth  ( 1<<(log2MinCUSize + maxCUDepthDelta) );
    8571004  pcSPS->setMaxCUHeight ( 1<<(log2MinCUSize + maxCUDepthDelta) );
    858   READ_UVLC( uiCode, "log2_min_transform_block_size_minus2" );   pcSPS->setQuadtreeTULog2MinSize( uiCode + 2 );
    859 
    860   READ_UVLC( uiCode, "log2_diff_max_min_transform_block_size" ); pcSPS->setQuadtreeTULog2MaxSize( uiCode + pcSPS->getQuadtreeTULog2MinSize() );
     1005  READ_UVLC( uiCode, "log2_min_luma_transform_block_size_minus2" );   pcSPS->setQuadtreeTULog2MinSize( uiCode + 2 );
     1006
     1007  READ_UVLC( uiCode, "log2_diff_max_min_luma_transform_block_size" ); pcSPS->setQuadtreeTULog2MaxSize( uiCode + pcSPS->getQuadtreeTULog2MinSize() );
    8611008  pcSPS->setMaxTrSize( 1<<(uiCode + pcSPS->getQuadtreeTULog2MinSize()) );
    8621009
     
    8651012
    8661013  Int addCuDepth = max (0, log2MinCUSize - (Int)pcSPS->getQuadtreeTULog2MinSize() );
    867   pcSPS->setMaxCUDepth( maxCUDepthDelta + addCuDepth );
     1014  pcSPS->setMaxTotalCUDepth( maxCUDepthDelta + addCuDepth  + getMaxCUDepthOffset(pcSPS->getChromaFormatIdc(), pcSPS->getQuadtreeTULog2MinSize()) );
    8681015
    8691016  READ_FLAG( uiCode, "scaling_list_enabled_flag" );                 pcSPS->setScalingListFlag ( uiCode );
    8701017  if(pcSPS->getScalingListFlag())
    8711018  {
    872 #if H_MV
     1019#if NH_MV
    8731020    if ( pcSPS->getMultiLayerExtSpsFlag() )
    8741021    {   
     
    8831030    {   
    8841031#endif
    885       READ_FLAG( uiCode, "sps_scaling_list_data_present_flag" );                 pcSPS->setScalingListPresentFlag ( uiCode );
    886       if(pcSPS->getScalingListPresentFlag ())
    887       {
    888         parseScalingList( pcSPS->getScalingList() );
    889       }
    890 #if H_MV
     1032    READ_FLAG( uiCode, "sps_scaling_list_data_present_flag" );                 pcSPS->setScalingListPresentFlag ( uiCode );
     1033    if(pcSPS->getScalingListPresentFlag ())
     1034    {
     1035      parseScalingList( &(pcSPS->getScalingList()) );
     1036    }
     1037#if NH_MV
    8911038    }
    8921039#endif
     
    8981045  if( pcSPS->getUsePCM() )
    8991046  {
    900     READ_CODE( 4, uiCode, "pcm_sample_bit_depth_luma_minus1" );          pcSPS->setPCMBitDepthLuma   ( 1 + uiCode );
    901     READ_CODE( 4, uiCode, "pcm_sample_bit_depth_chroma_minus1" );        pcSPS->setPCMBitDepthChroma ( 1 + uiCode );
     1047    READ_CODE( 4, uiCode, "pcm_sample_bit_depth_luma_minus1" );          pcSPS->setPCMBitDepth    ( CHANNEL_TYPE_LUMA, 1 + uiCode );
     1048    READ_CODE( 4, uiCode, "pcm_sample_bit_depth_chroma_minus1" );        pcSPS->setPCMBitDepth    ( CHANNEL_TYPE_CHROMA, 1 + uiCode );
    9021049    READ_UVLC( uiCode, "log2_min_pcm_luma_coding_block_size_minus3" );   pcSPS->setPCMLog2MinSize (uiCode+3);
    9031050    READ_UVLC( uiCode, "log2_diff_max_min_pcm_luma_coding_block_size" ); pcSPS->setPCMLog2MaxSize ( uiCode+pcSPS->getPCMLog2MinSize() );
     
    9181065  }
    9191066  READ_FLAG( uiCode, "long_term_ref_pics_present_flag" );          pcSPS->setLongTermRefsPresent(uiCode);
    920   if (pcSPS->getLongTermRefsPresent()) 
    921   {
    922     READ_UVLC( uiCode, "num_long_term_ref_pic_sps" );
     1067  if (pcSPS->getLongTermRefsPresent())
     1068  {
     1069    READ_UVLC( uiCode, "num_long_term_ref_pics_sps" );
    9231070    pcSPS->setNumLongTermRefPicSPS(uiCode);
    9241071    for (UInt k = 0; k < pcSPS->getNumLongTermRefPicSPS(); k++)
     
    9411088  }
    9421089
    943 
    944 #if H_MV
    9451090  READ_FLAG( uiCode, "sps_extension_present_flag");
     1091#if NH_MV
    9461092  pcSPS->setSpsExtensionPresentFlag( uiCode );
    9471093  if (pcSPS->getSpsExtensionPresentFlag( ) )
     1094  { 
     1095    READ_FLAG( uiCode, "sps_range_extensions_flag" );     pcSPS->setSpsRangeExtensionsFlag( uiCode == 1 );
     1096    READ_FLAG( uiCode, "sps_multilayer_extension_flag" ); pcSPS->setSpsMultilayerExtensionFlag( uiCode == 1 );
     1097    READ_FLAG( uiCode   , "sps_3d_extension_flag" );      pcSPS->setSps3dExtensionFlag( uiCode == 1 );
     1098    READ_CODE( 5, uiCode, "sps_extension_5bits" )  ;      pcSPS->setSpsExtension5bits( uiCode );
     1099
     1100    if ( pcSPS->getSpsRangeExtensionsFlag() )
     1101    {
     1102              TComSPSRExt &spsRangeExtension = pcSPS->getSpsRangeExtension();
     1103              READ_FLAG( uiCode, "transform_skip_rotation_enabled_flag");     spsRangeExtension.setTransformSkipRotationEnabledFlag(uiCode != 0);
     1104              READ_FLAG( uiCode, "transform_skip_context_enabled_flag");      spsRangeExtension.setTransformSkipContextEnabledFlag (uiCode != 0);
     1105              READ_FLAG( uiCode, "implicit_rdpcm_enabled_flag");              spsRangeExtension.setRdpcmEnabledFlag(RDPCM_SIGNAL_IMPLICIT, (uiCode != 0));
     1106              READ_FLAG( uiCode, "explicit_rdpcm_enabled_flag");              spsRangeExtension.setRdpcmEnabledFlag(RDPCM_SIGNAL_EXPLICIT, (uiCode != 0));
     1107              READ_FLAG( uiCode, "extended_precision_processing_flag");       spsRangeExtension.setExtendedPrecisionProcessingFlag (uiCode != 0);
     1108              READ_FLAG( uiCode, "intra_smoothing_disabled_flag");            spsRangeExtension.setIntraSmoothingDisabledFlag      (uiCode != 0);
     1109              READ_FLAG( uiCode, "high_precision_offsets_enabled_flag");      spsRangeExtension.setHighPrecisionOffsetsEnabledFlag (uiCode != 0);
     1110              READ_FLAG( uiCode, "persistent_rice_adaptation_enabled_flag");  spsRangeExtension.setPersistentRiceAdaptationEnabledFlag (uiCode != 0);
     1111              READ_FLAG( uiCode, "cabac_bypass_alignment_enabled_flag");      spsRangeExtension.setCabacBypassAlignmentEnabledFlag  (uiCode != 0);
     1112    }
     1113
     1114    if ( pcSPS->getSpsMultilayerExtensionFlag() )
     1115    {
     1116      parseSpsMultilayerExtension( pcSPS );
     1117    }
     1118
     1119    if ( pcSPS->getSps3dExtensionFlag() )
     1120    {
     1121#if NH_3D
     1122      parseSps3dExtension( pcSPS );
     1123#endif
     1124    }
     1125
     1126#if NH_3D
     1127    if ( pcSPS->getSpsExtension5bits() )
    9481128#else
    949   READ_FLAG( uiCode, "sps_extension_flag");
     1129    if ( pcSPS->getSpsExtension5bits() || pcSPS->getSps3dExtensionFlag() )
     1130#endif
     1131    {
     1132      while ( xMoreRbspData() )
     1133      {
     1134        READ_FLAG( uiCode, "sps_extension_data_flag");
     1135      }
     1136    }
     1137  }
     1138#else
    9501139  if (uiCode)
    951 #endif
    952   {
    953 #if H_MV
    954     READ_FLAG( uiCode, "sps_range_extensions_flag" ); pcSPS->setSpsRangeExtensionsFlag( uiCode == 1 );
    955     READ_FLAG( uiCode, "sps_multilayer_extension_flag" ); pcSPS->setSpsMultilayerExtensionFlag( uiCode == 1 );
    956 #if !H_3D
    957     READ_CODE( 6, uiCode, "sps_extension_6bits" ); pcSPS->setSpsExtension6bits( uiCode );
    958 #else
    959     READ_FLAG( uiCode, "sps_3d_extension_flag" ); pcSPS->setSps3dExtensionFlag( uiCode == 1 );
    960     READ_CODE( 5, uiCode, "sps_extension_5bits" ); pcSPS->setSpsExtension5bits( uiCode );
    961 #endif
    962   }
    963 
    964   if ( pcSPS->getSpsRangeExtensionsFlag() )
    965   {
    966     assert( 0 );
    967   }
    968 
    969   if ( pcSPS->getSpsMultilayerExtensionFlag() )
    970   {
    971     parseSPSExtension( pcSPS );
    972   }
    973 
    974 #if H_3D
    975   if ( pcSPS->getSps3dExtensionFlag() )
    976   {
    977     parseSPS3dExtension( pcSPS );
    978   }
    979 
    980   if ( pcSPS->getSpsExtension5bits() )
    981   {
    982 #else
    983   if ( pcSPS->getSpsExtension6bits() )
    984   {
    985 #endif
    986 
    987 #endif
    988     while ( xMoreRbspData() )
    989     {
    990       READ_FLAG( uiCode, "sps_extension_data_flag");
    991     }
    992   }
    993 }
    994 
    995 #if H_MV
    996 Void TDecCavlc::parseSPSExtension( TComSPS* pcSPS )
     1140  {
     1141
     1142#if ENC_DEC_TRACE || RExt__DECODER_DEBUG_BIT_STATISTICS
     1143    static const char *syntaxStrings[]={ "sps_range_extension_flag",
     1144                                         "sps_multilayer_extension_flag",
     1145                                         "sps_extension_6bits[0]",
     1146                                         "sps_extension_6bits[1]",
     1147                                         "sps_extension_6bits[2]",
     1148                                         "sps_extension_6bits[3]",
     1149                                         "sps_extension_6bits[4]",
     1150                                         "sps_extension_6bits[5]" };
     1151#endif
     1152    Bool sps_extension_flags[NUM_SPS_EXTENSION_FLAGS];
     1153
     1154    for(Int i=0; i<NUM_SPS_EXTENSION_FLAGS; i++)
     1155    {
     1156      READ_FLAG( uiCode, syntaxStrings[i] );
     1157      sps_extension_flags[i] = uiCode!=0;
     1158    }
     1159
     1160    Bool bSkipTrailingExtensionBits=false;
     1161    for(Int i=0; i<NUM_SPS_EXTENSION_FLAGS; i++) // loop used so that the order is determined by the enum.
     1162    {
     1163      if (sps_extension_flags[i])
     1164      {
     1165        switch (SPSExtensionFlagIndex(i))
     1166        {
     1167          case SPS_EXT__REXT:
     1168            assert(!bSkipTrailingExtensionBits);
     1169            {
     1170              TComSPSRExt &spsRangeExtension = pcSPS->getSpsRangeExtension();
     1171              READ_FLAG( uiCode, "transform_skip_rotation_enabled_flag");     spsRangeExtension.setTransformSkipRotationEnabledFlag(uiCode != 0);
     1172              READ_FLAG( uiCode, "transform_skip_context_enabled_flag");      spsRangeExtension.setTransformSkipContextEnabledFlag (uiCode != 0);
     1173              READ_FLAG( uiCode, "implicit_rdpcm_enabled_flag");              spsRangeExtension.setRdpcmEnabledFlag(RDPCM_SIGNAL_IMPLICIT, (uiCode != 0));
     1174              READ_FLAG( uiCode, "explicit_rdpcm_enabled_flag");              spsRangeExtension.setRdpcmEnabledFlag(RDPCM_SIGNAL_EXPLICIT, (uiCode != 0));
     1175              READ_FLAG( uiCode, "extended_precision_processing_flag");       spsRangeExtension.setExtendedPrecisionProcessingFlag (uiCode != 0);
     1176              READ_FLAG( uiCode, "intra_smoothing_disabled_flag");            spsRangeExtension.setIntraSmoothingDisabledFlag      (uiCode != 0);
     1177              READ_FLAG( uiCode, "high_precision_offsets_enabled_flag");      spsRangeExtension.setHighPrecisionOffsetsEnabledFlag (uiCode != 0);
     1178              READ_FLAG( uiCode, "persistent_rice_adaptation_enabled_flag");  spsRangeExtension.setPersistentRiceAdaptationEnabledFlag (uiCode != 0);
     1179              READ_FLAG( uiCode, "cabac_bypass_alignment_enabled_flag");      spsRangeExtension.setCabacBypassAlignmentEnabledFlag  (uiCode != 0);
     1180            }
     1181            break;
     1182          default:
     1183            bSkipTrailingExtensionBits=true;
     1184            break;
     1185        }
     1186      }
     1187    }
     1188    if (bSkipTrailingExtensionBits)
     1189    {
     1190      while ( xMoreRbspData() )
     1191      {
     1192        READ_FLAG( uiCode, "sps_extension_data_flag");
     1193      }
     1194    }
     1195  }
     1196#endif
     1197  xReadRbspTrailingBits();
     1198}
     1199
     1200#if NH_MV
     1201Void TDecCavlc::parseSpsMultilayerExtension( TComSPS* pcSPS )
    9971202{
    9981203  UInt uiCode;
    999   READ_FLAG( uiCode, "inter_view_mv_vert_constraint_flag" );    pcSPS->setInterViewMvVertConstraintFlag(uiCode == 1 ? true : false);
    1000  
    1001 }
    1002 
    1003 #if H_3D
    1004 Void TDecCavlc::parseSPS3dExtension( TComSPS* pcSPS )
     1204  READ_FLAG( uiCode, "inter_view_mv_vert_constraint_flag" );    pcSPS->setInterViewMvVertConstraintFlag(uiCode == 1 ? true : false); 
     1205}
     1206
     1207#if NH_3D
     1208Void TDecCavlc::parseSps3dExtension( TComSPS* pcSPS )
    10051209{
    1006   TComSps3dExtension* sps3dExt = pcSPS->getSps3dExtension();
     1210  TComSps3dExtension sps3dExt;
    10071211  UInt uiCode;
    10081212  for( Int d = 0; d  <=  1; d++ )
    10091213  {
    1010     READ_FLAG( uiCode, "iv_mv_pred_flag" ); sps3dExt->setIvMvPredFlag( d, uiCode == 1 );
    1011     READ_FLAG( uiCode, "iv_mv_scaling_flag" ); sps3dExt->setIvMvScalingFlag( d, uiCode == 1 );
     1214    READ_FLAG( uiCode, "iv_mv_pred_flag" ); sps3dExt.setIvMvPredFlag( d, uiCode == 1 );
     1215    READ_FLAG( uiCode, "iv_mv_scaling_flag" ); sps3dExt.setIvMvScalingFlag( d, uiCode == 1 );
    10121216    if( d  ==  0 )
    10131217    {
    1014       READ_UVLC( uiCode, "log2_sub_pb_size_minus3" ); sps3dExt->setLog2SubPbSizeMinus3( d, uiCode );
    1015       READ_FLAG( uiCode, "iv_res_pred_flag" ); sps3dExt->setIvResPredFlag( d, uiCode == 1 );
    1016       READ_FLAG( uiCode, "depth_refinement_flag" ); sps3dExt->setDepthRefinementFlag( d, uiCode == 1 );
    1017       READ_FLAG( uiCode, "view_synthesis_pred_flag" ); sps3dExt->setViewSynthesisPredFlag( d, uiCode == 1 );
    1018       READ_FLAG( uiCode, "depth_based_blk_part_flag" ); sps3dExt->setDepthBasedBlkPartFlag( d, uiCode == 1 );
     1218      READ_UVLC( uiCode, "log2_sub_pb_size_minus3" ); sps3dExt.setLog2SubPbSizeMinus3( d, uiCode );
     1219      READ_FLAG( uiCode, "iv_res_pred_flag" ); sps3dExt.setIvResPredFlag( d, uiCode == 1 );
     1220      READ_FLAG( uiCode, "depth_refinement_flag" ); sps3dExt.setDepthRefinementFlag( d, uiCode == 1 );
     1221      READ_FLAG( uiCode, "view_synthesis_pred_flag" ); sps3dExt.setViewSynthesisPredFlag( d, uiCode == 1 );
     1222      READ_FLAG( uiCode, "depth_based_blk_part_flag" ); sps3dExt.setDepthBasedBlkPartFlag( d, uiCode == 1 );
    10191223    }
    10201224    else
    10211225    {
    1022       READ_FLAG( uiCode, "mpi_flag" ); sps3dExt->setMpiFlag( d, uiCode == 1 );
    1023       READ_UVLC( uiCode, "log2_mpi_sub_pb_size_minus3" ); sps3dExt->setLog2MpiSubPbSizeMinus3( d, uiCode );
    1024       READ_FLAG( uiCode, "intra_contour_flag" ); sps3dExt->setIntraContourFlag( d, uiCode == 1 );
    1025       READ_FLAG( uiCode, "intra_sdc_wedge_flag" ); sps3dExt->setIntraSdcWedgeFlag( d, uiCode == 1 );
    1026       READ_FLAG( uiCode, "qt_pred_flag" ); sps3dExt->setQtPredFlag( d, uiCode == 1 );
    1027       READ_FLAG( uiCode, "inter_sdc_flag" ); sps3dExt->setInterSdcFlag( d, uiCode == 1 );
    1028       READ_FLAG( uiCode, "intra_skip_flag" ); sps3dExt->setDepthIntraSkipFlag( d, uiCode == 1 );
    1029     }
    1030   }
    1031 }
    1032 #endif
    1033 
    1034 Void TDecCavlc::parsePPSMultilayerExtension(TComPPS* pcPPS)
     1226      READ_FLAG( uiCode, "mpi_flag" ); sps3dExt.setMpiFlag( d, uiCode == 1 );
     1227      READ_UVLC( uiCode, "log2_mpi_sub_pb_size_minus3" ); sps3dExt.setLog2MpiSubPbSizeMinus3( d, uiCode );
     1228      READ_FLAG( uiCode, "intra_contour_flag" ); sps3dExt.setIntraContourFlag( d, uiCode == 1 );
     1229      READ_FLAG( uiCode, "intra_sdc_wedge_flag" ); sps3dExt.setIntraSdcWedgeFlag( d, uiCode == 1 );
     1230      READ_FLAG( uiCode, "qt_pred_flag" ); sps3dExt.setQtPredFlag( d, uiCode == 1 );
     1231      READ_FLAG( uiCode, "inter_sdc_flag" ); sps3dExt.setInterSdcFlag( d, uiCode == 1 );
     1232      READ_FLAG( uiCode, "intra_skip_flag" ); sps3dExt.setDepthIntraSkipFlag( d, uiCode == 1 );
     1233    }
     1234  }
     1235  pcSPS->setSps3dExtension( sps3dExt );
     1236}
     1237#endif
     1238
     1239Void TDecCavlc::parsePpsMultilayerExtension(TComPPS* pcPPS)
    10351240{
    10361241  UInt uiCode = 0;
     
    10871292Void TDecCavlc::parseVPS(TComVPS* pcVPS)
    10881293{
     1294#if ENC_DEC_TRACE
     1295#if H_MV_ENC_DEC_TRAC
     1296  tracePSHeader( "VPS", getDecTop()->getLayerId() );
     1297#else
     1298  xTraceVPSHeader ();
     1299#endif
     1300#endif
     1301
    10891302  UInt  uiCode;
    1090  
     1303
    10911304  READ_CODE( 4,  uiCode,  "vps_video_parameter_set_id" );         pcVPS->setVPSId( uiCode );
    1092 #if H_MV
     1305#if NH_MV
    10931306  READ_FLAG( uiCode, "vps_base_layer_internal_flag" );            pcVPS->setVpsBaseLayerInternalFlag( uiCode == 1 );
    10941307  READ_FLAG( uiCode, "vps_base_layer_available_flag" );           pcVPS->setVpsBaseLayerAvailableFlag( uiCode == 1 );
    10951308#else
    1096   READ_CODE( 2,  uiCode,  "vps_reserved_three_2bits" );           assert(uiCode == 3);
    1097 #endif
    1098 #if H_MV
     1309  READ_FLAG( uiCode,      "vps_base_layer_internal_flag" );       assert(uiCode == 1);
     1310  READ_FLAG( uiCode,      "vps_base_layer_available_flag" );      assert(uiCode == 1);
     1311#endif
     1312#if NH_MV
    10991313  READ_CODE( 6,  uiCode,  "vps_max_layers_minus1" );              pcVPS->setMaxLayersMinus1( std::min( uiCode, (UInt) ( MAX_NUM_LAYER_IDS-1) )  );
    11001314#else
    1101   READ_CODE( 6,  uiCode,  "vps_reserved_zero_6bits" );            assert(uiCode == 0);
     1315  READ_CODE( 6,  uiCode,  "vps_max_layers_minus1" );
    11021316#endif
    11031317  READ_CODE( 3,  uiCode,  "vps_max_sub_layers_minus1" );          pcVPS->setMaxTLayers( uiCode + 1 );    assert(uiCode+1 <= MAX_TLAYER);
    11041318  READ_FLAG(     uiCode,  "vps_temporal_id_nesting_flag" );       pcVPS->setTemporalNestingFlag( uiCode ? true:false );
    11051319  assert (pcVPS->getMaxTLayers()>1||pcVPS->getTemporalNestingFlag());
    1106 
    1107   READ_CODE( 16, uiCode,  "vps_reserved_ffff_16bits" );           assert(uiCode == 0xffff);
     1320  READ_CODE( 16, uiCode,  "vps_reserved_0xffff_16bits" );         assert(uiCode == 0xffff);
    11081321  parsePTL ( pcVPS->getPTL(), true, pcVPS->getMaxTLayers()-1);
    1109 #if H_MV
     1322#if NH_MV
    11101323  pcVPS->getPTL()->inferGeneralValues ( true, 0, NULL );
    11111324  pcVPS->getPTL()->inferSubLayerValues( pcVPS->getMaxTLayers() - 1, 0, NULL );
     
    11151328  for(UInt i = 0; i <= pcVPS->getMaxTLayers()-1; i++)
    11161329  {
    1117     READ_UVLC( uiCode,  "vps_max_dec_pic_buffering_minus1[i]" );     pcVPS->setMaxDecPicBuffering( uiCode + 1, i );
    1118     READ_UVLC( uiCode,  "vps_num_reorder_pics[i]" );          pcVPS->setNumReorderPics( uiCode, i );
     1330    READ_UVLC( uiCode,  "vps_max_dec_pic_buffering_minus1[i]" );    pcVPS->setMaxDecPicBuffering( uiCode + 1, i );
     1331    READ_UVLC( uiCode,  "vps_max_num_reorder_pics[i]" );            pcVPS->setNumReorderPics( uiCode, i );
    11191332    READ_UVLC( uiCode,  "vps_max_latency_increase_plus1[i]" );      pcVPS->setMaxLatencyIncrease( uiCode, i );
    11201333
     
    11321345
    11331346  assert( pcVPS->getNumHrdParameters() < MAX_VPS_OP_SETS_PLUS1 );
    1134 #if H_MV
     1347#if NH_MV
    11351348  assert( pcVPS->getVpsMaxLayerId() < MAX_VPS_NUH_LAYER_ID_PLUS1 );
    11361349  READ_CODE( 6, uiCode, "vps_max_layer_id" );   pcVPS->setVpsMaxLayerId( uiCode );
     
    11421355#else
    11431356  assert( pcVPS->getMaxNuhReservedZeroLayerId() < MAX_VPS_NUH_RESERVED_ZERO_LAYER_ID_PLUS1 );
    1144   READ_CODE( 6, uiCode, "vps_max_nuh_reserved_zero_layer_id" );   pcVPS->setMaxNuhReservedZeroLayerId( uiCode );
    1145   READ_UVLC(    uiCode, "vps_max_op_sets_minus1" );               pcVPS->setMaxOpSets( uiCode + 1 );
     1357  READ_CODE( 6, uiCode, "vps_max_layer_id" );                        pcVPS->setMaxNuhReservedZeroLayerId( uiCode );
     1358  READ_UVLC(    uiCode, "vps_num_layer_sets_minus1" );               pcVPS->setMaxOpSets( uiCode + 1 );
    11461359  for( UInt opsIdx = 1; opsIdx <= ( pcVPS->getMaxOpSets() - 1 ); opsIdx ++ )
    11471360  {
     
    11501363#endif
    11511364    {
    1152       READ_FLAG( uiCode, "layer_id_included_flag[opsIdx][i]" );     pcVPS->setLayerIdIncludedFlag( uiCode == 1 ? true : false, opsIdx, i );
    1153     }
    1154   }
    1155 #if H_MV
     1365      READ_FLAG( uiCode, "layer_id_included_flag[opsIdx][i]" );   pcVPS->setLayerIdIncludedFlag( uiCode == 1 ? true : false, opsIdx, i );
     1366    }
     1367  }
     1368#if NH_MV
    11561369  pcVPS->deriveLayerSetLayerIdList();
    11571370#endif
     1371
    11581372  TimingInfo *timingInfo = pcVPS->getTimingInfo();
    11591373  READ_FLAG(       uiCode, "vps_timing_info_present_flag");         timingInfo->setTimingInfoPresentFlag      (uiCode ? true : false);
     
    11671381      READ_UVLC(   uiCode, "vps_num_ticks_poc_diff_one_minus1");    timingInfo->setNumTicksPocDiffOneMinus1   (uiCode);
    11681382    }
     1383
    11691384    READ_UVLC( uiCode, "vps_num_hrd_parameters" );                  pcVPS->setNumHrdParameters( uiCode );
    11701385
     
    11751390    for( UInt i = 0; i < pcVPS->getNumHrdParameters(); i ++ )
    11761391    {
    1177       READ_UVLC( uiCode, "hrd_op_set_idx" );                       pcVPS->setHrdOpSetIdx( uiCode, i );
     1392      READ_UVLC( uiCode, "hrd_layer_set_idx[i]" );                  pcVPS->setHrdOpSetIdx( uiCode, i );
    11781393      if( i > 0 )
    11791394      {
    1180         READ_FLAG( uiCode, "cprms_present_flag[i]" );              pcVPS->setCprmsPresentFlag( uiCode == 1 ? true : false, i );
     1395        READ_FLAG( uiCode, "cprms_present_flag[i]" );               pcVPS->setCprmsPresentFlag( uiCode == 1 ? true : false, i );
    11811396      }
    11821397      else
     
    11881403    }
    11891404  }
    1190 #if H_MV
     1405#if NH_MV
    11911406  READ_FLAG( uiCode,  "vps_extension_flag" );                      pcVPS->setVpsExtensionFlag( uiCode == 1 ? true : false );
    11921407  if ( pcVPS->getVpsExtensionFlag() )
     
    11961411#endif
    11971412  {
    1198 #if H_MV
     1413#if NH_MV
    11991414    m_pcBitstream->readOutTrailingBits();
    12001415    parseVPSExtension( pcVPS );   
     
    12021417    if (uiCode)
    12031418    {
    1204 #if H_3D
     1419#if NH_3D
    12051420      READ_FLAG( uiCode,  "vps_3d_extension_flag" );
    12061421      if ( uiCode )
     
    12081423        m_pcBitstream->readOutTrailingBits();
    12091424        pcVPS->createCamPars(pcVPS->getNumViews());
    1210         parseVPS3dExtension( pcVPS );   
     1425        parseVps3dExtension( pcVPS );   
    12111426      }
    12121427      READ_FLAG( uiCode,  "vps_extension3_flag" );
     
    12191434          READ_FLAG( uiCode, "vps_extension_data_flag");
    12201435        }
    1221 #if H_MV
    1222 #if H_3D
    1223       }
    1224 #endif
    1225     }
    1226 #endif
    1227   }
    1228   return;
    1229 }
    1230 
    1231 #if H_MV
     1436#if NH_MV
     1437#if NH_3D
     1438      }
     1439#endif
     1440    }
     1441#endif
     1442  }
     1443
     1444  xReadRbspTrailingBits();
     1445}
     1446
     1447#if NH_MV
    12321448Void TDecCavlc::parseVPSExtension( TComVPS* pcVPS )
    12331449{
     
    13061522  }
    13071523
    1308 #if H_3D
     1524#if NH_3D
    13091525  pcVPS->initViewCompLayer( );
    13101526#endif
     
    14411657  READ_UVLC( uiCode, "vps_num_rep_formats_minus1" ); pcVPS->setVpsNumRepFormatsMinus1( uiCode );
    14421658
     1659  std::vector<TComRepFormat> repFormats;
     1660  repFormats.resize( pcVPS->getVpsNumRepFormatsMinus1() + 1 );
    14431661  for (Int i = 0; i <= pcVPS->getVpsNumRepFormatsMinus1(); i++ )
    1444   {
    1445     assert( pcVPS->getRepFormat(i) == NULL );
    1446     TComRepFormat* curRepFormat = new TComRepFormat();
    1447     TComRepFormat* prevRepFormat = i > 0 ? pcVPS->getRepFormat( i - 1) : NULL;
    1448     parseRepFormat( i, curRepFormat ,  prevRepFormat);
    1449     pcVPS->setRepFormat(i, curRepFormat );
    1450   }
     1662  {     
     1663    TComRepFormat* curRepFormat = &repFormats[i];
     1664    TComRepFormat* prevRepFormat = i > 0 ? &repFormats[ i - 1] : NULL;
     1665    parseRepFormat( i, curRepFormat ,  prevRepFormat);     
     1666  }
     1667  pcVPS->setRepFormat( repFormats );
    14511668
    14521669  if ( pcVPS->getVpsNumRepFormatsMinus1() > 0 )
     
    15141731  }
    15151732  READ_FLAG( uiCode, "vps_vui_present_flag" );  pcVPS->setVpsVuiPresentFlag( uiCode == 1 );
     1733 
     1734  TComVPSVUI vpsVui;
    15161735  if( pcVPS->getVpsVuiPresentFlag() )
    15171736  {
    15181737    m_pcBitstream->readOutTrailingBits(); // vps_vui_alignment_bit_equal_to_one
    1519     parseVPSVUI( pcVPS );
     1738    parseVPSVUI( pcVPS, &vpsVui );
    15201739  }     
    15211740  else
    1522   {
    1523     TComVPSVUI* pcVPSVUI = pcVPS->getVPSVUI( );
    1524     assert( pcVPSVUI );
    1525     pcVPSVUI->inferVpsVui( false );
    1526   }
     1741  {   
     1742    // inference of syntax elements that differ from default inference (as done in constructor), when VPS VUI is not present   
     1743    vpsVui.setCrossLayerIrapAlignedFlag( false );
     1744  }
     1745  pcVPS->setVPSVUI( vpsVui );
    15271746  pcVPS->checkVPSExtensionSyntax();
    15281747}
    15291748
    1530 Void TDecCavlc::parseRepFormat( Int i, TComRepFormat* pcRepFormat, TComRepFormat* pcPrevRepFormat )
     1749Void TDecCavlc::parseRepFormat( Int i, TComRepFormat* pcRepFormat, const TComRepFormat* pcPrevRepFormat )
    15311750{
    15321751  assert( pcRepFormat );
     
    15521771  else
    15531772  {
    1554     pcRepFormat->inferChromaAndBitDepth(pcPrevRepFormat, false );
     1773    pcRepFormat->inferChromaAndBitDepth(pcPrevRepFormat );
    15551774  }
    15561775  READ_FLAG( uiCode, "conformance_window_vps_flag" ); pcRepFormat->setConformanceWindowVpsFlag( uiCode == 1 );
     
    15651784
    15661785
    1567 Void TDecCavlc::parseVPSVUI( TComVPS* pcVPS )
     1786Void TDecCavlc::parseVPSVUI( const TComVPS* pcVPS, TComVPSVUI* vpsVui )
    15681787{
    15691788  assert( pcVPS );
    1570 
    1571   TComVPSVUI* pcVPSVUI = pcVPS->getVPSVUI( );
    1572 
    1573   assert( pcVPSVUI );
     1789  assert( vpsVui );
     1790 
     1791  vpsVui->init(pcVPS->getNumAddLayerSets(),pcVPS->getMaxSubLayersMinus1() + 1, pcVPS->getMaxLayersMinus1() + 1 ); 
    15741792
    15751793  UInt uiCode;
    1576   READ_FLAG( uiCode, "cross_layer_pic_type_aligned_flag" ); pcVPSVUI->setCrossLayerPicTypeAlignedFlag( uiCode == 1 );
    1577   if ( !pcVPSVUI->getCrossLayerPicTypeAlignedFlag() )
     1794  READ_FLAG( uiCode, "cross_layer_pic_type_aligned_flag" ); vpsVui->setCrossLayerPicTypeAlignedFlag( uiCode == 1 );
     1795  if ( !vpsVui->getCrossLayerPicTypeAlignedFlag() )
    15781796  { 
    1579     READ_FLAG( uiCode, "cross_layer_irap_aligned_flag" ); pcVPSVUI->setCrossLayerIrapAlignedFlag( uiCode == 1 );
    1580   }
    1581   if( pcVPSVUI->getCrossLayerIrapAlignedFlag( ) )
    1582   {
    1583     READ_FLAG( uiCode, "all_layers_idr_aligned_flag" ); pcVPSVUI->setAllLayersIdrAlignedFlag( uiCode == 1 );
    1584   }
    1585   READ_FLAG( uiCode, "bit_rate_present_vps_flag" ); pcVPSVUI->setBitRatePresentVpsFlag( uiCode == 1 );
    1586   READ_FLAG( uiCode, "pic_rate_present_vps_flag" ); pcVPSVUI->setPicRatePresentVpsFlag( uiCode == 1 );
    1587   if( pcVPSVUI->getBitRatePresentVpsFlag( )  ||  pcVPSVUI->getPicRatePresentVpsFlag( ) )
     1797    READ_FLAG( uiCode, "cross_layer_irap_aligned_flag" ); vpsVui->setCrossLayerIrapAlignedFlag( uiCode == 1 );
     1798  }
     1799  if( vpsVui->getCrossLayerIrapAlignedFlag( ) )
     1800  {
     1801    READ_FLAG( uiCode, "all_layers_idr_aligned_flag" ); vpsVui->setAllLayersIdrAlignedFlag( uiCode == 1 );
     1802  }
     1803  READ_FLAG( uiCode, "bit_rate_present_vps_flag" ); vpsVui->setBitRatePresentVpsFlag( uiCode == 1 );
     1804  READ_FLAG( uiCode, "pic_rate_present_vps_flag" ); vpsVui->setPicRatePresentVpsFlag( uiCode == 1 );
     1805  if( vpsVui->getBitRatePresentVpsFlag( )  ||  vpsVui->getPicRatePresentVpsFlag( ) )
    15881806  {
    15891807    for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ? 0 : 1; i  <  pcVPS->getNumLayerSets(); i++ )
     
    15911809      for( Int j = 0; j  <=  pcVPS->getMaxSubLayersInLayerSetMinus1( i ); j++ )
    15921810      {
    1593         if( pcVPSVUI->getBitRatePresentVpsFlag( ) )
    1594         {
    1595           READ_FLAG( uiCode, "bit_rate_present_flag" ); pcVPSVUI->setBitRatePresentFlag( i, j, uiCode == 1 );           
    1596         }
    1597         if( pcVPSVUI->getPicRatePresentVpsFlag( )  )
    1598         {
    1599           READ_FLAG( uiCode, "pic_rate_present_flag" ); pcVPSVUI->setPicRatePresentFlag( i, j, uiCode == 1 );
    1600         }
    1601         if( pcVPSVUI->getBitRatePresentFlag( i, j ) )
    1602         {
    1603           READ_CODE( 16, uiCode, "avg_bit_rate" ); pcVPSVUI->setAvgBitRate( i, j, uiCode );
    1604           READ_CODE( 16, uiCode, "max_bit_rate" ); pcVPSVUI->setMaxBitRate( i, j, uiCode );
    1605         }
    1606         if( pcVPSVUI->getPicRatePresentFlag( i, j ) )
    1607         {
    1608           READ_CODE( 2,  uiCode, "constant_pic_rate_idc" ); pcVPSVUI->setConstantPicRateIdc( i, j, uiCode );
    1609           READ_CODE( 16, uiCode, "avg_pic_rate" );          pcVPSVUI->setAvgPicRate( i, j, uiCode );
    1610         }
    1611       }
    1612     }
    1613   }
    1614 
    1615   READ_FLAG( uiCode, "video_signal_info_idx_present_flag" ); pcVPSVUI->setVideoSignalInfoIdxPresentFlag( uiCode == 1 );
    1616   if( pcVPSVUI->getVideoSignalInfoIdxPresentFlag() )
    1617   {
    1618     READ_CODE( 4, uiCode, "vps_num_video_signal_info_minus1" ); pcVPSVUI->setVpsNumVideoSignalInfoMinus1( uiCode );
     1811        if( vpsVui->getBitRatePresentVpsFlag( ) )
     1812        {
     1813          READ_FLAG( uiCode, "bit_rate_present_flag" ); vpsVui->setBitRatePresentFlag( i, j, uiCode == 1 );           
     1814        }
     1815        if( vpsVui->getPicRatePresentVpsFlag( )  )
     1816        {
     1817          READ_FLAG( uiCode, "pic_rate_present_flag" ); vpsVui->setPicRatePresentFlag( i, j, uiCode == 1 );
     1818        }
     1819        if( vpsVui->getBitRatePresentFlag( i, j ) )
     1820        {
     1821          READ_CODE( 16, uiCode, "avg_bit_rate" ); vpsVui->setAvgBitRate( i, j, uiCode );
     1822          READ_CODE( 16, uiCode, "max_bit_rate" ); vpsVui->setMaxBitRate( i, j, uiCode );
     1823        }
     1824        if( vpsVui->getPicRatePresentFlag( i, j ) )
     1825        {
     1826          READ_CODE( 2,  uiCode, "constant_pic_rate_idc" ); vpsVui->setConstantPicRateIdc( i, j, uiCode );
     1827          READ_CODE( 16, uiCode, "avg_pic_rate" );          vpsVui->setAvgPicRate( i, j, uiCode );
     1828        }
     1829      }
     1830    }
     1831  }
     1832
     1833  READ_FLAG( uiCode, "video_signal_info_idx_present_flag" ); vpsVui->setVideoSignalInfoIdxPresentFlag( uiCode == 1 );
     1834  if( vpsVui->getVideoSignalInfoIdxPresentFlag() )
     1835  {
     1836    READ_CODE( 4, uiCode, "vps_num_video_signal_info_minus1" ); vpsVui->setVpsNumVideoSignalInfoMinus1( uiCode );
    16191837  }
    16201838  else
    16211839  {
    1622     pcVPSVUI->setVpsNumVideoSignalInfoMinus1( pcVPS->getMaxLayersMinus1() - pcVPS->getVpsBaseLayerInternalFlag() ? 0 : 1 );
    1623   }
    1624 
    1625   for( Int i = 0; i <= pcVPSVUI->getVpsNumVideoSignalInfoMinus1(); i++ )
    1626   {
    1627     assert( pcVPSVUI->getVideoSignalInfo( i ) == NULL );
    1628     TComVideoSignalInfo* curVideoSignalInfo = new TComVideoSignalInfo();     
    1629     parseVideoSignalInfo( curVideoSignalInfo );
    1630     pcVPSVUI->setVideoSignalInfo(i, curVideoSignalInfo );
    1631   }
    1632 
    1633   if( pcVPSVUI->getVideoSignalInfoIdxPresentFlag() && pcVPSVUI->getVpsNumVideoSignalInfoMinus1() > 0 )
     1840    vpsVui->setVpsNumVideoSignalInfoMinus1( (pcVPS->getMaxLayersMinus1() - pcVPS->getVpsBaseLayerInternalFlag()) ? 0 : 1 );
     1841  }
     1842
     1843  std::vector<TComVideoSignalInfo> videoSignalInfos;
     1844  videoSignalInfos.resize(vpsVui->getVpsNumVideoSignalInfoMinus1() + 1 );
     1845
     1846  for( Int i = 0; i <= vpsVui->getVpsNumVideoSignalInfoMinus1(); i++ )
     1847  {
     1848    parseVideoSignalInfo( &videoSignalInfos[i] );     
     1849  }
     1850  vpsVui->setVideoSignalInfo( videoSignalInfos );
     1851
     1852  if( vpsVui->getVideoSignalInfoIdxPresentFlag() && vpsVui->getVpsNumVideoSignalInfoMinus1() > 0 )
    16341853  {
    16351854    for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ? 0 : 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
    16361855    {
    1637       READ_CODE( 4, uiCode, "vps_video_signal_info_idx" ); pcVPSVUI->setVpsVideoSignalInfoIdx( i, uiCode );
    1638     }
    1639   }
    1640   else if ( !pcVPSVUI->getVideoSignalInfoIdxPresentFlag() )
     1856      READ_CODE( 4, uiCode, "vps_video_signal_info_idx" ); vpsVui->setVpsVideoSignalInfoIdx( i, uiCode );
     1857    }
     1858  }
     1859  else if ( !vpsVui->getVideoSignalInfoIdxPresentFlag() )
    16411860  {
    16421861    for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ? 0 : 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
    16431862    {
    1644       pcVPSVUI->setVpsVideoSignalInfoIdx( i, i );
     1863      vpsVui->setVpsVideoSignalInfoIdx( i, i );
    16451864    }
    16461865  }
     
    16491868    for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ? 0 : 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
    16501869    {
    1651       pcVPSVUI->setVpsVideoSignalInfoIdx( i, 0 );
    1652     }
    1653   }
    1654 
    1655   READ_FLAG( uiCode, "tiles_not_in_use_flag" ); pcVPSVUI->setTilesNotInUseFlag( uiCode == 1 );
    1656   if( !pcVPSVUI->getTilesNotInUseFlag() )
     1870      vpsVui->setVpsVideoSignalInfoIdx( i, 0 );
     1871    }
     1872  }
     1873
     1874  READ_FLAG( uiCode, "tiles_not_in_use_flag" ); vpsVui->setTilesNotInUseFlag( uiCode == 1 );
     1875  if( !vpsVui->getTilesNotInUseFlag() )
    16571876  {     
    16581877    for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ? 0 : 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
    16591878    {
    1660       READ_FLAG( uiCode, "tiles_in_use_flag[i]" ); pcVPSVUI->setTilesInUseFlag( i, uiCode == 1 );
    1661       if( pcVPSVUI->getTilesInUseFlag( i ) ) 
    1662       {
    1663         READ_FLAG( uiCode, "loop_filter_not_across_tiles_flag[i]" ); pcVPSVUI->setLoopFilterNotAcrossTilesFlag( i, uiCode == 1 );
     1879      READ_FLAG( uiCode, "tiles_in_use_flag[i]" ); vpsVui->setTilesInUseFlag( i, uiCode == 1 );
     1880      if( vpsVui->getTilesInUseFlag( i ) ) 
     1881      {
     1882        READ_FLAG( uiCode, "loop_filter_not_across_tiles_flag[i]" ); vpsVui->setLoopFilterNotAcrossTilesFlag( i, uiCode == 1 );
    16641883      }
    16651884    } 
     
    16691888      {
    16701889        Int layerIdx = pcVPS->getLayerIdInVps(pcVPS->getIdDirectRefLayer(pcVPS->getLayerIdInNuh( i ) , j  )); 
    1671         if( pcVPSVUI->getTilesInUseFlag( i )  &&  pcVPSVUI->getTilesInUseFlag( layerIdx ) ) 
    1672         {
    1673           READ_FLAG( uiCode, "tile_boundaries_aligned_flag[i][j]" ); pcVPSVUI->setTileBoundariesAlignedFlag( i, j, uiCode == 1 );
     1890        if( vpsVui->getTilesInUseFlag( i )  &&  vpsVui->getTilesInUseFlag( layerIdx ) ) 
     1891        {
     1892          READ_FLAG( uiCode, "tile_boundaries_aligned_flag[i][j]" ); vpsVui->setTileBoundariesAlignedFlag( i, j, uiCode == 1 );
    16741893        }
    16751894      } 
     
    16771896  } 
    16781897 
    1679   READ_FLAG( uiCode, "wpp_not_in_use_flag" ); pcVPSVUI->setWppNotInUseFlag( uiCode == 1 );
     1898  READ_FLAG( uiCode, "wpp_not_in_use_flag" ); vpsVui->setWppNotInUseFlag( uiCode == 1 );
    16801899 
    1681   if( !pcVPSVUI->getWppNotInUseFlag( ))
     1900  if( !vpsVui->getWppNotInUseFlag( ))
    16821901  {
    16831902    for( Int i = 0; i  <=  pcVPS->getMaxLayersMinus1(); i++ ) 
    16841903    {
    1685       READ_FLAG( uiCode, "wpp_in_use_flag[i]" ); pcVPSVUI->setWppInUseFlag( i, uiCode == 1 );
    1686     }
    1687   }
    1688   READ_FLAG( uiCode, "single_layer_for_non_irap_flag" ); pcVPSVUI->setSingleLayerForNonIrapFlag( uiCode == 1 );
    1689   READ_FLAG( uiCode, "higher_layer_irap_skip_flag" ); pcVPSVUI->setHigherLayerIrapSkipFlag( uiCode == 1 );
    1690   READ_FLAG( uiCode, "ilp_restricted_ref_layers_flag" ); pcVPSVUI->setIlpRestrictedRefLayersFlag( uiCode == 1 );
    1691 
    1692   if( pcVPSVUI->getIlpRestrictedRefLayersFlag( ) )
     1904      READ_FLAG( uiCode, "wpp_in_use_flag[i]" ); vpsVui->setWppInUseFlag( i, uiCode == 1 );
     1905    }
     1906  }
     1907  READ_FLAG( uiCode, "single_layer_for_non_irap_flag" ); vpsVui->setSingleLayerForNonIrapFlag( uiCode == 1 );
     1908  READ_FLAG( uiCode, "higher_layer_irap_skip_flag" ); vpsVui->setHigherLayerIrapSkipFlag( uiCode == 1 );
     1909  READ_FLAG( uiCode, "ilp_restricted_ref_layers_flag" ); vpsVui->setIlpRestrictedRefLayersFlag( uiCode == 1 );
     1910
     1911  if( vpsVui->getIlpRestrictedRefLayersFlag( ) )
    16931912  {
    16941913    for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
     
    16981917        if( pcVPS->getVpsBaseLayerInternalFlag() || pcVPS->getIdDirectRefLayer( pcVPS->getLayerIdInNuh( i ), j ) > 0 )
    16991918        {       
    1700           READ_UVLC( uiCode, "min_spatial_segment_offset_plus1" ); pcVPSVUI->setMinSpatialSegmentOffsetPlus1( i, j, uiCode );
    1701           if( pcVPSVUI->getMinSpatialSegmentOffsetPlus1( i, j ) > 0 )
     1919          READ_UVLC( uiCode, "min_spatial_segment_offset_plus1" ); vpsVui->setMinSpatialSegmentOffsetPlus1( i, j, uiCode );
     1920          if( vpsVui->getMinSpatialSegmentOffsetPlus1( i, j ) > 0 )
    17021921          {
    1703             READ_FLAG( uiCode, "ctu_based_offset_enabled_flag" ); pcVPSVUI->setCtuBasedOffsetEnabledFlag( i, j, uiCode == 1 );
    1704             if( pcVPSVUI->getCtuBasedOffsetEnabledFlag( i, j ) )
     1922            READ_FLAG( uiCode, "ctu_based_offset_enabled_flag" ); vpsVui->setCtuBasedOffsetEnabledFlag( i, j, uiCode == 1 );
     1923            if( vpsVui->getCtuBasedOffsetEnabledFlag( i, j ) )
    17051924            {
    1706               READ_UVLC( uiCode, "min_horizontal_ctu_offset_plus1" ); pcVPSVUI->setMinHorizontalCtuOffsetPlus1( i, j, uiCode );
     1925              READ_UVLC( uiCode, "min_horizontal_ctu_offset_plus1" ); vpsVui->setMinHorizontalCtuOffsetPlus1( i, j, uiCode );
    17071926            }
    17081927          }
     
    17121931  }
    17131932
    1714   READ_FLAG( uiCode, "vps_vui_bsp_hrd_present_flag" ); pcVPSVUI->setVpsVuiBspHrdPresentFlag( uiCode == 1 );
    1715   if ( pcVPSVUI->getVpsVuiBspHrdPresentFlag( ) )
    1716   {
    1717     assert(pcVPS->getTimingInfo()->getTimingInfoPresentFlag() == 1);
    1718     parseVpsVuiBspHrdParameters( pcVPS );
     1933  READ_FLAG( uiCode, "vps_vui_bsp_hrd_present_flag" ); vpsVui->setVpsVuiBspHrdPresentFlag( uiCode == 1 );
     1934  if ( vpsVui->getVpsVuiBspHrdPresentFlag( ) )
     1935  {
     1936    assert(pcVPS->getTimingInfo()->getTimingInfoPresentFlag() == 1);   
     1937    parseVpsVuiBspHrdParameters( pcVPS, vpsVui );   
    17191938  }
    17201939  for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
     
    17221941    if( pcVPS->getNumDirectRefLayers( pcVPS->getLayerIdInNuh( i )) == 0 )
    17231942    {
    1724       READ_FLAG( uiCode, "base_layer_parameter_set_compatibility_flag" ); pcVPSVUI->setBaseLayerParameterSetCompatibilityFlag( i, uiCode == 1 );
    1725     }
    1726   }
    1727 }
    1728 
    1729 Void TDecCavlc::parseVpsVuiBspHrdParameters( TComVPS* pcVPS )
    1730 {
    1731   assert( pcVPS );
    1732 
    1733   TComVPSVUI* pcVPSVUI = pcVPS->getVPSVUI( );
    1734 
    1735   assert( pcVPSVUI );
    1736 
    1737   TComVpsVuiBspHrdParameters*  vpsVuiBspHrdP = pcVPSVUI->getVpsVuiBspHrdParameters();
    1738   assert( vpsVuiBspHrdP == NULL );
    1739   vpsVuiBspHrdP = new TComVpsVuiBspHrdParameters;
    1740   pcVPSVUI->setVpsVuiBspHrdParameters( vpsVuiBspHrdP );
     1943      READ_FLAG( uiCode, "base_layer_parameter_set_compatibility_flag" ); vpsVui->setBaseLayerParameterSetCompatibilityFlag( i, uiCode == 1 );
     1944    }
     1945  } 
     1946}
     1947
     1948Void TDecCavlc::parseVpsVuiBspHrdParameters( const TComVPS* pcVPS, TComVPSVUI* vpsVui )
     1949{
     1950  assert( pcVPS  );
     1951  assert( vpsVui );
     1952
     1953  TComVpsVuiBspHrdParameters  vpsVuiBspHrdP;   
     1954 
    17411955  UInt uiCode;
    1742   READ_UVLC( uiCode, "vps_num_add_hrd_params" ); vpsVuiBspHrdP->setVpsNumAddHrdParams( uiCode );
    1743   vpsVuiBspHrdP->createAfterVpsNumAddHrdParams( pcVPS );
    1744   for( Int i = pcVPS->getNumHrdParameters(); i < pcVPS->getNumHrdParameters() + vpsVuiBspHrdP->getVpsNumAddHrdParams(); i++ )
     1956  READ_UVLC( uiCode, "vps_num_add_hrd_params" ); vpsVuiBspHrdP.setVpsNumAddHrdParams( uiCode );
     1957  vpsVuiBspHrdP.createAfterVpsNumAddHrdParams( pcVPS );
     1958  for( Int i = pcVPS->getNumHrdParameters(); i < pcVPS->getNumHrdParameters() + vpsVuiBspHrdP.getVpsNumAddHrdParams(); i++ )
    17451959  { 
    17461960    if( i > 0 ) 
    17471961    {
    1748       READ_FLAG( uiCode, "cprms_add_present_flag" ); vpsVuiBspHrdP->setCprmsAddPresentFlag( i, uiCode == 1 );
     1962      READ_FLAG( uiCode, "cprms_add_present_flag" ); vpsVuiBspHrdP.setCprmsAddPresentFlag( i, uiCode == 1 );
    17491963    }
    17501964    else
    17511965    {
    1752        vpsVuiBspHrdP->setCprmsAddPresentFlag( i, true );
    1753     }
    1754 
    1755     READ_UVLC( uiCode, "num_sub_layer_hrd_minus1" ); vpsVuiBspHrdP->setNumSubLayerHrdMinus1( i, uiCode );
    1756     TComHRD* hrdParameters = vpsVuiBspHrdP->getHrdParametermeters( i );
    1757     parseHrdParameters( hrdParameters, vpsVuiBspHrdP->getCprmsAddPresentFlag( i ), vpsVuiBspHrdP->getNumSubLayerHrdMinus1( i ) );     
    1758   }
    1759 
    1760   vpsVuiBspHrdP->setNumPartitionsInSchemeMinus1( 0, 0, 0);
    1761   vpsVuiBspHrdP->createAfterNumPartitionsInSchemeMinus1( 0, 0 );
     1966       vpsVuiBspHrdP.setCprmsAddPresentFlag( i, true );
     1967    }
     1968
     1969    READ_UVLC( uiCode, "num_sub_layer_hrd_minus1" ); vpsVuiBspHrdP.setNumSubLayerHrdMinus1( i, uiCode );
     1970   
     1971    TComHRD hrdParameters;
     1972    parseHrdParameters( &hrdParameters, vpsVuiBspHrdP.getCprmsAddPresentFlag( i ), vpsVuiBspHrdP.getNumSubLayerHrdMinus1( i ) );     
     1973    vpsVuiBspHrdP.setHrdParametermeters( i, hrdParameters );
     1974  }
     1975
     1976  vpsVuiBspHrdP.setNumPartitionsInSchemeMinus1( 0, 0, 0);
     1977  vpsVuiBspHrdP.createAfterNumPartitionsInSchemeMinus1( pcVPS, 0, 0 );
    17621978
    17631979  for( Int h = 0; h < pcVPS->getNumOutputLayerSets(); h++ )
     
    17651981    if ( h == 0)
    17661982    {
    1767       vpsVuiBspHrdP->setNumSignalledPartitioningSchemes( h, 0 );
     1983      vpsVuiBspHrdP.setNumSignalledPartitioningSchemes( h, 0 );
    17681984    }
    17691985    else
    17701986    {
    1771       READ_UVLC( uiCode, "num_signalled_partitioning_schemes" ); vpsVuiBspHrdP->setNumSignalledPartitioningSchemes( h, uiCode );
     1987      READ_UVLC( uiCode, "num_signalled_partitioning_schemes" ); vpsVuiBspHrdP.setNumSignalledPartitioningSchemes( h, uiCode );
    17721988    }   
    1773     vpsVuiBspHrdP->createAfterNumSignalledPartitioningSchemes( h );
    1774 
    1775     for( Int j = 0; j < vpsVuiBspHrdP->getNumSignalledPartitioningSchemes( h ) + 1; j++ )
     1989    vpsVuiBspHrdP.createAfterNumSignalledPartitioningSchemes( pcVPS, h );
     1990
     1991    for( Int j = 0; j < vpsVuiBspHrdP.getNumSignalledPartitioningSchemes( h ) + 1; j++ )
    17761992    {
    17771993      if ( j == 0 && h == 0 )
    17781994      {
    1779         vpsVuiBspHrdP->setNumPartitionsInSchemeMinus1( h, j, uiCode );
     1995        vpsVuiBspHrdP.setNumPartitionsInSchemeMinus1( h, j, uiCode );
    17801996      }
    17811997      else if( j == 0 )
    17821998      {
    1783         vpsVuiBspHrdP->setNumPartitionsInSchemeMinus1( h, j, pcVPS->getNumLayersInIdList( h ) - 1 );
     1999        vpsVuiBspHrdP.setNumPartitionsInSchemeMinus1( h, j, pcVPS->getNumLayersInIdList( h ) - 1 );
    17842000      }
    17852001      else
    17862002      {
    1787         READ_UVLC( uiCode, "num_partitions_in_scheme_minus1" ); vpsVuiBspHrdP->setNumPartitionsInSchemeMinus1( h, j, uiCode );
    1788       }
    1789       vpsVuiBspHrdP->createAfterNumPartitionsInSchemeMinus1( h, j );
    1790 
    1791       for( Int k = 0; k  <=  vpsVuiBspHrdP->getNumPartitionsInSchemeMinus1( h, j ); k++ ) 
     2003        READ_UVLC( uiCode, "num_partitions_in_scheme_minus1" ); vpsVuiBspHrdP.setNumPartitionsInSchemeMinus1( h, j, uiCode );
     2004      }
     2005      vpsVuiBspHrdP.createAfterNumPartitionsInSchemeMinus1(pcVPS, h, j );
     2006
     2007      for( Int k = 0; k  <=  vpsVuiBspHrdP.getNumPartitionsInSchemeMinus1( h, j ); k++ ) 
    17922008      {
    17932009        for( Int r = 0; r < pcVPS->getNumLayersInIdList(pcVPS->olsIdxToLsIdx( h ) )   ; r++ ) 
     
    17952011          if( h == 0 && j == 0 && k == 0 && r == 0 )
    17962012          {
    1797              vpsVuiBspHrdP->setLayerIncludedInPartitionFlag( h, j, k, r, true );
     2013             vpsVuiBspHrdP.setLayerIncludedInPartitionFlag( h, j, k, r, true );
    17982014          }
    17992015          else if ( h > 0 && j == 0 )
    18002016          {
    1801              vpsVuiBspHrdP->setLayerIncludedInPartitionFlag( h, j, k, r, (k == r) );
     2017             vpsVuiBspHrdP.setLayerIncludedInPartitionFlag( h, j, k, r, (k == r) );
    18022018          }
    18032019          else
    18042020          {
    1805             READ_FLAG( uiCode, "layer_included_in_partition_flag" ); vpsVuiBspHrdP->setLayerIncludedInPartitionFlag( h, j, k, r, uiCode == 1 );
     2021            READ_FLAG( uiCode, "layer_included_in_partition_flag" ); vpsVuiBspHrdP.setLayerIncludedInPartitionFlag( h, j, k, r, uiCode == 1 );
    18062022          }         
    18072023        }
     
    18102026    if ( h > 0 )
    18112027    {
    1812       for( Int i = 0; i < vpsVuiBspHrdP->getNumSignalledPartitioningSchemes( h ) + 1; i++ ) 
     2028      for( Int i = 0; i < vpsVuiBspHrdP.getNumSignalledPartitioningSchemes( h ) + 1; i++ ) 
    18132029      {
    18142030        for( Int t = 0; t  <=  pcVPS->getMaxSubLayersInLayerSetMinus1( pcVPS->olsIdxToLsIdx( i ) ); t++ )
    18152031        { 
    1816           READ_UVLC( uiCode, "num_bsp_schedules_minus1" ); vpsVuiBspHrdP->setNumBspSchedulesMinus1( h, i, t, uiCode );
    1817           vpsVuiBspHrdP->createAfterNumBspSchedulesMinus1( h, i, t );
    1818           for( Int j = 0; j  <=  vpsVuiBspHrdP->getNumBspSchedulesMinus1( h, i, t ); j++ ) 
     2032          READ_UVLC( uiCode, "num_bsp_schedules_minus1" ); vpsVuiBspHrdP.setNumBspSchedulesMinus1( h, i, t, uiCode );
     2033          vpsVuiBspHrdP.createAfterNumBspSchedulesMinus1(pcVPS, h, i, t );
     2034          for( Int j = 0; j  <=  vpsVuiBspHrdP.getNumBspSchedulesMinus1( h, i, t ); j++ ) 
    18192035          {
    1820             for( Int k = 0; k  <=  vpsVuiBspHrdP->getNumPartitionsInSchemeMinus1( h, j ); k++ )
     2036            for( Int k = 0; k  <=  vpsVuiBspHrdP.getNumPartitionsInSchemeMinus1( h, j ); k++ )
    18212037            { 
    1822               READ_CODE( vpsVuiBspHrdP->getBspHrdIdxLen( pcVPS ), uiCode, "bsp_hrd_idx" ); vpsVuiBspHrdP->setBspHrdIdx( h, i, t, j, k, uiCode );
    1823               READ_UVLC( uiCode, "bsp_sched_idx" ); vpsVuiBspHrdP->setBspSchedIdx( h, i, t, j, k, uiCode );
     2038              READ_CODE( vpsVuiBspHrdP.getBspHrdIdxLen( pcVPS ), uiCode, "bsp_hrd_idx" ); vpsVuiBspHrdP.setBspHrdIdx( h, i, t, j, k, uiCode );
     2039              READ_UVLC( uiCode, "bsp_sched_idx" ); vpsVuiBspHrdP.setBspSchedIdx( h, i, t, j, k, uiCode );
    18242040            } 
    18252041          }
     
    18282044    }
    18292045  } 
     2046  vpsVui->setVpsVuiBspHrdParameters( vpsVuiBspHrdP );
    18302047}
    18312048
     
    18432060{
    18442061  UInt uiCode;
    1845   TComDpbSize* dpbSize = vps->getDpbSize();
    1846   assert ( dpbSize != 0 );
     2062  TComDpbSize dpbSize;
     2063 
     2064  dpbSize.init( vps->getNumOutputLayerSets(), vps->getVpsMaxLayerId() + 1, vps->getMaxSubLayersMinus1() + 1 ) ;
    18472065
    18482066  for( Int i = 1; i < vps->getNumOutputLayerSets(); i++ )
    18492067  { 
    18502068    Int currLsIdx = vps->olsIdxToLsIdx( i );
    1851     READ_FLAG( uiCode, "sub_layer_flag_info_present_flag" ); dpbSize->setSubLayerFlagInfoPresentFlag( i, uiCode == 1 );
     2069    READ_FLAG( uiCode, "sub_layer_flag_info_present_flag" ); dpbSize.setSubLayerFlagInfoPresentFlag( i, uiCode == 1 );
    18522070    for( Int j = 0; j  <=  vps->getMaxSubLayersInLayerSetMinus1( currLsIdx ); j++ )
    18532071    { 
    1854       if( j > 0  &&  dpbSize->getSubLayerDpbInfoPresentFlag( i, j )  ) 
    1855       {
    1856         READ_FLAG( uiCode, "sub_layer_dpb_info_present_flag" ); dpbSize->setSubLayerDpbInfoPresentFlag( i, j, uiCode == 1 );
    1857       }
    1858       if( dpbSize->getSubLayerDpbInfoPresentFlag( i, j ) )
     2072      if( j > 0  &&  dpbSize.getSubLayerDpbInfoPresentFlag( i, j )  ) 
     2073      {
     2074        READ_FLAG( uiCode, "sub_layer_dpb_info_present_flag" ); dpbSize.setSubLayerDpbInfoPresentFlag( i, j, uiCode == 1 );
     2075      }
     2076      if( dpbSize.getSubLayerDpbInfoPresentFlag( i, j ) )
    18592077      { 
    18602078        for( Int k = 0; k < vps->getNumLayersInIdList( currLsIdx ); k++ )   
     
    18622080          if ( vps->getNecessaryLayerFlag( i, k ) && ( vps->getVpsBaseLayerInternalFlag() || ( vps->getLayerSetLayerIdList(vps->olsIdxToLsIdx(i),k) != 0 ) ))
    18632081          {
    1864             READ_UVLC( uiCode, "max_vps_dec_pic_buffering_minus1" ); dpbSize->setMaxVpsDecPicBufferingMinus1( i, k, j, uiCode );
     2082            READ_UVLC( uiCode, "max_vps_dec_pic_buffering_minus1" ); dpbSize.setMaxVpsDecPicBufferingMinus1( i, k, j, uiCode );
    18652083          }
    18662084          else
     
    18682086            if ( vps->getNecessaryLayerFlag( i, k ) && ( j == 0 ) && ( k == 0 ))
    18692087            {
    1870               dpbSize->setMaxVpsDecPicBufferingMinus1(i ,k, j, 0 );
     2088              dpbSize.setMaxVpsDecPicBufferingMinus1(i ,k, j, 0 );
    18712089            }
    18722090          }
    18732091        }
    1874         READ_UVLC( uiCode, "max_vps_num_reorder_pics" ); dpbSize->setMaxVpsNumReorderPics( i, j, uiCode );
    1875         READ_UVLC( uiCode, "max_vps_latency_increase_plus1" ); dpbSize->setMaxVpsLatencyIncreasePlus1( i, j, uiCode );
     2092        READ_UVLC( uiCode, "max_vps_num_reorder_pics" ); dpbSize.setMaxVpsNumReorderPics( i, j, uiCode );
     2093        READ_UVLC( uiCode, "max_vps_latency_increase_plus1" ); dpbSize.setMaxVpsLatencyIncreasePlus1( i, j, uiCode );
    18762094      }
    18772095      else
     
    18832101            if ( vps->getNecessaryLayerFlag(i, k ) )
    18842102            {           
    1885               dpbSize->setMaxVpsDecPicBufferingMinus1( i, k, j, dpbSize->getMaxVpsDecPicBufferingMinus1( i,k, j - 1 ) );
     2103              dpbSize.setMaxVpsDecPicBufferingMinus1( i, k, j, dpbSize.getMaxVpsDecPicBufferingMinus1( i,k, j - 1 ) );
    18862104            }
    18872105          }
    1888           dpbSize->setMaxVpsNumReorderPics      ( i, j, dpbSize->getMaxVpsNumReorderPics      ( i, j - 1 ) );
    1889           dpbSize->setMaxVpsLatencyIncreasePlus1( i, j, dpbSize->getMaxVpsLatencyIncreasePlus1( i, j - 1 ) );
     2106          dpbSize.setMaxVpsNumReorderPics      ( i, j, dpbSize.getMaxVpsNumReorderPics      ( i, j - 1 ) );
     2107          dpbSize.setMaxVpsLatencyIncreasePlus1( i, j, dpbSize.getMaxVpsLatencyIncreasePlus1( i, j - 1 ) );
    18902108        }
    18912109      }
    18922110    } 
    18932111  } 
    1894 }
    1895 
    1896 #if H_3D
    1897 Void TDecCavlc::parseVPS3dExtension( TComVPS* pcVPS )
     2112  vps->setDpbSize( dpbSize );
     2113}
     2114
     2115#if NH_3D
     2116Void TDecCavlc::parseVps3dExtension( TComVPS* pcVPS )
    18982117{
    18992118  UInt uiCode;   
     
    19292148#endif
    19302149#endif
    1931 #if H_MV
    1932 Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager, Int targetOlsIdx)
    1933 #else
    1934 Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager)
    1935 #endif
     2150
     2151Void TDecCavlc::parseSliceHeader (TComSlice* pcSlice, ParameterSetManager *parameterSetManager, const Int prevTid0POC)
    19362152{
    19372153  UInt  uiCode;
     
    19392155
    19402156#if ENC_DEC_TRACE
    1941   xTraceSliceHeader(rpcSlice);
     2157#if NH_MV
     2158  tracePSHeader( "Slice", pcSlice->getLayerId() );
     2159#else
     2160  xTraceSliceHeader();
     2161#endif
    19422162#endif
    19432163  TComPPS* pps = NULL;
    19442164  TComSPS* sps = NULL;
    1945 #if H_MV
     2165#if NH_MV
    19462166  TComVPS* vps = NULL;
    19472167#endif
     
    19492169  UInt firstSliceSegmentInPic;
    19502170  READ_FLAG( firstSliceSegmentInPic, "first_slice_segment_in_pic_flag" );
    1951   if( rpcSlice->getRapPicFlag())
    1952   { 
     2171  if( pcSlice->getRapPicFlag())
     2172  {
    19532173    READ_FLAG( uiCode, "no_output_of_prior_pics_flag" );  //ignored -- updated already
    1954 #if SETTING_NO_OUT_PIC_PRIOR
    1955     rpcSlice->setNoOutputPriorPicsFlag(uiCode ? true : false);
    1956 #else
    1957     rpcSlice->setNoOutputPicPrior( false );
    1958 #endif
    1959   }
    1960 
    1961   READ_UVLC (    uiCode, "slice_pic_parameter_set_id" );  rpcSlice->setPPSId(uiCode);
    1962   pps = parameterSetManager->getPrefetchedPPS(uiCode);
     2174    pcSlice->setNoOutputPriorPicsFlag(uiCode ? true : false);
     2175  }
     2176  READ_UVLC (    uiCode, "slice_pic_parameter_set_id" );  pcSlice->setPPSId(uiCode);
     2177  pps = parameterSetManager->getPPS(uiCode);
    19632178  //!KS: need to add error handling code here, if PPS is not available
    19642179  assert(pps!=0);
    1965   sps = parameterSetManager->getPrefetchedSPS(pps->getSPSId());
     2180  sps = parameterSetManager->getSPS(pps->getSPSId());
    19662181  //!KS: need to add error handling code here, if SPS is not available
    19672182  assert(sps!=0);
    1968 #if H_MV
    1969   vps = parameterSetManager->getPrefetchedVPS(sps->getVPSId());
    1970   assert( vps != NULL );
    1971  
    1972   sps->inferRepFormat  ( vps , rpcSlice->getLayerId() );
     2183#if NH_MV 
     2184  vps = parameterSetManager->getVPS(sps->getVPSId());
     2185  assert( vps != NULL ); 
     2186  m_decTop->initFromActiveVps( vps );
     2187  Int targetOlsIdx = m_decTop->getTargetOlsIdx();
     2188
     2189  // Do inference
     2190  sps->inferRepFormat  ( vps , pcSlice->getLayerId(), false );
    19732191  sps->inferScalingList( parameterSetManager->getActiveSPS( sps->getSpsScalingListRefLayerId() ) );   
    1974   sps->inferSpsMaxDecPicBufferingMinus1( vps, targetOlsIdx, rpcSlice->getLayerId(), false );
     2192  sps->inferSpsMaxDecPicBufferingMinus1( vps, targetOlsIdx, pcSlice->getLayerId(), false );
     2193
     2194  if( sps->getMultiLayerExtSpsFlag() )
     2195  {
     2196    sps->setTemporalIdNestingFlag( (sps->getMaxTLayers() > 1) ? vps->getTemporalNestingFlag() : true );
     2197  }
    19752198
    19762199  if ( sps->getVuiParametersPresentFlag() )
    19772200  {
    1978     sps->getVuiParameters()->inferVideoSignalInfo( vps, rpcSlice->getLayerId() );
    1979   }
    1980   rpcSlice->setVPS(vps);     
    1981   rpcSlice->setViewId   ( vps->getViewId   ( rpcSlice->getLayerId() )      );
    1982   rpcSlice->setViewIndex( vps->getViewIndex( rpcSlice->getLayerId() )      ); 
    1983 #if H_3D 
    1984   rpcSlice->setIsDepth  ( vps->getDepthId  ( rpcSlice->getLayerId() ) == 1 );
    1985 #endif
    1986 #endif
    1987   rpcSlice->setSPS(sps);
    1988   rpcSlice->setPPS(pps);
     2201    sps->getVuiParameters()->inferVideoSignalInfo( vps, pcSlice->getLayerId() );
     2202  }
     2203
     2204
     2205  pcSlice->setVPS(vps);     
     2206  pcSlice->setSPS(sps);
     2207  pcSlice->setPPS(pps);
     2208
     2209  pcSlice->setViewId   ( vps->getViewId   ( pcSlice->getLayerId() )      );
     2210  pcSlice->setViewIndex( vps->getViewIndex( pcSlice->getLayerId() )      ); 
     2211#if NH_3D
     2212  pcSlice->setIsDepth  ( vps->getDepthId  ( pcSlice->getLayerId() ) == 1 );
     2213#endif
     2214#endif
     2215
     2216  const ChromaFormat chFmt = sps->getChromaFormatIdc();
     2217  const UInt numValidComp=getNumberValidComponents(chFmt);
     2218  const Bool bChroma=(chFmt!=CHROMA_400);
     2219
    19892220  if( pps->getDependentSliceSegmentsEnabledFlag() && ( !firstSliceSegmentInPic ))
    19902221  {
    1991     READ_FLAG( uiCode, "dependent_slice_segment_flag" );       rpcSlice->setDependentSliceSegmentFlag(uiCode ? true : false);
     2222    READ_FLAG( uiCode, "dependent_slice_segment_flag" );       pcSlice->setDependentSliceSegmentFlag(uiCode ? true : false);
    19922223  }
    19932224  else
    19942225  {
    1995     rpcSlice->setDependentSliceSegmentFlag(false);
     2226    pcSlice->setDependentSliceSegmentFlag(false);
    19962227  }
    19972228  Int numCTUs = ((sps->getPicWidthInLumaSamples()+sps->getMaxCUWidth()-1)/sps->getMaxCUWidth())*((sps->getPicHeightInLumaSamples()+sps->getMaxCUHeight()-1)/sps->getMaxCUHeight());
    1998   Int maxParts = (1<<(sps->getMaxCUDepth()<<1));
    19992229  UInt sliceSegmentAddress = 0;
    20002230  Int bitsSliceSegmentAddress = 0;
     
    20092239  }
    20102240  //set uiCode to equal slice start address (or dependent slice start address)
    2011   Int startCuAddress = maxParts*sliceSegmentAddress;
    2012   rpcSlice->setSliceSegmentCurStartCUAddr( startCuAddress );
    2013   rpcSlice->setSliceSegmentCurEndCUAddr(numCTUs*maxParts);
    2014 
    2015   if (rpcSlice->getDependentSliceSegmentFlag())
    2016   {
    2017     rpcSlice->setNextSlice          ( false );
    2018     rpcSlice->setNextSliceSegment ( true  );
    2019   }
    2020   else
    2021   {
    2022     rpcSlice->setNextSlice          ( true  );
    2023     rpcSlice->setNextSliceSegment ( false );
    2024 
    2025     rpcSlice->setSliceCurStartCUAddr(startCuAddress);
    2026     rpcSlice->setSliceCurEndCUAddr(numCTUs*maxParts);
    2027   }
    2028  
    2029 #if H_MV
     2241  pcSlice->setSliceSegmentCurStartCtuTsAddr( sliceSegmentAddress );// this is actually a Raster-Scan (RS) address, but we do not have the RS->TS conversion table defined yet.
     2242  pcSlice->setSliceSegmentCurEndCtuTsAddr(numCTUs);                // Set end as the last CTU of the picture.
     2243
     2244#if NH_MV
    20302245    UInt slicePicOrderCntLsb = 0;
    20312246#endif
    20322247
    2033   if(!rpcSlice->getDependentSliceSegmentFlag())
    2034   {
    2035 #if H_MV   
     2248
     2249  if (!pcSlice->getDependentSliceSegmentFlag())
     2250  {
     2251    pcSlice->setSliceCurStartCtuTsAddr(sliceSegmentAddress); // this is actually a Raster-Scan (RS) address, but we do not have the RS->TS conversion table defined yet.
     2252    pcSlice->setSliceCurEndCtuTsAddr(numCTUs);
     2253  }
     2254
     2255  if(!pcSlice->getDependentSliceSegmentFlag())
     2256  {
     2257#if NH_MV   
    20362258    Int esb = 0; //Don't use i, otherwise will shadow something below
    20372259
    2038     if ( rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > esb )
     2260    if ( pps->getNumExtraSliceHeaderBits() > esb )
    20392261    {
    20402262      esb++;
    2041       READ_FLAG( uiCode, "discardable_flag" ); rpcSlice->setDiscardableFlag( uiCode == 1 );
     2263      READ_FLAG( uiCode, "discardable_flag" ); pcSlice->setDiscardableFlag( uiCode == 1 );
    20422264      if ( uiCode == 1 )
    20432265      {
    2044         assert(rpcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_TRAIL_R &&
    2045           rpcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_TSA_R &&
    2046           rpcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_STSA_R &&
    2047           rpcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_RADL_R &&
    2048           rpcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_RASL_R);
    2049       }
    2050     }
    2051 
    2052     if ( rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > esb )
     2266        assert(pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_TRAIL_R &&
     2267          pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_TSA_R &&
     2268          pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_STSA_R &&
     2269          pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_RADL_R &&
     2270          pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_RASL_R);
     2271      }
     2272    }
     2273
     2274    if ( pps->getNumExtraSliceHeaderBits() > esb )
    20532275    {
    20542276      esb++;
    2055       READ_FLAG( uiCode, "cross_layer_bla_flag" ); rpcSlice->setCrossLayerBlaFlag( uiCode == 1 );
    2056     }
    2057     rpcSlice->checkCrossLayerBlaFlag( );
    2058 
    2059 
    2060     for (; esb < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); esb++)   
     2277      READ_FLAG( uiCode, "cross_layer_bla_flag" ); pcSlice->setCrossLayerBlaFlag( uiCode == 1 );
     2278    }
     2279    pcSlice->checkCrossLayerBlaFlag( );
     2280
     2281
     2282    for (; esb < pps->getNumExtraSliceHeaderBits(); esb++)   
    20612283#else
    2062     for (Int i = 0; i < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
    2063 #endif     
    2064     {
    2065       READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
    2066     }
    2067 
    2068     READ_UVLC (    uiCode, "slice_type" );            rpcSlice->setSliceType((SliceType)uiCode);
     2284    for (Int i = 0; i < pps->getNumExtraSliceHeaderBits(); i++)
     2285#endif
     2286    {
     2287      READ_FLAG(uiCode, "slice_reserved_flag[]"); // ignored
     2288    }
     2289
     2290    READ_UVLC (    uiCode, "slice_type" );            pcSlice->setSliceType((SliceType)uiCode);
    20692291    if( pps->getOutputFlagPresentFlag() )
    20702292    {
    2071       READ_FLAG( uiCode, "pic_output_flag" );    rpcSlice->setPicOutputFlag( uiCode ? true : false );
     2293      READ_FLAG( uiCode, "pic_output_flag" );    pcSlice->setPicOutputFlag( uiCode ? true : false );
    20722294    }
    20732295    else
    20742296    {
    2075       rpcSlice->setPicOutputFlag( true );
    2076     }
    2077     // in the first version chroma_format_idc is equal to one, thus colour_plane_id will not be present
    2078 
    2079 #if H_3D_DISABLE_CHROMA
    2080     assert (sps->getChromaFormatIdc() == 1 || rpcSlice->getIsDepth() );
    2081     assert (sps->getChromaFormatIdc() == 0 || !rpcSlice->getIsDepth() );
    2082 #else
    2083     assert (sps->getChromaFormatIdc() == 1 );
    2084 #endif
    2085     // if( separate_colour_plane_flag  ==  1 )
    2086     //   colour_plane_id                                      u(2)
    2087 
    2088 
    2089 #if H_MV
     2297      pcSlice->setPicOutputFlag( true );
     2298    }
     2299
     2300    // if (separate_colour_plane_flag == 1)
     2301    //   read colour_plane_id
     2302    //   (separate_colour_plane_flag == 1) is not supported in this version of the standard.
     2303
     2304#if NH_MV
    20902305    Int iPOClsb = slicePicOrderCntLsb;  // Needed later
    2091     if ( (rpcSlice->getLayerId() > 0 && !vps->getPocLsbNotPresentFlag( rpcSlice->getLayerIdInVps())) || !rpcSlice->getIdrPicFlag() )
     2306    if ( (pcSlice->getLayerId() > 0 && !vps->getPocLsbNotPresentFlag( pcSlice->getLayerIdInVps())) || !pcSlice->getIdrPicFlag() )
    20922307    {
    20932308      READ_CODE(sps->getBitsForPOC(), slicePicOrderCntLsb, "slice_pic_order_cnt_lsb");       
    20942309    }   
    2095     rpcSlice->setSlicePicOrderCntLsb( slicePicOrderCntLsb );
     2310    pcSlice->setSlicePicOrderCntLsb( slicePicOrderCntLsb );
    20962311
    20972312    Bool picOrderCntMSBZeroFlag = false;     
    20982313
    20992314    // as in HM code. However are all cases for IRAP picture with NoRaslOutputFlag equal to 1 covered??
    2100     picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag || ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP   );
    2101     picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag || ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL );
    2102     picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag || ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP   );
    2103     picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag ||   rpcSlice->getIdrPicFlag();
     2315    picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag || ( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP   );
     2316    picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag || ( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL );
     2317    picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag || ( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP   );
     2318    picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag ||   pcSlice->getIdrPicFlag();
    21042319
    21052320    // TBD picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag || ( rpcSlice->getLayerId() > 0 &&   !rpcSlice->getFirstPicInLayerDecodedFlag() );
     
    21092324    if ( !picOrderCntMSBZeroFlag )
    21102325    {
    2111       Int prevPicOrderCnt    = rpcSlice->getPrevTid0POC();
     2326      Int prevPicOrderCnt    = prevTid0POC;
    21122327      Int maxPicOrderCntLsb  = 1 << sps->getBitsForPOC();
    21132328      Int prevPicOrderCntLsb = prevPicOrderCnt & (maxPicOrderCntLsb - 1);
     
    21282343    }
    21292344     
    2130     rpcSlice->setPOC( picOrderCntMSB + slicePicOrderCntLsb );
    2131     if ( rpcSlice->getPocResetFlag() ) 
    2132     {
    2133       rpcSlice->setPocBeforeReset   ( rpcSlice->getPOC() );
    2134       rpcSlice->setPOC              ( 0 );
     2345    pcSlice->setPOC( picOrderCntMSB + slicePicOrderCntLsb );
     2346    if ( pcSlice->getPocResetFlag() ) 
     2347    {
     2348      pcSlice->setPocBeforeReset   ( pcSlice->getPOC() );
     2349      pcSlice->setPOC              ( 0 );
    21352350    }     
    21362351#endif
    21372352
    2138     if( rpcSlice->getIdrPicFlag() )
    2139     {
    2140 #if !H_MV
    2141       rpcSlice->setPOC(0);
    2142 #endif
    2143       TComReferencePictureSet* rps = rpcSlice->getLocalRPS();
    2144       rps->setNumberOfNegativePictures(0);
    2145       rps->setNumberOfPositivePictures(0);
    2146       rps->setNumberOfLongtermPictures(0);
    2147       rps->setNumberOfPictures(0);
    2148       rpcSlice->setRPS(rps);
    2149 #if H_MV
    2150       rpcSlice->setEnableTMVPFlag(false);
     2353    if( pcSlice->getIdrPicFlag() )
     2354    {
     2355#if !NH_MV
     2356      pcSlice->setPOC(0);
     2357#endif
     2358      TComReferencePictureSet* rps = pcSlice->getLocalRPS();
     2359      (*rps)=TComReferencePictureSet();
     2360      pcSlice->setRPS(rps);
     2361#if NH_MV
     2362      pcSlice->setEnableTMVPFlag(false);
    21512363#endif
    21522364    }
    21532365    else
    21542366    {
    2155 #if !H_MV
    2156       READ_CODE(sps->getBitsForPOC(), uiCode, "pic_order_cnt_lsb"); 
     2367#if !NH_MV
     2368      READ_CODE(sps->getBitsForPOC(), uiCode, "slice_pic_order_cnt_lsb");
    21572369      Int iPOClsb = uiCode;
    2158       Int iPrevPOC = rpcSlice->getPrevTid0POC();
     2370      Int iPrevPOC = prevTid0POC;
    21592371      Int iMaxPOClsb = 1<< sps->getBitsForPOC();
    21602372      Int iPrevPOClsb = iPrevPOC & (iMaxPOClsb - 1);
     
    21652377        iPOCmsb = iPrevPOCmsb + iMaxPOClsb;
    21662378      }
    2167       else if( (iPOClsb  >  iPrevPOClsb )  && ( (iPOClsb - iPrevPOClsb )  >  ( iMaxPOClsb / 2 ) ) ) 
     2379      else if( (iPOClsb  >  iPrevPOClsb )  && ( (iPOClsb - iPrevPOClsb )  >  ( iMaxPOClsb / 2 ) ) )
    21682380      {
    21692381        iPOCmsb = iPrevPOCmsb - iMaxPOClsb;
     
    21732385        iPOCmsb = iPrevPOCmsb;
    21742386      }
    2175       if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
    2176         || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
    2177         || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
     2387      if ( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
     2388        || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
     2389        || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
    21782390      {
    21792391        // For BLA picture types, POCmsb is set to 0.
    21802392        iPOCmsb = 0;
    21812393      }
    2182       rpcSlice->setPOC              (iPOCmsb+iPOClsb);
     2394      pcSlice->setPOC              (iPOCmsb+iPOClsb);
    21832395#endif
    21842396      TComReferencePictureSet* rps;
    2185       rps = rpcSlice->getLocalRPS();
    2186       rpcSlice->setRPS(rps);
     2397      rps = pcSlice->getLocalRPS();
     2398      (*rps)=TComReferencePictureSet();
     2399
     2400      pcSlice->setRPS(rps);
    21872401      READ_FLAG( uiCode, "short_term_ref_pic_set_sps_flag" );
    21882402      if(uiCode == 0) // use short-term reference picture set explicitly signalled in slice header
    2189       {       
     2403      {
    21902404        parseShortTermRefPicSet(sps,rps, sps->getRPSList()->getNumberOfReferencePictureSets());
    2191 #if H_MV
     2405#if NH_MV
    21922406        if ( !rps->getInterRPSPrediction( ) )
    21932407        { // check sum of num_positive_pics and num_negative_pics
     
    21952409            vps->getVpsExtensionFlag(),
    21962410            MAX_INT,  // To be replaced by MaxDbpSize
    2197             rpcSlice->getLayerId(),
     2411            pcSlice->getLayerId(),
    21982412            sps->getMaxDecPicBuffering( sps->getSpsMaxSubLayersMinus1() ) - 1 );
    21992413        }
    22002414#endif
     2415
    22012416      }
    22022417      else // use reference to short-term reference picture set in PPS
    22032418      {
    22042419        Int numBits = 0;
    2205         while ((1 << numBits) < rpcSlice->getSPS()->getRPSList()->getNumberOfReferencePictureSets())
     2420        while ((1 << numBits) < sps->getRPSList()->getNumberOfReferencePictureSets())
    22062421        {
    22072422          numBits++;
     
    22142429        {
    22152430          uiCode = 0;
     2431       
    22162432        }
    22172433        *rps = *(sps->getRPSList()->getReferencePictureSet(uiCode));
     
    22222438        UInt numOfLtrp = 0;
    22232439        UInt numLtrpInSPS = 0;
    2224         if (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > 0)
     2440        if (sps->getNumLongTermRefPicSPS() > 0)
    22252441        {
    22262442          READ_UVLC( uiCode, "num_long_term_sps");
     
    22302446        }
    22312447        Int bitsForLtrpInSPS = 0;
    2232         while (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > (1 << bitsForLtrpInSPS))
     2448        while (sps->getNumLongTermRefPicSPS() > (1 << bitsForLtrpInSPS))
    22332449        {
    22342450          bitsForLtrpInSPS++;
     
    22372453        numOfLtrp += uiCode;
    22382454        rps->setNumberOfLongtermPictures(numOfLtrp);
    2239         Int maxPicOrderCntLSB = 1 << rpcSlice->getSPS()->getBitsForPOC();
    2240         Int prevDeltaMSB = 0, deltaPocMSBCycleLT = 0;;
     2455        Int maxPicOrderCntLSB = 1 << sps->getBitsForPOC();
     2456        Int prevDeltaMSB = 0, deltaPocMSBCycleLT = 0;
    22412457        for(Int j=offset+rps->getNumberOfLongtermPictures()-1, k = 0; k < numOfLtrp; j--, k++)
    22422458        {
     
    22492465              READ_CODE(bitsForLtrpInSPS, uiCode, "lt_idx_sps[i]");
    22502466            }
    2251             Int usedByCurrFromSPS=rpcSlice->getSPS()->getUsedByCurrPicLtSPSFlag(uiCode);
    2252 
    2253             pocLsbLt = rpcSlice->getSPS()->getLtRefPicPocLsbSps(uiCode);
     2467            Bool usedByCurrFromSPS=sps->getUsedByCurrPicLtSPSFlag(uiCode);
     2468
     2469            pocLsbLt = sps->getLtRefPicPocLsbSps(uiCode);
    22542470            rps->setUsed(j,usedByCurrFromSPS);
    22552471          }
    22562472          else
    22572473          {
    2258             READ_CODE(rpcSlice->getSPS()->getBitsForPOC(), uiCode, "poc_lsb_lt"); pocLsbLt= uiCode;
     2474            READ_CODE(sps->getBitsForPOC(), uiCode, "poc_lsb_lt"); pocLsbLt= uiCode;
    22592475            READ_FLAG( uiCode, "used_by_curr_pic_lt_flag");     rps->setUsed(j,uiCode);
    22602476          }
    22612477          READ_FLAG(uiCode,"delta_poc_msb_present_flag");
    22622478          Bool mSBPresentFlag = uiCode ? true : false;
    2263           if(mSBPresentFlag)                 
     2479          if(mSBPresentFlag)
    22642480          {
    22652481            READ_UVLC( uiCode, "delta_poc_msb_cycle_lt[i]" );
     
    22762492            else
    22772493            {
    2278               deltaPocMSBCycleLT = uiCode + prevDeltaMSB;             
     2494              deltaPocMSBCycleLT = uiCode + prevDeltaMSB;
    22792495            }
    22802496
    2281             Int pocLTCurr = rpcSlice->getPOC() - deltaPocMSBCycleLT * maxPicOrderCntLSB
     2497            Int pocLTCurr = pcSlice->getPOC() - deltaPocMSBCycleLT * maxPicOrderCntLSB
    22822498                                        - iPOClsb + pocLsbLt;
    2283             rps->setPOC     (j, pocLTCurr); 
    2284             rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLTCurr);
    2285             rps->setCheckLTMSBPresent(j,true); 
     2499            rps->setPOC     (j, pocLTCurr);
     2500            rps->setDeltaPOC(j, - pcSlice->getPOC() + pocLTCurr);
     2501            rps->setCheckLTMSBPresent(j,true);
    22862502          }
    22872503          else
    22882504          {
    22892505            rps->setPOC     (j, pocLsbLt);
    2290             rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLsbLt);
    2291             rps->setCheckLTMSBPresent(j,false); 
    2292            
     2506            rps->setDeltaPOC(j, - pcSlice->getPOC() + pocLsbLt);
     2507            rps->setCheckLTMSBPresent(j,false);
     2508
    22932509            // reset deltaPocMSBCycleLT for first LTRP from slice header if MSB not present
    22942510            if( j == offset+(numOfLtrp-numLtrpInSPS)-1 )
     
    23002516        }
    23012517        offset += rps->getNumberOfLongtermPictures();
    2302         rps->setNumberOfPictures(offset);       
    2303       } 
    2304 #if H_MV
     2518        rps->setNumberOfPictures(offset);
     2519      }
     2520#if NH_MV
    23052521      if ( !rps->getInterRPSPrediction( ) )
    23062522      { // check sum of NumPositivePics, NumNegativePics, num_long_term_sps and num_long_term_pics
     
    23082524          vps->getVpsExtensionFlag(),
    23092525            MAX_INT,  // To be replaced by MaxDbpsize
    2310           rpcSlice->getLayerId(),
     2526          pcSlice->getLayerId(),
    23112527          sps->getMaxDecPicBuffering( sps->getSpsMaxSubLayersMinus1() ) - 1 );
    23122528      }
    23132529#endif
    2314       if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
    2315         || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
    2316         || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
     2530
     2531      if ( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
     2532        || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
     2533        || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
    23172534      {
    23182535        // In the case of BLA picture types, rps data is read from slice header but ignored
    2319         rps = rpcSlice->getLocalRPS();
    2320         rps->setNumberOfNegativePictures(0);
    2321         rps->setNumberOfPositivePictures(0);
    2322         rps->setNumberOfLongtermPictures(0);
    2323         rps->setNumberOfPictures(0);
    2324         rpcSlice->setRPS(rps);
    2325       }
    2326       if (rpcSlice->getSPS()->getTMVPFlagsPresent())
    2327       {
    2328 #if H_MV
     2536        rps = pcSlice->getLocalRPS();
     2537        (*rps)=TComReferencePictureSet();
     2538        pcSlice->setRPS(rps);
     2539      }
     2540      if (sps->getTMVPFlagsPresent())
     2541      {
     2542#if NH_MV
    23292543        READ_FLAG( uiCode, "slice_temporal_mvp_enabled_flag" );
    23302544#else
    2331         READ_FLAG( uiCode, "slice_temporal_mvp_enable_flag" );
    2332 #endif
    2333         rpcSlice->setEnableTMVPFlag( uiCode == 1 ? true : false );
     2545        READ_FLAG( uiCode, "slice_temporal_mvp_enabled_flag" );
     2546#endif
     2547        pcSlice->setEnableTMVPFlag( uiCode == 1 ? true : false );
    23342548      }
    23352549      else
    23362550      {
    2337         rpcSlice->setEnableTMVPFlag(false);
    2338       }
    2339     }
    2340 #if H_MV
     2551        pcSlice->setEnableTMVPFlag(false);
     2552      }
     2553    }
     2554#if NH_MV
    23412555    Bool interLayerPredLayerIdcPresentFlag = false;
    2342     Int layerId       = rpcSlice->getLayerId();
    2343 #if H_3D
    2344     if( rpcSlice->getLayerId() > 0 && !vps->getAllRefLayersActiveFlag() && vps->getNumRefListLayers( layerId ) > 0 )
     2556    Int layerId       = pcSlice->getLayerId();
     2557#if NH_3D
     2558    if( pcSlice->getLayerId() > 0 && !vps->getAllRefLayersActiveFlag() && vps->getNumRefListLayers( layerId ) > 0 )
    23452559#else
    2346     if( rpcSlice->getLayerId() > 0 && !vps->getAllRefLayersActiveFlag() && vps->getNumDirectRefLayers( layerId ) > 0 )
     2560    if( pcSlice->getLayerId() > 0 && !vps->getAllRefLayersActiveFlag() && vps->getNumDirectRefLayers( layerId ) > 0 )
    23472561#endif
    23482562    {   
    2349       READ_FLAG( uiCode, "inter_layer_pred_enabled_flag" ); rpcSlice->setInterLayerPredEnabledFlag( uiCode == 1 );
    2350 #if H_3D
    2351       if( rpcSlice->getInterLayerPredEnabledFlag() && vps->getNumRefListLayers( layerId ) > 1 )
     2563      READ_FLAG( uiCode, "inter_layer_pred_enabled_flag" ); pcSlice->setInterLayerPredEnabledFlag( uiCode == 1 );
     2564#if NH_3D
     2565      if( pcSlice->getInterLayerPredEnabledFlag() && vps->getNumRefListLayers( layerId ) > 1 )
    23522566#else
    2353       if( rpcSlice->getInterLayerPredEnabledFlag() && vps->getNumDirectRefLayers( layerId ) > 1 )
     2567      if( pcSlice->getInterLayerPredEnabledFlag() && vps->getNumDirectRefLayers( layerId ) > 1 )
    23542568#endif
    23552569      {           
    23562570        if( !vps->getMaxOneActiveRefLayerFlag()) 
    23572571        {
    2358           READ_CODE( rpcSlice->getNumInterLayerRefPicsMinus1Len( ), uiCode, "num_inter_layer_ref_pics_minus1" ); rpcSlice->setNumInterLayerRefPicsMinus1( uiCode );
    2359         }
    2360 #if H_3D
    2361         if ( rpcSlice->getNumActiveRefLayerPics() != vps->getNumRefListLayers( layerId ) )
     2572          READ_CODE( pcSlice->getNumInterLayerRefPicsMinus1Len( ), uiCode, "num_inter_layer_ref_pics_minus1" ); pcSlice->setNumInterLayerRefPicsMinus1( uiCode );
     2573        }
     2574#if NH_3D
     2575        if ( pcSlice->getNumActiveRefLayerPics() != vps->getNumRefListLayers( layerId ) )
    23622576#else
    2363         if ( rpcSlice->getNumActiveRefLayerPics() != vps->getNumDirectRefLayers( layerId ) )
     2577        if ( pcSlice->getNumActiveRefLayerPics() != vps->getNumDirectRefLayers( layerId ) )
    23642578#endif
    23652579        {
    23662580          interLayerPredLayerIdcPresentFlag = true;
    2367           for( Int idx = 0; idx < rpcSlice->getNumActiveRefLayerPics(); idx++ )   
     2581          for( Int idx = 0; idx < pcSlice->getNumActiveRefLayerPics(); idx++ )   
    23682582          {
    2369             READ_CODE( rpcSlice->getInterLayerPredLayerIdcLen( ), uiCode, "inter_layer_pred_layer_idc" ); rpcSlice->setInterLayerPredLayerIdc( idx, uiCode );
     2583            READ_CODE( pcSlice->getInterLayerPredLayerIdcLen( ), uiCode, "inter_layer_pred_layer_idc" ); pcSlice->setInterLayerPredLayerIdc( idx, uiCode );
    23702584          }
    23712585        }
     
    23742588    if ( !interLayerPredLayerIdcPresentFlag )
    23752589    {
    2376       for( Int i = 0; i < rpcSlice->getNumActiveRefLayerPics(); i++ )   
    2377       {
    2378         rpcSlice->setInterLayerPredLayerIdc( i, rpcSlice->getRefLayerPicIdc( i ) );
    2379       }
    2380     }
    2381 #if H_3D
     2590      for( Int i = 0; i < pcSlice->getNumActiveRefLayerPics(); i++ )   
     2591      {
     2592        pcSlice->setInterLayerPredLayerIdc( i, pcSlice->getRefLayerPicIdc( i ) );
     2593      }
     2594    }
     2595#if NH_3D
    23822596    if ( getDecTop()->decProcAnnexI() )
    23832597    {   
    2384       rpcSlice->deriveInCmpPredAndCpAvailFlag();
    2385       if ( rpcSlice->getInCmpPredAvailFlag() )
    2386       {
    2387         READ_FLAG(uiCode, "in_comp_pred_flag");  rpcSlice->setInCompPredFlag((Bool)uiCode);     
    2388       }
    2389       rpcSlice->init3dToolParameters();
     2598      pcSlice->deriveInCmpPredAndCpAvailFlag( );
     2599      if ( pcSlice->getInCmpPredAvailFlag() )
     2600      {
     2601        READ_FLAG(uiCode, "in_comp_pred_flag");  pcSlice->setInCompPredFlag((Bool)uiCode);     
     2602      }
     2603      pcSlice->init3dToolParameters();
    23902604    }
    23912605#endif
     
    23932607    if(sps->getUseSAO())
    23942608    {
    2395       READ_FLAG(uiCode, "slice_sao_luma_flag");  rpcSlice->setSaoEnabledFlag((Bool)uiCode);
    2396 #if H_3D_DISABLE_CHROMA
    2397       if( rpcSlice->getSPS()->getChromaFormatIdc() != 0 )
    2398       {
    2399         READ_FLAG(uiCode, "slice_sao_chroma_flag");  rpcSlice->setSaoEnabledFlagChroma((Bool)uiCode);
    2400       }
    2401       else
    2402       {
    2403         rpcSlice->setSaoEnabledFlagChroma( false );
    2404       }
    2405 #else
    2406       READ_FLAG(uiCode, "slice_sao_chroma_flag");  rpcSlice->setSaoEnabledFlagChroma((Bool)uiCode);
    2407 #endif
    2408     }
    2409 
    2410     if (rpcSlice->getIdrPicFlag())
    2411     {
    2412       rpcSlice->setEnableTMVPFlag(false);
    2413     }
    2414     if (!rpcSlice->isIntra())
     2609      READ_FLAG(uiCode, "slice_sao_luma_flag");  pcSlice->setSaoEnabledFlag(CHANNEL_TYPE_LUMA, (Bool)uiCode);
     2610
     2611      if (bChroma)
     2612      {
     2613        READ_FLAG(uiCode, "slice_sao_chroma_flag");  pcSlice->setSaoEnabledFlag(CHANNEL_TYPE_CHROMA, (Bool)uiCode);
     2614      }
     2615    }
     2616
     2617    if (pcSlice->getIdrPicFlag())
     2618    {
     2619      pcSlice->setEnableTMVPFlag(false);
     2620    }
     2621    if (!pcSlice->isIntra())
    24152622    {
    24162623
     
    24182625      if (uiCode)
    24192626      {
    2420         READ_UVLC (uiCode, "num_ref_idx_l0_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_0, uiCode + 1 );
    2421         if (rpcSlice->isInterB())
    2422         {
    2423           READ_UVLC (uiCode, "num_ref_idx_l1_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_1, uiCode + 1 );
     2627        READ_UVLC (uiCode, "num_ref_idx_l0_active_minus1" );  pcSlice->setNumRefIdx( REF_PIC_LIST_0, uiCode + 1 );
     2628        if (pcSlice->isInterB())
     2629        {
     2630          READ_UVLC (uiCode, "num_ref_idx_l1_active_minus1" );  pcSlice->setNumRefIdx( REF_PIC_LIST_1, uiCode + 1 );
    24242631        }
    24252632        else
    24262633        {
    2427           rpcSlice->setNumRefIdx(REF_PIC_LIST_1, 0);
     2634          pcSlice->setNumRefIdx(REF_PIC_LIST_1, 0);
    24282635        }
    24292636      }
    24302637      else
    24312638      {
    2432         rpcSlice->setNumRefIdx(REF_PIC_LIST_0, rpcSlice->getPPS()->getNumRefIdxL0DefaultActive());
    2433         if (rpcSlice->isInterB())
    2434         {
    2435           rpcSlice->setNumRefIdx(REF_PIC_LIST_1, rpcSlice->getPPS()->getNumRefIdxL1DefaultActive());
     2639        pcSlice->setNumRefIdx(REF_PIC_LIST_0, pps->getNumRefIdxL0DefaultActive());
     2640        if (pcSlice->isInterB())
     2641        {
     2642          pcSlice->setNumRefIdx(REF_PIC_LIST_1, pps->getNumRefIdxL1DefaultActive());
    24362643        }
    24372644        else
    24382645        {
    2439           rpcSlice->setNumRefIdx(REF_PIC_LIST_1,0);
     2646          pcSlice->setNumRefIdx(REF_PIC_LIST_1,0);
    24402647        }
    24412648      }
    24422649    }
    24432650    // }
    2444     TComRefPicListModification* refPicListModification = rpcSlice->getRefPicListModification();
    2445     if(!rpcSlice->isIntra())
    2446     {
    2447       if( !rpcSlice->getPPS()->getListsModificationPresentFlag() || rpcSlice->getNumRpsCurrTempList() <= 1 )
     2651    TComRefPicListModification* refPicListModification = pcSlice->getRefPicListModification();
     2652    if(!pcSlice->isIntra())
     2653    {
     2654      if( !pps->getListsModificationPresentFlag() || pcSlice->getNumRpsCurrTempList() <= 1 )
    24482655      {
    24492656        refPicListModification->setRefPicListModificationFlagL0( 0 );
     
    24552662
    24562663      if(refPicListModification->getRefPicListModificationFlagL0())
    2457       { 
     2664      {
    24582665        uiCode = 0;
    24592666        Int i = 0;
    2460         Int numRpsCurrTempList0 = rpcSlice->getNumRpsCurrTempList();
     2667        Int numRpsCurrTempList0 = pcSlice->getNumRpsCurrTempList();
    24612668        if ( numRpsCurrTempList0 > 1 )
    24622669        {
    24632670          Int length = 1;
    24642671          numRpsCurrTempList0 --;
    2465           while ( numRpsCurrTempList0 >>= 1) 
     2672          while ( numRpsCurrTempList0 >>= 1)
    24662673          {
    24672674            length ++;
    24682675          }
    2469           for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
     2676          for (i = 0; i < pcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
    24702677          {
    24712678            READ_CODE( length, uiCode, "list_entry_l0" );
     
    24752682        else
    24762683        {
    2477           for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
     2684          for (i = 0; i < pcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
    24782685          {
    24792686            refPicListModification->setRefPicSetIdxL0(i, 0 );
     
    24862693      refPicListModification->setRefPicListModificationFlagL0(0);
    24872694    }
    2488     if(rpcSlice->isInterB())
    2489     {
    2490       if( !rpcSlice->getPPS()->getListsModificationPresentFlag() || rpcSlice->getNumRpsCurrTempList() <= 1 )
     2695    if(pcSlice->isInterB())
     2696    {
     2697      if( !pps->getListsModificationPresentFlag() || pcSlice->getNumRpsCurrTempList() <= 1 )
    24912698      {
    24922699        refPicListModification->setRefPicListModificationFlagL1( 0 );
     
    25002707        uiCode = 0;
    25012708        Int i = 0;
    2502         Int numRpsCurrTempList1 = rpcSlice->getNumRpsCurrTempList();
     2709        Int numRpsCurrTempList1 = pcSlice->getNumRpsCurrTempList();
    25032710        if ( numRpsCurrTempList1 > 1 )
    25042711        {
    25052712          Int length = 1;
    25062713          numRpsCurrTempList1 --;
    2507           while ( numRpsCurrTempList1 >>= 1) 
     2714          while ( numRpsCurrTempList1 >>= 1)
    25082715          {
    25092716            length ++;
    25102717          }
    2511           for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
     2718          for (i = 0; i < pcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
    25122719          {
    25132720            READ_CODE( length, uiCode, "list_entry_l1" );
     
    25172724        else
    25182725        {
    2519           for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
     2726          for (i = 0; i < pcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
    25202727          {
    25212728            refPicListModification->setRefPicSetIdxL1(i, 0 );
     
    25232730        }
    25242731      }
    2525     } 
     2732    }
    25262733    else
    25272734    {
    25282735      refPicListModification->setRefPicListModificationFlagL1(0);
    25292736    }
    2530     if (rpcSlice->isInterB())
    2531     {
    2532       READ_FLAG( uiCode, "mvd_l1_zero_flag" );       rpcSlice->setMvdL1ZeroFlag( (uiCode ? true : false) );
    2533     }
    2534 
    2535     rpcSlice->setCabacInitFlag( false ); // default
    2536     if(pps->getCabacInitPresentFlag() && !rpcSlice->isIntra())
     2737    if (pcSlice->isInterB())
     2738    {
     2739      READ_FLAG( uiCode, "mvd_l1_zero_flag" );       pcSlice->setMvdL1ZeroFlag( (uiCode ? true : false) );
     2740    }
     2741
     2742    pcSlice->setCabacInitFlag( false ); // default
     2743    if(pps->getCabacInitPresentFlag() && !pcSlice->isIntra())
    25372744    {
    25382745      READ_FLAG(uiCode, "cabac_init_flag");
    2539       rpcSlice->setCabacInitFlag( uiCode ? true : false );
    2540     }
    2541 
    2542     if ( rpcSlice->getEnableTMVPFlag() )
    2543     {
    2544       if ( rpcSlice->getSliceType() == B_SLICE )
     2746      pcSlice->setCabacInitFlag( uiCode ? true : false );
     2747    }
     2748
     2749    if ( pcSlice->getEnableTMVPFlag() )
     2750    {
     2751      if ( pcSlice->getSliceType() == B_SLICE )
    25452752      {
    25462753        READ_FLAG( uiCode, "collocated_from_l0_flag" );
    2547         rpcSlice->setColFromL0Flag(uiCode);
     2754        pcSlice->setColFromL0Flag(uiCode);
    25482755      }
    25492756      else
    25502757      {
    2551         rpcSlice->setColFromL0Flag( 1 );
    2552       }
    2553 
    2554       if ( rpcSlice->getSliceType() != I_SLICE &&
    2555           ((rpcSlice->getColFromL0Flag() == 1 && rpcSlice->getNumRefIdx(REF_PIC_LIST_0) > 1)||
    2556            (rpcSlice->getColFromL0Flag() == 0 && rpcSlice->getNumRefIdx(REF_PIC_LIST_1) > 1)))
     2758        pcSlice->setColFromL0Flag( 1 );
     2759      }
     2760
     2761      if ( pcSlice->getSliceType() != I_SLICE &&
     2762          ((pcSlice->getColFromL0Flag() == 1 && pcSlice->getNumRefIdx(REF_PIC_LIST_0) > 1)||
     2763           (pcSlice->getColFromL0Flag() == 0 && pcSlice->getNumRefIdx(REF_PIC_LIST_1) > 1)))
    25572764      {
    25582765        READ_UVLC( uiCode, "collocated_ref_idx" );
    2559         rpcSlice->setColRefIdx(uiCode);
     2766        pcSlice->setColRefIdx(uiCode);
    25602767      }
    25612768      else
    25622769      {
    2563         rpcSlice->setColRefIdx(0);
    2564       }
    2565     }
    2566     if ( (pps->getUseWP() && rpcSlice->getSliceType()==P_SLICE) || (pps->getWPBiPred() && rpcSlice->getSliceType()==B_SLICE) )
    2567     {
    2568       xParsePredWeightTable(rpcSlice);
    2569       rpcSlice->initWpScaling();
    2570     }
    2571 #if H_3D_IC
    2572     else if(    rpcSlice->getViewIndex() && ( rpcSlice->getSliceType() == P_SLICE || rpcSlice->getSliceType() == B_SLICE )
    2573              && !rpcSlice->getIsDepth() && vps->getNumRefListLayers( layerId ) > 0
     2770        pcSlice->setColRefIdx(0);
     2771      }
     2772    }
     2773    if ( (pps->getUseWP() && pcSlice->getSliceType()==P_SLICE) || (pps->getWPBiPred() && pcSlice->getSliceType()==B_SLICE) )
     2774    {
     2775      xParsePredWeightTable(pcSlice, sps);
     2776      pcSlice->initWpScaling(sps);
     2777    }
     2778
     2779#if NH_3D_IC
     2780    else if(    pcSlice->getViewIndex() && ( pcSlice->getSliceType() == P_SLICE || pcSlice->getSliceType() == B_SLICE )
     2781             && !pcSlice->getIsDepth() && vps->getNumRefListLayers( layerId ) > 0
    25742782             && getDecTop()->decProcAnnexI()
    25752783           )
     
    25782786
    25792787      READ_FLAG ( uiCodeTmp, "slice_ic_enable_flag" );
    2580       rpcSlice->setApplyIC( uiCodeTmp );
     2788      pcSlice->setApplyIC( uiCodeTmp );
    25812789
    25822790      if ( uiCodeTmp )
    25832791      {
    2584         READ_FLAG ( uiCodeTmp, "ic_skip_mergeidx0" );
    2585         rpcSlice->setIcSkipParseFlag( uiCodeTmp );
    2586       }
    2587     }
    2588 #endif
    2589     if (!rpcSlice->isIntra())
     2792        READ_FLAG ( uiCodeTmp, "slice_ic_disabled_merge_zero_idx_flag" );
     2793        pcSlice->setIcSkipParseFlag( uiCodeTmp );
     2794      }
     2795    }
     2796#endif
     2797
     2798    if (!pcSlice->isIntra())
    25902799    {
    25912800      READ_UVLC( uiCode, "five_minus_max_num_merge_cand");
    2592 #if H_3D_IV_MERGE
    2593       rpcSlice->setMaxNumMergeCand(( ( rpcSlice->getMpiFlag() || rpcSlice->getIvMvPredFlag() || rpcSlice->getViewSynthesisPredFlag() ) ? MRG_MAX_NUM_CANDS_MEM : MRG_MAX_NUM_CANDS) - uiCode);
     2801#if NH_3D_IV_MERGE
     2802      pcSlice->setMaxNumMergeCand(( ( pcSlice->getMpiFlag() || pcSlice->getIvMvPredFlag() || pcSlice->getViewSynthesisPredFlag() ) ? MRG_MAX_NUM_CANDS_MEM : MRG_MAX_NUM_CANDS) - uiCode);
    25942803#else
    2595       rpcSlice->setMaxNumMergeCand(MRG_MAX_NUM_CANDS - uiCode);
     2804      pcSlice->setMaxNumMergeCand(MRG_MAX_NUM_CANDS - uiCode);
    25962805#endif
    25972806    }
    25982807
    25992808    READ_SVLC( iCode, "slice_qp_delta" );
    2600     rpcSlice->setSliceQp (26 + pps->getPicInitQPMinus26() + iCode);
    2601 
    2602     assert( rpcSlice->getSliceQp() >= -sps->getQpBDOffsetY() );
    2603     assert( rpcSlice->getSliceQp() <=  51 );
    2604 
    2605     if (rpcSlice->getPPS()->getSliceChromaQpFlag())
    2606     {
    2607       READ_SVLC( iCode, "slice_qp_delta_cb" );
    2608       rpcSlice->setSliceQpDeltaCb( iCode );
    2609       assert( rpcSlice->getSliceQpDeltaCb() >= -12 );
    2610       assert( rpcSlice->getSliceQpDeltaCb() <=  12 );
    2611       assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) >= -12 );
    2612       assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) <=  12 );
    2613 
    2614       READ_SVLC( iCode, "slice_qp_delta_cr" );
    2615       rpcSlice->setSliceQpDeltaCr( iCode );
    2616       assert( rpcSlice->getSliceQpDeltaCr() >= -12 );
    2617       assert( rpcSlice->getSliceQpDeltaCr() <=  12 );
    2618       assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) >= -12 );
    2619       assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) <=  12 );
    2620     }
    2621 
    2622     if (rpcSlice->getPPS()->getDeblockingFilterControlPresentFlag())
    2623     {
    2624       if(rpcSlice->getPPS()->getDeblockingFilterOverrideEnabledFlag())
    2625       {
    2626         READ_FLAG ( uiCode, "deblocking_filter_override_flag" );        rpcSlice->setDeblockingFilterOverrideFlag(uiCode ? true : false);
     2809    pcSlice->setSliceQp (26 + pps->getPicInitQPMinus26() + iCode);
     2810
     2811    assert( pcSlice->getSliceQp() >= -sps->getQpBDOffset(CHANNEL_TYPE_LUMA) );
     2812    assert( pcSlice->getSliceQp() <=  51 );
     2813
     2814    if (pps->getSliceChromaQpFlag())
     2815    {
     2816      if (numValidComp>COMPONENT_Cb)
     2817      {
     2818        READ_SVLC( iCode, "slice_cb_qp_offset" );
     2819        pcSlice->setSliceChromaQpDelta(COMPONENT_Cb, iCode );
     2820        assert( pcSlice->getSliceChromaQpDelta(COMPONENT_Cb) >= -12 );
     2821        assert( pcSlice->getSliceChromaQpDelta(COMPONENT_Cb) <=  12 );
     2822        assert( (pps->getQpOffset(COMPONENT_Cb) + pcSlice->getSliceChromaQpDelta(COMPONENT_Cb)) >= -12 );
     2823        assert( (pps->getQpOffset(COMPONENT_Cb) + pcSlice->getSliceChromaQpDelta(COMPONENT_Cb)) <=  12 );
     2824      }
     2825
     2826      if (numValidComp>COMPONENT_Cr)
     2827      {
     2828        READ_SVLC( iCode, "slice_cr_qp_offset" );
     2829        pcSlice->setSliceChromaQpDelta(COMPONENT_Cr, iCode );
     2830        assert( pcSlice->getSliceChromaQpDelta(COMPONENT_Cr) >= -12 );
     2831        assert( pcSlice->getSliceChromaQpDelta(COMPONENT_Cr) <=  12 );
     2832        assert( (pps->getQpOffset(COMPONENT_Cr) + pcSlice->getSliceChromaQpDelta(COMPONENT_Cr)) >= -12 );
     2833        assert( (pps->getQpOffset(COMPONENT_Cr) + pcSlice->getSliceChromaQpDelta(COMPONENT_Cr)) <=  12 );
     2834      }
     2835    }
     2836
     2837    if (pps->getPpsRangeExtension().getChromaQpOffsetListEnabledFlag())
     2838    {
     2839      READ_FLAG(uiCode, "cu_chroma_qp_offset_enabled_flag"); pcSlice->setUseChromaQpAdj(uiCode != 0);
     2840    }
     2841    else
     2842    {
     2843      pcSlice->setUseChromaQpAdj(false);
     2844    }
     2845
     2846    if (pps->getDeblockingFilterControlPresentFlag())
     2847    {
     2848      if(pps->getDeblockingFilterOverrideEnabledFlag())
     2849      {
     2850        READ_FLAG ( uiCode, "deblocking_filter_override_flag" );        pcSlice->setDeblockingFilterOverrideFlag(uiCode ? true : false);
    26272851      }
    26282852      else
    2629       { 
    2630         rpcSlice->setDeblockingFilterOverrideFlag(0);
    2631       }
    2632       if(rpcSlice->getDeblockingFilterOverrideFlag())
    2633       {
    2634         READ_FLAG ( uiCode, "slice_disable_deblocking_filter_flag" );   rpcSlice->setDeblockingFilterDisable(uiCode ? 1 : 0);
    2635         if(!rpcSlice->getDeblockingFilterDisable())
    2636         {
    2637           READ_SVLC( iCode, "slice_beta_offset_div2" );                       rpcSlice->setDeblockingFilterBetaOffsetDiv2(iCode);
    2638           assert(rpcSlice->getDeblockingFilterBetaOffsetDiv2() >= -6 &&
    2639                  rpcSlice->getDeblockingFilterBetaOffsetDiv2() <=  6);
    2640           READ_SVLC( iCode, "slice_tc_offset_div2" );                         rpcSlice->setDeblockingFilterTcOffsetDiv2(iCode);
    2641           assert(rpcSlice->getDeblockingFilterTcOffsetDiv2() >= -6 &&
    2642                  rpcSlice->getDeblockingFilterTcOffsetDiv2() <=  6);
     2853      {
     2854        pcSlice->setDeblockingFilterOverrideFlag(0);
     2855      }
     2856      if(pcSlice->getDeblockingFilterOverrideFlag())
     2857      {
     2858        READ_FLAG ( uiCode, "slice_disable_deblocking_filter_flag" );   pcSlice->setDeblockingFilterDisable(uiCode ? 1 : 0);
     2859        if(!pcSlice->getDeblockingFilterDisable())
     2860        {
     2861          READ_SVLC( iCode, "slice_beta_offset_div2" );                       pcSlice->setDeblockingFilterBetaOffsetDiv2(iCode);
     2862          assert(pcSlice->getDeblockingFilterBetaOffsetDiv2() >= -6 &&
     2863                 pcSlice->getDeblockingFilterBetaOffsetDiv2() <=  6);
     2864          READ_SVLC( iCode, "slice_tc_offset_div2" );                         pcSlice->setDeblockingFilterTcOffsetDiv2(iCode);
     2865          assert(pcSlice->getDeblockingFilterTcOffsetDiv2() >= -6 &&
     2866                 pcSlice->getDeblockingFilterTcOffsetDiv2() <=  6);
    26432867        }
    26442868      }
    26452869      else
    26462870      {
    2647         rpcSlice->setDeblockingFilterDisable   ( rpcSlice->getPPS()->getPicDisableDeblockingFilterFlag() );
    2648         rpcSlice->setDeblockingFilterBetaOffsetDiv2( rpcSlice->getPPS()->getDeblockingFilterBetaOffsetDiv2() );
    2649         rpcSlice->setDeblockingFilterTcOffsetDiv2  ( rpcSlice->getPPS()->getDeblockingFilterTcOffsetDiv2() );
     2871        pcSlice->setDeblockingFilterDisable   ( pps->getPicDisableDeblockingFilterFlag() );
     2872        pcSlice->setDeblockingFilterBetaOffsetDiv2( pps->getDeblockingFilterBetaOffsetDiv2() );
     2873        pcSlice->setDeblockingFilterTcOffsetDiv2  ( pps->getDeblockingFilterTcOffsetDiv2() );
    26502874      }
    26512875    }
    26522876    else
    2653     { 
    2654       rpcSlice->setDeblockingFilterDisable       ( false );
    2655       rpcSlice->setDeblockingFilterBetaOffsetDiv2( 0 );
    2656       rpcSlice->setDeblockingFilterTcOffsetDiv2  ( 0 );
    2657     }
    2658 
    2659     Bool isSAOEnabled = (!rpcSlice->getSPS()->getUseSAO())?(false):(rpcSlice->getSaoEnabledFlag()||rpcSlice->getSaoEnabledFlagChroma());
    2660     Bool isDBFEnabled = (!rpcSlice->getDeblockingFilterDisable());
    2661 
    2662     if(rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag() && ( isSAOEnabled || isDBFEnabled ))
     2877    {
     2878      pcSlice->setDeblockingFilterDisable       ( false );
     2879      pcSlice->setDeblockingFilterBetaOffsetDiv2( 0 );
     2880      pcSlice->setDeblockingFilterTcOffsetDiv2  ( 0 );
     2881    }
     2882
     2883    Bool isSAOEnabled = sps->getUseSAO() && (pcSlice->getSaoEnabledFlag(CHANNEL_TYPE_LUMA) || (bChroma && pcSlice->getSaoEnabledFlag(CHANNEL_TYPE_CHROMA)));
     2884    Bool isDBFEnabled = (!pcSlice->getDeblockingFilterDisable());
     2885
     2886    if(pps->getLoopFilterAcrossSlicesEnabledFlag() && ( isSAOEnabled || isDBFEnabled ))
    26632887    {
    26642888      READ_FLAG( uiCode, "slice_loop_filter_across_slices_enabled_flag");
     
    26662890    else
    26672891    {
    2668       uiCode = rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag()?1:0;
    2669     }
    2670     rpcSlice->setLFCrossSliceBoundaryFlag( (uiCode==1)?true:false);
    2671 
    2672 #if H_3D
     2892      uiCode = pps->getLoopFilterAcrossSlicesEnabledFlag()?1:0;
     2893    }
     2894    pcSlice->setLFCrossSliceBoundaryFlag( (uiCode==1)?true:false);
     2895
     2896#if NH_3D
    26732897    if ( getDecTop()->decProcAnnexI() )
    26742898    {
    2675       Int voiInVps = vps->getVoiInVps( rpcSlice->getViewIndex() );
    2676       if( vps->getCpInSliceSegmentHeaderFlag( voiInVps ) && !rpcSlice->getIsDepth() )
     2899      Int voiInVps = vps->getVoiInVps( pcSlice->getViewIndex() );
     2900#if NH_3D_FIX_TICKET_101
     2901      if( vps->getCpInSliceSegmentHeaderFlag( voiInVps ) )
     2902#else
     2903      if( vps->getCpInSliceSegmentHeaderFlag( voiInVps ) && !pcSlice->getIsDepth() )
     2904#endif
    26772905      {
    26782906        for( Int m = 0; m < vps->getNumCp( voiInVps ); m++ )
    26792907        {
    26802908          Int jInVps = vps->getVoiInVps( vps->getCpRefVoi( voiInVps, m ));
    2681           READ_SVLC( iCode, "cp_scale" );                rpcSlice->setCpScale   ( jInVps, iCode );
    2682           READ_SVLC( iCode, "cp_off" );                  rpcSlice->setCpOff     ( jInVps, iCode );
    2683           READ_SVLC( iCode, "cp_inv_scale_plus_scale" ); rpcSlice->setCpInvScale( jInVps, iCode - rpcSlice->getCpScale   ( jInVps ));
    2684           READ_SVLC( iCode, "cp_inv_off_plus_off" );     rpcSlice->setCpInvOff  ( jInVps, iCode - rpcSlice->getCpOff     ( jInVps ));
    2685         }
    2686       }
    2687     }
    2688 #endif
    2689   }
    2690  
    2691     UInt *entryPointOffset          = NULL;
    2692     UInt numEntryPointOffsets, offsetLenMinus1;
     2909          READ_SVLC( iCode, "cp_scale" );                pcSlice->setCpScale   ( jInVps, iCode );
     2910          READ_SVLC( iCode, "cp_off" );                  pcSlice->setCpOff     ( jInVps, iCode );
     2911          READ_SVLC( iCode, "cp_inv_scale_plus_scale" ); pcSlice->setCpInvScale( jInVps, iCode - pcSlice->getCpScale   ( jInVps ));
     2912          READ_SVLC( iCode, "cp_inv_off_plus_off" );     pcSlice->setCpInvOff  ( jInVps, iCode - pcSlice->getCpOff     ( jInVps ));
     2913        }
     2914      }
     2915    }
     2916#endif
     2917
     2918  }
     2919
     2920  std::vector<UInt> entryPointOffset;
    26932921  if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
    26942922  {
    2695     READ_UVLC(numEntryPointOffsets, "num_entry_point_offsets"); rpcSlice->setNumEntryPointOffsets ( numEntryPointOffsets );
     2923    UInt numEntryPointOffsets;
     2924    UInt offsetLenMinus1;
     2925    READ_UVLC(numEntryPointOffsets, "num_entry_point_offsets");
    26962926    if (numEntryPointOffsets>0)
    26972927    {
    26982928      READ_UVLC(offsetLenMinus1, "offset_len_minus1");
    2699     }
    2700     entryPointOffset = new UInt[numEntryPointOffsets];
    2701     for (UInt idx=0; idx<numEntryPointOffsets; idx++)
    2702     {
    2703       READ_CODE(offsetLenMinus1+1, uiCode, "entry_point_offset_minus1");
    2704       entryPointOffset[ idx ] = uiCode + 1;
    2705     }
    2706   }
    2707   else
    2708   {
    2709     rpcSlice->setNumEntryPointOffsets ( 0 );
    2710   }
    2711 
     2929      entryPointOffset.resize(numEntryPointOffsets);
     2930      for (UInt idx=0; idx<numEntryPointOffsets; idx++)
     2931      {
     2932        READ_CODE(offsetLenMinus1+1, uiCode, "entry_point_offset_minus1");
     2933        entryPointOffset[ idx ] = uiCode + 1;
     2934      }
     2935    }
     2936  }
    27122937
    27132938  if(pps->getSliceHeaderExtensionPresentFlag())
    27142939  {
    2715 #if H_MV
    2716     READ_UVLC( uiCode, "slice_segment_header_extension_length" ); rpcSlice->setSliceSegmentHeaderExtensionLength( uiCode );
     2940#if NH_MV
     2941    READ_UVLC( uiCode, "slice_segment_header_extension_length" ); pcSlice->setSliceSegmentHeaderExtensionLength( uiCode );
    27172942    UInt posFollSliceSegHeaderExtLen = m_pcBitstream->getNumBitsRead();
    27182943
    2719     if( rpcSlice->getPPS()->getPocResetInfoPresentFlag() )
    2720     {
    2721       READ_CODE( 2, uiCode, "poc_reset_idc" ); rpcSlice->setPocResetIdc( uiCode );
     2944    if( pps->getPocResetInfoPresentFlag() )
     2945    {
     2946      READ_CODE( 2, uiCode, "poc_reset_idc" ); pcSlice->setPocResetIdc( uiCode );
    27222947    }
    27232948    else
    27242949    {
    2725       rpcSlice->setPocResetIdc( 0 );
    2726     }
    2727     rpcSlice->checkPocResetIdc();
    2728 
    2729     if ( rpcSlice->getVPS()->getPocLsbNotPresentFlag(rpcSlice->getLayerId()) && slicePicOrderCntLsb > 0 )
    2730     {
    2731       assert( rpcSlice->getPocResetIdc() != 2 );
    2732     }
    2733 
    2734     if( rpcSlice->getPocResetIdc() !=  0 )
    2735     {
    2736       READ_CODE( 6, uiCode, "poc_reset_period_id" ); rpcSlice->setPocResetPeriodId( uiCode );
     2950      pcSlice->setPocResetIdc( 0 );
     2951    }
     2952    pcSlice->checkPocResetIdc();
     2953
     2954    if ( pcSlice->getVPS()->getPocLsbNotPresentFlag(pcSlice->getLayerId()) && slicePicOrderCntLsb > 0 )
     2955    {
     2956      assert( pcSlice->getPocResetIdc() != 2 );
     2957    }
     2958
     2959    if( pcSlice->getPocResetIdc() !=  0 )
     2960    {
     2961      READ_CODE( 6, uiCode, "poc_reset_period_id" ); pcSlice->setPocResetPeriodId( uiCode );
    27372962    }
    27382963    else
    27392964    {
    27402965      // TODO Copy poc_reset_period from earlier picture
    2741       rpcSlice->setPocResetPeriodId( 0 );
     2966      pcSlice->setPocResetPeriodId( 0 );
    27422967    }
    27432968   
    2744     if( rpcSlice->getPocResetIdc() ==  3 )
    2745     {
    2746       READ_FLAG( uiCode, "full_poc_reset_flag" ); rpcSlice->setFullPocResetFlag( uiCode == 1 );
    2747       READ_CODE( rpcSlice->getPocLsbValLen() , uiCode, "poc_lsb_val" ); rpcSlice->setPocLsbVal( uiCode );
     2969    if( pcSlice->getPocResetIdc() ==  3 )
     2970    {
     2971      READ_FLAG( uiCode, "full_poc_reset_flag" ); pcSlice->setFullPocResetFlag( uiCode == 1 );
     2972      READ_CODE( pcSlice->getPocLsbValLen() , uiCode, "poc_lsb_val" ); pcSlice->setPocLsbVal( uiCode );
    27482973    }         
    2749     rpcSlice->checkPocLsbVal();
     2974    pcSlice->checkPocLsbVal();
    27502975
    27512976    // Derive the value of PocMs8bValRequiredFlag
    27522977
    2753     if( !rpcSlice->getPocMsbValRequiredFlag() && rpcSlice->getVPS()->getVpsPocLsbAlignedFlag() )
    2754     {
    2755       READ_FLAG( uiCode, "poc_msb_val_present_flag" ); rpcSlice->setPocMsbValPresentFlag( uiCode == 1 );
     2978    if( !pcSlice->getPocMsbValRequiredFlag() && pcSlice->getVPS()->getVpsPocLsbAlignedFlag() )
     2979    {
     2980      READ_FLAG( uiCode, "poc_msb_val_present_flag" ); pcSlice->setPocMsbValPresentFlag( uiCode == 1 );
    27562981    }
    27572982    else
    27582983    {
    2759       rpcSlice->setPocMsbValPresentFlag( rpcSlice->inferPocMsbValPresentFlag( ) );
     2984      pcSlice->setPocMsbValPresentFlag( pcSlice->inferPocMsbValPresentFlag( ) );
    27602985    }
    27612986
    27622987   
    2763     if( rpcSlice->getPocMsbValPresentFlag() )
    2764     {
    2765       READ_UVLC( uiCode, "poc_msb_val" ); rpcSlice->setPocMsbVal( uiCode );
    2766     }
    2767 
    2768     while( ( m_pcBitstream->getNumBitsRead() - posFollSliceSegHeaderExtLen ) < rpcSlice->getSliceSegmentHeaderExtensionLength() * 8 )
     2988    if( pcSlice->getPocMsbValPresentFlag() )
     2989    {
     2990      READ_UVLC( uiCode, "poc_msb_val" ); pcSlice->setPocMsbVal( uiCode );
     2991    }
     2992
     2993    while( ( m_pcBitstream->getNumBitsRead() - posFollSliceSegHeaderExtLen ) < pcSlice->getSliceSegmentHeaderExtensionLength() * 8 )
    27692994    {
    27702995     READ_FLAG( uiCode, "slice_segment_header_extension_data_bit" );
    27712996    }
    2772     assert( ( m_pcBitstream->getNumBitsRead() - posFollSliceSegHeaderExtLen ) == rpcSlice->getSliceSegmentHeaderExtensionLength() * 8  );
     2997    assert( ( m_pcBitstream->getNumBitsRead() - posFollSliceSegHeaderExtLen ) == pcSlice->getSliceSegmentHeaderExtensionLength() * 8  );
    27732998  }
    27742999#else
    2775     READ_UVLC( uiCode, "slice_header_extension_length" );
     3000
     3001    READ_UVLC(uiCode,"slice_segment_header_extension_length");
    27763002    for(Int i=0; i<uiCode; i++)
    27773003    {
    27783004      UInt ignore;
    2779       READ_CODE(8,ignore,"slice_header_extension_data_byte");
    2780     } 
    2781   }
    2782 #endif
     3005      READ_CODE(8,ignore,"slice_segment_header_extension_data_byte");
     3006    }
     3007  }
     3008#endif
     3009#if RExt__DECODER_DEBUG_BIT_STATISTICS
     3010  TComCodingStatistics::IncrementStatisticEP(STATS__BYTE_ALIGNMENT_BITS,m_pcBitstream->readByteAlignment(),0);
     3011#else
    27833012  m_pcBitstream->readByteAlignment();
     3013#endif
     3014
     3015  pcSlice->clearSubstreamSizes();
    27843016
    27853017  if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
    27863018  {
    27873019    Int endOfSliceHeaderLocation = m_pcBitstream->getByteLocation();
    2788    
     3020
    27893021    // Adjust endOfSliceHeaderLocation to account for emulation prevention bytes in the slice segment header
    27903022    for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
     
    27983030    Int  curEntryPointOffset     = 0;
    27993031    Int  prevEntryPointOffset    = 0;
    2800     for (UInt idx=0; idx<numEntryPointOffsets; idx++)
     3032    for (UInt idx=0; idx<entryPointOffset.size(); idx++)
    28013033    {
    28023034      curEntryPointOffset += entryPointOffset[ idx ];
     
    28053037      for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
    28063038      {
    2807         if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) >= ( prevEntryPointOffset + endOfSliceHeaderLocation ) && 
     3039        if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) >= ( prevEntryPointOffset + endOfSliceHeaderLocation ) &&
    28083040             m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) <  ( curEntryPointOffset  + endOfSliceHeaderLocation ) )
    28093041        {
     
    28143046      entryPointOffset[ idx ] -= emulationPreventionByteCount;
    28153047      prevEntryPointOffset = curEntryPointOffset;
    2816     }
    2817 
    2818     if ( pps->getTilesEnabledFlag() )
    2819     {
    2820       rpcSlice->setTileLocationCount( numEntryPointOffsets );
    2821 
    2822       UInt prevPos = 0;
    2823       for (Int idx=0; idx<rpcSlice->getTileLocationCount(); idx++)
    2824       {
    2825         rpcSlice->setTileLocation( idx, prevPos + entryPointOffset [ idx ] );
    2826         prevPos += entryPointOffset[ idx ];
    2827       }
    2828     }
    2829     else if ( pps->getEntropyCodingSyncEnabledFlag() )
    2830     {
    2831     Int numSubstreams = rpcSlice->getNumEntryPointOffsets()+1;
    2832       rpcSlice->allocSubstreamSizes(numSubstreams);
    2833       UInt *pSubstreamSizes       = rpcSlice->getSubstreamSizes();
    2834       for (Int idx=0; idx<numSubstreams-1; idx++)
    2835       {
    2836         if ( idx < numEntryPointOffsets )
    2837         {
    2838           pSubstreamSizes[ idx ] = ( entryPointOffset[ idx ] << 3 ) ;
    2839         }
    2840         else
    2841         {
    2842           pSubstreamSizes[ idx ] = 0;
    2843         }
    2844       }
    2845     }
    2846 
    2847     if (entryPointOffset)
    2848     {
    2849       delete [] entryPointOffset;
     3048      pcSlice->addSubstreamSize(entryPointOffset [ idx ] );
    28503049    }
    28513050  }
     
    28533052  return;
    28543053}
    2855  
     3054
    28563055Void TDecCavlc::parsePTL( TComPTL *rpcPTL, Bool profilePresentFlag, Int maxNumSubLayersMinus1 )
    28573056{
     
    28593058  if(profilePresentFlag)
    28603059  {
    2861     parseProfileTier(rpcPTL->getGeneralPTL());
    2862   }
    2863   READ_CODE( 8, uiCode, "general_level_idc" );    rpcPTL->getGeneralPTL()->setLevelIdc(uiCode);
     3060    parseProfileTier(rpcPTL->getGeneralPTL(), false);
     3061  }
     3062  READ_CODE( 8, uiCode, "general_level_idc" );    rpcPTL->getGeneralPTL()->setLevelIdc(Level::Name(uiCode));
    28643063
    28653064  for (Int i = 0; i < maxNumSubLayersMinus1; i++)
    28663065  {
    2867 #if !H_MV
    2868     if(profilePresentFlag)
    2869     {
    2870 #endif
    2871       READ_FLAG( uiCode, "sub_layer_profile_present_flag[i]" ); rpcPTL->setSubLayerProfilePresentFlag(i, uiCode);
    2872 #if H_MV
    2873       // When profilePresentFlag is equal to 0, sub_layer_profile_present_flag[ i ] shall be equal to 0.
    2874       assert( profilePresentFlag || !rpcPTL->getSubLayerProfilePresentFlag(i) );
    2875 #else
    2876     }
    2877 #endif
     3066    READ_FLAG( uiCode, "sub_layer_profile_present_flag[i]" ); rpcPTL->setSubLayerProfilePresentFlag(i, uiCode);
    28783067    READ_FLAG( uiCode, "sub_layer_level_present_flag[i]"   ); rpcPTL->setSubLayerLevelPresentFlag  (i, uiCode);
    2879   }
    2880  
     3068#if NH_MV
     3069    // When profilePresentFlag is equal to 0, sub_layer_profile_present_flag[ i ] shall be equal to 0.
     3070    assert( profilePresentFlag || !rpcPTL->getSubLayerProfilePresentFlag(i) );
     3071#endif
     3072  }
     3073
    28813074  if (maxNumSubLayersMinus1 > 0)
    28823075  {
     
    28873080    }
    28883081  }
    2889  
     3082
    28903083  for(Int i = 0; i < maxNumSubLayersMinus1; i++)
    28913084  {
    2892 #if H_MV
    28933085    if( rpcPTL->getSubLayerProfilePresentFlag(i) )         
     3086    {
     3087      parseProfileTier(rpcPTL->getSubLayerPTL(i), true);
     3088    }
     3089    if(rpcPTL->getSubLayerLevelPresentFlag(i))
     3090    {
     3091      READ_CODE( 8, uiCode, "sub_layer_level_idc[i]" );   rpcPTL->getSubLayerPTL(i)->setLevelIdc(Level::Name(uiCode));
     3092    }
     3093  }
     3094}
     3095
     3096#if ENC_DEC_TRACE || RExt__DECODER_DEBUG_BIT_STATISTICS
     3097Void TDecCavlc::parseProfileTier(ProfileTierLevel *ptl, const Bool bIsSubLayer)
     3098#define PTL_TRACE_TEXT(txt) bIsSubLayer?("sub_layer_" txt) : ("general_" txt)
    28943099#else
    2895     if( profilePresentFlag && rpcPTL->getSubLayerProfilePresentFlag(i) )         
    2896 #endif
    2897     {
    2898       parseProfileTier(rpcPTL->getSubLayerPTL(i));
    2899     }
    2900     if(rpcPTL->getSubLayerLevelPresentFlag(i))
    2901     {
    2902       READ_CODE( 8, uiCode, "sub_layer_level_idc[i]" );   rpcPTL->getSubLayerPTL(i)->setLevelIdc(uiCode);
    2903     }
    2904   }
    2905 }
    2906 
    2907 Void TDecCavlc::parseProfileTier(ProfileTierLevel *ptl)
     3100Void TDecCavlc::parseProfileTier(ProfileTierLevel *ptl, const Bool /*bIsSubLayer*/)
     3101#define PTL_TRACE_TEXT(txt) txt
     3102#endif
    29083103{
    29093104  UInt uiCode;
    2910   READ_CODE(2 , uiCode, "XXX_profile_space[]");  ptl->setProfileSpace(uiCode);
    2911   READ_FLAG(    uiCode, "XXX_tier_flag[]"    );   ptl->setTierFlag    (uiCode ? 1 : 0);
    2912   READ_CODE(5 , uiCode, "XXX_profile_idc[]"  );   ptl->setProfileIdc  (uiCode);
     3105  READ_CODE(2 , uiCode,   PTL_TRACE_TEXT("profile_space"                   )); ptl->setProfileSpace(uiCode);
     3106  READ_FLAG(    uiCode,   PTL_TRACE_TEXT("tier_flag"                       )); ptl->setTierFlag    (uiCode ? Level::HIGH : Level::MAIN);
     3107  READ_CODE(5 , uiCode,   PTL_TRACE_TEXT("profile_idc"                     )); ptl->setProfileIdc  (Profile::Name(uiCode));
    29133108  for(Int j = 0; j < 32; j++)
    29143109  {
    2915     READ_FLAG(  uiCode, "XXX_profile_compatibility_flag[][j]");   ptl->setProfileCompatibilityFlag(j, uiCode ? 1 : 0);
    2916   }
    2917   READ_FLAG(uiCode, "general_progressive_source_flag");
    2918   ptl->setProgressiveSourceFlag(uiCode ? true : false);
    2919 
    2920   READ_FLAG(uiCode, "general_interlaced_source_flag");
    2921   ptl->setInterlacedSourceFlag(uiCode ? true : false);
    2922  
    2923   READ_FLAG(uiCode, "general_non_packed_constraint_flag");
    2924   ptl->setNonPackedConstraintFlag(uiCode ? true : false);
    2925  
    2926   READ_FLAG(uiCode, "general_frame_only_constraint_flag");
    2927   ptl->setFrameOnlyConstraintFlag(uiCode ? true : false);
    2928  
    2929 #if H_MV
     3110    READ_FLAG(  uiCode,   PTL_TRACE_TEXT("profile_compatibility_flag[][j]" )); ptl->setProfileCompatibilityFlag(j, uiCode ? 1 : 0);
     3111  }
     3112  READ_FLAG(uiCode,       PTL_TRACE_TEXT("progressive_source_flag"         )); ptl->setProgressiveSourceFlag(uiCode ? true : false);
     3113
     3114  READ_FLAG(uiCode,       PTL_TRACE_TEXT("interlaced_source_flag"          )); ptl->setInterlacedSourceFlag(uiCode ? true : false);
     3115
     3116  READ_FLAG(uiCode,       PTL_TRACE_TEXT("non_packed_constraint_flag"      )); ptl->setNonPackedConstraintFlag(uiCode ? true : false);
     3117
     3118  READ_FLAG(uiCode,       PTL_TRACE_TEXT("frame_only_constraint_flag"      )); ptl->setFrameOnlyConstraintFlag(uiCode ? true : false);
     3119#if NH_MV
    29303120  if( ptl->getV2ConstraintsPresentFlag() )
    29313121  {
     
    29583148  }
    29593149#else
    2960   READ_CODE(16, uiCode, "XXX_reserved_zero_44bits[0..15]");
    2961   READ_CODE(16, uiCode, "XXX_reserved_zero_44bits[16..31]");
    2962   READ_CODE(12, uiCode, "XXX_reserved_zero_44bits[32..43]");
     3150
     3151  if (ptl->getProfileIdc() == Profile::MAINREXT           || ptl->getProfileCompatibilityFlag(Profile::MAINREXT) ||
     3152      ptl->getProfileIdc() == Profile::HIGHTHROUGHPUTREXT || ptl->getProfileCompatibilityFlag(Profile::HIGHTHROUGHPUTREXT))
     3153  {
     3154    UInt maxBitDepth=16;
     3155    READ_FLAG(    uiCode, PTL_TRACE_TEXT("max_12bit_constraint_flag"       )); if (uiCode) maxBitDepth=12;
     3156    READ_FLAG(    uiCode, PTL_TRACE_TEXT("max_10bit_constraint_flag"       )); if (uiCode) maxBitDepth=10;
     3157    READ_FLAG(    uiCode, PTL_TRACE_TEXT("max_8bit_constraint_flag"        )); if (uiCode) maxBitDepth=8;
     3158    ptl->setBitDepthConstraint(maxBitDepth);
     3159    ChromaFormat chromaFmtConstraint=CHROMA_444;
     3160    READ_FLAG(    uiCode, PTL_TRACE_TEXT("max_422chroma_constraint_flag"   )); if (uiCode) chromaFmtConstraint=CHROMA_422;
     3161    READ_FLAG(    uiCode, PTL_TRACE_TEXT("max_420chroma_constraint_flag"   )); if (uiCode) chromaFmtConstraint=CHROMA_420;
     3162    READ_FLAG(    uiCode, PTL_TRACE_TEXT("max_monochrome_constraint_flag"  )); if (uiCode) chromaFmtConstraint=CHROMA_400;
     3163    ptl->setChromaFormatConstraint(chromaFmtConstraint);
     3164    READ_FLAG(    uiCode, PTL_TRACE_TEXT("intra_constraint_flag"           )); ptl->setIntraConstraintFlag(uiCode != 0);
     3165    READ_FLAG(    uiCode, PTL_TRACE_TEXT("one_picture_only_constraint_flag")); ptl->setOnePictureOnlyConstraintFlag(uiCode != 0);
     3166    READ_FLAG(    uiCode, PTL_TRACE_TEXT("lower_bit_rate_constraint_flag"  )); ptl->setLowerBitRateConstraintFlag(uiCode != 0);
     3167    READ_CODE(16, uiCode, PTL_TRACE_TEXT("reserved_zero_34bits[0..15]"     ));
     3168    READ_CODE(16, uiCode, PTL_TRACE_TEXT("reserved_zero_34bits[16..31]"    ));
     3169    READ_CODE(2,  uiCode, PTL_TRACE_TEXT("reserved_zero_34bits[32..33]"    ));
     3170  }
     3171  else
     3172  {
     3173    ptl->setBitDepthConstraint((ptl->getProfileIdc() == Profile::MAIN10)?10:8);
     3174    ptl->setChromaFormatConstraint(CHROMA_420);
     3175    ptl->setIntraConstraintFlag(false);
     3176    ptl->setLowerBitRateConstraintFlag(true);
     3177    READ_CODE(16, uiCode, PTL_TRACE_TEXT("reserved_zero_43bits[0..15]"     ));
     3178    READ_CODE(16, uiCode, PTL_TRACE_TEXT("reserved_zero_43bits[16..31]"    ));
     3179    READ_CODE(11, uiCode, PTL_TRACE_TEXT("reserved_zero_43bits[32..42]"    ));
     3180  }
     3181
     3182  if ((ptl->getProfileIdc() >= Profile::MAIN && ptl->getProfileIdc() <= Profile::HIGHTHROUGHPUTREXT) ||
     3183       ptl->getProfileCompatibilityFlag(Profile::MAIN) ||
     3184       ptl->getProfileCompatibilityFlag(Profile::MAIN10) ||
     3185       ptl->getProfileCompatibilityFlag(Profile::MAINSTILLPICTURE) ||
     3186       ptl->getProfileCompatibilityFlag(Profile::MAINREXT) ||
     3187       ptl->getProfileCompatibilityFlag(Profile::HIGHTHROUGHPUTREXT) )
     3188  {
     3189    READ_FLAG(    uiCode, PTL_TRACE_TEXT("inbld_flag"                      )); assert(uiCode == 0);
     3190  }
     3191  else
     3192  {
     3193    READ_FLAG(    uiCode, PTL_TRACE_TEXT("reserved_zero_bit"               ));
     3194  }
     3195#undef PTL_TRACE_TEXT
    29633196#endif
    29643197}
     
    29783211}
    29793212
     3213Void TDecCavlc::parseRemainingBytes( Bool noTrailingBytesExpected )
     3214{
     3215  if (noTrailingBytesExpected)
     3216  {
     3217    const UInt numberOfRemainingSubstreamBytes=m_pcBitstream->getNumBitsLeft();
     3218    assert (numberOfRemainingSubstreamBytes == 0);
     3219  }
     3220  else
     3221  {
     3222    while (m_pcBitstream->getNumBitsLeft())
     3223    {
     3224      UInt trailingNullByte=m_pcBitstream->readByte();
     3225      if (trailingNullByte!=0)
     3226      {
     3227        printf("Trailing byte should be 0, but has value %02x\n", trailingNullByte);
     3228        assert(trailingNullByte==0);
     3229      }
     3230    }
     3231  }
     3232}
     3233
     3234#if NH_3D_DIS
     3235Void TDecCavlc::parseDIS( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
     3236{
     3237  assert(0);
     3238}
     3239#endif
     3240
    29803241Void TDecCavlc::parseSkipFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
    29813242{
    29823243  assert(0);
    29833244}
    2984 #if H_3D
    2985 Void TDecCavlc::parseDIS( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
     3245
     3246Void TDecCavlc::parseCUTransquantBypassFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
    29863247{
    29873248  assert(0);
    29883249}
    2989 #endif
    2990 
    2991 Void TDecCavlc::parseCUTransquantBypassFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
     3250
     3251Void TDecCavlc::parseMVPIdx( Int& /*riMVPIdx*/ )
    29923252{
    29933253  assert(0);
    29943254}
    29953255
    2996 Void TDecCavlc::parseMVPIdx( Int& /*riMVPIdx*/ )
     3256Void TDecCavlc::parseSplitFlag     ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
    29973257{
    29983258  assert(0);
    29993259}
    30003260
    3001 Void TDecCavlc::parseSplitFlag     ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
     3261Void TDecCavlc::parsePartSize( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
    30023262{
    30033263  assert(0);
    30043264}
    30053265
    3006 Void TDecCavlc::parsePartSize( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
     3266Void TDecCavlc::parsePredMode( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
    30073267{
    30083268  assert(0);
    30093269}
    30103270
    3011 Void TDecCavlc::parsePredMode( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
    3012 {
    3013   assert(0);
    3014 }
    3015 
    3016 /** Parse I_PCM information.
     3271/** Parse I_PCM information.
    30173272* \param pcCU pointer to CU
    30183273* \param uiAbsPartIdx CU index
     
    30203275* \returns Void
    30213276*
    3022 * If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes. 
     3277* If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes.
    30233278*/
    30243279Void TDecCavlc::parseIPCMInfo( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
     
    30283283
    30293284Void TDecCavlc::parseIntraDirLumaAng  ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
    3030 { 
     3285{
    30313286  assert(0);
    30323287}
     
    30523307}
    30533308
     3309Void TDecCavlc::parseCrossComponentPrediction( class TComTU& /*rTu*/, ComponentID /*compID*/ )
     3310{
     3311  assert(0);
     3312}
     3313
    30543314Void TDecCavlc::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    30553315{
    3056   Int qp;
    30573316  Int  iDQp;
    30583317
     3318#if RExt__DECODER_DEBUG_BIT_STATISTICS
     3319  READ_SVLC(iDQp, "delta_qp");
     3320#else
    30593321  xReadSvlc( iDQp );
    3060 
    3061   Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY();
    3062   qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+ qpBdOffsetY)) -  qpBdOffsetY;
    3063 
    3064   UInt uiAbsQpCUPartIdx = (uiAbsPartIdx>>((g_uiMaxCUDepth - pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())<<1))<<((g_uiMaxCUDepth - pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())<<1) ;
    3065   UInt uiQpCUDepth =   min(uiDepth,pcCU->getSlice()->getPPS()->getMaxCuDQPDepth()) ;
     3322#endif
     3323
     3324  Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA);
     3325  const Int qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+ qpBdOffsetY)) -  qpBdOffsetY;
     3326
     3327  const UInt maxCUDepth        = pcCU->getSlice()->getSPS()->getMaxTotalCUDepth();
     3328  const UInt maxCuDQPDepth     = pcCU->getSlice()->getPPS()->getMaxCuDQPDepth();
     3329  const UInt doubleDepthDifference = ((maxCUDepth - maxCuDQPDepth)<<1);
     3330  const UInt uiAbsQpCUPartIdx = (uiAbsPartIdx>>doubleDepthDifference)<<doubleDepthDifference ;
     3331  const UInt uiQpCUDepth =   min(uiDepth,pcCU->getSlice()->getPPS()->getMaxCuDQPDepth()) ;
    30663332
    30673333  pcCU->setQPSubParts( qp, uiAbsQpCUPartIdx, uiQpCUDepth );
    30683334}
    30693335
    3070 Void TDecCavlc::parseCoeffNxN( TComDataCU* /*pcCU*/, TCoeff* /*pcCoef*/, UInt /*uiAbsPartIdx*/, UInt /*uiWidth*/, UInt /*uiHeight*/, UInt /*uiDepth*/, TextType /*eTType*/ )
     3336Void TDecCavlc::parseChromaQpAdjustment( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
    30713337{
    30723338  assert(0);
    30733339}
    30743340
     3341Void TDecCavlc::parseCoeffNxN( TComTU &/*rTu*/, ComponentID /*compID*/ )
     3342{
     3343  assert(0);
     3344}
     3345
    30753346Void TDecCavlc::parseTransformSubdivFlag( UInt& /*ruiSubdivFlag*/, UInt /*uiLog2TransformBlockSize*/ )
    30763347{
     
    30783349}
    30793350
    3080 Void TDecCavlc::parseQtCbf( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, TextType /*eType*/, UInt /*uiTrDepth*/, UInt /*uiDepth*/ )
     3351Void TDecCavlc::parseQtCbf( TComTU &/*rTu*/, const ComponentID /*compID*/, const Bool /*lowestLevel*/ )
    30813352{
    30823353  assert(0);
     
    30883359}
    30893360
    3090 Void TDecCavlc::parseTransformSkipFlags (TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*width*/, UInt /*height*/, UInt /*uiDepth*/, TextType /*eTType*/)
     3361Void TDecCavlc::parseTransformSkipFlags (TComTU &/*rTu*/, ComponentID /*component*/)
    30913362{
    30923363  assert(0);
     
    31033374}
    31043375
    3105 #if H_3D_ARP
     3376#if NH_3D_ARP
    31063377Void TDecCavlc::parseARPW( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    31073378{
     
    31093380}
    31103381#endif
    3111 #if H_3D_IC
     3382#if NH_3D_IC
    31123383Void TDecCavlc::parseICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    31133384{
     
    31153386}
    31163387#endif
    3117 #if H_3D_INTER_SDC
    3118 Void TDecCavlc::parseDeltaDC( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
    3119 { 
     3388#if NH_3D_SDC_INTRA || NH_3D_SDC_INTER
     3389Void TDecCavlc::parseSDCFlag    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
     3390{
    31203391  assert(0);
    31213392}
    31223393
    3123 Void TDecCavlc::parseSDCFlag    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    3124 {
    3125   assert(0);
    3126 }
    3127 
    3128 #endif
    3129 #if H_3D_DBBP
     3394#endif
     3395#if NH_3D_DBBP
    31303396  Void TDecCavlc::parseDBBPFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    31313397  {
     
    31373403// ====================================================================================================================
    31383404
    3139 /** parse explicit wp tables
    3140 * \param TComSlice* pcSlice
    3141 * \returns Void
    3142 */
    3143 Void TDecCavlc::xParsePredWeightTable( TComSlice* pcSlice )
    3144 {
    3145   wpScalingParam  *wp;
    3146 #if H_3D_DISABLE_CHROMA
    3147   Bool            bChroma     = ( pcSlice->getSPS()->getChromaFormatIdc() != 0 );
    3148 #else
    3149   Bool            bChroma     = true; // color always present in HEVC ?
    3150 #endif
    3151   SliceType       eSliceType  = pcSlice->getSliceType();
    3152   Int             iNbRef       = (eSliceType == B_SLICE ) ? (2) : (1);
    3153   UInt            uiLog2WeightDenomLuma, uiLog2WeightDenomChroma;
    3154   UInt            uiTotalSignalledWeightFlags = 0;
     3405//! parse explicit wp tables
     3406Void TDecCavlc::xParsePredWeightTable( TComSlice* pcSlice, const TComSPS *sps )
     3407{
     3408        WPScalingParam *wp;
     3409  const ChromaFormat    chFmt        = sps->getChromaFormatIdc();
     3410  const Int             numValidComp = Int(getNumberValidComponents(chFmt));
     3411  const Bool            bChroma      = (chFmt!=CHROMA_400);
     3412  const SliceType       eSliceType   = pcSlice->getSliceType();
     3413  const Int             iNbRef       = (eSliceType == B_SLICE ) ? (2) : (1);
     3414        UInt            uiLog2WeightDenomLuma=0, uiLog2WeightDenomChroma=0;
     3415        UInt            uiTotalSignalledWeightFlags = 0;
    31553416
    31563417  Int iDeltaDenom;
    31573418  // decode delta_luma_log2_weight_denom :
    3158   READ_UVLC( uiLog2WeightDenomLuma, "luma_log2_weight_denom" );     // ue(v): luma_log2_weight_denom
     3419  READ_UVLC( uiLog2WeightDenomLuma, "luma_log2_weight_denom" );
    31593420  assert( uiLog2WeightDenomLuma <= 7 );
    3160   if( bChroma ) 
    3161   {
    3162     READ_SVLC( iDeltaDenom, "delta_chroma_log2_weight_denom" );     // se(v): delta_chroma_log2_weight_denom
     3421  if( bChroma )
     3422  {
     3423    READ_SVLC( iDeltaDenom, "delta_chroma_log2_weight_denom" );
    31633424    assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)>=0);
    31643425    assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)<=7);
    31653426    uiLog2WeightDenomChroma = (UInt)(iDeltaDenom + uiLog2WeightDenomLuma);
    31663427  }
    3167   else
    3168   {
    3169     // For some reasons this is also needed to fix a compiler warning when H_3D_DISABLE_CHROMA is equal to 0.
    3170     uiLog2WeightDenomChroma = 0;
    3171   }
    3172 
    3173 
    3174   for ( Int iNumRef=0 ; iNumRef<iNbRef ; iNumRef++ )
     3428
     3429
     3430
     3431  for ( Int iNumRef=0 ; iNumRef<iNbRef ; iNumRef++ ) // loop over l0 and l1 syntax elements
    31753432  {
    31763433    RefPicList  eRefPicList = ( iNumRef ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
    3177     for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) 
     3434    for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
    31783435    {
    31793436      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
    31803437
    3181       wp[0].uiLog2WeightDenom = uiLog2WeightDenomLuma;
    3182       wp[1].uiLog2WeightDenom = uiLog2WeightDenomChroma;
    3183       wp[2].uiLog2WeightDenom = uiLog2WeightDenomChroma;
     3438      wp[COMPONENT_Y].uiLog2WeightDenom = uiLog2WeightDenomLuma;
     3439      for(Int j=1; j<numValidComp; j++)
     3440      {
     3441        wp[j].uiLog2WeightDenom = uiLog2WeightDenomChroma;
     3442      }
    31843443
    31853444      UInt  uiCode;
    3186       READ_FLAG( uiCode, "luma_weight_lX_flag" );           // u(1): luma_weight_l0_flag
    3187       wp[0].bPresentFlag = ( uiCode == 1 );
    3188       uiTotalSignalledWeightFlags += wp[0].bPresentFlag;
    3189     }
    3190     if ( bChroma ) 
     3445      READ_FLAG( uiCode, iNumRef==0?"luma_weight_l0_flag[i]":"luma_weight_l1_flag[i]" );
     3446      wp[COMPONENT_Y].bPresentFlag = ( uiCode == 1 );
     3447      uiTotalSignalledWeightFlags += wp[COMPONENT_Y].bPresentFlag;
     3448    }
     3449    if ( bChroma )
    31913450    {
    31923451      UInt  uiCode;
    3193       for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) 
     3452      for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
    31943453      {
    31953454        pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
    3196         READ_FLAG( uiCode, "chroma_weight_lX_flag" );      // u(1): chroma_weight_l0_flag
    3197         wp[1].bPresentFlag = ( uiCode == 1 );
    3198         wp[2].bPresentFlag = ( uiCode == 1 );
    3199         uiTotalSignalledWeightFlags += 2*wp[1].bPresentFlag;
    3200       }
    3201     }
    3202     for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
     3455        READ_FLAG( uiCode, iNumRef==0?"chroma_weight_l0_flag[i]":"chroma_weight_l1_flag[i]" );
     3456        for(Int j=1; j<numValidComp; j++)
     3457        {
     3458          wp[j].bPresentFlag = ( uiCode == 1 );
     3459        }
     3460        uiTotalSignalledWeightFlags += 2*wp[COMPONENT_Cb].bPresentFlag;
     3461      }
     3462    }
     3463    for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
    32033464    {
    32043465      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
    3205       if ( wp[0].bPresentFlag )
     3466      if ( wp[COMPONENT_Y].bPresentFlag )
    32063467      {
    32073468        Int iDeltaWeight;
    3208         READ_SVLC( iDeltaWeight, "delta_luma_weight_lX" );  // se(v): delta_luma_weight_l0[i]
     3469        READ_SVLC( iDeltaWeight, iNumRef==0?"delta_luma_weight_l0[i]":"delta_luma_weight_l1[i]" );
    32093470        assert( iDeltaWeight >= -128 );
    32103471        assert( iDeltaWeight <=  127 );
    3211         wp[0].iWeight = (iDeltaWeight + (1<<wp[0].uiLog2WeightDenom));
    3212         READ_SVLC( wp[0].iOffset, "luma_offset_lX" );       // se(v): luma_offset_l0[i]
    3213         assert( wp[0].iOffset >= -128 );
    3214         assert( wp[0].iOffset <=  127 );
    3215       }
    3216       else
    3217       {
    3218         wp[0].iWeight = (1 << wp[0].uiLog2WeightDenom);
    3219         wp[0].iOffset = 0;
    3220       }
    3221       if ( bChroma )
    3222       {
    3223         if ( wp[1].bPresentFlag )
    3224         {
    3225           for ( Int j=1 ; j<3 ; j++ )
     3472        wp[COMPONENT_Y].iWeight = (iDeltaWeight + (1<<wp[COMPONENT_Y].uiLog2WeightDenom));
     3473        READ_SVLC( wp[COMPONENT_Y].iOffset, iNumRef==0?"luma_offset_l0[i]":"luma_offset_l1[i]" );
     3474        Int range=sps->getSpsRangeExtension().getHighPrecisionOffsetsEnabledFlag() ? (1<<sps->getBitDepth(CHANNEL_TYPE_LUMA))/2 : 128;
     3475        assert( wp[0].iOffset >= -range );
     3476        assert( wp[0].iOffset <   range );
     3477      }
     3478      else
     3479      {
     3480        wp[COMPONENT_Y].iWeight = (1 << wp[COMPONENT_Y].uiLog2WeightDenom);
     3481        wp[COMPONENT_Y].iOffset = 0;
     3482      }
     3483      if ( bChroma )
     3484      {
     3485        if ( wp[COMPONENT_Cb].bPresentFlag )
     3486        {
     3487          Int range=sps->getSpsRangeExtension().getHighPrecisionOffsetsEnabledFlag() ? (1<<sps->getBitDepth(CHANNEL_TYPE_CHROMA))/2 : 128;
     3488          for ( Int j=1 ; j<numValidComp ; j++ )
    32263489          {
    32273490            Int iDeltaWeight;
    3228             READ_SVLC( iDeltaWeight, "delta_chroma_weight_lX" );  // se(v): chroma_weight_l0[i][j]
     3491            READ_SVLC( iDeltaWeight, iNumRef==0?"delta_chroma_weight_l0[i]":"delta_chroma_weight_l1[i]" );
    32293492            assert( iDeltaWeight >= -128 );
    32303493            assert( iDeltaWeight <=  127 );
    3231             wp[j].iWeight = (iDeltaWeight + (1<<wp[1].uiLog2WeightDenom));
     3494            wp[j].iWeight = (iDeltaWeight + (1<<wp[j].uiLog2WeightDenom));
    32323495
    32333496            Int iDeltaChroma;
    3234             READ_SVLC( iDeltaChroma, "delta_chroma_offset_lX" );  // se(v): delta_chroma_offset_l0[i][j]
    3235             assert( iDeltaChroma >= -512 );
    3236             assert( iDeltaChroma <=  511 );
    3237             Int pred = ( 128 - ( ( 128*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) );
    3238             wp[j].iOffset = Clip3(-128, 127, (iDeltaChroma + pred) );
     3497            READ_SVLC( iDeltaChroma, iNumRef==0?"delta_chroma_offset_l0[i]":"delta_chroma_offset_l1[i]" );
     3498            assert( iDeltaChroma >= -4*range);
     3499            assert( iDeltaChroma <   4*range);
     3500            Int pred = ( range - ( ( range*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) );
     3501            wp[j].iOffset = Clip3(-range, range-1, (iDeltaChroma + pred) );
    32393502          }
    32403503        }
    3241         else 
    3242         {
    3243           for ( Int j=1 ; j<3 ; j++ )
     3504        else
     3505        {
     3506          for ( Int j=1 ; j<numValidComp ; j++ )
    32443507          {
    32453508            wp[j].iWeight = (1 << wp[j].uiLog2WeightDenom);
     
    32503513    }
    32513514
    3252     for ( Int iRefIdx=pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx<MAX_NUM_REF ; iRefIdx++ ) 
     3515    for ( Int iRefIdx=pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx<MAX_NUM_REF ; iRefIdx++ )
    32533516    {
    32543517      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
     
    32723535  for(sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
    32733536  {
    3274     for(listId = 0; listId <  g_scalingListNum[sizeId]; listId++)
    3275     {
    3276       READ_FLAG( code, "scaling_list_pred_mode_flag");
    3277       scalingListPredModeFlag = (code) ? true : false;
    3278       if(!scalingListPredModeFlag) //Copy Mode
    3279       {
    3280         READ_UVLC( code, "scaling_list_pred_matrix_id_delta");
    3281         scalingList->setRefMatrixId (sizeId,listId,(UInt)((Int)(listId)-(code)));
    3282         if( sizeId > SCALING_LIST_8x8 )
    3283         {
    3284           scalingList->setScalingListDC(sizeId,listId,((listId == scalingList->getRefMatrixId (sizeId,listId))? 16 :scalingList->getScalingListDC(sizeId, scalingList->getRefMatrixId (sizeId,listId))));
    3285         }
    3286         scalingList->processRefMatrix( sizeId, listId, scalingList->getRefMatrixId (sizeId,listId));
    3287 
    3288       }
    3289       else //DPCM Mode
    3290       {
    3291         xDecodeScalingList(scalingList, sizeId, listId);
     3537    for(listId = 0; listId <  SCALING_LIST_NUM; listId++)
     3538    {
     3539      if ((sizeId==SCALING_LIST_32x32) && (listId%(SCALING_LIST_NUM/NUMBER_OF_PREDICTION_MODES) != 0))
     3540      {
     3541        Int *src = scalingList->getScalingListAddress(sizeId, listId);
     3542        const Int size = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]);
     3543        const Int *srcNextSmallerSize = scalingList->getScalingListAddress(sizeId-1, listId);
     3544        for(Int i=0; i<size; i++)
     3545        {
     3546          src[i] = srcNextSmallerSize[i];
     3547        }
     3548        scalingList->setScalingListDC(sizeId,listId,(sizeId > SCALING_LIST_8x8) ? scalingList->getScalingListDC(sizeId-1, listId) : src[0]);
     3549      }
     3550      else
     3551      {
     3552        READ_FLAG( code, "scaling_list_pred_mode_flag");
     3553        scalingListPredModeFlag = (code) ? true : false;
     3554        scalingList->setScalingListPredModeFlag(sizeId, listId, scalingListPredModeFlag);
     3555        if(!scalingListPredModeFlag) //Copy Mode
     3556        {
     3557          READ_UVLC( code, "scaling_list_pred_matrix_id_delta");
     3558
     3559          if (sizeId==SCALING_LIST_32x32)
     3560          {
     3561            code*=(SCALING_LIST_NUM/NUMBER_OF_PREDICTION_MODES); // Adjust the decoded code for this size, to cope with the missing 32x32 chroma entries.
     3562          }
     3563
     3564          scalingList->setRefMatrixId (sizeId,listId,(UInt)((Int)(listId)-(code)));
     3565          if( sizeId > SCALING_LIST_8x8 )
     3566          {
     3567            scalingList->setScalingListDC(sizeId,listId,((listId == scalingList->getRefMatrixId (sizeId,listId))? 16 :scalingList->getScalingListDC(sizeId, scalingList->getRefMatrixId (sizeId,listId))));
     3568          }
     3569          scalingList->processRefMatrix( sizeId, listId, scalingList->getRefMatrixId (sizeId,listId));
     3570
     3571        }
     3572        else //DPCM Mode
     3573        {
     3574          xDecodeScalingList(scalingList, sizeId, listId);
     3575        }
    32923576      }
    32933577    }
     
    33073591  Int scalingListDcCoefMinus8 = 0;
    33083592  Int nextCoef = SCALING_LIST_START_VALUE;
    3309   UInt* scan  = (sizeId == 0) ? g_auiSigLastScan [ SCAN_DIAG ] [ 1 ] :  g_sigLastScanCG32x32;
     3593  UInt* scan  = g_scanOrder[SCAN_UNGROUPED][SCAN_DIAG][sizeId==0 ? 2 : 3][sizeId==0 ? 2 : 3];
    33103594  Int *dst = scalingList->getScalingListAddress(sizeId, listId);
    33113595
     
    33263610
    33273611Bool TDecCavlc::xMoreRbspData()
    3328 { 
     3612{
    33293613  Int bitsLeft = m_pcBitstream->getNumBitsLeft();
    33303614
     
    33543638}
    33553639
     3640Void TDecCavlc::parseExplicitRdpcmMode( TComTU& /*rTu*/, ComponentID /*compID*/ )
     3641{
     3642  assert(0);
     3643}
    33563644//! \}
    33573645
Note: See TracChangeset for help on using the changeset viewer.