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 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 12 | #ifndef AV1_COMMON_AV1_CONVOLVE_H_ |
| 13 | #define AV1_COMMON_AV1_CONVOLVE_H_ |
| 14 | #include "av1/common/filter.h" |
| 15 | |
| 16 | #ifdef __cplusplus |
| 17 | extern "C" { |
| 18 | #endif |
| 19 | |
Angie Chiang | 9f45bc4 | 2017-01-13 16:27:54 -0800 | [diff] [blame] | 20 | typedef enum CONVOLVE_OPT { |
| 21 | // indicate the results in dst buf is rounded by FILTER_BITS or not |
| 22 | CONVOLVE_OPT_ROUND, |
| 23 | CONVOLVE_OPT_NO_ROUND, |
| 24 | } CONVOLVE_OPT; |
| 25 | |
Angie Chiang | 7927a97 | 2017-02-02 18:13:04 -0800 | [diff] [blame] | 26 | typedef int32_t CONV_BUF_TYPE; |
| 27 | |
Angie Chiang | 674bffd | 2017-01-11 16:15:55 -0800 | [diff] [blame] | 28 | typedef struct ConvolveParams { |
| 29 | int ref; |
David Barker | e64d51a | 2017-06-09 14:52:42 +0100 | [diff] [blame] | 30 | int do_average; |
Angie Chiang | 9f45bc4 | 2017-01-13 16:27:54 -0800 | [diff] [blame] | 31 | CONVOLVE_OPT round; |
Angie Chiang | 7927a97 | 2017-02-02 18:13:04 -0800 | [diff] [blame] | 32 | CONV_BUF_TYPE *dst; |
Angie Chiang | f715922 | 2017-01-18 12:51:12 -0800 | [diff] [blame] | 33 | int dst_stride; |
Angie Chiang | 7927a97 | 2017-02-02 18:13:04 -0800 | [diff] [blame] | 34 | int round_0; |
| 35 | int round_1; |
Angie Chiang | e3a4c1c | 2017-02-10 16:26:49 -0800 | [diff] [blame] | 36 | int plane; |
Angie Chiang | 05685e9 | 2017-05-08 12:55:39 -0700 | [diff] [blame] | 37 | int do_post_rounding; |
Yunqing Wang | 17be4d8 | 2017-12-19 17:00:27 -0800 | [diff] [blame] | 38 | int is_compound; |
Cheng Chen | d867c9a | 2017-10-09 19:03:56 -0700 | [diff] [blame] | 39 | #if CONFIG_JNT_COMP |
Cheng Chen | 8263f80 | 2017-11-14 15:50:00 -0800 | [diff] [blame] | 40 | int use_jnt_comp_avg; |
Cheng Chen | d867c9a | 2017-10-09 19:03:56 -0700 | [diff] [blame] | 41 | int fwd_offset; |
| 42 | int bck_offset; |
| 43 | #endif |
Angie Chiang | 674bffd | 2017-01-11 16:15:55 -0800 | [diff] [blame] | 44 | } ConvolveParams; |
| 45 | |
Debargha Mukherjee | 948f2a9 | 2018-02-18 07:19:26 -0800 | [diff] [blame] | 46 | #if CONFIG_LOWPRECISION_BLEND |
| 47 | #define ROUND0_BITS 3 |
| 48 | #define COMPOUND_ROUND1_BITS (5 + CONFIG_LOWPRECISION_BLEND) |
Debargha Mukherjee | e820b82 | 2018-02-09 13:18:29 -0800 | [diff] [blame] | 49 | #else |
Debargha Mukherjee | 948f2a9 | 2018-02-18 07:19:26 -0800 | [diff] [blame] | 50 | #define ROUND0_BITS 5 |
Debargha Mukherjee | e820b82 | 2018-02-09 13:18:29 -0800 | [diff] [blame] | 51 | #define COMPOUND_ROUND1_BITS 0 |
| 52 | #endif // CONFIG_LOWPRECISION_BLEND |
| 53 | |
Yunqing Wang | d790c80 | 2017-12-20 17:41:37 -0800 | [diff] [blame] | 54 | 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] | 55 | uint8_t *dst, int dst_stride, int w, int h, |
| 56 | InterpFilterParams *filter_params_x, |
Yunqing Wang | d790c80 | 2017-12-20 17:41:37 -0800 | [diff] [blame] | 57 | InterpFilterParams *filter_params_y, |
| 58 | const int subpel_x_q4, const int subpel_y_q4, |
| 59 | ConvolveParams *conv_params); |
| 60 | |
Zhijie Yang | f02f8ae | 2017-10-26 17:58:29 -0700 | [diff] [blame] | 61 | static INLINE void av1_get_convolve_filter_params(InterpFilters interp_filters, |
Zhijie Yang | f02f8ae | 2017-10-26 17:58:29 -0700 | [diff] [blame] | 62 | InterpFilterParams *params_x, |
| 63 | InterpFilterParams *params_y |
| 64 | #if CONFIG_SHORT_FILTER |
| 65 | , |
| 66 | int w, int h |
| 67 | #endif |
Johann | 6b41d4d | 2018-02-08 14:32:53 -0800 | [diff] [blame] | 68 | ) { |
Rupert Swarbrick | 27e9029 | 2017-09-28 17:46:50 +0100 | [diff] [blame] | 69 | #if CONFIG_DUAL_FILTER |
| 70 | InterpFilter filter_x = av1_extract_interp_filter(interp_filters, 1); |
| 71 | InterpFilter filter_y = av1_extract_interp_filter(interp_filters, 0); |
| 72 | #else |
| 73 | InterpFilter filter_x = av1_extract_interp_filter(interp_filters, 0); |
| 74 | InterpFilter filter_y = av1_extract_interp_filter(interp_filters, 0); |
| 75 | #endif |
Zhijie Yang | f02f8ae | 2017-10-26 17:58:29 -0700 | [diff] [blame] | 76 | #if CONFIG_SHORT_FILTER |
| 77 | *params_x = av1_get_interp_filter_params_with_block_size(filter_x, w); |
| 78 | *params_y = av1_get_interp_filter_params_with_block_size(filter_y, h); |
| 79 | #else |
Rupert Swarbrick | 27e9029 | 2017-09-28 17:46:50 +0100 | [diff] [blame] | 80 | *params_x = av1_get_interp_filter_params(filter_x); |
| 81 | *params_y = av1_get_interp_filter_params(filter_y); |
Zhijie Yang | f02f8ae | 2017-10-26 17:58:29 -0700 | [diff] [blame] | 82 | #endif |
Rupert Swarbrick | 27e9029 | 2017-09-28 17:46:50 +0100 | [diff] [blame] | 83 | } |
| 84 | |
Angie Chiang | 0a2c0cb | 2017-02-23 14:19:15 -0800 | [diff] [blame] | 85 | struct AV1Common; |
Yunqing Wang | d790c80 | 2017-12-20 17:41:37 -0800 | [diff] [blame] | 86 | struct scale_factors; |
Debargha Mukherjee | 1fc3df5 | 2018-02-13 12:44:52 -0800 | [diff] [blame] | 87 | |
Angie Chiang | 7927a97 | 2017-02-02 18:13:04 -0800 | [diff] [blame] | 88 | void av1_convolve_2d_facade(const uint8_t *src, int src_stride, uint8_t *dst, |
| 89 | int dst_stride, int w, int h, |
Rupert Swarbrick | 27e9029 | 2017-09-28 17:46:50 +0100 | [diff] [blame] | 90 | InterpFilters interp_filters, const int subpel_x_q4, |
| 91 | int x_step_q4, const int subpel_y_q4, int y_step_q4, |
Yunqing Wang | d790c80 | 2017-12-20 17:41:37 -0800 | [diff] [blame] | 92 | int scaled, ConvolveParams *conv_params, |
| 93 | const struct scale_factors *sf); |
Angie Chiang | 7927a97 | 2017-02-02 18:13:04 -0800 | [diff] [blame] | 94 | |
Debargha Mukherjee | 1fc3df5 | 2018-02-13 12:44:52 -0800 | [diff] [blame] | 95 | static INLINE ConvolveParams get_conv_params_round(int ref, int do_average, |
| 96 | int plane, int bd) { |
| 97 | ConvolveParams conv_params; |
| 98 | conv_params.ref = ref; |
| 99 | conv_params.do_average = do_average; |
| 100 | conv_params.plane = plane; |
| 101 | conv_params.round = CONVOLVE_OPT_ROUND; |
| 102 | conv_params.round_0 = ROUND0_BITS; |
| 103 | conv_params.round_1 = 0; |
| 104 | conv_params.do_post_rounding = 0; |
| 105 | conv_params.is_compound = 0; |
| 106 | conv_params.dst = NULL; |
| 107 | conv_params.dst_stride = 0; |
Debargha Mukherjee | c7a5e88 | 2018-02-19 04:05:21 -0800 | [diff] [blame] | 108 | #if CONFIG_LOWPRECISION_BLEND |
Debargha Mukherjee | 1fc3df5 | 2018-02-13 12:44:52 -0800 | [diff] [blame] | 109 | const int intbufrange = bd + FILTER_BITS - conv_params.round_0 + 2; |
| 110 | if (bd < 12) assert(intbufrange <= 16); |
| 111 | if (intbufrange > 16) { |
| 112 | conv_params.round_0 += intbufrange - 16; |
| 113 | } |
David Barker | aec60dd | 2018-02-20 15:31:05 +0000 | [diff] [blame^] | 114 | #else |
| 115 | (void)bd; |
Debargha Mukherjee | c7a5e88 | 2018-02-19 04:05:21 -0800 | [diff] [blame] | 116 | #endif // CONFIG_LOWPRECISION_BLEND |
Debargha Mukherjee | 1fc3df5 | 2018-02-13 12:44:52 -0800 | [diff] [blame] | 117 | return conv_params; |
| 118 | } |
| 119 | |
David Barker | e64d51a | 2017-06-09 14:52:42 +0100 | [diff] [blame] | 120 | static INLINE ConvolveParams get_conv_params_no_round(int ref, int do_average, |
| 121 | int plane, int32_t *dst, |
Yunqing Wang | 17be4d8 | 2017-12-19 17:00:27 -0800 | [diff] [blame] | 122 | int dst_stride, |
Debargha Mukherjee | e820b82 | 2018-02-09 13:18:29 -0800 | [diff] [blame] | 123 | int is_compound, int bd) { |
Angie Chiang | 117aa0d | 2017-01-18 15:27:03 -0800 | [diff] [blame] | 124 | ConvolveParams conv_params; |
| 125 | conv_params.ref = ref; |
David Barker | e64d51a | 2017-06-09 14:52:42 +0100 | [diff] [blame] | 126 | conv_params.do_average = do_average; |
Debargha Mukherjee | 91b235f | 2018-02-15 16:00:13 -0800 | [diff] [blame] | 127 | assert(IMPLIES(do_average, is_compound)); |
Angie Chiang | 117aa0d | 2017-01-18 15:27:03 -0800 | [diff] [blame] | 128 | conv_params.round = CONVOLVE_OPT_NO_ROUND; |
Yunqing Wang | 17be4d8 | 2017-12-19 17:00:27 -0800 | [diff] [blame] | 129 | conv_params.is_compound = is_compound; |
Debargha Mukherjee | e820b82 | 2018-02-09 13:18:29 -0800 | [diff] [blame] | 130 | conv_params.round_0 = ROUND0_BITS; |
| 131 | #if CONFIG_LOWPRECISION_BLEND |
Debargha Mukherjee | 1fc3df5 | 2018-02-13 12:44:52 -0800 | [diff] [blame] | 132 | conv_params.round_1 = is_compound ? COMPOUND_ROUND1_BITS |
| 133 | : 2 * FILTER_BITS - conv_params.round_0; |
Debargha Mukherjee | e820b82 | 2018-02-09 13:18:29 -0800 | [diff] [blame] | 134 | const int intbufrange = bd + FILTER_BITS - conv_params.round_0 + 2; |
| 135 | if (bd < 12) assert(intbufrange <= 16); |
| 136 | if (intbufrange > 16) { |
| 137 | conv_params.round_0 += intbufrange - 16; |
Debargha Mukherjee | c7a5e88 | 2018-02-19 04:05:21 -0800 | [diff] [blame] | 138 | conv_params.round_1 -= intbufrange - 16; |
Debargha Mukherjee | e820b82 | 2018-02-09 13:18:29 -0800 | [diff] [blame] | 139 | } |
Debargha Mukherjee | c7a5e88 | 2018-02-19 04:05:21 -0800 | [diff] [blame] | 140 | #else |
David Barker | aec60dd | 2018-02-20 15:31:05 +0000 | [diff] [blame^] | 141 | (void)bd; |
Debargha Mukherjee | c7a5e88 | 2018-02-19 04:05:21 -0800 | [diff] [blame] | 142 | conv_params.round_1 = 0; |
| 143 | #endif // CONFIG_LOWPRECISION_BLEND |
Yunqing Wang | 17be4d8 | 2017-12-19 17:00:27 -0800 | [diff] [blame] | 144 | // TODO(yunqing): The following dst should only be valid while |
| 145 | // is_compound = 1; |
Angie Chiang | 117aa0d | 2017-01-18 15:27:03 -0800 | [diff] [blame] | 146 | conv_params.dst = dst; |
| 147 | conv_params.dst_stride = dst_stride; |
Angie Chiang | e3a4c1c | 2017-02-10 16:26:49 -0800 | [diff] [blame] | 148 | conv_params.plane = plane; |
Angie Chiang | 05685e9 | 2017-05-08 12:55:39 -0700 | [diff] [blame] | 149 | conv_params.do_post_rounding = 0; |
Angie Chiang | 117aa0d | 2017-01-18 15:27:03 -0800 | [diff] [blame] | 150 | return conv_params; |
| 151 | } |
| 152 | |
Debargha Mukherjee | 1fc3df5 | 2018-02-13 12:44:52 -0800 | [diff] [blame] | 153 | static INLINE ConvolveParams get_conv_params(int ref, int do_average, int plane, |
| 154 | int bd) { |
| 155 | return get_conv_params_no_round(ref, do_average, plane, NULL, 0, 0, bd); |
| 156 | } |
| 157 | |
Angie Chiang | b03545b | 2017-05-05 12:07:30 -0700 | [diff] [blame] | 158 | void av1_highbd_convolve_2d_facade(const uint8_t *src8, int src_stride, |
| 159 | uint8_t *dst, int dst_stride, int w, int h, |
Rupert Swarbrick | 27e9029 | 2017-09-28 17:46:50 +0100 | [diff] [blame] | 160 | InterpFilters interp_filters, |
Angie Chiang | b03545b | 2017-05-05 12:07:30 -0700 | [diff] [blame] | 161 | const int subpel_x_q4, int x_step_q4, |
| 162 | const int subpel_y_q4, int y_step_q4, |
Debargha Mukherjee | 9c5b108 | 2017-08-14 10:46:51 -0700 | [diff] [blame] | 163 | int scaled, ConvolveParams *conv_params, |
| 164 | int bd); |
Angie Chiang | 117aa0d | 2017-01-18 15:27:03 -0800 | [diff] [blame] | 165 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 166 | void av1_convolve(const uint8_t *src, int src_stride, uint8_t *dst, |
Rupert Swarbrick | 27e9029 | 2017-09-28 17:46:50 +0100 | [diff] [blame] | 167 | int dst_stride, int w, int h, InterpFilters interp_filters, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 168 | const int subpel_x, int xstep, const int subpel_y, int ystep, |
Angie Chiang | 674bffd | 2017-01-11 16:15:55 -0800 | [diff] [blame] | 169 | ConvolveParams *conv_params); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 170 | |
Fergus Simpson | fc59389 | 2017-04-06 12:19:06 -0700 | [diff] [blame] | 171 | void av1_convolve_c(const uint8_t *src, int src_stride, uint8_t *dst, |
Rupert Swarbrick | 27e9029 | 2017-09-28 17:46:50 +0100 | [diff] [blame] | 172 | int dst_stride, int w, int h, InterpFilters interp_filters, |
Fergus Simpson | fc59389 | 2017-04-06 12:19:06 -0700 | [diff] [blame] | 173 | const int subpel_x, int xstep, const int subpel_y, |
| 174 | int ystep, ConvolveParams *conv_params); |
| 175 | |
Fergus Simpson | 505f006 | 2017-06-27 11:23:34 -0700 | [diff] [blame] | 176 | void av1_convolve_scale(const uint8_t *src, int src_stride, uint8_t *dst, |
| 177 | int dst_stride, int w, int h, |
Rupert Swarbrick | 27e9029 | 2017-09-28 17:46:50 +0100 | [diff] [blame] | 178 | InterpFilters interp_filters, const int subpel_x, |
| 179 | int xstep, const int subpel_y, int ystep, |
| 180 | ConvolveParams *conv_params); |
Fergus Simpson | 505f006 | 2017-06-27 11:23:34 -0700 | [diff] [blame] | 181 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 182 | void av1_highbd_convolve(const uint8_t *src, int src_stride, uint8_t *dst, |
| 183 | int dst_stride, int w, int h, |
Rupert Swarbrick | 27e9029 | 2017-09-28 17:46:50 +0100 | [diff] [blame] | 184 | InterpFilters interp_filters, const int subpel_x, |
| 185 | int xstep, const int subpel_y, int ystep, int avg, |
| 186 | int bd); |
Debargha Mukherjee | 7739752 | 2017-07-13 10:56:15 -0700 | [diff] [blame] | 187 | |
| 188 | void av1_highbd_convolve_scale(const uint8_t *src, int src_stride, uint8_t *dst, |
| 189 | int dst_stride, int w, int h, |
Rupert Swarbrick | 27e9029 | 2017-09-28 17:46:50 +0100 | [diff] [blame] | 190 | InterpFilters interp_filters, const int subpel_x, |
| 191 | int xstep, const int subpel_y, int ystep, |
| 192 | int avg, int bd); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 193 | #ifdef __cplusplus |
| 194 | } // extern "C" |
| 195 | #endif |
| 196 | |
| 197 | #endif // AV1_COMMON_AV1_CONVOLVE_H_ |