1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
|
/*
* Copyright (c) 2016, Alliance for Open Media. All rights reserved.
*
* This source code is subject to the terms of the BSD 2 Clause License and
* the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
* was not distributed with this source code in the LICENSE file, you can
* obtain it at www.aomedia.org/license/software. If the Alliance for Open
* Media Patent License 1.0 was not distributed with this source code in the
* PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/
#ifndef AOM_AV1_COMMON_QUANT_COMMON_H_
#define AOM_AV1_COMMON_QUANT_COMMON_H_
#include <stdbool.h>
#include "aom/aom_codec.h"
#include "av1/common/seg_common.h"
#include "av1/common/enums.h"
#include "av1/common/entropy.h"
#ifdef __cplusplus
extern "C" {
#endif
#define MINQ 0
#define MAXQ 255
#define QINDEX_RANGE (MAXQ - MINQ + 1)
#define QINDEX_BITS 8
// Total number of QM sets stored
#define QM_LEVEL_BITS 4
#define NUM_QM_LEVELS (1 << QM_LEVEL_BITS)
/* Range of QMS is between first and last value, with offset applied to inter
* blocks*/
#define DEFAULT_QM_Y 10
#define DEFAULT_QM_U 11
#define DEFAULT_QM_V 12
#define DEFAULT_QM_FIRST 5
#define DEFAULT_QM_LAST 9
#define DEFAULT_QM_FIRST_ALLINTRA 4
#define DEFAULT_QM_LAST_ALLINTRA 10
#define QM_FIRST_IQ_SSIMULACRA2 2
#define QM_LAST_IQ_SSIMULACRA2 10
#define LOSSLESS_Q_STEP 4 // this should equal to dc/ac_qlookup_QTX[0]
struct AV1Common;
struct CommonQuantParams;
struct macroblockd;
int16_t av1_dc_quant_QTX(int qindex, int delta, aom_bit_depth_t bit_depth);
int16_t av1_ac_quant_QTX(int qindex, int delta, aom_bit_depth_t bit_depth);
int av1_get_qindex(const struct segmentation *seg, int segment_id,
int base_qindex);
// Returns true if we are using quantization matrix.
bool av1_use_qmatrix(const struct CommonQuantParams *quant_params,
const struct macroblockd *xd, int segment_id);
// Reduce the large number of quantizers to a smaller number of levels for which
// different matrices may be defined. This is an increasing function in qindex.
static inline int aom_get_qmlevel(int qindex, int first, int last) {
return first + (qindex * (last + 1 - first)) / QINDEX_RANGE;
}
// QM levels tuned for all intra mode (including still images)
// This formula was empirically derived by encoding the CID22 validation
// testset for each QP/QM tuple, and building a convex hull that
// maximizes SSIMULACRA 2 scores, and a final subjective visual quality pass
// as a quick validation. This is a decreasing function in qindex.
// There are a total of 16 luma QM levels, and the higher the level, the
// flatter these QMs are.
// QM level 15 is a completely-flat matrix and level 0 is the steepest.
// This formula only uses levels 4 through 10, unless qm-min and qm-max are
// both set below or above this range.
// For more information on quantization matrices, please refer to
// https://arxiv.org/pdf/2008.06091, section F.
static inline int aom_get_qmlevel_allintra(int qindex, int first, int last) {
int qm_level = 0;
if (qindex <= 40) {
qm_level = 10;
} else if (qindex <= 100) {
qm_level = 9;
} else if (qindex <= 160) {
qm_level = 8;
} else if (qindex <= 200) {
qm_level = 7;
} else if (qindex <= 220) {
qm_level = 6;
} else if (qindex <= 240) {
qm_level = 5;
} else {
qm_level = 4;
}
return clamp(qm_level, first, last);
}
// Luma QM levels tuned for SSIMULACRA 2
// This formula was empirically derived by encoding Daala's subset1 validation
// testset for each QP/QM tuple, and building a convex hull that maximizes
// SSIMULACRA 2 scores, and a final subjective visual quality pass as a quick
// validation. This is a decreasing function in qindex.
// There are a total of 16 luma QM levels, and the higher the level, the
// flatter these QMs are.
// QM level 15 is a completely-flat matrix and level 0 is the steepest.
// This formula only uses levels 2 through 10, unless qm-min and qm-max are
// both set below or above this range.
// For more information on quantization matrices, please refer to
// https://arxiv.org/pdf/2008.06091, section F.
static inline int aom_get_qmlevel_luma_ssimulacra2(int qindex, int first,
int last) {
int qm_level = 0;
if (qindex <= 40) {
qm_level = 10;
} else if (qindex <= 60) {
qm_level = 9;
} else if (qindex <= 100) {
qm_level = 8;
} else if (qindex <= 120) {
qm_level = 7;
} else if (qindex <= 140) {
qm_level = 6;
} else if (qindex <= 160) {
qm_level = 5;
} else if (qindex <= 200) {
qm_level = 4;
} else if (qindex <= 220) {
qm_level = 3;
} else {
qm_level = 2;
}
return clamp(qm_level, first, last);
}
// Chroma QM levels for 4:4:4 subsampling used for SSIMULACRA 2 and IQ tunings
// This formula was empirically derived by encoding Daala's subset1 validation
// testset for each QP/QM tuple, and building a convex hull that maximizes
// SSIMULACRA 2 scores, and a final subjective visual quality pass as a quick
// validation. This is a decreasing function in qindex.
// Like with luma QMs, there are a total of 16 chroma QM levels, and the higher
// the level, the flatter these QMs are.
// QM level 15 is a completely-flat matrix and level 0 is the steepest.
// This formula only uses levels 2 through 10, unless qm-min and qm-max are
// both set below or above this range.
// For more information on quantization matrices, please refer to
// https://arxiv.org/pdf/2008.06091, section F.
static inline int aom_get_qmlevel_444_chroma(int qindex, int first, int last) {
int chroma_qm_level = 0;
if (qindex <= 12) {
chroma_qm_level = 10;
} else if (qindex <= 24) {
chroma_qm_level = 9;
} else if (qindex <= 32) {
chroma_qm_level = 8;
} else if (qindex <= 36) {
chroma_qm_level = 7;
} else if (qindex <= 44) {
chroma_qm_level = 6;
} else if (qindex <= 48) {
chroma_qm_level = 5;
} else if (qindex <= 56) {
chroma_qm_level = 4;
} else if (qindex <= 88) {
chroma_qm_level = 3;
} else {
chroma_qm_level = 2;
}
return clamp(chroma_qm_level, first, last);
}
// Initialize all global quant/dequant matrices.
void av1_qm_init(struct CommonQuantParams *quant_params, int num_planes);
// Get either local / global dequant matrix as appropriate.
const qm_val_t *av1_get_iqmatrix(const struct CommonQuantParams *quant_params,
const struct macroblockd *xd, int plane,
TX_SIZE tx_size, TX_TYPE tx_type);
// Get either local / global quant matrix as appropriate.
const qm_val_t *av1_get_qmatrix(const struct CommonQuantParams *quant_params,
const struct macroblockd *xd, int plane,
TX_SIZE tx_size, TX_TYPE tx_type);
#ifdef __cplusplus
} // extern "C"
#endif
#endif // AOM_AV1_COMMON_QUANT_COMMON_H_
|