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


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

merge SHM-dev

Location:
trunk
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/source

  • trunk/source/Lib/TLibEncoder/SEIwrite.cpp

    r815 r906  
    9292    break;
    9393#endif
    94 #if Q0074_SEI_COLOR_MAPPING
    95   case SEI::COLOR_MAPPING_INFO:
    96     fprintf( g_hTrace, "=========== Color Mapping Info SEI message ===========\n");
     94#if Q0074_COLOUR_REMAPPING_SEI
     95  case SEI::COLOUR_REMAPPING_INFO:
     96    fprintf( g_hTrace, "=========== Colour Remapping Information SEI message ===========\n");
    9797    break;
    9898#endif
     
    126126    fprintf( g_hTrace, "=========== Bitstream parition initial arrival time SEI message ===========\n");
    127127    break;
     128#if !REMOVE_BSP_HRD_SEI
    128129  case SEI::BSP_HRD:
    129130    fprintf( g_hTrace, "=========== Bitstream parition HRD parameters SEI message ===========\n");
    130131    break;
     132#endif
    131133#endif
    132134#if Q0078_ADD_LAYER_SETS
     
    147149
    148150#if O0164_MULTI_LAYER_HRD
     151#if VPS_VUI_BSP_HRD_PARAMS
     152void SEIWriter::xWriteSEIpayloadData(TComBitIf& bs, const SEI& sei, TComVPS *vps, TComSPS *sps, const SEIScalableNesting* nestingSeiPtr, const SEIBspNesting* bspNestingSeiPtr)
     153#else
    149154void SEIWriter::xWriteSEIpayloadData(TComBitIf& bs, const SEI& sei, TComVPS *vps, TComSPS *sps, const SEIScalableNesting& nestingSei, const SEIBspNesting& bspNestingSei)
     155#endif
    150156#else
    151157void SEIWriter::xWriteSEIpayloadData(TComBitIf& bs, const SEI& sei, TComSPS *sps)
    152158#endif
    153159{
     160#if VPS_VUI_BSP_HRD_PARAMS
     161  SEIScalableNesting nestingSei;
     162  SEIBspNesting      bspNestingSei;
     163  if( nestingSeiPtr )
     164  {
     165    nestingSei = *nestingSeiPtr;
     166  }
     167  if( bspNestingSeiPtr )
     168  {
     169    bspNestingSei = *bspNestingSeiPtr;
     170  }
     171#endif
    154172  switch (sei.payloadType())
    155173  {
     
    160178    xWriteSEIActiveParameterSets(*static_cast<const SEIActiveParameterSets*>(& sei));
    161179    break;
     180  case SEI::DECODED_PICTURE_HASH:
     181    xWriteSEIDecodedPictureHash(*static_cast<const SEIDecodedPictureHash*>(&sei));
     182    break;
     183#if VPS_VUI_BSP_HRD_PARAMS
     184  case SEI::DECODING_UNIT_INFO:
     185    xWriteSEIDecodingUnitInfo(*static_cast<const SEIDecodingUnitInfo*>(& sei), sps, nestingSeiPtr, bspNestingSeiPtr, vps);
     186    break;
     187  case SEI::BUFFERING_PERIOD:
     188    xWriteSEIBufferingPeriod(*static_cast<const SEIBufferingPeriod*>(&sei), sps, nestingSeiPtr, bspNestingSeiPtr, vps);
     189    break;
     190  case SEI::PICTURE_TIMING:
     191    xWriteSEIPictureTiming(*static_cast<const SEIPictureTiming*>(&sei), sps, nestingSeiPtr, bspNestingSeiPtr, vps);
     192    break;
     193#else
    162194  case SEI::DECODING_UNIT_INFO:
    163195    xWriteSEIDecodingUnitInfo(*static_cast<const SEIDecodingUnitInfo*>(& sei), sps);
    164196    break;
    165   case SEI::DECODED_PICTURE_HASH:
    166     xWriteSEIDecodedPictureHash(*static_cast<const SEIDecodedPictureHash*>(&sei));
    167     break;
    168197  case SEI::BUFFERING_PERIOD:
    169198    xWriteSEIBufferingPeriod(*static_cast<const SEIBufferingPeriod*>(&sei), sps);
     
    172201    xWriteSEIPictureTiming(*static_cast<const SEIPictureTiming*>(&sei), sps);
    173202    break;
     203#endif
    174204  case SEI::RECOVERY_POINT:
    175205    xWriteSEIRecoveryPoint(*static_cast<const SEIRecoveryPoint*>(&sei));
     
    195225    break;
    196226#endif
    197 #if Q0074_SEI_COLOR_MAPPING
    198   case SEI::COLOR_MAPPING_INFO:
    199     xWriteSEIColorMappingInfo(*static_cast<const SEIColorMappingInfo*>(&sei));
     227#if Q0074_COLOUR_REMAPPING_SEI
     228  case SEI::COLOUR_REMAPPING_INFO:
     229    xWriteSEIColourRemappingInfo(*static_cast<const SEIColourRemappingInfo*>(&sei));
    200230    break;
    201231#endif
     
    233263     xWriteSEIBspInitialArrivalTime(*static_cast<const SEIBspInitialArrivalTime*>(&sei), vps, sps, nestingSei, bspNestingSei);
    234264     break;
     265#if !REMOVE_BSP_HRD_SEI
    235266   case SEI::BSP_HRD:
    236267     xWriteSEIBspHrd(*static_cast<const SEIBspHrd*>(&sei), sps, nestingSei);
    237268     break;
     269#endif
    238270#endif
    239271#if Q0078_ADD_LAYER_SETS
     
    283315#endif
    284316#if O0164_MULTI_LAYER_HRD
     317#if VPS_VUI_BSP_HRD_PARAMS
     318  xWriteSEIpayloadData(bs_count, sei, vps, sps, nestingSei, bspNestingSei);
     319#else
    285320  xWriteSEIpayloadData(bs_count, sei, vps, sps, *nestingSei, *bspNestingSei);
     321#endif
    286322#else
    287323  xWriteSEIpayloadData(bs_count, sei, sps);
     
    322358
    323359#if O0164_MULTI_LAYER_HRD
     360#if VPS_VUI_BSP_HRD_PARAMS
     361  xWriteSEIpayloadData(bs, sei, vps, sps, nestingSei, bspNestingSei);
     362#else
    324363  xWriteSEIpayloadData(bs, sei, vps, sps, *nestingSei, *bspNestingSei);
     364#endif
    325365#else
    326366  xWriteSEIpayloadData(bs, sei, sps);
     
    390430    WRITE_UVLC(sei.activeSeqParameterSetId[i], "active_seq_parameter_set_id");
    391431  }
    392   xWriteByteAlign();
    393 }
    394 
     432#if R0247_SEI_ACTIVE
     433  for (Int i = 1; i < sei.activeSeqParameterSetId.size(); i++)
     434  {
     435    WRITE_UVLC(sei.layerSpsIdx[i], "layer_sps_idx");
     436  }
     437#endif
     438  xWriteByteAlign();
     439}
     440
     441#if VPS_VUI_BSP_HRD_PARAMS
     442Void SEIWriter::xWriteSEIDecodingUnitInfo(const SEIDecodingUnitInfo& sei, TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei, TComVPS *vps)
     443#else
    395444Void SEIWriter::xWriteSEIDecodingUnitInfo(const SEIDecodingUnitInfo& sei, TComSPS *sps)
    396 {
     445#endif
     446{
     447#if VPS_VUI_BSP_HRD_PARAMS
     448  TComHRD *hrd;
     449  if( bspNestingSei )   // If DU info SEI contained inside a BSP nesting SEI message
     450  {
     451    assert( nestingSei );
     452    Int psIdx = bspNestingSei->m_seiPartitioningSchemeIdx;
     453    Int seiOlsIdx = bspNestingSei->m_seiOlsIdx;
     454    Int maxTemporalId = nestingSei->m_nestingMaxTemporalIdPlus1[0] - 1;
     455    Int maxValues = vps->getNumBspSchedulesMinus1(seiOlsIdx, psIdx, maxTemporalId) + 1;
     456    std::vector<Int> hrdIdx(maxValues, 0);
     457    std::vector<TComHRD *> hrdVec;
     458    std::vector<Int> syntaxElemLen(maxValues, 0);
     459    for(Int i = 0; i < maxValues; i++)
     460    {
     461      hrdIdx[i] = vps->getBspHrdIdx( seiOlsIdx, psIdx, maxTemporalId, i, bspNestingSei->m_bspIdx);
     462      hrdVec.push_back(vps->getBspHrd(hrdIdx[i]));
     463   
     464      syntaxElemLen[i] = hrdVec[i]->getInitialCpbRemovalDelayLengthMinus1() + 1;
     465      if ( !(hrdVec[i]->getNalHrdParametersPresentFlag() || hrdVec[i]->getVclHrdParametersPresentFlag()) )
     466      {
     467        assert( syntaxElemLen[i] == 24 ); // Default of value init_cpb_removal_delay_length_minus1 is 23
     468      }
     469      if( i > 0 )
     470      {
     471        assert( hrdVec[i]->getSubPicCpbParamsPresentFlag()    == hrdVec[i-1]->getSubPicCpbParamsPresentFlag() );
     472        assert( hrdVec[i]->getSubPicCpbParamsInPicTimingSEIFlag()   == hrdVec[i-1]->getSubPicCpbParamsInPicTimingSEIFlag() );
     473        assert( hrdVec[i]->getDpbOutputDelayDuLengthMinus1()  == hrdVec[i-1]->getDpbOutputDelayDuLengthMinus1() );
     474        // To be done: Check CpbDpbDelaysPresentFlag
     475      }
     476    }
     477    hrd = hrdVec[0];
     478  }
     479  else
     480  {
     481    TComVUI *vui = sps->getVuiParameters();
     482    hrd = vui->getHrdParameters();
     483  }
     484#else
    397485  TComVUI *vui = sps->getVuiParameters();
     486  TComHrd *hrd = vui->getHrdParameters();
     487#endif
    398488  WRITE_UVLC(sei.m_decodingUnitIdx, "decoding_unit_idx");
    399   if(vui->getHrdParameters()->getSubPicCpbParamsInPicTimingSEIFlag())
    400   {
    401     WRITE_CODE( sei.m_duSptCpbRemovalDelay, (vui->getHrdParameters()->getDuCpbRemovalDelayLengthMinus1() + 1), "du_spt_cpb_removal_delay");
     489  if(hrd->getSubPicCpbParamsInPicTimingSEIFlag())
     490  {
     491    WRITE_CODE( sei.m_duSptCpbRemovalDelay, (hrd->getDuCpbRemovalDelayLengthMinus1() + 1), "du_spt_cpb_removal_delay");
    402492  }
    403493  WRITE_FLAG( sei.m_dpbOutputDuDelayPresentFlag, "dpb_output_du_delay_present_flag");
    404494  if(sei.m_dpbOutputDuDelayPresentFlag)
    405495  {
    406     WRITE_CODE(sei.m_picSptDpbOutputDuDelay, vui->getHrdParameters()->getDpbOutputDelayDuLengthMinus1() + 1, "pic_spt_dpb_output_du_delay");
    407   }
    408   xWriteByteAlign();
    409 }
    410 
     496    WRITE_CODE(sei.m_picSptDpbOutputDuDelay,hrd->getDpbOutputDelayDuLengthMinus1() + 1, "pic_spt_dpb_output_du_delay");
     497  }
     498  xWriteByteAlign();
     499}
     500
     501#if VPS_VUI_BSP_HRD_PARAMS
     502Void SEIWriter::xWriteSEIBufferingPeriod(const SEIBufferingPeriod& sei, TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei, TComVPS *vps)
     503#else
    411504Void SEIWriter::xWriteSEIBufferingPeriod(const SEIBufferingPeriod& sei, TComSPS *sps)
     505#endif
    412506{
    413507  Int i, nalOrVcl;
     508#if VPS_VUI_BSP_HRD_PARAMS
     509  TComHRD *hrd;
     510  if( bspNestingSei )   // If BP SEI contained inside a BSP nesting SEI message
     511  {
     512    assert( nestingSei );
     513    Int psIdx = bspNestingSei->m_seiPartitioningSchemeIdx;
     514    Int seiOlsIdx = bspNestingSei->m_seiOlsIdx;
     515    Int maxTemporalId = nestingSei->m_nestingMaxTemporalIdPlus1[0] - 1;
     516    Int maxValues = vps->getNumBspSchedulesMinus1(seiOlsIdx, psIdx, maxTemporalId) + 1;
     517    std::vector<Int> hrdIdx(maxValues, 0);
     518    std::vector<TComHRD *> hrdVec;
     519    std::vector<Int> syntaxElemLen(maxValues, 0);
     520    for(i = 0; i < maxValues; i++)
     521    {
     522      hrdIdx[i] = vps->getBspHrdIdx( seiOlsIdx, psIdx, maxTemporalId, i, bspNestingSei->m_bspIdx);
     523      hrdVec.push_back(vps->getBspHrd(hrdIdx[i]));
     524   
     525      syntaxElemLen[i] = hrdVec[i]->getInitialCpbRemovalDelayLengthMinus1() + 1;
     526      if ( !(hrdVec[i]->getNalHrdParametersPresentFlag() || hrdVec[i]->getVclHrdParametersPresentFlag()) )
     527      {
     528        assert( syntaxElemLen[i] == 24 ); // Default of value init_cpb_removal_delay_length_minus1 is 23
     529      }
     530      if( i > 0 )
     531      {
     532        assert( hrdVec[i]->getCpbRemovalDelayLengthMinus1()   == hrdVec[i-1]->getCpbRemovalDelayLengthMinus1() );
     533        assert( hrdVec[i]->getDpbOutputDelayDuLengthMinus1()  == hrdVec[i-1]->getDpbOutputDelayDuLengthMinus1() );
     534        assert( hrdVec[i]->getSubPicCpbParamsPresentFlag()    == hrdVec[i-1]->getSubPicCpbParamsPresentFlag() );
     535      }
     536    }
     537    hrd = hrdVec[i];
     538  }
     539  else
     540  {
     541    TComVUI *vui = sps->getVuiParameters();
     542    hrd = vui->getHrdParameters();
     543  }
     544  // To be done: When contained in an BSP HRD SEI message, the hrd structure is to be chosen differently.
     545#else
    414546  TComVUI *vui = sps->getVuiParameters();
    415547  TComHRD *hrd = vui->getHrdParameters();
     548#endif
    416549
    417550  WRITE_UVLC( sei.m_bpSeqParameterSetId, "bp_seq_parameter_set_id" );
     
    452585  xWriteByteAlign();
    453586}
     587#if VPS_VUI_BSP_HRD_PARAMS
     588Void SEIWriter::xWriteSEIPictureTiming(const SEIPictureTiming& sei,  TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei, TComVPS *vps)
     589#else
    454590Void SEIWriter::xWriteSEIPictureTiming(const SEIPictureTiming& sei,  TComSPS *sps)
     591#endif
    455592{
    456593  Int i;
     594#if VPS_VUI_BSP_HRD_PARAMS
     595  TComHRD *hrd;   
     596  TComVUI *vui = sps->getVuiParameters();
     597  if( bspNestingSei )   // If BP SEI contained inside a BSP nesting SEI message
     598  {
     599    assert( nestingSei );
     600    Int psIdx = bspNestingSei->m_seiPartitioningSchemeIdx;
     601    Int seiOlsIdx = bspNestingSei->m_seiOlsIdx;
     602    Int maxTemporalId = nestingSei->m_nestingMaxTemporalIdPlus1[0] - 1;
     603    Int maxValues = vps->getNumBspSchedulesMinus1(seiOlsIdx, psIdx, maxTemporalId) + 1;
     604    std::vector<Int> hrdIdx(maxValues, 0);
     605    std::vector<TComHRD *> hrdVec;
     606    std::vector<Int> syntaxElemLen(maxValues, 0);
     607    for(i = 0; i < maxValues; i++)
     608    {
     609      hrdIdx[i] = vps->getBspHrdIdx( seiOlsIdx, psIdx, maxTemporalId, i, bspNestingSei->m_bspIdx);
     610      hrdVec.push_back(vps->getBspHrd(hrdIdx[i]));
     611   
     612      syntaxElemLen[i] = hrdVec[i]->getInitialCpbRemovalDelayLengthMinus1() + 1;
     613      if ( !(hrdVec[i]->getNalHrdParametersPresentFlag() || hrdVec[i]->getVclHrdParametersPresentFlag()) )
     614      {
     615        assert( syntaxElemLen[i] == 24 ); // Default of value init_cpb_removal_delay_length_minus1 is 23
     616      }
     617      if( i > 0 )
     618      {
     619        assert( hrdVec[i]->getSubPicCpbParamsPresentFlag()    == hrdVec[i-1]->getSubPicCpbParamsPresentFlag() );
     620        assert( hrdVec[i]->getSubPicCpbParamsInPicTimingSEIFlag()   == hrdVec[i-1]->getSubPicCpbParamsInPicTimingSEIFlag() );
     621        assert( hrdVec[i]->getCpbRemovalDelayLengthMinus1()  == hrdVec[i-1]->getCpbRemovalDelayLengthMinus1() );
     622        assert( hrdVec[i]->getDpbOutputDelayLengthMinus1()  == hrdVec[i-1]->getDpbOutputDelayLengthMinus1() );
     623        assert( hrdVec[i]->getDpbOutputDelayDuLengthMinus1()  == hrdVec[i-1]->getDpbOutputDelayDuLengthMinus1() );
     624        assert( hrdVec[i]->getDuCpbRemovalDelayLengthMinus1()  == hrdVec[i-1]->getDuCpbRemovalDelayLengthMinus1() );
     625        // To be done: Check CpbDpbDelaysPresentFlag
     626      }
     627    }
     628    hrd = hrdVec[0];
     629  }
     630  else
     631  {
     632    hrd = vui->getHrdParameters();
     633  }
     634  // To be done: When contained in an BSP HRD SEI message, the hrd structure is to be chosen differently.
     635#else
    457636  TComVUI *vui = sps->getVuiParameters();
    458637  TComHRD *hrd = vui->getHrdParameters();
    459 
    460   if( vui->getFrameFieldInfoPresentFlag() )
     638#endif
     639
     640  if( vui->getFrameFieldInfoPresentFlag() ) // To be done: Check whether this is the correct invocation of vui when PT SEI contained in BSP nesting SEI
    461641  {
    462642    WRITE_CODE( sei.m_picStruct, 4,              "pic_struct" );
     
    634814}
    635815#endif
    636 #if Q0074_SEI_COLOR_MAPPING
    637 Void SEIWriter::xWriteSEIColorMappingInfo(const SEIColorMappingInfo& sei)
    638 {
    639   WRITE_UVLC( sei.m_colorMapId,                    "colour_map_id" );
    640   WRITE_FLAG( sei.m_colorMapCancelFlag,            "colour_map_cancel_flag" );
    641   if( !sei.m_colorMapCancelFlag )
    642   {
    643     WRITE_FLAG( sei.m_colorMapPersistenceFlag,            "colour_map_persistence_flag" );
    644     WRITE_FLAG( sei.m_colorMap_video_signal_type_present_flag,            "colour_map_video_signal_type_present_flag" );
    645     if ( sei.m_colorMap_video_signal_type_present_flag )
    646     {
    647       WRITE_FLAG( sei.m_colorMap_video_full_range_flag,       "colour_map_video_full_range_flag" );
    648       WRITE_CODE( sei.m_colorMap_primaries,                 8,      "colour_map_primaries" );
    649       WRITE_CODE( sei.m_colorMap_transfer_characteristics,  8,      "colour_map_transfer_characteristics" );
    650       WRITE_CODE( sei.m_colorMap_matrix_coeffs,             8,      "colour_map_matrix_coeffs" );
    651     }
    652   }
    653 
    654   WRITE_CODE( sei.m_colour_map_coded_data_bit_depth,  5,  "colour_map_coded_data_bit_depth" );
    655   WRITE_CODE( sei.m_colour_map_target_bit_depth,  5,      "colour_map_target_bit_depth" );
    656   WRITE_UVLC( sei.m_colorMapModelId,                      "colour_map_model_id" );
    657 
    658   assert( sei.m_colorMapModelId == 0 );
    659  
    660   for( Int i=0 ; i<3 ; i++ )
    661   {
    662     WRITE_CODE( sei.m_num_input_pivots[i] - 1,         8,      "num_input_pivots_minus1[i]" );
    663     for( Int j=0 ; j<sei.m_num_input_pivots[i] ; j++ )
    664     {
    665       WRITE_CODE( sei.m_coded_input_pivot_value[i][j],  (( sei.m_colour_map_coded_data_bit_depth + 7 ) >> 3 ) << 3, "coded_input_pivot_value[i][j]" );
    666       WRITE_CODE( sei.m_target_input_pivot_value[i][j], (( sei.m_colour_map_coded_data_bit_depth + 7 ) >> 3 ) << 3, "target_input_pivot_value[i][j]" );
    667     }
    668   }
    669 
    670   WRITE_FLAG( sei.m_matrix_flag,            "matrix_flag" );
    671   if( sei.m_matrix_flag )
    672   {
    673     WRITE_CODE( sei.m_log2_matrix_denom, 4, "log2_matrix_denom" );
    674     for( Int i=0 ; i<3 ; i++ )
    675     {
    676       for( Int j=0 ; j<3 ; j++ )
    677       {
    678         WRITE_SVLC( sei.m_matrix_coef[i][j],  "matrix_coef[i][j]" );
    679       }
    680     }
    681   }
    682 
    683   for( Int i=0 ; i<3 ; i++ )
    684   {
    685     WRITE_CODE( sei.m_num_output_pivots[i] - 1,         8,      "num_output_pivots_minus1[i]" );
    686     for( Int j=0 ; j<sei.m_num_output_pivots[i] ; j++ )
    687     {
    688       WRITE_CODE( sei.m_coded_output_pivot_value[i][j],  (( sei.m_colour_map_coded_data_bit_depth + 7 ) >> 3 ) << 3, "coded_output_pivot_value[i][j]" );
    689       WRITE_CODE( sei.m_target_output_pivot_value[i][j], (( sei.m_colour_map_coded_data_bit_depth + 7 ) >> 3 ) << 3, "target_output_pivot_value[i][j]" );
    690     }
    691   }
    692 
     816#if Q0074_COLOUR_REMAPPING_SEI
     817Void SEIWriter::xWriteSEIColourRemappingInfo(const SEIColourRemappingInfo& sei)
     818{
     819  WRITE_UVLC( sei.m_colourRemapId,                             "colour_remap_id" );
     820  WRITE_FLAG( sei.m_colourRemapCancelFlag,                     "colour_remap_cancel_flag" );
     821  if( !sei.m_colourRemapCancelFlag )
     822  {
     823    WRITE_FLAG( sei.m_colourRemapPersistenceFlag,              "colour_remap_persistence_flag" );
     824    WRITE_FLAG( sei.m_colourRemapVideoSignalInfoPresentFlag,   "colour_remap_video_signal_info_present_flag" );
     825    if ( sei.m_colourRemapVideoSignalInfoPresentFlag )
     826    {
     827      WRITE_FLAG( sei.m_colourRemapFullRangeFlag,              "colour_remap_full_range_flag" );
     828      WRITE_CODE( sei.m_colourRemapPrimaries,               8, "colour_remap_primaries" );
     829      WRITE_CODE( sei.m_colourRemapTransferFunction,        8, "colour_remap_transfer_function" );
     830      WRITE_CODE( sei.m_colourRemapMatrixCoefficients,      8, "colour_remap_matrix_coefficients" );
     831    }
     832    WRITE_CODE( sei.m_colourRemapInputBitDepth,             8, "colour_remap_input_bit_depth" );
     833    WRITE_CODE( sei.m_colourRemapBitDepth,                  8, "colour_remap_bit_depth" );
     834    for( Int c=0 ; c<3 ; c++ )
     835    {
     836      WRITE_CODE( sei.m_preLutNumValMinus1[c],              8, "pre_lut_num_val_minus1[c]" );
     837      if( sei.m_preLutNumValMinus1[c]>0 )
     838        for( Int i=0 ; i<=sei.m_preLutNumValMinus1[c] ; i++ )
     839        {
     840          WRITE_CODE( sei.m_preLutCodedValue[c][i], (( sei.m_colourRemapInputBitDepth + 7 ) >> 3 ) << 3, "pre_lut_coded_value[c][i]" );
     841          WRITE_CODE( sei.m_preLutTargetValue[c][i], (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, "pre_lut_target_value[c][i]" );
     842        }
     843    }
     844    WRITE_FLAG( sei.m_colourRemapMatrixPresentFlag,            "colour_remap_matrix_present_flag" );
     845    if( sei.m_colourRemapMatrixPresentFlag )
     846    {
     847      WRITE_CODE( sei.m_log2MatrixDenom,                    4, "log2_matrix_denom" );
     848      for( Int c=0 ; c<3 ; c++ )
     849        for( Int i=0 ; i<3 ; i++ )
     850          WRITE_SVLC( sei.m_colourRemapCoeffs[c][i],           "colour_remap_coeffs[c][i]" );
     851    }
     852
     853    for( Int c=0 ; c<3 ; c++ )
     854    {
     855      WRITE_CODE( sei.m_postLutNumValMinus1[c],             8, "m_postLutNumValMinus1[c]" );
     856      if( sei.m_postLutNumValMinus1[c]>0 )
     857        for( Int i=0 ; i<=sei.m_postLutNumValMinus1[c] ; i++ )
     858        {
     859          WRITE_CODE( sei.m_postLutCodedValue[c][i], (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, "post_lut_coded_value[c][i]" );       
     860          WRITE_CODE( sei.m_postLutTargetValue[c][i], (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, "post_lut_target_value[c][i]" );
     861        }
     862    }
     863  }
    693864  xWriteByteAlign();
    694865}
     
    753924  {
    754925    WRITE_FLAG( sei.m_defaultOpFlag,                 "default_op_flag"               );
    755     WRITE_UVLC( sei.m_nestingNumOpsMinus1,           "nesting_num_ops"               );
     926    WRITE_UVLC( sei.m_nestingNumOpsMinus1,           "nesting_num_ops_minus1"        );
    756927    for (UInt i = (sei.m_defaultOpFlag ? 1 : 0); i <= sei.m_nestingNumOpsMinus1; i++)
    757928    {
    758       WRITE_CODE( sei.m_nestingNoOpMaxTemporalIdPlus1, 3, "nesting_no_op_max_temporal_id" );
    759       WRITE_CODE( sei.m_nestingMaxTemporalIdPlus1[i], 3,  "nesting_max_temporal_id"       );
     929      WRITE_CODE( sei.m_nestingMaxTemporalIdPlus1[i], 3,  "nesting_max_temporal_id_plus1" );
    760930      WRITE_UVLC( sei.m_nestingOpIdx[i],                  "nesting_op_idx"                );
    761931    }
     
    766936    if (!sei.m_allLayersFlag)
    767937    {
    768       WRITE_CODE( sei.m_nestingNoOpMaxTemporalIdPlus1, 3, "nesting_no_op_max_temporal_id" );
    769       WRITE_UVLC( sei.m_nestingNumLayersMinus1,           "nesting_num_layers"            );
     938      WRITE_CODE( sei.m_nestingNoOpMaxTemporalIdPlus1, 3, "nesting_no_op_max_temporal_id_plus1" );
     939      WRITE_UVLC( sei.m_nestingNumLayersMinus1,           "nesting_num_layers"                  );
    770940      for (UInt i = 0; i <= sei.m_nestingNumLayersMinus1; i++)
    771941      {
     
    9011071    WRITE_FLAG( 0, "bsp_nesting_zero_bit" );
    9021072  }
    903 
     1073#if NESTING_SEI_EXTENSIBILITY
     1074  assert( sei.m_nestedSEIs.size() <= MAX_SEIS_IN_BSP_NESTING );
     1075  WRITE_UVLC( sei.m_nestedSEIs.size(), "num_seis_in_bsp_minus1" );
     1076#endif
    9041077  // write nested SEI messages
    9051078  for (SEIMessages::const_iterator it = sei.m_nestedSEIs.begin(); it != sei.m_nestedSEIs.end(); it++)
     
    9131086  assert(vps->getVpsVuiPresentFlag());
    9141087
     1088#if VPS_VUI_BSP_HRD_PARAMS
     1089  Int psIdx = bspNestingSei.m_seiPartitioningSchemeIdx;
     1090  Int seiOlsIdx = bspNestingSei.m_seiOlsIdx;
     1091  Int maxTemporalId = nestingSei.m_nestingMaxTemporalIdPlus1[0] - 1;
     1092  Int maxValues = vps->getNumBspSchedulesMinus1(seiOlsIdx, psIdx, maxTemporalId) + 1;
     1093  std::vector<Int> hrdIdx(maxValues, 0);
     1094  std::vector<TComHRD *> hrdVec;
     1095  std::vector<Int> syntaxElemLen(maxValues, 0);
     1096  for(Int i = 0; i < maxValues; i++)
     1097  {
     1098    hrdIdx[i] = vps->getBspHrdIdx( seiOlsIdx, psIdx, maxTemporalId, i, bspNestingSei.m_bspIdx);
     1099    hrdVec.push_back(vps->getBspHrd(hrdIdx[i]));
     1100   
     1101    syntaxElemLen[i] = hrdVec[i]->getInitialCpbRemovalDelayLengthMinus1() + 1;
     1102    if ( !(hrdVec[i]->getNalHrdParametersPresentFlag() || hrdVec[i]->getVclHrdParametersPresentFlag()) )
     1103    {
     1104      assert( syntaxElemLen[i] == 24 ); // Default of value init_cpb_removal_delay_length_minus1 is 23
     1105    }
     1106    if( i > 0 )
     1107    {
     1108      assert( hrdVec[i]->getNalHrdParametersPresentFlag() == hrdVec[i-1]->getNalHrdParametersPresentFlag() );
     1109      assert( hrdVec[i]->getVclHrdParametersPresentFlag() == hrdVec[i-1]->getVclHrdParametersPresentFlag() );
     1110    }
     1111  }
     1112  if (hrdVec[0]->getNalHrdParametersPresentFlag())
     1113  {
     1114    for(UInt i = 0; i < maxValues; i++)
     1115    {
     1116      WRITE_CODE( sei.m_nalInitialArrivalDelay[i], syntaxElemLen[i], "nal_initial_arrival_delay[i]" );
     1117    }
     1118  }
     1119  if( hrdVec[0]->getVclHrdParametersPresentFlag() )
     1120  {
     1121    for(UInt i = 0; i < maxValues; i++)
     1122    {
     1123      WRITE_CODE( sei.m_vclInitialArrivalDelay[i], syntaxElemLen[i], "vcl_initial_arrival_delay[i]" );
     1124    }
     1125  }
     1126#else
    9151127  UInt schedCombCnt = vps->getNumBspSchedCombinations(nestingSei.m_nestingOpIdx[0]);
    9161128  UInt len;
     
    9441156    }
    9451157  }
     1158#if BSP_INIT_ARRIVAL_SEI
     1159  if( hrd->getVclHrdParametersPresentFlag() )
     1160#else
    9461161  else
     1162#endif
    9471163  {
    9481164    for(UInt i = 0; i < schedCombCnt; i++)
     
    9511167    }
    9521168  }
    953 }
    954 
     1169#endif
     1170}
     1171
     1172#if !REMOVE_BSP_HRD_SEI
    9551173Void SEIWriter::xWriteSEIBspHrd(const SEIBspHrd &sei, TComSPS *sps, const SEIScalableNesting &nestingSei)
    9561174{
     
    10041222  }
    10051223}
     1224#endif
    10061225
    10071226Void SEIWriter::xCodeHrdParameters( TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1 )
  • trunk/source/Lib/TLibEncoder/SEIwrite.h

    r815 r906  
    5555protected:
    5656#if O0164_MULTI_LAYER_HRD
     57#if VPS_VUI_BSP_HRD_PARAMS
     58  Void xWriteSEIpayloadData(TComBitIf& bs, const SEI& sei, TComVPS *vps, TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei);
     59#else
    5760  Void xWriteSEIpayloadData(TComBitIf& bs, const SEI& sei, TComVPS *vps, TComSPS *sps, const SEIScalableNesting& nestingSei, const SEIBspNesting& bspNestingSei);
     61#endif
    5862#else
    5963  Void xWriteSEIpayloadData(TComBitIf& bs, const SEI& sei, TComSPS *sps);
     
    6165  Void xWriteSEIuserDataUnregistered(const SEIuserDataUnregistered &sei);
    6266  Void xWriteSEIActiveParameterSets(const SEIActiveParameterSets& sei);
     67  Void xWriteSEIDecodedPictureHash(const SEIDecodedPictureHash& sei);
     68#if VPS_VUI_BSP_HRD_PARAMS
     69  Void xWriteSEIDecodingUnitInfo(const SEIDecodingUnitInfo& sei, TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei, TComVPS *vps);
     70  Void xWriteSEIBufferingPeriod(const SEIBufferingPeriod& sei, TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei, TComVPS *vps);
     71  Void xWriteSEIPictureTiming(const SEIPictureTiming& sei, TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei, TComVPS *vps);
     72#else
    6373  Void xWriteSEIDecodingUnitInfo(const SEIDecodingUnitInfo& sei, TComSPS *sps);
    64   Void xWriteSEIDecodedPictureHash(const SEIDecodedPictureHash& sei);
    6574  Void xWriteSEIBufferingPeriod(const SEIBufferingPeriod& sei, TComSPS *sps);
    6675  Void xWriteSEIPictureTiming(const SEIPictureTiming& sei, TComSPS *sps);
     76#endif
    6777  TComSPS *m_pSPS;
    6878  Void xWriteSEIRecoveryPoint(const SEIRecoveryPoint& sei);
     
    7585  Void xWriteSEIKneeFunctionInfo(const SEIKneeFunctionInfo &sei);
    7686#endif
    77 #if Q0074_SEI_COLOR_MAPPING
    78   Void xWriteSEIColorMappingInfo(const SEIColorMappingInfo& sei);
     87#if Q0074_COLOUR_REMAPPING_SEI
     88  Void xWriteSEIColourRemappingInfo(const SEIColourRemappingInfo& sei);
    7989#endif
    8090  Void xWriteSEISOPDescription(const SEISOPDescription& sei);
     
    104114  Void xWriteSEIBspNesting(TComBitIf& bs, const SEIBspNesting &sei, TComVPS *vps, TComSPS *sps, const SEIScalableNesting &nestingSei);
    105115  Void xWriteSEIBspInitialArrivalTime(const SEIBspInitialArrivalTime &sei, TComVPS *vps, TComSPS *sps, const SEIScalableNesting &nestingSei, const SEIBspNesting &bspNestingSei);
     116#if !REMOVE_BSP_HRD_SEI
    106117  Void xWriteSEIBspHrd(const SEIBspHrd &sei, TComSPS *sps, const SEIScalableNesting &nestingSei);
     118#endif
    107119  Void xCodeHrdParameters( TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1 );
    108120#endif
  • trunk/source/Lib/TLibEncoder/TEnc3DAsymLUT.cpp

    r815 r906  
    1414  m_pColorInfoC = NULL;
    1515  m_pEncCuboid = NULL;
     16
    1617  m_pBestEncCuboid = NULL;
     18#if R0151_CGS_3D_ASYMLUT_IMPROVE
     19  m_nAccuFrameBit = 0;
     20  m_nAccuFrameCGSBit = 0;
     21  m_nPrevFrameCGSPartNumLog2 = 0;
     22#else
    1723  memset( m_nPrevFrameBit , 0 , sizeof( m_nPrevFrameBit ) );
    1824  memset( m_nPrevFrameCGSBit , 0 , sizeof( m_nPrevFrameCGSBit ) );
    1925  memset( m_nPrevFrameCGSPartNumLog2 , 0 , sizeof( m_nPrevFrameCGSPartNumLog2 ) );
    2026  memset( m_nPrevFrameOverWritePPS , 0 , sizeof( m_nPrevFrameOverWritePPS ) );
     27#endif
    2128  m_dTotalFrameBit = 0;
    2229  m_nTotalCGSBit = 0;
    2330  m_nPPSBit = 0;
    2431  m_pDsOrigPic = NULL;
     32#if R0179_ENC_OPT_3DLUT_SIZE
     33  m_pMaxColorInfo = NULL;
     34  m_pMaxColorInfoC = NULL;
     35
     36 
     37  // fixed m_dDistFactor
     38  Double dTmpFactor[3];   
     39  dTmpFactor[I_SLICE] = 1.0;
     40  dTmpFactor[P_SLICE] = 4./3.;
     41  dTmpFactor[B_SLICE] = 1.5;
     42  for( Int iSliceType = 0; iSliceType < 3; iSliceType++)
     43  {
     44    for(Int iLayer = 0; iLayer < MAX_TLAYER; iLayer++)
     45    {
     46      m_dDistFactor[iSliceType][iLayer] = dTmpFactor[iSliceType]*(Double)(1<<iLayer);     
     47    }
     48  }
     49  // initialization with approximate number of bits to code the LUT
     50  m_nNumLUTBits[0][0] = 200; // 1x1x1
     51  m_nNumLUTBits[1][0] = 400; // 2x1x1 
     52  m_nNumLUTBits[1][1] = 1500; // 2x2x2 
     53  m_nNumLUTBits[2][0] = 800; // 4x1x1
     54  m_nNumLUTBits[2][1] = 3200; // 4x2x2 
     55  m_nNumLUTBits[2][2] = 8500; // 4x4x4 
     56  m_nNumLUTBits[3][0] = 1200; // 8x1x1
     57  m_nNumLUTBits[3][1] = 4500; // 8x2x2 
     58  m_nNumLUTBits[3][2] = 10000; // 8x4x4 
     59  m_nNumLUTBits[3][3] = 12000; // 8x8x8
     60#endif
    2561}
    2662
     
    3268  }
    3369
    34   TCom3DAsymLUT::create( nMaxOctantDepth , nInputBitDepth , nInputBitDepthC, nOutputBitDepth , nOutputBitDepthC, nMaxYPartNumLog2 );
     70  TCom3DAsymLUT::create( nMaxOctantDepth , nInputBitDepth , nInputBitDepthC, nOutputBitDepth , nOutputBitDepthC, nMaxYPartNumLog2
     71#if R0151_CGS_3D_ASYMLUT_IMPROVE
     72    , 1 << ( nInputBitDepthC - 1 ) , 1 << ( nInputBitDepthC - 1 )
     73#endif
     74    );
    3575  xAllocate3DArray( m_pColorInfo , xGetYSize() , xGetUSize() , xGetVSize() );
    3676  xAllocate3DArray( m_pColorInfoC , xGetYSize() , xGetUSize() , xGetVSize() );
    3777  xAllocate3DArray( m_pEncCuboid , xGetYSize() , xGetUSize() , xGetVSize() );
    3878  xAllocate3DArray( m_pBestEncCuboid , xGetYSize() , xGetUSize() , xGetVSize() );
     79#if R0179_ENC_OPT_3DLUT_SIZE
     80  xAllocate3DArray( m_pMaxColorInfo , xGetYSize() , xGetUSize() , xGetVSize() );
     81  xAllocate3DArray( m_pMaxColorInfoC , xGetYSize() , xGetUSize() , xGetVSize() );
     82
     83  m_pEncCavlc = new TEncCavlc;
     84  m_pBitstreamRedirect = new TComOutputBitstream;
     85  m_pEncCavlc->setBitstream(m_pBitstreamRedirect);
     86#endif
    3987}
    4088
     
    4593  xFree3DArray( m_pEncCuboid );
    4694  xFree3DArray( m_pBestEncCuboid );
     95#if R0179_ENC_OPT_3DLUT_SIZE
     96  xFree3DArray( m_pMaxColorInfo );
     97  xFree3DArray( m_pMaxColorInfoC );
     98  delete m_pBitstreamRedirect;
     99  delete m_pEncCavlc;
     100#endif
    47101  TCom3DAsymLUT::destroy();
    48102}
     
    58112}
    59113
     114#if R0151_CGS_3D_ASYMLUT_IMPROVE
     115Double TEnc3DAsymLUT::xxDeriveVertexPerColor( Double N , Double Ys , Double Yy , Double Yu , Double Yv , Double ys , Double us , Double vs , Double yy , Double yu , Double yv , Double uu , Double uv , Double vv , Double YY ,
     116  Pel & rP0 , Pel & rP1 , Pel & rP3 , Pel & rP7 , Int nResQuantBit )
     117{
     118  Int nInitP0 = rP0;
     119  Int nInitP1 = rP1;
     120  Int nInitP3 = rP3;
     121  Int nInitP7 = rP7;
     122
     123  const Int nOne = xGetNormCoeffOne();
     124  Double dNorm = (N * yy * vv * uu - N * yy * uv * uv - N * yv * yv * uu - N * vv * yu * yu + 2 * N * yv * uv * yu - yy * vs * vs * uu + 2 * yy * vs * uv * us - yy * vv * us * us - 2 * vs * uv * yu * ys + uv * uv * ys * ys + vs * vs * yu * yu - 2 * yv * vs * us * yu + 2 * yv * vs * ys * uu - 2 * yv * uv * us * ys + 2 * vv * yu * ys * us - vv * uu * ys * ys + yv * yv * us * us);
     125  if( N > 16 && dNorm != 0 )
     126  {
     127    Double dInitA = (-N * uu * yv * Yv + N * uu * Yy * vv - N * Yy * uv * uv + N * yv * uv * Yu - N * yu * Yu * vv + N * yu * uv * Yv + yu * us * Ys * vv - vs * ys * uv * Yu - yu * vs * us * Yv - yv * uv * us * Ys - yv * vs * us * Yu - yu * uv * vs * Ys - ys * us * uv * Yv + ys * us * Yu * vv + 2 * Yy * vs * uv * us + uu * yv * vs * Ys - uu * ys * Ys * vv + uu * vs * ys * Yv + ys * Ys * uv * uv - Yy * vv * us * us + yu * Yu * vs * vs + yv * Yv * us * us - uu * Yy * vs * vs) / dNorm;
     128    Double dInitB = (N * yy * Yu * vv - N * yy * uv * Yv - N * Yu * yv * yv - N * yu * Yy * vv + N * uv * yv * Yy + N * yv * yu * Yv - yy * us * Ys * vv + yy * uv * vs * Ys - yy * Yu * vs * vs + yy * vs * us * Yv - uv * vs * ys * Yy - yv * yu * vs * Ys + yu * Yy * vs * vs + yu * ys * Ys * vv - uv * yv * ys * Ys + 2 * Yu * yv * vs * ys + us * ys * Yy * vv - vs * ys * yu * Yv + uv * ys * ys * Yv + us * Ys * yv * yv - Yu * ys * ys * vv - yv * ys * us * Yv - vs * us * yv * Yy) / dNorm;
     129    Double dInitC = -(-N * yy * Yv * uu + N * yy * uv * Yu - N * yv * yu * Yu - N * uv * yu * Yy + N * Yv * yu * yu + N * yv * Yy * uu - yy * uv * us * Ys + yy * Yv * us * us + yy * vs * Ys * uu - yy * vs * us * Yu + yv * ys * us * Yu - vs * Ys * yu * yu - yv * ys * Ys * uu + vs * us * yu * Yy + vs * ys * yu * Yu - uv * Yu * ys * ys + Yv * uu * ys * ys - yv * Yy * us * us - 2 * Yv * yu * ys * us - vs * ys * Yy * uu + uv * us * ys * Yy + uv * yu * ys * Ys + yv * yu * us * Ys) / dNorm;
     130    nInitP0 = ( Int )( dInitA * nOne + 0.5 ) >> nResQuantBit << nResQuantBit;
     131    nInitP1 = ( Int )( dInitB * nOne + 0.5 ) >> nResQuantBit << nResQuantBit;
     132    nInitP3 = ( Int )( dInitC * nOne + 0.5 ) >> nResQuantBit << nResQuantBit;
     133  }
     134
     135  Int nMin = - ( 1 << ( m_nLUTBitDepth - 1 ) );
     136  Int nMax = - nMin - ( 1 << nResQuantBit  );
     137  Int nMask = ( 1 << nResQuantBit ) - 1;
     138
     139  Double dMinError = MAX_DOUBLE;
     140  Int nTestRange = 2;
     141  Int nStepSize = 1 << nResQuantBit;
     142  for( Int i = - nTestRange ; i <= nTestRange ; i++ )
     143  {
     144    for( Int j = - nTestRange ; j <= nTestRange ; j++ )
     145    {
     146      for( Int k = - nTestRange ; k <= nTestRange ; k++ )
     147      {
     148        Int nTestP0 = Clip3( nMin , nMax , nInitP0 + i * nStepSize );
     149        Int nTestP1 = Clip3( nMin , nMax , nInitP1 + j * nStepSize );
     150        Int nTestP3 = Clip3( nMin , nMax , nInitP3 + k * nStepSize );
     151        Double a = 1.0 * nTestP0 / nOne;
     152        Double b = 1.0 * nTestP1 / nOne;
     153        Double c = 1.0 * nTestP3 / nOne;
     154        Double d = ( Ys - a * ys - b * us - c * vs ) / N;
     155        nInitP7 = ( ( Int )d ) >> nResQuantBit << nResQuantBit;
     156        for( Int m = 0 ; m < 2 ; m++ )
     157        {
     158          Int nTestP7 = Clip3( nMin , nMax , nInitP7 + m * nStepSize );
     159          Double dError = xxCalEstDist( N , Ys , Yy , Yu , Yv , ys , us , vs , yy , yu , yv , uu , uv , vv , YY , a , b , c , nTestP7 );
     160          if( dError < dMinError )
     161          {
     162            dMinError = dError;
     163            rP0 = ( Pel )nTestP0;
     164            rP1 = ( Pel )nTestP1;
     165            rP3 = ( Pel )nTestP3;
     166            rP7 = ( Pel )nTestP7;
     167          }
     168        }
     169      }
     170    }
     171  }
     172  assert( !( rP0 & nMask ) && !( rP1 & nMask ) && !( rP3 & nMask ) && !( rP7 & nMask ) );
     173
     174  return( dMinError );
     175}
     176#else
    60177Double TEnc3DAsymLUT::xxDeriveVertexPerColor( Double N , Double Ys , Double Yy , Double Yu , Double Yv , Double ys , Double us , Double vs , Double yy , Double yu , Double yv , Double uu , Double uv , Double vv , Double YY ,
    61178  Int y0 , Int u0 , Int v0 , Int nLengthY , Int nLengthUV ,
     
    134251  return( dMinError );
    135252}
    136 
     253#endif
     254
     255#if R0151_CGS_3D_ASYMLUT_IMPROVE
     256Double TEnc3DAsymLUT::estimateDistWithCur3DAsymLUT( TComPic * pCurPic , UInt refLayerIdc )
     257{
     258  xxCollectData( pCurPic , refLayerIdc );
     259
     260  Double dErrorLuma = 0 , dErrorChroma = 0;
     261  Int nYSize = 1 << ( getCurOctantDepth() + getCurYPartNumLog2() );
     262  Int nUVSize = 1 << getCurOctantDepth();
     263  for( Int yIdx = 0 ; yIdx < nYSize ; yIdx++ )
     264  {
     265    for( Int uIdx = 0 ; uIdx < nUVSize ; uIdx++ )
     266    {
     267      for( Int vIdx = 0 ; vIdx < nUVSize ; vIdx++ )
     268      {
     269        SColorInfo & rCuboidColorInfo = m_pColorInfo[yIdx][uIdx][vIdx];
     270        SColorInfo & rCuboidColorInfoC = m_pColorInfoC[yIdx][uIdx][vIdx];
     271        SCuboid & rCuboid = xGetCuboid( yIdx , uIdx , vIdx );
     272        if( rCuboidColorInfo.N > 0 )
     273        {
     274          dErrorLuma += xxCalEstDist( rCuboidColorInfo.N , rCuboidColorInfo.Ys , rCuboidColorInfo.Yy , rCuboidColorInfo.Yu , rCuboidColorInfo.Yv , rCuboidColorInfo.ys , rCuboidColorInfo.us , rCuboidColorInfo.vs , rCuboidColorInfo.yy , rCuboidColorInfo.yu , rCuboidColorInfo.yv , rCuboidColorInfo.uu , rCuboidColorInfo.uv , rCuboidColorInfo.vv , rCuboidColorInfo.YY ,
     275            rCuboid.P[0].Y , rCuboid.P[1].Y , rCuboid.P[2].Y , rCuboid.P[3].Y );
     276        }
     277        if( rCuboidColorInfoC.N > 0 )
     278        {
     279          dErrorChroma += xxCalEstDist( rCuboidColorInfoC.N , rCuboidColorInfoC.Us , rCuboidColorInfoC.Uy , rCuboidColorInfoC.Uu , rCuboidColorInfoC.Uv , rCuboidColorInfoC.ys , rCuboidColorInfoC.us , rCuboidColorInfoC.vs , rCuboidColorInfoC.yy , rCuboidColorInfoC.yu , rCuboidColorInfoC.yv , rCuboidColorInfoC.uu , rCuboidColorInfoC.uv , rCuboidColorInfoC.vv , rCuboidColorInfoC.UU ,
     280            rCuboid.P[0].U , rCuboid.P[1].U , rCuboid.P[2].U , rCuboid.P[3].U );
     281          dErrorChroma += xxCalEstDist( rCuboidColorInfoC.N , rCuboidColorInfoC.Vs , rCuboidColorInfoC.Vy , rCuboidColorInfoC.Vu , rCuboidColorInfoC.Vv , rCuboidColorInfoC.ys , rCuboidColorInfoC.us , rCuboidColorInfoC.vs , rCuboidColorInfoC.yy , rCuboidColorInfoC.yu , rCuboidColorInfoC.yv , rCuboidColorInfoC.uu , rCuboidColorInfoC.uv , rCuboidColorInfoC.vv , rCuboidColorInfoC.VV ,
     282            rCuboid.P[0].V , rCuboid.P[1].V , rCuboid.P[2].V , rCuboid.P[3].V );
     283        }
     284      }
     285    }
     286  }
     287
     288  return( dErrorLuma + dErrorChroma);
     289}
     290#else
    137291Double TEnc3DAsymLUT::estimateDistWithCur3DAsymLUT( TComPic * pCurPic , UInt refLayerIdc )
    138292{
     
    174328  return( dErrorLuma + dErrorChroma);
    175329}
    176 
     330#endif
     331
     332#if R0151_CGS_3D_ASYMLUT_IMPROVE
     333#if R0179_ENC_OPT_3DLUT_SIZE
     334Double TEnc3DAsymLUT::derive3DAsymLUT( TComSlice * pSlice , TComPic * pCurPic , UInt refLayerIdc , TEncCfg * pCfg , Bool bSignalPPS , Bool bElRapSliceTypeB, Double dFrameLambda )
     335{
     336  m_nLUTBitDepth = pCfg->getCGSLUTBit();
     337
     338  Int nBestAdaptCThresholdU = 1 << ( getInputBitDepthC() - 1 );
     339  Int nBestAdaptCThresholdV = 1 << ( getInputBitDepthC() - 1 );
     340  Int nAdaptCThresholdU, nAdaptCThresholdV;
     341
     342  Int nTmpLutBits[MAX_Y_SIZE][MAX_C_SIZE] ;
     343  memset(nTmpLutBits, 0, sizeof(nTmpLutBits));
     344
     345  SLUTSize sMaxLutSize; 
     346
     347  // collect stats for the most partitions
     348  Int nCurYPartNumLog2 = 0 , nCurOctantDepth = 0;
     349  Int nMaxPartNumLog2 = xGetMaxPartNumLog2();
     350
     351  xxMapPartNum2DepthYPart( nMaxPartNumLog2 , nCurOctantDepth , nCurYPartNumLog2 );
     352  xUpdatePartitioning( nCurOctantDepth , nCurYPartNumLog2, nBestAdaptCThresholdU, nBestAdaptCThresholdV );
     353  xxCollectData( pCurPic , refLayerIdc );
     354  xxCopyColorInfo(m_pMaxColorInfo, m_pColorInfo, m_pMaxColorInfoC, m_pColorInfoC);
     355 
     356  sMaxLutSize.iCPartNumLog2 = nCurOctantDepth;
     357  sMaxLutSize.iYPartNumLog2 = nCurOctantDepth + nCurYPartNumLog2;
     358
     359  m_pBitstreamRedirect->clear();
     360
     361  // find the best partition based on RD cost
     362  Int i;
     363  Double dMinCost, dCurCost;
     364
     365  Int iBestLUTSizeIdx = 0;   
     366  Int nBestResQuanBit = 0;
     367  Double dCurError, dMinError;
     368  Int iNumBitsCurSize;
     369  Int iNumBitsCurSizeSave = m_pEncCavlc->getNumberOfWrittenBits();
     370  Double dDistFactor = getDistFactor(pSlice->getSliceType(), pSlice->getDepth());
     371
     372  // check all LUT sizes
     373  xxGetAllLutSizes(pSlice); 
     374  if (m_nTotalLutSizes == 0) // return if no valid size is found, LUT will not be updated
     375  {
     376    nCurOctantDepth = sMaxLutSize.iCPartNumLog2;
     377    nCurYPartNumLog2 = sMaxLutSize.iYPartNumLog2-nCurOctantDepth;
     378    xUpdatePartitioning( nCurOctantDepth , nCurYPartNumLog2, nBestAdaptCThresholdU, nBestAdaptCThresholdV );
     379    return MAX_DOUBLE;
     380  }
     381
     382  dMinCost = MAX_DOUBLE; dMinError = MAX_DOUBLE;
     383  for (i = 0; i < m_nTotalLutSizes; i++)
     384  {
     385    // add up the stats
     386    nCurOctantDepth = m_sLutSizes[i].iCPartNumLog2;
     387    nCurYPartNumLog2 = m_sLutSizes[i].iYPartNumLog2-nCurOctantDepth;
     388    xUpdatePartitioning( nCurOctantDepth , nCurYPartNumLog2, nBestAdaptCThresholdU, nBestAdaptCThresholdV );
     389    xxConsolidateData( &m_sLutSizes[i], &sMaxLutSize );
     390 
     391    dCurError = xxDeriveVertexes(nBestResQuanBit, m_pEncCuboid);
     392
     393    setResQuantBit( nBestResQuanBit );
     394    xSaveCuboids( m_pEncCuboid );
     395    m_pEncCavlc->xCode3DAsymLUT( this );
     396    iNumBitsCurSize = m_pEncCavlc->getNumberOfWrittenBits();
     397    dCurCost = dCurError/dDistFactor + dFrameLambda*(Double)(iNumBitsCurSize-iNumBitsCurSizeSave); 
     398    nTmpLutBits[m_sLutSizes[i].iYPartNumLog2][m_sLutSizes[i].iCPartNumLog2] = iNumBitsCurSize-iNumBitsCurSizeSave; // store LUT size
     399    iNumBitsCurSizeSave = iNumBitsCurSize;
     400    if(dCurCost < dMinCost )
     401    {
     402      SCuboid *** tmp = m_pBestEncCuboid;
     403      m_pBestEncCuboid = m_pEncCuboid;
     404      m_pEncCuboid = tmp;
     405      dMinCost = dCurCost;
     406      dMinError = dCurError;
     407      iBestLUTSizeIdx = i;
     408    }
     409  }
     410
     411  nCurOctantDepth = m_sLutSizes[iBestLUTSizeIdx].iCPartNumLog2;
     412  nCurYPartNumLog2 = m_sLutSizes[iBestLUTSizeIdx].iYPartNumLog2-nCurOctantDepth;
     413
     414  xUpdatePartitioning( nCurOctantDepth , nCurYPartNumLog2, nBestAdaptCThresholdU, nBestAdaptCThresholdV );
     415
     416  Bool bUseNewColorInfo = false;
     417  if( pCfg->getCGSAdaptChroma() && nCurOctantDepth <= 1 ) // if the best size found so far has depth = 0 or 1, then check AdaptC U/V thresholds
     418  {
     419    nAdaptCThresholdU = ( Int )( m_dSumU / m_nNChroma + 0.5 );
     420    nAdaptCThresholdV = ( Int )( m_dSumV / m_nNChroma + 0.5 );
     421    if( !(nAdaptCThresholdU == nBestAdaptCThresholdU && nAdaptCThresholdV == nBestAdaptCThresholdV ) )
     422    {
     423      nCurOctantDepth = 1;
     424      if( nCurOctantDepth + nCurYPartNumLog2 > getMaxYPartNumLog2()+getMaxOctantDepth() )
     425        nCurYPartNumLog2 = getMaxYPartNumLog2()+getMaxOctantDepth()-nCurOctantDepth;
     426      xUpdatePartitioning( nCurOctantDepth , nCurYPartNumLog2 , nAdaptCThresholdU , nAdaptCThresholdV );
     427      xxCollectData( pCurPic , refLayerIdc );
     428
     429      dCurError = xxDeriveVertexes( nBestResQuanBit , m_pEncCuboid ) ;
     430      setResQuantBit( nBestResQuanBit );
     431      xSaveCuboids( m_pEncCuboid );
     432      m_pEncCavlc->xCode3DAsymLUT( this );
     433      iNumBitsCurSize = m_pEncCavlc->getNumberOfWrittenBits();
     434      dCurCost = dCurError/dDistFactor + dFrameLambda*(Double)(iNumBitsCurSize-iNumBitsCurSizeSave); 
     435      iNumBitsCurSizeSave = iNumBitsCurSize;
     436      if(dCurCost < dMinCost )
     437      {
     438        SCuboid *** tmp = m_pBestEncCuboid;
     439        m_pBestEncCuboid = m_pEncCuboid;
     440        m_pEncCuboid = tmp;
     441        dMinCost = dCurCost;
     442        dMinError = dCurError;
     443        nBestAdaptCThresholdU = nAdaptCThresholdU;
     444        nBestAdaptCThresholdV = nAdaptCThresholdV;
     445        bUseNewColorInfo = true;
     446      }
     447    }
     448  }
     449
     450  xUpdatePartitioning( nCurOctantDepth , nCurYPartNumLog2, nBestAdaptCThresholdU, nBestAdaptCThresholdV );
     451
     452  // check res_quant_bits only for the best table size and best U/V threshold
     453  if( !bUseNewColorInfo )
     454    xxConsolidateData( &m_sLutSizes[iBestLUTSizeIdx], &sMaxLutSize );
     455
     456  //    xxCollectData( pCurPic , refLayerIdc );
     457  for( Int nResQuanBit = 1 ; nResQuanBit < 4 ; nResQuanBit++ )
     458  {
     459    dCurError = xxDeriveVertexes( nResQuanBit , m_pEncCuboid );
     460
     461    setResQuantBit( nResQuanBit );
     462    xSaveCuboids( m_pEncCuboid );
     463    m_pEncCavlc->xCode3DAsymLUT( this );
     464    iNumBitsCurSize = m_pEncCavlc->getNumberOfWrittenBits();
     465    dCurCost = dCurError/dDistFactor + dFrameLambda*(Double)(iNumBitsCurSize-iNumBitsCurSizeSave);   
     466
     467    iNumBitsCurSizeSave = iNumBitsCurSize;
     468    if(dCurCost < dMinCost)
     469    {
     470      nBestResQuanBit = nResQuanBit;
     471      SCuboid *** tmp = m_pBestEncCuboid;
     472      m_pBestEncCuboid = m_pEncCuboid;
     473      m_pEncCuboid = tmp;
     474      dMinCost = dCurCost;
     475      dMinError = dCurError;
     476    }
     477    else
     478    {
     479      break;
     480    }
     481  }
     482   
     483  setResQuantBit( nBestResQuanBit );
     484  xSaveCuboids( m_pBestEncCuboid );
     485
     486  // update LUT size stats
     487  for(Int iLutSizeY = 0; iLutSizeY < MAX_Y_SIZE; iLutSizeY++)
     488  {
     489    for(Int iLutSizeC = 0; iLutSizeC < MAX_C_SIZE; iLutSizeC++)
     490    {
     491      if(nTmpLutBits[iLutSizeY][iLutSizeC] != 0)
     492        m_nNumLUTBits[iLutSizeY][iLutSizeC] =  (m_nNumLUTBits[iLutSizeY][iLutSizeC] + nTmpLutBits[iLutSizeY][iLutSizeC]*3+2)>>2; // update with new stats
     493    }
     494  }
     495
     496  // return cost rather than error
     497  return( dMinCost );
     498}
     499#endif
     500
     501
     502Double TEnc3DAsymLUT::derive3DAsymLUT( TComSlice * pSlice , TComPic * pCurPic , UInt refLayerIdc , TEncCfg * pCfg , Bool bSignalPPS , Bool bElRapSliceTypeB )
     503{
     504  m_nLUTBitDepth = pCfg->getCGSLUTBit();
     505  Int nCurYPartNumLog2 = 0 , nCurOctantDepth = 0;
     506  xxDerivePartNumLog2( pSlice , pCfg , nCurOctantDepth , nCurYPartNumLog2 , bSignalPPS , bElRapSliceTypeB );
     507
     508  Int nBestResQuanBit = 0;
     509  Int nBestAdaptCThresholdU = 1 << ( getInputBitDepthC() - 1 );
     510  Int nBestAdaptCThresholdV = 1 << ( getInputBitDepthC() - 1 );
     511  Int nBestOctantDepth = nCurOctantDepth;
     512  Int nBestYPartNumLog2 = nCurYPartNumLog2;
     513  Int nTargetLoop = 1 + ( pCfg->getCGSAdaptChroma() && ( nCurOctantDepth == 1 || ( nCurOctantDepth * 3 + nCurYPartNumLog2 ) >= 5 ) );
     514  Double dMinError = MAX_DOUBLE;
     515  for( Int nLoop = 0 ; nLoop < nTargetLoop ; nLoop++ )
     516  {
     517    Int nAdaptCThresholdU = 1 << ( getInputBitDepthC() - 1 );
     518    Int nAdaptCThresholdV = 1 << ( getInputBitDepthC() - 1 );
     519    if( nLoop > 0 )
     520    {
     521      nAdaptCThresholdU = ( Int )( m_dSumU / m_nNChroma + 0.5 );
     522      nAdaptCThresholdV = ( Int )( m_dSumV / m_nNChroma + 0.5 );
     523      if( nCurOctantDepth > 1 )
     524      {
     525        nCurOctantDepth = 1;
     526        nCurYPartNumLog2 = 2;
     527      }
     528      if( nAdaptCThresholdU == nBestAdaptCThresholdU && nAdaptCThresholdV == nBestAdaptCThresholdV
     529        && nCurOctantDepth == nBestOctantDepth && nCurYPartNumLog2 == nBestYPartNumLog2 )
     530        break;
     531    }
     532
     533    xUpdatePartitioning( nCurOctantDepth , nCurYPartNumLog2 , nAdaptCThresholdU , nAdaptCThresholdV );
     534    xxCollectData( pCurPic , refLayerIdc );
     535    for( Int nResQuanBit = 0 ; nResQuanBit < 4 ; nResQuanBit++ )
     536    {
     537      Double dError = xxDeriveVertexes( nResQuanBit , m_pEncCuboid ) / ( 1 + ( nResQuanBit > 0 ) * 0.001 * ( pSlice->getDepth() + 1 ) );
     538      if( dError <= dMinError )
     539      {
     540        nBestResQuanBit = nResQuanBit;
     541        nBestAdaptCThresholdU = nAdaptCThresholdU;
     542        nBestAdaptCThresholdV = nAdaptCThresholdV;
     543        nBestOctantDepth = nCurOctantDepth;
     544        nBestYPartNumLog2 = nCurYPartNumLog2;
     545        SCuboid *** tmp = m_pBestEncCuboid;
     546        m_pBestEncCuboid = m_pEncCuboid;
     547        m_pEncCuboid = tmp;
     548        dMinError = dError;
     549      }
     550      else
     551      {
     552        break;
     553      }
     554    }
     555  }
     556
     557  setResQuantBit( nBestResQuanBit );
     558  xUpdatePartitioning( nBestOctantDepth , nBestYPartNumLog2 , nBestAdaptCThresholdU , nBestAdaptCThresholdV );
     559
     560  xSaveCuboids( m_pBestEncCuboid );
     561  return( dMinError );
     562}
     563#else
    177564Double TEnc3DAsymLUT::derive3DAsymLUT( TComSlice * pSlice , TComPic * pCurPic , UInt refLayerIdc , TEncCfg * pCfg , Bool bSignalPPS , Bool bElRapSliceTypeB )
    178565{
     
    204591  setResQuantBit( nBestResQuanBit );
    205592  xSaveCuboids( m_pBestEncCuboid );
    206 
    207593  return( dCurError );
    208594}
     595#endif
    209596
    210597Double TEnc3DAsymLUT::xxDeriveVertexes( Int nResQuanBit , SCuboid *** pCurCuboid )
     
    213600  Int nYSize = 1 << ( getCurOctantDepth() + getCurYPartNumLog2() );
    214601  Int nUVSize = 1 << getCurOctantDepth();
     602#if !R0151_CGS_3D_ASYMLUT_IMPROVE
    215603  Int nLengthY = 1 << ( getInputBitDepthY() - getCurOctantDepth() - getCurYPartNumLog2() );
    216604  Int nLengthUV = 1 << ( getInputBitDepthC() - getCurOctantDepth() );
     605#endif
    217606  for( Int yIdx = 0 ; yIdx < nYSize ; yIdx++ )
    218607  {
     
    224613        SColorInfo & rCuboidColorInfoC = m_pColorInfoC[yIdx][uIdx][vIdx];
    225614        SCuboid & rCuboid = pCurCuboid[yIdx][uIdx][vIdx];
     615#if !R0151_CGS_3D_ASYMLUT_IMPROVE
    226616        Int y0 = yIdx << xGetYShift2Idx();
    227617        Int u0 = uIdx << xGetUShift2Idx();
    228618        Int v0 = vIdx << xGetVShift2Idx();
     619#endif
    229620        for( Int idxVertex = 0 ; idxVertex < 4 ; idxVertex++ )
    230621        {
     
    235626        {
    236627          dErrorLuma += xxDeriveVertexPerColor( rCuboidColorInfo.N , rCuboidColorInfo.Ys , rCuboidColorInfo.Yy , rCuboidColorInfo.Yu , rCuboidColorInfo.Yv , rCuboidColorInfo.ys , rCuboidColorInfo.us , rCuboidColorInfo.vs , rCuboidColorInfo.yy , rCuboidColorInfo.yu , rCuboidColorInfo.yv , rCuboidColorInfo.uu , rCuboidColorInfo.uv , rCuboidColorInfo.vv , rCuboidColorInfo.YY ,
    237             y0 , u0 , v0 , nLengthY , nLengthUV , rCuboid.P[0].Y , rCuboid.P[1].Y , rCuboid.P[2].Y , rCuboid.P[3].Y , nResQuanBit );
     628#if !R0151_CGS_3D_ASYMLUT_IMPROVE
     629            y0 , u0 , v0 , nLengthY , nLengthUV ,
     630#endif
     631            rCuboid.P[0].Y , rCuboid.P[1].Y , rCuboid.P[2].Y , rCuboid.P[3].Y , nResQuanBit );
    238632        }
    239633        if( rCuboidColorInfoC.N > 0 )
    240634        {
    241635          dErrorChroma += xxDeriveVertexPerColor( rCuboidColorInfoC.N , rCuboidColorInfoC.Us , rCuboidColorInfoC.Uy , rCuboidColorInfoC.Uu , rCuboidColorInfoC.Uv , rCuboidColorInfoC.ys , rCuboidColorInfoC.us , rCuboidColorInfoC.vs , rCuboidColorInfoC.yy , rCuboidColorInfoC.yu , rCuboidColorInfoC.yv , rCuboidColorInfoC.uu , rCuboidColorInfoC.uv , rCuboidColorInfoC.vv , rCuboidColorInfoC.UU ,
    242             y0 , u0 , v0 , nLengthY , nLengthUV , rCuboid.P[0].U , rCuboid.P[1].U , rCuboid.P[2].U , rCuboid.P[3].U , nResQuanBit );
     636#if !R0151_CGS_3D_ASYMLUT_IMPROVE
     637            y0 , u0 , v0 , nLengthY , nLengthUV ,
     638#endif
     639            rCuboid.P[0].U , rCuboid.P[1].U , rCuboid.P[2].U , rCuboid.P[3].U , nResQuanBit );
    243640          dErrorChroma += xxDeriveVertexPerColor( rCuboidColorInfoC.N , rCuboidColorInfoC.Vs , rCuboidColorInfoC.Vy , rCuboidColorInfoC.Vu , rCuboidColorInfoC.Vv , rCuboidColorInfoC.ys , rCuboidColorInfoC.us , rCuboidColorInfoC.vs , rCuboidColorInfoC.yy , rCuboidColorInfoC.yu , rCuboidColorInfoC.yv , rCuboidColorInfoC.uu , rCuboidColorInfoC.uv , rCuboidColorInfoC.vv , rCuboidColorInfoC.VV ,
    244             y0 , u0 , v0 , nLengthY , nLengthUV , rCuboid.P[0].V , rCuboid.P[1].V , rCuboid.P[2].V , rCuboid.P[3].V , nResQuanBit );
     641#if !R0151_CGS_3D_ASYMLUT_IMPROVE
     642            y0 , u0 , v0 , nLengthY , nLengthUV ,
     643#endif
     644            rCuboid.P[0].V , rCuboid.P[1].V , rCuboid.P[2].V , rCuboid.P[3].V , nResQuanBit );
    245645        }
    246646
     
    276676  Int nStrideILRY = pRecPic->getStride();
    277677  Int nStrideILRC = pRecPic->getCStride();
     678#if R0179_ENC_OPT_3DLUT_SIZE
     679  xReset3DArray( m_pColorInfo  , getMaxYSize() , getMaxCSize() , getMaxCSize() );
     680  xReset3DArray( m_pColorInfoC , getMaxYSize() , getMaxCSize() , getMaxCSize() );
     681#else
    278682  xReset3DArray( m_pColorInfo , xGetYSize() , xGetUSize() , xGetVSize() );
    279683  xReset3DArray( m_pColorInfoC , xGetYSize() , xGetUSize() , xGetVSize() );
     684#endif
    280685
    281686  //alignment padding
     
    285690  TComSlice * pSlice = pCurPic->getSlice(pCurPic->getCurrSliceIdx());
    286691  UInt refLayerId = pSlice->getVPS()->getRefLayerId(pSlice->getLayerId(), refLayerIdc);
     692#if MOVE_SCALED_OFFSET_TO_PPS
     693  const Window &scalEL = pSlice->getPPS()->getScaledRefLayerWindowForLayer(refLayerId);
     694#else
    287695  const Window &scalEL = pSlice->getSPS()->getScaledRefLayerWindowForLayer(refLayerId);
     696#endif
    288697  TComPicYuv *pcRecPicBL = pSlice->getBaseColPic(refLayerIdc)->getPicYuvRec();
    289698  // borders of down-sampled picture
     
    299708  // since we do data collection only for overlapped region, the border extension is good enough
    300709
     710#if R0151_CGS_3D_ASYMLUT_IMPROVE
     711  m_dSumU = m_dSumV = 0;
     712  m_nNChroma = 0;
     713#endif
    301714  for( Int i = top ; i <= bottom ; i++ )
    302715  {
     
    330743      }
    331744
     745#if R0151_CGS_3D_ASYMLUT_IMPROVE
     746      m_dSumU += u;
     747      m_dSumV += v;
     748      m_nNChroma++;
     749#endif
    332750      SColorInfo sColorInfo;
     751#if R0151_CGS_3D_ASYMLUT_IMPROVE
     752      SColorInfo & rCuboidColorInfo = m_pColorInfo[xGetYIdx(y)][xGetUIdx(u)][xGetVIdx(v)];
     753#else
    333754      SColorInfo & rCuboidColorInfo = m_pColorInfo[y>>xGetYShift2Idx()][u>>xGetUShift2Idx()][v>>xGetVShift2Idx()];
     755#endif
    334756      memset(&sColorInfo, 0, sizeof(SColorInfo));
    335757      sColorInfo.Ys = Y;
     
    358780        u = pIRLU[posIRLUV];
    359781        v = pIRLV[posIRLUV];
     782#if R0151_CGS_3D_ASYMLUT_IMPROVE
     783        SColorInfo & rCuboidColorInfoC = m_pColorInfoC[xGetYIdx(y)][xGetUIdx(u)][xGetVIdx(v)];
     784#else
    360785        SColorInfo & rCuboidColorInfoC = m_pColorInfoC[y>>xGetYShift2Idx()][u>>xGetUShift2Idx()][v>>xGetVShift2Idx()];
     786#endif
    361787        sColorInfo.Us = U;
    362788        sColorInfo.Vs = V;
     
    389815Void TEnc3DAsymLUT::xxDerivePartNumLog2( TComSlice * pSlice , TEncCfg * pcCfg , Int & rOctantDepth , Int & rYPartNumLog2 , Bool bSignalPPS , Bool bElRapSliceTypeB )
    390816{
     817#if !R0151_CGS_3D_ASYMLUT_IMPROVE
    391818  Int nSliceType = pSlice->getSliceType();
    392819  // update slice type as what will be done later
     
    406833
    407834  const Int nSliceTempLevel = pSlice->getDepth();
     835#endif
    408836  Int nPartNumLog2 = 4;
    409837  if( pSlice->getBaseColPic( pSlice->getInterLayerPredLayerIdc( 0 ) )->getSlice( 0 )->isIntra() )
     
    411839    nPartNumLog2 = xGetMaxPartNumLog2();
    412840  }
     841#if R0151_CGS_3D_ASYMLUT_IMPROVE
     842  if( m_nAccuFrameBit && pSlice->getPPS()->getCGSFlag() )
     843  {
     844    Double dBitCost = 1.0 * m_nAccuFrameCGSBit / m_nAccuFrameBit;
     845    nPartNumLog2 = m_nPrevFrameCGSPartNumLog2;
     846#else
    413847  if( m_nPrevFrameBit[nSliceType][nSliceTempLevel] && pSlice->getPPS()->getCGSFlag() )
    414848  {
    415849    Double dBitCost = 1.0 * m_nPrevFrameCGSBit[nSliceType][nSliceTempLevel] / m_nPrevFrameBit[nSliceType][nSliceTempLevel];
    416850    nPartNumLog2 = m_nPrevFrameCGSPartNumLog2[nSliceType][nSliceTempLevel];
     851#endif
    417852    Double dBitCostT = 0.03;
    418853    if( dBitCost < dBitCostT / 6.0 )
     
    425860    }
    426861  }
     862#if !R0151_CGS_3D_ASYMLUT_IMPROVE
    427863  else
    428864  {
    429865    nPartNumLog2 -= nSliceTempLevel;
    430866  }
    431   nPartNumLog2 = Clip3( 0 , xGetMaxPartNumLog2() , nPartNumLog2 );
     867#endif
     868  nPartNumLog2 = Clip3( 0 , xGetMaxPartNumLog2()  , nPartNumLog2 );
    432869  xxMapPartNum2DepthYPart( nPartNumLog2 , rOctantDepth , rYPartNumLog2 );
    433870}
     
    453890Void TEnc3DAsymLUT::updatePicCGSBits( TComSlice * pcSlice , Int nPPSBit )
    454891{
     892#if !R0151_CGS_3D_ASYMLUT_IMPROVE
    455893  const Int nSliceType = pcSlice->getSliceType();
    456894  const Int nSliceTempLevel = pcSlice->getDepth();
    457 
     895#endif
    458896  for( Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
    459897  {
    460898    UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i);
     899#if R0151_CGS_3D_ASYMLUT_IMPROVE
     900    m_nAccuFrameBit += pcSlice->getPic()->getFrameBit() + pcSlice->getBaseColPic(refLayerIdc)->getFrameBit();
     901#else
    461902    m_nPrevFrameBit[nSliceType][nSliceTempLevel] = pcSlice->getPic()->getFrameBit() + pcSlice->getBaseColPic(refLayerIdc)->getFrameBit();
     903#endif
    462904    m_dTotalFrameBit += pcSlice->getPic()->getFrameBit() + pcSlice->getBaseColPic(refLayerIdc)->getFrameBit();
    463905  }
     906#if R0151_CGS_3D_ASYMLUT_IMPROVE
     907  m_nAccuFrameCGSBit += nPPSBit;
     908  m_nTotalCGSBit += nPPSBit;
     909  m_nPrevFrameCGSPartNumLog2 = getCurOctantDepth() * 3 + getCurYPartNumLog2();
     910#else
    464911  m_nPrevFrameOverWritePPS[nSliceType][nSliceTempLevel] = pcSlice->getCGSOverWritePPS();
    465912  m_nPrevFrameCGSBit[nSliceType][nSliceTempLevel] = nPPSBit;
    466913  m_nTotalCGSBit += nPPSBit;
    467914  m_nPrevFrameCGSPartNumLog2[nSliceType][nSliceTempLevel] = getCurOctantDepth() * 3 + getCurYPartNumLog2();
    468 }
    469 
    470 #endif
     915#endif
     916#if R0179_ENC_OPT_3DLUT_SIZE
     917  Int nCurELFrameBit = pcSlice->getPic()->getFrameBit();
     918  const Int nSliceType = pcSlice->getSliceType();
     919  const Int nSliceTempLevel = pcSlice->getDepth();
     920  m_nPrevELFrameBit[nSliceType][nSliceTempLevel] = m_nPrevELFrameBit[nSliceType][nSliceTempLevel] == 0 ? nCurELFrameBit:((m_nPrevELFrameBit[nSliceType][nSliceTempLevel]+nCurELFrameBit)>>1);
     921#endif
     922}
     923
     924#if R0179_ENC_OPT_3DLUT_SIZE
     925
     926Void TEnc3DAsymLUT::xxGetAllLutSizes(TComSlice *pSlice)
     927{
     928  Int iMaxYPartNumLog2, iMaxCPartNumLog2;
     929  Int iCurYPartNumLog2, iCurCPartNumLog2;
     930  Int iMaxAddYPartNumLog2;
     931  Int iNumELFrameBits = m_nPrevELFrameBit[pSlice->getSliceType()][pSlice->getDepth()];
     932
     933  xxMapPartNum2DepthYPart( xGetMaxPartNumLog2() , iMaxCPartNumLog2 , iMaxYPartNumLog2 );
     934  iMaxAddYPartNumLog2 = iMaxYPartNumLog2;
     935  iMaxYPartNumLog2 += iMaxCPartNumLog2;
     936
     937  //m_sLutSizes[0].iYPartNumLog2 = iMaxYPartNumLog2;
     938  //m_sLutSizes[0].iCPartNumLog2 = iMaxCPartNumLog2;
     939  m_nTotalLutSizes = 0;
     940
     941
     942  for(iCurYPartNumLog2 = iMaxYPartNumLog2; iCurYPartNumLog2 >= 0; iCurYPartNumLog2--)
     943  {
     944    for(iCurCPartNumLog2 = iMaxCPartNumLog2; iCurCPartNumLog2 >= 0; iCurCPartNumLog2--)
     945    {
     946       // try more sizes
     947      if(iCurCPartNumLog2 <= iCurYPartNumLog2  &&
     948         (m_nNumLUTBits[iCurYPartNumLog2][iCurCPartNumLog2] < (iNumELFrameBits>>1)) &&
     949         m_nTotalLutSizes < MAX_NUM_LUT_SIZES)
     950      {
     951        m_sLutSizes[m_nTotalLutSizes].iYPartNumLog2 = iCurYPartNumLog2;
     952        m_sLutSizes[m_nTotalLutSizes].iCPartNumLog2 = iCurCPartNumLog2;
     953        m_nTotalLutSizes ++;
     954      }
     955    }
     956  }
     957
     958}
     959
     960Void TEnc3DAsymLUT::xxCopyColorInfo( SColorInfo *** dst, SColorInfo *** src ,  SColorInfo *** dstC, SColorInfo *** srcC )
     961{
     962  Int yIdx, uIdx, vIdx;
     963
     964  // copy from pColorInfo to pMaxColorInfo
     965  for(yIdx = 0; yIdx < xGetYSize(); yIdx++)
     966  {
     967    for(uIdx = 0; uIdx < xGetUSize(); uIdx++)
     968    {
     969      for(vIdx = 0; vIdx < xGetVSize(); vIdx++)
     970      {
     971        dst [yIdx][uIdx][vIdx] = src [yIdx][uIdx][vIdx];
     972        dstC[yIdx][uIdx][vIdx] = srcC[yIdx][uIdx][vIdx];
     973      }
     974    }
     975  }
     976}
     977
     978Void TEnc3DAsymLUT::xxAddColorInfo( Int yIdx, Int uIdx, Int vIdx, Int iYDiffLog2, Int iCDiffLog2 )
     979{
     980  SColorInfo & rCuboidColorInfo  = m_pColorInfo [yIdx][uIdx][vIdx];
     981  SColorInfo & rCuboidColorInfoC = m_pColorInfoC[yIdx][uIdx][vIdx];
     982 
     983  for( Int i = 0; i < (1<<iYDiffLog2); i++)
     984  {
     985    for (Int j = 0; j < (1<<iCDiffLog2); j++)
     986    {
     987      for(Int k = 0; k < (1<<iCDiffLog2); k++)
     988      {
     989        rCuboidColorInfo  += m_pMaxColorInfo [(yIdx<<iYDiffLog2)+i][(uIdx<<iCDiffLog2)+j][(vIdx<<iCDiffLog2)+k];
     990        rCuboidColorInfoC += m_pMaxColorInfoC[(yIdx<<iYDiffLog2)+i][(uIdx<<iCDiffLog2)+j][(vIdx<<iCDiffLog2)+k];
     991      }
     992    }
     993  }
     994}
     995
     996Void TEnc3DAsymLUT::xxConsolidateData( SLUTSize *pCurLUTSize, SLUTSize *pMaxLUTSize )
     997{
     998  Int yIdx, uIdx, vIdx;
     999  Int iYDiffLog2, iCDiffLog2;
     1000  Int nYSize = 1<< pMaxLUTSize->iYPartNumLog2;
     1001  Int nCSize = 1<< pMaxLUTSize->iCPartNumLog2;
     1002
     1003  iYDiffLog2 = pMaxLUTSize->iYPartNumLog2-pCurLUTSize->iYPartNumLog2;
     1004  iCDiffLog2 = pMaxLUTSize->iCPartNumLog2-pCurLUTSize->iCPartNumLog2;
     1005
     1006  //assert(pMaxLUTSize->iCPartNumLog2 >= pCurLUTSize->iCPartNumLog2 && pMaxLUTSize->iYPartNumLog2 >= pCurLUTSize->iYPartNumLog2);
     1007  if (iYDiffLog2 == 0 && iCDiffLog2 == 0) // shouldn't have to do anything
     1008  {
     1009    xxCopyColorInfo(m_pColorInfo, m_pMaxColorInfo, m_pColorInfoC, m_pMaxColorInfoC);
     1010    return;
     1011  }
     1012
     1013  xReset3DArray( m_pColorInfo  ,  1<<pMaxLUTSize->iYPartNumLog2, 1<<pMaxLUTSize->iCPartNumLog2, 1<<pMaxLUTSize->iCPartNumLog2 );
     1014  xReset3DArray( m_pColorInfoC ,  1<<pMaxLUTSize->iYPartNumLog2, 1<<pMaxLUTSize->iCPartNumLog2, 1<<pMaxLUTSize->iCPartNumLog2 );
     1015
     1016  for(yIdx = 0; yIdx < nYSize; yIdx++)
     1017  {
     1018    for(uIdx = 0; uIdx < nCSize; uIdx++)
     1019    {
     1020      for(vIdx = 0; vIdx < nCSize; vIdx++)
     1021      {
     1022        const SColorInfo & rCuboidSrc   = m_pMaxColorInfo [yIdx][uIdx][vIdx];
     1023        const SColorInfo & rCuboidSrcC  = m_pMaxColorInfoC[yIdx][uIdx][vIdx];
     1024       
     1025        Int yIdx2, uIdx2, vIdx2;
     1026        yIdx2 = yIdx>>iYDiffLog2;
     1027        uIdx2 = uIdx>>iCDiffLog2;
     1028        vIdx2 = vIdx>>iCDiffLog2;
     1029
     1030        m_pColorInfo [yIdx2][uIdx2][vIdx2] += rCuboidSrc;
     1031        m_pColorInfoC[yIdx2][uIdx2][vIdx2] += rCuboidSrcC;
     1032      }
     1033    }
     1034  }
     1035}
     1036
     1037Void TEnc3DAsymLUT::update3DAsymLUTParam( TEnc3DAsymLUT * pSrc )
     1038{
     1039  assert( pSrc->getMaxOctantDepth() == getMaxOctantDepth() && pSrc->getMaxYPartNumLog2() == getMaxYPartNumLog2() );
     1040  xUpdatePartitioning( pSrc->getCurOctantDepth() , pSrc->getCurYPartNumLog2()
     1041#if R0151_CGS_3D_ASYMLUT_IMPROVE
     1042    , pSrc->getAdaptChromaThresholdU() , pSrc->getAdaptChromaThresholdV()
     1043#endif
     1044    );
     1045  setResQuantBit( pSrc->getResQuantBit() );
     1046}
     1047
     1048#endif
     1049#endif
  • trunk/source/Lib/TLibEncoder/TEnc3DAsymLUT.h

    r713 r906  
    88#include "../TLibCommon/TComPic.h"
    99#include "TEncCfg.h"
     10#if R0179_ENC_OPT_3DLUT_SIZE
     11#include "TEncCavlc.h"
     12#define MAX_NUM_LUT_SIZES               10   // 4+3+2+1
     13#define MAX_Y_SIZE                       4
     14#define MAX_C_SIZE                       4
     15#endif
    1016
    1117#if Q0048_CGS_3D_ASYMLUT
     
    5561}SColorInfo;
    5662
     63#if R0179_ENC_OPT_3DLUT_SIZE
     64typedef struct _LUTSize
     65{
     66  Int iYPartNumLog2;
     67  Int iCPartNumLog2;
     68} SLUTSize;
     69#endif
    5770
    5871class TEnc3DAsymLUT : public TCom3DAsymLUT
     
    6679  Double derive3DAsymLUT( TComSlice * pSlice , TComPic * pCurPic , UInt refLayerIdc , TEncCfg * pCfg , Bool bSignalPPS , Bool bElRapSliceTypeB );
    6780  Double estimateDistWithCur3DAsymLUT( TComPic * pCurPic , UInt refLayerIdc );
     81#if R0179_ENC_OPT_3DLUT_SIZE
     82  Double getDistFactor( Int iSliceType, Int iLayer) { return m_dDistFactor[iSliceType][iLayer];}
     83  Double derive3DAsymLUT( TComSlice * pSlice , TComPic * pCurPic , UInt refLayerIdc , TEncCfg * pCfg , Bool bSignalPPS , Bool bElRapSliceTypeB, Double dFrameLambda );
     84  Void   update3DAsymLUTParam( TEnc3DAsymLUT * pSrc );
     85#endif
    6886
    6987  Void  updatePicCGSBits( TComSlice * pcSlice , Int nPPSBit );
     
    7593  SColorInfo *** m_pColorInfo;
    7694  SColorInfo *** m_pColorInfoC;
     95#if R0179_ENC_OPT_3DLUT_SIZE
     96  SColorInfo *** m_pMaxColorInfo;
     97  SColorInfo *** m_pMaxColorInfoC;
     98#endif
    7799  TComPicYuv* m_pDsOrigPic;
    78100  SCuboid *** m_pEncCuboid;
    79101  SCuboid *** m_pBestEncCuboid;
     102#if R0151_CGS_3D_ASYMLUT_IMPROVE
     103  Int   m_nAccuFrameBit;                  // base + enhancement layer
     104  Int   m_nAccuFrameCGSBit;
     105  Int   m_nPrevFrameCGSPartNumLog2;
     106#else
    80107  Int   m_nPrevFrameBit[3][MAX_TLAYER];                  // base + enhancement layer
    81108  Int   m_nPrevFrameCGSBit[3][MAX_TLAYER];
    82109  Int   m_nPrevFrameCGSPartNumLog2[3][MAX_TLAYER];
    83110  Int   m_nPrevFrameOverWritePPS[3][MAX_TLAYER];
     111#endif
    84112  Double m_dTotalFrameBit;
    85113  Int   m_nTotalCGSBit;
    86114  Int   m_nPPSBit;
    87115  Int   m_nLUTBitDepth;
     116#if R0179_ENC_OPT_3DLUT_SIZE
     117
     118  Double m_dDistFactor[3][MAX_TLAYER];         
     119  Int    m_nNumLUTBits[MAX_Y_SIZE][MAX_C_SIZE];
     120  Int    m_nPrevELFrameBit[3][MAX_TLAYER];   
     121
     122
     123  Int   m_nTotalLutSizes;
     124  SLUTSize m_sLutSizes[MAX_NUM_LUT_SIZES];
     125#endif
     126#if R0151_CGS_3D_ASYMLUT_IMPROVE
     127  Double m_dSumU;
     128  Double m_dSumV;
     129  Int    m_nNChroma;
     130#endif
     131#if R0179_ENC_OPT_3DLUT_SIZE
     132  TComOutputBitstream  *m_pBitstreamRedirect;
     133  TEncCavlc *m_pEncCavlc;
     134#endif
    88135
    89136private:
     137#if R0151_CGS_3D_ASYMLUT_IMPROVE
     138  Double  xxDeriveVertexPerColor( Double N , Double Ys , Double Yy , Double Yu , Double Yv , Double ys , Double us , Double vs , Double yy , Double yu , Double yv , Double uu , Double uv , Double vv , Double YY ,
     139    Pel & rP0 , Pel & rP1 , Pel & rP3 , Pel & rP7 , Int nResQuantBit );
     140#else
    90141  Double  xxDeriveVertexPerColor( Double N , Double Ys , Double Yy , Double Yu , Double Yv , Double ys , Double us , Double vs , Double yy , Double yu , Double yv , Double uu , Double uv , Double vv , Double YY ,
    91142    Int y0 , Int u0 , Int v0 , Int nLengthY , Int nLengthUV ,
    92143    Pel & rP0 , Pel & rP1 , Pel & rP3 , Pel & rP7 , Int nResQuantBit );
     144#endif
    93145  Void    xxDerivePartNumLog2( TComSlice * pSlice , TEncCfg * pcCfg , Int & rOctantDepth , Int & rYPartNumLog2 , Bool bSignalPPS , Bool bElRapSliceTypeB );
    94146  Void    xxMapPartNum2DepthYPart( Int nPartNumLog2 , Int & rOctantDepth , Int & rYPartNumLog2 );
    95147  Int     xxCoeff2Vertex( Double a , Double b , Double c , Double d , Int y , Int u , Int v ) { return ( ( Int )( a * y + b * u + c * v + d + 0.5 ) ); }
    96148  Void    xxCollectData( TComPic * pCurPic , UInt refLayerIdc );
     149
    97150  Double  xxDeriveVertexes( Int nResQuantBit , SCuboid *** pCurCuboid );
    98151  inline Double  xxCalEstDist( Double N , Double Ys , Double Yy , Double Yu , Double Yv , Double ys , Double us , Double vs , Double yy , Double yu , Double yv , Double uu , Double uv , Double vv , Double YY ,
     
    100153  inline Double  xxCalEstDist( Double N , Double Ys , Double Yy , Double Yu , Double Yv , Double ys , Double us , Double vs , Double yy , Double yu , Double yv , Double uu , Double uv , Double vv , Double YY ,
    101154    Double a , Double b , Double c , Double d );
     155#if R0151_CGS_3D_ASYMLUT_IMPROVE
     156  inline Double  xxCalEstDist( Double N , Double Ys , Double Yy , Double Yu , Double Yv , Double ys , Double us , Double vs , Double yy , Double yu , Double yv , Double uu , Double uv , Double vv , Double YY ,
     157    Pel nP0 , Pel nP1 , Pel nP3 , Pel nP7 );
     158#endif
     159#if R0179_ENC_OPT_3DLUT_SIZE
     160  Void    xxConsolidateData( SLUTSize *pCurLUTSize, SLUTSize *pMaxLUTSize );
     161  Void    xxGetAllLutSizes(TComSlice *pSlice);
     162  Void    xxCopyColorInfo( SColorInfo *** dst, SColorInfo *** src ,  SColorInfo *** dstC, SColorInfo *** srcC );
     163  Void    xxAddColorInfo( Int yIdx, Int uIdx, Int vIdx, Int iYDiffLog2, Int iCDiffLog2 );
     164#endif
    102165};
    103166
     
    118181  return( dError );
    119182};
    120 #endif
    121 
    122 #endif
     183
     184#if R0151_CGS_3D_ASYMLUT_IMPROVE
     185Double TEnc3DAsymLUT::xxCalEstDist( Double N , Double Ys , Double Yy , Double Yu , Double Yv , Double ys , Double us , Double vs , Double yy , Double yu , Double yv , Double uu , Double uv , Double vv , Double YY ,
     186  Pel nP0 , Pel nP1 , Pel nP3 , Pel nP7 )
     187{
     188  const Int nOne = xGetNormCoeffOne();
     189  Double a = 1.0 * nP0 / nOne;
     190  Double b = 1.0 * nP1 / nOne;
     191  Double c = 1.0 * nP3 / nOne;
     192  Double d = nP7;
     193  Double dError = N * d * d + 2 * b * c * uv + 2 * a * c * yv + 2 * a * b * yu - 2 * c * Yv - 2 * b * Yu - 2 * a * Yy + 2 * c * d * vs + 2 * b * d * us + 2 * a * d * ys + a * a * yy + c * c * vv + b * b * uu - 2 * d * Ys + YY;
     194  return( dError );
     195};
     196#endif
     197
     198#endif
     199
     200#endif
  • trunk/source/Lib/TLibEncoder/TEncCavlc.cpp

    r815 r906  
    193193  if( pcPPS->getTilesEnabledFlag() )
    194194  {
    195     WRITE_UVLC( pcPPS->getNumColumnsMinus1(),                                    "num_tile_columns_minus1" );
    196     WRITE_UVLC( pcPPS->getNumRowsMinus1(),                                       "num_tile_rows_minus1" );
    197     WRITE_FLAG( pcPPS->getUniformSpacingFlag(),                                  "uniform_spacing_flag" );
    198     if( pcPPS->getUniformSpacingFlag() == 0 )
    199     {
    200       for(UInt i=0; i<pcPPS->getNumColumnsMinus1(); i++)
    201       {
    202         WRITE_UVLC( pcPPS->getColumnWidth(i)-1,                                  "column_width_minus1" );
    203       }
    204       for(UInt i=0; i<pcPPS->getNumRowsMinus1(); i++)
    205       {
    206         WRITE_UVLC( pcPPS->getRowHeight(i)-1,                                    "row_height_minus1" );
    207       }
    208     }
    209     if(pcPPS->getNumColumnsMinus1() !=0 || pcPPS->getNumRowsMinus1() !=0)
     195    WRITE_UVLC( pcPPS->getNumTileColumnsMinus1(),                                    "num_tile_columns_minus1" );
     196    WRITE_UVLC( pcPPS->getTileNumRowsMinus1(),                                       "num_tile_rows_minus1" );
     197    WRITE_FLAG( pcPPS->getTileUniformSpacingFlag(),                                  "uniform_spacing_flag" );
     198    if( !pcPPS->getTileUniformSpacingFlag() )
     199    {
     200      for(UInt i=0; i<pcPPS->getNumTileColumnsMinus1(); i++)
     201      {
     202        WRITE_UVLC( pcPPS->getTileColumnWidth(i)-1,                                  "column_width_minus1" );
     203      }
     204      for(UInt i=0; i<pcPPS->getTileNumRowsMinus1(); i++)
     205      {
     206        WRITE_UVLC( pcPPS->getTileRowHeight(i)-1,                                    "row_height_minus1" );
     207      }
     208    }
     209    if(pcPPS->getNumTileColumnsMinus1() !=0 || pcPPS->getTileNumRowsMinus1() !=0)
    210210    {
    211211      WRITE_FLAG( pcPPS->getLoopFilterAcrossTilesEnabledFlag()?1 : 0,          "loop_filter_across_tiles_enabled_flag");
     
    225225  }
    226226
     227#if !R0042_PROFILE_INDICATION
    227228#if SCALINGLIST_INFERRING
    228229  if( pcPPS->getLayerId() > 0 )
     
    241242  {
    242243#endif
     244#endif
    243245
    244246  WRITE_FLAG( pcPPS->getScalingListPresentFlag() ? 1 : 0,                          "pps_scaling_list_data_present_flag" );
     
    247249    codeScalingList( m_pcSlice->getScalingList() );
    248250  }
    249 
     251#if !R0042_PROFILE_INDICATION
    250252#if SCALINGLIST_INFERRING
    251253  }
     254#endif
    252255#endif
    253256
     
    256259  WRITE_FLAG( pcPPS->getSliceHeaderExtensionPresentFlag() ? 1 : 0, "slice_segment_header_extension_present_flag");
    257260#if P0166_MODIFIED_PPS_EXTENSION
     261#if !R0042_PROFILE_INDICATION
    258262  WRITE_FLAG( pcPPS->getExtensionFlag() ? 1 : 0, "pps_extension_flag" );
     263#else
     264  WRITE_FLAG( pcPPS->getExtensionFlag() ? 1 : 0, "pps_extension_present_flag" );
     265#endif
    259266
    260267  if( pcPPS->getExtensionFlag() )
    261268  {
     269#if !R0042_PROFILE_INDICATION
    262270#if !POC_RESET_IDC
    263271    UInt ppsExtensionTypeFlag[8] = { 0, 1, 0, 0, 0, 0, 0, 0 };
     
    273281    {
    274282      WRITE_FLAG( pcPPS->getPocResetInfoPresentFlag() ? 1 : 0, "poc_reset_info_present_flag" );
     283#if REF_REGION_OFFSET
     284      WRITE_UVLC( pcPPS->getNumScaledRefLayerOffsets(),      "num_scaled_ref_layer_offsets" );
     285      for(Int i = 0; i < pcPPS->getNumScaledRefLayerOffsets(); i++)
     286      {
     287        WRITE_CODE( pcPPS->getScaledRefLayerId(i), 6, "scaled_ref_layer_id" );
     288        WRITE_FLAG( pcPPS->getScaledRefLayerOffsetPresentFlag(i) ? 1 : 0, "scaled_ref_layer_offset_prsent_flag" );
     289        if (pcPPS->getScaledRefLayerOffsetPresentFlag(i))
     290        {
     291          Window scaledWindow = pcPPS->getScaledRefLayerWindow(i);
     292          WRITE_SVLC( scaledWindow.getWindowLeftOffset()   >> 1, "scaled_ref_layer_left_offset" );
     293          WRITE_SVLC( scaledWindow.getWindowTopOffset()    >> 1, "scaled_ref_layer_top_offset" );
     294          WRITE_SVLC( scaledWindow.getWindowRightOffset()  >> 1, "scaled_ref_layer_right_offset" );
     295          WRITE_SVLC( scaledWindow.getWindowBottomOffset() >> 1, "scaled_ref_layer_bottom_offset" );
     296        }
     297        WRITE_FLAG( pcPPS->getRefRegionOffsetPresentFlag(i) ? 1 : 0, "ref_region_offset_prsent_flag" );
     298        if (pcPPS->getRefRegionOffsetPresentFlag(i))
     299        {
     300          Window refWindow = pcPPS->getRefLayerWindow(i);
     301          WRITE_SVLC( refWindow.getWindowLeftOffset()   >> 1, "ref_layer_left_offset" );
     302          WRITE_SVLC( refWindow.getWindowTopOffset()    >> 1, "ref_layer_top_offset" );
     303          WRITE_SVLC( refWindow.getWindowRightOffset()  >> 1, "ref_layer_right_offset" );
     304          WRITE_SVLC( refWindow.getWindowBottomOffset() >> 1, "ref_layer_bottom_offset" );
     305        }
     306#if R0209_GENERIC_PHASE
     307        WRITE_FLAG( pcPPS->getResamplePhaseSetPresentFlag(i) ? 1 : 0, "resample_phase_set_present_flag" );
     308        if (pcPPS->getResamplePhaseSetPresentFlag(i))
     309        {
     310          WRITE_UVLC( pcPPS->getPhaseHorLuma(i), "phase_hor_luma" );
     311          WRITE_UVLC( pcPPS->getPhaseVerLuma(i), "phase_ver_luma" );
     312          WRITE_UVLC( pcPPS->getPhaseHorChroma(i) + 8, "phase_hor_chroma_plus8" );
     313          WRITE_UVLC( pcPPS->getPhaseVerChroma(i) + 8, "phase_ver_chroma_plus8" );
     314        }
     315#endif
     316      }
     317#else
     318#if MOVE_SCALED_OFFSET_TO_PPS
     319      WRITE_UVLC( pcPPS->getNumScaledRefLayerOffsets(),      "num_scaled_ref_layer_offsets" );
     320      for(Int i = 0; i < pcPPS->getNumScaledRefLayerOffsets(); i++)
     321      {
     322        Window scaledWindow = pcPPS->getScaledRefLayerWindow(i);
     323#if O0098_SCALED_REF_LAYER_ID
     324        WRITE_CODE( pcPPS->getScaledRefLayerId(i), 6,          "scaled_ref_layer_id" );
     325#endif
     326        WRITE_SVLC( scaledWindow.getWindowLeftOffset()   >> 1, "scaled_ref_layer_left_offset" );
     327        WRITE_SVLC( scaledWindow.getWindowTopOffset()    >> 1, "scaled_ref_layer_top_offset" );
     328        WRITE_SVLC( scaledWindow.getWindowRightOffset()  >> 1, "scaled_ref_layer_right_offset" );
     329        WRITE_SVLC( scaledWindow.getWindowBottomOffset() >> 1, "scaled_ref_layer_bottom_offset" );
     330      }
     331#endif
     332#endif
    275333#if Q0048_CGS_3D_ASYMLUT
    276334      UInt uiPos = getNumberOfWrittenBits();
     
    285343#endif
    286344    }
     345#else
     346  WRITE_FLAG( 0, "pps_range_extension_flag" );
     347  WRITE_FLAG( 1, "pps_multilayer_extension_flag" );
     348  WRITE_CODE( 0, 6,  "pps_extension_6bits" );     
     349
     350  WRITE_FLAG( pcPPS->getPocResetInfoPresentFlag() ? 1 : 0, "poc_reset_info_present_flag" );
     351#if SCALINGLIST_INFERRING
     352  WRITE_FLAG( pcPPS->getInferScalingListFlag() ? 1 : 0, "pps_infer_scaling_list_flag" );
     353  if( pcPPS->getInferScalingListFlag() )
     354  {
     355    // The value of pps_scaling_list_ref_layer_id shall be in the range of 0 to 62, inclusive
     356    assert( pcPPS->getScalingListRefLayerId() <= 62 );
     357    WRITE_UVLC( pcPPS->getScalingListRefLayerId(), "pps_scaling_list_ref_layer_id" );
     358  }
     359#endif
     360
     361#if REF_REGION_OFFSET
     362  WRITE_UVLC( pcPPS->getNumScaledRefLayerOffsets(),      "num_ref_loc_offsets" );
     363  for(Int i = 0; i < pcPPS->getNumScaledRefLayerOffsets(); i++)
     364  {
     365    WRITE_CODE( pcPPS->getScaledRefLayerId(i), 6, "ref_loc_offset_layer_id" );
     366    WRITE_FLAG( pcPPS->getScaledRefLayerOffsetPresentFlag(i) ? 1 : 0, "scaled_ref_layer_offset_prsent_flag" );
     367    if (pcPPS->getScaledRefLayerOffsetPresentFlag(i))
     368    {
     369      Window scaledWindow = pcPPS->getScaledRefLayerWindow(i);
     370      WRITE_SVLC( scaledWindow.getWindowLeftOffset()   >> 1, "scaled_ref_layer_left_offset" );
     371      WRITE_SVLC( scaledWindow.getWindowTopOffset()    >> 1, "scaled_ref_layer_top_offset" );
     372      WRITE_SVLC( scaledWindow.getWindowRightOffset()  >> 1, "scaled_ref_layer_right_offset" );
     373      WRITE_SVLC( scaledWindow.getWindowBottomOffset() >> 1, "scaled_ref_layer_bottom_offset" );
     374    }
     375    WRITE_FLAG( pcPPS->getRefRegionOffsetPresentFlag(i) ? 1 : 0, "ref_region_offset_prsent_flag" );
     376    if (pcPPS->getRefRegionOffsetPresentFlag(i))
     377    {
     378      Window refWindow = pcPPS->getRefLayerWindow(i);
     379      WRITE_SVLC( refWindow.getWindowLeftOffset()   >> 1, "ref_region_left_offset" );
     380      WRITE_SVLC( refWindow.getWindowTopOffset()    >> 1, "ref_region_top_offset" );
     381      WRITE_SVLC( refWindow.getWindowRightOffset()  >> 1, "ref_region_right_offset" );
     382      WRITE_SVLC( refWindow.getWindowBottomOffset() >> 1, "ref_region_bottom_offset" );
     383    }
     384#if R0209_GENERIC_PHASE
     385    WRITE_FLAG( pcPPS->getResamplePhaseSetPresentFlag(i) ? 1 : 0, "resample_phase_set_present_flag" );
     386    if (pcPPS->getResamplePhaseSetPresentFlag(i))
     387    {
     388      WRITE_UVLC( pcPPS->getPhaseHorLuma(i), "phase_hor_luma" );
     389      WRITE_UVLC( pcPPS->getPhaseVerLuma(i), "phase_ver_luma" );
     390      WRITE_UVLC( pcPPS->getPhaseHorChroma(i) + 8, "phase_hor_chroma_plus8" );
     391      WRITE_UVLC( pcPPS->getPhaseVerChroma(i) + 8, "phase_ver_chroma_plus8" );
     392    }
     393#endif
     394  }
     395#else
     396#if MOVE_SCALED_OFFSET_TO_PPS
     397  WRITE_UVLC( pcPPS->getNumScaledRefLayerOffsets(),      "num_scaled_ref_layer_offsets" );
     398  for(Int i = 0; i < pcPPS->getNumScaledRefLayerOffsets(); i++)
     399  {
     400    Window scaledWindow = pcPPS->getScaledRefLayerWindow(i);
     401#if O0098_SCALED_REF_LAYER_ID
     402    WRITE_CODE( pcPPS->getScaledRefLayerId(i), 6,          "scaled_ref_layer_id" );
     403#endif
     404    WRITE_SVLC( scaledWindow.getWindowLeftOffset()   >> 1, "scaled_ref_layer_left_offset" );
     405    WRITE_SVLC( scaledWindow.getWindowTopOffset()    >> 1, "scaled_ref_layer_top_offset" );
     406    WRITE_SVLC( scaledWindow.getWindowRightOffset()  >> 1, "scaled_ref_layer_right_offset" );
     407    WRITE_SVLC( scaledWindow.getWindowBottomOffset() >> 1, "scaled_ref_layer_bottom_offset" );
     408  }
     409#endif
     410#endif
     411#if Q0048_CGS_3D_ASYMLUT
     412  UInt uiPos = getNumberOfWrittenBits();
     413  WRITE_FLAG( pcPPS->getCGSFlag() , "colour_mapping_enabled_flag" );
     414  if( pcPPS->getCGSFlag() )
     415  {
     416    assert( pc3DAsymLUT != NULL );
     417    xCode3DAsymLUT( pc3DAsymLUT );
     418  }
     419  pc3DAsymLUT->setPPSBit( getNumberOfWrittenBits() - uiPos );
     420#endif
     421#endif
    287422  }
    288423#else
     
    340475  if( defaultDisplayWindow.getWindowEnabledFlag() )
    341476  {
    342     WRITE_UVLC(defaultDisplayWindow.getWindowLeftOffset(),      "def_disp_win_left_offset");
    343     WRITE_UVLC(defaultDisplayWindow.getWindowRightOffset(),    "def_disp_win_right_offset");
    344     WRITE_UVLC(defaultDisplayWindow.getWindowTopOffset(),      "def_disp_win_top_offset");
    345     WRITE_UVLC(defaultDisplayWindow.getWindowBottomOffset(),    "def_disp_win_bottom_offset");
     477    WRITE_UVLC(defaultDisplayWindow.getWindowLeftOffset()  / TComSPS::getWinUnitX(pcSPS->getChromaFormatIdc()), "def_disp_win_left_offset");
     478    WRITE_UVLC(defaultDisplayWindow.getWindowRightOffset() / TComSPS::getWinUnitX(pcSPS->getChromaFormatIdc()), "def_disp_win_right_offset");
     479    WRITE_UVLC(defaultDisplayWindow.getWindowTopOffset()   / TComSPS::getWinUnitY(pcSPS->getChromaFormatIdc()), "def_disp_win_top_offset");
     480    WRITE_UVLC(defaultDisplayWindow.getWindowBottomOffset()/ TComSPS::getWinUnitY(pcSPS->getChromaFormatIdc()), "def_disp_win_bottom_offset");
    346481  }
    347482  TimingInfo *timingInfo = pcVUI->getTimingInfo();
     
    452587Void TEncCavlc::codeSPS( TComSPS* pcSPS )
    453588{
     589#if R0042_PROFILE_INDICATION
     590  Bool bMultiLayerExtSpsFlag = (pcSPS->getNumDirectRefLayers() != 0 ) ;
     591#endif
    454592#if ENC_DEC_TRACE 
    455593  xTraceSPSHeader (pcSPS);
     
    461599#endif
    462600    WRITE_CODE( pcSPS->getMaxTLayers() - 1,  3,       "sps_max_sub_layers_minus1" );
     601#if SVC_EXTENSION
     602  }
     603#if R0042_PROFILE_INDICATION
     604  else
     605  {
     606    WRITE_CODE(bMultiLayerExtSpsFlag? 7:(pcSPS->getMaxTLayers() - 1) ,  3,       "sps_ext_or_max_sub_layers_minus1" );
     607  }
     608#endif
     609#endif
     610
     611#if SVC_EXTENSION
     612#if !R0042_PROFILE_INDICATION
     613  if(pcSPS->getLayerId() == 0)
     614#else
     615  if(!bMultiLayerExtSpsFlag)
     616#endif
     617  {
     618#endif
    463619    WRITE_FLAG( pcSPS->getTemporalIdNestingFlag() ? 1 : 0,                             "sps_temporal_id_nesting_flag" );
    464620#if SVC_EXTENSION
     
    466622#endif
    467623#ifdef SPS_PTL_FIX
     624#if !R0042_PROFILE_INDICATION
    468625  if (pcSPS->getLayerId() == 0)
     626#else
     627  if(!bMultiLayerExtSpsFlag)
     628#endif
    469629  {
    470630    codePTL(pcSPS->getPTL(), 1, pcSPS->getMaxTLayers() - 1);
     
    475635  WRITE_UVLC( pcSPS->getSPSId (),                   "sps_seq_parameter_set_id" );
    476636#if REPN_FORMAT_IN_VPS
     637#if !R0042_PROFILE_INDICATION
    477638  if( pcSPS->getLayerId() > 0 )
     639#else
     640  if(bMultiLayerExtSpsFlag)
     641#endif
    478642  {
    479643    WRITE_FLAG( pcSPS->getUpdateRepFormatFlag(), "update_rep_format_flag" );
    480644  }
     645#if R0042_PROFILE_INDICATION
     646  if( bMultiLayerExtSpsFlag && pcSPS->getUpdateRepFormatFlag())
     647  {
     648    WRITE_CODE( pcSPS->getUpdateRepFormatIndex(), 8,   "sps_rep_format_idx");
     649  }
     650#endif
     651
     652#if R0042_PROFILE_INDICATION
     653  if(!bMultiLayerExtSpsFlag)
     654  {
     655#endif
     656#if !R0042_PROFILE_INDICATION
    481657#if O0096_REP_FORMAT_INDEX
    482658  if( pcSPS->getLayerId() == 0 )
    483659#else
    484660  if( pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() )
     661#endif
    485662#endif
    486663  {
     
    498675#if REPN_FORMAT_IN_VPS
    499676  }
     677#if !R0042_PROFILE_INDICATION
    500678#if O0096_REP_FORMAT_INDEX
    501679  else if (pcSPS->getUpdateRepFormatFlag())
     
    505683#endif
    506684#endif
    507   Window conf = pcSPS->getConformanceWindow();
    508 
    509   WRITE_FLAG( conf.getWindowEnabledFlag(),          "conformance_window_flag" );
    510   if (conf.getWindowEnabledFlag())
    511   {
     685#endif
     686
     687#if R0156_CONF_WINDOW_IN_REP_FORMAT
    512688#if REPN_FORMAT_IN_VPS
    513     WRITE_UVLC( conf.getWindowLeftOffset(),   "conf_win_left_offset"   );
    514     WRITE_UVLC( conf.getWindowRightOffset(),  "conf_win_right_offset"  );
    515     WRITE_UVLC( conf.getWindowTopOffset(),    "conf_win_top_offset"    );
    516     WRITE_UVLC( conf.getWindowBottomOffset(), "conf_win_bottom_offset" );
    517 #else
    518     WRITE_UVLC( conf.getWindowLeftOffset()   / TComSPS::getWinUnitX(pcSPS->getChromaFormatIdc() ), "conf_win_left_offset" );
    519     WRITE_UVLC( conf.getWindowRightOffset()  / TComSPS::getWinUnitX(pcSPS->getChromaFormatIdc() ), "conf_win_right_offset" );
    520     WRITE_UVLC( conf.getWindowTopOffset()    / TComSPS::getWinUnitY(pcSPS->getChromaFormatIdc() ), "conf_win_top_offset" );
    521     WRITE_UVLC( conf.getWindowBottomOffset() / TComSPS::getWinUnitY(pcSPS->getChromaFormatIdc() ), "conf_win_bottom_offset" );
    522 #endif
    523   }
    524 
    525 #if REPN_FORMAT_IN_VPS
     689#if !R0042_PROFILE_INDICATION
    526690#if O0096_REP_FORMAT_INDEX
    527691  if( pcSPS->getLayerId() == 0 )
     
    529693  if( pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() )
    530694#endif 
     695#endif
     696  {
     697#endif
     698#endif
     699    Window conf = pcSPS->getConformanceWindow();
     700
     701    WRITE_FLAG( conf.getWindowEnabledFlag(),          "conformance_window_flag" );
     702    if (conf.getWindowEnabledFlag())
     703    {
     704#if REPN_FORMAT_IN_VPS
     705      WRITE_UVLC( conf.getWindowLeftOffset(),   "conf_win_left_offset"   );
     706      WRITE_UVLC( conf.getWindowRightOffset(),  "conf_win_right_offset"  );
     707      WRITE_UVLC( conf.getWindowTopOffset(),    "conf_win_top_offset"    );
     708      WRITE_UVLC( conf.getWindowBottomOffset(), "conf_win_bottom_offset" );
     709#else
     710      WRITE_UVLC( conf.getWindowLeftOffset()   / TComSPS::getWinUnitX(pcSPS->getChromaFormatIdc() ), "conf_win_left_offset" );
     711      WRITE_UVLC( conf.getWindowRightOffset()  / TComSPS::getWinUnitX(pcSPS->getChromaFormatIdc() ), "conf_win_right_offset" );
     712      WRITE_UVLC( conf.getWindowTopOffset()    / TComSPS::getWinUnitY(pcSPS->getChromaFormatIdc() ), "conf_win_top_offset" );
     713      WRITE_UVLC( conf.getWindowBottomOffset() / TComSPS::getWinUnitY(pcSPS->getChromaFormatIdc() ), "conf_win_bottom_offset" );
     714#endif
     715    }
     716#if R0156_CONF_WINDOW_IN_REP_FORMAT
     717#if REPN_FORMAT_IN_VPS
     718  }
     719#endif
     720#endif
     721
     722#if REPN_FORMAT_IN_VPS
     723#if !R0042_PROFILE_INDICATION
     724#if O0096_REP_FORMAT_INDEX
     725  if( pcSPS->getLayerId() == 0 )
     726#else
     727  if( pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() )
     728#endif
     729#endif
    531730  {
    532731    assert( pcSPS->getBitDepthY() >= 8 );
     
    538737  }
    539738#endif
     739#if R0042_PROFILE_INDICATION
     740  }
     741#endif
     742
    540743  WRITE_UVLC( pcSPS->getBitsForPOC()-4,                 "log2_max_pic_order_cnt_lsb_minus4" );
    541744
    542745#if SPS_DPB_PARAMS
     746#if !R0042_PROFILE_INDICATION
    543747  if( pcSPS->getLayerId() == 0 )
     748#else
     749  if(!bMultiLayerExtSpsFlag)
     750#endif
    544751  {
    545752#endif
     
    571778  {
    572779#if SCALINGLIST_INFERRING
     780#if !R0042_PROFILE_INDICATION
    573781    if( pcSPS->getLayerId() > 0 )
     782#else
     783    if( bMultiLayerExtSpsFlag)
     784#endif
    574785    {
    575786      WRITE_FLAG( pcSPS->getInferScalingListFlag() ? 1 : 0, "sps_infer_scaling_list_flag" );
     
    640851
    641852#if SVC_EXTENSION
     853#if !R0042_PROFILE_INDICATION
    642854  WRITE_FLAG( pcSPS->getExtensionFlag() ? 1 : 0, "sps_extension_flag" );
     855#else
     856  WRITE_FLAG( pcSPS->getExtensionFlag() ? 1 : 0, "sps_extension_present_flag" );
     857#endif
    643858
    644859  if( pcSPS->getExtensionFlag() )
    645860  {
     861#if !R0042_PROFILE_INDICATION
    646862#if O0142_CONDITIONAL_SPS_EXTENSION
    647863    UInt spsExtensionTypeFlag[8] = { 0, 1, 0, 0, 0, 0, 0, 0 };
     
    658874    WRITE_FLAG( 0, "sps_extension2_flag" );
    659875#endif
     876#else
     877    WRITE_FLAG( 0, "sps_range_extension_flag" );
     878    WRITE_FLAG( 1, "sps_multilayer_extension_flag" );
     879    WRITE_CODE( 0, 6,  "sps_extension_6bits" );   
     880    codeSPSExtension( pcSPS ); //it is sps_multilayer_extension
     881#endif
    660882  }
    661883#else
     
    672894  WRITE_FLAG( 0, "inter_view_mv_vert_constraint_flag" );
    673895
     896#if !MOVE_SCALED_OFFSET_TO_PPS
    674897  if( pcSPS->getLayerId() > 0 )
    675898  {
     
    690913    }
    691914  }
     915#endif
    692916}
    693917#endif //SVC_EXTENSION
     
    706930#endif
    707931  WRITE_CODE( pcVPS->getVPSId(),                    4,        "vps_video_parameter_set_id" );
     932#if VPS_RESERVED_FLAGS
     933  WRITE_FLAG( pcVPS->getBaseLayerInternalFlag(),              "vps_base_layer_internal_flag");
     934  WRITE_FLAG( pcVPS->getBaseLayerAvailableFlag(),             "vps_base_layer_available_flag");
     935#else
    708936  WRITE_CODE( 3,                                    2,        "vps_reserved_three_2bits" );
     937#endif
    709938#if SVC_EXTENSION
    710939  WRITE_CODE( pcVPS->getMaxLayers() - 1,            6,        "vps_max_layers_minus1" );           
     
    7741003    }
    7751004  }
     1005#if !NECESSARY_FLAG   // Already called once in TAppEncTop.cpp
    7761006#if DERIVE_LAYER_ID_LIST_VARIABLES
    7771007  pcVPS->deriveLayerIdListVariables();
     1008#endif
    7781009#endif
    7791010  TimingInfo *timingInfo = pcVPS->getTimingInfo();
     
    8481079  Int OlsHighestOutputLayerId[MAX_VPS_LAYER_SETS_PLUS1];
    8491080#endif
     1081#if LIST_OF_PTL
     1082  if( vps->getMaxLayers() > 1 && vps->getBaseLayerInternalFlag() )
     1083  {
     1084    codePTL( vps->getPTLForExtn(1), false, vps->getMaxTLayers() - 1 );
     1085  }
     1086#endif
    8501087#if VPS_EXTN_MASK_AND_DIM_INFO
    8511088  UInt i = 0, j = 0;
    852 
     1089#if !VPS_AVC_BL_FLAG_REMOVAL
    8531090  WRITE_FLAG( vps->getAvcBaseLayerFlag(),              "avc_base_layer_flag" );
     1091#endif
    8541092#if !P0307_REMOVE_VPS_VUI_OFFSET
    8551093#if O0109_MOVE_VPS_VUI_FLAG
     
    9481186    }
    9491187  }
     1188#endif
     1189#if MOVE_ADDN_LS_SIGNALLING
     1190#if Q0078_ADD_LAYER_SETS
     1191  if (vps->getNumIndependentLayers() > 1)
     1192  {
     1193    WRITE_UVLC( vps->getNumAddLayerSets(), "num_add_layer_sets" );
     1194    for (i = 0; i < vps->getNumAddLayerSets(); i++)
     1195    {
     1196      for (j = 1; j < vps->getNumIndependentLayers(); j++)
     1197      {
     1198        int len = 1;
     1199        while ((1 << len) < (vps->getNumLayersInTreePartition(j) + 1))
     1200        {
     1201          len++;
     1202        }
     1203        WRITE_CODE(vps->getHighestLayerIdxPlus1(i, j), len, "highest_layer_idx_plus1[i][j]");
     1204      }
     1205    }
     1206  }
     1207#endif
    9501208#endif
    9511209#if VPS_TSLAYERS
     
    9851243#else
    9861244  WRITE_UVLC( vps->getNumProfileTierLevel() - 1, "vps_num_profile_tier_level_minus1");
    987 #endif
     1245#if PER_LAYER_PTL
     1246  Int const numBitsForPtlIdx = vps->calculateLenOfSyntaxElement( vps->getNumProfileTierLevel() );
     1247#endif
     1248#endif
     1249#if LIST_OF_PTL
     1250  assert( vps->getNumProfileTierLevel() == vps->getPTLForExtnPtr()->size());
     1251  for(Int idx = vps->getBaseLayerInternalFlag() ? 2 : 1; idx <= vps->getNumProfileTierLevel() - 1; idx++)
     1252#else
    9881253  for(Int idx = 1; idx <= vps->getNumProfileTierLevel() - 1; idx++)
     1254#endif
    9891255  {
    9901256    WRITE_FLAG( vps->getProfilePresentFlag(idx),       "vps_profile_present_flag[i]" );
     
    9991265#endif
    10001266
     1267
     1268#if !MOVE_ADDN_LS_SIGNALLING
    10011269#if Q0078_ADD_LAYER_SETS
    10021270  if (vps->getNumIndependentLayers() > 1)
     
    10161284    }
    10171285  }
     1286#endif
    10181287#endif
    10191288
     
    10601329  for(i = 1; i < numOutputLayerSets; i++)
    10611330  {
     1331    Int layerSetIdxForOutputLayerSet = vps->getOutputLayerSetIdx(i);
    10621332    if( i > (vps->getNumLayerSets() - 1) )
    10631333    {
     
    10771347    {
    10781348#endif
    1079       Int lsIdx = vps->getOutputLayerSetIdx(i);
    10801349#if NUM_OL_FLAGS
    1081       for(j = 0; j < vps->getNumLayersInIdList(lsIdx) ; j++)
     1350      for(j = 0; j < vps->getNumLayersInIdList(layerSetIdxForOutputLayerSet) ; j++)
    10821351#else
    10831352      for(j = 0; j < vps->getNumLayersInIdList(lsIdx) - 1; j++)
     
    10871356      }
    10881357    }
     1358#if PER_LAYER_PTL
     1359    for(j = 0; j < vps->getNumLayersInIdList(layerSetIdxForOutputLayerSet) ; j++)
     1360    {
     1361      if( vps->getNecessaryLayerFlag(i, j) )
     1362      {
     1363        WRITE_CODE( vps->getProfileLevelTierIdx(i, j), numBitsForPtlIdx, "profile_level_tier_idx[i]" );
     1364      }
     1365    }
     1366#else
    10891367    Int numBits = 1;
    10901368    while ((1 << numBits) < (vps->getNumProfileTierLevel()))
     
    10931371    }
    10941372    WRITE_CODE( vps->getProfileLevelTierIdx(i), numBits, "profile_level_tier_idx[i]" );     
     1373#endif
    10951374#if P0300_ALT_OUTPUT_LAYER_FLAG
    10961375    NumOutputLayersInOutputLayerSet[i] = 0;
    1097     Int layerSetIdxForOutputLayerSet = vps->getOutputLayerSetIdx(i);
    10981376    for (j = 0; j < vps->getNumLayersInIdList(layerSetIdxForOutputLayerSet); j++)
    10991377    {
     
    12111489
    12121490  WRITE_FLAG(vps->getMaxOneActiveRefLayerFlag(), "max_one_active_ref_layer_flag");
     1491#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     1492  WRITE_FLAG(vps->getVpsPocLsbAlignedFlag(), "vps_poc_lsb_aligned_flag");
     1493#endif
    12131494#if O0062_POC_LSB_NOT_PRESENT_FLAG
    12141495  for(i = 1; i< vps->getMaxLayers(); i++)
     
    13671648  WRITE_CODE( repFormat->getBitDepthVpsChroma() - 8, 4, "bit_depth_chroma_minus8" );
    13681649#endif
     1650
     1651#if R0156_CONF_WINDOW_IN_REP_FORMAT
     1652  Window conf = repFormat->getConformanceWindowVps();
     1653
     1654  WRITE_FLAG( conf.getWindowEnabledFlag(),    "conformance_window_vps_flag" );
     1655  if (conf.getWindowEnabledFlag())
     1656  {
     1657    WRITE_UVLC( conf.getWindowLeftOffset(),   "conf_win_vps_left_offset"   );
     1658    WRITE_UVLC( conf.getWindowRightOffset(),  "conf_win_vps_right_offset"  );
     1659    WRITE_UVLC( conf.getWindowTopOffset(),    "conf_win_vps_top_offset"    );
     1660    WRITE_UVLC( conf.getWindowBottomOffset(), "conf_win_vps_bottom_offset" );
     1661  }
     1662#endif
    13691663}
    13701664#endif
     
    13721666Void TEncCavlc::codeVpsDpbSizeTable(TComVPS *vps)
    13731667{
     1668#if !SUB_LAYERS_IN_LAYER_SET  // MaxSLInLayerSets calculated earlier in the encoder
    13741669#if DPB_PARAMS_MAXTLAYERS
    13751670#if BITRATE_PICRATE_SIGNALLING
     
    14001695    }
    14011696#endif
     1697#endif
    14021698   
    14031699   
     
    14081704#endif
    14091705    WRITE_FLAG( vps->getSubLayerFlagInfoPresentFlag( i ), "sub_layer_flag_info_present_flag[i]");
     1706#if SUB_LAYERS_IN_LAYER_SET
     1707    for(Int j = 0; j <= vps->getMaxSLayersInLayerSetMinus1( layerSetIdxForOutputLayerSet ); j++)
     1708#else
    14101709#if DPB_PARAMS_MAXTLAYERS
    14111710#if BITRATE_PICRATE_SIGNALLING
     
    14171716    for(Int j = 0; j < vps->getMaxTLayers(); j++)
    14181717#endif
     1718#endif
    14191719    {
    14201720      if( j > 0 && vps->getSubLayerFlagInfoPresentFlag(i) )
     
    14341734#endif
    14351735        {
    1436           WRITE_UVLC( vps->getMaxVpsDecPicBufferingMinus1( i, k, j), "max_vps_dec_pic_buffering_minus1[i][k][j]" );
     1736#if DPB_INTERNAL_BL_SIG
     1737        if(vps->getBaseLayerInternalFlag()  || ( vps->getLayerSetLayerIdList(layerSetIdxForOutputLayerSet, k)   !=  0 ) )
     1738#endif
     1739          WRITE_UVLC( vps->getMaxVpsDecPicBufferingMinus1( i, k, j), "max_vps_dec_pic_buffering_minus1[i][k][j]" );
    14371740        }
    14381741        WRITE_UVLC( vps->getMaxVpsNumReorderPics( i, j), "max_vps_num_reorder_pics[i][j]" );             
     
    14501753    }
    14511754  }
     1755
     1756#if !SUB_LAYERS_IN_LAYER_SET
     1757#if BITRATE_PICRATE_SIGNALLING
     1758  if( MaxSubLayersInLayerSetMinus1 )
     1759  {
     1760    delete [] MaxSubLayersInLayerSetMinus1;
     1761  }
     1762#endif
     1763#endif
    14521764}
    14531765#endif
     
    14791791  {
    14801792#if Q0078_ADD_LAYER_SETS
     1793#if R0227_BR_PR_ADD_LAYER_SET
     1794#if SIGNALLING_BITRATE_PICRATE_FIX
     1795    for( i = vps->getBaseLayerInternalFlag() ? 0 : 1; i < vps->getNumLayerSets(); i++ )
     1796#else
     1797    for( i = 0; i < vps->getNumLayerSets(); i++ )
     1798#endif
     1799#else
    14811800    for( i = 0; i <= vps->getVpsNumLayerSetsMinus1(); i++ )
     1801#endif
    14821802#else
    14831803    for( i = 0; i < vps->getNumLayerSets(); i++ )
     
    15291849  if (vps->getVideoSigPresentVpsFlag() && vps->getNumVideoSignalInfo() > 1 )
    15301850  {
     1851#if VPS_VUI_VST_PARAMS
     1852    for(i = vps->getBaseLayerInternalFlag() ? 0 : 1; i < vps->getMaxLayers(); i++)
     1853    {
     1854      WRITE_CODE( vps->getVideoSignalInfoIdx(i), 4, "vps_video_signal_info_idx" );
     1855    }
     1856#else
    15311857    for (i=1; i < vps->getMaxLayers(); i++)
    15321858      WRITE_CODE(vps->getVideoSignalInfoIdx(i), 4, "vps_video_signal_info_idx" );
     1859#endif
    15331860  }
    15341861#endif
     
    16451972    if (vps->getVpsVuiBspHrdPresentFlag())
    16461973    {
     1974#if VPS_VUI_BSP_HRD_PARAMS
     1975      codeVpsVuiBspHrdParams(vps);
     1976#else
    16471977      WRITE_UVLC( vps->getVpsNumBspHrdParametersMinus1(), "vps_num_bsp_hrd_parameters_minus1" );
    16481978      for( i = 0; i <= vps->getVpsNumBspHrdParametersMinus1(); i++ )
     
    16882018        }
    16892019      }
     2020#endif
    16902021    }
    16912022#endif
     
    17862117    }
    17872118#else
     2119#if CROSS_LAYER_BLA_FLAG_FIX
     2120    Int iBits = 0;
     2121    if(pcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits)
     2122#else
    17882123    if (pcSlice->getPPS()->getNumExtraSliceHeaderBits()>0)
     2124#endif
    17892125    {
    17902126      assert(!!"discardable_flag");
     2127#if NON_REF_NAL_TYPE_DISCARDABLE
     2128      if (pcSlice->getDiscardableFlag())
     2129      {
     2130        assert(pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_TRAIL_R &&
     2131          pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_TSA_R &&
     2132          pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_STSA_R &&
     2133          pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_RADL_R &&
     2134          pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_RASL_R);
     2135      }
     2136#endif
    17912137      WRITE_FLAG(pcSlice->getDiscardableFlag(), "discardable_flag");
    1792     }
     2138#if CROSS_LAYER_BLA_FLAG_FIX
     2139      iBits++;
     2140#endif
     2141    }
     2142#if CROSS_LAYER_BLA_FLAG_FIX
     2143    if( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits )
     2144    {
     2145      assert(!!"cross_layer_bla_flag");
     2146      WRITE_FLAG(pcSlice->getCrossLayerBLAFlag(), "cross_layer_bla_flag");
     2147      iBits++;
     2148    }
     2149    for (; iBits < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); iBits++)
     2150#else
    17932151    for (Int i = 1; i < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
     2152#endif
    17942153    {
    17952154      assert(!!"slice_reserved_undetermined_flag[]");
     
    19782337      if (pcSlice->getSPS()->getTMVPFlagsPresent())
    19792338      {
     2339#if R0226_SLICE_TMVP
     2340        WRITE_FLAG( pcSlice->getEnableTMVPFlag() ? 1 : 0, "slice_temporal_mvp_enabled_flag" );
     2341#else
    19802342        WRITE_FLAG( pcSlice->getEnableTMVPFlag() ? 1 : 0, "slice_temporal_mvp_enable_flag" );
     2343#endif
    19812344      }
    19822345#if N0065_LAYER_POC_ALIGNMENT && !SHM_FIX7
     
    22622625  }
    22632626  UInt numEntryPointOffsets = 0, offsetLenMinus1 = 0, maxOffset = 0;
     2627#if !WPP_FIX
    22642628  Int  numZeroSubstreamsAtStartOfSlice  = 0;
     2629#endif
    22652630  UInt *entryPointOffset = NULL;
    22662631  if ( pSlice->getPPS()->getTilesEnabledFlag() )
     
    22892654    UInt* pSubstreamSizes               = pSlice->getSubstreamSizes();
    22902655    Int maxNumParts                       = pSlice->getPic()->getNumPartInCU();
     2656#if WPP_FIX
     2657    Int  numZeroSubstreamsAtStartOfSlice  = pSlice->getPic()->getSubstreamForLCUAddr(pSlice->getSliceSegmentCurStartCUAddr()/maxNumParts, false, pSlice);
     2658    Int  subStreamOfLastSegmentOfSlice    = pSlice->getPic()->getSubstreamForLCUAddr((pSlice->getSliceSegmentCurEndCUAddr()/maxNumParts)-1, false, pSlice);
     2659    numEntryPointOffsets                  = subStreamOfLastSegmentOfSlice-numZeroSubstreamsAtStartOfSlice;
     2660#else
    22912661    numZeroSubstreamsAtStartOfSlice       = pSlice->getSliceSegmentCurStartCUAddr()/maxNumParts/pSlice->getPic()->getFrameWidthInCU();
    22922662    Int  numZeroSubstreamsAtEndOfSlice    = pSlice->getPic()->getFrameHeightInCU()-1 - ((pSlice->getSliceSegmentCurEndCUAddr()-1)/maxNumParts/pSlice->getPic()->getFrameWidthInCU());
    22932663    numEntryPointOffsets                  = pSlice->getPPS()->getNumSubstreams() - numZeroSubstreamsAtStartOfSlice - numZeroSubstreamsAtEndOfSlice - 1;
     2664#endif
    22942665    pSlice->setNumEntryPointOffsets(numEntryPointOffsets);
    22952666    entryPointOffset           = new UInt[numEntryPointOffsets];
     
    23332704  {
    23342705    // Derive the value of PocMsbValRequiredFlag
    2335     slice->setPocMsbValRequiredFlag( slice->getCraPicFlag() || slice->getBlaPicFlag()
    2336                                           /* || related to vps_poc_lsb_aligned_flag */
    2337                                           );
     2706#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     2707    slice->setPocMsbValRequiredFlag( (slice->getCraPicFlag() || slice->getBlaPicFlag())
     2708                                  && (!slice->getVPS()->getVpsPocLsbAlignedFlag() ||
     2709                                      (slice->getVPS()->getVpsPocLsbAlignedFlag() && slice->getVPS()->getNumDirectRefLayers(slice->getLayerId()) == 0))
     2710                                   );
     2711#else
     2712    slice->setPocMsbValRequiredFlag( slice->getCraPicFlag() || slice->getBlaPicFlag() );
     2713#endif
    23382714
    23392715    // Determine value of SH extension length.
     
    23532729
    23542730
    2355     if( !slice->getPocMsbValRequiredFlag() /* &&  vps_poc_lsb_aligned_flag */ )
     2731#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     2732    if (!slice->getPocMsbValRequiredFlag() && slice->getVPS()->getVpsPocLsbAlignedFlag())
     2733#else
     2734    if (!slice->getPocMsbValRequiredFlag() /* &&  vps_poc_lsb_aligned_flag */)
     2735#endif
    23562736    {
    23572737      shExtnLengthInBit++;
     
    23692749    }
    23702750
    2371     if( slice->getPocMsbValPresentFlag() )
     2751#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     2752    if (slice->getPocMsbNeeded())
     2753    {
     2754      slice->setPocMsbValPresentFlag(true);
     2755    }
     2756#endif
     2757
     2758    if (slice->getPocMsbValPresentFlag())
    23722759    {
    23732760      UInt lengthVal = 1;
     
    24032790    }
    24042791
    2405     if( !slice->getPocMsbValRequiredFlag() /* &&  vps_poc_lsb_aligned_flag */ )
    2406     {
     2792#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     2793    if (!slice->getPocMsbValRequiredFlag() && slice->getVPS()->getVpsPocLsbAlignedFlag())
     2794#else
     2795    if (!slice->getPocMsbValRequiredFlag() /* &&  vps_poc_lsb_aligned_flag */)
     2796#endif
     2797    {
     2798#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     2799      WRITE_FLAG( slice->getPocMsbValPresentFlag(),                           "poc_msb_cycle_val_present_flag" );
     2800#else
    24072801      WRITE_FLAG( slice->getPocMsbValPresentFlag(),                           "poc_msb_val_present_flag" );
    2408     }
    2409     if( slice->getPocMsbValPresentFlag() )
    2410     {
    2411       assert( slice->getPocMsbVal() % maxPocLsb == 0 );
    2412       WRITE_UVLC( slice->getPocMsbVal() / maxPocLsb,                                      "poc_msb_val" );
     2802#endif
     2803    }
     2804    if (slice->getPocMsbValPresentFlag())
     2805    {
     2806      assert(slice->getPocMsbVal() % maxPocLsb == 0);
     2807#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     2808      WRITE_UVLC(slice->getPocMsbVal() / maxPocLsb, "poc_msb_cycle_val");
     2809#else
     2810      WRITE_UVLC(slice->getPocMsbVal() / maxPocLsb, "poc_msb_val");
     2811#endif
    24132812    }
    24142813    for (Int i = 0; i < shExtnAdditionalBits; i++)
     
    27553154Void TEncCavlc::xCode3DAsymLUT( TCom3DAsymLUT * pc3DAsymLUT )
    27563155{
     3156#if R0150_CGS_SIGNAL_CONSTRAINTS
     3157  UInt uiNumRefLayers = ( UInt )pc3DAsymLUT->getRefLayerNum();
     3158  WRITE_UVLC( uiNumRefLayers - 1 , "num_cm_ref_layers_minus1" );
     3159  for( UInt i = 0 ; i < uiNumRefLayers ; i++ )
     3160  {
     3161    WRITE_CODE( pc3DAsymLUT->getRefLayerId( i ) , 6 , "cm_ref_layer_id" );
     3162  }
     3163#endif
    27573164  assert( pc3DAsymLUT->getCurOctantDepth() < 4 );
    27583165  WRITE_CODE( pc3DAsymLUT->getCurOctantDepth() , 2 , "cm_octant_depth" );
     
    27603167  WRITE_CODE( pc3DAsymLUT->getCurYPartNumLog2() , 2 , "cm_y_part_num_log2" );
    27613168  assert( pc3DAsymLUT->getInputBitDepthY() < 16 );
     3169#if R0150_CGS_SIGNAL_CONSTRAINTS
     3170  WRITE_UVLC( pc3DAsymLUT->getInputBitDepthY() - 8 , "cm_input_luma_bit_depth_minus8" );
     3171  WRITE_UVLC( pc3DAsymLUT->getInputBitDepthC() - 8 , "cm_input_chroma_bit_depth_minus8" );
     3172  WRITE_UVLC( pc3DAsymLUT->getOutputBitDepthY() - 8 , "cm_output_luma_bit_depth_minus8" );
     3173  WRITE_UVLC( pc3DAsymLUT->getOutputBitDepthC() - 8 , "cm_output_chroma_bit_depth_minus8" );
     3174#else
    27623175  WRITE_CODE( pc3DAsymLUT->getInputBitDepthY() - 8 , 3 , "cm_input_bit_depth_minus8" );
    27633176  WRITE_SVLC(pc3DAsymLUT->getInputBitDepthC()-pc3DAsymLUT->getInputBitDepthY(), "cm_input_bit_depth_chroma delta");
     
    27653178  WRITE_CODE( pc3DAsymLUT->getOutputBitDepthY() - 8 , 3 , "cm_output_bit_depth_minus8" );
    27663179  WRITE_SVLC(pc3DAsymLUT->getOutputBitDepthC()-pc3DAsymLUT->getOutputBitDepthY(), "cm_output_bit_depth_chroma_delta");
     3180#endif
    27673181  assert( pc3DAsymLUT->getResQuantBit() < 4 );
    27683182  WRITE_CODE( pc3DAsymLUT->getResQuantBit() , 2 , "cm_res_quant_bit" );
    2769 
     3183#if R0300_CGS_RES_COEFF_CODING
     3184  xFindDeltaBits( pc3DAsymLUT );
     3185  assert(pc3DAsymLUT->getDeltaBits() >=1 && pc3DAsymLUT->getDeltaBits() <= 4);
     3186  WRITE_CODE( pc3DAsymLUT->getDeltaBits()-1 , 2 , "cm_delta_bit" );
     3187#endif
     3188#if R0151_CGS_3D_ASYMLUT_IMPROVE
     3189  if( pc3DAsymLUT->getCurOctantDepth() == 1 )
     3190  {
     3191    WRITE_SVLC( pc3DAsymLUT->getAdaptChromaThresholdU() - ( 1 << ( pc3DAsymLUT->getInputBitDepthC() - 1 ) ) , "cm_adapt_threshold_u_delta" );
     3192    WRITE_SVLC( pc3DAsymLUT->getAdaptChromaThresholdV() - ( 1 << ( pc3DAsymLUT->getInputBitDepthC() - 1 ) ) , "cm_adapt_threshold_v_delta" );
     3193  }
     3194#endif
     3195
     3196#if R0164_CGS_LUT_BUGFIX_CHECK
     3197  pc3DAsymLUT->xInitCuboids();
     3198#endif
    27703199  xCode3DAsymLUTOctant( pc3DAsymLUT , 0 , 0 , 0 , 0 , 1 << pc3DAsymLUT->getCurOctantDepth() );
     3200#if R0164_CGS_LUT_BUGFIX_CHECK
     3201  xCuboidsFilledCheck( false );
     3202  pc3DAsymLUT->display( false );
     3203#endif
    27713204}
    27723205
     
    27933226  else
    27943227  {
     3228#if R0300_CGS_RES_COEFF_CODING
     3229    Int nFLCbits = pc3DAsymLUT->getMappingShift()-pc3DAsymLUT->getResQuantBit()-pc3DAsymLUT->getDeltaBits() ;
     3230    nFLCbits = nFLCbits >= 0 ? nFLCbits : 0;
     3231#endif
    27953232    for( Int l = 0 ; l < nYPartNum ; l++ )
    27963233    {
     3234#if R0164_CGS_LUT_BUGFIX     
     3235      Int shift = pc3DAsymLUT->getCurOctantDepth() - nDepth ;
     3236#endif
    27973237      for( Int nVertexIdx = 0 ; nVertexIdx < 4 ; nVertexIdx++ )
    27983238      {
     3239#if R0164_CGS_LUT_BUGFIX
     3240        SYUVP sRes = pc3DAsymLUT->getCuboidVertexResTree( yIdx + (l<<shift) , uIdx , vIdx , nVertexIdx );
     3241#else
    27993242        SYUVP sRes = pc3DAsymLUT->getCuboidVertexResTree( yIdx + l , uIdx , vIdx , nVertexIdx );
     3243#endif
    28003244        UInt uiCodeVertex = sRes.Y != 0 || sRes.U != 0 || sRes.V != 0;
    28013245        WRITE_FLAG( uiCodeVertex , "coded_vertex_flag" );
    28023246        if( uiCodeVertex )
    28033247        {
     3248#if R0151_CGS_3D_ASYMLUT_IMPROVE
     3249#if R0300_CGS_RES_COEFF_CODING
     3250          xWriteParam( sRes.Y, nFLCbits );
     3251          xWriteParam( sRes.U, nFLCbits );
     3252          xWriteParam( sRes.V, nFLCbits );
     3253#else
     3254          xWriteParam( sRes.Y );
     3255          xWriteParam( sRes.U );
     3256          xWriteParam( sRes.V );
     3257#endif
     3258#else
    28043259          WRITE_SVLC( sRes.Y , "resY" );
    28053260          WRITE_SVLC( sRes.U , "resU" );
    28063261          WRITE_SVLC( sRes.V , "resV" );
    2807         }
    2808       }
    2809     }
    2810   }
    2811 }
     3262#endif
     3263        }
     3264      }
     3265#if R0164_CGS_LUT_BUGFIX_CHECK
     3266      pc3DAsymLUT->xSetExplicit( yIdx + (l<<shift) , uIdx , vIdx );
     3267#endif
     3268    }
     3269  }
     3270}
     3271
     3272#if R0151_CGS_3D_ASYMLUT_IMPROVE
     3273#if R0300_CGS_RES_COEFF_CODING
     3274Void TEncCavlc::xWriteParam( Int param, UInt rParam)
     3275#else
     3276Void TEncCavlc::xWriteParam( Int param)
     3277#endif
     3278{
     3279#if !R0300_CGS_RES_COEFF_CODING
     3280  const UInt rParam = 7;
     3281#endif
     3282  Int codeNumber = abs(param);
     3283  WRITE_UVLC(codeNumber / (1 << rParam), "quotient");
     3284  WRITE_CODE((codeNumber % (1 << rParam)), rParam, "remainder");
     3285  if (abs(param))
     3286    WRITE_FLAG( param <0, "sign");
     3287}
     3288#endif
     3289
     3290#if R0300_CGS_RES_COEFF_CODING
     3291Void TEncCavlc::xFindDeltaBits( TCom3DAsymLUT * pc3DAsymLUT )
     3292{
     3293  Int nDeltaBits;
     3294  Int nBestDeltaBits = -1;
     3295  Int nBestBits = MAX_INT;
     3296  for( nDeltaBits = 1; nDeltaBits < 5; nDeltaBits++)
     3297  {
     3298    Int nCurBits = 0;
     3299    xTally3DAsymLUTOctantBits( pc3DAsymLUT , 0 , 0 , 0 , 0 , 1 << pc3DAsymLUT->getCurOctantDepth(), nDeltaBits, nCurBits );
     3300    //printf("%d, %d, %d\n", nDeltaBits, nCurBits, nBestBits);
     3301    if(nCurBits < nBestBits)
     3302    {
     3303      nBestDeltaBits = nDeltaBits;
     3304      nBestBits = nCurBits;
     3305    }
     3306  }
     3307
     3308  assert(nBestDeltaBits >=1 && nBestDeltaBits < 5);
     3309  pc3DAsymLUT->setDeltaBits(nBestDeltaBits);
     3310}
     3311
     3312Void TEncCavlc::xTally3DAsymLUTOctantBits( TCom3DAsymLUT * pc3DAsymLUT , Int nDepth , Int yIdx , Int uIdx , Int vIdx , Int nLength, Int nDeltaBits, Int& nCurBits )
     3313{
     3314  UInt uiOctantSplit = nDepth < pc3DAsymLUT->getCurOctantDepth();
     3315  if( nDepth < pc3DAsymLUT->getCurOctantDepth() )
     3316    nCurBits ++;
     3317  Int nYPartNum = 1 << pc3DAsymLUT->getCurYPartNumLog2();
     3318  if( uiOctantSplit )
     3319  {
     3320    Int nHalfLength = nLength >> 1;
     3321    for( Int l = 0 ; l < 2 ; l++ )
     3322    {
     3323      for( Int m = 0 ; m < 2 ; m++ )
     3324      {
     3325        for( Int n = 0 ; n < 2 ; n++ )
     3326        {
     3327          xTally3DAsymLUTOctantBits( pc3DAsymLUT , nDepth + 1 , yIdx + l * nHalfLength * nYPartNum , uIdx + m * nHalfLength , vIdx + n * nHalfLength , nHalfLength, nDeltaBits, nCurBits );
     3328        }
     3329      }
     3330    }
     3331  }
     3332  else
     3333  {
     3334    Int nFLCbits = pc3DAsymLUT->getMappingShift()-pc3DAsymLUT->getResQuantBit()-nDeltaBits ;
     3335    nFLCbits = nFLCbits >= 0 ? nFLCbits:0;
     3336    //printf("nFLCbits = %d\n", nFLCbits);
     3337
     3338    for( Int l = 0 ; l < nYPartNum ; l++ )
     3339    {
     3340      for( Int nVertexIdx = 0 ; nVertexIdx < 4 ; nVertexIdx++ )
     3341      {
     3342        SYUVP sRes = pc3DAsymLUT->getCuboidVertexResTree( yIdx + l , uIdx , vIdx , nVertexIdx );
     3343
     3344        UInt uiCodeVertex = sRes.Y != 0 || sRes.U != 0 || sRes.V != 0;
     3345        nCurBits++;
     3346        if( uiCodeVertex )
     3347        {
     3348          xCheckParamBits( sRes.Y, nFLCbits, nCurBits );
     3349          xCheckParamBits( sRes.U, nFLCbits, nCurBits );
     3350          xCheckParamBits( sRes.V, nFLCbits, nCurBits );
     3351        }
     3352      }
     3353    }
     3354  }
     3355}
     3356
     3357Void TEncCavlc::xCheckParamBits( Int param, Int rParam, Int &nBits)
     3358{
     3359  Int codeNumber = abs(param);
     3360  Int codeQuotient = codeNumber >> rParam;
     3361  Int qLen;
     3362
     3363  UInt uiLength = 1;
     3364  UInt uiTemp = ++codeQuotient;
     3365   
     3366  while( 1 != uiTemp )
     3367  {
     3368    uiTemp >>= 1;
     3369    uiLength += 2;
     3370  }
     3371
     3372  qLen  = (uiLength >> 1);
     3373  qLen += ((uiLength+1) >> 1);
     3374
     3375  nBits += qLen;
     3376  nBits += rParam;
     3377  if (abs(param))
     3378    nBits++;
     3379}
     3380#endif
     3381#if VPS_VUI_BSP_HRD_PARAMS
     3382Void TEncCavlc::codeVpsVuiBspHrdParams(TComVPS * const vps)
     3383{
     3384  WRITE_UVLC( vps->getVpsNumAddHrdParams(), "vps_num_add_hrd_params" );
     3385  for( Int i = vps->getNumHrdParameters(), j = 0; i < vps->getNumHrdParameters() + vps->getVpsNumAddHrdParams(); i++, j++ ) // j = i - vps->getNumHrdParameters()
     3386  {
     3387    if( i > 0 )
     3388    {
     3389      WRITE_FLAG( vps->getCprmsAddPresentFlag(j), "cprms_add_present_flag[i]" );
     3390    }
     3391    WRITE_UVLC( vps->getNumSubLayerHrdMinus1(j), "num_sub_layer_hrd_minus1[i]" );
     3392    codeHrdParameters(vps->getBspHrd(j), i == 0 ? true : vps->getCprmsAddPresentFlag(j), vps->getNumSubLayerHrdMinus1(j));
     3393  }
     3394  for( Int h = 1; h < vps->getNumOutputLayerSets(); h++ )
     3395  {
     3396    Int lsIdx = vps->getOutputLayerSetIdx( h );
     3397    WRITE_UVLC( vps->getNumSignalledPartitioningSchemes(h), "num_signalled_partitioning_schemes[h]");
     3398    for( Int j = 0; j < vps->getNumSignalledPartitioningSchemes(h); j++ )
     3399    {
     3400      WRITE_UVLC( vps->getNumPartitionsInSchemeMinus1(h, j), "num_partitions_in_scheme_minus1[h][j]" );
     3401      for( Int k = 0; k <= vps->getNumPartitionsInSchemeMinus1(h, j); k++ )
     3402      {
     3403        for( Int r = 0; r < vps->getNumLayersInIdList( lsIdx ); r++ )
     3404        {
     3405          WRITE_FLAG( vps->getLayerIncludedInPartitionFlag(h, j, k, r), "layer_included_in_partition_flag[h][j][k][r]" );
     3406        }
     3407      }
     3408    }
     3409    for( Int i = 0; i < vps->getNumSignalledPartitioningSchemes(h) + 1; i++ )
     3410    {
     3411      for( Int t = 0; t <= vps->getMaxSLayersInLayerSetMinus1(lsIdx); t++ )
     3412      {
     3413        WRITE_UVLC(vps->getNumBspSchedulesMinus1(h, i, t), "num_bsp_schedules_minus1[h][i][t]");
     3414        for( Int j = 0; j <= vps->getNumBspSchedulesMinus1(h, i, t); j++ )
     3415        {
     3416          for( Int k = 0; k < vps->getNumPartitionsInSchemeMinus1(h, i); k++ )
     3417          {
     3418            WRITE_UVLC( vps->getBspHrdIdx(h, i, t, j, k),   "bsp_comb_hrd_idx[h][i][t][j][k]");
     3419            WRITE_UVLC( vps->getBspSchedIdx(h, i, t, j, k), "bsp_comb_sched_idx[h][i][t][j][k]");
     3420          }
     3421        }
     3422      }
     3423    }
     3424  }
     3425}
     3426#endif
    28123427#endif
    28133428//! \}
  • trunk/source/Lib/TLibEncoder/TEncCavlc.h

    r815 r906  
    169169  Void  codeVpsDpbSizeTable    (TComVPS *vps);
    170170#endif
    171 #if Q0048_CGS_3D_ASYMLUT
     171#if VPS_VUI_BSP_HRD_PARAMS
     172  Void  codeVpsVuiBspHrdParams  (TComVPS * const);
     173#endif
     174#if Q0048_CGS_3D_ASYMLUT
     175#if R0179_ENC_OPT_3DLUT_SIZE
     176public:
     177  Void xCode3DAsymLUT( TCom3DAsymLUT * pc3DAsymLUT );
     178protected:
     179  Void xCode3DAsymLUTOctant( TCom3DAsymLUT * pc3DAsymLUT , Int nDepth , Int yIdx , Int uIdx , Int vIdx , Int nLength );
     180#else
    172181protected:
    173182  Void xCode3DAsymLUT( TCom3DAsymLUT * pc3DAsymLUT );
    174183  Void xCode3DAsymLUTOctant( TCom3DAsymLUT * pc3DAsymLUT , Int nDepth , Int yIdx , Int uIdx , Int vIdx , Int nLength );
    175184#endif
     185#if R0151_CGS_3D_ASYMLUT_IMPROVE
     186#if R0300_CGS_RES_COEFF_CODING
     187  Void xWriteParam( Int param, UInt nFLCBits);
     188  Void xCheckParamBits( Int param, Int nFLCBits, Int & nCurBits);
     189  Void xTally3DAsymLUTOctantBits( TCom3DAsymLUT * pc3DAsymLUT , Int nDepth , Int yIdx , Int uIdx , Int vIdx , Int nLength, Int nDeltaBits, Int &nCurBits);
     190  Void xFindDeltaBits( TCom3DAsymLUT * pc3DAsymLUT );
     191#else
     192  Void xWriteParam( Int param);
     193#endif
     194#endif
     195#endif
    176196#endif //SVC_EXTENSION
    177197
  • trunk/source/Lib/TLibEncoder/TEncCfg.h

    r815 r906  
    107107  Int       m_iSourceWidth;
    108108  Int       m_iSourceHeight;
    109   Int       m_conformanceMode;
    110109  Window    m_conformanceWindow;
    111110  Int       m_framesToBeEncoded;
     
    208207  Bool      m_bPCMFilterDisableFlag;
    209208  Bool      m_loopFilterAcrossTilesEnabledFlag;
    210   Int       m_iUniformSpacingIdr;
     209  Bool      m_tileUniformSpacingFlag;
    211210  Int       m_iNumColumnsMinus1;
    212   UInt*     m_puiColumnWidth;
    213211  Int       m_iNumRowsMinus1;
    214   UInt*     m_puiRowHeight;
     212  std::vector<Int> m_tileColumnWidth;
     213  std::vector<Int> m_tileRowHeight;
    215214
    216215  Int       m_iWaveFrontSynchro;
     
    248247  Int*      m_codedPivotValue;
    249248  Int*      m_targetPivotValue;
    250 #if P0050_KNEE_FUNCTION_SEI
    251   Bool      m_kneeSEIEnabled;
    252   Int       m_kneeSEIId;
    253   Bool      m_kneeSEICancelFlag;
    254   Bool      m_kneeSEIPersistenceFlag;
    255   Bool      m_kneeSEIMappingFlag;
    256   Int       m_kneeSEIInputDrange;
    257   Int       m_kneeSEIInputDispLuminance;
    258   Int       m_kneeSEIOutputDrange;
    259   Int       m_kneeSEIOutputDispLuminance;
    260   Int       m_kneeSEINumKneePointsMinus1;
    261   Int*      m_kneeSEIInputKneePoint;
    262   Int*      m_kneeSEIOutputKneePoint;
    263 #endif
    264 #if Q0074_SEI_COLOR_MAPPING
    265   Char*     m_seiColorMappingFile;
    266 #endif
    267249  Int       m_framePackingSEIEnabled;
    268250  Int       m_framePackingSEIType;
     
    276258  Int       m_SOPDescriptionSEIEnabled;
    277259  Int       m_scalableNestingSEIEnabled;
    278 #if Q0189_TMVP_CONSTRAINTS
    279   Int       m_TMVPConstraintsSEIEnabled;
    280 #endif
    281260  //====== Weighted Prediction ========
    282261  Bool      m_useWeightedPred;       //< Use of Weighting Prediction (P_SLICE)
     
    388367  Int  m_nCGSMaxYPartNumLog2;
    389368  Int  m_nCGSLUTBit;
     369#if R0151_CGS_3D_ASYMLUT_IMPROVE
     370  Int  m_nCGSAdaptiveChroma;
     371#endif
     372#if R0179_ENC_OPT_3DLUT_SIZE
     373  Int  m_nCGSLutSizeRDO;
     374#endif
     375#endif
     376#if P0050_KNEE_FUNCTION_SEI
     377  Bool      m_kneeSEIEnabled;
     378  Int       m_kneeSEIId;
     379  Bool      m_kneeSEICancelFlag;
     380  Bool      m_kneeSEIPersistenceFlag;
     381  Bool      m_kneeSEIMappingFlag;
     382  Int       m_kneeSEIInputDrange;
     383  Int       m_kneeSEIInputDispLuminance;
     384  Int       m_kneeSEIOutputDrange;
     385  Int       m_kneeSEIOutputDispLuminance;
     386  Int       m_kneeSEINumKneePointsMinus1;
     387  Int*      m_kneeSEIInputKneePoint;
     388  Int*      m_kneeSEIOutputKneePoint;
     389#endif
     390#if Q0189_TMVP_CONSTRAINTS
     391  Int       m_TMVPConstraintsSEIEnabled;
    390392#endif
    391393#endif //SVC_EXTENSION
     394#if Q0074_COLOUR_REMAPPING_SEI
     395  Char*     m_colourRemapSEIFile;          ///< SEI Colour Remapping File (initialized from external file)
     396  Int       m_colourRemapSEIId;
     397  Bool      m_colourRemapSEICancelFlag;
     398  Bool      m_colourRemapSEIPersistenceFlag;
     399  Bool      m_colourRemapSEIVideoSignalInfoPresentFlag;
     400  Bool      m_colourRemapSEIFullRangeFlag;
     401  Int       m_colourRemapSEIPrimaries;
     402  Int       m_colourRemapSEITransferFunction;
     403  Int       m_colourRemapSEIMatrixCoefficients;
     404  Int       m_colourRemapSEIInputBitDepth;
     405  Int       m_colourRemapSEIBitDepth;
     406  Int       m_colourRemapSEIPreLutNumValMinus1[3];
     407  Int*      m_colourRemapSEIPreLutCodedValue[3];
     408  Int*      m_colourRemapSEIPreLutTargetValue[3];
     409  Bool      m_colourRemapSEIMatrixPresentFlag;
     410  Int       m_colourRemapSEILog2MatrixDenom;
     411  Int       m_colourRemapSEICoeffs[3][3];
     412  Int       m_colourRemapSEIPostLutNumValMinus1[3];
     413  Int*      m_colourRemapSEIPostLutCodedValue[3];
     414  Int*      m_colourRemapSEIPostLutTargetValue[3];
     415#endif
    392416
    393417public:
    394418  TEncCfg()
    395   : m_puiColumnWidth()
    396   , m_puiRowHeight()
     419  : m_tileColumnWidth()
     420  , m_tileRowHeight()
    397421  {}
    398422
    399423  virtual ~TEncCfg()
    400   {
    401     delete[] m_puiColumnWidth;
    402     delete[] m_puiRowHeight;
    403   }
     424  {}
    404425 
    405426  Void setProfile(Profile::Name profile) { m_profile = profile; }
     
    412433
    413434  Window   &getConformanceWindow()                           { return m_conformanceWindow; }
    414 #if P0312_VERT_PHASE_ADJ
     435#if P0312_VERT_PHASE_ADJ && !R0209_GENERIC_PHASE
    415436  Void      setConformanceWindow (Int confLeft, Int confRight, Int confTop, Int confBottom ) { m_conformanceWindow.setWindow (confLeft, confRight, confTop, confBottom, false); }
    416437#else
     
    437458  Void      setMaxRefPicNum                 ( Int iMaxRefPicNum )           { m_iMaxRefPicNum = iMaxRefPicNum;  }
    438459
    439   Bool      getMaxTempLayer                 ()                              { return m_maxTempLayer;              }
     460  Int       getMaxTempLayer                 ()                              { return m_maxTempLayer;              }
    440461  Void      setMaxTempLayer                 ( Int maxTempLayer )            { m_maxTempLayer = maxTempLayer;      }
    441462  //======== Transform =============
     
    582603  Void  setLFCrossTileBoundaryFlag               ( Bool   val  )       { m_loopFilterAcrossTilesEnabledFlag = val; }
    583604  Bool  getLFCrossTileBoundaryFlag               ()                    { return m_loopFilterAcrossTilesEnabledFlag;   }
    584   Void  setUniformSpacingIdr           ( Int i )           { m_iUniformSpacingIdr = i; }
    585   Int   getUniformSpacingIdr           ()                  { return m_iUniformSpacingIdr; }
     605  Void  setTileUniformSpacingFlag      ( Bool b )          { m_tileUniformSpacingFlag = b; }
     606  Bool  getTileUniformSpacingFlag      ()                  { return m_tileUniformSpacingFlag; }
    586607  Void  setNumColumnsMinus1            ( Int i )           { m_iNumColumnsMinus1 = i; }
    587608  Int   getNumColumnsMinus1            ()                  { return m_iNumColumnsMinus1; }
    588   Void  setColumnWidth ( UInt* columnWidth )
    589   {
    590     if( m_iUniformSpacingIdr == 0 && m_iNumColumnsMinus1 > 0 )
    591     {
    592       Int  m_iWidthInCU = ( m_iSourceWidth%g_uiMaxCUWidth ) ? m_iSourceWidth/g_uiMaxCUWidth + 1 : m_iSourceWidth/g_uiMaxCUWidth;
    593       m_puiColumnWidth = new UInt[ m_iNumColumnsMinus1 ];
    594 
    595       for(Int i=0; i<m_iNumColumnsMinus1; i++)
    596       {
    597         m_puiColumnWidth[i] = columnWidth[i];
    598         printf("col: m_iWidthInCU= %4d i=%4d width= %4d\n",m_iWidthInCU,i,m_puiColumnWidth[i]); //AFU
    599       }
    600     }
    601   }
    602   UInt  getColumnWidth                 ( UInt columnidx )  { return *( m_puiColumnWidth + columnidx ); }
     609  Void  setColumnWidth ( const std::vector<Int>& columnWidth ) { m_tileColumnWidth = columnWidth; }
     610  UInt  getColumnWidth                 ( UInt columnIdx )      { return m_tileColumnWidth[columnIdx]; }
    603611  Void  setNumRowsMinus1               ( Int i )           { m_iNumRowsMinus1 = i; }
    604612  Int   getNumRowsMinus1               ()                  { return m_iNumRowsMinus1; }
    605   Void  setRowHeight (UInt* rowHeight)
    606   {
    607     if( m_iUniformSpacingIdr == 0 && m_iNumRowsMinus1 > 0 )
    608     {
    609       Int  m_iHeightInCU = ( m_iSourceHeight%g_uiMaxCUHeight ) ? m_iSourceHeight/g_uiMaxCUHeight + 1 : m_iSourceHeight/g_uiMaxCUHeight;
    610       m_puiRowHeight = new UInt[ m_iNumRowsMinus1 ];
    611 
    612       for(Int i=0; i<m_iNumRowsMinus1; i++)
    613       {
    614         m_puiRowHeight[i] = rowHeight[i];
    615         printf("row: m_iHeightInCU=%4d i=%4d height=%4d\n",m_iHeightInCU,i,m_puiRowHeight[i]); //AFU
    616       }
    617     }
    618   }
    619   UInt  getRowHeight                   ( UInt rowIdx )     { return *( m_puiRowHeight + rowIdx ); }
     613  Void  setRowHeight ( const std::vector<Int>& rowHeight)      { m_tileRowHeight = rowHeight; }
     614  UInt  getRowHeight                   ( UInt rowIdx )         { return m_tileRowHeight[rowIdx]; }
    620615  Void  xCheckGSParameters();
    621616  Void  setWaveFrontSynchro(Int iWaveFrontSynchro)       { m_iWaveFrontSynchro = iWaveFrontSynchro; }
     
    711706  Int*  getKneeSEIOutputKneePoint()                          { return m_kneeSEIOutputKneePoint; }
    712707#endif
    713 #if Q0074_SEI_COLOR_MAPPING
    714   Void  setColorMappingInfoSEIFile( Char* nameFile )         {  m_seiColorMappingFile = nameFile; }
    715   Char* getColorMappingInfoSEIFile()                         {  return m_seiColorMappingFile; }
     708#if Q0074_COLOUR_REMAPPING_SEI
     709  Void  setCRISEIFile( Char* pch )                           { m_colourRemapSEIFile = pch; }
     710  Char* getCRISEIFile()                                      { return m_colourRemapSEIFile; }
     711  Void  setCRISEIId(Int i)                                   { m_colourRemapSEIId = i; }
     712  Int   getCRISEIId()                                        { return m_colourRemapSEIId; }
     713  Void  setCRISEICancelFlag(Bool b)                          { m_colourRemapSEICancelFlag = b; }
     714  Bool  getCRISEICancelFlag()                                { return m_colourRemapSEICancelFlag; }
     715  Void  setCRISEIPersistenceFlag(Bool b)                     { m_colourRemapSEIPersistenceFlag = b; }
     716  Bool  getCRISEIPersistenceFlag()                           { return m_colourRemapSEIPersistenceFlag; }
     717  Void  setCRISEIVideoSignalInfoPresentFlag(Bool b)          { m_colourRemapSEIVideoSignalInfoPresentFlag = b; }
     718  Bool  getCRISEIVideoSignalInfoPresentFlag()                { return m_colourRemapSEIVideoSignalInfoPresentFlag; }
     719  Void  setCRISEIFullRangeFlag(Bool b)                       { m_colourRemapSEIFullRangeFlag = b; }
     720  Bool  getCRISEIFullRangeFlag()                             { return m_colourRemapSEIFullRangeFlag; }
     721  Void  setCRISEIPrimaries(Int i)                            { m_colourRemapSEIPrimaries = i; }
     722  Int   getCRISEIPrimaries()                                 { return m_colourRemapSEIPrimaries; } 
     723  Void  setCRISEITransferFunction(Int i)                     { m_colourRemapSEITransferFunction = i; }
     724  Int   getCRISEITransferFunction()                          { return m_colourRemapSEITransferFunction; } 
     725  Void  setCRISEIMatrixCoefficients(Int i)                   { m_colourRemapSEIMatrixCoefficients = i; }
     726  Int   getCRISEIMatrixCoefficients()                        { return m_colourRemapSEIMatrixCoefficients; }
     727  Void  setCRISEIInputBitDepth(Int i)                        { m_colourRemapSEIInputBitDepth = i; }
     728  Int   getCRISEIInputBitDepth()                             { return m_colourRemapSEIInputBitDepth; }
     729  Void  setCRISEIBitDepth(Int i)                             { m_colourRemapSEIBitDepth = i; }
     730  Int   getCRISEIBitDepth()                                  { return m_colourRemapSEIBitDepth; }
     731  Void  setCRISEIPreLutNumValMinus1(Int *i)                  { for(Int c=0 ; c<3 ; c++) m_colourRemapSEIPreLutNumValMinus1[c] = i[c]; }
     732  Int   getCRISEIPreLutNumValMinus1(Int i)                   { return m_colourRemapSEIPreLutNumValMinus1[i]; }
     733  Void  setCRISEIPreLutCodedValue(Int **i)                   { for(Int c=0 ; c<3 ; c++) m_colourRemapSEIPreLutCodedValue[c] = i[c]; }
     734  Int*  getCRISEIPreLutCodedValue(Int i)                     { return m_colourRemapSEIPreLutCodedValue[i]; }
     735  Void  setCRISEIPreLutTargetValue(Int **i)                  { for(Int c=0 ; c<3 ; c++) m_colourRemapSEIPreLutTargetValue[c] = i[c]; }
     736  Int*  getCRISEIPreLutTargetValue(Int i)                    { return m_colourRemapSEIPreLutTargetValue[i]; }
     737  Void  setCRISEIMatrixPresentFlag(Bool b)                   { m_colourRemapSEIMatrixPresentFlag = b; }
     738  Bool  getCRISEIMatrixPresentFlag()                         { return m_colourRemapSEIMatrixPresentFlag; }
     739  Void  setCRISEILog2MatrixDenom(Int i)                      { m_colourRemapSEILog2MatrixDenom = i; }
     740  Int   getCRISEILog2MatrixDenom()                           { return m_colourRemapSEILog2MatrixDenom; }
     741  Void  setCRISEICoeffs(Int i[3][3])                         { for(Int c=0 ; c<3 ; c++) for(Int j=0 ; j<3 ; j++) m_colourRemapSEICoeffs[c][j] = i[c][j]; }
     742  Int*  getCRISEICoeffs(Int i)                               { return m_colourRemapSEICoeffs[i]; }
     743  Void  setCRISEIPostLutNumValMinus1(Int *i)                 { for(Int c=0 ; c<3 ; c++) m_colourRemapSEIPostLutNumValMinus1[c] = i[c]; }
     744  Int   getCRISEIPostLutNumValMinus1(Int i)                  { return m_colourRemapSEIPostLutNumValMinus1[i]; }
     745  Void  setCRISEIPostLutCodedValue(Int **i)                  { for(Int c=0 ; c<3 ; c++) m_colourRemapSEIPostLutCodedValue[c] = i[c]; }
     746  Int*  getCRISEIPostLutCodedValue(Int i)                    { return m_colourRemapSEIPostLutCodedValue[i]; }
     747  Void  setCRISEIPostLutTargetValue(Int **i)                 { for(Int c=0 ; c<3 ; c++) m_colourRemapSEIPostLutTargetValue[c] = i[c]; }
     748  Int*  getCRISEIPostLutTargetValue(Int i)                   { return m_colourRemapSEIPostLutTargetValue[i]; }
    716749#endif
    717750  Void  setFramePackingArrangementSEIEnabled(Int b)      { m_framePackingSEIEnabled = b; }
     
    865898  UInt      getNumLayer           () { return m_numLayer;             } 
    866899  Void      setNumLayer           (UInt uiNum)   { m_numLayer = uiNum;  }
    867   Void      setConformanceMode    (Int mode)     { m_conformanceMode = mode; }
    868900  Void      setConformanceWindow(Window& conformanceWindow ) { m_conformanceWindow = conformanceWindow; }
    869901  Void      setElRapSliceTypeB(Int bEnabled) {m_elRapSliceBEnabled = bEnabled;}
     
    9711003  Void      setCGSLUTBit(Int n)           { m_nCGSLUTBit = n;    }
    9721004  Int       getCGSLUTBit()                { return m_nCGSLUTBit; }
     1005#if R0151_CGS_3D_ASYMLUT_IMPROVE
     1006  Void      setCGSAdaptChroma(Int n)      { m_nCGSAdaptiveChroma = n;  }
     1007  Int       getCGSAdaptChroma()           { return m_nCGSAdaptiveChroma; }
     1008#endif
     1009#if R0179_ENC_OPT_3DLUT_SIZE
     1010  Void      setCGSLutSizeRDO(Int n)      { m_nCGSLutSizeRDO = n;  }
     1011  Int       getCGSLutSizeRDO()           { return m_nCGSLutSizeRDO; }
     1012#endif
    9731013#endif
    9741014#endif
  • trunk/source/Lib/TLibEncoder/TEncGOP.cpp

    r815 r906  
    4949#include <time.h>
    5050#include <math.h>
     51#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     52#include <limits.h>
     53#endif
    5154
    5255using namespace std;
     
    202205  seiActiveParameterSets->m_selfContainedCvsFlag = false;
    203206  seiActiveParameterSets->m_noParameterSetUpdateFlag = false;
     207#if !R0247_SEI_ACTIVE
    204208  seiActiveParameterSets->numSpsIdsMinus1 = 0;
    205209  seiActiveParameterSets->activeSeqParameterSetId.resize(seiActiveParameterSets->numSpsIdsMinus1 + 1);
    206210  seiActiveParameterSets->activeSeqParameterSetId[0] = sps->getSPSId();
     211#else
     212  seiActiveParameterSets->numSpsIdsMinus1 = m_pcCfg->getNumLayer()-1;
     213  seiActiveParameterSets->activeSeqParameterSetId.resize(seiActiveParameterSets->numSpsIdsMinus1 + 1);
     214  seiActiveParameterSets->layerSpsIdx.resize(seiActiveParameterSets->numSpsIdsMinus1+ 1); 
     215  for (Int c=0; c <= seiActiveParameterSets->numSpsIdsMinus1; c++)
     216  {
     217     seiActiveParameterSets->activeSeqParameterSetId[c] = c;
     218  }
     219  for (Int c=1; c <= seiActiveParameterSets->numSpsIdsMinus1; c++)
     220  {
     221     seiActiveParameterSets->layerSpsIdx[c] = c;
     222  }
     223#endif
    207224  return seiActiveParameterSets;
    208225}
     
    365382#endif
    366383
    367 #if Q0074_SEI_COLOR_MAPPING
    368 SEIColorMappingInfo*  TEncGOP::xCreateSEIColorMappingInfo( Char* file )
     384#if Q0074_COLOUR_REMAPPING_SEI
     385SEIColourRemappingInfo*  TEncGOP::xCreateSEIColourRemappingInfo()
    369386{
    370   SEIColorMappingInfo *seiColorMappingInfo = new SEIColorMappingInfo();
    371 
    372   FILE* fic = fopen( file, "r" );
    373 
    374   Int iVal, retval;
    375 
    376   retval = fscanf( fic, "%d", &seiColorMappingInfo->m_colorMapId );
    377   retval = fscanf( fic, "%d", &iVal );
    378   seiColorMappingInfo->m_colorMapCancelFlag = iVal;
    379   if( !seiColorMappingInfo->m_colorMapCancelFlag )
    380   {
    381     retval = fscanf( fic, "%d", &iVal );
    382     seiColorMappingInfo->m_colorMapPersistenceFlag = iVal;
    383     retval = fscanf( fic, "%d", &iVal );
    384     seiColorMappingInfo->m_colorMap_video_signal_type_present_flag = iVal;
    385     if( seiColorMappingInfo->m_colorMap_video_signal_type_present_flag )
    386     {
    387       retval = fscanf( fic, "%d", &iVal );
    388       seiColorMappingInfo->m_colorMap_video_full_range_flag = iVal;
    389       retval = fscanf( fic, "%d", &seiColorMappingInfo->m_colorMap_primaries );
    390       retval = fscanf( fic, "%d", &seiColorMappingInfo->m_colorMap_transfer_characteristics );
    391       retval = fscanf( fic, "%d", &seiColorMappingInfo->m_colorMap_matrix_coeffs );
    392     }
    393   }
    394 
    395   retval = fscanf( fic, "%d", &seiColorMappingInfo->m_colour_map_coded_data_bit_depth );
    396   retval = fscanf( fic, "%d", &seiColorMappingInfo->m_colour_map_target_bit_depth );
    397   retval = fscanf( fic, "%d", &iVal );
    398   seiColorMappingInfo->m_colorMapModelId = iVal;
    399 
    400   assert( seiColorMappingInfo->m_colorMapModelId == 0 );
    401  
    402   for( Int i=0 ; i<3 ; i++ )
    403   {
    404     retval = fscanf( fic, "%d", &seiColorMappingInfo->m_num_input_pivots[i] );
    405     seiColorMappingInfo->m_coded_input_pivot_value[i]   = new Int[ seiColorMappingInfo->m_num_input_pivots[i] ];
    406     seiColorMappingInfo->m_target_input_pivot_value[i]  = new Int[ seiColorMappingInfo->m_num_input_pivots[i] ];
    407     for( Int j=0 ; j<seiColorMappingInfo->m_num_input_pivots[i] ; j++ )
    408     {
    409       retval = fscanf( fic, "%d", &seiColorMappingInfo->m_coded_input_pivot_value[i][j] );
    410       retval = fscanf( fic, "%d", &seiColorMappingInfo->m_target_input_pivot_value[i][j] );
    411     }
    412   }
    413 
    414   retval = fscanf( fic, "%d", &iVal );
    415   seiColorMappingInfo->m_matrix_flag = iVal;
    416   if( seiColorMappingInfo->m_matrix_flag )
    417   {
    418     retval = fscanf( fic, "%d", &seiColorMappingInfo->m_log2_matrix_denom );
    419     for( Int i=0 ; i<3 ; i++ )
    420     {
    421       for( Int j=0 ; j<3 ; j++ )
    422       {
    423         retval = fscanf( fic, "%d", &seiColorMappingInfo->m_matrix_coef[i][j] );
    424       }
    425     }
    426   }
    427 
    428   for( Int i=0 ; i<3 ; i++ )
    429   {
    430     retval = fscanf( fic, "%d", &seiColorMappingInfo->m_num_output_pivots[i] );
    431     seiColorMappingInfo->m_coded_output_pivot_value[i]   = new Int[ seiColorMappingInfo->m_num_output_pivots[i] ];
    432     seiColorMappingInfo->m_target_output_pivot_value[i]  = new Int[ seiColorMappingInfo->m_num_output_pivots[i] ];
    433     for( Int j=0 ; j<seiColorMappingInfo->m_num_output_pivots[i] ; j++ )
    434     {
    435       retval = fscanf( fic, "%d", &seiColorMappingInfo->m_coded_output_pivot_value[i][j] );
    436       retval = fscanf( fic, "%d", &seiColorMappingInfo->m_target_output_pivot_value[i][j] );
    437     }
    438   }
    439 
    440   fclose( fic );
    441 
    442   if( retval != 1 )
    443   {
    444     printf("Error: can't read color mapping information\n");
    445   }
    446 
    447   return seiColorMappingInfo;
     387  SEIColourRemappingInfo *seiColourRemappingInfo = new SEIColourRemappingInfo();
     388  seiColourRemappingInfo->m_colourRemapId         = m_pcCfg->getCRISEIId();
     389  seiColourRemappingInfo->m_colourRemapCancelFlag = m_pcCfg->getCRISEICancelFlag();
     390  if( !seiColourRemappingInfo->m_colourRemapCancelFlag )
     391  {
     392    seiColourRemappingInfo->m_colourRemapPersistenceFlag            = m_pcCfg->getCRISEIPersistenceFlag();
     393    seiColourRemappingInfo->m_colourRemapVideoSignalInfoPresentFlag = m_pcCfg->getCRISEIVideoSignalInfoPresentFlag();
     394    if( seiColourRemappingInfo->m_colourRemapVideoSignalInfoPresentFlag )
     395    {
     396      seiColourRemappingInfo->m_colourRemapFullRangeFlag           = m_pcCfg->getCRISEIFullRangeFlag();
     397      seiColourRemappingInfo->m_colourRemapPrimaries               = m_pcCfg->getCRISEIPrimaries();
     398      seiColourRemappingInfo->m_colourRemapTransferFunction        = m_pcCfg->getCRISEITransferFunction();
     399      seiColourRemappingInfo->m_colourRemapMatrixCoefficients      = m_pcCfg->getCRISEIMatrixCoefficients();
     400    }
     401    seiColourRemappingInfo->m_colourRemapInputBitDepth             = m_pcCfg->getCRISEIInputBitDepth();
     402    seiColourRemappingInfo->m_colourRemapBitDepth                  = m_pcCfg->getCRISEIBitDepth();
     403    for( Int c=0 ; c<3 ; c++ )
     404    {
     405      seiColourRemappingInfo->m_preLutNumValMinus1[c] = m_pcCfg->getCRISEIPreLutNumValMinus1(c);
     406      if( seiColourRemappingInfo->m_preLutNumValMinus1[c]>0 )
     407      {
     408        seiColourRemappingInfo->m_preLutCodedValue[c].resize(seiColourRemappingInfo->m_preLutNumValMinus1[c]+1);
     409        seiColourRemappingInfo->m_preLutTargetValue[c].resize(seiColourRemappingInfo->m_preLutNumValMinus1[c]+1);
     410        for( Int i=0 ; i<=seiColourRemappingInfo->m_preLutNumValMinus1[c] ; i++)
     411        {
     412          seiColourRemappingInfo->m_preLutCodedValue[c][i]  = (m_pcCfg->getCRISEIPreLutCodedValue(c))[i];
     413          seiColourRemappingInfo->m_preLutTargetValue[c][i] = (m_pcCfg->getCRISEIPreLutTargetValue(c))[i];
     414        }
     415      }
     416    }
     417    seiColourRemappingInfo->m_colourRemapMatrixPresentFlag = m_pcCfg->getCRISEIMatrixPresentFlag();
     418    if( seiColourRemappingInfo->m_colourRemapMatrixPresentFlag )
     419    {
     420      seiColourRemappingInfo->m_log2MatrixDenom = m_pcCfg->getCRISEILog2MatrixDenom();
     421      for( Int c=0 ; c<3 ; c++ )
     422        for( Int i=0 ; i<3 ; i++ )
     423          seiColourRemappingInfo->m_colourRemapCoeffs[c][i] = (m_pcCfg->getCRISEICoeffs(c))[i];
     424    }
     425    for( Int c=0 ; c<3 ; c++ )
     426    {
     427      seiColourRemappingInfo->m_postLutNumValMinus1[c] = m_pcCfg->getCRISEIPostLutNumValMinus1(c);
     428      if( seiColourRemappingInfo->m_postLutNumValMinus1[c]>0 )
     429      {
     430        seiColourRemappingInfo->m_postLutCodedValue[c].resize(seiColourRemappingInfo->m_postLutNumValMinus1[c]+1);
     431        seiColourRemappingInfo->m_postLutTargetValue[c].resize(seiColourRemappingInfo->m_postLutNumValMinus1[c]+1);
     432        for( Int i=0 ; i<=seiColourRemappingInfo->m_postLutNumValMinus1[c] ; i++)
     433        {
     434          seiColourRemappingInfo->m_postLutCodedValue[c][i]  = (m_pcCfg->getCRISEIPostLutCodedValue(c))[i];
     435          seiColourRemappingInfo->m_postLutTargetValue[c][i] = (m_pcCfg->getCRISEIPostLutTargetValue(c))[i];
     436        }
     437      }
     438    }
     439  }
     440  return seiColourRemappingInfo;
    448441}
    449442#endif
     
    453446  OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI);
    454447
    455   if(m_pcCfg->getActiveParameterSetsSEIEnabled())
     448  if(m_pcCfg->getActiveParameterSetsSEIEnabled()
     449#if R0247_SEI_ACTIVE
     450    && m_layerId == 0
     451#endif
     452    )
    456453  {
    457454    SEIActiveParameterSets *sei = xCreateSEIActiveParameterSets (sps);
     
    532529  }
    533530#endif
    534 #if Q0074_SEI_COLOR_MAPPING
    535   if(m_pcCfg->getColorMappingInfoSEIFile())
    536   {
    537     SEIColorMappingInfo *sei = xCreateSEIColorMappingInfo( m_pcCfg->getColorMappingInfoSEIFile() );
     531#if Q0074_COLOUR_REMAPPING_SEI
     532  if(strlen(m_pcCfg->getCRISEIFile()))
     533  {
     534    SEIColourRemappingInfo *sei = xCreateSEIColourRemappingInfo ();
    538535     
    539536#if SVC_EXTENSION
    540     nalu = NALUnit(NAL_UNIT_PREFIX_SEI, 0, m_layerId);  // temporalId = 0 ?
     537    nalu = NALUnit(NAL_UNIT_PREFIX_SEI, 0, sps->getLayerId());  // SEI-CRI is applied per layer
    541538#else
    542539    nalu = NALUnit(NAL_UNIT_PREFIX_SEI);
     
    609606  TEncSbac* pcSbacCoders = NULL;
    610607  TComOutputBitstream* pcSubstreamsOut = NULL;
    611 #if Q0108_TSA_STSA
    612   Int flagTSTA = 0;
    613 #endif
    614608
    615609  xInitGOP( iPOCLast, iNumPicRcvd, rcListPic, rcListPicYuvRecOut, isField );
     
    918912    determinePocResetIdc(pocCurr, pcSlice);
    919913
     914#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     915    Bool pocResettingFlag = false;
     916
     917    if (pcSlice->getPocResetIdc() != 0)
     918    {
     919      if (pcSlice->getVPS()->getVpsPocLsbAlignedFlag())
     920      {
     921        pocResettingFlag = true;
     922      }
     923      else if (m_pcEncTop->getPocDecrementedInDPBFlag())
     924      {
     925        pocResettingFlag = false;
     926      }
     927      else
     928      {
     929        pocResettingFlag = true;
     930      }
     931    }
     932#endif
     933
    920934    // If reset, do the following steps:
     935#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     936    if( pocResettingFlag )
     937#else
    921938    if( pcSlice->getPocResetIdc() )
     939#endif
    922940    {
    923941      updatePocValuesOfPics(pocCurr, pcSlice);
     
    10201038      // inferring of the scaling list can be moved to the config file
    10211039      UInt refLayerId = 0;
     1040#if VPS_AVC_BL_FLAG_REMOVAL
     1041      if( m_layerId > 0 && !m_pcEncTop->getVPS()->getNonHEVCBaseLayerFlag() && m_pcEncTop->getVPS()->getRecursiveRefLayerFlag( m_layerId, refLayerId ) )
     1042#else
    10221043      if( m_layerId > 0 && !m_pcEncTop->getVPS()->getAvcBaseLayerFlag() && m_pcEncTop->getVPS()->getRecursiveRefLayerFlag( m_layerId, refLayerId ) )
     1044#endif
    10231045      {
    10241046        m_pcEncTop->getSPS()->setInferScalingListFlag( true );
     
    10501072      // inferring of the scaling list can be moved to the config file
    10511073      UInt refLayerId = 0;
     1074#if VPS_AVC_BL_FLAG_REMOVAL
     1075      if( m_layerId > 0 && !m_pcEncTop->getVPS()->getNonHEVCBaseLayerFlag() && m_pcEncTop->getVPS()->getRecursiveRefLayerFlag( m_layerId, refLayerId ) )
     1076#else
    10521077      if( m_layerId > 0 && !m_pcEncTop->getVPS()->getAvcBaseLayerFlag() && m_pcEncTop->getVPS()->getRecursiveRefLayerFlag( m_layerId, refLayerId ) )
     1078#endif
    10531079      {
    10541080        m_pcEncTop->getSPS()->setInferScalingListFlag( true );
     
    11351161#endif
    11361162
     1163#if REF_REGION_OFFSET
     1164        const Window &windowRL  = m_pcEncTop->getRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc));
     1165        Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth() - windowRL.getWindowLeftOffset() - windowRL.getWindowRightOffset();
     1166        Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight() - windowRL.getWindowTopOffset() - windowRL.getWindowBottomOffset();
     1167#else
    11371168        Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth();
    11381169        Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight();
     
    11431174        heightBL -= ( confBL.getWindowTopOffset() + confBL.getWindowBottomOffset() ) * TComSPS::getWinUnitY( chromaFormatIdc );
    11441175#endif
     1176#endif
    11451177        Int widthEL   = pcPic->getPicYuvRec()->getWidth()  - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
    11461178        Int heightEL  = pcPic->getPicYuvRec()->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
     1179
     1180#if RESAMPLING_FIX
     1181#if REF_REGION_OFFSET
     1182        // conformance check: the values of RefLayerRegionWidthInSamplesY, RefLayerRegionHeightInSamplesY, ScaledRefRegionWidthInSamplesY and ScaledRefRegionHeightInSamplesY shall be greater than 0
     1183        assert(widthEL > 0 && heightEL > 0 && widthBL > 0 && widthEL > 0);
     1184
     1185        // conformance check: ScaledRefRegionWidthInSamplesY shall be greater or equal to RefLayerRegionWidthInSamplesY and ScaledRefRegionHeightInSamplesY shall be greater or equal to RefLayerRegionHeightInSamplesY
     1186        assert(widthEL >= widthBL && heightEL >= heightBL);
     1187
     1188#if R0209_GENERIC_PHASE
     1189        // 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.
     1190        Int phaseHorLuma   = pcSlice->getPPS()->getPhaseHorLuma(refLayerIdc);
     1191        Int phaseVerLuma   = pcSlice->getPPS()->getPhaseVerLuma(refLayerIdc);
     1192        Int phaseHorChroma = pcSlice->getPPS()->getPhaseHorChroma(refLayerIdc);
     1193        Int phaseVerChroma = pcSlice->getPPS()->getPhaseVerChroma(refLayerIdc);
     1194        assert( ( (widthEL  != widthBL)  || (phaseHorLuma == 0 && phaseHorChroma == 0) )
     1195             && ( (heightEL != heightBL) || (phaseVerLuma == 0 && phaseVerChroma == 0) ) );
     1196#endif
     1197#endif
     1198#endif
    11471199
    11481200        g_mvScalingFactor[refLayerIdc][0] = widthEL  == widthBL  ? 4096 : Clip3(-4096, 4095, ((widthEL  << 8) + (widthBL  >> 1)) / widthBL);
     
    11561208        if( pcSlice->getPPS()->getCGSFlag() )
    11571209        {
     1210#if R0150_CGS_SIGNAL_CONSTRAINTS
     1211          // all reference layers are currently taken as CGS reference layers
     1212          m_Enc3DAsymLUTPPS.addRefLayerId( pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc) );
     1213          m_Enc3DAsymLUTPicUpdate.addRefLayerId( pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc) );
     1214#endif
    11581215          if(g_posScalingFactor[refLayerIdc][0] < (1<<16) || g_posScalingFactor[refLayerIdc][1] < (1<<16)) //if(pcPic->isSpatialEnhLayer(refLayerIdc))
    11591216          {
     
    12071264#if O0194_JOINT_US_BITSHIFT
    12081265#if Q0048_CGS_3D_ASYMLUT
    1209             m_pcPredSearch->upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL );
    1210 #else
    1211             m_pcPredSearch->upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
     1266#if REF_REGION_OFFSET
     1267          m_pcPredSearch->upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL, altRL );
     1268#else
     1269          m_pcPredSearch->upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL );
     1270#endif
     1271#else
     1272          m_pcPredSearch->upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
    12121273#endif
    12131274#else
     
    12701331        }
    12711332      }
    1272 
     1333#if ISLICE_TYPE_NUMDIR
     1334      if( pcSlice->getActiveNumILRRefIdx() == 0 && pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA && (m_pcEncTop->getNumDirectRefLayers() == 0) )
     1335#else
    12731336      if( pcSlice->getActiveNumILRRefIdx() == 0 && pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA )
     1337#endif
    12741338      {
    12751339        pcSlice->setSliceType(I_SLICE);
     
    13951459      if(pcSlice->isTemporalLayerSwitchingPoint(rcListPic) || pcSlice->getSPS()->getTemporalIdNestingFlag())
    13961460      {
    1397 #if !Q0108_TSA_STSA
     1461#if SVC_EXTENSION && !Q0108_TSA_STSA
    13981462        if( pcSlice->getLayerId() > 0 )
    13991463        {
     
    14941558        if(isSTSA==true)
    14951559        {   
    1496 #if !Q0108_TSA_STSA
     1560#if SVC_EXTENSION && !Q0108_TSA_STSA
    14971561          if( pcSlice->getLayerId() > 0 )
    14981562          {
     
    15631627      }
    15641628    }
     1629
     1630    arrangeLongtermPicturesInRPS(pcSlice, rcListPic);
     1631    TComRefPicListModification* refPicListModification = pcSlice->getRefPicListModification();
     1632    refPicListModification->setRefPicListModificationFlagL0(0);
     1633    refPicListModification->setRefPicListModificationFlagL1(0);
     1634    pcSlice->setNumRefIdx(REF_PIC_LIST_0,min(m_pcCfg->getGOPEntry(iGOPid).m_numRefPicsActive,pcSlice->getRPS()->getNumberOfPictures()));
     1635    pcSlice->setNumRefIdx(REF_PIC_LIST_1,min(m_pcCfg->getGOPEntry(iGOPid).m_numRefPicsActive,pcSlice->getRPS()->getNumberOfPictures()));
     1636
     1637#if SVC_EXTENSION
     1638    if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() )
     1639    {
     1640#if POC_RESET_FLAG || POC_RESET_IDC_ENCODER
     1641      if ( pocCurr > 0 && pcSlice->isRADL() && pcPic->getSlice(0)->getBaseColPic(pcPic->getSlice(0)->getInterLayerPredLayerIdc(0))->getSlice(0)->isRASL())
     1642#else
     1643      if (pcSlice->getPOC()>0  && pcSlice->isRADL() && pcPic->getSlice(0)->getBaseColPic(pcPic->getSlice(0)->getInterLayerPredLayerIdc(0))->getSlice(0)->isRASL())
     1644#endif
     1645      {
     1646        pcSlice->setActiveNumILRRefIdx(0);
     1647        pcSlice->setInterLayerPredEnabledFlag(0);
     1648      }
     1649      if( pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA )
     1650      {
     1651        pcSlice->setNumRefIdx(REF_PIC_LIST_0, pcSlice->getActiveNumILRRefIdx());
     1652        pcSlice->setNumRefIdx(REF_PIC_LIST_1, pcSlice->getActiveNumILRRefIdx());
     1653      }
     1654      else
     1655      {
     1656        pcSlice->setNumRefIdx(REF_PIC_LIST_0, pcSlice->getNumRefIdx(REF_PIC_LIST_0)+pcSlice->getActiveNumILRRefIdx());
     1657        pcSlice->setNumRefIdx(REF_PIC_LIST_1, pcSlice->getNumRefIdx(REF_PIC_LIST_1)+pcSlice->getActiveNumILRRefIdx());
     1658      }
     1659
     1660      // check for the reference pictures whether there is at least one either temporal picture or ILRP with sample prediction type
     1661      if( pcSlice->getNumRefIdx( REF_PIC_LIST_0 ) - pcSlice->getActiveNumILRRefIdx() == 0 && pcSlice->getNumRefIdx( REF_PIC_LIST_1 ) - pcSlice->getActiveNumILRRefIdx() == 0 )
     1662      {
     1663        Bool foundSamplePredPicture = false;               
     1664
     1665        for( Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
     1666        {
     1667          if( m_ppcTEncTop[m_layerId]->getSamplePredEnabledFlag( pcSlice->getVPS()->getRefLayerId( m_layerId, pcSlice->getInterLayerPredLayerIdc(i) ) ) )
     1668          {
     1669            foundSamplePredPicture = true;
     1670            break;
     1671          }
     1672        }
     1673
     1674        if( !foundSamplePredPicture )
     1675        {
     1676          pcSlice->setSliceType(I_SLICE);
     1677          pcSlice->setInterLayerPredEnabledFlag(0);
     1678          pcSlice->setActiveNumILRRefIdx(0);
     1679        }
     1680      }
     1681    }
     1682#endif //SVC_EXTENSION
     1683
    15651684#if Q0108_TSA_STSA
    1566     else if( ( pcSlice->getTLayer() == 0 && pcSlice->getLayerId() > 0)    // only for enhancement layer and with temporal layer 0
    1567        && !( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N     
     1685   if( ( pcSlice->getTLayer() == 0 && pcSlice->getLayerId() > 0  )    // only for enhancement layer and with temporal layer 0
     1686     && !( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N     
    15681687          || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_R
    15691688          || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N
     
    15761695    {
    15771696        Bool isSTSA=true;
     1697        Bool isIntra=false;
     1698
     1699        for( Int i = 0; i < pcSlice->getLayerId(); i++)
     1700        {
     1701          TComList<TComPic *> *cListPic = m_ppcTEncTop[i]->getListPic();
     1702          TComPic *lowerLayerPic = pcSlice->getRefPic(*cListPic, pcSlice->getPOC());
     1703          if( lowerLayerPic && pcSlice->getVPS()->getDirectDependencyFlag(pcSlice->getLayerId(), i) )
     1704          {
     1705            if( lowerLayerPic->getSlice(0)->getSliceType() == I_SLICE)
     1706            {
     1707              isIntra = true;
     1708            }
     1709          }
     1710        }
     1711
    15781712        for(Int ii=iGOPid+1; ii < m_pcCfg->getGOPSize() && isSTSA; ii++)
    15791713        {
     
    16051739          }
    16061740        }
    1607         if(isSTSA==true)
     1741        if(isSTSA==true && isIntra == false)
    16081742        {   
    1609 #if !Q0108_TSA_STSA
    1610           if( pcSlice->getLayerId() > 0 )
    1611           {
    1612             Bool oneRefLayerSTSA = false, oneRefLayerNotSTSA = false;
    1613             for( Int i = 0; i < pcSlice->getLayerId(); i++)
    1614             {
    1615               TComList<TComPic *> *cListPic = m_ppcTEncTop[i]->getListPic();
    1616               TComPic *lowerLayerPic = pcSlice->getRefPic(*cListPic, pcSlice->getPOC());
    1617               if( lowerLayerPic && pcSlice->getVPS()->getDirectDependencyFlag(pcSlice->getLayerId(), i) )
    1618               {
    1619                 if( ( lowerLayerPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N ) ||
    1620                     ( lowerLayerPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_R )
    1621                   )
    1622                 {
    1623                   if(pcSlice->getTemporalLayerNonReferenceFlag() )
    1624                   {
    1625                     pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_N);
    1626                   }
    1627                   else
    1628                   {
    1629                     pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_R );
    1630                   }
    1631                   oneRefLayerSTSA = true;
    1632                 }
    1633                 else
    1634                 {
    1635                   oneRefLayerNotSTSA = true;
    1636                 }
    1637               }
    1638             }
    1639             assert( !( oneRefLayerNotSTSA && oneRefLayerSTSA ) ); // Only one variable should be true - failure of this assert means
    1640                                                                   // that two independent reference layers that are not dependent on
    1641                                                                   // each other, but are reference for current layer have inconsistency
    1642             if( oneRefLayerNotSTSA /*&& !oneRefLayerSTSA*/ )          // No reference layer is STSA - set current as TRAIL
    1643             {
    1644               if(pcSlice->getTemporalLayerNonReferenceFlag() )
    1645               {
    1646                 pcSlice->setNalUnitType( NAL_UNIT_CODED_SLICE_TRAIL_N );
    1647               }
    1648               else
    1649               {
    1650                 pcSlice->setNalUnitType( NAL_UNIT_CODED_SLICE_TRAIL_R );
    1651               }
    1652             }
    1653             else  // This means there is no reference layer picture for current picture in this AU
    1654             {
    1655               if(pcSlice->getTemporalLayerNonReferenceFlag() )
    1656               {
    1657                 pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_N);
    1658               }
    1659               else
    1660               {
    1661                 pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_R );
    1662               }
    1663             }
    1664           }
    1665 #else
    16661743          if(pcSlice->getTemporalLayerNonReferenceFlag())
    16671744          {
    16681745            pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_N);
    1669             flagTSTA = 1;
    16701746          }
    16711747          else
    16721748          {
    16731749            pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_R);
    1674             flagTSTA = 1;
    1675           }
    1676 #endif
    1677         }
    1678     }
    1679 #endif
    1680 
    1681     arrangeLongtermPicturesInRPS(pcSlice, rcListPic);
    1682     TComRefPicListModification* refPicListModification = pcSlice->getRefPicListModification();
    1683     refPicListModification->setRefPicListModificationFlagL0(0);
    1684     refPicListModification->setRefPicListModificationFlagL1(0);
    1685     pcSlice->setNumRefIdx(REF_PIC_LIST_0,min(m_pcCfg->getGOPEntry(iGOPid).m_numRefPicsActive,pcSlice->getRPS()->getNumberOfPictures()));
    1686     pcSlice->setNumRefIdx(REF_PIC_LIST_1,min(m_pcCfg->getGOPEntry(iGOPid).m_numRefPicsActive,pcSlice->getRPS()->getNumberOfPictures()));
    1687 
    1688 #if SVC_EXTENSION
    1689     if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() )
    1690     {
    1691 #if POC_RESET_FLAG || POC_RESET_IDC_ENCODER
    1692       if ( pocCurr > 0 && pcSlice->isRADL() && pcPic->getSlice(0)->getBaseColPic(pcPic->getSlice(0)->getInterLayerPredLayerIdc(0))->getSlice(0)->isRASL())
    1693 #else
    1694       if (pcSlice->getPOC()>0  && pcSlice->isRADL() && pcPic->getSlice(0)->getBaseColPic(pcPic->getSlice(0)->getInterLayerPredLayerIdc(0))->getSlice(0)->isRASL())
    1695 #endif
    1696       {
    1697         pcSlice->setActiveNumILRRefIdx(0);
    1698         pcSlice->setInterLayerPredEnabledFlag(0);
    1699       }
    1700 #if Q0108_TSA_STSA
    1701      if( ( pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA ) || flagTSTA == 1 )
    1702 #else
    1703      if( pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA )
    1704 #endif
    1705       {
    1706         pcSlice->setNumRefIdx(REF_PIC_LIST_0, pcSlice->getActiveNumILRRefIdx());
    1707         pcSlice->setNumRefIdx(REF_PIC_LIST_1, pcSlice->getActiveNumILRRefIdx());
    1708       }
    1709       else
    1710       {
    1711         pcSlice->setNumRefIdx(REF_PIC_LIST_0, pcSlice->getNumRefIdx(REF_PIC_LIST_0)+pcSlice->getActiveNumILRRefIdx());
    1712         pcSlice->setNumRefIdx(REF_PIC_LIST_1, pcSlice->getNumRefIdx(REF_PIC_LIST_1)+pcSlice->getActiveNumILRRefIdx());
    1713       }
    1714 
    1715       // check for the reference pictures whether there is at least one either temporal picture or ILRP with sample prediction type
    1716       if( pcSlice->getNumRefIdx( REF_PIC_LIST_0 ) - pcSlice->getActiveNumILRRefIdx() == 0 && pcSlice->getNumRefIdx( REF_PIC_LIST_1 ) - pcSlice->getActiveNumILRRefIdx() == 0 )
    1717       {
    1718         Bool foundSamplePredPicture = false;               
    1719 
    1720         for( Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
    1721         {
    1722           if( m_ppcTEncTop[m_layerId]->getSamplePredEnabledFlag( pcSlice->getVPS()->getRefLayerId( m_layerId, pcSlice->getInterLayerPredLayerIdc(i) ) ) )
    1723           {
    1724             foundSamplePredPicture = true;
    1725             break;
    1726           }
    1727         }
    1728 
    1729         if( !foundSamplePredPicture )
    1730         {
    1731           pcSlice->setSliceType(I_SLICE);
    1732           pcSlice->setInterLayerPredEnabledFlag(0);
    1733           pcSlice->setActiveNumILRRefIdx(0);
    1734         }
    1735       }
    1736     }
    1737 #endif //SVC_EXTENSION
     1750          }
     1751        }
     1752    }
     1753#endif
    17381754
    17391755#if ADAPTIVE_QP_SELECTION
     
    17501766    if(m_layerId ==  0 || ( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() == 0 ) )
    17511767    {
    1752       pcSlice->setRefPicList( rcListPic);
     1768      pcSlice->setRefPicList( rcListPic );
    17531769    }
    17541770
     
    17561772    {
    17571773      pcSlice->setILRPic( m_pcEncTop->getIlpList() );
    1758 #if REF_IDX_MFM
    1759       if( pcSlice->getMFMEnabledFlag() )
    1760       {
    1761         pcSlice->setRefPOCListILP(m_pcEncTop->getIlpList(), pcSlice->getBaseColPic());
    1762       }
    1763 #else
     1774#if !REF_IDX_MFM
    17641775      //  Set reference list
    17651776      pcSlice->setRefPicList ( rcListPic );
     
    21102121    UInt uiRealEndAddress = uiExternalAddress*pcPic->getNumPartInCU()+uiInternalAddress;
    21112122
    2112     UInt uiCummulativeTileWidth;
    2113     UInt uiCummulativeTileHeight;
    21142123    Int  p, j;
    21152124    UInt uiEncCUAddr;
    21162125
    2117     //set NumColumnsMinus1 and NumRowsMinus1
    2118     pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() );
    2119     pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() );
    2120 
    2121     //create the TComTileArray
    2122     pcPic->getPicSym()->xCreateTComTileArray();
    2123 
    2124     if( pcSlice->getPPS()->getUniformSpacingFlag() == 1 )
    2125     {
    2126       //set the width for each tile
    2127       for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
    2128       {
    2129         for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
    2130         {
    2131           pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
    2132             setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1)
    2133             - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
    2134         }
    2135       }
    2136 
    2137       //set the height for each tile
    2138       for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
    2139       {
    2140         for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
    2141         {
    2142           pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
    2143             setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1)
    2144             - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
    2145         }
    2146       }
    2147     }
    2148     else
    2149     {
    2150       //set the width for each tile
    2151       for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
    2152       {
    2153         uiCummulativeTileWidth = 0;
    2154         for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1(); p++)
    2155         {
    2156           pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->setTileWidth( pcSlice->getPPS()->getColumnWidth(p) );
    2157           uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(p);
    2158         }
    2159         pcPic->getPicSym()->getTComTile(j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
    2160       }
    2161 
    2162       //set the height for each tile
    2163       for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
    2164       {
    2165         uiCummulativeTileHeight = 0;
    2166         for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1(); p++)
    2167         {
    2168           pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->setTileHeight( pcSlice->getPPS()->getRowHeight(p) );
    2169           uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(p);
    2170         }
    2171         pcPic->getPicSym()->getTComTile(p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
    2172       }
    2173     }
    2174     //intialize each tile of the current picture
    2175     pcPic->getPicSym()->xInitTiles();
     2126    pcPic->getPicSym()->initTiles(pcSlice->getPPS());
    21762127
    21772128#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
     
    21832134
    21842135    // Allocate some coders, now we know how many tiles there are.
     2136#if WPP_FIX
     2137    const Int iNumSubstreams = pcSlice->getPPS()->getNumSubstreams();
     2138#else
    21852139    Int iNumSubstreams = pcSlice->getPPS()->getNumSubstreams();
     2140#endif
    21862141
    21872142    //generate the Coding Order Map and Inverse Coding Order Map
     
    22152170    startCUAddrSliceSegmentIdx++;
    22162171#if AVC_BASE
     2172#if VPS_AVC_BL_FLAG_REMOVAL
     2173    if( m_layerId == 0 && m_pcEncTop->getVPS()->getNonHEVCBaseLayerFlag() )
     2174#else
    22172175    if( m_layerId == 0 && m_pcEncTop->getVPS()->getAvcBaseLayerFlag() )
     2176#endif
    22182177    {
    22192178      pcPic->getPicYuvOrg()->copyToPic( pcPic->getPicYuvRec() );
     
    22252184      }
    22262185#endif
    2227 #if AVC_SYNTAX
    2228       pcPic->readBLSyntax( m_ppcTEncTop[0]->getBLSyntaxFile(), SYNTAX_BYTES );
    2229 #endif
     2186
     2187      if( pcSubstreamsOut )
     2188      {
     2189        delete[] pcSubstreamsOut;
     2190        pcSubstreamsOut = NULL;
     2191      }
     2192
     2193      if( pcBitstreamRedirect )
     2194      {
     2195        delete pcBitstreamRedirect;
     2196        pcBitstreamRedirect = NULL;
     2197      }
     2198
    22302199      return;
    22312200    }
     
    23182287      OutputNALUnit nalu( NAL_UNIT_VPS, 0, 0 ); // The value of nuh_layer_id of VPS NAL unit shall be equal to 0.
    23192288#if AVC_BASE
     2289#if VPS_AVC_BL_FLAG_REMOVAL
     2290      if( ( m_layerId == 1 && m_pcEncTop->getVPS()->getNonHEVCBaseLayerFlag() ) || ( m_layerId == 0 && !m_pcEncTop->getVPS()->getNonHEVCBaseLayerFlag() ) )
     2291#else
    23202292      if( ( m_layerId == 1 && m_pcEncTop->getVPS()->getAvcBaseLayerFlag() ) || ( m_layerId == 0 && !m_pcEncTop->getVPS()->getAvcBaseLayerFlag() ) )
     2293#endif
    23212294#else
    23222295      if( m_layerId == 0 )
     
    24182391      if (pcSlice->getLayerId() == 0 && m_pcEncTop->getVPS()->getVpsVuiBspHrdPresentFlag())
    24192392      {
    2420         nalu = NALUnit(NAL_UNIT_PREFIX_SEI, 0, 1);
    2421         m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice);
    2422         m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
    2423         SEIScalableNesting *scalableBspNestingSei = xCreateBspNestingSEI(pcSlice);
    2424         m_seiWriter.writeSEImessage(nalu.m_Bitstream, *scalableBspNestingSei, m_pcEncTop->getVPS(), pcSlice->getSPS());
    2425         writeRBSPTrailingBits(nalu.m_Bitstream);
    2426 
    2427         UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit);
    2428         UInt offsetPosition = m_activeParameterSetSEIPresentInAU
    2429           + m_bufferingPeriodSEIPresentInAU
    2430           + m_pictureTimingSEIPresentInAU
    2431           + m_nestedPictureTimingSEIPresentInAU;  // Insert SEI after APS, BP and PT SEI
    2432         AccessUnit::iterator it;
    2433         for(j = 0, it = accessUnit.begin(); j < seiPositionInAu + offsetPosition; j++)
    2434         {
    2435           it++;
    2436         }
    2437         accessUnit.insert(it, new NALUnitEBSP(nalu));
     2393#if VPS_VUI_BSP_HRD_PARAMS
     2394        TComVPS *vps = m_pcEncTop->getVPS();
     2395        for(Int i = 0; i < vps->getNumOutputLayerSets(); i++)
     2396        {
     2397          for(Int k = 0; k < vps->getNumSignalledPartitioningSchemes(i); k++)
     2398          {
     2399            for(Int l = 0; l < vps->getNumPartitionsInSchemeMinus1(i, k)+1; l++)
     2400            {
     2401#endif
     2402              nalu = NALUnit(NAL_UNIT_PREFIX_SEI, 0, 1);
     2403              m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice);
     2404              m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
     2405#if VPS_VUI_BSP_HRD_PARAMS
     2406              SEIScalableNesting *scalableBspNestingSei = xCreateBspNestingSEI(pcSlice, i, k, l);
     2407#else
     2408              SEIScalableNesting *scalableBspNestingSei = xCreateBspNestingSEI(pcSlice);
     2409#endif
     2410              m_seiWriter.writeSEImessage(nalu.m_Bitstream, *scalableBspNestingSei, m_pcEncTop->getVPS(), pcSlice->getSPS());
     2411              writeRBSPTrailingBits(nalu.m_Bitstream);
     2412
     2413              UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit);
     2414              UInt offsetPosition = m_activeParameterSetSEIPresentInAU
     2415                + m_bufferingPeriodSEIPresentInAU
     2416                + m_pictureTimingSEIPresentInAU
     2417                + m_nestedPictureTimingSEIPresentInAU;  // Insert SEI after APS, BP and PT SEI
     2418              AccessUnit::iterator it;
     2419              for(j = 0, it = accessUnit.begin(); j < seiPositionInAu + offsetPosition; j++)
     2420              {
     2421                it++;
     2422              }
     2423              accessUnit.insert(it, new NALUnitEBSP(nalu));
     2424#if VPS_VUI_BSP_HRD_PARAMS
     2425            }
     2426          }
     2427        }
     2428#endif
    24382429      }
    24392430#endif
     
    28422833
    28432834#if SETTING_NO_OUT_PIC_PRIOR
     2835          pcSlice->setNoRaslOutputFlag(false);
    28442836          if (pcSlice->isIRAP())
    28452837          {
     
    28492841            }
    28502842            //the inference for NoOutputPriorPicsFlag
     2843            // KJS: This cannot happen at the encoder
    28512844            if (!m_bFirst && pcSlice->isIRAP() && pcSlice->getNoRaslOutputFlag())
    28522845            {
     
    28762869            m_pcEntropyCoder->setEntropyCoder ( m_pcSbacCoder, pcSlice );
    28772870            m_pcEntropyCoder->resetEntropy    ();
     2871#if WPP_FIX
     2872            for ( UInt ui = 0 ; ui < iNumSubstreams ; ui++ )
     2873#else
    28782874            for ( UInt ui = 0 ; ui < pcSlice->getPPS()->getNumSubstreams() ; ui++ )
     2875#endif
    28792876            {
    28802877              m_pcEntropyCoder->setEntropyCoder ( &pcSbacCoders[ui], pcSlice );
     
    28882885            m_pcSbacCoder->init( (TEncBinIf*)m_pcBinCABAC );
    28892886            {
     2887#if WPP_FIX
     2888              for ( UInt ui = 0 ; ui < iNumSubstreams ; ui++ )
     2889#else
    28902890              for ( UInt ui = 0 ; ui < pcSlice->getPPS()->getNumSubstreams() ; ui++ )
     2891#endif
    28912892              {
    28922893                m_pcEntropyCoder->setEntropyCoder ( &pcSbacCoders[ui], pcSlice );
     
    29152916
    29162917          pcSlice->setTileOffstForMultES( uiOneBitstreamPerSliceLength );
    2917             pcSlice->setTileLocationCount ( 0 );
     2918          pcSlice->setTileLocationCount ( 0 );
    29182919          m_pcSliceEncoder->encodeSlice(pcPic, pcSubstreamsOut);
    29192920
     
    29422943
    29432944              Bool bNextSubstreamInNewTile = ((ui+1) < iNumSubstreams)&& ((ui+1)%uiNumSubstreamsPerTile == 0);
     2945#if WPP_FIX
     2946              if (bNextSubstreamInNewTile &&  !pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag() )
     2947#else
    29442948              if (bNextSubstreamInNewTile)
     2949#endif
    29452950              {
    29462951                pcSlice->setTileLocation(ui/uiNumSubstreamsPerTile, pcSlice->getTileOffstForMultES()+(uiTotalCodedSize>>3));
    29472952              }
     2953#if WPP_FIX
     2954              if (ui+1 < iNumSubstreams)
     2955              {
     2956                puiSubstreamSizes[ui] = pcSubstreamsOut[ui].getNumberOfWrittenBits() + (pcSubstreamsOut[ui].countStartCodeEmulations()<<3);
     2957              }
     2958#else
    29482959              if (ui+1 < pcSlice->getPPS()->getNumSubstreams())
    29492960              {
    29502961                puiSubstreamSizes[ui] = pcSubstreamsOut[ui].getNumberOfWrittenBits() + (pcSubstreamsOut[ui].countStartCodeEmulations()<<3);
    29512962              }
     2963#endif
    29522964            }
    29532965
     
    29662978            // Substreams...
    29672979            TComOutputBitstream *pcOut = pcBitstreamRedirect;
    2968           Int offs = 0;
     2980#if WPP_FIX
     2981            Int numZeroSubstreamsAtStartOfSlice = 0;
     2982            Int numSubstreamsToCode = pcSlice->getPPS()->getNumSubstreams();
     2983            if (pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag())
     2984            {
     2985              Int  maxNumParts                      = pcPic->getNumPartInCU();
     2986              numZeroSubstreamsAtStartOfSlice  = pcPic->getSubstreamForLCUAddr(pcSlice->getSliceSegmentCurStartCUAddr()/maxNumParts, false, pcSlice);
     2987              // 1st line present for WPP.
     2988              numSubstreamsToCode  = pcSlice->getNumEntryPointOffsets()+1;
     2989            }
     2990            for ( UInt ui = 0 ; ui < numSubstreamsToCode; ui++ )
     2991            {
     2992              pcOut->addSubstream(&pcSubstreamsOut[ui+numZeroSubstreamsAtStartOfSlice]);
     2993            }
     2994#else
     2995            Int offs = 0;
    29692996          Int nss = pcSlice->getPPS()->getNumSubstreams();
    29702997          if (pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag())
     
    29783005            pcOut->addSubstream(&pcSubstreamsOut[ui+offs]);
    29793006            }
     3007#endif
    29803008          }
    29813009
     
    33963424      pcPicYuvRecOut->setReconstructed(true);
    33973425#endif
    3398 
     3426#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     3427      m_pcEncTop->setFirstPicInLayerDecodedFlag(true);
     3428#endif
    33993429      pcPic->setReconMark   ( true );
    34003430      m_bFirst = false;
     
    34553485  // If BL picture in the AU is IDR, and another picture is not IDR, set the poc_reset_idc to 2
    34563486  // If BL picture is IRAP, and another picture is non-IRAP, then the poc_reset_idc is equal to 1 or 2.
     3487#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     3488  slice->setPocMsbNeeded(false);
     3489#endif
    34573490  if( slice->getSliceIdx() == 0 ) // First slice - compute, copy for other slices
    34583491  {
     
    35143547        {
    35153548          slice->setPocResetIdc( 2 ); // Full reset needed
     3549#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     3550          if (slice->getVPS()->getVpsPocLsbAlignedFlag() && slice->getVPS()->getNumDirectRefLayers(slice->getLayerId()) == 0)
     3551          {
     3552            slice->setPocMsbNeeded(true);  // Force msb writing
     3553          }
     3554#endif
    35163555        }
    35173556        else
     
    35303569        Int periodId = rand() % 64;
    35313570        m_lastPocPeriodId = (periodId == m_lastPocPeriodId) ? (periodId + 1) % 64 : periodId ;
     3571
     3572#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     3573        for (UInt i = 0; i < MAX_LAYERS; i++)
     3574        {
     3575          m_ppcTEncTop[i]->setPocDecrementedInDPBFlag(false);
     3576        }
     3577#endif
    35323578      }
    35333579      else
     
    35463592Void TEncGOP::updatePocValuesOfPics(Int const pocCurr, TComSlice *const slice)
    35473593{
     3594#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     3595  UInt affectedLayerList[MAX_NUM_LAYER_IDS];
     3596  Int  numAffectedLayers;
     3597
     3598  affectedLayerList[0] = m_layerId;
     3599  numAffectedLayers = 1;
     3600
     3601  if (m_pcEncTop->getVPS()->getVpsPocLsbAlignedFlag())
     3602  {
     3603    for (UInt j = 0; j < m_pcEncTop->getVPS()->getNumPredictedLayers(m_layerId); j++)
     3604    {
     3605      affectedLayerList[j + 1] = m_pcEncTop->getVPS()->getPredictedLayerId(m_layerId, j);
     3606    }
     3607    numAffectedLayers = m_pcEncTop->getVPS()->getNumPredictedLayers(m_layerId) + 1;
     3608  }
     3609#endif
    35483610
    35493611  Int pocAdjustValue = pocCurr - m_pcEncTop->getPocAdjustmentValue();
     
    35533615
    35543616  maxPocLsb   = 1 << slice->getSPS()->getBitsForPOC();
     3617
     3618#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     3619  Int adjustedPocValue = pocCurr;
     3620
     3621  if (m_pcEncTop->getFirstPicInLayerDecodedFlag())
     3622  {
     3623#endif
     3624
    35553625  pocLsbVal   = (slice->getPocResetIdc() == 3)
    35563626                ? slice->getPocLsbVal()
     
    35613631                : 0;
    35623632  deltaPocVal = pocMsbDelta  + pocLsbDelta;
    3563  
     3633
     3634#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     3635  Int origDeltaPocVal = deltaPocVal;  // original value needed when updating POC adjustment value
     3636
     3637  if (slice->getPocMsbNeeded())  // IDR picture in base layer, non-IDR picture in other layers, poc_lsb_aligned_flag = 1
     3638  {
     3639    if (slice->getLayerId() == 0)
     3640    {
     3641      Int highestPoc = INT_MIN;
     3642      // Find greatest POC in DPB for layer 0
     3643      for (TComList<TComPic*>::iterator iterPic = m_pcEncTop->getListPic()->begin(); iterPic != m_pcEncTop->getListPic()->end(); ++iterPic)
     3644      {
     3645        TComPic *dpbPic = *iterPic;
     3646        if (dpbPic->getReconMark() && dpbPic->getLayerId() == 0 && dpbPic->getPOC() > highestPoc)
     3647        {
     3648          highestPoc = dpbPic->getPOC();
     3649        }
     3650      }
     3651      deltaPocVal = (highestPoc - (highestPoc & (maxPocLsb - 1))) + 1*maxPocLsb;
     3652      m_pcEncTop->setCurrPocMsb(deltaPocVal);
     3653    }
     3654    else
     3655    {
     3656      deltaPocVal = m_ppcTEncTop[0]->getCurrPocMsb();  // copy from base layer
     3657    }
     3658    slice->setPocMsbVal(deltaPocVal);
     3659  }
     3660#endif
     3661
     3662#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     3663  for (UInt layerIdx = 0; layerIdx < numAffectedLayers; layerIdx++)
     3664  {
     3665    if (!m_ppcTEncTop[affectedLayerList[layerIdx]]->getPocDecrementedInDPBFlag())
     3666    {
     3667      m_ppcTEncTop[affectedLayerList[layerIdx]]->setPocDecrementedInDPBFlag(true);
     3668
     3669      // Decrement value of associatedIrapPoc of the TEncGop object
     3670      m_ppcTEncTop[affectedLayerList[layerIdx]]->getGOPEncoder()->m_associatedIRAPPOC -= deltaPocVal;
     3671
     3672      // Decrememnt the value of m_pocCRA
     3673      m_ppcTEncTop[affectedLayerList[layerIdx]]->getGOPEncoder()->m_pocCRA -= deltaPocVal;
     3674
     3675      TComList<TComPic*>::iterator  iterPic = m_ppcTEncTop[affectedLayerList[layerIdx]]->getListPic()->begin();
     3676      while (iterPic != m_ppcTEncTop[affectedLayerList[layerIdx]]->getListPic()->end())
     3677#else
    35643678  // Decrement value of associatedIrapPoc of the TEncGop object
    35653679  this->m_associatedIRAPPOC -= deltaPocVal;
     
    35713685  TComList<TComPic*>::iterator  iterPic = getListPic()->begin(); 
    35723686  while( iterPic != getListPic()->end() )
     3687#endif
    35733688  {
    35743689    TComPic *dpbPic = *iterPic;
     
    35953710        // Update value of associatedIrapPoc of each slice
    35963711        dpbPicSlice->setAssociatedIRAPPOC( dpbPicSlice->getAssociatedIRAPPOC() - deltaPocVal );
     3712
     3713#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     3714        if (slice->getPocMsbNeeded())
     3715        {
     3716          // this delta value is needed when computing delta POCs in reference picture set initialization
     3717          dpbPicSlice->setPocResetDeltaPoc(dpbPicSlice->getPocResetDeltaPoc() + (deltaPocVal - pocLsbVal));
     3718        }
     3719#endif
    35973720      }
    35983721    }
    35993722    iterPic++;
    36003723  }
    3601  
     3724#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     3725    }
     3726  }
     3727#endif
     3728
    36023729  // Actual POC value before reset
     3730#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     3731  adjustedPocValue = pocCurr - m_pcEncTop->getPocAdjustmentValue();
     3732#else
    36033733  Int adjustedPocValue = pocCurr - m_pcEncTop->getPocAdjustmentValue();
     3734#endif
    36043735
    36053736  // Set MSB value before reset
    36063737  Int tempLsbVal = adjustedPocValue & (maxPocLsb - 1);
    3607   slice->setPocMsbVal( adjustedPocValue - tempLsbVal);
     3738#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     3739  if (!slice->getPocMsbNeeded())  // set poc msb normally if special msb handling is not needed
     3740  {
     3741#endif
     3742    slice->setPocMsbVal(adjustedPocValue - tempLsbVal);
     3743#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     3744  }
     3745#endif
    36083746
    36093747  // Set LSB value before reset - this is needed in the case of resetIdc = 2
     
    36113749
    36123750  // Cumulative delta
     3751#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     3752  deltaPocVal = origDeltaPocVal;  // restore deltaPoc for correct adjustment value update
     3753#endif
    36133754  m_pcEncTop->setPocAdjustmentValue( m_pcEncTop->getPocAdjustmentValue() + deltaPocVal );
     3755
     3756#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     3757  }
     3758#endif
    36143759
    36153760  // New LSB value, after reset
     
    37383883  assert (m_iGopSize > 0);
    37393884 
    3740   return;
    3741 }
    3742 
    3743 Void TEncGOP::xInitGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut )
    3744 {
    3745   assert( iNumPicRcvd > 0 );
    3746   //  Exception for the first frame
    3747   if ( iPOCLast == 0 )
    3748   {
    3749     m_iGopSize    = 1;
    3750   }
    3751   else
    3752     m_iGopSize    = m_pcCfg->getGOPSize();
    3753  
    3754   assert (m_iGopSize > 0);
    3755 
    37563885  return;
    37573886}
     
    40904219      {
    40914220#if POC_RESET_IDC_ENCODER
    4092         printf( "%d(%d)", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex), pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->getLayerId() );
     4221        UInt refLayerId = pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->getLayerId();
     4222        UInt refLayerIdc = pcSlice->getReferenceLayerIdc(refLayerId);
     4223        assert( g_posScalingFactor[refLayerIdc][0] );
     4224        assert( g_posScalingFactor[refLayerIdc][1] );
     4225
     4226        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] );
    40934227#else
    40944228        printf( "%d(%d)", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)-pcSlice->getLastIDR(), pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->getLayerId() );
     
    41204254  if( m_layerId && pcSlice->getPPS()->getCGSFlag() )
    41214255  {
     4256#if R0179_ENC_OPT_3DLUT_SIZE
     4257      m_Enc3DAsymLUTPicUpdate.update3DAsymLUTParam( &m_Enc3DAsymLUTPPS );
     4258#else
     4259    if( m_Enc3DAsymLUTPPS.getPPSBit() > 0 )
     4260      m_Enc3DAsymLUTPicUpdate.copy3DAsymLUT( &m_Enc3DAsymLUTPPS );
     4261#endif
    41224262    m_Enc3DAsymLUTPicUpdate.updatePicCGSBits( pcSlice , m_Enc3DAsymLUTPPS.getPPSBit() );
    41234263  }
     
    47714911
    47724912#if O0164_MULTI_LAYER_HRD
     4913#if VPS_VUI_BSP_HRD_PARAMS
     4914SEIScalableNesting* TEncGOP::xCreateBspNestingSEI(TComSlice *pcSlice, Int olsIdx, Int partitioningSchemeIdx, Int bspIdx)
     4915#else
    47734916SEIScalableNesting* TEncGOP::xCreateBspNestingSEI(TComSlice *pcSlice)
     4917#endif
    47744918{
    47754919  SEIScalableNesting *seiScalableNesting = new SEIScalableNesting();
     
    47844928  seiScalableNesting->m_defaultOpFlag                 = 0;
    47854929  seiScalableNesting->m_nestingNumOpsMinus1           = 0;      //nesting_num_ops_minus1
     4930#if VPS_VUI_BSP_HRD_PARAMS
     4931  seiScalableNesting->m_nestingOpIdx[0]               = pcSlice->getVPS()->getOutputLayerSetIdx(olsIdx);
     4932  seiScalableNesting->m_nestingMaxTemporalIdPlus1[0]  = 6 + 1;
     4933#else
    47864934  seiScalableNesting->m_nestingOpIdx[0]               = 1;
     4935#endif
    47874936  seiScalableNesting->m_allLayersFlag                 = 0;
    47884937  seiScalableNesting->m_nestingNoOpMaxTemporalIdPlus1 = 6 + 1;  //nesting_no_op_max_temporal_id_plus1
     
    48304979  seiBspNesting->m_nestedSEIs.push_back(seiBufferingPeriod);
    48314980  seiBspNesting->m_nestedSEIs.push_back(seiBspInitialArrivalTime);
     4981#if VPS_VUI_BSP_HRD_PARAMS
     4982  seiBspNesting->m_bspIdx = bspIdx;
     4983  seiBspNesting->m_seiOlsIdx = olsIdx;
     4984  seiBspNesting->m_seiPartitioningSchemeIdx = partitioningSchemeIdx;
     4985#endif
    48324986  seiScalableNesting->m_nestedSEIs.push_back(seiBspNesting); // BSP nesting SEI is contained in scalable nesting SEI
    48334987
     
    48424996  m_Enc3DAsymLUTPPS.setPPSBit( 0 );
    48434997  Double dErrorUpdatedPPS = 0 , dErrorPPS = 0;
    4844   dErrorUpdatedPPS = m_Enc3DAsymLUTPicUpdate.derive3DAsymLUT( pSlice , pCurPic , refLayerIdc , pCfg , bSignalPPS , m_pcEncTop->getElRapSliceTypeB() );
     4998
     4999#if R0179_ENC_OPT_3DLUT_SIZE
     5000  Int nTLthres = m_pcCfg->getCGSLutSizeRDO() ? 2:7;
     5001  Double dFrameLambda;
     5002#if FULL_NBIT
     5003  Int    SHIFT_QP = 12 + 6 * (pSlice->getBitDepthY() - 8);
     5004#else
     5005  Int    SHIFT_QP = 12;
     5006#endif
     5007  Int QP = pSlice->getSliceQp();
     5008
     5009  // set frame lambda
     5010  dFrameLambda = 0.68 * pow (2, (QP  - SHIFT_QP) / 3.0) * (m_pcCfg->getGOPSize() > 1 && pSlice->isInterB()? 2 : 1);
     5011
     5012  if(m_pcCfg->getCGSLutSizeRDO() == 1 && (!bSignalPPS && (pSlice->getDepth() < nTLthres)))
     5013    dErrorUpdatedPPS = m_Enc3DAsymLUTPicUpdate.derive3DAsymLUT( pSlice , pCurPic , refLayerIdc , pCfg , bSignalPPS , m_pcEncTop->getElRapSliceTypeB(), dFrameLambda );
     5014  else if (pSlice->getDepth() >= nTLthres)
     5015    dErrorUpdatedPPS = MAX_DOUBLE;
     5016  else // if (m_pcCfg->getCGSLutSizeRDO() = 0 || bSignalPPS)
     5017#endif   
     5018    dErrorUpdatedPPS = m_Enc3DAsymLUTPicUpdate.derive3DAsymLUT( pSlice , pCurPic , refLayerIdc , pCfg , bSignalPPS , m_pcEncTop->getElRapSliceTypeB() );
     5019
     5020
    48455021  if( bSignalPPS )
    48465022  {
     
    48505026  else if( nCGSFlag )
    48515027  {
    4852     dErrorPPS = m_Enc3DAsymLUTPPS.estimateDistWithCur3DAsymLUT( pCurPic , refLayerIdc );
    4853     Double dFactor = pCfg->getIntraPeriod() == 1 ? 0.99 : 0.9;
    4854     pSlice->setCGSOverWritePPS( dErrorUpdatedPPS < dFactor * dErrorPPS );
     5028#if R0179_ENC_OPT_3DLUT_SIZE
     5029    if(pSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || pSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N)
     5030    {
     5031      pSlice->setCGSOverWritePPS( 0 );
     5032    }
     5033    else if (pSlice->getDepth() >= nTLthres)
     5034    {
     5035      pSlice->setCGSOverWritePPS( 0 );
     5036    }
     5037    else
     5038    {
     5039#endif   
     5040      dErrorPPS = m_Enc3DAsymLUTPPS.estimateDistWithCur3DAsymLUT( pCurPic , refLayerIdc );
     5041      Double dFactor = pCfg->getIntraPeriod() == 1 ? 0.99 : 0.9;
     5042
     5043#if R0179_ENC_OPT_3DLUT_SIZE
     5044      if( m_pcCfg->getCGSLutSizeRDO() )
     5045      {
     5046        dErrorPPS = dErrorPPS/m_Enc3DAsymLUTPicUpdate.getDistFactor(pSlice->getSliceType(), pSlice->getDepth());
     5047      }
     5048#endif
     5049      pSlice->setCGSOverWritePPS( dErrorUpdatedPPS < dFactor * dErrorPPS );
     5050#if R0179_ENC_OPT_3DLUT_SIZE
     5051    }
     5052#endif
    48555053    if( pSlice->getCGSOverWritePPS() )
    48565054    {
  • trunk/source/Lib/TLibEncoder/TEncGOP.h

    r815 r906  
    207207protected:
    208208 
    209   Void xInitGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, Bool isField );
    210   Void  xInitGOP          ( Int iPOC, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut );
    211   Void  xGetBuffer        ( TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, Int iNumPicRcvd, Int iTimeOffset, TComPic*& rpcPic, TComPicYuv*& rpcPicYuvRecOut, Int pocCurr, Bool isField );
     209  Void  xInitGOP          ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, bool isField );
     210  Void  xGetBuffer        ( TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, Int iNumPicRcvd, Int iTimeOffset, TComPic*& rpcPic, TComPicYuv*& rpcPicYuvRecOut, Int pocCurr, bool isField );
    212211 
    213212  Void  xCalculateAddPSNR ( TComPic* pcPic, TComPicYuv* pcPicD, const AccessUnit&, Double dEncTime );
     
    226225  SEIKneeFunctionInfo*    xCreateSEIKneeFunctionInfo();
    227226#endif
    228 #if Q0074_SEI_COLOR_MAPPING
    229   SEIColorMappingInfo*    xCreateSEIColorMappingInfo( Char* file );
     227#if Q0074_COLOUR_REMAPPING_SEI
     228  SEIColourRemappingInfo* xCreateSEIColourRemappingInfo();
    230229#endif
    231230
     
    254253#endif
    255254#if O0164_MULTI_LAYER_HRD
     255#if VPS_VUI_BSP_HRD_PARAMS
     256  SEIScalableNesting* xCreateBspNestingSEI(TComSlice *pcSlice, Int olsIdx, Int partitioningSchemeIdx, Int bspIdx);
     257#else
    256258  SEIScalableNesting* xCreateBspNestingSEI(TComSlice *pcSlice);
     259#endif
    257260#endif
    258261#if Q0048_CGS_3D_ASYMLUT
  • trunk/source/Lib/TLibEncoder/TEncSearch.cpp

    r815 r906  
    48964896    if( bCodeChroma )
    48974897    {
     4898      m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] );
     4899      m_pcEntropyCoder->resetBits();
    48984900      m_pcEntropyCoder->encodeQtCbf   ( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrMode );
    48994901      m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrU, uiAbsPartIdx, trWidthC, trHeightC, uiDepth, TEXT_CHROMA_U );
    4900       uiSingleBitsU = m_pcEntropyCoder->getNumberOfWrittenBits() - uiSingleBitsY;
     4902      uiSingleBitsU = m_pcEntropyCoder->getNumberOfWrittenBits();
    49014903     
     4904      m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] );
     4905      m_pcEntropyCoder->resetBits();
    49024906      m_pcEntropyCoder->encodeQtCbf   ( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrMode );
    49034907      m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrV, uiAbsPartIdx, trWidthC, trHeightC, uiDepth, TEXT_CHROMA_V );
    4904       uiSingleBitsV = m_pcEntropyCoder->getNumberOfWrittenBits() - ( uiSingleBitsY + uiSingleBitsU );
     4908      uiSingleBitsV = m_pcEntropyCoder->getNumberOfWrittenBits();
    49054909    }
    49064910   
     
    49394943      {
    49404944        const Double singleCostY = m_pcRdCost->calcRdCost( uiSingleBitsY, uiNonzeroDistY );
     4945        m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] );
    49414946        m_pcEntropyCoder->resetBits();
    49424947        m_pcEntropyCoder->encodeQtCbfZero( pcCU, TEXT_LUMA,     uiTrMode );
     
    49644969    else if( checkTransformSkipY )
    49654970    {
     4971      m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] );
    49664972      m_pcEntropyCoder->resetBits();
    49674973      m_pcEntropyCoder->encodeQtCbfZero( pcCU, TEXT_LUMA, uiTrMode );
     
    50155021        {
    50165022          const Double dSingleCostU = m_pcRdCost->calcRdCost( uiSingleBitsU, uiNonzeroDistU );
     5023          m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] );
    50175024          m_pcEntropyCoder->resetBits();
    50185025          m_pcEntropyCoder->encodeQtCbfZero( pcCU, TEXT_CHROMA_U,     uiTrMode );
     
    50405047      else if( checkTransformSkipUV )
    50415048      {
     5049        m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] );
    50425050        m_pcEntropyCoder->resetBits();
    50435051        m_pcEntropyCoder->encodeQtCbfZero( pcCU, TEXT_CHROMA_U, uiTrMode );
     
    50845092        {
    50855093          const Double dSingleCostV = m_pcRdCost->calcRdCost( uiSingleBitsV, uiNonzeroDistV );
     5094          m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] );
    50865095          m_pcEntropyCoder->resetBits();
    50875096          m_pcEntropyCoder->encodeQtCbfZero( pcCU, TEXT_CHROMA_V,     uiTrMode );
     
    51095118      else if( checkTransformSkipUV )
    51105119      {
     5120        m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] );
    51115121        m_pcEntropyCoder->resetBits();
    51125122        m_pcEntropyCoder->encodeQtCbfZero( pcCU, TEXT_CHROMA_V, uiTrMode );
     
    52875297      pcCU->setCbfSubParts( uiAbsSumTransformSkipV ? uiSetCbf : 0, TEXT_CHROMA_V, uiAbsPartIdx, pcCU->getDepth(0)+uiTrModeC );
    52885298
    5289       m_pcEntropyCoder->resetBits();
    52905299      uiSingleBitsU = 0;
    52915300      uiSingleBitsV = 0;
     
    52935302      if( uiAbsSumTransformSkipU )
    52945303      {
     5304        m_pcEntropyCoder->resetBits();
    52955305        m_pcEntropyCoder->encodeQtCbf   ( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrMode );
    52965306        m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrU, uiAbsPartIdx, trWidthC, trHeightC, uiDepth, TEXT_CHROMA_U );
     
    53355345      if( uiAbsSumTransformSkipV )
    53365346      {
     5347        m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] );
     5348        m_pcEntropyCoder->resetBits();
    53375349        m_pcEntropyCoder->encodeQtCbf   ( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrMode );
    53385350        m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrV, uiAbsPartIdx, trWidthC, trHeightC, uiDepth, TEXT_CHROMA_V );
    5339         uiSingleBitsV = m_pcEntropyCoder->getNumberOfWrittenBits() - uiSingleBitsU;
     5351        uiSingleBitsV = m_pcEntropyCoder->getNumberOfWrittenBits();
    53405352
    53415353        curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr();
  • trunk/source/Lib/TLibEncoder/TEncSlice.cpp

    r713 r906  
    836836Void TEncSlice::compressSlice( TComPic*& rpcPic )
    837837{
     838#if !WPP_FIX
    838839  UInt  uiCUAddr;
     840#endif
    839841  UInt   uiStartCUAddr;
    840842  UInt   uiBoundingCUAddr;
     
    907909  TEncSbac**** ppppcRDSbacCoders    = pcEncTop->getRDSbacCoders();
    908910  TComBitCounter* pcBitCounters     = pcEncTop->getBitCounters();
     911#if WPP_FIX
     912  const Int  iNumSubstreams = pcSlice->getPPS()->getNumSubstreams();
     913  const UInt uiTilesAcross  = rpcPic->getPicSym()->getNumColumnsMinus1()+1;
     914#else
    909915  Int  iNumSubstreams = 1;
    910916  UInt uiTilesAcross  = 0;
     
    912918  iNumSubstreams = pcSlice->getPPS()->getNumSubstreams();
    913919  uiTilesAcross = rpcPic->getPicSym()->getNumColumnsMinus1()+1;
     920#endif
    914921  delete[] m_pcBufferSbacCoders;
    915922  delete[] m_pcBufferBinCoderCABACs;
     
    943950  UInt uiWidthInLCUs  = rpcPic->getPicSym()->getFrameWidthInCU();
    944951  //UInt uiHeightInLCUs = rpcPic->getPicSym()->getFrameHeightInCU();
     952#if WPP_FIX
     953  UInt      uiTileCol               = 0;
     954  Bool      depSliceSegmentsEnabled = pcSlice->getPPS()->getDependentSliceSegmentsEnabledFlag();
     955  UInt      uiCUAddr                = rpcPic->getPicSym()->getCUOrderMap( uiStartCUAddr /rpcPic->getNumPartInCU());
     956  UInt      currentTileIdx          = rpcPic->getPicSym()->getTileIdxMap(uiCUAddr);
     957  TComTile *pCurrentTile            = rpcPic->getPicSym()->getTComTile(currentTileIdx);
     958  UInt      uiTileStartLCU          = pCurrentTile->getFirstCUAddr();
     959#else
    945960  UInt uiCol=0, uiLin=0, uiSubStrm=0;
    946961  UInt uiTileCol      = 0;
     
    950965  uiCUAddr = rpcPic->getPicSym()->getCUOrderMap( uiStartCUAddr /rpcPic->getNumPartInCU());
    951966  uiTileStartLCU = rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr();
     967#endif
    952968  if( depSliceSegmentsEnabled )
    953969  {
    954970    if((pcSlice->getSliceSegmentCurStartCUAddr()!= pcSlice->getSliceCurStartCUAddr())&&(uiCUAddr != uiTileStartLCU))
    955971    {
     972#if WPP_FIX
     973      UInt uiSubStrm=0;
     974#endif
    956975      if( m_pcCfg->getWaveFrontsynchro() )
    957976      {
     977#if WPP_FIX
     978        uiTileCol = currentTileIdx % (rpcPic->getPicSym()->getNumColumnsMinus1()+1);
     979         m_pcBufferSbacCoders[uiTileCol].loadContexts( CTXMem[1] );
     980         //uiCUAddr = rpcPic->getPicSym()->getCUOrderMap( uiStartCUAddr /rpcPic->getNumPartInCU());
     981         uiSubStrm=rpcPic->getSubstreamForLCUAddr(uiCUAddr, true, pcSlice);
     982         if ( pCurrentTile->getTileWidth() < 2)
     983         {
     984           CTXMem[0]->loadContexts(m_pcSbacCoder);
     985         }
     986#else
    958987        uiTileCol = rpcPic->getPicSym()->getTileIdxMap(uiCUAddr) % (rpcPic->getPicSym()->getNumColumnsMinus1()+1);
    959988        m_pcBufferSbacCoders[uiTileCol].loadContexts( CTXMem[1] );
     
    9721001          }
    9731002        }
     1003#endif
    9741004      }
    9751005      m_pppcRDSbacCoder[0][CI_CURR_BEST]->loadContexts( CTXMem[0] );
     
    9981028    uiTileCol = rpcPic->getPicSym()->getTileIdxMap(uiCUAddr) % (rpcPic->getPicSym()->getNumColumnsMinus1()+1); // what column of tiles are we in?
    9991029    uiTileStartLCU = rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr();
     1030#if WPP_FIX
     1031    UInt uiTileLCUX = uiTileStartLCU % uiWidthInLCUs;
     1032    //UInt uiSliceStartLCU = pcSlice->getSliceCurStartCUAddr();
     1033    UInt uiCol     = uiCUAddr % uiWidthInLCUs;
     1034    UInt uiSubStrm=rpcPic->getSubstreamForLCUAddr(uiCUAddr, true, pcSlice);
     1035
     1036    if ( ((iNumSubstreams > 1) || depSliceSegmentsEnabled ) && (uiCol == uiTileLCUX) && m_pcCfg->getWaveFrontsynchro())
     1037#else
    10001038    uiTileLCUX = uiTileStartLCU % uiWidthInLCUs;
    10011039    //UInt uiSliceStartLCU = pcSlice->getSliceCurStartCUAddr();
     
    10151053    }
    10161054    if ( ((pcSlice->getPPS()->getNumSubstreams() > 1) || depSliceSegmentsEnabled ) && (uiCol == uiTileLCUX) && m_pcCfg->getWaveFrontsynchro())
     1055#endif
    10171056    {
    10181057      // We'll sync if the TR is available.
     
    11381177    ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST]->load( m_pppcRDSbacCoder[0][CI_CURR_BEST] );
    11391178    //Store probabilties of second LCU in line into buffer
     1179#if WPP_FIX
     1180    if ( ( uiCol == uiTileLCUX+1) && (depSliceSegmentsEnabled || (iNumSubstreams > 1)) && m_pcCfg->getWaveFrontsynchro())
     1181#else
    11401182    if ( ( uiCol == uiTileLCUX+1) && (depSliceSegmentsEnabled || (pcSlice->getPPS()->getNumSubstreams() > 1)) && m_pcCfg->getWaveFrontsynchro())
     1183#endif
    11411184    {
    11421185      m_pcBufferSbacCoders[uiTileCol].loadContexts(ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST]);
     
    11771220    m_uiPicDist      += pcCU->getTotalDistortion();
    11781221  }
     1222#if WPP_FIX
     1223  if ((iNumSubstreams > 1) && !depSliceSegmentsEnabled)
     1224#else
    11791225  if ((pcSlice->getPPS()->getNumSubstreams() > 1) && !depSliceSegmentsEnabled)
     1226#endif
    11801227  {
    11811228    pcSlice->setNextSlice( true );
     
    12391286  TEncTop* pcEncTop = (TEncTop*) m_pcCfg;
    12401287  TEncSbac* pcSbacCoders = pcEncTop->getSbacCoders(); //coder for each substream
     1288#if WPP_FIX
     1289  const Int iNumSubstreams = pcSlice->getPPS()->getNumSubstreams();
     1290#else
    12411291  Int iNumSubstreams = pcSlice->getPPS()->getNumSubstreams();
     1292#endif
    12421293  UInt uiBitsOriginallyInSubstreams = 0;
    12431294  {
     
    12601311
    12611312  UInt uiWidthInLCUs  = rpcPic->getPicSym()->getFrameWidthInCU();
     1313#if WPP_FIX
     1314  UInt uiCol=0, uiSubStrm=0;
     1315#else
    12621316  UInt uiCol=0, uiLin=0, uiSubStrm=0;
     1317#endif
    12631318  UInt uiTileCol      = 0;
    12641319  UInt uiTileStartLCU = 0;
     
    12681323                                                                                               an encoding order index, so we need to convert the index (uiStartCUAddr)
    12691324                                                                                               into the real raster scan address (uiCUAddr) via the CUOrderMap */
     1325#if WPP_FIX
     1326  UInt currentTileIdx=rpcPic->getPicSym()->getTileIdxMap(uiCUAddr);
     1327  TComTile *pCurrentTile=rpcPic->getPicSym()->getTComTile(currentTileIdx);
     1328  uiTileStartLCU = pCurrentTile->getFirstCUAddr();
     1329#else
    12701330  uiTileStartLCU = rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr();
     1331#endif
    12711332  if( depSliceSegmentsEnabled )
    12721333  {
     1334#if WPP_FIX
     1335    if( pcSlice->isNextSlice()|| uiCUAddr == uiTileStartLCU)
     1336#else
    12731337    if( pcSlice->isNextSlice()||
    12741338        uiCUAddr == rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr())
     1339#endif
    12751340    {
    12761341      if(m_pcCfg->getWaveFrontsynchro())
     
    12841349      if(m_pcCfg->getWaveFrontsynchro())
    12851350      {
     1351#if WPP_FIX
     1352        uiTileCol = currentTileIdx % (rpcPic->getPicSym()->getNumColumnsMinus1()+1);
     1353#else
    12861354        uiTileCol = rpcPic->getPicSym()->getTileIdxMap(uiCUAddr) % (rpcPic->getPicSym()->getNumColumnsMinus1()+1);
     1355#endif
    12871356        m_pcBufferSbacCoders[uiTileCol].loadContexts( CTXMem[1] );
     1357#if WPP_FIX
     1358        uiCUAddr = rpcPic->getPicSym()->getCUOrderMap( uiStartCUAddr /rpcPic->getNumPartInCU());
     1359        uiSubStrm=rpcPic->getSubstreamForLCUAddr(uiCUAddr, true, pcSlice);
     1360        if ( pCurrentTile->getTileWidth() < 2)
     1361        {
     1362          CTXMem[0]->loadContexts(m_pcSbacCoder);
     1363        }
     1364#else
    12881365        Int iNumSubstreamsPerTile = iNumSubstreams/rpcPic->getPicSym()->getNumTiles();
    12891366        uiLin     = uiCUAddr / uiWidthInLCUs;
     
    12991376          }
    13001377        }
     1378#endif
    13011379      }
    13021380      pcSbacCoders[uiSubStrm].loadContexts( CTXMem[0] );
     
    13141392    //UInt uiSliceStartLCU = pcSlice->getSliceCurStartCUAddr();
    13151393    uiCol     = uiCUAddr % uiWidthInLCUs;
     1394#if WPP_FIX
     1395    uiSubStrm=rpcPic->getSubstreamForLCUAddr(uiCUAddr, true, pcSlice);
     1396#else
    13161397    uiLin     = uiCUAddr / uiWidthInLCUs;
    13171398    if (pcSlice->getPPS()->getNumSubstreams() > 1)
     
    13271408      uiSubStrm = uiLin % iNumSubstreams;
    13281409    }
     1410#endif
    13291411
    13301412    m_pcEntropyCoder->setBitstream( &pcSubstreams[uiSubStrm] );
    13311413    // Synchronize cabac probabilities with upper-right LCU if it's available and we're at the start of a line.
     1414#if WPP_FIX
     1415    if (((iNumSubstreams > 1) || depSliceSegmentsEnabled) && (uiCol == uiTileLCUX) && m_pcCfg->getWaveFrontsynchro())
     1416#else
    13321417    if (((pcSlice->getPPS()->getNumSubstreams() > 1) || depSliceSegmentsEnabled) && (uiCol == uiTileLCUX) && m_pcCfg->getWaveFrontsynchro())
     1418#endif
    13331419    {
    13341420      // We'll sync if the TR is available.
     
    13681454        // When tiles are independent, we have "substreams per tile".  Each substream has already been terminated, and we no longer
    13691455        // have to perform it here.
     1456#if WPP_FIX
     1457        if (iNumSubstreams <= 1)
     1458#else
    13701459        if (pcSlice->getPPS()->getNumSubstreams() > 1)
    13711460        {
     
    13731462        }
    13741463        else
     1464#endif
    13751465        {
    13761466          SliceType sliceType  = pcSlice->getSliceType();
     
    14481538    pcSbacCoders[uiSubStrm].load(m_pcSbacCoder);   //load back status of the entropy coder after encoding the LCU into relevant bitstream entropy coder
    14491539    //Store probabilties of second LCU in line into buffer
     1540#if WPP_FIX
     1541    if ( (depSliceSegmentsEnabled || (iNumSubstreams > 1)) && (uiCol == uiTileLCUX+1) && m_pcCfg->getWaveFrontsynchro())
     1542#else
    14501543    if ( (depSliceSegmentsEnabled || (pcSlice->getPPS()->getNumSubstreams() > 1)) && (uiCol == uiTileLCUX+1) && m_pcCfg->getWaveFrontsynchro())
     1544#endif
    14511545    {
    14521546      m_pcBufferSbacCoders[uiTileCol].loadContexts( &pcSbacCoders[uiSubStrm] );
     
    14801574}
    14811575
     1576#if WPP_FIX
     1577Void TEncSlice::calculateBoundingCUAddrForSlice(UInt &uiStartCUAddrSlice, UInt &uiBoundingCUAddrSlice, Bool &bReachedTileBoundary, TComPic*& rpcPic, Bool bEncodeSlice, Int sliceMode, Int sliceArgument, UInt uiSliceCurEndCUAddr)
     1578{
     1579  TComSlice* pcSlice = rpcPic->getSlice(getSliceIdx());
     1580  UInt uiNumberOfCUsInFrame = rpcPic->getNumCUsInFrame();
     1581  const UInt scaleCUAddr = rpcPic->getNumPartInCU(); // due to fine granularity slices all addresses are scaled.
     1582  uiBoundingCUAddrSlice=0;
     1583  bReachedTileBoundary=false;
     1584
     1585  switch (sliceMode)
     1586  {
     1587  case FIXED_NUMBER_OF_LCU:
     1588    {
     1589      UInt uiCUAddrIncrement    = sliceArgument;
     1590      uiBoundingCUAddrSlice     = ((uiStartCUAddrSlice + uiCUAddrIncrement) < uiNumberOfCUsInFrame*scaleCUAddr) ? (uiStartCUAddrSlice + uiCUAddrIncrement) : uiNumberOfCUsInFrame*scaleCUAddr;
     1591    }
     1592    break;
     1593  case FIXED_NUMBER_OF_BYTES:
     1594    if (bEncodeSlice)
     1595      uiBoundingCUAddrSlice     = uiSliceCurEndCUAddr;
     1596    else
     1597      uiBoundingCUAddrSlice     = uiNumberOfCUsInFrame*scaleCUAddr;
     1598    break;
     1599  case FIXED_NUMBER_OF_TILES:
     1600    {
     1601      UInt tileIdx              = rpcPic->getPicSym()->getTileIdxMap( rpcPic->getPicSym()->getCUOrderMap(uiStartCUAddrSlice/scaleCUAddr) );
     1602      UInt uiCUAddrIncrement    = 0;
     1603      UInt tileTotalCount       = (rpcPic->getPicSym()->getNumColumnsMinus1()+1) * (rpcPic->getPicSym()->getNumRowsMinus1()+1);
     1604
     1605      for(UInt tileIdxIncrement = 0; tileIdxIncrement < sliceArgument; tileIdxIncrement++)
     1606      {
     1607        if((tileIdx + tileIdxIncrement) < tileTotalCount)
     1608        {
     1609          UInt tileWidthInLcu   = rpcPic->getPicSym()->getTComTile(tileIdx + tileIdxIncrement)->getTileWidth();
     1610          UInt tileHeightInLcu  = rpcPic->getPicSym()->getTComTile(tileIdx + tileIdxIncrement)->getTileHeight();
     1611          uiCUAddrIncrement    += (tileWidthInLcu * tileHeightInLcu * scaleCUAddr);
     1612        }
     1613      }
     1614
     1615      uiBoundingCUAddrSlice     = ((uiStartCUAddrSlice + uiCUAddrIncrement) < uiNumberOfCUsInFrame*scaleCUAddr) ? (uiStartCUAddrSlice + uiCUAddrIncrement) : uiNumberOfCUsInFrame*scaleCUAddr;
     1616    }
     1617    break;
     1618  default:
     1619    uiBoundingCUAddrSlice       = uiNumberOfCUsInFrame*scaleCUAddr;
     1620    break;
     1621  }
     1622
     1623  // Adjust for tiles and wavefronts.
     1624  if ((sliceMode == FIXED_NUMBER_OF_LCU || sliceMode == FIXED_NUMBER_OF_BYTES) &&
     1625    (m_pcCfg->getNumRowsMinus1() > 0 || m_pcCfg->getNumColumnsMinus1() > 0))
     1626  {
     1627    const UInt lcuEncAddrStart = (uiStartCUAddrSlice+scaleCUAddr-1)/scaleCUAddr;
     1628    const UInt lcuAddr = rpcPic->getPicSym()->getCUOrderMap(lcuEncAddrStart);
     1629    const UInt startTileIdx = rpcPic->getPicSym()->getTileIdxMap(lcuAddr);
     1630    const Bool bWavefrontsEnabled = m_pcCfg->getWaveFrontsynchro();
     1631
     1632    TComTile *pStartingTile = rpcPic->getPicSym()->getTComTile(startTileIdx);
     1633    const UInt uiTileStartLCUEncAddr      = rpcPic->getPicSym()->getInverseCUOrderMap(pStartingTile->getFirstCUAddr());
     1634    const UInt uiTileStartWidth           = pStartingTile->getTileWidth();
     1635    const UInt uiTileStartHeight          = pStartingTile->getTileHeight();
     1636    const UInt uiTileLastLCUEncAddr_excl  = uiTileStartLCUEncAddr + uiTileStartWidth*uiTileStartHeight;
     1637    const UInt tileBoundingCUAddrSlice    = uiTileLastLCUEncAddr_excl * scaleCUAddr;
     1638
     1639    const UInt lcuColumnOfStartingTile=((lcuEncAddrStart-uiTileStartLCUEncAddr)%uiTileStartWidth);
     1640    if (bWavefrontsEnabled && lcuColumnOfStartingTile!=0)
     1641    {
     1642      // WPP: if a slice does not start at the beginning of a CTB row, it must end within the same CTB row
     1643      const UInt numberOfLCUsToEndOfRow=uiTileStartWidth-lcuColumnOfStartingTile;
     1644      const UInt wavefrontTileBoundingCUAddrSlice = (lcuEncAddrStart+numberOfLCUsToEndOfRow)*scaleCUAddr;
     1645      if (wavefrontTileBoundingCUAddrSlice < uiBoundingCUAddrSlice)
     1646      {
     1647        uiBoundingCUAddrSlice = wavefrontTileBoundingCUAddrSlice;
     1648      }
     1649    }
     1650
     1651    if (tileBoundingCUAddrSlice < uiBoundingCUAddrSlice)
     1652    {
     1653      uiBoundingCUAddrSlice = tileBoundingCUAddrSlice;
     1654      bReachedTileBoundary = true;
     1655    }
     1656  }
     1657  else if (pcSlice->getPPS()->getNumSubstreams() > 1 && (uiStartCUAddrSlice % (rpcPic->getFrameWidthInCU()*scaleCUAddr) != 0))
     1658  {
     1659    // WPP: if a slice does not start at the beginning of a CTB row, it must end within the same CTB row
     1660    uiBoundingCUAddrSlice = min(uiBoundingCUAddrSlice, uiStartCUAddrSlice - (uiStartCUAddrSlice % (rpcPic->getFrameWidthInCU()*scaleCUAddr)) + (rpcPic->getFrameWidthInCU()*scaleCUAddr));
     1661  }
     1662
     1663  //calculate real slice start address (fine granularity slices)
     1664  {
     1665    UInt uiInternalAddress = rpcPic->getPicSym()->getPicSCUAddr(uiStartCUAddrSlice) % scaleCUAddr;
     1666    UInt uiExternalAddress = rpcPic->getPicSym()->getPicSCUAddr(uiStartCUAddrSlice) / scaleCUAddr;
     1667    UInt uiPosX = ( uiExternalAddress % rpcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ];
     1668    UInt uiPosY = ( uiExternalAddress / rpcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ];
     1669#if REPN_FORMAT_IN_VPS
     1670    UInt uiWidth = pcSlice->getPicWidthInLumaSamples();
     1671    UInt uiHeight = pcSlice->getPicHeightInLumaSamples();
     1672#else
     1673    UInt uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples();
     1674    UInt uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples();
     1675#endif
     1676    while((uiPosX>=uiWidth||uiPosY>=uiHeight)&&!(uiPosX>=uiWidth&&uiPosY>=uiHeight))
     1677    {
     1678      uiInternalAddress++;
     1679      if(uiInternalAddress>=scaleCUAddr)
     1680      {
     1681        uiInternalAddress=0;
     1682        uiExternalAddress = rpcPic->getPicSym()->getCUOrderMap(rpcPic->getPicSym()->getInverseCUOrderMap(uiExternalAddress)+1);
     1683      }
     1684      uiPosX = ( uiExternalAddress % rpcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ];
     1685      uiPosY = ( uiExternalAddress / rpcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ];
     1686    }
     1687    UInt uiRealStartAddress = rpcPic->getPicSym()->getPicSCUEncOrder(uiExternalAddress*scaleCUAddr+uiInternalAddress);
     1688
     1689    uiStartCUAddrSlice=uiRealStartAddress;
     1690  }
     1691}
     1692
     1693/** Determines the starting and bounding LCU address of current slice / dependent slice
     1694* \param bEncodeSlice Identifies if the calling function is compressSlice() [false] or encodeSlice() [true]
     1695* \returns Updates uiStartCUAddr, uiBoundingCUAddr with appropriate LCU address
     1696*/
     1697Void TEncSlice::xDetermineStartAndBoundingCUAddr  ( UInt& startCUAddr, UInt& boundingCUAddr, TComPic*& rpcPic, Bool bEncodeSlice )
     1698{
     1699  TComSlice* pcSlice = rpcPic->getSlice(getSliceIdx());
     1700
     1701  // Non-dependent slice
     1702  UInt uiStartCUAddrSlice   = pcSlice->getSliceCurStartCUAddr();
     1703  Bool bTileBoundarySlice   = false;
     1704  UInt uiBoundingCUAddrSlice;
     1705  calculateBoundingCUAddrForSlice(uiStartCUAddrSlice, uiBoundingCUAddrSlice, bTileBoundarySlice, rpcPic, bEncodeSlice, m_pcCfg->getSliceMode(), m_pcCfg->getSliceArgument(), pcSlice->getSliceCurEndCUAddr());
     1706  pcSlice->setSliceCurEndCUAddr( uiBoundingCUAddrSlice );
     1707  pcSlice->setSliceCurStartCUAddr(uiStartCUAddrSlice);
     1708
     1709  // Dependent slice
     1710  UInt startCUAddrSliceSegment    = pcSlice->getSliceSegmentCurStartCUAddr();
     1711  Bool bTileBoundarySliceSegment  = false;
     1712  UInt boundingCUAddrSliceSegment;
     1713  calculateBoundingCUAddrForSlice(startCUAddrSliceSegment, boundingCUAddrSliceSegment, bTileBoundarySliceSegment, rpcPic, bEncodeSlice, m_pcCfg->getSliceSegmentMode(), m_pcCfg->getSliceSegmentArgument(), pcSlice->getSliceSegmentCurEndCUAddr());
     1714  pcSlice->setSliceSegmentCurEndCUAddr( boundingCUAddrSliceSegment );
     1715  pcSlice->setSliceSegmentCurStartCUAddr(startCUAddrSliceSegment);
     1716
     1717  // Make a joint decision based on reconstruction and dependent slice bounds
     1718  startCUAddr    = max(uiStartCUAddrSlice   , startCUAddrSliceSegment   );
     1719  boundingCUAddr = min(uiBoundingCUAddrSlice, boundingCUAddrSliceSegment);
     1720
     1721
     1722  if (!bEncodeSlice)
     1723  {
     1724    // For fixed number of LCU within an entropy and reconstruction slice we already know whether we will encounter end of entropy and/or reconstruction slice
     1725    // first. Set the flags accordingly.
     1726    if ( (m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_LCU && m_pcCfg->getSliceSegmentMode()==FIXED_NUMBER_OF_LCU)
     1727      || (m_pcCfg->getSliceMode()==0 && m_pcCfg->getSliceSegmentMode()==FIXED_NUMBER_OF_LCU)
     1728      || (m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_LCU && m_pcCfg->getSliceSegmentMode()==0)
     1729      || (m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_TILES && m_pcCfg->getSliceSegmentMode()==FIXED_NUMBER_OF_LCU)
     1730      || (m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_TILES && m_pcCfg->getSliceSegmentMode()==0)
     1731      || (m_pcCfg->getSliceSegmentMode()==FIXED_NUMBER_OF_TILES && m_pcCfg->getSliceMode()==0)
     1732      || bTileBoundarySlice || bTileBoundarySliceSegment )
     1733    {
     1734      if (uiBoundingCUAddrSlice < boundingCUAddrSliceSegment)
     1735      {
     1736        pcSlice->setNextSlice       ( true );
     1737        pcSlice->setNextSliceSegment( false );
     1738      }
     1739      else if (uiBoundingCUAddrSlice > boundingCUAddrSliceSegment)
     1740      {
     1741        pcSlice->setNextSlice       ( false );
     1742        pcSlice->setNextSliceSegment( true );
     1743      }
     1744      else
     1745      {
     1746        pcSlice->setNextSlice       ( true );
     1747        pcSlice->setNextSliceSegment( true );
     1748      }
     1749    }
     1750    else
     1751    {
     1752      pcSlice->setNextSlice       ( false );
     1753      pcSlice->setNextSliceSegment( false );
     1754    }
     1755  }
     1756}
     1757#else
    14821758/** Determines the starting and bounding LCU address of current slice / dependent slice
    14831759 * \param bEncodeSlice Identifies if the calling function is compressSlice() [false] or encodeSlice() [true]
     
    18162092  }
    18172093}
     2094#endif
    18182095
    18192096Double TEncSlice::xGetQPValueAccordingToLambda ( Double lambda )
  • trunk/source/Lib/TLibEncoder/TEncSlice.h

    r595 r906  
    150150  Void      setCtxMem( TEncSbac* sb, Int b )   { CTXMem[b] = sb; }
    151151
     152#if WPP_FIX
     153  Void     calculateBoundingCUAddrForSlice(UInt &uiStartCUAddrSlice, UInt &uiBoundingCUAddrSlice, Bool &bReachedTileBoundary, TComPic*& rpcPic, Bool bEncodeSlice, Int sliceMode, Int sliceArgument, UInt uiSliceCurEndCUAddr);
     154#endif
     155
    152156private:
    153157  Double  xGetQPValueAccordingToLambda ( Double lambda );
  • trunk/source/Lib/TLibEncoder/TEncTop.cpp

    r815 r906  
    9898  m_noOutputOfPriorPicsFlags   = false;
    9999#endif
     100#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     101  m_pocDecrementedInDPBFlag    = false;
     102#endif
    100103#endif //SVC_EXTENSION
    101104}
     
    323326  /* set the VPS profile information */
    324327  *m_cVPS.getPTL() = *m_cSPS.getPTL();
     328#if VPS_VUI_BSP_HRD_PARAMS
     329  m_cVPS.getTimingInfo()->setTimingInfoPresentFlag       ( true );
     330#else
    325331  m_cVPS.getTimingInfo()->setTimingInfoPresentFlag       ( false );
     332#endif
    326333  // initialize PPS
    327334  m_cPPS.setSPS(&m_cSPS);
     
    779786        for(UInt i = 0; i < m_cVPS.getNumDirectRefLayers( m_layerId ); i++ )
    780787        {
     788#if MOVE_SCALED_OFFSET_TO_PPS
     789#if O0098_SCALED_REF_LAYER_ID
     790          const Window scalEL = getPPS()->getScaledRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i));
     791#else
     792          const Window scalEL = getPPS()->getScaledRefLayerWindow(i);
     793#endif
     794#else
    781795#if O0098_SCALED_REF_LAYER_ID
    782796          const Window scalEL = getSPS()->getScaledRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i));
     
    784798          const Window scalEL = getSPS()->getScaledRefLayerWindow(i);
    785799#endif
     800#endif
     801#if REF_REGION_OFFSET
     802          const Window altRL  = getPPS()->getRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i));
     803#if RESAMPLING_FIX
     804          Bool equalOffsets = scalEL.hasEqualOffset(altRL);
     805#if R0209_GENERIC_PHASE
     806          Bool zeroPhase = getPPS()->hasZeroResamplingPhase(m_cVPS.getRefLayerId(m_layerId, i));
     807#endif
     808#else
     809          Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0
     810                               && altRL.getWindowLeftOffset() == 0 && altRL.getWindowRightOffset() == 0 && altRL.getWindowTopOffset() == 0 && altRL.getWindowBottomOffset() == 0);
     811#endif
     812#else
    786813          Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0 );
     814#endif
    787815
    788816#if VPS_EXTN_DIRECT_REF_LAYERS
     
    795823          Bool sameBitDepths = ( g_bitDepthYLayer[m_layerId] == g_bitDepthYLayer[refLayerId] ) && ( g_bitDepthCLayer[m_layerId] == g_bitDepthCLayer[refLayerId] );
    796824
    797           if( m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !zeroOffsets || !sameBitDepths
     825#if REF_IDX_MFM
     826          if( m_iSourceWidth == pcEncTopBase->getSourceWidth() && m_iSourceHeight == pcEncTopBase->getSourceHeight() && equalOffsets && zeroPhase )
     827          {
     828            pcEPic->setEqualPictureSizeAndOffsetFlag( i, true );
     829          }
     830
     831          if( !pcEPic->equalPictureSizeAndOffsetFlag(i) || !sameBitDepths
     832#else
     833          if( m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !sameBitDepths
     834#if REF_REGION_OFFSET && RESAMPLING_FIX
     835            || !equalOffsets
     836#if R0209_GENERIC_PHASE
     837            || !zeroPhase
     838#endif
     839#else
     840            || !zeroOffsets
     841#endif
     842#endif
    798843#if Q0048_CGS_3D_ASYMLUT
    799844            || m_cPPS.getCGSFlag() > 0
     
    804849            )
    805850#else
    806           if(m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !zeroOffsets )
     851          if(m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight()
     852#if REF_REGION_OFFSET && RESAMPLING_FIX
     853            || !equalOffsets
     854#if R0209_GENERIC_PHASE
     855            || !zeroPhase
     856#endif
     857#else
     858            || !zeroOffsets
     859#endif
     860          )
    807861#endif
    808862          {
     
    839893        for(UInt i = 0; i < m_cVPS.getNumDirectRefLayers( m_layerId ); i++ )
    840894        {
     895#if MOVE_SCALED_OFFSET_TO_PPS
     896#if O0098_SCALED_REF_LAYER_ID
     897          const Window scalEL = getPPS()->getScaledRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i));
     898#else
     899          const Window scalEL = getPPS()->getScaledRefLayerWindow(i);
     900#endif
     901#else
    841902#if O0098_SCALED_REF_LAYER_ID
    842903          const Window scalEL = getSPS()->getScaledRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i));
     
    844905          const Window scalEL = getSPS()->getScaledRefLayerWindow(i);
    845906#endif
     907#endif
     908#if REF_REGION_OFFSET
     909          const Window altRL  = getPPS()->getRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i));
     910#if RESAMPLING_FIX
     911          Bool equalOffsets = scalEL.hasEqualOffset(altRL);
     912#if R0209_GENERIC_PHASE
     913          Bool zeroPhase = getPPS()->hasZeroResamplingPhase(m_cVPS.getRefLayerId(m_layerId, i));
     914#endif
     915#else
     916          Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0
     917                               && altRL.getWindowLeftOffset() == 0 && altRL.getWindowRightOffset() == 0 && altRL.getWindowTopOffset() == 0 && altRL.getWindowBottomOffset() == 0);
     918#endif
     919#else
    846920          Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0 );
     921#endif
    847922
    848923#if VPS_EXTN_DIRECT_REF_LAYERS
     
    855930          Bool sameBitDepths = ( g_bitDepthYLayer[m_layerId] == g_bitDepthYLayer[refLayerId] ) && ( g_bitDepthCLayer[m_layerId] == g_bitDepthCLayer[refLayerId] );
    856931
    857           if( m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !zeroOffsets || !sameBitDepths
     932          if( m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !sameBitDepths
     933#if REF_REGION_OFFSET && RESAMPLING_FIX
     934            || !equalOffsets
     935#if R0209_GENERIC_PHASE
     936            || !zeroPhase
     937#endif
     938#else
     939            || !zeroOffsets
     940#endif
    858941#if Q0048_CGS_3D_ASYMLUT
    859942            || m_cPPS.getCGSFlag() > 0
     
    864947)
    865948#else
    866           if(m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !zeroOffsets )
     949          if(m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight()
     950#if REF_REGION_OFFSET && RESAMPLING_FIX
     951            || !equalOffsets
     952#if R0209_GENERIC_PHASE
     953            || !zeroPhase
     954#endif
     955#else
     956            || !zeroOffsets
     957#endif
     958          )
    867959#endif
    868960          {
     
    905997#if SVC_EXTENSION
    906998  m_cSPS.setExtensionFlag( m_layerId > 0 ? true : false );
    907 
     999#if R0042_PROFILE_INDICATION
     1000  m_cSPS.setNumDirectRefLayers(m_numAddLayerSets);
     1001#endif
    9081002#if Q0078_ADD_LAYER_SETS
    909   if (getNumDirectRefLayers() == 0 && getNumAddLayerSets() > 0)
     1003  if( !m_numDirectRefLayers && m_numAddLayerSets )
    9101004  {
    9111005    m_cSPS.setLayerId(0); // layer ID 0 for independent layers
     
    9181012  m_cSPS.setLayerId(m_layerId);
    9191013#endif
     1014#if !MOVE_SCALED_OFFSET_TO_PPS
    9201015  m_cSPS.setNumScaledRefLayerOffsets(m_numScaledRefLayerOffsets);
    9211016  for(Int i = 0; i < m_cSPS.getNumScaledRefLayerOffsets(); i++)
     
    9291024#endif
    9301025  }
     1026#endif
    9311027#endif //SVC_EXTENSION
    9321028  ProfileTierLevel& profileTierLevel = *m_cSPS.getPTL()->getGeneralPTL();
     
    10411137  {
    10421138    TComVUI* pcVUI = m_cSPS.getVuiParameters();
    1043     pcVUI->setAspectRatioInfoPresentFlag(getAspectRatioIdc() != -1);
     1139    pcVUI->setAspectRatioInfoPresentFlag(getAspectRatioInfoPresentFlag());
    10441140    pcVUI->setAspectRatioIdc(getAspectRatioIdc());
    10451141    pcVUI->setSarWidth(getSarWidth());
     
    11771273
    11781274#if Q0078_ADD_LAYER_SETS
    1179   if (getNumDirectRefLayers() == 0 && getNumAddLayerSets() > 0)
     1275  if( !m_numDirectRefLayers && m_numAddLayerSets )
    11801276  {
    11811277    m_cPPS.setLayerId(0); // layer ID 0 for independent layers
     
    12031299  {
    12041300    m_cPPS.setNumExtraSliceHeaderBits( 3 );
     1301  }
     1302#endif
     1303#if MOVE_SCALED_OFFSET_TO_PPS
     1304  m_cPPS.setNumScaledRefLayerOffsets(m_numScaledRefLayerOffsets);
     1305  for(Int i = 0; i < m_cPPS.getNumScaledRefLayerOffsets(); i++)
     1306  {
     1307#if O0098_SCALED_REF_LAYER_ID
     1308    m_cPPS.setScaledRefLayerId(i, m_scaledRefLayerId[i]);
     1309#endif
     1310    m_cPPS.getScaledRefLayerWindow(i) = m_scaledRefLayerWindow[i];
     1311#if REF_REGION_OFFSET
     1312    m_cPPS.getRefLayerWindow(i) = m_refLayerWindow[i];
     1313    m_cPPS.setScaledRefLayerOffsetPresentFlag( m_scaledRefLayerId[i], m_scaledRefLayerOffsetPresentFlag[i] );
     1314    m_cPPS.setRefRegionOffsetPresentFlag( m_scaledRefLayerId[i], m_refRegionOffsetPresentFlag[i] );
     1315#endif
     1316#if R0209_GENERIC_PHASE
     1317    m_cPPS.setResamplePhaseSetPresentFlag( m_scaledRefLayerId[i], m_resamplePhaseSetPresentFlag[i] );
     1318    m_cPPS.setPhaseHorLuma( m_scaledRefLayerId[i], m_phaseHorLuma[i] );
     1319    m_cPPS.setPhaseVerLuma( m_scaledRefLayerId[i], m_phaseVerLuma[i] );
     1320    m_cPPS.setPhaseHorChroma( m_scaledRefLayerId[i], m_phaseHorChroma[i] );
     1321    m_cPPS.setPhaseVerChroma( m_scaledRefLayerId[i], m_phaseVerChroma[i] );
     1322#endif
     1323#if P0312_VERT_PHASE_ADJ
     1324    m_cPPS.setVertPhasePositionEnableFlag( m_scaledRefLayerId[i], m_scaledRefLayerWindow[i].getVertPhasePositionEnableFlag() );
     1325#endif
    12051326  }
    12061327#endif
     
    14771598Void  TEncTop::xInitPPSforTiles()
    14781599{
    1479   m_cPPS.setUniformSpacingFlag( m_iUniformSpacingIdr );
    1480   m_cPPS.setNumColumnsMinus1( m_iNumColumnsMinus1 );
    1481   m_cPPS.setNumRowsMinus1( m_iNumRowsMinus1 );
    1482   if( m_iUniformSpacingIdr == 0 )
    1483   {
    1484     m_cPPS.setColumnWidth( m_puiColumnWidth );
    1485     m_cPPS.setRowHeight( m_puiRowHeight );
     1600  m_cPPS.setTileUniformSpacingFlag( m_tileUniformSpacingFlag );
     1601  m_cPPS.setNumTileColumnsMinus1( m_iNumColumnsMinus1 );
     1602  m_cPPS.setNumTileRowsMinus1( m_iNumRowsMinus1 );
     1603  if( !m_tileUniformSpacingFlag )
     1604  {
     1605    m_cPPS.setTileColumnWidth( m_tileColumnWidth );
     1606    m_cPPS.setTileRowHeight( m_tileRowHeight );
    14861607  }
    14871608  m_cPPS.setLoopFilterAcrossTilesEnabledFlag( m_loopFilterAcrossTilesEnabledFlag );
    14881609
    14891610  // # substreams is "per tile" when tiles are independent.
    1490   if (m_iWaveFrontSynchro
    1491     )
     1611  if (m_iWaveFrontSynchro )
    14921612  {
    14931613    m_cPPS.setNumSubstreams(m_iWaveFrontSubstreams * (m_iNumColumnsMinus1+1));
     
    15151635  }
    15161636
    1517   if( m_iNumColumnsMinus1 && m_iUniformSpacingIdr==0 )
     1637  if( m_iNumColumnsMinus1 && !m_tileUniformSpacingFlag )
    15181638  {
    15191639    for(Int i=0; i<m_iNumColumnsMinus1; i++)
    15201640    {
    1521       uiCummulativeColumnWidth += m_puiColumnWidth[i];
     1641      uiCummulativeColumnWidth += m_tileColumnWidth[i];
    15221642    }
    15231643
     
    15421662  }
    15431663
    1544   if( m_iNumRowsMinus1 && m_iUniformSpacingIdr==0 )
     1664  if( m_iNumRowsMinus1 && !m_tileUniformSpacingFlag )
    15451665  {
    15461666    for(Int i=0; i<m_iNumRowsMinus1; i++)
    1547     {
    1548       uiCummulativeRowHeight += m_puiRowHeight[i];
    1549     }
     1667      uiCummulativeRowHeight += m_tileRowHeight[i];
    15501668
    15511669    if( uiCummulativeRowHeight >= iHeightInCU )
     
    16461764
    16471765    Int  numReorderPics[MAX_TLAYER];
     1766#if R0156_CONF_WINDOW_IN_REP_FORMAT
     1767    Window &conformanceWindow = repFormat->getConformanceWindowVps();
     1768#else
    16481769    Window &conformanceWindow = m_cSPS.getConformanceWindow();
     1770#endif
    16491771    Window defaultDisplayWindow = m_cSPS.getVuiParametersPresentFlag() ? m_cSPS.getVuiParameters()->getDefaultDisplayWindow() : Window();
    16501772
     
    16851807  return win;
    16861808}
     1809#if REF_REGION_OFFSET
     1810Window& TEncTop::getRefLayerWindowForLayer(Int layerId)
     1811{
     1812  static Window win;
     1813
     1814  for (Int i = 0; i < m_numScaledRefLayerOffsets; i++)
     1815  {
     1816    if (layerId == m_refLayerId[i])
     1817    {
     1818      return m_refLayerWindow[i];
     1819    }
     1820  }
     1821
     1822  win.resetWindow();  // reference offsets are inferred to be zero when not present
     1823  return win;
     1824}
     1825#endif
    16871826#endif
    16881827
  • trunk/source/Lib/TLibEncoder/TEncTop.h

    r815 r906  
    125125  static Int              m_iSPSIdCnt;                    ///< next Id number for SPS   
    126126  static Int              m_iPPSIdCnt;                    ///< next Id number for PPS   
    127 #if AVC_SYNTAX
    128   fstream*                m_pBLSyntaxFile;
    129 #endif
    130127  TEncTop**               m_ppcTEncTop;
    131128  TEncTop*                getLayerEnc(UInt layer)   { return m_ppcTEncTop[layer]; }
     
    139136#endif
    140137  Window                  m_scaledRefLayerWindow[MAX_LAYERS];
     138#if REF_REGION_OFFSET
     139  UInt                    m_numRefLayerOffsets;
     140  UInt                    m_refLayerId[MAX_LAYERS];
     141  Window                  m_refLayerWindow[MAX_LAYERS];
     142  Bool                    m_scaledRefLayerOffsetPresentFlag[MAX_LAYERS];
     143  Bool                    m_refRegionOffsetPresentFlag[MAX_LAYERS];
     144#endif
     145#if R0209_GENERIC_PHASE
     146  Int                     m_phaseHorLuma  [MAX_LAYERS];
     147  Int                     m_phaseVerLuma  [MAX_LAYERS];
     148  Int                     m_phaseHorChroma[MAX_LAYERS];
     149  Int                     m_phaseVerChroma[MAX_LAYERS];
     150  Int                     m_resamplePhaseSetPresentFlag[MAX_LAYERS];
     151#endif
    141152#if P0312_VERT_PHASE_ADJ
    142153  Bool                    m_vertPhasePositionEnableFlag[MAX_LAYERS];
     
    156167#if Q0078_ADD_LAYER_SETS
    157168  int                     m_numAddLayerSets;
     169#endif
     170#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     171  Bool                    m_pocDecrementedInDPBFlag;
     172  Int                     m_currPocMsb;
    158173#endif
    159174#endif //SVC_EXTENSION
     
    232247#endif
    233248  Window&   getScaledRefLayerWindow(Int x)                 { return m_scaledRefLayerWindow[x];        }
     249#if REF_REGION_OFFSET
     250  Void      setNumRefLayerOffsets(Int x) { m_numRefLayerOffsets = x; }
     251  UInt      getNumRefLayerOffsets() { return m_numRefLayerOffsets; }
     252  Void      setRefLayerId(Int x, UInt id) { m_refLayerId[x] = id;   }
     253  UInt      getRefLayerId(Int x)          { return m_refLayerId[x]; }
     254  Window&   getRefLayerWindowForLayer(Int layerId);
     255  Window&   getRefLayerWindow(Int x)            { return m_refLayerWindow[x]; }
     256  Bool      getScaledRefLayerOffsetPresentFlag(Int x) { return m_scaledRefLayerOffsetPresentFlag[x]; }
     257  Void      setScaledRefLayerOffsetPresentFlag(Int x, Bool b) { m_scaledRefLayerOffsetPresentFlag[x] = b; }
     258  Bool      getRefRegionOffsetPresentFlag(Int x) { return m_refRegionOffsetPresentFlag[x]; }
     259  Void      setRefRegionOffsetPresentFlag(Int x, Bool b) { m_refRegionOffsetPresentFlag[x] = b; }
     260#endif
    234261#if P0312_VERT_PHASE_ADJ
    235262  Void      setVertPhasePositionEnableFlag(Int x, Bool b)  { m_vertPhasePositionEnableFlag[x] = b;    }
    236263  UInt      getVertPhasePositionEnableFlag(Int x)          { return m_vertPhasePositionEnableFlag[x]; }
     264#endif
     265#if R0209_GENERIC_PHASE
     266  Int getPhaseHorLuma(Int x) { return m_phaseHorLuma[x]; }
     267  Int getPhaseVerLuma(Int x) { return m_phaseVerLuma[x]; }
     268  Int getPhaseHorChroma(Int x) { return m_phaseHorChroma[x]; }
     269  Int getPhaseVerChroma(Int x) { return m_phaseVerChroma[x]; }
     270  Void setPhaseHorLuma(Int x, Int val) { m_phaseHorLuma[x] = val; }
     271  Void setPhaseVerLuma(Int x, Int val) { m_phaseVerLuma[x] = val; }
     272  Void setPhaseHorChroma(Int x, Int val) { m_phaseHorChroma[x] = val; }
     273  Void setPhaseVerChroma(Int x, Int val) { m_phaseVerChroma[x] = val; }
     274  Bool getResamplePhaseSetPresentFlag(Int x) { return m_resamplePhaseSetPresentFlag[x]; }
     275  Void setResamplePhaseSetPresentFlag(Int x, Bool b) { m_resamplePhaseSetPresentFlag[x] = b; }
    237276#endif
    238277
     
    245284  Void      setInterLayerWeightedPredFlag(Bool flag)   { m_interLayerWeightedPredFlag = flag; }
    246285  Bool      getInterLayerWeightedPredFlag()            { return m_interLayerWeightedPredFlag; }
    247 #endif
    248 #if AVC_SYNTAX
    249   Void      setBLSyntaxFile( fstream* pFile ) { m_pBLSyntaxFile = pFile; }
    250   fstream*  getBLSyntaxFile() { return m_pBLSyntaxFile; }
    251286#endif
    252287  Void      encode( TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP );
     
    275310  Int  getNumAddLayerSets()                  { return m_numAddLayerSets; }
    276311#endif
     312#if P0297_VPS_POC_LSB_ALIGNED_FLAG
     313  Void setPocDecrementedInDPBFlag(Bool x)    { m_pocDecrementedInDPBFlag = x; }
     314  Bool getPocDecrementedInDPBFlag()          { return m_pocDecrementedInDPBFlag; }
     315  Void setCurrPocMsb(Int poc)                { m_currPocMsb = poc; }
     316  Int  getCurrPocMsb()                       { return m_currPocMsb; }
     317#endif
    277318#else //SVC_EXTENSION
    278319  Void encode( Bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut,
Note: See TracChangeset for help on using the changeset viewer.