/src/aom/av1/common/cdef.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 <math.h> |
14 | | #include <string.h> |
15 | | |
16 | | #include "config/aom_scale_rtcd.h" |
17 | | |
18 | | #include "aom/aom_integer.h" |
19 | | #include "av1/common/av1_common_int.h" |
20 | | #include "av1/common/cdef.h" |
21 | | #include "av1/common/cdef_block.h" |
22 | | #include "av1/common/reconinter.h" |
23 | | |
24 | | static int is_8x8_block_skip(MB_MODE_INFO **grid, int mi_row, int mi_col, |
25 | 34.8M | int mi_stride) { |
26 | 34.8M | MB_MODE_INFO **mbmi = grid + mi_row * mi_stride + mi_col; |
27 | 50.8M | for (int r = 0; r < mi_size_high[BLOCK_8X8]; ++r, mbmi += mi_stride) { |
28 | 74.8M | for (int c = 0; c < mi_size_wide[BLOCK_8X8]; ++c) { |
29 | 58.8M | if (!mbmi[c]->skip_txfm) return 0; |
30 | 58.8M | } |
31 | 42.8M | } |
32 | | |
33 | 8.00M | return 1; |
34 | 34.8M | } |
35 | | |
36 | | int av1_cdef_compute_sb_list(const CommonModeInfoParams *const mi_params, |
37 | | int mi_row, int mi_col, cdef_list *dlist, |
38 | 609k | BLOCK_SIZE bs) { |
39 | 609k | MB_MODE_INFO **grid = mi_params->mi_grid_base; |
40 | 609k | int maxc = mi_params->mi_cols - mi_col; |
41 | 609k | int maxr = mi_params->mi_rows - mi_row; |
42 | | |
43 | 610k | if (bs == BLOCK_128X128 || bs == BLOCK_128X64) |
44 | 0 | maxc = AOMMIN(maxc, MI_SIZE_128X128); |
45 | 609k | else |
46 | 609k | maxc = AOMMIN(maxc, MI_SIZE_64X64); |
47 | 609k | if (bs == BLOCK_128X128 || bs == BLOCK_64X128) |
48 | 0 | maxr = AOMMIN(maxr, MI_SIZE_128X128); |
49 | 609k | else |
50 | 609k | maxr = AOMMIN(maxr, MI_SIZE_64X64); |
51 | | |
52 | 609k | const int r_step = 2; // mi_size_high[BLOCK_8X8] |
53 | 609k | const int c_step = 2; // mi_size_wide[BLOCK_8X8] |
54 | 609k | const int r_shift = 1; |
55 | 609k | const int c_shift = 1; |
56 | 609k | int count = 0; |
57 | 5.28M | for (int r = 0; r < maxr; r += r_step) { |
58 | 39.4M | for (int c = 0; c < maxc; c += c_step) { |
59 | 34.8M | if (!is_8x8_block_skip(grid, mi_row + r, mi_col + c, |
60 | 34.8M | mi_params->mi_stride)) { |
61 | 26.8M | dlist[count].by = r >> r_shift; |
62 | 26.8M | dlist[count].bx = c >> c_shift; |
63 | 26.8M | count++; |
64 | 26.8M | } |
65 | 34.8M | } |
66 | 4.67M | } |
67 | 609k | return count; |
68 | 609k | } |
69 | | |
70 | | void cdef_copy_rect8_8bit_to_16bit_c(uint16_t *dst, int dstride, |
71 | | const uint8_t *src, int sstride, int width, |
72 | 0 | int height) { |
73 | 0 | for (int i = 0; i < height; i++) { |
74 | 0 | for (int j = 0; j < width; j++) { |
75 | 0 | dst[i * dstride + j] = src[i * sstride + j]; |
76 | 0 | } |
77 | 0 | } |
78 | 0 | } |
79 | | |
80 | | void cdef_copy_rect8_16bit_to_16bit_c(uint16_t *dst, int dstride, |
81 | | const uint16_t *src, int sstride, |
82 | 0 | int width, int height) { |
83 | 0 | for (int i = 0; i < height; i++) { |
84 | 0 | for (int j = 0; j < width; j++) { |
85 | 0 | dst[i * dstride + j] = src[i * sstride + j]; |
86 | 0 | } |
87 | 0 | } |
88 | 0 | } |
89 | | |
90 | | void av1_cdef_copy_sb8_16_lowbd(uint16_t *const dst, int dstride, |
91 | | const uint8_t *src, int src_voffset, |
92 | | int src_hoffset, int sstride, int vsize, |
93 | 1.12M | int hsize) { |
94 | 1.12M | const uint8_t *base = &src[src_voffset * sstride + src_hoffset]; |
95 | 1.12M | cdef_copy_rect8_8bit_to_16bit(dst, dstride, base, sstride, hsize, vsize); |
96 | 1.12M | } |
97 | | |
98 | | void av1_cdef_copy_sb8_16_highbd(uint16_t *const dst, int dstride, |
99 | | const uint8_t *src, int src_voffset, |
100 | | int src_hoffset, int sstride, int vsize, |
101 | 481k | int hsize) { |
102 | 481k | const uint16_t *base = |
103 | 481k | &CONVERT_TO_SHORTPTR(src)[src_voffset * sstride + src_hoffset]; |
104 | 481k | cdef_copy_rect8_16bit_to_16bit(dst, dstride, base, sstride, hsize, vsize); |
105 | 481k | } |
106 | | |
107 | | void av1_cdef_copy_sb8_16(const AV1_COMMON *const cm, uint16_t *const dst, |
108 | | int dstride, const uint8_t *src, int src_voffset, |
109 | 1.60M | int src_hoffset, int sstride, int vsize, int hsize) { |
110 | 1.60M | if (cm->seq_params->use_highbitdepth) { |
111 | 481k | av1_cdef_copy_sb8_16_highbd(dst, dstride, src, src_voffset, src_hoffset, |
112 | 481k | sstride, vsize, hsize); |
113 | 1.12M | } else { |
114 | 1.12M | av1_cdef_copy_sb8_16_lowbd(dst, dstride, src, src_voffset, src_hoffset, |
115 | 1.12M | sstride, vsize, hsize); |
116 | 1.12M | } |
117 | 1.60M | } |
118 | | |
119 | | static INLINE void copy_rect(uint16_t *dst, int dstride, const uint16_t *src, |
120 | 9.43M | int sstride, int v, int h) { |
121 | 142M | for (int i = 0; i < v; i++) { |
122 | 1.36G | for (int j = 0; j < h; j++) { |
123 | 1.22G | dst[i * dstride + j] = src[i * sstride + j]; |
124 | 1.22G | } |
125 | 133M | } |
126 | 9.43M | } |
127 | | |
128 | | // Prepares intermediate input buffer for CDEF. |
129 | | // Inputs: |
130 | | // cm: Pointer to common structure. |
131 | | // fb_info: Pointer to the CDEF block-level parameter structure. |
132 | | // colbuf: Left column buffer for CDEF. |
133 | | // cdef_left: Left block is filtered or not. |
134 | | // fbc, fbr: col and row index of a block. |
135 | | // plane: plane index Y/CB/CR. |
136 | | // Returns: |
137 | | // Nothing will be returned. |
138 | | static void cdef_prepare_fb(const AV1_COMMON *const cm, CdefBlockInfo *fb_info, |
139 | | uint16_t **const colbuf, const int cdef_left, |
140 | 1.31M | int fbc, int fbr, int plane) { |
141 | 1.31M | const CommonModeInfoParams *const mi_params = &cm->mi_params; |
142 | 1.31M | uint16_t *src = fb_info->src; |
143 | 1.31M | const int luma_stride = |
144 | 1.31M | ALIGN_POWER_OF_TWO(mi_params->mi_cols << MI_SIZE_LOG2, 4); |
145 | 1.31M | const int nvfb = (mi_params->mi_rows + MI_SIZE_64X64 - 1) / MI_SIZE_64X64; |
146 | 1.31M | const int nhfb = (mi_params->mi_cols + MI_SIZE_64X64 - 1) / MI_SIZE_64X64; |
147 | 1.31M | int cstart = 0; |
148 | 1.31M | if (!cdef_left) cstart = -CDEF_HBORDER; |
149 | 1.31M | int rend, cend; |
150 | 1.31M | const int nhb = |
151 | 1.31M | AOMMIN(MI_SIZE_64X64, mi_params->mi_cols - MI_SIZE_64X64 * fbc); |
152 | 1.31M | const int nvb = |
153 | 1.31M | AOMMIN(MI_SIZE_64X64, mi_params->mi_rows - MI_SIZE_64X64 * fbr); |
154 | 1.31M | const int hsize = nhb << fb_info->mi_wide_l2; |
155 | 1.31M | const int vsize = nvb << fb_info->mi_high_l2; |
156 | 1.31M | const uint16_t *top_linebuf = fb_info->top_linebuf[plane]; |
157 | 1.31M | const uint16_t *bot_linebuf = fb_info->bot_linebuf[plane]; |
158 | 1.31M | const int bot_offset = (vsize + CDEF_VBORDER) * CDEF_BSTRIDE; |
159 | 1.31M | const int stride = |
160 | 1.31M | luma_stride >> (plane == AOM_PLANE_Y ? 0 : cm->seq_params->subsampling_x); |
161 | | |
162 | 1.31M | if (fbc == nhfb - 1) |
163 | 125k | cend = hsize; |
164 | 1.19M | else |
165 | 1.19M | cend = hsize + CDEF_HBORDER; |
166 | | |
167 | 1.31M | if (fbr == nvfb - 1) |
168 | 125k | rend = vsize; |
169 | 1.19M | else |
170 | 1.19M | rend = vsize + CDEF_VBORDER; |
171 | | |
172 | | /* Copy in the pixels we need from the current superblock for |
173 | | deringing.*/ |
174 | 1.31M | av1_cdef_copy_sb8_16( |
175 | 1.31M | cm, &src[CDEF_VBORDER * CDEF_BSTRIDE + CDEF_HBORDER + cstart], |
176 | 1.31M | CDEF_BSTRIDE, fb_info->dst, fb_info->roffset, fb_info->coffset + cstart, |
177 | 1.31M | fb_info->dst_stride, vsize, cend - cstart); |
178 | | |
179 | | /* Copy in the pixels we need for the current superblock from bottom buffer.*/ |
180 | 1.31M | if (fbr < nvfb - 1) { |
181 | 1.19M | copy_rect(&src[bot_offset + CDEF_HBORDER], CDEF_BSTRIDE, |
182 | 1.19M | &bot_linebuf[fb_info->coffset], stride, CDEF_VBORDER, hsize); |
183 | 1.19M | } else { |
184 | 122k | fill_rect(&src[bot_offset + CDEF_HBORDER], CDEF_BSTRIDE, CDEF_VBORDER, |
185 | 122k | hsize, CDEF_VERY_LARGE); |
186 | 122k | } |
187 | 1.31M | if (fbr < nvfb - 1 && fbc > 0) { |
188 | 1.10M | copy_rect(&src[bot_offset], CDEF_BSTRIDE, |
189 | 1.10M | &bot_linebuf[fb_info->coffset - CDEF_HBORDER], stride, |
190 | 1.10M | CDEF_VBORDER, CDEF_HBORDER); |
191 | 1.10M | } else { |
192 | 211k | fill_rect(&src[bot_offset], CDEF_BSTRIDE, CDEF_VBORDER, CDEF_HBORDER, |
193 | 211k | CDEF_VERY_LARGE); |
194 | 211k | } |
195 | 1.31M | if (fbr < nvfb - 1 && fbc < nhfb - 1) { |
196 | 1.10M | copy_rect(&src[bot_offset + hsize + CDEF_HBORDER], CDEF_BSTRIDE, |
197 | 1.10M | &bot_linebuf[fb_info->coffset + hsize], stride, CDEF_VBORDER, |
198 | 1.10M | CDEF_HBORDER); |
199 | 1.10M | } else { |
200 | 208k | fill_rect(&src[bot_offset + hsize + CDEF_HBORDER], CDEF_BSTRIDE, |
201 | 208k | CDEF_VBORDER, CDEF_HBORDER, CDEF_VERY_LARGE); |
202 | 208k | } |
203 | | |
204 | | /* Copy in the pixels we need from the current superblock from top buffer.*/ |
205 | 1.31M | if (fbr > 0) { |
206 | 1.21M | copy_rect(&src[CDEF_HBORDER], CDEF_BSTRIDE, &top_linebuf[fb_info->coffset], |
207 | 1.21M | stride, CDEF_VBORDER, hsize); |
208 | 1.21M | } else { |
209 | 105k | fill_rect(&src[CDEF_HBORDER], CDEF_BSTRIDE, CDEF_VBORDER, hsize, |
210 | 105k | CDEF_VERY_LARGE); |
211 | 105k | } |
212 | 1.31M | if (fbr > 0 && fbc > 0) { |
213 | 1.11M | copy_rect(src, CDEF_BSTRIDE, &top_linebuf[fb_info->coffset - CDEF_HBORDER], |
214 | 1.11M | stride, CDEF_VBORDER, CDEF_HBORDER); |
215 | 1.11M | } else { |
216 | 197k | fill_rect(src, CDEF_BSTRIDE, CDEF_VBORDER, CDEF_HBORDER, CDEF_VERY_LARGE); |
217 | 197k | } |
218 | 1.31M | if (fbr > 0 && fbc < nhfb - 1) { |
219 | 1.12M | copy_rect(&src[hsize + CDEF_HBORDER], CDEF_BSTRIDE, |
220 | 1.12M | &top_linebuf[fb_info->coffset + hsize], stride, CDEF_VBORDER, |
221 | 1.12M | CDEF_HBORDER); |
222 | 1.12M | } else { |
223 | 195k | fill_rect(&src[hsize + CDEF_HBORDER], CDEF_BSTRIDE, CDEF_VBORDER, |
224 | 195k | CDEF_HBORDER, CDEF_VERY_LARGE); |
225 | 195k | } |
226 | 1.31M | if (cdef_left) { |
227 | | /* If we deringed the superblock on the left then we need to copy in |
228 | | saved pixels. */ |
229 | 1.29M | copy_rect(src, CDEF_BSTRIDE, colbuf[plane], CDEF_HBORDER, |
230 | 1.29M | rend + CDEF_VBORDER, CDEF_HBORDER); |
231 | 1.29M | } |
232 | | /* Saving pixels in case we need to dering the superblock on the |
233 | | right. */ |
234 | 1.31M | copy_rect(colbuf[plane], CDEF_HBORDER, src + hsize, CDEF_BSTRIDE, |
235 | 1.31M | rend + CDEF_VBORDER, CDEF_HBORDER); |
236 | | |
237 | 1.31M | if (fb_info->frame_boundary[LEFT]) { |
238 | 129k | fill_rect(src, CDEF_BSTRIDE, vsize + 2 * CDEF_VBORDER, CDEF_HBORDER, |
239 | 129k | CDEF_VERY_LARGE); |
240 | 129k | } |
241 | 1.31M | if (fb_info->frame_boundary[RIGHT]) { |
242 | 125k | fill_rect(&src[hsize + CDEF_HBORDER], CDEF_BSTRIDE, |
243 | 125k | vsize + 2 * CDEF_VBORDER, CDEF_HBORDER, CDEF_VERY_LARGE); |
244 | 125k | } |
245 | 1.31M | } |
246 | | |
247 | | static INLINE void cdef_filter_fb(CdefBlockInfo *const fb_info, int plane, |
248 | 1.32M | uint8_t use_highbitdepth) { |
249 | 1.32M | int offset = fb_info->dst_stride * fb_info->roffset + fb_info->coffset; |
250 | 1.32M | if (use_highbitdepth) { |
251 | 367k | av1_cdef_filter_fb( |
252 | 367k | NULL, CONVERT_TO_SHORTPTR(fb_info->dst + offset), fb_info->dst_stride, |
253 | 367k | &fb_info->src[CDEF_VBORDER * CDEF_BSTRIDE + CDEF_HBORDER], |
254 | 367k | fb_info->xdec, fb_info->ydec, fb_info->dir, NULL, fb_info->var, plane, |
255 | 367k | fb_info->dlist, fb_info->cdef_count, fb_info->level, |
256 | 367k | fb_info->sec_strength, fb_info->damping, fb_info->coeff_shift); |
257 | 954k | } else { |
258 | 954k | av1_cdef_filter_fb( |
259 | 954k | fb_info->dst + offset, NULL, fb_info->dst_stride, |
260 | 954k | &fb_info->src[CDEF_VBORDER * CDEF_BSTRIDE + CDEF_HBORDER], |
261 | 954k | fb_info->xdec, fb_info->ydec, fb_info->dir, NULL, fb_info->var, plane, |
262 | 954k | fb_info->dlist, fb_info->cdef_count, fb_info->level, |
263 | 954k | fb_info->sec_strength, fb_info->damping, fb_info->coeff_shift); |
264 | 954k | } |
265 | 1.32M | } |
266 | | |
267 | | // Initializes block-level parameters for CDEF. |
268 | | static INLINE void cdef_init_fb_col(const MACROBLOCKD *const xd, |
269 | | CdefBlockInfo *const fb_info, int *level, |
270 | | int *sec_strength, int fbc, int fbr, |
271 | 1.31M | int plane) { |
272 | 1.31M | const PLANE_TYPE plane_type = get_plane_type(plane); |
273 | 1.31M | fb_info->level = level[plane_type]; |
274 | 1.31M | fb_info->sec_strength = sec_strength[plane_type]; |
275 | 1.31M | fb_info->dst = xd->plane[plane].dst.buf; |
276 | 1.31M | fb_info->dst_stride = xd->plane[plane].dst.stride; |
277 | | |
278 | 1.31M | fb_info->xdec = xd->plane[plane].subsampling_x; |
279 | 1.31M | fb_info->ydec = xd->plane[plane].subsampling_y; |
280 | 1.31M | fb_info->mi_wide_l2 = MI_SIZE_LOG2 - xd->plane[plane].subsampling_x; |
281 | 1.31M | fb_info->mi_high_l2 = MI_SIZE_LOG2 - xd->plane[plane].subsampling_y; |
282 | 1.31M | fb_info->roffset = MI_SIZE_64X64 * fbr << fb_info->mi_high_l2; |
283 | 1.31M | fb_info->coffset = MI_SIZE_64X64 * fbc << fb_info->mi_wide_l2; |
284 | 1.31M | } |
285 | | |
286 | | static void cdef_fb_col(const AV1_COMMON *const cm, const MACROBLOCKD *const xd, |
287 | | CdefBlockInfo *const fb_info, uint16_t **const colbuf, |
288 | 619k | int *cdef_left, int fbc, int fbr) { |
289 | 619k | const CommonModeInfoParams *const mi_params = &cm->mi_params; |
290 | 619k | const int mbmi_cdef_strength = |
291 | 619k | mi_params |
292 | 619k | ->mi_grid_base[MI_SIZE_64X64 * fbr * mi_params->mi_stride + |
293 | 619k | MI_SIZE_64X64 * fbc] |
294 | 619k | ->cdef_strength; |
295 | 619k | const int num_planes = av1_num_planes(cm); |
296 | 619k | int is_zero_level[PLANE_TYPES] = { 1, 1 }; |
297 | 619k | int level[PLANE_TYPES] = { 0 }; |
298 | 619k | int sec_strength[PLANE_TYPES] = { 0 }; |
299 | 619k | const CdefInfo *const cdef_info = &cm->cdef_info; |
300 | | |
301 | 619k | if (mi_params->mi_grid_base[MI_SIZE_64X64 * fbr * mi_params->mi_stride + |
302 | 619k | MI_SIZE_64X64 * fbc] == NULL || |
303 | 620k | mbmi_cdef_strength == -1) { |
304 | 0 | av1_zero_array(cdef_left, num_planes); |
305 | 0 | return; |
306 | 0 | } |
307 | | |
308 | | // Compute level and secondary strength for planes |
309 | 619k | level[PLANE_TYPE_Y] = |
310 | 619k | cdef_info->cdef_strengths[mbmi_cdef_strength] / CDEF_SEC_STRENGTHS; |
311 | 619k | sec_strength[PLANE_TYPE_Y] = |
312 | 619k | cdef_info->cdef_strengths[mbmi_cdef_strength] % CDEF_SEC_STRENGTHS; |
313 | 619k | sec_strength[PLANE_TYPE_Y] += sec_strength[PLANE_TYPE_Y] == 3; |
314 | 619k | is_zero_level[PLANE_TYPE_Y] = |
315 | 619k | (level[PLANE_TYPE_Y] == 0) && (sec_strength[PLANE_TYPE_Y] == 0); |
316 | | |
317 | 619k | if (num_planes > 1) { |
318 | 593k | level[PLANE_TYPE_UV] = |
319 | 593k | cdef_info->cdef_uv_strengths[mbmi_cdef_strength] / CDEF_SEC_STRENGTHS; |
320 | 593k | sec_strength[PLANE_TYPE_UV] = |
321 | 593k | cdef_info->cdef_uv_strengths[mbmi_cdef_strength] % CDEF_SEC_STRENGTHS; |
322 | 593k | sec_strength[PLANE_TYPE_UV] += sec_strength[PLANE_TYPE_UV] == 3; |
323 | 593k | is_zero_level[PLANE_TYPE_UV] = |
324 | 593k | (level[PLANE_TYPE_UV] == 0) && (sec_strength[PLANE_TYPE_UV] == 0); |
325 | 593k | } |
326 | | |
327 | 619k | if (is_zero_level[PLANE_TYPE_Y] && is_zero_level[PLANE_TYPE_UV]) { |
328 | 10.6k | av1_zero_array(cdef_left, num_planes); |
329 | 10.6k | return; |
330 | 10.6k | } |
331 | | |
332 | 609k | fb_info->cdef_count = av1_cdef_compute_sb_list(mi_params, fbr * MI_SIZE_64X64, |
333 | 609k | fbc * MI_SIZE_64X64, |
334 | 609k | fb_info->dlist, BLOCK_64X64); |
335 | 609k | if (!fb_info->cdef_count) { |
336 | 153k | av1_zero_array(cdef_left, num_planes); |
337 | 153k | return; |
338 | 153k | } |
339 | | |
340 | 1.79M | for (int plane = 0; plane < num_planes; plane++) { |
341 | | // Do not skip cdef filtering for luma plane as filter direction is |
342 | | // computed based on luma. |
343 | 1.33M | if (plane && is_zero_level[get_plane_type(plane)]) { |
344 | 23.2k | cdef_left[plane] = 0; |
345 | 23.2k | continue; |
346 | 23.2k | } |
347 | 1.31M | cdef_init_fb_col(xd, fb_info, level, sec_strength, fbc, fbr, plane); |
348 | 1.31M | cdef_prepare_fb(cm, fb_info, colbuf, cdef_left[plane], fbc, fbr, plane); |
349 | 1.31M | cdef_filter_fb(fb_info, plane, cm->seq_params->use_highbitdepth); |
350 | 1.31M | cdef_left[plane] = 1; |
351 | 1.31M | } |
352 | 455k | } |
353 | | |
354 | | // Initializes row-level parameters for CDEF frame. |
355 | | void av1_cdef_init_fb_row(const AV1_COMMON *const cm, |
356 | | const MACROBLOCKD *const xd, |
357 | | CdefBlockInfo *const fb_info, |
358 | | uint16_t **const linebuf, uint16_t *const src, |
359 | 13.5k | struct AV1CdefSyncData *const cdef_sync, int fbr) { |
360 | 13.5k | (void)cdef_sync; |
361 | 13.5k | const int num_planes = av1_num_planes(cm); |
362 | 13.5k | const int nvfb = (cm->mi_params.mi_rows + MI_SIZE_64X64 - 1) / MI_SIZE_64X64; |
363 | 13.5k | const int luma_stride = |
364 | 13.5k | ALIGN_POWER_OF_TWO(cm->mi_params.mi_cols << MI_SIZE_LOG2, 4); |
365 | 13.5k | const bool ping_pong = fbr & 1; |
366 | | // for the current filter block, it's top left corner mi structure (mi_tl) |
367 | | // is first accessed to check whether the top and left boundaries are |
368 | | // frame boundaries. Then bottom-left and top-right mi structures are |
369 | | // accessed to check whether the bottom and right boundaries |
370 | | // (respectively) are frame boundaries. |
371 | | // |
372 | | // Note that we can't just check the bottom-right mi structure - eg. if |
373 | | // we're at the right-hand edge of the frame but not the bottom, then |
374 | | // the bottom-right mi is NULL but the bottom-left is not. |
375 | 13.5k | fb_info->frame_boundary[TOP] = (MI_SIZE_64X64 * fbr == 0) ? 1 : 0; |
376 | 13.5k | if (fbr != nvfb - 1) |
377 | 8.36k | fb_info->frame_boundary[BOTTOM] = |
378 | 8.36k | (MI_SIZE_64X64 * (fbr + 1) == cm->mi_params.mi_rows) ? 1 : 0; |
379 | 5.18k | else |
380 | 5.18k | fb_info->frame_boundary[BOTTOM] = 1; |
381 | | |
382 | 13.5k | fb_info->src = src; |
383 | 13.5k | fb_info->damping = cm->cdef_info.cdef_damping; |
384 | 13.5k | fb_info->coeff_shift = AOMMAX(cm->seq_params->bit_depth - 8, 0); |
385 | 13.5k | av1_zero(fb_info->dir); |
386 | 13.5k | av1_zero(fb_info->var); |
387 | | |
388 | 53.2k | for (int plane = 0; plane < num_planes; plane++) { |
389 | 39.7k | const int mi_high_l2 = MI_SIZE_LOG2 - xd->plane[plane].subsampling_y; |
390 | 39.7k | const int offset = MI_SIZE_64X64 * (fbr + 1) << mi_high_l2; |
391 | 39.7k | const int stride = luma_stride >> xd->plane[plane].subsampling_x; |
392 | | // here ping-pong buffers are maintained for top linebuf |
393 | | // to avoid linebuf over-write by consecutive row. |
394 | 39.7k | uint16_t *const top_linebuf = |
395 | 39.7k | &linebuf[plane][ping_pong * CDEF_VBORDER * stride]; |
396 | 39.7k | fb_info->bot_linebuf[plane] = &linebuf[plane][(CDEF_VBORDER << 1) * stride]; |
397 | | |
398 | 39.7k | if (fbr != nvfb - 1) // top line buffer copy |
399 | 24.4k | av1_cdef_copy_sb8_16(cm, top_linebuf, stride, xd->plane[plane].dst.buf, |
400 | 24.4k | offset - CDEF_VBORDER, 0, |
401 | 24.4k | xd->plane[plane].dst.stride, CDEF_VBORDER, stride); |
402 | 39.7k | fb_info->top_linebuf[plane] = |
403 | 39.7k | &linebuf[plane][(!ping_pong) * CDEF_VBORDER * stride]; |
404 | | |
405 | 39.7k | if (fbr != nvfb - 1) // bottom line buffer copy |
406 | 24.4k | av1_cdef_copy_sb8_16(cm, fb_info->bot_linebuf[plane], stride, |
407 | 24.4k | xd->plane[plane].dst.buf, offset, 0, |
408 | 24.4k | xd->plane[plane].dst.stride, CDEF_VBORDER, stride); |
409 | 39.7k | } |
410 | 13.5k | } |
411 | | |
412 | | void av1_cdef_fb_row(const AV1_COMMON *const cm, MACROBLOCKD *xd, |
413 | | uint16_t **const linebuf, uint16_t **const colbuf, |
414 | | uint16_t *const src, int fbr, |
415 | | cdef_init_fb_row_t cdef_init_fb_row_fn, |
416 | 70.6k | struct AV1CdefSyncData *const cdef_sync) { |
417 | 70.6k | CdefBlockInfo fb_info; |
418 | 70.6k | int cdef_left[MAX_MB_PLANE] = { 1, 1, 1 }; |
419 | 70.6k | const int nhfb = (cm->mi_params.mi_cols + MI_SIZE_64X64 - 1) / MI_SIZE_64X64; |
420 | | |
421 | 70.6k | cdef_init_fb_row_fn(cm, xd, &fb_info, linebuf, src, cdef_sync, fbr); |
422 | 690k | for (int fbc = 0; fbc < nhfb; fbc++) { |
423 | 619k | fb_info.frame_boundary[LEFT] = (MI_SIZE_64X64 * fbc == 0) ? 1 : 0; |
424 | 619k | if (fbc != nhfb - 1) |
425 | 550k | fb_info.frame_boundary[RIGHT] = |
426 | 550k | (MI_SIZE_64X64 * (fbc + 1) == cm->mi_params.mi_cols) ? 1 : 0; |
427 | 69.3k | else |
428 | 69.3k | fb_info.frame_boundary[RIGHT] = 1; |
429 | 619k | cdef_fb_col(cm, xd, &fb_info, colbuf, &cdef_left[0], fbc, fbr); |
430 | 619k | } |
431 | 70.6k | } |
432 | | |
433 | | // Perform CDEF on input frame. |
434 | | // Inputs: |
435 | | // frame: Pointer to input frame buffer. |
436 | | // cm: Pointer to common structure. |
437 | | // xd: Pointer to common current coding block structure. |
438 | | // Returns: |
439 | | // Nothing will be returned. |
440 | | void av1_cdef_frame(YV12_BUFFER_CONFIG *frame, AV1_COMMON *const cm, |
441 | 5.18k | MACROBLOCKD *xd, cdef_init_fb_row_t cdef_init_fb_row_fn) { |
442 | 5.18k | const int num_planes = av1_num_planes(cm); |
443 | 5.18k | const int nvfb = (cm->mi_params.mi_rows + MI_SIZE_64X64 - 1) / MI_SIZE_64X64; |
444 | | |
445 | 5.18k | av1_setup_dst_planes(xd->plane, cm->seq_params->sb_size, frame, 0, 0, 0, |
446 | 5.18k | num_planes); |
447 | | |
448 | 18.7k | for (int fbr = 0; fbr < nvfb; fbr++) |
449 | 13.5k | av1_cdef_fb_row(cm, xd, cm->cdef_info.linebuf, cm->cdef_info.colbuf, |
450 | 13.5k | cm->cdef_info.srcbuf, fbr, cdef_init_fb_row_fn, NULL); |
451 | 5.18k | } |