[x265-commits] [x265] split ScalingList class into its own header and source file

Steve Borho steve at borho.org
Fri Jul 18 09:20:53 CEST 2014


details:   http://hg.videolan.org/x265/rev/eef6867b9c53
branches:  
changeset: 7483:eef6867b9c53
user:      Steve Borho <steve at borho.org>
date:      Fri Jul 18 02:19:55 2014 -0500
description:
split ScalingList class into its own header and source file

The PPS and SPS headers no longer have scaling list pointers, so there is no
need for it to be declared in the same header

diffstat:

 source/Lib/TLibCommon/TComTrQuant.h |    1 +
 source/common/CMakeLists.txt        |    1 +
 source/common/scalinglist.cpp       |  193 ++++++++++++++++++++++++++++++++++++
 source/common/scalinglist.h         |   79 ++++++++++++++
 source/common/slice.cpp             |  168 +-------------------------------
 source/common/slice.h               |   45 --------
 source/encoder/encoder.h            |    2 +-
 source/encoder/entropy.cpp          |    3 +-
 source/encoder/entropy.h            |    1 +
 9 files changed, 279 insertions(+), 214 deletions(-)

diffs (truncated from 578 to 300 lines):

diff -r e4199c04d78d -r eef6867b9c53 source/Lib/TLibCommon/TComTrQuant.h
--- a/source/Lib/TLibCommon/TComTrQuant.h	Fri Jul 18 02:00:19 2014 -0500
+++ b/source/Lib/TLibCommon/TComTrQuant.h	Fri Jul 18 02:19:55 2014 -0500
@@ -39,6 +39,7 @@
 #define X265_TCOMTRQUANT_H
 
 #include "common.h"
+#include "scalinglist.h"
 #include "TComYuv.h"
 #include "TComDataCU.h"
 #include "ContextTables.h"
diff -r e4199c04d78d -r eef6867b9c53 source/common/CMakeLists.txt
--- a/source/common/CMakeLists.txt	Fri Jul 18 02:00:19 2014 -0500
+++ b/source/common/CMakeLists.txt	Fri Jul 18 02:19:55 2014 -0500
@@ -148,4 +148,5 @@ add_library(common OBJECT
     slice.cpp slice.h
     lowres.cpp lowres.h
     piclist.cpp piclist.h
+    scalinglist.cpp scalinglist.h
     loopfilter.cpp)
diff -r e4199c04d78d -r eef6867b9c53 source/common/scalinglist.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/source/common/scalinglist.cpp	Fri Jul 18 02:19:55 2014 -0500
@@ -0,0 +1,193 @@
+/*****************************************************************************
+ * Copyright (C) 2014 x265 project
+ *
+ * Authors: Steve Borho <steve at borho.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
+ *
+ * This program is also available under a commercial proprietary license.
+ * For more information, contact us at license @ x265.com.
+ *****************************************************************************/
+
+#include "common.h"
+#include "TLibCommon/TComRom.h"
+#include "scalinglist.h"
+
+namespace x265 {
+// private namespace
+
+ScalingList::ScalingList()
+{
+    for (uint32_t sizeId = 0; sizeId < ScalingList::NUM_SIZES; sizeId++)
+        for (uint32_t listId = 0; listId < g_scalingListNum[sizeId]; listId++)
+            m_scalingListCoef[sizeId][listId] = new int[X265_MIN(MAX_MATRIX_COEF_NUM, (int)g_scalingListSize[sizeId])];
+}
+
+ScalingList::~ScalingList()
+{
+    for (uint32_t sizeId = 0; sizeId < ScalingList::NUM_SIZES; sizeId++)
+        for (uint32_t listId = 0; listId < g_scalingListNum[sizeId]; listId++)
+            delete [] m_scalingListCoef[sizeId][listId];
+}
+
+  
+bool ScalingList::checkPredMode(uint32_t sizeId, int listId)
+{
+    for (int predListIdx = listId; predListIdx >= 0; predListIdx--)
+    {
+        if (!memcmp(m_scalingListCoef[sizeId][listId],
+                    ((listId == predListIdx) ? getScalingListDefaultAddress(sizeId, predListIdx) : m_scalingListCoef[sizeId][predListIdx]),
+                    sizeof(int) * X265_MIN(MAX_MATRIX_COEF_NUM, (int)g_scalingListSize[sizeId])) // check value of matrix
+            && ((sizeId < SIZE_16x16) || (m_scalingListDC[sizeId][listId] == m_scalingListDC[sizeId][predListIdx]))) // check DC value
+        {
+            m_refMatrixId[sizeId][listId] = predListIdx;
+            return false;
+        }
+    }
+
+    return true;
+}
+
+/* check if use default quantization matrix
+ * returns true if default quantization matrix is used in all sizes */
+bool ScalingList::checkDefaultScalingList()
+{
+    uint32_t defaultCounter = 0;
+
+    for (uint32_t s = 0; s < ScalingList::NUM_SIZES; s++)
+        for (uint32_t l = 0; l < g_scalingListNum[s]; l++)
+            if (!memcmp(m_scalingListCoef[s][l], getScalingListDefaultAddress(s, l),
+                        sizeof(int) * X265_MIN(MAX_MATRIX_COEF_NUM, (int)g_scalingListSize[s])) &&
+                ((s < SIZE_16x16) || (m_scalingListDC[s][l] == 16)))
+                defaultCounter++;
+
+    return (defaultCounter == (NUM_LISTS * ScalingList::NUM_SIZES - 4)) ? false : true; // -4 for 32x32
+}
+
+/* get address of default quantization matrix */
+int32_t* ScalingList::getScalingListDefaultAddress(uint32_t sizeId, uint32_t listId)
+{
+    switch (sizeId)
+    {
+    case SIZE_4x4:
+        return g_quantTSDefault4x4;
+    case SIZE_8x8:
+        return (listId < 3) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8;
+    case SIZE_16x16:
+        return (listId < 3) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8;
+    case SIZE_32x32:
+        return (listId < 1) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8;
+    default:
+        break;
+    }
+
+    X265_CHECK(0, "invalid scaling list size\n");
+    return NULL;
+}
+
+void ScalingList::processDefaultMarix(uint32_t sizeId, uint32_t listId)
+{
+    ::memcpy(m_scalingListCoef[sizeId][listId], getScalingListDefaultAddress(sizeId, listId), sizeof(int) * X265_MIN(MAX_MATRIX_COEF_NUM, (int)g_scalingListSize[sizeId]));
+    m_scalingListDC[sizeId][listId] = SCALING_LIST_DC;
+}
+
+void ScalingList::setDefaultScalingList()
+{
+    for (uint32_t sizeId = 0; sizeId < ScalingList::NUM_SIZES; sizeId++)
+        for (uint32_t listId = 0; listId < g_scalingListNum[sizeId]; listId++)
+            processDefaultMarix(sizeId, listId);
+}
+
+bool ScalingList::parseScalingList(char* filename)
+{
+    FILE *fp;
+    char line[1024];
+    uint32_t sizeIdc, listIdc;
+    uint32_t i, size = 0;
+    int32_t *src = 0, data;
+    char *ret;
+    uint32_t  retval;
+
+    if ((fp = fopen(filename, "r")) == (FILE*)NULL)
+    {
+        printf("can't open file %s :: set Default Matrix\n", filename);
+        return true;
+    }
+
+    for (sizeIdc = 0; sizeIdc < ScalingList::NUM_SIZES; sizeIdc++)
+    {
+        size = X265_MIN(MAX_MATRIX_COEF_NUM, (int)g_scalingListSize[sizeIdc]);
+        for (listIdc = 0; listIdc < g_scalingListNum[sizeIdc]; listIdc++)
+        {
+            src = m_scalingListCoef[sizeIdc][listIdc];
+
+            fseek(fp, 0, 0);
+            do
+            {
+                ret = fgets(line, 1024, fp);
+                if ((ret == NULL) || (strstr(line, MatrixType[sizeIdc][listIdc]) == NULL && feof(fp)))
+                {
+                    printf("Error: can't read Matrix :: set Default Matrix\n");
+                    return true;
+                }
+            }
+            while (strstr(line, MatrixType[sizeIdc][listIdc]) == NULL);
+            for (i = 0; i < size; i++)
+            {
+                retval = fscanf(fp, "%d,", &data);
+                if (retval != 1)
+                {
+                    printf("Error: can't read Matrix :: set Default Matrix\n");
+                    return true;
+                }
+                src[i] = data;
+            }
+
+            // set DC value for default matrix check
+            m_scalingListDC[sizeIdc][listIdc] = src[0];
+
+            if (sizeIdc > SIZE_8x8)
+            {
+                fseek(fp, 0, 0);
+                do
+                {
+                    ret = fgets(line, 1024, fp);
+                    if ((ret == NULL) || (strstr(line, MatrixType_DC[sizeIdc][listIdc]) == NULL && feof(fp)))
+                    {
+                        printf("Error: can't read DC :: set Default Matrix\n");
+                        return true;
+                    }
+                }
+                while (strstr(line, MatrixType_DC[sizeIdc][listIdc]) == NULL);
+                retval = fscanf(fp, "%d,", &data);
+                if (retval != 1)
+                {
+                    printf("Error: can't read Matrix :: set Default Matrix\n");
+                    return true;
+                }
+                // overwrite DC value when size of matrix is larger than 16x16
+                m_scalingListDC[sizeIdc][listIdc] = data;
+            }
+        }
+    }
+
+    fclose(fp);
+    return false;
+}
+
+const uint32_t g_scalingListSize[4] = { 16, 64, 256, 1024 };
+const uint32_t g_scalingListSizeX[4] = { 4, 8, 16, 32 };
+const uint32_t g_scalingListNum[ScalingList::NUM_SIZES] = { 6, 6, 6, 6 };
+}
\ No newline at end of file
diff -r e4199c04d78d -r eef6867b9c53 source/common/scalinglist.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/source/common/scalinglist.h	Fri Jul 18 02:19:55 2014 -0500
@@ -0,0 +1,79 @@
+/*****************************************************************************
+ * Copyright (C) 2014 x265 project
+ *
+ * Authors: Steve Borho <steve at borho.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
+ *
+ * This program is also available under a commercial proprietary license.
+ * For more information, contact us at license @ x265.com.
+ *****************************************************************************/
+
+#ifndef X265_SCALINGLIST_H
+#define X265_SCALINGLIST_H
+
+#include "common.h"
+
+namespace x265 {
+// private namespace
+
+class ScalingList
+{
+public:
+
+    static const int NUM_LISTS = 6;            // list number for quantization matrix
+    static const int NUM_REM = 6;              // remainder of QP/6
+    static const int START_VALUE = 8;          // start value for dpcm mode
+    static const int MAX_MATRIX_COEF_NUM = 64; // max coefficient number for quantization matrix
+    static const int MAX_MATRIX_SIZE_NUM = 8;  // max size number for quantization matrix
+
+    enum Size
+    {
+        SIZE_4x4 = 0,
+        SIZE_8x8,
+        SIZE_16x16,
+        SIZE_32x32,
+        NUM_SIZES
+    };
+
+    uint32_t m_refMatrixId[NUM_SIZES][NUM_LISTS];     // used during coding
+    int      m_scalingListDC[NUM_SIZES][NUM_LISTS];   // the DC value of the matrix coefficient for 16x16
+    int     *m_scalingListCoef[NUM_SIZES][NUM_LISTS]; // quantization matrix
+    bool     m_bEnabled;
+    bool     m_bDataPresent; // non-default scaling lists must be signaled
+
+    ScalingList();
+    ~ScalingList();
+
+    bool     checkDefaultScalingList();
+    void     setDefaultScalingList();
+    bool     checkPredMode(uint32_t sizeId, int listId);
+    bool     parseScalingList(char* filename);
+
+protected:
+
+    static const int SCALING_LIST_DC = 16;    // default DC value
+
+    int32_t* getScalingListDefaultAddress(uint32_t sizeId, uint32_t listId);
+    void     processDefaultMarix(uint32_t sizeId, uint32_t listId);
+};
+
+extern const uint32_t g_scalingListSize[ScalingList::NUM_SIZES];
+extern const uint32_t g_scalingListSizeX[ScalingList::NUM_SIZES];
+extern const uint32_t g_scalingListNum[ScalingList::NUM_SIZES];
+
+}
+


More information about the x265-commits mailing list