19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/*
29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *  Copyright (c) 2011 The WebM project authors. All Rights Reserved.
39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *
49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *  Use of this source code is governed by a BSD-style license
59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *  that can be found in the LICENSE file in the root of the source
69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *  tree. An additional intellectual property rights grant can be found
79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *  in the file PATENTS.  All contributing project authors may
89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *  be found in the AUTHORS file in the root of the source tree.
99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */
109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <assert.h>
129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "error_concealment.h"
149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "onyxd_int.h"
159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "decodemv.h"
169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "vpx_mem/vpx_mem.h"
179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "vp8/common/findnearmv.h"
189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "vp8/common/common.h"
199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define FLOOR(x,q) ((x) & -(1 << (q)))
219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define NUM_NEIGHBORS 20
239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Halltypedef struct ec_position
259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int row;
279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int col;
289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} EC_POS;
299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/*
319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Regenerate the table in Matlab with:
329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * x = meshgrid((1:4), (1:4));
339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * y = meshgrid((1:4), (1:4))';
349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * W = round((1./(sqrt(x.^2 + y.^2))*2^7));
359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * W(1,1) = 0;
369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */
379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic const int weights_q7[5][5] = {
389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall       {  0,   128,    64,    43,    32 },
399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall       {128,    91,    57,    40,    31 },
409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall       { 64,    57,    45,    36,    29 },
419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall       { 43,    40,    36,    30,    26 },
429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall       { 32,    31,    29,    26,    23 }
439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall};
449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint vp8_alloc_overlap_lists(VP8D_COMP *pbi)
469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if (pbi->overlaps != NULL)
489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        vpx_free(pbi->overlaps);
509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        pbi->overlaps = NULL;
519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    pbi->overlaps = vpx_calloc(pbi->common.mb_rows * pbi->common.mb_cols,
549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                               sizeof(MB_OVERLAP));
559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if (pbi->overlaps == NULL)
579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        return -1;
589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    return 0;
609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid vp8_de_alloc_overlap_lists(VP8D_COMP *pbi)
639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    vpx_free(pbi->overlaps);
659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    pbi->overlaps = NULL;
669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Inserts a new overlap area value to the list of overlaps of a block */
699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void assign_overlap(OVERLAP_NODE* overlaps,
709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                           union b_mode_info *bmi,
719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                           int overlap)
729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int i;
749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if (overlap <= 0)
759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        return;
769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* Find and assign to the next empty overlap node in the list of overlaps.
779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     * Empty is defined as bmi == NULL */
789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    for (i = 0; i < MAX_OVERLAPS; i++)
799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        if (overlaps[i].bmi == NULL)
819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        {
829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            overlaps[i].bmi = bmi;
839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            overlaps[i].overlap = overlap;
849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            break;
859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        }
869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Calculates the overlap area between two 4x4 squares, where the first
909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * square has its upper-left corner at (b1_row, b1_col) and the second
919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * square has its upper-left corner at (b2_row, b2_col). Doesn't
929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * properly handle squares which do not overlap.
939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */
949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int block_overlap(int b1_row, int b1_col, int b2_row, int b2_col)
959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    const int int_top = MAX(b1_row, b2_row); // top
979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    const int int_left = MAX(b1_col, b2_col); // left
989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* Since each block is 4x4 pixels, adding 4 (Q3) to the left/top edge
999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     * gives us the right/bottom edge.
1009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     */
1019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    const int int_right = MIN(b1_col + (4<<3), b2_col + (4<<3)); // right
1029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    const int int_bottom = MIN(b1_row + (4<<3), b2_row + (4<<3)); // bottom
1039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    return (int_bottom - int_top) * (int_right - int_left);
1049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
1059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Calculates the overlap area for all blocks in a macroblock at position
1079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * (mb_row, mb_col) in macroblocks, which are being overlapped by a given
1089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * overlapping block at position (new_row, new_col) (in pixels, Q3). The
1099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * first block being overlapped in the macroblock has position (first_blk_row,
1109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * first_blk_col) in blocks relative the upper-left corner of the image.
1119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */
1129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void calculate_overlaps_mb(B_OVERLAP *b_overlaps, union b_mode_info *bmi,
1139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                  int new_row, int new_col,
1149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                  int mb_row, int mb_col,
1159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                  int first_blk_row, int first_blk_col)
1169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
1179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* Find the blocks within this MB (defined by mb_row, mb_col) which are
1189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     * overlapped by bmi and calculate and assign overlap for each of those
1199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     * blocks. */
1209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* Block coordinates relative the upper-left block */
1229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    const int rel_ol_blk_row = first_blk_row - mb_row * 4;
1239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    const int rel_ol_blk_col = first_blk_col - mb_col * 4;
1249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* If the block partly overlaps any previous MB, these coordinates
1259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     * can be < 0. We don't want to access blocks in previous MBs.
1269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     */
1279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    const int blk_idx = MAX(rel_ol_blk_row,0) * 4 + MAX(rel_ol_blk_col,0);
1289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* Upper left overlapping block */
1299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    B_OVERLAP *b_ol_ul = &(b_overlaps[blk_idx]);
1309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* Calculate and assign overlaps for all blocks in this MB
1329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     * which the motion compensated block overlaps
1339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     */
1349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* Avoid calculating overlaps for blocks in later MBs */
1359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int end_row = MIN(4 + mb_row * 4 - first_blk_row, 2);
1369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int end_col = MIN(4 + mb_col * 4 - first_blk_col, 2);
1379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int row, col;
1389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* Check if new_row and new_col are evenly divisible by 4 (Q3),
1409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     * and if so we shouldn't check neighboring blocks
1419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     */
1429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if (new_row >= 0 && (new_row & 0x1F) == 0)
1439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        end_row = 1;
1449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if (new_col >= 0 && (new_col & 0x1F) == 0)
1459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        end_col = 1;
1469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* Check if the overlapping block partly overlaps a previous MB
1489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     * and if so, we're overlapping fewer blocks in this MB.
1499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     */
1509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if (new_row < (mb_row*16)<<3)
1519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        end_row = 1;
1529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if (new_col < (mb_col*16)<<3)
1539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        end_col = 1;
1549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    for (row = 0; row < end_row; ++row)
1569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
1579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        for (col = 0; col < end_col; ++col)
1589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        {
1599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            /* input in Q3, result in Q6 */
1609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            const int overlap = block_overlap(new_row, new_col,
1619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                                  (((first_blk_row + row) *
1629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                                      4) << 3),
1639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                                  (((first_blk_col + col) *
1649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                                      4) << 3));
1659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            assign_overlap(b_ol_ul[row * 4 + col].overlaps, bmi, overlap);
1669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        }
1679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
1689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
1699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid vp8_calculate_overlaps(MB_OVERLAP *overlap_ul,
1719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                            int mb_rows, int mb_cols,
1729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                            union b_mode_info *bmi,
1739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                            int b_row, int b_col)
1749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
1759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    MB_OVERLAP *mb_overlap;
1769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int row, col, rel_row, rel_col;
1779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int new_row, new_col;
1789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int end_row, end_col;
1799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int overlap_b_row, overlap_b_col;
1809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int overlap_mb_row, overlap_mb_col;
1819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* mb subpixel position */
1839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    row = (4 * b_row) << 3; /* Q3 */
1849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    col = (4 * b_col) << 3; /* Q3 */
1859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* reverse compensate for motion */
1879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    new_row = row - bmi->mv.as_mv.row;
1889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    new_col = col - bmi->mv.as_mv.col;
1899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if (new_row >= ((16*mb_rows) << 3) || new_col >= ((16*mb_cols) << 3))
1919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
1929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        /* the new block ended up outside the frame */
1939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        return;
1949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
1959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if (new_row <= (-4 << 3) || new_col <= (-4 << 3))
1979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
1989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        /* outside the frame */
1999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        return;
2009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
2019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* overlapping block's position in blocks */
2029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    overlap_b_row = FLOOR(new_row / 4, 3) >> 3;
2039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    overlap_b_col = FLOOR(new_col / 4, 3) >> 3;
2049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* overlapping block's MB position in MBs
2069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     * operations are done in Q3
2079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     */
2089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    overlap_mb_row = FLOOR((overlap_b_row << 3) / 4, 3) >> 3;
2099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    overlap_mb_col = FLOOR((overlap_b_col << 3) / 4, 3) >> 3;
2109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    end_row = MIN(mb_rows - overlap_mb_row, 2);
2129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    end_col = MIN(mb_cols - overlap_mb_col, 2);
2139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* Don't calculate overlap for MBs we don't overlap */
2159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* Check if the new block row starts at the last block row of the MB */
2169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if (abs(new_row - ((16*overlap_mb_row) << 3)) < ((3*4) << 3))
2179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        end_row = 1;
2189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* Check if the new block col starts at the last block col of the MB */
2199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if (abs(new_col - ((16*overlap_mb_col) << 3)) < ((3*4) << 3))
2209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        end_col = 1;
2219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* find the MB(s) this block is overlapping */
2239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    for (rel_row = 0; rel_row < end_row; ++rel_row)
2249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
2259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        for (rel_col = 0; rel_col < end_col; ++rel_col)
2269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        {
2279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            if (overlap_mb_row + rel_row < 0 ||
2289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                overlap_mb_col + rel_col < 0)
2299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                continue;
2309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            mb_overlap = overlap_ul + (overlap_mb_row + rel_row) * mb_cols +
2319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                 overlap_mb_col + rel_col;
2329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            calculate_overlaps_mb(mb_overlap->overlaps, bmi,
2349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                  new_row, new_col,
2359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                  overlap_mb_row + rel_row,
2369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                  overlap_mb_col + rel_col,
2379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                  overlap_b_row + rel_row,
2389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                  overlap_b_col + rel_col);
2399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        }
2409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
2419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
2429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Estimates a motion vector given the overlapping blocks' motion vectors.
2449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Filters out all overlapping blocks which do not refer to the correct
2459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * reference frame type.
2469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */
2479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void estimate_mv(const OVERLAP_NODE *overlaps, union b_mode_info *bmi)
2489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
2499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int i;
2509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int overlap_sum = 0;
2519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int row_acc = 0;
2529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int col_acc = 0;
2539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    bmi->mv.as_int = 0;
2559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    for (i=0; i < MAX_OVERLAPS; ++i)
2569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
2579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        if (overlaps[i].bmi == NULL)
2589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            break;
2599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        col_acc += overlaps[i].overlap * overlaps[i].bmi->mv.as_mv.col;
2609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        row_acc += overlaps[i].overlap * overlaps[i].bmi->mv.as_mv.row;
2619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        overlap_sum += overlaps[i].overlap;
2629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
2639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if (overlap_sum > 0)
2649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
2659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        /* Q9 / Q6 = Q3 */
2669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        bmi->mv.as_mv.col = col_acc / overlap_sum;
2679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        bmi->mv.as_mv.row = row_acc / overlap_sum;
2689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
2699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    else
2709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
2719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        bmi->mv.as_mv.col = 0;
2729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        bmi->mv.as_mv.row = 0;
2739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
2749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
2759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Estimates all motion vectors for a macroblock given the lists of
2779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * overlaps for each block. Decides whether or not the MVs must be clamped.
2789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */
2799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void estimate_mb_mvs(const B_OVERLAP *block_overlaps,
2809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                            MODE_INFO *mi,
2819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                            int mb_to_left_edge,
2829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                            int mb_to_right_edge,
2839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                            int mb_to_top_edge,
2849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                            int mb_to_bottom_edge)
2859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
2869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int row, col;
2879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int non_zero_count = 0;
2889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    MV * const filtered_mv = &(mi->mbmi.mv.as_mv);
2899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    union b_mode_info * const bmi = mi->bmi;
2909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    filtered_mv->col = 0;
2919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    filtered_mv->row = 0;
2929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    mi->mbmi.need_to_clamp_mvs = 0;
2939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    for (row = 0; row < 4; ++row)
2949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
2959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        int this_b_to_top_edge = mb_to_top_edge + ((row*4)<<3);
2969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        int this_b_to_bottom_edge = mb_to_bottom_edge - ((row*4)<<3);
2979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        for (col = 0; col < 4; ++col)
2989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        {
2999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            int i = row * 4 + col;
3009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            int this_b_to_left_edge = mb_to_left_edge + ((col*4)<<3);
3019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            int this_b_to_right_edge = mb_to_right_edge - ((col*4)<<3);
3029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            /* Estimate vectors for all blocks which are overlapped by this */
3039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            /* type. Interpolate/extrapolate the rest of the block's MVs */
3049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            estimate_mv(block_overlaps[i].overlaps, &(bmi[i]));
3059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            mi->mbmi.need_to_clamp_mvs |= vp8_check_mv_bounds(
3069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                                         &bmi[i].mv,
3079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                                         this_b_to_left_edge,
3089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                                         this_b_to_right_edge,
3099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                                         this_b_to_top_edge,
3109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                                         this_b_to_bottom_edge);
3119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            if (bmi[i].mv.as_int != 0)
3129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            {
3139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                ++non_zero_count;
3149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                filtered_mv->col += bmi[i].mv.as_mv.col;
3159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                filtered_mv->row += bmi[i].mv.as_mv.row;
3169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            }
3179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        }
3189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
3199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if (non_zero_count > 0)
3209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
3219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        filtered_mv->col /= non_zero_count;
3229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        filtered_mv->row /= non_zero_count;
3239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
3249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
3259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void calc_prev_mb_overlaps(MB_OVERLAP *overlaps, MODE_INFO *prev_mi,
3279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                    int mb_row, int mb_col,
3289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                    int mb_rows, int mb_cols)
3299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
3309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int sub_row;
3319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int sub_col;
3329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    for (sub_row = 0; sub_row < 4; ++sub_row)
3339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
3349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        for (sub_col = 0; sub_col < 4; ++sub_col)
3359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        {
3369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            vp8_calculate_overlaps(
3379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                overlaps, mb_rows, mb_cols,
3389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                &(prev_mi->bmi[sub_row * 4 + sub_col]),
3399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                4 * mb_row + sub_row,
3409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                4 * mb_col + sub_col);
3419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        }
3429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
3439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
3449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Estimate all missing motion vectors. This function does the same as the one
3469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * above, but has different input arguments. */
3479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void estimate_missing_mvs(MB_OVERLAP *overlaps,
3489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                 MODE_INFO *mi, MODE_INFO *prev_mi,
3499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                 int mb_rows, int mb_cols,
3509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                 unsigned int first_corrupt)
3519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
3529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int mb_row, mb_col;
3539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    vpx_memset(overlaps, 0, sizeof(MB_OVERLAP) * mb_rows * mb_cols);
3549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* First calculate the overlaps for all blocks */
3559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    for (mb_row = 0; mb_row < mb_rows; ++mb_row)
3569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
3579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        for (mb_col = 0; mb_col < mb_cols; ++mb_col)
3589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        {
3599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            /* We're only able to use blocks referring to the last frame
3609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall             * when extrapolating new vectors.
3619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall             */
3629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            if (prev_mi->mbmi.ref_frame == LAST_FRAME)
3639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            {
3649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                calc_prev_mb_overlaps(overlaps, prev_mi,
3659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                      mb_row, mb_col,
3669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                      mb_rows, mb_cols);
3679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            }
3689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            ++prev_mi;
3699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        }
3709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        ++prev_mi;
3719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
3729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    mb_row = first_corrupt / mb_cols;
3749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    mb_col = first_corrupt - mb_row * mb_cols;
3759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    mi += mb_row*(mb_cols + 1) + mb_col;
3769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* Go through all macroblocks in the current image with missing MVs
3779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     * and calculate new MVs using the overlaps.
3789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     */
3799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    for (; mb_row < mb_rows; ++mb_row)
3809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
3819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        int mb_to_top_edge = -((mb_row * 16)) << 3;
3829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        int mb_to_bottom_edge = ((mb_rows - 1 - mb_row) * 16) << 3;
3839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        for (; mb_col < mb_cols; ++mb_col)
3849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        {
3859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            int mb_to_left_edge = -((mb_col * 16) << 3);
3869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            int mb_to_right_edge = ((mb_cols - 1 - mb_col) * 16) << 3;
3879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            const B_OVERLAP *block_overlaps =
3889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                    overlaps[mb_row*mb_cols + mb_col].overlaps;
3899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            mi->mbmi.ref_frame = LAST_FRAME;
3909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            mi->mbmi.mode = SPLITMV;
3919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            mi->mbmi.uv_mode = DC_PRED;
3929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            mi->mbmi.partitioning = 3;
3939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            mi->mbmi.segment_id = 0;
3949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            estimate_mb_mvs(block_overlaps,
3959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                            mi,
3969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                            mb_to_left_edge,
3979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                            mb_to_right_edge,
3989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                            mb_to_top_edge,
3999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                            mb_to_bottom_edge);
4009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            ++mi;
4019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        }
4029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mb_col = 0;
4039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        ++mi;
4049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
4059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
4069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid vp8_estimate_missing_mvs(VP8D_COMP *pbi)
4089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
4099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    VP8_COMMON * const pc = &pbi->common;
4109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    estimate_missing_mvs(pbi->overlaps,
4119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                         pc->mi, pc->prev_mi,
4129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                         pc->mb_rows, pc->mb_cols,
4139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                         pbi->mvs_corrupt_from_mb);
4149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
4159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void assign_neighbor(EC_BLOCK *neighbor, MODE_INFO *mi, int block_idx)
4179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
4189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    assert(mi->mbmi.ref_frame < MAX_REF_FRAMES);
4199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    neighbor->ref_frame = mi->mbmi.ref_frame;
4209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    neighbor->mv = mi->bmi[block_idx].mv.as_mv;
4219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
4229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Finds the neighboring blocks of a macroblocks. In the general case
4249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * 20 blocks are found. If a fewer number of blocks are found due to
4259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * image boundaries, those positions in the EC_BLOCK array are left "empty".
4269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * The neighbors are enumerated with the upper-left neighbor as the first
4279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * element, the second element refers to the neighbor to right of the previous
4289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * neighbor, and so on. The last element refers to the neighbor below the first
4299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * neighbor.
4309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */
4319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void find_neighboring_blocks(MODE_INFO *mi,
4329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                    EC_BLOCK *neighbors,
4339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                    int mb_row, int mb_col,
4349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                    int mb_rows, int mb_cols,
4359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                    int mi_stride)
4369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
4379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int i = 0;
4389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int j;
4399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if (mb_row > 0)
4409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
4419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        /* upper left */
4429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        if (mb_col > 0)
4439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            assign_neighbor(&neighbors[i], mi - mi_stride - 1, 15);
4449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        ++i;
4459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        /* above */
4469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        for (j = 12; j < 16; ++j, ++i)
4479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            assign_neighbor(&neighbors[i], mi - mi_stride, j);
4489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
4499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    else
4509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        i += 5;
4519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if (mb_col < mb_cols - 1)
4529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
4539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        /* upper right */
4549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        if (mb_row > 0)
4559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            assign_neighbor(&neighbors[i], mi - mi_stride + 1, 12);
4569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        ++i;
4579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        /* right */
4589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        for (j = 0; j <= 12; j += 4, ++i)
4599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            assign_neighbor(&neighbors[i], mi + 1, j);
4609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
4619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    else
4629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        i += 5;
4639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if (mb_row < mb_rows - 1)
4649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
4659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        /* lower right */
4669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        if (mb_col < mb_cols - 1)
4679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            assign_neighbor(&neighbors[i], mi + mi_stride + 1, 0);
4689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        ++i;
4699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        /* below */
4709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        for (j = 0; j < 4; ++j, ++i)
4719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            assign_neighbor(&neighbors[i], mi + mi_stride, j);
4729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
4739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    else
4749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        i += 5;
4759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if (mb_col > 0)
4769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
4779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        /* lower left */
4789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        if (mb_row < mb_rows - 1)
4799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            assign_neighbor(&neighbors[i], mi + mi_stride - 1, 4);
4809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        ++i;
4819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        /* left */
4829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        for (j = 3; j < 16; j += 4, ++i)
4839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        {
4849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            assign_neighbor(&neighbors[i], mi - 1, j);
4859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        }
4869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
4879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    else
4889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        i += 5;
4899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    assert(i == 20);
4909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
4919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Interpolates all motion vectors for a macroblock from the neighboring blocks'
4939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * motion vectors.
4949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */
4959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void interpolate_mvs(MACROBLOCKD *mb,
4969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                         EC_BLOCK *neighbors,
4979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                         MV_REFERENCE_FRAME dom_ref_frame)
4989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
4999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int row, col, i;
5009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    MODE_INFO * const mi = mb->mode_info_context;
5019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* Table with the position of the neighboring blocks relative the position
5029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     * of the upper left block of the current MB. Starting with the upper left
5039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     * neighbor and going to the right.
5049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     */
5059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    const EC_POS neigh_pos[NUM_NEIGHBORS] = {
5069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                        {-1,-1}, {-1,0}, {-1,1}, {-1,2}, {-1,3},
5079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                        {-1,4}, {0,4}, {1,4}, {2,4}, {3,4},
5089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                        {4,4}, {4,3}, {4,2}, {4,1}, {4,0},
5099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                        {4,-1}, {3,-1}, {2,-1}, {1,-1}, {0,-1}
5109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                      };
5119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    mi->mbmi.need_to_clamp_mvs = 0;
5129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    for (row = 0; row < 4; ++row)
5139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
5149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        int mb_to_top_edge = mb->mb_to_top_edge + ((row*4)<<3);
5159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        int mb_to_bottom_edge = mb->mb_to_bottom_edge - ((row*4)<<3);
5169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        for (col = 0; col < 4; ++col)
5179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        {
5189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            int mb_to_left_edge = mb->mb_to_left_edge + ((col*4)<<3);
5199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            int mb_to_right_edge = mb->mb_to_right_edge - ((col*4)<<3);
5209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            int w_sum = 0;
5219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            int mv_row_sum = 0;
5229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            int mv_col_sum = 0;
5239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            int_mv * const mv = &(mi->bmi[row*4 + col].mv);
5249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            mv->as_int = 0;
5259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            for (i = 0; i < NUM_NEIGHBORS; ++i)
5269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            {
5279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                /* Calculate the weighted sum of neighboring MVs referring
5289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                 * to the dominant frame type.
5299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                 */
5309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                const int w = weights_q7[abs(row - neigh_pos[i].row)]
5319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                        [abs(col - neigh_pos[i].col)];
5329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                if (neighbors[i].ref_frame != dom_ref_frame)
5339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                    continue;
5349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                w_sum += w;
5359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                /* Q7 * Q3 = Q10 */
5369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                mv_row_sum += w*neighbors[i].mv.row;
5379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                mv_col_sum += w*neighbors[i].mv.col;
5389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            }
5399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            if (w_sum > 0)
5409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            {
5419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                /* Avoid division by zero.
5429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                 * Normalize with the sum of the coefficients
5439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                 * Q3 = Q10 / Q7
5449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                 */
5459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                mv->as_mv.row = mv_row_sum / w_sum;
5469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                mv->as_mv.col = mv_col_sum / w_sum;
5479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                mi->mbmi.need_to_clamp_mvs |= vp8_check_mv_bounds(
5489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                                            mv,
5499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                                            mb_to_left_edge,
5509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                                            mb_to_right_edge,
5519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                                            mb_to_top_edge,
5529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                                            mb_to_bottom_edge);
5539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            }
5549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        }
5559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
5569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
5579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid vp8_interpolate_motion(MACROBLOCKD *mb,
5599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                        int mb_row, int mb_col,
5609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                        int mb_rows, int mb_cols,
5619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                        int mi_stride)
5629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
5639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* Find relevant neighboring blocks */
5649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    EC_BLOCK neighbors[NUM_NEIGHBORS];
5659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int i;
5669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* Initialize the array. MAX_REF_FRAMES is interpreted as "doesn't exist" */
5679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    for (i = 0; i < NUM_NEIGHBORS; ++i)
5689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
5699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        neighbors[i].ref_frame = MAX_REF_FRAMES;
5709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        neighbors[i].mv.row = neighbors[i].mv.col = 0;
5719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
5729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    find_neighboring_blocks(mb->mode_info_context,
5739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                neighbors,
5749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                mb_row, mb_col,
5759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                mb_rows, mb_cols,
5769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                mb->mode_info_stride);
5779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* Interpolate MVs for the missing blocks from the surrounding
5789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     * blocks which refer to the last frame. */
5799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    interpolate_mvs(mb, neighbors, LAST_FRAME);
5809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    mb->mode_info_context->mbmi.ref_frame = LAST_FRAME;
5829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    mb->mode_info_context->mbmi.mode = SPLITMV;
5839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    mb->mode_info_context->mbmi.uv_mode = DC_PRED;
5849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    mb->mode_info_context->mbmi.partitioning = 3;
5859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    mb->mode_info_context->mbmi.segment_id = 0;
5869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
5879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid vp8_conceal_corrupt_mb(MACROBLOCKD *xd)
5899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
5909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* This macroblock has corrupt residual, use the motion compensated
5919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall       image (predictor) for concealment */
5929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* The build predictor functions now output directly into the dst buffer,
5949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     * so the copies are no longer necessary */
5959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
5979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall