Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [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 | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [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 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 12 | #ifndef AV1_COMMON_MV_H_ |
| 13 | #define AV1_COMMON_MV_H_ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 14 | |
| 15 | #include "av1/common/common.h" |
Sarah Parker | ae7c458 | 2017-02-28 16:30:30 -0800 | [diff] [blame] | 16 | #include "av1/common/common_data.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 17 | #include "aom_dsp/aom_filter.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 18 | |
| 19 | #ifdef __cplusplus |
| 20 | extern "C" { |
| 21 | #endif |
| 22 | |
| 23 | typedef struct mv { |
| 24 | int16_t row; |
| 25 | int16_t col; |
| 26 | } MV; |
| 27 | |
| 28 | typedef union int_mv { |
| 29 | uint32_t as_int; |
| 30 | MV as_mv; |
| 31 | } int_mv; /* facilitates faster equality tests and copies */ |
| 32 | |
| 33 | typedef struct mv32 { |
| 34 | int32_t row; |
| 35 | int32_t col; |
| 36 | } MV32; |
| 37 | |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 38 | #if CONFIG_WARPED_MOTION |
| 39 | #define WARPED_MOTION_SORT_SAMPLES 1 |
| 40 | #endif // CONFIG_WARPED_MOTION |
| 41 | |
Sarah Parker | e529986 | 2016-08-16 14:57:37 -0700 | [diff] [blame] | 42 | #if CONFIG_GLOBAL_MOTION || CONFIG_WARPED_MOTION |
| 43 | // Bits of precision used for the model |
Debargha Mukherjee | 3a50db4 | 2016-12-06 15:20:03 -0800 | [diff] [blame] | 44 | #define WARPEDMODEL_PREC_BITS 16 |
| 45 | #define WARPEDMODEL_ROW3HOMO_PREC_BITS 16 |
Sarah Parker | e529986 | 2016-08-16 14:57:37 -0700 | [diff] [blame] | 46 | |
Debargha Mukherjee | 1e6e130 | 2017-04-07 15:27:53 -0700 | [diff] [blame] | 47 | #define WARPEDMODEL_TRANS_CLAMP (128 << WARPEDMODEL_PREC_BITS) |
Debargha Mukherjee | f053cba | 2017-06-21 19:04:00 -0700 | [diff] [blame] | 48 | #define WARPEDMODEL_NONDIAGAFFINE_CLAMP (1 << (WARPEDMODEL_PREC_BITS - 3)) |
| 49 | #define WARPEDMODEL_ROW3HOMO_CLAMP (1 << (WARPEDMODEL_PREC_BITS - 2)) |
Debargha Mukherjee | 1e6e130 | 2017-04-07 15:27:53 -0700 | [diff] [blame] | 50 | |
Sarah Parker | e529986 | 2016-08-16 14:57:37 -0700 | [diff] [blame] | 51 | // Bits of subpel precision for warped interpolation |
| 52 | #define WARPEDPIXEL_PREC_BITS 6 |
| 53 | #define WARPEDPIXEL_PREC_SHIFTS (1 << WARPEDPIXEL_PREC_BITS) |
| 54 | |
| 55 | // Taps for ntap filter |
| 56 | #define WARPEDPIXEL_FILTER_TAPS 6 |
| 57 | |
| 58 | // Precision of filter taps |
| 59 | #define WARPEDPIXEL_FILTER_BITS 7 |
| 60 | |
Sean Purser-Haskell | 14b8112 | 2017-05-03 16:50:07 -0700 | [diff] [blame] | 61 | #define WARP_PARAM_REDUCE_BITS 6 |
| 62 | |
Debargha Mukherjee | 1d18460 | 2017-04-04 04:54:07 -0700 | [diff] [blame] | 63 | // Precision bits reduction after horizontal shear |
| 64 | #define HORSHEAR_REDUCE_PREC_BITS 5 |
| 65 | #define VERSHEAR_REDUCE_PREC_BITS \ |
| 66 | (2 * WARPEDPIXEL_FILTER_BITS - HORSHEAR_REDUCE_PREC_BITS) |
| 67 | |
Sarah Parker | e529986 | 2016-08-16 14:57:37 -0700 | [diff] [blame] | 68 | #define WARPEDDIFF_PREC_BITS (WARPEDMODEL_PREC_BITS - WARPEDPIXEL_PREC_BITS) |
| 69 | |
David Barker | cf3d0b0 | 2016-11-10 10:14:49 +0000 | [diff] [blame] | 70 | /* clang-format off */ |
Sarah Parker | e529986 | 2016-08-16 14:57:37 -0700 | [diff] [blame] | 71 | typedef enum { |
Debargha Mukherjee | 5dfa930 | 2017-02-10 05:00:08 -0800 | [diff] [blame] | 72 | IDENTITY = 0, // identity transformation, 0-parameter |
| 73 | TRANSLATION = 1, // translational motion 2-parameter |
| 74 | ROTZOOM = 2, // simplified affine with rotation + zoom only, 4-parameter |
| 75 | AFFINE = 3, // affine, 6-parameter |
| 76 | HORTRAPEZOID = 4, // constrained homography, hor trapezoid, 6-parameter |
| 77 | VERTRAPEZOID = 5, // constrained homography, ver trapezoid, 6-parameter |
| 78 | HOMOGRAPHY = 6, // homography, 8-parameter |
| 79 | TRANS_TYPES = 7, |
Sarah Parker | e529986 | 2016-08-16 14:57:37 -0700 | [diff] [blame] | 80 | } TransformationType; |
David Barker | cf3d0b0 | 2016-11-10 10:14:49 +0000 | [diff] [blame] | 81 | /* clang-format on */ |
| 82 | |
Debargha Mukherjee | b0f6bd4 | 2016-12-02 09:19:39 -0800 | [diff] [blame] | 83 | // Number of types used for global motion (must be >= 3 and <= TRANS_TYPES) |
Debargha Mukherjee | 5dfa930 | 2017-02-10 05:00:08 -0800 | [diff] [blame] | 84 | // The following can be useful: |
| 85 | // GLOBAL_TRANS_TYPES 3 - up to rotation-zoom |
| 86 | // GLOBAL_TRANS_TYPES 4 - up to affine |
| 87 | // GLOBAL_TRANS_TYPES 6 - up to hor/ver trapezoids |
| 88 | // GLOBAL_TRANS_TYPES 7 - up to full homography |
Debargha Mukherjee | 5f35e58 | 2017-04-25 18:05:18 -0700 | [diff] [blame] | 89 | #define GLOBAL_TRANS_TYPES 4 |
Sarah Parker | e529986 | 2016-08-16 14:57:37 -0700 | [diff] [blame] | 90 | |
Thomas Davies | b732c1e | 2017-06-09 14:13:43 +0100 | [diff] [blame] | 91 | // First bit indicates whether using identity or not |
| 92 | // GLOBAL_TYPE_BITS=ceiling(log2(GLOBAL_TRANS_TYPES-1)) is the |
| 93 | // number of bits needed to cover the remaining possibilities |
| 94 | #define GLOBAL_TYPE_BITS (get_msb(2 * GLOBAL_TRANS_TYPES - 3)) |
| 95 | |
Sarah Parker | 4c10a3c | 2017-04-10 19:37:59 -0700 | [diff] [blame] | 96 | typedef struct { |
| 97 | #if CONFIG_GLOBAL_MOTION |
| 98 | int global_warp_allowed; |
| 99 | #endif // CONFIG_GLOBAL_MOTION |
| 100 | #if CONFIG_WARPED_MOTION |
| 101 | int local_warp_allowed; |
| 102 | #endif // CONFIG_WARPED_MOTION |
| 103 | } WarpTypesAllowed; |
| 104 | |
Sarah Parker | e529986 | 2016-08-16 14:57:37 -0700 | [diff] [blame] | 105 | // number of parameters used by each transformation in TransformationTypes |
Debargha Mukherjee | 5dfa930 | 2017-02-10 05:00:08 -0800 | [diff] [blame] | 106 | static const int trans_model_params[TRANS_TYPES] = { 0, 2, 4, 6, 6, 6, 8 }; |
Sarah Parker | e529986 | 2016-08-16 14:57:37 -0700 | [diff] [blame] | 107 | |
Debargha Mukherjee | 8db4c77 | 2016-11-07 12:54:21 -0800 | [diff] [blame] | 108 | // The order of values in the wmmat matrix below is best described |
| 109 | // by the homography: |
Debargha Mukherjee | 5dfa930 | 2017-02-10 05:00:08 -0800 | [diff] [blame] | 110 | // [x' (m2 m3 m0 [x |
| 111 | // z . y' = m4 m5 m1 * y |
| 112 | // 1] m6 m7 1) 1] |
Sarah Parker | e529986 | 2016-08-16 14:57:37 -0700 | [diff] [blame] | 113 | typedef struct { |
| 114 | TransformationType wmtype; |
David Barker | cf3d0b0 | 2016-11-10 10:14:49 +0000 | [diff] [blame] | 115 | int32_t wmmat[8]; |
Debargha Mukherjee | 27f6e66 | 2017-04-10 11:17:16 -0700 | [diff] [blame] | 116 | int16_t alpha, beta, gamma, delta; |
Sarah Parker | e529986 | 2016-08-16 14:57:37 -0700 | [diff] [blame] | 117 | } WarpedMotionParams; |
Sarah Parker | 4c10a3c | 2017-04-10 19:37:59 -0700 | [diff] [blame] | 118 | |
| 119 | static INLINE void set_default_warp_params(WarpedMotionParams *wm) { |
| 120 | static const int32_t default_wm_mat[8] = { |
| 121 | 0, 0, (1 << WARPEDMODEL_PREC_BITS), 0, 0, (1 << WARPEDMODEL_PREC_BITS), 0, 0 |
| 122 | }; |
| 123 | memset(wm, 0, sizeof(*wm)); |
| 124 | memcpy(wm->wmmat, default_wm_mat, sizeof(wm->wmmat)); |
| 125 | wm->wmtype = IDENTITY; |
| 126 | } |
Sarah Parker | e529986 | 2016-08-16 14:57:37 -0700 | [diff] [blame] | 127 | #endif // CONFIG_GLOBAL_MOTION || CONFIG_WARPED_MOTION |
| 128 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 129 | #if CONFIG_GLOBAL_MOTION |
Sarah Parker | f7ab7e3 | 2017-04-26 12:23:56 -0700 | [diff] [blame] | 130 | // The following constants describe the various precisions |
| 131 | // of different parameters in the global motion experiment. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 132 | // |
Sarah Parker | f7ab7e3 | 2017-04-26 12:23:56 -0700 | [diff] [blame] | 133 | // Given the general homography: |
| 134 | // [x' (a b c [x |
| 135 | // z . y' = d e f * y |
| 136 | // 1] g h i) 1] |
| 137 | // |
| 138 | // Constants using the name ALPHA here are related to parameters |
| 139 | // a, b, d, e. Constants using the name TRANS are related |
| 140 | // to parameters c and f. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 141 | // |
| 142 | // Anything ending in PREC_BITS is the number of bits of precision |
| 143 | // to maintain when converting from double to integer. |
| 144 | // |
| 145 | // The ABS parameters are used to create an upper and lower bound |
| 146 | // for each parameter. In other words, after a parameter is integerized |
| 147 | // it is clamped between -(1 << ABS_XXX_BITS) and (1 << ABS_XXX_BITS). |
| 148 | // |
| 149 | // XXX_PREC_DIFF and XXX_DECODE_FACTOR |
| 150 | // are computed once here to prevent repetitive |
| 151 | // computation on the decoder side. These are |
| 152 | // to allow the global motion parameters to be encoded in a lower |
| 153 | // precision than the warped model precision. This means that they |
| 154 | // need to be changed to warped precision when they are decoded. |
| 155 | // |
| 156 | // XX_MIN, XX_MAX are also computed to avoid repeated computation |
| 157 | |
Sarah Parker | f178329 | 2017-04-05 11:55:27 -0700 | [diff] [blame] | 158 | #define SUBEXPFIN_K 3 |
David Barker | 6c65278 | 2017-02-13 13:46:40 +0000 | [diff] [blame] | 159 | #define GM_TRANS_PREC_BITS 6 |
| 160 | #define GM_ABS_TRANS_BITS 12 |
Sarah Parker | 13d0662 | 2017-03-10 17:03:28 -0800 | [diff] [blame] | 161 | #define GM_ABS_TRANS_ONLY_BITS (GM_ABS_TRANS_BITS - GM_TRANS_PREC_BITS + 3) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 162 | #define GM_TRANS_PREC_DIFF (WARPEDMODEL_PREC_BITS - GM_TRANS_PREC_BITS) |
Sarah Parker | 13d0662 | 2017-03-10 17:03:28 -0800 | [diff] [blame] | 163 | #define GM_TRANS_ONLY_PREC_DIFF (WARPEDMODEL_PREC_BITS - 3) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 164 | #define GM_TRANS_DECODE_FACTOR (1 << GM_TRANS_PREC_DIFF) |
Sarah Parker | 13d0662 | 2017-03-10 17:03:28 -0800 | [diff] [blame] | 165 | #define GM_TRANS_ONLY_DECODE_FACTOR (1 << GM_TRANS_ONLY_PREC_DIFF) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 166 | |
Debargha Mukherjee | 3a50db4 | 2016-12-06 15:20:03 -0800 | [diff] [blame] | 167 | #define GM_ALPHA_PREC_BITS 15 |
| 168 | #define GM_ABS_ALPHA_BITS 12 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 169 | #define GM_ALPHA_PREC_DIFF (WARPEDMODEL_PREC_BITS - GM_ALPHA_PREC_BITS) |
| 170 | #define GM_ALPHA_DECODE_FACTOR (1 << GM_ALPHA_PREC_DIFF) |
| 171 | |
Debargha Mukherjee | 3a50db4 | 2016-12-06 15:20:03 -0800 | [diff] [blame] | 172 | #define GM_ROW3HOMO_PREC_BITS 16 |
| 173 | #define GM_ABS_ROW3HOMO_BITS 11 |
Debargha Mukherjee | 8db4c77 | 2016-11-07 12:54:21 -0800 | [diff] [blame] | 174 | #define GM_ROW3HOMO_PREC_DIFF \ |
| 175 | (WARPEDMODEL_ROW3HOMO_PREC_BITS - GM_ROW3HOMO_PREC_BITS) |
| 176 | #define GM_ROW3HOMO_DECODE_FACTOR (1 << GM_ROW3HOMO_PREC_DIFF) |
| 177 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 178 | #define GM_TRANS_MAX (1 << GM_ABS_TRANS_BITS) |
| 179 | #define GM_ALPHA_MAX (1 << GM_ABS_ALPHA_BITS) |
Debargha Mukherjee | 8db4c77 | 2016-11-07 12:54:21 -0800 | [diff] [blame] | 180 | #define GM_ROW3HOMO_MAX (1 << GM_ABS_ROW3HOMO_BITS) |
| 181 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 182 | #define GM_TRANS_MIN -GM_TRANS_MAX |
| 183 | #define GM_ALPHA_MIN -GM_ALPHA_MAX |
Debargha Mukherjee | 8db4c77 | 2016-11-07 12:54:21 -0800 | [diff] [blame] | 184 | #define GM_ROW3HOMO_MIN -GM_ROW3HOMO_MAX |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 185 | |
Sarah Parker | ae7c458 | 2017-02-28 16:30:30 -0800 | [diff] [blame] | 186 | // Use global motion parameters for sub8x8 blocks |
| 187 | #define GLOBAL_SUB8X8_USED 0 |
| 188 | |
| 189 | static INLINE int block_center_x(int mi_col, BLOCK_SIZE bs) { |
| 190 | const int bw = block_size_wide[bs]; |
Debargha Mukherjee | 07b1d38 | 2017-03-24 08:54:26 -0700 | [diff] [blame] | 191 | return mi_col * MI_SIZE + bw / 2 - 1; |
Sarah Parker | ae7c458 | 2017-02-28 16:30:30 -0800 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | static INLINE int block_center_y(int mi_row, BLOCK_SIZE bs) { |
| 195 | const int bh = block_size_high[bs]; |
Debargha Mukherjee | 07b1d38 | 2017-03-24 08:54:26 -0700 | [diff] [blame] | 196 | return mi_row * MI_SIZE + bh / 2 - 1; |
Sarah Parker | ae7c458 | 2017-02-28 16:30:30 -0800 | [diff] [blame] | 197 | } |
| 198 | |
Sarah Parker | 13d0662 | 2017-03-10 17:03:28 -0800 | [diff] [blame] | 199 | static INLINE int convert_to_trans_prec(int allow_hp, int coor) { |
Yaowu Xu | f9d15b6 | 2017-05-01 15:14:10 -0700 | [diff] [blame] | 200 | if (allow_hp) |
| 201 | return ROUND_POWER_OF_TWO_SIGNED(coor, WARPEDMODEL_PREC_BITS - 3); |
| 202 | else |
| 203 | return ROUND_POWER_OF_TWO_SIGNED(coor, WARPEDMODEL_PREC_BITS - 2) * 2; |
Sarah Parker | 13d0662 | 2017-03-10 17:03:28 -0800 | [diff] [blame] | 204 | } |
| 205 | |
Debargha Mukherjee | 5f30585 | 2016-11-03 15:47:21 -0700 | [diff] [blame] | 206 | // Convert a global motion translation vector (which may have more bits than a |
| 207 | // regular motion vector) into a motion vector |
David Barker | cdcac6d | 2016-12-01 17:04:16 +0000 | [diff] [blame] | 208 | static INLINE int_mv gm_get_motion_vector(const WarpedMotionParams *gm, |
Sarah Parker | ae7c458 | 2017-02-28 16:30:30 -0800 | [diff] [blame] | 209 | int allow_hp, BLOCK_SIZE bsize, |
Debargha Mukherjee | febb59c | 2017-03-02 12:23:45 -0800 | [diff] [blame] | 210 | int mi_col, int mi_row, |
| 211 | int block_idx) { |
| 212 | const int unify_bsize = CONFIG_CB4X4; |
Debargha Mukherjee | 5f30585 | 2016-11-03 15:47:21 -0700 | [diff] [blame] | 213 | int_mv res; |
David Barker | 45390c1 | 2017-02-20 14:44:40 +0000 | [diff] [blame] | 214 | const int32_t *mat = gm->wmmat; |
Debargha Mukherjee | 552b0b2 | 2017-05-01 15:29:16 -0700 | [diff] [blame] | 215 | int x, y, tx, ty; |
Sarah Parker | 13d0662 | 2017-03-10 17:03:28 -0800 | [diff] [blame] | 216 | |
| 217 | if (gm->wmtype == TRANSLATION) { |
| 218 | res.as_mv.row = gm->wmmat[0] >> GM_TRANS_ONLY_PREC_DIFF; |
| 219 | res.as_mv.col = gm->wmmat[1] >> GM_TRANS_ONLY_PREC_DIFF; |
| 220 | return res; |
| 221 | } |
| 222 | |
Debargha Mukherjee | febb59c | 2017-03-02 12:23:45 -0800 | [diff] [blame] | 223 | if (bsize >= BLOCK_8X8 || unify_bsize) { |
| 224 | x = block_center_x(mi_col, bsize); |
| 225 | y = block_center_y(mi_row, bsize); |
| 226 | } else { |
| 227 | x = block_center_x(mi_col, bsize); |
| 228 | y = block_center_y(mi_row, bsize); |
| 229 | x += (block_idx & 1) * MI_SIZE / 2; |
| 230 | y += (block_idx & 2) * MI_SIZE / 4; |
| 231 | } |
David Barker | 45390c1 | 2017-02-20 14:44:40 +0000 | [diff] [blame] | 232 | |
| 233 | if (gm->wmtype == ROTZOOM) { |
| 234 | assert(gm->wmmat[5] == gm->wmmat[2]); |
| 235 | assert(gm->wmmat[4] == -gm->wmmat[3]); |
| 236 | } |
Debargha Mukherjee | f6dd3c6 | 2017-02-23 13:21:23 -0800 | [diff] [blame] | 237 | if (gm->wmtype > AFFINE) { |
Debargha Mukherjee | 552b0b2 | 2017-05-01 15:29:16 -0700 | [diff] [blame] | 238 | int xc = (int)((int64_t)mat[2] * x + (int64_t)mat[3] * y + mat[0]); |
| 239 | int yc = (int)((int64_t)mat[4] * x + (int64_t)mat[5] * y + mat[1]); |
| 240 | const int Z = (int)((int64_t)mat[6] * x + (int64_t)mat[7] * y + |
| 241 | (1 << WARPEDMODEL_ROW3HOMO_PREC_BITS)); |
| 242 | xc *= 1 << (WARPEDMODEL_ROW3HOMO_PREC_BITS - WARPEDMODEL_PREC_BITS); |
| 243 | yc *= 1 << (WARPEDMODEL_ROW3HOMO_PREC_BITS - WARPEDMODEL_PREC_BITS); |
| 244 | xc = (int)(xc > 0 ? ((int64_t)xc + Z / 2) / Z : ((int64_t)xc - Z / 2) / Z); |
| 245 | yc = (int)(yc > 0 ? ((int64_t)yc + Z / 2) / Z : ((int64_t)yc - Z / 2) / Z); |
| 246 | tx = convert_to_trans_prec(allow_hp, xc) - (x << 3); |
| 247 | ty = convert_to_trans_prec(allow_hp, yc) - (y << 3); |
| 248 | } else { |
| 249 | const int xc = |
| 250 | (mat[2] - (1 << WARPEDMODEL_PREC_BITS)) * x + mat[3] * y + mat[0]; |
| 251 | const int yc = |
| 252 | mat[4] * x + (mat[5] - (1 << WARPEDMODEL_PREC_BITS)) * y + mat[1]; |
| 253 | tx = convert_to_trans_prec(allow_hp, xc); |
| 254 | ty = convert_to_trans_prec(allow_hp, yc); |
Debargha Mukherjee | f6dd3c6 | 2017-02-23 13:21:23 -0800 | [diff] [blame] | 255 | } |
| 256 | |
David Barker | 45390c1 | 2017-02-20 14:44:40 +0000 | [diff] [blame] | 257 | res.as_mv.row = ty; |
| 258 | res.as_mv.col = tx; |
Debargha Mukherjee | 5f30585 | 2016-11-03 15:47:21 -0700 | [diff] [blame] | 259 | return res; |
| 260 | } |
| 261 | |
David Barker | cf3d0b0 | 2016-11-10 10:14:49 +0000 | [diff] [blame] | 262 | static INLINE TransformationType get_gmtype(const WarpedMotionParams *gm) { |
Debargha Mukherjee | 5dfa930 | 2017-02-10 05:00:08 -0800 | [diff] [blame] | 263 | if (gm->wmmat[6] != 0 || gm->wmmat[7] != 0) { |
| 264 | if (!gm->wmmat[6] && !gm->wmmat[4]) return HORTRAPEZOID; |
| 265 | if (!gm->wmmat[7] && !gm->wmmat[3]) return VERTRAPEZOID; |
| 266 | return HOMOGRAPHY; |
| 267 | } |
David Barker | cf3d0b0 | 2016-11-10 10:14:49 +0000 | [diff] [blame] | 268 | if (gm->wmmat[5] == (1 << WARPEDMODEL_PREC_BITS) && !gm->wmmat[4] && |
| 269 | gm->wmmat[2] == (1 << WARPEDMODEL_PREC_BITS) && !gm->wmmat[3]) { |
| 270 | return ((!gm->wmmat[1] && !gm->wmmat[0]) ? IDENTITY : TRANSLATION); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 271 | } |
David Barker | cf3d0b0 | 2016-11-10 10:14:49 +0000 | [diff] [blame] | 272 | if (gm->wmmat[2] == gm->wmmat[5] && gm->wmmat[3] == -gm->wmmat[4]) |
| 273 | return ROTZOOM; |
Debargha Mukherjee | 8db4c77 | 2016-11-07 12:54:21 -0800 | [diff] [blame] | 274 | else |
David Barker | cf3d0b0 | 2016-11-10 10:14:49 +0000 | [diff] [blame] | 275 | return AFFINE; |
Debargha Mukherjee | 8db4c77 | 2016-11-07 12:54:21 -0800 | [diff] [blame] | 276 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 277 | #endif // CONFIG_GLOBAL_MOTION |
| 278 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 279 | typedef struct candidate_mv { |
| 280 | int_mv this_mv; |
| 281 | int_mv comp_mv; |
Jingning Han | 3f33883 | 2016-11-18 11:01:48 -0800 | [diff] [blame] | 282 | uint8_t pred_diff[2]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 283 | int weight; |
| 284 | } CANDIDATE_MV; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 285 | |
| 286 | static INLINE int is_zero_mv(const MV *mv) { |
| 287 | return *((const uint32_t *)mv) == 0; |
| 288 | } |
| 289 | |
| 290 | static INLINE int is_equal_mv(const MV *a, const MV *b) { |
| 291 | return *((const uint32_t *)a) == *((const uint32_t *)b); |
| 292 | } |
| 293 | |
| 294 | static INLINE void clamp_mv(MV *mv, int min_col, int max_col, int min_row, |
| 295 | int max_row) { |
| 296 | mv->col = clamp(mv->col, min_col, max_col); |
| 297 | mv->row = clamp(mv->row, min_row, max_row); |
| 298 | } |
| 299 | |
| 300 | static INLINE int mv_has_subpel(const MV *mv) { |
| 301 | return (mv->row & SUBPEL_MASK) || (mv->col & SUBPEL_MASK); |
| 302 | } |
| 303 | #ifdef __cplusplus |
| 304 | } // extern "C" |
| 305 | #endif |
| 306 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 307 | #endif // AV1_COMMON_MV_H_ |