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