OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 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 <math.h> | 11 #include <math.h> |
12 | 12 |
13 #include "vpx_mem/vpx_mem.h" | 13 #include "vpx_mem/vpx_mem.h" |
14 | 14 |
15 #include "vp9/common/vp9_quant_common.h" | 15 #include "vp9/common/vp9_quant_common.h" |
16 #include "vp9/common/vp9_seg_common.h" | 16 #include "vp9/common/vp9_seg_common.h" |
17 | 17 |
18 #include "vp9/encoder/vp9_encoder.h" | 18 #include "vp9/encoder/vp9_encoder.h" |
19 #include "vp9/encoder/vp9_quantize.h" | 19 #include "vp9/encoder/vp9_quantize.h" |
20 #include "vp9/encoder/vp9_rd.h" | 20 #include "vp9/encoder/vp9_rd.h" |
21 | 21 |
22 void vp9_quantize_dc(const int16_t *coeff_ptr, int skip_block, | 22 void vp9_quantize_dc(const tran_low_t *coeff_ptr, int skip_block, |
23 const int16_t *round_ptr, const int16_t quant, | 23 const int16_t *round_ptr, const int16_t quant, |
24 int16_t *qcoeff_ptr, int16_t *dqcoeff_ptr, | 24 tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, |
25 const int16_t dequant_ptr, uint16_t *eob_ptr) { | 25 const int16_t dequant_ptr, uint16_t *eob_ptr) { |
26 const int rc = 0; | 26 const int rc = 0; |
27 const int coeff = coeff_ptr[rc]; | 27 const int coeff = coeff_ptr[rc]; |
28 const int coeff_sign = (coeff >> 31); | 28 const int coeff_sign = (coeff >> 31); |
29 const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; | 29 const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; |
30 int tmp, eob = -1; | 30 int tmp, eob = -1; |
31 | 31 |
32 if (!skip_block) { | 32 if (!skip_block) { |
33 tmp = clamp(abs_coeff + round_ptr[rc != 0], INT16_MIN, INT16_MAX); | 33 tmp = clamp(abs_coeff + round_ptr[rc != 0], INT16_MIN, INT16_MAX); |
34 tmp = (tmp * quant) >> 16; | 34 tmp = (tmp * quant) >> 16; |
35 qcoeff_ptr[rc] = (tmp ^ coeff_sign) - coeff_sign; | 35 qcoeff_ptr[rc] = (tmp ^ coeff_sign) - coeff_sign; |
36 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr; | 36 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr; |
37 if (tmp) | 37 if (tmp) |
38 eob = 0; | 38 eob = 0; |
39 } | 39 } |
40 *eob_ptr = eob + 1; | 40 *eob_ptr = eob + 1; |
41 } | 41 } |
42 | 42 |
43 void vp9_quantize_dc_32x32(const int16_t *coeff_ptr, int skip_block, | 43 #if CONFIG_VP9_HIGHBITDEPTH |
| 44 void vp9_high_quantize_dc(const tran_low_t *coeff_ptr, int skip_block, |
| 45 const int16_t *round_ptr, const int16_t quant, |
| 46 tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, |
| 47 const int16_t dequant_ptr, uint16_t *eob_ptr) { |
| 48 int eob = -1; |
| 49 |
| 50 if (!skip_block) { |
| 51 const int rc = 0; |
| 52 const int coeff = coeff_ptr[rc]; |
| 53 const int coeff_sign = (coeff >> 31); |
| 54 const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; |
| 55 |
| 56 const int64_t tmp = |
| 57 (clamp(abs_coeff + round_ptr[rc != 0], INT32_MIN, INT32_MAX) * |
| 58 quant) >> 16; |
| 59 qcoeff_ptr[rc] = (tmp ^ coeff_sign) - coeff_sign; |
| 60 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr; |
| 61 if (tmp) |
| 62 eob = 0; |
| 63 } |
| 64 *eob_ptr = eob + 1; |
| 65 } |
| 66 #endif |
| 67 |
| 68 void vp9_quantize_dc_32x32(const tran_low_t *coeff_ptr, int skip_block, |
44 const int16_t *round_ptr, const int16_t quant, | 69 const int16_t *round_ptr, const int16_t quant, |
45 int16_t *qcoeff_ptr, int16_t *dqcoeff_ptr, | 70 tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, |
46 const int16_t dequant_ptr, uint16_t *eob_ptr) { | 71 const int16_t dequant_ptr, uint16_t *eob_ptr) { |
47 const int rc = 0; | 72 const int rc = 0; |
48 const int coeff = coeff_ptr[rc]; | 73 const int coeff = coeff_ptr[rc]; |
49 const int coeff_sign = (coeff >> 31); | 74 const int coeff_sign = (coeff >> 31); |
50 const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; | 75 const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; |
51 int tmp, eob = -1; | 76 int tmp, eob = -1; |
52 | 77 |
53 if (!skip_block) { | 78 if (!skip_block) { |
54 | 79 |
55 tmp = clamp(abs_coeff + round_ptr[rc != 0], INT16_MIN, INT16_MAX); | 80 tmp = clamp(abs_coeff + round_ptr[rc != 0], INT16_MIN, INT16_MAX); |
56 tmp = (tmp * quant) >> 15; | 81 tmp = (tmp * quant) >> 15; |
57 qcoeff_ptr[rc] = (tmp ^ coeff_sign) - coeff_sign; | 82 qcoeff_ptr[rc] = (tmp ^ coeff_sign) - coeff_sign; |
58 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr / 2; | 83 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr / 2; |
59 if (tmp) | 84 if (tmp) |
60 eob = 0; | 85 eob = 0; |
61 } | 86 } |
62 *eob_ptr = eob + 1; | 87 *eob_ptr = eob + 1; |
63 } | 88 } |
64 | 89 |
65 void vp9_quantize_fp_c(const int16_t *coeff_ptr, intptr_t count, | 90 #if CONFIG_VP9_HIGHBITDEPTH |
| 91 void vp9_high_quantize_dc_32x32(const tran_low_t *coeff_ptr, int skip_block, |
| 92 const int16_t *round_ptr, const int16_t quant, |
| 93 tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, |
| 94 const int16_t dequant_ptr, uint16_t *eob_ptr) { |
| 95 int eob = -1; |
| 96 |
| 97 if (!skip_block) { |
| 98 const int rc = 0; |
| 99 const int coeff = coeff_ptr[rc]; |
| 100 const int coeff_sign = (coeff >> 31); |
| 101 const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; |
| 102 |
| 103 const int64_t tmp = |
| 104 (clamp(abs_coeff + round_ptr[rc != 0], INT32_MIN, INT32_MAX) * |
| 105 quant) >> 15; |
| 106 qcoeff_ptr[rc] = (tmp ^ coeff_sign) - coeff_sign; |
| 107 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr / 2; |
| 108 if (tmp) |
| 109 eob = 0; |
| 110 } |
| 111 *eob_ptr = eob + 1; |
| 112 } |
| 113 #endif |
| 114 |
| 115 void vp9_quantize_fp_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, |
66 int skip_block, | 116 int skip_block, |
67 const int16_t *zbin_ptr, const int16_t *round_ptr, | 117 const int16_t *zbin_ptr, const int16_t *round_ptr, |
68 const int16_t *quant_ptr, const int16_t *quant_shift_ptr, | 118 const int16_t *quant_ptr, const int16_t *quant_shift_ptr, |
69 int16_t *qcoeff_ptr, int16_t *dqcoeff_ptr, | 119 tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, |
70 const int16_t *dequant_ptr, | 120 const int16_t *dequant_ptr, |
71 int zbin_oq_value, uint16_t *eob_ptr, | 121 int zbin_oq_value, uint16_t *eob_ptr, |
72 const int16_t *scan, const int16_t *iscan) { | 122 const int16_t *scan, const int16_t *iscan) { |
73 int i, eob = -1; | 123 int i, eob = -1; |
74 // TODO(jingning) Decide the need of these arguments after the | 124 // TODO(jingning) Decide the need of these arguments after the |
75 // quantization process is completed. | 125 // quantization process is completed. |
76 (void)zbin_ptr; | 126 (void)zbin_ptr; |
77 (void)quant_shift_ptr; | 127 (void)quant_shift_ptr; |
78 (void)zbin_oq_value; | 128 (void)zbin_oq_value; |
79 (void)iscan; | 129 (void)iscan; |
80 | 130 |
81 vpx_memset(qcoeff_ptr, 0, count * sizeof(int16_t)); | 131 vpx_memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr)); |
82 vpx_memset(dqcoeff_ptr, 0, count * sizeof(int16_t)); | 132 vpx_memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr)); |
83 | 133 |
84 if (!skip_block) { | 134 if (!skip_block) { |
85 // Quantization pass: All coefficients with index >= zero_flag are | 135 // Quantization pass: All coefficients with index >= zero_flag are |
86 // skippable. Note: zero_flag can be zero. | 136 // skippable. Note: zero_flag can be zero. |
87 for (i = 0; i < count; i++) { | 137 for (i = 0; i < n_coeffs; i++) { |
88 const int rc = scan[i]; | 138 const int rc = scan[i]; |
89 const int coeff = coeff_ptr[rc]; | 139 const int coeff = coeff_ptr[rc]; |
90 const int coeff_sign = (coeff >> 31); | 140 const int coeff_sign = (coeff >> 31); |
91 const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; | 141 const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; |
92 | 142 |
93 int tmp = clamp(abs_coeff + round_ptr[rc != 0], INT16_MIN, INT16_MAX); | 143 int tmp = clamp(abs_coeff + round_ptr[rc != 0], INT16_MIN, INT16_MAX); |
94 tmp = (tmp * quant_ptr[rc != 0]) >> 16; | 144 tmp = (tmp * quant_ptr[rc != 0]) >> 16; |
95 | 145 |
96 qcoeff_ptr[rc] = (tmp ^ coeff_sign) - coeff_sign; | 146 qcoeff_ptr[rc] = (tmp ^ coeff_sign) - coeff_sign; |
97 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr[rc != 0]; | 147 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr[rc != 0]; |
98 | 148 |
99 if (tmp) | 149 if (tmp) |
100 eob = i; | 150 eob = i; |
101 } | 151 } |
102 } | 152 } |
103 *eob_ptr = eob + 1; | 153 *eob_ptr = eob + 1; |
104 } | 154 } |
105 | 155 |
| 156 #if CONFIG_VP9_HIGHBITDEPTH |
| 157 void vp9_high_quantize_fp_c(const tran_low_t *coeff_ptr, intptr_t count, |
| 158 int skip_block, const int16_t *zbin_ptr, |
| 159 const int16_t *round_ptr, const int16_t *quant_ptr, |
| 160 const int16_t *quant_shift_ptr, |
| 161 tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, |
| 162 const int16_t *dequant_ptr, |
| 163 int zbin_oq_value, uint16_t *eob_ptr, |
| 164 const int16_t *scan, const int16_t *iscan) { |
| 165 int i; |
| 166 int eob = -1; |
| 167 // TODO(jingning) Decide the need of these arguments after the |
| 168 // quantization process is completed. |
| 169 (void)zbin_ptr; |
| 170 (void)quant_shift_ptr; |
| 171 (void)zbin_oq_value; |
| 172 (void)iscan; |
| 173 |
| 174 vpx_memset(qcoeff_ptr, 0, count * sizeof(*qcoeff_ptr)); |
| 175 vpx_memset(dqcoeff_ptr, 0, count * sizeof(*dqcoeff_ptr)); |
| 176 |
| 177 if (!skip_block) { |
| 178 // Quantization pass: All coefficients with index >= zero_flag are |
| 179 // skippable. Note: zero_flag can be zero. |
| 180 for (i = 0; i < count; i++) { |
| 181 const int rc = scan[i]; |
| 182 const int coeff = coeff_ptr[rc]; |
| 183 const int coeff_sign = (coeff >> 31); |
| 184 const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; |
| 185 |
| 186 const int64_t tmp = |
| 187 (clamp(abs_coeff + round_ptr[rc != 0], INT32_MIN, INT32_MAX) * |
| 188 quant_ptr[rc != 0]) >> 16; |
| 189 |
| 190 qcoeff_ptr[rc] = (tmp ^ coeff_sign) - coeff_sign; |
| 191 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr[rc != 0]; |
| 192 |
| 193 if (tmp) |
| 194 eob = i; |
| 195 } |
| 196 } |
| 197 *eob_ptr = eob + 1; |
| 198 } |
| 199 #endif |
| 200 |
106 // TODO(jingning) Refactor this file and combine functions with similar | 201 // TODO(jingning) Refactor this file and combine functions with similar |
107 // operations. | 202 // operations. |
108 void vp9_quantize_fp_32x32_c(const int16_t *coeff_ptr, intptr_t n_coeffs, | 203 void vp9_quantize_fp_32x32_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, |
109 int skip_block, | 204 int skip_block, |
110 const int16_t *zbin_ptr, const int16_t *round_ptr, | 205 const int16_t *zbin_ptr, const int16_t *round_ptr, |
111 const int16_t *quant_ptr, | 206 const int16_t *quant_ptr, |
112 const int16_t *quant_shift_ptr, | 207 const int16_t *quant_shift_ptr, |
113 int16_t *qcoeff_ptr, int16_t *dqcoeff_ptr, | 208 tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, |
114 const int16_t *dequant_ptr, | 209 const int16_t *dequant_ptr, |
115 int zbin_oq_value, uint16_t *eob_ptr, | 210 int zbin_oq_value, uint16_t *eob_ptr, |
116 const int16_t *scan, const int16_t *iscan) { | 211 const int16_t *scan, const int16_t *iscan) { |
117 int i, eob = -1; | 212 int i, eob = -1; |
118 (void)zbin_ptr; | 213 (void)zbin_ptr; |
119 (void)quant_shift_ptr; | 214 (void)quant_shift_ptr; |
120 (void)zbin_oq_value; | 215 (void)zbin_oq_value; |
121 (void)iscan; | 216 (void)iscan; |
122 | 217 |
123 vpx_memset(qcoeff_ptr, 0, n_coeffs * sizeof(int16_t)); | 218 vpx_memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr)); |
124 vpx_memset(dqcoeff_ptr, 0, n_coeffs * sizeof(int16_t)); | 219 vpx_memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr)); |
125 | 220 |
126 if (!skip_block) { | 221 if (!skip_block) { |
127 for (i = 0; i < n_coeffs; i++) { | 222 for (i = 0; i < n_coeffs; i++) { |
128 const int rc = scan[i]; | 223 const int rc = scan[i]; |
129 const int coeff = coeff_ptr[rc]; | 224 const int coeff = coeff_ptr[rc]; |
130 const int coeff_sign = (coeff >> 31); | 225 const int coeff_sign = (coeff >> 31); |
131 int tmp = 0; | 226 int tmp = 0; |
132 int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; | 227 int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; |
133 | 228 |
134 if (abs_coeff >= (dequant_ptr[rc != 0] >> 2)) { | 229 if (abs_coeff >= (dequant_ptr[rc != 0] >> 2)) { |
135 abs_coeff += ROUND_POWER_OF_TWO(round_ptr[rc != 0], 1); | 230 abs_coeff += ROUND_POWER_OF_TWO(round_ptr[rc != 0], 1); |
136 abs_coeff = clamp(abs_coeff, INT16_MIN, INT16_MAX); | 231 abs_coeff = clamp(abs_coeff, INT16_MIN, INT16_MAX); |
137 tmp = (abs_coeff * quant_ptr[rc != 0]) >> 15; | 232 tmp = (abs_coeff * quant_ptr[rc != 0]) >> 15; |
138 qcoeff_ptr[rc] = (tmp ^ coeff_sign) - coeff_sign; | 233 qcoeff_ptr[rc] = (tmp ^ coeff_sign) - coeff_sign; |
139 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr[rc != 0] / 2; | 234 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr[rc != 0] / 2; |
140 } | 235 } |
141 | 236 |
142 if (tmp) | 237 if (tmp) |
143 eob = i; | 238 eob = i; |
144 } | 239 } |
145 } | 240 } |
146 *eob_ptr = eob + 1; | 241 *eob_ptr = eob + 1; |
147 } | 242 } |
148 | 243 |
149 void vp9_quantize_b_c(const int16_t *coeff_ptr, intptr_t count, | 244 #if CONFIG_VP9_HIGHBITDEPTH |
| 245 void vp9_high_quantize_fp_32x32_c(const tran_low_t *coeff_ptr, |
| 246 intptr_t n_coeffs, int skip_block, |
| 247 const int16_t *zbin_ptr, |
| 248 const int16_t *round_ptr, |
| 249 const int16_t *quant_ptr, |
| 250 const int16_t *quant_shift_ptr, |
| 251 tran_low_t *qcoeff_ptr, |
| 252 tran_low_t *dqcoeff_ptr, |
| 253 const int16_t *dequant_ptr, |
| 254 int zbin_oq_value, uint16_t *eob_ptr, |
| 255 const int16_t *scan, const int16_t *iscan) { |
| 256 int i, eob = -1; |
| 257 (void)zbin_ptr; |
| 258 (void)quant_shift_ptr; |
| 259 (void)zbin_oq_value; |
| 260 (void)iscan; |
| 261 |
| 262 vpx_memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr)); |
| 263 vpx_memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr)); |
| 264 |
| 265 if (!skip_block) { |
| 266 for (i = 0; i < n_coeffs; i++) { |
| 267 const int rc = scan[i]; |
| 268 const int coeff = coeff_ptr[rc]; |
| 269 const int coeff_sign = (coeff >> 31); |
| 270 int64_t tmp = 0; |
| 271 const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; |
| 272 |
| 273 if (abs_coeff >= (dequant_ptr[rc != 0] >> 2)) { |
| 274 tmp = clamp(abs_coeff + ROUND_POWER_OF_TWO(round_ptr[rc != 0], 1), |
| 275 INT32_MIN, INT32_MAX); |
| 276 tmp = (tmp * quant_ptr[rc != 0]) >> 15; |
| 277 qcoeff_ptr[rc] = (tmp ^ coeff_sign) - coeff_sign; |
| 278 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr[rc != 0] / 2; |
| 279 } |
| 280 |
| 281 if (tmp) |
| 282 eob = i; |
| 283 } |
| 284 } |
| 285 *eob_ptr = eob + 1; |
| 286 } |
| 287 #endif |
| 288 |
| 289 void vp9_quantize_b_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, |
150 int skip_block, | 290 int skip_block, |
151 const int16_t *zbin_ptr, const int16_t *round_ptr, | 291 const int16_t *zbin_ptr, const int16_t *round_ptr, |
152 const int16_t *quant_ptr, const int16_t *quant_shift_ptr, | 292 const int16_t *quant_ptr, const int16_t *quant_shift_ptr, |
153 int16_t *qcoeff_ptr, int16_t *dqcoeff_ptr, | 293 tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, |
154 const int16_t *dequant_ptr, | 294 const int16_t *dequant_ptr, |
155 int zbin_oq_value, uint16_t *eob_ptr, | 295 int zbin_oq_value, uint16_t *eob_ptr, |
156 const int16_t *scan, const int16_t *iscan) { | 296 const int16_t *scan, const int16_t *iscan) { |
157 int i, non_zero_count = (int)count, eob = -1; | 297 int i, non_zero_count = (int)n_coeffs, eob = -1; |
158 const int zbins[2] = { zbin_ptr[0] + zbin_oq_value, | 298 const int zbins[2] = { zbin_ptr[0] + zbin_oq_value, |
159 zbin_ptr[1] + zbin_oq_value }; | 299 zbin_ptr[1] + zbin_oq_value }; |
160 const int nzbins[2] = { zbins[0] * -1, | 300 const int nzbins[2] = { zbins[0] * -1, |
161 zbins[1] * -1 }; | 301 zbins[1] * -1 }; |
162 (void)iscan; | 302 (void)iscan; |
163 | 303 |
164 vpx_memset(qcoeff_ptr, 0, count * sizeof(int16_t)); | 304 vpx_memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr)); |
165 vpx_memset(dqcoeff_ptr, 0, count * sizeof(int16_t)); | 305 vpx_memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr)); |
166 | 306 |
167 if (!skip_block) { | 307 if (!skip_block) { |
168 // Pre-scan pass | 308 // Pre-scan pass |
169 for (i = (int)count - 1; i >= 0; i--) { | 309 for (i = (int)n_coeffs - 1; i >= 0; i--) { |
170 const int rc = scan[i]; | 310 const int rc = scan[i]; |
171 const int coeff = coeff_ptr[rc]; | 311 const int coeff = coeff_ptr[rc]; |
172 | 312 |
173 if (coeff < zbins[rc != 0] && coeff > nzbins[rc != 0]) | 313 if (coeff < zbins[rc != 0] && coeff > nzbins[rc != 0]) |
174 non_zero_count--; | 314 non_zero_count--; |
175 else | 315 else |
176 break; | 316 break; |
177 } | 317 } |
178 | 318 |
179 // Quantization pass: All coefficients with index >= zero_flag are | 319 // Quantization pass: All coefficients with index >= zero_flag are |
(...skipping 12 matching lines...) Expand all Loading... |
192 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr[rc != 0]; | 332 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr[rc != 0]; |
193 | 333 |
194 if (tmp) | 334 if (tmp) |
195 eob = i; | 335 eob = i; |
196 } | 336 } |
197 } | 337 } |
198 } | 338 } |
199 *eob_ptr = eob + 1; | 339 *eob_ptr = eob + 1; |
200 } | 340 } |
201 | 341 |
202 void vp9_quantize_b_32x32_c(const int16_t *coeff_ptr, intptr_t n_coeffs, | 342 #if CONFIG_VP9_HIGHBITDEPTH |
| 343 void vp9_high_quantize_b_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, |
| 344 int skip_block, const int16_t *zbin_ptr, |
| 345 const int16_t *round_ptr, const int16_t *quant_ptr, |
| 346 const int16_t *quant_shift_ptr, |
| 347 tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, |
| 348 const int16_t *dequant_ptr, int zbin_oq_value, |
| 349 uint16_t *eob_ptr, const int16_t *scan, |
| 350 const int16_t *iscan) { |
| 351 int i, non_zero_count = (int)n_coeffs, eob = -1; |
| 352 const int zbins[2] = { zbin_ptr[0] + zbin_oq_value, |
| 353 zbin_ptr[1] + zbin_oq_value }; |
| 354 const int nzbins[2] = { zbins[0] * -1, |
| 355 zbins[1] * -1 }; |
| 356 (void)iscan; |
| 357 |
| 358 vpx_memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr)); |
| 359 vpx_memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr)); |
| 360 |
| 361 if (!skip_block) { |
| 362 // Pre-scan pass |
| 363 for (i = (int)n_coeffs - 1; i >= 0; i--) { |
| 364 const int rc = scan[i]; |
| 365 const int coeff = coeff_ptr[rc]; |
| 366 |
| 367 if (coeff < zbins[rc != 0] && coeff > nzbins[rc != 0]) |
| 368 non_zero_count--; |
| 369 else |
| 370 break; |
| 371 } |
| 372 |
| 373 // Quantization pass: All coefficients with index >= zero_flag are |
| 374 // skippable. Note: zero_flag can be zero. |
| 375 for (i = 0; i < non_zero_count; i++) { |
| 376 const int rc = scan[i]; |
| 377 const int coeff = coeff_ptr[rc]; |
| 378 const int coeff_sign = (coeff >> 31); |
| 379 const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; |
| 380 |
| 381 if (abs_coeff >= zbins[rc != 0]) { |
| 382 int64_t tmp = clamp(abs_coeff + round_ptr[rc != 0], |
| 383 INT32_MIN, INT32_MAX); |
| 384 tmp = ((((tmp * quant_ptr[rc != 0]) >> 16) + tmp) * |
| 385 quant_shift_ptr[rc != 0]) >> 16; // quantization |
| 386 qcoeff_ptr[rc] = (tmp ^ coeff_sign) - coeff_sign; |
| 387 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr[rc != 0]; |
| 388 |
| 389 if (tmp) |
| 390 eob = i; |
| 391 } |
| 392 } |
| 393 } |
| 394 *eob_ptr = eob + 1; |
| 395 } |
| 396 #endif |
| 397 |
| 398 void vp9_quantize_b_32x32_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, |
203 int skip_block, | 399 int skip_block, |
204 const int16_t *zbin_ptr, const int16_t *round_ptr, | 400 const int16_t *zbin_ptr, const int16_t *round_ptr, |
205 const int16_t *quant_ptr, | 401 const int16_t *quant_ptr, |
206 const int16_t *quant_shift_ptr, | 402 const int16_t *quant_shift_ptr, |
207 int16_t *qcoeff_ptr, int16_t *dqcoeff_ptr, | 403 tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, |
208 const int16_t *dequant_ptr, | 404 const int16_t *dequant_ptr, |
209 int zbin_oq_value, uint16_t *eob_ptr, | 405 int zbin_oq_value, uint16_t *eob_ptr, |
210 const int16_t *scan, const int16_t *iscan) { | 406 const int16_t *scan, const int16_t *iscan) { |
211 const int zbins[2] = { ROUND_POWER_OF_TWO(zbin_ptr[0] + zbin_oq_value, 1), | 407 const int zbins[2] = { ROUND_POWER_OF_TWO(zbin_ptr[0] + zbin_oq_value, 1), |
212 ROUND_POWER_OF_TWO(zbin_ptr[1] + zbin_oq_value, 1) }; | 408 ROUND_POWER_OF_TWO(zbin_ptr[1] + zbin_oq_value, 1) }; |
213 const int nzbins[2] = {zbins[0] * -1, zbins[1] * -1}; | 409 const int nzbins[2] = {zbins[0] * -1, zbins[1] * -1}; |
214 | 410 |
215 int idx = 0; | 411 int idx = 0; |
216 int idx_arr[1024]; | 412 int idx_arr[1024]; |
217 int i, eob = -1; | 413 int i, eob = -1; |
218 (void)iscan; | 414 (void)iscan; |
219 | 415 |
220 vpx_memset(qcoeff_ptr, 0, n_coeffs * sizeof(int16_t)); | 416 vpx_memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr)); |
221 vpx_memset(dqcoeff_ptr, 0, n_coeffs * sizeof(int16_t)); | 417 vpx_memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr)); |
222 | 418 |
223 if (!skip_block) { | 419 if (!skip_block) { |
224 // Pre-scan pass | 420 // Pre-scan pass |
225 for (i = 0; i < n_coeffs; i++) { | 421 for (i = 0; i < n_coeffs; i++) { |
226 const int rc = scan[i]; | 422 const int rc = scan[i]; |
227 const int coeff = coeff_ptr[rc]; | 423 const int coeff = coeff_ptr[rc]; |
228 | 424 |
229 // If the coefficient is out of the base ZBIN range, keep it for | 425 // If the coefficient is out of the base ZBIN range, keep it for |
230 // quantization. | 426 // quantization. |
231 if (coeff >= zbins[rc != 0] || coeff <= nzbins[rc != 0]) | 427 if (coeff >= zbins[rc != 0] || coeff <= nzbins[rc != 0]) |
(...skipping 16 matching lines...) Expand all Loading... |
248 qcoeff_ptr[rc] = (tmp ^ coeff_sign) - coeff_sign; | 444 qcoeff_ptr[rc] = (tmp ^ coeff_sign) - coeff_sign; |
249 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr[rc != 0] / 2; | 445 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr[rc != 0] / 2; |
250 | 446 |
251 if (tmp) | 447 if (tmp) |
252 eob = idx_arr[i]; | 448 eob = idx_arr[i]; |
253 } | 449 } |
254 } | 450 } |
255 *eob_ptr = eob + 1; | 451 *eob_ptr = eob + 1; |
256 } | 452 } |
257 | 453 |
| 454 #if CONFIG_VP9_HIGHBITDEPTH |
| 455 void vp9_high_quantize_b_32x32_c(const tran_low_t *coeff_ptr, |
| 456 intptr_t n_coeffs, int skip_block, |
| 457 const int16_t *zbin_ptr, |
| 458 const int16_t *round_ptr, |
| 459 const int16_t *quant_ptr, |
| 460 const int16_t *quant_shift_ptr, |
| 461 tran_low_t *qcoeff_ptr, |
| 462 tran_low_t *dqcoeff_ptr, |
| 463 const int16_t *dequant_ptr, |
| 464 int zbin_oq_value, uint16_t *eob_ptr, |
| 465 const int16_t *scan, const int16_t *iscan) { |
| 466 const int zbins[2] = { ROUND_POWER_OF_TWO(zbin_ptr[0] + zbin_oq_value, 1), |
| 467 ROUND_POWER_OF_TWO(zbin_ptr[1] + zbin_oq_value, 1) }; |
| 468 const int nzbins[2] = { zbins[0] * -1, zbins[1] * -1 }; |
| 469 |
| 470 int idx = 0; |
| 471 int idx_arr[1024]; |
| 472 int i, eob = -1; |
| 473 (void)iscan; |
| 474 |
| 475 vpx_memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr)); |
| 476 vpx_memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr)); |
| 477 |
| 478 if (!skip_block) { |
| 479 // Pre-scan pass |
| 480 for (i = 0; i < n_coeffs; i++) { |
| 481 const int rc = scan[i]; |
| 482 const int coeff = coeff_ptr[rc]; |
| 483 |
| 484 // If the coefficient is out of the base ZBIN range, keep it for |
| 485 // quantization. |
| 486 if (coeff >= zbins[rc != 0] || coeff <= nzbins[rc != 0]) |
| 487 idx_arr[idx++] = i; |
| 488 } |
| 489 |
| 490 // Quantization pass: only process the coefficients selected in |
| 491 // pre-scan pass. Note: idx can be zero. |
| 492 for (i = 0; i < idx; i++) { |
| 493 const int rc = scan[idx_arr[i]]; |
| 494 const int coeff = coeff_ptr[rc]; |
| 495 const int coeff_sign = (coeff >> 31); |
| 496 const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; |
| 497 int64_t tmp = clamp(abs_coeff + |
| 498 ROUND_POWER_OF_TWO(round_ptr[rc != 0], 1), |
| 499 INT32_MIN, INT32_MAX); |
| 500 tmp = ((((tmp * quant_ptr[rc != 0]) >> 16) + tmp) * |
| 501 quant_shift_ptr[rc != 0]) >> 15; |
| 502 |
| 503 qcoeff_ptr[rc] = (tmp ^ coeff_sign) - coeff_sign; |
| 504 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr[rc != 0] / 2; |
| 505 |
| 506 if (tmp) |
| 507 eob = idx_arr[i]; |
| 508 } |
| 509 } |
| 510 *eob_ptr = eob + 1; |
| 511 } |
| 512 #endif |
| 513 |
258 void vp9_regular_quantize_b_4x4(MACROBLOCK *x, int plane, int block, | 514 void vp9_regular_quantize_b_4x4(MACROBLOCK *x, int plane, int block, |
259 const int16_t *scan, const int16_t *iscan) { | 515 const int16_t *scan, const int16_t *iscan) { |
260 MACROBLOCKD *const xd = &x->e_mbd; | 516 MACROBLOCKD *const xd = &x->e_mbd; |
261 struct macroblock_plane *p = &x->plane[plane]; | 517 struct macroblock_plane *p = &x->plane[plane]; |
262 struct macroblockd_plane *pd = &xd->plane[plane]; | 518 struct macroblockd_plane *pd = &xd->plane[plane]; |
263 | 519 |
| 520 #if CONFIG_VP9_HIGHBITDEPTH |
| 521 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 522 vp9_high_quantize_b(BLOCK_OFFSET(p->coeff, block), |
| 523 16, x->skip_block, |
| 524 p->zbin, p->round, p->quant, p->quant_shift, |
| 525 BLOCK_OFFSET(p->qcoeff, block), |
| 526 BLOCK_OFFSET(pd->dqcoeff, block), |
| 527 pd->dequant, p->zbin_extra, &p->eobs[block], |
| 528 scan, iscan); |
| 529 return; |
| 530 } |
| 531 #endif |
264 vp9_quantize_b(BLOCK_OFFSET(p->coeff, block), | 532 vp9_quantize_b(BLOCK_OFFSET(p->coeff, block), |
265 16, x->skip_block, | 533 16, x->skip_block, |
266 p->zbin, p->round, p->quant, p->quant_shift, | 534 p->zbin, p->round, p->quant, p->quant_shift, |
267 BLOCK_OFFSET(p->qcoeff, block), | 535 BLOCK_OFFSET(p->qcoeff, block), |
268 BLOCK_OFFSET(pd->dqcoeff, block), | 536 BLOCK_OFFSET(pd->dqcoeff, block), |
269 pd->dequant, p->zbin_extra, &p->eobs[block], scan, iscan); | 537 pd->dequant, p->zbin_extra, &p->eobs[block], scan, iscan); |
270 } | 538 } |
271 | 539 |
272 static void invert_quant(int16_t *quant, int16_t *shift, int d) { | 540 static void invert_quant(int16_t *quant, int16_t *shift, int d) { |
273 unsigned t; | 541 unsigned t; |
274 int l; | 542 int l; |
275 t = d; | 543 t = d; |
276 for (l = 0; t > 1; l++) | 544 for (l = 0; t > 1; l++) |
277 t >>= 1; | 545 t >>= 1; |
278 t = 1 + (1 << (16 + l)) / d; | 546 t = 1 + (1 << (16 + l)) / d; |
279 *quant = (int16_t)(t - (1 << 16)); | 547 *quant = (int16_t)(t - (1 << 16)); |
280 *shift = 1 << (16 - l); | 548 *shift = 1 << (16 - l); |
281 } | 549 } |
282 | 550 |
| 551 static int get_qzbin_factor(int q, vpx_bit_depth_t bit_depth) { |
| 552 const int quant = vp9_dc_quant(q, 0, bit_depth); |
| 553 #if CONFIG_VP9_HIGHBITDEPTH |
| 554 switch (bit_depth) { |
| 555 case VPX_BITS_8: |
| 556 return q == 0 ? 64 : (quant < 148 ? 84 : 80); |
| 557 case VPX_BITS_10: |
| 558 return q == 0 ? 64 : (quant < 592 ? 84 : 80); |
| 559 case VPX_BITS_12: |
| 560 return q == 0 ? 64 : (quant < 2368 ? 84 : 80); |
| 561 default: |
| 562 assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12"); |
| 563 return -1; |
| 564 } |
| 565 #else |
| 566 (void) bit_depth; |
| 567 return q == 0 ? 64 : (quant < 148 ? 84 : 80); |
| 568 #endif |
| 569 } |
| 570 |
283 void vp9_init_quantizer(VP9_COMP *cpi) { | 571 void vp9_init_quantizer(VP9_COMP *cpi) { |
284 VP9_COMMON *const cm = &cpi->common; | 572 VP9_COMMON *const cm = &cpi->common; |
285 QUANTS *const quants = &cpi->quants; | 573 QUANTS *const quants = &cpi->quants; |
286 int i, q, quant; | 574 int i, q, quant; |
287 | 575 |
288 for (q = 0; q < QINDEX_RANGE; q++) { | 576 for (q = 0; q < QINDEX_RANGE; q++) { |
289 const int qzbin_factor = q == 0 ? 64 : (vp9_dc_quant(q, 0) < 148 ? 84 : 80); | 577 const int qzbin_factor = get_qzbin_factor(q, cm->bit_depth); |
290 const int qrounding_factor = q == 0 ? 64 : 48; | 578 const int qrounding_factor = q == 0 ? 64 : 48; |
291 | 579 |
292 for (i = 0; i < 2; ++i) { | 580 for (i = 0; i < 2; ++i) { |
293 int qrounding_factor_fp = i == 0 ? 48 : 42; | 581 int qrounding_factor_fp = i == 0 ? 48 : 42; |
294 if (q == 0) | 582 if (q == 0) |
295 qrounding_factor_fp = 64; | 583 qrounding_factor_fp = 64; |
296 | 584 |
297 // y | 585 // y |
298 quant = i == 0 ? vp9_dc_quant(q, cm->y_dc_delta_q) | 586 quant = i == 0 ? vp9_dc_quant(q, cm->y_dc_delta_q, cm->bit_depth) |
299 : vp9_ac_quant(q, 0); | 587 : vp9_ac_quant(q, 0, cm->bit_depth); |
300 invert_quant(&quants->y_quant[q][i], &quants->y_quant_shift[q][i], quant); | 588 invert_quant(&quants->y_quant[q][i], &quants->y_quant_shift[q][i], quant); |
301 quants->y_quant_fp[q][i] = (1 << 16) / quant; | 589 quants->y_quant_fp[q][i] = (1 << 16) / quant; |
302 quants->y_round_fp[q][i] = (qrounding_factor_fp * quant) >> 7; | 590 quants->y_round_fp[q][i] = (qrounding_factor_fp * quant) >> 7; |
303 quants->y_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant, 7); | 591 quants->y_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant, 7); |
304 quants->y_round[q][i] = (qrounding_factor * quant) >> 7; | 592 quants->y_round[q][i] = (qrounding_factor * quant) >> 7; |
305 cm->y_dequant[q][i] = quant; | 593 cm->y_dequant[q][i] = quant; |
306 | 594 |
307 // uv | 595 // uv |
308 quant = i == 0 ? vp9_dc_quant(q, cm->uv_dc_delta_q) | 596 quant = i == 0 ? vp9_dc_quant(q, cm->uv_dc_delta_q, cm->bit_depth) |
309 : vp9_ac_quant(q, cm->uv_ac_delta_q); | 597 : vp9_ac_quant(q, cm->uv_ac_delta_q, cm->bit_depth); |
310 invert_quant(&quants->uv_quant[q][i], | 598 invert_quant(&quants->uv_quant[q][i], |
311 &quants->uv_quant_shift[q][i], quant); | 599 &quants->uv_quant_shift[q][i], quant); |
312 quants->uv_quant_fp[q][i] = (1 << 16) / quant; | 600 quants->uv_quant_fp[q][i] = (1 << 16) / quant; |
313 quants->uv_round_fp[q][i] = (qrounding_factor_fp * quant) >> 7; | 601 quants->uv_round_fp[q][i] = (qrounding_factor_fp * quant) >> 7; |
314 quants->uv_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant, 7); | 602 quants->uv_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant, 7); |
315 quants->uv_round[q][i] = (qrounding_factor * quant) >> 7; | 603 quants->uv_round[q][i] = (qrounding_factor * quant) >> 7; |
316 cm->uv_dequant[q][i] = quant; | 604 cm->uv_dequant[q][i] = quant; |
317 } | 605 } |
318 | 606 |
319 for (i = 2; i < 8; i++) { | 607 for (i = 2; i < 8; i++) { |
(...skipping 13 matching lines...) Expand all Loading... |
333 quants->uv_round[q][i] = quants->uv_round[q][1]; | 621 quants->uv_round[q][i] = quants->uv_round[q][1]; |
334 cm->uv_dequant[q][i] = cm->uv_dequant[q][1]; | 622 cm->uv_dequant[q][i] = cm->uv_dequant[q][1]; |
335 } | 623 } |
336 } | 624 } |
337 } | 625 } |
338 | 626 |
339 void vp9_init_plane_quantizers(VP9_COMP *cpi, MACROBLOCK *x) { | 627 void vp9_init_plane_quantizers(VP9_COMP *cpi, MACROBLOCK *x) { |
340 const VP9_COMMON *const cm = &cpi->common; | 628 const VP9_COMMON *const cm = &cpi->common; |
341 MACROBLOCKD *const xd = &x->e_mbd; | 629 MACROBLOCKD *const xd = &x->e_mbd; |
342 QUANTS *const quants = &cpi->quants; | 630 QUANTS *const quants = &cpi->quants; |
343 const int segment_id = xd->mi[0]->mbmi.segment_id; | 631 const int segment_id = xd->mi[0].src_mi->mbmi.segment_id; |
344 const int qindex = vp9_get_qindex(&cm->seg, segment_id, cm->base_qindex); | 632 const int qindex = vp9_get_qindex(&cm->seg, segment_id, cm->base_qindex); |
345 const int rdmult = vp9_compute_rd_mult(cpi, qindex + cm->y_dc_delta_q); | 633 const int rdmult = vp9_compute_rd_mult(cpi, qindex + cm->y_dc_delta_q); |
346 const int zbin = cpi->zbin_mode_boost; | 634 const int zbin = cpi->zbin_mode_boost; |
347 int i; | 635 int i; |
348 | 636 |
349 // Y | 637 // Y |
350 x->plane[0].quant = quants->y_quant[qindex]; | 638 x->plane[0].quant = quants->y_quant[qindex]; |
351 x->plane[0].quant_fp = quants->y_quant_fp[qindex]; | 639 x->plane[0].quant_fp = quants->y_quant_fp[qindex]; |
352 x->plane[0].round_fp = quants->y_round_fp[qindex]; | 640 x->plane[0].round_fp = quants->y_round_fp[qindex]; |
353 x->plane[0].quant_shift = quants->y_quant_shift[qindex]; | 641 x->plane[0].quant_shift = quants->y_quant_shift[qindex]; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 | 718 |
431 int vp9_qindex_to_quantizer(int qindex) { | 719 int vp9_qindex_to_quantizer(int qindex) { |
432 int quantizer; | 720 int quantizer; |
433 | 721 |
434 for (quantizer = 0; quantizer < 64; ++quantizer) | 722 for (quantizer = 0; quantizer < 64; ++quantizer) |
435 if (quantizer_to_qindex[quantizer] >= qindex) | 723 if (quantizer_to_qindex[quantizer] >= qindex) |
436 return quantizer; | 724 return quantizer; |
437 | 725 |
438 return 63; | 726 return 63; |
439 } | 727 } |
OLD | NEW |