MODE_INFO size reduction
[profile/ivi/libvpx.git] / vp8 / common / findnearmv.h
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, 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)
37 static 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
50 static 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 }
62 static 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
74 void 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
84 vp8_prob *vp8_mv_ref_probs(
85     vp8_prob p[VP8_MVREFS-1], const int near_mv_ref_ct[4]
86 );
87
88 extern const unsigned char vp8_mbsplit_offset[4][16];
89
90
91 static 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
106 static 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 }
120 static 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         b += 4;
127     }
128
129     return (cur_mb->bmi + b - 1)->as_mode;
130 }
131
132 static B_PREDICTION_MODE above_block_mode(const MODE_INFO *cur_mb, int b, int mi_stride)
133 {
134     if (!(b >> 2))
135     {
136         /* On top edge, get from MB above us */
137         cur_mb -= mi_stride;
138         b += 16;
139     }
140
141     return (cur_mb->bmi + b - 4)->as_mode;
142 }
143
144 #endif