Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 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. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 12 | #ifndef AV1_COMMON_QUANT_COMMON_H_ |
| 13 | #define AV1_COMMON_QUANT_COMMON_H_ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 14 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 15 | #include "aom/aom_codec.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 16 | #include "av1/common/seg_common.h" |
| 17 | #include "av1/common/enums.h" |
Debargha Mukherjee | 3c42c09 | 2016-09-29 09:17:36 -0700 | [diff] [blame] | 18 | #include "av1/common/entropy.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 19 | |
| 20 | #ifdef __cplusplus |
| 21 | extern "C" { |
| 22 | #endif |
| 23 | |
| 24 | #define MINQ 0 |
| 25 | #define MAXQ 255 |
| 26 | #define QINDEX_RANGE (MAXQ - MINQ + 1) |
| 27 | #define QINDEX_BITS 8 |
| 28 | #if CONFIG_AOM_QM |
| 29 | // Total number of QM sets stored |
| 30 | #define QM_LEVEL_BITS 4 |
| 31 | #define NUM_QM_LEVELS (1 << QM_LEVEL_BITS) |
Thomas Davies | 6675adf | 2017-05-04 17:39:21 +0100 | [diff] [blame^] | 32 | /* Range of QMS is between first and last value, with offset applied to inter |
| 33 | * blocks*/ |
| 34 | #define DEFAULT_QM_FIRST 5 |
| 35 | #define DEFAULT_QM_LAST 9 |
| 36 | #define DEFAULT_QM_INTER_OFFSET 0 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 37 | #endif |
| 38 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 39 | struct AV1Common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 40 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 41 | int16_t av1_dc_quant(int qindex, int delta, aom_bit_depth_t bit_depth); |
| 42 | int16_t av1_ac_quant(int qindex, int delta, aom_bit_depth_t bit_depth); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 43 | int16_t av1_qindex_from_ac(int ac, aom_bit_depth_t bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 44 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 45 | int av1_get_qindex(const struct segmentation *seg, int segment_id, |
| 46 | int base_qindex); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 47 | #if CONFIG_AOM_QM |
| 48 | // Reduce the large number of quantizers to a smaller number of levels for which |
| 49 | // different matrices may be defined |
Debargha Mukherjee | 3c42c09 | 2016-09-29 09:17:36 -0700 | [diff] [blame] | 50 | static INLINE int aom_get_qmlevel(int qindex, int first, int last) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 51 | int qmlevel = (qindex * (last + 1 - first) + QINDEX_RANGE / 2) / QINDEX_RANGE; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 52 | qmlevel = AOMMIN(qmlevel + first, NUM_QM_LEVELS - 1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 53 | return qmlevel; |
| 54 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 55 | void aom_qm_init(struct AV1Common *cm); |
| 56 | qm_val_t *aom_iqmatrix(struct AV1Common *cm, int qindex, int comp, |
Thomas Davies | 6675adf | 2017-05-04 17:39:21 +0100 | [diff] [blame^] | 57 | TX_SIZE tx_size, int is_intra); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 58 | qm_val_t *aom_qmatrix(struct AV1Common *cm, int qindex, int comp, |
Thomas Davies | 6675adf | 2017-05-04 17:39:21 +0100 | [diff] [blame^] | 59 | TX_SIZE tx_size, int is_intra); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 60 | #endif |
| 61 | |
| 62 | #if CONFIG_NEW_QUANT |
| 63 | |
Debargha Mukherjee | 3c42c09 | 2016-09-29 09:17:36 -0700 | [diff] [blame] | 64 | #define QUANT_PROFILES 4 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 65 | #define QUANT_RANGES 2 |
| 66 | #define NUQ_KNOTS 3 |
| 67 | |
| 68 | typedef tran_low_t dequant_val_type_nuq[NUQ_KNOTS + 1]; |
| 69 | typedef tran_low_t cuml_bins_type_nuq[NUQ_KNOTS]; |
Debargha Mukherjee | 3c42c09 | 2016-09-29 09:17:36 -0700 | [diff] [blame] | 70 | void av1_get_dequant_val_nuq(int q, int band, tran_low_t *dq, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 71 | tran_low_t *cuml_bins, int dq_off_index); |
| 72 | tran_low_t av1_dequant_abscoeff_nuq(int v, int q, const tran_low_t *dq); |
| 73 | tran_low_t av1_dequant_coeff_nuq(int v, int q, const tran_low_t *dq); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 74 | |
Debargha Mukherjee | 3c42c09 | 2016-09-29 09:17:36 -0700 | [diff] [blame] | 75 | static INLINE int qindex_to_qrange(int qindex) { |
| 76 | return (qindex < 140 ? 1 : 0); |
| 77 | } |
| 78 | |
| 79 | static INLINE int get_dq_profile_from_ctx(int qindex, int q_ctx, int is_inter, |
Debargha Mukherjee | 9324d38 | 2016-09-23 10:52:13 -0700 | [diff] [blame] | 80 | PLANE_TYPE plane_type) { |
Debargha Mukherjee | 3c42c09 | 2016-09-29 09:17:36 -0700 | [diff] [blame] | 81 | // intra/inter, Y/UV, ctx, qrange |
| 82 | static const int |
| 83 | def_dq_profile_lookup[REF_TYPES][PLANE_TYPES][COEFF_CONTEXTS0] |
| 84 | [QUANT_RANGES] = { |
| 85 | { |
| 86 | // intra |
| 87 | { { 2, 1 }, { 2, 1 }, { 2, 1 } }, // Y |
| 88 | { { 3, 1 }, { 3, 1 }, { 3, 1 } }, // UV |
| 89 | }, |
| 90 | { |
| 91 | // inter |
| 92 | { { 3, 1 }, { 2, 1 }, { 2, 1 } }, // Y |
| 93 | { { 3, 1 }, { 3, 1 }, { 3, 1 } }, // UV |
| 94 | }, |
| 95 | }; |
| 96 | if (!qindex) return 0; // lossless |
| 97 | return def_dq_profile_lookup[is_inter][plane_type][q_ctx] |
| 98 | [qindex_to_qrange(qindex)]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 99 | } |
| 100 | #endif // CONFIG_NEW_QUANT |
| 101 | |
Yushin Cho | 7a428ba | 2017-01-12 16:28:49 -0800 | [diff] [blame] | 102 | #if CONFIG_PVQ || CONFIG_DAALA_DIST |
| 103 | extern const int OD_QM8_Q4_FLAT[]; |
| 104 | extern const int OD_QM8_Q4_HVS[]; |
| 105 | #endif |
| 106 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 107 | #ifdef __cplusplus |
| 108 | } // extern "C" |
| 109 | #endif |
| 110 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 111 | #endif // AV1_COMMON_QUANT_COMMON_H_ |