| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2015 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebM project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "vpx_dsp/quantize.h" | 11 #include "vpx_dsp/quantize.h" |
| 12 #include "vpx_mem/vpx_mem.h" | 12 #include "vpx_mem/vpx_mem.h" |
| 13 | 13 |
| 14 void vp9_quantize_dc(const tran_low_t *coeff_ptr, | 14 void vpx_quantize_dc(const tran_low_t *coeff_ptr, |
| 15 int n_coeffs, int skip_block, | 15 int n_coeffs, int skip_block, |
| 16 const int16_t *round_ptr, const int16_t quant, | 16 const int16_t *round_ptr, const int16_t quant, |
| 17 tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, | 17 tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, |
| 18 const int16_t dequant_ptr, uint16_t *eob_ptr) { | 18 const int16_t dequant_ptr, uint16_t *eob_ptr) { |
| 19 const int rc = 0; | 19 const int rc = 0; |
| 20 const int coeff = coeff_ptr[rc]; | 20 const int coeff = coeff_ptr[rc]; |
| 21 const int coeff_sign = (coeff >> 31); | 21 const int coeff_sign = (coeff >> 31); |
| 22 const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; | 22 const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; |
| 23 int tmp, eob = -1; | 23 int tmp, eob = -1; |
| 24 | 24 |
| 25 memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr)); | 25 memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr)); |
| 26 memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr)); | 26 memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr)); |
| 27 | 27 |
| 28 if (!skip_block) { | 28 if (!skip_block) { |
| 29 tmp = clamp(abs_coeff + round_ptr[rc != 0], INT16_MIN, INT16_MAX); | 29 tmp = clamp(abs_coeff + round_ptr[rc != 0], INT16_MIN, INT16_MAX); |
| 30 tmp = (tmp * quant) >> 16; | 30 tmp = (tmp * quant) >> 16; |
| 31 qcoeff_ptr[rc] = (tmp ^ coeff_sign) - coeff_sign; | 31 qcoeff_ptr[rc] = (tmp ^ coeff_sign) - coeff_sign; |
| 32 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr; | 32 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr; |
| 33 if (tmp) | 33 if (tmp) |
| 34 eob = 0; | 34 eob = 0; |
| 35 } | 35 } |
| 36 *eob_ptr = eob + 1; | 36 *eob_ptr = eob + 1; |
| 37 } | 37 } |
| 38 | 38 |
| 39 #if CONFIG_VP9_HIGHBITDEPTH | 39 #if CONFIG_VP9_HIGHBITDEPTH |
| 40 void vp9_highbd_quantize_dc(const tran_low_t *coeff_ptr, | 40 void vpx_highbd_quantize_dc(const tran_low_t *coeff_ptr, |
| 41 int n_coeffs, int skip_block, | 41 int n_coeffs, int skip_block, |
| 42 const int16_t *round_ptr, const int16_t quant, | 42 const int16_t *round_ptr, const int16_t quant, |
| 43 tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, | 43 tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, |
| 44 const int16_t dequant_ptr, uint16_t *eob_ptr) { | 44 const int16_t dequant_ptr, uint16_t *eob_ptr) { |
| 45 int eob = -1; | 45 int eob = -1; |
| 46 | 46 |
| 47 memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr)); | 47 memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr)); |
| 48 memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr)); | 48 memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr)); |
| 49 | 49 |
| 50 if (!skip_block) { | 50 if (!skip_block) { |
| 51 const int coeff = coeff_ptr[0]; | 51 const int coeff = coeff_ptr[0]; |
| 52 const int coeff_sign = (coeff >> 31); | 52 const int coeff_sign = (coeff >> 31); |
| 53 const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; | 53 const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; |
| 54 const int64_t tmp = abs_coeff + round_ptr[0]; | 54 const int64_t tmp = abs_coeff + round_ptr[0]; |
| 55 const uint32_t abs_qcoeff = (uint32_t)((tmp * quant) >> 16); | 55 const uint32_t abs_qcoeff = (uint32_t)((tmp * quant) >> 16); |
| 56 qcoeff_ptr[0] = (tran_low_t)((abs_qcoeff ^ coeff_sign) - coeff_sign); | 56 qcoeff_ptr[0] = (tran_low_t)((abs_qcoeff ^ coeff_sign) - coeff_sign); |
| 57 dqcoeff_ptr[0] = qcoeff_ptr[0] * dequant_ptr; | 57 dqcoeff_ptr[0] = qcoeff_ptr[0] * dequant_ptr; |
| 58 if (abs_qcoeff) | 58 if (abs_qcoeff) |
| 59 eob = 0; | 59 eob = 0; |
| 60 } | 60 } |
| 61 *eob_ptr = eob + 1; | 61 *eob_ptr = eob + 1; |
| 62 } | 62 } |
| 63 #endif | 63 #endif |
| 64 | 64 |
| 65 void vp9_quantize_dc_32x32(const tran_low_t *coeff_ptr, int skip_block, | 65 void vpx_quantize_dc_32x32(const tran_low_t *coeff_ptr, int skip_block, |
| 66 const int16_t *round_ptr, const int16_t quant, | 66 const int16_t *round_ptr, const int16_t quant, |
| 67 tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, | 67 tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, |
| 68 const int16_t dequant_ptr, uint16_t *eob_ptr) { | 68 const int16_t dequant_ptr, uint16_t *eob_ptr) { |
| 69 const int n_coeffs = 1024; | 69 const int n_coeffs = 1024; |
| 70 const int rc = 0; | 70 const int rc = 0; |
| 71 const int coeff = coeff_ptr[rc]; | 71 const int coeff = coeff_ptr[rc]; |
| 72 const int coeff_sign = (coeff >> 31); | 72 const int coeff_sign = (coeff >> 31); |
| 73 const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; | 73 const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; |
| 74 int tmp, eob = -1; | 74 int tmp, eob = -1; |
| 75 | 75 |
| 76 memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr)); | 76 memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr)); |
| 77 memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr)); | 77 memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr)); |
| 78 | 78 |
| 79 if (!skip_block) { | 79 if (!skip_block) { |
| 80 tmp = clamp(abs_coeff + ROUND_POWER_OF_TWO(round_ptr[rc != 0], 1), | 80 tmp = clamp(abs_coeff + ROUND_POWER_OF_TWO(round_ptr[rc != 0], 1), |
| 81 INT16_MIN, INT16_MAX); | 81 INT16_MIN, INT16_MAX); |
| 82 tmp = (tmp * quant) >> 15; | 82 tmp = (tmp * quant) >> 15; |
| 83 qcoeff_ptr[rc] = (tmp ^ coeff_sign) - coeff_sign; | 83 qcoeff_ptr[rc] = (tmp ^ coeff_sign) - coeff_sign; |
| 84 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr / 2; | 84 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr / 2; |
| 85 if (tmp) | 85 if (tmp) |
| 86 eob = 0; | 86 eob = 0; |
| 87 } | 87 } |
| 88 *eob_ptr = eob + 1; | 88 *eob_ptr = eob + 1; |
| 89 } | 89 } |
| 90 | 90 |
| 91 #if CONFIG_VP9_HIGHBITDEPTH | 91 #if CONFIG_VP9_HIGHBITDEPTH |
| 92 void vp9_highbd_quantize_dc_32x32(const tran_low_t *coeff_ptr, | 92 void vpx_highbd_quantize_dc_32x32(const tran_low_t *coeff_ptr, |
| 93 int skip_block, | 93 int skip_block, |
| 94 const int16_t *round_ptr, | 94 const int16_t *round_ptr, |
| 95 const int16_t quant, | 95 const int16_t quant, |
| 96 tran_low_t *qcoeff_ptr, | 96 tran_low_t *qcoeff_ptr, |
| 97 tran_low_t *dqcoeff_ptr, | 97 tran_low_t *dqcoeff_ptr, |
| 98 const int16_t dequant_ptr, | 98 const int16_t dequant_ptr, |
| 99 uint16_t *eob_ptr) { | 99 uint16_t *eob_ptr) { |
| 100 const int n_coeffs = 1024; | 100 const int n_coeffs = 1024; |
| 101 int eob = -1; | 101 int eob = -1; |
| 102 | 102 |
| 103 memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr)); | 103 memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr)); |
| 104 memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr)); | 104 memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr)); |
| 105 | 105 |
| 106 if (!skip_block) { | 106 if (!skip_block) { |
| 107 const int coeff = coeff_ptr[0]; | 107 const int coeff = coeff_ptr[0]; |
| 108 const int coeff_sign = (coeff >> 31); | 108 const int coeff_sign = (coeff >> 31); |
| 109 const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; | 109 const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; |
| 110 const int64_t tmp = abs_coeff + ROUND_POWER_OF_TWO(round_ptr[0], 1); | 110 const int64_t tmp = abs_coeff + ROUND_POWER_OF_TWO(round_ptr[0], 1); |
| 111 const uint32_t abs_qcoeff = (uint32_t)((tmp * quant) >> 15); | 111 const uint32_t abs_qcoeff = (uint32_t)((tmp * quant) >> 15); |
| 112 qcoeff_ptr[0] = (tran_low_t)((abs_qcoeff ^ coeff_sign) - coeff_sign); | 112 qcoeff_ptr[0] = (tran_low_t)((abs_qcoeff ^ coeff_sign) - coeff_sign); |
| 113 dqcoeff_ptr[0] = qcoeff_ptr[0] * dequant_ptr / 2; | 113 dqcoeff_ptr[0] = qcoeff_ptr[0] * dequant_ptr / 2; |
| 114 if (abs_qcoeff) | 114 if (abs_qcoeff) |
| 115 eob = 0; | 115 eob = 0; |
| 116 } | 116 } |
| 117 *eob_ptr = eob + 1; | 117 *eob_ptr = eob + 1; |
| 118 } | 118 } |
| 119 #endif | 119 #endif |
| 120 | 120 |
| 121 void vp9_quantize_b_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, | 121 void vpx_quantize_b_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, |
| 122 int skip_block, | 122 int skip_block, |
| 123 const int16_t *zbin_ptr, const int16_t *round_ptr, | 123 const int16_t *zbin_ptr, const int16_t *round_ptr, |
| 124 const int16_t *quant_ptr, const int16_t *quant_shift_ptr, | 124 const int16_t *quant_ptr, const int16_t *quant_shift_ptr, |
| 125 tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, | 125 tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, |
| 126 const int16_t *dequant_ptr, | 126 const int16_t *dequant_ptr, |
| 127 uint16_t *eob_ptr, | 127 uint16_t *eob_ptr, |
| 128 const int16_t *scan, const int16_t *iscan) { | 128 const int16_t *scan, const int16_t *iscan) { |
| 129 int i, non_zero_count = (int)n_coeffs, eob = -1; | 129 int i, non_zero_count = (int)n_coeffs, eob = -1; |
| 130 const int zbins[2] = {zbin_ptr[0], zbin_ptr[1]}; | 130 const int zbins[2] = {zbin_ptr[0], zbin_ptr[1]}; |
| 131 const int nzbins[2] = {zbins[0] * -1, zbins[1] * -1}; | 131 const int nzbins[2] = {zbins[0] * -1, zbins[1] * -1}; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 | 163 |
| 164 if (tmp) | 164 if (tmp) |
| 165 eob = i; | 165 eob = i; |
| 166 } | 166 } |
| 167 } | 167 } |
| 168 } | 168 } |
| 169 *eob_ptr = eob + 1; | 169 *eob_ptr = eob + 1; |
| 170 } | 170 } |
| 171 | 171 |
| 172 #if CONFIG_VP9_HIGHBITDEPTH | 172 #if CONFIG_VP9_HIGHBITDEPTH |
| 173 void vp9_highbd_quantize_b_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, | 173 void vpx_highbd_quantize_b_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, |
| 174 int skip_block, const int16_t *zbin_ptr, | 174 int skip_block, const int16_t *zbin_ptr, |
| 175 const int16_t *round_ptr, const int16_t *quant_ptr, | 175 const int16_t *round_ptr, const int16_t *quant_ptr, |
| 176 const int16_t *quant_shift_ptr, | 176 const int16_t *quant_shift_ptr, |
| 177 tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, | 177 tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, |
| 178 const int16_t *dequant_ptr, | 178 const int16_t *dequant_ptr, |
| 179 uint16_t *eob_ptr, const int16_t *scan, | 179 uint16_t *eob_ptr, const int16_t *scan, |
| 180 const int16_t *iscan) { | 180 const int16_t *iscan) { |
| 181 int i, non_zero_count = (int)n_coeffs, eob = -1; | 181 int i, non_zero_count = (int)n_coeffs, eob = -1; |
| 182 const int zbins[2] = {zbin_ptr[0], zbin_ptr[1]}; | 182 const int zbins[2] = {zbin_ptr[0], zbin_ptr[1]}; |
| 183 const int nzbins[2] = {zbins[0] * -1, zbins[1] * -1}; | 183 const int nzbins[2] = {zbins[0] * -1, zbins[1] * -1}; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr[rc != 0]; | 215 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr[rc != 0]; |
| 216 if (abs_qcoeff) | 216 if (abs_qcoeff) |
| 217 eob = i; | 217 eob = i; |
| 218 } | 218 } |
| 219 } | 219 } |
| 220 } | 220 } |
| 221 *eob_ptr = eob + 1; | 221 *eob_ptr = eob + 1; |
| 222 } | 222 } |
| 223 #endif | 223 #endif |
| 224 | 224 |
| 225 void vp9_quantize_b_32x32_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, | 225 void vpx_quantize_b_32x32_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, |
| 226 int skip_block, | 226 int skip_block, |
| 227 const int16_t *zbin_ptr, const int16_t *round_ptr, | 227 const int16_t *zbin_ptr, const int16_t *round_ptr, |
| 228 const int16_t *quant_ptr, | 228 const int16_t *quant_ptr, |
| 229 const int16_t *quant_shift_ptr, | 229 const int16_t *quant_shift_ptr, |
| 230 tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, | 230 tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, |
| 231 const int16_t *dequant_ptr, | 231 const int16_t *dequant_ptr, |
| 232 uint16_t *eob_ptr, | 232 uint16_t *eob_ptr, |
| 233 const int16_t *scan, const int16_t *iscan) { | 233 const int16_t *scan, const int16_t *iscan) { |
| 234 const int zbins[2] = {ROUND_POWER_OF_TWO(zbin_ptr[0], 1), | 234 const int zbins[2] = {ROUND_POWER_OF_TWO(zbin_ptr[0], 1), |
| 235 ROUND_POWER_OF_TWO(zbin_ptr[1], 1)}; | 235 ROUND_POWER_OF_TWO(zbin_ptr[1], 1)}; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr[rc != 0] / 2; | 272 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr[rc != 0] / 2; |
| 273 | 273 |
| 274 if (tmp) | 274 if (tmp) |
| 275 eob = idx_arr[i]; | 275 eob = idx_arr[i]; |
| 276 } | 276 } |
| 277 } | 277 } |
| 278 *eob_ptr = eob + 1; | 278 *eob_ptr = eob + 1; |
| 279 } | 279 } |
| 280 | 280 |
| 281 #if CONFIG_VP9_HIGHBITDEPTH | 281 #if CONFIG_VP9_HIGHBITDEPTH |
| 282 void vp9_highbd_quantize_b_32x32_c(const tran_low_t *coeff_ptr, | 282 void vpx_highbd_quantize_b_32x32_c(const tran_low_t *coeff_ptr, |
| 283 intptr_t n_coeffs, int skip_block, | 283 intptr_t n_coeffs, int skip_block, |
| 284 const int16_t *zbin_ptr, | 284 const int16_t *zbin_ptr, |
| 285 const int16_t *round_ptr, | 285 const int16_t *round_ptr, |
| 286 const int16_t *quant_ptr, | 286 const int16_t *quant_ptr, |
| 287 const int16_t *quant_shift_ptr, | 287 const int16_t *quant_shift_ptr, |
| 288 tran_low_t *qcoeff_ptr, | 288 tran_low_t *qcoeff_ptr, |
| 289 tran_low_t *dqcoeff_ptr, | 289 tran_low_t *dqcoeff_ptr, |
| 290 const int16_t *dequant_ptr, | 290 const int16_t *dequant_ptr, |
| 291 uint16_t *eob_ptr, | 291 uint16_t *eob_ptr, |
| 292 const int16_t *scan, const int16_t *iscan) { | 292 const int16_t *scan, const int16_t *iscan) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 (uint32_t)((tmp2 * quant_shift_ptr[rc != 0]) >> 15); | 328 (uint32_t)((tmp2 * quant_shift_ptr[rc != 0]) >> 15); |
| 329 qcoeff_ptr[rc] = (tran_low_t)((abs_qcoeff ^ coeff_sign) - coeff_sign); | 329 qcoeff_ptr[rc] = (tran_low_t)((abs_qcoeff ^ coeff_sign) - coeff_sign); |
| 330 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr[rc != 0] / 2; | 330 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr[rc != 0] / 2; |
| 331 if (abs_qcoeff) | 331 if (abs_qcoeff) |
| 332 eob = idx_arr[i]; | 332 eob = idx_arr[i]; |
| 333 } | 333 } |
| 334 } | 334 } |
| 335 *eob_ptr = eob + 1; | 335 *eob_ptr = eob + 1; |
| 336 } | 336 } |
| 337 #endif | 337 #endif |
| OLD | NEW |