FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/vvc/filter.c
Date: 2024-07-16 12:46:59
Exec Total Coverage
Lines: 720 766 94.0%
Functions: 50 51 98.0%
Branches: 552 629 87.8%

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 3543701 static int get_virtual_boundary(const VVCFrameContext *fc, const int ctu_pos, const int vertical)
63 {
64 3543701 const VVCSPS *sps = fc->ps.sps;
65 3543701 const VVCPH *ph = &fc->ps.ph;
66
2/2
✓ Branch 0 taken 1784136 times.
✓ Branch 1 taken 1759565 times.
3543701 const uint16_t *vbs = vertical ? ph->vb_pos_x : ph->vb_pos_y;
67
2/2
✓ Branch 0 taken 1784136 times.
✓ Branch 1 taken 1759565 times.
3543701 const uint8_t nb_vbs = vertical ? ph->num_ver_vbs : ph->num_hor_vbs;
68 3543701 const int pos = ctu_pos << sps->ctb_log2_size_y;
69
70
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3543701 times.
3543701 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 3543701 return 0;
78 }
79
80 3474429 static int is_virtual_boundary(const VVCFrameContext *fc, const int pos, const int vertical)
81 {
82 3474429 return get_virtual_boundary(fc, pos >> fc->ps.sps->ctb_log2_size_y, vertical) == pos;
83 }
84
85 6387706 static int get_qPc(const VVCFrameContext *fc, const int x0, const int y0, const int chroma)
86 {
87 6387706 const int x = x0 >> MIN_TU_LOG2;
88 6387706 const int y = y0 >> MIN_TU_LOG2;
89 6387706 const int min_tu_width = fc->ps.pps->min_tu_width;
90 6387706 return fc->tab.qp[chroma][x + y * min_tu_width];
91 }
92
93 45673 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 4494852 times.
✓ Branch 1 taken 45673 times.
4540525 for (int y = 0; y < height; y++) {
97 4494852 memcpy(dst, src, width);
98
99 4494852 dst += dst_stride;
100 4494852 src += src_stride;
101 }
102 45673 }
103
104 19416 static void copy_pixel(uint8_t *dst, const uint8_t *src, const int pixel_shift)
105 {
106
1/2
✓ Branch 0 taken 19416 times.
✗ Branch 1 not taken.
19416 if (pixel_shift)
107 19416 *(uint16_t *)dst = *(uint16_t *)src;
108 else
109 *dst = *src;
110 19416 }
111
112 266806 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
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 266806 times.
266806 if (pixel_shift == 0) {
117 for (i = 0; i < height; i++) {
118 *dst = *src;
119 dst += dst_stride;
120 src += src_stride;
121 }
122 } else {
123
2/2
✓ Branch 0 taken 24954096 times.
✓ Branch 1 taken 266806 times.
25220902 for (i = 0; i < height; i++) {
124 24954096 *(uint16_t *)dst = *(uint16_t *)src;
125 24954096 dst += dst_stride;
126 24954096 src += src_stride;
127 }
128 }
129 266806 }
130
131 255146 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 255146 const int ps = fc->ps.sps->pixel_shift;
136 255146 const int w = fc->ps.pps->width >> fc->ps.sps->hshift[c_idx];
137 255146 const int h = fc->ps.pps->height >> fc->ps.sps->vshift[c_idx];
138
139
2/2
✓ Branch 0 taken 127573 times.
✓ Branch 1 taken 127573 times.
255146 if (top) {
140 /* top */
141 127573 memcpy(fc->tab.sao_pixel_buffer_h[c_idx] + (((2 * ry) * w + x) << ps),
142 127573 src, width << ps);
143 } else {
144 /* bottom */
145 127573 memcpy(fc->tab.sao_pixel_buffer_h[c_idx] + (((2 * ry + 1) * w + x) << ps),
146 127573 src + src_stride * (height - 1), width << ps);
147
148 /* copy vertical edges */
149 127573 copy_vert(fc->tab.sao_pixel_buffer_v[c_idx] + (((2 * rx) * h + y) << ps), src, ps, height, 1 << ps, src_stride);
150 127573 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 255146 }
153
154 85742 static void sao_copy_ctb_to_hv(VVCLocalContext *lc, const int rx, const int ry, const int top)
155 {
156 85742 VVCFrameContext *fc = lc->fc;
157 85742 const int ctb_size_y = fc->ps.sps->ctb_size_y;
158 85742 const int x0 = rx << fc->ps.sps->ctb_log2_size_y;
159 85742 const int y0 = ry << fc->ps.sps->ctb_log2_size_y;
160
161
4/4
✓ Branch 0 taken 338808 times.
✓ Branch 1 taken 2080 times.
✓ Branch 2 taken 255146 times.
✓ Branch 3 taken 85742 times.
340888 for (int c_idx = 0; c_idx < (fc->ps.sps->r->sps_chroma_format_idc ? 3 : 1); c_idx++) {
162 255146 const int x = x0 >> fc->ps.sps->hshift[c_idx];
163 255146 const int y = y0 >> fc->ps.sps->vshift[c_idx];
164 255146 const ptrdiff_t src_stride = fc->frame->linesize[c_idx];
165 255146 const int ctb_size_h = ctb_size_y >> fc->ps.sps->hshift[c_idx];
166 255146 const int ctb_size_v = ctb_size_y >> fc->ps.sps->vshift[c_idx];
167 255146 const int width = FFMIN(ctb_size_h, (fc->ps.pps->width >> fc->ps.sps->hshift[c_idx]) - x);
168 255146 const int height = FFMIN(ctb_size_v, (fc->ps.pps->height >> fc->ps.sps->vshift[c_idx]) - y);
169 255146 const uint8_t *src = POS(c_idx, x0, y0);
170 255146 copy_ctb_to_hv(fc, src, src_stride, x, y, width, height, c_idx, rx, ry, top);
171 }
172 85742 }
173
174 42871 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 36124 times.
✓ Branch 1 taken 6747 times.
42871 if (ry)
177 36124 sao_copy_ctb_to_hv(lc, rx, ry - 1, 0);
178
179 42871 sao_copy_ctb_to_hv(lc, rx, ry, 1);
180
181
2/2
✓ Branch 0 taken 6747 times.
✓ Branch 1 taken 36124 times.
42871 if (last_row)
182 6747 sao_copy_ctb_to_hv(lc, rx, ry, 0);
183 42871 }
184
185 263364 static int sao_can_cross_slices(const VVCFrameContext *fc, const int rx, const int ry, const int dx, const int dy)
186 {
187 263364 const uint8_t lfase = fc->ps.pps->r->pps_loop_filter_across_slices_enabled_flag;
188
189
3/4
✓ Branch 0 taken 263364 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 261278 times.
✓ Branch 3 taken 2086 times.
263364 return lfase || CTB(fc->tab.slice_idx, rx, ry) == CTB(fc->tab.slice_idx, rx + dx, ry + dy);
190 }
191
192 42871 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 42871 const VVCFrameContext *fc = lc->fc;
196 42871 const VVCSPS *sps = fc->ps.sps;
197 42871 const H266RawSPS *rsps = sps->r;
198 42871 const VVCPPS *pps = fc->ps.pps;
199 42871 const int subpic_idx = lc->sc->sh.r->curr_subpic_idx;
200 42871 const uint8_t lfase = fc->ps.pps->r->pps_loop_filter_across_slices_enabled_flag;
201
4/4
✓ Branch 0 taken 3774 times.
✓ Branch 1 taken 39097 times.
✓ Branch 2 taken 939 times.
✓ Branch 3 taken 2835 times.
42871 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 939 times.
✓ Branch 1 taken 41932 times.
✓ Branch 2 taken 939 times.
✗ Branch 3 not taken.
42871 const uint8_t no_subpic_filter = rsps->sps_num_subpics_minus1 && !rsps->sps_loop_filter_across_subpic_enabled_flag[subpic_idx];
203 42871 uint8_t lf_edge[] = { 0, 0, 0, 0 };
204
205
6/8
✓ Branch 0 taken 41932 times.
✓ Branch 1 taken 939 times.
✓ Branch 2 taken 41932 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2835 times.
✓ Branch 5 taken 39097 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2835 times.
42871 *restore = no_subpic_filter || no_tile_filter || !lfase || rsps->sps_virtual_boundaries_enabled_flag;
206
207
2/2
✓ Branch 0 taken 2835 times.
✓ Branch 1 taken 40036 times.
42871 if (!*restore)
208 2835 return;
209
210
2/2
✓ Branch 0 taken 36412 times.
✓ Branch 1 taken 3624 times.
40036 if (!edges[LEFT]) {
211
4/4
✓ Branch 0 taken 828 times.
✓ Branch 1 taken 35584 times.
✓ Branch 2 taken 333 times.
✓ Branch 3 taken 495 times.
36412 lf_edge[LEFT] = no_tile_filter && pps->ctb_to_col_bd[rx] == rx;
212
4/4
✓ Branch 0 taken 828 times.
✓ Branch 1 taken 35584 times.
✓ Branch 2 taken 273 times.
✓ Branch 3 taken 555 times.
36412 lf_edge[LEFT] |= no_subpic_filter && rsps->sps_subpic_ctu_top_left_x[subpic_idx] == rx;
213 36412 lf_edge[LEFT] |= is_virtual_boundary(fc, rx << sps->ctb_log2_size_y, 1);
214
4/4
✓ Branch 1 taken 36139 times.
✓ Branch 2 taken 273 times.
✓ Branch 3 taken 60 times.
✓ Branch 4 taken 36079 times.
36412 vert_edge[0] = !sao_can_cross_slices(fc, rx, ry, -1, 0) || lf_edge[LEFT];
215 }
216
2/2
✓ Branch 0 taken 36412 times.
✓ Branch 1 taken 3624 times.
40036 if (!edges[RIGHT]) {
217
4/4
✓ Branch 0 taken 828 times.
✓ Branch 1 taken 35584 times.
✓ Branch 2 taken 333 times.
✓ Branch 3 taken 495 times.
36412 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 828 times.
✓ Branch 1 taken 35584 times.
✓ Branch 2 taken 273 times.
✓ Branch 3 taken 555 times.
36412 lf_edge[RIGHT] |= no_subpic_filter && rsps->sps_subpic_ctu_top_left_x[subpic_idx] + rsps->sps_subpic_width_minus1[subpic_idx] == rx;
219 36412 lf_edge[RIGHT] |= is_virtual_boundary(fc, (rx + 1) << sps->ctb_log2_size_y, 1);
220
4/4
✓ Branch 1 taken 36139 times.
✓ Branch 2 taken 273 times.
✓ Branch 3 taken 60 times.
✓ Branch 4 taken 36079 times.
36412 vert_edge[1] = !sao_can_cross_slices(fc, rx, ry, 1, 0) || lf_edge[RIGHT];
221 }
222
2/2
✓ Branch 0 taken 33604 times.
✓ Branch 1 taken 6432 times.
40036 if (!edges[TOP]) {
223
4/4
✓ Branch 0 taken 732 times.
✓ Branch 1 taken 32872 times.
✓ Branch 2 taken 282 times.
✓ Branch 3 taken 450 times.
33604 lf_edge[TOP] = no_tile_filter && pps->ctb_to_row_bd[ry] == ry;
224
4/4
✓ Branch 0 taken 732 times.
✓ Branch 1 taken 32872 times.
✓ Branch 2 taken 207 times.
✓ Branch 3 taken 525 times.
33604 lf_edge[TOP] |= no_subpic_filter && rsps->sps_subpic_ctu_top_left_y[subpic_idx] == ry;
225 33604 lf_edge[TOP] |= is_virtual_boundary(fc, ry << sps->ctb_log2_size_y, 0);
226
4/4
✓ Branch 1 taken 33352 times.
✓ Branch 2 taken 252 times.
✓ Branch 3 taken 60 times.
✓ Branch 4 taken 33292 times.
33604 horiz_edge[0] = !sao_can_cross_slices(fc, rx, ry, 0, -1) || lf_edge[TOP];
227 }
228
2/2
✓ Branch 0 taken 33604 times.
✓ Branch 1 taken 6432 times.
40036 if (!edges[BOTTOM]) {
229
4/4
✓ Branch 0 taken 732 times.
✓ Branch 1 taken 32872 times.
✓ Branch 2 taken 282 times.
✓ Branch 3 taken 450 times.
33604 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 732 times.
✓ Branch 1 taken 32872 times.
✓ Branch 2 taken 207 times.
✓ Branch 3 taken 525 times.
33604 lf_edge[BOTTOM] |= no_subpic_filter && rsps->sps_subpic_ctu_top_left_y[subpic_idx] + rsps->sps_subpic_height_minus1[subpic_idx] == ry;
231 33604 lf_edge[BOTTOM] |= is_virtual_boundary(fc, (ry + 1) << sps->ctb_log2_size_y, 0);
232
4/4
✓ Branch 1 taken 33352 times.
✓ Branch 2 taken 252 times.
✓ Branch 3 taken 60 times.
✓ Branch 4 taken 33292 times.
33604 horiz_edge[1] = !sao_can_cross_slices(fc, rx, ry, 0, 1) || lf_edge[BOTTOM];
233 }
234
235
4/4
✓ Branch 0 taken 36412 times.
✓ Branch 1 taken 3624 times.
✓ Branch 2 taken 30833 times.
✓ Branch 3 taken 5579 times.
40036 if (!edges[LEFT] && !edges[TOP])
236
6/6
✓ Branch 1 taken 30574 times.
✓ Branch 2 taken 259 times.
✓ Branch 3 taken 30529 times.
✓ Branch 4 taken 45 times.
✓ Branch 5 taken 45 times.
✓ Branch 6 taken 30484 times.
30833 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 33604 times.
✓ Branch 1 taken 6432 times.
✓ Branch 2 taken 30833 times.
✓ Branch 3 taken 2771 times.
40036 if (!edges[TOP] && !edges[RIGHT])
239
6/6
✓ Branch 1 taken 30574 times.
✓ Branch 2 taken 259 times.
✓ Branch 3 taken 30529 times.
✓ Branch 4 taken 45 times.
✓ Branch 5 taken 45 times.
✓ Branch 6 taken 30484 times.
30833 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 36412 times.
✓ Branch 1 taken 3624 times.
✓ Branch 2 taken 30833 times.
✓ Branch 3 taken 5579 times.
40036 if (!edges[RIGHT] && !edges[BOTTOM])
242
6/6
✓ Branch 1 taken 30574 times.
✓ Branch 2 taken 259 times.
✓ Branch 3 taken 30529 times.
✓ Branch 4 taken 45 times.
✓ Branch 5 taken 45 times.
✓ Branch 6 taken 30484 times.
30833 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 36412 times.
✓ Branch 1 taken 3624 times.
✓ Branch 2 taken 30833 times.
✓ Branch 3 taken 5579 times.
40036 if (!edges[LEFT] && !edges[BOTTOM])
245
6/6
✓ Branch 1 taken 30574 times.
✓ Branch 2 taken 259 times.
✓ Branch 3 taken 30529 times.
✓ Branch 4 taken 45 times.
✓ Branch 5 taken 45 times.
✓ Branch 6 taken 30484 times.
30833 diag_edge[3] = !sao_can_cross_slices(fc, rx, ry, -1, 1) || lf_edge[LEFT] || lf_edge[BOTTOM];
246 }
247
248 10475 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 10475 const int left = 1 - edges[LEFT];
252 10475 const int right = 1 - edges[RIGHT];
253 10475 int pos = 0;
254
255 10475 src -= left << ps;
256 10475 dst -= left << ps;
257
258
2/2
✓ Branch 0 taken 9705 times.
✓ Branch 1 taken 770 times.
10475 if (left) {
259 9705 copy_pixel(dst, src, ps);
260 9705 pos += (1 << ps);
261 }
262 10475 memcpy(dst + pos, src + pos, width << ps);
263
2/2
✓ Branch 0 taken 9711 times.
✓ Branch 1 taken 764 times.
10475 if (right) {
264 9711 pos += width << ps;
265 9711 copy_pixel(dst + pos, src + pos, ps);
266 }
267 10475 }
268
269 6380 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 6380 const uint8_t *sao_h = fc->tab.sao_pixel_buffer_h[c_idx];
274 6380 const uint8_t *sao_v = fc->tab.sao_pixel_buffer_v[c_idx];
275 6380 const int x = x0 >> fc->ps.sps->hshift[c_idx];
276 6380 const int y = y0 >> fc->ps.sps->vshift[c_idx];
277 6380 const int w = fc->ps.pps->width >> fc->ps.sps->hshift[c_idx];
278 6380 const int h = fc->ps.pps->height >> fc->ps.sps->vshift[c_idx];
279 6380 const int ps = fc->ps.sps->pixel_shift;
280
281
2/2
✓ Branch 0 taken 5250 times.
✓ Branch 1 taken 1130 times.
6380 if (!edges[TOP])
282 5250 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 5225 times.
✓ Branch 1 taken 1155 times.
6380 if (!edges[BOTTOM])
285 5225 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 5830 times.
✓ Branch 1 taken 550 times.
6380 if (!edges[LEFT])
288 5830 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 5830 times.
✓ Branch 1 taken 550 times.
6380 if (!edges[RIGHT])
291 5830 copy_vert(dst + (width << ps), sao_v + (((2 * rx + 2) * h + y) << ps), ps, height, dst_stride, 1 << ps);
292
293 6380 copy_ctb(dst, src, width << ps, height, dst_stride, src_stride);
294 6380 }
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 42871 void ff_vvc_sao_filter(VVCLocalContext *lc, int x0, int y0)
315 {
316 42871 VVCFrameContext *fc = lc->fc;
317 42871 const VVCSPS *sps = fc->ps.sps;
318 42871 const int rx = x0 >> sps->ctb_log2_size_y;
319 42871 const int ry = y0 >> sps->ctb_log2_size_y;
320 42871 const int edges[4] = { !rx, !ry, rx == fc->ps.pps->ctb_width - 1, ry == fc->ps.pps->ctb_height - 1 };
321 42871 const SAOParams *sao = &CTB(fc->tab.sao, rx, ry);
322 // flags indicating unfilterable edges
323 42871 uint8_t vert_edge[] = { 0, 0 };
324 42871 uint8_t horiz_edge[] = { 0, 0 };
325 42871 uint8_t diag_edge[] = { 0, 0, 0, 0 };
326 42871 int restore, vb_x = 0, vb_y = 0;;
327
328
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42871 times.
42871 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 42871 sao_get_edges(vert_edge, horiz_edge, diag_edge, &restore, lc, edges, rx, ry);
334
335
4/4
✓ Branch 0 taken 169404 times.
✓ Branch 1 taken 1040 times.
✓ Branch 2 taken 127573 times.
✓ Branch 3 taken 42871 times.
170444 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 127573 const ptrdiff_t src_stride = fc->frame->linesize[c_idx];
338 127573 uint8_t *src = POS(c_idx, x0, y0);
339 127573 const int hs = sps->hshift[c_idx];
340 127573 const int vs = sps->vshift[c_idx];
341 127573 const int ps = sps->pixel_shift;
342 127573 const int width = FFMIN(sps->ctb_size_y, fc->ps.pps->width - x0) >> hs;
343 127573 const int height = FFMIN(sps->ctb_size_y, fc->ps.pps->height - y0) >> vs;
344 127573 const int tab = sao_tab[(FFALIGN(width, 8) >> 3) - 1];
345 127573 const int sao_eo_class = sao->eo_class[c_idx];
346
347
3/3
✓ Branch 0 taken 4599 times.
✓ Branch 1 taken 6380 times.
✓ Branch 2 taken 116594 times.
127573 switch (sao->type_idx[c_idx]) {
348 4599 case SAO_BAND:
349 4599 fc->vvcdsp.sao.band_filter[tab](src, src, src_stride, src_stride,
350 4599 sao->offset_val[c_idx], sao->band_position[c_idx], width, height);
351 4599 break;
352 6380 case SAO_EDGE:
353 {
354 6380 const ptrdiff_t dst_stride = 2 * MAX_PB_SIZE + AV_INPUT_BUFFER_PADDING_SIZE;
355 6380 uint8_t *dst = lc->sao_buffer + dst_stride + AV_INPUT_BUFFER_PADDING_SIZE;
356
357 6380 sao_extends_edges(dst, dst_stride, src, src_stride, width, height, fc, x0, y0, rx, ry, edges, c_idx);
358
359 6380 fc->vvcdsp.sao.edge_filter[tab](src, dst, src_stride, sao->offset_val[c_idx],
360 6380 sao->eo_class[c_idx], width, height);
361 6380 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 6380 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6380 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 6380 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6380 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 6380 break;
370 }
371 }
372 }
373 42871 }
374
375 #define TAB_BS(t, x, y) (t)[((y) >> 2) * (fc->tab.sz.bs_width) + ((x) >> 2)]
376 #define TAB_MAX_LEN(t, x, y) (t)[((y) >> 2) * (fc->tab.sz.bs_width) + ((x) >> 2)]
377
378 //8 samples a time
379 #define DEBLOCK_STEP 8
380 #define LUMA_GRID 4
381 #define CHROMA_GRID 8
382
383 9387421 static int boundary_strength(const VVCLocalContext *lc, const MvField *curr, const MvField *neigh,
384 const RefPicList *neigh_rpl)
385 {
386 9387421 RefPicList *rpl = lc->sc->rpl;
387
388
2/2
✓ Branch 0 taken 1752 times.
✓ Branch 1 taken 9385669 times.
9387421 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 4517897 times.
✓ Branch 1 taken 4867772 times.
✓ Branch 2 taken 4210676 times.
✓ Branch 3 taken 307221 times.
9385669 if (curr->pred_flag == PF_BI && neigh->pred_flag == PF_BI) {
392 // same L0 and L1
393
2/2
✓ Branch 0 taken 4135480 times.
✓ Branch 1 taken 75196 times.
4210676 if (rpl[L0].refs[curr->ref_idx[L0]].poc == neigh_rpl[L0].refs[neigh->ref_idx[L0]].poc &&
394
2/2
✓ Branch 0 taken 437765 times.
✓ Branch 1 taken 3697715 times.
4135480 rpl[L0].refs[curr->ref_idx[L0]].poc == rpl[L1].refs[curr->ref_idx[L1]].poc &&
395
2/2
✓ Branch 0 taken 434411 times.
✓ Branch 1 taken 3354 times.
437765 neigh_rpl[L0].refs[neigh->ref_idx[L0]].poc == neigh_rpl[L1].refs[neigh->ref_idx[L1]].poc) {
396
4/4
✓ Branch 0 taken 388553 times.
✓ Branch 1 taken 45858 times.
✓ Branch 2 taken 363427 times.
✓ Branch 3 taken 25126 times.
434411 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 359857 times.
✓ Branch 1 taken 3570 times.
✓ Branch 2 taken 3009 times.
✓ Branch 3 taken 356848 times.
363427 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 19030 times.
✓ Branch 1 taken 58533 times.
✓ Branch 2 taken 4657 times.
✓ Branch 3 taken 14373 times.
77563 (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 2401 times.
✓ Branch 1 taken 2256 times.
✓ Branch 2 taken 1894 times.
✓ Branch 3 taken 507 times.
4657 FFABS(neigh->mv[0].x - curr->mv[1].x) >= 8 || FFABS(neigh->mv[0].y - curr->mv[1].y) >= 8))
400 77056 return 1;
401 else
402 357355 return 0;
403
2/2
✓ Branch 0 taken 3701069 times.
✓ Branch 1 taken 75196 times.
3776265 } 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 3682475 times.
✓ Branch 1 taken 18594 times.
3701069 neigh_rpl[L1].refs[neigh->ref_idx[L1]].poc == rpl[L1].refs[curr->ref_idx[L1]].poc) {
405
4/4
✓ Branch 0 taken 3159803 times.
✓ Branch 1 taken 522672 times.
✓ Branch 2 taken 3006932 times.
✓ Branch 3 taken 152871 times.
3682475 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 2975107 times.
✓ Branch 1 taken 31825 times.
✓ Branch 2 taken 20306 times.
✓ Branch 3 taken 2954801 times.
3006932 FFABS(neigh->mv[1].x - curr->mv[1].x) >= 8 || FFABS(neigh->mv[1].y - curr->mv[1].y) >= 8)
407 727674 return 1;
408 else
409 2954801 return 0;
410
2/2
✓ Branch 0 taken 26341 times.
✓ Branch 1 taken 67449 times.
93790 } 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 8232 times.
✓ Branch 1 taken 18109 times.
26341 neigh_rpl[L0].refs[neigh->ref_idx[L0]].poc == rpl[L1].refs[curr->ref_idx[L1]].poc) {
412
4/4
✓ Branch 0 taken 2920 times.
✓ Branch 1 taken 5312 times.
✓ Branch 2 taken 1133 times.
✓ Branch 3 taken 1787 times.
8232 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 309 times.
✓ Branch 2 taken 180 times.
✓ Branch 3 taken 644 times.
1133 FFABS(neigh->mv[0].x - curr->mv[1].x) >= 8 || FFABS(neigh->mv[0].y - curr->mv[1].y) >= 8)
414 7588 return 1;
415 else
416 644 return 0;
417 } else {
418 85558 return 1;
419 }
420
4/4
✓ Branch 0 taken 4867772 times.
✓ Branch 1 taken 307221 times.
✓ Branch 2 taken 4564179 times.
✓ Branch 3 taken 303593 times.
5174993 } 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 3737763 times.
✓ Branch 1 taken 826416 times.
4564179 if (curr->pred_flag & 1) {
425 3737763 A = curr->mv[0];
426 3737763 ref_A = rpl[L0].refs[curr->ref_idx[L0]].poc;
427 } else {
428 826416 A = curr->mv[1];
429 826416 ref_A = rpl[L1].refs[curr->ref_idx[L1]].poc;
430 }
431
432
2/2
✓ Branch 0 taken 3735771 times.
✓ Branch 1 taken 828408 times.
4564179 if (neigh->pred_flag & 1) {
433 3735771 B = neigh->mv[0];
434 3735771 ref_B = neigh_rpl[L0].refs[neigh->ref_idx[L0]].poc;
435 } else {
436 828408 B = neigh->mv[1];
437 828408 ref_B = neigh_rpl[L1].refs[neigh->ref_idx[L1]].poc;
438 }
439
440
2/2
✓ Branch 0 taken 4456184 times.
✓ Branch 1 taken 107995 times.
4564179 if (ref_A == ref_B) {
441
4/4
✓ Branch 0 taken 4118057 times.
✓ Branch 1 taken 338127 times.
✓ Branch 2 taken 151501 times.
✓ Branch 3 taken 3966556 times.
4456184 if (FFABS(A.x - B.x) >= 8 || FFABS(A.y - B.y) >= 8)
442 489628 return 1;
443 else
444 3966556 return 0;
445 } else
446 107995 return 1;
447 }
448
449 610814 return 1;
450 }
451
452 //part of 8.8.3.3 Derivation process of transform block boundary
453 9261949 static void derive_max_filter_length_luma(const VVCFrameContext *fc, const int qx, const int qy,
454 const int is_intra, const int has_subblock, const int vertical, uint8_t *max_len_p, uint8_t *max_len_q)
455 {
456
2/2
✓ Branch 0 taken 4456050 times.
✓ Branch 1 taken 4805899 times.
9261949 const int px = vertical ? qx - 1 : qx;
457
2/2
✓ Branch 0 taken 4805899 times.
✓ Branch 1 taken 4456050 times.
9261949 const int py = !vertical ? qy - 1 : qy;
458
2/2
✓ Branch 0 taken 4456050 times.
✓ Branch 1 taken 4805899 times.
9261949 const uint8_t *tb_size = vertical ? fc->tab.tb_width[LUMA] : fc->tab.tb_height[LUMA];
459 9261949 const int size_p = tb_size[(py >> MIN_TU_LOG2) * fc->ps.pps->min_tu_width + (px >> MIN_TU_LOG2)];
460 9261949 const int size_q = tb_size[(qy >> MIN_TU_LOG2) * fc->ps.pps->min_tu_width + (qx >> MIN_TU_LOG2)];
461 9261949 const int min_cb_log2 = fc->ps.sps->min_cb_log2_size_y;
462 9261949 const int off_p = (py >> min_cb_log2) * fc->ps.pps->min_cb_width + (px >> min_cb_log2);
463
4/4
✓ Branch 0 taken 7993159 times.
✓ Branch 1 taken 1268790 times.
✓ Branch 2 taken 590823 times.
✓ Branch 3 taken 7402336 times.
9261949 if (size_p <= 4 || size_q <= 4) {
464 1859613 *max_len_p = *max_len_q = 1;
465 } else {
466 7402336 *max_len_p = *max_len_q = 3;
467
2/2
✓ Branch 0 taken 4826848 times.
✓ Branch 1 taken 2575488 times.
7402336 if (size_p >= 32)
468 4826848 *max_len_p = 7;
469
2/2
✓ Branch 0 taken 4686842 times.
✓ Branch 1 taken 2715494 times.
7402336 if (size_q >= 32)
470 4686842 *max_len_q = 7;
471 }
472
2/2
✓ Branch 0 taken 1044424 times.
✓ Branch 1 taken 8217525 times.
9261949 if (has_subblock)
473 1044424 *max_len_q = FFMIN(5, *max_len_q);
474
4/4
✓ Branch 0 taken 8320823 times.
✓ Branch 1 taken 941126 times.
✓ Branch 2 taken 220664 times.
✓ Branch 3 taken 8100159 times.
9261949 if (fc->tab.msf[off_p] || fc->tab.iaf[off_p])
475 1161790 *max_len_p = FFMIN(5, *max_len_p);
476 9261949 }
477
478 144860 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 144860 const VVCFrameContext *fc = lc->fc;
482 144860 const MvField *tab_mvf = fc->tab.mvf;
483 144860 const RefPicList *rpl = lc->sc->rpl;
484 144860 int stridea = fc->ps.pps->min_pu_width;
485 144860 int strideb = 1;
486 144860 const int log2_min_pu_size = MIN_PU_LOG2;
487
488
2/2
✓ Branch 0 taken 72430 times.
✓ Branch 1 taken 72430 times.
144860 if (!vertical) {
489 72430 FFSWAP(int, x0, y0);
490 72430 FFSWAP(int, width, height);
491 72430 FFSWAP(int, stridea, strideb);
492 }
493
494 // bs for TU internal vertical PU boundaries
495
2/2
✓ Branch 0 taken 464562 times.
✓ Branch 1 taken 144860 times.
609422 for (int i = 8 - ((x0 - cb) % 8); i < width; i += 8) {
496 464562 const int is_vb = is_virtual_boundary(fc, x0 + i, vertical);
497 464562 const int xp_pu = (x0 + i - 1) >> log2_min_pu_size;
498 464562 const int xq_pu = (x0 + i) >> log2_min_pu_size;
499
500
2/2
✓ Branch 0 taken 5332726 times.
✓ Branch 1 taken 464562 times.
5797288 for (int j = 0; j < height; j += 4) {
501 5332726 const int y_pu = (y0 + j) >> log2_min_pu_size;
502 5332726 const MvField *mvf_p = &tab_mvf[y_pu * stridea + xp_pu * strideb];
503 5332726 const MvField *mvf_q = &tab_mvf[y_pu * stridea + xq_pu * strideb];
504
1/2
✓ Branch 0 taken 5332726 times.
✗ Branch 1 not taken.
5332726 const int bs = is_vb ? 0 : boundary_strength(lc, mvf_q, mvf_p, rpl);
505 5332726 int x = x0 + i;
506 5332726 int y = y0 + j;
507 5332726 uint8_t max_len_p = 0, max_len_q = 0;
508
509
2/2
✓ Branch 0 taken 2654620 times.
✓ Branch 1 taken 2678106 times.
5332726 if (!vertical)
510 2654620 FFSWAP(int, x, y);
511
512 5332726 TAB_BS(fc->tab.bs[vertical][LUMA], x, y) = bs;
513
514
4/4
✓ Branch 0 taken 5331546 times.
✓ Branch 1 taken 1180 times.
✓ Branch 2 taken 1480 times.
✓ Branch 3 taken 5330066 times.
5332726 if (i == 4 || i == width - 4)
515 2660 max_len_p = max_len_q = 1;
516
4/4
✓ Branch 0 taken 4254162 times.
✓ Branch 1 taken 1075904 times.
✓ Branch 2 taken 863486 times.
✓ Branch 3 taken 3390676 times.
5330066 else if (i == 8 || i == width - 8)
517 1939390 max_len_p = max_len_q = 2;
518 else
519 3390676 max_len_p = max_len_q = 3;
520
521 5332726 TAB_MAX_LEN(fc->tab.max_len_p[vertical], x, y) = max_len_p;
522 5332726 TAB_MAX_LEN(fc->tab.max_len_q[vertical], x, y) = max_len_q;
523 }
524 }
525 144860 }
526
527 36766485 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,
529 const RefPicList *rpl_p, const int c_idx, const int off_to_cb, const uint8_t has_sub_block)
530 {
531 36766485 const VVCFrameContext *fc = lc->fc;
532 36766485 const MvField *tab_mvf = fc->tab.mvf;
533 36766485 const int log2_min_pu_size = MIN_PU_LOG2;
534 36766485 const int log2_min_tu_size = MIN_TU_LOG2;
535 36766485 const int log2_min_cb_size = fc->ps.sps->min_cb_log2_size_y;
536 36766485 const int min_pu_width = fc->ps.pps->min_pu_width;
537 36766485 const int min_tu_width = fc->ps.pps->min_tu_width;
538 36766485 const int min_cb_width = fc->ps.pps->min_cb_width;
539 36766485 const int pu_p = (y_p >> log2_min_pu_size) * min_pu_width + (x_p >> log2_min_pu_size);
540 36766485 const int pu_q = (y_q >> log2_min_pu_size) * min_pu_width + (x_q >> log2_min_pu_size);
541 36766485 const MvField *mvf_p = &tab_mvf[pu_p];
542 36766485 const MvField *mvf_q = &tab_mvf[pu_q];
543 36766485 const uint8_t chroma = !!c_idx;
544 36766485 const int tu_p = (y_p >> log2_min_tu_size) * min_tu_width + (x_p >> log2_min_tu_size);
545 36766485 const int tu_q = (y_q >> log2_min_tu_size) * min_tu_width + (x_q >> log2_min_tu_size);
546
4/4
✓ Branch 0 taken 178 times.
✓ Branch 1 taken 36766307 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 167 times.
36766485 const uint8_t pcmf = fc->tab.pcmf[chroma][tu_p] && fc->tab.pcmf[chroma][tu_q];
547 36766485 const int cb_p = (y_p >> log2_min_cb_size) * min_cb_width + (x_p >> log2_min_cb_size);
548 36766485 const int cb_q = (y_q >> log2_min_cb_size) * min_cb_width + (x_q >> log2_min_cb_size);
549
4/4
✓ Branch 0 taken 29181361 times.
✓ Branch 1 taken 7585124 times.
✓ Branch 2 taken 616695 times.
✓ Branch 3 taken 28564666 times.
36766485 const uint8_t intra = fc->tab.cpm[chroma][cb_p] == MODE_INTRA || fc->tab.cpm[chroma][cb_q] == MODE_INTRA;
550 36766485 const uint8_t same_mode = fc->tab.cpm[chroma][cb_p] == fc->tab.cpm[chroma][cb_q];
551
552
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 36766474 times.
36766485 if (pcmf)
553 11 return 0;
554
555
6/6
✓ Branch 0 taken 28564666 times.
✓ Branch 1 taken 8201808 times.
✓ Branch 2 taken 28205410 times.
✓ Branch 3 taken 359256 times.
✓ Branch 4 taken 285370 times.
✓ Branch 5 taken 27920040 times.
36766474 if (intra || mvf_p->ciip_flag || mvf_q->ciip_flag)
556 8846434 return 2;
557
558
2/2
✓ Branch 0 taken 21702532 times.
✓ Branch 1 taken 6217508 times.
27920040 if (chroma) {
559 43029246 return fc->tab.tu_coded_flag[c_idx][tu_p] ||
560
2/2
✓ Branch 0 taken 21159382 times.
✓ Branch 1 taken 167332 times.
21326714 fc->tab.tu_coded_flag[c_idx][tu_q] ||
561
4/4
✓ Branch 0 taken 21326714 times.
✓ Branch 1 taken 375818 times.
✓ Branch 2 taken 21136794 times.
✓ Branch 3 taken 22588 times.
64166040 fc->tab.tu_joint_cbcr_residual_flag[tu_p] ||
562
2/2
✓ Branch 0 taken 19964 times.
✓ Branch 1 taken 21116830 times.
21136794 fc->tab.tu_joint_cbcr_residual_flag[tu_q];
563 }
564
565
4/4
✓ Branch 0 taken 5529077 times.
✓ Branch 1 taken 688431 times.
✓ Branch 2 taken 342176 times.
✓ Branch 3 taken 5186901 times.
6217508 if (fc->tab.tu_coded_flag[LUMA][tu_p] || fc->tab.tu_coded_flag[LUMA][tu_q])
566 1030607 return 1;
567
568
6/6
✓ Branch 0 taken 1325249 times.
✓ Branch 1 taken 3861652 times.
✓ Branch 2 taken 1317210 times.
✓ Branch 3 taken 8039 times.
✓ Branch 4 taken 1124032 times.
✓ Branch 5 taken 193178 times.
5186901 if ((off_to_cb && ((off_to_cb % 8) || !has_sub_block)))
569 1132071 return 0; // inside a cu, not aligned to 8 or with no subblocks
570
571
2/2
✓ Branch 0 taken 135 times.
✓ Branch 1 taken 4054695 times.
4054830 if (!same_mode)
572 135 return 1;
573
574 4054695 return boundary_strength(lc, mvf_q, mvf_p, rpl_p);
575 }
576
577 3235986 static int deblock_is_boundary(const VVCLocalContext *lc, const int boundary,
578 const int pos, const int rs, const int vertical)
579 {
580 3235986 const VVCFrameContext *fc = lc->fc;
581 3235986 const H266RawSPS *rsps = fc->ps.sps->r;
582 3235986 const H266RawPPS *rpps = fc->ps.pps->r;
583 int flag;
584
4/4
✓ Branch 0 taken 2877345 times.
✓ Branch 1 taken 358641 times.
✓ Branch 2 taken 507380 times.
✓ Branch 3 taken 2369965 times.
3235986 if (boundary && (pos % fc->ps.sps->ctb_size_y) == 0) {
585
2/2
✓ Branch 0 taken 271608 times.
✓ Branch 1 taken 235772 times.
507380 flag = vertical ? BOUNDARY_LEFT_SLICE : BOUNDARY_UPPER_SLICE;
586
2/2
✓ Branch 0 taken 17213 times.
✓ Branch 1 taken 490167 times.
507380 if (lc->boundary_flags & flag &&
587
2/2
✓ Branch 0 taken 6215 times.
✓ Branch 1 taken 10998 times.
17213 !rpps->pps_loop_filter_across_slices_enabled_flag)
588 6215 return 0;
589
590
2/2
✓ Branch 0 taken 268310 times.
✓ Branch 1 taken 232855 times.
501165 flag = vertical ? BOUNDARY_LEFT_TILE : BOUNDARY_UPPER_TILE;
591
2/2
✓ Branch 0 taken 14396 times.
✓ Branch 1 taken 486769 times.
501165 if (lc->boundary_flags & flag &&
592
2/2
✓ Branch 0 taken 1295 times.
✓ Branch 1 taken 13101 times.
14396 !rpps->pps_loop_filter_across_tiles_enabled_flag)
593 1295 return 0;
594
595
2/2
✓ Branch 0 taken 267445 times.
✓ Branch 1 taken 232425 times.
499870 flag = vertical ? BOUNDARY_LEFT_SUBPIC : BOUNDARY_UPPER_SUBPIC;
596
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 499870 times.
499870 if (lc->boundary_flags & flag) {
597 const int q_rs = rs - (vertical ? 1 : fc->ps.pps->ctb_width);
598 const SliceContext *q_slice = lc->fc->slices[lc->fc->tab.slice_idx[q_rs]];
599
600 if (!rsps->sps_loop_filter_across_subpic_enabled_flag[q_slice->sh.r->curr_subpic_idx] ||
601 !rsps->sps_loop_filter_across_subpic_enabled_flag[lc->sc->sh.r->curr_subpic_idx])
602 return 0;
603 }
604 }
605 3228476 return boundary;
606 }
607
608 1966586 static void vvc_deblock_bs_luma(const VVCLocalContext *lc,
609 const int x0, const int y0, const int width, const int height, const int rs, const int vertical)
610 {
611 1966586 const VVCFrameContext *fc = lc->fc;
612 1966586 const MvField *tab_mvf = fc->tab.mvf;
613 1966586 const int mask = LUMA_GRID - 1;
614 1966586 const int log2_min_pu_size = MIN_PU_LOG2;
615 1966586 const int min_pu_width = fc->ps.pps->min_pu_width;
616 1966586 const int min_cb_log2 = fc->ps.sps->min_cb_log2_size_y;
617 1966586 const int min_cb_width = fc->ps.pps->min_cb_width;
618
2/2
✓ Branch 0 taken 983293 times.
✓ Branch 1 taken 983293 times.
1966586 const int pos = vertical ? x0 : y0;
619 1966586 const int off_q = (y0 >> min_cb_log2) * min_cb_width + (x0 >> min_cb_log2);
620
2/2
✓ Branch 0 taken 983293 times.
✓ Branch 1 taken 983293 times.
1966586 const int cb = (vertical ? fc->tab.cb_pos_x : fc->tab.cb_pos_y )[LUMA][off_q];
621 1966586 const int is_intra = tab_mvf[(y0 >> log2_min_pu_size) * min_pu_width +
622 1966586 (x0 >> log2_min_pu_size)].pred_flag == PF_INTRA;
623
624
5/6
✓ Branch 0 taken 1923170 times.
✓ Branch 1 taken 43416 times.
✓ Branch 2 taken 1923170 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1918765 times.
✓ Branch 6 taken 47821 times.
1966586 if (deblock_is_boundary(lc, pos > 0 && !(pos & mask), pos, rs, vertical)) {
625 1918765 const int is_vb = is_virtual_boundary(fc, pos, vertical);
626
2/2
✓ Branch 0 taken 964041 times.
✓ Branch 1 taken 954724 times.
1918765 const int size = vertical ? height : width;
627 1918765 const int off = cb - pos;
628
2/2
✓ Branch 0 taken 964041 times.
✓ Branch 1 taken 954724 times.
1918765 const int cb_size = (vertical ? fc->tab.cb_width : fc->tab.cb_height)[LUMA][off_q];
629
8/8
✓ Branch 0 taken 965704 times.
✓ Branch 1 taken 953061 times.
✓ Branch 2 taken 848330 times.
✓ Branch 3 taken 117374 times.
✓ Branch 4 taken 22108 times.
✓ Branch 5 taken 826222 times.
✓ Branch 6 taken 114869 times.
✓ Branch 7 taken 24613 times.
1918765 const int has_sb = !is_intra && (fc->tab.msf[off_q] || fc->tab.iaf[off_q]) && cb_size > 8;
630
2/2
✓ Branch 0 taken 964041 times.
✓ Branch 1 taken 954724 times.
1918765 const int flag = vertical ? BOUNDARY_LEFT_SLICE : BOUNDARY_UPPER_SLICE;
631 1918765 const RefPicList *rpl_p =
632
2/2
✓ Branch 0 taken 51546 times.
✓ Branch 1 taken 1867219 times.
1918765 (lc->boundary_flags & flag) ? ff_vvc_get_ref_list(fc, fc->ref, x0 - vertical, y0 - !vertical) : lc->sc->rpl;
633
634
2/2
✓ Branch 0 taken 9261949 times.
✓ Branch 1 taken 1918765 times.
11180714 for (int i = 0; i < size; i += 4) {
635 9261949 const int x = x0 + i * !vertical;
636 9261949 const int y = y0 + i * vertical;
637 uint8_t max_len_p, max_len_q;
638
1/2
✓ Branch 0 taken 9261949 times.
✗ Branch 1 not taken.
9261949 const int bs = is_vb ? 0 : deblock_bs(lc, x - vertical, y - !vertical, x, y, rpl_p, LUMA, off, has_sb);
639
640 9261949 TAB_BS(fc->tab.bs[vertical][LUMA], x, y) = bs;
641
642 9261949 derive_max_filter_length_luma(fc, x, y, is_intra, has_sb, vertical, &max_len_p, &max_len_q);
643 9261949 TAB_MAX_LEN(fc->tab.max_len_p[vertical], x, y) = max_len_p;
644 9261949 TAB_MAX_LEN(fc->tab.max_len_q[vertical], x, y) = max_len_q;
645 }
646 }
647
648
2/2
✓ Branch 0 taken 999368 times.
✓ Branch 1 taken 967218 times.
1966586 if (!is_intra) {
649
4/4
✓ Branch 0 taken 878326 times.
✓ Branch 1 taken 121042 times.
✓ Branch 2 taken 23818 times.
✓ Branch 3 taken 854508 times.
999368 if (fc->tab.msf[off_q] || fc->tab.iaf[off_q])
650 144860 vvc_deblock_subblock_bs(lc, cb, x0, y0, width, height, vertical);
651 }
652 1966586 }
653
654 1269400 static void vvc_deblock_bs_chroma(const VVCLocalContext *lc,
655 const int x0, const int y0, const int width, const int height, const int rs, const int vertical)
656 {
657 1269400 const VVCFrameContext *fc = lc->fc;
658
2/2
✓ Branch 0 taken 634700 times.
✓ Branch 1 taken 634700 times.
1269400 const int shift = (vertical ? fc->ps.sps->hshift : fc->ps.sps->vshift)[CHROMA];
659 1269400 const int mask = (CHROMA_GRID << shift) - 1;
660
2/2
✓ Branch 0 taken 634700 times.
✓ Branch 1 taken 634700 times.
1269400 const int pos = vertical ? x0 : y0;
661
662
6/6
✓ Branch 0 taken 1233431 times.
✓ Branch 1 taken 35969 times.
✓ Branch 2 taken 954175 times.
✓ Branch 3 taken 279256 times.
✓ Branch 5 taken 951070 times.
✓ Branch 6 taken 318330 times.
1269400 if (deblock_is_boundary(lc, pos > 0 && !(pos & mask), pos, rs, vertical)) {
663 951070 const int is_vb = is_virtual_boundary(fc, pos, vertical);
664
2/2
✓ Branch 0 taken 474666 times.
✓ Branch 1 taken 476404 times.
951070 const int size = vertical ? height : width;
665
666
2/2
✓ Branch 0 taken 1902140 times.
✓ Branch 1 taken 951070 times.
2853210 for (int c_idx = CB; c_idx <= CR; c_idx++) {
667
2/2
✓ Branch 0 taken 27504536 times.
✓ Branch 1 taken 1902140 times.
29406676 for (int i = 0; i < size; i += 2) {
668 27504536 const int x = x0 + i * !vertical;
669 27504536 const int y = y0 + i * vertical;
670
1/2
✓ Branch 0 taken 27504536 times.
✗ Branch 1 not taken.
27504536 const int bs = is_vb ? 0 : deblock_bs(lc, x - vertical, y - !vertical, x, y, NULL, c_idx, 0, 0);
671
672 27504536 TAB_BS(fc->tab.bs[vertical][c_idx], x, y) = bs;
673 }
674 }
675 }
676 1269400 }
677
678 typedef void (*deblock_bs_fn)(const VVCLocalContext *lc, const int x0, const int y0,
679 const int width, const int height, const int rs, const int vertical);
680
681 86366 static void vvc_deblock_bs(const VVCLocalContext *lc, const int x0, const int y0, const int rs, const int vertical)
682 {
683 86366 const VVCFrameContext *fc = lc->fc;
684 86366 const VVCSPS *sps = fc->ps.sps;
685 86366 const VVCPPS *pps = fc->ps.pps;
686 86366 const int ctb_size = sps->ctb_size_y;
687 86366 const int x_end = FFMIN(x0 + ctb_size, pps->width) >> MIN_TU_LOG2;
688 86366 const int y_end = FFMIN(y0 + ctb_size, pps->height) >> MIN_TU_LOG2;
689 86366 deblock_bs_fn deblock_bs[] = {
690 vvc_deblock_bs_luma, vvc_deblock_bs_chroma
691 };
692
693
2/2
✓ Branch 0 taken 172732 times.
✓ Branch 1 taken 86366 times.
259098 for (int is_chroma = 0; is_chroma <= 1; is_chroma++) {
694 172732 const int hs = sps->hshift[is_chroma];
695 172732 const int vs = sps->vshift[is_chroma];
696
2/2
✓ Branch 0 taken 5152760 times.
✓ Branch 1 taken 172732 times.
5325492 for (int y = y0 >> MIN_TU_LOG2; y < y_end; y++) {
697
2/2
✓ Branch 0 taken 160836480 times.
✓ Branch 1 taken 5152760 times.
165989240 for (int x = x0 >> MIN_TU_LOG2; x < x_end; x++) {
698 160836480 const int off = y * fc->ps.pps->min_tu_width + x;
699
4/4
✓ Branch 0 taken 17187798 times.
✓ Branch 1 taken 143648682 times.
✓ Branch 2 taken 3235986 times.
✓ Branch 3 taken 13951812 times.
160836480 if ((fc->tab.tb_pos_x0[is_chroma][off] >> MIN_TU_LOG2) == x && (fc->tab.tb_pos_y0[is_chroma][off] >> MIN_TU_LOG2) == y) {
700 3235986 deblock_bs[is_chroma](lc, x << MIN_TU_LOG2, y << MIN_TU_LOG2,
701 3235986 fc->tab.tb_width[is_chroma][off] << hs, fc->tab.tb_height[is_chroma][off] << vs, rs, vertical);
702 }
703 }
704 }
705 }
706 86366 }
707
708 //part of 8.8.3.3 Derivation process of transform block boundary
709 6182572 static void max_filter_length_luma(const VVCFrameContext *fc, const int qx, const int qy,
710 const int vertical, uint8_t *max_len_p, uint8_t *max_len_q)
711 {
712 6182572 *max_len_p = TAB_MAX_LEN(fc->tab.max_len_p[vertical], qx, qy);
713 6182572 *max_len_q = TAB_MAX_LEN(fc->tab.max_len_q[vertical], qx, qy);
714 6182572 }
715
716 //part of 8.8.3.3 Derivation process of transform block boundary
717 3193853 static void max_filter_length_chroma(const VVCFrameContext *fc, const int qx, const int qy,
718 const int vertical, const int horizontal_ctu_edge, const int bs, uint8_t *max_len_p, uint8_t *max_len_q)
719 {
720
2/2
✓ Branch 0 taken 1548210 times.
✓ Branch 1 taken 1645643 times.
3193853 const int px = vertical ? qx - 1 : qx;
721
2/2
✓ Branch 0 taken 1645643 times.
✓ Branch 1 taken 1548210 times.
3193853 const int py = !vertical ? qy - 1 : qy;
722
2/2
✓ Branch 0 taken 1548210 times.
✓ Branch 1 taken 1645643 times.
3193853 const uint8_t *tb_size = vertical ? fc->tab.tb_width[CHROMA] : fc->tab.tb_height[CHROMA];
723
724 3193853 const int size_p = tb_size[(py >> MIN_TU_LOG2) * fc->ps.pps->min_tu_width + (px >> MIN_TU_LOG2)];
725 3193853 const int size_q = tb_size[(qy >> MIN_TU_LOG2) * fc->ps.pps->min_tu_width + (qx >> MIN_TU_LOG2)];
726
4/4
✓ Branch 0 taken 2643930 times.
✓ Branch 1 taken 549923 times.
✓ Branch 2 taken 2285607 times.
✓ Branch 3 taken 358323 times.
3193853 if (size_p >= 8 && size_q >= 8) {
727 2285607 *max_len_p = *max_len_q = 3;
728
2/2
✓ Branch 0 taken 286611 times.
✓ Branch 1 taken 1998996 times.
2285607 if (horizontal_ctu_edge)
729 286611 *max_len_p = 1;
730 } else {
731 //part of 8.8.3.6.4 Decision process for chroma block edges
732 908246 *max_len_p = *max_len_q = (bs == 2);
733 }
734 3193853 }
735
736 9376425 static void max_filter_length(const VVCFrameContext *fc, const int qx, const int qy,
737 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)
738 {
739
2/2
✓ Branch 0 taken 6182572 times.
✓ Branch 1 taken 3193853 times.
9376425 if (!c_idx)
740 6182572 max_filter_length_luma(fc, qx, qy, vertical, max_len_p, max_len_q);
741 else
742 3193853 max_filter_length_chroma(fc, qx, qy, vertical, horizontal_ctu_edge, bs, max_len_p, max_len_q);
743 9376425 }
744
745 #define TC_CALC(qp, bs) \
746 tctable[av_clip((qp) + DEFAULT_INTRA_TC_OFFSET * ((bs) - 1) + \
747 (tc_offset & -2), \
748 0, MAX_QP + DEFAULT_INTRA_TC_OFFSET)]
749
750 // part of 8.8.3.6.2 Decision process for luma block edges
751 6182572 static int get_qp_y(const VVCFrameContext *fc, const uint8_t *src, const int x, const int y, const int vertical)
752 {
753 6182572 const VVCSPS *sps = fc->ps.sps;
754 6182572 const int qp = (ff_vvc_get_qPy(fc, x - vertical, y - !vertical) + ff_vvc_get_qPy(fc, x, y) + 1) >> 1;
755 6182572 int qp_offset = 0;
756 int level;
757
758
1/2
✓ Branch 0 taken 6182572 times.
✗ Branch 1 not taken.
6182572 if (!sps->r->sps_ladf_enabled_flag)
759 6182572 return qp;
760
761 level = fc->vvcdsp.lf.ladf_level[vertical](src, fc->frame->linesize[LUMA]);
762 qp_offset = sps->r->sps_ladf_lowest_interval_qp_offset;
763 for (int i = 0; i < sps->num_ladf_intervals - 1 && level > sps->ladf_interval_lower_bound[i + 1]; i++)
764 qp_offset = sps->r->sps_ladf_qp_offset[i];
765
766 return qp + qp_offset;
767 }
768
769 // part of 8.8.3.6.2 Decision process for luma block edges
770 3193853 static int get_qp_c(const VVCFrameContext *fc, const int x, const int y, const int c_idx, const int vertical)
771 {
772 3193853 const VVCSPS *sps = fc->ps.sps;
773 3193853 return (get_qPc(fc, x - vertical, y - !vertical, c_idx) + get_qPc(fc, x, y, c_idx) - 2 * sps->qp_bd_offset + 1) >> 1;
774 }
775
776 9376425 static int get_qp(const VVCFrameContext *fc, const uint8_t *src, const int x, const int y, const int c_idx, const int vertical)
777 {
778
2/2
✓ Branch 0 taken 6182572 times.
✓ Branch 1 taken 3193853 times.
9376425 if (!c_idx)
779 6182572 return get_qp_y(fc, src, x, y, vertical);
780 3193853 return get_qp_c(fc, x, y, c_idx, vertical);
781 }
782
783 86366 static void vvc_deblock(const VVCLocalContext *lc, int x0, int y0, const int rs, const int vertical)
784 {
785 86366 VVCFrameContext *fc = lc->fc;
786 86366 const VVCSPS *sps = fc->ps.sps;
787
2/2
✓ Branch 0 taken 85326 times.
✓ Branch 1 taken 1040 times.
86366 const int c_end = sps->r->sps_chroma_format_idc ? VVC_MAX_SAMPLE_ARRAYS : 1;
788 86366 const int ctb_size = fc->ps.sps->ctb_size_y;
789 86366 const DBParams *params = fc->tab.deblock + rs;
790 86366 int x_end = FFMIN(x0 + ctb_size, fc->ps.pps->width);
791 86366 int y_end = FFMIN(y0 + ctb_size, fc->ps.pps->height);
792
793 //not use this yet, may needed by plt.
794 86366 const uint8_t no_p[4] = { 0 };
795 86366 const uint8_t no_q[4] = { 0 } ;
796
797 86366 vvc_deblock_bs(lc, x0, y0, rs, vertical);
798
799
2/2
✓ Branch 0 taken 43183 times.
✓ Branch 1 taken 43183 times.
86366 if (!vertical) {
800 43183 FFSWAP(int, x_end, y_end);
801 43183 FFSWAP(int, x0, y0);
802 }
803
804
2/2
✓ Branch 0 taken 257018 times.
✓ Branch 1 taken 86366 times.
343384 for (int c_idx = 0; c_idx < c_end; c_idx++) {
805
2/2
✓ Branch 0 taken 128509 times.
✓ Branch 1 taken 128509 times.
257018 const int hs = (vertical ? sps->hshift : sps->vshift)[c_idx];
806
2/2
✓ Branch 0 taken 128509 times.
✓ Branch 1 taken 128509 times.
257018 const int vs = (vertical ? sps->vshift : sps->hshift)[c_idx];
807
2/2
✓ Branch 0 taken 170652 times.
✓ Branch 1 taken 86366 times.
257018 const int grid = c_idx ? (CHROMA_GRID << hs) : LUMA_GRID;
808 257018 const int tc_offset = params->tc_offset[c_idx];
809 257018 const int beta_offset = params->beta_offset[c_idx];
810 257018 const int src_stride = fc->frame->linesize[c_idx];
811
812
2/2
✓ Branch 0 taken 3041111 times.
✓ Branch 1 taken 257018 times.
3298129 for (int y = y0; y < y_end; y += (DEBLOCK_STEP << vs)) {
813
4/4
✓ Branch 0 taken 2691556 times.
✓ Branch 1 taken 349555 times.
✓ Branch 2 taken 59665085 times.
✓ Branch 3 taken 3041111 times.
62706196 for (int x = x0 ? x0 : grid; x < x_end; x += grid) {
814
4/4
✓ Branch 0 taken 29784156 times.
✓ Branch 1 taken 29880929 times.
✓ Branch 2 taken 1330692 times.
✓ Branch 3 taken 28453464 times.
59665085 const uint8_t horizontal_ctu_edge = !vertical && !(x % ctb_size);
815 59665085 int32_t bs[4], beta[4], tc[4] = { 0 }, all_zero_bs = 1;
816 uint8_t max_len_p[4], max_len_q[4];
817
818
2/2
✓ Branch 0 taken 132531254 times.
✓ Branch 1 taken 59665085 times.
192196339 for (int i = 0; i < DEBLOCK_STEP >> (2 - vs); i++) {
819 132531254 int tx = x;
820 132531254 int ty = y + (i << 2);
821 132531254 const int end = ty >= y_end;
822
823
2/2
✓ Branch 0 taken 66137168 times.
✓ Branch 1 taken 66394086 times.
132531254 if (!vertical)
824 66137168 FFSWAP(int, tx, ty);
825
826
2/2
✓ Branch 0 taken 132456998 times.
✓ Branch 1 taken 74256 times.
132531254 bs[i] = end ? 0 : TAB_BS(fc->tab.bs[vertical][c_idx], tx, ty);
827
2/2
✓ Branch 0 taken 9376425 times.
✓ Branch 1 taken 123154829 times.
132531254 if (bs[i]) {
828 9376425 const int qp = get_qp(fc, POS(c_idx, tx, ty), tx, ty, c_idx, vertical);
829 9376425 beta[i] = betatable[av_clip(qp + beta_offset, 0, MAX_QP)];
830 9376425 tc[i] = TC_CALC(qp, bs[i]) ;
831 9376425 max_filter_length(fc, tx, ty, c_idx, vertical, horizontal_ctu_edge, bs[i], &max_len_p[i], &max_len_q[i]);
832 9376425 all_zero_bs = 0;
833 }
834 }
835
836
2/2
✓ Branch 0 taken 4119278 times.
✓ Branch 1 taken 55545807 times.
59665085 if (!all_zero_bs) {
837
2/2
✓ Branch 0 taken 2007676 times.
✓ Branch 1 taken 2111602 times.
4119278 uint8_t *src = vertical ? POS(c_idx, x, y) : POS(c_idx, y, x);
838
2/2
✓ Branch 0 taken 3154061 times.
✓ Branch 1 taken 965217 times.
4119278 if (!c_idx)
839 3154061 fc->vvcdsp.lf.filter_luma[vertical](src, src_stride, beta, tc, no_p, no_q, max_len_p, max_len_q, horizontal_ctu_edge);
840 else
841 965217 fc->vvcdsp.lf.filter_chroma[vertical](src, src_stride, beta, tc, no_p, no_q, max_len_p, max_len_q, vs);
842 }
843 }
844 }
845 }
846 86366 }
847
848 43183 void ff_vvc_deblock_vertical(const VVCLocalContext *lc, const int x0, const int y0, const int rs)
849 {
850 43183 vvc_deblock(lc, x0, y0, rs, 1);
851 43183 }
852
853 43183 void ff_vvc_deblock_horizontal(const VVCLocalContext *lc, const int x0, const int y0, const int rs)
854 {
855 43183 vvc_deblock(lc, x0, y0, rs, 0);
856 43183 }
857
858 545663 static void alf_copy_border(uint8_t *dst, const uint8_t *src,
859 const int pixel_shift, int width, const int height, const ptrdiff_t dst_stride, const ptrdiff_t src_stride)
860 {
861 545663 width <<= pixel_shift;
862
2/2
✓ Branch 0 taken 27576723 times.
✓ Branch 1 taken 545663 times.
28122386 for (int i = 0; i < height; i++) {
863 27576723 memcpy(dst, src, width);
864 27576723 dst += dst_stride;
865 27576723 src += src_stride;
866 }
867 545663 }
868
869 8168 static void alf_extend_vert(uint8_t *_dst, const uint8_t *_src,
870 const int pixel_shift, const int width, const int height, ptrdiff_t stride)
871 {
872
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8168 times.
8168 if (pixel_shift == 0) {
873 for (int i = 0; i < height; i++) {
874 memset(_dst, *_src, width);
875 _src += stride;
876 _dst += stride;
877 }
878 } else {
879 8168 const uint16_t *src = (const uint16_t *)_src;
880 8168 uint16_t *dst = (uint16_t *)_dst;
881 8168 stride >>= pixel_shift;
882
883
2/2
✓ Branch 0 taken 797026 times.
✓ Branch 1 taken 8168 times.
805194 for (int i = 0; i < height; i++) {
884
2/2
✓ Branch 0 taken 2061514 times.
✓ Branch 1 taken 797026 times.
2858540 for (int j = 0; j < width; j++)
885 2061514 dst[j] = *src;
886 797026 src += stride;
887 797026 dst += stride;
888 }
889 }
890 8168 }
891
892 39301 static void alf_extend_horz(uint8_t *dst, const uint8_t *src,
893 const int pixel_shift, int width, const int height, const ptrdiff_t stride)
894 {
895 39301 width <<= pixel_shift;
896
2/2
✓ Branch 0 taken 97085 times.
✓ Branch 1 taken 39301 times.
136386 for (int i = 0; i < height; i++) {
897 97085 memcpy(dst, src, width);
898 97085 dst += stride;
899 }
900 39301 }
901
902 102868 static void alf_copy_ctb_to_hv(VVCFrameContext *fc, const uint8_t *src, const ptrdiff_t src_stride,
903 const int x, const int y, const int width, const int height, const int rx, const int ry, const int c_idx)
904 {
905 102868 const int ps = fc->ps.sps->pixel_shift;
906 102868 const int w = fc->ps.pps->width >> fc->ps.sps->hshift[c_idx];
907 102868 const int h = fc->ps.pps->height >> fc->ps.sps->vshift[c_idx];
908
2/2
✓ Branch 0 taken 34636 times.
✓ Branch 1 taken 68232 times.
102868 const int border_pixels = (c_idx == 0) ? ALF_BORDER_LUMA : ALF_BORDER_CHROMA;
909 102868 const int offset_h[] = { 0, height - border_pixels };
910 102868 const int offset_v[] = { 0, width - border_pixels };
911
912 /* copy horizontal edges */
913
2/2
✓ Branch 0 taken 205736 times.
✓ Branch 1 taken 102868 times.
308604 for (int i = 0; i < FF_ARRAY_ELEMS(offset_h); i++) {
914 205736 alf_copy_border(fc->tab.alf_pixel_buffer_h[c_idx][i] + ((border_pixels * ry * w + x)<< ps),
915 205736 src + offset_h[i] * src_stride, ps, width, border_pixels, w << ps, src_stride);
916 }
917 /* copy vertical edges */
918
2/2
✓ Branch 0 taken 205736 times.
✓ Branch 1 taken 102868 times.
308604 for (int i = 0; i < FF_ARRAY_ELEMS(offset_v); i++) {
919 205736 alf_copy_border(fc->tab.alf_pixel_buffer_v[c_idx][i] + ((h * rx + y) * (border_pixels << ps)),
920 205736 src + (offset_v[i] << ps), ps, border_pixels, height, border_pixels << ps, src_stride);
921 }
922 102868 }
923
924 78586 static void alf_fill_border_h(uint8_t *dst, const ptrdiff_t dst_stride, const uint8_t *src, const ptrdiff_t src_stride,
925 const uint8_t *border, const int width, const int border_pixels, const int ps, const int edge)
926 {
927
2/2
✓ Branch 0 taken 14813 times.
✓ Branch 1 taken 63773 times.
78586 if (edge)
928 14813 alf_extend_horz(dst, border, ps, width, border_pixels, dst_stride);
929 else
930 63773 alf_copy_border(dst, src, ps, width, border_pixels, dst_stride, src_stride);
931 78586 }
932
933 78586 static void alf_fill_border_v(uint8_t *dst, const ptrdiff_t dst_stride, const uint8_t *src,
934 const uint8_t *border, const int border_pixels, const int height, const int pixel_shift, const int *edges, const int edge)
935 {
936 78586 const ptrdiff_t src_stride = (border_pixels << pixel_shift);
937
938
2/2
✓ Branch 0 taken 8168 times.
✓ Branch 1 taken 70418 times.
78586 if (edge) {
939 8168 alf_extend_vert(dst, border, pixel_shift, border_pixels, height + 2 * border_pixels, dst_stride);
940 8168 return;
941 }
942
943 //left/right
944 70418 alf_copy_border(dst + dst_stride * border_pixels * edges[TOP], src + src_stride * border_pixels * edges[TOP],
945 70418 pixel_shift, border_pixels, height + (!edges[TOP] + !edges[BOTTOM]) * border_pixels, dst_stride, src_stride);
946
947 //top left/right
948
2/2
✓ Branch 0 taken 11017 times.
✓ Branch 1 taken 59401 times.
70418 if (edges[TOP])
949 11017 alf_extend_horz(dst, dst + dst_stride * border_pixels, pixel_shift, border_pixels, border_pixels, dst_stride);
950
951 //bottom left/right
952
2/2
✓ Branch 0 taken 13471 times.
✓ Branch 1 taken 56947 times.
70418 if (edges[BOTTOM]) {
953 13471 dst += dst_stride * (border_pixels + height);
954 13471 alf_extend_horz(dst, dst - dst_stride, pixel_shift, border_pixels, border_pixels, dst_stride);
955 }
956 }
957
958 39293 static void alf_prepare_buffer(VVCFrameContext *fc, uint8_t *_dst, const uint8_t *_src, const int x, const int y,
959 const int rx, const int ry, const int width, const int height, const ptrdiff_t dst_stride, const ptrdiff_t src_stride,
960 const int c_idx, const int *edges)
961 {
962 39293 const int ps = fc->ps.sps->pixel_shift;
963 39293 const int w = fc->ps.pps->width >> fc->ps.sps->hshift[c_idx];
964 39293 const int h = fc->ps.pps->height >> fc->ps.sps->vshift[c_idx];
965
2/2
✓ Branch 0 taken 18225 times.
✓ Branch 1 taken 21068 times.
39293 const int border_pixels = c_idx == 0 ? ALF_BORDER_LUMA : ALF_BORDER_CHROMA;
966 uint8_t *dst, *src;
967
968 39293 copy_ctb(_dst, _src, width << ps, height, dst_stride, src_stride);
969
970 //top
971 39293 src = fc->tab.alf_pixel_buffer_h[c_idx][1] + (((border_pixels * w) << ps) * (ry - 1) + (x << ps));
972 39293 dst = _dst - border_pixels * dst_stride;
973 39293 alf_fill_border_h(dst, dst_stride, src, w << ps, _dst, width, border_pixels, ps, edges[TOP]);
974
975 //bottom
976 39293 src = fc->tab.alf_pixel_buffer_h[c_idx][0] + (((border_pixels * w) << ps) * (ry + 1) + (x << ps));
977 39293 dst = _dst + height * dst_stride;
978 39293 alf_fill_border_h(dst, dst_stride, src, w << ps, _dst + (height - 1) * dst_stride, width, border_pixels, ps, edges[BOTTOM]);
979
980
981 //left
982 39293 src = fc->tab.alf_pixel_buffer_v[c_idx][1] + (h * (rx - 1) + y - border_pixels) * (border_pixels << ps);
983 39293 dst = _dst - (border_pixels << ps) - border_pixels * dst_stride;
984 39293 alf_fill_border_v(dst, dst_stride, src, dst + (border_pixels << ps), border_pixels, height, ps, edges, edges[LEFT]);
985
986 //right
987 39293 src = fc->tab.alf_pixel_buffer_v[c_idx][0] + (h * (rx + 1) + y - border_pixels) * (border_pixels << ps);
988 39293 dst = _dst + (width << ps) - border_pixels * dst_stride;
989 39293 alf_fill_border_v(dst, dst_stride, src, dst - (1 << ps), border_pixels, height, ps, edges, edges[RIGHT]);
990 39293 }
991
992 #define ALF_MAX_BLOCKS_IN_CTU (MAX_CTU_SIZE * MAX_CTU_SIZE / ALF_BLOCK_SIZE / ALF_BLOCK_SIZE)
993 #define ALF_MAX_FILTER_SIZE (ALF_MAX_BLOCKS_IN_CTU * ALF_NUM_COEFF_LUMA)
994
995 17746 static void alf_get_coeff_and_clip(VVCLocalContext *lc, int16_t *coeff, int16_t *clip,
996 const uint8_t *src, ptrdiff_t src_stride, int width, int height, int vb_pos, const ALFParams *alf)
997 {
998 17746 const VVCFrameContext *fc = lc->fc;
999 17746 const H266RawSliceHeader *rsh = lc->sc->sh.r;
1000 17746 uint8_t fixed_clip_set[ALF_NUM_FILTERS_LUMA][ALF_NUM_COEFF_LUMA] = { 0 };
1001 const int16_t *coeff_set;
1002 const uint8_t *clip_idx_set;
1003 const uint8_t *class_to_filt;
1004 17746 const int size = width * height / ALF_BLOCK_SIZE / ALF_BLOCK_SIZE;
1005 int class_idx[ALF_MAX_BLOCKS_IN_CTU];
1006 int transpose_idx[ALF_MAX_BLOCKS_IN_CTU];
1007
1008
2/2
✓ Branch 0 taken 2378 times.
✓ Branch 1 taken 15368 times.
17746 if (alf->ctb_filt_set_idx_y < 16) {
1009 2378 coeff_set = &ff_vvc_alf_fix_filt_coeff[0][0];
1010 2378 clip_idx_set = &fixed_clip_set[0][0];
1011 2378 class_to_filt = ff_vvc_alf_class_to_filt_map[alf->ctb_filt_set_idx_y];
1012 } else {
1013 15368 const int id = rsh->sh_alf_aps_id_luma[alf->ctb_filt_set_idx_y - 16];
1014 15368 const VVCALF *aps = fc->ps.alf_list[id];
1015 15368 coeff_set = &aps->luma_coeff[0][0];
1016 15368 clip_idx_set = &aps->luma_clip_idx[0][0];
1017 15368 class_to_filt = ff_vvc_alf_aps_class_to_filt_map;
1018 }
1019 17746 fc->vvcdsp.alf.classify(class_idx, transpose_idx, src, src_stride, width, height,
1020 17746 vb_pos, lc->alf_gradient_tmp);
1021 17746 fc->vvcdsp.alf.recon_coeff_and_clip(coeff, clip, class_idx, transpose_idx, size,
1022 coeff_set, clip_idx_set, class_to_filt);
1023 17746 }
1024
1025 17746 static void alf_filter_luma(VVCLocalContext *lc, uint8_t *dst, const uint8_t *src,
1026 const ptrdiff_t dst_stride, const ptrdiff_t src_stride, const int x0, const int y0,
1027 const int width, const int height, const int _vb_pos, const ALFParams *alf)
1028 {
1029 17746 const VVCFrameContext *fc = lc->fc;
1030 17746 int vb_pos = _vb_pos - y0;
1031 17746 int16_t *coeff = (int16_t*)lc->tmp;
1032 17746 int16_t *clip = (int16_t *)lc->tmp1;
1033
1034 av_assert0(ALF_MAX_FILTER_SIZE <= sizeof(lc->tmp));
1035 av_assert0(ALF_MAX_FILTER_SIZE * sizeof(int16_t) <= sizeof(lc->tmp1));
1036
1037 17746 alf_get_coeff_and_clip(lc, coeff, clip, src, src_stride, width, height, vb_pos, alf);
1038 17746 fc->vvcdsp.alf.filter[LUMA](dst, dst_stride, src, src_stride, width, height, coeff, clip, vb_pos);
1039 17746 }
1040
1041 126408 static int alf_clip_from_idx(const VVCFrameContext *fc, const int idx)
1042 {
1043 126408 const VVCSPS *sps = fc->ps.sps;
1044 126408 const int offset[] = {0, 3, 5, 7};
1045
1046 126408 return 1 << (sps->bit_depth - offset[idx]);
1047 }
1048
1049 21068 static void alf_filter_chroma(VVCLocalContext *lc, uint8_t *dst, const uint8_t *src,
1050 const ptrdiff_t dst_stride, const ptrdiff_t src_stride, const int c_idx,
1051 const int width, const int height, const int vb_pos, const ALFParams *alf)
1052 {
1053 21068 VVCFrameContext *fc = lc->fc;
1054 21068 const H266RawSliceHeader *rsh = lc->sc->sh.r;
1055 21068 const VVCALF *aps = fc->ps.alf_list[rsh->sh_alf_aps_id_chroma];
1056 21068 const int idx = alf->alf_ctb_filter_alt_idx[c_idx - 1];
1057 21068 const int16_t *coeff = aps->chroma_coeff[idx];
1058 int16_t clip[ALF_NUM_COEFF_CHROMA];
1059
1060
2/2
✓ Branch 0 taken 126408 times.
✓ Branch 1 taken 21068 times.
147476 for (int i = 0; i < ALF_NUM_COEFF_CHROMA; i++)
1061 126408 clip[i] = alf_clip_from_idx(fc, aps->chroma_clip_idx[idx][i]);
1062
1063 21068 fc->vvcdsp.alf.filter[CHROMA](dst, dst_stride, src, src_stride, width, height, coeff, clip, vb_pos);
1064 21068 }
1065
1066 8365 static void alf_filter_cc(VVCLocalContext *lc, uint8_t *dst, const uint8_t *luma,
1067 const ptrdiff_t dst_stride, const ptrdiff_t luma_stride, const int c_idx,
1068 const int width, const int height, const int hs, const int vs, const int vb_pos, const ALFParams *alf)
1069 {
1070 8365 const VVCFrameContext *fc = lc->fc;
1071 8365 const H266RawSliceHeader *rsh = lc->sc->sh.r;
1072 8365 const int idx = c_idx - 1;
1073
2/2
✓ Branch 0 taken 4332 times.
✓ Branch 1 taken 4033 times.
8365 const int cc_aps_id = c_idx == CB ? rsh->sh_alf_cc_cb_aps_id : rsh->sh_alf_cc_cr_aps_id;
1074 8365 const VVCALF *aps = fc->ps.alf_list[cc_aps_id];
1075
1076
1/2
✓ Branch 0 taken 8365 times.
✗ Branch 1 not taken.
8365 if (aps) {
1077 8365 const int16_t *coeff = aps->cc_coeff[idx][alf->ctb_cc_idc[idx] - 1];
1078
1079 8365 fc->vvcdsp.alf.filter_cc(dst, dst_stride, luma, luma_stride, width, height, hs, vs, coeff, vb_pos);
1080 }
1081 8365 }
1082
1083 34636 void ff_vvc_alf_copy_ctu_to_hv(VVCLocalContext* lc, const int x0, const int y0)
1084 {
1085 34636 VVCFrameContext *fc = lc->fc;
1086 34636 const int rx = x0 >> fc->ps.sps->ctb_log2_size_y;
1087 34636 const int ry = y0 >> fc->ps.sps->ctb_log2_size_y;
1088 34636 const int ctb_size_y = fc->ps.sps->ctb_size_y;
1089
2/2
✓ Branch 0 taken 34116 times.
✓ Branch 1 taken 520 times.
34636 const int c_end = fc->ps.sps->r->sps_chroma_format_idc ? VVC_MAX_SAMPLE_ARRAYS : 1;
1090
1091
2/2
✓ Branch 0 taken 102868 times.
✓ Branch 1 taken 34636 times.
137504 for (int c_idx = 0; c_idx < c_end; c_idx++) {
1092 102868 const int hs = fc->ps.sps->hshift[c_idx];
1093 102868 const int vs = fc->ps.sps->vshift[c_idx];
1094 102868 const int x = x0 >> hs;
1095 102868 const int y = y0 >> vs;
1096 102868 const int width = FFMIN(fc->ps.pps->width - x0, ctb_size_y) >> hs;
1097 102868 const int height = FFMIN(fc->ps.pps->height - y0, ctb_size_y) >> vs;
1098
1099 102868 const int src_stride = fc->frame->linesize[c_idx];
1100 102868 uint8_t *src = POS(c_idx, x0, y0);
1101
1102 102868 alf_copy_ctb_to_hv(fc, src, src_stride, x, y, width, height, rx, ry, c_idx);
1103 }
1104 34636 }
1105
1106 34636 static void alf_get_edges(const VVCLocalContext *lc, int edges[MAX_EDGES], const int rx, const int ry)
1107 {
1108 34636 VVCFrameContext *fc = lc->fc;
1109 34636 const VVCSPS *sps = fc->ps.sps;
1110 34636 const VVCPPS *pps = fc->ps.pps;
1111 34636 const int subpic_idx = lc->sc->sh.r->curr_subpic_idx;
1112
1113 // we can't use |= instead of || in this function; |= is not a shortcut operator
1114
1115
2/2
✓ Branch 0 taken 31801 times.
✓ Branch 1 taken 2835 times.
34636 if (!pps->r->pps_loop_filter_across_tiles_enabled_flag) {
1116
4/4
✓ Branch 0 taken 28726 times.
✓ Branch 1 taken 3075 times.
✓ Branch 2 taken 333 times.
✓ Branch 3 taken 28393 times.
31801 edges[LEFT] = edges[LEFT] || (lc->boundary_flags & BOUNDARY_LEFT_TILE);
1117
4/4
✓ Branch 0 taken 26284 times.
✓ Branch 1 taken 5517 times.
✓ Branch 2 taken 282 times.
✓ Branch 3 taken 26002 times.
31801 edges[TOP] = edges[TOP] || (lc->boundary_flags & BOUNDARY_UPPER_TILE);
1118
4/4
✓ Branch 0 taken 28726 times.
✓ Branch 1 taken 3075 times.
✓ Branch 2 taken 333 times.
✓ Branch 3 taken 28393 times.
31801 edges[RIGHT] = edges[RIGHT] || pps->ctb_to_col_bd[rx] != pps->ctb_to_col_bd[rx + 1];
1119
4/4
✓ Branch 0 taken 26284 times.
✓ Branch 1 taken 5517 times.
✓ Branch 2 taken 282 times.
✓ Branch 3 taken 26002 times.
31801 edges[BOTTOM] = edges[BOTTOM] || pps->ctb_to_row_bd[ry] != pps->ctb_to_row_bd[ry + 1];
1120 }
1121
1122
2/2
✓ Branch 0 taken 31801 times.
✓ Branch 1 taken 2835 times.
34636 if (!pps->r->pps_loop_filter_across_slices_enabled_flag) {
1123
3/4
✓ Branch 0 taken 28393 times.
✓ Branch 1 taken 3408 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 28393 times.
31801 edges[LEFT] = edges[LEFT] || (lc->boundary_flags & BOUNDARY_LEFT_SLICE);
1124
4/4
✓ Branch 0 taken 26002 times.
✓ Branch 1 taken 5799 times.
✓ Branch 2 taken 30 times.
✓ Branch 3 taken 25972 times.
31801 edges[TOP] = edges[TOP] || (lc->boundary_flags & BOUNDARY_UPPER_SLICE);
1125
3/4
✓ Branch 0 taken 28393 times.
✓ Branch 1 taken 3408 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 28393 times.
31801 edges[RIGHT] = edges[RIGHT] || CTB(fc->tab.slice_idx, rx, ry) != CTB(fc->tab.slice_idx, rx + 1, ry);
1126
4/4
✓ Branch 0 taken 26002 times.
✓ Branch 1 taken 5799 times.
✓ Branch 2 taken 30 times.
✓ Branch 3 taken 25972 times.
31801 edges[BOTTOM] = edges[BOTTOM] || CTB(fc->tab.slice_idx, rx, ry) != CTB(fc->tab.slice_idx, rx, ry + 1);
1127 }
1128
1129
1/2
✓ Branch 0 taken 34636 times.
✗ Branch 1 not taken.
34636 if (!sps->r->sps_loop_filter_across_subpic_enabled_flag[subpic_idx]) {
1130
3/4
✓ Branch 0 taken 31039 times.
✓ Branch 1 taken 3597 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 31039 times.
34636 edges[LEFT] = edges[LEFT] || (lc->boundary_flags & BOUNDARY_LEFT_SUBPIC);
1131
3/4
✓ Branch 0 taken 28492 times.
✓ Branch 1 taken 6144 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 28492 times.
34636 edges[TOP] = edges[TOP] || (lc->boundary_flags & BOUNDARY_UPPER_SUBPIC);
1132
3/4
✓ Branch 0 taken 31039 times.
✓ Branch 1 taken 3597 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 31039 times.
34636 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;
1133
3/4
✓ Branch 0 taken 28492 times.
✓ Branch 1 taken 6144 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 28492 times.
34636 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;
1134 }
1135
1136
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 34636 times.
34636 if (sps->r->sps_virtual_boundaries_enabled_flag) {
1137 edges[LEFT] = edges[LEFT] || is_virtual_boundary(fc, rx << sps->ctb_log2_size_y, 1);
1138 edges[TOP] = edges[TOP] || is_virtual_boundary(fc, ry << sps->ctb_log2_size_y, 0);
1139 edges[RIGHT] = edges[RIGHT] || is_virtual_boundary(fc, (rx + 1) << sps->ctb_log2_size_y, 1);
1140 edges[BOTTOM] = edges[BOTTOM] || is_virtual_boundary(fc, (ry + 1) << sps->ctb_log2_size_y, 0);
1141 }
1142 34636 }
1143
1144 34636 static void alf_init_subblock(VVCRect *sb, int sb_edges[MAX_EDGES], const VVCRect *b, const int edges[MAX_EDGES])
1145 {
1146 34636 *sb = *b;
1147 34636 memcpy(sb_edges, edges, sizeof(int) * MAX_EDGES);
1148 34636 }
1149
1150 34636 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])
1151 {
1152 34636 int *pos[] = { &sb->l, &sb->t, &sb->r, &sb->b };
1153
1154
2/2
✓ Branch 0 taken 69272 times.
✓ Branch 1 taken 34636 times.
103908 for (int vertical = 0; vertical <= 1; vertical++) {
1155
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 69272 times.
69272 if (has_vb[vertical]) {
1156 const int c = vertical ? (bx ? LEFT : RIGHT) : (by ? TOP : BOTTOM);
1157 *pos[c] = vb_pos[vertical];
1158 edges[c] = 1;
1159 }
1160 }
1161 34636 }
1162
1163 34636 static void alf_get_subblocks(const VVCLocalContext *lc, VVCRect sbs[MAX_VBBS], int sb_edges[MAX_VBBS][MAX_EDGES], int *nb_sbs,
1164 const int x0, const int y0, const int rx, const int ry)
1165 {
1166 34636 VVCFrameContext *fc = lc->fc;
1167 34636 const VVCSPS *sps = fc->ps.sps;
1168 34636 const VVCPPS *pps = fc->ps.pps;
1169 34636 const int ctu_size_y = sps->ctb_size_y;
1170 34636 const int vb_pos[] = { get_virtual_boundary(fc, ry, 0), get_virtual_boundary(fc, rx, 1) };
1171 34636 const int has_vb[] = { vb_pos[0] > y0, vb_pos[1] > x0 };
1172 34636 const VVCRect b = { x0, y0, FFMIN(x0 + ctu_size_y, pps->width), FFMIN(y0 + ctu_size_y, pps->height) };
1173 34636 int edges[MAX_EDGES] = { !rx, !ry, rx == pps->ctb_width - 1, ry == pps->ctb_height - 1 };
1174 34636 int i = 0;
1175
1176 34636 alf_get_edges(lc, edges, rx, ry);
1177
1178
2/2
✓ Branch 0 taken 34636 times.
✓ Branch 1 taken 34636 times.
69272 for (int by = 0; by <= has_vb[0]; by++) {
1179
2/2
✓ Branch 0 taken 34636 times.
✓ Branch 1 taken 34636 times.
69272 for (int bx = 0; bx <= has_vb[1]; bx++, i++) {
1180 34636 alf_init_subblock(sbs + i, sb_edges[i], &b, edges);
1181 34636 alf_get_subblock(sbs + i, sb_edges[i], bx, by, vb_pos, has_vb);
1182 }
1183 }
1184 34636 *nb_sbs = i;
1185 34636 }
1186
1187 34636 void ff_vvc_alf_filter(VVCLocalContext *lc, const int x0, const int y0)
1188 {
1189 34636 VVCFrameContext *fc = lc->fc;
1190 34636 const VVCSPS *sps = fc->ps.sps;
1191 34636 const int rx = x0 >> sps->ctb_log2_size_y;
1192 34636 const int ry = y0 >> sps->ctb_log2_size_y;
1193 34636 const int ps = sps->pixel_shift;
1194 34636 const int padded_stride = EDGE_EMU_BUFFER_STRIDE << ps;
1195 34636 const int padded_offset = padded_stride * ALF_PADDING_SIZE + (ALF_PADDING_SIZE << ps);
1196
2/2
✓ Branch 0 taken 34116 times.
✓ Branch 1 taken 520 times.
34636 const int c_end = sps->r->sps_chroma_format_idc ? VVC_MAX_SAMPLE_ARRAYS : 1;
1197 34636 const int ctu_end = y0 + sps->ctb_size_y;
1198 34636 const ALFParams *alf = &CTB(fc->tab.alf, rx, ry);
1199 int sb_edges[MAX_VBBS][MAX_EDGES], nb_sbs;
1200 VVCRect sbs[MAX_VBBS];
1201
1202 34636 alf_get_subblocks(lc, sbs, sb_edges, &nb_sbs, x0, y0, rx, ry);
1203
1204
2/2
✓ Branch 0 taken 34636 times.
✓ Branch 1 taken 34636 times.
69272 for (int i = 0; i < nb_sbs; i++) {
1205 34636 const VVCRect *sb = sbs + i;
1206
2/2
✓ Branch 0 taken 102868 times.
✓ Branch 1 taken 34636 times.
137504 for (int c_idx = 0; c_idx < c_end; c_idx++) {
1207 102868 const int hs = fc->ps.sps->hshift[c_idx];
1208 102868 const int vs = fc->ps.sps->vshift[c_idx];
1209 102868 const int x = sb->l >> hs;
1210 102868 const int y = sb->t >> vs;
1211 102868 const int width = (sb->r - sb->l) >> hs;
1212 102868 const int height = (sb->b - sb->t) >> vs;
1213 102868 const int src_stride = fc->frame->linesize[c_idx];
1214 102868 uint8_t *src = POS(c_idx, sb->l, sb->t);
1215 uint8_t *padded;
1216
1217
8/8
✓ Branch 0 taken 64054 times.
✓ Branch 1 taken 38814 times.
✓ Branch 2 taken 16890 times.
✓ Branch 3 taken 47164 times.
✓ Branch 4 taken 16482 times.
✓ Branch 5 taken 408 times.
✓ Branch 6 taken 71 times.
✓ Branch 7 taken 16411 times.
102868 if (alf->ctb_flag[c_idx] || (!c_idx && (alf->ctb_cc_idc[0] || alf->ctb_cc_idc[1]))) {
1218
2/2
✓ Branch 0 taken 21068 times.
✓ Branch 1 taken 18225 times.
39293 padded = (c_idx ? lc->alf_buffer_chroma : lc->alf_buffer_luma) + padded_offset;
1219 39293 alf_prepare_buffer(fc, padded, src, x, y, rx, ry, width, height,
1220 39293 padded_stride, src_stride, c_idx, sb_edges[i]);
1221 }
1222
2/2
✓ Branch 0 taken 38814 times.
✓ Branch 1 taken 64054 times.
102868 if (alf->ctb_flag[c_idx]) {
1223
2/2
✓ Branch 0 taken 17746 times.
✓ Branch 1 taken 21068 times.
38814 if (!c_idx) {
1224 17746 alf_filter_luma(lc, src, padded, src_stride, padded_stride, x, y,
1225 width, height, ctu_end - ALF_VB_POS_ABOVE_LUMA, alf);
1226 } else {
1227 21068 alf_filter_chroma(lc, src, padded, src_stride, padded_stride, c_idx,
1228 21068 width, height, ((ctu_end - sb->t) >> vs) - ALF_VB_POS_ABOVE_CHROMA, alf);
1229 }
1230 }
1231
4/4
✓ Branch 0 taken 68232 times.
✓ Branch 1 taken 34636 times.
✓ Branch 2 taken 8365 times.
✓ Branch 3 taken 59867 times.
102868 if (c_idx && alf->ctb_cc_idc[c_idx - 1]) {
1232 8365 padded = lc->alf_buffer_luma + padded_offset;
1233 8365 alf_filter_cc(lc, src, padded, src_stride, padded_stride, c_idx,
1234 8365 width, height, hs, vs, ctu_end - sb->t - ALF_VB_POS_ABOVE_LUMA, alf);
1235 }
1236 }
1237 }
1238 34636 }
1239
1240
1241 43183 void ff_vvc_lmcs_filter(const VVCLocalContext *lc, const int x, const int y)
1242 {
1243 43183 const SliceContext *sc = lc->sc;
1244 43183 const VVCFrameContext *fc = lc->fc;
1245 43183 const int ctb_size = fc->ps.sps->ctb_size_y;
1246 43183 const int width = FFMIN(fc->ps.pps->width - x, ctb_size);
1247 43183 const int height = FFMIN(fc->ps.pps->height - y, ctb_size);
1248 43183 uint8_t *data = POS(LUMA, x, y);
1249
2/2
✓ Branch 0 taken 18884 times.
✓ Branch 1 taken 24299 times.
43183 if (sc->sh.r->sh_lmcs_used_flag)
1250 18884 fc->vvcdsp.lmcs.filter(data, fc->frame->linesize[LUMA], width, height, &fc->ps.lmcs.inv_lut);
1251 43183 }
1252