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