1 /*
2  * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3  *
4  * This source code is subject to the terms of the BSD 2 Clause License and
5  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6  * was not distributed with this source code in the LICENSE file, you can
7  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8  * Media Patent License 1.0 was not distributed with this source code in the
9  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10  */
11 
12 #ifndef AOM_AV1_ENCODER_GLOBAL_MOTION_H_
13 #define AOM_AV1_ENCODER_GLOBAL_MOTION_H_
14 
15 #include "aom/aom_integer.h"
16 #include "aom_scale/yv12config.h"
17 #include "av1/common/mv.h"
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 #define RANSAC_NUM_MOTIONS 1
24 
25 typedef enum {
26   GLOBAL_MOTION_FEATURE_BASED,
27   GLOBAL_MOTION_DISFLOW_BASED,
28 } GlobalMotionEstimationType;
29 
30 void av1_convert_model_to_params(const double *params,
31                                  WarpedMotionParams *model);
32 
33 int av1_is_enough_erroradvantage(double best_erroradvantage, int params_cost,
34                                  int erroradv_type);
35 
36 // Returns the av1_warp_error between "dst" and the result of applying the
37 // motion params that result from fine-tuning "wm" to "ref". Note that "wm" is
38 // modified in place.
39 int64_t av1_refine_integerized_param(WarpedMotionParams *wm,
40                                      TransformationType wmtype, int use_hbd,
41                                      int bd, uint8_t *ref, int r_width,
42                                      int r_height, int r_stride, uint8_t *dst,
43                                      int d_width, int d_height, int d_stride,
44                                      int n_refinements,
45                                      int64_t best_frame_error);
46 
47 /*
48   Computes "num_motions" candidate global motion parameters between two frames.
49   The array "params_by_motion" should be length 8 * "num_motions". The ordering
50   of each set of parameters is best described  by the homography:
51 
52         [x'     (m2 m3 m0   [x
53     z .  y'  =   m4 m5 m1 *  y
54          1]      m6 m7 1)    1]
55 
56   where m{i} represents the ith value in any given set of parameters.
57 
58   "num_inliers" should be length "num_motions", and will be populated with the
59   number of inlier feature points for each motion. Params for which the
60   num_inliers entry is 0 should be ignored by the caller.
61 */
62 int av1_compute_global_motion(TransformationType type, YV12_BUFFER_CONFIG *frm,
63                               YV12_BUFFER_CONFIG *ref, int bit_depth,
64                               GlobalMotionEstimationType gm_estimation_type,
65                               int *num_inliers_by_motion,
66                               double *params_by_motion, int num_motions);
67 #ifdef __cplusplus
68 }  // extern "C"
69 #endif
70 #endif  // AOM_AV1_ENCODER_GLOBAL_MOTION_H_
71