Changeset 906 in SHVCSoftware for trunk/source/Lib/TLibDecoder


Ignore:
Timestamp:
15 Oct 2014, 07:25:10 (10 years ago)
Author:
seregin
Message:

merge SHM-dev

Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/source

  • trunk/source/Lib/TLibDecoder/SEIread.cpp

    r815 r906  
    9898    break;
    9999#endif
    100 #if Q0074_SEI_COLOR_MAPPING
    101   case SEI::COLOR_MAPPING_INFO:
    102     fprintf( g_hTrace, "===========Color Mapping Info SEI message ===========\n");
     100#if Q0074_COLOUR_REMAPPING_SEI
     101  case SEI::COLOUR_REMAPPING_INFO:
     102    fprintf( g_hTrace, "===========Colour Remapping Information SEI message ===========\n");
    103103    break;
    104104#endif
     
    132132    fprintf( g_hTrace, "=========== Bitstream parition initial arrival time SEI message ===========\n");
    133133    break;
     134#if !REMOVE_BSP_HRD_SEI
    134135  case SEI::BSP_HRD:
    135136    fprintf( g_hTrace, "=========== Bitstream parition HRD parameters SEI message ===========\n");
    136137    break;
     138#endif
    137139#endif
    138140#if Q0078_ADD_LAYER_SETS
     
    249251      {
    250252        sei = new SEIDecodingUnitInfo;
     253#if VPS_VUI_BSP_HRD_PARAMS
     254        xParseSEIDecodingUnitInfo((SEIDecodingUnitInfo&) *sei, payloadSize, sps, nestingSei, bspNestingSei, vps);
     255#else
    251256        xParseSEIDecodingUnitInfo((SEIDecodingUnitInfo&) *sei, payloadSize, sps);
     257#endif
    252258      }
    253259      break;
     
    260266      {
    261267        sei = new SEIBufferingPeriod;
     268#if VPS_VUI_BSP_HRD_PARAMS
     269        xParseSEIBufferingPeriod((SEIBufferingPeriod&) *sei, payloadSize, sps, nestingSei, bspNestingSei, vps);
     270#else
    262271        xParseSEIBufferingPeriod((SEIBufferingPeriod&) *sei, payloadSize, sps);
     272#endif
    263273      }
    264274      break;
     
    271281      {
    272282        sei = new SEIPictureTiming;
     283#if VPS_VUI_BSP_HRD_PARAMS
     284        xParseSEIPictureTiming((SEIPictureTiming&)*sei, payloadSize, sps, nestingSei, bspNestingSei, vps);
     285#else
    273286        xParseSEIPictureTiming((SEIPictureTiming&)*sei, payloadSize, sps);
     287#endif
    274288      }
    275289      break;
     
    304318      break;
    305319#endif
    306 #if Q0074_SEI_COLOR_MAPPING
    307     case SEI::COLOR_MAPPING_INFO:
    308       sei = new SEIColorMappingInfo;
    309       xParseSEIColorMappingInfo((SEIColorMappingInfo&) *sei, payloadSize);
     320#if Q0074_COLOUR_REMAPPING_SEI
     321    case SEI::COLOUR_REMAPPING_INFO:
     322      sei = new SEIColourRemappingInfo;
     323      xParseSEIColourRemappingInfo((SEIColourRemappingInfo&) *sei, payloadSize);
    310324      break;
    311325#endif
     
    345359   case SEI::SUB_BITSTREAM_PROPERTY:
    346360     sei = new SEISubBitstreamProperty;
     361#if OLS_IDX_CHK
     362     xParseSEISubBitstreamProperty((SEISubBitstreamProperty&) *sei, vps);
     363#else
    347364     xParseSEISubBitstreamProperty((SEISubBitstreamProperty&) *sei);
     365#endif
    348366     break;
    349367#endif
     
    361379     xParseSEIBspInitialArrivalTime((SEIBspInitialArrivalTime&) *sei, vps, sps, *nestingSei, *bspNestingSei);
    362380     break;
     381#if !REMOVE_BSP_HRD_SEI
    363382   case SEI::BSP_HRD:
    364383     sei = new SEIBspHrd;
    365384     xParseSEIBspHrd((SEIBspHrd&) *sei, sps, *nestingSei);
    366385     break;
     386#endif
    367387#endif
    368388#if Q0078_ADD_LAYER_SETS
     
    580600
    581601  sei.activeSeqParameterSetId.resize(sei.numSpsIdsMinus1 + 1);
     602#if R0247_SEI_ACTIVE
     603  sei.layerSpsIdx.resize(sei.numSpsIdsMinus1 + 1);
     604#endif
    582605  for (Int i=0; i < (sei.numSpsIdsMinus1 + 1); i++)
    583606  {
    584607    READ_UVLC(val, "active_seq_parameter_set_id");      sei.activeSeqParameterSetId[i] = val;
    585608  }
    586 
     609#if R0247_SEI_ACTIVE
     610  for (Int i=1; i < (sei.numSpsIdsMinus1 + 1); i++)
     611  {
     612    READ_UVLC(val, "layer_sps_idx"); sei.layerSpsIdx[i] = val;
     613  }
     614#endif
    587615  xParseByteAlign();
    588616}
    589617
     618#if VPS_VUI_BSP_HRD_PARAMS
     619Void SEIReader::xParseSEIDecodingUnitInfo(SEIDecodingUnitInfo& sei, UInt /*payloadSize*/, TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei, TComVPS *vps)
     620#else
    590621Void SEIReader::xParseSEIDecodingUnitInfo(SEIDecodingUnitInfo& sei, UInt /*payloadSize*/, TComSPS *sps)
     622#endif
    591623{
    592624  UInt val;
     
    594626  sei.m_decodingUnitIdx = val;
    595627
     628#if VPS_VUI_BSP_HRD_PARAMS
     629  TComHRD *hrd;
     630  if( bspNestingSei )   // If DU info SEI contained inside a BSP nesting SEI message
     631  {
     632    assert( nestingSei );
     633    Int psIdx = bspNestingSei->m_seiPartitioningSchemeIdx;
     634    Int seiOlsIdx = bspNestingSei->m_seiOlsIdx;
     635    Int maxTemporalId = nestingSei->m_nestingMaxTemporalIdPlus1[0] - 1;
     636    Int maxValues = vps->getNumBspSchedulesMinus1(seiOlsIdx, psIdx, maxTemporalId) + 1;
     637    std::vector<Int> hrdIdx(maxValues, 0);
     638    std::vector<TComHRD *> hrdVec;
     639    std::vector<Int> syntaxElemLen(maxValues, 0);
     640    for(Int i = 0; i < maxValues; i++)
     641    {
     642      hrdIdx[i] = vps->getBspHrdIdx( seiOlsIdx, psIdx, maxTemporalId, i, bspNestingSei->m_bspIdx);
     643      hrdVec.push_back(vps->getBspHrd(hrdIdx[i]));
     644   
     645      syntaxElemLen[i] = hrdVec[i]->getInitialCpbRemovalDelayLengthMinus1() + 1;
     646      if ( !(hrdVec[i]->getNalHrdParametersPresentFlag() || hrdVec[i]->getVclHrdParametersPresentFlag()) )
     647      {
     648        assert( syntaxElemLen[i] == 24 ); // Default of value init_cpb_removal_delay_length_minus1 is 23
     649      }
     650      if( i > 0 )
     651      {
     652        assert( hrdVec[i]->getSubPicCpbParamsPresentFlag()    == hrdVec[i-1]->getSubPicCpbParamsPresentFlag() );
     653        assert( hrdVec[i]->getSubPicCpbParamsInPicTimingSEIFlag()   == hrdVec[i-1]->getSubPicCpbParamsInPicTimingSEIFlag() );
     654        assert( hrdVec[i]->getDpbOutputDelayDuLengthMinus1()  == hrdVec[i-1]->getDpbOutputDelayDuLengthMinus1() );
     655        // To be done: Check CpbDpbDelaysPresentFlag
     656      }
     657    }
     658    hrd = hrdVec[0];
     659  }
     660  else
     661  {
     662    TComVUI *vui = sps->getVuiParameters();
     663    hrd = vui->getHrdParameters();
     664  }
     665#else
    596666  TComVUI *vui = sps->getVuiParameters();
    597   if(vui->getHrdParameters()->getSubPicCpbParamsInPicTimingSEIFlag())
    598   {
    599     READ_CODE( ( vui->getHrdParameters()->getDuCpbRemovalDelayLengthMinus1() + 1 ), val, "du_spt_cpb_removal_delay");
     667  TComHrd *hrd = vui->getHrdParameters();
     668#endif
     669  if(hrd->getSubPicCpbParamsInPicTimingSEIFlag())
     670  {
     671    READ_CODE( ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ), val, "du_spt_cpb_removal_delay");
    600672    sei.m_duSptCpbRemovalDelay = val;
    601673  }
     
    607679  if(sei.m_dpbOutputDuDelayPresentFlag)
    608680  {
    609     READ_CODE(vui->getHrdParameters()->getDpbOutputDelayDuLengthMinus1() + 1, val, "pic_spt_dpb_output_du_delay");
     681    READ_CODE(hrd->getDpbOutputDelayDuLengthMinus1() + 1, val, "pic_spt_dpb_output_du_delay");
    610682    sei.m_picSptDpbOutputDuDelay = val;
    611683  }
     
    613685}
    614686
     687#if VPS_VUI_BSP_HRD_PARAMS
     688Void SEIReader::xParseSEIBufferingPeriod(SEIBufferingPeriod& sei, UInt /*payloadSize*/, TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei, TComVPS *vps)
     689#else
    615690Void SEIReader::xParseSEIBufferingPeriod(SEIBufferingPeriod& sei, UInt /*payloadSize*/, TComSPS *sps)
     691#endif
    616692{
    617693  Int i, nalOrVcl;
    618694  UInt code;
    619695
     696#if VPS_VUI_BSP_HRD_PARAMS
     697  TComHRD *pHRD;
     698  if( bspNestingSei )   // If BP SEI contained inside a BSP nesting SEI message
     699  {
     700    assert( nestingSei );
     701    Int psIdx = bspNestingSei->m_seiPartitioningSchemeIdx;
     702    Int seiOlsIdx = bspNestingSei->m_seiOlsIdx;
     703    Int maxTemporalId = nestingSei->m_nestingMaxTemporalIdPlus1[0] - 1;
     704    Int maxValues = vps->getNumBspSchedulesMinus1(seiOlsIdx, psIdx, maxTemporalId) + 1;
     705    std::vector<Int> hrdIdx(maxValues, 0);
     706    std::vector<TComHRD *> hrdVec;
     707    std::vector<Int> syntaxElemLen(maxValues, 0);
     708    for(i = 0; i < maxValues; i++)
     709    {
     710      hrdIdx[i] = vps->getBspHrdIdx( seiOlsIdx, psIdx, maxTemporalId, i, bspNestingSei->m_bspIdx);
     711      hrdVec.push_back(vps->getBspHrd(hrdIdx[i]));
     712   
     713      syntaxElemLen[i] = hrdVec[i]->getInitialCpbRemovalDelayLengthMinus1() + 1;
     714      if ( !(hrdVec[i]->getNalHrdParametersPresentFlag() || hrdVec[i]->getVclHrdParametersPresentFlag()) )
     715      {
     716        assert( syntaxElemLen[i] == 24 ); // Default of value init_cpb_removal_delay_length_minus1 is 23
     717      }
     718      if( i > 0 )
     719      {
     720        assert( hrdVec[i]->getCpbRemovalDelayLengthMinus1()   == hrdVec[i-1]->getCpbRemovalDelayLengthMinus1() );
     721        assert( hrdVec[i]->getDpbOutputDelayDuLengthMinus1()  == hrdVec[i-1]->getDpbOutputDelayDuLengthMinus1() );
     722        assert( hrdVec[i]->getSubPicCpbParamsPresentFlag()    == hrdVec[i-1]->getSubPicCpbParamsPresentFlag() );
     723      }
     724    }
     725    pHRD = hrdVec[i];
     726  }
     727  else
     728  {
     729    TComVUI *vui = sps->getVuiParameters();
     730    pHRD = vui->getHrdParameters();
     731  }
     732  // To be done: When contained in an BSP HRD SEI message, the hrd structure is to be chosen differently.
     733#else
    620734  TComVUI *pVUI = sps->getVuiParameters();
    621735  TComHRD *pHRD = pVUI->getHrdParameters();
     736#endif
    622737
    623738  READ_UVLC( code, "bp_seq_parameter_set_id" );                         sei.m_bpSeqParameterSetId     = code;
     
    671786  xParseByteAlign();
    672787}
     788#if VPS_VUI_BSP_HRD_PARAMS
     789Void SEIReader::xParseSEIPictureTiming(SEIPictureTiming& sei, UInt /*payloadSize*/, TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei, TComVPS *vps)
     790#else
    673791Void SEIReader::xParseSEIPictureTiming(SEIPictureTiming& sei, UInt /*payloadSize*/, TComSPS *sps)
     792#endif
    674793{
    675794  Int i;
    676795  UInt code;
    677796
     797#if VPS_VUI_BSP_HRD_PARAMS
     798  TComHRD *hrd;   
     799  TComVUI *vui = sps->getVuiParameters();
     800  if( bspNestingSei )   // If BP SEI contained inside a BSP nesting SEI message
     801  {
     802    assert( nestingSei );
     803    Int psIdx = bspNestingSei->m_seiPartitioningSchemeIdx;
     804    Int seiOlsIdx = bspNestingSei->m_seiOlsIdx;
     805    Int maxTemporalId = nestingSei->m_nestingMaxTemporalIdPlus1[0] - 1;
     806    Int maxValues = vps->getNumBspSchedulesMinus1(seiOlsIdx, psIdx, maxTemporalId) + 1;
     807    std::vector<Int> hrdIdx(maxValues, 0);
     808    std::vector<TComHRD *> hrdVec;
     809    std::vector<Int> syntaxElemLen(maxValues, 0);
     810    for(i = 0; i < maxValues; i++)
     811    {
     812      hrdIdx[i] = vps->getBspHrdIdx( seiOlsIdx, psIdx, maxTemporalId, i, bspNestingSei->m_bspIdx);
     813      hrdVec.push_back(vps->getBspHrd(hrdIdx[i]));
     814   
     815      syntaxElemLen[i] = hrdVec[i]->getInitialCpbRemovalDelayLengthMinus1() + 1;
     816      if ( !(hrdVec[i]->getNalHrdParametersPresentFlag() || hrdVec[i]->getVclHrdParametersPresentFlag()) )
     817      {
     818        assert( syntaxElemLen[i] == 24 ); // Default of value init_cpb_removal_delay_length_minus1 is 23
     819      }
     820      if( i > 0 )
     821      {
     822        assert( hrdVec[i]->getSubPicCpbParamsPresentFlag()    == hrdVec[i-1]->getSubPicCpbParamsPresentFlag() );
     823        assert( hrdVec[i]->getSubPicCpbParamsInPicTimingSEIFlag()   == hrdVec[i-1]->getSubPicCpbParamsInPicTimingSEIFlag() );
     824        assert( hrdVec[i]->getCpbRemovalDelayLengthMinus1()  == hrdVec[i-1]->getCpbRemovalDelayLengthMinus1() );
     825        assert( hrdVec[i]->getDpbOutputDelayLengthMinus1()  == hrdVec[i-1]->getDpbOutputDelayLengthMinus1() );
     826        assert( hrdVec[i]->getDpbOutputDelayDuLengthMinus1()  == hrdVec[i-1]->getDpbOutputDelayDuLengthMinus1() );
     827        assert( hrdVec[i]->getDuCpbRemovalDelayLengthMinus1()  == hrdVec[i-1]->getDuCpbRemovalDelayLengthMinus1() );
     828        // To be done: Check CpbDpbDelaysPresentFlag
     829      }
     830    }
     831    hrd = hrdVec[0];
     832  }
     833  else
     834  {
     835    hrd = vui->getHrdParameters();
     836  }
     837  // To be done: When contained in an BSP HRD SEI message, the hrd structure is to be chosen differently.
     838#else
    678839  TComVUI *vui = sps->getVuiParameters();
    679840  TComHRD *hrd = vui->getHrdParameters();
     841#endif
    680842
    681843  if( vui->getFrameFieldInfoPresentFlag() )
     
    9211083#endif
    9221084
    923 #if Q0074_SEI_COLOR_MAPPING
    924 Void SEIReader::xParseSEIColorMappingInfo(SEIColorMappingInfo& sei, UInt /*payloadSize*/)
     1085#if Q0074_COLOUR_REMAPPING_SEI
     1086Void SEIReader::xParseSEIColourRemappingInfo(SEIColourRemappingInfo& sei, UInt /*payloadSize*/)
    9251087{
    9261088  UInt  uiVal;
    9271089  Int   iVal;
    9281090
    929   READ_UVLC( uiVal, "colour_map_id" );          sei.m_colorMapId = uiVal;
    930   READ_FLAG( uiVal, "colour_map_cancel_flag" ); sei.m_colorMapCancelFlag = uiVal;
    931   if( !sei.m_colorMapCancelFlag )
    932   {
    933     READ_FLAG( uiVal, "colour_map_persistence_flag" );                sei.m_colorMapPersistenceFlag = uiVal;
    934     READ_FLAG( uiVal, "colour_map_video_signal_type_present_flag" );  sei.m_colorMap_video_signal_type_present_flag = uiVal;
    935     if ( sei.m_colorMap_video_signal_type_present_flag ) {
    936       READ_FLAG( uiVal,     "colour_map_video_full_range_flag" );     sei.m_colorMap_video_full_range_flag = uiVal;
    937       READ_CODE( 8, uiVal,  "colour_map_primaries" );                 sei.m_colorMap_primaries = uiVal;
    938       READ_CODE( 8, uiVal,  "colour_map_transfer_characteristics" );  sei.m_colorMap_transfer_characteristics = uiVal;
    939       READ_CODE( 8, uiVal,  "colour_map_matrix_coeffs" );             sei.m_colorMap_matrix_coeffs = uiVal;
    940     }
    941   }
    942 
    943   READ_CODE( 5, uiVal,  "colour_map_coded_data_bit_depth" );  sei.m_colour_map_coded_data_bit_depth = uiVal;
    944   READ_CODE( 5, uiVal,  "colour_map_target_bit_depth" );      sei.m_colour_map_target_bit_depth = uiVal;
    945   READ_UVLC( uiVal, "colour_map_model_id" );                  sei.m_colorMapModelId = uiVal;
    946 
    947   assert( sei.m_colorMapModelId == 0 );
     1091  READ_UVLC( uiVal, "colour_remap_id" );          sei.m_colourRemapId = uiVal;
     1092  READ_FLAG( uiVal, "colour_remap_cancel_flag" ); sei.m_colourRemapCancelFlag = uiVal;
     1093  if( !sei.m_colourRemapCancelFlag )
     1094  {
     1095    READ_FLAG( uiVal, "colour_remap_persistence_flag" );                sei.m_colourRemapPersistenceFlag = uiVal;
     1096    READ_FLAG( uiVal, "colour_remap_video_signal_info_present_flag" );  sei.m_colourRemapVideoSignalInfoPresentFlag = uiVal;
     1097    if ( sei.m_colourRemapVideoSignalInfoPresentFlag )
     1098    {
     1099      READ_FLAG( uiVal,    "colour_remap_full_range_flag" );           sei.m_colourRemapFullRangeFlag = uiVal;
     1100      READ_CODE( 8, uiVal, "colour_remap_primaries" );                 sei.m_colourRemapPrimaries = uiVal;
     1101      READ_CODE( 8, uiVal, "colour_remap_transfer_function" );         sei.m_colourRemapTransferFunction = uiVal;
     1102      READ_CODE( 8, uiVal, "colour_remap_matrix_coefficients" );       sei.m_colourRemapMatrixCoefficients = uiVal;
     1103    }
     1104    READ_CODE( 8, uiVal, "colour_remap_input_bit_depth" ); sei.m_colourRemapInputBitDepth = uiVal;
     1105    READ_CODE( 8, uiVal, "colour_remap_bit_depth" ); sei.m_colourRemapBitDepth = uiVal;
    9481106 
    949   for( Int i=0 ; i<3 ; i++ )
    950   {
    951     READ_CODE( 8, uiVal, "num_input_pivots_minus1[i]" ); sei.m_num_input_pivots[i] = (uiVal==0) ? 2 : (uiVal + 1) ;
    952     sei.m_coded_input_pivot_value[i]   = new Int[ sei.m_num_input_pivots[i] ];
    953     sei.m_target_input_pivot_value[i]  = new Int[ sei.m_num_input_pivots[i] ];
    954     if( uiVal > 0 )
    955     {
    956       for ( Int j=0 ; j<sei.m_num_input_pivots[i] ; j++ )
    957       {
    958         READ_CODE( (( sei.m_colour_map_coded_data_bit_depth + 7 ) >> 3 ) << 3, uiVal, "coded_input_pivot_value[i][j]" );  sei.m_coded_input_pivot_value[i][j] = uiVal;
    959         READ_CODE( (( sei.m_colour_map_coded_data_bit_depth + 7 ) >> 3 ) << 3, uiVal, "target_input_pivot_value[i][j]" ); sei.m_target_input_pivot_value[i][j] = uiVal;
    960       }
    961     }
    962     else
    963     {
    964       sei.m_coded_input_pivot_value[i][0]  = 0;
    965       sei.m_target_input_pivot_value[i][0] = 0;
    966       sei.m_coded_input_pivot_value[i][1]  = (1 << sei.m_colour_map_coded_data_bit_depth) - 1 ;
    967       sei.m_target_input_pivot_value[i][1] = (1 << sei.m_colour_map_target_bit_depth) - 1 ;
    968     }
    969   }
    970 
    971   READ_FLAG( uiVal,           "matrix_flag" ); sei.m_matrix_flag = uiVal;
    972   if( sei.m_matrix_flag )
    973   {
    974     READ_CODE( 4, uiVal,         "log2_matrix_denom" ); sei.m_log2_matrix_denom = uiVal;
    975     for ( Int i=0 ; i<3 ; i++ )
    976     {
    977       for ( Int j=0 ; j<3 ; j++ )
    978       {
    979         READ_SVLC( iVal,        "matrix_coef[i][j]" ); sei.m_matrix_coef[i][j] = iVal;
    980       }
    981     }
    982   }
    983 
    984   for ( Int i=0 ; i<3 ; i++ )
    985   {
    986     READ_CODE( 8, uiVal, "num_output_pivots_minus1[i]" ); sei.m_num_output_pivots[i] = (uiVal==0) ? 2 : (uiVal + 1) ;
    987     sei.m_coded_output_pivot_value[i]   = new Int[ sei.m_num_output_pivots[i] ];
    988     sei.m_target_output_pivot_value[i]  = new Int[ sei.m_num_output_pivots[i] ];
    989     if( uiVal > 0 )
    990     {
    991       for ( Int j=0 ; j<sei.m_num_output_pivots[i] ; j++ )
    992       {
    993         READ_CODE( (( sei.m_colour_map_coded_data_bit_depth + 7 ) >> 3 ) << 3, uiVal, "coded_output_pivot_value[i][j]" );  sei.m_coded_output_pivot_value[i][j] = uiVal;
    994         READ_CODE( (( sei.m_colour_map_coded_data_bit_depth + 7 ) >> 3 ) << 3, uiVal, "target_output_pivot_value[i][j]" ); sei.m_target_output_pivot_value[i][j] = uiVal;
    995       }
    996     }
    997     else
    998     {
    999       sei.m_coded_output_pivot_value[i][0]  = 0;
    1000       sei.m_target_output_pivot_value[i][0] = 0;
    1001       sei.m_coded_output_pivot_value[i][1]  = (1 << sei.m_colour_map_coded_data_bit_depth) - 1 ;
    1002       sei.m_target_output_pivot_value[i][1] = (1 << sei.m_colour_map_target_bit_depth) - 1 ;
     1107    for( Int c=0 ; c<3 ; c++ )
     1108    {
     1109      READ_CODE( 8, uiVal, "pre_lut_num_val_minus1[c]" ); sei.m_preLutNumValMinus1[c] = (uiVal==0) ? 1 : uiVal;
     1110      sei.m_preLutCodedValue[c].resize(sei.m_preLutNumValMinus1[c]+1);
     1111      sei.m_preLutTargetValue[c].resize(sei.m_preLutNumValMinus1[c]+1);
     1112      if( uiVal> 0 )
     1113        for ( Int i=0 ; i<=sei.m_preLutNumValMinus1[c] ; i++ )
     1114        {
     1115          READ_CODE( (( sei.m_colourRemapInputBitDepth   + 7 ) >> 3 ) << 3, uiVal, "pre_lut_coded_value[c][i]" );  sei.m_preLutCodedValue[c][i]  = uiVal;
     1116          READ_CODE( (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, uiVal, "pre_lut_target_value[c][i]" ); sei.m_preLutTargetValue[c][i] = uiVal;
     1117        }
     1118      else // pre_lut_num_val_minus1[c] == 0
     1119      {
     1120        sei.m_preLutCodedValue[c][0]  = 0;
     1121        sei.m_preLutTargetValue[c][0] = 0;
     1122        sei.m_preLutCodedValue[c][1]  = (1 << sei.m_colourRemapInputBitDepth) - 1 ;
     1123        sei.m_preLutTargetValue[c][1] = (1 << sei.m_colourRemapBitDepth) - 1 ;
     1124      }
     1125    }
     1126
     1127    READ_FLAG( uiVal,      "colour_remap_matrix_present_flag" ); sei.m_colourRemapMatrixPresentFlag = uiVal;
     1128    if( sei.m_colourRemapMatrixPresentFlag )
     1129    {
     1130      READ_CODE( 4, uiVal, "log2_matrix_denom" ); sei.m_log2MatrixDenom = uiVal;
     1131      for ( Int c=0 ; c<3 ; c++ )
     1132        for ( Int i=0 ; i<3 ; i++ )
     1133        {
     1134          READ_SVLC( iVal, "colour_remap_coeffs[c][i]" ); sei.m_colourRemapCoeffs[c][i] = iVal;
     1135        }
     1136    }
     1137    else // setting default matrix (I3)
     1138    {
     1139      sei.m_log2MatrixDenom = 0;
     1140      for ( Int c=0 ; c<3 ; c++ )
     1141        for ( Int i=0 ; i<3 ; i++ )
     1142          sei.m_colourRemapCoeffs[c][i] = (c==i) ? 1 : 0;
     1143    }
     1144    for( Int c=0 ; c<3 ; c++ )
     1145    {
     1146      READ_CODE( 8, uiVal, "post_lut_num_val_minus1[c]" ); sei.m_postLutNumValMinus1[c] = (uiVal==0) ? 1 : uiVal;
     1147      sei.m_postLutCodedValue[c].resize(sei.m_postLutNumValMinus1[c]+1);
     1148      sei.m_postLutTargetValue[c].resize(sei.m_postLutNumValMinus1[c]+1);
     1149      if( uiVal > 0 )
     1150        for ( Int i=0 ; i<=sei.m_postLutNumValMinus1[c] ; i++ )
     1151        {
     1152          READ_CODE( (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, uiVal, "post_lut_coded_value[c][i]" );  sei.m_postLutCodedValue[c][i] = uiVal;
     1153          READ_CODE( (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, uiVal, "post_lut_target_value[c][i]" ); sei.m_postLutTargetValue[c][i] = uiVal;
     1154        }
     1155      else
     1156      {
     1157        sei.m_postLutCodedValue[c][0]  = 0;
     1158        sei.m_postLutTargetValue[c][0] = 0;
     1159        sei.m_postLutTargetValue[c][1] = (1 << sei.m_colourRemapBitDepth) - 1;
     1160        sei.m_postLutCodedValue[c][1]  = (1 << sei.m_colourRemapBitDepth) - 1;
     1161      }
    10031162    }
    10041163  }
     
    11941353#endif
    11951354#if SUB_BITSTREAM_PROPERTY_SEI
     1355#if OLS_IDX_CHK
     1356Void SEIReader::xParseSEISubBitstreamProperty(SEISubBitstreamProperty &sei, TComVPS *vps)
     1357#else
    11961358Void SEIReader::xParseSEISubBitstreamProperty(SEISubBitstreamProperty &sei)
     1359#endif
    11971360{
    11981361  UInt uiCode;
     
    12031366  {
    12041367    READ_CODE(  2, uiCode, "sub_bitstream_mode[i]"           ); sei.m_subBitstreamMode[i] = uiCode;
    1205     READ_UVLC(     uiCode, "output_layer_set_idx_to_vps[i]"  ); sei.m_outputLayerSetIdxToVps[i] = uiCode;
     1368    READ_UVLC(     uiCode, "output_layer_set_idx_to_vps[i]"  );
     1369#if OLS_IDX_CHK
     1370      // The value of output_layer_set_idx_to_vps[ i ]  shall be in the range of 0 to NumOutputLayerSets − 1, inclusive.
     1371      assert(uiCode > 0 && uiCode <= vps->getNumOutputLayerSets()-1);
     1372#endif
     1373      sei.m_outputLayerSetIdxToVps[i] = uiCode;
    12061374    READ_CODE(  3, uiCode, "highest_sub_layer_id[i]"         ); sei.m_highestSublayerId[i] = uiCode;
    12071375    READ_CODE( 16, uiCode, "avg_bit_rate[i]"                 ); sei.m_avgBitRate[i] = uiCode;
     
    12321400
    12331401  // read nested SEI messages
     1402#if NESTING_SEI_EXTENSIBILITY
     1403  Int numSeiMessages = 0;
     1404  READ_UVLC( uiCode, "num_seis_in_bsp_minus1" );  assert( uiCode <= MAX_SEIS_IN_BSP_NESTING );
     1405  numSeiMessages = uiCode;
     1406  for(Int i = 0; i < numSeiMessages; i++)
     1407  {
     1408    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps, &nestingSei, &sei);
     1409  }
     1410#else
    12341411  do {
    12351412#if LAYERS_NOT_PRESENT_SEI
     
    12391416#endif
    12401417  } while (m_pcBitstream->getNumBitsLeft() > 8);
     1418#endif
    12411419}
    12421420
     
    12451423  assert(vps->getVpsVuiPresentFlag());
    12461424
     1425#if VPS_VUI_BSP_HRD_PARAMS
     1426  UInt uiCode;
     1427  Int psIdx         = bspNestingSei.m_seiPartitioningSchemeIdx;
     1428  Int seiOlsIdx     = bspNestingSei.m_seiOlsIdx;
     1429  Int maxTemporalId = nestingSei.m_nestingMaxTemporalIdPlus1[0];
     1430  Int maxValues     = vps->getNumBspSchedulesMinus1(seiOlsIdx, psIdx, maxTemporalId) + 1;
     1431  std::vector<Int> hrdIdx(0, maxValues);
     1432  std::vector<TComHRD *> hrdVec;
     1433  std::vector<Int> syntaxElemLen;
     1434  for(Int i = 0; i < maxValues; i++)
     1435  {
     1436    hrdIdx[i] = vps->getBspHrdIdx( seiOlsIdx, psIdx, maxTemporalId, i, bspNestingSei.m_bspIdx);
     1437    hrdVec[i] = vps->getBspHrd(hrdIdx[i]);
     1438   
     1439    syntaxElemLen[i] = hrdVec[i]->getInitialCpbRemovalDelayLengthMinus1() + 1;
     1440    if ( !(hrdVec[i]->getNalHrdParametersPresentFlag() || hrdVec[i]->getVclHrdParametersPresentFlag()) )
     1441    {
     1442      assert( syntaxElemLen[i] == 24 ); // Default value of init_cpb_removal_delay_length_minus1 is 23
     1443    }
     1444    if( i > 0 )
     1445    {
     1446      assert( hrdVec[i]->getNalHrdParametersPresentFlag() == hrdVec[i-1]->getNalHrdParametersPresentFlag() );
     1447      assert( hrdVec[i]->getVclHrdParametersPresentFlag() == hrdVec[i-1]->getVclHrdParametersPresentFlag() );
     1448    }
     1449  }
     1450  if (hrdVec[0]->getNalHrdParametersPresentFlag())
     1451  {
     1452    for(UInt i = 0; i < maxValues; i++)
     1453    {
     1454      READ_CODE( syntaxElemLen[i], uiCode, "nal_initial_arrival_delay[i]" ); sei.m_nalInitialArrivalDelay[i] = uiCode;
     1455    }
     1456  }
     1457  if( hrdVec[0]->getVclHrdParametersPresentFlag() )
     1458  {
     1459    for(UInt i = 0; i < maxValues; i++)
     1460    {
     1461      READ_CODE( syntaxElemLen[i], uiCode, "vcl_initial_arrival_delay[i]" ); sei.m_vclInitialArrivalDelay[i] = uiCode;
     1462    }
     1463  }
     1464#else
    12471465  UInt schedCombCnt = vps->getNumBspSchedCombinations(nestingSei.m_nestingOpIdx[0]);
    12481466  UInt len;
     
    12771495    }
    12781496  }
     1497#if BSP_INIT_ARRIVAL_SEI
     1498  if( hrd->getVclHrdParametersPresentFlag() )
     1499#else
    12791500  else
     1501#endif
    12801502  {
    12811503    for(UInt i = 0; i < schedCombCnt; i++)
     
    12841506    }
    12851507  }
    1286 }
    1287 
     1508#endif
     1509}
     1510
     1511#if !REMOVE_BSP_HRD_SEI
    12881512Void SEIReader::xParseSEIBspHrd(SEIBspHrd &sei, TComSPS *sps, const SEIScalableNesting &nestingSei)
    12891513{
     
    13711595  }
    13721596}
     1597#endif
    13731598
    13741599Void SEIReader::xParseHrdParameters(TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1)
  • trunk/source/Lib/TLibDecoder/SEIread.h

    r815 r906  
    8080  Void xParseSEIuserDataUnregistered  (SEIuserDataUnregistered &sei, UInt payloadSize);
    8181  Void xParseSEIActiveParameterSets   (SEIActiveParameterSets  &sei, UInt payloadSize);
     82  Void xParseSEIDecodedPictureHash    (SEIDecodedPictureHash& sei, UInt payloadSize);
     83#if VPS_VUI_BSP_HRD_PARAMS
     84  Void xParseSEIDecodingUnitInfo      (SEIDecodingUnitInfo& sei, UInt payloadSize, TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei, TComVPS *vps);
     85  Void xParseSEIBufferingPeriod       (SEIBufferingPeriod& sei, UInt payloadSize, TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei, TComVPS *vps);
     86  Void xParseSEIPictureTiming         (SEIPictureTiming& sei, UInt payloadSize, TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei, TComVPS *vps);
     87#else
    8288  Void xParseSEIDecodingUnitInfo      (SEIDecodingUnitInfo& sei, UInt payloadSize, TComSPS *sps);
    83   Void xParseSEIDecodedPictureHash    (SEIDecodedPictureHash& sei, UInt payloadSize);
    8489  Void xParseSEIBufferingPeriod       (SEIBufferingPeriod& sei, UInt payloadSize, TComSPS *sps);
    8590  Void xParseSEIPictureTiming         (SEIPictureTiming& sei, UInt payloadSize, TComSPS *sps);
     91#endif
    8692  Void xParseSEIRecoveryPoint         (SEIRecoveryPoint& sei, UInt payloadSize);
    8793  Void xParseSEIFramePacking          (SEIFramePacking& sei, UInt payloadSize);
     
    9399  Void xParseSEIKneeFunctionInfo      (SEIKneeFunctionInfo& sei, UInt payloadSize);
    94100#endif
    95 #if Q0074_SEI_COLOR_MAPPING
    96   Void xParseSEIColorMappingInfo      (SEIColorMappingInfo& sei, UInt payloadSize);
     101#if Q0074_COLOUR_REMAPPING_SEI
     102  Void xParseSEIColourRemappingInfo   (SEIColourRemappingInfo& sei, UInt payloadSize);
    97103#endif
    98104  Void xParseSEISOPDescription        (SEISOPDescription &sei, UInt payloadSize);
     
    101107#endif
    102108#if SUB_BITSTREAM_PROPERTY_SEI
     109#if OLS_IDX_CHK
     110Void   xParseSEISubBitstreamProperty   (SEISubBitstreamProperty &sei, TComVPS *vps);
     111#else
    103112Void   xParseSEISubBitstreamProperty   (SEISubBitstreamProperty &sei);
     113#endif
    104114#endif
    105115#if LAYERS_NOT_PRESENT_SEI
     
    116126#endif
    117127  Void xParseSEIBspInitialArrivalTime(SEIBspInitialArrivalTime &sei, TComVPS *vps, TComSPS *sps, const SEIScalableNesting &nestingSei, const SEIBspNesting &bspNestingSei);
     128#if !REMOVE_BSP_HRD_SEI
    118129  Void xParseSEIBspHrd(SEIBspHrd &sei, TComSPS *sps, const SEIScalableNesting &nestingSei);
     130#endif
    119131  Void xParseHrdParameters(TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1);
    120132#endif
  • trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp

    r815 r906  
    255255  if( pcPPS->getTilesEnabledFlag() )
    256256  {
    257     READ_UVLC ( uiCode, "num_tile_columns_minus1" );                pcPPS->setNumColumnsMinus1( uiCode );
    258     READ_UVLC ( uiCode, "num_tile_rows_minus1" );                   pcPPS->setNumRowsMinus1( uiCode );
    259     READ_FLAG ( uiCode, "uniform_spacing_flag" );                   pcPPS->setUniformSpacingFlag( uiCode );
    260 
    261     if( !pcPPS->getUniformSpacingFlag())
    262     {
    263       UInt* columnWidth = (UInt*)malloc(pcPPS->getNumColumnsMinus1()*sizeof(UInt));
    264       for(UInt i=0; i<pcPPS->getNumColumnsMinus1(); i++)
     257    READ_UVLC ( uiCode, "num_tile_columns_minus1" );                pcPPS->setNumTileColumnsMinus1( uiCode ); 
     258    READ_UVLC ( uiCode, "num_tile_rows_minus1" );                   pcPPS->setNumTileRowsMinus1( uiCode ); 
     259    READ_FLAG ( uiCode, "uniform_spacing_flag" );                   pcPPS->setTileUniformSpacingFlag( uiCode == 1 );
     260
     261    if( !pcPPS->getTileUniformSpacingFlag())
     262    {
     263      std::vector<Int> columnWidth(pcPPS->getNumTileColumnsMinus1());
     264      for(UInt i=0; i<pcPPS->getNumTileColumnsMinus1(); i++)
    265265      {
    266266        READ_UVLC( uiCode, "column_width_minus1" );
    267267        columnWidth[i] = uiCode+1;
    268268      }
    269       pcPPS->setColumnWidth(columnWidth);
    270       free(columnWidth);
    271 
    272       UInt* rowHeight = (UInt*)malloc(pcPPS->getNumRowsMinus1()*sizeof(UInt));
    273       for(UInt i=0; i<pcPPS->getNumRowsMinus1(); i++)
     269      pcPPS->setTileColumnWidth(columnWidth);
     270
     271      std::vector<Int> rowHeight (pcPPS->getTileNumRowsMinus1());
     272      for(UInt i=0; i<pcPPS->getTileNumRowsMinus1(); i++)
    274273      {
    275274        READ_UVLC( uiCode, "row_height_minus1" );
    276275        rowHeight[i] = uiCode + 1;
    277276      }
    278       pcPPS->setRowHeight(rowHeight);
    279       free(rowHeight);
    280     }
    281 
    282     if(pcPPS->getNumColumnsMinus1() !=0 || pcPPS->getNumRowsMinus1() !=0)
     277      pcPPS->setTileRowHeight(rowHeight);
     278    }
     279
     280    if(pcPPS->getNumTileColumnsMinus1() !=0 || pcPPS->getTileNumRowsMinus1() !=0)
    283281    {
    284282      READ_FLAG ( uiCode, "loop_filter_across_tiles_enabled_flag" );   pcPPS->setLoopFilterAcrossTilesEnabledFlag( uiCode ? true : false );
     
    297295    }
    298296  }
    299 
     297#if !R0042_PROFILE_INDICATION
    300298#if SCALINGLIST_INFERRING
    301299  if( pcPPS->getLayerId() > 0 )
     
    317315  {
    318316#endif
    319 
    320   READ_FLAG( uiCode, "pps_scaling_list_data_present_flag" );           pcPPS->setScalingListPresentFlag( uiCode ? true : false );
    321 
    322   if(pcPPS->getScalingListPresentFlag ())
    323   {
    324     parseScalingList( pcPPS->getScalingList() );
    325   }
    326 
     317#endif
     318
     319    READ_FLAG( uiCode, "pps_scaling_list_data_present_flag" );           pcPPS->setScalingListPresentFlag( uiCode ? true : false );
     320
     321    if(pcPPS->getScalingListPresentFlag ())
     322    {
     323      parseScalingList( pcPPS->getScalingList() );
     324    }
     325#if !R0042_PROFILE_INDICATION
    327326#if SCALINGLIST_INFERRING
    328327  }
     328#endif
    329329#endif
    330330
     
    338338  pcPPS->setSliceHeaderExtensionPresentFlag(uiCode);
    339339
     340#if !R0042_PROFILE_INDICATION
    340341  READ_FLAG( uiCode, "pps_extension_flag");
     342#else
     343  READ_FLAG( uiCode, "pps_extension_present_flag");
     344#endif
     345
     346#if !R0042_PROFILE_INDICATION
    341347#if POC_RESET_INFO_INFERENCE
    342348  pcPPS->setExtensionFlag( uiCode ? true : false );
     
    361367      READ_FLAG( uiCode, "poc_reset_info_present_flag" );
    362368      pcPPS->setPocResetInfoPresentFlag(uiCode ? true : false);
     369#if REF_REGION_OFFSET
     370      READ_UVLC( uiCode,      "num_scaled_ref_layer_offsets" ); pcPPS->setNumScaledRefLayerOffsets(uiCode);
     371      for(Int i = 0; i < pcPPS->getNumScaledRefLayerOffsets(); i++)
     372      {
     373        READ_CODE( 6, uiCode,  "scaled_ref_layer_id" );  pcPPS->setScaledRefLayerId( i, uiCode );
     374        READ_FLAG( uiCode, "scaled_ref_layer_offset_present_flag" );   pcPPS->setScaledRefLayerOffsetPresentFlag( i, uiCode );
     375        if (uiCode)
     376        {
     377          Window& scaledWindow = pcPPS->getScaledRefLayerWindow(i);
     378          READ_SVLC( iCode, "scaled_ref_layer_left_offset" );    scaledWindow.setWindowLeftOffset  (iCode << 1);
     379          READ_SVLC( iCode, "scaled_ref_layer_top_offset" );     scaledWindow.setWindowTopOffset   (iCode << 1);
     380          READ_SVLC( iCode, "scaled_ref_layer_right_offset" );   scaledWindow.setWindowRightOffset (iCode << 1);
     381          READ_SVLC( iCode, "scaled_ref_layer_bottom_offset" );  scaledWindow.setWindowBottomOffset(iCode << 1);
     382#if P0312_VERT_PHASE_ADJ
     383          READ_FLAG( uiCode, "vert_phase_position_enable_flag" ); scaledWindow.setVertPhasePositionEnableFlag(uiCode);  pcPPS->setVertPhasePositionEnableFlag( pcPPS->getScaledRefLayerId(i), uiCode);
     384#endif
     385        }
     386        READ_FLAG( uiCode, "ref_region_offset_present_flag" );   pcPPS->setRefRegionOffsetPresentFlag( i, uiCode );
     387        if (uiCode)
     388        {
     389          Window& refWindow = pcPPS->getRefLayerWindow(i);
     390          READ_SVLC( iCode, "ref_region_left_offset" );    refWindow.setWindowLeftOffset  (iCode << 1);
     391          READ_SVLC( iCode, "ref_region_top_offset" );     refWindow.setWindowTopOffset   (iCode << 1);
     392          READ_SVLC( iCode, "ref_region_right_offset" );   refWindow.setWindowRightOffset (iCode << 1);
     393          READ_SVLC( iCode, "ref_region_bottom_offset" );  refWindow.setWindowBottomOffset(iCode << 1);
     394        }
     395#if R0209_GENERIC_PHASE
     396        READ_FLAG( uiCode, "resample_phase_set_present_flag" );   pcPPS->setResamplePhaseSetPresentFlag( i, uiCode );
     397        if (uiCode)
     398        {
     399          READ_UVLC( uiCode, "phase_hor_luma" );    pcPPS->setPhaseHorLuma ( i, uiCode );
     400          READ_UVLC( uiCode, "phase_ver_luma" );    pcPPS->setPhaseVerLuma ( i, uiCode );
     401          READ_UVLC( uiCode, "phase_hor_chroma_plus8" );  pcPPS->setPhaseHorChroma (i, uiCode - 8);
     402          READ_UVLC( uiCode, "phase_ver_chroma_plus8" );  pcPPS->setPhaseVerChroma (i, uiCode - 8);
     403        }
     404#endif
     405      }
     406#else
     407#if MOVE_SCALED_OFFSET_TO_PPS
     408      READ_UVLC( uiCode,      "num_scaled_ref_layer_offsets" ); pcPPS->setNumScaledRefLayerOffsets(uiCode);
     409      for(Int i = 0; i < pcPPS->getNumScaledRefLayerOffsets(); i++)
     410      {
     411        Window& scaledWindow = pcPPS->getScaledRefLayerWindow(i);
     412#if O0098_SCALED_REF_LAYER_ID
     413        READ_CODE( 6,  uiCode,  "scaled_ref_layer_id" );       pcPPS->setScaledRefLayerId( i, uiCode );
     414#endif
     415        READ_SVLC( iCode, "scaled_ref_layer_left_offset" );    scaledWindow.setWindowLeftOffset  (iCode << 1);
     416        READ_SVLC( iCode, "scaled_ref_layer_top_offset" );     scaledWindow.setWindowTopOffset   (iCode << 1);
     417        READ_SVLC( iCode, "scaled_ref_layer_right_offset" );   scaledWindow.setWindowRightOffset (iCode << 1);
     418        READ_SVLC( iCode, "scaled_ref_layer_bottom_offset" );  scaledWindow.setWindowBottomOffset(iCode << 1);
     419#if P0312_VERT_PHASE_ADJ
     420        READ_FLAG( uiCode, "vert_phase_position_enable_flag" ); scaledWindow.setVertPhasePositionEnableFlag(uiCode);  pcPPS->setVertPhasePositionEnableFlag( pcPPS->getScaledRefLayerId(i), uiCode);
     421#endif
     422      }
     423#endif
     424#endif
    363425#if Q0048_CGS_3D_ASYMLUT
    364426      READ_FLAG( uiCode , "colour_mapping_enabled_flag" );
     
    383445#endif
    384446
    385     while ( xMoreRbspData() )
    386     {
    387       READ_FLAG( uiCode, "pps_extension_data_flag");
    388     }
     447      while ( xMoreRbspData() )
     448      {
     449        READ_FLAG( uiCode, "pps_extension_data_flag");
     450      }
    389451#if P0166_MODIFIED_PPS_EXTENSION
    390452    }
     
    397459  }
    398460#endif
     461#else
     462  pcPPS->setExtensionFlag( uiCode ? true : false );
     463  if( pcPPS->getExtensionFlag() )
     464  {
     465    READ_FLAG( uiCode, "pps_range_extension_flag" );
     466    assert(uiCode == 0);
     467    READ_FLAG( uiCode, "pps_multilayer_extension_flag" );
     468    assert(uiCode == 1);
     469    READ_CODE(6, uiCode, "pps_extension_6bits");
     470    assert(uiCode == 0);
     471
     472    READ_FLAG( uiCode, "poc_reset_info_present_flag" );
     473    pcPPS->setPocResetInfoPresentFlag(uiCode ? true : false);
     474
     475#if SCALINGLIST_INFERRING
     476    READ_FLAG( uiCode, "pps_infer_scaling_list_flag" );
     477    pcPPS->setInferScalingListFlag( uiCode );
     478
     479    if( pcPPS->getInferScalingListFlag() )
     480    {
     481      READ_UVLC( uiCode, "pps_scaling_list_ref_layer_id" );
     482      pcPPS->setScalingListRefLayerId( uiCode );
     483      // The value of pps_scaling_list_ref_layer_id shall be in the range of 0 to 62, inclusive
     484      assert( pcPPS->getScalingListRefLayerId() <= 62 );
     485      pcPPS->setScalingListPresentFlag( false );
     486    }
     487#endif
     488
     489#if REF_REGION_OFFSET
     490    READ_UVLC( uiCode,      "num_ref_loc_offsets" ); pcPPS->setNumScaledRefLayerOffsets(uiCode);
     491    for(Int i = 0; i < pcPPS->getNumScaledRefLayerOffsets(); i++)
     492    {
     493      READ_CODE( 6, uiCode,  "ref_loc_offset_layer_id" );  pcPPS->setScaledRefLayerId( i, uiCode );
     494      READ_FLAG( uiCode, "scaled_ref_layer_offset_present_flag" );   pcPPS->setScaledRefLayerOffsetPresentFlag( i, uiCode );
     495      if (uiCode)
     496      {
     497        Window& scaledWindow = pcPPS->getScaledRefLayerWindow(i);
     498        READ_SVLC( iCode, "scaled_ref_layer_left_offset" );    scaledWindow.setWindowLeftOffset  (iCode << 1);
     499        READ_SVLC( iCode, "scaled_ref_layer_top_offset" );     scaledWindow.setWindowTopOffset   (iCode << 1);
     500        READ_SVLC( iCode, "scaled_ref_layer_right_offset" );   scaledWindow.setWindowRightOffset (iCode << 1);
     501        READ_SVLC( iCode, "scaled_ref_layer_bottom_offset" );  scaledWindow.setWindowBottomOffset(iCode << 1);
     502#if P0312_VERT_PHASE_ADJ
     503        READ_FLAG( uiCode, "vert_phase_position_enable_flag" ); scaledWindow.setVertPhasePositionEnableFlag(uiCode);  pcPPS->setVertPhasePositionEnableFlag( pcPPS->getScaledRefLayerId(i), uiCode);
     504#endif
     505      }
     506      READ_FLAG( uiCode, "ref_region_offset_present_flag" );   pcPPS->setRefRegionOffsetPresentFlag( i, uiCode );
     507      if (uiCode)
     508      {
     509        Window& refWindow = pcPPS->getRefLayerWindow(i);
     510        READ_SVLC( iCode, "ref_region_left_offset" );    refWindow.setWindowLeftOffset  (iCode << 1);
     511        READ_SVLC( iCode, "ref_region_top_offset" );     refWindow.setWindowTopOffset   (iCode << 1);
     512        READ_SVLC( iCode, "ref_region_right_offset" );   refWindow.setWindowRightOffset (iCode << 1);
     513        READ_SVLC( iCode, "ref_region_bottom_offset" );  refWindow.setWindowBottomOffset(iCode << 1);
     514      }
     515#if R0209_GENERIC_PHASE
     516      READ_FLAG( uiCode, "resample_phase_set_present_flag" );   pcPPS->setResamplePhaseSetPresentFlag( i, uiCode );
     517      if (uiCode)
     518      {
     519        READ_UVLC( uiCode, "phase_hor_luma" );    pcPPS->setPhaseHorLuma ( i, uiCode );
     520        READ_UVLC( uiCode, "phase_ver_luma" );    pcPPS->setPhaseVerLuma ( i, uiCode );
     521        READ_UVLC( uiCode, "phase_hor_chroma_plus8" );  pcPPS->setPhaseHorChroma (i, uiCode - 8);
     522        READ_UVLC( uiCode, "phase_ver_chroma_plus8" );  pcPPS->setPhaseVerChroma (i, uiCode - 8);
     523      }
     524#endif
     525    }
     526#else
     527#if MOVE_SCALED_OFFSET_TO_PPS
     528      READ_UVLC( uiCode,      "num_scaled_ref_layer_offsets" ); pcPPS->setNumScaledRefLayerOffsets(uiCode);
     529      for(Int i = 0; i < pcPPS->getNumScaledRefLayerOffsets(); i++)
     530      {
     531        Window& scaledWindow = pcPPS->getScaledRefLayerWindow(i);
     532#if O0098_SCALED_REF_LAYER_ID
     533        READ_CODE( 6,  uiCode,  "scaled_ref_layer_id" );       pcPPS->setScaledRefLayerId( i, uiCode );
     534#endif
     535        READ_SVLC( iCode, "scaled_ref_layer_left_offset" );    scaledWindow.setWindowLeftOffset  (iCode << 1);
     536        READ_SVLC( iCode, "scaled_ref_layer_top_offset" );     scaledWindow.setWindowTopOffset   (iCode << 1);
     537        READ_SVLC( iCode, "scaled_ref_layer_right_offset" );   scaledWindow.setWindowRightOffset (iCode << 1);
     538        READ_SVLC( iCode, "scaled_ref_layer_bottom_offset" );  scaledWindow.setWindowBottomOffset(iCode << 1);
     539#if P0312_VERT_PHASE_ADJ
     540        READ_FLAG( uiCode, "vert_phase_position_enable_flag" ); scaledWindow.setVertPhasePositionEnableFlag(uiCode);  pcPPS->setVertPhasePositionEnableFlag( pcPPS->getScaledRefLayerId(i), uiCode);
     541#endif
     542      }
     543#endif
     544#endif
     545#if Q0048_CGS_3D_ASYMLUT
     546      READ_FLAG( uiCode , "colour_mapping_enabled_flag" );
     547      pcPPS->setCGSFlag( uiCode );
     548      if( pcPPS->getCGSFlag() )
     549      {
     550        xParse3DAsymLUT( pc3DAsymLUT );
     551        pcPPS->setCGSOutputBitDepthY( pc3DAsymLUT->getOutputBitDepthY() );
     552        pcPPS->setCGSOutputBitDepthC( pc3DAsymLUT->getOutputBitDepthC() );
     553      }
     554#endif
     555  }
     556#endif
     557
    399558}
    400559
     
    476635      READ_UVLC(   uiCode, "vui_num_ticks_poc_diff_one_minus1");    timingInfo->setNumTicksPocDiffOneMinus1   (uiCode);
    477636    }
    478   READ_FLAG(     uiCode, "hrd_parameters_present_flag");              pcVUI->setHrdParametersPresentFlag(uiCode);
    479   if( pcVUI->getHrdParametersPresentFlag() )
    480   {
    481     parseHrdParameters( pcVUI->getHrdParameters(), 1, pcSPS->getMaxTLayers() - 1 );
    482   }
     637    READ_FLAG(     uiCode, "hrd_parameters_present_flag");              pcVUI->setHrdParametersPresentFlag(uiCode);
     638    if( pcVUI->getHrdParametersPresentFlag() )
     639    {
     640      parseHrdParameters( pcVUI->getHrdParameters(), 1, pcSPS->getMaxTLayers() - 1 );
     641    }
    483642  }
    484643  READ_FLAG(     uiCode, "bitstream_restriction_flag");               pcVUI->setBitstreamRestrictionFlag(uiCode);
     
    524683      READ_CODE( 5, uiCode, "dpb_output_delay_length_minus1" );       hrd->setDpbOutputDelayLengthMinus1( uiCode );
    525684    }
     685#if VPS_VUI_BSP_HRD_PARAMS
     686    else
     687    {
     688      hrd->setInitialCpbRemovalDelayLengthMinus1( 23 );
     689      // Add inferred values for other syntax elements here.
     690    }
     691#endif
    526692  }
    527693  Int i, j, nalOrVcl;
     
    554720    {
    555721      if( ( ( nalOrVcl == 0 ) && ( hrd->getNalHrdParametersPresentFlag() ) ) ||
    556           ( ( nalOrVcl == 1 ) && ( hrd->getVclHrdParametersPresentFlag() ) ) )
     722        ( ( nalOrVcl == 1 ) && ( hrd->getVclHrdParametersPresentFlag() ) ) )
    557723      {
    558724        for( j = 0; j <= ( hrd->getCpbCntMinus1( i ) ); j ++ )
     
    582748#endif
    583749
     750#if R0042_PROFILE_INDICATION
     751  UInt uiTmp = 0;
     752  Bool bMultiLayerExtSpsFlag;
     753#endif
    584754  UInt  uiCode;
    585755  READ_CODE( 4,  uiCode, "sps_video_parameter_set_id");          pcSPS->setVPSId        ( uiCode );
     
    590760    READ_CODE( 3,  uiCode, "sps_max_sub_layers_minus1" );          pcSPS->setMaxTLayers   ( uiCode+1 );
    591761    assert(uiCode <= 6);
    592 
     762#if SVC_EXTENSION
     763  }
     764#if R0042_PROFILE_INDICATION
     765  else
     766  {
     767    READ_CODE( 3,  uiCode, "sps_ext_or_max_sub_layers_minus1" );     uiTmp = uiCode;
     768  }
     769#endif
     770#if !SPS_DPB_PARAMS
     771  if(pcSPS->getLayerId() != 0)
     772  {
     773    pcSPS->setMaxTLayers           ( parameterSetManager->getPrefetchedVPS(pcSPS->getVPSId())->getMaxTLayers()          );
     774  }
     775#endif
     776#endif
     777
     778#if SVC_EXTENSION
     779#if R0042_PROFILE_INDICATION
     780  bMultiLayerExtSpsFlag = ( pcSPS->getLayerId() != 0 && uiTmp == 7 );
     781#endif
     782#endif
     783
     784#if SVC_EXTENSION
     785#if !R0042_PROFILE_INDICATION
     786  if(pcSPS->getLayerId() == 0)
     787#else
     788  if(!bMultiLayerExtSpsFlag)
     789#endif
     790  {
     791#endif
    593792    READ_FLAG( uiCode, "sps_temporal_id_nesting_flag" );               pcSPS->setTemporalIdNestingFlag ( uiCode > 0 ? true : false );
    594793#if SVC_EXTENSION
     
    597796  else
    598797  {
    599     pcSPS->setMaxTLayers           ( parameterSetManager->getPrefetchedVPS(pcSPS->getVPSId())->getMaxTLayers()          );
    600798    pcSPS->setTemporalIdNestingFlag( parameterSetManager->getPrefetchedVPS(pcSPS->getVPSId())->getTemporalNestingFlag() );
    601799  }
     
    618816
    619817#ifdef SPS_PTL_FIX
     818#if !R0042_PROFILE_INDICATION
    620819  if ( pcSPS->getLayerId() == 0)
     820#else
     821  if(!bMultiLayerExtSpsFlag)
     822#endif
    621823  {
    622824    parsePTL(pcSPS->getPTL(), 1, pcSPS->getMaxTLayers() - 1);
     
    630832
    631833#if REPN_FORMAT_IN_VPS
     834#if !R0042_PROFILE_INDICATION
    632835  if( pcSPS->getLayerId() > 0 )
     836#else
     837  if( bMultiLayerExtSpsFlag)
     838#endif
    633839  {
    634840    READ_FLAG( uiCode, "update_rep_format_flag" );
    635841    pcSPS->setUpdateRepFormatFlag( uiCode ? true : false );
     842#if R0042_PROFILE_INDICATION   
     843    if( bMultiLayerExtSpsFlag && uiCode)
     844    {
     845      READ_CODE(8, uiCode, "sps_rep_format_idx");
     846      pcSPS->setUpdateRepFormatIndex(uiCode);
     847    }
     848#endif
    636849  }
    637850  else
     
    643856#endif
    644857  }
     858
     859#if R0042_PROFILE_INDICATION 
     860  if( !bMultiLayerExtSpsFlag )
     861  {
     862#else
    645863#if O0096_REP_FORMAT_INDEX
    646864  if( pcSPS->getLayerId() == 0 )
    647865#else
    648866  if( pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() )
     867#endif
    649868#endif
    650869  {
     
    668887  }
    669888#if O0096_REP_FORMAT_INDEX
     889#if !R0042_PROFILE_INDICATION
    670890  else if ( pcSPS->getUpdateRepFormatFlag() )
    671891  {
     
    675895#endif
    676896#endif
    677   READ_FLAG(     uiCode, "conformance_window_flag");
    678   if (uiCode != 0)
    679   {
    680     Window &conf = pcSPS->getConformanceWindow();
     897#endif
     898
     899#if R0156_CONF_WINDOW_IN_REP_FORMAT
    681900#if REPN_FORMAT_IN_VPS
    682     READ_UVLC(   uiCode, "conf_win_left_offset" );               conf.setWindowLeftOffset  ( uiCode );
    683     READ_UVLC(   uiCode, "conf_win_right_offset" );              conf.setWindowRightOffset ( uiCode );
    684     READ_UVLC(   uiCode, "conf_win_top_offset" );                conf.setWindowTopOffset   ( uiCode );
    685     READ_UVLC(   uiCode, "conf_win_bottom_offset" );             conf.setWindowBottomOffset( uiCode );
    686 #else
    687     READ_UVLC(   uiCode, "conf_win_left_offset" );               conf.setWindowLeftOffset  ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
    688     READ_UVLC(   uiCode, "conf_win_right_offset" );              conf.setWindowRightOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
    689     READ_UVLC(   uiCode, "conf_win_top_offset" );                conf.setWindowTopOffset   ( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
    690     READ_UVLC(   uiCode, "conf_win_bottom_offset" );             conf.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
    691 #endif
    692   }
    693 #if REPN_FORMAT_IN_VPS
     901#if !R0042_PROFILE_INDICATION 
    694902#if O0096_REP_FORMAT_INDEX
    695903  if( pcSPS->getLayerId() == 0 )
    696904#else
    697905  if(  pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() )
     906#endif
     907#endif
     908  {
     909#endif
     910#endif
     911    READ_FLAG(     uiCode, "conformance_window_flag");
     912    if (uiCode != 0)
     913    {
     914      Window &conf = pcSPS->getConformanceWindow();
     915#if REPN_FORMAT_IN_VPS
     916      READ_UVLC(   uiCode, "conf_win_left_offset" );               conf.setWindowLeftOffset  ( uiCode );
     917      READ_UVLC(   uiCode, "conf_win_right_offset" );              conf.setWindowRightOffset ( uiCode );
     918      READ_UVLC(   uiCode, "conf_win_top_offset" );                conf.setWindowTopOffset   ( uiCode );
     919      READ_UVLC(   uiCode, "conf_win_bottom_offset" );             conf.setWindowBottomOffset( uiCode );
     920#else
     921      READ_UVLC(   uiCode, "conf_win_left_offset" );               conf.setWindowLeftOffset  ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
     922      READ_UVLC(   uiCode, "conf_win_right_offset" );              conf.setWindowRightOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
     923      READ_UVLC(   uiCode, "conf_win_top_offset" );                conf.setWindowTopOffset   ( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
     924      READ_UVLC(   uiCode, "conf_win_bottom_offset" );             conf.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
     925#endif
     926    }
     927#if R0156_CONF_WINDOW_IN_REP_FORMAT
     928#if REPN_FORMAT_IN_VPS
     929  }
     930#endif
     931#endif
     932
     933#if REPN_FORMAT_IN_VPS
     934#if !R0042_PROFILE_INDICATION 
     935#if O0096_REP_FORMAT_INDEX
     936  if( pcSPS->getLayerId() == 0 )
     937#else
     938  if(  pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() )
     939#endif
    698940#endif
    699941  {
     
    711953  }
    712954#endif
     955#if R0042_PROFILE_INDICATION 
     956  }
     957#endif
     958
    713959  READ_UVLC( uiCode,    "log2_max_pic_order_cnt_lsb_minus4" );   pcSPS->setBitsForPOC( 4 + uiCode );
    714960  assert(uiCode <= 12);
    715961
    716962#if SPS_DPB_PARAMS
     963#if !R0042_PROFILE_INDICATION
    717964  if( pcSPS->getLayerId() == 0 ) 
    718965  {
     966#else
     967  if( !bMultiLayerExtSpsFlag ) 
     968  {
     969#endif
    719970#endif
    720971    UInt subLayerOrderingInfoPresentFlag;
     
    7491000  READ_UVLC( uiCode, "log2_diff_max_min_coding_block_size" );
    7501001  pcSPS->setLog2DiffMaxMinCodingBlockSize(uiCode);
    751  
     1002
    7521003  if (pcSPS->getPTL()->getGeneralPTL()->getLevelIdc() >= Level::LEVEL5)
    7531004  {
    7541005    assert(log2MinCUSize + pcSPS->getLog2DiffMaxMinCodingBlockSize() >= 5);
    7551006  }
    756  
     1007
    7571008  Int maxCUDepthDelta = uiCode;
    7581009  pcSPS->setMaxCUWidth  ( 1<<(log2MinCUSize + maxCUDepthDelta) );
     
    7731024  {
    7741025#if SCALINGLIST_INFERRING
     1026#if !R0042_PROFILE_INDICATION
    7751027    if( pcSPS->getLayerId() > 0 )
     1028#else
     1029    if( bMultiLayerExtSpsFlag )
     1030#endif
    7761031    {
    7771032      READ_FLAG( uiCode, "sps_infer_scaling_list_flag" ); pcSPS->setInferScalingListFlag( uiCode );
     
    7901045    {
    7911046#endif
    792     READ_FLAG( uiCode, "sps_scaling_list_data_present_flag" );                 pcSPS->setScalingListPresentFlag ( uiCode );
    793     if(pcSPS->getScalingListPresentFlag ())
    794     {
    795       parseScalingList( pcSPS->getScalingList() );
    796     }
     1047      READ_FLAG( uiCode, "sps_scaling_list_data_present_flag" );                 pcSPS->setScalingListPresentFlag ( uiCode );
     1048      if(pcSPS->getScalingListPresentFlag ())
     1049      {
     1050        parseScalingList( pcSPS->getScalingList() );
     1051      }
    7971052#if SCALINGLIST_INFERRING
    7981053    }
     
    8541109  if( pcSPS->getExtensionFlag() )
    8551110  {
     1111#if !R0042_PROFILE_INDICATION
    8561112#if O0142_CONDITIONAL_SPS_EXTENSION
    8571113    UInt spsExtensionTypeFlag[8];
     
    8771133      }
    8781134    }
    879   }
     1135    }
     1136#else
     1137    READ_FLAG( uiCode, "sps_range_extension_flag" );
     1138    assert(uiCode == 0);
     1139    READ_FLAG( uiCode, "sps_multilayer_extension_flag" );
     1140    assert(uiCode == 1);
     1141    READ_CODE(6, uiCode, "sps_extension_6bits");
     1142    assert(uiCode == 0);
     1143    parseSPSExtension( pcSPS );
     1144  }
     1145#endif
    8801146#else
    8811147  if (uiCode)
     
    8991165  assert( uiCode == 0 );
    9001166
     1167#if !MOVE_SCALED_OFFSET_TO_PPS
    9011168  if( pcSPS->getLayerId() > 0 )
    9021169  {
     
    9181185    }
    9191186  }
     1187#endif
    9201188}
    9211189#endif
     
    9261194
    9271195  READ_CODE( 4,  uiCode,  "vps_video_parameter_set_id" );         pcVPS->setVPSId( uiCode );
     1196#if VPS_RESERVED_FLAGS
     1197  READ_FLAG( uiCode, "vps_base_layer_internal_flag");             pcVPS->setBaseLayerInternalFlag( uiCode ? true : false );
     1198  READ_FLAG( uiCode, "vps_base_layer_available_flag");            pcVPS->setBaseLayerAvailableFlag( uiCode ? true : false );
     1199#if VPS_AVC_BL_FLAG_REMOVAL
     1200  pcVPS->setNonHEVCBaseLayerFlag( (pcVPS->getBaseLayerAvailableFlag() && !pcVPS->getBaseLayerInternalFlag()) ? true : false);
     1201#endif
     1202#else
    9281203  READ_CODE( 2,  uiCode,  "vps_reserved_three_2bits" );           assert(uiCode == 3);
     1204#endif
    9291205#if SVC_EXTENSION
    9301206#if O0137_MAX_LAYERID
     
    10251301        READ_FLAG( uiCode, "cprms_present_flag[i]" );               pcVPS->setCprmsPresentFlag( uiCode == 1 ? true : false, i );
    10261302      }
     1303      else
     1304      {
     1305        pcVPS->setCprmsPresentFlag( true, i );
     1306      }
     1307
    10271308      parseHrdParameters(pcVPS->getHrdParameters(i), pcVPS->getCprmsPresentFlag( i ), pcVPS->getMaxTLayers() - 1);
    10281309    }
     
    10821363  Int OlsHighestOutputLayerId[MAX_VPS_LAYER_SETS_PLUS1];
    10831364#endif
     1365#if LIST_OF_PTL
     1366  if( vps->getMaxLayers() > 1 && vps->getBaseLayerInternalFlag() )
     1367  {
     1368    vps->setProfilePresentFlag(1, false);
     1369    vps->getPTLForExtnPtr()->empty();
     1370    vps->getPTLForExtnPtr()->resize(2);
     1371    vps->getPTLForExtn(1)->copyProfileInfo( vps->getPTL() );
     1372    parsePTL( vps->getPTLForExtn(1), vps->getProfilePresentFlag(1), vps->getMaxTLayers() - 1 );
     1373  }
     1374#endif
    10841375#if VPS_EXTN_MASK_AND_DIM_INFO
    10851376  UInt numScalabilityTypes = 0, i = 0, j = 0;
    10861377
     1378#if !VPS_AVC_BL_FLAG_REMOVAL
    10871379  READ_FLAG( uiCode, "avc_base_layer_flag" ); vps->setAvcBaseLayerFlag(uiCode ? true : false);
     1380#endif
    10881381
    10891382#if !P0307_REMOVE_VPS_VUI_OFFSET
     
    10941387#endif
    10951388#if VPS_VUI_OFFSET
    1096   READ_CODE( 16, uiCode, "vps_vui_offset" );  vps->setVpsVuiOffset( uiCode );
     1389    READ_CODE( 16, uiCode, "vps_vui_offset" );  vps->setVpsVuiOffset( uiCode );
    10971390#endif
    10981391#if O0109_MOVE_VPS_VUI_FLAG
     
    11451438    if( !vps->getSplittingFlag() )
    11461439    {
    1147     for(j = 0; j < numScalabilityTypes; j++)
    1148     {
    1149       READ_CODE( vps->getDimensionIdLen(j), uiCode, "dimension_id[i][j]" ); vps->setDimensionId(i, j, uiCode);
     1440      for(j = 0; j < numScalabilityTypes; j++)
     1441      {
     1442        READ_CODE( vps->getDimensionIdLen(j), uiCode, "dimension_id[i][j]" ); vps->setDimensionId(i, j, uiCode);
    11501443#if !AUXILIARY_PICTURES
    1151       assert( uiCode <= vps->getMaxLayerId() );
    1152 #endif
    1153     }
    1154   }
     1444        assert( uiCode <= vps->getMaxLayerId() );
     1445#endif
     1446      }
     1447    }
    11551448  }
    11561449#endif
     
    12151508  vps->setTreePartitionLayerIdList();
    12161509#endif
     1510#if MOVE_ADDN_LS_SIGNALLING
     1511#if Q0078_ADD_LAYER_SETS
     1512  if (vps->getNumIndependentLayers() > 1)
     1513  {
     1514    READ_UVLC(uiCode, "num_add_layer_sets"); vps->setNumAddLayerSets(uiCode);
     1515    for (i = 0; i < vps->getNumAddLayerSets(); i++)
     1516    {
     1517      for (j = 1; j < vps->getNumIndependentLayers(); j++)
     1518      {
     1519        int len = 1;
     1520        while ((1 << len) < (vps->getNumLayersInTreePartition(j) + 1))
     1521        {
     1522          len++;
     1523        }
     1524        READ_CODE(len, uiCode, "highest_layer_idx_plus1[i][j]"); vps->setHighestLayerIdxPlus1(i, j, uiCode);
     1525      }
     1526    }
     1527    vps->setNumLayerSets(vps->getNumLayerSets() + vps->getNumAddLayerSets());
     1528    vps->setLayerIdIncludedFlagsForAddLayerSets();
     1529  }
     1530#endif
     1531#endif
    12171532#if VPS_TSLAYERS
    12181533  READ_FLAG( uiCode, "vps_sub_layers_max_minus1_present_flag"); vps->setMaxTSLayersPresentFlag(uiCode ? true : false);
     
    12391554    {
    12401555#if O0225_MAX_TID_FOR_REF_LAYERS
    1241        for( j = i+1; j <= vps->getMaxLayers() - 1; j++)
    1242        {
    1243          if(vps->getDirectDependencyFlag(j, i))
    1244          {
    1245            READ_CODE( 3, uiCode, "max_tid_il_ref_pics_plus1[i][j]" ); vps->setMaxTidIlRefPicsPlus1(i, j, uiCode);
    1246            assert( uiCode <= vps->getMaxTLayers());
    1247          }
    1248        }
     1556      for( j = i+1; j <= vps->getMaxLayers() - 1; j++)
     1557      {
     1558        if(vps->getDirectDependencyFlag(j, i))
     1559        {
     1560          READ_CODE( 3, uiCode, "max_tid_il_ref_pics_plus1[i][j]" ); vps->setMaxTidIlRefPicsPlus1(i, j, uiCode);         
     1561        }
     1562      }
    12491563#else
    12501564      READ_CODE( 3, uiCode, "max_tid_il_ref_pics_plus1[i]" ); vps->setMaxTidIlRefPicsPlus1(i, uiCode);
     
    12581572    {
    12591573#if O0225_MAX_TID_FOR_REF_LAYERS
    1260        for( j = i+1; j <= vps->getMaxLayers() - 1; j++)
    1261        {
    1262           vps->setMaxTidIlRefPicsPlus1(i, j, 7);
    1263        }
     1574      for( j = i+1; j <= vps->getMaxLayers() - 1; j++)
     1575      {
     1576        vps->setMaxTidIlRefPicsPlus1(i, j, 7);
     1577      }
    12641578#else
    12651579      vps->setMaxTidIlRefPicsPlus1(i, 7);
     
    12761590  READ_UVLC(  uiCode, "vps_num_profile_tier_level_minus1"); vps->setNumProfileTierLevel( uiCode + 1 );
    12771591#endif
     1592#if PER_LAYER_PTL
     1593  Int const numBitsForPtlIdx = vps->calculateLenOfSyntaxElement( vps->getNumProfileTierLevel() );
     1594#endif
    12781595  vps->getPTLForExtnPtr()->resize(vps->getNumProfileTierLevel());
     1596#if LIST_OF_PTL
     1597  for(Int idx = vps->getBaseLayerInternalFlag() ? 2 : 1; idx <= vps->getNumProfileTierLevel() - 1; idx++)
     1598#else
    12791599  for(Int idx = 1; idx <= vps->getNumProfileTierLevel() - 1; idx++)
     1600#endif
    12801601  {
    12811602    READ_FLAG( uiCode, "vps_profile_present_flag[i]" ); vps->setProfilePresentFlag(idx, uiCode ? true : false);
     
    13001621#endif
    13011622
     1623#if !MOVE_ADDN_LS_SIGNALLING
    13021624#if Q0078_ADD_LAYER_SETS
    13031625  if (vps->getNumIndependentLayers() > 1)
     
    13191641    vps->setLayerIdIncludedFlagsForAddLayerSets();
    13201642  }
     1643#endif
    13211644#endif
    13221645
     
    13631686#endif
    13641687  vps->setNumOutputLayerSets( numOutputLayerSets );
    1365 
     1688#if NECESSARY_LAYER_FLAG
     1689  // Default output layer set
     1690  vps->setOutputLayerSetIdx(0, 0);
     1691  vps->setOutputLayerFlag(0, 0, true);
     1692  vps->deriveNecessaryLayerFlag(0);
     1693#if PER_LAYER_PTL
     1694  vps->getProfileLevelTierIdx()->resize(numOutputLayerSets);
     1695  vps->getProfileLevelTierIdx(0)->push_back( vps->getBaseLayerInternalFlag() && vps->getMaxLayers() > 1 ? 1 : 0);
     1696#endif
     1697#endif
    13661698  for(i = 1; i < numOutputLayerSets; i++)
    13671699  {
     
    13791711      vps->setOutputLayerSetIdx( i, i );
    13801712    }
     1713    Int layerSetIdxForOutputLayerSet = vps->getOutputLayerSetIdx(i);
    13811714#if Q0078_ADD_LAYER_SETS
    13821715    if ( i > vps->getVpsNumLayerSetsMinus1() || vps->getDefaultTargetOutputLayerIdc() >= 2 )
     
    13851718#endif
    13861719    {
    1387       Int lsIdx = vps->getOutputLayerSetIdx(i);
    13881720#if NUM_OL_FLAGS
    1389       for(j = 0; j < vps->getNumLayersInIdList(lsIdx); j++)
     1721      for(j = 0; j < vps->getNumLayersInIdList(layerSetIdxForOutputLayerSet); j++)
    13901722#else
    13911723      for(j = 0; j < vps->getNumLayersInIdList(lsIdx) - 1; j++)
     
    13991731      // i <= (vps->getNumLayerSets() - 1)
    14001732      // Assign OutputLayerFlag depending on default_one_target_output_layer_flag
    1401       Int lsIdx = i;
    14021733      if( vps->getDefaultTargetOutputLayerIdc() == 1 )
    14031734      {
    1404         for(j = 0; j < vps->getNumLayersInIdList(lsIdx); j++)
    1405         {
    1406           vps->setOutputLayerFlag(i, j, (j == (vps->getNumLayersInIdList(lsIdx)-1)) && (vps->getDimensionId(j,1) == 0) );
     1735        for(j = 0; j < vps->getNumLayersInIdList(layerSetIdxForOutputLayerSet); j++)
     1736        {
     1737#if DEF_OPT_LAYER_IDC
     1738          vps->setOutputLayerFlag(i, j, (j == (vps->getNumLayersInIdList(layerSetIdxForOutputLayerSet)-1))  );
     1739
     1740#else
     1741          vps->setOutputLayerFlag(i, j, (j == (vps->getNumLayersInIdList(layerSetIdxForOutputLayerSet)-1)) && (vps->getDimensionId(j,1) == 0) );
     1742#endif
    14071743        }
    14081744      }
    14091745      else if ( vps->getDefaultTargetOutputLayerIdc() == 0 )
    14101746      {
    1411         for(j = 0; j < vps->getNumLayersInIdList(lsIdx); j++)
     1747        for(j = 0; j < vps->getNumLayersInIdList(layerSetIdxForOutputLayerSet); j++)
    14121748        {
    14131749          vps->setOutputLayerFlag(i, j, 1);
     
    14151751      }
    14161752    }
     1753#if NECESSARY_LAYER_FLAG
     1754    vps->deriveNecessaryLayerFlag(i); 
     1755#endif
     1756#if PER_LAYER_PTL
     1757    vps->getProfileLevelTierIdx(i)->assign(vps->getNumLayersInIdList(layerSetIdxForOutputLayerSet), -1);
     1758    for(j = 0; j < vps->getNumLayersInIdList(layerSetIdxForOutputLayerSet) ; j++)
     1759    {
     1760      if( vps->getNecessaryLayerFlag(i, j) )
     1761      {
     1762        READ_CODE( numBitsForPtlIdx, uiCode, "profile_level_tier_idx[i]" );
     1763        vps->setProfileLevelTierIdx(i, j, uiCode );
     1764      }
     1765    }
     1766#else
    14171767    Int numBits = 1;
    14181768    while ((1 << numBits) < (vps->getNumProfileTierLevel()))
     
    14211771    }
    14221772    READ_CODE( numBits, uiCode, "profile_level_tier_idx[i]" );     vps->setProfileLevelTierIdx(i, uiCode);
     1773#endif
    14231774#if P0300_ALT_OUTPUT_LAYER_FLAG
    14241775    NumOutputLayersInOutputLayerSet[i] = 0;
    1425     Int layerSetIdxForOutputLayerSet = vps->getOutputLayerSetIdx(i);
    14261776    for (j = 0; j < vps->getNumLayersInIdList(layerSetIdxForOutputLayerSet); j++)
    14271777    {
     
    14371787      vps->setAltOuputLayerFlag(i, uiCode ? true : false);
    14381788    }
     1789#if ALT_OPT_LAYER_FLAG
     1790    else
     1791    {
     1792          uiCode=0;
     1793          vps->setAltOuputLayerFlag(i, uiCode ? true : false);
     1794    }
     1795#endif
    14391796#if Q0165_OUTPUT_LAYER_SET
    14401797    assert( NumOutputLayersInOutputLayerSet[i]>0 );
     
    14431800#endif
    14441801  }
     1802#if NECESSARY_LAYER_FLAG
     1803  vps->checkNecessaryLayerFlagCondition(); 
     1804#endif
    14451805#else
    14461806  if( numOutputLayerSets > 1 )
     
    14881848        {
    14891849#if O0135_DEFAULT_ONE_OUT_SEMANTIC
     1850#if DEF_OPT_LAYER_IDC
     1851        vps->setOutputLayerFlag(i, j, (j == (vps->getNumLayersInIdList(lsIdx)-1)) );
     1852#else
    14901853          vps->setOutputLayerFlag(i, j, (j == (vps->getNumLayersInIdList(lsIdx)-1)) && (vps->getDimensionId(j,1)==0) );
     1854#endif
    14911855#else
    14921856          vps->setOutputLayerFlag(i, j, (j == (vps->getNumLayersInIdList(lsIdx)-1)));
     
    16692033  READ_FLAG(uiCode, "max_one_active_ref_layer_flag" );
    16702034  vps->setMaxOneActiveRefLayerFlag(uiCode);
     2035#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     2036  READ_FLAG(uiCode, "vps_poc_lsb_aligned_flag");
     2037  vps->setVpsPocLsbAlignedFlag(uiCode);
     2038#endif
    16712039#if O0062_POC_LSB_NOT_PRESENT_FLAG
    16722040  for(i = 1; i< vps->getMaxLayers(); i++)
     
    18242192#endif
    18252193  }
    1826  
     2194
    18272195  // When not present, the value of num_add_olss is inferred to be equal to 0.
    18282196  // NumOutputLayerSets = num_add_olss + NumLayerSets
     
    18382206    for( j = 0; j < vps->getNumLayersInIdList(lsIdx); j++ )
    18392207    {
    1840     vps->setOutputLayerFlag(i, j, 1);
     2208      vps->setOutputLayerFlag(i, j, 1);
    18412209    }
    18422210  }
     
    18482216    vps->setSubLayerDpbInfoPresentFlag( i, 0, true );
    18492217  }
    1850  
     2218
    18512219  // When not present, the value of vps_num_rep_formats_minus1 is inferred to be equal to MaxLayersMinus1.
    18522220  vps->setVpsNumRepFormats( vps->getMaxLayers() );
     
    18642232  }
    18652233
    1866   // vps_poc_lsb_aligned_flag
    1867   // When not present, vps_poc_lsb_aligned_flag is inferred to be equal to 0.
    1868  
     2234#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     2235  vps->setVpsPocLsbAlignedFlag(false);
     2236#endif
     2237
    18692238#if O0062_POC_LSB_NOT_PRESENT_FLAG
    18702239  // When not present, poc_lsb_not_present_flag[ i ] is inferred to be equal to 0.
     
    19372306    repFormat->setBitDepthVpsChroma         ( repFormatPrev->getBitDepthVpsChroma() );
    19382307  }
     2308
    19392309#else
    19402310#if AUXILIARY_PICTURES
     
    19432313  READ_CODE( 2, uiCode, "chroma_format_idc" );               repFormat->setChromaFormatVpsIdc( uiCode );
    19442314#endif
    1945  
     2315
    19462316  if( repFormat->getChromaFormatVpsIdc() == 3 )
    19472317  {
     
    19552325  READ_CODE( 4, uiCode, "bit_depth_chroma_minus8" );         repFormat->setBitDepthVpsChroma( uiCode + 8 );
    19562326#endif
     2327
     2328#if R0156_CONF_WINDOW_IN_REP_FORMAT
     2329  READ_FLAG( uiCode, "conformance_window_vps_flag" );
     2330  if( uiCode != 0)
     2331  {
     2332    Window &conf = repFormat->getConformanceWindowVps();
     2333    READ_UVLC( uiCode, "conf_win_vps_left_offset" );         conf.setWindowLeftOffset  ( uiCode );
     2334    READ_UVLC( uiCode, "conf_win_vps_right_offset" );        conf.setWindowRightOffset ( uiCode );
     2335    READ_UVLC( uiCode, "conf_win_vps_top_offset" );          conf.setWindowTopOffset   ( uiCode );
     2336    READ_UVLC( uiCode, "conf_win_vps_bottom_offset" );       conf.setWindowBottomOffset( uiCode );
     2337  }
     2338#endif
    19572339}
    19582340#endif
     
    19612343{
    19622344  UInt uiCode;
     2345#if SUB_LAYERS_IN_LAYER_SET
     2346  vps->calculateMaxSLInLayerSets();
     2347#else
    19632348#if DPB_PARAMS_MAXTLAYERS
    19642349#if BITRATE_PICRATE_SIGNALLING
    1965     Int * MaxSubLayersInLayerSetMinus1 = new Int[vps->getNumLayerSets()];
    1966     for(Int i = 0; i < vps->getNumLayerSets(); i++)
    1967 #else
    1968     Int * MaxSubLayersInLayerSetMinus1 = new Int[vps->getNumOutputLayerSets()];
    1969     for(Int i = 1; i < vps->getNumOutputLayerSets(); i++)
    1970 #endif
    1971     {
    1972         UInt maxSLMinus1 = 0;
     2350  Int * MaxSubLayersInLayerSetMinus1 = new Int[vps->getNumLayerSets()];
     2351  for(Int i = 0; i < vps->getNumLayerSets(); i++)
     2352#else
     2353  Int * MaxSubLayersInLayerSetMinus1 = new Int[vps->getNumOutputLayerSets()];
     2354  for(Int i = 1; i < vps->getNumOutputLayerSets(); i++)
     2355#endif
     2356  {
     2357    UInt maxSLMinus1 = 0;
    19732358#if CHANGE_NUMSUBDPB_IDX
    1974         Int optLsIdx = vps->getOutputLayerSetIdx( i );
    1975 #else
    1976         Int optLsIdx = i;
     2359    Int optLsIdx = vps->getOutputLayerSetIdx( i );
     2360#else
     2361    Int optLsIdx = i;
    19772362#endif
    19782363#if BITRATE_PICRATE_SIGNALLING
    1979         optLsIdx = i;
    1980 #endif
    1981         for(Int k = 0; k < vps->getNumLayersInIdList(optLsIdx); k++ ) {
    1982             Int  lId = vps->getLayerSetLayerIdList(optLsIdx, k);
    1983             maxSLMinus1 = max(maxSLMinus1, vps->getMaxTSLayersMinus1(vps->getLayerIdInVps(lId)));
    1984         }
    1985         MaxSubLayersInLayerSetMinus1[ i ] = maxSLMinus1;
     2364    optLsIdx = i;
     2365#endif
     2366    for(Int k = 0; k < vps->getNumLayersInIdList(optLsIdx); k++ ) {
     2367      Int  lId = vps->getLayerSetLayerIdList(optLsIdx, k);
     2368      maxSLMinus1 = max(maxSLMinus1, vps->getMaxTSLayersMinus1(vps->getLayerIdInVps(lId)));
     2369    }
     2370    MaxSubLayersInLayerSetMinus1[ i ] = maxSLMinus1;
    19862371#if BITRATE_PICRATE_SIGNALLING
    1987         vps->setMaxSLayersInLayerSetMinus1(i,MaxSubLayersInLayerSetMinus1[ i ]);
    1988 #endif
    1989     }
    1990 #endif
    1991    
     2372    vps->setMaxSLayersInLayerSetMinus1(i,MaxSubLayersInLayerSetMinus1[ i ]);
     2373#endif
     2374  }
     2375#endif
     2376#endif
     2377
    19922378#if !RESOLUTION_BASED_DPB
    19932379  vps->deriveNumberOfSubDpbs();
     
    19992385#endif
    20002386    READ_FLAG( uiCode, "sub_layer_flag_info_present_flag[i]");  vps->setSubLayerFlagInfoPresentFlag( i, uiCode ? true : false );
     2387#if SUB_LAYERS_IN_LAYER_SET
     2388    for(Int j = 0; j <= vps->getMaxSLayersInLayerSetMinus1( layerSetIdxForOutputLayerSet ); j++)
     2389#else
    20012390#if DPB_PARAMS_MAXTLAYERS
    20022391#if BITRATE_PICRATE_SIGNALLING
     
    20082397    for(Int j = 0; j <= vps->getMaxTLayers(); j++)
    20092398#endif
     2399#endif
    20102400    {
    20112401      if( j > 0 && vps->getSubLayerFlagInfoPresentFlag(i) )
     
    20322422#endif
    20332423        {
     2424#if DPB_INTERNAL_BL_SIG
     2425            uiCode=0;
     2426        if(vps->getBaseLayerInternalFlag()  || ( vps->getLayerSetLayerIdList(layerSetIdxForOutputLayerSet, k)   !=  0 ) )
     2427#endif
    20342428          READ_UVLC( uiCode, "max_vps_dec_pic_buffering_minus1[i][k][j]" ); vps->setMaxVpsDecPicBufferingMinus1( i, k, j, uiCode );
    20352429        }
     
    20602454  }
    20612455
     2456#if !SUB_LAYERS_IN_LAYER_SET
     2457#if BITRATE_PICRATE_SIGNALLING
     2458  if( MaxSubLayersInLayerSetMinus1 )
     2459  {
     2460    delete [] MaxSubLayersInLayerSetMinus1;
     2461  }
     2462#endif
     2463#endif
     2464
    20622465  // Infer values when not signalled
    20632466  for(Int i = 1; i < vps->getNumOutputLayerSets(); i++)
     
    21222525  READ_FLAG( uiCode,        "pic_rate_present_vps_flag" );  vps->setPicRatePresentVpsFlag( uiCode ? true : false );
    21232526
     2527#if SIGNALLING_BITRATE_PICRATE_FIX
     2528  if ( vps->getBitRatePresentVpsFlag() || vps->getPicRatePresentVpsFlag() )
     2529  {
     2530    for( i = vps->getBaseLayerInternalFlag() ? 0 : 1; i < vps->getNumLayerSets(); i++ )
     2531    {
     2532      for( j = 0; j <= vps->getMaxSLayersInLayerSetMinus1( i ); j++ )
     2533      {
     2534        if( vps->getBitRatePresentVpsFlag() )
     2535        {
     2536          READ_FLAG( uiCode, "bit_rate_present_flag[i][j]" ); vps->setBitRatePresentFlag( i, j, uiCode ? true : false );           
     2537        }
     2538        if( vps->getPicRatePresentVpsFlag( )  )
     2539        {
     2540          READ_FLAG( uiCode, "pic_rate_present_flag[i][j]" ); vps->setPicRatePresentFlag( i, j, uiCode ? true : false );
     2541        }
     2542        if( vps->getBitRatePresentFlag( i, j ) )
     2543        {
     2544          READ_CODE( 16, uiCode, "avg_bit_rate" ); vps->setAvgBitRate( i, j, uiCode );
     2545          READ_CODE( 16, uiCode, "max_bit_rate" ); vps->setMaxBitRate( i, j, uiCode );
     2546        }
     2547        else
     2548        {
     2549          vps->setAvgBitRate( i, j, 0 );
     2550          vps->setMaxBitRate( i, j, 0 );
     2551        }
     2552        if( vps->getPicRatePresentFlag( i, j ) )
     2553        {
     2554          READ_CODE( 2,  uiCode, "constant_pic_rate_idc" ); vps->setConstPicRateIdc( i, j, uiCode );
     2555          READ_CODE( 16, uiCode, "avg_pic_rate" );          vps->setAvgPicRate( i, j, uiCode );
     2556        }
     2557        else
     2558        {
     2559          vps->setConstPicRateIdc( i, j, 0 );
     2560          vps->setAvgPicRate( i, j, 0 );
     2561        }
     2562      }
     2563    }
     2564  }
     2565#else
    21242566  Bool parseFlag = vps->getBitRatePresentVpsFlag() || vps->getPicRatePresentVpsFlag();
    21252567
    21262568#if Q0078_ADD_LAYER_SETS
     2569#if R0227_BR_PR_ADD_LAYER_SET
     2570  for( i = 0; i < vps->getNumLayerSets(); i++ )
     2571#else
    21272572  for( i = 0; i <= vps->getVpsNumLayerSetsMinus1(); i++ )
     2573#endif
    21282574#else
    21292575  for( i = 0; i < vps->getNumLayerSets(); i++ )
     
    21742620    }
    21752621  }
     2622#endif
    21762623#if VPS_VUI_VIDEO_SIGNAL_MOVE
    21772624  READ_FLAG( uiCode, "video_signal_info_idx_present_flag" ); vps->setVideoSigPresentVpsFlag( uiCode == 1 );
     
    21822629  else
    21832630  {
     2631#if VPS_VUI_VST_PARAMS
     2632    vps->setNumVideoSignalInfo(vps->getMaxLayers() - vps->getBaseLayerInternalFlag() ? 0 : 1);
     2633#else
    21842634    vps->setNumVideoSignalInfo(vps->getMaxLayers());
     2635#endif
    21852636  }
    21862637
     
    21932644    READ_CODE(8, uiCode, "matrix_coeffs_vps" );vps->setMaxtrixCoeff(i,uiCode);
    21942645  }
     2646#if VPS_VUI_VST_PARAMS
     2647  if( vps->getVideoSigPresentVpsFlag() && vps->getNumVideoSignalInfo() > 1 )
     2648  {
     2649    for(i = vps->getBaseLayerInternalFlag() ? 0 : 1; i < vps->getMaxLayers(); i++)
     2650    {
     2651      READ_CODE(4, uiCode, "vps_video_signal_info_idx" ); vps->setVideoSignalInfoIdx(i, uiCode);
     2652    }
     2653  }
     2654  else if ( !vps->getVideoSigPresentVpsFlag() )
     2655  {
     2656    for(i = vps->getBaseLayerInternalFlag() ? 0 : 1; i < vps->getMaxLayers(); i++)
     2657    {
     2658      vps->setVideoSignalInfoIdx( i, i );
     2659    }
     2660  }
     2661  else // ( vps->getNumVideoSignalInfo() = 0 )
     2662  {
     2663    for(i = vps->getBaseLayerInternalFlag() ? 0 : 1; i < vps->getMaxLayers(); i++)
     2664    {
     2665      vps->setVideoSignalInfoIdx( i, 0 );
     2666    }
     2667  }
     2668#else
    21952669  if(!vps->getVideoSigPresentVpsFlag())
    21962670  {
     
    22142688    }
    22152689  }
     2690#endif
    22162691#endif
    22172692#if VPS_VUI_TILES_NOT_IN_USE__FLAG
     
    23032778#if VPS_VUI_VIDEO_SIGNAL_MOVE
    23042779#else
    2305     READ_FLAG( uiCode, "video_signal_info_idx_present_flag" ); vps->setVideoSigPresentVpsFlag( uiCode == 1 );
    2306     if (vps->getVideoSigPresentVpsFlag())
    2307     {
    2308         READ_CODE(4, uiCode, "vps_num_video_signal_info_minus1" ); vps->setNumVideoSignalInfo(uiCode + 1);
     2780  READ_FLAG( uiCode, "video_signal_info_idx_present_flag" ); vps->setVideoSigPresentVpsFlag( uiCode == 1 );
     2781  if (vps->getVideoSigPresentVpsFlag())
     2782  {
     2783    READ_CODE(4, uiCode, "vps_num_video_signal_info_minus1" ); vps->setNumVideoSignalInfo(uiCode + 1);
     2784  }
     2785  else
     2786  {
     2787    vps->setNumVideoSignalInfo(vps->getMaxLayers());
     2788  }
     2789
     2790
     2791  for(i = 0; i < vps->getNumVideoSignalInfo(); i++)
     2792  {
     2793    READ_CODE(3, uiCode, "video_vps_format" ); vps->setVideoVPSFormat(i,uiCode);
     2794    READ_FLAG(uiCode, "video_full_range_vps_flag" ); vps->setVideoFullRangeVpsFlag(i,uiCode);
     2795    READ_CODE(8, uiCode, "color_primaries_vps" ); vps->setColorPrimaries(i,uiCode);
     2796    READ_CODE(8, uiCode, "transfer_characteristics_vps" ); vps->setTransCharacter(i,uiCode);
     2797    READ_CODE(8, uiCode, "matrix_coeffs_vps" );vps->setMaxtrixCoeff(i,uiCode);
     2798  }
     2799  if(!vps->getVideoSigPresentVpsFlag())
     2800  {
     2801    for (i=0; i < vps->getMaxLayers(); i++)
     2802    {
     2803      vps->setVideoSignalInfoIdx(i,i);
     2804    }
     2805  }
     2806  else {
     2807    vps->setVideoSignalInfoIdx(0,0);
     2808    if (vps->getNumVideoSignalInfo() > 1 )
     2809    {
     2810      for (i=1; i < vps->getMaxLayers(); i++)
     2811        READ_CODE(4, uiCode, "vps_video_signal_info_idx" ); vps->setVideoSignalInfoIdx(i, uiCode);
     2812    }
     2813    else {
     2814      for (i=1; i < vps->getMaxLayers(); i++)
     2815      {
     2816        vps->setVideoSignalInfoIdx(i,0);
     2817      }
     2818    }
     2819  }
     2820#endif
     2821#endif
     2822
     2823#if O0164_MULTI_LAYER_HRD
     2824  READ_FLAG(uiCode, "vps_vui_bsp_hrd_present_flag" ); vps->setVpsVuiBspHrdPresentFlag(uiCode);
     2825  if (vps->getVpsVuiBspHrdPresentFlag())
     2826  {
     2827#if VPS_VUI_BSP_HRD_PARAMS
     2828    parseVpsVuiBspHrdParams(vps);
     2829#else
     2830#if R0227_VUI_BSP_HRD_FLAG
     2831    assert (vps->getTimingInfo()->getTimingInfoPresentFlag() == 1);
     2832#endif
     2833    READ_UVLC( uiCode, "vps_num_bsp_hrd_parameters_minus1" ); vps->setVpsNumBspHrdParametersMinus1(uiCode);
     2834    vps->createBspHrdParamBuffer(vps->getVpsNumBspHrdParametersMinus1() + 1);
     2835    for( i = 0; i <= vps->getVpsNumBspHrdParametersMinus1(); i++ )
     2836    {
     2837      if( i > 0 )
     2838      {
     2839        READ_FLAG( uiCode, "bsp_cprms_present_flag[i]" ); vps->setBspCprmsPresentFlag(i, uiCode);
     2840      }
     2841      parseHrdParameters(vps->getBspHrd(i), i==0 ? 1 : vps->getBspCprmsPresentFlag(i), vps->getMaxTLayers()-1);
     2842    }
     2843#if Q0078_ADD_LAYER_SETS
     2844    for (UInt h = 1; h <= vps->getVpsNumLayerSetsMinus1(); h++)
     2845#else
     2846    for( UInt h = 1; h <= (vps->getNumLayerSets()-1); h++ )
     2847#endif
     2848    {
     2849      READ_UVLC( uiCode, "num_bitstream_partitions[i]"); vps->setNumBitstreamPartitions(h, uiCode);
     2850#if HRD_BPB
     2851      Int chkPart=0;
     2852#endif
     2853      for( i = 0; i < vps->getNumBitstreamPartitions(h); i++ )
     2854      {
     2855        for( j = 0; j <= (vps->getMaxLayers()-1); j++ )
     2856        {
     2857          if( vps->getLayerIdIncludedFlag(h, j) )
     2858          {
     2859            READ_FLAG( uiCode, "layer_in_bsp_flag[h][i][j]" ); vps->setLayerInBspFlag(h, i, j, uiCode);
     2860          }
     2861        }
     2862#if HRD_BPB
     2863        chkPart+=vps->getLayerInBspFlag(h, i, j);
     2864#endif
     2865      }
     2866#if HRD_BPB
     2867      assert(chkPart<=1);
     2868#endif
     2869#if HRD_BPB
     2870      if(vps->getNumBitstreamPartitions(h)==1)
     2871      {
     2872        Int chkPartition1=0; Int chkPartition2=0;
     2873        for( j = 0; j <= (vps->getMaxLayers()-1); j++ )
     2874        {
     2875          if( vps->getLayerIdIncludedFlag(h, j) )
     2876          {
     2877            chkPartition1+=vps->getLayerInBspFlag(h, 0, j);
     2878            chkPartition2++;
     2879          }
     2880        }
     2881        assert(chkPartition1!=chkPartition2);
     2882      }
     2883#endif
     2884      if (vps->getNumBitstreamPartitions(h))
     2885      {
     2886#if Q0182_MULTI_LAYER_HRD_UPDATE
     2887        READ_UVLC( uiCode, "num_bsp_sched_combinations_minus1[h]"); vps->setNumBspSchedCombinations(h, uiCode + 1);
     2888#else
     2889        READ_UVLC( uiCode, "num_bsp_sched_combinations[h]"); vps->setNumBspSchedCombinations(h, uiCode);
     2890#endif
     2891        for( i = 0; i < vps->getNumBspSchedCombinations(h); i++ )
     2892        {
     2893          for( j = 0; j < vps->getNumBitstreamPartitions(h); j++ )
     2894          {
     2895            READ_UVLC( uiCode, "bsp_comb_hrd_idx[h][i][j]"); vps->setBspCombHrdIdx(h, i, j, uiCode);
     2896#if HRD_BPB
     2897            assert(uiCode <= vps->getVpsNumBspHrdParametersMinus1());
     2898#endif
     2899
     2900            READ_UVLC( uiCode, "bsp_comb_sched_idx[h][i][j]"); vps->setBspCombSchedIdx(h, i, j, uiCode);
     2901#if HRD_BPB
     2902            assert(uiCode <= vps->getBspHrdParamBufferCpbCntMinus1(uiCode,vps->getMaxTLayers()-1));
     2903#endif
     2904          }
     2905        }
     2906      }
     2907    }
     2908#endif
     2909  }
     2910#endif
     2911#if P0182_VPS_VUI_PS_FLAG
     2912  for(i = 1; i < vps->getMaxLayers(); i++)
     2913  {
     2914    if (vps->getNumRefLayers(vps->getLayerIdInNuh(i)) == 0)
     2915    {
     2916      READ_FLAG( uiCode, "base_layer_parameter_set_compatibility_flag" );
     2917      vps->setBaseLayerPSCompatibilityFlag( i, uiCode );
    23092918    }
    23102919    else
    23112920    {
    2312         vps->setNumVideoSignalInfo(vps->getMaxLayers());
    2313     }
    2314    
    2315    
    2316     for(i = 0; i < vps->getNumVideoSignalInfo(); i++)
    2317     {
    2318         READ_CODE(3, uiCode, "video_vps_format" ); vps->setVideoVPSFormat(i,uiCode);
    2319         READ_FLAG(uiCode, "video_full_range_vps_flag" ); vps->setVideoFullRangeVpsFlag(i,uiCode);
    2320         READ_CODE(8, uiCode, "color_primaries_vps" ); vps->setColorPrimaries(i,uiCode);
    2321         READ_CODE(8, uiCode, "transfer_characteristics_vps" ); vps->setTransCharacter(i,uiCode);
    2322         READ_CODE(8, uiCode, "matrix_coeffs_vps" );vps->setMaxtrixCoeff(i,uiCode);
    2323     }
    2324     if(!vps->getVideoSigPresentVpsFlag())
    2325     {
    2326         for (i=0; i < vps->getMaxLayers(); i++)
    2327         {
    2328             vps->setVideoSignalInfoIdx(i,i);
    2329         }
    2330     }
    2331     else {
    2332         vps->setVideoSignalInfoIdx(0,0);
    2333         if (vps->getNumVideoSignalInfo() > 1 )
    2334         {
    2335             for (i=1; i < vps->getMaxLayers(); i++)
    2336                 READ_CODE(4, uiCode, "vps_video_signal_info_idx" ); vps->setVideoSignalInfoIdx(i, uiCode);
    2337         }
    2338         else {
    2339           for (i=1; i < vps->getMaxLayers(); i++)
    2340           {
    2341             vps->setVideoSignalInfoIdx(i,0);
    2342           }
    2343         }
    2344     }
    2345 #endif
    2346 #endif
    2347 
    2348 #if O0164_MULTI_LAYER_HRD
    2349     READ_FLAG(uiCode, "vps_vui_bsp_hrd_present_flag" ); vps->setVpsVuiBspHrdPresentFlag(uiCode);
    2350     if (vps->getVpsVuiBspHrdPresentFlag())
    2351     {
    2352       READ_UVLC( uiCode, "vps_num_bsp_hrd_parameters_minus1" ); vps->setVpsNumBspHrdParametersMinus1(uiCode);
    2353       vps->createBspHrdParamBuffer(vps->getVpsNumBspHrdParametersMinus1() + 1);
    2354       for( i = 0; i <= vps->getVpsNumBspHrdParametersMinus1(); i++ )
    2355       {
    2356         if( i > 0 )
    2357         {
    2358           READ_FLAG( uiCode, "bsp_cprms_present_flag[i]" ); vps->setBspCprmsPresentFlag(i, uiCode);
    2359         }
    2360         parseHrdParameters(vps->getBspHrd(i), i==0 ? 1 : vps->getBspCprmsPresentFlag(i), vps->getMaxTLayers()-1);
    2361       }
    2362 #if Q0078_ADD_LAYER_SETS
    2363       for (UInt h = 1; h <= vps->getVpsNumLayerSetsMinus1(); h++)
    2364 #else
    2365       for( UInt h = 1; h <= (vps->getNumLayerSets()-1); h++ )
    2366 #endif
    2367       {
    2368         READ_UVLC( uiCode, "num_bitstream_partitions[i]"); vps->setNumBitstreamPartitions(h, uiCode);
    2369 #if HRD_BPB
    2370         Int chkPart=0;
    2371 #endif
    2372         for( i = 0; i < vps->getNumBitstreamPartitions(h); i++ )
    2373         {
    2374           for( j = 0; j <= (vps->getMaxLayers()-1); j++ )
    2375           {
    2376             if( vps->getLayerIdIncludedFlag(h, j) )
    2377             {
    2378               READ_FLAG( uiCode, "layer_in_bsp_flag[h][i][j]" ); vps->setLayerInBspFlag(h, i, j, uiCode);
    2379             }
    2380           }
    2381 #if HRD_BPB
    2382           chkPart+=vps->getLayerInBspFlag(h, i, j);
    2383 #endif
    2384         }
    2385 #if HRD_BPB
    2386         assert(chkPart<=1);
    2387 #endif
    2388 #if HRD_BPB
    2389         if(vps->getNumBitstreamPartitions(h)==1)
    2390         {
    2391           Int chkPartition1=0; Int chkPartition2=0;
    2392           for( j = 0; j <= (vps->getMaxLayers()-1); j++ )
    2393           {
    2394             if( vps->getLayerIdIncludedFlag(h, j) )
    2395             {
    2396               chkPartition1+=vps->getLayerInBspFlag(h, 0, j);
    2397               chkPartition2++;
    2398             }
    2399           }
    2400           assert(chkPartition1!=chkPartition2);
    2401         }
    2402 #endif
    2403         if (vps->getNumBitstreamPartitions(h))
    2404         {
    2405 #if Q0182_MULTI_LAYER_HRD_UPDATE
    2406           READ_UVLC( uiCode, "num_bsp_sched_combinations_minus1[h]"); vps->setNumBspSchedCombinations(h, uiCode + 1);
    2407 #else
    2408           READ_UVLC( uiCode, "num_bsp_sched_combinations[h]"); vps->setNumBspSchedCombinations(h, uiCode);
    2409 #endif
    2410           for( i = 0; i < vps->getNumBspSchedCombinations(h); i++ )
    2411           {
    2412             for( j = 0; j < vps->getNumBitstreamPartitions(h); j++ )
    2413             {
    2414               READ_UVLC( uiCode, "bsp_comb_hrd_idx[h][i][j]"); vps->setBspCombHrdIdx(h, i, j, uiCode);
    2415 #if HRD_BPB
    2416               assert(uiCode <= vps->getVpsNumBspHrdParametersMinus1());
    2417 #endif
    2418                
    2419               READ_UVLC( uiCode, "bsp_comb_sched_idx[h][i][j]"); vps->setBspCombSchedIdx(h, i, j, uiCode);
    2420 #if HRD_BPB
    2421               assert(uiCode <= vps->getBspHrdParamBufferCpbCntMinus1(uiCode,vps->getMaxTLayers()-1));
    2422 #endif
    2423             }
    2424           }
    2425         }
    2426       }
    2427     }
    2428 #endif
    2429 
    2430 #if P0182_VPS_VUI_PS_FLAG
    2431     for(i = 1; i < vps->getMaxLayers(); i++)
    2432     {
    2433       if (vps->getNumRefLayers(vps->getLayerIdInNuh(i)) == 0)
    2434       {
    2435         READ_FLAG( uiCode, "base_layer_parameter_set_compatibility_flag" );
    2436         vps->setBaseLayerPSCompatibilityFlag( i, uiCode );
    2437       }
    2438       else
    2439       {
    2440         vps->setBaseLayerPSCompatibilityFlag( i, 0 );
    2441       }
    2442     }
    2443 #endif
    2444 }
     2921      vps->setBaseLayerPSCompatibilityFlag( i, 0 );
     2922    }
     2923  }
     2924#endif
     2925}
     2926
    24452927#endif //SVC_EXTENSION
    24462928
     
    24762958  rpcSlice->setSPS(sps);
    24772959  rpcSlice->setPPS(pps);
     2960
     2961#if R0227_REP_FORMAT_CONSTRAINT //Conformance checking for rep format -- rep format of current picture of current layer shall never be greater rep format defined in VPS for the current layer
     2962  TComVPS* vps = NULL;
     2963  vps = parameterSetManager->getPrefetchedVPS(sps->getVPSId());
     2964#if R0279_REP_FORMAT_INBL
     2965  if ( vps->getVpsExtensionFlag() == 1 && (rpcSlice->getLayerId() == 0 || sps->getV1CompatibleSPSFlag() == 1) )
     2966  {
     2967    assert( sps->getPicWidthInLumaSamples() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(rpcSlice->getLayerId()) )->getPicWidthVpsInLumaSamples() );
     2968    assert( sps->getPicHeightInLumaSamples() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(rpcSlice->getLayerId()) )->getPicHeightVpsInLumaSamples() );
     2969    assert( sps->getChromaFormatIdc() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(rpcSlice->getLayerId()) )->getChromaFormatVpsIdc() );
     2970    assert( sps->getBitDepthY() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(rpcSlice->getLayerId()) )->getBitDepthVpsLuma() );
     2971    assert( sps->getBitDepthC() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(rpcSlice->getLayerId()) )->getBitDepthVpsChroma() );
     2972#else
     2973  if ( rpcSlice->getLayerId() == 0 && vps->getVpsExtensionFlag() == 1 )
     2974  {
     2975    assert( sps->getPicWidthInLumaSamples() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(0) )->getPicWidthVpsInLumaSamples() );
     2976    assert( sps->getPicHeightInLumaSamples() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(0) )->getPicHeightVpsInLumaSamples() );
     2977    assert( sps->getChromaFormatIdc() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(0) )->getChromaFormatVpsIdc() );
     2978    assert( sps->getBitDepthY() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(0) )->getBitDepthVpsLuma() );
     2979    assert( sps->getBitDepthC() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(0) )->getBitDepthVpsChroma() );
     2980#endif
     2981  }
     2982  else if ( vps->getVpsExtensionFlag() == 1 )
     2983  {
     2984    assert(vps->getVpsRepFormat( vps->getVpsRepFormatIdx(sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : rpcSlice->getLayerId()))->getPicWidthVpsInLumaSamples() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(rpcSlice->getLayerId()))->getPicWidthVpsInLumaSamples());
     2985    assert(vps->getVpsRepFormat( vps->getVpsRepFormatIdx(sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : rpcSlice->getLayerId()))->getPicHeightVpsInLumaSamples() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(rpcSlice->getLayerId()))->getPicHeightVpsInLumaSamples());
     2986    assert(vps->getVpsRepFormat( vps->getVpsRepFormatIdx(sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : rpcSlice->getLayerId()))->getChromaFormatVpsIdc() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(rpcSlice->getLayerId()))->getChromaFormatVpsIdc());
     2987    assert(vps->getVpsRepFormat( vps->getVpsRepFormatIdx(sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : rpcSlice->getLayerId()))->getBitDepthVpsLuma() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(rpcSlice->getLayerId()))->getBitDepthVpsLuma());
     2988    assert(vps->getVpsRepFormat( vps->getVpsRepFormatIdx(sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : rpcSlice->getLayerId()))->getBitDepthVpsChroma() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(rpcSlice->getLayerId()))->getBitDepthVpsChroma());
     2989  }
     2990#endif
     2991
    24782992  if( pps->getDependentSliceSegmentsEnabledFlag() && ( !firstSliceSegmentInPic ))
    24792993  {
     
    25223036#if Q0142_POC_LSB_NOT_PRESENT
    25233037#if SHM_FIX7
    2524     Int iPOClsb = 0;
     3038  Int iPOClsb = 0;
    25253039#endif
    25263040#endif
     
    25573071    }
    25583072#else
     3073#if CROSS_LAYER_BLA_FLAG_FIX
     3074    Int iBits = 0;
     3075    if(rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits)
     3076#else
    25593077    if(rpcSlice->getPPS()->getNumExtraSliceHeaderBits()>0)
     3078#endif
    25603079    {
    25613080      READ_FLAG(uiCode, "discardable_flag"); // ignored
    2562     }
     3081#if NON_REF_NAL_TYPE_DISCARDABLE
     3082      rpcSlice->setDiscardableFlag( uiCode ? true : false );
     3083      if (uiCode)
     3084      {
     3085        assert(rpcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_TRAIL_R &&
     3086          rpcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_TSA_R &&
     3087          rpcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_STSA_R &&
     3088          rpcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_RADL_R &&
     3089          rpcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_RASL_R);
     3090      }
     3091#endif
     3092#if CROSS_LAYER_BLA_FLAG_FIX
     3093      iBits++;
     3094#endif
     3095    }
     3096#if CROSS_LAYER_BLA_FLAG_FIX
     3097    if(rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits)
     3098    {
     3099      READ_FLAG(uiCode, "cross_layer_bla_flag");  rpcSlice->setCrossLayerBLAFlag( uiCode ? true : false );
     3100      iBits++;
     3101    }
     3102    for ( ; iBits < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); iBits++)
     3103#else
    25633104    for (Int i = 1; i < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
     3105#endif
    25643106    {
    25653107      READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
     
    26493191#if N0065_LAYER_POC_ALIGNMENT
    26503192#if SHM_FIX7
    2651       }
     3193    }
    26523194#endif
    26533195#if POC_RESET_IDC_DECODER
    2654     else
    2655     {
    2656       rpcSlice->setPicOrderCntLsb( 0 );
    2657     }
    2658 #endif
    2659       if( !rpcSlice->getIdrPicFlag() )
    2660       {
    2661 #endif
    2662       TComReferencePictureSet* rps;
    2663       rps = rpcSlice->getLocalRPS();
    2664       rpcSlice->setRPS(rps);
    2665       READ_FLAG( uiCode, "short_term_ref_pic_set_sps_flag" );
    2666       if(uiCode == 0) // use short-term reference picture set explicitly signalled in slice header
    2667       {
    2668         parseShortTermRefPicSet(sps,rps, sps->getRPSList()->getNumberOfReferencePictureSets());
    2669       }
    2670       else // use reference to short-term reference picture set in PPS
    2671       {
    2672         Int numBits = 0;
    2673         while ((1 << numBits) < rpcSlice->getSPS()->getRPSList()->getNumberOfReferencePictureSets())
    2674         {
    2675           numBits++;
    2676         }
    2677         if (numBits > 0)
    2678         {
    2679           READ_CODE( numBits, uiCode, "short_term_ref_pic_set_idx");
     3196  else
     3197  {
     3198    rpcSlice->setPicOrderCntLsb( 0 );
     3199  }
     3200#endif
     3201  if( !rpcSlice->getIdrPicFlag() )
     3202  {
     3203#endif
     3204    TComReferencePictureSet* rps;
     3205    rps = rpcSlice->getLocalRPS();
     3206    rpcSlice->setRPS(rps);
     3207    READ_FLAG( uiCode, "short_term_ref_pic_set_sps_flag" );
     3208    if(uiCode == 0) // use short-term reference picture set explicitly signalled in slice header
     3209    {
     3210      parseShortTermRefPicSet(sps,rps, sps->getRPSList()->getNumberOfReferencePictureSets());
     3211    }
     3212    else // use reference to short-term reference picture set in PPS
     3213    {
     3214      Int numBits = 0;
     3215      while ((1 << numBits) < rpcSlice->getSPS()->getRPSList()->getNumberOfReferencePictureSets())
     3216      {
     3217        numBits++;
     3218      }
     3219      if (numBits > 0)
     3220      {
     3221        READ_CODE( numBits, uiCode, "short_term_ref_pic_set_idx");
     3222      }
     3223      else
     3224      {
     3225        uiCode = 0;       
     3226      }
     3227      *rps = *(sps->getRPSList()->getReferencePictureSet(uiCode));
     3228    }
     3229    if(sps->getLongTermRefsPresent())
     3230    {
     3231      Int offset = rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures();
     3232      UInt numOfLtrp = 0;
     3233      UInt numLtrpInSPS = 0;
     3234      if (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > 0)
     3235      {
     3236        READ_UVLC( uiCode, "num_long_term_sps");
     3237        numLtrpInSPS = uiCode;
     3238        numOfLtrp += numLtrpInSPS;
     3239        rps->setNumberOfLongtermPictures(numOfLtrp);
     3240      }
     3241      Int bitsForLtrpInSPS = 0;
     3242      while (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > (1 << bitsForLtrpInSPS))
     3243      {
     3244        bitsForLtrpInSPS++;
     3245      }
     3246      READ_UVLC( uiCode, "num_long_term_pics");             rps->setNumberOfLongtermPictures(uiCode);
     3247      numOfLtrp += uiCode;
     3248      rps->setNumberOfLongtermPictures(numOfLtrp);
     3249      Int maxPicOrderCntLSB = 1 << rpcSlice->getSPS()->getBitsForPOC();
     3250      Int prevDeltaMSB = 0, deltaPocMSBCycleLT = 0;;
     3251      for(Int j=offset+rps->getNumberOfLongtermPictures()-1, k = 0; k < numOfLtrp; j--, k++)
     3252      {
     3253        Int pocLsbLt;
     3254        if (k < numLtrpInSPS)
     3255        {
     3256          uiCode = 0;
     3257          if (bitsForLtrpInSPS > 0)
     3258          {
     3259            READ_CODE(bitsForLtrpInSPS, uiCode, "lt_idx_sps[i]");
     3260          }
     3261          Int usedByCurrFromSPS=rpcSlice->getSPS()->getUsedByCurrPicLtSPSFlag(uiCode);
     3262
     3263          pocLsbLt = rpcSlice->getSPS()->getLtRefPicPocLsbSps(uiCode);
     3264          rps->setUsed(j,usedByCurrFromSPS);
    26803265        }
    26813266        else
    26823267        {
    2683           uiCode = 0;       
    2684         }
    2685         *rps = *(sps->getRPSList()->getReferencePictureSet(uiCode));
    2686       }
    2687       if(sps->getLongTermRefsPresent())
    2688       {
    2689         Int offset = rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures();
    2690         UInt numOfLtrp = 0;
    2691         UInt numLtrpInSPS = 0;
    2692         if (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > 0)
    2693         {
    2694           READ_UVLC( uiCode, "num_long_term_sps");
    2695           numLtrpInSPS = uiCode;
    2696           numOfLtrp += numLtrpInSPS;
    2697           rps->setNumberOfLongtermPictures(numOfLtrp);
    2698         }
    2699         Int bitsForLtrpInSPS = 0;
    2700         while (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > (1 << bitsForLtrpInSPS))
    2701         {
    2702           bitsForLtrpInSPS++;
    2703         }
    2704         READ_UVLC( uiCode, "num_long_term_pics");             rps->setNumberOfLongtermPictures(uiCode);
    2705         numOfLtrp += uiCode;
    2706         rps->setNumberOfLongtermPictures(numOfLtrp);
    2707         Int maxPicOrderCntLSB = 1 << rpcSlice->getSPS()->getBitsForPOC();
    2708         Int prevDeltaMSB = 0, deltaPocMSBCycleLT = 0;;
    2709         for(Int j=offset+rps->getNumberOfLongtermPictures()-1, k = 0; k < numOfLtrp; j--, k++)
    2710         {
    2711           Int pocLsbLt;
    2712           if (k < numLtrpInSPS)
     3268          READ_CODE(rpcSlice->getSPS()->getBitsForPOC(), uiCode, "poc_lsb_lt"); pocLsbLt= uiCode;
     3269          READ_FLAG( uiCode, "used_by_curr_pic_lt_flag");     rps->setUsed(j,uiCode);
     3270        }
     3271        READ_FLAG(uiCode,"delta_poc_msb_present_flag");
     3272        Bool mSBPresentFlag = uiCode ? true : false;
     3273        if(mSBPresentFlag)
     3274        {
     3275          READ_UVLC( uiCode, "delta_poc_msb_cycle_lt[i]" );
     3276          Bool deltaFlag = false;
     3277          //            First LTRP                               || First LTRP from SH
     3278          if( (j == offset+rps->getNumberOfLongtermPictures()-1) || (j == offset+(numOfLtrp-numLtrpInSPS)-1) )
    27133279          {
    2714             uiCode = 0;
    2715             if (bitsForLtrpInSPS > 0)
    2716             {
    2717               READ_CODE(bitsForLtrpInSPS, uiCode, "lt_idx_sps[i]");
    2718             }
    2719             Int usedByCurrFromSPS=rpcSlice->getSPS()->getUsedByCurrPicLtSPSFlag(uiCode);
    2720 
    2721             pocLsbLt = rpcSlice->getSPS()->getLtRefPicPocLsbSps(uiCode);
    2722             rps->setUsed(j,usedByCurrFromSPS);
     3280            deltaFlag = true;
     3281          }
     3282          if(deltaFlag)
     3283          {
     3284            deltaPocMSBCycleLT = uiCode;
    27233285          }
    27243286          else
    27253287          {
    2726             READ_CODE(rpcSlice->getSPS()->getBitsForPOC(), uiCode, "poc_lsb_lt"); pocLsbLt= uiCode;
    2727             READ_FLAG( uiCode, "used_by_curr_pic_lt_flag");     rps->setUsed(j,uiCode);
     3288            deltaPocMSBCycleLT = uiCode + prevDeltaMSB;
    27283289          }
    2729           READ_FLAG(uiCode,"delta_poc_msb_present_flag");
    2730           Bool mSBPresentFlag = uiCode ? true : false;
    2731           if(mSBPresentFlag)
     3290
     3291          Int pocLTCurr = rpcSlice->getPOC() - deltaPocMSBCycleLT * maxPicOrderCntLSB
     3292            - iPOClsb + pocLsbLt;
     3293          rps->setPOC     (j, pocLTCurr);
     3294          rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLTCurr);
     3295          rps->setCheckLTMSBPresent(j,true);
     3296        }
     3297        else
     3298        {
     3299          rps->setPOC     (j, pocLsbLt);
     3300          rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLsbLt);
     3301          rps->setCheckLTMSBPresent(j,false);
     3302
     3303          // reset deltaPocMSBCycleLT for first LTRP from slice header if MSB not present
     3304          if( j == offset+(numOfLtrp-numLtrpInSPS)-1 )
    27323305          {
    2733             READ_UVLC( uiCode, "delta_poc_msb_cycle_lt[i]" );
    2734             Bool deltaFlag = false;
    2735             //            First LTRP                               || First LTRP from SH
    2736             if( (j == offset+rps->getNumberOfLongtermPictures()-1) || (j == offset+(numOfLtrp-numLtrpInSPS)-1) )
    2737             {
    2738               deltaFlag = true;
    2739             }
    2740             if(deltaFlag)
    2741             {
    2742               deltaPocMSBCycleLT = uiCode;
    2743             }
    2744             else
    2745             {
    2746               deltaPocMSBCycleLT = uiCode + prevDeltaMSB;
    2747             }
    2748 
    2749             Int pocLTCurr = rpcSlice->getPOC() - deltaPocMSBCycleLT * maxPicOrderCntLSB
    2750                                         - iPOClsb + pocLsbLt;
    2751             rps->setPOC     (j, pocLTCurr);
    2752             rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLTCurr);
    2753             rps->setCheckLTMSBPresent(j,true);
     3306            deltaPocMSBCycleLT = 0;
    27543307          }
    2755           else
     3308        }
     3309        prevDeltaMSB = deltaPocMSBCycleLT;
     3310      }
     3311      offset += rps->getNumberOfLongtermPictures();
     3312      rps->setNumberOfPictures(offset);
     3313    }
     3314#if DPB_CONSTRAINTS
     3315    if(rpcSlice->getVPS()->getVpsExtensionFlag()==1)
     3316    {
     3317#if Q0078_ADD_LAYER_SETS
     3318      for (Int ii = 1; ii < (rpcSlice->getVPS()->getVpsNumLayerSetsMinus1() + 1); ii++)  // prevent assert error when num_add_layer_sets > 0
     3319#else
     3320      for (Int ii=1; ii< rpcSlice->getVPS()->getNumOutputLayerSets(); ii++ )
     3321#endif
     3322      {
     3323        Int layerSetIdxForOutputLayerSet = rpcSlice->getVPS()->getOutputLayerSetIdx( ii );
     3324        Int chkAssert=0;
     3325        for(Int kk = 0; kk < rpcSlice->getVPS()->getNumLayersInIdList(layerSetIdxForOutputLayerSet); kk++)
     3326        {
     3327          if(rpcSlice->getLayerId()==rpcSlice->getVPS()->getLayerSetLayerIdList(layerSetIdxForOutputLayerSet, kk))
    27563328          {
    2757             rps->setPOC     (j, pocLsbLt);
    2758             rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLsbLt);
    2759             rps->setCheckLTMSBPresent(j,false);
    2760 
    2761             // reset deltaPocMSBCycleLT for first LTRP from slice header if MSB not present
    2762             if( j == offset+(numOfLtrp-numLtrpInSPS)-1 )
    2763             {
    2764               deltaPocMSBCycleLT = 0;
     3329            chkAssert=1;
     3330          }
     3331        }
     3332        if(chkAssert)
     3333        {
     3334          // There may be something wrong here (layer id assumed to be layer idx?)
     3335          assert(rps->getNumberOfNegativePictures() <= rpcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii , rpcSlice->getLayerId() , rpcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)));
     3336          assert(rps->getNumberOfPositivePictures() <= rpcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii , rpcSlice->getLayerId() , rpcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)) - rps->getNumberOfNegativePictures());
     3337          assert((rps->getNumberOfPositivePictures() + rps->getNumberOfNegativePictures() + rps->getNumberOfLongtermPictures()) <= rpcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii , rpcSlice->getLayerId() , rpcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)));
     3338        }
     3339      }
     3340
     3341
     3342    }
     3343    if(rpcSlice->getLayerId() == 0)
     3344    {
     3345      assert(rps->getNumberOfNegativePictures() <= rpcSlice->getSPS()->getMaxDecPicBuffering(rpcSlice->getSPS()->getMaxTLayers()-1) );
     3346      assert(rps->getNumberOfPositivePictures() <= rpcSlice->getSPS()->getMaxDecPicBuffering(rpcSlice->getSPS()->getMaxTLayers()-1) -rps->getNumberOfNegativePictures());
     3347      assert((rps->getNumberOfPositivePictures() + rps->getNumberOfNegativePictures() + rps->getNumberOfLongtermPictures()) <= rpcSlice->getSPS()->getMaxDecPicBuffering(rpcSlice->getSPS()->getMaxTLayers()-1));
     3348    }
     3349#endif
     3350    if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
     3351      || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
     3352      || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
     3353    {
     3354      // In the case of BLA picture types, rps data is read from slice header but ignored
     3355      rps = rpcSlice->getLocalRPS();
     3356      rps->setNumberOfNegativePictures(0);
     3357      rps->setNumberOfPositivePictures(0);
     3358      rps->setNumberOfLongtermPictures(0);
     3359      rps->setNumberOfPictures(0);
     3360      rpcSlice->setRPS(rps);
     3361    }
     3362    if (rpcSlice->getSPS()->getTMVPFlagsPresent())
     3363    {
     3364#if R0226_SLICE_TMVP
     3365      READ_FLAG( uiCode, "slice_temporal_mvp_enabled_flag" );
     3366#else
     3367      READ_FLAG( uiCode, "slice_temporal_mvp_enable_flag" );
     3368#endif
     3369      rpcSlice->setEnableTMVPFlag( uiCode == 1 ? true : false );
     3370    }
     3371    else
     3372    {
     3373      rpcSlice->setEnableTMVPFlag(false);
     3374    }
     3375#if N0065_LAYER_POC_ALIGNMENT && !SHM_FIX7
     3376  }
     3377#endif
     3378  }
     3379
     3380#if SVC_EXTENSION
     3381  rpcSlice->setActiveNumILRRefIdx(0);
     3382  if((rpcSlice->getLayerId() > 0) && !(rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag()) && (rpcSlice->getNumILRRefIdx() > 0) )
     3383  {
     3384    READ_FLAG(uiCode,"inter_layer_pred_enabled_flag");
     3385    rpcSlice->setInterLayerPredEnabledFlag(uiCode);
     3386    if( rpcSlice->getInterLayerPredEnabledFlag())
     3387    {
     3388      if(rpcSlice->getNumILRRefIdx() > 1)
     3389      {
     3390        Int numBits = 1;
     3391        while ((1 << numBits) < rpcSlice->getNumILRRefIdx())
     3392        {
     3393          numBits++;
     3394        }
     3395        if( !rpcSlice->getVPS()->getMaxOneActiveRefLayerFlag())
     3396        {
     3397          READ_CODE( numBits, uiCode,"num_inter_layer_ref_pics_minus1" );
     3398          rpcSlice->setActiveNumILRRefIdx(uiCode + 1);
     3399        }
     3400        else
     3401        {
     3402#if P0079_DERIVE_NUMACTIVE_REF_PICS
     3403          for( Int i = 0; i < rpcSlice->getNumILRRefIdx(); i++ )
     3404          {
     3405#if Q0060_MAX_TID_REF_EQUAL_TO_ZERO
     3406            if((rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(rpcSlice->getVPS()->getLayerIdInVps(i),rpcSlice->getLayerId()) >  rpcSlice->getTLayer() || rpcSlice->getTLayer()==0) &&
     3407              (rpcSlice->getVPS()->getMaxTSLayersMinus1(rpcSlice->getVPS()->getLayerIdInVps(i)) >=  rpcSlice->getTLayer()) )
     3408#else
     3409            if(rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(rpcSlice->getVPS()->getLayerIdInVps(i),rpcSlice->getLayerId()) >  rpcSlice->getTLayer() &&
     3410              (rpcSlice->getVPS()->getMaxTSLayersMinus1(rpcSlice->getVPS()->getLayerIdInVps(i)) >=  rpcSlice->getTLayer()) )
     3411#endif
     3412            {         
     3413              rpcSlice->setActiveNumILRRefIdx(1);
     3414              break;
    27653415            }
    27663416          }
    2767           prevDeltaMSB = deltaPocMSBCycleLT;
    2768         }
    2769         offset += rps->getNumberOfLongtermPictures();
    2770         rps->setNumberOfPictures(offset);
    2771       }
    2772 #if DPB_CONSTRAINTS
    2773           if(rpcSlice->getVPS()->getVpsExtensionFlag()==1)
     3417#else
     3418          rpcSlice->setActiveNumILRRefIdx(1);
     3419#endif
     3420        }
     3421
     3422        if( rpcSlice->getActiveNumILRRefIdx() == rpcSlice->getNumILRRefIdx() )
     3423        {
     3424          for( Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
    27743425          {
    2775 #if Q0078_ADD_LAYER_SETS
    2776               for (Int ii = 1; ii < (rpcSlice->getVPS()->getVpsNumLayerSetsMinus1() + 1); ii++)  // prevent assert error when num_add_layer_sets > 0
    2777 #else
    2778               for (Int ii=1; ii< rpcSlice->getVPS()->getNumOutputLayerSets(); ii++ )
    2779 #endif
    2780               {
    2781                   Int layerSetIdxForOutputLayerSet = rpcSlice->getVPS()->getOutputLayerSetIdx( ii );
    2782                   Int chkAssert=0;
    2783                   for(Int kk = 0; kk < rpcSlice->getVPS()->getNumLayersInIdList(layerSetIdxForOutputLayerSet); kk++)
    2784                   {
    2785                       if(rpcSlice->getLayerId()==rpcSlice->getVPS()->getLayerSetLayerIdList(layerSetIdxForOutputLayerSet, kk))
    2786                       {
    2787                           chkAssert=1;
    2788                       }
    2789                   }
    2790                   if(chkAssert)
    2791                   {
    2792                       // There may be something wrong here (layer id assumed to be layer idx?)
    2793                       assert(rps->getNumberOfNegativePictures() <= rpcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii , rpcSlice->getLayerId() , rpcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)));
    2794                       assert(rps->getNumberOfPositivePictures() <= rpcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii , rpcSlice->getLayerId() , rpcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)) - rps->getNumberOfNegativePictures());
    2795                       assert((rps->getNumberOfPositivePictures() + rps->getNumberOfNegativePictures() + rps->getNumberOfLongtermPictures()) <= rpcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii , rpcSlice->getLayerId() , rpcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)));
    2796                   }
    2797               }
    2798              
    2799              
     3426            rpcSlice->setInterLayerPredLayerIdc(i,i);
    28003427          }
    2801           if(rpcSlice->getLayerId() == 0)
     3428        }
     3429        else
     3430        {
     3431          for(Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
    28023432          {
    2803               assert(rps->getNumberOfNegativePictures() <= rpcSlice->getSPS()->getMaxDecPicBuffering(rpcSlice->getSPS()->getMaxTLayers()-1) );
    2804               assert(rps->getNumberOfPositivePictures() <= rpcSlice->getSPS()->getMaxDecPicBuffering(rpcSlice->getSPS()->getMaxTLayers()-1) -rps->getNumberOfNegativePictures());
    2805               assert((rps->getNumberOfPositivePictures() + rps->getNumberOfNegativePictures() + rps->getNumberOfLongtermPictures()) <= rpcSlice->getSPS()->getMaxDecPicBuffering(rpcSlice->getSPS()->getMaxTLayers()-1));
     3433            READ_CODE( numBits,uiCode,"inter_layer_pred_layer_idc[i]" );
     3434            rpcSlice->setInterLayerPredLayerIdc(uiCode,i);
    28063435          }
    2807 #endif
    2808       if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
    2809         || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
    2810         || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
    2811       {
    2812         // In the case of BLA picture types, rps data is read from slice header but ignored
    2813         rps = rpcSlice->getLocalRPS();
    2814         rps->setNumberOfNegativePictures(0);
    2815         rps->setNumberOfPositivePictures(0);
    2816         rps->setNumberOfLongtermPictures(0);
    2817         rps->setNumberOfPictures(0);
    2818         rpcSlice->setRPS(rps);
    2819       }
    2820       if (rpcSlice->getSPS()->getTMVPFlagsPresent())
    2821       {
    2822         READ_FLAG( uiCode, "slice_temporal_mvp_enable_flag" );
    2823         rpcSlice->setEnableTMVPFlag( uiCode == 1 ? true : false );
     3436        }
    28243437      }
    28253438      else
    28263439      {
    2827         rpcSlice->setEnableTMVPFlag(false);
    2828       }
    2829 #if N0065_LAYER_POC_ALIGNMENT && !SHM_FIX7
    2830     }
    2831 #endif
    2832     }
    2833 
    2834 #if SVC_EXTENSION
    2835     rpcSlice->setActiveNumILRRefIdx(0);
    2836     if((rpcSlice->getLayerId() > 0) && !(rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag()) && (rpcSlice->getNumILRRefIdx() > 0) )
    2837     {
    2838       READ_FLAG(uiCode,"inter_layer_pred_enabled_flag");
    2839       rpcSlice->setInterLayerPredEnabledFlag(uiCode);
    2840       if( rpcSlice->getInterLayerPredEnabledFlag())
    2841       {
    2842         if(rpcSlice->getNumILRRefIdx() > 1)
    2843         {
    2844           Int numBits = 1;
    2845           while ((1 << numBits) < rpcSlice->getNumILRRefIdx())
    2846           {
    2847             numBits++;
    2848           }
    2849           if( !rpcSlice->getVPS()->getMaxOneActiveRefLayerFlag())
    2850           {
    2851             READ_CODE( numBits, uiCode,"num_inter_layer_ref_pics_minus1" );
    2852             rpcSlice->setActiveNumILRRefIdx(uiCode + 1);
    2853           }
    2854           else
    2855           {
    2856 #if P0079_DERIVE_NUMACTIVE_REF_PICS
    2857             for( Int i = 0; i < rpcSlice->getNumILRRefIdx(); i++ )
    2858             {
    2859 #if Q0060_MAX_TID_REF_EQUAL_TO_ZERO
    2860               if((rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(rpcSlice->getVPS()->getLayerIdInVps(i),rpcSlice->getLayerId()) >  rpcSlice->getTLayer() || rpcSlice->getTLayer()==0) &&
    2861                 (rpcSlice->getVPS()->getMaxTSLayersMinus1(rpcSlice->getVPS()->getLayerIdInVps(i)) >=  rpcSlice->getTLayer()) )
    2862 #else
    2863               if(rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(rpcSlice->getVPS()->getLayerIdInVps(i),rpcSlice->getLayerId()) >  rpcSlice->getTLayer() &&
    2864                 (rpcSlice->getVPS()->getMaxTSLayersMinus1(rpcSlice->getVPS()->getLayerIdInVps(i)) >=  rpcSlice->getTLayer()) )
    2865 #endif
    2866               {         
    2867                 rpcSlice->setActiveNumILRRefIdx(1);
    2868                 break;
    2869               }
    2870             }
    2871 #else
    2872             rpcSlice->setActiveNumILRRefIdx(1);
    2873 #endif
    2874           }
    2875 
    2876           if( rpcSlice->getActiveNumILRRefIdx() == rpcSlice->getNumILRRefIdx() )
    2877           {
    2878             for( Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
    2879             {
    2880               rpcSlice->setInterLayerPredLayerIdc(i,i);
    2881             }
    2882           }
    2883           else
    2884           {
    2885             for(Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
    2886             {
    2887               READ_CODE( numBits,uiCode,"inter_layer_pred_layer_idc[i]" );
    2888               rpcSlice->setInterLayerPredLayerIdc(uiCode,i);
    2889             }
    2890           }
    2891         }
    2892         else
    2893         {
    28943440#if O0225_TID_BASED_IL_RPS_DERIV && TSLAYERS_IL_RPS
    28953441#if Q0060_MAX_TID_REF_EQUAL_TO_ZERO
    2896           if((rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(0,rpcSlice->getLayerId()) >  rpcSlice->getTLayer() || rpcSlice->getTLayer()==0) &&
    2897             (rpcSlice->getVPS()->getMaxTSLayersMinus1(0) >=  rpcSlice->getTLayer()) )
    2898 #else
    2899           if( (rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(0,rpcSlice->getLayerId()) >  rpcSlice->getTLayer()) &&
    2900              (rpcSlice->getVPS()->getMaxTSLayersMinus1(0) >=  rpcSlice->getTLayer()) )
     3442        if((rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(0,rpcSlice->getLayerId()) >  rpcSlice->getTLayer() || rpcSlice->getTLayer()==0) &&
     3443          (rpcSlice->getVPS()->getMaxTSLayersMinus1(0) >=  rpcSlice->getTLayer()) )
     3444#else
     3445        if( (rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(0,rpcSlice->getLayerId()) >  rpcSlice->getTLayer()) &&
     3446          (rpcSlice->getVPS()->getMaxTSLayersMinus1(0) >=  rpcSlice->getTLayer()) )
    29013447#endif
    29023448        {
     
    29073453        }
    29083454#endif
    2909         }
    2910       }
    2911     }
    2912     else if( rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag() == true &&  (rpcSlice->getLayerId() > 0 ))
    2913     {
    2914       rpcSlice->setInterLayerPredEnabledFlag(true);
     3455      }
     3456    }
     3457  }
     3458  else if( rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag() == true &&  (rpcSlice->getLayerId() > 0 ))
     3459  {
     3460    rpcSlice->setInterLayerPredEnabledFlag(true);
    29153461
    29163462#if O0225_TID_BASED_IL_RPS_DERIV && TSLAYERS_IL_RPS
    2917       Int   numRefLayerPics = 0;
    2918       Int   i = 0;
    2919       Int   refLayerPicIdc  [MAX_VPS_LAYER_ID_PLUS1];
    2920       for(i = 0, numRefLayerPics = 0;  i < rpcSlice->getNumILRRefIdx(); i++ )
    2921       {
     3463    Int   numRefLayerPics = 0;
     3464    Int   i = 0;
     3465    Int   refLayerPicIdc  [MAX_VPS_LAYER_ID_PLUS1];
     3466    for(i = 0, numRefLayerPics = 0;  i < rpcSlice->getNumILRRefIdx(); i++ )
     3467    {
    29223468#if Q0060_MAX_TID_REF_EQUAL_TO_ZERO
    2923         if((rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(rpcSlice->getVPS()->getLayerIdInVps(i),rpcSlice->getLayerId()) >  rpcSlice->getTLayer() || rpcSlice->getTLayer()==0) &&
    2924           (rpcSlice->getVPS()->getMaxTSLayersMinus1(rpcSlice->getVPS()->getLayerIdInVps(i)) >=  rpcSlice->getTLayer()) )
     3469      if((rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(rpcSlice->getVPS()->getLayerIdInVps(i),rpcSlice->getLayerId()) >  rpcSlice->getTLayer() || rpcSlice->getTLayer()==0) &&
     3470        (rpcSlice->getVPS()->getMaxTSLayersMinus1(rpcSlice->getVPS()->getLayerIdInVps(i)) >=  rpcSlice->getTLayer()) )
    29253471#else
    2926         if(rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(rpcSlice->getVPS()->getLayerIdInVps(i),rpcSlice->getLayerId()) >  rpcSlice->getTLayer() &&
    2927            (rpcSlice->getVPS()->getMaxTSLayersMinus1(rpcSlice->getVPS()->getLayerIdInVps(i)) >=  rpcSlice->getTLayer()) )
     3472      if(rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(rpcSlice->getVPS()->getLayerIdInVps(i),rpcSlice->getLayerId()) >  rpcSlice->getTLayer() &&
     3473        (rpcSlice->getVPS()->getMaxTSLayersMinus1(rpcSlice->getVPS()->getLayerIdInVps(i)) >=  rpcSlice->getTLayer()) )
    29283474#endif
    2929         {         
    2930           refLayerPicIdc[ numRefLayerPics++ ] = i;
    2931         }
    2932       }
    2933       rpcSlice->setActiveNumILRRefIdx(numRefLayerPics);
    2934       for( i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
    2935       {
    2936         rpcSlice->setInterLayerPredLayerIdc(refLayerPicIdc[i],i);
    2937       }     
    2938 #else
    2939       rpcSlice->setActiveNumILRRefIdx(rpcSlice->getNumILRRefIdx());
    2940       for( Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
    2941       {
    2942         rpcSlice->setInterLayerPredLayerIdc(i,i);
    2943       }
     3475      {         
     3476        refLayerPicIdc[ numRefLayerPics++ ] = i;
     3477      }
     3478    }
     3479    rpcSlice->setActiveNumILRRefIdx(numRefLayerPics);
     3480    for( i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
     3481    {
     3482      rpcSlice->setInterLayerPredLayerIdc(refLayerPicIdc[i],i);
     3483    }     
     3484#else
     3485    rpcSlice->setActiveNumILRRefIdx(rpcSlice->getNumILRRefIdx());
     3486    for( Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
     3487    {
     3488      rpcSlice->setInterLayerPredLayerIdc(i,i);
     3489    }
    29443490#endif
    2945     }
     3491  }
    29463492#if P0312_VERT_PHASE_ADJ
    29473493    for(Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
    29483494    {
    29493495      UInt refLayerIdc = rpcSlice->getInterLayerPredLayerIdc(i);
     3496#if !MOVE_SCALED_OFFSET_TO_PPS
    29503497      if( rpcSlice->getSPS()->getVertPhasePositionEnableFlag(refLayerIdc) )
     3498#else
     3499      if( rpcSlice->getPPS()->getVertPhasePositionEnableFlag(refLayerIdc) )
     3500#endif
    29513501      {
    29523502        READ_FLAG( uiCode, "vert_phase_position_flag" ); rpcSlice->setVertPhasePositionFlag( uiCode? true : false, refLayerIdc );
    29533503      }
    2954     }
     3504  }
    29553505#endif
    29563506#endif //SVC_EXTENSION
    29573507
    2958     if(sps->getUseSAO())
    2959     {
    2960       READ_FLAG(uiCode, "slice_sao_luma_flag");  rpcSlice->setSaoEnabledFlag((Bool)uiCode);
     3508  if(sps->getUseSAO())
     3509  {
     3510    READ_FLAG(uiCode, "slice_sao_luma_flag");  rpcSlice->setSaoEnabledFlag((Bool)uiCode);
    29613511#if AUXILIARY_PICTURES
    2962       ChromaFormat format;
     3512    ChromaFormat format;
    29633513#if REPN_FORMAT_IN_VPS
    29643514#if O0096_REP_FORMAT_INDEX
    2965       if( sps->getLayerId() == 0 )
    2966       {
    2967         format = sps->getChromaFormatIdc();
    2968       }
    2969       else
    2970       {
    2971         format = rpcSlice->getVPS()->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : rpcSlice->getVPS()->getVpsRepFormatIdx(sps->getLayerId()) )->getChromaFormatVpsIdc();
     3515    if( sps->getLayerId() == 0 )
     3516    {
     3517      format = sps->getChromaFormatIdc();
     3518    }
     3519    else
     3520    {
     3521      format = rpcSlice->getVPS()->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : rpcSlice->getVPS()->getVpsRepFormatIdx(sps->getLayerId()) )->getChromaFormatVpsIdc();
    29723522#if Q0195_REP_FORMAT_CLEANUP
    2973          assert( (sps->getUpdateRepFormatFlag()==false && rpcSlice->getVPS()->getVpsNumRepFormats()==1) || rpcSlice->getVPS()->getVpsNumRepFormats() > 1 ); //conformance check
    2974 #endif
    2975       }
    2976 #else
    2977       if( ( sps->getLayerId() == 0 ) || sps->getUpdateRepFormatFlag() )
    2978       {
    2979         format = sps->getChromaFormatIdc();
    2980       }
    2981       else
    2982       {
    2983         format = rpcSlice->getVPS()->getVpsRepFormat( rpcSlice->getVPS()->getVpsRepFormatIdx(sps->getLayerId()) )->getChromaFormatVpsIdc();
    2984       }
    2985 #endif
    2986 #else
     3523      assert( (sps->getUpdateRepFormatFlag()==false && rpcSlice->getVPS()->getVpsNumRepFormats()==1) || rpcSlice->getVPS()->getVpsNumRepFormats() > 1 ); //conformance check
     3524#endif
     3525    }
     3526#else
     3527    if( ( sps->getLayerId() == 0 ) || sps->getUpdateRepFormatFlag() )
     3528    {
    29873529      format = sps->getChromaFormatIdc();
    2988 #endif
    2989       if (format != CHROMA_400)
    2990       {
     3530    }
     3531    else
     3532    {
     3533      format = rpcSlice->getVPS()->getVpsRepFormat( rpcSlice->getVPS()->getVpsRepFormatIdx(sps->getLayerId()) )->getChromaFormatVpsIdc();
     3534    }
     3535#endif
     3536#else
     3537    format = sps->getChromaFormatIdc();
     3538#endif
     3539    if (format != CHROMA_400)
     3540    {
    29913541#endif
    29923542      READ_FLAG(uiCode, "slice_sao_chroma_flag");  rpcSlice->setSaoEnabledFlagChroma((Bool)uiCode);
    29933543#if AUXILIARY_PICTURES
     3544    }
     3545    else
     3546    {
     3547      rpcSlice->setSaoEnabledFlagChroma(false);
     3548    }
     3549#endif
     3550  }
     3551
     3552  if (rpcSlice->getIdrPicFlag())
     3553  {
     3554    rpcSlice->setEnableTMVPFlag(false);
     3555  }
     3556  if (!rpcSlice->isIntra())
     3557  {
     3558
     3559    READ_FLAG( uiCode, "num_ref_idx_active_override_flag");
     3560    if (uiCode)
     3561    {
     3562      READ_UVLC (uiCode, "num_ref_idx_l0_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_0, uiCode + 1 );
     3563      if (rpcSlice->isInterB())
     3564      {
     3565        READ_UVLC (uiCode, "num_ref_idx_l1_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_1, uiCode + 1 );
    29943566      }
    29953567      else
    29963568      {
    2997         rpcSlice->setSaoEnabledFlagChroma(false);
    2998       }
    2999 #endif
    3000     }
    3001 
    3002     if (rpcSlice->getIdrPicFlag())
    3003     {
    3004       rpcSlice->setEnableTMVPFlag(false);
    3005     }
    3006     if (!rpcSlice->isIntra())
    3007     {
    3008 
    3009       READ_FLAG( uiCode, "num_ref_idx_active_override_flag");
    3010       if (uiCode)
    3011       {
    3012         READ_UVLC (uiCode, "num_ref_idx_l0_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_0, uiCode + 1 );
    3013         if (rpcSlice->isInterB())
    3014         {
    3015           READ_UVLC (uiCode, "num_ref_idx_l1_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_1, uiCode + 1 );
    3016         }
    3017         else
    3018         {
    3019           rpcSlice->setNumRefIdx(REF_PIC_LIST_1, 0);
    3020         }
     3569        rpcSlice->setNumRefIdx(REF_PIC_LIST_1, 0);
     3570      }
     3571    }
     3572    else
     3573    {
     3574      rpcSlice->setNumRefIdx(REF_PIC_LIST_0, rpcSlice->getPPS()->getNumRefIdxL0DefaultActive());
     3575      if (rpcSlice->isInterB())
     3576      {
     3577        rpcSlice->setNumRefIdx(REF_PIC_LIST_1, rpcSlice->getPPS()->getNumRefIdxL1DefaultActive());
    30213578      }
    30223579      else
    30233580      {
    3024         rpcSlice->setNumRefIdx(REF_PIC_LIST_0, rpcSlice->getPPS()->getNumRefIdxL0DefaultActive());
    3025         if (rpcSlice->isInterB())
    3026         {
    3027           rpcSlice->setNumRefIdx(REF_PIC_LIST_1, rpcSlice->getPPS()->getNumRefIdxL1DefaultActive());
    3028         }
    3029         else
    3030         {
    3031           rpcSlice->setNumRefIdx(REF_PIC_LIST_1,0);
    3032         }
    3033       }
    3034     }
    3035     // }
    3036     TComRefPicListModification* refPicListModification = rpcSlice->getRefPicListModification();
    3037     if(!rpcSlice->isIntra())
    3038     {
    3039       if( !rpcSlice->getPPS()->getListsModificationPresentFlag() || rpcSlice->getNumRpsCurrTempList() <= 1 )
    3040       {
    3041         refPicListModification->setRefPicListModificationFlagL0( 0 );
     3581        rpcSlice->setNumRefIdx(REF_PIC_LIST_1,0);
     3582      }
     3583    }
     3584  }
     3585  // }
     3586  TComRefPicListModification* refPicListModification = rpcSlice->getRefPicListModification();
     3587  if(!rpcSlice->isIntra())
     3588  {
     3589    if( !rpcSlice->getPPS()->getListsModificationPresentFlag() || rpcSlice->getNumRpsCurrTempList() <= 1 )
     3590    {
     3591      refPicListModification->setRefPicListModificationFlagL0( 0 );
     3592    }
     3593    else
     3594    {
     3595      READ_FLAG( uiCode, "ref_pic_list_modification_flag_l0" ); refPicListModification->setRefPicListModificationFlagL0( uiCode ? 1 : 0 );
     3596    }
     3597
     3598    if(refPicListModification->getRefPicListModificationFlagL0())
     3599    {
     3600      uiCode = 0;
     3601      Int i = 0;
     3602      Int numRpsCurrTempList0 = rpcSlice->getNumRpsCurrTempList();
     3603      if ( numRpsCurrTempList0 > 1 )
     3604      {
     3605        Int length = 1;
     3606        numRpsCurrTempList0 --;
     3607        while ( numRpsCurrTempList0 >>= 1)
     3608        {
     3609          length ++;
     3610        }
     3611        for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
     3612        {
     3613          READ_CODE( length, uiCode, "list_entry_l0" );
     3614          refPicListModification->setRefPicSetIdxL0(i, uiCode );
     3615        }
    30423616      }
    30433617      else
    30443618      {
    3045         READ_FLAG( uiCode, "ref_pic_list_modification_flag_l0" ); refPicListModification->setRefPicListModificationFlagL0( uiCode ? 1 : 0 );
    3046       }
    3047 
    3048       if(refPicListModification->getRefPicListModificationFlagL0())
    3049       {
    3050         uiCode = 0;
    3051         Int i = 0;
    3052         Int numRpsCurrTempList0 = rpcSlice->getNumRpsCurrTempList();
    3053         if ( numRpsCurrTempList0 > 1 )
    3054         {
    3055           Int length = 1;
    3056           numRpsCurrTempList0 --;
    3057           while ( numRpsCurrTempList0 >>= 1)
    3058           {
    3059             length ++;
    3060           }
    3061           for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
    3062           {
    3063             READ_CODE( length, uiCode, "list_entry_l0" );
    3064             refPicListModification->setRefPicSetIdxL0(i, uiCode );
    3065           }
    3066         }
    3067         else
    3068         {
    3069           for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
    3070           {
    3071             refPicListModification->setRefPicSetIdxL0(i, 0 );
    3072           }
    3073         }
    3074       }
     3619        for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
     3620        {
     3621          refPicListModification->setRefPicSetIdxL0(i, 0 );
     3622        }
     3623      }
     3624    }
     3625  }
     3626  else
     3627  {
     3628    refPicListModification->setRefPicListModificationFlagL0(0);
     3629  }
     3630  if(rpcSlice->isInterB())
     3631  {
     3632    if( !rpcSlice->getPPS()->getListsModificationPresentFlag() || rpcSlice->getNumRpsCurrTempList() <= 1 )
     3633    {
     3634      refPicListModification->setRefPicListModificationFlagL1( 0 );
    30753635    }
    30763636    else
    30773637    {
    3078       refPicListModification->setRefPicListModificationFlagL0(0);
    3079     }
    3080     if(rpcSlice->isInterB())
    3081     {
    3082       if( !rpcSlice->getPPS()->getListsModificationPresentFlag() || rpcSlice->getNumRpsCurrTempList() <= 1 )
    3083       {
    3084         refPicListModification->setRefPicListModificationFlagL1( 0 );
     3638      READ_FLAG( uiCode, "ref_pic_list_modification_flag_l1" ); refPicListModification->setRefPicListModificationFlagL1( uiCode ? 1 : 0 );
     3639    }
     3640    if(refPicListModification->getRefPicListModificationFlagL1())
     3641    {
     3642      uiCode = 0;
     3643      Int i = 0;
     3644      Int numRpsCurrTempList1 = rpcSlice->getNumRpsCurrTempList();
     3645      if ( numRpsCurrTempList1 > 1 )
     3646      {
     3647        Int length = 1;
     3648        numRpsCurrTempList1 --;
     3649        while ( numRpsCurrTempList1 >>= 1)
     3650        {
     3651          length ++;
     3652        }
     3653        for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
     3654        {
     3655          READ_CODE( length, uiCode, "list_entry_l1" );
     3656          refPicListModification->setRefPicSetIdxL1(i, uiCode );
     3657        }
    30853658      }
    30863659      else
    30873660      {
    3088         READ_FLAG( uiCode, "ref_pic_list_modification_flag_l1" ); refPicListModification->setRefPicListModificationFlagL1( uiCode ? 1 : 0 );
    3089       }
    3090       if(refPicListModification->getRefPicListModificationFlagL1())
    3091       {
    3092         uiCode = 0;
    3093         Int i = 0;
    3094         Int numRpsCurrTempList1 = rpcSlice->getNumRpsCurrTempList();
    3095         if ( numRpsCurrTempList1 > 1 )
    3096         {
    3097           Int length = 1;
    3098           numRpsCurrTempList1 --;
    3099           while ( numRpsCurrTempList1 >>= 1)
    3100           {
    3101             length ++;
    3102           }
    3103           for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
    3104           {
    3105             READ_CODE( length, uiCode, "list_entry_l1" );
    3106             refPicListModification->setRefPicSetIdxL1(i, uiCode );
    3107           }
    3108         }
    3109         else
    3110         {
    3111           for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
    3112           {
    3113             refPicListModification->setRefPicSetIdxL1(i, 0 );
    3114           }
    3115         }
    3116       }
     3661        for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
     3662        {
     3663          refPicListModification->setRefPicSetIdxL1(i, 0 );
     3664        }
     3665      }
     3666    }
     3667  }
     3668  else
     3669  {
     3670    refPicListModification->setRefPicListModificationFlagL1(0);
     3671  }
     3672  if (rpcSlice->isInterB())
     3673  {
     3674    READ_FLAG( uiCode, "mvd_l1_zero_flag" );       rpcSlice->setMvdL1ZeroFlag( (uiCode ? true : false) );
     3675  }
     3676
     3677  rpcSlice->setCabacInitFlag( false ); // default
     3678  if(pps->getCabacInitPresentFlag() && !rpcSlice->isIntra())
     3679  {
     3680    READ_FLAG(uiCode, "cabac_init_flag");
     3681    rpcSlice->setCabacInitFlag( uiCode ? true : false );
     3682  }
     3683
     3684  if ( rpcSlice->getEnableTMVPFlag() )
     3685  {
     3686#if SVC_EXTENSION && REF_IDX_MFM
     3687    // set motion mapping flag
     3688    rpcSlice->setMFMEnabledFlag( ( rpcSlice->getNumMotionPredRefLayers() > 0 && rpcSlice->getActiveNumILRRefIdx() && !rpcSlice->isIntra() ) ? true : false );
     3689#endif
     3690    if ( rpcSlice->getSliceType() == B_SLICE )
     3691    {
     3692      READ_FLAG( uiCode, "collocated_from_l0_flag" );
     3693      rpcSlice->setColFromL0Flag(uiCode);
    31173694    }
    31183695    else
    31193696    {
    3120       refPicListModification->setRefPicListModificationFlagL1(0);
    3121     }
    3122     if (rpcSlice->isInterB())
    3123     {
    3124       READ_FLAG( uiCode, "mvd_l1_zero_flag" );       rpcSlice->setMvdL1ZeroFlag( (uiCode ? true : false) );
    3125     }
    3126 
    3127     rpcSlice->setCabacInitFlag( false ); // default
    3128     if(pps->getCabacInitPresentFlag() && !rpcSlice->isIntra())
    3129     {
    3130       READ_FLAG(uiCode, "cabac_init_flag");
    3131       rpcSlice->setCabacInitFlag( uiCode ? true : false );
    3132     }
    3133 
    3134     if ( rpcSlice->getEnableTMVPFlag() )
    3135     {
    3136 #if SVC_EXTENSION && REF_IDX_MFM
    3137       // set motion mapping flag
    3138       rpcSlice->setMFMEnabledFlag( ( rpcSlice->getNumMotionPredRefLayers() > 0 && rpcSlice->getActiveNumILRRefIdx() && !rpcSlice->isIntra() ) ? true : false );
    3139 #endif
    3140       if ( rpcSlice->getSliceType() == B_SLICE )
    3141       {
    3142         READ_FLAG( uiCode, "collocated_from_l0_flag" );
    3143         rpcSlice->setColFromL0Flag(uiCode);
    3144       }
    3145       else
    3146       {
    3147         rpcSlice->setColFromL0Flag( 1 );
    3148       }
    3149 
    3150       if ( rpcSlice->getSliceType() != I_SLICE &&
    3151           ((rpcSlice->getColFromL0Flag() == 1 && rpcSlice->getNumRefIdx(REF_PIC_LIST_0) > 1)||
    3152            (rpcSlice->getColFromL0Flag() == 0 && rpcSlice->getNumRefIdx(REF_PIC_LIST_1) > 1)))
    3153       {
    3154         READ_UVLC( uiCode, "collocated_ref_idx" );
    3155         rpcSlice->setColRefIdx(uiCode);
    3156       }
    3157       else
    3158       {
    3159         rpcSlice->setColRefIdx(0);
    3160       }
    3161     }
    3162     if ( (pps->getUseWP() && rpcSlice->getSliceType()==P_SLICE) || (pps->getWPBiPred() && rpcSlice->getSliceType()==B_SLICE) )
    3163     {
    3164       xParsePredWeightTable(rpcSlice);
    3165       rpcSlice->initWpScaling();
    3166     }
    3167     if (!rpcSlice->isIntra())
    3168     {
    3169       READ_UVLC( uiCode, "five_minus_max_num_merge_cand");
    3170       rpcSlice->setMaxNumMergeCand(MRG_MAX_NUM_CANDS - uiCode);
    3171     }
    3172 
    3173     READ_SVLC( iCode, "slice_qp_delta" );
    3174     rpcSlice->setSliceQp (26 + pps->getPicInitQPMinus26() + iCode);
     3697      rpcSlice->setColFromL0Flag( 1 );
     3698    }
     3699
     3700    if ( rpcSlice->getSliceType() != I_SLICE &&
     3701      ((rpcSlice->getColFromL0Flag() == 1 && rpcSlice->getNumRefIdx(REF_PIC_LIST_0) > 1)||
     3702      (rpcSlice->getColFromL0Flag() == 0 && rpcSlice->getNumRefIdx(REF_PIC_LIST_1) > 1)))
     3703    {
     3704      READ_UVLC( uiCode, "collocated_ref_idx" );
     3705      rpcSlice->setColRefIdx(uiCode);
     3706    }
     3707    else
     3708    {
     3709      rpcSlice->setColRefIdx(0);
     3710    }
     3711  }
     3712  if ( (pps->getUseWP() && rpcSlice->getSliceType()==P_SLICE) || (pps->getWPBiPred() && rpcSlice->getSliceType()==B_SLICE) )
     3713  {
     3714    xParsePredWeightTable(rpcSlice);
     3715    rpcSlice->initWpScaling();
     3716  }
     3717  if (!rpcSlice->isIntra())
     3718  {
     3719    READ_UVLC( uiCode, "five_minus_max_num_merge_cand");
     3720    rpcSlice->setMaxNumMergeCand(MRG_MAX_NUM_CANDS - uiCode);
     3721  }
     3722
     3723  READ_SVLC( iCode, "slice_qp_delta" );
     3724  rpcSlice->setSliceQp (26 + pps->getPicInitQPMinus26() + iCode);
    31753725
    31763726#if REPN_FORMAT_IN_VPS
    31773727#if O0194_DIFFERENT_BITDEPTH_EL_BL
    3178     g_bitDepthYLayer[rpcSlice->getLayerId()] = rpcSlice->getBitDepthY();
    3179     g_bitDepthCLayer[rpcSlice->getLayerId()] = rpcSlice->getBitDepthC();
    3180 #endif
    3181     assert( rpcSlice->getSliceQp() >= -rpcSlice->getQpBDOffsetY() );
    3182 #else
    3183     assert( rpcSlice->getSliceQp() >= -sps->getQpBDOffsetY() );
    3184 #endif
    3185     assert( rpcSlice->getSliceQp() <=  51 );
    3186 
    3187     if (rpcSlice->getPPS()->getSliceChromaQpFlag())
    3188     {
    3189       READ_SVLC( iCode, "slice_qp_delta_cb" );
    3190       rpcSlice->setSliceQpDeltaCb( iCode );
    3191       assert( rpcSlice->getSliceQpDeltaCb() >= -12 );
    3192       assert( rpcSlice->getSliceQpDeltaCb() <=  12 );
    3193       assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) >= -12 );
    3194       assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) <=  12 );
    3195 
    3196       READ_SVLC( iCode, "slice_qp_delta_cr" );
    3197       rpcSlice->setSliceQpDeltaCr( iCode );
    3198       assert( rpcSlice->getSliceQpDeltaCr() >= -12 );
    3199       assert( rpcSlice->getSliceQpDeltaCr() <=  12 );
    3200       assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) >= -12 );
    3201       assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) <=  12 );
    3202     }
    3203 
    3204     if (rpcSlice->getPPS()->getDeblockingFilterControlPresentFlag())
    3205     {
    3206       if(rpcSlice->getPPS()->getDeblockingFilterOverrideEnabledFlag())
    3207       {
    3208         READ_FLAG ( uiCode, "deblocking_filter_override_flag" );        rpcSlice->setDeblockingFilterOverrideFlag(uiCode ? true : false);
     3728  g_bitDepthYLayer[rpcSlice->getLayerId()] = rpcSlice->getBitDepthY();
     3729  g_bitDepthCLayer[rpcSlice->getLayerId()] = rpcSlice->getBitDepthC();
     3730#endif
     3731  assert( rpcSlice->getSliceQp() >= -rpcSlice->getQpBDOffsetY() );
     3732#else
     3733  assert( rpcSlice->getSliceQp() >= -sps->getQpBDOffsetY() );
     3734#endif
     3735  assert( rpcSlice->getSliceQp() <=  51 );
     3736
     3737  if (rpcSlice->getPPS()->getSliceChromaQpFlag())
     3738  {
     3739    READ_SVLC( iCode, "slice_qp_delta_cb" );
     3740    rpcSlice->setSliceQpDeltaCb( iCode );
     3741    assert( rpcSlice->getSliceQpDeltaCb() >= -12 );
     3742    assert( rpcSlice->getSliceQpDeltaCb() <=  12 );
     3743    assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) >= -12 );
     3744    assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) <=  12 );
     3745
     3746    READ_SVLC( iCode, "slice_qp_delta_cr" );
     3747    rpcSlice->setSliceQpDeltaCr( iCode );
     3748    assert( rpcSlice->getSliceQpDeltaCr() >= -12 );
     3749    assert( rpcSlice->getSliceQpDeltaCr() <=  12 );
     3750    assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) >= -12 );
     3751    assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) <=  12 );
     3752  }
     3753
     3754  if (rpcSlice->getPPS()->getDeblockingFilterControlPresentFlag())
     3755  {
     3756    if(rpcSlice->getPPS()->getDeblockingFilterOverrideEnabledFlag())
     3757    {
     3758      READ_FLAG ( uiCode, "deblocking_filter_override_flag" );        rpcSlice->setDeblockingFilterOverrideFlag(uiCode ? true : false);
     3759    }
     3760    else
     3761    {
     3762      rpcSlice->setDeblockingFilterOverrideFlag(0);
     3763    }
     3764    if(rpcSlice->getDeblockingFilterOverrideFlag())
     3765    {
     3766      READ_FLAG ( uiCode, "slice_disable_deblocking_filter_flag" );   rpcSlice->setDeblockingFilterDisable(uiCode ? 1 : 0);
     3767      if(!rpcSlice->getDeblockingFilterDisable())
     3768      {
     3769        READ_SVLC( iCode, "slice_beta_offset_div2" );                       rpcSlice->setDeblockingFilterBetaOffsetDiv2(iCode);
     3770        assert(rpcSlice->getDeblockingFilterBetaOffsetDiv2() >= -6 &&
     3771          rpcSlice->getDeblockingFilterBetaOffsetDiv2() <=  6);
     3772        READ_SVLC( iCode, "slice_tc_offset_div2" );                         rpcSlice->setDeblockingFilterTcOffsetDiv2(iCode);
     3773        assert(rpcSlice->getDeblockingFilterTcOffsetDiv2() >= -6 &&
     3774          rpcSlice->getDeblockingFilterTcOffsetDiv2() <=  6);
     3775      }
     3776    }
     3777    else
     3778    {
     3779      rpcSlice->setDeblockingFilterDisable   ( rpcSlice->getPPS()->getPicDisableDeblockingFilterFlag() );
     3780      rpcSlice->setDeblockingFilterBetaOffsetDiv2( rpcSlice->getPPS()->getDeblockingFilterBetaOffsetDiv2() );
     3781      rpcSlice->setDeblockingFilterTcOffsetDiv2  ( rpcSlice->getPPS()->getDeblockingFilterTcOffsetDiv2() );
     3782    }
     3783  }
     3784  else
     3785  {
     3786    rpcSlice->setDeblockingFilterDisable       ( false );
     3787    rpcSlice->setDeblockingFilterBetaOffsetDiv2( 0 );
     3788    rpcSlice->setDeblockingFilterTcOffsetDiv2  ( 0 );
     3789  }
     3790
     3791  Bool isSAOEnabled = (!rpcSlice->getSPS()->getUseSAO())?(false):(rpcSlice->getSaoEnabledFlag()||rpcSlice->getSaoEnabledFlagChroma());
     3792  Bool isDBFEnabled = (!rpcSlice->getDeblockingFilterDisable());
     3793
     3794  if(rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag() && ( isSAOEnabled || isDBFEnabled ))
     3795  {
     3796    READ_FLAG( uiCode, "slice_loop_filter_across_slices_enabled_flag");
     3797  }
     3798  else
     3799  {
     3800    uiCode = rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag()?1:0;
     3801  }
     3802  rpcSlice->setLFCrossSliceBoundaryFlag( (uiCode==1)?true:false);
     3803
     3804}
     3805
     3806UInt *entryPointOffset          = NULL;
     3807UInt numEntryPointOffsets, offsetLenMinus1;
     3808if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
     3809{
     3810  READ_UVLC(numEntryPointOffsets, "num_entry_point_offsets"); rpcSlice->setNumEntryPointOffsets ( numEntryPointOffsets );
     3811  if (numEntryPointOffsets>0)
     3812  {
     3813    READ_UVLC(offsetLenMinus1, "offset_len_minus1");
     3814  }
     3815  entryPointOffset = new UInt[numEntryPointOffsets];
     3816  for (UInt idx=0; idx<numEntryPointOffsets; idx++)
     3817  {
     3818    READ_CODE(offsetLenMinus1+1, uiCode, "entry_point_offset_minus1");
     3819    entryPointOffset[ idx ] = uiCode + 1;
     3820  }
     3821}
     3822else
     3823{
     3824  rpcSlice->setNumEntryPointOffsets ( 0 );
     3825}
     3826
     3827#if POC_RESET_IDC_SIGNALLING
     3828Int sliceHeaderExtensionLength = 0;
     3829if(pps->getSliceHeaderExtensionPresentFlag())
     3830{
     3831  READ_UVLC( uiCode, "slice_header_extension_length"); sliceHeaderExtensionLength = uiCode;
     3832}
     3833else
     3834{
     3835  sliceHeaderExtensionLength = 0;
     3836#if INFERENCE_POC_MSB_VAL_PRESENT
     3837  rpcSlice->setPocMsbValPresentFlag( false );
     3838#endif
     3839}
     3840UInt startBits = m_pcBitstream->getNumBitsRead();     // Start counter of # SH Extn bits
     3841if( sliceHeaderExtensionLength > 0 )
     3842{
     3843  if( rpcSlice->getPPS()->getPocResetInfoPresentFlag() )
     3844  {
     3845    READ_CODE( 2, uiCode,       "poc_reset_idc"); rpcSlice->setPocResetIdc(uiCode);
     3846#if POC_RESET_RESTRICTIONS
     3847    /* The value of poc_reset_idc shall not be equal to 1 or 2 for a RASL picture, a RADL picture,
     3848       a sub-layer non-reference picture, or a picture that has TemporalId greater than 0,
     3849       or a picture that has discardable_flag equal to 1. */
     3850    if( rpcSlice->getPocResetIdc() == 1 || rpcSlice->getPocResetIdc() == 2 )
     3851    {
     3852      assert( !rpcSlice->isRASL() );
     3853      assert( !rpcSlice->isRADL() );
     3854      assert( !rpcSlice->isSLNR() );
     3855      assert( rpcSlice->getTLayer() == 0 );
     3856      assert( rpcSlice->getDiscardableFlag() == 0 );
     3857    }
     3858
     3859    // The value of poc_reset_idc of a CRA or BLA picture shall be less than 3.
     3860    if( rpcSlice->getPocResetIdc() == 3)
     3861    {
     3862      assert( ! ( rpcSlice->isCRA() || rpcSlice->isBLA() ) );
     3863    }
     3864#endif
     3865  }
     3866  else
     3867  {
     3868    rpcSlice->setPocResetIdc( 0 );
     3869  }
     3870#if Q0142_POC_LSB_NOT_PRESENT
     3871  if ( rpcSlice->getVPS()->getPocLsbNotPresentFlag(rpcSlice->getLayerId()) && iPOClsb > 0 )
     3872  {
     3873    assert( rpcSlice->getPocResetIdc() != 2 );
     3874  }
     3875#endif
     3876  if( rpcSlice->getPocResetIdc() > 0 )
     3877  {
     3878    READ_CODE(6, uiCode,      "poc_reset_period_id"); rpcSlice->setPocResetPeriodId(uiCode);
     3879  }
     3880  else
     3881  {
     3882
     3883    rpcSlice->setPocResetPeriodId( 0 );
     3884  }
     3885
     3886  if (rpcSlice->getPocResetIdc() == 3)
     3887  {
     3888    READ_FLAG( uiCode,        "full_poc_reset_flag"); rpcSlice->setFullPocResetFlag((uiCode == 1) ? true : false);
     3889    READ_CODE(rpcSlice->getSPS()->getBitsForPOC(), uiCode,"poc_lsb_val"); rpcSlice->setPocLsbVal(uiCode);
     3890#if Q0142_POC_LSB_NOT_PRESENT
     3891    if ( rpcSlice->getVPS()->getPocLsbNotPresentFlag(rpcSlice->getLayerId()) && rpcSlice->getFullPocResetFlag() )
     3892    {
     3893      assert( rpcSlice->getPocLsbVal() == 0 );
     3894    }
     3895#endif
     3896  }
     3897
     3898  // Derive the value of PocMsbValRequiredFlag
     3899#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     3900  rpcSlice->setPocMsbValRequiredFlag( (rpcSlice->getCraPicFlag() || rpcSlice->getBlaPicFlag())
     3901                                      && (!rpcSlice->getVPS()->getVpsPocLsbAlignedFlag() ||
     3902                                         (rpcSlice->getVPS()->getVpsPocLsbAlignedFlag() && rpcSlice->getVPS()->getNumDirectRefLayers(rpcSlice->getLayerId()) == 0))
     3903                                    );
     3904#else
     3905  rpcSlice->setPocMsbValRequiredFlag( rpcSlice->getCraPicFlag() || rpcSlice->getBlaPicFlag() );
     3906#endif
     3907
     3908#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     3909  if (!rpcSlice->getPocMsbValRequiredFlag() && rpcSlice->getVPS()->getVpsPocLsbAlignedFlag())
     3910#else
     3911  if (!rpcSlice->getPocMsbValRequiredFlag() /* vps_poc_lsb_aligned_flag */)
     3912#endif
     3913  {
     3914#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     3915    READ_FLAG(uiCode, "poc_msb_cycle_val_present_flag"); rpcSlice->setPocMsbValPresentFlag(uiCode ? true : false);
     3916#else
     3917    READ_FLAG(uiCode, "poc_msb_val_present_flag"); rpcSlice->setPocMsbValPresentFlag(uiCode ? true : false);
     3918#endif
     3919  }
     3920  else
     3921  {
     3922#if POC_MSB_VAL_PRESENT_FLAG_SEM
     3923    if( sliceHeaderExtensionLength == 0 )
     3924    {
     3925      rpcSlice->setPocMsbValPresentFlag( false );
     3926    }
     3927    else if( rpcSlice->getPocMsbValRequiredFlag() )
     3928#else
     3929    if( rpcSlice->getPocMsbValRequiredFlag() )
     3930#endif
     3931    {
     3932      rpcSlice->setPocMsbValPresentFlag( true );
     3933    }
     3934    else
     3935    {
     3936      rpcSlice->setPocMsbValPresentFlag( false );
     3937    }
     3938  }
     3939
     3940#if !POC_RESET_IDC_DECODER
     3941  Int maxPocLsb  = 1 << rpcSlice->getSPS()->getBitsForPOC();
     3942#endif
     3943  if( rpcSlice->getPocMsbValPresentFlag() )
     3944  {
     3945#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     3946    READ_UVLC( uiCode,    "poc_msb_cycle_val");             rpcSlice->setPocMsbVal( uiCode );
     3947#else
     3948    READ_UVLC( uiCode,    "poc_msb_val");             rpcSlice->setPocMsbVal( uiCode );
     3949#endif
     3950
     3951#if !POC_RESET_IDC_DECODER
     3952    // Update POC of the slice based on this MSB val
     3953    Int pocLsb     = rpcSlice->getPOC() % maxPocLsb;
     3954    rpcSlice->setPOC((rpcSlice->getPocMsbVal() * maxPocLsb) + pocLsb);
     3955  }
     3956  else
     3957  {
     3958    rpcSlice->setPocMsbVal( rpcSlice->getPOC() / maxPocLsb );
     3959#endif
     3960  }
     3961
     3962  // Read remaining bits in the slice header extension.
     3963  UInt endBits = m_pcBitstream->getNumBitsRead();
     3964  Int counter = (endBits - startBits) % 8;
     3965  if( counter )
     3966  {
     3967    counter = 8 - counter;
     3968  }
     3969
     3970  while( counter )
     3971  {
     3972#if Q0146_SSH_EXT_DATA_BIT
     3973    READ_FLAG( uiCode, "slice_segment_header_extension_data_bit" );
     3974#else
     3975    READ_FLAG( uiCode, "slice_segment_header_extension_reserved_bit" ); assert( uiCode == 1 );
     3976#endif
     3977    counter--;
     3978  }
     3979}
     3980#else
     3981if(pps->getSliceHeaderExtensionPresentFlag())
     3982{
     3983  READ_UVLC(uiCode,"slice_header_extension_length");
     3984  for(Int i=0; i<uiCode; i++)
     3985  {
     3986    UInt ignore;
     3987    READ_CODE(8,ignore,"slice_header_extension_data_byte");
     3988  }
     3989}
     3990#endif
     3991m_pcBitstream->readByteAlignment();
     3992
     3993if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
     3994{
     3995  Int endOfSliceHeaderLocation = m_pcBitstream->getByteLocation();
     3996
     3997  // Adjust endOfSliceHeaderLocation to account for emulation prevention bytes in the slice segment header
     3998  for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
     3999  {
     4000    if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) < endOfSliceHeaderLocation )
     4001    {
     4002      endOfSliceHeaderLocation++;
     4003    }
     4004  }
     4005
     4006  Int  curEntryPointOffset     = 0;
     4007  Int  prevEntryPointOffset    = 0;
     4008  for (UInt idx=0; idx<numEntryPointOffsets; idx++)
     4009  {
     4010    curEntryPointOffset += entryPointOffset[ idx ];
     4011
     4012    Int emulationPreventionByteCount = 0;
     4013    for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
     4014    {
     4015      if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) >= ( prevEntryPointOffset + endOfSliceHeaderLocation ) &&
     4016        m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) <  ( curEntryPointOffset  + endOfSliceHeaderLocation ) )
     4017      {
     4018        emulationPreventionByteCount++;
     4019      }
     4020    }
     4021
     4022    entryPointOffset[ idx ] -= emulationPreventionByteCount;
     4023    prevEntryPointOffset = curEntryPointOffset;
     4024  }
     4025
     4026  if ( pps->getTilesEnabledFlag() )
     4027  {
     4028    rpcSlice->setTileLocationCount( numEntryPointOffsets );
     4029
     4030    UInt prevPos = 0;
     4031    for (Int idx=0; idx<rpcSlice->getTileLocationCount(); idx++)
     4032    {
     4033      rpcSlice->setTileLocation( idx, prevPos + entryPointOffset [ idx ] );
     4034      prevPos += entryPointOffset[ idx ];
     4035    }
     4036  }
     4037  else if ( pps->getEntropyCodingSyncEnabledFlag() )
     4038  {
     4039    Int numSubstreams = rpcSlice->getNumEntryPointOffsets()+1;
     4040    rpcSlice->allocSubstreamSizes(numSubstreams);
     4041    UInt *pSubstreamSizes       = rpcSlice->getSubstreamSizes();
     4042    for (Int idx=0; idx<numSubstreams-1; idx++)
     4043    {
     4044      if ( idx < numEntryPointOffsets )
     4045      {
     4046        pSubstreamSizes[ idx ] = ( entryPointOffset[ idx ] << 3 ) ;
    32094047      }
    32104048      else
    32114049      {
    3212         rpcSlice->setDeblockingFilterOverrideFlag(0);
    3213       }
    3214       if(rpcSlice->getDeblockingFilterOverrideFlag())
    3215       {
    3216         READ_FLAG ( uiCode, "slice_disable_deblocking_filter_flag" );   rpcSlice->setDeblockingFilterDisable(uiCode ? 1 : 0);
    3217         if(!rpcSlice->getDeblockingFilterDisable())
    3218         {
    3219           READ_SVLC( iCode, "slice_beta_offset_div2" );                       rpcSlice->setDeblockingFilterBetaOffsetDiv2(iCode);
    3220           assert(rpcSlice->getDeblockingFilterBetaOffsetDiv2() >= -6 &&
    3221                  rpcSlice->getDeblockingFilterBetaOffsetDiv2() <=  6);
    3222           READ_SVLC( iCode, "slice_tc_offset_div2" );                         rpcSlice->setDeblockingFilterTcOffsetDiv2(iCode);
    3223           assert(rpcSlice->getDeblockingFilterTcOffsetDiv2() >= -6 &&
    3224                  rpcSlice->getDeblockingFilterTcOffsetDiv2() <=  6);
    3225         }
    3226       }
    3227       else
    3228       {
    3229         rpcSlice->setDeblockingFilterDisable   ( rpcSlice->getPPS()->getPicDisableDeblockingFilterFlag() );
    3230         rpcSlice->setDeblockingFilterBetaOffsetDiv2( rpcSlice->getPPS()->getDeblockingFilterBetaOffsetDiv2() );
    3231         rpcSlice->setDeblockingFilterTcOffsetDiv2  ( rpcSlice->getPPS()->getDeblockingFilterTcOffsetDiv2() );
    3232       }
    3233     }
    3234     else
    3235     {
    3236       rpcSlice->setDeblockingFilterDisable       ( false );
    3237       rpcSlice->setDeblockingFilterBetaOffsetDiv2( 0 );
    3238       rpcSlice->setDeblockingFilterTcOffsetDiv2  ( 0 );
    3239     }
    3240 
    3241     Bool isSAOEnabled = (!rpcSlice->getSPS()->getUseSAO())?(false):(rpcSlice->getSaoEnabledFlag()||rpcSlice->getSaoEnabledFlagChroma());
    3242     Bool isDBFEnabled = (!rpcSlice->getDeblockingFilterDisable());
    3243 
    3244     if(rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag() && ( isSAOEnabled || isDBFEnabled ))
    3245     {
    3246       READ_FLAG( uiCode, "slice_loop_filter_across_slices_enabled_flag");
    3247     }
    3248     else
    3249     {
    3250       uiCode = rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag()?1:0;
    3251     }
    3252     rpcSlice->setLFCrossSliceBoundaryFlag( (uiCode==1)?true:false);
    3253 
    3254   }
    3255 
    3256     UInt *entryPointOffset          = NULL;
    3257     UInt numEntryPointOffsets, offsetLenMinus1;
    3258   if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
    3259   {
    3260     READ_UVLC(numEntryPointOffsets, "num_entry_point_offsets"); rpcSlice->setNumEntryPointOffsets ( numEntryPointOffsets );
    3261     if (numEntryPointOffsets>0)
    3262     {
    3263       READ_UVLC(offsetLenMinus1, "offset_len_minus1");
    3264     }
    3265     entryPointOffset = new UInt[numEntryPointOffsets];
    3266     for (UInt idx=0; idx<numEntryPointOffsets; idx++)
    3267     {
    3268       READ_CODE(offsetLenMinus1+1, uiCode, "entry_point_offset_minus1");
    3269       entryPointOffset[ idx ] = uiCode + 1;
    3270     }
    3271   }
    3272   else
    3273   {
    3274     rpcSlice->setNumEntryPointOffsets ( 0 );
    3275   }
    3276 
    3277 #if POC_RESET_IDC_SIGNALLING
    3278   Int sliceHeaderExtensionLength = 0;
    3279   if(pps->getSliceHeaderExtensionPresentFlag())
    3280   {
    3281     READ_UVLC( uiCode, "slice_header_extension_length"); sliceHeaderExtensionLength = uiCode;
    3282   }
    3283   else
    3284   {
    3285     sliceHeaderExtensionLength = 0;
    3286   }
    3287   UInt startBits = m_pcBitstream->getNumBitsRead();     // Start counter of # SH Extn bits
    3288   if( sliceHeaderExtensionLength > 0 )
    3289   {
    3290     if( rpcSlice->getPPS()->getPocResetInfoPresentFlag() )
    3291     {
    3292       READ_CODE( 2, uiCode,       "poc_reset_idc"); rpcSlice->setPocResetIdc(uiCode);
    3293     }
    3294     else
    3295     {
    3296       rpcSlice->setPocResetIdc( 0 );
    3297     }
    3298 #if Q0142_POC_LSB_NOT_PRESENT
    3299     if ( rpcSlice->getVPS()->getPocLsbNotPresentFlag(rpcSlice->getLayerId()) && iPOClsb > 0 )
    3300     {
    3301       assert( rpcSlice->getPocResetIdc() != 2 );
    3302     }
    3303 #endif
    3304     if( rpcSlice->getPocResetIdc() > 0 )
    3305     {
    3306       READ_CODE(6, uiCode,      "poc_reset_period_id"); rpcSlice->setPocResetPeriodId(uiCode);
    3307     }
    3308     else
    3309     {
    3310      
    3311       rpcSlice->setPocResetPeriodId( 0 );
    3312     }
    3313 
    3314     if (rpcSlice->getPocResetIdc() == 3)
    3315     {
    3316       READ_FLAG( uiCode,        "full_poc_reset_flag"); rpcSlice->setFullPocResetFlag((uiCode == 1) ? true : false);
    3317       READ_CODE(rpcSlice->getSPS()->getBitsForPOC(), uiCode,"poc_lsb_val"); rpcSlice->setPocLsbVal(uiCode);
    3318 #if Q0142_POC_LSB_NOT_PRESENT
    3319       if ( rpcSlice->getVPS()->getPocLsbNotPresentFlag(rpcSlice->getLayerId()) && rpcSlice->getFullPocResetFlag() )
    3320       {
    3321         assert( rpcSlice->getPocLsbVal() == 0 );
    3322       }
    3323 #endif
    3324     }
    3325 
    3326     // Derive the value of PocMsbValRequiredFlag
    3327     rpcSlice->setPocMsbValRequiredFlag( rpcSlice->getCraPicFlag() || rpcSlice->getBlaPicFlag()
    3328                                           /* || related to vps_poc_lsb_aligned_flag */
    3329                                           );
    3330 
    3331     if( !rpcSlice->getPocMsbValRequiredFlag() /* vps_poc_lsb_aligned_flag */ )
    3332     {
    3333       READ_FLAG( uiCode,    "poc_msb_val_present_flag"); rpcSlice->setPocMsbValPresentFlag( uiCode ? true : false );
    3334     }
    3335     else
    3336     {
    3337 #if POC_MSB_VAL_PRESENT_FLAG_SEM
    3338       if( sliceHeaderExtensionLength == 0 )
    3339       {
    3340         rpcSlice->setPocMsbValPresentFlag( false );
    3341       }
    3342       else if( rpcSlice->getPocMsbValRequiredFlag() )
    3343 #else
    3344       if( rpcSlice->getPocMsbValRequiredFlag() )
    3345 #endif
    3346       {
    3347         rpcSlice->setPocMsbValPresentFlag( true );
    3348       }
    3349       else
    3350       {
    3351         rpcSlice->setPocMsbValPresentFlag( false );
    3352       }
    3353     }
    3354 
    3355 #if !POC_RESET_IDC_DECODER
    3356     Int maxPocLsb  = 1 << rpcSlice->getSPS()->getBitsForPOC();
    3357 #endif
    3358     if( rpcSlice->getPocMsbValPresentFlag() )
    3359     {
    3360       READ_UVLC( uiCode,    "poc_msb_val");             rpcSlice->setPocMsbVal( uiCode );
    3361 
    3362 #if !POC_RESET_IDC_DECODER
    3363       // Update POC of the slice based on this MSB val
    3364       Int pocLsb     = rpcSlice->getPOC() % maxPocLsb;
    3365       rpcSlice->setPOC((rpcSlice->getPocMsbVal() * maxPocLsb) + pocLsb);
    3366     }
    3367     else
    3368     {
    3369       rpcSlice->setPocMsbVal( rpcSlice->getPOC() / maxPocLsb );
    3370 #endif
    3371     }
    3372 
    3373     // Read remaining bits in the slice header extension.
    3374     UInt endBits = m_pcBitstream->getNumBitsRead();
    3375     Int counter = (endBits - startBits) % 8;
    3376     if( counter )
    3377     {
    3378       counter = 8 - counter;
    3379     }
    3380 
    3381     while( counter )
    3382     {
    3383 #if Q0146_SSH_EXT_DATA_BIT
    3384       READ_FLAG( uiCode, "slice_segment_header_extension_data_bit" );
    3385 #else
    3386       READ_FLAG( uiCode, "slice_segment_header_extension_reserved_bit" ); assert( uiCode == 1 );
    3387 #endif
    3388       counter--;
    3389     }
    3390   }
    3391 #else
    3392   if(pps->getSliceHeaderExtensionPresentFlag())
    3393   {
    3394     READ_UVLC(uiCode,"slice_header_extension_length");
    3395     for(Int i=0; i<uiCode; i++)
    3396     {
    3397       UInt ignore;
    3398       READ_CODE(8,ignore,"slice_header_extension_data_byte");
    3399     }
    3400   }
    3401 #endif
    3402   m_pcBitstream->readByteAlignment();
    3403 
    3404   if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
    3405   {
    3406     Int endOfSliceHeaderLocation = m_pcBitstream->getByteLocation();
    3407 
    3408     // Adjust endOfSliceHeaderLocation to account for emulation prevention bytes in the slice segment header
    3409     for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
    3410     {
    3411       if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) < endOfSliceHeaderLocation )
    3412       {
    3413         endOfSliceHeaderLocation++;
    3414       }
    3415     }
    3416 
    3417     Int  curEntryPointOffset     = 0;
    3418     Int  prevEntryPointOffset    = 0;
    3419     for (UInt idx=0; idx<numEntryPointOffsets; idx++)
    3420     {
    3421       curEntryPointOffset += entryPointOffset[ idx ];
    3422 
    3423       Int emulationPreventionByteCount = 0;
    3424       for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
    3425       {
    3426         if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) >= ( prevEntryPointOffset + endOfSliceHeaderLocation ) &&
    3427              m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) <  ( curEntryPointOffset  + endOfSliceHeaderLocation ) )
    3428         {
    3429           emulationPreventionByteCount++;
    3430         }
    3431       }
    3432 
    3433       entryPointOffset[ idx ] -= emulationPreventionByteCount;
    3434       prevEntryPointOffset = curEntryPointOffset;
    3435     }
    3436 
    3437     if ( pps->getTilesEnabledFlag() )
    3438     {
    3439       rpcSlice->setTileLocationCount( numEntryPointOffsets );
    3440 
    3441       UInt prevPos = 0;
    3442       for (Int idx=0; idx<rpcSlice->getTileLocationCount(); idx++)
    3443       {
    3444         rpcSlice->setTileLocation( idx, prevPos + entryPointOffset [ idx ] );
    3445         prevPos += entryPointOffset[ idx ];
    3446       }
    3447     }
    3448     else if ( pps->getEntropyCodingSyncEnabledFlag() )
    3449     {
    3450     Int numSubstreams = rpcSlice->getNumEntryPointOffsets()+1;
    3451       rpcSlice->allocSubstreamSizes(numSubstreams);
    3452       UInt *pSubstreamSizes       = rpcSlice->getSubstreamSizes();
    3453       for (Int idx=0; idx<numSubstreams-1; idx++)
    3454       {
    3455         if ( idx < numEntryPointOffsets )
    3456         {
    3457           pSubstreamSizes[ idx ] = ( entryPointOffset[ idx ] << 3 ) ;
    3458         }
    3459         else
    3460         {
    3461           pSubstreamSizes[ idx ] = 0;
    3462         }
    3463       }
    3464     }
    3465 
    3466     if (entryPointOffset)
    3467     {
    3468       delete [] entryPointOffset;
    3469     }
    3470   }
    3471 
    3472   return;
     4050        pSubstreamSizes[ idx ] = 0;
     4051      }
     4052    }
     4053  }
     4054
     4055  if (entryPointOffset)
     4056  {
     4057    delete [] entryPointOffset;
     4058  }
     4059}
     4060
     4061return;
    34734062}
    34744063
     
    37334322      {
    37344323#endif
    3735       wp[1].uiLog2WeightDenom = uiLog2WeightDenomChroma;
    3736       wp[2].uiLog2WeightDenom = uiLog2WeightDenomChroma;
     4324        wp[1].uiLog2WeightDenom = uiLog2WeightDenomChroma;
     4325        wp[2].uiLog2WeightDenom = uiLog2WeightDenomChroma;
    37374326#if AUXILIARY_PICTURES
    37384327      }
     
    39134502Void TDecCavlc::xParse3DAsymLUT( TCom3DAsymLUT * pc3DAsymLUT )
    39144503{
     4504#if R0150_CGS_SIGNAL_CONSTRAINTS
     4505  UInt uiNumRefLayersM1;
     4506  READ_UVLC( uiNumRefLayersM1 , "num_cm_ref_layers_minus1" );
     4507  assert( uiNumRefLayersM1 <= 61 );
     4508  for( UInt i = 0 ; i <= uiNumRefLayersM1 ; i++ )
     4509  {
     4510    UInt uiRefLayerId;
     4511    READ_CODE( 6 , uiRefLayerId , "cm_ref_layer_id" );
     4512    pc3DAsymLUT->addRefLayerId( uiRefLayerId );
     4513  }
     4514#endif
    39154515  UInt uiCurOctantDepth , uiCurPartNumLog2 , uiInputBitDepthM8 , uiOutputBitDepthM8 , uiResQaunBit;
     4516#if R0300_CGS_RES_COEFF_CODING
     4517  UInt uiDeltaBits;
     4518#endif
    39164519  READ_CODE( 2 , uiCurOctantDepth , "cm_octant_depth" );
    39174520  READ_CODE( 2 , uiCurPartNumLog2 , "cm_y_part_num_log2" );     
     4521#if R0150_CGS_SIGNAL_CONSTRAINTS
     4522  UInt uiChromaInputBitDepthM8 , uiChromaOutputBitDepthM8;
     4523  READ_UVLC( uiInputBitDepthM8 , "cm_input_luma_bit_depth_minus8" );
     4524  READ_UVLC( uiChromaInputBitDepthM8 , "cm_input_chroma_bit_depth_minus8" );
     4525  READ_UVLC( uiOutputBitDepthM8 , "cm_output_luma_bit_depth_minus8" );
     4526  READ_UVLC( uiChromaOutputBitDepthM8 , "cm_output_chroma_bit_depth_minus8" );
     4527#else
    39184528  READ_CODE( 3 , uiInputBitDepthM8 , "cm_input_bit_depth_minus8" );
    39194529  Int iInputBitDepthCDelta;
     
    39224532  Int iOutputBitDepthCDelta;
    39234533  READ_SVLC(iOutputBitDepthCDelta, "cm_output_bit_depth_chroma_delta");
     4534#endif
    39244535  READ_CODE( 2 , uiResQaunBit , "cm_res_quant_bit" );
     4536#if R0300_CGS_RES_COEFF_CODING
     4537  READ_CODE( 2 , uiDeltaBits , "cm_flc_bits" );
     4538  pc3DAsymLUT->setDeltaBits(uiDeltaBits + 1);
     4539#endif
     4540
     4541#if R0151_CGS_3D_ASYMLUT_IMPROVE
     4542#if R0150_CGS_SIGNAL_CONSTRAINTS
     4543  Int nAdaptCThresholdU = 1 << ( uiChromaInputBitDepthM8 + 8 - 1 );
     4544  Int nAdaptCThresholdV = 1 << ( uiChromaInputBitDepthM8 + 8 - 1 );
     4545#else
     4546  Int nAdaptCThresholdU = 1 << ( uiInputBitDepthM8 + 8 + iInputBitDepthCDelta - 1 );
     4547  Int nAdaptCThresholdV = 1 << ( uiInputBitDepthM8 + 8 + iInputBitDepthCDelta - 1 );
     4548#endif
     4549  if( uiCurOctantDepth == 1 )
     4550  {
     4551    Int delta = 0;
     4552    READ_SVLC( delta , "cm_adapt_threshold_u_delta" );
     4553    nAdaptCThresholdU += delta;
     4554    READ_SVLC( delta , "cm_adapt_threshold_v_delta" );
     4555    nAdaptCThresholdV += delta;
     4556  }
     4557#endif
    39254558  pc3DAsymLUT->destroy();
    3926   pc3DAsymLUT->create( uiCurOctantDepth , uiInputBitDepthM8 + 8 ,  uiInputBitDepthM8 + 8 + iInputBitDepthCDelta, uiOutputBitDepthM8 + 8 , uiOutputBitDepthM8 + 8 + iOutputBitDepthCDelta ,uiCurPartNumLog2 );
     4559  pc3DAsymLUT->create( uiCurOctantDepth , uiInputBitDepthM8 + 8 , 
     4560#if R0150_CGS_SIGNAL_CONSTRAINTS
     4561    uiChromaInputBitDepthM8 + 8 ,
     4562#else
     4563    uiInputBitDepthM8 + 8 + iInputBitDepthCDelta,
     4564#endif
     4565    uiOutputBitDepthM8 + 8 ,
     4566#if R0150_CGS_SIGNAL_CONSTRAINTS
     4567    uiChromaOutputBitDepthM8 + 8 ,
     4568#else
     4569    uiOutputBitDepthM8 + 8 + iOutputBitDepthCDelta ,
     4570#endif
     4571    uiCurPartNumLog2
     4572#if R0151_CGS_3D_ASYMLUT_IMPROVE
     4573    , nAdaptCThresholdU , nAdaptCThresholdV
     4574#endif   
     4575    );
    39274576  pc3DAsymLUT->setResQuantBit( uiResQaunBit );
    39284577
     4578#if R0164_CGS_LUT_BUGFIX_CHECK
     4579  pc3DAsymLUT->xInitCuboids();
     4580#endif
    39294581  xParse3DAsymLUTOctant( pc3DAsymLUT , 0 , 0 , 0 , 0 , 1 << pc3DAsymLUT->getCurOctantDepth() );
     4582#if R0164_CGS_LUT_BUGFIX
     4583#if R0164_CGS_LUT_BUGFIX_CHECK
     4584  printf("============= Before 'xCuboidsFilledCheck()': ================\n");
     4585  pc3DAsymLUT->display();
     4586  pc3DAsymLUT->xCuboidsFilledCheck( false );
     4587  printf("============= After 'xCuboidsFilledCheck()': =================\n");
     4588  pc3DAsymLUT->display();
     4589#endif
     4590#endif
    39304591}
    39314592
     
    39524613  else
    39534614  {
     4615#if R0300_CGS_RES_COEFF_CODING
     4616    Int nFLCbits = pc3DAsymLUT->getMappingShift()-pc3DAsymLUT->getResQuantBit()-pc3DAsymLUT->getDeltaBits() ;
     4617    nFLCbits = nFLCbits >= 0 ? nFLCbits:0;
     4618#endif
    39544619    for( Int l = 0 ; l < nYPartNum ; l++ )
    39554620    {
     4621#if R0164_CGS_LUT_BUGFIX
     4622      Int shift = pc3DAsymLUT->getCurOctantDepth() - nDepth ;
     4623#endif
    39564624      for( Int nVertexIdx = 0 ; nVertexIdx < 4 ; nVertexIdx++ )
    39574625      {
     
    39614629        if( uiCodeVertex )
    39624630        {
     4631#if R0151_CGS_3D_ASYMLUT_IMPROVE
     4632#if R0300_CGS_RES_COEFF_CODING
     4633          xReadParam( deltaY, nFLCbits );
     4634          xReadParam( deltaU, nFLCbits );
     4635          xReadParam( deltaV, nFLCbits );
     4636#else
     4637          xReadParam( deltaY );
     4638          xReadParam( deltaU );
     4639          xReadParam( deltaV );
     4640#endif
     4641#else
    39634642          READ_SVLC( deltaY , "resY" );
    39644643          READ_SVLC( deltaU , "resU" );
    39654644          READ_SVLC( deltaV , "resV" );
    3966         }
     4645#endif
     4646        }
     4647#if R0164_CGS_LUT_BUGFIX
     4648        pc3DAsymLUT->setCuboidVertexResTree( yIdx + (l<<shift) , uIdx , vIdx , nVertexIdx , deltaY , deltaU , deltaV );
     4649        for (Int m = 1; m < (1<<shift); m++) {
     4650          pc3DAsymLUT->setCuboidVertexResTree( yIdx + (l<<shift) + m , uIdx , vIdx , nVertexIdx , 0 , 0 , 0 );
     4651#if R0164_CGS_LUT_BUGFIX_CHECK
     4652          pc3DAsymLUT->xSetFilled( yIdx + (l<<shift) + m , uIdx , vIdx );
     4653#endif
     4654        }
     4655#else
    39674656        pc3DAsymLUT->setCuboidVertexResTree( yIdx + l , uIdx , vIdx , nVertexIdx , deltaY , deltaU , deltaV );
    3968       }
    3969     }
    3970   }
    3971 }
     4657#endif
     4658      }
     4659#if R0164_CGS_LUT_BUGFIX_CHECK
     4660      pc3DAsymLUT->xSetExplicit( yIdx + (l<<shift) , uIdx , vIdx );
     4661#endif
     4662    }
     4663#if R0164_CGS_LUT_BUGFIX
     4664    for ( Int u=0 ; u<nLength ; u++ ) {
     4665      for ( Int v=0 ; v<nLength ; v++ ) {
     4666        if ( u!=0 || v!=0 ) {
     4667          for ( Int y=0 ; y<nLength*nYPartNum ; y++ ) {
     4668            for( Int nVertexIdx = 0 ; nVertexIdx < 4 ; nVertexIdx++ )
     4669            {
     4670              pc3DAsymLUT->setCuboidVertexResTree( yIdx + y , uIdx + u , vIdx + v , nVertexIdx , 0 , 0 , 0 );
     4671#if R0164_CGS_LUT_BUGFIX_CHECK
     4672              pc3DAsymLUT->xSetFilled( yIdx + y , uIdx + u , vIdx + v );
     4673#endif
     4674            }
     4675          }
     4676        }
     4677      }
     4678    }
     4679#endif
     4680  }
     4681}
     4682
     4683#if R0151_CGS_3D_ASYMLUT_IMPROVE
     4684#if R0300_CGS_RES_COEFF_CODING
     4685Void TDecCavlc::xReadParam( Int& param, Int rParam )
     4686#else
     4687Void TDecCavlc::xReadParam( Int& param )
     4688#endif
     4689{
     4690#if !R0300_CGS_RES_COEFF_CODING
     4691  const UInt rParam = 7;
     4692#endif
     4693  UInt prefix;
     4694  UInt codeWord ;
     4695  UInt rSymbol;
     4696  UInt sign;
     4697
     4698  READ_UVLC( prefix, "quotient")  ;
     4699  READ_CODE (rParam, codeWord, "remainder");
     4700  rSymbol = (prefix<<rParam) + codeWord;
     4701
     4702  if(rSymbol)
     4703  {
     4704    READ_FLAG(sign, "sign");
     4705    param = sign ? -(Int)(rSymbol) : (Int)(rSymbol);
     4706  }
     4707  else param = 0;
     4708}
     4709#endif
     4710#if VPS_VUI_BSP_HRD_PARAMS
     4711Void TDecCavlc::parseVpsVuiBspHrdParams( TComVPS *vps )
     4712{
     4713  UInt uiCode;
     4714  assert (vps->getTimingInfo()->getTimingInfoPresentFlag() == 1);
     4715  READ_UVLC( uiCode, "vps_num_add_hrd_params" ); vps->setVpsNumAddHrdParams(uiCode);
     4716  vps->createBspHrdParamBuffer(vps->getVpsNumAddHrdParams()); // Also allocates m_cprmsAddPresentFlag and m_numSubLayerHrdMinus
     4717
     4718  for( Int i = vps->getNumHrdParameters(), j = 0; i < vps->getNumHrdParameters() + vps->getVpsNumAddHrdParams(); i++, j++ ) // j = i - vps->getNumHrdParameters()
     4719  {
     4720    if( i > 0 )
     4721    {
     4722      READ_FLAG( uiCode, "cprms_add_present_flag[i]" );   vps->setCprmsAddPresentFlag(j, uiCode ? true : false);
     4723    }
     4724    else
     4725    {
     4726      // i == 0
     4727      if( vps->getNumHrdParameters() == 0 )
     4728      {
     4729        vps->setCprmsAddPresentFlag(0, true);
     4730      }
     4731    }
     4732    READ_UVLC( uiCode, "num_sub_layer_hrd_minus1[i]" ); vps->setNumSubLayerHrdMinus1(j, uiCode );
     4733    assert( uiCode <= vps->getMaxTLayers() - 1 );
     4734   
     4735    parseHrdParameters( vps->getBspHrd(j), vps->getCprmsAddPresentFlag(j), vps->getNumSubLayerHrdMinus1(j) );
     4736    if( i > 0 && !vps->getCprmsAddPresentFlag(i) )
     4737    {
     4738      // Copy common information parameters
     4739      if( i == vps->getNumHrdParameters() )
     4740      {
     4741        vps->getBspHrd(j)->copyCommonInformation( vps->getHrdParameters( vps->getNumHrdParameters() - 1 ) );
     4742      }
     4743      else
     4744      {
     4745        vps->getBspHrd(j)->copyCommonInformation( vps->getBspHrd( j - 1 ) );
     4746      }
     4747    }
     4748  }
     4749  for (Int h = 1; h < vps->getNumOutputLayerSets(); h++)
     4750  {
     4751    Int lsIdx = vps->getOutputLayerSetIdx( h );
     4752    READ_UVLC( uiCode, "num_signalled_partitioning_schemes[h]"); vps->setNumSignalledPartitioningSchemes(h, uiCode);
     4753    for( Int j = 0; j < vps->getNumSignalledPartitioningSchemes(h); j++ )
     4754    {
     4755      READ_UVLC( uiCode, "num_partitions_in_scheme_minus1[h][j]" ); vps->setNumPartitionsInSchemeMinus1(h, j, uiCode);
     4756      for( Int k = 0; k <= vps->getNumPartitionsInSchemeMinus1(h, j); k++ )
     4757      {
     4758        for( Int r = 0; r < vps->getNumLayersInIdList( lsIdx ); r++ )
     4759        {
     4760          READ_FLAG( uiCode, "layer_included_in_partition_flag[h][j][k][r]" ); vps->setLayerIncludedInPartitionFlag(h, j, k, r, uiCode ? true : false);
     4761        }
     4762      }
     4763    }
     4764    for( Int i = 0; i < vps->getNumSignalledPartitioningSchemes(h) + 1; i++ )
     4765    {
     4766      for( Int t = 0; t <= vps->getMaxSLayersInLayerSetMinus1(lsIdx); t++ )
     4767      {
     4768        READ_UVLC( uiCode, "num_bsp_schedules_minus1[h][i][t]");              vps->setNumBspSchedulesMinus1(h, i, t, uiCode);
     4769        for( Int j = 0; j <= vps->getNumBspSchedulesMinus1(h, i, t); j++ )
     4770        {
     4771          for( Int k = 0; k < vps->getNumPartitionsInSchemeMinus1(h, i); k++ )
     4772          {
     4773            READ_UVLC( uiCode, "bsp_comb_hrd_idx[h][i][t][j][k]");      vps->setBspHrdIdx(h, i, t, j, k, uiCode);
     4774            READ_UVLC( uiCode, "bsp_comb_sched_idx[h][i][t][j][k]");    vps->setBspSchedIdx(h, i, t, j, k, uiCode);
     4775          }
     4776        }
     4777      }
     4778    }
     4779
     4780    // To be done: Check each layer included in not more than one BSP in every partitioning scheme,
     4781    // and other related checks associated with layers in bitstream partitions.
     4782
     4783  }
     4784}
     4785#endif
    39724786#endif
    39734787//! \}
  • trunk/source/Lib/TLibDecoder/TDecCAVLC.h

    r815 r906  
    8686  Void  parseVpsDpbSizeTable( TComVPS *vps );
    8787#endif
     88#if VPS_VUI_BSP_HRD_PARAMS
     89  Void  parseVpsVuiBspHrdParams( TComVPS *vps );
     90#endif
    8891#if SPS_DPB_PARAMS
    8992  Void  parseSPS            ( TComSPS* pcSPS ); // it should be removed after macro clean up
     
    143146  Void xParse3DAsymLUT( TCom3DAsymLUT * pc3DAsymLUT );
    144147  Void xParse3DAsymLUTOctant( TCom3DAsymLUT * pc3DAsymLUT , Int nDepth , Int yIdx , Int uIdx , Int vIdx , Int nLength );
     148#if R0151_CGS_3D_ASYMLUT_IMPROVE
     149#if R0300_CGS_RES_COEFF_CODING
     150  Void xReadParam( Int& param, Int flc_bits );
     151#else
     152  Void xReadParam( Int& param );
     153#endif
     154#endif
    145155#endif
    146156};
  • trunk/source/Lib/TLibDecoder/TDecGop.cpp

    r713 r906  
    5454//! \{
    5555static void calcAndPrintHashStatus(TComPicYuv& pic, const SEIDecodedPictureHash* pictureHashSEI);
     56#if Q0074_COLOUR_REMAPPING_SEI
     57static Void applyColourRemapping(TComPicYuv& pic, const SEIColourRemappingInfo* colourRemappingInfoSEI, UInt layerId=0 );
     58static std::vector<SEIColourRemappingInfo> storeCriSEI; //Persistent Colour Remapping Information SEI
     59#endif
    5660// ====================================================================================================================
    5761// Constructor / destructor / initialization / destroy
     
    218222      if( pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->isILR( m_layerId ) )
    219223      {
    220         printf( "%d(%d)", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex), pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->getLayerId() );
     224        UInt refLayerId = pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->getLayerId();
     225        UInt refLayerIdc = pcSlice->getReferenceLayerIdc(refLayerId);
     226        assert( g_posScalingFactor[refLayerIdc][0] );
     227        assert( g_posScalingFactor[refLayerIdc][1] );
     228
     229        printf( "%d(%d, {%1.2f, %1.2f}x)", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex), refLayerId, 65536.0/g_posScalingFactor[refLayerIdc][0], 65536.0/g_posScalingFactor[refLayerIdc][1] );
    221230      }
    222231      else
     
    247256    calcAndPrintHashStatus(*rpcPic->getPicYuvRec(), hash);
    248257  }
     258#if Q0074_COLOUR_REMAPPING_SEI
     259  if (m_colourRemapSEIEnabled)
     260  {
     261    SEIMessages colourRemappingInfo = getSeisByType(rpcPic->getSEIs(), SEI::COLOUR_REMAPPING_INFO );
     262    const SEIColourRemappingInfo *seiColourRemappingInfo = ( colourRemappingInfo.size() > 0 ) ? (SEIColourRemappingInfo*) *(colourRemappingInfo.begin()) : NULL;
     263    if (colourRemappingInfo.size() > 1)
     264    {
     265      printf ("Warning: Got multiple Colour Remapping Information SEI messages. Using first.");
     266    }
     267    applyColourRemapping(*rpcPic->getPicYuvRec(), seiColourRemappingInfo
     268#if SVC_EXTENSION
     269     , rpcPic->getLayerId()
     270#endif
     271     );
     272  }
     273#endif
    249274
    250275#if SETTING_PIC_OUTPUT_MARK
     
    334359  }
    335360}
     361
     362#if Q0074_COLOUR_REMAPPING_SEI
     363Void xInitColourRemappingLut( const Int bitDepthY, const Int bitDepthC, std::vector<Int>(&preLut)[3], std::vector<Int>(&postLut)[3], const SEIColourRemappingInfo* const pCriSEI )
     364{
     365  for ( Int c=0 ; c<3 ; c++ )
     366  { 
     367    Int bitDepth = c ? bitDepthC : bitDepthY ;
     368    preLut[c].resize(1 << bitDepth);
     369    postLut[c].resize(1 << pCriSEI->m_colourRemapBitDepth);
     370   
     371    Int bitDepthDiff = pCriSEI->m_colourRemapBitDepth - bitDepth;
     372    Int iShift1 = (bitDepthDiff>0) ? bitDepthDiff : 0; //bit scale from bitdepth to ColourRemapBitdepth (manage only case colourRemapBitDepth>= bitdepth)
     373    if( bitDepthDiff<0 )
     374      printf ("Warning: CRI SEI - colourRemapBitDepth (%d) <bitDepth (%d) - case not handled\n", pCriSEI->m_colourRemapBitDepth, bitDepth);
     375    bitDepthDiff = pCriSEI->m_colourRemapBitDepth - pCriSEI->m_colourRemapInputBitDepth;
     376    Int iShift2 = (bitDepthDiff>0) ? bitDepthDiff : 0; //bit scale from ColourRemapInputBitdepth to ColourRemapBitdepth (manage only case colourRemapBitDepth>= colourRemapInputBitDepth)
     377    if( bitDepthDiff<0 )
     378      printf ("Warning: CRI SEI - colourRemapBitDepth (%d) <colourRemapInputBitDepth (%d) - case not handled\n", pCriSEI->m_colourRemapBitDepth, pCriSEI->m_colourRemapInputBitDepth);
     379
     380    //Fill preLut
     381    for ( Int k=0 ; k<(1<<bitDepth) ; k++ )
     382    {
     383      Int iSample = k << iShift1 ;
     384      for ( Int iPivot=0 ; iPivot<=pCriSEI->m_preLutNumValMinus1[c] ; iPivot++ )
     385      {
     386        Int iCodedPrev  = pCriSEI->m_preLutCodedValue[c][iPivot]    << iShift2; //Coded in CRInputBitdepth
     387        Int iCodedNext  = pCriSEI->m_preLutCodedValue[c][iPivot+1]  << iShift2; //Coded in CRInputBitdepth
     388        Int iTargetPrev = pCriSEI->m_preLutTargetValue[c][iPivot];              //Coded in CRBitdepth
     389        Int iTargetNext = pCriSEI->m_preLutTargetValue[c][iPivot+1];            //Coded in CRBitdepth
     390        if ( iCodedPrev <= iSample && iSample <= iCodedNext )
     391        {
     392          Float fInterpol = (Float)( (iCodedNext - iSample)*iTargetPrev + (iSample - iCodedPrev)*iTargetNext ) * 1.f / (Float)(iCodedNext - iCodedPrev);
     393          preLut[c][k]  = (Int)( 0.5f + fInterpol );
     394          iPivot = pCriSEI->m_preLutNumValMinus1[c] + 1;
     395        }
     396      }
     397    }
     398   
     399    //Fill postLut
     400    for ( Int k=0 ; k<(1<<pCriSEI->m_colourRemapBitDepth) ; k++ )
     401    {
     402      Int iSample = k;
     403      for ( Int iPivot=0 ; iPivot<=pCriSEI->m_postLutNumValMinus1[c] ; iPivot++ )
     404      {
     405        Int iCodedPrev  = pCriSEI->m_postLutCodedValue[c][iPivot];    //Coded in CRBitdepth
     406        Int iCodedNext  = pCriSEI->m_postLutCodedValue[c][iPivot+1];  //Coded in CRBitdepth
     407        Int iTargetPrev = pCriSEI->m_postLutTargetValue[c][iPivot];   //Coded in CRBitdepth
     408        Int iTargetNext = pCriSEI->m_postLutTargetValue[c][iPivot+1]; //Coded in CRBitdepth
     409        if ( iCodedPrev <= iSample && iSample <= iCodedNext )
     410        {
     411          Float fInterpol =  (Float)( (iCodedNext - iSample)*iTargetPrev + (iSample - iCodedPrev)*iTargetNext ) * 1.f / (Float)(iCodedNext - iCodedPrev) ;
     412          postLut[c][k]  = (Int)( 0.5f + fInterpol );
     413          iPivot = pCriSEI->m_postLutNumValMinus1[c] + 1;
     414        }
     415      }
     416    }
     417  }
     418}
     419
     420static void applyColourRemapping(TComPicYuv& pic, const SEIColourRemappingInfo* pCriSEI, UInt layerId )
     421
     422  if( !storeCriSEI.size() )
     423#if SVC_EXTENSION
     424    storeCriSEI.resize(MAX_LAYERS);
     425#else
     426    storeCriSEI.resize(1);
     427#endif
     428
     429  if ( pCriSEI ) //if a CRI SEI has just been retrieved, keep it in memory (persistence management)
     430    storeCriSEI[layerId] = *pCriSEI;
     431
     432  if( !storeCriSEI[layerId].m_colourRemapCancelFlag )
     433  {
     434    Int iHeight  = pic.getHeight();
     435    Int iWidth   = pic.getWidth();
     436    Int iStride  = pic.getStride();
     437    Int iCStride = pic.getCStride();
     438
     439    Pel *YUVIn[3], *YUVOut[3];
     440    YUVIn[0] = pic.getLumaAddr();
     441    YUVIn[1] = pic.getCbAddr();
     442    YUVIn[2] = pic.getCrAddr();
     443   
     444    TComPicYuv picColourRemapped;
     445#if SVC_EXTENSION
     446#if AUXILIARY_PICTURES
     447    picColourRemapped.create( pic.getWidth(), pic.getHeight(), pic.getChromaFormat(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, NULL );
     448#else
     449    picColourRemapped.create( pic.getWidth(), pic.getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, NULL );
     450#endif
     451#else
     452    picColourRemapped.create( pic.getWidth(), pic.getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
     453#endif
     454    YUVOut[0] = picColourRemapped.getLumaAddr();
     455    YUVOut[1] = picColourRemapped.getCbAddr();
     456    YUVOut[2] = picColourRemapped.getCrAddr();
     457
     458#if SVC_EXTENSION
     459    Int bitDepthY = g_bitDepthYLayer[layerId];
     460    Int bitDepthC = g_bitDepthCLayer[layerId];
     461
     462    assert( g_bitDepthY == bitDepthY );
     463    assert( g_bitDepthC == bitDepthC );
     464#else
     465    Int bitDepthY = g_bitDepthY;
     466    Int bitDepthC = g_bitDepthC;
     467#endif
     468
     469    std::vector<Int> preLut[3];
     470    std::vector<Int> postLut[3];
     471    xInitColourRemappingLut( bitDepthY, bitDepthC, preLut, postLut, &storeCriSEI[layerId] );
     472   
     473    Int roundingOffset = (storeCriSEI[layerId].m_log2MatrixDenom==0) ? 0 : (1 << (storeCriSEI[layerId].m_log2MatrixDenom - 1));
     474
     475    for( Int y = 0; y < iHeight ; y++ )
     476    {
     477      for( Int x = 0; x < iWidth ; x++ )
     478      {
     479        Int YUVPre[3], YUVMat[3];
     480        YUVPre[0] = preLut[0][ YUVIn[0][x]   ];
     481        YUVPre[1] = preLut[1][ YUVIn[1][x>>1] ];
     482        YUVPre[2] = preLut[2][ YUVIn[2][x>>1] ];
     483
     484        YUVMat[0] = ( storeCriSEI[layerId].m_colourRemapCoeffs[0][0]*YUVPre[0]
     485                    + storeCriSEI[layerId].m_colourRemapCoeffs[0][1]*YUVPre[1]
     486                    + storeCriSEI[layerId].m_colourRemapCoeffs[0][2]*YUVPre[2]
     487                    + roundingOffset ) >> ( storeCriSEI[layerId].m_log2MatrixDenom );
     488        YUVMat[0] = Clip3( 0, (1<<storeCriSEI[layerId].m_colourRemapBitDepth)-1, YUVMat[0] );
     489        YUVOut[0][x] = postLut[0][ YUVMat[0] ];
     490
     491        if( (y&1) && (x&1) )
     492        {
     493          for(Int c=1 ; c<3 ; c++)
     494          {
     495            YUVMat[c] = ( storeCriSEI[layerId].m_colourRemapCoeffs[c][0]*YUVPre[0]
     496                        + storeCriSEI[layerId].m_colourRemapCoeffs[c][1]*YUVPre[1]
     497                        + storeCriSEI[layerId].m_colourRemapCoeffs[c][2]*YUVPre[2]
     498                        + roundingOffset ) >> ( storeCriSEI[layerId].m_log2MatrixDenom );
     499            YUVMat[c] = Clip3( 0, (1<<storeCriSEI[layerId].m_colourRemapBitDepth)-1, YUVMat[c] );
     500            YUVOut[c][x>>1] = postLut[c][ YUVMat[c] ];   
     501          }
     502        }
     503      }
     504      YUVIn[0]  += iStride;
     505      YUVOut[0] += iStride;
     506      if( y&1 )
     507      {
     508        YUVIn[1]  += iCStride;
     509        YUVIn[2]  += iCStride;
     510        YUVOut[1] += iCStride;
     511        YUVOut[2] += iCStride;
     512      }
     513    }
     514
     515    //Write remapped picture in decoding order
     516    Char  cTemp[255];
     517    sprintf(cTemp, "seiColourRemappedPic_L%d_%dx%d_%dbits.yuv", layerId, iWidth, iHeight, storeCriSEI[layerId].m_colourRemapBitDepth );
     518    picColourRemapped.dump( cTemp, true, storeCriSEI[layerId].m_colourRemapBitDepth );
     519
     520    picColourRemapped.destroy();
     521
     522    storeCriSEI[layerId].m_colourRemapCancelFlag = !storeCriSEI[layerId].m_colourRemapPersistenceFlag; //Handling persistence
     523  }
     524}
     525#endif
    336526//! \}
  • trunk/source/Lib/TLibDecoder/TDecGop.h

    r595 r906  
    8282  Double                m_dDecTime;
    8383  Int                   m_decodedPictureHashSEIEnabled;  ///< Checksum(3)/CRC(2)/MD5(1)/disable(0) acting on decoded picture hash SEI message
    84 
     84#if Q0074_COLOUR_REMAPPING_SEI
     85  Bool                  m_colourRemapSEIEnabled;         ///< Enable/disable Colour Remapping Information SEI message acting on decoded pictures
     86#endif
    8587#if SVC_EXTENSION
    8688  UInt                  m_layerId;
     
    114116
    115117  void setDecodedPictureHashSEIEnabled(Int enabled) { m_decodedPictureHashSEIEnabled = enabled; }
     118#if Q0074_COLOUR_REMAPPING_SEI
     119  void setColourRemappingInfoSEIEnabled(Int enabled) { m_colourRemapSEIEnabled = enabled; }
     120#endif
    116121#if SVC_EXTENSION
    117122  TDecTop*   getLayerDec(UInt LayerId)  { return m_ppcTDecTop[LayerId]; }
  • trunk/source/Lib/TLibDecoder/TDecSlice.cpp

    r644 r906  
    4242
    4343#if SVC_EXTENSION
    44   ParameterSetMap<TComVPS> ParameterSetManagerDecoder::m_vpsBuffer(MAX_NUM_VPS);
     44ParameterSetMap<TComVPS> ParameterSetManagerDecoder::m_vpsBuffer(MAX_NUM_VPS);
     45ParameterSetMap<TComSPS> ParameterSetManagerDecoder::m_spsBuffer(MAX_NUM_SPS);
     46ParameterSetMap<TComPPS> ParameterSetManagerDecoder::m_ppsBuffer(MAX_NUM_PPS);
    4547#endif
    4648
     
    144146  UInt uiTilesAcross   = rpcPic->getPicSym()->getNumColumnsMinus1()+1;
    145147  TComSlice*  pcSlice = rpcPic->getSlice(rpcPic->getCurrSliceIdx());
     148#if !WPP_FIX
    146149  Int  iNumSubstreams = pcSlice->getPPS()->getNumSubstreams();
     150#endif
    147151
    148152  // delete decoders if already allocated in previous slice
     
    191195  UInt uiWidthInLCUs  = rpcPic->getPicSym()->getFrameWidthInCU();
    192196  //UInt uiHeightInLCUs = rpcPic->getPicSym()->getFrameHeightInCU();
     197
     198#if WPP_FIX
     199  UInt uiTileCol;
     200  UInt uiTileLCUX;
     201  const Bool depSliceSegmentsEnabled = rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getPPS()->getDependentSliceSegmentsEnabledFlag();
     202  const UInt startTileIdx=rpcPic->getPicSym()->getTileIdxMap(iStartCUAddr);
     203  TComTile *pCurrentTile=rpcPic->getPicSym()->getTComTile(startTileIdx);
     204  UInt uiTileStartLCU = pCurrentTile->getFirstCUAddr(); // Code tidy
     205
     206  // The first LCU of the slice is the first coded substream, but the global substream number, as calculated by getSubstreamForLCUAddr may be higher.
     207  // This calculates the common offset for all substreams in this slice.
     208  const UInt subStreamOffset=rpcPic->getSubstreamForLCUAddr(iStartCUAddr, true, pcSlice);
     209#else
    193210  UInt uiCol=0, uiLin=0, uiSubStrm=0;
    194211
     
    199216  Bool depSliceSegmentsEnabled = rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getPPS()->getDependentSliceSegmentsEnabledFlag();
    200217  uiTileStartLCU = rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(iStartCUAddr))->getFirstCUAddr();
     218#endif
    201219  if( depSliceSegmentsEnabled )
    202220  {
     221#if WPP_FIX
     222    if( (!rpcPic->getSlice(rpcPic->getCurrSliceIdx())->isNextSlice()) && iStartCUAddr != uiTileStartLCU)  // Code tidy // Is this a dependent slice segment and not the start of a tile?
     223#else
    203224    if( (!rpcPic->getSlice(rpcPic->getCurrSliceIdx())->isNextSlice()) &&
    204225       iStartCUAddr != rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(iStartCUAddr))->getFirstCUAddr())
     226#endif
    205227    {
    206228      if(pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag())
    207229      {
     230#if WPP_FIX
     231        uiTileCol = startTileIdx % (rpcPic->getPicSym()->getNumColumnsMinus1()+1); // Code tidy
     232#else
    208233        uiTileCol = rpcPic->getPicSym()->getTileIdxMap(iStartCUAddr) % (rpcPic->getPicSym()->getNumColumnsMinus1()+1);
     234#endif
    209235        m_pcBufferSbacDecoders[uiTileCol].loadContexts( CTXMem[1]  );//2.LCU
     236#if WPP_FIX
     237        if ( pCurrentTile->getTileWidth() < 2)
     238        {
     239          CTXMem[0]->loadContexts(pcSbacDecoder); // If tile width is less than 2, need to ensure CTX states get initialised to un-adapted CABAC. Set here, to load a few lines later (!)
     240        }
     241#else
    210242        if ( (iStartCUAddr%uiWidthInLCUs+1) >= uiWidthInLCUs  )
    211243        {
     
    217249          }
    218250        }
     251#endif
    219252      }
    220253      pcSbacDecoder->loadContexts(CTXMem[0] ); //end of depSlice-1
     254#if WPP_FIX
     255      pcSbacDecoders[0].loadContexts(pcSbacDecoder); // The first substream used for the slice will always be 0. (The original code was equivalent)
     256#else
    221257      pcSbacDecoders[uiSubStrm].loadContexts(pcSbacDecoder);
     258#endif
    222259    }
    223260    else
     
    237274    uiTileStartLCU = rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(iCUAddr))->getFirstCUAddr();
    238275    uiTileLCUX = uiTileStartLCU % uiWidthInLCUs;
     276#if WPP_FIX
     277    UInt uiCol     = iCUAddr % uiWidthInLCUs;
     278    UInt uiSubStrm=rpcPic->getSubstreamForLCUAddr(iCUAddr, true, pcSlice)-subStreamOffset;
     279#else
    239280    uiCol     = iCUAddr % uiWidthInLCUs;
    240281    // The 'line' is now relative to the 1st line in the slice, not the 1st line in the picture.
    241282    uiLin     = (iCUAddr/uiWidthInLCUs)-(iStartCUAddr/uiWidthInLCUs);
     283#endif
    242284    // inherit from TR if necessary, select substream to use.
    243285    if( (pcSlice->getPPS()->getNumSubstreams() > 1) || ( depSliceSegmentsEnabled  && (uiCol == uiTileLCUX)&&(pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag()) ))
    244286    {
     287#if !WPP_FIX
    245288      // independent tiles => substreams are "per tile".  iNumSubstreams has already been multiplied.
    246289      iNumSubstreamsPerTile = iNumSubstreams/rpcPic->getPicSym()->getNumTiles();
    247290      uiSubStrm = rpcPic->getPicSym()->getTileIdxMap(iCUAddr)*iNumSubstreamsPerTile
    248291                  + uiLin%iNumSubstreamsPerTile;
     292#endif
    249293      m_pcEntropyDecoder->setBitstream( ppcSubstreams[uiSubStrm] );
    250294      // Synchronize cabac probabilities with upper-right LCU if it's available and we're at the start of a line.
     
    278322      pcSbacDecoder->load(&pcSbacDecoders[uiSubStrm]);  //this load is used to simplify the code (avoid to change all the call to pcSbacDecoders)
    279323    }
     324#if !WPP_FIX
    280325    else if ( pcSlice->getPPS()->getNumSubstreams() <= 1 )
    281326    {
     
    283328      iNumSubstreamsPerTile = 1;
    284329    }
     330#endif
    285331
    286332    if ( (iCUAddr == rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(iCUAddr))->getFirstCUAddr()) && // 1st in tile.
     
    397443
    398444ParameterSetManagerDecoder::ParameterSetManagerDecoder()
    399 #if SVC_EXTENSION
    400 : m_spsBuffer(MAX_NUM_SPS)
    401 , m_ppsBuffer(MAX_NUM_PPS)
    402 #else
     445#if !SVC_EXTENSION
    403446: m_vpsBuffer(MAX_NUM_VPS)
    404447, m_spsBuffer(MAX_NUM_SPS)
  • trunk/source/Lib/TLibDecoder/TDecSlice.h

    r644 r906  
    110110#if SVC_EXTENSION
    111111  static ParameterSetMap<TComVPS> m_vpsBuffer;
     112  static ParameterSetMap<TComSPS> m_spsBuffer;
     113  static ParameterSetMap<TComPPS> m_ppsBuffer;
    112114#else
    113115  ParameterSetMap<TComVPS> m_vpsBuffer;
    114 #endif
    115116  ParameterSetMap<TComSPS> m_spsBuffer;
    116117  ParameterSetMap<TComPPS> m_ppsBuffer;
     118#endif
    117119};
    118120
  • trunk/source/Lib/TLibDecoder/TDecTop.cpp

    r815 r906  
    4343UInt  TDecTop::m_uiPrevLayerId = MAX_UINT;
    4444Bool  TDecTop::m_bFirstSliceInSequence = true;
     45#if POC_RESET_RESTRICTIONS
     46Bool  TDecTop::m_checkPocRestrictionsForCurrAu       = false;
     47Int   TDecTop::m_pocResetIdcOrCurrAu                 = -1;
     48Bool  TDecTop::m_baseLayerIdrFlag                    = false;
     49Bool  TDecTop::m_baseLayerPicPresentFlag             = false;
     50Bool  TDecTop::m_baseLayerIrapFlag                   = false;
     51Bool  TDecTop::m_nonBaseIdrPresentFlag               = false;
     52Int   TDecTop::m_nonBaseIdrType                      = -1;
     53Bool  TDecTop::m_picNonIdrWithRadlPresentFlag        = false;
     54Bool  TDecTop::m_picNonIdrNoLpPresentFlag            = false;
     55#endif
     56#if POC_RESET_VALUE_RESTRICTION
     57Int   TDecTop::m_crossLayerPocResetPeriodId          = -1;
     58Int   TDecTop::m_crossLayerPocResetIdc               = -1;
     59#endif
    4560#endif
    4661
     
    7489  memset(m_cIlpPic, 0, sizeof(m_cIlpPic));
    7590#endif
    76 #if AVC_SYNTAX || SYNTAX_OUTPUT
    77   m_pBLSyntaxFile = NULL;
    78 #endif
    7991  m_prevSliceSkipped = false;
    8092  m_skippedPOC = 0;
     
    105117#endif
    106118
    107 #if Q0074_SEI_COLOR_MAPPING
    108   m_ColorMapping = new TDecColorMapping();
     119#if POC_RESET_RESTRICTIONS
     120  resetPocRestrictionCheckParameters();
     121#endif
     122#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     123  m_pocResettingFlag        = false;
     124  m_pocDecrementedInDPBFlag = false;
    109125#endif
    110126}
     
    112128TDecTop::~TDecTop()
    113129{
    114 #if Q0078_ADD_LAYER_SETS
    115   for (Int psId = 0; psId < MAX_NUM_SPS; psId++)
    116   {
    117     TComSPS* sps = m_parameterSetManagerDecoder.getSPS(psId);
    118     if (sps != NULL)
    119     {
    120       // Remove parameter set from other layers to prevent multiple deletes of the same object
    121       for (Int lId = 0; lId < m_numLayer; lId++)
    122       {
    123         if (m_ppcTDecTop[lId] != this)
    124         {
    125           m_parameterSetManagerDecoder.removeSPS(psId);
    126         }
    127       }
    128     }
    129   }
    130   for (Int psId = 0; psId < MAX_NUM_PPS; psId++)
    131   {
    132     TComPPS* pps = m_parameterSetManagerDecoder.getPPS(psId);
    133     if (pps != NULL)
    134     {
    135       // Remove parameter set from other layers to prevent multiple deletes of the same object
    136       for (Int lId = 0; lId < m_numLayer; lId++)
    137       {
    138         if (m_ppcTDecTop[lId] != this)
    139         {
    140           m_parameterSetManagerDecoder.removePPS(psId);
    141         }
    142       }
    143     }
    144   }
    145 #endif
    146130#if ENC_DEC_TRACE
    147131  fclose( g_hTrace );
     
    154138    m_pColorMappedPic = NULL;
    155139  }
    156 #endif
    157 #if Q0074_SEI_COLOR_MAPPING
    158   if ( m_ColorMapping )  delete m_ColorMapping;
    159140#endif
    160141}
     
    188169      m_cIlpPic[i] = NULL;
    189170    }
    190   }   
     171  }
    191172#endif
    192173}
     
    237218
    238219    Int  numReorderPics[MAX_TLAYER];
     220#if R0156_CONF_WINDOW_IN_REP_FORMAT
     221    Window &conformanceWindow = slice->getConformanceWindow();
     222#else
    239223    Window &conformanceWindow = pcSPS->getConformanceWindow();
     224#endif
    240225    Window defaultDisplayWindow = pcSPS->getVuiParametersPresentFlag() ? pcSPS->getVuiParameters()->getDefaultDisplayWindow() : Window();
    241226
     
    326311{
    327312  Int  numReorderPics[MAX_TLAYER];
     313#if R0156_CONF_WINDOW_IN_REP_FORMAT
     314  Window &conformanceWindow = pcSlice->getConformanceWindow();
     315#else
    328316  Window &conformanceWindow = pcSlice->getSPS()->getConformanceWindow();
     317#endif
    329318  Window defaultDisplayWindow = pcSlice->getSPS()->getVuiParametersPresentFlag() ? pcSlice->getSPS()->getVuiParameters()->getDefaultDisplayWindow() : Window();
    330319
     
    362351#else
    363352    m_iMaxRefPicNum = pcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1( getCommonDecoderParams()->getTargetOutputLayerSetIdx(), pcSlice->getLayerId(), pcSlice->getTLayer() ) + 1; // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
     353    //TODO: HENDRY -- Do the checking here.
    364354#endif
    365355  }
     
    381371      for(UInt i = 0; i < pcSlice->getVPS()->getNumDirectRefLayers( m_layerId ); i++ )
    382372      {
     373#if MOVE_SCALED_OFFSET_TO_PPS
     374#if O0098_SCALED_REF_LAYER_ID
     375        const Window scalEL = pcSlice->getPPS()->getScaledRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, i));
     376#else
     377        const Window scalEL = pcSlice->getPPS()->getScaledRefLayerWindow(i);
     378#endif
     379#else
    383380#if O0098_SCALED_REF_LAYER_ID
    384381        const Window scalEL = pcSlice->getSPS()->getScaledRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, i));
     
    386383        const Window scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(i);
    387384#endif
     385#endif
     386#if REF_REGION_OFFSET
     387        const Window refEL = pcSlice->getPPS()->getRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, i));
     388#if RESAMPLING_FIX
     389        Bool equalOffsets = scalEL.hasEqualOffset(refEL);
     390#if R0209_GENERIC_PHASE
     391        Bool zeroPhase = pcSlice->getPPS()->hasZeroResamplingPhase(pcSlice->getVPS()->getRefLayerId(m_layerId, i));
     392#endif
     393#else
     394        Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0
     395                             && refEL.getWindowLeftOffset() == 0 && refEL.getWindowRightOffset() == 0 && refEL.getWindowTopOffset() == 0 && refEL.getWindowBottomOffset() == 0 );
     396#endif
     397#else
    388398        Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0 );
     399#endif
    389400
    390401#if VPS_EXTN_DIRECT_REF_LAYERS
     
    400411        Bool sameBitDepths = ( g_bitDepthYLayer[m_layerId] == g_bitDepthYLayer[refLayerId] ) && ( g_bitDepthCLayer[m_layerId] == g_bitDepthCLayer[refLayerId] );
    401412
    402         if( pcPicYuvRecBase->getWidth() != pcSlice->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getPicHeightInLumaSamples() || !zeroOffsets || !sameBitDepths
     413#if REF_IDX_MFM
     414        if( pcPicYuvRecBase->getWidth() == pcSlice->getPicWidthInLumaSamples() && pcPicYuvRecBase->getHeight() == pcSlice->getPicHeightInLumaSamples() && equalOffsets && zeroPhase )
     415        {
     416          rpcPic->setEqualPictureSizeAndOffsetFlag( i, true );
     417        }
     418
     419        if( !rpcPic->equalPictureSizeAndOffsetFlag(i) || !sameBitDepths
     420#else
     421        if( pcPicYuvRecBase->getWidth() != pcSlice->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getPicHeightInLumaSamples() || !sameBitDepths
     422#if REF_REGION_OFFSET && RESAMPLING_FIX
     423          || !equalOffsets
     424#if R0209_GENERIC_PHASE
     425          || !zeroPhase
     426#endif
     427#else
     428          || !zeroOffsets
     429#endif
     430#endif
    403431#if Q0048_CGS_3D_ASYMLUT
    404432          || pcSlice->getPPS()->getCGSFlag() > 0
     
    409437          )
    410438#else
    411         if(pcPicYuvRecBase->getWidth() != pcSlice->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getPicHeightInLumaSamples() || !zeroOffsets )
    412 #endif
    413 #else
    414         if(pcPicYuvRecBase->getWidth() != pcSlice->getSPS()->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getSPS()->getPicHeightInLumaSamples() || !zeroOffsets )
     439        if(pcPicYuvRecBase->getWidth() != pcSlice->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getPicHeightInLumaSamples()
     440#if REF_REGION_OFFSET && RESAMPLING_FIX
     441          || !equalOffsets
     442#if R0209_GENERIC_PHASE
     443          || !zeroPhase
     444#endif
     445#else
     446          || !zeroOffsets
     447#endif
     448        )
     449#endif
     450#else
     451        if(pcPicYuvRecBase->getWidth() != pcSlice->getSPS()->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getSPS()->getPicHeightInLumaSamples()
     452#if REF_REGION_OFFSET && RESAMPLING_FIX
     453          || !equalOffsets
     454#if R0209_GENERIC_PHASE
     455          || !zeroPhase
     456#endif
     457#else
     458          || !zeroOffsets
     459#endif
     460        )
    415461#endif
    416462        {
     
    522568  m_cGopDecoder.filterPicture(pcPic);
    523569
    524 #if SYNTAX_OUTPUT
    525   pcPic->wrireBLSyntax( getBLSyntaxFile(), SYNTAX_BYTES );
    526 #endif
    527570  TComSlice::sortPicList( m_cListPic ); // sorting for application output
    528571  poc                 = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
     
    713756
    714757    // When avc_base_layer_flag is equal to 1, it is a requirement of bitstream conformance that the value of sps_scaling_list_ref_layer_id shall be greater than 0
     758#if VPS_AVC_BL_FLAG_REMOVAL
     759    if( activeVPS->getNonHEVCBaseLayerFlag() )
     760#else
    715761    if( activeVPS->getAvcBaseLayerFlag() )
     762#endif
    716763    {
    717764      assert( refLayerId > 0 );
     
    742789
    743790    // When avc_base_layer_flag is equal to 1, it is a requirement of bitstream conformance that the value of sps_scaling_list_ref_layer_id shall be greater than 0
     791#if VPS_AVC_BL_FLAG_REMOVAL
     792    if( activeVPS->getNonHEVCBaseLayerFlag() )
     793#else
    744794    if( activeVPS->getAvcBaseLayerFlag() )
     795#endif
    745796    {
    746797      assert( refLayerId > 0 );
     
    768819
    769820#if AVC_BASE
     821#if VPS_AVC_BL_FLAG_REMOVAL
     822  if( activeVPS->getNonHEVCBaseLayerFlag() )
     823#else
    770824  if( activeVPS->getAvcBaseLayerFlag() )
     825#endif
    771826  {
    772827    TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin());
     
    777832
    778833      Int  numReorderPics[MAX_TLAYER];
     834#if !R0156_CONF_WINDOW_IN_REP_FORMAT
    779835      Window conformanceWindow;
     836#endif
    780837      Window defaultDisplayWindow;
    781838
     839#if R0156_CONF_WINDOW_IN_REP_FORMAT
    782840#if AUXILIARY_PICTURES
    783 #if AVC_SYNTAX
    784       pBLPic->create( repFormat->getPicWidthVpsInLumaSamples(), repFormat->getPicHeightVpsInLumaSamples(), repFormat->getChromaFormatVpsIdc(), activeSPS->getMaxCUWidth(), activeSPS->getMaxCUHeight(), activeSPS->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, activeSPS, true);
    785 #else
     841      pBLPic->create( repFormat->getPicWidthVpsInLumaSamples(), repFormat->getPicHeightVpsInLumaSamples(), repFormat->getChromaFormatVpsIdc(), activeSPS->getMaxCUWidth(), activeSPS->getMaxCUHeight(), activeSPS->getMaxCUDepth(), repFormat->getConformanceWindowVps(), defaultDisplayWindow, numReorderPics, NULL, true);
     842#else
     843      pBLPic->create( repFormat->getPicWidthVpsInLumaSamples(), repFormat->getPicHeightVpsInLumaSamples(), activeSPS->getMaxCUWidth(), activeSPS->getMaxCUHeight(), activeSPS->getMaxCUDepth(), repFormat->getConformanceWindowVps(), defaultDisplayWindow, numReorderPics, NULL, true);
     844#endif
     845#else
     846#if AUXILIARY_PICTURES
    786847      pBLPic->create( repFormat->getPicWidthVpsInLumaSamples(), repFormat->getPicHeightVpsInLumaSamples(), repFormat->getChromaFormatVpsIdc(), activeSPS->getMaxCUWidth(), activeSPS->getMaxCUHeight(), activeSPS->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, NULL, true);
    787 #endif
    788 #else
    789 #if AVC_SYNTAX
    790       pBLPic->create( repFormat->getPicWidthVpsInLumaSamples(), repFormat->getPicHeightVpsInLumaSamples(), activeSPS->getMaxCUWidth(), activeSPS->getMaxCUHeight(), activeSPS->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, activeSPS, true);
    791848#else
    792849      pBLPic->create( repFormat->getPicWidthVpsInLumaSamples(), repFormat->getPicHeightVpsInLumaSamples(), activeSPS->getMaxCUWidth(), activeSPS->getMaxCUHeight(), activeSPS->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, NULL, true);
     
    805862
    806863#if P0312_VERT_PHASE_ADJ
     864#if MOVE_SCALED_OFFSET_TO_PPS
     865  if( activeVPS->getVpsVuiVertPhaseInUseFlag() == 0 )
     866  {   
     867    for(Int i = 0; i < activePPS->getNumScaledRefLayerOffsets(); i++)
     868    {
     869      UInt scaledRefLayerId = activePPS->getScaledRefLayerId(i);
     870      if( activePPS->getVertPhasePositionEnableFlag( scaledRefLayerId ) )
     871      {
     872        printf("\nWarning: LayerId = %d: vert_phase_position_enable_flag[%d] = 1, however indication vert_phase_position_in_use_flag = 0\n", m_layerId, scaledRefLayerId );
     873        break;
     874      }
     875    }
     876  }
     877#else
    807878  if( activeVPS->getVpsVuiVertPhaseInUseFlag() == 0 )
    808879  {   
     
    817888    }
    818889  }
     890#endif
    819891#endif
    820892
     
    868940  pps->setSPS(sps);
    869941#if REPN_FORMAT_IN_VPS
    870   pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1);
    871 #else
    872   pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1);
     942  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumTileColumnsMinus1() + 1) : 1);
     943#else
     944  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumTileColumnsMinus1() + 1) : 1);
    873945#endif
    874946  pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
     
    885957  g_uiMaxCUDepth  = sps->getMaxCUDepth();
    886958  g_uiAddCUDepth  = max (0, sps->getLog2MinCodingBlockSize() - (Int)sps->getQuadtreeTULog2MinSize() );
    887 
    888 #if Q0074_SEI_COLOR_MAPPING
    889   for(Int compID=0; compID<3; compID++)
    890   {
    891     m_ColorMapping->setColorMapping( compID ? g_bitDepthC : g_bitDepthY, compID );
    892   }
    893 #endif
    894959
    895960  for (Int i = 0; i < sps->getLog2DiffMaxMinCodingBlockSize(); i++)
     
    9531018
    9541019  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
     1020#if POC_RESET_RESTRICTIONS
     1021  m_apcSlicePilot->setTLayer( nalu.m_temporalId );
     1022#endif
    9551023  Bool nonReferenceFlag = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N ||
    9561024                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N   ||
     
    10181086  }
    10191087
     1088  //TODO: HENDRY -- Probably do the checking for max number of positive and negative pics here
     1089
     1090
    10201091  //For inference of PicOutputFlag
    10211092  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R)
     
    11091180  }
    11101181#endif
     1182
    11111183#if POC_RESET_IDC_DECODER
    11121184  if( m_parseIdc != -1 ) // Second pass for a POC resetting picture
     
    11291201    if(( m_layerId < m_uiPrevLayerId) ||( ( m_layerId == m_uiPrevLayerId) && bNewPOC)) // Decoding a lower layer than or same layer as previous - mark all earlier pictures as not in current AU
    11301202    {
     1203#if POC_RESET_RESTRICTIONS
     1204      // New access unit; reset all variables related to POC reset restrictions
     1205      resetPocRestrictionCheckParameters();
     1206#endif
    11311207      markAllPicsAsNoCurrAu();
    1132     }
     1208#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     1209      for (UInt i = 0; i < MAX_LAYERS; i++)
     1210      {
     1211        m_ppcTDecTop[i]->m_pocDecrementedInDPBFlag = false;
     1212      }
     1213#endif
     1214    }
     1215
     1216
     1217#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     1218    m_pocResettingFlag = false;
     1219
     1220    if (m_apcSlicePilot->getPocResetIdc() != 0)
     1221    {
     1222      if (m_apcSlicePilot->getVPS()->getVpsPocLsbAlignedFlag())
     1223      {
     1224        m_pocResettingFlag = true;
     1225      }
     1226      else if (m_pocDecrementedInDPBFlag)
     1227      {
     1228        m_pocResettingFlag = false;
     1229      }
     1230      else
     1231      {
     1232        m_pocResettingFlag = true;
     1233      }
     1234    }
     1235#endif
    11331236
    11341237    if( m_apcSlicePilot->getPocResetIdc() && m_apcSlicePilot->getSliceIdx() == 0 )
     
    11411244        m_parseIdc = 0;
    11421245      }
     1246#if POC_RESET_VALUE_RESTRICTION
     1247      // Check if the POC Reset period ID matches with the Reset Period ID
     1248      if( pocResetPeriodId == m_crossLayerPocResetPeriodId )
     1249      {
     1250        // If matching, and current poc_reset_idc = 3, then the values should match
     1251        if( m_apcSlicePilot->getPocResetIdc() == 3 )
     1252        {
     1253          assert( ( m_apcSlicePilot->getFullPocResetFlag() == false && m_crossLayerPocResetIdc == 1 ) ||
     1254                  ( m_apcSlicePilot->getFullPocResetFlag() == true  && m_crossLayerPocResetIdc == 2 ) );
     1255        }
     1256      }
     1257      else
     1258      {
     1259        // This is the first picture of a POC resetting access unit
     1260        m_crossLayerPocResetPeriodId = pocResetPeriodId;
     1261        if( m_apcSlicePilot->getPocResetIdc() == 1 || m_apcSlicePilot->getPocResetIdc() == 2 )
     1262        {
     1263          m_crossLayerPocResetIdc = m_apcSlicePilot->getPocResetIdc();
     1264        }
     1265        else
     1266        { // poc_reset_idc = 3
     1267          // In this case, the entire POC resetting access unit has been lost.
     1268          // Need more checking to ensure poc_reset_idc = 3 works.
     1269          assert ( 0 );
     1270        }
     1271      }
     1272#endif
    11431273    }
    11441274    else
    11451275    {
    11461276      m_parseIdc = 3; // Proceed to decoding POC and RPS
    1147     } 
     1277    }
    11481278  }
    11491279#endif
     
    11511281#if ALIGNED_BUMPING
    11521282#if POC_RESET_IDC_DECODER
     1283
     1284#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     1285  UInt affectedLayerList[MAX_NUM_LAYER_IDS];
     1286  Int  numAffectedLayers;
     1287
     1288  affectedLayerList[0] = m_apcSlicePilot->getLayerId();
     1289  numAffectedLayers = 1;
     1290
     1291  if (m_apcSlicePilot->getVPS()->getVpsPocLsbAlignedFlag())
     1292  {
     1293    for (UInt j = 0; j < m_apcSlicePilot->getVPS()->getNumPredictedLayers(m_apcSlicePilot->getLayerId()); j++)
     1294    {
     1295      affectedLayerList[j + 1] = m_apcSlicePilot->getVPS()->getPredictedLayerId(m_apcSlicePilot->getLayerId(), j);
     1296    }
     1297    numAffectedLayers = m_apcSlicePilot->getVPS()->getNumPredictedLayers(m_apcSlicePilot->getLayerId()) + 1;
     1298  }
     1299#endif
     1300
    11531301  //if(  (bNewPOC || m_layerId != m_uiPrevLayerId) && ( m_parseIdc != 1) )
    1154   if( m_parseIdc == 1 )
     1302#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     1303  if (m_parseIdc == 1 && m_pocResettingFlag)
     1304#else
     1305  if (m_parseIdc == 1)
     1306#endif
    11551307  {
    11561308    // Invoke output of pictures if the current picture is a POC reset picture
     
    12031355    Int deltaPocVal  =  pocMsbDelta + pocLsbDelta;
    12041356
     1357#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     1358    for (UInt layerIdx = 0; layerIdx < numAffectedLayers; layerIdx++)
     1359    {
     1360      if (!m_ppcTDecTop[affectedLayerList[layerIdx]]->m_pocDecrementedInDPBFlag)
     1361      {
     1362        m_ppcTDecTop[affectedLayerList[layerIdx]]->m_pocDecrementedInDPBFlag = true;
     1363        TComList<TComPic*>::iterator  iterPic = m_ppcTDecTop[affectedLayerList[layerIdx]]->getListPic()->begin();
     1364        while (iterPic != m_ppcTDecTop[affectedLayerList[layerIdx]]->getListPic()->end())
     1365#else
    12051366    //Reset all POC for DPB -> basically do it for each slice in the picutre
    12061367    TComList<TComPic*>::iterator  iterPic = m_cListPic.begin(); 
     
    12081369    // Iterate through all picture in DPB
    12091370    while( iterPic != m_cListPic.end() )
     1371#endif
    12101372    {
    12111373      TComPic *dpbPic = *iterPic;
    12121374      // Check if the picture pointed to by iterPic is either used for reference or
    12131375      // needed for output, are in the same layer, and not the current picture.
    1214       if( /*  ( ( dpbPic->getSlice(0)->isReferenced() ) || ( dpbPic->getOutputMark() ) )
     1376#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     1377      assert(dpbPic->getLayerId() == affectedLayerList[layerIdx]);
     1378      if ( (dpbPic->getReconMark()) && (dpbPic->getPicSym()->getSlice(0)->getPicOutputFlag()) )
     1379#else
     1380      if ( /*  ( ( dpbPic->getSlice(0)->isReferenced() ) || ( dpbPic->getOutputMark() ) )
    12151381          &&*/ ( dpbPic->getLayerId() == m_apcSlicePilot->getLayerId() )
    12161382            && ( dpbPic->getReconMark() ) && ( dpbPic->getPicSym()->getSlice(0)->getPicOutputFlag() ))
     1383#endif
    12171384      {
    12181385        for(Int i = dpbPic->getNumAllocatedSlice()-1; i >= 0; i--)
     
    12411408      iterPic++;
    12421409    }
     1410#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     1411        // Update the value of pocCRA
     1412        m_ppcTDecTop[affectedLayerList[layerIdx]]->m_pocCRA -= deltaPocVal;
     1413      }
     1414    }
     1415#else
    12431416    // Update the value of pocCRA
    12441417    m_pocCRA -= deltaPocVal;
     1418#endif
    12451419
    12461420    // Update value of POCLastDisplay
     
    12501424  Int slicePicOrderCntLsb = m_apcSlicePilot->getPicOrderCntLsb();
    12511425
    1252   if( m_parseIdc == 1 || m_parseIdc == 2 ) // TODO This should be replaced by pocResettingFlag.
     1426#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     1427  if (m_pocResettingFlag && (m_parseIdc == 1 || m_parseIdc == 2))
     1428#else
     1429  if (m_parseIdc == 1 || m_parseIdc == 2) // TODO This should be replaced by pocResettingFlag.
     1430#endif
    12531431  {
    12541432    // Set poc for current slice
     
    12961474        && !m_apcSlicePilot->getDiscardableFlag() )
    12971475    {
     1476#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     1477      for (UInt i = 0; i < numAffectedLayers; i++)
     1478      {
     1479        m_ppcTDecTop[affectedLayerList[i]]->setPrevPicOrderCnt(m_apcSlicePilot->getPOC());
     1480      }
     1481#else
    12981482      this->setPrevPicOrderCnt( m_apcSlicePilot->getPOC() );
     1483#endif
    12991484    }
    13001485    else if ( m_apcSlicePilot->getPocResetIdc() == 3 )
    13011486    {
     1487#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     1488      if (!m_firstPicInLayerDecodedFlag || (m_firstPicInLayerDecodedFlag && m_pocResettingFlag))
     1489      {
     1490        for (UInt i = 0; i < numAffectedLayers; i++)
     1491        {
     1492          m_ppcTDecTop[affectedLayerList[i]]->setPrevPicOrderCnt( m_apcSlicePilot->getFullPocResetFlag()
     1493                                                                  ? 0 : m_apcSlicePilot->getPocLsbVal() );
     1494        }
     1495      }
     1496#else
    13021497      this->setPrevPicOrderCnt( m_apcSlicePilot->getFullPocResetFlag()
    13031498                                            ? 0 : m_apcSlicePilot->getPocLsbVal() );
     1499#endif
    13041500    }
    13051501#else
     
    13241520#if POC_RESET_IDC_DECODER
    13251521  m_parseIdc = -1;
     1522#endif
     1523
     1524
     1525#if R0226_SLICE_TMVP
     1526  if ( m_apcSlicePilot->getTLayer() == 0 && m_apcSlicePilot->getEnableTMVPFlag() == 0 )
     1527  {
     1528    //update all pics in the DPB such that they cannot be used for TMPV ref
     1529    TComList<TComPic*>::iterator  iterRefPic = m_cListPic.begin(); 
     1530    while( iterRefPic != m_cListPic.end() )
     1531    {
     1532      TComPic *refPic = *iterRefPic;
     1533      if( ( refPic->getLayerId() == m_apcSlicePilot->getLayerId() ) && refPic->getReconMark() )
     1534      {
     1535        for(Int i = refPic->getNumAllocatedSlice()-1; i >= 0; i--)
     1536        {
     1537
     1538          TComSlice *refSlice = refPic->getSlice(i);
     1539          refSlice->setAvailableForTMVPRefFlag( false );
     1540        }
     1541      }
     1542      iterRefPic++;
     1543    }
     1544  }
     1545  m_apcSlicePilot->setAvailableForTMVPRefFlag( true );
    13261546#endif
    13271547
     
    14831703  {
    14841704#if AVC_BASE
     1705#if VPS_AVC_BL_FLAG_REMOVAL
     1706    if( m_layerId == 1 && m_parameterSetManagerDecoder.getPrefetchedVPS(0)->getNonHEVCBaseLayerFlag() )
     1707#else
    14851708    if( m_layerId == 1 && m_parameterSetManagerDecoder.getPrefetchedVPS(0)->getAvcBaseLayerFlag() )
     1709#endif
    14861710    {
    14871711      TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin());
     
    16111835
    16121836#if POC_RESET_IDC_DECODER
    1613   pcPic->setCurrAuFlag( true );
     1837    pcPic->setCurrAuFlag( true );
     1838#if POC_RESET_RESTRICTIONS
     1839    if( pcPic->getLayerId() > 0 && m_apcSlicePilot->isIDR() && !m_nonBaseIdrPresentFlag )
     1840    {
     1841      // IDR picture with nuh_layer_id > 0 present
     1842      m_nonBaseIdrPresentFlag = true;
     1843      m_nonBaseIdrType = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL);
     1844    }
     1845    else
     1846    {
     1847      if( m_apcSlicePilot->getNalUnitType() != NAL_UNIT_CODED_SLICE_IDR_W_RADL )
     1848      {
     1849        // Picture with nal_unit_type not equal IDR_W_RADL present
     1850        m_picNonIdrWithRadlPresentFlag = true;
     1851      }
     1852      if( m_apcSlicePilot->getNalUnitType() != NAL_UNIT_CODED_SLICE_IDR_N_LP )
     1853      {
     1854        // Picture with nal_unit_type not equal IDR_N_LP present
     1855        m_picNonIdrNoLpPresentFlag = true;
     1856      }
     1857    }
     1858    if( !m_checkPocRestrictionsForCurrAu )  // Will be true for the first slice/picture of the AU
     1859    {
     1860      m_checkPocRestrictionsForCurrAu = true;
     1861      m_pocResetIdcOrCurrAu = m_apcSlicePilot->getPocResetIdc();
     1862      if( pcPic->getLayerId() == 0 )
     1863      {
     1864        // Base layer picture is present
     1865        m_baseLayerPicPresentFlag = true;
     1866        if( m_apcSlicePilot->isIRAP() )
     1867        {
     1868          // Base layer picture is IRAP
     1869          m_baseLayerIrapFlag = true;
     1870        }
     1871        if( m_apcSlicePilot->isIDR() )
     1872        {
     1873          // Base layer picture is IDR
     1874          m_baseLayerIdrFlag = true;
     1875        }
     1876        else
     1877        {
     1878          if( m_apcSlicePilot->getVPS()->getBaseLayerInternalFlag())
     1879          {
     1880            /* When the picture with nuh_layer_id equal to 0 in an access unit is not an IDR picture
     1881            and vps_base_layer_internal_flag is equal to 1, the value of poc_reset_idc shall not be equal to 2
     1882            for any picture in the access unit. */
     1883            assert( m_apcSlicePilot->getPocResetIdc() != 2 );
     1884          }
     1885        }
     1886      }
     1887    }
     1888    else
     1889    {
     1890      // The value of poc_reset_idc of all coded pictures that are present in the bitstream in an access unit shall be the same.
     1891      assert( m_pocResetIdcOrCurrAu == m_apcSlicePilot->getPocResetIdc() );
     1892
     1893      /* When the picture in an access unit with nuh_layer_id equal to 0 is an IRAP picture and vps_base_layer_internal_flag is equal to 1
     1894      and there is at least one other picture in the same access unit that is not an IRAP picture,
     1895      the value of poc_reset_idc shall be equal to 1 or 2 for all pictures in the access unit. */
     1896      if( m_baseLayerPicPresentFlag && m_baseLayerIrapFlag && !m_apcSlicePilot->isIRAP() && m_apcSlicePilot->getVPS()->getBaseLayerInternalFlag() )
     1897      {
     1898        assert( m_apcSlicePilot->getPocResetIdc() == 1 || m_apcSlicePilot->getPocResetIdc() == 2 );
     1899      }
     1900
     1901      /* When the picture with nuh_layer_id equal to 0 in an access unit is an IDR picture and
     1902      vps_base_layer_internal_flag is equal to 1 and there is at least one non-IDR picture in the same access unit,
     1903      the value of poc_reset_idc shall be equal to 2 for all pictures in the access unit. */
     1904      if( m_baseLayerPicPresentFlag && m_baseLayerIdrFlag && !m_apcSlicePilot->isIDR() && m_apcSlicePilot->getVPS()->getBaseLayerInternalFlag() )
     1905      {
     1906        assert( m_apcSlicePilot->getPocResetIdc() == 2 );
     1907      }
     1908
     1909      /* When there is at least one picture that has nuh_layer_id greater than 0 and that is an IDR picture
     1910      with a particular value of nal_unit_type in an access unit and there is at least one other coded picture
     1911      that is present in the bitstream in the same access unit with a different value of nal_unit_type,
     1912      the value of poc_reset_idc shall be equal to 1 or 2 for all pictures in the access unit. */
     1913      if( m_nonBaseIdrPresentFlag && (
     1914            ( m_nonBaseIdrType == 1 && m_picNonIdrWithRadlPresentFlag ) ||
     1915            ( m_nonBaseIdrType == 0 && m_picNonIdrNoLpPresentFlag )
     1916        ))
     1917      {
     1918        assert( m_apcSlicePilot->getPocResetIdc() == 1 || m_apcSlicePilot->getPocResetIdc() == 2 );
     1919      }
     1920    }
     1921#endif
    16141922#endif
    16151923
     
    16271935        isTff =  (pictureTiming->m_picStruct == 1);
    16281936      }
     1937
     1938#if R0226_CONSTRAINT_TMVP_SEI
     1939      // Check if any new temporal motion vector prediction constraints SEI has arrived
     1940      SEIMessages seiTMVPConstrainsList = extractSeisByType (m_SEIs, SEI::TMVP_CONSTRAINTS);
     1941      if (seiTMVPConstrainsList.size() > 0)
     1942      {
     1943        assert ( pcPic->getTLayer() == 0 );  //this SEI can present only for AU with Tid equal to 0
     1944        SEITMVPConstrains* tmvpConstraintSEI = (SEITMVPConstrains*) *(seiTMVPConstrainsList.begin());
     1945        if ( tmvpConstraintSEI->prev_pics_not_used_flag == 1 )
     1946        {
     1947          //update all pics in the DPB such that they cannot be used for TMPV ref
     1948          TComList<TComPic*>::iterator  iterRefPic = m_cListPic.begin(); 
     1949          while( iterRefPic != m_cListPic.end() )
     1950          {
     1951            TComPic *refPic = *iterRefPic;
     1952            if( ( refPic->getLayerId() == pcPic->getLayerId() ) && refPic->getReconMark() )
     1953            {
     1954              for(Int i = refPic->getNumAllocatedSlice()-1; i >= 0; i--)
     1955              {
     1956                TComSlice *refSlice = refPic->getSlice(i);
     1957                refSlice->setAvailableForTMVPRefFlag( false );
     1958              }
     1959            }
     1960            iterRefPic++;
     1961          }
     1962        }
     1963      }
     1964#endif
    16291965    }
    16301966   
     
    16652001  Bool bNextSlice     = pcSlice->isNextSlice();
    16662002
    1667   UInt uiCummulativeTileWidth;
    1668   UInt uiCummulativeTileHeight;
    1669   UInt i, j, p;
    1670 
    1671   //set NumColumnsMins1 and NumRowsMinus1
    1672   pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() );
    1673   pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() );
    1674 
    1675   //create the TComTileArray
    1676   pcPic->getPicSym()->xCreateTComTileArray();
    1677 
    1678   if( pcSlice->getPPS()->getUniformSpacingFlag() )
    1679   {
    1680     //set the width for each tile
    1681     for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
    1682     {
    1683       for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
    1684       {
    1685         pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
    1686           setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1)
    1687           - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
    1688       }
    1689     }
    1690 
    1691     //set the height for each tile
    1692     for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
    1693     {
    1694       for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
    1695       {
    1696         pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
    1697           setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1)
    1698           - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
    1699       }
    1700     }
    1701   }
    1702   else
    1703   {
    1704     //set the width for each tile
    1705     for(j=0; j < pcSlice->getPPS()->getNumRowsMinus1()+1; j++)
    1706     {
    1707       uiCummulativeTileWidth = 0;
    1708       for(i=0; i < pcSlice->getPPS()->getNumColumnsMinus1(); i++)
    1709       {
    1710         pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getPPS()->getColumnWidth(i) );
    1711         uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(i);
    1712       }
    1713       pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
    1714     }
    1715 
    1716     //set the height for each tile
    1717     for(j=0; j < pcSlice->getPPS()->getNumColumnsMinus1()+1; j++)
    1718     {
    1719       uiCummulativeTileHeight = 0;
    1720       for(i=0; i < pcSlice->getPPS()->getNumRowsMinus1(); i++)
    1721       {
    1722         pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getPPS()->getRowHeight(i) );
    1723         uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(i);
    1724       }
    1725       pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
    1726     }
    1727   }
    1728 
    1729   pcPic->getPicSym()->xInitTiles();
     2003  UInt i;
     2004  pcPic->getPicSym()->initTiles(pcSlice->getPPS());
    17302005
    17312006  //generate the Coding Order Map and Inverse Coding Order Map
     
    17932068        UInt refLayerId = pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc);
    17942069#if AVC_BASE
     2070#if VPS_AVC_BL_FLAG_REMOVAL
     2071        if( refLayerId == 0 && m_parameterSetManagerDecoder.getActiveVPS()->getNonHEVCBaseLayerFlag() )
     2072#else
    17952073        if( refLayerId == 0 && m_parameterSetManagerDecoder.getActiveVPS()->getAvcBaseLayerFlag() )
     2074#endif
    17962075        {         
    17972076          TComPic* pic = *m_ppcTDecTop[0]->getListPic()->begin();
     
    18052084            continue;
    18062085          }
    1807 #if AVC_SYNTAX
    1808           TComPic* pBLPic = pcSlice->getBaseColPic(refLayerIdc);
    1809           if( pcSlice->getPOC() == 0 )
    1810           {
    1811             // initialize partition order.
    1812             UInt* piTmp = &g_auiZscanToRaster[0];
    1813             initZscanToRaster( pBLPic->getPicSym()->getMaxDepth() + 1, 1, 0, piTmp );
    1814             initRasterToZscan( pBLPic->getPicSym()->getMaxCUWidth(), pBLPic->getPicSym()->getMaxCUHeight(), pBLPic->getPicSym()->getMaxDepth() + 1 );
    1815           }     
    1816           pBLPic->getSlice( 0 )->initBaseLayerRPL( pcSlice );
    1817           pBLPic->readBLSyntax( m_ppcTDecTop[0]->getBLSyntaxFile(), SYNTAX_BYTES );
    1818 #endif
    18192086        }
    18202087        else
     
    18412108#endif
    18422109
     2110#if MOVE_SCALED_OFFSET_TO_PPS
     2111#if O0098_SCALED_REF_LAYER_ID
     2112        const Window &scalEL = pcSlice->getPPS()->getScaledRefLayerWindowForLayer(refLayerId);
     2113#else
     2114        const Window &scalEL = pcSlice->getPPS()->getScaledRefLayerWindow(refLayerIdc);
     2115#endif
     2116#else
    18432117#if O0098_SCALED_REF_LAYER_ID
    18442118        const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindowForLayer(refLayerId);
     
    18462120        const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc);
    18472121#endif
    1848 
     2122#endif
     2123
     2124#if REF_REGION_OFFSET
     2125        const Window &windowRL = pcSlice->getPPS()->getRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc));
     2126        Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth() - windowRL.getWindowLeftOffset() - windowRL.getWindowRightOffset();
     2127        Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight() - windowRL.getWindowTopOffset() - windowRL.getWindowBottomOffset();
     2128#else
    18492129        Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth();
    18502130        Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight();
     
    18552135        heightBL -= ( confBL.getWindowTopOffset() + confBL.getWindowBottomOffset() ) * TComSPS::getWinUnitY( chromaFormatIdc );
    18562136#endif
     2137#endif
    18572138        Int widthEL   = pcPic->getPicYuvRec()->getWidth()  - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
    18582139        Int heightEL  = pcPic->getPicYuvRec()->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
    18592140
     2141#if RESAMPLING_FIX
     2142#if REF_REGION_OFFSET
     2143        // conformance check: the values of RefLayerRegionWidthInSamplesY, RefLayerRegionHeightInSamplesY, ScaledRefRegionWidthInSamplesY and ScaledRefRegionHeightInSamplesY shall be greater than 0
     2144        assert(widthEL > 0 && heightEL > 0 && widthBL > 0 && widthEL > 0);
     2145
     2146        // conformance check: ScaledRefRegionWidthInSamplesY shall be greater or equal to RefLayerRegionWidthInSamplesY and ScaledRefRegionHeightInSamplesY shall be greater or equal to RefLayerRegionHeightInSamplesY
     2147        assert(widthEL >= widthBL && heightEL >= heightBL);
     2148
     2149#if R0209_GENERIC_PHASE
     2150        // conformance check: when ScaledRefRegionWidthInSamplesY is equal to RefLayerRegionWidthInSamplesY, PhaseHorY shall be equal to 0, when ScaledRefRegionWidthInSamplesC is equal to RefLayerRegionWidthInSamplesC, PhaseHorC shall be equal to 0, when ScaledRefRegionHeightInSamplesY is equal to RefLayerRegionHeightInSamplesY, PhaseVerY shall be equal to 0, and when ScaledRefRegionHeightInSamplesC is equal to RefLayerRegionHeightInSamplesC, PhaseVerC shall be equal to 0.
     2151        Int phaseHorLuma   = pcSlice->getPPS()->getPhaseHorLuma(refLayerIdc);
     2152        Int phaseVerLuma   = pcSlice->getPPS()->getPhaseVerLuma(refLayerIdc);
     2153        Int phaseHorChroma = pcSlice->getPPS()->getPhaseHorChroma(refLayerIdc);
     2154        Int phaseVerChroma = pcSlice->getPPS()->getPhaseVerChroma(refLayerIdc);
     2155        assert( ( (widthEL  != widthBL)  || (phaseHorLuma == 0 && phaseHorChroma == 0) )
     2156             && ( (heightEL != heightBL) || (phaseVerLuma == 0 && phaseVerChroma == 0) ) );
     2157#endif
     2158#endif
     2159#endif
     2160
    18602161        g_mvScalingFactor[refLayerIdc][0] = widthEL  == widthBL  ? 4096 : Clip3(-4096, 4095, ((widthEL  << 8) + (widthBL  >> 1)) / widthBL);
    18612162        g_mvScalingFactor[refLayerIdc][1] = heightEL == heightBL ? 4096 : Clip3(-4096, 4095, ((heightEL << 8) + (heightBL >> 1)) / heightBL);
     
    18662167#if Q0048_CGS_3D_ASYMLUT
    18672168        TComPicYuv* pBaseColRec = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec();
    1868         if( pcSlice->getPPS()->getCGSFlag() )
    1869         {
     2169        if( pcSlice->getPPS()->getCGSFlag()
     2170#if R0150_CGS_SIGNAL_CONSTRAINTS
     2171          && m_c3DAsymLUTPPS.isRefLayer( pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc) )
     2172#endif
     2173          )
     2174        {
     2175#if R0150_CGS_SIGNAL_CONSTRAINTS
     2176          assert( pcSlice->getBaseColPic( refLayerIdc )->getSlice( 0 )->getBitDepthY() == m_c3DAsymLUTPPS.getInputBitDepthY() );
     2177          assert( pcSlice->getBaseColPic( refLayerIdc )->getSlice( 0 )->getBitDepthC() == m_c3DAsymLUTPPS.getInputBitDepthC() );
     2178          assert( pcSlice->getBitDepthY() >= m_c3DAsymLUTPPS.getOutputBitDepthY() );
     2179          assert( pcSlice->getBitDepthY() >= m_c3DAsymLUTPPS.getOutputBitDepthC() );
     2180#endif
    18702181          if(!m_pColorMappedPic)
    18712182          {
     
    18912202#else
    18922203#if Q0048_CGS_3D_ASYMLUT
    1893             m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc), pcSlice->getVPS()->getPhaseAlignFlag() );
    1894 #else
    1895             m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL, pcSlice->getVPS()->getPhaseAlignFlag() );
     2204#if MOVE_SCALED_OFFSET_TO_PPS
     2205          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), pcSlice->getPPS()->getScaledRefLayerWindow(refLayerIdc), pcSlice->getVPS()->getPhaseAlignFlag() );
     2206#else
     2207          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc), pcSlice->getVPS()->getPhaseAlignFlag() );
     2208#endif
     2209#else
     2210          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL, pcSlice->getVPS()->getPhaseAlignFlag() );
    18962211#endif
    18972212#endif
     
    18992214#if O0194_JOINT_US_BITSHIFT
    19002215#if Q0048_CGS_3D_ASYMLUT
    1901             m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL );
    1902 #else
    1903             m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
     2216#if REF_REGION_OFFSET
     2217          m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL, altRL );
     2218#else
     2219          m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL );
     2220#endif
     2221#else
     2222          m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
    19042223#endif
    19052224#else
     
    19282247        UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i);
    19292248#if AVC_BASE
     2249#if VPS_AVC_BL_FLAG_REMOVAL
     2250        if( pcSlice->getVPS()->getRefLayerId( m_layerId, refLayerIdc ) == 0 && m_parameterSetManagerDecoder.getActiveVPS()->getNonHEVCBaseLayerFlag() )
     2251#else
    19302252        if( pcSlice->getVPS()->getRefLayerId( m_layerId, refLayerIdc ) == 0 && m_parameterSetManagerDecoder.getActiveVPS()->getAvcBaseLayerFlag() )
     2253#endif
    19312254        {
    19322255          pcSlice->setBaseColPic ( refLayerIdc, *m_ppcTDecTop[0]->getListPic()->begin() );
    1933 #if AVC_SYNTAX
    1934           TComPic* pBLPic = pcSlice->getBaseColPic(refLayerIdc);
    1935           if( pcSlice->getPOC() == 0 )
    1936           {
    1937             // initialize partition order.
    1938             UInt* piTmp = &g_auiZscanToRaster[0];
    1939             initZscanToRaster( pBLPic->getPicSym()->getMaxDepth() + 1, 1, 0, piTmp );
    1940             initRasterToZscan( pBLPic->getPicSym()->getMaxCUWidth(), pBLPic->getPicSym()->getMaxCUHeight(), pBLPic->getPicSym()->getMaxDepth() + 1 );
    1941           }     
    1942           pBLPic->getSlice( 0 )->initBaseLayerRPL( pcSlice );
    1943           pBLPic->readBLSyntax( m_ppcTDecTop[0]->getBLSyntaxFile(), SYNTAX_BYTES );
    1944 #endif
    19452256        }
    19462257        else
     
    19702281
    19712282#if REF_IDX_MFM
    1972       if( pcSlice->getMFMEnabledFlag() )
    1973       {
    1974         pcSlice->setRefPOCListILP(m_ppcTDecTop[m_layerId]->m_cIlpPic, pcSlice->getBaseColPic());
    1975       }
    19762283      pcSlice->setRefPicList( m_cListPic, false, m_cIlpPic);
    19772284    }
     
    20152322      }
    20162323    }
    2017 
     2324   
    20182325    if( m_layerId > 0 && !pcSlice->isIntra() && pcSlice->getEnableTMVPFlag() )
    20192326    {
     
    20212328
    20222329      assert( refPic );
     2330#if R0226_SLICE_TMVP
     2331      assert ( refPic->getPicSym()->getSlice(0)->getAvailableForTMVPRefFlag() == true );
     2332#endif
    20232333
    20242334      // It is a requirement of bitstream conformance when the collocated picture, used for temporal motion vector prediction, is an inter-layer reference picture,
     
    21002410  //  Decode a picture
    21012411  m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic);
     2412
     2413#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     2414  setFirstPicInLayerDecodedFlag(true);
     2415#endif
    21022416
    21032417  m_bFirstSliceInPicture = false;
     
    21152429}
    21162430
     2431#if SVC_EXTENSION
    21172432Void TDecTop::xDecodeSPS()
    21182433{
    21192434  TComSPS* sps = new TComSPS();
    2120 #if SVC_EXTENSION
    21212435  sps->setLayerId(m_layerId);
    21222436#if SPS_DPB_PARAMS
     
    21262440#endif
    21272441  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
    2128 #if Q0078_ADD_LAYER_SETS
    2129   // Store SPS for all layers
    2130   for (Int lId = 0; lId < m_numLayer; lId++)
    2131   {
    2132     if (m_ppcTDecTop[lId] != this)
    2133     {
    2134       m_ppcTDecTop[lId]->getParameterSetManager()->storePrefetchedSPS(sps);
    2135     }
    2136   }
    2137 #endif
    21382442#if !REPN_FORMAT_IN_VPS   // ILRP can only be initialized at activation 
    21392443  if(m_numLayer>0)
     
    21422446  }
    21432447#endif
    2144 #else //SVC_EXTENSION
    2145   m_cEntropyDecoder.decodeSPS( sps );
    2146   m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
    2147 #endif //SVC_EXTENSION
    21482448}
    21492449
     
    21662466    );
    21672467  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
    2168 #if Q0078_ADD_LAYER_SETS
    2169   // Store PPS for all layers
    2170   for (Int lId = 0; lId < m_numLayer; lId++)
    2171   {
    2172     if (m_ppcTDecTop[lId] != this)
    2173     {
    2174       m_ppcTDecTop[lId]->getParameterSetManager()->storePrefetchedPPS(pps);
    2175     }
    2176   }
    2177 #endif
    2178 
    2179   if( pps->getDependentSliceSegmentsEnabledFlag() )
    2180   {
    2181     Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1;
    2182     m_cSliceDecoder.initCtxMem(NumCtx);
    2183     for ( UInt st = 0; st < NumCtx; st++ )
    2184     {
    2185       TDecSbac* ctx = NULL;
    2186       ctx = new TDecSbac;
    2187       ctx->init( &m_cBinCABAC );
    2188       m_cSliceDecoder.setCtxMem( ctx, st );
    2189     }
    2190   }
    21912468}
     2469#else
     2470Void TDecTop::xDecodeSPS()
     2471{
     2472  TComSPS* sps = new TComSPS();
     2473  m_cEntropyDecoder.decodeSPS( sps );
     2474  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
     2475}
     2476
     2477Void TDecTop::xDecodePPS()
     2478{
     2479  TComPPS* pps = new TComPPS();
     2480  m_cEntropyDecoder.decodePPS( pps );
     2481  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
     2482}
     2483#endif //SVC_EXTENSION
    21922484
    21932485Void TDecTop::xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType )
     
    22172509    {
    22182510      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
     2511#if !R0247_SEI_ACTIVE
    22192512      m_parameterSetManagerDecoder.applyPrefetchedPS();
    22202513      assert(seiAps->activeSeqParameterSetId.size()>0);
     
    22232516        printf ("Warning SPS activation with Active parameter set SEI failed");
    22242517      }
    2225     }
    2226 #if Q0074_SEI_COLOR_MAPPING
    2227     m_ColorMapping->setColorMapping( m_SEIs );
    2228 #endif
     2518#else
     2519      getLayerDec(0)->m_parameterSetManagerDecoder.applyPrefetchedPS();
     2520      assert(seiAps->activeSeqParameterSetId.size()>0);
     2521      if( !getLayerDec(0)->m_parameterSetManagerDecoder.activateSPSWithSEI( seiAps->activeSeqParameterSetId[0] ) )
     2522      {
     2523        printf ("Warning SPS activation with Active parameter set SEI failed");
     2524      }
     2525      for (Int c=1 ; c <= seiAps->numSpsIdsMinus1; c++)
     2526      {
     2527        Int layerIdx = seiAps->layerSpsIdx[c];
     2528        getLayerDec(layerIdx)->m_parameterSetManagerDecoder.applyPrefetchedPS();
     2529        if( !getLayerDec(layerIdx)->m_parameterSetManagerDecoder.activateSPSWithSEI( seiAps->activeSeqParameterSetId[layerIdx] ) )
     2530        {
     2531          printf ("Warning SPS activation with Active parameter set SEI failed");
     2532        }
     2533      }
     2534#endif
     2535    }
    22292536  }
    22302537#else
     
    22872594#endif
    22882595#if AVC_BASE
     2596#if VPS_AVC_BL_FLAG_REMOVAL
     2597      if( m_parameterSetManagerDecoder.getPrefetchedVPS(0)->getNonHEVCBaseLayerFlag() )
     2598#else
    22892599      if( m_parameterSetManagerDecoder.getPrefetchedVPS(0)->getAvcBaseLayerFlag() )
     2600#endif
    22902601      {
    22912602        if( !m_ppcTDecTop[0]->getBLReconFile()->good() )
     
    22942605          exit(EXIT_FAILURE);
    22952606        }       
    2296 #if AVC_SYNTAX
    2297         if( !m_ppcTDecTop[0]->getBLSyntaxFile()->good() )
    2298         {
    2299           printf( "Base layer syntax input reading error\n" );
    2300           exit(EXIT_FAILURE);
    2301         }
    2302 #endif
    23032607      }
    23042608      else
     
    27483052}
    27493053#endif
    2750 
     3054#if POC_RESET_RESTRICTIONS
     3055Void TDecTop::resetPocRestrictionCheckParameters()
     3056{
     3057  TDecTop::m_checkPocRestrictionsForCurrAu       = false;
     3058  TDecTop::m_pocResetIdcOrCurrAu                 = -1;
     3059  TDecTop::m_baseLayerIdrFlag                    = false;
     3060  TDecTop::m_baseLayerPicPresentFlag             = false;
     3061  TDecTop::m_baseLayerIrapFlag                   = false;
     3062  TDecTop::m_nonBaseIdrPresentFlag               = false;
     3063  TDecTop::m_nonBaseIdrType                      = -1;
     3064  TDecTop::m_picNonIdrWithRadlPresentFlag        = false;
     3065  TDecTop::m_picNonIdrNoLpPresentFlag            = false;
     3066}
     3067#endif
    27513068#endif //SVC_EXTENSION
    27523069
    2753 #if Q0074_SEI_COLOR_MAPPING
    2754 TDecColorMapping::TDecColorMapping()
    2755 {
    2756   m_pcColorMappingPic[0]   = NULL;
    2757   m_pcColorMappingPic[1]   = NULL;
    2758 
    2759   m_colorMapCancelFlag  = true;
    2760 
    2761   for( Int i=0 ; i<3 ; i++ )
    2762   {
    2763     m_lut1d_computed[i]             = false;
    2764     m_lut1d_input[i]                = NULL;
    2765     m_coded_input_pivot_value[i]    = NULL;
    2766     m_target_input_pivot_value[i]   = NULL;
    2767   }
    2768   for( Int i=0 ; i<3 ; i++ )
    2769   {
    2770     m_lut1d_output[i]               = NULL;
    2771     m_coded_output_pivot_value[i]   = NULL;
    2772     m_target_output_pivot_value[i]  = NULL;
    2773   }
    2774 }
    2775 
    2776 TDecColorMapping::~TDecColorMapping()
    2777 {
    2778   if ( m_pcColorMappingPic[0] )  delete m_pcColorMappingPic[0];
    2779   if ( m_pcColorMappingPic[1] )  delete m_pcColorMappingPic[1];
    2780 
    2781   for( Int i=0 ; i<3 ; i++ )
    2782   {
    2783     if ( m_lut1d_input[i] )               delete  m_lut1d_input[i];
    2784     if ( m_coded_input_pivot_value[i] )   delete  m_coded_input_pivot_value[i];
    2785     if ( m_target_input_pivot_value[i] )  delete  m_target_input_pivot_value[i];
    2786   }
    2787   for( Int i=0 ; i<3 ; i++ )
    2788   {
    2789     if ( m_lut1d_output[i] )               delete  m_lut1d_output[i];
    2790     if ( m_coded_output_pivot_value[i] )   delete  m_coded_output_pivot_value[i];
    2791     if ( m_target_output_pivot_value[i] )  delete  m_target_output_pivot_value[i];
    2792   }
    2793 }
    2794 
    2795 Void  TDecColorMapping::setColorMapping( SEIMessages m_SEIs )
    2796 {
    2797   SEIMessages colorMappingInfo = getSeisByType(m_SEIs, SEI::COLOR_MAPPING_INFO) ;
    2798   SEIColorMappingInfo *seiColorMappingInfo = NULL;
    2799   if (colorMappingInfo.size() !=0)
    2800   {
    2801     seiColorMappingInfo = (SEIColorMappingInfo*)(*colorMappingInfo.begin());
    2802 
    2803     m_colorMapId                              = seiColorMappingInfo->m_colorMapId;
    2804     m_colorMapCancelFlag                      = seiColorMappingInfo->m_colorMapCancelFlag;
    2805     if( !m_colorMapCancelFlag )
    2806     {
    2807       m_colorMapPersistenceFlag                 = seiColorMappingInfo->m_colorMapPersistenceFlag;
    2808       m_colorMap_video_signal_type_present_flag = seiColorMappingInfo->m_colorMap_video_signal_type_present_flag;
    2809       m_colorMap_video_full_range_flag          = seiColorMappingInfo->m_colorMap_video_full_range_flag;
    2810       m_colorMap_primaries                      = seiColorMappingInfo->m_colorMap_primaries;
    2811       m_colorMap_transfer_characteristics       = seiColorMappingInfo->m_colorMap_transfer_characteristics;
    2812       m_colorMap_matrix_coeffs                  = seiColorMappingInfo->m_colorMap_matrix_coeffs;
    2813       m_colorMapModelId                         = seiColorMappingInfo->m_colorMapModelId;
    2814 
    2815       m_colour_map_coded_data_bit_depth         = seiColorMappingInfo->m_colour_map_coded_data_bit_depth;
    2816       m_colour_map_target_bit_depth             = seiColorMappingInfo->m_colour_map_target_bit_depth;
    2817 
    2818       for( Int i=0 ; i<3 ; i++ )
    2819       {
    2820         m_num_input_pivots[i]                 = seiColorMappingInfo->m_num_input_pivots[i];
    2821         if ( m_coded_input_pivot_value[i] )   delete  m_coded_input_pivot_value[i];
    2822         if ( m_target_input_pivot_value[i] )  delete  m_target_input_pivot_value[i];
    2823         m_coded_input_pivot_value[i]          = new Int[ m_num_input_pivots[i] ];
    2824         m_target_input_pivot_value[i]         = new Int[ m_num_input_pivots[i] ];
    2825         for( Int j=0 ; j<m_num_input_pivots[i] ; j++ )
    2826         {
    2827           m_coded_input_pivot_value[i][j]     = seiColorMappingInfo->m_coded_input_pivot_value[i][j];
    2828           m_target_input_pivot_value[i][j]    = seiColorMappingInfo->m_target_input_pivot_value[i][j];
    2829         }
    2830       }
    2831 
    2832       m_matrix_flag       = seiColorMappingInfo->m_matrix_flag;
    2833       m_log2_matrix_denom = m_matrix_flag ? (seiColorMappingInfo->m_log2_matrix_denom) : (0) ;
    2834       for( Int i=0 ; i<3 ; i++ )
    2835       {
    2836         for( Int j=0 ; j<3 ; j++ )
    2837         {
    2838           m_matrix_coef[i][j]  = seiColorMappingInfo->m_matrix_coef[i][j];
    2839         }
    2840       }
    2841 
    2842       for( Int i=0 ; i<3 ; i++ )
    2843       {
    2844         m_num_output_pivots[i]                 = seiColorMappingInfo->m_num_output_pivots[i];
    2845         if ( m_coded_output_pivot_value[i] )   delete  m_coded_output_pivot_value[i];
    2846         if ( m_target_output_pivot_value[i] )  delete  m_target_output_pivot_value[i];
    2847         m_coded_output_pivot_value[i]          = new Int[ m_num_output_pivots[i] ];
    2848         m_target_output_pivot_value[i]         = new Int[ m_num_output_pivots[i] ];
    2849         for( Int j=0 ; j<m_num_output_pivots[i] ; j++ )
    2850         {
    2851           m_coded_output_pivot_value[i][j]     = seiColorMappingInfo->m_coded_output_pivot_value[i][j];
    2852           m_target_output_pivot_value[i][j]    = seiColorMappingInfo->m_target_output_pivot_value[i][j];
    2853         }
    2854       }
    2855 
    2856       memset( m_lut1d_computed, 0, sizeof( m_lut1d_computed ) );
    2857     }
    2858   }
    2859 
    2860 }
    2861 
    2862 Void  TDecColorMapping::setColorMapping( Int bitDepth, Int iComp )
    2863 {
    2864   if( !m_colorMapCancelFlag && !m_lut1d_computed[iComp] )
    2865   {
    2866 
    2867     if ( m_lut1d_input[iComp] )   delete m_lut1d_input[iComp];
    2868     if ( m_lut1d_output[iComp] )  delete m_lut1d_output[iComp];
    2869 
    2870     m_lut1d_input[iComp]  = new Int[ 1 << bitDepth ];
    2871     m_lut1d_output[iComp] = new Int[ 1 << bitDepth ];
    2872 
    2873     Int iShift      = (m_colour_map_coded_data_bit_depth >= bitDepth) ? (m_colour_map_coded_data_bit_depth - bitDepth) : (0);
    2874     Int iShiftPivot = (m_colour_map_coded_data_bit_depth >= bitDepth) ? (0) : (bitDepth - m_colour_map_coded_data_bit_depth);
    2875 
    2876     for( Int k=0 ; k<(1<<bitDepth) ; k++ )
    2877     {
    2878       Int iSample = k << iShift ;
    2879       if( m_num_input_pivots[iComp] > 1 )
    2880       {
    2881         for( Int iPivot=0 ; iPivot<m_num_input_pivots[iComp] ; iPivot++ )
    2882         {
    2883           Int iCodedPrev  = m_coded_input_pivot_value[iComp][iPivot]     << iShiftPivot;
    2884           Int iCodedNext  = m_coded_input_pivot_value[iComp][iPivot+1]   << iShiftPivot;
    2885           Int iTargetPrev = m_target_input_pivot_value[iComp][iPivot]    << iShiftPivot;
    2886           Int iTargetNext = m_target_input_pivot_value[iComp][iPivot+1]  << iShiftPivot;
    2887           if ( iCodedPrev <= iSample && iSample < iCodedNext )
    2888           {
    2889             Float fInterpol = (Float)( (iCodedNext - iSample)*iTargetPrev + (iSample - iCodedPrev)*iTargetNext ) / (Float)(iCodedNext - iCodedPrev) ;
    2890             m_lut1d_input[iComp][k]  = (Int)( 0.5 + fInterpol );
    2891             iPivot = m_num_input_pivots[iComp]; // stop
    2892           }
    2893         }
    2894       }
    2895       else
    2896       {
    2897         m_lut1d_input[iComp][k]  = k;
    2898       }
    2899     }
    2900 
    2901     iShift      = ( (m_colour_map_coded_data_bit_depth >= bitDepth) ? (m_colour_map_coded_data_bit_depth - bitDepth) : (0) );
    2902     Int iOffset = iShift ? (1 << (iShift - 1)) : (0) ;
    2903     iShiftPivot = (m_colour_map_target_bit_depth >= bitDepth) ? (0) : (bitDepth - m_colour_map_target_bit_depth) ;
    2904     for( Int k=0 ; k<(1<<bitDepth) ; k++ )
    2905     {
    2906       Int iSample = k << iShift;
    2907       if ( m_num_output_pivots[iComp]>1 )
    2908       {
    2909         for( Int iPivot=0 ; iPivot<m_num_output_pivots[iComp] ; iPivot++ )
    2910         {
    2911           Int iCodedPrev  = m_coded_output_pivot_value[iComp][iPivot]     << iShiftPivot;
    2912           Int iCodedNext  = m_coded_output_pivot_value[iComp][iPivot+1]   << iShiftPivot;
    2913           Int iTargetPrev = m_target_output_pivot_value[iComp][iPivot]    << iShiftPivot;
    2914           Int iTargetNext = m_target_output_pivot_value[iComp][iPivot+1]  << iShiftPivot;
    2915           if ( iCodedPrev <= iSample && iSample < iCodedNext )
    2916           {
    2917             Float fInterpol =  (Float)( (iCodedNext - iSample)*iTargetPrev + (iSample - iCodedPrev)*iTargetNext ) / (Float)(iCodedNext - iCodedPrev) ;
    2918             m_lut1d_output[iComp][k]  = ( (Int)(0.5 + fInterpol) + iOffset ) >> iShift ;
    2919             iPivot = m_num_output_pivots[iComp]; // stop
    2920           }
    2921         }
    2922       }
    2923       else
    2924       {
    2925         m_lut1d_output[iComp][k]  = k;
    2926       }
    2927     }
    2928 
    2929     m_lut1d_computed[iComp] = true;
    2930   }
    2931 
    2932 }
    2933 
    2934 TComPicYuv* TDecColorMapping::getColorMapping( TComPicYuv* pPicYuvRec, Int iTop, Int curlayerId )
    2935 {
    2936   if( !m_colorMapCancelFlag )
    2937   {
    2938     if( !m_pcColorMappingPic[iTop] )
    2939     {
    2940       m_pcColorMappingPic[iTop] = new TComPicYuv;
    2941 #if SVC_EXTENSION
    2942       m_pcColorMappingPic[iTop]->create( pPicYuvRec->getWidth(), pPicYuvRec->getHeight(), pPicYuvRec->getChromaFormat(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
    2943 #else
    2944       m_pcColorMappingPic[iTop]->create( pPicYuvRec->getWidth(), pPicYuvRec->getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
    2945 #endif
    2946     }
    2947 
    2948     Int iHeight   = pPicYuvRec->getHeight();
    2949     Int iWidth    = pPicYuvRec->getWidth();
    2950     Int iStride   = pPicYuvRec->getStride();
    2951     Int iCStride  = pPicYuvRec->getCStride();
    2952 
    2953     Pel* Lum0   = pPicYuvRec->getLumaAddr();
    2954     Pel* Cb0    = pPicYuvRec->getCbAddr();
    2955     Pel* Cr0    = pPicYuvRec->getCrAddr();
    2956     Pel* Lum1   = m_pcColorMappingPic[iTop]->getLumaAddr();
    2957     Pel* Cb1    = m_pcColorMappingPic[iTop]->getCbAddr();
    2958     Pel* Cr1    = m_pcColorMappingPic[iTop]->getCrAddr();
    2959 
    2960 #if SVC_EXTENSION
    2961     Int bitDepthY = g_bitDepthYLayer[curlayerId];
    2962     Int bitDepthC = g_bitDepthCLayer[curlayerId];
    2963 
    2964     assert( g_bitDepthY == bitDepthY );
    2965     assert( g_bitDepthC == bitDepthC );
    2966 #else
    2967     Int bitDepthY = g_bitDepthY;
    2968     Int bitDepthC = g_bitDepthC;
    2969 #endif
    2970 
    2971     Int iYShift = (m_colour_map_target_bit_depth >= bitDepthY) ? (m_colour_map_target_bit_depth - bitDepthY) : (0) ;
    2972     Int iCShift = (m_colour_map_target_bit_depth >= bitDepthC) ? (m_colour_map_target_bit_depth - bitDepthC) : (0) ;
    2973     Int offsetY = (1 << (m_log2_matrix_denom+iYShift - 1));
    2974     Int offsetC = (1 << (m_log2_matrix_denom+iCShift - 1));
    2975 
    2976     Int   cShift  = 1 ;
    2977 
    2978     //Pel*  LumPrev0 = Lum0;
    2979     for( Int y = 0; y < iHeight ; y++ )
    2980     {
    2981       Bool  bDoChroma = (y % 2);
    2982       for( Int x = 0; x < iWidth ; x++ )
    2983       {
    2984         Int s1Y = m_lut1d_input[0][ Lum0[x]   ];
    2985         Int s1U = m_lut1d_input[1][ Cb0[x>>1] ];
    2986         Int s1V = m_lut1d_input[2][ Cr0[x>>1] ];
    2987 
    2988         Int s2Y, s2U, s2V;
    2989         if( m_matrix_flag )
    2990         {
    2991           s2Y = ( m_matrix_coef[0][0]*s1Y + m_matrix_coef[0][1]*s1U + m_matrix_coef[0][2]*s1V + offsetY ) >> ( m_log2_matrix_denom + iYShift );
    2992           //s2Y = ClipBD( s2Y , bitDepthY );
    2993           s2Y = ClipY( s2Y );
    2994           Lum1[x]   = m_lut1d_output[0][ s2Y ];
    2995         }
    2996         else
    2997         {
    2998           s1Y       = ( s1Y + offsetY ) >> iYShift ;
    2999           //s1Y = ClipBD( s1Y , bitDepthY );
    3000           s1Y = ClipY( s1Y );
    3001           Lum1[x]   = m_lut1d_output[0][ s1Y ];
    3002         }
    3003 
    3004         if( bDoChroma && (x%2) )
    3005         {
    3006           if( m_matrix_flag )
    3007           {
    3008             //s1Y = ( m_lut1d_input[0][ Lum0[x] ] + m_lut1d_input[0][ Lum0[x+1] ] + m_lut1d_input[0][ LumPrev0[x] ] + m_lut1d_input[0][ LumPrev0[x+1] ] + 2 ) >> 2 ;
    3009             //s1Y = m_lut1d_input[0][ (Lum0[x] + Lum0[x+1] + LumPrev0[x] + LumPrev0[x+1] + 2)>>2 ] ;
    3010             s1Y = m_lut1d_input[0][ Lum0[x] ];
    3011 
    3012             s2U = ( m_matrix_coef[1][0]*s1Y + m_matrix_coef[1][1]*s1U + m_matrix_coef[1][2]*s1V + offsetC ) >> ( m_log2_matrix_denom + iCShift ) ;
    3013             s2V = ( m_matrix_coef[2][0]*s1Y + m_matrix_coef[2][1]*s1U + m_matrix_coef[2][2]*s1V + offsetC ) >> ( m_log2_matrix_denom + iCShift ) ;
    3014             //s2U = ClipBD( s2U , bitDepthC );
    3015             //s2V = ClipBD( s2V , bitDepthC );
    3016             s2U = ClipC( s2U );
    3017             s2V = ClipC( s2V );
    3018             Cb1[x>>cShift] = m_lut1d_output[1][ s2U ];
    3019             Cr1[x>>cShift] = m_lut1d_output[2][ s2V ];
    3020           }
    3021           else
    3022           {
    3023             s1U       = ( s1U + offsetC ) >> iCShift ;
    3024             s1V       = ( s1V + offsetC ) >> iCShift ;
    3025             //s1U = ClipBD( s1U , bitDepthC );
    3026             //s1V = ClipBD( s1V , bitDepthC );
    3027             s1U = ClipC( s1U );
    3028             s1V = ClipC( s1V );
    3029             Cb1[x>>cShift] = m_lut1d_output[1][ s1U ];
    3030             Cr1[x>>cShift] = m_lut1d_output[2][ s1V ];
    3031           }
    3032         }
    3033 
    3034       }
    3035 
    3036       //LumPrev0 = Lum0;
    3037       Lum0  += iStride;
    3038       Lum1  += iStride;
    3039       if( bDoChroma )
    3040       {
    3041         Cb0 += iCStride;
    3042         Cr0 += iCStride;
    3043         Cb1 += iCStride;
    3044         Cr1 += iCStride;
    3045       }
    3046     }
    3047 
    3048     return m_pcColorMappingPic[iTop];
    3049   }
    3050 
    3051   return pPicYuvRec;
    3052 }
    3053 #endif
    30543070
    30553071//! \}
  • trunk/source/Lib/TLibDecoder/TDecTop.h

    r815 r906  
    6464// ====================================================================================================================
    6565
    66 #if Q0074_SEI_COLOR_MAPPING
    67 class TDecColorMapping
    68 {
    69   Int   m_colorMapId;
    70   Bool  m_colorMapCancelFlag;
    71   Bool  m_colorMapPersistenceFlag;
    72   Bool  m_colorMap_video_signal_type_present_flag;
    73   Bool  m_colorMap_video_full_range_flag;
    74   Int   m_colorMap_primaries;
    75   Int   m_colorMap_transfer_characteristics;
    76   Int   m_colorMap_matrix_coeffs;
    77   Int   m_colorMapModelId;
    78 
    79   Int   m_colour_map_coded_data_bit_depth;
    80   Int   m_colour_map_target_bit_depth;
    81 
    82   Int   m_num_input_pivots[3];
    83   Int*  m_coded_input_pivot_value[3];
    84   Int*  m_target_input_pivot_value[3];
    85  
    86   Bool  m_matrix_flag;
    87   Int   m_log2_matrix_denom;
    88   Int   m_matrix_coef[3][3];
    89 
    90   Int   m_num_output_pivots[3];
    91   Int*  m_coded_output_pivot_value[3];
    92   Int*  m_target_output_pivot_value[3];
    93 
    94   Bool  m_lut1d_computed[3];
    95   Int*  m_lut1d_input[3];
    96   Int*  m_lut1d_output[3];
    97   TComPicYuv* m_pcColorMappingPic[2];
    98 
    99 public:
    100   TDecColorMapping();
    101   ~TDecColorMapping();
    102 
    103   Bool        getColorMappingFlag()                     { return(!m_colorMapCancelFlag);};
    104 
    105   Void        setColorMapping( SEIMessages m_SEIs );
    106   Void        setColorMapping( Int bitDepthY, Int bitDepthC );
    107   TComPicYuv* getColorMapping( TComPicYuv* pPicYuvRec, Int iTop=0, Int curlayerId=0 );
    108 };// END CLASS DEFINITION TDecColorMapping
    109 #endif
    110 
    11166/// decoder class
    11267class TDecTop
     
    165120  Bool                    m_isLastNALWasEos;
    166121#endif
    167 
    168122#if SVC_EXTENSION
    169123  static UInt             m_prevPOC;        // POC of the previous slice
     
    173127  UInt                    m_numLayer;
    174128  TDecTop**               m_ppcTDecTop;
     129#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     130  Bool                    m_pocResettingFlag;
     131  Bool                    m_pocDecrementedInDPBFlag;
     132#endif
    175133#if AVC_BASE
    176134  fstream*                m_pBLReconFile;
     
    195153  CommonDecoderParams*    m_commonDecoderParams;
    196154#endif
    197 #if AVC_SYNTAX || SYNTAX_OUTPUT
    198   fstream*               m_pBLSyntaxFile;
    199 #endif
    200 
    201155#if NO_CLRAS_OUTPUT_FLAG 
    202156  Bool                    m_noClrasOutputFlag;
     
    214168#endif
    215169public:
    216 #if Q0074_SEI_COLOR_MAPPING
    217   TDecColorMapping* m_ColorMapping;
     170#if POC_RESET_RESTRICTIONS
     171  static Bool                    m_checkPocRestrictionsForCurrAu;
     172  static Int                     m_pocResetIdcOrCurrAu;
     173  static Bool                    m_baseLayerIdrFlag;
     174  static Bool                    m_baseLayerPicPresentFlag;
     175  static Bool                    m_baseLayerIrapFlag;
     176  static Bool                    m_nonBaseIdrPresentFlag;
     177  static Int                     m_nonBaseIdrType;
     178  static Bool                    m_picNonIdrWithRadlPresentFlag;
     179  static Bool                    m_picNonIdrNoLpPresentFlag;
     180#endif
     181#if POC_RESET_VALUE_RESTRICTION
     182  static Int                     m_crossLayerPocResetPeriodId;
     183  static Int                     m_crossLayerPocResetIdc;
    218184#endif
    219185
     
    225191
    226192  void setDecodedPictureHashSEIEnabled(Int enabled) { m_cGopDecoder.setDecodedPictureHashSEIEnabled(enabled); }
     193#if Q0074_COLOUR_REMAPPING_SEI
     194  void setColourRemappingInfoSEIEnabled(Bool enabled)  { m_cGopDecoder.setColourRemappingInfoSEIEnabled(enabled); }
     195#endif
    227196
    228197  Void  init();
     
    327296#endif
    328297#endif //SVC_EXTENSION
    329 #if AVC_SYNTAX || SYNTAX_OUTPUT
    330   Void      setBLSyntaxFile( fstream* pFile ) { m_pBLSyntaxFile = pFile; }
    331   fstream* getBLSyntaxFile() { return m_pBLSyntaxFile; }
    332 #endif
     298
    333299protected:
    334300  Void  xGetNewPicBuffer  (TComSlice* pcSlice, TComPic*& rpcPic);
     
    365331  Void initAsymLut(TComSlice *pcSlice);
    366332#endif
     333#if POC_RESET_RESTRICTIONS
     334  Void resetPocRestrictionCheckParameters();
     335#endif
    367336};// END CLASS DEFINITION TDecTop
    368337
    369338
     339
    370340//! \}
    371341
Note: See TracChangeset for help on using the changeset viewer.