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_ENCODER_AV1_QUANTIZE_H_ 13 #define AOM_AV1_ENCODER_AV1_QUANTIZE_H_ 14 15 #include "config/aom_config.h" 16 17 #include "av1/common/quant_common.h" 18 #include "av1/common/scan.h" 19 #include "av1/encoder/block.h" 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 #define EOB_FACTOR 325 26 #define SKIP_EOB_FACTOR_ADJUST 200 27 28 typedef struct QUANT_PARAM { 29 int log_scale; 30 TX_SIZE tx_size; 31 const qm_val_t *qmatrix; 32 const qm_val_t *iqmatrix; 33 int use_quant_b_adapt; 34 } QUANT_PARAM; 35 36 typedef void (*AV1_QUANT_FACADE)(const tran_low_t *coeff_ptr, intptr_t n_coeffs, 37 const MACROBLOCK_PLANE *p, 38 tran_low_t *qcoeff_ptr, 39 tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr, 40 const SCAN_ORDER *sc, 41 const QUANT_PARAM *qparam); 42 43 // The QUANTS structure is used only for internal quantizer setup in 44 // av1_quantize.c. 45 // All of its fields use the same coefficient shift/scaling at TX. 46 typedef struct { 47 // 0: dc 1: ac 2-8: ac repeated to SIMD width 48 DECLARE_ALIGNED(16, int16_t, y_quant[QINDEX_RANGE][8]); 49 DECLARE_ALIGNED(16, int16_t, y_quant_shift[QINDEX_RANGE][8]); 50 DECLARE_ALIGNED(16, int16_t, y_zbin[QINDEX_RANGE][8]); 51 DECLARE_ALIGNED(16, int16_t, y_round[QINDEX_RANGE][8]); 52 53 // TODO(jingning): in progress of re-working the quantization. will decide 54 // if we want to deprecate the current use of y_quant. 55 DECLARE_ALIGNED(16, int16_t, y_quant_fp[QINDEX_RANGE][8]); 56 DECLARE_ALIGNED(16, int16_t, u_quant_fp[QINDEX_RANGE][8]); 57 DECLARE_ALIGNED(16, int16_t, v_quant_fp[QINDEX_RANGE][8]); 58 DECLARE_ALIGNED(16, int16_t, y_round_fp[QINDEX_RANGE][8]); 59 DECLARE_ALIGNED(16, int16_t, u_round_fp[QINDEX_RANGE][8]); 60 DECLARE_ALIGNED(16, int16_t, v_round_fp[QINDEX_RANGE][8]); 61 62 DECLARE_ALIGNED(16, int16_t, u_quant[QINDEX_RANGE][8]); 63 DECLARE_ALIGNED(16, int16_t, v_quant[QINDEX_RANGE][8]); 64 DECLARE_ALIGNED(16, int16_t, u_quant_shift[QINDEX_RANGE][8]); 65 DECLARE_ALIGNED(16, int16_t, v_quant_shift[QINDEX_RANGE][8]); 66 DECLARE_ALIGNED(16, int16_t, u_zbin[QINDEX_RANGE][8]); 67 DECLARE_ALIGNED(16, int16_t, v_zbin[QINDEX_RANGE][8]); 68 DECLARE_ALIGNED(16, int16_t, u_round[QINDEX_RANGE][8]); 69 DECLARE_ALIGNED(16, int16_t, v_round[QINDEX_RANGE][8]); 70 } QUANTS; 71 72 // The Dequants structure is used only for internal quantizer setup in 73 // av1_quantize.c. 74 // Fields are suffixed according to whether or not they're expressed in 75 // the same coefficient shift/precision as TX or a fixed Q3 format. 76 typedef struct { 77 DECLARE_ALIGNED(16, int16_t, 78 y_dequant_QTX[QINDEX_RANGE][8]); // 8: SIMD width 79 DECLARE_ALIGNED(16, int16_t, 80 u_dequant_QTX[QINDEX_RANGE][8]); // 8: SIMD width 81 DECLARE_ALIGNED(16, int16_t, 82 v_dequant_QTX[QINDEX_RANGE][8]); // 8: SIMD width 83 DECLARE_ALIGNED(16, int16_t, y_dequant_Q3[QINDEX_RANGE][8]); // 8: SIMD width 84 DECLARE_ALIGNED(16, int16_t, u_dequant_Q3[QINDEX_RANGE][8]); // 8: SIMD width 85 DECLARE_ALIGNED(16, int16_t, v_dequant_Q3[QINDEX_RANGE][8]); // 8: SIMD width 86 } Dequants; 87 88 struct AV1_COMP; 89 struct AV1Common; 90 91 void av1_frame_init_quantizer(struct AV1_COMP *cpi); 92 93 void av1_init_plane_quantizers(const struct AV1_COMP *cpi, MACROBLOCK *x, 94 int segment_id); 95 96 void av1_build_quantizer(aom_bit_depth_t bit_depth, int y_dc_delta_q, 97 int u_dc_delta_q, int u_ac_delta_q, int v_dc_delta_q, 98 int v_ac_delta_q, QUANTS *const quants, 99 Dequants *const deq); 100 101 void av1_init_quantizer(struct AV1_COMP *cpi); 102 103 void av1_set_quantizer(struct AV1Common *cm, int q); 104 105 int av1_quantizer_to_qindex(int quantizer); 106 107 int av1_qindex_to_quantizer(int qindex); 108 109 void av1_quantize_skip(intptr_t n_coeffs, tran_low_t *qcoeff_ptr, 110 tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr); 111 112 void av1_quantize_fp_facade(const tran_low_t *coeff_ptr, intptr_t n_coeffs, 113 const MACROBLOCK_PLANE *p, tran_low_t *qcoeff_ptr, 114 tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr, 115 const SCAN_ORDER *sc, const QUANT_PARAM *qparam); 116 117 void av1_quantize_b_facade(const tran_low_t *coeff_ptr, intptr_t n_coeffs, 118 const MACROBLOCK_PLANE *p, tran_low_t *qcoeff_ptr, 119 tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr, 120 const SCAN_ORDER *sc, const QUANT_PARAM *qparam); 121 122 void av1_quantize_dc_facade(const tran_low_t *coeff_ptr, intptr_t n_coeffs, 123 const MACROBLOCK_PLANE *p, tran_low_t *qcoeff_ptr, 124 tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr, 125 const SCAN_ORDER *sc, const QUANT_PARAM *qparam); 126 127 void av1_highbd_quantize_fp_facade(const tran_low_t *coeff_ptr, 128 intptr_t n_coeffs, const MACROBLOCK_PLANE *p, 129 tran_low_t *qcoeff_ptr, 130 tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr, 131 const SCAN_ORDER *sc, 132 const QUANT_PARAM *qparam); 133 134 void av1_highbd_quantize_b_facade(const tran_low_t *coeff_ptr, 135 intptr_t n_coeffs, const MACROBLOCK_PLANE *p, 136 tran_low_t *qcoeff_ptr, 137 tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr, 138 const SCAN_ORDER *sc, 139 const QUANT_PARAM *qparam); 140 141 void av1_highbd_quantize_dc_facade(const tran_low_t *coeff_ptr, 142 intptr_t n_coeffs, const MACROBLOCK_PLANE *p, 143 tran_low_t *qcoeff_ptr, 144 tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr, 145 const SCAN_ORDER *sc, 146 const QUANT_PARAM *qparam); 147 148 #ifdef __cplusplus 149 } // extern "C" 150 #endif 151 152 #endif // AOM_AV1_ENCODER_AV1_QUANTIZE_H_ 153