xref: /aosp_15_r20/external/libaom/av1/common/convolve.h (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
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_CONVOLVE_H_
13 #define AOM_AV1_COMMON_CONVOLVE_H_
14 #include "av1/common/filter.h"
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 typedef uint16_t CONV_BUF_TYPE;
21 typedef struct ConvolveParams {
22   int do_average;
23   CONV_BUF_TYPE *dst;
24   int dst_stride;
25   int round_0;
26   int round_1;
27   int plane;
28   int is_compound;
29   int use_dist_wtd_comp_avg;
30   int fwd_offset;
31   int bck_offset;
32 } ConvolveParams;
33 
34 typedef struct WienerConvolveParams {
35   int round_0;
36   int round_1;
37 } WienerConvolveParams;
38 
39 #define ROUND0_BITS 3
40 #define COMPOUND_ROUND1_BITS 7
41 #define WIENER_ROUND0_BITS 3
42 
43 #define WIENER_CLAMP_LIMIT(r0, bd) (1 << ((bd) + 1 + FILTER_BITS - r0))
44 
45 typedef void (*aom_convolve_fn_t)(const uint8_t *src, int src_stride,
46                                   uint8_t *dst, int dst_stride, int w, int h,
47                                   const InterpFilterParams *filter_params_x,
48                                   const InterpFilterParams *filter_params_y,
49                                   const int subpel_x_qn, const int subpel_y_qn,
50                                   ConvolveParams *conv_params);
51 
52 typedef void (*aom_highbd_convolve_fn_t)(
53     const uint16_t *src, int src_stride, uint16_t *dst, int dst_stride, int w,
54     int h, const InterpFilterParams *filter_params_x,
55     const InterpFilterParams *filter_params_y, const int subpel_x_qn,
56     const int subpel_y_qn, ConvolveParams *conv_params, int bd);
57 
58 struct AV1Common;
59 struct scale_factors;
60 
61 void av1_convolve_2d_facade(const uint8_t *src, int src_stride, uint8_t *dst,
62                             int dst_stride, int w, int h,
63                             const InterpFilterParams *interp_filters[2],
64                             const int subpel_x_qn, int x_step_q4,
65                             const int subpel_y_qn, int y_step_q4, int scaled,
66                             ConvolveParams *conv_params);
67 
get_conv_params_no_round(int cmp_index,int plane,CONV_BUF_TYPE * dst,int dst_stride,int is_compound,int bd)68 static inline ConvolveParams get_conv_params_no_round(int cmp_index, int plane,
69                                                       CONV_BUF_TYPE *dst,
70                                                       int dst_stride,
71                                                       int is_compound, int bd) {
72   ConvolveParams conv_params;
73   assert(IMPLIES(cmp_index, is_compound));
74 
75   conv_params.is_compound = is_compound;
76   conv_params.use_dist_wtd_comp_avg = 0;
77   conv_params.round_0 = ROUND0_BITS;
78   conv_params.round_1 = is_compound ? COMPOUND_ROUND1_BITS
79                                     : 2 * FILTER_BITS - conv_params.round_0;
80 #if CONFIG_AV1_HIGHBITDEPTH
81   const int intbufrange = bd + FILTER_BITS - conv_params.round_0 + 2;
82   assert(IMPLIES(bd < 12, intbufrange <= 16));
83   if (intbufrange > 16) {
84     conv_params.round_0 += intbufrange - 16;
85     if (!is_compound) conv_params.round_1 -= intbufrange - 16;
86   }
87 #else
88   (void)bd;
89 #endif  // CONFIG_AV1_HIGHBITDEPTH
90   // TODO(yunqing): The following dst should only be valid while
91   // is_compound = 1;
92   conv_params.dst = dst;
93   conv_params.dst_stride = dst_stride;
94   conv_params.plane = plane;
95 
96   // By default, set do average to 1 if this is the second single prediction
97   // in a compound mode.
98   conv_params.do_average = cmp_index;
99   return conv_params;
100 }
101 
get_conv_params(int do_average,int plane,int bd)102 static inline ConvolveParams get_conv_params(int do_average, int plane,
103                                              int bd) {
104   return get_conv_params_no_round(do_average, plane, NULL, 0, 0, bd);
105 }
106 
get_conv_params_wiener(int bd)107 static inline WienerConvolveParams get_conv_params_wiener(int bd) {
108   WienerConvolveParams conv_params;
109   conv_params.round_0 = WIENER_ROUND0_BITS;
110   conv_params.round_1 = 2 * FILTER_BITS - conv_params.round_0;
111   const int intbufrange = bd + FILTER_BITS - conv_params.round_0 + 2;
112   assert(IMPLIES(bd < 12, intbufrange <= 16));
113   if (intbufrange > 16) {
114     conv_params.round_0 += intbufrange - 16;
115     conv_params.round_1 -= intbufrange - 16;
116   }
117   return conv_params;
118 }
119 
120 void av1_highbd_convolve_2d_facade(const uint8_t *src8, int src_stride,
121                                    uint8_t *dst, int dst_stride, int w, int h,
122                                    const InterpFilterParams *interp_filters[2],
123                                    const int subpel_x_qn, int x_step_q4,
124                                    const int subpel_y_qn, int y_step_q4,
125                                    int scaled, ConvolveParams *conv_params,
126                                    int bd);
127 
128 #ifdef __cplusplus
129 }  // extern "C"
130 #endif
131 
132 #endif  // AOM_AV1_COMMON_CONVOLVE_H_
133