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 | 5032201 | static int get_virtual_boundary(const VVCFrameContext *fc, const int ctu_pos, const int vertical) | |
63 | { | ||
64 | 5032201 | const VVCSPS *sps = fc->ps.sps; | |
65 | 5032201 | const VVCPH *ph = &fc->ps.ph; | |
66 |
2/2✓ Branch 0 taken 2549475 times.
✓ Branch 1 taken 2482726 times.
|
5032201 | const uint16_t *vbs = vertical ? ph->vb_pos_x : ph->vb_pos_y; |
67 |
2/2✓ Branch 0 taken 2549475 times.
✓ Branch 1 taken 2482726 times.
|
5032201 | const uint8_t nb_vbs = vertical ? ph->num_ver_vbs : ph->num_hor_vbs; |
68 | 5032201 | const int pos = ctu_pos << sps->ctb_log2_size_y; | |
69 | |||
70 |
2/2✓ Branch 0 taken 329281 times.
✓ Branch 1 taken 4702920 times.
|
5032201 | if (sps->r->sps_virtual_boundaries_enabled_flag) { |
71 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 329281 times.
|
329281 | for (int i = 0; i < nb_vbs; i++) { |
72 | ✗ | const int o = vbs[i] - pos; | |
73 | ✗ | if (o >= 0 && o < sps->ctb_size_y) | |
74 | ✗ | return vbs[i]; | |
75 | } | ||
76 | } | ||
77 | 5032201 | return 0; | |
78 | } | ||
79 | |||
80 | 4943509 | static int is_virtual_boundary(const VVCFrameContext *fc, const int pos, const int vertical) | |
81 | { | ||
82 | 4943509 | return get_virtual_boundary(fc, pos >> fc->ps.sps->ctb_log2_size_y, vertical) == pos; | |
83 | } | ||
84 | |||
85 | 9287456 | static int get_qPc(const VVCFrameContext *fc, const int x0, const int y0, const int chroma) | |
86 | { | ||
87 | 9287456 | const int x = x0 >> MIN_TU_LOG2; | |
88 | 9287456 | const int y = y0 >> MIN_TU_LOG2; | |
89 | 9287456 | const int min_tu_width = fc->ps.pps->min_tu_width; | |
90 | 9287456 | return fc->tab.qp[chroma][x + y * min_tu_width]; | |
91 | } | ||
92 | |||
93 | 57715 | 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 5647556 times.
✓ Branch 1 taken 57715 times.
|
5705271 | for (int y = 0; y < height; y++) { |
97 | 5647556 | memcpy(dst, src, width); | |
98 | |||
99 | 5647556 | dst += dst_stride; | |
100 | 5647556 | src += src_stride; | |
101 | } | ||
102 | 57715 | } | |
103 | |||
104 | 30739 | static void copy_pixel(uint8_t *dst, const uint8_t *src, const int pixel_shift) | |
105 | { | ||
106 |
2/2✓ Branch 0 taken 28523 times.
✓ Branch 1 taken 2216 times.
|
30739 | if (pixel_shift) |
107 | 28523 | *(uint16_t *)dst = *(uint16_t *)src; | |
108 | else | ||
109 | 2216 | *dst = *src; | |
110 | 30739 | } | |
111 | |||
112 | 333797 | 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 325054 times.
|
333797 | 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 31299864 times.
✓ Branch 1 taken 325054 times.
|
31624918 | for (i = 0; i < height; i++) { |
124 | 31299864 | *(uint16_t *)dst = *(uint16_t *)src; | |
125 | 31299864 | dst += dst_stride; | |
126 | 31299864 | src += src_stride; | |
127 | } | ||
128 | } | ||
129 | 333797 | } | |
130 | |||
131 | 315498 | 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 | 315498 | const int ps = fc->ps.sps->pixel_shift; | |
136 | 315498 | const int w = fc->ps.pps->width >> fc->ps.sps->hshift[c_idx]; | |
137 | 315498 | const int h = fc->ps.pps->height >> fc->ps.sps->vshift[c_idx]; | |
138 | |||
139 |
2/2✓ Branch 0 taken 157749 times.
✓ Branch 1 taken 157749 times.
|
315498 | if (top) { |
140 | /* top */ | ||
141 | 157749 | memcpy(fc->tab.sao_pixel_buffer_h[c_idx] + (((2 * ry) * w + x) << ps), | |
142 | 157749 | src, width << ps); | |
143 | } else { | ||
144 | /* bottom */ | ||
145 | 157749 | memcpy(fc->tab.sao_pixel_buffer_h[c_idx] + (((2 * ry + 1) * w + x) << ps), | |
146 | 157749 | src + src_stride * (height - 1), width << ps); | |
147 | |||
148 | /* copy vertical edges */ | ||
149 | 157749 | copy_vert(fc->tab.sao_pixel_buffer_v[c_idx] + (((2 * rx) * h + y) << ps), src, ps, height, 1 << ps, src_stride); | |
150 | 157749 | 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 | 315498 | } | |
153 | |||
154 | 105870 | static void sao_copy_ctb_to_hv(VVCLocalContext *lc, const int rx, const int ry, const int top) | |
155 | { | ||
156 | 105870 | VVCFrameContext *fc = lc->fc; | |
157 | 105870 | const int ctb_size_y = fc->ps.sps->ctb_size_y; | |
158 | 105870 | const int x0 = rx << fc->ps.sps->ctb_log2_size_y; | |
159 | 105870 | const int y0 = ry << fc->ps.sps->ctb_log2_size_y; | |
160 | |||
161 |
4/4✓ Branch 0 taken 419256 times.
✓ Branch 1 taken 2112 times.
✓ Branch 2 taken 315498 times.
✓ Branch 3 taken 105870 times.
|
421368 | for (int c_idx = 0; c_idx < (fc->ps.sps->r->sps_chroma_format_idc ? 3 : 1); c_idx++) { |
162 | 315498 | const int x = x0 >> fc->ps.sps->hshift[c_idx]; | |
163 | 315498 | const int y = y0 >> fc->ps.sps->vshift[c_idx]; | |
164 | 315498 | const ptrdiff_t src_stride = fc->frame->linesize[c_idx]; | |
165 | 315498 | const int ctb_size_h = ctb_size_y >> fc->ps.sps->hshift[c_idx]; | |
166 | 315498 | const int ctb_size_v = ctb_size_y >> fc->ps.sps->vshift[c_idx]; | |
167 | 315498 | const int width = FFMIN(ctb_size_h, (fc->ps.pps->width >> fc->ps.sps->hshift[c_idx]) - x); | |
168 | 315498 | const int height = FFMIN(ctb_size_v, (fc->ps.pps->height >> fc->ps.sps->vshift[c_idx]) - y); | |
169 | 315498 | const uint8_t *src = POS(c_idx, x0, y0); | |
170 | 315498 | copy_ctb_to_hv(fc, src, src_stride, x, y, width, height, c_idx, rx, ry, top); | |
171 | } | ||
172 | 105870 | } | |
173 | |||
174 | 52935 | 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 44592 times.
✓ Branch 1 taken 8343 times.
|
52935 | if (ry) |
177 | 44592 | sao_copy_ctb_to_hv(lc, rx, ry - 1, 0); | |
178 | |||
179 | 52935 | sao_copy_ctb_to_hv(lc, rx, ry, 1); | |
180 | |||
181 |
2/2✓ Branch 0 taken 8343 times.
✓ Branch 1 taken 44592 times.
|
52935 | if (last_row) |
182 | 8343 | sao_copy_ctb_to_hv(lc, rx, ry, 0); | |
183 | 52935 | } | |
184 | |||
185 | 328090 | static int sao_can_cross_slices(const VVCFrameContext *fc, const int rx, const int ry, const int dx, const int dy) | |
186 | { | ||
187 | 328090 | const uint8_t lfase = fc->ps.pps->r->pps_loop_filter_across_slices_enabled_flag; | |
188 | |||
189 |
4/4✓ Branch 0 taken 324970 times.
✓ Branch 1 taken 3120 times.
✓ Branch 2 taken 322238 times.
✓ Branch 3 taken 2732 times.
|
328090 | return lfase || CTB(fc->tab.slice_idx, rx, ry) == CTB(fc->tab.slice_idx, rx + dx, ry + dy); |
190 | } | ||
191 | |||
192 | 52935 | 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 | 52935 | const VVCFrameContext *fc = lc->fc; | |
196 | 52935 | const VVCSPS *sps = fc->ps.sps; | |
197 | 52935 | const H266RawSPS *rsps = sps->r; | |
198 | 52935 | const VVCPPS *pps = fc->ps.pps; | |
199 | 52935 | const int subpic_idx = lc->sc->sh.r->curr_subpic_idx; | |
200 | 52935 | const uint8_t lfase = fc->ps.pps->r->pps_loop_filter_across_slices_enabled_flag; | |
201 |
4/4✓ Branch 0 taken 5081 times.
✓ Branch 1 taken 47854 times.
✓ Branch 2 taken 1662 times.
✓ Branch 3 taken 3419 times.
|
52935 | const uint8_t no_tile_filter = pps->r->num_tiles_in_pic > 1 && !pps->r->pps_loop_filter_across_tiles_enabled_flag; |
202 |
4/4✓ Branch 0 taken 2103 times.
✓ Branch 1 taken 50832 times.
✓ Branch 2 taken 1137 times.
✓ Branch 3 taken 966 times.
|
52935 | const uint8_t no_subpic_filter = rsps->sps_num_subpics_minus1 && !rsps->sps_loop_filter_across_subpic_enabled_flag[subpic_idx]; |
203 | 52935 | uint8_t lf_edge[] = { 0, 0, 0, 0 }; | |
204 | |||
205 |
8/8✓ Branch 0 taken 51798 times.
✓ Branch 1 taken 1137 times.
✓ Branch 2 taken 51246 times.
✓ Branch 3 taken 552 times.
✓ Branch 4 taken 3162 times.
✓ Branch 5 taken 48084 times.
✓ Branch 6 taken 184 times.
✓ Branch 7 taken 2978 times.
|
52935 | *restore = no_subpic_filter || no_tile_filter || !lfase || rsps->sps_virtual_boundaries_enabled_flag; |
206 | |||
207 |
2/2✓ Branch 0 taken 2978 times.
✓ Branch 1 taken 49957 times.
|
52935 | if (!*restore) |
208 | 2978 | return; | |
209 | |||
210 |
2/2✓ Branch 0 taken 45357 times.
✓ Branch 1 taken 4600 times.
|
49957 | if (!edges[LEFT]) { |
211 |
4/4✓ Branch 0 taken 1458 times.
✓ Branch 1 taken 43899 times.
✓ Branch 2 taken 612 times.
✓ Branch 3 taken 846 times.
|
45357 | lf_edge[LEFT] = no_tile_filter && pps->ctb_to_col_bd[rx] == rx; |
212 |
4/4✓ Branch 0 taken 1017 times.
✓ Branch 1 taken 44340 times.
✓ Branch 2 taken 309 times.
✓ Branch 3 taken 708 times.
|
45357 | lf_edge[LEFT] |= no_subpic_filter && rsps->sps_subpic_ctu_top_left_x[subpic_idx] == rx; |
213 | 45357 | lf_edge[LEFT] |= is_virtual_boundary(fc, rx << sps->ctb_log2_size_y, 1); | |
214 |
4/4✓ Branch 1 taken 45058 times.
✓ Branch 2 taken 299 times.
✓ Branch 3 taken 322 times.
✓ Branch 4 taken 44736 times.
|
45357 | vert_edge[0] = !sao_can_cross_slices(fc, rx, ry, -1, 0) || lf_edge[LEFT]; |
215 | } | ||
216 |
2/2✓ Branch 0 taken 45357 times.
✓ Branch 1 taken 4600 times.
|
49957 | if (!edges[RIGHT]) { |
217 |
4/4✓ Branch 0 taken 1458 times.
✓ Branch 1 taken 43899 times.
✓ Branch 2 taken 612 times.
✓ Branch 3 taken 846 times.
|
45357 | lf_edge[RIGHT] = no_tile_filter && pps->ctb_to_col_bd[rx] != pps->ctb_to_col_bd[rx + 1]; |
218 |
4/4✓ Branch 0 taken 996 times.
✓ Branch 1 taken 44361 times.
✓ Branch 2 taken 288 times.
✓ Branch 3 taken 708 times.
|
45357 | lf_edge[RIGHT] |= no_subpic_filter && rsps->sps_subpic_ctu_top_left_x[subpic_idx] + rsps->sps_subpic_width_minus1[subpic_idx] == rx; |
219 | 45357 | lf_edge[RIGHT] |= is_virtual_boundary(fc, (rx + 1) << sps->ctb_log2_size_y, 1); | |
220 |
4/4✓ Branch 1 taken 45058 times.
✓ Branch 2 taken 299 times.
✓ Branch 3 taken 318 times.
✓ Branch 4 taken 44740 times.
|
45357 | vert_edge[1] = !sao_can_cross_slices(fc, rx, ry, 1, 0) || lf_edge[RIGHT]; |
221 | } | ||
222 |
2/2✓ Branch 0 taken 41948 times.
✓ Branch 1 taken 8009 times.
|
49957 | if (!edges[TOP]) { |
223 |
4/4✓ Branch 0 taken 1356 times.
✓ Branch 1 taken 40592 times.
✓ Branch 2 taken 564 times.
✓ Branch 3 taken 792 times.
|
41948 | lf_edge[TOP] = no_tile_filter && pps->ctb_to_row_bd[ry] == ry; |
224 |
4/4✓ Branch 0 taken 852 times.
✓ Branch 1 taken 41096 times.
✓ Branch 2 taken 222 times.
✓ Branch 3 taken 630 times.
|
41948 | lf_edge[TOP] |= no_subpic_filter && rsps->sps_subpic_ctu_top_left_y[subpic_idx] == ry; |
225 | 41948 | lf_edge[TOP] |= is_virtual_boundary(fc, ry << sps->ctb_log2_size_y, 0); | |
226 |
4/4✓ Branch 1 taken 41595 times.
✓ Branch 2 taken 353 times.
✓ Branch 3 taken 282 times.
✓ Branch 4 taken 41313 times.
|
41948 | horiz_edge[0] = !sao_can_cross_slices(fc, rx, ry, 0, -1) || lf_edge[TOP]; |
227 | } | ||
228 |
2/2✓ Branch 0 taken 41948 times.
✓ Branch 1 taken 8009 times.
|
49957 | if (!edges[BOTTOM]) { |
229 |
4/4✓ Branch 0 taken 1356 times.
✓ Branch 1 taken 40592 times.
✓ Branch 2 taken 564 times.
✓ Branch 3 taken 792 times.
|
41948 | lf_edge[BOTTOM] = no_tile_filter && pps->ctb_to_row_bd[ry] != pps->ctb_to_row_bd[ry + 1]; |
230 |
4/4✓ Branch 0 taken 915 times.
✓ Branch 1 taken 41033 times.
✓ Branch 2 taken 285 times.
✓ Branch 3 taken 630 times.
|
41948 | lf_edge[BOTTOM] |= no_subpic_filter && rsps->sps_subpic_ctu_top_left_y[subpic_idx] + rsps->sps_subpic_height_minus1[subpic_idx] == ry; |
231 | 41948 | lf_edge[BOTTOM] |= is_virtual_boundary(fc, (ry + 1) << sps->ctb_log2_size_y, 0); | |
232 |
4/4✓ Branch 1 taken 41595 times.
✓ Branch 2 taken 353 times.
✓ Branch 3 taken 294 times.
✓ Branch 4 taken 41301 times.
|
41948 | horiz_edge[1] = !sao_can_cross_slices(fc, rx, ry, 0, 1) || lf_edge[BOTTOM]; |
233 | } | ||
234 | |||
235 |
4/4✓ Branch 0 taken 45357 times.
✓ Branch 1 taken 4600 times.
✓ Branch 2 taken 38370 times.
✓ Branch 3 taken 6987 times.
|
49957 | if (!edges[LEFT] && !edges[TOP]) |
236 |
6/6✓ Branch 1 taken 38013 times.
✓ Branch 2 taken 357 times.
✓ Branch 3 taken 37761 times.
✓ Branch 4 taken 252 times.
✓ Branch 5 taken 144 times.
✓ Branch 6 taken 37617 times.
|
38370 | 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 41948 times.
✓ Branch 1 taken 8009 times.
✓ Branch 2 taken 38370 times.
✓ Branch 3 taken 3578 times.
|
49957 | if (!edges[TOP] && !edges[RIGHT]) |
239 |
6/6✓ Branch 1 taken 38013 times.
✓ Branch 2 taken 357 times.
✓ Branch 3 taken 37761 times.
✓ Branch 4 taken 252 times.
✓ Branch 5 taken 144 times.
✓ Branch 6 taken 37617 times.
|
38370 | 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 45357 times.
✓ Branch 1 taken 4600 times.
✓ Branch 2 taken 38370 times.
✓ Branch 3 taken 6987 times.
|
49957 | if (!edges[RIGHT] && !edges[BOTTOM]) |
242 |
6/6✓ Branch 1 taken 38013 times.
✓ Branch 2 taken 357 times.
✓ Branch 3 taken 37761 times.
✓ Branch 4 taken 252 times.
✓ Branch 5 taken 152 times.
✓ Branch 6 taken 37609 times.
|
38370 | 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 45357 times.
✓ Branch 1 taken 4600 times.
✓ Branch 2 taken 38370 times.
✓ Branch 3 taken 6987 times.
|
49957 | if (!edges[LEFT] && !edges[BOTTOM]) |
245 |
6/6✓ Branch 1 taken 38013 times.
✓ Branch 2 taken 357 times.
✓ Branch 3 taken 37757 times.
✓ Branch 4 taken 256 times.
✓ Branch 5 taken 152 times.
✓ Branch 6 taken 37605 times.
|
38370 | diag_edge[3] = !sao_can_cross_slices(fc, rx, ry, -1, 1) || lf_edge[LEFT] || lf_edge[BOTTOM]; |
246 | } | ||
247 | |||
248 | 16738 | 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 | 16738 | const int left = 1 - edges[LEFT]; | |
252 | 16738 | const int right = 1 - edges[RIGHT]; | |
253 | 16738 | int pos = 0; | |
254 | |||
255 | 16738 | src -= left << ps; | |
256 | 16738 | dst -= left << ps; | |
257 | |||
258 |
2/2✓ Branch 0 taken 15291 times.
✓ Branch 1 taken 1447 times.
|
16738 | if (left) { |
259 | 15291 | copy_pixel(dst, src, ps); | |
260 | 15291 | pos += (1 << ps); | |
261 | } | ||
262 | 16738 | memcpy(dst + pos, src + pos, width << ps); | |
263 |
2/2✓ Branch 0 taken 15448 times.
✓ Branch 1 taken 1290 times.
|
16738 | if (right) { |
264 | 15448 | pos += width << ps; | |
265 | 15448 | copy_pixel(dst + pos, src + pos, ps); | |
266 | } | ||
267 | 16738 | } | |
268 | |||
269 | 10076 | 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 | 10076 | const uint8_t *sao_h = fc->tab.sao_pixel_buffer_h[c_idx]; | |
274 | 10076 | const uint8_t *sao_v = fc->tab.sao_pixel_buffer_v[c_idx]; | |
275 | 10076 | const int x = x0 >> fc->ps.sps->hshift[c_idx]; | |
276 | 10076 | const int y = y0 >> fc->ps.sps->vshift[c_idx]; | |
277 | 10076 | const int w = fc->ps.pps->width >> fc->ps.sps->hshift[c_idx]; | |
278 | 10076 | const int h = fc->ps.pps->height >> fc->ps.sps->vshift[c_idx]; | |
279 | 10076 | const int ps = fc->ps.sps->pixel_shift; | |
280 | |||
281 |
2/2✓ Branch 0 taken 8376 times.
✓ Branch 1 taken 1700 times.
|
10076 | if (!edges[TOP]) |
282 | 8376 | 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 8362 times.
✓ Branch 1 taken 1714 times.
|
10076 | if (!edges[BOTTOM]) |
285 | 8362 | 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 9120 times.
✓ Branch 1 taken 956 times.
|
10076 | if (!edges[LEFT]) |
288 | 9120 | 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 9179 times.
✓ Branch 1 taken 897 times.
|
10076 | if (!edges[RIGHT]) |
291 | 9179 | copy_vert(dst + (width << ps), sao_v + (((2 * rx + 2) * h + y) << ps), ps, height, dst_stride, 1 << ps); | |
292 | |||
293 | 10076 | copy_ctb(dst, src, width << ps, height, dst_stride, src_stride); | |
294 | 10076 | } | |
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 | 52935 | void ff_vvc_sao_filter(VVCLocalContext *lc, int x0, int y0) | |
315 | { | ||
316 | 52935 | VVCFrameContext *fc = lc->fc; | |
317 | 52935 | const VVCSPS *sps = fc->ps.sps; | |
318 | 52935 | const int rx = x0 >> sps->ctb_log2_size_y; | |
319 | 52935 | const int ry = y0 >> sps->ctb_log2_size_y; | |
320 | 52935 | const int edges[4] = { !rx, !ry, rx == fc->ps.pps->ctb_width - 1, ry == fc->ps.pps->ctb_height - 1 }; | |
321 | 52935 | const SAOParams *sao = &CTB(fc->tab.sao, rx, ry); | |
322 | // flags indicating unfilterable edges | ||
323 | 52935 | uint8_t vert_edge[] = { 0, 0 }; | |
324 | 52935 | uint8_t horiz_edge[] = { 0, 0 }; | |
325 | 52935 | uint8_t diag_edge[] = { 0, 0, 0, 0 }; | |
326 | 52935 | int restore, vb_x = 0, vb_y = 0;; | |
327 | |||
328 |
2/2✓ Branch 0 taken 1029 times.
✓ Branch 1 taken 51906 times.
|
52935 | if (sps->r->sps_virtual_boundaries_enabled_flag) { |
329 | 1029 | vb_x = get_virtual_boundary(fc, rx, 1); | |
330 | 1029 | vb_y = get_virtual_boundary(fc, ry, 0); | |
331 | } | ||
332 | |||
333 | 52935 | sao_get_edges(vert_edge, horiz_edge, diag_edge, &restore, lc, edges, rx, ry); | |
334 | |||
335 |
4/4✓ Branch 0 taken 209628 times.
✓ Branch 1 taken 1056 times.
✓ Branch 2 taken 157749 times.
✓ Branch 3 taken 52935 times.
|
210684 | 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 | 157749 | const ptrdiff_t src_stride = fc->frame->linesize[c_idx]; | |
338 | 157749 | uint8_t *src = POS(c_idx, x0, y0); | |
339 | 157749 | const int hs = sps->hshift[c_idx]; | |
340 | 157749 | const int vs = sps->vshift[c_idx]; | |
341 | 157749 | const int ps = sps->pixel_shift; | |
342 | 157749 | const int width = FFMIN(sps->ctb_size_y, fc->ps.pps->width - x0) >> hs; | |
343 | 157749 | const int height = FFMIN(sps->ctb_size_y, fc->ps.pps->height - y0) >> vs; | |
344 | 157749 | const int tab = sao_tab[(FFALIGN(width, 8) >> 3) - 1]; | |
345 | 157749 | const int sao_eo_class = sao->eo_class[c_idx]; | |
346 | |||
347 |
3/3✓ Branch 0 taken 5836 times.
✓ Branch 1 taken 10076 times.
✓ Branch 2 taken 141837 times.
|
157749 | switch (sao->type_idx[c_idx]) { |
348 | 5836 | case SAO_BAND: | |
349 | 5836 | fc->vvcdsp.sao.band_filter[tab](src, src, src_stride, src_stride, | |
350 | 5836 | sao->offset_val[c_idx], sao->band_position[c_idx], width, height); | |
351 | 5836 | break; | |
352 | 10076 | case SAO_EDGE: | |
353 | { | ||
354 | 10076 | const ptrdiff_t dst_stride = 2 * MAX_PB_SIZE + AV_INPUT_BUFFER_PADDING_SIZE; | |
355 | 10076 | uint8_t *dst = lc->sao_buffer + dst_stride + AV_INPUT_BUFFER_PADDING_SIZE; | |
356 | |||
357 | 10076 | sao_extends_edges(dst, dst_stride, src, src_stride, width, height, fc, x0, y0, rx, ry, edges, c_idx); | |
358 | |||
359 | 10076 | fc->vvcdsp.sao.edge_filter[tab](src, dst, src_stride, sao->offset_val[c_idx], | |
360 | 10076 | sao->eo_class[c_idx], width, height); | |
361 | 10076 | 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 10076 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
10076 | 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 10076 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
10076 | 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 | 10076 | break; | |
370 | } | ||
371 | } | ||
372 | } | ||
373 | 52935 | } | |
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 | 11449720 | static int boundary_strength(const VVCLocalContext *lc, const MvField *curr, const MvField *neigh, | |
384 | const RefPicList *neigh_rpl) | ||
385 | { | ||
386 | 11449720 | RefPicList *rpl = lc->sc->rpl; | |
387 | |||
388 |
2/2✓ Branch 0 taken 8974 times.
✓ Branch 1 taken 11440746 times.
|
11449720 | if (curr->pred_flag == PF_PLT) |
389 | 8974 | return 0; | |
390 | |||
391 |
2/2✓ Branch 0 taken 111582 times.
✓ Branch 1 taken 11329164 times.
|
11440746 | if (curr->pred_flag == PF_IBC) |
392 |
4/4✓ Branch 0 taken 66652 times.
✓ Branch 1 taken 44930 times.
✓ Branch 2 taken 5166 times.
✓ Branch 3 taken 61486 times.
|
111582 | return FFABS(neigh->mv[0].x - curr->mv[0].x) >= 8 || FFABS(neigh->mv[0].y - curr->mv[0].y) >= 8; |
393 | |||
394 |
4/4✓ Branch 0 taken 5507715 times.
✓ Branch 1 taken 5821449 times.
✓ Branch 2 taken 5168479 times.
✓ Branch 3 taken 339236 times.
|
11329164 | if (curr->pred_flag == PF_BI && neigh->pred_flag == PF_BI) { |
395 | // same L0 and L1 | ||
396 |
2/2✓ Branch 0 taken 5086379 times.
✓ Branch 1 taken 82100 times.
|
5168479 | if (rpl[L0].refs[curr->ref_idx[L0]].poc == neigh_rpl[L0].refs[neigh->ref_idx[L0]].poc && |
397 |
2/2✓ Branch 0 taken 554793 times.
✓ Branch 1 taken 4531586 times.
|
5086379 | rpl[L0].refs[curr->ref_idx[L0]].poc == rpl[L1].refs[curr->ref_idx[L1]].poc && |
398 |
2/2✓ Branch 0 taken 551249 times.
✓ Branch 1 taken 3544 times.
|
554793 | neigh_rpl[L0].refs[neigh->ref_idx[L0]].poc == neigh_rpl[L1].refs[neigh->ref_idx[L1]].poc) { |
399 |
4/4✓ Branch 0 taken 503952 times.
✓ Branch 1 taken 47297 times.
✓ Branch 2 taken 478187 times.
✓ Branch 3 taken 25765 times.
|
551249 | if ((FFABS(neigh->mv[0].x - curr->mv[0].x) >= 8 || FFABS(neigh->mv[0].y - curr->mv[0].y) >= 8 || |
400 |
4/4✓ Branch 0 taken 474364 times.
✓ Branch 1 taken 3823 times.
✓ Branch 2 taken 3253 times.
✓ Branch 3 taken 471111 times.
|
478187 | FFABS(neigh->mv[1].x - curr->mv[1].x) >= 8 || FFABS(neigh->mv[1].y - curr->mv[1].y) >= 8) && |
401 |
4/4✓ Branch 0 taken 19736 times.
✓ Branch 1 taken 60402 times.
✓ Branch 2 taken 4909 times.
✓ Branch 3 taken 14827 times.
|
80138 | (FFABS(neigh->mv[1].x - curr->mv[0].x) >= 8 || FFABS(neigh->mv[1].y - curr->mv[0].y) >= 8 || |
402 |
4/4✓ Branch 0 taken 2557 times.
✓ Branch 1 taken 2352 times.
✓ Branch 2 taken 2041 times.
✓ Branch 3 taken 516 times.
|
4909 | FFABS(neigh->mv[0].x - curr->mv[1].x) >= 8 || FFABS(neigh->mv[0].y - curr->mv[1].y) >= 8)) |
403 | 79622 | return 1; | |
404 | else | ||
405 | 471627 | return 0; | |
406 |
2/2✓ Branch 0 taken 4535130 times.
✓ Branch 1 taken 82100 times.
|
4617230 | } else if (neigh_rpl[L0].refs[neigh->ref_idx[L0]].poc == rpl[L0].refs[curr->ref_idx[L0]].poc && |
407 |
2/2✓ Branch 0 taken 4514758 times.
✓ Branch 1 taken 20372 times.
|
4535130 | neigh_rpl[L1].refs[neigh->ref_idx[L1]].poc == rpl[L1].refs[curr->ref_idx[L1]].poc) { |
408 |
4/4✓ Branch 0 taken 3978660 times.
✓ Branch 1 taken 536098 times.
✓ Branch 2 taken 3821656 times.
✓ Branch 3 taken 157004 times.
|
4514758 | if (FFABS(neigh->mv[0].x - curr->mv[0].x) >= 8 || FFABS(neigh->mv[0].y - curr->mv[0].y) >= 8 || |
409 |
4/4✓ Branch 0 taken 3787357 times.
✓ Branch 1 taken 34299 times.
✓ Branch 2 taken 21517 times.
✓ Branch 3 taken 3765840 times.
|
3821656 | FFABS(neigh->mv[1].x - curr->mv[1].x) >= 8 || FFABS(neigh->mv[1].y - curr->mv[1].y) >= 8) |
410 | 748918 | return 1; | |
411 | else | ||
412 | 3765840 | return 0; | |
413 |
2/2✓ Branch 0 taken 28007 times.
✓ Branch 1 taken 74465 times.
|
102472 | } else if (neigh_rpl[L1].refs[neigh->ref_idx[L1]].poc == rpl[L0].refs[curr->ref_idx[L0]].poc && |
414 |
2/2✓ Branch 0 taken 8707 times.
✓ Branch 1 taken 19300 times.
|
28007 | neigh_rpl[L0].refs[neigh->ref_idx[L0]].poc == rpl[L1].refs[curr->ref_idx[L1]].poc) { |
415 |
4/4✓ Branch 0 taken 2997 times.
✓ Branch 1 taken 5710 times.
✓ Branch 2 taken 1184 times.
✓ Branch 3 taken 1813 times.
|
8707 | if (FFABS(neigh->mv[1].x - curr->mv[0].x) >= 8 || FFABS(neigh->mv[1].y - curr->mv[0].y) >= 8 || |
416 |
4/4✓ Branch 0 taken 869 times.
✓ Branch 1 taken 315 times.
✓ Branch 2 taken 180 times.
✓ Branch 3 taken 689 times.
|
1184 | FFABS(neigh->mv[0].x - curr->mv[1].x) >= 8 || FFABS(neigh->mv[0].y - curr->mv[1].y) >= 8) |
417 | 8018 | return 1; | |
418 | else | ||
419 | 689 | return 0; | |
420 | } else { | ||
421 | 93765 | return 1; | |
422 | } | ||
423 |
4/4✓ Branch 0 taken 5821449 times.
✓ Branch 1 taken 339236 times.
✓ Branch 2 taken 5475010 times.
✓ Branch 3 taken 346439 times.
|
6160685 | } else if ((curr->pred_flag != PF_BI) && (neigh->pred_flag != PF_BI)){ // 1 MV |
424 | Mv A, B; | ||
425 | int ref_A, ref_B; | ||
426 | |||
427 |
2/2✓ Branch 0 taken 4240413 times.
✓ Branch 1 taken 1234597 times.
|
5475010 | if (curr->pred_flag & 1) { |
428 | 4240413 | A = curr->mv[0]; | |
429 | 4240413 | ref_A = rpl[L0].refs[curr->ref_idx[L0]].poc; | |
430 | } else { | ||
431 | 1234597 | A = curr->mv[1]; | |
432 | 1234597 | ref_A = rpl[L1].refs[curr->ref_idx[L1]].poc; | |
433 | } | ||
434 | |||
435 |
2/2✓ Branch 0 taken 4238580 times.
✓ Branch 1 taken 1236430 times.
|
5475010 | if (neigh->pred_flag & 1) { |
436 | 4238580 | B = neigh->mv[0]; | |
437 | 4238580 | ref_B = neigh_rpl[L0].refs[neigh->ref_idx[L0]].poc; | |
438 | } else { | ||
439 | 1236430 | B = neigh->mv[1]; | |
440 | 1236430 | ref_B = neigh_rpl[L1].refs[neigh->ref_idx[L1]].poc; | |
441 | } | ||
442 | |||
443 |
2/2✓ Branch 0 taken 5309455 times.
✓ Branch 1 taken 165555 times.
|
5475010 | if (ref_A == ref_B) { |
444 |
4/4✓ Branch 0 taken 4938002 times.
✓ Branch 1 taken 371453 times.
✓ Branch 2 taken 160592 times.
✓ Branch 3 taken 4777410 times.
|
5309455 | if (FFABS(A.x - B.x) >= 8 || FFABS(A.y - B.y) >= 8) |
445 | 532045 | return 1; | |
446 | else | ||
447 | 4777410 | return 0; | |
448 | } else | ||
449 | 165555 | return 1; | |
450 | } | ||
451 | |||
452 | 685675 | return 1; | |
453 | } | ||
454 | |||
455 | //part of 8.8.3.3 Derivation process of transform block boundary | ||
456 | 12283625 | static void derive_max_filter_length_luma(const VVCFrameContext *fc, const int qx, const int qy, | |
457 | const int size_q, const int has_subblock, const int vertical, uint8_t *max_len_p, uint8_t *max_len_q) | ||
458 | { | ||
459 |
2/2✓ Branch 0 taken 5889658 times.
✓ Branch 1 taken 6393967 times.
|
12283625 | const int px = vertical ? qx - 1 : qx; |
460 |
2/2✓ Branch 0 taken 6393967 times.
✓ Branch 1 taken 5889658 times.
|
12283625 | const int py = !vertical ? qy - 1 : qy; |
461 |
2/2✓ Branch 0 taken 5889658 times.
✓ Branch 1 taken 6393967 times.
|
12283625 | const uint8_t *tb_size = vertical ? fc->tab.tb_width[LUMA] : fc->tab.tb_height[LUMA]; |
462 | 12283625 | const int size_p = tb_size[(py >> MIN_TU_LOG2) * fc->ps.pps->min_tu_width + (px >> MIN_TU_LOG2)]; | |
463 | 12283625 | const int min_cb_log2 = fc->ps.sps->min_cb_log2_size_y; | |
464 | 12283625 | const int off_p = (py >> min_cb_log2) * fc->ps.pps->min_cb_width + (px >> min_cb_log2); | |
465 | |||
466 |
4/4✓ Branch 0 taken 10351236 times.
✓ Branch 1 taken 1932389 times.
✓ Branch 2 taken 867487 times.
✓ Branch 3 taken 9483749 times.
|
12283625 | if (size_p <= 4 || size_q <= 4) { |
467 | 2799876 | *max_len_p = *max_len_q = 1; | |
468 | } else { | ||
469 | 9483749 | *max_len_p = *max_len_q = 3; | |
470 |
2/2✓ Branch 0 taken 6268180 times.
✓ Branch 1 taken 3215569 times.
|
9483749 | if (size_p >= 32) |
471 | 6268180 | *max_len_p = 7; | |
472 |
2/2✓ Branch 0 taken 6096126 times.
✓ Branch 1 taken 3387623 times.
|
9483749 | if (size_q >= 32) |
473 | 6096126 | *max_len_q = 7; | |
474 | } | ||
475 |
2/2✓ Branch 0 taken 1392982 times.
✓ Branch 1 taken 10890643 times.
|
12283625 | if (has_subblock) |
476 | 1392982 | *max_len_q = FFMIN(5, *max_len_q); | |
477 |
4/4✓ Branch 0 taken 11021606 times.
✓ Branch 1 taken 1262019 times.
✓ Branch 2 taken 260400 times.
✓ Branch 3 taken 10761206 times.
|
12283625 | if (fc->tab.msf[off_p] || fc->tab.iaf[off_p]) |
478 | 1522419 | *max_len_p = FFMIN(5, *max_len_p); | |
479 | 12283625 | } | |
480 | |||
481 | 166822 | static void vvc_deblock_subblock_bs(const VVCLocalContext *lc, | |
482 | const int cb, int x0, int y0, int width, int height, const int vertical) | ||
483 | { | ||
484 | 166822 | const VVCFrameContext *fc = lc->fc; | |
485 | 166822 | const MvField *tab_mvf = fc->tab.mvf; | |
486 | 166822 | const RefPicList *rpl = lc->sc->rpl; | |
487 | 166822 | int stridea = fc->ps.pps->min_pu_width; | |
488 | 166822 | int strideb = 1; | |
489 | 166822 | const int log2_min_pu_size = MIN_PU_LOG2; | |
490 | |||
491 |
2/2✓ Branch 0 taken 83818 times.
✓ Branch 1 taken 83004 times.
|
166822 | if (!vertical) { |
492 | 83818 | FFSWAP(int, x0, y0); | |
493 | 83818 | FFSWAP(int, width, height); | |
494 | 83818 | FFSWAP(int, stridea, strideb); | |
495 | } | ||
496 | |||
497 | // bs for TU internal vertical PU boundaries | ||
498 |
2/2✓ Branch 0 taken 603651 times.
✓ Branch 1 taken 166822 times.
|
770473 | for (int i = 8 - ((x0 - cb) % 8); i < width; i += 8) { |
499 | 603651 | const int is_vb = is_virtual_boundary(fc, x0 + i, vertical); | |
500 | 603651 | const int xp_pu = (x0 + i - 1) >> log2_min_pu_size; | |
501 | 603651 | const int xq_pu = (x0 + i) >> log2_min_pu_size; | |
502 | |||
503 |
2/2✓ Branch 0 taken 6468786 times.
✓ Branch 1 taken 603651 times.
|
7072437 | for (int j = 0; j < height; j += 4) { |
504 | 6468786 | const int y_pu = (y0 + j) >> log2_min_pu_size; | |
505 | 6468786 | const MvField *mvf_p = &tab_mvf[y_pu * stridea + xp_pu * strideb]; | |
506 | 6468786 | const MvField *mvf_q = &tab_mvf[y_pu * stridea + xq_pu * strideb]; | |
507 |
1/2✓ Branch 0 taken 6468786 times.
✗ Branch 1 not taken.
|
6468786 | const int bs = is_vb ? 0 : boundary_strength(lc, mvf_q, mvf_p, rpl); |
508 | 6468786 | int x = x0 + i; | |
509 | 6468786 | int y = y0 + j; | |
510 | 6468786 | uint8_t max_len_p = 0, max_len_q = 0; | |
511 | |||
512 |
2/2✓ Branch 0 taken 3216606 times.
✓ Branch 1 taken 3252180 times.
|
6468786 | if (!vertical) |
513 | 3216606 | FFSWAP(int, x, y); | |
514 | |||
515 | 6468786 | TAB_BS(fc->tab.bs[vertical][LUMA], x, y) = bs; | |
516 | |||
517 |
4/4✓ Branch 0 taken 6467206 times.
✓ Branch 1 taken 1580 times.
✓ Branch 2 taken 1816 times.
✓ Branch 3 taken 6465390 times.
|
6468786 | if (i == 4 || i == width - 4) |
518 | 3396 | max_len_p = max_len_q = 1; | |
519 |
4/4✓ Branch 0 taken 5030410 times.
✓ Branch 1 taken 1434980 times.
✓ Branch 2 taken 1197342 times.
✓ Branch 3 taken 3833068 times.
|
6465390 | else if (i == 8 || i == width - 8) |
520 | 2632322 | max_len_p = max_len_q = 2; | |
521 | else | ||
522 | 3833068 | max_len_p = max_len_q = 3; | |
523 | |||
524 | 6468786 | TAB_MAX_LEN(fc->tab.max_len_p[vertical], x, y) = max_len_p; | |
525 | 6468786 | TAB_MAX_LEN(fc->tab.max_len_q[vertical], x, y) = max_len_q; | |
526 | } | ||
527 | } | ||
528 | 166822 | } | |
529 | |||
530 | 48238209 | static av_always_inline int deblock_bs(const VVCLocalContext *lc, | |
531 | const int x_p, const int y_p, const int x_q, const int y_q, const CodingUnit *cu, const TransformUnit *tu, | ||
532 | const RefPicList *rpl_p, const int c_idx, const int off_to_cb, const uint8_t has_sub_block) | ||
533 | { | ||
534 | 48238209 | const VVCFrameContext *fc = lc->fc; | |
535 | 48238209 | const MvField *tab_mvf = fc->tab.mvf; | |
536 | 48238209 | const int log2_min_pu_size = MIN_PU_LOG2; | |
537 | 48238209 | const int log2_min_tu_size = MIN_TU_LOG2; | |
538 | 48238209 | const int log2_min_cb_size = fc->ps.sps->min_cb_log2_size_y; | |
539 | 48238209 | const int min_pu_width = fc->ps.pps->min_pu_width; | |
540 | 48238209 | const int min_tu_width = fc->ps.pps->min_tu_width; | |
541 | 48238209 | const int min_cb_width = fc->ps.pps->min_cb_width; | |
542 | 48238209 | const int pu_p = (y_p >> log2_min_pu_size) * min_pu_width + (x_p >> log2_min_pu_size); | |
543 | 48238209 | const int pu_q = (y_q >> log2_min_pu_size) * min_pu_width + (x_q >> log2_min_pu_size); | |
544 | 48238209 | const MvField *mvf_p = &tab_mvf[pu_p]; | |
545 | 48238209 | const MvField *mvf_q = &tab_mvf[pu_q]; | |
546 | 48238209 | const uint8_t chroma = !!c_idx; | |
547 | 48238209 | const int tu_p = (y_p >> log2_min_tu_size) * min_tu_width + (x_p >> log2_min_tu_size); | |
548 | 48238209 | const int cb_p = (y_p >> log2_min_cb_size) * min_cb_width + (x_p >> log2_min_cb_size); | |
549 |
4/4✓ Branch 0 taken 67992 times.
✓ Branch 1 taken 48170217 times.
✓ Branch 2 taken 30213 times.
✓ Branch 3 taken 37779 times.
|
48238209 | const uint8_t pcmf = fc->tab.pcmf[chroma][cb_p] && cu->bdpcm_flag[chroma]; |
550 |
4/4✓ Branch 0 taken 37506136 times.
✓ Branch 1 taken 10732073 times.
✓ Branch 2 taken 1013647 times.
✓ Branch 3 taken 36492489 times.
|
48238209 | const uint8_t intra = fc->tab.cpm[chroma][cb_p] == MODE_INTRA || cu->pred_mode == MODE_INTRA; |
551 | 48238209 | const uint8_t same_mode = fc->tab.cpm[chroma][cb_p] == cu->pred_mode; | |
552 | |||
553 |
2/2✓ Branch 0 taken 30213 times.
✓ Branch 1 taken 48207996 times.
|
48238209 | if (pcmf) |
554 | 30213 | return 0; | |
555 | |||
556 |
6/6✓ Branch 0 taken 36492489 times.
✓ Branch 1 taken 11715507 times.
✓ Branch 2 taken 36105809 times.
✓ Branch 3 taken 386680 times.
✓ Branch 4 taken 302791 times.
✓ Branch 5 taken 35803018 times.
|
48207996 | if (intra || mvf_p->ciip_flag || mvf_q->ciip_flag) |
557 | 12404978 | return 2; | |
558 | |||
559 |
2/2✓ Branch 0 taken 27829128 times.
✓ Branch 1 taken 7973890 times.
|
35803018 | if (chroma) { |
560 | 54984878 | return fc->tab.tu_coded_flag[c_idx][tu_p] || | |
561 |
2/2✓ Branch 0 taken 26930712 times.
✓ Branch 1 taken 225038 times.
|
27155750 | fc->tab.tu_joint_cbcr_residual_flag[tu_p] || |
562 |
4/4✓ Branch 0 taken 27155750 times.
✓ Branch 1 taken 673378 times.
✓ Branch 2 taken 26667032 times.
✓ Branch 3 taken 263680 times.
|
81651910 | tu->coded_flag[c_idx] || |
563 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 26667032 times.
|
26667032 | tu->joint_cbcr_residual_flag; |
564 | } | ||
565 | |||
566 |
4/4✓ Branch 0 taken 7083553 times.
✓ Branch 1 taken 890337 times.
✓ Branch 2 taken 416826 times.
✓ Branch 3 taken 6666727 times.
|
7973890 | if (fc->tab.tu_coded_flag[LUMA][tu_p] || tu->coded_flag[LUMA]) |
567 | 1307163 | return 1; | |
568 | |||
569 |
6/6✓ Branch 0 taken 2010289 times.
✓ Branch 1 taken 4656438 times.
✓ Branch 2 taken 1996346 times.
✓ Branch 3 taken 13943 times.
✓ Branch 4 taken 1620032 times.
✓ Branch 5 taken 376314 times.
|
6666727 | if ((off_to_cb && ((off_to_cb % 8) || !has_sub_block))) |
570 | 1633975 | return 0; // inside a cu, not aligned to 8 or with no subblocks | |
571 | |||
572 |
2/2✓ Branch 0 taken 51818 times.
✓ Branch 1 taken 4980934 times.
|
5032752 | if (!same_mode) |
573 | 51818 | return 1; | |
574 | |||
575 | 4980934 | return boundary_strength(lc, mvf_q, mvf_p, rpl_p); | |
576 | } | ||
577 | |||
578 | 4733240 | static int deblock_is_boundary(const VVCLocalContext *lc, const int boundary, | |
579 | const int pos, const int rs, const int vertical) | ||
580 | { | ||
581 | 4733240 | const VVCFrameContext *fc = lc->fc; | |
582 | 4733240 | const H266RawSPS *rsps = fc->ps.sps->r; | |
583 | 4733240 | const H266RawPPS *rpps = fc->ps.pps->r; | |
584 | int flag; | ||
585 |
4/4✓ Branch 0 taken 4180447 times.
✓ Branch 1 taken 552793 times.
✓ Branch 2 taken 681052 times.
✓ Branch 3 taken 3499395 times.
|
4733240 | if (boundary && (pos % fc->ps.sps->ctb_size_y) == 0) { |
586 |
2/2✓ Branch 0 taken 368174 times.
✓ Branch 1 taken 312878 times.
|
681052 | flag = vertical ? BOUNDARY_LEFT_SLICE : BOUNDARY_UPPER_SLICE; |
587 |
2/2✓ Branch 0 taken 20714 times.
✓ Branch 1 taken 660338 times.
|
681052 | if (lc->boundary_flags & flag && |
588 |
2/2✓ Branch 0 taken 8259 times.
✓ Branch 1 taken 12455 times.
|
20714 | !rpps->pps_loop_filter_across_slices_enabled_flag) |
589 | 8259 | return 0; | |
590 | |||
591 |
2/2✓ Branch 0 taken 364184 times.
✓ Branch 1 taken 308609 times.
|
672793 | flag = vertical ? BOUNDARY_LEFT_TILE : BOUNDARY_UPPER_TILE; |
592 |
2/2✓ Branch 0 taken 29697 times.
✓ Branch 1 taken 643096 times.
|
672793 | if (lc->boundary_flags & flag && |
593 |
2/2✓ Branch 0 taken 9204 times.
✓ Branch 1 taken 20493 times.
|
29697 | !rpps->pps_loop_filter_across_tiles_enabled_flag) |
594 | 9204 | return 0; | |
595 | |||
596 |
2/2✓ Branch 0 taken 358605 times.
✓ Branch 1 taken 304984 times.
|
663589 | flag = vertical ? BOUNDARY_LEFT_SUBPIC : BOUNDARY_UPPER_SUBPIC; |
597 |
2/2✓ Branch 0 taken 363 times.
✓ Branch 1 taken 663226 times.
|
663589 | if (lc->boundary_flags & flag) { |
598 |
2/2✓ Branch 0 taken 313 times.
✓ Branch 1 taken 50 times.
|
363 | const int q_rs = rs - (vertical ? 1 : fc->ps.pps->ctb_width); |
599 | 363 | const SliceContext *q_slice = lc->fc->slices[lc->fc->tab.slice_idx[q_rs]]; | |
600 | |||
601 |
2/2✓ Branch 0 taken 253 times.
✓ Branch 1 taken 110 times.
|
363 | if (!rsps->sps_loop_filter_across_subpic_enabled_flag[q_slice->sh.r->curr_subpic_idx] || |
602 |
2/2✓ Branch 0 taken 50 times.
✓ Branch 1 taken 203 times.
|
253 | !rsps->sps_loop_filter_across_subpic_enabled_flag[lc->sc->sh.r->curr_subpic_idx]) |
603 | 160 | return 0; | |
604 | } | ||
605 | } | ||
606 | 4715617 | return boundary; | |
607 | } | ||
608 | |||
609 | 2948834 | static void vvc_deblock_bs_luma(const VVCLocalContext *lc, | |
610 | const int x0, const int y0, const int width, const int height, | ||
611 | const CodingUnit *cu, const TransformUnit *tu, int rs, const int vertical) | ||
612 | { | ||
613 | 2948834 | const VVCFrameContext *fc = lc->fc; | |
614 | 2948834 | const PredictionUnit *pu = &cu->pu; | |
615 | 2948834 | const int mask = LUMA_GRID - 1; | |
616 |
2/2✓ Branch 0 taken 1474417 times.
✓ Branch 1 taken 1474417 times.
|
2948834 | const int pos = vertical ? x0 : y0; |
617 |
2/2✓ Branch 0 taken 1474417 times.
✓ Branch 1 taken 1474417 times.
|
2948834 | const int cb = vertical ? cu->x0 : cu->y0; |
618 | 2948834 | const int is_intra = cu->pred_mode == MODE_INTRA; | |
619 |
2/2✓ Branch 0 taken 1474417 times.
✓ Branch 1 taken 1474417 times.
|
2948834 | const int cb_size = vertical ? cu->cb_width : cu->cb_height; |
620 |
8/8✓ Branch 0 taken 1404120 times.
✓ Branch 1 taken 1544714 times.
✓ Branch 2 taken 1239004 times.
✓ Branch 3 taken 165116 times.
✓ Branch 4 taken 29848 times.
✓ Branch 5 taken 1209156 times.
✓ Branch 6 taken 166822 times.
✓ Branch 7 taken 28142 times.
|
2948834 | const int has_sb = !is_intra && (pu->merge_subblock_flag || pu->inter_affine_flag) && cb_size > 8; |
621 | |||
622 |
6/6✓ Branch 0 taken 2892119 times.
✓ Branch 1 taken 56715 times.
✓ Branch 2 taken 2839043 times.
✓ Branch 3 taken 53076 times.
✓ Branch 5 taken 2828647 times.
✓ Branch 6 taken 120187 times.
|
2948834 | if (deblock_is_boundary(lc, pos > 0 && !(pos & mask), pos, rs, vertical)) { |
623 | 2828647 | const int is_vb = is_virtual_boundary(fc, pos, vertical); | |
624 |
2/2✓ Branch 0 taken 1431218 times.
✓ Branch 1 taken 1397429 times.
|
2828647 | const int size = vertical ? height : width; |
625 |
2/2✓ Branch 0 taken 1431218 times.
✓ Branch 1 taken 1397429 times.
|
2828647 | const int size_q = vertical ? width : height; |
626 | 2828647 | const int off = cb - pos; | |
627 |
2/2✓ Branch 0 taken 1431218 times.
✓ Branch 1 taken 1397429 times.
|
2828647 | const int flag = vertical ? BOUNDARY_LEFT_SLICE : BOUNDARY_UPPER_SLICE; |
628 | 2828647 | const RefPicList *rpl_p = | |
629 |
2/2✓ Branch 0 taken 73777 times.
✓ Branch 1 taken 2754870 times.
|
2828647 | (lc->boundary_flags & flag) ? ff_vvc_get_ref_list(fc, fc->ref, x0 - vertical, y0 - !vertical) : lc->sc->rpl; |
630 | |||
631 |
2/2✓ Branch 0 taken 12283625 times.
✓ Branch 1 taken 2828647 times.
|
15112272 | for (int i = 0; i < size; i += 4) { |
632 | 12283625 | const int x = x0 + i * !vertical; | |
633 | 12283625 | const int y = y0 + i * vertical; | |
634 | uint8_t max_len_p, max_len_q; | ||
635 |
1/2✓ Branch 0 taken 12283625 times.
✗ Branch 1 not taken.
|
12283625 | const int bs = is_vb ? 0 : deblock_bs(lc, x - vertical, y - !vertical, x, y, cu, tu, rpl_p, LUMA, off, has_sb); |
636 | |||
637 | 12283625 | TAB_BS(fc->tab.bs[vertical][LUMA], x, y) = bs; | |
638 | |||
639 | 12283625 | derive_max_filter_length_luma(fc, x, y, size_q, has_sb, vertical, &max_len_p, &max_len_q); | |
640 | 12283625 | TAB_MAX_LEN(fc->tab.max_len_p[vertical], x, y) = max_len_p; | |
641 | 12283625 | TAB_MAX_LEN(fc->tab.max_len_q[vertical], x, y) = max_len_q; | |
642 | } | ||
643 | } | ||
644 | |||
645 |
2/2✓ Branch 0 taken 166822 times.
✓ Branch 1 taken 2782012 times.
|
2948834 | if (has_sb) |
646 | 166822 | vvc_deblock_subblock_bs(lc, cb, x0, y0, width, height, vertical); | |
647 | 2948834 | } | |
648 | |||
649 | 1784406 | static void vvc_deblock_bs_chroma(const VVCLocalContext *lc, | |
650 | const int x0, const int y0, const int width, const int height, | ||
651 | const CodingUnit *cu, const TransformUnit *tu, const int rs, const int vertical) | ||
652 | { | ||
653 | 1784406 | const VVCFrameContext *fc = lc->fc; | |
654 |
2/2✓ Branch 0 taken 892203 times.
✓ Branch 1 taken 892203 times.
|
1784406 | const int shift = (vertical ? fc->ps.sps->hshift : fc->ps.sps->vshift)[CHROMA]; |
655 | 1784406 | const int mask = (CHROMA_GRID << shift) - 1; | |
656 |
2/2✓ Branch 0 taken 892203 times.
✓ Branch 1 taken 892203 times.
|
1784406 | const int pos = vertical ? x0 : y0; |
657 | |||
658 |
6/6✓ Branch 0 taken 1738112 times.
✓ Branch 1 taken 46294 times.
✓ Branch 2 taken 1341404 times.
✓ Branch 3 taken 396708 times.
✓ Branch 5 taken 1334177 times.
✓ Branch 6 taken 450229 times.
|
1784406 | if (deblock_is_boundary(lc, pos > 0 && !(pos & mask), pos, rs, vertical)) { |
659 | 1334177 | const int is_vb = is_virtual_boundary(fc, pos, vertical); | |
660 |
2/2✓ Branch 0 taken 671377 times.
✓ Branch 1 taken 662800 times.
|
1334177 | const int size = vertical ? height : width; |
661 | |||
662 |
2/2✓ Branch 0 taken 2668354 times.
✓ Branch 1 taken 1334177 times.
|
4002531 | for (int c_idx = CB; c_idx <= CR; c_idx++) { |
663 |
2/2✓ Branch 0 taken 35954584 times.
✓ Branch 1 taken 2668354 times.
|
38622938 | for (int i = 0; i < size; i += 2) { |
664 | 35954584 | const int x = x0 + i * !vertical; | |
665 | 35954584 | const int y = y0 + i * vertical; | |
666 |
1/2✓ Branch 0 taken 35954584 times.
✗ Branch 1 not taken.
|
35954584 | const int bs = is_vb ? 0 : deblock_bs(lc, x - vertical, y - !vertical, x, y, cu, tu, NULL, c_idx, 0, 0); |
667 | |||
668 | 35954584 | TAB_BS(fc->tab.bs[vertical][c_idx], x, y) = bs; | |
669 | } | ||
670 | } | ||
671 | } | ||
672 | 1784406 | } | |
673 | |||
674 | typedef void (*deblock_bs_fn)(const VVCLocalContext *lc, const int x0, const int y0, | ||
675 | const int width, const int height, const int rs, const int vertical); | ||
676 | |||
677 | 53351 | void ff_vvc_deblock_bs(VVCLocalContext *lc, const int rx, const int ry, const int rs) | |
678 | { | ||
679 | 53351 | const VVCFrameContext *fc = lc->fc; | |
680 | 53351 | const VVCSPS *sps = fc->ps.sps; | |
681 | 53351 | const int x0 = rx << sps->ctb_log2_size_y; | |
682 | 53351 | const int y0 = ry << sps->ctb_log2_size_y; | |
683 | |||
684 | 53351 | ff_vvc_decode_neighbour(lc, x0, y0, rx, ry, rs); | |
685 |
2/2✓ Branch 0 taken 1343208 times.
✓ Branch 1 taken 53351 times.
|
1396559 | for (const CodingUnit *cu = fc->tab.cus[rs]; cu; cu = cu->next) { |
686 |
2/2✓ Branch 0 taken 1662413 times.
✓ Branch 1 taken 1343208 times.
|
3005621 | for (const TransformUnit *tu = cu->tus.head; tu; tu = tu->next) { |
687 |
2/2✓ Branch 0 taken 3324826 times.
✓ Branch 1 taken 1662413 times.
|
4987239 | for (int vertical = 0; vertical <= 1; vertical++) { |
688 |
2/2✓ Branch 0 taken 2948834 times.
✓ Branch 1 taken 375992 times.
|
3324826 | if (tu->avail[LUMA]) |
689 | 2948834 | vvc_deblock_bs_luma(lc, tu->x0, tu->y0, tu->width, tu->height, cu, tu, rs, vertical); | |
690 |
2/2✓ Branch 0 taken 1784406 times.
✓ Branch 1 taken 1540420 times.
|
3324826 | if (tu->avail[CHROMA]) { |
691 |
3/4✓ Branch 0 taken 11254 times.
✓ Branch 1 taken 1773152 times.
✓ Branch 2 taken 11254 times.
✗ Branch 3 not taken.
|
1784406 | if (cu->isp_split_type != ISP_NO_SPLIT && cu->tree_type == SINGLE_TREE) |
692 | 11254 | vvc_deblock_bs_chroma(lc, cu->x0, cu->y0, cu->cb_width, cu->cb_height, cu, tu, rs, vertical); | |
693 | else | ||
694 | 1773152 | vvc_deblock_bs_chroma(lc, tu->x0, tu->y0, tu->width, tu->height, cu, tu, rs, vertical); | |
695 | } | ||
696 | } | ||
697 | } | ||
698 | } | ||
699 | 53351 | } | |
700 | |||
701 | //part of 8.8.3.3 Derivation process of transform block boundary | ||
702 | 7950353 | static void max_filter_length_luma(const VVCFrameContext *fc, const int qx, const int qy, | |
703 | const int vertical, uint8_t *max_len_p, uint8_t *max_len_q) | ||
704 | { | ||
705 | 7950353 | *max_len_p = TAB_MAX_LEN(fc->tab.max_len_p[vertical], qx, qy); | |
706 | 7950353 | *max_len_q = TAB_MAX_LEN(fc->tab.max_len_q[vertical], qx, qy); | |
707 | 7950353 | } | |
708 | |||
709 | //part of 8.8.3.3 Derivation process of transform block boundary | ||
710 | 4643728 | static void max_filter_length_chroma(const VVCFrameContext *fc, const int qx, const int qy, | |
711 | const int vertical, const int horizontal_ctu_edge, const int bs, uint8_t *max_len_p, uint8_t *max_len_q) | ||
712 | { | ||
713 |
2/2✓ Branch 0 taken 2234925 times.
✓ Branch 1 taken 2408803 times.
|
4643728 | const int px = vertical ? qx - 1 : qx; |
714 |
2/2✓ Branch 0 taken 2408803 times.
✓ Branch 1 taken 2234925 times.
|
4643728 | const int py = !vertical ? qy - 1 : qy; |
715 |
2/2✓ Branch 0 taken 2234925 times.
✓ Branch 1 taken 2408803 times.
|
4643728 | const uint8_t *tb_size = vertical ? fc->tab.tb_width[CHROMA] : fc->tab.tb_height[CHROMA]; |
716 | |||
717 | 4643728 | const int size_p = tb_size[(py >> MIN_TU_LOG2) * fc->ps.pps->min_tu_width + (px >> MIN_TU_LOG2)]; | |
718 | 4643728 | const int size_q = tb_size[(qy >> MIN_TU_LOG2) * fc->ps.pps->min_tu_width + (qx >> MIN_TU_LOG2)]; | |
719 |
4/4✓ Branch 0 taken 3767209 times.
✓ Branch 1 taken 876519 times.
✓ Branch 2 taken 3221711 times.
✓ Branch 3 taken 545498 times.
|
4643728 | if (size_p >= 8 && size_q >= 8) { |
720 | 3221711 | *max_len_p = *max_len_q = 3; | |
721 |
2/2✓ Branch 0 taken 382205 times.
✓ Branch 1 taken 2839506 times.
|
3221711 | if (horizontal_ctu_edge) |
722 | 382205 | *max_len_p = 1; | |
723 | } else { | ||
724 | //part of 8.8.3.6.4 Decision process for chroma block edges | ||
725 | 1422017 | *max_len_p = *max_len_q = (bs == 2); | |
726 | } | ||
727 | 4643728 | } | |
728 | |||
729 | 12594081 | static void max_filter_length(const VVCFrameContext *fc, const int qx, const int qy, | |
730 | const int c_idx, const int vertical, const int horizontal_ctu_edge, const int bs, uint8_t *max_len_p, uint8_t *max_len_q) | ||
731 | { | ||
732 |
2/2✓ Branch 0 taken 7950353 times.
✓ Branch 1 taken 4643728 times.
|
12594081 | if (!c_idx) |
733 | 7950353 | max_filter_length_luma(fc, qx, qy, vertical, max_len_p, max_len_q); | |
734 | else | ||
735 | 4643728 | max_filter_length_chroma(fc, qx, qy, vertical, horizontal_ctu_edge, bs, max_len_p, max_len_q); | |
736 | 12594081 | } | |
737 | |||
738 | #define TC_CALC(qp, bs) \ | ||
739 | tctable[av_clip((qp) + DEFAULT_INTRA_TC_OFFSET * ((bs) - 1) + \ | ||
740 | (tc_offset & -2), \ | ||
741 | 0, MAX_QP + DEFAULT_INTRA_TC_OFFSET)] | ||
742 | |||
743 | // part of 8.8.3.6.2 Decision process for luma block edges | ||
744 | 7950353 | static int get_qp_y(const VVCFrameContext *fc, const uint8_t *src, const int x, const int y, const int vertical) | |
745 | { | ||
746 | 7950353 | const VVCSPS *sps = fc->ps.sps; | |
747 | 7950353 | const int qp = (ff_vvc_get_qPy(fc, x - vertical, y - !vertical) + ff_vvc_get_qPy(fc, x, y) + 1) >> 1; | |
748 | 7950353 | int qp_offset = 0; | |
749 | int level; | ||
750 | |||
751 |
2/2✓ Branch 0 taken 7478474 times.
✓ Branch 1 taken 471879 times.
|
7950353 | if (!sps->r->sps_ladf_enabled_flag) |
752 | 7478474 | return qp; | |
753 | |||
754 | 471879 | level = fc->vvcdsp.lf.ladf_level[vertical](src, fc->frame->linesize[LUMA]); | |
755 | 471879 | qp_offset = sps->r->sps_ladf_lowest_interval_qp_offset; | |
756 |
4/4✓ Branch 0 taken 932712 times.
✓ Branch 1 taken 437994 times.
✓ Branch 2 taken 898827 times.
✓ Branch 3 taken 33885 times.
|
1370706 | for (int i = 0; i < sps->num_ladf_intervals - 1 && level > sps->ladf_interval_lower_bound[i + 1]; i++) |
757 | 898827 | qp_offset = sps->r->sps_ladf_qp_offset[i]; | |
758 | |||
759 | 471879 | return qp + qp_offset; | |
760 | } | ||
761 | |||
762 | // part of 8.8.3.6.2 Decision process for luma block edges | ||
763 | 4643728 | static int get_qp_c(const VVCFrameContext *fc, const int x, const int y, const int c_idx, const int vertical) | |
764 | { | ||
765 | 4643728 | const VVCSPS *sps = fc->ps.sps; | |
766 | 4643728 | return (get_qPc(fc, x - vertical, y - !vertical, c_idx) + get_qPc(fc, x, y, c_idx) - 2 * sps->qp_bd_offset + 1) >> 1; | |
767 | } | ||
768 | |||
769 | 12594081 | static int get_qp(const VVCFrameContext *fc, const uint8_t *src, const int x, const int y, const int c_idx, const int vertical) | |
770 | { | ||
771 |
2/2✓ Branch 0 taken 7950353 times.
✓ Branch 1 taken 4643728 times.
|
12594081 | if (!c_idx) |
772 | 7950353 | return get_qp_y(fc, src, x, y, vertical); | |
773 | 4643728 | return get_qp_c(fc, x, y, c_idx, vertical); | |
774 | } | ||
775 | |||
776 | 106702 | static void vvc_deblock(const VVCLocalContext *lc, int x0, int y0, const int rs, const int vertical) | |
777 | { | ||
778 | 106702 | VVCFrameContext *fc = lc->fc; | |
779 | 106702 | const VVCSPS *sps = fc->ps.sps; | |
780 |
2/2✓ Branch 0 taken 105646 times.
✓ Branch 1 taken 1056 times.
|
106702 | const int c_end = sps->r->sps_chroma_format_idc ? VVC_MAX_SAMPLE_ARRAYS : 1; |
781 | 106702 | const int ctb_size = fc->ps.sps->ctb_size_y; | |
782 | 106702 | const DBParams *params = fc->tab.deblock + rs; | |
783 | 106702 | int x_end = FFMIN(x0 + ctb_size, fc->ps.pps->width); | |
784 | 106702 | int y_end = FFMIN(y0 + ctb_size, fc->ps.pps->height); | |
785 | 106702 | const int log2_min_cb_size = fc->ps.sps->min_cb_log2_size_y; | |
786 | 106702 | const int min_cb_width = fc->ps.pps->min_cb_width; | |
787 | |||
788 |
2/2✓ Branch 0 taken 53351 times.
✓ Branch 1 taken 53351 times.
|
106702 | if (!vertical) { |
789 | 53351 | FFSWAP(int, x_end, y_end); | |
790 | 53351 | FFSWAP(int, x0, y0); | |
791 | } | ||
792 | |||
793 |
2/2✓ Branch 0 taken 317994 times.
✓ Branch 1 taken 106702 times.
|
424696 | for (int c_idx = 0; c_idx < c_end; c_idx++) { |
794 |
2/2✓ Branch 0 taken 158997 times.
✓ Branch 1 taken 158997 times.
|
317994 | const int hs = (vertical ? sps->hshift : sps->vshift)[c_idx]; |
795 |
2/2✓ Branch 0 taken 158997 times.
✓ Branch 1 taken 158997 times.
|
317994 | const int vs = (vertical ? sps->vshift : sps->hshift)[c_idx]; |
796 |
2/2✓ Branch 0 taken 211292 times.
✓ Branch 1 taken 106702 times.
|
317994 | const int grid = c_idx ? (CHROMA_GRID << hs) : LUMA_GRID; |
797 | 317994 | const int tc_offset = params->tc_offset[c_idx]; | |
798 | 317994 | const int beta_offset = params->beta_offset[c_idx]; | |
799 | 317994 | const int src_stride = fc->frame->linesize[c_idx]; | |
800 | |||
801 |
2/2✓ Branch 0 taken 3788561 times.
✓ Branch 1 taken 317994 times.
|
4106555 | for (int y = y0; y < y_end; y += (DEBLOCK_STEP << vs)) { |
802 |
4/4✓ Branch 0 taken 3345861 times.
✓ Branch 1 taken 442700 times.
✓ Branch 2 taken 73955640 times.
✓ Branch 3 taken 3788561 times.
|
77744201 | for (int x = x0 ? x0 : grid; x < x_end; x += grid) { |
803 |
4/4✓ Branch 0 taken 36919102 times.
✓ Branch 1 taken 37036538 times.
✓ Branch 2 taken 1636732 times.
✓ Branch 3 taken 35282370 times.
|
73955640 | const uint8_t horizontal_ctu_edge = !vertical && !(x % ctb_size); |
804 | 73955640 | int32_t bs[4], beta[4], tc[4] = { 0 }, all_zero_bs = 1; | |
805 | uint8_t max_len_p[4], max_len_q[4]; | ||
806 | 73955640 | uint8_t no_p[4] = { 0 }; | |
807 | 73955640 | uint8_t no_q[4] = { 0 }; | |
808 | |||
809 |
2/2✓ Branch 0 taken 163455800 times.
✓ Branch 1 taken 73955640 times.
|
237411440 | for (int i = 0; i < DEBLOCK_STEP >> (2 - vs); i++) { |
810 | 163455800 | int tx = x; | |
811 | 163455800 | int ty = y + (i << 2); | |
812 | 163455800 | const int end = ty >= y_end; | |
813 | |||
814 |
2/2✓ Branch 0 taken 82155116 times.
✓ Branch 1 taken 81300684 times.
|
163455800 | if (!vertical) |
815 | 82155116 | FFSWAP(int, tx, ty); | |
816 | |||
817 |
2/2✓ Branch 0 taken 163374332 times.
✓ Branch 1 taken 81468 times.
|
163455800 | bs[i] = end ? 0 : TAB_BS(fc->tab.bs[vertical][c_idx], tx, ty); |
818 |
2/2✓ Branch 0 taken 12594081 times.
✓ Branch 1 taken 150861719 times.
|
163455800 | if (bs[i]) { |
819 | 12594081 | const int qp = get_qp(fc, POS(c_idx, tx, ty), tx, ty, c_idx, vertical); | |
820 | 12594081 | beta[i] = betatable[av_clip(qp + beta_offset, 0, MAX_QP)]; | |
821 | 12594081 | tc[i] = TC_CALC(qp, bs[i]) ; | |
822 | 12594081 | max_filter_length(fc, tx, ty, c_idx, vertical, horizontal_ctu_edge, bs[i], &max_len_p[i], &max_len_q[i]); | |
823 | 12594081 | all_zero_bs = 0; | |
824 | |||
825 |
2/2✓ Branch 0 taken 759484 times.
✓ Branch 1 taken 11834597 times.
|
12594081 | if (sps->r->sps_palette_enabled_flag) { |
826 | 759484 | const int cu_q = (ty >> log2_min_cb_size) * min_cb_width + (tx >> log2_min_cb_size); | |
827 | 759484 | const int cu_p = (ty - !vertical >> log2_min_cb_size) * min_cb_width + (tx - vertical >> log2_min_cb_size); | |
828 | 759484 | no_q[i] = fc->tab.cpm[!!c_idx][cu_q] == MODE_PLT; | |
829 |
3/4✓ Branch 0 taken 759484 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 34199 times.
✓ Branch 3 taken 725285 times.
|
759484 | no_p[i] = cu_p >= 0 && fc->tab.cpm[!!c_idx][cu_p] == MODE_PLT; |
830 | } | ||
831 | } | ||
832 | } | ||
833 | |||
834 |
2/2✓ Branch 0 taken 5500790 times.
✓ Branch 1 taken 68454850 times.
|
73955640 | if (!all_zero_bs) { |
835 |
2/2✓ Branch 0 taken 2661444 times.
✓ Branch 1 taken 2839346 times.
|
5500790 | uint8_t *src = vertical ? POS(c_idx, x, y) : POS(c_idx, y, x); |
836 |
2/2✓ Branch 0 taken 4078123 times.
✓ Branch 1 taken 1422667 times.
|
5500790 | if (!c_idx) |
837 | 4078123 | fc->vvcdsp.lf.filter_luma[vertical](src, src_stride, beta, tc, no_p, no_q, max_len_p, max_len_q, horizontal_ctu_edge); | |
838 | else | ||
839 | 1422667 | fc->vvcdsp.lf.filter_chroma[vertical](src, src_stride, beta, tc, no_p, no_q, max_len_p, max_len_q, vs); | |
840 | } | ||
841 | } | ||
842 | } | ||
843 | } | ||
844 | 106702 | } | |
845 | |||
846 | 53351 | void ff_vvc_deblock_vertical(const VVCLocalContext *lc, const int x0, const int y0, const int rs) | |
847 | { | ||
848 | 53351 | vvc_deblock(lc, x0, y0, rs, 1); | |
849 | 53351 | } | |
850 | |||
851 | 53351 | void ff_vvc_deblock_horizontal(const VVCLocalContext *lc, const int x0, const int y0, const int rs) | |
852 | { | ||
853 | 53351 | vvc_deblock(lc, x0, y0, rs, 0); | |
854 | 53351 | } | |
855 | |||
856 | 676533 | static void alf_copy_border(uint8_t *dst, const uint8_t *src, | |
857 | const int pixel_shift, int width, const int height, const ptrdiff_t dst_stride, const ptrdiff_t src_stride) | ||
858 | { | ||
859 | 676533 | width <<= pixel_shift; | |
860 |
2/2✓ Branch 0 taken 34932385 times.
✓ Branch 1 taken 676533 times.
|
35608918 | for (int i = 0; i < height; i++) { |
861 | 34932385 | memcpy(dst, src, width); | |
862 | 34932385 | dst += dst_stride; | |
863 | 34932385 | src += src_stride; | |
864 | } | ||
865 | 676533 | } | |
866 | |||
867 | 10889 | static void alf_extend_vert(uint8_t *_dst, const uint8_t *_src, | |
868 | const int pixel_shift, const int width, const int height, ptrdiff_t stride) | ||
869 | { | ||
870 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10889 times.
|
10889 | if (pixel_shift == 0) { |
871 | ✗ | for (int i = 0; i < height; i++) { | |
872 | ✗ | memset(_dst, *_src, width); | |
873 | ✗ | _src += stride; | |
874 | ✗ | _dst += stride; | |
875 | } | ||
876 | } else { | ||
877 | 10889 | const uint16_t *src = (const uint16_t *)_src; | |
878 | 10889 | uint16_t *dst = (uint16_t *)_dst; | |
879 | 10889 | stride >>= pixel_shift; | |
880 | |||
881 |
2/2✓ Branch 0 taken 1068596 times.
✓ Branch 1 taken 10889 times.
|
1079485 | for (int i = 0; i < height; i++) { |
882 |
2/2✓ Branch 0 taken 2750808 times.
✓ Branch 1 taken 1068596 times.
|
3819404 | for (int j = 0; j < width; j++) |
883 | 2750808 | dst[j] = *src; | |
884 | 1068596 | src += stride; | |
885 | 1068596 | dst += stride; | |
886 | } | ||
887 | } | ||
888 | 10889 | } | |
889 | |||
890 | 48844 | static void alf_extend_horz(uint8_t *dst, const uint8_t *src, | |
891 | const int pixel_shift, int width, const int height, const ptrdiff_t stride) | ||
892 | { | ||
893 | 48844 | width <<= pixel_shift; | |
894 |
2/2✓ Branch 0 taken 120145 times.
✓ Branch 1 taken 48844 times.
|
168989 | for (int i = 0; i < height; i++) { |
895 | 120145 | memcpy(dst, src, width); | |
896 | 120145 | dst += stride; | |
897 | } | ||
898 | 48844 | } | |
899 | |||
900 | 128895 | static void alf_copy_ctb_to_hv(VVCFrameContext *fc, const uint8_t *src, const ptrdiff_t src_stride, | |
901 | const int x, const int y, const int width, const int height, const int rx, const int ry, const int c_idx) | ||
902 | { | ||
903 | 128895 | const int ps = fc->ps.sps->pixel_shift; | |
904 | 128895 | const int w = fc->ps.pps->width >> fc->ps.sps->hshift[c_idx]; | |
905 | 128895 | const int h = fc->ps.pps->height >> fc->ps.sps->vshift[c_idx]; | |
906 |
2/2✓ Branch 0 taken 43317 times.
✓ Branch 1 taken 85578 times.
|
128895 | const int border_pixels = (c_idx == 0) ? ALF_BORDER_LUMA : ALF_BORDER_CHROMA; |
907 | 128895 | const int offset_h[] = { 0, height - border_pixels }; | |
908 | 128895 | const int offset_v[] = { 0, width - border_pixels }; | |
909 | |||
910 | /* copy horizontal edges */ | ||
911 |
2/2✓ Branch 0 taken 257790 times.
✓ Branch 1 taken 128895 times.
|
386685 | for (int i = 0; i < FF_ARRAY_ELEMS(offset_h); i++) { |
912 | 257790 | alf_copy_border(fc->tab.alf_pixel_buffer_h[c_idx][i] + ((border_pixels * ry * w + x)<< ps), | |
913 | 257790 | src + offset_h[i] * src_stride, ps, width, border_pixels, w << ps, src_stride); | |
914 | } | ||
915 | /* copy vertical edges */ | ||
916 |
2/2✓ Branch 0 taken 257790 times.
✓ Branch 1 taken 128895 times.
|
386685 | for (int i = 0; i < FF_ARRAY_ELEMS(offset_v); i++) { |
917 | 257790 | alf_copy_border(fc->tab.alf_pixel_buffer_v[c_idx][i] + ((h * rx + y) * (border_pixels << ps)), | |
918 | 257790 | src + (offset_v[i] << ps), ps, border_pixels, height, border_pixels << ps, src_stride); | |
919 | } | ||
920 | 128895 | } | |
921 | |||
922 | 95278 | static void alf_fill_border_h(uint8_t *dst, const ptrdiff_t dst_stride, const uint8_t *src, const ptrdiff_t src_stride, | |
923 | const uint8_t *border, const int width, const int border_pixels, const int ps, const int edge) | ||
924 | { | ||
925 |
2/2✓ Branch 0 taken 18714 times.
✓ Branch 1 taken 76564 times.
|
95278 | if (edge) |
926 | 18714 | alf_extend_horz(dst, border, ps, width, border_pixels, dst_stride); | |
927 | else | ||
928 | 76564 | alf_copy_border(dst, src, ps, width, border_pixels, dst_stride, src_stride); | |
929 | 95278 | } | |
930 | |||
931 | 95278 | static void alf_fill_border_v(uint8_t *dst, const ptrdiff_t dst_stride, const uint8_t *src, | |
932 | const uint8_t *border, const int border_pixels, const int height, const int pixel_shift, const int *edges, const int edge) | ||
933 | { | ||
934 | 95278 | const ptrdiff_t src_stride = (border_pixels << pixel_shift); | |
935 | |||
936 |
2/2✓ Branch 0 taken 10889 times.
✓ Branch 1 taken 84389 times.
|
95278 | if (edge) { |
937 | 10889 | alf_extend_vert(dst, border, pixel_shift, border_pixels, height + 2 * border_pixels, dst_stride); | |
938 | 10889 | return; | |
939 | } | ||
940 | |||
941 | //left/right | ||
942 | 84389 | alf_copy_border(dst + dst_stride * border_pixels * edges[TOP], src + src_stride * border_pixels * edges[TOP], | |
943 | 84389 | pixel_shift, border_pixels, height + (!edges[TOP] + !edges[BOTTOM]) * border_pixels, dst_stride, src_stride); | |
944 | |||
945 | //top left/right | ||
946 |
2/2✓ Branch 0 taken 13714 times.
✓ Branch 1 taken 70675 times.
|
84389 | if (edges[TOP]) |
947 | 13714 | alf_extend_horz(dst, dst + dst_stride * border_pixels, pixel_shift, border_pixels, border_pixels, dst_stride); | |
948 | |||
949 | //bottom left/right | ||
950 |
2/2✓ Branch 0 taken 16416 times.
✓ Branch 1 taken 67973 times.
|
84389 | if (edges[BOTTOM]) { |
951 | 16416 | dst += dst_stride * (border_pixels + height); | |
952 | 16416 | alf_extend_horz(dst, dst - dst_stride, pixel_shift, border_pixels, border_pixels, dst_stride); | |
953 | } | ||
954 | } | ||
955 | |||
956 | 47639 | static void alf_prepare_buffer(VVCFrameContext *fc, uint8_t *_dst, const uint8_t *_src, const int x, const int y, | |
957 | const int rx, const int ry, const int width, const int height, const ptrdiff_t dst_stride, const ptrdiff_t src_stride, | ||
958 | const int c_idx, const int *edges) | ||
959 | { | ||
960 | 47639 | const int ps = fc->ps.sps->pixel_shift; | |
961 | 47639 | const int w = fc->ps.pps->width >> fc->ps.sps->hshift[c_idx]; | |
962 | 47639 | const int h = fc->ps.pps->height >> fc->ps.sps->vshift[c_idx]; | |
963 |
2/2✓ Branch 0 taken 21430 times.
✓ Branch 1 taken 26209 times.
|
47639 | const int border_pixels = c_idx == 0 ? ALF_BORDER_LUMA : ALF_BORDER_CHROMA; |
964 | uint8_t *dst, *src; | ||
965 | |||
966 | 47639 | copy_ctb(_dst, _src, width << ps, height, dst_stride, src_stride); | |
967 | |||
968 | //top | ||
969 | 47639 | src = fc->tab.alf_pixel_buffer_h[c_idx][1] + (((border_pixels * w) << ps) * (ry - 1) + (x << ps)); | |
970 | 47639 | dst = _dst - border_pixels * dst_stride; | |
971 | 47639 | alf_fill_border_h(dst, dst_stride, src, w << ps, _dst, width, border_pixels, ps, edges[TOP]); | |
972 | |||
973 | //bottom | ||
974 | 47639 | src = fc->tab.alf_pixel_buffer_h[c_idx][0] + (((border_pixels * w) << ps) * (ry + 1) + (x << ps)); | |
975 | 47639 | dst = _dst + height * dst_stride; | |
976 | 47639 | alf_fill_border_h(dst, dst_stride, src, w << ps, _dst + (height - 1) * dst_stride, width, border_pixels, ps, edges[BOTTOM]); | |
977 | |||
978 | |||
979 | //left | ||
980 | 47639 | src = fc->tab.alf_pixel_buffer_v[c_idx][1] + (h * (rx - 1) + y - border_pixels) * (border_pixels << ps); | |
981 | 47639 | dst = _dst - (border_pixels << ps) - border_pixels * dst_stride; | |
982 | 47639 | alf_fill_border_v(dst, dst_stride, src, dst + (border_pixels << ps), border_pixels, height, ps, edges, edges[LEFT]); | |
983 | |||
984 | //right | ||
985 | 47639 | src = fc->tab.alf_pixel_buffer_v[c_idx][0] + (h * (rx + 1) + y - border_pixels) * (border_pixels << ps); | |
986 | 47639 | dst = _dst + (width << ps) - border_pixels * dst_stride; | |
987 | 47639 | alf_fill_border_v(dst, dst_stride, src, dst - (1 << ps), border_pixels, height, ps, edges, edges[RIGHT]); | |
988 | 47639 | } | |
989 | |||
990 | #define ALF_MAX_BLOCKS_IN_CTU (MAX_CTU_SIZE * MAX_CTU_SIZE / ALF_BLOCK_SIZE / ALF_BLOCK_SIZE) | ||
991 | #define ALF_MAX_FILTER_SIZE (ALF_MAX_BLOCKS_IN_CTU * ALF_NUM_COEFF_LUMA) | ||
992 | |||
993 | 20795 | static void alf_get_coeff_and_clip(VVCLocalContext *lc, int16_t *coeff, int16_t *clip, | |
994 | const uint8_t *src, ptrdiff_t src_stride, int width, int height, int vb_pos, const ALFParams *alf) | ||
995 | { | ||
996 | 20795 | const VVCFrameContext *fc = lc->fc; | |
997 | 20795 | const H266RawSliceHeader *rsh = lc->sc->sh.r; | |
998 | 20795 | uint8_t fixed_clip_set[ALF_NUM_FILTERS_LUMA][ALF_NUM_COEFF_LUMA] = { 0 }; | |
999 | const int16_t *coeff_set; | ||
1000 | const uint8_t *clip_idx_set; | ||
1001 | const uint8_t *class_to_filt; | ||
1002 | 20795 | const int size = width * height / ALF_BLOCK_SIZE / ALF_BLOCK_SIZE; | |
1003 | int class_idx[ALF_MAX_BLOCKS_IN_CTU]; | ||
1004 | int transpose_idx[ALF_MAX_BLOCKS_IN_CTU]; | ||
1005 | |||
1006 |
2/2✓ Branch 0 taken 2791 times.
✓ Branch 1 taken 18004 times.
|
20795 | if (alf->ctb_filt_set_idx_y < 16) { |
1007 | 2791 | coeff_set = &ff_vvc_alf_fix_filt_coeff[0][0]; | |
1008 | 2791 | clip_idx_set = &fixed_clip_set[0][0]; | |
1009 | 2791 | class_to_filt = ff_vvc_alf_class_to_filt_map[alf->ctb_filt_set_idx_y]; | |
1010 | } else { | ||
1011 | 18004 | const int id = rsh->sh_alf_aps_id_luma[alf->ctb_filt_set_idx_y - 16]; | |
1012 | 18004 | const VVCALF *aps = fc->ps.alf_list[id]; | |
1013 | 18004 | coeff_set = &aps->luma_coeff[0][0]; | |
1014 | 18004 | clip_idx_set = &aps->luma_clip_idx[0][0]; | |
1015 | 18004 | class_to_filt = ff_vvc_alf_aps_class_to_filt_map; | |
1016 | } | ||
1017 | 20795 | fc->vvcdsp.alf.classify(class_idx, transpose_idx, src, src_stride, width, height, | |
1018 | 20795 | vb_pos, lc->alf_gradient_tmp); | |
1019 | 20795 | fc->vvcdsp.alf.recon_coeff_and_clip(coeff, clip, class_idx, transpose_idx, size, | |
1020 | coeff_set, clip_idx_set, class_to_filt); | ||
1021 | 20795 | } | |
1022 | |||
1023 | 20795 | static void alf_filter_luma(VVCLocalContext *lc, uint8_t *dst, const uint8_t *src, | |
1024 | const ptrdiff_t dst_stride, const ptrdiff_t src_stride, const int x0, const int y0, | ||
1025 | const int width, const int height, const int _vb_pos, const ALFParams *alf) | ||
1026 | { | ||
1027 | 20795 | const VVCFrameContext *fc = lc->fc; | |
1028 | 20795 | int vb_pos = _vb_pos - y0; | |
1029 | 20795 | int16_t *coeff = (int16_t*)lc->tmp; | |
1030 | 20795 | int16_t *clip = (int16_t *)lc->tmp1; | |
1031 | |||
1032 | av_assert0(ALF_MAX_FILTER_SIZE <= sizeof(lc->tmp)); | ||
1033 | av_assert0(ALF_MAX_FILTER_SIZE * sizeof(int16_t) <= sizeof(lc->tmp1)); | ||
1034 | |||
1035 | 20795 | alf_get_coeff_and_clip(lc, coeff, clip, src, src_stride, width, height, vb_pos, alf); | |
1036 | 20795 | fc->vvcdsp.alf.filter[LUMA](dst, dst_stride, src, src_stride, width, height, coeff, clip, vb_pos); | |
1037 | 20795 | } | |
1038 | |||
1039 | 157254 | static int alf_clip_from_idx(const VVCFrameContext *fc, const int idx) | |
1040 | { | ||
1041 | 157254 | const VVCSPS *sps = fc->ps.sps; | |
1042 | 157254 | const int offset[] = {0, 3, 5, 7}; | |
1043 | |||
1044 | 157254 | return 1 << (sps->bit_depth - offset[idx]); | |
1045 | } | ||
1046 | |||
1047 | 26209 | static void alf_filter_chroma(VVCLocalContext *lc, uint8_t *dst, const uint8_t *src, | |
1048 | const ptrdiff_t dst_stride, const ptrdiff_t src_stride, const int c_idx, | ||
1049 | const int width, const int height, const int vb_pos, const ALFParams *alf) | ||
1050 | { | ||
1051 | 26209 | VVCFrameContext *fc = lc->fc; | |
1052 | 26209 | const H266RawSliceHeader *rsh = lc->sc->sh.r; | |
1053 | 26209 | const VVCALF *aps = fc->ps.alf_list[rsh->sh_alf_aps_id_chroma]; | |
1054 | 26209 | const int idx = alf->alf_ctb_filter_alt_idx[c_idx - 1]; | |
1055 | 26209 | const int16_t *coeff = aps->chroma_coeff[idx]; | |
1056 | int16_t clip[ALF_NUM_COEFF_CHROMA]; | ||
1057 | |||
1058 |
2/2✓ Branch 0 taken 157254 times.
✓ Branch 1 taken 26209 times.
|
183463 | for (int i = 0; i < ALF_NUM_COEFF_CHROMA; i++) |
1059 | 157254 | clip[i] = alf_clip_from_idx(fc, aps->chroma_clip_idx[idx][i]); | |
1060 | |||
1061 | 26209 | fc->vvcdsp.alf.filter[CHROMA](dst, dst_stride, src, src_stride, width, height, coeff, clip, vb_pos); | |
1062 | 26209 | } | |
1063 | |||
1064 | 10527 | static void alf_filter_cc(VVCLocalContext *lc, uint8_t *dst, const uint8_t *luma, | |
1065 | const ptrdiff_t dst_stride, const ptrdiff_t luma_stride, const int c_idx, | ||
1066 | const int width, const int height, const int hs, const int vs, const int vb_pos, const ALFParams *alf) | ||
1067 | { | ||
1068 | 10527 | const VVCFrameContext *fc = lc->fc; | |
1069 | 10527 | const H266RawSliceHeader *rsh = lc->sc->sh.r; | |
1070 | 10527 | const int idx = c_idx - 1; | |
1071 |
2/2✓ Branch 0 taken 5379 times.
✓ Branch 1 taken 5148 times.
|
10527 | const int cc_aps_id = c_idx == CB ? rsh->sh_alf_cc_cb_aps_id : rsh->sh_alf_cc_cr_aps_id; |
1072 | 10527 | const VVCALF *aps = fc->ps.alf_list[cc_aps_id]; | |
1073 | |||
1074 |
1/2✓ Branch 0 taken 10527 times.
✗ Branch 1 not taken.
|
10527 | if (aps) { |
1075 | 10527 | const int16_t *coeff = aps->cc_coeff[idx][alf->ctb_cc_idc[idx] - 1]; | |
1076 | |||
1077 | 10527 | fc->vvcdsp.alf.filter_cc(dst, dst_stride, luma, luma_stride, width, height, hs, vs, coeff, vb_pos); | |
1078 | } | ||
1079 | 10527 | } | |
1080 | |||
1081 | 43317 | void ff_vvc_alf_copy_ctu_to_hv(VVCLocalContext* lc, const int x0, const int y0) | |
1082 | { | ||
1083 | 43317 | VVCFrameContext *fc = lc->fc; | |
1084 | 43317 | const int rx = x0 >> fc->ps.sps->ctb_log2_size_y; | |
1085 | 43317 | const int ry = y0 >> fc->ps.sps->ctb_log2_size_y; | |
1086 | 43317 | const int ctb_size_y = fc->ps.sps->ctb_size_y; | |
1087 |
2/2✓ Branch 0 taken 42789 times.
✓ Branch 1 taken 528 times.
|
43317 | const int c_end = fc->ps.sps->r->sps_chroma_format_idc ? VVC_MAX_SAMPLE_ARRAYS : 1; |
1088 | |||
1089 |
2/2✓ Branch 0 taken 128895 times.
✓ Branch 1 taken 43317 times.
|
172212 | for (int c_idx = 0; c_idx < c_end; c_idx++) { |
1090 | 128895 | const int hs = fc->ps.sps->hshift[c_idx]; | |
1091 | 128895 | const int vs = fc->ps.sps->vshift[c_idx]; | |
1092 | 128895 | const int x = x0 >> hs; | |
1093 | 128895 | const int y = y0 >> vs; | |
1094 | 128895 | const int width = FFMIN(fc->ps.pps->width - x0, ctb_size_y) >> hs; | |
1095 | 128895 | const int height = FFMIN(fc->ps.pps->height - y0, ctb_size_y) >> vs; | |
1096 | |||
1097 | 128895 | const int src_stride = fc->frame->linesize[c_idx]; | |
1098 | 128895 | uint8_t *src = POS(c_idx, x0, y0); | |
1099 | |||
1100 | 128895 | alf_copy_ctb_to_hv(fc, src, src_stride, x, y, width, height, rx, ry, c_idx); | |
1101 | } | ||
1102 | 43317 | } | |
1103 | |||
1104 | 43317 | static void alf_get_edges(const VVCLocalContext *lc, int edges[MAX_EDGES], const int rx, const int ry) | |
1105 | { | ||
1106 | 43317 | VVCFrameContext *fc = lc->fc; | |
1107 | 43317 | const VVCSPS *sps = fc->ps.sps; | |
1108 | 43317 | const VVCPPS *pps = fc->ps.pps; | |
1109 | 43317 | const int subpic_idx = lc->sc->sh.r->curr_subpic_idx; | |
1110 | |||
1111 | // we can't use |= instead of || in this function; |= is not a shortcut operator | ||
1112 | |||
1113 |
2/2✓ Branch 0 taken 39898 times.
✓ Branch 1 taken 3419 times.
|
43317 | if (!pps->r->pps_loop_filter_across_tiles_enabled_flag) { |
1114 |
4/4✓ Branch 0 taken 36076 times.
✓ Branch 1 taken 3822 times.
✓ Branch 2 taken 612 times.
✓ Branch 3 taken 35464 times.
|
39898 | edges[LEFT] = edges[LEFT] || (lc->boundary_flags & BOUNDARY_LEFT_TILE); |
1115 |
4/4✓ Branch 0 taken 33134 times.
✓ Branch 1 taken 6764 times.
✓ Branch 2 taken 564 times.
✓ Branch 3 taken 32570 times.
|
39898 | edges[TOP] = edges[TOP] || (lc->boundary_flags & BOUNDARY_UPPER_TILE); |
1116 |
4/4✓ Branch 0 taken 36076 times.
✓ Branch 1 taken 3822 times.
✓ Branch 2 taken 612 times.
✓ Branch 3 taken 35464 times.
|
39898 | edges[RIGHT] = edges[RIGHT] || pps->ctb_to_col_bd[rx] != pps->ctb_to_col_bd[rx + 1]; |
1117 |
4/4✓ Branch 0 taken 33134 times.
✓ Branch 1 taken 6764 times.
✓ Branch 2 taken 564 times.
✓ Branch 3 taken 32570 times.
|
39898 | edges[BOTTOM] = edges[BOTTOM] || pps->ctb_to_row_bd[ry] != pps->ctb_to_row_bd[ry + 1]; |
1118 | } | ||
1119 | |||
1120 |
2/2✓ Branch 0 taken 39849 times.
✓ Branch 1 taken 3468 times.
|
43317 | if (!pps->r->pps_loop_filter_across_slices_enabled_flag) { |
1121 |
4/4✓ Branch 0 taken 35548 times.
✓ Branch 1 taken 4301 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 35543 times.
|
39849 | edges[LEFT] = edges[LEFT] || (lc->boundary_flags & BOUNDARY_LEFT_SLICE); |
1122 |
4/4✓ Branch 0 taken 32654 times.
✓ Branch 1 taken 7195 times.
✓ Branch 2 taken 71 times.
✓ Branch 3 taken 32583 times.
|
39849 | edges[TOP] = edges[TOP] || (lc->boundary_flags & BOUNDARY_UPPER_SLICE); |
1123 |
4/4✓ Branch 0 taken 35548 times.
✓ Branch 1 taken 4301 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 35543 times.
|
39849 | edges[RIGHT] = edges[RIGHT] || CTB(fc->tab.slice_idx, rx, ry) != CTB(fc->tab.slice_idx, rx + 1, ry); |
1124 |
4/4✓ Branch 0 taken 32654 times.
✓ Branch 1 taken 7195 times.
✓ Branch 2 taken 71 times.
✓ Branch 3 taken 32583 times.
|
39849 | edges[BOTTOM] = edges[BOTTOM] || CTB(fc->tab.slice_idx, rx, ry) != CTB(fc->tab.slice_idx, rx, ry + 1); |
1125 | } | ||
1126 | |||
1127 |
2/2✓ Branch 0 taken 42351 times.
✓ Branch 1 taken 966 times.
|
43317 | if (!sps->r->sps_loop_filter_across_subpic_enabled_flag[subpic_idx]) { |
1128 |
4/4✓ Branch 0 taken 38010 times.
✓ Branch 1 taken 4341 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 38006 times.
|
42351 | edges[LEFT] = edges[LEFT] || (lc->boundary_flags & BOUNDARY_LEFT_SUBPIC); |
1129 |
3/4✓ Branch 0 taken 34926 times.
✓ Branch 1 taken 7425 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 34926 times.
|
42351 | edges[TOP] = edges[TOP] || (lc->boundary_flags & BOUNDARY_UPPER_SUBPIC); |
1130 |
3/4✓ Branch 0 taken 38006 times.
✓ Branch 1 taken 4345 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 38006 times.
|
42351 | edges[RIGHT] = edges[RIGHT] || fc->ps.sps->r->sps_subpic_ctu_top_left_x[subpic_idx] + fc->ps.sps->r->sps_subpic_width_minus1[subpic_idx] == rx; |
1131 |
4/4✓ Branch 0 taken 34938 times.
✓ Branch 1 taken 7413 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 34926 times.
|
42351 | edges[BOTTOM] = edges[BOTTOM] || fc->ps.sps->r->sps_subpic_ctu_top_left_y[subpic_idx] + fc->ps.sps->r->sps_subpic_height_minus1[subpic_idx] == ry; |
1132 | } | ||
1133 | |||
1134 |
2/2✓ Branch 0 taken 1029 times.
✓ Branch 1 taken 42288 times.
|
43317 | if (sps->r->sps_virtual_boundaries_enabled_flag) { |
1135 |
3/4✓ Branch 0 taken 621 times.
✓ Branch 1 taken 408 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 621 times.
|
1029 | edges[LEFT] = edges[LEFT] || is_virtual_boundary(fc, rx << sps->ctb_log2_size_y, 1); |
1136 |
3/4✓ Branch 0 taken 595 times.
✓ Branch 1 taken 434 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 595 times.
|
1029 | edges[TOP] = edges[TOP] || is_virtual_boundary(fc, ry << sps->ctb_log2_size_y, 0); |
1137 |
3/4✓ Branch 0 taken 625 times.
✓ Branch 1 taken 404 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 625 times.
|
1029 | edges[RIGHT] = edges[RIGHT] || is_virtual_boundary(fc, (rx + 1) << sps->ctb_log2_size_y, 1); |
1138 |
3/4✓ Branch 0 taken 583 times.
✓ Branch 1 taken 446 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 583 times.
|
1029 | edges[BOTTOM] = edges[BOTTOM] || is_virtual_boundary(fc, (ry + 1) << sps->ctb_log2_size_y, 0); |
1139 | } | ||
1140 | 43317 | } | |
1141 | |||
1142 | 43317 | static void alf_init_subblock(VVCRect *sb, int sb_edges[MAX_EDGES], const VVCRect *b, const int edges[MAX_EDGES]) | |
1143 | { | ||
1144 | 43317 | *sb = *b; | |
1145 | 43317 | memcpy(sb_edges, edges, sizeof(int) * MAX_EDGES); | |
1146 | 43317 | } | |
1147 | |||
1148 | 43317 | static void alf_get_subblock(VVCRect *sb, int edges[MAX_EDGES], const int bx, const int by, const int vb_pos[2], const int has_vb[2]) | |
1149 | { | ||
1150 | 43317 | int *pos[] = { &sb->l, &sb->t, &sb->r, &sb->b }; | |
1151 | |||
1152 |
2/2✓ Branch 0 taken 86634 times.
✓ Branch 1 taken 43317 times.
|
129951 | for (int vertical = 0; vertical <= 1; vertical++) { |
1153 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 86634 times.
|
86634 | if (has_vb[vertical]) { |
1154 | ✗ | const int c = vertical ? (bx ? LEFT : RIGHT) : (by ? TOP : BOTTOM); | |
1155 | ✗ | *pos[c] = vb_pos[vertical]; | |
1156 | ✗ | edges[c] = 1; | |
1157 | } | ||
1158 | } | ||
1159 | 43317 | } | |
1160 | |||
1161 | 43317 | static void alf_get_subblocks(const VVCLocalContext *lc, VVCRect sbs[MAX_VBBS], int sb_edges[MAX_VBBS][MAX_EDGES], int *nb_sbs, | |
1162 | const int x0, const int y0, const int rx, const int ry) | ||
1163 | { | ||
1164 | 43317 | VVCFrameContext *fc = lc->fc; | |
1165 | 43317 | const VVCSPS *sps = fc->ps.sps; | |
1166 | 43317 | const VVCPPS *pps = fc->ps.pps; | |
1167 | 43317 | const int ctu_size_y = sps->ctb_size_y; | |
1168 | 43317 | const int vb_pos[] = { get_virtual_boundary(fc, ry, 0), get_virtual_boundary(fc, rx, 1) }; | |
1169 | 43317 | const int has_vb[] = { vb_pos[0] > y0, vb_pos[1] > x0 }; | |
1170 | 43317 | const VVCRect b = { x0, y0, FFMIN(x0 + ctu_size_y, pps->width), FFMIN(y0 + ctu_size_y, pps->height) }; | |
1171 | 43317 | int edges[MAX_EDGES] = { !rx, !ry, rx == pps->ctb_width - 1, ry == pps->ctb_height - 1 }; | |
1172 | 43317 | int i = 0; | |
1173 | |||
1174 | 43317 | alf_get_edges(lc, edges, rx, ry); | |
1175 | |||
1176 |
2/2✓ Branch 0 taken 43317 times.
✓ Branch 1 taken 43317 times.
|
86634 | for (int by = 0; by <= has_vb[0]; by++) { |
1177 |
2/2✓ Branch 0 taken 43317 times.
✓ Branch 1 taken 43317 times.
|
86634 | for (int bx = 0; bx <= has_vb[1]; bx++, i++) { |
1178 | 43317 | alf_init_subblock(sbs + i, sb_edges[i], &b, edges); | |
1179 | 43317 | alf_get_subblock(sbs + i, sb_edges[i], bx, by, vb_pos, has_vb); | |
1180 | } | ||
1181 | } | ||
1182 | 43317 | *nb_sbs = i; | |
1183 | 43317 | } | |
1184 | |||
1185 | 43317 | void ff_vvc_alf_filter(VVCLocalContext *lc, const int x0, const int y0) | |
1186 | { | ||
1187 | 43317 | VVCFrameContext *fc = lc->fc; | |
1188 | 43317 | const VVCSPS *sps = fc->ps.sps; | |
1189 | 43317 | const int rx = x0 >> sps->ctb_log2_size_y; | |
1190 | 43317 | const int ry = y0 >> sps->ctb_log2_size_y; | |
1191 | 43317 | const int ps = sps->pixel_shift; | |
1192 | 43317 | const int padded_stride = EDGE_EMU_BUFFER_STRIDE << ps; | |
1193 | 43317 | const int padded_offset = padded_stride * ALF_PADDING_SIZE + (ALF_PADDING_SIZE << ps); | |
1194 |
2/2✓ Branch 0 taken 42789 times.
✓ Branch 1 taken 528 times.
|
43317 | const int c_end = sps->r->sps_chroma_format_idc ? VVC_MAX_SAMPLE_ARRAYS : 1; |
1195 | 43317 | const int has_chroma = !!sps->r->sps_chroma_format_idc; | |
1196 | 43317 | const int ctu_end = y0 + sps->ctb_size_y; | |
1197 | 43317 | const ALFParams *alf = &CTB(fc->tab.alf, rx, ry); | |
1198 | int sb_edges[MAX_VBBS][MAX_EDGES], nb_sbs; | ||
1199 | VVCRect sbs[MAX_VBBS]; | ||
1200 | |||
1201 | 43317 | alf_get_subblocks(lc, sbs, sb_edges, &nb_sbs, x0, y0, rx, ry); | |
1202 | |||
1203 |
2/2✓ Branch 0 taken 43317 times.
✓ Branch 1 taken 43317 times.
|
86634 | for (int i = 0; i < nb_sbs; i++) { |
1204 | 43317 | const VVCRect *sb = sbs + i; | |
1205 |
2/2✓ Branch 0 taken 128895 times.
✓ Branch 1 taken 43317 times.
|
172212 | for (int c_idx = 0; c_idx < c_end; c_idx++) { |
1206 | 128895 | const int hs = fc->ps.sps->hshift[c_idx]; | |
1207 | 128895 | const int vs = fc->ps.sps->vshift[c_idx]; | |
1208 | 128895 | const int x = sb->l >> hs; | |
1209 | 128895 | const int y = sb->t >> vs; | |
1210 | 128895 | const int width = (sb->r - sb->l) >> hs; | |
1211 | 128895 | const int height = (sb->b - sb->t) >> vs; | |
1212 | 128895 | const int src_stride = fc->frame->linesize[c_idx]; | |
1213 | 128895 | uint8_t *src = POS(c_idx, sb->l, sb->t); | |
1214 | uint8_t *padded; | ||
1215 | |||
1216 |
10/10✓ Branch 0 taken 81891 times.
✓ Branch 1 taken 47004 times.
✓ Branch 2 taken 22522 times.
✓ Branch 3 taken 59369 times.
✓ Branch 4 taken 22352 times.
✓ Branch 5 taken 170 times.
✓ Branch 6 taken 21816 times.
✓ Branch 7 taken 536 times.
✓ Branch 8 taken 99 times.
✓ Branch 9 taken 21717 times.
|
128895 | if (alf->ctb_flag[c_idx] || (!c_idx && has_chroma && (alf->ctb_cc_idc[0] || alf->ctb_cc_idc[1]))) { |
1217 |
2/2✓ Branch 0 taken 26209 times.
✓ Branch 1 taken 21430 times.
|
47639 | padded = (c_idx ? lc->alf_buffer_chroma : lc->alf_buffer_luma) + padded_offset; |
1218 | 47639 | alf_prepare_buffer(fc, padded, src, x, y, rx, ry, width, height, | |
1219 | 47639 | padded_stride, src_stride, c_idx, sb_edges[i]); | |
1220 | } | ||
1221 |
2/2✓ Branch 0 taken 47004 times.
✓ Branch 1 taken 81891 times.
|
128895 | if (alf->ctb_flag[c_idx]) { |
1222 |
2/2✓ Branch 0 taken 20795 times.
✓ Branch 1 taken 26209 times.
|
47004 | if (!c_idx) { |
1223 | 20795 | alf_filter_luma(lc, src, padded, src_stride, padded_stride, x, y, | |
1224 | width, height, ctu_end - ALF_VB_POS_ABOVE_LUMA, alf); | ||
1225 | } else { | ||
1226 | 26209 | alf_filter_chroma(lc, src, padded, src_stride, padded_stride, c_idx, | |
1227 | 26209 | width, height, ((ctu_end - sb->t) >> vs) - ALF_VB_POS_ABOVE_CHROMA, alf); | |
1228 | } | ||
1229 | } | ||
1230 |
4/4✓ Branch 0 taken 85578 times.
✓ Branch 1 taken 43317 times.
✓ Branch 2 taken 10527 times.
✓ Branch 3 taken 75051 times.
|
128895 | if (c_idx && alf->ctb_cc_idc[c_idx - 1]) { |
1231 | 10527 | padded = lc->alf_buffer_luma + padded_offset; | |
1232 | 10527 | alf_filter_cc(lc, src, padded, src_stride, padded_stride, c_idx, | |
1233 | 10527 | width, height, hs, vs, ctu_end - sb->t - ALF_VB_POS_ABOVE_LUMA, alf); | |
1234 | } | ||
1235 | } | ||
1236 | } | ||
1237 | 43317 | } | |
1238 | |||
1239 | |||
1240 | 53355 | void ff_vvc_lmcs_filter(const VVCLocalContext *lc, const int x, const int y) | |
1241 | { | ||
1242 | 53355 | const SliceContext *sc = lc->sc; | |
1243 | 53355 | const VVCFrameContext *fc = lc->fc; | |
1244 | 53355 | const int ctb_size = fc->ps.sps->ctb_size_y; | |
1245 | 53355 | const int width = FFMIN(fc->ps.pps->width - x, ctb_size); | |
1246 | 53355 | const int height = FFMIN(fc->ps.pps->height - y, ctb_size); | |
1247 | 53355 | uint8_t *data = POS(LUMA, x, y); | |
1248 |
2/2✓ Branch 0 taken 20135 times.
✓ Branch 1 taken 33220 times.
|
53355 | if (sc->sh.r->sh_lmcs_used_flag) |
1249 | 20135 | fc->vvcdsp.lmcs.filter(data, fc->frame->linesize[LUMA], width, height, &fc->ps.lmcs.inv_lut); | |
1250 | 53355 | } | |
1251 |