diff --git a/source/Lib/CommonLib/Slice.h b/source/Lib/CommonLib/Slice.h index e7cbe11f2c9f3d044705f4ebda877f7ea7eb3630..63e61422159c71e85818f8c24f9725190fa9744c 100644 --- a/source/Lib/CommonLib/Slice.h +++ b/source/Lib/CommonLib/Slice.h @@ -2300,6 +2300,9 @@ public: CcAlfFilterParam& getCcAlfAPSParam() { return m_ccAlfAPSParam; } void setHasPrefixNalUnitType( bool b ) { m_hasPrefixNalUnitType = b; } bool getHasPrefixNalUnitType() const { return m_hasPrefixNalUnitType; } +#if JVET_R0433 + bool chromaPresentFlag; +#endif }; struct WPScalingParam diff --git a/source/Lib/CommonLib/TypeDef.h b/source/Lib/CommonLib/TypeDef.h index b628b1c33be21b782a35bfd32d877486bd3bfb85..8081fc0c07dfcb3bec94745350e0891eeddd4e61 100644 --- a/source/Lib/CommonLib/TypeDef.h +++ b/source/Lib/CommonLib/TypeDef.h @@ -51,6 +51,8 @@ #include <cassert> //########### place macros to be removed in next cycle below this line ############### +#define JVET_R0433 1 // JVET-R0433: APS signaling and semantics cleanup + #define JVET_S0076_ASPECT1 1 // JVET-S0076: aspect 1: Move ph_non_ref_pic_flag to earlier position #define JVET_S0133_PH_SYNTAX_OVERRIDE_ENC_FIX 1 // JVET-S0133: Encoder-only fix on the override of partition constriants in PH diff --git a/source/Lib/DecoderLib/DecLib.cpp b/source/Lib/DecoderLib/DecLib.cpp index 38fef215c1915d6ca1de21176ab2fe8988e15d31..34c4f8aca33423580e50d65e1ed254efa8690c6e 100644 --- a/source/Lib/DecoderLib/DecLib.cpp +++ b/source/Lib/DecoderLib/DecLib.cpp @@ -1287,6 +1287,10 @@ void activateAPS(PicHeader* picHeader, Slice* pSlice, ParameterSetManager& param CHECK( aps->getTemporalId() > pSlice->getTLayer(), "TemporalId shall be less than or equal to the TemporalId of the coded slice NAL unit" ); //ToDO: APS NAL unit containing the APS RBSP shall have nuh_layer_id either equal to the nuh_layer_id of a coded slice NAL unit that referrs it, or equal to the nuh_layer_id of a direct dependent layer of the layer containing a coded slice NAL unit that referrs it. +#if JVET_R0433 + CHECK( sps->getChromaFormatIdc() == CHROMA_400 && aps->chromaPresentFlag, "When ChromaArrayType is equal to 0, the value of aps_chroma_present_flag of an ALF_APS shall be equal to 0" ); +#endif + CHECK(((sps->getCCALFEnabledFlag() == false) && (aps->getCcAlfAPSParam().newCcAlfFilter[0] || aps->getCcAlfAPSParam().newCcAlfFilter[1])), "When sps_ccalf_enabled_flag is 0, the values of alf_cc_cb_filter_signal_flag and alf_cc_cr_filter_signal_flag shall be equal to 0"); } } @@ -1389,6 +1393,12 @@ void activateAPS(PicHeader* picHeader, Slice* pSlice, ParameterSetManager& param THROW("LMCS APS activation failed!"); } +#if JVET_R0433 + CHECK( sps->getChromaFormatIdc() == CHROMA_400 && lmcsAPS->chromaPresentFlag, "When ChromaArrayType is equal to 0, the value of aps_chroma_present_flag of an LMCS_APS shall be equal to 0"); + + CHECK( lmcsAPS->getReshaperAPSInfo().maxNbitsNeededDeltaCW - 1 < 0 || lmcsAPS->getReshaperAPSInfo().maxNbitsNeededDeltaCW - 1 > sps->getBitDepth(CHANNEL_TYPE_LUMA) - 2, "The value of lmcs_delta_cw_prec_minus1 of an LMCS_APS shall be in the range of 0 to BitDepth 2, inclusive" ); +#endif + CHECK( lmcsAPS->getTemporalId() > pSlice->getTLayer(), "TemporalId shall be less than or equal to the TemporalId of the coded slice NAL unit" ); //ToDO: APS NAL unit containing the APS RBSP shall have nuh_layer_id either equal to the nuh_layer_id of a coded slice NAL unit that referrs it, or equal to the nuh_layer_id of a direct dependent layer of the layer containing a coded slice NAL unit that referrs it. } @@ -1407,6 +1417,11 @@ void activateAPS(PicHeader* picHeader, Slice* pSlice, ParameterSetManager& param THROW( "SCALING LIST APS activation failed!" ); } +#if JVET_R0433 + CHECK( (sps->getChromaFormatIdc() == CHROMA_400 && scalingListAPS->chromaPresentFlag) || (sps->getChromaFormatIdc() != CHROMA_400 && !scalingListAPS->chromaPresentFlag), + "The value of aps_chroma_present_flag of the APS NAL unit having aps_params_type equal to SCALING_APS and adaptation_parameter_set_id equal to ph_scaling_list_aps_id shall be equal to ChromaArrayType = = 0 ? 0 : 1" ); +#endif + CHECK( scalingListAPS->getTemporalId() > pSlice->getTLayer(), "TemporalId shall be less than or equal to the TemporalId of the coded slice NAL unit" ); //ToDO: APS NAL unit containing the APS RBSP shall have nuh_layer_id either equal to the nuh_layer_id of a coded slice NAL unit that referrs it, or equal to the nuh_layer_id of a direct dependent layer of the layer containing a coded slice NAL unit that referrs it. } diff --git a/source/Lib/DecoderLib/VLCReader.cpp b/source/Lib/DecoderLib/VLCReader.cpp index 4b3cb438d14b9c25f8ea12a9f052c69fee1e2df6..3ee87217a43622264d2fa23951d97adc438b1065 100644 --- a/source/Lib/DecoderLib/VLCReader.cpp +++ b/source/Lib/DecoderLib/VLCReader.cpp @@ -913,6 +913,13 @@ void HLSyntaxReader::parseAPS( APS* aps ) READ_CODE(3, code, "aps_params_type"); aps->setAPSType( ApsType(code) ); + +#if JVET_R0433 + uint32_t codeApsChromaPresentFlag; + READ_FLAG(codeApsChromaPresentFlag, "aps_chroma_present_flag"); + aps->chromaPresentFlag = codeApsChromaPresentFlag; +#endif + if( code == ALF_APS ) { parseAlfAps( aps ); @@ -945,14 +952,48 @@ void HLSyntaxReader::parseAlfAps( APS* aps ) param.enabledFlag[COMPONENT_Y] = param.enabledFlag[COMPONENT_Cb] = param.enabledFlag[COMPONENT_Cr] = true; READ_FLAG(code, "alf_luma_new_filter"); param.newFilterFlag[CHANNEL_TYPE_LUMA] = code; - READ_FLAG(code, "alf_chroma_new_filter"); - param.newFilterFlag[CHANNEL_TYPE_CHROMA] = code; + + #if JVET_R0433 + if (aps->chromaPresentFlag) + { +#endif + READ_FLAG(code, "alf_chroma_new_filter"); + param.newFilterFlag[CHANNEL_TYPE_CHROMA] = code; +#if JVET_R0433 + } + else + { + param.newFilterFlag[CHANNEL_TYPE_CHROMA] = 0; + } +#endif CcAlfFilterParam ccAlfParam = aps->getCcAlfAPSParam(); +#if JVET_R0433 + if (aps->chromaPresentFlag) + { +#endif READ_FLAG(code, "alf_cc_cb_filter_signal_flag"); ccAlfParam.newCcAlfFilter[COMPONENT_Cb - 1] = code; +#if JVET_R0433 + } + else + { + ccAlfParam.newCcAlfFilter[COMPONENT_Cb - 1] = 0; + } +#endif +#if JVET_R0433 + if (aps->chromaPresentFlag) + { +#endif READ_FLAG(code, "alf_cc_cr_filter_signal_flag"); ccAlfParam.newCcAlfFilter[COMPONENT_Cr - 1] = code; +#if JVET_R0433 + } + else + { + ccAlfParam.newCcAlfFilter[COMPONENT_Cr - 1] = 0; + } +#endif CHECK(param.newFilterFlag[CHANNEL_TYPE_LUMA] == 0 && param.newFilterFlag[CHANNEL_TYPE_CHROMA] == 0 && ccAlfParam.newCcAlfFilter[COMPONENT_Cb - 1] == 0 && ccAlfParam.newCcAlfFilter[COMPONENT_Cr - 1] == 0, "bitstream conformance error: one of alf_luma_filter_signal_flag, alf_chroma_filter_signal_flag, " @@ -1074,8 +1115,17 @@ void HLSyntaxReader::parseLmcsAps( APS* aps ) int signCW = code; info.reshaperModelBinCWDelta[i] = (1 - 2 * signCW) * absCW; } +#if JVET_R0433 + if (aps->chromaPresentFlag) + { +#endif READ_CODE(3, code, "lmcs_delta_abs_crs"); +#if JVET_R0433 + } + int absCW = aps->chromaPresentFlag ? code : 0; +#else int absCW = code; +#endif if (absCW > 0) { READ_CODE(1, code, "lmcs_delta_sign_crs_flag"); @@ -1089,7 +1139,11 @@ void HLSyntaxReader::parseLmcsAps( APS* aps ) void HLSyntaxReader::parseScalingListAps( APS* aps ) { ScalingList& info = aps->getScalingList(); +#if JVET_R0433 + parseScalingList(&info, aps->chromaPresentFlag); +#else parseScalingList( &info ); +#endif } void HLSyntaxReader::parseVUI(VUI* pcVUI, SPS *pcSPS) @@ -4993,16 +5047,29 @@ void HLSyntaxReader::parsePredWeightTable(PicHeader *picHeader, const SPS *sps) /** decode quantization matrix * \param scalingList quantization matrix information */ +#if JVET_R0433 +void HLSyntaxReader::parseScalingList(ScalingList *scalingList, bool aps_chromaPrsentFlag) +#else void HLSyntaxReader::parseScalingList(ScalingList* scalingList) +#endif { uint32_t code; bool scalingListCopyModeFlag; - +#if !JVET_R0433 READ_FLAG(code, "scaling_list_chroma_present_flag"); +#endif +#if JVET_R0433 + scalingList->setChromaScalingListPresentFlag(aps_chromaPrsentFlag); +#else scalingList->setChromaScalingListPresentFlag(code ? true : false); +#endif for (int scalingListId = 0; scalingListId < 28; scalingListId++) { +#if JVET_R0433 + if (aps_chromaPrsentFlag || scalingList->isLumaScalingList(scalingListId)) +#else if(scalingList->getChromaScalingListPresentFlag()|| scalingList->isLumaScalingList(scalingListId)) +#endif { READ_FLAG(code, "scaling_list_copy_mode_flag"); scalingListCopyModeFlag = (code) ? true : false; diff --git a/source/Lib/DecoderLib/VLCReader.h b/source/Lib/DecoderLib/VLCReader.h index 33cebe969bf9936fb6263185003f12e31cfcbe6e..091749fc79a6e9004e6febb635df6cedad106b6f 100644 --- a/source/Lib/DecoderLib/VLCReader.h +++ b/source/Lib/DecoderLib/VLCReader.h @@ -178,7 +178,11 @@ public: void parsePredWeightTable( Slice* pcSlice, const SPS *sps ); void parsePredWeightTable ( PicHeader *picHeader, const SPS *sps ); - void parseScalingList ( ScalingList* scalingList ); +#if JVET_R0433 + void parseScalingList ( ScalingList *scalingList, bool aps_chromaPresentFlag ); +#else + void parseScalingList ( ScalingList *scalingList ); +#endif void decodeScalingList ( ScalingList *scalingList, uint32_t scalingListId, bool isPredictor); void parseReshaper ( SliceReshapeInfo& sliceReshaperInfo, const SPS* pcSPS, const bool isIntra ); void alfFilter( AlfParam& alfParam, const bool isChroma, const int altIdx ); diff --git a/source/Lib/EncoderLib/EncGOP.cpp b/source/Lib/EncoderLib/EncGOP.cpp index 16d9fbf88a949ff697056d4351693ae1d2fdbc04..407b904fa1e9f417aede49d8b8d78760ac48e088 100644 --- a/source/Lib/EncoderLib/EncGOP.cpp +++ b/source/Lib/EncoderLib/EncGOP.cpp @@ -3180,6 +3180,9 @@ void EncGOP::compressGOP( int iPOCLast, int iNumPicRcvd, PicList& rcListPic, bool writeAPS = aps && apsMap->getChangedFlag((apsId << NUM_APS_TYPE_LEN) + LMCS_APS); if (writeAPS) { +#if JVET_R0433 + aps->chromaPresentFlag = pcSlice->getSPS()->getChromaFormatIdc() != CHROMA_400; +#endif actualTotalBits += xWriteAPS( accessUnit, aps, m_pcEncLib->getLayerId(), true ); apsMap->clearChangedFlag((apsId << NUM_APS_TYPE_LEN) + LMCS_APS); CHECK(aps != picHeader->getLmcsAPS(), "Wrong LMCS APS pointer in compressGOP"); @@ -3195,6 +3198,9 @@ void EncGOP::compressGOP( int iPOCLast, int iNumPicRcvd, PicList& rcListPic, bool writeAPS = aps && apsMap->getChangedFlag( ( apsId << NUM_APS_TYPE_LEN ) + SCALING_LIST_APS ); if( writeAPS ) { +#if JVET_R0433 + aps->chromaPresentFlag = pcSlice->getSPS()->getChromaFormatIdc() != CHROMA_400; +#endif actualTotalBits += xWriteAPS( accessUnit, aps, m_pcEncLib->getLayerId(), true ); apsMap->clearChangedFlag( ( apsId << NUM_APS_TYPE_LEN ) + SCALING_LIST_APS ); CHECK( aps != picHeader->getScalingListAPS(), "Wrong SCALING LIST APS pointer in compressGOP" ); @@ -3229,6 +3235,9 @@ void EncGOP::compressGOP( int iPOCLast, int iNumPicRcvd, PicList& rcListPic, if (writeAPS ) { +#if JVET_R0433 + aps->chromaPresentFlag = pcSlice->getSPS()->getChromaFormatIdc() != CHROMA_400; +#endif actualTotalBits += xWriteAPS( accessUnit, aps, m_pcEncLib->getLayerId(), true ); apsMap->clearChangedFlag((apsId << NUM_APS_TYPE_LEN) + ALF_APS); CHECK(aps != pcSlice->getAlfAPSs()[apsId] && apsId != pcSlice->getTileGroupCcAlfCbApsId() && apsId != pcSlice->getTileGroupCcAlfCrApsId(), "Wrong APS pointer in compressGOP"); diff --git a/source/Lib/EncoderLib/VLCWriter.cpp b/source/Lib/EncoderLib/VLCWriter.cpp index a1d1405b97592ff2a008eb258a2f2f8522bfc20b..6f58f7311e9736fcf33a16064b4cb86d80860500 100644 --- a/source/Lib/EncoderLib/VLCWriter.cpp +++ b/source/Lib/EncoderLib/VLCWriter.cpp @@ -513,6 +513,9 @@ void HLSWriter::codeAPS( APS* pcAPS ) WRITE_CODE(pcAPS->getAPSId(), 5, "adaptation_parameter_set_id"); WRITE_CODE( (int)pcAPS->getAPSType(), 3, "aps_params_type" ); +#if JVET_R0433 + WRITE_FLAG(pcAPS->chromaPresentFlag, "aps_chroma_present_flag"); +#endif if (pcAPS->getAPSType() == ALF_APS) { @@ -535,11 +538,25 @@ void HLSWriter::codeAlfAps( APS* pcAPS ) AlfParam param = pcAPS->getAlfAPSParam(); WRITE_FLAG(param.newFilterFlag[CHANNEL_TYPE_LUMA], "alf_luma_new_filter"); +#if JVET_R0433 + if (pcAPS->chromaPresentFlag) + { +#endif WRITE_FLAG(param.newFilterFlag[CHANNEL_TYPE_CHROMA], "alf_chroma_new_filter"); +#if JVET_R0433 + } +#endif CcAlfFilterParam paramCcAlf = pcAPS->getCcAlfAPSParam(); - WRITE_FLAG(paramCcAlf.newCcAlfFilter[COMPONENT_Cb - 1], "alf_cc_cb_filter_signal_flag"); - WRITE_FLAG(paramCcAlf.newCcAlfFilter[COMPONENT_Cr - 1], "alf_cc_cr_filter_signal_flag"); +#if JVET_R0433 + if (pcAPS->chromaPresentFlag) + { +#endif + WRITE_FLAG(paramCcAlf.newCcAlfFilter[COMPONENT_Cb - 1], "alf_cc_cb_filter_signal_flag"); + WRITE_FLAG(paramCcAlf.newCcAlfFilter[COMPONENT_Cr - 1], "alf_cc_cr_filter_signal_flag"); +#if JVET_R0433 + } +#endif if (param.newFilterFlag[CHANNEL_TYPE_LUMA]) { @@ -632,10 +649,21 @@ void HLSWriter::codeLmcsAps( APS* pcAPS ) WRITE_FLAG(signCW, "lmcs_delta_sign_cw_flag[ i ]"); } } +#if JVET_R0433 + int deltaCRS = pcAPS->chromaPresentFlag ? param.chrResScalingOffset : 0; +#else int deltaCRS = param.chrResScalingOffset; +#endif int signCRS = (deltaCRS < 0) ? 1 : 0; int absCRS = (deltaCRS < 0) ? (-deltaCRS) : deltaCRS; - WRITE_CODE(absCRS, 3, "lmcs_delta_abs_crs"); +#if JVET_R0433 + if (pcAPS->chromaPresentFlag) + { +#endif + WRITE_CODE(absCRS, 3, "lmcs_delta_abs_crs"); +#if JVET_R0433 + } +#endif if (absCRS > 0) { WRITE_FLAG(signCRS, "lmcs_delta_sign_crs_flag"); @@ -645,7 +673,11 @@ void HLSWriter::codeLmcsAps( APS* pcAPS ) void HLSWriter::codeScalingListAps( APS* pcAPS ) { ScalingList param = pcAPS->getScalingList(); +#if JVET_R0433 + codeScalingList(param, pcAPS->chromaPresentFlag); +#else codeScalingList( param ); +#endif } void HLSWriter::codeVUI( const VUI *pcVUI, const SPS* pcSPS ) @@ -2917,13 +2949,23 @@ void HLSWriter::xCodePredWeightTable(PicHeader *picHeader, const SPS *sps) /** code quantization matrix * \param scalingList quantization matrix information */ +#if JVET_R0433 +void HLSWriter::codeScalingList( const ScalingList &scalingList, bool aps_chromaPresentFlag ) +#else void HLSWriter::codeScalingList( const ScalingList &scalingList ) +#endif { //for each size +#if !JVET_R0433 WRITE_FLAG(scalingList.getChromaScalingListPresentFlag(), "scaling_list_chroma_present_flag"); +#endif for (uint32_t scalingListId = 0; scalingListId < 28; scalingListId++) { +#if JVET_R0433 + if (aps_chromaPresentFlag || scalingList.isLumaScalingList(scalingListId)) +#else if(scalingList.getChromaScalingListPresentFlag()|| scalingList.isLumaScalingList(scalingListId)) +#endif { bool scalingListCopyModeFlag = scalingList.getScalingListCopyModeFlag(scalingListId); WRITE_FLAG(scalingListCopyModeFlag, "scaling_list_copy_mode_flag"); //copy mode diff --git a/source/Lib/EncoderLib/VLCWriter.h b/source/Lib/EncoderLib/VLCWriter.h index c044001e6745f22504e72700f03e1aa89eab1274..45e7cb2010b0fb711266789e22f5d95c036c68af 100644 --- a/source/Lib/EncoderLib/VLCWriter.h +++ b/source/Lib/EncoderLib/VLCWriter.h @@ -141,8 +141,11 @@ public: void codeGeneralHrdparameters(const GeneralHrdParams *hrd); void codeTilesWPPEntryPoint ( Slice* pSlice ); +#if JVET_R0433 + void codeScalingList(const ScalingList &scalingList, bool aps_chromaPresentFlag); +#else void codeScalingList ( const ScalingList &scalingList ); - +#endif void alfFilter( const AlfParam& alfParam, const bool isChroma, const int altIdx ); void dpb_parameters(int maxSubLayersMinus1, bool subLayerInfoFlag, const SPS *pcSPS); private: