blob: af0230ab17b0b42a87579f10f2cfde894c5729b7 [file] [log] [blame]
Angie Chiang64211912016-10-25 15:09:56 -07001/*
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 Xuf883b422016-08-30 14:01:10 -070012#ifndef AV1_COMMON_AV1_CONVOLVE_H_
13#define AV1_COMMON_AV1_CONVOLVE_H_
14#include "av1/common/filter.h"
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
Angie Chiang9f45bc42017-01-13 16:27:54 -080020typedef 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 Chiang7927a972017-02-02 18:13:04 -080026typedef int32_t CONV_BUF_TYPE;
27
Angie Chiang674bffd2017-01-11 16:15:55 -080028typedef struct ConvolveParams {
29 int ref;
David Barkere64d51a2017-06-09 14:52:42 +010030 int do_average;
Angie Chiang9f45bc42017-01-13 16:27:54 -080031 CONVOLVE_OPT round;
Angie Chiang7927a972017-02-02 18:13:04 -080032 CONV_BUF_TYPE *dst;
Angie Chiangf7159222017-01-18 12:51:12 -080033 int dst_stride;
Angie Chiang7927a972017-02-02 18:13:04 -080034 int round_0;
35 int round_1;
Angie Chiange3a4c1c2017-02-10 16:26:49 -080036 int plane;
Angie Chiang05685e92017-05-08 12:55:39 -070037 int do_post_rounding;
Yunqing Wang17be4d82017-12-19 17:00:27 -080038 int is_compound;
Cheng Chend867c9a2017-10-09 19:03:56 -070039#if CONFIG_JNT_COMP
Cheng Chen8263f802017-11-14 15:50:00 -080040 int use_jnt_comp_avg;
Cheng Chend867c9a2017-10-09 19:03:56 -070041 int fwd_offset;
42 int bck_offset;
43#endif
Angie Chiang674bffd2017-01-11 16:15:55 -080044} ConvolveParams;
45
Debargha Mukherjee948f2a92018-02-18 07:19:26 -080046#if CONFIG_LOWPRECISION_BLEND
47#define ROUND0_BITS 3
48#define COMPOUND_ROUND1_BITS (5 + CONFIG_LOWPRECISION_BLEND)
Debargha Mukherjeee820b822018-02-09 13:18:29 -080049#else
Debargha Mukherjee948f2a92018-02-18 07:19:26 -080050#define ROUND0_BITS 5
Debargha Mukherjeee820b822018-02-09 13:18:29 -080051#define COMPOUND_ROUND1_BITS 0
52#endif // CONFIG_LOWPRECISION_BLEND
53
Yunqing Wangd790c802017-12-20 17:41:37 -080054typedef void (*aom_convolve_fn_t)(const uint8_t *src, int src_stride,
Yunqing Wang94e3fe32017-12-22 14:17:44 -080055 uint8_t *dst, int dst_stride, int w, int h,
56 InterpFilterParams *filter_params_x,
Yunqing Wangd790c802017-12-20 17:41:37 -080057 InterpFilterParams *filter_params_y,
58 const int subpel_x_q4, const int subpel_y_q4,
59 ConvolveParams *conv_params);
60
Zhijie Yangf02f8ae2017-10-26 17:58:29 -070061static INLINE void av1_get_convolve_filter_params(InterpFilters interp_filters,
Zhijie Yangf02f8ae2017-10-26 17:58:29 -070062 InterpFilterParams *params_x,
63 InterpFilterParams *params_y
64#if CONFIG_SHORT_FILTER
65 ,
66 int w, int h
67#endif
Johann6b41d4d2018-02-08 14:32:53 -080068) {
Rupert Swarbrick27e90292017-09-28 17:46:50 +010069#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 Yangf02f8ae2017-10-26 17:58:29 -070076#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 Swarbrick27e90292017-09-28 17:46:50 +010080 *params_x = av1_get_interp_filter_params(filter_x);
81 *params_y = av1_get_interp_filter_params(filter_y);
Zhijie Yangf02f8ae2017-10-26 17:58:29 -070082#endif
Rupert Swarbrick27e90292017-09-28 17:46:50 +010083}
84
Angie Chiang0a2c0cb2017-02-23 14:19:15 -080085struct AV1Common;
Yunqing Wangd790c802017-12-20 17:41:37 -080086struct scale_factors;
Debargha Mukherjee1fc3df52018-02-13 12:44:52 -080087
Angie Chiang7927a972017-02-02 18:13:04 -080088void av1_convolve_2d_facade(const uint8_t *src, int src_stride, uint8_t *dst,
89 int dst_stride, int w, int h,
Rupert Swarbrick27e90292017-09-28 17:46:50 +010090 InterpFilters interp_filters, const int subpel_x_q4,
91 int x_step_q4, const int subpel_y_q4, int y_step_q4,
Yunqing Wangd790c802017-12-20 17:41:37 -080092 int scaled, ConvolveParams *conv_params,
93 const struct scale_factors *sf);
Angie Chiang7927a972017-02-02 18:13:04 -080094
Debargha Mukherjee1fc3df52018-02-13 12:44:52 -080095static 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 Mukherjeec7a5e882018-02-19 04:05:21 -0800108#if CONFIG_LOWPRECISION_BLEND
Debargha Mukherjee1fc3df52018-02-13 12:44:52 -0800109 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 Barkeraec60dd2018-02-20 15:31:05 +0000114#else
115 (void)bd;
Debargha Mukherjeec7a5e882018-02-19 04:05:21 -0800116#endif // CONFIG_LOWPRECISION_BLEND
Debargha Mukherjee1fc3df52018-02-13 12:44:52 -0800117 return conv_params;
118}
119
David Barkere64d51a2017-06-09 14:52:42 +0100120static INLINE ConvolveParams get_conv_params_no_round(int ref, int do_average,
121 int plane, int32_t *dst,
Yunqing Wang17be4d82017-12-19 17:00:27 -0800122 int dst_stride,
Debargha Mukherjeee820b822018-02-09 13:18:29 -0800123 int is_compound, int bd) {
Angie Chiang117aa0d2017-01-18 15:27:03 -0800124 ConvolveParams conv_params;
125 conv_params.ref = ref;
David Barkere64d51a2017-06-09 14:52:42 +0100126 conv_params.do_average = do_average;
Debargha Mukherjee91b235f2018-02-15 16:00:13 -0800127 assert(IMPLIES(do_average, is_compound));
Angie Chiang117aa0d2017-01-18 15:27:03 -0800128 conv_params.round = CONVOLVE_OPT_NO_ROUND;
Yunqing Wang17be4d82017-12-19 17:00:27 -0800129 conv_params.is_compound = is_compound;
Debargha Mukherjeee820b822018-02-09 13:18:29 -0800130 conv_params.round_0 = ROUND0_BITS;
131#if CONFIG_LOWPRECISION_BLEND
Debargha Mukherjee1fc3df52018-02-13 12:44:52 -0800132 conv_params.round_1 = is_compound ? COMPOUND_ROUND1_BITS
133 : 2 * FILTER_BITS - conv_params.round_0;
Debargha Mukherjeee820b822018-02-09 13:18:29 -0800134 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 Mukherjeec7a5e882018-02-19 04:05:21 -0800138 conv_params.round_1 -= intbufrange - 16;
Debargha Mukherjeee820b822018-02-09 13:18:29 -0800139 }
Debargha Mukherjeec7a5e882018-02-19 04:05:21 -0800140#else
David Barkeraec60dd2018-02-20 15:31:05 +0000141 (void)bd;
Debargha Mukherjeec7a5e882018-02-19 04:05:21 -0800142 conv_params.round_1 = 0;
143#endif // CONFIG_LOWPRECISION_BLEND
Yunqing Wang17be4d82017-12-19 17:00:27 -0800144 // TODO(yunqing): The following dst should only be valid while
145 // is_compound = 1;
Angie Chiang117aa0d2017-01-18 15:27:03 -0800146 conv_params.dst = dst;
147 conv_params.dst_stride = dst_stride;
Angie Chiange3a4c1c2017-02-10 16:26:49 -0800148 conv_params.plane = plane;
Angie Chiang05685e92017-05-08 12:55:39 -0700149 conv_params.do_post_rounding = 0;
Angie Chiang117aa0d2017-01-18 15:27:03 -0800150 return conv_params;
151}
152
Debargha Mukherjee1fc3df52018-02-13 12:44:52 -0800153static 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 Chiangb03545b2017-05-05 12:07:30 -0700158void av1_highbd_convolve_2d_facade(const uint8_t *src8, int src_stride,
159 uint8_t *dst, int dst_stride, int w, int h,
Rupert Swarbrick27e90292017-09-28 17:46:50 +0100160 InterpFilters interp_filters,
Angie Chiangb03545b2017-05-05 12:07:30 -0700161 const int subpel_x_q4, int x_step_q4,
162 const int subpel_y_q4, int y_step_q4,
Debargha Mukherjee9c5b1082017-08-14 10:46:51 -0700163 int scaled, ConvolveParams *conv_params,
164 int bd);
Angie Chiang117aa0d2017-01-18 15:27:03 -0800165
Yaowu Xuf883b422016-08-30 14:01:10 -0700166void av1_convolve(const uint8_t *src, int src_stride, uint8_t *dst,
Rupert Swarbrick27e90292017-09-28 17:46:50 +0100167 int dst_stride, int w, int h, InterpFilters interp_filters,
Yaowu Xuf883b422016-08-30 14:01:10 -0700168 const int subpel_x, int xstep, const int subpel_y, int ystep,
Angie Chiang674bffd2017-01-11 16:15:55 -0800169 ConvolveParams *conv_params);
Yaowu Xuf883b422016-08-30 14:01:10 -0700170
Fergus Simpsonfc593892017-04-06 12:19:06 -0700171void av1_convolve_c(const uint8_t *src, int src_stride, uint8_t *dst,
Rupert Swarbrick27e90292017-09-28 17:46:50 +0100172 int dst_stride, int w, int h, InterpFilters interp_filters,
Fergus Simpsonfc593892017-04-06 12:19:06 -0700173 const int subpel_x, int xstep, const int subpel_y,
174 int ystep, ConvolveParams *conv_params);
175
Fergus Simpson505f0062017-06-27 11:23:34 -0700176void av1_convolve_scale(const uint8_t *src, int src_stride, uint8_t *dst,
177 int dst_stride, int w, int h,
Rupert Swarbrick27e90292017-09-28 17:46:50 +0100178 InterpFilters interp_filters, const int subpel_x,
179 int xstep, const int subpel_y, int ystep,
180 ConvolveParams *conv_params);
Fergus Simpson505f0062017-06-27 11:23:34 -0700181
Yaowu Xuf883b422016-08-30 14:01:10 -0700182void av1_highbd_convolve(const uint8_t *src, int src_stride, uint8_t *dst,
183 int dst_stride, int w, int h,
Rupert Swarbrick27e90292017-09-28 17:46:50 +0100184 InterpFilters interp_filters, const int subpel_x,
185 int xstep, const int subpel_y, int ystep, int avg,
186 int bd);
Debargha Mukherjee77397522017-07-13 10:56:15 -0700187
188void av1_highbd_convolve_scale(const uint8_t *src, int src_stride, uint8_t *dst,
189 int dst_stride, int w, int h,
Rupert Swarbrick27e90292017-09-28 17:46:50 +0100190 InterpFilters interp_filters, const int subpel_x,
191 int xstep, const int subpel_y, int ystep,
192 int avg, int bd);
Yaowu Xuf883b422016-08-30 14:01:10 -0700193#ifdef __cplusplus
194} // extern "C"
195#endif
196
197#endif // AV1_COMMON_AV1_CONVOLVE_H_