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 VP9_ENCODER_VP9_MCOMP_H_
13 #define VP9_ENCODER_VP9_MCOMP_H_
14 
15 #include "vp9/encoder/vp9_block.h"
16 #include "vp9/encoder/vp9_variance.h"
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 // The maximum number of steps in a step search given the largest
23 // allowed initial step
24 #define MAX_MVSEARCH_STEPS 11
25 // Max full pel mv specified in the unit of full pixel
26 // Enable the use of motion vector in range [-1023, 1023].
27 #define MAX_FULL_PEL_VAL ((1 << (MAX_MVSEARCH_STEPS - 1)) - 1)
28 // Maximum size of the first step in full pel units
29 #define MAX_FIRST_STEP (1 << (MAX_MVSEARCH_STEPS-1))
30 // Allowed motion vector pixel distance outside image border
31 // for Block_16x16
32 #define BORDER_MV_PIXELS_B16 (16 + VP9_INTERP_EXTEND)
33 
34 
35 void vp9_set_mv_search_range(MACROBLOCK *x, const MV *mv);
36 int vp9_mv_bit_cost(const MV *mv, const MV *ref,
37                     const int *mvjcost, int *mvcost[2], int weight);
38 
39 // Utility to compute variance + MV rate cost for a given MV
40 int vp9_get_mvpred_var(const MACROBLOCK *x,
41                        const MV *best_mv, const MV *center_mv,
42                        const vp9_variance_fn_ptr_t *vfp,
43                        int use_mvcost);
44 int vp9_get_mvpred_av_var(const MACROBLOCK *x,
45                           const MV *best_mv, const MV *center_mv,
46                           const uint8_t *second_pred,
47                           const vp9_variance_fn_ptr_t *vfp,
48                           int use_mvcost);
49 void vp9_init_dsmotion_compensation(MACROBLOCK *x, int stride);
50 void vp9_init3smotion_compensation(MACROBLOCK *x,  int stride);
51 
52 struct VP9_COMP;
53 int vp9_init_search_range(struct VP9_COMP *cpi, int size);
54 
55 // Runs sequence of diamond searches in smaller steps for RD
56 int vp9_full_pixel_diamond(const struct VP9_COMP *cpi, MACROBLOCK *x,
57                            MV *mvp_full, int step_param,
58                            int sadpb, int further_steps, int do_refine,
59                            const vp9_variance_fn_ptr_t *fn_ptr,
60                            const MV *ref_mv, MV *dst_mv);
61 
62 typedef int (integer_mv_pattern_search_fn) (
63     const MACROBLOCK *x,
64     MV *ref_mv,
65     int search_param,
66     int error_per_bit,
67     int do_init_search,
68     const vp9_variance_fn_ptr_t *vf,
69     int use_mvcost,
70     const MV *center_mv,
71     MV *best_mv);
72 
73 integer_mv_pattern_search_fn vp9_hex_search;
74 integer_mv_pattern_search_fn vp9_bigdia_search;
75 integer_mv_pattern_search_fn vp9_square_search;
76 integer_mv_pattern_search_fn vp9_fast_hex_search;
77 integer_mv_pattern_search_fn vp9_fast_dia_search;
78 
79 typedef int (fractional_mv_step_fp) (
80     const MACROBLOCK *x,
81     MV *bestmv, const MV *ref_mv,
82     int allow_hp,
83     int error_per_bit,
84     const vp9_variance_fn_ptr_t *vfp,
85     int forced_stop,  // 0 - full, 1 - qtr only, 2 - half only
86     int iters_per_step,
87     int *mvjcost,
88     int *mvcost[2],
89     int *distortion,
90     unsigned int *sse);
91 
92 extern fractional_mv_step_fp vp9_find_best_sub_pixel_tree;
93 
94 typedef int (fractional_mv_step_comp_fp) (
95     const MACROBLOCK *x,
96     MV *bestmv, const MV *ref_mv,
97     int allow_hp,
98     int error_per_bit,
99     const vp9_variance_fn_ptr_t *vfp,
100     int forced_stop,  // 0 - full, 1 - qtr only, 2 - half only
101     int iters_per_step,
102     int *mvjcost, int *mvcost[2],
103     int *distortion, unsigned int *sse1,
104     const uint8_t *second_pred,
105     int w, int h);
106 
107 extern fractional_mv_step_comp_fp vp9_find_best_sub_pixel_comp_tree;
108 
109 typedef int (*vp9_full_search_fn_t)(const MACROBLOCK *x,
110                                     const MV *ref_mv, int sad_per_bit,
111                                     int distance,
112                                     const vp9_variance_fn_ptr_t *fn_ptr,
113                                     int *mvjcost, int *mvcost[2],
114                                     const MV *center_mv, MV *best_mv);
115 
116 typedef int (*vp9_refining_search_fn_t)(const MACROBLOCK *x,
117                                         MV *ref_mv, int sad_per_bit,
118                                         int distance,
119                                         const vp9_variance_fn_ptr_t *fn_ptr,
120                                         int *mvjcost, int *mvcost[2],
121                                         const MV *center_mv);
122 
123 typedef int (*vp9_diamond_search_fn_t)(const MACROBLOCK *x,
124                                        MV *ref_mv, MV *best_mv,
125                                        int search_param, int sad_per_bit,
126                                        int *num00,
127                                        const vp9_variance_fn_ptr_t *fn_ptr,
128                                        int *mvjcost, int *mvcost[2],
129                                        const MV *center_mv);
130 
131 int vp9_refining_search_8p_c(const MACROBLOCK *x,
132                              MV *ref_mv, int error_per_bit,
133                              int search_range,
134                              const vp9_variance_fn_ptr_t *fn_ptr,
135                              int *mvjcost, int *mvcost[2],
136                              const MV *center_mv, const uint8_t *second_pred,
137                              int w, int h);
138 #ifdef __cplusplus
139 }  // extern "C"
140 #endif
141 
142 #endif  // VP9_ENCODER_VP9_MCOMP_H_
143