Changeset 608 in 3DVCSoftware for trunk/source/Lib/TLibEncoder/TEncCavlc.cpp


Ignore:
Timestamp:
1 Sep 2013, 22:47:26 (11 years ago)
Author:
tech
Message:

Merged DEV-2.0-dev0@604.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/Lib/TLibEncoder/TEncCavlc.cpp

    r443 r608  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2012, ITU/ISO/IEC
     6 * Copyright (c) 2010-2013, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    3939#include "TEncCavlc.h"
    4040#include "SEIwrite.h"
     41#include "../TLibCommon/TypeDef.h"
    4142
    4243//! \ingroup TLibEncoder
     
    4546#if ENC_DEC_TRACE
    4647
    47 #define WRITE_CODE( value, length, name)    xWriteCodeTr ( value, length, name )
    48 #define WRITE_UVLC( value,         name)    xWriteUvlcTr ( value,         name )
    49 #define WRITE_SVLC( value,         name)    xWriteSvlcTr ( value,         name )
    50 #define WRITE_FLAG( value,         name)    xWriteFlagTr ( value,         name )
    51 
    52 Void  xWriteUvlcTr          ( UInt value,               const Char *pSymbolName);
    53 Void  xWriteSvlcTr          ( Int  value,               const Char *pSymbolName);
    54 Void  xWriteFlagTr          ( UInt value,               const Char *pSymbolName);
    55 
    5648Void  xTraceSPSHeader (TComSPS *pSPS)
    5749{
     50#if H_MV_ENC_DEC_TRAC
     51  fprintf( g_hTrace, "=========== Sequence Parameter Set ===========\n" );
     52#else
    5853  fprintf( g_hTrace, "=========== Sequence Parameter Set ID: %d ===========\n", pSPS->getSPSId() );
     54#endif
    5955}
    6056
    6157Void  xTracePPSHeader (TComPPS *pPPS)
    6258{
     59#if H_MV_ENC_DEC_TRAC
     60  fprintf( g_hTrace, "=========== Picture Parameter Set ===========\n" );
     61#else
    6362  fprintf( g_hTrace, "=========== Picture Parameter Set ID: %d ===========\n", pPPS->getPPSId() );
    64 }
    65 
    66 Void  xTraceAPSHeader (TComAPS *pAPS)
    67 {
    68   fprintf( g_hTrace, "=========== Adaptation Parameter Set ===========\n");
     63#endif
    6964}
    7065
     
    7368  fprintf( g_hTrace, "=========== Slice ===========\n");
    7469}
    75 
    76 
    77 Void  TEncCavlc::xWriteCodeTr (UInt value, UInt  length, const Char *pSymbolName)
    78 {
    79   xWriteCode (value,length);
    80   fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
    81   fprintf( g_hTrace, "%-40s u(%d) : %d\n", pSymbolName, length, value );
    82 }
    83 
    84 Void  TEncCavlc::xWriteUvlcTr (UInt value, const Char *pSymbolName)
    85 {
    86   xWriteUvlc (value);
    87   fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
    88   fprintf( g_hTrace, "%-40s u(v) : %d\n", pSymbolName, value );
    89 }
    90 
    91 Void  TEncCavlc::xWriteSvlcTr (Int value, const Char *pSymbolName)
    92 {
    93   xWriteSvlc(value);
    94   fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
    95   fprintf( g_hTrace, "%-40s s(v) : %d\n", pSymbolName, value );
    96 }
    97 
    98 Void  TEncCavlc::xWriteFlagTr(UInt value, const Char *pSymbolName)
    99 {
    100   xWriteFlag(value);
    101   fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
    102   fprintf( g_hTrace, "%-40s u(1) : %d\n", pSymbolName, value );
    103 }
    104 
    105 #else
    106 
    107 #define WRITE_CODE( value, length, name)     xWriteCode ( value, length )
    108 #define WRITE_UVLC( value,         name)     xWriteUvlc ( value )
    109 #define WRITE_SVLC( value,         name)     xWriteSvlc ( value )
    110 #define WRITE_FLAG( value,         name)     xWriteFlag ( value )
    11170
    11271#endif
     
    12281  m_pcBitIf           = NULL;
    12382  m_uiCoeffCost       = 0;
    124   m_bAlfCtrl = false;
    125   m_uiMaxAlfCtrlDepth = 0;
    126  
    127   m_iSliceGranularity = 0;
    12883}
    12984
     
    14196}
    14297
    143 /**
    144  * marshall the SEI message sei.
    145  */
    146 void TEncCavlc::codeSEI(const SEI& sei)
    147 {
    148   writeSEImessage(*m_pcBitIf, sei);
    149 }
    150 
    151 Void  TEncCavlc::codeAPSInitInfo(TComAPS* pcAPS)
    152 {
    153 
    154 #if ENC_DEC_TRACE 
    155   xTraceAPSHeader(pcAPS);
    156 #endif
    157   //APS ID
    158   WRITE_UVLC( pcAPS->getAPSID(), "aps_id" );
    159 
    160   WRITE_FLAG( pcAPS->getScalingListEnabled()?1:0, "aps_scaling_list_data_present_flag");
    161   //DF flag
    162   WRITE_FLAG(pcAPS->getLoopFilterOffsetInAPS()?1:0, "aps_deblocking_filter_flag");
    163 }
    164 Void TEncCavlc::codeAPSAlflag(UInt uiCode)
    165 {
    166   WRITE_FLAG(uiCode, "aps_adaptive_loop_filter_flag");
    167 }
    16898
    16999Void TEncCavlc::codeDFFlag(UInt uiCode, const Char *pSymbolName)
     
    176106}
    177107
    178 Void TEncCavlc::codeShortTermRefPicSet( TComSPS* pcSPS, TComReferencePictureSet* rps )
     108Void TEncCavlc::codeShortTermRefPicSet( TComSPS* pcSPS, TComReferencePictureSet* rps, Bool calledFromSliceHeader, Int idx)
    179109{
    180110#if PRINT_RPS_INFO
    181   int lastBits = getNumberOfWrittenBits();
    182 #endif
     111  Int lastBits = getNumberOfWrittenBits();
     112#endif
     113  if (idx > 0)
     114  {
    183115  WRITE_FLAG( rps->getInterRPSPrediction(), "inter_ref_pic_set_prediction_flag" ); // inter_RPS_prediction_flag
    184   if (rps->getInterRPSPrediction())
     116  }
     117  if (rps->getInterRPSPrediction())
    185118  {
    186119    Int deltaRPS = rps->getDeltaRPS();
    187     WRITE_UVLC( rps->getDeltaRIdxMinus1(), "delta_idx_minus1" ); // delta index of the Reference Picture Set used for prediction minus 1
     120    if(calledFromSliceHeader)
     121    {
     122      WRITE_UVLC( rps->getDeltaRIdxMinus1(), "delta_idx_minus1" ); // delta index of the Reference Picture Set used for prediction minus 1
     123    }
     124
    188125    WRITE_CODE( (deltaRPS >=0 ? 0: 1), 1, "delta_rps_sign" ); //delta_rps_sign
    189126    WRITE_UVLC( abs(deltaRPS) - 1, "abs_delta_rps_minus1"); // absolute delta RPS minus 1
     
    232169#endif
    233170 
    234   WRITE_UVLC( pcPPS->getPPSId(),                             "pic_parameter_set_id" );
    235   WRITE_UVLC( pcPPS->getSPSId(),                             "seq_parameter_set_id" );
    236 
     171  WRITE_UVLC( pcPPS->getPPSId(),                             "pps_pic_parameter_set_id" );
     172  WRITE_UVLC( pcPPS->getSPSId(),                             "pps_seq_parameter_set_id" );
     173  WRITE_FLAG( pcPPS->getDependentSliceSegmentsEnabledFlag()    ? 1 : 0, "dependent_slice_segments_enabled_flag" );
     174  WRITE_FLAG( pcPPS->getOutputFlagPresentFlag() ? 1 : 0,     "output_flag_present_flag" );
     175  WRITE_CODE( pcPPS->getNumExtraSliceHeaderBits(), 3,        "num_extra_slice_header_bits");
    237176  WRITE_FLAG( pcPPS->getSignHideFlag(), "sign_data_hiding_flag" );
    238   if( pcPPS->getSignHideFlag() )
    239   {
    240     WRITE_CODE(pcPPS->getTSIG(), 4, "sign_hiding_threshold");
    241   }
    242 #if CABAC_INIT_FLAG
    243177  WRITE_FLAG( pcPPS->getCabacInitPresentFlag() ? 1 : 0,   "cabac_init_present_flag" );
    244 #endif
    245   // entropy_coding_mode_flag
    246   // We code the entropy_coding_mode_flag, it's needed for tests.
    247   WRITE_FLAG( pcPPS->getEntropyCodingMode() ? 1 : 0,         "entropy_coding_mode_flag" );
    248   if (pcPPS->getEntropyCodingMode())
    249   {
    250   }
    251   //   num_ref_idx_l0_default_active_minus1
    252   //   num_ref_idx_l1_default_active_minus1
    253   WRITE_SVLC( pcPPS->getPicInitQPMinus26(),                  "pic_init_qp_minus26");
     178  WRITE_UVLC( pcPPS->getNumRefIdxL0DefaultActive()-1,     "num_ref_idx_l0_default_active_minus1");
     179  WRITE_UVLC( pcPPS->getNumRefIdxL1DefaultActive()-1,     "num_ref_idx_l1_default_active_minus1");
     180
     181  WRITE_SVLC( pcPPS->getPicInitQPMinus26(),                  "init_qp_minus26");
    254182  WRITE_FLAG( pcPPS->getConstrainedIntraPred() ? 1 : 0,      "constrained_intra_pred_flag" );
    255   WRITE_FLAG( pcPPS->getEnableTMVPFlag() ? 1 : 0,            "enable_temporal_mvp_flag" );
    256   WRITE_CODE( pcPPS->getSliceGranularity(), 2,               "slice_granularity");
    257   WRITE_UVLC( pcPPS->getMaxCuDQPDepth() + pcPPS->getUseDQP(),                   "max_cu_qp_delta_depth" );
    258 
    259   WRITE_SVLC( pcPPS->getChromaQpOffset(),                   "chroma_qp_offset"     );
    260   WRITE_SVLC( pcPPS->getChromaQpOffset2nd(),                "chroma_qp_offset_2nd" );
     183  WRITE_FLAG( pcPPS->getUseTransformSkip() ? 1 : 0,  "transform_skip_enabled_flag" );
     184  WRITE_FLAG( pcPPS->getUseDQP() ? 1 : 0, "cu_qp_delta_enabled_flag" );
     185  if ( pcPPS->getUseDQP() )
     186  {
     187    WRITE_UVLC( pcPPS->getMaxCuDQPDepth(), "diff_cu_qp_delta_depth" );
     188  }
     189  WRITE_SVLC( pcPPS->getChromaCbQpOffset(),                   "pps_cb_qp_offset" );
     190  WRITE_SVLC( pcPPS->getChromaCrQpOffset(),                   "pps_cr_qp_offset" );
     191  WRITE_FLAG( pcPPS->getSliceChromaQpFlag() ? 1 : 0,          "pps_slice_chroma_qp_offsets_present_flag" );
    261192
    262193  WRITE_FLAG( pcPPS->getUseWP() ? 1 : 0,  "weighted_pred_flag" );   // Use of Weighting Prediction (P_SLICE)
    263   WRITE_CODE( pcPPS->getWPBiPredIdc(), 2, "weighted_bipred_idc" );  // Use of Weighting Bi-Prediction (B_SLICE)
    264   WRITE_FLAG( pcPPS->getOutputFlagPresentFlag() ? 1 : 0,  "output_flag_present_flag" );
    265   if(pcPPS->getSPS()->getTilesOrEntropyCodingSyncIdc()==1)
    266   {
    267     WRITE_FLAG( pcPPS->getColumnRowInfoPresent(),           "tile_info_present_flag" );
    268     WRITE_FLAG( pcPPS->getTileBehaviorControlPresentFlag(),  "tile_control_present_flag");
    269     if( pcPPS->getColumnRowInfoPresent() == 1 )
    270     {
    271       WRITE_UVLC( pcPPS->getNumColumnsMinus1(),                                    "num_tile_columns_minus1" );
    272       WRITE_UVLC( pcPPS->getNumRowsMinus1(),                                       "num_tile_rows_minus1" );
    273       WRITE_FLAG( pcPPS->getUniformSpacingIdr(),                                   "uniform_spacing_flag" );
    274       if( pcPPS->getUniformSpacingIdr() == 0 )
    275       {
    276         for(UInt i=0; i<pcPPS->getNumColumnsMinus1(); i++)
    277         {
    278           WRITE_UVLC( pcPPS->getColumnWidth(i),                                    "column_width" );
    279         }
    280         for(UInt i=0; i<pcPPS->getNumRowsMinus1(); i++)
    281         {
    282           WRITE_UVLC( pcPPS->getRowHeight(i),                                      "row_height" );
    283         }
    284       }
    285     }
    286 
    287     if(pcPPS->getTileBehaviorControlPresentFlag() == 1)
    288     {
    289       Int iNumColTilesMinus1 = (pcPPS->getColumnRowInfoPresent() == 1)?(pcPPS->getNumColumnsMinus1()):(pcPPS->getSPS()->getNumColumnsMinus1());
    290       Int iNumRowTilesMinus1 = (pcPPS->getColumnRowInfoPresent() == 1)?(pcPPS->getNumColumnsMinus1()):(pcPPS->getSPS()->getNumRowsMinus1());
    291 
    292       if(iNumColTilesMinus1 !=0 || iNumRowTilesMinus1 !=0)
    293       {
    294           WRITE_FLAG( pcPPS->getLFCrossTileBoundaryFlag()?1 : 0,            "loop_filter_across_tile_flag");
    295       }
    296     }
    297   }
    298   else if(pcPPS->getSPS()->getTilesOrEntropyCodingSyncIdc()==2)
    299   {
    300     WRITE_UVLC( pcPPS->getNumSubstreams()-1,               "num_substreams_minus1" );
    301   }
    302 
    303   WRITE_FLAG( pcPPS->getDeblockingFilterControlPresent()?1 : 0, "deblocking_filter_control_present_flag");
     194  WRITE_FLAG( pcPPS->getWPBiPred() ? 1 : 0, "weighted_bipred_flag" );  // Use of Weighting Bi-Prediction (B_SLICE)
     195  WRITE_FLAG( pcPPS->getTransquantBypassEnableFlag() ? 1 : 0, "transquant_bypass_enable_flag" );
     196  WRITE_FLAG( pcPPS->getTilesEnabledFlag()             ? 1 : 0, "tiles_enabled_flag" );
     197  WRITE_FLAG( pcPPS->getEntropyCodingSyncEnabledFlag() ? 1 : 0, "entropy_coding_sync_enabled_flag" );
     198  if( pcPPS->getTilesEnabledFlag() )
     199  {
     200    WRITE_UVLC( pcPPS->getNumColumnsMinus1(),                                    "num_tile_columns_minus1" );
     201    WRITE_UVLC( pcPPS->getNumRowsMinus1(),                                       "num_tile_rows_minus1" );
     202    WRITE_FLAG( pcPPS->getUniformSpacingFlag(),                                  "uniform_spacing_flag" );
     203    if( pcPPS->getUniformSpacingFlag() == 0 )
     204    {
     205      for(UInt i=0; i<pcPPS->getNumColumnsMinus1(); i++)
     206      {
     207        WRITE_UVLC( pcPPS->getColumnWidth(i)-1,                                  "column_width_minus1" );
     208      }
     209      for(UInt i=0; i<pcPPS->getNumRowsMinus1(); i++)
     210      {
     211        WRITE_UVLC( pcPPS->getRowHeight(i)-1,                                    "row_height_minus1" );
     212      }
     213    }
     214    if(pcPPS->getNumColumnsMinus1() !=0 || pcPPS->getNumRowsMinus1() !=0)
     215    {
     216      WRITE_FLAG( pcPPS->getLoopFilterAcrossTilesEnabledFlag()?1 : 0,          "loop_filter_across_tiles_enabled_flag");
     217    }
     218  }
     219  WRITE_FLAG( pcPPS->getLoopFilterAcrossSlicesEnabledFlag()?1 : 0,        "loop_filter_across_slices_enabled_flag");
     220  WRITE_FLAG( pcPPS->getDeblockingFilterControlPresentFlag()?1 : 0,       "deblocking_filter_control_present_flag");
     221  if(pcPPS->getDeblockingFilterControlPresentFlag())
     222  {
     223    WRITE_FLAG( pcPPS->getDeblockingFilterOverrideEnabledFlag() ? 1 : 0,  "deblocking_filter_override_enabled_flag" );
     224    WRITE_FLAG( pcPPS->getPicDisableDeblockingFilterFlag() ? 1 : 0,       "pps_disable_deblocking_filter_flag" );
     225    if(!pcPPS->getPicDisableDeblockingFilterFlag())
     226    {
     227      WRITE_SVLC( pcPPS->getDeblockingFilterBetaOffsetDiv2(),             "pps_beta_offset_div2" );
     228      WRITE_SVLC( pcPPS->getDeblockingFilterTcOffsetDiv2(),               "pps_tc_offset_div2" );
     229    }
     230  }
     231  WRITE_FLAG( pcPPS->getScalingListPresentFlag() ? 1 : 0,                          "pps_scaling_list_data_present_flag" );
     232  if( pcPPS->getScalingListPresentFlag() )
     233  {
     234#if SCALING_LIST_OUTPUT_RESULT
     235    printf("PPS\n");
     236#endif
     237    codeScalingList( m_pcSlice->getScalingList() );
     238  }
     239  WRITE_FLAG( pcPPS->getListsModificationPresentFlag(), "lists_modification_present_flag");
    304240  WRITE_UVLC( pcPPS->getLog2ParallelMergeLevelMinus2(), "log2_parallel_merge_level_minus2");
     241  WRITE_FLAG( pcPPS->getSliceHeaderExtensionPresentFlag() ? 1 : 0, "slice_segment_header_extension_present_flag");
    305242  WRITE_FLAG( 0, "pps_extension_flag" );
    306243}
    307244
    308 #if QC_MVHEVC_B0046
     245Void TEncCavlc::codeVUI( TComVUI *pcVUI, TComSPS* pcSPS )
     246{
     247#if ENC_DEC_TRACE
     248  fprintf( g_hTrace, "----------- vui_parameters -----------\n");
     249#endif
     250  WRITE_FLAG(pcVUI->getAspectRatioInfoPresentFlag(),            "aspect_ratio_info_present_flag");
     251  if (pcVUI->getAspectRatioInfoPresentFlag())
     252  {
     253    WRITE_CODE(pcVUI->getAspectRatioIdc(), 8,                   "aspect_ratio_idc" );
     254    if (pcVUI->getAspectRatioIdc() == 255)
     255    {
     256      WRITE_CODE(pcVUI->getSarWidth(), 16,                      "sar_width");
     257      WRITE_CODE(pcVUI->getSarHeight(), 16,                     "sar_height");
     258    }
     259  }
     260  WRITE_FLAG(pcVUI->getOverscanInfoPresentFlag(),               "overscan_info_present_flag");
     261  if (pcVUI->getOverscanInfoPresentFlag())
     262  {
     263    WRITE_FLAG(pcVUI->getOverscanAppropriateFlag(),             "overscan_appropriate_flag");
     264  }
     265  WRITE_FLAG(pcVUI->getVideoSignalTypePresentFlag(),            "video_signal_type_present_flag");
     266  if (pcVUI->getVideoSignalTypePresentFlag())
     267  {
     268    WRITE_CODE(pcVUI->getVideoFormat(), 3,                      "video_format");
     269    WRITE_FLAG(pcVUI->getVideoFullRangeFlag(),                  "video_full_range_flag");
     270    WRITE_FLAG(pcVUI->getColourDescriptionPresentFlag(),        "colour_description_present_flag");
     271    if (pcVUI->getColourDescriptionPresentFlag())
     272    {
     273      WRITE_CODE(pcVUI->getColourPrimaries(), 8,                "colour_primaries");
     274      WRITE_CODE(pcVUI->getTransferCharacteristics(), 8,        "transfer_characteristics");
     275      WRITE_CODE(pcVUI->getMatrixCoefficients(), 8,             "matrix_coefficients");
     276    }
     277  }
     278
     279  WRITE_FLAG(pcVUI->getChromaLocInfoPresentFlag(),              "chroma_loc_info_present_flag");
     280  if (pcVUI->getChromaLocInfoPresentFlag())
     281  {
     282    WRITE_UVLC(pcVUI->getChromaSampleLocTypeTopField(),         "chroma_sample_loc_type_top_field");
     283    WRITE_UVLC(pcVUI->getChromaSampleLocTypeBottomField(),      "chroma_sample_loc_type_bottom_field");
     284  }
     285
     286  WRITE_FLAG(pcVUI->getNeutralChromaIndicationFlag(),           "neutral_chroma_indication_flag");
     287  WRITE_FLAG(pcVUI->getFieldSeqFlag(),                          "field_seq_flag");
     288  WRITE_FLAG(pcVUI->getFrameFieldInfoPresentFlag(),             "frame_field_info_present_flag");
     289
     290  Window defaultDisplayWindow = pcVUI->getDefaultDisplayWindow();
     291  WRITE_FLAG(defaultDisplayWindow.getWindowEnabledFlag(),       "default_display_window_flag");
     292  if( defaultDisplayWindow.getWindowEnabledFlag() )
     293  {
     294    WRITE_UVLC(defaultDisplayWindow.getWindowLeftOffset(),      "def_disp_win_left_offset");
     295    WRITE_UVLC(defaultDisplayWindow.getWindowRightOffset(),     "def_disp_win_right_offset");
     296    WRITE_UVLC(defaultDisplayWindow.getWindowTopOffset(),       "def_disp_win_top_offset");
     297    WRITE_UVLC(defaultDisplayWindow.getWindowBottomOffset(),    "def_disp_win_bottom_offset");
     298  }
     299  TimingInfo *timingInfo = pcVUI->getTimingInfo();
     300  WRITE_FLAG(timingInfo->getTimingInfoPresentFlag(),          "vui_timing_info_present_flag");
     301  if(timingInfo->getTimingInfoPresentFlag())
     302  {
     303    WRITE_CODE(timingInfo->getNumUnitsInTick(), 32,           "vui_num_units_in_tick");
     304    WRITE_CODE(timingInfo->getTimeScale(),      32,           "vui_time_scale");
     305    WRITE_FLAG(timingInfo->getPocProportionalToTimingFlag(),  "vui_poc_proportional_to_timing_flag");
     306    if(timingInfo->getPocProportionalToTimingFlag())
     307    {
     308      WRITE_UVLC(timingInfo->getNumTicksPocDiffOneMinus1(),   "vui_num_ticks_poc_diff_one_minus1");
     309    }
     310  WRITE_FLAG(pcVUI->getHrdParametersPresentFlag(),              "hrd_parameters_present_flag");
     311  if( pcVUI->getHrdParametersPresentFlag() )
     312  {
     313    codeHrdParameters(pcVUI->getHrdParameters(), 1, pcSPS->getMaxTLayers() - 1 );
     314  }
     315  }
     316
     317  WRITE_FLAG(pcVUI->getBitstreamRestrictionFlag(),              "bitstream_restriction_flag");
     318  if (pcVUI->getBitstreamRestrictionFlag())
     319  {
     320    WRITE_FLAG(pcVUI->getTilesFixedStructureFlag(),             "tiles_fixed_structure_flag");
     321#if H_MV
     322    if ( pcSPS->getLayerId() > 0 )
     323    {
     324      WRITE_FLAG( pcVUI->getTileBoundariesAlignedFlag( ) ? 1 : 0 , "tile_boundaries_aligned_flag" );
     325    }
     326#endif
     327    WRITE_FLAG(pcVUI->getMotionVectorsOverPicBoundariesFlag(),  "motion_vectors_over_pic_boundaries_flag");
     328    WRITE_FLAG(pcVUI->getRestrictedRefPicListsFlag(),           "restricted_ref_pic_lists_flag");
     329    WRITE_UVLC(pcVUI->getMinSpatialSegmentationIdc(),           "min_spatial_segmentation_idc");
     330    WRITE_UVLC(pcVUI->getMaxBytesPerPicDenom(),                 "max_bytes_per_pic_denom");
     331    WRITE_UVLC(pcVUI->getMaxBitsPerMinCuDenom(),                "max_bits_per_mincu_denom");
     332    WRITE_UVLC(pcVUI->getLog2MaxMvLengthHorizontal(),           "log2_max_mv_length_horizontal");
     333    WRITE_UVLC(pcVUI->getLog2MaxMvLengthVertical(),             "log2_max_mv_length_vertical");
     334  }
     335}
     336
     337Void TEncCavlc::codeHrdParameters( TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1 )
     338{
     339  if( commonInfPresentFlag )
     340  {
     341    WRITE_FLAG( hrd->getNalHrdParametersPresentFlag() ? 1 : 0 ,  "nal_hrd_parameters_present_flag" );
     342    WRITE_FLAG( hrd->getVclHrdParametersPresentFlag() ? 1 : 0 ,  "vcl_hrd_parameters_present_flag" );
     343    if( hrd->getNalHrdParametersPresentFlag() || hrd->getVclHrdParametersPresentFlag() )
     344    {
     345      WRITE_FLAG( hrd->getSubPicCpbParamsPresentFlag() ? 1 : 0,  "sub_pic_cpb_params_present_flag" );
     346      if( hrd->getSubPicCpbParamsPresentFlag() )
     347      {
     348        WRITE_CODE( hrd->getTickDivisorMinus2(), 8,              "tick_divisor_minus2" );
     349        WRITE_CODE( hrd->getDuCpbRemovalDelayLengthMinus1(), 5,  "du_cpb_removal_delay_length_minus1" );
     350        WRITE_FLAG( hrd->getSubPicCpbParamsInPicTimingSEIFlag() ? 1 : 0, "sub_pic_cpb_params_in_pic_timing_sei_flag" );
     351        WRITE_CODE( hrd->getDpbOutputDelayDuLengthMinus1(), 5,   "dpb_output_delay_du_length_minus1"  );
     352      }
     353      WRITE_CODE( hrd->getBitRateScale(), 4,                     "bit_rate_scale" );
     354      WRITE_CODE( hrd->getCpbSizeScale(), 4,                     "cpb_size_scale" );
     355      if( hrd->getSubPicCpbParamsPresentFlag() )
     356      {
     357        WRITE_CODE( hrd->getDuCpbSizeScale(), 4,                "du_cpb_size_scale" );
     358      }
     359      WRITE_CODE( hrd->getInitialCpbRemovalDelayLengthMinus1(), 5, "initial_cpb_removal_delay_length_minus1" );
     360      WRITE_CODE( hrd->getCpbRemovalDelayLengthMinus1(),        5, "au_cpb_removal_delay_length_minus1" );
     361      WRITE_CODE( hrd->getDpbOutputDelayLengthMinus1(),         5, "dpb_output_delay_length_minus1" );
     362    }
     363  }
     364  Int i, j, nalOrVcl;
     365  for( i = 0; i <= maxNumSubLayersMinus1; i ++ )
     366  {
     367    WRITE_FLAG( hrd->getFixedPicRateFlag( i ) ? 1 : 0,          "fixed_pic_rate_general_flag");
     368    if( !hrd->getFixedPicRateFlag( i ) )
     369    {
     370      WRITE_FLAG( hrd->getFixedPicRateWithinCvsFlag( i ) ? 1 : 0, "fixed_pic_rate_within_cvs_flag");
     371    }
     372    else
     373    {
     374      hrd->setFixedPicRateWithinCvsFlag( i, true );
     375    }
     376    if( hrd->getFixedPicRateWithinCvsFlag( i ) )
     377    {
     378      WRITE_UVLC( hrd->getPicDurationInTcMinus1( i ),           "elemental_duration_in_tc_minus1");
     379    }
     380    else
     381    {
     382      WRITE_FLAG( hrd->getLowDelayHrdFlag( i ) ? 1 : 0,           "low_delay_hrd_flag");
     383    }
     384    if (!hrd->getLowDelayHrdFlag( i ))
     385    {
     386      WRITE_UVLC( hrd->getCpbCntMinus1( i ),                      "cpb_cnt_minus1");
     387    }
     388   
     389    for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
     390    {
     391      if( ( ( nalOrVcl == 0 ) && ( hrd->getNalHrdParametersPresentFlag() ) ) ||
     392          ( ( nalOrVcl == 1 ) && ( hrd->getVclHrdParametersPresentFlag() ) ) )
     393      {
     394        for( j = 0; j <= ( hrd->getCpbCntMinus1( i ) ); j ++ )
     395        {
     396          WRITE_UVLC( hrd->getBitRateValueMinus1( i, j, nalOrVcl ), "bit_rate_value_minus1");
     397          WRITE_UVLC( hrd->getCpbSizeValueMinus1( i, j, nalOrVcl ), "cpb_size_value_minus1");
     398          if( hrd->getSubPicCpbParamsPresentFlag() )
     399          {
     400            WRITE_UVLC( hrd->getDuCpbSizeValueMinus1( i, j, nalOrVcl ), "cpb_size_du_value_minus1"); 
     401            WRITE_UVLC( hrd->getDuBitRateValueMinus1( i, j, nalOrVcl ), "bit_rate_du_value_minus1");
     402          }
     403          WRITE_FLAG( hrd->getCbrFlag( i, j, nalOrVcl ) ? 1 : 0, "cbr_flag");
     404        }
     405      }
     406    }
     407  }
     408}
     409
     410#if H_3D
     411Void TEncCavlc::codeSPS( TComSPS* pcSPS, Int viewIndex, Bool depthFlag )
     412#else
     413Void TEncCavlc::codeSPS( TComSPS* pcSPS )
     414#endif
     415{
     416#if ENC_DEC_TRACE 
     417  xTraceSPSHeader (pcSPS);
     418#endif
     419  WRITE_CODE( pcSPS->getVPSId (),          4,       "sps_video_parameter_set_id" );
     420#if H_MV
     421  if ( pcSPS->getLayerId() == 0 )
     422  {
     423#endif
     424  WRITE_CODE( pcSPS->getMaxTLayers() - 1,  3,       "sps_max_sub_layers_minus1" );
     425  WRITE_FLAG( pcSPS->getTemporalIdNestingFlag() ? 1 : 0,                             "sps_temporal_id_nesting_flag" );
     426  codePTL(pcSPS->getPTL(), 1, pcSPS->getMaxTLayers() - 1);
     427#if H_MV
     428}
     429#endif
     430  WRITE_UVLC( pcSPS->getSPSId (),                   "sps_seq_parameter_set_id" );
     431  WRITE_UVLC( pcSPS->getChromaFormatIdc (),         "chroma_format_idc" );
     432  assert(pcSPS->getChromaFormatIdc () == 1);
     433  // in the first version chroma_format_idc can only be equal to 1 (4:2:0)
     434  if( pcSPS->getChromaFormatIdc () == 3 )
     435  {
     436    WRITE_FLAG( 0,                                  "separate_colour_plane_flag");
     437  }
     438
     439  WRITE_UVLC( pcSPS->getPicWidthInLumaSamples (),   "pic_width_in_luma_samples" );
     440  WRITE_UVLC( pcSPS->getPicHeightInLumaSamples(),   "pic_height_in_luma_samples" );
     441  Window conf = pcSPS->getConformanceWindow();
     442
     443  WRITE_FLAG( conf.getWindowEnabledFlag(),          "conformance_window_flag" );
     444  if (conf.getWindowEnabledFlag())
     445  {
     446    WRITE_UVLC( conf.getWindowLeftOffset()   / TComSPS::getWinUnitX(pcSPS->getChromaFormatIdc() ), "conf_win_left_offset" );
     447    WRITE_UVLC( conf.getWindowRightOffset()  / TComSPS::getWinUnitX(pcSPS->getChromaFormatIdc() ), "conf_win_right_offset" );
     448    WRITE_UVLC( conf.getWindowTopOffset()    / TComSPS::getWinUnitY(pcSPS->getChromaFormatIdc() ), "conf_win_top_offset" );
     449    WRITE_UVLC( conf.getWindowBottomOffset() / TComSPS::getWinUnitY(pcSPS->getChromaFormatIdc() ), "conf_win_bottom_offset" );
     450  }
     451
     452  WRITE_UVLC( pcSPS->getBitDepthY() - 8,             "bit_depth_luma_minus8" );
     453  WRITE_UVLC( pcSPS->getBitDepthC() - 8,             "bit_depth_chroma_minus8" );
     454
     455  WRITE_UVLC( pcSPS->getBitsForPOC()-4,                 "log2_max_pic_order_cnt_lsb_minus4" );
     456
     457  const Bool subLayerOrderingInfoPresentFlag = 1;
     458  WRITE_FLAG(subLayerOrderingInfoPresentFlag,       "sps_sub_layer_ordering_info_present_flag");
     459  for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++)
     460  {
     461    WRITE_UVLC( pcSPS->getMaxDecPicBuffering(i) - 1,       "sps_max_dec_pic_buffering_minus1[i]" );
     462    WRITE_UVLC( pcSPS->getNumReorderPics(i),               "sps_num_reorder_pics[i]" );
     463    WRITE_UVLC( pcSPS->getMaxLatencyIncrease(i),           "sps_max_latency_increase_plus1[i]" );
     464    if (!subLayerOrderingInfoPresentFlag)
     465    {
     466      break;
     467    }
     468  }
     469  assert( pcSPS->getMaxCUWidth() == pcSPS->getMaxCUHeight() );
     470 
     471  WRITE_UVLC( pcSPS->getLog2MinCodingBlockSize() - 3,                                "log2_min_coding_block_size_minus3" );
     472  WRITE_UVLC( pcSPS->getLog2DiffMaxMinCodingBlockSize(),                             "log2_diff_max_min_coding_block_size" );
     473  WRITE_UVLC( pcSPS->getQuadtreeTULog2MinSize() - 2,                                 "log2_min_transform_block_size_minus2" );
     474  WRITE_UVLC( pcSPS->getQuadtreeTULog2MaxSize() - pcSPS->getQuadtreeTULog2MinSize(), "log2_diff_max_min_transform_block_size" );
     475  WRITE_UVLC( pcSPS->getQuadtreeTUMaxDepthInter() - 1,                               "max_transform_hierarchy_depth_inter" );
     476  WRITE_UVLC( pcSPS->getQuadtreeTUMaxDepthIntra() - 1,                               "max_transform_hierarchy_depth_intra" );
     477  WRITE_FLAG( pcSPS->getScalingListFlag() ? 1 : 0,                                   "scaling_list_enabled_flag" );
     478  if(pcSPS->getScalingListFlag())
     479  {
     480    WRITE_FLAG( pcSPS->getScalingListPresentFlag() ? 1 : 0,                          "sps_scaling_list_data_present_flag" );
     481    if(pcSPS->getScalingListPresentFlag())
     482    {
     483#if SCALING_LIST_OUTPUT_RESULT
     484    printf("SPS\n");
     485#endif
     486      codeScalingList( m_pcSlice->getScalingList() );
     487    }
     488  }
     489  WRITE_FLAG( pcSPS->getUseAMP() ? 1 : 0,                                            "amp_enabled_flag" );
     490  WRITE_FLAG( pcSPS->getUseSAO() ? 1 : 0,                                            "sample_adaptive_offset_enabled_flag");
     491
     492  WRITE_FLAG( pcSPS->getUsePCM() ? 1 : 0,                                            "pcm_enabled_flag");
     493  if( pcSPS->getUsePCM() )
     494  {
     495    WRITE_CODE( pcSPS->getPCMBitDepthLuma() - 1, 4,                                  "pcm_sample_bit_depth_luma_minus1" );
     496    WRITE_CODE( pcSPS->getPCMBitDepthChroma() - 1, 4,                                "pcm_sample_bit_depth_chroma_minus1" );
     497    WRITE_UVLC( pcSPS->getPCMLog2MinSize() - 3,                                      "log2_min_pcm_luma_coding_block_size_minus3" );
     498    WRITE_UVLC( pcSPS->getPCMLog2MaxSize() - pcSPS->getPCMLog2MinSize(),             "log2_diff_max_min_pcm_luma_coding_block_size" );
     499    WRITE_FLAG( pcSPS->getPCMFilterDisableFlag()?1 : 0,                              "pcm_loop_filter_disable_flag");
     500  }
     501
     502  assert( pcSPS->getMaxTLayers() > 0 );         
     503
     504  TComRPSList* rpsList = pcSPS->getRPSList();
     505  TComReferencePictureSet*      rps;
     506
     507  WRITE_UVLC(rpsList->getNumberOfReferencePictureSets(), "num_short_term_ref_pic_sets" );
     508  for(Int i=0; i < rpsList->getNumberOfReferencePictureSets(); i++)
     509  {
     510    rps = rpsList->getReferencePictureSet(i);
     511    codeShortTermRefPicSet(pcSPS,rps,false, i);
     512  }
     513  WRITE_FLAG( pcSPS->getLongTermRefsPresent() ? 1 : 0,         "long_term_ref_pics_present_flag" );
     514  if (pcSPS->getLongTermRefsPresent())
     515  {
     516    WRITE_UVLC(pcSPS->getNumLongTermRefPicSPS(), "num_long_term_ref_pic_sps" );
     517    for (UInt k = 0; k < pcSPS->getNumLongTermRefPicSPS(); k++)
     518    {
     519      WRITE_CODE( pcSPS->getLtRefPicPocLsbSps(k), pcSPS->getBitsForPOC(), "lt_ref_pic_poc_lsb_sps");
     520      WRITE_FLAG( pcSPS->getUsedByCurrPicLtSPSFlag(k), "used_by_curr_pic_lt_sps_flag");
     521    }
     522  }
     523  WRITE_FLAG( pcSPS->getTMVPFlagsPresent()  ? 1 : 0,           "sps_temporal_mvp_enable_flag" );
     524
     525  WRITE_FLAG( pcSPS->getUseStrongIntraSmoothing(),             "sps_strong_intra_smoothing_enable_flag" );
     526
     527  WRITE_FLAG( pcSPS->getVuiParametersPresentFlag(),             "vui_parameters_present_flag" );
     528  if (pcSPS->getVuiParametersPresentFlag())
     529  {
     530      codeVUI(pcSPS->getVuiParameters(), pcSPS);
     531  }
     532
     533#if H_MV
     534  WRITE_FLAG( 1, "sps_extension_flag" );
     535  WRITE_FLAG( pcSPS->getInterViewMvVertConstraintFlag() ? 1 : 0, "inter_view_mv_vert_constraint_flag" );
     536  ////   sps_extension_vui_parameters( )
     537  if( pcSPS->getVuiParameters()->getBitstreamRestrictionFlag() )
     538  { 
     539    WRITE_UVLC( pcSPS->getNumIlpRestrictedRefLayers( ),           "num_ilp_restricted_ref_layers" );
     540    for( Int i = 0; i < pcSPS->getNumIlpRestrictedRefLayers( ); i++ )
     541    { 
     542      WRITE_UVLC( pcSPS->getMinSpatialSegmentOffsetPlus1( i ),    "min_spatial_segment_offset_plus1" );
     543      if( pcSPS->getMinSpatialSegmentOffsetPlus1( i ) > 0 )
     544      { 
     545        WRITE_FLAG( pcSPS->getCtuBasedOffsetEnabledFlag( i ),      "ctu_based_offset_enabled_flag[ i ]");
     546        if( pcSPS->getCtuBasedOffsetEnabledFlag( i ) ) 
     547        {
     548          WRITE_UVLC( pcSPS->getMinHorizontalCtuOffsetPlus1( i ), "min_horizontal_ctu_offset_plus1[ i ]");
     549        }
     550      } 
     551    } 
     552  }
     553#if H_3D_QTLPC
     554  if( depthFlag )
     555  {
     556    WRITE_FLAG( pcSPS->getUseQTL() ? 1 : 0, "use_qtl_flag");
     557    WRITE_FLAG( pcSPS->getUsePC()  ? 1 : 0, "use_pc_flag");
     558  }
     559#endif
     560  ////   sps_extension_vui_parameters( ) END
     561  WRITE_UVLC( 0, "sps_shvc_reserved_zero_idc" );
     562#if !H_3D
     563  WRITE_FLAG( 0, "sps_extension2_flag" );
     564#else
     565  WRITE_FLAG( 1, "sps_extension2_flag"  );
     566  if (!depthFlag )
     567  {
     568    WRITE_UVLC( pcSPS->getCamParPrecision(), "cp_precision" );
     569    WRITE_FLAG( pcSPS->hasCamParInSliceHeader() ? 1 : 0, "cp_in_slice_header_flag" );
     570    if( !pcSPS->hasCamParInSliceHeader() )
     571    {
     572      for( UInt uiIndex = 0; uiIndex < viewIndex; uiIndex++ )
     573      {
     574        WRITE_SVLC( pcSPS->getCodedScale    ()[ uiIndex ],                                      "cp_scale" );
     575        WRITE_SVLC( pcSPS->getCodedOffset   ()[ uiIndex ],                                      "cp_off" );
     576        WRITE_SVLC( pcSPS->getInvCodedScale ()[ uiIndex ] + pcSPS->getCodedScale ()[ uiIndex ], "cp_inv_scale_plus_scale" );
     577        WRITE_SVLC( pcSPS->getInvCodedOffset()[ uiIndex ] + pcSPS->getCodedOffset()[ uiIndex ], "cp_inv_off_plus_off" );
     578      }
     579    }
     580  }
     581
     582  WRITE_FLAG( 0, "sps_extension3_flag" );
     583#endif
     584#else
     585  WRITE_FLAG( 0, "sps_extension_flag" );
     586#endif
     587}
     588
    309589Void TEncCavlc::codeVPS( TComVPS* pcVPS )
    310590{
    311   WRITE_CODE( pcVPS->getVPSId(),               4,        "video_parameter_set_id"     );
    312   WRITE_FLAG( pcVPS->getTemporalNestingFlag() -1,        "temporal_id_nesting_flag"   );
    313   WRITE_CODE( 0,                 2,        "vps_reserved_zero_2bits"    );
    314   WRITE_CODE( pcVPS->getMaxLayers() - 1,       6,        "vps_max_layers_minus1"      );
    315   WRITE_CODE( pcVPS->getMaxTLayers() - 1,      3,        "vps_max_sub_layers_minus1"  );
    316   //to be determined
    317   //profile_tier_level( 1, vps_max_sub_layers_minus1 );
    318   //to be modified
    319   WRITE_CODE( 0,                              12,         "vps_extension_offset"      );
     591  WRITE_CODE( pcVPS->getVPSId(),                    4,        "vps_video_parameter_set_id" );
     592  WRITE_CODE( 3,                                    2,        "vps_reserved_three_2bits" );
     593#if H_MV
     594  WRITE_CODE( pcVPS->getMaxLayers() - 1,            6,        "vps_max_layers_minus1" );
     595#else
     596  WRITE_CODE( 0,                                    6,        "vps_reserved_zero_6bits" );
     597#endif
     598  WRITE_CODE( pcVPS->getMaxTLayers() - 1,           3,        "vps_max_sub_layers_minus1" );
     599  WRITE_FLAG( pcVPS->getTemporalNestingFlag(),                "vps_temporal_id_nesting_flag" );
     600  assert (pcVPS->getMaxTLayers()>1||pcVPS->getTemporalNestingFlag());
     601#if H_MV
     602  WRITE_CODE( 0xffff,                              16,        "vps_extension_offset" );
     603#else
     604  WRITE_CODE( 0xffff,                              16,        "vps_reserved_ffff_16bits" );
     605#endif
     606  codePTL( pcVPS->getPTL(), true, pcVPS->getMaxTLayers() - 1 );
     607  const Bool subLayerOrderingInfoPresentFlag = 1;
     608  WRITE_FLAG(subLayerOrderingInfoPresentFlag,              "vps_sub_layer_ordering_info_present_flag");
    320609  for(UInt i=0; i <= pcVPS->getMaxTLayers()-1; i++)
    321610  {
    322     WRITE_UVLC( pcVPS->getMaxDecPicBuffering(i),           "max_dec_pic_buffering[i]" );
    323     WRITE_UVLC( pcVPS->getNumReorderPics(i),               "num_reorder_pics[i]"      );
    324     WRITE_UVLC( pcVPS->getMaxLatencyIncrease(i),           "max_latency_increase[i]"  );
    325   }
    326   //!!!waste one bit: 3-view, 3; 2-view or more views: 1
    327   WRITE_UVLC(pcVPS->getNumHRDParameters(),                 "vps_num_hrd_parameters"   );
    328   assert(pcVPS->getNumHRDParameters()==0);
    329   for ( UInt i = 0; i < pcVPS->getNumHRDParameters(); i ++)
    330   {
    331    //   if( i > 0 ) 
    332     //{
    333     //  WRITE_UVLC (0, "op_num_layer_id_values_minus1[ opIdx ]");
    334     //  for( i = 0; i <= op_num_layer_id_values_minus1[ opIdx ]; i++ ) 
    335     //    WRITE_CODE(0, 6, "op_layer_id[ opIdx ][ i ]");
    336     //} 
    337     //hrd_parameters( i  = =  0, vps_max_sub_layers_minus1 ); 
    338   }
    339   WRITE_CODE( 1,      1,        "bit_equal_to_one" );
    340   //btye aligned
    341   m_pcBitIf->writeAlignOne();
    342 
    343   if(pcVPS->getMaxLayers() == 3)
    344     pcVPS->setNumAddiLayerOperationPoints (pcVPS->getMaxLayers());    //may be configured
    345   else
    346     pcVPS->setNumAddiLayerOperationPoints (1);   
    347   pcVPS->setNumAddiProLevelSets         (1);
    348   WRITE_CODE( pcVPS->getNumAddiLayerOperationPoints(),         8,               "num_additional_layer_operation_points" );   
    349   WRITE_CODE( pcVPS->getNumAddiProLevelSets(),                 8,               "num_additional_profile_level_sets"     );   
    350   for(UInt i=0; i <= pcVPS->getMaxLayers()-1; i++)
    351   {
    352     WRITE_CODE( 0,         4,               "num_types_zero_4bits[i]" );   
    353     WRITE_CODE( 0,         4,               "type_zero_4bits[i]"      );   
    354     WRITE_CODE( pcVPS->getViewId(i),         8,               "view_id[i]" );   
    355     if(i)
    356     {
    357       WRITE_CODE( pcVPS->getNumDirectRefLayer(i), 6,  "num_direct_ref_layers[ i ]" );   
    358       for (UInt j = 0; j< pcVPS->getNumDirectRefLayer(i); j++)
    359       {
    360         WRITE_CODE( pcVPS->getDirectRefLayerId (i, j), 6,  "ref_layer_id[i][j]" );
    361       }
    362     }
    363   }
    364   for( UInt i=1; i<=pcVPS->getNumAddiProLevelSets(); i++)
    365   {
    366     //profile_tier_level
    367   }
    368   for( UInt i=1; i<= pcVPS->getNumAddiLayerOperationPoints(); i++)
    369   {   
    370     if(pcVPS->getMaxLayers() == 3)
    371     {
    372       pcVPS->setNumOpLayerIdMinus1((i < pcVPS->getNumAddiLayerOperationPoints() ? 1: 2), (i-1));
    373     }
    374     else if( i==1 )
    375     {
    376       assert(pcVPS->getNumAddiLayerOperationPoints()==1);
    377       pcVPS->setNumOpLayerIdMinus1(pcVPS->getMaxLayers()-1, (i-1));
    378     }
    379     WRITE_UVLC( pcVPS->getNumOpLayerIdMinus1(i-1),           "op_num_layer_id_values_minus1[ opIdx ]" );
    380     for(UInt j = 0; j <= pcVPS->getNumOpLayerIdMinus1(i-1); j++ )
    381     {
    382       if(pcVPS->getMaxLayers() == 3 && i== 2 && j==1)
    383         pcVPS->setNumOpLayerId (2, i-1, j);
     611    WRITE_UVLC( pcVPS->getMaxDecPicBuffering(i) - 1,       "vps_max_dec_pic_buffering_minus1[i]" );
     612    WRITE_UVLC( pcVPS->getNumReorderPics(i),               "vps_num_reorder_pics[i]" );
     613    WRITE_UVLC( pcVPS->getMaxLatencyIncrease(i),           "vps_max_latency_increase_plus1[i]" );
     614    if (!subLayerOrderingInfoPresentFlag)
     615    {
     616      break;
     617    }
     618  }
     619
     620  assert( pcVPS->getNumHrdParameters() <= MAX_VPS_NUM_HRD_PARAMETERS );
     621#if H_MV
     622  assert( pcVPS->getVpsMaxLayerId() < MAX_VPS_NUH_LAYER_ID_PLUS1 );
     623  WRITE_CODE( pcVPS->getVpsMaxLayerId(), 6,                 "vps_max_layer_id" ); 
     624 
     625  WRITE_UVLC( pcVPS->getVpsNumLayerSetsMinus1(),  "vps_max_num_layer_sets_minus1" );
     626  for( UInt opsIdx = 1; opsIdx <= pcVPS->getVpsNumLayerSetsMinus1(); opsIdx ++ )
     627  {
     628    // Operation point set
     629    for( UInt i = 0; i <= pcVPS->getVpsMaxLayerId(); i ++ )
     630    {
     631#else
     632  assert( pcVPS->getMaxNuhReservedZeroLayerId() < MAX_VPS_NUH_RESERVED_ZERO_LAYER_ID_PLUS1 );
     633  WRITE_CODE( pcVPS->getMaxNuhReservedZeroLayerId(), 6,     "vps_max_nuh_reserved_zero_layer_id" );
     634  pcVPS->setMaxOpSets(1);
     635  WRITE_UVLC( pcVPS->getMaxOpSets() - 1,                    "vps_max_op_sets_minus1" );
     636  for( UInt opsIdx = 1; opsIdx <= ( pcVPS->getMaxOpSets() - 1 ); opsIdx ++ )
     637  {
     638    // Operation point set
     639    for( UInt i = 0; i <= pcVPS->getMaxNuhReservedZeroLayerId(); i ++ )
     640    {
     641      // Only applicable for version 1
     642      pcVPS->setLayerIdIncludedFlag( true, opsIdx, i );
     643#endif
     644      WRITE_FLAG( pcVPS->getLayerIdIncludedFlag( opsIdx, i ) ? 1 : 0, "layer_id_included_flag[opsIdx][i]" );
     645    }
     646  }
     647  TimingInfo *timingInfo = pcVPS->getTimingInfo();
     648  WRITE_FLAG(timingInfo->getTimingInfoPresentFlag(),          "vps_timing_info_present_flag");
     649  if(timingInfo->getTimingInfoPresentFlag())
     650  {
     651    WRITE_CODE(timingInfo->getNumUnitsInTick(), 32,           "vps_num_units_in_tick");
     652    WRITE_CODE(timingInfo->getTimeScale(),      32,           "vps_time_scale");
     653    WRITE_FLAG(timingInfo->getPocProportionalToTimingFlag(),  "vps_poc_proportional_to_timing_flag");
     654    if(timingInfo->getPocProportionalToTimingFlag())
     655    {
     656      WRITE_UVLC(timingInfo->getNumTicksPocDiffOneMinus1(),   "vps_num_ticks_poc_diff_one_minus1");
     657    }
     658    pcVPS->setNumHrdParameters( 0 );
     659    WRITE_UVLC( pcVPS->getNumHrdParameters(),                 "vps_num_hrd_parameters" );
     660
     661    if( pcVPS->getNumHrdParameters() > 0 )
     662    {
     663      pcVPS->createHrdParamBuffer();
     664    }
     665    for( UInt i = 0; i < pcVPS->getNumHrdParameters(); i ++ )
     666    {
     667      // Only applicable for version 1
     668      pcVPS->setHrdOpSetIdx( 0, i );
     669      WRITE_UVLC( pcVPS->getHrdOpSetIdx( i ),                "hrd_op_set_idx" );
     670      if( i > 0 )
     671      {
     672        WRITE_FLAG( pcVPS->getCprmsPresentFlag( i ) ? 1 : 0, "cprms_present_flag[i]" );
     673      }
     674      codeHrdParameters(pcVPS->getHrdParameters(i), pcVPS->getCprmsPresentFlag( i ), pcVPS->getMaxTLayers() - 1);
     675    }
     676  }
     677#if H_MV
     678  WRITE_FLAG( 1,                                             "vps_extension_flag" );
     679
     680  m_pcBitIf->writeAlignOne();                       
     681
     682  WRITE_FLAG( pcVPS->getAvcBaseLayerFlag() ? 1 : 0,          "avc_base_layer_flag" );
     683  WRITE_FLAG( pcVPS->getSplittingFlag() ? 1 : 0,             "splitting_flag" );
     684 
     685  for( Int type = 0; type < MAX_NUM_SCALABILITY_TYPES; type++ )
     686  {
     687    WRITE_FLAG( pcVPS->getScalabilityMask( type ) ? 1 : 0,   "scalability_mask[i]" );
     688  }
     689
     690  for( Int sIdx = 0; sIdx < pcVPS->getNumScalabilityTypes( ) - ( pcVPS->getSplittingFlag() ? 1 : 0 ); sIdx++ )
     691  {
     692    WRITE_CODE( pcVPS->getDimensionIdLen( sIdx ) - 1 , 3,    "dimension_id_len_minus1[j]");   
     693  }
     694
     695  if ( pcVPS->getSplittingFlag() )
     696  { // Ignore old dimension id length
     697    pcVPS->setDimensionIdLen( pcVPS->getNumScalabilityTypes( ) - 1 ,pcVPS->inferLastDimsionIdLenMinus1() + 1 );       
     698  }   
     699
     700
     701  WRITE_FLAG( pcVPS->getVpsNuhLayerIdPresentFlag() ? 1 : 0,  "vps_nuh_layer_id_present_flag");
     702
     703  for( Int i = 0; i <= pcVPS->getMaxLayers() - 1; i++ )
     704  {
     705    if ( pcVPS->getVpsNuhLayerIdPresentFlag() && ( i > 0 ) )
     706    {     
     707      WRITE_CODE( pcVPS->getLayerIdInNuh( i ), 6,          "layer_id_in_nuh[i]");
     708  }
     709    else
     710    {
     711      assert( pcVPS->getLayerIdInNuh( i ) == i );
     712  }
     713
     714    assert(  pcVPS->getLayerIdInVps( pcVPS->getLayerIdInNuh( i ) ) == i );
     715
     716    for( Int j = 0; j < pcVPS->getNumScalabilityTypes() ; j++ )
     717  {
     718      if ( !pcVPS->getSplittingFlag() )
     719    {
     720        WRITE_CODE( pcVPS->getDimensionId( i, j ), pcVPS->getDimensionIdLen( j ), "dimension_id[i][j]");     
     721      }
    384722      else
    385         pcVPS->setNumOpLayerId (j, i-1, j);
    386       WRITE_UVLC( pcVPS->getNumOpLayerId(i-1, j),           "op_layer_id[ opIdx ][ i ]" );
    387     }
    388     if (pcVPS->getNumAddiProLevelSets())
    389     {
    390       //profile_level_idx[ i ]
    391     }
    392   }
    393   return;
    394 }
     723      {
     724        assert( pcVPS->getDimensionId( i, j ) ==  pcVPS->inferDimensionId( i, j )  );
     725      }
     726    }
     727  }
     728
     729  for( Int i = 1; i <= pcVPS->getMaxLayers() - 1; i++ )
     730  {
     731    for( Int j = 0; j < i; j++ )
     732    {
     733      WRITE_FLAG( pcVPS->getDirectDependencyFlag( i, j ),    "direct_dependency_flag[i][j]" );
     734    }
     735  }
     736
     737  for( Int i = 0; i < pcVPS->getMaxLayers() - 1; i++ )
     738  {
     739    WRITE_CODE( pcVPS->getMaxTidIlRefPicPlus1( i ), 3,       "max_tid_il_ref_pics_plus1[i]" );
     740  }
     741
     742  WRITE_CODE( pcVPS->getVpsNumberLayerSetsMinus1( )    , 10,    "vps_number_layer_sets_minus1"      );
     743  WRITE_CODE( pcVPS->getVpsNumProfileTierLevelMinus1( ), 6,     "vps_num_profile_tier_level_minus1" );
     744
     745  for( Int i = 1; i <= pcVPS->getVpsNumProfileTierLevelMinus1(); i++ )
     746  {
     747    WRITE_FLAG( pcVPS->getVpsProfilePresentFlag( i ) ? 1 : 0, "vps_profile_present_flag[i]" );
     748    if( !pcVPS->getVpsProfilePresentFlag( i ) )
     749    {   
     750      WRITE_CODE( pcVPS->getProfileRefMinus1( i ), 6, "profile_ref_minus1[i]" );
     751    }
     752    codePTL( pcVPS->getPTL( i ), pcVPS->getVpsProfilePresentFlag( i ), pcVPS->getMaxTLayers() - 1 );
     753  }
     754
     755  Int numOutputLayerSets = pcVPS->getVpsNumberLayerSetsMinus1( ) + 1;
     756
     757  WRITE_FLAG( pcVPS->getMoreOutputLayerSetsThanDefaultFlag( ) ? 1 : 0, "more_output_layer_sets_than_default_flag" );
     758
     759  if ( pcVPS->getMoreOutputLayerSetsThanDefaultFlag( ) )
     760  {
     761    WRITE_CODE( pcVPS->getNumAddOutputLayerSetsMinus1( )    , 10,    "num_add_output_layer_sets_minus1"      );
     762    numOutputLayerSets += ( pcVPS->getNumAddOutputLayerSetsMinus1( ) + 1 );
     763  }
     764
     765  if( numOutputLayerSets > 1)
     766  {
     767    WRITE_FLAG( pcVPS->getDefaultOneTargetOutputLayerFlag( ) ? 1 : 0, "default_one_target_output_layer_flag" );
     768  } 
     769
     770  for( Int i = 1; i < numOutputLayerSets; i++ )
     771  {
     772    if( i > pcVPS->getVpsNumberLayerSetsMinus1( ) )
     773    {     
     774      WRITE_UVLC( pcVPS->getOutputLayerSetIdxMinus1( i ),      "output_layer_set_idx_minus1[i]" );
     775      for( Int j = 0; j < pcVPS->getNumLayersInIdList( j ) - 1 ; j++ )
     776      {
     777        WRITE_FLAG( pcVPS->getOutputLayerFlag( i, j) ? 1 : 0, "output_layer_flag" );
     778      }     
     779    }
     780    if ( pcVPS->getProfileLevelTierIdxLen()  > 0 )
     781    {     
     782      WRITE_CODE( pcVPS->getProfileLevelTierIdx( i ), pcVPS->getProfileLevelTierIdxLen() ,"profile_level_tier_idx[ i ]" );   
     783    }
     784  }
     785
     786  WRITE_FLAG( pcVPS->getMaxOneActiveRefLayerFlag( ) ? 1 : 0, "max_one_active_ref_layer_flag" );
     787  WRITE_UVLC( pcVPS->getDirectDepTypeLenMinus2 ( ),         "direct_dep_type_len_minus2");
     788
     789    for( Int i = 1; i <= pcVPS->getMaxLayers() - 1; i++ )
     790    {
     791      for( Int j = 0; j < i; j++ )
     792      {
     793        if (pcVPS->getDirectDependencyFlag( i, j) )
     794        {       
     795          assert ( pcVPS->getDirectDependencyType( i, j ) != -1 );
     796          WRITE_CODE( pcVPS->getDirectDependencyType( i, j ),pcVPS->getDirectDepTypeLenMinus2( ) + 2,  "direct_dependency_type[i][j]" );
     797        }
     798      }
     799    }
     800
     801    WRITE_FLAG ( 0,                    "vps_shvc_reserved_zero_flag" );
     802
     803#if H_3D
     804  WRITE_FLAG( 1,                                             "vps_extension2_flag" );
     805  m_pcBitIf->writeAlignOne();     
     806  for( Int i = 0; i <= pcVPS->getMaxLayers() - 1; i++ )
     807  {
     808    if (i!= 0)
     809    {
     810      if ( !( pcVPS->getDepthId( i ) == 1 ) )
     811      {
     812#if H_3D_IV_MERGE
     813        WRITE_FLAG( pcVPS->getIvMvPredFlag         ( i ) ? 1 : 0 , "iv_mv_pred_flag[i]");
     814#endif
     815#if H_3D_ARP
     816        WRITE_FLAG( pcVPS->getUseAdvRP             ( i ) ? 1 : 0,  "iv_res_pred_flag[i]"  );
     817#endif
     818#if H_3D_NBDV_REF
     819        WRITE_FLAG( pcVPS->getDepthRefinementFlag  ( i ) ? 1 : 0 , "depth_refinement_flag[i]");
     820#endif
     821#if H_3D_VSP
     822        WRITE_FLAG( pcVPS->getViewSynthesisPredFlag( i ) ? 1 : 0 , "view_synthesis_pred_flag[i]");
     823#endif
     824      }         
     825      else
     826      {
     827        WRITE_FLAG( pcVPS->getVpsDepthModesFlag( i ) ? 1 : 0 ,          "vps_depth_modes_flag[i]" );
     828        //WRITE_FLAG( pcVPS->getLimQtPredFlag    ( i ) ? 1 : 0 ,          "lim_qt_pred_flag[i]"     );
     829#if H_3D_DIM_DLT
     830        if( pcVPS->getVpsDepthModesFlag( i ) )
     831        {
     832          WRITE_FLAG( pcVPS->getUseDLTFlag( i ) ? 1 : 0, "dlt_flag[i]" );
     833        }
     834        if( pcVPS->getUseDLTFlag( i ) )
     835        {
     836          // code mapping
     837          WRITE_UVLC(pcVPS->getNumDepthValues(i), "num_depth_values_in_dlt[i]");
     838          for(Int d=0; d<pcVPS->getNumDepthValues(i); d++)
     839          {
     840            WRITE_UVLC( pcVPS->idx2DepthValue(i, d), "dlt_depth_value[i][d]" );
     841          }
     842        }       
     843#endif
     844#if LGE_INTER_SDC_E0156
     845        WRITE_FLAG( pcVPS->getInterSDCFlag( i ) ? 1 : 0, "depth_inter_SDC_flag" );
     846#endif
     847      }
     848    } 
     849  }
     850#if H_3D_TMVP
     851  WRITE_FLAG( pcVPS->getIvMvScalingFlag( ) ? 1 : 0 ,          "iv_mv_scaling_flag" );
     852#endif
    395853#else
    396 #if VIDYO_VPS_INTEGRATION
    397 Void TEncCavlc::codeVPS( TComVPS* pcVPS )
    398 {
    399   WRITE_CODE( pcVPS->getMaxTLayers() - 1,     3,        "max_temporal_layers_minus1" );
    400   WRITE_CODE( pcVPS->getMaxLayers() - 1,      5,        "max_layers_minus1" );
    401   WRITE_FLAG( pcVPS->getTemporalNestingFlag() - 1,      "temporal_id_nesting_flag" );
    402   WRITE_UVLC( pcVPS->getVPSId(),                        "video_parameter_set_id" );
    403   for(UInt i=0; i <= pcVPS->getMaxTLayers()-1; i++)
    404   {
    405     WRITE_UVLC( pcVPS->getMaxDecPicBuffering(i),           "max_dec_pic_buffering[i]" );
    406     WRITE_UVLC( pcVPS->getNumReorderPics(i),               "num_reorder_pics[i]" );
    407     WRITE_UVLC( pcVPS->getMaxLatencyIncrease(i),           "max_latency_increase[i]" );
    408   }
    409  
    410   WRITE_CODE( 1,      1,        "bit_equal_to_one" );
    411  
    412   if( pcVPS->getMaxLayers() - 1 > 0 )
    413   {
    414     WRITE_UVLC( pcVPS->getExtensionType(),                        "extension_type" );
    415    
    416     for(UInt i=1; i <= pcVPS->getMaxLayers()-1; i++)
    417     {
    418       WRITE_FLAG( pcVPS->getDependentFlag(i),                     "dependent_flag[i]" );
    419       if( pcVPS->getDependentFlag(i) )
    420       {
    421         WRITE_UVLC( i - pcVPS->getDependentLayer(i) - 1,          "delta_reference_layer_id_minus1[i]" );
    422         if( pcVPS->getExtensionType() == VPS_EXTENSION_TYPE_MULTI_VIEW )
    423         {
    424           WRITE_UVLC( pcVPS->getViewId(i),                        "view_id[i]" );
    425           WRITE_FLAG( pcVPS->getDepthFlag(i),                     "depth_flag[i]" );
    426           WRITE_SVLC( pcVPS->getViewOrderIdx(i),                  "view_order_idx[i]" );
    427         }
    428        
    429       }
    430     }
    431 #if INTER_VIEW_VECTOR_SCALING_C0115
    432       WRITE_FLAG( pcVPS->getIVScalingFlag(),                      "inter_view_vector_scaling_flag" );
    433 #endif
    434   }
    435  
     854  WRITE_FLAG( 0,                                             "vps_extension2_flag" );
     855#endif
     856#else
    436857  WRITE_FLAG( 0,                     "vps_extension_flag" );
     858#endif
    437859 
    438860  //future extensions here..
     
    440862  return;
    441863}
    442 #endif
    443 #endif
    444 #if HHI_MPI || H3D_QTL
    445 Void TEncCavlc::codeSPS( TComSPS* pcSPS, Bool bIsDepth )
    446 #else
    447 Void TEncCavlc::codeSPS( TComSPS* pcSPS )
    448 #endif
    449 {
    450 #if ENC_DEC_TRACE 
    451   xTraceSPSHeader (pcSPS);
    452 #endif
    453   WRITE_CODE( pcSPS->getProfileIdc (),     8,       "profile_idc" );
    454   WRITE_CODE( 0,                           8,       "reserved_zero_8bits" );
    455   WRITE_CODE( pcSPS->getLevelIdc (),       8,       "level_idc" );
    456   WRITE_UVLC( pcSPS->getSPSId (),                   "seq_parameter_set_id" );
    457 #if VIDYO_VPS_INTEGRATION
    458   WRITE_UVLC( pcSPS->getVPSId (),                   "video_parameter_set_id" );
    459 #endif
    460   WRITE_UVLC( pcSPS->getChromaFormatIdc (),         "chroma_format_idc" );
    461   WRITE_CODE( pcSPS->getMaxTLayers() - 1,  3,       "max_temporal_layers_minus1" );
    462   WRITE_UVLC( pcSPS->getPicWidthInLumaSamples (),   "pic_width_in_luma_samples" );
    463   WRITE_UVLC( pcSPS->getPicHeightInLumaSamples(),   "pic_height_in_luma_samples" );
    464   WRITE_FLAG( pcSPS->getPicCroppingFlag(),          "pic_cropping_flag" );
    465   if (pcSPS->getPicCroppingFlag())
    466   {
    467     WRITE_UVLC( pcSPS->getPicCropLeftOffset(),      "pic_crop_left_offset" );
    468     WRITE_UVLC( pcSPS->getPicCropRightOffset(),     "pic_crop_right_offset" );
    469     WRITE_UVLC( pcSPS->getPicCropTopOffset(),       "pic_crop_top_offset" );
    470     WRITE_UVLC( pcSPS->getPicCropBottomOffset(),    "pic_crop_bottom_offset" );
    471   }
    472 
    473 #if FULL_NBIT
    474   WRITE_UVLC( pcSPS->getBitDepth() - 8,             "bit_depth_luma_minus8" );
    475 #else
    476   WRITE_UVLC( pcSPS->getBitIncrement(),             "bit_depth_luma_minus8" );
    477 #endif
    478 #if FULL_NBIT
    479   WRITE_UVLC( pcSPS->getBitDepth() - 8,             "bit_depth_chroma_minus8" );
    480 #else
    481   WRITE_UVLC( pcSPS->getBitIncrement(),             "bit_depth_chroma_minus8" );
    482 #endif
    483 
    484   WRITE_FLAG( pcSPS->getUsePCM() ? 1 : 0,                   "pcm_enabled_flag");
    485 
    486   if( pcSPS->getUsePCM() )
    487   {
    488   WRITE_CODE( pcSPS->getPCMBitDepthLuma() - 1, 4,   "pcm_bit_depth_luma_minus1" );
    489   WRITE_CODE( pcSPS->getPCMBitDepthChroma() - 1, 4, "pcm_bit_depth_chroma_minus1" );
    490   }
    491 
    492 #if LOSSLESS_CODING
    493   WRITE_FLAG( (pcSPS->getUseLossless ()) ? 1 : 0,                                    "qpprime_y_zero_transquant_bypass_flag" );
    494 #endif
    495 
    496   WRITE_UVLC( pcSPS->getBitsForPOC()-4,                 "log2_max_pic_order_cnt_lsb_minus4" );
    497   for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++)
    498   {
    499     WRITE_UVLC( pcSPS->getMaxDecPicBuffering(i),           "max_dec_pic_buffering[i]" );
    500     WRITE_UVLC( pcSPS->getNumReorderPics(i),               "num_reorder_pics[i]" );
    501     WRITE_UVLC( pcSPS->getMaxLatencyIncrease(i),           "max_latency_increase[i]" );
    502   }
    503   assert( pcSPS->getMaxCUWidth() == pcSPS->getMaxCUHeight() );
    504  
    505   UInt MinCUSize = pcSPS->getMaxCUWidth() >> ( pcSPS->getMaxCUDepth()-g_uiAddCUDepth );
    506   UInt log2MinCUSize = 0;
    507   while(MinCUSize > 1)
    508   {
    509     MinCUSize >>= 1;
    510     log2MinCUSize++;
    511   }
    512 
    513   WRITE_FLAG( pcSPS->getRestrictedRefPicListsFlag(),                                 "restricted_ref_pic_lists_flag" );
    514   if( pcSPS->getRestrictedRefPicListsFlag() )
    515   {
    516     WRITE_FLAG( pcSPS->getListsModificationPresentFlag(),                            "lists_modification_present_flag" );
    517   }
    518   WRITE_UVLC( log2MinCUSize - 3,                                                     "log2_min_coding_block_size_minus3" );
    519   WRITE_UVLC( pcSPS->getMaxCUDepth()-g_uiAddCUDepth,                                 "log2_diff_max_min_coding_block_size" );
    520   WRITE_UVLC( pcSPS->getQuadtreeTULog2MinSize() - 2,                                 "log2_min_transform_block_size_minus2" );
    521   WRITE_UVLC( pcSPS->getQuadtreeTULog2MaxSize() - pcSPS->getQuadtreeTULog2MinSize(), "log2_diff_max_min_transform_block_size" );
    522 
    523   if(log2MinCUSize == 3)
    524   {
    525     xWriteFlag  ( (pcSPS->getDisInter4x4()) ? 1 : 0 );
    526   }
    527 
    528   if( pcSPS->getUsePCM() )
    529   {
    530     WRITE_UVLC( pcSPS->getPCMLog2MinSize() - 3,                                      "log2_min_pcm_coding_block_size_minus3" );
    531     WRITE_UVLC( pcSPS->getPCMLog2MaxSize() - pcSPS->getPCMLog2MinSize(),             "log2_diff_max_min_pcm_coding_block_size" );
    532   }
    533   WRITE_UVLC( pcSPS->getQuadtreeTUMaxDepthInter() - 1,                               "max_transform_hierarchy_depth_inter" );
    534   WRITE_UVLC( pcSPS->getQuadtreeTUMaxDepthIntra() - 1,                               "max_transform_hierarchy_depth_intra" );
    535   WRITE_FLAG( pcSPS->getScalingListFlag() ? 1 : 0,                                   "scaling_list_enabled_flag" );
    536   WRITE_FLAG( pcSPS->getUseLMChroma () ? 1 : 0,                                      "chroma_pred_from_luma_enabled_flag" );
    537   WRITE_FLAG( pcSPS->getUseDF() ? 1 : 0,                                             "deblocking_filter_in_aps_enabled_flag");
    538   WRITE_FLAG( pcSPS->getLFCrossSliceBoundaryFlag()?1 : 0,                            "seq_loop_filter_across_slices_enabled_flag");
    539   WRITE_FLAG( pcSPS->getUseAMP(),                                                    "asymmetric_motion_partitions_enabled_flag" );
    540   WRITE_FLAG( pcSPS->getUseNSQT(),                                                   "non_square_quadtree_enabled_flag" );
    541   WRITE_FLAG( pcSPS->getUseSAO() ? 1 : 0,                                            "sample_adaptive_offset_enabled_flag");
    542   WRITE_FLAG( pcSPS->getUseALF () ? 1 : 0,                                           "adaptive_loop_filter_enabled_flag");
    543   if(pcSPS->getUseALF())
    544   {
    545     WRITE_FLAG( (pcSPS->getUseALFCoefInSlice()) ? 1 : 0,                             "alf_coef_in_slice_flag");
    546   }
    547 
    548   if( pcSPS->getUsePCM() )
    549   {
    550   WRITE_FLAG( pcSPS->getPCMFilterDisableFlag()?1 : 0,                                "pcm_loop_filter_disable_flag");
    551   }
    552 
    553   assert( pcSPS->getMaxTLayers() > 0 );         
    554 
    555   WRITE_FLAG( pcSPS->getTemporalIdNestingFlag() ? 1 : 0,                             "temporal_id_nesting_flag" );
    556 
    557   TComRPSList* rpsList = pcSPS->getRPSList();
    558   TComReferencePictureSet*      rps;
    559 
    560   WRITE_UVLC(rpsList->getNumberOfReferencePictureSets(), "num_short_term_ref_pic_sets" );
    561   for(Int i=0; i < rpsList->getNumberOfReferencePictureSets(); i++)
    562   {
    563     rps = rpsList->getReferencePictureSet(i);
    564     codeShortTermRefPicSet(pcSPS,rps);
    565   }   
    566   WRITE_FLAG( pcSPS->getLongTermRefsPresent() ? 1 : 0,         "long_term_ref_pics_present_flag" );
    567   // AMVP mode for each depth
    568   for (Int i = 0; i < pcSPS->getMaxCUDepth(); i++)
    569   {
    570     xWriteFlag( pcSPS->getAMVPMode(i) ? 1 : 0);
    571   }
    572 
    573   Int tilesOrEntropyCodingSyncIdc = 0;
    574   if ( pcSPS->getNumColumnsMinus1() > 0 || pcSPS->getNumRowsMinus1() > 0)
    575   {
    576     tilesOrEntropyCodingSyncIdc = 1;
    577   }
    578   else if ( pcSPS->getNumSubstreams() > 1 )
    579   {
    580     tilesOrEntropyCodingSyncIdc = 2;
    581   }
    582   pcSPS->setTilesOrEntropyCodingSyncIdc( tilesOrEntropyCodingSyncIdc );
    583   WRITE_CODE(tilesOrEntropyCodingSyncIdc, 2, "tiles_or_entropy_coding_sync_idc");
    584 
    585   if(tilesOrEntropyCodingSyncIdc == 1)
    586   {
    587     WRITE_UVLC( pcSPS->getNumColumnsMinus1(),                           "num_tile_columns_minus1" );
    588     WRITE_UVLC( pcSPS->getNumRowsMinus1(),                              "num_tile_rows_minus1" );
    589     WRITE_FLAG( pcSPS->getUniformSpacingIdr(),                          "uniform_spacing_flag" );
    590 
    591     if( pcSPS->getUniformSpacingIdr()==0 )
    592     {
    593       for(UInt i=0; i<pcSPS->getNumColumnsMinus1(); i++)
    594       {
    595         WRITE_UVLC( pcSPS->getColumnWidth(i),                           "column_width" );
    596       }
    597       for(UInt i=0; i<pcSPS->getNumRowsMinus1(); i++)
    598       {
    599         WRITE_UVLC( pcSPS->getRowHeight(i),                             "row_height" );
    600       }
    601     }
    602 
    603     if( pcSPS->getNumColumnsMinus1() !=0 || pcSPS->getNumRowsMinus1() != 0)
    604     {
    605         WRITE_FLAG( pcSPS->getLFCrossTileBoundaryFlag()?1 : 0,            "loop_filter_across_tile_flag");
    606     }
    607   }
    608   WRITE_FLAG( 1, "sps_extension_flag" );
    609 #if !QC_MVHEVC_B0046
    610   WRITE_FLAG( (pcSPS->getNumberOfUsableInterViewRefs() > 0) ? 1 : 0, "interview_refs_present_flag" );
    611   if( pcSPS->getNumberOfUsableInterViewRefs() > 0 )
    612   {
    613     WRITE_UVLC( pcSPS->getNumberOfUsableInterViewRefs() - 1,   "num_usable_interview_refs_minus1" );
    614 
    615     Int prev = 0;
    616     for( Int j = 0 ; j < pcSPS->getNumberOfUsableInterViewRefs(); j++ )
    617     {
    618       WRITE_UVLC( prev - pcSPS->getUsableInterViewRef( j ) - 1, "delta_usable_interview_ref_minus1" );
    619       prev = pcSPS->getUsableInterViewRef( j );
    620     }
    621   }
    622 
    623 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
    624   WRITE_FLAG( pcSPS->getUseDMM(), "enable_dmm_flag" );
    625 #endif
    626 
    627 #if HHI_MPI
    628   if( bIsDepth )
    629   {
    630     WRITE_FLAG( pcSPS->getUseMVI() ? 1 : 0, "use_mvi_flag" );
    631   }
    632 #endif
    633 
    634 #if H3D_QTL
    635   if( bIsDepth )
    636   {
    637     WRITE_FLAG( pcSPS->getUseQTLPC() ? 1 : 0, "use_qtlpc_flag");
    638   }
    639 #endif
    640  
    641 #if RWTH_SDC_DLT_B0036
    642   if( bIsDepth )
    643   {
    644     WRITE_FLAG( pcSPS->getUseDLT() ? 1 : 0, "use_dlt_flag" );
    645     if( pcSPS->getUseDLT() )
    646     {
    647       // code mapping
    648       xWriteUvlc  ( pcSPS->getNumDepthValues() );
    649       for(UInt i=0; i<pcSPS->getNumDepthValues(); i++)
    650       {
    651         xWriteUvlc( pcSPS->idx2DepthValue(i) );
    652       }
    653     }
    654   }
    655 #endif
    656 
    657   if( pcSPS->getViewId() || pcSPS->isDepth() )
    658   {
    659     WRITE_FLAG( 0, "base_view_flag" );
    660     if( pcSPS->isDepth() )
    661     {
    662       WRITE_FLAG( 1, "depth_flag" );
    663       WRITE_UVLC( pcSPS->getViewId(), "view_id" );
    664       WRITE_SVLC( pcSPS->getViewOrderIdx(), "view_order_idx" );
    665 #if FCO_FIX_SPS_CHANGE
    666       if ( pcSPS->getViewId() )
    667       {
    668         WRITE_UVLC( pcSPS->getCamParPrecision(), "camera_parameter_precision" );
    669         WRITE_FLAG( pcSPS->hasCamParInSliceHeader() ? 1 : 0, "camera_parameter_in_slice_header" );
    670         if( !pcSPS->hasCamParInSliceHeader() )
    671         {
    672           for( UInt uiId = 0; uiId < pcSPS->getViewId(); uiId++ )
    673           {
    674             WRITE_SVLC( pcSPS->getCodedScale    ()[ uiId ], "coded_scale" );
    675             WRITE_SVLC( pcSPS->getCodedOffset   ()[ uiId ], "coded_offset" );
    676             WRITE_SVLC( pcSPS->getInvCodedScale ()[ uiId ] + pcSPS->getCodedScale ()[ uiId ], "inverse_coded_scale_plus_coded_scale" );
    677             WRITE_SVLC( pcSPS->getInvCodedOffset()[ uiId ] + pcSPS->getCodedOffset()[ uiId ], "inverse_coded_offset_plus_coded_offset" );
    678           }
    679         }     
    680       }
    681 #endif
    682     }
    683     else
    684     {
    685       WRITE_FLAG( 0, "depth_flag" );
    686       WRITE_UVLC( pcSPS->getViewId() - 1, "view_id_minus1" );
    687       WRITE_SVLC( pcSPS->getViewOrderIdx(), "view_order_idx" );
    688       WRITE_UVLC( pcSPS->getCamParPrecision(), "camera_parameter_precision" );
    689       WRITE_FLAG( pcSPS->hasCamParInSliceHeader() ? 1 : 0, "camera_parameter_in_slice_header" );
    690       if( !pcSPS->hasCamParInSliceHeader() )
    691       {
    692         for( UInt uiId = 0; uiId < pcSPS->getViewId(); uiId++ )
    693         {
    694           WRITE_SVLC( pcSPS->getCodedScale    ()[ uiId ], "coded_scale" );
    695           WRITE_SVLC( pcSPS->getCodedOffset   ()[ uiId ], "coded_offset" );
    696           WRITE_SVLC( pcSPS->getInvCodedScale ()[ uiId ] + pcSPS->getCodedScale ()[ uiId ], "inverse_coded_scale_plus_coded_scale" );
    697           WRITE_SVLC( pcSPS->getInvCodedOffset()[ uiId ] + pcSPS->getCodedOffset()[ uiId ], "inverse_coded_offset_plus_coded_offset" );
    698         }
    699       }
    700 #if DEPTH_MAP_GENERATION
    701       WRITE_UVLC( pcSPS->getPredDepthMapGeneration(), "Pdm_generation" );
    702       if( pcSPS->getPredDepthMapGeneration() )
    703       {
    704         WRITE_UVLC( pcSPS->getPdmPrecision(), "Pdm_precision" );
    705         for( UInt uiId = 0; uiId < pcSPS->getViewId(); uiId++ )
    706         {
    707           WRITE_SVLC( pcSPS->getPdmScaleNomDelta()[ uiId ], "Pdm_scale_nom_delta" );
    708           WRITE_SVLC( pcSPS->getPdmOffset       ()[ uiId ], "Pdm_offset" );
    709         }
    710 #if H3D_IVMP
    711         WRITE_UVLC( pcSPS->getMultiviewMvPredMode(), "multi_view_mv_pred_mode" );
    712 #endif
    713 #if H3D_IVRP & !QC_ARP_D0177
    714         WRITE_FLAG  ( pcSPS->getMultiviewResPredMode(), "multi_view_residual_pred_mode" );
    715 #endif
    716       }
    717 #endif
    718 #if QC_ARP_D0177
    719       WRITE_FLAG( pcSPS->getUseAdvRP () ? 1 : 0,       "advanced_residual_pred_flag"  );
    720 #endif
    721     }
    722 
    723 #if MTK_D0156
    724 #if MERL_VSP_COMPENSATION_C0152
    725     WRITE_FLAG( pcSPS->getUseVSPCompensation() ? 1 : 0,              "view_synthesis_pred_flag" );
    726 #endif
    727 
    728     WRITE_FLAG( pcSPS->getUseDVPRefine() ? 1 : 0,                    "dv_refine_flag" );
    729 #endif
    730   }
    731   else
    732   {
    733     WRITE_FLAG( 1, "base_view_flag" );   
    734   }
    735   WRITE_FLAG( 0, "sps_extension2_flag" );
    736 #endif
    737 }
    738 
    739 Void TEncCavlc::writeTileMarker( UInt uiTileIdx, UInt uiBitsUsed )
    740 {
    741   xWriteCode( uiTileIdx, uiBitsUsed );
    742 }
    743864
    744865Void TEncCavlc::codeSliceHeader         ( TComSlice* pcSlice )
    745866{
     867#if H_MV
     868  TComVPS* vps = pcSlice->getVPS();
     869#endif
    746870#if ENC_DEC_TRACE 
    747871  xTraceSliceHeader (pcSlice);
    748872#endif
    749873
    750   // if( nal_ref_idc != 0 )
    751   //   dec_ref_pic_marking( )
    752   // if( entropy_coding_mode_flag  &&  slice_type  !=  I)
    753   //   cabac_init_idc
    754   // first_slice_in_pic_flag
    755   // if( first_slice_in_pic_flag == 0 )
    756   //    slice_address
    757874  //calculate number of bits required for slice address
    758   Int maxAddrOuter = pcSlice->getPic()->getNumCUsInFrame();
    759   Int reqBitsOuter = 0;
    760   while(maxAddrOuter>(1<<reqBitsOuter))
    761   {
    762     reqBitsOuter++;
    763   }
    764   Int maxAddrInner = pcSlice->getPic()->getNumPartInCU()>>(2);
    765   maxAddrInner = (1<<(pcSlice->getPPS()->getSliceGranularity()<<1));
    766   Int reqBitsInner = 0;
    767  
    768   while(maxAddrInner>(1<<reqBitsInner))
    769   {
    770     reqBitsInner++;
    771   }
    772   Int lCUAddress;
    773   Int innerAddress;
     875  Int maxSliceSegmentAddress = pcSlice->getPic()->getNumCUsInFrame();
     876  Int bitsSliceSegmentAddress = 0;
     877  while(maxSliceSegmentAddress>(1<<bitsSliceSegmentAddress))
     878  {
     879    bitsSliceSegmentAddress++;
     880  }
     881  Int ctuAddress;
    774882  if (pcSlice->isNextSlice())
    775883  {
    776884    // Calculate slice address
    777     lCUAddress = (pcSlice->getSliceCurStartCUAddr()/pcSlice->getPic()->getNumPartInCU());
    778     innerAddress = (pcSlice->getSliceCurStartCUAddr()%(pcSlice->getPic()->getNumPartInCU()))>>((pcSlice->getSPS()->getMaxCUDepth()-pcSlice->getPPS()->getSliceGranularity())<<1);
     885    ctuAddress = (pcSlice->getSliceCurStartCUAddr()/pcSlice->getPic()->getNumPartInCU());
    779886  }
    780887  else
    781888  {
    782889    // Calculate slice address
    783     lCUAddress = (pcSlice->getEntropySliceCurStartCUAddr()/pcSlice->getPic()->getNumPartInCU());
    784     innerAddress = (pcSlice->getEntropySliceCurStartCUAddr()%(pcSlice->getPic()->getNumPartInCU()))>>((pcSlice->getSPS()->getMaxCUDepth()-pcSlice->getPPS()->getSliceGranularity())<<1);
    785    
     890    ctuAddress = (pcSlice->getSliceSegmentCurStartCUAddr()/pcSlice->getPic()->getNumPartInCU());
    786891  }
    787892  //write slice address
    788   Int address = (pcSlice->getPic()->getPicSym()->getCUOrderMap(lCUAddress) << reqBitsInner) + innerAddress;
    789   WRITE_FLAG( address==0, "first_slice_in_pic_flag" );
    790 
    791 #if LGE_ILLUCOMP_B0045
    792   // IC flag is on only first_slice_in_pic
    793   if (address==0)
    794   {
    795     if( pcSlice->getSPS()->getViewId()
    796 #if !LGE_ILLUCOMP_DEPTH_C0046
    797         && !pcSlice->getIsDepth()
    798 #endif
    799         )
    800     {
    801       WRITE_FLAG( pcSlice->getApplyIC() ? 1 : 0, "applying IC flag" );
    802     }
    803 #if SHARP_ILLUCOMP_PARSE_D0060
    804     if (pcSlice->getApplyIC())
    805     {
    806       WRITE_FLAG( pcSlice->getIcSkipParseFlag() ? 1 : 0, "ic_skip_mergeidx0" );
    807     }
    808 #endif
    809   }
    810 #endif
    811 
    812   if(address>0)
    813   {
    814     WRITE_CODE( address, reqBitsOuter+reqBitsInner, "slice_address" );
    815   }
    816 
    817   WRITE_UVLC( pcSlice->getSliceType(),       "slice_type" );
    818   Bool bEntropySlice = (!pcSlice->isNextSlice());
    819   WRITE_FLAG( bEntropySlice ? 1 : 0, "lightweight_slice_flag" );
    820  
    821   if (!bEntropySlice)
    822   {
    823 #if QC_MVHEVC_B0046
    824     WRITE_UVLC( 0, "pic_parameter_set_id" );
     893  Int sliceSegmentAddress = pcSlice->getPic()->getPicSym()->getCUOrderMap(ctuAddress);
     894
     895  WRITE_FLAG( sliceSegmentAddress==0, "first_slice_segment_in_pic_flag" );
     896  if ( pcSlice->getRapPicFlag() )
     897  {
     898    WRITE_FLAG( 0, "no_output_of_prior_pics_flag" );
     899  }
     900  WRITE_UVLC( pcSlice->getPPS()->getPPSId(), "slice_pic_parameter_set_id" );
     901  pcSlice->setDependentSliceSegmentFlag(!pcSlice->isNextSlice());
     902  if ( pcSlice->getPPS()->getDependentSliceSegmentsEnabledFlag() && (sliceSegmentAddress!=0) )
     903  {
     904    WRITE_FLAG( pcSlice->getDependentSliceSegmentFlag() ? 1 : 0, "dependent_slice_segment_flag" );
     905  }
     906  if(sliceSegmentAddress>0)
     907  {
     908    WRITE_CODE( sliceSegmentAddress, bitsSliceSegmentAddress, "slice_segment_address" );
     909  }
     910  if ( !pcSlice->getDependentSliceSegmentFlag() )
     911  {
     912#if H_MV   
     913    if ( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > 0 )
     914    {
     915      WRITE_FLAG( pcSlice->getDiscardableFlag( ) ? 1 : 0 , "discardable_flag" );
     916    }
     917
     918    for (Int i = 1; i < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)   
    825919#else
    826     WRITE_UVLC( pcSlice->getPPS()->getPPSId(), "pic_parameter_set_id" );
    827 #endif
     920    for (Int i = 0; i < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
     921#endif
     922    {
     923      assert(!!"slice_reserved_undetermined_flag[]");
     924      WRITE_FLAG(0, "slice_reserved_undetermined_flag[]");
     925    }
     926
     927    WRITE_UVLC( pcSlice->getSliceType(),       "slice_type" );
     928
    828929    if( pcSlice->getPPS()->getOutputFlagPresentFlag() )
    829930    {
    830931      WRITE_FLAG( pcSlice->getPicOutputFlag() ? 1 : 0, "pic_output_flag" );
    831932    }
    832 #if QC_REM_IDV_B0046
    833     if(pcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_IDR && pcSlice->getViewId() == 0)
    834 #else
    835     if(pcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_IDR)
    836 #endif
    837     {
    838       WRITE_UVLC( 0, "idr_pic_id" );
    839       WRITE_FLAG( 0, "no_output_of_prior_pics_flag" );
    840     }
    841     else
    842     {
    843       WRITE_CODE( (pcSlice->getPOC()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC()))%(1<<pcSlice->getSPS()->getBitsForPOC()), pcSlice->getSPS()->getBitsForPOC(), "pic_order_cnt_lsb");
    844 #if QC_REM_IDV_B0046
    845       if( pcSlice->getPOC() == 0 && !(pcSlice->getSPS()->getViewId() && (pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)))
    846 #else
    847       if( pcSlice->getPOC() == 0 && pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_IDV )
    848 #endif
    849       {
    850         TComReferencePictureSet* rps = pcSlice->getRPS();
    851         if(pcSlice->getRPSidx() < 0)
    852         {
    853           WRITE_FLAG( 0, "short_term_ref_pic_set_sps_flag");
    854           codeShortTermRefPicSet(pcSlice->getSPS(), rps);
    855         }
    856         else
    857         {
    858           WRITE_FLAG( 1, "short_term_ref_pic_set_sps_flag");
    859           WRITE_UVLC( pcSlice->getRPSidx(), "short_term_ref_pic_set_idx" );
    860         }
    861         if(pcSlice->getSPS()->getLongTermRefsPresent())
    862         {
    863           WRITE_UVLC( rps->getNumberOfLongtermPictures(), "num_long_term_pics");
    864           Int maxPocLsb = 1<<pcSlice->getSPS()->getBitsForPOC();
    865           Int prev = 0;
    866           Int prevDeltaPocLt=0;
    867           Int currDeltaPocLt=0;
    868           for(Int i=rps->getNumberOfPictures()-1 ; i > rps->getNumberOfPictures()-rps->getNumberOfLongtermPictures()-1; i--)
     933
     934    // in the first version chroma_format_idc is equal to one, thus colour_plane_id will not be present
     935    assert (pcSlice->getSPS()->getChromaFormatIdc() == 1 );
     936    // if( separate_colour_plane_flag  ==  1 )
     937    //   colour_plane_id                                      u(2)
     938
     939    if( !pcSlice->getIdrPicFlag() )
     940    {
     941      Int picOrderCntLSB = (pcSlice->getPOC()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC()))%(1<<pcSlice->getSPS()->getBitsForPOC());
     942      WRITE_CODE( picOrderCntLSB, pcSlice->getSPS()->getBitsForPOC(), "pic_order_cnt_lsb");
     943      TComReferencePictureSet* rps = pcSlice->getRPS();
     944     
     945#if FIX1071
     946      // check for bitstream restriction stating that:
     947      // If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0.
     948      // Ideally this process should not be repeated for each slice in a picture
     949      if (pcSlice->isIRAP())
     950      {
     951          for (Int picIdx = 0; picIdx < rps->getNumberOfPictures(); picIdx++)
    869952          {
    870             WRITE_UVLC((maxPocLsb-rps->getDeltaPOC(i)+prev)%maxPocLsb, "delta_poc_lsb_lt");
    871          
    872             currDeltaPocLt=((maxPocLsb-rps->getDeltaPOC(i)+prev)%maxPocLsb)+prevDeltaPocLt;
    873 
    874             Int deltaMsbCycle=0;
    875             if( (i==(rps->getNumberOfPictures()-1)) )
     953          assert (!rps->getUsed(picIdx));
     954          }
     955        }
     956#endif
     957
     958      if(pcSlice->getRPSidx() < 0)
     959      {
     960        WRITE_FLAG( 0, "short_term_ref_pic_set_sps_flag");
     961        codeShortTermRefPicSet(pcSlice->getSPS(), rps, true, pcSlice->getSPS()->getRPSList()->getNumberOfReferencePictureSets());
     962      }
     963      else
     964      {
     965        WRITE_FLAG( 1, "short_term_ref_pic_set_sps_flag");
     966        Int numBits = 0;
     967        while ((1 << numBits) < pcSlice->getSPS()->getRPSList()->getNumberOfReferencePictureSets())
     968        {
     969          numBits++;
     970        }
     971        if (numBits > 0)
     972        {
     973          WRITE_CODE( pcSlice->getRPSidx(), numBits, "short_term_ref_pic_set_idx" );         
     974        }
     975      }
     976      if(pcSlice->getSPS()->getLongTermRefsPresent())
     977      {
     978        Int numLtrpInSH = rps->getNumberOfLongtermPictures();
     979        Int ltrpInSPS[MAX_NUM_REF_PICS];
     980        Int numLtrpInSPS = 0;
     981        UInt ltrpIndex;
     982        Int counter = 0;
     983        for(Int k = rps->getNumberOfPictures()-1; k > rps->getNumberOfPictures()-rps->getNumberOfLongtermPictures()-1; k--)
     984        {
     985          if (findMatchingLTRP(pcSlice, &ltrpIndex, rps->getPOC(k), rps->getUsed(k)))
     986          {
     987            ltrpInSPS[numLtrpInSPS] = ltrpIndex;
     988            numLtrpInSPS++;
     989          }
     990          else
     991          {
     992            counter++;
     993          }
     994        }
     995        numLtrpInSH -= numLtrpInSPS;
     996
     997        Int bitsForLtrpInSPS = 0;
     998        while (pcSlice->getSPS()->getNumLongTermRefPicSPS() > (1 << bitsForLtrpInSPS))
     999        {
     1000          bitsForLtrpInSPS++;
     1001        }
     1002        if (pcSlice->getSPS()->getNumLongTermRefPicSPS() > 0)
     1003        {
     1004          WRITE_UVLC( numLtrpInSPS, "num_long_term_sps");
     1005        }
     1006        WRITE_UVLC( numLtrpInSH, "num_long_term_pics");
     1007        // Note that the LSBs of the LT ref. pic. POCs must be sorted before.
     1008        // Not sorted here because LT ref indices will be used in setRefPicList()
     1009        Int prevDeltaMSB = 0, prevLSB = 0;
     1010        Int offset = rps->getNumberOfNegativePictures() + rps->getNumberOfPositivePictures();
     1011        for(Int i=rps->getNumberOfPictures()-1 ; i > offset-1; i--)
     1012        {
     1013          if (counter < numLtrpInSPS)
     1014          {
     1015            if (bitsForLtrpInSPS > 0)
    8761016            {
    877               deltaMsbCycle=((-rps->getDeltaPOC(i))/maxPocLsb)-1;
     1017              WRITE_CODE( ltrpInSPS[counter], bitsForLtrpInSPS, "lt_idx_sps[i]");             
    8781018            }
    879             else if( prevDeltaPocLt!=currDeltaPocLt )
     1019          }
     1020          else
     1021          {
     1022            WRITE_CODE( rps->getPocLSBLT(i), pcSlice->getSPS()->getBitsForPOC(), "poc_lsb_lt");
     1023            WRITE_FLAG( rps->getUsed(i), "used_by_curr_pic_lt_flag");
     1024          }
     1025          WRITE_FLAG( rps->getDeltaPocMSBPresentFlag(i), "delta_poc_msb_present_flag");
     1026
     1027          if(rps->getDeltaPocMSBPresentFlag(i))
     1028          {
     1029            Bool deltaFlag = false;
     1030            //  First LTRP from SPS                 ||  First LTRP from SH                              || curr LSB            != prev LSB
     1031            if( (i == rps->getNumberOfPictures()-1) || (i == rps->getNumberOfPictures()-1-numLtrpInSPS) || (rps->getPocLSBLT(i) != prevLSB) )
    8801032            {
    881               deltaMsbCycle=((-rps->getDeltaPOC(i))/maxPocLsb)-1;
    882               if( ((prevDeltaPocLt==maxPocLsb-1) && (currDeltaPocLt==maxPocLsb+1)) ||  ((prevDeltaPocLt==maxPocLsb-2) && (currDeltaPocLt==maxPocLsb)))
    883               {
    884                 deltaMsbCycle=deltaMsbCycle-1;
    885               }
     1033              deltaFlag = true;
     1034            }
     1035            if(deltaFlag)
     1036            {
     1037              WRITE_UVLC( rps->getDeltaPocMSBCycleLT(i), "delta_poc_msb_cycle_lt[i]" );
    8861038            }
    8871039            else
     1040            {             
     1041              Int differenceInDeltaMSB = rps->getDeltaPocMSBCycleLT(i) - prevDeltaMSB;
     1042              assert(differenceInDeltaMSB >= 0);
     1043              WRITE_UVLC( differenceInDeltaMSB, "delta_poc_msb_cycle_lt[i]" );
     1044            }
     1045            prevLSB = rps->getPocLSBLT(i);
     1046            prevDeltaMSB = rps->getDeltaPocMSBCycleLT(i);
     1047          }
     1048        }
     1049      }
     1050      if (pcSlice->getSPS()->getTMVPFlagsPresent())
     1051      {
     1052        WRITE_FLAG( pcSlice->getEnableTMVPFlag() ? 1 : 0, "slice_temporal_mvp_enable_flag" );
     1053      }
     1054    }
     1055#if H_MV
     1056    Int layerIdInVps       = pcSlice->getLayerIdInVps();
     1057    if( pcSlice->getLayerId() > 0 && vps->getNumDirectRefLayers( layerIdInVps ) > 0 )
     1058    {   
     1059      WRITE_FLAG( pcSlice->getInterLayerPredEnabledFlag( ) ? 1 : 0 , "inter_layer_pred_enabled_flag" );
     1060      if( pcSlice->getInterLayerPredEnabledFlag() && vps->getNumDirectRefLayers( layerIdInVps ) > 1 )
     1061      {           
     1062        if( !vps->getMaxOneActiveRefLayerFlag()) 
     1063        {
     1064          WRITE_CODE( pcSlice->getNumInterLayerRefPicsMinus1( ), pcSlice->getNumInterLayerRefPicsMinus1Len( ), "num_inter_layer_ref_pics_minus1" );
     1065        }
     1066        for( Int i = 0; i < pcSlice->getNumActiveRefLayerPics(); i++ )   
     1067        {
     1068          WRITE_CODE( pcSlice->getInterLayerPredLayerIdc( i ), pcSlice->getInterLayerPredLayerIdcLen( ), "inter_layer_pred_layer_idc" );
     1069        }
     1070      } 
     1071    }
     1072
     1073    if( vps->getNumSamplePredRefLayers( layerIdInVps ) > 0  &&  pcSlice->getNumActiveRefLayerPics() > 0 )
     1074    {
     1075      WRITE_FLAG( pcSlice->getInterLayerSamplePredOnlyFlag( ) ? 1 : 0 , "inter_layer_sample_pred_only_flag" );
     1076    }
     1077
     1078#endif
     1079    if(pcSlice->getSPS()->getUseSAO())
     1080    {
     1081      if (pcSlice->getSPS()->getUseSAO())
     1082      {
     1083         WRITE_FLAG( pcSlice->getSaoEnabledFlag(), "slice_sao_luma_flag" );
     1084         {
     1085           SAOParam *saoParam = pcSlice->getPic()->getPicSym()->getSaoParam();
     1086          WRITE_FLAG( saoParam->bSaoFlag[1], "slice_sao_chroma_flag" );
     1087         }
     1088      }
     1089    }
     1090
     1091    //check if numrefidxes match the defaults. If not, override
     1092
     1093    if (!pcSlice->isIntra())
     1094    {
     1095      Bool overrideFlag = (pcSlice->getNumRefIdx( REF_PIC_LIST_0 )!=pcSlice->getPPS()->getNumRefIdxL0DefaultActive()||(pcSlice->isInterB()&&pcSlice->getNumRefIdx( REF_PIC_LIST_1 )!=pcSlice->getPPS()->getNumRefIdxL1DefaultActive()));
     1096      WRITE_FLAG( overrideFlag ? 1 : 0,                               "num_ref_idx_active_override_flag");
     1097      if (overrideFlag)
     1098      {
     1099        WRITE_UVLC( pcSlice->getNumRefIdx( REF_PIC_LIST_0 ) - 1,      "num_ref_idx_l0_active_minus1" );
     1100        if (pcSlice->isInterB())
     1101        {
     1102          WRITE_UVLC( pcSlice->getNumRefIdx( REF_PIC_LIST_1 ) - 1,    "num_ref_idx_l1_active_minus1" );
     1103        }
     1104        else
     1105        {
     1106          pcSlice->setNumRefIdx(REF_PIC_LIST_1, 0);
     1107        }
     1108      }
     1109    }
     1110    else
     1111    {
     1112      pcSlice->setNumRefIdx(REF_PIC_LIST_0, 0);
     1113      pcSlice->setNumRefIdx(REF_PIC_LIST_1, 0);
     1114    }
     1115
     1116    if( pcSlice->getPPS()->getListsModificationPresentFlag() && pcSlice->getNumRpsCurrTempList() > 1)
     1117    {
     1118      TComRefPicListModification* refPicListModification = pcSlice->getRefPicListModification();
     1119      if(!pcSlice->isIntra())
     1120      {
     1121        WRITE_FLAG(pcSlice->getRefPicListModification()->getRefPicListModificationFlagL0() ? 1 : 0,       "ref_pic_list_modification_flag_l0" );
     1122        if (pcSlice->getRefPicListModification()->getRefPicListModificationFlagL0())
     1123        {
     1124          Int numRpsCurrTempList0 = pcSlice->getNumRpsCurrTempList();
     1125          if (numRpsCurrTempList0 > 1)
     1126          {
     1127            Int length = 1;
     1128            numRpsCurrTempList0 --;
     1129            while ( numRpsCurrTempList0 >>= 1)
    8881130            {
    889               deltaMsbCycle=((rps->getDeltaPOC(i+1)-rps->getDeltaPOC(i))/maxPocLsb)-1;
     1131              length ++;
    8901132            }
    891 
    892             if(deltaMsbCycle>=0)
     1133            for(Int i = 0; i < pcSlice->getNumRefIdx( REF_PIC_LIST_0 ); i++)
    8931134            {
    894               WRITE_FLAG( 1, "delta_poc_msb_present_flag");
    895               WRITE_UVLC(deltaMsbCycle, "delta_poc_msb_cycle_lt_minus1");
     1135              WRITE_CODE( refPicListModification->getRefPicSetIdxL0(i), length, "list_entry_l0");
    8961136            }
    897             else
     1137          }
     1138        }
     1139      }
     1140      if(pcSlice->isInterB())
     1141      {   
     1142        WRITE_FLAG(pcSlice->getRefPicListModification()->getRefPicListModificationFlagL1() ? 1 : 0,       "ref_pic_list_modification_flag_l1" );
     1143        if (pcSlice->getRefPicListModification()->getRefPicListModificationFlagL1())
     1144        {
     1145          Int numRpsCurrTempList1 = pcSlice->getNumRpsCurrTempList();
     1146          if ( numRpsCurrTempList1 > 1 )
     1147          {
     1148            Int length = 1;
     1149            numRpsCurrTempList1 --;
     1150            while ( numRpsCurrTempList1 >>= 1)
    8981151            {
    899               WRITE_FLAG( 0, "delta_poc_msb_present_flag");
     1152              length ++;
    9001153            }
    901             prevDeltaPocLt=currDeltaPocLt;
    902             prev = rps->getDeltaPOC(i);
    903             WRITE_FLAG( rps->getUsed(i), "used_by_curr_pic_lt_flag");
     1154            for(Int i = 0; i < pcSlice->getNumRefIdx( REF_PIC_LIST_1 ); i++)
     1155            {
     1156              WRITE_CODE( refPicListModification->getRefPicSetIdxL1(i), length, "list_entry_l1");
     1157            }
    9041158          }
    9051159        }
    9061160      }
    907       if( pcSlice->getPOC() != 0 )
    908       {
    909         TComReferencePictureSet* rps = pcSlice->getRPS();
    910         if(pcSlice->getRPSidx() < 0)
    911         {
    912           WRITE_FLAG( 0, "short_term_ref_pic_set_sps_flag");
    913           codeShortTermRefPicSet(pcSlice->getSPS(), rps);
    914         }
    915         else
    916         {
    917           WRITE_FLAG( 1, "short_term_ref_pic_set_sps_flag");
    918           WRITE_UVLC( pcSlice->getRPSidx(), "short_term_ref_pic_set_idx" );
    919         }
    920         if(pcSlice->getSPS()->getLongTermRefsPresent())
    921         {
    922           WRITE_UVLC( rps->getNumberOfLongtermPictures(), "num_long_term_pics");
    923           Int maxPocLsb = 1<<pcSlice->getSPS()->getBitsForPOC();
    924           Int prev = 0;
    925           Int prevDeltaPocLt=0;
    926           Int currDeltaPocLt=0;
    927           for(Int i=rps->getNumberOfPictures()-1 ; i > rps->getNumberOfPictures()-rps->getNumberOfLongtermPictures()-1; i--)
    928           {
    929             WRITE_UVLC((maxPocLsb-rps->getDeltaPOC(i)+prev)%maxPocLsb, "delta_poc_lsb_lt");
    930          
    931             currDeltaPocLt=((maxPocLsb-rps->getDeltaPOC(i)+prev)%maxPocLsb)+prevDeltaPocLt;
    932 
    933             Int deltaMsbCycle=0;
    934             if( (i==(rps->getNumberOfPictures()-1)) )
    935             {
    936               deltaMsbCycle=((-rps->getDeltaPOC(i))/maxPocLsb)-1;
    937             }
    938             else if( prevDeltaPocLt!=currDeltaPocLt )
    939             {
    940               deltaMsbCycle=((-rps->getDeltaPOC(i))/maxPocLsb)-1;
    941               if( ((prevDeltaPocLt==maxPocLsb-1) && (currDeltaPocLt==maxPocLsb+1)) ||  ((prevDeltaPocLt==maxPocLsb-2) && (currDeltaPocLt==maxPocLsb)))
    942               {
    943                 deltaMsbCycle=deltaMsbCycle-1;
    944               }
    945             }
    946             else
    947             {
    948               deltaMsbCycle=((rps->getDeltaPOC(i+1)-rps->getDeltaPOC(i))/maxPocLsb)-1;
    949             }
    950 
    951             if(deltaMsbCycle>=0)
    952             {
    953               WRITE_FLAG( 1, "delta_poc_msb_present_flag");
    954               WRITE_UVLC(deltaMsbCycle, "delta_poc_msb_cycle_lt_minus1");
    955             }
    956             else
    957             {
    958               WRITE_FLAG( 0, "delta_poc_msb_present_flag");
    959             }
    960             prevDeltaPocLt=currDeltaPocLt;
    961             prev = rps->getDeltaPOC(i);
    962             WRITE_FLAG( rps->getUsed(i), "used_by_curr_pic_lt_flag");
    963           }
    964         }
    965       }
    966     }
    967 
    968     if(pcSlice->getSPS()->getUseSAO() || pcSlice->getSPS()->getUseALF()|| pcSlice->getSPS()->getScalingListFlag() || pcSlice->getSPS()->getUseDF())
    969     {
    970       if (pcSlice->getSPS()->getUseALF())
    971       {
    972          WRITE_FLAG( pcSlice->getAlfEnabledFlag(), "ALF on/off flag in slice header" );
    973       }
    974       if (pcSlice->getSPS()->getUseSAO())
    975       {
    976 #if LGE_SAO_MIGRATION_D0091
    977         WRITE_FLAG( pcSlice->getSaoEnabledFlag(), "slice_sao_luma_flag" );
    978         {
    979             SAOParam *saoParam = pcSlice->getAPS()->getSaoParam();
    980             WRITE_FLAG( saoParam->bSaoFlag[1], "slice_sao_chroma_flag" );
    981         }
     1161    }
     1162   
     1163    if (pcSlice->isInterB())
     1164    {
     1165      WRITE_FLAG( pcSlice->getMvdL1ZeroFlag() ? 1 : 0,   "mvd_l1_zero_flag");
     1166    }
     1167
     1168    if(!pcSlice->isIntra())
     1169    {
     1170      if (!pcSlice->isIntra() && pcSlice->getPPS()->getCabacInitPresentFlag())
     1171      {
     1172        SliceType sliceType   = pcSlice->getSliceType();
     1173        Int  encCABACTableIdx = pcSlice->getPPS()->getEncCABACTableIdx();
     1174        Bool encCabacInitFlag = (sliceType!=encCABACTableIdx && encCABACTableIdx!=I_SLICE) ? true : false;
     1175        pcSlice->setCabacInitFlag( encCabacInitFlag );
     1176        WRITE_FLAG( encCabacInitFlag?1:0, "cabac_init_flag" );
     1177      }
     1178    }
     1179
     1180    if ( pcSlice->getEnableTMVPFlag() )
     1181    {
     1182#if H_MV
     1183      if( pcSlice->getLayerId() > 0 && pcSlice->getNumActiveMotionPredRefLayers() > 0 )
     1184      {
     1185        WRITE_FLAG( pcSlice->getAltCollocatedIndicationFlag( ) ? 1 : 0 , "alt_collocated_indication_flag" );
     1186      }
     1187      if( pcSlice->getAltCollocatedIndicationFlag() && pcSlice->getNumActiveMotionPredRefLayers() > 1 )
     1188      {         
     1189        WRITE_UVLC( pcSlice->getCollocatedRefLayerIdx( ), "collocated_ref_layer_idx" );
     1190      }     
     1191      else
     1192      {
     1193#endif
     1194      if ( pcSlice->getSliceType() == B_SLICE )
     1195      {
     1196        WRITE_FLAG( pcSlice->getColFromL0Flag(), "collocated_from_l0_flag" );
     1197      }
     1198
     1199      if ( pcSlice->getSliceType() != I_SLICE &&
     1200        ((pcSlice->getColFromL0Flag()==1 && pcSlice->getNumRefIdx(REF_PIC_LIST_0)>1)||
     1201        (pcSlice->getColFromL0Flag()==0  && pcSlice->getNumRefIdx(REF_PIC_LIST_1)>1)))
     1202      {
     1203        WRITE_UVLC( pcSlice->getColRefIdx(), "collocated_ref_idx" );
     1204      }
     1205    }
     1206#if H_MV
     1207    }
     1208#endif
     1209    if ( (pcSlice->getPPS()->getUseWP() && pcSlice->getSliceType()==P_SLICE) || (pcSlice->getPPS()->getWPBiPred() && pcSlice->getSliceType()==B_SLICE) )
     1210    {
     1211      xCodePredWeightTable( pcSlice );
     1212    }
     1213#if H_3D_IC
     1214    else if( pcSlice->getViewIndex() && ( pcSlice->getSliceType() == P_SLICE || pcSlice->getSliceType() == B_SLICE ) )
     1215    {
     1216      WRITE_FLAG( pcSlice->getApplyIC() ? 1 : 0, "slice_ic_enable_flag" );
     1217      if( pcSlice->getApplyIC() )
     1218      {
     1219        WRITE_FLAG( pcSlice->getIcSkipParseFlag() ? 1 : 0, "ic_skip_mergeidx0" );
     1220      }
     1221    }
     1222#endif
     1223
     1224#if H_3D_IV_MERGE
     1225    assert(pcSlice->getMaxNumMergeCand()<=MRG_MAX_NUM_CANDS_MEM);
    9821226#else
    983         WRITE_FLAG( pcSlice->getSaoInterleavingFlag(), "SAO interleaving flag" );
    984          assert (pcSlice->getSaoEnabledFlag() == pcSlice->getAPS()->getSaoEnabled());
    985          WRITE_FLAG( pcSlice->getSaoEnabledFlag(), "SAO on/off flag in slice header" );
    986          if (pcSlice->getSaoInterleavingFlag()&&pcSlice->getSaoEnabledFlag() )
    987          {
    988            WRITE_FLAG( pcSlice->getAPS()->getSaoParam()->bSaoFlag[1], "SAO on/off flag for Cb in slice header" );
    989            WRITE_FLAG( pcSlice->getAPS()->getSaoParam()->bSaoFlag[2], "SAO on/off flag for Cr in slice header" );
    990          }
    991 #endif
    992       }
    993       WRITE_UVLC( pcSlice->getAPS()->getAPSID(), "aps_id");
    994     }
    995 
    996     // we always set num_ref_idx_active_override_flag equal to one. this might be done in a more intelligent way
     1227    assert(pcSlice->getMaxNumMergeCand()<=MRG_MAX_NUM_CANDS);
     1228#endif
    9971229    if (!pcSlice->isIntra())
    9981230    {
    999       WRITE_FLAG( 1 ,                                             "num_ref_idx_active_override_flag");
    1000       WRITE_CODE( pcSlice->getNumRefIdx( REF_PIC_LIST_0 ) - 1, 3, "num_ref_idx_l0_active_minus1" );
    1001     }
    1002     else
    1003     {
    1004       pcSlice->setNumRefIdx(REF_PIC_LIST_0, 0);
    1005     }
    1006     if (pcSlice->isInterB())
    1007     {
    1008       WRITE_CODE( pcSlice->getNumRefIdx( REF_PIC_LIST_1 ) - 1, 3, "num_ref_idx_l1_active_minus1" );
    1009     }
    1010     else
    1011     {
    1012       pcSlice->setNumRefIdx(REF_PIC_LIST_1, 0);
    1013     }
    1014     if( pcSlice->getSPS()->getListsModificationPresentFlag() )
    1015     {
    1016     TComRefPicListModification* refPicListModification = pcSlice->getRefPicListModification();
    1017     if( !pcSlice->isIntra() )
    1018     {
    1019       WRITE_FLAG(pcSlice->getRefPicListModification()->getRefPicListModificationFlagL0() ? 1 : 0,       "ref_pic_list_modification_flag_l0" );
    1020       if (pcSlice->getRefPicListModification()->getRefPicListModificationFlagL0())
    1021       {
    1022         Int NumPocTotalCurr = pcSlice->getNumPocTotalCurrMvc();
    1023         if (NumPocTotalCurr > 1)
    1024         {
    1025           Int length = 1;
    1026           NumPocTotalCurr --;
    1027           while ( NumPocTotalCurr >>= 1)
    1028           {
    1029             length ++;
    1030           }
    1031           for(Int i = 0; i < pcSlice->getNumRefIdx( REF_PIC_LIST_0 ); i++)
    1032           {
    1033             WRITE_CODE( refPicListModification->getRefPicSetIdxL0(i), length, "list_entry_l0");
    1034           }
    1035         }
    1036       }
    1037     }
    1038     if(pcSlice->isInterB())
    1039     {   
    1040       WRITE_FLAG(pcSlice->getRefPicListModification()->getRefPicListModificationFlagL1() ? 1 : 0,       "ref_pic_list_modification_flag_l1" );
    1041       if (pcSlice->getRefPicListModification()->getRefPicListModificationFlagL1())
    1042       {
    1043         Int NumPocTotalCurr = pcSlice->getNumPocTotalCurrMvc();
    1044         if ( NumPocTotalCurr > 1 )
    1045         {
    1046           Int length = 1;
    1047           NumPocTotalCurr --;
    1048           while ( NumPocTotalCurr >>= 1)
    1049           {
    1050             length ++;
    1051           }
    1052           for(Int i = 0; i < pcSlice->getNumRefIdx( REF_PIC_LIST_1 ); i++)
    1053           {
    1054             WRITE_CODE( refPicListModification->getRefPicSetIdxL1(i), length, "list_entry_l1");
    1055           }
    1056         }
    1057       }
    1058     }
    1059     }
    1060   }
    1061   // ref_pic_list_combination( )
    1062   // maybe move to own function?
    1063   if (pcSlice->isInterB())
    1064   {
    1065     WRITE_FLAG(pcSlice->getRefPicListCombinationFlag() ? 1 : 0,       "ref_pic_list_combination_flag" );
    1066     if(pcSlice->getRefPicListCombinationFlag())
    1067     {
    1068       WRITE_UVLC( pcSlice->getNumRefIdx(REF_PIC_LIST_C) - 1,          "num_ref_idx lc_active_minus1");
    1069      
    1070       if( pcSlice->getSPS()->getListsModificationPresentFlag() )
    1071       {
    1072         WRITE_FLAG( pcSlice->getRefPicListModificationFlagLC() ? 1 : 0, "ref_pic_list_modification_flag_lc" );
    1073         if(pcSlice->getRefPicListModificationFlagLC())
    1074         {
    1075           for (UInt i=0;i<pcSlice->getNumRefIdx(REF_PIC_LIST_C);i++)
    1076           {
    1077             WRITE_FLAG( pcSlice->getListIdFromIdxOfLC(i),               "pic_from_list_0_flag" );
    1078           if (((pcSlice->getListIdFromIdxOfLC(i)==REF_PIC_LIST_0) && pcSlice->getNumRefIdx( REF_PIC_LIST_0 )>1 ) || ((pcSlice->getListIdFromIdxOfLC(i)==REF_PIC_LIST_1) && pcSlice->getNumRefIdx( REF_PIC_LIST_1 )>1 ) )
    1079           {
    1080             WRITE_UVLC( pcSlice->getRefIdxFromIdxOfLC(i),               "ref_idx_list_curr" );
    1081           }
    1082           }
    1083         }
    1084       }
    1085     }
    1086   }
    1087    
    1088   if (pcSlice->isInterB())
    1089   {
    1090     WRITE_FLAG( pcSlice->getMvdL1ZeroFlag() ? 1 : 0,   "mvd_l1_zero_flag");
    1091   }
    1092 
    1093   if(pcSlice->getPPS()->getEntropyCodingMode() && !pcSlice->isIntra())
    1094   {
    1095 #if CABAC_INIT_FLAG
    1096     if (!pcSlice->isIntra() && pcSlice->getPPS()->getCabacInitPresentFlag())
    1097     {
    1098       SliceType sliceType   = pcSlice->getSliceType();
    1099       Int  encCABACTableIdx = pcSlice->getPPS()->getEncCABACTableIdx();
    1100       Bool encCabacInitFlag = (sliceType!=encCABACTableIdx && encCABACTableIdx!=0) ? true : false;
    1101       pcSlice->setCabacInitFlag( encCabacInitFlag );
    1102       WRITE_FLAG( encCabacInitFlag?1:0, "cabac_init_flag" );
    1103     }
     1231#if H_3D_IV_MERGE
     1232      Bool ivMvPredFlag = pcSlice->getVPS()->getIvMvPredFlag( pcSlice->getLayerIdInVps() ) ;
     1233      WRITE_UVLC( ( ivMvPredFlag ? MRG_MAX_NUM_CANDS_MEM : MRG_MAX_NUM_CANDS ) - pcSlice->getMaxNumMergeCand(), "five_minus_max_num_merge_cand");
    11041234#else
    1105     WRITE_UVLC(pcSlice->getCABACinitIDC(),  "cabac_init_idc");
    1106 #endif
    1107   }
    1108 
    1109   // if( !lightweight_slice_flag ) {
    1110   if (!bEntropySlice)
    1111   {
     1235      WRITE_UVLC(MRG_MAX_NUM_CANDS - pcSlice->getMaxNumMergeCand(), "five_minus_max_num_merge_cand");
     1236#endif
     1237    }
    11121238    Int iCode = pcSlice->getSliceQp() - ( pcSlice->getPPS()->getPicInitQPMinus26() + 26 );
    11131239    WRITE_SVLC( iCode, "slice_qp_delta" );
    1114     if (pcSlice->getPPS()->getDeblockingFilterControlPresent())
    1115     {
    1116       if ( pcSlice->getSPS()->getUseDF() )
    1117       {
    1118         WRITE_FLAG(pcSlice->getInheritDblParamFromAPS(), "inherit_dbl_param_from_APS_flag");
    1119       }
    1120       if (!pcSlice->getInheritDblParamFromAPS())
    1121       {
    1122         WRITE_FLAG(pcSlice->getLoopFilterDisable(), "loop_filter_disable");  // should be an IDC
    1123         if(!pcSlice->getLoopFilterDisable())
    1124         {
    1125           WRITE_SVLC (pcSlice->getLoopFilterBetaOffset(), "beta_offset_div2");
    1126           WRITE_SVLC (pcSlice->getLoopFilterTcOffset(), "tc_offset_div2");
    1127         }
    1128       }
    1129     }
    1130     if ( pcSlice->getSliceType() == B_SLICE )
    1131     {
    1132       WRITE_FLAG( pcSlice->getColDir(), "collocated_from_l0_flag" );
    1133     }
    1134 
    1135 #if COLLOCATED_REF_IDX
    1136     if ( pcSlice->getSliceType() != I_SLICE &&
    1137       ((pcSlice->getColDir()==0 && pcSlice->getNumRefIdx(REF_PIC_LIST_0)>1)||
    1138       (pcSlice->getColDir()==1  && pcSlice->getNumRefIdx(REF_PIC_LIST_1)>1)))
    1139     {
    1140       WRITE_UVLC( pcSlice->getColRefIdx(), "collocated_ref_idx" );
    1141     }
    1142 #endif
    1143 
    1144 #if FIX_LGE_WP_FOR_3D_C0223
    1145     if ( (pcSlice->getPPS()->getUseWP() && pcSlice->getSliceType()==P_SLICE) || (pcSlice->getPPS()->getWPBiPredIdc() && pcSlice->getSliceType()==B_SLICE) )
     1240    if (pcSlice->getPPS()->getSliceChromaQpFlag())
     1241    {
     1242      iCode = pcSlice->getSliceQpDeltaCb();
     1243      WRITE_SVLC( iCode, "slice_qp_delta_cb" );
     1244      iCode = pcSlice->getSliceQpDeltaCr();
     1245      WRITE_SVLC( iCode, "slice_qp_delta_cr" );
     1246    }
     1247    if (pcSlice->getPPS()->getDeblockingFilterControlPresentFlag())
     1248    {
     1249      if (pcSlice->getPPS()->getDeblockingFilterOverrideEnabledFlag() )
     1250      {
     1251        WRITE_FLAG(pcSlice->getDeblockingFilterOverrideFlag(), "deblocking_filter_override_flag");
     1252      }
     1253      if (pcSlice->getDeblockingFilterOverrideFlag())
     1254      {
     1255        WRITE_FLAG(pcSlice->getDeblockingFilterDisable(), "slice_disable_deblocking_filter_flag");
     1256        if(!pcSlice->getDeblockingFilterDisable())
     1257        {
     1258          WRITE_SVLC (pcSlice->getDeblockingFilterBetaOffsetDiv2(), "slice_beta_offset_div2");
     1259          WRITE_SVLC (pcSlice->getDeblockingFilterTcOffsetDiv2(),   "slice_tc_offset_div2");
     1260        }
     1261      }
     1262    }
     1263
     1264    Bool isSAOEnabled = (!pcSlice->getSPS()->getUseSAO())?(false):(pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma());
     1265    Bool isDBFEnabled = (!pcSlice->getDeblockingFilterDisable());
     1266
     1267    if(pcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag() && ( isSAOEnabled || isDBFEnabled ))
     1268    {
     1269      WRITE_FLAG(pcSlice->getLFCrossSliceBoundaryFlag()?1:0, "slice_loop_filter_across_slices_enabled_flag");
     1270    }
     1271  }
     1272  if(pcSlice->getPPS()->getSliceHeaderExtensionPresentFlag())
     1273  {
     1274#if !H_3D
     1275    WRITE_UVLC(0,"slice_header_extension_length");
    11461276#else
    1147     if ( (pcSlice->getPPS()->getUseWP() && pcSlice->getSliceType()==P_SLICE) || (pcSlice->getPPS()->getWPBiPredIdc()==1 && pcSlice->getSliceType()==B_SLICE) )
    1148 #endif   
    1149     {
    1150       xCodePredWeightTable( pcSlice );
    1151     }
    1152   }
    1153 
    1154   // !!!! sytnax elements not in the WD !!!!
    1155   if (!bEntropySlice)
    1156   {
     1277    WRITE_UVLC(0,"slice_header_extension_length"); //<- this element needs to be set to the correct value!!
     1278
    11571279    if( pcSlice->getSPS()->hasCamParInSliceHeader() )
    11581280    {
    1159       for( UInt uiId = 0; uiId < pcSlice->getSPS()->getViewId(); uiId++ )
    1160       {
    1161         WRITE_SVLC( pcSlice->getCodedScale    ()[ uiId ], "coded_scale" );
    1162         WRITE_SVLC( pcSlice->getCodedOffset   ()[ uiId ], "coded_offset" );
    1163         WRITE_SVLC( pcSlice->getInvCodedScale ()[ uiId ] + pcSlice->getCodedScale ()[ uiId ], "inverse_coded_scale_plus_coded_scale" );
    1164         WRITE_SVLC( pcSlice->getInvCodedOffset()[ uiId ] + pcSlice->getCodedOffset()[ uiId ], "inverse_coded_offset_plus_coded_offset" );
    1165       }
    1166     }
     1281      for( UInt uiId = 0; uiId < pcSlice->getViewIndex(); uiId++ )
     1282      {
     1283        WRITE_SVLC( pcSlice->getCodedScale    ()[ uiId ],                                     "cp_scale" );
     1284        WRITE_SVLC( pcSlice->getCodedOffset   ()[ uiId ],                                     "cp_off" );
     1285        WRITE_SVLC( pcSlice->getInvCodedScale ()[ uiId ] + pcSlice->getCodedScale ()[ uiId ], "cp_inv_scale_plus_scale" );
     1286        WRITE_SVLC( pcSlice->getInvCodedOffset()[ uiId ] + pcSlice->getCodedOffset()[ uiId ], "cp_inv_off_plus_off" );
     1287      }
     1288    }
     1289
     1290    Bool sliceSegmentHeaderExtension2Flag = false;
     1291    WRITE_FLAG( sliceSegmentHeaderExtension2Flag ? 1 : 0 , "slice_segment_header_extension2_flag" );
     1292    if ( sliceSegmentHeaderExtension2Flag )
     1293    {
     1294      WRITE_UVLC(0,"slice_header_extension2_length");
     1295    }
     1296#endif
     1297  }
     1298}
     1299
     1300Void TEncCavlc::codePTL( TComPTL* pcPTL, Bool profilePresentFlag, Int maxNumSubLayersMinus1)
     1301{
     1302  if(profilePresentFlag)
     1303  {
     1304    codeProfileTier(pcPTL->getGeneralPTL());    // general_...
     1305  }
     1306  WRITE_CODE( pcPTL->getGeneralPTL()->getLevelIdc(), 8, "general_level_idc" );
     1307
     1308  for (Int i = 0; i < maxNumSubLayersMinus1; i++)
     1309  {
     1310#if !H_MV
     1311    if(profilePresentFlag)
     1312    {
     1313#endif
     1314      WRITE_FLAG( pcPTL->getSubLayerProfilePresentFlag(i), "sub_layer_profile_present_flag[i]" );
     1315#if !H_MV
     1316    }
     1317#endif
     1318   
     1319    WRITE_FLAG( pcPTL->getSubLayerLevelPresentFlag(i),   "sub_layer_level_present_flag[i]" );
    11671320  }
    11681321 
    1169 #if ( HHI_MPI || H3D_IVMP )
    1170   #if ( HHI_MPI && H3D_IVMP )
    1171   const int iExtraMergeCandidates = ( pcSlice->getSPS()->getUseMVI() || pcSlice->getSPS()->getMultiviewMvPredMode() ) ? 1 : 0;
    1172   #elif HHI_MPI
    1173   const int iExtraMergeCandidates = pcSlice->getSPS()->getUseMVI() ? 1 : 0;
    1174   #elif MTK_DEPTH_MERGE_TEXTURE_CANDIDATE_C0137
    1175   const int iExtraMergeCandidates = ( pcSlice->getIsDepth() || pcSlice->getSPS()->getMultiviewMvPredMode() ) ? 1 : 0;
    1176   #else
    1177   const int iExtraMergeCandidates = pcSlice->getSPS()->getMultiviewMvPredMode() ? 1 : 0;
    1178   #endif
    1179   assert(pcSlice->getMaxNumMergeCand()<=(MRG_MAX_NUM_CANDS_SIGNALED+iExtraMergeCandidates));
    1180   assert(MRG_MAX_NUM_CANDS_SIGNALED<=MRG_MAX_NUM_CANDS);
    1181   WRITE_UVLC(MRG_MAX_NUM_CANDS + iExtraMergeCandidates - pcSlice->getMaxNumMergeCand(), "maxNumMergeCand");
    1182 #else
    1183   assert(pcSlice->getMaxNumMergeCand()<=MRG_MAX_NUM_CANDS_SIGNALED);
    1184   assert(MRG_MAX_NUM_CANDS_SIGNALED<=MRG_MAX_NUM_CANDS);
    1185   WRITE_UVLC(MRG_MAX_NUM_CANDS - pcSlice->getMaxNumMergeCand(), "maxNumMergeCand");
    1186 #endif
    1187 }
    1188 
    1189 
    1190 Void TEncCavlc::codeTileMarkerFlag(TComSlice* pcSlice)
    1191 {
    1192   Bool bEntropySlice = (!pcSlice->isNextSlice());
    1193   if (!bEntropySlice)
    1194   {
    1195     xWriteFlag  (pcSlice->getTileMarkerFlag() ? 1 : 0 );
    1196   }
    1197 }
     1322  if (maxNumSubLayersMinus1 > 0)
     1323  {
     1324    for (Int i = maxNumSubLayersMinus1; i < 8; i++)
     1325    {
     1326      WRITE_CODE(0, 2, "reserved_zero_2bits");
     1327    }
     1328  }
     1329 
     1330  for(Int i = 0; i < maxNumSubLayersMinus1; i++)
     1331  {
     1332    if( profilePresentFlag && pcPTL->getSubLayerProfilePresentFlag(i) )
     1333    {
     1334      codeProfileTier(pcPTL->getSubLayerPTL(i));  // sub_layer_...
     1335    }
     1336    if( pcPTL->getSubLayerLevelPresentFlag(i) )
     1337    {
     1338      WRITE_CODE( pcPTL->getSubLayerPTL(i)->getLevelIdc(), 8, "sub_layer_level_idc[i]" );
     1339    }
     1340  }
     1341}
     1342Void TEncCavlc::codeProfileTier( ProfileTierLevel* ptl )
     1343{
     1344  WRITE_CODE( ptl->getProfileSpace(), 2 ,     "XXX_profile_space[]");
     1345  WRITE_FLAG( ptl->getTierFlag    (),         "XXX_tier_flag[]"    );
     1346  WRITE_CODE( ptl->getProfileIdc  (), 5 ,     "XXX_profile_idc[]"  );   
     1347  for(Int j = 0; j < 32; j++)
     1348  {
     1349    WRITE_FLAG( ptl->getProfileCompatibilityFlag(j), "XXX_profile_compatibility_flag[][j]");   
     1350  }
     1351
     1352  WRITE_FLAG(ptl->getProgressiveSourceFlag(),   "general_progressive_source_flag");
     1353  WRITE_FLAG(ptl->getInterlacedSourceFlag(),    "general_interlaced_source_flag");
     1354  WRITE_FLAG(ptl->getNonPackedConstraintFlag(), "general_non_packed_constraint_flag");
     1355  WRITE_FLAG(ptl->getFrameOnlyConstraintFlag(), "general_frame_only_constraint_flag");
     1356 
     1357  WRITE_CODE(0 , 16, "XXX_reserved_zero_44bits[0..15]");
     1358  WRITE_CODE(0 , 16, "XXX_reserved_zero_44bits[16..31]");
     1359  WRITE_CODE(0 , 12, "XXX_reserved_zero_44bits[32..43]");
     1360    }
    11981361
    11991362/**
     
    12041367Void  TEncCavlc::codeTilesWPPEntryPoint( TComSlice* pSlice )
    12051368{
    1206   Int tilesOrEntropyCodingSyncIdc = pSlice->getSPS()->getTilesOrEntropyCodingSyncIdc();
    1207 
    1208   if ( tilesOrEntropyCodingSyncIdc == 0 )
     1369  if (!pSlice->getPPS()->getTilesEnabledFlag() && !pSlice->getPPS()->getEntropyCodingSyncEnabledFlag())
    12091370  {
    12101371    return;
    12111372  }
    1212 
    12131373  UInt numEntryPointOffsets = 0, offsetLenMinus1 = 0, maxOffset = 0;
     1374  Int  numZeroSubstreamsAtStartOfSlice  = 0;
    12141375  UInt *entryPointOffset = NULL;
    1215   if (tilesOrEntropyCodingSyncIdc == 1) // tiles
     1376  if ( pSlice->getPPS()->getTilesEnabledFlag() )
    12161377  {
    12171378    numEntryPointOffsets = pSlice->getTileLocationCount();
     
    12341395    }
    12351396  }
    1236   else if (tilesOrEntropyCodingSyncIdc == 2) // wavefront
    1237   {
    1238     Int  numZeroSubstreamsAtEndOfSlice  = 0;
     1397  else if ( pSlice->getPPS()->getEntropyCodingSyncEnabledFlag() )
     1398  {
    12391399    UInt* pSubstreamSizes               = pSlice->getSubstreamSizes();
    1240     // Find number of zero substreams at the end of slice
    1241     for (Int idx=pSlice->getPPS()->getNumSubstreams()-2; idx>=0; idx--)
    1242     {
    1243       if ( pSubstreamSizes[ idx ] ==  0 )
    1244       {
    1245         numZeroSubstreamsAtEndOfSlice++;
    1246       }
    1247       else
    1248       {
    1249         break;
    1250       }
    1251     }
    1252     numEntryPointOffsets       = pSlice->getPPS()->getNumSubstreams() - 1 - numZeroSubstreamsAtEndOfSlice;
     1400    Int maxNumParts                       = pSlice->getPic()->getNumPartInCU();
     1401    numZeroSubstreamsAtStartOfSlice       = pSlice->getSliceSegmentCurStartCUAddr()/maxNumParts/pSlice->getPic()->getFrameWidthInCU();
     1402    Int  numZeroSubstreamsAtEndOfSlice    = pSlice->getPic()->getFrameHeightInCU()-1 - ((pSlice->getSliceSegmentCurEndCUAddr()-1)/maxNumParts/pSlice->getPic()->getFrameWidthInCU());
     1403    numEntryPointOffsets                  = pSlice->getPPS()->getNumSubstreams() - numZeroSubstreamsAtStartOfSlice - numZeroSubstreamsAtEndOfSlice - 1;
     1404    pSlice->setNumEntryPointOffsets(numEntryPointOffsets);
    12531405    entryPointOffset           = new UInt[numEntryPointOffsets];
    12541406    for (Int idx=0; idx<numEntryPointOffsets; idx++)
    12551407    {
    1256       entryPointOffset[ idx ] = ( pSubstreamSizes[ idx ] >> 3 ) ;
     1408      entryPointOffset[ idx ] = ( pSubstreamSizes[ idx+numZeroSubstreamsAtStartOfSlice ] >> 3 ) ;
    12571409      if ( entryPointOffset[ idx ] > maxOffset )
    12581410      {
     
    12611413    }
    12621414  }
    1263 
    1264   maxOffset += ((m_pcBitIf->getNumberOfWrittenBits() + 16) >> 3) + 8 + 2; // allowing for NALU header, slice header, bytes added for "offset_len_minus1" and "num_entry_point_offsets"
    1265 
    12661415  // Determine number of bits "offsetLenMinus1+1" required for entry point information
    12671416  offsetLenMinus1 = 0;
    1268   while (1)
    1269   {
    1270     if (maxOffset >= (1 << offsetLenMinus1) )
    1271     {
    1272       offsetLenMinus1++;
    1273       if ( offsetLenMinus1 > 32 )
    1274       {
    1275         FATAL_ERROR_0("exceeded 32-bits", -1);
    1276       }
    1277     }
    1278     else
    1279     {
    1280       break;
    1281     }
     1417  while (maxOffset >= (1u << (offsetLenMinus1 + 1)))
     1418  {
     1419    offsetLenMinus1++;
     1420    assert(offsetLenMinus1 + 1 < 32);   
    12821421  }
    12831422
     
    12901429  for (UInt idx=0; idx<numEntryPointOffsets; idx++)
    12911430  {
    1292     if ( idx == 0 )
    1293     {
    1294       // Adding sizes of NALU header and slice header information to entryPointOffset[ 0 ]
    1295       Int bitDistFromNALUHdrStart    = m_pcBitIf->getNumberOfWrittenBits() + 16;
    1296       entryPointOffset[ idx ] += ( bitDistFromNALUHdrStart + numEntryPointOffsets*(offsetLenMinus1+1) ) >> 3;
    1297     }
    1298     WRITE_CODE(entryPointOffset[ idx ], offsetLenMinus1+1, "entry_point_offset");
     1431    WRITE_CODE(entryPointOffset[ idx ]-1, offsetLenMinus1+1, "entry_point_offset_minus1");
    12991432  }
    13001433
     
    13101443}
    13111444
    1312 #if H3D_IVMP
    1313 Void TEncCavlc::codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList, Int iNum )
    1314 #else
    13151445Void TEncCavlc::codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
    1316 #endif
    13171446{
    13181447  assert(0);
     
    13391468}
    13401469
    1341 #if H3D_IVRP
    1342 Void
    1343 TEncCavlc::codeResPredFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
    1344 {
    1345   assert(0);
    1346 }
    1347 #endif
    1348 #if QC_ARP_D0177
     1470#if H_3D_ARP
    13491471Void TEncCavlc::codeARPW( TComDataCU* pcCU, UInt uiAbsPartIdx )
    13501472{
    1351   assert( false );
    1352 }
    1353 #endif
    1354 Void TEncCavlc::codeAlfCtrlFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
    1355 
    1356   if (!m_bAlfCtrl)
    1357   {
    1358     return;
    1359   }
    1360  
    1361   if( pcCU->getDepth(uiAbsPartIdx) > m_uiMaxAlfCtrlDepth && !pcCU->isFirstAbsZorderIdxInDepth(uiAbsPartIdx, m_uiMaxAlfCtrlDepth))
    1362   {
    1363     return;
    1364   }
    1365  
    1366   // get context function is here
    1367   UInt uiSymbol = pcCU->getAlfCtrlFlag( uiAbsPartIdx ) ? 1 : 0;
    1368  
    1369   xWriteFlag( uiSymbol );
    1370 }
    1371 
    1372 Void TEncCavlc::codeApsExtensionFlag ()
    1373 {
    1374   WRITE_FLAG(0, "aps_extension_flag");
    1375 }
    1376 
    1377 Void TEncCavlc::codeAlfCtrlDepth()
    1378 
    1379   if (!m_bAlfCtrl)
    1380   {
    1381     return;
    1382   }
    1383  
    1384   UInt uiDepth = m_uiMaxAlfCtrlDepth;
    1385  
    1386   xWriteUvlc(uiDepth);
    1387 }
     1473  assert(0);
     1474}
     1475#endif
     1476
     1477#if H_3D_IC
     1478Void TEncCavlc::codeICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
     1479{
     1480  assert(0);
     1481}
     1482#endif
    13881483
    13891484Void TEncCavlc::codeInterModeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiEncMode )
     
    13921487}
    13931488
     1489Void TEncCavlc::codeCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
     1490{
     1491  assert(0);
     1492}
     1493
    13941494Void TEncCavlc::codeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
    13951495{
     
    13971497}
    13981498
    1399 #if LGE_ILLUCOMP_B0045
    1400 Void TEncCavlc::codeICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
    1401 {
    1402   assert(0);
    1403 }
    1404 #endif
    1405 
    14061499Void TEncCavlc::codeSplitFlag   ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    14071500{
     
    14241517}
    14251518
    1426 /** Code I_PCM information.
     1519Void TEncCavlc::codeQtCbfZero( TComDataCU* pcCU, TextType eType, UInt uiTrDepth )
     1520{
     1521  assert(0);
     1522}
     1523Void TEncCavlc::codeQtRootCbfZero( TComDataCU* pcCU )
     1524{
     1525  assert(0);
     1526}
     1527
     1528Void TEncCavlc::codeTransformSkipFlags (TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, TextType eTType )
     1529{
     1530  assert(0);
     1531}
     1532
     1533/** Code I_PCM information.
    14271534 * \param pcCU pointer to CU
    14281535 * \param uiAbsPartIdx CU index
    1429  * \param numIPCM the number of succesive IPCM blocks with the same size
    1430  * \param firstIPCMFlag
    14311536 * \returns Void
    14321537 */
    1433 Void TEncCavlc::codeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Int numIPCM, Bool firstIPCMFlag)
    1434 {
    1435   assert(0);
    1436 }
    1437 
    1438 Void TEncCavlc::codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx
    1439 #if PKU_QC_DEPTH_INTRA_UNI_D0195
    1440                                     , Bool bSdcRD
    1441 #endif
    1442                                     )
     1538Void TEncCavlc::codeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx )
     1539{
     1540  assert(0);
     1541}
     1542
     1543Void TEncCavlc::codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool isMultiple)
    14431544{
    14441545  assert(0);
     
    14821583}
    14831584
    1484 Void TEncCavlc::codeAlfFlag( UInt uiCode )
    1485 
    1486   xWriteFlag( uiCode );
    1487 }
    1488 
    1489 Void TEncCavlc::codeAlfCtrlFlag( UInt uiSymbol )
    1490 {
    1491   xWriteFlag( uiSymbol );
    1492 }
    1493 
    1494 Void TEncCavlc::codeAlfUvlc( UInt uiCode )
    1495 {
    1496   xWriteUvlc( uiCode );
    1497 }
    1498 
    1499 Void TEncCavlc::codeAlfSvlc( Int iCode )
    1500 {
    1501   xWriteSvlc( iCode );
    1502 }
    1503 /** Code the fixed length code (smaller than one max value) in OSALF
    1504  * \param idx:  coded value
    1505  * \param maxValue: max value
    1506  */
    1507 Void TEncCavlc::codeAlfFixedLengthIdx( UInt idx, UInt maxValue)
    1508 {
    1509   UInt length = 0;
    1510   assert(idx<=maxValue);
    1511 
    1512   UInt temp = maxValue;
    1513   for(UInt i=0; i<32; i++)
    1514   {
    1515     if(temp&0x1)
    1516     {
    1517       length = i+1;
    1518     }
    1519     temp = (temp >> 1);
    1520   }
    1521 
    1522   if(length)
    1523   {
    1524     xWriteCode( idx, length );
    1525   }
    1526 }
    1527 #if !LGE_SAO_MIGRATION_D0091
    1528 Void TEncCavlc::codeSaoFlag( UInt uiCode )
    1529 {
    1530   xWriteFlag( uiCode );
    1531 }
    1532 
    1533 Void TEncCavlc::codeSaoUvlc( UInt uiCode )
    1534 {
    1535     xWriteUvlc( uiCode );
    1536 }
    1537 
    1538 Void TEncCavlc::codeSaoSvlc( Int iCode )
    1539 {
    1540     xWriteSvlc( iCode );
    1541 }
    1542 /** Code SAO run.
    1543  * \param uiCode
    1544  * \param maxValue
    1545  */
    1546 Void TEncCavlc::codeSaoRun( UInt uiCode, UInt maxValue)
    1547 {
    1548   UInt uiLength = 0;
    1549   if (!maxValue)
    1550   {
    1551     return;
    1552   }
    1553   assert(uiCode<=maxValue);             
    1554 
    1555   for(UInt i=0; i<32; i++)                                     
    1556   {                                                           
    1557     if(maxValue&0x1)                                               
    1558     {                                                         
    1559       uiLength = i+1;                                         
    1560     }                                                         
    1561     maxValue = (maxValue >> 1);                                       
    1562   }
    1563   WRITE_CODE( uiCode, uiLength, "sao_run_diff");
    1564 }
    1565 #endif
    1566 
    15671585Void TEncCavlc::estBit( estBitsSbacStruct* pcEstBitsCabac, Int width, Int height, TextType eTType )
    15681586{
     
    15741592// Protected member functions
    15751593// ====================================================================================================================
    1576 
    1577 Void TEncCavlc::xWriteCode     ( UInt uiCode, UInt uiLength )
    1578 {
    1579   assert ( uiLength > 0 );
    1580   m_pcBitIf->write( uiCode, uiLength );
    1581 }
    1582 
    1583 Void TEncCavlc::xWriteUvlc     ( UInt uiCode )
    1584 {
    1585   UInt uiLength = 1;
    1586   UInt uiTemp = ++uiCode;
    1587  
    1588   assert ( uiTemp );
    1589  
    1590   while( 1 != uiTemp )
    1591   {
    1592     uiTemp >>= 1;
    1593     uiLength += 2;
    1594   }
    1595  
    1596   //m_pcBitIf->write( uiCode, uiLength );
    1597   // Take care of cases where uiLength > 32
    1598   m_pcBitIf->write( 0, uiLength >> 1);
    1599   m_pcBitIf->write( uiCode, (uiLength+1) >> 1);
    1600 }
    1601 
    1602 Void TEncCavlc::xWriteSvlc     ( Int iCode )
    1603 {
    1604   UInt uiCode;
    1605  
    1606   uiCode = xConvertToUInt( iCode );
    1607   xWriteUvlc( uiCode );
    1608 }
    1609 
    1610 Void TEncCavlc::xWriteFlag( UInt uiCode )
    1611 {
    1612   m_pcBitIf->write( uiCode, 1 );
    1613 }
    1614 
    1615 /** Write PCM alignment bits.
    1616  * \returns Void
    1617  */
    1618 Void  TEncCavlc::xWritePCMAlignZero    ()
    1619 {
    1620   m_pcBitIf->writeAlignZero();
    1621 }
    1622 
    1623 Void TEncCavlc::xWriteUnaryMaxSymbol( UInt uiSymbol, UInt uiMaxSymbol )
    1624 {
    1625   if (uiMaxSymbol == 0)
    1626   {
    1627     return;
    1628   }
    1629   xWriteFlag( uiSymbol ? 1 : 0 );
    1630   if ( uiSymbol == 0 )
    1631   {
    1632     return;
    1633   }
    1634  
    1635   Bool bCodeLast = ( uiMaxSymbol > uiSymbol );
    1636  
    1637   while( --uiSymbol )
    1638   {
    1639     xWriteFlag( 1 );
    1640   }
    1641   if( bCodeLast )
    1642   {
    1643     xWriteFlag( 0 );
    1644   }
    1645   return;
    1646 }
    1647 
    1648 Void TEncCavlc::xWriteExGolombLevel( UInt uiSymbol )
    1649 {
    1650   if( uiSymbol )
    1651   {
    1652     xWriteFlag( 1 );
    1653     UInt uiCount = 0;
    1654     Bool bNoExGo = (uiSymbol < 13);
    1655    
    1656     while( --uiSymbol && ++uiCount < 13 )
    1657     {
    1658       xWriteFlag( 1 );
    1659     }
    1660     if( bNoExGo )
    1661     {
    1662       xWriteFlag( 0 );
    1663     }
    1664     else
    1665     {
    1666       xWriteEpExGolomb( uiSymbol, 0 );
    1667     }
    1668   }
    1669   else
    1670   {
    1671     xWriteFlag( 0 );
    1672   }
    1673   return;
    1674 }
    1675 
    1676 Void TEncCavlc::xWriteEpExGolomb( UInt uiSymbol, UInt uiCount )
    1677 {
    1678   while( uiSymbol >= (UInt)(1<<uiCount) )
    1679   {
    1680     xWriteFlag( 1 );
    1681     uiSymbol -= 1<<uiCount;
    1682     uiCount  ++;
    1683   }
    1684   xWriteFlag( 0 );
    1685   while( uiCount-- )
    1686   {
    1687     xWriteFlag( (uiSymbol>>uiCount) & 1 );
    1688   }
    1689   return;
    1690 }
    16911594
    16921595/** code explicit wp tables
     
    17001603  Int             iNbRef       = (pcSlice->getSliceType() == B_SLICE ) ? (2) : (1);
    17011604  Bool            bDenomCoded  = false;
    1702 
    17031605  UInt            uiMode = 0;
    1704   if ( (pcSlice->getSliceType()==P_SLICE && pcSlice->getPPS()->getUseWP()) || (pcSlice->getSliceType()==B_SLICE && pcSlice->getPPS()->getWPBiPredIdc()==1 && pcSlice->getRefPicListCombinationFlag()==0 ) )
     1606  UInt            uiTotalSignalledWeightFlags = 0;
     1607  if ( (pcSlice->getSliceType()==P_SLICE && pcSlice->getPPS()->getUseWP()) || (pcSlice->getSliceType()==B_SLICE && pcSlice->getPPS()->getWPBiPred()) )
     1608  {
    17051609    uiMode = 1; // explicit
    1706   else if ( pcSlice->getSliceType()==B_SLICE && pcSlice->getPPS()->getWPBiPredIdc()==2 )
    1707     uiMode = 2; // implicit (does not use this mode in this syntax)
    1708   if (pcSlice->getSliceType()==B_SLICE && pcSlice->getPPS()->getWPBiPredIdc()==1 && pcSlice->getRefPicListCombinationFlag())
    1709     uiMode = 3; // combined explicit
     1610  }
    17101611  if(uiMode == 1)
    17111612  {
     1613
    17121614    for ( Int iNumRef=0 ; iNumRef<iNbRef ; iNumRef++ )
    17131615    {
    17141616      RefPicList  eRefPicList = ( iNumRef ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
     1617
    17151618      for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
    17161619      {
     
    17281631          bDenomCoded = true;
    17291632        }
    1730 
    17311633        WRITE_FLAG( wp[0].bPresentFlag, "luma_weight_lX_flag" );               // u(1): luma_weight_lX_flag
    1732 
     1634        uiTotalSignalledWeightFlags += wp[0].bPresentFlag;
     1635      }
     1636      if (bChroma)
     1637      {
     1638        for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
     1639        {
     1640          pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
     1641          WRITE_FLAG( wp[1].bPresentFlag, "chroma_weight_lX_flag" );           // u(1): chroma_weight_lX_flag
     1642          uiTotalSignalledWeightFlags += 2*wp[1].bPresentFlag;
     1643        }
     1644      }
     1645
     1646      for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
     1647      {
     1648        pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
    17331649        if ( wp[0].bPresentFlag )
    17341650        {
     
    17401656        if ( bChroma )
    17411657        {
    1742           WRITE_FLAG( wp[1].bPresentFlag, "chroma_weight_lX_flag" );           // u(1): chroma_weight_lX_flag
    1743 
    17441658          if ( wp[1].bPresentFlag )
    17451659          {
     
    17491663              WRITE_SVLC( iDeltaWeight, "delta_chroma_weight_lX" );            // se(v): delta_chroma_weight_lX
    17501664
    1751               Int iDeltaChroma = (wp[j].iOffset + ( ( (g_uiIBDI_MAX>>1)*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) - (g_uiIBDI_MAX>>1));
     1665              Int pred = ( 128 - ( ( 128*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) );
     1666              Int iDeltaChroma = (wp[j].iOffset - pred);
    17521667              WRITE_SVLC( iDeltaChroma, "delta_chroma_offset_lX" );            // se(v): delta_chroma_offset_lX
    17531668            }
     
    17561671      }
    17571672    }
    1758   }
    1759   else if (uiMode == 3)
    1760   {
    1761     for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(REF_PIC_LIST_C) ; iRefIdx++ )
    1762     {
    1763       RefPicList  eRefPicList = (RefPicList)pcSlice->getListIdFromIdxOfLC(iRefIdx);
    1764       Int iCombRefIdx = pcSlice->getRefIdxFromIdxOfLC(iRefIdx);
    1765 
    1766       pcSlice->getWpScaling(eRefPicList, iCombRefIdx, wp);
    1767       if ( !bDenomCoded )
    1768       {
    1769         Int iDeltaDenom;
    1770         WRITE_UVLC( wp[0].uiLog2WeightDenom, "luma_log2_weight_denom" );       // ue(v): luma_log2_weight_denom
    1771 
    1772         if( bChroma )
    1773         {
    1774           iDeltaDenom = (wp[1].uiLog2WeightDenom - wp[0].uiLog2WeightDenom);
    1775           WRITE_SVLC( iDeltaDenom, "delta_chroma_log2_weight_denom" );         // se(v): delta_chroma_log2_weight_denom
    1776         }
    1777         bDenomCoded = true;
    1778       }
    1779 
    1780       WRITE_FLAG( wp[0].bPresentFlag, "luma_weight_lc_flag" );                 // u(1): luma_weight_lc_flag
    1781 
    1782       if ( wp[0].bPresentFlag )
    1783       {
    1784         Int iDeltaWeight = (wp[0].iWeight - (1<<wp[0].uiLog2WeightDenom));
    1785         WRITE_SVLC( iDeltaWeight, "delta_luma_weight_lc" );                    // se(v): delta_luma_weight_lc
    1786         WRITE_SVLC( wp[0].iOffset, "luma_offset_lc" );                         // se(v): luma_offset_lc
    1787       }
    1788       if ( bChroma )
    1789       {
    1790         WRITE_FLAG( wp[1].bPresentFlag, "chroma_weight_lc_flag" );             // u(1): luma_weight_lc_flag
    1791 
    1792         if ( wp[1].bPresentFlag )
    1793         {
    1794           for ( Int j=1 ; j<3 ; j++ )
    1795           {
    1796             Int iDeltaWeight = (wp[j].iWeight - (1<<wp[1].uiLog2WeightDenom));
    1797             WRITE_SVLC( iDeltaWeight, "delta_chroma_weight_lc" );              // se(v): delta_chroma_weight_lc
    1798 
    1799             Int iDeltaChroma = (wp[j].iOffset + ( ( (g_uiIBDI_MAX>>1)*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) - (g_uiIBDI_MAX>>1));
    1800             WRITE_SVLC( iDeltaChroma, "delta_chroma_offset_lc" );              // se(v): delta_chroma_offset_lc
    1801           }
    1802         }
    1803       }
    1804     }
     1673    assert(uiTotalSignalledWeightFlags<=24);
    18051674  }
    18061675}
     
    18211690#endif
    18221691
    1823   WRITE_FLAG( scalingList->getScalingListPresentFlag (), "scaling_list_present_flag" );
    1824 
    1825   if(scalingList->getScalingListPresentFlag () == false)
    1826   {
    1827 #if SCALING_LIST_OUTPUT_RESULT
    1828     printf("Header Bit %d\n",m_pcBitIf->getNumberOfWrittenBits()-startBit);
    1829 #endif
    18301692    //for each size
    18311693    for(sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
     
    18401702        if(!scalingListPredModeFlag)// Copy Mode
    18411703        {
    1842           WRITE_UVLC( (Int)listId - (Int)scalingList->getRefMatrixId (sizeId,listId) - 1, "scaling_list_pred_matrix_id_delta");
     1704          WRITE_UVLC( (Int)listId - (Int)scalingList->getRefMatrixId (sizeId,listId), "scaling_list_pred_matrix_id_delta");
    18431705        }
    18441706        else// DPCM Mode
     
    18511713      }
    18521714    }
    1853   }
    18541715#if SCALING_LIST_OUTPUT_RESULT
    1855   else
    1856   {
    1857     printf("Header Bit %d\n",m_pcBitIf->getNumberOfWrittenBits()-startTotalBit);
    1858   }
    18591716  printf("Total Bit %d\n",m_pcBitIf->getNumberOfWrittenBits()-startTotalBit);
    18601717#endif
     
    18691726{
    18701727  Int coefNum = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]);
    1871   UInt* scan    = g_auiFrameScanXY [ (sizeId == 0)? 1 : 2];
     1728  UInt* scan  = (sizeId == 0) ? g_auiSigLastScan [ SCAN_DIAG ] [ 1 ] :  g_sigLastScanCG32x32;
    18721729  Int nextCoef = SCALING_LIST_START_VALUE;
    18731730  Int data;
    18741731  Int *src = scalingList->getScalingListAddress(sizeId, listId);
    1875   if(sizeId > SCALING_LIST_8x8 && scalingList->getUseDefaultScalingMatrixFlag(sizeId,listId))
    1876   {
    1877     WRITE_SVLC( -8, "scaling_list_dc_coef_minus8");
    1878   }
    1879   else if(sizeId < SCALING_LIST_16x16 && scalingList->getUseDefaultScalingMatrixFlag(sizeId,listId))
    1880   {
    1881     WRITE_SVLC( -8, "scaling_list_delta_coef");
    1882   }
    1883   else
    1884   {
    18851732    if( sizeId > SCALING_LIST_8x8 )
    18861733    {
    18871734      WRITE_SVLC( scalingList->getScalingListDC(sizeId,listId) - 8, "scaling_list_dc_coef_minus8");
     1735      nextCoef = scalingList->getScalingListDC(sizeId,listId);
    18881736    }
    18891737    for(Int i=0;i<coefNum;i++)
     
    19021750      WRITE_SVLC( data,  "scaling_list_delta_coef");
    19031751    }
    1904   }
     1752}
     1753Bool TEncCavlc::findMatchingLTRP ( TComSlice* pcSlice, UInt *ltrpsIndex, Int ltrpPOC, Bool usedFlag )
     1754{
     1755  // Bool state = true, state2 = false;
     1756  Int lsb = ltrpPOC % (1<<pcSlice->getSPS()->getBitsForPOC());
     1757  for (Int k = 0; k < pcSlice->getSPS()->getNumLongTermRefPicSPS(); k++)
     1758  {
     1759    if ( (lsb == pcSlice->getSPS()->getLtRefPicPocLsbSps(k)) && (usedFlag == pcSlice->getSPS()->getUsedByCurrPicLtSPSFlag(k)) )
     1760    {
     1761      *ltrpsIndex = k;
     1762      return true;
     1763    }
     1764  }
     1765  return false;
    19051766}
    19061767Bool TComScalingList::checkPredMode(UInt sizeId, UInt listId)
    19071768{
    1908   for(Int predListIdx = (Int)listId -1 ; predListIdx >= 0; predListIdx--)
    1909   {
    1910     if( !memcmp(getScalingListAddress(sizeId,listId),getScalingListAddress(sizeId, predListIdx),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])) // check value of matrix
     1769  for(Int predListIdx = (Int)listId ; predListIdx >= 0; predListIdx--)
     1770  {
     1771    if( !memcmp(getScalingListAddress(sizeId,listId),((listId == predListIdx) ?
     1772      getScalingListDefaultAddress(sizeId, predListIdx): getScalingListAddress(sizeId, predListIdx)),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])) // check value of matrix
    19111773     && ((sizeId < SCALING_LIST_16x16) || (getScalingListDC(sizeId,listId) == getScalingListDC(sizeId,predListIdx)))) // check DC value
    19121774    {
     
    19181780}
    19191781
    1920 #if RWTH_SDC_DLT_B0036
    1921 #if !PKU_QC_DEPTH_INTRA_UNI_D0195
    1922 Void TEncCavlc::codeSDCFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx )
    1923 {
    1924   assert(0);
    1925 }
    1926 #endif
    1927 Void TEncCavlc::codeSDCResidualData  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiSegment )
    1928 {
    1929   assert(0);
    1930 }
    1931 #if !PKU_QC_DEPTH_INTRA_UNI_D0195
    1932 Void TEncCavlc::codeSDCPredMode ( TComDataCU* pcCU, UInt uiAbsPartIdx )
    1933 {
    1934   assert(0);
    1935 }
    1936 #endif
     1782#if LGE_INTER_SDC_E0156
     1783Void TEncCavlc::codeInterSDCFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx )
     1784{
     1785  assert(0);
     1786}
     1787
     1788Void TEncCavlc::codeInterSDCResidualData  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiSegment )
     1789{
     1790  assert(0);
     1791}
    19371792#endif
    19381793//! \}
Note: See TracChangeset for help on using the changeset viewer.