FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/vvc/filter.c
Date: 2025-06-01 09:29:47
Exec Total Coverage
Lines: 735 764 96.2%
Functions: 50 51 98.0%
Branches: 598 641 93.3%

Line Branch Exec Source
1 /*
2 * VVC filters
3 *
4 * Copyright (C) 2021 Nuo Mi
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22 #include "libavutil/frame.h"
23 #include "libavutil/imgutils.h"
24
25 #include "ctu.h"
26 #include "data.h"
27 #include "filter.h"
28 #include "refs.h"
29
30 #define LEFT 0
31 #define TOP 1
32 #define RIGHT 2
33 #define BOTTOM 3
34 #define MAX_EDGES 4
35
36 #define DEFAULT_INTRA_TC_OFFSET 2
37
38 #define POS(c_idx, x, y) \
39 &fc->frame->data[c_idx][((y) >> fc->ps.sps->vshift[c_idx]) * fc->frame->linesize[c_idx] + \
40 (((x) >> fc->ps.sps->hshift[c_idx]) << fc->ps.sps->pixel_shift)]
41
42 //Table 43 Derivation of threshold variables beta' and tc' from input Q
43 static const uint16_t tctable[66] = {
44 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
45 0, 0, 3, 4, 4, 4, 4, 5, 5, 5, 5, 7, 7, 8, 9, 10,
46 10, 11, 13, 14, 15, 17, 19, 21, 24, 25, 29, 33, 36, 41, 45, 51,
47 57, 64, 71, 80, 89, 100, 112, 125, 141, 157, 177, 198, 222, 250, 280, 314,
48 352, 395,
49 };
50
51 //Table 43 Derivation of threshold variables beta' and tc' from input Q
52 static const uint8_t betatable[64] = {
53 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
54 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 22, 24,
55 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56,
56 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88,
57 };
58
59 // One vertical and one horizontal virtual boundary in a CTU at most. The CTU will be divided into 4 subblocks.
60 #define MAX_VBBS 4
61
62 4312918 static int get_virtual_boundary(const VVCFrameContext *fc, const int ctu_pos, const int vertical)
63 {
64 4312918 const VVCSPS *sps = fc->ps.sps;
65 4312918 const VVCPH *ph = &fc->ps.ph;
66
2/2
✓ Branch 0 taken 2184727 times.
✓ Branch 1 taken 2128191 times.
4312918 const uint16_t *vbs = vertical ? ph->vb_pos_x : ph->vb_pos_y;
67
2/2
✓ Branch 0 taken 2184727 times.
✓ Branch 1 taken 2128191 times.
4312918 const uint8_t nb_vbs = vertical ? ph->num_ver_vbs : ph->num_hor_vbs;
68 4312918 const int pos = ctu_pos << sps->ctb_log2_size_y;
69
70
2/2
✓ Branch 0 taken 329281 times.
✓ Branch 1 taken 3983637 times.
4312918 if (sps->r->sps_virtual_boundaries_enabled_flag) {
71
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 329281 times.
329281 for (int i = 0; i < nb_vbs; i++) {
72 const int o = vbs[i] - pos;
73 if (o >= 0 && o < sps->ctb_size_y)
74 return vbs[i];
75 }
76 }
77 4312918 return 0;
78 }
79
80 4237510 static int is_virtual_boundary(const VVCFrameContext *fc, const int pos, const int vertical)
81 {
82 4237510 return get_virtual_boundary(fc, pos >> fc->ps.sps->ctb_log2_size_y, vertical) == pos;
83 }
84
85 8607050 static int get_qPc(const VVCFrameContext *fc, const int x0, const int y0, const int chroma)
86 {
87 8607050 const int x = x0 >> MIN_TU_LOG2;
88 8607050 const int y = y0 >> MIN_TU_LOG2;
89 8607050 const int min_tu_width = fc->ps.pps->min_tu_width;
90 8607050 return fc->tab.qp[chroma][x + y * min_tu_width];
91 }
92
93 53802 static void copy_ctb(uint8_t *dst, const uint8_t *src, const int width, const int height,
94 const ptrdiff_t dst_stride, const ptrdiff_t src_stride)
95 {
96
2/2
✓ Branch 0 taken 5182644 times.
✓ Branch 1 taken 53802 times.
5236446 for (int y = 0; y < height; y++) {
97 5182644 memcpy(dst, src, width);
98
99 5182644 dst += dst_stride;
100 5182644 src += src_stride;
101 }
102 53802 }
103
104 28604 static void copy_pixel(uint8_t *dst, const uint8_t *src, const int pixel_shift)
105 {
106
2/2
✓ Branch 0 taken 26388 times.
✓ Branch 1 taken 2216 times.
28604 if (pixel_shift)
107 26388 *(uint16_t *)dst = *(uint16_t *)src;
108 else
109 2216 *dst = *src;
110 28604 }
111
112 292723 static void copy_vert(uint8_t *dst, const uint8_t *src, const int pixel_shift, const int height,
113 const ptrdiff_t dst_stride, const ptrdiff_t src_stride)
114 {
115 int i;
116
2/2
✓ Branch 0 taken 8743 times.
✓ Branch 1 taken 283980 times.
292723 if (pixel_shift == 0) {
117
2/2
✓ Branch 0 taken 370688 times.
✓ Branch 1 taken 8743 times.
379431 for (i = 0; i < height; i++) {
118 370688 *dst = *src;
119 370688 dst += dst_stride;
120 370688 src += src_stride;
121 }
122 } else {
123
2/2
✓ Branch 0 taken 26430248 times.
✓ Branch 1 taken 283980 times.
26714228 for (i = 0; i < height; i++) {
124 26430248 *(uint16_t *)dst = *(uint16_t *)src;
125 26430248 dst += dst_stride;
126 26430248 src += src_stride;
127 }
128 }
129 292723 }
130
131 275646 static void copy_ctb_to_hv(VVCFrameContext *fc, const uint8_t *src,
132 const ptrdiff_t src_stride, const int x, const int y, const int width, const int height,
133 const int c_idx, const int rx, const int ry, const int top)
134 {
135 275646 const int ps = fc->ps.sps->pixel_shift;
136 275646 const int w = fc->ps.pps->width >> fc->ps.sps->hshift[c_idx];
137 275646 const int h = fc->ps.pps->height >> fc->ps.sps->vshift[c_idx];
138
139
2/2
✓ Branch 0 taken 137823 times.
✓ Branch 1 taken 137823 times.
275646 if (top) {
140 /* top */
141 137823 memcpy(fc->tab.sao_pixel_buffer_h[c_idx] + (((2 * ry) * w + x) << ps),
142 137823 src, width << ps);
143 } else {
144 /* bottom */
145 137823 memcpy(fc->tab.sao_pixel_buffer_h[c_idx] + (((2 * ry + 1) * w + x) << ps),
146 137823 src + src_stride * (height - 1), width << ps);
147
148 /* copy vertical edges */
149 137823 copy_vert(fc->tab.sao_pixel_buffer_v[c_idx] + (((2 * rx) * h + y) << ps), src, ps, height, 1 << ps, src_stride);
150 137823 copy_vert(fc->tab.sao_pixel_buffer_v[c_idx] + (((2 * rx + 1) * h + y) << ps), src + ((width - 1) << ps), ps, height, 1 << ps, src_stride);
151 }
152 275646 }
153
154 92586 static void sao_copy_ctb_to_hv(VVCLocalContext *lc, const int rx, const int ry, const int top)
155 {
156 92586 VVCFrameContext *fc = lc->fc;
157 92586 const int ctb_size_y = fc->ps.sps->ctb_size_y;
158 92586 const int x0 = rx << fc->ps.sps->ctb_log2_size_y;
159 92586 const int y0 = ry << fc->ps.sps->ctb_log2_size_y;
160
161
4/4
✓ Branch 0 taken 366120 times.
✓ Branch 1 taken 2112 times.
✓ Branch 2 taken 275646 times.
✓ Branch 3 taken 92586 times.
368232 for (int c_idx = 0; c_idx < (fc->ps.sps->r->sps_chroma_format_idc ? 3 : 1); c_idx++) {
162 275646 const int x = x0 >> fc->ps.sps->hshift[c_idx];
163 275646 const int y = y0 >> fc->ps.sps->vshift[c_idx];
164 275646 const ptrdiff_t src_stride = fc->frame->linesize[c_idx];
165 275646 const int ctb_size_h = ctb_size_y >> fc->ps.sps->hshift[c_idx];
166 275646 const int ctb_size_v = ctb_size_y >> fc->ps.sps->vshift[c_idx];
167 275646 const int width = FFMIN(ctb_size_h, (fc->ps.pps->width >> fc->ps.sps->hshift[c_idx]) - x);
168 275646 const int height = FFMIN(ctb_size_v, (fc->ps.pps->height >> fc->ps.sps->vshift[c_idx]) - y);
169 275646 const uint8_t *src = POS(c_idx, x0, y0);
170 275646 copy_ctb_to_hv(fc, src, src_stride, x, y, width, height, c_idx, rx, ry, top);
171 }
172 92586 }
173
174 46293 void ff_vvc_sao_copy_ctb_to_hv(VVCLocalContext *lc, const int rx, const int ry, const int last_row)
175 {
176
2/2
✓ Branch 0 taken 39006 times.
✓ Branch 1 taken 7287 times.
46293 if (ry)
177 39006 sao_copy_ctb_to_hv(lc, rx, ry - 1, 0);
178
179 46293 sao_copy_ctb_to_hv(lc, rx, ry, 1);
180
181
2/2
✓ Branch 0 taken 7287 times.
✓ Branch 1 taken 39006 times.
46293 if (last_row)
182 7287 sao_copy_ctb_to_hv(lc, rx, ry, 0);
183 46293 }
184
185 284470 static int sao_can_cross_slices(const VVCFrameContext *fc, const int rx, const int ry, const int dx, const int dy)
186 {
187 284470 const uint8_t lfase = fc->ps.pps->r->pps_loop_filter_across_slices_enabled_flag;
188
189
4/4
✓ Branch 0 taken 281350 times.
✓ Branch 1 taken 3120 times.
✓ Branch 2 taken 278618 times.
✓ Branch 3 taken 2732 times.
284470 return lfase || CTB(fc->tab.slice_idx, rx, ry) == CTB(fc->tab.slice_idx, rx + dx, ry + dy);
190 }
191
192 46293 static void sao_get_edges(uint8_t vert_edge[2], uint8_t horiz_edge[2], uint8_t diag_edge[4], int *restore,
193 const VVCLocalContext *lc, const int edges[4], const int rx, const int ry)
194 {
195 46293 const VVCFrameContext *fc = lc->fc;
196 46293 const VVCSPS *sps = fc->ps.sps;
197 46293 const H266RawSPS *rsps = sps->r;
198 46293 const VVCPPS *pps = fc->ps.pps;
199 46293 const int subpic_idx = lc->sc->sh.r->curr_subpic_idx;
200 46293 const uint8_t lfase = fc->ps.pps->r->pps_loop_filter_across_slices_enabled_flag;
201
4/4
✓ Branch 0 taken 5081 times.
✓ Branch 1 taken 41212 times.
✓ Branch 2 taken 1662 times.
✓ Branch 3 taken 3419 times.
46293 const uint8_t no_tile_filter = pps->r->num_tiles_in_pic > 1 && !pps->r->pps_loop_filter_across_tiles_enabled_flag;
202
4/4
✓ Branch 0 taken 2103 times.
✓ Branch 1 taken 44190 times.
✓ Branch 2 taken 1137 times.
✓ Branch 3 taken 966 times.
46293 const uint8_t no_subpic_filter = rsps->sps_num_subpics_minus1 && !rsps->sps_loop_filter_across_subpic_enabled_flag[subpic_idx];
203 46293 uint8_t lf_edge[] = { 0, 0, 0, 0 };
204
205
8/8
✓ Branch 0 taken 45156 times.
✓ Branch 1 taken 1137 times.
✓ Branch 2 taken 44604 times.
✓ Branch 3 taken 552 times.
✓ Branch 4 taken 3162 times.
✓ Branch 5 taken 41442 times.
✓ Branch 6 taken 184 times.
✓ Branch 7 taken 2978 times.
46293 *restore = no_subpic_filter || no_tile_filter || !lfase || rsps->sps_virtual_boundaries_enabled_flag;
206
207
2/2
✓ Branch 0 taken 2978 times.
✓ Branch 1 taken 43315 times.
46293 if (!*restore)
208 2978 return;
209
210
2/2
✓ Branch 0 taken 39315 times.
✓ Branch 1 taken 4000 times.
43315 if (!edges[LEFT]) {
211
4/4
✓ Branch 0 taken 1458 times.
✓ Branch 1 taken 37857 times.
✓ Branch 2 taken 612 times.
✓ Branch 3 taken 846 times.
39315 lf_edge[LEFT] = no_tile_filter && pps->ctb_to_col_bd[rx] == rx;
212
4/4
✓ Branch 0 taken 1017 times.
✓ Branch 1 taken 38298 times.
✓ Branch 2 taken 309 times.
✓ Branch 3 taken 708 times.
39315 lf_edge[LEFT] |= no_subpic_filter && rsps->sps_subpic_ctu_top_left_x[subpic_idx] == rx;
213 39315 lf_edge[LEFT] |= is_virtual_boundary(fc, rx << sps->ctb_log2_size_y, 1);
214
4/4
✓ Branch 1 taken 39016 times.
✓ Branch 2 taken 299 times.
✓ Branch 3 taken 322 times.
✓ Branch 4 taken 38694 times.
39315 vert_edge[0] = !sao_can_cross_slices(fc, rx, ry, -1, 0) || lf_edge[LEFT];
215 }
216
2/2
✓ Branch 0 taken 39315 times.
✓ Branch 1 taken 4000 times.
43315 if (!edges[RIGHT]) {
217
4/4
✓ Branch 0 taken 1458 times.
✓ Branch 1 taken 37857 times.
✓ Branch 2 taken 612 times.
✓ Branch 3 taken 846 times.
39315 lf_edge[RIGHT] = no_tile_filter && pps->ctb_to_col_bd[rx] != pps->ctb_to_col_bd[rx + 1];
218
4/4
✓ Branch 0 taken 996 times.
✓ Branch 1 taken 38319 times.
✓ Branch 2 taken 288 times.
✓ Branch 3 taken 708 times.
39315 lf_edge[RIGHT] |= no_subpic_filter && rsps->sps_subpic_ctu_top_left_x[subpic_idx] + rsps->sps_subpic_width_minus1[subpic_idx] == rx;
219 39315 lf_edge[RIGHT] |= is_virtual_boundary(fc, (rx + 1) << sps->ctb_log2_size_y, 1);
220
4/4
✓ Branch 1 taken 39016 times.
✓ Branch 2 taken 299 times.
✓ Branch 3 taken 318 times.
✓ Branch 4 taken 38698 times.
39315 vert_edge[1] = !sao_can_cross_slices(fc, rx, ry, 1, 0) || lf_edge[RIGHT];
221 }
222
2/2
✓ Branch 0 taken 36362 times.
✓ Branch 1 taken 6953 times.
43315 if (!edges[TOP]) {
223
4/4
✓ Branch 0 taken 1356 times.
✓ Branch 1 taken 35006 times.
✓ Branch 2 taken 564 times.
✓ Branch 3 taken 792 times.
36362 lf_edge[TOP] = no_tile_filter && pps->ctb_to_row_bd[ry] == ry;
224
4/4
✓ Branch 0 taken 852 times.
✓ Branch 1 taken 35510 times.
✓ Branch 2 taken 222 times.
✓ Branch 3 taken 630 times.
36362 lf_edge[TOP] |= no_subpic_filter && rsps->sps_subpic_ctu_top_left_y[subpic_idx] == ry;
225 36362 lf_edge[TOP] |= is_virtual_boundary(fc, ry << sps->ctb_log2_size_y, 0);
226
4/4
✓ Branch 1 taken 36009 times.
✓ Branch 2 taken 353 times.
✓ Branch 3 taken 282 times.
✓ Branch 4 taken 35727 times.
36362 horiz_edge[0] = !sao_can_cross_slices(fc, rx, ry, 0, -1) || lf_edge[TOP];
227 }
228
2/2
✓ Branch 0 taken 36362 times.
✓ Branch 1 taken 6953 times.
43315 if (!edges[BOTTOM]) {
229
4/4
✓ Branch 0 taken 1356 times.
✓ Branch 1 taken 35006 times.
✓ Branch 2 taken 564 times.
✓ Branch 3 taken 792 times.
36362 lf_edge[BOTTOM] = no_tile_filter && pps->ctb_to_row_bd[ry] != pps->ctb_to_row_bd[ry + 1];
230
4/4
✓ Branch 0 taken 915 times.
✓ Branch 1 taken 35447 times.
✓ Branch 2 taken 285 times.
✓ Branch 3 taken 630 times.
36362 lf_edge[BOTTOM] |= no_subpic_filter && rsps->sps_subpic_ctu_top_left_y[subpic_idx] + rsps->sps_subpic_height_minus1[subpic_idx] == ry;
231 36362 lf_edge[BOTTOM] |= is_virtual_boundary(fc, (ry + 1) << sps->ctb_log2_size_y, 0);
232
4/4
✓ Branch 1 taken 36009 times.
✓ Branch 2 taken 353 times.
✓ Branch 3 taken 294 times.
✓ Branch 4 taken 35715 times.
36362 horiz_edge[1] = !sao_can_cross_slices(fc, rx, ry, 0, 1) || lf_edge[BOTTOM];
233 }
234
235
4/4
✓ Branch 0 taken 39315 times.
✓ Branch 1 taken 4000 times.
✓ Branch 2 taken 33279 times.
✓ Branch 3 taken 6036 times.
43315 if (!edges[LEFT] && !edges[TOP])
236
6/6
✓ Branch 1 taken 32922 times.
✓ Branch 2 taken 357 times.
✓ Branch 3 taken 32670 times.
✓ Branch 4 taken 252 times.
✓ Branch 5 taken 144 times.
✓ Branch 6 taken 32526 times.
33279 diag_edge[0] = !sao_can_cross_slices(fc, rx, ry, -1, -1) || lf_edge[LEFT] || lf_edge[TOP];
237
238
4/4
✓ Branch 0 taken 36362 times.
✓ Branch 1 taken 6953 times.
✓ Branch 2 taken 33279 times.
✓ Branch 3 taken 3083 times.
43315 if (!edges[TOP] && !edges[RIGHT])
239
6/6
✓ Branch 1 taken 32922 times.
✓ Branch 2 taken 357 times.
✓ Branch 3 taken 32670 times.
✓ Branch 4 taken 252 times.
✓ Branch 5 taken 144 times.
✓ Branch 6 taken 32526 times.
33279 diag_edge[1] = !sao_can_cross_slices(fc, rx, ry, 1, -1) || lf_edge[RIGHT] || lf_edge[TOP];
240
241
4/4
✓ Branch 0 taken 39315 times.
✓ Branch 1 taken 4000 times.
✓ Branch 2 taken 33279 times.
✓ Branch 3 taken 6036 times.
43315 if (!edges[RIGHT] && !edges[BOTTOM])
242
6/6
✓ Branch 1 taken 32922 times.
✓ Branch 2 taken 357 times.
✓ Branch 3 taken 32670 times.
✓ Branch 4 taken 252 times.
✓ Branch 5 taken 152 times.
✓ Branch 6 taken 32518 times.
33279 diag_edge[2] = !sao_can_cross_slices(fc, rx, ry, 1, 1) || lf_edge[RIGHT] || lf_edge[BOTTOM];
243
244
4/4
✓ Branch 0 taken 39315 times.
✓ Branch 1 taken 4000 times.
✓ Branch 2 taken 33279 times.
✓ Branch 3 taken 6036 times.
43315 if (!edges[LEFT] && !edges[BOTTOM])
245
6/6
✓ Branch 1 taken 32922 times.
✓ Branch 2 taken 357 times.
✓ Branch 3 taken 32666 times.
✓ Branch 4 taken 256 times.
✓ Branch 5 taken 152 times.
✓ Branch 6 taken 32514 times.
33279 diag_edge[3] = !sao_can_cross_slices(fc, rx, ry, -1, 1) || lf_edge[LEFT] || lf_edge[BOTTOM];
246 }
247
248 15574 static void sao_copy_hor(uint8_t *dst, const ptrdiff_t dst_stride,
249 const uint8_t *src, const ptrdiff_t src_stride, const int width, const int edges[4], const int ps)
250 {
251 15574 const int left = 1 - edges[LEFT];
252 15574 const int right = 1 - edges[RIGHT];
253 15574 int pos = 0;
254
255 15574 src -= left << ps;
256 15574 dst -= left << ps;
257
258
2/2
✓ Branch 0 taken 14271 times.
✓ Branch 1 taken 1303 times.
15574 if (left) {
259 14271 copy_pixel(dst, src, ps);
260 14271 pos += (1 << ps);
261 }
262 15574 memcpy(dst + pos, src + pos, width << ps);
263
2/2
✓ Branch 0 taken 14333 times.
✓ Branch 1 taken 1241 times.
15574 if (right) {
264 14333 pos += width << ps;
265 14333 copy_pixel(dst + pos, src + pos, ps);
266 }
267 15574 }
268
269 9407 static void sao_extends_edges(uint8_t *dst, const ptrdiff_t dst_stride,
270 const uint8_t *src, const ptrdiff_t src_stride, const int width, const int height,
271 const VVCFrameContext *fc, const int x0, const int y0, const int rx, const int ry, const int edges[4], const int c_idx)
272 {
273 9407 const uint8_t *sao_h = fc->tab.sao_pixel_buffer_h[c_idx];
274 9407 const uint8_t *sao_v = fc->tab.sao_pixel_buffer_v[c_idx];
275 9407 const int x = x0 >> fc->ps.sps->hshift[c_idx];
276 9407 const int y = y0 >> fc->ps.sps->vshift[c_idx];
277 9407 const int w = fc->ps.pps->width >> fc->ps.sps->hshift[c_idx];
278 9407 const int h = fc->ps.pps->height >> fc->ps.sps->vshift[c_idx];
279 9407 const int ps = fc->ps.sps->pixel_shift;
280
281
2/2
✓ Branch 0 taken 7796 times.
✓ Branch 1 taken 1611 times.
9407 if (!edges[TOP])
282 7796 sao_copy_hor(dst - dst_stride, dst_stride, sao_h + (((2 * ry - 1) * w + x) << ps), src_stride, width, edges, ps);
283
284
2/2
✓ Branch 0 taken 7778 times.
✓ Branch 1 taken 1629 times.
9407 if (!edges[BOTTOM])
285 7778 sao_copy_hor(dst + height * dst_stride, dst_stride, sao_h + (((2 * ry + 2) * w + x) << ps), src_stride, width, edges, ps);
286
287
2/2
✓ Branch 0 taken 8533 times.
✓ Branch 1 taken 874 times.
9407 if (!edges[LEFT])
288 8533 copy_vert(dst - (1 << ps), sao_v + (((2 * rx - 1) * h + y) << ps), ps, height, dst_stride, 1 << ps);
289
290
2/2
✓ Branch 0 taken 8544 times.
✓ Branch 1 taken 863 times.
9407 if (!edges[RIGHT])
291 8544 copy_vert(dst + (width << ps), sao_v + (((2 * rx + 2) * h + y) << ps), ps, height, dst_stride, 1 << ps);
292
293 9407 copy_ctb(dst, src, width << ps, height, dst_stride, src_stride);
294 9407 }
295
296 static void sao_restore_vb(uint8_t *dst, ptrdiff_t dst_stride, const uint8_t *src, ptrdiff_t src_stride,
297 const int width, const int height, const int vb_pos, const int ps, const int vertical)
298 {
299 int w = 2;
300 int h = (vertical ? height : width);
301 int dx = vb_pos - 1;
302 int dy = 0;
303
304 if (!vertical) {
305 FFSWAP(int, w, h);
306 FFSWAP(int, dx, dy);
307 }
308 dst += dy * dst_stride +(dx << ps);
309 src += dy * src_stride +(dx << ps);
310
311 av_image_copy_plane(dst, dst_stride, src, src_stride, w << ps, h);
312 }
313
314 46293 void ff_vvc_sao_filter(VVCLocalContext *lc, int x0, int y0)
315 {
316 46293 VVCFrameContext *fc = lc->fc;
317 46293 const VVCSPS *sps = fc->ps.sps;
318 46293 const int rx = x0 >> sps->ctb_log2_size_y;
319 46293 const int ry = y0 >> sps->ctb_log2_size_y;
320 46293 const int edges[4] = { !rx, !ry, rx == fc->ps.pps->ctb_width - 1, ry == fc->ps.pps->ctb_height - 1 };
321 46293 const SAOParams *sao = &CTB(fc->tab.sao, rx, ry);
322 // flags indicating unfilterable edges
323 46293 uint8_t vert_edge[] = { 0, 0 };
324 46293 uint8_t horiz_edge[] = { 0, 0 };
325 46293 uint8_t diag_edge[] = { 0, 0, 0, 0 };
326 46293 int restore, vb_x = 0, vb_y = 0;;
327
328
2/2
✓ Branch 0 taken 1029 times.
✓ Branch 1 taken 45264 times.
46293 if (sps->r->sps_virtual_boundaries_enabled_flag) {
329 1029 vb_x = get_virtual_boundary(fc, rx, 1);
330 1029 vb_y = get_virtual_boundary(fc, ry, 0);
331 }
332
333 46293 sao_get_edges(vert_edge, horiz_edge, diag_edge, &restore, lc, edges, rx, ry);
334
335
4/4
✓ Branch 0 taken 183060 times.
✓ Branch 1 taken 1056 times.
✓ Branch 2 taken 137823 times.
✓ Branch 3 taken 46293 times.
184116 for (int c_idx = 0; c_idx < (sps->r->sps_chroma_format_idc ? 3 : 1); c_idx++) {
336 static const uint8_t sao_tab[16] = { 0, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8 };
337 137823 const ptrdiff_t src_stride = fc->frame->linesize[c_idx];
338 137823 uint8_t *src = POS(c_idx, x0, y0);
339 137823 const int hs = sps->hshift[c_idx];
340 137823 const int vs = sps->vshift[c_idx];
341 137823 const int ps = sps->pixel_shift;
342 137823 const int width = FFMIN(sps->ctb_size_y, fc->ps.pps->width - x0) >> hs;
343 137823 const int height = FFMIN(sps->ctb_size_y, fc->ps.pps->height - y0) >> vs;
344 137823 const int tab = sao_tab[(FFALIGN(width, 8) >> 3) - 1];
345 137823 const int sao_eo_class = sao->eo_class[c_idx];
346
347
3/3
✓ Branch 0 taken 5154 times.
✓ Branch 1 taken 9407 times.
✓ Branch 2 taken 123262 times.
137823 switch (sao->type_idx[c_idx]) {
348 5154 case SAO_BAND:
349 5154 fc->vvcdsp.sao.band_filter[tab](src, src, src_stride, src_stride,
350 5154 sao->offset_val[c_idx], sao->band_position[c_idx], width, height);
351 5154 break;
352 9407 case SAO_EDGE:
353 {
354 9407 const ptrdiff_t dst_stride = 2 * MAX_PB_SIZE + AV_INPUT_BUFFER_PADDING_SIZE;
355 9407 uint8_t *dst = lc->sao_buffer + dst_stride + AV_INPUT_BUFFER_PADDING_SIZE;
356
357 9407 sao_extends_edges(dst, dst_stride, src, src_stride, width, height, fc, x0, y0, rx, ry, edges, c_idx);
358
359 9407 fc->vvcdsp.sao.edge_filter[tab](src, dst, src_stride, sao->offset_val[c_idx],
360 9407 sao->eo_class[c_idx], width, height);
361 9407 fc->vvcdsp.sao.edge_restore[restore](src, dst, src_stride, dst_stride,
362 sao, edges, width, height, c_idx, vert_edge, horiz_edge, diag_edge);
363
364
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9407 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9407 if (vb_x > x0 && sao_eo_class != SAO_EO_VERT)
365 sao_restore_vb(src, src_stride, dst, dst_stride, width, height, (vb_x - x0) >> hs, ps, 1);
366
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9407 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9407 if (vb_y > y0 && sao_eo_class != SAO_EO_HORIZ)
367 sao_restore_vb(src, src_stride, dst, dst_stride, width, height, (vb_y - y0) >> vs, ps, 0);
368
369 9407 break;
370 }
371 }
372 }
373 46293 }
374
375 #define TAB_BS(t, x, y) (t)[((y) >> MIN_TU_LOG2) * (fc->ps.pps->min_tu_width) + ((x) >> MIN_TU_LOG2)]
376 #define TAB_MAX_LEN(t, x, y) (t)[((y) >> MIN_TU_LOG2) * (fc->ps.pps->min_tu_width) + ((x) >> MIN_TU_LOG2)]
377
378 //8 samples a time
379 #define DEBLOCK_STEP 8
380 #define LUMA_GRID 4
381 #define CHROMA_GRID 8
382
383 9612681 static int boundary_strength(const VVCLocalContext *lc, const MvField *curr, const MvField *neigh,
384 const RefPicList *neigh_rpl)
385 {
386 9612681 RefPicList *rpl = lc->sc->rpl;
387
388
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9612681 times.
9612681 if (curr->pred_flag == PF_PLT)
389 return 0;
390
391
2/2
✓ Branch 0 taken 19857 times.
✓ Branch 1 taken 9592824 times.
9612681 if (curr->pred_flag == PF_IBC)
392
4/4
✓ Branch 0 taken 11262 times.
✓ Branch 1 taken 8595 times.
✓ Branch 2 taken 1775 times.
✓ Branch 3 taken 9487 times.
19857 return FFABS(neigh->mv[0].x - curr->mv[0].x) >= 8 || FFABS(neigh->mv[0].y - curr->mv[0].y) >= 8;
393
394
4/4
✓ Branch 0 taken 4589817 times.
✓ Branch 1 taken 5003007 times.
✓ Branch 2 taken 4275961 times.
✓ Branch 3 taken 313856 times.
9592824 if (curr->pred_flag == PF_BI && neigh->pred_flag == PF_BI) {
395 // same L0 and L1
396
2/2
✓ Branch 0 taken 4198947 times.
✓ Branch 1 taken 77014 times.
4275961 if (rpl[L0].refs[curr->ref_idx[L0]].poc == neigh_rpl[L0].refs[neigh->ref_idx[L0]].poc &&
397
2/2
✓ Branch 0 taken 460391 times.
✓ Branch 1 taken 3738556 times.
4198947 rpl[L0].refs[curr->ref_idx[L0]].poc == rpl[L1].refs[curr->ref_idx[L1]].poc &&
398
2/2
✓ Branch 0 taken 456910 times.
✓ Branch 1 taken 3481 times.
460391 neigh_rpl[L0].refs[neigh->ref_idx[L0]].poc == neigh_rpl[L1].refs[neigh->ref_idx[L1]].poc) {
399
4/4
✓ Branch 0 taken 410440 times.
✓ Branch 1 taken 46470 times.
✓ Branch 2 taken 385271 times.
✓ Branch 3 taken 25169 times.
456910 if ((FFABS(neigh->mv[0].x - curr->mv[0].x) >= 8 || FFABS(neigh->mv[0].y - curr->mv[0].y) >= 8 ||
400
4/4
✓ Branch 0 taken 381496 times.
✓ Branch 1 taken 3775 times.
✓ Branch 2 taken 3203 times.
✓ Branch 3 taken 378293 times.
385271 FFABS(neigh->mv[1].x - curr->mv[1].x) >= 8 || FFABS(neigh->mv[1].y - curr->mv[1].y) >= 8) &&
401
4/4
✓ Branch 0 taken 19050 times.
✓ Branch 1 taken 59567 times.
✓ Branch 2 taken 4673 times.
✓ Branch 3 taken 14377 times.
78617 (FFABS(neigh->mv[1].x - curr->mv[0].x) >= 8 || FFABS(neigh->mv[1].y - curr->mv[0].y) >= 8 ||
402
4/4
✓ Branch 0 taken 2405 times.
✓ Branch 1 taken 2268 times.
✓ Branch 2 taken 1898 times.
✓ Branch 3 taken 507 times.
4673 FFABS(neigh->mv[0].x - curr->mv[1].x) >= 8 || FFABS(neigh->mv[0].y - curr->mv[1].y) >= 8))
403 78110 return 1;
404 else
405 378800 return 0;
406
2/2
✓ Branch 0 taken 3742037 times.
✓ Branch 1 taken 77014 times.
3819051 } else if (neigh_rpl[L0].refs[neigh->ref_idx[L0]].poc == rpl[L0].refs[curr->ref_idx[L0]].poc &&
407
2/2
✓ Branch 0 taken 3723042 times.
✓ Branch 1 taken 18995 times.
3742037 neigh_rpl[L1].refs[neigh->ref_idx[L1]].poc == rpl[L1].refs[curr->ref_idx[L1]].poc) {
408
4/4
✓ Branch 0 taken 3199293 times.
✓ Branch 1 taken 523749 times.
✓ Branch 2 taken 3046191 times.
✓ Branch 3 taken 153102 times.
3723042 if (FFABS(neigh->mv[0].x - curr->mv[0].x) >= 8 || FFABS(neigh->mv[0].y - curr->mv[0].y) >= 8 ||
409
4/4
✓ Branch 0 taken 3013589 times.
✓ Branch 1 taken 32602 times.
✓ Branch 2 taken 20993 times.
✓ Branch 3 taken 2992596 times.
3046191 FFABS(neigh->mv[1].x - curr->mv[1].x) >= 8 || FFABS(neigh->mv[1].y - curr->mv[1].y) >= 8)
410 730446 return 1;
411 else
412 2992596 return 0;
413
2/2
✓ Branch 0 taken 27250 times.
✓ Branch 1 taken 68759 times.
96009 } else if (neigh_rpl[L1].refs[neigh->ref_idx[L1]].poc == rpl[L0].refs[curr->ref_idx[L0]].poc &&
414
2/2
✓ Branch 0 taken 8629 times.
✓ Branch 1 taken 18621 times.
27250 neigh_rpl[L0].refs[neigh->ref_idx[L0]].poc == rpl[L1].refs[curr->ref_idx[L1]].poc) {
415
4/4
✓ Branch 0 taken 2934 times.
✓ Branch 1 taken 5695 times.
✓ Branch 2 taken 1135 times.
✓ Branch 3 taken 1799 times.
8629 if (FFABS(neigh->mv[1].x - curr->mv[0].x) >= 8 || FFABS(neigh->mv[1].y - curr->mv[0].y) >= 8 ||
416
4/4
✓ Branch 0 taken 824 times.
✓ Branch 1 taken 311 times.
✓ Branch 2 taken 180 times.
✓ Branch 3 taken 644 times.
1135 FFABS(neigh->mv[0].x - curr->mv[1].x) >= 8 || FFABS(neigh->mv[0].y - curr->mv[1].y) >= 8)
417 7985 return 1;
418 else
419 644 return 0;
420 } else {
421 87380 return 1;
422 }
423
4/4
✓ Branch 0 taken 5003007 times.
✓ Branch 1 taken 313856 times.
✓ Branch 2 taken 4692078 times.
✓ Branch 3 taken 310929 times.
5316863 } else if ((curr->pred_flag != PF_BI) && (neigh->pred_flag != PF_BI)){ // 1 MV
424 Mv A, B;
425 int ref_A, ref_B;
426
427
2/2
✓ Branch 0 taken 3827667 times.
✓ Branch 1 taken 864411 times.
4692078 if (curr->pred_flag & 1) {
428 3827667 A = curr->mv[0];
429 3827667 ref_A = rpl[L0].refs[curr->ref_idx[L0]].poc;
430 } else {
431 864411 A = curr->mv[1];
432 864411 ref_A = rpl[L1].refs[curr->ref_idx[L1]].poc;
433 }
434
435
2/2
✓ Branch 0 taken 3825385 times.
✓ Branch 1 taken 866693 times.
4692078 if (neigh->pred_flag & 1) {
436 3825385 B = neigh->mv[0];
437 3825385 ref_B = neigh_rpl[L0].refs[neigh->ref_idx[L0]].poc;
438 } else {
439 866693 B = neigh->mv[1];
440 866693 ref_B = neigh_rpl[L1].refs[neigh->ref_idx[L1]].poc;
441 }
442
443
2/2
✓ Branch 0 taken 4568497 times.
✓ Branch 1 taken 123581 times.
4692078 if (ref_A == ref_B) {
444
4/4
✓ Branch 0 taken 4212248 times.
✓ Branch 1 taken 356249 times.
✓ Branch 2 taken 154553 times.
✓ Branch 3 taken 4057695 times.
4568497 if (FFABS(A.x - B.x) >= 8 || FFABS(A.y - B.y) >= 8)
445 510802 return 1;
446 else
447 4057695 return 0;
448 } else
449 123581 return 1;
450 }
451
452 624785 return 1;
453 }
454
455 //part of 8.8.3.3 Derivation process of transform block boundary
456 10601762 static void derive_max_filter_length_luma(const VVCFrameContext *fc, const int qx, const int qy,
457 const int size_q, const int has_subblock, const int vertical, uint8_t *max_len_p, uint8_t *max_len_q)
458 {
459
2/2
✓ Branch 0 taken 5088463 times.
✓ Branch 1 taken 5513299 times.
10601762 const int px = vertical ? qx - 1 : qx;
460
2/2
✓ Branch 0 taken 5513299 times.
✓ Branch 1 taken 5088463 times.
10601762 const int py = !vertical ? qy - 1 : qy;
461
2/2
✓ Branch 0 taken 5088463 times.
✓ Branch 1 taken 5513299 times.
10601762 const uint8_t *tb_size = vertical ? fc->tab.tb_width[LUMA] : fc->tab.tb_height[LUMA];
462 10601762 const int size_p = tb_size[(py >> MIN_TU_LOG2) * fc->ps.pps->min_tu_width + (px >> MIN_TU_LOG2)];
463 10601762 const int min_cb_log2 = fc->ps.sps->min_cb_log2_size_y;
464 10601762 const int off_p = (py >> min_cb_log2) * fc->ps.pps->min_cb_width + (px >> min_cb_log2);
465
466
4/4
✓ Branch 0 taken 8831275 times.
✓ Branch 1 taken 1770487 times.
✓ Branch 2 taken 780918 times.
✓ Branch 3 taken 8050357 times.
10601762 if (size_p <= 4 || size_q <= 4) {
467 2551405 *max_len_p = *max_len_q = 1;
468 } else {
469 8050357 *max_len_p = *max_len_q = 3;
470
2/2
✓ Branch 0 taken 5088023 times.
✓ Branch 1 taken 2962334 times.
8050357 if (size_p >= 32)
471 5088023 *max_len_p = 7;
472
2/2
✓ Branch 0 taken 4944298 times.
✓ Branch 1 taken 3106059 times.
8050357 if (size_q >= 32)
473 4944298 *max_len_q = 7;
474 }
475
2/2
✓ Branch 0 taken 1093634 times.
✓ Branch 1 taken 9508128 times.
10601762 if (has_subblock)
476 1093634 *max_len_q = FFMIN(5, *max_len_q);
477
4/4
✓ Branch 0 taken 9639328 times.
✓ Branch 1 taken 962434 times.
✓ Branch 2 taken 256067 times.
✓ Branch 3 taken 9383261 times.
10601762 if (fc->tab.msf[off_p] || fc->tab.iaf[off_p])
478 1218501 *max_len_p = FFMIN(5, *max_len_p);
479 10601762 }
480
481 128608 static void vvc_deblock_subblock_bs(const VVCLocalContext *lc,
482 const int cb, int x0, int y0, int width, int height, const int vertical)
483 {
484 128608 const VVCFrameContext *fc = lc->fc;
485 128608 const MvField *tab_mvf = fc->tab.mvf;
486 128608 const RefPicList *rpl = lc->sc->rpl;
487 128608 int stridea = fc->ps.pps->min_pu_width;
488 128608 int strideb = 1;
489 128608 const int log2_min_pu_size = MIN_PU_LOG2;
490
491
2/2
✓ Branch 0 taken 64952 times.
✓ Branch 1 taken 63656 times.
128608 if (!vertical) {
492 64952 FFSWAP(int, x0, y0);
493 64952 FFSWAP(int, width, height);
494 64952 FFSWAP(int, stridea, strideb);
495 }
496
497 // bs for TU internal vertical PU boundaries
498
2/2
✓ Branch 0 taken 484527 times.
✓ Branch 1 taken 128608 times.
613135 for (int i = 8 - ((x0 - cb) % 8); i < width; i += 8) {
499 484527 const int is_vb = is_virtual_boundary(fc, x0 + i, vertical);
500 484527 const int xp_pu = (x0 + i - 1) >> log2_min_pu_size;
501 484527 const int xq_pu = (x0 + i) >> log2_min_pu_size;
502
503
2/2
✓ Branch 0 taken 5457742 times.
✓ Branch 1 taken 484527 times.
5942269 for (int j = 0; j < height; j += 4) {
504 5457742 const int y_pu = (y0 + j) >> log2_min_pu_size;
505 5457742 const MvField *mvf_p = &tab_mvf[y_pu * stridea + xp_pu * strideb];
506 5457742 const MvField *mvf_q = &tab_mvf[y_pu * stridea + xq_pu * strideb];
507
1/2
✓ Branch 0 taken 5457742 times.
✗ Branch 1 not taken.
5457742 const int bs = is_vb ? 0 : boundary_strength(lc, mvf_q, mvf_p, rpl);
508 5457742 int x = x0 + i;
509 5457742 int y = y0 + j;
510 5457742 uint8_t max_len_p = 0, max_len_q = 0;
511
512
2/2
✓ Branch 0 taken 2717100 times.
✓ Branch 1 taken 2740642 times.
5457742 if (!vertical)
513 2717100 FFSWAP(int, x, y);
514
515 5457742 TAB_BS(fc->tab.bs[vertical][LUMA], x, y) = bs;
516
517
4/4
✓ Branch 0 taken 5456214 times.
✓ Branch 1 taken 1528 times.
✓ Branch 2 taken 1772 times.
✓ Branch 3 taken 5454442 times.
5457742 if (i == 4 || i == width - 4)
518 3300 max_len_p = max_len_q = 1;
519
4/4
✓ Branch 0 taken 4327132 times.
✓ Branch 1 taken 1127310 times.
✓ Branch 2 taken 907304 times.
✓ Branch 3 taken 3419828 times.
5454442 else if (i == 8 || i == width - 8)
520 2034614 max_len_p = max_len_q = 2;
521 else
522 3419828 max_len_p = max_len_q = 3;
523
524 5457742 TAB_MAX_LEN(fc->tab.max_len_p[vertical], x, y) = max_len_p;
525 5457742 TAB_MAX_LEN(fc->tab.max_len_q[vertical], x, y) = max_len_q;
526 }
527 }
528 128608 }
529
530 40513626 static av_always_inline int deblock_bs(const VVCLocalContext *lc,
531 const int x_p, const int y_p, const int x_q, const int y_q, const CodingUnit *cu, const TransformUnit *tu,
532 const RefPicList *rpl_p, const int c_idx, const int off_to_cb, const uint8_t has_sub_block)
533 {
534 40513626 const VVCFrameContext *fc = lc->fc;
535 40513626 const MvField *tab_mvf = fc->tab.mvf;
536 40513626 const int log2_min_pu_size = MIN_PU_LOG2;
537 40513626 const int log2_min_tu_size = MIN_TU_LOG2;
538 40513626 const int log2_min_cb_size = fc->ps.sps->min_cb_log2_size_y;
539 40513626 const int min_pu_width = fc->ps.pps->min_pu_width;
540 40513626 const int min_tu_width = fc->ps.pps->min_tu_width;
541 40513626 const int min_cb_width = fc->ps.pps->min_cb_width;
542 40513626 const int pu_p = (y_p >> log2_min_pu_size) * min_pu_width + (x_p >> log2_min_pu_size);
543 40513626 const int pu_q = (y_q >> log2_min_pu_size) * min_pu_width + (x_q >> log2_min_pu_size);
544 40513626 const MvField *mvf_p = &tab_mvf[pu_p];
545 40513626 const MvField *mvf_q = &tab_mvf[pu_q];
546 40513626 const uint8_t chroma = !!c_idx;
547 40513626 const int tu_p = (y_p >> log2_min_tu_size) * min_tu_width + (x_p >> log2_min_tu_size);
548 40513626 const int cb_p = (y_p >> log2_min_cb_size) * min_cb_width + (x_p >> log2_min_cb_size);
549
4/4
✓ Branch 0 taken 195 times.
✓ Branch 1 taken 40513431 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 184 times.
40513626 const uint8_t pcmf = fc->tab.pcmf[chroma][cb_p] && cu->bdpcm_flag[chroma];
550
4/4
✓ Branch 0 taken 30368050 times.
✓ Branch 1 taken 10145576 times.
✓ Branch 2 taken 827648 times.
✓ Branch 3 taken 29540402 times.
40513626 const uint8_t intra = fc->tab.cpm[chroma][cb_p] == MODE_INTRA || cu->pred_mode == MODE_INTRA;
551 40513626 const uint8_t same_mode = fc->tab.cpm[chroma][cb_p] == cu->pred_mode;
552
553
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 40513615 times.
40513626 if (pcmf)
554 11 return 0;
555
556
6/6
✓ Branch 0 taken 29540402 times.
✓ Branch 1 taken 10973213 times.
✓ Branch 2 taken 29176818 times.
✓ Branch 3 taken 363584 times.
✓ Branch 4 taken 288598 times.
✓ Branch 5 taken 28888220 times.
40513615 if (intra || mvf_p->ciip_flag || mvf_q->ciip_flag)
557 11625395 return 2;
558
559
2/2
✓ Branch 0 taken 22386876 times.
✓ Branch 1 taken 6501344 times.
28888220 if (chroma) {
560 44141506 return fc->tab.tu_coded_flag[c_idx][tu_p] ||
561
2/2
✓ Branch 0 taken 21542638 times.
✓ Branch 1 taken 211992 times.
21754630 fc->tab.tu_joint_cbcr_residual_flag[tu_p] ||
562
4/4
✓ Branch 0 taken 21754630 times.
✓ Branch 1 taken 632246 times.
✓ Branch 2 taken 21304814 times.
✓ Branch 3 taken 237824 times.
65446320 tu->coded_flag[c_idx] ||
563
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21304814 times.
21304814 tu->joint_cbcr_residual_flag;
564 }
565
566
4/4
✓ Branch 0 taken 5696077 times.
✓ Branch 1 taken 805267 times.
✓ Branch 2 taken 373668 times.
✓ Branch 3 taken 5322409 times.
6501344 if (fc->tab.tu_coded_flag[LUMA][tu_p] || tu->coded_flag[LUMA])
567 1178935 return 1;
568
569
6/6
✓ Branch 0 taken 1349240 times.
✓ Branch 1 taken 3973169 times.
✓ Branch 2 taken 1335392 times.
✓ Branch 3 taken 13848 times.
✓ Branch 4 taken 1135982 times.
✓ Branch 5 taken 199410 times.
5322409 if ((off_to_cb && ((off_to_cb % 8) || !has_sub_block)))
570 1149830 return 0; // inside a cu, not aligned to 8 or with no subblocks
571
572
2/2
✓ Branch 0 taken 17640 times.
✓ Branch 1 taken 4154939 times.
4172579 if (!same_mode)
573 17640 return 1;
574
575 4154939 return boundary_strength(lc, mvf_q, mvf_p, rpl_p);
576 }
577
578 4113608 static int deblock_is_boundary(const VVCLocalContext *lc, const int boundary,
579 const int pos, const int rs, const int vertical)
580 {
581 4113608 const VVCFrameContext *fc = lc->fc;
582 4113608 const H266RawSPS *rsps = fc->ps.sps->r;
583 4113608 const H266RawPPS *rpps = fc->ps.pps->r;
584 int flag;
585
4/4
✓ Branch 0 taken 3616828 times.
✓ Branch 1 taken 496780 times.
✓ Branch 2 taken 584168 times.
✓ Branch 3 taken 3032660 times.
4113608 if (boundary && (pos % fc->ps.sps->ctb_size_y) == 0) {
586
2/2
✓ Branch 0 taken 316132 times.
✓ Branch 1 taken 268036 times.
584168 flag = vertical ? BOUNDARY_LEFT_SLICE : BOUNDARY_UPPER_SLICE;
587
2/2
✓ Branch 0 taken 20714 times.
✓ Branch 1 taken 563454 times.
584168 if (lc->boundary_flags & flag &&
588
2/2
✓ Branch 0 taken 8259 times.
✓ Branch 1 taken 12455 times.
20714 !rpps->pps_loop_filter_across_slices_enabled_flag)
589 8259 return 0;
590
591
2/2
✓ Branch 0 taken 312142 times.
✓ Branch 1 taken 263767 times.
575909 flag = vertical ? BOUNDARY_LEFT_TILE : BOUNDARY_UPPER_TILE;
592
2/2
✓ Branch 0 taken 29697 times.
✓ Branch 1 taken 546212 times.
575909 if (lc->boundary_flags & flag &&
593
2/2
✓ Branch 0 taken 9204 times.
✓ Branch 1 taken 20493 times.
29697 !rpps->pps_loop_filter_across_tiles_enabled_flag)
594 9204 return 0;
595
596
2/2
✓ Branch 0 taken 306563 times.
✓ Branch 1 taken 260142 times.
566705 flag = vertical ? BOUNDARY_LEFT_SUBPIC : BOUNDARY_UPPER_SUBPIC;
597
2/2
✓ Branch 0 taken 363 times.
✓ Branch 1 taken 566342 times.
566705 if (lc->boundary_flags & flag) {
598
2/2
✓ Branch 0 taken 313 times.
✓ Branch 1 taken 50 times.
363 const int q_rs = rs - (vertical ? 1 : fc->ps.pps->ctb_width);
599 363 const SliceContext *q_slice = lc->fc->slices[lc->fc->tab.slice_idx[q_rs]];
600
601
2/2
✓ Branch 0 taken 253 times.
✓ Branch 1 taken 110 times.
363 if (!rsps->sps_loop_filter_across_subpic_enabled_flag[q_slice->sh.r->curr_subpic_idx] ||
602
2/2
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 203 times.
253 !rsps->sps_loop_filter_across_subpic_enabled_flag[lc->sc->sh.r->curr_subpic_idx])
603 160 return 0;
604 }
605 }
606 4095985 return boundary;
607 }
608
609 2620510 static void vvc_deblock_bs_luma(const VVCLocalContext *lc,
610 const int x0, const int y0, const int width, const int height,
611 const CodingUnit *cu, const TransformUnit *tu, int rs, const int vertical)
612 {
613 2620510 const VVCFrameContext *fc = lc->fc;
614 2620510 const PredictionUnit *pu = &cu->pu;
615 2620510 const int mask = LUMA_GRID - 1;
616
2/2
✓ Branch 0 taken 1310255 times.
✓ Branch 1 taken 1310255 times.
2620510 const int pos = vertical ? x0 : y0;
617
2/2
✓ Branch 0 taken 1310255 times.
✓ Branch 1 taken 1310255 times.
2620510 const int cb = vertical ? cu->x0 : cu->y0;
618 2620510 const int is_intra = cu->pred_mode == MODE_INTRA;
619
2/2
✓ Branch 0 taken 1310255 times.
✓ Branch 1 taken 1310255 times.
2620510 const int cb_size = vertical ? cu->cb_width : cu->cb_height;
620
8/8
✓ Branch 0 taken 1142018 times.
✓ Branch 1 taken 1478492 times.
✓ Branch 2 taken 1015658 times.
✓ Branch 3 taken 126360 times.
✓ Branch 4 taken 29242 times.
✓ Branch 5 taken 986416 times.
✓ Branch 6 taken 128608 times.
✓ Branch 7 taken 26994 times.
2620510 const int has_sb = !is_intra && (pu->merge_subblock_flag || pu->inter_affine_flag) && cb_size > 8;
621
622
6/6
✓ Branch 0 taken 2570589 times.
✓ Branch 1 taken 49921 times.
✓ Branch 2 taken 2520027 times.
✓ Branch 3 taken 50562 times.
✓ Branch 5 taken 2509631 times.
✓ Branch 6 taken 110879 times.
2620510 if (deblock_is_boundary(lc, pos > 0 && !(pos & mask), pos, rs, vertical)) {
623 2509631 const int is_vb = is_virtual_boundary(fc, pos, vertical);
624
2/2
✓ Branch 0 taken 1270205 times.
✓ Branch 1 taken 1239426 times.
2509631 const int size = vertical ? height : width;
625
2/2
✓ Branch 0 taken 1270205 times.
✓ Branch 1 taken 1239426 times.
2509631 const int size_q = vertical ? width : height;
626 2509631 const int off = cb - pos;
627
2/2
✓ Branch 0 taken 1270205 times.
✓ Branch 1 taken 1239426 times.
2509631 const int flag = vertical ? BOUNDARY_LEFT_SLICE : BOUNDARY_UPPER_SLICE;
628 2509631 const RefPicList *rpl_p =
629
2/2
✓ Branch 0 taken 73777 times.
✓ Branch 1 taken 2435854 times.
2509631 (lc->boundary_flags & flag) ? ff_vvc_get_ref_list(fc, fc->ref, x0 - vertical, y0 - !vertical) : lc->sc->rpl;
630
631
2/2
✓ Branch 0 taken 10601762 times.
✓ Branch 1 taken 2509631 times.
13111393 for (int i = 0; i < size; i += 4) {
632 10601762 const int x = x0 + i * !vertical;
633 10601762 const int y = y0 + i * vertical;
634 uint8_t max_len_p, max_len_q;
635
1/2
✓ Branch 0 taken 10601762 times.
✗ Branch 1 not taken.
10601762 const int bs = is_vb ? 0 : deblock_bs(lc, x - vertical, y - !vertical, x, y, cu, tu, rpl_p, LUMA, off, has_sb);
636
637 10601762 TAB_BS(fc->tab.bs[vertical][LUMA], x, y) = bs;
638
639 10601762 derive_max_filter_length_luma(fc, x, y, size_q, has_sb, vertical, &max_len_p, &max_len_q);
640 10601762 TAB_MAX_LEN(fc->tab.max_len_p[vertical], x, y) = max_len_p;
641 10601762 TAB_MAX_LEN(fc->tab.max_len_q[vertical], x, y) = max_len_q;
642 }
643 }
644
645
2/2
✓ Branch 0 taken 128608 times.
✓ Branch 1 taken 2491902 times.
2620510 if (has_sb)
646 128608 vvc_deblock_subblock_bs(lc, cb, x0, y0, width, height, vertical);
647 2620510 }
648
649 1493098 static void vvc_deblock_bs_chroma(const VVCLocalContext *lc,
650 const int x0, const int y0, const int width, const int height,
651 const CodingUnit *cu, const TransformUnit *tu, const int rs, const int vertical)
652 {
653 1493098 const VVCFrameContext *fc = lc->fc;
654
2/2
✓ Branch 0 taken 746549 times.
✓ Branch 1 taken 746549 times.
1493098 const int shift = (vertical ? fc->ps.sps->hshift : fc->ps.sps->vshift)[CHROMA];
655 1493098 const int mask = (CHROMA_GRID << shift) - 1;
656
2/2
✓ Branch 0 taken 746549 times.
✓ Branch 1 taken 746549 times.
1493098 const int pos = vertical ? x0 : y0;
657
658
6/6
✓ Branch 0 taken 1453406 times.
✓ Branch 1 taken 39692 times.
✓ Branch 2 taken 1096801 times.
✓ Branch 3 taken 356605 times.
✓ Branch 5 taken 1089574 times.
✓ Branch 6 taken 403524 times.
1493098 if (deblock_is_boundary(lc, pos > 0 && !(pos & mask), pos, rs, vertical)) {
659 1089574 const int is_vb = is_virtual_boundary(fc, pos, vertical);
660
2/2
✓ Branch 0 taken 548943 times.
✓ Branch 1 taken 540631 times.
1089574 const int size = vertical ? height : width;
661
662
2/2
✓ Branch 0 taken 2179148 times.
✓ Branch 1 taken 1089574 times.
3268722 for (int c_idx = CB; c_idx <= CR; c_idx++) {
663
2/2
✓ Branch 0 taken 29911864 times.
✓ Branch 1 taken 2179148 times.
32091012 for (int i = 0; i < size; i += 2) {
664 29911864 const int x = x0 + i * !vertical;
665 29911864 const int y = y0 + i * vertical;
666
1/2
✓ Branch 0 taken 29911864 times.
✗ Branch 1 not taken.
29911864 const int bs = is_vb ? 0 : deblock_bs(lc, x - vertical, y - !vertical, x, y, cu, tu, NULL, c_idx, 0, 0);
667
668 29911864 TAB_BS(fc->tab.bs[vertical][c_idx], x, y) = bs;
669 }
670 }
671 }
672 1493098 }
673
674 typedef void (*deblock_bs_fn)(const VVCLocalContext *lc, const int x0, const int y0,
675 const int width, const int height, const int rs, const int vertical);
676
677 46709 void ff_vvc_deblock_bs(VVCLocalContext *lc, const int rx, const int ry, const int rs)
678 {
679 46709 const VVCFrameContext *fc = lc->fc;
680 46709 const VVCSPS *sps = fc->ps.sps;
681 46709 const int x0 = rx << sps->ctb_log2_size_y;
682 46709 const int y0 = ry << sps->ctb_log2_size_y;
683
684 46709 ff_vvc_decode_neighbour(lc, x0, y0, rx, ry, rs);
685
2/2
✓ Branch 0 taken 1232181 times.
✓ Branch 1 taken 46709 times.
1278890 for (const CodingUnit *cu = fc->tab.cus[rs]; cu; cu = cu->next) {
686
2/2
✓ Branch 0 taken 1492100 times.
✓ Branch 1 taken 1232181 times.
2724281 for (const TransformUnit *tu = cu->tus.head; tu; tu = tu->next) {
687
2/2
✓ Branch 0 taken 2984200 times.
✓ Branch 1 taken 1492100 times.
4476300 for (int vertical = 0; vertical <= 1; vertical++) {
688
2/2
✓ Branch 0 taken 2620510 times.
✓ Branch 1 taken 363690 times.
2984200 if (tu->avail[LUMA])
689 2620510 vvc_deblock_bs_luma(lc, tu->x0, tu->y0, tu->width, tu->height, cu, tu, rs, vertical);
690
2/2
✓ Branch 0 taken 1493098 times.
✓ Branch 1 taken 1491102 times.
2984200 if (tu->avail[CHROMA]) {
691
3/4
✓ Branch 0 taken 10382 times.
✓ Branch 1 taken 1482716 times.
✓ Branch 2 taken 10382 times.
✗ Branch 3 not taken.
1493098 if (cu->isp_split_type != ISP_NO_SPLIT && cu->tree_type == SINGLE_TREE)
692 10382 vvc_deblock_bs_chroma(lc, cu->x0, cu->y0, cu->cb_width, cu->cb_height, cu, tu, rs, vertical);
693 else
694 1482716 vvc_deblock_bs_chroma(lc, tu->x0, tu->y0, tu->width, tu->height, cu, tu, rs, vertical);
695 }
696 }
697 }
698 }
699 46709 }
700
701 //part of 8.8.3.3 Derivation process of transform block boundary
702 7421001 static void max_filter_length_luma(const VVCFrameContext *fc, const int qx, const int qy,
703 const int vertical, uint8_t *max_len_p, uint8_t *max_len_q)
704 {
705 7421001 *max_len_p = TAB_MAX_LEN(fc->tab.max_len_p[vertical], qx, qy);
706 7421001 *max_len_q = TAB_MAX_LEN(fc->tab.max_len_q[vertical], qx, qy);
707 7421001 }
708
709 //part of 8.8.3.3 Derivation process of transform block boundary
710 4303525 static void max_filter_length_chroma(const VVCFrameContext *fc, const int qx, const int qy,
711 const int vertical, const int horizontal_ctu_edge, const int bs, uint8_t *max_len_p, uint8_t *max_len_q)
712 {
713
2/2
✓ Branch 0 taken 2086213 times.
✓ Branch 1 taken 2217312 times.
4303525 const int px = vertical ? qx - 1 : qx;
714
2/2
✓ Branch 0 taken 2217312 times.
✓ Branch 1 taken 2086213 times.
4303525 const int py = !vertical ? qy - 1 : qy;
715
2/2
✓ Branch 0 taken 2086213 times.
✓ Branch 1 taken 2217312 times.
4303525 const uint8_t *tb_size = vertical ? fc->tab.tb_width[CHROMA] : fc->tab.tb_height[CHROMA];
716
717 4303525 const int size_p = tb_size[(py >> MIN_TU_LOG2) * fc->ps.pps->min_tu_width + (px >> MIN_TU_LOG2)];
718 4303525 const int size_q = tb_size[(qy >> MIN_TU_LOG2) * fc->ps.pps->min_tu_width + (qx >> MIN_TU_LOG2)];
719
4/4
✓ Branch 0 taken 3506049 times.
✓ Branch 1 taken 797476 times.
✓ Branch 2 taken 3007274 times.
✓ Branch 3 taken 498775 times.
4303525 if (size_p >= 8 && size_q >= 8) {
720 3007274 *max_len_p = *max_len_q = 3;
721
2/2
✓ Branch 0 taken 362284 times.
✓ Branch 1 taken 2644990 times.
3007274 if (horizontal_ctu_edge)
722 362284 *max_len_p = 1;
723 } else {
724 //part of 8.8.3.6.4 Decision process for chroma block edges
725 1296251 *max_len_p = *max_len_q = (bs == 2);
726 }
727 4303525 }
728
729 11724526 static void max_filter_length(const VVCFrameContext *fc, const int qx, const int qy,
730 const int c_idx, const int vertical, const int horizontal_ctu_edge, const int bs, uint8_t *max_len_p, uint8_t *max_len_q)
731 {
732
2/2
✓ Branch 0 taken 7421001 times.
✓ Branch 1 taken 4303525 times.
11724526 if (!c_idx)
733 7421001 max_filter_length_luma(fc, qx, qy, vertical, max_len_p, max_len_q);
734 else
735 4303525 max_filter_length_chroma(fc, qx, qy, vertical, horizontal_ctu_edge, bs, max_len_p, max_len_q);
736 11724526 }
737
738 #define TC_CALC(qp, bs) \
739 tctable[av_clip((qp) + DEFAULT_INTRA_TC_OFFSET * ((bs) - 1) + \
740 (tc_offset & -2), \
741 0, MAX_QP + DEFAULT_INTRA_TC_OFFSET)]
742
743 // part of 8.8.3.6.2 Decision process for luma block edges
744 7421001 static int get_qp_y(const VVCFrameContext *fc, const uint8_t *src, const int x, const int y, const int vertical)
745 {
746 7421001 const VVCSPS *sps = fc->ps.sps;
747 7421001 const int qp = (ff_vvc_get_qPy(fc, x - vertical, y - !vertical) + ff_vvc_get_qPy(fc, x, y) + 1) >> 1;
748 7421001 int qp_offset = 0;
749 int level;
750
751
2/2
✓ Branch 0 taken 6949122 times.
✓ Branch 1 taken 471879 times.
7421001 if (!sps->r->sps_ladf_enabled_flag)
752 6949122 return qp;
753
754 471879 level = fc->vvcdsp.lf.ladf_level[vertical](src, fc->frame->linesize[LUMA]);
755 471879 qp_offset = sps->r->sps_ladf_lowest_interval_qp_offset;
756
4/4
✓ Branch 0 taken 932712 times.
✓ Branch 1 taken 437994 times.
✓ Branch 2 taken 898827 times.
✓ Branch 3 taken 33885 times.
1370706 for (int i = 0; i < sps->num_ladf_intervals - 1 && level > sps->ladf_interval_lower_bound[i + 1]; i++)
757 898827 qp_offset = sps->r->sps_ladf_qp_offset[i];
758
759 471879 return qp + qp_offset;
760 }
761
762 // part of 8.8.3.6.2 Decision process for luma block edges
763 4303525 static int get_qp_c(const VVCFrameContext *fc, const int x, const int y, const int c_idx, const int vertical)
764 {
765 4303525 const VVCSPS *sps = fc->ps.sps;
766 4303525 return (get_qPc(fc, x - vertical, y - !vertical, c_idx) + get_qPc(fc, x, y, c_idx) - 2 * sps->qp_bd_offset + 1) >> 1;
767 }
768
769 11724526 static int get_qp(const VVCFrameContext *fc, const uint8_t *src, const int x, const int y, const int c_idx, const int vertical)
770 {
771
2/2
✓ Branch 0 taken 7421001 times.
✓ Branch 1 taken 4303525 times.
11724526 if (!c_idx)
772 7421001 return get_qp_y(fc, src, x, y, vertical);
773 4303525 return get_qp_c(fc, x, y, c_idx, vertical);
774 }
775
776 93418 static void vvc_deblock(const VVCLocalContext *lc, int x0, int y0, const int rs, const int vertical)
777 {
778 93418 VVCFrameContext *fc = lc->fc;
779 93418 const VVCSPS *sps = fc->ps.sps;
780
2/2
✓ Branch 0 taken 92362 times.
✓ Branch 1 taken 1056 times.
93418 const int c_end = sps->r->sps_chroma_format_idc ? VVC_MAX_SAMPLE_ARRAYS : 1;
781 93418 const int ctb_size = fc->ps.sps->ctb_size_y;
782 93418 const DBParams *params = fc->tab.deblock + rs;
783 93418 int x_end = FFMIN(x0 + ctb_size, fc->ps.pps->width);
784 93418 int y_end = FFMIN(y0 + ctb_size, fc->ps.pps->height);
785 93418 const int log2_min_cb_size = fc->ps.sps->min_cb_log2_size_y;
786 93418 const int min_cb_width = fc->ps.pps->min_cb_width;
787
788
2/2
✓ Branch 0 taken 46709 times.
✓ Branch 1 taken 46709 times.
93418 if (!vertical) {
789 46709 FFSWAP(int, x_end, y_end);
790 46709 FFSWAP(int, x0, y0);
791 }
792
793
2/2
✓ Branch 0 taken 278142 times.
✓ Branch 1 taken 93418 times.
371560 for (int c_idx = 0; c_idx < c_end; c_idx++) {
794
2/2
✓ Branch 0 taken 139071 times.
✓ Branch 1 taken 139071 times.
278142 const int hs = (vertical ? sps->hshift : sps->vshift)[c_idx];
795
2/2
✓ Branch 0 taken 139071 times.
✓ Branch 1 taken 139071 times.
278142 const int vs = (vertical ? sps->vshift : sps->hshift)[c_idx];
796
2/2
✓ Branch 0 taken 184724 times.
✓ Branch 1 taken 93418 times.
278142 const int grid = c_idx ? (CHROMA_GRID << hs) : LUMA_GRID;
797 278142 const int tc_offset = params->tc_offset[c_idx];
798 278142 const int beta_offset = params->beta_offset[c_idx];
799 278142 const int src_stride = fc->frame->linesize[c_idx];
800
801
2/2
✓ Branch 0 taken 3218051 times.
✓ Branch 1 taken 278142 times.
3496193 for (int y = y0; y < y_end; y += (DEBLOCK_STEP << vs)) {
802
4/4
✓ Branch 0 taken 2845821 times.
✓ Branch 1 taken 372230 times.
✓ Branch 2 taken 62640210 times.
✓ Branch 3 taken 3218051 times.
65858261 for (int x = x0 ? x0 : grid; x < x_end; x += grid) {
803
4/4
✓ Branch 0 taken 31270252 times.
✓ Branch 1 taken 31369958 times.
✓ Branch 2 taken 1405432 times.
✓ Branch 3 taken 29864820 times.
62640210 const uint8_t horizontal_ctu_edge = !vertical && !(x % ctb_size);
804 62640210 int32_t bs[4], beta[4], tc[4] = { 0 }, all_zero_bs = 1;
805 uint8_t max_len_p[4], max_len_q[4];
806 62640210 uint8_t no_p[4] = { 0 };
807 62640210 uint8_t no_q[4] = { 0 };
808
809
2/2
✓ Branch 0 taken 139558820 times.
✓ Branch 1 taken 62640210 times.
202199030 for (int i = 0; i < DEBLOCK_STEP >> (2 - vs); i++) {
810 139558820 int tx = x;
811 139558820 int ty = y + (i << 2);
812 139558820 const int end = ty >= y_end;
813
814
2/2
✓ Branch 0 taken 69646736 times.
✓ Branch 1 taken 69912084 times.
139558820 if (!vertical)
815 69646736 FFSWAP(int, tx, ty);
816
817
2/2
✓ Branch 0 taken 139477352 times.
✓ Branch 1 taken 81468 times.
139558820 bs[i] = end ? 0 : TAB_BS(fc->tab.bs[vertical][c_idx], tx, ty);
818
2/2
✓ Branch 0 taken 11724526 times.
✓ Branch 1 taken 127834294 times.
139558820 if (bs[i]) {
819 11724526 const int qp = get_qp(fc, POS(c_idx, tx, ty), tx, ty, c_idx, vertical);
820 11724526 beta[i] = betatable[av_clip(qp + beta_offset, 0, MAX_QP)];
821 11724526 tc[i] = TC_CALC(qp, bs[i]) ;
822 11724526 max_filter_length(fc, tx, ty, c_idx, vertical, horizontal_ctu_edge, bs[i], &max_len_p[i], &max_len_q[i]);
823 11724526 all_zero_bs = 0;
824
825
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11724526 times.
11724526 if (sps->r->sps_palette_enabled_flag) {
826 const int cu_q = (ty >> log2_min_cb_size) * min_cb_width + (tx >> log2_min_cb_size);
827 const int cu_p = (ty - !vertical >> log2_min_cb_size) * min_cb_width + (tx - vertical >> log2_min_cb_size);
828 no_q[i] = fc->tab.cpm[!!c_idx][cu_q] == MODE_PLT;
829 no_p[i] = cu_p >= 0 && fc->tab.cpm[!!c_idx][cu_p] == MODE_PLT;
830 }
831 }
832 }
833
834
2/2
✓ Branch 0 taken 5078040 times.
✓ Branch 1 taken 57562170 times.
62640210 if (!all_zero_bs) {
835
2/2
✓ Branch 0 taken 2459910 times.
✓ Branch 1 taken 2618130 times.
5078040 uint8_t *src = vertical ? POS(c_idx, x, y) : POS(c_idx, y, x);
836
2/2
✓ Branch 0 taken 3803343 times.
✓ Branch 1 taken 1274697 times.
5078040 if (!c_idx)
837 3803343 fc->vvcdsp.lf.filter_luma[vertical](src, src_stride, beta, tc, no_p, no_q, max_len_p, max_len_q, horizontal_ctu_edge);
838 else
839 1274697 fc->vvcdsp.lf.filter_chroma[vertical](src, src_stride, beta, tc, no_p, no_q, max_len_p, max_len_q, vs);
840 }
841 }
842 }
843 }
844 93418 }
845
846 46709 void ff_vvc_deblock_vertical(const VVCLocalContext *lc, const int x0, const int y0, const int rs)
847 {
848 46709 vvc_deblock(lc, x0, y0, rs, 1);
849 46709 }
850
851 46709 void ff_vvc_deblock_horizontal(const VVCLocalContext *lc, const int x0, const int y0, const int rs)
852 {
853 46709 vvc_deblock(lc, x0, y0, rs, 0);
854 46709 }
855
856 585487 static void alf_copy_border(uint8_t *dst, const uint8_t *src,
857 const int pixel_shift, int width, const int height, const ptrdiff_t dst_stride, const ptrdiff_t src_stride)
858 {
859 585487 width <<= pixel_shift;
860
2/2
✓ Branch 0 taken 29380116 times.
✓ Branch 1 taken 585487 times.
29965603 for (int i = 0; i < height; i++) {
861 29380116 memcpy(dst, src, width);
862 29380116 dst += dst_stride;
863 29380116 src += src_stride;
864 }
865 585487 }
866
867 10319 static void alf_extend_vert(uint8_t *_dst, const uint8_t *_src,
868 const int pixel_shift, const int width, const int height, ptrdiff_t stride)
869 {
870
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10319 times.
10319 if (pixel_shift == 0) {
871 for (int i = 0; i < height; i++) {
872 memset(_dst, *_src, width);
873 _src += stride;
874 _dst += stride;
875 }
876 } else {
877 10319 const uint16_t *src = (const uint16_t *)_src;
878 10319 uint16_t *dst = (uint16_t *)_dst;
879 10319 stride >>= pixel_shift;
880
881
2/2
✓ Branch 0 taken 999384 times.
✓ Branch 1 taken 10319 times.
1009703 for (int i = 0; i < height; i++) {
882
2/2
✓ Branch 0 taken 2586436 times.
✓ Branch 1 taken 999384 times.
3585820 for (int j = 0; j < width; j++)
883 2586436 dst[j] = *src;
884 999384 src += stride;
885 999384 dst += stride;
886 }
887 }
888 10319 }
889
890 45875 static void alf_extend_horz(uint8_t *dst, const uint8_t *src,
891 const int pixel_shift, int width, const int height, const ptrdiff_t stride)
892 {
893 45875 width <<= pixel_shift;
894
2/2
✓ Branch 0 taken 112894 times.
✓ Branch 1 taken 45875 times.
158769 for (int i = 0; i < height; i++) {
895 112894 memcpy(dst, src, width);
896 112894 dst += stride;
897 }
898 45875 }
899
900 108969 static void alf_copy_ctb_to_hv(VVCFrameContext *fc, const uint8_t *src, const ptrdiff_t src_stride,
901 const int x, const int y, const int width, const int height, const int rx, const int ry, const int c_idx)
902 {
903 108969 const int ps = fc->ps.sps->pixel_shift;
904 108969 const int w = fc->ps.pps->width >> fc->ps.sps->hshift[c_idx];
905 108969 const int h = fc->ps.pps->height >> fc->ps.sps->vshift[c_idx];
906
2/2
✓ Branch 0 taken 36675 times.
✓ Branch 1 taken 72294 times.
108969 const int border_pixels = (c_idx == 0) ? ALF_BORDER_LUMA : ALF_BORDER_CHROMA;
907 108969 const int offset_h[] = { 0, height - border_pixels };
908 108969 const int offset_v[] = { 0, width - border_pixels };
909
910 /* copy horizontal edges */
911
2/2
✓ Branch 0 taken 217938 times.
✓ Branch 1 taken 108969 times.
326907 for (int i = 0; i < FF_ARRAY_ELEMS(offset_h); i++) {
912 217938 alf_copy_border(fc->tab.alf_pixel_buffer_h[c_idx][i] + ((border_pixels * ry * w + x)<< ps),
913 217938 src + offset_h[i] * src_stride, ps, width, border_pixels, w << ps, src_stride);
914 }
915 /* copy vertical edges */
916
2/2
✓ Branch 0 taken 217938 times.
✓ Branch 1 taken 108969 times.
326907 for (int i = 0; i < FF_ARRAY_ELEMS(offset_v); i++) {
917 217938 alf_copy_border(fc->tab.alf_pixel_buffer_v[c_idx][i] + ((h * rx + y) * (border_pixels << ps)),
918 217938 src + (offset_v[i] << ps), ps, border_pixels, height, border_pixels << ps, src_stride);
919 }
920 108969 }
921
922 88790 static void alf_fill_border_h(uint8_t *dst, const ptrdiff_t dst_stride, const uint8_t *src, const ptrdiff_t src_stride,
923 const uint8_t *border, const int width, const int border_pixels, const int ps, const int edge)
924 {
925
2/2
✓ Branch 0 taken 17650 times.
✓ Branch 1 taken 71140 times.
88790 if (edge)
926 17650 alf_extend_horz(dst, border, ps, width, border_pixels, dst_stride);
927 else
928 71140 alf_copy_border(dst, src, ps, width, border_pixels, dst_stride, src_stride);
929 88790 }
930
931 88790 static void alf_fill_border_v(uint8_t *dst, const ptrdiff_t dst_stride, const uint8_t *src,
932 const uint8_t *border, const int border_pixels, const int height, const int pixel_shift, const int *edges, const int edge)
933 {
934 88790 const ptrdiff_t src_stride = (border_pixels << pixel_shift);
935
936
2/2
✓ Branch 0 taken 10319 times.
✓ Branch 1 taken 78471 times.
88790 if (edge) {
937 10319 alf_extend_vert(dst, border, pixel_shift, border_pixels, height + 2 * border_pixels, dst_stride);
938 10319 return;
939 }
940
941 //left/right
942 78471 alf_copy_border(dst + dst_stride * border_pixels * edges[TOP], src + src_stride * border_pixels * edges[TOP],
943 78471 pixel_shift, border_pixels, height + (!edges[TOP] + !edges[BOTTOM]) * border_pixels, dst_stride, src_stride);
944
945 //top left/right
946
2/2
✓ Branch 0 taken 12868 times.
✓ Branch 1 taken 65603 times.
78471 if (edges[TOP])
947 12868 alf_extend_horz(dst, dst + dst_stride * border_pixels, pixel_shift, border_pixels, border_pixels, dst_stride);
948
949 //bottom left/right
950
2/2
✓ Branch 0 taken 15357 times.
✓ Branch 1 taken 63114 times.
78471 if (edges[BOTTOM]) {
951 15357 dst += dst_stride * (border_pixels + height);
952 15357 alf_extend_horz(dst, dst - dst_stride, pixel_shift, border_pixels, border_pixels, dst_stride);
953 }
954 }
955
956 44395 static void alf_prepare_buffer(VVCFrameContext *fc, uint8_t *_dst, const uint8_t *_src, const int x, const int y,
957 const int rx, const int ry, const int width, const int height, const ptrdiff_t dst_stride, const ptrdiff_t src_stride,
958 const int c_idx, const int *edges)
959 {
960 44395 const int ps = fc->ps.sps->pixel_shift;
961 44395 const int w = fc->ps.pps->width >> fc->ps.sps->hshift[c_idx];
962 44395 const int h = fc->ps.pps->height >> fc->ps.sps->vshift[c_idx];
963
2/2
✓ Branch 0 taken 20190 times.
✓ Branch 1 taken 24205 times.
44395 const int border_pixels = c_idx == 0 ? ALF_BORDER_LUMA : ALF_BORDER_CHROMA;
964 uint8_t *dst, *src;
965
966 44395 copy_ctb(_dst, _src, width << ps, height, dst_stride, src_stride);
967
968 //top
969 44395 src = fc->tab.alf_pixel_buffer_h[c_idx][1] + (((border_pixels * w) << ps) * (ry - 1) + (x << ps));
970 44395 dst = _dst - border_pixels * dst_stride;
971 44395 alf_fill_border_h(dst, dst_stride, src, w << ps, _dst, width, border_pixels, ps, edges[TOP]);
972
973 //bottom
974 44395 src = fc->tab.alf_pixel_buffer_h[c_idx][0] + (((border_pixels * w) << ps) * (ry + 1) + (x << ps));
975 44395 dst = _dst + height * dst_stride;
976 44395 alf_fill_border_h(dst, dst_stride, src, w << ps, _dst + (height - 1) * dst_stride, width, border_pixels, ps, edges[BOTTOM]);
977
978
979 //left
980 44395 src = fc->tab.alf_pixel_buffer_v[c_idx][1] + (h * (rx - 1) + y - border_pixels) * (border_pixels << ps);
981 44395 dst = _dst - (border_pixels << ps) - border_pixels * dst_stride;
982 44395 alf_fill_border_v(dst, dst_stride, src, dst + (border_pixels << ps), border_pixels, height, ps, edges, edges[LEFT]);
983
984 //right
985 44395 src = fc->tab.alf_pixel_buffer_v[c_idx][0] + (h * (rx + 1) + y - border_pixels) * (border_pixels << ps);
986 44395 dst = _dst + (width << ps) - border_pixels * dst_stride;
987 44395 alf_fill_border_v(dst, dst_stride, src, dst - (1 << ps), border_pixels, height, ps, edges, edges[RIGHT]);
988 44395 }
989
990 #define ALF_MAX_BLOCKS_IN_CTU (MAX_CTU_SIZE * MAX_CTU_SIZE / ALF_BLOCK_SIZE / ALF_BLOCK_SIZE)
991 #define ALF_MAX_FILTER_SIZE (ALF_MAX_BLOCKS_IN_CTU * ALF_NUM_COEFF_LUMA)
992
993 19555 static void alf_get_coeff_and_clip(VVCLocalContext *lc, int16_t *coeff, int16_t *clip,
994 const uint8_t *src, ptrdiff_t src_stride, int width, int height, int vb_pos, const ALFParams *alf)
995 {
996 19555 const VVCFrameContext *fc = lc->fc;
997 19555 const H266RawSliceHeader *rsh = lc->sc->sh.r;
998 19555 uint8_t fixed_clip_set[ALF_NUM_FILTERS_LUMA][ALF_NUM_COEFF_LUMA] = { 0 };
999 const int16_t *coeff_set;
1000 const uint8_t *clip_idx_set;
1001 const uint8_t *class_to_filt;
1002 19555 const int size = width * height / ALF_BLOCK_SIZE / ALF_BLOCK_SIZE;
1003 int class_idx[ALF_MAX_BLOCKS_IN_CTU];
1004 int transpose_idx[ALF_MAX_BLOCKS_IN_CTU];
1005
1006
2/2
✓ Branch 0 taken 2775 times.
✓ Branch 1 taken 16780 times.
19555 if (alf->ctb_filt_set_idx_y < 16) {
1007 2775 coeff_set = &ff_vvc_alf_fix_filt_coeff[0][0];
1008 2775 clip_idx_set = &fixed_clip_set[0][0];
1009 2775 class_to_filt = ff_vvc_alf_class_to_filt_map[alf->ctb_filt_set_idx_y];
1010 } else {
1011 16780 const int id = rsh->sh_alf_aps_id_luma[alf->ctb_filt_set_idx_y - 16];
1012 16780 const VVCALF *aps = fc->ps.alf_list[id];
1013 16780 coeff_set = &aps->luma_coeff[0][0];
1014 16780 clip_idx_set = &aps->luma_clip_idx[0][0];
1015 16780 class_to_filt = ff_vvc_alf_aps_class_to_filt_map;
1016 }
1017 19555 fc->vvcdsp.alf.classify(class_idx, transpose_idx, src, src_stride, width, height,
1018 19555 vb_pos, lc->alf_gradient_tmp);
1019 19555 fc->vvcdsp.alf.recon_coeff_and_clip(coeff, clip, class_idx, transpose_idx, size,
1020 coeff_set, clip_idx_set, class_to_filt);
1021 19555 }
1022
1023 19555 static void alf_filter_luma(VVCLocalContext *lc, uint8_t *dst, const uint8_t *src,
1024 const ptrdiff_t dst_stride, const ptrdiff_t src_stride, const int x0, const int y0,
1025 const int width, const int height, const int _vb_pos, const ALFParams *alf)
1026 {
1027 19555 const VVCFrameContext *fc = lc->fc;
1028 19555 int vb_pos = _vb_pos - y0;
1029 19555 int16_t *coeff = (int16_t*)lc->tmp;
1030 19555 int16_t *clip = (int16_t *)lc->tmp1;
1031
1032 av_assert0(ALF_MAX_FILTER_SIZE <= sizeof(lc->tmp));
1033 av_assert0(ALF_MAX_FILTER_SIZE * sizeof(int16_t) <= sizeof(lc->tmp1));
1034
1035 19555 alf_get_coeff_and_clip(lc, coeff, clip, src, src_stride, width, height, vb_pos, alf);
1036 19555 fc->vvcdsp.alf.filter[LUMA](dst, dst_stride, src, src_stride, width, height, coeff, clip, vb_pos);
1037 19555 }
1038
1039 145230 static int alf_clip_from_idx(const VVCFrameContext *fc, const int idx)
1040 {
1041 145230 const VVCSPS *sps = fc->ps.sps;
1042 145230 const int offset[] = {0, 3, 5, 7};
1043
1044 145230 return 1 << (sps->bit_depth - offset[idx]);
1045 }
1046
1047 24205 static void alf_filter_chroma(VVCLocalContext *lc, uint8_t *dst, const uint8_t *src,
1048 const ptrdiff_t dst_stride, const ptrdiff_t src_stride, const int c_idx,
1049 const int width, const int height, const int vb_pos, const ALFParams *alf)
1050 {
1051 24205 VVCFrameContext *fc = lc->fc;
1052 24205 const H266RawSliceHeader *rsh = lc->sc->sh.r;
1053 24205 const VVCALF *aps = fc->ps.alf_list[rsh->sh_alf_aps_id_chroma];
1054 24205 const int idx = alf->alf_ctb_filter_alt_idx[c_idx - 1];
1055 24205 const int16_t *coeff = aps->chroma_coeff[idx];
1056 int16_t clip[ALF_NUM_COEFF_CHROMA];
1057
1058
2/2
✓ Branch 0 taken 145230 times.
✓ Branch 1 taken 24205 times.
169435 for (int i = 0; i < ALF_NUM_COEFF_CHROMA; i++)
1059 145230 clip[i] = alf_clip_from_idx(fc, aps->chroma_clip_idx[idx][i]);
1060
1061 24205 fc->vvcdsp.alf.filter[CHROMA](dst, dst_stride, src, src_stride, width, height, coeff, clip, vb_pos);
1062 24205 }
1063
1064 10527 static void alf_filter_cc(VVCLocalContext *lc, uint8_t *dst, const uint8_t *luma,
1065 const ptrdiff_t dst_stride, const ptrdiff_t luma_stride, const int c_idx,
1066 const int width, const int height, const int hs, const int vs, const int vb_pos, const ALFParams *alf)
1067 {
1068 10527 const VVCFrameContext *fc = lc->fc;
1069 10527 const H266RawSliceHeader *rsh = lc->sc->sh.r;
1070 10527 const int idx = c_idx - 1;
1071
2/2
✓ Branch 0 taken 5379 times.
✓ Branch 1 taken 5148 times.
10527 const int cc_aps_id = c_idx == CB ? rsh->sh_alf_cc_cb_aps_id : rsh->sh_alf_cc_cr_aps_id;
1072 10527 const VVCALF *aps = fc->ps.alf_list[cc_aps_id];
1073
1074
1/2
✓ Branch 0 taken 10527 times.
✗ Branch 1 not taken.
10527 if (aps) {
1075 10527 const int16_t *coeff = aps->cc_coeff[idx][alf->ctb_cc_idc[idx] - 1];
1076
1077 10527 fc->vvcdsp.alf.filter_cc(dst, dst_stride, luma, luma_stride, width, height, hs, vs, coeff, vb_pos);
1078 }
1079 10527 }
1080
1081 36675 void ff_vvc_alf_copy_ctu_to_hv(VVCLocalContext* lc, const int x0, const int y0)
1082 {
1083 36675 VVCFrameContext *fc = lc->fc;
1084 36675 const int rx = x0 >> fc->ps.sps->ctb_log2_size_y;
1085 36675 const int ry = y0 >> fc->ps.sps->ctb_log2_size_y;
1086 36675 const int ctb_size_y = fc->ps.sps->ctb_size_y;
1087
2/2
✓ Branch 0 taken 36147 times.
✓ Branch 1 taken 528 times.
36675 const int c_end = fc->ps.sps->r->sps_chroma_format_idc ? VVC_MAX_SAMPLE_ARRAYS : 1;
1088
1089
2/2
✓ Branch 0 taken 108969 times.
✓ Branch 1 taken 36675 times.
145644 for (int c_idx = 0; c_idx < c_end; c_idx++) {
1090 108969 const int hs = fc->ps.sps->hshift[c_idx];
1091 108969 const int vs = fc->ps.sps->vshift[c_idx];
1092 108969 const int x = x0 >> hs;
1093 108969 const int y = y0 >> vs;
1094 108969 const int width = FFMIN(fc->ps.pps->width - x0, ctb_size_y) >> hs;
1095 108969 const int height = FFMIN(fc->ps.pps->height - y0, ctb_size_y) >> vs;
1096
1097 108969 const int src_stride = fc->frame->linesize[c_idx];
1098 108969 uint8_t *src = POS(c_idx, x0, y0);
1099
1100 108969 alf_copy_ctb_to_hv(fc, src, src_stride, x, y, width, height, rx, ry, c_idx);
1101 }
1102 36675 }
1103
1104 36675 static void alf_get_edges(const VVCLocalContext *lc, int edges[MAX_EDGES], const int rx, const int ry)
1105 {
1106 36675 VVCFrameContext *fc = lc->fc;
1107 36675 const VVCSPS *sps = fc->ps.sps;
1108 36675 const VVCPPS *pps = fc->ps.pps;
1109 36675 const int subpic_idx = lc->sc->sh.r->curr_subpic_idx;
1110
1111 // we can't use |= instead of || in this function; |= is not a shortcut operator
1112
1113
2/2
✓ Branch 0 taken 33256 times.
✓ Branch 1 taken 3419 times.
36675 if (!pps->r->pps_loop_filter_across_tiles_enabled_flag) {
1114
4/4
✓ Branch 0 taken 30034 times.
✓ Branch 1 taken 3222 times.
✓ Branch 2 taken 612 times.
✓ Branch 3 taken 29422 times.
33256 edges[LEFT] = edges[LEFT] || (lc->boundary_flags & BOUNDARY_LEFT_TILE);
1115
4/4
✓ Branch 0 taken 27548 times.
✓ Branch 1 taken 5708 times.
✓ Branch 2 taken 564 times.
✓ Branch 3 taken 26984 times.
33256 edges[TOP] = edges[TOP] || (lc->boundary_flags & BOUNDARY_UPPER_TILE);
1116
4/4
✓ Branch 0 taken 30034 times.
✓ Branch 1 taken 3222 times.
✓ Branch 2 taken 612 times.
✓ Branch 3 taken 29422 times.
33256 edges[RIGHT] = edges[RIGHT] || pps->ctb_to_col_bd[rx] != pps->ctb_to_col_bd[rx + 1];
1117
4/4
✓ Branch 0 taken 27548 times.
✓ Branch 1 taken 5708 times.
✓ Branch 2 taken 564 times.
✓ Branch 3 taken 26984 times.
33256 edges[BOTTOM] = edges[BOTTOM] || pps->ctb_to_row_bd[ry] != pps->ctb_to_row_bd[ry + 1];
1118 }
1119
1120
2/2
✓ Branch 0 taken 33207 times.
✓ Branch 1 taken 3468 times.
36675 if (!pps->r->pps_loop_filter_across_slices_enabled_flag) {
1121
4/4
✓ Branch 0 taken 29506 times.
✓ Branch 1 taken 3701 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 29501 times.
33207 edges[LEFT] = edges[LEFT] || (lc->boundary_flags & BOUNDARY_LEFT_SLICE);
1122
4/4
✓ Branch 0 taken 27068 times.
✓ Branch 1 taken 6139 times.
✓ Branch 2 taken 71 times.
✓ Branch 3 taken 26997 times.
33207 edges[TOP] = edges[TOP] || (lc->boundary_flags & BOUNDARY_UPPER_SLICE);
1123
4/4
✓ Branch 0 taken 29506 times.
✓ Branch 1 taken 3701 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 29501 times.
33207 edges[RIGHT] = edges[RIGHT] || CTB(fc->tab.slice_idx, rx, ry) != CTB(fc->tab.slice_idx, rx + 1, ry);
1124
4/4
✓ Branch 0 taken 27068 times.
✓ Branch 1 taken 6139 times.
✓ Branch 2 taken 71 times.
✓ Branch 3 taken 26997 times.
33207 edges[BOTTOM] = edges[BOTTOM] || CTB(fc->tab.slice_idx, rx, ry) != CTB(fc->tab.slice_idx, rx, ry + 1);
1125 }
1126
1127
2/2
✓ Branch 0 taken 35709 times.
✓ Branch 1 taken 966 times.
36675 if (!sps->r->sps_loop_filter_across_subpic_enabled_flag[subpic_idx]) {
1128
4/4
✓ Branch 0 taken 31968 times.
✓ Branch 1 taken 3741 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 31964 times.
35709 edges[LEFT] = edges[LEFT] || (lc->boundary_flags & BOUNDARY_LEFT_SUBPIC);
1129
3/4
✓ Branch 0 taken 29340 times.
✓ Branch 1 taken 6369 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 29340 times.
35709 edges[TOP] = edges[TOP] || (lc->boundary_flags & BOUNDARY_UPPER_SUBPIC);
1130
3/4
✓ Branch 0 taken 31964 times.
✓ Branch 1 taken 3745 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 31964 times.
35709 edges[RIGHT] = edges[RIGHT] || fc->ps.sps->r->sps_subpic_ctu_top_left_x[subpic_idx] + fc->ps.sps->r->sps_subpic_width_minus1[subpic_idx] == rx;
1131
4/4
✓ Branch 0 taken 29352 times.
✓ Branch 1 taken 6357 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 29340 times.
35709 edges[BOTTOM] = edges[BOTTOM] || fc->ps.sps->r->sps_subpic_ctu_top_left_y[subpic_idx] + fc->ps.sps->r->sps_subpic_height_minus1[subpic_idx] == ry;
1132 }
1133
1134
2/2
✓ Branch 0 taken 1029 times.
✓ Branch 1 taken 35646 times.
36675 if (sps->r->sps_virtual_boundaries_enabled_flag) {
1135
3/4
✓ Branch 0 taken 621 times.
✓ Branch 1 taken 408 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 621 times.
1029 edges[LEFT] = edges[LEFT] || is_virtual_boundary(fc, rx << sps->ctb_log2_size_y, 1);
1136
3/4
✓ Branch 0 taken 595 times.
✓ Branch 1 taken 434 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 595 times.
1029 edges[TOP] = edges[TOP] || is_virtual_boundary(fc, ry << sps->ctb_log2_size_y, 0);
1137
3/4
✓ Branch 0 taken 625 times.
✓ Branch 1 taken 404 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 625 times.
1029 edges[RIGHT] = edges[RIGHT] || is_virtual_boundary(fc, (rx + 1) << sps->ctb_log2_size_y, 1);
1138
3/4
✓ Branch 0 taken 583 times.
✓ Branch 1 taken 446 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 583 times.
1029 edges[BOTTOM] = edges[BOTTOM] || is_virtual_boundary(fc, (ry + 1) << sps->ctb_log2_size_y, 0);
1139 }
1140 36675 }
1141
1142 36675 static void alf_init_subblock(VVCRect *sb, int sb_edges[MAX_EDGES], const VVCRect *b, const int edges[MAX_EDGES])
1143 {
1144 36675 *sb = *b;
1145 36675 memcpy(sb_edges, edges, sizeof(int) * MAX_EDGES);
1146 36675 }
1147
1148 36675 static void alf_get_subblock(VVCRect *sb, int edges[MAX_EDGES], const int bx, const int by, const int vb_pos[2], const int has_vb[2])
1149 {
1150 36675 int *pos[] = { &sb->l, &sb->t, &sb->r, &sb->b };
1151
1152
2/2
✓ Branch 0 taken 73350 times.
✓ Branch 1 taken 36675 times.
110025 for (int vertical = 0; vertical <= 1; vertical++) {
1153
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 73350 times.
73350 if (has_vb[vertical]) {
1154 const int c = vertical ? (bx ? LEFT : RIGHT) : (by ? TOP : BOTTOM);
1155 *pos[c] = vb_pos[vertical];
1156 edges[c] = 1;
1157 }
1158 }
1159 36675 }
1160
1161 36675 static void alf_get_subblocks(const VVCLocalContext *lc, VVCRect sbs[MAX_VBBS], int sb_edges[MAX_VBBS][MAX_EDGES], int *nb_sbs,
1162 const int x0, const int y0, const int rx, const int ry)
1163 {
1164 36675 VVCFrameContext *fc = lc->fc;
1165 36675 const VVCSPS *sps = fc->ps.sps;
1166 36675 const VVCPPS *pps = fc->ps.pps;
1167 36675 const int ctu_size_y = sps->ctb_size_y;
1168 36675 const int vb_pos[] = { get_virtual_boundary(fc, ry, 0), get_virtual_boundary(fc, rx, 1) };
1169 36675 const int has_vb[] = { vb_pos[0] > y0, vb_pos[1] > x0 };
1170 36675 const VVCRect b = { x0, y0, FFMIN(x0 + ctu_size_y, pps->width), FFMIN(y0 + ctu_size_y, pps->height) };
1171 36675 int edges[MAX_EDGES] = { !rx, !ry, rx == pps->ctb_width - 1, ry == pps->ctb_height - 1 };
1172 36675 int i = 0;
1173
1174 36675 alf_get_edges(lc, edges, rx, ry);
1175
1176
2/2
✓ Branch 0 taken 36675 times.
✓ Branch 1 taken 36675 times.
73350 for (int by = 0; by <= has_vb[0]; by++) {
1177
2/2
✓ Branch 0 taken 36675 times.
✓ Branch 1 taken 36675 times.
73350 for (int bx = 0; bx <= has_vb[1]; bx++, i++) {
1178 36675 alf_init_subblock(sbs + i, sb_edges[i], &b, edges);
1179 36675 alf_get_subblock(sbs + i, sb_edges[i], bx, by, vb_pos, has_vb);
1180 }
1181 }
1182 36675 *nb_sbs = i;
1183 36675 }
1184
1185 36675 void ff_vvc_alf_filter(VVCLocalContext *lc, const int x0, const int y0)
1186 {
1187 36675 VVCFrameContext *fc = lc->fc;
1188 36675 const VVCSPS *sps = fc->ps.sps;
1189 36675 const int rx = x0 >> sps->ctb_log2_size_y;
1190 36675 const int ry = y0 >> sps->ctb_log2_size_y;
1191 36675 const int ps = sps->pixel_shift;
1192 36675 const int padded_stride = EDGE_EMU_BUFFER_STRIDE << ps;
1193 36675 const int padded_offset = padded_stride * ALF_PADDING_SIZE + (ALF_PADDING_SIZE << ps);
1194
2/2
✓ Branch 0 taken 36147 times.
✓ Branch 1 taken 528 times.
36675 const int c_end = sps->r->sps_chroma_format_idc ? VVC_MAX_SAMPLE_ARRAYS : 1;
1195 36675 const int has_chroma = !!sps->r->sps_chroma_format_idc;
1196 36675 const int ctu_end = y0 + sps->ctb_size_y;
1197 36675 const ALFParams *alf = &CTB(fc->tab.alf, rx, ry);
1198 int sb_edges[MAX_VBBS][MAX_EDGES], nb_sbs;
1199 VVCRect sbs[MAX_VBBS];
1200
1201 36675 alf_get_subblocks(lc, sbs, sb_edges, &nb_sbs, x0, y0, rx, ry);
1202
1203
2/2
✓ Branch 0 taken 36675 times.
✓ Branch 1 taken 36675 times.
73350 for (int i = 0; i < nb_sbs; i++) {
1204 36675 const VVCRect *sb = sbs + i;
1205
2/2
✓ Branch 0 taken 108969 times.
✓ Branch 1 taken 36675 times.
145644 for (int c_idx = 0; c_idx < c_end; c_idx++) {
1206 108969 const int hs = fc->ps.sps->hshift[c_idx];
1207 108969 const int vs = fc->ps.sps->vshift[c_idx];
1208 108969 const int x = sb->l >> hs;
1209 108969 const int y = sb->t >> vs;
1210 108969 const int width = (sb->r - sb->l) >> hs;
1211 108969 const int height = (sb->b - sb->t) >> vs;
1212 108969 const int src_stride = fc->frame->linesize[c_idx];
1213 108969 uint8_t *src = POS(c_idx, sb->l, sb->t);
1214 uint8_t *padded;
1215
1216
10/10
✓ Branch 0 taken 65209 times.
✓ Branch 1 taken 43760 times.
✓ Branch 2 taken 17120 times.
✓ Branch 3 taken 48089 times.
✓ Branch 4 taken 16950 times.
✓ Branch 5 taken 170 times.
✓ Branch 6 taken 16414 times.
✓ Branch 7 taken 536 times.
✓ Branch 8 taken 99 times.
✓ Branch 9 taken 16315 times.
108969 if (alf->ctb_flag[c_idx] || (!c_idx && has_chroma && (alf->ctb_cc_idc[0] || alf->ctb_cc_idc[1]))) {
1217
2/2
✓ Branch 0 taken 24205 times.
✓ Branch 1 taken 20190 times.
44395 padded = (c_idx ? lc->alf_buffer_chroma : lc->alf_buffer_luma) + padded_offset;
1218 44395 alf_prepare_buffer(fc, padded, src, x, y, rx, ry, width, height,
1219 44395 padded_stride, src_stride, c_idx, sb_edges[i]);
1220 }
1221
2/2
✓ Branch 0 taken 43760 times.
✓ Branch 1 taken 65209 times.
108969 if (alf->ctb_flag[c_idx]) {
1222
2/2
✓ Branch 0 taken 19555 times.
✓ Branch 1 taken 24205 times.
43760 if (!c_idx) {
1223 19555 alf_filter_luma(lc, src, padded, src_stride, padded_stride, x, y,
1224 width, height, ctu_end - ALF_VB_POS_ABOVE_LUMA, alf);
1225 } else {
1226 24205 alf_filter_chroma(lc, src, padded, src_stride, padded_stride, c_idx,
1227 24205 width, height, ((ctu_end - sb->t) >> vs) - ALF_VB_POS_ABOVE_CHROMA, alf);
1228 }
1229 }
1230
4/4
✓ Branch 0 taken 72294 times.
✓ Branch 1 taken 36675 times.
✓ Branch 2 taken 10527 times.
✓ Branch 3 taken 61767 times.
108969 if (c_idx && alf->ctb_cc_idc[c_idx - 1]) {
1231 10527 padded = lc->alf_buffer_luma + padded_offset;
1232 10527 alf_filter_cc(lc, src, padded, src_stride, padded_stride, c_idx,
1233 10527 width, height, hs, vs, ctu_end - sb->t - ALF_VB_POS_ABOVE_LUMA, alf);
1234 }
1235 }
1236 }
1237 36675 }
1238
1239
1240 46713 void ff_vvc_lmcs_filter(const VVCLocalContext *lc, const int x, const int y)
1241 {
1242 46713 const SliceContext *sc = lc->sc;
1243 46713 const VVCFrameContext *fc = lc->fc;
1244 46713 const int ctb_size = fc->ps.sps->ctb_size_y;
1245 46713 const int width = FFMIN(fc->ps.pps->width - x, ctb_size);
1246 46713 const int height = FFMIN(fc->ps.pps->height - y, ctb_size);
1247 46713 uint8_t *data = POS(LUMA, x, y);
1248
2/2
✓ Branch 0 taken 19694 times.
✓ Branch 1 taken 27019 times.
46713 if (sc->sh.r->sh_lmcs_used_flag)
1249 19694 fc->vvcdsp.lmcs.filter(data, fc->frame->linesize[LUMA], width, height, &fc->ps.lmcs.inv_lut);
1250 46713 }
1251