Commit 3f611555 authored by Dmitry Kovalev's avatar Dmitry Kovalev
Browse files

Changing the order switchable filter enum constants.

This changeset allows to remove vp9_switchable_interp and
vp9_switchable_interp_map arrays and make code much clear. Actually we
still have to use these mapping but only inside read_interp_filter_type and
write_interp_filter_type functions.

Change-Id: I4026c6f8c4acefba6c81421b7bacbaa52cc45f50
parent d007446b
...@@ -56,11 +56,11 @@ typedef enum { ...@@ -56,11 +56,11 @@ typedef enum {
} FRAME_TYPE; } FRAME_TYPE;
typedef enum { typedef enum {
EIGHTTAP_SMOOTH, EIGHTTAP = 0,
EIGHTTAP, EIGHTTAP_SMOOTH = 1,
EIGHTTAP_SHARP, EIGHTTAP_SHARP = 2,
BILINEAR, BILINEAR = 3,
SWITCHABLE /* should be the last one */ SWITCHABLE = 4 /* should be the last one */
} INTERPOLATIONFILTERTYPE; } INTERPOLATIONFILTERTYPE;
typedef enum { typedef enum {
......
...@@ -339,13 +339,10 @@ void vp9_init_mbmode_probs(VP9_COMMON *cm) { ...@@ -339,13 +339,10 @@ void vp9_init_mbmode_probs(VP9_COMMON *cm) {
} }
const vp9_tree_index vp9_switchable_interp_tree[VP9_SWITCHABLE_FILTERS*2-2] = { const vp9_tree_index vp9_switchable_interp_tree[VP9_SWITCHABLE_FILTERS*2-2] = {
-0, 2, -EIGHTTAP, 2,
-1, -2 -EIGHTTAP_SMOOTH, -EIGHTTAP_SHARP
}; };
struct vp9_token vp9_switchable_interp_encodings[VP9_SWITCHABLE_FILTERS]; struct vp9_token vp9_switchable_interp_encodings[VP9_SWITCHABLE_FILTERS];
const INTERPOLATIONFILTERTYPE vp9_switchable_interp[VP9_SWITCHABLE_FILTERS] = {
EIGHTTAP, EIGHTTAP_SMOOTH, EIGHTTAP_SHARP};
const int vp9_switchable_interp_map[SWITCHABLE + 1] = {1, 0, 2, -1, -1};
void vp9_entropy_mode_init() { void vp9_entropy_mode_init() {
vp9_tokens_from_tree(vp9_intra_mode_encodings, vp9_intra_mode_tree); vp9_tokens_from_tree(vp9_intra_mode_encodings, vp9_intra_mode_tree);
......
...@@ -49,11 +49,6 @@ extern struct vp9_token vp9_inter_mode_encodings[VP9_INTER_MODES]; ...@@ -49,11 +49,6 @@ extern struct vp9_token vp9_inter_mode_encodings[VP9_INTER_MODES];
extern const vp9_tree_index vp9_partition_tree[]; extern const vp9_tree_index vp9_partition_tree[];
extern struct vp9_token vp9_partition_encodings[PARTITION_TYPES]; extern struct vp9_token vp9_partition_encodings[PARTITION_TYPES];
extern const INTERPOLATIONFILTERTYPE vp9_switchable_interp
[VP9_SWITCHABLE_FILTERS];
extern const int vp9_switchable_interp_map[SWITCHABLE + 1];
extern const vp9_tree_index vp9_switchable_interp_tree extern const vp9_tree_index vp9_switchable_interp_tree
[2 * (VP9_SWITCHABLE_FILTERS - 1)]; [2 * (VP9_SWITCHABLE_FILTERS - 1)];
......
...@@ -29,18 +29,16 @@ unsigned char vp9_get_pred_context_switchable_interp(const MACROBLOCKD *xd) { ...@@ -29,18 +29,16 @@ unsigned char vp9_get_pred_context_switchable_interp(const MACROBLOCKD *xd) {
// The prediction flags in these dummy entries are initialised to 0. // The prediction flags in these dummy entries are initialised to 0.
// left // left
const int left_mv_pred = is_inter_mode(left_mbmi->mode); const int left_mv_pred = is_inter_mode(left_mbmi->mode);
const int left_interp = left_in_image && left_mv_pred ? const int left_interp = left_in_image && left_mv_pred
vp9_switchable_interp_map[left_mbmi->interp_filter] : ? left_mbmi->interp_filter
VP9_SWITCHABLE_FILTERS; : VP9_SWITCHABLE_FILTERS;
// above // above
const int above_mv_pred = is_inter_mode(above_mbmi->mode); const int above_mv_pred = is_inter_mode(above_mbmi->mode);
const int above_interp = above_in_image && above_mv_pred ? const int above_interp = above_in_image && above_mv_pred
vp9_switchable_interp_map[above_mbmi->interp_filter] : ? above_mbmi->interp_filter
VP9_SWITCHABLE_FILTERS; : VP9_SWITCHABLE_FILTERS;
assert(left_interp != -1);
assert(above_interp != -1);
if (left_interp == above_interp) if (left_interp == above_interp)
return left_interp; return left_interp;
......
...@@ -371,10 +371,10 @@ static INLINE INTERPOLATIONFILTERTYPE read_switchable_filter_type( ...@@ -371,10 +371,10 @@ static INLINE INTERPOLATIONFILTERTYPE read_switchable_filter_type(
VP9_COMMON *const cm = &pbi->common; VP9_COMMON *const cm = &pbi->common;
MACROBLOCKD *const xd = &pbi->mb; MACROBLOCKD *const xd = &pbi->mb;
const vp9_prob *probs = vp9_get_pred_probs_switchable_interp(cm, xd); const vp9_prob *probs = vp9_get_pred_probs_switchable_interp(cm, xd);
const int index = treed_read(r, vp9_switchable_interp_tree, probs); const int type = treed_read(r, vp9_switchable_interp_tree, probs);
const int ctx = vp9_get_pred_context_switchable_interp(xd); const int ctx = vp9_get_pred_context_switchable_interp(xd);
++cm->counts.switchable_interp[ctx][index]; ++cm->counts.switchable_interp[ctx][type];
return vp9_switchable_interp[index]; return type;
} }
static void read_intra_block_mode_info(VP9D_COMP *pbi, MODE_INFO *mi, static void read_intra_block_mode_info(VP9D_COMP *pbi, MODE_INFO *mi,
......
...@@ -497,8 +497,11 @@ static void setup_quantization(VP9D_COMP *pbi, struct vp9_read_bit_buffer *rb) { ...@@ -497,8 +497,11 @@ static void setup_quantization(VP9D_COMP *pbi, struct vp9_read_bit_buffer *rb) {
static INTERPOLATIONFILTERTYPE read_interp_filter_type( static INTERPOLATIONFILTERTYPE read_interp_filter_type(
struct vp9_read_bit_buffer *rb) { struct vp9_read_bit_buffer *rb) {
const INTERPOLATIONFILTERTYPE literal_to_type[] = { EIGHTTAP_SMOOTH,
EIGHTTAP,
EIGHTTAP_SHARP };
return vp9_rb_read_bit(rb) ? SWITCHABLE return vp9_rb_read_bit(rb) ? SWITCHABLE
: vp9_rb_read_literal(rb, 2); : literal_to_type[vp9_rb_read_literal(rb, 2)];
} }
static void read_frame_size(struct vp9_read_bit_buffer *rb, static void read_frame_size(struct vp9_read_bit_buffer *rb,
......
...@@ -479,8 +479,7 @@ static void pack_inter_mode_mvs(VP9_COMP *cpi, MODE_INFO *m, vp9_writer *bc) { ...@@ -479,8 +479,7 @@ static void pack_inter_mode_mvs(VP9_COMP *cpi, MODE_INFO *m, vp9_writer *bc) {
if (cpi->common.mcomp_filter_type == SWITCHABLE) { if (cpi->common.mcomp_filter_type == SWITCHABLE) {
write_token(bc, vp9_switchable_interp_tree, write_token(bc, vp9_switchable_interp_tree,
vp9_get_pred_probs_switchable_interp(&cpi->common, xd), vp9_get_pred_probs_switchable_interp(&cpi->common, xd),
vp9_switchable_interp_encodings + &vp9_switchable_interp_encodings[mi->interp_filter]);
vp9_switchable_interp_map[mi->interp_filter]);
} else { } else {
assert(mi->interp_filter == cpi->common.mcomp_filter_type); assert(mi->interp_filter == cpi->common.mcomp_filter_type);
} }
...@@ -1072,9 +1071,11 @@ static void encode_txfm_probs(VP9_COMP *cpi, vp9_writer *w) { ...@@ -1072,9 +1071,11 @@ static void encode_txfm_probs(VP9_COMP *cpi, vp9_writer *w) {
static void write_interp_filter_type(INTERPOLATIONFILTERTYPE type, static void write_interp_filter_type(INTERPOLATIONFILTERTYPE type,
struct vp9_write_bit_buffer *wb) { struct vp9_write_bit_buffer *wb) {
const int type_to_literal[] = { 1, 0, 2 };
vp9_wb_write_bit(wb, type == SWITCHABLE); vp9_wb_write_bit(wb, type == SWITCHABLE);
if (type != SWITCHABLE) if (type != SWITCHABLE)
vp9_wb_write_literal(wb, type, 2); vp9_wb_write_literal(wb, type_to_literal[type], 2);
} }
static void fix_mcomp_filter_type(VP9_COMP *cpi) { static void fix_mcomp_filter_type(VP9_COMP *cpi) {
...@@ -1094,7 +1095,7 @@ static void fix_mcomp_filter_type(VP9_COMP *cpi) { ...@@ -1094,7 +1095,7 @@ static void fix_mcomp_filter_type(VP9_COMP *cpi) {
// Only one filter is used. So set the filter at frame level // Only one filter is used. So set the filter at frame level
for (i = 0; i < VP9_SWITCHABLE_FILTERS; ++i) { for (i = 0; i < VP9_SWITCHABLE_FILTERS; ++i) {
if (count[i]) { if (count[i]) {
cm->mcomp_filter_type = vp9_switchable_interp[i]; cm->mcomp_filter_type = i;
break; break;
} }
} }
......
...@@ -439,8 +439,7 @@ static void update_state(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx, ...@@ -439,8 +439,7 @@ static void update_state(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx,
if (cpi->common.mcomp_filter_type == SWITCHABLE if (cpi->common.mcomp_filter_type == SWITCHABLE
&& is_inter_mode(mbmi->mode)) { && is_inter_mode(mbmi->mode)) {
++cpi->common.counts.switchable_interp[ ++cpi->common.counts.switchable_interp[
vp9_get_pred_context_switchable_interp(xd)] vp9_get_pred_context_switchable_interp(xd)][mbmi->interp_filter];
[vp9_switchable_interp_map[mbmi->interp_filter]];
} }
cpi->rd_comp_pred_diff[SINGLE_PREDICTION_ONLY] += ctx->single_pred_diff; cpi->rd_comp_pred_diff[SINGLE_PREDICTION_ONLY] += ctx->single_pred_diff;
...@@ -2385,15 +2384,15 @@ void vp9_encode_frame(VP9_COMP *cpi) { ...@@ -2385,15 +2384,15 @@ void vp9_encode_frame(VP9_COMP *cpi) {
cpi->rd_filter_threshes[frame_type][2] && cpi->rd_filter_threshes[frame_type][2] &&
cpi->rd_filter_threshes[frame_type][1] > cpi->rd_filter_threshes[frame_type][1] >
cpi->rd_filter_threshes[frame_type][VP9_SWITCHABLE_FILTERS]) { cpi->rd_filter_threshes[frame_type][VP9_SWITCHABLE_FILTERS]) {
filter_type = vp9_switchable_interp[1]; filter_type = EIGHTTAP_SMOOTH;
} else if (cpi->rd_filter_threshes[frame_type][2] > } else if (cpi->rd_filter_threshes[frame_type][2] >
cpi->rd_filter_threshes[frame_type][0] && cpi->rd_filter_threshes[frame_type][0] &&
cpi->rd_filter_threshes[frame_type][2] > cpi->rd_filter_threshes[frame_type][2] >
cpi->rd_filter_threshes[frame_type][VP9_SWITCHABLE_FILTERS]) { cpi->rd_filter_threshes[frame_type][VP9_SWITCHABLE_FILTERS]) {
filter_type = vp9_switchable_interp[2]; filter_type = EIGHTTAP_SHARP;
} else if (cpi->rd_filter_threshes[frame_type][0] > } else if (cpi->rd_filter_threshes[frame_type][0] >
cpi->rd_filter_threshes[frame_type][VP9_SWITCHABLE_FILTERS]) { cpi->rd_filter_threshes[frame_type][VP9_SWITCHABLE_FILTERS]) {
filter_type = vp9_switchable_interp[0]; filter_type = EIGHTTAP;
} else { } else {
filter_type = SWITCHABLE; filter_type = SWITCHABLE;
} }
......
...@@ -2003,7 +2003,7 @@ static void rd_check_segment_txsize(VP9_COMP *cpi, MACROBLOCK *x, ...@@ -2003,7 +2003,7 @@ static void rd_check_segment_txsize(VP9_COMP *cpi, MACROBLOCK *x,
} }
if (mbmi->ref_frame[1] > 0 && this_mode == NEWMV && if (mbmi->ref_frame[1] > 0 && this_mode == NEWMV &&
mbmi->interp_filter == vp9_switchable_interp[0]) { mbmi->interp_filter == EIGHTTAP) {
if (seg_mvs[i][mbmi->ref_frame[1]].as_int == INVALID_MV || if (seg_mvs[i][mbmi->ref_frame[1]].as_int == INVALID_MV ||
seg_mvs[i][mbmi->ref_frame[0]].as_int == INVALID_MV) seg_mvs[i][mbmi->ref_frame[0]].as_int == INVALID_MV)
continue; continue;
...@@ -2456,7 +2456,7 @@ static INLINE int get_switchable_rate(MACROBLOCK *x) { ...@@ -2456,7 +2456,7 @@ static INLINE int get_switchable_rate(MACROBLOCK *x) {
MB_MODE_INFO *const mbmi = &xd->mode_info_context->mbmi; MB_MODE_INFO *const mbmi = &xd->mode_info_context->mbmi;
const int c = vp9_get_pred_context_switchable_interp(xd); const int c = vp9_get_pred_context_switchable_interp(xd);
const int m = vp9_switchable_interp_map[mbmi->interp_filter]; const int m = mbmi->interp_filter;
return SWITCHABLE_INTERP_RATE_FACTOR * x->switchable_interp_costs[c][m]; return SWITCHABLE_INTERP_RATE_FACTOR * x->switchable_interp_costs[c][m];
} }
...@@ -2882,9 +2882,8 @@ static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, ...@@ -2882,9 +2882,8 @@ static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
for (i = 0; i < VP9_SWITCHABLE_FILTERS; ++i) { for (i = 0; i < VP9_SWITCHABLE_FILTERS; ++i) {
int j; int j;
int64_t rs_rd; int64_t rs_rd;
const INTERPOLATIONFILTERTYPE filter = vp9_switchable_interp[i];
const int is_intpel_interp = intpel_mv; const int is_intpel_interp = intpel_mv;
mbmi->interp_filter = filter; mbmi->interp_filter = i;
vp9_setup_interp_filters(xd, mbmi->interp_filter, cm); vp9_setup_interp_filters(xd, mbmi->interp_filter, cm);
rs = get_switchable_rate(x); rs = get_switchable_rate(x);
rs_rd = RDCOST(x->rdmult, x->rddiv, rs, 0); rs_rd = RDCOST(x->rdmult, x->rddiv, rs, 0);
...@@ -3593,8 +3592,7 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, ...@@ -3593,8 +3592,7 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
++switchable_filter_index) { ++switchable_filter_index) {
int newbest, rs; int newbest, rs;
int64_t rs_rd; int64_t rs_rd;
mbmi->interp_filter = mbmi->interp_filter = switchable_filter_index;
vp9_switchable_interp[switchable_filter_index];
vp9_setup_interp_filters(xd, mbmi->interp_filter, &cpi->common); vp9_setup_interp_filters(xd, mbmi->interp_filter, &cpi->common);
tmp_rd = rd_pick_best_mbsegmentation(cpi, x, tmp_rd = rd_pick_best_mbsegmentation(cpi, x,
...@@ -3927,8 +3925,7 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, ...@@ -3927,8 +3925,7 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
if (!mode_excluded && !disable_skip && ref_frame != INTRA_FRAME && if (!mode_excluded && !disable_skip && ref_frame != INTRA_FRAME &&
cm->mcomp_filter_type != BILINEAR) { cm->mcomp_filter_type != BILINEAR) {
int64_t ref = cpi->rd_filter_cache[cm->mcomp_filter_type == SWITCHABLE ? int64_t ref = cpi->rd_filter_cache[cm->mcomp_filter_type == SWITCHABLE ?
VP9_SWITCHABLE_FILTERS : VP9_SWITCHABLE_FILTERS : cm->mcomp_filter_type];
vp9_switchable_interp_map[cm->mcomp_filter_type]];
for (i = 0; i <= VP9_SWITCHABLE_FILTERS; i++) { for (i = 0; i <= VP9_SWITCHABLE_FILTERS; i++) {
int64_t adj_rd; int64_t adj_rd;
// In cases of poor prediction, filter_cache[] can contain really big // In cases of poor prediction, filter_cache[] can contain really big
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment