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