/src/aom/av1/common/convolve.c
Line | Count | Source |
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 | | #include <assert.h> |
13 | | #include <string.h> |
14 | | |
15 | | #include "config/aom_dsp_rtcd.h" |
16 | | #include "config/av1_rtcd.h" |
17 | | |
18 | | #include "av1/common/av1_common_int.h" |
19 | | #include "av1/common/blockd.h" |
20 | | #include "av1/common/convolve.h" |
21 | | #include "av1/common/filter.h" |
22 | | #include "av1/common/resize.h" |
23 | | #include "aom_dsp/aom_dsp_common.h" |
24 | | #include "aom_ports/mem.h" |
25 | | |
26 | | void av1_convolve_horiz_rs_c(const uint8_t *src, int src_stride, uint8_t *dst, |
27 | | int dst_stride, int w, int h, |
28 | | const int16_t *x_filters, int x0_qn, |
29 | 35.6k | int x_step_qn) { |
30 | 35.6k | src -= UPSCALE_NORMATIVE_TAPS / 2 - 1; |
31 | 1.21M | for (int y = 0; y < h; ++y) { |
32 | 1.18M | int x_qn = x0_qn; |
33 | 146M | for (int x = 0; x < w; ++x) { |
34 | 145M | const uint8_t *const src_x = &src[x_qn >> RS_SCALE_SUBPEL_BITS]; |
35 | 145M | const int x_filter_idx = |
36 | 145M | (x_qn & RS_SCALE_SUBPEL_MASK) >> RS_SCALE_EXTRA_BITS; |
37 | 145M | assert(x_filter_idx <= RS_SUBPEL_MASK); |
38 | 145M | const int16_t *const x_filter = |
39 | 145M | &x_filters[x_filter_idx * UPSCALE_NORMATIVE_TAPS]; |
40 | 145M | int sum = 0; |
41 | 1.30G | for (int k = 0; k < UPSCALE_NORMATIVE_TAPS; ++k) |
42 | 1.16G | sum += src_x[k] * x_filter[k]; |
43 | 145M | dst[x] = clip_pixel(ROUND_POWER_OF_TWO(sum, FILTER_BITS)); |
44 | 145M | x_qn += x_step_qn; |
45 | 145M | } |
46 | 1.18M | src += src_stride; |
47 | 1.18M | dst += dst_stride; |
48 | 1.18M | } |
49 | 35.6k | } |
50 | | |
51 | | void av1_highbd_convolve_horiz_rs_c(const uint16_t *src, int src_stride, |
52 | | uint16_t *dst, int dst_stride, int w, int h, |
53 | | const int16_t *x_filters, int x0_qn, |
54 | 122k | int x_step_qn, int bd) { |
55 | 122k | src -= UPSCALE_NORMATIVE_TAPS / 2 - 1; |
56 | 4.69M | for (int y = 0; y < h; ++y) { |
57 | 4.57M | int x_qn = x0_qn; |
58 | 308M | for (int x = 0; x < w; ++x) { |
59 | 303M | const uint16_t *const src_x = &src[x_qn >> RS_SCALE_SUBPEL_BITS]; |
60 | 303M | const int x_filter_idx = |
61 | 303M | (x_qn & RS_SCALE_SUBPEL_MASK) >> RS_SCALE_EXTRA_BITS; |
62 | 303M | assert(x_filter_idx <= RS_SUBPEL_MASK); |
63 | 303M | const int16_t *const x_filter = |
64 | 303M | &x_filters[x_filter_idx * UPSCALE_NORMATIVE_TAPS]; |
65 | 303M | int sum = 0; |
66 | 2.73G | for (int k = 0; k < UPSCALE_NORMATIVE_TAPS; ++k) |
67 | 2.42G | sum += src_x[k] * x_filter[k]; |
68 | 303M | dst[x] = clip_pixel_highbd(ROUND_POWER_OF_TWO(sum, FILTER_BITS), bd); |
69 | 303M | x_qn += x_step_qn; |
70 | 303M | } |
71 | 4.57M | src += src_stride; |
72 | 4.57M | dst += dst_stride; |
73 | 4.57M | } |
74 | 122k | } |
75 | | |
76 | | void av1_convolve_2d_sobel_y_c(const uint8_t *src, int src_stride, double *dst, |
77 | | int dst_stride, int w, int h, int dir, |
78 | 0 | double norm) { |
79 | 0 | int16_t im_block[(MAX_SB_SIZE + MAX_FILTER_TAP - 1) * MAX_SB_SIZE]; |
80 | 0 | DECLARE_ALIGNED(256, static const int16_t, sobel_a[3]) = { 1, 0, -1 }; |
81 | 0 | DECLARE_ALIGNED(256, static const int16_t, sobel_b[3]) = { 1, 2, 1 }; |
82 | 0 | const int taps = 3; |
83 | 0 | int im_h = h + taps - 1; |
84 | 0 | int im_stride = w; |
85 | 0 | const int fo_vert = 1; |
86 | 0 | const int fo_horiz = 1; |
87 | | |
88 | | // horizontal filter |
89 | 0 | const uint8_t *src_horiz = src - fo_vert * src_stride; |
90 | 0 | const int16_t *x_filter = dir ? sobel_a : sobel_b; |
91 | 0 | for (int y = 0; y < im_h; ++y) { |
92 | 0 | for (int x = 0; x < w; ++x) { |
93 | 0 | int16_t sum = 0; |
94 | 0 | for (int k = 0; k < taps; ++k) { |
95 | 0 | sum += x_filter[k] * src_horiz[y * src_stride + x - fo_horiz + k]; |
96 | 0 | } |
97 | 0 | im_block[y * im_stride + x] = sum; |
98 | 0 | } |
99 | 0 | } |
100 | | |
101 | | // vertical filter |
102 | 0 | int16_t *src_vert = im_block + fo_vert * im_stride; |
103 | 0 | const int16_t *y_filter = dir ? sobel_b : sobel_a; |
104 | 0 | for (int y = 0; y < h; ++y) { |
105 | 0 | for (int x = 0; x < w; ++x) { |
106 | 0 | int16_t sum = 0; |
107 | 0 | for (int k = 0; k < taps; ++k) { |
108 | 0 | sum += y_filter[k] * src_vert[(y - fo_vert + k) * im_stride + x]; |
109 | 0 | } |
110 | 0 | dst[y * dst_stride + x] = sum * norm; |
111 | 0 | } |
112 | 0 | } |
113 | 0 | } |
114 | | |
115 | | void av1_convolve_2d_sr_c(const uint8_t *src, int src_stride, uint8_t *dst, |
116 | | int dst_stride, int w, int h, |
117 | | const InterpFilterParams *filter_params_x, |
118 | | const InterpFilterParams *filter_params_y, |
119 | | const int subpel_x_qn, const int subpel_y_qn, |
120 | 16.3k | ConvolveParams *conv_params) { |
121 | 16.3k | int16_t im_block[(MAX_SB_SIZE + MAX_FILTER_TAP - 1) * MAX_SB_SIZE]; |
122 | 16.3k | int im_h = h + filter_params_y->taps - 1; |
123 | 16.3k | int im_stride = w; |
124 | 16.3k | assert(w <= MAX_SB_SIZE && h <= MAX_SB_SIZE); |
125 | 16.3k | const int fo_vert = filter_params_y->taps / 2 - 1; |
126 | 16.3k | const int fo_horiz = filter_params_x->taps / 2 - 1; |
127 | 16.3k | const int bd = 8; |
128 | 16.3k | const int bits = |
129 | 16.3k | FILTER_BITS * 2 - conv_params->round_0 - conv_params->round_1; |
130 | | |
131 | | // horizontal filter |
132 | 16.3k | const uint8_t *src_horiz = src - fo_vert * src_stride; |
133 | 16.3k | const int16_t *x_filter = av1_get_interp_filter_subpel_kernel( |
134 | 16.3k | filter_params_x, subpel_x_qn & SUBPEL_MASK); |
135 | 192k | for (int y = 0; y < im_h; ++y) { |
136 | 1.63M | for (int x = 0; x < w; ++x) { |
137 | 1.45M | int32_t sum = (1 << (bd + FILTER_BITS - 1)); |
138 | 7.78M | for (int k = 0; k < filter_params_x->taps; ++k) { |
139 | 6.32M | sum += x_filter[k] * src_horiz[y * src_stride + x - fo_horiz + k]; |
140 | 6.32M | } |
141 | 1.45M | assert(0 <= sum && sum < (1 << (bd + FILTER_BITS + 1))); |
142 | 1.45M | im_block[y * im_stride + x] = |
143 | 1.45M | (int16_t)ROUND_POWER_OF_TWO(sum, conv_params->round_0); |
144 | 1.45M | } |
145 | 175k | } |
146 | | |
147 | | // vertical filter |
148 | 16.3k | int16_t *src_vert = im_block + fo_vert * im_stride; |
149 | 16.3k | const int16_t *y_filter = av1_get_interp_filter_subpel_kernel( |
150 | 16.3k | filter_params_y, subpel_y_qn & SUBPEL_MASK); |
151 | 16.3k | const int offset_bits = bd + 2 * FILTER_BITS - conv_params->round_0; |
152 | 125k | for (int y = 0; y < h; ++y) { |
153 | 1.19M | for (int x = 0; x < w; ++x) { |
154 | 1.08M | int32_t sum = 1 << offset_bits; |
155 | 4.85M | for (int k = 0; k < filter_params_y->taps; ++k) { |
156 | 3.77M | sum += y_filter[k] * src_vert[(y - fo_vert + k) * im_stride + x]; |
157 | 3.77M | } |
158 | 1.08M | assert(0 <= sum && sum < (1 << (offset_bits + 2))); |
159 | 1.08M | int16_t res = ROUND_POWER_OF_TWO(sum, conv_params->round_1) - |
160 | 1.08M | ((1 << (offset_bits - conv_params->round_1)) + |
161 | 1.08M | (1 << (offset_bits - conv_params->round_1 - 1))); |
162 | 1.08M | dst[y * dst_stride + x] = clip_pixel(ROUND_POWER_OF_TWO(res, bits)); |
163 | 1.08M | } |
164 | 108k | } |
165 | 16.3k | } |
166 | | |
167 | | void av1_convolve_y_sr_c(const uint8_t *src, int src_stride, uint8_t *dst, |
168 | | int dst_stride, int w, int h, |
169 | | const InterpFilterParams *filter_params_y, |
170 | 13.9k | const int subpel_y_qn) { |
171 | 13.9k | const int fo_vert = filter_params_y->taps / 2 - 1; |
172 | | |
173 | | // vertical filter |
174 | 13.9k | const int16_t *y_filter = av1_get_interp_filter_subpel_kernel( |
175 | 13.9k | filter_params_y, subpel_y_qn & SUBPEL_MASK); |
176 | 111k | for (int y = 0; y < h; ++y) { |
177 | 1.14M | for (int x = 0; x < w; ++x) { |
178 | 1.04M | int32_t res = 0; |
179 | 4.40M | for (int k = 0; k < filter_params_y->taps; ++k) { |
180 | 3.36M | res += y_filter[k] * src[(y - fo_vert + k) * src_stride + x]; |
181 | 3.36M | } |
182 | 1.04M | dst[y * dst_stride + x] = |
183 | 1.04M | clip_pixel(ROUND_POWER_OF_TWO(res, FILTER_BITS)); |
184 | 1.04M | } |
185 | 97.1k | } |
186 | 13.9k | } |
187 | | |
188 | | void av1_convolve_x_sr_c(const uint8_t *src, int src_stride, uint8_t *dst, |
189 | | int dst_stride, int w, int h, |
190 | | const InterpFilterParams *filter_params_x, |
191 | 11.1k | const int subpel_x_qn, ConvolveParams *conv_params) { |
192 | 11.1k | const int fo_horiz = filter_params_x->taps / 2 - 1; |
193 | 11.1k | const int bits = FILTER_BITS - conv_params->round_0; |
194 | | |
195 | 11.1k | assert(bits >= 0); |
196 | 11.1k | assert((FILTER_BITS - conv_params->round_1) >= 0 || |
197 | 11.1k | ((conv_params->round_0 + conv_params->round_1) == 2 * FILTER_BITS)); |
198 | | |
199 | | // horizontal filter |
200 | 11.1k | const int16_t *x_filter = av1_get_interp_filter_subpel_kernel( |
201 | 11.1k | filter_params_x, subpel_x_qn & SUBPEL_MASK); |
202 | | |
203 | 99.4k | for (int y = 0; y < h; ++y) { |
204 | 1.41M | for (int x = 0; x < w; ++x) { |
205 | 1.32M | int32_t res = 0; |
206 | 4.91M | for (int k = 0; k < filter_params_x->taps; ++k) { |
207 | 3.58M | res += x_filter[k] * src[y * src_stride + x - fo_horiz + k]; |
208 | 3.58M | } |
209 | 1.32M | res = ROUND_POWER_OF_TWO(res, conv_params->round_0); |
210 | 1.32M | dst[y * dst_stride + x] = clip_pixel(ROUND_POWER_OF_TWO(res, bits)); |
211 | 1.32M | } |
212 | 88.3k | } |
213 | 11.1k | } |
214 | | |
215 | | void av1_dist_wtd_convolve_2d_c(const uint8_t *src, int src_stride, |
216 | | uint8_t *dst, int dst_stride, int w, int h, |
217 | | const InterpFilterParams *filter_params_x, |
218 | | const InterpFilterParams *filter_params_y, |
219 | | const int subpel_x_qn, const int subpel_y_qn, |
220 | 10.0k | ConvolveParams *conv_params) { |
221 | 10.0k | CONV_BUF_TYPE *dst16 = conv_params->dst; |
222 | 10.0k | int dst16_stride = conv_params->dst_stride; |
223 | 10.0k | int16_t im_block[(MAX_SB_SIZE + MAX_FILTER_TAP - 1) * MAX_SB_SIZE]; |
224 | 10.0k | int im_h = h + filter_params_y->taps - 1; |
225 | 10.0k | int im_stride = w; |
226 | 10.0k | const int fo_vert = filter_params_y->taps / 2 - 1; |
227 | 10.0k | const int fo_horiz = filter_params_x->taps / 2 - 1; |
228 | 10.0k | const int bd = 8; |
229 | 10.0k | const int round_bits = |
230 | 10.0k | 2 * FILTER_BITS - conv_params->round_0 - conv_params->round_1; |
231 | | |
232 | | // horizontal filter |
233 | 10.0k | const uint8_t *src_horiz = src - fo_vert * src_stride; |
234 | 10.0k | const int16_t *x_filter = av1_get_interp_filter_subpel_kernel( |
235 | 10.0k | filter_params_x, subpel_x_qn & SUBPEL_MASK); |
236 | 166k | for (int y = 0; y < im_h; ++y) { |
237 | 1.37M | for (int x = 0; x < w; ++x) { |
238 | 1.21M | int32_t sum = (1 << (bd + FILTER_BITS - 1)); |
239 | 10.9M | for (int k = 0; k < filter_params_x->taps; ++k) { |
240 | 9.73M | sum += x_filter[k] * src_horiz[y * src_stride + x - fo_horiz + k]; |
241 | 9.73M | } |
242 | 1.21M | assert(0 <= sum && sum < (1 << (bd + FILTER_BITS + 1))); |
243 | 1.21M | im_block[y * im_stride + x] = |
244 | 1.21M | (int16_t)ROUND_POWER_OF_TWO(sum, conv_params->round_0); |
245 | 1.21M | } |
246 | 156k | } |
247 | | |
248 | | // vertical filter |
249 | 10.0k | int16_t *src_vert = im_block + fo_vert * im_stride; |
250 | 10.0k | const int16_t *y_filter = av1_get_interp_filter_subpel_kernel( |
251 | 10.0k | filter_params_y, subpel_y_qn & SUBPEL_MASK); |
252 | 10.0k | const int offset_bits = bd + 2 * FILTER_BITS - conv_params->round_0; |
253 | 96.2k | for (int y = 0; y < h; ++y) { |
254 | 764k | for (int x = 0; x < w; ++x) { |
255 | 678k | int32_t sum = 1 << offset_bits; |
256 | 6.10M | for (int k = 0; k < filter_params_y->taps; ++k) { |
257 | 5.42M | sum += y_filter[k] * src_vert[(y - fo_vert + k) * im_stride + x]; |
258 | 5.42M | } |
259 | 678k | assert(0 <= sum && sum < (1 << (offset_bits + 2))); |
260 | 678k | CONV_BUF_TYPE res = ROUND_POWER_OF_TWO(sum, conv_params->round_1); |
261 | 678k | if (conv_params->do_average) { |
262 | 284k | int32_t tmp = dst16[y * dst16_stride + x]; |
263 | 284k | if (conv_params->use_dist_wtd_comp_avg) { |
264 | 77.1k | tmp = tmp * conv_params->fwd_offset + res * conv_params->bck_offset; |
265 | 77.1k | tmp = tmp >> DIST_PRECISION_BITS; |
266 | 207k | } else { |
267 | 207k | tmp += res; |
268 | 207k | tmp = tmp >> 1; |
269 | 207k | } |
270 | 284k | tmp -= (1 << (offset_bits - conv_params->round_1)) + |
271 | 284k | (1 << (offset_bits - conv_params->round_1 - 1)); |
272 | 284k | dst[y * dst_stride + x] = |
273 | 284k | clip_pixel(ROUND_POWER_OF_TWO(tmp, round_bits)); |
274 | 393k | } else { |
275 | 393k | dst16[y * dst16_stride + x] = res; |
276 | 393k | } |
277 | 678k | } |
278 | 86.2k | } |
279 | 10.0k | } |
280 | | |
281 | | void av1_dist_wtd_convolve_y_c(const uint8_t *src, int src_stride, uint8_t *dst, |
282 | | int dst_stride, int w, int h, |
283 | | const InterpFilterParams *filter_params_y, |
284 | | const int subpel_y_qn, |
285 | 7.95k | ConvolveParams *conv_params) { |
286 | 7.95k | CONV_BUF_TYPE *dst16 = conv_params->dst; |
287 | 7.95k | int dst16_stride = conv_params->dst_stride; |
288 | 7.95k | const int fo_vert = filter_params_y->taps / 2 - 1; |
289 | 7.95k | const int bits = FILTER_BITS - conv_params->round_0; |
290 | 7.95k | const int bd = 8; |
291 | 7.95k | const int offset_bits = bd + 2 * FILTER_BITS - conv_params->round_0; |
292 | 7.95k | const int round_offset = (1 << (offset_bits - conv_params->round_1)) + |
293 | 7.95k | (1 << (offset_bits - conv_params->round_1 - 1)); |
294 | 7.95k | const int round_bits = |
295 | 7.95k | 2 * FILTER_BITS - conv_params->round_0 - conv_params->round_1; |
296 | | |
297 | | // vertical filter |
298 | 7.95k | const int16_t *y_filter = av1_get_interp_filter_subpel_kernel( |
299 | 7.95k | filter_params_y, subpel_y_qn & SUBPEL_MASK); |
300 | 82.6k | for (int y = 0; y < h; ++y) { |
301 | 668k | for (int x = 0; x < w; ++x) { |
302 | 594k | int32_t res = 0; |
303 | 5.34M | for (int k = 0; k < filter_params_y->taps; ++k) { |
304 | 4.75M | res += y_filter[k] * src[(y - fo_vert + k) * src_stride + x]; |
305 | 4.75M | } |
306 | 594k | res *= (1 << bits); |
307 | 594k | res = ROUND_POWER_OF_TWO(res, conv_params->round_1) + round_offset; |
308 | | |
309 | 594k | if (conv_params->do_average) { |
310 | 171k | int32_t tmp = dst16[y * dst16_stride + x]; |
311 | 171k | if (conv_params->use_dist_wtd_comp_avg) { |
312 | 34.7k | tmp = tmp * conv_params->fwd_offset + res * conv_params->bck_offset; |
313 | 34.7k | tmp = tmp >> DIST_PRECISION_BITS; |
314 | 136k | } else { |
315 | 136k | tmp += res; |
316 | 136k | tmp = tmp >> 1; |
317 | 136k | } |
318 | 171k | tmp -= round_offset; |
319 | 171k | dst[y * dst_stride + x] = |
320 | 171k | clip_pixel(ROUND_POWER_OF_TWO(tmp, round_bits)); |
321 | 422k | } else { |
322 | 422k | dst16[y * dst16_stride + x] = res; |
323 | 422k | } |
324 | 594k | } |
325 | 74.7k | } |
326 | 7.95k | } |
327 | | |
328 | | void av1_dist_wtd_convolve_x_c(const uint8_t *src, int src_stride, uint8_t *dst, |
329 | | int dst_stride, int w, int h, |
330 | | const InterpFilterParams *filter_params_x, |
331 | | const int subpel_x_qn, |
332 | 3.74k | ConvolveParams *conv_params) { |
333 | 3.74k | CONV_BUF_TYPE *dst16 = conv_params->dst; |
334 | 3.74k | int dst16_stride = conv_params->dst_stride; |
335 | 3.74k | const int fo_horiz = filter_params_x->taps / 2 - 1; |
336 | 3.74k | const int bits = FILTER_BITS - conv_params->round_1; |
337 | 3.74k | const int bd = 8; |
338 | 3.74k | const int offset_bits = bd + 2 * FILTER_BITS - conv_params->round_0; |
339 | 3.74k | const int round_offset = (1 << (offset_bits - conv_params->round_1)) + |
340 | 3.74k | (1 << (offset_bits - conv_params->round_1 - 1)); |
341 | 3.74k | const int round_bits = |
342 | 3.74k | 2 * FILTER_BITS - conv_params->round_0 - conv_params->round_1; |
343 | | |
344 | | // horizontal filter |
345 | 3.74k | const int16_t *x_filter = av1_get_interp_filter_subpel_kernel( |
346 | 3.74k | filter_params_x, subpel_x_qn & SUBPEL_MASK); |
347 | 44.1k | for (int y = 0; y < h; ++y) { |
348 | 369k | for (int x = 0; x < w; ++x) { |
349 | 329k | int32_t res = 0; |
350 | 2.96M | for (int k = 0; k < filter_params_x->taps; ++k) { |
351 | 2.63M | res += x_filter[k] * src[y * src_stride + x - fo_horiz + k]; |
352 | 2.63M | } |
353 | 329k | res = (1 << bits) * ROUND_POWER_OF_TWO(res, conv_params->round_0); |
354 | 329k | res += round_offset; |
355 | | |
356 | 329k | if (conv_params->do_average) { |
357 | 85.1k | int32_t tmp = dst16[y * dst16_stride + x]; |
358 | 85.1k | if (conv_params->use_dist_wtd_comp_avg) { |
359 | 37.1k | tmp = tmp * conv_params->fwd_offset + res * conv_params->bck_offset; |
360 | 37.1k | tmp = tmp >> DIST_PRECISION_BITS; |
361 | 48.0k | } else { |
362 | 48.0k | tmp += res; |
363 | 48.0k | tmp = tmp >> 1; |
364 | 48.0k | } |
365 | 85.1k | tmp -= round_offset; |
366 | 85.1k | dst[y * dst_stride + x] = |
367 | 85.1k | clip_pixel(ROUND_POWER_OF_TWO(tmp, round_bits)); |
368 | 243k | } else { |
369 | 243k | dst16[y * dst16_stride + x] = res; |
370 | 243k | } |
371 | 329k | } |
372 | 40.4k | } |
373 | 3.74k | } |
374 | | |
375 | | void av1_dist_wtd_convolve_2d_copy_c(const uint8_t *src, int src_stride, |
376 | | uint8_t *dst, int dst_stride, int w, int h, |
377 | 8.16k | ConvolveParams *conv_params) { |
378 | 8.16k | CONV_BUF_TYPE *dst16 = conv_params->dst; |
379 | 8.16k | int dst16_stride = conv_params->dst_stride; |
380 | 8.16k | const int bits = |
381 | 8.16k | FILTER_BITS * 2 - conv_params->round_1 - conv_params->round_0; |
382 | 8.16k | const int bd = 8; |
383 | 8.16k | const int offset_bits = bd + 2 * FILTER_BITS - conv_params->round_0; |
384 | 8.16k | const int round_offset = (1 << (offset_bits - conv_params->round_1)) + |
385 | 8.16k | (1 << (offset_bits - conv_params->round_1 - 1)); |
386 | | |
387 | 81.6k | for (int y = 0; y < h; ++y) { |
388 | 672k | for (int x = 0; x < w; ++x) { |
389 | 598k | CONV_BUF_TYPE res = src[y * src_stride + x] << bits; |
390 | 598k | res += round_offset; |
391 | | |
392 | 598k | if (conv_params->do_average) { |
393 | 178k | int32_t tmp = dst16[y * dst16_stride + x]; |
394 | 178k | if (conv_params->use_dist_wtd_comp_avg) { |
395 | 34.3k | tmp = tmp * conv_params->fwd_offset + res * conv_params->bck_offset; |
396 | 34.3k | tmp = tmp >> DIST_PRECISION_BITS; |
397 | 143k | } else { |
398 | 143k | tmp += res; |
399 | 143k | tmp = tmp >> 1; |
400 | 143k | } |
401 | 178k | tmp -= round_offset; |
402 | 178k | dst[y * dst_stride + x] = clip_pixel(ROUND_POWER_OF_TWO(tmp, bits)); |
403 | 420k | } else { |
404 | 420k | dst16[y * dst16_stride + x] = res; |
405 | 420k | } |
406 | 598k | } |
407 | 73.4k | } |
408 | 8.16k | } |
409 | | |
410 | | void av1_convolve_2d_scale_c(const uint8_t *src, int src_stride, uint8_t *dst, |
411 | | int dst_stride, int w, int h, |
412 | | const InterpFilterParams *filter_params_x, |
413 | | const InterpFilterParams *filter_params_y, |
414 | | const int subpel_x_qn, const int x_step_qn, |
415 | | const int subpel_y_qn, const int y_step_qn, |
416 | 8.22k | ConvolveParams *conv_params) { |
417 | 8.22k | int16_t im_block[(2 * MAX_SB_SIZE + MAX_FILTER_TAP) * MAX_SB_SIZE]; |
418 | 8.22k | int im_h = (((h - 1) * y_step_qn + subpel_y_qn) >> SCALE_SUBPEL_BITS) + |
419 | 8.22k | filter_params_y->taps; |
420 | 8.22k | CONV_BUF_TYPE *dst16 = conv_params->dst; |
421 | 8.22k | const int dst16_stride = conv_params->dst_stride; |
422 | 8.22k | const int bits = |
423 | 8.22k | FILTER_BITS * 2 - conv_params->round_0 - conv_params->round_1; |
424 | 8.22k | assert(bits >= 0); |
425 | 8.22k | int im_stride = w; |
426 | 8.22k | const int fo_vert = filter_params_y->taps / 2 - 1; |
427 | 8.22k | const int fo_horiz = filter_params_x->taps / 2 - 1; |
428 | 8.22k | const int bd = 8; |
429 | | |
430 | | // horizontal filter |
431 | 8.22k | const uint8_t *src_horiz = src - fo_vert * src_stride; |
432 | 123k | for (int y = 0; y < im_h; ++y) { |
433 | 115k | int x_qn = subpel_x_qn; |
434 | 985k | for (int x = 0; x < w; ++x, x_qn += x_step_qn) { |
435 | 869k | const uint8_t *const src_x = &src_horiz[(x_qn >> SCALE_SUBPEL_BITS)]; |
436 | 869k | const int x_filter_idx = (x_qn & SCALE_SUBPEL_MASK) >> SCALE_EXTRA_BITS; |
437 | 869k | assert(x_filter_idx < SUBPEL_SHIFTS); |
438 | 869k | const int16_t *x_filter = |
439 | 869k | av1_get_interp_filter_subpel_kernel(filter_params_x, x_filter_idx); |
440 | 869k | int32_t sum = (1 << (bd + FILTER_BITS - 1)); |
441 | 7.82M | for (int k = 0; k < filter_params_x->taps; ++k) { |
442 | 6.95M | sum += x_filter[k] * src_x[k - fo_horiz]; |
443 | 6.95M | } |
444 | 869k | assert(0 <= sum && sum < (1 << (bd + FILTER_BITS + 1))); |
445 | 869k | im_block[y * im_stride + x] = |
446 | 869k | (int16_t)ROUND_POWER_OF_TWO(sum, conv_params->round_0); |
447 | 869k | } |
448 | 115k | src_horiz += src_stride; |
449 | 115k | } |
450 | | |
451 | | // vertical filter |
452 | 8.22k | int16_t *src_vert = im_block + fo_vert * im_stride; |
453 | 8.22k | const int offset_bits = bd + 2 * FILTER_BITS - conv_params->round_0; |
454 | 64.2k | for (int x = 0; x < w; ++x) { |
455 | 56.0k | int y_qn = subpel_y_qn; |
456 | 523k | for (int y = 0; y < h; ++y, y_qn += y_step_qn) { |
457 | 467k | const int16_t *src_y = &src_vert[(y_qn >> SCALE_SUBPEL_BITS) * im_stride]; |
458 | 467k | const int y_filter_idx = (y_qn & SCALE_SUBPEL_MASK) >> SCALE_EXTRA_BITS; |
459 | 467k | assert(y_filter_idx < SUBPEL_SHIFTS); |
460 | 467k | const int16_t *y_filter = |
461 | 467k | av1_get_interp_filter_subpel_kernel(filter_params_y, y_filter_idx); |
462 | 467k | int32_t sum = 1 << offset_bits; |
463 | 4.20M | for (int k = 0; k < filter_params_y->taps; ++k) { |
464 | 3.73M | sum += y_filter[k] * src_y[(k - fo_vert) * im_stride]; |
465 | 3.73M | } |
466 | 467k | assert(0 <= sum && sum < (1 << (offset_bits + 2))); |
467 | 467k | CONV_BUF_TYPE res = ROUND_POWER_OF_TWO(sum, conv_params->round_1); |
468 | 467k | if (conv_params->is_compound) { |
469 | 162k | if (conv_params->do_average) { |
470 | 62.9k | int32_t tmp = dst16[y * dst16_stride + x]; |
471 | 62.9k | if (conv_params->use_dist_wtd_comp_avg) { |
472 | 14.2k | tmp = tmp * conv_params->fwd_offset + res * conv_params->bck_offset; |
473 | 14.2k | tmp = tmp >> DIST_PRECISION_BITS; |
474 | 48.7k | } else { |
475 | 48.7k | tmp += res; |
476 | 48.7k | tmp = tmp >> 1; |
477 | 48.7k | } |
478 | | /* Subtract round offset and convolve round */ |
479 | 62.9k | tmp = tmp - ((1 << (offset_bits - conv_params->round_1)) + |
480 | 62.9k | (1 << (offset_bits - conv_params->round_1 - 1))); |
481 | 62.9k | dst[y * dst_stride + x] = clip_pixel(ROUND_POWER_OF_TWO(tmp, bits)); |
482 | 99.9k | } else { |
483 | 99.9k | dst16[y * dst16_stride + x] = res; |
484 | 99.9k | } |
485 | 304k | } else { |
486 | | /* Subtract round offset and convolve round */ |
487 | 304k | int32_t tmp = res - ((1 << (offset_bits - conv_params->round_1)) + |
488 | 304k | (1 << (offset_bits - conv_params->round_1 - 1))); |
489 | 304k | dst[y * dst_stride + x] = clip_pixel(ROUND_POWER_OF_TWO(tmp, bits)); |
490 | 304k | } |
491 | 467k | } |
492 | 56.0k | src_vert++; |
493 | 56.0k | } |
494 | 8.22k | } |
495 | | |
496 | | static void convolve_2d_scale_wrapper( |
497 | | const uint8_t *src, int src_stride, uint8_t *dst, int dst_stride, int w, |
498 | | int h, const InterpFilterParams *filter_params_x, |
499 | | const InterpFilterParams *filter_params_y, const int subpel_x_qn, |
500 | | const int x_step_qn, const int subpel_y_qn, const int y_step_qn, |
501 | 8.22k | ConvolveParams *conv_params) { |
502 | 8.22k | if (conv_params->is_compound) { |
503 | 1.86k | assert(conv_params->dst != NULL); |
504 | 1.86k | } |
505 | 8.22k | av1_convolve_2d_scale(src, src_stride, dst, dst_stride, w, h, filter_params_x, |
506 | 8.22k | filter_params_y, subpel_x_qn, x_step_qn, subpel_y_qn, |
507 | 8.22k | y_step_qn, conv_params); |
508 | 8.22k | } |
509 | | |
510 | | static void convolve_2d_facade_compound( |
511 | | const uint8_t *src, int src_stride, uint8_t *dst, int dst_stride, int w, |
512 | | int h, const InterpFilterParams *filter_params_x, |
513 | | const InterpFilterParams *filter_params_y, const int subpel_x_qn, |
514 | 29.9k | const int subpel_y_qn, ConvolveParams *conv_params) { |
515 | 29.9k | const bool need_x = subpel_x_qn != 0; |
516 | 29.9k | const bool need_y = subpel_y_qn != 0; |
517 | 29.9k | if (!need_x && !need_y) { |
518 | 8.16k | av1_dist_wtd_convolve_2d_copy(src, src_stride, dst, dst_stride, w, h, |
519 | 8.16k | conv_params); |
520 | 21.7k | } else if (need_x && !need_y) { |
521 | 3.74k | av1_dist_wtd_convolve_x(src, src_stride, dst, dst_stride, w, h, |
522 | 3.74k | filter_params_x, subpel_x_qn, conv_params); |
523 | 18.0k | } else if (!need_x && need_y) { |
524 | 7.95k | av1_dist_wtd_convolve_y(src, src_stride, dst, dst_stride, w, h, |
525 | 7.95k | filter_params_y, subpel_y_qn, conv_params); |
526 | 10.0k | } else { |
527 | 10.0k | assert(need_y && need_x); |
528 | 10.0k | av1_dist_wtd_convolve_2d(src, src_stride, dst, dst_stride, w, h, |
529 | 10.0k | filter_params_x, filter_params_y, subpel_x_qn, |
530 | 10.0k | subpel_y_qn, conv_params); |
531 | 10.0k | } |
532 | 29.9k | } |
533 | | |
534 | | static void convolve_2d_facade_single( |
535 | | const uint8_t *src, int src_stride, uint8_t *dst, int dst_stride, int w, |
536 | | int h, const InterpFilterParams *filter_params_x, |
537 | | const InterpFilterParams *filter_params_y, const int subpel_x_qn, |
538 | 82.8k | const int subpel_y_qn, ConvolveParams *conv_params) { |
539 | 82.8k | const bool need_x = subpel_x_qn != 0; |
540 | 82.8k | const bool need_y = subpel_y_qn != 0; |
541 | 82.8k | if (!need_x && !need_y) { |
542 | 64.9k | aom_convolve_copy(src, src_stride, dst, dst_stride, w, h); |
543 | 64.9k | } else if (need_x && !need_y) { |
544 | 3.17k | av1_convolve_x_sr(src, src_stride, dst, dst_stride, w, h, filter_params_x, |
545 | 3.17k | subpel_x_qn, conv_params); |
546 | 14.7k | } else if (!need_x && need_y) { |
547 | 6.30k | av1_convolve_y_sr(src, src_stride, dst, dst_stride, w, h, filter_params_y, |
548 | 6.30k | subpel_y_qn); |
549 | 8.42k | } else { |
550 | 8.42k | assert(need_x && need_y); |
551 | 8.42k | av1_convolve_2d_sr(src, src_stride, dst, dst_stride, w, h, filter_params_x, |
552 | 8.42k | filter_params_y, subpel_x_qn, subpel_y_qn, conv_params); |
553 | 8.42k | } |
554 | 82.8k | } |
555 | | |
556 | | void av1_convolve_2d_facade(const uint8_t *src, int src_stride, uint8_t *dst, |
557 | | int dst_stride, int w, int h, |
558 | | const InterpFilterParams *interp_filters[2], |
559 | | const int subpel_x_qn, int x_step_q4, |
560 | | const int subpel_y_qn, int y_step_q4, int scaled, |
561 | 144k | ConvolveParams *conv_params) { |
562 | 144k | (void)x_step_q4; |
563 | 144k | (void)y_step_q4; |
564 | 144k | (void)dst; |
565 | 144k | (void)dst_stride; |
566 | | |
567 | 144k | const InterpFilterParams *filter_params_x = interp_filters[0]; |
568 | 144k | const InterpFilterParams *filter_params_y = interp_filters[1]; |
569 | | |
570 | | // TODO(jingning, yunqing): Add SIMD support to 2-tap filter case. |
571 | | // Do we have SIMD support to 4-tap case? |
572 | | // 2-tap filter indicates that it is for IntraBC. |
573 | 144k | if (filter_params_x->taps == 2 || filter_params_y->taps == 2) { |
574 | 68.9k | assert(filter_params_x->taps == 2 && filter_params_y->taps == 2); |
575 | 68.9k | assert(!scaled); |
576 | 68.9k | if (subpel_x_qn && subpel_y_qn) { |
577 | 7.94k | av1_convolve_2d_sr_c(src, src_stride, dst, dst_stride, w, h, |
578 | 7.94k | filter_params_x, filter_params_y, subpel_x_qn, |
579 | 7.94k | subpel_y_qn, conv_params); |
580 | 7.94k | return; |
581 | 61.0k | } else if (subpel_x_qn) { |
582 | 7.94k | av1_convolve_x_sr_c(src, src_stride, dst, dst_stride, w, h, |
583 | 7.94k | filter_params_x, subpel_x_qn, conv_params); |
584 | 7.94k | return; |
585 | 53.0k | } else if (subpel_y_qn) { |
586 | 7.61k | av1_convolve_y_sr_c(src, src_stride, dst, dst_stride, w, h, |
587 | 7.61k | filter_params_y, subpel_y_qn); |
588 | 7.61k | return; |
589 | 7.61k | } |
590 | 68.9k | } |
591 | | |
592 | 120k | if (scaled) { |
593 | 8.22k | convolve_2d_scale_wrapper(src, src_stride, dst, dst_stride, w, h, |
594 | 8.22k | filter_params_x, filter_params_y, subpel_x_qn, |
595 | 8.22k | x_step_q4, subpel_y_qn, y_step_q4, conv_params); |
596 | 112k | } else if (conv_params->is_compound) { |
597 | 29.9k | convolve_2d_facade_compound(src, src_stride, dst, dst_stride, w, h, |
598 | 29.9k | filter_params_x, filter_params_y, subpel_x_qn, |
599 | 29.9k | subpel_y_qn, conv_params); |
600 | 82.8k | } else { |
601 | 82.8k | convolve_2d_facade_single(src, src_stride, dst, dst_stride, w, h, |
602 | 82.8k | filter_params_x, filter_params_y, subpel_x_qn, |
603 | 82.8k | subpel_y_qn, conv_params); |
604 | 82.8k | } |
605 | 120k | } |
606 | | |
607 | | #if CONFIG_AV1_HIGHBITDEPTH |
608 | | void av1_highbd_convolve_x_sr_c(const uint16_t *src, int src_stride, |
609 | | uint16_t *dst, int dst_stride, int w, int h, |
610 | | const InterpFilterParams *filter_params_x, |
611 | | const int subpel_x_qn, |
612 | 32.8k | ConvolveParams *conv_params, int bd) { |
613 | 32.8k | const int fo_horiz = filter_params_x->taps / 2 - 1; |
614 | 32.8k | const int bits = FILTER_BITS - conv_params->round_0; |
615 | | |
616 | 32.8k | assert(bits >= 0); |
617 | 32.8k | assert((FILTER_BITS - conv_params->round_1) >= 0 || |
618 | 32.8k | ((conv_params->round_0 + conv_params->round_1) == 2 * FILTER_BITS)); |
619 | | |
620 | | // horizontal filter |
621 | 32.8k | const int16_t *x_filter = av1_get_interp_filter_subpel_kernel( |
622 | 32.8k | filter_params_x, subpel_x_qn & SUBPEL_MASK); |
623 | 262k | for (int y = 0; y < h; ++y) { |
624 | 2.59M | for (int x = 0; x < w; ++x) { |
625 | 2.36M | int32_t res = 0; |
626 | 10.3M | for (int k = 0; k < filter_params_x->taps; ++k) { |
627 | 7.96M | res += x_filter[k] * src[y * src_stride + x - fo_horiz + k]; |
628 | 7.96M | } |
629 | 2.36M | res = ROUND_POWER_OF_TWO(res, conv_params->round_0); |
630 | 2.36M | dst[y * dst_stride + x] = |
631 | 2.36M | clip_pixel_highbd(ROUND_POWER_OF_TWO(res, bits), bd); |
632 | 2.36M | } |
633 | 229k | } |
634 | 32.8k | } |
635 | | |
636 | | void av1_highbd_convolve_y_sr_c(const uint16_t *src, int src_stride, |
637 | | uint16_t *dst, int dst_stride, int w, int h, |
638 | | const InterpFilterParams *filter_params_y, |
639 | 25.1k | const int subpel_y_qn, int bd) { |
640 | 25.1k | const int fo_vert = filter_params_y->taps / 2 - 1; |
641 | | // vertical filter |
642 | 25.1k | const int16_t *y_filter = av1_get_interp_filter_subpel_kernel( |
643 | 25.1k | filter_params_y, subpel_y_qn & SUBPEL_MASK); |
644 | 188k | for (int y = 0; y < h; ++y) { |
645 | 1.55M | for (int x = 0; x < w; ++x) { |
646 | 1.39M | int32_t res = 0; |
647 | 5.34M | for (int k = 0; k < filter_params_y->taps; ++k) { |
648 | 3.94M | res += y_filter[k] * src[(y - fo_vert + k) * src_stride + x]; |
649 | 3.94M | } |
650 | 1.39M | dst[y * dst_stride + x] = |
651 | 1.39M | clip_pixel_highbd(ROUND_POWER_OF_TWO(res, FILTER_BITS), bd); |
652 | 1.39M | } |
653 | 162k | } |
654 | 25.1k | } |
655 | | |
656 | | void av1_highbd_convolve_2d_sr_c(const uint16_t *src, int src_stride, |
657 | | uint16_t *dst, int dst_stride, int w, int h, |
658 | | const InterpFilterParams *filter_params_x, |
659 | | const InterpFilterParams *filter_params_y, |
660 | | const int subpel_x_qn, const int subpel_y_qn, |
661 | 29.0k | ConvolveParams *conv_params, int bd) { |
662 | 29.0k | int16_t im_block[(MAX_SB_SIZE + MAX_FILTER_TAP - 1) * MAX_SB_SIZE]; |
663 | 29.0k | int im_h = h + filter_params_y->taps - 1; |
664 | 29.0k | int im_stride = w; |
665 | 29.0k | assert(w <= MAX_SB_SIZE && h <= MAX_SB_SIZE); |
666 | 29.0k | const int fo_vert = filter_params_y->taps / 2 - 1; |
667 | 29.0k | const int fo_horiz = filter_params_x->taps / 2 - 1; |
668 | 29.0k | const int bits = |
669 | 29.0k | FILTER_BITS * 2 - conv_params->round_0 - conv_params->round_1; |
670 | 29.0k | assert(bits >= 0); |
671 | | |
672 | | // horizontal filter |
673 | 29.0k | const uint16_t *src_horiz = src - fo_vert * src_stride; |
674 | 29.0k | const int16_t *x_filter = av1_get_interp_filter_subpel_kernel( |
675 | 29.0k | filter_params_x, subpel_x_qn & SUBPEL_MASK); |
676 | 286k | for (int y = 0; y < im_h; ++y) { |
677 | 2.41M | for (int x = 0; x < w; ++x) { |
678 | 2.15M | int32_t sum = (1 << (bd + FILTER_BITS - 1)); |
679 | 9.71M | for (int k = 0; k < filter_params_x->taps; ++k) { |
680 | 7.55M | sum += x_filter[k] * src_horiz[y * src_stride + x - fo_horiz + k]; |
681 | 7.55M | } |
682 | 2.15M | assert(0 <= sum && sum < (1 << (bd + FILTER_BITS + 1))); |
683 | 2.15M | im_block[y * im_stride + x] = |
684 | 2.15M | ROUND_POWER_OF_TWO(sum, conv_params->round_0); |
685 | 2.15M | } |
686 | 257k | } |
687 | | |
688 | | // vertical filter |
689 | 29.0k | int16_t *src_vert = im_block + fo_vert * im_stride; |
690 | 29.0k | const int16_t *y_filter = av1_get_interp_filter_subpel_kernel( |
691 | 29.0k | filter_params_y, subpel_y_qn & SUBPEL_MASK); |
692 | 29.0k | const int offset_bits = bd + 2 * FILTER_BITS - conv_params->round_0; |
693 | 221k | for (int y = 0; y < h; ++y) { |
694 | 1.91M | for (int x = 0; x < w; ++x) { |
695 | 1.72M | int32_t sum = 1 << offset_bits; |
696 | 6.83M | for (int k = 0; k < filter_params_y->taps; ++k) { |
697 | 5.11M | sum += y_filter[k] * src_vert[(y - fo_vert + k) * im_stride + x]; |
698 | 5.11M | } |
699 | 1.72M | assert(0 <= sum && sum < (1 << (offset_bits + 2))); |
700 | 1.72M | int32_t res = ROUND_POWER_OF_TWO(sum, conv_params->round_1) - |
701 | 1.72M | ((1 << (offset_bits - conv_params->round_1)) + |
702 | 1.72M | (1 << (offset_bits - conv_params->round_1 - 1))); |
703 | 1.72M | dst[y * dst_stride + x] = |
704 | 1.72M | clip_pixel_highbd(ROUND_POWER_OF_TWO(res, bits), bd); |
705 | 1.72M | } |
706 | 192k | } |
707 | 29.0k | } |
708 | | |
709 | | void av1_highbd_dist_wtd_convolve_2d_c( |
710 | | const uint16_t *src, int src_stride, uint16_t *dst, int dst_stride, int w, |
711 | | int h, const InterpFilterParams *filter_params_x, |
712 | | const InterpFilterParams *filter_params_y, const int subpel_x_qn, |
713 | 4.47k | const int subpel_y_qn, ConvolveParams *conv_params, int bd) { |
714 | 4.47k | int x, y, k; |
715 | 4.47k | int16_t im_block[(MAX_SB_SIZE + MAX_FILTER_TAP - 1) * MAX_SB_SIZE]; |
716 | 4.47k | CONV_BUF_TYPE *dst16 = conv_params->dst; |
717 | 4.47k | int dst16_stride = conv_params->dst_stride; |
718 | 4.47k | int im_h = h + filter_params_y->taps - 1; |
719 | 4.47k | int im_stride = w; |
720 | 4.47k | const int fo_vert = filter_params_y->taps / 2 - 1; |
721 | 4.47k | const int fo_horiz = filter_params_x->taps / 2 - 1; |
722 | 4.47k | const int round_bits = |
723 | 4.47k | 2 * FILTER_BITS - conv_params->round_0 - conv_params->round_1; |
724 | 4.47k | assert(round_bits >= 0); |
725 | | |
726 | | // horizontal filter |
727 | 4.47k | const uint16_t *src_horiz = src - fo_vert * src_stride; |
728 | 4.47k | const int16_t *x_filter = av1_get_interp_filter_subpel_kernel( |
729 | 4.47k | filter_params_x, subpel_x_qn & SUBPEL_MASK); |
730 | 76.4k | for (y = 0; y < im_h; ++y) { |
731 | 700k | for (x = 0; x < w; ++x) { |
732 | 628k | int32_t sum = (1 << (bd + FILTER_BITS - 1)); |
733 | 5.65M | for (k = 0; k < filter_params_x->taps; ++k) { |
734 | 5.02M | sum += x_filter[k] * src_horiz[y * src_stride + x - fo_horiz + k]; |
735 | 5.02M | } |
736 | 628k | assert(0 <= sum && sum < (1 << (bd + FILTER_BITS + 1))); |
737 | 628k | (void)bd; |
738 | 628k | im_block[y * im_stride + x] = |
739 | 628k | (int16_t)ROUND_POWER_OF_TWO(sum, conv_params->round_0); |
740 | 628k | } |
741 | 71.9k | } |
742 | | |
743 | | // vertical filter |
744 | 4.47k | int16_t *src_vert = im_block + fo_vert * im_stride; |
745 | 4.47k | const int offset_bits = bd + 2 * FILTER_BITS - conv_params->round_0; |
746 | 4.47k | const int16_t *y_filter = av1_get_interp_filter_subpel_kernel( |
747 | 4.47k | filter_params_y, subpel_y_qn & SUBPEL_MASK); |
748 | 45.1k | for (y = 0; y < h; ++y) { |
749 | 406k | for (x = 0; x < w; ++x) { |
750 | 365k | int32_t sum = 1 << offset_bits; |
751 | 3.28M | for (k = 0; k < filter_params_y->taps; ++k) { |
752 | 2.92M | sum += y_filter[k] * src_vert[(y - fo_vert + k) * im_stride + x]; |
753 | 2.92M | } |
754 | 365k | assert(0 <= sum && sum < (1 << (offset_bits + 2))); |
755 | 365k | CONV_BUF_TYPE res = ROUND_POWER_OF_TWO(sum, conv_params->round_1); |
756 | 365k | if (conv_params->do_average) { |
757 | 133k | int32_t tmp = dst16[y * dst16_stride + x]; |
758 | 133k | if (conv_params->use_dist_wtd_comp_avg) { |
759 | 23.4k | tmp = tmp * conv_params->fwd_offset + res * conv_params->bck_offset; |
760 | 23.4k | tmp = tmp >> DIST_PRECISION_BITS; |
761 | 110k | } else { |
762 | 110k | tmp += res; |
763 | 110k | tmp = tmp >> 1; |
764 | 110k | } |
765 | 133k | tmp -= (1 << (offset_bits - conv_params->round_1)) + |
766 | 133k | (1 << (offset_bits - conv_params->round_1 - 1)); |
767 | 133k | dst[y * dst_stride + x] = |
768 | 133k | clip_pixel_highbd(ROUND_POWER_OF_TWO(tmp, round_bits), bd); |
769 | 232k | } else { |
770 | 232k | dst16[y * dst16_stride + x] = res; |
771 | 232k | } |
772 | 365k | } |
773 | 40.6k | } |
774 | 4.47k | } |
775 | | |
776 | | void av1_highbd_dist_wtd_convolve_x_c(const uint16_t *src, int src_stride, |
777 | | uint16_t *dst, int dst_stride, int w, |
778 | | int h, |
779 | | const InterpFilterParams *filter_params_x, |
780 | | const int subpel_x_qn, |
781 | 6.60k | ConvolveParams *conv_params, int bd) { |
782 | 6.60k | CONV_BUF_TYPE *dst16 = conv_params->dst; |
783 | 6.60k | int dst16_stride = conv_params->dst_stride; |
784 | 6.60k | const int fo_horiz = filter_params_x->taps / 2 - 1; |
785 | 6.60k | const int bits = FILTER_BITS - conv_params->round_1; |
786 | 6.60k | const int offset_bits = bd + 2 * FILTER_BITS - conv_params->round_0; |
787 | 6.60k | const int round_offset = (1 << (offset_bits - conv_params->round_1)) + |
788 | 6.60k | (1 << (offset_bits - conv_params->round_1 - 1)); |
789 | 6.60k | const int round_bits = |
790 | 6.60k | 2 * FILTER_BITS - conv_params->round_0 - conv_params->round_1; |
791 | 6.60k | assert(round_bits >= 0); |
792 | 6.60k | assert(bits >= 0); |
793 | | // horizontal filter |
794 | 6.60k | const int16_t *x_filter = av1_get_interp_filter_subpel_kernel( |
795 | 6.60k | filter_params_x, subpel_x_qn & SUBPEL_MASK); |
796 | 72.1k | for (int y = 0; y < h; ++y) { |
797 | 573k | for (int x = 0; x < w; ++x) { |
798 | 508k | int32_t res = 0; |
799 | 4.57M | for (int k = 0; k < filter_params_x->taps; ++k) { |
800 | 4.06M | res += x_filter[k] * src[y * src_stride + x - fo_horiz + k]; |
801 | 4.06M | } |
802 | 508k | res = (1 << bits) * ROUND_POWER_OF_TWO(res, conv_params->round_0); |
803 | 508k | res += round_offset; |
804 | | |
805 | 508k | if (conv_params->do_average) { |
806 | 269k | int32_t tmp = dst16[y * dst16_stride + x]; |
807 | 269k | if (conv_params->use_dist_wtd_comp_avg) { |
808 | 38.2k | tmp = tmp * conv_params->fwd_offset + res * conv_params->bck_offset; |
809 | 38.2k | tmp = tmp >> DIST_PRECISION_BITS; |
810 | 230k | } else { |
811 | 230k | tmp += res; |
812 | 230k | tmp = tmp >> 1; |
813 | 230k | } |
814 | 269k | tmp -= round_offset; |
815 | 269k | dst[y * dst_stride + x] = |
816 | 269k | clip_pixel_highbd(ROUND_POWER_OF_TWO(tmp, round_bits), bd); |
817 | 269k | } else { |
818 | 239k | dst16[y * dst16_stride + x] = res; |
819 | 239k | } |
820 | 508k | } |
821 | 65.5k | } |
822 | 6.60k | } |
823 | | |
824 | | void av1_highbd_dist_wtd_convolve_y_c(const uint16_t *src, int src_stride, |
825 | | uint16_t *dst, int dst_stride, int w, |
826 | | int h, |
827 | | const InterpFilterParams *filter_params_y, |
828 | | const int subpel_y_qn, |
829 | 2.58k | ConvolveParams *conv_params, int bd) { |
830 | 2.58k | CONV_BUF_TYPE *dst16 = conv_params->dst; |
831 | 2.58k | int dst16_stride = conv_params->dst_stride; |
832 | 2.58k | const int fo_vert = filter_params_y->taps / 2 - 1; |
833 | 2.58k | const int bits = FILTER_BITS - conv_params->round_0; |
834 | 2.58k | const int offset_bits = bd + 2 * FILTER_BITS - conv_params->round_0; |
835 | 2.58k | const int round_offset = (1 << (offset_bits - conv_params->round_1)) + |
836 | 2.58k | (1 << (offset_bits - conv_params->round_1 - 1)); |
837 | 2.58k | const int round_bits = |
838 | 2.58k | 2 * FILTER_BITS - conv_params->round_0 - conv_params->round_1; |
839 | 2.58k | assert(round_bits >= 0); |
840 | 2.58k | assert(bits >= 0); |
841 | | // vertical filter |
842 | 2.58k | const int16_t *y_filter = av1_get_interp_filter_subpel_kernel( |
843 | 2.58k | filter_params_y, subpel_y_qn & SUBPEL_MASK); |
844 | 28.9k | for (int y = 0; y < h; ++y) { |
845 | 258k | for (int x = 0; x < w; ++x) { |
846 | 232k | int32_t res = 0; |
847 | 2.09M | for (int k = 0; k < filter_params_y->taps; ++k) { |
848 | 1.85M | res += y_filter[k] * src[(y - fo_vert + k) * src_stride + x]; |
849 | 1.85M | } |
850 | 232k | res *= (1 << bits); |
851 | 232k | res = ROUND_POWER_OF_TWO(res, conv_params->round_1) + round_offset; |
852 | | |
853 | 232k | if (conv_params->do_average) { |
854 | 104k | int32_t tmp = dst16[y * dst16_stride + x]; |
855 | 104k | if (conv_params->use_dist_wtd_comp_avg) { |
856 | 22.0k | tmp = tmp * conv_params->fwd_offset + res * conv_params->bck_offset; |
857 | 22.0k | tmp = tmp >> DIST_PRECISION_BITS; |
858 | 82.6k | } else { |
859 | 82.6k | tmp += res; |
860 | 82.6k | tmp = tmp >> 1; |
861 | 82.6k | } |
862 | 104k | tmp -= round_offset; |
863 | 104k | dst[y * dst_stride + x] = |
864 | 104k | clip_pixel_highbd(ROUND_POWER_OF_TWO(tmp, round_bits), bd); |
865 | 127k | } else { |
866 | 127k | dst16[y * dst16_stride + x] = res; |
867 | 127k | } |
868 | 232k | } |
869 | 26.3k | } |
870 | 2.58k | } |
871 | | |
872 | | void av1_highbd_dist_wtd_convolve_2d_copy_c(const uint16_t *src, int src_stride, |
873 | | uint16_t *dst, int dst_stride, |
874 | | int w, int h, |
875 | | ConvolveParams *conv_params, |
876 | 25.2k | int bd) { |
877 | 25.2k | CONV_BUF_TYPE *dst16 = conv_params->dst; |
878 | 25.2k | int dst16_stride = conv_params->dst_stride; |
879 | 25.2k | const int bits = |
880 | 25.2k | FILTER_BITS * 2 - conv_params->round_1 - conv_params->round_0; |
881 | 25.2k | const int offset_bits = bd + 2 * FILTER_BITS - conv_params->round_0; |
882 | 25.2k | const int round_offset = (1 << (offset_bits - conv_params->round_1)) + |
883 | 25.2k | (1 << (offset_bits - conv_params->round_1 - 1)); |
884 | 25.2k | assert(bits >= 0); |
885 | | |
886 | 248k | for (int y = 0; y < h; ++y) { |
887 | 2.08M | for (int x = 0; x < w; ++x) { |
888 | 1.85M | CONV_BUF_TYPE res = src[y * src_stride + x] << bits; |
889 | 1.85M | res += round_offset; |
890 | 1.85M | if (conv_params->do_average) { |
891 | 679k | int32_t tmp = dst16[y * dst16_stride + x]; |
892 | 679k | if (conv_params->use_dist_wtd_comp_avg) { |
893 | 268k | tmp = tmp * conv_params->fwd_offset + res * conv_params->bck_offset; |
894 | 268k | tmp = tmp >> DIST_PRECISION_BITS; |
895 | 411k | } else { |
896 | 411k | tmp += res; |
897 | 411k | tmp = tmp >> 1; |
898 | 411k | } |
899 | 679k | tmp -= round_offset; |
900 | 679k | dst[y * dst_stride + x] = |
901 | 679k | clip_pixel_highbd(ROUND_POWER_OF_TWO(tmp, bits), bd); |
902 | 1.17M | } else { |
903 | 1.17M | dst16[y * dst16_stride + x] = res; |
904 | 1.17M | } |
905 | 1.85M | } |
906 | 222k | } |
907 | 25.2k | } |
908 | | |
909 | | void av1_highbd_convolve_2d_scale_c(const uint16_t *src, int src_stride, |
910 | | uint16_t *dst, int dst_stride, int w, int h, |
911 | | const InterpFilterParams *filter_params_x, |
912 | | const InterpFilterParams *filter_params_y, |
913 | | const int subpel_x_qn, const int x_step_qn, |
914 | | const int subpel_y_qn, const int y_step_qn, |
915 | 7.72k | ConvolveParams *conv_params, int bd) { |
916 | 7.72k | int16_t im_block[(2 * MAX_SB_SIZE + MAX_FILTER_TAP) * MAX_SB_SIZE]; |
917 | 7.72k | int im_h = (((h - 1) * y_step_qn + subpel_y_qn) >> SCALE_SUBPEL_BITS) + |
918 | 7.72k | filter_params_y->taps; |
919 | 7.72k | int im_stride = w; |
920 | 7.72k | const int fo_vert = filter_params_y->taps / 2 - 1; |
921 | 7.72k | const int fo_horiz = filter_params_x->taps / 2 - 1; |
922 | 7.72k | CONV_BUF_TYPE *dst16 = conv_params->dst; |
923 | 7.72k | const int dst16_stride = conv_params->dst_stride; |
924 | 7.72k | const int bits = |
925 | 7.72k | FILTER_BITS * 2 - conv_params->round_0 - conv_params->round_1; |
926 | 7.72k | assert(bits >= 0); |
927 | | // horizontal filter |
928 | 7.72k | const uint16_t *src_horiz = src - fo_vert * src_stride; |
929 | 123k | for (int y = 0; y < im_h; ++y) { |
930 | 115k | int x_qn = subpel_x_qn; |
931 | 1.09M | for (int x = 0; x < w; ++x, x_qn += x_step_qn) { |
932 | 976k | const uint16_t *const src_x = &src_horiz[(x_qn >> SCALE_SUBPEL_BITS)]; |
933 | 976k | const int x_filter_idx = (x_qn & SCALE_SUBPEL_MASK) >> SCALE_EXTRA_BITS; |
934 | 976k | assert(x_filter_idx < SUBPEL_SHIFTS); |
935 | 976k | const int16_t *x_filter = |
936 | 976k | av1_get_interp_filter_subpel_kernel(filter_params_x, x_filter_idx); |
937 | 976k | int32_t sum = (1 << (bd + FILTER_BITS - 1)); |
938 | 8.79M | for (int k = 0; k < filter_params_x->taps; ++k) { |
939 | 7.81M | sum += x_filter[k] * src_x[k - fo_horiz]; |
940 | 7.81M | } |
941 | 976k | assert(0 <= sum && sum < (1 << (bd + FILTER_BITS + 1))); |
942 | 976k | im_block[y * im_stride + x] = |
943 | 976k | (int16_t)ROUND_POWER_OF_TWO(sum, conv_params->round_0); |
944 | 976k | } |
945 | 115k | src_horiz += src_stride; |
946 | 115k | } |
947 | | |
948 | | // vertical filter |
949 | 7.72k | int16_t *src_vert = im_block + fo_vert * im_stride; |
950 | 7.72k | const int offset_bits = bd + 2 * FILTER_BITS - conv_params->round_0; |
951 | 66.4k | for (int x = 0; x < w; ++x) { |
952 | 58.7k | int y_qn = subpel_y_qn; |
953 | 584k | for (int y = 0; y < h; ++y, y_qn += y_step_qn) { |
954 | 525k | const int16_t *src_y = &src_vert[(y_qn >> SCALE_SUBPEL_BITS) * im_stride]; |
955 | 525k | const int y_filter_idx = (y_qn & SCALE_SUBPEL_MASK) >> SCALE_EXTRA_BITS; |
956 | 525k | assert(y_filter_idx < SUBPEL_SHIFTS); |
957 | 525k | const int16_t *y_filter = |
958 | 525k | av1_get_interp_filter_subpel_kernel(filter_params_y, y_filter_idx); |
959 | 525k | int32_t sum = 1 << offset_bits; |
960 | 4.73M | for (int k = 0; k < filter_params_y->taps; ++k) { |
961 | 4.20M | sum += y_filter[k] * src_y[(k - fo_vert) * im_stride]; |
962 | 4.20M | } |
963 | 525k | assert(0 <= sum && sum < (1 << (offset_bits + 2))); |
964 | 525k | CONV_BUF_TYPE res = ROUND_POWER_OF_TWO(sum, conv_params->round_1); |
965 | 525k | if (conv_params->is_compound) { |
966 | 107k | if (conv_params->do_average) { |
967 | 42.5k | int32_t tmp = dst16[y * dst16_stride + x]; |
968 | 42.5k | if (conv_params->use_dist_wtd_comp_avg) { |
969 | 14.0k | tmp = tmp * conv_params->fwd_offset + res * conv_params->bck_offset; |
970 | 14.0k | tmp = tmp >> DIST_PRECISION_BITS; |
971 | 28.5k | } else { |
972 | 28.5k | tmp += res; |
973 | 28.5k | tmp = tmp >> 1; |
974 | 28.5k | } |
975 | | /* Subtract round offset and convolve round */ |
976 | 42.5k | tmp = tmp - ((1 << (offset_bits - conv_params->round_1)) + |
977 | 42.5k | (1 << (offset_bits - conv_params->round_1 - 1))); |
978 | 42.5k | dst[y * dst_stride + x] = |
979 | 42.5k | clip_pixel_highbd(ROUND_POWER_OF_TWO(tmp, bits), bd); |
980 | 65.4k | } else { |
981 | 65.4k | dst16[y * dst16_stride + x] = res; |
982 | 65.4k | } |
983 | 417k | } else { |
984 | | /* Subtract round offset and convolve round */ |
985 | 417k | int32_t tmp = res - ((1 << (offset_bits - conv_params->round_1)) + |
986 | 417k | (1 << (offset_bits - conv_params->round_1 - 1))); |
987 | 417k | dst[y * dst_stride + x] = |
988 | 417k | clip_pixel_highbd(ROUND_POWER_OF_TWO(tmp, bits), bd); |
989 | 417k | } |
990 | 525k | } |
991 | 58.7k | src_vert++; |
992 | 58.7k | } |
993 | 7.72k | } |
994 | | |
995 | | static void highbd_convolve_2d_facade_compound( |
996 | | const uint16_t *src, int src_stride, uint16_t *dst, int dst_stride, |
997 | | const int w, const int h, const InterpFilterParams *filter_params_x, |
998 | | const InterpFilterParams *filter_params_y, const int subpel_x_qn, |
999 | 38.9k | const int subpel_y_qn, ConvolveParams *conv_params, int bd) { |
1000 | 38.9k | const bool need_x = subpel_x_qn != 0; |
1001 | 38.9k | const bool need_y = subpel_y_qn != 0; |
1002 | 38.9k | if (!need_x && !need_y) { |
1003 | 25.2k | av1_highbd_dist_wtd_convolve_2d_copy(src, src_stride, dst, dst_stride, w, h, |
1004 | 25.2k | conv_params, bd); |
1005 | 25.2k | } else if (need_x && !need_y) { |
1006 | 6.60k | av1_highbd_dist_wtd_convolve_x(src, src_stride, dst, dst_stride, w, h, |
1007 | 6.60k | filter_params_x, subpel_x_qn, conv_params, |
1008 | 6.60k | bd); |
1009 | 7.06k | } else if (!need_x && need_y) { |
1010 | 2.58k | av1_highbd_dist_wtd_convolve_y(src, src_stride, dst, dst_stride, w, h, |
1011 | 2.58k | filter_params_y, subpel_y_qn, conv_params, |
1012 | 2.58k | bd); |
1013 | 4.47k | } else { |
1014 | 4.47k | assert(need_x && need_y); |
1015 | 4.47k | av1_highbd_dist_wtd_convolve_2d(src, src_stride, dst, dst_stride, w, h, |
1016 | 4.47k | filter_params_x, filter_params_y, |
1017 | 4.47k | subpel_x_qn, subpel_y_qn, conv_params, bd); |
1018 | 4.47k | } |
1019 | 38.9k | } |
1020 | | |
1021 | | static void highbd_convolve_2d_facade_single( |
1022 | | const uint16_t *src, int src_stride, uint16_t *dst, int dst_stride, |
1023 | | const int w, const int h, const InterpFilterParams *filter_params_x, |
1024 | | const InterpFilterParams *filter_params_y, const int subpel_x_qn, |
1025 | 217k | const int subpel_y_qn, ConvolveParams *conv_params, int bd) { |
1026 | 217k | const bool need_x = subpel_x_qn != 0; |
1027 | 217k | const bool need_y = subpel_y_qn != 0; |
1028 | | |
1029 | 217k | if (!need_x && !need_y) { |
1030 | 130k | aom_highbd_convolve_copy(src, src_stride, dst, dst_stride, w, h); |
1031 | 130k | } else if (need_x && !need_y) { |
1032 | 32.8k | av1_highbd_convolve_x_sr(src, src_stride, dst, dst_stride, w, h, |
1033 | 32.8k | filter_params_x, subpel_x_qn, conv_params, bd); |
1034 | 54.2k | } else if (!need_x && need_y) { |
1035 | 25.1k | av1_highbd_convolve_y_sr(src, src_stride, dst, dst_stride, w, h, |
1036 | 25.1k | filter_params_y, subpel_y_qn, bd); |
1037 | 29.0k | } else { |
1038 | 29.0k | assert(need_x && need_y); |
1039 | 29.0k | av1_highbd_convolve_2d_sr(src, src_stride, dst, dst_stride, w, h, |
1040 | 29.0k | filter_params_x, filter_params_y, subpel_x_qn, |
1041 | 29.0k | subpel_y_qn, conv_params, bd); |
1042 | 29.0k | } |
1043 | 217k | } |
1044 | | |
1045 | | void av1_highbd_convolve_2d_facade(const uint8_t *src8, int src_stride, |
1046 | | uint8_t *dst8, int dst_stride, int w, int h, |
1047 | | const InterpFilterParams *interp_filters[2], |
1048 | | const int subpel_x_qn, int x_step_q4, |
1049 | | const int subpel_y_qn, int y_step_q4, |
1050 | | int scaled, ConvolveParams *conv_params, |
1051 | 264k | int bd) { |
1052 | 264k | (void)x_step_q4; |
1053 | 264k | (void)y_step_q4; |
1054 | 264k | (void)dst_stride; |
1055 | 264k | const uint16_t *src = CONVERT_TO_SHORTPTR(src8); |
1056 | | |
1057 | 264k | const int need_filter_params_x = (subpel_x_qn != 0) | scaled; |
1058 | 264k | const int need_filter_params_y = (subpel_y_qn != 0) | scaled; |
1059 | 264k | const InterpFilterParams *filter_params_x = |
1060 | 264k | need_filter_params_x ? interp_filters[0] : NULL; |
1061 | 264k | const InterpFilterParams *filter_params_y = |
1062 | 264k | need_filter_params_y ? interp_filters[1] : NULL; |
1063 | | |
1064 | 264k | uint16_t *dst = CONVERT_TO_SHORTPTR(dst8); |
1065 | 264k | if (scaled) { |
1066 | 7.72k | if (conv_params->is_compound) { |
1067 | 708 | assert(conv_params->dst != NULL); |
1068 | 708 | } |
1069 | 7.72k | av1_highbd_convolve_2d_scale(src, src_stride, dst, dst_stride, w, h, |
1070 | 7.72k | filter_params_x, filter_params_y, subpel_x_qn, |
1071 | 7.72k | x_step_q4, subpel_y_qn, y_step_q4, conv_params, |
1072 | 7.72k | bd); |
1073 | 256k | } else if (conv_params->is_compound) { |
1074 | 38.9k | highbd_convolve_2d_facade_compound( |
1075 | 38.9k | src, src_stride, dst, dst_stride, w, h, filter_params_x, |
1076 | 38.9k | filter_params_y, subpel_x_qn, subpel_y_qn, conv_params, bd); |
1077 | 217k | } else { |
1078 | 217k | highbd_convolve_2d_facade_single(src, src_stride, dst, dst_stride, w, h, |
1079 | 217k | filter_params_x, filter_params_y, |
1080 | 217k | subpel_x_qn, subpel_y_qn, conv_params, bd); |
1081 | 217k | } |
1082 | 264k | } |
1083 | | #endif // CONFIG_AV1_HIGHBITDEPTH |
1084 | | |
1085 | | // Note: Fixed size intermediate buffers, place limits on parameters |
1086 | | // of some functions. 2d filtering proceeds in 2 steps: |
1087 | | // (1) Interpolate horizontally into an intermediate buffer, temp. |
1088 | | // (2) Interpolate temp vertically to derive the sub-pixel result. |
1089 | | // Deriving the maximum number of rows in the temp buffer (135): |
1090 | | // --Smallest scaling factor is x1/2 ==> y_step_q4 = 32 (Normative). |
1091 | | // --Largest block size is 128x128 pixels. |
1092 | | // --128 rows in the downscaled frame span a distance of (128 - 1) * 32 in the |
1093 | | // original frame (in 1/16th pixel units). |
1094 | | // --Must round-up because block may be located at sub-pixel position. |
1095 | | // --Require an additional SUBPEL_TAPS rows for the 8-tap filter tails. |
1096 | | // --((128 - 1) * 32 + 15) >> 4 + 8 = 263. |
1097 | | #define WIENER_MAX_EXT_SIZE 263 |
1098 | | |
1099 | 48.3M | static INLINE int horz_scalar_product(const uint8_t *a, const int16_t *b) { |
1100 | 48.3M | int sum = 0; |
1101 | 435M | for (int k = 0; k < SUBPEL_TAPS; ++k) sum += a[k] * b[k]; |
1102 | 48.3M | return sum; |
1103 | 48.3M | } |
1104 | | |
1105 | | #if CONFIG_AV1_HIGHBITDEPTH |
1106 | | static INLINE int highbd_horz_scalar_product(const uint16_t *a, |
1107 | 98.6M | const int16_t *b) { |
1108 | 98.6M | int sum = 0; |
1109 | 887M | for (int k = 0; k < SUBPEL_TAPS; ++k) sum += a[k] * b[k]; |
1110 | 98.6M | return sum; |
1111 | 98.6M | } |
1112 | | #endif |
1113 | | |
1114 | | static INLINE int highbd_vert_scalar_product(const uint16_t *a, |
1115 | | ptrdiff_t a_stride, |
1116 | 130M | const int16_t *b) { |
1117 | 130M | int sum = 0; |
1118 | 1.17G | for (int k = 0; k < SUBPEL_TAPS; ++k) sum += a[k * a_stride] * b[k]; |
1119 | 130M | return sum; |
1120 | 130M | } |
1121 | | |
1122 | 104k | static const InterpKernel *get_filter_base(const int16_t *filter) { |
1123 | | // NOTE: This assumes that the filter table is 256-byte aligned. |
1124 | | // TODO(agrange) Modify to make independent of table alignment. |
1125 | 104k | return (const InterpKernel *)(((intptr_t)filter) & ~((intptr_t)0xFF)); |
1126 | 104k | } |
1127 | | |
1128 | 104k | static int get_filter_offset(const int16_t *f, const InterpKernel *base) { |
1129 | 104k | return (int)((const InterpKernel *)(intptr_t)f - base); |
1130 | 104k | } |
1131 | | |
1132 | | static void convolve_add_src_horiz_hip(const uint8_t *src, ptrdiff_t src_stride, |
1133 | | uint16_t *dst, ptrdiff_t dst_stride, |
1134 | | const InterpKernel *x_filters, int x0_q4, |
1135 | | int x_step_q4, int w, int h, |
1136 | 18.4k | int round0_bits) { |
1137 | 18.4k | const int bd = 8; |
1138 | 18.4k | src -= SUBPEL_TAPS / 2 - 1; |
1139 | 1.03M | for (int y = 0; y < h; ++y) { |
1140 | 1.01M | int x_q4 = x0_q4; |
1141 | 49.3M | for (int x = 0; x < w; ++x) { |
1142 | 48.3M | const uint8_t *const src_x = &src[x_q4 >> SUBPEL_BITS]; |
1143 | 48.3M | const int16_t *const x_filter = x_filters[x_q4 & SUBPEL_MASK]; |
1144 | 48.3M | const int rounding = ((int)src_x[SUBPEL_TAPS / 2 - 1] << FILTER_BITS) + |
1145 | 48.3M | (1 << (bd + FILTER_BITS - 1)); |
1146 | 48.3M | const int sum = horz_scalar_product(src_x, x_filter) + rounding; |
1147 | 48.3M | dst[x] = (uint16_t)clamp(ROUND_POWER_OF_TWO(sum, round0_bits), 0, |
1148 | 48.3M | WIENER_CLAMP_LIMIT(round0_bits, bd) - 1); |
1149 | 48.3M | x_q4 += x_step_q4; |
1150 | 48.3M | } |
1151 | 1.01M | src += src_stride; |
1152 | 1.01M | dst += dst_stride; |
1153 | 1.01M | } |
1154 | 18.4k | } |
1155 | | |
1156 | | static void convolve_add_src_vert_hip(const uint16_t *src, ptrdiff_t src_stride, |
1157 | | uint8_t *dst, ptrdiff_t dst_stride, |
1158 | | const InterpKernel *y_filters, int y0_q4, |
1159 | | int y_step_q4, int w, int h, |
1160 | 18.4k | int round1_bits) { |
1161 | 18.4k | const int bd = 8; |
1162 | 18.4k | src -= src_stride * (SUBPEL_TAPS / 2 - 1); |
1163 | | |
1164 | 854k | for (int x = 0; x < w; ++x) { |
1165 | 836k | int y_q4 = y0_q4; |
1166 | 44.1M | for (int y = 0; y < h; ++y) { |
1167 | 43.3M | const uint16_t *src_y = &src[(y_q4 >> SUBPEL_BITS) * src_stride]; |
1168 | 43.3M | const int16_t *const y_filter = y_filters[y_q4 & SUBPEL_MASK]; |
1169 | 43.3M | const int rounding = |
1170 | 43.3M | ((int)src_y[(SUBPEL_TAPS / 2 - 1) * src_stride] << FILTER_BITS) - |
1171 | 43.3M | (1 << (bd + round1_bits - 1)); |
1172 | 43.3M | const int sum = |
1173 | 43.3M | highbd_vert_scalar_product(src_y, src_stride, y_filter) + rounding; |
1174 | 43.3M | dst[y * dst_stride] = clip_pixel(ROUND_POWER_OF_TWO(sum, round1_bits)); |
1175 | 43.3M | y_q4 += y_step_q4; |
1176 | 43.3M | } |
1177 | 836k | ++src; |
1178 | 836k | ++dst; |
1179 | 836k | } |
1180 | 18.4k | } |
1181 | | |
1182 | | void av1_wiener_convolve_add_src_c(const uint8_t *src, ptrdiff_t src_stride, |
1183 | | uint8_t *dst, ptrdiff_t dst_stride, |
1184 | | const int16_t *filter_x, int x_step_q4, |
1185 | | const int16_t *filter_y, int y_step_q4, |
1186 | | int w, int h, |
1187 | 18.4k | const ConvolveParams *conv_params) { |
1188 | 18.4k | const InterpKernel *const filters_x = get_filter_base(filter_x); |
1189 | 18.4k | const int x0_q4 = get_filter_offset(filter_x, filters_x); |
1190 | | |
1191 | 18.4k | const InterpKernel *const filters_y = get_filter_base(filter_y); |
1192 | 18.4k | const int y0_q4 = get_filter_offset(filter_y, filters_y); |
1193 | | |
1194 | 18.4k | uint16_t temp[WIENER_MAX_EXT_SIZE * MAX_SB_SIZE]; |
1195 | 18.4k | const int intermediate_height = |
1196 | 18.4k | (((h - 1) * y_step_q4 + y0_q4) >> SUBPEL_BITS) + SUBPEL_TAPS - 1; |
1197 | 18.4k | memset(temp + (intermediate_height * MAX_SB_SIZE), 0, MAX_SB_SIZE); |
1198 | | |
1199 | 18.4k | assert(w <= MAX_SB_SIZE); |
1200 | 18.4k | assert(h <= MAX_SB_SIZE); |
1201 | 18.4k | assert(y_step_q4 <= 32); |
1202 | 18.4k | assert(x_step_q4 <= 32); |
1203 | | |
1204 | 18.4k | convolve_add_src_horiz_hip(src - src_stride * (SUBPEL_TAPS / 2 - 1), |
1205 | 18.4k | src_stride, temp, MAX_SB_SIZE, filters_x, x0_q4, |
1206 | 18.4k | x_step_q4, w, intermediate_height, |
1207 | 18.4k | conv_params->round_0); |
1208 | 18.4k | convolve_add_src_vert_hip(temp + MAX_SB_SIZE * (SUBPEL_TAPS / 2 - 1), |
1209 | 18.4k | MAX_SB_SIZE, dst, dst_stride, filters_y, y0_q4, |
1210 | 18.4k | y_step_q4, w, h, conv_params->round_1); |
1211 | 18.4k | } |
1212 | | |
1213 | | #if CONFIG_AV1_HIGHBITDEPTH |
1214 | | static void highbd_convolve_add_src_horiz_hip( |
1215 | | const uint8_t *src8, ptrdiff_t src_stride, uint16_t *dst, |
1216 | | ptrdiff_t dst_stride, const InterpKernel *x_filters, int x0_q4, |
1217 | 33.7k | int x_step_q4, int w, int h, int round0_bits, int bd) { |
1218 | 33.7k | const int extraprec_clamp_limit = WIENER_CLAMP_LIMIT(round0_bits, bd); |
1219 | 33.7k | uint16_t *src = CONVERT_TO_SHORTPTR(src8); |
1220 | 33.7k | src -= SUBPEL_TAPS / 2 - 1; |
1221 | 2.08M | for (int y = 0; y < h; ++y) { |
1222 | 2.05M | int x_q4 = x0_q4; |
1223 | 100M | for (int x = 0; x < w; ++x) { |
1224 | 98.6M | const uint16_t *const src_x = &src[x_q4 >> SUBPEL_BITS]; |
1225 | 98.6M | const int16_t *const x_filter = x_filters[x_q4 & SUBPEL_MASK]; |
1226 | 98.6M | const int rounding = ((int)src_x[SUBPEL_TAPS / 2 - 1] << FILTER_BITS) + |
1227 | 98.6M | (1 << (bd + FILTER_BITS - 1)); |
1228 | 98.6M | const int sum = highbd_horz_scalar_product(src_x, x_filter) + rounding; |
1229 | 98.6M | dst[x] = (uint16_t)clamp(ROUND_POWER_OF_TWO(sum, round0_bits), 0, |
1230 | 98.6M | extraprec_clamp_limit - 1); |
1231 | 98.6M | x_q4 += x_step_q4; |
1232 | 98.6M | } |
1233 | 2.05M | src += src_stride; |
1234 | 2.05M | dst += dst_stride; |
1235 | 2.05M | } |
1236 | 33.7k | } |
1237 | | |
1238 | | static void highbd_convolve_add_src_vert_hip( |
1239 | | const uint16_t *src, ptrdiff_t src_stride, uint8_t *dst8, |
1240 | | ptrdiff_t dst_stride, const InterpKernel *y_filters, int y0_q4, |
1241 | 33.7k | int y_step_q4, int w, int h, int round1_bits, int bd) { |
1242 | 33.7k | uint16_t *dst = CONVERT_TO_SHORTPTR(dst8); |
1243 | 33.7k | src -= src_stride * (SUBPEL_TAPS / 2 - 1); |
1244 | 1.65M | for (int x = 0; x < w; ++x) { |
1245 | 1.61M | int y_q4 = y0_q4; |
1246 | 88.9M | for (int y = 0; y < h; ++y) { |
1247 | 87.2M | const uint16_t *src_y = &src[(y_q4 >> SUBPEL_BITS) * src_stride]; |
1248 | 87.2M | const int16_t *const y_filter = y_filters[y_q4 & SUBPEL_MASK]; |
1249 | 87.2M | const int rounding = |
1250 | 87.2M | ((int)src_y[(SUBPEL_TAPS / 2 - 1) * src_stride] << FILTER_BITS) - |
1251 | 87.2M | (1 << (bd + round1_bits - 1)); |
1252 | 87.2M | const int sum = |
1253 | 87.2M | highbd_vert_scalar_product(src_y, src_stride, y_filter) + rounding; |
1254 | 87.2M | dst[y * dst_stride] = |
1255 | 87.2M | clip_pixel_highbd(ROUND_POWER_OF_TWO(sum, round1_bits), bd); |
1256 | 87.2M | y_q4 += y_step_q4; |
1257 | 87.2M | } |
1258 | 1.61M | ++src; |
1259 | 1.61M | ++dst; |
1260 | 1.61M | } |
1261 | 33.7k | } |
1262 | | |
1263 | | void av1_highbd_wiener_convolve_add_src_c( |
1264 | | const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, |
1265 | | ptrdiff_t dst_stride, const int16_t *filter_x, int x_step_q4, |
1266 | | const int16_t *filter_y, int y_step_q4, int w, int h, |
1267 | 33.7k | const ConvolveParams *conv_params, int bd) { |
1268 | 33.7k | const InterpKernel *const filters_x = get_filter_base(filter_x); |
1269 | 33.7k | const int x0_q4 = get_filter_offset(filter_x, filters_x); |
1270 | | |
1271 | 33.7k | const InterpKernel *const filters_y = get_filter_base(filter_y); |
1272 | 33.7k | const int y0_q4 = get_filter_offset(filter_y, filters_y); |
1273 | | |
1274 | 33.7k | uint16_t temp[WIENER_MAX_EXT_SIZE * MAX_SB_SIZE]; |
1275 | 33.7k | const int intermediate_height = |
1276 | 33.7k | (((h - 1) * y_step_q4 + y0_q4) >> SUBPEL_BITS) + SUBPEL_TAPS; |
1277 | | |
1278 | 33.7k | assert(w <= MAX_SB_SIZE); |
1279 | 33.7k | assert(h <= MAX_SB_SIZE); |
1280 | 33.7k | assert(y_step_q4 <= 32); |
1281 | 33.7k | assert(x_step_q4 <= 32); |
1282 | 33.7k | assert(bd + FILTER_BITS - conv_params->round_0 + 2 <= 16); |
1283 | | |
1284 | 33.7k | highbd_convolve_add_src_horiz_hip(src - src_stride * (SUBPEL_TAPS / 2 - 1), |
1285 | 33.7k | src_stride, temp, MAX_SB_SIZE, filters_x, |
1286 | 33.7k | x0_q4, x_step_q4, w, intermediate_height, |
1287 | 33.7k | conv_params->round_0, bd); |
1288 | 33.7k | highbd_convolve_add_src_vert_hip( |
1289 | 33.7k | temp + MAX_SB_SIZE * (SUBPEL_TAPS / 2 - 1), MAX_SB_SIZE, dst, dst_stride, |
1290 | 33.7k | filters_y, y0_q4, y_step_q4, w, h, conv_params->round_1, bd); |
1291 | 33.7k | } |
1292 | | #endif // CONFIG_AV1_HIGHBITDEPTH |