Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -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 | 9c01aa1 | 2016-09-01 14:32:49 -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 | |
| 12 | #include <math.h> |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 13 | #include "./aom_dsp_rtcd.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 14 | #include "aom_dsp/quantize.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 15 | #include "aom_mem/aom_mem.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 16 | #include "aom_ports/mem.h" |
| 17 | |
Yi Luo | 554bd72 | 2016-11-14 10:02:26 -0800 | [diff] [blame] | 18 | #include "av1/common/idct.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 19 | #include "av1/common/quant_common.h" |
| 20 | #include "av1/common/scan.h" |
| 21 | #include "av1/common/seg_common.h" |
| 22 | |
Tom Finegan | 17ce8b1 | 2017-02-08 12:46:31 -0800 | [diff] [blame] | 23 | #include "av1/encoder/av1_quantize.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 24 | #include "av1/encoder/encoder.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 25 | #include "av1/encoder/rd.h" |
| 26 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 27 | void av1_quantize_skip(intptr_t n_coeffs, tran_low_t *qcoeff_ptr, |
| 28 | tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 29 | memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr)); |
| 30 | memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr)); |
| 31 | *eob_ptr = 0; |
| 32 | } |
| 33 | |
Cheng Chen | 4c2e434 | 2017-04-20 18:10:08 -0700 | [diff] [blame] | 34 | static void quantize_fp_helper_c( |
| 35 | const tran_low_t *coeff_ptr, intptr_t n_coeffs, int skip_block, |
| 36 | const int16_t *zbin_ptr, const int16_t *round_ptr, const int16_t *quant_ptr, |
| 37 | const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr, |
| 38 | tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 39 | const int16_t *scan, const int16_t *iscan, const qm_val_t *qm_ptr, |
| 40 | const qm_val_t *iqm_ptr, int log_scale) { |
Cheng Chen | 4c2e434 | 2017-04-20 18:10:08 -0700 | [diff] [blame] | 41 | int i, eob = -1; |
| 42 | // TODO(jingning) Decide the need of these arguments after the |
| 43 | // quantization process is completed. |
| 44 | (void)zbin_ptr; |
| 45 | (void)quant_shift_ptr; |
| 46 | (void)iscan; |
Cheng Chen | 4c2e434 | 2017-04-20 18:10:08 -0700 | [diff] [blame] | 47 | |
| 48 | memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr)); |
| 49 | memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr)); |
| 50 | |
| 51 | if (!skip_block) { |
| 52 | // Quantization pass: All coefficients with index >= zero_flag are |
| 53 | // skippable. Note: zero_flag can be zero. |
| 54 | for (i = 0; i < n_coeffs; i++) { |
| 55 | const int rc = scan[i]; |
| 56 | const int coeff = coeff_ptr[rc]; |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 57 | const qm_val_t wt = qm_ptr ? qm_ptr[rc] : (1 << AOM_QM_BITS); |
| 58 | const qm_val_t iwt = iqm_ptr ? iqm_ptr[rc] : (1 << AOM_QM_BITS); |
Cheng Chen | 4c2e434 | 2017-04-20 18:10:08 -0700 | [diff] [blame] | 59 | const int dequant = |
| 60 | (dequant_ptr[rc != 0] * iwt + (1 << (AOM_QM_BITS - 1))) >> |
| 61 | AOM_QM_BITS; |
Cheng Chen | 4c2e434 | 2017-04-20 18:10:08 -0700 | [diff] [blame] | 62 | const int coeff_sign = (coeff >> 31); |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 63 | int64_t abs_coeff = (coeff ^ coeff_sign) - coeff_sign; |
Cheng Chen | 4c2e434 | 2017-04-20 18:10:08 -0700 | [diff] [blame] | 64 | int tmp32 = 0; |
Cheng Chen | 4c2e434 | 2017-04-20 18:10:08 -0700 | [diff] [blame] | 65 | if (abs_coeff * wt >= |
| 66 | (dequant_ptr[rc != 0] << (AOM_QM_BITS - (1 + log_scale)))) { |
Cheng Chen | 4c2e434 | 2017-04-20 18:10:08 -0700 | [diff] [blame] | 67 | abs_coeff += ROUND_POWER_OF_TWO(round_ptr[rc != 0], log_scale); |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 68 | abs_coeff = clamp64(abs_coeff, INT16_MIN, INT16_MAX); |
Cheng Chen | 4c2e434 | 2017-04-20 18:10:08 -0700 | [diff] [blame] | 69 | tmp32 = (int)((abs_coeff * wt * quant_ptr[rc != 0]) >> |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 70 | (16 - log_scale + AOM_QM_BITS)); |
Cheng Chen | 4c2e434 | 2017-04-20 18:10:08 -0700 | [diff] [blame] | 71 | qcoeff_ptr[rc] = (tmp32 ^ coeff_sign) - coeff_sign; |
| 72 | dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant / (1 << log_scale); |
Cheng Chen | 4c2e434 | 2017-04-20 18:10:08 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | if (tmp32) eob = i; |
| 76 | } |
| 77 | } |
| 78 | *eob_ptr = eob + 1; |
| 79 | } |
| 80 | |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 81 | static void highbd_quantize_fp_helper_c( |
| 82 | const tran_low_t *coeff_ptr, intptr_t count, int skip_block, |
| 83 | const int16_t *zbin_ptr, const int16_t *round_ptr, const int16_t *quant_ptr, |
| 84 | const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr, |
| 85 | tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, |
| 86 | const int16_t *scan, const int16_t *iscan, const qm_val_t *qm_ptr, |
| 87 | const qm_val_t *iqm_ptr, int log_scale) { |
| 88 | int i; |
| 89 | int eob = -1; |
| 90 | const int scale = 1 << log_scale; |
| 91 | const int shift = 16 - log_scale; |
| 92 | // TODO(jingning) Decide the need of these arguments after the |
| 93 | // quantization process is completed. |
| 94 | (void)zbin_ptr; |
| 95 | (void)quant_shift_ptr; |
| 96 | (void)iscan; |
| 97 | |
| 98 | memset(qcoeff_ptr, 0, count * sizeof(*qcoeff_ptr)); |
| 99 | memset(dqcoeff_ptr, 0, count * sizeof(*dqcoeff_ptr)); |
| 100 | |
| 101 | if (!skip_block) { |
| 102 | // Quantization pass: All coefficients with index >= zero_flag are |
| 103 | // skippable. Note: zero_flag can be zero. |
| 104 | for (i = 0; i < count; i++) { |
| 105 | const int rc = scan[i]; |
| 106 | const int coeff = coeff_ptr[rc]; |
| 107 | const qm_val_t wt = qm_ptr != NULL ? qm_ptr[rc] : (1 << AOM_QM_BITS); |
| 108 | const qm_val_t iwt = iqm_ptr != NULL ? iqm_ptr[rc] : (1 << AOM_QM_BITS); |
| 109 | const int dequant = |
| 110 | (dequant_ptr[rc != 0] * iwt + (1 << (AOM_QM_BITS - 1))) >> |
| 111 | AOM_QM_BITS; |
| 112 | const int coeff_sign = (coeff >> 31); |
| 113 | const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; |
| 114 | const int64_t tmp = abs_coeff + (round_ptr[rc != 0] >> log_scale); |
| 115 | const int abs_qcoeff = |
| 116 | (int)((tmp * quant_ptr[rc != 0] * wt) >> (shift + AOM_QM_BITS)); |
| 117 | qcoeff_ptr[rc] = (tran_low_t)((abs_qcoeff ^ coeff_sign) - coeff_sign); |
| 118 | dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant / scale; |
| 119 | if (abs_qcoeff) eob = i; |
| 120 | } |
| 121 | } |
| 122 | *eob_ptr = eob + 1; |
| 123 | } |
| 124 | |
Cheng Chen | 4c2e434 | 2017-04-20 18:10:08 -0700 | [diff] [blame] | 125 | void av1_quantize_fp_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, |
| 126 | int skip_block, const int16_t *zbin_ptr, |
| 127 | const int16_t *round_ptr, const int16_t *quant_ptr, |
| 128 | const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr, |
| 129 | tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, |
| 130 | uint16_t *eob_ptr, const int16_t *scan, |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 131 | const int16_t *iscan) { |
Cheng Chen | 4c2e434 | 2017-04-20 18:10:08 -0700 | [diff] [blame] | 132 | quantize_fp_helper_c(coeff_ptr, n_coeffs, skip_block, zbin_ptr, round_ptr, |
| 133 | quant_ptr, quant_shift_ptr, qcoeff_ptr, dqcoeff_ptr, |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 134 | dequant_ptr, eob_ptr, scan, iscan, NULL, NULL, 0); |
Cheng Chen | 4c2e434 | 2017-04-20 18:10:08 -0700 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | void av1_quantize_fp_32x32_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, |
| 138 | int skip_block, const int16_t *zbin_ptr, |
| 139 | const int16_t *round_ptr, const int16_t *quant_ptr, |
| 140 | const int16_t *quant_shift_ptr, |
| 141 | tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, |
| 142 | const int16_t *dequant_ptr, uint16_t *eob_ptr, |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 143 | const int16_t *scan, const int16_t *iscan) { |
Cheng Chen | 4c2e434 | 2017-04-20 18:10:08 -0700 | [diff] [blame] | 144 | quantize_fp_helper_c(coeff_ptr, n_coeffs, skip_block, zbin_ptr, round_ptr, |
| 145 | quant_ptr, quant_shift_ptr, qcoeff_ptr, dqcoeff_ptr, |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 146 | dequant_ptr, eob_ptr, scan, iscan, NULL, NULL, 1); |
Cheng Chen | 4c2e434 | 2017-04-20 18:10:08 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Cheng Chen | 4c2e434 | 2017-04-20 18:10:08 -0700 | [diff] [blame] | 149 | void av1_quantize_fp_64x64_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, |
| 150 | int skip_block, const int16_t *zbin_ptr, |
| 151 | const int16_t *round_ptr, const int16_t *quant_ptr, |
| 152 | const int16_t *quant_shift_ptr, |
| 153 | tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, |
| 154 | const int16_t *dequant_ptr, uint16_t *eob_ptr, |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 155 | const int16_t *scan, const int16_t *iscan) { |
Cheng Chen | 4c2e434 | 2017-04-20 18:10:08 -0700 | [diff] [blame] | 156 | quantize_fp_helper_c(coeff_ptr, n_coeffs, skip_block, zbin_ptr, round_ptr, |
| 157 | quant_ptr, quant_shift_ptr, qcoeff_ptr, dqcoeff_ptr, |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 158 | dequant_ptr, eob_ptr, scan, iscan, NULL, NULL, 2); |
Cheng Chen | 4c2e434 | 2017-04-20 18:10:08 -0700 | [diff] [blame] | 159 | } |
Cheng Chen | 4c2e434 | 2017-04-20 18:10:08 -0700 | [diff] [blame] | 160 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 161 | void av1_quantize_fp_facade(const tran_low_t *coeff_ptr, intptr_t n_coeffs, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 162 | const MACROBLOCK_PLANE *p, tran_low_t *qcoeff_ptr, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 163 | tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr, |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 164 | const SCAN_ORDER *sc, const QUANT_PARAM *qparam) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 165 | // obsolete skip_block |
| 166 | const int skip_block = 0; |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 167 | const qm_val_t *qm_ptr = qparam->qmatrix; |
| 168 | const qm_val_t *iqm_ptr = qparam->iqmatrix; |
Thomas Davies | 1870382 | 2017-07-21 14:39:33 +0100 | [diff] [blame] | 169 | if (qm_ptr != NULL && iqm_ptr != NULL) { |
Monty Montgomery | 125c0fc | 2017-10-26 00:44:35 -0400 | [diff] [blame] | 170 | quantize_fp_helper_c(coeff_ptr, n_coeffs, skip_block, p->zbin_QTX, |
| 171 | p->round_fp_QTX, p->quant_fp_QTX, p->quant_shift_QTX, |
| 172 | qcoeff_ptr, dqcoeff_ptr, p->dequant_QTX, eob_ptr, |
| 173 | sc->scan, sc->iscan, qm_ptr, iqm_ptr, |
| 174 | qparam->log_scale); |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 175 | } else { |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 176 | switch (qparam->log_scale) { |
| 177 | case 0: |
| 178 | if (n_coeffs < 16) { |
| 179 | // TODO(jingning): Need SIMD implementation for smaller block size |
| 180 | // quantization. |
Monty Montgomery | 125c0fc | 2017-10-26 00:44:35 -0400 | [diff] [blame] | 181 | quantize_fp_helper_c(coeff_ptr, n_coeffs, skip_block, p->zbin_QTX, |
| 182 | p->round_fp_QTX, p->quant_fp_QTX, |
| 183 | p->quant_shift_QTX, qcoeff_ptr, dqcoeff_ptr, |
| 184 | p->dequant_QTX, eob_ptr, sc->scan, sc->iscan, |
| 185 | NULL, NULL, qparam->log_scale); |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 186 | } else { |
Debargha Mukherjee | 24e3104 | 2017-11-29 20:21:15 -0800 | [diff] [blame] | 187 | if (qparam->tx_size == TX_4X16 || qparam->tx_size == TX_16X4 || |
| 188 | qparam->tx_size == TX_8X32 || qparam->tx_size == TX_32X8) |
| 189 | av1_quantize_fp_c(coeff_ptr, n_coeffs, skip_block, p->zbin_QTX, |
| 190 | p->round_fp_QTX, p->quant_fp_QTX, |
| 191 | p->quant_shift_QTX, qcoeff_ptr, dqcoeff_ptr, |
| 192 | p->dequant_QTX, eob_ptr, sc->scan, sc->iscan); |
| 193 | else |
Debargha Mukherjee | 24e3104 | 2017-11-29 20:21:15 -0800 | [diff] [blame] | 194 | av1_quantize_fp(coeff_ptr, n_coeffs, skip_block, p->zbin_QTX, |
| 195 | p->round_fp_QTX, p->quant_fp_QTX, |
| 196 | p->quant_shift_QTX, qcoeff_ptr, dqcoeff_ptr, |
| 197 | p->dequant_QTX, eob_ptr, sc->scan, sc->iscan); |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 198 | } |
| 199 | break; |
| 200 | case 1: |
Debargha Mukherjee | 3f92108 | 2017-12-01 21:45:57 -0800 | [diff] [blame] | 201 | if (qparam->tx_size == TX_16X64 || qparam->tx_size == TX_64X16) |
| 202 | av1_quantize_fp_32x32_c(coeff_ptr, n_coeffs, skip_block, p->zbin_QTX, |
| 203 | p->round_fp_QTX, p->quant_fp_QTX, |
| 204 | p->quant_shift_QTX, qcoeff_ptr, dqcoeff_ptr, |
| 205 | p->dequant_QTX, eob_ptr, sc->scan, sc->iscan); |
| 206 | else |
Debargha Mukherjee | 3f92108 | 2017-12-01 21:45:57 -0800 | [diff] [blame] | 207 | av1_quantize_fp_32x32(coeff_ptr, n_coeffs, skip_block, p->zbin_QTX, |
| 208 | p->round_fp_QTX, p->quant_fp_QTX, |
| 209 | p->quant_shift_QTX, qcoeff_ptr, dqcoeff_ptr, |
| 210 | p->dequant_QTX, eob_ptr, sc->scan, sc->iscan); |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 211 | break; |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 212 | case 2: |
Monty Montgomery | 125c0fc | 2017-10-26 00:44:35 -0400 | [diff] [blame] | 213 | av1_quantize_fp_64x64(coeff_ptr, n_coeffs, skip_block, p->zbin_QTX, |
| 214 | p->round_fp_QTX, p->quant_fp_QTX, |
| 215 | p->quant_shift_QTX, qcoeff_ptr, dqcoeff_ptr, |
| 216 | p->dequant_QTX, eob_ptr, sc->scan, sc->iscan); |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 217 | break; |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 218 | default: assert(0); |
| 219 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 220 | } |
| 221 | } |
| 222 | |
| 223 | void av1_quantize_b_facade(const tran_low_t *coeff_ptr, intptr_t n_coeffs, |
| 224 | const MACROBLOCK_PLANE *p, tran_low_t *qcoeff_ptr, |
Monty Montgomery | 125c0fc | 2017-10-26 00:44:35 -0400 | [diff] [blame] | 225 | tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr, |
| 226 | const SCAN_ORDER *sc, const QUANT_PARAM *qparam) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 227 | // obsolete skip_block |
| 228 | const int skip_block = 0; |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 229 | const qm_val_t *qm_ptr = qparam->qmatrix; |
| 230 | const qm_val_t *iqm_ptr = qparam->iqmatrix; |
Thomas Davies | 1870382 | 2017-07-21 14:39:33 +0100 | [diff] [blame] | 231 | if (qm_ptr != NULL && iqm_ptr != NULL) { |
Monty Montgomery | 125c0fc | 2017-10-26 00:44:35 -0400 | [diff] [blame] | 232 | quantize_b_helper_c(coeff_ptr, n_coeffs, skip_block, p->zbin_QTX, |
| 233 | p->round_QTX, p->quant_QTX, p->quant_shift_QTX, |
| 234 | qcoeff_ptr, dqcoeff_ptr, p->dequant_QTX, eob_ptr, |
| 235 | sc->scan, sc->iscan, qm_ptr, iqm_ptr, |
| 236 | qparam->log_scale); |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 237 | } else { |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 238 | switch (qparam->log_scale) { |
| 239 | case 0: |
Monty Montgomery | 125c0fc | 2017-10-26 00:44:35 -0400 | [diff] [blame] | 240 | aom_quantize_b(coeff_ptr, n_coeffs, skip_block, p->zbin_QTX, |
| 241 | p->round_QTX, p->quant_QTX, p->quant_shift_QTX, |
| 242 | qcoeff_ptr, dqcoeff_ptr, p->dequant_QTX, eob_ptr, |
| 243 | sc->scan, sc->iscan); |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 244 | break; |
| 245 | case 1: |
Monty Montgomery | 125c0fc | 2017-10-26 00:44:35 -0400 | [diff] [blame] | 246 | aom_quantize_b_32x32(coeff_ptr, n_coeffs, skip_block, p->zbin_QTX, |
| 247 | p->round_QTX, p->quant_QTX, p->quant_shift_QTX, |
| 248 | qcoeff_ptr, dqcoeff_ptr, p->dequant_QTX, eob_ptr, |
| 249 | sc->scan, sc->iscan); |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 250 | break; |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 251 | case 2: |
Monty Montgomery | 125c0fc | 2017-10-26 00:44:35 -0400 | [diff] [blame] | 252 | aom_quantize_b_64x64(coeff_ptr, n_coeffs, skip_block, p->zbin_QTX, |
| 253 | p->round_QTX, p->quant_QTX, p->quant_shift_QTX, |
| 254 | qcoeff_ptr, dqcoeff_ptr, p->dequant_QTX, eob_ptr, |
| 255 | sc->scan, sc->iscan); |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 256 | break; |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 257 | default: assert(0); |
| 258 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 259 | } |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | static void quantize_dc(const tran_low_t *coeff_ptr, int n_coeffs, |
| 263 | int skip_block, const int16_t *round_ptr, |
| 264 | const int16_t quant, tran_low_t *qcoeff_ptr, |
| 265 | tran_low_t *dqcoeff_ptr, const int16_t dequant_ptr, |
| 266 | uint16_t *eob_ptr, const qm_val_t *qm_ptr, |
| 267 | const qm_val_t *iqm_ptr, const int log_scale) { |
| 268 | const int rc = 0; |
| 269 | const int coeff = coeff_ptr[rc]; |
| 270 | const int coeff_sign = (coeff >> 31); |
| 271 | const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; |
Sarah Parker | af210e4 | 2017-09-08 14:19:04 -0700 | [diff] [blame] | 272 | int64_t tmp; |
| 273 | int eob = -1; |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 274 | int32_t tmp32; |
| 275 | int dequant; |
| 276 | |
| 277 | memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr)); |
| 278 | memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr)); |
| 279 | |
| 280 | if (!skip_block) { |
| 281 | const int wt = qm_ptr != NULL ? qm_ptr[rc] : (1 << AOM_QM_BITS); |
| 282 | const int iwt = iqm_ptr != NULL ? iqm_ptr[rc] : (1 << AOM_QM_BITS); |
| 283 | tmp = clamp(abs_coeff + ROUND_POWER_OF_TWO(round_ptr[rc != 0], log_scale), |
| 284 | INT16_MIN, INT16_MAX); |
| 285 | tmp32 = (int32_t)((tmp * wt * quant) >> (16 - log_scale + AOM_QM_BITS)); |
| 286 | qcoeff_ptr[rc] = (tmp32 ^ coeff_sign) - coeff_sign; |
| 287 | dequant = (dequant_ptr * iwt + (1 << (AOM_QM_BITS - 1))) >> AOM_QM_BITS; |
| 288 | dqcoeff_ptr[rc] = (qcoeff_ptr[rc] * dequant) / (1 << log_scale); |
| 289 | if (tmp32) eob = 0; |
| 290 | } |
| 291 | *eob_ptr = eob + 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 292 | } |
| 293 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 294 | void av1_quantize_dc_facade(const tran_low_t *coeff_ptr, intptr_t n_coeffs, |
| 295 | const MACROBLOCK_PLANE *p, tran_low_t *qcoeff_ptr, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 296 | tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr, |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 297 | const SCAN_ORDER *sc, const QUANT_PARAM *qparam) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 298 | // obsolete skip_block |
| 299 | const int skip_block = 0; |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 300 | (void)sc; |
Yaowu Xu | d3d4159 | 2018-02-14 13:26:52 -0800 | [diff] [blame] | 301 | assert(qparam->log_scale >= 0 && qparam->log_scale < (3)); |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 302 | const qm_val_t *qm_ptr = qparam->qmatrix; |
| 303 | const qm_val_t *iqm_ptr = qparam->iqmatrix; |
Monty Montgomery | 125c0fc | 2017-10-26 00:44:35 -0400 | [diff] [blame] | 304 | quantize_dc(coeff_ptr, (int)n_coeffs, skip_block, p->round_QTX, |
| 305 | p->quant_fp_QTX[0], qcoeff_ptr, dqcoeff_ptr, p->dequant_QTX[0], |
| 306 | eob_ptr, qm_ptr, iqm_ptr, qparam->log_scale); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 307 | } |
| 308 | |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 309 | void av1_highbd_quantize_fp_facade(const tran_low_t *coeff_ptr, |
| 310 | intptr_t n_coeffs, const MACROBLOCK_PLANE *p, |
| 311 | tran_low_t *qcoeff_ptr, |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 312 | tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr, |
| 313 | const SCAN_ORDER *sc, |
| 314 | const QUANT_PARAM *qparam) { |
| 315 | // obsolete skip_block |
| 316 | const int skip_block = 0; |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 317 | const qm_val_t *qm_ptr = qparam->qmatrix; |
| 318 | const qm_val_t *iqm_ptr = qparam->iqmatrix; |
Thomas Davies | 1870382 | 2017-07-21 14:39:33 +0100 | [diff] [blame] | 319 | if (qm_ptr != NULL && iqm_ptr != NULL) { |
Monty Montgomery | 125c0fc | 2017-10-26 00:44:35 -0400 | [diff] [blame] | 320 | highbd_quantize_fp_helper_c(coeff_ptr, n_coeffs, skip_block, p->zbin_QTX, |
| 321 | p->round_fp_QTX, p->quant_fp_QTX, |
| 322 | p->quant_shift_QTX, qcoeff_ptr, dqcoeff_ptr, |
| 323 | p->dequant_QTX, eob_ptr, sc->scan, sc->iscan, |
| 324 | qm_ptr, iqm_ptr, qparam->log_scale); |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 325 | } else { |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 326 | if (n_coeffs < 16) { |
| 327 | // TODO(jingning): Need SIMD implementation for smaller block size |
| 328 | // quantization. |
Monty Montgomery | 125c0fc | 2017-10-26 00:44:35 -0400 | [diff] [blame] | 329 | av1_highbd_quantize_fp_c( |
| 330 | coeff_ptr, n_coeffs, skip_block, p->zbin_QTX, p->round_fp_QTX, |
| 331 | p->quant_fp_QTX, p->quant_shift_QTX, qcoeff_ptr, dqcoeff_ptr, |
| 332 | p->dequant_QTX, eob_ptr, sc->scan, sc->iscan, qparam->log_scale); |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 333 | return; |
| 334 | } |
Jingning Han | daf03ee | 2017-03-08 08:52:30 -0800 | [diff] [blame] | 335 | |
Monty Montgomery | 125c0fc | 2017-10-26 00:44:35 -0400 | [diff] [blame] | 336 | av1_highbd_quantize_fp(coeff_ptr, n_coeffs, skip_block, p->zbin_QTX, |
| 337 | p->round_fp_QTX, p->quant_fp_QTX, p->quant_shift_QTX, |
| 338 | qcoeff_ptr, dqcoeff_ptr, p->dequant_QTX, eob_ptr, |
| 339 | sc->scan, sc->iscan, qparam->log_scale); |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 340 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 341 | } |
| 342 | |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 343 | void av1_highbd_quantize_b_facade(const tran_low_t *coeff_ptr, |
| 344 | intptr_t n_coeffs, const MACROBLOCK_PLANE *p, |
| 345 | tran_low_t *qcoeff_ptr, |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 346 | tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr, |
| 347 | const SCAN_ORDER *sc, |
| 348 | const QUANT_PARAM *qparam) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 349 | // obsolete skip_block |
| 350 | const int skip_block = 0; |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 351 | const qm_val_t *qm_ptr = qparam->qmatrix; |
| 352 | const qm_val_t *iqm_ptr = qparam->iqmatrix; |
Thomas Davies | 1870382 | 2017-07-21 14:39:33 +0100 | [diff] [blame] | 353 | if (qm_ptr != NULL && iqm_ptr != NULL) { |
Monty Montgomery | 125c0fc | 2017-10-26 00:44:35 -0400 | [diff] [blame] | 354 | highbd_quantize_b_helper_c(coeff_ptr, n_coeffs, skip_block, p->zbin_QTX, |
| 355 | p->round_QTX, p->quant_QTX, p->quant_shift_QTX, |
| 356 | qcoeff_ptr, dqcoeff_ptr, p->dequant_QTX, eob_ptr, |
| 357 | sc->scan, sc->iscan, qm_ptr, iqm_ptr, |
| 358 | qparam->log_scale); |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 359 | } else { |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 360 | switch (qparam->log_scale) { |
| 361 | case 0: |
| 362 | if (LIKELY(n_coeffs >= 8)) { |
Monty Montgomery | 125c0fc | 2017-10-26 00:44:35 -0400 | [diff] [blame] | 363 | aom_highbd_quantize_b(coeff_ptr, n_coeffs, skip_block, p->zbin_QTX, |
| 364 | p->round_QTX, p->quant_QTX, p->quant_shift_QTX, |
| 365 | qcoeff_ptr, dqcoeff_ptr, p->dequant_QTX, |
| 366 | eob_ptr, sc->scan, sc->iscan); |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 367 | } else { |
| 368 | // TODO(luoyi): Need SIMD (e.g. sse2) for smaller block size |
| 369 | // quantization |
Monty Montgomery | 125c0fc | 2017-10-26 00:44:35 -0400 | [diff] [blame] | 370 | aom_highbd_quantize_b_c(coeff_ptr, n_coeffs, skip_block, p->zbin_QTX, |
| 371 | p->round_QTX, p->quant_QTX, |
| 372 | p->quant_shift_QTX, qcoeff_ptr, dqcoeff_ptr, |
| 373 | p->dequant_QTX, eob_ptr, sc->scan, sc->iscan); |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 374 | } |
| 375 | break; |
| 376 | case 1: |
Monty Montgomery | 125c0fc | 2017-10-26 00:44:35 -0400 | [diff] [blame] | 377 | aom_highbd_quantize_b_32x32( |
| 378 | coeff_ptr, n_coeffs, skip_block, p->zbin_QTX, p->round_QTX, |
| 379 | p->quant_QTX, p->quant_shift_QTX, qcoeff_ptr, dqcoeff_ptr, |
| 380 | p->dequant_QTX, eob_ptr, sc->scan, sc->iscan); |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 381 | break; |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 382 | case 2: |
Monty Montgomery | 125c0fc | 2017-10-26 00:44:35 -0400 | [diff] [blame] | 383 | aom_highbd_quantize_b_64x64( |
| 384 | coeff_ptr, n_coeffs, skip_block, p->zbin_QTX, p->round_QTX, |
| 385 | p->quant_QTX, p->quant_shift_QTX, qcoeff_ptr, dqcoeff_ptr, |
| 386 | p->dequant_QTX, eob_ptr, sc->scan, sc->iscan); |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 387 | break; |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 388 | default: assert(0); |
| 389 | } |
Cheng Chen | 9b18037 | 2017-04-24 16:21:25 -0700 | [diff] [blame] | 390 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 391 | } |
| 392 | |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 393 | static INLINE void highbd_quantize_dc( |
| 394 | const tran_low_t *coeff_ptr, int n_coeffs, int skip_block, |
| 395 | const int16_t *round_ptr, const int16_t quant, tran_low_t *qcoeff_ptr, |
| 396 | tran_low_t *dqcoeff_ptr, const int16_t dequant_ptr, uint16_t *eob_ptr, |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 397 | const qm_val_t *qm_ptr, const qm_val_t *iqm_ptr, const int log_scale) { |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 398 | int eob = -1; |
| 399 | |
| 400 | memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr)); |
| 401 | memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr)); |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 402 | |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 403 | if (!skip_block) { |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 404 | const qm_val_t wt = qm_ptr != NULL ? qm_ptr[0] : (1 << AOM_QM_BITS); |
| 405 | const qm_val_t iwt = iqm_ptr != NULL ? iqm_ptr[0] : (1 << AOM_QM_BITS); |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 406 | const int coeff = coeff_ptr[0]; |
| 407 | const int coeff_sign = (coeff >> 31); |
| 408 | const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 409 | const int64_t tmp = abs_coeff + ROUND_POWER_OF_TWO(round_ptr[0], log_scale); |
| 410 | const int64_t tmpw = tmp * wt; |
| 411 | const int abs_qcoeff = |
| 412 | (int)((tmpw * quant) >> (16 - log_scale + AOM_QM_BITS)); |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 413 | qcoeff_ptr[0] = (tran_low_t)((abs_qcoeff ^ coeff_sign) - coeff_sign); |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 414 | const int dequant = |
| 415 | (dequant_ptr * iwt + (1 << (AOM_QM_BITS - 1))) >> AOM_QM_BITS; |
| 416 | |
| 417 | dqcoeff_ptr[0] = (qcoeff_ptr[0] * dequant) / (1 << log_scale); |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 418 | if (abs_qcoeff) eob = 0; |
| 419 | } |
| 420 | *eob_ptr = eob + 1; |
| 421 | } |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 422 | |
| 423 | void av1_highbd_quantize_dc_facade(const tran_low_t *coeff_ptr, |
| 424 | intptr_t n_coeffs, const MACROBLOCK_PLANE *p, |
| 425 | tran_low_t *qcoeff_ptr, |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 426 | tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr, |
| 427 | const SCAN_ORDER *sc, |
| 428 | const QUANT_PARAM *qparam) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 429 | // obsolete skip_block |
| 430 | const int skip_block = 0; |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 431 | const qm_val_t *qm_ptr = qparam->qmatrix; |
| 432 | const qm_val_t *iqm_ptr = qparam->iqmatrix; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 433 | (void)sc; |
| 434 | |
Monty Montgomery | 125c0fc | 2017-10-26 00:44:35 -0400 | [diff] [blame] | 435 | highbd_quantize_dc(coeff_ptr, (int)n_coeffs, skip_block, p->round_QTX, |
| 436 | p->quant_fp_QTX[0], qcoeff_ptr, dqcoeff_ptr, |
| 437 | p->dequant_QTX[0], eob_ptr, qm_ptr, iqm_ptr, |
| 438 | qparam->log_scale); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 439 | } |
| 440 | |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 441 | void av1_highbd_quantize_fp_c( |
| 442 | const tran_low_t *coeff_ptr, intptr_t count, int skip_block, |
| 443 | const int16_t *zbin_ptr, const int16_t *round_ptr, const int16_t *quant_ptr, |
| 444 | const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr, |
| 445 | tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, |
| 446 | const int16_t *scan, const int16_t *iscan, int log_scale) { |
| 447 | highbd_quantize_fp_helper_c(coeff_ptr, count, skip_block, zbin_ptr, round_ptr, |
| 448 | quant_ptr, quant_shift_ptr, qcoeff_ptr, |
| 449 | dqcoeff_ptr, dequant_ptr, eob_ptr, scan, iscan, |
| 450 | NULL, NULL, log_scale); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 451 | } |
| 452 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 453 | static void invert_quant(int16_t *quant, int16_t *shift, int d) { |
Yaowu Xu | af04863 | 2016-05-18 17:35:34 -0700 | [diff] [blame] | 454 | uint32_t t; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 455 | int l, m; |
| 456 | t = d; |
| 457 | for (l = 0; t > 1; l++) t >>= 1; |
| 458 | m = 1 + (1 << (16 + l)) / d; |
| 459 | *quant = (int16_t)(m - (1 << 16)); |
| 460 | *shift = 1 << (16 - l); |
| 461 | } |
| 462 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 463 | static int get_qzbin_factor(int q, aom_bit_depth_t bit_depth) { |
Monty Montgomery | 60f2a22 | 2017-11-01 19:48:38 -0400 | [diff] [blame] | 464 | const int quant = av1_dc_quant_Q3(q, 0, bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 465 | switch (bit_depth) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 466 | case AOM_BITS_8: return q == 0 ? 64 : (quant < 148 ? 84 : 80); |
| 467 | case AOM_BITS_10: return q == 0 ? 64 : (quant < 592 ? 84 : 80); |
| 468 | case AOM_BITS_12: return q == 0 ? 64 : (quant < 2368 ? 84 : 80); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 469 | default: |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 470 | assert(0 && "bit_depth should be AOM_BITS_8, AOM_BITS_10 or AOM_BITS_12"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 471 | return -1; |
| 472 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 473 | } |
| 474 | |
Yi Luo | c621023 | 2017-05-25 15:09:25 -0700 | [diff] [blame] | 475 | void av1_build_quantizer(aom_bit_depth_t bit_depth, int y_dc_delta_q, |
Yaowu Xu | be42dc7 | 2017-11-08 17:38:24 -0800 | [diff] [blame] | 476 | int u_dc_delta_q, int u_ac_delta_q, int v_dc_delta_q, |
| 477 | int v_ac_delta_q, QUANTS *const quants, |
| 478 | Dequants *const deq) { |
Monty Montgomery | 125c0fc | 2017-10-26 00:44:35 -0400 | [diff] [blame] | 479 | int i, q, quant_Q3, quant_QTX; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 480 | |
| 481 | for (q = 0; q < QINDEX_RANGE; q++) { |
Yi Luo | c621023 | 2017-05-25 15:09:25 -0700 | [diff] [blame] | 482 | const int qzbin_factor = get_qzbin_factor(q, bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 483 | const int qrounding_factor = q == 0 ? 64 : 48; |
| 484 | |
| 485 | for (i = 0; i < 2; ++i) { |
| 486 | int qrounding_factor_fp = 64; |
Monty Montgomery | 125c0fc | 2017-10-26 00:44:35 -0400 | [diff] [blame] | 487 | // y quantizer setup with original coeff shift of Q3 |
Monty Montgomery | 60f2a22 | 2017-11-01 19:48:38 -0400 | [diff] [blame] | 488 | quant_Q3 = i == 0 ? av1_dc_quant_Q3(q, y_dc_delta_q, bit_depth) |
| 489 | : av1_ac_quant_Q3(q, 0, bit_depth); |
| 490 | // y quantizer with TX scale |
| 491 | quant_QTX = i == 0 ? av1_dc_quant_QTX(q, y_dc_delta_q, bit_depth) |
| 492 | : av1_ac_quant_QTX(q, 0, bit_depth); |
Monty Montgomery | 125c0fc | 2017-10-26 00:44:35 -0400 | [diff] [blame] | 493 | invert_quant(&quants->y_quant[q][i], &quants->y_quant_shift[q][i], |
| 494 | quant_QTX); |
| 495 | quants->y_quant_fp[q][i] = (1 << 16) / quant_QTX; |
| 496 | quants->y_round_fp[q][i] = (qrounding_factor_fp * quant_QTX) >> 7; |
| 497 | quants->y_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant_QTX, 7); |
| 498 | quants->y_round[q][i] = (qrounding_factor * quant_QTX) >> 7; |
| 499 | deq->y_dequant_QTX[q][i] = quant_QTX; |
| 500 | deq->y_dequant_Q3[q][i] = quant_Q3; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 501 | |
Yaowu Xu | be42dc7 | 2017-11-08 17:38:24 -0800 | [diff] [blame] | 502 | // u quantizer setup with original coeff shift of Q3 |
Monty Montgomery | 60f2a22 | 2017-11-01 19:48:38 -0400 | [diff] [blame] | 503 | quant_Q3 = i == 0 ? av1_dc_quant_Q3(q, u_dc_delta_q, bit_depth) |
| 504 | : av1_ac_quant_Q3(q, u_ac_delta_q, bit_depth); |
| 505 | // u quantizer with TX scale |
| 506 | quant_QTX = i == 0 ? av1_dc_quant_QTX(q, u_dc_delta_q, bit_depth) |
| 507 | : av1_ac_quant_QTX(q, u_ac_delta_q, bit_depth); |
Yaowu Xu | be42dc7 | 2017-11-08 17:38:24 -0800 | [diff] [blame] | 508 | invert_quant(&quants->u_quant[q][i], &quants->u_quant_shift[q][i], |
Monty Montgomery | 125c0fc | 2017-10-26 00:44:35 -0400 | [diff] [blame] | 509 | quant_QTX); |
Yaowu Xu | be42dc7 | 2017-11-08 17:38:24 -0800 | [diff] [blame] | 510 | quants->u_quant_fp[q][i] = (1 << 16) / quant_QTX; |
| 511 | quants->u_round_fp[q][i] = (qrounding_factor_fp * quant_QTX) >> 7; |
| 512 | quants->u_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant_QTX, 7); |
| 513 | quants->u_round[q][i] = (qrounding_factor * quant_QTX) >> 7; |
| 514 | deq->u_dequant_QTX[q][i] = quant_QTX; |
| 515 | deq->u_dequant_Q3[q][i] = quant_Q3; |
| 516 | |
| 517 | // v quantizer setup with original coeff shift of Q3 |
Monty Montgomery | 60f2a22 | 2017-11-01 19:48:38 -0400 | [diff] [blame] | 518 | quant_Q3 = i == 0 ? av1_dc_quant_Q3(q, v_dc_delta_q, bit_depth) |
| 519 | : av1_ac_quant_Q3(q, v_ac_delta_q, bit_depth); |
| 520 | // v quantizer with TX scale |
| 521 | quant_QTX = i == 0 ? av1_dc_quant_QTX(q, v_dc_delta_q, bit_depth) |
| 522 | : av1_ac_quant_QTX(q, v_ac_delta_q, bit_depth); |
Yaowu Xu | be42dc7 | 2017-11-08 17:38:24 -0800 | [diff] [blame] | 523 | invert_quant(&quants->v_quant[q][i], &quants->v_quant_shift[q][i], |
| 524 | quant_QTX); |
| 525 | quants->v_quant_fp[q][i] = (1 << 16) / quant_QTX; |
| 526 | quants->v_round_fp[q][i] = (qrounding_factor_fp * quant_QTX) >> 7; |
| 527 | quants->v_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant_QTX, 7); |
| 528 | quants->v_round[q][i] = (qrounding_factor * quant_QTX) >> 7; |
| 529 | deq->v_dequant_QTX[q][i] = quant_QTX; |
| 530 | deq->v_dequant_Q3[q][i] = quant_Q3; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 531 | } |
| 532 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 533 | for (i = 2; i < 8; i++) { // 8: SIMD width |
| 534 | quants->y_quant[q][i] = quants->y_quant[q][1]; |
| 535 | quants->y_quant_fp[q][i] = quants->y_quant_fp[q][1]; |
| 536 | quants->y_round_fp[q][i] = quants->y_round_fp[q][1]; |
| 537 | quants->y_quant_shift[q][i] = quants->y_quant_shift[q][1]; |
| 538 | quants->y_zbin[q][i] = quants->y_zbin[q][1]; |
| 539 | quants->y_round[q][i] = quants->y_round[q][1]; |
Monty Montgomery | 125c0fc | 2017-10-26 00:44:35 -0400 | [diff] [blame] | 540 | deq->y_dequant_QTX[q][i] = deq->y_dequant_QTX[q][1]; |
| 541 | deq->y_dequant_Q3[q][i] = deq->y_dequant_Q3[q][1]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 542 | |
Yaowu Xu | be42dc7 | 2017-11-08 17:38:24 -0800 | [diff] [blame] | 543 | quants->u_quant[q][i] = quants->u_quant[q][1]; |
| 544 | quants->u_quant_fp[q][i] = quants->u_quant_fp[q][1]; |
| 545 | quants->u_round_fp[q][i] = quants->u_round_fp[q][1]; |
| 546 | quants->u_quant_shift[q][i] = quants->u_quant_shift[q][1]; |
| 547 | quants->u_zbin[q][i] = quants->u_zbin[q][1]; |
| 548 | quants->u_round[q][i] = quants->u_round[q][1]; |
| 549 | deq->u_dequant_QTX[q][i] = deq->u_dequant_QTX[q][1]; |
| 550 | deq->u_dequant_Q3[q][i] = deq->u_dequant_Q3[q][1]; |
| 551 | quants->v_quant[q][i] = quants->u_quant[q][1]; |
| 552 | quants->v_quant_fp[q][i] = quants->v_quant_fp[q][1]; |
| 553 | quants->v_round_fp[q][i] = quants->v_round_fp[q][1]; |
| 554 | quants->v_quant_shift[q][i] = quants->v_quant_shift[q][1]; |
| 555 | quants->v_zbin[q][i] = quants->v_zbin[q][1]; |
| 556 | quants->v_round[q][i] = quants->v_round[q][1]; |
| 557 | deq->v_dequant_QTX[q][i] = deq->v_dequant_QTX[q][1]; |
| 558 | deq->v_dequant_Q3[q][i] = deq->v_dequant_Q3[q][1]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 559 | } |
| 560 | } |
| 561 | } |
| 562 | |
Yi Luo | c621023 | 2017-05-25 15:09:25 -0700 | [diff] [blame] | 563 | void av1_init_quantizer(AV1_COMP *cpi) { |
| 564 | AV1_COMMON *const cm = &cpi->common; |
| 565 | QUANTS *const quants = &cpi->quants; |
| 566 | Dequants *const dequants = &cpi->dequants; |
Yaowu Xu | be42dc7 | 2017-11-08 17:38:24 -0800 | [diff] [blame] | 567 | av1_build_quantizer(cm->bit_depth, cm->y_dc_delta_q, cm->u_dc_delta_q, |
| 568 | cm->u_ac_delta_q, cm->v_dc_delta_q, cm->v_ac_delta_q, |
| 569 | quants, dequants); |
Yi Luo | c621023 | 2017-05-25 15:09:25 -0700 | [diff] [blame] | 570 | } |
| 571 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 572 | void av1_init_plane_quantizers(const AV1_COMP *cpi, MACROBLOCK *x, |
| 573 | int segment_id) { |
| 574 | const AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 575 | MACROBLOCKD *const xd = &x->e_mbd; |
| 576 | const QUANTS *const quants = &cpi->quants; |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 577 | |
Fangwen Fu | 6160df2 | 2017-04-24 09:45:51 -0700 | [diff] [blame] | 578 | #if CONFIG_EXT_DELTA_Q |
Johann | b0ef6ff | 2018-02-08 14:32:21 -0800 | [diff] [blame] | 579 | int current_q_index = AOMMAX( |
| 580 | 0, AOMMIN(QINDEX_RANGE - 1, cpi->oxcf.deltaq_mode != NO_DELTA_Q |
| 581 | ? cm->base_qindex + xd->delta_qindex |
| 582 | : cm->base_qindex)); |
Fangwen Fu | 6160df2 | 2017-04-24 09:45:51 -0700 | [diff] [blame] | 583 | #else |
Yaowu Xu | bfed738 | 2018-02-25 20:18:14 -0800 | [diff] [blame] | 584 | int current_q_index = AOMMAX( |
| 585 | 0, AOMMIN(QINDEX_RANGE - 1, cm->delta_q_present_flag |
| 586 | ? cm->base_qindex + xd->delta_qindex |
| 587 | : cm->base_qindex)); |
Fangwen Fu | 6160df2 | 2017-04-24 09:45:51 -0700 | [diff] [blame] | 588 | #endif |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 589 | const int qindex = av1_get_qindex(&cm->seg, segment_id, current_q_index); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 590 | const int rdmult = av1_compute_rd_mult(cpi, qindex + cm->y_dc_delta_q); |
Yaowu Xu | f7a1242 | 2018-01-31 15:29:20 -0800 | [diff] [blame] | 591 | #if CONFIG_AOM_QM_EXT |
| 592 | int qmlevel = (xd->lossless[segment_id] || cm->using_qmatrix == 0) |
| 593 | ? NUM_QM_LEVELS - 1 |
| 594 | : cm->qm_y; |
| 595 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 596 | int minqm = cm->min_qmlevel; |
| 597 | int maxqm = cm->max_qmlevel; |
| 598 | // Quant matrix only depends on the base QP so there is only one set per frame |
Yaowu Xu | 0dd0463 | 2016-10-19 09:31:50 -0700 | [diff] [blame] | 599 | int qmlevel = (xd->lossless[segment_id] || cm->using_qmatrix == 0) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 600 | ? NUM_QM_LEVELS - 1 |
| 601 | : aom_get_qmlevel(cm->base_qindex, minqm, maxqm); |
Yaowu Xu | f7a1242 | 2018-01-31 15:29:20 -0800 | [diff] [blame] | 602 | #endif // CONFIG_AOM_QM_EXT |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 603 | |
| 604 | // Y |
Monty Montgomery | 125c0fc | 2017-10-26 00:44:35 -0400 | [diff] [blame] | 605 | x->plane[0].quant_QTX = quants->y_quant[qindex]; |
| 606 | x->plane[0].quant_fp_QTX = quants->y_quant_fp[qindex]; |
| 607 | x->plane[0].round_fp_QTX = quants->y_round_fp[qindex]; |
| 608 | x->plane[0].quant_shift_QTX = quants->y_quant_shift[qindex]; |
| 609 | x->plane[0].zbin_QTX = quants->y_zbin[qindex]; |
| 610 | x->plane[0].round_QTX = quants->y_round[qindex]; |
| 611 | x->plane[0].dequant_QTX = cpi->dequants.y_dequant_QTX[qindex]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 612 | memcpy(&xd->plane[0].seg_qmatrix[segment_id], cm->gqmatrix[qmlevel][0], |
| 613 | sizeof(cm->gqmatrix[qmlevel][0])); |
| 614 | memcpy(&xd->plane[0].seg_iqmatrix[segment_id], cm->giqmatrix[qmlevel][0], |
| 615 | sizeof(cm->giqmatrix[qmlevel][0])); |
Monty Montgomery | 125c0fc | 2017-10-26 00:44:35 -0400 | [diff] [blame] | 616 | xd->plane[0].dequant_Q3 = cpi->dequants.y_dequant_Q3[qindex]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 617 | |
Yaowu Xu | f7a1242 | 2018-01-31 15:29:20 -0800 | [diff] [blame] | 618 | // U |
Yaowu Xu | f7a1242 | 2018-01-31 15:29:20 -0800 | [diff] [blame] | 619 | #if CONFIG_AOM_QM_EXT |
| 620 | qmlevel = (xd->lossless[segment_id] || cm->using_qmatrix == 0) |
| 621 | ? NUM_QM_LEVELS - 1 |
| 622 | : cm->qm_u; |
| 623 | #endif |
Yaowu Xu | be42dc7 | 2017-11-08 17:38:24 -0800 | [diff] [blame] | 624 | { |
| 625 | x->plane[1].quant_QTX = quants->u_quant[qindex]; |
| 626 | x->plane[1].quant_fp_QTX = quants->u_quant_fp[qindex]; |
| 627 | x->plane[1].round_fp_QTX = quants->u_round_fp[qindex]; |
| 628 | x->plane[1].quant_shift_QTX = quants->u_quant_shift[qindex]; |
| 629 | x->plane[1].zbin_QTX = quants->u_zbin[qindex]; |
| 630 | x->plane[1].round_QTX = quants->u_round[qindex]; |
| 631 | x->plane[1].dequant_QTX = cpi->dequants.u_dequant_QTX[qindex]; |
Yaowu Xu | be42dc7 | 2017-11-08 17:38:24 -0800 | [diff] [blame] | 632 | memcpy(&xd->plane[1].seg_qmatrix[segment_id], cm->gqmatrix[qmlevel][1], |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 633 | sizeof(cm->gqmatrix[qmlevel][1])); |
Yaowu Xu | be42dc7 | 2017-11-08 17:38:24 -0800 | [diff] [blame] | 634 | memcpy(&xd->plane[1].seg_iqmatrix[segment_id], cm->giqmatrix[qmlevel][1], |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 635 | sizeof(cm->giqmatrix[qmlevel][1])); |
Yaowu Xu | be42dc7 | 2017-11-08 17:38:24 -0800 | [diff] [blame] | 636 | x->plane[1].dequant_QTX = cpi->dequants.u_dequant_QTX[qindex]; |
| 637 | xd->plane[1].dequant_Q3 = cpi->dequants.u_dequant_Q3[qindex]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 638 | } |
Yaowu Xu | f7a1242 | 2018-01-31 15:29:20 -0800 | [diff] [blame] | 639 | // V |
Yaowu Xu | f7a1242 | 2018-01-31 15:29:20 -0800 | [diff] [blame] | 640 | #if CONFIG_AOM_QM_EXT |
| 641 | qmlevel = (xd->lossless[segment_id] || cm->using_qmatrix == 0) |
| 642 | ? NUM_QM_LEVELS - 1 |
| 643 | : cm->qm_v; |
| 644 | #endif |
Yaowu Xu | be42dc7 | 2017-11-08 17:38:24 -0800 | [diff] [blame] | 645 | { |
| 646 | x->plane[2].quant_QTX = quants->v_quant[qindex]; |
| 647 | x->plane[2].quant_fp_QTX = quants->v_quant_fp[qindex]; |
| 648 | x->plane[2].round_fp_QTX = quants->v_round_fp[qindex]; |
| 649 | x->plane[2].quant_shift_QTX = quants->v_quant_shift[qindex]; |
| 650 | x->plane[2].zbin_QTX = quants->v_zbin[qindex]; |
| 651 | x->plane[2].round_QTX = quants->v_round[qindex]; |
| 652 | x->plane[2].dequant_QTX = cpi->dequants.v_dequant_QTX[qindex]; |
Yaowu Xu | d467bba | 2017-11-09 13:39:11 -0800 | [diff] [blame] | 653 | memcpy(&xd->plane[2].seg_qmatrix[segment_id], cm->gqmatrix[qmlevel][2], |
| 654 | sizeof(cm->gqmatrix[qmlevel][2])); |
| 655 | memcpy(&xd->plane[2].seg_iqmatrix[segment_id], cm->giqmatrix[qmlevel][2], |
| 656 | sizeof(cm->giqmatrix[qmlevel][2])); |
Yaowu Xu | be42dc7 | 2017-11-08 17:38:24 -0800 | [diff] [blame] | 657 | x->plane[2].dequant_QTX = cpi->dequants.v_dequant_QTX[qindex]; |
| 658 | xd->plane[2].dequant_Q3 = cpi->dequants.v_dequant_Q3[qindex]; |
Yaowu Xu | be42dc7 | 2017-11-08 17:38:24 -0800 | [diff] [blame] | 659 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 660 | x->skip_block = segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP); |
David Barker | d7d78c8 | 2016-10-24 10:55:35 +0100 | [diff] [blame] | 661 | x->qindex = qindex; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 662 | |
| 663 | set_error_per_bit(x, rdmult); |
| 664 | |
David Barker | d7d78c8 | 2016-10-24 10:55:35 +0100 | [diff] [blame] | 665 | av1_initialize_me_consts(cpi, x, qindex); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 666 | } |
| 667 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 668 | void av1_frame_init_quantizer(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 669 | MACROBLOCK *const x = &cpi->td.mb; |
| 670 | MACROBLOCKD *const xd = &x->e_mbd; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 671 | av1_init_plane_quantizers(cpi, x, xd->mi[0]->mbmi.segment_id); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 672 | } |
| 673 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 674 | void av1_set_quantizer(AV1_COMMON *cm, int q) { |
| 675 | // quantizer has to be reinitialized with av1_init_quantizer() if any |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 676 | // delta_q changes. |
| 677 | cm->base_qindex = q; |
| 678 | cm->y_dc_delta_q = 0; |
Yaowu Xu | be42dc7 | 2017-11-08 17:38:24 -0800 | [diff] [blame] | 679 | cm->u_dc_delta_q = 0; |
| 680 | cm->u_ac_delta_q = 0; |
| 681 | cm->v_dc_delta_q = 0; |
| 682 | cm->v_ac_delta_q = 0; |
Yaowu Xu | f7a1242 | 2018-01-31 15:29:20 -0800 | [diff] [blame] | 683 | #if CONFIG_AOM_QM_EXT |
| 684 | cm->qm_y = aom_get_qmlevel(cm->base_qindex, cm->min_qmlevel, cm->max_qmlevel); |
| 685 | cm->qm_u = aom_get_qmlevel(cm->base_qindex + cm->u_ac_delta_q, |
| 686 | cm->min_qmlevel, cm->max_qmlevel); |
| 687 | |
Yaowu Xu | f7a1242 | 2018-01-31 15:29:20 -0800 | [diff] [blame] | 688 | if (!cm->separate_uv_delta_q) |
| 689 | cm->qm_v = cm->qm_u; |
| 690 | else |
Yaowu Xu | f7a1242 | 2018-01-31 15:29:20 -0800 | [diff] [blame] | 691 | cm->qm_v = aom_get_qmlevel(cm->base_qindex + cm->v_ac_delta_q, |
| 692 | cm->min_qmlevel, cm->max_qmlevel); |
| 693 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | // Table that converts 0-63 Q-range values passed in outside to the Qindex |
| 697 | // range used internally. |
| 698 | static const int quantizer_to_qindex[] = { |
| 699 | 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, |
| 700 | 52, 56, 60, 64, 68, 72, 76, 80, 84, 88, 92, 96, 100, |
| 701 | 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 144, 148, 152, |
| 702 | 156, 160, 164, 168, 172, 176, 180, 184, 188, 192, 196, 200, 204, |
| 703 | 208, 212, 216, 220, 224, 228, 232, 236, 240, 244, 249, 255, |
| 704 | }; |
| 705 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 706 | int av1_quantizer_to_qindex(int quantizer) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 707 | return quantizer_to_qindex[quantizer]; |
| 708 | } |
| 709 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 710 | int av1_qindex_to_quantizer(int qindex) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 711 | int quantizer; |
| 712 | |
| 713 | for (quantizer = 0; quantizer < 64; ++quantizer) |
| 714 | if (quantizer_to_qindex[quantizer] >= qindex) return quantizer; |
| 715 | |
| 716 | return 63; |
| 717 | } |