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 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 const int rc = 0; |
| 27 const int coeff = coeff_ptr[rc]; |
| 28 const int coeff_sign = (coeff >> 31); |
| 29 const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; |
| 30 int tmp, eob = -1; |
27 | 31 |
28 if (!skip_block) { | 32 if (!skip_block) { |
29 const int rc = 0; | 33 tmp = clamp(abs_coeff + round_ptr[rc != 0], INT16_MIN, INT16_MAX); |
30 const int coeff = coeff_ptr[rc]; | |
31 const int coeff_sign = (coeff >> 31); | |
32 const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; | |
33 | |
34 int tmp = clamp(abs_coeff + round_ptr[rc != 0], INT16_MIN, INT16_MAX); | |
35 tmp = (tmp * quant) >> 16; | 34 tmp = (tmp * quant) >> 16; |
36 qcoeff_ptr[rc] = (tmp ^ coeff_sign) - coeff_sign; | 35 qcoeff_ptr[rc] = (tmp ^ coeff_sign) - coeff_sign; |
37 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr; | 36 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr; |
38 if (tmp) | 37 if (tmp) |
39 eob = 0; | 38 eob = 0; |
40 } | 39 } |
41 *eob_ptr = eob + 1; | 40 *eob_ptr = eob + 1; |
42 } | 41 } |
43 | 42 |
44 void vp9_quantize_dc_32x32(const int16_t *coeff_ptr, int skip_block, | 43 void vp9_quantize_dc_32x32(const int16_t *coeff_ptr, int skip_block, |
45 const int16_t *round_ptr, const int16_t quant, | 44 const int16_t *round_ptr, const int16_t quant, |
46 int16_t *qcoeff_ptr, int16_t *dqcoeff_ptr, | 45 int16_t *qcoeff_ptr, int16_t *dqcoeff_ptr, |
47 const int16_t dequant_ptr, uint16_t *eob_ptr) { | 46 const int16_t dequant_ptr, uint16_t *eob_ptr) { |
48 int eob = -1; | 47 const int rc = 0; |
| 48 const int coeff = coeff_ptr[rc]; |
| 49 const int coeff_sign = (coeff >> 31); |
| 50 const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; |
| 51 int tmp, eob = -1; |
49 | 52 |
50 if (!skip_block) { | 53 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 | 54 |
56 int tmp = clamp(abs_coeff + round_ptr[rc != 0], INT16_MIN, INT16_MAX); | 55 tmp = clamp(abs_coeff + round_ptr[rc != 0], INT16_MIN, INT16_MAX); |
57 tmp = (tmp * quant) >> 15; | 56 tmp = (tmp * quant) >> 15; |
58 qcoeff_ptr[rc] = (tmp ^ coeff_sign) - coeff_sign; | 57 qcoeff_ptr[rc] = (tmp ^ coeff_sign) - coeff_sign; |
59 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr / 2; | 58 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr / 2; |
60 if (tmp) | 59 if (tmp) |
61 eob = 0; | 60 eob = 0; |
62 } | 61 } |
63 *eob_ptr = eob + 1; | 62 *eob_ptr = eob + 1; |
64 } | 63 } |
65 | 64 |
66 void vp9_quantize_fp_c(const int16_t *coeff_ptr, intptr_t count, | 65 void vp9_quantize_fp_c(const int16_t *coeff_ptr, intptr_t count, |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 const int zbin = cpi->zbin_mode_boost; | 346 const int zbin = cpi->zbin_mode_boost; |
348 int i; | 347 int i; |
349 | 348 |
350 // Y | 349 // Y |
351 x->plane[0].quant = quants->y_quant[qindex]; | 350 x->plane[0].quant = quants->y_quant[qindex]; |
352 x->plane[0].quant_fp = quants->y_quant_fp[qindex]; | 351 x->plane[0].quant_fp = quants->y_quant_fp[qindex]; |
353 x->plane[0].round_fp = quants->y_round_fp[qindex]; | 352 x->plane[0].round_fp = quants->y_round_fp[qindex]; |
354 x->plane[0].quant_shift = quants->y_quant_shift[qindex]; | 353 x->plane[0].quant_shift = quants->y_quant_shift[qindex]; |
355 x->plane[0].zbin = quants->y_zbin[qindex]; | 354 x->plane[0].zbin = quants->y_zbin[qindex]; |
356 x->plane[0].round = quants->y_round[qindex]; | 355 x->plane[0].round = quants->y_round[qindex]; |
| 356 x->plane[0].quant_thred[0] = cm->y_dequant[qindex][0] * |
| 357 cm->y_dequant[qindex][0]; |
| 358 x->plane[0].quant_thred[1] = cm->y_dequant[qindex][1] * |
| 359 cm->y_dequant[qindex][1]; |
357 x->plane[0].zbin_extra = (int16_t)((cm->y_dequant[qindex][1] * zbin) >> 7); | 360 x->plane[0].zbin_extra = (int16_t)((cm->y_dequant[qindex][1] * zbin) >> 7); |
358 xd->plane[0].dequant = cm->y_dequant[qindex]; | 361 xd->plane[0].dequant = cm->y_dequant[qindex]; |
359 | 362 |
360 // UV | 363 // UV |
361 for (i = 1; i < 3; i++) { | 364 for (i = 1; i < 3; i++) { |
362 x->plane[i].quant = quants->uv_quant[qindex]; | 365 x->plane[i].quant = quants->uv_quant[qindex]; |
363 x->plane[i].quant_fp = quants->uv_quant_fp[qindex]; | 366 x->plane[i].quant_fp = quants->uv_quant_fp[qindex]; |
364 x->plane[i].round_fp = quants->uv_round_fp[qindex]; | 367 x->plane[i].round_fp = quants->uv_round_fp[qindex]; |
365 x->plane[i].quant_shift = quants->uv_quant_shift[qindex]; | 368 x->plane[i].quant_shift = quants->uv_quant_shift[qindex]; |
366 x->plane[i].zbin = quants->uv_zbin[qindex]; | 369 x->plane[i].zbin = quants->uv_zbin[qindex]; |
367 x->plane[i].round = quants->uv_round[qindex]; | 370 x->plane[i].round = quants->uv_round[qindex]; |
| 371 x->plane[i].quant_thred[0] = cm->y_dequant[qindex][0] * |
| 372 cm->y_dequant[qindex][0]; |
| 373 x->plane[i].quant_thred[1] = cm->y_dequant[qindex][1] * |
| 374 cm->y_dequant[qindex][1]; |
368 x->plane[i].zbin_extra = (int16_t)((cm->uv_dequant[qindex][1] * zbin) >> 7); | 375 x->plane[i].zbin_extra = (int16_t)((cm->uv_dequant[qindex][1] * zbin) >> 7); |
369 xd->plane[i].dequant = cm->uv_dequant[qindex]; | 376 xd->plane[i].dequant = cm->uv_dequant[qindex]; |
370 } | 377 } |
371 | 378 |
372 x->skip_block = vp9_segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP); | 379 x->skip_block = vp9_segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP); |
373 x->q_index = qindex; | 380 x->q_index = qindex; |
374 | 381 |
375 x->errorperbit = rdmult >> 6; | 382 x->errorperbit = rdmult >> 6; |
376 x->errorperbit += (x->errorperbit == 0); | 383 x->errorperbit += (x->errorperbit == 0); |
377 | 384 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 | 430 |
424 int vp9_qindex_to_quantizer(int qindex) { | 431 int vp9_qindex_to_quantizer(int qindex) { |
425 int quantizer; | 432 int quantizer; |
426 | 433 |
427 for (quantizer = 0; quantizer < 64; ++quantizer) | 434 for (quantizer = 0; quantizer < 64; ++quantizer) |
428 if (quantizer_to_qindex[quantizer] >= qindex) | 435 if (quantizer_to_qindex[quantizer] >= qindex) |
429 return quantizer; | 436 return quantizer; |
430 | 437 |
431 return 63; | 438 return 63; |
432 } | 439 } |
OLD | NEW |