Index: trunk/source/Lib/TLibDecoder/SEIread.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/SEIread.cpp	(revision 815)
+++ trunk/source/Lib/TLibDecoder/SEIread.cpp	(revision 906)
@@ -98,7 +98,7 @@
     break;
 #endif
-#if Q0074_SEI_COLOR_MAPPING
-  case SEI::COLOR_MAPPING_INFO:
-    fprintf( g_hTrace, "===========Color Mapping Info SEI message ===========\n");
+#if Q0074_COLOUR_REMAPPING_SEI
+  case SEI::COLOUR_REMAPPING_INFO:
+    fprintf( g_hTrace, "===========Colour Remapping Information SEI message ===========\n");
     break;
 #endif
@@ -132,7 +132,9 @@
     fprintf( g_hTrace, "=========== Bitstream parition initial arrival time SEI message ===========\n");
     break;
+#if !REMOVE_BSP_HRD_SEI
   case SEI::BSP_HRD:
     fprintf( g_hTrace, "=========== Bitstream parition HRD parameters SEI message ===========\n");
     break;
+#endif
 #endif
 #if Q0078_ADD_LAYER_SETS
@@ -249,5 +251,9 @@
       {
         sei = new SEIDecodingUnitInfo; 
+#if VPS_VUI_BSP_HRD_PARAMS
+        xParseSEIDecodingUnitInfo((SEIDecodingUnitInfo&) *sei, payloadSize, sps, nestingSei, bspNestingSei, vps);
+#else
         xParseSEIDecodingUnitInfo((SEIDecodingUnitInfo&) *sei, payloadSize, sps);
+#endif
       }
       break; 
@@ -260,5 +266,9 @@
       {
         sei = new SEIBufferingPeriod;
+#if VPS_VUI_BSP_HRD_PARAMS
+        xParseSEIBufferingPeriod((SEIBufferingPeriod&) *sei, payloadSize, sps, nestingSei, bspNestingSei, vps);
+#else
         xParseSEIBufferingPeriod((SEIBufferingPeriod&) *sei, payloadSize, sps);
+#endif
       }
       break;
@@ -271,5 +281,9 @@
       {
         sei = new SEIPictureTiming;
+#if VPS_VUI_BSP_HRD_PARAMS
+        xParseSEIPictureTiming((SEIPictureTiming&)*sei, payloadSize, sps, nestingSei, bspNestingSei, vps);
+#else
         xParseSEIPictureTiming((SEIPictureTiming&)*sei, payloadSize, sps);
+#endif
       }
       break;
@@ -304,8 +318,8 @@
       break;
 #endif
-#if Q0074_SEI_COLOR_MAPPING
-    case SEI::COLOR_MAPPING_INFO:
-      sei = new SEIColorMappingInfo;
-      xParseSEIColorMappingInfo((SEIColorMappingInfo&) *sei, payloadSize);
+#if Q0074_COLOUR_REMAPPING_SEI
+    case SEI::COLOUR_REMAPPING_INFO:
+      sei = new SEIColourRemappingInfo;
+      xParseSEIColourRemappingInfo((SEIColourRemappingInfo&) *sei, payloadSize);
       break;
 #endif
@@ -345,5 +359,9 @@
    case SEI::SUB_BITSTREAM_PROPERTY:
      sei = new SEISubBitstreamProperty;
+#if OLS_IDX_CHK
+     xParseSEISubBitstreamProperty((SEISubBitstreamProperty&) *sei, vps);
+#else
      xParseSEISubBitstreamProperty((SEISubBitstreamProperty&) *sei);
+#endif
      break;
 #endif
@@ -361,8 +379,10 @@
      xParseSEIBspInitialArrivalTime((SEIBspInitialArrivalTime&) *sei, vps, sps, *nestingSei, *bspNestingSei);
      break;
+#if !REMOVE_BSP_HRD_SEI
    case SEI::BSP_HRD:
      sei = new SEIBspHrd;
      xParseSEIBspHrd((SEIBspHrd&) *sei, sps, *nestingSei);
      break;
+#endif
 #endif
 #if Q0078_ADD_LAYER_SETS
@@ -580,13 +600,25 @@
 
   sei.activeSeqParameterSetId.resize(sei.numSpsIdsMinus1 + 1);
+#if R0247_SEI_ACTIVE
+  sei.layerSpsIdx.resize(sei.numSpsIdsMinus1 + 1);
+#endif
   for (Int i=0; i < (sei.numSpsIdsMinus1 + 1); i++)
   {
     READ_UVLC(val, "active_seq_parameter_set_id");      sei.activeSeqParameterSetId[i] = val; 
   }
-
+#if R0247_SEI_ACTIVE
+  for (Int i=1; i < (sei.numSpsIdsMinus1 + 1); i++)
+  {
+    READ_UVLC(val, "layer_sps_idx"); sei.layerSpsIdx[i] = val; 
+  }
+#endif
   xParseByteAlign();
 }
 
+#if VPS_VUI_BSP_HRD_PARAMS
+Void SEIReader::xParseSEIDecodingUnitInfo(SEIDecodingUnitInfo& sei, UInt /*payloadSize*/, TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei, TComVPS *vps)
+#else
 Void SEIReader::xParseSEIDecodingUnitInfo(SEIDecodingUnitInfo& sei, UInt /*payloadSize*/, TComSPS *sps)
+#endif
 {
   UInt val;
@@ -594,8 +626,48 @@
   sei.m_decodingUnitIdx = val;
 
+#if VPS_VUI_BSP_HRD_PARAMS
+  TComHRD *hrd;
+  if( bspNestingSei )   // If DU info SEI contained inside a BSP nesting SEI message
+  {
+    assert( nestingSei );
+    Int psIdx = bspNestingSei->m_seiPartitioningSchemeIdx;
+    Int seiOlsIdx = bspNestingSei->m_seiOlsIdx;
+    Int maxTemporalId = nestingSei->m_nestingMaxTemporalIdPlus1[0] - 1;
+    Int maxValues = vps->getNumBspSchedulesMinus1(seiOlsIdx, psIdx, maxTemporalId) + 1;
+    std::vector<Int> hrdIdx(maxValues, 0);
+    std::vector<TComHRD *> hrdVec;
+    std::vector<Int> syntaxElemLen(maxValues, 0);
+    for(Int i = 0; i < maxValues; i++)
+    {
+      hrdIdx[i] = vps->getBspHrdIdx( seiOlsIdx, psIdx, maxTemporalId, i, bspNestingSei->m_bspIdx);
+      hrdVec.push_back(vps->getBspHrd(hrdIdx[i]));
+    
+      syntaxElemLen[i] = hrdVec[i]->getInitialCpbRemovalDelayLengthMinus1() + 1;
+      if ( !(hrdVec[i]->getNalHrdParametersPresentFlag() || hrdVec[i]->getVclHrdParametersPresentFlag()) )
+      {
+        assert( syntaxElemLen[i] == 24 ); // Default of value init_cpb_removal_delay_length_minus1 is 23
+      }
+      if( i > 0 )
+      {
+        assert( hrdVec[i]->getSubPicCpbParamsPresentFlag()    == hrdVec[i-1]->getSubPicCpbParamsPresentFlag() );
+        assert( hrdVec[i]->getSubPicCpbParamsInPicTimingSEIFlag()   == hrdVec[i-1]->getSubPicCpbParamsInPicTimingSEIFlag() );
+        assert( hrdVec[i]->getDpbOutputDelayDuLengthMinus1()  == hrdVec[i-1]->getDpbOutputDelayDuLengthMinus1() );
+        // To be done: Check CpbDpbDelaysPresentFlag
+      }
+    }
+    hrd = hrdVec[0];
+  }
+  else
+  {
+    TComVUI *vui = sps->getVuiParameters();
+    hrd = vui->getHrdParameters();
+  }
+#else
   TComVUI *vui = sps->getVuiParameters();
-  if(vui->getHrdParameters()->getSubPicCpbParamsInPicTimingSEIFlag())
-  {
-    READ_CODE( ( vui->getHrdParameters()->getDuCpbRemovalDelayLengthMinus1() + 1 ), val, "du_spt_cpb_removal_delay");
+  TComHrd *hrd = vui->getHrdParameters();
+#endif
+  if(hrd->getSubPicCpbParamsInPicTimingSEIFlag())
+  {
+    READ_CODE( ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ), val, "du_spt_cpb_removal_delay");
     sei.m_duSptCpbRemovalDelay = val;
   }
@@ -607,5 +679,5 @@
   if(sei.m_dpbOutputDuDelayPresentFlag)
   {
-    READ_CODE(vui->getHrdParameters()->getDpbOutputDelayDuLengthMinus1() + 1, val, "pic_spt_dpb_output_du_delay"); 
+    READ_CODE(hrd->getDpbOutputDelayDuLengthMinus1() + 1, val, "pic_spt_dpb_output_du_delay"); 
     sei.m_picSptDpbOutputDuDelay = val;
   }
@@ -613,11 +685,54 @@
 }
 
+#if VPS_VUI_BSP_HRD_PARAMS
+Void SEIReader::xParseSEIBufferingPeriod(SEIBufferingPeriod& sei, UInt /*payloadSize*/, TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei, TComVPS *vps)
+#else
 Void SEIReader::xParseSEIBufferingPeriod(SEIBufferingPeriod& sei, UInt /*payloadSize*/, TComSPS *sps)
+#endif
 {
   Int i, nalOrVcl;
   UInt code;
 
+#if VPS_VUI_BSP_HRD_PARAMS
+  TComHRD *pHRD;
+  if( bspNestingSei )   // If BP SEI contained inside a BSP nesting SEI message
+  {
+    assert( nestingSei );
+    Int psIdx = bspNestingSei->m_seiPartitioningSchemeIdx;
+    Int seiOlsIdx = bspNestingSei->m_seiOlsIdx;
+    Int maxTemporalId = nestingSei->m_nestingMaxTemporalIdPlus1[0] - 1;
+    Int maxValues = vps->getNumBspSchedulesMinus1(seiOlsIdx, psIdx, maxTemporalId) + 1;
+    std::vector<Int> hrdIdx(maxValues, 0);
+    std::vector<TComHRD *> hrdVec;
+    std::vector<Int> syntaxElemLen(maxValues, 0);
+    for(i = 0; i < maxValues; i++)
+    {
+      hrdIdx[i] = vps->getBspHrdIdx( seiOlsIdx, psIdx, maxTemporalId, i, bspNestingSei->m_bspIdx);
+      hrdVec.push_back(vps->getBspHrd(hrdIdx[i]));
+    
+      syntaxElemLen[i] = hrdVec[i]->getInitialCpbRemovalDelayLengthMinus1() + 1;
+      if ( !(hrdVec[i]->getNalHrdParametersPresentFlag() || hrdVec[i]->getVclHrdParametersPresentFlag()) )
+      {
+        assert( syntaxElemLen[i] == 24 ); // Default of value init_cpb_removal_delay_length_minus1 is 23
+      }
+      if( i > 0 )
+      {
+        assert( hrdVec[i]->getCpbRemovalDelayLengthMinus1()   == hrdVec[i-1]->getCpbRemovalDelayLengthMinus1() );
+        assert( hrdVec[i]->getDpbOutputDelayDuLengthMinus1()  == hrdVec[i-1]->getDpbOutputDelayDuLengthMinus1() );
+        assert( hrdVec[i]->getSubPicCpbParamsPresentFlag()    == hrdVec[i-1]->getSubPicCpbParamsPresentFlag() );
+      }
+    }
+    pHRD = hrdVec[i];
+  }
+  else
+  {
+    TComVUI *vui = sps->getVuiParameters();
+    pHRD = vui->getHrdParameters();
+  }
+  // To be done: When contained in an BSP HRD SEI message, the hrd structure is to be chosen differently.
+#else
   TComVUI *pVUI = sps->getVuiParameters();
   TComHRD *pHRD = pVUI->getHrdParameters();
+#endif
 
   READ_UVLC( code, "bp_seq_parameter_set_id" );                         sei.m_bpSeqParameterSetId     = code;
@@ -671,11 +786,58 @@
   xParseByteAlign();
 }
+#if VPS_VUI_BSP_HRD_PARAMS
+Void SEIReader::xParseSEIPictureTiming(SEIPictureTiming& sei, UInt /*payloadSize*/, TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei, TComVPS *vps)
+#else
 Void SEIReader::xParseSEIPictureTiming(SEIPictureTiming& sei, UInt /*payloadSize*/, TComSPS *sps)
+#endif
 {
   Int i;
   UInt code;
 
+#if VPS_VUI_BSP_HRD_PARAMS
+  TComHRD *hrd;    
+  TComVUI *vui = sps->getVuiParameters(); 
+  if( bspNestingSei )   // If BP SEI contained inside a BSP nesting SEI message
+  {
+    assert( nestingSei );
+    Int psIdx = bspNestingSei->m_seiPartitioningSchemeIdx;
+    Int seiOlsIdx = bspNestingSei->m_seiOlsIdx;
+    Int maxTemporalId = nestingSei->m_nestingMaxTemporalIdPlus1[0] - 1;
+    Int maxValues = vps->getNumBspSchedulesMinus1(seiOlsIdx, psIdx, maxTemporalId) + 1;
+    std::vector<Int> hrdIdx(maxValues, 0);
+    std::vector<TComHRD *> hrdVec;
+    std::vector<Int> syntaxElemLen(maxValues, 0);
+    for(i = 0; i < maxValues; i++)
+    {
+      hrdIdx[i] = vps->getBspHrdIdx( seiOlsIdx, psIdx, maxTemporalId, i, bspNestingSei->m_bspIdx);
+      hrdVec.push_back(vps->getBspHrd(hrdIdx[i]));
+    
+      syntaxElemLen[i] = hrdVec[i]->getInitialCpbRemovalDelayLengthMinus1() + 1;
+      if ( !(hrdVec[i]->getNalHrdParametersPresentFlag() || hrdVec[i]->getVclHrdParametersPresentFlag()) )
+      {
+        assert( syntaxElemLen[i] == 24 ); // Default of value init_cpb_removal_delay_length_minus1 is 23
+      }
+      if( i > 0 )
+      {
+        assert( hrdVec[i]->getSubPicCpbParamsPresentFlag()    == hrdVec[i-1]->getSubPicCpbParamsPresentFlag() );
+        assert( hrdVec[i]->getSubPicCpbParamsInPicTimingSEIFlag()   == hrdVec[i-1]->getSubPicCpbParamsInPicTimingSEIFlag() );
+        assert( hrdVec[i]->getCpbRemovalDelayLengthMinus1()  == hrdVec[i-1]->getCpbRemovalDelayLengthMinus1() );
+        assert( hrdVec[i]->getDpbOutputDelayLengthMinus1()  == hrdVec[i-1]->getDpbOutputDelayLengthMinus1() );
+        assert( hrdVec[i]->getDpbOutputDelayDuLengthMinus1()  == hrdVec[i-1]->getDpbOutputDelayDuLengthMinus1() );
+        assert( hrdVec[i]->getDuCpbRemovalDelayLengthMinus1()  == hrdVec[i-1]->getDuCpbRemovalDelayLengthMinus1() );
+        // To be done: Check CpbDpbDelaysPresentFlag
+      }
+    }
+    hrd = hrdVec[0];
+  }
+  else
+  {
+    hrd = vui->getHrdParameters();
+  }
+  // To be done: When contained in an BSP HRD SEI message, the hrd structure is to be chosen differently.
+#else
   TComVUI *vui = sps->getVuiParameters();
   TComHRD *hrd = vui->getHrdParameters();
+#endif
 
   if( vui->getFrameFieldInfoPresentFlag() )
@@ -921,84 +1083,81 @@
 #endif
 
-#if Q0074_SEI_COLOR_MAPPING
-Void SEIReader::xParseSEIColorMappingInfo(SEIColorMappingInfo& sei, UInt /*payloadSize*/)
+#if Q0074_COLOUR_REMAPPING_SEI
+Void SEIReader::xParseSEIColourRemappingInfo(SEIColourRemappingInfo& sei, UInt /*payloadSize*/)
 {
   UInt  uiVal;
   Int   iVal;
 
-  READ_UVLC( uiVal, "colour_map_id" );          sei.m_colorMapId = uiVal;
-  READ_FLAG( uiVal, "colour_map_cancel_flag" ); sei.m_colorMapCancelFlag = uiVal;
-  if( !sei.m_colorMapCancelFlag ) 
-  {
-    READ_FLAG( uiVal, "colour_map_persistence_flag" );                sei.m_colorMapPersistenceFlag = uiVal;
-    READ_FLAG( uiVal, "colour_map_video_signal_type_present_flag" );  sei.m_colorMap_video_signal_type_present_flag = uiVal;
-    if ( sei.m_colorMap_video_signal_type_present_flag ) {
-      READ_FLAG( uiVal,     "colour_map_video_full_range_flag" );     sei.m_colorMap_video_full_range_flag = uiVal;
-      READ_CODE( 8, uiVal,  "colour_map_primaries" );                 sei.m_colorMap_primaries = uiVal;
-      READ_CODE( 8, uiVal,  "colour_map_transfer_characteristics" );  sei.m_colorMap_transfer_characteristics = uiVal;
-      READ_CODE( 8, uiVal,  "colour_map_matrix_coeffs" );             sei.m_colorMap_matrix_coeffs = uiVal;
-    }
-  }
-
-  READ_CODE( 5, uiVal,  "colour_map_coded_data_bit_depth" );  sei.m_colour_map_coded_data_bit_depth = uiVal;
-  READ_CODE( 5, uiVal,  "colour_map_target_bit_depth" );      sei.m_colour_map_target_bit_depth = uiVal;
-  READ_UVLC( uiVal, "colour_map_model_id" );                  sei.m_colorMapModelId = uiVal;
-
-  assert( sei.m_colorMapModelId == 0 );
+  READ_UVLC( uiVal, "colour_remap_id" );          sei.m_colourRemapId = uiVal;
+  READ_FLAG( uiVal, "colour_remap_cancel_flag" ); sei.m_colourRemapCancelFlag = uiVal;
+  if( !sei.m_colourRemapCancelFlag ) 
+  {
+    READ_FLAG( uiVal, "colour_remap_persistence_flag" );                sei.m_colourRemapPersistenceFlag = uiVal;
+    READ_FLAG( uiVal, "colour_remap_video_signal_info_present_flag" );  sei.m_colourRemapVideoSignalInfoPresentFlag = uiVal;
+    if ( sei.m_colourRemapVideoSignalInfoPresentFlag )
+    {
+      READ_FLAG( uiVal,    "colour_remap_full_range_flag" );           sei.m_colourRemapFullRangeFlag = uiVal;
+      READ_CODE( 8, uiVal, "colour_remap_primaries" );                 sei.m_colourRemapPrimaries = uiVal;
+      READ_CODE( 8, uiVal, "colour_remap_transfer_function" );         sei.m_colourRemapTransferFunction = uiVal;
+      READ_CODE( 8, uiVal, "colour_remap_matrix_coefficients" );       sei.m_colourRemapMatrixCoefficients = uiVal;
+    }
+    READ_CODE( 8, uiVal, "colour_remap_input_bit_depth" ); sei.m_colourRemapInputBitDepth = uiVal;
+    READ_CODE( 8, uiVal, "colour_remap_bit_depth" ); sei.m_colourRemapBitDepth = uiVal;
   
-  for( Int i=0 ; i<3 ; i++ )
-  {
-    READ_CODE( 8, uiVal, "num_input_pivots_minus1[i]" ); sei.m_num_input_pivots[i] = (uiVal==0) ? 2 : (uiVal + 1) ;
-    sei.m_coded_input_pivot_value[i]   = new Int[ sei.m_num_input_pivots[i] ];
-    sei.m_target_input_pivot_value[i]  = new Int[ sei.m_num_input_pivots[i] ];
-    if( uiVal > 0 )
-    {
-      for ( Int j=0 ; j<sei.m_num_input_pivots[i] ; j++ )
-      {
-        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;
-        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;
-      }
-    }
-    else
-    {
-      sei.m_coded_input_pivot_value[i][0]  = 0;
-      sei.m_target_input_pivot_value[i][0] = 0;
-      sei.m_coded_input_pivot_value[i][1]  = (1 << sei.m_colour_map_coded_data_bit_depth) - 1 ;
-      sei.m_target_input_pivot_value[i][1] = (1 << sei.m_colour_map_target_bit_depth) - 1 ;
-    }
-  }
-
-  READ_FLAG( uiVal,           "matrix_flag" ); sei.m_matrix_flag = uiVal;
-  if( sei.m_matrix_flag )
-  {
-    READ_CODE( 4, uiVal,         "log2_matrix_denom" ); sei.m_log2_matrix_denom = uiVal;
-    for ( Int i=0 ; i<3 ; i++ )
-    {
-      for ( Int j=0 ; j<3 ; j++ )
-      {
-        READ_SVLC( iVal,        "matrix_coef[i][j]" ); sei.m_matrix_coef[i][j] = iVal;
-      }
-    }
-  }
-
-  for ( Int i=0 ; i<3 ; i++ )
-  {
-    READ_CODE( 8, uiVal, "num_output_pivots_minus1[i]" ); sei.m_num_output_pivots[i] = (uiVal==0) ? 2 : (uiVal + 1) ;
-    sei.m_coded_output_pivot_value[i]   = new Int[ sei.m_num_output_pivots[i] ];
-    sei.m_target_output_pivot_value[i]  = new Int[ sei.m_num_output_pivots[i] ];
-    if( uiVal > 0 )
-    {
-      for ( Int j=0 ; j<sei.m_num_output_pivots[i] ; j++ )
-      {
-        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;
-        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;
-      }
-    }
-    else
-    {
-      sei.m_coded_output_pivot_value[i][0]  = 0;
-      sei.m_target_output_pivot_value[i][0] = 0;
-      sei.m_coded_output_pivot_value[i][1]  = (1 << sei.m_colour_map_coded_data_bit_depth) - 1 ;
-      sei.m_target_output_pivot_value[i][1] = (1 << sei.m_colour_map_target_bit_depth) - 1 ;
+    for( Int c=0 ; c<3 ; c++ )
+    {
+      READ_CODE( 8, uiVal, "pre_lut_num_val_minus1[c]" ); sei.m_preLutNumValMinus1[c] = (uiVal==0) ? 1 : uiVal;
+      sei.m_preLutCodedValue[c].resize(sei.m_preLutNumValMinus1[c]+1);
+      sei.m_preLutTargetValue[c].resize(sei.m_preLutNumValMinus1[c]+1);
+      if( uiVal> 0 )
+        for ( Int i=0 ; i<=sei.m_preLutNumValMinus1[c] ; i++ )
+        {
+          READ_CODE( (( sei.m_colourRemapInputBitDepth   + 7 ) >> 3 ) << 3, uiVal, "pre_lut_coded_value[c][i]" );  sei.m_preLutCodedValue[c][i]  = uiVal;
+          READ_CODE( (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, uiVal, "pre_lut_target_value[c][i]" ); sei.m_preLutTargetValue[c][i] = uiVal;
+        }
+      else // pre_lut_num_val_minus1[c] == 0
+      {
+        sei.m_preLutCodedValue[c][0]  = 0;
+        sei.m_preLutTargetValue[c][0] = 0;
+        sei.m_preLutCodedValue[c][1]  = (1 << sei.m_colourRemapInputBitDepth) - 1 ;
+        sei.m_preLutTargetValue[c][1] = (1 << sei.m_colourRemapBitDepth) - 1 ;
+      }
+    }
+
+    READ_FLAG( uiVal,      "colour_remap_matrix_present_flag" ); sei.m_colourRemapMatrixPresentFlag = uiVal;
+    if( sei.m_colourRemapMatrixPresentFlag )
+    {
+      READ_CODE( 4, uiVal, "log2_matrix_denom" ); sei.m_log2MatrixDenom = uiVal;
+      for ( Int c=0 ; c<3 ; c++ )
+        for ( Int i=0 ; i<3 ; i++ )
+        {
+          READ_SVLC( iVal, "colour_remap_coeffs[c][i]" ); sei.m_colourRemapCoeffs[c][i] = iVal;
+        }
+    }
+    else // setting default matrix (I3)
+    {
+      sei.m_log2MatrixDenom = 0;
+      for ( Int c=0 ; c<3 ; c++ )
+        for ( Int i=0 ; i<3 ; i++ )
+          sei.m_colourRemapCoeffs[c][i] = (c==i) ? 1 : 0;
+    }
+    for( Int c=0 ; c<3 ; c++ )
+    {
+      READ_CODE( 8, uiVal, "post_lut_num_val_minus1[c]" ); sei.m_postLutNumValMinus1[c] = (uiVal==0) ? 1 : uiVal;
+      sei.m_postLutCodedValue[c].resize(sei.m_postLutNumValMinus1[c]+1);
+      sei.m_postLutTargetValue[c].resize(sei.m_postLutNumValMinus1[c]+1);
+      if( uiVal > 0 )
+        for ( Int i=0 ; i<=sei.m_postLutNumValMinus1[c] ; i++ )
+        {
+          READ_CODE( (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, uiVal, "post_lut_coded_value[c][i]" );  sei.m_postLutCodedValue[c][i] = uiVal;
+          READ_CODE( (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, uiVal, "post_lut_target_value[c][i]" ); sei.m_postLutTargetValue[c][i] = uiVal;
+        }
+      else
+      {
+        sei.m_postLutCodedValue[c][0]  = 0;
+        sei.m_postLutTargetValue[c][0] = 0;
+        sei.m_postLutTargetValue[c][1] = (1 << sei.m_colourRemapBitDepth) - 1;
+        sei.m_postLutCodedValue[c][1]  = (1 << sei.m_colourRemapBitDepth) - 1;
+      }
     }
   }
@@ -1194,5 +1353,9 @@
 #endif
 #if SUB_BITSTREAM_PROPERTY_SEI
+#if OLS_IDX_CHK
+Void SEIReader::xParseSEISubBitstreamProperty(SEISubBitstreamProperty &sei, TComVPS *vps)
+#else
 Void SEIReader::xParseSEISubBitstreamProperty(SEISubBitstreamProperty &sei)
+#endif
 {
   UInt uiCode;
@@ -1203,5 +1366,10 @@
   {
     READ_CODE(  2, uiCode, "sub_bitstream_mode[i]"           ); sei.m_subBitstreamMode[i] = uiCode;
-    READ_UVLC(     uiCode, "output_layer_set_idx_to_vps[i]"  ); sei.m_outputLayerSetIdxToVps[i] = uiCode;
+    READ_UVLC(     uiCode, "output_layer_set_idx_to_vps[i]"  );
+#if OLS_IDX_CHK
+      // The value of output_layer_set_idx_to_vps[ i ]  shall be in the range of 0 to NumOutputLayerSets − 1, inclusive.
+      assert(uiCode > 0 && uiCode <= vps->getNumOutputLayerSets()-1);
+#endif
+      sei.m_outputLayerSetIdxToVps[i] = uiCode;
     READ_CODE(  3, uiCode, "highest_sub_layer_id[i]"         ); sei.m_highestSublayerId[i] = uiCode;
     READ_CODE( 16, uiCode, "avg_bit_rate[i]"                 ); sei.m_avgBitRate[i] = uiCode;
@@ -1232,4 +1400,13 @@
 
   // read nested SEI messages
+#if NESTING_SEI_EXTENSIBILITY
+  Int numSeiMessages = 0;
+  READ_UVLC( uiCode, "num_seis_in_bsp_minus1" );  assert( uiCode <= MAX_SEIS_IN_BSP_NESTING );
+  numSeiMessages = uiCode;
+  for(Int i = 0; i < numSeiMessages; i++)
+  {
+    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps, &nestingSei, &sei);
+  }
+#else
   do {
 #if LAYERS_NOT_PRESENT_SEI
@@ -1239,4 +1416,5 @@
 #endif
   } while (m_pcBitstream->getNumBitsLeft() > 8);
+#endif
 }
 
@@ -1245,4 +1423,44 @@
   assert(vps->getVpsVuiPresentFlag());
 
+#if VPS_VUI_BSP_HRD_PARAMS
+  UInt uiCode;
+  Int psIdx         = bspNestingSei.m_seiPartitioningSchemeIdx;
+  Int seiOlsIdx     = bspNestingSei.m_seiOlsIdx;
+  Int maxTemporalId = nestingSei.m_nestingMaxTemporalIdPlus1[0];
+  Int maxValues     = vps->getNumBspSchedulesMinus1(seiOlsIdx, psIdx, maxTemporalId) + 1;
+  std::vector<Int> hrdIdx(0, maxValues);
+  std::vector<TComHRD *> hrdVec;
+  std::vector<Int> syntaxElemLen;
+  for(Int i = 0; i < maxValues; i++)
+  {
+    hrdIdx[i] = vps->getBspHrdIdx( seiOlsIdx, psIdx, maxTemporalId, i, bspNestingSei.m_bspIdx);
+    hrdVec[i] = vps->getBspHrd(hrdIdx[i]);
+    
+    syntaxElemLen[i] = hrdVec[i]->getInitialCpbRemovalDelayLengthMinus1() + 1;
+    if ( !(hrdVec[i]->getNalHrdParametersPresentFlag() || hrdVec[i]->getVclHrdParametersPresentFlag()) )
+    {
+      assert( syntaxElemLen[i] == 24 ); // Default value of init_cpb_removal_delay_length_minus1 is 23
+    }
+    if( i > 0 )
+    {
+      assert( hrdVec[i]->getNalHrdParametersPresentFlag() == hrdVec[i-1]->getNalHrdParametersPresentFlag() );
+      assert( hrdVec[i]->getVclHrdParametersPresentFlag() == hrdVec[i-1]->getVclHrdParametersPresentFlag() );
+    }
+  }
+  if (hrdVec[0]->getNalHrdParametersPresentFlag())
+  {
+    for(UInt i = 0; i < maxValues; i++)
+    {
+      READ_CODE( syntaxElemLen[i], uiCode, "nal_initial_arrival_delay[i]" ); sei.m_nalInitialArrivalDelay[i] = uiCode;
+    }
+  }
+  if( hrdVec[0]->getVclHrdParametersPresentFlag() )
+  {
+    for(UInt i = 0; i < maxValues; i++)
+    {
+      READ_CODE( syntaxElemLen[i], uiCode, "vcl_initial_arrival_delay[i]" ); sei.m_vclInitialArrivalDelay[i] = uiCode;
+    }
+  }
+#else
   UInt schedCombCnt = vps->getNumBspSchedCombinations(nestingSei.m_nestingOpIdx[0]);
   UInt len;
@@ -1277,5 +1495,9 @@
     }
   }
+#if BSP_INIT_ARRIVAL_SEI
+  if( hrd->getVclHrdParametersPresentFlag() )
+#else
   else
+#endif
   {
     for(UInt i = 0; i < schedCombCnt; i++)
@@ -1284,6 +1506,8 @@
     }
   }
-}
-
+#endif
+}
+
+#if !REMOVE_BSP_HRD_SEI
 Void SEIReader::xParseSEIBspHrd(SEIBspHrd &sei, TComSPS *sps, const SEIScalableNesting &nestingSei)
 {
@@ -1371,4 +1595,5 @@
   }
 }
+#endif
 
 Void SEIReader::xParseHrdParameters(TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1)
Index: trunk/source/Lib/TLibDecoder/SEIread.h
===================================================================
--- trunk/source/Lib/TLibDecoder/SEIread.h	(revision 815)
+++ trunk/source/Lib/TLibDecoder/SEIread.h	(revision 906)
@@ -80,8 +80,14 @@
   Void xParseSEIuserDataUnregistered  (SEIuserDataUnregistered &sei, UInt payloadSize);
   Void xParseSEIActiveParameterSets   (SEIActiveParameterSets  &sei, UInt payloadSize);
+  Void xParseSEIDecodedPictureHash    (SEIDecodedPictureHash& sei, UInt payloadSize);
+#if VPS_VUI_BSP_HRD_PARAMS
+  Void xParseSEIDecodingUnitInfo      (SEIDecodingUnitInfo& sei, UInt payloadSize, TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei, TComVPS *vps);
+  Void xParseSEIBufferingPeriod       (SEIBufferingPeriod& sei, UInt payloadSize, TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei, TComVPS *vps);
+  Void xParseSEIPictureTiming         (SEIPictureTiming& sei, UInt payloadSize, TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei, TComVPS *vps);
+#else
   Void xParseSEIDecodingUnitInfo      (SEIDecodingUnitInfo& sei, UInt payloadSize, TComSPS *sps);
-  Void xParseSEIDecodedPictureHash    (SEIDecodedPictureHash& sei, UInt payloadSize);
   Void xParseSEIBufferingPeriod       (SEIBufferingPeriod& sei, UInt payloadSize, TComSPS *sps);
   Void xParseSEIPictureTiming         (SEIPictureTiming& sei, UInt payloadSize, TComSPS *sps);
+#endif
   Void xParseSEIRecoveryPoint         (SEIRecoveryPoint& sei, UInt payloadSize);
   Void xParseSEIFramePacking          (SEIFramePacking& sei, UInt payloadSize);
@@ -93,6 +99,6 @@
   Void xParseSEIKneeFunctionInfo      (SEIKneeFunctionInfo& sei, UInt payloadSize);
 #endif
-#if Q0074_SEI_COLOR_MAPPING
-  Void xParseSEIColorMappingInfo      (SEIColorMappingInfo& sei, UInt payloadSize);
+#if Q0074_COLOUR_REMAPPING_SEI
+  Void xParseSEIColourRemappingInfo   (SEIColourRemappingInfo& sei, UInt payloadSize);
 #endif
   Void xParseSEISOPDescription        (SEISOPDescription &sei, UInt payloadSize);
@@ -101,5 +107,9 @@
 #endif
 #if SUB_BITSTREAM_PROPERTY_SEI
+#if OLS_IDX_CHK
+Void   xParseSEISubBitstreamProperty   (SEISubBitstreamProperty &sei, TComVPS *vps);
+#else
 Void   xParseSEISubBitstreamProperty   (SEISubBitstreamProperty &sei);
+#endif
 #endif
 #if LAYERS_NOT_PRESENT_SEI
@@ -116,5 +126,7 @@
 #endif
   Void xParseSEIBspInitialArrivalTime(SEIBspInitialArrivalTime &sei, TComVPS *vps, TComSPS *sps, const SEIScalableNesting &nestingSei, const SEIBspNesting &bspNestingSei);
+#if !REMOVE_BSP_HRD_SEI
   Void xParseSEIBspHrd(SEIBspHrd &sei, TComSPS *sps, const SEIScalableNesting &nestingSei);
+#endif
   Void xParseHrdParameters(TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1);
 #endif
Index: trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 815)
+++ trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 906)
@@ -255,30 +255,28 @@
   if( pcPPS->getTilesEnabledFlag() )
   {
-    READ_UVLC ( uiCode, "num_tile_columns_minus1" );                pcPPS->setNumColumnsMinus1( uiCode );
-    READ_UVLC ( uiCode, "num_tile_rows_minus1" );                   pcPPS->setNumRowsMinus1( uiCode );
-    READ_FLAG ( uiCode, "uniform_spacing_flag" );                   pcPPS->setUniformSpacingFlag( uiCode );
-
-    if( !pcPPS->getUniformSpacingFlag())
-    {
-      UInt* columnWidth = (UInt*)malloc(pcPPS->getNumColumnsMinus1()*sizeof(UInt));
-      for(UInt i=0; i<pcPPS->getNumColumnsMinus1(); i++)
+    READ_UVLC ( uiCode, "num_tile_columns_minus1" );                pcPPS->setNumTileColumnsMinus1( uiCode );  
+    READ_UVLC ( uiCode, "num_tile_rows_minus1" );                   pcPPS->setNumTileRowsMinus1( uiCode );  
+    READ_FLAG ( uiCode, "uniform_spacing_flag" );                   pcPPS->setTileUniformSpacingFlag( uiCode == 1 );
+
+    if( !pcPPS->getTileUniformSpacingFlag())
+    {
+      std::vector<Int> columnWidth(pcPPS->getNumTileColumnsMinus1());
+      for(UInt i=0; i<pcPPS->getNumTileColumnsMinus1(); i++)
       {
         READ_UVLC( uiCode, "column_width_minus1" );
         columnWidth[i] = uiCode+1;
       }
-      pcPPS->setColumnWidth(columnWidth);
-      free(columnWidth);
-
-      UInt* rowHeight = (UInt*)malloc(pcPPS->getNumRowsMinus1()*sizeof(UInt));
-      for(UInt i=0; i<pcPPS->getNumRowsMinus1(); i++)
+      pcPPS->setTileColumnWidth(columnWidth);
+
+      std::vector<Int> rowHeight (pcPPS->getTileNumRowsMinus1());
+      for(UInt i=0; i<pcPPS->getTileNumRowsMinus1(); i++)
       {
         READ_UVLC( uiCode, "row_height_minus1" );
         rowHeight[i] = uiCode + 1;
       }
-      pcPPS->setRowHeight(rowHeight);
-      free(rowHeight);
-    }
-
-    if(pcPPS->getNumColumnsMinus1() !=0 || pcPPS->getNumRowsMinus1() !=0)
+      pcPPS->setTileRowHeight(rowHeight);
+    }
+
+    if(pcPPS->getNumTileColumnsMinus1() !=0 || pcPPS->getTileNumRowsMinus1() !=0)
     {
       READ_FLAG ( uiCode, "loop_filter_across_tiles_enabled_flag" );   pcPPS->setLoopFilterAcrossTilesEnabledFlag( uiCode ? true : false );
@@ -297,5 +295,5 @@
     }
   }
-
+#if !R0042_PROFILE_INDICATION
 #if SCALINGLIST_INFERRING
   if( pcPPS->getLayerId() > 0 )
@@ -317,14 +315,16 @@
   {
 #endif
-
-  READ_FLAG( uiCode, "pps_scaling_list_data_present_flag" );           pcPPS->setScalingListPresentFlag( uiCode ? true : false );
-
-  if(pcPPS->getScalingListPresentFlag ())
-  {
-    parseScalingList( pcPPS->getScalingList() );
-  }
-
+#endif
+
+    READ_FLAG( uiCode, "pps_scaling_list_data_present_flag" );           pcPPS->setScalingListPresentFlag( uiCode ? true : false );
+
+    if(pcPPS->getScalingListPresentFlag ())
+    {
+      parseScalingList( pcPPS->getScalingList() );
+    }
+#if !R0042_PROFILE_INDICATION
 #if SCALINGLIST_INFERRING
   }
+#endif
 #endif
 
@@ -338,5 +338,11 @@
   pcPPS->setSliceHeaderExtensionPresentFlag(uiCode);
 
+#if !R0042_PROFILE_INDICATION
   READ_FLAG( uiCode, "pps_extension_flag");
+#else
+  READ_FLAG( uiCode, "pps_extension_present_flag");
+#endif
+
+#if !R0042_PROFILE_INDICATION
 #if POC_RESET_INFO_INFERENCE
   pcPPS->setExtensionFlag( uiCode ? true : false );
@@ -361,4 +367,60 @@
       READ_FLAG( uiCode, "poc_reset_info_present_flag" );
       pcPPS->setPocResetInfoPresentFlag(uiCode ? true : false);
+#if REF_REGION_OFFSET
+      READ_UVLC( uiCode,      "num_scaled_ref_layer_offsets" ); pcPPS->setNumScaledRefLayerOffsets(uiCode);
+      for(Int i = 0; i < pcPPS->getNumScaledRefLayerOffsets(); i++)
+      {
+        READ_CODE( 6, uiCode,  "scaled_ref_layer_id" );  pcPPS->setScaledRefLayerId( i, uiCode );
+        READ_FLAG( uiCode, "scaled_ref_layer_offset_present_flag" );   pcPPS->setScaledRefLayerOffsetPresentFlag( i, uiCode );
+        if (uiCode)
+        {
+          Window& scaledWindow = pcPPS->getScaledRefLayerWindow(i);
+          READ_SVLC( iCode, "scaled_ref_layer_left_offset" );    scaledWindow.setWindowLeftOffset  (iCode << 1);
+          READ_SVLC( iCode, "scaled_ref_layer_top_offset" );     scaledWindow.setWindowTopOffset   (iCode << 1);
+          READ_SVLC( iCode, "scaled_ref_layer_right_offset" );   scaledWindow.setWindowRightOffset (iCode << 1);
+          READ_SVLC( iCode, "scaled_ref_layer_bottom_offset" );  scaledWindow.setWindowBottomOffset(iCode << 1);
+#if P0312_VERT_PHASE_ADJ
+          READ_FLAG( uiCode, "vert_phase_position_enable_flag" ); scaledWindow.setVertPhasePositionEnableFlag(uiCode);  pcPPS->setVertPhasePositionEnableFlag( pcPPS->getScaledRefLayerId(i), uiCode);
+#endif
+        }
+        READ_FLAG( uiCode, "ref_region_offset_present_flag" );   pcPPS->setRefRegionOffsetPresentFlag( i, uiCode );
+        if (uiCode)
+        {
+          Window& refWindow = pcPPS->getRefLayerWindow(i);
+          READ_SVLC( iCode, "ref_region_left_offset" );    refWindow.setWindowLeftOffset  (iCode << 1);
+          READ_SVLC( iCode, "ref_region_top_offset" );     refWindow.setWindowTopOffset   (iCode << 1);
+          READ_SVLC( iCode, "ref_region_right_offset" );   refWindow.setWindowRightOffset (iCode << 1);
+          READ_SVLC( iCode, "ref_region_bottom_offset" );  refWindow.setWindowBottomOffset(iCode << 1);
+        }
+#if R0209_GENERIC_PHASE
+        READ_FLAG( uiCode, "resample_phase_set_present_flag" );   pcPPS->setResamplePhaseSetPresentFlag( i, uiCode );
+        if (uiCode)
+        {
+          READ_UVLC( uiCode, "phase_hor_luma" );    pcPPS->setPhaseHorLuma ( i, uiCode );
+          READ_UVLC( uiCode, "phase_ver_luma" );    pcPPS->setPhaseVerLuma ( i, uiCode );
+          READ_UVLC( uiCode, "phase_hor_chroma_plus8" );  pcPPS->setPhaseHorChroma (i, uiCode - 8);
+          READ_UVLC( uiCode, "phase_ver_chroma_plus8" );  pcPPS->setPhaseVerChroma (i, uiCode - 8);
+        }
+#endif
+      }
+#else
+#if MOVE_SCALED_OFFSET_TO_PPS
+      READ_UVLC( uiCode,      "num_scaled_ref_layer_offsets" ); pcPPS->setNumScaledRefLayerOffsets(uiCode);
+      for(Int i = 0; i < pcPPS->getNumScaledRefLayerOffsets(); i++)
+      {
+        Window& scaledWindow = pcPPS->getScaledRefLayerWindow(i);
+#if O0098_SCALED_REF_LAYER_ID
+        READ_CODE( 6,  uiCode,  "scaled_ref_layer_id" );       pcPPS->setScaledRefLayerId( i, uiCode );
+#endif
+        READ_SVLC( iCode, "scaled_ref_layer_left_offset" );    scaledWindow.setWindowLeftOffset  (iCode << 1);
+        READ_SVLC( iCode, "scaled_ref_layer_top_offset" );     scaledWindow.setWindowTopOffset   (iCode << 1);
+        READ_SVLC( iCode, "scaled_ref_layer_right_offset" );   scaledWindow.setWindowRightOffset (iCode << 1);
+        READ_SVLC( iCode, "scaled_ref_layer_bottom_offset" );  scaledWindow.setWindowBottomOffset(iCode << 1);
+#if P0312_VERT_PHASE_ADJ
+        READ_FLAG( uiCode, "vert_phase_position_enable_flag" ); scaledWindow.setVertPhasePositionEnableFlag(uiCode);  pcPPS->setVertPhasePositionEnableFlag( pcPPS->getScaledRefLayerId(i), uiCode);
+#endif
+      }
+#endif
+#endif
 #if Q0048_CGS_3D_ASYMLUT
       READ_FLAG( uiCode , "colour_mapping_enabled_flag" ); 
@@ -383,8 +445,8 @@
 #endif
 
-    while ( xMoreRbspData() )
-    {
-      READ_FLAG( uiCode, "pps_extension_data_flag");
-    }
+      while ( xMoreRbspData() )
+      {
+        READ_FLAG( uiCode, "pps_extension_data_flag");
+      }
 #if P0166_MODIFIED_PPS_EXTENSION
     }
@@ -397,4 +459,101 @@
   }
 #endif
+#else
+  pcPPS->setExtensionFlag( uiCode ? true : false );
+  if( pcPPS->getExtensionFlag() )
+  {
+    READ_FLAG( uiCode, "pps_range_extension_flag" );
+    assert(uiCode == 0);
+    READ_FLAG( uiCode, "pps_multilayer_extension_flag" );
+    assert(uiCode == 1);
+    READ_CODE(6, uiCode, "pps_extension_6bits");
+    assert(uiCode == 0);
+
+    READ_FLAG( uiCode, "poc_reset_info_present_flag" );
+    pcPPS->setPocResetInfoPresentFlag(uiCode ? true : false);
+
+#if SCALINGLIST_INFERRING
+    READ_FLAG( uiCode, "pps_infer_scaling_list_flag" );
+    pcPPS->setInferScalingListFlag( uiCode );
+
+    if( pcPPS->getInferScalingListFlag() )
+    {
+      READ_UVLC( uiCode, "pps_scaling_list_ref_layer_id" ); 
+      pcPPS->setScalingListRefLayerId( uiCode );
+      // The value of pps_scaling_list_ref_layer_id shall be in the range of 0 to 62, inclusive
+      assert( pcPPS->getScalingListRefLayerId() <= 62 );
+      pcPPS->setScalingListPresentFlag( false );
+    }
+#endif
+
+#if REF_REGION_OFFSET
+    READ_UVLC( uiCode,      "num_ref_loc_offsets" ); pcPPS->setNumScaledRefLayerOffsets(uiCode);
+    for(Int i = 0; i < pcPPS->getNumScaledRefLayerOffsets(); i++)
+    {
+      READ_CODE( 6, uiCode,  "ref_loc_offset_layer_id" );  pcPPS->setScaledRefLayerId( i, uiCode );
+      READ_FLAG( uiCode, "scaled_ref_layer_offset_present_flag" );   pcPPS->setScaledRefLayerOffsetPresentFlag( i, uiCode );
+      if (uiCode)
+      {
+        Window& scaledWindow = pcPPS->getScaledRefLayerWindow(i);
+        READ_SVLC( iCode, "scaled_ref_layer_left_offset" );    scaledWindow.setWindowLeftOffset  (iCode << 1);
+        READ_SVLC( iCode, "scaled_ref_layer_top_offset" );     scaledWindow.setWindowTopOffset   (iCode << 1);
+        READ_SVLC( iCode, "scaled_ref_layer_right_offset" );   scaledWindow.setWindowRightOffset (iCode << 1);
+        READ_SVLC( iCode, "scaled_ref_layer_bottom_offset" );  scaledWindow.setWindowBottomOffset(iCode << 1);
+#if P0312_VERT_PHASE_ADJ
+        READ_FLAG( uiCode, "vert_phase_position_enable_flag" ); scaledWindow.setVertPhasePositionEnableFlag(uiCode);  pcPPS->setVertPhasePositionEnableFlag( pcPPS->getScaledRefLayerId(i), uiCode);
+#endif
+      }
+      READ_FLAG( uiCode, "ref_region_offset_present_flag" );   pcPPS->setRefRegionOffsetPresentFlag( i, uiCode );
+      if (uiCode)
+      {
+        Window& refWindow = pcPPS->getRefLayerWindow(i);
+        READ_SVLC( iCode, "ref_region_left_offset" );    refWindow.setWindowLeftOffset  (iCode << 1);
+        READ_SVLC( iCode, "ref_region_top_offset" );     refWindow.setWindowTopOffset   (iCode << 1);
+        READ_SVLC( iCode, "ref_region_right_offset" );   refWindow.setWindowRightOffset (iCode << 1);
+        READ_SVLC( iCode, "ref_region_bottom_offset" );  refWindow.setWindowBottomOffset(iCode << 1);
+      }
+#if R0209_GENERIC_PHASE
+      READ_FLAG( uiCode, "resample_phase_set_present_flag" );   pcPPS->setResamplePhaseSetPresentFlag( i, uiCode );
+      if (uiCode)
+      {
+        READ_UVLC( uiCode, "phase_hor_luma" );    pcPPS->setPhaseHorLuma ( i, uiCode );
+        READ_UVLC( uiCode, "phase_ver_luma" );    pcPPS->setPhaseVerLuma ( i, uiCode );
+        READ_UVLC( uiCode, "phase_hor_chroma_plus8" );  pcPPS->setPhaseHorChroma (i, uiCode - 8);
+        READ_UVLC( uiCode, "phase_ver_chroma_plus8" );  pcPPS->setPhaseVerChroma (i, uiCode - 8);
+      }
+#endif
+    }
+#else
+#if MOVE_SCALED_OFFSET_TO_PPS
+      READ_UVLC( uiCode,      "num_scaled_ref_layer_offsets" ); pcPPS->setNumScaledRefLayerOffsets(uiCode);
+      for(Int i = 0; i < pcPPS->getNumScaledRefLayerOffsets(); i++)
+      {
+        Window& scaledWindow = pcPPS->getScaledRefLayerWindow(i);
+#if O0098_SCALED_REF_LAYER_ID
+        READ_CODE( 6,  uiCode,  "scaled_ref_layer_id" );       pcPPS->setScaledRefLayerId( i, uiCode );
+#endif
+        READ_SVLC( iCode, "scaled_ref_layer_left_offset" );    scaledWindow.setWindowLeftOffset  (iCode << 1);
+        READ_SVLC( iCode, "scaled_ref_layer_top_offset" );     scaledWindow.setWindowTopOffset   (iCode << 1);
+        READ_SVLC( iCode, "scaled_ref_layer_right_offset" );   scaledWindow.setWindowRightOffset (iCode << 1);
+        READ_SVLC( iCode, "scaled_ref_layer_bottom_offset" );  scaledWindow.setWindowBottomOffset(iCode << 1);
+#if P0312_VERT_PHASE_ADJ
+        READ_FLAG( uiCode, "vert_phase_position_enable_flag" ); scaledWindow.setVertPhasePositionEnableFlag(uiCode);  pcPPS->setVertPhasePositionEnableFlag( pcPPS->getScaledRefLayerId(i), uiCode);
+#endif
+      }
+#endif
+#endif
+#if Q0048_CGS_3D_ASYMLUT
+      READ_FLAG( uiCode , "colour_mapping_enabled_flag" ); 
+      pcPPS->setCGSFlag( uiCode );
+      if( pcPPS->getCGSFlag() )
+      {
+        xParse3DAsymLUT( pc3DAsymLUT );
+        pcPPS->setCGSOutputBitDepthY( pc3DAsymLUT->getOutputBitDepthY() );
+        pcPPS->setCGSOutputBitDepthC( pc3DAsymLUT->getOutputBitDepthC() );
+      }
+#endif
+  }
+#endif
+
 }
 
@@ -476,9 +635,9 @@
       READ_UVLC(   uiCode, "vui_num_ticks_poc_diff_one_minus1");    timingInfo->setNumTicksPocDiffOneMinus1   (uiCode);
     }
-  READ_FLAG(     uiCode, "hrd_parameters_present_flag");              pcVUI->setHrdParametersPresentFlag(uiCode);
-  if( pcVUI->getHrdParametersPresentFlag() )
-  {
-    parseHrdParameters( pcVUI->getHrdParameters(), 1, pcSPS->getMaxTLayers() - 1 );
-  }
+    READ_FLAG(     uiCode, "hrd_parameters_present_flag");              pcVUI->setHrdParametersPresentFlag(uiCode);
+    if( pcVUI->getHrdParametersPresentFlag() )
+    {
+      parseHrdParameters( pcVUI->getHrdParameters(), 1, pcSPS->getMaxTLayers() - 1 );
+    }
   }
   READ_FLAG(     uiCode, "bitstream_restriction_flag");               pcVUI->setBitstreamRestrictionFlag(uiCode);
@@ -524,4 +683,11 @@
       READ_CODE( 5, uiCode, "dpb_output_delay_length_minus1" );       hrd->setDpbOutputDelayLengthMinus1( uiCode );
     }
+#if VPS_VUI_BSP_HRD_PARAMS
+    else
+    {
+      hrd->setInitialCpbRemovalDelayLengthMinus1( 23 );
+      // Add inferred values for other syntax elements here.
+    }
+#endif
   }
   Int i, j, nalOrVcl;
@@ -554,5 +720,5 @@
     {
       if( ( ( nalOrVcl == 0 ) && ( hrd->getNalHrdParametersPresentFlag() ) ) ||
-          ( ( nalOrVcl == 1 ) && ( hrd->getVclHrdParametersPresentFlag() ) ) )
+        ( ( nalOrVcl == 1 ) && ( hrd->getVclHrdParametersPresentFlag() ) ) )
       {
         for( j = 0; j <= ( hrd->getCpbCntMinus1( i ) ); j ++ )
@@ -582,4 +748,8 @@
 #endif
 
+#if R0042_PROFILE_INDICATION
+  UInt uiTmp = 0;
+  Bool bMultiLayerExtSpsFlag;
+#endif
   UInt  uiCode;
   READ_CODE( 4,  uiCode, "sps_video_parameter_set_id");          pcSPS->setVPSId        ( uiCode );
@@ -590,5 +760,34 @@
     READ_CODE( 3,  uiCode, "sps_max_sub_layers_minus1" );          pcSPS->setMaxTLayers   ( uiCode+1 );
     assert(uiCode <= 6);
-
+#if SVC_EXTENSION
+  }
+#if R0042_PROFILE_INDICATION
+  else
+  {
+    READ_CODE( 3,  uiCode, "sps_ext_or_max_sub_layers_minus1" );     uiTmp = uiCode;
+  }
+#endif
+#if !SPS_DPB_PARAMS
+  if(pcSPS->getLayerId() != 0)
+  {
+    pcSPS->setMaxTLayers           ( parameterSetManager->getPrefetchedVPS(pcSPS->getVPSId())->getMaxTLayers()          );
+  }
+#endif
+#endif
+
+#if SVC_EXTENSION
+#if R0042_PROFILE_INDICATION
+  bMultiLayerExtSpsFlag = ( pcSPS->getLayerId() != 0 && uiTmp == 7 );
+#endif
+#endif
+
+#if SVC_EXTENSION
+#if !R0042_PROFILE_INDICATION
+  if(pcSPS->getLayerId() == 0)
+#else
+  if(!bMultiLayerExtSpsFlag)
+#endif
+  {
+#endif
     READ_FLAG( uiCode, "sps_temporal_id_nesting_flag" );               pcSPS->setTemporalIdNestingFlag ( uiCode > 0 ? true : false );
 #if SVC_EXTENSION
@@ -597,5 +796,4 @@
   else
   {
-    pcSPS->setMaxTLayers           ( parameterSetManager->getPrefetchedVPS(pcSPS->getVPSId())->getMaxTLayers()          );
     pcSPS->setTemporalIdNestingFlag( parameterSetManager->getPrefetchedVPS(pcSPS->getVPSId())->getTemporalNestingFlag() );
   }
@@ -618,5 +816,9 @@
 
 #ifdef SPS_PTL_FIX
+#if !R0042_PROFILE_INDICATION
   if ( pcSPS->getLayerId() == 0)
+#else
+  if(!bMultiLayerExtSpsFlag)
+#endif
   {
     parsePTL(pcSPS->getPTL(), 1, pcSPS->getMaxTLayers() - 1);
@@ -630,8 +832,19 @@
 
 #if REPN_FORMAT_IN_VPS
+#if !R0042_PROFILE_INDICATION
   if( pcSPS->getLayerId() > 0 )
+#else
+  if( bMultiLayerExtSpsFlag)
+#endif
   {
     READ_FLAG( uiCode, "update_rep_format_flag" );
     pcSPS->setUpdateRepFormatFlag( uiCode ? true : false );
+#if R0042_PROFILE_INDICATION    
+    if( bMultiLayerExtSpsFlag && uiCode)
+    {
+      READ_CODE(8, uiCode, "sps_rep_format_idx");
+      pcSPS->setUpdateRepFormatIndex(uiCode);
+    }
+#endif
   }
   else
@@ -643,8 +856,14 @@
 #endif
   }
+
+#if R0042_PROFILE_INDICATION  
+  if( !bMultiLayerExtSpsFlag )
+  {
+#else
 #if O0096_REP_FORMAT_INDEX
   if( pcSPS->getLayerId() == 0 )
 #else
   if( pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() )
+#endif
 #endif
   {
@@ -668,4 +887,5 @@
   }
 #if O0096_REP_FORMAT_INDEX
+#if !R0042_PROFILE_INDICATION
   else if ( pcSPS->getUpdateRepFormatFlag() )
   {
@@ -675,25 +895,47 @@
 #endif
 #endif
-  READ_FLAG(     uiCode, "conformance_window_flag");
-  if (uiCode != 0)
-  {
-    Window &conf = pcSPS->getConformanceWindow();
+#endif
+
+#if R0156_CONF_WINDOW_IN_REP_FORMAT
 #if REPN_FORMAT_IN_VPS
-    READ_UVLC(   uiCode, "conf_win_left_offset" );               conf.setWindowLeftOffset  ( uiCode );
-    READ_UVLC(   uiCode, "conf_win_right_offset" );              conf.setWindowRightOffset ( uiCode );
-    READ_UVLC(   uiCode, "conf_win_top_offset" );                conf.setWindowTopOffset   ( uiCode );
-    READ_UVLC(   uiCode, "conf_win_bottom_offset" );             conf.setWindowBottomOffset( uiCode );
-#else
-    READ_UVLC(   uiCode, "conf_win_left_offset" );               conf.setWindowLeftOffset  ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
-    READ_UVLC(   uiCode, "conf_win_right_offset" );              conf.setWindowRightOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
-    READ_UVLC(   uiCode, "conf_win_top_offset" );                conf.setWindowTopOffset   ( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
-    READ_UVLC(   uiCode, "conf_win_bottom_offset" );             conf.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
-#endif
-  }
-#if REPN_FORMAT_IN_VPS
+#if !R0042_PROFILE_INDICATION  
 #if O0096_REP_FORMAT_INDEX
   if( pcSPS->getLayerId() == 0 )
 #else
   if(  pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() )
+#endif
+#endif
+  {
+#endif
+#endif
+    READ_FLAG(     uiCode, "conformance_window_flag");
+    if (uiCode != 0)
+    {
+      Window &conf = pcSPS->getConformanceWindow();
+#if REPN_FORMAT_IN_VPS
+      READ_UVLC(   uiCode, "conf_win_left_offset" );               conf.setWindowLeftOffset  ( uiCode );
+      READ_UVLC(   uiCode, "conf_win_right_offset" );              conf.setWindowRightOffset ( uiCode );
+      READ_UVLC(   uiCode, "conf_win_top_offset" );                conf.setWindowTopOffset   ( uiCode );
+      READ_UVLC(   uiCode, "conf_win_bottom_offset" );             conf.setWindowBottomOffset( uiCode );
+#else
+      READ_UVLC(   uiCode, "conf_win_left_offset" );               conf.setWindowLeftOffset  ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
+      READ_UVLC(   uiCode, "conf_win_right_offset" );              conf.setWindowRightOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
+      READ_UVLC(   uiCode, "conf_win_top_offset" );                conf.setWindowTopOffset   ( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
+      READ_UVLC(   uiCode, "conf_win_bottom_offset" );             conf.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
+#endif
+    }
+#if R0156_CONF_WINDOW_IN_REP_FORMAT
+#if REPN_FORMAT_IN_VPS
+  }
+#endif
+#endif
+
+#if REPN_FORMAT_IN_VPS
+#if !R0042_PROFILE_INDICATION  
+#if O0096_REP_FORMAT_INDEX
+  if( pcSPS->getLayerId() == 0 )
+#else
+  if(  pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() )
+#endif
 #endif
   {
@@ -711,10 +953,19 @@
   }
 #endif
+#if R0042_PROFILE_INDICATION  
+  }
+#endif
+
   READ_UVLC( uiCode,    "log2_max_pic_order_cnt_lsb_minus4" );   pcSPS->setBitsForPOC( 4 + uiCode );
   assert(uiCode <= 12);
 
 #if SPS_DPB_PARAMS
+#if !R0042_PROFILE_INDICATION
   if( pcSPS->getLayerId() == 0 )  
   {
+#else
+  if( !bMultiLayerExtSpsFlag )  
+  {
+#endif
 #endif
     UInt subLayerOrderingInfoPresentFlag;
@@ -749,10 +1000,10 @@
   READ_UVLC( uiCode, "log2_diff_max_min_coding_block_size" );
   pcSPS->setLog2DiffMaxMinCodingBlockSize(uiCode);
-  
+
   if (pcSPS->getPTL()->getGeneralPTL()->getLevelIdc() >= Level::LEVEL5)
   {
     assert(log2MinCUSize + pcSPS->getLog2DiffMaxMinCodingBlockSize() >= 5);
   }
-  
+
   Int maxCUDepthDelta = uiCode;
   pcSPS->setMaxCUWidth  ( 1<<(log2MinCUSize + maxCUDepthDelta) );
@@ -773,5 +1024,9 @@
   {
 #if SCALINGLIST_INFERRING
+#if !R0042_PROFILE_INDICATION
     if( pcSPS->getLayerId() > 0 )
+#else
+    if( bMultiLayerExtSpsFlag )
+#endif
     {
       READ_FLAG( uiCode, "sps_infer_scaling_list_flag" ); pcSPS->setInferScalingListFlag( uiCode );
@@ -790,9 +1045,9 @@
     {
 #endif
-    READ_FLAG( uiCode, "sps_scaling_list_data_present_flag" );                 pcSPS->setScalingListPresentFlag ( uiCode );
-    if(pcSPS->getScalingListPresentFlag ())
-    {
-      parseScalingList( pcSPS->getScalingList() );
-    }
+      READ_FLAG( uiCode, "sps_scaling_list_data_present_flag" );                 pcSPS->setScalingListPresentFlag ( uiCode );
+      if(pcSPS->getScalingListPresentFlag ())
+      {
+        parseScalingList( pcSPS->getScalingList() );
+      }
 #if SCALINGLIST_INFERRING
     }
@@ -854,4 +1109,5 @@
   if( pcSPS->getExtensionFlag() )
   {
+#if !R0042_PROFILE_INDICATION
 #if O0142_CONDITIONAL_SPS_EXTENSION
     UInt spsExtensionTypeFlag[8];
@@ -877,5 +1133,15 @@
       }
     }
-  }
+    }
+#else
+    READ_FLAG( uiCode, "sps_range_extension_flag" );
+    assert(uiCode == 0);
+    READ_FLAG( uiCode, "sps_multilayer_extension_flag" );
+    assert(uiCode == 1);
+    READ_CODE(6, uiCode, "sps_extension_6bits");
+    assert(uiCode == 0);
+    parseSPSExtension( pcSPS );
+  }
+#endif
 #else
   if (uiCode)
@@ -899,4 +1165,5 @@
   assert( uiCode == 0 );
 
+#if !MOVE_SCALED_OFFSET_TO_PPS
   if( pcSPS->getLayerId() > 0 )
   {
@@ -918,4 +1185,5 @@
     }
   }
+#endif
 }
 #endif
@@ -926,5 +1194,13 @@
 
   READ_CODE( 4,  uiCode,  "vps_video_parameter_set_id" );         pcVPS->setVPSId( uiCode );
+#if VPS_RESERVED_FLAGS
+  READ_FLAG( uiCode, "vps_base_layer_internal_flag");             pcVPS->setBaseLayerInternalFlag( uiCode ? true : false );
+  READ_FLAG( uiCode, "vps_base_layer_available_flag");            pcVPS->setBaseLayerAvailableFlag( uiCode ? true : false );
+#if VPS_AVC_BL_FLAG_REMOVAL
+  pcVPS->setNonHEVCBaseLayerFlag( (pcVPS->getBaseLayerAvailableFlag() && !pcVPS->getBaseLayerInternalFlag()) ? true : false);
+#endif
+#else
   READ_CODE( 2,  uiCode,  "vps_reserved_three_2bits" );           assert(uiCode == 3);
+#endif
 #if SVC_EXTENSION
 #if O0137_MAX_LAYERID
@@ -1025,4 +1301,9 @@
         READ_FLAG( uiCode, "cprms_present_flag[i]" );               pcVPS->setCprmsPresentFlag( uiCode == 1 ? true : false, i );
       }
+      else
+      {
+        pcVPS->setCprmsPresentFlag( true, i );
+      }
+
       parseHrdParameters(pcVPS->getHrdParameters(i), pcVPS->getCprmsPresentFlag( i ), pcVPS->getMaxTLayers() - 1);
     }
@@ -1082,8 +1363,20 @@
   Int OlsHighestOutputLayerId[MAX_VPS_LAYER_SETS_PLUS1];
 #endif
+#if LIST_OF_PTL
+  if( vps->getMaxLayers() > 1 && vps->getBaseLayerInternalFlag() )
+  {
+    vps->setProfilePresentFlag(1, false);
+    vps->getPTLForExtnPtr()->empty();
+    vps->getPTLForExtnPtr()->resize(2);
+    vps->getPTLForExtn(1)->copyProfileInfo( vps->getPTL() );
+    parsePTL( vps->getPTLForExtn(1), vps->getProfilePresentFlag(1), vps->getMaxTLayers() - 1 );
+  }
+#endif
 #if VPS_EXTN_MASK_AND_DIM_INFO
   UInt numScalabilityTypes = 0, i = 0, j = 0;
 
+#if !VPS_AVC_BL_FLAG_REMOVAL
   READ_FLAG( uiCode, "avc_base_layer_flag" ); vps->setAvcBaseLayerFlag(uiCode ? true : false);
+#endif
 
 #if !P0307_REMOVE_VPS_VUI_OFFSET
@@ -1094,5 +1387,5 @@
 #endif
 #if VPS_VUI_OFFSET
-  READ_CODE( 16, uiCode, "vps_vui_offset" );  vps->setVpsVuiOffset( uiCode );
+    READ_CODE( 16, uiCode, "vps_vui_offset" );  vps->setVpsVuiOffset( uiCode );
 #endif
 #if O0109_MOVE_VPS_VUI_FLAG
@@ -1145,12 +1438,12 @@
     if( !vps->getSplittingFlag() )
     {
-    for(j = 0; j < numScalabilityTypes; j++)
-    {
-      READ_CODE( vps->getDimensionIdLen(j), uiCode, "dimension_id[i][j]" ); vps->setDimensionId(i, j, uiCode);
+      for(j = 0; j < numScalabilityTypes; j++)
+      {
+        READ_CODE( vps->getDimensionIdLen(j), uiCode, "dimension_id[i][j]" ); vps->setDimensionId(i, j, uiCode);
 #if !AUXILIARY_PICTURES
-      assert( uiCode <= vps->getMaxLayerId() );
-#endif
-    }
-  }
+        assert( uiCode <= vps->getMaxLayerId() );
+#endif
+      }
+    }
   }
 #endif
@@ -1215,4 +1508,26 @@
   vps->setTreePartitionLayerIdList();
 #endif
+#if MOVE_ADDN_LS_SIGNALLING
+#if Q0078_ADD_LAYER_SETS
+  if (vps->getNumIndependentLayers() > 1)
+  {
+    READ_UVLC(uiCode, "num_add_layer_sets"); vps->setNumAddLayerSets(uiCode);
+    for (i = 0; i < vps->getNumAddLayerSets(); i++)
+    {
+      for (j = 1; j < vps->getNumIndependentLayers(); j++)
+      {
+        int len = 1;
+        while ((1 << len) < (vps->getNumLayersInTreePartition(j) + 1))
+        {
+          len++;
+        }
+        READ_CODE(len, uiCode, "highest_layer_idx_plus1[i][j]"); vps->setHighestLayerIdxPlus1(i, j, uiCode);
+      }
+    }
+    vps->setNumLayerSets(vps->getNumLayerSets() + vps->getNumAddLayerSets());
+    vps->setLayerIdIncludedFlagsForAddLayerSets();
+  }
+#endif
+#endif
 #if VPS_TSLAYERS
   READ_FLAG( uiCode, "vps_sub_layers_max_minus1_present_flag"); vps->setMaxTSLayersPresentFlag(uiCode ? true : false);
@@ -1239,12 +1554,11 @@
     {
 #if O0225_MAX_TID_FOR_REF_LAYERS
-       for( j = i+1; j <= vps->getMaxLayers() - 1; j++)
-       {
-         if(vps->getDirectDependencyFlag(j, i))
-         {
-           READ_CODE( 3, uiCode, "max_tid_il_ref_pics_plus1[i][j]" ); vps->setMaxTidIlRefPicsPlus1(i, j, uiCode);
-           assert( uiCode <= vps->getMaxTLayers());
-         }
-       }
+      for( j = i+1; j <= vps->getMaxLayers() - 1; j++)
+      {
+        if(vps->getDirectDependencyFlag(j, i))
+        {
+          READ_CODE( 3, uiCode, "max_tid_il_ref_pics_plus1[i][j]" ); vps->setMaxTidIlRefPicsPlus1(i, j, uiCode);          
+        }
+      }
 #else
       READ_CODE( 3, uiCode, "max_tid_il_ref_pics_plus1[i]" ); vps->setMaxTidIlRefPicsPlus1(i, uiCode);
@@ -1258,8 +1572,8 @@
     {
 #if O0225_MAX_TID_FOR_REF_LAYERS
-       for( j = i+1; j <= vps->getMaxLayers() - 1; j++)
-       {
-          vps->setMaxTidIlRefPicsPlus1(i, j, 7);
-       }
+      for( j = i+1; j <= vps->getMaxLayers() - 1; j++)
+      {
+        vps->setMaxTidIlRefPicsPlus1(i, j, 7);
+      }
 #else
       vps->setMaxTidIlRefPicsPlus1(i, 7);
@@ -1276,6 +1590,13 @@
   READ_UVLC(  uiCode, "vps_num_profile_tier_level_minus1"); vps->setNumProfileTierLevel( uiCode + 1 );
 #endif
+#if PER_LAYER_PTL
+  Int const numBitsForPtlIdx = vps->calculateLenOfSyntaxElement( vps->getNumProfileTierLevel() );
+#endif
   vps->getPTLForExtnPtr()->resize(vps->getNumProfileTierLevel());
+#if LIST_OF_PTL
+  for(Int idx = vps->getBaseLayerInternalFlag() ? 2 : 1; idx <= vps->getNumProfileTierLevel() - 1; idx++)
+#else
   for(Int idx = 1; idx <= vps->getNumProfileTierLevel() - 1; idx++)
+#endif
   {
     READ_FLAG( uiCode, "vps_profile_present_flag[i]" ); vps->setProfilePresentFlag(idx, uiCode ? true : false);
@@ -1300,4 +1621,5 @@
 #endif
 
+#if !MOVE_ADDN_LS_SIGNALLING
 #if Q0078_ADD_LAYER_SETS
   if (vps->getNumIndependentLayers() > 1)
@@ -1319,4 +1641,5 @@
     vps->setLayerIdIncludedFlagsForAddLayerSets();
   }
+#endif
 #endif
 
@@ -1363,5 +1686,14 @@
 #endif
   vps->setNumOutputLayerSets( numOutputLayerSets );
-
+#if NECESSARY_LAYER_FLAG
+  // Default output layer set
+  vps->setOutputLayerSetIdx(0, 0);
+  vps->setOutputLayerFlag(0, 0, true);
+  vps->deriveNecessaryLayerFlag(0);
+#if PER_LAYER_PTL
+  vps->getProfileLevelTierIdx()->resize(numOutputLayerSets);
+  vps->getProfileLevelTierIdx(0)->push_back( vps->getBaseLayerInternalFlag() && vps->getMaxLayers() > 1 ? 1 : 0);
+#endif
+#endif
   for(i = 1; i < numOutputLayerSets; i++)
   {
@@ -1379,4 +1711,5 @@
       vps->setOutputLayerSetIdx( i, i );
     }
+    Int layerSetIdxForOutputLayerSet = vps->getOutputLayerSetIdx(i);
 #if Q0078_ADD_LAYER_SETS
     if ( i > vps->getVpsNumLayerSetsMinus1() || vps->getDefaultTargetOutputLayerIdc() >= 2 )
@@ -1385,7 +1718,6 @@
 #endif
     {
-      Int lsIdx = vps->getOutputLayerSetIdx(i);
 #if NUM_OL_FLAGS
-      for(j = 0; j < vps->getNumLayersInIdList(lsIdx); j++)
+      for(j = 0; j < vps->getNumLayersInIdList(layerSetIdxForOutputLayerSet); j++)
 #else
       for(j = 0; j < vps->getNumLayersInIdList(lsIdx) - 1; j++)
@@ -1399,15 +1731,19 @@
       // i <= (vps->getNumLayerSets() - 1)
       // Assign OutputLayerFlag depending on default_one_target_output_layer_flag
-      Int lsIdx = i;
       if( vps->getDefaultTargetOutputLayerIdc() == 1 )
       {
-        for(j = 0; j < vps->getNumLayersInIdList(lsIdx); j++)
-        {
-          vps->setOutputLayerFlag(i, j, (j == (vps->getNumLayersInIdList(lsIdx)-1)) && (vps->getDimensionId(j,1) == 0) );
+        for(j = 0; j < vps->getNumLayersInIdList(layerSetIdxForOutputLayerSet); j++)
+        {
+#if DEF_OPT_LAYER_IDC
+          vps->setOutputLayerFlag(i, j, (j == (vps->getNumLayersInIdList(layerSetIdxForOutputLayerSet)-1))  );
+
+#else
+          vps->setOutputLayerFlag(i, j, (j == (vps->getNumLayersInIdList(layerSetIdxForOutputLayerSet)-1)) && (vps->getDimensionId(j,1) == 0) );
+#endif
         }
       }
       else if ( vps->getDefaultTargetOutputLayerIdc() == 0 )
       {
-        for(j = 0; j < vps->getNumLayersInIdList(lsIdx); j++)
+        for(j = 0; j < vps->getNumLayersInIdList(layerSetIdxForOutputLayerSet); j++)
         {
           vps->setOutputLayerFlag(i, j, 1);
@@ -1415,4 +1751,18 @@
       }
     }
+#if NECESSARY_LAYER_FLAG
+    vps->deriveNecessaryLayerFlag(i);  
+#endif
+#if PER_LAYER_PTL
+    vps->getProfileLevelTierIdx(i)->assign(vps->getNumLayersInIdList(layerSetIdxForOutputLayerSet), -1);
+    for(j = 0; j < vps->getNumLayersInIdList(layerSetIdxForOutputLayerSet) ; j++)
+    {
+      if( vps->getNecessaryLayerFlag(i, j) )
+      {
+        READ_CODE( numBitsForPtlIdx, uiCode, "profile_level_tier_idx[i]" ); 
+        vps->setProfileLevelTierIdx(i, j, uiCode );
+      }
+    }
+#else
     Int numBits = 1;
     while ((1 << numBits) < (vps->getNumProfileTierLevel()))
@@ -1421,7 +1771,7 @@
     }
     READ_CODE( numBits, uiCode, "profile_level_tier_idx[i]" );     vps->setProfileLevelTierIdx(i, uiCode);
+#endif
 #if P0300_ALT_OUTPUT_LAYER_FLAG
     NumOutputLayersInOutputLayerSet[i] = 0;
-    Int layerSetIdxForOutputLayerSet = vps->getOutputLayerSetIdx(i);
     for (j = 0; j < vps->getNumLayersInIdList(layerSetIdxForOutputLayerSet); j++)
     {
@@ -1437,4 +1787,11 @@
       vps->setAltOuputLayerFlag(i, uiCode ? true : false);
     }
+#if ALT_OPT_LAYER_FLAG
+    else
+    {
+          uiCode=0;
+          vps->setAltOuputLayerFlag(i, uiCode ? true : false);
+    }
+#endif
 #if Q0165_OUTPUT_LAYER_SET
     assert( NumOutputLayersInOutputLayerSet[i]>0 );
@@ -1443,4 +1800,7 @@
 #endif
   }
+#if NECESSARY_LAYER_FLAG
+  vps->checkNecessaryLayerFlagCondition();  
+#endif
 #else
   if( numOutputLayerSets > 1 )
@@ -1488,5 +1848,9 @@
         {
 #if O0135_DEFAULT_ONE_OUT_SEMANTIC
+#if DEF_OPT_LAYER_IDC
+        vps->setOutputLayerFlag(i, j, (j == (vps->getNumLayersInIdList(lsIdx)-1)) );
+#else
           vps->setOutputLayerFlag(i, j, (j == (vps->getNumLayersInIdList(lsIdx)-1)) && (vps->getDimensionId(j,1)==0) );
+#endif
 #else
           vps->setOutputLayerFlag(i, j, (j == (vps->getNumLayersInIdList(lsIdx)-1)));
@@ -1669,4 +2033,8 @@
   READ_FLAG(uiCode, "max_one_active_ref_layer_flag" );
   vps->setMaxOneActiveRefLayerFlag(uiCode);
+#if P0297_VPS_POC_LSB_ALIGNED_FLAG
+  READ_FLAG(uiCode, "vps_poc_lsb_aligned_flag");
+  vps->setVpsPocLsbAlignedFlag(uiCode);
+#endif
 #if O0062_POC_LSB_NOT_PRESENT_FLAG
   for(i = 1; i< vps->getMaxLayers(); i++)
@@ -1824,5 +2192,5 @@
 #endif
   }
-  
+
   // When not present, the value of num_add_olss is inferred to be equal to 0.
   // NumOutputLayerSets = num_add_olss + NumLayerSets
@@ -1838,5 +2206,5 @@
     for( j = 0; j < vps->getNumLayersInIdList(lsIdx); j++ )
     {
-    vps->setOutputLayerFlag(i, j, 1);
+      vps->setOutputLayerFlag(i, j, 1);
     }
   }
@@ -1848,5 +2216,5 @@
     vps->setSubLayerDpbInfoPresentFlag( i, 0, true );
   }
-  
+
   // When not present, the value of vps_num_rep_formats_minus1 is inferred to be equal to MaxLayersMinus1.
   vps->setVpsNumRepFormats( vps->getMaxLayers() );
@@ -1864,7 +2232,8 @@
   }
 
-  // vps_poc_lsb_aligned_flag
-  // When not present, vps_poc_lsb_aligned_flag is inferred to be equal to 0.
-  
+#if P0297_VPS_POC_LSB_ALIGNED_FLAG
+  vps->setVpsPocLsbAlignedFlag(false);
+#endif
+
 #if O0062_POC_LSB_NOT_PRESENT_FLAG
   // When not present, poc_lsb_not_present_flag[ i ] is inferred to be equal to 0.
@@ -1937,4 +2306,5 @@
     repFormat->setBitDepthVpsChroma         ( repFormatPrev->getBitDepthVpsChroma() );
   }
+
 #else 
 #if AUXILIARY_PICTURES
@@ -1943,5 +2313,5 @@
   READ_CODE( 2, uiCode, "chroma_format_idc" );               repFormat->setChromaFormatVpsIdc( uiCode );
 #endif
-  
+
   if( repFormat->getChromaFormatVpsIdc() == 3 )
   {
@@ -1955,4 +2325,16 @@
   READ_CODE( 4, uiCode, "bit_depth_chroma_minus8" );         repFormat->setBitDepthVpsChroma( uiCode + 8 );
 #endif 
+
+#if R0156_CONF_WINDOW_IN_REP_FORMAT
+  READ_FLAG( uiCode, "conformance_window_vps_flag" );
+  if( uiCode != 0) 
+  {
+    Window &conf = repFormat->getConformanceWindowVps();
+    READ_UVLC( uiCode, "conf_win_vps_left_offset" );         conf.setWindowLeftOffset  ( uiCode );
+    READ_UVLC( uiCode, "conf_win_vps_right_offset" );        conf.setWindowRightOffset ( uiCode );
+    READ_UVLC( uiCode, "conf_win_vps_top_offset" );          conf.setWindowTopOffset   ( uiCode );
+    READ_UVLC( uiCode, "conf_win_vps_bottom_offset" );       conf.setWindowBottomOffset( uiCode );
+  }
+#endif
 }
 #endif
@@ -1961,33 +2343,37 @@
 {
   UInt uiCode;
+#if SUB_LAYERS_IN_LAYER_SET
+  vps->calculateMaxSLInLayerSets();
+#else
 #if DPB_PARAMS_MAXTLAYERS
 #if BITRATE_PICRATE_SIGNALLING
-    Int * MaxSubLayersInLayerSetMinus1 = new Int[vps->getNumLayerSets()];
-    for(Int i = 0; i < vps->getNumLayerSets(); i++)
-#else
-    Int * MaxSubLayersInLayerSetMinus1 = new Int[vps->getNumOutputLayerSets()];
-    for(Int i = 1; i < vps->getNumOutputLayerSets(); i++)
-#endif
-    {
-        UInt maxSLMinus1 = 0;
+  Int * MaxSubLayersInLayerSetMinus1 = new Int[vps->getNumLayerSets()];
+  for(Int i = 0; i < vps->getNumLayerSets(); i++)
+#else
+  Int * MaxSubLayersInLayerSetMinus1 = new Int[vps->getNumOutputLayerSets()];
+  for(Int i = 1; i < vps->getNumOutputLayerSets(); i++)
+#endif
+  {
+    UInt maxSLMinus1 = 0;
 #if CHANGE_NUMSUBDPB_IDX
-        Int optLsIdx = vps->getOutputLayerSetIdx( i );
-#else
-        Int optLsIdx = i;
+    Int optLsIdx = vps->getOutputLayerSetIdx( i );
+#else
+    Int optLsIdx = i;
 #endif
 #if BITRATE_PICRATE_SIGNALLING
-        optLsIdx = i;
-#endif
-        for(Int k = 0; k < vps->getNumLayersInIdList(optLsIdx); k++ ) {
-            Int  lId = vps->getLayerSetLayerIdList(optLsIdx, k);
-            maxSLMinus1 = max(maxSLMinus1, vps->getMaxTSLayersMinus1(vps->getLayerIdInVps(lId)));
-        }
-        MaxSubLayersInLayerSetMinus1[ i ] = maxSLMinus1;
+    optLsIdx = i;
+#endif
+    for(Int k = 0; k < vps->getNumLayersInIdList(optLsIdx); k++ ) {
+      Int  lId = vps->getLayerSetLayerIdList(optLsIdx, k);
+      maxSLMinus1 = max(maxSLMinus1, vps->getMaxTSLayersMinus1(vps->getLayerIdInVps(lId)));
+    }
+    MaxSubLayersInLayerSetMinus1[ i ] = maxSLMinus1;
 #if BITRATE_PICRATE_SIGNALLING
-        vps->setMaxSLayersInLayerSetMinus1(i,MaxSubLayersInLayerSetMinus1[ i ]);
-#endif
-    }
-#endif
-    
+    vps->setMaxSLayersInLayerSetMinus1(i,MaxSubLayersInLayerSetMinus1[ i ]);
+#endif
+  }
+#endif
+#endif
+
 #if !RESOLUTION_BASED_DPB
   vps->deriveNumberOfSubDpbs();
@@ -1999,4 +2385,7 @@
 #endif
     READ_FLAG( uiCode, "sub_layer_flag_info_present_flag[i]");  vps->setSubLayerFlagInfoPresentFlag( i, uiCode ? true : false );
+#if SUB_LAYERS_IN_LAYER_SET
+    for(Int j = 0; j <= vps->getMaxSLayersInLayerSetMinus1( layerSetIdxForOutputLayerSet ); j++)
+#else
 #if DPB_PARAMS_MAXTLAYERS
 #if BITRATE_PICRATE_SIGNALLING
@@ -2008,4 +2397,5 @@
     for(Int j = 0; j <= vps->getMaxTLayers(); j++)
 #endif
+#endif
     {
       if( j > 0 && vps->getSubLayerFlagInfoPresentFlag(i) )
@@ -2032,4 +2422,8 @@
 #endif
         {
+#if DPB_INTERNAL_BL_SIG
+            uiCode=0;
+        if(vps->getBaseLayerInternalFlag()  || ( vps->getLayerSetLayerIdList(layerSetIdxForOutputLayerSet, k)   !=  0 ) )
+#endif
           READ_UVLC( uiCode, "max_vps_dec_pic_buffering_minus1[i][k][j]" ); vps->setMaxVpsDecPicBufferingMinus1( i, k, j, uiCode );
         }
@@ -2060,4 +2454,13 @@
   }
 
+#if !SUB_LAYERS_IN_LAYER_SET
+#if BITRATE_PICRATE_SIGNALLING
+  if( MaxSubLayersInLayerSetMinus1 )
+  {
+    delete [] MaxSubLayersInLayerSetMinus1;
+  }
+#endif
+#endif
+
   // Infer values when not signalled
   for(Int i = 1; i < vps->getNumOutputLayerSets(); i++)
@@ -2122,8 +2525,51 @@
   READ_FLAG( uiCode,        "pic_rate_present_vps_flag" );  vps->setPicRatePresentVpsFlag( uiCode ? true : false );
 
+#if SIGNALLING_BITRATE_PICRATE_FIX
+  if ( vps->getBitRatePresentVpsFlag() || vps->getPicRatePresentVpsFlag() )
+  {
+    for( i = vps->getBaseLayerInternalFlag() ? 0 : 1; i < vps->getNumLayerSets(); i++ )
+    {
+      for( j = 0; j <= vps->getMaxSLayersInLayerSetMinus1( i ); j++ ) 
+      {
+        if( vps->getBitRatePresentVpsFlag() )
+        {
+          READ_FLAG( uiCode, "bit_rate_present_flag[i][j]" ); vps->setBitRatePresentFlag( i, j, uiCode ? true : false );            
+        }
+        if( vps->getPicRatePresentVpsFlag( )  )
+        {
+          READ_FLAG( uiCode, "pic_rate_present_flag[i][j]" ); vps->setPicRatePresentFlag( i, j, uiCode ? true : false );
+        }
+        if( vps->getBitRatePresentFlag( i, j ) )
+        {
+          READ_CODE( 16, uiCode, "avg_bit_rate" ); vps->setAvgBitRate( i, j, uiCode );
+          READ_CODE( 16, uiCode, "max_bit_rate" ); vps->setMaxBitRate( i, j, uiCode );
+        }
+        else
+        {
+          vps->setAvgBitRate( i, j, 0 );
+          vps->setMaxBitRate( i, j, 0 );
+        }
+        if( vps->getPicRatePresentFlag( i, j ) )
+        {
+          READ_CODE( 2,  uiCode, "constant_pic_rate_idc" ); vps->setConstPicRateIdc( i, j, uiCode );
+          READ_CODE( 16, uiCode, "avg_pic_rate" );          vps->setAvgPicRate( i, j, uiCode );
+        }
+        else
+        {
+          vps->setConstPicRateIdc( i, j, 0 );
+          vps->setAvgPicRate( i, j, 0 );
+        }
+      }
+    }
+  }
+#else
   Bool parseFlag = vps->getBitRatePresentVpsFlag() || vps->getPicRatePresentVpsFlag();
 
 #if Q0078_ADD_LAYER_SETS
+#if R0227_BR_PR_ADD_LAYER_SET
+  for( i = 0; i < vps->getNumLayerSets(); i++ )
+#else
   for( i = 0; i <= vps->getVpsNumLayerSetsMinus1(); i++ )
+#endif
 #else
   for( i = 0; i < vps->getNumLayerSets(); i++ )
@@ -2174,4 +2620,5 @@
     }
   }
+#endif
 #if VPS_VUI_VIDEO_SIGNAL_MOVE
   READ_FLAG( uiCode, "video_signal_info_idx_present_flag" ); vps->setVideoSigPresentVpsFlag( uiCode == 1 );
@@ -2182,5 +2629,9 @@
   else
   {
+#if VPS_VUI_VST_PARAMS
+    vps->setNumVideoSignalInfo(vps->getMaxLayers() - vps->getBaseLayerInternalFlag() ? 0 : 1);
+#else
     vps->setNumVideoSignalInfo(vps->getMaxLayers());
+#endif
   }
 
@@ -2193,4 +2644,27 @@
     READ_CODE(8, uiCode, "matrix_coeffs_vps" );vps->setMaxtrixCoeff(i,uiCode);
   }
+#if VPS_VUI_VST_PARAMS
+  if( vps->getVideoSigPresentVpsFlag() && vps->getNumVideoSignalInfo() > 1 )
+  {
+    for(i = vps->getBaseLayerInternalFlag() ? 0 : 1; i < vps->getMaxLayers(); i++)
+    {
+      READ_CODE(4, uiCode, "vps_video_signal_info_idx" ); vps->setVideoSignalInfoIdx(i, uiCode);
+    }
+  }
+  else if ( !vps->getVideoSigPresentVpsFlag() )
+  {
+    for(i = vps->getBaseLayerInternalFlag() ? 0 : 1; i < vps->getMaxLayers(); i++)
+    {
+      vps->setVideoSignalInfoIdx( i, i );
+    }
+  }
+  else // ( vps->getNumVideoSignalInfo() = 0 )
+  {
+    for(i = vps->getBaseLayerInternalFlag() ? 0 : 1; i < vps->getMaxLayers(); i++)
+    {
+      vps->setVideoSignalInfoIdx( i, 0 );
+    }
+  }
+#else
   if(!vps->getVideoSigPresentVpsFlag())
   {
@@ -2214,4 +2688,5 @@
     }
   }
+#endif
 #endif 
 #if VPS_VUI_TILES_NOT_IN_USE__FLAG
@@ -2303,144 +2778,151 @@
 #if VPS_VUI_VIDEO_SIGNAL_MOVE
 #else
-    READ_FLAG( uiCode, "video_signal_info_idx_present_flag" ); vps->setVideoSigPresentVpsFlag( uiCode == 1 );
-    if (vps->getVideoSigPresentVpsFlag())
-    {
-        READ_CODE(4, uiCode, "vps_num_video_signal_info_minus1" ); vps->setNumVideoSignalInfo(uiCode + 1);
+  READ_FLAG( uiCode, "video_signal_info_idx_present_flag" ); vps->setVideoSigPresentVpsFlag( uiCode == 1 );
+  if (vps->getVideoSigPresentVpsFlag())
+  {
+    READ_CODE(4, uiCode, "vps_num_video_signal_info_minus1" ); vps->setNumVideoSignalInfo(uiCode + 1);
+  }
+  else
+  {
+    vps->setNumVideoSignalInfo(vps->getMaxLayers());
+  }
+
+
+  for(i = 0; i < vps->getNumVideoSignalInfo(); i++)
+  {
+    READ_CODE(3, uiCode, "video_vps_format" ); vps->setVideoVPSFormat(i,uiCode);
+    READ_FLAG(uiCode, "video_full_range_vps_flag" ); vps->setVideoFullRangeVpsFlag(i,uiCode);
+    READ_CODE(8, uiCode, "color_primaries_vps" ); vps->setColorPrimaries(i,uiCode);
+    READ_CODE(8, uiCode, "transfer_characteristics_vps" ); vps->setTransCharacter(i,uiCode);
+    READ_CODE(8, uiCode, "matrix_coeffs_vps" );vps->setMaxtrixCoeff(i,uiCode);
+  }
+  if(!vps->getVideoSigPresentVpsFlag())
+  {
+    for (i=0; i < vps->getMaxLayers(); i++)
+    {
+      vps->setVideoSignalInfoIdx(i,i);
+    }
+  }
+  else {
+    vps->setVideoSignalInfoIdx(0,0);
+    if (vps->getNumVideoSignalInfo() > 1 )
+    {
+      for (i=1; i < vps->getMaxLayers(); i++)
+        READ_CODE(4, uiCode, "vps_video_signal_info_idx" ); vps->setVideoSignalInfoIdx(i, uiCode);
+    }
+    else {
+      for (i=1; i < vps->getMaxLayers(); i++)
+      {
+        vps->setVideoSignalInfoIdx(i,0);
+      }
+    }
+  }
+#endif 
+#endif
+
+#if O0164_MULTI_LAYER_HRD
+  READ_FLAG(uiCode, "vps_vui_bsp_hrd_present_flag" ); vps->setVpsVuiBspHrdPresentFlag(uiCode);
+  if (vps->getVpsVuiBspHrdPresentFlag())
+  {
+#if VPS_VUI_BSP_HRD_PARAMS
+    parseVpsVuiBspHrdParams(vps);
+#else
+#if R0227_VUI_BSP_HRD_FLAG
+    assert (vps->getTimingInfo()->getTimingInfoPresentFlag() == 1);
+#endif
+    READ_UVLC( uiCode, "vps_num_bsp_hrd_parameters_minus1" ); vps->setVpsNumBspHrdParametersMinus1(uiCode);
+    vps->createBspHrdParamBuffer(vps->getVpsNumBspHrdParametersMinus1() + 1);
+    for( i = 0; i <= vps->getVpsNumBspHrdParametersMinus1(); i++ )
+    {
+      if( i > 0 )
+      {
+        READ_FLAG( uiCode, "bsp_cprms_present_flag[i]" ); vps->setBspCprmsPresentFlag(i, uiCode);
+      }
+      parseHrdParameters(vps->getBspHrd(i), i==0 ? 1 : vps->getBspCprmsPresentFlag(i), vps->getMaxTLayers()-1);
+    }
+#if Q0078_ADD_LAYER_SETS
+    for (UInt h = 1; h <= vps->getVpsNumLayerSetsMinus1(); h++)
+#else
+    for( UInt h = 1; h <= (vps->getNumLayerSets()-1); h++ )
+#endif
+    {
+      READ_UVLC( uiCode, "num_bitstream_partitions[i]"); vps->setNumBitstreamPartitions(h, uiCode);
+#if HRD_BPB
+      Int chkPart=0;
+#endif
+      for( i = 0; i < vps->getNumBitstreamPartitions(h); i++ )
+      {
+        for( j = 0; j <= (vps->getMaxLayers()-1); j++ )
+        {
+          if( vps->getLayerIdIncludedFlag(h, j) )
+          {
+            READ_FLAG( uiCode, "layer_in_bsp_flag[h][i][j]" ); vps->setLayerInBspFlag(h, i, j, uiCode);
+          }
+        }
+#if HRD_BPB
+        chkPart+=vps->getLayerInBspFlag(h, i, j);
+#endif
+      }
+#if HRD_BPB
+      assert(chkPart<=1);
+#endif
+#if HRD_BPB
+      if(vps->getNumBitstreamPartitions(h)==1)
+      {
+        Int chkPartition1=0; Int chkPartition2=0;
+        for( j = 0; j <= (vps->getMaxLayers()-1); j++ )
+        {
+          if( vps->getLayerIdIncludedFlag(h, j) )
+          {
+            chkPartition1+=vps->getLayerInBspFlag(h, 0, j);
+            chkPartition2++;
+          }
+        }
+        assert(chkPartition1!=chkPartition2);
+      }
+#endif
+      if (vps->getNumBitstreamPartitions(h))
+      {
+#if Q0182_MULTI_LAYER_HRD_UPDATE
+        READ_UVLC( uiCode, "num_bsp_sched_combinations_minus1[h]"); vps->setNumBspSchedCombinations(h, uiCode + 1);
+#else
+        READ_UVLC( uiCode, "num_bsp_sched_combinations[h]"); vps->setNumBspSchedCombinations(h, uiCode);
+#endif
+        for( i = 0; i < vps->getNumBspSchedCombinations(h); i++ )
+        {
+          for( j = 0; j < vps->getNumBitstreamPartitions(h); j++ )
+          {
+            READ_UVLC( uiCode, "bsp_comb_hrd_idx[h][i][j]"); vps->setBspCombHrdIdx(h, i, j, uiCode);
+#if HRD_BPB
+            assert(uiCode <= vps->getVpsNumBspHrdParametersMinus1());
+#endif
+
+            READ_UVLC( uiCode, "bsp_comb_sched_idx[h][i][j]"); vps->setBspCombSchedIdx(h, i, j, uiCode);
+#if HRD_BPB
+            assert(uiCode <= vps->getBspHrdParamBufferCpbCntMinus1(uiCode,vps->getMaxTLayers()-1));
+#endif
+          }
+        }
+      }
+    }
+#endif
+  }
+#endif
+#if P0182_VPS_VUI_PS_FLAG
+  for(i = 1; i < vps->getMaxLayers(); i++)
+  {
+    if (vps->getNumRefLayers(vps->getLayerIdInNuh(i)) == 0)
+    {
+      READ_FLAG( uiCode, "base_layer_parameter_set_compatibility_flag" ); 
+      vps->setBaseLayerPSCompatibilityFlag( i, uiCode );
     }
     else
     {
-        vps->setNumVideoSignalInfo(vps->getMaxLayers());
-    }
-    
-    
-    for(i = 0; i < vps->getNumVideoSignalInfo(); i++)
-    {
-        READ_CODE(3, uiCode, "video_vps_format" ); vps->setVideoVPSFormat(i,uiCode);
-        READ_FLAG(uiCode, "video_full_range_vps_flag" ); vps->setVideoFullRangeVpsFlag(i,uiCode);
-        READ_CODE(8, uiCode, "color_primaries_vps" ); vps->setColorPrimaries(i,uiCode);
-        READ_CODE(8, uiCode, "transfer_characteristics_vps" ); vps->setTransCharacter(i,uiCode);
-        READ_CODE(8, uiCode, "matrix_coeffs_vps" );vps->setMaxtrixCoeff(i,uiCode);
-    }
-    if(!vps->getVideoSigPresentVpsFlag())
-    {
-        for (i=0; i < vps->getMaxLayers(); i++)
-        {
-            vps->setVideoSignalInfoIdx(i,i);
-        }
-    }
-    else {
-        vps->setVideoSignalInfoIdx(0,0);
-        if (vps->getNumVideoSignalInfo() > 1 )
-        {
-            for (i=1; i < vps->getMaxLayers(); i++)
-                READ_CODE(4, uiCode, "vps_video_signal_info_idx" ); vps->setVideoSignalInfoIdx(i, uiCode);
-        }
-        else {
-          for (i=1; i < vps->getMaxLayers(); i++)
-          {
-            vps->setVideoSignalInfoIdx(i,0);
-          }
-        }
-    }
-#endif 
-#endif
-
-#if O0164_MULTI_LAYER_HRD
-    READ_FLAG(uiCode, "vps_vui_bsp_hrd_present_flag" ); vps->setVpsVuiBspHrdPresentFlag(uiCode);
-    if (vps->getVpsVuiBspHrdPresentFlag())
-    {
-      READ_UVLC( uiCode, "vps_num_bsp_hrd_parameters_minus1" ); vps->setVpsNumBspHrdParametersMinus1(uiCode);
-      vps->createBspHrdParamBuffer(vps->getVpsNumBspHrdParametersMinus1() + 1);
-      for( i = 0; i <= vps->getVpsNumBspHrdParametersMinus1(); i++ )
-      {
-        if( i > 0 )
-        {
-          READ_FLAG( uiCode, "bsp_cprms_present_flag[i]" ); vps->setBspCprmsPresentFlag(i, uiCode);
-        }
-        parseHrdParameters(vps->getBspHrd(i), i==0 ? 1 : vps->getBspCprmsPresentFlag(i), vps->getMaxTLayers()-1);
-      }
-#if Q0078_ADD_LAYER_SETS
-      for (UInt h = 1; h <= vps->getVpsNumLayerSetsMinus1(); h++)
-#else
-      for( UInt h = 1; h <= (vps->getNumLayerSets()-1); h++ )
-#endif
-      {
-        READ_UVLC( uiCode, "num_bitstream_partitions[i]"); vps->setNumBitstreamPartitions(h, uiCode);
-#if HRD_BPB
-        Int chkPart=0;
-#endif
-        for( i = 0; i < vps->getNumBitstreamPartitions(h); i++ )
-        {
-          for( j = 0; j <= (vps->getMaxLayers()-1); j++ )
-          {
-            if( vps->getLayerIdIncludedFlag(h, j) )
-            {
-              READ_FLAG( uiCode, "layer_in_bsp_flag[h][i][j]" ); vps->setLayerInBspFlag(h, i, j, uiCode);
-            }
-          }
-#if HRD_BPB
-          chkPart+=vps->getLayerInBspFlag(h, i, j);
-#endif
-        }
-#if HRD_BPB
-        assert(chkPart<=1);
-#endif
-#if HRD_BPB
-        if(vps->getNumBitstreamPartitions(h)==1)
-        {
-          Int chkPartition1=0; Int chkPartition2=0;
-          for( j = 0; j <= (vps->getMaxLayers()-1); j++ )
-          {
-            if( vps->getLayerIdIncludedFlag(h, j) )
-            {
-              chkPartition1+=vps->getLayerInBspFlag(h, 0, j);
-              chkPartition2++;
-            }
-          }
-          assert(chkPartition1!=chkPartition2);
-        }
-#endif
-        if (vps->getNumBitstreamPartitions(h))
-        {
-#if Q0182_MULTI_LAYER_HRD_UPDATE
-          READ_UVLC( uiCode, "num_bsp_sched_combinations_minus1[h]"); vps->setNumBspSchedCombinations(h, uiCode + 1);
-#else
-          READ_UVLC( uiCode, "num_bsp_sched_combinations[h]"); vps->setNumBspSchedCombinations(h, uiCode);
-#endif
-          for( i = 0; i < vps->getNumBspSchedCombinations(h); i++ )
-          {
-            for( j = 0; j < vps->getNumBitstreamPartitions(h); j++ )
-            {
-              READ_UVLC( uiCode, "bsp_comb_hrd_idx[h][i][j]"); vps->setBspCombHrdIdx(h, i, j, uiCode);
-#if HRD_BPB
-              assert(uiCode <= vps->getVpsNumBspHrdParametersMinus1());
-#endif
-                
-              READ_UVLC( uiCode, "bsp_comb_sched_idx[h][i][j]"); vps->setBspCombSchedIdx(h, i, j, uiCode);
-#if HRD_BPB
-              assert(uiCode <= vps->getBspHrdParamBufferCpbCntMinus1(uiCode,vps->getMaxTLayers()-1));
-#endif
-            }
-          }
-        }
-      }
-    }
-#endif
-
-#if P0182_VPS_VUI_PS_FLAG
-    for(i = 1; i < vps->getMaxLayers(); i++)
-    {
-      if (vps->getNumRefLayers(vps->getLayerIdInNuh(i)) == 0)
-      {
-        READ_FLAG( uiCode, "base_layer_parameter_set_compatibility_flag" ); 
-        vps->setBaseLayerPSCompatibilityFlag( i, uiCode );
-      }
-      else
-      {
-        vps->setBaseLayerPSCompatibilityFlag( i, 0 );
-      }
-    }
-#endif
-}
+      vps->setBaseLayerPSCompatibilityFlag( i, 0 );
+    }
+  }
+#endif
+}
+
 #endif //SVC_EXTENSION
 
@@ -2476,4 +2958,36 @@
   rpcSlice->setSPS(sps);
   rpcSlice->setPPS(pps);
+
+#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
+  TComVPS* vps = NULL;
+  vps = parameterSetManager->getPrefetchedVPS(sps->getVPSId());
+#if R0279_REP_FORMAT_INBL
+  if ( vps->getVpsExtensionFlag() == 1 && (rpcSlice->getLayerId() == 0 || sps->getV1CompatibleSPSFlag() == 1) )
+  {
+    assert( sps->getPicWidthInLumaSamples() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(rpcSlice->getLayerId()) )->getPicWidthVpsInLumaSamples() );
+    assert( sps->getPicHeightInLumaSamples() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(rpcSlice->getLayerId()) )->getPicHeightVpsInLumaSamples() );
+    assert( sps->getChromaFormatIdc() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(rpcSlice->getLayerId()) )->getChromaFormatVpsIdc() );
+    assert( sps->getBitDepthY() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(rpcSlice->getLayerId()) )->getBitDepthVpsLuma() );
+    assert( sps->getBitDepthC() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(rpcSlice->getLayerId()) )->getBitDepthVpsChroma() );
+#else
+  if ( rpcSlice->getLayerId() == 0 && vps->getVpsExtensionFlag() == 1 )
+  {
+    assert( sps->getPicWidthInLumaSamples() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(0) )->getPicWidthVpsInLumaSamples() );
+    assert( sps->getPicHeightInLumaSamples() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(0) )->getPicHeightVpsInLumaSamples() );
+    assert( sps->getChromaFormatIdc() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(0) )->getChromaFormatVpsIdc() );
+    assert( sps->getBitDepthY() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(0) )->getBitDepthVpsLuma() );
+    assert( sps->getBitDepthC() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(0) )->getBitDepthVpsChroma() );
+#endif
+  }
+  else if ( vps->getVpsExtensionFlag() == 1 )
+  {
+    assert(vps->getVpsRepFormat( vps->getVpsRepFormatIdx(sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : rpcSlice->getLayerId()))->getPicWidthVpsInLumaSamples() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(rpcSlice->getLayerId()))->getPicWidthVpsInLumaSamples());
+    assert(vps->getVpsRepFormat( vps->getVpsRepFormatIdx(sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : rpcSlice->getLayerId()))->getPicHeightVpsInLumaSamples() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(rpcSlice->getLayerId()))->getPicHeightVpsInLumaSamples());
+    assert(vps->getVpsRepFormat( vps->getVpsRepFormatIdx(sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : rpcSlice->getLayerId()))->getChromaFormatVpsIdc() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(rpcSlice->getLayerId()))->getChromaFormatVpsIdc());
+    assert(vps->getVpsRepFormat( vps->getVpsRepFormatIdx(sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : rpcSlice->getLayerId()))->getBitDepthVpsLuma() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(rpcSlice->getLayerId()))->getBitDepthVpsLuma());
+    assert(vps->getVpsRepFormat( vps->getVpsRepFormatIdx(sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : rpcSlice->getLayerId()))->getBitDepthVpsChroma() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(rpcSlice->getLayerId()))->getBitDepthVpsChroma());
+  }
+#endif
+
   if( pps->getDependentSliceSegmentsEnabledFlag() && ( !firstSliceSegmentInPic ))
   {
@@ -2522,5 +3036,5 @@
 #if Q0142_POC_LSB_NOT_PRESENT
 #if SHM_FIX7
-    Int iPOClsb = 0;
+  Int iPOClsb = 0;
 #endif
 #endif
@@ -2557,9 +3071,37 @@
     }
 #else
+#if CROSS_LAYER_BLA_FLAG_FIX
+    Int iBits = 0;
+    if(rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits)
+#else
     if(rpcSlice->getPPS()->getNumExtraSliceHeaderBits()>0)
+#endif
     {
       READ_FLAG(uiCode, "discardable_flag"); // ignored
-    }
+#if NON_REF_NAL_TYPE_DISCARDABLE
+      rpcSlice->setDiscardableFlag( uiCode ? true : false );
+      if (uiCode)
+      {
+        assert(rpcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_TRAIL_R &&
+          rpcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_TSA_R &&
+          rpcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_STSA_R &&
+          rpcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_RADL_R &&
+          rpcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_RASL_R);
+      }
+#endif
+#if CROSS_LAYER_BLA_FLAG_FIX
+      iBits++;
+#endif
+    }
+#if CROSS_LAYER_BLA_FLAG_FIX
+    if(rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits)
+    {
+      READ_FLAG(uiCode, "cross_layer_bla_flag");  rpcSlice->setCrossLayerBLAFlag( uiCode ? true : false );
+      iBits++;
+    }
+    for ( ; iBits < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); iBits++)
+#else
     for (Int i = 1; i < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
+#endif
     {
       READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
@@ -2649,254 +3191,258 @@
 #if N0065_LAYER_POC_ALIGNMENT
 #if SHM_FIX7
-      }
+    }
 #endif
 #if POC_RESET_IDC_DECODER
-    else
-    {
-      rpcSlice->setPicOrderCntLsb( 0 );
-    }
-#endif
-      if( !rpcSlice->getIdrPicFlag() )
-      {
-#endif
-      TComReferencePictureSet* rps;
-      rps = rpcSlice->getLocalRPS();
-      rpcSlice->setRPS(rps);
-      READ_FLAG( uiCode, "short_term_ref_pic_set_sps_flag" );
-      if(uiCode == 0) // use short-term reference picture set explicitly signalled in slice header
-      {
-        parseShortTermRefPicSet(sps,rps, sps->getRPSList()->getNumberOfReferencePictureSets());
-      }
-      else // use reference to short-term reference picture set in PPS
-      {
-        Int numBits = 0;
-        while ((1 << numBits) < rpcSlice->getSPS()->getRPSList()->getNumberOfReferencePictureSets())
-        {
-          numBits++;
-        }
-        if (numBits > 0)
-        {
-          READ_CODE( numBits, uiCode, "short_term_ref_pic_set_idx");
+  else
+  {
+    rpcSlice->setPicOrderCntLsb( 0 );
+  }
+#endif
+  if( !rpcSlice->getIdrPicFlag() )
+  {
+#endif
+    TComReferencePictureSet* rps;
+    rps = rpcSlice->getLocalRPS();
+    rpcSlice->setRPS(rps);
+    READ_FLAG( uiCode, "short_term_ref_pic_set_sps_flag" );
+    if(uiCode == 0) // use short-term reference picture set explicitly signalled in slice header
+    {
+      parseShortTermRefPicSet(sps,rps, sps->getRPSList()->getNumberOfReferencePictureSets());
+    }
+    else // use reference to short-term reference picture set in PPS
+    {
+      Int numBits = 0;
+      while ((1 << numBits) < rpcSlice->getSPS()->getRPSList()->getNumberOfReferencePictureSets())
+      {
+        numBits++;
+      }
+      if (numBits > 0)
+      {
+        READ_CODE( numBits, uiCode, "short_term_ref_pic_set_idx");
+      }
+      else
+      {
+        uiCode = 0;       
+      }
+      *rps = *(sps->getRPSList()->getReferencePictureSet(uiCode));
+    }
+    if(sps->getLongTermRefsPresent())
+    {
+      Int offset = rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures();
+      UInt numOfLtrp = 0;
+      UInt numLtrpInSPS = 0;
+      if (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > 0)
+      {
+        READ_UVLC( uiCode, "num_long_term_sps");
+        numLtrpInSPS = uiCode;
+        numOfLtrp += numLtrpInSPS;
+        rps->setNumberOfLongtermPictures(numOfLtrp);
+      }
+      Int bitsForLtrpInSPS = 0;
+      while (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > (1 << bitsForLtrpInSPS))
+      {
+        bitsForLtrpInSPS++;
+      }
+      READ_UVLC( uiCode, "num_long_term_pics");             rps->setNumberOfLongtermPictures(uiCode);
+      numOfLtrp += uiCode;
+      rps->setNumberOfLongtermPictures(numOfLtrp);
+      Int maxPicOrderCntLSB = 1 << rpcSlice->getSPS()->getBitsForPOC();
+      Int prevDeltaMSB = 0, deltaPocMSBCycleLT = 0;;
+      for(Int j=offset+rps->getNumberOfLongtermPictures()-1, k = 0; k < numOfLtrp; j--, k++)
+      {
+        Int pocLsbLt;
+        if (k < numLtrpInSPS)
+        {
+          uiCode = 0;
+          if (bitsForLtrpInSPS > 0)
+          {
+            READ_CODE(bitsForLtrpInSPS, uiCode, "lt_idx_sps[i]");
+          }
+          Int usedByCurrFromSPS=rpcSlice->getSPS()->getUsedByCurrPicLtSPSFlag(uiCode);
+
+          pocLsbLt = rpcSlice->getSPS()->getLtRefPicPocLsbSps(uiCode);
+          rps->setUsed(j,usedByCurrFromSPS);
         }
         else
         {
-          uiCode = 0;       
-        }
-        *rps = *(sps->getRPSList()->getReferencePictureSet(uiCode));
-      }
-      if(sps->getLongTermRefsPresent())
-      {
-        Int offset = rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures();
-        UInt numOfLtrp = 0;
-        UInt numLtrpInSPS = 0;
-        if (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > 0)
-        {
-          READ_UVLC( uiCode, "num_long_term_sps");
-          numLtrpInSPS = uiCode;
-          numOfLtrp += numLtrpInSPS;
-          rps->setNumberOfLongtermPictures(numOfLtrp);
-        }
-        Int bitsForLtrpInSPS = 0;
-        while (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > (1 << bitsForLtrpInSPS))
-        {
-          bitsForLtrpInSPS++;
-        }
-        READ_UVLC( uiCode, "num_long_term_pics");             rps->setNumberOfLongtermPictures(uiCode);
-        numOfLtrp += uiCode;
-        rps->setNumberOfLongtermPictures(numOfLtrp);
-        Int maxPicOrderCntLSB = 1 << rpcSlice->getSPS()->getBitsForPOC();
-        Int prevDeltaMSB = 0, deltaPocMSBCycleLT = 0;;
-        for(Int j=offset+rps->getNumberOfLongtermPictures()-1, k = 0; k < numOfLtrp; j--, k++)
-        {
-          Int pocLsbLt;
-          if (k < numLtrpInSPS)
+          READ_CODE(rpcSlice->getSPS()->getBitsForPOC(), uiCode, "poc_lsb_lt"); pocLsbLt= uiCode;
+          READ_FLAG( uiCode, "used_by_curr_pic_lt_flag");     rps->setUsed(j,uiCode);
+        }
+        READ_FLAG(uiCode,"delta_poc_msb_present_flag");
+        Bool mSBPresentFlag = uiCode ? true : false;
+        if(mSBPresentFlag)
+        {
+          READ_UVLC( uiCode, "delta_poc_msb_cycle_lt[i]" );
+          Bool deltaFlag = false;
+          //            First LTRP                               || First LTRP from SH
+          if( (j == offset+rps->getNumberOfLongtermPictures()-1) || (j == offset+(numOfLtrp-numLtrpInSPS)-1) )
           {
-            uiCode = 0;
-            if (bitsForLtrpInSPS > 0)
-            {
-              READ_CODE(bitsForLtrpInSPS, uiCode, "lt_idx_sps[i]");
-            }
-            Int usedByCurrFromSPS=rpcSlice->getSPS()->getUsedByCurrPicLtSPSFlag(uiCode);
-
-            pocLsbLt = rpcSlice->getSPS()->getLtRefPicPocLsbSps(uiCode);
-            rps->setUsed(j,usedByCurrFromSPS);
+            deltaFlag = true;
+          }
+          if(deltaFlag)
+          {
+            deltaPocMSBCycleLT = uiCode;
           }
           else
           {
-            READ_CODE(rpcSlice->getSPS()->getBitsForPOC(), uiCode, "poc_lsb_lt"); pocLsbLt= uiCode;
-            READ_FLAG( uiCode, "used_by_curr_pic_lt_flag");     rps->setUsed(j,uiCode);
+            deltaPocMSBCycleLT = uiCode + prevDeltaMSB;
           }
-          READ_FLAG(uiCode,"delta_poc_msb_present_flag");
-          Bool mSBPresentFlag = uiCode ? true : false;
-          if(mSBPresentFlag)
+
+          Int pocLTCurr = rpcSlice->getPOC() - deltaPocMSBCycleLT * maxPicOrderCntLSB
+            - iPOClsb + pocLsbLt;
+          rps->setPOC     (j, pocLTCurr);
+          rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLTCurr);
+          rps->setCheckLTMSBPresent(j,true);
+        }
+        else
+        {
+          rps->setPOC     (j, pocLsbLt);
+          rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLsbLt);
+          rps->setCheckLTMSBPresent(j,false);
+
+          // reset deltaPocMSBCycleLT for first LTRP from slice header if MSB not present
+          if( j == offset+(numOfLtrp-numLtrpInSPS)-1 )
           {
-            READ_UVLC( uiCode, "delta_poc_msb_cycle_lt[i]" );
-            Bool deltaFlag = false;
-            //            First LTRP                               || First LTRP from SH
-            if( (j == offset+rps->getNumberOfLongtermPictures()-1) || (j == offset+(numOfLtrp-numLtrpInSPS)-1) )
-            {
-              deltaFlag = true;
-            }
-            if(deltaFlag)
-            {
-              deltaPocMSBCycleLT = uiCode;
-            }
-            else
-            {
-              deltaPocMSBCycleLT = uiCode + prevDeltaMSB;
-            }
-
-            Int pocLTCurr = rpcSlice->getPOC() - deltaPocMSBCycleLT * maxPicOrderCntLSB
-                                        - iPOClsb + pocLsbLt;
-            rps->setPOC     (j, pocLTCurr);
-            rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLTCurr);
-            rps->setCheckLTMSBPresent(j,true);
+            deltaPocMSBCycleLT = 0;
           }
-          else
+        }
+        prevDeltaMSB = deltaPocMSBCycleLT;
+      }
+      offset += rps->getNumberOfLongtermPictures();
+      rps->setNumberOfPictures(offset);
+    }
+#if DPB_CONSTRAINTS
+    if(rpcSlice->getVPS()->getVpsExtensionFlag()==1)
+    {
+#if Q0078_ADD_LAYER_SETS
+      for (Int ii = 1; ii < (rpcSlice->getVPS()->getVpsNumLayerSetsMinus1() + 1); ii++)  // prevent assert error when num_add_layer_sets > 0
+#else
+      for (Int ii=1; ii< rpcSlice->getVPS()->getNumOutputLayerSets(); ii++ )
+#endif
+      {
+        Int layerSetIdxForOutputLayerSet = rpcSlice->getVPS()->getOutputLayerSetIdx( ii );
+        Int chkAssert=0;
+        for(Int kk = 0; kk < rpcSlice->getVPS()->getNumLayersInIdList(layerSetIdxForOutputLayerSet); kk++)
+        {
+          if(rpcSlice->getLayerId()==rpcSlice->getVPS()->getLayerSetLayerIdList(layerSetIdxForOutputLayerSet, kk))
           {
-            rps->setPOC     (j, pocLsbLt);
-            rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLsbLt);
-            rps->setCheckLTMSBPresent(j,false);
-
-            // reset deltaPocMSBCycleLT for first LTRP from slice header if MSB not present
-            if( j == offset+(numOfLtrp-numLtrpInSPS)-1 )
-            {
-              deltaPocMSBCycleLT = 0;
+            chkAssert=1;
+          }
+        }
+        if(chkAssert)
+        {
+          // There may be something wrong here (layer id assumed to be layer idx?)
+          assert(rps->getNumberOfNegativePictures() <= rpcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii , rpcSlice->getLayerId() , rpcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)));
+          assert(rps->getNumberOfPositivePictures() <= rpcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii , rpcSlice->getLayerId() , rpcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)) - rps->getNumberOfNegativePictures());
+          assert((rps->getNumberOfPositivePictures() + rps->getNumberOfNegativePictures() + rps->getNumberOfLongtermPictures()) <= rpcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii , rpcSlice->getLayerId() , rpcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)));
+        }
+      }
+
+
+    }
+    if(rpcSlice->getLayerId() == 0)
+    {
+      assert(rps->getNumberOfNegativePictures() <= rpcSlice->getSPS()->getMaxDecPicBuffering(rpcSlice->getSPS()->getMaxTLayers()-1) );
+      assert(rps->getNumberOfPositivePictures() <= rpcSlice->getSPS()->getMaxDecPicBuffering(rpcSlice->getSPS()->getMaxTLayers()-1) -rps->getNumberOfNegativePictures());
+      assert((rps->getNumberOfPositivePictures() + rps->getNumberOfNegativePictures() + rps->getNumberOfLongtermPictures()) <= rpcSlice->getSPS()->getMaxDecPicBuffering(rpcSlice->getSPS()->getMaxTLayers()-1));
+    }
+#endif
+    if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
+      || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
+      || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
+    {
+      // In the case of BLA picture types, rps data is read from slice header but ignored
+      rps = rpcSlice->getLocalRPS();
+      rps->setNumberOfNegativePictures(0);
+      rps->setNumberOfPositivePictures(0);
+      rps->setNumberOfLongtermPictures(0);
+      rps->setNumberOfPictures(0);
+      rpcSlice->setRPS(rps);
+    }
+    if (rpcSlice->getSPS()->getTMVPFlagsPresent())
+    {
+#if R0226_SLICE_TMVP
+      READ_FLAG( uiCode, "slice_temporal_mvp_enabled_flag" );
+#else
+      READ_FLAG( uiCode, "slice_temporal_mvp_enable_flag" );
+#endif
+      rpcSlice->setEnableTMVPFlag( uiCode == 1 ? true : false );
+    }
+    else
+    {
+      rpcSlice->setEnableTMVPFlag(false);
+    }
+#if N0065_LAYER_POC_ALIGNMENT && !SHM_FIX7
+  }
+#endif
+  }
+
+#if SVC_EXTENSION
+  rpcSlice->setActiveNumILRRefIdx(0);
+  if((rpcSlice->getLayerId() > 0) && !(rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag()) && (rpcSlice->getNumILRRefIdx() > 0) )
+  {
+    READ_FLAG(uiCode,"inter_layer_pred_enabled_flag");
+    rpcSlice->setInterLayerPredEnabledFlag(uiCode);
+    if( rpcSlice->getInterLayerPredEnabledFlag())
+    {
+      if(rpcSlice->getNumILRRefIdx() > 1)
+      {
+        Int numBits = 1;
+        while ((1 << numBits) < rpcSlice->getNumILRRefIdx())
+        {
+          numBits++;
+        }
+        if( !rpcSlice->getVPS()->getMaxOneActiveRefLayerFlag())
+        {
+          READ_CODE( numBits, uiCode,"num_inter_layer_ref_pics_minus1" );
+          rpcSlice->setActiveNumILRRefIdx(uiCode + 1);
+        }
+        else
+        {
+#if P0079_DERIVE_NUMACTIVE_REF_PICS
+          for( Int i = 0; i < rpcSlice->getNumILRRefIdx(); i++ ) 
+          {
+#if Q0060_MAX_TID_REF_EQUAL_TO_ZERO
+            if((rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(rpcSlice->getVPS()->getLayerIdInVps(i),rpcSlice->getLayerId()) >  rpcSlice->getTLayer() || rpcSlice->getTLayer()==0) &&
+              (rpcSlice->getVPS()->getMaxTSLayersMinus1(rpcSlice->getVPS()->getLayerIdInVps(i)) >=  rpcSlice->getTLayer()) )
+#else 
+            if(rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(rpcSlice->getVPS()->getLayerIdInVps(i),rpcSlice->getLayerId()) >  rpcSlice->getTLayer() &&
+              (rpcSlice->getVPS()->getMaxTSLayersMinus1(rpcSlice->getVPS()->getLayerIdInVps(i)) >=  rpcSlice->getTLayer()) )
+#endif 
+            {          
+              rpcSlice->setActiveNumILRRefIdx(1);
+              break;
             }
           }
-          prevDeltaMSB = deltaPocMSBCycleLT;
-        }
-        offset += rps->getNumberOfLongtermPictures();
-        rps->setNumberOfPictures(offset);
-      }
-#if DPB_CONSTRAINTS
-          if(rpcSlice->getVPS()->getVpsExtensionFlag()==1)
+#else
+          rpcSlice->setActiveNumILRRefIdx(1);
+#endif 
+        }
+
+        if( rpcSlice->getActiveNumILRRefIdx() == rpcSlice->getNumILRRefIdx() )
+        {
+          for( Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
           {
-#if Q0078_ADD_LAYER_SETS
-              for (Int ii = 1; ii < (rpcSlice->getVPS()->getVpsNumLayerSetsMinus1() + 1); ii++)  // prevent assert error when num_add_layer_sets > 0
-#else
-              for (Int ii=1; ii< rpcSlice->getVPS()->getNumOutputLayerSets(); ii++ )
-#endif
-              {
-                  Int layerSetIdxForOutputLayerSet = rpcSlice->getVPS()->getOutputLayerSetIdx( ii );
-                  Int chkAssert=0;
-                  for(Int kk = 0; kk < rpcSlice->getVPS()->getNumLayersInIdList(layerSetIdxForOutputLayerSet); kk++)
-                  {
-                      if(rpcSlice->getLayerId()==rpcSlice->getVPS()->getLayerSetLayerIdList(layerSetIdxForOutputLayerSet, kk))
-                      {
-                          chkAssert=1;
-                      }
-                  }
-                  if(chkAssert)
-                  {
-                      // There may be something wrong here (layer id assumed to be layer idx?)
-                      assert(rps->getNumberOfNegativePictures() <= rpcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii , rpcSlice->getLayerId() , rpcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)));
-                      assert(rps->getNumberOfPositivePictures() <= rpcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii , rpcSlice->getLayerId() , rpcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)) - rps->getNumberOfNegativePictures());
-                      assert((rps->getNumberOfPositivePictures() + rps->getNumberOfNegativePictures() + rps->getNumberOfLongtermPictures()) <= rpcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii , rpcSlice->getLayerId() , rpcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)));
-                  }
-              }
-              
-              
+            rpcSlice->setInterLayerPredLayerIdc(i,i);
           }
-          if(rpcSlice->getLayerId() == 0)
+        }
+        else
+        {
+          for(Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
           {
-              assert(rps->getNumberOfNegativePictures() <= rpcSlice->getSPS()->getMaxDecPicBuffering(rpcSlice->getSPS()->getMaxTLayers()-1) );
-              assert(rps->getNumberOfPositivePictures() <= rpcSlice->getSPS()->getMaxDecPicBuffering(rpcSlice->getSPS()->getMaxTLayers()-1) -rps->getNumberOfNegativePictures());
-              assert((rps->getNumberOfPositivePictures() + rps->getNumberOfNegativePictures() + rps->getNumberOfLongtermPictures()) <= rpcSlice->getSPS()->getMaxDecPicBuffering(rpcSlice->getSPS()->getMaxTLayers()-1));
+            READ_CODE( numBits,uiCode,"inter_layer_pred_layer_idc[i]" );
+            rpcSlice->setInterLayerPredLayerIdc(uiCode,i);
           }
-#endif
-      if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
-        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
-        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
-      {
-        // In the case of BLA picture types, rps data is read from slice header but ignored
-        rps = rpcSlice->getLocalRPS();
-        rps->setNumberOfNegativePictures(0);
-        rps->setNumberOfPositivePictures(0);
-        rps->setNumberOfLongtermPictures(0);
-        rps->setNumberOfPictures(0);
-        rpcSlice->setRPS(rps);
-      }
-      if (rpcSlice->getSPS()->getTMVPFlagsPresent())
-      {
-        READ_FLAG( uiCode, "slice_temporal_mvp_enable_flag" );
-        rpcSlice->setEnableTMVPFlag( uiCode == 1 ? true : false );
+        }
       }
       else
       {
-        rpcSlice->setEnableTMVPFlag(false);
-      }
-#if N0065_LAYER_POC_ALIGNMENT && !SHM_FIX7
-    }
-#endif
-    }
-
-#if SVC_EXTENSION
-    rpcSlice->setActiveNumILRRefIdx(0);
-    if((rpcSlice->getLayerId() > 0) && !(rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag()) && (rpcSlice->getNumILRRefIdx() > 0) )
-    {
-      READ_FLAG(uiCode,"inter_layer_pred_enabled_flag");
-      rpcSlice->setInterLayerPredEnabledFlag(uiCode);
-      if( rpcSlice->getInterLayerPredEnabledFlag())
-      {
-        if(rpcSlice->getNumILRRefIdx() > 1)
-        {
-          Int numBits = 1;
-          while ((1 << numBits) < rpcSlice->getNumILRRefIdx())
-          {
-            numBits++;
-          }
-          if( !rpcSlice->getVPS()->getMaxOneActiveRefLayerFlag())
-          {
-            READ_CODE( numBits, uiCode,"num_inter_layer_ref_pics_minus1" );
-            rpcSlice->setActiveNumILRRefIdx(uiCode + 1);
-          }
-          else
-          {
-#if P0079_DERIVE_NUMACTIVE_REF_PICS
-            for( Int i = 0; i < rpcSlice->getNumILRRefIdx(); i++ ) 
-            {
-#if Q0060_MAX_TID_REF_EQUAL_TO_ZERO
-              if((rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(rpcSlice->getVPS()->getLayerIdInVps(i),rpcSlice->getLayerId()) >  rpcSlice->getTLayer() || rpcSlice->getTLayer()==0) &&
-                (rpcSlice->getVPS()->getMaxTSLayersMinus1(rpcSlice->getVPS()->getLayerIdInVps(i)) >=  rpcSlice->getTLayer()) )
-#else 
-              if(rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(rpcSlice->getVPS()->getLayerIdInVps(i),rpcSlice->getLayerId()) >  rpcSlice->getTLayer() &&
-                (rpcSlice->getVPS()->getMaxTSLayersMinus1(rpcSlice->getVPS()->getLayerIdInVps(i)) >=  rpcSlice->getTLayer()) )
-#endif 
-              {          
-                rpcSlice->setActiveNumILRRefIdx(1);
-                break;
-              }
-            }
-#else
-            rpcSlice->setActiveNumILRRefIdx(1);
-#endif 
-          }
-
-          if( rpcSlice->getActiveNumILRRefIdx() == rpcSlice->getNumILRRefIdx() )
-          {
-            for( Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
-            {
-              rpcSlice->setInterLayerPredLayerIdc(i,i);
-            }
-          }
-          else
-          {
-            for(Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
-            {
-              READ_CODE( numBits,uiCode,"inter_layer_pred_layer_idc[i]" );
-              rpcSlice->setInterLayerPredLayerIdc(uiCode,i);
-            }
-          }
-        }
-        else
-        {
 #if O0225_TID_BASED_IL_RPS_DERIV && TSLAYERS_IL_RPS
 #if Q0060_MAX_TID_REF_EQUAL_TO_ZERO
-          if((rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(0,rpcSlice->getLayerId()) >  rpcSlice->getTLayer() || rpcSlice->getTLayer()==0) &&
-            (rpcSlice->getVPS()->getMaxTSLayersMinus1(0) >=  rpcSlice->getTLayer()) )
-#else
-          if( (rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(0,rpcSlice->getLayerId()) >  rpcSlice->getTLayer()) &&
-             (rpcSlice->getVPS()->getMaxTSLayersMinus1(0) >=  rpcSlice->getTLayer()) )
+        if((rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(0,rpcSlice->getLayerId()) >  rpcSlice->getTLayer() || rpcSlice->getTLayer()==0) &&
+          (rpcSlice->getVPS()->getMaxTSLayersMinus1(0) >=  rpcSlice->getTLayer()) )
+#else
+        if( (rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(0,rpcSlice->getLayerId()) >  rpcSlice->getTLayer()) &&
+          (rpcSlice->getVPS()->getMaxTSLayersMinus1(0) >=  rpcSlice->getTLayer()) )
 #endif 
         {
@@ -2907,568 +3453,611 @@
         }
 #endif
-        }
-      }
-    }
-    else if( rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag() == true &&  (rpcSlice->getLayerId() > 0 ))
-    {
-      rpcSlice->setInterLayerPredEnabledFlag(true);
+      }
+    }
+  }
+  else if( rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag() == true &&  (rpcSlice->getLayerId() > 0 ))
+  {
+    rpcSlice->setInterLayerPredEnabledFlag(true);
 
 #if O0225_TID_BASED_IL_RPS_DERIV && TSLAYERS_IL_RPS
-      Int   numRefLayerPics = 0;
-      Int   i = 0;
-      Int   refLayerPicIdc  [MAX_VPS_LAYER_ID_PLUS1];
-      for(i = 0, numRefLayerPics = 0;  i < rpcSlice->getNumILRRefIdx(); i++ ) 
-      {
+    Int   numRefLayerPics = 0;
+    Int   i = 0;
+    Int   refLayerPicIdc  [MAX_VPS_LAYER_ID_PLUS1];
+    for(i = 0, numRefLayerPics = 0;  i < rpcSlice->getNumILRRefIdx(); i++ ) 
+    {
 #if Q0060_MAX_TID_REF_EQUAL_TO_ZERO
-        if((rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(rpcSlice->getVPS()->getLayerIdInVps(i),rpcSlice->getLayerId()) >  rpcSlice->getTLayer() || rpcSlice->getTLayer()==0) &&
-          (rpcSlice->getVPS()->getMaxTSLayersMinus1(rpcSlice->getVPS()->getLayerIdInVps(i)) >=  rpcSlice->getTLayer()) )
+      if((rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(rpcSlice->getVPS()->getLayerIdInVps(i),rpcSlice->getLayerId()) >  rpcSlice->getTLayer() || rpcSlice->getTLayer()==0) &&
+        (rpcSlice->getVPS()->getMaxTSLayersMinus1(rpcSlice->getVPS()->getLayerIdInVps(i)) >=  rpcSlice->getTLayer()) )
 #else 
-        if(rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(rpcSlice->getVPS()->getLayerIdInVps(i),rpcSlice->getLayerId()) >  rpcSlice->getTLayer() &&
-           (rpcSlice->getVPS()->getMaxTSLayersMinus1(rpcSlice->getVPS()->getLayerIdInVps(i)) >=  rpcSlice->getTLayer()) )
+      if(rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(rpcSlice->getVPS()->getLayerIdInVps(i),rpcSlice->getLayerId()) >  rpcSlice->getTLayer() &&
+        (rpcSlice->getVPS()->getMaxTSLayersMinus1(rpcSlice->getVPS()->getLayerIdInVps(i)) >=  rpcSlice->getTLayer()) )
 #endif 
-        {          
-          refLayerPicIdc[ numRefLayerPics++ ] = i;
-        }
-      }
-      rpcSlice->setActiveNumILRRefIdx(numRefLayerPics);
-      for( i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
-      {
-        rpcSlice->setInterLayerPredLayerIdc(refLayerPicIdc[i],i);
-      }      
-#else
-      rpcSlice->setActiveNumILRRefIdx(rpcSlice->getNumILRRefIdx());
-      for( Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
-      {
-        rpcSlice->setInterLayerPredLayerIdc(i,i);
-      }
+      {          
+        refLayerPicIdc[ numRefLayerPics++ ] = i;
+      }
+    }
+    rpcSlice->setActiveNumILRRefIdx(numRefLayerPics);
+    for( i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
+    {
+      rpcSlice->setInterLayerPredLayerIdc(refLayerPicIdc[i],i);
+    }      
+#else
+    rpcSlice->setActiveNumILRRefIdx(rpcSlice->getNumILRRefIdx());
+    for( Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
+    {
+      rpcSlice->setInterLayerPredLayerIdc(i,i);
+    }
 #endif 
-    }
+  }
 #if P0312_VERT_PHASE_ADJ
     for(Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ ) 
     {
       UInt refLayerIdc = rpcSlice->getInterLayerPredLayerIdc(i);
+#if !MOVE_SCALED_OFFSET_TO_PPS
       if( rpcSlice->getSPS()->getVertPhasePositionEnableFlag(refLayerIdc) )
+#else
+      if( rpcSlice->getPPS()->getVertPhasePositionEnableFlag(refLayerIdc) )
+#endif
       {
         READ_FLAG( uiCode, "vert_phase_position_flag" ); rpcSlice->setVertPhasePositionFlag( uiCode? true : false, refLayerIdc );
       }
-    }
+  }
 #endif
 #endif //SVC_EXTENSION
 
-    if(sps->getUseSAO())
-    {
-      READ_FLAG(uiCode, "slice_sao_luma_flag");  rpcSlice->setSaoEnabledFlag((Bool)uiCode);
+  if(sps->getUseSAO())
+  {
+    READ_FLAG(uiCode, "slice_sao_luma_flag");  rpcSlice->setSaoEnabledFlag((Bool)uiCode);
 #if AUXILIARY_PICTURES
-      ChromaFormat format;
+    ChromaFormat format;
 #if REPN_FORMAT_IN_VPS
 #if O0096_REP_FORMAT_INDEX
-      if( sps->getLayerId() == 0 )
-      {
-        format = sps->getChromaFormatIdc();
-      }
-      else
-      {
-        format = rpcSlice->getVPS()->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : rpcSlice->getVPS()->getVpsRepFormatIdx(sps->getLayerId()) )->getChromaFormatVpsIdc();
+    if( sps->getLayerId() == 0 )
+    {
+      format = sps->getChromaFormatIdc();
+    }
+    else
+    {
+      format = rpcSlice->getVPS()->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : rpcSlice->getVPS()->getVpsRepFormatIdx(sps->getLayerId()) )->getChromaFormatVpsIdc();
 #if Q0195_REP_FORMAT_CLEANUP
-         assert( (sps->getUpdateRepFormatFlag()==false && rpcSlice->getVPS()->getVpsNumRepFormats()==1) || rpcSlice->getVPS()->getVpsNumRepFormats() > 1 ); //conformance check
-#endif
-      }
-#else
-      if( ( sps->getLayerId() == 0 ) || sps->getUpdateRepFormatFlag() )
-      {
-        format = sps->getChromaFormatIdc();
-      }
-      else
-      {
-        format = rpcSlice->getVPS()->getVpsRepFormat( rpcSlice->getVPS()->getVpsRepFormatIdx(sps->getLayerId()) )->getChromaFormatVpsIdc();
-      }
-#endif
-#else
+      assert( (sps->getUpdateRepFormatFlag()==false && rpcSlice->getVPS()->getVpsNumRepFormats()==1) || rpcSlice->getVPS()->getVpsNumRepFormats() > 1 ); //conformance check
+#endif
+    }
+#else
+    if( ( sps->getLayerId() == 0 ) || sps->getUpdateRepFormatFlag() )
+    {
       format = sps->getChromaFormatIdc();
-#endif
-      if (format != CHROMA_400)
-      {
+    }
+    else
+    {
+      format = rpcSlice->getVPS()->getVpsRepFormat( rpcSlice->getVPS()->getVpsRepFormatIdx(sps->getLayerId()) )->getChromaFormatVpsIdc();
+    }
+#endif
+#else
+    format = sps->getChromaFormatIdc();
+#endif
+    if (format != CHROMA_400)
+    {
 #endif
       READ_FLAG(uiCode, "slice_sao_chroma_flag");  rpcSlice->setSaoEnabledFlagChroma((Bool)uiCode);
 #if AUXILIARY_PICTURES
+    }
+    else
+    {
+      rpcSlice->setSaoEnabledFlagChroma(false);
+    }
+#endif
+  }
+
+  if (rpcSlice->getIdrPicFlag())
+  {
+    rpcSlice->setEnableTMVPFlag(false);
+  }
+  if (!rpcSlice->isIntra())
+  {
+
+    READ_FLAG( uiCode, "num_ref_idx_active_override_flag");
+    if (uiCode)
+    {
+      READ_UVLC (uiCode, "num_ref_idx_l0_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_0, uiCode + 1 );
+      if (rpcSlice->isInterB())
+      {
+        READ_UVLC (uiCode, "num_ref_idx_l1_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_1, uiCode + 1 );
       }
       else
       {
-        rpcSlice->setSaoEnabledFlagChroma(false);
-      }
-#endif
-    }
-
-    if (rpcSlice->getIdrPicFlag())
-    {
-      rpcSlice->setEnableTMVPFlag(false);
-    }
-    if (!rpcSlice->isIntra())
-    {
-
-      READ_FLAG( uiCode, "num_ref_idx_active_override_flag");
-      if (uiCode)
-      {
-        READ_UVLC (uiCode, "num_ref_idx_l0_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_0, uiCode + 1 );
-        if (rpcSlice->isInterB())
-        {
-          READ_UVLC (uiCode, "num_ref_idx_l1_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_1, uiCode + 1 );
-        }
-        else
-        {
-          rpcSlice->setNumRefIdx(REF_PIC_LIST_1, 0);
-        }
+        rpcSlice->setNumRefIdx(REF_PIC_LIST_1, 0);
+      }
+    }
+    else
+    {
+      rpcSlice->setNumRefIdx(REF_PIC_LIST_0, rpcSlice->getPPS()->getNumRefIdxL0DefaultActive());
+      if (rpcSlice->isInterB())
+      {
+        rpcSlice->setNumRefIdx(REF_PIC_LIST_1, rpcSlice->getPPS()->getNumRefIdxL1DefaultActive());
       }
       else
       {
-        rpcSlice->setNumRefIdx(REF_PIC_LIST_0, rpcSlice->getPPS()->getNumRefIdxL0DefaultActive());
-        if (rpcSlice->isInterB())
-        {
-          rpcSlice->setNumRefIdx(REF_PIC_LIST_1, rpcSlice->getPPS()->getNumRefIdxL1DefaultActive());
-        }
-        else
-        {
-          rpcSlice->setNumRefIdx(REF_PIC_LIST_1,0);
-        }
-      }
-    }
-    // }
-    TComRefPicListModification* refPicListModification = rpcSlice->getRefPicListModification();
-    if(!rpcSlice->isIntra())
-    {
-      if( !rpcSlice->getPPS()->getListsModificationPresentFlag() || rpcSlice->getNumRpsCurrTempList() <= 1 )
-      {
-        refPicListModification->setRefPicListModificationFlagL0( 0 );
+        rpcSlice->setNumRefIdx(REF_PIC_LIST_1,0);
+      }
+    }
+  }
+  // }
+  TComRefPicListModification* refPicListModification = rpcSlice->getRefPicListModification();
+  if(!rpcSlice->isIntra())
+  {
+    if( !rpcSlice->getPPS()->getListsModificationPresentFlag() || rpcSlice->getNumRpsCurrTempList() <= 1 )
+    {
+      refPicListModification->setRefPicListModificationFlagL0( 0 );
+    }
+    else
+    {
+      READ_FLAG( uiCode, "ref_pic_list_modification_flag_l0" ); refPicListModification->setRefPicListModificationFlagL0( uiCode ? 1 : 0 );
+    }
+
+    if(refPicListModification->getRefPicListModificationFlagL0())
+    {
+      uiCode = 0;
+      Int i = 0;
+      Int numRpsCurrTempList0 = rpcSlice->getNumRpsCurrTempList();
+      if ( numRpsCurrTempList0 > 1 )
+      {
+        Int length = 1;
+        numRpsCurrTempList0 --;
+        while ( numRpsCurrTempList0 >>= 1)
+        {
+          length ++;
+        }
+        for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
+        {
+          READ_CODE( length, uiCode, "list_entry_l0" );
+          refPicListModification->setRefPicSetIdxL0(i, uiCode );
+        }
       }
       else
       {
-        READ_FLAG( uiCode, "ref_pic_list_modification_flag_l0" ); refPicListModification->setRefPicListModificationFlagL0( uiCode ? 1 : 0 );
-      }
-
-      if(refPicListModification->getRefPicListModificationFlagL0())
-      {
-        uiCode = 0;
-        Int i = 0;
-        Int numRpsCurrTempList0 = rpcSlice->getNumRpsCurrTempList();
-        if ( numRpsCurrTempList0 > 1 )
-        {
-          Int length = 1;
-          numRpsCurrTempList0 --;
-          while ( numRpsCurrTempList0 >>= 1)
-          {
-            length ++;
-          }
-          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
-          {
-            READ_CODE( length, uiCode, "list_entry_l0" );
-            refPicListModification->setRefPicSetIdxL0(i, uiCode );
-          }
-        }
-        else
-        {
-          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
-          {
-            refPicListModification->setRefPicSetIdxL0(i, 0 );
-          }
-        }
-      }
+        for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
+        {
+          refPicListModification->setRefPicSetIdxL0(i, 0 );
+        }
+      }
+    }
+  }
+  else
+  {
+    refPicListModification->setRefPicListModificationFlagL0(0);
+  }
+  if(rpcSlice->isInterB())
+  {
+    if( !rpcSlice->getPPS()->getListsModificationPresentFlag() || rpcSlice->getNumRpsCurrTempList() <= 1 )
+    {
+      refPicListModification->setRefPicListModificationFlagL1( 0 );
     }
     else
     {
-      refPicListModification->setRefPicListModificationFlagL0(0);
-    }
-    if(rpcSlice->isInterB())
-    {
-      if( !rpcSlice->getPPS()->getListsModificationPresentFlag() || rpcSlice->getNumRpsCurrTempList() <= 1 )
-      {
-        refPicListModification->setRefPicListModificationFlagL1( 0 );
+      READ_FLAG( uiCode, "ref_pic_list_modification_flag_l1" ); refPicListModification->setRefPicListModificationFlagL1( uiCode ? 1 : 0 );
+    }
+    if(refPicListModification->getRefPicListModificationFlagL1())
+    {
+      uiCode = 0;
+      Int i = 0;
+      Int numRpsCurrTempList1 = rpcSlice->getNumRpsCurrTempList();
+      if ( numRpsCurrTempList1 > 1 )
+      {
+        Int length = 1;
+        numRpsCurrTempList1 --;
+        while ( numRpsCurrTempList1 >>= 1)
+        {
+          length ++;
+        }
+        for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
+        {
+          READ_CODE( length, uiCode, "list_entry_l1" );
+          refPicListModification->setRefPicSetIdxL1(i, uiCode );
+        }
       }
       else
       {
-        READ_FLAG( uiCode, "ref_pic_list_modification_flag_l1" ); refPicListModification->setRefPicListModificationFlagL1( uiCode ? 1 : 0 );
-      }
-      if(refPicListModification->getRefPicListModificationFlagL1())
-      {
-        uiCode = 0;
-        Int i = 0;
-        Int numRpsCurrTempList1 = rpcSlice->getNumRpsCurrTempList();
-        if ( numRpsCurrTempList1 > 1 )
-        {
-          Int length = 1;
-          numRpsCurrTempList1 --;
-          while ( numRpsCurrTempList1 >>= 1)
-          {
-            length ++;
-          }
-          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
-          {
-            READ_CODE( length, uiCode, "list_entry_l1" );
-            refPicListModification->setRefPicSetIdxL1(i, uiCode );
-          }
-        }
-        else
-        {
-          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
-          {
-            refPicListModification->setRefPicSetIdxL1(i, 0 );
-          }
-        }
-      }
+        for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
+        {
+          refPicListModification->setRefPicSetIdxL1(i, 0 );
+        }
+      }
+    }
+  }
+  else
+  {
+    refPicListModification->setRefPicListModificationFlagL1(0);
+  }
+  if (rpcSlice->isInterB())
+  {
+    READ_FLAG( uiCode, "mvd_l1_zero_flag" );       rpcSlice->setMvdL1ZeroFlag( (uiCode ? true : false) );
+  }
+
+  rpcSlice->setCabacInitFlag( false ); // default
+  if(pps->getCabacInitPresentFlag() && !rpcSlice->isIntra())
+  {
+    READ_FLAG(uiCode, "cabac_init_flag");
+    rpcSlice->setCabacInitFlag( uiCode ? true : false );
+  }
+
+  if ( rpcSlice->getEnableTMVPFlag() )
+  {
+#if SVC_EXTENSION && REF_IDX_MFM
+    // set motion mapping flag
+    rpcSlice->setMFMEnabledFlag( ( rpcSlice->getNumMotionPredRefLayers() > 0 && rpcSlice->getActiveNumILRRefIdx() && !rpcSlice->isIntra() ) ? true : false );
+#endif
+    if ( rpcSlice->getSliceType() == B_SLICE )
+    {
+      READ_FLAG( uiCode, "collocated_from_l0_flag" );
+      rpcSlice->setColFromL0Flag(uiCode);
     }
     else
     {
-      refPicListModification->setRefPicListModificationFlagL1(0);
-    }
-    if (rpcSlice->isInterB())
-    {
-      READ_FLAG( uiCode, "mvd_l1_zero_flag" );       rpcSlice->setMvdL1ZeroFlag( (uiCode ? true : false) );
-    }
-
-    rpcSlice->setCabacInitFlag( false ); // default
-    if(pps->getCabacInitPresentFlag() && !rpcSlice->isIntra())
-    {
-      READ_FLAG(uiCode, "cabac_init_flag");
-      rpcSlice->setCabacInitFlag( uiCode ? true : false );
-    }
-
-    if ( rpcSlice->getEnableTMVPFlag() )
-    {
-#if SVC_EXTENSION && REF_IDX_MFM
-      // set motion mapping flag
-      rpcSlice->setMFMEnabledFlag( ( rpcSlice->getNumMotionPredRefLayers() > 0 && rpcSlice->getActiveNumILRRefIdx() && !rpcSlice->isIntra() ) ? true : false );
-#endif
-      if ( rpcSlice->getSliceType() == B_SLICE )
-      {
-        READ_FLAG( uiCode, "collocated_from_l0_flag" );
-        rpcSlice->setColFromL0Flag(uiCode);
-      }
-      else
-      {
-        rpcSlice->setColFromL0Flag( 1 );
-      }
-
-      if ( rpcSlice->getSliceType() != I_SLICE &&
-          ((rpcSlice->getColFromL0Flag() == 1 && rpcSlice->getNumRefIdx(REF_PIC_LIST_0) > 1)||
-           (rpcSlice->getColFromL0Flag() == 0 && rpcSlice->getNumRefIdx(REF_PIC_LIST_1) > 1)))
-      {
-        READ_UVLC( uiCode, "collocated_ref_idx" );
-        rpcSlice->setColRefIdx(uiCode);
-      }
-      else
-      {
-        rpcSlice->setColRefIdx(0);
-      }
-    }
-    if ( (pps->getUseWP() && rpcSlice->getSliceType()==P_SLICE) || (pps->getWPBiPred() && rpcSlice->getSliceType()==B_SLICE) )
-    {
-      xParsePredWeightTable(rpcSlice);
-      rpcSlice->initWpScaling();
-    }
-    if (!rpcSlice->isIntra())
-    {
-      READ_UVLC( uiCode, "five_minus_max_num_merge_cand");
-      rpcSlice->setMaxNumMergeCand(MRG_MAX_NUM_CANDS - uiCode);
-    }
-
-    READ_SVLC( iCode, "slice_qp_delta" );
-    rpcSlice->setSliceQp (26 + pps->getPicInitQPMinus26() + iCode);
+      rpcSlice->setColFromL0Flag( 1 );
+    }
+
+    if ( rpcSlice->getSliceType() != I_SLICE &&
+      ((rpcSlice->getColFromL0Flag() == 1 && rpcSlice->getNumRefIdx(REF_PIC_LIST_0) > 1)||
+      (rpcSlice->getColFromL0Flag() == 0 && rpcSlice->getNumRefIdx(REF_PIC_LIST_1) > 1)))
+    {
+      READ_UVLC( uiCode, "collocated_ref_idx" );
+      rpcSlice->setColRefIdx(uiCode);
+    }
+    else
+    {
+      rpcSlice->setColRefIdx(0);
+    }
+  }
+  if ( (pps->getUseWP() && rpcSlice->getSliceType()==P_SLICE) || (pps->getWPBiPred() && rpcSlice->getSliceType()==B_SLICE) )
+  {
+    xParsePredWeightTable(rpcSlice);
+    rpcSlice->initWpScaling();
+  }
+  if (!rpcSlice->isIntra())
+  {
+    READ_UVLC( uiCode, "five_minus_max_num_merge_cand");
+    rpcSlice->setMaxNumMergeCand(MRG_MAX_NUM_CANDS - uiCode);
+  }
+
+  READ_SVLC( iCode, "slice_qp_delta" );
+  rpcSlice->setSliceQp (26 + pps->getPicInitQPMinus26() + iCode);
 
 #if REPN_FORMAT_IN_VPS
 #if O0194_DIFFERENT_BITDEPTH_EL_BL
-    g_bitDepthYLayer[rpcSlice->getLayerId()] = rpcSlice->getBitDepthY();
-    g_bitDepthCLayer[rpcSlice->getLayerId()] = rpcSlice->getBitDepthC();
-#endif
-    assert( rpcSlice->getSliceQp() >= -rpcSlice->getQpBDOffsetY() );
-#else
-    assert( rpcSlice->getSliceQp() >= -sps->getQpBDOffsetY() );
-#endif
-    assert( rpcSlice->getSliceQp() <=  51 );
-
-    if (rpcSlice->getPPS()->getSliceChromaQpFlag())
-    {
-      READ_SVLC( iCode, "slice_qp_delta_cb" );
-      rpcSlice->setSliceQpDeltaCb( iCode );
-      assert( rpcSlice->getSliceQpDeltaCb() >= -12 );
-      assert( rpcSlice->getSliceQpDeltaCb() <=  12 );
-      assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) >= -12 );
-      assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) <=  12 );
-
-      READ_SVLC( iCode, "slice_qp_delta_cr" );
-      rpcSlice->setSliceQpDeltaCr( iCode );
-      assert( rpcSlice->getSliceQpDeltaCr() >= -12 );
-      assert( rpcSlice->getSliceQpDeltaCr() <=  12 );
-      assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) >= -12 );
-      assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) <=  12 );
-    }
-
-    if (rpcSlice->getPPS()->getDeblockingFilterControlPresentFlag())
-    {
-      if(rpcSlice->getPPS()->getDeblockingFilterOverrideEnabledFlag())
-      {
-        READ_FLAG ( uiCode, "deblocking_filter_override_flag" );        rpcSlice->setDeblockingFilterOverrideFlag(uiCode ? true : false);
+  g_bitDepthYLayer[rpcSlice->getLayerId()] = rpcSlice->getBitDepthY();
+  g_bitDepthCLayer[rpcSlice->getLayerId()] = rpcSlice->getBitDepthC();
+#endif
+  assert( rpcSlice->getSliceQp() >= -rpcSlice->getQpBDOffsetY() );
+#else
+  assert( rpcSlice->getSliceQp() >= -sps->getQpBDOffsetY() );
+#endif
+  assert( rpcSlice->getSliceQp() <=  51 );
+
+  if (rpcSlice->getPPS()->getSliceChromaQpFlag())
+  {
+    READ_SVLC( iCode, "slice_qp_delta_cb" );
+    rpcSlice->setSliceQpDeltaCb( iCode );
+    assert( rpcSlice->getSliceQpDeltaCb() >= -12 );
+    assert( rpcSlice->getSliceQpDeltaCb() <=  12 );
+    assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) >= -12 );
+    assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) <=  12 );
+
+    READ_SVLC( iCode, "slice_qp_delta_cr" );
+    rpcSlice->setSliceQpDeltaCr( iCode );
+    assert( rpcSlice->getSliceQpDeltaCr() >= -12 );
+    assert( rpcSlice->getSliceQpDeltaCr() <=  12 );
+    assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) >= -12 );
+    assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) <=  12 );
+  }
+
+  if (rpcSlice->getPPS()->getDeblockingFilterControlPresentFlag())
+  {
+    if(rpcSlice->getPPS()->getDeblockingFilterOverrideEnabledFlag())
+    {
+      READ_FLAG ( uiCode, "deblocking_filter_override_flag" );        rpcSlice->setDeblockingFilterOverrideFlag(uiCode ? true : false);
+    }
+    else
+    {
+      rpcSlice->setDeblockingFilterOverrideFlag(0);
+    }
+    if(rpcSlice->getDeblockingFilterOverrideFlag())
+    {
+      READ_FLAG ( uiCode, "slice_disable_deblocking_filter_flag" );   rpcSlice->setDeblockingFilterDisable(uiCode ? 1 : 0);
+      if(!rpcSlice->getDeblockingFilterDisable())
+      {
+        READ_SVLC( iCode, "slice_beta_offset_div2" );                       rpcSlice->setDeblockingFilterBetaOffsetDiv2(iCode);
+        assert(rpcSlice->getDeblockingFilterBetaOffsetDiv2() >= -6 &&
+          rpcSlice->getDeblockingFilterBetaOffsetDiv2() <=  6);
+        READ_SVLC( iCode, "slice_tc_offset_div2" );                         rpcSlice->setDeblockingFilterTcOffsetDiv2(iCode);
+        assert(rpcSlice->getDeblockingFilterTcOffsetDiv2() >= -6 &&
+          rpcSlice->getDeblockingFilterTcOffsetDiv2() <=  6);
+      }
+    }
+    else
+    {
+      rpcSlice->setDeblockingFilterDisable   ( rpcSlice->getPPS()->getPicDisableDeblockingFilterFlag() );
+      rpcSlice->setDeblockingFilterBetaOffsetDiv2( rpcSlice->getPPS()->getDeblockingFilterBetaOffsetDiv2() );
+      rpcSlice->setDeblockingFilterTcOffsetDiv2  ( rpcSlice->getPPS()->getDeblockingFilterTcOffsetDiv2() );
+    }
+  }
+  else
+  {
+    rpcSlice->setDeblockingFilterDisable       ( false );
+    rpcSlice->setDeblockingFilterBetaOffsetDiv2( 0 );
+    rpcSlice->setDeblockingFilterTcOffsetDiv2  ( 0 );
+  }
+
+  Bool isSAOEnabled = (!rpcSlice->getSPS()->getUseSAO())?(false):(rpcSlice->getSaoEnabledFlag()||rpcSlice->getSaoEnabledFlagChroma());
+  Bool isDBFEnabled = (!rpcSlice->getDeblockingFilterDisable());
+
+  if(rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag() && ( isSAOEnabled || isDBFEnabled ))
+  {
+    READ_FLAG( uiCode, "slice_loop_filter_across_slices_enabled_flag");
+  }
+  else
+  {
+    uiCode = rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag()?1:0;
+  }
+  rpcSlice->setLFCrossSliceBoundaryFlag( (uiCode==1)?true:false);
+
+}
+
+UInt *entryPointOffset          = NULL;
+UInt numEntryPointOffsets, offsetLenMinus1;
+if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
+{
+  READ_UVLC(numEntryPointOffsets, "num_entry_point_offsets"); rpcSlice->setNumEntryPointOffsets ( numEntryPointOffsets );
+  if (numEntryPointOffsets>0)
+  {
+    READ_UVLC(offsetLenMinus1, "offset_len_minus1");
+  }
+  entryPointOffset = new UInt[numEntryPointOffsets];
+  for (UInt idx=0; idx<numEntryPointOffsets; idx++)
+  {
+    READ_CODE(offsetLenMinus1+1, uiCode, "entry_point_offset_minus1");
+    entryPointOffset[ idx ] = uiCode + 1;
+  }
+}
+else
+{
+  rpcSlice->setNumEntryPointOffsets ( 0 );
+}
+
+#if POC_RESET_IDC_SIGNALLING
+Int sliceHeaderExtensionLength = 0;
+if(pps->getSliceHeaderExtensionPresentFlag())
+{
+  READ_UVLC( uiCode, "slice_header_extension_length"); sliceHeaderExtensionLength = uiCode;
+}
+else
+{
+  sliceHeaderExtensionLength = 0;
+#if INFERENCE_POC_MSB_VAL_PRESENT
+  rpcSlice->setPocMsbValPresentFlag( false );
+#endif
+}
+UInt startBits = m_pcBitstream->getNumBitsRead();     // Start counter of # SH Extn bits
+if( sliceHeaderExtensionLength > 0 )
+{
+  if( rpcSlice->getPPS()->getPocResetInfoPresentFlag() )
+  {
+    READ_CODE( 2, uiCode,       "poc_reset_idc"); rpcSlice->setPocResetIdc(uiCode);
+#if POC_RESET_RESTRICTIONS
+    /* The value of poc_reset_idc shall not be equal to 1 or 2 for a RASL picture, a RADL picture, 
+       a sub-layer non-reference picture, or a picture that has TemporalId greater than 0, 
+       or a picture that has discardable_flag equal to 1. */
+    if( rpcSlice->getPocResetIdc() == 1 || rpcSlice->getPocResetIdc() == 2 )
+    {
+      assert( !rpcSlice->isRASL() );
+      assert( !rpcSlice->isRADL() );
+      assert( !rpcSlice->isSLNR() );
+      assert( rpcSlice->getTLayer() == 0 );
+      assert( rpcSlice->getDiscardableFlag() == 0 );
+    }
+
+    // The value of poc_reset_idc of a CRA or BLA picture shall be less than 3.
+    if( rpcSlice->getPocResetIdc() == 3)
+    {
+      assert( ! ( rpcSlice->isCRA() || rpcSlice->isBLA() ) );
+    }
+#endif
+  }
+  else
+  {
+    rpcSlice->setPocResetIdc( 0 );
+  }
+#if Q0142_POC_LSB_NOT_PRESENT
+  if ( rpcSlice->getVPS()->getPocLsbNotPresentFlag(rpcSlice->getLayerId()) && iPOClsb > 0 )
+  {
+    assert( rpcSlice->getPocResetIdc() != 2 );
+  }
+#endif
+  if( rpcSlice->getPocResetIdc() > 0 )
+  {
+    READ_CODE(6, uiCode,      "poc_reset_period_id"); rpcSlice->setPocResetPeriodId(uiCode);
+  }
+  else
+  {
+
+    rpcSlice->setPocResetPeriodId( 0 );
+  }
+
+  if (rpcSlice->getPocResetIdc() == 3)
+  {
+    READ_FLAG( uiCode,        "full_poc_reset_flag"); rpcSlice->setFullPocResetFlag((uiCode == 1) ? true : false);
+    READ_CODE(rpcSlice->getSPS()->getBitsForPOC(), uiCode,"poc_lsb_val"); rpcSlice->setPocLsbVal(uiCode);
+#if Q0142_POC_LSB_NOT_PRESENT
+    if ( rpcSlice->getVPS()->getPocLsbNotPresentFlag(rpcSlice->getLayerId()) && rpcSlice->getFullPocResetFlag() )
+    {
+      assert( rpcSlice->getPocLsbVal() == 0 );
+    }
+#endif
+  }
+
+  // Derive the value of PocMsbValRequiredFlag
+#if P0297_VPS_POC_LSB_ALIGNED_FLAG
+  rpcSlice->setPocMsbValRequiredFlag( (rpcSlice->getCraPicFlag() || rpcSlice->getBlaPicFlag())
+                                      && (!rpcSlice->getVPS()->getVpsPocLsbAlignedFlag() ||
+                                         (rpcSlice->getVPS()->getVpsPocLsbAlignedFlag() && rpcSlice->getVPS()->getNumDirectRefLayers(rpcSlice->getLayerId()) == 0))
+                                    );
+#else
+  rpcSlice->setPocMsbValRequiredFlag( rpcSlice->getCraPicFlag() || rpcSlice->getBlaPicFlag() );
+#endif
+
+#if P0297_VPS_POC_LSB_ALIGNED_FLAG
+  if (!rpcSlice->getPocMsbValRequiredFlag() && rpcSlice->getVPS()->getVpsPocLsbAlignedFlag())
+#else
+  if (!rpcSlice->getPocMsbValRequiredFlag() /* vps_poc_lsb_aligned_flag */)
+#endif
+  {
+#if P0297_VPS_POC_LSB_ALIGNED_FLAG
+    READ_FLAG(uiCode, "poc_msb_cycle_val_present_flag"); rpcSlice->setPocMsbValPresentFlag(uiCode ? true : false);
+#else
+    READ_FLAG(uiCode, "poc_msb_val_present_flag"); rpcSlice->setPocMsbValPresentFlag(uiCode ? true : false);
+#endif
+  }
+  else
+  {
+#if POC_MSB_VAL_PRESENT_FLAG_SEM
+    if( sliceHeaderExtensionLength == 0 )
+    {
+      rpcSlice->setPocMsbValPresentFlag( false );
+    }
+    else if( rpcSlice->getPocMsbValRequiredFlag() )
+#else
+    if( rpcSlice->getPocMsbValRequiredFlag() )
+#endif
+    {
+      rpcSlice->setPocMsbValPresentFlag( true );
+    }
+    else
+    {
+      rpcSlice->setPocMsbValPresentFlag( false );
+    }
+  }
+
+#if !POC_RESET_IDC_DECODER
+  Int maxPocLsb  = 1 << rpcSlice->getSPS()->getBitsForPOC();
+#endif
+  if( rpcSlice->getPocMsbValPresentFlag() )
+  {
+#if P0297_VPS_POC_LSB_ALIGNED_FLAG
+    READ_UVLC( uiCode,    "poc_msb_cycle_val");             rpcSlice->setPocMsbVal( uiCode );
+#else
+    READ_UVLC( uiCode,    "poc_msb_val");             rpcSlice->setPocMsbVal( uiCode );
+#endif
+
+#if !POC_RESET_IDC_DECODER
+    // Update POC of the slice based on this MSB val
+    Int pocLsb     = rpcSlice->getPOC() % maxPocLsb;
+    rpcSlice->setPOC((rpcSlice->getPocMsbVal() * maxPocLsb) + pocLsb);
+  }
+  else
+  {
+    rpcSlice->setPocMsbVal( rpcSlice->getPOC() / maxPocLsb );
+#endif
+  }
+
+  // Read remaining bits in the slice header extension.
+  UInt endBits = m_pcBitstream->getNumBitsRead();
+  Int counter = (endBits - startBits) % 8;
+  if( counter )
+  {
+    counter = 8 - counter;
+  }
+
+  while( counter )
+  {
+#if Q0146_SSH_EXT_DATA_BIT 
+    READ_FLAG( uiCode, "slice_segment_header_extension_data_bit" );
+#else
+    READ_FLAG( uiCode, "slice_segment_header_extension_reserved_bit" ); assert( uiCode == 1 );
+#endif
+    counter--;
+  }
+}
+#else
+if(pps->getSliceHeaderExtensionPresentFlag())
+{
+  READ_UVLC(uiCode,"slice_header_extension_length");
+  for(Int i=0; i<uiCode; i++)
+  {
+    UInt ignore;
+    READ_CODE(8,ignore,"slice_header_extension_data_byte");
+  }
+}
+#endif
+m_pcBitstream->readByteAlignment();
+
+if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
+{
+  Int endOfSliceHeaderLocation = m_pcBitstream->getByteLocation();
+
+  // Adjust endOfSliceHeaderLocation to account for emulation prevention bytes in the slice segment header
+  for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
+  {
+    if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) < endOfSliceHeaderLocation )
+    {
+      endOfSliceHeaderLocation++;
+    }
+  }
+
+  Int  curEntryPointOffset     = 0;
+  Int  prevEntryPointOffset    = 0;
+  for (UInt idx=0; idx<numEntryPointOffsets; idx++)
+  {
+    curEntryPointOffset += entryPointOffset[ idx ];
+
+    Int emulationPreventionByteCount = 0;
+    for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
+    {
+      if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) >= ( prevEntryPointOffset + endOfSliceHeaderLocation ) &&
+        m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) <  ( curEntryPointOffset  + endOfSliceHeaderLocation ) )
+      {
+        emulationPreventionByteCount++;
+      }
+    }
+
+    entryPointOffset[ idx ] -= emulationPreventionByteCount;
+    prevEntryPointOffset = curEntryPointOffset;
+  }
+
+  if ( pps->getTilesEnabledFlag() )
+  {
+    rpcSlice->setTileLocationCount( numEntryPointOffsets );
+
+    UInt prevPos = 0;
+    for (Int idx=0; idx<rpcSlice->getTileLocationCount(); idx++)
+    {
+      rpcSlice->setTileLocation( idx, prevPos + entryPointOffset [ idx ] );
+      prevPos += entryPointOffset[ idx ];
+    }
+  }
+  else if ( pps->getEntropyCodingSyncEnabledFlag() )
+  {
+    Int numSubstreams = rpcSlice->getNumEntryPointOffsets()+1;
+    rpcSlice->allocSubstreamSizes(numSubstreams);
+    UInt *pSubstreamSizes       = rpcSlice->getSubstreamSizes();
+    for (Int idx=0; idx<numSubstreams-1; idx++)
+    {
+      if ( idx < numEntryPointOffsets )
+      {
+        pSubstreamSizes[ idx ] = ( entryPointOffset[ idx ] << 3 ) ;
       }
       else
       {
-        rpcSlice->setDeblockingFilterOverrideFlag(0);
-      }
-      if(rpcSlice->getDeblockingFilterOverrideFlag())
-      {
-        READ_FLAG ( uiCode, "slice_disable_deblocking_filter_flag" );   rpcSlice->setDeblockingFilterDisable(uiCode ? 1 : 0);
-        if(!rpcSlice->getDeblockingFilterDisable())
-        {
-          READ_SVLC( iCode, "slice_beta_offset_div2" );                       rpcSlice->setDeblockingFilterBetaOffsetDiv2(iCode);
-          assert(rpcSlice->getDeblockingFilterBetaOffsetDiv2() >= -6 &&
-                 rpcSlice->getDeblockingFilterBetaOffsetDiv2() <=  6);
-          READ_SVLC( iCode, "slice_tc_offset_div2" );                         rpcSlice->setDeblockingFilterTcOffsetDiv2(iCode);
-          assert(rpcSlice->getDeblockingFilterTcOffsetDiv2() >= -6 &&
-                 rpcSlice->getDeblockingFilterTcOffsetDiv2() <=  6);
-        }
-      }
-      else
-      {
-        rpcSlice->setDeblockingFilterDisable   ( rpcSlice->getPPS()->getPicDisableDeblockingFilterFlag() );
-        rpcSlice->setDeblockingFilterBetaOffsetDiv2( rpcSlice->getPPS()->getDeblockingFilterBetaOffsetDiv2() );
-        rpcSlice->setDeblockingFilterTcOffsetDiv2  ( rpcSlice->getPPS()->getDeblockingFilterTcOffsetDiv2() );
-      }
-    }
-    else
-    {
-      rpcSlice->setDeblockingFilterDisable       ( false );
-      rpcSlice->setDeblockingFilterBetaOffsetDiv2( 0 );
-      rpcSlice->setDeblockingFilterTcOffsetDiv2  ( 0 );
-    }
-
-    Bool isSAOEnabled = (!rpcSlice->getSPS()->getUseSAO())?(false):(rpcSlice->getSaoEnabledFlag()||rpcSlice->getSaoEnabledFlagChroma());
-    Bool isDBFEnabled = (!rpcSlice->getDeblockingFilterDisable());
-
-    if(rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag() && ( isSAOEnabled || isDBFEnabled ))
-    {
-      READ_FLAG( uiCode, "slice_loop_filter_across_slices_enabled_flag");
-    }
-    else
-    {
-      uiCode = rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag()?1:0;
-    }
-    rpcSlice->setLFCrossSliceBoundaryFlag( (uiCode==1)?true:false);
-
-  }
-
-    UInt *entryPointOffset          = NULL;
-    UInt numEntryPointOffsets, offsetLenMinus1;
-  if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
-  {
-    READ_UVLC(numEntryPointOffsets, "num_entry_point_offsets"); rpcSlice->setNumEntryPointOffsets ( numEntryPointOffsets );
-    if (numEntryPointOffsets>0)
-    {
-      READ_UVLC(offsetLenMinus1, "offset_len_minus1");
-    }
-    entryPointOffset = new UInt[numEntryPointOffsets];
-    for (UInt idx=0; idx<numEntryPointOffsets; idx++)
-    {
-      READ_CODE(offsetLenMinus1+1, uiCode, "entry_point_offset_minus1");
-      entryPointOffset[ idx ] = uiCode + 1;
-    }
-  }
-  else
-  {
-    rpcSlice->setNumEntryPointOffsets ( 0 );
-  }
-
-#if POC_RESET_IDC_SIGNALLING
-  Int sliceHeaderExtensionLength = 0;
-  if(pps->getSliceHeaderExtensionPresentFlag())
-  {
-    READ_UVLC( uiCode, "slice_header_extension_length"); sliceHeaderExtensionLength = uiCode;
-  }
-  else
-  {
-    sliceHeaderExtensionLength = 0;
-  }
-  UInt startBits = m_pcBitstream->getNumBitsRead();     // Start counter of # SH Extn bits
-  if( sliceHeaderExtensionLength > 0 )
-  {
-    if( rpcSlice->getPPS()->getPocResetInfoPresentFlag() )
-    {
-      READ_CODE( 2, uiCode,       "poc_reset_idc"); rpcSlice->setPocResetIdc(uiCode);
-    }
-    else
-    {
-      rpcSlice->setPocResetIdc( 0 );
-    }
-#if Q0142_POC_LSB_NOT_PRESENT
-    if ( rpcSlice->getVPS()->getPocLsbNotPresentFlag(rpcSlice->getLayerId()) && iPOClsb > 0 )
-    {
-      assert( rpcSlice->getPocResetIdc() != 2 );
-    }
-#endif
-    if( rpcSlice->getPocResetIdc() > 0 )
-    {
-      READ_CODE(6, uiCode,      "poc_reset_period_id"); rpcSlice->setPocResetPeriodId(uiCode);
-    }
-    else
-    {
-     
-      rpcSlice->setPocResetPeriodId( 0 );
-    }
-
-    if (rpcSlice->getPocResetIdc() == 3)
-    {
-      READ_FLAG( uiCode,        "full_poc_reset_flag"); rpcSlice->setFullPocResetFlag((uiCode == 1) ? true : false);
-      READ_CODE(rpcSlice->getSPS()->getBitsForPOC(), uiCode,"poc_lsb_val"); rpcSlice->setPocLsbVal(uiCode);
-#if Q0142_POC_LSB_NOT_PRESENT
-      if ( rpcSlice->getVPS()->getPocLsbNotPresentFlag(rpcSlice->getLayerId()) && rpcSlice->getFullPocResetFlag() )
-      {
-        assert( rpcSlice->getPocLsbVal() == 0 );
-      }
-#endif
-    }
-
-    // Derive the value of PocMsbValRequiredFlag
-    rpcSlice->setPocMsbValRequiredFlag( rpcSlice->getCraPicFlag() || rpcSlice->getBlaPicFlag()
-                                          /* || related to vps_poc_lsb_aligned_flag */
-                                          );
-
-    if( !rpcSlice->getPocMsbValRequiredFlag() /* vps_poc_lsb_aligned_flag */ )
-    {
-      READ_FLAG( uiCode,    "poc_msb_val_present_flag"); rpcSlice->setPocMsbValPresentFlag( uiCode ? true : false );
-    }
-    else
-    {
-#if POC_MSB_VAL_PRESENT_FLAG_SEM
-      if( sliceHeaderExtensionLength == 0 )
-      {
-        rpcSlice->setPocMsbValPresentFlag( false );
-      }
-      else if( rpcSlice->getPocMsbValRequiredFlag() )
-#else
-      if( rpcSlice->getPocMsbValRequiredFlag() )
-#endif
-      {
-        rpcSlice->setPocMsbValPresentFlag( true );
-      }
-      else
-      {
-        rpcSlice->setPocMsbValPresentFlag( false );
-      }
-    }
-
-#if !POC_RESET_IDC_DECODER
-    Int maxPocLsb  = 1 << rpcSlice->getSPS()->getBitsForPOC();
-#endif
-    if( rpcSlice->getPocMsbValPresentFlag() )
-    {
-      READ_UVLC( uiCode,    "poc_msb_val");             rpcSlice->setPocMsbVal( uiCode );
-
-#if !POC_RESET_IDC_DECODER
-      // Update POC of the slice based on this MSB val
-      Int pocLsb     = rpcSlice->getPOC() % maxPocLsb;
-      rpcSlice->setPOC((rpcSlice->getPocMsbVal() * maxPocLsb) + pocLsb);
-    }
-    else
-    {
-      rpcSlice->setPocMsbVal( rpcSlice->getPOC() / maxPocLsb );
-#endif
-    }
-
-    // Read remaining bits in the slice header extension.
-    UInt endBits = m_pcBitstream->getNumBitsRead();
-    Int counter = (endBits - startBits) % 8;
-    if( counter )
-    {
-      counter = 8 - counter;
-    }
-
-    while( counter )
-    {
-#if Q0146_SSH_EXT_DATA_BIT 
-      READ_FLAG( uiCode, "slice_segment_header_extension_data_bit" );
-#else
-      READ_FLAG( uiCode, "slice_segment_header_extension_reserved_bit" ); assert( uiCode == 1 );
-#endif
-      counter--;
-    }
-  }
-#else
-  if(pps->getSliceHeaderExtensionPresentFlag())
-  {
-    READ_UVLC(uiCode,"slice_header_extension_length");
-    for(Int i=0; i<uiCode; i++)
-    {
-      UInt ignore;
-      READ_CODE(8,ignore,"slice_header_extension_data_byte");
-    }
-  }
-#endif
-  m_pcBitstream->readByteAlignment();
-
-  if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
-  {
-    Int endOfSliceHeaderLocation = m_pcBitstream->getByteLocation();
-
-    // Adjust endOfSliceHeaderLocation to account for emulation prevention bytes in the slice segment header
-    for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
-    {
-      if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) < endOfSliceHeaderLocation )
-      {
-        endOfSliceHeaderLocation++;
-      }
-    }
-
-    Int  curEntryPointOffset     = 0;
-    Int  prevEntryPointOffset    = 0;
-    for (UInt idx=0; idx<numEntryPointOffsets; idx++)
-    {
-      curEntryPointOffset += entryPointOffset[ idx ];
-
-      Int emulationPreventionByteCount = 0;
-      for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
-      {
-        if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) >= ( prevEntryPointOffset + endOfSliceHeaderLocation ) &&
-             m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) <  ( curEntryPointOffset  + endOfSliceHeaderLocation ) )
-        {
-          emulationPreventionByteCount++;
-        }
-      }
-
-      entryPointOffset[ idx ] -= emulationPreventionByteCount;
-      prevEntryPointOffset = curEntryPointOffset;
-    }
-
-    if ( pps->getTilesEnabledFlag() )
-    {
-      rpcSlice->setTileLocationCount( numEntryPointOffsets );
-
-      UInt prevPos = 0;
-      for (Int idx=0; idx<rpcSlice->getTileLocationCount(); idx++)
-      {
-        rpcSlice->setTileLocation( idx, prevPos + entryPointOffset [ idx ] );
-        prevPos += entryPointOffset[ idx ];
-      }
-    }
-    else if ( pps->getEntropyCodingSyncEnabledFlag() )
-    {
-    Int numSubstreams = rpcSlice->getNumEntryPointOffsets()+1;
-      rpcSlice->allocSubstreamSizes(numSubstreams);
-      UInt *pSubstreamSizes       = rpcSlice->getSubstreamSizes();
-      for (Int idx=0; idx<numSubstreams-1; idx++)
-      {
-        if ( idx < numEntryPointOffsets )
-        {
-          pSubstreamSizes[ idx ] = ( entryPointOffset[ idx ] << 3 ) ;
-        }
-        else
-        {
-          pSubstreamSizes[ idx ] = 0;
-        }
-      }
-    }
-
-    if (entryPointOffset)
-    {
-      delete [] entryPointOffset;
-    }
-  }
-
-  return;
+        pSubstreamSizes[ idx ] = 0;
+      }
+    }
+  }
+
+  if (entryPointOffset)
+  {
+    delete [] entryPointOffset;
+  }
+}
+
+return;
 }
 
@@ -3733,6 +4322,6 @@
       {
 #endif
-      wp[1].uiLog2WeightDenom = uiLog2WeightDenomChroma;
-      wp[2].uiLog2WeightDenom = uiLog2WeightDenomChroma;
+        wp[1].uiLog2WeightDenom = uiLog2WeightDenomChroma;
+        wp[2].uiLog2WeightDenom = uiLog2WeightDenomChroma;
 #if AUXILIARY_PICTURES
       }
@@ -3913,7 +4502,28 @@
 Void TDecCavlc::xParse3DAsymLUT( TCom3DAsymLUT * pc3DAsymLUT )
 {
+#if R0150_CGS_SIGNAL_CONSTRAINTS
+  UInt uiNumRefLayersM1;
+  READ_UVLC( uiNumRefLayersM1 , "num_cm_ref_layers_minus1" );
+  assert( uiNumRefLayersM1 <= 61 );
+  for( UInt i = 0 ; i <= uiNumRefLayersM1 ; i++ )
+  {
+    UInt uiRefLayerId;
+    READ_CODE( 6 , uiRefLayerId , "cm_ref_layer_id" );
+    pc3DAsymLUT->addRefLayerId( uiRefLayerId );
+  }
+#endif
   UInt uiCurOctantDepth , uiCurPartNumLog2 , uiInputBitDepthM8 , uiOutputBitDepthM8 , uiResQaunBit;
+#if R0300_CGS_RES_COEFF_CODING
+  UInt uiDeltaBits; 
+#endif 
   READ_CODE( 2 , uiCurOctantDepth , "cm_octant_depth" ); 
   READ_CODE( 2 , uiCurPartNumLog2 , "cm_y_part_num_log2" );     
+#if R0150_CGS_SIGNAL_CONSTRAINTS
+  UInt uiChromaInputBitDepthM8 , uiChromaOutputBitDepthM8;
+  READ_UVLC( uiInputBitDepthM8 , "cm_input_luma_bit_depth_minus8" );
+  READ_UVLC( uiChromaInputBitDepthM8 , "cm_input_chroma_bit_depth_minus8" );
+  READ_UVLC( uiOutputBitDepthM8 , "cm_output_luma_bit_depth_minus8" );
+  READ_UVLC( uiChromaOutputBitDepthM8 , "cm_output_chroma_bit_depth_minus8" );
+#else
   READ_CODE( 3 , uiInputBitDepthM8 , "cm_input_bit_depth_minus8" );
   Int iInputBitDepthCDelta;
@@ -3922,10 +4532,61 @@
   Int iOutputBitDepthCDelta;
   READ_SVLC(iOutputBitDepthCDelta, "cm_output_bit_depth_chroma_delta");
+#endif
   READ_CODE( 2 , uiResQaunBit , "cm_res_quant_bit" );
+#if R0300_CGS_RES_COEFF_CODING
+  READ_CODE( 2 , uiDeltaBits , "cm_flc_bits" );
+  pc3DAsymLUT->setDeltaBits(uiDeltaBits + 1);
+#endif
+
+#if R0151_CGS_3D_ASYMLUT_IMPROVE
+#if R0150_CGS_SIGNAL_CONSTRAINTS
+  Int nAdaptCThresholdU = 1 << ( uiChromaInputBitDepthM8 + 8 - 1 );
+  Int nAdaptCThresholdV = 1 << ( uiChromaInputBitDepthM8 + 8 - 1 );
+#else
+  Int nAdaptCThresholdU = 1 << ( uiInputBitDepthM8 + 8 + iInputBitDepthCDelta - 1 );
+  Int nAdaptCThresholdV = 1 << ( uiInputBitDepthM8 + 8 + iInputBitDepthCDelta - 1 );
+#endif
+  if( uiCurOctantDepth == 1 )
+  {
+    Int delta = 0;
+    READ_SVLC( delta , "cm_adapt_threshold_u_delta" );
+    nAdaptCThresholdU += delta;
+    READ_SVLC( delta , "cm_adapt_threshold_v_delta" );
+    nAdaptCThresholdV += delta;
+  }
+#endif
   pc3DAsymLUT->destroy();
-  pc3DAsymLUT->create( uiCurOctantDepth , uiInputBitDepthM8 + 8 ,  uiInputBitDepthM8 + 8 + iInputBitDepthCDelta, uiOutputBitDepthM8 + 8 , uiOutputBitDepthM8 + 8 + iOutputBitDepthCDelta ,uiCurPartNumLog2 );
+  pc3DAsymLUT->create( uiCurOctantDepth , uiInputBitDepthM8 + 8 ,  
+#if R0150_CGS_SIGNAL_CONSTRAINTS
+    uiChromaInputBitDepthM8 + 8 ,
+#else
+    uiInputBitDepthM8 + 8 + iInputBitDepthCDelta, 
+#endif
+    uiOutputBitDepthM8 + 8 , 
+#if R0150_CGS_SIGNAL_CONSTRAINTS
+    uiChromaOutputBitDepthM8 + 8 ,
+#else
+    uiOutputBitDepthM8 + 8 + iOutputBitDepthCDelta ,
+#endif
+    uiCurPartNumLog2 
+#if R0151_CGS_3D_ASYMLUT_IMPROVE
+    , nAdaptCThresholdU , nAdaptCThresholdV 
+#endif    
+    );
   pc3DAsymLUT->setResQuantBit( uiResQaunBit );
 
+#if R0164_CGS_LUT_BUGFIX_CHECK
+  pc3DAsymLUT->xInitCuboids();
+#endif
   xParse3DAsymLUTOctant( pc3DAsymLUT , 0 , 0 , 0 , 0 , 1 << pc3DAsymLUT->getCurOctantDepth() );
+#if R0164_CGS_LUT_BUGFIX
+#if R0164_CGS_LUT_BUGFIX_CHECK
+  printf("============= Before 'xCuboidsFilledCheck()': ================\n");
+  pc3DAsymLUT->display();
+  pc3DAsymLUT->xCuboidsFilledCheck( false );
+  printf("============= After 'xCuboidsFilledCheck()': =================\n");
+  pc3DAsymLUT->display();
+#endif
+#endif
 }
 
@@ -3952,6 +4613,13 @@
   else
   {
+#if R0300_CGS_RES_COEFF_CODING
+    Int nFLCbits = pc3DAsymLUT->getMappingShift()-pc3DAsymLUT->getResQuantBit()-pc3DAsymLUT->getDeltaBits() ; 
+    nFLCbits = nFLCbits >= 0 ? nFLCbits:0;
+#endif
     for( Int l = 0 ; l < nYPartNum ; l++ )
     {
+#if R0164_CGS_LUT_BUGFIX
+      Int shift = pc3DAsymLUT->getCurOctantDepth() - nDepth ;
+#endif
       for( Int nVertexIdx = 0 ; nVertexIdx < 4 ; nVertexIdx++ )
       {
@@ -3961,13 +4629,159 @@
         if( uiCodeVertex )
         {
+#if R0151_CGS_3D_ASYMLUT_IMPROVE
+#if R0300_CGS_RES_COEFF_CODING
+          xReadParam( deltaY, nFLCbits );
+          xReadParam( deltaU, nFLCbits );
+          xReadParam( deltaV, nFLCbits );
+#else
+          xReadParam( deltaY );
+          xReadParam( deltaU );
+          xReadParam( deltaV );
+#endif
+#else
           READ_SVLC( deltaY , "resY" );
           READ_SVLC( deltaU , "resU" );
           READ_SVLC( deltaV , "resV" );
-        }
+#endif
+        }
+#if R0164_CGS_LUT_BUGFIX
+        pc3DAsymLUT->setCuboidVertexResTree( yIdx + (l<<shift) , uIdx , vIdx , nVertexIdx , deltaY , deltaU , deltaV );
+        for (Int m = 1; m < (1<<shift); m++) {
+          pc3DAsymLUT->setCuboidVertexResTree( yIdx + (l<<shift) + m , uIdx , vIdx , nVertexIdx , 0 , 0 , 0 );
+#if R0164_CGS_LUT_BUGFIX_CHECK
+          pc3DAsymLUT->xSetFilled( yIdx + (l<<shift) + m , uIdx , vIdx );
+#endif
+        }
+#else
         pc3DAsymLUT->setCuboidVertexResTree( yIdx + l , uIdx , vIdx , nVertexIdx , deltaY , deltaU , deltaV );
-      }
-    }
-  }
-}
+#endif
+      }
+#if R0164_CGS_LUT_BUGFIX_CHECK
+      pc3DAsymLUT->xSetExplicit( yIdx + (l<<shift) , uIdx , vIdx );
+#endif
+    }
+#if R0164_CGS_LUT_BUGFIX
+    for ( Int u=0 ; u<nLength ; u++ ) {
+      for ( Int v=0 ; v<nLength ; v++ ) {
+        if ( u!=0 || v!=0 ) {
+          for ( Int y=0 ; y<nLength*nYPartNum ; y++ ) {
+            for( Int nVertexIdx = 0 ; nVertexIdx < 4 ; nVertexIdx++ )
+            {
+              pc3DAsymLUT->setCuboidVertexResTree( yIdx + y , uIdx + u , vIdx + v , nVertexIdx , 0 , 0 , 0 );
+#if R0164_CGS_LUT_BUGFIX_CHECK
+              pc3DAsymLUT->xSetFilled( yIdx + y , uIdx + u , vIdx + v );
+#endif
+            }
+          }
+        }
+      }
+    }
+#endif
+  }
+}
+
+#if R0151_CGS_3D_ASYMLUT_IMPROVE
+#if R0300_CGS_RES_COEFF_CODING
+Void TDecCavlc::xReadParam( Int& param, Int rParam )
+#else
+Void TDecCavlc::xReadParam( Int& param )
+#endif
+{
+#if !R0300_CGS_RES_COEFF_CODING
+  const UInt rParam = 7;
+#endif
+  UInt prefix;
+  UInt codeWord ;
+  UInt rSymbol;
+  UInt sign;
+
+  READ_UVLC( prefix, "quotient")  ;
+  READ_CODE (rParam, codeWord, "remainder");
+  rSymbol = (prefix<<rParam) + codeWord;
+
+  if(rSymbol)
+  {
+    READ_FLAG(sign, "sign");
+    param = sign ? -(Int)(rSymbol) : (Int)(rSymbol);
+  }
+  else param = 0;
+}
+#endif
+#if VPS_VUI_BSP_HRD_PARAMS
+Void TDecCavlc::parseVpsVuiBspHrdParams( TComVPS *vps )
+{
+  UInt uiCode;
+  assert (vps->getTimingInfo()->getTimingInfoPresentFlag() == 1);
+  READ_UVLC( uiCode, "vps_num_add_hrd_params" ); vps->setVpsNumAddHrdParams(uiCode);
+  vps->createBspHrdParamBuffer(vps->getVpsNumAddHrdParams()); // Also allocates m_cprmsAddPresentFlag and m_numSubLayerHrdMinus
+
+  for( Int i = vps->getNumHrdParameters(), j = 0; i < vps->getNumHrdParameters() + vps->getVpsNumAddHrdParams(); i++, j++ ) // j = i - vps->getNumHrdParameters()
+  {
+    if( i > 0 )
+    {
+      READ_FLAG( uiCode, "cprms_add_present_flag[i]" );   vps->setCprmsAddPresentFlag(j, uiCode ? true : false);
+    }
+    else
+    {
+      // i == 0
+      if( vps->getNumHrdParameters() == 0 )
+      {
+        vps->setCprmsAddPresentFlag(0, true);
+      }
+    }
+    READ_UVLC( uiCode, "num_sub_layer_hrd_minus1[i]" ); vps->setNumSubLayerHrdMinus1(j, uiCode );
+    assert( uiCode <= vps->getMaxTLayers() - 1 );
+    
+    parseHrdParameters( vps->getBspHrd(j), vps->getCprmsAddPresentFlag(j), vps->getNumSubLayerHrdMinus1(j) );
+    if( i > 0 && !vps->getCprmsAddPresentFlag(i) )
+    {
+      // Copy common information parameters
+      if( i == vps->getNumHrdParameters() )
+      {
+        vps->getBspHrd(j)->copyCommonInformation( vps->getHrdParameters( vps->getNumHrdParameters() - 1 ) );
+      }
+      else
+      {
+        vps->getBspHrd(j)->copyCommonInformation( vps->getBspHrd( j - 1 ) );
+      }
+    }
+  }
+  for (Int h = 1; h < vps->getNumOutputLayerSets(); h++)
+  {
+    Int lsIdx = vps->getOutputLayerSetIdx( h );
+    READ_UVLC( uiCode, "num_signalled_partitioning_schemes[h]"); vps->setNumSignalledPartitioningSchemes(h, uiCode);
+    for( Int j = 0; j < vps->getNumSignalledPartitioningSchemes(h); j++ )
+    {
+      READ_UVLC( uiCode, "num_partitions_in_scheme_minus1[h][j]" ); vps->setNumPartitionsInSchemeMinus1(h, j, uiCode);
+      for( Int k = 0; k <= vps->getNumPartitionsInSchemeMinus1(h, j); k++ )
+      {
+        for( Int r = 0; r < vps->getNumLayersInIdList( lsIdx ); r++ )
+        {
+          READ_FLAG( uiCode, "layer_included_in_partition_flag[h][j][k][r]" ); vps->setLayerIncludedInPartitionFlag(h, j, k, r, uiCode ? true : false);
+        }
+      }
+    }
+    for( Int i = 0; i < vps->getNumSignalledPartitioningSchemes(h) + 1; i++ )
+    {
+      for( Int t = 0; t <= vps->getMaxSLayersInLayerSetMinus1(lsIdx); t++ )
+      {
+        READ_UVLC( uiCode, "num_bsp_schedules_minus1[h][i][t]");              vps->setNumBspSchedulesMinus1(h, i, t, uiCode);
+        for( Int j = 0; j <= vps->getNumBspSchedulesMinus1(h, i, t); j++ )
+        {
+          for( Int k = 0; k < vps->getNumPartitionsInSchemeMinus1(h, i); k++ )
+          {
+            READ_UVLC( uiCode, "bsp_comb_hrd_idx[h][i][t][j][k]");      vps->setBspHrdIdx(h, i, t, j, k, uiCode);
+            READ_UVLC( uiCode, "bsp_comb_sched_idx[h][i][t][j][k]");    vps->setBspSchedIdx(h, i, t, j, k, uiCode);
+          }
+        }
+      }
+    }
+
+    // To be done: Check each layer included in not more than one BSP in every partitioning scheme,
+    // and other related checks associated with layers in bitstream partitions.
+
+  }
+}
+#endif
 #endif
 //! \}
Index: trunk/source/Lib/TLibDecoder/TDecCAVLC.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 815)
+++ trunk/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 906)
@@ -86,4 +86,7 @@
   Void  parseVpsDpbSizeTable( TComVPS *vps );
 #endif
+#if VPS_VUI_BSP_HRD_PARAMS
+  Void  parseVpsVuiBspHrdParams( TComVPS *vps );
+#endif
 #if SPS_DPB_PARAMS
   Void  parseSPS            ( TComSPS* pcSPS ); // it should be removed after macro clean up
@@ -143,4 +146,11 @@
   Void xParse3DAsymLUT( TCom3DAsymLUT * pc3DAsymLUT );
   Void xParse3DAsymLUTOctant( TCom3DAsymLUT * pc3DAsymLUT , Int nDepth , Int yIdx , Int uIdx , Int vIdx , Int nLength );
+#if R0151_CGS_3D_ASYMLUT_IMPROVE
+#if R0300_CGS_RES_COEFF_CODING
+  Void xReadParam( Int& param, Int flc_bits );
+#else
+  Void xReadParam( Int& param );
+#endif
+#endif
 #endif
 };
Index: trunk/source/Lib/TLibDecoder/TDecGop.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecGop.cpp	(revision 815)
+++ trunk/source/Lib/TLibDecoder/TDecGop.cpp	(revision 906)
@@ -54,4 +54,8 @@
 //! \{
 static void calcAndPrintHashStatus(TComPicYuv& pic, const SEIDecodedPictureHash* pictureHashSEI);
+#if Q0074_COLOUR_REMAPPING_SEI
+static Void applyColourRemapping(TComPicYuv& pic, const SEIColourRemappingInfo* colourRemappingInfoSEI, UInt layerId=0 );
+static std::vector<SEIColourRemappingInfo> storeCriSEI; //Persistent Colour Remapping Information SEI
+#endif
 // ====================================================================================================================
 // Constructor / destructor / initialization / destroy
@@ -218,5 +222,10 @@
       if( pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->isILR( m_layerId ) )
       {
-        printf( "%d(%d)", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex), pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->getLayerId() );
+        UInt refLayerId = pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->getLayerId();
+        UInt refLayerIdc = pcSlice->getReferenceLayerIdc(refLayerId);
+        assert( g_posScalingFactor[refLayerIdc][0] );
+        assert( g_posScalingFactor[refLayerIdc][1] );
+
+        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] );
       }
       else
@@ -247,4 +256,20 @@
     calcAndPrintHashStatus(*rpcPic->getPicYuvRec(), hash);
   }
+#if Q0074_COLOUR_REMAPPING_SEI
+  if (m_colourRemapSEIEnabled)
+  {
+    SEIMessages colourRemappingInfo = getSeisByType(rpcPic->getSEIs(), SEI::COLOUR_REMAPPING_INFO );
+    const SEIColourRemappingInfo *seiColourRemappingInfo = ( colourRemappingInfo.size() > 0 ) ? (SEIColourRemappingInfo*) *(colourRemappingInfo.begin()) : NULL;
+    if (colourRemappingInfo.size() > 1)
+    {
+      printf ("Warning: Got multiple Colour Remapping Information SEI messages. Using first.");
+    }
+    applyColourRemapping(*rpcPic->getPicYuvRec(), seiColourRemappingInfo
+#if SVC_EXTENSION
+     , rpcPic->getLayerId()
+#endif
+     );
+  }
+#endif
 
 #if SETTING_PIC_OUTPUT_MARK
@@ -334,3 +359,168 @@
   }
 }
+
+#if Q0074_COLOUR_REMAPPING_SEI
+Void xInitColourRemappingLut( const Int bitDepthY, const Int bitDepthC, std::vector<Int>(&preLut)[3], std::vector<Int>(&postLut)[3], const SEIColourRemappingInfo* const pCriSEI )
+{
+  for ( Int c=0 ; c<3 ; c++ )
+  {  
+    Int bitDepth = c ? bitDepthC : bitDepthY ;
+    preLut[c].resize(1 << bitDepth);
+    postLut[c].resize(1 << pCriSEI->m_colourRemapBitDepth);
+    
+    Int bitDepthDiff = pCriSEI->m_colourRemapBitDepth - bitDepth;
+    Int iShift1 = (bitDepthDiff>0) ? bitDepthDiff : 0; //bit scale from bitdepth to ColourRemapBitdepth (manage only case colourRemapBitDepth>= bitdepth)
+    if( bitDepthDiff<0 )
+      printf ("Warning: CRI SEI - colourRemapBitDepth (%d) <bitDepth (%d) - case not handled\n", pCriSEI->m_colourRemapBitDepth, bitDepth);
+    bitDepthDiff = pCriSEI->m_colourRemapBitDepth - pCriSEI->m_colourRemapInputBitDepth;
+    Int iShift2 = (bitDepthDiff>0) ? bitDepthDiff : 0; //bit scale from ColourRemapInputBitdepth to ColourRemapBitdepth (manage only case colourRemapBitDepth>= colourRemapInputBitDepth)
+    if( bitDepthDiff<0 )
+      printf ("Warning: CRI SEI - colourRemapBitDepth (%d) <colourRemapInputBitDepth (%d) - case not handled\n", pCriSEI->m_colourRemapBitDepth, pCriSEI->m_colourRemapInputBitDepth);
+
+    //Fill preLut
+    for ( Int k=0 ; k<(1<<bitDepth) ; k++ )
+    {
+      Int iSample = k << iShift1 ;
+      for ( Int iPivot=0 ; iPivot<=pCriSEI->m_preLutNumValMinus1[c] ; iPivot++ )
+      {
+        Int iCodedPrev  = pCriSEI->m_preLutCodedValue[c][iPivot]    << iShift2; //Coded in CRInputBitdepth
+        Int iCodedNext  = pCriSEI->m_preLutCodedValue[c][iPivot+1]  << iShift2; //Coded in CRInputBitdepth
+        Int iTargetPrev = pCriSEI->m_preLutTargetValue[c][iPivot];              //Coded in CRBitdepth
+        Int iTargetNext = pCriSEI->m_preLutTargetValue[c][iPivot+1];            //Coded in CRBitdepth
+        if ( iCodedPrev <= iSample && iSample <= iCodedNext )
+        {
+          Float fInterpol = (Float)( (iCodedNext - iSample)*iTargetPrev + (iSample - iCodedPrev)*iTargetNext ) * 1.f / (Float)(iCodedNext - iCodedPrev);
+          preLut[c][k]  = (Int)( 0.5f + fInterpol );
+          iPivot = pCriSEI->m_preLutNumValMinus1[c] + 1;
+        }
+      }
+    }
+    
+    //Fill postLut
+    for ( Int k=0 ; k<(1<<pCriSEI->m_colourRemapBitDepth) ; k++ )
+    {
+      Int iSample = k;
+      for ( Int iPivot=0 ; iPivot<=pCriSEI->m_postLutNumValMinus1[c] ; iPivot++ )
+      {
+        Int iCodedPrev  = pCriSEI->m_postLutCodedValue[c][iPivot];    //Coded in CRBitdepth
+        Int iCodedNext  = pCriSEI->m_postLutCodedValue[c][iPivot+1];  //Coded in CRBitdepth
+        Int iTargetPrev = pCriSEI->m_postLutTargetValue[c][iPivot];   //Coded in CRBitdepth
+        Int iTargetNext = pCriSEI->m_postLutTargetValue[c][iPivot+1]; //Coded in CRBitdepth
+        if ( iCodedPrev <= iSample && iSample <= iCodedNext )
+        {
+          Float fInterpol =  (Float)( (iCodedNext - iSample)*iTargetPrev + (iSample - iCodedPrev)*iTargetNext ) * 1.f / (Float)(iCodedNext - iCodedPrev) ;
+          postLut[c][k]  = (Int)( 0.5f + fInterpol );
+          iPivot = pCriSEI->m_postLutNumValMinus1[c] + 1;
+        }
+      }
+    }
+  }
+}
+
+static void applyColourRemapping(TComPicYuv& pic, const SEIColourRemappingInfo* pCriSEI, UInt layerId )
+{  
+  if( !storeCriSEI.size() )
+#if SVC_EXTENSION
+    storeCriSEI.resize(MAX_LAYERS);
+#else
+    storeCriSEI.resize(1);
+#endif
+
+  if ( pCriSEI ) //if a CRI SEI has just been retrieved, keep it in memory (persistence management)
+    storeCriSEI[layerId] = *pCriSEI;
+
+  if( !storeCriSEI[layerId].m_colourRemapCancelFlag )
+  {
+    Int iHeight  = pic.getHeight();
+    Int iWidth   = pic.getWidth();
+    Int iStride  = pic.getStride();
+    Int iCStride = pic.getCStride();
+
+    Pel *YUVIn[3], *YUVOut[3];
+    YUVIn[0] = pic.getLumaAddr();
+    YUVIn[1] = pic.getCbAddr();
+    YUVIn[2] = pic.getCrAddr();
+    
+    TComPicYuv picColourRemapped;
+#if SVC_EXTENSION
+#if AUXILIARY_PICTURES
+    picColourRemapped.create( pic.getWidth(), pic.getHeight(), pic.getChromaFormat(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, NULL );
+#else
+    picColourRemapped.create( pic.getWidth(), pic.getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, NULL );
+#endif
+#else
+    picColourRemapped.create( pic.getWidth(), pic.getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
+#endif 
+    YUVOut[0] = picColourRemapped.getLumaAddr();
+    YUVOut[1] = picColourRemapped.getCbAddr();
+    YUVOut[2] = picColourRemapped.getCrAddr();
+
+#if SVC_EXTENSION
+    Int bitDepthY = g_bitDepthYLayer[layerId];
+    Int bitDepthC = g_bitDepthCLayer[layerId];
+
+    assert( g_bitDepthY == bitDepthY );
+    assert( g_bitDepthC == bitDepthC );
+#else
+    Int bitDepthY = g_bitDepthY;
+    Int bitDepthC = g_bitDepthC;
+#endif
+
+    std::vector<Int> preLut[3];
+    std::vector<Int> postLut[3];
+    xInitColourRemappingLut( bitDepthY, bitDepthC, preLut, postLut, &storeCriSEI[layerId] );
+    
+    Int roundingOffset = (storeCriSEI[layerId].m_log2MatrixDenom==0) ? 0 : (1 << (storeCriSEI[layerId].m_log2MatrixDenom - 1));
+
+    for( Int y = 0; y < iHeight ; y++ )
+    {
+      for( Int x = 0; x < iWidth ; x++ )
+      {
+        Int YUVPre[3], YUVMat[3];
+        YUVPre[0] = preLut[0][ YUVIn[0][x]   ];
+        YUVPre[1] = preLut[1][ YUVIn[1][x>>1] ];
+        YUVPre[2] = preLut[2][ YUVIn[2][x>>1] ];
+
+        YUVMat[0] = ( storeCriSEI[layerId].m_colourRemapCoeffs[0][0]*YUVPre[0]
+                    + storeCriSEI[layerId].m_colourRemapCoeffs[0][1]*YUVPre[1] 
+                    + storeCriSEI[layerId].m_colourRemapCoeffs[0][2]*YUVPre[2] 
+                    + roundingOffset ) >> ( storeCriSEI[layerId].m_log2MatrixDenom );
+        YUVMat[0] = Clip3( 0, (1<<storeCriSEI[layerId].m_colourRemapBitDepth)-1, YUVMat[0] );
+        YUVOut[0][x] = postLut[0][ YUVMat[0] ];
+
+        if( (y&1) && (x&1) )
+        {
+          for(Int c=1 ; c<3 ; c++)
+          {
+            YUVMat[c] = ( storeCriSEI[layerId].m_colourRemapCoeffs[c][0]*YUVPre[0] 
+                        + storeCriSEI[layerId].m_colourRemapCoeffs[c][1]*YUVPre[1] 
+                        + storeCriSEI[layerId].m_colourRemapCoeffs[c][2]*YUVPre[2] 
+                        + roundingOffset ) >> ( storeCriSEI[layerId].m_log2MatrixDenom );
+            YUVMat[c] = Clip3( 0, (1<<storeCriSEI[layerId].m_colourRemapBitDepth)-1, YUVMat[c] );
+            YUVOut[c][x>>1] = postLut[c][ YUVMat[c] ];   
+          }
+        }
+      }
+      YUVIn[0]  += iStride;
+      YUVOut[0] += iStride;
+      if( y&1 )
+      {
+        YUVIn[1]  += iCStride;
+        YUVIn[2]  += iCStride;
+        YUVOut[1] += iCStride;
+        YUVOut[2] += iCStride;
+      }
+    }
+
+    //Write remapped picture in decoding order
+    Char  cTemp[255];
+    sprintf(cTemp, "seiColourRemappedPic_L%d_%dx%d_%dbits.yuv", layerId, iWidth, iHeight, storeCriSEI[layerId].m_colourRemapBitDepth );
+    picColourRemapped.dump( cTemp, true, storeCriSEI[layerId].m_colourRemapBitDepth );
+
+    picColourRemapped.destroy();
+
+    storeCriSEI[layerId].m_colourRemapCancelFlag = !storeCriSEI[layerId].m_colourRemapPersistenceFlag; //Handling persistence
+  }
+}
+#endif
 //! \}
Index: trunk/source/Lib/TLibDecoder/TDecGop.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecGop.h	(revision 815)
+++ trunk/source/Lib/TLibDecoder/TDecGop.h	(revision 906)
@@ -82,5 +82,7 @@
   Double                m_dDecTime;
   Int                   m_decodedPictureHashSEIEnabled;  ///< Checksum(3)/CRC(2)/MD5(1)/disable(0) acting on decoded picture hash SEI message
-
+#if Q0074_COLOUR_REMAPPING_SEI
+  Bool                  m_colourRemapSEIEnabled;         ///< Enable/disable Colour Remapping Information SEI message acting on decoded pictures
+#endif
 #if SVC_EXTENSION
   UInt                  m_layerId;
@@ -114,4 +116,7 @@
 
   void setDecodedPictureHashSEIEnabled(Int enabled) { m_decodedPictureHashSEIEnabled = enabled; }
+#if Q0074_COLOUR_REMAPPING_SEI
+  void setColourRemappingInfoSEIEnabled(Int enabled) { m_colourRemapSEIEnabled = enabled; }
+#endif
 #if SVC_EXTENSION
   TDecTop*   getLayerDec(UInt LayerId)  { return m_ppcTDecTop[LayerId]; }
Index: trunk/source/Lib/TLibDecoder/TDecSlice.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecSlice.cpp	(revision 815)
+++ trunk/source/Lib/TLibDecoder/TDecSlice.cpp	(revision 906)
@@ -42,5 +42,7 @@
 
 #if SVC_EXTENSION
-  ParameterSetMap<TComVPS> ParameterSetManagerDecoder::m_vpsBuffer(MAX_NUM_VPS);
+ParameterSetMap<TComVPS> ParameterSetManagerDecoder::m_vpsBuffer(MAX_NUM_VPS);
+ParameterSetMap<TComSPS> ParameterSetManagerDecoder::m_spsBuffer(MAX_NUM_SPS);
+ParameterSetMap<TComPPS> ParameterSetManagerDecoder::m_ppsBuffer(MAX_NUM_PPS);
 #endif
 
@@ -144,5 +146,7 @@
   UInt uiTilesAcross   = rpcPic->getPicSym()->getNumColumnsMinus1()+1;
   TComSlice*  pcSlice = rpcPic->getSlice(rpcPic->getCurrSliceIdx());
+#if !WPP_FIX
   Int  iNumSubstreams = pcSlice->getPPS()->getNumSubstreams();
+#endif
 
   // delete decoders if already allocated in previous slice
@@ -191,4 +195,17 @@
   UInt uiWidthInLCUs  = rpcPic->getPicSym()->getFrameWidthInCU();
   //UInt uiHeightInLCUs = rpcPic->getPicSym()->getFrameHeightInCU();
+
+#if WPP_FIX
+  UInt uiTileCol;
+  UInt uiTileLCUX;
+  const Bool depSliceSegmentsEnabled = rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getPPS()->getDependentSliceSegmentsEnabledFlag();
+  const UInt startTileIdx=rpcPic->getPicSym()->getTileIdxMap(iStartCUAddr);
+  TComTile *pCurrentTile=rpcPic->getPicSym()->getTComTile(startTileIdx);
+  UInt uiTileStartLCU = pCurrentTile->getFirstCUAddr(); // Code tidy
+
+  // The first LCU of the slice is the first coded substream, but the global substream number, as calculated by getSubstreamForLCUAddr may be higher.
+  // This calculates the common offset for all substreams in this slice.
+  const UInt subStreamOffset=rpcPic->getSubstreamForLCUAddr(iStartCUAddr, true, pcSlice);
+#else
   UInt uiCol=0, uiLin=0, uiSubStrm=0;
 
@@ -199,13 +216,28 @@
   Bool depSliceSegmentsEnabled = rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getPPS()->getDependentSliceSegmentsEnabledFlag();
   uiTileStartLCU = rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(iStartCUAddr))->getFirstCUAddr();
+#endif
   if( depSliceSegmentsEnabled )
   {
+#if WPP_FIX
+    if( (!rpcPic->getSlice(rpcPic->getCurrSliceIdx())->isNextSlice()) && iStartCUAddr != uiTileStartLCU)  // Code tidy // Is this a dependent slice segment and not the start of a tile?
+#else
     if( (!rpcPic->getSlice(rpcPic->getCurrSliceIdx())->isNextSlice()) &&
        iStartCUAddr != rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(iStartCUAddr))->getFirstCUAddr())
+#endif
     {
       if(pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag())
       {
+#if WPP_FIX
+        uiTileCol = startTileIdx % (rpcPic->getPicSym()->getNumColumnsMinus1()+1); // Code tidy
+#else
         uiTileCol = rpcPic->getPicSym()->getTileIdxMap(iStartCUAddr) % (rpcPic->getPicSym()->getNumColumnsMinus1()+1);
+#endif
         m_pcBufferSbacDecoders[uiTileCol].loadContexts( CTXMem[1]  );//2.LCU
+#if WPP_FIX
+        if ( pCurrentTile->getTileWidth() < 2)
+        {
+          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 (!)
+        }
+#else
         if ( (iStartCUAddr%uiWidthInLCUs+1) >= uiWidthInLCUs  )
         {
@@ -217,7 +249,12 @@
           }
         }
+#endif
       }
       pcSbacDecoder->loadContexts(CTXMem[0] ); //end of depSlice-1
+#if WPP_FIX
+      pcSbacDecoders[0].loadContexts(pcSbacDecoder); // The first substream used for the slice will always be 0. (The original code was equivalent)
+#else
       pcSbacDecoders[uiSubStrm].loadContexts(pcSbacDecoder);
+#endif
     }
     else
@@ -237,14 +274,21 @@
     uiTileStartLCU = rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(iCUAddr))->getFirstCUAddr();
     uiTileLCUX = uiTileStartLCU % uiWidthInLCUs;
+#if WPP_FIX
+    UInt uiCol     = iCUAddr % uiWidthInLCUs;
+    UInt uiSubStrm=rpcPic->getSubstreamForLCUAddr(iCUAddr, true, pcSlice)-subStreamOffset;
+#else
     uiCol     = iCUAddr % uiWidthInLCUs;
     // The 'line' is now relative to the 1st line in the slice, not the 1st line in the picture.
     uiLin     = (iCUAddr/uiWidthInLCUs)-(iStartCUAddr/uiWidthInLCUs);
+#endif
     // inherit from TR if necessary, select substream to use.
     if( (pcSlice->getPPS()->getNumSubstreams() > 1) || ( depSliceSegmentsEnabled  && (uiCol == uiTileLCUX)&&(pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag()) ))
     {
+#if !WPP_FIX
       // independent tiles => substreams are "per tile".  iNumSubstreams has already been multiplied.
       iNumSubstreamsPerTile = iNumSubstreams/rpcPic->getPicSym()->getNumTiles();
       uiSubStrm = rpcPic->getPicSym()->getTileIdxMap(iCUAddr)*iNumSubstreamsPerTile
                   + uiLin%iNumSubstreamsPerTile;
+#endif
       m_pcEntropyDecoder->setBitstream( ppcSubstreams[uiSubStrm] );
       // Synchronize cabac probabilities with upper-right LCU if it's available and we're at the start of a line.
@@ -278,4 +322,5 @@
       pcSbacDecoder->load(&pcSbacDecoders[uiSubStrm]);  //this load is used to simplify the code (avoid to change all the call to pcSbacDecoders)
     }
+#if !WPP_FIX
     else if ( pcSlice->getPPS()->getNumSubstreams() <= 1 )
     {
@@ -283,4 +328,5 @@
       iNumSubstreamsPerTile = 1;
     }
+#endif
 
     if ( (iCUAddr == rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(iCUAddr))->getFirstCUAddr()) && // 1st in tile.
@@ -397,8 +443,5 @@
 
 ParameterSetManagerDecoder::ParameterSetManagerDecoder()
-#if SVC_EXTENSION
-: m_spsBuffer(MAX_NUM_SPS)
-, m_ppsBuffer(MAX_NUM_PPS)
-#else
+#if !SVC_EXTENSION
 : m_vpsBuffer(MAX_NUM_VPS)
 , m_spsBuffer(MAX_NUM_SPS)
Index: trunk/source/Lib/TLibDecoder/TDecSlice.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecSlice.h	(revision 815)
+++ trunk/source/Lib/TLibDecoder/TDecSlice.h	(revision 906)
@@ -110,9 +110,11 @@
 #if SVC_EXTENSION
   static ParameterSetMap<TComVPS> m_vpsBuffer;
+  static ParameterSetMap<TComSPS> m_spsBuffer; 
+  static ParameterSetMap<TComPPS> m_ppsBuffer;
 #else
   ParameterSetMap<TComVPS> m_vpsBuffer;
-#endif
   ParameterSetMap<TComSPS> m_spsBuffer; 
   ParameterSetMap<TComPPS> m_ppsBuffer;
+#endif
 };
 
Index: trunk/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecTop.cpp	(revision 815)
+++ trunk/source/Lib/TLibDecoder/TDecTop.cpp	(revision 906)
@@ -43,4 +43,19 @@
 UInt  TDecTop::m_uiPrevLayerId = MAX_UINT;
 Bool  TDecTop::m_bFirstSliceInSequence = true;
+#if POC_RESET_RESTRICTIONS
+Bool  TDecTop::m_checkPocRestrictionsForCurrAu       = false;
+Int   TDecTop::m_pocResetIdcOrCurrAu                 = -1;
+Bool  TDecTop::m_baseLayerIdrFlag                    = false;
+Bool  TDecTop::m_baseLayerPicPresentFlag             = false;
+Bool  TDecTop::m_baseLayerIrapFlag                   = false;
+Bool  TDecTop::m_nonBaseIdrPresentFlag               = false;
+Int   TDecTop::m_nonBaseIdrType                      = -1;
+Bool  TDecTop::m_picNonIdrWithRadlPresentFlag        = false;
+Bool  TDecTop::m_picNonIdrNoLpPresentFlag            = false;
+#endif
+#if POC_RESET_VALUE_RESTRICTION
+Int   TDecTop::m_crossLayerPocResetPeriodId          = -1;
+Int   TDecTop::m_crossLayerPocResetIdc               = -1;
+#endif
 #endif
 
@@ -74,7 +89,4 @@
   memset(m_cIlpPic, 0, sizeof(m_cIlpPic));
 #endif
-#if AVC_SYNTAX || SYNTAX_OUTPUT
-  m_pBLSyntaxFile = NULL;
-#endif
   m_prevSliceSkipped = false;
   m_skippedPOC = 0;
@@ -105,6 +117,10 @@
 #endif
 
-#if Q0074_SEI_COLOR_MAPPING
-  m_ColorMapping = new TDecColorMapping();
+#if POC_RESET_RESTRICTIONS
+  resetPocRestrictionCheckParameters();
+#endif
+#if P0297_VPS_POC_LSB_ALIGNED_FLAG
+  m_pocResettingFlag        = false;
+  m_pocDecrementedInDPBFlag = false;
 #endif
 }
@@ -112,36 +128,4 @@
 TDecTop::~TDecTop()
 {
-#if Q0078_ADD_LAYER_SETS
-  for (Int psId = 0; psId < MAX_NUM_SPS; psId++)
-  {
-    TComSPS* sps = m_parameterSetManagerDecoder.getSPS(psId);
-    if (sps != NULL)
-    {
-      // Remove parameter set from other layers to prevent multiple deletes of the same object
-      for (Int lId = 0; lId < m_numLayer; lId++)
-      {
-        if (m_ppcTDecTop[lId] != this)
-        {
-          m_parameterSetManagerDecoder.removeSPS(psId);
-        }
-      }
-    }
-  }
-  for (Int psId = 0; psId < MAX_NUM_PPS; psId++)
-  {
-    TComPPS* pps = m_parameterSetManagerDecoder.getPPS(psId);
-    if (pps != NULL)
-    {
-      // Remove parameter set from other layers to prevent multiple deletes of the same object
-      for (Int lId = 0; lId < m_numLayer; lId++)
-      {
-        if (m_ppcTDecTop[lId] != this)
-        {
-          m_parameterSetManagerDecoder.removePPS(psId);
-        }
-      }
-    }
-  }
-#endif
 #if ENC_DEC_TRACE
   fclose( g_hTrace );
@@ -154,7 +138,4 @@
     m_pColorMappedPic = NULL;
   }
-#endif
-#if Q0074_SEI_COLOR_MAPPING
-  if ( m_ColorMapping )  delete m_ColorMapping;
 #endif
 }
@@ -188,5 +169,5 @@
       m_cIlpPic[i] = NULL;
     }
-  }    
+  }
 #endif
 }
@@ -237,5 +218,9 @@
 
     Int  numReorderPics[MAX_TLAYER];
+#if R0156_CONF_WINDOW_IN_REP_FORMAT
+    Window &conformanceWindow = slice->getConformanceWindow();
+#else
     Window &conformanceWindow = pcSPS->getConformanceWindow();
+#endif
     Window defaultDisplayWindow = pcSPS->getVuiParametersPresentFlag() ? pcSPS->getVuiParameters()->getDefaultDisplayWindow() : Window();
 
@@ -326,5 +311,9 @@
 {
   Int  numReorderPics[MAX_TLAYER];
+#if R0156_CONF_WINDOW_IN_REP_FORMAT
+  Window &conformanceWindow = pcSlice->getConformanceWindow();
+#else
   Window &conformanceWindow = pcSlice->getSPS()->getConformanceWindow();
+#endif
   Window defaultDisplayWindow = pcSlice->getSPS()->getVuiParametersPresentFlag() ? pcSlice->getSPS()->getVuiParameters()->getDefaultDisplayWindow() : Window();
 
@@ -362,4 +351,5 @@
 #else
     m_iMaxRefPicNum = pcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1( getCommonDecoderParams()->getTargetOutputLayerSetIdx(), pcSlice->getLayerId(), pcSlice->getTLayer() ) + 1; // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
+    //TODO: HENDRY -- Do the checking here.
 #endif
   }
@@ -381,4 +371,11 @@
       for(UInt i = 0; i < pcSlice->getVPS()->getNumDirectRefLayers( m_layerId ); i++ )
       {
+#if MOVE_SCALED_OFFSET_TO_PPS
+#if O0098_SCALED_REF_LAYER_ID
+        const Window scalEL = pcSlice->getPPS()->getScaledRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, i));
+#else
+        const Window scalEL = pcSlice->getPPS()->getScaledRefLayerWindow(i);
+#endif
+#else
 #if O0098_SCALED_REF_LAYER_ID
         const Window scalEL = pcSlice->getSPS()->getScaledRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, i));
@@ -386,5 +383,19 @@
         const Window scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(i);
 #endif
+#endif
+#if REF_REGION_OFFSET
+        const Window refEL = pcSlice->getPPS()->getRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, i));
+#if RESAMPLING_FIX
+        Bool equalOffsets = scalEL.hasEqualOffset(refEL);
+#if R0209_GENERIC_PHASE
+        Bool zeroPhase = pcSlice->getPPS()->hasZeroResamplingPhase(pcSlice->getVPS()->getRefLayerId(m_layerId, i));
+#endif
+#else
+        Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0
+                             && refEL.getWindowLeftOffset() == 0 && refEL.getWindowRightOffset() == 0 && refEL.getWindowTopOffset() == 0 && refEL.getWindowBottomOffset() == 0 );
+#endif
+#else
         Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0 );
+#endif
 
 #if VPS_EXTN_DIRECT_REF_LAYERS
@@ -400,5 +411,22 @@
         Bool sameBitDepths = ( g_bitDepthYLayer[m_layerId] == g_bitDepthYLayer[refLayerId] ) && ( g_bitDepthCLayer[m_layerId] == g_bitDepthCLayer[refLayerId] );
 
-        if( pcPicYuvRecBase->getWidth() != pcSlice->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getPicHeightInLumaSamples() || !zeroOffsets || !sameBitDepths
+#if REF_IDX_MFM
+        if( pcPicYuvRecBase->getWidth() == pcSlice->getPicWidthInLumaSamples() && pcPicYuvRecBase->getHeight() == pcSlice->getPicHeightInLumaSamples() && equalOffsets && zeroPhase )
+        {
+          rpcPic->setEqualPictureSizeAndOffsetFlag( i, true );
+        }
+
+        if( !rpcPic->equalPictureSizeAndOffsetFlag(i) || !sameBitDepths 
+#else
+        if( pcPicYuvRecBase->getWidth() != pcSlice->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getPicHeightInLumaSamples() || !sameBitDepths
+#if REF_REGION_OFFSET && RESAMPLING_FIX
+          || !equalOffsets
+#if R0209_GENERIC_PHASE
+          || !zeroPhase
+#endif
+#else
+          || !zeroOffsets
+#endif
+#endif
 #if Q0048_CGS_3D_ASYMLUT
           || pcSlice->getPPS()->getCGSFlag() > 0
@@ -409,8 +437,26 @@
           )
 #else
-        if(pcPicYuvRecBase->getWidth() != pcSlice->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getPicHeightInLumaSamples() || !zeroOffsets )
-#endif
-#else
-        if(pcPicYuvRecBase->getWidth() != pcSlice->getSPS()->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getSPS()->getPicHeightInLumaSamples() || !zeroOffsets )
+        if(pcPicYuvRecBase->getWidth() != pcSlice->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getPicHeightInLumaSamples()
+#if REF_REGION_OFFSET && RESAMPLING_FIX
+          || !equalOffsets
+#if R0209_GENERIC_PHASE
+          || !zeroPhase
+#endif
+#else
+          || !zeroOffsets
+#endif
+        )
+#endif
+#else
+        if(pcPicYuvRecBase->getWidth() != pcSlice->getSPS()->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getSPS()->getPicHeightInLumaSamples()
+#if REF_REGION_OFFSET && RESAMPLING_FIX
+          || !equalOffsets
+#if R0209_GENERIC_PHASE
+          || !zeroPhase
+#endif
+#else
+          || !zeroOffsets
+#endif
+        )
 #endif
         {
@@ -522,7 +568,4 @@
   m_cGopDecoder.filterPicture(pcPic);
 
-#if SYNTAX_OUTPUT
-  pcPic->wrireBLSyntax( getBLSyntaxFile(), SYNTAX_BYTES );
-#endif
   TComSlice::sortPicList( m_cListPic ); // sorting for application output
   poc                 = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
@@ -713,5 +756,9 @@
 
     // 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
+#if VPS_AVC_BL_FLAG_REMOVAL
+    if( activeVPS->getNonHEVCBaseLayerFlag() )
+#else
     if( activeVPS->getAvcBaseLayerFlag() )
+#endif
     {
       assert( refLayerId > 0 );
@@ -742,5 +789,9 @@
 
     // 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
+#if VPS_AVC_BL_FLAG_REMOVAL
+    if( activeVPS->getNonHEVCBaseLayerFlag() )
+#else
     if( activeVPS->getAvcBaseLayerFlag() )
+#endif
     {
       assert( refLayerId > 0 );
@@ -768,5 +819,9 @@
 
 #if AVC_BASE
+#if VPS_AVC_BL_FLAG_REMOVAL
+  if( activeVPS->getNonHEVCBaseLayerFlag() )
+#else
   if( activeVPS->getAvcBaseLayerFlag() )
+#endif
   {
     TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin());
@@ -777,16 +832,18 @@
 
       Int  numReorderPics[MAX_TLAYER];
+#if !R0156_CONF_WINDOW_IN_REP_FORMAT
       Window conformanceWindow;
+#endif
       Window defaultDisplayWindow;
 
+#if R0156_CONF_WINDOW_IN_REP_FORMAT
 #if AUXILIARY_PICTURES
-#if AVC_SYNTAX
-      pBLPic->create( repFormat->getPicWidthVpsInLumaSamples(), repFormat->getPicHeightVpsInLumaSamples(), repFormat->getChromaFormatVpsIdc(), activeSPS->getMaxCUWidth(), activeSPS->getMaxCUHeight(), activeSPS->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, activeSPS, true);
-#else
+      pBLPic->create( repFormat->getPicWidthVpsInLumaSamples(), repFormat->getPicHeightVpsInLumaSamples(), repFormat->getChromaFormatVpsIdc(), activeSPS->getMaxCUWidth(), activeSPS->getMaxCUHeight(), activeSPS->getMaxCUDepth(), repFormat->getConformanceWindowVps(), defaultDisplayWindow, numReorderPics, NULL, true);
+#else
+      pBLPic->create( repFormat->getPicWidthVpsInLumaSamples(), repFormat->getPicHeightVpsInLumaSamples(), activeSPS->getMaxCUWidth(), activeSPS->getMaxCUHeight(), activeSPS->getMaxCUDepth(), repFormat->getConformanceWindowVps(), defaultDisplayWindow, numReorderPics, NULL, true);
+#endif
+#else
+#if AUXILIARY_PICTURES
       pBLPic->create( repFormat->getPicWidthVpsInLumaSamples(), repFormat->getPicHeightVpsInLumaSamples(), repFormat->getChromaFormatVpsIdc(), activeSPS->getMaxCUWidth(), activeSPS->getMaxCUHeight(), activeSPS->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, NULL, true);
-#endif
-#else
-#if AVC_SYNTAX
-      pBLPic->create( repFormat->getPicWidthVpsInLumaSamples(), repFormat->getPicHeightVpsInLumaSamples(), activeSPS->getMaxCUWidth(), activeSPS->getMaxCUHeight(), activeSPS->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, activeSPS, true);
 #else
       pBLPic->create( repFormat->getPicWidthVpsInLumaSamples(), repFormat->getPicHeightVpsInLumaSamples(), activeSPS->getMaxCUWidth(), activeSPS->getMaxCUHeight(), activeSPS->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, NULL, true);
@@ -805,4 +862,18 @@
 
 #if P0312_VERT_PHASE_ADJ
+#if MOVE_SCALED_OFFSET_TO_PPS
+  if( activeVPS->getVpsVuiVertPhaseInUseFlag() == 0 )
+  {    
+    for(Int i = 0; i < activePPS->getNumScaledRefLayerOffsets(); i++)
+    {
+      UInt scaledRefLayerId = activePPS->getScaledRefLayerId(i);
+      if( activePPS->getVertPhasePositionEnableFlag( scaledRefLayerId ) )
+      {
+        printf("\nWarning: LayerId = %d: vert_phase_position_enable_flag[%d] = 1, however indication vert_phase_position_in_use_flag = 0\n", m_layerId, scaledRefLayerId );
+        break;
+      }
+    }
+  }
+#else
   if( activeVPS->getVpsVuiVertPhaseInUseFlag() == 0 )
   {    
@@ -817,4 +888,5 @@
     }
   }
+#endif
 #endif
 
@@ -868,7 +940,7 @@
   pps->setSPS(sps);
 #if REPN_FORMAT_IN_VPS
-  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1);
-#else
-  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1);
+  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumTileColumnsMinus1() + 1) : 1);
+#else
+  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumTileColumnsMinus1() + 1) : 1);
 #endif
   pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
@@ -885,11 +957,4 @@
   g_uiMaxCUDepth  = sps->getMaxCUDepth();
   g_uiAddCUDepth  = max (0, sps->getLog2MinCodingBlockSize() - (Int)sps->getQuadtreeTULog2MinSize() );
-
-#if Q0074_SEI_COLOR_MAPPING
-  for(Int compID=0; compID<3; compID++)
-  {
-    m_ColorMapping->setColorMapping( compID ? g_bitDepthC : g_bitDepthY, compID );
-  }
-#endif
 
   for (Int i = 0; i < sps->getLog2DiffMaxMinCodingBlockSize(); i++)
@@ -953,4 +1018,7 @@
 
   m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
+#if POC_RESET_RESTRICTIONS
+  m_apcSlicePilot->setTLayer( nalu.m_temporalId );
+#endif
   Bool nonReferenceFlag = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N ||
                            m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N   ||
@@ -1018,4 +1086,7 @@
   }
 
+  //TODO: HENDRY -- Probably do the checking for max number of positive and negative pics here
+
+
   //For inference of PicOutputFlag
   if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R)
@@ -1109,4 +1180,5 @@
   }
 #endif
+
 #if POC_RESET_IDC_DECODER
   if( m_parseIdc != -1 ) // Second pass for a POC resetting picture
@@ -1129,6 +1201,37 @@
     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
     {
+#if POC_RESET_RESTRICTIONS
+      // New access unit; reset all variables related to POC reset restrictions
+      resetPocRestrictionCheckParameters();
+#endif
       markAllPicsAsNoCurrAu();
-    }
+#if P0297_VPS_POC_LSB_ALIGNED_FLAG
+      for (UInt i = 0; i < MAX_LAYERS; i++)
+      {
+        m_ppcTDecTop[i]->m_pocDecrementedInDPBFlag = false;
+      }
+#endif
+    }
+
+
+#if P0297_VPS_POC_LSB_ALIGNED_FLAG
+    m_pocResettingFlag = false;
+
+    if (m_apcSlicePilot->getPocResetIdc() != 0)
+    {
+      if (m_apcSlicePilot->getVPS()->getVpsPocLsbAlignedFlag())
+      {
+        m_pocResettingFlag = true;
+      }
+      else if (m_pocDecrementedInDPBFlag)
+      {
+        m_pocResettingFlag = false;
+      }
+      else
+      {
+        m_pocResettingFlag = true;
+      }
+    }
+#endif
 
     if( m_apcSlicePilot->getPocResetIdc() && m_apcSlicePilot->getSliceIdx() == 0 )
@@ -1141,9 +1244,36 @@
         m_parseIdc = 0;
       }
+#if POC_RESET_VALUE_RESTRICTION
+      // Check if the POC Reset period ID matches with the Reset Period ID 
+      if( pocResetPeriodId == m_crossLayerPocResetPeriodId )
+      {
+        // If matching, and current poc_reset_idc = 3, then the values should match
+        if( m_apcSlicePilot->getPocResetIdc() == 3 )
+        {
+          assert( ( m_apcSlicePilot->getFullPocResetFlag() == false && m_crossLayerPocResetIdc == 1 ) ||
+                  ( m_apcSlicePilot->getFullPocResetFlag() == true  && m_crossLayerPocResetIdc == 2 ) );
+        }
+      }
+      else
+      {
+        // This is the first picture of a POC resetting access unit
+        m_crossLayerPocResetPeriodId = pocResetPeriodId;
+        if( m_apcSlicePilot->getPocResetIdc() == 1 || m_apcSlicePilot->getPocResetIdc() == 2 )
+        {
+          m_crossLayerPocResetIdc = m_apcSlicePilot->getPocResetIdc();
+        }
+        else
+        { // poc_reset_idc = 3
+          // In this case, the entire POC resetting access unit has been lost. 
+          // Need more checking to ensure poc_reset_idc = 3 works.
+          assert ( 0 );
+        }
+      }
+#endif
     }
     else
     {
       m_parseIdc = 3; // Proceed to decoding POC and RPS
-    }  
+    }
   }
 #endif
@@ -1151,6 +1281,28 @@
 #if ALIGNED_BUMPING
 #if POC_RESET_IDC_DECODER
+
+#if P0297_VPS_POC_LSB_ALIGNED_FLAG
+  UInt affectedLayerList[MAX_NUM_LAYER_IDS];
+  Int  numAffectedLayers;
+
+  affectedLayerList[0] = m_apcSlicePilot->getLayerId();
+  numAffectedLayers = 1;
+
+  if (m_apcSlicePilot->getVPS()->getVpsPocLsbAlignedFlag())
+  {
+    for (UInt j = 0; j < m_apcSlicePilot->getVPS()->getNumPredictedLayers(m_apcSlicePilot->getLayerId()); j++)
+    {
+      affectedLayerList[j + 1] = m_apcSlicePilot->getVPS()->getPredictedLayerId(m_apcSlicePilot->getLayerId(), j);
+    }
+    numAffectedLayers = m_apcSlicePilot->getVPS()->getNumPredictedLayers(m_apcSlicePilot->getLayerId()) + 1;
+  }
+#endif
+
   //if(  (bNewPOC || m_layerId != m_uiPrevLayerId) && ( m_parseIdc != 1) )
-  if( m_parseIdc == 1 )
+#if P0297_VPS_POC_LSB_ALIGNED_FLAG
+  if (m_parseIdc == 1 && m_pocResettingFlag)
+#else
+  if (m_parseIdc == 1)
+#endif
   {
     // Invoke output of pictures if the current picture is a POC reset picture
@@ -1203,4 +1355,13 @@
     Int deltaPocVal  =  pocMsbDelta + pocLsbDelta;
 
+#if P0297_VPS_POC_LSB_ALIGNED_FLAG
+    for (UInt layerIdx = 0; layerIdx < numAffectedLayers; layerIdx++)
+    {
+      if (!m_ppcTDecTop[affectedLayerList[layerIdx]]->m_pocDecrementedInDPBFlag)
+      {
+        m_ppcTDecTop[affectedLayerList[layerIdx]]->m_pocDecrementedInDPBFlag = true;
+        TComList<TComPic*>::iterator  iterPic = m_ppcTDecTop[affectedLayerList[layerIdx]]->getListPic()->begin();
+        while (iterPic != m_ppcTDecTop[affectedLayerList[layerIdx]]->getListPic()->end())
+#else
     //Reset all POC for DPB -> basically do it for each slice in the picutre
     TComList<TComPic*>::iterator  iterPic = m_cListPic.begin();  
@@ -1208,11 +1369,17 @@
     // Iterate through all picture in DPB
     while( iterPic != m_cListPic.end() )
+#endif
     {
       TComPic *dpbPic = *iterPic;
       // Check if the picture pointed to by iterPic is either used for reference or
       // needed for output, are in the same layer, and not the current picture.
-      if( /*  ( ( dpbPic->getSlice(0)->isReferenced() ) || ( dpbPic->getOutputMark() ) )
+#if P0297_VPS_POC_LSB_ALIGNED_FLAG
+      assert(dpbPic->getLayerId() == affectedLayerList[layerIdx]);
+      if ( (dpbPic->getReconMark()) && (dpbPic->getPicSym()->getSlice(0)->getPicOutputFlag()) )
+#else
+      if ( /*  ( ( dpbPic->getSlice(0)->isReferenced() ) || ( dpbPic->getOutputMark() ) )
           &&*/ ( dpbPic->getLayerId() == m_apcSlicePilot->getLayerId() )
             && ( dpbPic->getReconMark() ) && ( dpbPic->getPicSym()->getSlice(0)->getPicOutputFlag() ))
+#endif
       {
         for(Int i = dpbPic->getNumAllocatedSlice()-1; i >= 0; i--)
@@ -1241,6 +1408,13 @@
       iterPic++;
     }
+#if P0297_VPS_POC_LSB_ALIGNED_FLAG
+        // Update the value of pocCRA
+        m_ppcTDecTop[affectedLayerList[layerIdx]]->m_pocCRA -= deltaPocVal;
+      }
+    }
+#else
     // Update the value of pocCRA
     m_pocCRA -= deltaPocVal;
+#endif
 
     // Update value of POCLastDisplay
@@ -1250,5 +1424,9 @@
   Int slicePicOrderCntLsb = m_apcSlicePilot->getPicOrderCntLsb();
 
-  if( m_parseIdc == 1 || m_parseIdc == 2 ) // TODO This should be replaced by pocResettingFlag.
+#if P0297_VPS_POC_LSB_ALIGNED_FLAG
+  if (m_pocResettingFlag && (m_parseIdc == 1 || m_parseIdc == 2))
+#else
+  if (m_parseIdc == 1 || m_parseIdc == 2) // TODO This should be replaced by pocResettingFlag.
+#endif
   {
     // Set poc for current slice
@@ -1296,10 +1474,28 @@
         && !m_apcSlicePilot->getDiscardableFlag() )
     {
+#if P0297_VPS_POC_LSB_ALIGNED_FLAG
+      for (UInt i = 0; i < numAffectedLayers; i++)
+      {
+        m_ppcTDecTop[affectedLayerList[i]]->setPrevPicOrderCnt(m_apcSlicePilot->getPOC());
+      }
+#else
       this->setPrevPicOrderCnt( m_apcSlicePilot->getPOC() );
+#endif
     }
     else if ( m_apcSlicePilot->getPocResetIdc() == 3 )
     {
+#if P0297_VPS_POC_LSB_ALIGNED_FLAG
+      if (!m_firstPicInLayerDecodedFlag || (m_firstPicInLayerDecodedFlag && m_pocResettingFlag))
+      {
+        for (UInt i = 0; i < numAffectedLayers; i++)
+        {
+          m_ppcTDecTop[affectedLayerList[i]]->setPrevPicOrderCnt( m_apcSlicePilot->getFullPocResetFlag() 
+                                                                  ? 0 : m_apcSlicePilot->getPocLsbVal() );
+        }
+      }
+#else
       this->setPrevPicOrderCnt( m_apcSlicePilot->getFullPocResetFlag() 
                                             ? 0 : m_apcSlicePilot->getPocLsbVal() );
+#endif
     }
 #else
@@ -1324,4 +1520,28 @@
 #if POC_RESET_IDC_DECODER
   m_parseIdc = -1;
+#endif
+
+
+#if R0226_SLICE_TMVP
+  if ( m_apcSlicePilot->getTLayer() == 0 && m_apcSlicePilot->getEnableTMVPFlag() == 0 )
+  {
+    //update all pics in the DPB such that they cannot be used for TMPV ref
+    TComList<TComPic*>::iterator  iterRefPic = m_cListPic.begin();  
+    while( iterRefPic != m_cListPic.end() )
+    {
+      TComPic *refPic = *iterRefPic;
+      if( ( refPic->getLayerId() == m_apcSlicePilot->getLayerId() ) && refPic->getReconMark() )
+      {
+        for(Int i = refPic->getNumAllocatedSlice()-1; i >= 0; i--)
+        {
+
+          TComSlice *refSlice = refPic->getSlice(i);
+          refSlice->setAvailableForTMVPRefFlag( false );
+        }
+      }
+      iterRefPic++;
+    }
+  }
+  m_apcSlicePilot->setAvailableForTMVPRefFlag( true );
 #endif
 
@@ -1483,5 +1703,9 @@
   {
 #if AVC_BASE
+#if VPS_AVC_BL_FLAG_REMOVAL
+    if( m_layerId == 1 && m_parameterSetManagerDecoder.getPrefetchedVPS(0)->getNonHEVCBaseLayerFlag() )
+#else
     if( m_layerId == 1 && m_parameterSetManagerDecoder.getPrefetchedVPS(0)->getAvcBaseLayerFlag() )
+#endif
     {
       TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin());
@@ -1611,5 +1835,89 @@
 
 #if POC_RESET_IDC_DECODER
-  pcPic->setCurrAuFlag( true );
+    pcPic->setCurrAuFlag( true );
+#if POC_RESET_RESTRICTIONS
+    if( pcPic->getLayerId() > 0 && m_apcSlicePilot->isIDR() && !m_nonBaseIdrPresentFlag )
+    {
+      // IDR picture with nuh_layer_id > 0 present
+      m_nonBaseIdrPresentFlag = true;
+      m_nonBaseIdrType = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL);
+    }
+    else
+    {
+      if( m_apcSlicePilot->getNalUnitType() != NAL_UNIT_CODED_SLICE_IDR_W_RADL )
+      {
+        // Picture with nal_unit_type not equal IDR_W_RADL present
+        m_picNonIdrWithRadlPresentFlag = true;
+      }
+      if( m_apcSlicePilot->getNalUnitType() != NAL_UNIT_CODED_SLICE_IDR_N_LP )
+      {
+        // Picture with nal_unit_type not equal IDR_N_LP present
+        m_picNonIdrNoLpPresentFlag = true;
+      }
+    }
+    if( !m_checkPocRestrictionsForCurrAu )  // Will be true for the first slice/picture of the AU
+    {
+      m_checkPocRestrictionsForCurrAu = true;
+      m_pocResetIdcOrCurrAu = m_apcSlicePilot->getPocResetIdc();
+      if( pcPic->getLayerId() == 0 )
+      {
+        // Base layer picture is present
+        m_baseLayerPicPresentFlag = true;
+        if( m_apcSlicePilot->isIRAP() )
+        {
+          // Base layer picture is IRAP
+          m_baseLayerIrapFlag = true;
+        }
+        if( m_apcSlicePilot->isIDR() )
+        {
+          // Base layer picture is IDR
+          m_baseLayerIdrFlag = true;
+        }
+        else
+        {
+          if( m_apcSlicePilot->getVPS()->getBaseLayerInternalFlag())
+          {
+            /* When the picture with nuh_layer_id equal to 0 in an access unit is not an IDR picture 
+            and vps_base_layer_internal_flag is equal to 1, the value of poc_reset_idc shall not be equal to 2 
+            for any picture in the access unit. */
+            assert( m_apcSlicePilot->getPocResetIdc() != 2 );
+          }
+        }
+      }
+    }
+    else
+    {
+      // The value of poc_reset_idc of all coded pictures that are present in the bitstream in an access unit shall be the same.
+      assert( m_pocResetIdcOrCurrAu == m_apcSlicePilot->getPocResetIdc() );
+
+      /* 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 
+      and there is at least one other picture in the same access unit that is not an IRAP picture, 
+      the value of poc_reset_idc shall be equal to 1 or 2 for all pictures in the access unit. */
+      if( m_baseLayerPicPresentFlag && m_baseLayerIrapFlag && !m_apcSlicePilot->isIRAP() && m_apcSlicePilot->getVPS()->getBaseLayerInternalFlag() )
+      {
+        assert( m_apcSlicePilot->getPocResetIdc() == 1 || m_apcSlicePilot->getPocResetIdc() == 2 );
+      }
+
+      /* When the picture with nuh_layer_id equal to 0 in an access unit is an IDR picture and 
+      vps_base_layer_internal_flag is equal to 1 and there is at least one non-IDR picture in the same access unit, 
+      the value of poc_reset_idc shall be equal to 2 for all pictures in the access unit. */
+      if( m_baseLayerPicPresentFlag && m_baseLayerIdrFlag && !m_apcSlicePilot->isIDR() && m_apcSlicePilot->getVPS()->getBaseLayerInternalFlag() )
+      {
+        assert( m_apcSlicePilot->getPocResetIdc() == 2 );
+      }
+
+      /* When there is at least one picture that has nuh_layer_id greater than 0 and that is an IDR picture 
+      with a particular value of nal_unit_type in an access unit and there is at least one other coded picture 
+      that is present in the bitstream in the same access unit with a different value of nal_unit_type, 
+      the value of poc_reset_idc shall be equal to 1 or 2 for all pictures in the access unit. */
+      if( m_nonBaseIdrPresentFlag && (
+            ( m_nonBaseIdrType == 1 && m_picNonIdrWithRadlPresentFlag ) ||
+            ( m_nonBaseIdrType == 0 && m_picNonIdrNoLpPresentFlag )
+        ))
+      {
+        assert( m_apcSlicePilot->getPocResetIdc() == 1 || m_apcSlicePilot->getPocResetIdc() == 2 );
+      }
+    }
+#endif
 #endif
 
@@ -1627,4 +1935,32 @@
         isTff =  (pictureTiming->m_picStruct == 1);
       }
+
+#if R0226_CONSTRAINT_TMVP_SEI
+      // Check if any new temporal motion vector prediction constraints SEI has arrived
+      SEIMessages seiTMVPConstrainsList = extractSeisByType (m_SEIs, SEI::TMVP_CONSTRAINTS);
+      if (seiTMVPConstrainsList.size() > 0)
+      {
+        assert ( pcPic->getTLayer() == 0 );  //this SEI can present only for AU with Tid equal to 0
+        SEITMVPConstrains* tmvpConstraintSEI = (SEITMVPConstrains*) *(seiTMVPConstrainsList.begin());
+        if ( tmvpConstraintSEI->prev_pics_not_used_flag == 1 )
+        {
+          //update all pics in the DPB such that they cannot be used for TMPV ref
+          TComList<TComPic*>::iterator  iterRefPic = m_cListPic.begin();  
+          while( iterRefPic != m_cListPic.end() )
+          {
+            TComPic *refPic = *iterRefPic;
+            if( ( refPic->getLayerId() == pcPic->getLayerId() ) && refPic->getReconMark() )
+            {
+              for(Int i = refPic->getNumAllocatedSlice()-1; i >= 0; i--)
+              {
+                TComSlice *refSlice = refPic->getSlice(i);
+                refSlice->setAvailableForTMVPRefFlag( false );
+              }
+            }
+            iterRefPic++;
+          }
+        }
+      }
+#endif
     }
     
@@ -1665,67 +2001,6 @@
   Bool bNextSlice     = pcSlice->isNextSlice();
 
-  UInt uiCummulativeTileWidth;
-  UInt uiCummulativeTileHeight;
-  UInt i, j, p;
-
-  //set NumColumnsMins1 and NumRowsMinus1
-  pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() );
-  pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() );
-
-  //create the TComTileArray
-  pcPic->getPicSym()->xCreateTComTileArray();
-
-  if( pcSlice->getPPS()->getUniformSpacingFlag() )
-  {
-    //set the width for each tile
-    for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
-    {
-      for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
-      {
-        pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
-          setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) 
-          - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
-      }
-    }
-
-    //set the height for each tile
-    for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
-    {
-      for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
-      {
-        pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
-          setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) 
-          - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
-      }
-    }
-  }
-  else
-  {
-    //set the width for each tile
-    for(j=0; j < pcSlice->getPPS()->getNumRowsMinus1()+1; j++)
-    {
-      uiCummulativeTileWidth = 0;
-      for(i=0; i < pcSlice->getPPS()->getNumColumnsMinus1(); i++)
-      {
-        pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getPPS()->getColumnWidth(i) );
-        uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(i);
-      }
-      pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
-    }
-
-    //set the height for each tile
-    for(j=0; j < pcSlice->getPPS()->getNumColumnsMinus1()+1; j++)
-    {
-      uiCummulativeTileHeight = 0;
-      for(i=0; i < pcSlice->getPPS()->getNumRowsMinus1(); i++)
-      { 
-        pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getPPS()->getRowHeight(i) );
-        uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(i);
-      }
-      pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
-    }
-  }
-
-  pcPic->getPicSym()->xInitTiles();
+  UInt i;
+  pcPic->getPicSym()->initTiles(pcSlice->getPPS());
 
   //generate the Coding Order Map and Inverse Coding Order Map
@@ -1793,5 +2068,9 @@
         UInt refLayerId = pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc);
 #if AVC_BASE
+#if VPS_AVC_BL_FLAG_REMOVAL
+        if( refLayerId == 0 && m_parameterSetManagerDecoder.getActiveVPS()->getNonHEVCBaseLayerFlag() )
+#else
         if( refLayerId == 0 && m_parameterSetManagerDecoder.getActiveVPS()->getAvcBaseLayerFlag() )
+#endif
         {          
           TComPic* pic = *m_ppcTDecTop[0]->getListPic()->begin();
@@ -1805,16 +2084,4 @@
             continue;
           }
-#if AVC_SYNTAX
-          TComPic* pBLPic = pcSlice->getBaseColPic(refLayerIdc);
-          if( pcSlice->getPOC() == 0 )
-          {
-            // initialize partition order.
-            UInt* piTmp = &g_auiZscanToRaster[0];
-            initZscanToRaster( pBLPic->getPicSym()->getMaxDepth() + 1, 1, 0, piTmp );
-            initRasterToZscan( pBLPic->getPicSym()->getMaxCUWidth(), pBLPic->getPicSym()->getMaxCUHeight(), pBLPic->getPicSym()->getMaxDepth() + 1 );
-          }      
-          pBLPic->getSlice( 0 )->initBaseLayerRPL( pcSlice );
-          pBLPic->readBLSyntax( m_ppcTDecTop[0]->getBLSyntaxFile(), SYNTAX_BYTES );
-#endif
         }
         else
@@ -1841,4 +2108,11 @@
 #endif
 
+#if MOVE_SCALED_OFFSET_TO_PPS
+#if O0098_SCALED_REF_LAYER_ID
+        const Window &scalEL = pcSlice->getPPS()->getScaledRefLayerWindowForLayer(refLayerId);
+#else
+        const Window &scalEL = pcSlice->getPPS()->getScaledRefLayerWindow(refLayerIdc);
+#endif
+#else
 #if O0098_SCALED_REF_LAYER_ID
         const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindowForLayer(refLayerId);
@@ -1846,5 +2120,11 @@
         const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc);
 #endif
-
+#endif
+
+#if REF_REGION_OFFSET
+        const Window &windowRL = pcSlice->getPPS()->getRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc));
+        Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth() - windowRL.getWindowLeftOffset() - windowRL.getWindowRightOffset();
+        Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight() - windowRL.getWindowTopOffset() - windowRL.getWindowBottomOffset();
+#else
         Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth();
         Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight();
@@ -1855,7 +2135,28 @@
         heightBL -= ( confBL.getWindowTopOffset() + confBL.getWindowBottomOffset() ) * TComSPS::getWinUnitY( chromaFormatIdc );
 #endif
+#endif
         Int widthEL   = pcPic->getPicYuvRec()->getWidth()  - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
         Int heightEL  = pcPic->getPicYuvRec()->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
 
+#if RESAMPLING_FIX
+#if REF_REGION_OFFSET
+        // conformance check: the values of RefLayerRegionWidthInSamplesY, RefLayerRegionHeightInSamplesY, ScaledRefRegionWidthInSamplesY and ScaledRefRegionHeightInSamplesY shall be greater than 0
+        assert(widthEL > 0 && heightEL > 0 && widthBL > 0 && widthEL > 0);
+
+        // conformance check: ScaledRefRegionWidthInSamplesY shall be greater or equal to RefLayerRegionWidthInSamplesY and ScaledRefRegionHeightInSamplesY shall be greater or equal to RefLayerRegionHeightInSamplesY
+        assert(widthEL >= widthBL && heightEL >= heightBL);
+
+#if R0209_GENERIC_PHASE
+        // 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.
+        Int phaseHorLuma   = pcSlice->getPPS()->getPhaseHorLuma(refLayerIdc);
+        Int phaseVerLuma   = pcSlice->getPPS()->getPhaseVerLuma(refLayerIdc);
+        Int phaseHorChroma = pcSlice->getPPS()->getPhaseHorChroma(refLayerIdc);
+        Int phaseVerChroma = pcSlice->getPPS()->getPhaseVerChroma(refLayerIdc);
+        assert( ( (widthEL  != widthBL)  || (phaseHorLuma == 0 && phaseHorChroma == 0) )
+             && ( (heightEL != heightBL) || (phaseVerLuma == 0 && phaseVerChroma == 0) ) );
+#endif
+#endif
+#endif
+
         g_mvScalingFactor[refLayerIdc][0] = widthEL  == widthBL  ? 4096 : Clip3(-4096, 4095, ((widthEL  << 8) + (widthBL  >> 1)) / widthBL);
         g_mvScalingFactor[refLayerIdc][1] = heightEL == heightBL ? 4096 : Clip3(-4096, 4095, ((heightEL << 8) + (heightBL >> 1)) / heightBL);
@@ -1866,6 +2167,16 @@
 #if Q0048_CGS_3D_ASYMLUT 
         TComPicYuv* pBaseColRec = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec();
-        if( pcSlice->getPPS()->getCGSFlag() )
-        {
+        if( pcSlice->getPPS()->getCGSFlag() 
+#if R0150_CGS_SIGNAL_CONSTRAINTS
+          && m_c3DAsymLUTPPS.isRefLayer( pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc) )
+#endif
+          )
+        {
+#if R0150_CGS_SIGNAL_CONSTRAINTS
+          assert( pcSlice->getBaseColPic( refLayerIdc )->getSlice( 0 )->getBitDepthY() == m_c3DAsymLUTPPS.getInputBitDepthY() );
+          assert( pcSlice->getBaseColPic( refLayerIdc )->getSlice( 0 )->getBitDepthC() == m_c3DAsymLUTPPS.getInputBitDepthC() );
+          assert( pcSlice->getBitDepthY() >= m_c3DAsymLUTPPS.getOutputBitDepthY() );
+          assert( pcSlice->getBitDepthY() >= m_c3DAsymLUTPPS.getOutputBitDepthC() );
+#endif
           if(!m_pColorMappedPic)
           {
@@ -1891,7 +2202,11 @@
 #else
 #if Q0048_CGS_3D_ASYMLUT 
-            m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc), pcSlice->getVPS()->getPhaseAlignFlag() );
-#else
-            m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL, pcSlice->getVPS()->getPhaseAlignFlag() );
+#if MOVE_SCALED_OFFSET_TO_PPS
+          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), pcSlice->getPPS()->getScaledRefLayerWindow(refLayerIdc), pcSlice->getVPS()->getPhaseAlignFlag() );
+#else
+          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc), pcSlice->getVPS()->getPhaseAlignFlag() );
+#endif
+#else
+          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL, pcSlice->getVPS()->getPhaseAlignFlag() );
 #endif
 #endif
@@ -1899,7 +2214,11 @@
 #if O0194_JOINT_US_BITSHIFT
 #if Q0048_CGS_3D_ASYMLUT 
-            m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL );
-#else
-            m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
+#if REF_REGION_OFFSET
+          m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL, altRL );
+#else
+          m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL );
+#endif
+#else
+          m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
 #endif
 #else
@@ -1928,19 +2247,11 @@
         UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i);
 #if AVC_BASE
+#if VPS_AVC_BL_FLAG_REMOVAL
+        if( pcSlice->getVPS()->getRefLayerId( m_layerId, refLayerIdc ) == 0 && m_parameterSetManagerDecoder.getActiveVPS()->getNonHEVCBaseLayerFlag() )
+#else
         if( pcSlice->getVPS()->getRefLayerId( m_layerId, refLayerIdc ) == 0 && m_parameterSetManagerDecoder.getActiveVPS()->getAvcBaseLayerFlag() )
+#endif
         {
           pcSlice->setBaseColPic ( refLayerIdc, *m_ppcTDecTop[0]->getListPic()->begin() );
-#if AVC_SYNTAX
-          TComPic* pBLPic = pcSlice->getBaseColPic(refLayerIdc);
-          if( pcSlice->getPOC() == 0 )
-          {
-            // initialize partition order.
-            UInt* piTmp = &g_auiZscanToRaster[0];
-            initZscanToRaster( pBLPic->getPicSym()->getMaxDepth() + 1, 1, 0, piTmp );
-            initRasterToZscan( pBLPic->getPicSym()->getMaxCUWidth(), pBLPic->getPicSym()->getMaxCUHeight(), pBLPic->getPicSym()->getMaxDepth() + 1 );
-          }      
-          pBLPic->getSlice( 0 )->initBaseLayerRPL( pcSlice );
-          pBLPic->readBLSyntax( m_ppcTDecTop[0]->getBLSyntaxFile(), SYNTAX_BYTES );
-#endif
         }
         else
@@ -1970,8 +2281,4 @@
 
 #if REF_IDX_MFM
-      if( pcSlice->getMFMEnabledFlag() )
-      {
-        pcSlice->setRefPOCListILP(m_ppcTDecTop[m_layerId]->m_cIlpPic, pcSlice->getBaseColPic());
-      }
       pcSlice->setRefPicList( m_cListPic, false, m_cIlpPic);
     }
@@ -2015,5 +2322,5 @@
       }
     }
-
+    
     if( m_layerId > 0 && !pcSlice->isIntra() && pcSlice->getEnableTMVPFlag() )
     {
@@ -2021,4 +2328,7 @@
 
       assert( refPic );
+#if R0226_SLICE_TMVP
+      assert ( refPic->getPicSym()->getSlice(0)->getAvailableForTMVPRefFlag() == true );
+#endif
 
       // It is a requirement of bitstream conformance when the collocated picture, used for temporal motion vector prediction, is an inter-layer reference picture, 
@@ -2100,4 +2410,8 @@
   //  Decode a picture
   m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic);
+
+#if P0297_VPS_POC_LSB_ALIGNED_FLAG
+  setFirstPicInLayerDecodedFlag(true);
+#endif
 
   m_bFirstSliceInPicture = false;
@@ -2115,8 +2429,8 @@
 }
 
+#if SVC_EXTENSION
 Void TDecTop::xDecodeSPS()
 {
   TComSPS* sps = new TComSPS();
-#if SVC_EXTENSION
   sps->setLayerId(m_layerId);
 #if SPS_DPB_PARAMS
@@ -2126,14 +2440,4 @@
 #endif
   m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
-#if Q0078_ADD_LAYER_SETS
-  // Store SPS for all layers
-  for (Int lId = 0; lId < m_numLayer; lId++)
-  {
-    if (m_ppcTDecTop[lId] != this)
-    {
-      m_ppcTDecTop[lId]->getParameterSetManager()->storePrefetchedSPS(sps);
-    }
-  }
-#endif
 #if !REPN_FORMAT_IN_VPS   // ILRP can only be initialized at activation  
   if(m_numLayer>0)
@@ -2142,8 +2446,4 @@
   }
 #endif
-#else //SVC_EXTENSION
-  m_cEntropyDecoder.decodeSPS( sps );
-  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
-#endif //SVC_EXTENSION
 }
 
@@ -2166,28 +2466,20 @@
     );
   m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
-#if Q0078_ADD_LAYER_SETS
-  // Store PPS for all layers
-  for (Int lId = 0; lId < m_numLayer; lId++)
-  {
-    if (m_ppcTDecTop[lId] != this)
-    {
-      m_ppcTDecTop[lId]->getParameterSetManager()->storePrefetchedPPS(pps);
-    }
-  }
-#endif
-
-  if( pps->getDependentSliceSegmentsEnabledFlag() )
-  {
-    Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1;
-    m_cSliceDecoder.initCtxMem(NumCtx);
-    for ( UInt st = 0; st < NumCtx; st++ )
-    {
-      TDecSbac* ctx = NULL;
-      ctx = new TDecSbac;
-      ctx->init( &m_cBinCABAC );
-      m_cSliceDecoder.setCtxMem( ctx, st );
-    }
-  }
 }
+#else
+Void TDecTop::xDecodeSPS()
+{
+  TComSPS* sps = new TComSPS();
+  m_cEntropyDecoder.decodeSPS( sps );
+  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
+}
+
+Void TDecTop::xDecodePPS()
+{
+  TComPPS* pps = new TComPPS();
+  m_cEntropyDecoder.decodePPS( pps );
+  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
+}
+#endif //SVC_EXTENSION
 
 Void TDecTop::xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType )
@@ -2217,4 +2509,5 @@
     {
       SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
+#if !R0247_SEI_ACTIVE
       m_parameterSetManagerDecoder.applyPrefetchedPS();
       assert(seiAps->activeSeqParameterSetId.size()>0);
@@ -2223,8 +2516,22 @@
         printf ("Warning SPS activation with Active parameter set SEI failed");
       }
-    }
-#if Q0074_SEI_COLOR_MAPPING
-    m_ColorMapping->setColorMapping( m_SEIs );
-#endif
+#else
+      getLayerDec(0)->m_parameterSetManagerDecoder.applyPrefetchedPS();
+      assert(seiAps->activeSeqParameterSetId.size()>0);
+      if( !getLayerDec(0)->m_parameterSetManagerDecoder.activateSPSWithSEI( seiAps->activeSeqParameterSetId[0] ) )
+      {
+        printf ("Warning SPS activation with Active parameter set SEI failed");
+      }
+      for (Int c=1 ; c <= seiAps->numSpsIdsMinus1; c++)
+      {
+        Int layerIdx = seiAps->layerSpsIdx[c];
+        getLayerDec(layerIdx)->m_parameterSetManagerDecoder.applyPrefetchedPS();
+        if( !getLayerDec(layerIdx)->m_parameterSetManagerDecoder.activateSPSWithSEI( seiAps->activeSeqParameterSetId[layerIdx] ) )
+        {
+          printf ("Warning SPS activation with Active parameter set SEI failed");
+        }
+      }
+#endif
+    }
   }
 #else
@@ -2287,5 +2594,9 @@
 #endif
 #if AVC_BASE
+#if VPS_AVC_BL_FLAG_REMOVAL
+      if( m_parameterSetManagerDecoder.getPrefetchedVPS(0)->getNonHEVCBaseLayerFlag() )
+#else
       if( m_parameterSetManagerDecoder.getPrefetchedVPS(0)->getAvcBaseLayerFlag() )
+#endif
       {
         if( !m_ppcTDecTop[0]->getBLReconFile()->good() )
@@ -2294,11 +2605,4 @@
           exit(EXIT_FAILURE);
         }        
-#if AVC_SYNTAX
-        if( !m_ppcTDecTop[0]->getBLSyntaxFile()->good() )
-        {
-          printf( "Base layer syntax input reading error\n" );
-          exit(EXIT_FAILURE);
-        }
-#endif
       }
       else
@@ -2748,308 +3052,20 @@
 }
 #endif
-
+#if POC_RESET_RESTRICTIONS
+Void TDecTop::resetPocRestrictionCheckParameters()
+{
+  TDecTop::m_checkPocRestrictionsForCurrAu       = false;
+  TDecTop::m_pocResetIdcOrCurrAu                 = -1;
+  TDecTop::m_baseLayerIdrFlag                    = false;
+  TDecTop::m_baseLayerPicPresentFlag             = false;
+  TDecTop::m_baseLayerIrapFlag                   = false;
+  TDecTop::m_nonBaseIdrPresentFlag               = false;
+  TDecTop::m_nonBaseIdrType                      = -1;
+  TDecTop::m_picNonIdrWithRadlPresentFlag        = false;
+  TDecTop::m_picNonIdrNoLpPresentFlag            = false;
+}
+#endif
 #endif //SVC_EXTENSION
 
-#if Q0074_SEI_COLOR_MAPPING
-TDecColorMapping::TDecColorMapping()
-{
-  m_pcColorMappingPic[0]   = NULL;
-  m_pcColorMappingPic[1]   = NULL;
-
-  m_colorMapCancelFlag  = true;
-
-  for( Int i=0 ; i<3 ; i++ )
-  {
-    m_lut1d_computed[i]             = false;
-    m_lut1d_input[i]                = NULL;
-    m_coded_input_pivot_value[i]    = NULL;
-    m_target_input_pivot_value[i]   = NULL;
-  }
-  for( Int i=0 ; i<3 ; i++ )
-  {
-    m_lut1d_output[i]               = NULL;
-    m_coded_output_pivot_value[i]   = NULL;
-    m_target_output_pivot_value[i]  = NULL;
-  }
-}
-
-TDecColorMapping::~TDecColorMapping()
-{
-  if ( m_pcColorMappingPic[0] )  delete m_pcColorMappingPic[0];
-  if ( m_pcColorMappingPic[1] )  delete m_pcColorMappingPic[1];
-
-  for( Int i=0 ; i<3 ; i++ )
-  {
-    if ( m_lut1d_input[i] )               delete  m_lut1d_input[i];
-    if ( m_coded_input_pivot_value[i] )   delete  m_coded_input_pivot_value[i];
-    if ( m_target_input_pivot_value[i] )  delete  m_target_input_pivot_value[i];
-  }
-  for( Int i=0 ; i<3 ; i++ )
-  {
-    if ( m_lut1d_output[i] )               delete  m_lut1d_output[i];
-    if ( m_coded_output_pivot_value[i] )   delete  m_coded_output_pivot_value[i];
-    if ( m_target_output_pivot_value[i] )  delete  m_target_output_pivot_value[i];
-  }
-}
-
-Void  TDecColorMapping::setColorMapping( SEIMessages m_SEIs )
-{
-  SEIMessages colorMappingInfo = getSeisByType(m_SEIs, SEI::COLOR_MAPPING_INFO) ;
-  SEIColorMappingInfo *seiColorMappingInfo = NULL;
-  if (colorMappingInfo.size() !=0)
-  {
-    seiColorMappingInfo = (SEIColorMappingInfo*)(*colorMappingInfo.begin());
-
-    m_colorMapId                              = seiColorMappingInfo->m_colorMapId;
-    m_colorMapCancelFlag                      = seiColorMappingInfo->m_colorMapCancelFlag;
-    if( !m_colorMapCancelFlag )
-    {
-      m_colorMapPersistenceFlag                 = seiColorMappingInfo->m_colorMapPersistenceFlag;
-      m_colorMap_video_signal_type_present_flag = seiColorMappingInfo->m_colorMap_video_signal_type_present_flag;
-      m_colorMap_video_full_range_flag          = seiColorMappingInfo->m_colorMap_video_full_range_flag;
-      m_colorMap_primaries                      = seiColorMappingInfo->m_colorMap_primaries;
-      m_colorMap_transfer_characteristics       = seiColorMappingInfo->m_colorMap_transfer_characteristics;
-      m_colorMap_matrix_coeffs                  = seiColorMappingInfo->m_colorMap_matrix_coeffs;
-      m_colorMapModelId                         = seiColorMappingInfo->m_colorMapModelId;
-
-      m_colour_map_coded_data_bit_depth         = seiColorMappingInfo->m_colour_map_coded_data_bit_depth;
-      m_colour_map_target_bit_depth             = seiColorMappingInfo->m_colour_map_target_bit_depth;
-
-      for( Int i=0 ; i<3 ; i++ )
-      {
-        m_num_input_pivots[i]                 = seiColorMappingInfo->m_num_input_pivots[i];
-        if ( m_coded_input_pivot_value[i] )   delete  m_coded_input_pivot_value[i];
-        if ( m_target_input_pivot_value[i] )  delete  m_target_input_pivot_value[i];
-        m_coded_input_pivot_value[i]          = new Int[ m_num_input_pivots[i] ];
-        m_target_input_pivot_value[i]         = new Int[ m_num_input_pivots[i] ];
-        for( Int j=0 ; j<m_num_input_pivots[i] ; j++ )
-        {
-          m_coded_input_pivot_value[i][j]     = seiColorMappingInfo->m_coded_input_pivot_value[i][j];
-          m_target_input_pivot_value[i][j]    = seiColorMappingInfo->m_target_input_pivot_value[i][j];
-        }
-      }
-
-      m_matrix_flag       = seiColorMappingInfo->m_matrix_flag;
-      m_log2_matrix_denom = m_matrix_flag ? (seiColorMappingInfo->m_log2_matrix_denom) : (0) ;
-      for( Int i=0 ; i<3 ; i++ )
-      {
-        for( Int j=0 ; j<3 ; j++ )
-        {
-          m_matrix_coef[i][j]  = seiColorMappingInfo->m_matrix_coef[i][j];
-        }
-      }
-
-      for( Int i=0 ; i<3 ; i++ )
-      {
-        m_num_output_pivots[i]                 = seiColorMappingInfo->m_num_output_pivots[i];
-        if ( m_coded_output_pivot_value[i] )   delete  m_coded_output_pivot_value[i];
-        if ( m_target_output_pivot_value[i] )  delete  m_target_output_pivot_value[i];
-        m_coded_output_pivot_value[i]          = new Int[ m_num_output_pivots[i] ];
-        m_target_output_pivot_value[i]         = new Int[ m_num_output_pivots[i] ];
-        for( Int j=0 ; j<m_num_output_pivots[i] ; j++ )
-        {
-          m_coded_output_pivot_value[i][j]     = seiColorMappingInfo->m_coded_output_pivot_value[i][j];
-          m_target_output_pivot_value[i][j]    = seiColorMappingInfo->m_target_output_pivot_value[i][j];
-        }
-      }
-
-      memset( m_lut1d_computed, 0, sizeof( m_lut1d_computed ) );
-    }
-  }
-
-}
-
-Void  TDecColorMapping::setColorMapping( Int bitDepth, Int iComp )
-{
-  if( !m_colorMapCancelFlag && !m_lut1d_computed[iComp] )
-  {
-
-    if ( m_lut1d_input[iComp] )   delete m_lut1d_input[iComp];
-    if ( m_lut1d_output[iComp] )  delete m_lut1d_output[iComp];
-
-    m_lut1d_input[iComp]  = new Int[ 1 << bitDepth ];
-    m_lut1d_output[iComp] = new Int[ 1 << bitDepth ];
-
-    Int iShift      = (m_colour_map_coded_data_bit_depth >= bitDepth) ? (m_colour_map_coded_data_bit_depth - bitDepth) : (0);
-    Int iShiftPivot = (m_colour_map_coded_data_bit_depth >= bitDepth) ? (0) : (bitDepth - m_colour_map_coded_data_bit_depth);
-
-    for( Int k=0 ; k<(1<<bitDepth) ; k++ )
-    {
-      Int iSample = k << iShift ;
-      if( m_num_input_pivots[iComp] > 1 )
-      {
-        for( Int iPivot=0 ; iPivot<m_num_input_pivots[iComp] ; iPivot++ )
-        {
-          Int iCodedPrev  = m_coded_input_pivot_value[iComp][iPivot]     << iShiftPivot;
-          Int iCodedNext  = m_coded_input_pivot_value[iComp][iPivot+1]   << iShiftPivot;
-          Int iTargetPrev = m_target_input_pivot_value[iComp][iPivot]    << iShiftPivot;
-          Int iTargetNext = m_target_input_pivot_value[iComp][iPivot+1]  << iShiftPivot;
-          if ( iCodedPrev <= iSample && iSample < iCodedNext )
-          {
-            Float fInterpol = (Float)( (iCodedNext - iSample)*iTargetPrev + (iSample - iCodedPrev)*iTargetNext ) / (Float)(iCodedNext - iCodedPrev) ;
-            m_lut1d_input[iComp][k]  = (Int)( 0.5 + fInterpol );
-            iPivot = m_num_input_pivots[iComp]; // stop
-          }
-        }
-      }
-      else
-      {
-        m_lut1d_input[iComp][k]  = k;
-      }
-    }
-
-    iShift      = ( (m_colour_map_coded_data_bit_depth >= bitDepth) ? (m_colour_map_coded_data_bit_depth - bitDepth) : (0) );
-    Int iOffset = iShift ? (1 << (iShift - 1)) : (0) ;
-    iShiftPivot = (m_colour_map_target_bit_depth >= bitDepth) ? (0) : (bitDepth - m_colour_map_target_bit_depth) ;
-    for( Int k=0 ; k<(1<<bitDepth) ; k++ )
-    {
-      Int iSample = k << iShift;
-      if ( m_num_output_pivots[iComp]>1 )
-      {
-        for( Int iPivot=0 ; iPivot<m_num_output_pivots[iComp] ; iPivot++ )
-        {
-          Int iCodedPrev  = m_coded_output_pivot_value[iComp][iPivot]     << iShiftPivot;
-          Int iCodedNext  = m_coded_output_pivot_value[iComp][iPivot+1]   << iShiftPivot;
-          Int iTargetPrev = m_target_output_pivot_value[iComp][iPivot]    << iShiftPivot;
-          Int iTargetNext = m_target_output_pivot_value[iComp][iPivot+1]  << iShiftPivot;
-          if ( iCodedPrev <= iSample && iSample < iCodedNext )
-          {
-            Float fInterpol =  (Float)( (iCodedNext - iSample)*iTargetPrev + (iSample - iCodedPrev)*iTargetNext ) / (Float)(iCodedNext - iCodedPrev) ;
-            m_lut1d_output[iComp][k]  = ( (Int)(0.5 + fInterpol) + iOffset ) >> iShift ;
-            iPivot = m_num_output_pivots[iComp]; // stop
-          }
-        }
-      }
-      else
-      {
-        m_lut1d_output[iComp][k]  = k;
-      }
-    }
-
-    m_lut1d_computed[iComp] = true;
-  }
-
-}
-
-TComPicYuv* TDecColorMapping::getColorMapping( TComPicYuv* pPicYuvRec, Int iTop, Int curlayerId )
-{
-  if( !m_colorMapCancelFlag )
-  {
-    if( !m_pcColorMappingPic[iTop] )
-    {
-      m_pcColorMappingPic[iTop] = new TComPicYuv;
-#if SVC_EXTENSION
-      m_pcColorMappingPic[iTop]->create( pPicYuvRec->getWidth(), pPicYuvRec->getHeight(), pPicYuvRec->getChromaFormat(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
-#else
-      m_pcColorMappingPic[iTop]->create( pPicYuvRec->getWidth(), pPicYuvRec->getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
-#endif
-    }
-
-    Int iHeight   = pPicYuvRec->getHeight();
-    Int iWidth    = pPicYuvRec->getWidth();
-    Int iStride   = pPicYuvRec->getStride();
-    Int iCStride  = pPicYuvRec->getCStride();
-
-    Pel* Lum0   = pPicYuvRec->getLumaAddr();
-    Pel* Cb0    = pPicYuvRec->getCbAddr();
-    Pel* Cr0    = pPicYuvRec->getCrAddr();
-    Pel* Lum1   = m_pcColorMappingPic[iTop]->getLumaAddr();
-    Pel* Cb1    = m_pcColorMappingPic[iTop]->getCbAddr();
-    Pel* Cr1    = m_pcColorMappingPic[iTop]->getCrAddr();
-
-#if SVC_EXTENSION
-    Int bitDepthY = g_bitDepthYLayer[curlayerId];
-    Int bitDepthC = g_bitDepthCLayer[curlayerId];
-
-    assert( g_bitDepthY == bitDepthY );
-    assert( g_bitDepthC == bitDepthC );
-#else
-    Int bitDepthY = g_bitDepthY;
-    Int bitDepthC = g_bitDepthC;
-#endif
-
-    Int iYShift = (m_colour_map_target_bit_depth >= bitDepthY) ? (m_colour_map_target_bit_depth - bitDepthY) : (0) ;
-    Int iCShift = (m_colour_map_target_bit_depth >= bitDepthC) ? (m_colour_map_target_bit_depth - bitDepthC) : (0) ;
-    Int offsetY = (1 << (m_log2_matrix_denom+iYShift - 1));
-    Int offsetC = (1 << (m_log2_matrix_denom+iCShift - 1));
-
-    Int   cShift  = 1 ;
-
-    //Pel*  LumPrev0 = Lum0;
-    for( Int y = 0; y < iHeight ; y++ )
-    {
-      Bool  bDoChroma = (y % 2);
-      for( Int x = 0; x < iWidth ; x++ )
-      {
-        Int s1Y = m_lut1d_input[0][ Lum0[x]   ];
-        Int s1U = m_lut1d_input[1][ Cb0[x>>1] ];
-        Int s1V = m_lut1d_input[2][ Cr0[x>>1] ];
-
-        Int s2Y, s2U, s2V;
-        if( m_matrix_flag )
-        {
-          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 );
-          //s2Y = ClipBD( s2Y , bitDepthY );
-          s2Y = ClipY( s2Y );
-          Lum1[x]   = m_lut1d_output[0][ s2Y ];
-        }
-        else
-        {
-          s1Y       = ( s1Y + offsetY ) >> iYShift ;
-          //s1Y = ClipBD( s1Y , bitDepthY );
-          s1Y = ClipY( s1Y );
-          Lum1[x]   = m_lut1d_output[0][ s1Y ];
-        }
-
-        if( bDoChroma && (x%2) )
-        {
-          if( m_matrix_flag )
-          {
-            //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 ; 
-            //s1Y = m_lut1d_input[0][ (Lum0[x] + Lum0[x+1] + LumPrev0[x] + LumPrev0[x+1] + 2)>>2 ] ; 
-            s1Y = m_lut1d_input[0][ Lum0[x] ];
-
-            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 ) ;
-            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 ) ;
-            //s2U = ClipBD( s2U , bitDepthC );
-            //s2V = ClipBD( s2V , bitDepthC );
-            s2U = ClipC( s2U );
-            s2V = ClipC( s2V );
-            Cb1[x>>cShift] = m_lut1d_output[1][ s2U ];
-            Cr1[x>>cShift] = m_lut1d_output[2][ s2V ];
-          }
-          else
-          {
-            s1U       = ( s1U + offsetC ) >> iCShift ;
-            s1V       = ( s1V + offsetC ) >> iCShift ;
-            //s1U = ClipBD( s1U , bitDepthC );
-            //s1V = ClipBD( s1V , bitDepthC );
-            s1U = ClipC( s1U );
-            s1V = ClipC( s1V );
-            Cb1[x>>cShift] = m_lut1d_output[1][ s1U ];
-            Cr1[x>>cShift] = m_lut1d_output[2][ s1V ];
-          }
-        }
-
-      }
-
-      //LumPrev0 = Lum0;
-      Lum0  += iStride;
-      Lum1  += iStride;
-      if( bDoChroma )
-      {
-        Cb0 += iCStride;
-        Cr0 += iCStride;
-        Cb1 += iCStride;
-        Cr1 += iCStride;
-      }
-    }
-
-    return m_pcColorMappingPic[iTop];
-  }
-
-  return pPicYuvRec; 
-}
-#endif
 
 //! \}
Index: trunk/source/Lib/TLibDecoder/TDecTop.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecTop.h	(revision 815)
+++ trunk/source/Lib/TLibDecoder/TDecTop.h	(revision 906)
@@ -64,49 +64,4 @@
 // ====================================================================================================================
 
-#if Q0074_SEI_COLOR_MAPPING
-class TDecColorMapping
-{
-  Int   m_colorMapId;
-  Bool  m_colorMapCancelFlag;
-  Bool  m_colorMapPersistenceFlag;
-  Bool  m_colorMap_video_signal_type_present_flag;
-  Bool  m_colorMap_video_full_range_flag;
-  Int   m_colorMap_primaries;
-  Int   m_colorMap_transfer_characteristics;
-  Int   m_colorMap_matrix_coeffs;
-  Int   m_colorMapModelId;
-
-  Int   m_colour_map_coded_data_bit_depth;
-  Int   m_colour_map_target_bit_depth;
-
-  Int   m_num_input_pivots[3];
-  Int*  m_coded_input_pivot_value[3];
-  Int*  m_target_input_pivot_value[3];
-  
-  Bool  m_matrix_flag;
-  Int   m_log2_matrix_denom;
-  Int   m_matrix_coef[3][3];
-
-  Int   m_num_output_pivots[3];
-  Int*  m_coded_output_pivot_value[3];
-  Int*  m_target_output_pivot_value[3];
-
-  Bool  m_lut1d_computed[3];
-  Int*  m_lut1d_input[3];
-  Int*  m_lut1d_output[3];
-  TComPicYuv* m_pcColorMappingPic[2];
-
-public:
-  TDecColorMapping();
-  ~TDecColorMapping();
-
-  Bool        getColorMappingFlag()                     { return(!m_colorMapCancelFlag);};
-
-  Void        setColorMapping( SEIMessages m_SEIs );
-  Void        setColorMapping( Int bitDepthY, Int bitDepthC );
-  TComPicYuv* getColorMapping( TComPicYuv* pPicYuvRec, Int iTop=0, Int curlayerId=0 );
-};// END CLASS DEFINITION TDecColorMapping
-#endif
-
 /// decoder class
 class TDecTop
@@ -165,5 +120,4 @@
   Bool                    m_isLastNALWasEos;
 #endif
-
 #if SVC_EXTENSION
   static UInt             m_prevPOC;        // POC of the previous slice
@@ -173,4 +127,8 @@
   UInt                    m_numLayer;
   TDecTop**               m_ppcTDecTop;
+#if P0297_VPS_POC_LSB_ALIGNED_FLAG
+  Bool                    m_pocResettingFlag;
+  Bool                    m_pocDecrementedInDPBFlag;
+#endif
 #if AVC_BASE
   fstream*                m_pBLReconFile;
@@ -195,8 +153,4 @@
   CommonDecoderParams*    m_commonDecoderParams;
 #endif
-#if AVC_SYNTAX || SYNTAX_OUTPUT
-  fstream*               m_pBLSyntaxFile;
-#endif
-
 #if NO_CLRAS_OUTPUT_FLAG  
   Bool                    m_noClrasOutputFlag;
@@ -214,6 +168,18 @@
 #endif
 public:
-#if Q0074_SEI_COLOR_MAPPING
-  TDecColorMapping* m_ColorMapping;
+#if POC_RESET_RESTRICTIONS
+  static Bool                    m_checkPocRestrictionsForCurrAu;
+  static Int                     m_pocResetIdcOrCurrAu;
+  static Bool                    m_baseLayerIdrFlag;
+  static Bool                    m_baseLayerPicPresentFlag;
+  static Bool                    m_baseLayerIrapFlag;
+  static Bool                    m_nonBaseIdrPresentFlag;
+  static Int                     m_nonBaseIdrType;
+  static Bool                    m_picNonIdrWithRadlPresentFlag;
+  static Bool                    m_picNonIdrNoLpPresentFlag;
+#endif
+#if POC_RESET_VALUE_RESTRICTION
+  static Int                     m_crossLayerPocResetPeriodId;
+  static Int                     m_crossLayerPocResetIdc;
 #endif
 
@@ -225,4 +191,7 @@
 
   void setDecodedPictureHashSEIEnabled(Int enabled) { m_cGopDecoder.setDecodedPictureHashSEIEnabled(enabled); }
+#if Q0074_COLOUR_REMAPPING_SEI
+  void setColourRemappingInfoSEIEnabled(Bool enabled)  { m_cGopDecoder.setColourRemappingInfoSEIEnabled(enabled); }
+#endif
 
   Void  init();
@@ -327,8 +296,5 @@
 #endif
 #endif //SVC_EXTENSION
-#if AVC_SYNTAX || SYNTAX_OUTPUT
-  Void      setBLSyntaxFile( fstream* pFile ) { m_pBLSyntaxFile = pFile; }
-  fstream* getBLSyntaxFile() { return m_pBLSyntaxFile; }
-#endif
+
 protected:
   Void  xGetNewPicBuffer  (TComSlice* pcSlice, TComPic*& rpcPic);
@@ -365,7 +331,11 @@
   Void initAsymLut(TComSlice *pcSlice);
 #endif
+#if POC_RESET_RESTRICTIONS
+  Void resetPocRestrictionCheckParameters();
+#endif
 };// END CLASS DEFINITION TDecTop
 
 
+
 //! \}
 
