注:问号以及未注释部分 会在x265-1.9版本内更新
/*****************************************************************************
* Copyright (C) 2015 x265 project
*
* Authors: Steve Borho <steve@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_NS {
// private namespace
class ScalingList//用途:存储每个TU单元中每个点对应的量化、反量化系数 只存在于Encoder类 Quant类的只是一个指针
{
public:
enum { NUM_SIZES = 4 }; // 所有的块大小个数:4x4, 8x8, 16x16, 32x32
enum { NUM_LISTS = 6 }; // 存储方式:intra: Y U V inter Y U V number of quantization matrix lists (YUV * inter/intra)
enum { NUM_REM = 6 }; // QP模6的最大个数 number of remainders of QP/6
enum { MAX_MATRIX_COEF_NUM = 64 }; // 量化矩阵的最大系数个数 max coefficient number per quantization matrix
enum { MAX_MATRIX_SIZE_NUM = 8 }; // 量化矩阵的最大宽度 max size number for quantization matrix
static const int s_numCoefPerSize[NUM_SIZES];
static const int32_t s_invQuantScales[NUM_REM];
static const int32_t s_quantScales[NUM_REM];
int32_t m_scalingListDC[NUM_SIZES][NUM_LISTS]; //DC系数量化矩阵,默认值为16 the DC value of the matrix coefficient for 16x16
int32_t* m_scalingListCoef[NUM_SIZES][NUM_LISTS]; // 存储:量化矩阵 第一维:所有的块大小个数:0-4x4, 1-8x8, 2-16x16, 3-32x32 第二维:存储方式:intra:0- Y 1-U 2-V inter 3-Y 4-U 5-V 第三维:空间大小为当前块系数个数(最大为64)quantization matrix
int32_t* m_quantCoef[NUM_SIZES][NUM_LISTS][NUM_REM]; // 存储:对应TU块每个点的量化系数 默认:为标准规定的均匀量化系数 使用量化矩阵 为对应量化矩阵的系数 第一维:所有的块大小个数:0-4x4, 1-8x8, 2-16x16, 3-32x32 第二维:存储方式:intra:0- Y 1-U 2-V inter 3-Y 4-U 5-V 第三维:QP模6的值 第四维:空间大小为当前块系数个数 array of quantization matrix coefficient 4x4
int32_t* m_dequantCoef[NUM_SIZES][NUM_LISTS][NUM_REM]; // 存储:对应TU块每个点的反量化系数 默认:为标准规定的均匀反量化系数 使用量化矩阵 为对应反量化矩阵的系数 第一维:所有的块大小个数:0-4x4, 1-8x8, 2-16x16, 3-32x32 第二维:存储方式:intra:0- Y 1-U 2-V inter 3-Y 4-U 5-V 第三维:QP模6的值 第四维:空间大小为当前块系数个数 array of dequantization matrix coefficient 4x4
bool m_bEnabled; // 是否使用量化矩阵
bool m_bDataPresent; //应用默认量化矩阵时为false 否则为true non-default scaling lists must be signaled
/** 函数功能 : 构造函数,初始化为0
/* 调用范围 : 随encoder类创建而构造*/
ScalingList();
/** 函数功能 : 析构函数,释放内存
/* 调用范围 : 随encoder类析构而析构*/
~ScalingList();
/** 函数功能 :为量化参数申请空间,申请成功返回true 否则返回false
* 前向量化表"m_quantCoef"/反量化表"m_dequantCoef"/量化矩阵表"m_scalingListCoef"
/* 调用范围 : 只在Encoder::create()函数中被调用
* \返回值 ok : 初始化成功则返回true,否则返回false
*/
bool init();
/** 函数功能 : 设置默认的量化矩阵
** 调用范围 : 仅在Encoder::create()中被调用
*/
void setDefaultScalingList();
/** 函数功能 : 解析用户自定义的量化矩阵文件
** 调用范围 : 仅在Encoder::create()中被调用
** 返回值 : 失败返回true 成功返回false
*/
bool parseScalingList(const char* filename);
/** 函数功能 :根据不同的TU尺寸,不同的list类型,不同的量化矩阵,生成不同的量化矩阵。
** 如果m_bEnabled为true,则使用默认的量化矩阵或者从文件中读取的量化矩阵,生成新的非均匀量化矩阵。
** 如果m_bEnabled为false,则直接使用默认的量化系数得到均匀量化矩阵。
** 调用范围 : 仅在Encoder::create()中被调用
*/
void setupQuantMatrices();
/* used during SPS coding */
int checkPredMode(int sizeId, int listId) const;
protected:
static const int SCALING_LIST_DC = 16; //DC系数量化矩阵默认值 default DC value
/** 函数功能 : 根据不同的TU尺寸,不同的list类型得到不同的默认量化矩阵
* \参数 sizeId : TU尺寸的ID
* \参数 listId : list类型的ID
*/
const int32_t* getScalingListDefaultAddress(int sizeId, int listId) const;
/** 函数功能 :将默认量化矩阵中拷贝到m_scalingListCoef,用于之后的量化
* \参数 sizeId : TU尺寸的ID
* \参数 listId : list类型的ID
*/
void processDefaultMarix(int sizeId, int listId);
/** 函数功能 : 判断读取的量化矩阵是否与默认量化矩阵相同(相同false 不同 true)
** 调用范围 : 仅在ScalingList::parseScalingList中被调用
** 返回值 : 相同false 不同 true
*/
bool checkDefaultScalingList() const;
/** 函数功能 : 生成非均匀量化矩阵
** 调用范围 : 仅在ScalingList::setupQuantMatrices()中被调用
* \参数 coeff : 输入的非均匀量化矩阵
* \参数 quantcoeff : 输出的新建立的非均匀量化矩阵
* \参数 quantScales: 默认的均匀量化系数
* \参数 height : TU的高度
* \参数 width : TU的宽度
* \参数 ratio : TU尺寸与量化矩阵尺寸的比例 = TU width / min(8, TU width). 假如TU width<=8, 则ratio = 1; 假如TU height>8, ratio = TU width/8
* \参数 stride : TU的步长, = width
* \参数 dc : 输入的非均匀DC量化系数
*/
void processScalingListEnc(int32_t *coeff, int32_t *quantcoeff, int32_t quantScales, int height, int width, int ratio, int stride, int32_t dc);
/** 函数功能 : 生成非均匀反量化矩阵
** 调用范围 : 仅在ScalingList::setupQuantMatrices()中被调用
* \参数 coeff : 输入的非均匀量化矩阵
* \参数 dequantcoeff : 输出的新建立的非均匀反量化矩阵
* \参数 invQuantScales : 默认的均匀反量化系数
* \参数 height : TU的高度
* \参数 width : TU的宽度
* \参数 ratio : TU尺寸与量化矩阵尺寸的比例 = TU width / min(8, TU width). 假如TU width<=8, 则ratio = 1; 假如TU height>8, ratio = TU width/8
* \参数 stride : TU的步长, = width
* \参数 dc : 输入的非均匀DC量化系数
*/
void processScalingListDec(int32_t *coeff, int32_t *dequantcoeff, int32_t invQuantScales, int height, int width, int ratio, int stride, int32_t dc);
};
}
#endif // ifndef X265_SCALINGLIST_H