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 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 7, 14, 11, 15, | 66 7, 14, 11, 15, |
67 }; | 67 }; |
68 | 68 |
69 DECLARE_ALIGNED(16, const int16_t, vp9_row_scan_4x4[16]) = { | 69 DECLARE_ALIGNED(16, const int16_t, vp9_row_scan_4x4[16]) = { |
70 0, 1, 4, 2, | 70 0, 1, 4, 2, |
71 5, 3, 6, 8, | 71 5, 3, 6, 8, |
72 9, 7, 12, 10, | 72 9, 7, 12, 10, |
73 13, 11, 14, 15, | 73 13, 11, 14, 15, |
74 }; | 74 }; |
75 | 75 |
76 DECLARE_ALIGNED(64, const int16_t, vp9_default_scan_8x8[64]) = { | 76 DECLARE_ALIGNED(16, const int16_t, vp9_default_scan_8x8[64]) = { |
77 0, 8, 1, 16, 9, 2, 17, 24, | 77 0, 8, 1, 16, 9, 2, 17, 24, |
78 10, 3, 18, 25, 32, 11, 4, 26, | 78 10, 3, 18, 25, 32, 11, 4, 26, |
79 33, 19, 40, 12, 34, 27, 5, 41, | 79 33, 19, 40, 12, 34, 27, 5, 41, |
80 20, 48, 13, 35, 42, 28, 21, 6, | 80 20, 48, 13, 35, 42, 28, 21, 6, |
81 49, 56, 36, 43, 29, 7, 14, 50, | 81 49, 56, 36, 43, 29, 7, 14, 50, |
82 57, 44, 22, 37, 15, 51, 58, 30, | 82 57, 44, 22, 37, 15, 51, 58, 30, |
83 45, 23, 52, 59, 38, 31, 60, 53, | 83 45, 23, 52, 59, 38, 31, 60, 53, |
84 46, 39, 61, 54, 47, 62, 55, 63, | 84 46, 39, 61, 54, 47, 62, 55, 63, |
85 }; | 85 }; |
86 | 86 |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 {255, 230, 233, 255, 231, 255, 252, 254}, | 370 {255, 230, 233, 255, 231, 255, 252, 254}, |
371 {255, 232, 235, 255, 232, 255, 252, 254}, | 371 {255, 232, 235, 255, 232, 255, 252, 254}, |
372 {255, 235, 237, 255, 233, 255, 252, 254}, | 372 {255, 235, 237, 255, 233, 255, 252, 254}, |
373 {255, 238, 240, 255, 235, 255, 252, 255}, | 373 {255, 238, 240, 255, 235, 255, 252, 255}, |
374 {255, 241, 243, 255, 236, 255, 252, 254}, | 374 {255, 241, 243, 255, 236, 255, 252, 254}, |
375 {255, 246, 247, 255, 239, 255, 253, 255} | 375 {255, 246, 247, 255, 239, 255, 253, 255} |
376 }; | 376 }; |
377 | 377 |
378 static void extend_model_to_full_distribution(vp9_prob p, | 378 static void extend_model_to_full_distribution(vp9_prob p, |
379 vp9_prob *tree_probs) { | 379 vp9_prob *tree_probs) { |
380 const int l = ((p - 1) / 2); | 380 const int l = (p - 1) / 2; |
381 const vp9_prob (*model)[MODEL_NODES] = modelcoefprobs_pareto8; | 381 const vp9_prob (*model)[MODEL_NODES] = modelcoefprobs_pareto8; |
382 if (p & 1) { | 382 if (p & 1) { |
383 vpx_memcpy(tree_probs + UNCONSTRAINED_NODES, | 383 vpx_memcpy(tree_probs + UNCONSTRAINED_NODES, |
384 model[l], MODEL_NODES * sizeof(vp9_prob)); | 384 model[l], MODEL_NODES * sizeof(vp9_prob)); |
385 } else { | 385 } else { |
386 // interpolate | 386 // interpolate |
387 int i; | 387 int i; |
388 for (i = UNCONSTRAINED_NODES; i < ENTROPY_NODES; ++i) | 388 for (i = UNCONSTRAINED_NODES; i < ENTROPY_NODES; ++i) |
389 tree_probs[i] = (model[l][i - UNCONSTRAINED_NODES] + | 389 tree_probs[i] = (model[l][i - UNCONSTRAINED_NODES] + |
390 model[l + 1][i - UNCONSTRAINED_NODES]) >> 1; | 390 model[l + 1][i - UNCONSTRAINED_NODES]) >> 1; |
(...skipping 21 matching lines...) Expand all Loading... |
412 | 412 |
413 static void init_bit_trees() { | 413 static void init_bit_trees() { |
414 init_bit_tree(cat1, 1); | 414 init_bit_tree(cat1, 1); |
415 init_bit_tree(cat2, 2); | 415 init_bit_tree(cat2, 2); |
416 init_bit_tree(cat3, 3); | 416 init_bit_tree(cat3, 3); |
417 init_bit_tree(cat4, 4); | 417 init_bit_tree(cat4, 4); |
418 init_bit_tree(cat5, 5); | 418 init_bit_tree(cat5, 5); |
419 init_bit_tree(cat6, 14); | 419 init_bit_tree(cat6, 14); |
420 } | 420 } |
421 | 421 |
422 vp9_extra_bit vp9_extra_bits[12] = { | 422 const vp9_extra_bit vp9_extra_bits[12] = { |
423 { 0, 0, 0, 0}, | 423 { 0, 0, 0, 0}, |
424 { 0, 0, 0, 1}, | 424 { 0, 0, 0, 1}, |
425 { 0, 0, 0, 2}, | 425 { 0, 0, 0, 2}, |
426 { 0, 0, 0, 3}, | 426 { 0, 0, 0, 3}, |
427 { 0, 0, 0, 4}, | 427 { 0, 0, 0, 4}, |
428 { cat1, Pcat1, 1, 5}, | 428 { cat1, Pcat1, 1, 5}, |
429 { cat2, Pcat2, 2, 7}, | 429 { cat2, Pcat2, 2, 7}, |
430 { cat3, Pcat3, 3, 11}, | 430 { cat3, Pcat3, 3, 11}, |
431 { cat4, Pcat4, 4, 19}, | 431 { cat4, Pcat4, 4, 19}, |
432 { cat5, Pcat5, 5, 35}, | 432 { cat5, Pcat5, 5, 35}, |
433 { cat6, Pcat6, 14, 67}, | 433 { cat6, Pcat6, 14, 67}, |
434 { 0, 0, 0, 0} | 434 { 0, 0, 0, 0} |
435 }; | 435 }; |
436 | 436 |
437 #include "vp9/common/vp9_default_coef_probs.h" | 437 #include "vp9/common/vp9_default_coef_probs.h" |
438 | 438 |
439 void vp9_default_coef_probs(VP9_COMMON *pc) { | 439 void vp9_default_coef_probs(VP9_COMMON *pc) { |
440 vpx_memcpy(pc->fc.coef_probs[TX_4X4], default_coef_probs_4x4, | 440 vp9_copy(pc->fc.coef_probs[TX_4X4], default_coef_probs_4x4); |
441 sizeof(pc->fc.coef_probs[TX_4X4])); | 441 vp9_copy(pc->fc.coef_probs[TX_8X8], default_coef_probs_8x8); |
442 vpx_memcpy(pc->fc.coef_probs[TX_8X8], default_coef_probs_8x8, | 442 vp9_copy(pc->fc.coef_probs[TX_16X16], default_coef_probs_16x16); |
443 sizeof(pc->fc.coef_probs[TX_8X8])); | 443 vp9_copy(pc->fc.coef_probs[TX_32X32], default_coef_probs_32x32); |
444 vpx_memcpy(pc->fc.coef_probs[TX_16X16], default_coef_probs_16x16, | |
445 sizeof(pc->fc.coef_probs[TX_16X16])); | |
446 vpx_memcpy(pc->fc.coef_probs[TX_32X32], default_coef_probs_32x32, | |
447 sizeof(pc->fc.coef_probs[TX_32X32])); | |
448 } | 444 } |
449 | 445 |
450 // Neighborhood 5-tuples for various scans and blocksizes, | 446 // Neighborhood 5-tuples for various scans and blocksizes, |
451 // in {top, left, topleft, topright, bottomleft} order | 447 // in {top, left, topleft, topright, bottomleft} order |
452 // for each position in raster scan order. | 448 // for each position in raster scan order. |
453 // -1 indicates the neighbor does not exist. | 449 // -1 indicates the neighbor does not exist. |
454 DECLARE_ALIGNED(16, int16_t, | 450 DECLARE_ALIGNED(16, int16_t, |
455 vp9_default_scan_4x4_neighbors[17 * MAX_NEIGHBORS]); | 451 vp9_default_scan_4x4_neighbors[17 * MAX_NEIGHBORS]); |
456 DECLARE_ALIGNED(16, int16_t, | 452 DECLARE_ALIGNED(16, int16_t, |
457 vp9_col_scan_4x4_neighbors[17 * MAX_NEIGHBORS]); | 453 vp9_col_scan_4x4_neighbors[17 * MAX_NEIGHBORS]); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 | 602 |
607 // #define COEF_COUNT_TESTING | 603 // #define COEF_COUNT_TESTING |
608 | 604 |
609 #define COEF_COUNT_SAT 24 | 605 #define COEF_COUNT_SAT 24 |
610 #define COEF_MAX_UPDATE_FACTOR 112 | 606 #define COEF_MAX_UPDATE_FACTOR 112 |
611 #define COEF_COUNT_SAT_KEY 24 | 607 #define COEF_COUNT_SAT_KEY 24 |
612 #define COEF_MAX_UPDATE_FACTOR_KEY 112 | 608 #define COEF_MAX_UPDATE_FACTOR_KEY 112 |
613 #define COEF_COUNT_SAT_AFTER_KEY 24 | 609 #define COEF_COUNT_SAT_AFTER_KEY 24 |
614 #define COEF_MAX_UPDATE_FACTOR_AFTER_KEY 128 | 610 #define COEF_MAX_UPDATE_FACTOR_AFTER_KEY 128 |
615 | 611 |
616 static void adapt_coef_probs(VP9_COMMON *cm, TX_SIZE txfm_size, | 612 static void adapt_coef_probs(VP9_COMMON *cm, TX_SIZE tx_size, |
617 int count_sat, int update_factor) { | 613 unsigned int count_sat, |
| 614 unsigned int update_factor) { |
618 FRAME_CONTEXT *pre_fc = &cm->frame_contexts[cm->frame_context_idx]; | 615 FRAME_CONTEXT *pre_fc = &cm->frame_contexts[cm->frame_context_idx]; |
619 | 616 |
620 vp9_coeff_probs_model *dst_coef_probs = cm->fc.coef_probs[txfm_size]; | 617 vp9_coeff_probs_model *dst_coef_probs = cm->fc.coef_probs[tx_size]; |
621 vp9_coeff_probs_model *pre_coef_probs = pre_fc->coef_probs[txfm_size]; | 618 vp9_coeff_probs_model *pre_coef_probs = pre_fc->coef_probs[tx_size]; |
622 vp9_coeff_count_model *coef_counts = cm->counts.coef[txfm_size]; | 619 vp9_coeff_count_model *coef_counts = cm->counts.coef[tx_size]; |
623 unsigned int (*eob_branch_count)[REF_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS] = | 620 unsigned int (*eob_branch_count)[REF_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS] = |
624 cm->counts.eob_branch[txfm_size]; | 621 cm->counts.eob_branch[tx_size]; |
625 int t, i, j, k, l, count; | 622 int t, i, j, k, l; |
626 int factor; | |
627 unsigned int branch_ct[UNCONSTRAINED_NODES][2]; | 623 unsigned int branch_ct[UNCONSTRAINED_NODES][2]; |
628 vp9_prob coef_probs[UNCONSTRAINED_NODES]; | 624 vp9_prob coef_probs[UNCONSTRAINED_NODES]; |
629 int entropy_nodes_adapt = UNCONSTRAINED_NODES; | |
630 | 625 |
631 for (i = 0; i < BLOCK_TYPES; ++i) | 626 for (i = 0; i < BLOCK_TYPES; ++i) |
632 for (j = 0; j < REF_TYPES; ++j) | 627 for (j = 0; j < REF_TYPES; ++j) |
633 for (k = 0; k < COEF_BANDS; ++k) | 628 for (k = 0; k < COEF_BANDS; ++k) |
634 for (l = 0; l < PREV_COEF_CONTEXTS; ++l) { | 629 for (l = 0; l < PREV_COEF_CONTEXTS; ++l) { |
635 if (l >= 3 && k == 0) | 630 if (l >= 3 && k == 0) |
636 continue; | 631 continue; |
637 vp9_tree_probs_from_distribution( | 632 vp9_tree_probs_from_distribution(vp9_coefmodel_tree, coef_probs, |
638 vp9_coefmodel_tree, | 633 branch_ct, coef_counts[i][j][k][l], |
639 coef_probs, branch_ct, | 634 0); |
640 coef_counts[i][j][k][l], 0); | |
641 branch_ct[0][1] = eob_branch_count[i][j][k][l] - branch_ct[0][0]; | 635 branch_ct[0][1] = eob_branch_count[i][j][k][l] - branch_ct[0][0]; |
642 coef_probs[0] = get_binary_prob(branch_ct[0][0], branch_ct[0][1]); | 636 coef_probs[0] = get_binary_prob(branch_ct[0][0], branch_ct[0][1]); |
643 for (t = 0; t < entropy_nodes_adapt; ++t) { | 637 for (t = 0; t < UNCONSTRAINED_NODES; ++t) |
644 count = branch_ct[t][0] + branch_ct[t][1]; | 638 dst_coef_probs[i][j][k][l][t] = merge_probs( |
645 count = count > count_sat ? count_sat : count; | 639 pre_coef_probs[i][j][k][l][t], coef_probs[t], |
646 factor = (update_factor * count / count_sat); | 640 branch_ct[t], count_sat, update_factor); |
647 dst_coef_probs[i][j][k][l][t] = | |
648 weighted_prob(pre_coef_probs[i][j][k][l][t], | |
649 coef_probs[t], factor); | |
650 } | |
651 } | 641 } |
652 } | 642 } |
653 | 643 |
654 void vp9_adapt_coef_probs(VP9_COMMON *cm) { | 644 void vp9_adapt_coef_probs(VP9_COMMON *cm) { |
655 TX_SIZE t; | 645 TX_SIZE t; |
656 int count_sat; | 646 unsigned int count_sat, update_factor; |
657 int update_factor; /* denominator 256 */ | |
658 | 647 |
659 if ((cm->frame_type == KEY_FRAME) || cm->intra_only) { | 648 if (cm->frame_type == KEY_FRAME || cm->intra_only) { |
660 update_factor = COEF_MAX_UPDATE_FACTOR_KEY; | 649 update_factor = COEF_MAX_UPDATE_FACTOR_KEY; |
661 count_sat = COEF_COUNT_SAT_KEY; | 650 count_sat = COEF_COUNT_SAT_KEY; |
662 } else if (cm->last_frame_type == KEY_FRAME) { | 651 } else if (cm->last_frame_type == KEY_FRAME) { |
663 update_factor = COEF_MAX_UPDATE_FACTOR_AFTER_KEY; /* adapt quickly */ | 652 update_factor = COEF_MAX_UPDATE_FACTOR_AFTER_KEY; /* adapt quickly */ |
664 count_sat = COEF_COUNT_SAT_AFTER_KEY; | 653 count_sat = COEF_COUNT_SAT_AFTER_KEY; |
665 } else { | 654 } else { |
666 update_factor = COEF_MAX_UPDATE_FACTOR; | 655 update_factor = COEF_MAX_UPDATE_FACTOR; |
667 count_sat = COEF_COUNT_SAT; | 656 count_sat = COEF_COUNT_SAT; |
668 } | 657 } |
669 for (t = TX_4X4; t <= TX_32X32; t++) | 658 for (t = TX_4X4; t <= TX_32X32; t++) |
670 adapt_coef_probs(cm, t, count_sat, update_factor); | 659 adapt_coef_probs(cm, t, count_sat, update_factor); |
671 } | 660 } |
OLD | NEW |