tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

av1_quantize.h (8794B)


      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 <stdbool.h>
     16 
     17 #include "config/aom_config.h"
     18 
     19 #include "aom/aomcx.h"
     20 #include "av1/common/quant_common.h"
     21 #include "av1/common/scan.h"
     22 #include "av1/encoder/block.h"
     23 
     24 #ifdef __cplusplus
     25 extern "C" {
     26 #endif
     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  int use_optimize_b;
     35  int xform_quant_idx;
     36 } QUANT_PARAM;
     37 
     38 typedef void (*AV1_QUANT_FACADE)(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
     39                                 const MACROBLOCK_PLANE *p,
     40                                 tran_low_t *qcoeff_ptr,
     41                                 tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr,
     42                                 const SCAN_ORDER *sc,
     43                                 const QUANT_PARAM *qparam);
     44 
     45 // The QUANTS structure is used only for internal quantizer setup in
     46 // av1_quantize.c.
     47 // All of its fields use the same coefficient shift/scaling at TX.
     48 typedef struct {
     49  // 0: dc 1: ac 2-8: ac repeated to SIMD width
     50  DECLARE_ALIGNED(16, int16_t, y_quant[QINDEX_RANGE][8]);
     51  DECLARE_ALIGNED(16, int16_t, y_quant_shift[QINDEX_RANGE][8]);
     52  DECLARE_ALIGNED(16, int16_t, y_zbin[QINDEX_RANGE][8]);
     53  DECLARE_ALIGNED(16, int16_t, y_round[QINDEX_RANGE][8]);
     54 
     55  // TODO(jingning): in progress of re-working the quantization. will decide
     56  // if we want to deprecate the current use of y_quant.
     57  DECLARE_ALIGNED(16, int16_t, y_quant_fp[QINDEX_RANGE][8]);
     58  DECLARE_ALIGNED(16, int16_t, u_quant_fp[QINDEX_RANGE][8]);
     59  DECLARE_ALIGNED(16, int16_t, v_quant_fp[QINDEX_RANGE][8]);
     60  DECLARE_ALIGNED(16, int16_t, y_round_fp[QINDEX_RANGE][8]);
     61  DECLARE_ALIGNED(16, int16_t, u_round_fp[QINDEX_RANGE][8]);
     62  DECLARE_ALIGNED(16, int16_t, v_round_fp[QINDEX_RANGE][8]);
     63 
     64  DECLARE_ALIGNED(16, int16_t, u_quant[QINDEX_RANGE][8]);
     65  DECLARE_ALIGNED(16, int16_t, v_quant[QINDEX_RANGE][8]);
     66  DECLARE_ALIGNED(16, int16_t, u_quant_shift[QINDEX_RANGE][8]);
     67  DECLARE_ALIGNED(16, int16_t, v_quant_shift[QINDEX_RANGE][8]);
     68  DECLARE_ALIGNED(16, int16_t, u_zbin[QINDEX_RANGE][8]);
     69  DECLARE_ALIGNED(16, int16_t, v_zbin[QINDEX_RANGE][8]);
     70  DECLARE_ALIGNED(16, int16_t, u_round[QINDEX_RANGE][8]);
     71  DECLARE_ALIGNED(16, int16_t, v_round[QINDEX_RANGE][8]);
     72 } QUANTS;
     73 
     74 // The Dequants structure is used only for internal quantizer setup in
     75 // av1_quantize.c.
     76 // Fields are suffixed according to whether or not they're expressed in
     77 // the same coefficient shift/precision as TX or a fixed Q3 format.
     78 typedef struct {
     79  DECLARE_ALIGNED(16, int16_t,
     80                  y_dequant_QTX[QINDEX_RANGE][8]);  // 8: SIMD width
     81  DECLARE_ALIGNED(16, int16_t,
     82                  u_dequant_QTX[QINDEX_RANGE][8]);  // 8: SIMD width
     83  DECLARE_ALIGNED(16, int16_t,
     84                  v_dequant_QTX[QINDEX_RANGE][8]);  // 8: SIMD width
     85 } Dequants;
     86 
     87 // The DeltaQuantParams structure holds the dc/ac deltaq parameters.
     88 typedef struct {
     89  int y_dc_delta_q;
     90  int u_dc_delta_q;
     91  int u_ac_delta_q;
     92  int v_dc_delta_q;
     93  int v_ac_delta_q;
     94  int sharpness;
     95 } DeltaQuantParams;
     96 
     97 typedef struct {
     98  // Quantization parameters for internal quantizer setup.
     99  QUANTS quants;
    100  // Dequantization parameters for internal quantizer setup.
    101  Dequants dequants;
    102  // Deltaq parameters to track the state of the dc/ac deltaq parameters in
    103  // cm->quant_params. It is used to decide whether the quantizer tables need
    104  // to be re-initialized.
    105  DeltaQuantParams prev_deltaq_params;
    106 } EncQuantDequantParams;
    107 
    108 struct AV1_COMP;
    109 struct AV1Common;
    110 
    111 void av1_frame_init_quantizer(struct AV1_COMP *cpi);
    112 
    113 void av1_init_plane_quantizers(const struct AV1_COMP *cpi, MACROBLOCK *x,
    114                               int segment_id, const int do_update);
    115 
    116 void av1_build_quantizer(aom_bit_depth_t bit_depth, int y_dc_delta_q,
    117                         int u_dc_delta_q, int u_ac_delta_q, int v_dc_delta_q,
    118                         int v_ac_delta_q, QUANTS *const quants,
    119                         Dequants *const deq, int sharpness);
    120 
    121 void av1_init_quantizer(EncQuantDequantParams *const enc_quant_dequant_params,
    122                        CommonQuantParams *quant_params,
    123                        aom_bit_depth_t bit_depth, int sharpness);
    124 
    125 void av1_set_quantizer(struct AV1Common *const cm, int min_qmlevel,
    126                       int max_qmlevel, int q, int enable_chroma_deltaq,
    127                       int enable_hdr_deltaq, bool is_allintra,
    128                       aom_tune_metric tuning);
    129 
    130 int av1_quantizer_to_qindex(int quantizer);
    131 
    132 int av1_qindex_to_quantizer(int qindex);
    133 
    134 void av1_quantize_skip(intptr_t n_coeffs, tran_low_t *qcoeff_ptr,
    135                       tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr);
    136 
    137 /*!\brief Quantize transform coefficients without using qmatrix
    138 *
    139 * quant_ptr, dequant_ptr and round_ptr are size 2 arrays,
    140 * where index 0 corresponds to dc coeff and index 1 corresponds to ac coeffs.
    141 *
    142 * \param[in]  quant_ptr    16-bit fixed point representation of inverse
    143 *                          quantize step size, i.e. 2^16/dequant
    144 * \param[in]  dequant_ptr  quantize step size
    145 * \param[in]  round_ptr    rounding
    146 * \param[in]  log_scale    the relative log scale of the transform
    147 *                          coefficients
    148 * \param[in]  scan         scan[i] indicates the position of ith to-be-coded
    149 *                          coefficient
    150 * \param[in]  coeff_count  number of coefficients
    151 * \param[out] qcoeff_ptr   quantized coefficients
    152 * \param[out] dqcoeff_ptr  dequantized coefficients
    153 *
    154 * \return The last non-zero coefficient's scan index plus 1
    155 */
    156 int av1_quantize_fp_no_qmatrix(const int16_t quant_ptr[2],
    157                               const int16_t dequant_ptr[2],
    158                               const int16_t round_ptr[2], int log_scale,
    159                               const int16_t *scan, int coeff_count,
    160                               const tran_low_t *coeff_ptr,
    161                               tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr);
    162 
    163 void av1_quantize_fp_facade(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
    164                            const MACROBLOCK_PLANE *p, tran_low_t *qcoeff_ptr,
    165                            tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr,
    166                            const SCAN_ORDER *sc, const QUANT_PARAM *qparam);
    167 
    168 void av1_quantize_b_facade(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
    169                           const MACROBLOCK_PLANE *p, tran_low_t *qcoeff_ptr,
    170                           tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr,
    171                           const SCAN_ORDER *sc, const QUANT_PARAM *qparam);
    172 
    173 void av1_quantize_dc_facade(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
    174                            const MACROBLOCK_PLANE *p, tran_low_t *qcoeff_ptr,
    175                            tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr,
    176                            const SCAN_ORDER *sc, const QUANT_PARAM *qparam);
    177 
    178 #if CONFIG_AV1_HIGHBITDEPTH
    179 void av1_highbd_quantize_fp_facade(const tran_low_t *coeff_ptr,
    180                                   intptr_t n_coeffs, const MACROBLOCK_PLANE *p,
    181                                   tran_low_t *qcoeff_ptr,
    182                                   tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr,
    183                                   const SCAN_ORDER *sc,
    184                                   const QUANT_PARAM *qparam);
    185 
    186 void av1_highbd_quantize_b_facade(const tran_low_t *coeff_ptr,
    187                                  intptr_t n_coeffs, const MACROBLOCK_PLANE *p,
    188                                  tran_low_t *qcoeff_ptr,
    189                                  tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr,
    190                                  const SCAN_ORDER *sc,
    191                                  const QUANT_PARAM *qparam);
    192 
    193 void av1_highbd_quantize_dc_facade(const tran_low_t *coeff_ptr,
    194                                   intptr_t n_coeffs, const MACROBLOCK_PLANE *p,
    195                                   tran_low_t *qcoeff_ptr,
    196                                   tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr,
    197                                   const SCAN_ORDER *sc,
    198                                   const QUANT_PARAM *qparam);
    199 
    200 #endif
    201 
    202 #ifdef __cplusplus
    203 }  // extern "C"
    204 #endif
    205 
    206 #endif  // AOM_AV1_ENCODER_AV1_QUANTIZE_H_