From 1f01ec57d36623b6ceedd3f5af51a2e4a1049c89 Mon Sep 17 00:00:00 2001
From: Jonathan Taquet <jonathan.taquet@crf.canon.fr>
Date: Fri, 26 Jul 2019 16:17:32 +0000
Subject: [PATCH] move AlfSliceParam from TypeDef.h to new AlfParameters.h

---
 source/Lib/CommonLib/AlfParameters.h | 215 +++++++++++++++++++++++++++
 source/Lib/CommonLib/CommonDef.h     |   7 +
 source/Lib/CommonLib/Slice.h         |   1 +
 source/Lib/CommonLib/TypeDef.h       | 173 ---------------------
 4 files changed, 223 insertions(+), 173 deletions(-)
 create mode 100644 source/Lib/CommonLib/AlfParameters.h

diff --git a/source/Lib/CommonLib/AlfParameters.h b/source/Lib/CommonLib/AlfParameters.h
new file mode 100644
index 0000000000..7c0e768ad4
--- /dev/null
+++ b/source/Lib/CommonLib/AlfParameters.h
@@ -0,0 +1,215 @@
+/* The copyright in this software is being made available under the BSD
+ * License, included below. This software may be subject to other third party
+ * and contributor rights, including patent rights, and no such rights are
+ * granted under this license.
+ *
+ * Copyright (c) 2010-2019, ITU/ISO/IEC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *  * Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
+ *    be used to endorse or promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** \file     AlfParameters.h
+    \brief    Define types for storing ALF parameters
+*/
+
+#ifndef __ALFPARAMETERS__
+#define __ALFPARAMETERS__
+
+#include <vector>
+#include "CommonDef.h"
+
+//! \ingroup AlfParameters
+//! \{
+
+enum AlfFilterType
+{
+  ALF_FILTER_5,
+  ALF_FILTER_7,
+  ALF_NUM_OF_FILTER_TYPES
+};
+
+struct AlfFilterShape
+{
+  AlfFilterShape( int size )
+    : filterLength( size ),
+    numCoeff( size * size / 4 + 1 ),
+    filterSize( size * size / 2 + 1 )
+  {
+    if( size == 5 )
+    {
+      pattern = {
+                 0,
+             1,  2,  3,
+         4,  5,  6,  5,  4,
+             3,  2,  1,
+                 0
+      };
+
+      weights = {
+                 2,
+              2, 2, 2,
+           2, 2, 1, 1
+      };
+#if !JVET_O0216_ALF_COEFF_EG3 || !JVET_O0064_SIMP_ALF_CLIP_CODING
+      golombIdx = {
+                 0,
+              0, 1, 0,
+           0, 1, 2, 2
+      };
+#endif
+
+      filterType = ALF_FILTER_5;
+    }
+    else if( size == 7 )
+    {
+      pattern = {
+                     0,
+                 1,  2,  3,
+             4,  5,  6,  7,  8,
+         9, 10, 11, 12, 11, 10, 9,
+             8,  7,  6,  5,  4,
+                 3,  2,  1,
+                     0
+      };
+
+      weights = {
+                    2,
+                2,  2,  2,
+            2,  2,  2,  2,  2,
+        2,  2,  2,  1,  1
+      };
+#if !JVET_O0216_ALF_COEFF_EG3 || !JVET_O0064_SIMP_ALF_CLIP_CODING
+      golombIdx = {
+                    0,
+                 0, 1, 0,
+              0, 1, 2, 1, 0,
+           0, 1, 2, 3, 3
+      };
+#endif
+
+      filterType = ALF_FILTER_7;
+    }
+    else
+    {
+      filterType = ALF_NUM_OF_FILTER_TYPES;
+      CHECK( 0, "Wrong ALF filter shape" );
+    }
+  }
+
+  AlfFilterType filterType;
+  int filterLength;
+  int numCoeff;      //TO DO: check whether we need both numCoeff and filterSize
+  int filterSize;
+  std::vector<int> pattern;
+  std::vector<int> weights;
+#if !JVET_O0216_ALF_COEFF_EG3 || !JVET_O0064_SIMP_ALF_CLIP_CODING
+  std::vector<int> golombIdx;
+#endif
+};
+
+struct AlfParam
+{
+  bool                         enabledFlag[MAX_NUM_COMPONENT];                          // alf_slice_enable_flag, alf_chroma_idc
+  bool                         nonLinearFlag[MAX_NUM_CHANNEL_TYPE];                     // alf_nonlinear_enable_flag[Luma/Chroma]
+  short                        lumaCoeff[MAX_NUM_ALF_CLASSES * MAX_NUM_ALF_LUMA_COEFF]; // alf_coeff_luma_delta[i][j]
+  short                        lumaClipp[MAX_NUM_ALF_CLASSES * MAX_NUM_ALF_LUMA_COEFF]; // alf_clipp_luma_[i][j]
+  short                        chromaCoeff[MAX_NUM_ALF_CHROMA_COEFF];                   // alf_coeff_chroma[i]
+  short                        chromaClipp[MAX_NUM_ALF_CHROMA_COEFF];                   // alf_clipp_chroma[i]
+  short                        filterCoeffDeltaIdx[MAX_NUM_ALF_CLASSES];                // filter_coeff_delta[i]
+  bool                         alfLumaCoeffFlag[MAX_NUM_ALF_CLASSES];                   // alf_luma_coeff_flag[i]
+  int                          numLumaFilters;                                          // number_of_filters_minus1 + 1
+  bool                         alfLumaCoeffDeltaFlag;                                   // alf_luma_coeff_delta_flag
+#if !JVET_O0669_REMOVE_ALF_COEFF_PRED
+  bool                         alfLumaCoeffDeltaPredictionFlag;                         // alf_luma_coeff_delta_prediction_flag
+#endif
+  std::vector<AlfFilterShape>* filterShapes;
+  int                          tLayer;
+  bool                         newFilterFlag[MAX_NUM_CHANNEL_TYPE];
+#if !JVET_O0669_REMOVE_ALF_COEFF_PRED
+  int                          fixedFilterPattern;
+  int                          fixedFilterIdx[MAX_NUM_ALF_CLASSES];
+  int                          fixedFilterSetIndex;
+#endif
+
+  AlfParam()
+  {
+    reset();
+  }
+
+  void reset()
+  {
+    std::memset( enabledFlag, false, sizeof( enabledFlag ) );
+    std::memset( nonLinearFlag, false, sizeof( nonLinearFlag ) );
+    std::memset( lumaCoeff, 0, sizeof( lumaCoeff ) );
+    std::memset( lumaClipp, 0, sizeof( lumaClipp ) );
+    std::memset( chromaCoeff, 0, sizeof( chromaCoeff ) );
+    std::memset( chromaClipp, 0, sizeof( chromaClipp ) );
+    std::memset( filterCoeffDeltaIdx, 0, sizeof( filterCoeffDeltaIdx ) );
+    std::memset( alfLumaCoeffFlag, true, sizeof( alfLumaCoeffFlag ) );
+    numLumaFilters = 1;
+    alfLumaCoeffDeltaFlag = false;
+#if !JVET_O0669_REMOVE_ALF_COEFF_PRED
+    alfLumaCoeffDeltaPredictionFlag = false;
+#endif
+    tLayer = 0;
+    memset(newFilterFlag, 0, sizeof(newFilterFlag));
+#if !JVET_O0669_REMOVE_ALF_COEFF_PRED
+    fixedFilterPattern = 0;
+    std::memset(fixedFilterIdx, 0, sizeof(fixedFilterIdx));
+    fixedFilterSetIndex = 0;
+#endif
+  }
+
+  const AlfParam& operator = ( const AlfParam& src )
+  {
+    std::memcpy( enabledFlag, src.enabledFlag, sizeof( enabledFlag ) );
+    std::memcpy( nonLinearFlag, src.nonLinearFlag, sizeof( nonLinearFlag ) );
+    std::memcpy( lumaCoeff, src.lumaCoeff, sizeof( lumaCoeff ) );
+    std::memcpy( lumaClipp, src.lumaClipp, sizeof( lumaClipp ) );
+    std::memcpy( chromaCoeff, src.chromaCoeff, sizeof( chromaCoeff ) );
+    std::memcpy( chromaClipp, src.chromaClipp, sizeof( chromaClipp ) );
+    std::memcpy( filterCoeffDeltaIdx, src.filterCoeffDeltaIdx, sizeof( filterCoeffDeltaIdx ) );
+    std::memcpy( alfLumaCoeffFlag, src.alfLumaCoeffFlag, sizeof( alfLumaCoeffFlag ) );
+    numLumaFilters = src.numLumaFilters;
+    alfLumaCoeffDeltaFlag = src.alfLumaCoeffDeltaFlag;
+#if !JVET_O0669_REMOVE_ALF_COEFF_PRED
+    alfLumaCoeffDeltaPredictionFlag = src.alfLumaCoeffDeltaPredictionFlag;
+#endif
+    filterShapes = src.filterShapes;
+    tLayer = src.tLayer;
+    std::memcpy(newFilterFlag, src.newFilterFlag, sizeof(newFilterFlag));
+#if !JVET_O0669_REMOVE_ALF_COEFF_PRED
+    fixedFilterPattern = src.fixedFilterPattern;
+    std::memcpy(fixedFilterIdx, src.fixedFilterIdx, sizeof(fixedFilterIdx));
+    fixedFilterSetIndex = src.fixedFilterSetIndex;
+#endif
+    return *this;
+  }
+};
+
+//! \}
+
+#endif  // end of #ifndef  __ALFPARAMETERS__
\ No newline at end of file
diff --git a/source/Lib/CommonLib/CommonDef.h b/source/Lib/CommonLib/CommonDef.h
index 36dd1f45f6..031dcc5974 100644
--- a/source/Lib/CommonLib/CommonDef.h
+++ b/source/Lib/CommonLib/CommonDef.h
@@ -176,6 +176,13 @@ static const int MAXIMUM_INTRA_FILTERED_HEIGHT =                   16;
 static const int MIP_MAX_WIDTH =                                   64;
 static const int MIP_MAX_HEIGHT =                                  64;
 
+static const int MAX_NUM_ALF_CLASSES         =                     25;
+static const int MAX_NUM_ALF_LUMA_COEFF      =                     13;
+static const int MAX_NUM_ALF_CHROMA_COEFF    =                      7;
+static const int MAX_ALF_FILTER_LENGTH       =                      7;
+static const int MAX_NUM_ALF_COEFF           =                     MAX_ALF_FILTER_LENGTH * MAX_ALF_FILTER_LENGTH / 2 + 1;
+static const int MAX_ALF_PADDING_SIZE        =                      4;
+
 static const int ALF_FIXED_FILTER_NUM        =                     64;
 static const int ALF_CTB_MAX_NUM_APS         =                      6;
 static const int NUM_FIXED_FILTER_SETS       =                     16;
diff --git a/source/Lib/CommonLib/Slice.h b/source/Lib/CommonLib/Slice.h
index a136798f31..a4f18555db 100644
--- a/source/Lib/CommonLib/Slice.h
+++ b/source/Lib/CommonLib/Slice.h
@@ -47,6 +47,7 @@
 #include "ChromaFormat.h"
 #include "Common.h"
 #include "HRD.h"
+#include "AlfParameters.h"
 
 //! \ingroup CommonLib
 //! \{
diff --git a/source/Lib/CommonLib/TypeDef.h b/source/Lib/CommonLib/TypeDef.h
index 26398d7a6e..47da5eaf43 100644
--- a/source/Lib/CommonLib/TypeDef.h
+++ b/source/Lib/CommonLib/TypeDef.h
@@ -1413,179 +1413,6 @@ struct XUCache
 
 #define SIGN(x) ( (x) >= 0 ? 1 : -1 )
 
-#define MAX_NUM_ALF_CLASSES             25
-#define MAX_NUM_ALF_LUMA_COEFF          13
-#define MAX_NUM_ALF_CHROMA_COEFF        7
-#define MAX_ALF_FILTER_LENGTH           7
-#define MAX_NUM_ALF_COEFF               (MAX_ALF_FILTER_LENGTH * MAX_ALF_FILTER_LENGTH / 2 + 1)
-#define MAX_ALF_PADDING_SIZE            4
-
-enum AlfFilterType
-{
-  ALF_FILTER_5,
-  ALF_FILTER_7,
-  ALF_NUM_OF_FILTER_TYPES
-};
-
-struct AlfFilterShape
-{
-  AlfFilterShape( int size )
-    : filterLength( size ),
-    numCoeff( size * size / 4 + 1 ),
-    filterSize( size * size / 2 + 1 )
-  {
-    if( size == 5 )
-    {
-      pattern = {
-                 0,
-             1,  2,  3,
-         4,  5,  6,  5,  4,
-             3,  2,  1,
-                 0
-      };
-
-      weights = {
-                 2,
-              2, 2, 2,
-           2, 2, 1, 1
-      };
-#if !JVET_O0216_ALF_COEFF_EG3 || !JVET_O0064_SIMP_ALF_CLIP_CODING
-      golombIdx = {
-                 0,
-              0, 1, 0,
-           0, 1, 2, 2
-      };
-#endif
-
-      filterType = ALF_FILTER_5;
-    }
-    else if( size == 7 )
-    {
-      pattern = {
-                     0,
-                 1,  2,  3,
-             4,  5,  6,  7,  8,
-         9, 10, 11, 12, 11, 10, 9,
-             8,  7,  6,  5,  4,
-                 3,  2,  1,
-                     0
-      };
-
-      weights = {
-                    2,
-                2,  2,  2,
-            2,  2,  2,  2,  2,
-        2,  2,  2,  1,  1
-      };
-#if !JVET_O0216_ALF_COEFF_EG3 || !JVET_O0064_SIMP_ALF_CLIP_CODING
-      golombIdx = {
-                    0,
-                 0, 1, 0,
-              0, 1, 2, 1, 0,
-           0, 1, 2, 3, 3
-      };
-#endif
-
-      filterType = ALF_FILTER_7;
-    }
-    else
-    {
-      filterType = ALF_NUM_OF_FILTER_TYPES;
-      CHECK( 0, "Wrong ALF filter shape" );
-    }
-  }
-
-  AlfFilterType filterType;
-  int filterLength;
-  int numCoeff;      //TO DO: check whether we need both numCoeff and filterSize
-  int filterSize;
-  std::vector<int> pattern;
-  std::vector<int> weights;
-#if !JVET_O0216_ALF_COEFF_EG3 || !JVET_O0064_SIMP_ALF_CLIP_CODING
-  std::vector<int> golombIdx;
-#endif
-};
-
-struct AlfParam
-{
-  bool                         enabledFlag[MAX_NUM_COMPONENT];                          // alf_slice_enable_flag, alf_chroma_idc
-  bool                         nonLinearFlag[MAX_NUM_CHANNEL_TYPE];                     // alf_nonlinear_enable_flag[Luma/Chroma]
-  short                        lumaCoeff[MAX_NUM_ALF_CLASSES * MAX_NUM_ALF_LUMA_COEFF]; // alf_coeff_luma_delta[i][j]
-  short                        lumaClipp[MAX_NUM_ALF_CLASSES * MAX_NUM_ALF_LUMA_COEFF]; // alf_clipp_luma_[i][j]
-  short                        chromaCoeff[MAX_NUM_ALF_CHROMA_COEFF];                   // alf_coeff_chroma[i]
-  short                        chromaClipp[MAX_NUM_ALF_CHROMA_COEFF];                   // alf_clipp_chroma[i]
-  short                        filterCoeffDeltaIdx[MAX_NUM_ALF_CLASSES];                // filter_coeff_delta[i]
-  bool                         alfLumaCoeffFlag[MAX_NUM_ALF_CLASSES];                   // alf_luma_coeff_flag[i]
-  int                          numLumaFilters;                                          // number_of_filters_minus1 + 1
-  bool                         alfLumaCoeffDeltaFlag;                                   // alf_luma_coeff_delta_flag
-#if !JVET_O0669_REMOVE_ALF_COEFF_PRED
-  bool                         alfLumaCoeffDeltaPredictionFlag;                         // alf_luma_coeff_delta_prediction_flag
-#endif
-  std::vector<AlfFilterShape>* filterShapes;
-  int                          tLayer;
-  bool                         newFilterFlag[MAX_NUM_CHANNEL_TYPE];
-#if !JVET_O0669_REMOVE_ALF_COEFF_PRED
-  int                          fixedFilterPattern;
-  int                          fixedFilterIdx[MAX_NUM_ALF_CLASSES];
-  int                          fixedFilterSetIndex;
-#endif
-
-  AlfParam()
-  {
-    reset();
-  }
-
-  void reset()
-  {
-    std::memset( enabledFlag, false, sizeof( enabledFlag ) );
-    std::memset( nonLinearFlag, false, sizeof( nonLinearFlag ) );
-    std::memset( lumaCoeff, 0, sizeof( lumaCoeff ) );
-    std::memset( lumaClipp, 0, sizeof( lumaClipp ) );
-    std::memset( chromaCoeff, 0, sizeof( chromaCoeff ) );
-    std::memset( chromaClipp, 0, sizeof( chromaClipp ) );
-    std::memset( filterCoeffDeltaIdx, 0, sizeof( filterCoeffDeltaIdx ) );
-    std::memset( alfLumaCoeffFlag, true, sizeof( alfLumaCoeffFlag ) );
-    numLumaFilters = 1;
-    alfLumaCoeffDeltaFlag = false;
-#if !JVET_O0669_REMOVE_ALF_COEFF_PRED
-    alfLumaCoeffDeltaPredictionFlag = false;
-#endif
-    tLayer = 0;
-    memset(newFilterFlag, 0, sizeof(newFilterFlag));
-#if !JVET_O0669_REMOVE_ALF_COEFF_PRED
-    fixedFilterPattern = 0;
-    std::memset(fixedFilterIdx, 0, sizeof(fixedFilterIdx));
-    fixedFilterSetIndex = 0;
-#endif
-  }
-
-  const AlfParam& operator = ( const AlfParam& src )
-  {
-    std::memcpy( enabledFlag, src.enabledFlag, sizeof( enabledFlag ) );
-    std::memcpy( nonLinearFlag, src.nonLinearFlag, sizeof( nonLinearFlag ) );
-    std::memcpy( lumaCoeff, src.lumaCoeff, sizeof( lumaCoeff ) );
-    std::memcpy( lumaClipp, src.lumaClipp, sizeof( lumaClipp ) );
-    std::memcpy( chromaCoeff, src.chromaCoeff, sizeof( chromaCoeff ) );
-    std::memcpy( chromaClipp, src.chromaClipp, sizeof( chromaClipp ) );
-    std::memcpy( filterCoeffDeltaIdx, src.filterCoeffDeltaIdx, sizeof( filterCoeffDeltaIdx ) );
-    std::memcpy( alfLumaCoeffFlag, src.alfLumaCoeffFlag, sizeof( alfLumaCoeffFlag ) );
-    numLumaFilters = src.numLumaFilters;
-    alfLumaCoeffDeltaFlag = src.alfLumaCoeffDeltaFlag;
-#if !JVET_O0669_REMOVE_ALF_COEFF_PRED
-    alfLumaCoeffDeltaPredictionFlag = src.alfLumaCoeffDeltaPredictionFlag;
-#endif
-    filterShapes = src.filterShapes;
-    tLayer = src.tLayer;
-    std::memcpy(newFilterFlag, src.newFilterFlag, sizeof(newFilterFlag));
-#if !JVET_O0669_REMOVE_ALF_COEFF_PRED
-    fixedFilterPattern = src.fixedFilterPattern;
-    std::memcpy(fixedFilterIdx, src.fixedFilterIdx, sizeof(fixedFilterIdx));
-    fixedFilterSetIndex = src.fixedFilterSetIndex;
-#endif
-    return *this;
-  }
-};
-
 //! \}
 
 #endif
-- 
GitLab