PageRenderTime 28ms CodeModel.GetById 16ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/media/libvpx/vp8/common/findnearmv.h

http://github.com/zpao/v8monkey
C Header | 173 lines | 135 code | 25 blank | 13 comment | 18 complexity | 0ec3f6f64953c8bef671d02ec8831eee MD5 | raw file
  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
 21static void mv_bias(int refmb_ref_frame_sign_bias, int refframe, int_mv *mvp, const int *ref_frame_sign_bias)
 22{
 23    MV xmv;
 24    xmv = mvp->as_mv;
 25
 26    if (refmb_ref_frame_sign_bias != ref_frame_sign_bias[refframe])
 27    {
 28        xmv.row *= -1;
 29        xmv.col *= -1;
 30    }
 31
 32    mvp->as_mv = xmv;
 33}
 34
 35#define LEFT_TOP_MARGIN (16 << 3)
 36#define RIGHT_BOTTOM_MARGIN (16 << 3)
 37static void vp8_clamp_mv2(int_mv *mv, const MACROBLOCKD *xd)
 38{
 39    if (mv->as_mv.col < (xd->mb_to_left_edge - LEFT_TOP_MARGIN))
 40        mv->as_mv.col = xd->mb_to_left_edge - LEFT_TOP_MARGIN;
 41    else if (mv->as_mv.col > xd->mb_to_right_edge + RIGHT_BOTTOM_MARGIN)
 42        mv->as_mv.col = xd->mb_to_right_edge + RIGHT_BOTTOM_MARGIN;
 43
 44    if (mv->as_mv.row < (xd->mb_to_top_edge - LEFT_TOP_MARGIN))
 45        mv->as_mv.row = xd->mb_to_top_edge - LEFT_TOP_MARGIN;
 46    else if (mv->as_mv.row > xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN)
 47        mv->as_mv.row = xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN;
 48}
 49
 50static void vp8_clamp_mv(int_mv *mv, int mb_to_left_edge, int mb_to_right_edge,
 51                         int mb_to_top_edge, int mb_to_bottom_edge)
 52{
 53    mv->as_mv.col = (mv->as_mv.col < mb_to_left_edge) ?
 54        mb_to_left_edge : mv->as_mv.col;
 55    mv->as_mv.col = (mv->as_mv.col > mb_to_right_edge) ?
 56        mb_to_right_edge : mv->as_mv.col;
 57    mv->as_mv.row = (mv->as_mv.row < mb_to_top_edge) ?
 58        mb_to_top_edge : mv->as_mv.row;
 59    mv->as_mv.row = (mv->as_mv.row > mb_to_bottom_edge) ?
 60        mb_to_bottom_edge : mv->as_mv.row;
 61}
 62static unsigned int vp8_check_mv_bounds(int_mv *mv, int mb_to_left_edge,
 63                                int mb_to_right_edge, int mb_to_top_edge,
 64                                int mb_to_bottom_edge)
 65{
 66    unsigned int need_to_clamp;
 67    need_to_clamp = (mv->as_mv.col < mb_to_left_edge) ? 1 : 0;
 68    need_to_clamp |= (mv->as_mv.col > mb_to_right_edge) ? 1 : 0;
 69    need_to_clamp |= (mv->as_mv.row < mb_to_top_edge) ? 1 : 0;
 70    need_to_clamp |= (mv->as_mv.row > mb_to_bottom_edge) ? 1 : 0;
 71    return need_to_clamp;
 72}
 73
 74void vp8_find_near_mvs
 75(
 76    MACROBLOCKD *xd,
 77    const MODE_INFO *here,
 78    int_mv *nearest, int_mv *nearby, int_mv *best,
 79    int near_mv_ref_cts[4],
 80    int refframe,
 81    int *ref_frame_sign_bias
 82);
 83
 84vp8_prob *vp8_mv_ref_probs(
 85    vp8_prob p[VP8_MVREFS-1], const int near_mv_ref_ct[4]
 86);
 87
 88extern const unsigned char vp8_mbsplit_offset[4][16];
 89
 90
 91static int left_block_mv(const MODE_INFO *cur_mb, int b)
 92{
 93    if (!(b & 3))
 94    {
 95        /* On L edge, get from MB to left of us */
 96        --cur_mb;
 97
 98        if(cur_mb->mbmi.mode != SPLITMV)
 99            return cur_mb->mbmi.mv.as_int;
100        b += 4;
101    }
102
103    return (cur_mb->bmi + b - 1)->mv.as_int;
104}
105
106static int above_block_mv(const MODE_INFO *cur_mb, int b, int mi_stride)
107{
108    if (!(b >> 2))
109    {
110        /* On top edge, get from MB above us */
111        cur_mb -= mi_stride;
112
113        if(cur_mb->mbmi.mode != SPLITMV)
114            return cur_mb->mbmi.mv.as_int;
115        b += 16;
116    }
117
118    return (cur_mb->bmi + b - 4)->mv.as_int;
119}
120static B_PREDICTION_MODE left_block_mode(const MODE_INFO *cur_mb, int b)
121{
122    if (!(b & 3))
123    {
124        /* On L edge, get from MB to left of us */
125        --cur_mb;
126        switch (cur_mb->mbmi.mode)
127        {
128            case B_PRED:
129              return (cur_mb->bmi + b + 3)->as_mode;
130            case DC_PRED:
131                return B_DC_PRED;
132            case V_PRED:
133                return B_VE_PRED;
134            case H_PRED:
135                return B_HE_PRED;
136            case TM_PRED:
137                return B_TM_PRED;
138            default:
139                return B_DC_PRED;
140        }
141    }
142
143    return (cur_mb->bmi + b - 1)->as_mode;
144}
145
146static B_PREDICTION_MODE above_block_mode(const MODE_INFO *cur_mb, int b, int mi_stride)
147{
148    if (!(b >> 2))
149    {
150        /* On top edge, get from MB above us */
151        cur_mb -= mi_stride;
152
153        switch (cur_mb->mbmi.mode)
154        {
155            case B_PRED:
156              return (cur_mb->bmi + b + 12)->as_mode;
157            case DC_PRED:
158                return B_DC_PRED;
159            case V_PRED:
160                return B_VE_PRED;
161            case H_PRED:
162                return B_HE_PRED;
163            case TM_PRED:
164                return B_TM_PRED;
165            default:
166                return B_DC_PRED;
167        }
168    }
169
170    return (cur_mb->bmi + b - 4)->as_mode;
171}
172
173#endif