blob: b5ff837b71420bdf7a93c9d8a3bf7a05dec4191a [file] [log] [blame]
Yaowu Xuc27fc142016-08-22 16:08:15 -07001/*
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Yaowu Xuc27fc142016-08-22 16:08:15 -07003 *
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07004 * 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.
Yaowu Xuc27fc142016-08-22 16:08:15 -070010 */
11
James Zerne1cbb132018-08-22 14:10:36 -070012#ifndef AOM_AV1_ENCODER_MCOMP_H_
13#define AOM_AV1_ENCODER_MCOMP_H_
Yaowu Xuc27fc142016-08-22 16:08:15 -070014
chiyotsai2ad959b2020-02-12 14:29:32 -080015#include "av1/common/mv.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070016#include "av1/encoder/block.h"
chiyotsaibcf2e782021-03-11 16:52:49 -080017#include "av1/encoder/rd.h"
chiyotsai19a58ee2019-03-18 18:01:05 -070018
Yaowu Xuc27fc142016-08-22 16:08:15 -070019#include "aom_dsp/variance.h"
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
chiyotsai9f664e32020-02-19 14:17:31 -080025struct AV1_COMP;
26struct SPEED_FEATURES;
Yaowu Xuc27fc142016-08-22 16:08:15 -070027
chiyotsai9f664e32020-02-19 14:17:31 -080028// =============================================================================
29// Cost functions
30// =============================================================================
chiyotsaic95e3642020-04-10 13:17:06 -070031
32enum {
33 MV_COST_ENTROPY, // Use the entropy rate of the mv as the cost
34 MV_COST_L1_LOWRES, // Use the l1 norm of the mv as the cost (<480p)
35 MV_COST_L1_MIDRES, // Use the l1 norm of the mv as the cost (>=480p)
36 MV_COST_L1_HDRES, // Use the l1 norm of the mv as the cost (>=720p)
37 MV_COST_NONE // Use 0 as as cost irrespective of the current mv
38} UENUM1BYTE(MV_COST_TYPE);
39
chiyotsai9f664e32020-02-19 14:17:31 -080040typedef struct {
Cheng Chenbb983ba2020-04-21 12:17:53 -070041 // The reference mv used to compute the mv cost
chiyotsai9f664e32020-02-19 14:17:31 -080042 const MV *ref_mv;
chiyotsai2e42a662020-02-26 17:39:03 -080043 FULLPEL_MV full_ref_mv;
chiyotsaic95e3642020-04-10 13:17:06 -070044 MV_COST_TYPE mv_cost_type;
chiyotsai9f664e32020-02-19 14:17:31 -080045 const int *mvjcost;
46 const int *mvcost[2];
47 int error_per_bit;
Cheng Chenbb983ba2020-04-21 12:17:53 -070048 // A multiplier used to convert rate to sad cost
chiyotsai2e42a662020-02-26 17:39:03 -080049 int sad_per_bit;
chiyotsai9f664e32020-02-19 14:17:31 -080050} MV_COST_PARAMS;
Yunqing Wang8e173422017-04-21 09:27:55 -070051
chiyotsaie46cff72020-02-05 15:03:34 -080052int av1_mv_bit_cost(const MV *mv, const MV *ref_mv, const int *mvjcost,
chiyotsai41fd15c2021-03-15 14:12:02 -070053 int *const mvcost[2], int weight);
Yaowu Xuc27fc142016-08-22 16:08:15 -070054
chiyotsaic95e3642020-04-10 13:17:06 -070055int av1_get_mvpred_sse(const MV_COST_PARAMS *mv_cost_params,
56 const FULLPEL_MV best_mv,
57 const aom_variance_fn_ptr_t *vfp,
58 const struct buf_2d *src, const struct buf_2d *pre);
chiyotsai30a5bdf2020-04-06 14:28:59 -070059int av1_get_mvpred_compound_var(const MV_COST_PARAMS *ms_params,
60 const FULLPEL_MV best_mv,
61 const uint8_t *second_pred, const uint8_t *mask,
62 int mask_stride, int invert_mask,
63 const aom_variance_fn_ptr_t *vfp,
64 const struct buf_2d *src,
65 const struct buf_2d *pre);
Yaowu Xuc27fc142016-08-22 16:08:15 -070066
chiyotsai9f664e32020-02-19 14:17:31 -080067// =============================================================================
chiyotsai30a5bdf2020-04-06 14:28:59 -070068// Motion Search
chiyotsai9f664e32020-02-19 14:17:31 -080069// =============================================================================
chiyotsai94f4aca2020-03-20 12:54:47 -070070typedef struct {
71 // The reference buffer
72 const struct buf_2d *ref;
73
74 // The source and predictors/mask used by translational search
75 const struct buf_2d *src;
76 const uint8_t *second_pred;
77 const uint8_t *mask;
78 int mask_stride;
79 int inv_mask;
80
81 // The weighted source and mask used by OBMC
82 const int32_t *wsrc;
83 const int32_t *obmc_mask;
84} MSBuffers;
85
chiyotsai4d1b7d92020-04-07 13:56:22 -070086static INLINE void av1_set_ms_compound_refs(MSBuffers *ms_buffers,
87 const uint8_t *second_pred,
88 const uint8_t *mask,
89 int mask_stride, int invert_mask) {
chiyotsai30a5bdf2020-04-06 14:28:59 -070090 ms_buffers->second_pred = second_pred;
91 ms_buffers->mask = mask;
92 ms_buffers->mask_stride = mask_stride;
93 ms_buffers->inv_mask = invert_mask;
94}
95
96// =============================================================================
97// Fullpixel Motion Search
98// =============================================================================
chiyotsai2e42a662020-02-26 17:39:03 -080099// This struct holds fullpixel motion search parameters that should be constant
100// during the search
101typedef struct {
102 BLOCK_SIZE bsize;
Cheng Chenbb983ba2020-04-21 12:17:53 -0700103 // A function pointer to the simd function for fast computation
chiyotsai2e42a662020-02-26 17:39:03 -0800104 const aom_variance_fn_ptr_t *vfp;
105
chiyotsai94f4aca2020-03-20 12:54:47 -0700106 MSBuffers ms_buffers;
107
chiyotsai7430da62020-07-27 14:06:26 -0700108 // WARNING: search_method should be regarded as a private variable and should
109 // not be modified directly so it is in sync with search_sites. To modify it,
110 // use av1_set_mv_search_method.
chiyotsai2e42a662020-02-26 17:39:03 -0800111 SEARCH_METHODS search_method;
112 const search_site_config *search_sites;
113 FullMvLimits mv_limits;
114
115 int run_mesh_search; // Sets mesh search unless it got pruned by
116 // prune_mesh_search.
117 int prune_mesh_search; // Disables mesh search if the best_mv after a normal
118 // search if close to the start_mv.
Aasaipriya414784b2021-12-24 11:59:30 +0530119 int mesh_search_mv_diff_threshold; // mv diff threshold to enable
120 // prune_mesh_search
chiyotsai2e42a662020-02-26 17:39:03 -0800121 int force_mesh_thresh; // Forces mesh search if the residue variance is
122 // higher than the threshold.
123 const struct MESH_PATTERN *mesh_patterns[2];
124
Cheng Chencf16b022020-04-15 11:19:23 -0700125 // Use maximum search interval of 4 if true. This helps motion search to find
126 // the best motion vector for screen content types.
127 int fine_search_interval;
128
chiyotsai2e42a662020-02-26 17:39:03 -0800129 int is_intra_mode;
130
chiyotsai2e42a662020-02-26 17:39:03 -0800131 int fast_obmc_search;
132
133 // For calculating mv cost
134 MV_COST_PARAMS mv_cost_params;
chiyotsai0a32d3c2020-08-04 13:12:35 -0700135
136 // Stores the function used to compute the sad. This can be different from the
137 // sdf in vfp (e.g. downsampled sad and not sad) to allow speed up.
138 aom_sad_fn_t sdf;
139 aom_sad_multi_d_fn_t sdx4df;
chiyotsai2e42a662020-02-26 17:39:03 -0800140} FULLPEL_MOTION_SEARCH_PARAMS;
141
Nithya V Sb6871a72020-12-25 23:05:48 +0530142void av1_init_obmc_buffer(OBMCBuffer *obmc_buffer);
143
venkat sanampudi14affd02020-07-23 07:41:05 +0530144void av1_make_default_fullpel_ms_params(
145 FULLPEL_MOTION_SEARCH_PARAMS *ms_params, const struct AV1_COMP *cpi,
146 const MACROBLOCK *x, BLOCK_SIZE bsize, const MV *ref_mv,
venkat sanampudi67dc8da2021-12-21 11:57:41 +0530147 const search_site_config search_sites[NUM_DISTINCT_SEARCH_METHODS],
chiyotsai7430da62020-07-27 14:06:26 -0700148 int fine_search_interval);
chiyotsai2e42a662020-02-26 17:39:03 -0800149
chiyotsaibcf2e782021-03-11 16:52:49 -0800150/*! Sets the \ref FULLPEL_MOTION_SEARCH_PARAMS to intra mode. */
151void av1_set_ms_to_intra_mode(FULLPEL_MOTION_SEARCH_PARAMS *ms_params,
152 const IntraBCMVCosts *dv_costs);
153
Nithya V S41b585c2020-07-28 18:01:58 +0530154// Sets up configs for fullpixel DIAMOND / CLAMPED_DIAMOND search method.
155void av1_init_dsmotion_compensation(search_site_config *cfg, int stride,
156 int level);
venkat sanampudi14affd02020-07-23 07:41:05 +0530157// Sets up configs for firstpass motion search.
chiyotsai9f664e32020-02-19 14:17:31 -0800158void av1_init_motion_fpf(search_site_config *cfg, int stride);
Nithya V S41b585c2020-07-28 18:01:58 +0530159// Sets up configs for NSTEP / NSTEP_8PT motion search method.
160void av1_init_motion_compensation_nstep(search_site_config *cfg, int stride,
161 int level);
venkat sanampudi14affd02020-07-23 07:41:05 +0530162// Sets up configs for BIGDIA / FAST_DIAMOND / FAST_BIGDIA
163// motion search method.
Nithya V S41b585c2020-07-28 18:01:58 +0530164void av1_init_motion_compensation_bigdia(search_site_config *cfg, int stride,
165 int level);
venkat sanampudi14affd02020-07-23 07:41:05 +0530166// Sets up configs for HEX or FAST_HEX motion search method.
Nithya V S41b585c2020-07-28 18:01:58 +0530167void av1_init_motion_compensation_hex(search_site_config *cfg, int stride,
168 int level);
venkat sanampudi14affd02020-07-23 07:41:05 +0530169// Sets up configs for SQUARE motion search method.
Nithya V S41b585c2020-07-28 18:01:58 +0530170void av1_init_motion_compensation_square(search_site_config *cfg, int stride,
171 int level);
chiyotsai9f664e32020-02-19 14:17:31 -0800172
chiyotsaifbebe9d2022-05-23 13:31:41 -0700173/*! Function pointer to search site config initialization of different search
174 * method functions. */
175typedef void (*av1_init_search_site_config)(search_site_config *cfg, int stride,
176 int level);
177
178/*! Array of function pointer used to set the motion search config. */
179static const av1_init_search_site_config
180 av1_init_motion_compensation[NUM_DISTINCT_SEARCH_METHODS] = {
181 av1_init_dsmotion_compensation, av1_init_motion_compensation_nstep,
182 av1_init_motion_compensation_nstep, av1_init_dsmotion_compensation,
183 av1_init_motion_compensation_hex, av1_init_motion_compensation_bigdia,
184 av1_init_motion_compensation_square
185 };
186
187// Array to inform which all search methods are having
188// same candidates and different in number of search steps.
189static const SEARCH_METHODS search_method_lookup[NUM_SEARCH_METHODS] = {
190 DIAMOND, // DIAMOND
191 NSTEP, // NSTEP
192 NSTEP_8PT, // NSTEP_8PT
193 CLAMPED_DIAMOND, // CLAMPED_DIAMOND
194 HEX, // HEX
195 BIGDIA, // BIGDIA
196 SQUARE, // SQUARE
197 HEX, // FAST_HEX
198 BIGDIA, // FAST_DIAMOND
Neeraj Gadgil85348942022-11-24 14:36:06 +0530199 BIGDIA, // FAST_BIGDIA
200 BIGDIA // VFAST_DIAMOND
chiyotsaifbebe9d2022-05-23 13:31:41 -0700201};
202
chiyotsai7430da62020-07-27 14:06:26 -0700203// Mv beyond the range do not produce new/different prediction block.
204static INLINE void av1_set_mv_search_method(
205 FULLPEL_MOTION_SEARCH_PARAMS *ms_params,
venkat sanampudi67dc8da2021-12-21 11:57:41 +0530206 const search_site_config search_sites[NUM_DISTINCT_SEARCH_METHODS],
chiyotsai7430da62020-07-27 14:06:26 -0700207 SEARCH_METHODS search_method) {
chiyotsai7430da62020-07-27 14:06:26 -0700208 ms_params->search_method = search_method;
209 ms_params->search_sites =
210 &search_sites[search_method_lookup[ms_params->search_method]];
211}
212
Yunqing Wang96640052020-02-25 18:59:47 -0800213// Set up limit values for MV components.
214// Mv beyond the range do not produce new/different prediction block.
Urvang Joshi9dc909d2020-03-23 16:07:02 -0700215static INLINE void av1_set_mv_row_limits(
216 const CommonModeInfoParams *const mi_params, FullMvLimits *mv_limits,
217 int mi_row, int mi_height, int border) {
Yunqing Wang6a35bf92020-02-28 13:44:21 -0800218 const int min1 = -(mi_row * MI_SIZE + border - 2 * AOM_INTERP_EXTEND);
219 const int min2 = -(((mi_row + mi_height) * MI_SIZE) + 2 * AOM_INTERP_EXTEND);
220 mv_limits->row_min = AOMMAX(min1, min2);
Urvang Joshi9dc909d2020-03-23 16:07:02 -0700221 const int max1 = (mi_params->mi_rows - mi_row - mi_height) * MI_SIZE +
222 border - 2 * AOM_INTERP_EXTEND;
223 const int max2 =
224 (mi_params->mi_rows - mi_row) * MI_SIZE + 2 * AOM_INTERP_EXTEND;
Yunqing Wang6a35bf92020-02-28 13:44:21 -0800225 mv_limits->row_max = AOMMIN(max1, max2);
226}
227
Urvang Joshi9dc909d2020-03-23 16:07:02 -0700228static INLINE void av1_set_mv_col_limits(
229 const CommonModeInfoParams *const mi_params, FullMvLimits *mv_limits,
230 int mi_col, int mi_width, int border) {
Yunqing Wang6a35bf92020-02-28 13:44:21 -0800231 const int min1 = -(mi_col * MI_SIZE + border - 2 * AOM_INTERP_EXTEND);
232 const int min2 = -(((mi_col + mi_width) * MI_SIZE) + 2 * AOM_INTERP_EXTEND);
233 mv_limits->col_min = AOMMAX(min1, min2);
Urvang Joshi9dc909d2020-03-23 16:07:02 -0700234 const int max1 = (mi_params->mi_cols - mi_col - mi_width) * MI_SIZE + border -
Yunqing Wang6a35bf92020-02-28 13:44:21 -0800235 2 * AOM_INTERP_EXTEND;
Urvang Joshi9dc909d2020-03-23 16:07:02 -0700236 const int max2 =
237 (mi_params->mi_cols - mi_col) * MI_SIZE + 2 * AOM_INTERP_EXTEND;
Yunqing Wang6a35bf92020-02-28 13:44:21 -0800238 mv_limits->col_max = AOMMIN(max1, max2);
239}
240
Urvang Joshi9dc909d2020-03-23 16:07:02 -0700241static INLINE void av1_set_mv_limits(
242 const CommonModeInfoParams *const mi_params, FullMvLimits *mv_limits,
243 int mi_row, int mi_col, int mi_height, int mi_width, int border) {
244 av1_set_mv_row_limits(mi_params, mv_limits, mi_row, mi_height, border);
245 av1_set_mv_col_limits(mi_params, mv_limits, mi_col, mi_width, border);
Yunqing Wang96640052020-02-25 18:59:47 -0800246}
247
chiyotsai9f664e32020-02-19 14:17:31 -0800248void av1_set_mv_search_range(FullMvLimits *mv_limits, const MV *mv);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700249
Yaowu Xuf883b422016-08-30 14:01:10 -0700250int av1_init_search_range(int size);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700251
kyslov9de0d282019-02-27 16:14:08 -0800252unsigned int av1_int_pro_motion_estimation(const struct AV1_COMP *cpi,
253 MACROBLOCK *x, BLOCK_SIZE bsize,
254 int mi_row, int mi_col,
255 const MV *ref_mv);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700256
chiyotsai30a5bdf2020-04-06 14:28:59 -0700257int av1_refining_search_8p_c(const FULLPEL_MOTION_SEARCH_PARAMS *ms_params,
258 const FULLPEL_MV start_mv, FULLPEL_MV *best_mv);
chiyotsai9f664e32020-02-19 14:17:31 -0800259
chiyotsai2e42a662020-02-26 17:39:03 -0800260int av1_full_pixel_search(const FULLPEL_MV start_mv,
261 const FULLPEL_MOTION_SEARCH_PARAMS *ms_params,
262 const int step_param, int *cost_list,
chiyotsai8bbdd412020-03-03 14:57:23 -0800263 FULLPEL_MV *best_mv, FULLPEL_MV *second_best_mv);
chiyotsai9f664e32020-02-19 14:17:31 -0800264
chiyotsai82f36c92020-04-09 16:18:02 -0700265int av1_intrabc_hash_search(const struct AV1_COMP *cpi, const MACROBLOCKD *xd,
266 const FULLPEL_MOTION_SEARCH_PARAMS *ms_params,
267 IntraBCHashInfo *intrabc_hash_info,
268 FULLPEL_MV *best_mv);
chiyotsai8bbdd412020-03-03 14:57:23 -0800269
chiyotsai94f4aca2020-03-20 12:54:47 -0700270int av1_obmc_full_pixel_search(const FULLPEL_MV start_mv,
chiyotsai2e42a662020-02-26 17:39:03 -0800271 const FULLPEL_MOTION_SEARCH_PARAMS *ms_params,
272 const int step_param, FULLPEL_MV *best_mv);
chiyotsai9f664e32020-02-19 14:17:31 -0800273
chiyotsai9f664e32020-02-19 14:17:31 -0800274static INLINE int av1_is_fullmv_in_range(const FullMvLimits *mv_limits,
275 FULLPEL_MV mv) {
276 return (mv.col >= mv_limits->col_min) && (mv.col <= mv_limits->col_max) &&
277 (mv.row >= mv_limits->row_min) && (mv.row <= mv_limits->row_max);
278}
279// =============================================================================
280// Subpixel Motion Search
281// =============================================================================
chiyotsai2aac3002020-02-13 17:02:01 -0800282enum {
283 EIGHTH_PEL,
284 QUARTER_PEL,
285 HALF_PEL,
286 FULL_PEL
287} UENUM1BYTE(SUBPEL_FORCE_STOP);
288
289typedef struct {
chiyotsai2aac3002020-02-13 17:02:01 -0800290 const aom_variance_fn_ptr_t *vfp;
291 SUBPEL_SEARCH_TYPE subpel_search_type;
chiyotsai5aa70752020-03-26 10:13:10 -0700292 // Source and reference buffers
293 MSBuffers ms_buffers;
chiyotsai2aac3002020-02-13 17:02:01 -0800294 int w, h;
chiyotsaia742e7d2020-02-14 17:27:58 -0800295} SUBPEL_SEARCH_VAR_PARAMS;
chiyotsai2aac3002020-02-13 17:02:01 -0800296
297// This struct holds subpixel motion search parameters that should be constant
298// during the search
299typedef struct {
300 // High level motion search settings
301 int allow_hp;
302 const int *cost_list;
303 SUBPEL_FORCE_STOP forced_stop;
304 int iters_per_step;
chiyotsai5aa70752020-03-26 10:13:10 -0700305 SubpelMvLimits mv_limits;
chiyotsai2aac3002020-02-13 17:02:01 -0800306
307 // For calculating mv cost
308 MV_COST_PARAMS mv_cost_params;
309
310 // Distortion calculation params
chiyotsaia742e7d2020-02-14 17:27:58 -0800311 SUBPEL_SEARCH_VAR_PARAMS var_params;
chiyotsai2aac3002020-02-13 17:02:01 -0800312} SUBPEL_MOTION_SEARCH_PARAMS;
313
chiyotsai083db972020-03-30 11:43:52 -0700314void av1_make_default_subpel_ms_params(SUBPEL_MOTION_SEARCH_PARAMS *ms_params,
315 const struct AV1_COMP *cpi,
316 const MACROBLOCK *x, BLOCK_SIZE bsize,
chiyotsai4d1b7d92020-04-07 13:56:22 -0700317 const MV *ref_mv, const int *cost_list);
chiyotsai2aac3002020-02-13 17:02:01 -0800318
chiyotsai5aa70752020-03-26 10:13:10 -0700319typedef int(fractional_mv_step_fp)(MACROBLOCKD *xd, const AV1_COMMON *const cm,
chiyotsai2aac3002020-02-13 17:02:01 -0800320 const SUBPEL_MOTION_SEARCH_PARAMS *ms_params,
Yaowu Xuf8b0e9b2020-03-31 13:14:38 -0700321 MV start_mv, MV *bestmv, int *distortion,
322 unsigned int *sse1,
chiyotsai5aa70752020-03-26 10:13:10 -0700323 int_mv *last_mv_search_list);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700324
Yaowu Xuf883b422016-08-30 14:01:10 -0700325extern fractional_mv_step_fp av1_find_best_sub_pixel_tree;
326extern fractional_mv_step_fp av1_find_best_sub_pixel_tree_pruned;
327extern fractional_mv_step_fp av1_find_best_sub_pixel_tree_pruned_more;
Yunqing Wangff4fa062017-04-21 10:56:08 -0700328extern fractional_mv_step_fp av1_return_max_sub_pixel_mv;
329extern fractional_mv_step_fp av1_return_min_sub_pixel_mv;
chiyotsai2aac3002020-02-13 17:02:01 -0800330extern fractional_mv_step_fp av1_find_best_obmc_sub_pixel_tree_up;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700331
chiyotsai74da72b2020-04-07 13:45:40 -0700332unsigned int av1_refine_warped_mv(MACROBLOCKD *xd, const AV1_COMMON *const cm,
333 const SUBPEL_MOTION_SEARCH_PARAMS *ms_params,
334 BLOCK_SIZE bsize, const int *pts0,
335 const int *pts_inref0, int total_samples);
chiyotsai30a5bdf2020-04-06 14:28:59 -0700336
Venkate846e2b2018-09-21 07:31:14 +0530337static INLINE void av1_set_fractional_mv(int_mv *fractional_best_mv) {
338 for (int z = 0; z < 3; z++) {
339 fractional_best_mv[z].as_int = INVALID_MV;
340 }
341}
342
chiyotsai2ad959b2020-02-12 14:29:32 -0800343static INLINE void av1_set_subpel_mv_search_range(SubpelMvLimits *subpel_limits,
344 const FullMvLimits *mv_limits,
345 const MV *ref_mv) {
chiyotsai87bb8052020-02-12 16:56:33 -0800346 const int max_mv = GET_MV_SUBPEL(MAX_FULL_PEL_VAL);
347 const int minc =
348 AOMMAX(GET_MV_SUBPEL(mv_limits->col_min), ref_mv->col - max_mv);
349 const int maxc =
350 AOMMIN(GET_MV_SUBPEL(mv_limits->col_max), ref_mv->col + max_mv);
351 const int minr =
352 AOMMAX(GET_MV_SUBPEL(mv_limits->row_min), ref_mv->row - max_mv);
353 const int maxr =
354 AOMMIN(GET_MV_SUBPEL(mv_limits->row_max), ref_mv->row + max_mv);
Yunqing Wangda213612019-06-12 08:47:03 -0700355
chiyotsai2ad959b2020-02-12 14:29:32 -0800356 subpel_limits->col_min = AOMMAX(MV_LOW + 1, minc);
357 subpel_limits->col_max = AOMMIN(MV_UPP - 1, maxc);
358 subpel_limits->row_min = AOMMAX(MV_LOW + 1, minr);
359 subpel_limits->row_max = AOMMIN(MV_UPP - 1, maxr);
360}
361
chiyotsai2ad959b2020-02-12 14:29:32 -0800362static INLINE int av1_is_subpelmv_in_range(const SubpelMvLimits *mv_limits,
363 MV mv) {
364 return (mv.col >= mv_limits->col_min) && (mv.col <= mv_limits->col_max) &&
365 (mv.row >= mv_limits->row_min) && (mv.row <= mv_limits->row_max);
Yunqing Wangda213612019-06-12 08:47:03 -0700366}
367
Ranjit Kumar Tulabandu332b7302022-10-10 01:12:08 +0530368static INLINE int get_offset_from_fullmv(const FULLPEL_MV *mv, int stride) {
369 return mv->row * stride + mv->col;
370}
371
372static INLINE const uint8_t *get_buf_from_fullmv(const struct buf_2d *buf,
373 const FULLPEL_MV *mv) {
374 return &buf->buf[get_offset_from_fullmv(mv, buf->stride)];
375}
376
Peng Bin6e2ced62018-05-08 11:34:36 +0800377#ifdef __cplusplus
378} // extern "C"
379#endif
380
James Zerne1cbb132018-08-22 14:10:36 -0700381#endif // AOM_AV1_ENCODER_MCOMP_H_