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