/src/aom/av1/common/convolve.c
Line | Count | Source (jump to first uncovered line) |
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 | 5.53k | int x_step_qn) { |
30 | 5.53k | src -= UPSCALE_NORMATIVE_TAPS / 2 - 1; |
31 | 484k | for (int y = 0; y < h; ++y) { |
32 | 478k | int x_qn = x0_qn; |
33 | 136M | for (int x = 0; x < w; ++x) { |
34 | 136M | const uint8_t *const src_x = &src[x_qn >> RS_SCALE_SUBPEL_BITS]; |
35 | 136M | const int x_filter_idx = |
36 | 136M | (x_qn & RS_SCALE_SUBPEL_MASK) >> RS_SCALE_EXTRA_BITS; |
37 | 136M | assert(x_filter_idx <= RS_SUBPEL_MASK); |
38 | 136M | const int16_t *const x_filter = |
39 | 136M | &x_filters[x_filter_idx * UPSCALE_NORMATIVE_TAPS]; |
40 | 136M | int sum = 0; |
41 | 1.22G | for (int k = 0; k < UPSCALE_NORMATIVE_TAPS; ++k) |
42 | 1.08G | sum += src_x[k] * x_filter[k]; |
43 | 136M | dst[x] = clip_pixel(ROUND_POWER_OF_TWO(sum, FILTER_BITS)); |
44 | 136M | x_qn += x_step_qn; |
45 | 136M | } |
46 | 478k | src += src_stride; |
47 | 478k | dst += dst_stride; |
48 | 478k | } |
49 | 5.53k | } |
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 | 2.36k | int x_step_qn, int bd) { |
55 | 2.36k | src -= UPSCALE_NORMATIVE_TAPS / 2 - 1; |
56 | 213k | for (int y = 0; y < h; ++y) { |
57 | 210k | int x_qn = x0_qn; |
58 | 62.3M | for (int x = 0; x < w; ++x) { |
59 | 62.1M | const uint16_t *const src_x = &src[x_qn >> RS_SCALE_SUBPEL_BITS]; |
60 | 62.1M | const int x_filter_idx = |
61 | 62.1M | (x_qn & RS_SCALE_SUBPEL_MASK) >> RS_SCALE_EXTRA_BITS; |
62 | 62.1M | assert(x_filter_idx <= RS_SUBPEL_MASK); |
63 | 62.1M | const int16_t *const x_filter = |
64 | 62.1M | &x_filters[x_filter_idx * UPSCALE_NORMATIVE_TAPS]; |
65 | 62.1M | int sum = 0; |
66 | 558M | for (int k = 0; k < UPSCALE_NORMATIVE_TAPS; ++k) |
67 | 496M | sum += src_x[k] * x_filter[k]; |
68 | 62.1M | dst[x] = clip_pixel_highbd(ROUND_POWER_OF_TWO(sum, FILTER_BITS), bd); |
69 | 62.1M | x_qn += x_step_qn; |
70 | 62.1M | } |
71 | 210k | src += src_stride; |
72 | 210k | dst += dst_stride; |
73 | 210k | } |
74 | 2.36k | } |
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 | 15.6k | ConvolveParams *conv_params) { |
121 | 15.6k | int16_t im_block[(MAX_SB_SIZE + MAX_FILTER_TAP - 1) * MAX_SB_SIZE]; |
122 | 15.6k | int im_h = h + filter_params_y->taps - 1; |
123 | 15.6k | int im_stride = w; |
124 | 15.6k | assert(w <= MAX_SB_SIZE && h <= MAX_SB_SIZE); |
125 | 15.6k | const int fo_vert = filter_params_y->taps / 2 - 1; |
126 | 15.6k | const int fo_horiz = filter_params_x->taps / 2 - 1; |
127 | 15.6k | const int bd = 8; |
128 | 15.6k | const int bits = |
129 | 15.6k | FILTER_BITS * 2 - conv_params->round_0 - conv_params->round_1; |
130 | | |
131 | | // horizontal filter |
132 | 15.6k | const uint8_t *src_horiz = src - fo_vert * src_stride; |
133 | 15.6k | const int16_t *x_filter = av1_get_interp_filter_subpel_kernel( |
134 | 15.6k | filter_params_x, subpel_x_qn & SUBPEL_MASK); |
135 | 158k | for (int y = 0; y < im_h; ++y) { |
136 | 1.92M | for (int x = 0; x < w; ++x) { |
137 | 1.78M | int32_t sum = (1 << (bd + FILTER_BITS - 1)); |
138 | 5.65M | for (int k = 0; k < filter_params_x->taps; ++k) { |
139 | 3.86M | sum += x_filter[k] * src_horiz[y * src_stride + x - fo_horiz + k]; |
140 | 3.86M | } |
141 | 1.78M | assert(0 <= sum && sum < (1 << (bd + FILTER_BITS + 1))); |
142 | 1.78M | im_block[y * im_stride + x] = |
143 | 1.78M | (int16_t)ROUND_POWER_OF_TWO(sum, conv_params->round_0); |
144 | 1.78M | } |
145 | 143k | } |
146 | | |
147 | | // vertical filter |
148 | 15.6k | int16_t *src_vert = im_block + fo_vert * im_stride; |
149 | 15.6k | const int16_t *y_filter = av1_get_interp_filter_subpel_kernel( |
150 | 15.6k | filter_params_y, subpel_y_qn & SUBPEL_MASK); |
151 | 15.6k | const int offset_bits = bd + 2 * FILTER_BITS - conv_params->round_0; |
152 | 136k | for (int y = 0; y < h; ++y) { |
153 | 1.74M | for (int x = 0; x < w; ++x) { |
154 | 1.62M | int32_t sum = 1 << offset_bits; |
155 | 4.97M | for (int k = 0; k < filter_params_y->taps; ++k) { |
156 | 3.35M | sum += y_filter[k] * src_vert[(y - fo_vert + k) * im_stride + x]; |
157 | 3.35M | } |
158 | 1.62M | assert(0 <= sum && sum < (1 << (offset_bits + 2))); |
159 | 1.62M | int16_t res = ROUND_POWER_OF_TWO(sum, conv_params->round_1) - |
160 | 1.62M | ((1 << (offset_bits - conv_params->round_1)) + |
161 | 1.62M | (1 << (offset_bits - conv_params->round_1 - 1))); |
162 | 1.62M | dst[y * dst_stride + x] = clip_pixel(ROUND_POWER_OF_TWO(res, bits)); |
163 | 1.62M | } |
164 | 121k | } |
165 | 15.6k | } |
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 | 14.4k | const int subpel_y_qn) { |
171 | 14.4k | const int fo_vert = filter_params_y->taps / 2 - 1; |
172 | | |
173 | | // vertical filter |
174 | 14.4k | const int16_t *y_filter = av1_get_interp_filter_subpel_kernel( |
175 | 14.4k | filter_params_y, subpel_y_qn & SUBPEL_MASK); |
176 | 124k | for (int y = 0; y < h; ++y) { |
177 | 1.57M | for (int x = 0; x < w; ++x) { |
178 | 1.46M | int32_t res = 0; |
179 | 4.44M | for (int k = 0; k < filter_params_y->taps; ++k) { |
180 | 2.98M | res += y_filter[k] * src[(y - fo_vert + k) * src_stride + x]; |
181 | 2.98M | } |
182 | 1.46M | dst[y * dst_stride + x] = |
183 | 1.46M | clip_pixel(ROUND_POWER_OF_TWO(res, FILTER_BITS)); |
184 | 1.46M | } |
185 | 109k | } |
186 | 14.4k | } |
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 | 14.8k | const int subpel_x_qn, ConvolveParams *conv_params) { |
192 | 14.8k | const int fo_horiz = filter_params_x->taps / 2 - 1; |
193 | 14.8k | const int bits = FILTER_BITS - conv_params->round_0; |
194 | | |
195 | 14.8k | assert(bits >= 0); |
196 | 14.8k | assert((FILTER_BITS - conv_params->round_1) >= 0 || |
197 | 14.8k | ((conv_params->round_0 + conv_params->round_1) == 2 * FILTER_BITS)); |
198 | | |
199 | | // horizontal filter |
200 | 14.8k | const int16_t *x_filter = av1_get_interp_filter_subpel_kernel( |
201 | 14.8k | filter_params_x, subpel_x_qn & SUBPEL_MASK); |
202 | | |
203 | 131k | for (int y = 0; y < h; ++y) { |
204 | 1.69M | for (int x = 0; x < w; ++x) { |
205 | 1.57M | int32_t res = 0; |
206 | 4.78M | for (int k = 0; k < filter_params_x->taps; ++k) { |
207 | 3.20M | res += x_filter[k] * src[y * src_stride + x - fo_horiz + k]; |
208 | 3.20M | } |
209 | 1.57M | res = ROUND_POWER_OF_TWO(res, conv_params->round_0); |
210 | 1.57M | dst[y * dst_stride + x] = clip_pixel(ROUND_POWER_OF_TWO(res, bits)); |
211 | 1.57M | } |
212 | 117k | } |
213 | 14.8k | } |
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 | 173 | ConvolveParams *conv_params) { |
221 | 173 | CONV_BUF_TYPE *dst16 = conv_params->dst; |
222 | 173 | int dst16_stride = conv_params->dst_stride; |
223 | 173 | int16_t im_block[(MAX_SB_SIZE + MAX_FILTER_TAP - 1) * MAX_SB_SIZE]; |
224 | 173 | int im_h = h + filter_params_y->taps - 1; |
225 | 173 | int im_stride = w; |
226 | 173 | const int fo_vert = filter_params_y->taps / 2 - 1; |
227 | 173 | const int fo_horiz = filter_params_x->taps / 2 - 1; |
228 | 173 | const int bd = 8; |
229 | 173 | const int round_bits = |
230 | 173 | 2 * FILTER_BITS - conv_params->round_0 - conv_params->round_1; |
231 | | |
232 | | // horizontal filter |
233 | 173 | const uint8_t *src_horiz = src - fo_vert * src_stride; |
234 | 173 | const int16_t *x_filter = av1_get_interp_filter_subpel_kernel( |
235 | 173 | filter_params_x, subpel_x_qn & SUBPEL_MASK); |
236 | 2.69k | for (int y = 0; y < im_h; ++y) { |
237 | 22.9k | for (int x = 0; x < w; ++x) { |
238 | 20.4k | int32_t sum = (1 << (bd + FILTER_BITS - 1)); |
239 | 184k | for (int k = 0; k < filter_params_x->taps; ++k) { |
240 | 163k | sum += x_filter[k] * src_horiz[y * src_stride + x - fo_horiz + k]; |
241 | 163k | } |
242 | 20.4k | assert(0 <= sum && sum < (1 << (bd + FILTER_BITS + 1))); |
243 | 20.4k | im_block[y * im_stride + x] = |
244 | 20.4k | (int16_t)ROUND_POWER_OF_TWO(sum, conv_params->round_0); |
245 | 20.4k | } |
246 | 2.52k | } |
247 | | |
248 | | // vertical filter |
249 | 173 | int16_t *src_vert = im_block + fo_vert * im_stride; |
250 | 173 | const int16_t *y_filter = av1_get_interp_filter_subpel_kernel( |
251 | 173 | filter_params_y, subpel_y_qn & SUBPEL_MASK); |
252 | 173 | const int offset_bits = bd + 2 * FILTER_BITS - conv_params->round_0; |
253 | 1.48k | for (int y = 0; y < h; ++y) { |
254 | 12.0k | for (int x = 0; x < w; ++x) { |
255 | 10.7k | int32_t sum = 1 << offset_bits; |
256 | 97.0k | for (int k = 0; k < filter_params_y->taps; ++k) { |
257 | 86.2k | sum += y_filter[k] * src_vert[(y - fo_vert + k) * im_stride + x]; |
258 | 86.2k | } |
259 | 10.7k | assert(0 <= sum && sum < (1 << (offset_bits + 2))); |
260 | 10.7k | CONV_BUF_TYPE res = ROUND_POWER_OF_TWO(sum, conv_params->round_1); |
261 | 10.7k | if (conv_params->do_average) { |
262 | 3.16k | int32_t tmp = dst16[y * dst16_stride + x]; |
263 | 3.16k | if (conv_params->use_dist_wtd_comp_avg) { |
264 | 832 | tmp = tmp * conv_params->fwd_offset + res * conv_params->bck_offset; |
265 | 832 | tmp = tmp >> DIST_PRECISION_BITS; |
266 | 2.33k | } else { |
267 | 2.33k | tmp += res; |
268 | 2.33k | tmp = tmp >> 1; |
269 | 2.33k | } |
270 | 3.16k | tmp -= (1 << (offset_bits - conv_params->round_1)) + |
271 | 3.16k | (1 << (offset_bits - conv_params->round_1 - 1)); |
272 | 3.16k | dst[y * dst_stride + x] = |
273 | 3.16k | clip_pixel(ROUND_POWER_OF_TWO(tmp, round_bits)); |
274 | 7.61k | } else { |
275 | 7.61k | dst16[y * dst16_stride + x] = res; |
276 | 7.61k | } |
277 | 10.7k | } |
278 | 1.31k | } |
279 | 173 | } |
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 | 144 | ConvolveParams *conv_params) { |
286 | 144 | CONV_BUF_TYPE *dst16 = conv_params->dst; |
287 | 144 | int dst16_stride = conv_params->dst_stride; |
288 | 144 | const int fo_vert = filter_params_y->taps / 2 - 1; |
289 | 144 | const int bits = FILTER_BITS - conv_params->round_0; |
290 | 144 | const int bd = 8; |
291 | 144 | const int offset_bits = bd + 2 * FILTER_BITS - conv_params->round_0; |
292 | 144 | const int round_offset = (1 << (offset_bits - conv_params->round_1)) + |
293 | 144 | (1 << (offset_bits - conv_params->round_1 - 1)); |
294 | 144 | const int round_bits = |
295 | 144 | 2 * FILTER_BITS - conv_params->round_0 - conv_params->round_1; |
296 | | |
297 | | // vertical filter |
298 | 144 | const int16_t *y_filter = av1_get_interp_filter_subpel_kernel( |
299 | 144 | filter_params_y, subpel_y_qn & SUBPEL_MASK); |
300 | 1.21k | for (int y = 0; y < h; ++y) { |
301 | 9.52k | for (int x = 0; x < w; ++x) { |
302 | 8.44k | int32_t res = 0; |
303 | 76.0k | for (int k = 0; k < filter_params_y->taps; ++k) { |
304 | 67.5k | res += y_filter[k] * src[(y - fo_vert + k) * src_stride + x]; |
305 | 67.5k | } |
306 | 8.44k | res *= (1 << bits); |
307 | 8.44k | res = ROUND_POWER_OF_TWO(res, conv_params->round_1) + round_offset; |
308 | | |
309 | 8.44k | if (conv_params->do_average) { |
310 | 4.41k | int32_t tmp = dst16[y * dst16_stride + x]; |
311 | 4.41k | if (conv_params->use_dist_wtd_comp_avg) { |
312 | 1.60k | tmp = tmp * conv_params->fwd_offset + res * conv_params->bck_offset; |
313 | 1.60k | tmp = tmp >> DIST_PRECISION_BITS; |
314 | 2.81k | } else { |
315 | 2.81k | tmp += res; |
316 | 2.81k | tmp = tmp >> 1; |
317 | 2.81k | } |
318 | 4.41k | tmp -= round_offset; |
319 | 4.41k | dst[y * dst_stride + x] = |
320 | 4.41k | clip_pixel(ROUND_POWER_OF_TWO(tmp, round_bits)); |
321 | 4.41k | } else { |
322 | 4.03k | dst16[y * dst16_stride + x] = res; |
323 | 4.03k | } |
324 | 8.44k | } |
325 | 1.07k | } |
326 | 144 | } |
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 | 1.13k | ConvolveParams *conv_params) { |
333 | 1.13k | CONV_BUF_TYPE *dst16 = conv_params->dst; |
334 | 1.13k | int dst16_stride = conv_params->dst_stride; |
335 | 1.13k | const int fo_horiz = filter_params_x->taps / 2 - 1; |
336 | 1.13k | const int bits = FILTER_BITS - conv_params->round_1; |
337 | 1.13k | const int bd = 8; |
338 | 1.13k | const int offset_bits = bd + 2 * FILTER_BITS - conv_params->round_0; |
339 | 1.13k | const int round_offset = (1 << (offset_bits - conv_params->round_1)) + |
340 | 1.13k | (1 << (offset_bits - conv_params->round_1 - 1)); |
341 | 1.13k | const int round_bits = |
342 | 1.13k | 2 * FILTER_BITS - conv_params->round_0 - conv_params->round_1; |
343 | | |
344 | | // horizontal filter |
345 | 1.13k | const int16_t *x_filter = av1_get_interp_filter_subpel_kernel( |
346 | 1.13k | filter_params_x, subpel_x_qn & SUBPEL_MASK); |
347 | 10.2k | for (int y = 0; y < h; ++y) { |
348 | 81.3k | for (int x = 0; x < w; ++x) { |
349 | 72.3k | int32_t res = 0; |
350 | 650k | for (int k = 0; k < filter_params_x->taps; ++k) { |
351 | 578k | res += x_filter[k] * src[y * src_stride + x - fo_horiz + k]; |
352 | 578k | } |
353 | 72.3k | res = (1 << bits) * ROUND_POWER_OF_TWO(res, conv_params->round_0); |
354 | 72.3k | res += round_offset; |
355 | | |
356 | 72.3k | if (conv_params->do_average) { |
357 | 35.2k | int32_t tmp = dst16[y * dst16_stride + x]; |
358 | 35.2k | if (conv_params->use_dist_wtd_comp_avg) { |
359 | 34.3k | tmp = tmp * conv_params->fwd_offset + res * conv_params->bck_offset; |
360 | 34.3k | tmp = tmp >> DIST_PRECISION_BITS; |
361 | 34.3k | } else { |
362 | 832 | tmp += res; |
363 | 832 | tmp = tmp >> 1; |
364 | 832 | } |
365 | 35.2k | tmp -= round_offset; |
366 | 35.2k | dst[y * dst_stride + x] = |
367 | 35.2k | clip_pixel(ROUND_POWER_OF_TWO(tmp, round_bits)); |
368 | 37.1k | } else { |
369 | 37.1k | dst16[y * dst16_stride + x] = res; |
370 | 37.1k | } |
371 | 72.3k | } |
372 | 9.06k | } |
373 | 1.13k | } |
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 | 419 | ConvolveParams *conv_params) { |
378 | 419 | CONV_BUF_TYPE *dst16 = conv_params->dst; |
379 | 419 | int dst16_stride = conv_params->dst_stride; |
380 | 419 | const int bits = |
381 | 419 | FILTER_BITS * 2 - conv_params->round_1 - conv_params->round_0; |
382 | 419 | const int bd = 8; |
383 | 419 | const int offset_bits = bd + 2 * FILTER_BITS - conv_params->round_0; |
384 | 419 | const int round_offset = (1 << (offset_bits - conv_params->round_1)) + |
385 | 419 | (1 << (offset_bits - conv_params->round_1 - 1)); |
386 | | |
387 | 3.74k | for (int y = 0; y < h; ++y) { |
388 | 32.9k | for (int x = 0; x < w; ++x) { |
389 | 29.6k | CONV_BUF_TYPE res = src[y * src_stride + x] << bits; |
390 | 29.6k | res += round_offset; |
391 | | |
392 | 29.6k | if (conv_params->do_average) { |
393 | 17.0k | int32_t tmp = dst16[y * dst16_stride + x]; |
394 | 17.0k | if (conv_params->use_dist_wtd_comp_avg) { |
395 | 3.71k | tmp = tmp * conv_params->fwd_offset + res * conv_params->bck_offset; |
396 | 3.71k | tmp = tmp >> DIST_PRECISION_BITS; |
397 | 13.3k | } else { |
398 | 13.3k | tmp += res; |
399 | 13.3k | tmp = tmp >> 1; |
400 | 13.3k | } |
401 | 17.0k | tmp -= round_offset; |
402 | 17.0k | dst[y * dst_stride + x] = clip_pixel(ROUND_POWER_OF_TWO(tmp, bits)); |
403 | 17.0k | } else { |
404 | 12.5k | dst16[y * dst16_stride + x] = res; |
405 | 12.5k | } |
406 | 29.6k | } |
407 | 3.32k | } |
408 | 419 | } |
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 | 4.23k | ConvolveParams *conv_params) { |
417 | 4.23k | int16_t im_block[(2 * MAX_SB_SIZE + MAX_FILTER_TAP) * MAX_SB_SIZE]; |
418 | 4.23k | int im_h = (((h - 1) * y_step_qn + subpel_y_qn) >> SCALE_SUBPEL_BITS) + |
419 | 4.23k | filter_params_y->taps; |
420 | 4.23k | CONV_BUF_TYPE *dst16 = conv_params->dst; |
421 | 4.23k | const int dst16_stride = conv_params->dst_stride; |
422 | 4.23k | const int bits = |
423 | 4.23k | FILTER_BITS * 2 - conv_params->round_0 - conv_params->round_1; |
424 | 4.23k | assert(bits >= 0); |
425 | 4.23k | int im_stride = w; |
426 | 4.23k | const int fo_vert = filter_params_y->taps / 2 - 1; |
427 | 4.23k | const int fo_horiz = filter_params_x->taps / 2 - 1; |
428 | 4.23k | const int bd = 8; |
429 | | |
430 | | // horizontal filter |
431 | 4.23k | const uint8_t *src_horiz = src - fo_vert * src_stride; |
432 | 61.5k | for (int y = 0; y < im_h; ++y) { |
433 | 57.3k | int x_qn = subpel_x_qn; |
434 | 442k | for (int x = 0; x < w; ++x, x_qn += x_step_qn) { |
435 | 385k | const uint8_t *const src_x = &src_horiz[(x_qn >> SCALE_SUBPEL_BITS)]; |
436 | 385k | const int x_filter_idx = (x_qn & SCALE_SUBPEL_MASK) >> SCALE_EXTRA_BITS; |
437 | 385k | assert(x_filter_idx < SUBPEL_SHIFTS); |
438 | 385k | const int16_t *x_filter = |
439 | 385k | av1_get_interp_filter_subpel_kernel(filter_params_x, x_filter_idx); |
440 | 385k | int32_t sum = (1 << (bd + FILTER_BITS - 1)); |
441 | 3.46M | for (int k = 0; k < filter_params_x->taps; ++k) { |
442 | 3.08M | sum += x_filter[k] * src_x[k - fo_horiz]; |
443 | 3.08M | } |
444 | 385k | assert(0 <= sum && sum < (1 << (bd + FILTER_BITS + 1))); |
445 | 385k | im_block[y * im_stride + x] = |
446 | 385k | (int16_t)ROUND_POWER_OF_TWO(sum, conv_params->round_0); |
447 | 385k | } |
448 | 57.3k | src_horiz += src_stride; |
449 | 57.3k | } |
450 | | |
451 | | // vertical filter |
452 | 4.23k | int16_t *src_vert = im_block + fo_vert * im_stride; |
453 | 4.23k | const int offset_bits = bd + 2 * FILTER_BITS - conv_params->round_0; |
454 | 30.9k | for (int x = 0; x < w; ++x) { |
455 | 26.7k | int y_qn = subpel_y_qn; |
456 | 206k | for (int y = 0; y < h; ++y, y_qn += y_step_qn) { |
457 | 179k | const int16_t *src_y = &src_vert[(y_qn >> SCALE_SUBPEL_BITS) * im_stride]; |
458 | 179k | const int y_filter_idx = (y_qn & SCALE_SUBPEL_MASK) >> SCALE_EXTRA_BITS; |
459 | 179k | assert(y_filter_idx < SUBPEL_SHIFTS); |
460 | 179k | const int16_t *y_filter = |
461 | 179k | av1_get_interp_filter_subpel_kernel(filter_params_y, y_filter_idx); |
462 | 179k | int32_t sum = 1 << offset_bits; |
463 | 1.61M | for (int k = 0; k < filter_params_y->taps; ++k) { |
464 | 1.43M | sum += y_filter[k] * src_y[(k - fo_vert) * im_stride]; |
465 | 1.43M | } |
466 | 179k | assert(0 <= sum && sum < (1 << (offset_bits + 2))); |
467 | 179k | CONV_BUF_TYPE res = ROUND_POWER_OF_TWO(sum, conv_params->round_1); |
468 | 179k | if (conv_params->is_compound) { |
469 | 64.1k | if (conv_params->do_average) { |
470 | 24.5k | int32_t tmp = dst16[y * dst16_stride + x]; |
471 | 24.5k | if (conv_params->use_dist_wtd_comp_avg) { |
472 | 704 | tmp = tmp * conv_params->fwd_offset + res * conv_params->bck_offset; |
473 | 704 | tmp = tmp >> DIST_PRECISION_BITS; |
474 | 23.8k | } else { |
475 | 23.8k | tmp += res; |
476 | 23.8k | tmp = tmp >> 1; |
477 | 23.8k | } |
478 | | /* Subtract round offset and convolve round */ |
479 | 24.5k | tmp = tmp - ((1 << (offset_bits - conv_params->round_1)) + |
480 | 24.5k | (1 << (offset_bits - conv_params->round_1 - 1))); |
481 | 24.5k | dst[y * dst_stride + x] = clip_pixel(ROUND_POWER_OF_TWO(tmp, bits)); |
482 | 39.6k | } else { |
483 | 39.6k | dst16[y * dst16_stride + x] = res; |
484 | 39.6k | } |
485 | 115k | } else { |
486 | | /* Subtract round offset and convolve round */ |
487 | 115k | int32_t tmp = res - ((1 << (offset_bits - conv_params->round_1)) + |
488 | 115k | (1 << (offset_bits - conv_params->round_1 - 1))); |
489 | 115k | dst[y * dst_stride + x] = clip_pixel(ROUND_POWER_OF_TWO(tmp, bits)); |
490 | 115k | } |
491 | 179k | } |
492 | 26.7k | src_vert++; |
493 | 26.7k | } |
494 | 4.23k | } |
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 | 4.23k | ConvolveParams *conv_params) { |
502 | 4.23k | if (conv_params->is_compound) { |
503 | 856 | assert(conv_params->dst != NULL); |
504 | 856 | } |
505 | 4.23k | av1_convolve_2d_scale(src, src_stride, dst, dst_stride, w, h, filter_params_x, |
506 | 4.23k | filter_params_y, subpel_x_qn, x_step_qn, subpel_y_qn, |
507 | 4.23k | y_step_qn, conv_params); |
508 | 4.23k | } |
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 | 1.87k | const int subpel_y_qn, ConvolveParams *conv_params) { |
515 | 1.87k | const bool need_x = subpel_x_qn != 0; |
516 | 1.87k | const bool need_y = subpel_y_qn != 0; |
517 | 1.87k | if (!need_x && !need_y) { |
518 | 419 | av1_dist_wtd_convolve_2d_copy(src, src_stride, dst, dst_stride, w, h, |
519 | 419 | conv_params); |
520 | 1.45k | } else if (need_x && !need_y) { |
521 | 1.13k | av1_dist_wtd_convolve_x(src, src_stride, dst, dst_stride, w, h, |
522 | 1.13k | filter_params_x, subpel_x_qn, conv_params); |
523 | 1.13k | } else if (!need_x && need_y) { |
524 | 144 | av1_dist_wtd_convolve_y(src, src_stride, dst, dst_stride, w, h, |
525 | 144 | filter_params_y, subpel_y_qn, conv_params); |
526 | 173 | } else { |
527 | 173 | assert(need_y && need_x); |
528 | 173 | av1_dist_wtd_convolve_2d(src, src_stride, dst, dst_stride, w, h, |
529 | 173 | filter_params_x, filter_params_y, subpel_x_qn, |
530 | 173 | subpel_y_qn, conv_params); |
531 | 173 | } |
532 | 1.87k | } |
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 | 57.1k | const int subpel_y_qn, ConvolveParams *conv_params) { |
539 | 57.1k | const bool need_x = subpel_x_qn != 0; |
540 | 57.1k | const bool need_y = subpel_y_qn != 0; |
541 | 57.1k | if (!need_x && !need_y) { |
542 | 55.2k | aom_convolve_copy(src, src_stride, dst, dst_stride, w, h); |
543 | 55.2k | } else if (need_x && !need_y) { |
544 | 449 | av1_convolve_x_sr(src, src_stride, dst, dst_stride, w, h, filter_params_x, |
545 | 449 | subpel_x_qn, conv_params); |
546 | 1.49k | } else if (!need_x && need_y) { |
547 | 431 | av1_convolve_y_sr(src, src_stride, dst, dst_stride, w, h, filter_params_y, |
548 | 431 | subpel_y_qn); |
549 | 1.06k | } else { |
550 | 1.06k | assert(need_x && need_y); |
551 | 1.06k | av1_convolve_2d_sr(src, src_stride, dst, dst_stride, w, h, filter_params_x, |
552 | 1.06k | filter_params_y, subpel_x_qn, subpel_y_qn, conv_params); |
553 | 1.06k | } |
554 | 57.1k | } |
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 | 106k | ConvolveParams *conv_params) { |
562 | 106k | (void)x_step_q4; |
563 | 106k | (void)y_step_q4; |
564 | 106k | (void)dst; |
565 | 106k | (void)dst_stride; |
566 | | |
567 | 106k | const InterpFilterParams *filter_params_x = interp_filters[0]; |
568 | 106k | 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 | 106k | if (filter_params_x->taps == 2 || filter_params_y->taps == 2) { |
574 | 96.7k | assert(filter_params_x->taps == 2 && filter_params_y->taps == 2); |
575 | 96.7k | assert(!scaled); |
576 | 96.7k | if (subpel_x_qn && subpel_y_qn) { |
577 | 14.5k | av1_convolve_2d_sr_c(src, src_stride, dst, dst_stride, w, h, |
578 | 14.5k | filter_params_x, filter_params_y, subpel_x_qn, |
579 | 14.5k | subpel_y_qn, conv_params); |
580 | 14.5k | return; |
581 | 82.1k | } else if (subpel_x_qn) { |
582 | 14.3k | av1_convolve_x_sr_c(src, src_stride, dst, dst_stride, w, h, |
583 | 14.3k | filter_params_x, subpel_x_qn, conv_params); |
584 | 14.3k | return; |
585 | 67.7k | } else if (subpel_y_qn) { |
586 | 14.0k | av1_convolve_y_sr_c(src, src_stride, dst, dst_stride, w, h, |
587 | 14.0k | filter_params_y, subpel_y_qn); |
588 | 14.0k | return; |
589 | 14.0k | } |
590 | 96.7k | } |
591 | | |
592 | 63.2k | if (scaled) { |
593 | 4.23k | convolve_2d_scale_wrapper(src, src_stride, dst, dst_stride, w, h, |
594 | 4.23k | filter_params_x, filter_params_y, subpel_x_qn, |
595 | 4.23k | x_step_q4, subpel_y_qn, y_step_q4, conv_params); |
596 | 59.0k | } else if (conv_params->is_compound) { |
597 | 1.87k | convolve_2d_facade_compound(src, src_stride, dst, dst_stride, w, h, |
598 | 1.87k | filter_params_x, filter_params_y, subpel_x_qn, |
599 | 1.87k | subpel_y_qn, conv_params); |
600 | 57.1k | } else { |
601 | 57.1k | convolve_2d_facade_single(src, src_stride, dst, dst_stride, w, h, |
602 | 57.1k | filter_params_x, filter_params_y, subpel_x_qn, |
603 | 57.1k | subpel_y_qn, conv_params); |
604 | 57.1k | } |
605 | 63.2k | } |
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 | 6.87k | ConvolveParams *conv_params, int bd) { |
613 | 6.87k | const int fo_horiz = filter_params_x->taps / 2 - 1; |
614 | 6.87k | const int bits = FILTER_BITS - conv_params->round_0; |
615 | | |
616 | 6.87k | assert(bits >= 0); |
617 | 6.87k | assert((FILTER_BITS - conv_params->round_1) >= 0 || |
618 | 6.87k | ((conv_params->round_0 + conv_params->round_1) == 2 * FILTER_BITS)); |
619 | | |
620 | | // horizontal filter |
621 | 6.87k | const int16_t *x_filter = av1_get_interp_filter_subpel_kernel( |
622 | 6.87k | filter_params_x, subpel_x_qn & SUBPEL_MASK); |
623 | 69.5k | for (int y = 0; y < h; ++y) { |
624 | 1.25M | for (int x = 0; x < w; ++x) { |
625 | 1.18M | int32_t res = 0; |
626 | 3.57M | for (int k = 0; k < filter_params_x->taps; ++k) { |
627 | 2.38M | res += x_filter[k] * src[y * src_stride + x - fo_horiz + k]; |
628 | 2.38M | } |
629 | 1.18M | res = ROUND_POWER_OF_TWO(res, conv_params->round_0); |
630 | 1.18M | dst[y * dst_stride + x] = |
631 | 1.18M | clip_pixel_highbd(ROUND_POWER_OF_TWO(res, bits), bd); |
632 | 1.18M | } |
633 | 62.6k | } |
634 | 6.87k | } |
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 | 5.57k | const int subpel_y_qn, int bd) { |
640 | 5.57k | const int fo_vert = filter_params_y->taps / 2 - 1; |
641 | | // vertical filter |
642 | 5.57k | const int16_t *y_filter = av1_get_interp_filter_subpel_kernel( |
643 | 5.57k | filter_params_y, subpel_y_qn & SUBPEL_MASK); |
644 | 40.5k | for (int y = 0; y < h; ++y) { |
645 | 380k | for (int x = 0; x < w; ++x) { |
646 | 345k | int32_t res = 0; |
647 | 1.05M | for (int k = 0; k < filter_params_y->taps; ++k) { |
648 | 706k | res += y_filter[k] * src[(y - fo_vert + k) * src_stride + x]; |
649 | 706k | } |
650 | 345k | dst[y * dst_stride + x] = |
651 | 345k | clip_pixel_highbd(ROUND_POWER_OF_TWO(res, FILTER_BITS), bd); |
652 | 345k | } |
653 | 35.0k | } |
654 | 5.57k | } |
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 | 5.24k | ConvolveParams *conv_params, int bd) { |
662 | 5.24k | int16_t im_block[(MAX_SB_SIZE + MAX_FILTER_TAP - 1) * MAX_SB_SIZE]; |
663 | 5.24k | int im_h = h + filter_params_y->taps - 1; |
664 | 5.24k | int im_stride = w; |
665 | 5.24k | assert(w <= MAX_SB_SIZE && h <= MAX_SB_SIZE); |
666 | 5.24k | const int fo_vert = filter_params_y->taps / 2 - 1; |
667 | 5.24k | const int fo_horiz = filter_params_x->taps / 2 - 1; |
668 | 5.24k | const int bits = |
669 | 5.24k | FILTER_BITS * 2 - conv_params->round_0 - conv_params->round_1; |
670 | 5.24k | assert(bits >= 0); |
671 | | |
672 | | // horizontal filter |
673 | 5.24k | const uint16_t *src_horiz = src - fo_vert * src_stride; |
674 | 5.24k | const int16_t *x_filter = av1_get_interp_filter_subpel_kernel( |
675 | 5.24k | filter_params_x, subpel_x_qn & SUBPEL_MASK); |
676 | 47.1k | for (int y = 0; y < im_h; ++y) { |
677 | 454k | for (int x = 0; x < w; ++x) { |
678 | 412k | int32_t sum = (1 << (bd + FILTER_BITS - 1)); |
679 | 1.29M | for (int k = 0; k < filter_params_x->taps; ++k) { |
680 | 882k | sum += x_filter[k] * src_horiz[y * src_stride + x - fo_horiz + k]; |
681 | 882k | } |
682 | 412k | assert(0 <= sum && sum < (1 << (bd + FILTER_BITS + 1))); |
683 | 412k | im_block[y * im_stride + x] = |
684 | 412k | ROUND_POWER_OF_TWO(sum, conv_params->round_0); |
685 | 412k | } |
686 | 41.9k | } |
687 | | |
688 | | // vertical filter |
689 | 5.24k | int16_t *src_vert = im_block + fo_vert * im_stride; |
690 | 5.24k | const int16_t *y_filter = av1_get_interp_filter_subpel_kernel( |
691 | 5.24k | filter_params_y, subpel_y_qn & SUBPEL_MASK); |
692 | 5.24k | const int offset_bits = bd + 2 * FILTER_BITS - conv_params->round_0; |
693 | 40.6k | for (int y = 0; y < h; ++y) { |
694 | 403k | for (int x = 0; x < w; ++x) { |
695 | 367k | int32_t sum = 1 << offset_bits; |
696 | 1.12M | for (int k = 0; k < filter_params_y->taps; ++k) { |
697 | 757k | sum += y_filter[k] * src_vert[(y - fo_vert + k) * im_stride + x]; |
698 | 757k | } |
699 | 367k | assert(0 <= sum && sum < (1 << (offset_bits + 2))); |
700 | 367k | int32_t res = ROUND_POWER_OF_TWO(sum, conv_params->round_1) - |
701 | 367k | ((1 << (offset_bits - conv_params->round_1)) + |
702 | 367k | (1 << (offset_bits - conv_params->round_1 - 1))); |
703 | 367k | dst[y * dst_stride + x] = |
704 | 367k | clip_pixel_highbd(ROUND_POWER_OF_TWO(res, bits), bd); |
705 | 367k | } |
706 | 35.4k | } |
707 | 5.24k | } |
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 | 56 | const int subpel_y_qn, ConvolveParams *conv_params, int bd) { |
714 | 56 | int x, y, k; |
715 | 56 | int16_t im_block[(MAX_SB_SIZE + MAX_FILTER_TAP - 1) * MAX_SB_SIZE]; |
716 | 56 | CONV_BUF_TYPE *dst16 = conv_params->dst; |
717 | 56 | int dst16_stride = conv_params->dst_stride; |
718 | 56 | int im_h = h + filter_params_y->taps - 1; |
719 | 56 | int im_stride = w; |
720 | 56 | const int fo_vert = filter_params_y->taps / 2 - 1; |
721 | 56 | const int fo_horiz = filter_params_x->taps / 2 - 1; |
722 | 56 | const int round_bits = |
723 | 56 | 2 * FILTER_BITS - conv_params->round_0 - conv_params->round_1; |
724 | 56 | assert(round_bits >= 0); |
725 | | |
726 | | // horizontal filter |
727 | 56 | const uint16_t *src_horiz = src - fo_vert * src_stride; |
728 | 56 | const int16_t *x_filter = av1_get_interp_filter_subpel_kernel( |
729 | 56 | filter_params_x, subpel_x_qn & SUBPEL_MASK); |
730 | 824 | for (y = 0; y < im_h; ++y) { |
731 | 6.48k | for (x = 0; x < w; ++x) { |
732 | 5.71k | int32_t sum = (1 << (bd + FILTER_BITS - 1)); |
733 | 51.4k | for (k = 0; k < filter_params_x->taps; ++k) { |
734 | 45.6k | sum += x_filter[k] * src_horiz[y * src_stride + x - fo_horiz + k]; |
735 | 45.6k | } |
736 | 5.71k | assert(0 <= sum && sum < (1 << (bd + FILTER_BITS + 1))); |
737 | 5.71k | (void)bd; |
738 | 5.71k | im_block[y * im_stride + x] = |
739 | 5.71k | (int16_t)ROUND_POWER_OF_TWO(sum, conv_params->round_0); |
740 | 5.71k | } |
741 | 768 | } |
742 | | |
743 | | // vertical filter |
744 | 56 | int16_t *src_vert = im_block + fo_vert * im_stride; |
745 | 56 | const int offset_bits = bd + 2 * FILTER_BITS - conv_params->round_0; |
746 | 56 | const int16_t *y_filter = av1_get_interp_filter_subpel_kernel( |
747 | 56 | filter_params_y, subpel_y_qn & SUBPEL_MASK); |
748 | 432 | for (y = 0; y < h; ++y) { |
749 | 3.28k | for (x = 0; x < w; ++x) { |
750 | 2.91k | int32_t sum = 1 << offset_bits; |
751 | 26.2k | for (k = 0; k < filter_params_y->taps; ++k) { |
752 | 23.2k | sum += y_filter[k] * src_vert[(y - fo_vert + k) * im_stride + x]; |
753 | 23.2k | } |
754 | 2.91k | assert(0 <= sum && sum < (1 << (offset_bits + 2))); |
755 | 2.91k | CONV_BUF_TYPE res = ROUND_POWER_OF_TWO(sum, conv_params->round_1); |
756 | 2.91k | if (conv_params->do_average) { |
757 | 1.24k | int32_t tmp = dst16[y * dst16_stride + x]; |
758 | 1.24k | if (conv_params->use_dist_wtd_comp_avg) { |
759 | 384 | tmp = tmp * conv_params->fwd_offset + res * conv_params->bck_offset; |
760 | 384 | tmp = tmp >> DIST_PRECISION_BITS; |
761 | 864 | } else { |
762 | 864 | tmp += res; |
763 | 864 | tmp = tmp >> 1; |
764 | 864 | } |
765 | 1.24k | tmp -= (1 << (offset_bits - conv_params->round_1)) + |
766 | 1.24k | (1 << (offset_bits - conv_params->round_1 - 1)); |
767 | 1.24k | dst[y * dst_stride + x] = |
768 | 1.24k | clip_pixel_highbd(ROUND_POWER_OF_TWO(tmp, round_bits), bd); |
769 | 1.66k | } else { |
770 | 1.66k | dst16[y * dst16_stride + x] = res; |
771 | 1.66k | } |
772 | 2.91k | } |
773 | 376 | } |
774 | 56 | } |
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 | 47 | ConvolveParams *conv_params, int bd) { |
782 | 47 | CONV_BUF_TYPE *dst16 = conv_params->dst; |
783 | 47 | int dst16_stride = conv_params->dst_stride; |
784 | 47 | const int fo_horiz = filter_params_x->taps / 2 - 1; |
785 | 47 | const int bits = FILTER_BITS - conv_params->round_1; |
786 | 47 | const int offset_bits = bd + 2 * FILTER_BITS - conv_params->round_0; |
787 | 47 | const int round_offset = (1 << (offset_bits - conv_params->round_1)) + |
788 | 47 | (1 << (offset_bits - conv_params->round_1 - 1)); |
789 | 47 | const int round_bits = |
790 | 47 | 2 * FILTER_BITS - conv_params->round_0 - conv_params->round_1; |
791 | 47 | assert(round_bits >= 0); |
792 | 47 | assert(bits >= 0); |
793 | | // horizontal filter |
794 | 47 | const int16_t *x_filter = av1_get_interp_filter_subpel_kernel( |
795 | 47 | filter_params_x, subpel_x_qn & SUBPEL_MASK); |
796 | 407 | for (int y = 0; y < h; ++y) { |
797 | 3.17k | for (int x = 0; x < w; ++x) { |
798 | 2.81k | int32_t res = 0; |
799 | 25.3k | for (int k = 0; k < filter_params_x->taps; ++k) { |
800 | 22.5k | res += x_filter[k] * src[y * src_stride + x - fo_horiz + k]; |
801 | 22.5k | } |
802 | 2.81k | res = (1 << bits) * ROUND_POWER_OF_TWO(res, conv_params->round_0); |
803 | 2.81k | res += round_offset; |
804 | | |
805 | 2.81k | if (conv_params->do_average) { |
806 | 1.40k | int32_t tmp = dst16[y * dst16_stride + x]; |
807 | 1.40k | if (conv_params->use_dist_wtd_comp_avg) { |
808 | 896 | tmp = tmp * conv_params->fwd_offset + res * conv_params->bck_offset; |
809 | 896 | tmp = tmp >> DIST_PRECISION_BITS; |
810 | 896 | } else { |
811 | 512 | tmp += res; |
812 | 512 | tmp = tmp >> 1; |
813 | 512 | } |
814 | 1.40k | tmp -= round_offset; |
815 | 1.40k | dst[y * dst_stride + x] = |
816 | 1.40k | clip_pixel_highbd(ROUND_POWER_OF_TWO(tmp, round_bits), bd); |
817 | 1.40k | } else { |
818 | 1.40k | dst16[y * dst16_stride + x] = res; |
819 | 1.40k | } |
820 | 2.81k | } |
821 | 360 | } |
822 | 47 | } |
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 | 33 | ConvolveParams *conv_params, int bd) { |
830 | 33 | CONV_BUF_TYPE *dst16 = conv_params->dst; |
831 | 33 | int dst16_stride = conv_params->dst_stride; |
832 | 33 | const int fo_vert = filter_params_y->taps / 2 - 1; |
833 | 33 | const int bits = FILTER_BITS - conv_params->round_0; |
834 | 33 | const int offset_bits = bd + 2 * FILTER_BITS - conv_params->round_0; |
835 | 33 | const int round_offset = (1 << (offset_bits - conv_params->round_1)) + |
836 | 33 | (1 << (offset_bits - conv_params->round_1 - 1)); |
837 | 33 | const int round_bits = |
838 | 33 | 2 * FILTER_BITS - conv_params->round_0 - conv_params->round_1; |
839 | 33 | assert(round_bits >= 0); |
840 | 33 | assert(bits >= 0); |
841 | | // vertical filter |
842 | 33 | const int16_t *y_filter = av1_get_interp_filter_subpel_kernel( |
843 | 33 | filter_params_y, subpel_y_qn & SUBPEL_MASK); |
844 | 257 | for (int y = 0; y < h; ++y) { |
845 | 2.04k | for (int x = 0; x < w; ++x) { |
846 | 1.82k | int32_t res = 0; |
847 | 16.4k | for (int k = 0; k < filter_params_y->taps; ++k) { |
848 | 14.5k | res += y_filter[k] * src[(y - fo_vert + k) * src_stride + x]; |
849 | 14.5k | } |
850 | 1.82k | res *= (1 << bits); |
851 | 1.82k | res = ROUND_POWER_OF_TWO(res, conv_params->round_1) + round_offset; |
852 | | |
853 | 1.82k | if (conv_params->do_average) { |
854 | 864 | int32_t tmp = dst16[y * dst16_stride + x]; |
855 | 864 | if (conv_params->use_dist_wtd_comp_avg) { |
856 | 192 | tmp = tmp * conv_params->fwd_offset + res * conv_params->bck_offset; |
857 | 192 | tmp = tmp >> DIST_PRECISION_BITS; |
858 | 672 | } else { |
859 | 672 | tmp += res; |
860 | 672 | tmp = tmp >> 1; |
861 | 672 | } |
862 | 864 | tmp -= round_offset; |
863 | 864 | dst[y * dst_stride + x] = |
864 | 864 | clip_pixel_highbd(ROUND_POWER_OF_TWO(tmp, round_bits), bd); |
865 | 960 | } else { |
866 | 960 | dst16[y * dst16_stride + x] = res; |
867 | 960 | } |
868 | 1.82k | } |
869 | 224 | } |
870 | 33 | } |
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 | 180 | int bd) { |
877 | 180 | CONV_BUF_TYPE *dst16 = conv_params->dst; |
878 | 180 | int dst16_stride = conv_params->dst_stride; |
879 | 180 | const int bits = |
880 | 180 | FILTER_BITS * 2 - conv_params->round_1 - conv_params->round_0; |
881 | 180 | const int offset_bits = bd + 2 * FILTER_BITS - conv_params->round_0; |
882 | 180 | const int round_offset = (1 << (offset_bits - conv_params->round_1)) + |
883 | 180 | (1 << (offset_bits - conv_params->round_1 - 1)); |
884 | 180 | assert(bits >= 0); |
885 | | |
886 | 1.50k | for (int y = 0; y < h; ++y) { |
887 | 11.8k | for (int x = 0; x < w; ++x) { |
888 | 10.5k | CONV_BUF_TYPE res = src[y * src_stride + x] << bits; |
889 | 10.5k | res += round_offset; |
890 | 10.5k | if (conv_params->do_average) { |
891 | 4.25k | int32_t tmp = dst16[y * dst16_stride + x]; |
892 | 4.25k | if (conv_params->use_dist_wtd_comp_avg) { |
893 | 320 | tmp = tmp * conv_params->fwd_offset + res * conv_params->bck_offset; |
894 | 320 | tmp = tmp >> DIST_PRECISION_BITS; |
895 | 3.93k | } else { |
896 | 3.93k | tmp += res; |
897 | 3.93k | tmp = tmp >> 1; |
898 | 3.93k | } |
899 | 4.25k | tmp -= round_offset; |
900 | 4.25k | dst[y * dst_stride + x] = |
901 | 4.25k | clip_pixel_highbd(ROUND_POWER_OF_TWO(tmp, bits), bd); |
902 | 6.30k | } else { |
903 | 6.30k | dst16[y * dst16_stride + x] = res; |
904 | 6.30k | } |
905 | 10.5k | } |
906 | 1.32k | } |
907 | 180 | } |
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 | 1.26k | ConvolveParams *conv_params, int bd) { |
916 | 1.26k | int16_t im_block[(2 * MAX_SB_SIZE + MAX_FILTER_TAP) * MAX_SB_SIZE]; |
917 | 1.26k | int im_h = (((h - 1) * y_step_qn + subpel_y_qn) >> SCALE_SUBPEL_BITS) + |
918 | 1.26k | filter_params_y->taps; |
919 | 1.26k | int im_stride = w; |
920 | 1.26k | const int fo_vert = filter_params_y->taps / 2 - 1; |
921 | 1.26k | const int fo_horiz = filter_params_x->taps / 2 - 1; |
922 | 1.26k | CONV_BUF_TYPE *dst16 = conv_params->dst; |
923 | 1.26k | const int dst16_stride = conv_params->dst_stride; |
924 | 1.26k | const int bits = |
925 | 1.26k | FILTER_BITS * 2 - conv_params->round_0 - conv_params->round_1; |
926 | 1.26k | assert(bits >= 0); |
927 | | // horizontal filter |
928 | 1.26k | const uint16_t *src_horiz = src - fo_vert * src_stride; |
929 | 16.4k | for (int y = 0; y < im_h; ++y) { |
930 | 15.1k | int x_qn = subpel_x_qn; |
931 | 96.6k | for (int x = 0; x < w; ++x, x_qn += x_step_qn) { |
932 | 81.4k | const uint16_t *const src_x = &src_horiz[(x_qn >> SCALE_SUBPEL_BITS)]; |
933 | 81.4k | const int x_filter_idx = (x_qn & SCALE_SUBPEL_MASK) >> SCALE_EXTRA_BITS; |
934 | 81.4k | assert(x_filter_idx < SUBPEL_SHIFTS); |
935 | 81.4k | const int16_t *x_filter = |
936 | 81.4k | av1_get_interp_filter_subpel_kernel(filter_params_x, x_filter_idx); |
937 | 81.4k | int32_t sum = (1 << (bd + FILTER_BITS - 1)); |
938 | 733k | for (int k = 0; k < filter_params_x->taps; ++k) { |
939 | 651k | sum += x_filter[k] * src_x[k - fo_horiz]; |
940 | 651k | } |
941 | 81.4k | assert(0 <= sum && sum < (1 << (bd + FILTER_BITS + 1))); |
942 | 81.4k | im_block[y * im_stride + x] = |
943 | 81.4k | (int16_t)ROUND_POWER_OF_TWO(sum, conv_params->round_0); |
944 | 81.4k | } |
945 | 15.1k | src_horiz += src_stride; |
946 | 15.1k | } |
947 | | |
948 | | // vertical filter |
949 | 1.26k | int16_t *src_vert = im_block + fo_vert * im_stride; |
950 | 1.26k | const int offset_bits = bd + 2 * FILTER_BITS - conv_params->round_0; |
951 | 7.62k | for (int x = 0; x < w; ++x) { |
952 | 6.35k | int y_qn = subpel_y_qn; |
953 | 43.1k | for (int y = 0; y < h; ++y, y_qn += y_step_qn) { |
954 | 36.8k | const int16_t *src_y = &src_vert[(y_qn >> SCALE_SUBPEL_BITS) * im_stride]; |
955 | 36.8k | const int y_filter_idx = (y_qn & SCALE_SUBPEL_MASK) >> SCALE_EXTRA_BITS; |
956 | 36.8k | assert(y_filter_idx < SUBPEL_SHIFTS); |
957 | 36.8k | const int16_t *y_filter = |
958 | 36.8k | av1_get_interp_filter_subpel_kernel(filter_params_y, y_filter_idx); |
959 | 36.8k | int32_t sum = 1 << offset_bits; |
960 | 331k | for (int k = 0; k < filter_params_y->taps; ++k) { |
961 | 294k | sum += y_filter[k] * src_y[(k - fo_vert) * im_stride]; |
962 | 294k | } |
963 | 36.8k | assert(0 <= sum && sum < (1 << (offset_bits + 2))); |
964 | 36.8k | CONV_BUF_TYPE res = ROUND_POWER_OF_TWO(sum, conv_params->round_1); |
965 | 36.8k | if (conv_params->is_compound) { |
966 | 9.08k | if (conv_params->do_average) { |
967 | 2.36k | int32_t tmp = dst16[y * dst16_stride + x]; |
968 | 2.36k | if (conv_params->use_dist_wtd_comp_avg) { |
969 | 192 | tmp = tmp * conv_params->fwd_offset + res * conv_params->bck_offset; |
970 | 192 | tmp = tmp >> DIST_PRECISION_BITS; |
971 | 2.17k | } else { |
972 | 2.17k | tmp += res; |
973 | 2.17k | tmp = tmp >> 1; |
974 | 2.17k | } |
975 | | /* Subtract round offset and convolve round */ |
976 | 2.36k | tmp = tmp - ((1 << (offset_bits - conv_params->round_1)) + |
977 | 2.36k | (1 << (offset_bits - conv_params->round_1 - 1))); |
978 | 2.36k | dst[y * dst_stride + x] = |
979 | 2.36k | clip_pixel_highbd(ROUND_POWER_OF_TWO(tmp, bits), bd); |
980 | 6.72k | } else { |
981 | 6.72k | dst16[y * dst16_stride + x] = res; |
982 | 6.72k | } |
983 | 27.7k | } else { |
984 | | /* Subtract round offset and convolve round */ |
985 | 27.7k | int32_t tmp = res - ((1 << (offset_bits - conv_params->round_1)) + |
986 | 27.7k | (1 << (offset_bits - conv_params->round_1 - 1))); |
987 | 27.7k | dst[y * dst_stride + x] = |
988 | 27.7k | clip_pixel_highbd(ROUND_POWER_OF_TWO(tmp, bits), bd); |
989 | 27.7k | } |
990 | 36.8k | } |
991 | 6.35k | src_vert++; |
992 | 6.35k | } |
993 | 1.26k | } |
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 | 316 | const int subpel_y_qn, ConvolveParams *conv_params, int bd) { |
1000 | 316 | const bool need_x = subpel_x_qn != 0; |
1001 | 316 | const bool need_y = subpel_y_qn != 0; |
1002 | 316 | if (!need_x && !need_y) { |
1003 | 180 | av1_highbd_dist_wtd_convolve_2d_copy(src, src_stride, dst, dst_stride, w, h, |
1004 | 180 | conv_params, bd); |
1005 | 180 | } else if (need_x && !need_y) { |
1006 | 47 | av1_highbd_dist_wtd_convolve_x(src, src_stride, dst, dst_stride, w, h, |
1007 | 47 | filter_params_x, subpel_x_qn, conv_params, |
1008 | 47 | bd); |
1009 | 89 | } else if (!need_x && need_y) { |
1010 | 33 | av1_highbd_dist_wtd_convolve_y(src, src_stride, dst, dst_stride, w, h, |
1011 | 33 | filter_params_y, subpel_y_qn, conv_params, |
1012 | 33 | bd); |
1013 | 56 | } else { |
1014 | 56 | assert(need_x && need_y); |
1015 | 56 | av1_highbd_dist_wtd_convolve_2d(src, src_stride, dst, dst_stride, w, h, |
1016 | 56 | filter_params_x, filter_params_y, |
1017 | 56 | subpel_x_qn, subpel_y_qn, conv_params, bd); |
1018 | 56 | } |
1019 | 316 | } |
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 | 73.7k | const int subpel_y_qn, ConvolveParams *conv_params, int bd) { |
1026 | 73.7k | const bool need_x = subpel_x_qn != 0; |
1027 | 73.7k | const bool need_y = subpel_y_qn != 0; |
1028 | | |
1029 | 73.7k | if (!need_x && !need_y) { |
1030 | 56.0k | aom_highbd_convolve_copy(src, src_stride, dst, dst_stride, w, h); |
1031 | 56.0k | } else if (need_x && !need_y) { |
1032 | 6.87k | av1_highbd_convolve_x_sr(src, src_stride, dst, dst_stride, w, h, |
1033 | 6.87k | filter_params_x, subpel_x_qn, conv_params, bd); |
1034 | 10.8k | } else if (!need_x && need_y) { |
1035 | 5.57k | av1_highbd_convolve_y_sr(src, src_stride, dst, dst_stride, w, h, |
1036 | 5.57k | filter_params_y, subpel_y_qn, bd); |
1037 | 5.57k | } else { |
1038 | 5.24k | assert(need_x && need_y); |
1039 | 5.24k | av1_highbd_convolve_2d_sr(src, src_stride, dst, dst_stride, w, h, |
1040 | 5.24k | filter_params_x, filter_params_y, subpel_x_qn, |
1041 | 5.24k | subpel_y_qn, conv_params, bd); |
1042 | 5.24k | } |
1043 | 73.7k | } |
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 | 75.3k | int bd) { |
1052 | 75.3k | (void)x_step_q4; |
1053 | 75.3k | (void)y_step_q4; |
1054 | 75.3k | (void)dst_stride; |
1055 | 75.3k | const uint16_t *src = CONVERT_TO_SHORTPTR(src8); |
1056 | | |
1057 | 75.3k | const int need_filter_params_x = (subpel_x_qn != 0) | scaled; |
1058 | 75.3k | const int need_filter_params_y = (subpel_y_qn != 0) | scaled; |
1059 | 75.3k | const InterpFilterParams *filter_params_x = |
1060 | 75.3k | need_filter_params_x ? interp_filters[0] : NULL; |
1061 | 75.3k | const InterpFilterParams *filter_params_y = |
1062 | 75.3k | need_filter_params_y ? interp_filters[1] : NULL; |
1063 | | |
1064 | 75.3k | uint16_t *dst = CONVERT_TO_SHORTPTR(dst8); |
1065 | 75.3k | if (scaled) { |
1066 | 1.26k | if (conv_params->is_compound) { |
1067 | 103 | assert(conv_params->dst != NULL); |
1068 | 103 | } |
1069 | 1.26k | av1_highbd_convolve_2d_scale(src, src_stride, dst, dst_stride, w, h, |
1070 | 1.26k | filter_params_x, filter_params_y, subpel_x_qn, |
1071 | 1.26k | x_step_q4, subpel_y_qn, y_step_q4, conv_params, |
1072 | 1.26k | bd); |
1073 | 74.0k | } else if (conv_params->is_compound) { |
1074 | 316 | highbd_convolve_2d_facade_compound( |
1075 | 316 | src, src_stride, dst, dst_stride, w, h, filter_params_x, |
1076 | 316 | filter_params_y, subpel_x_qn, subpel_y_qn, conv_params, bd); |
1077 | 73.7k | } else { |
1078 | 73.7k | highbd_convolve_2d_facade_single(src, src_stride, dst, dst_stride, w, h, |
1079 | 73.7k | filter_params_x, filter_params_y, |
1080 | 73.7k | subpel_x_qn, subpel_y_qn, conv_params, bd); |
1081 | 73.7k | } |
1082 | 75.3k | } |
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 | 34.8M | static INLINE int horz_scalar_product(const uint8_t *a, const int16_t *b) { |
1100 | 34.8M | int sum = 0; |
1101 | 313M | for (int k = 0; k < SUBPEL_TAPS; ++k) sum += a[k] * b[k]; |
1102 | 34.8M | return sum; |
1103 | 34.8M | } |
1104 | | |
1105 | | #if CONFIG_AV1_HIGHBITDEPTH |
1106 | | static INLINE int highbd_horz_scalar_product(const uint16_t *a, |
1107 | 11.1M | const int16_t *b) { |
1108 | 11.1M | int sum = 0; |
1109 | 100M | for (int k = 0; k < SUBPEL_TAPS; ++k) sum += a[k] * b[k]; |
1110 | 11.1M | return sum; |
1111 | 11.1M | } |
1112 | | #endif |
1113 | | |
1114 | | static INLINE int highbd_vert_scalar_product(const uint16_t *a, |
1115 | | ptrdiff_t a_stride, |
1116 | 41.0M | const int16_t *b) { |
1117 | 41.0M | int sum = 0; |
1118 | 369M | for (int k = 0; k < SUBPEL_TAPS; ++k) sum += a[k * a_stride] * b[k]; |
1119 | 41.0M | return sum; |
1120 | 41.0M | } |
1121 | | |
1122 | 31.6k | 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 | 31.6k | return (const InterpKernel *)(((intptr_t)filter) & ~((intptr_t)0xFF)); |
1126 | 31.6k | } |
1127 | | |
1128 | 31.6k | static int get_filter_offset(const int16_t *f, const InterpKernel *base) { |
1129 | 31.6k | return (int)((const InterpKernel *)(intptr_t)f - base); |
1130 | 31.6k | } |
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 | 10.5k | int round0_bits) { |
1137 | 10.5k | const int bd = 8; |
1138 | 10.5k | src -= SUBPEL_TAPS / 2 - 1; |
1139 | 640k | for (int y = 0; y < h; ++y) { |
1140 | 630k | int x_q4 = x0_q4; |
1141 | 35.4M | for (int x = 0; x < w; ++x) { |
1142 | 34.8M | const uint8_t *const src_x = &src[x_q4 >> SUBPEL_BITS]; |
1143 | 34.8M | const int16_t *const x_filter = x_filters[x_q4 & SUBPEL_MASK]; |
1144 | 34.8M | const int rounding = ((int)src_x[SUBPEL_TAPS / 2 - 1] << FILTER_BITS) + |
1145 | 34.8M | (1 << (bd + FILTER_BITS - 1)); |
1146 | 34.8M | const int sum = horz_scalar_product(src_x, x_filter) + rounding; |
1147 | 34.8M | dst[x] = (uint16_t)clamp(ROUND_POWER_OF_TWO(sum, round0_bits), 0, |
1148 | 34.8M | WIENER_CLAMP_LIMIT(round0_bits, bd) - 1); |
1149 | 34.8M | x_q4 += x_step_q4; |
1150 | 34.8M | } |
1151 | 630k | src += src_stride; |
1152 | 630k | dst += dst_stride; |
1153 | 630k | } |
1154 | 10.5k | } |
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 | 10.5k | int round1_bits) { |
1161 | 10.5k | const int bd = 8; |
1162 | 10.5k | src -= src_stride * (SUBPEL_TAPS / 2 - 1); |
1163 | | |
1164 | 572k | for (int x = 0; x < w; ++x) { |
1165 | 561k | int y_q4 = y0_q4; |
1166 | 32.0M | for (int y = 0; y < h; ++y) { |
1167 | 31.4M | const uint16_t *src_y = &src[(y_q4 >> SUBPEL_BITS) * src_stride]; |
1168 | 31.4M | const int16_t *const y_filter = y_filters[y_q4 & SUBPEL_MASK]; |
1169 | 31.4M | const int rounding = |
1170 | 31.4M | ((int)src_y[(SUBPEL_TAPS / 2 - 1) * src_stride] << FILTER_BITS) - |
1171 | 31.4M | (1 << (bd + round1_bits - 1)); |
1172 | 31.4M | const int sum = |
1173 | 31.4M | highbd_vert_scalar_product(src_y, src_stride, y_filter) + rounding; |
1174 | 31.4M | dst[y * dst_stride] = clip_pixel(ROUND_POWER_OF_TWO(sum, round1_bits)); |
1175 | 31.4M | y_q4 += y_step_q4; |
1176 | 31.4M | } |
1177 | 561k | ++src; |
1178 | 561k | ++dst; |
1179 | 561k | } |
1180 | 10.5k | } |
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 | 10.5k | const ConvolveParams *conv_params) { |
1188 | 10.5k | const InterpKernel *const filters_x = get_filter_base(filter_x); |
1189 | 10.5k | const int x0_q4 = get_filter_offset(filter_x, filters_x); |
1190 | | |
1191 | 10.5k | const InterpKernel *const filters_y = get_filter_base(filter_y); |
1192 | 10.5k | const int y0_q4 = get_filter_offset(filter_y, filters_y); |
1193 | | |
1194 | 10.5k | uint16_t temp[WIENER_MAX_EXT_SIZE * MAX_SB_SIZE]; |
1195 | 10.5k | const int intermediate_height = |
1196 | 10.5k | (((h - 1) * y_step_q4 + y0_q4) >> SUBPEL_BITS) + SUBPEL_TAPS - 1; |
1197 | 10.5k | memset(temp + (intermediate_height * MAX_SB_SIZE), 0, MAX_SB_SIZE); |
1198 | | |
1199 | 10.5k | assert(w <= MAX_SB_SIZE); |
1200 | 10.5k | assert(h <= MAX_SB_SIZE); |
1201 | 10.5k | assert(y_step_q4 <= 32); |
1202 | 10.5k | assert(x_step_q4 <= 32); |
1203 | | |
1204 | 10.5k | convolve_add_src_horiz_hip(src - src_stride * (SUBPEL_TAPS / 2 - 1), |
1205 | 10.5k | src_stride, temp, MAX_SB_SIZE, filters_x, x0_q4, |
1206 | 10.5k | x_step_q4, w, intermediate_height, |
1207 | 10.5k | conv_params->round_0); |
1208 | 10.5k | convolve_add_src_vert_hip(temp + MAX_SB_SIZE * (SUBPEL_TAPS / 2 - 1), |
1209 | 10.5k | MAX_SB_SIZE, dst, dst_stride, filters_y, y0_q4, |
1210 | 10.5k | y_step_q4, w, h, conv_params->round_1); |
1211 | 10.5k | } |
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 | 5.24k | int x_step_q4, int w, int h, int round0_bits, int bd) { |
1218 | 5.24k | const int extraprec_clamp_limit = WIENER_CLAMP_LIMIT(round0_bits, bd); |
1219 | 5.24k | uint16_t *src = CONVERT_TO_SHORTPTR(src8); |
1220 | 5.24k | src -= SUBPEL_TAPS / 2 - 1; |
1221 | 257k | for (int y = 0; y < h; ++y) { |
1222 | 251k | int x_q4 = x0_q4; |
1223 | 11.3M | for (int x = 0; x < w; ++x) { |
1224 | 11.1M | const uint16_t *const src_x = &src[x_q4 >> SUBPEL_BITS]; |
1225 | 11.1M | const int16_t *const x_filter = x_filters[x_q4 & SUBPEL_MASK]; |
1226 | 11.1M | const int rounding = ((int)src_x[SUBPEL_TAPS / 2 - 1] << FILTER_BITS) + |
1227 | 11.1M | (1 << (bd + FILTER_BITS - 1)); |
1228 | 11.1M | const int sum = highbd_horz_scalar_product(src_x, x_filter) + rounding; |
1229 | 11.1M | dst[x] = (uint16_t)clamp(ROUND_POWER_OF_TWO(sum, round0_bits), 0, |
1230 | 11.1M | extraprec_clamp_limit - 1); |
1231 | 11.1M | x_q4 += x_step_q4; |
1232 | 11.1M | } |
1233 | 251k | src += src_stride; |
1234 | 251k | dst += dst_stride; |
1235 | 251k | } |
1236 | 5.24k | } |
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 | 5.24k | int y_step_q4, int w, int h, int round1_bits, int bd) { |
1242 | 5.24k | uint16_t *dst = CONVERT_TO_SHORTPTR(dst8); |
1243 | 5.24k | src -= src_stride * (SUBPEL_TAPS / 2 - 1); |
1244 | 225k | for (int x = 0; x < w; ++x) { |
1245 | 220k | int y_q4 = y0_q4; |
1246 | 9.79M | for (int y = 0; y < h; ++y) { |
1247 | 9.57M | const uint16_t *src_y = &src[(y_q4 >> SUBPEL_BITS) * src_stride]; |
1248 | 9.57M | const int16_t *const y_filter = y_filters[y_q4 & SUBPEL_MASK]; |
1249 | 9.57M | const int rounding = |
1250 | 9.57M | ((int)src_y[(SUBPEL_TAPS / 2 - 1) * src_stride] << FILTER_BITS) - |
1251 | 9.57M | (1 << (bd + round1_bits - 1)); |
1252 | 9.57M | const int sum = |
1253 | 9.57M | highbd_vert_scalar_product(src_y, src_stride, y_filter) + rounding; |
1254 | 9.57M | dst[y * dst_stride] = |
1255 | 9.57M | clip_pixel_highbd(ROUND_POWER_OF_TWO(sum, round1_bits), bd); |
1256 | 9.57M | y_q4 += y_step_q4; |
1257 | 9.57M | } |
1258 | 220k | ++src; |
1259 | 220k | ++dst; |
1260 | 220k | } |
1261 | 5.24k | } |
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 | 5.24k | const ConvolveParams *conv_params, int bd) { |
1268 | 5.24k | const InterpKernel *const filters_x = get_filter_base(filter_x); |
1269 | 5.24k | const int x0_q4 = get_filter_offset(filter_x, filters_x); |
1270 | | |
1271 | 5.24k | const InterpKernel *const filters_y = get_filter_base(filter_y); |
1272 | 5.24k | const int y0_q4 = get_filter_offset(filter_y, filters_y); |
1273 | | |
1274 | 5.24k | uint16_t temp[WIENER_MAX_EXT_SIZE * MAX_SB_SIZE]; |
1275 | 5.24k | const int intermediate_height = |
1276 | 5.24k | (((h - 1) * y_step_q4 + y0_q4) >> SUBPEL_BITS) + SUBPEL_TAPS; |
1277 | | |
1278 | 5.24k | assert(w <= MAX_SB_SIZE); |
1279 | 5.24k | assert(h <= MAX_SB_SIZE); |
1280 | 5.24k | assert(y_step_q4 <= 32); |
1281 | 5.24k | assert(x_step_q4 <= 32); |
1282 | 5.24k | assert(bd + FILTER_BITS - conv_params->round_0 + 2 <= 16); |
1283 | | |
1284 | 5.24k | highbd_convolve_add_src_horiz_hip(src - src_stride * (SUBPEL_TAPS / 2 - 1), |
1285 | 5.24k | src_stride, temp, MAX_SB_SIZE, filters_x, |
1286 | 5.24k | x0_q4, x_step_q4, w, intermediate_height, |
1287 | 5.24k | conv_params->round_0, bd); |
1288 | 5.24k | highbd_convolve_add_src_vert_hip( |
1289 | 5.24k | temp + MAX_SB_SIZE * (SUBPEL_TAPS / 2 - 1), MAX_SB_SIZE, dst, dst_stride, |
1290 | 5.24k | filters_y, y0_q4, y_step_q4, w, h, conv_params->round_1, bd); |
1291 | 5.24k | } |
1292 | | #endif // CONFIG_AV1_HIGHBITDEPTH |