• Rupert Swarbrick's avatar
    Refactor and generalise OBMC prediction code · 29824a42
    Rupert Swarbrick authored
    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
rdopt.c 470 KB