• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 compound_index;  // 0: the first single in compound mode, 1: the second.
30   int use_dist_wtd_comp_avg;
31   int fwd_offset;
32   int bck_offset;
33 } ConvolveParams;
34 
35 #define ROUND0_BITS 3
36 #define COMPOUND_ROUND1_BITS 7
37 #define WIENER_ROUND0_BITS 3
38 
39 #define WIENER_CLAMP_LIMIT(r0, bd) (1 << ((bd) + 1 + FILTER_BITS - r0))
40 
41 typedef void (*aom_convolve_fn_t)(const uint8_t *src, int src_stride,
42                                   uint8_t *dst, int dst_stride, int w, int h,
43                                   const InterpFilterParams *filter_params_x,
44                                   const InterpFilterParams *filter_params_y,
45                                   const int subpel_x_qn, const int subpel_y_qn,
46                                   ConvolveParams *conv_params);
47 
48 typedef void (*aom_highbd_convolve_fn_t)(
49     const uint16_t *src, int src_stride, uint16_t *dst, int dst_stride, int w,
50     int h, const InterpFilterParams *filter_params_x,
51     const InterpFilterParams *filter_params_y, const int subpel_x_qn,
52     const int subpel_y_qn, ConvolveParams *conv_params, int bd);
53 
54 struct AV1Common;
55 struct scale_factors;
56 
57 void av1_convolve_2d_facade(const uint8_t *src, int src_stride, uint8_t *dst,
58                             int dst_stride, int w, int h,
59                             const InterpFilterParams *interp_filters[2],
60                             const int subpel_x_qn, int x_step_q4,
61                             const int subpel_y_qn, int y_step_q4, int scaled,
62                             ConvolveParams *conv_params,
63                             const struct scale_factors *sf);
64 
get_conv_params_no_round(int cmp_index,int plane,CONV_BUF_TYPE * dst,int dst_stride,int is_compound,int bd)65 static INLINE ConvolveParams get_conv_params_no_round(int cmp_index, int plane,
66                                                       CONV_BUF_TYPE *dst,
67                                                       int dst_stride,
68                                                       int is_compound, int bd) {
69   ConvolveParams conv_params;
70   conv_params.compound_index = cmp_index;
71   assert(IMPLIES(cmp_index, is_compound));
72 
73   conv_params.is_compound = is_compound;
74   conv_params.round_0 = ROUND0_BITS;
75   conv_params.round_1 = is_compound ? COMPOUND_ROUND1_BITS
76                                     : 2 * FILTER_BITS - conv_params.round_0;
77   const int intbufrange = bd + FILTER_BITS - conv_params.round_0 + 2;
78   assert(IMPLIES(bd < 12, intbufrange <= 16));
79   if (intbufrange > 16) {
80     conv_params.round_0 += intbufrange - 16;
81     if (!is_compound) conv_params.round_1 -= intbufrange - 16;
82   }
83   // TODO(yunqing): The following dst should only be valid while
84   // is_compound = 1;
85   conv_params.dst = dst;
86   conv_params.dst_stride = dst_stride;
87   conv_params.plane = plane;
88 
89   // By default, set do average to 1 if this is the second single prediction
90   // in a compound mode.
91   conv_params.do_average = cmp_index;
92   return conv_params;
93 }
94 
get_conv_params(int do_average,int plane,int bd)95 static INLINE ConvolveParams get_conv_params(int do_average, int plane,
96                                              int bd) {
97   return get_conv_params_no_round(do_average, plane, NULL, 0, 0, bd);
98 }
99 
get_conv_params_wiener(int bd)100 static INLINE ConvolveParams get_conv_params_wiener(int bd) {
101   ConvolveParams conv_params;
102   (void)bd;
103   conv_params.do_average = 0;
104   conv_params.is_compound = 0;
105   conv_params.round_0 = WIENER_ROUND0_BITS;
106   conv_params.round_1 = 2 * FILTER_BITS - conv_params.round_0;
107   const int intbufrange = bd + FILTER_BITS - conv_params.round_0 + 2;
108   assert(IMPLIES(bd < 12, intbufrange <= 16));
109   if (intbufrange > 16) {
110     conv_params.round_0 += intbufrange - 16;
111     conv_params.round_1 -= intbufrange - 16;
112   }
113   conv_params.dst = NULL;
114   conv_params.dst_stride = 0;
115   conv_params.plane = 0;
116   return conv_params;
117 }
118 
119 void av1_highbd_convolve_2d_facade(const uint8_t *src8, int src_stride,
120                                    uint8_t *dst, int dst_stride, int w, int h,
121                                    const InterpFilterParams *interp_filters[2],
122                                    const int subpel_x_qn, int x_step_q4,
123                                    const int subpel_y_qn, int y_step_q4,
124                                    int scaled, ConvolveParams *conv_params,
125                                    const struct scale_factors *sf, int bd);
126 
127 // TODO(sarahparker) This will need to be integerized and optimized
128 void av1_convolve_2d_sobel_y_c(const uint8_t *src, int src_stride, double *dst,
129                                int dst_stride, int w, int h, int dir,
130                                double norm);
131 
132 #ifdef __cplusplus
133 }  // extern "C"
134 #endif
135 
136 #endif  // AOM_AV1_COMMON_CONVOLVE_H_
137