diff --git a/doc/software-manual.tex b/doc/software-manual.tex index 5a28f878430813ce0331be5e330e3c8fa70e57bb..c0e19aa2b0e728a583344a3c06c36c2272d40a73 100644 --- a/doc/software-manual.tex +++ b/doc/software-manual.tex @@ -3070,6 +3070,18 @@ Enables control of CCALF filter strength. The parameter scales the magnitudes of Enables control of CCALF filter strength target in filter optimization. The parameter scales the auto-correlation matrix E and the cross-correlation vector y for CCALF. Valid values are in the range 0.0 to 1.0. \\ +\Option{MaxNumALFAPS} & +%\ShortOption{\None} & +\Default{8} & +Maximum number of ALF APSs. +\\ + +\Option{ConstantJointCbCrSignFlag} & +%\ShortOption{\None} & +\Default{0} & +Constant JointCbCr sign flag. +\\ + \Option{SMVD} & %\ShortOption{\None} & \Default{false} & diff --git a/source/App/BitstreamExtractorApp/BitstreamExtractorApp.cpp b/source/App/BitstreamExtractorApp/BitstreamExtractorApp.cpp index 40834c3c1cda7b797726a70e09155d994ec19085..7a34a185f4263904d34dfed5ee7956ceca42c654 100644 --- a/source/App/BitstreamExtractorApp/BitstreamExtractorApp.cpp +++ b/source/App/BitstreamExtractorApp/BitstreamExtractorApp.cpp @@ -274,7 +274,10 @@ void BitstreamExtractorApp::xRewritePPS(PPS &targetPPS, const PPS &sourcePPS, co targetPPS.setPicWidthInLumaSamples(subPic.getSubPicWidthInLumaSample()); targetPPS.setPicHeightInLumaSamples(subPic.getSubPicHeightInLumaSample()); // todo: Conformance window (conf window rewriting is not needed per JVET-S0117) - +#if JVET_X0143_EXTRACTOR_FIXES + if (sourcePPS.getScalingWindow().getWindowEnabledFlag()) + { +#endif int subWidthC = SPS::getWinUnitX(sourceSPS.getChromaFormatIdc()); int subHeightC = SPS::getWinUnitY(sourceSPS.getChromaFormatIdc()); int subpicScalWinLeftOffset = sourcePPS.getScalingWindow().getWindowLeftOffset() - (int)subPic.getSubPicCtuTopLeftX() * sourceSPS.getCTUSize() / subWidthC; @@ -286,7 +289,9 @@ void BitstreamExtractorApp::xRewritePPS(PPS &targetPPS, const PPS &sourcePPS, co Window scalingWindow; scalingWindow.setWindow(subpicScalWinLeftOffset, subpicScalWinRightOffset, subpicScalWinTopOffset, subpicScalWinBotOffset); targetPPS.setScalingWindow(scalingWindow); - +#if JVET_X0143_EXTRACTOR_FIXES + } +#endif // Tiles int numTileCols = 1; int numTileRows = 1; diff --git a/source/App/EncoderApp/EncApp.cpp b/source/App/EncoderApp/EncApp.cpp index 4efcbcb9f0f492541bf33a59b868dff1bdace5e5..eb4ea511368bbd58de796d07b8343cccc957d42e 100644 --- a/source/App/EncoderApp/EncApp.cpp +++ b/source/App/EncoderApp/EncApp.cpp @@ -1201,7 +1201,10 @@ void EncApp::xInitLibCfg() m_cEncLib.setReshapeIntraCMD ( m_intraCMD ); m_cEncLib.setReshapeCW ( m_reshapeCW ); m_cEncLib.setReshapeCSoffset ( m_CSoffset ); - +#if JVET_X0143_ALF_APS_CHANGES + m_cEncLib.setMaxNumALFAPS (m_maxNumAlfAps); + m_cEncLib.setConstantJointCbCrSignFlag (m_constantJointCbCrSignFlag); +#endif #if JVET_O0756_CALCULATE_HDRMETRICS for (int i=0; i<hdrtoolslib::NB_REF_WHITE; i++) { diff --git a/source/App/EncoderApp/EncAppCfg.cpp b/source/App/EncoderApp/EncAppCfg.cpp index 67ab25b6767b8ce48588769b4f60bd21e23873b7..8f7e8e384605fe47fbb57559271186f2dbca97ed 100644 --- a/source/App/EncoderApp/EncAppCfg.cpp +++ b/source/App/EncoderApp/EncAppCfg.cpp @@ -1579,6 +1579,10 @@ bool EncAppCfg::parseCfg( int argc, char* argv[] ) ("DebugCTU", m_debugCTU, -1, "If DebugBitstream is present, load frames up to this POC from this bitstream. Starting with DebugPOC-frame at CTUline containin debug CTU.") ("AlfTrueOrg", m_alfTrueOrg, true, "Using true original samples for ALF optimization when MCTF is enabled\n") ( "ALF", m_alf, true, "Adaptive Loop Filter\n" ) +#if JVET_X0143_ALF_APS_CHANGES + ("MaxNumALFAPS", m_maxNumAlfAps, 8, "Maximum number of ALF APSs" ) + ("ConstantJointCbCrSignFlag", m_constantJointCbCrSignFlag, 0, "Constant JointCbCr sign flag" ) +#endif ("ALFStrengthLuma", m_alfStrengthLuma, 1.0, "Adaptive Loop Filter strength for luma. The parameter scales the magnitudes of the ALF filter coefficients for luma. Valid range is 0.0 <= ALFStrengthLuma <= 1.0") ("ALFAllowPredefinedFilters", m_alfAllowPredefinedFilters, true, "Allow use of predefined filters for ALF") ("CCALFStrength", m_ccalfStrength, 1.0, "Cross-component Adaptive Loop Filter strength. The parameter scales the magnitudes of the CCALF filter coefficients. Valid range is 0.0 <= CCALFStrength <= 1.0") @@ -3045,6 +3049,9 @@ bool EncAppCfg::xCheckParameter() bool check_failed = false; /* abort if there is a fatal configuration problem */ #define xConfirmPara(a,b) check_failed |= confirmPara(a,b) +#if JVET_X0143_ALF_APS_CHANGES + xConfirmPara(m_maxNumAlfAps > ALF_CTB_MAX_NUM_APS, "The number of ALF APSs should not be more than ALF_CTB_MAX_NUM_APS"); +#endif if( m_depQuantEnabledFlag ) { @@ -3400,6 +3407,12 @@ bool EncAppCfg::xCheckParameter() xConfirmPara( m_ccalf, "CCALF cannot be enabled when ALF is disabled" ); } +#if JVET_X0143_ALF_APS_CHANGES + if (m_maxNumAlfAps == 0) + { + xConfirmPara(m_ccalf, "CCALF cannot be enabled when ALF APS is disabled"); + } +#endif xConfirmPara( m_sourceWidth % SPS::getWinUnitX(m_chromaFormatIDC) != 0, "Picture width must be an integer multiple of the specified chroma subsampling"); xConfirmPara( m_sourceHeight % SPS::getWinUnitY(m_chromaFormatIDC) != 0, "Picture height must be an integer multiple of the specified chroma subsampling"); @@ -4522,7 +4535,10 @@ void EncAppCfg::xPrintParameter() msg( VERBOSE, "SAO:%d ", (m_bUseSAO)?(1):(0)); msg( VERBOSE, "ALF:%d ", m_alf ? 1 : 0 ); msg( VERBOSE, "CCALF:%d ", m_ccalf ? 1 : 0 ); - +#if JVET_X0143_ALF_APS_CHANGES + msg(VERBOSE, "MaxNumALFAPS", m_maxNumAlfAps); + msg(VERBOSE, "ConstantJointCbCrSignFlag", m_constantJointCbCrSignFlag); +#endif msg( VERBOSE, "WPP:%d ", (int)m_useWeightedPred); msg( VERBOSE, "WPB:%d ", (int)m_useWeightedBiPred); msg( VERBOSE, "PME:%d ", m_log2ParallelMergeLevel); diff --git a/source/App/EncoderApp/EncAppCfg.h b/source/App/EncoderApp/EncAppCfg.h index ccf8cfa6c5fe95dbee98a21105c0703b2d7fa1c3..a52f6823463008c0d1d95f11258fc2fe3b7932e9 100644 --- a/source/App/EncoderApp/EncAppCfg.h +++ b/source/App/EncoderApp/EncAppCfg.h @@ -808,7 +808,11 @@ protected: bool m_bs2ModPOCAndType; bool m_forceDecodeBitstream1; - bool m_alf; ///< Adaptive Loop Filter +#if JVET_X0143_ALF_APS_CHANGES + int m_maxNumAlfAps; + int m_constantJointCbCrSignFlag; +#endif + bool m_alf; ///< Adaptive Loop Filter bool m_alfTrueOrg; double m_alfStrengthLuma; bool m_alfAllowPredefinedFilters; diff --git a/source/App/SubpicMergeApp/SubpicMergeApp.cpp b/source/App/SubpicMergeApp/SubpicMergeApp.cpp index c5903447ac12ecd673bfc383837d3e6ac40d0129..0c6bd4eb9544637ae442d451704ff3d556956554 100644 --- a/source/App/SubpicMergeApp/SubpicMergeApp.cpp +++ b/source/App/SubpicMergeApp/SubpicMergeApp.cpp @@ -521,7 +521,11 @@ void SubpicMergeApp::generateMergedStreamSPSes(std::vector<SPS*> &spsList) { for (auto spsId : subpic.spsIds) { +#if JVET_X0143_MERGER_FIXES + CHECK(subpic.psManager.getSPS(spsId)->getSubPicInfoPresentFlag() && subpic.psManager.getSPS(spsId)->getNumSubPics() > 1, "Input streams containing subpictures not supported"); +#else CHECK(subpic.psManager.getSPS(spsId)->getSubPicInfoPresentFlag(), "Input streams containing subpictures not supported") +#endif } } @@ -1007,6 +1011,9 @@ void SubpicMergeApp::generateMergedPic(ParameterSetManager &psManager, bool mixe updateSliceHeadersForMergedStream(psManager); // Code merged stream prefix APS NAL units +#if JVET_X0143_MERGER_FIXES + std::vector<int> usedApsIds; +#endif for (auto &subpic : *m_subpics) { auto apsIdIt = subpic.apsIds.begin(); @@ -1014,11 +1021,19 @@ void SubpicMergeApp::generateMergedPic(ParameterSetManager &psManager, bool mixe { if (nalu.m_nalUnitType == NAL_UNIT_PREFIX_APS) { +#if JVET_X0143_MERGER_FIXES + if (std::find(usedApsIds.begin(), usedApsIds.end(), apsIdIt->first) == usedApsIds.end()) + { +#endif OutputNALUnit naluOut(NAL_UNIT_PREFIX_APS, nalu.m_nuhLayerId, nalu.m_temporalId); hlsWriter.setBitstream( &naluOut.m_Bitstream ); hlsWriter.codeAPS(subpic.psManager.getAPS(apsIdIt->first, apsIdIt->second)); accessUnit.push_back(new NALUnitEBSP(naluOut)); apsIdIt++; +#if JVET_X0143_MERGER_FIXES + usedApsIds.push_back(apsIdIt->first); + } +#endif } } } diff --git a/source/Lib/CommonLib/TypeDef.h b/source/Lib/CommonLib/TypeDef.h index a938783ef656703151620ccb54dac54f4f2eaa3e..422d1fb63316364daf2477af7f820fea8735d09f 100644 --- a/source/Lib/CommonLib/TypeDef.h +++ b/source/Lib/CommonLib/TypeDef.h @@ -53,6 +53,10 @@ // clang-format off //########### place macros to be removed in next cycle below this line ############### +#define JVET_X0143_ALF_APS_CHANGES 1 +#define JVET_X0143_ALF_APS_ID_OFFSET 0 // A value between 0 to 7 inclusive. This macro should be kept, or to be defined as a configuration parameter if possible. +#define JVET_X0143_MERGER_FIXES 1 +#define JVET_X0143_EXTRACTOR_FIXES 1 #define JVET_X0128_V2_WPP 1 // JVET-X0128 method 2, VVC v2 WPP diff --git a/source/Lib/EncoderLib/EncAdaptiveLoopFilter.cpp b/source/Lib/EncoderLib/EncAdaptiveLoopFilter.cpp index dd40a624c790b15b83413883719e1e9e9166658f..480aa23e340f3f6106b2998a1dea1d09ab83e188 100644 --- a/source/Lib/EncoderLib/EncAdaptiveLoopFilter.cpp +++ b/source/Lib/EncoderLib/EncAdaptiveLoopFilter.cpp @@ -884,7 +884,11 @@ void EncAdaptiveLoopFilter::ALFProcess(CodingStructure& cs, const double *lambda if( !layerIdx && ( cs.slice->getPendingRasInit() || cs.slice->isIDRorBLA() || ( cs.slice->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_encCfg->getCraAPSreset() ) ) ) { memset(cs.slice->getAlfAPSs(), 0, sizeof(*cs.slice->getAlfAPSs())*ALF_CTB_MAX_NUM_APS); +#if JVET_X0143_ALF_APS_CHANGES + m_apsIdStart = m_encCfg->getMaxNumALFAPS(); +#else m_apsIdStart = ALF_CTB_MAX_NUM_APS; +#endif m_apsMap->clearActive(); for (int i = 0; i < ALF_CTB_MAX_NUM_APS; i++) @@ -1017,7 +1021,11 @@ void EncAdaptiveLoopFilter::ALFProcess(CodingStructure& cs, const double *lambda ); // derive filter (chroma) +#if JVET_X0143_ALF_APS_CHANGES + if (!(m_encCfg->getMaxNumALFAPS() == 0) && isChromaEnabled(cs.pcv->chrFormat)) // Find ALF parameters for chroma if ALF APS is enabled +#else if (isChromaEnabled(cs.pcv->chrFormat)) +#endif { alfEncoder( cs, alfParam, orgYuv, recYuv, cs.getRecoBuf(), CHANNEL_TYPE_CHROMA #if ENABLE_QPA @@ -2547,17 +2555,30 @@ void EncAdaptiveLoopFilter::setCtuEnableFlag( uint8_t** ctuFlags, ChannelType ch std::vector<int> EncAdaptiveLoopFilter::getAvaiApsIdsLuma(CodingStructure& cs, int &newApsId) { APS** apss = cs.slice->getAlfAPSs(); +#if JVET_X0143_ALF_APS_CHANGES + for (int i = 0; i < m_encCfg->getMaxNumALFAPS(); i++) +#else for (int i = 0; i < ALF_CTB_MAX_NUM_APS; i++) +#endif { apss[i] = m_apsMap->getPS((i << NUM_APS_TYPE_LEN) + ALF_APS); } std::vector<int> result; int apsIdChecked = 0, curApsId = m_apsIdStart; +#if JVET_X0143_ALF_APS_CHANGES + if (curApsId < m_encCfg->getMaxNumALFAPS()) +#else if (curApsId < ALF_CTB_MAX_NUM_APS) +#endif { +#if JVET_X0143_ALF_APS_CHANGES + while ((apsIdChecked < m_encCfg->getMaxNumALFAPS()) && !cs.slice->isIRAP() && (result.size() < m_encCfg->getMaxNumALFAPS()) + && !cs.slice->getPendingRasInit()) +#else while (apsIdChecked < ALF_CTB_MAX_NUM_APS && !cs.slice->isIRAP() && result.size() < ALF_CTB_MAX_NUM_APS && !cs.slice->getPendingRasInit()) +#endif { APS* curAPS = cs.slice->getAlfAPSs()[curApsId]; @@ -2566,7 +2587,11 @@ std::vector<int> EncAdaptiveLoopFilter::getAvaiApsIdsLuma(CodingStructure& cs, i result.push_back(curApsId); } apsIdChecked++; +#if JVET_X0143_ALF_APS_CHANGES + curApsId = (curApsId + 1) % m_encCfg->getMaxNumALFAPS(); +#else curApsId = (curApsId + 1) % ALF_CTB_MAX_NUM_APS; +#endif } } cs.slice->setNumAlfApsIdsLuma((int)result.size()); @@ -2574,9 +2599,17 @@ std::vector<int> EncAdaptiveLoopFilter::getAvaiApsIdsLuma(CodingStructure& cs, i newApsId = m_apsIdStart - 1; if (newApsId < 0) { +#if JVET_X0143_ALF_APS_CHANGES + newApsId = m_encCfg->getMaxNumALFAPS() - 1; +#else newApsId = ALF_CTB_MAX_NUM_APS - 1; +#endif } +#if JVET_X0143_ALF_APS_CHANGES + CHECK(newApsId >= m_encCfg->getMaxNumALFAPS(), "Wrong APS index assignment in getAvaiApsIdsLuma"); +#else CHECK(newApsId >= ALF_CTB_MAX_NUM_APS, "Wrong APS index assignment in getAvaiApsIdsLuma"); +#endif return result; } void EncAdaptiveLoopFilter::initDistortion() @@ -2651,7 +2684,17 @@ void EncAdaptiveLoopFilter::alfEncoderCtb(CodingStructure& cs, AlfParam& alfPar int numIter = useNewFilter ? 2 : 1; for (int numTemporalAps = 0; numTemporalAps <= apsIds.size(); numTemporalAps++) { +#if JVET_X0143_ALF_APS_CHANGES + if ((m_encCfg->getMaxNumALFAPS()==0) && ((numTemporalAps + useNewFilter) > 0)) + { + continue; + } +#endif +#if JVET_X0143_ALF_APS_CHANGES + if (numTemporalAps + useNewFilter > std::min(ALF_CTB_MAX_NUM_APS - 1, m_encCfg->getMaxNumALFAPS())) +#else if (numTemporalAps + useNewFilter >= ALF_CTB_MAX_NUM_APS) +#endif { continue; } @@ -2896,7 +2939,11 @@ void EncAdaptiveLoopFilter::alfEncoderCtb(CodingStructure& cs, AlfParam& alfPar } //chroma +#if JVET_X0143_ALF_APS_CHANGES + if (!(m_encCfg->getMaxNumALFAPS() == 0) && isChromaEnabled(cs.pcv->chrFormat)) // Find ALF parameters for chroma if ALF APS is enabled. +#else if (isChromaEnabled(cs.pcv->chrFormat)) +#endif { m_alfParamTemp = alfParamNewFiltersBest; if (m_alfParamTemp.numAlternativesChroma < 1) @@ -2919,12 +2966,23 @@ void EncAdaptiveLoopFilter::alfEncoderCtb(CodingStructure& cs, AlfParam& alfPar else if (alfParamNewFiltersBest.enabledFlag[COMPONENT_Cb] || alfParamNewFiltersBest.enabledFlag[COMPONENT_Cr]) { int curId = m_apsIdStart; +// Do not assign ALF APS for chroma if any new APS ID is not avaiable + +#if JVET_X0143_ALF_APS_CHANGES + int counter = m_encCfg->getMaxNumALFAPS(); + while ((newApsIdChroma < 0) && ((counter--))) +#else while (newApsIdChroma < 0) +#endif { curId--; if (curId < 0) { +#if JVET_X0143_ALF_APS_CHANGES + curId = m_encCfg->getMaxNumALFAPS() - 1; +#else curId = ALF_CTB_MAX_NUM_APS - 1; +#endif } if (std::find(bestApsIds.begin(), bestApsIds.end(), curId) == bestApsIds.end()) { @@ -2932,7 +2990,11 @@ void EncAdaptiveLoopFilter::alfEncoderCtb(CodingStructure& cs, AlfParam& alfPar } } } +#if JVET_X0143_ALF_APS_CHANGES + for (int curApsId = 0; curApsId < m_encCfg->getMaxNumALFAPS(); curApsId++) +#else for (int curApsId = 0; curApsId < ALF_CTB_MAX_NUM_APS; curApsId++) +#endif { const bool reuseExistingAPS = curApsId != newApsIdChroma; @@ -3581,17 +3643,28 @@ void EncAdaptiveLoopFilter::determineControlIdcValues(CodingStructure &cs, const std::vector<int> EncAdaptiveLoopFilter::getAvailableCcAlfApsIds(CodingStructure& cs, ComponentID compID) { APS** apss = cs.slice->getAlfAPSs(); +#if JVET_X0143_ALF_APS_CHANGES + for (int i = 0; i < m_encCfg->getMaxNumALFAPS(); i++) +#else for (int i = 0; i < ALF_CTB_MAX_NUM_APS; i++) +#endif { apss[i] = m_apsMap->getPS((i << NUM_APS_TYPE_LEN) + ALF_APS); } std::vector<int> result; int apsIdChecked = 0, curApsId = m_apsIdStart; +#if JVET_X0143_ALF_APS_CHANGES + if (curApsId < m_encCfg->getMaxNumALFAPS()) + { + while ((apsIdChecked < m_encCfg->getMaxNumALFAPS()) && !cs.slice->isIRAP() && (result.size() < m_encCfg->getMaxNumALFAPS()) + && !cs.slice->getPendingRasInit()) +#else if (curApsId < ALF_CTB_MAX_NUM_APS) { while (apsIdChecked < ALF_CTB_MAX_NUM_APS && !cs.slice->isIRAP() && result.size() < ALF_CTB_MAX_NUM_APS && !cs.slice->getPendingRasInit()) +#endif { APS* curAPS = cs.slice->getAlfAPSs()[curApsId]; if (curAPS && curAPS->getLayerId() == cs.slice->getPic()->layerId @@ -3600,7 +3673,11 @@ std::vector<int> EncAdaptiveLoopFilter::getAvailableCcAlfApsIds(CodingStructure& result.push_back(curApsId); } apsIdChecked++; +#if JVET_X0143_ALF_APS_CHANGES + curApsId = (curApsId + 1) % m_encCfg->getMaxNumALFAPS(); +#else curApsId = (curApsId + 1) % ALF_CTB_MAX_NUM_APS; +#endif } } return result; diff --git a/source/Lib/EncoderLib/EncCfg.h b/source/Lib/EncoderLib/EncCfg.h index 748f5680b5cb277829bf6a5d27bdc7f5fc1f5d18..2d6adad2480cb767acff582554d749ea3031bc49 100644 --- a/source/Lib/EncoderLib/EncCfg.h +++ b/source/Lib/EncoderLib/EncCfg.h @@ -853,6 +853,10 @@ protected: CfgVPSParameters m_cfgVPSParameters; +#if JVET_X0143_ALF_APS_CHANGES + int m_maxNumAlfAps; + bool m_constantJointCbCrSignFlag; +#endif bool m_alf; ///< Adaptive Loop Filter bool m_alfTrueOrg; double m_alfStrengthLuma; @@ -2272,6 +2276,13 @@ public: void setDebugCTU( int i ) { m_debugCTU = i; } int getDebugCTU() const { return m_debugCTU; } +#if JVET_X0143_ALF_APS_CHANGES + void setMaxNumALFAPS(int n) { m_maxNumAlfAps = n; } + int getMaxNumALFAPS() const { return m_maxNumAlfAps; } + void setConstantJointCbCrSignFlag(bool b) { m_constantJointCbCrSignFlag = b; } + int getConstantJointCbCrSignFlag() const { return m_constantJointCbCrSignFlag; } +#endif + void setUseALF( bool b ) { m_alf = b; } bool getUseALF() const { return m_alf; } void setAlfTrueOrg( bool b ) { m_alfTrueOrg = b; } diff --git a/source/Lib/EncoderLib/EncGOP.cpp b/source/Lib/EncoderLib/EncGOP.cpp index e8aa895a51658c0f7043a39be6b549089328efb3..17a827756e91982e4efd025a2cc8cdfcba7772f7 100644 --- a/source/Lib/EncoderLib/EncGOP.cpp +++ b/source/Lib/EncoderLib/EncGOP.cpp @@ -3111,9 +3111,13 @@ void EncGOP::compressGOP( int iPOCLast, int iNumPicRcvd, PicList& rcListPic, } if (pcSlice->getSPS()->getJointCbCrEnabledFlag()) { - m_pcSliceEncoder->setJointCbCrModes(*pcPic->cs, Position(0, 0), pcPic->cs->area.lumaSize()); +#if JVET_X0143_ALF_APS_CHANGES + if (m_pcCfg->getConstantJointCbCrSignFlag()) + pcPic->cs->picHeader->setJointCbCrSignFlag(m_pcCfg->getConstantJointCbCrSignFlag()-1); + else +#endif + m_pcSliceEncoder->setJointCbCrModes(*pcPic->cs, Position(0, 0), pcPic->cs->area.lumaSize()); } - if (!pcSlice->getSPS()->getSpsRangeExtension().getReverseLastSigCoeffEnabledFlag() || pcSlice->getSliceQp() > 12) { pcSlice->setReverseLastSigCoeffFlag(false); @@ -3512,13 +3516,21 @@ void EncGOP::compressGOP( int iPOCLast, int iNumPicRcvd, PicList& rcListPic, // Get active ALF APSs from picture/slice header const std::vector<int> sliceApsIdsLuma = pcSlice->getAlfApsIdsLuma(); +#if JVET_X0143_ALF_APS_CHANGES + m_pcALF->setApsIdStart(m_pcCfg->getMaxNumALFAPS()); +#else m_pcALF->setApsIdStart( ALF_CTB_MAX_NUM_APS ); +#endif ParameterSetMap<APS>* apsMap = m_pcEncLib->getApsMap(); apsMap->clearActive(); - for( int apsId = 0; apsId < ALF_CTB_MAX_NUM_APS; apsId++ ) - { +#if JVET_X0143_ALF_APS_CHANGES + for (int apsId = 0; apsId < m_pcCfg->getMaxNumALFAPS(); apsId++) +#else + for( int apsId = 0; apsId < ALF_CTB_MAX_NUM_APS; apsId++ ) +#endif + { int psId = ( apsId << NUM_APS_TYPE_LEN ) + ALF_APS; APS* aps = apsMap->getPS( psId ); if( aps ) @@ -3559,7 +3571,11 @@ void EncGOP::compressGOP( int iPOCLast, int iNumPicRcvd, PicList& rcListPic, // Assign tne correct APS to slice and emulate the setting of ALF start APS ID int changedApsId = -1; - for( int apsId = ALF_CTB_MAX_NUM_APS - 1; apsId >= 0; apsId-- ) +#if JVET_X0143_ALF_APS_CHANGES + for (int apsId = m_pcCfg->getMaxNumALFAPS() - 1; apsId >= 0; apsId--) +#else + for (int apsId = ALF_CTB_MAX_NUM_APS - 1; apsId >= 0; apsId--) +#endif { ParameterSetMap<APS>* apsMap = m_pcEncLib->getApsMap(); int psId = ( apsId << NUM_APS_TYPE_LEN ) + ALF_APS; @@ -3698,7 +3714,11 @@ void EncGOP::compressGOP( int iPOCLast, int iNumPicRcvd, PicList& rcListPic, if (pcSlice->getSPS()->getALFEnabledFlag() && (pcSlice->getAlfEnabledFlag(COMPONENT_Y) || pcSlice->getCcAlfCbEnabledFlag() || pcSlice->getCcAlfCrEnabledFlag())) { +#if JVET_X0143_ALF_APS_CHANGES + for (int apsId = 0; apsId < m_pcCfg->getMaxNumALFAPS(); apsId++) +#else for (int apsId = 0; apsId < ALF_CTB_MAX_NUM_APS; apsId++) +#endif { ParameterSetMap<APS> *apsMap = m_pcEncLib->getApsMap(); diff --git a/source/Lib/EncoderLib/VLCWriter.cpp b/source/Lib/EncoderLib/VLCWriter.cpp index c431ef9ce618ba5b072a3e784d7f99d770f59912..c09ad730389b4870099ca085dac8605371abffff 100644 --- a/source/Lib/EncoderLib/VLCWriter.cpp +++ b/source/Lib/EncoderLib/VLCWriter.cpp @@ -501,6 +501,13 @@ void HLSWriter::codeAPS( APS* pcAPS ) #endif WRITE_CODE((int)pcAPS->getAPSType(), 3, "aps_params_type"); +#if JVET_X0143_ALF_APS_ID_OFFSET + if (pcAPS->getAPSType() == ALF_APS) + { + WRITE_CODE((pcAPS->getAPSId() + JVET_X0143_ALF_APS_ID_OFFSET ) % 8, 5, "adaptation_parameter_set_id"); + } + else +#endif WRITE_CODE(pcAPS->getAPSId(), 5, "adaptation_parameter_set_id"); WRITE_FLAG(pcAPS->chromaPresentFlag, "aps_chroma_present_flag"); @@ -2252,7 +2259,11 @@ void HLSWriter::codeSliceHeader ( Slice* pcSlice, PicHeader *picHeader ) const std::vector<int>& apsId = pcSlice->getAlfApsIdsLuma(); for (int i = 0; i < pcSlice->getNumAlfApsIdsLuma(); i++) { +#if JVET_X0143_ALF_APS_ID_OFFSET + WRITE_CODE((apsId[i] + JVET_X0143_ALF_APS_ID_OFFSET ) % 8, 3, "sh_alf_aps_id_luma[i]"); +#else WRITE_CODE(apsId[i], 3, "sh_alf_aps_id_luma[i]"); +#endif } const int alfChromaIdc = pcSlice->getAlfEnabledFlag(COMPONENT_Cb) + pcSlice->getAlfEnabledFlag(COMPONENT_Cr) * 2; @@ -2263,7 +2274,11 @@ void HLSWriter::codeSliceHeader ( Slice* pcSlice, PicHeader *picHeader ) } if (alfChromaIdc) { +#if JVET_X0143_ALF_APS_ID_OFFSET + WRITE_CODE((pcSlice->getAlfApsIdChroma() + JVET_X0143_ALF_APS_ID_OFFSET ) % 8, 3, "sh_alf_aps_id_chroma"); +#else WRITE_CODE(pcSlice->getAlfApsIdChroma(), 3, "sh_alf_aps_id_chroma"); +#endif } if (pcSlice->getSPS()->getCCALFEnabledFlag()) @@ -2273,14 +2288,22 @@ void HLSWriter::codeSliceHeader ( Slice* pcSlice, PicHeader *picHeader ) if (filterParam.ccAlfFilterEnabled[COMPONENT_Cb - 1]) { // write CC ALF Cb APS ID +#if JVET_X0143_ALF_APS_ID_OFFSET + WRITE_CODE((pcSlice->getCcAlfCbApsId() + JVET_X0143_ALF_APS_ID_OFFSET ) % 8, 3, "sh_alf_cc_cb_aps_id"); +#else WRITE_CODE(pcSlice->getCcAlfCbApsId(), 3, "sh_alf_cc_cb_aps_id"); +#endif } // Cr WRITE_FLAG(filterParam.ccAlfFilterEnabled[COMPONENT_Cr - 1] ? 1 : 0, "sh_alf_cc_cr_enabled_flag"); if (filterParam.ccAlfFilterEnabled[COMPONENT_Cr - 1]) { // write CC ALF Cr APS ID +#if JVET_X0143_ALF_APS_ID_OFFSET + WRITE_CODE((pcSlice->getCcAlfCrApsId() + JVET_X0143_ALF_APS_ID_OFFSET ) % 8, 3, "sh_alf_cc_cr_aps_id"); +#else WRITE_CODE(pcSlice->getCcAlfCrApsId(), 3, "sh_alf_cc_cr_aps_id"); +#endif } } }