blob: 87b9309b614e64823292e02512ddfd41ebe4c205 [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;
chiyotsaia4c4f182022-12-05 14:41:05 -0800140 aom_sad_multi_d_fn_t sdx3df;
chiyotsai2e42a662020-02-26 17:39:03 -0800141} FULLPEL_MOTION_SEARCH_PARAMS;
142
Deepa K Gdc6842e2023-06-07 15:44:56 +0530143typedef struct {
144 int err_cost;
145 unsigned int distortion;
146 unsigned int sse;
147} FULLPEL_MV_STATS;
148
Nithya V Sb6871a72020-12-25 23:05:48 +0530149void av1_init_obmc_buffer(OBMCBuffer *obmc_buffer);
150
venkat sanampudi14affd02020-07-23 07:41:05 +0530151void av1_make_default_fullpel_ms_params(
152 FULLPEL_MOTION_SEARCH_PARAMS *ms_params, const struct AV1_COMP *cpi,
Deepa K Gcb899e82023-04-21 23:26:20 +0530153 MACROBLOCK *x, BLOCK_SIZE bsize, const MV *ref_mv, FULLPEL_MV start_mv,
venkat sanampudi67dc8da2021-12-21 11:57:41 +0530154 const search_site_config search_sites[NUM_DISTINCT_SEARCH_METHODS],
chiyotsaif7acaa72023-07-24 11:10:40 -0700155 SEARCH_METHODS search_method, int fine_search_interval);
chiyotsai2e42a662020-02-26 17:39:03 -0800156
chiyotsaibcf2e782021-03-11 16:52:49 -0800157/*! Sets the \ref FULLPEL_MOTION_SEARCH_PARAMS to intra mode. */
158void av1_set_ms_to_intra_mode(FULLPEL_MOTION_SEARCH_PARAMS *ms_params,
159 const IntraBCMVCosts *dv_costs);
160
Nithya V S41b585c2020-07-28 18:01:58 +0530161// Sets up configs for fullpixel DIAMOND / CLAMPED_DIAMOND search method.
162void av1_init_dsmotion_compensation(search_site_config *cfg, int stride,
163 int level);
venkat sanampudi14affd02020-07-23 07:41:05 +0530164// Sets up configs for firstpass motion search.
chiyotsai9f664e32020-02-19 14:17:31 -0800165void av1_init_motion_fpf(search_site_config *cfg, int stride);
Nithya V S41b585c2020-07-28 18:01:58 +0530166// Sets up configs for NSTEP / NSTEP_8PT motion search method.
167void av1_init_motion_compensation_nstep(search_site_config *cfg, int stride,
168 int level);
venkat sanampudi14affd02020-07-23 07:41:05 +0530169// Sets up configs for BIGDIA / FAST_DIAMOND / FAST_BIGDIA
170// motion search method.
Nithya V S41b585c2020-07-28 18:01:58 +0530171void av1_init_motion_compensation_bigdia(search_site_config *cfg, int stride,
172 int level);
venkat sanampudi14affd02020-07-23 07:41:05 +0530173// Sets up configs for HEX or FAST_HEX motion search method.
Nithya V S41b585c2020-07-28 18:01:58 +0530174void av1_init_motion_compensation_hex(search_site_config *cfg, int stride,
175 int level);
venkat sanampudi14affd02020-07-23 07:41:05 +0530176// Sets up configs for SQUARE motion search method.
Nithya V S41b585c2020-07-28 18:01:58 +0530177void av1_init_motion_compensation_square(search_site_config *cfg, int stride,
178 int level);
chiyotsai9f664e32020-02-19 14:17:31 -0800179
chiyotsaifbebe9d2022-05-23 13:31:41 -0700180/*! Function pointer to search site config initialization of different search
181 * method functions. */
182typedef void (*av1_init_search_site_config)(search_site_config *cfg, int stride,
183 int level);
184
Wan-Teh Chang4690e032023-08-24 18:29:28 -0700185/*! Array of function pointers used to set the motion search config. */
186extern const av1_init_search_site_config
187 av1_init_motion_compensation[NUM_DISTINCT_SEARCH_METHODS];
chiyotsaifbebe9d2022-05-23 13:31:41 -0700188
189// Array to inform which all search methods are having
190// same candidates and different in number of search steps.
191static const SEARCH_METHODS search_method_lookup[NUM_SEARCH_METHODS] = {
192 DIAMOND, // DIAMOND
193 NSTEP, // NSTEP
194 NSTEP_8PT, // NSTEP_8PT
195 CLAMPED_DIAMOND, // CLAMPED_DIAMOND
196 HEX, // HEX
197 BIGDIA, // BIGDIA
198 SQUARE, // SQUARE
199 HEX, // FAST_HEX
200 BIGDIA, // FAST_DIAMOND
Neeraj Gadgil85348942022-11-24 14:36:06 +0530201 BIGDIA, // FAST_BIGDIA
202 BIGDIA // VFAST_DIAMOND
chiyotsaifbebe9d2022-05-23 13:31:41 -0700203};
204
chiyotsai945edd62023-01-24 15:50:09 -0800205// Reinitialize the search site config.
206static AOM_INLINE void av1_refresh_search_site_config(
207 search_site_config *ss_cfg_buf, SEARCH_METHODS search_method,
208 const int ref_stride) {
209 const int level =
210 search_method == NSTEP_8PT || search_method == CLAMPED_DIAMOND;
211 search_method = search_method_lookup[search_method];
212 av1_init_motion_compensation[search_method](&ss_cfg_buf[search_method],
213 ref_stride, level);
214}
215
chiyotsai7430da62020-07-27 14:06:26 -0700216// Mv beyond the range do not produce new/different prediction block.
217static INLINE void av1_set_mv_search_method(
218 FULLPEL_MOTION_SEARCH_PARAMS *ms_params,
venkat sanampudi67dc8da2021-12-21 11:57:41 +0530219 const search_site_config search_sites[NUM_DISTINCT_SEARCH_METHODS],
chiyotsai7430da62020-07-27 14:06:26 -0700220 SEARCH_METHODS search_method) {
chiyotsai7430da62020-07-27 14:06:26 -0700221 ms_params->search_method = search_method;
222 ms_params->search_sites =
223 &search_sites[search_method_lookup[ms_params->search_method]];
224}
225
Yunqing Wang96640052020-02-25 18:59:47 -0800226// Set up limit values for MV components.
227// Mv beyond the range do not produce new/different prediction block.
Urvang Joshi9dc909d2020-03-23 16:07:02 -0700228static INLINE void av1_set_mv_row_limits(
229 const CommonModeInfoParams *const mi_params, FullMvLimits *mv_limits,
230 int mi_row, int mi_height, int border) {
Yunqing Wang6a35bf92020-02-28 13:44:21 -0800231 const int min1 = -(mi_row * MI_SIZE + border - 2 * AOM_INTERP_EXTEND);
232 const int min2 = -(((mi_row + mi_height) * MI_SIZE) + 2 * AOM_INTERP_EXTEND);
233 mv_limits->row_min = AOMMAX(min1, min2);
Urvang Joshi9dc909d2020-03-23 16:07:02 -0700234 const int max1 = (mi_params->mi_rows - mi_row - mi_height) * MI_SIZE +
235 border - 2 * AOM_INTERP_EXTEND;
236 const int max2 =
237 (mi_params->mi_rows - mi_row) * MI_SIZE + 2 * AOM_INTERP_EXTEND;
Yunqing Wang6a35bf92020-02-28 13:44:21 -0800238 mv_limits->row_max = AOMMIN(max1, max2);
239}
240
Urvang Joshi9dc909d2020-03-23 16:07:02 -0700241static INLINE void av1_set_mv_col_limits(
242 const CommonModeInfoParams *const mi_params, FullMvLimits *mv_limits,
243 int mi_col, int mi_width, int border) {
Yunqing Wang6a35bf92020-02-28 13:44:21 -0800244 const int min1 = -(mi_col * MI_SIZE + border - 2 * AOM_INTERP_EXTEND);
245 const int min2 = -(((mi_col + mi_width) * MI_SIZE) + 2 * AOM_INTERP_EXTEND);
246 mv_limits->col_min = AOMMAX(min1, min2);
Urvang Joshi9dc909d2020-03-23 16:07:02 -0700247 const int max1 = (mi_params->mi_cols - mi_col - mi_width) * MI_SIZE + border -
Yunqing Wang6a35bf92020-02-28 13:44:21 -0800248 2 * AOM_INTERP_EXTEND;
Urvang Joshi9dc909d2020-03-23 16:07:02 -0700249 const int max2 =
250 (mi_params->mi_cols - mi_col) * MI_SIZE + 2 * AOM_INTERP_EXTEND;
Yunqing Wang6a35bf92020-02-28 13:44:21 -0800251 mv_limits->col_max = AOMMIN(max1, max2);
252}
253
Urvang Joshi9dc909d2020-03-23 16:07:02 -0700254static INLINE void av1_set_mv_limits(
255 const CommonModeInfoParams *const mi_params, FullMvLimits *mv_limits,
256 int mi_row, int mi_col, int mi_height, int mi_width, int border) {
257 av1_set_mv_row_limits(mi_params, mv_limits, mi_row, mi_height, border);
258 av1_set_mv_col_limits(mi_params, mv_limits, mi_col, mi_width, border);
Yunqing Wang96640052020-02-25 18:59:47 -0800259}
260
chiyotsai9f664e32020-02-19 14:17:31 -0800261void av1_set_mv_search_range(FullMvLimits *mv_limits, const MV *mv);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700262
Yaowu Xuf883b422016-08-30 14:01:10 -0700263int av1_init_search_range(int size);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700264
Marco Paniconi5a4ea092023-08-09 14:36:15 -0700265unsigned int av1_int_pro_motion_estimation(
266 const struct AV1_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bsize, int mi_row,
Marco Paniconi83cb7a52023-08-26 20:49:53 -0700267 int mi_col, const MV *ref_mv, unsigned int *y_sad_zero,
268 int me_search_size_col, int me_search_size_row);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700269
chiyotsai30a5bdf2020-04-06 14:28:59 -0700270int av1_refining_search_8p_c(const FULLPEL_MOTION_SEARCH_PARAMS *ms_params,
271 const FULLPEL_MV start_mv, FULLPEL_MV *best_mv);
chiyotsai9f664e32020-02-19 14:17:31 -0800272
chiyotsai2e42a662020-02-26 17:39:03 -0800273int av1_full_pixel_search(const FULLPEL_MV start_mv,
274 const FULLPEL_MOTION_SEARCH_PARAMS *ms_params,
275 const int step_param, int *cost_list,
Deepa K Gdc6842e2023-06-07 15:44:56 +0530276 FULLPEL_MV *best_mv, FULLPEL_MV_STATS *best_mv_stats,
277 FULLPEL_MV *second_best_mv);
chiyotsai9f664e32020-02-19 14:17:31 -0800278
chiyotsai82f36c92020-04-09 16:18:02 -0700279int av1_intrabc_hash_search(const struct AV1_COMP *cpi, const MACROBLOCKD *xd,
280 const FULLPEL_MOTION_SEARCH_PARAMS *ms_params,
281 IntraBCHashInfo *intrabc_hash_info,
282 FULLPEL_MV *best_mv);
chiyotsai8bbdd412020-03-03 14:57:23 -0800283
chiyotsai94f4aca2020-03-20 12:54:47 -0700284int av1_obmc_full_pixel_search(const FULLPEL_MV start_mv,
chiyotsai2e42a662020-02-26 17:39:03 -0800285 const FULLPEL_MOTION_SEARCH_PARAMS *ms_params,
286 const int step_param, FULLPEL_MV *best_mv);
chiyotsai9f664e32020-02-19 14:17:31 -0800287
chiyotsai9f664e32020-02-19 14:17:31 -0800288static INLINE int av1_is_fullmv_in_range(const FullMvLimits *mv_limits,
289 FULLPEL_MV mv) {
290 return (mv.col >= mv_limits->col_min) && (mv.col <= mv_limits->col_max) &&
291 (mv.row >= mv_limits->row_min) && (mv.row <= mv_limits->row_max);
292}
293// =============================================================================
294// Subpixel Motion Search
295// =============================================================================
chiyotsai2aac3002020-02-13 17:02:01 -0800296enum {
297 EIGHTH_PEL,
298 QUARTER_PEL,
299 HALF_PEL,
300 FULL_PEL
301} UENUM1BYTE(SUBPEL_FORCE_STOP);
302
303typedef struct {
chiyotsai2aac3002020-02-13 17:02:01 -0800304 const aom_variance_fn_ptr_t *vfp;
305 SUBPEL_SEARCH_TYPE subpel_search_type;
chiyotsai5aa70752020-03-26 10:13:10 -0700306 // Source and reference buffers
307 MSBuffers ms_buffers;
chiyotsai2aac3002020-02-13 17:02:01 -0800308 int w, h;
chiyotsaia742e7d2020-02-14 17:27:58 -0800309} SUBPEL_SEARCH_VAR_PARAMS;
chiyotsai2aac3002020-02-13 17:02:01 -0800310
311// This struct holds subpixel motion search parameters that should be constant
312// during the search
313typedef struct {
314 // High level motion search settings
315 int allow_hp;
316 const int *cost_list;
317 SUBPEL_FORCE_STOP forced_stop;
318 int iters_per_step;
chiyotsai5aa70752020-03-26 10:13:10 -0700319 SubpelMvLimits mv_limits;
chiyotsai2aac3002020-02-13 17:02:01 -0800320
321 // For calculating mv cost
322 MV_COST_PARAMS mv_cost_params;
323
324 // Distortion calculation params
chiyotsaia742e7d2020-02-14 17:27:58 -0800325 SUBPEL_SEARCH_VAR_PARAMS var_params;
chiyotsai2aac3002020-02-13 17:02:01 -0800326} SUBPEL_MOTION_SEARCH_PARAMS;
327
chiyotsai083db972020-03-30 11:43:52 -0700328void av1_make_default_subpel_ms_params(SUBPEL_MOTION_SEARCH_PARAMS *ms_params,
329 const struct AV1_COMP *cpi,
330 const MACROBLOCK *x, BLOCK_SIZE bsize,
chiyotsai4d1b7d92020-04-07 13:56:22 -0700331 const MV *ref_mv, const int *cost_list);
chiyotsai2aac3002020-02-13 17:02:01 -0800332
chiyotsai5aa70752020-03-26 10:13:10 -0700333typedef int(fractional_mv_step_fp)(MACROBLOCKD *xd, const AV1_COMMON *const cm,
chiyotsai2aac3002020-02-13 17:02:01 -0800334 const SUBPEL_MOTION_SEARCH_PARAMS *ms_params,
Deepa K Gdc6842e2023-06-07 15:44:56 +0530335 MV start_mv,
336 const FULLPEL_MV_STATS *start_mv_stats,
337 MV *bestmv, int *distortion,
Yaowu Xuf8b0e9b2020-03-31 13:14:38 -0700338 unsigned int *sse1,
chiyotsai5aa70752020-03-26 10:13:10 -0700339 int_mv *last_mv_search_list);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700340
Yaowu Xuf883b422016-08-30 14:01:10 -0700341extern fractional_mv_step_fp av1_find_best_sub_pixel_tree;
342extern fractional_mv_step_fp av1_find_best_sub_pixel_tree_pruned;
343extern fractional_mv_step_fp av1_find_best_sub_pixel_tree_pruned_more;
Yunqing Wangff4fa062017-04-21 10:56:08 -0700344extern fractional_mv_step_fp av1_return_max_sub_pixel_mv;
345extern fractional_mv_step_fp av1_return_min_sub_pixel_mv;
chiyotsai2aac3002020-02-13 17:02:01 -0800346extern fractional_mv_step_fp av1_find_best_obmc_sub_pixel_tree_up;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700347
chiyotsai74da72b2020-04-07 13:45:40 -0700348unsigned int av1_refine_warped_mv(MACROBLOCKD *xd, const AV1_COMMON *const cm,
349 const SUBPEL_MOTION_SEARCH_PARAMS *ms_params,
350 BLOCK_SIZE bsize, const int *pts0,
Rachel Barkerc6878ab2023-01-09 17:03:54 +0000351 const int *pts_inref0, int total_samples,
352 WARP_SEARCH_METHOD search_method,
353 int num_iterations);
chiyotsai30a5bdf2020-04-06 14:28:59 -0700354
Venkate846e2b2018-09-21 07:31:14 +0530355static INLINE void av1_set_fractional_mv(int_mv *fractional_best_mv) {
356 for (int z = 0; z < 3; z++) {
357 fractional_best_mv[z].as_int = INVALID_MV;
358 }
359}
360
chiyotsai2ad959b2020-02-12 14:29:32 -0800361static INLINE void av1_set_subpel_mv_search_range(SubpelMvLimits *subpel_limits,
362 const FullMvLimits *mv_limits,
363 const MV *ref_mv) {
chiyotsai87bb8052020-02-12 16:56:33 -0800364 const int max_mv = GET_MV_SUBPEL(MAX_FULL_PEL_VAL);
Jingning Han68047e72023-02-27 15:46:02 -0800365 int minc = AOMMAX(GET_MV_SUBPEL(mv_limits->col_min), ref_mv->col - max_mv);
366 int maxc = AOMMIN(GET_MV_SUBPEL(mv_limits->col_max), ref_mv->col + max_mv);
367 int minr = AOMMAX(GET_MV_SUBPEL(mv_limits->row_min), ref_mv->row - max_mv);
368 int maxr = AOMMIN(GET_MV_SUBPEL(mv_limits->row_max), ref_mv->row + max_mv);
369
370 maxc = AOMMAX(minc, maxc);
371 maxr = AOMMAX(minr, maxr);
Yunqing Wangda213612019-06-12 08:47:03 -0700372
chiyotsai2ad959b2020-02-12 14:29:32 -0800373 subpel_limits->col_min = AOMMAX(MV_LOW + 1, minc);
374 subpel_limits->col_max = AOMMIN(MV_UPP - 1, maxc);
375 subpel_limits->row_min = AOMMAX(MV_LOW + 1, minr);
376 subpel_limits->row_max = AOMMIN(MV_UPP - 1, maxr);
377}
378
chiyotsai2ad959b2020-02-12 14:29:32 -0800379static INLINE int av1_is_subpelmv_in_range(const SubpelMvLimits *mv_limits,
380 MV mv) {
381 return (mv.col >= mv_limits->col_min) && (mv.col <= mv_limits->col_max) &&
382 (mv.row >= mv_limits->row_min) && (mv.row <= mv_limits->row_max);
Yunqing Wangda213612019-06-12 08:47:03 -0700383}
384
Ranjit Kumar Tulabandu332b7302022-10-10 01:12:08 +0530385static INLINE int get_offset_from_fullmv(const FULLPEL_MV *mv, int stride) {
386 return mv->row * stride + mv->col;
387}
388
389static INLINE const uint8_t *get_buf_from_fullmv(const struct buf_2d *buf,
390 const FULLPEL_MV *mv) {
391 return &buf->buf[get_offset_from_fullmv(mv, buf->stride)];
392}
393
Peng Bin6e2ced62018-05-08 11:34:36 +0800394#ifdef __cplusplus
395} // extern "C"
396#endif
397
James Zerne1cbb132018-08-22 14:10:36 -0700398#endif // AOM_AV1_ENCODER_MCOMP_H_