Angie Chiang | 6421191 | 2016-10-25 15:09:56 -0700 | [diff] [blame] | 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 | |
James Zern | e1cbb13 | 2018-08-22 14:10:36 -0700 | [diff] [blame] | 12 | #ifndef AOM_AV1_COMMON_CONVOLVE_H_ |
| 13 | #define AOM_AV1_COMMON_CONVOLVE_H_ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 14 | #include "av1/common/filter.h" |
| 15 | |
| 16 | #ifdef __cplusplus |
| 17 | extern "C" { |
| 18 | #endif |
| 19 | |
Cherma Rajan A | a7be368 | 2018-03-20 10:00:51 +0530 | [diff] [blame] | 20 | typedef uint16_t CONV_BUF_TYPE; |
Angie Chiang | 674bffd | 2017-01-11 16:15:55 -0800 | [diff] [blame] | 21 | typedef struct ConvolveParams { |
David Barker | e64d51a | 2017-06-09 14:52:42 +0100 | [diff] [blame] | 22 | int do_average; |
Angie Chiang | 7927a97 | 2017-02-02 18:13:04 -0800 | [diff] [blame] | 23 | CONV_BUF_TYPE *dst; |
Angie Chiang | f715922 | 2017-01-18 12:51:12 -0800 | [diff] [blame] | 24 | int dst_stride; |
Angie Chiang | 7927a97 | 2017-02-02 18:13:04 -0800 | [diff] [blame] | 25 | int round_0; |
| 26 | int round_1; |
Angie Chiang | e3a4c1c | 2017-02-10 16:26:49 -0800 | [diff] [blame] | 27 | int plane; |
Yunqing Wang | 17be4d8 | 2017-12-19 17:00:27 -0800 | [diff] [blame] | 28 | int is_compound; |
Debargha Mukherjee | 7ac3eb1 | 2018-12-12 10:26:50 -0800 | [diff] [blame] | 29 | int use_dist_wtd_comp_avg; |
Cheng Chen | d867c9a | 2017-10-09 19:03:56 -0700 | [diff] [blame] | 30 | int fwd_offset; |
| 31 | int bck_offset; |
Angie Chiang | 674bffd | 2017-01-11 16:15:55 -0800 | [diff] [blame] | 32 | } ConvolveParams; |
| 33 | |
Debargha Mukherjee | 948f2a9 | 2018-02-18 07:19:26 -0800 | [diff] [blame] | 34 | #define ROUND0_BITS 3 |
Debargha Mukherjee | 648a72b | 2018-02-26 09:09:27 -0800 | [diff] [blame] | 35 | #define COMPOUND_ROUND1_BITS 7 |
Debargha Mukherjee | 9a82a4f | 2018-03-12 14:11:18 -0700 | [diff] [blame] | 36 | #define WIENER_ROUND0_BITS 3 |
Debargha Mukherjee | e820b82 | 2018-02-09 13:18:29 -0800 | [diff] [blame] | 37 | |
Debargha Mukherjee | 9a82a4f | 2018-03-12 14:11:18 -0700 | [diff] [blame] | 38 | #define WIENER_CLAMP_LIMIT(r0, bd) (1 << ((bd) + 1 + FILTER_BITS - r0)) |
Debargha Mukherjee | e6ceeec | 2018-03-11 18:21:52 -0700 | [diff] [blame] | 39 | |
Yunqing Wang | d790c80 | 2017-12-20 17:41:37 -0800 | [diff] [blame] | 40 | typedef void (*aom_convolve_fn_t)(const uint8_t *src, int src_stride, |
Yunqing Wang | 94e3fe3 | 2017-12-22 14:17:44 -0800 | [diff] [blame] | 41 | uint8_t *dst, int dst_stride, int w, int h, |
Peng Bin | 3a0c2ed | 2018-07-19 16:24:00 +0800 | [diff] [blame] | 42 | const InterpFilterParams *filter_params_x, |
| 43 | const InterpFilterParams *filter_params_y, |
Yaowu Xu | 89ed7d4 | 2019-05-08 12:09:27 -0700 | [diff] [blame] | 44 | const int subpel_x_qn, const int subpel_y_qn, |
Yunqing Wang | d790c80 | 2017-12-20 17:41:37 -0800 | [diff] [blame] | 45 | ConvolveParams *conv_params); |
| 46 | |
Cherma Rajan A | 09d4530 | 2018-02-22 17:25:15 +0530 | [diff] [blame] | 47 | typedef void (*aom_highbd_convolve_fn_t)( |
| 48 | const uint16_t *src, int src_stride, uint16_t *dst, int dst_stride, int w, |
Peng Bin | 3a0c2ed | 2018-07-19 16:24:00 +0800 | [diff] [blame] | 49 | int h, const InterpFilterParams *filter_params_x, |
Yaowu Xu | 89ed7d4 | 2019-05-08 12:09:27 -0700 | [diff] [blame] | 50 | const InterpFilterParams *filter_params_y, const int subpel_x_qn, |
| 51 | const int subpel_y_qn, ConvolveParams *conv_params, int bd); |
Cherma Rajan A | 09d4530 | 2018-02-22 17:25:15 +0530 | [diff] [blame] | 52 | |
Angie Chiang | 0a2c0cb | 2017-02-23 14:19:15 -0800 | [diff] [blame] | 53 | struct AV1Common; |
Yunqing Wang | d790c80 | 2017-12-20 17:41:37 -0800 | [diff] [blame] | 54 | struct scale_factors; |
Debargha Mukherjee | 1fc3df5 | 2018-02-13 12:44:52 -0800 | [diff] [blame] | 55 | |
Angie Chiang | 7927a97 | 2017-02-02 18:13:04 -0800 | [diff] [blame] | 56 | void av1_convolve_2d_facade(const uint8_t *src, int src_stride, uint8_t *dst, |
| 57 | int dst_stride, int w, int h, |
Jingning Han | 12d93eb | 2019-10-24 12:12:01 -0700 | [diff] [blame] | 58 | const InterpFilterParams *interp_filters[2], |
Ravi Chaudhary | 1e4f94b | 2019-06-20 16:19:49 +0530 | [diff] [blame] | 59 | const int subpel_x_qn, int x_step_q4, |
| 60 | const int subpel_y_qn, int y_step_q4, int scaled, |
Elliott Karpilovsky | ebe812f | 2020-04-13 18:48:50 -0700 | [diff] [blame] | 61 | ConvolveParams *conv_params); |
Angie Chiang | 7927a97 | 2017-02-02 18:13:04 -0800 | [diff] [blame] | 62 | |
Jingning Han | 1a27d7f | 2019-11-18 10:30:54 -0800 | [diff] [blame] | 63 | static INLINE ConvolveParams get_conv_params_no_round(int cmp_index, int plane, |
Yue Chen | 19d7601 | 2018-02-16 15:13:40 -0800 | [diff] [blame] | 64 | CONV_BUF_TYPE *dst, |
Yunqing Wang | 17be4d8 | 2017-12-19 17:00:27 -0800 | [diff] [blame] | 65 | int dst_stride, |
Debargha Mukherjee | e820b82 | 2018-02-09 13:18:29 -0800 | [diff] [blame] | 66 | int is_compound, int bd) { |
Angie Chiang | 117aa0d | 2017-01-18 15:27:03 -0800 | [diff] [blame] | 67 | ConvolveParams conv_params; |
Jingning Han | 1a27d7f | 2019-11-18 10:30:54 -0800 | [diff] [blame] | 68 | assert(IMPLIES(cmp_index, is_compound)); |
| 69 | |
Yunqing Wang | 17be4d8 | 2017-12-19 17:00:27 -0800 | [diff] [blame] | 70 | conv_params.is_compound = is_compound; |
Jingning Han | 4b592ec | 2020-12-30 16:46:27 -0800 | [diff] [blame] | 71 | conv_params.use_dist_wtd_comp_avg = 0; |
Debargha Mukherjee | e820b82 | 2018-02-09 13:18:29 -0800 | [diff] [blame] | 72 | conv_params.round_0 = ROUND0_BITS; |
Debargha Mukherjee | 1fc3df5 | 2018-02-13 12:44:52 -0800 | [diff] [blame] | 73 | conv_params.round_1 = is_compound ? COMPOUND_ROUND1_BITS |
| 74 | : 2 * FILTER_BITS - conv_params.round_0; |
Debargha Mukherjee | e820b82 | 2018-02-09 13:18:29 -0800 | [diff] [blame] | 75 | const int intbufrange = bd + FILTER_BITS - conv_params.round_0 + 2; |
Debargha Mukherjee | 9a82a4f | 2018-03-12 14:11:18 -0700 | [diff] [blame] | 76 | assert(IMPLIES(bd < 12, intbufrange <= 16)); |
Debargha Mukherjee | e820b82 | 2018-02-09 13:18:29 -0800 | [diff] [blame] | 77 | if (intbufrange > 16) { |
| 78 | conv_params.round_0 += intbufrange - 16; |
Debargha Mukherjee | 9a65bb0 | 2018-03-01 10:35:03 -0800 | [diff] [blame] | 79 | if (!is_compound) conv_params.round_1 -= intbufrange - 16; |
Debargha Mukherjee | e820b82 | 2018-02-09 13:18:29 -0800 | [diff] [blame] | 80 | } |
Yunqing Wang | 17be4d8 | 2017-12-19 17:00:27 -0800 | [diff] [blame] | 81 | // TODO(yunqing): The following dst should only be valid while |
| 82 | // is_compound = 1; |
Angie Chiang | 117aa0d | 2017-01-18 15:27:03 -0800 | [diff] [blame] | 83 | conv_params.dst = dst; |
| 84 | conv_params.dst_stride = dst_stride; |
Angie Chiang | e3a4c1c | 2017-02-10 16:26:49 -0800 | [diff] [blame] | 85 | conv_params.plane = plane; |
Jingning Han | 1a27d7f | 2019-11-18 10:30:54 -0800 | [diff] [blame] | 86 | |
| 87 | // By default, set do average to 1 if this is the second single prediction |
| 88 | // in a compound mode. |
| 89 | conv_params.do_average = cmp_index; |
Angie Chiang | 117aa0d | 2017-01-18 15:27:03 -0800 | [diff] [blame] | 90 | return conv_params; |
| 91 | } |
| 92 | |
Peng Bin | f7b11f5 | 2018-08-09 17:29:39 +0800 | [diff] [blame] | 93 | static INLINE ConvolveParams get_conv_params(int do_average, int plane, |
Debargha Mukherjee | 1fc3df5 | 2018-02-13 12:44:52 -0800 | [diff] [blame] | 94 | int bd) { |
Peng Bin | f7b11f5 | 2018-08-09 17:29:39 +0800 | [diff] [blame] | 95 | return get_conv_params_no_round(do_average, plane, NULL, 0, 0, bd); |
Debargha Mukherjee | 1fc3df5 | 2018-02-13 12:44:52 -0800 | [diff] [blame] | 96 | } |
| 97 | |
Debargha Mukherjee | 2697139 | 2018-03-12 08:20:46 -0700 | [diff] [blame] | 98 | static INLINE ConvolveParams get_conv_params_wiener(int bd) { |
| 99 | ConvolveParams conv_params; |
| 100 | (void)bd; |
Debargha Mukherjee | 2697139 | 2018-03-12 08:20:46 -0700 | [diff] [blame] | 101 | conv_params.do_average = 0; |
| 102 | conv_params.is_compound = 0; |
| 103 | conv_params.round_0 = WIENER_ROUND0_BITS; |
Debargha Mukherjee | 9a82a4f | 2018-03-12 14:11:18 -0700 | [diff] [blame] | 104 | conv_params.round_1 = 2 * FILTER_BITS - conv_params.round_0; |
| 105 | const int intbufrange = bd + FILTER_BITS - conv_params.round_0 + 2; |
| 106 | assert(IMPLIES(bd < 12, intbufrange <= 16)); |
| 107 | if (intbufrange > 16) { |
| 108 | conv_params.round_0 += intbufrange - 16; |
| 109 | conv_params.round_1 -= intbufrange - 16; |
| 110 | } |
Debargha Mukherjee | 2697139 | 2018-03-12 08:20:46 -0700 | [diff] [blame] | 111 | conv_params.dst = NULL; |
| 112 | conv_params.dst_stride = 0; |
| 113 | conv_params.plane = 0; |
| 114 | return conv_params; |
| 115 | } |
| 116 | |
Angie Chiang | b03545b | 2017-05-05 12:07:30 -0700 | [diff] [blame] | 117 | void av1_highbd_convolve_2d_facade(const uint8_t *src8, int src_stride, |
| 118 | uint8_t *dst, int dst_stride, int w, int h, |
Jingning Han | 12d93eb | 2019-10-24 12:12:01 -0700 | [diff] [blame] | 119 | const InterpFilterParams *interp_filters[2], |
Yaowu Xu | 89ed7d4 | 2019-05-08 12:09:27 -0700 | [diff] [blame] | 120 | const int subpel_x_qn, int x_step_q4, |
| 121 | const int subpel_y_qn, int y_step_q4, |
Debargha Mukherjee | 9c5b108 | 2017-08-14 10:46:51 -0700 | [diff] [blame] | 122 | int scaled, ConvolveParams *conv_params, |
Elliott Karpilovsky | ebe812f | 2020-04-13 18:48:50 -0700 | [diff] [blame] | 123 | int bd); |
Angie Chiang | 117aa0d | 2017-01-18 15:27:03 -0800 | [diff] [blame] | 124 | |
Sarah Parker | 0115e93 | 2018-10-22 14:14:22 -0700 | [diff] [blame] | 125 | // TODO(sarahparker) This will need to be integerized and optimized |
| 126 | void av1_convolve_2d_sobel_y_c(const uint8_t *src, int src_stride, double *dst, |
| 127 | int dst_stride, int w, int h, int dir, |
| 128 | double norm); |
| 129 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 130 | #ifdef __cplusplus |
| 131 | } // extern "C" |
| 132 | #endif |
| 133 | |
James Zern | e1cbb13 | 2018-08-22 14:10:36 -0700 | [diff] [blame] | 134 | #endif // AOM_AV1_COMMON_CONVOLVE_H_ |