diff --git a/vp9/common/vp9_blockd.h b/vp9/common/vp9_blockd.h index 05b4fda1b..d7419e449 100644 --- a/vp9/common/vp9_blockd.h +++ b/vp9/common/vp9_blockd.h @@ -21,6 +21,7 @@ #include "vp9/common/vp9_common.h" #include "vp9/common/vp9_enums.h" +#define BLOCK_SIZE_GROUPS 4 #define MAX_MB_SEGMENTS 8 #define MB_SEG_TREE_PROBS (MAX_MB_SEGMENTS-1) #define PREDICTION_PROBS 3 @@ -55,7 +56,8 @@ static INLINE int combine_entropy_contexts(ENTROPY_CONTEXT a, typedef enum { KEY_FRAME = 0, - INTER_FRAME = 1 + INTER_FRAME = 1, + NUM_FRAME_TYPES, } FRAME_TYPE; typedef enum { diff --git a/vp9/common/vp9_entropymode.c b/vp9/common/vp9_entropymode.c index 5f4d20789..411388afa 100644 --- a/vp9/common/vp9_entropymode.c +++ b/vp9/common/vp9_entropymode.c @@ -15,58 +15,87 @@ #include "vp9/common/vp9_alloccommon.h" #include "vpx_mem/vpx_mem.h" -static const unsigned int y_mode_cts[VP9_INTRA_MODES] = { - /* DC V H D45 D135 D117 D153 D27 D63 TM */ - 98, 19, 15, 14, 14, 14, 14, 12, 12, 13, +static const vp9_prob default_kf_uv_probs[VP9_INTRA_MODES] + [VP9_INTRA_MODES - 1] = { + { 149, 13, 48, 141, 174, 131, 54, 61, 109 } /* y = dc */, + { 120, 17, 119, 132, 103, 103, 54, 100, 130 } /* y = v */, + { 114, 16, 19, 177, 220, 145, 31, 33, 122 } /* y = h */, + { 119, 12, 43, 102, 133, 133, 77, 90, 102 } /* y = d45 */, + { 110, 10, 28, 144, 78, 158, 40, 49, 161 } /* y = d135 */, + { 114, 10, 46, 169, 50, 96, 48, 70, 150 } /* y = d117 */, + { 116, 10, 24, 125, 134, 168, 26, 27, 193 } /* y = d153 */, + { 121, 14, 26, 124, 175, 143, 36, 37, 79 } /* y = d27 */, + { 116, 13, 54, 100, 105, 122, 58, 126, 122 } /* y = d63 */, + { 98, 22, 60, 147, 159, 124, 45, 68, 128 } /* y = tm */ }; -static const unsigned int uv_mode_cts[VP9_INTRA_MODES][VP9_INTRA_MODES] = { - /* DC V H D45 135 117 153 D27 D63 TM */ - { 200, 15, 15, 10, 10, 10, 10, 10, 10, 6}, /* DC */ - { 130, 75, 10, 10, 10, 10, 10, 10, 10, 6}, /* V */ - { 130, 10, 75, 10, 10, 10, 10, 10, 10, 6}, /* H */ - { 130, 15, 10, 75, 10, 10, 10, 10, 10, 6}, /* D45 */ - { 150, 15, 10, 10, 75, 10, 10, 10, 10, 6}, /* D135 */ - { 150, 15, 10, 10, 10, 75, 10, 10, 10, 6}, /* D117 */ - { 150, 15, 10, 10, 10, 10, 75, 10, 10, 6}, /* D153 */ - { 150, 15, 10, 10, 10, 10, 10, 75, 10, 6}, /* D27 */ - { 150, 15, 10, 10, 10, 10, 10, 10, 75, 6}, /* D63 */ - { 160, 30, 30, 10, 10, 10, 10, 10, 10, 16}, /* TM */ +static const vp9_prob default_if_y_probs[BLOCK_SIZE_GROUPS] + [VP9_INTRA_MODES - 1] = { + { 42, 31, 23, 150, 161, 193, 32, 53, 100 } /* block_size < 8x8 */, + { 132, 58, 30, 160, 209, 195, 52, 47, 76 } /* block_size < 16x16 */, + { 179, 85, 24, 168, 236, 198, 87, 45, 46 } /* block_size < 32x32 */, + { 221, 176, 63, 133, 233, 121, 125, 105, 34 } /* block_size >= 32x32 */ }; -static const unsigned int kf_uv_mode_cts[VP9_INTRA_MODES][VP9_INTRA_MODES] = { - // DC V H D45 135 117 153 D27 D63 TM - { 160, 24, 24, 20, 20, 20, 20, 20, 20, 8}, /* DC */ - { 102, 64, 30, 20, 20, 20, 20, 20, 20, 10}, /* V */ - { 102, 30, 64, 20, 20, 20, 20, 20, 20, 10}, /* H */ - { 102, 33, 20, 64, 20, 20, 20, 20, 20, 14}, /* D45 */ - { 102, 33, 20, 20, 64, 20, 20, 20, 20, 14}, /* D135 */ - { 122, 33, 20, 20, 20, 64, 20, 20, 20, 14}, /* D117 */ - { 102, 33, 20, 20, 20, 20, 64, 20, 20, 14}, /* D153 */ - { 102, 33, 20, 20, 20, 20, 20, 64, 20, 14}, /* D27 */ - { 102, 33, 20, 20, 20, 20, 20, 20, 64, 14}, /* D63 */ - { 132, 36, 30, 20, 20, 20, 20, 20, 20, 18}, /* TM */ +static const vp9_prob default_if_uv_probs[VP9_INTRA_MODES] + [VP9_INTRA_MODES - 1] = { + { 115, 7, 78, 180, 210, 127, 34, 57, 104 } /* y = dc */, + { 43, 9, 165, 140, 112, 93, 45, 125, 117 } /* y = v */, + { 68, 6, 25, 206, 241, 154, 16, 23, 102 } /* y = h */, + { 90, 5, 48, 117, 155, 134, 61, 88, 96 } /* y = d45 */, + { 77, 5, 43, 148, 100, 147, 37, 60, 146 } /* y = d135 */, + { 75, 5, 57, 167, 62, 91, 45, 76, 139 } /* y = d117 */, + { 86, 4, 34, 155, 185, 163, 22, 29, 160 } /* y = d153 */, + { 82, 5, 34, 155, 207, 144, 26, 38, 79 } /* y = d27 */, + { 69, 6, 65, 105, 104, 122, 48, 131, 116 } /* y = d63 */, + { 86, 16, 114, 177, 189, 108, 28, 72, 120 } /* y = tm */ }; -const vp9_prob vp9_partition_probs[NUM_PARTITION_CONTEXTS] +const vp9_prob vp9_partition_probs[NUM_FRAME_TYPES][NUM_PARTITION_CONTEXTS] [PARTITION_TYPES - 1] = { - // FIXME(jingning,rbultje) put real probabilities here - {202, 162, 107}, - {16, 2, 169}, - {3, 246, 19}, - {104, 90, 134}, - {202, 162, 107}, - {16, 2, 169}, - {3, 246, 19}, - {104, 90, 134}, - {202, 162, 107}, - {16, 2, 169}, - {3, 246, 19}, - {104, 90, 134}, - {183, 70, 109}, - {30, 14, 162}, - {67, 208, 22}, - {4, 17, 5}, + { /* frame_type = keyframe */ + /* 8x8 -> 4x4 */ + { 164, 121, 109 } /* a/l both not split */, + { 69, 11, 129 } /* a split, l not split */, + { 52, 181, 37 } /* l split, a not split */, + { 66, 71, 93 } /* a/l both split */, + /* 16x16 -> 8x8 */ + { 154, 48, 43 } /* a/l both not split */, + { 81, 11, 63 } /* a split, l not split */, + { 67, 65, 17 } /* l split, a not split */, + { 57, 18, 24 } /* a/l both split */, + /* 32x32 -> 16x16 */ + { 156, 42, 35 } /* a/l both not split */, + { 74, 10, 40 } /* a split, l not split */, + { 59, 53, 10 } /* l split, a not split */, + { 28, 10, 9 } /* a/l both split */, + /* 64x64 -> 32x32 */ + { 168, 32, 43 } /* a/l both not split */, + { 59, 13, 41 } /* a split, l not split */, + { 60, 25, 10 } /* l split, a not split */, + { 13, 5, 4 } /* a/l both split */ + }, { /* frame_type = interframe */ + /* 8x8 -> 4x4 */ + { 192, 121, 151 } /* a/l both not split */, + { 134, 63, 162 } /* a split, l not split */, + { 136, 134, 127 } /* l split, a not split */, + { 101, 97, 131 } /* a/l both split */, + /* 16x16 -> 8x8 */ + { 167, 67, 80 } /* a/l both not split */, + { 87, 36, 70 } /* a split, l not split */, + { 90, 61, 45 } /* l split, a not split */, + { 46, 31, 32 } /* a/l both split */, + /* 32x32 -> 16x16 */ + { 167, 63, 75 } /* a/l both not split */, + { 67, 27, 61 } /* a split, l not split */, + { 56, 87, 31 } /* l split, a not split */, + { 15, 13, 11 } /* a/l both split */, + /* 64x64 -> 32x32 */ + { 222, 45, 44 } /* a/l both not split */, + { 62, 17, 62 } /* a split, l not split */, + { 52, 65, 16 } /* l split, a not split */, + { 9, 7, 6 } /* a/l both split */ + } }; /* Array indices are identical to previously-existing INTRAMODECONTEXTNODES. */ @@ -101,18 +130,12 @@ struct vp9_token vp9_sb_mv_ref_encoding_array[VP9_INTER_MODES]; struct vp9_token vp9_partition_encodings[PARTITION_TYPES]; void vp9_init_mbmode_probs(VP9_COMMON *x) { - unsigned int bct[VP9_INTRA_MODES][2]; // num Ymodes > num UV modes - int i; - - vp9_tree_probs_from_distribution(vp9_intra_mode_tree, x->fc.y_mode_prob, - bct, y_mode_cts, 0); - - for (i = 0; i < VP9_INTRA_MODES; i++) { - vp9_tree_probs_from_distribution(vp9_intra_mode_tree, x->kf_uv_mode_prob[i], - bct, kf_uv_mode_cts[i], 0); - vp9_tree_probs_from_distribution(vp9_intra_mode_tree, x->fc.uv_mode_prob[i], - bct, uv_mode_cts[i], 0); - } + vpx_memcpy(x->fc.uv_mode_prob, default_if_uv_probs, + sizeof(default_if_uv_probs)); + vpx_memcpy(x->kf_uv_mode_prob, default_kf_uv_probs, + sizeof(default_kf_uv_probs)); + vpx_memcpy(x->fc.y_mode_prob, default_if_y_probs, + sizeof(default_if_y_probs)); vpx_memcpy(x->fc.switchable_interp_prob, vp9_switchable_interp_prob, sizeof(vp9_switchable_interp_prob)); @@ -280,9 +303,10 @@ void vp9_adapt_mode_probs(VP9_COMMON *cm) { printf("};\n"); #endif - update_mode_probs(VP9_INTRA_MODES, vp9_intra_mode_tree, - fc->y_mode_counts, fc->pre_y_mode_prob, - fc->y_mode_prob, 0); + for (i = 0; i < BLOCK_SIZE_GROUPS; i++) + update_mode_probs(VP9_INTRA_MODES, vp9_intra_mode_tree, + fc->y_mode_counts[i], fc->pre_y_mode_prob[i], + fc->y_mode_prob[i], 0); for (i = 0; i < VP9_INTRA_MODES; ++i) update_mode_probs(VP9_INTRA_MODES, vp9_intra_mode_tree, @@ -292,7 +316,7 @@ void vp9_adapt_mode_probs(VP9_COMMON *cm) { for (i = 0; i < NUM_PARTITION_CONTEXTS; i++) update_mode_probs(PARTITION_TYPES, vp9_partition_tree, fc->partition_counts[i], fc->pre_partition_prob[i], - fc->partition_prob[i], 0); + fc->partition_prob[INTER_FRAME][i], 0); if (cm->mcomp_filter_type == SWITCHABLE) { for (i = 0; i <= VP9_SWITCHABLE_FILTERS; i++) { diff --git a/vp9/common/vp9_entropymode.h b/vp9/common/vp9_entropymode.h index 14dfae95b..32a40adc7 100644 --- a/vp9/common/vp9_entropymode.h +++ b/vp9/common/vp9_entropymode.h @@ -21,7 +21,7 @@ extern int vp9_mv_cont(const int_mv *l, const int_mv *a); extern const vp9_prob vp9_kf_default_bmode_probs[VP9_INTRA_MODES] [VP9_INTRA_MODES] - [VP9_INTRA_MODES -1 ]; + [VP9_INTRA_MODES - 1]; extern const vp9_tree_index vp9_intra_mode_tree[]; extern const vp9_tree_index vp9_sb_mv_ref_tree[]; @@ -35,6 +35,9 @@ extern struct vp9_token vp9_sb_mv_ref_encoding_array[VP9_INTER_MODES]; // probability models for partition information extern const vp9_tree_index vp9_partition_tree[]; extern struct vp9_token vp9_partition_encodings[PARTITION_TYPES]; +extern const vp9_prob vp9_partition_probs[NUM_FRAME_TYPES] + [NUM_PARTITION_CONTEXTS] + [PARTITION_TYPES - 1]; void vp9_entropy_mode_init(void); diff --git a/vp9/common/vp9_modecontext.c b/vp9/common/vp9_modecontext.c index 39d53f57b..f50652a62 100644 --- a/vp9/common/vp9_modecontext.c +++ b/vp9/common/vp9_modecontext.c @@ -13,116 +13,116 @@ const vp9_prob vp9_kf_default_bmode_probs[VP9_INTRA_MODES] [VP9_INTRA_MODES] - [VP9_INTRA_MODES-1] = { - { // Above 0 - { 231, 9, 124, 138, 96, 200, 76, 42, 88, }, // left 0 - { 152, 11, 187, 112, 170, 139, 130, 91, 113, }, // left 1 - { 175, 10, 71, 182, 212, 191, 43, 39, 82, }, // left 2 - { 56, 23, 63, 38, 76, 60, 185, 206, 159, }, // left 3 - { 144, 52, 89, 192, 19, 236, 134, 93, 37, }, // left 4 - { 114, 22, 29, 133, 37, 18, 60, 156, 233, }, // left 5 - { 121, 16, 26, 124, 176, 50, 29, 20, 234, }, // left 6 - { 170, 19, 50, 91, 169, 216, 14, 16, 5, }, // left 7 - { 63, 14, 21, 68, 32, 29, 71, 224, 181, }, // left 8 - { 81, 93, 62, 65, 78, 171, 152, 103, 172, }, // left 9 - }, { // Above 1 - { 134, 2, 185, 147, 159, 152, 83, 33, 136, }, // left 0 - { 72, 9, 194, 141, 208, 108, 124, 73, 119, }, // left 1 - { 66, 1, 102, 183, 236, 151, 35, 8, 78, }, // left 2 - { 41, 30, 60, 26, 101, 148, 212, 206, 177, }, // left 3 - { 104, 91, 122, 184, 33, 243, 156, 73, 1, }, // left 4 - { 74, 23, 47, 119, 63, 60, 79, 135, 211, }, // left 5 - { 65, 12, 40, 134, 211, 79, 42, 37, 187, }, // left 6 - { 87, 26, 76, 97, 218, 183, 27, 7, 31, }, // left 7 - { 47, 24, 45, 53, 78, 89, 105, 215, 128, }, // left 8 - { 66, 89, 68, 91, 120, 113, 190, 105, 98, }, // left 9 - }, { // Above 2 - { 88, 1, 88, 166, 229, 115, 30, 23, 155, }, // left 0 - { 43, 5, 98, 198, 244, 158, 50, 14, 113, }, // left 1 - { 39, 1, 53, 208, 247, 208, 10, 11, 92, }, // left 2 - { 56, 42, 41, 102, 156, 110, 76, 61, 106, }, // left 3 - { 107, 79, 78, 158, 85, 255, 20, 64, 114, }, // left 4 - { 39, 15, 30, 174, 135, 66, 85, 28, 176, }, // left 5 - { 34, 5, 22, 137, 222, 64, 22, 5, 220, }, // left 6 - { 68, 7, 25, 135, 206, 192, 7, 14, 8, }, // left 7 - { 34, 45, 24, 78, 85, 55, 85, 120, 60, }, // left 8 - { 62, 54, 23, 142, 182, 177, 64, 57, 171, }, // left 9 - }, { // Above 3 - { 193, 15, 108, 82, 121, 192, 188, 119, 145, }, // left 0 - { 60, 15, 157, 65, 142, 61, 202, 203, 85, }, // left 1 - { 112, 17, 121, 128, 175, 128, 94, 85, 1, }, // left 2 - { 40, 25, 47, 12, 20, 64, 221, 194, 57, }, // left 3 - { 100, 74, 112, 85, 43, 255, 64, 142, 128, }, // left 4 - { 88, 24, 47, 91, 93, 73, 141, 171, 85, }, // left 5 - { 61, 9, 65, 75, 107, 146, 53, 100, 255, }, // left 6 - { 142, 8, 80, 105, 199, 255, 20, 43, 1, }, // left 7 - { 41, 17, 43, 22, 64, 43, 98, 246, 255, }, // left 8 - { 51, 37, 59, 56, 94, 64, 200, 154, 128, }, // left 9 - }, { // Above 4 - { 125, 10, 103, 129, 89, 209, 65, 22, 91, }, // left 0 - { 95, 25, 93, 146, 108, 208, 96, 34, 108, }, // left 1 - { 75, 17, 84, 185, 188, 199, 20, 1, 43, }, // left 2 - { 57, 91, 27, 83, 23, 205, 67, 75, 149, }, // left 3 - { 115, 70, 29, 237, 3, 247, 73, 51, 1, }, // left 4 - { 38, 67, 45, 73, 64, 85, 51, 96, 255, }, // left 5 - { 41, 25, 11, 142, 133, 128, 77, 73, 205, }, // left 6 - { 101, 26, 32, 124, 38, 247, 7, 7, 8, }, // left 7 - { 57, 91, 28, 128, 32, 73, 128, 128, 128, }, // left 8 - { 117, 127, 39, 164, 51, 230, 128, 183, 255, }, // left 9 - }, { // Above 5 - { 138, 5, 32, 135, 70, 29, 33, 115, 208, }, // left 0 - { 67, 9, 91, 111, 142, 38, 78, 87, 199, }, // left 1 - { 63, 7, 60, 172, 138, 60, 85, 64, 199, }, // left 2 - { 40, 25, 44, 87, 71, 79, 102, 183, 85, }, // left 3 - { 57, 110, 80, 140, 85, 255, 51, 128, 128, }, // left 4 - { 47, 12, 16, 167, 26, 23, 69, 135, 171, }, // left 5 - { 46, 14, 18, 102, 89, 15, 7, 67, 238, }, // left 6 - { 65, 8, 33, 123, 158, 51, 18, 79, 114, }, // left 7 - { 40, 16, 3, 91, 28, 32, 37, 207, 224, }, // left 8 - { 87, 66, 49, 98, 32, 146, 59, 51, 224, }, // left 9 - }, { // Above 6 - { 104, 1, 55, 88, 130, 39, 9, 17, 234, }, // left 0 - { 64, 15, 96, 103, 192, 37, 43, 15, 248, }, // left 1 - { 54, 2, 57, 135, 213, 70, 4, 22, 203, }, // left 2 - { 30, 38, 40, 64, 128, 43, 114, 141, 171, }, // left 3 - { 75, 43, 38, 181, 21, 233, 154, 128, 1, }, // left 4 - { 39, 1, 19, 126, 107, 12, 35, 40, 237, }, // left 5 - { 31, 6, 9, 77, 221, 1, 2, 4, 244, }, // left 6 - { 88, 20, 33, 90, 110, 192, 39, 23, 51, }, // left 7 - { 56, 21, 23, 119, 55, 70, 48, 177, 128, }, // left 8 - { 55, 44, 46, 120, 188, 1, 60, 98, 192, }, // left 9 - }, { // Above 7 - { 102, 1, 61, 95, 192, 205, 6, 9, 31, }, // left 0 - { 69, 12, 63, 104, 187, 166, 14, 5, 20, }, // left 1 - { 68, 1, 45, 136, 242, 154, 1, 7, 30, }, // left 2 - { 62, 69, 24, 92, 73, 205, 82, 90, 93, }, // left 3 - { 75, 31, 17, 215, 12, 246, 16, 17, 1, }, // left 4 - { 37, 18, 46, 128, 80, 93, 112, 1, 114, }, // left 5 - { 63, 9, 10, 125, 195, 85, 20, 11, 134, }, // left 6 - { 86, 6, 6, 54, 136, 224, 1, 1, 1, }, // left 7 - { 56, 24, 9, 110, 43, 77, 128, 96, 1, }, // left 8 - { 58, 60, 20, 59, 116, 171, 69, 28, 75, }, // left 9 - }, { // Above 8 - { 164, 10, 52, 70, 121, 74, 105, 168, 164, }, // left 0 - { 51, 20, 112, 95, 138, 85, 101, 166, 238, }, // left 1 - { 86, 9, 42, 122, 140, 77, 117, 39, 23, }, // left 2 - { 22, 18, 28, 30, 156, 146, 141, 247, 255, }, // left 3 - { 83, 98, 20, 128, 43, 205, 128, 85, 1, }, // left 4 - { 45, 32, 18, 92, 67, 18, 38, 238, 255, }, // left 5 - { 56, 7, 22, 104, 98, 32, 54, 85, 154, }, // left 6 - { 85, 13, 27, 120, 192, 128, 57, 73, 51, }, // left 7 - { 18, 7, 12, 29, 67, 37, 40, 240, 192, }, // left 8 - { 35, 40, 32, 55, 57, 37, 147, 165, 154, }, // left 9 - }, { // Above 9 - { 190, 31, 91, 133, 82, 229, 152, 59, 141, }, // left 0 - { 85, 47, 155, 116, 163, 213, 141, 85, 171, }, // left 1 - { 101, 8, 78, 184, 186, 142, 118, 37, 128, }, // left 2 - { 56, 40, 49, 37, 128, 183, 219, 149, 205, }, // left 3 - { 146, 92, 56, 184, 45, 229, 114, 102, 1, }, // left 4 - { 71, 45, 37, 107, 51, 32, 110, 224, 1, }, // left 5 - { 101, 26, 43, 111, 158, 102, 45, 91, 228, }, // left 6 - { 138, 17, 48, 117, 144, 255, 81, 20, 21, }, // left 7 - { 32, 33, 47, 64, 93, 73, 101, 179, 171, }, // left 8 - { 112, 125, 38, 113, 56, 213, 168, 154, 192, }, // left 9 - }, + [VP9_INTRA_MODES - 1] = { + { /* above = dc */ + { 165, 25, 57, 147, 137, 207, 70, 49, 89 } /* left = dc */, + { 107, 33, 127, 132, 131, 173, 86, 88, 105 } /* left = v */, + { 87, 25, 24, 193, 225, 213, 44, 33, 94 } /* left = h */, + { 82, 32, 42, 91, 116, 154, 134, 119, 110 } /* left = d45 */, + { 87, 41, 47, 164, 49, 219, 85, 72, 84 } /* left = d135 */, + { 83, 29, 29, 134, 55, 84, 58, 132, 185 } /* left = d117 */, + { 78, 22, 24, 134, 145, 161, 37, 32, 199 } /* left = d153 */, + { 103, 25, 33, 121, 156, 215, 34, 32, 29 } /* left = d27 */, + { 73, 28, 26, 91, 75, 116, 67, 169, 128 } /* left = d63 */, + { 62, 79, 46, 119, 142, 197, 97, 73, 133 } /* left = tm */ + }, { /* above = v */ + { 77, 19, 144, 147, 131, 159, 67, 75, 108 } /* left = dc */, + { 48, 30, 180, 135, 139, 124, 84, 125, 102 } /* left = v */, + { 47, 14, 76, 169, 216, 171, 48, 35, 77 } /* left = h */, + { 53, 39, 82, 93, 98, 165, 128, 156, 115 } /* left = d45 */, + { 59, 52, 88, 155, 54, 208, 95, 109, 23 } /* left = d135 */, + { 45, 30, 76, 136, 51, 95, 62, 154, 157 } /* left = d117 */, + { 45, 22, 60, 127, 136, 156, 45, 67, 157 } /* left = d153 */, + { 59, 30, 78, 107, 157, 181, 49, 39, 50 } /* left = d27 */, + { 45, 33, 70, 85, 76, 127, 76, 185, 89 } /* left = d63 */, + { 41, 69, 104, 113, 125, 154, 110, 123, 88 } /* left = tm */ + }, { /* above = h */ + { 85, 12, 38, 172, 219, 185, 40, 29, 118 } /* left = dc */, + { 52, 25, 78, 175, 211, 189, 56, 37, 108 } /* left = v */, + { 38, 11, 17, 207, 245, 224, 18, 13, 84 } /* left = h */, + { 63, 42, 25, 121, 162, 179, 63, 53, 90 } /* left = d45 */, + { 69, 59, 35, 146, 108, 245, 33, 56, 115 } /* left = d135 */, + { 45, 27, 30, 160, 118, 128, 75, 49, 147 } /* left = d117 */, + { 40, 17, 19, 147, 198, 169, 30, 14, 181 } /* left = d153 */, + { 56, 19, 15, 150, 207, 212, 17, 22, 28 } /* left = d27 */, + { 45, 50, 21, 97, 113, 135, 68, 89, 72 } /* left = d63 */, + { 41, 70, 19, 165, 199, 203, 54, 52, 121 } /* left = tm */ + }, { /* above = d45 */ + { 124, 25, 52, 122, 127, 200, 116, 88, 105 } /* left = dc */, + { 60, 31, 107, 103, 119, 136, 135, 150, 90 } /* left = v */, + { 70, 28, 37, 157, 203, 192, 73, 67, 21 } /* left = h */, + { 62, 33, 39, 54, 67, 159, 150, 114, 61 } /* left = d45 */, + { 69, 41, 46, 102, 64, 240, 68, 103, 111 } /* left = d135 */, + { 59, 27, 39, 121, 68, 132, 101, 139, 96 } /* left = d117 */, + { 55, 19, 33, 119, 109, 198, 61, 88, 224 } /* left = d153 */, + { 92, 16, 40, 107, 160, 242, 48, 62, 15 } /* left = d27 */, + { 57, 27, 36, 65, 95, 130, 94, 213, 222 } /* left = d63 */, + { 47, 47, 47, 101, 130, 154, 130, 105, 102 } /* left = tm */ + }, { /* above = d135 */ + { 80, 19, 42, 132, 81, 205, 51, 36, 99 } /* left = dc */, + { 60, 34, 67, 145, 76, 196, 72, 61, 112 } /* left = v */, + { 46, 25, 29, 172, 181, 208, 37, 11, 79 } /* left = h */, + { 59, 45, 20, 103, 42, 203, 57, 68, 107 } /* left = d45 */, + { 68, 41, 25, 190, 21, 226, 68, 65, 38 } /* left = d135 */, + { 42, 38, 34, 133, 48, 145, 57, 106, 237 } /* left = d117 */, + { 35, 20, 11, 139, 94, 197, 49, 50, 182 } /* left = d153 */, + { 64, 26, 24, 122, 73, 230, 27, 27, 39 } /* left = d27 */, + { 53, 49, 25, 118, 52, 147, 84, 104, 103 } /* left = d63 */, + { 62, 70, 35, 156, 90, 214, 95, 140, 211 } /* left = tm */ + }, { /* above = d117 */ + { 78, 14, 37, 152, 67, 100, 44, 103, 160 } /* left = dc */, + { 50, 20, 86, 139, 72, 98, 62, 111, 157 } /* left = v */, + { 42, 17, 33, 169, 153, 139, 62, 61, 136 } /* left = h */, + { 48, 21, 39, 123, 65, 143, 76, 131, 87 } /* left = d45 */, + { 47, 41, 44, 149, 49, 221, 51, 107, 122 } /* left = d135 */, + { 37, 18, 26, 177, 20, 66, 58, 131, 148 } /* left = d117 */, + { 39, 19, 26, 125, 77, 115, 22, 75, 192 } /* left = d153 */, + { 48, 13, 33, 125, 113, 132, 30, 77, 99 } /* left = d27 */, + { 45, 27, 15, 119, 42, 96, 45, 168, 164 } /* left = d63 */, + { 48, 52, 52, 129, 60, 158, 58, 89, 153 } /* left = tm */ + }, { /* above = d153 */ + { 82, 9, 31, 121, 146, 145, 23, 28, 194 } /* left = dc */, + { 57, 32, 78, 121, 148, 128, 50, 37, 217 } /* left = v */, + { 38, 12, 19, 158, 221, 172, 12, 22, 166 } /* left = h */, + { 49, 32, 24, 100, 125, 142, 72, 83, 132 } /* left = d45 */, + { 54, 36, 22, 172, 49, 225, 88, 72, 59 } /* left = d135 */, + { 43, 7, 23, 130, 95, 86, 44, 57, 206 } /* left = d117 */, + { 34, 13, 12, 90, 196, 91, 8, 10, 226 } /* left = d153 */, + { 55, 23, 17, 106, 127, 207, 32, 23, 92 } /* left = d27 */, + { 54, 28, 20, 121, 76, 151, 45, 110, 124 } /* left = d63 */, + { 41, 51, 31, 120, 192, 74, 45, 62, 163 } /* left = tm */ + }, { /* above = d27 */ + { 88, 10, 40, 120, 157, 211, 25, 27, 54 } /* left = dc */, + { 64, 31, 69, 121, 129, 184, 36, 29, 45 } /* left = v */, + { 51, 11, 22, 170, 232, 209, 11, 20, 64 } /* left = h */, + { 65, 43, 19, 102, 91, 208, 68, 78, 75 } /* left = d45 */, + { 64, 40, 23, 171, 47, 229, 45, 48, 19 } /* left = d135 */, + { 43, 27, 39, 136, 76, 149, 92, 13, 114 } /* left = d117 */, + { 53, 19, 14, 128, 148, 173, 31, 25, 133 } /* left = d153 */, + { 73, 19, 13, 97, 137, 218, 12, 12, 10 } /* left = d27 */, + { 57, 35, 15, 111, 68, 149, 90, 102, 16 } /* left = d63 */, + { 43, 63, 23, 107, 144, 200, 64, 47, 88 } /* left = tm */ + }, { /* above = d63 */ + { 95, 19, 44, 97, 120, 145, 81, 142, 115 } /* left = dc */, + { 46, 29, 93, 95, 106, 133, 83, 189, 177 } /* left = v */, + { 54, 19, 29, 136, 181, 157, 80, 67, 47 } /* left = h */, + { 44, 26, 34, 83, 125, 180, 116, 218, 206 } /* left = d45 */, + { 56, 41, 25, 118, 55, 192, 93, 121, 22 } /* left = d135 */, + { 44, 31, 30, 110, 67, 80, 56, 217, 225 } /* left = d117 */, + { 44, 14, 25, 101, 105, 136, 57, 83, 133 } /* left = d153 */, + { 62, 16, 28, 105, 157, 164, 67, 92, 58 } /* left = d27 */, + { 36, 18, 25, 57, 88, 113, 59, 210, 127 } /* left = d63 */, + { 36, 41, 44, 79, 104, 129, 100, 151, 105 } /* left = tm */ + }, { /* above = tm */ + { 90, 61, 68, 152, 141, 209, 79, 59, 93 } /* left = dc */, + { 49, 71, 127, 132, 129, 187, 89, 105, 113 } /* left = v */, + { 48, 29, 26, 190, 225, 190, 55, 32, 75 } /* left = h */, + { 58, 51, 46, 110, 134, 192, 124, 100, 113 } /* left = d45 */, + { 69, 60, 38, 156, 82, 214, 79, 89, 24 } /* left = d135 */, + { 48, 54, 50, 139, 71, 106, 77, 162, 18 } /* left = d117 */, + { 52, 34, 33, 137, 149, 184, 45, 67, 169 } /* left = d153 */, + { 67, 29, 32, 123, 176, 244, 47, 27, 31 } /* left = d27 */, + { 38, 43, 46, 93, 106, 140, 78, 143, 111 } /* left = d63 */, + { 55, 98, 50, 135, 140, 208, 95, 103, 95 } /* left = tm */ + } }; diff --git a/vp9/common/vp9_onyxc_int.h b/vp9/common/vp9_onyxc_int.h index ddc0c39ab..68a8052d9 100644 --- a/vp9/common/vp9_onyxc_int.h +++ b/vp9/common/vp9_onyxc_int.h @@ -45,18 +45,19 @@ #define MAX_LAG_BUFFERS 25 typedef struct frame_contexts { - vp9_prob y_mode_prob[VP9_INTRA_MODES - 1]; /* interframe intra mode probs */ + vp9_prob y_mode_prob[BLOCK_SIZE_GROUPS][VP9_INTRA_MODES - 1]; vp9_prob uv_mode_prob[VP9_INTRA_MODES][VP9_INTRA_MODES - 1]; - vp9_prob partition_prob[NUM_PARTITION_CONTEXTS][PARTITION_TYPES - 1]; + vp9_prob partition_prob[NUM_FRAME_TYPES][NUM_PARTITION_CONTEXTS] + [PARTITION_TYPES - 1]; nmv_context nmvc; nmv_context pre_nmvc; /* interframe intra mode probs */ - vp9_prob pre_y_mode_prob[VP9_INTRA_MODES - 1]; + vp9_prob pre_y_mode_prob[BLOCK_SIZE_GROUPS][VP9_INTRA_MODES - 1]; vp9_prob pre_uv_mode_prob[VP9_INTRA_MODES][VP9_INTRA_MODES - 1]; vp9_prob pre_partition_prob[NUM_PARTITION_CONTEXTS][PARTITION_TYPES - 1]; /* interframe intra mode probs */ - unsigned int y_mode_counts[VP9_INTRA_MODES]; + unsigned int y_mode_counts[BLOCK_SIZE_GROUPS][VP9_INTRA_MODES]; unsigned int uv_mode_counts[VP9_INTRA_MODES][VP9_INTRA_MODES]; unsigned int partition_counts[NUM_PARTITION_CONTEXTS][PARTITION_TYPES]; diff --git a/vp9/decoder/vp9_decodemv.c b/vp9/decoder/vp9_decodemv.c index 397c0639b..c5ec8203d 100644 --- a/vp9/decoder/vp9_decodemv.c +++ b/vp9/decoder/vp9_decodemv.c @@ -404,17 +404,20 @@ static void mb_mode_mv_init(VP9D_COMP *pbi, vp9_reader *r) { cm->prob_comppred[i] = vp9_read_prob(r); // VP9_INTRA_MODES - for (i = 0; i < VP9_INTRA_MODES - 1; ++i) { - if (vp9_read(r, VP9_DEF_UPDATE_PROB)) { - cm->fc.y_mode_prob[i] = - vp9_read_prob_diff_update(r, cm->fc.y_mode_prob[i]); + for (j = 0; j < BLOCK_SIZE_GROUPS; j++) { + for (i = 0; i < VP9_INTRA_MODES - 1; ++i) { + if (vp9_read(r, VP9_DEF_UPDATE_PROB)) { + cm->fc.y_mode_prob[j][i] = + vp9_read_prob_diff_update(r, cm->fc.y_mode_prob[j][i]); + } } } for (j = 0; j < NUM_PARTITION_CONTEXTS; ++j) { for (i = 0; i < PARTITION_TYPES - 1; ++i) { if (vp9_read(r, VP9_DEF_UPDATE_PROB)) { - cm->fc.partition_prob[j][i] = - vp9_read_prob_diff_update(r, cm->fc.partition_prob[j][i]); + cm->fc.partition_prob[INTER_FRAME][j][i] = + vp9_read_prob_diff_update(r, + cm->fc.partition_prob[INTER_FRAME][j][i]); } } } @@ -785,16 +788,19 @@ static void read_mb_modes_mv(VP9D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi, mv0->as_int = 0; if (bsize >= BLOCK_SIZE_SB8X8) { - mbmi->mode = read_intra_mode(r, cm->fc.y_mode_prob); - cm->fc.y_mode_counts[mbmi->mode]++; + const BLOCK_SIZE_TYPE bsize = xd->mode_info_context->mbmi.sb_type; + const int bwl = b_width_log2(bsize), bhl = b_height_log2(bsize); + const int bsl = MIN(bwl, bhl); + mbmi->mode = read_intra_mode(r, cm->fc.y_mode_prob[MIN(3, bsl)]); + cm->fc.y_mode_counts[MIN(3, bsl)][mbmi->mode]++; } else { int idx, idy; for (idy = 0; idy < 2; idy += bh) { for (idx = 0; idx < 2; idx += bw) { int ib = idy * 2 + idx, k; - int m = read_intra_mode(r, cm->fc.y_mode_prob); + int m = read_intra_mode(r, cm->fc.y_mode_prob[0]); mi->bmi[ib].as_mode.first = m; - cm->fc.y_mode_counts[m]++; + cm->fc.y_mode_counts[0][m]++; for (k = 1; k < bh; ++k) mi->bmi[ib + k * 2].as_mode.first = m; for (k = 1; k < bw; ++k) diff --git a/vp9/decoder/vp9_decodframe.c b/vp9/decoder/vp9_decodframe.c index 92c5c9d1b..133feb03a 100644 --- a/vp9/decoder/vp9_decodframe.c +++ b/vp9/decoder/vp9_decodframe.c @@ -474,7 +474,7 @@ static void decode_modes_sb(VP9D_COMP *pbi, int mi_row, int mi_col, xd->above_seg_context = pc->above_seg_context + mi_col; pl = partition_plane_context(xd, bsize); partition = treed_read(r, vp9_partition_tree, - pc->fc.partition_prob[pl]); + pc->fc.partition_prob[pc->frame_type][pl]); pc->fc.partition_counts[pl][partition]++; } @@ -757,7 +757,7 @@ static void update_frame_context(FRAME_CONTEXT *fc) { vp9_copy(fc->pre_coef_probs, fc->coef_probs); vp9_copy(fc->pre_y_mode_prob, fc->y_mode_prob); vp9_copy(fc->pre_uv_mode_prob, fc->uv_mode_prob); - vp9_copy(fc->pre_partition_prob, fc->partition_prob); + vp9_copy(fc->pre_partition_prob, fc->partition_prob[1]); fc->pre_nmvc = fc->nmvc; vp9_copy(fc->pre_switchable_interp_prob, fc->switchable_interp_prob); vp9_copy(fc->pre_inter_mode_probs, fc->inter_mode_probs); diff --git a/vp9/encoder/vp9_bitstream.c b/vp9/encoder/vp9_bitstream.c index ce06b53ab..fe933d889 100644 --- a/vp9/encoder/vp9_bitstream.c +++ b/vp9/encoder/vp9_bitstream.c @@ -325,13 +325,15 @@ static void update_mode( static void update_mbintra_mode_probs(VP9_COMP* const cpi, vp9_writer* const bc) { VP9_COMMON *const cm = &cpi->common; - + int j; vp9_prob pnew[VP9_INTRA_MODES - 1]; unsigned int bct[VP9_INTRA_MODES - 1][2]; - update_mode(bc, VP9_INTRA_MODES, vp9_intra_mode_encodings, - vp9_intra_mode_tree, pnew, - cm->fc.y_mode_prob, bct, (unsigned int *)cpi->y_mode_count); + for (j = 0; j < BLOCK_SIZE_GROUPS; j++) + update_mode(bc, VP9_INTRA_MODES, vp9_intra_mode_encodings, + vp9_intra_mode_tree, pnew, + cm->fc.y_mode_prob[j], bct, + (unsigned int *)cpi->y_mode_count[j]); } void vp9_update_skip_probs(VP9_COMP *cpi) { @@ -676,15 +678,19 @@ static void pack_inter_mode_mvs(VP9_COMP *cpi, MODE_INFO *m, #endif if (m->mbmi.sb_type >= BLOCK_SIZE_SB8X8) { - write_intra_mode(bc, mode, pc->fc.y_mode_prob); + const BLOCK_SIZE_TYPE bsize = xd->mode_info_context->mbmi.sb_type; + const int bwl = b_width_log2(bsize), bhl = b_height_log2(bsize); + const int bsl = MIN(bwl, bhl); + write_intra_mode(bc, mode, pc->fc.y_mode_prob[MIN(3, bsl)]); } else { int idx, idy; int bw = 1 << b_width_log2(mi->sb_type); int bh = 1 << b_height_log2(mi->sb_type); for (idy = 0; idy < 2; idy += bh) - for (idx = 0; idx < 2; idx += bw) - write_intra_mode(bc, m->bmi[idy * 2 + idx].as_mode.first, - pc->fc.y_mode_prob); + for (idx = 0; idx < 2; idx += bw) { + MB_PREDICTION_MODE bm = m->bmi[idy * 2 + idx].as_mode.first; + write_intra_mode(bc, bm, pc->fc.y_mode_prob[0]); + } } write_intra_mode(bc, mi->uv_mode, pc->fc.uv_mode_prob[mode]); @@ -900,7 +906,8 @@ static void write_modes_sb(VP9_COMP *cpi, MODE_INFO *m, vp9_writer *bc, xd->above_seg_context = cm->above_seg_context + mi_col; pl = partition_plane_context(xd, bsize); // encode the partition information - write_token(bc, vp9_partition_tree, cm->fc.partition_prob[pl], + write_token(bc, vp9_partition_tree, + cm->fc.partition_prob[cm->frame_type][pl], vp9_partition_encodings + partition); } @@ -1557,7 +1564,8 @@ void vp9_pack_bitstream(VP9_COMP *cpi, uint8_t *dest, unsigned long *size) { vp9_copy(pc->fc.pre_coef_probs, pc->fc.coef_probs); vp9_copy(pc->fc.pre_y_mode_prob, pc->fc.y_mode_prob); vp9_copy(pc->fc.pre_uv_mode_prob, pc->fc.uv_mode_prob); - vp9_copy(pc->fc.pre_partition_prob, pc->fc.partition_prob); + vp9_copy(cpi->common.fc.pre_partition_prob, + cpi->common.fc.partition_prob[INTER_FRAME]); pc->fc.pre_nmvc = pc->fc.nmvc; vp9_copy(pc->fc.pre_switchable_interp_prob, pc->fc.switchable_interp_prob); vp9_copy(pc->fc.pre_inter_mode_probs, pc->fc.inter_mode_probs); @@ -1614,7 +1622,8 @@ void vp9_pack_bitstream(VP9_COMP *cpi, uint8_t *dest, unsigned long *size) { vp9_prob Pnew[PARTITION_TYPES - 1]; unsigned int bct[PARTITION_TYPES - 1][2]; update_mode(&header_bc, PARTITION_TYPES, vp9_partition_encodings, - vp9_partition_tree, Pnew, pc->fc.partition_prob[i], bct, + vp9_partition_tree, Pnew, + pc->fc.partition_prob[pc->frame_type][i], bct, (unsigned int *)cpi->partition_count[i]); } diff --git a/vp9/encoder/vp9_encodeframe.c b/vp9/encoder/vp9_encodeframe.c index 6efcdd042..084e7b346 100644 --- a/vp9/encoder/vp9_encodeframe.c +++ b/vp9/encoder/vp9_encodeframe.c @@ -1928,7 +1928,10 @@ static void sum_intra_stats(VP9_COMP *cpi, MACROBLOCK *x) { ++cpi->y_uv_mode_count[m][uvm]; if (xd->mode_info_context->mbmi.sb_type >= BLOCK_SIZE_SB8X8) { - ++cpi->y_mode_count[m]; + const BLOCK_SIZE_TYPE bsize = xd->mode_info_context->mbmi.sb_type; + const int bwl = b_width_log2(bsize), bhl = b_height_log2(bsize); + const int bsl = MIN(bwl, bhl); + ++cpi->y_mode_count[MIN(bsl, 3)][m]; } else { int idx, idy; int bw = 1 << b_width_log2(xd->mode_info_context->mbmi.sb_type); @@ -1936,7 +1939,7 @@ static void sum_intra_stats(VP9_COMP *cpi, MACROBLOCK *x) { for (idy = 0; idy < 2; idy += bh) { for (idx = 0; idx < 2; idx += bw) { int m = xd->mode_info_context->bmi[idy * 2 + idx].as_mode.first; - ++cpi->y_mode_count[m]; + ++cpi->y_mode_count[0][m]; } } } diff --git a/vp9/encoder/vp9_modecosts.c b/vp9/encoder/vp9_modecosts.c index 099a04404..f2e4ce40f 100644 --- a/vp9/encoder/vp9_modecosts.c +++ b/vp9/encoder/vp9_modecosts.c @@ -28,7 +28,7 @@ void vp9_init_mode_costs(VP9_COMP *c) { } // TODO(rbultje) separate tables for superblock costing? - vp9_cost_tokens(c->mb.mbmode_cost, x->fc.y_mode_prob, + vp9_cost_tokens(c->mb.mbmode_cost, x->fc.y_mode_prob[1], vp9_intra_mode_tree); vp9_cost_tokens(c->mb.intra_uv_mode_cost[1], x->fc.uv_mode_prob[VP9_INTRA_MODES - 1], vp9_intra_mode_tree); diff --git a/vp9/encoder/vp9_onyx_int.h b/vp9/encoder/vp9_onyx_int.h index de9d18c16..1f102e869 100644 --- a/vp9/encoder/vp9_onyx_int.h +++ b/vp9/encoder/vp9_onyx_int.h @@ -78,9 +78,9 @@ typedef struct { vp9_coeff_probs_model coef_probs[TX_SIZE_MAX_SB][BLOCK_TYPES]; - vp9_prob y_mode_prob[VP9_INTRA_MODES - 1]; /* interframe intra mode probs */ + vp9_prob y_mode_prob[4][VP9_INTRA_MODES - 1]; vp9_prob uv_mode_prob[VP9_INTRA_MODES][VP9_INTRA_MODES - 1]; - vp9_prob partition_prob[NUM_PARTITION_CONTEXTS][PARTITION_TYPES - 1]; + vp9_prob partition_prob[2][NUM_PARTITION_CONTEXTS][PARTITION_TYPES - 1]; vp9_prob switchable_interp_prob[VP9_SWITCHABLE_FILTERS + 1] [VP9_SWITCHABLE_FILTERS - 1]; @@ -406,7 +406,7 @@ typedef struct VP9_COMP { int cq_target_quality; - int y_mode_count[VP9_INTRA_MODES]; + int y_mode_count[4][VP9_INTRA_MODES]; int y_uv_mode_count[VP9_INTRA_MODES][VP9_INTRA_MODES]; unsigned int partition_count[NUM_PARTITION_CONTEXTS][PARTITION_TYPES]; diff --git a/vp9/encoder/vp9_rdopt.c b/vp9/encoder/vp9_rdopt.c index b5b968bda..f785c32ca 100644 --- a/vp9/encoder/vp9_rdopt.c +++ b/vp9/encoder/vp9_rdopt.c @@ -264,7 +264,7 @@ void vp9_initialize_rd_consts(VP9_COMP *cpi, int qindex) { for (i = 0; i < NUM_PARTITION_CONTEXTS; i++) vp9_cost_tokens(cpi->mb.partition_cost[i], - cpi->common.fc.partition_prob[i], + cpi->common.fc.partition_prob[cpi->common.frame_type][i], vp9_partition_tree); /*rough estimate for costing*/