Changeset 1313 in 3DVCSoftware for trunk/source/Lib/TLibEncoder/TEncCavlc.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/TLibEncoder/TEncCavlc.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 *
    6 * Copyright (c) 2010-2015, ITU/ISO/IEC
     6 * Copyright (c) 2010-2015, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    3939#include "TEncCavlc.h"
    4040#include "SEIwrite.h"
    41 #include "../TLibCommon/TypeDef.h"
    42 #if H_3D
     41
     42#if NH_3D
    4343#include "TEncTop.h"
    4444#endif
     45
    4546//! \ingroup TLibEncoder
    4647//! \{
    4748
    48 
    4949#if ENC_DEC_TRACE
    5050
    51 Void  xTraceSPSHeader (TComSPS *pSPS)
    52 {
    53 #if H_MV_ENC_DEC_TRAC
    54   fprintf( g_hTrace, "=========== Sequence Parameter Set LayerId: %d ===========\n", pSPS->getLayerId() );
    55 #else
    56   fprintf( g_hTrace, "=========== Sequence Parameter Set ID: %d ===========\n", pSPS->getSPSId() );
    57 #endif
    58 }
    59 
    60 Void  xTracePPSHeader (TComPPS *pPPS)
    61 {
    62 #if H_MV_ENC_DEC_TRAC
    63   fprintf( g_hTrace, "=========== Picture Parameter Set LayerId: %d ===========\n", pPPS->getLayerId() );
    64 #else
    65   fprintf( g_hTrace, "=========== Picture Parameter Set ID: %d ===========\n", pPPS->getPPSId() );
    66 #endif
    67 }
    68 
    69 Void  xTraceSliceHeader (TComSlice *pSlice)
     51#if !H_MV_ENC_DEC_TRAC
     52Void  xTraceVPSHeader ()
     53{
     54  fprintf( g_hTrace, "=========== Video Parameter Set     ===========\n" );
     55
     56Void  xTraceSPSHeader ()
     57{
     58  fprintf( g_hTrace, "=========== Sequence Parameter Set  ===========\n" );
     59}
     60
     61Void  xTracePPSHeader ()
     62{
     63  fprintf( g_hTrace, "=========== Picture Parameter Set  ===========\n");
     64}
     65
     66Void  xTraceSliceHeader ( )
    7067{
    7168  fprintf( g_hTrace, "=========== Slice ===========\n");
    7269}
    73 
    74 #endif
    75 
    76 
    77 
     70#endif
     71#endif
    7872// ====================================================================================================================
    7973// Constructor / destructor / create / destroy
     
    8377{
    8478  m_pcBitIf           = NULL;
    85   m_uiCoeffCost       = 0;
    8679}
    8780
     
    9588// ====================================================================================================================
    9689
    97 Void TEncCavlc::resetEntropy()
    98 {
    99 }
    100 
    101 
    102 Void TEncCavlc::codeDFFlag(UInt uiCode, const Char *pSymbolName)
    103 {
    104   WRITE_FLAG(uiCode, pSymbolName);
    105 }
    106 Void TEncCavlc::codeDFSvlc(Int iCode, const Char *pSymbolName)
    107 {
    108   WRITE_SVLC(iCode, pSymbolName);
    109 }
    110 
    111 Void TEncCavlc::codeShortTermRefPicSet( TComSPS* pcSPS, TComReferencePictureSet* rps, Bool calledFromSliceHeader, Int idx)
     90Void TEncCavlc::resetEntropy(const TComSlice* /*pSlice*/)
     91{
     92}
     93
     94
     95Void TEncCavlc::codeShortTermRefPicSet( const TComReferencePictureSet* rps, Bool calledFromSliceHeader, Int idx)
    11296{
    11397#if PRINT_RPS_INFO
     
    132116    {
    133117      Int refIdc = rps->getRefIdc(j);
    134       WRITE_CODE( (refIdc==1? 1: 0), 1, "used_by_curr_pic_flag" ); //first bit is "1" if Idc is 1 
    135       if (refIdc != 1) 
     118      WRITE_CODE( (refIdc==1? 1: 0), 1, "used_by_curr_pic_flag" ); //first bit is "1" if Idc is 1
     119      if (refIdc != 1)
    136120      {
    137121        WRITE_CODE( refIdc>>1, 1, "use_delta_flag" ); //second bit is "1" if Idc is 2, "0" otherwise.
     
    143127    WRITE_UVLC( rps->getNumberOfNegativePictures(), "num_negative_pics" );
    144128    WRITE_UVLC( rps->getNumberOfPositivePictures(), "num_positive_pics" );
    145 
    146129    Int prev = 0;
    147130    for(Int j=0 ; j < rps->getNumberOfNegativePictures(); j++)
     
    149132      WRITE_UVLC( prev-rps->getDeltaPOC(j)-1, "delta_poc_s0_minus1" );
    150133      prev = rps->getDeltaPOC(j);
    151       WRITE_FLAG( rps->getUsed(j), "used_by_curr_pic_s0_flag"); 
     134      WRITE_FLAG( rps->getUsed(j), "used_by_curr_pic_s0_flag");
    152135    }
    153136    prev = 0;
     
    156139      WRITE_UVLC( rps->getDeltaPOC(j)-prev-1, "delta_poc_s1_minus1" );
    157140      prev = rps->getDeltaPOC(j);
    158       WRITE_FLAG( rps->getUsed(j), "used_by_curr_pic_s1_flag" ); 
     141      WRITE_FLAG( rps->getUsed(j), "used_by_curr_pic_s1_flag" );
    159142    }
    160143  }
     
    167150
    168151
    169 Void TEncCavlc::codePPS( TComPPS* pcPPS )
    170 {
    171 #if ENC_DEC_TRACE 
    172   xTracePPSHeader (pcPPS);
    173 #endif
    174  
     152Void TEncCavlc::codePPS( const TComPPS* pcPPS )
     153{
     154#if ENC_DEC_TRACE
     155#if H_MV_ENC_DEC_TRAC
     156  tracePSHeader( "PPS", pcPPS->getLayerId() );
     157#else
     158  xTracePPSHeader ();
     159#endif
     160#endif
    175161  WRITE_UVLC( pcPPS->getPPSId(),                             "pps_pic_parameter_set_id" );
    176162  WRITE_UVLC( pcPPS->getSPSId(),                             "pps_seq_parameter_set_id" );
     
    196182  WRITE_SVLC( pcPPS->getPicInitQPMinus26(),                  "init_qp_minus26");
    197183  WRITE_FLAG( pcPPS->getConstrainedIntraPred() ? 1 : 0,      "constrained_intra_pred_flag" );
    198   WRITE_FLAG( pcPPS->getUseTransformSkip() ? 1 : 0,  "transform_skip_enabled_flag" ); 
     184  WRITE_FLAG( pcPPS->getUseTransformSkip() ? 1 : 0,  "transform_skip_enabled_flag" );
    199185  WRITE_FLAG( pcPPS->getUseDQP() ? 1 : 0, "cu_qp_delta_enabled_flag" );
    200186  if ( pcPPS->getUseDQP() )
     
    202188    WRITE_UVLC( pcPPS->getMaxCuDQPDepth(), "diff_cu_qp_delta_depth" );
    203189  }
    204   WRITE_SVLC( pcPPS->getChromaCbQpOffset(),                   "pps_cb_qp_offset" );
    205   WRITE_SVLC( pcPPS->getChromaCrQpOffset(),                   "pps_cr_qp_offset" );
     190
     191  WRITE_SVLC( pcPPS->getQpOffset(COMPONENT_Cb), "pps_cb_qp_offset" );
     192  WRITE_SVLC( pcPPS->getQpOffset(COMPONENT_Cr), "pps_cr_qp_offset" );
     193
    206194  WRITE_FLAG( pcPPS->getSliceChromaQpFlag() ? 1 : 0,          "pps_slice_chroma_qp_offsets_present_flag" );
    207195
     
    214202  {
    215203    WRITE_UVLC( pcPPS->getNumTileColumnsMinus1(),                                    "num_tile_columns_minus1" );
    216     WRITE_UVLC( pcPPS->getTileNumRowsMinus1(),                                       "num_tile_rows_minus1" );
     204    WRITE_UVLC( pcPPS->getNumTileRowsMinus1(),                                       "num_tile_rows_minus1" );
    217205    WRITE_FLAG( pcPPS->getTileUniformSpacingFlag(),                                  "uniform_spacing_flag" );
    218206    if( !pcPPS->getTileUniformSpacingFlag() )
     
    222210        WRITE_UVLC( pcPPS->getTileColumnWidth(i)-1,                                  "column_width_minus1" );
    223211      }
    224       for(UInt i=0; i<pcPPS->getTileNumRowsMinus1(); i++)
     212      for(UInt i=0; i<pcPPS->getNumTileRowsMinus1(); i++)
    225213      {
    226214        WRITE_UVLC( pcPPS->getTileRowHeight(i)-1,                                    "row_height_minus1" );
    227215      }
    228216    }
    229     if(pcPPS->getNumTileColumnsMinus1() !=0 || pcPPS->getTileNumRowsMinus1() !=0)
     217    if(pcPPS->getNumTileColumnsMinus1() !=0 || pcPPS->getNumTileRowsMinus1() !=0)
    230218    {
    231219      WRITE_FLAG( pcPPS->getLoopFilterAcrossTilesEnabledFlag()?1 : 0,          "loop_filter_across_tiles_enabled_flag");
    232220    }
    233221  }
    234   WRITE_FLAG( pcPPS->getLoopFilterAcrossSlicesEnabledFlag()?1 : 0,        "loop_filter_across_slices_enabled_flag");
     222  WRITE_FLAG( pcPPS->getLoopFilterAcrossSlicesEnabledFlag()?1 : 0,        "pps_loop_filter_across_slices_enabled_flag");
    235223  WRITE_FLAG( pcPPS->getDeblockingFilterControlPresentFlag()?1 : 0,       "deblocking_filter_control_present_flag");
    236224  if(pcPPS->getDeblockingFilterControlPresentFlag())
    237225  {
    238     WRITE_FLAG( pcPPS->getDeblockingFilterOverrideEnabledFlag() ? 1 : 0,  "deblocking_filter_override_enabled_flag" ); 
     226    WRITE_FLAG( pcPPS->getDeblockingFilterOverrideEnabledFlag() ? 1 : 0,  "deblocking_filter_override_enabled_flag" );
    239227    WRITE_FLAG( pcPPS->getPicDisableDeblockingFilterFlag() ? 1 : 0,       "pps_disable_deblocking_filter_flag" );
    240228    if(!pcPPS->getPicDisableDeblockingFilterFlag())
     
    244232    }
    245233  }
    246   WRITE_FLAG( pcPPS->getScalingListPresentFlag() ? 1 : 0,                          "pps_scaling_list_data_present_flag" ); 
     234  WRITE_FLAG( pcPPS->getScalingListPresentFlag() ? 1 : 0,                          "pps_scaling_list_data_present_flag" );
    247235  if( pcPPS->getScalingListPresentFlag() )
    248236  {
    249     codeScalingList( m_pcSlice->getScalingList() );
     237    codeScalingList( pcPPS->getScalingList() );
    250238  }
    251239#if PPS_FIX_DEPTH
     
    259247  WRITE_UVLC( pcPPS->getLog2ParallelMergeLevelMinus2(), "log2_parallel_merge_level_minus2");
    260248  WRITE_FLAG( pcPPS->getSliceHeaderExtensionPresentFlag() ? 1 : 0, "slice_segment_header_extension_present_flag");
    261 
    262   #if H_3D
    263     if(( !pcPPS->getSPS()->getVPS()->getDepthId( pcPPS->getSPS()->getLayerId() ) )||
    264         pcPPS->getLayerId() != 1  )
    265     {
    266       pcPPS->setPps3dExtensionFlag( false );
    267     }
    268   #endif
    269 
    270 #if !H_MV
    271   WRITE_FLAG( 0, "pps_extension_flag" );
     249#if !NH_MV
     250  Bool pps_extension_present_flag=false;
     251  Bool pps_extension_flags[NUM_PPS_EXTENSION_FLAGS]={false};
     252
     253  pps_extension_flags[PPS_EXT__REXT] = pcPPS->getPpsRangeExtension().settingsDifferFromDefaults(pcPPS->getUseTransformSkip());
     254
     255  // Other PPS extension flags checked here.
     256
     257  for(Int i=0; i<NUM_PPS_EXTENSION_FLAGS; i++)
     258  {
     259    pps_extension_present_flag|=pps_extension_flags[i];
     260  }
     261
     262  WRITE_FLAG( (pps_extension_present_flag?1:0), "pps_extension_present_flag" );
     263
     264  if (pps_extension_present_flag)
     265  {
     266#if ENC_DEC_TRACE || RExt__DECODER_DEBUG_BIT_STATISTICS
     267    static const char *syntaxStrings[]={ "pps_range_extension_flag",
     268                                         "pps_multilayer_extension_flag",
     269                                         "pps_extension_6bits[0]",
     270                                         "pps_extension_6bits[1]",
     271                                         "pps_extension_6bits[2]",
     272                                         "pps_extension_6bits[3]",
     273                                         "pps_extension_6bits[4]",
     274                                         "pps_extension_6bits[5]" };
     275#endif
     276
     277    for(Int i=0; i<NUM_PPS_EXTENSION_FLAGS; i++)
     278    {
     279      WRITE_FLAG( pps_extension_flags[i]?1:0, syntaxStrings[i] );
     280    }
     281
     282    for(Int i=0; i<NUM_PPS_EXTENSION_FLAGS; i++) // loop used so that the order is determined by the enum.
     283    {
     284      if (pps_extension_flags[i])
     285      {
     286        switch (PPSExtensionFlagIndex(i))
     287        {
     288          case PPS_EXT__REXT:
     289            {
     290              const TComPPSRExt &ppsRangeExtension = pcPPS->getPpsRangeExtension();
     291            if (pcPPS->getUseTransformSkip())
     292            {
     293                WRITE_UVLC( ppsRangeExtension.getLog2MaxTransformSkipBlockSize()-2,            "log2_max_transform_skip_block_size_minus2");
     294            }
     295
     296              WRITE_FLAG((ppsRangeExtension.getCrossComponentPredictionEnabledFlag() ? 1 : 0), "cross_component_prediction_enabled_flag" );
     297
     298              WRITE_FLAG(UInt(ppsRangeExtension.getChromaQpOffsetListEnabledFlag()),           "chroma_qp_offset_list_enabled_flag" );
     299              if (ppsRangeExtension.getChromaQpOffsetListEnabledFlag())
     300            {
     301                WRITE_UVLC(ppsRangeExtension.getDiffCuChromaQpOffsetDepth(),                   "diff_cu_chroma_qp_offset_depth");
     302                WRITE_UVLC(ppsRangeExtension.getChromaQpOffsetListLen() - 1,                   "chroma_qp_offset_list_len_minus1");
     303              /* skip zero index */
     304                for (Int cuChromaQpOffsetIdx = 0; cuChromaQpOffsetIdx < ppsRangeExtension.getChromaQpOffsetListLen(); cuChromaQpOffsetIdx++)
     305              {
     306                  WRITE_SVLC(ppsRangeExtension.getChromaQpOffsetListEntry(cuChromaQpOffsetIdx+1).u.comp.CbOffset,     "cb_qp_offset_list[i]");
     307                  WRITE_SVLC(ppsRangeExtension.getChromaQpOffsetListEntry(cuChromaQpOffsetIdx+1).u.comp.CrOffset,     "cr_qp_offset_list[i]");
     308              }
     309            }
     310
     311              WRITE_UVLC( ppsRangeExtension.getLog2SaoOffsetScale(CHANNEL_TYPE_LUMA),           "log2_sao_offset_scale_luma"   );
     312              WRITE_UVLC( ppsRangeExtension.getLog2SaoOffsetScale(CHANNEL_TYPE_CHROMA),         "log2_sao_offset_scale_chroma" );
     313            }
     314            break;
     315          default:
     316            assert(pps_extension_flags[i]==false); // Should never get here with an active PPS extension flag.
     317            break;
     318        } // switch
     319      } // if flag present
     320    } // loop over PPS flags
     321  } // pps_extension_present_flag is non-zero
    272322#else
    273   WRITE_FLAG( 1, "pps_extension_present_flag" );
     323    WRITE_FLAG( 1, "pps_extension_present_flag" );
    274324
    275325    WRITE_FLAG( pcPPS->getPpsRangeExtensionsFlag( ) ? 1 : 0 , "pps_range_extensions_flag" );
    276326    WRITE_FLAG( pcPPS->getPpsMultilayerExtensionFlag( ) ? 1 : 0 , "pps_multilayer_extension_flag" );
    277 #if !H_3D
    278     WRITE_CODE( pcPPS->getPpsExtension6bits( ), 6, "pps_extension_6bits" );
    279 #else
    280327    WRITE_FLAG( pcPPS->getPps3dExtensionFlag( ) ? 1 : 0 , "pps_3d_extension_flag" );
    281328    WRITE_CODE( pcPPS->getPpsExtension5bits( ), 5, "pps_extension_5bits" );
    282 #endif
    283329    if ( pcPPS->getPpsRangeExtensionsFlag() )
    284330    {
    285       assert(0);
     331              const TComPPSRExt &ppsRangeExtension = pcPPS->getPpsRangeExtension();
     332              if (pcPPS->getUseTransformSkip())
     333              {
     334                WRITE_UVLC( ppsRangeExtension.getLog2MaxTransformSkipBlockSize()-2,            "log2_max_transform_skip_block_size_minus2");
     335              }
     336
     337              WRITE_FLAG((ppsRangeExtension.getCrossComponentPredictionEnabledFlag() ? 1 : 0), "cross_component_prediction_enabled_flag" );
     338
     339              WRITE_FLAG(UInt(ppsRangeExtension.getChromaQpOffsetListEnabledFlag()),           "chroma_qp_offset_list_enabled_flag" );
     340              if (ppsRangeExtension.getChromaQpOffsetListEnabledFlag())
     341              {
     342                WRITE_UVLC(ppsRangeExtension.getDiffCuChromaQpOffsetDepth(),                   "diff_cu_chroma_qp_offset_depth");
     343                WRITE_UVLC(ppsRangeExtension.getChromaQpOffsetListLen() - 1,                   "chroma_qp_offset_list_len_minus1");
     344                /* skip zero index */
     345                for (Int cuChromaQpOffsetIdx = 0; cuChromaQpOffsetIdx < ppsRangeExtension.getChromaQpOffsetListLen(); cuChromaQpOffsetIdx++)
     346                {
     347                  WRITE_SVLC(ppsRangeExtension.getChromaQpOffsetListEntry(cuChromaQpOffsetIdx+1).u.comp.CbOffset,     "cb_qp_offset_list[i]");
     348                  WRITE_SVLC(ppsRangeExtension.getChromaQpOffsetListEntry(cuChromaQpOffsetIdx+1).u.comp.CrOffset,     "cr_qp_offset_list[i]");
     349                }
     350              }
     351
     352              WRITE_UVLC( ppsRangeExtension.getLog2SaoOffsetScale(CHANNEL_TYPE_LUMA),           "log2_sao_offset_scale_luma"   );
     353              WRITE_UVLC( ppsRangeExtension.getLog2SaoOffsetScale(CHANNEL_TYPE_CHROMA),         "log2_sao_offset_scale_chroma" );
    286354    }
    287355
    288356    if ( pcPPS->getPpsMultilayerExtensionFlag() )
    289357    {
    290       codePPSMultilayerExtension( pcPPS );
    291     }
    292 
    293 #if H_3D
     358      codePpsMultilayerExtension( pcPPS );
     359    }
     360
     361#if NH_3D
    294362    if( pcPPS->getPps3dExtensionFlag( )  ) // This probably needs to be aligned with Rext and SHVC
    295363    {
    296       codePPSExtension( pcPPS );
    297     }
    298 #endif
    299 #endif
    300 
    301 }
    302 
    303 #if H_3D
    304 Void  TEncCavlc::codePPSExtension        ( TComPPS* pcPPS )
    305 {
    306   // Assuming that all PPS indirectly refer to the same VPS via different SPS
    307   // There is no parsing dependency in decoding DLT in PPS.
    308   // The VPS information passed to decodePPS() is used to arrange the decoded DLT tables to their corresponding layers.
    309   // This is equivalent to the process of
    310   //   Step 1) decoding DLT tables based on the number of depth layers, and
    311   //   Step 2) mapping DLT tables to the depth layers
    312   // as described in the 3D-HEVC WD.
    313   TComVPS* pcVPS = pcPPS->getSPS()->getVPS();
    314 
    315   TComDLT* pcDLT = pcPPS->getDLT();
    316 
    317   WRITE_FLAG( pcDLT->getDltPresentFlag() ? 1 : 0, "dlt_present_flag" );
    318 
    319   if ( pcDLT->getDltPresentFlag() )
    320   {
    321     WRITE_CODE(pcDLT->getNumDepthViews(), 6, "pps_depth_layers_minus1");
    322     WRITE_CODE((pcDLT->getDepthViewBitDepth() - 8), 4, "pps_bit_depth_for_depth_views_minus8");
    323 
    324     for( Int i = 0; i <= pcVPS->getMaxLayersMinus1(); i++ )
    325     {
    326       if ( i != 0 )
    327       {
    328         if ( pcVPS->getDepthId( i ) == 1 )
    329         {
    330           WRITE_FLAG( pcDLT->getUseDLTFlag( i ) ? 1 : 0, "dlt_flag[i]" );
    331 
    332           if ( pcDLT->getUseDLTFlag( i ) )
     364      codePps3dExtension( pcPPS );
     365    }
     366#endif
     367#endif
     368  xWriteRbspTrailingBits();
     369}
     370
     371#if NH_3D
     372Void  TEncCavlc::codePps3dExtension        ( const TComPPS* pcPPS )
     373{
     374#if NH_3D_DLT
     375  WRITE_FLAG( pcPPS->getDLT()->getDltPresentFlag() ? 1 : 0, "dlts_present_flag" );
     376
     377  if ( pcPPS->getDLT()->getDltPresentFlag() )
     378  {
     379    WRITE_CODE(pcPPS->getDLT()->getNumDepthViews() - 1, 6, "pps_depth_layers_minus1");
     380    WRITE_CODE((pcPPS->getDLT()->getDepthViewBitDepth() - 8), 4, "pps_bit_depth_for_depth_layers_minus8");
     381   
     382#if NH_3D_DLT_FIX
     383    for( Int i = 0; i <= pcPPS->getDLT()->getNumDepthViews()-1; i++ )
     384#else
     385    for( Int i = 0; i <= pcPPS->getDLT()->getNumDepthViews(); i++ )
     386#endif
     387    {
     388      Int layerId = pcPPS->getDLT()->getDepthIdxToLayerId(i);
     389     
     390      WRITE_FLAG( pcPPS->getDLT()->getUseDLTFlag( layerId ) ? 1 : 0, "dlt_flag[i]" );
     391     
     392      if ( pcPPS->getDLT()->getUseDLTFlag( layerId ) )
     393      {
     394        std::vector<Int> aiIdx2DepthValue_coded(256, 0);
     395        UInt uiNumDepthValues_coded = pcPPS->getDLT()->getNumDepthValues(layerId);
     396       
     397        // ----------------------------- Actual coding -----------------------------
     398        WRITE_FLAG( pcPPS->getDLT()->getInterViewDltPredEnableFlag( layerId ) ? 1 : 0, "dlt_pred_flag[i]");
     399        if ( pcPPS->getDLT()->getInterViewDltPredEnableFlag( layerId ) == false )
     400        {
     401          WRITE_FLAG( pcPPS->getDLT()->getUseBitmapRep( layerId ) ? 1 : 0, "dlt_val_flags_present_flag[i]" );
     402         
     403          for( UInt ui = 0; ui<uiNumDepthValues_coded; ui++ )
    333404          {
    334             WRITE_FLAG( pcDLT->getInterViewDltPredEnableFlag( i ) ? 1 : 0, "inter_view_dlt_pred_enable_flag[ i ]");
    335 
    336             // ----------------------------- determine whether to use bit-map -----------------------------
    337             Bool bDltBitMapRepFlag       = false;
    338             UInt uiNumBitsNonBitMap      = 0;
    339             UInt uiNumBitsBitMap         = 0;
    340 
    341             UInt uiMaxDiff               = 0;
    342             UInt uiMinDiff               = 0xffffffff;
    343             UInt uiLengthMinDiff         = 0;
    344             UInt uiLengthDltDiffMinusMin = 0;
    345 
    346             UInt* puiDltDiffValues       = NULL;
    347            
    348             Int aiIdx2DepthValue_coded[256];
    349             UInt uiNumDepthValues_coded = 0;
    350            
    351             uiNumDepthValues_coded = pcDLT->getNumDepthValues(i);
    352             for( UInt ui = 0; ui<uiNumDepthValues_coded; ui++ )
     405            aiIdx2DepthValue_coded[ui] = pcPPS->getDLT()->idx2DepthValue(layerId, ui);
     406          }
     407        }
     408        else
     409        {
     410          AOF( layerId > 1 );
     411          // assumes ref layer id to be 1
     412          std::vector<Int> viRefDLT = pcPPS->getDLT()->idx2DepthValue( 1 );
     413          UInt uiRefNum = pcPPS->getDLT()->getNumDepthValues( 1 );
     414          pcPPS->getDLT()->getDeltaDLT(layerId, viRefDLT, uiRefNum, aiIdx2DepthValue_coded, uiNumDepthValues_coded);
     415        }
     416       
     417        // bit map coding
     418        if ( pcPPS->getDLT()->getUseBitmapRep( layerId ) )
     419        {
     420          UInt uiDltArrayIndex = 0;
     421          for (UInt d=0; d < 256; d++)
     422          {
     423            if ( d == aiIdx2DepthValue_coded[uiDltArrayIndex] )
    353424            {
    354               aiIdx2DepthValue_coded[ui] = pcDLT->idx2DepthValue(i, ui);
    355             }
    356            
    357             if( pcDLT->getInterViewDltPredEnableFlag( i ) )
    358             {
    359               AOF( pcVPS->getDepthId( 1 ) == 1 );
    360               AOF( i > 1 );
    361               // assumes ref layer id to be 1
    362               Int* piRefDLT = pcDLT->idx2DepthValue( 1 );
    363               UInt uiRefNum = pcDLT->getNumDepthValues( 1 );
    364               pcDLT->getDeltaDLT(i, piRefDLT, uiRefNum, aiIdx2DepthValue_coded, &uiNumDepthValues_coded);
    365             }
    366 
    367             if ( NULL == (puiDltDiffValues = (UInt *)calloc(uiNumDepthValues_coded, sizeof(UInt))) )
    368             {
    369               // This should be changed to an assertion.
    370               exit(-1);
    371             }
    372 
    373             for (UInt d = 1; d < uiNumDepthValues_coded; d++)
    374             {
    375               puiDltDiffValues[d] = aiIdx2DepthValue_coded[d] - aiIdx2DepthValue_coded[d-1];
    376 
    377               if ( uiMaxDiff < puiDltDiffValues[d] )
    378               {
    379                 uiMaxDiff = puiDltDiffValues[d];
    380               }
    381 
    382               if ( uiMinDiff > puiDltDiffValues[d] )
    383               {
    384                 uiMinDiff = puiDltDiffValues[d];
    385               }
    386             }
    387 
    388             // counting bits
    389             // diff coding branch
    390             uiNumBitsNonBitMap += 8;                          // u(v) bits for num_depth_values_in_dlt[layerId] (i.e. num_entry[ layerId ])
    391 
    392             if ( uiNumDepthValues_coded > 1 )
    393             {
    394               uiNumBitsNonBitMap += 8;                        // u(v) bits for max_diff[ layerId ]
    395             }
    396 
    397             if ( uiNumDepthValues_coded > 2 )
    398             {
    399               uiLengthMinDiff    = (UInt) ceil(Log2(uiMaxDiff + 1));
    400               uiNumBitsNonBitMap += uiLengthMinDiff;          // u(v)  bits for min_diff[ layerId ]
    401             }
    402 
    403             uiNumBitsNonBitMap += 8;                          // u(v) bits for dlt_depth_value0[ layerId ]
    404 
    405             if (uiMaxDiff > uiMinDiff)
    406             {
    407               uiLengthDltDiffMinusMin = (UInt) ceil(Log2(uiMaxDiff - uiMinDiff + 1));
    408               uiNumBitsNonBitMap += uiLengthDltDiffMinusMin * (uiNumDepthValues_coded - 1);  // u(v) bits for dlt_depth_value_diff_minus_min[ layerId ][ j ]
    409             }
    410 
    411             // bit map branch
    412             uiNumBitsBitMap = 256;   // uiNumBitsBitMap = 1 << pcDLT->getDepthViewBitDepth();
    413 
    414             // determine bDltBitMapFlag
    415             bDltBitMapRepFlag = (uiNumBitsBitMap > uiNumBitsNonBitMap) ? false : true;
    416 
    417             // ----------------------------- Actual coding -----------------------------
    418             if ( pcDLT->getInterViewDltPredEnableFlag( i ) == false )
    419             {
    420               WRITE_FLAG( bDltBitMapRepFlag ? 1 : 0, "dlt_bit_map_rep_flag[ layerId ]" );
     425              WRITE_FLAG(1, "dlt_value_flag[i][j]");
     426              uiDltArrayIndex++;
    421427            }
    422428            else
    423429            {
    424               bDltBitMapRepFlag = false;
     430              WRITE_FLAG(0, "dlt_value_flag[i][j]");
    425431            }
    426 
    427             // bit map coding
    428             if ( bDltBitMapRepFlag )
     432          }
     433        }
     434        // Diff Coding
     435        else
     436        {
     437          UInt uiMaxDiff               = 0;
     438          UInt uiMinDiff               = MAX_INT;
     439          UInt uiLengthMinDiff         = 0;
     440          UInt uiLengthDltDiffMinusMin = 0;
     441         
     442          std::vector<UInt> puiDltDiffValues(uiNumDepthValues_coded, 0);
     443         
     444          for (UInt d = 1; d < uiNumDepthValues_coded; d++)
     445          {
     446            puiDltDiffValues[d] = aiIdx2DepthValue_coded[d] - aiIdx2DepthValue_coded[d-1];
     447           
     448            if ( uiMaxDiff < puiDltDiffValues[d] )
    429449            {
    430               UInt uiDltArrayIndex = 0;
    431               for (UInt d=0; d < 256; d++)
     450              uiMaxDiff = puiDltDiffValues[d];
     451            }
     452           
     453            if ( uiMinDiff > puiDltDiffValues[d] )
     454            {
     455              uiMinDiff = puiDltDiffValues[d];
     456            }
     457          }
     458         
     459          if ( uiNumDepthValues_coded > 2 )
     460          {
     461            uiLengthMinDiff    = (UInt) gCeilLog2(uiMaxDiff + 1);
     462          }
     463          if (uiMaxDiff > uiMinDiff)
     464          {
     465            uiLengthDltDiffMinusMin = (UInt) gCeilLog2(uiMaxDiff - uiMinDiff + 1);
     466          }
     467         
     468          WRITE_CODE(uiNumDepthValues_coded, 8, "num_val_delta_dlt");    // num_entry
     469          {
     470            // The condition if( uiNumDepthValues_coded > 0 ) is always true since for Single-view Diff Coding, there is at least one depth value in depth component.
     471            if ( uiNumDepthValues_coded > 1 )
     472            {
     473              WRITE_CODE(uiMaxDiff, 8, "max_diff");        // max_diff
     474            }
     475           
     476            if ( uiNumDepthValues_coded > 2 )
     477            {
     478              WRITE_CODE((uiMinDiff - 1), uiLengthMinDiff, "min_diff_minus1");     // min_diff_minus1
     479            }
     480           
     481            WRITE_CODE(aiIdx2DepthValue_coded[0], 8, "delta_dlt_val0");          // entry0
     482           
     483            if (uiMaxDiff > uiMinDiff)
     484            {
     485              for (UInt d=1; d < uiNumDepthValues_coded; d++)
    432486              {
    433                 if ( d == aiIdx2DepthValue_coded[uiDltArrayIndex] )
    434                 {                 
    435                   WRITE_FLAG(1, "dlt_bit_map_flag[ layerId ][ j ]");
    436                   uiDltArrayIndex++;
    437                 }
    438                 else
    439                 {
    440                   WRITE_FLAG(0, "dlt_bit_map_flag[ layerId ][ j ]");
    441                 }
     487                WRITE_CODE( (puiDltDiffValues[d] - uiMinDiff), uiLengthDltDiffMinusMin, "delta_val_diff_minus_min[k]");    // entry_value_diff_minus_min[ k ]
    442488              }
    443489            }
    444             // Diff Coding
    445             else
    446             {
    447               WRITE_CODE(uiNumDepthValues_coded, 8, "num_depth_values_in_dlt[i]");    // num_entry
    448               {
    449                 // The condition if( uiNumDepthValues_coded > 0 ) is always true since for Single-view Diff Coding, there is at least one depth value in depth component.
    450                 if ( uiNumDepthValues_coded > 1 )
    451                 {
    452                   WRITE_CODE(uiMaxDiff, 8, "max_diff[ layerId ]");        // max_diff
    453                 }
    454 
    455                 if ( uiNumDepthValues_coded > 2 )
    456                 {
    457                   WRITE_CODE((uiMinDiff - 1), uiLengthMinDiff, "min_diff_minus1[ layerId ]");     // min_diff_minus1
    458                 }
    459 
    460                 WRITE_CODE(aiIdx2DepthValue_coded[0], 8, "dlt_depth_value0[layerId]");          // entry0
    461 
    462                 if (uiMaxDiff > uiMinDiff)
    463                 {
    464                   for (UInt d=1; d < uiNumDepthValues_coded; d++)
    465                   {
    466                     WRITE_CODE( (puiDltDiffValues[d] - uiMinDiff), uiLengthDltDiffMinusMin, "dlt_depth_value_diff_minus_min[ layerId ][ j ]");    // entry_value_diff_minus_min[ k ]
    467                   }
    468                 }
    469               }
    470             }
    471 
    472             free(puiDltDiffValues);
    473490          }
    474         }
    475       }
    476     }
    477   }
    478 }
    479 #endif
    480 
    481 Void TEncCavlc::codeVUI( TComVUI *pcVUI, TComSPS* pcSPS )
     491         
     492        }
     493      }
     494    }
     495  }
     496#endif
     497}
     498#endif
     499
     500Void TEncCavlc::codeVUI( const TComVUI *pcVUI, const TComSPS* pcSPS )
    482501{
    483502#if ENC_DEC_TRACE
     
    500519  }
    501520  WRITE_FLAG(pcVUI->getVideoSignalTypePresentFlag(),            "video_signal_type_present_flag");
    502 #if H_MV
     521#if NH_MV
    503522  assert( pcSPS->getLayerId() == 0 || !pcVUI->getVideoSignalTypePresentFlag() );
    504523#endif
     
    512531      WRITE_CODE(pcVUI->getColourPrimaries(), 8,                "colour_primaries");
    513532      WRITE_CODE(pcVUI->getTransferCharacteristics(), 8,        "transfer_characteristics");
    514       WRITE_CODE(pcVUI->getMatrixCoefficients(), 8,             "matrix_coefficients");
     533      WRITE_CODE(pcVUI->getMatrixCoefficients(), 8,             "matrix_coeffs");
    515534    }
    516535  }
     
    536555    WRITE_UVLC(defaultDisplayWindow.getWindowBottomOffset()/ TComSPS::getWinUnitY(pcSPS->getChromaFormatIdc()), "def_disp_win_bottom_offset");
    537556  }
    538   TimingInfo *timingInfo = pcVUI->getTimingInfo();
     557  const TimingInfo *timingInfo = pcVUI->getTimingInfo();
    539558  WRITE_FLAG(timingInfo->getTimingInfoPresentFlag(),          "vui_timing_info_present_flag");
    540559  if(timingInfo->getTimingInfoPresentFlag())
     
    547566      WRITE_UVLC(timingInfo->getNumTicksPocDiffOneMinus1(),   "vui_num_ticks_poc_diff_one_minus1");
    548567    }
    549   WRITE_FLAG(pcVUI->getHrdParametersPresentFlag(),              "hrd_parameters_present_flag");
    550   if( pcVUI->getHrdParametersPresentFlag() )
    551   {
    552     codeHrdParameters(pcVUI->getHrdParameters(), 1, pcSPS->getMaxTLayers() - 1 );
    553   }
     568    WRITE_FLAG(pcVUI->getHrdParametersPresentFlag(),              "vui_hrd_parameters_present_flag");
     569    if( pcVUI->getHrdParametersPresentFlag() )
     570    {
     571      codeHrdParameters(pcVUI->getHrdParameters(), 1, pcSPS->getMaxTLayers() - 1 );
     572    }
    554573  }
    555574
     
    562581    WRITE_UVLC(pcVUI->getMinSpatialSegmentationIdc(),           "min_spatial_segmentation_idc");
    563582    WRITE_UVLC(pcVUI->getMaxBytesPerPicDenom(),                 "max_bytes_per_pic_denom");
    564     WRITE_UVLC(pcVUI->getMaxBitsPerMinCuDenom(),                "max_bits_per_mincu_denom");
     583    WRITE_UVLC(pcVUI->getMaxBitsPerMinCuDenom(),                "max_bits_per_min_cu_denom");
    565584    WRITE_UVLC(pcVUI->getLog2MaxMvLengthHorizontal(),           "log2_max_mv_length_horizontal");
    566585    WRITE_UVLC(pcVUI->getLog2MaxMvLengthVertical(),             "log2_max_mv_length_vertical");
     
    568587}
    569588
    570 Void TEncCavlc::codeHrdParameters( TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1 )
     589Void TEncCavlc::codeHrdParameters( const TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1 )
    571590{
    572591  if( commonInfPresentFlag )
     
    576595    if( hrd->getNalHrdParametersPresentFlag() || hrd->getVclHrdParametersPresentFlag() )
    577596    {
    578       WRITE_FLAG( hrd->getSubPicCpbParamsPresentFlag() ? 1 : 0,  "sub_pic_cpb_params_present_flag" );
     597      WRITE_FLAG( hrd->getSubPicCpbParamsPresentFlag() ? 1 : 0,  "sub_pic_hrd_params_present_flag" );
    579598      if( hrd->getSubPicCpbParamsPresentFlag() )
    580599      {
    581600        WRITE_CODE( hrd->getTickDivisorMinus2(), 8,              "tick_divisor_minus2" );
    582         WRITE_CODE( hrd->getDuCpbRemovalDelayLengthMinus1(), 5,  "du_cpb_removal_delay_length_minus1" );
     601        WRITE_CODE( hrd->getDuCpbRemovalDelayLengthMinus1(), 5,  "du_cpb_removal_delay_increment_length_minus1" );
    583602        WRITE_FLAG( hrd->getSubPicCpbParamsInPicTimingSEIFlag() ? 1 : 0, "sub_pic_cpb_params_in_pic_timing_sei_flag" );
    584603        WRITE_CODE( hrd->getDpbOutputDelayDuLengthMinus1(), 5,   "dpb_output_delay_du_length_minus1"  );
     
    588607      if( hrd->getSubPicCpbParamsPresentFlag() )
    589608      {
    590         WRITE_CODE( hrd->getDuCpbSizeScale(), 4,                "du_cpb_size_scale" ); 
     609        WRITE_CODE( hrd->getDuCpbSizeScale(), 4,                "du_cpb_size_scale" );
    591610      }
    592611      WRITE_CODE( hrd->getInitialCpbRemovalDelayLengthMinus1(), 5, "initial_cpb_removal_delay_length_minus1" );
     
    599618  {
    600619    WRITE_FLAG( hrd->getFixedPicRateFlag( i ) ? 1 : 0,          "fixed_pic_rate_general_flag");
     620    Bool fixedPixRateWithinCvsFlag = true;
    601621    if( !hrd->getFixedPicRateFlag( i ) )
    602622    {
     623      fixedPixRateWithinCvsFlag = hrd->getFixedPicRateWithinCvsFlag( i );
    603624      WRITE_FLAG( hrd->getFixedPicRateWithinCvsFlag( i ) ? 1 : 0, "fixed_pic_rate_within_cvs_flag");
    604625    }
     626    if( fixedPixRateWithinCvsFlag )
     627    {
     628      WRITE_UVLC( hrd->getPicDurationInTcMinus1( i ),           "elemental_duration_in_tc_minus1");
     629    }
    605630    else
    606631    {
    607       hrd->setFixedPicRateWithinCvsFlag( i, true );
    608     }
    609     if( hrd->getFixedPicRateWithinCvsFlag( i ) )
    610     {
    611       WRITE_UVLC( hrd->getPicDurationInTcMinus1( i ),           "elemental_duration_in_tc_minus1");
    612     }
    613     else
    614     {
    615632      WRITE_FLAG( hrd->getLowDelayHrdFlag( i ) ? 1 : 0,           "low_delay_hrd_flag");
    616633    }
     
    619636      WRITE_UVLC( hrd->getCpbCntMinus1( i ),                      "cpb_cnt_minus1");
    620637    }
    621    
     638
    622639    for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
    623640    {
     
    631648          if( hrd->getSubPicCpbParamsPresentFlag() )
    632649          {
    633             WRITE_UVLC( hrd->getDuCpbSizeValueMinus1( i, j, nalOrVcl ), "cpb_size_du_value_minus1"); 
     650            WRITE_UVLC( hrd->getDuCpbSizeValueMinus1( i, j, nalOrVcl ), "cpb_size_du_value_minus1");
    634651            WRITE_UVLC( hrd->getDuBitRateValueMinus1( i, j, nalOrVcl ), "bit_rate_du_value_minus1");
    635652          }
     
    641658}
    642659
    643 Void TEncCavlc::codeSPS( TComSPS* pcSPS )
    644 {
    645 #if ENC_DEC_TRACE 
    646   xTraceSPSHeader (pcSPS);
     660Void TEncCavlc::codeSPS( const TComSPS* pcSPS )
     661{
     662
     663  const ChromaFormat format                = pcSPS->getChromaFormatIdc();
     664  const Bool         chromaEnabled         = isChromaEnabled(format);
     665
     666#if ENC_DEC_TRACE
     667#if H_MV_ENC_DEC_TRAC
     668  tracePSHeader( "SPS", pcSPS->getLayerId() );
     669#else
     670  xTraceSPSHeader ();
     671#endif
    647672#endif
    648673  WRITE_CODE( pcSPS->getVPSId (),          4,       "sps_video_parameter_set_id" );
    649 #if H_MV
     674#if NH_MV
    650675  if ( pcSPS->getLayerId() == 0 )
    651676  {
    652677#endif
    653678  WRITE_CODE( pcSPS->getMaxTLayers() - 1,  3,       "sps_max_sub_layers_minus1" );
    654 #if H_MV
     679#if NH_MV
    655680  }
    656681  else
     
    661686  {
    662687#endif
    663 
    664   WRITE_FLAG( pcSPS->getTemporalIdNestingFlag() ? 1 : 0,                             "sps_temporal_id_nesting_flag" );
     688  WRITE_FLAG( pcSPS->getTemporalIdNestingFlag() ? 1 : 0, "sps_temporal_id_nesting_flag" );
    665689  codePTL(pcSPS->getPTL(), 1, pcSPS->getMaxTLayers() - 1);
    666 #if H_MV
     690#if NH_MV
    667691}
    668692#endif
    669693  WRITE_UVLC( pcSPS->getSPSId (),                   "sps_seq_parameter_set_id" );
    670 #if H_MV
     694#if NH_MV
    671695    if ( pcSPS->getMultiLayerExtSpsFlag() )
    672696  {
     
    680704  {
    681705#endif
    682   WRITE_UVLC( pcSPS->getChromaFormatIdc (),         "chroma_format_idc" );
    683 #if !H_3D_DISABLE_CHROMA
    684   assert(pcSPS->getChromaFormatIdc () == 1);
    685 #endif
    686   // in the first version chroma_format_idc can only be equal to 1 (4:2:0)
    687   if( pcSPS->getChromaFormatIdc () == 3 )
     706  WRITE_UVLC( Int(pcSPS->getChromaFormatIdc ()),    "chroma_format_idc" );
     707  if( format == CHROMA_444 )
    688708  {
    689709    WRITE_FLAG( 0,                                  "separate_colour_plane_flag");
     
    702722    WRITE_UVLC( conf.getWindowBottomOffset() / TComSPS::getWinUnitY(pcSPS->getChromaFormatIdc() ), "conf_win_bottom_offset" );
    703723  }
    704 #if H_MV
    705 }
    706 #endif
    707 
    708 #if H_MV
     724#if NH_MV
     725}
     726#endif
     727#if NH_MV
    709728  if ( !pcSPS->getMultiLayerExtSpsFlag() )
    710729  {
    711730#endif
    712   WRITE_UVLC( pcSPS->getBitDepthY() - 8,             "bit_depth_luma_minus8" );
    713   WRITE_UVLC( pcSPS->getBitDepthC() - 8,             "bit_depth_chroma_minus8" );
    714 #if H_MV
     731
     732  WRITE_UVLC( pcSPS->getBitDepth(CHANNEL_TYPE_LUMA) - 8,                      "bit_depth_luma_minus8" );
     733
     734  WRITE_UVLC( chromaEnabled ? (pcSPS->getBitDepth(CHANNEL_TYPE_CHROMA) - 8):0,  "bit_depth_chroma_minus8" );
     735#if NH_MV
    715736  }
    716737#endif
    717738  WRITE_UVLC( pcSPS->getBitsForPOC()-4,                 "log2_max_pic_order_cnt_lsb_minus4" );
    718 #if H_MV
     739#if NH_MV
    719740  if ( !pcSPS->getMultiLayerExtSpsFlag())
    720741  { 
    721742#endif
     743
    722744  const Bool subLayerOrderingInfoPresentFlag = 1;
    723745  WRITE_FLAG(subLayerOrderingInfoPresentFlag,       "sps_sub_layer_ordering_info_present_flag");
     
    725747  {
    726748    WRITE_UVLC( pcSPS->getMaxDecPicBuffering(i) - 1,       "sps_max_dec_pic_buffering_minus1[i]" );
    727     WRITE_UVLC( pcSPS->getNumReorderPics(i),               "sps_num_reorder_pics[i]" );
     749    WRITE_UVLC( pcSPS->getNumReorderPics(i),               "sps_max_num_reorder_pics[i]" );
    728750    WRITE_UVLC( pcSPS->getMaxLatencyIncrease(i),           "sps_max_latency_increase_plus1[i]" );
    729751    if (!subLayerOrderingInfoPresentFlag)
     
    732754    }
    733755  }
    734 #if H_MV
     756#if NH_MV
    735757  }
    736758#endif
    737759
    738760  assert( pcSPS->getMaxCUWidth() == pcSPS->getMaxCUHeight() );
    739  
    740   WRITE_UVLC( pcSPS->getLog2MinCodingBlockSize() - 3,                                "log2_min_coding_block_size_minus3" );
    741   WRITE_UVLC( pcSPS->getLog2DiffMaxMinCodingBlockSize(),                             "log2_diff_max_min_coding_block_size" );
    742   WRITE_UVLC( pcSPS->getQuadtreeTULog2MinSize() - 2,                                 "log2_min_transform_block_size_minus2" );
    743   WRITE_UVLC( pcSPS->getQuadtreeTULog2MaxSize() - pcSPS->getQuadtreeTULog2MinSize(), "log2_diff_max_min_transform_block_size" );
     761  WRITE_UVLC( pcSPS->getLog2MinCodingBlockSize() - 3,                                "log2_min_luma_coding_block_size_minus3" );
     762  WRITE_UVLC( pcSPS->getLog2DiffMaxMinCodingBlockSize(),                             "log2_diff_max_min_luma_coding_block_size" );
     763  WRITE_UVLC( pcSPS->getQuadtreeTULog2MinSize() - 2,                                 "log2_min_luma_transform_block_size_minus2" );
     764  WRITE_UVLC( pcSPS->getQuadtreeTULog2MaxSize() - pcSPS->getQuadtreeTULog2MinSize(), "log2_diff_max_min_luma_transform_block_size" );
    744765  WRITE_UVLC( pcSPS->getQuadtreeTUMaxDepthInter() - 1,                               "max_transform_hierarchy_depth_inter" );
    745766  WRITE_UVLC( pcSPS->getQuadtreeTUMaxDepthIntra() - 1,                               "max_transform_hierarchy_depth_intra" );
    746   WRITE_FLAG( pcSPS->getScalingListFlag() ? 1 : 0,                                   "scaling_list_enabled_flag" ); 
     767  WRITE_FLAG( pcSPS->getScalingListFlag() ? 1 : 0,                                   "scaling_list_enabled_flag" );
    747768  if(pcSPS->getScalingListFlag())
    748769  {
    749 #if H_MV
     770#if NH_MV
    750771    if ( pcSPS->getMultiLayerExtSpsFlag() )
    751772    {   
     
    760781    {   
    761782#endif
    762     WRITE_FLAG( pcSPS->getScalingListPresentFlag() ? 1 : 0,                          "sps_scaling_list_data_present_flag" );
     783
     784    WRITE_FLAG( pcSPS->getScalingListPresentFlag() ? 1 : 0,                          "sps_scaling_list_data_present_flag" );
    763785    if(pcSPS->getScalingListPresentFlag())
    764786    {
    765       codeScalingList( m_pcSlice->getScalingList() );
    766     }
    767 #if H_MV
     787      codeScalingList( pcSPS->getScalingList() );
     788    }
     789#if NH_MV
    768790    }
    769791#endif
     
    775797  if( pcSPS->getUsePCM() )
    776798  {
    777     WRITE_CODE( pcSPS->getPCMBitDepthLuma() - 1, 4,                                  "pcm_sample_bit_depth_luma_minus1" );
    778     WRITE_CODE( pcSPS->getPCMBitDepthChroma() - 1, 4,                                "pcm_sample_bit_depth_chroma_minus1" );
     799    WRITE_CODE( pcSPS->getPCMBitDepth(CHANNEL_TYPE_LUMA) - 1, 4,                            "pcm_sample_bit_depth_luma_minus1" );
     800    WRITE_CODE( chromaEnabled ? (pcSPS->getPCMBitDepth(CHANNEL_TYPE_CHROMA) - 1) : 0, 4,    "pcm_sample_bit_depth_chroma_minus1" );
    779801    WRITE_UVLC( pcSPS->getPCMLog2MinSize() - 3,                                      "log2_min_pcm_luma_coding_block_size_minus3" );
    780802    WRITE_UVLC( pcSPS->getPCMLog2MaxSize() - pcSPS->getPCMLog2MinSize(),             "log2_diff_max_min_pcm_luma_coding_block_size" );
     
    782804  }
    783805
    784   assert( pcSPS->getMaxTLayers() > 0 );         
    785 
    786   TComRPSList* rpsList = pcSPS->getRPSList();
    787   TComReferencePictureSet*      rps;
     806  assert( pcSPS->getMaxTLayers() > 0 );
     807
     808  const TComRPSList* rpsList = pcSPS->getRPSList();
    788809
    789810  WRITE_UVLC(rpsList->getNumberOfReferencePictureSets(), "num_short_term_ref_pic_sets" );
    790811  for(Int i=0; i < rpsList->getNumberOfReferencePictureSets(); i++)
    791812  {
    792     rps = rpsList->getReferencePictureSet(i);
    793     codeShortTermRefPicSet(pcSPS,rps,false, i);
     813    const TComReferencePictureSet*rps = rpsList->getReferencePictureSet(i);
     814    codeShortTermRefPicSet( rps,false, i);
    794815  }
    795816  WRITE_FLAG( pcSPS->getLongTermRefsPresent() ? 1 : 0,         "long_term_ref_pics_present_flag" );
    796   if (pcSPS->getLongTermRefsPresent()) 
    797   {
    798     WRITE_UVLC(pcSPS->getNumLongTermRefPicSPS(), "num_long_term_ref_pic_sps" );
     817  if (pcSPS->getLongTermRefsPresent())
     818  {
     819    WRITE_UVLC(pcSPS->getNumLongTermRefPicSPS(), "num_long_term_ref_pics_sps" );
    799820    for (UInt k = 0; k < pcSPS->getNumLongTermRefPicSPS(); k++)
    800821    {
    801822      WRITE_CODE( pcSPS->getLtRefPicPocLsbSps(k), pcSPS->getBitsForPOC(), "lt_ref_pic_poc_lsb_sps");
    802       WRITE_FLAG( pcSPS->getUsedByCurrPicLtSPSFlag(k), "used_by_curr_pic_lt_sps_flag");
     823      WRITE_FLAG( pcSPS->getUsedByCurrPicLtSPSFlag(k), "used_by_curr_pic_lt_sps_flag[i]");
    803824    }
    804825  }
     
    813834  }
    814835
    815 #if !H_MV
    816   WRITE_FLAG( 0, "sps_extension_flag" );
     836#if !NH_MV
     837  Bool sps_extension_present_flag=false;
     838  Bool sps_extension_flags[NUM_SPS_EXTENSION_FLAGS]={false};
     839
     840  sps_extension_flags[SPS_EXT__REXT] = pcSPS->getSpsRangeExtension().settingsDifferFromDefaults();
     841
     842  // Other SPS extension flags checked here.
     843
     844  for(Int i=0; i<NUM_SPS_EXTENSION_FLAGS; i++)
     845  {
     846    sps_extension_present_flag|=sps_extension_flags[i];
     847  }
     848
     849  WRITE_FLAG( (sps_extension_present_flag?1:0), "sps_extension_present_flag" );
     850
     851  if (sps_extension_present_flag)
     852  {
     853#if ENC_DEC_TRACE || RExt__DECODER_DEBUG_BIT_STATISTICS
     854    static const char *syntaxStrings[]={ "sps_range_extension_flag",
     855      "sps_multilayer_extension_flag",
     856      "sps_extension_6bits[0]",
     857      "sps_extension_6bits[1]",
     858      "sps_extension_6bits[2]",
     859      "sps_extension_6bits[3]",
     860      "sps_extension_6bits[4]",
     861      "sps_extension_6bits[5]" };
     862#endif
     863
     864    for(Int i=0; i<NUM_SPS_EXTENSION_FLAGS; i++)
     865    {
     866      WRITE_FLAG( sps_extension_flags[i]?1:0, syntaxStrings[i] );
     867    }
     868
     869    for(Int i=0; i<NUM_SPS_EXTENSION_FLAGS; i++) // loop used so that the order is determined by the enum.
     870    {
     871      if (sps_extension_flags[i])
     872      {
     873        switch (SPSExtensionFlagIndex(i))
     874        {
     875        case SPS_EXT__REXT:
     876          {
     877            const TComSPSRExt &spsRangeExtension=pcSPS->getSpsRangeExtension();
     878
     879            WRITE_FLAG( (spsRangeExtension.getTransformSkipRotationEnabledFlag() ? 1 : 0),      "transform_skip_rotation_enabled_flag");
     880            WRITE_FLAG( (spsRangeExtension.getTransformSkipContextEnabledFlag() ? 1 : 0),       "transform_skip_context_enabled_flag");
     881            WRITE_FLAG( (spsRangeExtension.getRdpcmEnabledFlag(RDPCM_SIGNAL_IMPLICIT) ? 1 : 0), "implicit_rdpcm_enabled_flag" );
     882            WRITE_FLAG( (spsRangeExtension.getRdpcmEnabledFlag(RDPCM_SIGNAL_EXPLICIT) ? 1 : 0), "explicit_rdpcm_enabled_flag" );
     883            WRITE_FLAG( (spsRangeExtension.getExtendedPrecisionProcessingFlag() ? 1 : 0),       "extended_precision_processing_flag" );
     884            WRITE_FLAG( (spsRangeExtension.getIntraSmoothingDisabledFlag() ? 1 : 0),            "intra_smoothing_disabled_flag" );
     885            WRITE_FLAG( (spsRangeExtension.getHighPrecisionOffsetsEnabledFlag() ? 1 : 0),       "high_precision_offsets_enabled_flag" );
     886            WRITE_FLAG( (spsRangeExtension.getPersistentRiceAdaptationEnabledFlag() ? 1 : 0),   "persistent_rice_adaptation_enabled_flag" );
     887            WRITE_FLAG( (spsRangeExtension.getCabacBypassAlignmentEnabledFlag() ? 1 : 0),       "cabac_bypass_alignment_enabled_flag" );
     888          break;
     889          }
     890        default:
     891          assert(sps_extension_flags[i]==false); // Should never get here with an active SPS extension flag.
     892          break;
     893        }
     894      }
     895    }
     896  }
    817897#else
    818898  WRITE_FLAG( pcSPS->getSpsExtensionPresentFlag(), "sps_extension_present_flag" );
     
    820900  if ( pcSPS->getSpsExtensionPresentFlag() )
    821901  {
    822     WRITE_FLAG( pcSPS->getSpsRangeExtensionsFlag( ) ? 1 : 0 , "sps_range_extensions_flag" );
     902    WRITE_FLAG( pcSPS->getSpsRangeExtensionsFlag( )     ? 1 : 0 , "sps_range_extensions_flag" );
    823903    WRITE_FLAG( pcSPS->getSpsMultilayerExtensionFlag( ) ? 1 : 0 , "sps_multilayer_extension_flag" );
    824 #if !H_3D
    825     WRITE_CODE( pcSPS->getSpsExtension6bits( ), 6, "sps_extension_6bits" ); 
    826 #else
    827     WRITE_FLAG( pcSPS->getSps3dExtensionFlag( ) ? 1 : 0 , "sps_3d_extension_flag" );
    828     WRITE_CODE( pcSPS->getSpsExtension5bits( ), 5, "sps_extension_5bits" );
    829 #endif
     904    WRITE_FLAG( pcSPS->getSps3dExtensionFlag( )         ? 1 : 0 , "sps_3d_extension_flag" );
     905    WRITE_CODE( pcSPS->getSpsExtension5bits( )              , 5 , "sps_extension_5bits" );
    830906  }
    831907
    832908  if ( pcSPS->getSpsRangeExtensionsFlag() )
    833909  {
    834     assert( 0 );
     910    const TComSPSRExt &spsRangeExtension=pcSPS->getSpsRangeExtension();
     911
     912    WRITE_FLAG( (spsRangeExtension.getTransformSkipRotationEnabledFlag() ? 1 : 0),      "transform_skip_rotation_enabled_flag");
     913    WRITE_FLAG( (spsRangeExtension.getTransformSkipContextEnabledFlag() ? 1 : 0),       "transform_skip_context_enabled_flag");
     914    WRITE_FLAG( (spsRangeExtension.getRdpcmEnabledFlag(RDPCM_SIGNAL_IMPLICIT) ? 1 : 0), "implicit_rdpcm_enabled_flag" );
     915    WRITE_FLAG( (spsRangeExtension.getRdpcmEnabledFlag(RDPCM_SIGNAL_EXPLICIT) ? 1 : 0), "explicit_rdpcm_enabled_flag" );
     916    WRITE_FLAG( (spsRangeExtension.getExtendedPrecisionProcessingFlag() ? 1 : 0),       "extended_precision_processing_flag" );
     917    WRITE_FLAG( (spsRangeExtension.getIntraSmoothingDisabledFlag() ? 1 : 0),            "intra_smoothing_disabled_flag" );
     918    WRITE_FLAG( (spsRangeExtension.getHighPrecisionOffsetsEnabledFlag() ? 1 : 0),       "high_precision_offsets_enabled_flag" );
     919    WRITE_FLAG( (spsRangeExtension.getPersistentRiceAdaptationEnabledFlag() ? 1 : 0),   "persistent_rice_adaptation_enabled_flag" );
     920    WRITE_FLAG( (spsRangeExtension.getCabacBypassAlignmentEnabledFlag() ? 1 : 0),       "cabac_bypass_alignment_enabled_flag" );
    835921  }
    836922
     
    840926  }
    841927
    842 #if H_3D
     928#if NH_3D
    843929  if ( pcSPS->getSps3dExtensionFlag() )
    844930  {
     
    848934#endif
    849935#endif
    850 
    851 }
    852 
    853 #if H_MV
    854 Void TEncCavlc::codeSPSExtension( TComSPS* pcSPS )
     936  xWriteRbspTrailingBits();
     937}
     938
     939#if NH_MV
     940Void TEncCavlc::codeSPSExtension( const TComSPS* pcSPS )
    855941{
    856942  WRITE_FLAG( pcSPS->getInterViewMvVertConstraintFlag() ? 1 : 0, "inter_view_mv_vert_constraint_flag" );
     
    858944
    859945
    860 Void TEncCavlc::codePPSMultilayerExtension(TComPPS* pcPPS)
     946Void TEncCavlc::codePpsMultilayerExtension(const TComPPS* pcPPS)
    861947{
    862948  WRITE_FLAG( pcPPS->getPocResetInfoPresentFlag( ) ? 1 : 0 , "poc_reset_info_present_flag" );
     
    873959#endif
    874960
    875 #if H_3D
    876 Void TEncCavlc::codeSPS3dExtension( TComSPS* pcSPS )
    877 {
    878   TComSps3dExtension* sps3dExt = pcSPS->getSps3dExtension();
     961#if NH_3D
     962Void TEncCavlc::codeSPS3dExtension( const TComSPS* pcSPS )
     963{
     964  const TComSps3dExtension* sps3dExt = pcSPS->getSps3dExtension();
    879965  for( Int d = 0; d  <=  1; d++ )
    880966  {
     
    904990
    905991
    906 
    907 
    908 Void TEncCavlc::codeVPS( TComVPS* pcVPS )
    909 {
     992Void TEncCavlc::codeVPS( const TComVPS* pcVPS )
     993{
     994#if ENC_DEC_TRACE
     995#if H_MV_ENC_DEC_TRAC
     996  tracePSHeader( "VPS", getEncTop()->getLayerId() );
     997#else
     998  xTraceVPSHeader();
     999#endif
     1000#endif
    9101001  WRITE_CODE( pcVPS->getVPSId(),                    4,        "vps_video_parameter_set_id" );
    911 #if H_MV
     1002#if NH_MV
    9121003  WRITE_FLAG( pcVPS->getVpsBaseLayerInternalFlag( ) ? 1 : 0 , "vps_base_layer_internal_flag" );
    9131004  WRITE_FLAG( pcVPS->getVpsBaseLayerAvailableFlag( ) ? 1 : 0 , "vps_base_layer_available_flag" );
    9141005#else
    915   WRITE_CODE( 3,                                    2,        "vps_reserved_three_2bits" );
    916 #endif
    917 #if H_MV
     1006  WRITE_FLAG(                                       1,        "vps_base_layer_internal_flag" );
     1007  WRITE_FLAG(                                       1,        "vps_base_layer_available_flag" );
     1008#endif
     1009#if NH_MV
    9181010  WRITE_CODE( pcVPS->getMaxLayersMinus1(),       6,        "vps_max_layers_minus1" );
    9191011#else
    920   WRITE_CODE( 0,                                    6,        "vps_reserved_zero_6bits" );
     1012  WRITE_CODE( 0,                                    6,        "vps_max_layers_minus1" );
    9211013#endif
    9221014  WRITE_CODE( pcVPS->getMaxTLayers() - 1,           3,        "vps_max_sub_layers_minus1" );
    9231015  WRITE_FLAG( pcVPS->getTemporalNestingFlag(),                "vps_temporal_id_nesting_flag" );
    9241016  assert (pcVPS->getMaxTLayers()>1||pcVPS->getTemporalNestingFlag());
    925   WRITE_CODE( 0xffff,                              16,        "vps_reserved_ffff_16bits" );
     1017  WRITE_CODE( 0xffff,                              16,        "vps_reserved_0xffff_16bits" );
    9261018  codePTL( pcVPS->getPTL(), true, pcVPS->getMaxTLayers() - 1 );
    9271019  const Bool subLayerOrderingInfoPresentFlag = 1;
     
    9301022  {
    9311023    WRITE_UVLC( pcVPS->getMaxDecPicBuffering(i) - 1,       "vps_max_dec_pic_buffering_minus1[i]" );
    932     WRITE_UVLC( pcVPS->getNumReorderPics(i),               "vps_num_reorder_pics[i]" );
     1024    WRITE_UVLC( pcVPS->getNumReorderPics(i),               "vps_max_num_reorder_pics[i]" );
    9331025    WRITE_UVLC( pcVPS->getMaxLatencyIncrease(i),           "vps_max_latency_increase_plus1[i]" );
    9341026    if (!subLayerOrderingInfoPresentFlag)
     
    9371029    }
    9381030  }
     1031
    9391032  assert( pcVPS->getNumHrdParameters() <= MAX_VPS_NUM_HRD_PARAMETERS );
    940 #if H_MV
     1033#if NH_MV
    9411034  assert( pcVPS->getVpsMaxLayerId() < MAX_VPS_NUH_LAYER_ID_PLUS1 );
    9421035  WRITE_CODE( pcVPS->getVpsMaxLayerId(), 6,                 "vps_max_layer_id" ); 
     
    9491042#else
    9501043  assert( pcVPS->getMaxNuhReservedZeroLayerId() < MAX_VPS_NUH_RESERVED_ZERO_LAYER_ID_PLUS1 );
    951   WRITE_CODE( pcVPS->getMaxNuhReservedZeroLayerId(), 6,     "vps_max_nuh_reserved_zero_layer_id" );
    952   pcVPS->setMaxOpSets(1);
    953   WRITE_UVLC( pcVPS->getMaxOpSets() - 1,                    "vps_max_op_sets_minus1" );
     1044  WRITE_CODE( pcVPS->getMaxNuhReservedZeroLayerId(), 6,     "vps_max_layer_id" );
     1045  WRITE_UVLC( pcVPS->getMaxOpSets() - 1,                    "vps_num_layer_sets_minus1" );
    9541046  for( UInt opsIdx = 1; opsIdx <= ( pcVPS->getMaxOpSets() - 1 ); opsIdx ++ )
    9551047  {
     
    9581050    {
    9591051      // Only applicable for version 1
    960       pcVPS->setLayerIdIncludedFlag( true, opsIdx, i );
     1052      // pcVPS->setLayerIdIncludedFlag( true, opsIdx, i );
    9611053#endif
    9621054      WRITE_FLAG( pcVPS->getLayerIdIncludedFlag( opsIdx, i ) ? 1 : 0, "layer_id_included_flag[opsIdx][i]" );
    9631055    }
    9641056  }
    965   TimingInfo *timingInfo = pcVPS->getTimingInfo();
     1057  const TimingInfo *timingInfo = pcVPS->getTimingInfo();
    9661058  WRITE_FLAG(timingInfo->getTimingInfoPresentFlag(),          "vps_timing_info_present_flag");
    9671059  if(timingInfo->getTimingInfoPresentFlag())
     
    9741066      WRITE_UVLC(timingInfo->getNumTicksPocDiffOneMinus1(),   "vps_num_ticks_poc_diff_one_minus1");
    9751067    }
    976     pcVPS->setNumHrdParameters( 0 );
    9771068    WRITE_UVLC( pcVPS->getNumHrdParameters(),                 "vps_num_hrd_parameters" );
    9781069
    9791070    if( pcVPS->getNumHrdParameters() > 0 )
    9801071    {
    981       pcVPS->createHrdParamBuffer();
    982     }
    983     for( UInt i = 0; i < pcVPS->getNumHrdParameters(); i ++ )
    984     {
    985       // Only applicable for version 1
    986       pcVPS->setHrdOpSetIdx( 0, i );
    987       WRITE_UVLC( pcVPS->getHrdOpSetIdx( i ),                "hrd_op_set_idx" );
    988       if( i > 0 )
    989       {
    990         WRITE_FLAG( pcVPS->getCprmsPresentFlag( i ) ? 1 : 0, "cprms_present_flag[i]" );
    991       }
    992       codeHrdParameters(pcVPS->getHrdParameters(i), pcVPS->getCprmsPresentFlag( i ), pcVPS->getMaxTLayers() - 1);
    993     }
    994   }
    995 #if H_MV
     1072      for( UInt i = 0; i < pcVPS->getNumHrdParameters(); i ++ )
     1073      {
     1074        // Only applicable for version 1
     1075        WRITE_UVLC( pcVPS->getHrdOpSetIdx( i ),                "hrd_layer_set_idx" );
     1076        if( i > 0 )
     1077        {
     1078          WRITE_FLAG( pcVPS->getCprmsPresentFlag( i ) ? 1 : 0, "cprms_present_flag[i]" );
     1079        }
     1080        codeHrdParameters(pcVPS->getHrdParameters(i), pcVPS->getCprmsPresentFlag( i ), pcVPS->getMaxTLayers() - 1);
     1081      }
     1082    }
     1083  }
     1084#if NH_MV
    9961085  WRITE_FLAG( pcVPS->getVpsExtensionFlag(),                     "vps_extension_flag" );
    9971086  m_pcBitIf->writeAlignOne();
    9981087  codeVPSExtension( pcVPS );                           
    999 #if H_3D
     1088#if NH_3D
    10001089  WRITE_FLAG( 1,                     "vps_extension2_flag" ); 
    10011090  WRITE_FLAG( 1,                     "vps_3d_extension_flag" );
     
    10091098  WRITE_FLAG( 0,                     "vps_extension_flag" );
    10101099#endif
     1100
    10111101  //future extensions here..
    1012 
    1013   return;
    1014 }
    1015 
    1016 
    1017 
    1018 #if H_MV
    1019 Void TEncCavlc::codeVPSExtension( TComVPS *pcVPS )
     1102  xWriteRbspTrailingBits();
     1103}
     1104
     1105#if NH_MV
     1106Void TEncCavlc::codeVPSExtension( const TComVPS *pcVPS )
    10201107{
    10211108  if( pcVPS->getMaxLayersMinus1() > 0  &&  pcVPS->getVpsBaseLayerInternalFlag() )
     
    10371124
    10381125  if ( pcVPS->getSplittingFlag() )
    1039   {
    1040     pcVPS->setDimensionIdLen( pcVPS->getNumScalabilityTypes( ) - 1 ,pcVPS->inferLastDimsionIdLenMinus1() + 1 );       
     1126  {   
     1127    assert( pcVPS->getDimensionIdLen( pcVPS->getNumScalabilityTypes( ) - 1 ) == pcVPS->inferLastDimsionIdLenMinus1() + 1 );
    10411128  }   
    10421129
     
    12131300  for (Int i = 0; i <= pcVPS->getVpsNumRepFormatsMinus1(); i++ )
    12141301  {   
    1215 
    1216     TComRepFormat* curRepFormat = pcVPS->getRepFormat(i);     
    1217     TComRepFormat* prevRepFormat = i > 0 ? pcVPS->getRepFormat( i - 1) : NULL;
     1302    const TComRepFormat* curRepFormat = pcVPS->getRepFormat(i);     
     1303    const TComRepFormat* prevRepFormat = i > 0 ? pcVPS->getRepFormat( i - 1) : NULL;
    12181304    codeRepFormat( i, curRepFormat ,  prevRepFormat);
    1219 
    12201305  }
    12211306
     
    12911376  else
    12921377  {
    1293     TComVPSVUI* pcVPSVUI = pcVPS->getVPSVUI( );
     1378    const TComVPSVUI* pcVPSVUI = pcVPS->getVPSVUI( );
    12941379    assert( pcVPSVUI );
    1295     pcVPSVUI->inferVpsVui( true );
    1296   }
    1297 
    1298 }
    1299 
    1300 Void TEncCavlc::codeVideoSignalInfo( TComVideoSignalInfo* pcVideoSignalInfo )
     1380    assert( !pcVPSVUI->getCrossLayerIrapAlignedFlag() );   
     1381  }
     1382
     1383}
     1384
     1385Void TEncCavlc::codeVideoSignalInfo( const TComVideoSignalInfo* pcVideoSignalInfo )
    13011386{
    13021387  assert( pcVideoSignalInfo );
     
    13081393}
    13091394
    1310 Void TEncCavlc::codeDpbSize( TComVPS* vps )
     1395Void TEncCavlc::codeDpbSize( const TComVPS* vps )
    13111396{
    1312   TComDpbSize* dpbSize = vps->getDpbSize();
    1313   assert ( dpbSize != 0 );
     1397  const TComDpbSize * dpbSize = vps->getDpbSize();
    13141398
    13151399  for( Int i = 1; i < vps->getNumOutputLayerSets(); i++ )
     
    13611445}
    13621446
    1363 Void TEncCavlc::codeRepFormat( Int i, TComRepFormat* pcRepFormat, TComRepFormat* pcPrevRepFormat )
     1447Void TEncCavlc::codeRepFormat( Int i, const TComRepFormat* pcRepFormat, const TComRepFormat* pcPrevRepFormat )
    13641448{
    13651449  assert( pcRepFormat );
     
    13841468  else
    13851469  {
    1386     pcRepFormat->inferChromaAndBitDepth(pcPrevRepFormat, true );
     1470    pcRepFormat->checkInferChromaAndBitDepth(pcPrevRepFormat );
    13871471  }
    13881472  WRITE_FLAG( pcRepFormat->getConformanceWindowVpsFlag( ) ? 1 : 0 , "conformance_window_vps_flag" );
     
    13961480}
    13971481
    1398 Void TEncCavlc::codeVPSVUI( TComVPS* pcVPS )
     1482Void TEncCavlc::codeVPSVUI( const TComVPS* pcVPS )
    13991483{
    14001484  assert( pcVPS );
    14011485
    1402   TComVPSVUI* pcVPSVUI = pcVPS->getVPSVUI( );
     1486  const TComVPSVUI* pcVPSVUI = pcVPS->getVPSVUI( );
    14031487
    14041488  assert( pcVPSVUI );
     
    14571541  {
    14581542    assert( pcVPSVUI->getVideoSignalInfo( i ) != NULL );
    1459     TComVideoSignalInfo* curVideoSignalInfo = pcVPSVUI->getVideoSignalInfo( i );
     1543    const TComVideoSignalInfo* curVideoSignalInfo = pcVPSVUI->getVideoSignalInfo( i );
    14601544    codeVideoSignalInfo( curVideoSignalInfo );     
    14611545
     
    15431627}
    15441628
    1545 Void TEncCavlc::codeVpsVuiBspHrdParameters( TComVPS* pcVPS )
     1629Void TEncCavlc::codeVpsVuiBspHrdParameters( const TComVPS* pcVPS )
    15461630{
    15471631  assert( pcVPS );
    15481632
    1549   TComVPSVUI* pcVPSVUI = pcVPS->getVPSVUI( );
     1633  const TComVPSVUI* pcVPSVUI = pcVPS->getVPSVUI( );
    15501634
    15511635  assert( pcVPSVUI );
    15521636
    1553   TComVpsVuiBspHrdParameters*  vpsVuiBspHrdP = pcVPSVUI->getVpsVuiBspHrdParameters();
     1637  const TComVpsVuiBspHrdParameters*  vpsVuiBspHrdP = pcVPSVUI->getVpsVuiBspHrdParameters();
    15541638
    15551639  assert ( vpsVuiBspHrdP );
     
    15641648    }
    15651649    WRITE_UVLC( vpsVuiBspHrdP->getNumSubLayerHrdMinus1( i ), "num_sub_layer_hrd_minus1" );
    1566     TComHRD* hrdParameters = vpsVuiBspHrdP->getHrdParametermeters( i );
     1650    const TComHRD* hrdParameters = vpsVuiBspHrdP->getHrdParametermeters( i );
    15671651    codeHrdParameters( hrdParameters, vpsVuiBspHrdP->getCprmsAddPresentFlag( i ), vpsVuiBspHrdP->getNumSubLayerHrdMinus1( i ) );     
    15681652  }
     
    15991683    }
    16001684  } 
    1601 
    16021685
    16031686#endif
    16041687
    1605 #if H_3D
    1606 Void TEncCavlc::codeVPS3dExtension( TComVPS* pcVPS )
     1688#if NH_3D
     1689Void TEncCavlc::codeVPS3dExtension( const TComVPS* pcVPS )
    16071690{
    16081691  WRITE_UVLC( pcVPS->getCpPrecision( ), "cp_precision" );
     
    16341717#endif
    16351718
     1719
    16361720Void TEncCavlc::codeSliceHeader         ( TComSlice* pcSlice )
    16371721{
    1638 #if H_MV
    1639   TComVPS* vps = pcSlice->getVPS();
    1640 #endif
    1641 #if ENC_DEC_TRACE 
    1642   xTraceSliceHeader (pcSlice);
    1643 #endif
     1722#if NH_MV
     1723  const TComVPS* vps = pcSlice->getVPS();
     1724#endif
     1725
     1726#if ENC_DEC_TRACE
     1727#if NH_MV
     1728  tracePSHeader( "Slice", pcSlice->getLayerId() );
     1729#else
     1730  xTraceSliceHeader ();
     1731#endif
     1732#endif
     1733
     1734  const ChromaFormat format                = pcSlice->getSPS()->getChromaFormatIdc();
     1735  const UInt         numberValidComponents = getNumberValidComponents(format);
     1736  const Bool         chromaEnabled         = isChromaEnabled(format);
    16441737
    16451738  //calculate number of bits required for slice address
    1646   Int maxSliceSegmentAddress = pcSlice->getPic()->getNumCUsInFrame();
     1739  Int maxSliceSegmentAddress = pcSlice->getPic()->getNumberOfCtusInFrame();
    16471740  Int bitsSliceSegmentAddress = 0;
    1648   while(maxSliceSegmentAddress>(1<<bitsSliceSegmentAddress)) 
     1741  while(maxSliceSegmentAddress>(1<<bitsSliceSegmentAddress))
    16491742  {
    16501743    bitsSliceSegmentAddress++;
    16511744  }
    1652   Int ctuAddress;
    1653   if (pcSlice->isNextSlice())
    1654   {
    1655     // Calculate slice address
    1656     ctuAddress = (pcSlice->getSliceCurStartCUAddr()/pcSlice->getPic()->getNumPartInCU());
    1657   }
    1658   else
    1659   {
    1660     // Calculate slice address
    1661     ctuAddress = (pcSlice->getSliceSegmentCurStartCUAddr()/pcSlice->getPic()->getNumPartInCU());
    1662   }
     1745  const Int ctuTsAddress = pcSlice->getSliceSegmentCurStartCtuTsAddr();
     1746
    16631747  //write slice address
    1664   Int sliceSegmentAddress = pcSlice->getPic()->getPicSym()->getCUOrderMap(ctuAddress);
    1665 
    1666   WRITE_FLAG( sliceSegmentAddress==0, "first_slice_segment_in_pic_flag" );
     1748  const Int sliceSegmentRsAddress = pcSlice->getPic()->getPicSym()->getCtuTsToRsAddrMap(ctuTsAddress);
     1749
     1750  WRITE_FLAG( sliceSegmentRsAddress==0, "first_slice_segment_in_pic_flag" );
    16671751  if ( pcSlice->getRapPicFlag() )
    16681752  {
    1669 #if SETTING_NO_OUT_PIC_PRIOR
    16701753    WRITE_FLAG( pcSlice->getNoOutputPriorPicsFlag() ? 1 : 0, "no_output_of_prior_pics_flag" );
    1671 #else
    1672     WRITE_FLAG( 0, "no_output_of_prior_pics_flag" );
    1673 #endif
    16741754  }
    16751755#if PPS_FIX_DEPTH
     
    16801760  else
    16811761#endif
     1762
    16821763  WRITE_UVLC( pcSlice->getPPS()->getPPSId(), "slice_pic_parameter_set_id" );
    1683   pcSlice->setDependentSliceSegmentFlag(!pcSlice->isNextSlice());
    1684   if ( pcSlice->getPPS()->getDependentSliceSegmentsEnabledFlag() && (sliceSegmentAddress!=0) )
     1764  if ( pcSlice->getPPS()->getDependentSliceSegmentsEnabledFlag() && (sliceSegmentRsAddress!=0) )
    16851765  {
    16861766    WRITE_FLAG( pcSlice->getDependentSliceSegmentFlag() ? 1 : 0, "dependent_slice_segment_flag" );
    16871767  }
    1688   if(sliceSegmentAddress>0)
    1689   {
    1690     WRITE_CODE( sliceSegmentAddress, bitsSliceSegmentAddress, "slice_segment_address" );
     1768  if(sliceSegmentRsAddress>0)
     1769  {
     1770    WRITE_CODE( sliceSegmentRsAddress, bitsSliceSegmentAddress, "slice_segment_address" );
    16911771  }
    16921772  if ( !pcSlice->getDependentSliceSegmentFlag() )
    16931773  {
    1694 #if H_MV   
     1774
     1775#if NH_MV   
    16951776    Int esb = 0;  //Don't use i, otherwise will shadow something below
    16961777
     
    17161797    pcSlice->checkCrossLayerBlaFlag( );
    17171798
    1718 
    1719 
    17201799    for (; esb < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); esb++)   
    17211800#else
     
    17231802#endif
    17241803    {
    1725       assert(!!"slice_reserved_undetermined_flag[]");
    1726       WRITE_FLAG(0, "slice_reserved_undetermined_flag[]");
    1727     }
     1804      WRITE_FLAG(0, "slice_reserved_flag[]");
     1805    }
     1806
     1807
    17281808
    17291809    WRITE_UVLC( pcSlice->getSliceType(),       "slice_type" );
     
    17341814    }
    17351815
    1736     // in the first version chroma_format_idc is equal to one, thus colour_plane_id will not be present
    1737 #if H_3D_DISABLE_CHROMA
    1738     assert (pcSlice->getSPS()->getChromaFormatIdc() == 1 || pcSlice->getIsDepth() );
    1739     assert (pcSlice->getSPS()->getChromaFormatIdc() == 0 || !pcSlice->getIsDepth() );
    1740 #else
    1741     assert (pcSlice->getSPS()->getChromaFormatIdc() == 1 );
    1742 #endif
    1743     // if( separate_colour_plane_flag  ==  1 )
    1744     //   colour_plane_id                                      u(2)
    1745 #if H_MV
     1816#if NH_MV
    17461817    if ( (pcSlice->getLayerId() > 0 && !vps->getPocLsbNotPresentFlag( pcSlice->getLayerIdInVps())) || !pcSlice->getIdrPicFlag() )
    17471818    {
     
    17521823
    17531824#endif
     1825
    17541826    if( !pcSlice->getIdrPicFlag() )
    17551827    {
    1756 #if !H_MV
     1828#if !NH_MV
    17571829      Int picOrderCntLSB = (pcSlice->getPOC()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC())) & ((1<<pcSlice->getSPS()->getBitsForPOC())-1);
    1758       WRITE_CODE( picOrderCntLSB, pcSlice->getSPS()->getBitsForPOC(), "pic_order_cnt_lsb");
    1759 #endif
    1760       TComReferencePictureSet* rps = pcSlice->getRPS();
    1761      
     1830      WRITE_CODE( picOrderCntLSB, pcSlice->getSPS()->getBitsForPOC(), "slice_pic_order_cnt_lsb");
     1831#endif
     1832      const TComReferencePictureSet* rps = pcSlice->getRPS();
     1833
    17621834      // check for bitstream restriction stating that:
    17631835      // If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0.
     
    17651837      if (pcSlice->isIRAP())
    17661838      {
    1767           for (Int picIdx = 0; picIdx < rps->getNumberOfPictures(); picIdx++)
    1768           {
     1839        for (Int picIdx = 0; picIdx < rps->getNumberOfPictures(); picIdx++)
     1840        {
    17691841          assert (!rps->getUsed(picIdx));
    1770           }
    1771         }
     1842        }
     1843      }
    17721844
    17731845      if(pcSlice->getRPSidx() < 0)
    17741846      {
    17751847        WRITE_FLAG( 0, "short_term_ref_pic_set_sps_flag");
    1776         codeShortTermRefPicSet(pcSlice->getSPS(), rps, true, pcSlice->getSPS()->getRPSList()->getNumberOfReferencePictureSets());
     1848        codeShortTermRefPicSet( rps, true, pcSlice->getSPS()->getRPSList()->getNumberOfReferencePictureSets());
    17771849      }
    17781850      else
     
    17861858        if (numBits > 0)
    17871859        {
    1788           WRITE_CODE( pcSlice->getRPSidx(), numBits, "short_term_ref_pic_set_idx" );         
     1860          WRITE_CODE( pcSlice->getRPSidx(), numBits, "short_term_ref_pic_set_idx" );
    17891861        }
    17901862      }
     
    17961868        UInt ltrpIndex;
    17971869        Int counter = 0;
    1798         for(Int k = rps->getNumberOfPictures()-1; k > rps->getNumberOfPictures()-rps->getNumberOfLongtermPictures()-1; k--)
    1799         {
    1800           if (findMatchingLTRP(pcSlice, &ltrpIndex, rps->getPOC(k), rps->getUsed(k)))
     1870        // WARNING: The following code only works only if a matching long-term RPS is
     1871        //          found in the SPS for ALL long-term pictures
     1872        //          The problem is that the SPS coded long-term pictures are moved to the
     1873        //          beginning of the list which causes a mismatch when no reference picture
     1874        //          list reordering is used
     1875        //          NB: Long-term coding is currently not supported in general by the HM encoder
     1876        for(Int k = rps->getNumberOfPictures()-1; k > rps->getNumberOfPictures()-rps->getNumberOfLongtermPictures()-1; k--)
     1877        {
     1878          if (findMatchingLTRP(pcSlice, &ltrpIndex, rps->getPOC(k), rps->getUsed(k)))
    18011879          {
    18021880            ltrpInSPS[numLtrpInSPS] = ltrpIndex;
     
    18091887        }
    18101888        numLtrpInSH -= numLtrpInSPS;
     1889        // check that either all long-term pictures are coded in SPS or in slice header (no mixing)
     1890        assert (numLtrpInSH==0 || numLtrpInSPS==0);
    18111891
    18121892        Int bitsForLtrpInSPS = 0;
     
    18151895          bitsForLtrpInSPS++;
    18161896        }
    1817         if (pcSlice->getSPS()->getNumLongTermRefPicSPS() > 0) 
     1897        if (pcSlice->getSPS()->getNumLongTermRefPicSPS() > 0)
    18181898        {
    18191899          WRITE_UVLC( numLtrpInSPS, "num_long_term_sps");
     
    18241904        Int prevDeltaMSB = 0, prevLSB = 0;
    18251905        Int offset = rps->getNumberOfNegativePictures() + rps->getNumberOfPositivePictures();
    1826         for(Int i=rps->getNumberOfPictures()-1 ; i > offset-1; i--)
     1906        counter = 0;
     1907        // Warning: If some pictures are moved to ltrpInSPS, i is referring to a wrong index
     1908        //          (mapping would be required)
     1909        for(Int i=rps->getNumberOfPictures()-1 ; i > offset-1; i--, counter++)
    18271910        {
    18281911          if (counter < numLtrpInSPS)
     
    18301913            if (bitsForLtrpInSPS > 0)
    18311914            {
    1832               WRITE_CODE( ltrpInSPS[counter], bitsForLtrpInSPS, "lt_idx_sps[i]");             
     1915              WRITE_CODE( ltrpInSPS[counter], bitsForLtrpInSPS, "lt_idx_sps[i]");
    18331916            }
    18341917          }
    1835           else 
     1918          else
    18361919          {
    18371920            WRITE_CODE( rps->getPocLSBLT(i), pcSlice->getSPS()->getBitsForPOC(), "poc_lsb_lt");
    1838             WRITE_FLAG( rps->getUsed(i), "used_by_curr_pic_lt_flag"); 
     1921            WRITE_FLAG( rps->getUsed(i), "used_by_curr_pic_lt_flag");
    18391922          }
    18401923          WRITE_FLAG( rps->getDeltaPocMSBPresentFlag(i), "delta_poc_msb_present_flag");
     
    18531936            }
    18541937            else
    1855             {             
     1938            {
    18561939              Int differenceInDeltaMSB = rps->getDeltaPocMSBCycleLT(i) - prevDeltaMSB;
    18571940              assert(differenceInDeltaMSB >= 0);
     
    18651948      if (pcSlice->getSPS()->getTMVPFlagsPresent())
    18661949      {
    1867 #if H_MV
     1950#if NH_MV
    18681951        WRITE_FLAG( pcSlice->getEnableTMVPFlag() ? 1 : 0, "slice_temporal_mvp_enabled_flag" );
    18691952#else
    1870         WRITE_FLAG( pcSlice->getEnableTMVPFlag() ? 1 : 0, "slice_temporal_mvp_enable_flag" );
    1871 #endif
    1872       }
    1873     }
    1874 #if H_MV
     1953        WRITE_FLAG( pcSlice->getEnableTMVPFlag() ? 1 : 0, "slice_temporal_mvp_enabled_flag" );
     1954#endif
     1955      }
     1956    }
     1957#if NH_MV
    18751958    Bool interLayerPredLayerIdcPresentFlag = false;
    18761959    Int layerId = pcSlice->getLayerId();
    1877 #if H_3D
     1960#if NH_3D
    18781961    if( pcSlice->getLayerId() > 0 && !vps->getAllRefLayersActiveFlag() && vps->getNumRefListLayers( layerId ) > 0 )
    18791962#else
     
    18821965    {   
    18831966      WRITE_FLAG( pcSlice->getInterLayerPredEnabledFlag( ) ? 1 : 0 , "inter_layer_pred_enabled_flag" );
    1884 #if H_3D
     1967#if NH_3D
    18851968      if( pcSlice->getInterLayerPredEnabledFlag() && vps->getNumRefListLayers( layerId ) > 1 )
    18861969#else
     
    18921975          WRITE_CODE( pcSlice->getNumInterLayerRefPicsMinus1( ), pcSlice->getNumInterLayerRefPicsMinus1Len( ), "num_inter_layer_ref_pics_minus1" );
    18931976        }
    1894 #if H_3D
     1977#if NH_3D
    18951978        if ( pcSlice->getNumActiveRefLayerPics() != vps->getNumRefListLayers( layerId ) )
    18961979#else
     
    19151998#endif
    19161999
    1917 #if H_3D     
     2000#if NH_3D     
    19182001  if( getEncTop()->decProcAnnexI() )
    19192002  {
     
    19242007  }
    19252008#endif
     2009
    19262010    if(pcSlice->getSPS()->getUseSAO())
    19272011    {
    1928       if (pcSlice->getSPS()->getUseSAO())
    1929       {
    1930          WRITE_FLAG( pcSlice->getSaoEnabledFlag(), "slice_sao_luma_flag" );
    1931 #if H_3D_DISABLE_CHROMA
    1932          if ( !pcSlice->getIsDepth() )
    1933          {
    1934          WRITE_FLAG( pcSlice->getSaoEnabledFlagChroma(), "slice_sao_chroma_flag" );
    1935       }
    1936 #else
    1937          WRITE_FLAG( pcSlice->getSaoEnabledFlagChroma(), "slice_sao_chroma_flag" );
    1938 #endif
    1939       }
     2012       WRITE_FLAG( pcSlice->getSaoEnabledFlag(CHANNEL_TYPE_LUMA), "slice_sao_luma_flag" );
     2013       if (chromaEnabled)
     2014       {
     2015         WRITE_FLAG( pcSlice->getSaoEnabledFlag(CHANNEL_TYPE_CHROMA), "slice_sao_chroma_flag" );
     2016       }
    19402017    }
    19412018
     
    19492026#endif
    19502027      WRITE_FLAG( overrideFlag ? 1 : 0,                               "num_ref_idx_active_override_flag");
    1951       if (overrideFlag) 
     2028      if (overrideFlag)
    19522029      {
    19532030        WRITE_UVLC( pcSlice->getNumRefIdx( REF_PIC_LIST_0 ) - 1,      "num_ref_idx_l0_active_minus1" );
     
    19842061            Int length = 1;
    19852062            numRpsCurrTempList0 --;
    1986             while ( numRpsCurrTempList0 >>= 1) 
     2063            while ( numRpsCurrTempList0 >>= 1)
    19872064            {
    19882065              length ++;
     
    19962073      }
    19972074      if(pcSlice->isInterB())
    1998       {   
     2075      {
    19992076        WRITE_FLAG(pcSlice->getRefPicListModification()->getRefPicListModificationFlagL1() ? 1 : 0,       "ref_pic_list_modification_flag_l1" );
    20002077        if (pcSlice->getRefPicListModification()->getRefPicListModificationFlagL1())
     
    20172094      }
    20182095    }
    2019    
     2096
    20202097    if (pcSlice->isInterB())
    20212098    {
     
    20282105      {
    20292106        SliceType sliceType   = pcSlice->getSliceType();
    2030         Int  encCABACTableIdx = pcSlice->getPPS()->getEncCABACTableIdx();
     2107        SliceType  encCABACTableIdx = pcSlice->getEncCABACTableIdx();
    20312108        Bool encCabacInitFlag = (sliceType!=encCABACTableIdx && encCABACTableIdx!=I_SLICE) ? true : false;
    20322109        pcSlice->setCabacInitFlag( encCabacInitFlag );
     
    20532130      xCodePredWeightTable( pcSlice );
    20542131    }
    2055 #if H_3D_IC
     2132#if NH_3D_IC
    20562133    else if( pcSlice->getViewIndex() && ( pcSlice->getSliceType() == P_SLICE || pcSlice->getSliceType() == B_SLICE )
    20572134      && !pcSlice->getIsDepth() && vps->getNumRefListLayers( layerId ) > 0
     
    20622139      if( pcSlice->getApplyIC() )
    20632140      {
    2064         WRITE_FLAG( pcSlice->getIcSkipParseFlag() ? 1 : 0, "ic_skip_mergeidx0" );
    2065       }
    2066     }
    2067 #endif
    2068 #if H_3D_IV_MERGE
     2141        WRITE_FLAG( pcSlice->getIcSkipParseFlag() ? 1 : 0, "slice_ic_disabled_merge_zero_idx_flag" );
     2142      }
     2143    }
     2144#endif
     2145#if NH_3D_IV_MERGE
    20692146    assert(pcSlice->getMaxNumMergeCand()<=MRG_MAX_NUM_CANDS_MEM);
    20702147#else
     
    20732150    if (!pcSlice->isIntra())
    20742151    {
    2075 #if H_3D_IV_MERGE
     2152#if NH_3D_IV_MERGE
    20762153      WRITE_UVLC( ( ( pcSlice->getMpiFlag( ) || pcSlice->getIvMvPredFlag( ) || pcSlice->getViewSynthesisPredFlag( ) ) ? MRG_MAX_NUM_CANDS_MEM : MRG_MAX_NUM_CANDS ) - pcSlice->getMaxNumMergeCand(), "five_minus_max_num_merge_cand");
    20772154#else
     
    20802157    }
    20812158    Int iCode = pcSlice->getSliceQp() - ( pcSlice->getPPS()->getPicInitQPMinus26() + 26 );
    2082     WRITE_SVLC( iCode, "slice_qp_delta" ); 
     2159    WRITE_SVLC( iCode, "slice_qp_delta" );
    20832160    if (pcSlice->getPPS()->getSliceChromaQpFlag())
    20842161    {
    2085       iCode = pcSlice->getSliceQpDeltaCb();
    2086       WRITE_SVLC( iCode, "slice_qp_delta_cb" );
    2087       iCode = pcSlice->getSliceQpDeltaCr();
    2088       WRITE_SVLC( iCode, "slice_qp_delta_cr" );
    2089     }
     2162      if (numberValidComponents > COMPONENT_Cb)
     2163      {
     2164        WRITE_SVLC( pcSlice->getSliceChromaQpDelta(COMPONENT_Cb), "slice_cb_qp_offset" );
     2165      }
     2166      if (numberValidComponents > COMPONENT_Cr)
     2167      {
     2168        WRITE_SVLC( pcSlice->getSliceChromaQpDelta(COMPONENT_Cr), "slice_cr_qp_offset" );
     2169      }
     2170      assert(numberValidComponents <= COMPONENT_Cr+1);
     2171    }
     2172
     2173    if (pcSlice->getPPS()->getPpsRangeExtension().getChromaQpOffsetListEnabledFlag())
     2174    {
     2175      WRITE_FLAG(pcSlice->getUseChromaQpAdj(), "cu_chroma_qp_offset_enabled_flag");
     2176    }
     2177
    20902178    if (pcSlice->getPPS()->getDeblockingFilterControlPresentFlag())
    20912179    {
     
    21052193    }
    21062194
    2107     Bool isSAOEnabled = (!pcSlice->getSPS()->getUseSAO())?(false):(pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma());
     2195    Bool isSAOEnabled = pcSlice->getSPS()->getUseSAO() && (pcSlice->getSaoEnabledFlag(CHANNEL_TYPE_LUMA) || (chromaEnabled && pcSlice->getSaoEnabledFlag(CHANNEL_TYPE_CHROMA)));
    21082196    Bool isDBFEnabled = (!pcSlice->getDeblockingFilterDisable());
    21092197
     
    21122200      WRITE_FLAG(pcSlice->getLFCrossSliceBoundaryFlag()?1:0, "slice_loop_filter_across_slices_enabled_flag");
    21132201    }
    2114 #if H_3D
     2202#if NH_3D
    21152203    if (getEncTop()->decProcAnnexI() )
    21162204    {
    21172205      Int voiInVps = vps->getVoiInVps( pcSlice->getViewIndex() );
     2206#if NH_3D_FIX_TICKET_101
     2207      if( vps->getCpInSliceSegmentHeaderFlag( voiInVps ) )
     2208#else
    21182209      if( vps->getCpInSliceSegmentHeaderFlag( voiInVps ) && !pcSlice->getIsDepth() )
     2210#endif
    21192211      {
    21202212        for( Int m = 0; m < vps->getNumCp( voiInVps ); m++ )
     
    21292221    }
    21302222#endif
    2131   }
    2132 
    2133 
    2134 
    2135 #if !H_MV
     2223
     2224  }
     2225#if !NH_MV
    21362226  if(pcSlice->getPPS()->getSliceHeaderExtensionPresentFlag())
    21372227  {
    2138     WRITE_UVLC(0,"slice_header_extension_length");
     2228    WRITE_UVLC(0,"slice_segment_header_extension_length");
    21392229  }
    21402230#else
     
    22442334  }
    22452335#endif
    2246 }
    2247 
    2248 Void TEncCavlc::codePTL( TComPTL* pcPTL, Bool profilePresentFlag, Int maxNumSubLayersMinus1)
     2336
     2337}
     2338
     2339Void TEncCavlc::codePTL( const TComPTL* pcPTL, Bool profilePresentFlag, Int maxNumSubLayersMinus1)
    22492340{
    22502341  if(profilePresentFlag)
    22512342  {
    2252     codeProfileTier(pcPTL->getGeneralPTL());    // general_...
    2253   }
    2254   WRITE_CODE( pcPTL->getGeneralPTL()->getLevelIdc(), 8, "general_level_idc" );
     2343    codeProfileTier(pcPTL->getGeneralPTL(), false);    // general_...
     2344  }
     2345  WRITE_CODE( Int(pcPTL->getGeneralPTL()->getLevelIdc()), 8, "general_level_idc" );
    22552346
    22562347  for (Int i = 0; i < maxNumSubLayersMinus1; i++)
    22572348  {
    2258 #if !H_MV
    2259     if(profilePresentFlag)
    2260     {
    2261 #endif
    2262       WRITE_FLAG( pcPTL->getSubLayerProfilePresentFlag(i), "sub_layer_profile_present_flag[i]" );
    2263 #if !H_MV
    2264     }
    2265 #endif
    2266    
     2349#if !NH_MV
     2350#endif
     2351    WRITE_FLAG( pcPTL->getSubLayerProfilePresentFlag(i), "sub_layer_profile_present_flag[i]" );
     2352#if !NH_MV
     2353#endif
    22672354    WRITE_FLAG( pcPTL->getSubLayerLevelPresentFlag(i),   "sub_layer_level_present_flag[i]" );
    22682355  }
    2269  
     2356
    22702357  if (maxNumSubLayersMinus1 > 0)
    22712358  {
     
    22752362    }
    22762363  }
    2277  
     2364
    22782365  for(Int i = 0; i < maxNumSubLayersMinus1; i++)
    22792366  {
    2280     if( profilePresentFlag && pcPTL->getSubLayerProfilePresentFlag(i) )
    2281     {
    2282       codeProfileTier(pcPTL->getSubLayerPTL(i));  // sub_layer_...
     2367    if( pcPTL->getSubLayerProfilePresentFlag(i) )
     2368    {
     2369      codeProfileTier(pcPTL->getSubLayerPTL(i), true);  // sub_layer_...
    22832370    }
    22842371    if( pcPTL->getSubLayerLevelPresentFlag(i) )
    22852372    {
    2286       WRITE_CODE( pcPTL->getSubLayerPTL(i)->getLevelIdc(), 8, "sub_layer_level_idc[i]" );
    2287     }
    2288   }
    2289 }
    2290 Void TEncCavlc::codeProfileTier( ProfileTierLevel* ptl )
    2291 {
    2292   WRITE_CODE( ptl->getProfileSpace(), 2 ,     "XXX_profile_space[]");
    2293   WRITE_FLAG( ptl->getTierFlag    (),         "XXX_tier_flag[]"    );
    2294   WRITE_CODE( ptl->getProfileIdc  (), 5 ,     "XXX_profile_idc[]"  );   
     2373      WRITE_CODE( Int(pcPTL->getSubLayerPTL(i)->getLevelIdc()), 8, "sub_layer_level_idc[i]" );
     2374    }
     2375  }
     2376}
     2377
     2378#if ENC_DEC_TRACE || RExt__DECODER_DEBUG_BIT_STATISTICS
     2379Void TEncCavlc::codeProfileTier( const ProfileTierLevel* ptl, const Bool bIsSubLayer )
     2380#define PTL_TRACE_TEXT(txt) bIsSubLayer?("sub_layer_" txt) : ("general_" txt)
     2381#else
     2382Void TEncCavlc::codeProfileTier( const ProfileTierLevel* ptl, const Bool /*bIsSubLayer*/ )
     2383#define PTL_TRACE_TEXT(txt) txt
     2384#endif
     2385{
     2386  WRITE_CODE( ptl->getProfileSpace(), 2 ,      PTL_TRACE_TEXT("profile_space"                   ));
     2387  WRITE_FLAG( ptl->getTierFlag()==Level::HIGH, PTL_TRACE_TEXT("tier_flag"                       ));
     2388  WRITE_CODE( Int(ptl->getProfileIdc()), 5 ,   PTL_TRACE_TEXT("profile_idc"                     ));
    22952389  for(Int j = 0; j < 32; j++)
    22962390  {
    2297     WRITE_FLAG( ptl->getProfileCompatibilityFlag(j), "XXX_profile_compatibility_flag[][j]");   
    2298   }
    2299 
    2300   WRITE_FLAG(ptl->getProgressiveSourceFlag(),   "general_progressive_source_flag");
    2301   WRITE_FLAG(ptl->getInterlacedSourceFlag(),    "general_interlaced_source_flag");
    2302   WRITE_FLAG(ptl->getNonPackedConstraintFlag(), "general_non_packed_constraint_flag");
    2303   WRITE_FLAG(ptl->getFrameOnlyConstraintFlag(), "general_frame_only_constraint_flag");
    2304  
    2305 #if H_MV
     2391    WRITE_FLAG( ptl->getProfileCompatibilityFlag(j), PTL_TRACE_TEXT("profile_compatibility_flag[][j]" ));
     2392  }
     2393
     2394  WRITE_FLAG(ptl->getProgressiveSourceFlag(),   PTL_TRACE_TEXT("progressive_source_flag"         ));
     2395  WRITE_FLAG(ptl->getInterlacedSourceFlag(),    PTL_TRACE_TEXT("interlaced_source_flag"          ));
     2396  WRITE_FLAG(ptl->getNonPackedConstraintFlag(), PTL_TRACE_TEXT("non_packed_constraint_flag"      ));
     2397  WRITE_FLAG(ptl->getFrameOnlyConstraintFlag(), PTL_TRACE_TEXT("frame_only_constraint_flag"      ));
     2398
     2399#if NH_MV
    23062400  if( ptl->getV2ConstraintsPresentFlag() )
    23072401  {
     
    23342428  }
    23352429#else
    2336   WRITE_CODE(0 , 16, "XXX_reserved_zero_44bits[0..15]");
    2337   WRITE_CODE(0 , 16, "XXX_reserved_zero_44bits[16..31]");
    2338   WRITE_CODE(0 , 12, "XXX_reserved_zero_44bits[32..43]");
     2430  if (ptl->getProfileIdc() == Profile::MAINREXT || ptl->getProfileIdc() == Profile::HIGHTHROUGHPUTREXT )
     2431  {
     2432    const UInt         bitDepthConstraint=ptl->getBitDepthConstraint();
     2433    WRITE_FLAG(bitDepthConstraint<=12,          PTL_TRACE_TEXT("max_12bit_constraint_flag"       ));
     2434    WRITE_FLAG(bitDepthConstraint<=10,          PTL_TRACE_TEXT("max_10bit_constraint_flag"       ));
     2435    WRITE_FLAG(bitDepthConstraint<= 8,          PTL_TRACE_TEXT("max_8bit_constraint_flag"        ));
     2436    const ChromaFormat chromaFmtConstraint=ptl->getChromaFormatConstraint();
     2437    WRITE_FLAG(chromaFmtConstraint==CHROMA_422||chromaFmtConstraint==CHROMA_420||chromaFmtConstraint==CHROMA_400, PTL_TRACE_TEXT("max_422chroma_constraint_flag" ));
     2438    WRITE_FLAG(chromaFmtConstraint==CHROMA_420||chromaFmtConstraint==CHROMA_400,                                  PTL_TRACE_TEXT("max_420chroma_constraint_flag" ));
     2439    WRITE_FLAG(chromaFmtConstraint==CHROMA_400,                                                                   PTL_TRACE_TEXT("max_monochrome_constraint_flag"));
     2440    WRITE_FLAG(ptl->getIntraConstraintFlag(),        PTL_TRACE_TEXT("intra_constraint_flag"           ));
     2441    WRITE_FLAG(ptl->getOnePictureOnlyConstraintFlag(), PTL_TRACE_TEXT("one_picture_only_constraint_flag"));
     2442    WRITE_FLAG(ptl->getLowerBitRateConstraintFlag(), PTL_TRACE_TEXT("lower_bit_rate_constraint_flag"  ));
     2443    WRITE_CODE(0 , 16, PTL_TRACE_TEXT("reserved_zero_34bits[0..15]"     ));
     2444    WRITE_CODE(0 , 16, PTL_TRACE_TEXT("reserved_zero_34bits[16..31]"    ));
     2445    WRITE_CODE(0 ,  2, PTL_TRACE_TEXT("reserved_zero_34bits[32..33]"    ));
     2446  }
     2447  else
     2448  {
     2449    WRITE_CODE(0x0000 , 16, PTL_TRACE_TEXT("reserved_zero_43bits[0..15]"     ));
     2450    WRITE_CODE(0x0000 , 16, PTL_TRACE_TEXT("reserved_zero_43bits[16..31]"    ));
     2451    WRITE_CODE(0x000  , 11, PTL_TRACE_TEXT("reserved_zero_43bits[32..42]"    ));
     2452  }
     2453  WRITE_FLAG(false,   PTL_TRACE_TEXT("inbld_flag" ));
     2454#undef PTL_TRACE_TEXT
    23392455#endif
    23402456}
    23412457
    23422458/**
    2343  - write wavefront substreams sizes for the slice header.
    2344  .
    2345  \param pcSlice Where we find the substream size information.
     2459 * Write tiles and wavefront substreams sizes for the slice header (entry points).
     2460 *
     2461 * \param pSlice TComSlice structure that contains the substream size information.
    23462462 */
    23472463Void  TEncCavlc::codeTilesWPPEntryPoint( TComSlice* pSlice )
     
    23512467    return;
    23522468  }
    2353   UInt numEntryPointOffsets = 0, offsetLenMinus1 = 0, maxOffset = 0;
    2354   Int  numZeroSubstreamsAtStartOfSlice  = 0;
    2355   UInt *entryPointOffset = NULL;
    2356   if ( pSlice->getPPS()->getTilesEnabledFlag() )
    2357   {
    2358     numEntryPointOffsets = pSlice->getTileLocationCount();
    2359     entryPointOffset     = new UInt[numEntryPointOffsets];
    2360     for (Int idx=0; idx<pSlice->getTileLocationCount(); idx++)
    2361     {
    2362       if ( idx == 0 )
    2363       {
    2364         entryPointOffset [ idx ] = pSlice->getTileLocation( 0 );
    2365       }
    2366       else
    2367       {
    2368         entryPointOffset [ idx ] = pSlice->getTileLocation( idx ) - pSlice->getTileLocation( idx-1 );
    2369       }
    2370 
    2371       if ( entryPointOffset[ idx ] > maxOffset )
    2372       {
    2373         maxOffset = entryPointOffset[ idx ];
    2374       }
    2375     }
    2376   }
    2377   else if ( pSlice->getPPS()->getEntropyCodingSyncEnabledFlag() )
    2378   {
    2379     UInt* pSubstreamSizes               = pSlice->getSubstreamSizes();
    2380     Int maxNumParts                       = pSlice->getPic()->getNumPartInCU();
    2381     numZeroSubstreamsAtStartOfSlice       = pSlice->getSliceSegmentCurStartCUAddr()/maxNumParts/pSlice->getPic()->getFrameWidthInCU();
    2382     Int  numZeroSubstreamsAtEndOfSlice    = pSlice->getPic()->getFrameHeightInCU()-1 - ((pSlice->getSliceSegmentCurEndCUAddr()-1)/maxNumParts/pSlice->getPic()->getFrameWidthInCU());
    2383     numEntryPointOffsets                  = pSlice->getPPS()->getNumSubstreams() - numZeroSubstreamsAtStartOfSlice - numZeroSubstreamsAtEndOfSlice - 1;
    2384     pSlice->setNumEntryPointOffsets(numEntryPointOffsets);
    2385     entryPointOffset           = new UInt[numEntryPointOffsets];
    2386     for (Int idx=0; idx<numEntryPointOffsets; idx++)
    2387     {
    2388       entryPointOffset[ idx ] = ( pSubstreamSizes[ idx+numZeroSubstreamsAtStartOfSlice ] >> 3 ) ;
    2389       if ( entryPointOffset[ idx ] > maxOffset )
    2390       {
    2391         maxOffset = entryPointOffset[ idx ];
    2392       }
    2393     }
    2394   }
     2469  UInt maxOffset = 0;
     2470  for(Int idx=0; idx<pSlice->getNumberOfSubstreamSizes(); idx++)
     2471  {
     2472    UInt offset=pSlice->getSubstreamSize(idx);
     2473    if ( offset > maxOffset )
     2474    {
     2475      maxOffset = offset;
     2476    }
     2477  }
     2478
    23952479  // Determine number of bits "offsetLenMinus1+1" required for entry point information
    2396   offsetLenMinus1 = 0;
     2480  UInt offsetLenMinus1 = 0;
    23972481  while (maxOffset >= (1u << (offsetLenMinus1 + 1)))
    23982482  {
    23992483    offsetLenMinus1++;
    2400     assert(offsetLenMinus1 + 1 < 32);   
    2401   }
    2402 
    2403   WRITE_UVLC(numEntryPointOffsets, "num_entry_point_offsets");
    2404   if (numEntryPointOffsets>0)
     2484    assert(offsetLenMinus1 + 1 < 32);
     2485  }
     2486
     2487  WRITE_UVLC(pSlice->getNumberOfSubstreamSizes(), "num_entry_point_offsets");
     2488  if (pSlice->getNumberOfSubstreamSizes()>0)
    24052489  {
    24062490    WRITE_UVLC(offsetLenMinus1, "offset_len_minus1");
    2407   }
    2408 
    2409   for (UInt idx=0; idx<numEntryPointOffsets; idx++)
    2410   {
    2411     WRITE_CODE(entryPointOffset[ idx ]-1, offsetLenMinus1+1, "entry_point_offset_minus1");
    2412   }
    2413 
    2414   delete [] entryPointOffset;
    2415 }
    2416 
    2417 Void TEncCavlc::codeTerminatingBit      ( UInt uilsLast )
     2491
     2492    for (UInt idx=0; idx<pSlice->getNumberOfSubstreamSizes(); idx++)
     2493    {
     2494      WRITE_CODE(pSlice->getSubstreamSize(idx)-1, offsetLenMinus1+1, "entry_point_offset_minus1");
     2495    }
     2496  }
     2497}
     2498
     2499Void TEncCavlc::codeTerminatingBit      ( UInt /*uilsLast*/ )
    24182500{
    24192501}
     
    24232505}
    24242506
    2425 Void TEncCavlc::codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
     2507Void TEncCavlc::codeMVPIdx ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, RefPicList /*eRefList*/ )
    24262508{
    24272509  assert(0);
    24282510}
    24292511
    2430 Void TEncCavlc::codePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
     2512Void TEncCavlc::codePartSize( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
    24312513{
    24322514  assert(0);
    24332515}
    24342516
    2435 Void TEncCavlc::codePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx )
     2517Void TEncCavlc::codePredMode( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/ )
    24362518{
    24372519  assert(0);
    24382520}
    24392521
    2440 Void TEncCavlc::codeMergeFlag    ( TComDataCU* pcCU, UInt uiAbsPartIdx )
     2522Void TEncCavlc::codeMergeFlag    ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/ )
    24412523{
    24422524  assert(0);
    24432525}
    24442526
    2445 Void TEncCavlc::codeMergeIndex    ( TComDataCU* pcCU, UInt uiAbsPartIdx )
     2527Void TEncCavlc::codeMergeIndex    ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/ )
    24462528{
    24472529  assert(0);
    24482530}
    24492531
    2450 #if H_3D_ARP
     2532#if NH_3D_ARP
    24512533Void TEncCavlc::codeARPW( TComDataCU* pcCU, UInt uiAbsPartIdx )
    24522534{
     
    24552537#endif
    24562538
    2457 #if H_3D_IC
     2539#if NH_3D_IC
    24582540Void TEncCavlc::codeICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
    24592541{
     
    24622544#endif
    24632545
    2464 Void TEncCavlc::codeInterModeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiEncMode )
     2546Void TEncCavlc::codeInterModeFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/, UInt /*uiEncMode*/ )
    24652547{
    24662548  assert(0);
    24672549}
    24682550
    2469 Void TEncCavlc::codeCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
     2551Void TEncCavlc::codeCUTransquantBypassFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/ )
    24702552{
    24712553  assert(0);
    24722554}
    24732555
    2474 Void TEncCavlc::codeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
     2556Void TEncCavlc::codeSkipFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/ )
    24752557{
    24762558  assert(0);
    24772559}
    2478 #if H_3D
     2560#if NH_3D_DIS
    24792561Void TEncCavlc::codeDIS( TComDataCU* pcCU, UInt uiAbsPartIdx )
    24802562{
     
    24832565#endif
    24842566
    2485 Void TEncCavlc::codeSplitFlag   ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
     2567Void TEncCavlc::codeSplitFlag   ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
    24862568{
    24872569  assert(0);
    24882570}
    24892571
    2490 Void TEncCavlc::codeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx )
     2572Void TEncCavlc::codeTransformSubdivFlag( UInt /*uiSymbol*/, UInt /*uiCtx*/ )
    24912573{
    24922574  assert(0);
    24932575}
    24942576
    2495 Void TEncCavlc::codeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth )
     2577Void TEncCavlc::codeQtCbf( TComTU& /*rTu*/, const ComponentID /*compID*/, const Bool /*lowestLevel*/ )
    24962578{
    24972579  assert(0);
    24982580}
    24992581
    2500 Void TEncCavlc::codeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx )
     2582Void TEncCavlc::codeQtRootCbf( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/ )
    25012583{
    25022584  assert(0);
    25032585}
    25042586
    2505 Void TEncCavlc::codeQtCbfZero( TComDataCU* pcCU, TextType eType, UInt uiTrDepth )
     2587Void TEncCavlc::codeQtCbfZero( TComTU& /*rTu*/, const ChannelType /*chType*/ )
    25062588{
    25072589  assert(0);
    25082590}
    2509 Void TEncCavlc::codeQtRootCbfZero( TComDataCU* pcCU )
     2591Void TEncCavlc::codeQtRootCbfZero( )
    25102592{
    25112593  assert(0);
    25122594}
    25132595
    2514 Void TEncCavlc::codeTransformSkipFlags (TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, TextType eTType )
     2596Void TEncCavlc::codeTransformSkipFlags (TComTU& /*rTu*/, ComponentID /*component*/ )
    25152597{
    25162598  assert(0);
     
    25222604 * \returns Void
    25232605 */
    2524 Void TEncCavlc::codeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx )
     2606Void TEncCavlc::codeIPCMInfo( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/ )
    25252607{
    25262608  assert(0);
    25272609}
    25282610
    2529 Void TEncCavlc::codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool isMultiple)
     2611Void TEncCavlc::codeIntraDirLumaAng( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, Bool /*isMultiple*/)
    25302612{
    25312613  assert(0);
    25322614}
    25332615
    2534 Void TEncCavlc::codeIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx )
     2616Void TEncCavlc::codeIntraDirChroma( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/ )
    25352617{
    25362618  assert(0);
    25372619}
    25382620
    2539 Void TEncCavlc::codeInterDir( TComDataCU* pcCU, UInt uiAbsPartIdx )
     2621Void TEncCavlc::codeInterDir( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/ )
    25402622{
    25412623  assert(0);
    25422624}
    25432625
    2544 Void TEncCavlc::codeRefFrmIdx( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
     2626Void TEncCavlc::codeRefFrmIdx( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, RefPicList /*eRefList*/ )
    25452627{
    25462628  assert(0);
    25472629}
    25482630
    2549 Void TEncCavlc::codeMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
     2631Void TEncCavlc::codeMvd( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, RefPicList /*eRefList*/ )
    25502632{
    25512633  assert(0);
    25522634}
    25532635
     2636Void TEncCavlc::codeCrossComponentPrediction( TComTU& /*rTu*/, ComponentID /*compID*/ )
     2637{
     2638  assert(0);
     2639}
     2640
    25542641Void TEncCavlc::codeDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx )
    25552642{
    25562643  Int iDQp  = pcCU->getQP( uiAbsPartIdx ) - pcCU->getRefQP( uiAbsPartIdx );
    25572644
    2558   Int qpBdOffsetY =  pcCU->getSlice()->getSPS()->getQpBDOffsetY();
     2645  Int qpBdOffsetY =  pcCU->getSlice()->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA);
    25592646  iDQp = (iDQp + 78 + qpBdOffsetY + (qpBdOffsetY/2)) % (52 + qpBdOffsetY) - 26 - (qpBdOffsetY/2);
    25602647
    25612648  xWriteSvlc( iDQp );
    2562  
     2649
    25632650  return;
    25642651}
    25652652
    2566 Void TEncCavlc::codeCoeffNxN    ( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType )
     2653Void TEncCavlc::codeChromaQpAdjustment( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/ )
    25672654{
    25682655  assert(0);
    25692656}
    25702657
    2571 Void TEncCavlc::estBit( estBitsSbacStruct* pcEstBitsCabac, Int width, Int height, TextType eTType )
     2658Void TEncCavlc::codeCoeffNxN    ( TComTU& /*rTu*/, TCoeff* /*pcCoef*/, const ComponentID /*compID*/ )
     2659{
     2660  assert(0);
     2661}
     2662
     2663Void TEncCavlc::estBit( estBitsSbacStruct* /*pcEstBitsCabac*/, Int /*width*/, Int /*height*/, ChannelType /*chType*/ )
    25722664{
    25732665  // printf("error : no VLC mode support in this version\n");
     
    25792671// ====================================================================================================================
    25802672
    2581 /** code explicit wp tables
    2582  * \param TComSlice* pcSlice
    2583  * \returns Void
    2584  */
     2673//! Code weighted prediction tables
    25852674Void TEncCavlc::xCodePredWeightTable( TComSlice* pcSlice )
    25862675{
    2587   wpScalingParam  *wp;
    2588 #if  H_3D_DISABLE_CHROMA
    2589   Bool            bChroma     = !pcSlice->getIsDepth(); // color always present in HEVC ?
    2590 #else
    2591   Bool            bChroma     = true; // color always present in HEVC ?
    2592 #endif
    2593   Int             iNbRef       = (pcSlice->getSliceType() == B_SLICE ) ? (2) : (1);
    2594   Bool            bDenomCoded  = false;
    2595   UInt            uiMode = 0;
    2596   UInt            uiTotalSignalledWeightFlags = 0;
     2676  WPScalingParam  *wp;
     2677  const ChromaFormat    format                = pcSlice->getPic()->getChromaFormat();
     2678  const UInt            numberValidComponents = getNumberValidComponents(format);
     2679  const Bool            bChroma               = isChromaEnabled(format);
     2680  const Int             iNbRef                = (pcSlice->getSliceType() == B_SLICE ) ? (2) : (1);
     2681        Bool            bDenomCoded           = false;
     2682        UInt            uiTotalSignalledWeightFlags = 0;
     2683
    25972684  if ( (pcSlice->getSliceType()==P_SLICE && pcSlice->getPPS()->getUseWP()) || (pcSlice->getSliceType()==B_SLICE && pcSlice->getPPS()->getWPBiPred()) )
    25982685  {
    2599     uiMode = 1; // explicit
    2600   }
    2601   if(uiMode == 1)
    2602   {
    2603 
    2604     for ( Int iNumRef=0 ; iNumRef<iNbRef ; iNumRef++ )
     2686    for ( Int iNumRef=0 ; iNumRef<iNbRef ; iNumRef++ ) // loop over l0 and l1 syntax elements
    26052687    {
    26062688      RefPicList  eRefPicList = ( iNumRef ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
    26072689
    2608       for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
     2690      // NOTE: wp[].uiLog2WeightDenom and wp[].bPresentFlag are actually per-channel-type settings.
     2691
     2692      for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
    26092693      {
    26102694        pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
    2611         if ( !bDenomCoded ) 
     2695        if ( !bDenomCoded )
    26122696        {
    26132697          Int iDeltaDenom;
    2614           WRITE_UVLC( wp[0].uiLog2WeightDenom, "luma_log2_weight_denom" );     // ue(v): luma_log2_weight_denom
     2698          WRITE_UVLC( wp[COMPONENT_Y].uiLog2WeightDenom, "luma_log2_weight_denom" );
    26152699
    26162700          if( bChroma )
    26172701          {
    2618             iDeltaDenom = (wp[1].uiLog2WeightDenom - wp[0].uiLog2WeightDenom);
    2619             WRITE_SVLC( iDeltaDenom, "delta_chroma_log2_weight_denom" );       // se(v): delta_chroma_log2_weight_denom
     2702            assert(wp[COMPONENT_Cb].uiLog2WeightDenom == wp[COMPONENT_Cr].uiLog2WeightDenom); // check the channel-type settings are consistent across components.
     2703            iDeltaDenom = (wp[COMPONENT_Cb].uiLog2WeightDenom - wp[COMPONENT_Y].uiLog2WeightDenom);
     2704            WRITE_SVLC( iDeltaDenom, "delta_chroma_log2_weight_denom" );
    26202705          }
    26212706          bDenomCoded = true;
    26222707        }
    2623         WRITE_FLAG( wp[0].bPresentFlag, "luma_weight_lX_flag" );               // u(1): luma_weight_lX_flag
    2624         uiTotalSignalledWeightFlags += wp[0].bPresentFlag;
    2625       }
    2626       if (bChroma) 
    2627       {
    2628         for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) 
     2708        WRITE_FLAG( wp[COMPONENT_Y].bPresentFlag, iNumRef==0?"luma_weight_l0_flag[i]":"luma_weight_l1_flag[i]" );
     2709        uiTotalSignalledWeightFlags += wp[COMPONENT_Y].bPresentFlag;
     2710      }
     2711      if (bChroma)
     2712      {
     2713        for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
    26292714        {
    26302715          pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
    2631           WRITE_FLAG( wp[1].bPresentFlag, "chroma_weight_lX_flag" );           // u(1): chroma_weight_lX_flag
    2632           uiTotalSignalledWeightFlags += 2*wp[1].bPresentFlag;
    2633         }
    2634       }
    2635 
    2636       for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
     2716          assert(wp[COMPONENT_Cb].bPresentFlag == wp[COMPONENT_Cr].bPresentFlag); // check the channel-type settings are consistent across components.
     2717          WRITE_FLAG( wp[COMPONENT_Cb].bPresentFlag, iNumRef==0?"chroma_weight_l0_flag[i]":"chroma_weight_l1_flag[i]" );
     2718          uiTotalSignalledWeightFlags += 2*wp[COMPONENT_Cb].bPresentFlag;
     2719        }
     2720      }
     2721
     2722      for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
    26372723      {
    26382724        pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
    2639         if ( wp[0].bPresentFlag )
    2640         {
    2641           Int iDeltaWeight = (wp[0].iWeight - (1<<wp[0].uiLog2WeightDenom));
    2642           WRITE_SVLC( iDeltaWeight, "delta_luma_weight_lX" );                  // se(v): delta_luma_weight_lX
    2643           WRITE_SVLC( wp[0].iOffset, "luma_offset_lX" );                       // se(v): luma_offset_lX
    2644         }
    2645 
    2646         if ( bChroma ) 
    2647         {
    2648           if ( wp[1].bPresentFlag )
     2725        if ( wp[COMPONENT_Y].bPresentFlag )
     2726        {
     2727          Int iDeltaWeight = (wp[COMPONENT_Y].iWeight - (1<<wp[COMPONENT_Y].uiLog2WeightDenom));
     2728          WRITE_SVLC( iDeltaWeight, iNumRef==0?"delta_luma_weight_l0[i]":"delta_luma_weight_l1[i]" );
     2729          WRITE_SVLC( wp[COMPONENT_Y].iOffset, iNumRef==0?"luma_offset_l0[i]":"luma_offset_l1[i]" );
     2730        }
     2731
     2732        if ( bChroma )
     2733        {
     2734          if ( wp[COMPONENT_Cb].bPresentFlag )
    26492735          {
    2650             for ( Int j=1 ; j<3 ; j++ )
     2736            for ( Int j = COMPONENT_Cb ; j < numberValidComponents ; j++ )
    26512737            {
    2652               Int iDeltaWeight = (wp[j].iWeight - (1<<wp[1].uiLog2WeightDenom));
    2653               WRITE_SVLC( iDeltaWeight, "delta_chroma_weight_lX" );            // se(v): delta_chroma_weight_lX
    2654 
    2655               Int pred = ( 128 - ( ( 128*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) );
     2738              assert(wp[COMPONENT_Cb].uiLog2WeightDenom == wp[COMPONENT_Cr].uiLog2WeightDenom);
     2739              Int iDeltaWeight = (wp[j].iWeight - (1<<wp[COMPONENT_Cb].uiLog2WeightDenom));
     2740              WRITE_SVLC( iDeltaWeight, iNumRef==0?"delta_chroma_weight_l0[i]":"delta_chroma_weight_l1[i]" );
     2741
     2742              Int range=pcSlice->getSPS()->getSpsRangeExtension().getHighPrecisionOffsetsEnabledFlag() ? (1<<pcSlice->getSPS()->getBitDepth(CHANNEL_TYPE_CHROMA))/2 : 128;
     2743              Int pred = ( range - ( ( range*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) );
    26562744              Int iDeltaChroma = (wp[j].iOffset - pred);
    2657               WRITE_SVLC( iDeltaChroma, "delta_chroma_offset_lX" );            // se(v): delta_chroma_offset_lX
     2745              WRITE_SVLC( iDeltaChroma, iNumRef==0?"delta_chroma_offset_l0[i]":"delta_chroma_offset_l1[i]" );
    26582746            }
    26592747          }
     
    26682756 *  \param scalingList quantization matrix information
    26692757 */
    2670 Void TEncCavlc::codeScalingList( TComScalingList* scalingList )
    2671 {
    2672   UInt listId,sizeId;
    2673   Bool scalingListPredModeFlag;
    2674 
    2675     //for each size
    2676     for(sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
    2677     {
    2678       for(listId = 0; listId < g_scalingListNum[sizeId]; listId++)
    2679       {
    2680         scalingListPredModeFlag = scalingList->checkPredMode( sizeId, listId );
    2681         WRITE_FLAG( scalingListPredModeFlag, "scaling_list_pred_mode_flag" );
    2682         if(!scalingListPredModeFlag)// Copy Mode
    2683         {
    2684           WRITE_UVLC( (Int)listId - (Int)scalingList->getRefMatrixId (sizeId,listId), "scaling_list_pred_matrix_id_delta");
    2685         }
    2686         else// DPCM Mode
    2687         {
    2688           xCodeScalingList(scalingList, sizeId, listId);
    2689         }
    2690       }
    2691     }
     2758Void TEncCavlc::codeScalingList( const TComScalingList &scalingList )
     2759{
     2760  //for each size
     2761  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
     2762  {
     2763    const Int predListStep = (sizeId == SCALING_LIST_32x32? (SCALING_LIST_NUM/NUMBER_OF_PREDICTION_MODES) : 1); // if 32x32, skip over chroma entries.
     2764
     2765    for(UInt listId = 0; listId < SCALING_LIST_NUM; listId+=predListStep)
     2766    {
     2767      Bool scalingListPredModeFlag = scalingList.getScalingListPredModeFlag(sizeId, listId);
     2768      WRITE_FLAG( scalingListPredModeFlag, "scaling_list_pred_mode_flag" );
     2769      if(!scalingListPredModeFlag)// Copy Mode
     2770      {
     2771        if (sizeId == SCALING_LIST_32x32)
     2772        {
     2773          // adjust the code, to cope with the missing chroma entries
     2774          WRITE_UVLC( ((Int)listId - (Int)scalingList.getRefMatrixId (sizeId,listId)) / (SCALING_LIST_NUM/NUMBER_OF_PREDICTION_MODES), "scaling_list_pred_matrix_id_delta");
     2775        }
     2776        else
     2777        {
     2778          WRITE_UVLC( (Int)listId - (Int)scalingList.getRefMatrixId (sizeId,listId), "scaling_list_pred_matrix_id_delta");
     2779        }
     2780      }
     2781      else// DPCM Mode
     2782      {
     2783        xCodeScalingList(&scalingList, sizeId, listId);
     2784      }
     2785    }
     2786  }
    26922787  return;
    26932788}
    26942789/** code DPCM
    26952790 * \param scalingList quantization matrix information
    2696  * \param sizeIdc size index
    2697  * \param listIdc list index
     2791 * \param sizeId      size index
     2792 * \param listId      list index
    26982793 */
    2699 Void TEncCavlc::xCodeScalingList(TComScalingList* scalingList, UInt sizeId, UInt listId)
     2794Void TEncCavlc::xCodeScalingList(const TComScalingList* scalingList, UInt sizeId, UInt listId)
    27002795{
    27012796  Int coefNum = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]);
    2702   UInt* scan  = (sizeId == 0) ? g_auiSigLastScan [ SCAN_DIAG ] [ 1 ] :  g_sigLastScanCG32x32;
     2797  UInt* scan  = g_scanOrder[SCAN_UNGROUPED][SCAN_DIAG][sizeId==0 ? 2 : 3][sizeId==0 ? 2 : 3];
    27032798  Int nextCoef = SCALING_LIST_START_VALUE;
    27042799  Int data;
    2705   Int *src = scalingList->getScalingListAddress(sizeId, listId);
     2800  const Int *src = scalingList->getScalingListAddress(sizeId, listId);
    27062801    if( sizeId > SCALING_LIST_8x8 )
    27072802    {
     
    27392834  return false;
    27402835}
    2741 Bool TComScalingList::checkPredMode(UInt sizeId, UInt listId)
    2742 {
    2743   for(Int predListIdx = (Int)listId ; predListIdx >= 0; predListIdx--)
    2744   {
    2745     if( !memcmp(getScalingListAddress(sizeId,listId),((listId == predListIdx) ?
    2746       getScalingListDefaultAddress(sizeId, predListIdx): getScalingListAddress(sizeId, predListIdx)),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])) // check value of matrix
    2747      && ((sizeId < SCALING_LIST_16x16) || (getScalingListDC(sizeId,listId) == getScalingListDC(sizeId,predListIdx)))) // check DC value
    2748     {
    2749       setRefMatrixId(sizeId, listId, predListIdx);
    2750       return false;
    2751     }
    2752   }
    2753   return true;
    2754 }
    2755 
    2756 #if H_3D_INTER_SDC
    2757 Void TEncCavlc::codeDeltaDC( TComDataCU* pcCU, UInt uiAbsPartIdx )
     2836
     2837Void TEncCavlc::codeExplicitRdpcmMode( TComTU& /*rTu*/, const ComponentID /*compID*/ )
     2838 {
     2839   assert(0);
     2840 }
     2841#if NH_3D_SDC_INTRA || NH_3D_SDC_INTER
     2842Void TEncCavlc::codeSDCFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx )
    27582843{
    27592844  assert(0);
    27602845}
    2761 
    2762 Void TEncCavlc::codeSDCFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx )
     2846#endif
     2847   
     2848#if NH_3D_DBBP
     2849Void TEncCavlc::codeDBBPFlag    ( TComDataCU* pcCU, UInt uiAbsPartIdx )
    27632850{
    27642851  assert(0);
    27652852}
    2766 
    2767 #endif
    2768    
    2769 #if H_3D_DBBP
    2770 Void TEncCavlc::codeDBBPFlag    ( TComDataCU* pcCU, UInt uiAbsPartIdx )
    2771 {
    2772   assert(0);
    2773 }
    2774 #endif
     2853#endif
     2854
     2855
    27752856//! \}
Note: See TracChangeset for help on using the changeset viewer.