Commit 29824a42 authored by Rupert Swarbrick's avatar Rupert Swarbrick Committed by Debargha Mukherjee

Refactor and generalise OBMC prediction code

When doing OBMC prediction, the code must iterate over the blocks
above or to the left of the current block. In reconinter.c and
rdopt.c, there are several pieces of code that do this. These all work
in roughly the same way, iterating over the xd->mi array (although
some are written with for loops and others with do/while). To visit
each neighbouring block exactly once, each of these loops used an
"mi_step" variable which was set to the width or height of the
neighbouring block in mi-units and the loop counter got incremented by
mi_step to jump to the next block.

This patch unifies the code slightly (just using for loops) and
simplifies it when the CHROMA_SUB8X8 experiment is enabled. In this
case, chroma information is stored in the bottom right block of each
8x8 pixel region. That is, if a block has width 4 and an even mi_col,
the chroma information we need is actually found in the block
immediately to its right.

The existing code implemented this by bumping the current column or
row counter (usually mi_col_offset or mi_row_offset) and duplicating
the first part of the loop body to do it again with the new
counter. It also had to double mi_step to avoid visiting the next-door
block again.

The new code essentially just uses the "continue" keyword to restart
the loop. There's a little more book-keeping required: we might have
to increment "ilimit", the maximum loop index, to ensure we don't exit
the loop too early.

The result is hopefully easier to read, but it's also more general (in
the CHROMA_SUB8X8 case). The existing code assumed the current block
never had width or height below 8 and thus mi_col and mi_row were
always even. As such, whenever the neighbouring block had a width or
height of 4, we knew that we needed to skip to the next neighbouring
block to get the required chroma information. This version of the code
can deal with the current block being smaller. The main difference is
that it decides whether to skip forward by examining the parity of
(mi_col + i) or (mi_row + i).

This change will be needed for 16x4/4x16 block support.

Change-Id: I39c1bbc00a6e2ad1ac17b8eed3980a8bcc040074
parent d9e0e0be
This diff is collapsed.
......@@ -12516,7 +12516,6 @@ static void calc_target_weighted_pred(const AV1_COMMON *cm, const MACROBLOCK *x,
const int overlap =
AOMMIN(block_size_high[bsize] >> 1, block_size_high[BLOCK_64X64] >> 1);
const int miw = AOMMIN(xd->n8_w, cm->mi_cols - mi_col);
const int mi_row_offset = -1;
const uint8_t *const mask1d = av1_get_obmc_mask(overlap);
const int neighbor_limit = max_neighbor_obmc[b_width_log2_lookup[bsize]];
int neighbor_count = 0;
......@@ -12525,22 +12524,24 @@ static void calc_target_weighted_pred(const AV1_COMMON *cm, const MACROBLOCK *x,
i = 0;
do { // for each mi in the above row
const int mi_col_offset = i;
const MB_MODE_INFO *above_mbmi =
&xd->mi[mi_col_offset + mi_row_offset * xd->mi_stride]->mbmi;
const MB_MODE_INFO *above_mbmi = &xd->mi[i + (-1) * xd->mi_stride]->mbmi;
const int above_width = mi_size_wide[above_mbmi->sb_type];
int above_step = AOMMIN(above_width, mi_size_wide[BLOCK_64X64]);
#if CONFIG_CHROMA_SUB8X8
if (above_mbmi->sb_type < BLOCK_8X8)
above_mbmi =
&xd->mi[mi_col_offset + 1 + mi_row_offset * xd->mi_stride]->mbmi;
// If the block above is narrower than 8x8 and starts at an even column,
// we need to skip right one to get to the block with the correct chroma
// information.
if (above_width == 1 && ((mi_col + i) % 2 == 0)) {
above_mbmi = &xd->mi[i + 1 + (-1) * xd->mi_stride]->mbmi;
above_step = 2;
}
#endif
const BLOCK_SIZE a_bsize = AOMMAX(above_mbmi->sb_type, BLOCK_8X8);
const int above_step =
AOMMIN(mi_size_wide[a_bsize], mi_size_wide[BLOCK_64X64]);
const int mi_step = AOMMIN(xd->n8_w, above_step);
const int neighbor_bw = mi_step * MI_SIZE;
if (is_neighbor_overlappable(above_mbmi)) {
if (!CONFIG_CB4X4 && (a_bsize == BLOCK_4X4 || a_bsize == BLOCK_4X8))
if (!CONFIG_CB4X4 && above_width == mi_size_wide[BLOCK_4X4])
neighbor_count += 2;
else
neighbor_count++;
......@@ -12598,7 +12599,6 @@ static void calc_target_weighted_pred(const AV1_COMMON *cm, const MACROBLOCK *x,
const int overlap =
AOMMIN(block_size_wide[bsize] >> 1, block_size_wide[BLOCK_64X64] >> 1);
const int mih = AOMMIN(xd->n8_h, cm->mi_rows - mi_row);
const int mi_col_offset = -1;
const uint8_t *const mask1d = av1_get_obmc_mask(overlap);
const int neighbor_limit = max_neighbor_obmc[b_height_log2_lookup[bsize]];
int neighbor_count = 0;
......@@ -12607,23 +12607,23 @@ static void calc_target_weighted_pred(const AV1_COMMON *cm, const MACROBLOCK *x,
i = 0;
do { // for each mi in the left column
const int mi_row_offset = i;
MB_MODE_INFO *left_mbmi =
&xd->mi[mi_col_offset + mi_row_offset * xd->mi_stride]->mbmi;
const MB_MODE_INFO *left_mbmi = &xd->mi[-1 + i * xd->mi_stride]->mbmi;
const int left_height = mi_size_high[left_mbmi->sb_type];
int left_step = AOMMIN(left_height, mi_size_high[BLOCK_64X64]);
#if CONFIG_CHROMA_SUB8X8
if (left_mbmi->sb_type < BLOCK_8X8)
left_mbmi =
&xd->mi[mi_col_offset + (mi_row_offset + 1) * xd->mi_stride]->mbmi;
// If the block is shorter than 8x8 and starts on an even row, we need to
// skip down one to get to the block with the correct chroma information.
if (left_height == 1 && ((mi_row + i) % 2 == 0)) {
left_mbmi = &xd->mi[-1 + (i + 1) * xd->mi_stride]->mbmi;
left_step = 2;
}
#endif
const BLOCK_SIZE l_bsize = AOMMAX(left_mbmi->sb_type, BLOCK_8X8);
const int left_step =
AOMMIN(mi_size_high[l_bsize], mi_size_high[BLOCK_64X64]);
const int mi_step = AOMMIN(xd->n8_h, left_step);
const int neighbor_bh = mi_step * MI_SIZE;
if (is_neighbor_overlappable(left_mbmi)) {
if (!CONFIG_CB4X4 && (l_bsize == BLOCK_4X4 || l_bsize == BLOCK_8X4))
if (!CONFIG_CB4X4 && (left_height == mi_size_wide[BLOCK_4X4]))
neighbor_count += 2;
else
neighbor_count++;
......
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