From 9a204b2d9648e0cd05899ec22b42bdc3cedb105c Mon Sep 17 00:00:00 2001
From: KyungYong Kim <kyungyong.kim@wilusgroup.com>
Date: Wed, 6 Nov 2024 11:46:13 +0900
Subject: [PATCH 1/5] JVET-AJ0057: High-level intra tool control

---
 cfg/per-class/classF.cfg                 |   3 +-
 source/App/EncoderApp/EncApp.cpp         |   4 +-
 source/App/EncoderApp/EncAppCfg.cpp      |   6 +
 source/App/EncoderApp/EncAppCfg.h        |   4 +-
 source/Lib/CommonLib/IntraPrediction.cpp | 195 +++++++++++++++++++++--
 source/Lib/CommonLib/IntraPrediction.h   |  24 ++-
 source/Lib/CommonLib/Slice.cpp           |   5 +
 source/Lib/CommonLib/Slice.h             |  14 +-
 source/Lib/CommonLib/TypeDef.h           |   1 +
 source/Lib/DecoderLib/VLCReader.cpp      |   6 +
 source/Lib/EncoderLib/EncCfg.h           |   9 +-
 source/Lib/EncoderLib/EncLib.cpp         |   5 +
 source/Lib/EncoderLib/EncSlice.cpp       |  29 ++++
 source/Lib/EncoderLib/VLCWriter.cpp      |   5 +
 14 files changed, 289 insertions(+), 21 deletions(-)

diff --git a/cfg/per-class/classF.cfg b/cfg/per-class/classF.cfg
index e69df5c49..6d55b9bda 100644
--- a/cfg/per-class/classF.cfg
+++ b/cfg/per-class/classF.cfg
@@ -20,4 +20,5 @@ IBCNonAdjCand:      1
 IBCFilter:       1
 ItmpLicExtension:   1
 InterSliceSeparateTree:   0
-GeoInterIbc:     1
\ No newline at end of file
+GeoInterIbc:     1
+IntraToolControlMode:     2
diff --git a/source/App/EncoderApp/EncApp.cpp b/source/App/EncoderApp/EncApp.cpp
index d08941ec2..bdf45da33 100644
--- a/source/App/EncoderApp/EncApp.cpp
+++ b/source/App/EncoderApp/EncApp.cpp
@@ -1068,7 +1068,9 @@ void EncApp::xInitLibCfg()
   m_cEncLib.setTMIbc(m_tmibc);
   m_cEncLib.setIbcMerge                                          ( m_ibcMerge );
 #endif
-
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
+  m_cEncLib.setIntraToolControlMode                              ( m_intraToolControlMode );
+#endif
   m_cEncLib.setUseWrapAround                                     ( m_wrapAround );
   m_cEncLib.setWrapAroundOffset                                  ( m_wrapAroundOffset );
 #if JVET_V0130_INTRA_TMP
diff --git a/source/App/EncoderApp/EncAppCfg.cpp b/source/App/EncoderApp/EncAppCfg.cpp
index 46ed46f41..a3c911206 100644
--- a/source/App/EncoderApp/EncAppCfg.cpp
+++ b/source/App/EncoderApp/EncAppCfg.cpp
@@ -1305,6 +1305,9 @@ bool EncAppCfg::parseCfg( int argc, char* argv[] )
 
 #if JVET_AG0136_INTRA_TMP_LIC
   ("ItmpLicExtension",                                m_itmpLicExtension,                               false, "extended Itmp LIC(0:off, 1:on)  [default: off]" )
+#endif
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
+  ("IntraToolControlMode",                            m_intraToolControlMode,                               1, "Control of Intra tools related to reference Filtering, PDPC, and intra prediction fusion (0:tool off, 1:tool on, 2:decision by alogithm whether to signal 0 or 1 in SPS)  [default: 1]")
 #endif
   ("WrapAround",                                      m_wrapAround,                                     false, "Enable horizontal wrap-around motion compensation for inter prediction (0:off, 1:on)  [default: off]")
   ("WrapAroundOffset",                                m_wrapAroundOffset,                                  0u, "Offset in luma samples used for computing the horizontal wrap-around position")
@@ -5748,6 +5751,9 @@ void EncAppCfg::xPrintParameter()
 #if JVET_AG0136_INTRA_TMP_LIC
   msg( VERBOSE, "TmpLicExtension:%d ", m_itmpLicExtension );
   msg( VERBOSE, "TmpLicMode:%d ", m_itmpLicMode );
+#endif
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
+  msg(VERBOSE, "IntraToolControlMode:%d ", m_intraToolControlMode);
 #endif
   msg( VERBOSE, "HashME:%d ", m_HashME );
   msg( VERBOSE, "WrapAround:%d ", m_wrapAround);
diff --git a/source/App/EncoderApp/EncAppCfg.h b/source/App/EncoderApp/EncAppCfg.h
index ce2c501cf..4387376b3 100644
--- a/source/App/EncoderApp/EncAppCfg.h
+++ b/source/App/EncoderApp/EncAppCfg.h
@@ -620,7 +620,9 @@ protected:
   bool      m_itmpLicExtension;
   bool      m_itmpLicMode;
 #endif
-
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
+  int       m_intraToolControlMode;
+#endif
 #if JVET_AD0208_IBC_ADAPT_FOR_CAM_CAPTURED_CONTENTS
   bool      m_rribc;
   bool      m_tmibc;
diff --git a/source/Lib/CommonLib/IntraPrediction.cpp b/source/Lib/CommonLib/IntraPrediction.cpp
index d4e4c4d13..d421383cc 100644
--- a/source/Lib/CommonLib/IntraPrediction.cpp
+++ b/source/Lib/CommonLib/IntraPrediction.cpp
@@ -1543,7 +1543,11 @@ void IntraPrediction::predIntraAng( const ComponentID compId, PelBuf &piPred, co
         weightMode = 4;
       }
 #endif
-      xPredIntraAng(srcBuf, piPred, channelType, clpRng, bExtIntraDir, srcBuf2nd, pu.cu->ispMode != NOT_INTRA_SUBPARTITIONS, weightMode);
+      xPredIntraAng(
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
+        pu,
+#endif
+        srcBuf, piPred, channelType, clpRng, bExtIntraDir, srcBuf2nd, pu.cu->ispMode != NOT_INTRA_SUBPARTITIONS, weightMode);
         break;
 #else
     default:          xPredIntraAng(srcBuf, piPred, channelType, clpRng, bExtIntraDir); break;
@@ -1668,9 +1672,17 @@ void IntraPrediction::predIntraAng( const ComponentID compId, PelBuf &piPred, co
         else
 #endif
 #if JVET_W0123_TIMD_FUSION
-        xPredIntraAng(srcBuf, predAngExtra[i], channelType, clpRng, false, srcBuf2nd, pu.cu->ispMode!=NOT_INTRA_SUBPARTITIONS);
+        xPredIntraAng(
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
+          pu,
+#endif
+          srcBuf, predAngExtra[i], channelType, clpRng, false, srcBuf2nd, pu.cu->ispMode!=NOT_INTRA_SUBPARTITIONS);
 #else
-        xPredIntraAng(srcBuf, predAngExtra[i], channelType, clpRng);
+        xPredIntraAng(
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
+          pu,
+#endif
+          srcBuf, predAngExtra[i], channelType, clpRng);
 #endif
       }
     }
@@ -2095,9 +2107,17 @@ void IntraPrediction::predIntraAng( const ComponentID compId, PelBuf &piPred, co
 #endif
           case(DC_IDX):     xPredIntraDc(srcBuf, predFusion[i], channelType, false); break;
 #if JVET_AB0157_INTRA_FUSION
-          default:          xPredIntraAng(srcBuf, predFusion[i], channelType, clpRng, false, srcBuf2nd, pu.cu->ispMode!=NOT_INTRA_SUBPARTITIONS); break;
+          default:          xPredIntraAng(
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
+            pu,
+#endif
+            srcBuf, predFusion[i], channelType, clpRng, false, srcBuf2nd, pu.cu->ispMode!=NOT_INTRA_SUBPARTITIONS); break;
 #else
-          default:          xPredIntraAng(srcBuf, predFusion[i], channelType, clpRng, bExtIntraDir); break;
+          default:          xPredIntraAng(
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
+            pu,
+#endif
+            srcBuf, predFusion[i], channelType, clpRng, bExtIntraDir); break;
 #endif
         }
 
@@ -2218,9 +2238,17 @@ void IntraPrediction::predIntraAng( const ComponentID compId, PelBuf &piPred, co
 #endif
     case(DC_IDX):     xPredIntraDc(srcBuf3rd, predFusion, channelType, false); break;
 #if JVET_AB0157_INTRA_FUSION
-    default:          xPredIntraAng(srcBuf3rd, predFusion, channelType, clpRng, bExtIntraDir, srcBuf2nd, pu.cu->ispMode!=NOT_INTRA_SUBPARTITIONS, 0); break;
+    default:          xPredIntraAng(
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
+      pu,
+#endif
+      srcBuf3rd, predFusion, channelType, clpRng, bExtIntraDir, srcBuf2nd, pu.cu->ispMode!=NOT_INTRA_SUBPARTITIONS, 0); break;
 #else
-    default:          xPredIntraAng(srcBuf3rd, predFusion, channelType, clpRng, bExtIntraDir); break;
+    default:          xPredIntraAng(
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
+      pu,
+#endif
+      srcBuf3rd, predFusion, channelType, clpRng, bExtIntraDir); break;
 #endif
     }
 
@@ -2513,9 +2541,17 @@ void IntraPrediction::predIntraAng( const ComponentID compId, PelBuf &piPred, co
 #if JVET_AB0157_INTRA_FUSION
     default:
        int weightMode = 4;
-      xPredIntraAng(srcBuf2, predFusion, channelType, clpRng, bExtIntraDir, srcBuf2nd, pu.cu->ispMode!=NOT_INTRA_SUBPARTITIONS, weightMode); break;
+      xPredIntraAng(
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
+        pu,
+#endif
+        srcBuf2, predFusion, channelType, clpRng, bExtIntraDir, srcBuf2nd, pu.cu->ispMode!=NOT_INTRA_SUBPARTITIONS, weightMode); break;
 #else
-    default: xPredIntraAng(srcBuf2, predFusion, channelType, clpRng, bExtIntraDir); break;
+    default: xPredIntraAng(
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
+      pu,
+#endif
+      srcBuf2, predFusion, channelType, clpRng, bExtIntraDir); break;
 #endif
     }
 
@@ -3667,6 +3703,14 @@ void IntraPrediction::initPredIntraParams(const PredictionUnit & pu, const CompA
     m_ipaParam.useGradPDPC &= (m_intraOBMCNeighState == INTRA_OBMC_BOTH_NEIGH_AVAIL);
   }
 #endif
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
+  if (pu.cu->cs->sps->getDisablePdpc())
+  {
+    m_ipaParam.applyPDPC = false;
+    m_ipaParam.useGradPDPC = false;
+  }
+#endif
+
   // high level conditions and DC intra prediction
   if(   sps.getSpsRangeExtension().getIntraSmoothingDisabledFlag()
     || !isLuma( chType )
@@ -3775,6 +3819,13 @@ void IntraPrediction::initPredIntraParams(const PredictionUnit & pu, const CompA
 #if JVET_AG0128_REF_LINE_OPT_TIMD_FUSION
   }
 #endif
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
+  if (pu.cu->cs->sps->getDisableIntraFusion())
+  {
+    m_ipaParam.fetchRef2nd = false;
+    m_ipaParam.applyFusion = false;
+  }
+#endif
 #endif
 }
 
@@ -3793,12 +3844,24 @@ void IntraPrediction::initPredIntraParams(const PredictionUnit & pu, const CompA
 
 #if JVET_W0123_TIMD_FUSION
 #if JVET_AB0157_INTRA_FUSION
-void IntraPrediction::xPredIntraAng( const CPelBuf &pSrc, PelBuf &pDst, const ChannelType channelType, const ClpRng& clpRng, const bool bExtIntraDir, const CPelBuf &pSrc2nd, bool isISP, int weightMode)
+void IntraPrediction::xPredIntraAng(
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
+  const PredictionUnit& pu,
+#endif
+  const CPelBuf &pSrc, PelBuf &pDst, const ChannelType channelType, const ClpRng& clpRng, const bool bExtIntraDir, const CPelBuf &pSrc2nd, bool isISP, int weightMode)
 #else
-void IntraPrediction::xPredIntraAng( const CPelBuf &pSrc, PelBuf &pDst, const ChannelType channelType, const ClpRng& clpRng, const bool bExtIntraDir)
+void IntraPrediction::xPredIntraAng(
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
+  const PredictionUnit& pu,
+#endif
+  const CPelBuf &pSrc, PelBuf &pDst, const ChannelType channelType, const ClpRng& clpRng, const bool bExtIntraDir)
 #endif
 #else
-void IntraPrediction::xPredIntraAng( const CPelBuf &pSrc, PelBuf &pDst, const ChannelType channelType, const ClpRng& clpRng)
+void IntraPrediction::xPredIntraAng(
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
+  const PredictionUnit& pu,
+#endif
+  const CPelBuf &pSrc, PelBuf &pDst, const ChannelType channelType, const ClpRng& clpRng)
 #endif
 {
   int width =int(pDst.width);
@@ -3904,6 +3967,26 @@ void IntraPrediction::xPredIntraAng( const CPelBuf &pSrc, PelBuf &pDst, const Ch
       int frac32precision = (-k * absInvAngle + 8) >> 4;
       int intpel = frac32precision >> 5;
       int fracpel = frac32precision & 31;
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
+      if (pu.cu->cs->sps->getDisableRefFilter())
+      {
+        int left = refSide[Clip3(0, sizeSide + 2 + multiRefIdx, intpel)];
+        int right = refSide[Clip3(0, sizeSide + 2 + multiRefIdx, intpel + 1)];
+        refMain[k] = (Pel)(fracpel > 15 ? right : left);
+      }
+      else
+      {
+        //std::cout << " fracPel: " << fracpel << std::endl;
+        int left_minus1 = refSide[Clip3(0, sizeSide + 2 + multiRefIdx, intpel - 1)];
+        int left = refSide[Clip3(0, sizeSide + 2 + multiRefIdx, intpel)];
+        int right = refSide[Clip3(0, sizeSide + 2 + multiRefIdx, intpel + 1)];
+        int right_plus1 = refSide[Clip3(0, sizeSide + 2 + multiRefIdx, intpel + 2)];
+
+        const TFilterCoeff* f = InterpolationFilter::getWeak4TapFilterTable(fracpel);
+        int val = ((int)f[0] * left_minus1 + (int)f[1] * left + (int)f[2] * right + f[3] * (int)right_plus1 + 32) >> 6;
+        refMain[k] = (Pel)ClipPel(val, clpRng);
+      }
+#else
       //std::cout << " fracPel: " << fracpel << std::endl;
       int left_minus1 = refSide[Clip3(0, sizeSide + 2 + multiRefIdx, intpel - 1)];
       int left        = refSide[Clip3(0, sizeSide + 2 + multiRefIdx, intpel)];
@@ -3913,6 +3996,7 @@ void IntraPrediction::xPredIntraAng( const CPelBuf &pSrc, PelBuf &pDst, const Ch
       const TFilterCoeff* f = InterpolationFilter::getWeak4TapFilterTable(fracpel);
       int val = ((int)f[0] * left_minus1 + (int)f[1] * left + (int)f[2] * right + f[3] * (int)right_plus1 + 32) >> 6;
       refMain[k] = (Pel)ClipPel(val, clpRng);
+#endif
     }
 #else
     for (int x = 0; x <= width + 1 + multiRefIdx; x++)
@@ -4027,6 +4111,27 @@ void IntraPrediction::xPredIntraAng( const CPelBuf &pSrc, PelBuf &pDst, const Ch
         int frac32precision = (-k * absInvAngle + 8) >> 4;
         int intpel          = frac32precision >> 5;
         int fracpel         = frac32precision & 31;
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
+        if (pu.cu->cs->sps->getDisableRefFilter())
+        {
+          int left = refSide2nd[Clip3(0, sizeSideRange, intpel)];
+          int right = refSide2nd[Clip3(0, sizeSideRange, intpel + 1)];
+          refMain2nd[k] = (Pel)(fracpel > 15 ? right : left);
+        }
+        else
+        {
+          // std::cout << " fracPel: " << fracpel << std::endl;
+          int leftMinus1 = refSide2nd[Clip3(0, sizeSideRange, intpel - 1)];
+          int left = refSide2nd[Clip3(0, sizeSideRange, intpel)];
+          int right = refSide2nd[Clip3(0, sizeSideRange, intpel + 1)];
+          int rightPlus1 = refSide2nd[Clip3(0, sizeSideRange, intpel + 2)];
+
+          const TFilterCoeff* f = InterpolationFilter::getWeak4TapFilterTable(fracpel);
+          int                 val =
+            ((int)f[0] * leftMinus1 + (int)f[1] * left + (int)f[2] * right + f[3] * (int)rightPlus1 + 32) >> 6;
+          refMain2nd[k] = (Pel)ClipPel(val, clpRng);
+        }
+#else
         // std::cout << " fracPel: " << fracpel << std::endl;
         int leftMinus1  = refSide2nd[Clip3(0, sizeSideRange, intpel - 1)];
         int left        = refSide2nd[Clip3(0, sizeSideRange, intpel)];
@@ -4037,6 +4142,7 @@ void IntraPrediction::xPredIntraAng( const CPelBuf &pSrc, PelBuf &pDst, const Ch
         int                 val =
           ((int) f[0] * leftMinus1 + (int) f[1] * left + (int) f[2] * right + f[3] * (int) rightPlus1 + 32) >> 6;
         refMain2nd[k] = (Pel) ClipPel(val, clpRng);
+#endif
       }
     }
     else
@@ -5479,6 +5585,21 @@ void IntraPrediction::initIntraPatternChType(const CodingUnit &cu, const CompAre
   }
 #endif
   // ----- Step 2: filtered reference samples -----
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
+  if (cu.cs->sps->getDisableRefFilter())
+  {
+    m_ipaParam.refFilterFlag = false;
+    xCopyReferenceSamples(refBufUnfiltered, refBufFiltered, area, *cs.sps, cu.firstPU->multiRefIdx);
+  }
+  else if (m_ipaParam.refFilterFlag || forceRefFilterFlag
+#if JVET_AG0092_ENHANCED_TIMD_FUSION
+    || cu.timd
+#endif
+    )
+  {
+    xFilterReferenceSamples(refBufUnfiltered, refBufFiltered, area, *cs.sps, cu.firstPU->multiRefIdx);
+  }
+#else
   if( m_ipaParam.refFilterFlag || forceRefFilterFlag 
 #if JVET_AG0092_ENHANCED_TIMD_FUSION 
    || cu.timd
@@ -5487,6 +5608,7 @@ void IntraPrediction::initIntraPatternChType(const CodingUnit &cu, const CompAre
   {
     xFilterReferenceSamples( refBufUnfiltered, refBufFiltered, area, *cs.sps, cu.firstPU->multiRefIdx );
   }
+#endif
 }
 
 #if JVET_AJ0161_OBMC_EXT_WITH_INTRA_PRED
@@ -5630,12 +5752,28 @@ void IntraPrediction::initIntraPatternChTypeISP(const CodingUnit& cu, const Comp
     }
   }
   // ----- Step 2: filtered reference samples -----
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
+  if (cu.cs->sps->getDisableRefFilter())
+  {
+    m_ipaParam.refFilterFlag = false;
+    Pel* refBufUnfiltered = m_refBuffer[area.compID][PRED_BUF_UNFILTERED];
+    Pel* refBufFiltered = m_refBuffer[area.compID][PRED_BUF_FILTERED];
+    xCopyReferenceSamples(refBufUnfiltered, refBufFiltered, area, *cs.sps, cu.firstPU->multiRefIdx);
+  }
+  else if (m_ipaParam.refFilterFlag || forceRefFilterFlag)
+  {
+    Pel* refBufUnfiltered = m_refBuffer[area.compID][PRED_BUF_UNFILTERED];
+    Pel* refBufFiltered = m_refBuffer[area.compID][PRED_BUF_FILTERED];
+    xFilterReferenceSamples(refBufUnfiltered, refBufFiltered, area, *cs.sps, cu.firstPU->multiRefIdx);
+  }
+#else
   if (m_ipaParam.refFilterFlag || forceRefFilterFlag)
   {
     Pel *refBufUnfiltered = m_refBuffer[area.compID][PRED_BUF_UNFILTERED];
     Pel *refBufFiltered   = m_refBuffer[area.compID][PRED_BUF_FILTERED];
     xFilterReferenceSamples(refBufUnfiltered, refBufFiltered, area, *cs.sps, cu.firstPU->multiRefIdx);
   }
+#endif
 }
 
 #if JVET_V0130_INTRA_TMP
@@ -7079,6 +7217,32 @@ void IntraPrediction::xFillReferenceSamplesForCoLuma(const CPelBuf &recoBuf, Pel
 }
 #endif
 
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
+void IntraPrediction::xCopyReferenceSamples(const Pel* refBufUnfiltered, Pel* refBufFiltered, const CompArea& area, const SPS& sps,
+  int multiRefIdx
+)
+{
+  if (area.compID != COMPONENT_Y)
+  {
+    multiRefIdx = 0;
+  }
+  const int predSize = m_topRefLength + multiRefIdx;
+  const int predHSize = m_leftRefLength + multiRefIdx;
+  const size_t predStride = m_refBufferStride[area.compID];
+
+  for (int i = 0; i < predSize; i++)
+  {
+    refBufFiltered[i] = refBufUnfiltered[i];
+  }
+  refBufFiltered += predStride;
+  refBufUnfiltered += predStride;
+  for (int i = 0; i < predHSize; i++)
+  {
+    refBufFiltered[i] = refBufUnfiltered[i];
+  }
+}
+#endif
+
 void IntraPrediction::xFilterReferenceSamples(const Pel *refBufUnfiltered, Pel *refBufFiltered, const CompArea &area,
                                               const SPS &sps, int multiRefIdx)
 {
@@ -7576,6 +7740,13 @@ void IntraPrediction::initPredTimdIntraParams(const PredictionUnit & pu, const C
       m_ipaParam.applyPDPC &= m_ipaParam.angularScale >= 0;
     }
   }
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
+  if (pu.cu->cs->sps->getDisablePdpc())
+  {
+    m_ipaParam.applyPDPC = false;
+    m_ipaParam.useGradPDPC = false;
+  }
+#endif
 }
 
 void IntraPrediction::xPredTimdIntraAng( const CPelBuf &pSrc, const ClpRng& clpRng, Pel* pTrueDst, int iDstStride, int iWidth, int iHeight, TemplateType eTempType, int iTemplateWidth , int iTemplateHeight, uint32_t dirMode
diff --git a/source/Lib/CommonLib/IntraPrediction.h b/source/Lib/CommonLib/IntraPrediction.h
index d702673e5..d07a56348 100644
--- a/source/Lib/CommonLib/IntraPrediction.h
+++ b/source/Lib/CommonLib/IntraPrediction.h
@@ -540,12 +540,24 @@ protected:
   void xPredIntraDc               ( const CPelBuf &pSrc, PelBuf &pDst, const ChannelType channelType, const bool enableBoundaryFilter = true );
 #if JVET_W0123_TIMD_FUSION
 #if JVET_AB0157_INTRA_FUSION
-  void xPredIntraAng              ( const CPelBuf &pSrc, PelBuf &pDst, const ChannelType channelType, const ClpRng& clpRng, const bool bExtIntraDir, const CPelBuf &pSrc2nd, bool isISP = true, int weightMode = 4);
+  void xPredIntraAng              (
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
+    const PredictionUnit& pu,
+#endif
+    const CPelBuf &pSrc, PelBuf &pDst, const ChannelType channelType, const ClpRng& clpRng, const bool bExtIntraDir, const CPelBuf &pSrc2nd, bool isISP = true, int weightMode = 4);
 #else
-  void xPredIntraAng              ( const CPelBuf &pSrc, PelBuf &pDst, const ChannelType channelType, const ClpRng& clpRng, const bool bExtIntraDir);
+  void xPredIntraAng              (
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
+    const PredictionUnit& pu,
+#endif
+    const CPelBuf &pSrc, PelBuf &pDst, const ChannelType channelType, const ClpRng& clpRng, const bool bExtIntraDir);
 #endif
 #else
-  void xPredIntraAng              ( const CPelBuf &pSrc, PelBuf &pDst, const ChannelType channelType, const ClpRng& clpRng);
+  void xPredIntraAng              (
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
+    const PredictionUnit& pu,
+#endif
+    const CPelBuf &pSrc, PelBuf &pDst, const ChannelType channelType, const ClpRng& clpRng);
 #endif
 #if !(JVET_AC0112_IBC_CIIP || JVET_AC0112_IBC_GPM)
 #if JVET_AB0155_SGPM
@@ -580,6 +592,12 @@ protected:
                                int multiRefIdx
   );
 
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
+  void xCopyReferenceSamples(const Pel* refBufUnfiltered, Pel* refBufFiltered, const CompArea& area, const SPS& sps,
+    int multiRefIdx
+  );
+#endif
+
   static int getModifiedWideAngle         ( int width, int height, int predMode );
 #if JVET_W0123_TIMD_FUSION
 #if JVET_AB0155_SGPM
diff --git a/source/Lib/CommonLib/Slice.cpp b/source/Lib/CommonLib/Slice.cpp
index 3cb175e86..cf196c89b 100644
--- a/source/Lib/CommonLib/Slice.cpp
+++ b/source/Lib/CommonLib/Slice.cpp
@@ -4144,6 +4144,11 @@ SPS::SPS()
   , m_itmpLicExtension        ( false )
   , m_itmpLicMode             ( false )
 #endif
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
+  , m_disableRefFilter        ( false )
+  , m_disablePdpc             ( false )
+  , m_disableIntraFusion      ( false )
+#endif
 #if TM_AMVP || TM_MRG || JVET_Z0084_IBC_TM || MULTI_PASS_DMVR
  , m_DMVDMode                 ( false )
 #endif
diff --git a/source/Lib/CommonLib/Slice.h b/source/Lib/CommonLib/Slice.h
index 9e017aec4..d15711086 100644
--- a/source/Lib/CommonLib/Slice.h
+++ b/source/Lib/CommonLib/Slice.h
@@ -1579,6 +1579,11 @@ private:
   bool              m_itmpLicExtension;
   bool              m_itmpLicMode;
 #endif
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
+  bool              m_disableRefFilter;
+  bool              m_disablePdpc;
+  bool              m_disableIntraFusion;
+#endif
 #if TM_AMVP || TM_MRG || JVET_Z0084_IBC_TM || MULTI_PASS_DMVR
   bool              m_DMVDMode;
 #endif
@@ -2301,7 +2306,14 @@ void                    setCCALFEnabledFlag( bool b )
   void                    setItmpLicMode(bool b)                                                     { m_itmpLicMode = b; }
   bool                    getItmpLicMode() const                                                     { return m_itmpLicMode; }
 #endif
-
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
+  void                    setDisableRefFilter(bool b)                                                     { m_disableRefFilter = b; }
+  bool                    getDisableRefFilter() const                                                     { return m_disableRefFilter; }
+  void                    setDisablePdpc(bool b)                                                          { m_disablePdpc = b; }
+  bool                    getDisablePdpc() const                                                          { return m_disablePdpc; }
+  void                    setDisableIntraFusion(bool b)                                                   { m_disableIntraFusion = b; }
+  bool                    getDisableIntraFusion() const                                                   { return m_disableIntraFusion; }
+#endif
 #if TM_AMVP || TM_MRG || JVET_Z0084_IBC_TM || MULTI_PASS_DMVR
   void                    setUseDMVDMode(bool b)                                                          { m_DMVDMode = b; }
   bool                    getUseDMVDMode() const                                                          { return m_DMVDMode; }
diff --git a/source/Lib/CommonLib/TypeDef.h b/source/Lib/CommonLib/TypeDef.h
index dd2bbe4da..923108988 100644
--- a/source/Lib/CommonLib/TypeDef.h
+++ b/source/Lib/CommonLib/TypeDef.h
@@ -220,6 +220,7 @@
 #define JVET_AI0208_PDP_MIP                               1 // JVET_AI0208: Modifications to Matrix-based intra prediction
 #endif
 #define JVET_AI0136_ADAPTIVE_DUAL_TREE                    1 // JVET-AI0136: Adaptive dual tree in inter slices
+#define JVET_AJ0057_HL_INTRA_METHOD_CONTROL               1 // JVET-AJ0057: High-level control of intra prediction methods
 
 //IBC
 #define JVET_Y0058_IBC_LIST_MODIFY                        1 // JVET-Y0058: Modifications of IBC merge/AMVP list construction, ARMC-TM-IBC part is included under JVET_W0090_ARMC_TM
diff --git a/source/Lib/DecoderLib/VLCReader.cpp b/source/Lib/DecoderLib/VLCReader.cpp
index 285e85691..f6252d9c2 100644
--- a/source/Lib/DecoderLib/VLCReader.cpp
+++ b/source/Lib/DecoderLib/VLCReader.cpp
@@ -2963,6 +2963,12 @@ void HLSyntaxReader::parseSPS(SPS* pcSPS)
   READ_FLAG( uiCode, "sps_itmp_lic_mode_flag" );                              pcSPS->setItmpLicMode ( uiCode != 0 );
 #endif
 
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
+  READ_FLAG(uiCode, "sps_ref_filter_disabled_flag");                    pcSPS->setDisableRefFilter(uiCode != 0);
+  READ_FLAG(uiCode, "sps_pdpc_disabled_flag");                          pcSPS->setDisablePdpc(uiCode != 0);
+  READ_FLAG(uiCode, "sps_intra_fusion_disabled_flag");                  pcSPS->setDisableIntraFusion(uiCode != 0);
+#endif
+
 #if !JVET_S0074_SPS_REORDER
   READ_FLAG(uiCode, "sps_lmcs_enable_flag");                   pcSPS->setUseLmcs(uiCode == 1);
   READ_FLAG( uiCode, "sps_lfnst_enabled_flag" );                    pcSPS->setUseLFNST( uiCode != 0 );
diff --git a/source/Lib/EncoderLib/EncCfg.h b/source/Lib/EncoderLib/EncCfg.h
index a399a22ad..f5b41cb09 100644
--- a/source/Lib/EncoderLib/EncCfg.h
+++ b/source/Lib/EncoderLib/EncCfg.h
@@ -628,7 +628,9 @@ protected:
   bool      m_itmpLicExtension;
   bool      m_itmpLicMode;
 #endif
-
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
+  int       m_intraToolControlMode;
+#endif
   bool      m_wrapAround;
   unsigned  m_wrapAroundOffset;
 #if JVET_AH0135_TEMPORAL_PARTITIONING
@@ -1683,7 +1685,10 @@ public:
   void      setItmpLicMode                   ( bool b )       { m_itmpLicMode = b; }
   bool      getItmpLicMode                   ()         const { return m_itmpLicMode; }
 #endif
-
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
+  void      setIntraToolControlMode          ( int b )        { m_intraToolControlMode = b; }
+  int       getIntraToolControlMode          ()         const { return m_intraToolControlMode; }
+#endif
 #if TM_AMVP || TM_MRG || JVET_Z0084_IBC_TM || MULTI_PASS_DMVR
   void      setUseDMVDMode                  (bool b)         { m_DMVDMode = b; }
   bool      getUseDMVDMode                  ()         const { return m_DMVDMode; }
diff --git a/source/Lib/EncoderLib/EncLib.cpp b/source/Lib/EncoderLib/EncLib.cpp
index c0e572857..52650c0da 100644
--- a/source/Lib/EncoderLib/EncLib.cpp
+++ b/source/Lib/EncoderLib/EncLib.cpp
@@ -2138,6 +2138,11 @@ void EncLib::xInitSPS( SPS& sps )
 #if JVET_AG0136_INTRA_TMP_LIC
   sps.setItmpLicExtension                   ( m_itmpLicExtension );
   sps.setItmpLicMode                        ( m_itmpLicMode );
+#endif
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
+  sps.setDisableRefFilter                   ( false );
+  sps.setDisablePdpc                        ( false );
+  sps.setDisableIntraFusion                 ( false );
 #endif
   sps.setWrapAroundEnabledFlag                      ( m_wrapAround );
 #if JVET_AH0135_TEMPORAL_PARTITIONING
diff --git a/source/Lib/EncoderLib/EncSlice.cpp b/source/Lib/EncoderLib/EncSlice.cpp
index bf9b6f559..a807a7c05 100644
--- a/source/Lib/EncoderLib/EncSlice.cpp
+++ b/source/Lib/EncoderLib/EncSlice.cpp
@@ -2066,6 +2066,35 @@ void EncSlice::encodeCtus( Picture* pcPic, const bool bCompressEntireSlice, cons
   }
 #endif
 
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
+  if (m_pcCuEncoder->getEncCfg()->getIntraToolControlMode() == 0)
+  {
+    SPS* spsTmp = const_cast<SPS*>(cs.sps);
+    spsTmp->setDisableRefFilter(true);
+    spsTmp->setDisablePdpc(true);
+    spsTmp->setDisableIntraFusion(true);
+  }
+  else if (m_pcCuEncoder->getEncCfg()->getIntraToolControlMode() == 1)
+  {
+    SPS* spsTmp = const_cast<SPS*>(cs.sps);
+    spsTmp->setDisableRefFilter(false);
+    spsTmp->setDisablePdpc(false);
+    spsTmp->setDisableIntraFusion(false);
+  }
+  else if (m_pcCuEncoder->getEncCfg()->getIntraToolControlMode() == 2)
+  {
+    SPS* spsTmp = const_cast<SPS*>(cs.sps);    
+    if (cs.slice->getPOC() == 0 || cs.slice->getSliceType() == I_SLICE) // ensure sequential and parallel simulation generate same output
+    {
+      hashBlkHitPerc = (hashBlkHitPerc == -1) ? m_pcCuEncoder->getIbcHashMap().calHashBlkMatchPerc(cs.area.Y()) : hashBlkHitPerc;
+      bool isSCC = hashBlkHitPerc >= 20;
+      spsTmp->setDisableRefFilter(isSCC);
+      spsTmp->setDisablePdpc(isSCC);
+      spsTmp->setDisableIntraFusion(isSCC);
+    }
+  }  
+#endif
+
   // for every CTU in the slice
   for( uint32_t ctuIdx = 0; ctuIdx < pcSlice->getNumCtuInSlice(); ctuIdx++ )
   {
diff --git a/source/Lib/EncoderLib/VLCWriter.cpp b/source/Lib/EncoderLib/VLCWriter.cpp
index 350d72e71..89c3f215a 100644
--- a/source/Lib/EncoderLib/VLCWriter.cpp
+++ b/source/Lib/EncoderLib/VLCWriter.cpp
@@ -1947,6 +1947,11 @@ void HLSWriter::codeSPS( const SPS* pcSPS )
   WRITE_FLAG( pcSPS->getItmpLicExtension ( ) ? 1 : 0 , "sps_itmp_lic_extension_flag" );
   WRITE_FLAG( pcSPS->getItmpLicMode ( ) ? 1 : 0 , "sps_itmp_lic_mode_flag" );
 #endif
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
+  WRITE_FLAG(pcSPS->getDisableRefFilter() ? 1 : 0, "sps_ref_filter_disabled_flag");
+  WRITE_FLAG(pcSPS->getDisablePdpc() ? 1 : 0, "sps_pdpc_disabled_flag");
+  WRITE_FLAG(pcSPS->getDisableIntraFusion() ? 1 : 0, "sps_intra_fusion_disabled_flag");
+#endif
 #if !JVET_S0074_SPS_REORDER
   WRITE_FLAG(pcSPS->getUseLmcs() ? 1 : 0, "sps_lmcs_enable_flag");
 #if JVET_AH0103_LOW_DELAY_LFNST_NSPT
-- 
GitLab


From d9239948e26d02f1b1ea567be6b40ddd0ab97221 Mon Sep 17 00:00:00 2001
From: KyungYong Kim <kyungyong.kim@wilusgroup.com>
Date: Fri, 8 Nov 2024 18:24:29 +0900
Subject: [PATCH 2/5] Cleanup about JVET-AJ0057 (Test 2.14)

---
 source/Lib/CommonLib/IntraPrediction.cpp | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/source/Lib/CommonLib/IntraPrediction.cpp b/source/Lib/CommonLib/IntraPrediction.cpp
index d421383cc..b3fcb05be 100644
--- a/source/Lib/CommonLib/IntraPrediction.cpp
+++ b/source/Lib/CommonLib/IntraPrediction.cpp
@@ -1550,10 +1550,18 @@ void IntraPrediction::predIntraAng( const ComponentID compId, PelBuf &piPred, co
         srcBuf, piPred, channelType, clpRng, bExtIntraDir, srcBuf2nd, pu.cu->ispMode != NOT_INTRA_SUBPARTITIONS, weightMode);
         break;
 #else
-    default:          xPredIntraAng(srcBuf, piPred, channelType, clpRng, bExtIntraDir); break;
+    default:          xPredIntraAng(
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
+      pu,
+#endif
+      srcBuf, piPred, channelType, clpRng, bExtIntraDir); break;
 #endif
 #else
-    default:          xPredIntraAng(srcBuf, piPred, channelType, clpRng); break;
+    default:          xPredIntraAng(
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
+      pu,
+#endif
+      srcBuf, piPred, channelType, clpRng); break;
 #endif
     }
 #if CIIP_PDPC
@@ -3977,24 +3985,24 @@ void IntraPrediction::xPredIntraAng(
       else
       {
         //std::cout << " fracPel: " << fracpel << std::endl;
-        int left_minus1 = refSide[Clip3(0, sizeSide + 2 + multiRefIdx, intpel - 1)];
+        int leftMinus1 = refSide[Clip3(0, sizeSide + 2 + multiRefIdx, intpel - 1)];
         int left = refSide[Clip3(0, sizeSide + 2 + multiRefIdx, intpel)];
         int right = refSide[Clip3(0, sizeSide + 2 + multiRefIdx, intpel + 1)];
-        int right_plus1 = refSide[Clip3(0, sizeSide + 2 + multiRefIdx, intpel + 2)];
+        int rightPlus1 = refSide[Clip3(0, sizeSide + 2 + multiRefIdx, intpel + 2)];
 
         const TFilterCoeff* f = InterpolationFilter::getWeak4TapFilterTable(fracpel);
-        int val = ((int)f[0] * left_minus1 + (int)f[1] * left + (int)f[2] * right + f[3] * (int)right_plus1 + 32) >> 6;
+        int val = ((int)f[0] * leftMinus1 + (int)f[1] * left + (int)f[2] * right + f[3] * (int)rightPlus1 + 32) >> 6;
         refMain[k] = (Pel)ClipPel(val, clpRng);
       }
 #else
       //std::cout << " fracPel: " << fracpel << std::endl;
-      int left_minus1 = refSide[Clip3(0, sizeSide + 2 + multiRefIdx, intpel - 1)];
+      int leftMinus1 = refSide[Clip3(0, sizeSide + 2 + multiRefIdx, intpel - 1)];
       int left        = refSide[Clip3(0, sizeSide + 2 + multiRefIdx, intpel)];
       int right       = refSide[Clip3(0, sizeSide + 2 + multiRefIdx, intpel + 1)];
-      int right_plus1 = refSide[Clip3(0, sizeSide + 2 + multiRefIdx, intpel + 2)];
+      int rightPlus1 = refSide[Clip3(0, sizeSide + 2 + multiRefIdx, intpel + 2)];
 
       const TFilterCoeff* f = InterpolationFilter::getWeak4TapFilterTable(fracpel);
-      int val = ((int)f[0] * left_minus1 + (int)f[1] * left + (int)f[2] * right + f[3] * (int)right_plus1 + 32) >> 6;
+      int val = ((int)f[0] * leftMinus1 + (int)f[1] * left + (int)f[2] * right + f[3] * (int)rightPlus1 + 32) >> 6;
       refMain[k] = (Pel)ClipPel(val, clpRng);
 #endif
     }
-- 
GitLab


From 27a6c4291b9187862549fc7a6f840f5d9bceae2e Mon Sep 17 00:00:00 2001
From: KyungYong Kim <kyungyong.kim@wilusgroup.com>
Date: Mon, 11 Nov 2024 11:42:28 +0900
Subject: [PATCH 3/5] Additional cleanup about JVET-AJ0057 (Test 2.14)

---
 source/Lib/CommonLib/IntraPrediction.cpp | 66 +++++-------------------
 1 file changed, 13 insertions(+), 53 deletions(-)

diff --git a/source/Lib/CommonLib/IntraPrediction.cpp b/source/Lib/CommonLib/IntraPrediction.cpp
index b3fcb05be..320bfc1e2 100644
--- a/source/Lib/CommonLib/IntraPrediction.cpp
+++ b/source/Lib/CommonLib/IntraPrediction.cpp
@@ -3975,35 +3975,23 @@ void IntraPrediction::xPredIntraAng(
       int frac32precision = (-k * absInvAngle + 8) >> 4;
       int intpel = frac32precision >> 5;
       int fracpel = frac32precision & 31;
+
+      //std::cout << " fracPel: " << fracpel << std::endl;
+      int left = refSide[Clip3(0, sizeSide + 2 + multiRefIdx, intpel)];
+      int right = refSide[Clip3(0, sizeSide + 2 + multiRefIdx, intpel + 1)];
 #if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
       if (pu.cu->cs->sps->getDisableRefFilter())
       {
-        int left = refSide[Clip3(0, sizeSide + 2 + multiRefIdx, intpel)];
-        int right = refSide[Clip3(0, sizeSide + 2 + multiRefIdx, intpel + 1)];
         refMain[k] = (Pel)(fracpel > 15 ? right : left);
       }
       else
       {
-        //std::cout << " fracPel: " << fracpel << std::endl;
         int leftMinus1 = refSide[Clip3(0, sizeSide + 2 + multiRefIdx, intpel - 1)];
-        int left = refSide[Clip3(0, sizeSide + 2 + multiRefIdx, intpel)];
-        int right = refSide[Clip3(0, sizeSide + 2 + multiRefIdx, intpel + 1)];
         int rightPlus1 = refSide[Clip3(0, sizeSide + 2 + multiRefIdx, intpel + 2)];
-
         const TFilterCoeff* f = InterpolationFilter::getWeak4TapFilterTable(fracpel);
         int val = ((int)f[0] * leftMinus1 + (int)f[1] * left + (int)f[2] * right + f[3] * (int)rightPlus1 + 32) >> 6;
         refMain[k] = (Pel)ClipPel(val, clpRng);
       }
-#else
-      //std::cout << " fracPel: " << fracpel << std::endl;
-      int leftMinus1 = refSide[Clip3(0, sizeSide + 2 + multiRefIdx, intpel - 1)];
-      int left        = refSide[Clip3(0, sizeSide + 2 + multiRefIdx, intpel)];
-      int right       = refSide[Clip3(0, sizeSide + 2 + multiRefIdx, intpel + 1)];
-      int rightPlus1 = refSide[Clip3(0, sizeSide + 2 + multiRefIdx, intpel + 2)];
-
-      const TFilterCoeff* f = InterpolationFilter::getWeak4TapFilterTable(fracpel);
-      int val = ((int)f[0] * leftMinus1 + (int)f[1] * left + (int)f[2] * right + f[3] * (int)rightPlus1 + 32) >> 6;
-      refMain[k] = (Pel)ClipPel(val, clpRng);
 #endif
     }
 #else
@@ -4119,37 +4107,23 @@ void IntraPrediction::xPredIntraAng(
         int frac32precision = (-k * absInvAngle + 8) >> 4;
         int intpel          = frac32precision >> 5;
         int fracpel         = frac32precision & 31;
+
+        // std::cout << " fracPel: " << fracpel << std::endl;        
+        int left        = refSide2nd[Clip3(0, sizeSideRange, intpel)];
+        int right       = refSide2nd[Clip3(0, sizeSideRange, intpel + 1)];
 #if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
         if (pu.cu->cs->sps->getDisableRefFilter())
         {
-          int left = refSide2nd[Clip3(0, sizeSideRange, intpel)];
-          int right = refSide2nd[Clip3(0, sizeSideRange, intpel + 1)];
           refMain2nd[k] = (Pel)(fracpel > 15 ? right : left);
         }
         else
         {
-          // std::cout << " fracPel: " << fracpel << std::endl;
           int leftMinus1 = refSide2nd[Clip3(0, sizeSideRange, intpel - 1)];
-          int left = refSide2nd[Clip3(0, sizeSideRange, intpel)];
-          int right = refSide2nd[Clip3(0, sizeSideRange, intpel + 1)];
           int rightPlus1 = refSide2nd[Clip3(0, sizeSideRange, intpel + 2)];
-
           const TFilterCoeff* f = InterpolationFilter::getWeak4TapFilterTable(fracpel);
-          int                 val =
-            ((int)f[0] * leftMinus1 + (int)f[1] * left + (int)f[2] * right + f[3] * (int)rightPlus1 + 32) >> 6;
+          int val = ((int)f[0] * leftMinus1 + (int)f[1] * left + (int)f[2] * right + f[3] * (int)rightPlus1 + 32) >> 6;
           refMain2nd[k] = (Pel)ClipPel(val, clpRng);
         }
-#else
-        // std::cout << " fracPel: " << fracpel << std::endl;
-        int leftMinus1  = refSide2nd[Clip3(0, sizeSideRange, intpel - 1)];
-        int left        = refSide2nd[Clip3(0, sizeSideRange, intpel)];
-        int right       = refSide2nd[Clip3(0, sizeSideRange, intpel + 1)];
-        int rightPlus1  = refSide2nd[Clip3(0, sizeSideRange, intpel + 2)];
-
-        const TFilterCoeff *f = InterpolationFilter::getWeak4TapFilterTable(fracpel);
-        int                 val =
-          ((int) f[0] * leftMinus1 + (int) f[1] * left + (int) f[2] * right + f[3] * (int) rightPlus1 + 32) >> 6;
-        refMain2nd[k] = (Pel) ClipPel(val, clpRng);
 #endif
       }
     }
@@ -5599,24 +5573,16 @@ void IntraPrediction::initIntraPatternChType(const CodingUnit &cu, const CompAre
     m_ipaParam.refFilterFlag = false;
     xCopyReferenceSamples(refBufUnfiltered, refBufFiltered, area, *cs.sps, cu.firstPU->multiRefIdx);
   }
-  else if (m_ipaParam.refFilterFlag || forceRefFilterFlag
-#if JVET_AG0092_ENHANCED_TIMD_FUSION
-    || cu.timd
+  else
 #endif
-    )
-  {
-    xFilterReferenceSamples(refBufUnfiltered, refBufFiltered, area, *cs.sps, cu.firstPU->multiRefIdx);
-  }
-#else
   if( m_ipaParam.refFilterFlag || forceRefFilterFlag 
 #if JVET_AG0092_ENHANCED_TIMD_FUSION 
    || cu.timd
-#endif  
+#endif
   )
   {
     xFilterReferenceSamples( refBufUnfiltered, refBufFiltered, area, *cs.sps, cu.firstPU->multiRefIdx );
   }
-#endif
 }
 
 #if JVET_AJ0161_OBMC_EXT_WITH_INTRA_PRED
@@ -5768,20 +5734,14 @@ void IntraPrediction::initIntraPatternChTypeISP(const CodingUnit& cu, const Comp
     Pel* refBufFiltered = m_refBuffer[area.compID][PRED_BUF_FILTERED];
     xCopyReferenceSamples(refBufUnfiltered, refBufFiltered, area, *cs.sps, cu.firstPU->multiRefIdx);
   }
-  else if (m_ipaParam.refFilterFlag || forceRefFilterFlag)
-  {
-    Pel* refBufUnfiltered = m_refBuffer[area.compID][PRED_BUF_UNFILTERED];
-    Pel* refBufFiltered = m_refBuffer[area.compID][PRED_BUF_FILTERED];
-    xFilterReferenceSamples(refBufUnfiltered, refBufFiltered, area, *cs.sps, cu.firstPU->multiRefIdx);
-  }
-#else
+  else
+#endif
   if (m_ipaParam.refFilterFlag || forceRefFilterFlag)
   {
     Pel *refBufUnfiltered = m_refBuffer[area.compID][PRED_BUF_UNFILTERED];
     Pel *refBufFiltered   = m_refBuffer[area.compID][PRED_BUF_FILTERED];
     xFilterReferenceSamples(refBufUnfiltered, refBufFiltered, area, *cs.sps, cu.firstPU->multiRefIdx);
   }
-#endif
 }
 
 #if JVET_V0130_INTRA_TMP
-- 
GitLab


From 625de9b82cf0d65ad5f8cfada17f85cccead2301 Mon Sep 17 00:00:00 2001
From: KyungYong Kim <kyungyong.kim@wilusgroup.com>
Date: Tue, 12 Nov 2024 10:46:47 +0900
Subject: [PATCH 4/5] Additional change about JVET-AJ0057 (Test 2.14)

---
 source/Lib/CommonLib/IntraPrediction.cpp | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/source/Lib/CommonLib/IntraPrediction.cpp b/source/Lib/CommonLib/IntraPrediction.cpp
index 320bfc1e2..f98b7afc5 100644
--- a/source/Lib/CommonLib/IntraPrediction.cpp
+++ b/source/Lib/CommonLib/IntraPrediction.cpp
@@ -3986,11 +3986,13 @@ void IntraPrediction::xPredIntraAng(
       }
       else
       {
+#endif
         int leftMinus1 = refSide[Clip3(0, sizeSide + 2 + multiRefIdx, intpel - 1)];
         int rightPlus1 = refSide[Clip3(0, sizeSide + 2 + multiRefIdx, intpel + 2)];
         const TFilterCoeff* f = InterpolationFilter::getWeak4TapFilterTable(fracpel);
         int val = ((int)f[0] * leftMinus1 + (int)f[1] * left + (int)f[2] * right + f[3] * (int)rightPlus1 + 32) >> 6;
         refMain[k] = (Pel)ClipPel(val, clpRng);
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
       }
 #endif
     }
@@ -4118,11 +4120,13 @@ void IntraPrediction::xPredIntraAng(
         }
         else
         {
+#endif
           int leftMinus1 = refSide2nd[Clip3(0, sizeSideRange, intpel - 1)];
           int rightPlus1 = refSide2nd[Clip3(0, sizeSideRange, intpel + 2)];
           const TFilterCoeff* f = InterpolationFilter::getWeak4TapFilterTable(fracpel);
           int val = ((int)f[0] * leftMinus1 + (int)f[1] * left + (int)f[2] * right + f[3] * (int)rightPlus1 + 32) >> 6;
           refMain2nd[k] = (Pel)ClipPel(val, clpRng);
+#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
         }
 #endif
       }
-- 
GitLab


From a1c5d1dc25228ab70d1048a8c6739b639f9d9a08 Mon Sep 17 00:00:00 2001
From: KyungYong Kim <kyungyong.kim@wilusgroup.com>
Date: Tue, 12 Nov 2024 16:11:12 +0900
Subject: [PATCH 5/5] Change about JVET-AJ0057 (Test 2.14)

---
 source/Lib/CommonLib/IntraPrediction.cpp | 38 +++++-------------------
 source/Lib/CommonLib/IntraPrediction.h   |  6 ----
 2 files changed, 8 insertions(+), 36 deletions(-)

diff --git a/source/Lib/CommonLib/IntraPrediction.cpp b/source/Lib/CommonLib/IntraPrediction.cpp
index f98b7afc5..bb64c3c3f 100644
--- a/source/Lib/CommonLib/IntraPrediction.cpp
+++ b/source/Lib/CommonLib/IntraPrediction.cpp
@@ -3833,6 +3833,10 @@ void IntraPrediction::initPredIntraParams(const PredictionUnit & pu, const CompA
     m_ipaParam.fetchRef2nd = false;
     m_ipaParam.applyFusion = false;
   }
+  if (pu.cu->cs->sps->getDisableRefFilter())
+  {
+    m_ipaParam.refFilterFlag = false;
+  }
 #endif
 #endif
 }
@@ -5575,7 +5579,6 @@ void IntraPrediction::initIntraPatternChType(const CodingUnit &cu, const CompAre
   if (cu.cs->sps->getDisableRefFilter())
   {
     m_ipaParam.refFilterFlag = false;
-    xCopyReferenceSamples(refBufUnfiltered, refBufFiltered, area, *cs.sps, cu.firstPU->multiRefIdx);
   }
   else
 #endif
@@ -5734,9 +5737,6 @@ void IntraPrediction::initIntraPatternChTypeISP(const CodingUnit& cu, const Comp
   if (cu.cs->sps->getDisableRefFilter())
   {
     m_ipaParam.refFilterFlag = false;
-    Pel* refBufUnfiltered = m_refBuffer[area.compID][PRED_BUF_UNFILTERED];
-    Pel* refBufFiltered = m_refBuffer[area.compID][PRED_BUF_FILTERED];
-    xCopyReferenceSamples(refBufUnfiltered, refBufFiltered, area, *cs.sps, cu.firstPU->multiRefIdx);
   }
   else
 #endif
@@ -7189,32 +7189,6 @@ void IntraPrediction::xFillReferenceSamplesForCoLuma(const CPelBuf &recoBuf, Pel
 }
 #endif
 
-#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
-void IntraPrediction::xCopyReferenceSamples(const Pel* refBufUnfiltered, Pel* refBufFiltered, const CompArea& area, const SPS& sps,
-  int multiRefIdx
-)
-{
-  if (area.compID != COMPONENT_Y)
-  {
-    multiRefIdx = 0;
-  }
-  const int predSize = m_topRefLength + multiRefIdx;
-  const int predHSize = m_leftRefLength + multiRefIdx;
-  const size_t predStride = m_refBufferStride[area.compID];
-
-  for (int i = 0; i < predSize; i++)
-  {
-    refBufFiltered[i] = refBufUnfiltered[i];
-  }
-  refBufFiltered += predStride;
-  refBufUnfiltered += predStride;
-  for (int i = 0; i < predHSize; i++)
-  {
-    refBufFiltered[i] = refBufUnfiltered[i];
-  }
-}
-#endif
-
 void IntraPrediction::xFilterReferenceSamples(const Pel *refBufUnfiltered, Pel *refBufFiltered, const CompArea &area,
                                               const SPS &sps, int multiRefIdx)
 {
@@ -7718,6 +7692,10 @@ void IntraPrediction::initPredTimdIntraParams(const PredictionUnit & pu, const C
     m_ipaParam.applyPDPC = false;
     m_ipaParam.useGradPDPC = false;
   }
+  if (pu.cu->cs->sps->getDisableRefFilter())
+  {
+    m_ipaParam.refFilterFlag = false;
+  }
 #endif
 }
 
diff --git a/source/Lib/CommonLib/IntraPrediction.h b/source/Lib/CommonLib/IntraPrediction.h
index d07a56348..ab93d0172 100644
--- a/source/Lib/CommonLib/IntraPrediction.h
+++ b/source/Lib/CommonLib/IntraPrediction.h
@@ -592,12 +592,6 @@ protected:
                                int multiRefIdx
   );
 
-#if JVET_AJ0057_HL_INTRA_METHOD_CONTROL
-  void xCopyReferenceSamples(const Pel* refBufUnfiltered, Pel* refBufFiltered, const CompArea& area, const SPS& sps,
-    int multiRefIdx
-  );
-#endif
-
   static int getModifiedWideAngle         ( int width, int height, int predMode );
 #if JVET_W0123_TIMD_FUSION
 #if JVET_AB0155_SGPM
-- 
GitLab