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 | 4311054 | static int get_virtual_boundary(const VVCFrameContext *fc, const int ctu_pos, const int vertical) | |
63 | { | ||
64 | 4311054 | const VVCSPS *sps = fc->ps.sps; | |
65 | 4311054 | const VVCPH *ph = &fc->ps.ph; | |
66 |
2/2✓ Branch 0 taken 2183769 times.
✓ Branch 1 taken 2127285 times.
|
4311054 | const uint16_t *vbs = vertical ? ph->vb_pos_x : ph->vb_pos_y; |
67 |
2/2✓ Branch 0 taken 2183769 times.
✓ Branch 1 taken 2127285 times.
|
4311054 | const uint8_t nb_vbs = vertical ? ph->num_ver_vbs : ph->num_hor_vbs; |
68 | 4311054 | const int pos = ctu_pos << sps->ctb_log2_size_y; | |
69 | |||
70 |
2/2✓ Branch 0 taken 329281 times.
✓ Branch 1 taken 3981773 times.
|
4311054 | 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 | 4311054 | return 0; | |
78 | } | ||
79 | |||
80 | 4235662 | static int is_virtual_boundary(const VVCFrameContext *fc, const int pos, const int vertical) | |
81 | { | ||
82 | 4235662 | return get_virtual_boundary(fc, pos >> fc->ps.sps->ctb_log2_size_y, vertical) == pos; | |
83 | } | ||
84 | |||
85 | 8597362 | static int get_qPc(const VVCFrameContext *fc, const int x0, const int y0, const int chroma) | |
86 | { | ||
87 | 8597362 | const int x = x0 >> MIN_TU_LOG2; | |
88 | 8597362 | const int y = y0 >> MIN_TU_LOG2; | |
89 | 8597362 | const int min_tu_width = fc->ps.pps->min_tu_width; | |
90 | 8597362 | return fc->tab.qp[chroma][x + y * min_tu_width]; | |
91 | } | ||
92 | |||
93 | 53774 | 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 5180340 times.
✓ Branch 1 taken 53774 times.
|
5234114 | for (int y = 0; y < height; y++) { |
97 | 5180340 | memcpy(dst, src, width); | |
98 | |||
99 | 5180340 | dst += dst_stride; | |
100 | 5180340 | src += src_stride; | |
101 | } | ||
102 | 53774 | } | |
103 | |||
104 | 28598 | static void copy_pixel(uint8_t *dst, const uint8_t *src, const int pixel_shift) | |
105 | { | ||
106 |
2/2✓ Branch 0 taken 26382 times.
✓ Branch 1 taken 2216 times.
|
28598 | if (pixel_shift) |
107 | 26382 | *(uint16_t *)dst = *(uint16_t *)src; | |
108 | else | ||
109 | 2216 | *dst = *src; | |
110 | 28598 | } | |
111 | |||
112 | 292669 | 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 283926 times.
|
292669 | 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 26425640 times.
✓ Branch 1 taken 283926 times.
|
26709566 | for (i = 0; i < height; i++) { |
124 | 26425640 | *(uint16_t *)dst = *(uint16_t *)src; | |
125 | 26425640 | dst += dst_stride; | |
126 | 26425640 | src += src_stride; | |
127 | } | ||
128 | } | ||
129 | 292669 | } | |
130 | |||
131 | 275598 | 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 | 275598 | const int ps = fc->ps.sps->pixel_shift; | |
136 | 275598 | const int w = fc->ps.pps->width >> fc->ps.sps->hshift[c_idx]; | |
137 | 275598 | const int h = fc->ps.pps->height >> fc->ps.sps->vshift[c_idx]; | |
138 | |||
139 |
2/2✓ Branch 0 taken 137799 times.
✓ Branch 1 taken 137799 times.
|
275598 | if (top) { |
140 | /* top */ | ||
141 | 137799 | memcpy(fc->tab.sao_pixel_buffer_h[c_idx] + (((2 * ry) * w + x) << ps), | |
142 | 137799 | src, width << ps); | |
143 | } else { | ||
144 | /* bottom */ | ||
145 | 137799 | memcpy(fc->tab.sao_pixel_buffer_h[c_idx] + (((2 * ry + 1) * w + x) << ps), | |
146 | 137799 | src + src_stride * (height - 1), width << ps); | |
147 | |||
148 | /* copy vertical edges */ | ||
149 | 137799 | copy_vert(fc->tab.sao_pixel_buffer_v[c_idx] + (((2 * rx) * h + y) << ps), src, ps, height, 1 << ps, src_stride); | |
150 | 137799 | 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 | 275598 | } | |
153 | |||
154 | 92570 | static void sao_copy_ctb_to_hv(VVCLocalContext *lc, const int rx, const int ry, const int top) | |
155 | { | ||
156 | 92570 | VVCFrameContext *fc = lc->fc; | |
157 | 92570 | const int ctb_size_y = fc->ps.sps->ctb_size_y; | |
158 | 92570 | const int x0 = rx << fc->ps.sps->ctb_log2_size_y; | |
159 | 92570 | const int y0 = ry << fc->ps.sps->ctb_log2_size_y; | |
160 | |||
161 |
4/4✓ Branch 0 taken 366056 times.
✓ Branch 1 taken 2112 times.
✓ Branch 2 taken 275598 times.
✓ Branch 3 taken 92570 times.
|
368168 | for (int c_idx = 0; c_idx < (fc->ps.sps->r->sps_chroma_format_idc ? 3 : 1); c_idx++) { |
162 | 275598 | const int x = x0 >> fc->ps.sps->hshift[c_idx]; | |
163 | 275598 | const int y = y0 >> fc->ps.sps->vshift[c_idx]; | |
164 | 275598 | const ptrdiff_t src_stride = fc->frame->linesize[c_idx]; | |
165 | 275598 | const int ctb_size_h = ctb_size_y >> fc->ps.sps->hshift[c_idx]; | |
166 | 275598 | const int ctb_size_v = ctb_size_y >> fc->ps.sps->vshift[c_idx]; | |
167 | 275598 | const int width = FFMIN(ctb_size_h, (fc->ps.pps->width >> fc->ps.sps->hshift[c_idx]) - x); | |
168 | 275598 | const int height = FFMIN(ctb_size_v, (fc->ps.pps->height >> fc->ps.sps->vshift[c_idx]) - y); | |
169 | 275598 | const uint8_t *src = POS(c_idx, x0, y0); | |
170 | 275598 | copy_ctb_to_hv(fc, src, src_stride, x, y, width, height, c_idx, rx, ry, top); | |
171 | } | ||
172 | 92570 | } | |
173 | |||
174 | 46285 | 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 39002 times.
✓ Branch 1 taken 7283 times.
|
46285 | if (ry) |
177 | 39002 | sao_copy_ctb_to_hv(lc, rx, ry - 1, 0); | |
178 | |||
179 | 46285 | sao_copy_ctb_to_hv(lc, rx, ry, 1); | |
180 | |||
181 |
2/2✓ Branch 0 taken 7283 times.
✓ Branch 1 taken 39002 times.
|
46285 | if (last_row) |
182 | 7283 | sao_copy_ctb_to_hv(lc, rx, ry, 0); | |
183 | 46285 | } | |
184 | |||
185 | 284470 | static int sao_can_cross_slices(const VVCFrameContext *fc, const int rx, const int ry, const int dx, const int dy) | |
186 | { | ||
187 | 284470 | const uint8_t lfase = fc->ps.pps->r->pps_loop_filter_across_slices_enabled_flag; | |
188 | |||
189 |
4/4✓ Branch 0 taken 281350 times.
✓ Branch 1 taken 3120 times.
✓ Branch 2 taken 278618 times.
✓ Branch 3 taken 2732 times.
|
284470 | return lfase || CTB(fc->tab.slice_idx, rx, ry) == CTB(fc->tab.slice_idx, rx + dx, ry + dy); |
190 | } | ||
191 | |||
192 | 46285 | 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 | 46285 | const VVCFrameContext *fc = lc->fc; | |
196 | 46285 | const VVCSPS *sps = fc->ps.sps; | |
197 | 46285 | const H266RawSPS *rsps = sps->r; | |
198 | 46285 | const VVCPPS *pps = fc->ps.pps; | |
199 | 46285 | const int subpic_idx = lc->sc->sh.r->curr_subpic_idx; | |
200 | 46285 | const uint8_t lfase = fc->ps.pps->r->pps_loop_filter_across_slices_enabled_flag; | |
201 |
4/4✓ Branch 0 taken 5073 times.
✓ Branch 1 taken 41212 times.
✓ Branch 2 taken 1662 times.
✓ Branch 3 taken 3411 times.
|
46285 | 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 44182 times.
✓ Branch 2 taken 1137 times.
✓ Branch 3 taken 966 times.
|
46285 | const uint8_t no_subpic_filter = rsps->sps_num_subpics_minus1 && !rsps->sps_loop_filter_across_subpic_enabled_flag[subpic_idx]; |
203 | 46285 | uint8_t lf_edge[] = { 0, 0, 0, 0 }; | |
204 | |||
205 |
8/8✓ Branch 0 taken 45148 times.
✓ Branch 1 taken 1137 times.
✓ Branch 2 taken 44596 times.
✓ Branch 3 taken 552 times.
✓ Branch 4 taken 3154 times.
✓ Branch 5 taken 41442 times.
✓ Branch 6 taken 184 times.
✓ Branch 7 taken 2970 times.
|
46285 | *restore = no_subpic_filter || no_tile_filter || !lfase || rsps->sps_virtual_boundaries_enabled_flag; |
206 | |||
207 |
2/2✓ Branch 0 taken 2970 times.
✓ Branch 1 taken 43315 times.
|
46285 | if (!*restore) |
208 | 2970 | return; | |
209 | |||
210 |
2/2✓ Branch 0 taken 39315 times.
✓ Branch 1 taken 4000 times.
|
43315 | if (!edges[LEFT]) { |
211 |
4/4✓ Branch 0 taken 1458 times.
✓ Branch 1 taken 37857 times.
✓ Branch 2 taken 612 times.
✓ Branch 3 taken 846 times.
|
39315 | lf_edge[LEFT] = no_tile_filter && pps->ctb_to_col_bd[rx] == rx; |
212 |
4/4✓ Branch 0 taken 1017 times.
✓ Branch 1 taken 38298 times.
✓ Branch 2 taken 309 times.
✓ Branch 3 taken 708 times.
|
39315 | lf_edge[LEFT] |= no_subpic_filter && rsps->sps_subpic_ctu_top_left_x[subpic_idx] == rx; |
213 | 39315 | lf_edge[LEFT] |= is_virtual_boundary(fc, rx << sps->ctb_log2_size_y, 1); | |
214 |
4/4✓ Branch 1 taken 39016 times.
✓ Branch 2 taken 299 times.
✓ Branch 3 taken 322 times.
✓ Branch 4 taken 38694 times.
|
39315 | vert_edge[0] = !sao_can_cross_slices(fc, rx, ry, -1, 0) || lf_edge[LEFT]; |
215 | } | ||
216 |
2/2✓ Branch 0 taken 39315 times.
✓ Branch 1 taken 4000 times.
|
43315 | if (!edges[RIGHT]) { |
217 |
4/4✓ Branch 0 taken 1458 times.
✓ Branch 1 taken 37857 times.
✓ Branch 2 taken 612 times.
✓ Branch 3 taken 846 times.
|
39315 | lf_edge[RIGHT] = no_tile_filter && pps->ctb_to_col_bd[rx] != pps->ctb_to_col_bd[rx + 1]; |
218 |
4/4✓ Branch 0 taken 996 times.
✓ Branch 1 taken 38319 times.
✓ Branch 2 taken 288 times.
✓ Branch 3 taken 708 times.
|
39315 | lf_edge[RIGHT] |= no_subpic_filter && rsps->sps_subpic_ctu_top_left_x[subpic_idx] + rsps->sps_subpic_width_minus1[subpic_idx] == rx; |
219 | 39315 | lf_edge[RIGHT] |= is_virtual_boundary(fc, (rx + 1) << sps->ctb_log2_size_y, 1); | |
220 |
4/4✓ Branch 1 taken 39016 times.
✓ Branch 2 taken 299 times.
✓ Branch 3 taken 318 times.
✓ Branch 4 taken 38698 times.
|
39315 | vert_edge[1] = !sao_can_cross_slices(fc, rx, ry, 1, 0) || lf_edge[RIGHT]; |
221 | } | ||
222 |
2/2✓ Branch 0 taken 36362 times.
✓ Branch 1 taken 6953 times.
|
43315 | if (!edges[TOP]) { |
223 |
4/4✓ Branch 0 taken 1356 times.
✓ Branch 1 taken 35006 times.
✓ Branch 2 taken 564 times.
✓ Branch 3 taken 792 times.
|
36362 | lf_edge[TOP] = no_tile_filter && pps->ctb_to_row_bd[ry] == ry; |
224 |
4/4✓ Branch 0 taken 852 times.
✓ Branch 1 taken 35510 times.
✓ Branch 2 taken 222 times.
✓ Branch 3 taken 630 times.
|
36362 | lf_edge[TOP] |= no_subpic_filter && rsps->sps_subpic_ctu_top_left_y[subpic_idx] == ry; |
225 | 36362 | lf_edge[TOP] |= is_virtual_boundary(fc, ry << sps->ctb_log2_size_y, 0); | |
226 |
4/4✓ Branch 1 taken 36009 times.
✓ Branch 2 taken 353 times.
✓ Branch 3 taken 282 times.
✓ Branch 4 taken 35727 times.
|
36362 | horiz_edge[0] = !sao_can_cross_slices(fc, rx, ry, 0, -1) || lf_edge[TOP]; |
227 | } | ||
228 |
2/2✓ Branch 0 taken 36362 times.
✓ Branch 1 taken 6953 times.
|
43315 | if (!edges[BOTTOM]) { |
229 |
4/4✓ Branch 0 taken 1356 times.
✓ Branch 1 taken 35006 times.
✓ Branch 2 taken 564 times.
✓ Branch 3 taken 792 times.
|
36362 | lf_edge[BOTTOM] = no_tile_filter && pps->ctb_to_row_bd[ry] != pps->ctb_to_row_bd[ry + 1]; |
230 |
4/4✓ Branch 0 taken 915 times.
✓ Branch 1 taken 35447 times.
✓ Branch 2 taken 285 times.
✓ Branch 3 taken 630 times.
|
36362 | lf_edge[BOTTOM] |= no_subpic_filter && rsps->sps_subpic_ctu_top_left_y[subpic_idx] + rsps->sps_subpic_height_minus1[subpic_idx] == ry; |
231 | 36362 | lf_edge[BOTTOM] |= is_virtual_boundary(fc, (ry + 1) << sps->ctb_log2_size_y, 0); | |
232 |
4/4✓ Branch 1 taken 36009 times.
✓ Branch 2 taken 353 times.
✓ Branch 3 taken 294 times.
✓ Branch 4 taken 35715 times.
|
36362 | horiz_edge[1] = !sao_can_cross_slices(fc, rx, ry, 0, 1) || lf_edge[BOTTOM]; |
233 | } | ||
234 | |||
235 |
4/4✓ Branch 0 taken 39315 times.
✓ Branch 1 taken 4000 times.
✓ Branch 2 taken 33279 times.
✓ Branch 3 taken 6036 times.
|
43315 | if (!edges[LEFT] && !edges[TOP]) |
236 |
6/6✓ Branch 1 taken 32922 times.
✓ Branch 2 taken 357 times.
✓ Branch 3 taken 32670 times.
✓ Branch 4 taken 252 times.
✓ Branch 5 taken 144 times.
✓ Branch 6 taken 32526 times.
|
33279 | diag_edge[0] = !sao_can_cross_slices(fc, rx, ry, -1, -1) || lf_edge[LEFT] || lf_edge[TOP]; |
237 | |||
238 |
4/4✓ Branch 0 taken 36362 times.
✓ Branch 1 taken 6953 times.
✓ Branch 2 taken 33279 times.
✓ Branch 3 taken 3083 times.
|
43315 | if (!edges[TOP] && !edges[RIGHT]) |
239 |
6/6✓ Branch 1 taken 32922 times.
✓ Branch 2 taken 357 times.
✓ Branch 3 taken 32670 times.
✓ Branch 4 taken 252 times.
✓ Branch 5 taken 144 times.
✓ Branch 6 taken 32526 times.
|
33279 | diag_edge[1] = !sao_can_cross_slices(fc, rx, ry, 1, -1) || lf_edge[RIGHT] || lf_edge[TOP]; |
240 | |||
241 |
4/4✓ Branch 0 taken 39315 times.
✓ Branch 1 taken 4000 times.
✓ Branch 2 taken 33279 times.
✓ Branch 3 taken 6036 times.
|
43315 | if (!edges[RIGHT] && !edges[BOTTOM]) |
242 |
6/6✓ Branch 1 taken 32922 times.
✓ Branch 2 taken 357 times.
✓ Branch 3 taken 32670 times.
✓ Branch 4 taken 252 times.
✓ Branch 5 taken 152 times.
✓ Branch 6 taken 32518 times.
|
33279 | diag_edge[2] = !sao_can_cross_slices(fc, rx, ry, 1, 1) || lf_edge[RIGHT] || lf_edge[BOTTOM]; |
243 | |||
244 |
4/4✓ Branch 0 taken 39315 times.
✓ Branch 1 taken 4000 times.
✓ Branch 2 taken 33279 times.
✓ Branch 3 taken 6036 times.
|
43315 | if (!edges[LEFT] && !edges[BOTTOM]) |
245 |
6/6✓ Branch 1 taken 32922 times.
✓ Branch 2 taken 357 times.
✓ Branch 3 taken 32666 times.
✓ Branch 4 taken 256 times.
✓ Branch 5 taken 152 times.
✓ Branch 6 taken 32514 times.
|
33279 | diag_edge[3] = !sao_can_cross_slices(fc, rx, ry, -1, 1) || lf_edge[LEFT] || lf_edge[BOTTOM]; |
246 | } | ||
247 | |||
248 | 15568 | 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 | 15568 | const int left = 1 - edges[LEFT]; | |
252 | 15568 | const int right = 1 - edges[RIGHT]; | |
253 | 15568 | int pos = 0; | |
254 | |||
255 | 15568 | src -= left << ps; | |
256 | 15568 | dst -= left << ps; | |
257 | |||
258 |
2/2✓ Branch 0 taken 14269 times.
✓ Branch 1 taken 1299 times.
|
15568 | if (left) { |
259 | 14269 | copy_pixel(dst, src, ps); | |
260 | 14269 | pos += (1 << ps); | |
261 | } | ||
262 | 15568 | memcpy(dst + pos, src + pos, width << ps); | |
263 |
2/2✓ Branch 0 taken 14329 times.
✓ Branch 1 taken 1239 times.
|
15568 | if (right) { |
264 | 14329 | pos += width << ps; | |
265 | 14329 | copy_pixel(dst + pos, src + pos, ps); | |
266 | } | ||
267 | 15568 | } | |
268 | |||
269 | 9401 | 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 | 9401 | const uint8_t *sao_h = fc->tab.sao_pixel_buffer_h[c_idx]; | |
274 | 9401 | const uint8_t *sao_v = fc->tab.sao_pixel_buffer_v[c_idx]; | |
275 | 9401 | const int x = x0 >> fc->ps.sps->hshift[c_idx]; | |
276 | 9401 | const int y = y0 >> fc->ps.sps->vshift[c_idx]; | |
277 | 9401 | const int w = fc->ps.pps->width >> fc->ps.sps->hshift[c_idx]; | |
278 | 9401 | const int h = fc->ps.pps->height >> fc->ps.sps->vshift[c_idx]; | |
279 | 9401 | const int ps = fc->ps.sps->pixel_shift; | |
280 | |||
281 |
2/2✓ Branch 0 taken 7796 times.
✓ Branch 1 taken 1605 times.
|
9401 | if (!edges[TOP]) |
282 | 7796 | sao_copy_hor(dst - dst_stride, dst_stride, sao_h + (((2 * ry - 1) * w + x) << ps), src_stride, width, edges, ps); | |
283 | |||
284 |
2/2✓ Branch 0 taken 7772 times.
✓ Branch 1 taken 1629 times.
|
9401 | if (!edges[BOTTOM]) |
285 | 7772 | 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 8531 times.
✓ Branch 1 taken 870 times.
|
9401 | if (!edges[LEFT]) |
288 | 8531 | 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 8540 times.
✓ Branch 1 taken 861 times.
|
9401 | if (!edges[RIGHT]) |
291 | 8540 | copy_vert(dst + (width << ps), sao_v + (((2 * rx + 2) * h + y) << ps), ps, height, dst_stride, 1 << ps); | |
292 | |||
293 | 9401 | copy_ctb(dst, src, width << ps, height, dst_stride, src_stride); | |
294 | 9401 | } | |
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 | 46285 | void ff_vvc_sao_filter(VVCLocalContext *lc, int x0, int y0) | |
315 | { | ||
316 | 46285 | VVCFrameContext *fc = lc->fc; | |
317 | 46285 | const VVCSPS *sps = fc->ps.sps; | |
318 | 46285 | const int rx = x0 >> sps->ctb_log2_size_y; | |
319 | 46285 | const int ry = y0 >> sps->ctb_log2_size_y; | |
320 | 46285 | const int edges[4] = { !rx, !ry, rx == fc->ps.pps->ctb_width - 1, ry == fc->ps.pps->ctb_height - 1 }; | |
321 | 46285 | const SAOParams *sao = &CTB(fc->tab.sao, rx, ry); | |
322 | // flags indicating unfilterable edges | ||
323 | 46285 | uint8_t vert_edge[] = { 0, 0 }; | |
324 | 46285 | uint8_t horiz_edge[] = { 0, 0 }; | |
325 | 46285 | uint8_t diag_edge[] = { 0, 0, 0, 0 }; | |
326 | 46285 | int restore, vb_x = 0, vb_y = 0;; | |
327 | |||
328 |
2/2✓ Branch 0 taken 1029 times.
✓ Branch 1 taken 45256 times.
|
46285 | 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 | 46285 | sao_get_edges(vert_edge, horiz_edge, diag_edge, &restore, lc, edges, rx, ry); | |
334 | |||
335 |
4/4✓ Branch 0 taken 183028 times.
✓ Branch 1 taken 1056 times.
✓ Branch 2 taken 137799 times.
✓ Branch 3 taken 46285 times.
|
184084 | 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 | 137799 | const ptrdiff_t src_stride = fc->frame->linesize[c_idx]; | |
338 | 137799 | uint8_t *src = POS(c_idx, x0, y0); | |
339 | 137799 | const int hs = sps->hshift[c_idx]; | |
340 | 137799 | const int vs = sps->vshift[c_idx]; | |
341 | 137799 | const int ps = sps->pixel_shift; | |
342 | 137799 | const int width = FFMIN(sps->ctb_size_y, fc->ps.pps->width - x0) >> hs; | |
343 | 137799 | const int height = FFMIN(sps->ctb_size_y, fc->ps.pps->height - y0) >> vs; | |
344 | 137799 | const int tab = sao_tab[(FFALIGN(width, 8) >> 3) - 1]; | |
345 | 137799 | const int sao_eo_class = sao->eo_class[c_idx]; | |
346 | |||
347 |
3/3✓ Branch 0 taken 5150 times.
✓ Branch 1 taken 9401 times.
✓ Branch 2 taken 123248 times.
|
137799 | switch (sao->type_idx[c_idx]) { |
348 | 5150 | case SAO_BAND: | |
349 | 5150 | fc->vvcdsp.sao.band_filter[tab](src, src, src_stride, src_stride, | |
350 | 5150 | sao->offset_val[c_idx], sao->band_position[c_idx], width, height); | |
351 | 5150 | break; | |
352 | 9401 | case SAO_EDGE: | |
353 | { | ||
354 | 9401 | const ptrdiff_t dst_stride = 2 * MAX_PB_SIZE + AV_INPUT_BUFFER_PADDING_SIZE; | |
355 | 9401 | uint8_t *dst = lc->sao_buffer + dst_stride + AV_INPUT_BUFFER_PADDING_SIZE; | |
356 | |||
357 | 9401 | sao_extends_edges(dst, dst_stride, src, src_stride, width, height, fc, x0, y0, rx, ry, edges, c_idx); | |
358 | |||
359 | 9401 | fc->vvcdsp.sao.edge_filter[tab](src, dst, src_stride, sao->offset_val[c_idx], | |
360 | 9401 | sao->eo_class[c_idx], width, height); | |
361 | 9401 | 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 9401 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
9401 | 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 9401 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
9401 | 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 | 9401 | break; | |
370 | } | ||
371 | } | ||
372 | } | ||
373 | 46285 | } | |
374 | |||
375 | #define TAB_BS(t, x, y) (t)[((y) >> MIN_TU_LOG2) * (fc->ps.pps->min_tu_width) + ((x) >> MIN_TU_LOG2)] | ||
376 | #define TAB_MAX_LEN(t, x, y) (t)[((y) >> MIN_TU_LOG2) * (fc->ps.pps->min_tu_width) + ((x) >> MIN_TU_LOG2)] | ||
377 | |||
378 | //8 samples a time | ||
379 | #define DEBLOCK_STEP 8 | ||
380 | #define LUMA_GRID 4 | ||
381 | #define CHROMA_GRID 8 | ||
382 | |||
383 | 9612681 | static int boundary_strength(const VVCLocalContext *lc, const MvField *curr, const MvField *neigh, | |
384 | const RefPicList *neigh_rpl) | ||
385 | { | ||
386 | 9612681 | RefPicList *rpl = lc->sc->rpl; | |
387 | |||
388 |
2/2✓ Branch 0 taken 19857 times.
✓ Branch 1 taken 9592824 times.
|
9612681 | if (curr->pred_flag == PF_IBC) |
389 |
4/4✓ Branch 0 taken 11262 times.
✓ Branch 1 taken 8595 times.
✓ Branch 2 taken 1775 times.
✓ Branch 3 taken 9487 times.
|
19857 | return FFABS(neigh->mv[0].x - curr->mv[0].x) >= 8 || FFABS(neigh->mv[0].y - curr->mv[0].y) >= 8; |
390 | |||
391 |
4/4✓ Branch 0 taken 4589817 times.
✓ Branch 1 taken 5003007 times.
✓ Branch 2 taken 4275961 times.
✓ Branch 3 taken 313856 times.
|
9592824 | if (curr->pred_flag == PF_BI && neigh->pred_flag == PF_BI) { |
392 | // same L0 and L1 | ||
393 |
2/2✓ Branch 0 taken 4198947 times.
✓ Branch 1 taken 77014 times.
|
4275961 | if (rpl[L0].refs[curr->ref_idx[L0]].poc == neigh_rpl[L0].refs[neigh->ref_idx[L0]].poc && |
394 |
2/2✓ Branch 0 taken 460391 times.
✓ Branch 1 taken 3738556 times.
|
4198947 | rpl[L0].refs[curr->ref_idx[L0]].poc == rpl[L1].refs[curr->ref_idx[L1]].poc && |
395 |
2/2✓ Branch 0 taken 456910 times.
✓ Branch 1 taken 3481 times.
|
460391 | neigh_rpl[L0].refs[neigh->ref_idx[L0]].poc == neigh_rpl[L1].refs[neigh->ref_idx[L1]].poc) { |
396 |
4/4✓ Branch 0 taken 410440 times.
✓ Branch 1 taken 46470 times.
✓ Branch 2 taken 385271 times.
✓ Branch 3 taken 25169 times.
|
456910 | if ((FFABS(neigh->mv[0].x - curr->mv[0].x) >= 8 || FFABS(neigh->mv[0].y - curr->mv[0].y) >= 8 || |
397 |
4/4✓ Branch 0 taken 381496 times.
✓ Branch 1 taken 3775 times.
✓ Branch 2 taken 3203 times.
✓ Branch 3 taken 378293 times.
|
385271 | FFABS(neigh->mv[1].x - curr->mv[1].x) >= 8 || FFABS(neigh->mv[1].y - curr->mv[1].y) >= 8) && |
398 |
4/4✓ Branch 0 taken 19050 times.
✓ Branch 1 taken 59567 times.
✓ Branch 2 taken 4673 times.
✓ Branch 3 taken 14377 times.
|
78617 | (FFABS(neigh->mv[1].x - curr->mv[0].x) >= 8 || FFABS(neigh->mv[1].y - curr->mv[0].y) >= 8 || |
399 |
4/4✓ Branch 0 taken 2405 times.
✓ Branch 1 taken 2268 times.
✓ Branch 2 taken 1898 times.
✓ Branch 3 taken 507 times.
|
4673 | FFABS(neigh->mv[0].x - curr->mv[1].x) >= 8 || FFABS(neigh->mv[0].y - curr->mv[1].y) >= 8)) |
400 | 78110 | return 1; | |
401 | else | ||
402 | 378800 | return 0; | |
403 |
2/2✓ Branch 0 taken 3742037 times.
✓ Branch 1 taken 77014 times.
|
3819051 | } else if (neigh_rpl[L0].refs[neigh->ref_idx[L0]].poc == rpl[L0].refs[curr->ref_idx[L0]].poc && |
404 |
2/2✓ Branch 0 taken 3723042 times.
✓ Branch 1 taken 18995 times.
|
3742037 | neigh_rpl[L1].refs[neigh->ref_idx[L1]].poc == rpl[L1].refs[curr->ref_idx[L1]].poc) { |
405 |
4/4✓ Branch 0 taken 3199293 times.
✓ Branch 1 taken 523749 times.
✓ Branch 2 taken 3046191 times.
✓ Branch 3 taken 153102 times.
|
3723042 | if (FFABS(neigh->mv[0].x - curr->mv[0].x) >= 8 || FFABS(neigh->mv[0].y - curr->mv[0].y) >= 8 || |
406 |
4/4✓ Branch 0 taken 3013589 times.
✓ Branch 1 taken 32602 times.
✓ Branch 2 taken 20993 times.
✓ Branch 3 taken 2992596 times.
|
3046191 | FFABS(neigh->mv[1].x - curr->mv[1].x) >= 8 || FFABS(neigh->mv[1].y - curr->mv[1].y) >= 8) |
407 | 730446 | return 1; | |
408 | else | ||
409 | 2992596 | return 0; | |
410 |
2/2✓ Branch 0 taken 27250 times.
✓ Branch 1 taken 68759 times.
|
96009 | } else if (neigh_rpl[L1].refs[neigh->ref_idx[L1]].poc == rpl[L0].refs[curr->ref_idx[L0]].poc && |
411 |
2/2✓ Branch 0 taken 8629 times.
✓ Branch 1 taken 18621 times.
|
27250 | neigh_rpl[L0].refs[neigh->ref_idx[L0]].poc == rpl[L1].refs[curr->ref_idx[L1]].poc) { |
412 |
4/4✓ Branch 0 taken 2934 times.
✓ Branch 1 taken 5695 times.
✓ Branch 2 taken 1135 times.
✓ Branch 3 taken 1799 times.
|
8629 | if (FFABS(neigh->mv[1].x - curr->mv[0].x) >= 8 || FFABS(neigh->mv[1].y - curr->mv[0].y) >= 8 || |
413 |
4/4✓ Branch 0 taken 824 times.
✓ Branch 1 taken 311 times.
✓ Branch 2 taken 180 times.
✓ Branch 3 taken 644 times.
|
1135 | FFABS(neigh->mv[0].x - curr->mv[1].x) >= 8 || FFABS(neigh->mv[0].y - curr->mv[1].y) >= 8) |
414 | 7985 | return 1; | |
415 | else | ||
416 | 644 | return 0; | |
417 | } else { | ||
418 | 87380 | return 1; | |
419 | } | ||
420 |
4/4✓ Branch 0 taken 5003007 times.
✓ Branch 1 taken 313856 times.
✓ Branch 2 taken 4692078 times.
✓ Branch 3 taken 310929 times.
|
5316863 | } else if ((curr->pred_flag != PF_BI) && (neigh->pred_flag != PF_BI)){ // 1 MV |
421 | Mv A, B; | ||
422 | int ref_A, ref_B; | ||
423 | |||
424 |
2/2✓ Branch 0 taken 3827667 times.
✓ Branch 1 taken 864411 times.
|
4692078 | if (curr->pred_flag & 1) { |
425 | 3827667 | A = curr->mv[0]; | |
426 | 3827667 | ref_A = rpl[L0].refs[curr->ref_idx[L0]].poc; | |
427 | } else { | ||
428 | 864411 | A = curr->mv[1]; | |
429 | 864411 | ref_A = rpl[L1].refs[curr->ref_idx[L1]].poc; | |
430 | } | ||
431 | |||
432 |
2/2✓ Branch 0 taken 3825385 times.
✓ Branch 1 taken 866693 times.
|
4692078 | if (neigh->pred_flag & 1) { |
433 | 3825385 | B = neigh->mv[0]; | |
434 | 3825385 | ref_B = neigh_rpl[L0].refs[neigh->ref_idx[L0]].poc; | |
435 | } else { | ||
436 | 866693 | B = neigh->mv[1]; | |
437 | 866693 | ref_B = neigh_rpl[L1].refs[neigh->ref_idx[L1]].poc; | |
438 | } | ||
439 | |||
440 |
2/2✓ Branch 0 taken 4568497 times.
✓ Branch 1 taken 123581 times.
|
4692078 | if (ref_A == ref_B) { |
441 |
4/4✓ Branch 0 taken 4212248 times.
✓ Branch 1 taken 356249 times.
✓ Branch 2 taken 154553 times.
✓ Branch 3 taken 4057695 times.
|
4568497 | if (FFABS(A.x - B.x) >= 8 || FFABS(A.y - B.y) >= 8) |
442 | 510802 | return 1; | |
443 | else | ||
444 | 4057695 | return 0; | |
445 | } else | ||
446 | 123581 | return 1; | |
447 | } | ||
448 | |||
449 | 624785 | return 1; | |
450 | } | ||
451 | |||
452 | //part of 8.8.3.3 Derivation process of transform block boundary | ||
453 | 10597770 | static void derive_max_filter_length_luma(const VVCFrameContext *fc, const int qx, const int qy, | |
454 | const int size_q, const int has_subblock, const int vertical, uint8_t *max_len_p, uint8_t *max_len_q) | ||
455 | { | ||
456 |
2/2✓ Branch 0 taken 5086237 times.
✓ Branch 1 taken 5511533 times.
|
10597770 | const int px = vertical ? qx - 1 : qx; |
457 |
2/2✓ Branch 0 taken 5511533 times.
✓ Branch 1 taken 5086237 times.
|
10597770 | const int py = !vertical ? qy - 1 : qy; |
458 |
2/2✓ Branch 0 taken 5086237 times.
✓ Branch 1 taken 5511533 times.
|
10597770 | const uint8_t *tb_size = vertical ? fc->tab.tb_width[LUMA] : fc->tab.tb_height[LUMA]; |
459 | 10597770 | const int size_p = tb_size[(py >> MIN_TU_LOG2) * fc->ps.pps->min_tu_width + (px >> MIN_TU_LOG2)]; | |
460 | 10597770 | const int min_cb_log2 = fc->ps.sps->min_cb_log2_size_y; | |
461 | 10597770 | const int off_p = (py >> min_cb_log2) * fc->ps.pps->min_cb_width + (px >> min_cb_log2); | |
462 | |||
463 |
4/4✓ Branch 0 taken 8828393 times.
✓ Branch 1 taken 1769377 times.
✓ Branch 2 taken 780318 times.
✓ Branch 3 taken 8048075 times.
|
10597770 | if (size_p <= 4 || size_q <= 4) { |
464 | 2549695 | *max_len_p = *max_len_q = 1; | |
465 | } else { | ||
466 | 8048075 | *max_len_p = *max_len_q = 3; | |
467 |
2/2✓ Branch 0 taken 5087209 times.
✓ Branch 1 taken 2960866 times.
|
8048075 | if (size_p >= 32) |
468 | 5087209 | *max_len_p = 7; | |
469 |
2/2✓ Branch 0 taken 4943388 times.
✓ Branch 1 taken 3104687 times.
|
8048075 | if (size_q >= 32) |
470 | 4943388 | *max_len_q = 7; | |
471 | } | ||
472 |
2/2✓ Branch 0 taken 1093634 times.
✓ Branch 1 taken 9504136 times.
|
10597770 | if (has_subblock) |
473 | 1093634 | *max_len_q = FFMIN(5, *max_len_q); | |
474 |
4/4✓ Branch 0 taken 9635336 times.
✓ Branch 1 taken 962434 times.
✓ Branch 2 taken 256067 times.
✓ Branch 3 taken 9379269 times.
|
10597770 | if (fc->tab.msf[off_p] || fc->tab.iaf[off_p]) |
475 | 1218501 | *max_len_p = FFMIN(5, *max_len_p); | |
476 | 10597770 | } | |
477 | |||
478 | 128608 | 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 | 128608 | const VVCFrameContext *fc = lc->fc; | |
482 | 128608 | const MvField *tab_mvf = fc->tab.mvf; | |
483 | 128608 | const RefPicList *rpl = lc->sc->rpl; | |
484 | 128608 | int stridea = fc->ps.pps->min_pu_width; | |
485 | 128608 | int strideb = 1; | |
486 | 128608 | const int log2_min_pu_size = MIN_PU_LOG2; | |
487 | |||
488 |
2/2✓ Branch 0 taken 64952 times.
✓ Branch 1 taken 63656 times.
|
128608 | if (!vertical) { |
489 | 64952 | FFSWAP(int, x0, y0); | |
490 | 64952 | FFSWAP(int, width, height); | |
491 | 64952 | FFSWAP(int, stridea, strideb); | |
492 | } | ||
493 | |||
494 | // bs for TU internal vertical PU boundaries | ||
495 |
2/2✓ Branch 0 taken 484527 times.
✓ Branch 1 taken 128608 times.
|
613135 | for (int i = 8 - ((x0 - cb) % 8); i < width; i += 8) { |
496 | 484527 | const int is_vb = is_virtual_boundary(fc, x0 + i, vertical); | |
497 | 484527 | const int xp_pu = (x0 + i - 1) >> log2_min_pu_size; | |
498 | 484527 | const int xq_pu = (x0 + i) >> log2_min_pu_size; | |
499 | |||
500 |
2/2✓ Branch 0 taken 5457742 times.
✓ Branch 1 taken 484527 times.
|
5942269 | for (int j = 0; j < height; j += 4) { |
501 | 5457742 | const int y_pu = (y0 + j) >> log2_min_pu_size; | |
502 | 5457742 | const MvField *mvf_p = &tab_mvf[y_pu * stridea + xp_pu * strideb]; | |
503 | 5457742 | const MvField *mvf_q = &tab_mvf[y_pu * stridea + xq_pu * strideb]; | |
504 |
1/2✓ Branch 0 taken 5457742 times.
✗ Branch 1 not taken.
|
5457742 | const int bs = is_vb ? 0 : boundary_strength(lc, mvf_q, mvf_p, rpl); |
505 | 5457742 | int x = x0 + i; | |
506 | 5457742 | int y = y0 + j; | |
507 | 5457742 | uint8_t max_len_p = 0, max_len_q = 0; | |
508 | |||
509 |
2/2✓ Branch 0 taken 2717100 times.
✓ Branch 1 taken 2740642 times.
|
5457742 | if (!vertical) |
510 | 2717100 | FFSWAP(int, x, y); | |
511 | |||
512 | 5457742 | TAB_BS(fc->tab.bs[vertical][LUMA], x, y) = bs; | |
513 | |||
514 |
4/4✓ Branch 0 taken 5456214 times.
✓ Branch 1 taken 1528 times.
✓ Branch 2 taken 1772 times.
✓ Branch 3 taken 5454442 times.
|
5457742 | if (i == 4 || i == width - 4) |
515 | 3300 | max_len_p = max_len_q = 1; | |
516 |
4/4✓ Branch 0 taken 4327132 times.
✓ Branch 1 taken 1127310 times.
✓ Branch 2 taken 907304 times.
✓ Branch 3 taken 3419828 times.
|
5454442 | else if (i == 8 || i == width - 8) |
517 | 2034614 | max_len_p = max_len_q = 2; | |
518 | else | ||
519 | 3419828 | max_len_p = max_len_q = 3; | |
520 | |||
521 | 5457742 | TAB_MAX_LEN(fc->tab.max_len_p[vertical], x, y) = max_len_p; | |
522 | 5457742 | TAB_MAX_LEN(fc->tab.max_len_q[vertical], x, y) = max_len_q; | |
523 | } | ||
524 | } | ||
525 | 128608 | } | |
526 | |||
527 | 40499946 | static av_always_inline int deblock_bs(const VVCLocalContext *lc, | |
528 | const int x_p, const int y_p, const int x_q, const int y_q, const CodingUnit *cu, const TransformUnit *tu, | ||
529 | const RefPicList *rpl_p, const int c_idx, const int off_to_cb, const uint8_t has_sub_block) | ||
530 | { | ||
531 | 40499946 | const VVCFrameContext *fc = lc->fc; | |
532 | 40499946 | const MvField *tab_mvf = fc->tab.mvf; | |
533 | 40499946 | const int log2_min_pu_size = MIN_PU_LOG2; | |
534 | 40499946 | const int log2_min_tu_size = MIN_TU_LOG2; | |
535 | 40499946 | const int log2_min_cb_size = fc->ps.sps->min_cb_log2_size_y; | |
536 | 40499946 | const int min_pu_width = fc->ps.pps->min_pu_width; | |
537 | 40499946 | const int min_tu_width = fc->ps.pps->min_tu_width; | |
538 | 40499946 | const int min_cb_width = fc->ps.pps->min_cb_width; | |
539 | 40499946 | const int pu_p = (y_p >> log2_min_pu_size) * min_pu_width + (x_p >> log2_min_pu_size); | |
540 | 40499946 | const int pu_q = (y_q >> log2_min_pu_size) * min_pu_width + (x_q >> log2_min_pu_size); | |
541 | 40499946 | const MvField *mvf_p = &tab_mvf[pu_p]; | |
542 | 40499946 | const MvField *mvf_q = &tab_mvf[pu_q]; | |
543 | 40499946 | const uint8_t chroma = !!c_idx; | |
544 | 40499946 | const int tu_p = (y_p >> log2_min_tu_size) * min_tu_width + (x_p >> log2_min_tu_size); | |
545 | 40499946 | const int cb_p = (y_p >> log2_min_cb_size) * min_cb_width + (x_p >> log2_min_cb_size); | |
546 |
4/4✓ Branch 0 taken 195 times.
✓ Branch 1 taken 40499751 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 184 times.
|
40499946 | const uint8_t pcmf = fc->tab.pcmf[chroma][cb_p] && cu->bdpcm_flag[chroma]; |
547 |
4/4✓ Branch 0 taken 30368050 times.
✓ Branch 1 taken 10131896 times.
✓ Branch 2 taken 827648 times.
✓ Branch 3 taken 29540402 times.
|
40499946 | const uint8_t intra = fc->tab.cpm[chroma][cb_p] == MODE_INTRA || cu->pred_mode == MODE_INTRA; |
548 | 40499946 | const uint8_t same_mode = fc->tab.cpm[chroma][cb_p] == cu->pred_mode; | |
549 | |||
550 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 40499935 times.
|
40499946 | if (pcmf) |
551 | 11 | return 0; | |
552 | |||
553 |
6/6✓ Branch 0 taken 29540402 times.
✓ Branch 1 taken 10959533 times.
✓ Branch 2 taken 29176818 times.
✓ Branch 3 taken 363584 times.
✓ Branch 4 taken 288598 times.
✓ Branch 5 taken 28888220 times.
|
40499935 | if (intra || mvf_p->ciip_flag || mvf_q->ciip_flag) |
554 | 11611715 | return 2; | |
555 | |||
556 |
2/2✓ Branch 0 taken 22386876 times.
✓ Branch 1 taken 6501344 times.
|
28888220 | if (chroma) { |
557 | 44141506 | return fc->tab.tu_coded_flag[c_idx][tu_p] || | |
558 |
2/2✓ Branch 0 taken 21542638 times.
✓ Branch 1 taken 211992 times.
|
21754630 | fc->tab.tu_joint_cbcr_residual_flag[tu_p] || |
559 |
4/4✓ Branch 0 taken 21754630 times.
✓ Branch 1 taken 632246 times.
✓ Branch 2 taken 21304814 times.
✓ Branch 3 taken 237824 times.
|
65446320 | tu->coded_flag[c_idx] || |
560 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 21304814 times.
|
21304814 | tu->joint_cbcr_residual_flag; |
561 | } | ||
562 | |||
563 |
4/4✓ Branch 0 taken 5696077 times.
✓ Branch 1 taken 805267 times.
✓ Branch 2 taken 373668 times.
✓ Branch 3 taken 5322409 times.
|
6501344 | if (fc->tab.tu_coded_flag[LUMA][tu_p] || tu->coded_flag[LUMA]) |
564 | 1178935 | return 1; | |
565 | |||
566 |
6/6✓ Branch 0 taken 1349240 times.
✓ Branch 1 taken 3973169 times.
✓ Branch 2 taken 1335392 times.
✓ Branch 3 taken 13848 times.
✓ Branch 4 taken 1135982 times.
✓ Branch 5 taken 199410 times.
|
5322409 | if ((off_to_cb && ((off_to_cb % 8) || !has_sub_block))) |
567 | 1149830 | return 0; // inside a cu, not aligned to 8 or with no subblocks | |
568 | |||
569 |
2/2✓ Branch 0 taken 17640 times.
✓ Branch 1 taken 4154939 times.
|
4172579 | if (!same_mode) |
570 | 17640 | return 1; | |
571 | |||
572 | 4154939 | return boundary_strength(lc, mvf_q, mvf_p, rpl_p); | |
573 | } | ||
574 | |||
575 | 4111364 | static int deblock_is_boundary(const VVCLocalContext *lc, const int boundary, | |
576 | const int pos, const int rs, const int vertical) | ||
577 | { | ||
578 | 4111364 | const VVCFrameContext *fc = lc->fc; | |
579 | 4111364 | const H266RawSPS *rsps = fc->ps.sps->r; | |
580 | 4111364 | const H266RawPPS *rpps = fc->ps.pps->r; | |
581 | int flag; | ||
582 |
4/4✓ Branch 0 taken 3614980 times.
✓ Branch 1 taken 496384 times.
✓ Branch 2 taken 584018 times.
✓ Branch 3 taken 3030962 times.
|
4111364 | if (boundary && (pos % fc->ps.sps->ctb_size_y) == 0) { |
583 |
2/2✓ Branch 0 taken 316076 times.
✓ Branch 1 taken 267942 times.
|
584018 | flag = vertical ? BOUNDARY_LEFT_SLICE : BOUNDARY_UPPER_SLICE; |
584 |
2/2✓ Branch 0 taken 20714 times.
✓ Branch 1 taken 563304 times.
|
584018 | if (lc->boundary_flags & flag && |
585 |
2/2✓ Branch 0 taken 8259 times.
✓ Branch 1 taken 12455 times.
|
20714 | !rpps->pps_loop_filter_across_slices_enabled_flag) |
586 | 8259 | return 0; | |
587 | |||
588 |
2/2✓ Branch 0 taken 312086 times.
✓ Branch 1 taken 263673 times.
|
575759 | flag = vertical ? BOUNDARY_LEFT_TILE : BOUNDARY_UPPER_TILE; |
589 |
2/2✓ Branch 0 taken 29547 times.
✓ Branch 1 taken 546212 times.
|
575759 | if (lc->boundary_flags & flag && |
590 |
2/2✓ Branch 0 taken 9204 times.
✓ Branch 1 taken 20343 times.
|
29547 | !rpps->pps_loop_filter_across_tiles_enabled_flag) |
591 | 9204 | return 0; | |
592 | |||
593 |
2/2✓ Branch 0 taken 306507 times.
✓ Branch 1 taken 260048 times.
|
566555 | flag = vertical ? BOUNDARY_LEFT_SUBPIC : BOUNDARY_UPPER_SUBPIC; |
594 |
2/2✓ Branch 0 taken 363 times.
✓ Branch 1 taken 566192 times.
|
566555 | if (lc->boundary_flags & flag) { |
595 |
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); |
596 | 363 | const SliceContext *q_slice = lc->fc->slices[lc->fc->tab.slice_idx[q_rs]]; | |
597 | |||
598 |
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] || |
599 |
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]) |
600 | 160 | return 0; | |
601 | } | ||
602 | } | ||
603 | 4093741 | return boundary; | |
604 | } | ||
605 | |||
606 | 2619058 | static void vvc_deblock_bs_luma(const VVCLocalContext *lc, | |
607 | const int x0, const int y0, const int width, const int height, | ||
608 | const CodingUnit *cu, const TransformUnit *tu, int rs, const int vertical) | ||
609 | { | ||
610 | 2619058 | const VVCFrameContext *fc = lc->fc; | |
611 | 2619058 | const PredictionUnit *pu = &cu->pu; | |
612 | 2619058 | const int mask = LUMA_GRID - 1; | |
613 |
2/2✓ Branch 0 taken 1309529 times.
✓ Branch 1 taken 1309529 times.
|
2619058 | const int pos = vertical ? x0 : y0; |
614 |
2/2✓ Branch 0 taken 1309529 times.
✓ Branch 1 taken 1309529 times.
|
2619058 | const int cb = vertical ? cu->x0 : cu->y0; |
615 | 2619058 | const int is_intra = cu->pred_mode == MODE_INTRA; | |
616 |
2/2✓ Branch 0 taken 1309529 times.
✓ Branch 1 taken 1309529 times.
|
2619058 | const int cb_size = vertical ? cu->cb_width : cu->cb_height; |
617 |
8/8✓ Branch 0 taken 1142018 times.
✓ Branch 1 taken 1477040 times.
✓ Branch 2 taken 1015658 times.
✓ Branch 3 taken 126360 times.
✓ Branch 4 taken 29242 times.
✓ Branch 5 taken 986416 times.
✓ Branch 6 taken 128608 times.
✓ Branch 7 taken 26994 times.
|
2619058 | const int has_sb = !is_intra && (pu->merge_subblock_flag || pu->inter_affine_flag) && cb_size > 8; |
618 | |||
619 |
6/6✓ Branch 0 taken 2569227 times.
✓ Branch 1 taken 49831 times.
✓ Branch 2 taken 2518715 times.
✓ Branch 3 taken 50512 times.
✓ Branch 5 taken 2508319 times.
✓ Branch 6 taken 110739 times.
|
2619058 | if (deblock_is_boundary(lc, pos > 0 && !(pos & mask), pos, rs, vertical)) { |
620 | 2508319 | const int is_vb = is_virtual_boundary(fc, pos, vertical); | |
621 |
2/2✓ Branch 0 taken 1269543 times.
✓ Branch 1 taken 1238776 times.
|
2508319 | const int size = vertical ? height : width; |
622 |
2/2✓ Branch 0 taken 1269543 times.
✓ Branch 1 taken 1238776 times.
|
2508319 | const int size_q = vertical ? width : height; |
623 | 2508319 | const int off = cb - pos; | |
624 |
2/2✓ Branch 0 taken 1269543 times.
✓ Branch 1 taken 1238776 times.
|
2508319 | const int flag = vertical ? BOUNDARY_LEFT_SLICE : BOUNDARY_UPPER_SLICE; |
625 | 2508319 | const RefPicList *rpl_p = | |
626 |
2/2✓ Branch 0 taken 73777 times.
✓ Branch 1 taken 2434542 times.
|
2508319 | (lc->boundary_flags & flag) ? ff_vvc_get_ref_list(fc, fc->ref, x0 - vertical, y0 - !vertical) : lc->sc->rpl; |
627 | |||
628 |
2/2✓ Branch 0 taken 10597770 times.
✓ Branch 1 taken 2508319 times.
|
13106089 | for (int i = 0; i < size; i += 4) { |
629 | 10597770 | const int x = x0 + i * !vertical; | |
630 | 10597770 | const int y = y0 + i * vertical; | |
631 | uint8_t max_len_p, max_len_q; | ||
632 |
1/2✓ Branch 0 taken 10597770 times.
✗ Branch 1 not taken.
|
10597770 | const int bs = is_vb ? 0 : deblock_bs(lc, x - vertical, y - !vertical, x, y, cu, tu, rpl_p, LUMA, off, has_sb); |
633 | |||
634 | 10597770 | TAB_BS(fc->tab.bs[vertical][LUMA], x, y) = bs; | |
635 | |||
636 | 10597770 | derive_max_filter_length_luma(fc, x, y, size_q, has_sb, vertical, &max_len_p, &max_len_q); | |
637 | 10597770 | TAB_MAX_LEN(fc->tab.max_len_p[vertical], x, y) = max_len_p; | |
638 | 10597770 | TAB_MAX_LEN(fc->tab.max_len_q[vertical], x, y) = max_len_q; | |
639 | } | ||
640 | } | ||
641 | |||
642 |
2/2✓ Branch 0 taken 128608 times.
✓ Branch 1 taken 2490450 times.
|
2619058 | if (has_sb) |
643 | 128608 | vvc_deblock_subblock_bs(lc, cb, x0, y0, width, height, vertical); | |
644 | 2619058 | } | |
645 | |||
646 | 1492306 | static void vvc_deblock_bs_chroma(const VVCLocalContext *lc, | |
647 | const int x0, const int y0, const int width, const int height, | ||
648 | const CodingUnit *cu, const TransformUnit *tu, const int rs, const int vertical) | ||
649 | { | ||
650 | 1492306 | const VVCFrameContext *fc = lc->fc; | |
651 |
2/2✓ Branch 0 taken 746153 times.
✓ Branch 1 taken 746153 times.
|
1492306 | const int shift = (vertical ? fc->ps.sps->hshift : fc->ps.sps->vshift)[CHROMA]; |
652 | 1492306 | const int mask = (CHROMA_GRID << shift) - 1; | |
653 |
2/2✓ Branch 0 taken 746153 times.
✓ Branch 1 taken 746153 times.
|
1492306 | const int pos = vertical ? x0 : y0; |
654 | |||
655 |
6/6✓ Branch 0 taken 1452668 times.
✓ Branch 1 taken 39638 times.
✓ Branch 2 taken 1096265 times.
✓ Branch 3 taken 356403 times.
✓ Branch 5 taken 1089038 times.
✓ Branch 6 taken 403268 times.
|
1492306 | if (deblock_is_boundary(lc, pos > 0 && !(pos & mask), pos, rs, vertical)) { |
656 | 1089038 | const int is_vb = is_virtual_boundary(fc, pos, vertical); | |
657 |
2/2✓ Branch 0 taken 548655 times.
✓ Branch 1 taken 540383 times.
|
1089038 | const int size = vertical ? height : width; |
658 | |||
659 |
2/2✓ Branch 0 taken 2178076 times.
✓ Branch 1 taken 1089038 times.
|
3267114 | for (int c_idx = CB; c_idx <= CR; c_idx++) { |
660 |
2/2✓ Branch 0 taken 29902176 times.
✓ Branch 1 taken 2178076 times.
|
32080252 | for (int i = 0; i < size; i += 2) { |
661 | 29902176 | const int x = x0 + i * !vertical; | |
662 | 29902176 | const int y = y0 + i * vertical; | |
663 |
1/2✓ Branch 0 taken 29902176 times.
✗ Branch 1 not taken.
|
29902176 | const int bs = is_vb ? 0 : deblock_bs(lc, x - vertical, y - !vertical, x, y, cu, tu, NULL, c_idx, 0, 0); |
664 | |||
665 | 29902176 | TAB_BS(fc->tab.bs[vertical][c_idx], x, y) = bs; | |
666 | } | ||
667 | } | ||
668 | } | ||
669 | 1492306 | } | |
670 | |||
671 | typedef void (*deblock_bs_fn)(const VVCLocalContext *lc, const int x0, const int y0, | ||
672 | const int width, const int height, const int rs, const int vertical); | ||
673 | |||
674 | 46701 | void ff_vvc_deblock_bs(VVCLocalContext *lc, const int rx, const int ry, const int rs) | |
675 | { | ||
676 | 46701 | const VVCFrameContext *fc = lc->fc; | |
677 | 46701 | const VVCSPS *sps = fc->ps.sps; | |
678 | 46701 | const int x0 = rx << sps->ctb_log2_size_y; | |
679 | 46701 | const int y0 = ry << sps->ctb_log2_size_y; | |
680 | |||
681 | 46701 | ff_vvc_decode_neighbour(lc, x0, y0, rx, ry, rs); | |
682 |
2/2✓ Branch 0 taken 1231129 times.
✓ Branch 1 taken 46701 times.
|
1277830 | for (const CodingUnit *cu = fc->tab.cus[rs]; cu; cu = cu->next) { |
683 |
2/2✓ Branch 0 taken 1490978 times.
✓ Branch 1 taken 1231129 times.
|
2722107 | for (const TransformUnit *tu = cu->tus.head; tu; tu = tu->next) { |
684 |
2/2✓ Branch 0 taken 2981956 times.
✓ Branch 1 taken 1490978 times.
|
4472934 | for (int vertical = 0; vertical <= 1; vertical++) { |
685 |
2/2✓ Branch 0 taken 2619058 times.
✓ Branch 1 taken 362898 times.
|
2981956 | if (tu->avail[LUMA]) |
686 | 2619058 | vvc_deblock_bs_luma(lc, tu->x0, tu->y0, tu->width, tu->height, cu, tu, rs, vertical); | |
687 |
2/2✓ Branch 0 taken 1492306 times.
✓ Branch 1 taken 1489650 times.
|
2981956 | if (tu->avail[CHROMA]) { |
688 |
3/4✓ Branch 0 taken 10382 times.
✓ Branch 1 taken 1481924 times.
✓ Branch 2 taken 10382 times.
✗ Branch 3 not taken.
|
1492306 | if (cu->isp_split_type != ISP_NO_SPLIT && cu->tree_type == SINGLE_TREE) |
689 | 10382 | vvc_deblock_bs_chroma(lc, cu->x0, cu->y0, cu->cb_width, cu->cb_height, cu, tu, rs, vertical); | |
690 | else | ||
691 | 1481924 | vvc_deblock_bs_chroma(lc, tu->x0, tu->y0, tu->width, tu->height, cu, tu, rs, vertical); | |
692 | } | ||
693 | } | ||
694 | } | ||
695 | } | ||
696 | 46701 | } | |
697 | |||
698 | //part of 8.8.3.3 Derivation process of transform block boundary | ||
699 | 7417055 | static void max_filter_length_luma(const VVCFrameContext *fc, const int qx, const int qy, | |
700 | const int vertical, uint8_t *max_len_p, uint8_t *max_len_q) | ||
701 | { | ||
702 | 7417055 | *max_len_p = TAB_MAX_LEN(fc->tab.max_len_p[vertical], qx, qy); | |
703 | 7417055 | *max_len_q = TAB_MAX_LEN(fc->tab.max_len_q[vertical], qx, qy); | |
704 | 7417055 | } | |
705 | |||
706 | //part of 8.8.3.3 Derivation process of transform block boundary | ||
707 | 4298681 | static void max_filter_length_chroma(const VVCFrameContext *fc, const int qx, const int qy, | |
708 | const int vertical, const int horizontal_ctu_edge, const int bs, uint8_t *max_len_p, uint8_t *max_len_q) | ||
709 | { | ||
710 |
2/2✓ Branch 0 taken 2083401 times.
✓ Branch 1 taken 2215280 times.
|
4298681 | const int px = vertical ? qx - 1 : qx; |
711 |
2/2✓ Branch 0 taken 2215280 times.
✓ Branch 1 taken 2083401 times.
|
4298681 | const int py = !vertical ? qy - 1 : qy; |
712 |
2/2✓ Branch 0 taken 2083401 times.
✓ Branch 1 taken 2215280 times.
|
4298681 | const uint8_t *tb_size = vertical ? fc->tab.tb_width[CHROMA] : fc->tab.tb_height[CHROMA]; |
713 | |||
714 | 4298681 | const int size_p = tb_size[(py >> MIN_TU_LOG2) * fc->ps.pps->min_tu_width + (px >> MIN_TU_LOG2)]; | |
715 | 4298681 | const int size_q = tb_size[(qy >> MIN_TU_LOG2) * fc->ps.pps->min_tu_width + (qx >> MIN_TU_LOG2)]; | |
716 |
4/4✓ Branch 0 taken 3502533 times.
✓ Branch 1 taken 796148 times.
✓ Branch 2 taken 3004734 times.
✓ Branch 3 taken 497799 times.
|
4298681 | if (size_p >= 8 && size_q >= 8) { |
717 | 3004734 | *max_len_p = *max_len_q = 3; | |
718 |
2/2✓ Branch 0 taken 362076 times.
✓ Branch 1 taken 2642658 times.
|
3004734 | if (horizontal_ctu_edge) |
719 | 362076 | *max_len_p = 1; | |
720 | } else { | ||
721 | //part of 8.8.3.6.4 Decision process for chroma block edges | ||
722 | 1293947 | *max_len_p = *max_len_q = (bs == 2); | |
723 | } | ||
724 | 4298681 | } | |
725 | |||
726 | 11715736 | static void max_filter_length(const VVCFrameContext *fc, const int qx, const int qy, | |
727 | const int c_idx, const int vertical, const int horizontal_ctu_edge, const int bs, uint8_t *max_len_p, uint8_t *max_len_q) | ||
728 | { | ||
729 |
2/2✓ Branch 0 taken 7417055 times.
✓ Branch 1 taken 4298681 times.
|
11715736 | if (!c_idx) |
730 | 7417055 | max_filter_length_luma(fc, qx, qy, vertical, max_len_p, max_len_q); | |
731 | else | ||
732 | 4298681 | max_filter_length_chroma(fc, qx, qy, vertical, horizontal_ctu_edge, bs, max_len_p, max_len_q); | |
733 | 11715736 | } | |
734 | |||
735 | #define TC_CALC(qp, bs) \ | ||
736 | tctable[av_clip((qp) + DEFAULT_INTRA_TC_OFFSET * ((bs) - 1) + \ | ||
737 | (tc_offset & -2), \ | ||
738 | 0, MAX_QP + DEFAULT_INTRA_TC_OFFSET)] | ||
739 | |||
740 | // part of 8.8.3.6.2 Decision process for luma block edges | ||
741 | 7417055 | static int get_qp_y(const VVCFrameContext *fc, const uint8_t *src, const int x, const int y, const int vertical) | |
742 | { | ||
743 | 7417055 | const VVCSPS *sps = fc->ps.sps; | |
744 | 7417055 | const int qp = (ff_vvc_get_qPy(fc, x - vertical, y - !vertical) + ff_vvc_get_qPy(fc, x, y) + 1) >> 1; | |
745 | 7417055 | int qp_offset = 0; | |
746 | int level; | ||
747 | |||
748 |
2/2✓ Branch 0 taken 6945176 times.
✓ Branch 1 taken 471879 times.
|
7417055 | if (!sps->r->sps_ladf_enabled_flag) |
749 | 6945176 | return qp; | |
750 | |||
751 | 471879 | level = fc->vvcdsp.lf.ladf_level[vertical](src, fc->frame->linesize[LUMA]); | |
752 | 471879 | qp_offset = sps->r->sps_ladf_lowest_interval_qp_offset; | |
753 |
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++) |
754 | 898827 | qp_offset = sps->r->sps_ladf_qp_offset[i]; | |
755 | |||
756 | 471879 | return qp + qp_offset; | |
757 | } | ||
758 | |||
759 | // part of 8.8.3.6.2 Decision process for luma block edges | ||
760 | 4298681 | static int get_qp_c(const VVCFrameContext *fc, const int x, const int y, const int c_idx, const int vertical) | |
761 | { | ||
762 | 4298681 | const VVCSPS *sps = fc->ps.sps; | |
763 | 4298681 | return (get_qPc(fc, x - vertical, y - !vertical, c_idx) + get_qPc(fc, x, y, c_idx) - 2 * sps->qp_bd_offset + 1) >> 1; | |
764 | } | ||
765 | |||
766 | 11715736 | static int get_qp(const VVCFrameContext *fc, const uint8_t *src, const int x, const int y, const int c_idx, const int vertical) | |
767 | { | ||
768 |
2/2✓ Branch 0 taken 7417055 times.
✓ Branch 1 taken 4298681 times.
|
11715736 | if (!c_idx) |
769 | 7417055 | return get_qp_y(fc, src, x, y, vertical); | |
770 | 4298681 | return get_qp_c(fc, x, y, c_idx, vertical); | |
771 | } | ||
772 | |||
773 | 93402 | static void vvc_deblock(const VVCLocalContext *lc, int x0, int y0, const int rs, const int vertical) | |
774 | { | ||
775 | 93402 | VVCFrameContext *fc = lc->fc; | |
776 | 93402 | const VVCSPS *sps = fc->ps.sps; | |
777 |
2/2✓ Branch 0 taken 92346 times.
✓ Branch 1 taken 1056 times.
|
93402 | const int c_end = sps->r->sps_chroma_format_idc ? VVC_MAX_SAMPLE_ARRAYS : 1; |
778 | 93402 | const int ctb_size = fc->ps.sps->ctb_size_y; | |
779 | 93402 | const DBParams *params = fc->tab.deblock + rs; | |
780 | 93402 | int x_end = FFMIN(x0 + ctb_size, fc->ps.pps->width); | |
781 | 93402 | int y_end = FFMIN(y0 + ctb_size, fc->ps.pps->height); | |
782 | |||
783 | //not use this yet, may needed by plt. | ||
784 | 93402 | const uint8_t no_p[4] = { 0 }; | |
785 | 93402 | const uint8_t no_q[4] = { 0 } ; | |
786 | |||
787 |
2/2✓ Branch 0 taken 46701 times.
✓ Branch 1 taken 46701 times.
|
93402 | if (!vertical) { |
788 | 46701 | FFSWAP(int, x_end, y_end); | |
789 | 46701 | FFSWAP(int, x0, y0); | |
790 | } | ||
791 | |||
792 |
2/2✓ Branch 0 taken 278094 times.
✓ Branch 1 taken 93402 times.
|
371496 | for (int c_idx = 0; c_idx < c_end; c_idx++) { |
793 |
2/2✓ Branch 0 taken 139047 times.
✓ Branch 1 taken 139047 times.
|
278094 | const int hs = (vertical ? sps->hshift : sps->vshift)[c_idx]; |
794 |
2/2✓ Branch 0 taken 139047 times.
✓ Branch 1 taken 139047 times.
|
278094 | const int vs = (vertical ? sps->vshift : sps->hshift)[c_idx]; |
795 |
2/2✓ Branch 0 taken 184692 times.
✓ Branch 1 taken 93402 times.
|
278094 | const int grid = c_idx ? (CHROMA_GRID << hs) : LUMA_GRID; |
796 | 278094 | const int tc_offset = params->tc_offset[c_idx]; | |
797 | 278094 | const int beta_offset = params->beta_offset[c_idx]; | |
798 | 278094 | const int src_stride = fc->frame->linesize[c_idx]; | |
799 | |||
800 |
2/2✓ Branch 0 taken 3217539 times.
✓ Branch 1 taken 278094 times.
|
3495633 | for (int y = y0; y < y_end; y += (DEBLOCK_STEP << vs)) { |
801 |
4/4✓ Branch 0 taken 2845565 times.
✓ Branch 1 taken 371974 times.
✓ Branch 2 taken 62630226 times.
✓ Branch 3 taken 3217539 times.
|
65847765 | for (int x = x0 ? x0 : grid; x < x_end; x += grid) { |
802 |
4/4✓ Branch 0 taken 31265260 times.
✓ Branch 1 taken 31364966 times.
✓ Branch 2 taken 1405304 times.
✓ Branch 3 taken 29859956 times.
|
62630226 | const uint8_t horizontal_ctu_edge = !vertical && !(x % ctb_size); |
803 | 62630226 | int32_t bs[4], beta[4], tc[4] = { 0 }, all_zero_bs = 1; | |
804 | uint8_t max_len_p[4], max_len_q[4]; | ||
805 | |||
806 |
2/2✓ Branch 0 taken 139535012 times.
✓ Branch 1 taken 62630226 times.
|
202165238 | for (int i = 0; i < DEBLOCK_STEP >> (2 - vs); i++) { |
807 | 139535012 | int tx = x; | |
808 | 139535012 | int ty = y + (i << 2); | |
809 | 139535012 | const int end = ty >= y_end; | |
810 | |||
811 |
2/2✓ Branch 0 taken 69634832 times.
✓ Branch 1 taken 69900180 times.
|
139535012 | if (!vertical) |
812 | 69634832 | FFSWAP(int, tx, ty); | |
813 | |||
814 |
2/2✓ Branch 0 taken 139453544 times.
✓ Branch 1 taken 81468 times.
|
139535012 | bs[i] = end ? 0 : TAB_BS(fc->tab.bs[vertical][c_idx], tx, ty); |
815 |
2/2✓ Branch 0 taken 11715736 times.
✓ Branch 1 taken 127819276 times.
|
139535012 | if (bs[i]) { |
816 | 11715736 | const int qp = get_qp(fc, POS(c_idx, tx, ty), tx, ty, c_idx, vertical); | |
817 | 11715736 | beta[i] = betatable[av_clip(qp + beta_offset, 0, MAX_QP)]; | |
818 | 11715736 | tc[i] = TC_CALC(qp, bs[i]) ; | |
819 | 11715736 | max_filter_length(fc, tx, ty, c_idx, vertical, horizontal_ctu_edge, bs[i], &max_len_p[i], &max_len_q[i]); | |
820 | 11715736 | all_zero_bs = 0; | |
821 | } | ||
822 | } | ||
823 | |||
824 |
2/2✓ Branch 0 taken 5074796 times.
✓ Branch 1 taken 57555430 times.
|
62630226 | if (!all_zero_bs) { |
825 |
2/2✓ Branch 0 taken 2458066 times.
✓ Branch 1 taken 2616730 times.
|
5074796 | uint8_t *src = vertical ? POS(c_idx, x, y) : POS(c_idx, y, x); |
826 |
2/2✓ Branch 0 taken 3801319 times.
✓ Branch 1 taken 1273477 times.
|
5074796 | if (!c_idx) |
827 | 3801319 | fc->vvcdsp.lf.filter_luma[vertical](src, src_stride, beta, tc, no_p, no_q, max_len_p, max_len_q, horizontal_ctu_edge); | |
828 | else | ||
829 | 1273477 | fc->vvcdsp.lf.filter_chroma[vertical](src, src_stride, beta, tc, no_p, no_q, max_len_p, max_len_q, vs); | |
830 | } | ||
831 | } | ||
832 | } | ||
833 | } | ||
834 | 93402 | } | |
835 | |||
836 | 46701 | void ff_vvc_deblock_vertical(const VVCLocalContext *lc, const int x0, const int y0, const int rs) | |
837 | { | ||
838 | 46701 | vvc_deblock(lc, x0, y0, rs, 1); | |
839 | 46701 | } | |
840 | |||
841 | 46701 | void ff_vvc_deblock_horizontal(const VVCLocalContext *lc, const int x0, const int y0, const int rs) | |
842 | { | ||
843 | 46701 | vvc_deblock(lc, x0, y0, rs, 0); | |
844 | 46701 | } | |
845 | |||
846 | 585347 | static void alf_copy_border(uint8_t *dst, const uint8_t *src, | |
847 | const int pixel_shift, int width, const int height, const ptrdiff_t dst_stride, const ptrdiff_t src_stride) | ||
848 | { | ||
849 | 585347 | width <<= pixel_shift; | |
850 |
2/2✓ Branch 0 taken 29374016 times.
✓ Branch 1 taken 585347 times.
|
29959363 | for (int i = 0; i < height; i++) { |
851 | 29374016 | memcpy(dst, src, width); | |
852 | 29374016 | dst += dst_stride; | |
853 | 29374016 | src += src_stride; | |
854 | } | ||
855 | 585347 | } | |
856 | |||
857 | 10297 | static void alf_extend_vert(uint8_t *_dst, const uint8_t *_src, | |
858 | const int pixel_shift, const int width, const int height, ptrdiff_t stride) | ||
859 | { | ||
860 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10297 times.
|
10297 | if (pixel_shift == 0) { |
861 | ✗ | for (int i = 0; i < height; i++) { | |
862 | ✗ | memset(_dst, *_src, width); | |
863 | ✗ | _src += stride; | |
864 | ✗ | _dst += stride; | |
865 | } | ||
866 | } else { | ||
867 | 10297 | const uint16_t *src = (const uint16_t *)_src; | |
868 | 10297 | uint16_t *dst = (uint16_t *)_dst; | |
869 | 10297 | stride >>= pixel_shift; | |
870 | |||
871 |
2/2✓ Branch 0 taken 997492 times.
✓ Branch 1 taken 10297 times.
|
1007789 | for (int i = 0; i < height; i++) { |
872 |
2/2✓ Branch 0 taken 2581848 times.
✓ Branch 1 taken 997492 times.
|
3579340 | for (int j = 0; j < width; j++) |
873 | 2581848 | dst[j] = *src; | |
874 | 997492 | src += stride; | |
875 | 997492 | dst += stride; | |
876 | } | ||
877 | } | ||
878 | 10297 | } | |
879 | |||
880 | 45831 | static void alf_extend_horz(uint8_t *dst, const uint8_t *src, | |
881 | const int pixel_shift, int width, const int height, const ptrdiff_t stride) | ||
882 | { | ||
883 | 45831 | width <<= pixel_shift; | |
884 |
2/2✓ Branch 0 taken 112794 times.
✓ Branch 1 taken 45831 times.
|
158625 | for (int i = 0; i < height; i++) { |
885 | 112794 | memcpy(dst, src, width); | |
886 | 112794 | dst += stride; | |
887 | } | ||
888 | 45831 | } | |
889 | |||
890 | 108945 | static void alf_copy_ctb_to_hv(VVCFrameContext *fc, const uint8_t *src, const ptrdiff_t src_stride, | |
891 | const int x, const int y, const int width, const int height, const int rx, const int ry, const int c_idx) | ||
892 | { | ||
893 | 108945 | const int ps = fc->ps.sps->pixel_shift; | |
894 | 108945 | const int w = fc->ps.pps->width >> fc->ps.sps->hshift[c_idx]; | |
895 | 108945 | const int h = fc->ps.pps->height >> fc->ps.sps->vshift[c_idx]; | |
896 |
2/2✓ Branch 0 taken 36667 times.
✓ Branch 1 taken 72278 times.
|
108945 | const int border_pixels = (c_idx == 0) ? ALF_BORDER_LUMA : ALF_BORDER_CHROMA; |
897 | 108945 | const int offset_h[] = { 0, height - border_pixels }; | |
898 | 108945 | const int offset_v[] = { 0, width - border_pixels }; | |
899 | |||
900 | /* copy horizontal edges */ | ||
901 |
2/2✓ Branch 0 taken 217890 times.
✓ Branch 1 taken 108945 times.
|
326835 | for (int i = 0; i < FF_ARRAY_ELEMS(offset_h); i++) { |
902 | 217890 | alf_copy_border(fc->tab.alf_pixel_buffer_h[c_idx][i] + ((border_pixels * ry * w + x)<< ps), | |
903 | 217890 | src + offset_h[i] * src_stride, ps, width, border_pixels, w << ps, src_stride); | |
904 | } | ||
905 | /* copy vertical edges */ | ||
906 |
2/2✓ Branch 0 taken 217890 times.
✓ Branch 1 taken 108945 times.
|
326835 | for (int i = 0; i < FF_ARRAY_ELEMS(offset_v); i++) { |
907 | 217890 | alf_copy_border(fc->tab.alf_pixel_buffer_v[c_idx][i] + ((h * rx + y) * (border_pixels << ps)), | |
908 | 217890 | src + (offset_v[i] << ps), ps, border_pixels, height, border_pixels << ps, src_stride); | |
909 | } | ||
910 | 108945 | } | |
911 | |||
912 | 88746 | static void alf_fill_border_h(uint8_t *dst, const ptrdiff_t dst_stride, const uint8_t *src, const ptrdiff_t src_stride, | |
913 | const uint8_t *border, const int width, const int border_pixels, const int ps, const int edge) | ||
914 | { | ||
915 |
2/2✓ Branch 0 taken 17628 times.
✓ Branch 1 taken 71118 times.
|
88746 | if (edge) |
916 | 17628 | alf_extend_horz(dst, border, ps, width, border_pixels, dst_stride); | |
917 | else | ||
918 | 71118 | alf_copy_border(dst, src, ps, width, border_pixels, dst_stride, src_stride); | |
919 | 88746 | } | |
920 | |||
921 | 88746 | static void alf_fill_border_v(uint8_t *dst, const ptrdiff_t dst_stride, const uint8_t *src, | |
922 | const uint8_t *border, const int border_pixels, const int height, const int pixel_shift, const int *edges, const int edge) | ||
923 | { | ||
924 | 88746 | const ptrdiff_t src_stride = (border_pixels << pixel_shift); | |
925 | |||
926 |
2/2✓ Branch 0 taken 10297 times.
✓ Branch 1 taken 78449 times.
|
88746 | if (edge) { |
927 | 10297 | alf_extend_vert(dst, border, pixel_shift, border_pixels, height + 2 * border_pixels, dst_stride); | |
928 | 10297 | return; | |
929 | } | ||
930 | |||
931 | //left/right | ||
932 | 78449 | alf_copy_border(dst + dst_stride * border_pixels * edges[TOP], src + src_stride * border_pixels * edges[TOP], | |
933 | 78449 | pixel_shift, border_pixels, height + (!edges[TOP] + !edges[BOTTOM]) * border_pixels, dst_stride, src_stride); | |
934 | |||
935 | //top left/right | ||
936 |
2/2✓ Branch 0 taken 12856 times.
✓ Branch 1 taken 65593 times.
|
78449 | if (edges[TOP]) |
937 | 12856 | alf_extend_horz(dst, dst + dst_stride * border_pixels, pixel_shift, border_pixels, border_pixels, dst_stride); | |
938 | |||
939 | //bottom left/right | ||
940 |
2/2✓ Branch 0 taken 15347 times.
✓ Branch 1 taken 63102 times.
|
78449 | if (edges[BOTTOM]) { |
941 | 15347 | dst += dst_stride * (border_pixels + height); | |
942 | 15347 | alf_extend_horz(dst, dst - dst_stride, pixel_shift, border_pixels, border_pixels, dst_stride); | |
943 | } | ||
944 | } | ||
945 | |||
946 | 44373 | static void alf_prepare_buffer(VVCFrameContext *fc, uint8_t *_dst, const uint8_t *_src, const int x, const int y, | |
947 | const int rx, const int ry, const int width, const int height, const ptrdiff_t dst_stride, const ptrdiff_t src_stride, | ||
948 | const int c_idx, const int *edges) | ||
949 | { | ||
950 | 44373 | const int ps = fc->ps.sps->pixel_shift; | |
951 | 44373 | const int w = fc->ps.pps->width >> fc->ps.sps->hshift[c_idx]; | |
952 | 44373 | const int h = fc->ps.pps->height >> fc->ps.sps->vshift[c_idx]; | |
953 |
2/2✓ Branch 0 taken 20184 times.
✓ Branch 1 taken 24189 times.
|
44373 | const int border_pixels = c_idx == 0 ? ALF_BORDER_LUMA : ALF_BORDER_CHROMA; |
954 | uint8_t *dst, *src; | ||
955 | |||
956 | 44373 | copy_ctb(_dst, _src, width << ps, height, dst_stride, src_stride); | |
957 | |||
958 | //top | ||
959 | 44373 | src = fc->tab.alf_pixel_buffer_h[c_idx][1] + (((border_pixels * w) << ps) * (ry - 1) + (x << ps)); | |
960 | 44373 | dst = _dst - border_pixels * dst_stride; | |
961 | 44373 | alf_fill_border_h(dst, dst_stride, src, w << ps, _dst, width, border_pixels, ps, edges[TOP]); | |
962 | |||
963 | //bottom | ||
964 | 44373 | src = fc->tab.alf_pixel_buffer_h[c_idx][0] + (((border_pixels * w) << ps) * (ry + 1) + (x << ps)); | |
965 | 44373 | dst = _dst + height * dst_stride; | |
966 | 44373 | alf_fill_border_h(dst, dst_stride, src, w << ps, _dst + (height - 1) * dst_stride, width, border_pixels, ps, edges[BOTTOM]); | |
967 | |||
968 | |||
969 | //left | ||
970 | 44373 | src = fc->tab.alf_pixel_buffer_v[c_idx][1] + (h * (rx - 1) + y - border_pixels) * (border_pixels << ps); | |
971 | 44373 | dst = _dst - (border_pixels << ps) - border_pixels * dst_stride; | |
972 | 44373 | alf_fill_border_v(dst, dst_stride, src, dst + (border_pixels << ps), border_pixels, height, ps, edges, edges[LEFT]); | |
973 | |||
974 | //right | ||
975 | 44373 | src = fc->tab.alf_pixel_buffer_v[c_idx][0] + (h * (rx + 1) + y - border_pixels) * (border_pixels << ps); | |
976 | 44373 | dst = _dst + (width << ps) - border_pixels * dst_stride; | |
977 | 44373 | alf_fill_border_v(dst, dst_stride, src, dst - (1 << ps), border_pixels, height, ps, edges, edges[RIGHT]); | |
978 | 44373 | } | |
979 | |||
980 | #define ALF_MAX_BLOCKS_IN_CTU (MAX_CTU_SIZE * MAX_CTU_SIZE / ALF_BLOCK_SIZE / ALF_BLOCK_SIZE) | ||
981 | #define ALF_MAX_FILTER_SIZE (ALF_MAX_BLOCKS_IN_CTU * ALF_NUM_COEFF_LUMA) | ||
982 | |||
983 | 19551 | static void alf_get_coeff_and_clip(VVCLocalContext *lc, int16_t *coeff, int16_t *clip, | |
984 | const uint8_t *src, ptrdiff_t src_stride, int width, int height, int vb_pos, const ALFParams *alf) | ||
985 | { | ||
986 | 19551 | const VVCFrameContext *fc = lc->fc; | |
987 | 19551 | const H266RawSliceHeader *rsh = lc->sc->sh.r; | |
988 | 19551 | uint8_t fixed_clip_set[ALF_NUM_FILTERS_LUMA][ALF_NUM_COEFF_LUMA] = { 0 }; | |
989 | const int16_t *coeff_set; | ||
990 | const uint8_t *clip_idx_set; | ||
991 | const uint8_t *class_to_filt; | ||
992 | 19551 | const int size = width * height / ALF_BLOCK_SIZE / ALF_BLOCK_SIZE; | |
993 | int class_idx[ALF_MAX_BLOCKS_IN_CTU]; | ||
994 | int transpose_idx[ALF_MAX_BLOCKS_IN_CTU]; | ||
995 | |||
996 |
2/2✓ Branch 0 taken 2775 times.
✓ Branch 1 taken 16776 times.
|
19551 | if (alf->ctb_filt_set_idx_y < 16) { |
997 | 2775 | coeff_set = &ff_vvc_alf_fix_filt_coeff[0][0]; | |
998 | 2775 | clip_idx_set = &fixed_clip_set[0][0]; | |
999 | 2775 | class_to_filt = ff_vvc_alf_class_to_filt_map[alf->ctb_filt_set_idx_y]; | |
1000 | } else { | ||
1001 | 16776 | const int id = rsh->sh_alf_aps_id_luma[alf->ctb_filt_set_idx_y - 16]; | |
1002 | 16776 | const VVCALF *aps = fc->ps.alf_list[id]; | |
1003 | 16776 | coeff_set = &aps->luma_coeff[0][0]; | |
1004 | 16776 | clip_idx_set = &aps->luma_clip_idx[0][0]; | |
1005 | 16776 | class_to_filt = ff_vvc_alf_aps_class_to_filt_map; | |
1006 | } | ||
1007 | 19551 | fc->vvcdsp.alf.classify(class_idx, transpose_idx, src, src_stride, width, height, | |
1008 | 19551 | vb_pos, lc->alf_gradient_tmp); | |
1009 | 19551 | fc->vvcdsp.alf.recon_coeff_and_clip(coeff, clip, class_idx, transpose_idx, size, | |
1010 | coeff_set, clip_idx_set, class_to_filt); | ||
1011 | 19551 | } | |
1012 | |||
1013 | 19551 | static void alf_filter_luma(VVCLocalContext *lc, uint8_t *dst, const uint8_t *src, | |
1014 | const ptrdiff_t dst_stride, const ptrdiff_t src_stride, const int x0, const int y0, | ||
1015 | const int width, const int height, const int _vb_pos, const ALFParams *alf) | ||
1016 | { | ||
1017 | 19551 | const VVCFrameContext *fc = lc->fc; | |
1018 | 19551 | int vb_pos = _vb_pos - y0; | |
1019 | 19551 | int16_t *coeff = (int16_t*)lc->tmp; | |
1020 | 19551 | int16_t *clip = (int16_t *)lc->tmp1; | |
1021 | |||
1022 | av_assert0(ALF_MAX_FILTER_SIZE <= sizeof(lc->tmp)); | ||
1023 | av_assert0(ALF_MAX_FILTER_SIZE * sizeof(int16_t) <= sizeof(lc->tmp1)); | ||
1024 | |||
1025 | 19551 | alf_get_coeff_and_clip(lc, coeff, clip, src, src_stride, width, height, vb_pos, alf); | |
1026 | 19551 | fc->vvcdsp.alf.filter[LUMA](dst, dst_stride, src, src_stride, width, height, coeff, clip, vb_pos); | |
1027 | 19551 | } | |
1028 | |||
1029 | 145134 | static int alf_clip_from_idx(const VVCFrameContext *fc, const int idx) | |
1030 | { | ||
1031 | 145134 | const VVCSPS *sps = fc->ps.sps; | |
1032 | 145134 | const int offset[] = {0, 3, 5, 7}; | |
1033 | |||
1034 | 145134 | return 1 << (sps->bit_depth - offset[idx]); | |
1035 | } | ||
1036 | |||
1037 | 24189 | static void alf_filter_chroma(VVCLocalContext *lc, uint8_t *dst, const uint8_t *src, | |
1038 | const ptrdiff_t dst_stride, const ptrdiff_t src_stride, const int c_idx, | ||
1039 | const int width, const int height, const int vb_pos, const ALFParams *alf) | ||
1040 | { | ||
1041 | 24189 | VVCFrameContext *fc = lc->fc; | |
1042 | 24189 | const H266RawSliceHeader *rsh = lc->sc->sh.r; | |
1043 | 24189 | const VVCALF *aps = fc->ps.alf_list[rsh->sh_alf_aps_id_chroma]; | |
1044 | 24189 | const int idx = alf->alf_ctb_filter_alt_idx[c_idx - 1]; | |
1045 | 24189 | const int16_t *coeff = aps->chroma_coeff[idx]; | |
1046 | int16_t clip[ALF_NUM_COEFF_CHROMA]; | ||
1047 | |||
1048 |
2/2✓ Branch 0 taken 145134 times.
✓ Branch 1 taken 24189 times.
|
169323 | for (int i = 0; i < ALF_NUM_COEFF_CHROMA; i++) |
1049 | 145134 | clip[i] = alf_clip_from_idx(fc, aps->chroma_clip_idx[idx][i]); | |
1050 | |||
1051 | 24189 | fc->vvcdsp.alf.filter[CHROMA](dst, dst_stride, src, src_stride, width, height, coeff, clip, vb_pos); | |
1052 | 24189 | } | |
1053 | |||
1054 | 10519 | static void alf_filter_cc(VVCLocalContext *lc, uint8_t *dst, const uint8_t *luma, | |
1055 | const ptrdiff_t dst_stride, const ptrdiff_t luma_stride, const int c_idx, | ||
1056 | const int width, const int height, const int hs, const int vs, const int vb_pos, const ALFParams *alf) | ||
1057 | { | ||
1058 | 10519 | const VVCFrameContext *fc = lc->fc; | |
1059 | 10519 | const H266RawSliceHeader *rsh = lc->sc->sh.r; | |
1060 | 10519 | const int idx = c_idx - 1; | |
1061 |
2/2✓ Branch 0 taken 5375 times.
✓ Branch 1 taken 5144 times.
|
10519 | const int cc_aps_id = c_idx == CB ? rsh->sh_alf_cc_cb_aps_id : rsh->sh_alf_cc_cr_aps_id; |
1062 | 10519 | const VVCALF *aps = fc->ps.alf_list[cc_aps_id]; | |
1063 | |||
1064 |
1/2✓ Branch 0 taken 10519 times.
✗ Branch 1 not taken.
|
10519 | if (aps) { |
1065 | 10519 | const int16_t *coeff = aps->cc_coeff[idx][alf->ctb_cc_idc[idx] - 1]; | |
1066 | |||
1067 | 10519 | fc->vvcdsp.alf.filter_cc(dst, dst_stride, luma, luma_stride, width, height, hs, vs, coeff, vb_pos); | |
1068 | } | ||
1069 | 10519 | } | |
1070 | |||
1071 | 36667 | void ff_vvc_alf_copy_ctu_to_hv(VVCLocalContext* lc, const int x0, const int y0) | |
1072 | { | ||
1073 | 36667 | VVCFrameContext *fc = lc->fc; | |
1074 | 36667 | const int rx = x0 >> fc->ps.sps->ctb_log2_size_y; | |
1075 | 36667 | const int ry = y0 >> fc->ps.sps->ctb_log2_size_y; | |
1076 | 36667 | const int ctb_size_y = fc->ps.sps->ctb_size_y; | |
1077 |
2/2✓ Branch 0 taken 36139 times.
✓ Branch 1 taken 528 times.
|
36667 | const int c_end = fc->ps.sps->r->sps_chroma_format_idc ? VVC_MAX_SAMPLE_ARRAYS : 1; |
1078 | |||
1079 |
2/2✓ Branch 0 taken 108945 times.
✓ Branch 1 taken 36667 times.
|
145612 | for (int c_idx = 0; c_idx < c_end; c_idx++) { |
1080 | 108945 | const int hs = fc->ps.sps->hshift[c_idx]; | |
1081 | 108945 | const int vs = fc->ps.sps->vshift[c_idx]; | |
1082 | 108945 | const int x = x0 >> hs; | |
1083 | 108945 | const int y = y0 >> vs; | |
1084 | 108945 | const int width = FFMIN(fc->ps.pps->width - x0, ctb_size_y) >> hs; | |
1085 | 108945 | const int height = FFMIN(fc->ps.pps->height - y0, ctb_size_y) >> vs; | |
1086 | |||
1087 | 108945 | const int src_stride = fc->frame->linesize[c_idx]; | |
1088 | 108945 | uint8_t *src = POS(c_idx, x0, y0); | |
1089 | |||
1090 | 108945 | alf_copy_ctb_to_hv(fc, src, src_stride, x, y, width, height, rx, ry, c_idx); | |
1091 | } | ||
1092 | 36667 | } | |
1093 | |||
1094 | 36667 | static void alf_get_edges(const VVCLocalContext *lc, int edges[MAX_EDGES], const int rx, const int ry) | |
1095 | { | ||
1096 | 36667 | VVCFrameContext *fc = lc->fc; | |
1097 | 36667 | const VVCSPS *sps = fc->ps.sps; | |
1098 | 36667 | const VVCPPS *pps = fc->ps.pps; | |
1099 | 36667 | const int subpic_idx = lc->sc->sh.r->curr_subpic_idx; | |
1100 | |||
1101 | // we can't use |= instead of || in this function; |= is not a shortcut operator | ||
1102 | |||
1103 |
2/2✓ Branch 0 taken 33256 times.
✓ Branch 1 taken 3411 times.
|
36667 | if (!pps->r->pps_loop_filter_across_tiles_enabled_flag) { |
1104 |
4/4✓ Branch 0 taken 30034 times.
✓ Branch 1 taken 3222 times.
✓ Branch 2 taken 612 times.
✓ Branch 3 taken 29422 times.
|
33256 | edges[LEFT] = edges[LEFT] || (lc->boundary_flags & BOUNDARY_LEFT_TILE); |
1105 |
4/4✓ Branch 0 taken 27548 times.
✓ Branch 1 taken 5708 times.
✓ Branch 2 taken 564 times.
✓ Branch 3 taken 26984 times.
|
33256 | edges[TOP] = edges[TOP] || (lc->boundary_flags & BOUNDARY_UPPER_TILE); |
1106 |
4/4✓ Branch 0 taken 30034 times.
✓ Branch 1 taken 3222 times.
✓ Branch 2 taken 612 times.
✓ Branch 3 taken 29422 times.
|
33256 | edges[RIGHT] = edges[RIGHT] || pps->ctb_to_col_bd[rx] != pps->ctb_to_col_bd[rx + 1]; |
1107 |
4/4✓ Branch 0 taken 27548 times.
✓ Branch 1 taken 5708 times.
✓ Branch 2 taken 564 times.
✓ Branch 3 taken 26984 times.
|
33256 | edges[BOTTOM] = edges[BOTTOM] || pps->ctb_to_row_bd[ry] != pps->ctb_to_row_bd[ry + 1]; |
1108 | } | ||
1109 | |||
1110 |
2/2✓ Branch 0 taken 33207 times.
✓ Branch 1 taken 3460 times.
|
36667 | if (!pps->r->pps_loop_filter_across_slices_enabled_flag) { |
1111 |
4/4✓ Branch 0 taken 29506 times.
✓ Branch 1 taken 3701 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 29501 times.
|
33207 | edges[LEFT] = edges[LEFT] || (lc->boundary_flags & BOUNDARY_LEFT_SLICE); |
1112 |
4/4✓ Branch 0 taken 27068 times.
✓ Branch 1 taken 6139 times.
✓ Branch 2 taken 71 times.
✓ Branch 3 taken 26997 times.
|
33207 | edges[TOP] = edges[TOP] || (lc->boundary_flags & BOUNDARY_UPPER_SLICE); |
1113 |
4/4✓ Branch 0 taken 29506 times.
✓ Branch 1 taken 3701 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 29501 times.
|
33207 | edges[RIGHT] = edges[RIGHT] || CTB(fc->tab.slice_idx, rx, ry) != CTB(fc->tab.slice_idx, rx + 1, ry); |
1114 |
4/4✓ Branch 0 taken 27068 times.
✓ Branch 1 taken 6139 times.
✓ Branch 2 taken 71 times.
✓ Branch 3 taken 26997 times.
|
33207 | edges[BOTTOM] = edges[BOTTOM] || CTB(fc->tab.slice_idx, rx, ry) != CTB(fc->tab.slice_idx, rx, ry + 1); |
1115 | } | ||
1116 | |||
1117 |
2/2✓ Branch 0 taken 35701 times.
✓ Branch 1 taken 966 times.
|
36667 | if (!sps->r->sps_loop_filter_across_subpic_enabled_flag[subpic_idx]) { |
1118 |
4/4✓ Branch 0 taken 31964 times.
✓ Branch 1 taken 3737 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 31960 times.
|
35701 | edges[LEFT] = edges[LEFT] || (lc->boundary_flags & BOUNDARY_LEFT_SUBPIC); |
1119 |
3/4✓ Branch 0 taken 29336 times.
✓ Branch 1 taken 6365 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 29336 times.
|
35701 | edges[TOP] = edges[TOP] || (lc->boundary_flags & BOUNDARY_UPPER_SUBPIC); |
1120 |
3/4✓ Branch 0 taken 31960 times.
✓ Branch 1 taken 3741 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 31960 times.
|
35701 | edges[RIGHT] = edges[RIGHT] || fc->ps.sps->r->sps_subpic_ctu_top_left_x[subpic_idx] + fc->ps.sps->r->sps_subpic_width_minus1[subpic_idx] == rx; |
1121 |
4/4✓ Branch 0 taken 29348 times.
✓ Branch 1 taken 6353 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 29336 times.
|
35701 | edges[BOTTOM] = edges[BOTTOM] || fc->ps.sps->r->sps_subpic_ctu_top_left_y[subpic_idx] + fc->ps.sps->r->sps_subpic_height_minus1[subpic_idx] == ry; |
1122 | } | ||
1123 | |||
1124 |
2/2✓ Branch 0 taken 1029 times.
✓ Branch 1 taken 35638 times.
|
36667 | if (sps->r->sps_virtual_boundaries_enabled_flag) { |
1125 |
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); |
1126 |
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); |
1127 |
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); |
1128 |
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); |
1129 | } | ||
1130 | 36667 | } | |
1131 | |||
1132 | 36667 | static void alf_init_subblock(VVCRect *sb, int sb_edges[MAX_EDGES], const VVCRect *b, const int edges[MAX_EDGES]) | |
1133 | { | ||
1134 | 36667 | *sb = *b; | |
1135 | 36667 | memcpy(sb_edges, edges, sizeof(int) * MAX_EDGES); | |
1136 | 36667 | } | |
1137 | |||
1138 | 36667 | static void alf_get_subblock(VVCRect *sb, int edges[MAX_EDGES], const int bx, const int by, const int vb_pos[2], const int has_vb[2]) | |
1139 | { | ||
1140 | 36667 | int *pos[] = { &sb->l, &sb->t, &sb->r, &sb->b }; | |
1141 | |||
1142 |
2/2✓ Branch 0 taken 73334 times.
✓ Branch 1 taken 36667 times.
|
110001 | for (int vertical = 0; vertical <= 1; vertical++) { |
1143 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 73334 times.
|
73334 | if (has_vb[vertical]) { |
1144 | ✗ | const int c = vertical ? (bx ? LEFT : RIGHT) : (by ? TOP : BOTTOM); | |
1145 | ✗ | *pos[c] = vb_pos[vertical]; | |
1146 | ✗ | edges[c] = 1; | |
1147 | } | ||
1148 | } | ||
1149 | 36667 | } | |
1150 | |||
1151 | 36667 | static void alf_get_subblocks(const VVCLocalContext *lc, VVCRect sbs[MAX_VBBS], int sb_edges[MAX_VBBS][MAX_EDGES], int *nb_sbs, | |
1152 | const int x0, const int y0, const int rx, const int ry) | ||
1153 | { | ||
1154 | 36667 | VVCFrameContext *fc = lc->fc; | |
1155 | 36667 | const VVCSPS *sps = fc->ps.sps; | |
1156 | 36667 | const VVCPPS *pps = fc->ps.pps; | |
1157 | 36667 | const int ctu_size_y = sps->ctb_size_y; | |
1158 | 36667 | const int vb_pos[] = { get_virtual_boundary(fc, ry, 0), get_virtual_boundary(fc, rx, 1) }; | |
1159 | 36667 | const int has_vb[] = { vb_pos[0] > y0, vb_pos[1] > x0 }; | |
1160 | 36667 | const VVCRect b = { x0, y0, FFMIN(x0 + ctu_size_y, pps->width), FFMIN(y0 + ctu_size_y, pps->height) }; | |
1161 | 36667 | int edges[MAX_EDGES] = { !rx, !ry, rx == pps->ctb_width - 1, ry == pps->ctb_height - 1 }; | |
1162 | 36667 | int i = 0; | |
1163 | |||
1164 | 36667 | alf_get_edges(lc, edges, rx, ry); | |
1165 | |||
1166 |
2/2✓ Branch 0 taken 36667 times.
✓ Branch 1 taken 36667 times.
|
73334 | for (int by = 0; by <= has_vb[0]; by++) { |
1167 |
2/2✓ Branch 0 taken 36667 times.
✓ Branch 1 taken 36667 times.
|
73334 | for (int bx = 0; bx <= has_vb[1]; bx++, i++) { |
1168 | 36667 | alf_init_subblock(sbs + i, sb_edges[i], &b, edges); | |
1169 | 36667 | alf_get_subblock(sbs + i, sb_edges[i], bx, by, vb_pos, has_vb); | |
1170 | } | ||
1171 | } | ||
1172 | 36667 | *nb_sbs = i; | |
1173 | 36667 | } | |
1174 | |||
1175 | 36667 | void ff_vvc_alf_filter(VVCLocalContext *lc, const int x0, const int y0) | |
1176 | { | ||
1177 | 36667 | VVCFrameContext *fc = lc->fc; | |
1178 | 36667 | const VVCSPS *sps = fc->ps.sps; | |
1179 | 36667 | const int rx = x0 >> sps->ctb_log2_size_y; | |
1180 | 36667 | const int ry = y0 >> sps->ctb_log2_size_y; | |
1181 | 36667 | const int ps = sps->pixel_shift; | |
1182 | 36667 | const int padded_stride = EDGE_EMU_BUFFER_STRIDE << ps; | |
1183 | 36667 | const int padded_offset = padded_stride * ALF_PADDING_SIZE + (ALF_PADDING_SIZE << ps); | |
1184 |
2/2✓ Branch 0 taken 36139 times.
✓ Branch 1 taken 528 times.
|
36667 | const int c_end = sps->r->sps_chroma_format_idc ? VVC_MAX_SAMPLE_ARRAYS : 1; |
1185 | 36667 | const int has_chroma = !!sps->r->sps_chroma_format_idc; | |
1186 | 36667 | const int ctu_end = y0 + sps->ctb_size_y; | |
1187 | 36667 | const ALFParams *alf = &CTB(fc->tab.alf, rx, ry); | |
1188 | int sb_edges[MAX_VBBS][MAX_EDGES], nb_sbs; | ||
1189 | VVCRect sbs[MAX_VBBS]; | ||
1190 | |||
1191 | 36667 | alf_get_subblocks(lc, sbs, sb_edges, &nb_sbs, x0, y0, rx, ry); | |
1192 | |||
1193 |
2/2✓ Branch 0 taken 36667 times.
✓ Branch 1 taken 36667 times.
|
73334 | for (int i = 0; i < nb_sbs; i++) { |
1194 | 36667 | const VVCRect *sb = sbs + i; | |
1195 |
2/2✓ Branch 0 taken 108945 times.
✓ Branch 1 taken 36667 times.
|
145612 | for (int c_idx = 0; c_idx < c_end; c_idx++) { |
1196 | 108945 | const int hs = fc->ps.sps->hshift[c_idx]; | |
1197 | 108945 | const int vs = fc->ps.sps->vshift[c_idx]; | |
1198 | 108945 | const int x = sb->l >> hs; | |
1199 | 108945 | const int y = sb->t >> vs; | |
1200 | 108945 | const int width = (sb->r - sb->l) >> hs; | |
1201 | 108945 | const int height = (sb->b - sb->t) >> vs; | |
1202 | 108945 | const int src_stride = fc->frame->linesize[c_idx]; | |
1203 | 108945 | uint8_t *src = POS(c_idx, sb->l, sb->t); | |
1204 | uint8_t *padded; | ||
1205 | |||
1206 |
10/10✓ Branch 0 taken 65205 times.
✓ Branch 1 taken 43740 times.
✓ Branch 2 taken 17116 times.
✓ Branch 3 taken 48089 times.
✓ Branch 4 taken 16946 times.
✓ Branch 5 taken 170 times.
✓ Branch 6 taken 16412 times.
✓ Branch 7 taken 534 times.
✓ Branch 8 taken 99 times.
✓ Branch 9 taken 16313 times.
|
108945 | if (alf->ctb_flag[c_idx] || (!c_idx && has_chroma && (alf->ctb_cc_idc[0] || alf->ctb_cc_idc[1]))) { |
1207 |
2/2✓ Branch 0 taken 24189 times.
✓ Branch 1 taken 20184 times.
|
44373 | padded = (c_idx ? lc->alf_buffer_chroma : lc->alf_buffer_luma) + padded_offset; |
1208 | 44373 | alf_prepare_buffer(fc, padded, src, x, y, rx, ry, width, height, | |
1209 | 44373 | padded_stride, src_stride, c_idx, sb_edges[i]); | |
1210 | } | ||
1211 |
2/2✓ Branch 0 taken 43740 times.
✓ Branch 1 taken 65205 times.
|
108945 | if (alf->ctb_flag[c_idx]) { |
1212 |
2/2✓ Branch 0 taken 19551 times.
✓ Branch 1 taken 24189 times.
|
43740 | if (!c_idx) { |
1213 | 19551 | alf_filter_luma(lc, src, padded, src_stride, padded_stride, x, y, | |
1214 | width, height, ctu_end - ALF_VB_POS_ABOVE_LUMA, alf); | ||
1215 | } else { | ||
1216 | 24189 | alf_filter_chroma(lc, src, padded, src_stride, padded_stride, c_idx, | |
1217 | 24189 | width, height, ((ctu_end - sb->t) >> vs) - ALF_VB_POS_ABOVE_CHROMA, alf); | |
1218 | } | ||
1219 | } | ||
1220 |
4/4✓ Branch 0 taken 72278 times.
✓ Branch 1 taken 36667 times.
✓ Branch 2 taken 10519 times.
✓ Branch 3 taken 61759 times.
|
108945 | if (c_idx && alf->ctb_cc_idc[c_idx - 1]) { |
1221 | 10519 | padded = lc->alf_buffer_luma + padded_offset; | |
1222 | 10519 | alf_filter_cc(lc, src, padded, src_stride, padded_stride, c_idx, | |
1223 | 10519 | width, height, hs, vs, ctu_end - sb->t - ALF_VB_POS_ABOVE_LUMA, alf); | |
1224 | } | ||
1225 | } | ||
1226 | } | ||
1227 | 36667 | } | |
1228 | |||
1229 | |||
1230 | 46705 | void ff_vvc_lmcs_filter(const VVCLocalContext *lc, const int x, const int y) | |
1231 | { | ||
1232 | 46705 | const SliceContext *sc = lc->sc; | |
1233 | 46705 | const VVCFrameContext *fc = lc->fc; | |
1234 | 46705 | const int ctb_size = fc->ps.sps->ctb_size_y; | |
1235 | 46705 | const int width = FFMIN(fc->ps.pps->width - x, ctb_size); | |
1236 | 46705 | const int height = FFMIN(fc->ps.pps->height - y, ctb_size); | |
1237 | 46705 | uint8_t *data = POS(LUMA, x, y); | |
1238 |
2/2✓ Branch 0 taken 19686 times.
✓ Branch 1 taken 27019 times.
|
46705 | if (sc->sh.r->sh_lmcs_used_flag) |
1239 | 19686 | fc->vvcdsp.lmcs.filter(data, fc->frame->linesize[LUMA], width, height, &fc->ps.lmcs.inv_lut); | |
1240 | 46705 | } | |
1241 |