1 /*
2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3 *
4 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10 */
11
12 #ifndef AOM_AV1_COMMON_QUANT_COMMON_H_
13 #define AOM_AV1_COMMON_QUANT_COMMON_H_
14
15 #include <stdbool.h>
16 #include "aom/aom_codec.h"
17 #include "av1/common/seg_common.h"
18 #include "av1/common/enums.h"
19 #include "av1/common/entropy.h"
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 #define MINQ 0
26 #define MAXQ 255
27 #define QINDEX_RANGE (MAXQ - MINQ + 1)
28 #define QINDEX_BITS 8
29 // Total number of QM sets stored
30 #define QM_LEVEL_BITS 4
31 #define NUM_QM_LEVELS (1 << QM_LEVEL_BITS)
32 /* Range of QMS is between first and last value, with offset applied to inter
33 * blocks*/
34 #define DEFAULT_QM_Y 10
35 #define DEFAULT_QM_U 11
36 #define DEFAULT_QM_V 12
37 #define DEFAULT_QM_FIRST 5
38 #define DEFAULT_QM_LAST 9
39
40 struct AV1Common;
41 struct CommonQuantParams;
42 struct macroblockd;
43
44 int16_t av1_dc_quant_QTX(int qindex, int delta, aom_bit_depth_t bit_depth);
45 int16_t av1_ac_quant_QTX(int qindex, int delta, aom_bit_depth_t bit_depth);
46
47 int av1_get_qindex(const struct segmentation *seg, int segment_id,
48 int base_qindex);
49
50 // Returns true if we are using quantization matrix.
51 bool av1_use_qmatrix(const struct CommonQuantParams *quant_params,
52 const struct macroblockd *xd, int segment_id);
53
54 // Reduce the large number of quantizers to a smaller number of levels for which
55 // different matrices may be defined
aom_get_qmlevel(int qindex,int first,int last)56 static INLINE int aom_get_qmlevel(int qindex, int first, int last) {
57 return first + (qindex * (last + 1 - first)) / QINDEX_RANGE;
58 }
59
60 // Initialize all global quant/dequant matrices.
61 void av1_qm_init(struct CommonQuantParams *quant_params, int num_planes);
62
63 // Get global dequant matrix.
64 const qm_val_t *av1_iqmatrix(const struct CommonQuantParams *quant_params,
65 int qmlevel, int plane, TX_SIZE tx_size);
66 // Get global quant matrix.
67 const qm_val_t *av1_qmatrix(const struct CommonQuantParams *quant_params,
68 int qmlevel, int plane, TX_SIZE tx_size);
69
70 // Get either local / global dequant matrix as appropriate.
71 const qm_val_t *av1_get_iqmatrix(const struct CommonQuantParams *quant_params,
72 const struct macroblockd *xd, int plane,
73 TX_SIZE tx_size, TX_TYPE tx_type);
74 // Get either local / global quant matrix as appropriate.
75 const qm_val_t *av1_get_qmatrix(const struct CommonQuantParams *quant_params,
76 const struct macroblockd *xd, int plane,
77 TX_SIZE tx_size, TX_TYPE tx_type);
78
79 #ifdef __cplusplus
80 } // extern "C"
81 #endif
82
83 #endif // AOM_AV1_COMMON_QUANT_COMMON_H_
84