Home | History | Annotate | Download | only in common
      1 /*
      2  *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
      3  *
      4  *  Use of this source code is governed by a BSD-style license
      5  *  that can be found in the LICENSE file in the root of the source
      6  *  tree. An additional intellectual property rights grant can be found
      7  *  in the file PATENTS.  All contributing project authors may
      8  *  be found in the AUTHORS file in the root of the source tree.
      9  */
     10 
     11 
     12 #ifndef __INC_FINDNEARMV_H
     13 #define __INC_FINDNEARMV_H
     14 
     15 #include "mv.h"
     16 #include "blockd.h"
     17 #include "modecont.h"
     18 #include "treecoder.h"
     19 
     20 
     21 static void mv_bias(int refmb_ref_frame_sign_bias, int refframe, int_mv *mvp,
     22                     const int *ref_frame_sign_bias)
     23 {
     24     if (refmb_ref_frame_sign_bias != ref_frame_sign_bias[refframe])
     25     {
     26         mvp->as_mv.row *= -1;
     27         mvp->as_mv.col *= -1;
     28     }
     29 }
     30 
     31 #define LEFT_TOP_MARGIN (16 << 3)
     32 #define RIGHT_BOTTOM_MARGIN (16 << 3)
     33 static void vp8_clamp_mv2(int_mv *mv, const MACROBLOCKD *xd)
     34 {
     35     if (mv->as_mv.col < (xd->mb_to_left_edge - LEFT_TOP_MARGIN))
     36         mv->as_mv.col = xd->mb_to_left_edge - LEFT_TOP_MARGIN;
     37     else if (mv->as_mv.col > xd->mb_to_right_edge + RIGHT_BOTTOM_MARGIN)
     38         mv->as_mv.col = xd->mb_to_right_edge + RIGHT_BOTTOM_MARGIN;
     39 
     40     if (mv->as_mv.row < (xd->mb_to_top_edge - LEFT_TOP_MARGIN))
     41         mv->as_mv.row = xd->mb_to_top_edge - LEFT_TOP_MARGIN;
     42     else if (mv->as_mv.row > xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN)
     43         mv->as_mv.row = xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN;
     44 }
     45 
     46 static void vp8_clamp_mv(int_mv *mv, int mb_to_left_edge, int mb_to_right_edge,
     47                          int mb_to_top_edge, int mb_to_bottom_edge)
     48 {
     49     mv->as_mv.col = (mv->as_mv.col < mb_to_left_edge) ?
     50         mb_to_left_edge : mv->as_mv.col;
     51     mv->as_mv.col = (mv->as_mv.col > mb_to_right_edge) ?
     52         mb_to_right_edge : mv->as_mv.col;
     53     mv->as_mv.row = (mv->as_mv.row < mb_to_top_edge) ?
     54         mb_to_top_edge : mv->as_mv.row;
     55     mv->as_mv.row = (mv->as_mv.row > mb_to_bottom_edge) ?
     56         mb_to_bottom_edge : mv->as_mv.row;
     57 }
     58 static unsigned int vp8_check_mv_bounds(int_mv *mv, int mb_to_left_edge,
     59                                 int mb_to_right_edge, int mb_to_top_edge,
     60                                 int mb_to_bottom_edge)
     61 {
     62     unsigned int need_to_clamp;
     63     need_to_clamp = (mv->as_mv.col < mb_to_left_edge);
     64     need_to_clamp |= (mv->as_mv.col > mb_to_right_edge);
     65     need_to_clamp |= (mv->as_mv.row < mb_to_top_edge);
     66     need_to_clamp |= (mv->as_mv.row > mb_to_bottom_edge);
     67     return need_to_clamp;
     68 }
     69 
     70 void vp8_find_near_mvs
     71 (
     72     MACROBLOCKD *xd,
     73     const MODE_INFO *here,
     74     int_mv *nearest, int_mv *nearby, int_mv *best,
     75     int near_mv_ref_cts[4],
     76     int refframe,
     77     int *ref_frame_sign_bias
     78 );
     79 
     80 
     81 int vp8_find_near_mvs_bias
     82 (
     83     MACROBLOCKD *xd,
     84     const MODE_INFO *here,
     85     int_mv mode_mv_sb[2][MB_MODE_COUNT],
     86     int_mv best_mv_sb[2],
     87     int cnt[4],
     88     int refframe,
     89     int *ref_frame_sign_bias
     90 );
     91 
     92 
     93 vp8_prob *vp8_mv_ref_probs(
     94     vp8_prob p[VP8_MVREFS-1], const int near_mv_ref_ct[4]
     95 );
     96 
     97 extern const unsigned char vp8_mbsplit_offset[4][16];
     98 
     99 
    100 static int left_block_mv(const MODE_INFO *cur_mb, int b)
    101 {
    102     if (!(b & 3))
    103     {
    104         /* On L edge, get from MB to left of us */
    105         --cur_mb;
    106 
    107         if(cur_mb->mbmi.mode != SPLITMV)
    108             return cur_mb->mbmi.mv.as_int;
    109         b += 4;
    110     }
    111 
    112     return (cur_mb->bmi + b - 1)->mv.as_int;
    113 }
    114 
    115 static int above_block_mv(const MODE_INFO *cur_mb, int b, int mi_stride)
    116 {
    117     if (!(b >> 2))
    118     {
    119         /* On top edge, get from MB above us */
    120         cur_mb -= mi_stride;
    121 
    122         if(cur_mb->mbmi.mode != SPLITMV)
    123             return cur_mb->mbmi.mv.as_int;
    124         b += 16;
    125     }
    126 
    127     return (cur_mb->bmi + b - 4)->mv.as_int;
    128 }
    129 static B_PREDICTION_MODE left_block_mode(const MODE_INFO *cur_mb, int b)
    130 {
    131     if (!(b & 3))
    132     {
    133         /* On L edge, get from MB to left of us */
    134         --cur_mb;
    135         switch (cur_mb->mbmi.mode)
    136         {
    137             case B_PRED:
    138               return (cur_mb->bmi + b + 3)->as_mode;
    139             case DC_PRED:
    140                 return B_DC_PRED;
    141             case V_PRED:
    142                 return B_VE_PRED;
    143             case H_PRED:
    144                 return B_HE_PRED;
    145             case TM_PRED:
    146                 return B_TM_PRED;
    147             default:
    148                 return B_DC_PRED;
    149         }
    150     }
    151 
    152     return (cur_mb->bmi + b - 1)->as_mode;
    153 }
    154 
    155 static B_PREDICTION_MODE above_block_mode(const MODE_INFO *cur_mb, int b, int mi_stride)
    156 {
    157     if (!(b >> 2))
    158     {
    159         /* On top edge, get from MB above us */
    160         cur_mb -= mi_stride;
    161 
    162         switch (cur_mb->mbmi.mode)
    163         {
    164             case B_PRED:
    165               return (cur_mb->bmi + b + 12)->as_mode;
    166             case DC_PRED:
    167                 return B_DC_PRED;
    168             case V_PRED:
    169                 return B_VE_PRED;
    170             case H_PRED:
    171                 return B_HE_PRED;
    172             case TM_PRED:
    173                 return B_TM_PRED;
    174             default:
    175                 return B_DC_PRED;
    176         }
    177     }
    178 
    179     return (cur_mb->bmi + b - 4)->as_mode;
    180 }
    181 
    182 #endif
    183