Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Side by Side Diff: source/libvpx/vp9/encoder/vp9_quantize.c

Issue 375983002: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_quantize.h ('k') | source/libvpx/vp9/encoder/vp9_ratectrl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_rdopt.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 int16_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 int16_t *qcoeff_ptr, int16_t *dqcoeff_ptr,
25 const int16_t dequant_ptr, uint16_t *eob_ptr) { 25 const int16_t dequant_ptr, uint16_t *eob_ptr) {
26 int eob = -1; 26 int eob = -1;
27 27
28 if (!skip_block) { 28 if (!skip_block) {
29 const int rc = 0; 29 const int rc = 0;
30 const int coeff = coeff_ptr[rc]; 30 const int coeff = coeff_ptr[rc];
31 const int coeff_sign = (coeff >> 31); 31 const int coeff_sign = (coeff >> 31);
32 const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; 32 const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign;
33 33
34 int tmp = clamp(abs_coeff + round_ptr[rc != 0], INT16_MIN, INT16_MAX); 34 int tmp = clamp(abs_coeff + round_ptr[rc != 0], INT16_MIN, INT16_MAX);
35 tmp = (tmp * quant) >> 16; 35 tmp = (tmp * quant) >> 16;
36 qcoeff_ptr[rc] = (tmp ^ coeff_sign) - coeff_sign; 36 qcoeff_ptr[rc] = (tmp ^ coeff_sign) - coeff_sign;
37 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr; 37 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr;
38 if (tmp) 38 if (tmp)
39 eob = 0; 39 eob = 0;
40 } 40 }
41 *eob_ptr = eob + 1; 41 *eob_ptr = eob + 1;
42 } 42 }
43 43
44 void vp9_quantize_dc_32x32(const int16_t *coeff_ptr, int skip_block, 44 void vp9_quantize_dc_32x32(const int16_t *coeff_ptr, int skip_block,
45 const int16_t *round_ptr, const int16_t quant, 45 const int16_t *round_ptr, const int16_t quant,
46 int16_t *qcoeff_ptr, int16_t *dqcoeff_ptr, 46 int16_t *qcoeff_ptr, int16_t *dqcoeff_ptr,
47 const int16_t dequant_ptr, uint16_t *eob_ptr) { 47 const int16_t dequant_ptr, uint16_t *eob_ptr) {
48 int eob = -1; 48 int eob = -1;
49 49
50 if (!skip_block) { 50 if (!skip_block) {
51 const int rc = 0; 51 const int rc = 0;
52 const int coeff = coeff_ptr[rc]; 52 const int coeff = coeff_ptr[rc];
53 const int coeff_sign = (coeff >> 31); 53 const int coeff_sign = (coeff >> 31);
54 const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; 54 const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign;
55 55
56 int tmp = clamp(abs_coeff + round_ptr[rc != 0], INT16_MIN, INT16_MAX); 56 int tmp = clamp(abs_coeff + round_ptr[rc != 0], INT16_MIN, INT16_MAX);
57 tmp = (tmp * quant) >> 15; 57 tmp = (tmp * quant) >> 15;
58 qcoeff_ptr[rc] = (tmp ^ coeff_sign) - coeff_sign; 58 qcoeff_ptr[rc] = (tmp ^ coeff_sign) - coeff_sign;
59 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr / 2; 59 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr / 2;
60 if (tmp) 60 if (tmp)
61 eob = 0; 61 eob = 0;
62 } 62 }
63 *eob_ptr = eob + 1; 63 *eob_ptr = eob + 1;
64 } 64 }
65 65
66 void vp9_quantize_fp_c(const int16_t *coeff_ptr, intptr_t count,
67 int skip_block,
68 const int16_t *zbin_ptr, const int16_t *round_ptr,
69 const int16_t *quant_ptr, const int16_t *quant_shift_ptr,
70 int16_t *qcoeff_ptr, int16_t *dqcoeff_ptr,
71 const int16_t *dequant_ptr,
72 int zbin_oq_value, uint16_t *eob_ptr,
73 const int16_t *scan, const int16_t *iscan) {
74 int i, eob = -1;
75 // TODO(jingning) Decide the need of these arguments after the
76 // quantization process is completed.
77 (void)zbin_ptr;
78 (void)quant_shift_ptr;
79 (void)zbin_oq_value;
80 (void)iscan;
81
82 vpx_memset(qcoeff_ptr, 0, count * sizeof(int16_t));
83 vpx_memset(dqcoeff_ptr, 0, count * sizeof(int16_t));
84
85 if (!skip_block) {
86 // Quantization pass: All coefficients with index >= zero_flag are
87 // skippable. Note: zero_flag can be zero.
88 for (i = 0; i < count; i++) {
89 const int rc = scan[i];
90 const int coeff = coeff_ptr[rc];
91 const int coeff_sign = (coeff >> 31);
92 const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign;
93
94 int tmp = clamp(abs_coeff + round_ptr[rc != 0], INT16_MIN, INT16_MAX);
95 tmp = (tmp * quant_ptr[rc != 0]) >> 16;
96
97 qcoeff_ptr[rc] = (tmp ^ coeff_sign) - coeff_sign;
98 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr[rc != 0];
99
100 if (tmp)
101 eob = i;
102 }
103 }
104 *eob_ptr = eob + 1;
105 }
106
66 void vp9_quantize_b_c(const int16_t *coeff_ptr, intptr_t count, 107 void vp9_quantize_b_c(const int16_t *coeff_ptr, intptr_t count,
67 int skip_block, 108 int skip_block,
68 const int16_t *zbin_ptr, const int16_t *round_ptr, 109 const int16_t *zbin_ptr, const int16_t *round_ptr,
69 const int16_t *quant_ptr, const int16_t *quant_shift_ptr, 110 const int16_t *quant_ptr, const int16_t *quant_shift_ptr,
70 int16_t *qcoeff_ptr, int16_t *dqcoeff_ptr, 111 int16_t *qcoeff_ptr, int16_t *dqcoeff_ptr,
71 const int16_t *dequant_ptr, 112 const int16_t *dequant_ptr,
72 int zbin_oq_value, uint16_t *eob_ptr, 113 int zbin_oq_value, uint16_t *eob_ptr,
73 const int16_t *scan, const int16_t *iscan) { 114 const int16_t *scan, const int16_t *iscan) {
74 int i, non_zero_count = (int)count, eob = -1; 115 int i, non_zero_count = (int)count, eob = -1;
75 const int zbins[2] = { zbin_ptr[0] + zbin_oq_value, 116 const int zbins[2] = { zbin_ptr[0] + zbin_oq_value,
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 void vp9_init_quantizer(VP9_COMP *cpi) { 241 void vp9_init_quantizer(VP9_COMP *cpi) {
201 VP9_COMMON *const cm = &cpi->common; 242 VP9_COMMON *const cm = &cpi->common;
202 QUANTS *const quants = &cpi->quants; 243 QUANTS *const quants = &cpi->quants;
203 int i, q, quant; 244 int i, q, quant;
204 245
205 for (q = 0; q < QINDEX_RANGE; q++) { 246 for (q = 0; q < QINDEX_RANGE; q++) {
206 const int qzbin_factor = q == 0 ? 64 : (vp9_dc_quant(q, 0) < 148 ? 84 : 80); 247 const int qzbin_factor = q == 0 ? 64 : (vp9_dc_quant(q, 0) < 148 ? 84 : 80);
207 const int qrounding_factor = q == 0 ? 64 : 48; 248 const int qrounding_factor = q == 0 ? 64 : 48;
208 249
209 for (i = 0; i < 2; ++i) { 250 for (i = 0; i < 2; ++i) {
251 int qrounding_factor_fp = i == 0 ? 48 : 42;
252 if (q == 0)
253 qrounding_factor_fp = 64;
254
210 // y 255 // y
211 quant = i == 0 ? vp9_dc_quant(q, cm->y_dc_delta_q) 256 quant = i == 0 ? vp9_dc_quant(q, cm->y_dc_delta_q)
212 : vp9_ac_quant(q, 0); 257 : vp9_ac_quant(q, 0);
213 invert_quant(&quants->y_quant[q][i], &quants->y_quant_shift[q][i], quant); 258 invert_quant(&quants->y_quant[q][i], &quants->y_quant_shift[q][i], quant);
214 quants->y_quant_fp[q][i] = (1 << 16) / quant; 259 quants->y_quant_fp[q][i] = (1 << 16) / quant;
260 quants->y_round_fp[q][i] = (qrounding_factor_fp * quant) >> 7;
215 quants->y_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant, 7); 261 quants->y_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant, 7);
216 quants->y_round[q][i] = (qrounding_factor * quant) >> 7; 262 quants->y_round[q][i] = (qrounding_factor * quant) >> 7;
217 cm->y_dequant[q][i] = quant; 263 cm->y_dequant[q][i] = quant;
218 264
219 // uv 265 // uv
220 quant = i == 0 ? vp9_dc_quant(q, cm->uv_dc_delta_q) 266 quant = i == 0 ? vp9_dc_quant(q, cm->uv_dc_delta_q)
221 : vp9_ac_quant(q, cm->uv_ac_delta_q); 267 : vp9_ac_quant(q, cm->uv_ac_delta_q);
222 invert_quant(&quants->uv_quant[q][i], 268 invert_quant(&quants->uv_quant[q][i],
223 &quants->uv_quant_shift[q][i], quant); 269 &quants->uv_quant_shift[q][i], quant);
224 quants->uv_quant_fp[q][i] = (1 << 16) / quant; 270 quants->uv_quant_fp[q][i] = (1 << 16) / quant;
271 quants->uv_round_fp[q][i] = (qrounding_factor_fp * quant) >> 7;
225 quants->uv_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant, 7); 272 quants->uv_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant, 7);
226 quants->uv_round[q][i] = (qrounding_factor * quant) >> 7; 273 quants->uv_round[q][i] = (qrounding_factor * quant) >> 7;
227 cm->uv_dequant[q][i] = quant; 274 cm->uv_dequant[q][i] = quant;
228 275
229 #if CONFIG_ALPHA 276 #if CONFIG_ALPHA
230 // alpha 277 // alpha
231 quant = i == 0 ? vp9_dc_quant(q, cm->a_dc_delta_q) 278 quant = i == 0 ? vp9_dc_quant(q, cm->a_dc_delta_q)
232 : vp9_ac_quant(q, cm->a_ac_delta_q); 279 : vp9_ac_quant(q, cm->a_ac_delta_q);
233 invert_quant(&quants->a_quant[q][i], &quants->a_quant_shift[q][i], quant); 280 invert_quant(&quants->a_quant[q][i], &quants->a_quant_shift[q][i], quant);
234 quants->a_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant, 7); 281 quants->a_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant, 7);
235 quants->a_round[q][i] = (qrounding_factor * quant) >> 7; 282 quants->a_round[q][i] = (qrounding_factor * quant) >> 7;
236 cm->a_dequant[q][i] = quant; 283 cm->a_dequant[q][i] = quant;
237 #endif 284 #endif
238 } 285 }
239 286
240 for (i = 2; i < 8; i++) { 287 for (i = 2; i < 8; i++) {
241 quants->y_quant[q][i] = quants->y_quant[q][1]; 288 quants->y_quant[q][i] = quants->y_quant[q][1];
242 quants->y_quant_fp[q][i] = quants->y_quant_fp[q][1]; 289 quants->y_quant_fp[q][i] = quants->y_quant_fp[q][1];
290 quants->y_round_fp[q][i] = quants->y_round_fp[q][1];
243 quants->y_quant_shift[q][i] = quants->y_quant_shift[q][1]; 291 quants->y_quant_shift[q][i] = quants->y_quant_shift[q][1];
244 quants->y_zbin[q][i] = quants->y_zbin[q][1]; 292 quants->y_zbin[q][i] = quants->y_zbin[q][1];
245 quants->y_round[q][i] = quants->y_round[q][1]; 293 quants->y_round[q][i] = quants->y_round[q][1];
246 cm->y_dequant[q][i] = cm->y_dequant[q][1]; 294 cm->y_dequant[q][i] = cm->y_dequant[q][1];
247 295
248 quants->uv_quant[q][i] = quants->uv_quant[q][1]; 296 quants->uv_quant[q][i] = quants->uv_quant[q][1];
249 quants->uv_quant_fp[q][i] = quants->uv_quant_fp[q][1]; 297 quants->uv_quant_fp[q][i] = quants->uv_quant_fp[q][1];
298 quants->uv_round_fp[q][i] = quants->uv_round_fp[q][1];
250 quants->uv_quant_shift[q][i] = quants->uv_quant_shift[q][1]; 299 quants->uv_quant_shift[q][i] = quants->uv_quant_shift[q][1];
251 quants->uv_zbin[q][i] = quants->uv_zbin[q][1]; 300 quants->uv_zbin[q][i] = quants->uv_zbin[q][1];
252 quants->uv_round[q][i] = quants->uv_round[q][1]; 301 quants->uv_round[q][i] = quants->uv_round[q][1];
253 cm->uv_dequant[q][i] = cm->uv_dequant[q][1]; 302 cm->uv_dequant[q][i] = cm->uv_dequant[q][1];
254 303
255 #if CONFIG_ALPHA 304 #if CONFIG_ALPHA
256 quants->a_quant[q][i] = quants->a_quant[q][1]; 305 quants->a_quant[q][i] = quants->a_quant[q][1];
257 quants->a_quant_shift[q][i] = quants->a_quant_shift[q][1]; 306 quants->a_quant_shift[q][i] = quants->a_quant_shift[q][1];
258 quants->a_zbin[q][i] = quants->a_zbin[q][1]; 307 quants->a_zbin[q][i] = quants->a_zbin[q][1];
259 quants->a_round[q][i] = quants->a_round[q][1]; 308 quants->a_round[q][i] = quants->a_round[q][1];
260 cm->a_dequant[q][i] = cm->a_dequant[q][1]; 309 cm->a_dequant[q][i] = cm->a_dequant[q][1];
261 #endif 310 #endif
262 } 311 }
263 } 312 }
264 } 313 }
265 314
266 void vp9_init_plane_quantizers(VP9_COMP *cpi, MACROBLOCK *x) { 315 void vp9_init_plane_quantizers(VP9_COMP *cpi, MACROBLOCK *x) {
267 const VP9_COMMON *const cm = &cpi->common; 316 const VP9_COMMON *const cm = &cpi->common;
268 MACROBLOCKD *const xd = &x->e_mbd; 317 MACROBLOCKD *const xd = &x->e_mbd;
269 QUANTS *const quants = &cpi->quants; 318 QUANTS *const quants = &cpi->quants;
270 const int segment_id = xd->mi[0]->mbmi.segment_id; 319 const int segment_id = xd->mi[0]->mbmi.segment_id;
271 const int qindex = vp9_get_qindex(&cm->seg, segment_id, cm->base_qindex); 320 const int qindex = vp9_get_qindex(&cm->seg, segment_id, cm->base_qindex);
272 const int rdmult = vp9_compute_rd_mult(cpi, qindex + cm->y_dc_delta_q); 321 const int rdmult = vp9_compute_rd_mult(cpi, qindex + cm->y_dc_delta_q);
273 const int zbin = cpi->zbin_mode_boost; 322 const int zbin = cpi->zbin_mode_boost;
274 int i; 323 int i;
275 324
276 // Y 325 // Y
277 x->plane[0].quant = quants->y_quant[qindex]; 326 x->plane[0].quant = quants->y_quant[qindex];
278 x->plane[0].quant_fp = quants->y_quant_fp[qindex]; 327 x->plane[0].quant_fp = quants->y_quant_fp[qindex];
328 x->plane[0].round_fp = quants->y_round_fp[qindex];
279 x->plane[0].quant_shift = quants->y_quant_shift[qindex]; 329 x->plane[0].quant_shift = quants->y_quant_shift[qindex];
280 x->plane[0].zbin = quants->y_zbin[qindex]; 330 x->plane[0].zbin = quants->y_zbin[qindex];
281 x->plane[0].round = quants->y_round[qindex]; 331 x->plane[0].round = quants->y_round[qindex];
282 x->plane[0].zbin_extra = (int16_t)((cm->y_dequant[qindex][1] * zbin) >> 7); 332 x->plane[0].zbin_extra = (int16_t)((cm->y_dequant[qindex][1] * zbin) >> 7);
283 xd->plane[0].dequant = cm->y_dequant[qindex]; 333 xd->plane[0].dequant = cm->y_dequant[qindex];
284 334
285 // UV 335 // UV
286 for (i = 1; i < 3; i++) { 336 for (i = 1; i < 3; i++) {
287 x->plane[i].quant = quants->uv_quant[qindex]; 337 x->plane[i].quant = quants->uv_quant[qindex];
288 x->plane[i].quant_fp = quants->uv_quant_fp[qindex]; 338 x->plane[i].quant_fp = quants->uv_quant_fp[qindex];
339 x->plane[i].round_fp = quants->uv_round_fp[qindex];
289 x->plane[i].quant_shift = quants->uv_quant_shift[qindex]; 340 x->plane[i].quant_shift = quants->uv_quant_shift[qindex];
290 x->plane[i].zbin = quants->uv_zbin[qindex]; 341 x->plane[i].zbin = quants->uv_zbin[qindex];
291 x->plane[i].round = quants->uv_round[qindex]; 342 x->plane[i].round = quants->uv_round[qindex];
292 x->plane[i].zbin_extra = (int16_t)((cm->uv_dequant[qindex][1] * zbin) >> 7); 343 x->plane[i].zbin_extra = (int16_t)((cm->uv_dequant[qindex][1] * zbin) >> 7);
293 xd->plane[i].dequant = cm->uv_dequant[qindex]; 344 xd->plane[i].dequant = cm->uv_dequant[qindex];
294 } 345 }
295 346
296 #if CONFIG_ALPHA 347 #if CONFIG_ALPHA
297 x->plane[3].quant = quants->a_quant[qindex]; 348 x->plane[3].quant = quants->a_quant[qindex];
298 x->plane[3].quant_shift = quants->a_quant_shift[qindex]; 349 x->plane[3].quant_shift = quants->a_quant_shift[qindex];
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 407
357 int vp9_qindex_to_quantizer(int qindex) { 408 int vp9_qindex_to_quantizer(int qindex) {
358 int quantizer; 409 int quantizer;
359 410
360 for (quantizer = 0; quantizer < 64; ++quantizer) 411 for (quantizer = 0; quantizer < 64; ++quantizer)
361 if (quantizer_to_qindex[quantizer] >= qindex) 412 if (quantizer_to_qindex[quantizer] >= qindex)
362 return quantizer; 413 return quantizer;
363 414
364 return 63; 415 return 63;
365 } 416 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_quantize.h ('k') | source/libvpx/vp9/encoder/vp9_ratectrl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698