xref: /aosp_15_r20/external/libaom/av1/common/warped_motion.h (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
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_COMMON_WARPED_MOTION_H_
13 #define AOM_AV1_COMMON_WARPED_MOTION_H_
14 
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <memory.h>
18 #include <math.h>
19 #include <assert.h>
20 
21 #include "config/aom_config.h"
22 
23 #include "aom_ports/mem.h"
24 #include "aom_dsp/aom_dsp_common.h"
25 #include "av1/common/mv.h"
26 #include "av1/common/convolve.h"
27 
28 #define LEAST_SQUARES_SAMPLES_MAX_BITS 3
29 #define LEAST_SQUARES_SAMPLES_MAX (1 << LEAST_SQUARES_SAMPLES_MAX_BITS)
30 #define SAMPLES_ARRAY_SIZE (LEAST_SQUARES_SAMPLES_MAX * 2)
31 #define WARPED_MOTION_DEBUG 0
32 #define DEFAULT_WMTYPE AFFINE
33 #define WARP_ERROR_BLOCK_LOG 5
34 #define WARP_ERROR_BLOCK (1 << WARP_ERROR_BLOCK_LOG)
35 
36 extern const int16_t av1_warped_filter[WARPEDPIXEL_PREC_SHIFTS * 3 + 1][8];
37 
38 DECLARE_ALIGNED(8, extern const int8_t,
39                 av1_filter_8bit[WARPEDPIXEL_PREC_SHIFTS * 3 + 1][8]);
40 
41 static const uint8_t warp_pad_left[14][16] = {
42   { 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
43   { 2, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
44   { 3, 3, 3, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
45   { 4, 4, 4, 4, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
46   { 5, 5, 5, 5, 5, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
47   { 6, 6, 6, 6, 6, 6, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
48   { 7, 7, 7, 7, 7, 7, 7, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
49   { 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 10, 11, 12, 13, 14, 15 },
50   { 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 11, 12, 13, 14, 15 },
51   { 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 12, 13, 14, 15 },
52   { 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 13, 14, 15 },
53   { 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 14, 15 },
54   { 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 15 },
55   { 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15 },
56 };
57 
58 static const uint8_t warp_pad_right[14][16] = {
59   { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 14 },
60   { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 13, 13 },
61   { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12, 12, 12 },
62   { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 11, 11, 11, 11 },
63   { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 10, 10 },
64   { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9, 9, 9, 9, 9 },
65   { 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 8, 8, 8 },
66   { 0, 1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7 },
67   { 0, 1, 2, 3, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6 },
68   { 0, 1, 2, 3, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 },
69   { 0, 1, 2, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 },
70   { 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
71   { 0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 },
72   { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
73 };
74 
75 void highbd_warp_plane(WarpedMotionParams *wm, const uint16_t *const ref,
76                        int width, int height, int stride, uint16_t *const pred,
77                        int p_col, int p_row, int p_width, int p_height,
78                        int p_stride, int subsampling_x, int subsampling_y,
79                        int bd, ConvolveParams *conv_params);
80 
81 void warp_plane(WarpedMotionParams *wm, const uint8_t *const ref, int width,
82                 int height, int stride, uint8_t *pred, int p_col, int p_row,
83                 int p_width, int p_height, int p_stride, int subsampling_x,
84                 int subsampling_y, ConvolveParams *conv_params);
85 
86 void av1_warp_plane(WarpedMotionParams *wm, int use_hbd, int bd,
87                     const uint8_t *ref, int width, int height, int stride,
88                     uint8_t *pred, int p_col, int p_row, int p_width,
89                     int p_height, int p_stride, int subsampling_x,
90                     int subsampling_y, ConvolveParams *conv_params);
91 
92 int av1_find_projection(int np, const int *pts1, const int *pts2,
93                         BLOCK_SIZE bsize, int mvy, int mvx,
94                         WarpedMotionParams *wm_params, int mi_row, int mi_col);
95 
96 int av1_get_shear_params(WarpedMotionParams *wm);
97 #endif  // AOM_AV1_COMMON_WARPED_MOTION_H_
98