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 | 11 |
12 #include "./vp9_rtcd.h" | 12 #include "./vp9_rtcd.h" |
13 #include "./vpx_config.h" | 13 #include "./vpx_config.h" |
14 | 14 |
15 #include "vpx_mem/vpx_mem.h" | 15 #include "vpx_mem/vpx_mem.h" |
16 | 16 |
17 #include "vp9/common/vp9_idct.h" | 17 #include "vp9/common/vp9_idct.h" |
18 #include "vp9/common/vp9_reconinter.h" | 18 #include "vp9/common/vp9_reconinter.h" |
19 #include "vp9/common/vp9_reconintra.h" | 19 #include "vp9/common/vp9_reconintra.h" |
20 #include "vp9/common/vp9_systemdependent.h" | 20 #include "vp9/common/vp9_systemdependent.h" |
21 | 21 |
22 #include "vp9/encoder/vp9_encodemb.h" | 22 #include "vp9/encoder/vp9_encodemb.h" |
23 #include "vp9/encoder/vp9_quantize.h" | 23 #include "vp9/encoder/vp9_quantize.h" |
24 #include "vp9/encoder/vp9_rdopt.h" | 24 #include "vp9/encoder/vp9_rd.h" |
25 #include "vp9/encoder/vp9_tokenize.h" | 25 #include "vp9/encoder/vp9_tokenize.h" |
26 | 26 |
27 struct optimize_ctx { | 27 struct optimize_ctx { |
28 ENTROPY_CONTEXT ta[MAX_MB_PLANE][16]; | 28 ENTROPY_CONTEXT ta[MAX_MB_PLANE][16]; |
29 ENTROPY_CONTEXT tl[MAX_MB_PLANE][16]; | 29 ENTROPY_CONTEXT tl[MAX_MB_PLANE][16]; |
30 }; | 30 }; |
31 | 31 |
32 struct encode_b_args { | 32 struct encode_b_args { |
33 MACROBLOCK *x; | 33 MACROBLOCK *x; |
34 struct optimize_ctx *ctx; | 34 struct optimize_ctx *ctx; |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 vp9_fdct32x32_rd(src, dst, src_stride); | 299 vp9_fdct32x32_rd(src, dst, src_stride); |
300 else | 300 else |
301 vp9_fdct32x32(src, dst, src_stride); | 301 vp9_fdct32x32(src, dst, src_stride); |
302 } | 302 } |
303 | 303 |
304 void vp9_xform_quant_fp(MACROBLOCK *x, int plane, int block, | 304 void vp9_xform_quant_fp(MACROBLOCK *x, int plane, int block, |
305 BLOCK_SIZE plane_bsize, TX_SIZE tx_size) { | 305 BLOCK_SIZE plane_bsize, TX_SIZE tx_size) { |
306 MACROBLOCKD *const xd = &x->e_mbd; | 306 MACROBLOCKD *const xd = &x->e_mbd; |
307 const struct macroblock_plane *const p = &x->plane[plane]; | 307 const struct macroblock_plane *const p = &x->plane[plane]; |
308 const struct macroblockd_plane *const pd = &xd->plane[plane]; | 308 const struct macroblockd_plane *const pd = &xd->plane[plane]; |
| 309 const scan_order *const scan_order = &vp9_default_scan_orders[tx_size]; |
309 int16_t *const coeff = BLOCK_OFFSET(p->coeff, block); | 310 int16_t *const coeff = BLOCK_OFFSET(p->coeff, block); |
310 int16_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block); | 311 int16_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block); |
311 int16_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); | 312 int16_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); |
312 uint16_t *const eob = &p->eobs[block]; | 313 uint16_t *const eob = &p->eobs[block]; |
313 const int diff_stride = 4 * num_4x4_blocks_wide_lookup[plane_bsize]; | 314 const int diff_stride = 4 * num_4x4_blocks_wide_lookup[plane_bsize]; |
314 int i, j; | 315 int i, j; |
315 const int16_t *src_diff; | 316 const int16_t *src_diff; |
| 317 txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &i, &j); |
| 318 src_diff = &p->src_diff[4 * (j * diff_stride + i)]; |
| 319 |
| 320 switch (tx_size) { |
| 321 case TX_32X32: |
| 322 fdct32x32(x->use_lp32x32fdct, src_diff, coeff, diff_stride); |
| 323 vp9_quantize_b_32x32(coeff, 1024, x->skip_block, p->zbin, p->round, |
| 324 p->quant, p->quant_shift, qcoeff, dqcoeff, |
| 325 pd->dequant, p->zbin_extra, eob, scan_order->scan, |
| 326 scan_order->iscan); |
| 327 break; |
| 328 case TX_16X16: |
| 329 vp9_fdct16x16(src_diff, coeff, diff_stride); |
| 330 vp9_quantize_fp(coeff, 256, x->skip_block, p->zbin, p->round_fp, |
| 331 p->quant_fp, p->quant_shift, qcoeff, dqcoeff, |
| 332 pd->dequant, p->zbin_extra, eob, |
| 333 scan_order->scan, scan_order->iscan); |
| 334 break; |
| 335 case TX_8X8: |
| 336 vp9_fdct8x8(src_diff, coeff, diff_stride); |
| 337 vp9_quantize_fp(coeff, 64, x->skip_block, p->zbin, p->round_fp, |
| 338 p->quant_fp, p->quant_shift, qcoeff, dqcoeff, |
| 339 pd->dequant, p->zbin_extra, eob, |
| 340 scan_order->scan, scan_order->iscan); |
| 341 break; |
| 342 case TX_4X4: |
| 343 x->fwd_txm4x4(src_diff, coeff, diff_stride); |
| 344 vp9_quantize_fp(coeff, 16, x->skip_block, p->zbin, p->round_fp, |
| 345 p->quant_fp, p->quant_shift, qcoeff, dqcoeff, |
| 346 pd->dequant, p->zbin_extra, eob, |
| 347 scan_order->scan, scan_order->iscan); |
| 348 break; |
| 349 default: |
| 350 assert(0); |
| 351 } |
| 352 } |
| 353 |
| 354 void vp9_xform_quant_dc(MACROBLOCK *x, int plane, int block, |
| 355 BLOCK_SIZE plane_bsize, TX_SIZE tx_size) { |
| 356 MACROBLOCKD *const xd = &x->e_mbd; |
| 357 const struct macroblock_plane *const p = &x->plane[plane]; |
| 358 const struct macroblockd_plane *const pd = &xd->plane[plane]; |
| 359 int16_t *const coeff = BLOCK_OFFSET(p->coeff, block); |
| 360 int16_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block); |
| 361 int16_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); |
| 362 uint16_t *const eob = &p->eobs[block]; |
| 363 const int diff_stride = 4 * num_4x4_blocks_wide_lookup[plane_bsize]; |
| 364 int i, j; |
| 365 const int16_t *src_diff; |
316 | 366 |
317 txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &i, &j); | 367 txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &i, &j); |
318 src_diff = &p->src_diff[4 * (j * diff_stride + i)]; | 368 src_diff = &p->src_diff[4 * (j * diff_stride + i)]; |
319 | 369 |
320 switch (tx_size) { | 370 switch (tx_size) { |
321 case TX_32X32: | 371 case TX_32X32: |
322 vp9_fdct32x32_1(src_diff, coeff, diff_stride); | 372 vp9_fdct32x32_1(src_diff, coeff, diff_stride); |
323 vp9_quantize_dc_32x32(coeff, x->skip_block, p->round, | 373 vp9_quantize_dc_32x32(coeff, x->skip_block, p->round, |
324 p->quant_fp[0], qcoeff, dqcoeff, | 374 p->quant_fp[0], qcoeff, dqcoeff, |
325 pd->dequant[0], eob); | 375 pd->dequant[0], eob); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 // TODO(jingning): per transformed block zero forcing only enabled for | 467 // TODO(jingning): per transformed block zero forcing only enabled for |
418 // luma component. will integrate chroma components as well. | 468 // luma component. will integrate chroma components as well. |
419 if (x->zcoeff_blk[tx_size][block] && plane == 0) { | 469 if (x->zcoeff_blk[tx_size][block] && plane == 0) { |
420 p->eobs[block] = 0; | 470 p->eobs[block] = 0; |
421 *a = *l = 0; | 471 *a = *l = 0; |
422 return; | 472 return; |
423 } | 473 } |
424 | 474 |
425 if (x->skip_txfm == 0) { | 475 if (x->skip_txfm == 0) { |
426 // full forward transform and quantization | 476 // full forward transform and quantization |
427 if (!x->skip_recode) | 477 if (!x->skip_recode) { |
428 vp9_xform_quant(x, plane, block, plane_bsize, tx_size); | 478 if (x->quant_fp) |
| 479 vp9_xform_quant_fp(x, plane, block, plane_bsize, tx_size); |
| 480 else |
| 481 vp9_xform_quant(x, plane, block, plane_bsize, tx_size); |
| 482 } |
429 } else if (x->skip_txfm == 2) { | 483 } else if (x->skip_txfm == 2) { |
430 // fast path forward transform and quantization | 484 // fast path forward transform and quantization |
431 vp9_xform_quant_fp(x, plane, block, plane_bsize, tx_size); | 485 vp9_xform_quant_dc(x, plane, block, plane_bsize, tx_size); |
432 } else { | 486 } else { |
433 // skip forward transform | 487 // skip forward transform |
434 p->eobs[block] = 0; | 488 p->eobs[block] = 0; |
435 *a = *l = 0; | 489 *a = *l = 0; |
436 return; | 490 return; |
437 } | 491 } |
438 | 492 |
439 if (x->optimize && (!x->skip_recode || !x->skip_optimize)) { | 493 if (x->optimize && (!x->skip_recode || !x->skip_optimize)) { |
440 const int ctx = combine_entropy_contexts(*a, *l); | 494 const int ctx = combine_entropy_contexts(*a, *l); |
441 *a = *l = optimize_b(x, plane, block, tx_size, ctx) > 0; | 495 *a = *l = optimize_b(x, plane, block, tx_size, ctx) > 0; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; | 554 MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; |
501 struct encode_b_args arg = {x, &ctx, &mbmi->skip}; | 555 struct encode_b_args arg = {x, &ctx, &mbmi->skip}; |
502 int plane; | 556 int plane; |
503 | 557 |
504 for (plane = 0; plane < MAX_MB_PLANE; ++plane) { | 558 for (plane = 0; plane < MAX_MB_PLANE; ++plane) { |
505 if (!x->skip_recode) | 559 if (!x->skip_recode) |
506 vp9_subtract_plane(x, bsize, plane); | 560 vp9_subtract_plane(x, bsize, plane); |
507 | 561 |
508 if (x->optimize && (!x->skip_recode || !x->skip_optimize)) { | 562 if (x->optimize && (!x->skip_recode || !x->skip_optimize)) { |
509 const struct macroblockd_plane* const pd = &xd->plane[plane]; | 563 const struct macroblockd_plane* const pd = &xd->plane[plane]; |
510 const TX_SIZE tx_size = plane ? get_uv_tx_size(mbmi) : mbmi->tx_size; | 564 const TX_SIZE tx_size = plane ? get_uv_tx_size(mbmi, pd) : mbmi->tx_size; |
511 vp9_get_entropy_contexts(bsize, tx_size, pd, | 565 vp9_get_entropy_contexts(bsize, tx_size, pd, |
512 ctx.ta[plane], ctx.tl[plane]); | 566 ctx.ta[plane], ctx.tl[plane]); |
513 } | 567 } |
514 | 568 |
515 vp9_foreach_transformed_block_in_plane(xd, bsize, plane, encode_block, | 569 vp9_foreach_transformed_block_in_plane(xd, bsize, plane, encode_block, |
516 &arg); | 570 &arg); |
517 } | 571 } |
518 } | 572 } |
519 | 573 |
520 static void encode_block_intra(int plane, int block, BLOCK_SIZE plane_bsize, | 574 static void encode_block_intra(int plane, int block, BLOCK_SIZE plane_bsize, |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 } | 705 } |
652 | 706 |
653 | 707 |
654 void vp9_encode_intra_block_plane(MACROBLOCK *x, BLOCK_SIZE bsize, int plane) { | 708 void vp9_encode_intra_block_plane(MACROBLOCK *x, BLOCK_SIZE bsize, int plane) { |
655 const MACROBLOCKD *const xd = &x->e_mbd; | 709 const MACROBLOCKD *const xd = &x->e_mbd; |
656 struct encode_b_args arg = {x, NULL, &xd->mi[0]->mbmi.skip}; | 710 struct encode_b_args arg = {x, NULL, &xd->mi[0]->mbmi.skip}; |
657 | 711 |
658 vp9_foreach_transformed_block_in_plane(xd, bsize, plane, encode_block_intra, | 712 vp9_foreach_transformed_block_in_plane(xd, bsize, plane, encode_block_intra, |
659 &arg); | 713 &arg); |
660 } | 714 } |
OLD | NEW |