Adding has_second_ref function.

Updating implementation of vp9_get_pred_context_single_ref_p1 using
has_second_ref function to make code easier to read.

Change-Id: Ie8f60403a7195117ceb2c6c43176ca9a9e70b909
This commit is contained in:
Dmitry Kovalev 2013-08-19 18:39:34 -07:00
parent 31c97c2bdf
commit d8286dd56d
2 changed files with 39 additions and 34 deletions

View File

@ -161,10 +161,14 @@ typedef struct {
union b_mode_info bmi[4];
} MODE_INFO;
static int is_inter_block(const MB_MODE_INFO *mbmi) {
static INLINE int is_inter_block(const MB_MODE_INFO *mbmi) {
return mbmi->ref_frame[0] > INTRA_FRAME;
}
static INLINE int has_second_ref(const MB_MODE_INFO *mbmi) {
return mbmi->ref_frame[1] > INTRA_FRAME;
}
enum mv_precision {
MV_PRECISION_Q3,
MV_PRECISION_Q4

View File

@ -216,52 +216,53 @@ unsigned char vp9_get_pred_context_single_ref_p1(const MACROBLOCKD *xd) {
// left of the entries correpsonding to real macroblocks.
// The prediction flags in these dummy entries are initialised to 0.
if (above_in_image && left_in_image) { // both edges available
if (above_intra && left_intra) {
if (above_intra && left_intra) { // intra/intra
pred_context = 2;
} else if (above_intra || left_intra) {
} else if (above_intra || left_intra) { // intra/inter or inter/intra
const MB_MODE_INFO *edge_mbmi = above_intra ? left_mbmi : above_mbmi;
if (edge_mbmi->ref_frame[1] <= INTRA_FRAME)
if (!has_second_ref(edge_mbmi))
pred_context = 4 * (edge_mbmi->ref_frame[0] == LAST_FRAME);
else
pred_context = 1 + (edge_mbmi->ref_frame[0] == LAST_FRAME ||
edge_mbmi->ref_frame[1] == LAST_FRAME);
} else if (above_mbmi->ref_frame[1] <= INTRA_FRAME &&
left_mbmi->ref_frame[1] <= INTRA_FRAME) {
pred_context = 2 * (above_mbmi->ref_frame[0] == LAST_FRAME) +
2 * (left_mbmi->ref_frame[0] == LAST_FRAME);
} else if (above_mbmi->ref_frame[1] > INTRA_FRAME &&
left_mbmi->ref_frame[1] > INTRA_FRAME) {
pred_context = 1 + (above_mbmi->ref_frame[0] == LAST_FRAME ||
above_mbmi->ref_frame[1] == LAST_FRAME ||
left_mbmi->ref_frame[0] == LAST_FRAME ||
left_mbmi->ref_frame[1] == LAST_FRAME);
} else {
MV_REFERENCE_FRAME rfs = above_mbmi->ref_frame[1] <= INTRA_FRAME ?
above_mbmi->ref_frame[0] : left_mbmi->ref_frame[0];
MV_REFERENCE_FRAME crf1 = above_mbmi->ref_frame[1] > INTRA_FRAME ?
above_mbmi->ref_frame[0] : left_mbmi->ref_frame[0];
MV_REFERENCE_FRAME crf2 = above_mbmi->ref_frame[1] > INTRA_FRAME ?
above_mbmi->ref_frame[1] : left_mbmi->ref_frame[1];
} else { // inter/inter
if (!has_second_ref(above_mbmi) && !has_second_ref(left_mbmi)) {
pred_context = 2 * (above_mbmi->ref_frame[0] == LAST_FRAME) +
2 * (left_mbmi->ref_frame[0] == LAST_FRAME);
} else if (has_second_ref(above_mbmi) && has_second_ref(left_mbmi)) {
pred_context = 1 + (above_mbmi->ref_frame[0] == LAST_FRAME ||
above_mbmi->ref_frame[1] == LAST_FRAME ||
left_mbmi->ref_frame[0] == LAST_FRAME ||
left_mbmi->ref_frame[1] == LAST_FRAME);
} else {
const MV_REFERENCE_FRAME rfs = !has_second_ref(above_mbmi) ?
above_mbmi->ref_frame[0] : left_mbmi->ref_frame[0];
const MV_REFERENCE_FRAME crf1 = has_second_ref(above_mbmi) ?
above_mbmi->ref_frame[0] : left_mbmi->ref_frame[0];
const MV_REFERENCE_FRAME crf2 = has_second_ref(above_mbmi) ?
above_mbmi->ref_frame[1] : left_mbmi->ref_frame[1];
if (rfs == LAST_FRAME)
pred_context = 3 + (crf1 == LAST_FRAME || crf2 == LAST_FRAME);
else
pred_context = crf1 == LAST_FRAME || crf2 == LAST_FRAME;
if (rfs == LAST_FRAME)
pred_context = 3 + (crf1 == LAST_FRAME || crf2 == LAST_FRAME);
else
pred_context = crf1 == LAST_FRAME || crf2 == LAST_FRAME;
}
}
} else if (above_in_image || left_in_image) { // one edge available
const MB_MODE_INFO *edge_mbmi = above_in_image ? above_mbmi : left_mbmi;
if (edge_mbmi->ref_frame[0] == INTRA_FRAME)
if (!is_inter_block(edge_mbmi)) { // intra
pred_context = 2;
else if (edge_mbmi->ref_frame[1] <= INTRA_FRAME)
pred_context = 4 * (edge_mbmi->ref_frame[0] == LAST_FRAME);
else
pred_context = 1 + (edge_mbmi->ref_frame[0] == LAST_FRAME ||
edge_mbmi->ref_frame[1] == LAST_FRAME);
} else { // no edges available (2)
} else { // inter
if (!has_second_ref(edge_mbmi))
pred_context = 4 * (edge_mbmi->ref_frame[0] == LAST_FRAME);
else
pred_context = 1 + (edge_mbmi->ref_frame[0] == LAST_FRAME ||
edge_mbmi->ref_frame[1] == LAST_FRAME);
}
} else { // no edges available
pred_context = 2;
}
assert(pred_context >= 0 && pred_context < REF_CONTEXTS);
return pred_context;
}