FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/vvc/filter.c
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 714 755 94.6%
Functions: 50 51 98.0%
Branches: 559 633 88.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 3984669 static int get_virtual_boundary(const VVCFrameContext *fc, const int ctu_pos, const int vertical)
63 {
64 3984669 const VVCSPS *sps = fc->ps.sps;
65 3984669 const VVCPH *ph = &fc->ps.ph;
66
2/2
✓ Branch 0 taken 2017492 times.
✓ Branch 1 taken 1967177 times.
3984669 const uint16_t *vbs = vertical ? ph->vb_pos_x : ph->vb_pos_y;
67
2/2
✓ Branch 0 taken 2017492 times.
✓ Branch 1 taken 1967177 times.
3984669 const uint8_t nb_vbs = vertical ? ph->num_ver_vbs : ph->num_hor_vbs;
68 3984669 const int pos = ctu_pos << sps->ctb_log2_size_y;
69
70
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3984669 times.
3984669 if (sps->r->sps_virtual_boundaries_enabled_flag) {
71 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 3984669 return 0;
78 }
79
80 3913161 static int is_virtual_boundary(const VVCFrameContext *fc, const int pos, const int vertical)
81 {
82 3913161 return get_virtual_boundary(fc, pos >> fc->ps.sps->ctb_log2_size_y, vertical) == pos;
83 }
84
85 7622550 static int get_qPc(const VVCFrameContext *fc, const int x0, const int y0, const int chroma)
86 {
87 7622550 const int x = x0 >> MIN_TU_LOG2;
88 7622550 const int y = y0 >> MIN_TU_LOG2;
89 7622550 const int min_tu_width = fc->ps.pps->min_tu_width;
90 7622550 return fc->tab.qp[chroma][x + y * min_tu_width];
91 }
92
93 50855 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 4922620 times.
✓ Branch 1 taken 50855 times.
4973475 for (int y = 0; y < height; y++) {
97 4922620 memcpy(dst, src, width);
98
99 4922620 dst += dst_stride;
100 4922620 src += src_stride;
101 }
102 50855 }
103
104 25321 static void copy_pixel(uint8_t *dst, const uint8_t *src, const int pixel_shift)
105 {
106
2/2
✓ Branch 0 taken 23105 times.
✓ Branch 1 taken 2216 times.
25321 if (pixel_shift)
107 23105 *(uint16_t *)dst = *(uint16_t *)src;
108 else
109 2216 *dst = *src;
110 25321 }
111
112 285284 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 276541 times.
285284 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 25810768 times.
✓ Branch 1 taken 276541 times.
26087309 for (i = 0; i < height; i++) {
124 25810768 *(uint16_t *)dst = *(uint16_t *)src;
125 25810768 dst += dst_stride;
126 25810768 src += src_stride;
127 }
128 }
129 285284 }
130
131 270120 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 270120 const int ps = fc->ps.sps->pixel_shift;
136 270120 const int w = fc->ps.pps->width >> fc->ps.sps->hshift[c_idx];
137 270120 const int h = fc->ps.pps->height >> fc->ps.sps->vshift[c_idx];
138
139
2/2
✓ Branch 0 taken 135060 times.
✓ Branch 1 taken 135060 times.
270120 if (top) {
140 /* top */
141 135060 memcpy(fc->tab.sao_pixel_buffer_h[c_idx] + (((2 * ry) * w + x) << ps),
142 135060 src, width << ps);
143 } else {
144 /* bottom */
145 135060 memcpy(fc->tab.sao_pixel_buffer_h[c_idx] + (((2 * ry + 1) * w + x) << ps),
146 135060 src + src_stride * (height - 1), width << ps);
147
148 /* copy vertical edges */
149 135060 copy_vert(fc->tab.sao_pixel_buffer_v[c_idx] + (((2 * rx) * h + y) << ps), src, ps, height, 1 << ps, src_stride);
150 135060 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 270120 }
153
154 90744 static void sao_copy_ctb_to_hv(VVCLocalContext *lc, const int rx, const int ry, const int top)
155 {
156 90744 VVCFrameContext *fc = lc->fc;
157 90744 const int ctb_size_y = fc->ps.sps->ctb_size_y;
158 90744 const int x0 = rx << fc->ps.sps->ctb_log2_size_y;
159 90744 const int y0 = ry << fc->ps.sps->ctb_log2_size_y;
160
161
4/4
✓ Branch 0 taken 358752 times.
✓ Branch 1 taken 2112 times.
✓ Branch 2 taken 270120 times.
✓ Branch 3 taken 90744 times.
360864 for (int c_idx = 0; c_idx < (fc->ps.sps->r->sps_chroma_format_idc ? 3 : 1); c_idx++) {
162 270120 const int x = x0 >> fc->ps.sps->hshift[c_idx];
163 270120 const int y = y0 >> fc->ps.sps->vshift[c_idx];
164 270120 const ptrdiff_t src_stride = fc->frame->linesize[c_idx];
165 270120 const int ctb_size_h = ctb_size_y >> fc->ps.sps->hshift[c_idx];
166 270120 const int ctb_size_v = ctb_size_y >> fc->ps.sps->vshift[c_idx];
167 270120 const int width = FFMIN(ctb_size_h, (fc->ps.pps->width >> fc->ps.sps->hshift[c_idx]) - x);
168 270120 const int height = FFMIN(ctb_size_v, (fc->ps.pps->height >> fc->ps.sps->vshift[c_idx]) - y);
169 270120 const uint8_t *src = POS(c_idx, x0, y0);
170 270120 copy_ctb_to_hv(fc, src, src_stride, x, y, width, height, c_idx, rx, ry, top);
171 }
172 90744 }
173
174 45372 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 38180 times.
✓ Branch 1 taken 7192 times.
45372 if (ry)
177 38180 sao_copy_ctb_to_hv(lc, rx, ry - 1, 0);
178
179 45372 sao_copy_ctb_to_hv(lc, rx, ry, 1);
180
181
2/2
✓ Branch 0 taken 7192 times.
✓ Branch 1 taken 38180 times.
45372 if (last_row)
182 7192 sao_copy_ctb_to_hv(lc, rx, ry, 0);
183 45372 }
184
185 278394 static int sao_can_cross_slices(const VVCFrameContext *fc, const int rx, const int ry, const int dx, const int dy)
186 {
187 278394 const uint8_t lfase = fc->ps.pps->r->pps_loop_filter_across_slices_enabled_flag;
188
189
3/4
✓ Branch 0 taken 278394 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 276102 times.
✓ Branch 3 taken 2292 times.
278394 return lfase || CTB(fc->tab.slice_idx, rx, ry) == CTB(fc->tab.slice_idx, rx + dx, ry + dy);
190 }
191
192 45372 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 45372 const VVCFrameContext *fc = lc->fc;
196 45372 const VVCSPS *sps = fc->ps.sps;
197 45372 const H266RawSPS *rsps = sps->r;
198 45372 const VVCPPS *pps = fc->ps.pps;
199 45372 const int subpic_idx = lc->sc->sh.r->curr_subpic_idx;
200 45372 const uint8_t lfase = fc->ps.pps->r->pps_loop_filter_across_slices_enabled_flag;
201
4/4
✓ Branch 0 taken 4044 times.
✓ Branch 1 taken 41328 times.
✓ Branch 2 taken 1074 times.
✓ Branch 3 taken 2970 times.
45372 const uint8_t no_tile_filter = pps->r->num_tiles_in_pic > 1 && !pps->r->pps_loop_filter_across_tiles_enabled_flag;
202
3/4
✓ Branch 0 taken 1074 times.
✓ Branch 1 taken 44298 times.
✓ Branch 2 taken 1074 times.
✗ Branch 3 not taken.
45372 const uint8_t no_subpic_filter = rsps->sps_num_subpics_minus1 && !rsps->sps_loop_filter_across_subpic_enabled_flag[subpic_idx];
203 45372 uint8_t lf_edge[] = { 0, 0, 0, 0 };
204
205
6/8
✓ Branch 0 taken 44298 times.
✓ Branch 1 taken 1074 times.
✓ Branch 2 taken 44298 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2970 times.
✓ Branch 5 taken 41328 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2970 times.
45372 *restore = no_subpic_filter || no_tile_filter || !lfase || rsps->sps_virtual_boundaries_enabled_flag;
206
207
2/2
✓ Branch 0 taken 2970 times.
✓ Branch 1 taken 42402 times.
45372 if (!*restore)
208 2970 return;
209
210
2/2
✓ Branch 0 taken 38521 times.
✓ Branch 1 taken 3881 times.
42402 if (!edges[LEFT]) {
211
4/4
✓ Branch 0 taken 954 times.
✓ Branch 1 taken 37567 times.
✓ Branch 2 taken 360 times.
✓ Branch 3 taken 594 times.
38521 lf_edge[LEFT] = no_tile_filter && pps->ctb_to_col_bd[rx] == rx;
212
4/4
✓ Branch 0 taken 954 times.
✓ Branch 1 taken 37567 times.
✓ Branch 2 taken 288 times.
✓ Branch 3 taken 666 times.
38521 lf_edge[LEFT] |= no_subpic_filter && rsps->sps_subpic_ctu_top_left_x[subpic_idx] == rx;
213 38521 lf_edge[LEFT] |= is_virtual_boundary(fc, rx << sps->ctb_log2_size_y, 1);
214
4/4
✓ Branch 1 taken 38233 times.
✓ Branch 2 taken 288 times.
✓ Branch 3 taken 72 times.
✓ Branch 4 taken 38161 times.
38521 vert_edge[0] = !sao_can_cross_slices(fc, rx, ry, -1, 0) || lf_edge[LEFT];
215 }
216
2/2
✓ Branch 0 taken 38521 times.
✓ Branch 1 taken 3881 times.
42402 if (!edges[RIGHT]) {
217
4/4
✓ Branch 0 taken 954 times.
✓ Branch 1 taken 37567 times.
✓ Branch 2 taken 360 times.
✓ Branch 3 taken 594 times.
38521 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 954 times.
✓ Branch 1 taken 37567 times.
✓ Branch 2 taken 288 times.
✓ Branch 3 taken 666 times.
38521 lf_edge[RIGHT] |= no_subpic_filter && rsps->sps_subpic_ctu_top_left_x[subpic_idx] + rsps->sps_subpic_width_minus1[subpic_idx] == rx;
219 38521 lf_edge[RIGHT] |= is_virtual_boundary(fc, (rx + 1) << sps->ctb_log2_size_y, 1);
220
4/4
✓ Branch 1 taken 38233 times.
✓ Branch 2 taken 288 times.
✓ Branch 3 taken 72 times.
✓ Branch 4 taken 38161 times.
38521 vert_edge[1] = !sao_can_cross_slices(fc, rx, ry, 1, 0) || lf_edge[RIGHT];
221 }
222
2/2
✓ Branch 0 taken 35540 times.
✓ Branch 1 taken 6862 times.
42402 if (!edges[TOP]) {
223
4/4
✓ Branch 0 taken 852 times.
✓ Branch 1 taken 34688 times.
✓ Branch 2 taken 312 times.
✓ Branch 3 taken 540 times.
35540 lf_edge[TOP] = no_tile_filter && pps->ctb_to_row_bd[ry] == ry;
224
4/4
✓ Branch 0 taken 852 times.
✓ Branch 1 taken 34688 times.
✓ Branch 2 taken 222 times.
✓ Branch 3 taken 630 times.
35540 lf_edge[TOP] |= no_subpic_filter && rsps->sps_subpic_ctu_top_left_y[subpic_idx] == ry;
225 35540 lf_edge[TOP] |= is_virtual_boundary(fc, ry << sps->ctb_log2_size_y, 0);
226
4/4
✓ Branch 1 taken 35264 times.
✓ Branch 2 taken 276 times.
✓ Branch 3 taken 72 times.
✓ Branch 4 taken 35192 times.
35540 horiz_edge[0] = !sao_can_cross_slices(fc, rx, ry, 0, -1) || lf_edge[TOP];
227 }
228
2/2
✓ Branch 0 taken 35540 times.
✓ Branch 1 taken 6862 times.
42402 if (!edges[BOTTOM]) {
229
4/4
✓ Branch 0 taken 852 times.
✓ Branch 1 taken 34688 times.
✓ Branch 2 taken 312 times.
✓ Branch 3 taken 540 times.
35540 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 852 times.
✓ Branch 1 taken 34688 times.
✓ Branch 2 taken 222 times.
✓ Branch 3 taken 630 times.
35540 lf_edge[BOTTOM] |= no_subpic_filter && rsps->sps_subpic_ctu_top_left_y[subpic_idx] + rsps->sps_subpic_height_minus1[subpic_idx] == ry;
231 35540 lf_edge[BOTTOM] |= is_virtual_boundary(fc, (ry + 1) << sps->ctb_log2_size_y, 0);
232
4/4
✓ Branch 1 taken 35264 times.
✓ Branch 2 taken 276 times.
✓ Branch 3 taken 72 times.
✓ Branch 4 taken 35192 times.
35540 horiz_edge[1] = !sao_can_cross_slices(fc, rx, ry, 0, 1) || lf_edge[BOTTOM];
233 }
234
235
4/4
✓ Branch 0 taken 38521 times.
✓ Branch 1 taken 3881 times.
✓ Branch 2 taken 32568 times.
✓ Branch 3 taken 5953 times.
42402 if (!edges[LEFT] && !edges[TOP])
236
6/6
✓ Branch 1 taken 32277 times.
✓ Branch 2 taken 291 times.
✓ Branch 3 taken 32223 times.
✓ Branch 4 taken 54 times.
✓ Branch 5 taken 54 times.
✓ Branch 6 taken 32169 times.
32568 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 35540 times.
✓ Branch 1 taken 6862 times.
✓ Branch 2 taken 32568 times.
✓ Branch 3 taken 2972 times.
42402 if (!edges[TOP] && !edges[RIGHT])
239
6/6
✓ Branch 1 taken 32277 times.
✓ Branch 2 taken 291 times.
✓ Branch 3 taken 32223 times.
✓ Branch 4 taken 54 times.
✓ Branch 5 taken 54 times.
✓ Branch 6 taken 32169 times.
32568 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 38521 times.
✓ Branch 1 taken 3881 times.
✓ Branch 2 taken 32568 times.
✓ Branch 3 taken 5953 times.
42402 if (!edges[RIGHT] && !edges[BOTTOM])
242
6/6
✓ Branch 1 taken 32277 times.
✓ Branch 2 taken 291 times.
✓ Branch 3 taken 32223 times.
✓ Branch 4 taken 54 times.
✓ Branch 5 taken 54 times.
✓ Branch 6 taken 32169 times.
32568 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 38521 times.
✓ Branch 1 taken 3881 times.
✓ Branch 2 taken 32568 times.
✓ Branch 3 taken 5953 times.
42402 if (!edges[LEFT] && !edges[BOTTOM])
245
6/6
✓ Branch 1 taken 32277 times.
✓ Branch 2 taken 291 times.
✓ Branch 3 taken 32223 times.
✓ Branch 4 taken 54 times.
✓ Branch 5 taken 54 times.
✓ Branch 6 taken 32169 times.
32568 diag_edge[3] = !sao_can_cross_slices(fc, rx, ry, -1, 1) || lf_edge[LEFT] || lf_edge[BOTTOM];
246 }
247
248 13668 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 13668 const int left = 1 - edges[LEFT];
252 13668 const int right = 1 - edges[RIGHT];
253 13668 int pos = 0;
254
255 13668 src -= left << ps;
256 13668 dst -= left << ps;
257
258
2/2
✓ Branch 0 taken 12628 times.
✓ Branch 1 taken 1040 times.
13668 if (left) {
259 12628 copy_pixel(dst, src, ps);
260 12628 pos += (1 << ps);
261 }
262 13668 memcpy(dst + pos, src + pos, width << ps);
263
2/2
✓ Branch 0 taken 12693 times.
✓ Branch 1 taken 975 times.
13668 if (right) {
264 12693 pos += width << ps;
265 12693 copy_pixel(dst + pos, src + pos, ps);
266 }
267 13668 }
268
269 8294 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 8294 const uint8_t *sao_h = fc->tab.sao_pixel_buffer_h[c_idx];
274 8294 const uint8_t *sao_v = fc->tab.sao_pixel_buffer_v[c_idx];
275 8294 const int x = x0 >> fc->ps.sps->hshift[c_idx];
276 8294 const int y = y0 >> fc->ps.sps->vshift[c_idx];
277 8294 const int w = fc->ps.pps->width >> fc->ps.sps->hshift[c_idx];
278 8294 const int h = fc->ps.pps->height >> fc->ps.sps->vshift[c_idx];
279 8294 const int ps = fc->ps.sps->pixel_shift;
280
281
2/2
✓ Branch 0 taken 6846 times.
✓ Branch 1 taken 1448 times.
8294 if (!edges[TOP])
282 6846 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 6822 times.
✓ Branch 1 taken 1472 times.
8294 if (!edges[BOTTOM])
285 6822 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 7576 times.
✓ Branch 1 taken 718 times.
8294 if (!edges[LEFT])
288 7576 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 7588 times.
✓ Branch 1 taken 706 times.
8294 if (!edges[RIGHT])
291 7588 copy_vert(dst + (width << ps), sao_v + (((2 * rx + 2) * h + y) << ps), ps, height, dst_stride, 1 << ps);
292
293 8294 copy_ctb(dst, src, width << ps, height, dst_stride, src_stride);
294 8294 }
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 45372 void ff_vvc_sao_filter(VVCLocalContext *lc, int x0, int y0)
315 {
316 45372 VVCFrameContext *fc = lc->fc;
317 45372 const VVCSPS *sps = fc->ps.sps;
318 45372 const int rx = x0 >> sps->ctb_log2_size_y;
319 45372 const int ry = y0 >> sps->ctb_log2_size_y;
320 45372 const int edges[4] = { !rx, !ry, rx == fc->ps.pps->ctb_width - 1, ry == fc->ps.pps->ctb_height - 1 };
321 45372 const SAOParams *sao = &CTB(fc->tab.sao, rx, ry);
322 // flags indicating unfilterable edges
323 45372 uint8_t vert_edge[] = { 0, 0 };
324 45372 uint8_t horiz_edge[] = { 0, 0 };
325 45372 uint8_t diag_edge[] = { 0, 0, 0, 0 };
326 45372 int restore, vb_x = 0, vb_y = 0;;
327
328
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45372 times.
45372 if (sps->r->sps_virtual_boundaries_enabled_flag) {
329 vb_x = get_virtual_boundary(fc, rx, 1);
330 vb_y = get_virtual_boundary(fc, ry, 0);
331 }
332
333 45372 sao_get_edges(vert_edge, horiz_edge, diag_edge, &restore, lc, edges, rx, ry);
334
335
4/4
✓ Branch 0 taken 179376 times.
✓ Branch 1 taken 1056 times.
✓ Branch 2 taken 135060 times.
✓ Branch 3 taken 45372 times.
180432 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 135060 const ptrdiff_t src_stride = fc->frame->linesize[c_idx];
338 135060 uint8_t *src = POS(c_idx, x0, y0);
339 135060 const int hs = sps->hshift[c_idx];
340 135060 const int vs = sps->vshift[c_idx];
341 135060 const int ps = sps->pixel_shift;
342 135060 const int width = FFMIN(sps->ctb_size_y, fc->ps.pps->width - x0) >> hs;
343 135060 const int height = FFMIN(sps->ctb_size_y, fc->ps.pps->height - y0) >> vs;
344 135060 const int tab = sao_tab[(FFALIGN(width, 8) >> 3) - 1];
345 135060 const int sao_eo_class = sao->eo_class[c_idx];
346
347
3/3
✓ Branch 0 taken 4914 times.
✓ Branch 1 taken 8294 times.
✓ Branch 2 taken 121852 times.
135060 switch (sao->type_idx[c_idx]) {
348 4914 case SAO_BAND:
349 4914 fc->vvcdsp.sao.band_filter[tab](src, src, src_stride, src_stride,
350 4914 sao->offset_val[c_idx], sao->band_position[c_idx], width, height);
351 4914 break;
352 8294 case SAO_EDGE:
353 {
354 8294 const ptrdiff_t dst_stride = 2 * MAX_PB_SIZE + AV_INPUT_BUFFER_PADDING_SIZE;
355 8294 uint8_t *dst = lc->sao_buffer + dst_stride + AV_INPUT_BUFFER_PADDING_SIZE;
356
357 8294 sao_extends_edges(dst, dst_stride, src, src_stride, width, height, fc, x0, y0, rx, ry, edges, c_idx);
358
359 8294 fc->vvcdsp.sao.edge_filter[tab](src, dst, src_stride, sao->offset_val[c_idx],
360 8294 sao->eo_class[c_idx], width, height);
361 8294 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 8294 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
8294 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 8294 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
8294 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 8294 break;
370 }
371 }
372 }
373 45372 }
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 9424967 static int boundary_strength(const VVCLocalContext *lc, const MvField *curr, const MvField *neigh,
384 const RefPicList *neigh_rpl)
385 {
386 9424967 RefPicList *rpl = lc->sc->rpl;
387
388
2/2
✓ Branch 0 taken 1752 times.
✓ Branch 1 taken 9423215 times.
9424967 if (curr->pred_flag == PF_IBC)
389
4/4
✓ Branch 0 taken 685 times.
✓ Branch 1 taken 1067 times.
✓ Branch 2 taken 20 times.
✓ Branch 3 taken 665 times.
1752 return FFABS(neigh->mv[0].x - curr->mv[0].x) >= 8 || FFABS(neigh->mv[0].y - curr->mv[0].y) >= 8;
390
391
4/4
✓ Branch 0 taken 4549413 times.
✓ Branch 1 taken 4873802 times.
✓ Branch 2 taken 4240392 times.
✓ Branch 3 taken 309021 times.
9423215 if (curr->pred_flag == PF_BI && neigh->pred_flag == PF_BI) {
392 // same L0 and L1
393
2/2
✓ Branch 0 taken 4164828 times.
✓ Branch 1 taken 75564 times.
4240392 if (rpl[L0].refs[curr->ref_idx[L0]].poc == neigh_rpl[L0].refs[neigh->ref_idx[L0]].poc &&
394
2/2
✓ Branch 0 taken 447249 times.
✓ Branch 1 taken 3717579 times.
4164828 rpl[L0].refs[curr->ref_idx[L0]].poc == rpl[L1].refs[curr->ref_idx[L1]].poc &&
395
2/2
✓ Branch 0 taken 443871 times.
✓ Branch 1 taken 3378 times.
447249 neigh_rpl[L0].refs[neigh->ref_idx[L0]].poc == neigh_rpl[L1].refs[neigh->ref_idx[L1]].poc) {
396
4/4
✓ Branch 0 taken 397903 times.
✓ Branch 1 taken 45968 times.
✓ Branch 2 taken 372771 times.
✓ Branch 3 taken 25132 times.
443871 if ((FFABS(neigh->mv[0].x - curr->mv[0].x) >= 8 || FFABS(neigh->mv[0].y - curr->mv[0].y) >= 8 ||
397
4/4
✓ Branch 0 taken 369201 times.
✓ Branch 1 taken 3570 times.
✓ Branch 2 taken 3009 times.
✓ Branch 3 taken 366192 times.
372771 FFABS(neigh->mv[1].x - curr->mv[1].x) >= 8 || FFABS(neigh->mv[1].y - curr->mv[1].y) >= 8) &&
398
4/4
✓ Branch 0 taken 19046 times.
✓ Branch 1 taken 58633 times.
✓ Branch 2 taken 4669 times.
✓ Branch 3 taken 14377 times.
77679 (FFABS(neigh->mv[1].x - curr->mv[0].x) >= 8 || FFABS(neigh->mv[1].y - curr->mv[0].y) >= 8 ||
399
4/4
✓ Branch 0 taken 2403 times.
✓ Branch 1 taken 2266 times.
✓ Branch 2 taken 1896 times.
✓ Branch 3 taken 507 times.
4669 FFABS(neigh->mv[0].x - curr->mv[1].x) >= 8 || FFABS(neigh->mv[0].y - curr->mv[1].y) >= 8))
400 77172 return 1;
401 else
402 366699 return 0;
403
2/2
✓ Branch 0 taken 3720957 times.
✓ Branch 1 taken 75564 times.
3796521 } else if (neigh_rpl[L0].refs[neigh->ref_idx[L0]].poc == rpl[L0].refs[curr->ref_idx[L0]].poc &&
404
2/2
✓ Branch 0 taken 3702331 times.
✓ Branch 1 taken 18626 times.
3720957 neigh_rpl[L1].refs[neigh->ref_idx[L1]].poc == rpl[L1].refs[curr->ref_idx[L1]].poc) {
405
4/4
✓ Branch 0 taken 3176844 times.
✓ Branch 1 taken 525487 times.
✓ Branch 2 taken 3023547 times.
✓ Branch 3 taken 153297 times.
3702331 if (FFABS(neigh->mv[0].x - curr->mv[0].x) >= 8 || FFABS(neigh->mv[0].y - curr->mv[0].y) >= 8 ||
406
4/4
✓ Branch 0 taken 2991584 times.
✓ Branch 1 taken 31963 times.
✓ Branch 2 taken 20356 times.
✓ Branch 3 taken 2971228 times.
3023547 FFABS(neigh->mv[1].x - curr->mv[1].x) >= 8 || FFABS(neigh->mv[1].y - curr->mv[1].y) >= 8)
407 731103 return 1;
408 else
409 2971228 return 0;
410
2/2
✓ Branch 0 taken 26495 times.
✓ Branch 1 taken 67695 times.
94190 } else if (neigh_rpl[L1].refs[neigh->ref_idx[L1]].poc == rpl[L0].refs[curr->ref_idx[L0]].poc &&
411
2/2
✓ Branch 0 taken 8266 times.
✓ Branch 1 taken 18229 times.
26495 neigh_rpl[L0].refs[neigh->ref_idx[L0]].poc == rpl[L1].refs[curr->ref_idx[L1]].poc) {
412
4/4
✓ Branch 0 taken 2928 times.
✓ Branch 1 taken 5338 times.
✓ Branch 2 taken 1135 times.
✓ Branch 3 taken 1793 times.
8266 if (FFABS(neigh->mv[1].x - curr->mv[0].x) >= 8 || FFABS(neigh->mv[1].y - curr->mv[0].y) >= 8 ||
413
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)
414 7622 return 1;
415 else
416 644 return 0;
417 } else {
418 85924 return 1;
419 }
420
4/4
✓ Branch 0 taken 4873802 times.
✓ Branch 1 taken 309021 times.
✓ Branch 2 taken 4568327 times.
✓ Branch 3 taken 305475 times.
5182823 } else if ((curr->pred_flag != PF_BI) && (neigh->pred_flag != PF_BI)){ // 1 MV
421 Mv A, B;
422 int ref_A, ref_B;
423
424
2/2
✓ Branch 0 taken 3740653 times.
✓ Branch 1 taken 827674 times.
4568327 if (curr->pred_flag & 1) {
425 3740653 A = curr->mv[0];
426 3740653 ref_A = rpl[L0].refs[curr->ref_idx[L0]].poc;
427 } else {
428 827674 A = curr->mv[1];
429 827674 ref_A = rpl[L1].refs[curr->ref_idx[L1]].poc;
430 }
431
432
2/2
✓ Branch 0 taken 3738665 times.
✓ Branch 1 taken 829662 times.
4568327 if (neigh->pred_flag & 1) {
433 3738665 B = neigh->mv[0];
434 3738665 ref_B = neigh_rpl[L0].refs[neigh->ref_idx[L0]].poc;
435 } else {
436 829662 B = neigh->mv[1];
437 829662 ref_B = neigh_rpl[L1].refs[neigh->ref_idx[L1]].poc;
438 }
439
440
2/2
✓ Branch 0 taken 4460088 times.
✓ Branch 1 taken 108239 times.
4568327 if (ref_A == ref_B) {
441
4/4
✓ Branch 0 taken 4121736 times.
✓ Branch 1 taken 338352 times.
✓ Branch 2 taken 151559 times.
✓ Branch 3 taken 3970177 times.
4460088 if (FFABS(A.x - B.x) >= 8 || FFABS(A.y - B.y) >= 8)
442 489911 return 1;
443 else
444 3970177 return 0;
445 } else
446 108239 return 1;
447 }
448
449 614496 return 1;
450 }
451
452 //part of 8.8.3.3 Derivation process of transform block boundary
453 10107424 static void derive_max_filter_length_luma(const VVCFrameContext *fc, const int qx, const int qy,
454 const int size_q, const int has_subblock, const int vertical, uint8_t *max_len_p, uint8_t *max_len_q)
455 {
456
2/2
✓ Branch 0 taken 4842614 times.
✓ Branch 1 taken 5264810 times.
10107424 const int px = vertical ? qx - 1 : qx;
457
2/2
✓ Branch 0 taken 5264810 times.
✓ Branch 1 taken 4842614 times.
10107424 const int py = !vertical ? qy - 1 : qy;
458
2/2
✓ Branch 0 taken 4842614 times.
✓ Branch 1 taken 5264810 times.
10107424 const uint8_t *tb_size = vertical ? fc->tab.tb_width[LUMA] : fc->tab.tb_height[LUMA];
459 10107424 const int size_p = tb_size[(py >> MIN_TU_LOG2) * fc->ps.pps->min_tu_width + (px >> MIN_TU_LOG2)];
460 10107424 const int min_cb_log2 = fc->ps.sps->min_cb_log2_size_y;
461 10107424 const int off_p = (py >> min_cb_log2) * fc->ps.pps->min_cb_width + (px >> min_cb_log2);
462
463
4/4
✓ Branch 0 taken 8566651 times.
✓ Branch 1 taken 1540773 times.
✓ Branch 2 taken 692844 times.
✓ Branch 3 taken 7873807 times.
10107424 if (size_p <= 4 || size_q <= 4) {
464 2233617 *max_len_p = *max_len_q = 1;
465 } else {
466 7873807 *max_len_p = *max_len_q = 3;
467
2/2
✓ Branch 0 taken 4972737 times.
✓ Branch 1 taken 2901070 times.
7873807 if (size_p >= 32)
468 4972737 *max_len_p = 7;
469
2/2
✓ Branch 0 taken 4829148 times.
✓ Branch 1 taken 3044659 times.
7873807 if (size_q >= 32)
470 4829148 *max_len_q = 7;
471 }
472
2/2
✓ Branch 0 taken 1044984 times.
✓ Branch 1 taken 9062440 times.
10107424 if (has_subblock)
473 1044984 *max_len_q = FFMIN(5, *max_len_q);
474
4/4
✓ Branch 0 taken 9165508 times.
✓ Branch 1 taken 941916 times.
✓ Branch 2 taken 220759 times.
✓ Branch 3 taken 8944749 times.
10107424 if (fc->tab.msf[off_p] || fc->tab.iaf[off_p])
475 1162675 *max_len_p = FFMIN(5, *max_len_p);
476 10107424 }
477
478 119972 static void vvc_deblock_subblock_bs(const VVCLocalContext *lc,
479 const int cb, int x0, int y0, int width, int height, const int vertical)
480 {
481 119972 const VVCFrameContext *fc = lc->fc;
482 119972 const MvField *tab_mvf = fc->tab.mvf;
483 119972 const RefPicList *rpl = lc->sc->rpl;
484 119972 int stridea = fc->ps.pps->min_pu_width;
485 119972 int strideb = 1;
486 119972 const int log2_min_pu_size = MIN_PU_LOG2;
487
488
2/2
✓ Branch 0 taken 60713 times.
✓ Branch 1 taken 59259 times.
119972 if (!vertical) {
489 60713 FFSWAP(int, x0, y0);
490 60713 FFSWAP(int, width, height);
491 60713 FFSWAP(int, stridea, strideb);
492 }
493
494 // bs for TU internal vertical PU boundaries
495
2/2
✓ Branch 0 taken 464710 times.
✓ Branch 1 taken 119972 times.
584682 for (int i = 8 - ((x0 - cb) % 8); i < width; i += 8) {
496 464710 const int is_vb = is_virtual_boundary(fc, x0 + i, vertical);
497 464710 const int xp_pu = (x0 + i - 1) >> log2_min_pu_size;
498 464710 const int xq_pu = (x0 + i) >> log2_min_pu_size;
499
500
2/2
✓ Branch 0 taken 5333414 times.
✓ Branch 1 taken 464710 times.
5798124 for (int j = 0; j < height; j += 4) {
501 5333414 const int y_pu = (y0 + j) >> log2_min_pu_size;
502 5333414 const MvField *mvf_p = &tab_mvf[y_pu * stridea + xp_pu * strideb];
503 5333414 const MvField *mvf_q = &tab_mvf[y_pu * stridea + xq_pu * strideb];
504
1/2
✓ Branch 0 taken 5333414 times.
✗ Branch 1 not taken.
5333414 const int bs = is_vb ? 0 : boundary_strength(lc, mvf_q, mvf_p, rpl);
505 5333414 int x = x0 + i;
506 5333414 int y = y0 + j;
507 5333414 uint8_t max_len_p = 0, max_len_q = 0;
508
509
2/2
✓ Branch 0 taken 2654964 times.
✓ Branch 1 taken 2678450 times.
5333414 if (!vertical)
510 2654964 FFSWAP(int, x, y);
511
512 5333414 TAB_BS(fc->tab.bs[vertical][LUMA], x, y) = bs;
513
514
4/4
✓ Branch 0 taken 5332234 times.
✓ Branch 1 taken 1180 times.
✓ Branch 2 taken 1480 times.
✓ Branch 3 taken 5330754 times.
5333414 if (i == 4 || i == width - 4)
515 2660 max_len_p = max_len_q = 1;
516
4/4
✓ Branch 0 taken 4254290 times.
✓ Branch 1 taken 1076464 times.
✓ Branch 2 taken 863550 times.
✓ Branch 3 taken 3390740 times.
5330754 else if (i == 8 || i == width - 8)
517 1940014 max_len_p = max_len_q = 2;
518 else
519 3390740 max_len_p = max_len_q = 3;
520
521 5333414 TAB_MAX_LEN(fc->tab.max_len_p[vertical], x, y) = max_len_p;
522 5333414 TAB_MAX_LEN(fc->tab.max_len_q[vertical], x, y) = max_len_q;
523 }
524 }
525 119972 }
526
527 39037072 static av_always_inline int deblock_bs(const VVCLocalContext *lc,
528 const int x_p, const int y_p, const int x_q, const int y_q, const CodingUnit *cu, const TransformUnit *tu,
529 const RefPicList *rpl_p, const int c_idx, const int off_to_cb, const uint8_t has_sub_block)
530 {
531 39037072 const VVCFrameContext *fc = lc->fc;
532 39037072 const MvField *tab_mvf = fc->tab.mvf;
533 39037072 const int log2_min_pu_size = MIN_PU_LOG2;
534 39037072 const int log2_min_tu_size = MIN_TU_LOG2;
535 39037072 const int log2_min_cb_size = fc->ps.sps->min_cb_log2_size_y;
536 39037072 const int min_pu_width = fc->ps.pps->min_pu_width;
537 39037072 const int min_tu_width = fc->ps.pps->min_tu_width;
538 39037072 const int min_cb_width = fc->ps.pps->min_cb_width;
539 39037072 const int pu_p = (y_p >> log2_min_pu_size) * min_pu_width + (x_p >> log2_min_pu_size);
540 39037072 const int pu_q = (y_q >> log2_min_pu_size) * min_pu_width + (x_q >> log2_min_pu_size);
541 39037072 const MvField *mvf_p = &tab_mvf[pu_p];
542 39037072 const MvField *mvf_q = &tab_mvf[pu_q];
543 39037072 const uint8_t chroma = !!c_idx;
544 39037072 const int tu_p = (y_p >> log2_min_tu_size) * min_tu_width + (x_p >> log2_min_tu_size);
545 39037072 const int cb_p = (y_p >> log2_min_cb_size) * min_cb_width + (x_p >> log2_min_cb_size);
546
4/4
✓ Branch 0 taken 195 times.
✓ Branch 1 taken 39036877 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 184 times.
39037072 const uint8_t pcmf = fc->tab.pcmf[chroma][cb_p] && cu->bdpcm_flag[chroma];
547
4/4
✓ Branch 0 taken 29447160 times.
✓ Branch 1 taken 9589912 times.
✓ Branch 2 taken 625060 times.
✓ Branch 3 taken 28822100 times.
39037072 const uint8_t intra = fc->tab.cpm[chroma][cb_p] == MODE_INTRA || cu->pred_mode == MODE_INTRA;
548 39037072 const uint8_t same_mode = fc->tab.cpm[chroma][cb_p] == cu->pred_mode;
549
550
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 39037061 times.
39037072 if (pcmf)
551 11 return 0;
552
553
6/6
✓ Branch 0 taken 28822100 times.
✓ Branch 1 taken 10214961 times.
✓ Branch 2 taken 28462844 times.
✓ Branch 3 taken 359256 times.
✓ Branch 4 taken 285370 times.
✓ Branch 5 taken 28177474 times.
39037061 if (intra || mvf_p->ciip_flag || mvf_q->ciip_flag)
554 10859587 return 2;
555
556
2/2
✓ Branch 0 taken 21903660 times.
✓ Branch 1 taken 6273814 times.
28177474 if (chroma) {
557 43424666 return fc->tab.tu_coded_flag[c_idx][tu_p] ||
558
2/2
✓ Branch 0 taken 21497448 times.
✓ Branch 1 taken 23558 times.
21521006 fc->tab.tu_joint_cbcr_residual_flag[tu_p] ||
559
4/4
✓ Branch 0 taken 21521006 times.
✓ Branch 1 taken 382654 times.
✓ Branch 2 taken 21307098 times.
✓ Branch 3 taken 190350 times.
64731764 tu->coded_flag[c_idx] ||
560
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21307098 times.
21307098 tu->joint_cbcr_residual_flag;
561 }
562
563
4/4
✓ Branch 0 taken 5570955 times.
✓ Branch 1 taken 702859 times.
✓ Branch 2 taken 347196 times.
✓ Branch 3 taken 5223759 times.
6273814 if (fc->tab.tu_coded_flag[LUMA][tu_p] || tu->coded_flag[LUMA])
564 1050055 return 1;
565
566
6/6
✓ Branch 0 taken 1325249 times.
✓ Branch 1 taken 3898510 times.
✓ Branch 2 taken 1317210 times.
✓ Branch 3 taken 8039 times.
✓ Branch 4 taken 1124032 times.
✓ Branch 5 taken 193178 times.
5223759 if ((off_to_cb && ((off_to_cb % 8) || !has_sub_block)))
567 1132071 return 0; // inside a cu, not aligned to 8 or with no subblocks
568
569
2/2
✓ Branch 0 taken 135 times.
✓ Branch 1 taken 4091553 times.
4091688 if (!same_mode)
570 135 return 1;
571
572 4091553 return boundary_strength(lc, mvf_q, mvf_p, rpl_p);
573 }
574
575 3751734 static int deblock_is_boundary(const VVCLocalContext *lc, const int boundary,
576 const int pos, const int rs, const int vertical)
577 {
578 3751734 const VVCFrameContext *fc = lc->fc;
579 3751734 const H266RawSPS *rsps = fc->ps.sps->r;
580 3751734 const H266RawPPS *rpps = fc->ps.pps->r;
581 int flag;
582
4/4
✓ Branch 0 taken 3309001 times.
✓ Branch 1 taken 442733 times.
✓ Branch 2 taken 557258 times.
✓ Branch 3 taken 2751743 times.
3751734 if (boundary && (pos % fc->ps.sps->ctb_size_y) == 0) {
583
2/2
✓ Branch 0 taken 301394 times.
✓ Branch 1 taken 255864 times.
557258 flag = vertical ? BOUNDARY_LEFT_SLICE : BOUNDARY_UPPER_SLICE;
584
2/2
✓ Branch 0 taken 18537 times.
✓ Branch 1 taken 538721 times.
557258 if (lc->boundary_flags & flag &&
585
2/2
✓ Branch 0 taken 6962 times.
✓ Branch 1 taken 11575 times.
18537 !rpps->pps_loop_filter_across_slices_enabled_flag)
586 6962 return 0;
587
588
2/2
✓ Branch 0 taken 297623 times.
✓ Branch 1 taken 252673 times.
550296 flag = vertical ? BOUNDARY_LEFT_TILE : BOUNDARY_UPPER_TILE;
589
2/2
✓ Branch 0 taken 16590 times.
✓ Branch 1 taken 533706 times.
550296 if (lc->boundary_flags & flag &&
590
2/2
✓ Branch 0 taken 1710 times.
✓ Branch 1 taken 14880 times.
16590 !rpps->pps_loop_filter_across_tiles_enabled_flag)
591 1710 return 0;
592
593
2/2
✓ Branch 0 taken 296429 times.
✓ Branch 1 taken 252157 times.
548586 flag = vertical ? BOUNDARY_LEFT_SUBPIC : BOUNDARY_UPPER_SUBPIC;
594
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 548586 times.
548586 if (lc->boundary_flags & flag) {
595 const int q_rs = rs - (vertical ? 1 : fc->ps.pps->ctb_width);
596 const SliceContext *q_slice = lc->fc->slices[lc->fc->tab.slice_idx[q_rs]];
597
598 if (!rsps->sps_loop_filter_across_subpic_enabled_flag[q_slice->sh.r->curr_subpic_idx] ||
599 !rsps->sps_loop_filter_across_subpic_enabled_flag[lc->sc->sh.r->curr_subpic_idx])
600 return 0;
601 }
602 }
603 3743062 return boundary;
604 }
605
606 2378690 static void vvc_deblock_bs_luma(const VVCLocalContext *lc,
607 const int x0, const int y0, const int width, const int height,
608 const CodingUnit *cu, const TransformUnit *tu, int rs, const int vertical)
609 {
610 2378690 const VVCFrameContext *fc = lc->fc;
611 2378690 const PredictionUnit *pu = &cu->pu;
612 2378690 const int mask = LUMA_GRID - 1;
613
2/2
✓ Branch 0 taken 1189345 times.
✓ Branch 1 taken 1189345 times.
2378690 const int pos = vertical ? x0 : y0;
614
2/2
✓ Branch 0 taken 1189345 times.
✓ Branch 1 taken 1189345 times.
2378690 const int cb = vertical ? cu->x0 : cu->y0;
615 2378690 const int is_intra = cu->pred_mode == MODE_INTRA;
616
2/2
✓ Branch 0 taken 1189345 times.
✓ Branch 1 taken 1189345 times.
2378690 const int cb_size = vertical ? cu->cb_width : cu->cb_height;
617
8/8
✓ Branch 0 taken 1013484 times.
✓ Branch 1 taken 1365206 times.
✓ Branch 2 taken 892240 times.
✓ Branch 3 taken 121244 times.
✓ Branch 4 taken 23832 times.
✓ Branch 5 taken 868408 times.
✓ Branch 6 taken 119972 times.
✓ Branch 7 taken 25104 times.
2378690 const int has_sb = !is_intra && (pu->merge_subblock_flag || pu->inter_affine_flag) && cb_size > 8;
618
619
6/6
✓ Branch 0 taken 2331094 times.
✓ Branch 1 taken 47596 times.
✓ Branch 2 taken 2280710 times.
✓ Branch 3 taken 50384 times.
✓ Branch 5 taken 2275422 times.
✓ Branch 6 taken 103268 times.
2378690 if (deblock_is_boundary(lc, pos > 0 && !(pos & mask), pos, rs, vertical)) {
620 2275422 const int is_vb = is_virtual_boundary(fc, pos, vertical);
621
2/2
✓ Branch 0 taken 1153264 times.
✓ Branch 1 taken 1122158 times.
2275422 const int size = vertical ? height : width;
622
2/2
✓ Branch 0 taken 1153264 times.
✓ Branch 1 taken 1122158 times.
2275422 const int size_q = vertical ? width : height;
623 2275422 const int off = cb - pos;
624
2/2
✓ Branch 0 taken 1153264 times.
✓ Branch 1 taken 1122158 times.
2275422 const int flag = vertical ? BOUNDARY_LEFT_SLICE : BOUNDARY_UPPER_SLICE;
625 2275422 const RefPicList *rpl_p =
626
2/2
✓ Branch 0 taken 57004 times.
✓ Branch 1 taken 2218418 times.
2275422 (lc->boundary_flags & flag) ? ff_vvc_get_ref_list(fc, fc->ref, x0 - vertical, y0 - !vertical) : lc->sc->rpl;
627
628
2/2
✓ Branch 0 taken 10107424 times.
✓ Branch 1 taken 2275422 times.
12382846 for (int i = 0; i < size; i += 4) {
629 10107424 const int x = x0 + i * !vertical;
630 10107424 const int y = y0 + i * vertical;
631 uint8_t max_len_p, max_len_q;
632
1/2
✓ Branch 0 taken 10107424 times.
✗ Branch 1 not taken.
10107424 const int bs = is_vb ? 0 : deblock_bs(lc, x - vertical, y - !vertical, x, y, cu, tu, rpl_p, LUMA, off, has_sb);
633
634 10107424 TAB_BS(fc->tab.bs[vertical][LUMA], x, y) = bs;
635
636 10107424 derive_max_filter_length_luma(fc, x, y, size_q, has_sb, vertical, &max_len_p, &max_len_q);
637 10107424 TAB_MAX_LEN(fc->tab.max_len_p[vertical], x, y) = max_len_p;
638 10107424 TAB_MAX_LEN(fc->tab.max_len_q[vertical], x, y) = max_len_q;
639 }
640 }
641
642
2/2
✓ Branch 0 taken 119972 times.
✓ Branch 1 taken 2258718 times.
2378690 if (has_sb)
643 119972 vvc_deblock_subblock_bs(lc, cb, x0, y0, width, height, vertical);
644 2378690 }
645
646 1373044 static void vvc_deblock_bs_chroma(const VVCLocalContext *lc,
647 const int x0, const int y0, const int width, const int height,
648 const CodingUnit *cu, const TransformUnit *tu, const int rs, const int vertical)
649 {
650 1373044 const VVCFrameContext *fc = lc->fc;
651
2/2
✓ Branch 0 taken 686522 times.
✓ Branch 1 taken 686522 times.
1373044 const int shift = (vertical ? fc->ps.sps->hshift : fc->ps.sps->vshift)[CHROMA];
652 1373044 const int mask = (CHROMA_GRID << shift) - 1;
653
2/2
✓ Branch 0 taken 686522 times.
✓ Branch 1 taken 686522 times.
1373044 const int pos = vertical ? x0 : y0;
654
655
6/6
✓ Branch 0 taken 1335219 times.
✓ Branch 1 taken 37825 times.
✓ Branch 2 taken 1028291 times.
✓ Branch 3 taken 306928 times.
✓ Branch 5 taken 1024907 times.
✓ Branch 6 taken 348137 times.
1373044 if (deblock_is_boundary(lc, pos > 0 && !(pos & mask), pos, rs, vertical)) {
656 1024907 const int is_vb = is_virtual_boundary(fc, pos, vertical);
657
2/2
✓ Branch 0 taken 513389 times.
✓ Branch 1 taken 511518 times.
1024907 const int size = vertical ? height : width;
658
659
2/2
✓ Branch 0 taken 2049814 times.
✓ Branch 1 taken 1024907 times.
3074721 for (int c_idx = CB; c_idx <= CR; c_idx++) {
660
2/2
✓ Branch 0 taken 28929648 times.
✓ Branch 1 taken 2049814 times.
30979462 for (int i = 0; i < size; i += 2) {
661 28929648 const int x = x0 + i * !vertical;
662 28929648 const int y = y0 + i * vertical;
663
1/2
✓ Branch 0 taken 28929648 times.
✗ Branch 1 not taken.
28929648 const int bs = is_vb ? 0 : deblock_bs(lc, x - vertical, y - !vertical, x, y, cu, tu, NULL, c_idx, 0, 0);
664
665 28929648 TAB_BS(fc->tab.bs[vertical][c_idx], x, y) = bs;
666 }
667 }
668 }
669 1373044 }
670
671 typedef void (*deblock_bs_fn)(const VVCLocalContext *lc, const int x0, const int y0,
672 const int width, const int height, const int rs, const int vertical);
673
674 45788 void ff_vvc_deblock_bs(VVCLocalContext *lc, const int rx, const int ry, const int rs)
675 {
676 45788 const VVCFrameContext *fc = lc->fc;
677 45788 const VVCSPS *sps = fc->ps.sps;
678 45788 const int x0 = rx << sps->ctb_log2_size_y;
679 45788 const int y0 = ry << sps->ctb_log2_size_y;
680
681 45788 ff_vvc_decode_neighbour(lc, x0, y0, rx, ry, rs);
682
2/2
✓ Branch 0 taken 1106937 times.
✓ Branch 1 taken 45788 times.
1152725 for (const CodingUnit *cu = fc->tab.cus[rs]; cu; cu = cu->next) {
683
2/2
✓ Branch 0 taken 1348458 times.
✓ Branch 1 taken 1106937 times.
2455395 for (const TransformUnit *tu = cu->tus.head; tu; tu = tu->next) {
684
2/2
✓ Branch 0 taken 2696916 times.
✓ Branch 1 taken 1348458 times.
4045374 for (int vertical = 0; vertical <= 1; vertical++) {
685
2/2
✓ Branch 0 taken 2378690 times.
✓ Branch 1 taken 318226 times.
2696916 if (tu->avail[LUMA])
686 2378690 vvc_deblock_bs_luma(lc, tu->x0, tu->y0, tu->width, tu->height, cu, tu, rs, vertical);
687
2/2
✓ Branch 0 taken 1373044 times.
✓ Branch 1 taken 1323872 times.
2696916 if (tu->avail[CHROMA]) {
688
3/4
✓ Branch 0 taken 10306 times.
✓ Branch 1 taken 1362738 times.
✓ Branch 2 taken 10306 times.
✗ Branch 3 not taken.
1373044 if (cu->isp_split_type != ISP_NO_SPLIT && cu->tree_type == SINGLE_TREE)
689 10306 vvc_deblock_bs_chroma(lc, cu->x0, cu->y0, cu->cb_width, cu->cb_height, cu, tu, rs, vertical);
690 else
691 1362738 vvc_deblock_bs_chroma(lc, tu->x0, tu->y0, tu->width, tu->height, cu, tu, rs, vertical);
692 }
693 }
694 }
695 }
696 45788 }
697
698 //part of 8.8.3.3 Derivation process of transform block boundary
699 6950073 static void max_filter_length_luma(const VVCFrameContext *fc, const int qx, const int qy,
700 const int vertical, uint8_t *max_len_p, uint8_t *max_len_q)
701 {
702 6950073 *max_len_p = TAB_MAX_LEN(fc->tab.max_len_p[vertical], qx, qy);
703 6950073 *max_len_q = TAB_MAX_LEN(fc->tab.max_len_q[vertical], qx, qy);
704 6950073 }
705
706 //part of 8.8.3.3 Derivation process of transform block boundary
707 3811275 static void max_filter_length_chroma(const VVCFrameContext *fc, const int qx, const int qy,
708 const int vertical, const int horizontal_ctu_edge, const int bs, uint8_t *max_len_p, uint8_t *max_len_q)
709 {
710
2/2
✓ Branch 0 taken 1841028 times.
✓ Branch 1 taken 1970247 times.
3811275 const int px = vertical ? qx - 1 : qx;
711
2/2
✓ Branch 0 taken 1970247 times.
✓ Branch 1 taken 1841028 times.
3811275 const int py = !vertical ? qy - 1 : qy;
712
2/2
✓ Branch 0 taken 1841028 times.
✓ Branch 1 taken 1970247 times.
3811275 const uint8_t *tb_size = vertical ? fc->tab.tb_width[CHROMA] : fc->tab.tb_height[CHROMA];
713
714 3811275 const int size_p = tb_size[(py >> MIN_TU_LOG2) * fc->ps.pps->min_tu_width + (px >> MIN_TU_LOG2)];
715 3811275 const int size_q = tb_size[(qy >> MIN_TU_LOG2) * fc->ps.pps->min_tu_width + (qx >> MIN_TU_LOG2)];
716
4/4
✓ Branch 0 taken 3138620 times.
✓ Branch 1 taken 672655 times.
✓ Branch 2 taken 2710603 times.
✓ Branch 3 taken 428017 times.
3811275 if (size_p >= 8 && size_q >= 8) {
717 2710603 *max_len_p = *max_len_q = 3;
718
2/2
✓ Branch 0 taken 342061 times.
✓ Branch 1 taken 2368542 times.
2710603 if (horizontal_ctu_edge)
719 342061 *max_len_p = 1;
720 } else {
721 //part of 8.8.3.6.4 Decision process for chroma block edges
722 1100672 *max_len_p = *max_len_q = (bs == 2);
723 }
724 3811275 }
725
726 10761348 static void max_filter_length(const VVCFrameContext *fc, const int qx, const int qy,
727 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)
728 {
729
2/2
✓ Branch 0 taken 6950073 times.
✓ Branch 1 taken 3811275 times.
10761348 if (!c_idx)
730 6950073 max_filter_length_luma(fc, qx, qy, vertical, max_len_p, max_len_q);
731 else
732 3811275 max_filter_length_chroma(fc, qx, qy, vertical, horizontal_ctu_edge, bs, max_len_p, max_len_q);
733 10761348 }
734
735 #define TC_CALC(qp, bs) \
736 tctable[av_clip((qp) + DEFAULT_INTRA_TC_OFFSET * ((bs) - 1) + \
737 (tc_offset & -2), \
738 0, MAX_QP + DEFAULT_INTRA_TC_OFFSET)]
739
740 // part of 8.8.3.6.2 Decision process for luma block edges
741 6950073 static int get_qp_y(const VVCFrameContext *fc, const uint8_t *src, const int x, const int y, const int vertical)
742 {
743 6950073 const VVCSPS *sps = fc->ps.sps;
744 6950073 const int qp = (ff_vvc_get_qPy(fc, x - vertical, y - !vertical) + ff_vvc_get_qPy(fc, x, y) + 1) >> 1;
745 6950073 int qp_offset = 0;
746 int level;
747
748
1/2
✓ Branch 0 taken 6950073 times.
✗ Branch 1 not taken.
6950073 if (!sps->r->sps_ladf_enabled_flag)
749 6950073 return qp;
750
751 level = fc->vvcdsp.lf.ladf_level[vertical](src, fc->frame->linesize[LUMA]);
752 qp_offset = sps->r->sps_ladf_lowest_interval_qp_offset;
753 for (int i = 0; i < sps->num_ladf_intervals - 1 && level > sps->ladf_interval_lower_bound[i + 1]; i++)
754 qp_offset = sps->r->sps_ladf_qp_offset[i];
755
756 return qp + qp_offset;
757 }
758
759 // part of 8.8.3.6.2 Decision process for luma block edges
760 3811275 static int get_qp_c(const VVCFrameContext *fc, const int x, const int y, const int c_idx, const int vertical)
761 {
762 3811275 const VVCSPS *sps = fc->ps.sps;
763 3811275 return (get_qPc(fc, x - vertical, y - !vertical, c_idx) + get_qPc(fc, x, y, c_idx) - 2 * sps->qp_bd_offset + 1) >> 1;
764 }
765
766 10761348 static int get_qp(const VVCFrameContext *fc, const uint8_t *src, const int x, const int y, const int c_idx, const int vertical)
767 {
768
2/2
✓ Branch 0 taken 6950073 times.
✓ Branch 1 taken 3811275 times.
10761348 if (!c_idx)
769 6950073 return get_qp_y(fc, src, x, y, vertical);
770 3811275 return get_qp_c(fc, x, y, c_idx, vertical);
771 }
772
773 91576 static void vvc_deblock(const VVCLocalContext *lc, int x0, int y0, const int rs, const int vertical)
774 {
775 91576 VVCFrameContext *fc = lc->fc;
776 91576 const VVCSPS *sps = fc->ps.sps;
777
2/2
✓ Branch 0 taken 90520 times.
✓ Branch 1 taken 1056 times.
91576 const int c_end = sps->r->sps_chroma_format_idc ? VVC_MAX_SAMPLE_ARRAYS : 1;
778 91576 const int ctb_size = fc->ps.sps->ctb_size_y;
779 91576 const DBParams *params = fc->tab.deblock + rs;
780 91576 int x_end = FFMIN(x0 + ctb_size, fc->ps.pps->width);
781 91576 int y_end = FFMIN(y0 + ctb_size, fc->ps.pps->height);
782
783 //not use this yet, may needed by plt.
784 91576 const uint8_t no_p[4] = { 0 };
785 91576 const uint8_t no_q[4] = { 0 } ;
786
787
2/2
✓ Branch 0 taken 45788 times.
✓ Branch 1 taken 45788 times.
91576 if (!vertical) {
788 45788 FFSWAP(int, x_end, y_end);
789 45788 FFSWAP(int, x0, y0);
790 }
791
792
2/2
✓ Branch 0 taken 272616 times.
✓ Branch 1 taken 91576 times.
364192 for (int c_idx = 0; c_idx < c_end; c_idx++) {
793
2/2
✓ Branch 0 taken 136308 times.
✓ Branch 1 taken 136308 times.
272616 const int hs = (vertical ? sps->hshift : sps->vshift)[c_idx];
794
2/2
✓ Branch 0 taken 136308 times.
✓ Branch 1 taken 136308 times.
272616 const int vs = (vertical ? sps->vshift : sps->hshift)[c_idx];
795
2/2
✓ Branch 0 taken 181040 times.
✓ Branch 1 taken 91576 times.
272616 const int grid = c_idx ? (CHROMA_GRID << hs) : LUMA_GRID;
796 272616 const int tc_offset = params->tc_offset[c_idx];
797 272616 const int beta_offset = params->beta_offset[c_idx];
798 272616 const int src_stride = fc->frame->linesize[c_idx];
799
800
2/2
✓ Branch 0 taken 3162438 times.
✓ Branch 1 taken 272616 times.
3435054 for (int y = y0; y < y_end; y += (DEBLOCK_STEP << vs)) {
801
4/4
✓ Branch 0 taken 2796969 times.
✓ Branch 1 taken 365469 times.
✓ Branch 2 taken 61603179 times.
✓ Branch 3 taken 3162438 times.
64765617 for (int x = x0 ? x0 : grid; x < x_end; x += grid) {
802
4/4
✓ Branch 0 taken 30751228 times.
✓ Branch 1 taken 30851951 times.
✓ Branch 2 taken 1381664 times.
✓ Branch 3 taken 29369564 times.
61603179 const uint8_t horizontal_ctu_edge = !vertical && !(x % ctb_size);
803 61603179 int32_t bs[4], beta[4], tc[4] = { 0 }, all_zero_bs = 1;
804 uint8_t max_len_p[4], max_len_q[4];
805
806
2/2
✓ Branch 0 taken 137070582 times.
✓ Branch 1 taken 61603179 times.
198673761 for (int i = 0; i < DEBLOCK_STEP >> (2 - vs); i++) {
807 137070582 int tx = x;
808 137070582 int ty = y + (i << 2);
809 137070582 const int end = ty >= y_end;
810
811
2/2
✓ Branch 0 taken 68401080 times.
✓ Branch 1 taken 68669502 times.
137070582 if (!vertical)
812 68401080 FFSWAP(int, tx, ty);
813
814
2/2
✓ Branch 0 taken 136993326 times.
✓ Branch 1 taken 77256 times.
137070582 bs[i] = end ? 0 : TAB_BS(fc->tab.bs[vertical][c_idx], tx, ty);
815
2/2
✓ Branch 0 taken 10761348 times.
✓ Branch 1 taken 126309234 times.
137070582 if (bs[i]) {
816 10761348 const int qp = get_qp(fc, POS(c_idx, tx, ty), tx, ty, c_idx, vertical);
817 10761348 beta[i] = betatable[av_clip(qp + beta_offset, 0, MAX_QP)];
818 10761348 tc[i] = TC_CALC(qp, bs[i]) ;
819 10761348 max_filter_length(fc, tx, ty, c_idx, vertical, horizontal_ctu_edge, bs[i], &max_len_p[i], &max_len_q[i]);
820 10761348 all_zero_bs = 0;
821 }
822 }
823
824
2/2
✓ Branch 0 taken 4691348 times.
✓ Branch 1 taken 56911831 times.
61603179 if (!all_zero_bs) {
825
2/2
✓ Branch 0 taken 2266927 times.
✓ Branch 1 taken 2424421 times.
4691348 uint8_t *src = vertical ? POS(c_idx, x, y) : POS(c_idx, y, x);
826
2/2
✓ Branch 0 taken 3547985 times.
✓ Branch 1 taken 1143363 times.
4691348 if (!c_idx)
827 3547985 fc->vvcdsp.lf.filter_luma[vertical](src, src_stride, beta, tc, no_p, no_q, max_len_p, max_len_q, horizontal_ctu_edge);
828 else
829 1143363 fc->vvcdsp.lf.filter_chroma[vertical](src, src_stride, beta, tc, no_p, no_q, max_len_p, max_len_q, vs);
830 }
831 }
832 }
833 }
834 91576 }
835
836 45788 void ff_vvc_deblock_vertical(const VVCLocalContext *lc, const int x0, const int y0, const int rs)
837 {
838 45788 vvc_deblock(lc, x0, y0, rs, 1);
839 45788 }
840
841 45788 void ff_vvc_deblock_horizontal(const VVCLocalContext *lc, const int x0, const int y0, const int rs)
842 {
843 45788 vvc_deblock(lc, x0, y0, rs, 0);
844 45788 }
845
846 570172 static void alf_copy_border(uint8_t *dst, const uint8_t *src,
847 const int pixel_shift, int width, const int height, const ptrdiff_t dst_stride, const ptrdiff_t src_stride)
848 {
849 570172 width <<= pixel_shift;
850
2/2
✓ Branch 0 taken 28690147 times.
✓ Branch 1 taken 570172 times.
29260319 for (int i = 0; i < height; i++) {
851 28690147 memcpy(dst, src, width);
852 28690147 dst += dst_stride;
853 28690147 src += src_stride;
854 }
855 570172 }
856
857 8887 static void alf_extend_vert(uint8_t *_dst, const uint8_t *_src,
858 const int pixel_shift, const int width, const int height, ptrdiff_t stride)
859 {
860
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8887 times.
8887 if (pixel_shift == 0) {
861 for (int i = 0; i < height; i++) {
862 memset(_dst, *_src, width);
863 _src += stride;
864 _dst += stride;
865 }
866 } else {
867 8887 const uint16_t *src = (const uint16_t *)_src;
868 8887 uint16_t *dst = (uint16_t *)_dst;
869 8887 stride >>= pixel_shift;
870
871
2/2
✓ Branch 0 taken 860658 times.
✓ Branch 1 taken 8887 times.
869545 for (int i = 0; i < height; i++) {
872
2/2
✓ Branch 0 taken 2220262 times.
✓ Branch 1 taken 860658 times.
3080920 for (int j = 0; j < width; j++)
873 2220262 dst[j] = *src;
874 860658 src += stride;
875 860658 dst += stride;
876 }
877 }
878 8887 }
879
880 42497 static void alf_extend_horz(uint8_t *dst, const uint8_t *src,
881 const int pixel_shift, int width, const int height, const ptrdiff_t stride)
882 {
883 42497 width <<= pixel_shift;
884
2/2
✓ Branch 0 taken 104593 times.
✓ Branch 1 taken 42497 times.
147090 for (int i = 0; i < height; i++) {
885 104593 memcpy(dst, src, width);
886 104593 dst += stride;
887 }
888 42497 }
889
890 106206 static void alf_copy_ctb_to_hv(VVCFrameContext *fc, const uint8_t *src, const ptrdiff_t src_stride,
891 const int x, const int y, const int width, const int height, const int rx, const int ry, const int c_idx)
892 {
893 106206 const int ps = fc->ps.sps->pixel_shift;
894 106206 const int w = fc->ps.pps->width >> fc->ps.sps->hshift[c_idx];
895 106206 const int h = fc->ps.pps->height >> fc->ps.sps->vshift[c_idx];
896
2/2
✓ Branch 0 taken 35754 times.
✓ Branch 1 taken 70452 times.
106206 const int border_pixels = (c_idx == 0) ? ALF_BORDER_LUMA : ALF_BORDER_CHROMA;
897 106206 const int offset_h[] = { 0, height - border_pixels };
898 106206 const int offset_v[] = { 0, width - border_pixels };
899
900 /* copy horizontal edges */
901
2/2
✓ Branch 0 taken 212412 times.
✓ Branch 1 taken 106206 times.
318618 for (int i = 0; i < FF_ARRAY_ELEMS(offset_h); i++) {
902 212412 alf_copy_border(fc->tab.alf_pixel_buffer_h[c_idx][i] + ((border_pixels * ry * w + x)<< ps),
903 212412 src + offset_h[i] * src_stride, ps, width, border_pixels, w << ps, src_stride);
904 }
905 /* copy vertical edges */
906
2/2
✓ Branch 0 taken 212412 times.
✓ Branch 1 taken 106206 times.
318618 for (int i = 0; i < FF_ARRAY_ELEMS(offset_v); i++) {
907 212412 alf_copy_border(fc->tab.alf_pixel_buffer_v[c_idx][i] + ((h * rx + y) * (border_pixels << ps)),
908 212412 src + (offset_v[i] << ps), ps, border_pixels, height, border_pixels << ps, src_stride);
909 }
910 106206 }
911
912 85122 static void alf_fill_border_h(uint8_t *dst, const ptrdiff_t dst_stride, const uint8_t *src, const ptrdiff_t src_stride,
913 const uint8_t *border, const int width, const int border_pixels, const int ps, const int edge)
914 {
915
2/2
✓ Branch 0 taken 16009 times.
✓ Branch 1 taken 69113 times.
85122 if (edge)
916 16009 alf_extend_horz(dst, border, ps, width, border_pixels, dst_stride);
917 else
918 69113 alf_copy_border(dst, src, ps, width, border_pixels, dst_stride, src_stride);
919 85122 }
920
921 85122 static void alf_fill_border_v(uint8_t *dst, const ptrdiff_t dst_stride, const uint8_t *src,
922 const uint8_t *border, const int border_pixels, const int height, const int pixel_shift, const int *edges, const int edge)
923 {
924 85122 const ptrdiff_t src_stride = (border_pixels << pixel_shift);
925
926
2/2
✓ Branch 0 taken 8887 times.
✓ Branch 1 taken 76235 times.
85122 if (edge) {
927 8887 alf_extend_vert(dst, border, pixel_shift, border_pixels, height + 2 * border_pixels, dst_stride);
928 8887 return;
929 }
930
931 //left/right
932 76235 alf_copy_border(dst + dst_stride * border_pixels * edges[TOP], src + src_stride * border_pixels * edges[TOP],
933 76235 pixel_shift, border_pixels, height + (!edges[TOP] + !edges[BOTTOM]) * border_pixels, dst_stride, src_stride);
934
935 //top left/right
936
2/2
✓ Branch 0 taken 12017 times.
✓ Branch 1 taken 64218 times.
76235 if (edges[TOP])
937 12017 alf_extend_horz(dst, dst + dst_stride * border_pixels, pixel_shift, border_pixels, border_pixels, dst_stride);
938
939 //bottom left/right
940
2/2
✓ Branch 0 taken 14471 times.
✓ Branch 1 taken 61764 times.
76235 if (edges[BOTTOM]) {
941 14471 dst += dst_stride * (border_pixels + height);
942 14471 alf_extend_horz(dst, dst - dst_stride, pixel_shift, border_pixels, border_pixels, dst_stride);
943 }
944 }
945
946 42561 static void alf_prepare_buffer(VVCFrameContext *fc, uint8_t *_dst, const uint8_t *_src, const int x, const int y,
947 const int rx, const int ry, const int width, const int height, const ptrdiff_t dst_stride, const ptrdiff_t src_stride,
948 const int c_idx, const int *edges)
949 {
950 42561 const int ps = fc->ps.sps->pixel_shift;
951 42561 const int w = fc->ps.pps->width >> fc->ps.sps->hshift[c_idx];
952 42561 const int h = fc->ps.pps->height >> fc->ps.sps->vshift[c_idx];
953
2/2
✓ Branch 0 taken 19329 times.
✓ Branch 1 taken 23232 times.
42561 const int border_pixels = c_idx == 0 ? ALF_BORDER_LUMA : ALF_BORDER_CHROMA;
954 uint8_t *dst, *src;
955
956 42561 copy_ctb(_dst, _src, width << ps, height, dst_stride, src_stride);
957
958 //top
959 42561 src = fc->tab.alf_pixel_buffer_h[c_idx][1] + (((border_pixels * w) << ps) * (ry - 1) + (x << ps));
960 42561 dst = _dst - border_pixels * dst_stride;
961 42561 alf_fill_border_h(dst, dst_stride, src, w << ps, _dst, width, border_pixels, ps, edges[TOP]);
962
963 //bottom
964 42561 src = fc->tab.alf_pixel_buffer_h[c_idx][0] + (((border_pixels * w) << ps) * (ry + 1) + (x << ps));
965 42561 dst = _dst + height * dst_stride;
966 42561 alf_fill_border_h(dst, dst_stride, src, w << ps, _dst + (height - 1) * dst_stride, width, border_pixels, ps, edges[BOTTOM]);
967
968
969 //left
970 42561 src = fc->tab.alf_pixel_buffer_v[c_idx][1] + (h * (rx - 1) + y - border_pixels) * (border_pixels << ps);
971 42561 dst = _dst - (border_pixels << ps) - border_pixels * dst_stride;
972 42561 alf_fill_border_v(dst, dst_stride, src, dst + (border_pixels << ps), border_pixels, height, ps, edges, edges[LEFT]);
973
974 //right
975 42561 src = fc->tab.alf_pixel_buffer_v[c_idx][0] + (h * (rx + 1) + y - border_pixels) * (border_pixels << ps);
976 42561 dst = _dst + (width << ps) - border_pixels * dst_stride;
977 42561 alf_fill_border_v(dst, dst_stride, src, dst - (1 << ps), border_pixels, height, ps, edges, edges[RIGHT]);
978 42561 }
979
980 #define ALF_MAX_BLOCKS_IN_CTU (MAX_CTU_SIZE * MAX_CTU_SIZE / ALF_BLOCK_SIZE / ALF_BLOCK_SIZE)
981 #define ALF_MAX_FILTER_SIZE (ALF_MAX_BLOCKS_IN_CTU * ALF_NUM_COEFF_LUMA)
982
983 18836 static void alf_get_coeff_and_clip(VVCLocalContext *lc, int16_t *coeff, int16_t *clip,
984 const uint8_t *src, ptrdiff_t src_stride, int width, int height, int vb_pos, const ALFParams *alf)
985 {
986 18836 const VVCFrameContext *fc = lc->fc;
987 18836 const H266RawSliceHeader *rsh = lc->sc->sh.r;
988 18836 uint8_t fixed_clip_set[ALF_NUM_FILTERS_LUMA][ALF_NUM_COEFF_LUMA] = { 0 };
989 const int16_t *coeff_set;
990 const uint8_t *clip_idx_set;
991 const uint8_t *class_to_filt;
992 18836 const int size = width * height / ALF_BLOCK_SIZE / ALF_BLOCK_SIZE;
993 int class_idx[ALF_MAX_BLOCKS_IN_CTU];
994 int transpose_idx[ALF_MAX_BLOCKS_IN_CTU];
995
996
2/2
✓ Branch 0 taken 2496 times.
✓ Branch 1 taken 16340 times.
18836 if (alf->ctb_filt_set_idx_y < 16) {
997 2496 coeff_set = &ff_vvc_alf_fix_filt_coeff[0][0];
998 2496 clip_idx_set = &fixed_clip_set[0][0];
999 2496 class_to_filt = ff_vvc_alf_class_to_filt_map[alf->ctb_filt_set_idx_y];
1000 } else {
1001 16340 const int id = rsh->sh_alf_aps_id_luma[alf->ctb_filt_set_idx_y - 16];
1002 16340 const VVCALF *aps = fc->ps.alf_list[id];
1003 16340 coeff_set = &aps->luma_coeff[0][0];
1004 16340 clip_idx_set = &aps->luma_clip_idx[0][0];
1005 16340 class_to_filt = ff_vvc_alf_aps_class_to_filt_map;
1006 }
1007 18836 fc->vvcdsp.alf.classify(class_idx, transpose_idx, src, src_stride, width, height,
1008 18836 vb_pos, lc->alf_gradient_tmp);
1009 18836 fc->vvcdsp.alf.recon_coeff_and_clip(coeff, clip, class_idx, transpose_idx, size,
1010 coeff_set, clip_idx_set, class_to_filt);
1011 18836 }
1012
1013 18836 static void alf_filter_luma(VVCLocalContext *lc, uint8_t *dst, const uint8_t *src,
1014 const ptrdiff_t dst_stride, const ptrdiff_t src_stride, const int x0, const int y0,
1015 const int width, const int height, const int _vb_pos, const ALFParams *alf)
1016 {
1017 18836 const VVCFrameContext *fc = lc->fc;
1018 18836 int vb_pos = _vb_pos - y0;
1019 18836 int16_t *coeff = (int16_t*)lc->tmp;
1020 18836 int16_t *clip = (int16_t *)lc->tmp1;
1021
1022 av_assert0(ALF_MAX_FILTER_SIZE <= sizeof(lc->tmp));
1023 av_assert0(ALF_MAX_FILTER_SIZE * sizeof(int16_t) <= sizeof(lc->tmp1));
1024
1025 18836 alf_get_coeff_and_clip(lc, coeff, clip, src, src_stride, width, height, vb_pos, alf);
1026 18836 fc->vvcdsp.alf.filter[LUMA](dst, dst_stride, src, src_stride, width, height, coeff, clip, vb_pos);
1027 18836 }
1028
1029 139392 static int alf_clip_from_idx(const VVCFrameContext *fc, const int idx)
1030 {
1031 139392 const VVCSPS *sps = fc->ps.sps;
1032 139392 const int offset[] = {0, 3, 5, 7};
1033
1034 139392 return 1 << (sps->bit_depth - offset[idx]);
1035 }
1036
1037 23232 static void alf_filter_chroma(VVCLocalContext *lc, uint8_t *dst, const uint8_t *src,
1038 const ptrdiff_t dst_stride, const ptrdiff_t src_stride, const int c_idx,
1039 const int width, const int height, const int vb_pos, const ALFParams *alf)
1040 {
1041 23232 VVCFrameContext *fc = lc->fc;
1042 23232 const H266RawSliceHeader *rsh = lc->sc->sh.r;
1043 23232 const VVCALF *aps = fc->ps.alf_list[rsh->sh_alf_aps_id_chroma];
1044 23232 const int idx = alf->alf_ctb_filter_alt_idx[c_idx - 1];
1045 23232 const int16_t *coeff = aps->chroma_coeff[idx];
1046 int16_t clip[ALF_NUM_COEFF_CHROMA];
1047
1048
2/2
✓ Branch 0 taken 139392 times.
✓ Branch 1 taken 23232 times.
162624 for (int i = 0; i < ALF_NUM_COEFF_CHROMA; i++)
1049 139392 clip[i] = alf_clip_from_idx(fc, aps->chroma_clip_idx[idx][i]);
1050
1051 23232 fc->vvcdsp.alf.filter[CHROMA](dst, dst_stride, src, src_stride, width, height, coeff, clip, vb_pos);
1052 23232 }
1053
1054 9447 static void alf_filter_cc(VVCLocalContext *lc, uint8_t *dst, const uint8_t *luma,
1055 const ptrdiff_t dst_stride, const ptrdiff_t luma_stride, const int c_idx,
1056 const int width, const int height, const int hs, const int vs, const int vb_pos, const ALFParams *alf)
1057 {
1058 9447 const VVCFrameContext *fc = lc->fc;
1059 9447 const H266RawSliceHeader *rsh = lc->sc->sh.r;
1060 9447 const int idx = c_idx - 1;
1061
2/2
✓ Branch 0 taken 4819 times.
✓ Branch 1 taken 4628 times.
9447 const int cc_aps_id = c_idx == CB ? rsh->sh_alf_cc_cb_aps_id : rsh->sh_alf_cc_cr_aps_id;
1062 9447 const VVCALF *aps = fc->ps.alf_list[cc_aps_id];
1063
1064
1/2
✓ Branch 0 taken 9447 times.
✗ Branch 1 not taken.
9447 if (aps) {
1065 9447 const int16_t *coeff = aps->cc_coeff[idx][alf->ctb_cc_idc[idx] - 1];
1066
1067 9447 fc->vvcdsp.alf.filter_cc(dst, dst_stride, luma, luma_stride, width, height, hs, vs, coeff, vb_pos);
1068 }
1069 9447 }
1070
1071 35754 void ff_vvc_alf_copy_ctu_to_hv(VVCLocalContext* lc, const int x0, const int y0)
1072 {
1073 35754 VVCFrameContext *fc = lc->fc;
1074 35754 const int rx = x0 >> fc->ps.sps->ctb_log2_size_y;
1075 35754 const int ry = y0 >> fc->ps.sps->ctb_log2_size_y;
1076 35754 const int ctb_size_y = fc->ps.sps->ctb_size_y;
1077
2/2
✓ Branch 0 taken 35226 times.
✓ Branch 1 taken 528 times.
35754 const int c_end = fc->ps.sps->r->sps_chroma_format_idc ? VVC_MAX_SAMPLE_ARRAYS : 1;
1078
1079
2/2
✓ Branch 0 taken 106206 times.
✓ Branch 1 taken 35754 times.
141960 for (int c_idx = 0; c_idx < c_end; c_idx++) {
1080 106206 const int hs = fc->ps.sps->hshift[c_idx];
1081 106206 const int vs = fc->ps.sps->vshift[c_idx];
1082 106206 const int x = x0 >> hs;
1083 106206 const int y = y0 >> vs;
1084 106206 const int width = FFMIN(fc->ps.pps->width - x0, ctb_size_y) >> hs;
1085 106206 const int height = FFMIN(fc->ps.pps->height - y0, ctb_size_y) >> vs;
1086
1087 106206 const int src_stride = fc->frame->linesize[c_idx];
1088 106206 uint8_t *src = POS(c_idx, x0, y0);
1089
1090 106206 alf_copy_ctb_to_hv(fc, src, src_stride, x, y, width, height, rx, ry, c_idx);
1091 }
1092 35754 }
1093
1094 35754 static void alf_get_edges(const VVCLocalContext *lc, int edges[MAX_EDGES], const int rx, const int ry)
1095 {
1096 35754 VVCFrameContext *fc = lc->fc;
1097 35754 const VVCSPS *sps = fc->ps.sps;
1098 35754 const VVCPPS *pps = fc->ps.pps;
1099 35754 const int subpic_idx = lc->sc->sh.r->curr_subpic_idx;
1100
1101 // we can't use |= instead of || in this function; |= is not a shortcut operator
1102
1103
2/2
✓ Branch 0 taken 32784 times.
✓ Branch 1 taken 2970 times.
35754 if (!pps->r->pps_loop_filter_across_tiles_enabled_flag) {
1104
4/4
✓ Branch 0 taken 29618 times.
✓ Branch 1 taken 3166 times.
✓ Branch 2 taken 360 times.
✓ Branch 3 taken 29258 times.
32784 edges[LEFT] = edges[LEFT] || (lc->boundary_flags & BOUNDARY_LEFT_TILE);
1105
4/4
✓ Branch 0 taken 27104 times.
✓ Branch 1 taken 5680 times.
✓ Branch 2 taken 312 times.
✓ Branch 3 taken 26792 times.
32784 edges[TOP] = edges[TOP] || (lc->boundary_flags & BOUNDARY_UPPER_TILE);
1106
4/4
✓ Branch 0 taken 29618 times.
✓ Branch 1 taken 3166 times.
✓ Branch 2 taken 360 times.
✓ Branch 3 taken 29258 times.
32784 edges[RIGHT] = edges[RIGHT] || pps->ctb_to_col_bd[rx] != pps->ctb_to_col_bd[rx + 1];
1107
4/4
✓ Branch 0 taken 27104 times.
✓ Branch 1 taken 5680 times.
✓ Branch 2 taken 312 times.
✓ Branch 3 taken 26792 times.
32784 edges[BOTTOM] = edges[BOTTOM] || pps->ctb_to_row_bd[ry] != pps->ctb_to_row_bd[ry + 1];
1108 }
1109
1110
2/2
✓ Branch 0 taken 32784 times.
✓ Branch 1 taken 2970 times.
35754 if (!pps->r->pps_loop_filter_across_slices_enabled_flag) {
1111
3/4
✓ Branch 0 taken 29258 times.
✓ Branch 1 taken 3526 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 29258 times.
32784 edges[LEFT] = edges[LEFT] || (lc->boundary_flags & BOUNDARY_LEFT_SLICE);
1112
4/4
✓ Branch 0 taken 26792 times.
✓ Branch 1 taken 5992 times.
✓ Branch 2 taken 36 times.
✓ Branch 3 taken 26756 times.
32784 edges[TOP] = edges[TOP] || (lc->boundary_flags & BOUNDARY_UPPER_SLICE);
1113
3/4
✓ Branch 0 taken 29258 times.
✓ Branch 1 taken 3526 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 29258 times.
32784 edges[RIGHT] = edges[RIGHT] || CTB(fc->tab.slice_idx, rx, ry) != CTB(fc->tab.slice_idx, rx + 1, ry);
1114
4/4
✓ Branch 0 taken 26792 times.
✓ Branch 1 taken 5992 times.
✓ Branch 2 taken 36 times.
✓ Branch 3 taken 26756 times.
32784 edges[BOTTOM] = edges[BOTTOM] || CTB(fc->tab.slice_idx, rx, ry) != CTB(fc->tab.slice_idx, rx, ry + 1);
1115 }
1116
1117
1/2
✓ Branch 0 taken 35754 times.
✗ Branch 1 not taken.
35754 if (!sps->r->sps_loop_filter_across_subpic_enabled_flag[subpic_idx]) {
1118
3/4
✓ Branch 0 taken 32030 times.
✓ Branch 1 taken 3724 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 32030 times.
35754 edges[LEFT] = edges[LEFT] || (lc->boundary_flags & BOUNDARY_LEFT_SUBPIC);
1119
3/4
✓ Branch 0 taken 29396 times.
✓ Branch 1 taken 6358 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 29396 times.
35754 edges[TOP] = edges[TOP] || (lc->boundary_flags & BOUNDARY_UPPER_SUBPIC);
1120
3/4
✓ Branch 0 taken 32030 times.
✓ Branch 1 taken 3724 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 32030 times.
35754 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;
1121
3/4
✓ Branch 0 taken 29396 times.
✓ Branch 1 taken 6358 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 29396 times.
35754 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;
1122 }
1123
1124
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35754 times.
35754 if (sps->r->sps_virtual_boundaries_enabled_flag) {
1125 edges[LEFT] = edges[LEFT] || is_virtual_boundary(fc, rx << sps->ctb_log2_size_y, 1);
1126 edges[TOP] = edges[TOP] || is_virtual_boundary(fc, ry << sps->ctb_log2_size_y, 0);
1127 edges[RIGHT] = edges[RIGHT] || is_virtual_boundary(fc, (rx + 1) << sps->ctb_log2_size_y, 1);
1128 edges[BOTTOM] = edges[BOTTOM] || is_virtual_boundary(fc, (ry + 1) << sps->ctb_log2_size_y, 0);
1129 }
1130 35754 }
1131
1132 35754 static void alf_init_subblock(VVCRect *sb, int sb_edges[MAX_EDGES], const VVCRect *b, const int edges[MAX_EDGES])
1133 {
1134 35754 *sb = *b;
1135 35754 memcpy(sb_edges, edges, sizeof(int) * MAX_EDGES);
1136 35754 }
1137
1138 35754 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])
1139 {
1140 35754 int *pos[] = { &sb->l, &sb->t, &sb->r, &sb->b };
1141
1142
2/2
✓ Branch 0 taken 71508 times.
✓ Branch 1 taken 35754 times.
107262 for (int vertical = 0; vertical <= 1; vertical++) {
1143
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 71508 times.
71508 if (has_vb[vertical]) {
1144 const int c = vertical ? (bx ? LEFT : RIGHT) : (by ? TOP : BOTTOM);
1145 *pos[c] = vb_pos[vertical];
1146 edges[c] = 1;
1147 }
1148 }
1149 35754 }
1150
1151 35754 static void alf_get_subblocks(const VVCLocalContext *lc, VVCRect sbs[MAX_VBBS], int sb_edges[MAX_VBBS][MAX_EDGES], int *nb_sbs,
1152 const int x0, const int y0, const int rx, const int ry)
1153 {
1154 35754 VVCFrameContext *fc = lc->fc;
1155 35754 const VVCSPS *sps = fc->ps.sps;
1156 35754 const VVCPPS *pps = fc->ps.pps;
1157 35754 const int ctu_size_y = sps->ctb_size_y;
1158 35754 const int vb_pos[] = { get_virtual_boundary(fc, ry, 0), get_virtual_boundary(fc, rx, 1) };
1159 35754 const int has_vb[] = { vb_pos[0] > y0, vb_pos[1] > x0 };
1160 35754 const VVCRect b = { x0, y0, FFMIN(x0 + ctu_size_y, pps->width), FFMIN(y0 + ctu_size_y, pps->height) };
1161 35754 int edges[MAX_EDGES] = { !rx, !ry, rx == pps->ctb_width - 1, ry == pps->ctb_height - 1 };
1162 35754 int i = 0;
1163
1164 35754 alf_get_edges(lc, edges, rx, ry);
1165
1166
2/2
✓ Branch 0 taken 35754 times.
✓ Branch 1 taken 35754 times.
71508 for (int by = 0; by <= has_vb[0]; by++) {
1167
2/2
✓ Branch 0 taken 35754 times.
✓ Branch 1 taken 35754 times.
71508 for (int bx = 0; bx <= has_vb[1]; bx++, i++) {
1168 35754 alf_init_subblock(sbs + i, sb_edges[i], &b, edges);
1169 35754 alf_get_subblock(sbs + i, sb_edges[i], bx, by, vb_pos, has_vb);
1170 }
1171 }
1172 35754 *nb_sbs = i;
1173 35754 }
1174
1175 35754 void ff_vvc_alf_filter(VVCLocalContext *lc, const int x0, const int y0)
1176 {
1177 35754 VVCFrameContext *fc = lc->fc;
1178 35754 const VVCSPS *sps = fc->ps.sps;
1179 35754 const int rx = x0 >> sps->ctb_log2_size_y;
1180 35754 const int ry = y0 >> sps->ctb_log2_size_y;
1181 35754 const int ps = sps->pixel_shift;
1182 35754 const int padded_stride = EDGE_EMU_BUFFER_STRIDE << ps;
1183 35754 const int padded_offset = padded_stride * ALF_PADDING_SIZE + (ALF_PADDING_SIZE << ps);
1184
2/2
✓ Branch 0 taken 35226 times.
✓ Branch 1 taken 528 times.
35754 const int c_end = sps->r->sps_chroma_format_idc ? VVC_MAX_SAMPLE_ARRAYS : 1;
1185 35754 const int has_chroma = !!sps->r->sps_chroma_format_idc;
1186 35754 const int ctu_end = y0 + sps->ctb_size_y;
1187 35754 const ALFParams *alf = &CTB(fc->tab.alf, rx, ry);
1188 int sb_edges[MAX_VBBS][MAX_EDGES], nb_sbs;
1189 VVCRect sbs[MAX_VBBS];
1190
1191 35754 alf_get_subblocks(lc, sbs, sb_edges, &nb_sbs, x0, y0, rx, ry);
1192
1193
2/2
✓ Branch 0 taken 35754 times.
✓ Branch 1 taken 35754 times.
71508 for (int i = 0; i < nb_sbs; i++) {
1194 35754 const VVCRect *sb = sbs + i;
1195
2/2
✓ Branch 0 taken 106206 times.
✓ Branch 1 taken 35754 times.
141960 for (int c_idx = 0; c_idx < c_end; c_idx++) {
1196 106206 const int hs = fc->ps.sps->hshift[c_idx];
1197 106206 const int vs = fc->ps.sps->vshift[c_idx];
1198 106206 const int x = sb->l >> hs;
1199 106206 const int y = sb->t >> vs;
1200 106206 const int width = (sb->r - sb->l) >> hs;
1201 106206 const int height = (sb->b - sb->t) >> vs;
1202 106206 const int src_stride = fc->frame->linesize[c_idx];
1203 106206 uint8_t *src = POS(c_idx, sb->l, sb->t);
1204 uint8_t *padded;
1205
1206
10/10
✓ Branch 0 taken 64138 times.
✓ Branch 1 taken 42068 times.
✓ Branch 2 taken 16918 times.
✓ Branch 3 taken 47220 times.
✓ Branch 4 taken 16748 times.
✓ Branch 5 taken 170 times.
✓ Branch 6 taken 16331 times.
✓ Branch 7 taken 417 times.
✓ Branch 8 taken 76 times.
✓ Branch 9 taken 16255 times.
106206 if (alf->ctb_flag[c_idx] || (!c_idx && has_chroma && (alf->ctb_cc_idc[0] || alf->ctb_cc_idc[1]))) {
1207
2/2
✓ Branch 0 taken 23232 times.
✓ Branch 1 taken 19329 times.
42561 padded = (c_idx ? lc->alf_buffer_chroma : lc->alf_buffer_luma) + padded_offset;
1208 42561 alf_prepare_buffer(fc, padded, src, x, y, rx, ry, width, height,
1209 42561 padded_stride, src_stride, c_idx, sb_edges[i]);
1210 }
1211
2/2
✓ Branch 0 taken 42068 times.
✓ Branch 1 taken 64138 times.
106206 if (alf->ctb_flag[c_idx]) {
1212
2/2
✓ Branch 0 taken 18836 times.
✓ Branch 1 taken 23232 times.
42068 if (!c_idx) {
1213 18836 alf_filter_luma(lc, src, padded, src_stride, padded_stride, x, y,
1214 width, height, ctu_end - ALF_VB_POS_ABOVE_LUMA, alf);
1215 } else {
1216 23232 alf_filter_chroma(lc, src, padded, src_stride, padded_stride, c_idx,
1217 23232 width, height, ((ctu_end - sb->t) >> vs) - ALF_VB_POS_ABOVE_CHROMA, alf);
1218 }
1219 }
1220
4/4
✓ Branch 0 taken 70452 times.
✓ Branch 1 taken 35754 times.
✓ Branch 2 taken 9447 times.
✓ Branch 3 taken 61005 times.
106206 if (c_idx && alf->ctb_cc_idc[c_idx - 1]) {
1221 9447 padded = lc->alf_buffer_luma + padded_offset;
1222 9447 alf_filter_cc(lc, src, padded, src_stride, padded_stride, c_idx,
1223 9447 width, height, hs, vs, ctu_end - sb->t - ALF_VB_POS_ABOVE_LUMA, alf);
1224 }
1225 }
1226 }
1227 35754 }
1228
1229
1230 45792 void ff_vvc_lmcs_filter(const VVCLocalContext *lc, const int x, const int y)
1231 {
1232 45792 const SliceContext *sc = lc->sc;
1233 45792 const VVCFrameContext *fc = lc->fc;
1234 45792 const int ctb_size = fc->ps.sps->ctb_size_y;
1235 45792 const int width = FFMIN(fc->ps.pps->width - x, ctb_size);
1236 45792 const int height = FFMIN(fc->ps.pps->height - y, ctb_size);
1237 45792 uint8_t *data = POS(LUMA, x, y);
1238
2/2
✓ Branch 0 taken 19288 times.
✓ Branch 1 taken 26504 times.
45792 if (sc->sh.r->sh_lmcs_used_flag)
1239 19288 fc->vvcdsp.lmcs.filter(data, fc->frame->linesize[LUMA], width, height, &fc->ps.lmcs.inv_lut);
1240 45792 }
1241