Commit d01357bb authored by Deb Mukherjee's avatar Deb Mukherjee

New b-intra mode where direction is contextual

Preliminary patch on a new 4x4 intra mode B_CONTEXT_PRED where the
dominant direction from the context is used to encode. Various decoder
changes are needed to support decoding of B_CONTEXT_PRED in conjunction
with hybrid transforms since the scan order and tokenization depends on
the actual direction of prediction obtained from the context. Currently
the traditional directional modes are used in conjunction with the
B_CONTEXT_PRED, which also seems to provide the best results.

The gains are small - in the 0.1% range.

Change-Id: I5a7ea80b5218f42a9c0dfb42d3f79a68c7f0cdc2
parent 3f7182cb
......@@ -245,6 +245,7 @@ EXPERIMENT_LIST="
subpelrefmv
new_mvref
implicit_segmentation
newbintramodes
"
CONFIG_LIST="
external_build
......
......@@ -149,8 +149,8 @@ typedef enum {
B_DC_PRED, /* average of above and left pixels */
B_TM_PRED,
B_VE_PRED, /* vertical prediction */
B_HE_PRED, /* horizontal prediction */
B_VE_PRED, /* vertical prediction */
B_HE_PRED, /* horizontal prediction */
B_LD_PRED,
B_RD_PRED,
......@@ -159,6 +159,9 @@ typedef enum {
B_VL_PRED,
B_HD_PRED,
B_HU_PRED,
#if CONFIG_NEWBINTRAMODES
B_CONTEXT_PRED,
#endif
LEFT4X4,
ABOVE4X4,
......@@ -168,9 +171,19 @@ typedef enum {
B_MODE_COUNT
} B_PREDICTION_MODE;
#define VP9_BINTRAMODES (B_HU_PRED + 1) /* 10 */
#define VP9_BINTRAMODES (LEFT4X4)
#define VP9_SUBMVREFS (1 + NEW4X4 - LEFT4X4)
#if CONFIG_NEWBINTRAMODES
/* The number of B_PRED intra modes that are replaced by B_CONTEXT_PRED */
#define CONTEXT_PRED_REPLACEMENTS 0
#define VP9_KF_BINTRAMODES (VP9_BINTRAMODES - 1)
#define VP9_NKF_BINTRAMODES (VP9_BINTRAMODES - CONTEXT_PRED_REPLACEMENTS)
#else
#define VP9_KF_BINTRAMODES (VP9_BINTRAMODES) /* 10 */
#define VP9_NKF_BINTRAMODES (VP9_BINTRAMODES) /* 10 */
#endif
typedef enum {
PARTITIONING_16X8 = 0,
PARTITIONING_8X16,
......@@ -187,9 +200,11 @@ union b_mode_info {
struct {
B_PREDICTION_MODE first;
TX_TYPE tx_type;
#if CONFIG_COMP_INTRA_PRED
B_PREDICTION_MODE second;
#endif
#if CONFIG_NEWBINTRAMODES
B_PREDICTION_MODE context;
#endif
} as_mode;
struct {
......@@ -443,6 +458,12 @@ static TX_TYPE txfm_map(B_PREDICTION_MODE bmode) {
tx_type = DCT_ADST;
break;
#if CONFIG_NEWBINTRAMODES
case B_CONTEXT_PRED:
assert(0);
break;
#endif
default :
tx_type = DCT_DCT;
break;
......@@ -454,7 +475,11 @@ static TX_TYPE get_tx_type_4x4(const MACROBLOCKD *xd, const BLOCKD *b) {
TX_TYPE tx_type = DCT_DCT;
if (xd->mode_info_context->mbmi.mode == B_PRED &&
xd->q_index < ACTIVE_HT) {
tx_type = txfm_map(b->bmi.as_mode.first);
tx_type = txfm_map(
#if CONFIG_NEWBINTRAMODES
b->bmi.as_mode.first == B_CONTEXT_PRED ? b->bmi.as_mode.context :
#endif
b->bmi.as_mode.first);
}
return tx_type;
}
......
......@@ -68,9 +68,22 @@ static const unsigned int kf_uv_mode_cts [VP9_YMODES] [VP9_UV_MODES] = {
{ 122, 41, 35, 20, 20, 20, 20, 20, 20, 18}, /* BPRED */
};
static const unsigned int bmode_cts[VP9_BINTRAMODES] = {
static const unsigned int bmode_cts[VP9_NKF_BINTRAMODES] = {
#if CONFIG_NEWBINTRAMODES
#if CONTEXT_PRED_REPLACEMENTS == 6
/* DC TM VE HE CONTEXT */
43891, 17694, 10036, 3920, 20000
#elif CONTEXT_PRED_REPLACEMENTS == 4
/* DC TM VE HE LD RD CONTEXT */
43891, 17694, 10036, 3920, 3363, 2546, 14000
#elif CONTEXT_PRED_REPLACEMENTS == 0
/* DC TM VE HE LD RD VR VL HD HU CONTEXT */
43891, 17694, 10036, 3920, 3363, 2546, 5119, 3221, 2471, 1723, 50000
#endif
#else
/* DC TM VE HE LD RD VR VL HD HU */
43891, 17694, 10036, 3920, 3363, 2546, 5119, 3221, 2471, 1723
#endif
};
typedef enum {
......@@ -141,17 +154,55 @@ const vp9_prob vp9_mbsplit_probs [VP9_NUMMBSPLITS - 1] = { 110, 111, 150};
/* Array indices are identical to previously-existing INTRAMODECONTEXTNODES. */
const vp9_tree_index vp9_bmode_tree[VP9_BINTRAMODES * 2 - 2] = /* INTRAMODECONTEXTNODE value */
{
-B_DC_PRED, 2, /* 0 = DC_NODE */
-B_TM_PRED, 4, /* 1 = TM_NODE */
-B_VE_PRED, 6, /* 2 = VE_NODE */
8, 12, /* 3 = COM_NODE */
-B_HE_PRED, 10, /* 4 = HE_NODE */
-B_RD_PRED, -B_VR_PRED, /* 5 = RD_NODE */
-B_LD_PRED, 14, /* 6 = LD_NODE */
-B_VL_PRED, 16, /* 7 = VL_NODE */
-B_HD_PRED, -B_HU_PRED /* 8 = HD_NODE */
const vp9_tree_index vp9_kf_bmode_tree[VP9_KF_BINTRAMODES * 2 - 2] = {
-B_DC_PRED, 2, /* 0 = DC_NODE */
-B_TM_PRED, 4, /* 1 = TM_NODE */
-B_VE_PRED, 6, /* 2 = VE_NODE */
8, 12, /* 3 = COM_NODE */
-B_HE_PRED, 10, /* 4 = HE_NODE */
-B_RD_PRED, -B_VR_PRED, /* 5 = RD_NODE */
-B_LD_PRED, 14, /* 6 = LD_NODE */
-B_VL_PRED, 16, /* 7 = VL_NODE */
-B_HD_PRED, -B_HU_PRED /* 8 = HD_NODE */
};
const vp9_tree_index vp9_bmode_tree[VP9_NKF_BINTRAMODES * 2 - 2] = {
#if CONFIG_NEWBINTRAMODES
#if CONTEXT_PRED_REPLACEMENTS == 6
-B_DC_PRED, 2,
-B_TM_PRED, 4,
6, -(B_CONTEXT_PRED - CONTEXT_PRED_REPLACEMENTS),
-B_VE_PRED, -B_HE_PRED
#elif CONTEXT_PRED_REPLACEMENTS == 4
-B_DC_PRED, 2,
-B_TM_PRED, 4,
6, 8,
-B_VE_PRED, -B_HE_PRED,
10, -(B_CONTEXT_PRED - CONTEXT_PRED_REPLACEMENTS),
-B_RD_PRED, -B_LD_PRED,
#elif CONTEXT_PRED_REPLACEMENTS == 0
-B_DC_PRED, 2, /* 0 = DC_NODE */
-B_TM_PRED, 4, /* 1 = TM_NODE */
-B_VE_PRED, 6, /* 2 = VE_NODE */
8, 12, /* 3 = COM_NODE */
-B_HE_PRED, 10, /* 4 = HE_NODE */
-B_RD_PRED, -B_VR_PRED, /* 5 = RD_NODE */
-B_LD_PRED, 14, /* 6 = LD_NODE */
-B_VL_PRED, 16, /* 7 = VL_NODE */
-B_HD_PRED, 18,
-B_HU_PRED, -B_CONTEXT_PRED
#endif
#else
-B_DC_PRED, 2, /* 0 = DC_NODE */
-B_TM_PRED, 4, /* 1 = TM_NODE */
-B_VE_PRED, 6, /* 2 = VE_NODE */
8, 12, /* 3 = COM_NODE */
-B_HE_PRED, 10, /* 4 = HE_NODE */
-B_RD_PRED, -B_VR_PRED, /* 5 = RD_NODE */
-B_LD_PRED, 14, /* 6 = LD_NODE */
-B_VL_PRED, 16, /* 7 = VL_NODE */
-B_HD_PRED, -B_HU_PRED /* 8 = HD_NODE */
#endif
};
/* Again, these trees use the same probability indices as their
......@@ -235,21 +286,22 @@ const vp9_tree_index vp9_sub_mv_ref_tree[6] = {
-ZERO4X4, -NEW4X4
};
struct vp9_token_struct vp9_bmode_encodings [VP9_BINTRAMODES];
struct vp9_token_struct vp9_ymode_encodings [VP9_YMODES];
struct vp9_token_struct vp9_bmode_encodings[VP9_NKF_BINTRAMODES];
struct vp9_token_struct vp9_kf_bmode_encodings[VP9_KF_BINTRAMODES];
struct vp9_token_struct vp9_ymode_encodings[VP9_YMODES];
#if CONFIG_SUPERBLOCKS
struct vp9_token_struct vp9_sb_kf_ymode_encodings [VP9_I32X32_MODES];
#endif
struct vp9_token_struct vp9_kf_ymode_encodings [VP9_YMODES];
struct vp9_token_struct vp9_uv_mode_encodings [VP9_UV_MODES];
struct vp9_token_struct vp9_i8x8_mode_encodings [VP9_I8X8_MODES];
struct vp9_token_struct vp9_mbsplit_encodings [VP9_NUMMBSPLITS];
struct vp9_token_struct vp9_kf_ymode_encodings[VP9_YMODES];
struct vp9_token_struct vp9_uv_mode_encodings[VP9_UV_MODES];
struct vp9_token_struct vp9_i8x8_mode_encodings[VP9_I8X8_MODES];
struct vp9_token_struct vp9_mbsplit_encodings[VP9_NUMMBSPLITS];
struct vp9_token_struct vp9_mv_ref_encoding_array [VP9_MVREFS];
struct vp9_token_struct vp9_mv_ref_encoding_array[VP9_MVREFS];
#if CONFIG_SUPERBLOCKS
struct vp9_token_struct vp9_sb_mv_ref_encoding_array [VP9_MVREFS];
struct vp9_token_struct vp9_sb_mv_ref_encoding_array[VP9_MVREFS];
#endif
struct vp9_token_struct vp9_sub_mv_ref_encoding_array [VP9_SUBMVREFS];
struct vp9_token_struct vp9_sub_mv_ref_encoding_array[VP9_SUBMVREFS];
void vp9_init_mbmode_probs(VP9_COMMON *x) {
unsigned int bct [VP9_YMODES] [2]; /* num Ymodes > num UV modes */
......@@ -297,28 +349,36 @@ void vp9_init_mbmode_probs(VP9_COMMON *x) {
static void intra_bmode_probs_from_distribution(
vp9_prob p [VP9_BINTRAMODES - 1],
unsigned int branch_ct [VP9_BINTRAMODES - 1] [2],
const unsigned int events [VP9_BINTRAMODES]) {
vp9_tree_probs_from_distribution(VP9_BINTRAMODES, vp9_bmode_encodings,
vp9_bmode_tree, p, branch_ct,
events, 256, 1);
vp9_prob p[VP9_NKF_BINTRAMODES - 1],
unsigned int branch_ct[VP9_NKF_BINTRAMODES - 1][2],
const unsigned int events[VP9_NKF_BINTRAMODES]) {
vp9_tree_probs_from_distribution(VP9_NKF_BINTRAMODES, vp9_bmode_encodings,
vp9_bmode_tree, p, branch_ct, events, 256, 1);
}
void vp9_default_bmode_probs(vp9_prob p [VP9_BINTRAMODES - 1]) {
unsigned int branch_ct [VP9_BINTRAMODES - 1] [2];
void vp9_default_bmode_probs(vp9_prob p[VP9_NKF_BINTRAMODES - 1]) {
unsigned int branch_ct[VP9_NKF_BINTRAMODES - 1][2];
intra_bmode_probs_from_distribution(p, branch_ct, bmode_cts);
}
void vp9_kf_default_bmode_probs(vp9_prob p[VP9_BINTRAMODES][VP9_BINTRAMODES]
[VP9_BINTRAMODES - 1]) {
unsigned int branch_ct[VP9_BINTRAMODES - 1][2];
static void intra_kf_bmode_probs_from_distribution(
vp9_prob p[VP9_KF_BINTRAMODES - 1],
unsigned int branch_ct[VP9_KF_BINTRAMODES - 1][2],
const unsigned int events[VP9_KF_BINTRAMODES]) {
vp9_tree_probs_from_distribution(VP9_KF_BINTRAMODES, vp9_kf_bmode_encodings,
vp9_kf_bmode_tree, p, branch_ct, events, 256, 1);
}
void vp9_kf_default_bmode_probs(vp9_prob p[VP9_KF_BINTRAMODES]
[VP9_KF_BINTRAMODES]
[VP9_KF_BINTRAMODES - 1]) {
unsigned int branch_ct[VP9_KF_BINTRAMODES - 1][2];
int i, j;
for (i = 0; i < VP9_BINTRAMODES; i++) {
for (j = 0; j < VP9_BINTRAMODES; j++) {
intra_bmode_probs_from_distribution(
p[i][j], branch_ct, vp9_kf_default_bmode_counts[i][j]);
for (i = 0; i < VP9_KF_BINTRAMODES; ++i) {
for (j = 0; j < VP9_KF_BINTRAMODES; ++j) {
intra_kf_bmode_probs_from_distribution(
p[i][j], branch_ct, vp9_kf_default_bmode_counts[i][j]);
}
}
}
......@@ -353,6 +413,7 @@ const int vp9_switchable_interp_map[SWITCHABLE+1] = {-1, -1, 0, 1, -1}; //8, 8s
#endif
void vp9_entropy_mode_init() {
vp9_tokens_from_tree(vp9_kf_bmode_encodings, vp9_kf_bmode_tree);
vp9_tokens_from_tree(vp9_bmode_encodings, vp9_bmode_tree);
vp9_tokens_from_tree(vp9_ymode_encodings, vp9_ymode_tree);
vp9_tokens_from_tree(vp9_kf_ymode_encodings, vp9_kf_ymode_tree);
......@@ -444,7 +505,7 @@ void vp9_update_mode_context(VP9_COMMON *pc) {
this_prob = count > 0 ? 256 * mv_ref_ct[j][i][0] / count : 128;
count = count > MVREF_COUNT_SAT ? MVREF_COUNT_SAT : count;
factor = (MVREF_MAX_UPDATE_FACTOR * count / MVREF_COUNT_SAT);
this_prob = (pc->fc.vp8_mode_contexts[j][i] * (256 - factor) +
this_prob = (pc->fc.vp9_mode_contexts[j][i] * (256 - factor) +
this_prob * factor + 128) >> 8;
this_prob = this_prob ? (this_prob < 255 ? this_prob : 255) : 1;
mode_context[j][i] = this_prob;
......@@ -482,7 +543,7 @@ void vp9_adapt_mode_probs(VP9_COMMON *cm) {
unsigned int branch_ct[32][2];
vp9_prob ymode_probs[VP9_YMODES - 1];
vp9_prob uvmode_probs[VP9_UV_MODES - 1];
vp9_prob bmode_probs[VP9_BINTRAMODES - 1];
vp9_prob bmode_probs[VP9_NKF_BINTRAMODES - 1];
vp9_prob i8x8_mode_probs[VP9_I8X8_MODES - 1];
vp9_prob sub_mv_ref_probs[VP9_SUBMVREFS - 1];
vp9_prob mbsplit_probs[VP9_NUMMBSPLITS - 1];
......@@ -500,8 +561,9 @@ void vp9_adapt_mode_probs(VP9_COMMON *cm) {
}
printf("};\n");
printf("static const unsigned int\nbmode_counts"
"[VP9_BINTRAMODES] = {\n");
for (t = 0; t < VP9_BINTRAMODES; ++t) printf("%d, ", cm->fc.bmode_counts[t]);
"[VP9_NKF_BINTRAMODES] = {\n");
for (t = 0; t < VP9_NKF_BINTRAMODES; ++t)
printf("%d, ", cm->fc.bmode_counts[t]);
printf("};\n");
printf("static const unsigned int\ni8x8_mode_counts"
"[VP9_I8X8_MODES] = {\n");
......@@ -551,10 +613,10 @@ void vp9_adapt_mode_probs(VP9_COMMON *cm) {
else cm->fc.uv_mode_prob[i][t] = prob;
}
}
vp9_tree_probs_from_distribution(VP9_BINTRAMODES, vp9_bmode_encodings,
vp9_tree_probs_from_distribution(VP9_NKF_BINTRAMODES, vp9_bmode_encodings,
vp9_bmode_tree, bmode_probs, branch_ct,
cm->fc.bmode_counts, 256, 1);
for (t = 0; t < VP9_BINTRAMODES - 1; ++t) {
for (t = 0; t < VP9_NKF_BINTRAMODES - 1; ++t) {
int prob;
count = branch_ct[t][0] + branch_ct[t][1];
count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count;
......
......@@ -17,6 +17,9 @@
#define SUBMVREF_COUNT 5
#define VP9_NUMMBSPLITS 4
#if CONFIG_COMP_INTRA_PRED
#define DEFAULT_COMP_INTRA_PROB 32
#endif
typedef const int vp9_mbsplit[16];
......@@ -32,11 +35,12 @@ extern const vp9_prob vp9_sub_mv_ref_prob[VP9_SUBMVREFS - 1];
extern const vp9_prob vp9_sub_mv_ref_prob2[SUBMVREF_COUNT][VP9_SUBMVREFS - 1];
extern const unsigned int vp9_kf_default_bmode_counts[VP9_BINTRAMODES]
[VP9_BINTRAMODES]
[VP9_BINTRAMODES];
extern const unsigned int vp9_kf_default_bmode_counts[VP9_KF_BINTRAMODES]
[VP9_KF_BINTRAMODES]
[VP9_KF_BINTRAMODES];
extern const vp9_tree_index vp9_bmode_tree[];
extern const vp9_tree_index vp9_kf_bmode_tree[];
extern const vp9_tree_index vp9_ymode_tree[];
extern const vp9_tree_index vp9_kf_ymode_tree[];
......@@ -48,7 +52,8 @@ extern const vp9_tree_index vp9_mv_ref_tree[];
extern const vp9_tree_index vp9_sb_mv_ref_tree[];
extern const vp9_tree_index vp9_sub_mv_ref_tree[];
extern struct vp9_token_struct vp9_bmode_encodings[VP9_BINTRAMODES];
extern struct vp9_token_struct vp9_bmode_encodings[VP9_NKF_BINTRAMODES];
extern struct vp9_token_struct vp9_kf_bmode_encodings[VP9_KF_BINTRAMODES];
extern struct vp9_token_struct vp9_ymode_encodings[VP9_YMODES];
extern struct vp9_token_struct vp9_sb_kf_ymode_encodings[VP9_I32X32_MODES];
extern struct vp9_token_struct vp9_kf_ymode_encodings[VP9_YMODES];
......@@ -76,10 +81,11 @@ extern void vp9_accum_mv_refs(struct VP9Common *pc,
MB_PREDICTION_MODE m,
const int ct[4]);
void vp9_default_bmode_probs(vp9_prob dest[VP9_BINTRAMODES - 1]);
void vp9_default_bmode_probs(vp9_prob dest[VP9_NKF_BINTRAMODES - 1]);
void vp9_kf_default_bmode_probs(vp9_prob dest[VP9_BINTRAMODES][VP9_BINTRAMODES]
[VP9_BINTRAMODES - 1]);
void vp9_kf_default_bmode_probs(vp9_prob dest[VP9_KF_BINTRAMODES]
[VP9_KF_BINTRAMODES]
[VP9_KF_BINTRAMODES - 1]);
void vp9_adapt_mode_probs(struct VP9Common *);
......
......@@ -159,12 +159,12 @@ void vp9_find_near_mvs
}
vp9_prob *vp9_mv_ref_probs(VP9_COMMON *pc,
vp9_prob p[VP9_MVREFS - 1], const int near_mv_ref_ct[4]
) {
p[0] = pc->fc.vp8_mode_contexts [near_mv_ref_ct[0]] [0];
p[1] = pc->fc.vp8_mode_contexts [near_mv_ref_ct[1]] [1];
p[2] = pc->fc.vp8_mode_contexts [near_mv_ref_ct[2]] [2];
p[3] = pc->fc.vp8_mode_contexts [near_mv_ref_ct[3]] [3];
vp9_prob p[VP9_MVREFS - 1],
const int near_mv_ref_ct[4]) {
p[0] = pc->fc.vp9_mode_contexts[near_mv_ref_ct[0]][0];
p[1] = pc->fc.vp9_mode_contexts[near_mv_ref_ct[1]][1];
p[2] = pc->fc.vp9_mode_contexts[near_mv_ref_ct[2]][2];
p[3] = pc->fc.vp9_mode_contexts[near_mv_ref_ct[3]][3];
return p;
}
......
......@@ -11,7 +11,9 @@
#include "entropymode.h"
const unsigned int vp9_kf_default_bmode_counts[VP9_BINTRAMODES][VP9_BINTRAMODES][VP9_BINTRAMODES] = {
const unsigned int vp9_kf_default_bmode_counts[VP9_KF_BINTRAMODES]
[VP9_KF_BINTRAMODES]
[VP9_KF_BINTRAMODES] = {
{
/*Above Mode : 0*/
{ 43438, 2195, 470, 316, 615, 171, 217, 412, 124, 160, }, /* left_mode 0 */
......
......@@ -44,12 +44,12 @@ void vp9_initialize_common(void);
#define COMP_PRED_CONTEXTS 2
typedef struct frame_contexts {
vp9_prob bmode_prob [VP9_BINTRAMODES - 1];
vp9_prob ymode_prob [VP9_YMODES - 1]; /* interframe intra mode probs */
vp9_prob uv_mode_prob [VP9_YMODES][VP9_UV_MODES - 1];
vp9_prob i8x8_mode_prob [VP9_I8X8_MODES - 1];
vp9_prob sub_mv_ref_prob [SUBMVREF_COUNT][VP9_SUBMVREFS - 1];
vp9_prob mbsplit_prob [VP9_NUMMBSPLITS - 1];
vp9_prob bmode_prob[VP9_NKF_BINTRAMODES - 1];
vp9_prob ymode_prob[VP9_YMODES - 1]; /* interframe intra mode probs */
vp9_prob uv_mode_prob[VP9_YMODES][VP9_UV_MODES - 1];
vp9_prob i8x8_mode_prob[VP9_I8X8_MODES - 1];
vp9_prob sub_mv_ref_prob[SUBMVREF_COUNT][VP9_SUBMVREFS - 1];
vp9_prob mbsplit_prob[VP9_NUMMBSPLITS - 1];
vp9_prob coef_probs [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [ENTROPY_NODES];
vp9_prob hybrid_coef_probs [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [ENTROPY_NODES];
vp9_prob coef_probs_8x8 [BLOCK_TYPES_8X8] [COEF_BANDS] [PREV_COEF_CONTEXTS] [ENTROPY_NODES];
......@@ -59,18 +59,18 @@ typedef struct frame_contexts {
nmv_context nmvc;
nmv_context pre_nmvc;
vp9_prob pre_bmode_prob [VP9_BINTRAMODES - 1];
vp9_prob pre_ymode_prob [VP9_YMODES - 1]; /* interframe intra mode probs */
vp9_prob pre_uv_mode_prob [VP9_YMODES][VP9_UV_MODES - 1];
vp9_prob pre_i8x8_mode_prob [VP9_I8X8_MODES - 1];
vp9_prob pre_sub_mv_ref_prob [SUBMVREF_COUNT][VP9_SUBMVREFS - 1];
vp9_prob pre_mbsplit_prob [VP9_NUMMBSPLITS - 1];
unsigned int bmode_counts [VP9_BINTRAMODES];
unsigned int ymode_counts [VP9_YMODES]; /* interframe intra mode probs */
unsigned int uv_mode_counts [VP9_YMODES][VP9_UV_MODES];
unsigned int i8x8_mode_counts [VP9_I8X8_MODES]; /* interframe intra mode probs */
unsigned int sub_mv_ref_counts [SUBMVREF_COUNT][VP9_SUBMVREFS];
unsigned int mbsplit_counts [VP9_NUMMBSPLITS];
vp9_prob pre_bmode_prob[VP9_NKF_BINTRAMODES - 1];
vp9_prob pre_ymode_prob[VP9_YMODES - 1]; /* interframe intra mode probs */
vp9_prob pre_uv_mode_prob[VP9_YMODES][VP9_UV_MODES - 1];
vp9_prob pre_i8x8_mode_prob[VP9_I8X8_MODES - 1];
vp9_prob pre_sub_mv_ref_prob[SUBMVREF_COUNT][VP9_SUBMVREFS - 1];
vp9_prob pre_mbsplit_prob[VP9_NUMMBSPLITS - 1];
unsigned int bmode_counts[VP9_NKF_BINTRAMODES];
unsigned int ymode_counts[VP9_YMODES]; /* interframe intra mode probs */
unsigned int uv_mode_counts[VP9_YMODES][VP9_UV_MODES];
unsigned int i8x8_mode_counts[VP9_I8X8_MODES]; /* interframe intra probs */
unsigned int sub_mv_ref_counts[SUBMVREF_COUNT][VP9_SUBMVREFS];
unsigned int mbsplit_counts[VP9_NUMMBSPLITS];
vp9_prob pre_coef_probs [BLOCK_TYPES] [COEF_BANDS]
[PREV_COEF_CONTEXTS] [ENTROPY_NODES];
......@@ -108,7 +108,7 @@ typedef struct frame_contexts {
int mode_context[6][4];
int mode_context_a[6][4];
int vp8_mode_contexts[6][4];
int vp9_mode_contexts[6][4];
int mv_ref_ct[6][4][2];
int mv_ref_ct_a[6][4][2];
} FRAME_CONTEXT;
......@@ -241,7 +241,9 @@ typedef struct VP9Common {
/* keyframe block modes are predicted by their above, left neighbors */
vp9_prob kf_bmode_prob [VP9_BINTRAMODES] [VP9_BINTRAMODES] [VP9_BINTRAMODES - 1];
vp9_prob kf_bmode_prob[VP9_KF_BINTRAMODES]
[VP9_KF_BINTRAMODES]
[VP9_KF_BINTRAMODES - 1];
vp9_prob kf_ymode_prob[8][VP9_YMODES - 1]; /* keyframe "" */
#if CONFIG_SUPERBLOCKS
vp9_prob sb_kf_ymode_prob[8][VP9_I32X32_MODES - 1];
......
......@@ -196,9 +196,50 @@ static void d153_predictor(uint8_t *ypred_ptr, int y_stride, int n,
}
}
static void corner_predictor(unsigned char *ypred_ptr, int y_stride, int n,
unsigned char *yabove_row,
unsigned char *yleft_col) {
int h[32], v[32], mh, mv, maxgradh, maxgradv, x, y, nx, ny;
int i, j;
int top_left = yabove_row[-1];
mh = mv = 0;
maxgradh = yabove_row[1] - top_left;
maxgradv = yleft_col[1] - top_left;
for (i = 2; i < n; ++i) {
int gh = yabove_row[i] - yabove_row[i - 2];
int gv = yleft_col[i] - yleft_col[i - 2];
if (gh > maxgradh) {
maxgradh = gh;
mh = i - 1;
}
if (gv > maxgradv) {
maxgradv = gv;
mv = i - 1;
}
}
nx = mh + mv + 3;
ny = 2 * n + 1 - nx;
x = top_left;
for (i = 0; i <= mh; ++i) x += yabove_row[i];
for (i = 0; i <= mv; ++i) x += yleft_col[i];
x += (nx >> 1);
x /= nx;
y = 0;
for (i = mh + 1; i < n; ++i) y += yabove_row[i];
for (i = mv + 1; i < n; ++i) y += yleft_col[i];
y += (ny >> 1);
y /= ny;
for (i = 0; i < n; ++i) {
for (j = 0; j < n; ++j)
ypred_ptr[j] = (i <= mh && j <= mv ? x : y);
ypred_ptr += y_stride;
}
}
void vp9_recon_intra_mbuv(MACROBLOCKD *xd) {
int i;
for (i = 16; i < 24; i += 2) {
BLOCKD *b = &xd->block[i];
vp9_recon2b(b->predictor, b->diff, *(b->base_dst) + b->dst, b->dst_stride);
......
......@@ -14,5 +14,8 @@
#include "blockd.h"
extern void vp9_recon_intra_mbuv(MACROBLOCKD *xd);
extern B_PREDICTION_MODE vp9_find_dominant_direction(unsigned char *ptr,
int stride, int n);
extern B_PREDICTION_MODE vp9_find_bpred_context(BLOCKD *x);
#endif // __INC_RECONINTRA_H
......@@ -14,8 +14,146 @@
#include "reconintra.h"
#include "vpx_rtcd.h"
void vp9_intra4x4_predict_c(BLOCKD *x, int b_mode,
unsigned char *predictor) {
#if CONFIG_NEWBINTRAMODES
static int find_grad_measure(unsigned char *x, int stride, int n, int t,
int dx, int dy) {
int i, j;
int count = 0, gsum = 0, gdiv;
/* TODO: Make this code more efficient by breaking up into two loops */
for (i = -t; i < n; ++i)
for (j = -t; j < n; ++j) {
int g;
if (i >= 0 && j >= 0) continue;
if (i + dy >= 0 && j + dx >= 0) continue;
if (i + dy < -t || i + dy >= n || j + dx < -t || j + dx >= n) continue;
g = abs(x[(i + dy) * stride + j + dx] - x[i * stride + j]);
gsum += g * g;
count++;
}
gdiv = (dx * dx + dy * dy) * count;
return ((gsum << 8) + (gdiv >> 1)) / gdiv;
}
#if CONTEXT_PRED_REPLACEMENTS == 6
B_PREDICTION_MODE vp9_find_dominant_direction(
unsigned char *ptr, int stride, int n) {
int g[8], i, imin, imax;
g[1] = find_grad_measure(ptr, stride, n, 4, 2, 1);
g[2] = find_grad_measure(ptr, stride, n, 4, 1, 1);
g[3] = find_grad_measure(ptr, stride, n, 4, 1, 2);
g[5] = find_grad_measure(ptr, stride, n, 4, -1, 2);
g[6] = find_grad_measure(ptr, stride, n, 4, -1, 1);
g[7] = find_grad_measure(ptr, stride, n, 4, -2, 1);
imin = 1;
for (i = 2; i < 8; i += 1 + (i == 3))
imin = (g[i] < g[imin] ? i : imin);
imax = 1;
for (i = 2; i < 8; i += 1 + (i == 3))
imax = (g[i] > g[imax] ? i : imax);
/*
printf("%d %d %d %d %d %d = %d %d\n",
g[1], g[2], g[3], g[5], g[6], g[7], imin, imax);
*/
switch (imin) {
case 1:
return B_HD_PRED;
case 2:
return B_RD_PRED;
case 3:
return B_VR_PRED;
case 5:
return B_VL_PRED;
case 6:
return B_LD_PRED;
case 7:
return B_HU_PRED;
default:
assert(0);
}
}
#elif CONTEXT_PRED_REPLACEMENTS == 4
B_PREDICTION_MODE vp9_find_dominant_direction(
unsigned char *ptr, int stride, int n) {
int g[8], i, imin, imax;
g[1] = find_grad_measure(ptr, stride, n, 4, 2, 1);
g[3] = find_grad_measure(ptr, stride, n, 4, 1, 2);
g[5] = find_grad_measure(ptr, stride, n, 4, -1, 2);
g[7] = find_grad_measure(ptr, stride, n, 4, -2, 1);
imin = 1;
for (i = 3; i < 8; i+=2)
imin = (g[i] < g[imin] ? i : imin);