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 #if AOM_ARCH_ARM || AOM_ARCH_AARCH64 || AOM_ARCH_X86 || AOM_ARCH_X86_64 37 typedef int16_t WarpedFilterCoeff; 38 #else 39 typedef int8_t WarpedFilterCoeff; 40 #endif 41 42 extern const WarpedFilterCoeff 43 av1_warped_filter[WARPEDPIXEL_PREC_SHIFTS * 3 + 1][8]; 44 45 DECLARE_ALIGNED(8, extern const int8_t, 46 av1_filter_8bit[WARPEDPIXEL_PREC_SHIFTS * 3 + 1][8]); 47 48 static const uint8_t warp_pad_left[14][16] = { 49 { 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, 50 { 2, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, 51 { 3, 3, 3, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, 52 { 4, 4, 4, 4, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, 53 { 5, 5, 5, 5, 5, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, 54 { 6, 6, 6, 6, 6, 6, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, 55 { 7, 7, 7, 7, 7, 7, 7, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, 56 { 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 10, 11, 12, 13, 14, 15 }, 57 { 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 11, 12, 13, 14, 15 }, 58 { 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 12, 13, 14, 15 }, 59 { 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 13, 14, 15 }, 60 { 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 14, 15 }, 61 { 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 15 }, 62 { 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15 }, 63 }; 64 65 static const uint8_t warp_pad_right[14][16] = { 66 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 14 }, 67 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 13, 13 }, 68 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12, 12, 12 }, 69 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 11, 11, 11, 11 }, 70 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 10, 10 }, 71 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9, 9, 9, 9, 9 }, 72 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 8, 8, 8 }, 73 { 0, 1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7 }, 74 { 0, 1, 2, 3, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6 }, 75 { 0, 1, 2, 3, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 }, 76 { 0, 1, 2, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 }, 77 { 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 }, 78 { 0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 }, 79 { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } 80 }; 81 82 void highbd_warp_plane(WarpedMotionParams *wm, const uint16_t *const ref, 83 int width, int height, int stride, uint16_t *const pred, 84 int p_col, int p_row, int p_width, int p_height, 85 int p_stride, int subsampling_x, int subsampling_y, 86 int bd, ConvolveParams *conv_params); 87 88 void warp_plane(WarpedMotionParams *wm, const uint8_t *const ref, int width, 89 int height, int stride, uint8_t *pred, int p_col, int p_row, 90 int p_width, int p_height, int p_stride, int subsampling_x, 91 int subsampling_y, ConvolveParams *conv_params); 92 93 void av1_warp_plane(WarpedMotionParams *wm, int use_hbd, int bd, 94 const uint8_t *ref, int width, int height, int stride, 95 uint8_t *pred, int p_col, int p_row, int p_width, 96 int p_height, int p_stride, int subsampling_x, 97 int subsampling_y, ConvolveParams *conv_params); 98 99 int av1_find_projection(int np, const int *pts1, const int *pts2, 100 BLOCK_SIZE bsize, int mvy, int mvx, 101 WarpedMotionParams *wm_params, int mi_row, int mi_col); 102 103 int av1_get_shear_params(WarpedMotionParams *wm); 104 #endif // AOM_AV1_COMMON_WARPED_MOTION_H_ 105