From e201bcb73d87abce0070ec9b7c426215137589be Mon Sep 17 00:00:00 2001
From: Karsten Suehring <karsten.suehring@hhi.fraunhofer.de>
Date: Wed, 27 Jul 2022 01:11:28 +0200
Subject: [PATCH] remove macro JVET_Z0047_FG_IMPROVEMENT

---
 source/App/EncoderApp/EncApp.cpp              |  44 -----
 source/App/EncoderApp/EncAppCfg.cpp           |   6 -
 source/App/EncoderApp/EncAppCfg.h             |   2 -
 source/Lib/CommonLib/TypeDef.h                |   1 -
 source/Lib/EncoderLib/EncCfg.h                |   4 -
 source/Lib/EncoderLib/EncGOP.cpp              |  34 ----
 source/Lib/EncoderLib/EncLib.cpp              |   8 -
 .../Lib/EncoderLib/SEIFilmGrainAnalyzer.cpp   | 185 ------------------
 source/Lib/EncoderLib/SEIFilmGrainAnalyzer.h  |  28 ---
 9 files changed, 312 deletions(-)

diff --git a/source/App/EncoderApp/EncApp.cpp b/source/App/EncoderApp/EncApp.cpp
index 6e2b2eeaf7..72d1cb4ac7 100644
--- a/source/App/EncoderApp/EncApp.cpp
+++ b/source/App/EncoderApp/EncApp.cpp
@@ -989,13 +989,11 @@ void EncApp::xInitLibCfg()
   m_cEncLib.setFilmGrainCharactersticsSEIBlendingModeID          ((uint8_t)m_fgcSEIBlendingModeID);
   m_cEncLib.setFilmGrainCharactersticsSEILog2ScaleFactor         ((uint8_t)m_fgcSEILog2ScaleFactor);
   m_cEncLib.setFilmGrainAnalysisEnabled                          (m_fgcSEIAnalysisEnabled);
-#if JVET_Z0047_FG_IMPROVEMENT
   m_cEncLib.setFilmGrainExternalMask                             (m_fgcSEIExternalMask);
   m_cEncLib.setFilmGrainExternalDenoised                         (m_fgcSEIExternalDenoised);
   m_cEncLib.setFilmGrainTemporalFilterPastRefs                   (m_fgcSEITemporalFilterPastRefs);  
   m_cEncLib.setFilmGrainTemporalFilterFutureRefs                 (m_fgcSEITemporalFilterFutureRefs);
   m_cEncLib.setFilmGrainTemporalFilterStrengths                  (m_fgcSEITemporalFilterStrengths); 
-#endif
   m_cEncLib.setFilmGrainCharactersticsSEIPerPictureSEI           (m_fgcSEIPerPictureSEI);
   for (int i = 0; i < MAX_NUM_COMPONENT; i++) {
     m_cEncLib.setFGCSEICompModelPresent                          (m_fgcSEICompModelPresent[i], i);
@@ -1391,11 +1389,7 @@ void EncApp::createLib( const int layerIdx )
     m_filteredOrgPic = new PelStorage;
     m_filteredOrgPic->create( unitArea );
   }
-#if JVET_Z0047_FG_IMPROVEMENT
   if (m_fgcSEIAnalysisEnabled && m_fgcSEIExternalDenoised.empty())
-#else
-  if ( m_fgcSEIAnalysisEnabled )
-#endif
   {
     m_filteredOrgPicForFG = new PelStorage;
     m_filteredOrgPicForFG->create( unitArea );
@@ -1437,7 +1431,6 @@ void EncApp::createLib( const int layerIdx )
                           , m_gopBasedTemporalFilterEnabled, m_cEncLib.getAdaptQPmap(), m_cEncLib.getBIM(), m_uiCTUSize
                           );
   }
-#if JVET_Z0047_FG_IMPROVEMENT
   if ( m_fgcSEIAnalysisEnabled && m_fgcSEIExternalDenoised.empty() )
   {
     m_temporalFilterForFG.init(m_FrameSkip, m_inputBitDepth, m_MSBExtendedBitDepth, m_internalBitDepth, m_sourceWidth,
@@ -1448,27 +1441,6 @@ void EncApp::createLib( const int layerIdx )
                                , true, m_cEncLib.getAdaptQPmap(), m_cEncLib.getBIM(), m_uiCTUSize
                                );
   }
-#else
-  if ( m_fgcSEIAnalysisEnabled )
-  {
-    int  filteredFrame                 = 0;
-
-    if ( m_iIntraPeriod < 1 )
-      filteredFrame = 2 * m_iFrameRate;
-    else
-      filteredFrame = m_iIntraPeriod;
-
-    map<int, double> filteredFramesAndStrengths = { { filteredFrame, 1.5 } };   // TODO: adjust MCTF and MCTF strenght
-
-    m_temporalFilterForFG.init(m_FrameSkip, m_inputBitDepth, m_MSBExtendedBitDepth, m_internalBitDepth, m_sourceWidth,
-                               sourceHeight, m_sourcePadding, m_bClipInputVideoToRec709Range, m_inputFileName,
-                               m_chromaFormatIDC, m_inputColourSpaceConvert, m_iQP, filteredFramesAndStrengths,
-                               m_gopBasedTemporalFilterPastRefs, m_gopBasedTemporalFilterFutureRefs, m_firstValidFrame,
-                               m_lastValidFrame
-                               , m_gopBasedTemporalFilterEnabled, m_cEncLib.getAdaptQPmap(), m_cEncLib.getBIM(), m_uiCTUSize
-                               );
-  }
-#endif
 }
 
 void EncApp::destroyLib()
@@ -1511,11 +1483,7 @@ void EncApp::destroyLib()
       delete p;
     }
   }
-#if JVET_Z0047_FG_IMPROVEMENT
   if (m_fgcSEIAnalysisEnabled && m_fgcSEIExternalDenoised.empty())
-#else
-  if (m_fgcSEIAnalysisEnabled)
-#endif
   {
     m_filteredOrgPicForFG->destroy();
     delete m_filteredOrgPicForFG;
@@ -1548,28 +1516,16 @@ bool EncApp::encodePrep( bool& eos )
   m_cVideoIOYuvInputFile.read( *m_orgPic, *m_trueOrgPic, ipCSC, m_sourcePadding, m_InputChromaFormatIDC, m_bClipInputVideoToRec709Range );
 #endif
 
-#if JVET_Z0047_FG_IMPROVEMENT
   if (m_fgcSEIAnalysisEnabled && m_fgcSEIExternalDenoised.empty())
-#else
-  if (m_fgcSEIAnalysisEnabled)
-#endif
   {
     m_filteredOrgPicForFG->copyFrom(*m_orgPic);
-#if JVET_Z0047_FG_IMPROVEMENT
     m_temporalFilterForFG.filter(m_filteredOrgPicForFG, m_iFrameRcvd);
-#endif
   }
   if ( m_gopBasedTemporalFilterEnabled || m_bimEnabled )
   {
     m_temporalFilter.filter(m_orgPic, m_iFrameRcvd);
     m_filteredOrgPic->copyFrom(*m_orgPic);
   }
-#if !JVET_Z0047_FG_IMPROVEMENT // moved up
-  if (m_fgcSEIAnalysisEnabled)
-  {
-    m_temporalFilterForFG.filter(m_filteredOrgPicForFG, m_iFrameRcvd);
-  }
-#endif
 
   // increase number of received frames
   m_iFrameRcvd++;
diff --git a/source/App/EncoderApp/EncAppCfg.cpp b/source/App/EncoderApp/EncAppCfg.cpp
index f3d967b224..ec1ded0fca 100644
--- a/source/App/EncoderApp/EncAppCfg.cpp
+++ b/source/App/EncoderApp/EncAppCfg.cpp
@@ -1442,13 +1442,11 @@ bool EncAppCfg::parseCfg( int argc, char* argv[] )
   ("SEIFGCCompModelPresentComp1",                     m_fgcSEICompModelPresent[1],                       false, "Specifies the presence of film grain modelling on colour component 1.")
   ("SEIFGCCompModelPresentComp2",                     m_fgcSEICompModelPresent[2],                       false, "Specifies the presence of film grain modelling on colour component 2.")
   ("SEIFGCAnalysisEnabled",                           m_fgcSEIAnalysisEnabled,                           false, "Control adaptive film grain parameter estimation - film grain analysis")
-#if JVET_Z0047_FG_IMPROVEMENT
   ("SEIFGCExternalMask",                              m_fgcSEIExternalMask,                       string( "" ), "Read external file with mask for film grain analysis. If empty string, use internally calculated mask.")
   ("SEIFGCExternalDenoised",                          m_fgcSEIExternalDenoised,                   string( "" ), "Read external file with denoised sequence for film grain analysis. If empty string, use MCTF for denoising.")
   ("SEIFGCTemporalFilterPastRefs",                    m_fgcSEITemporalFilterPastRefs,          TF_DEFAULT_REFS, "Number of past references for temporal prefilter")
   ("SEIFGCTemporalFilterFutureRefs",                  m_fgcSEITemporalFilterFutureRefs,        TF_DEFAULT_REFS, "Number of future references for temporal prefilter")
   ("SEIFGCTemporalFilterStrengthFrame*",              m_fgcSEITemporalFilterStrengths, std::map<int, double>(), "Strength for every * frame in FGC-specific temporal filter, where * is an integer.")
-#endif
   ("SEIFGCPerPictureSEI",                             m_fgcSEIPerPictureSEI,                             false, "Film Grain SEI is added for each picture as speciffied in RDD5 to ensure bit accurate synthesis in tricky mode")
   ("SEIFGCNumIntensityIntervalMinus1Comp0",           m_fgcSEINumIntensityIntervalMinus1[0],                0u, "Specifies the number of intensity intervals minus1 on colour component 0.")
   ("SEIFGCNumIntensityIntervalMinus1Comp1",           m_fgcSEINumIntensityIntervalMinus1[1],                0u, "Specifies the number of intensity intervals minus1 on colour component 1.")
@@ -2792,14 +2790,12 @@ bool EncAppCfg::parseCfg( int argc, char* argv[] )
       msg(WARNING, "*************************************************************************\n");
       m_fgcSEIPersistenceFlag = false;
     }
-#if JVET_Z0047_FG_IMPROVEMENT
     if (m_fgcSEIAnalysisEnabled && m_fgcSEITemporalFilterStrengths.empty())
     {
       // By default: in random-acces = filter RAPs, in all-intra = filter every frame, otherwise = filter every 2s 
       int filteredFrame = m_iIntraPeriod < 1 ? 2 * m_iFrameRate : m_iIntraPeriod;
       m_fgcSEITemporalFilterStrengths[filteredFrame] = 1.5;
     }
-#endif
     uint32_t numModelCtr;
     if (m_fgcSEICompModelPresent[0])
     {
@@ -5037,9 +5033,7 @@ void EncAppCfg::xPrintParameter()
   msg(VERBOSE, "TemporalFilter:%d/%d ", m_gopBasedTemporalFilterPastRefs, m_gopBasedTemporalFilterFutureRefs);
   msg(VERBOSE, "SEI CTI:%d ", m_ctiSEIEnabled);
   msg(VERBOSE, "BIM:%d ", m_bimEnabled);
-#if JVET_Z0047_FG_IMPROVEMENT
   msg(VERBOSE, "SEI FGC:%d ", m_fgcSEIEnabled);
-#endif
 
 #if EXTENSION_360_VIDEO
   m_ext360.outputConfigurationSummary();
diff --git a/source/App/EncoderApp/EncAppCfg.h b/source/App/EncoderApp/EncAppCfg.h
index 6dcfa61134..1d73ff7ab1 100644
--- a/source/App/EncoderApp/EncAppCfg.h
+++ b/source/App/EncoderApp/EncAppCfg.h
@@ -549,13 +549,11 @@ protected:
   uint32_t  m_fgcSEILog2ScaleFactor;
   bool      m_fgcSEICompModelPresent[MAX_NUM_COMPONENT];
   bool      m_fgcSEIAnalysisEnabled;
-#if JVET_Z0047_FG_IMPROVEMENT
   std::string m_fgcSEIExternalMask;
   std::string m_fgcSEIExternalDenoised;
   int       m_fgcSEITemporalFilterPastRefs;
   int       m_fgcSEITemporalFilterFutureRefs;
   std::map<int, double> m_fgcSEITemporalFilterStrengths;
-#endif
   bool      m_fgcSEIPerPictureSEI;
   uint32_t  m_fgcSEINumModelValuesMinus1          [MAX_NUM_COMPONENT];
   uint32_t  m_fgcSEINumIntensityIntervalMinus1    [MAX_NUM_COMPONENT];
diff --git a/source/Lib/CommonLib/TypeDef.h b/source/Lib/CommonLib/TypeDef.h
index c8e0073f9e..83a042d4eb 100644
--- a/source/Lib/CommonLib/TypeDef.h
+++ b/source/Lib/CommonLib/TypeDef.h
@@ -54,7 +54,6 @@
 
 
 //########### place macros to be removed in next cycle below this line ###############
-#define JVET_Z0047_FG_IMPROVEMENT                         1 // Improvements to the film grain analysis code
 
 //########### place macros to be be kept below this line ###############
 #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.
diff --git a/source/Lib/EncoderLib/EncCfg.h b/source/Lib/EncoderLib/EncCfg.h
index 2b879b484f..d8890a4659 100644
--- a/source/Lib/EncoderLib/EncCfg.h
+++ b/source/Lib/EncoderLib/EncCfg.h
@@ -703,13 +703,11 @@ protected:
   uint8_t   m_fgcSEILog2ScaleFactor;
   bool      m_fgcSEICompModelPresent[MAX_NUM_COMPONENT];
   bool      m_fgcSEIAnalysisEnabled;
-#if JVET_Z0047_FG_IMPROVEMENT
   std::string m_fgcSEIExternalMask;
   std::string m_fgcSEIExternalDenoised;
   int       m_fgcSEITemporalFilterPastRefs;
   int       m_fgcSEITemporalFilterFutureRefs;
   std::map<int, double> m_fgcSEITemporalFilterStrengths;
-#endif
   bool      m_fgcSEIPerPictureSEI;
   uint8_t   m_fgcSEINumModelValuesMinus1          [MAX_NUM_COMPONENT];
   uint8_t   m_fgcSEINumIntensityIntervalMinus1    [MAX_NUM_COMPONENT];
@@ -2042,7 +2040,6 @@ public:
   bool*     getFGCSEICompModelPresent                 ()                        { return m_fgcSEICompModelPresent; }
   void      setFilmGrainAnalysisEnabled               (bool b)                  { m_fgcSEIAnalysisEnabled = b; }
   bool      getFilmGrainAnalysisEnabled               ()                        { return m_fgcSEIAnalysisEnabled; }
-#if JVET_Z0047_FG_IMPROVEMENT
   void        setFilmGrainExternalMask(std::string s) { m_fgcSEIExternalMask = s; }
   void        setFilmGrainExternalDenoised(std::string s) { m_fgcSEIExternalDenoised = s; }
   std::string getFilmGrainExternalMask() { return m_fgcSEIExternalMask; }
@@ -2053,7 +2050,6 @@ public:
   int         getFilmGrainTemporalFilterPastRefs()                              { return m_fgcSEITemporalFilterPastRefs; };
   int         getFilmGrainTemporalFilterFutureRef()                             { return m_fgcSEITemporalFilterFutureRefs; };
   std::map<int, double> getFilmGrainTemporalFilterStrengths()                   { return m_fgcSEITemporalFilterStrengths; };
-#endif
   void      setFilmGrainCharactersticsSEIPerPictureSEI(bool b)                  { m_fgcSEIPerPictureSEI = b; }
   bool      getFilmGrainCharactersticsSEIPerPictureSEI()                        { return m_fgcSEIPerPictureSEI; }
   void      setFGCSEINumIntensityIntervalMinus1 (uint8_t v, int index)          { m_fgcSEINumIntensityIntervalMinus1[index] = v; }
diff --git a/source/Lib/EncoderLib/EncGOP.cpp b/source/Lib/EncoderLib/EncGOP.cpp
index 6cbfcb7ff4..1a19707194 100644
--- a/source/Lib/EncoderLib/EncGOP.cpp
+++ b/source/Lib/EncoderLib/EncGOP.cpp
@@ -235,16 +235,11 @@ void EncGOP::init ( EncLib* pcEncLib )
 
   if (m_pcCfg->getFilmGrainAnalysisEnabled())
   {
-#if JVET_Z0047_FG_IMPROVEMENT
     m_FGAnalyser.init(m_pcCfg->getSourceWidth(), m_pcCfg->getSourceHeight(), m_pcCfg->getSourcePadding(0),
                       m_pcCfg->getSourcePadding(1), IPCOLOURSPACE_UNCHANGED, false, m_pcCfg->getChromaFormatIdc(),
                       *(BitDepths *) m_pcCfg->getInputBitDepth(), *(BitDepths *) m_pcCfg->getBitDepth(),
                       m_pcCfg->getFrameSkip(), m_pcCfg->getFGCSEICompModelPresent(),
                       m_pcCfg->getFilmGrainExternalMask(), m_pcCfg->getFilmGrainExternalDenoised());
-#else
-    m_FGAnalyser.init(m_pcCfg->getSourceWidth(), m_pcCfg->getSourceHeight(), m_pcCfg->getChromaFormatIdc(),
-                      *(BitDepths *) pcEncLib->getBitDepth(), m_pcCfg->getFGCSEICompModelPresent());
-#endif
   }
 
 #if WCG_EXT
@@ -3677,7 +3672,6 @@ void EncGOP::compressGOP(int pocLast, int numPicRcvd, PicList &rcListPic, std::l
 
     if (m_pcCfg->getFilmGrainAnalysisEnabled())
     {
-#if JVET_Z0047_FG_IMPROVEMENT
       int  filteredFrame    = m_pcCfg->getIntraPeriod() < 1 ? 2 * m_pcCfg->getFrameRate() : m_pcCfg->getIntraPeriod();
       bool ready_to_analyze = pcPic->getPOC() % filteredFrame ? false : true; // either it is mctf denoising or external source for film grain analysis. note: if mctf is used, it is different from mctf for encoding.
       if (ready_to_analyze)
@@ -3685,34 +3679,6 @@ void EncGOP::compressGOP(int pocLast, int numPicRcvd, PicList &rcListPic, std::l
         m_FGAnalyser.initBufs(pcPic);
         m_FGAnalyser.estimate_grain(pcPic);
       }
-#else
-      int picPoc        = pcPic->getPOC();
-      int filteredFrame = 0;
-
-      if (m_pcCfg->getIntraPeriod() < 1)
-      {
-        filteredFrame = 2 * m_pcCfg->getFrameRate();
-      }
-      else
-      {
-        filteredFrame = m_pcCfg->getIntraPeriod();
-      }
-
-      if (picPoc % filteredFrame == 0)
-      {
-        pcPic->m_isMctfFiltered = true;
-      }
-      else
-      {
-        pcPic->m_isMctfFiltered = false;
-      }
-
-      if (pcPic->m_isMctfFiltered)
-      {
-        m_FGAnalyser.initBufs(pcPic);
-        m_FGAnalyser.estimate_grain(pcPic);
-      }
-#endif
     }
 
     if( encPic || decPic )
diff --git a/source/Lib/EncoderLib/EncLib.cpp b/source/Lib/EncoderLib/EncLib.cpp
index 9a1cb81ee2..a847551aca 100644
--- a/source/Lib/EncoderLib/EncLib.cpp
+++ b/source/Lib/EncoderLib/EncLib.cpp
@@ -619,11 +619,7 @@ bool EncLib::encodePrep(bool flush, PelStorage *pcPicYuvOrg, PelStorage *cPicYuv
       {
         pcPicCurr->M_BUFS( 0, PIC_FILTERED_ORIGINAL ).swap( *pcPicYuvFilteredOrg );
       }
-#if JVET_Z0047_FG_IMPROVEMENT
       if (m_fgcSEIAnalysisEnabled && m_fgcSEIExternalDenoised.empty())
-#else
-      if (m_fgcSEIAnalysisEnabled)
-#endif
       {
         pcPicCurr->M_BUFS( 0, PIC_FILTERED_ORIGINAL_FG ).swap( *pcPicYuvFilteredOrgForFG );
       }
@@ -931,11 +927,7 @@ void EncLib::xGetNewPicBuffer ( std::list<PelUnitBuf*>& rcListPicYuvRecOut, Pict
   if (rpcPic==0)
   {
     rpcPic = new Picture;
-#if JVET_Z0047_FG_IMPROVEMENT
     bool fgAnalysisEnabled = m_fgcSEIAnalysisEnabled && m_fgcSEIExternalDenoised.empty();
-#else
-    bool fgAnalysisEnabled = m_fgcSEIAnalysisEnabled;
-#endif
 #if JVET_Z0120_SII_SEI_PROCESSING
     rpcPic->create(sps.getChromaFormatIdc(), Size(pps.getPicWidthInLumaSamples(), pps.getPicHeightInLumaSamples()),
       sps.getMaxCUWidth(), sps.getMaxCUWidth() + PIC_MARGIN, false, m_layerId, getShutterFilterFlag(),
diff --git a/source/Lib/EncoderLib/SEIFilmGrainAnalyzer.cpp b/source/Lib/EncoderLib/SEIFilmGrainAnalyzer.cpp
index 4d2ff7db95..1d1dc0969f 100644
--- a/source/Lib/EncoderLib/SEIFilmGrainAnalyzer.cpp
+++ b/source/Lib/EncoderLib/SEIFilmGrainAnalyzer.cpp
@@ -455,15 +455,10 @@ FGAnalyser::~FGAnalyser()
 }
 
 // initialize film grain parameters
-#if JVET_Z0047_FG_IMPROVEMENT
 void FGAnalyser::init(const int width, const int height, const int sourcePaddingWidth, const int sourcePaddingHeight,
                       const InputColourSpaceConversion ipCSC, bool clipInputVideoToRec709Range, const ChromaFormat inputChroma,
                       const BitDepths &inputBitDepths, const BitDepths &outputBitDepths, const int frameSkip, 
                       const bool doAnalysis[], std::string filmGrainExternalMask, std::string filmGrainExternalDenoised)
-#else
-void FGAnalyser::init(const int width, const int height, const ChromaFormat inputChroma,
-                      const BitDepths &inputBitDepths, const bool doAnalysis[])
-#endif
 {
   m_log2ScaleFactor = 2;
   for (int i = 0; i < MAX_NUM_COMPONENT; i++)
@@ -471,13 +466,8 @@ void FGAnalyser::init(const int width, const int height, const ChromaFormat inpu
     m_compModel[i].presentFlag           = true;
     m_compModel[i].numModelValues        = 1;
     m_compModel[i].numIntensityIntervals = 1;
-#if JVET_Z0047_FG_IMPROVEMENT
     m_compModel[i].intensityValues.resize(MAX_NUM_INTENSITIES);
     for (int j = 0; j < MAX_NUM_INTENSITIES; j++)
-#else
-    m_compModel[i].intensityValues.resize(MAX_ALLOWED_COMP_MODEL_PAIRS);
-    for (int j = 0; j < MAX_ALLOWED_COMP_MODEL_PAIRS; j++)
-#endif
     {
       m_compModel[i].intensityValues[j].intensityIntervalLowerBound = 10;
       m_compModel[i].intensityValues[j].intensityIntervalUpperBound = 250;
@@ -492,7 +482,6 @@ void FGAnalyser::init(const int width, const int height, const ChromaFormat inpu
 
   // initialize picture parameters and create buffers
   m_chromaFormatIDC = inputChroma;
-#if JVET_Z0047_FG_IMPROVEMENT
   m_bitDepthsIn                 = inputBitDepths;
   m_bitDepths                   = outputBitDepths;
   m_sourcePadding[0]            = sourcePaddingWidth;
@@ -502,9 +491,6 @@ void FGAnalyser::init(const int width, const int height, const ChromaFormat inpu
   m_frameSkip                   = frameSkip;
   m_filmGrainExternalMask       = filmGrainExternalMask;
   m_filmGrainExternalDenoised   = filmGrainExternalDenoised;
-#else
-  m_bitDepths       = inputBitDepths;
-#endif
 
   int margin = m_edgeDetector.m_convWidthG / 2;   // set margin for padding for filtering
 
@@ -529,7 +515,6 @@ void FGAnalyser::init(const int width, const int height, const ChromaFormat inpu
 void FGAnalyser::initBufs(Picture *pic)
 {
   m_originalBuf->copyFrom(pic->getTrueOrigBuf());   // original is here
-#if JVET_Z0047_FG_IMPROVEMENT
   PelStorage dummyPicBufferTO;                      // Only used temporary in yuvFrames.read
   dummyPicBufferTO.create(pic->cs->area);
   if (!m_filmGrainExternalDenoised.empty())         // read external denoised frame
@@ -567,16 +552,6 @@ void FGAnalyser::initBufs(Picture *pic)
   {
     findMask();
   }
-#else
-  if (pic->m_isMctfFiltered)
-  {
-    m_workingBuf->copyFrom(pic->m_bufs[PIC_FILTERED_ORIGINAL_FG]);   // filtered frame for film grain analysis is in here
-  }
-  else
-  {
-    THROW("ERROR: To estimate film grain parameters, you need to have filtered frame, e.g., MCTF filtered frame.\n");
-  }
-#endif
 }
 
 // delete picture buffers
@@ -605,10 +580,6 @@ void FGAnalyser::destroy()
 // main functions for film grain analysis
 void FGAnalyser::estimate_grain(Picture *pic)
 {
-#if !JVET_Z0047_FG_IMPROVEMENT // moved to other place; to be deleted
-  // find mask
-  findMask();
-#endif
 
   // estimate parameters
   estimate_grain_parameters();
@@ -656,20 +627,12 @@ void FGAnalyser::findMask()
     // full resolution
     m_edgeDetector.detect_edges(m_workingBuf, m_maskBuf, bitDepth, compID);
     suppressLowIntensity(*m_workingBuf, *m_maskBuf, bitDepth, compID);
-#if JVET_Z0047_FG_IMPROVEMENT
     m_morphOperation.dilation(m_maskBuf, bitDepth, compID, 4);
-#else
-    m_morphOperation.dilation(m_maskBuf, bitDepth, compID, 1);
-#endif
 
     // subsampled 2
     m_edgeDetector.detect_edges(workingBufSubsampled2, maskSubsampled2, bitDepth, compID);
     suppressLowIntensity(*workingBufSubsampled2, *maskSubsampled2, bitDepth, compID);
-#if JVET_Z0047_FG_IMPROVEMENT
     m_morphOperation.dilation(maskSubsampled2, bitDepth, compID, 3);
-#else
-    m_morphOperation.dilation(maskSubsampled2, bitDepth, compID, 1);
-#endif
 
     // upsample, combine maskBuf and maskUpsampled
     upsample(*maskSubsampled2, *maskUpsampled, compID, 2);
@@ -678,11 +641,7 @@ void FGAnalyser::findMask()
     // subsampled 4
     m_edgeDetector.detect_edges(workingBufSubsampled4, maskSubsampled4, bitDepth, compID);
     suppressLowIntensity(*workingBufSubsampled4, *maskSubsampled4, bitDepth, compID);
-#if JVET_Z0047_FG_IMPROVEMENT
     m_morphOperation.dilation(maskSubsampled4, bitDepth, compID, 2);
-#else
-    m_morphOperation.dilation(maskSubsampled4, bitDepth, compID, 1);
-#endif
 
     // upsample, combine maskBuf and maskUpsampled
     upsample(*maskSubsampled4, *maskUpsampled, compID, 4);
@@ -809,18 +768,6 @@ void FGAnalyser::combineMasks(PelStorage &buff1, PelStorage &buff2, ComponentID
   }
 }
 
-#if !JVET_Z0047_FG_IMPROVEMENT // to be deleted - unused function
-int FGAnalyser::denoise(Picture *pic)
-{
-  if (pic->m_isMctfFiltered)
-  {
-    return 0;
-  }
-
-  // add custom denoising algorithm
-  return 1;
-}
-#endif
 
 // estimate cut-off frequencies and scaling factors for different intensity intervals
 void FGAnalyser::estimate_grain_parameters()
@@ -891,11 +838,9 @@ void FGAnalyser::estimate_grain_parameters()
               // collect all data for parameter estimation; mean and variance are caluclated on blockSize x blockSize blocks
               mean = meanVar(*m_workingBuf, blockSize, compID, i + k * blockSize, j + m * blockSize, false);
               var  = meanVar(*tmpBuff, blockSize, compID, i + k * blockSize, j + m * blockSize, true);
-#if JVET_Z0047_FG_IMPROVEMENT
               // regularize high variations; controls excessively fluctuating points
               double tmp = 3.0 * pow((double)(var), .5) + .5;
               var = (int)tmp;
-#endif
               if (var < (MAX_REAL_SCALE << (bitDepth - BIT_DEPTH_8))) // limit data points to meaningful values. higher variance can be result of not perfect mask estimation (non-flat regions fall in estimation process)
               {
                 vec_mean.push_back(mean);   // mean of the filtered frame
@@ -934,12 +879,7 @@ void FGAnalyser::estimate_scaling_factors(std::vector<int> &data_x, std::vector<
 
   // Fit the points with the curve. Quantization of the curve using Lloyd Max quantization.
   bool valid;
-#if JVET_Z0047_FG_IMPROVEMENT
   for (int i = 0; i < NUM_PASSES; i++)   // if num_passes = 2, filtering of the dataset points is performed
-#else
-  int  num_passes = 2;
-  for (int i = 0; i < num_passes; i++) // if num_passes = 2, filtering of the dataset points is performed in the second step
-#endif
   {
     valid = fit_function(data_x, data_y, coeffs, scalingVec, ORDER, bitDepth, i);   // n-th order polynomial regression for scaling function estimation
     if (!valid)
@@ -1173,7 +1113,6 @@ int FGAnalyser::count_edges(PelStorage &buffer, int windowSize, ComponentID comp
 // calulate mean and variance for windowSize x windowSize block
 int FGAnalyser::meanVar(PelStorage &buffer, int windowSize, ComponentID compID, int offsetX, int offsetY, bool getVar)
 {
-#if JVET_Z0047_FG_IMPROVEMENT
   double m = 0, v = 0;
 
   for (int x = 0; x < windowSize; x++)
@@ -1192,37 +1131,6 @@ int FGAnalyser::meanVar(PelStorage &buffer, int windowSize, ComponentID compID,
   }
 
   return (int)(m + .5);
-#else
-  int m = 0, v = 0;
-  int log2WindowsSize = floorLog2(windowSize);
-
-  for (int x = 0; x < windowSize; x++)
-  {
-    for (int y = 0; y < windowSize; y++)
-    {
-      m += buffer.get(compID).at(offsetX + x, offsetY + y);
-    }
-  }
-  m = (m + (1 << (log2WindowsSize + log2WindowsSize - 1))) >> (log2WindowsSize + log2WindowsSize);
-
-  if (getVar)
-  {
-    for (int x = 0; x < windowSize; x++)
-    {
-      for (int y = 0; y < windowSize; y++)
-      {
-        v +=
-          (buffer.get(compID).at(offsetX + x, offsetY + y) - m) * (buffer.get(compID).at(offsetX + x, offsetY + y) - m);
-      }
-    }
-    v = (v + (1 << (log2WindowsSize + log2WindowsSize - 1))) >> (log2WindowsSize + log2WindowsSize);
-    return v;
-  }
-  else
-  {
-    return m;
-  }
-#endif
 }
 
 // Fit data to a function using n-th order polynomial interpolation
@@ -1308,7 +1216,6 @@ bool FGAnalyser::fit_function(std::vector<int> &data_x, std::vector<int> &data_y
                     // parameters are used
   }
 
-#if JVET_Z0047_FG_IMPROVEMENT
   for (i = 0; i < tmp_data_x.size(); i++) // remove single points before extending and fitting
   {
     int check = 0;
@@ -1330,12 +1237,6 @@ bool FGAnalyser::fit_function(std::vector<int> &data_x, std::vector<int> &data_y
   }
 
   extend_points(tmp_data_x, tmp_data_y, bitDepth);   // find the most left and the most right point, and extend edges
-#else
-  if (second_pass)
-  {
-    extend_points(tmp_data_x, tmp_data_y, bitDepth);   // find the most left and the most right point, and extend edges
-  }
-#endif
 
   CHECK(tmp_data_x.size() > MAXPAIRS, "Maximum dataset size exceeded.");
 
@@ -1957,76 +1858,6 @@ void FGAnalyser::setEstimatedParameters(std::vector<int> &quantizedVec, unsigned
     return;
   }
 
-#if !JVET_Z0047_FG_IMPROVEMENT // misunderstood limitation; number of intervals can be more than 10, but pairs of cut-off frequencies must be less or equal to 10
-                               // to be deleted
-  // if number of intervals is larger than 10, find smallest interval and merge it with the closest one
-  while (m_compModel[compID].numIntensityIntervals > 10)
-  {
-    int diff           = finalIntervalsandScalingFactors[1][0] - finalIntervalsandScalingFactors[0][0];
-    int minIntervalIdx = 0;
-
-    for (int i = 1; i < finalIntervalsandScalingFactors[2].size(); i++)
-    {
-      if (finalIntervalsandScalingFactors[2][i] != 0)
-      {
-        int tmp = finalIntervalsandScalingFactors[1][i] - finalIntervalsandScalingFactors[0][i];
-        if (tmp < diff)
-        {
-          minIntervalIdx = i;
-          diff           = tmp;
-        }
-      }
-    }
-
-    int diffRight = (minIntervalIdx == (finalIntervalsandScalingFactors[2].size() - 1))
-                        || (finalIntervalsandScalingFactors[2][minIntervalIdx + 1] == 0)
-                      ? std::numeric_limits<int>::max()
-                      : abs(finalIntervalsandScalingFactors[2][minIntervalIdx] - finalIntervalsandScalingFactors[2][minIntervalIdx + 1]);
-    int diffLeft = (minIntervalIdx == 0) || (finalIntervalsandScalingFactors[2][minIntervalIdx - 1] == 0)
-                     ? std::numeric_limits<int>::max()
-                     : abs(finalIntervalsandScalingFactors[2][minIntervalIdx] - finalIntervalsandScalingFactors[2][minIntervalIdx - 1]);
-
-    // merge with left or right interval
-    if (diffLeft < diffRight)
-    {
-      int tmp1 =
-        finalIntervalsandScalingFactors[1][minIntervalIdx - 1] - finalIntervalsandScalingFactors[0][minIntervalIdx - 1];
-      int tmp2 =
-        finalIntervalsandScalingFactors[1][minIntervalIdx] - finalIntervalsandScalingFactors[0][minIntervalIdx];
-
-      int newScale = (tmp1 * finalIntervalsandScalingFactors[2][minIntervalIdx - 1]
-                      + tmp2 * finalIntervalsandScalingFactors[2][minIntervalIdx])
-                     / (tmp1 + tmp2);
-
-      finalIntervalsandScalingFactors[1][minIntervalIdx - 1] = finalIntervalsandScalingFactors[1][minIntervalIdx];
-      finalIntervalsandScalingFactors[2][minIntervalIdx - 1] = newScale;
-      for (int i = 0; i < 3; i++)
-      {
-        finalIntervalsandScalingFactors[i].erase(finalIntervalsandScalingFactors[i].begin() + minIntervalIdx);
-      }
-    }
-    else
-    {
-      int tmp1 =
-        finalIntervalsandScalingFactors[1][minIntervalIdx + 1] - finalIntervalsandScalingFactors[0][minIntervalIdx + 1];
-      int tmp2 =
-        finalIntervalsandScalingFactors[1][minIntervalIdx] - finalIntervalsandScalingFactors[0][minIntervalIdx];
-
-      int newScale = (tmp1 * finalIntervalsandScalingFactors[2][minIntervalIdx + 1]
-                      + tmp2 * finalIntervalsandScalingFactors[2][minIntervalIdx])
-                     / (tmp1 + tmp2);
-
-      finalIntervalsandScalingFactors[1][minIntervalIdx] = finalIntervalsandScalingFactors[1][minIntervalIdx + 1];
-      finalIntervalsandScalingFactors[2][minIntervalIdx] = newScale;
-      for (int i = 0; i < 3; i++)
-      {
-        finalIntervalsandScalingFactors[i].erase(finalIntervalsandScalingFactors[i].begin() + minIntervalIdx + 1);
-      }
-    }
-
-    m_compModel[compID].numIntensityIntervals--;
-  }
-#endif
 
   // set final interval boundaries and scaling factors. check if some interval has scaling factor 0, and do not encode
   // them within SEI.
@@ -2043,9 +1874,7 @@ void FGAnalyser::setEstimatedParameters(std::vector<int> &quantizedVec, unsigned
       j++;
     }
   }
-#if JVET_Z0047_FG_IMPROVEMENT
   CHECK(j != m_compModel[compID].numIntensityIntervals, "Check film grain intensity levels");
-#endif
 }
 
 long double FGAnalyser::ldpow(long double n, unsigned p)
@@ -2137,39 +1966,26 @@ void FGAnalyser::extend_points(std::vector<int> &data_x, std::vector<int> &data_
   // extend points to the left
   int    step  = POINT_STEP;
   double scale = POINT_SCALE;
-#if JVET_Z0047_FG_IMPROVEMENT
   int num_extra_point_left  = MAX_NUM_POINT_TO_EXTEND;
   int num_extra_point_right = MAX_NUM_POINT_TO_EXTEND;
   while (xmin >= step && ymin > 1 && num_extra_point_left > 0)
-#else
-  while (xmin >= step && ymin > 1)
-#endif
   {
     xmin -= step;
     ymin = static_cast<int>(ymin / scale);
     data_x.push_back(xmin);
     data_y.push_back(ymin);
-#if JVET_Z0047_FG_IMPROVEMENT
     num_extra_point_left--;
-#endif
   }
 
   // extend points to the right
-#if JVET_Z0047_FG_IMPROVEMENT
   while (xmax + step <= ((1 << bitDepth) - 1) && ymax > 1 && num_extra_point_right > 0)
-#else
-  while (xmax + step <= ((1 << bitDepth) - 1) && ymax > 1)
-#endif
   {
     xmax += step;
     ymax = static_cast<int>(ymax / scale);
     data_x.push_back(xmax);
     data_y.push_back(ymax);
-#if JVET_Z0047_FG_IMPROVEMENT
     num_extra_point_right--;
-#endif
   }
-#if JVET_Z0047_FG_IMPROVEMENT
   for (int i = 0; i < data_x.size(); i++)
   {
     if (data_x[i] < MIN_INTENSITY || data_x[i] > MAX_INTENSITY)
@@ -2179,6 +1995,5 @@ void FGAnalyser::extend_points(std::vector<int> &data_x, std::vector<int> &data_
       i--;
     }
   }
-#endif
 }
 
diff --git a/source/Lib/EncoderLib/SEIFilmGrainAnalyzer.h b/source/Lib/EncoderLib/SEIFilmGrainAnalyzer.h
index a4062dc041..add67d232a 100644
--- a/source/Lib/EncoderLib/SEIFilmGrainAnalyzer.h
+++ b/source/Lib/EncoderLib/SEIFilmGrainAnalyzer.h
@@ -55,7 +55,6 @@ static constexpr double   PI                            =     3.1415926535897932
 // POLYFIT
 static constexpr int      MAXPAIRS                                  = 256;
 static constexpr int      MAXORDER                                  = 8;     // maximum order of polinomial fitting
-#if JVET_Z0047_FG_IMPROVEMENT
 static constexpr int      MAX_REAL_SCALE                            = 16;
 static constexpr int      ORDER                                     = 4;     // order of polinomial function
 static constexpr int      QUANT_LEVELS                              = 4;     // number of quantization levels in lloyd max quantization
@@ -73,20 +72,6 @@ static constexpr int      NBRS                                      = 1;     //
 static constexpr int      WINDOW                                    = 1;     // window to check surrounding points
 static constexpr int      MIN_INTENSITY                             = 40;
 static constexpr int      MAX_INTENSITY                             = 950;
-#else
-static constexpr int      MAX_REAL_SCALE                            = 32;
-static constexpr int      ORDER                                     = 3;     // order of polinomial function
-static constexpr int      QUANT_LEVELS                              = 4;     // number of quantization levels in lloyd max quantization
-static constexpr int      INTERVAL_SIZE                             = 16;
-static constexpr int      MIN_ELEMENT_NUMBER_PER_INTENSITY_INTERVAL = 32;
-static constexpr int      MIN_POINTS_FOR_INTENSITY_ESTIMATION       = 128;   // 4*32 = 128; 4 intervals with at least 32 points
-static constexpr int      MIN_BLOCKS_FOR_CUTOFF_ESTIMATION          = 4;     // 4 blocks of 64 x 64 size
-static constexpr int      POINT_STEP                                = 8;     // step size in point extension
-static constexpr double   POINT_SCALE                               = 1.5;   // scaling in point extension
-static constexpr double   VAR_SCALE_DOWN                            = 1.5;   // filter out large points
-static constexpr double   VAR_SCALE_UP                              = 0.5;   // filter out large points
-static constexpr int      NUM_PASSES                                = 2;     // number of passes when fitting the function
-#endif
 
 //! \ingroup SEIFilmGrainAnalyzer
 //! \{
@@ -154,7 +139,6 @@ public:
   FGAnalyser();
   ~FGAnalyser();
 
-#if JVET_Z0047_FG_IMPROVEMENT
   void init(const int width,
             const int height,
             const int sourcePaddingWidth,
@@ -168,13 +152,6 @@ public:
             const bool doAnalysis[],
             std::string filmGrainExternalMask,
             std::string filmGrainExternalDenoised);
-#else
-  void init(const int width,
-            const int height,
-            const ChromaFormat inputChroma,
-            const BitDepths& inputBitDepths,
-            const bool doAnalysis[]);
-#endif
   void destroy        ();
   void initBufs       (Picture* pic);
   void estimate_grain (Picture* pic);
@@ -183,7 +160,6 @@ public:
   SEIFilmGrainCharacteristics::CompModel  getCompModel(int idx) { return m_compModel[idx];  };
 
 private:
-#if JVET_Z0047_FG_IMPROVEMENT
   std::string                      m_filmGrainExternalMask     = "";
   std::string                      m_filmGrainExternalDenoised = "";
   int                              m_sourcePadding[2];
@@ -191,7 +167,6 @@ private:
   bool                             m_clipInputVideoToRec709Range;
   BitDepths                        m_bitDepthsIn;
   int                              m_frameSkip;
-#endif
   ChromaFormat  m_chromaFormatIDC;
   BitDepths     m_bitDepths;
   bool          m_doAnalysis[MAX_NUM_COMPONENT] = { false, false, false };
@@ -210,9 +185,6 @@ private:
   PelStorage *m_workingBuf  = nullptr;
   PelStorage *m_maskBuf     = nullptr;
 
-#if !JVET_Z0047_FG_IMPROVEMENT   // to be deleted - unused function
-  int  denoise                      (Picture* pic);
-#endif
   void findMask                     ();
 
   void estimate_grain_parameters    ();
-- 
GitLab