blob: 5f3e59625bfc357783bba453a1b210c78bb84856 [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
James Zerne1cbb132018-08-22 14:10:36 -070012#ifndef AOM_AV1_COMMON_CONVOLVE_H_
13#define AOM_AV1_COMMON_CONVOLVE_H_
Yaowu Xuf883b422016-08-30 14:01:10 -070014#include "av1/common/filter.h"
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
Cherma Rajan Aa7be3682018-03-20 10:00:51 +053020typedef uint16_t CONV_BUF_TYPE;
Angie Chiang674bffd2017-01-11 16:15:55 -080021typedef struct ConvolveParams {
David Barkere64d51a2017-06-09 14:52:42 +010022 int do_average;
Angie Chiang7927a972017-02-02 18:13:04 -080023 CONV_BUF_TYPE *dst;
Angie Chiangf7159222017-01-18 12:51:12 -080024 int dst_stride;
Angie Chiang7927a972017-02-02 18:13:04 -080025 int round_0;
26 int round_1;
Angie Chiange3a4c1c2017-02-10 16:26:49 -080027 int plane;
Yunqing Wang17be4d82017-12-19 17:00:27 -080028 int is_compound;
Debargha Mukherjee7ac3eb12018-12-12 10:26:50 -080029 int use_dist_wtd_comp_avg;
Cheng Chend867c9a2017-10-09 19:03:56 -070030 int fwd_offset;
31 int bck_offset;
Angie Chiang674bffd2017-01-11 16:15:55 -080032} ConvolveParams;
33
Debargha Mukherjee948f2a92018-02-18 07:19:26 -080034#define ROUND0_BITS 3
Debargha Mukherjee648a72b2018-02-26 09:09:27 -080035#define COMPOUND_ROUND1_BITS 7
Debargha Mukherjee9a82a4f2018-03-12 14:11:18 -070036#define WIENER_ROUND0_BITS 3
Debargha Mukherjeee820b822018-02-09 13:18:29 -080037
Debargha Mukherjee9a82a4f2018-03-12 14:11:18 -070038#define WIENER_CLAMP_LIMIT(r0, bd) (1 << ((bd) + 1 + FILTER_BITS - r0))
Debargha Mukherjeee6ceeec2018-03-11 18:21:52 -070039
Yunqing Wangd790c802017-12-20 17:41:37 -080040typedef void (*aom_convolve_fn_t)(const uint8_t *src, int src_stride,
Yunqing Wang94e3fe32017-12-22 14:17:44 -080041 uint8_t *dst, int dst_stride, int w, int h,
Peng Bin3a0c2ed2018-07-19 16:24:00 +080042 const InterpFilterParams *filter_params_x,
43 const InterpFilterParams *filter_params_y,
Yaowu Xu89ed7d42019-05-08 12:09:27 -070044 const int subpel_x_qn, const int subpel_y_qn,
Yunqing Wangd790c802017-12-20 17:41:37 -080045 ConvolveParams *conv_params);
46
Cherma Rajan A09d45302018-02-22 17:25:15 +053047typedef void (*aom_highbd_convolve_fn_t)(
48 const uint16_t *src, int src_stride, uint16_t *dst, int dst_stride, int w,
Peng Bin3a0c2ed2018-07-19 16:24:00 +080049 int h, const InterpFilterParams *filter_params_x,
Yaowu Xu89ed7d42019-05-08 12:09:27 -070050 const InterpFilterParams *filter_params_y, const int subpel_x_qn,
51 const int subpel_y_qn, ConvolveParams *conv_params, int bd);
Cherma Rajan A09d45302018-02-22 17:25:15 +053052
Angie Chiang0a2c0cb2017-02-23 14:19:15 -080053struct AV1Common;
Yunqing Wangd790c802017-12-20 17:41:37 -080054struct scale_factors;
Debargha Mukherjee1fc3df52018-02-13 12:44:52 -080055
Angie Chiang7927a972017-02-02 18:13:04 -080056void av1_convolve_2d_facade(const uint8_t *src, int src_stride, uint8_t *dst,
57 int dst_stride, int w, int h,
Jingning Han12d93eb2019-10-24 12:12:01 -070058 const InterpFilterParams *interp_filters[2],
Ravi Chaudhary1e4f94b2019-06-20 16:19:49 +053059 const int subpel_x_qn, int x_step_q4,
60 const int subpel_y_qn, int y_step_q4, int scaled,
Elliott Karpilovskyebe812f2020-04-13 18:48:50 -070061 ConvolveParams *conv_params);
Angie Chiang7927a972017-02-02 18:13:04 -080062
Jingning Han1a27d7f2019-11-18 10:30:54 -080063static INLINE ConvolveParams get_conv_params_no_round(int cmp_index, int plane,
Yue Chen19d76012018-02-16 15:13:40 -080064 CONV_BUF_TYPE *dst,
Yunqing Wang17be4d82017-12-19 17:00:27 -080065 int dst_stride,
Debargha Mukherjeee820b822018-02-09 13:18:29 -080066 int is_compound, int bd) {
Angie Chiang117aa0d2017-01-18 15:27:03 -080067 ConvolveParams conv_params;
Jingning Han1a27d7f2019-11-18 10:30:54 -080068 assert(IMPLIES(cmp_index, is_compound));
69
Yunqing Wang17be4d82017-12-19 17:00:27 -080070 conv_params.is_compound = is_compound;
Jingning Han4b592ec2020-12-30 16:46:27 -080071 conv_params.use_dist_wtd_comp_avg = 0;
Debargha Mukherjeee820b822018-02-09 13:18:29 -080072 conv_params.round_0 = ROUND0_BITS;
Debargha Mukherjee1fc3df52018-02-13 12:44:52 -080073 conv_params.round_1 = is_compound ? COMPOUND_ROUND1_BITS
74 : 2 * FILTER_BITS - conv_params.round_0;
Debargha Mukherjeee820b822018-02-09 13:18:29 -080075 const int intbufrange = bd + FILTER_BITS - conv_params.round_0 + 2;
Debargha Mukherjee9a82a4f2018-03-12 14:11:18 -070076 assert(IMPLIES(bd < 12, intbufrange <= 16));
Debargha Mukherjeee820b822018-02-09 13:18:29 -080077 if (intbufrange > 16) {
78 conv_params.round_0 += intbufrange - 16;
Debargha Mukherjee9a65bb02018-03-01 10:35:03 -080079 if (!is_compound) conv_params.round_1 -= intbufrange - 16;
Debargha Mukherjeee820b822018-02-09 13:18:29 -080080 }
Yunqing Wang17be4d82017-12-19 17:00:27 -080081 // TODO(yunqing): The following dst should only be valid while
82 // is_compound = 1;
Angie Chiang117aa0d2017-01-18 15:27:03 -080083 conv_params.dst = dst;
84 conv_params.dst_stride = dst_stride;
Angie Chiange3a4c1c2017-02-10 16:26:49 -080085 conv_params.plane = plane;
Jingning Han1a27d7f2019-11-18 10:30:54 -080086
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 Chiang117aa0d2017-01-18 15:27:03 -080090 return conv_params;
91}
92
Peng Binf7b11f52018-08-09 17:29:39 +080093static INLINE ConvolveParams get_conv_params(int do_average, int plane,
Debargha Mukherjee1fc3df52018-02-13 12:44:52 -080094 int bd) {
Peng Binf7b11f52018-08-09 17:29:39 +080095 return get_conv_params_no_round(do_average, plane, NULL, 0, 0, bd);
Debargha Mukherjee1fc3df52018-02-13 12:44:52 -080096}
97
Debargha Mukherjee26971392018-03-12 08:20:46 -070098static INLINE ConvolveParams get_conv_params_wiener(int bd) {
99 ConvolveParams conv_params;
100 (void)bd;
Debargha Mukherjee26971392018-03-12 08:20:46 -0700101 conv_params.do_average = 0;
102 conv_params.is_compound = 0;
103 conv_params.round_0 = WIENER_ROUND0_BITS;
Debargha Mukherjee9a82a4f2018-03-12 14:11:18 -0700104 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 Mukherjee26971392018-03-12 08:20:46 -0700111 conv_params.dst = NULL;
112 conv_params.dst_stride = 0;
113 conv_params.plane = 0;
114 return conv_params;
115}
116
Angie Chiangb03545b2017-05-05 12:07:30 -0700117void av1_highbd_convolve_2d_facade(const uint8_t *src8, int src_stride,
118 uint8_t *dst, int dst_stride, int w, int h,
Jingning Han12d93eb2019-10-24 12:12:01 -0700119 const InterpFilterParams *interp_filters[2],
Yaowu Xu89ed7d42019-05-08 12:09:27 -0700120 const int subpel_x_qn, int x_step_q4,
121 const int subpel_y_qn, int y_step_q4,
Debargha Mukherjee9c5b1082017-08-14 10:46:51 -0700122 int scaled, ConvolveParams *conv_params,
Elliott Karpilovskyebe812f2020-04-13 18:48:50 -0700123 int bd);
Angie Chiang117aa0d2017-01-18 15:27:03 -0800124
Sarah Parker0115e932018-10-22 14:14:22 -0700125// TODO(sarahparker) This will need to be integerized and optimized
126void 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 Xuf883b422016-08-30 14:01:10 -0700130#ifdef __cplusplus
131} // extern "C"
132#endif
133
James Zerne1cbb132018-08-22 14:10:36 -0700134#endif // AOM_AV1_COMMON_CONVOLVE_H_