Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | bde4ac8 | 2016-11-28 15:26:06 -0800 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | bde4ac8 | 2016-11-28 15:26:06 -0800 | [diff] [blame] | 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. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
James Zern | e1cbb13 | 2018-08-22 14:10:36 -0700 | [diff] [blame] | 12 | #ifndef AOM_AV1_COMMON_WARPED_MOTION_H_ |
| 13 | #define AOM_AV1_COMMON_WARPED_MOTION_H_ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 14 | |
| 15 | #include <stdio.h> |
| 16 | #include <stdlib.h> |
| 17 | #include <memory.h> |
| 18 | #include <math.h> |
| 19 | #include <assert.h> |
| 20 | |
Tom Finegan | 60e653d | 2018-05-22 11:34:58 -0700 | [diff] [blame] | 21 | #include "config/aom_config.h" |
| 22 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 23 | #include "aom_ports/mem.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 24 | #include "aom_dsp/aom_dsp_common.h" |
Sarah Parker | e529986 | 2016-08-16 14:57:37 -0700 | [diff] [blame] | 25 | #include "av1/common/mv.h" |
Angie Chiang | 81b2e50 | 2017-06-19 15:13:52 -0700 | [diff] [blame] | 26 | #include "av1/common/convolve.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 27 | |
Yue Chen | 1ab5780 | 2016-09-27 17:48:38 -0700 | [diff] [blame] | 28 | #define MAX_PARAMDIM 9 |
Debargha Mukherjee | 8c41024 | 2017-04-11 15:20:56 -0700 | [diff] [blame] | 29 | #define LEAST_SQUARES_SAMPLES_MAX_BITS 3 |
| 30 | #define LEAST_SQUARES_SAMPLES_MAX (1 << LEAST_SQUARES_SAMPLES_MAX_BITS) |
Yue Chen | d28bdba | 2017-06-16 10:38:03 -0700 | [diff] [blame] | 31 | #define SAMPLES_ARRAY_SIZE (LEAST_SQUARES_SAMPLES_MAX * 2) |
Yunqing Wang | d3c13e8 | 2018-01-02 17:52:56 -0800 | [diff] [blame] | 32 | #define WARPED_MOTION_DEBUG 0 |
Debargha Mukherjee | e6eb3b5 | 2017-02-26 08:50:56 -0800 | [diff] [blame] | 33 | #define DEFAULT_WMTYPE AFFINE |
Sarah Parker | 36b997b | 2019-05-09 16:06:53 -0700 | [diff] [blame] | 34 | #define WARP_ERROR_BLOCK_LOG 5 |
| 35 | #define WARP_ERROR_BLOCK (1 << WARP_ERROR_BLOCK_LOG) |
Yue Chen | 1ab5780 | 2016-09-27 17:48:38 -0700 | [diff] [blame] | 36 | |
Yaowu Xu | 3a19b8a | 2019-05-01 08:40:42 -0700 | [diff] [blame] | 37 | extern const int16_t av1_warped_filter[WARPEDPIXEL_PREC_SHIFTS * 3 + 1][8]; |
David Barker | d5dfa96 | 2017-01-10 15:06:08 +0000 | [diff] [blame] | 38 | |
Aniket Dhok | a80c64e | 2019-04-25 09:29:28 +0530 | [diff] [blame] | 39 | DECLARE_ALIGNED(8, extern const int8_t, |
Yaowu Xu | 2c61970 | 2019-05-03 08:55:45 -0700 | [diff] [blame] | 40 | av1_filter_8bit[WARPEDPIXEL_PREC_SHIFTS * 3 + 1][8]); |
Aniket Dhok | a80c64e | 2019-04-25 09:29:28 +0530 | [diff] [blame] | 41 | |
Remya | 9be8125 | 2020-05-24 10:59:14 +0530 | [diff] [blame] | 42 | #if CONFIG_EXT_WARP |
| 43 | extern const int16_t av1_ext_warped_filter[WARPEDPIXEL_PREC_SHIFTS + 1][8]; |
| 44 | |
| 45 | DECLARE_ALIGNED(16, extern const int16_t, |
| 46 | av1_ext_filter_16bit[WARPEDPIXEL_PREC_SHIFTS + 1][8]); |
| 47 | #endif // CONFIG_EXT_WARP |
| 48 | |
Sachin Kumar Garg | 6b10333 | 2019-05-10 19:18:19 +0530 | [diff] [blame] | 49 | /* clang-format off */ |
| 50 | static const int error_measure_lut[512] = { |
| 51 | // pow 0.7 |
| 52 | 16384, 16339, 16294, 16249, 16204, 16158, 16113, 16068, |
| 53 | 16022, 15977, 15932, 15886, 15840, 15795, 15749, 15703, |
| 54 | 15657, 15612, 15566, 15520, 15474, 15427, 15381, 15335, |
| 55 | 15289, 15242, 15196, 15149, 15103, 15056, 15010, 14963, |
| 56 | 14916, 14869, 14822, 14775, 14728, 14681, 14634, 14587, |
| 57 | 14539, 14492, 14445, 14397, 14350, 14302, 14254, 14206, |
| 58 | 14159, 14111, 14063, 14015, 13967, 13918, 13870, 13822, |
| 59 | 13773, 13725, 13676, 13628, 13579, 13530, 13481, 13432, |
| 60 | 13383, 13334, 13285, 13236, 13187, 13137, 13088, 13038, |
| 61 | 12988, 12939, 12889, 12839, 12789, 12739, 12689, 12639, |
| 62 | 12588, 12538, 12487, 12437, 12386, 12335, 12285, 12234, |
| 63 | 12183, 12132, 12080, 12029, 11978, 11926, 11875, 11823, |
| 64 | 11771, 11719, 11667, 11615, 11563, 11511, 11458, 11406, |
| 65 | 11353, 11301, 11248, 11195, 11142, 11089, 11036, 10982, |
| 66 | 10929, 10875, 10822, 10768, 10714, 10660, 10606, 10552, |
| 67 | 10497, 10443, 10388, 10333, 10279, 10224, 10168, 10113, |
| 68 | 10058, 10002, 9947, 9891, 9835, 9779, 9723, 9666, |
| 69 | 9610, 9553, 9497, 9440, 9383, 9326, 9268, 9211, |
| 70 | 9153, 9095, 9037, 8979, 8921, 8862, 8804, 8745, |
| 71 | 8686, 8627, 8568, 8508, 8449, 8389, 8329, 8269, |
| 72 | 8208, 8148, 8087, 8026, 7965, 7903, 7842, 7780, |
| 73 | 7718, 7656, 7593, 7531, 7468, 7405, 7341, 7278, |
| 74 | 7214, 7150, 7086, 7021, 6956, 6891, 6826, 6760, |
| 75 | 6695, 6628, 6562, 6495, 6428, 6361, 6293, 6225, |
| 76 | 6157, 6089, 6020, 5950, 5881, 5811, 5741, 5670, |
| 77 | 5599, 5527, 5456, 5383, 5311, 5237, 5164, 5090, |
| 78 | 5015, 4941, 4865, 4789, 4713, 4636, 4558, 4480, |
| 79 | 4401, 4322, 4242, 4162, 4080, 3998, 3916, 3832, |
| 80 | 3748, 3663, 3577, 3490, 3402, 3314, 3224, 3133, |
| 81 | 3041, 2948, 2854, 2758, 2661, 2562, 2461, 2359, |
| 82 | 2255, 2148, 2040, 1929, 1815, 1698, 1577, 1452, |
| 83 | 1323, 1187, 1045, 894, 731, 550, 339, 0, |
| 84 | 339, 550, 731, 894, 1045, 1187, 1323, 1452, |
| 85 | 1577, 1698, 1815, 1929, 2040, 2148, 2255, 2359, |
| 86 | 2461, 2562, 2661, 2758, 2854, 2948, 3041, 3133, |
| 87 | 3224, 3314, 3402, 3490, 3577, 3663, 3748, 3832, |
| 88 | 3916, 3998, 4080, 4162, 4242, 4322, 4401, 4480, |
| 89 | 4558, 4636, 4713, 4789, 4865, 4941, 5015, 5090, |
| 90 | 5164, 5237, 5311, 5383, 5456, 5527, 5599, 5670, |
| 91 | 5741, 5811, 5881, 5950, 6020, 6089, 6157, 6225, |
| 92 | 6293, 6361, 6428, 6495, 6562, 6628, 6695, 6760, |
| 93 | 6826, 6891, 6956, 7021, 7086, 7150, 7214, 7278, |
| 94 | 7341, 7405, 7468, 7531, 7593, 7656, 7718, 7780, |
| 95 | 7842, 7903, 7965, 8026, 8087, 8148, 8208, 8269, |
| 96 | 8329, 8389, 8449, 8508, 8568, 8627, 8686, 8745, |
| 97 | 8804, 8862, 8921, 8979, 9037, 9095, 9153, 9211, |
| 98 | 9268, 9326, 9383, 9440, 9497, 9553, 9610, 9666, |
| 99 | 9723, 9779, 9835, 9891, 9947, 10002, 10058, 10113, |
| 100 | 10168, 10224, 10279, 10333, 10388, 10443, 10497, 10552, |
| 101 | 10606, 10660, 10714, 10768, 10822, 10875, 10929, 10982, |
| 102 | 11036, 11089, 11142, 11195, 11248, 11301, 11353, 11406, |
| 103 | 11458, 11511, 11563, 11615, 11667, 11719, 11771, 11823, |
| 104 | 11875, 11926, 11978, 12029, 12080, 12132, 12183, 12234, |
| 105 | 12285, 12335, 12386, 12437, 12487, 12538, 12588, 12639, |
| 106 | 12689, 12739, 12789, 12839, 12889, 12939, 12988, 13038, |
| 107 | 13088, 13137, 13187, 13236, 13285, 13334, 13383, 13432, |
| 108 | 13481, 13530, 13579, 13628, 13676, 13725, 13773, 13822, |
| 109 | 13870, 13918, 13967, 14015, 14063, 14111, 14159, 14206, |
| 110 | 14254, 14302, 14350, 14397, 14445, 14492, 14539, 14587, |
| 111 | 14634, 14681, 14728, 14775, 14822, 14869, 14916, 14963, |
| 112 | 15010, 15056, 15103, 15149, 15196, 15242, 15289, 15335, |
| 113 | 15381, 15427, 15474, 15520, 15566, 15612, 15657, 15703, |
| 114 | 15749, 15795, 15840, 15886, 15932, 15977, 16022, 16068, |
| 115 | 16113, 16158, 16204, 16249, 16294, 16339, 16384, 16384, |
| 116 | }; |
| 117 | /* clang-format on */ |
| 118 | |
Ravi Chaudhary | 8ff220c | 2018-05-09 16:42:19 +0530 | [diff] [blame] | 119 | static const uint8_t warp_pad_left[14][16] = { |
| 120 | { 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, |
| 121 | { 2, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, |
| 122 | { 3, 3, 3, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, |
| 123 | { 4, 4, 4, 4, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, |
| 124 | { 5, 5, 5, 5, 5, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, |
| 125 | { 6, 6, 6, 6, 6, 6, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, |
| 126 | { 7, 7, 7, 7, 7, 7, 7, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, |
| 127 | { 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 10, 11, 12, 13, 14, 15 }, |
| 128 | { 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 11, 12, 13, 14, 15 }, |
| 129 | { 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 12, 13, 14, 15 }, |
| 130 | { 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 13, 14, 15 }, |
| 131 | { 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 14, 15 }, |
| 132 | { 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 15 }, |
| 133 | { 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15 }, |
| 134 | }; |
| 135 | |
| 136 | static const uint8_t warp_pad_right[14][16] = { |
| 137 | { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 14 }, |
| 138 | { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 13, 13 }, |
| 139 | { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12, 12, 12 }, |
| 140 | { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 11, 11, 11, 11 }, |
| 141 | { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 10, 10 }, |
| 142 | { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9, 9, 9, 9, 9 }, |
| 143 | { 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 8, 8, 8 }, |
| 144 | { 0, 1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7 }, |
| 145 | { 0, 1, 2, 3, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6 }, |
| 146 | { 0, 1, 2, 3, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 }, |
| 147 | { 0, 1, 2, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 }, |
| 148 | { 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 }, |
| 149 | { 0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 }, |
| 150 | { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } |
| 151 | }; |
| 152 | |
Sachin Kumar Garg | 6b10333 | 2019-05-10 19:18:19 +0530 | [diff] [blame] | 153 | static INLINE int error_measure(int err) { |
| 154 | return error_measure_lut[255 + err]; |
| 155 | } |
| 156 | |
emilkeyder@google.com | 6e3557c | 2017-03-27 10:52:53 -0400 | [diff] [blame] | 157 | // Returns the error between the result of applying motion 'wm' to the frame |
| 158 | // described by 'ref' and the frame described by 'dst'. |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 159 | int64_t av1_warp_error(WarpedMotionParams *wm, int use_hbd, int bd, |
emilkeyder@google.com | 6e3557c | 2017-03-27 10:52:53 -0400 | [diff] [blame] | 160 | const uint8_t *ref, int width, int height, int stride, |
| 161 | uint8_t *dst, int p_col, int p_row, int p_width, |
| 162 | int p_height, int p_stride, int subsampling_x, |
Sarah Parker | 36b997b | 2019-05-09 16:06:53 -0700 | [diff] [blame] | 163 | int subsampling_y, int64_t best_error, |
| 164 | uint8_t *segment_map, int segment_map_stride); |
emilkeyder@google.com | 6e3557c | 2017-03-27 10:52:53 -0400 | [diff] [blame] | 165 | |
| 166 | // Returns the error between the frame described by 'ref' and the frame |
| 167 | // described by 'dst'. |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 168 | int64_t av1_frame_error(int use_hbd, int bd, const uint8_t *ref, int stride, |
| 169 | uint8_t *dst, int p_width, int p_height, int p_stride); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 170 | |
Sarah Parker | 36b997b | 2019-05-09 16:06:53 -0700 | [diff] [blame] | 171 | int64_t av1_segmented_frame_error(int use_hbd, int bd, const uint8_t *ref, |
| 172 | int stride, uint8_t *dst, int p_width, |
| 173 | int p_height, int p_stride, |
| 174 | uint8_t *segment_map, int segment_map_stride); |
| 175 | |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 176 | void av1_warp_plane(WarpedMotionParams *wm, int use_hbd, int bd, |
Yaowu Xu | cd0f6c4 | 2017-05-05 11:18:22 -0700 | [diff] [blame] | 177 | const uint8_t *ref, int width, int height, int stride, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 178 | uint8_t *pred, int p_col, int p_row, int p_width, |
| 179 | int p_height, int p_stride, int subsampling_x, |
Remya | 7640d97 | 2020-07-08 19:21:17 +0530 | [diff] [blame] | 180 | int subsampling_y, |
| 181 | #if CONFIG_EXT_WARP && CONFIG_SUB8X8_WARP |
| 182 | int is_sub_8x8_block, |
| 183 | #endif // CONFIG_EXT_WARP && CONFIG_SUB8X8_WARP |
| 184 | ConvolveParams *conv_params); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 185 | |
Yaowu Xu | 3a19b8a | 2019-05-01 08:40:42 -0700 | [diff] [blame] | 186 | int av1_find_projection(int np, int *pts1, int *pts2, BLOCK_SIZE bsize, int mvy, |
| 187 | int mvx, WarpedMotionParams *wm_params, int mi_row, |
| 188 | int mi_col); |
Debargha Mukherjee | 11f0e40 | 2017-03-29 07:42:40 -0700 | [diff] [blame] | 189 | |
Yaowu Xu | 3a19b8a | 2019-05-01 08:40:42 -0700 | [diff] [blame] | 190 | int av1_get_shear_params(WarpedMotionParams *wm); |
James Zern | e1cbb13 | 2018-08-22 14:10:36 -0700 | [diff] [blame] | 191 | #endif // AOM_AV1_COMMON_WARPED_MOTION_H_ |