FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/vvc/ctu.c
Date: 2025-07-28 20:30:09
Exec Total Coverage
Lines: 1623 1861 87.2%
Functions: 82 89 92.1%
Branches: 1402 1744 80.4%

Line Branch Exec Source
1 /*
2 * VVC CTU(Coding Tree Unit) parser
3 *
4 * Copyright (C) 2022 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
23 #include "libavutil/error.h"
24 #include "libavutil/refstruct.h"
25
26 #include "cabac.h"
27 #include "ctu.h"
28 #include "inter.h"
29 #include "intra.h"
30 #include "mvs.h"
31
32 #define PROF_TEMP_SIZE (PROF_BLOCK_SIZE) * sizeof(int16_t)
33
34 #define TAB_MSM(fc, depth, x, y) fc->tab.msm[(depth)][((y) >> 5) * fc->ps.pps->width32 + ((x) >> 5)]
35 #define TAB_ISPMF(fc, x, y) fc->tab.ispmf[((y) >> 6) * fc->ps.pps->width64 + ((x) >> 6)]
36
37 typedef enum VVCModeType {
38 MODE_TYPE_ALL,
39 MODE_TYPE_INTER,
40 MODE_TYPE_INTRA,
41 } VVCModeType;
42
43 2058025 static void set_tb_size(const VVCFrameContext *fc, const TransformBlock *tb)
44 {
45 2058025 const int x_tb = tb->x0 >> MIN_TU_LOG2;
46 2058025 const int y_tb = tb->y0 >> MIN_TU_LOG2;
47 2058025 const int hs = fc->ps.sps->hshift[tb->c_idx];
48 2058025 const int vs = fc->ps.sps->vshift[tb->c_idx];
49 2058025 const int is_chroma = tb->c_idx != 0;
50 2058025 const int width = FFMAX(1, tb->tb_width >> (MIN_TU_LOG2 - hs));
51 2058025 const int end = y_tb + FFMAX(1, tb->tb_height >> (MIN_TU_LOG2 - vs));
52
53
2/2
✓ Branch 0 taken 9687955 times.
✓ Branch 1 taken 2058025 times.
11745980 for (int y = y_tb; y < end; y++) {
54 9687955 const int off = y * fc->ps.pps->min_tu_width + x_tb;
55 9687955 memset(fc->tab.tb_width [is_chroma] + off, tb->tb_width, width);
56 9687955 memset(fc->tab.tb_height[is_chroma] + off, tb->tb_height, width);
57 }
58 2058025 }
59
60 2877935 static void set_tb_tab(uint8_t *tab, uint8_t v, const VVCFrameContext *fc,
61 const TransformBlock *tb)
62 {
63 2877935 const int width = tb->tb_width << fc->ps.sps->hshift[tb->c_idx];
64 2877935 const int height = tb->tb_height << fc->ps.sps->vshift[tb->c_idx];
65
66
2/2
✓ Branch 0 taken 13399345 times.
✓ Branch 1 taken 2877935 times.
16277280 for (int h = 0; h < height; h += MIN_TU_SIZE) {
67 13399345 const int y = (tb->y0 + h) >> MIN_TU_LOG2;
68 13399345 const int off = y * fc->ps.pps->min_tu_width + (tb->x0 >> MIN_TU_LOG2);
69 13399345 const int w = FFMAX(1, width >> MIN_TU_LOG2);
70 13399345 memset(tab + off, v, w);
71 }
72 2877935 }
73
74 // 8.7.1 Derivation process for quantization parameters
75 2765 static int get_qp_y_pred(const VVCLocalContext *lc)
76 {
77 2765 const VVCFrameContext *fc = lc->fc;
78 2765 const VVCSPS *sps = fc->ps.sps;
79 2765 const VVCPPS *pps = fc->ps.pps;
80 2765 const CodingUnit *cu = lc->cu;
81 2765 const int ctb_log2_size = sps->ctb_log2_size_y;
82 2765 const int ctb_size_mask = (1 << ctb_log2_size) - 1;
83 2765 const int xQg = lc->parse.cu_qg_top_left_x;
84 2765 const int yQg = lc->parse.cu_qg_top_left_y;
85 2765 const int min_cb_width = fc->ps.pps->min_cb_width;
86 2765 const int x_cb = cu->x0 >> sps->min_cb_log2_size_y;
87 2765 const int y_cb = cu->y0 >> sps->min_cb_log2_size_y;
88 2765 const int rx = cu->x0 >> ctb_log2_size;
89 2765 const int ry = cu->y0 >> ctb_log2_size;
90
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2765 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2765 const int in_same_ctb_a = ((xQg - 1) >> ctb_log2_size) == rx && (yQg >> ctb_log2_size) == ry;
91
2/4
✓ Branch 0 taken 2765 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2765 times.
2765 const int in_same_ctb_b = (xQg >> ctb_log2_size) == rx && ((yQg - 1) >> ctb_log2_size) == ry;
92 int qPy_pred, qPy_a, qPy_b;
93
94
2/2
✓ Branch 0 taken 1681 times.
✓ Branch 1 taken 1084 times.
2765 if (lc->na.cand_up) {
95
2/4
✓ Branch 0 taken 1681 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1681 times.
✗ Branch 3 not taken.
1681 const int first_qg_in_ctu = !(xQg & ctb_size_mask) && !(yQg & ctb_size_mask);
96 1681 const int qPy_up = fc->tab.qp[LUMA][x_cb + (y_cb - 1) * min_cb_width];
97
3/4
✓ Branch 0 taken 1681 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 438 times.
✓ Branch 3 taken 1243 times.
1681 if (first_qg_in_ctu && pps->ctb_to_col_bd[xQg >> ctb_log2_size] == xQg >> ctb_log2_size)
98 438 return qPy_up;
99 }
100
101 // qPy_pred
102
2/2
✓ Branch 0 taken 429 times.
✓ Branch 1 taken 1898 times.
2327 qPy_pred = lc->ep->is_first_qg ? lc->sc->sh.slice_qp_y : lc->ep->qp_y;
103
104 // qPy_b
105
3/4
✓ Branch 0 taken 1243 times.
✓ Branch 1 taken 1084 times.
✓ Branch 2 taken 1243 times.
✗ Branch 3 not taken.
2327 if (!lc->na.cand_up || !in_same_ctb_b)
106 2327 qPy_b = qPy_pred;
107 else
108 qPy_b = fc->tab.qp[LUMA][x_cb + (y_cb - 1) * min_cb_width];
109
110 // qPy_a
111
3/4
✓ Branch 0 taken 1898 times.
✓ Branch 1 taken 429 times.
✓ Branch 2 taken 1898 times.
✗ Branch 3 not taken.
2327 if (!lc->na.cand_left || !in_same_ctb_a)
112 2327 qPy_a = qPy_pred;
113 else
114 qPy_a = fc->tab.qp[LUMA][(x_cb - 1) + y_cb * min_cb_width];
115
116 av_assert2(qPy_a >= -fc->ps.sps->qp_bd_offset && qPy_a <= 63);
117 av_assert2(qPy_b >= -fc->ps.sps->qp_bd_offset && qPy_b <= 63);
118
119 2327 return (qPy_a + qPy_b + 1) >> 1;
120 }
121
122 8829051 static void set_cb_tab(const VVCLocalContext *lc, uint8_t *tab, const uint8_t v)
123 {
124 8829051 const VVCFrameContext *fc = lc->fc;
125 8829051 const VVCPPS *pps = fc->ps.pps;
126 8829051 const CodingUnit *cu = lc->cu;
127 8829051 const int log2_min_cb_size = fc->ps.sps->min_cb_log2_size_y;
128 8829051 const int x_cb = cu->x0 >> log2_min_cb_size;
129 8829051 const int y_cb = cu->y0 >> log2_min_cb_size;
130 8829051 const int cb_width = cu->cb_width;
131 8829051 const int cb_height = cu->cb_height;
132 8829051 int x = y_cb * pps->min_cb_width + x_cb;
133
134
2/2
✓ Branch 0 taken 37659693 times.
✓ Branch 1 taken 8829051 times.
46488744 for (int y = 0; y < (cb_height >> log2_min_cb_size); y++) {
135 37659693 const int width = cb_width >> log2_min_cb_size;
136
137 37659693 memset(&tab[x], v, width);
138 37659693 x += pps->min_cb_width;
139 }
140 8829051 }
141
142 1248313 static int set_qp_y(VVCLocalContext *lc, const int x0, const int y0, const int has_qp_delta)
143 {
144 1248313 const VVCSPS *sps = lc->fc->ps.sps;
145 1248313 EntryPoint *ep = lc->ep;
146 1248313 CodingUnit *cu = lc->cu;
147 1248313 int cu_qp_delta = 0;
148
149
2/2
✓ Branch 0 taken 1080863 times.
✓ Branch 1 taken 167450 times.
1248313 if (!lc->fc->ps.pps->r->pps_cu_qp_delta_enabled_flag) {
150 1080863 ep->qp_y = lc->sc->sh.slice_qp_y;
151
6/6
✓ Branch 0 taken 167021 times.
✓ Branch 1 taken 429 times.
✓ Branch 2 taken 15446 times.
✓ Branch 3 taken 151575 times.
✓ Branch 4 taken 2336 times.
✓ Branch 5 taken 13110 times.
167450 } else if (ep->is_first_qg || (lc->parse.cu_qg_top_left_x == x0 && lc->parse.cu_qg_top_left_y == y0)) {
152 2765 ep->qp_y = get_qp_y_pred(lc);
153 2765 ep->is_first_qg = 0;
154 }
155
156
2/2
✓ Branch 0 taken 1888 times.
✓ Branch 1 taken 1246425 times.
1248313 if (has_qp_delta) {
157 1888 const int cu_qp_delta_abs = ff_vvc_cu_qp_delta_abs(lc);
158
159
2/2
✓ Branch 0 taken 1106 times.
✓ Branch 1 taken 782 times.
1888 if (cu_qp_delta_abs)
160
2/2
✓ Branch 1 taken 649 times.
✓ Branch 2 taken 457 times.
1106 cu_qp_delta = ff_vvc_cu_qp_delta_sign_flag(lc) ? -cu_qp_delta_abs : cu_qp_delta_abs;
161
2/4
✓ Branch 0 taken 1888 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1888 times.
1888 if (cu_qp_delta > (31 + sps->qp_bd_offset / 2) || cu_qp_delta < -(32 + sps->qp_bd_offset / 2))
162 return AVERROR_INVALIDDATA;
163 1888 lc->parse.is_cu_qp_delta_coded = 1;
164
165
2/2
✓ Branch 0 taken 1106 times.
✓ Branch 1 taken 782 times.
1888 if (cu_qp_delta) {
166 1106 int off = sps->qp_bd_offset;
167
1/2
✓ Branch 0 taken 1106 times.
✗ Branch 1 not taken.
1106 ep->qp_y = FFUMOD(ep->qp_y + cu_qp_delta + 64 + 2 * off, 64 + off) - off;
168 }
169 }
170
171 1248313 set_cb_tab(lc, lc->fc->tab.qp[LUMA], ep->qp_y);
172 1248313 cu->qp[LUMA] = ep->qp_y;
173
174 1248313 return 0;
175 }
176
177 1493996 static void set_qp_c_tab(const VVCLocalContext *lc, const TransformUnit *tu, const TransformBlock *tb)
178 {
179
6/6
✓ Branch 0 taken 104536 times.
✓ Branch 1 taken 1389460 times.
✓ Branch 2 taken 89096 times.
✓ Branch 3 taken 15440 times.
✓ Branch 4 taken 59546 times.
✓ Branch 5 taken 29550 times.
1493996 const int is_jcbcr = tu->joint_cbcr_residual_flag && tu->coded_flag[CB] && tu->coded_flag[CR];
180
2/2
✓ Branch 0 taken 1434450 times.
✓ Branch 1 taken 59546 times.
1493996 const int idx = is_jcbcr ? JCBCR : tb->c_idx;
181
182 1493996 set_tb_tab(lc->fc->tab.qp[tb->c_idx], lc->cu->qp[idx], lc->fc, tb);
183 1493996 }
184
185 1190916 static void set_qp_c(VVCLocalContext *lc)
186 {
187 1190916 const VVCFrameContext *fc = lc->fc;
188 1190916 const VVCSPS *sps = fc->ps.sps;
189 1190916 const VVCPPS *pps = fc->ps.pps;
190 1190916 const H266RawSliceHeader *rsh = lc->sc->sh.r;
191 1190916 CodingUnit *cu = lc->cu;
192 1190916 const int x_center = cu->x0 + cu->cb_width / 2;
193 1190916 const int y_center = cu->y0 + cu->cb_height / 2;
194 1190916 const int single_tree = cu->tree_type == SINGLE_TREE;
195
2/2
✓ Branch 0 taken 468948 times.
✓ Branch 1 taken 721968 times.
1190916 const int qp_luma = (single_tree ? lc->ep->qp_y : ff_vvc_get_qPy(fc, x_center, y_center)) + sps->qp_bd_offset;
196 1190916 const int qp_chroma = av_clip(qp_luma, 0, MAX_QP + sps->qp_bd_offset);
197 1190916 const int sh_chroma_qp_offset[] = {
198 1190916 rsh->sh_cb_qp_offset,
199 1190916 rsh->sh_cr_qp_offset,
200 1190916 rsh->sh_joint_cbcr_qp_offset,
201 };
202 int qp;
203
204
2/2
✓ Branch 0 taken 3529853 times.
✓ Branch 1 taken 1190916 times.
4720769 for (int i = CB - 1; i < CR + sps->r->sps_joint_cbcr_enabled_flag; i++) {
205 3529853 qp = sps->chroma_qp_table[i][qp_chroma];
206 3529853 qp = qp + pps->chroma_qp_offset[i] + sh_chroma_qp_offset[i] + lc->parse.chroma_qp_offset[i];
207 3529853 qp = av_clip(qp, -sps->qp_bd_offset, MAX_QP) + sps->qp_bd_offset;
208 3529853 cu->qp[i + 1] = qp;
209 }
210 1190916 }
211
212 1493040 static TransformUnit* alloc_tu(VVCFrameContext *fc, CodingUnit *cu)
213 {
214 1493040 TransformUnit *tu = av_refstruct_pool_get(fc->tu_pool);
215
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1493040 times.
1493040 if (!tu)
216 return NULL;
217
218 1493040 tu->next = NULL;
219
220
2/2
✓ Branch 0 taken 259919 times.
✓ Branch 1 taken 1233121 times.
1493040 if (cu->tus.tail)
221 259919 cu->tus.tail->next = tu;
222 else
223 1233121 cu->tus.head = tu;
224 1493040 cu->tus.tail = tu;
225
226 1493040 return tu;
227 }
228
229 1493040 static TransformUnit* add_tu(VVCFrameContext *fc, CodingUnit *cu, const int x0, const int y0, const int tu_width, const int tu_height)
230 {
231 1493040 TransformUnit *tu = alloc_tu(fc, cu);
232
233
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1493040 times.
1493040 if (!tu)
234 return NULL;
235
236 1493040 tu->x0 = x0;
237 1493040 tu->y0 = y0;
238 1493040 tu->width = tu_width;
239 1493040 tu->height = tu_height;
240 1493040 tu->joint_cbcr_residual_flag = 0;
241 1493040 memset(tu->coded_flag, 0, sizeof(tu->coded_flag));
242 1493040 tu->avail[LUMA] = tu->avail[CHROMA] = 0;
243 1493040 tu->nb_tbs = 0;
244
245 1493040 return tu;
246 }
247
248 2805023 static TransformBlock* add_tb(TransformUnit *tu, VVCLocalContext *lc,
249 const int x0, const int y0, const int tb_width, const int tb_height, const int c_idx)
250 {
251 TransformBlock *tb;
252
253 2805023 tb = &tu->tbs[tu->nb_tbs++];
254 2805023 tb->has_coeffs = 0;
255 2805023 tb->x0 = x0;
256 2805023 tb->y0 = y0;
257 2805023 tb->tb_width = tb_width;
258 2805023 tb->tb_height = tb_height;
259 2805023 tb->log2_tb_width = av_log2(tb_width);
260 2805023 tb->log2_tb_height = av_log2(tb_height);
261
262 2805023 tb->max_scan_x = tb->max_scan_y = 0;
263 2805023 tb->min_scan_x = tb->min_scan_y = 0;
264
265 2805023 tb->c_idx = c_idx;
266 2805023 tb->ts = 0;
267 2805023 tb->coeffs = lc->coeffs;
268 2805023 lc->coeffs += tb_width * tb_height;
269 2805023 tu->avail[!!c_idx] = true;
270 2805023 return tb;
271 }
272
273 953479 static uint8_t tu_y_coded_flag_decode(VVCLocalContext *lc, const int is_sbt_not_coded,
274 const int sub_tu_index, const int is_isp, const int is_chroma_coded)
275 {
276 953479 uint8_t tu_y_coded_flag = 0;
277 953479 const VVCSPS *sps = lc->fc->ps.sps;
278 953479 CodingUnit *cu = lc->cu;
279
280
2/2
✓ Branch 0 taken 908884 times.
✓ Branch 1 taken 44595 times.
953479 if (!is_sbt_not_coded) {
281
4/4
✓ Branch 0 taken 767156 times.
✓ Branch 1 taken 141728 times.
✓ Branch 2 taken 50609 times.
✓ Branch 3 taken 716547 times.
908884 int has_y_coded_flag = sub_tu_index < cu->num_intra_subpartitions - 1 || !lc->parse.infer_tu_cbf_luma;
282
2/2
✓ Branch 0 taken 704726 times.
✓ Branch 1 taken 204158 times.
908884 if (!is_isp) {
283
4/4
✓ Branch 0 taken 693238 times.
✓ Branch 1 taken 11488 times.
✓ Branch 2 taken 2504 times.
✓ Branch 3 taken 690734 times.
704726 const int is_large = cu->cb_width > sps->max_tb_size_y || cu->cb_height > sps->max_tb_size_y;
284
7/8
✓ Branch 0 taken 535860 times.
✓ Branch 1 taken 168866 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 535860 times.
✓ Branch 4 taken 108215 times.
✓ Branch 5 taken 60651 times.
✓ Branch 6 taken 2550 times.
✓ Branch 7 taken 105665 times.
704726 has_y_coded_flag = (cu->pred_mode == MODE_INTRA && !cu->act_enabled_flag) || is_chroma_coded || is_large;
285 }
286
2/2
✓ Branch 0 taken 791398 times.
✓ Branch 1 taken 117486 times.
908884 tu_y_coded_flag = has_y_coded_flag ? ff_vvc_tu_y_coded_flag(lc) : 1;
287 }
288
2/2
✓ Branch 0 taken 204158 times.
✓ Branch 1 taken 749321 times.
953479 if (is_isp)
289
4/4
✓ Branch 0 taken 101608 times.
✓ Branch 1 taken 102550 times.
✓ Branch 2 taken 39178 times.
✓ Branch 3 taken 62430 times.
204158 lc->parse.infer_tu_cbf_luma = lc->parse.infer_tu_cbf_luma && !tu_y_coded_flag;
290 953479 return tu_y_coded_flag;
291 }
292
293 470816 static void chroma_qp_offset_decode(VVCLocalContext *lc, const int is_128, const int is_chroma_coded)
294 {
295 470816 const VVCPPS *pps = lc->fc->ps.pps;
296 470816 const H266RawSliceHeader *rsh = lc->sc->sh.r;
297
298
4/4
✓ Branch 0 taken 462602 times.
✓ Branch 1 taken 8214 times.
✓ Branch 2 taken 186391 times.
✓ Branch 3 taken 276211 times.
470816 if ((is_128 || is_chroma_coded) &&
299
4/4
✓ Branch 0 taken 39307 times.
✓ Branch 1 taken 155298 times.
✓ Branch 2 taken 1029 times.
✓ Branch 3 taken 38278 times.
194605 rsh->sh_cu_chroma_qp_offset_enabled_flag && !lc->parse.is_cu_chroma_qp_offset_coded) {
300 1029 const int cu_chroma_qp_offset_flag = ff_vvc_cu_chroma_qp_offset_flag(lc);
301
1/2
✓ Branch 0 taken 1029 times.
✗ Branch 1 not taken.
1029 if (cu_chroma_qp_offset_flag) {
302 1029 int cu_chroma_qp_offset_idx = 0;
303
2/2
✓ Branch 0 taken 931 times.
✓ Branch 1 taken 98 times.
1029 if (pps->r->pps_chroma_qp_offset_list_len_minus1 > 0)
304 931 cu_chroma_qp_offset_idx = ff_vvc_cu_chroma_qp_offset_idx(lc);
305
2/2
✓ Branch 0 taken 3087 times.
✓ Branch 1 taken 1029 times.
4116 for (int i = CB - 1; i < JCBCR; i++)
306 3087 lc->parse.chroma_qp_offset[i] = pps->chroma_qp_offset_list[cu_chroma_qp_offset_idx][i];
307 } else {
308 memset(lc->parse.chroma_qp_offset, 0, sizeof(lc->parse.chroma_qp_offset));
309 }
310 1029 lc->parse.is_cu_chroma_qp_offset_coded = 1;
311 }
312 470816 }
313
314 1135492 static int hls_transform_unit(VVCLocalContext *lc, int x0, int y0,int tu_width, int tu_height, int sub_tu_index, int ch_type)
315 {
316 1135492 VVCFrameContext *fc = lc->fc;
317 1135492 const VVCSPS *sps = fc->ps.sps;
318 1135492 const VVCPPS *pps = fc->ps.pps;
319 1135492 CodingUnit *cu = lc->cu;
320 1135492 TransformUnit *tu = add_tu(fc, cu, x0, y0, tu_width, tu_height);
321 1135492 const int min_cb_width = pps->min_cb_width;
322 1135492 const VVCTreeType tree_type = cu->tree_type;
323
4/4
✓ Branch 0 taken 1128916 times.
✓ Branch 1 taken 6576 times.
✓ Branch 2 taken 1638 times.
✓ Branch 3 taken 1127278 times.
1135492 const int is_128 = cu->cb_width > 64 || cu->cb_height > 64;
324 1135492 const int is_isp = cu->isp_split_type != ISP_NO_SPLIT;
325
4/4
✓ Branch 0 taken 204158 times.
✓ Branch 1 taken 931334 times.
✓ Branch 2 taken 62430 times.
✓ Branch 3 taken 141728 times.
1135492 const int is_isp_last_tu = is_isp && (sub_tu_index == cu->num_intra_subpartitions - 1);
326
4/4
✓ Branch 0 taken 89190 times.
✓ Branch 1 taken 1046302 times.
✓ Branch 2 taken 44595 times.
✓ Branch 3 taken 44595 times.
1224682 const int is_sbt_not_coded = cu->sbt_flag &&
327
6/6
✓ Branch 0 taken 23208 times.
✓ Branch 1 taken 21387 times.
✓ Branch 2 taken 44595 times.
✓ Branch 3 taken 23208 times.
✓ Branch 4 taken 23208 times.
✓ Branch 5 taken 21387 times.
89190 ((sub_tu_index == 0 && cu->sbt_pos_flag) || (sub_tu_index == 1 && !cu->sbt_pos_flag));
328
6/6
✓ Branch 0 taken 470816 times.
✓ Branch 1 taken 664676 times.
✓ Branch 2 taken 447344 times.
✓ Branch 3 taken 23472 times.
✓ Branch 4 taken 20710 times.
✓ Branch 5 taken 426634 times.
1156202 const int chroma_available = tree_type != DUAL_TREE_LUMA && sps->r->sps_chroma_format_idc &&
329
2/2
✓ Branch 0 taken 5191 times.
✓ Branch 1 taken 15519 times.
20710 (!is_isp || is_isp_last_tu);
330 int ret, xc, yc, wc, hc, is_chroma_coded;
331
332
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1135492 times.
1135492 if (!tu)
333 return AVERROR_INVALIDDATA;
334
335
4/4
✓ Branch 0 taken 288803 times.
✓ Branch 1 taken 846689 times.
✓ Branch 2 taken 6973 times.
✓ Branch 3 taken 281830 times.
1135492 if (tree_type == SINGLE_TREE && is_isp_last_tu) {
336 6973 const int x_cu = x0 >> fc->ps.sps->min_cb_log2_size_y;
337 6973 const int y_cu = y0 >> fc->ps.sps->min_cb_log2_size_y;
338 6973 xc = SAMPLE_CTB(fc->tab.cb_pos_x[ch_type], x_cu, y_cu);
339 6973 yc = SAMPLE_CTB(fc->tab.cb_pos_y[ch_type], x_cu, y_cu);
340 6973 wc = SAMPLE_CTB(fc->tab.cb_width[ch_type], x_cu, y_cu);
341 6973 hc = SAMPLE_CTB(fc->tab.cb_height[ch_type], x_cu, y_cu);
342 } else {
343 1128519 xc = x0, yc = y0, wc = tu_width, hc = tu_height;
344 }
345
346
4/4
✓ Branch 0 taken 431825 times.
✓ Branch 1 taken 703667 times.
✓ Branch 2 taken 388522 times.
✓ Branch 3 taken 43303 times.
1135492 if (chroma_available && !is_sbt_not_coded) {
347 388522 tu->coded_flag[CB] = ff_vvc_tu_cb_coded_flag(lc);
348 388522 tu->coded_flag[CR] = ff_vvc_tu_cr_coded_flag(lc, tu->coded_flag[CB]);
349 }
350
351
6/6
✓ Branch 0 taken 431825 times.
✓ Branch 1 taken 703667 times.
✓ Branch 2 taken 268437 times.
✓ Branch 3 taken 163388 times.
✓ Branch 4 taken 28795 times.
✓ Branch 5 taken 239642 times.
1135492 is_chroma_coded = chroma_available && (tu->coded_flag[CB] || tu->coded_flag[CR]);
352
353
2/2
✓ Branch 0 taken 953479 times.
✓ Branch 1 taken 182013 times.
1135492 if (tree_type != DUAL_TREE_CHROMA) {
354 int has_qp_delta;
355 953479 tu->coded_flag[LUMA] = tu_y_coded_flag_decode(lc, is_sbt_not_coded, sub_tu_index, is_isp, is_chroma_coded);
356
4/4
✓ Branch 0 taken 253637 times.
✓ Branch 1 taken 691628 times.
✓ Branch 2 taken 34290 times.
✓ Branch 3 taken 219347 times.
945265 has_qp_delta = (is_128 || tu->coded_flag[LUMA] || is_chroma_coded) &&
357
6/6
✓ Branch 0 taken 945265 times.
✓ Branch 1 taken 8214 times.
✓ Branch 2 taken 77901 times.
✓ Branch 3 taken 656231 times.
✓ Branch 4 taken 1888 times.
✓ Branch 5 taken 76013 times.
1898744 pps->r->pps_cu_qp_delta_enabled_flag && !lc->parse.is_cu_qp_delta_coded;
358 953479 ret = set_qp_y(lc, x0, y0, has_qp_delta);
359
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 953479 times.
953479 if (ret < 0)
360 return ret;
361 953479 add_tb(tu, lc, x0, y0, tu_width, tu_height, LUMA);
362 }
363
2/2
✓ Branch 0 taken 470816 times.
✓ Branch 1 taken 664676 times.
1135492 if (tree_type != DUAL_TREE_LUMA) {
364 470816 chroma_qp_offset_decode(lc, is_128, is_chroma_coded);
365
2/2
✓ Branch 0 taken 431825 times.
✓ Branch 1 taken 38991 times.
470816 if (chroma_available) {
366 431825 const int hs = sps->hshift[CHROMA];
367 431825 const int vs = sps->vshift[CHROMA];
368 431825 add_tb(tu, lc, xc, yc, wc >> hs, hc >> vs, CB);
369 431825 add_tb(tu, lc, xc, yc, wc >> hs, hc >> vs, CR);
370 }
371 }
372
4/4
✓ Branch 0 taken 1092288 times.
✓ Branch 1 taken 43204 times.
✓ Branch 2 taken 887148 times.
✓ Branch 3 taken 205140 times.
1135492 if (sps->r->sps_joint_cbcr_enabled_flag && ((cu->pred_mode == MODE_INTRA &&
373
4/4
✓ Branch 0 taken 784513 times.
✓ Branch 1 taken 102635 times.
✓ Branch 2 taken 761152 times.
✓ Branch 3 taken 23361 times.
887148 (tu->coded_flag[CB] || tu->coded_flag[CR])) ||
374
5/6
✓ Branch 0 taken 55363 times.
✓ Branch 1 taken 910929 times.
✓ Branch 2 taken 23815 times.
✓ Branch 3 taken 31548 times.
✓ Branch 4 taken 149811 times.
✗ Branch 5 not taken.
1092288 (tu->coded_flag[CB] && tu->coded_flag[CR])) &&
375 chroma_available) {
376 149811 tu->joint_cbcr_residual_flag = ff_vvc_tu_joint_cbcr_residual_flag(lc, tu->coded_flag[1], tu->coded_flag[2]);
377 }
378
379
2/2
✓ Branch 0 taken 1817129 times.
✓ Branch 1 taken 1135492 times.
2952621 for (int i = 0; i < tu->nb_tbs; i++) {
380 1817129 TransformBlock *tb = &tu->tbs[i];
381 1817129 const int is_chroma = tb->c_idx != LUMA;
382 1817129 tb->has_coeffs = tu->coded_flag[tb->c_idx];
383
4/4
✓ Branch 0 taken 981887 times.
✓ Branch 1 taken 835242 times.
✓ Branch 2 taken 284468 times.
✓ Branch 3 taken 697419 times.
1817129 if (tb->has_coeffs && is_chroma)
384
6/6
✓ Branch 0 taken 121080 times.
✓ Branch 1 taken 163388 times.
✓ Branch 2 taken 92285 times.
✓ Branch 3 taken 28795 times.
✓ Branch 4 taken 62512 times.
✓ Branch 5 taken 29773 times.
284468 tb->has_coeffs = tb->c_idx == CB ? 1 : !(tu->coded_flag[CB] && tu->joint_cbcr_residual_flag);
385
2/2
✓ Branch 0 taken 952114 times.
✓ Branch 1 taken 865015 times.
1817129 if (tb->has_coeffs) {
386 952114 tb->ts = cu->bdpcm_flag[tb->c_idx];
387
4/4
✓ Branch 0 taken 834486 times.
✓ Branch 1 taken 117628 times.
✓ Branch 2 taken 834476 times.
✓ Branch 3 taken 10 times.
952114 if (sps->r->sps_transform_skip_enabled_flag && !cu->bdpcm_flag[tb->c_idx] &&
388
4/4
✓ Branch 0 taken 818090 times.
✓ Branch 1 taken 16386 times.
✓ Branch 2 taken 810921 times.
✓ Branch 3 taken 7169 times.
834476 tb->tb_width <= sps->max_ts_size && tb->tb_height <= sps->max_ts_size &&
389
6/6
✓ Branch 0 taken 771277 times.
✓ Branch 1 taken 39644 times.
✓ Branch 2 taken 594973 times.
✓ Branch 3 taken 176304 times.
✓ Branch 4 taken 461693 times.
✓ Branch 5 taken 133280 times.
810921 !cu->sbt_flag && (is_chroma || !is_isp)) {
390 637997 tb->ts = ff_vvc_transform_skip_flag(lc, is_chroma);
391 }
392 952114 ret = ff_vvc_residual_coding(lc, tb);
393
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 952114 times.
952114 if (ret < 0)
394 return ret;
395 952114 set_tb_tab(fc->tab.tu_coded_flag[tb->c_idx], tu->coded_flag[tb->c_idx], fc, tb);
396
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 865015 times.
865015 } else if (cu->act_enabled_flag) {
397 memset(tb->coeffs, 0, tb->tb_width * tb->tb_height * sizeof(*tb->coeffs));
398 }
399
2/2
✓ Branch 0 taken 1385304 times.
✓ Branch 1 taken 431825 times.
1817129 if (tb->c_idx != CR)
400 1385304 set_tb_size(fc, tb);
401
2/2
✓ Branch 0 taken 431825 times.
✓ Branch 1 taken 1385304 times.
1817129 if (tb->c_idx == CB)
402 431825 set_tb_tab(fc->tab.tu_joint_cbcr_residual_flag, tu->joint_cbcr_residual_flag, fc, tb);
403 }
404
405 1135492 return 0;
406 }
407
408 960051 static int hls_transform_tree(VVCLocalContext *lc, int x0, int y0,int tu_width, int tu_height, int ch_type)
409 {
410 960051 const CodingUnit *cu = lc->cu;
411 960051 const VVCSPS *sps = lc->fc->ps.sps;
412 int ret;
413
414 960051 lc->parse.infer_tu_cbf_luma = 1;
415
4/4
✓ Branch 0 taken 897621 times.
✓ Branch 1 taken 62430 times.
✓ Branch 2 taken 853026 times.
✓ Branch 3 taken 44595 times.
960051 if (cu->isp_split_type == ISP_NO_SPLIT && !cu->sbt_flag) {
416
4/4
✓ Branch 0 taken 843898 times.
✓ Branch 1 taken 9128 times.
✓ Branch 2 taken 1754 times.
✓ Branch 3 taken 842144 times.
863908 if (tu_width > sps->max_tb_size_y || tu_height > sps->max_tb_size_y) {
417
4/4
✓ Branch 0 taken 9128 times.
✓ Branch 1 taken 1754 times.
✓ Branch 2 taken 6596 times.
✓ Branch 3 taken 2532 times.
10882 const int ver_split_first = tu_width > sps->max_tb_size_y && tu_width > tu_height;
418
2/2
✓ Branch 0 taken 6596 times.
✓ Branch 1 taken 4286 times.
10882 const int trafo_width = ver_split_first ? (tu_width / 2) : tu_width;
419
2/2
✓ Branch 0 taken 4286 times.
✓ Branch 1 taken 6596 times.
10882 const int trafo_height = !ver_split_first ? (tu_height / 2) : tu_height;
420
421 #define TRANSFORM_TREE(x, y) do { \
422 ret = hls_transform_tree(lc, x, y, trafo_width, trafo_height, ch_type); \
423 if (ret < 0) \
424 return ret; \
425 } while (0)
426
427
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 10882 times.
10882 TRANSFORM_TREE(x0, y0);
428
2/2
✓ Branch 0 taken 6596 times.
✓ Branch 1 taken 4286 times.
10882 if (ver_split_first)
429
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6596 times.
6596 TRANSFORM_TREE(x0 + trafo_width, y0);
430 else
431
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4286 times.
4286 TRANSFORM_TREE(x0, y0 + trafo_height);
432
433 } else {
434 842144 ret = hls_transform_unit(lc, x0, y0, tu_width, tu_height, 0, ch_type);
435
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 842144 times.
842144 if (ret < 0)
436 return ret;
437
438 }
439
2/2
✓ Branch 0 taken 44595 times.
✓ Branch 1 taken 62430 times.
107025 } else if (cu->sbt_flag) {
440
2/2
✓ Branch 0 taken 23565 times.
✓ Branch 1 taken 21030 times.
44595 if (!cu->sbt_horizontal_flag) {
441 #define TRANSFORM_UNIT(x, width, idx) do { \
442 ret = hls_transform_unit(lc, x, y0, width, tu_height, idx, ch_type); \
443 if (ret < 0) \
444 return ret; \
445 } while (0)
446
447 23565 const int trafo_width = tu_width * lc->parse.sbt_num_fourths_tb0 / 4;
448
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 23565 times.
23565 TRANSFORM_UNIT(x0, trafo_width, 0);
449
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 23565 times.
23565 TRANSFORM_UNIT(x0 + trafo_width, tu_width - trafo_width, 1);
450
451 #undef TRANSFORM_UNIT
452 } else {
453 #define TRANSFORM_UNIT(y, height, idx) do { \
454 ret = hls_transform_unit(lc, x0, y, tu_width, height, idx, ch_type); \
455 if (ret < 0) \
456 return ret; \
457 } while (0)
458
459 21030 const int trafo_height = tu_height * lc->parse.sbt_num_fourths_tb0 / 4;
460
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 21030 times.
21030 TRANSFORM_UNIT(y0, trafo_height, 0);
461
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 21030 times.
21030 TRANSFORM_UNIT(y0 + trafo_height, tu_height - trafo_height, 1);
462
463 #undef TRANSFORM_UNIT
464 }
465
2/2
✓ Branch 0 taken 38604 times.
✓ Branch 1 taken 23826 times.
62430 } else if (cu->isp_split_type == ISP_HOR_SPLIT) {
466 38604 const int trafo_height = tu_height / cu->num_intra_subpartitions;
467
2/2
✓ Branch 0 taken 129978 times.
✓ Branch 1 taken 38604 times.
168582 for (int i = 0; i < cu->num_intra_subpartitions; i++) {
468 129978 ret = hls_transform_unit(lc, x0, y0 + trafo_height * i, tu_width, trafo_height, i, 0);
469
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 129978 times.
129978 if (ret < 0)
470 return ret;
471 }
472
1/2
✓ Branch 0 taken 23826 times.
✗ Branch 1 not taken.
23826 } else if (cu->isp_split_type == ISP_VER_SPLIT) {
473 23826 const int trafo_width = tu_width / cu->num_intra_subpartitions;
474
2/2
✓ Branch 0 taken 74180 times.
✓ Branch 1 taken 23826 times.
98006 for (int i = 0; i < cu->num_intra_subpartitions; i++) {
475 74180 ret = hls_transform_unit(lc, x0 + trafo_width * i , y0, trafo_width, tu_height, i, 0);
476
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 74180 times.
74180 if (ret < 0)
477 return ret;
478 }
479 }
480
481 960051 return 0;
482 }
483
484 420262 static int skipped_transform_tree(VVCLocalContext *lc, int x0, int y0,int tu_width, int tu_height)
485 {
486 420262 VVCFrameContext *fc = lc->fc;
487 420262 const CodingUnit *cu = lc->cu;
488 420262 const VVCSPS *sps = fc->ps.sps;
489
490
4/4
✓ Branch 0 taken 359840 times.
✓ Branch 1 taken 60422 times.
✓ Branch 2 taken 2292 times.
✓ Branch 3 taken 357548 times.
482976 if (tu_width > sps->max_tb_size_y || tu_height > sps->max_tb_size_y) {
491
4/4
✓ Branch 0 taken 60422 times.
✓ Branch 1 taken 2292 times.
✓ Branch 2 taken 41002 times.
✓ Branch 3 taken 19420 times.
62714 const int ver_split_first = tu_width > sps->max_tb_size_y && tu_width > tu_height;
492
2/2
✓ Branch 0 taken 41002 times.
✓ Branch 1 taken 21712 times.
62714 const int trafo_width = ver_split_first ? (tu_width / 2) : tu_width;
493
2/2
✓ Branch 0 taken 21712 times.
✓ Branch 1 taken 41002 times.
62714 const int trafo_height = !ver_split_first ? (tu_height / 2) : tu_height;
494
495 #define SKIPPED_TRANSFORM_TREE(x, y) do { \
496 int ret = skipped_transform_tree(lc, x, y, trafo_width, trafo_height); \
497 if (ret < 0) \
498 return ret; \
499 } while (0)
500
501
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 62714 times.
62714 SKIPPED_TRANSFORM_TREE(x0, y0);
502
2/2
✓ Branch 0 taken 41002 times.
✓ Branch 1 taken 21712 times.
62714 if (ver_split_first)
503
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 41002 times.
41002 SKIPPED_TRANSFORM_TREE(x0 + trafo_width, y0);
504 else
505
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 21712 times.
21712 SKIPPED_TRANSFORM_TREE(x0, y0 + trafo_height);
506 } else {
507 357548 TransformUnit *tu = add_tu(fc, lc->cu, x0, y0, tu_width, tu_height);
508 int start, end;
509
510
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 357548 times.
357548 if (!tu)
511 return AVERROR_INVALIDDATA;
512 357548 ff_vvc_channel_range(&start, &end, cu->tree_type, sps->r->sps_chroma_format_idc);
513
2/2
✓ Branch 0 taken 987894 times.
✓ Branch 1 taken 357548 times.
1345442 for (int i = start; i < end; i++) {
514 987894 TransformBlock *tb = add_tb(tu, lc, x0, y0, tu_width >> sps->hshift[i], tu_height >> sps->vshift[i], i);
515
2/2
✓ Branch 0 taken 672721 times.
✓ Branch 1 taken 315173 times.
987894 if (i != CR)
516 672721 set_tb_size(fc, tb);
517 }
518 }
519
520 420262 return 0;
521 }
522
523 //6.4.1 Allowed quad split process
524 //6.4.2 Allowed binary split process
525 //6.4.3 Allowed ternary split process
526 2032313 static void can_split(const VVCLocalContext *lc, int x0, int y0,int cb_width, int cb_height,
527 int mtt_depth, int depth_offset, int part_idx, VVCSplitMode last_split_mode,
528 VVCTreeType tree_type, VVCModeType mode_type, VVCAllowedSplit* split)
529 {
530 int min_qt_size, max_bt_size, max_tt_size, max_mtt_depth;
531 2032313 const VVCFrameContext *fc = lc->fc;
532 2032313 const VVCSH *sh = &lc->sc->sh;
533 2032313 const VVCSPS *sps = fc->ps.sps;
534 2032313 const VVCPPS *pps = fc->ps.pps;
535 2032313 const int chroma = tree_type == DUAL_TREE_CHROMA;
536 2032313 int min_cb_size_y = sps->min_cb_size_y;
537 2032313 int *qt = &split->qt;
538 2032313 int *btv = &split->btv;
539 2032313 int *bth = &split->bth;
540 2032313 int *ttv = &split->ttv;
541 2032313 int *tth = &split->tth;
542
543 2032313 *qt = *bth = *btv = *tth = *ttv = 1;
544
545
2/2
✓ Branch 0 taken 1565520 times.
✓ Branch 1 taken 466793 times.
2032313 if (mtt_depth)
546 1565520 *qt = 0;
547
548 2032313 min_qt_size = sh->min_qt_size[chroma];
549
2/2
✓ Branch 0 taken 861016 times.
✓ Branch 1 taken 1171297 times.
2032313 if (cb_width <= min_qt_size)
550 861016 *qt = 0;
551
552
2/2
✓ Branch 0 taken 283472 times.
✓ Branch 1 taken 1748841 times.
2032313 if (chroma) {
553 283472 int chroma_area = (cb_width >> sps->hshift[1]) * (cb_height >> sps->vshift[1]);
554 283472 int chroma_width = cb_width >> sps->hshift[1];
555
556
2/2
✓ Branch 0 taken 87516 times.
✓ Branch 1 taken 195956 times.
283472 if (chroma_width == 8)
557 87516 *ttv = 0;
558
2/2
✓ Branch 0 taken 69640 times.
✓ Branch 1 taken 126316 times.
195956 else if (chroma_width <= 4) {
559
1/2
✓ Branch 0 taken 69640 times.
✗ Branch 1 not taken.
69640 if (chroma_width == 4)
560 69640 *btv = 0;
561 69640 *qt = 0;
562 }
563
2/2
✓ Branch 0 taken 24495 times.
✓ Branch 1 taken 258977 times.
283472 if (mode_type == MODE_TYPE_INTRA)
564 24495 *qt = *btv = *bth = *ttv = *tth = 0;
565
2/2
✓ Branch 0 taken 103159 times.
✓ Branch 1 taken 180313 times.
283472 if (chroma_area <= 32) {
566 103159 *ttv = *tth = 0;
567
2/2
✓ Branch 0 taken 47232 times.
✓ Branch 1 taken 55927 times.
103159 if (chroma_area <= 16)
568 47232 *btv = *bth = 0;
569 }
570 }
571 2032313 max_bt_size = sh->max_bt_size[chroma];
572 2032313 max_tt_size = sh->max_tt_size[chroma];
573 2032313 max_mtt_depth = sh->max_mtt_depth[chroma] + depth_offset;
574
575
2/2
✓ Branch 0 taken 68840 times.
✓ Branch 1 taken 1963473 times.
2032313 if (mode_type == MODE_TYPE_INTER) {
576 68840 int area = cb_width * cb_height;
577
2/2
✓ Branch 0 taken 28596 times.
✓ Branch 1 taken 40244 times.
68840 if (area == 32)
578 28596 *btv = *bth = 0;
579
2/2
✓ Branch 0 taken 23813 times.
✓ Branch 1 taken 16431 times.
40244 else if (area == 64)
580 23813 *ttv = *tth = 0;
581 }
582
2/2
✓ Branch 0 taken 843499 times.
✓ Branch 1 taken 1188814 times.
2032313 if (cb_width <= 2 * min_cb_size_y) {
583 843499 *ttv = 0;
584
2/2
✓ Branch 0 taken 321924 times.
✓ Branch 1 taken 521575 times.
843499 if (cb_width <= min_cb_size_y)
585 321924 *btv = 0;
586 }
587
2/2
✓ Branch 0 taken 918314 times.
✓ Branch 1 taken 1113999 times.
2032313 if (cb_height <= 2 * min_cb_size_y) {
588 918314 *tth = 0;
589
2/2
✓ Branch 0 taken 368841 times.
✓ Branch 1 taken 549473 times.
918314 if (cb_height <= min_cb_size_y)
590 368841 *bth = 0;
591 }
592
4/4
✓ Branch 0 taken 1982200 times.
✓ Branch 1 taken 50113 times.
✓ Branch 2 taken 705 times.
✓ Branch 3 taken 1981495 times.
2032313 if (cb_width > max_bt_size || cb_height > max_bt_size)
593 50818 *btv = *bth = 0;
594 2032313 max_tt_size = FFMIN(64, max_tt_size);
595
4/4
✓ Branch 0 taken 1912096 times.
✓ Branch 1 taken 120217 times.
✓ Branch 2 taken 8480 times.
✓ Branch 3 taken 1903616 times.
2032313 if (cb_width > max_tt_size || cb_height > max_tt_size)
596 128697 *ttv = *tth = 0;
597
2/2
✓ Branch 0 taken 410102 times.
✓ Branch 1 taken 1622211 times.
2032313 if (mtt_depth >= max_mtt_depth)
598 410102 *btv = *bth = *ttv = *tth = 0;
599
2/2
✓ Branch 0 taken 4664 times.
✓ Branch 1 taken 2027649 times.
2032313 if (x0 + cb_width > pps->width) {
600 4664 *ttv = *tth = 0;
601
2/2
✓ Branch 0 taken 1423 times.
✓ Branch 1 taken 3241 times.
4664 if (cb_height > 64)
602 1423 *btv = 0;
603
2/2
✓ Branch 0 taken 3465 times.
✓ Branch 1 taken 1199 times.
4664 if (y0 + cb_height <= pps->height)
604 3465 *bth = 0;
605
2/2
✓ Branch 0 taken 1145 times.
✓ Branch 1 taken 54 times.
1199 else if (cb_width > min_qt_size)
606 1145 *btv = *bth = 0;
607 }
608
2/2
✓ Branch 0 taken 49171 times.
✓ Branch 1 taken 1983142 times.
2032313 if (y0 + cb_height > pps->height) {
609 49171 *btv = *ttv = *tth = 0;
610
2/2
✓ Branch 0 taken 6244 times.
✓ Branch 1 taken 42927 times.
49171 if (cb_width > 64)
611 6244 *bth = 0;
612 }
613
4/4
✓ Branch 0 taken 1565520 times.
✓ Branch 1 taken 466793 times.
✓ Branch 2 taken 680575 times.
✓ Branch 3 taken 884945 times.
2032313 if (mtt_depth > 0 && part_idx == 1) {
614
2/2
✓ Branch 0 taken 80770 times.
✓ Branch 1 taken 599805 times.
680575 if (last_split_mode == SPLIT_TT_VER)
615 80770 *btv = 0;
616
2/2
✓ Branch 0 taken 84349 times.
✓ Branch 1 taken 515456 times.
599805 else if (last_split_mode == SPLIT_TT_HOR)
617 84349 *bth = 0;
618 }
619
4/4
✓ Branch 0 taken 1989228 times.
✓ Branch 1 taken 43085 times.
✓ Branch 2 taken 3288 times.
✓ Branch 3 taken 1985940 times.
2032313 if (cb_width <= 64 && cb_height > 64)
620 3288 *btv = 0;
621
4/4
✓ Branch 0 taken 43085 times.
✓ Branch 1 taken 1989228 times.
✓ Branch 2 taken 3312 times.
✓ Branch 3 taken 39773 times.
2032313 if (cb_width > 64 && cb_height <= 64)
622 3312 *bth = 0;
623 2032313 }
624
625 488624 static int get_num_intra_subpartitions(enum IspType isp_split_type, int cb_width, int cb_height)
626 {
627
2/2
✓ Branch 0 taken 426194 times.
✓ Branch 1 taken 62430 times.
488624 if (isp_split_type == ISP_NO_SPLIT)
628 426194 return 1;
629
8/8
✓ Branch 0 taken 14953 times.
✓ Branch 1 taken 47477 times.
✓ Branch 2 taken 4227 times.
✓ Branch 3 taken 10726 times.
✓ Branch 4 taken 22244 times.
✓ Branch 5 taken 29460 times.
✓ Branch 6 taken 12055 times.
✓ Branch 7 taken 10189 times.
62430 if ((cb_width == 4 && cb_height == 8) || (cb_width == 8 && cb_height == 4))
630 22781 return 2;
631 39649 return 4;
632 }
633
634 227380 static int get_cclm_enabled(const VVCLocalContext *lc, const int x0, const int y0)
635 {
636 227380 const VVCFrameContext *fc = lc->fc;
637 227380 const VVCSPS *sps = fc->ps.sps;
638 227380 int enabled = 0;
639
640
2/2
✓ Branch 0 taken 449 times.
✓ Branch 1 taken 226931 times.
227380 if (!sps->r->sps_cclm_enabled_flag)
641 449 return 0;
642
6/6
✓ Branch 0 taken 220294 times.
✓ Branch 1 taken 6637 times.
✓ Branch 2 taken 156659 times.
✓ Branch 3 taken 63635 times.
✓ Branch 4 taken 1163 times.
✓ Branch 5 taken 155496 times.
226931 if (!sps->r->sps_qtbtt_dual_tree_intra_flag || !IS_I(lc->sc->sh.r) || sps->ctb_log2_size_y < 6)
643 71435 return 1;
644 else {
645 155496 const int x64 = x0 >> 6 << 6;
646 155496 const int y64 = y0 >> 6 << 6;
647 155496 const int y32 = y0 >> 5 << 5;
648 155496 const int x64_cu = x64 >> fc->ps.sps->min_cb_log2_size_y;
649 155496 const int y64_cu = y64 >> fc->ps.sps->min_cb_log2_size_y;
650 155496 const int y32_cu = y32 >> fc->ps.sps->min_cb_log2_size_y;
651 155496 const int min_cb_width = fc->ps.pps->min_cb_width;
652 155496 const int depth = SAMPLE_CTB(fc->tab.cqt_depth[1], x64_cu, y64_cu);
653 155496 const int min_depth = fc->ps.sps->ctb_log2_size_y - 6;
654 155496 const VVCSplitMode msm64 = (VVCSplitMode)TAB_MSM(fc, 0, x64, y64);
655 155496 const VVCSplitMode msm32 = (VVCSplitMode)TAB_MSM(fc, 1, x64, y32);
656
657
2/2
✓ Branch 0 taken 19353 times.
✓ Branch 1 taken 136143 times.
174849 enabled = SAMPLE_CTB(fc->tab.cb_width[1], x64_cu, y64_cu) == 64 &&
658
2/2
✓ Branch 0 taken 6523 times.
✓ Branch 1 taken 12830 times.
19353 SAMPLE_CTB(fc->tab.cb_height[1], x64_cu, y64_cu) == 64;
659
2/2
✓ Branch 0 taken 21626 times.
✓ Branch 1 taken 16231 times.
37857 enabled |= depth == min_depth && msm64 == SPLIT_BT_HOR &&
660
4/4
✓ Branch 0 taken 37857 times.
✓ Branch 1 taken 117639 times.
✓ Branch 2 taken 12074 times.
✓ Branch 3 taken 9552 times.
205427 SAMPLE_CTB(fc->tab.cb_width[1], x64_cu, y32_cu) == 64 &&
661
2/2
✓ Branch 0 taken 4732 times.
✓ Branch 1 taken 7342 times.
12074 SAMPLE_CTB(fc->tab.cb_height[1], x64_cu, y32_cu) == 32;
662 155496 enabled |= depth > min_depth;
663
6/6
✓ Branch 0 taken 37857 times.
✓ Branch 1 taken 117639 times.
✓ Branch 2 taken 21626 times.
✓ Branch 3 taken 16231 times.
✓ Branch 4 taken 7960 times.
✓ Branch 5 taken 13666 times.
155496 enabled |= depth == min_depth && msm64 == SPLIT_BT_HOR && msm32 == SPLIT_BT_VER;
664
665
2/2
✓ Branch 0 taken 136397 times.
✓ Branch 1 taken 19099 times.
155496 if (enabled) {
666 136397 const int w = SAMPLE_CTB(fc->tab.cb_width[0], x64_cu, y64_cu);
667 136397 const int h = SAMPLE_CTB(fc->tab.cb_height[0], x64_cu, y64_cu);
668 136397 const int depth0 = SAMPLE_CTB(fc->tab.cqt_depth[0], x64_cu, y64_cu);
669
8/8
✓ Branch 0 taken 5746 times.
✓ Branch 1 taken 130651 times.
✓ Branch 2 taken 5556 times.
✓ Branch 3 taken 190 times.
✓ Branch 4 taken 4964 times.
✓ Branch 5 taken 592 times.
✓ Branch 6 taken 5154 times.
✓ Branch 7 taken 130651 times.
136397 if ((w == 64 && h == 64 && TAB_ISPMF(fc, x64, y64)) ||
670
4/4
✓ Branch 0 taken 190 times.
✓ Branch 1 taken 4964 times.
✓ Branch 2 taken 1286 times.
✓ Branch 3 taken 129555 times.
135805 ((w < 64 || h < 64) && depth0 == min_depth))
671 1878 return 0;
672 }
673
674 }
675
676 153618 return enabled;
677 }
678
679 869848 static int less(const void *a, const void *b)
680 {
681 869848 return *(const int*)a - *(const int*)b;
682 }
683
684 //8.4.2 Derivation process for luma intra prediction mode
685 488624 static enum IntraPredMode luma_intra_pred_mode(VVCLocalContext* lc, const int intra_subpartitions_mode_flag)
686 {
687 488624 VVCFrameContext *fc = lc->fc;
688 488624 CodingUnit *cu = lc->cu;
689 488624 const int x0 = cu->x0;
690 488624 const int y0 = cu->y0;
691 enum IntraPredMode pred;
692 488624 int intra_luma_not_planar_flag = 1;
693 488624 int intra_luma_mpm_remainder = 0;
694 488624 int intra_luma_mpm_flag = 1;
695 488624 int intra_luma_mpm_idx = 0;
696
697
2/2
✓ Branch 0 taken 445157 times.
✓ Branch 1 taken 43467 times.
488624 if (!cu->intra_luma_ref_idx)
698 445157 intra_luma_mpm_flag = ff_vvc_intra_luma_mpm_flag(lc);
699
2/2
✓ Branch 0 taken 364641 times.
✓ Branch 1 taken 123983 times.
488624 if (intra_luma_mpm_flag) {
700
2/2
✓ Branch 0 taken 321174 times.
✓ Branch 1 taken 43467 times.
364641 if (!cu->intra_luma_ref_idx)
701 321174 intra_luma_not_planar_flag = ff_vvc_intra_luma_not_planar_flag(lc, intra_subpartitions_mode_flag);
702
2/2
✓ Branch 0 taken 192694 times.
✓ Branch 1 taken 171947 times.
364641 if (intra_luma_not_planar_flag)
703 192694 intra_luma_mpm_idx = ff_vvc_intra_luma_mpm_idx(lc);
704 } else {
705 123983 intra_luma_mpm_remainder = ff_vvc_intra_luma_mpm_remainder(lc);
706 }
707
708
2/2
✓ Branch 0 taken 171947 times.
✓ Branch 1 taken 316677 times.
488624 if (!intra_luma_not_planar_flag) {
709 171947 pred = INTRA_PLANAR;
710 } else {
711 316677 const VVCSPS *sps = fc->ps.sps;
712 316677 const int x_a = (x0 - 1) >> sps->min_cb_log2_size_y;
713 316677 const int y_a = (y0 + cu->cb_height - 1) >> sps->min_cb_log2_size_y;
714 316677 const int x_b = (x0 + cu->cb_width - 1) >> sps->min_cb_log2_size_y;
715 316677 const int y_b = (y0 - 1) >> sps->min_cb_log2_size_y;
716 316677 int min_cb_width = fc->ps.pps->min_cb_width;
717 316677 int x0b = av_zero_extend(x0, sps->ctb_log2_size_y);
718 316677 int y0b = av_zero_extend(y0, sps->ctb_log2_size_y);
719
4/4
✓ Branch 0 taken 71911 times.
✓ Branch 1 taken 244766 times.
✓ Branch 2 taken 66074 times.
✓ Branch 3 taken 5837 times.
316677 const int available_l = lc->ctb_left_flag || x0b;
720
4/4
✓ Branch 0 taken 112492 times.
✓ Branch 1 taken 204185 times.
✓ Branch 2 taken 106251 times.
✓ Branch 3 taken 6241 times.
316677 const int available_u = lc->ctb_up_flag || y0b;
721
722 int a, b, cand[5];
723
724
4/4
✓ Branch 0 taken 310840 times.
✓ Branch 1 taken 5837 times.
✓ Branch 2 taken 280499 times.
✓ Branch 3 taken 30341 times.
316677 if (!available_l || (SAMPLE_CTB(fc->tab.cpm[0], x_a, y_a) != MODE_INTRA) ||
725
2/2
✓ Branch 0 taken 38866 times.
✓ Branch 1 taken 241633 times.
280499 SAMPLE_CTB(fc->tab.imf, x_a, y_a)) {
726 75044 a = INTRA_PLANAR;
727 } else {
728 241633 a = SAMPLE_CTB(fc->tab.ipm, x_a, y_a);
729 }
730
731
4/4
✓ Branch 0 taken 310436 times.
✓ Branch 1 taken 6241 times.
✓ Branch 2 taken 278295 times.
✓ Branch 3 taken 32141 times.
316677 if (!available_u || (SAMPLE_CTB(fc->tab.cpm[0], x_b, y_b) != MODE_INTRA) ||
732
4/4
✓ Branch 0 taken 239234 times.
✓ Branch 1 taken 39061 times.
✓ Branch 2 taken 14035 times.
✓ Branch 3 taken 225199 times.
278295 SAMPLE_CTB(fc->tab.imf, x_b, y_b) || !y0b) {
733 91478 b = INTRA_PLANAR;
734 } else {
735 225199 b = SAMPLE_CTB(fc->tab.ipm, x_b, y_b);
736 }
737
738
4/4
✓ Branch 0 taken 98311 times.
✓ Branch 1 taken 218366 times.
✓ Branch 2 taken 18571 times.
✓ Branch 3 taken 79740 times.
316677 if (a == b && a > INTRA_DC) {
739 18571 cand[0] = a;
740 18571 cand[1] = 2 + ((a + 61) % 64);
741 18571 cand[2] = 2 + ((a - 1) % 64);
742 18571 cand[3] = 2 + ((a + 60) % 64);
743 18571 cand[4] = 2 + (a % 64);
744 } else {
745 298106 const int minab = FFMIN(a, b);
746 298106 const int maxab = FFMAX(a, b);
747
4/4
✓ Branch 0 taken 143723 times.
✓ Branch 1 taken 154383 times.
✓ Branch 2 taken 71154 times.
✓ Branch 3 taken 72569 times.
369260 if (a > INTRA_DC && b > INTRA_DC) {
748 71154 const int diff = maxab - minab;
749 71154 cand[0] = a;
750 71154 cand[1] = b;
751
2/2
✓ Branch 0 taken 14150 times.
✓ Branch 1 taken 57004 times.
71154 if (diff == 1) {
752 14150 cand[2] = 2 + ((minab + 61) % 64);
753 14150 cand[3] = 2 + ((maxab - 1) % 64);
754 14150 cand[4] = 2 + ((minab + 60) % 64);
755
2/2
✓ Branch 0 taken 574 times.
✓ Branch 1 taken 56430 times.
57004 } else if (diff >= 62) {
756 574 cand[2] = 2 + ((minab - 1) % 64);
757 574 cand[3] = 2 + ((maxab + 61) % 64);
758 574 cand[4] = 2 + (minab % 64);
759
2/2
✓ Branch 0 taken 6773 times.
✓ Branch 1 taken 49657 times.
56430 } else if (diff == 2) {
760 6773 cand[2] = 2 + ((minab - 1) % 64);
761 6773 cand[3] = 2 + ((minab + 61) % 64);
762 6773 cand[4] = 2 + ((maxab - 1) % 64);
763 } else {
764 49657 cand[2] = 2 + ((minab + 61) % 64);
765 49657 cand[3] = 2 + ((minab - 1) % 64);
766 49657 cand[4] = 2 + ((maxab + 61) % 64);
767 }
768
4/4
✓ Branch 0 taken 154383 times.
✓ Branch 1 taken 72569 times.
✓ Branch 2 taken 60018 times.
✓ Branch 3 taken 94365 times.
226952 } else if (a > INTRA_DC || b > INTRA_DC) {
769 132587 cand[0] = maxab;
770 132587 cand[1] = 2 + ((maxab + 61 ) % 64);
771 132587 cand[2] = 2 + ((maxab - 1) % 64);
772 132587 cand[3] = 2 + ((maxab + 60 ) % 64);
773 132587 cand[4] = 2 + (maxab % 64);
774 } else {
775 94365 cand[0] = INTRA_DC;
776 94365 cand[1] = INTRA_VERT;
777 94365 cand[2] = INTRA_HORZ;
778 94365 cand[3] = INTRA_VERT - 4;
779 94365 cand[4] = INTRA_VERT + 4;
780 }
781 }
782
2/2
✓ Branch 0 taken 192694 times.
✓ Branch 1 taken 123983 times.
316677 if (intra_luma_mpm_flag) {
783 192694 pred = cand[intra_luma_mpm_idx];
784 } else {
785 123983 qsort(cand, FF_ARRAY_ELEMS(cand), sizeof(cand[0]), less);
786 123983 pred = intra_luma_mpm_remainder + 1;
787
2/2
✓ Branch 0 taken 619915 times.
✓ Branch 1 taken 123983 times.
743898 for (int i = 0; i < FF_ARRAY_ELEMS(cand); i++) {
788
2/2
✓ Branch 0 taken 304054 times.
✓ Branch 1 taken 315861 times.
619915 if (pred >= cand[i])
789 304054 pred++;
790 }
791 }
792 }
793 488624 return pred;
794 }
795
796 938287 static int lfnst_idx_decode(VVCLocalContext *lc)
797 {
798 938287 CodingUnit *cu = lc->cu;
799 938287 const VVCTreeType tree_type = cu->tree_type;
800 938287 const VVCSPS *sps = lc->fc->ps.sps;
801 938287 const int cb_width = cu->cb_width;
802 938287 const int cb_height = cu->cb_height;
803 938287 const TransformUnit *tu = cu->tus.head;
804 int lfnst_width, lfnst_height, min_lfnst;
805 938287 int lfnst_idx = 0;
806
807 938287 memset(cu->apply_lfnst_flag, 0, sizeof(cu->apply_lfnst_flag));
808
809
6/6
✓ Branch 0 taken 714720 times.
✓ Branch 1 taken 223567 times.
✓ Branch 2 taken 598709 times.
✓ Branch 3 taken 116011 times.
✓ Branch 4 taken 1674 times.
✓ Branch 5 taken 597035 times.
938287 if (!sps->r->sps_lfnst_enabled_flag || cu->pred_mode != MODE_INTRA || FFMAX(cb_width, cb_height) > sps->max_tb_size_y)
810 341252 return 0;
811
812
2/2
✓ Branch 0 taken 704882 times.
✓ Branch 1 taken 582963 times.
1287845 while (tu) {
813
2/2
✓ Branch 0 taken 914754 times.
✓ Branch 1 taken 690810 times.
1605564 for (int j = 0; j < tu->nb_tbs; j++) {
814 914754 const TransformBlock *tb = tu->tbs + j;
815
4/4
✓ Branch 0 taken 595721 times.
✓ Branch 1 taken 319033 times.
✓ Branch 2 taken 14072 times.
✓ Branch 3 taken 581649 times.
914754 if (tu->coded_flag[tb->c_idx] && tb->ts)
816 14072 return 0;
817 }
818 690810 tu = tu->next;
819 }
820
821
2/2
✓ Branch 0 taken 141633 times.
✓ Branch 1 taken 441330 times.
582963 if (tree_type == DUAL_TREE_CHROMA) {
822 141633 lfnst_width = cb_width >> sps->hshift[1];
823 141633 lfnst_height = cb_height >> sps->vshift[1];
824 } else {
825 441330 const int vs = cu->isp_split_type == ISP_VER_SPLIT;
826 441330 const int hs = cu->isp_split_type == ISP_HOR_SPLIT;
827
2/2
✓ Branch 0 taken 17361 times.
✓ Branch 1 taken 423969 times.
441330 lfnst_width = vs ? cb_width / cu->num_intra_subpartitions : cb_width;
828
2/2
✓ Branch 0 taken 30328 times.
✓ Branch 1 taken 411002 times.
441330 lfnst_height = hs ? cb_height / cu->num_intra_subpartitions : cb_height;
829 }
830 582963 min_lfnst = FFMIN(lfnst_width, lfnst_height);
831
6/6
✓ Branch 0 taken 441330 times.
✓ Branch 1 taken 141633 times.
✓ Branch 2 taken 104237 times.
✓ Branch 3 taken 337093 times.
✓ Branch 4 taken 84256 times.
✓ Branch 5 taken 19981 times.
582963 if (tree_type != DUAL_TREE_CHROMA && cu->intra_mip_flag && min_lfnst < 16)
832 84256 return 0;
833
834
2/2
✓ Branch 0 taken 461266 times.
✓ Branch 1 taken 37441 times.
498707 if (min_lfnst >= 4) {
835
6/6
✓ Branch 0 taken 433725 times.
✓ Branch 1 taken 27541 times.
✓ Branch 2 taken 187714 times.
✓ Branch 3 taken 246011 times.
✓ Branch 4 taken 182927 times.
✓ Branch 5 taken 32328 times.
461266 if ((cu->isp_split_type != ISP_NO_SPLIT || !lc->parse.lfnst_dc_only) && lc->parse.lfnst_zero_out_sig_coeff_flag)
836 182927 lfnst_idx = ff_vvc_lfnst_idx(lc, tree_type != SINGLE_TREE);
837 }
838
839
2/2
✓ Branch 0 taken 138114 times.
✓ Branch 1 taken 360593 times.
498707 if (lfnst_idx) {
840 138114 cu->apply_lfnst_flag[LUMA] = tree_type != DUAL_TREE_CHROMA;
841 138114 cu->apply_lfnst_flag[CB] = cu->apply_lfnst_flag[CR] = tree_type == DUAL_TREE_CHROMA;
842 }
843
844 498707 return lfnst_idx;
845 }
846
847 938287 static MtsIdx mts_idx_decode(VVCLocalContext *lc)
848 {
849 938287 const CodingUnit *cu = lc->cu;
850 938287 const VVCSPS *sps = lc->fc->ps.sps;
851 938287 const int cb_width = cu->cb_width;
852 938287 const int cb_height = cu->cb_height;
853 938287 const uint8_t transform_skip_flag = cu->tus.head->tbs[0].ts; //fix me
854 938287 int mts_idx = MTS_DCT2_DCT2;
855
6/6
✓ Branch 0 taken 757130 times.
✓ Branch 1 taken 181157 times.
✓ Branch 2 taken 652739 times.
✓ Branch 3 taken 104391 times.
✓ Branch 4 taken 627306 times.
✓ Branch 5 taken 25433 times.
938287 if (cu->tree_type != DUAL_TREE_CHROMA && !cu->lfnst_idx &&
856
2/2
✓ Branch 0 taken 605721 times.
✓ Branch 1 taken 21585 times.
627306 !transform_skip_flag && FFMAX(cb_width, cb_height) <= 32 &&
857
4/4
✓ Branch 0 taken 560202 times.
✓ Branch 1 taken 45519 times.
✓ Branch 2 taken 517144 times.
✓ Branch 3 taken 43058 times.
605721 cu->isp_split_type == ISP_NO_SPLIT && !cu->sbt_flag &&
858
4/4
✓ Branch 0 taken 508291 times.
✓ Branch 1 taken 8853 times.
✓ Branch 2 taken 324171 times.
✓ Branch 3 taken 184120 times.
517144 lc->parse.mts_zero_out_sig_coeff_flag && !lc->parse.mts_dc_only) {
859
4/4
✓ Branch 0 taken 57155 times.
✓ Branch 1 taken 267016 times.
✓ Branch 2 taken 54689 times.
✓ Branch 3 taken 2466 times.
324171 if ((cu->pred_mode == MODE_INTER && sps->r->sps_explicit_mts_inter_enabled_flag) ||
860
4/4
✓ Branch 0 taken 263522 times.
✓ Branch 1 taken 58183 times.
✓ Branch 2 taken 244531 times.
✓ Branch 3 taken 18991 times.
321705 (cu->pred_mode == MODE_INTRA && sps->r->sps_explicit_mts_intra_enabled_flag)) {
861 246997 mts_idx = ff_vvc_mts_idx(lc);
862 }
863 }
864
865 938287 return mts_idx;
866 }
867
868 227236 static enum IntraPredMode derive_center_luma_intra_pred_mode(const VVCFrameContext *fc, const VVCSPS *sps, const VVCPPS *pps, const CodingUnit *cu)
869 {
870 227236 const int x_center = (cu->x0 + cu->cb_width / 2) >> sps->min_cb_log2_size_y;
871 227236 const int y_center = (cu->y0 + cu->cb_height / 2) >> sps->min_cb_log2_size_y;
872 227236 const int min_cb_width = pps->min_cb_width;
873 227236 const int intra_mip_flag = SAMPLE_CTB(fc->tab.imf, x_center, y_center);
874 227236 const int cu_pred_mode = SAMPLE_CTB(fc->tab.cpm[0], x_center, y_center);
875 227236 const int intra_pred_mode_y = SAMPLE_CTB(fc->tab.ipm, x_center, y_center);
876
877
2/2
✓ Branch 0 taken 46556 times.
✓ Branch 1 taken 180680 times.
227236 if (intra_mip_flag) {
878
4/4
✓ Branch 0 taken 9274 times.
✓ Branch 1 taken 37282 times.
✓ Branch 2 taken 244 times.
✓ Branch 3 taken 9030 times.
46556 if (cu->tree_type == SINGLE_TREE && sps->r->sps_chroma_format_idc == CHROMA_FORMAT_444)
879 244 return INTRA_INVALID;
880 46312 return INTRA_PLANAR;
881 }
882
3/4
✓ Branch 0 taken 173282 times.
✓ Branch 1 taken 7398 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 173282 times.
180680 if (cu_pred_mode == MODE_IBC || cu_pred_mode == MODE_PLT)
883 7398 return INTRA_DC;
884 173282 return intra_pred_mode_y;
885 }
886
887 227380 static void derive_chroma_intra_pred_mode(VVCLocalContext *lc,
888 const int cclm_mode_flag, const int cclm_mode_idx, const int intra_chroma_pred_mode)
889 {
890 227380 const VVCFrameContext *fc = lc->fc;
891 227380 CodingUnit *cu = lc->cu;
892 227380 const VVCSPS *sps = fc->ps.sps;
893 227380 const VVCPPS *pps = fc->ps.pps;
894 227380 const int x_cb = cu->x0 >> sps->min_cb_log2_size_y;
895 227380 const int y_cb = cu->y0 >> sps->min_cb_log2_size_y;
896 227380 const int min_cb_width = pps->min_cb_width;
897 227380 const int intra_mip_flag = SAMPLE_CTB(fc->tab.imf, x_cb, y_cb);
898 227380 enum IntraPredMode luma_intra_pred_mode = SAMPLE_CTB(fc->tab.ipm, x_cb, y_cb);
899
900
6/6
✓ Branch 0 taken 46226 times.
✓ Branch 1 taken 181154 times.
✓ Branch 2 taken 2125 times.
✓ Branch 3 taken 44101 times.
✓ Branch 4 taken 1446 times.
✓ Branch 5 taken 679 times.
227380 if (cu->tree_type == SINGLE_TREE && sps->r->sps_chroma_format_idc == CHROMA_FORMAT_444 &&
901
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1446 times.
✓ Branch 2 taken 144 times.
✓ Branch 3 taken 535 times.
2125 (intra_chroma_pred_mode == 4 || cu->act_enabled_flag) && intra_mip_flag) {
902 144 cu->mip_chroma_direct_flag = 1;
903 144 cu->intra_pred_mode_c = luma_intra_pred_mode;
904 144 return;
905 }
906 227236 luma_intra_pred_mode = derive_center_luma_intra_pred_mode(fc, sps, pps, cu);
907
908
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 227236 times.
227236 if (cu->act_enabled_flag) {
909 cu->intra_pred_mode_c = luma_intra_pred_mode;
910 return;
911 }
912
2/2
✓ Branch 0 taken 91531 times.
✓ Branch 1 taken 135705 times.
227236 if (cclm_mode_flag) {
913 91531 cu->intra_pred_mode_c = INTRA_LT_CCLM + cclm_mode_idx;
914
2/2
✓ Branch 0 taken 92693 times.
✓ Branch 1 taken 43012 times.
135705 } else if (intra_chroma_pred_mode == 4){
915 92693 cu->intra_pred_mode_c = luma_intra_pred_mode;
916 } else {
917 const static IntraPredMode pred_mode_c[][4 + 1] = {
918 {INTRA_VDIAG, INTRA_PLANAR, INTRA_PLANAR, INTRA_PLANAR, INTRA_PLANAR},
919 {INTRA_VERT, INTRA_VDIAG, INTRA_VERT, INTRA_VERT, INTRA_VERT},
920 {INTRA_HORZ, INTRA_HORZ, INTRA_VDIAG, INTRA_HORZ, INTRA_HORZ},
921 {INTRA_DC, INTRA_DC, INTRA_DC, INTRA_VDIAG, INTRA_DC},
922 };
923 43012 const int modes[4] = {INTRA_PLANAR, INTRA_VERT, INTRA_HORZ, INTRA_DC};
924 int idx;
925
926 // This workaround is necessary to have 4:4:4 video decode correctly
927 // See VVC ticket https://jvet.hhi.fraunhofer.de/trac/vvc/ticket/1602
928 // and VTM source https://vcgit.hhi.fraunhofer.de/jvet/VVCSoftware_VTM/-/blob/master/source/Lib/CommonLib/UnitTools.cpp#L736
929
6/6
✓ Branch 0 taken 3283 times.
✓ Branch 1 taken 39729 times.
✓ Branch 2 taken 243 times.
✓ Branch 3 taken 3040 times.
✓ Branch 4 taken 43 times.
✓ Branch 5 taken 200 times.
43012 if (cu->tree_type == SINGLE_TREE && sps->r->sps_chroma_format_idc == CHROMA_FORMAT_444 && intra_mip_flag) {
930 43 idx = 4;
931 } else {
932
2/2
✓ Branch 0 taken 108116 times.
✓ Branch 1 taken 15149 times.
123265 for (idx = 0; idx < FF_ARRAY_ELEMS(modes); idx++) {
933
2/2
✓ Branch 0 taken 27820 times.
✓ Branch 1 taken 80296 times.
108116 if (modes[idx] == luma_intra_pred_mode)
934 27820 break;
935 }
936 }
937
938 43012 cu->intra_pred_mode_c = pred_mode_c[intra_chroma_pred_mode][idx];
939 }
940
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 227236 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
227236 if (sps->r->sps_chroma_format_idc == CHROMA_FORMAT_422 && cu->intra_pred_mode_c <= INTRA_VDIAG) {
941 const static int mode_map_422[INTRA_VDIAG + 1] = {
942 0, 1, 61, 62, 63, 64, 65, 66, 2, 3, 5, 6, 8, 10, 12, 13,
943 14, 16, 18, 20, 22, 23, 24, 26, 28, 30, 31, 33, 34, 35, 36, 37,
944 38, 39, 40, 41, 41, 42, 43, 43, 44, 44, 45, 45, 46, 47, 48, 48,
945 49, 49, 50, 51, 51, 52, 52, 53, 54, 55, 55, 56, 56, 57, 57, 58,
946 59, 59, 60,
947 };
948 cu->intra_pred_mode_c = mode_map_422[cu->intra_pred_mode_c];
949 }
950 }
951
952 288862 static av_always_inline uint8_t pack_mip_info(int intra_mip_flag,
953 int intra_mip_transposed_flag, int intra_mip_mode)
954 {
955 288862 return (intra_mip_mode << 2) | (intra_mip_transposed_flag << 1) | intra_mip_flag;
956 }
957
958 596716 static void intra_luma_pred_modes(VVCLocalContext *lc)
959 {
960 596716 VVCFrameContext *fc = lc->fc;
961 596716 const VVCSPS *sps = fc->ps.sps;
962 596716 const VVCPPS *pps = fc->ps.pps;
963 596716 CodingUnit *cu = lc->cu;
964 596716 const int log2_min_cb_size = sps->min_cb_log2_size_y;
965 596716 const int x0 = cu->x0;
966 596716 const int y0 = cu->y0;
967 596716 const int x_cb = x0 >> log2_min_cb_size;
968 596716 const int y_cb = y0 >> log2_min_cb_size;
969 596716 const int cb_width = cu->cb_width;
970 596716 const int cb_height = cu->cb_height;
971
972 596716 cu->intra_luma_ref_idx = 0;
973
6/6
✓ Branch 0 taken 28688 times.
✓ Branch 1 taken 568028 times.
✓ Branch 2 taken 27889 times.
✓ Branch 3 taken 799 times.
✓ Branch 4 taken 27878 times.
✓ Branch 5 taken 11 times.
596716 if (sps->r->sps_bdpcm_enabled_flag && cb_width <= sps->max_ts_size && cb_height <= sps->max_ts_size)
974 27878 cu->bdpcm_flag[LUMA] = ff_vvc_intra_bdpcm_luma_flag(lc);
975
2/2
✓ Branch 0 taken 38 times.
✓ Branch 1 taken 596678 times.
596716 if (cu->bdpcm_flag[LUMA]) {
976
2/2
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 18 times.
38 cu->intra_pred_mode_y = ff_vvc_intra_bdpcm_luma_dir_flag(lc) ? INTRA_VERT : INTRA_HORZ;
977 } else {
978
2/2
✓ Branch 0 taken 454236 times.
✓ Branch 1 taken 142442 times.
596678 if (sps->r->sps_mip_enabled_flag)
979 454236 cu->intra_mip_flag = ff_vvc_intra_mip_flag(lc, fc->tab.imf);
980
2/2
✓ Branch 0 taken 108054 times.
✓ Branch 1 taken 488624 times.
596678 if (cu->intra_mip_flag) {
981 108054 int intra_mip_transposed_flag = ff_vvc_intra_mip_transposed_flag(lc);
982 108054 int intra_mip_mode = ff_vvc_intra_mip_mode(lc);
983 108054 int x = y_cb * pps->min_cb_width + x_cb;
984
2/2
✓ Branch 0 taken 288862 times.
✓ Branch 1 taken 108054 times.
396916 for (int y = 0; y < (cb_height>>log2_min_cb_size); y++) {
985 288862 int width = cb_width>>log2_min_cb_size;
986 288862 const uint8_t mip_info = pack_mip_info(cu->intra_mip_flag,
987 intra_mip_transposed_flag, intra_mip_mode);
988 288862 memset(&fc->tab.imf[x], mip_info, width);
989 288862 x += pps->min_cb_width;
990 }
991 108054 cu->intra_pred_mode_y = intra_mip_mode;
992 } else {
993 488624 int intra_subpartitions_mode_flag = 0;
994
4/4
✓ Branch 0 taken 469700 times.
✓ Branch 1 taken 18924 times.
✓ Branch 2 taken 430156 times.
✓ Branch 3 taken 39544 times.
488624 if (sps->r->sps_mrl_enabled_flag && ((y0 % sps->ctb_size_y) > 0))
995 430156 cu->intra_luma_ref_idx = ff_vvc_intra_luma_ref_idx(lc);
996
4/4
✓ Branch 0 taken 469700 times.
✓ Branch 1 taken 18924 times.
✓ Branch 2 taken 426233 times.
✓ Branch 3 taken 43467 times.
488624 if (sps->r->sps_isp_enabled_flag && !cu->intra_luma_ref_idx &&
997
4/4
✓ Branch 0 taken 426018 times.
✓ Branch 1 taken 215 times.
✓ Branch 2 taken 425752 times.
✓ Branch 3 taken 266 times.
426233 (cb_width <= sps->max_tb_size_y && cb_height <= sps->max_tb_size_y) &&
998
2/2
✓ Branch 0 taken 362432 times.
✓ Branch 1 taken 63320 times.
425752 (cb_width * cb_height > MIN_TU_SIZE * MIN_TU_SIZE) &&
999
1/2
✓ Branch 0 taken 362432 times.
✗ Branch 1 not taken.
362432 !cu->act_enabled_flag)
1000 362432 intra_subpartitions_mode_flag = ff_vvc_intra_subpartitions_mode_flag(lc);
1001
4/4
✓ Branch 0 taken 95087 times.
✓ Branch 1 taken 393537 times.
✓ Branch 2 taken 20731 times.
✓ Branch 3 taken 74356 times.
488624 if (!(x0 & 63) && !(y0 & 63))
1002 20731 TAB_ISPMF(fc, x0, y0) = intra_subpartitions_mode_flag;
1003 488624 cu->isp_split_type = ff_vvc_isp_split_type(lc, intra_subpartitions_mode_flag);
1004 488624 cu->num_intra_subpartitions = get_num_intra_subpartitions(cu->isp_split_type, cb_width, cb_height);
1005 488624 cu->intra_pred_mode_y = luma_intra_pred_mode(lc, intra_subpartitions_mode_flag);
1006 }
1007 }
1008 596716 set_cb_tab(lc, fc->tab.ipm, cu->intra_pred_mode_y);
1009 596716 }
1010
1011 227383 static void intra_chroma_pred_modes(VVCLocalContext *lc)
1012 {
1013 227383 const VVCSPS *sps = lc->fc->ps.sps;
1014 227383 CodingUnit *cu = lc->cu;
1015 227383 const int hs = sps->hshift[CHROMA];
1016 227383 const int vs = sps->vshift[CHROMA];
1017 227383 int cclm_mode_flag = 0;
1018 227383 int cclm_mode_idx = 0;
1019 227383 int intra_chroma_pred_mode = 0;
1020
1021
1/2
✓ Branch 0 taken 227383 times.
✗ Branch 1 not taken.
227383 if (!cu->act_enabled_flag) {
1022 227383 cu->mip_chroma_direct_flag = 0;
1023
2/2
✓ Branch 0 taken 25937 times.
✓ Branch 1 taken 201446 times.
227383 if (sps->r->sps_bdpcm_enabled_flag &&
1024
2/2
✓ Branch 0 taken 24636 times.
✓ Branch 1 taken 1301 times.
25937 (cu->cb_width >> hs) <= sps->max_ts_size &&
1025
2/2
✓ Branch 0 taken 24174 times.
✓ Branch 1 taken 462 times.
24636 (cu->cb_height >> vs) <= sps->max_ts_size) {
1026 24174 cu->bdpcm_flag[CB] = cu->bdpcm_flag[CR] = ff_vvc_intra_bdpcm_chroma_flag(lc);
1027 }
1028
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 227380 times.
227383 if (cu->bdpcm_flag[CHROMA]) {
1029
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2 times.
3 cu->intra_pred_mode_c = ff_vvc_intra_bdpcm_chroma_dir_flag(lc) ? INTRA_VERT : INTRA_HORZ;
1030 } else {
1031 227380 const int cclm_enabled = get_cclm_enabled(lc, cu->x0, cu->y0);
1032
1033
2/2
✓ Branch 0 taken 205954 times.
✓ Branch 1 taken 21426 times.
227380 if (cclm_enabled)
1034 205954 cclm_mode_flag = ff_vvc_cclm_mode_flag(lc);
1035
1036
2/2
✓ Branch 0 taken 91531 times.
✓ Branch 1 taken 135849 times.
227380 if (cclm_mode_flag)
1037 91531 cclm_mode_idx = ff_vvc_cclm_mode_idx(lc);
1038 else
1039 135849 intra_chroma_pred_mode = ff_vvc_intra_chroma_pred_mode(lc);
1040 }
1041 }
1042
1043
2/2
✓ Branch 0 taken 227380 times.
✓ Branch 1 taken 3 times.
227383 if (!cu->bdpcm_flag[CHROMA])
1044 227380 derive_chroma_intra_pred_mode(lc, cclm_mode_flag, cclm_mode_idx, intra_chroma_pred_mode);
1045 227383 }
1046
1047 1233121 static PredMode pred_mode_decode(VVCLocalContext *lc,
1048 const VVCTreeType tree_type,
1049 const VVCModeType mode_type)
1050 {
1051 1233121 const VVCFrameContext *fc = lc->fc;
1052 1233121 CodingUnit *cu = lc->cu;
1053 1233121 const VVCSPS *sps = fc->ps.sps;
1054 1233121 const H266RawSliceHeader *rsh = lc->sc->sh.r;
1055 1233121 const int ch_type = tree_type == DUAL_TREE_CHROMA ? 1 : 0;
1056
4/4
✓ Branch 0 taken 276313 times.
✓ Branch 1 taken 956808 times.
✓ Branch 2 taken 118920 times.
✓ Branch 3 taken 157393 times.
1233121 const int is_4x4 = cu->cb_width == 4 && cu->cb_height == 4;
1057
4/4
✓ Branch 0 taken 1210812 times.
✓ Branch 1 taken 22309 times.
✓ Branch 2 taken 2293 times.
✓ Branch 3 taken 1208519 times.
1233121 const int is_128 = cu->cb_width == 128 || cu->cb_height == 128;
1058 1233121 const int hs = sps->hshift[CHROMA];
1059 1233121 const int vs = sps->vshift[CHROMA];
1060 int pred_mode_flag;
1061 int pred_mode_ibc_flag;
1062 PredMode pred_mode;
1063
1064 1233121 cu->skip_flag = 0;
1065
4/4
✓ Branch 0 taken 649380 times.
✓ Branch 1 taken 583741 times.
✓ Branch 2 taken 27214 times.
✓ Branch 3 taken 622166 times.
1233121 if (!IS_I(rsh) || sps->r->sps_ibc_enabled_flag) {
1066
4/4
✓ Branch 0 taken 581040 times.
✓ Branch 1 taken 29915 times.
✓ Branch 2 taken 525194 times.
✓ Branch 3 taken 55846 times.
610955 if (tree_type != DUAL_TREE_CHROMA &&
1067
2/2
✓ Branch 0 taken 43948 times.
✓ Branch 1 taken 481246 times.
525194 ((!is_4x4 && mode_type != MODE_TYPE_INTRA) ||
1068
3/4
✓ Branch 0 taken 72148 times.
✓ Branch 1 taken 27646 times.
✓ Branch 2 taken 72148 times.
✗ Branch 3 not taken.
99794 (sps->r->sps_ibc_enabled_flag && !is_128))) {
1069 553394 cu->skip_flag = ff_vvc_cu_skip_flag(lc, fc->tab.skip);
1070 }
1071
1072
6/6
✓ Branch 0 taken 555109 times.
✓ Branch 1 taken 55846 times.
✓ Branch 2 taken 488828 times.
✓ Branch 3 taken 66281 times.
✓ Branch 4 taken 17902 times.
✓ Branch 5 taken 470926 times.
610955 if (is_4x4 || mode_type == MODE_TYPE_INTRA || IS_I(rsh)) {
1073 140029 pred_mode_flag = 1;
1074
4/4
✓ Branch 0 taken 407897 times.
✓ Branch 1 taken 63029 times.
✓ Branch 2 taken 208783 times.
✓ Branch 3 taken 199114 times.
470926 } else if (mode_type == MODE_TYPE_INTER || cu->skip_flag) {
1075 271812 pred_mode_flag = 0;
1076 } else {
1077 199114 pred_mode_flag = ff_vvc_pred_mode_flag(lc, ch_type);
1078 }
1079 610955 pred_mode = pred_mode_flag ? MODE_INTRA : MODE_INTER;
1080
1081
4/4
✓ Branch 0 taken 27214 times.
✓ Branch 1 taken 583741 times.
✓ Branch 2 taken 1682 times.
✓ Branch 3 taken 25532 times.
610955 if (((IS_I(rsh) && !cu->skip_flag) ||
1082
6/6
✓ Branch 0 taken 583741 times.
✓ Branch 1 taken 1682 times.
✓ Branch 2 taken 159630 times.
✓ Branch 3 taken 424111 times.
✓ Branch 4 taken 113096 times.
✓ Branch 5 taken 46534 times.
585423 (!IS_I(rsh) && (pred_mode != MODE_INTRA ||
1083
6/6
✓ Branch 0 taken 66281 times.
✓ Branch 1 taken 46815 times.
✓ Branch 2 taken 103298 times.
✓ Branch 3 taken 9517 times.
✓ Branch 4 taken 528398 times.
✓ Branch 5 taken 24543 times.
609273 ((is_4x4 || mode_type == MODE_TYPE_INTRA) && !cu->skip_flag)))) &&
1084
6/6
✓ Branch 0 taken 465369 times.
✓ Branch 1 taken 63029 times.
✓ Branch 2 taken 106224 times.
✓ Branch 3 taken 359145 times.
✓ Branch 4 taken 84747 times.
✓ Branch 5 taken 21477 times.
528398 !is_128 && mode_type != MODE_TYPE_INTER && sps->r->sps_ibc_enabled_flag &&
1085 tree_type != DUAL_TREE_CHROMA) {
1086 84747 pred_mode_ibc_flag = ff_vvc_pred_mode_ibc_flag(lc, ch_type);
1087
6/6
✓ Branch 0 taken 244296 times.
✓ Branch 1 taken 281912 times.
✓ Branch 2 taken 238109 times.
✓ Branch 3 taken 6187 times.
✓ Branch 4 taken 3752 times.
✓ Branch 5 taken 234357 times.
526208 } else if (cu->skip_flag && (is_4x4 || mode_type == MODE_TYPE_INTRA)) {
1088 9939 pred_mode_ibc_flag = 1;
1089
6/6
✓ Branch 0 taken 491667 times.
✓ Branch 1 taken 24602 times.
✓ Branch 2 taken 428638 times.
✓ Branch 3 taken 63029 times.
✓ Branch 4 taken 29915 times.
✓ Branch 5 taken 398723 times.
516269 } else if (is_128 || mode_type == MODE_TYPE_INTER || tree_type == DUAL_TREE_CHROMA) {
1090 117546 pred_mode_ibc_flag = 0;
1091 } else {
1092
2/2
✓ Branch 0 taken 1260 times.
✓ Branch 1 taken 397463 times.
398723 pred_mode_ibc_flag = (IS_I(rsh)) ? sps->r->sps_ibc_enabled_flag : 0;
1093 }
1094
2/2
✓ Branch 0 taken 31182 times.
✓ Branch 1 taken 579773 times.
610955 if (pred_mode_ibc_flag)
1095 31182 pred_mode = MODE_IBC;
1096 } else {
1097 622166 pred_mode = MODE_INTRA;
1098 }
1099
1100
3/10
✓ Branch 0 taken 777873 times.
✓ Branch 1 taken 455248 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 777873 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
1233121 if (pred_mode == MODE_INTRA && sps->r->sps_palette_enabled_flag && !is_128 && !cu->skip_flag &&
1101 mode_type != MODE_TYPE_INTER && ((cu->cb_width * cu->cb_height) >
1102 (tree_type != DUAL_TREE_CHROMA ? 16 : (16 << hs << vs))) &&
1103 (mode_type != MODE_TYPE_INTRA || tree_type != DUAL_TREE_CHROMA)) {
1104 if (ff_vvc_pred_mode_plt_flag(lc))
1105 pred_mode = MODE_PLT;
1106 }
1107
1108 1233121 set_cb_tab(lc, fc->tab.cpm[cu->ch_type], pred_mode);
1109
2/2
✓ Branch 0 taken 485459 times.
✓ Branch 1 taken 747662 times.
1233121 if (tree_type == SINGLE_TREE)
1110 485459 set_cb_tab(lc, fc->tab.cpm[CHROMA], pred_mode);
1111
1112 1233121 return pred_mode;
1113 }
1114
1115 938287 static void sbt_info(VVCLocalContext *lc, const VVCSPS *sps)
1116 {
1117 938287 CodingUnit *cu = lc->cu;
1118 938287 const int cb_width = cu->cb_width;
1119 938287 const int cb_height = cu->cb_height;
1120
1121
6/6
✓ Branch 0 taken 154951 times.
✓ Branch 1 taken 783336 times.
✓ Branch 2 taken 149223 times.
✓ Branch 3 taken 5728 times.
✓ Branch 4 taken 133961 times.
✓ Branch 5 taken 15262 times.
938287 if (cu->pred_mode == MODE_INTER && sps->r->sps_sbt_enabled_flag && !cu->ciip_flag
1122
4/4
✓ Branch 0 taken 131754 times.
✓ Branch 1 taken 2207 times.
✓ Branch 2 taken 130991 times.
✓ Branch 3 taken 763 times.
133961 && cb_width <= sps->max_tb_size_y && cb_height <= sps->max_tb_size_y) {
1123 130991 const int sbt_ver_h = cb_width >= 8;
1124 130991 const int sbt_hor_h = cb_height >= 8;
1125 130991 cu->sbt_flag = 0;
1126
3/4
✓ Branch 0 taken 20091 times.
✓ Branch 1 taken 110900 times.
✓ Branch 2 taken 20091 times.
✗ Branch 3 not taken.
130991 if (sbt_ver_h || sbt_hor_h)
1127 130991 cu->sbt_flag = ff_vvc_sbt_flag(lc);
1128
2/2
✓ Branch 0 taken 44595 times.
✓ Branch 1 taken 86396 times.
130991 if (cu->sbt_flag) {
1129 44595 const int sbt_ver_q = cb_width >= 16;
1130 44595 const int sbt_hor_q = cb_height >= 16;
1131 44595 int cu_sbt_quad_flag = 0;
1132
1133
7/8
✓ Branch 0 taken 7563 times.
✓ Branch 1 taken 37032 times.
✓ Branch 2 taken 7563 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 24860 times.
✓ Branch 5 taken 19735 times.
✓ Branch 6 taken 11976 times.
✓ Branch 7 taken 12884 times.
44595 if ((sbt_ver_h || sbt_hor_h) && (sbt_ver_q || sbt_hor_q))
1134 31711 cu_sbt_quad_flag = ff_vvc_sbt_quad_flag(lc);
1135
2/2
✓ Branch 0 taken 11525 times.
✓ Branch 1 taken 33070 times.
44595 if (cu_sbt_quad_flag) {
1136 11525 cu->sbt_horizontal_flag = sbt_hor_q;
1137
4/4
✓ Branch 0 taken 7579 times.
✓ Branch 1 taken 3946 times.
✓ Branch 2 taken 3455 times.
✓ Branch 3 taken 4124 times.
11525 if (sbt_ver_q && sbt_hor_q)
1138 3455 cu->sbt_horizontal_flag = ff_vvc_sbt_horizontal_flag(lc);
1139 } else {
1140 33070 cu->sbt_horizontal_flag = sbt_hor_h;
1141
4/4
✓ Branch 0 taken 27033 times.
✓ Branch 1 taken 6037 times.
✓ Branch 2 taken 21511 times.
✓ Branch 3 taken 5522 times.
33070 if (sbt_ver_h && sbt_hor_h)
1142 21511 cu->sbt_horizontal_flag = ff_vvc_sbt_horizontal_flag(lc);
1143 }
1144 44595 cu->sbt_pos_flag = ff_vvc_sbt_pos_flag(lc);
1145
1146 {
1147
2/2
✓ Branch 0 taken 11525 times.
✓ Branch 1 taken 33070 times.
44595 const int sbt_min = cu_sbt_quad_flag ? 1 : 2;
1148
2/2
✓ Branch 0 taken 21387 times.
✓ Branch 1 taken 23208 times.
44595 lc->parse.sbt_num_fourths_tb0 = cu->sbt_pos_flag ? (4 - sbt_min) : sbt_min;
1149 }
1150 }
1151 }
1152 938287 }
1153
1154 294834 static int skipped_transform_tree_unit(VVCLocalContext *lc)
1155 {
1156 294834 const H266RawSPS *rsps = lc->fc->ps.sps->r;
1157 294834 const CodingUnit *cu = lc->cu;
1158 int ret;
1159
1160
1/2
✓ Branch 0 taken 294834 times.
✗ Branch 1 not taken.
294834 if (cu->tree_type != DUAL_TREE_CHROMA)
1161 294834 set_qp_y(lc, cu->x0, cu->y0, 0);
1162
4/4
✓ Branch 0 taken 278323 times.
✓ Branch 1 taken 16511 times.
✓ Branch 2 taken 252629 times.
✓ Branch 3 taken 25694 times.
294834 if (rsps->sps_chroma_format_idc && cu->tree_type != DUAL_TREE_LUMA)
1163 252629 set_qp_c(lc);
1164 294834 ret = skipped_transform_tree(lc, cu->x0, cu->y0, cu->cb_width, cu->cb_height);
1165
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 294834 times.
294834 if (ret < 0)
1166 return ret;
1167 294834 return 0;
1168 }
1169
1170 1233121 static void set_cb_pos(const VVCFrameContext *fc, const CodingUnit *cu)
1171 {
1172 1233121 const VVCSPS *sps = fc->ps.sps;
1173 1233121 const VVCPPS *pps = fc->ps.pps;
1174 1233121 const int log2_min_cb_size = sps->min_cb_log2_size_y;
1175 1233121 const int x_cb = cu->x0 >> log2_min_cb_size;
1176 1233121 const int y_cb = cu->y0 >> log2_min_cb_size;
1177 1233121 const int ch_type = cu->ch_type;
1178 int x, y;
1179
1180 1233121 x = y_cb * pps->min_cb_width + x_cb;
1181
2/2
✓ Branch 0 taken 5092796 times.
✓ Branch 1 taken 1233121 times.
6325917 for (y = 0; y < (cu->cb_height >> log2_min_cb_size); y++) {
1182 5092796 const int width = cu->cb_width >> log2_min_cb_size;
1183
1184
2/2
✓ Branch 0 taken 47708400 times.
✓ Branch 1 taken 5092796 times.
52801196 for (int i = 0; i < width; i++) {
1185 47708400 fc->tab.cb_pos_x[ch_type][x + i] = cu->x0;
1186 47708400 fc->tab.cb_pos_y[ch_type][x + i] = cu->y0;
1187 }
1188 5092796 memset(&fc->tab.cb_width[ch_type][x], cu->cb_width, width);
1189 5092796 memset(&fc->tab.cb_height[ch_type][x], cu->cb_height, width);
1190 5092796 memset(&fc->tab.cqt_depth[ch_type][x], cu->cqt_depth, width);
1191
1192 5092796 x += pps->min_cb_width;
1193 }
1194 1233121 }
1195
1196 1233121 static CodingUnit* alloc_cu(VVCLocalContext *lc, const int x0, const int y0)
1197 {
1198 1233121 VVCFrameContext *fc = lc->fc;
1199 1233121 const VVCSPS *sps = fc->ps.sps;
1200 1233121 const VVCPPS *pps = fc->ps.pps;
1201 1233121 const int rx = x0 >> sps->ctb_log2_size_y;
1202 1233121 const int ry = y0 >> sps->ctb_log2_size_y;
1203 1233121 CodingUnit **cus = fc->tab.cus + ry * pps->ctb_width + rx;
1204 1233121 CodingUnit *cu = av_refstruct_pool_get(fc->cu_pool);
1205
1206
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1233121 times.
1233121 if (!cu)
1207 return NULL;
1208 1233121 cu->next = NULL;
1209
1210
2/2
✓ Branch 0 taken 1186408 times.
✓ Branch 1 taken 46713 times.
1233121 if (lc->cu)
1211 1186408 lc->cu->next = cu;
1212 else
1213 46713 *cus = cu;
1214 1233121 lc->cu = cu;
1215
1216 1233121 return cu;
1217 }
1218
1219 1233121 static CodingUnit* add_cu(VVCLocalContext *lc, const int x0, const int y0,
1220 const int cb_width, const int cb_height, const int cqt_depth, const VVCTreeType tree_type)
1221 {
1222 1233121 VVCFrameContext *fc = lc->fc;
1223 1233121 const int ch_type = tree_type == DUAL_TREE_CHROMA ? 1 : 0;
1224 1233121 CodingUnit *cu = alloc_cu(lc, x0, y0);
1225
1226
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1233121 times.
1233121 if (!cu)
1227 return NULL;
1228
1229 1233121 memset(&cu->pu, 0, sizeof(cu->pu));
1230
1231 1233121 lc->parse.prev_tu_cbf_y = 0;
1232
1233 1233121 cu->sbt_flag = 0;
1234 1233121 cu->act_enabled_flag = 0;
1235
1236 1233121 cu->tree_type = tree_type;
1237 1233121 cu->x0 = x0;
1238 1233121 cu->y0 = y0;
1239 1233121 cu->cb_width = cb_width;
1240 1233121 cu->cb_height = cb_height;
1241 1233121 cu->ch_type = ch_type;
1242 1233121 cu->cqt_depth = cqt_depth;
1243 1233121 cu->tus.head = cu->tus.tail = NULL;
1244 1233121 cu->bdpcm_flag[LUMA] = cu->bdpcm_flag[CB] = cu->bdpcm_flag[CR] = 0;
1245 1233121 cu->isp_split_type = ISP_NO_SPLIT;
1246 1233121 cu->intra_mip_flag = 0;
1247 1233121 cu->ciip_flag = 0;
1248 1233121 cu->coded_flag = 1;
1249 1233121 cu->num_intra_subpartitions = 1;
1250 1233121 cu->pu.dmvr_flag = 0;
1251
1252 1233121 set_cb_pos(fc, cu);
1253 1233121 return cu;
1254 }
1255
1256 1233121 static void set_cu_tabs(const VVCLocalContext *lc, const CodingUnit *cu)
1257 {
1258 1233121 const VVCFrameContext *fc = lc->fc;
1259 1233121 const PredictionUnit *pu = &cu->pu;
1260 1233121 const TransformUnit *tu = cu->tus.head;
1261
1262 1233121 set_cb_tab(lc, fc->tab.mmi, pu->mi.motion_model_idc);
1263 1233121 set_cb_tab(lc, fc->tab.msf, pu->merge_subblock_flag);
1264
2/2
✓ Branch 0 taken 1051964 times.
✓ Branch 1 taken 181157 times.
1233121 if (cu->tree_type != DUAL_TREE_CHROMA) {
1265 1051964 set_cb_tab(lc, fc->tab.skip, cu->skip_flag);
1266 1051964 set_cb_tab(lc, fc->tab.pcmf[LUMA], cu->bdpcm_flag[LUMA]);
1267 }
1268
2/2
✓ Branch 0 taken 666616 times.
✓ Branch 1 taken 566505 times.
1233121 if (cu->tree_type != DUAL_TREE_LUMA)
1269 666616 set_cb_tab(lc, fc->tab.pcmf[CHROMA], cu->bdpcm_flag[CHROMA]);
1270
1271
2/2
✓ Branch 0 taken 1493040 times.
✓ Branch 1 taken 1233121 times.
2726161 while (tu) {
1272
2/2
✓ Branch 0 taken 2805023 times.
✓ Branch 1 taken 1493040 times.
4298063 for (int j = 0; j < tu->nb_tbs; j++) {
1273 2805023 const TransformBlock *tb = tu->tbs + j;
1274
2/2
✓ Branch 0 taken 1493996 times.
✓ Branch 1 taken 1311027 times.
2805023 if (tb->c_idx != LUMA)
1275 1493996 set_qp_c_tab(lc, tu, tb);
1276 }
1277 1493040 tu = tu->next;
1278 }
1279 1233121 }
1280
1281 //8.5.2.7 Derivation process for merge motion vector difference
1282 55977 static void derive_mmvd(const VVCLocalContext *lc, MvField *mvf, const Mv *mmvd_offset)
1283 {
1284 55977 const SliceContext *sc = lc->sc;
1285 Mv mmvd[2];
1286
1287
2/2
✓ Branch 0 taken 23351 times.
✓ Branch 1 taken 32626 times.
55977 if (mvf->pred_flag == PF_BI) {
1288 23351 const RefPicList *rpl = sc->rpl;
1289 23351 const int poc = lc->fc->ps.ph.poc;
1290 23351 const int diff[] = {
1291 23351 poc - rpl[L0].refs[mvf->ref_idx[L0]].poc,
1292 23351 poc - rpl[L1].refs[mvf->ref_idx[L1]].poc
1293 };
1294
4/4
✓ Branch 0 taken 22020 times.
✓ Branch 1 taken 1331 times.
✓ Branch 2 taken 8875 times.
✓ Branch 3 taken 14476 times.
23351 const int sign = FFSIGN(diff[0]) != FFSIGN(diff[1]);
1295
1296
2/2
✓ Branch 0 taken 7969 times.
✓ Branch 1 taken 15382 times.
23351 if (diff[0] == diff[1]) {
1297 7969 mmvd[1] = mmvd[0] = *mmvd_offset;
1298 }
1299 else {
1300 15382 const int i = FFABS(diff[0]) < FFABS(diff[1]);
1301 15382 const int o = !i;
1302 15382 mmvd[i] = *mmvd_offset;
1303
4/4
✓ Branch 0 taken 15138 times.
✓ Branch 1 taken 244 times.
✓ Branch 2 taken 15061 times.
✓ Branch 3 taken 77 times.
15382 if (!rpl[L0].refs[mvf->ref_idx[L0]].is_lt && !rpl[L1].refs[mvf->ref_idx[L1]].is_lt) {
1304 15061 ff_vvc_mv_scale(&mmvd[o], mmvd_offset, diff[i], diff[o]);
1305 }
1306 else {
1307
2/2
✓ Branch 0 taken 199 times.
✓ Branch 1 taken 122 times.
321 mmvd[o].x = sign ? -mmvd[i].x : mmvd[i].x;
1308
2/2
✓ Branch 0 taken 199 times.
✓ Branch 1 taken 122 times.
321 mmvd[o].y = sign ? -mmvd[i].y : mmvd[i].y;
1309 }
1310 }
1311 23351 mvf->mv[0].x += mmvd[0].x;
1312 23351 mvf->mv[0].y += mmvd[0].y;
1313 23351 mvf->mv[1].x += mmvd[1].x;
1314 23351 mvf->mv[1].y += mmvd[1].y;
1315 } else {
1316 32626 const int idx = mvf->pred_flag - PF_L0;
1317 32626 mvf->mv[idx].x += mmvd_offset->x;
1318 32626 mvf->mv[idx].y += mmvd_offset->y;
1319 }
1320
1321 55977 }
1322
1323 273411 static void mvf_to_mi(const MvField *mvf, MotionInfo *mi)
1324 {
1325 273411 mi->pred_flag = mvf->pred_flag;
1326 273411 mi->bcw_idx = mvf->bcw_idx;
1327 273411 mi->hpel_if_idx = mvf->hpel_if_idx;
1328
2/2
✓ Branch 0 taken 546822 times.
✓ Branch 1 taken 273411 times.
820233 for (int i = 0; i < 2; i++) {
1329 546822 const PredFlag mask = i + 1;
1330
2/2
✓ Branch 0 taken 430639 times.
✓ Branch 1 taken 116183 times.
546822 if (mvf->pred_flag & mask) {
1331 430639 mi->mv[i][0] = mvf->mv[i];
1332 430639 mi->ref_idx[i] = mvf->ref_idx[i];
1333 }
1334 }
1335 273411 }
1336
1337 273411 static void mv_merge_refine_pred_flag(MvField *mvf, const int width, const int height)
1338 {
1339
4/4
✓ Branch 0 taken 162286 times.
✓ Branch 1 taken 111125 times.
✓ Branch 2 taken 5058 times.
✓ Branch 3 taken 157228 times.
273411 if (mvf->pred_flag == PF_BI && (width + height) == 12) {
1340 5058 mvf->pred_flag = PF_L0;
1341 5058 mvf->bcw_idx = 0;
1342 }
1343 273411 }
1344
1345 // subblock-based inter prediction data
1346 50089 static void merge_data_subblock(VVCLocalContext *lc)
1347 {
1348 50089 const VVCFrameContext *fc = lc->fc;
1349 50089 const VVCPH *ph = &fc->ps.ph;
1350 50089 CodingUnit* cu = lc->cu;
1351 50089 PredictionUnit *pu = &cu->pu;
1352 50089 int merge_subblock_idx = 0;
1353
1354
1/2
✓ Branch 0 taken 50089 times.
✗ Branch 1 not taken.
50089 if (ph->max_num_subblock_merge_cand > 1) {
1355 50089 merge_subblock_idx = ff_vvc_merge_subblock_idx(lc, ph->max_num_subblock_merge_cand);
1356 }
1357 50089 ff_vvc_sb_mv_merge_mode(lc, merge_subblock_idx, pu);
1358 50089 }
1359
1360 257725 static void merge_data_regular(VVCLocalContext *lc)
1361 {
1362 257725 const VVCFrameContext *fc = lc->fc;
1363 257725 const VVCSPS *sps = fc->ps.sps;
1364 257725 const VVCPH *ph = &fc->ps.ph;
1365 257725 const CodingUnit* cu = lc->cu;
1366 257725 PredictionUnit *pu = &lc->cu->pu;
1367 257725 int merge_idx = 0;
1368 Mv mmvd_offset;
1369 MvField mvf;
1370
1371
2/2
✓ Branch 0 taken 252561 times.
✓ Branch 1 taken 5164 times.
257725 if (sps->r->sps_mmvd_enabled_flag)
1372 252561 pu->mmvd_merge_flag = ff_vvc_mmvd_merge_flag(lc);
1373
2/2
✓ Branch 0 taken 55977 times.
✓ Branch 1 taken 201748 times.
257725 if (pu->mmvd_merge_flag) {
1374 55977 int mmvd_cand_flag = 0;
1375
1/2
✓ Branch 0 taken 55977 times.
✗ Branch 1 not taken.
55977 if (sps->max_num_merge_cand > 1)
1376 55977 mmvd_cand_flag = ff_vvc_mmvd_cand_flag(lc);
1377 55977 ff_vvc_mmvd_offset_coding(lc, &mmvd_offset, ph->r->ph_mmvd_fullpel_only_flag);
1378 55977 merge_idx = mmvd_cand_flag;
1379
1/2
✓ Branch 0 taken 201748 times.
✗ Branch 1 not taken.
201748 } else if (sps->max_num_merge_cand > 1) {
1380 201748 merge_idx = ff_vvc_merge_idx(lc);
1381 }
1382 257725 ff_vvc_luma_mv_merge_mode(lc, merge_idx, 0, &mvf);
1383
2/2
✓ Branch 0 taken 55977 times.
✓ Branch 1 taken 201748 times.
257725 if (pu->mmvd_merge_flag)
1384 55977 derive_mmvd(lc, &mvf, &mmvd_offset);
1385 257725 mv_merge_refine_pred_flag(&mvf, cu->cb_width, cu->cb_height);
1386 257725 ff_vvc_store_mvf(lc, &mvf);
1387 257725 mvf_to_mi(&mvf, &pu->mi);
1388 257725 }
1389
1390 41301 static int ciip_flag_decode(VVCLocalContext *lc, const int ciip_avaiable, const int gpm_avaiable, const int is_128)
1391 {
1392 41301 const VVCFrameContext *fc = lc->fc;
1393 41301 const VVCSPS *sps = fc->ps.sps;
1394 41301 const CodingUnit *cu = lc->cu;
1395
1396
4/4
✓ Branch 0 taken 26109 times.
✓ Branch 1 taken 15192 times.
✓ Branch 2 taken 19469 times.
✓ Branch 3 taken 6640 times.
41301 if (ciip_avaiable && gpm_avaiable)
1397 19469 return ff_vvc_ciip_flag(lc);
1398
3/4
✓ Branch 0 taken 6640 times.
✓ Branch 1 taken 15192 times.
✓ Branch 2 taken 6640 times.
✗ Branch 3 not taken.
21832 return sps->r->sps_ciip_enabled_flag && !cu->skip_flag &&
1399
2/4
✓ Branch 0 taken 21832 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6640 times.
✗ Branch 3 not taken.
43664 !is_128 && (cu->cb_width * cu->cb_height >= 64);
1400 }
1401
1402 25615 static void merge_data_gpm(VVCLocalContext *lc)
1403 {
1404 25615 const VVCFrameContext *fc = lc->fc;
1405 25615 const VVCSPS *sps = fc->ps.sps;
1406 25615 PredictionUnit *pu = &lc->cu->pu;
1407 int merge_gpm_idx[2];
1408
1409 25615 pu->merge_gpm_flag = 1;
1410 25615 pu->gpm_partition_idx = ff_vvc_merge_gpm_partition_idx(lc);
1411 25615 merge_gpm_idx[0] = ff_vvc_merge_gpm_idx(lc, 0);
1412 25615 merge_gpm_idx[1] = 0;
1413
1/2
✓ Branch 0 taken 25615 times.
✗ Branch 1 not taken.
25615 if (sps->max_num_gpm_merge_cand > 2)
1414 25615 merge_gpm_idx[1] = ff_vvc_merge_gpm_idx(lc, 1);
1415
1416 25615 ff_vvc_luma_mv_merge_gpm(lc, merge_gpm_idx, pu->gpm_mv);
1417 25615 ff_vvc_store_gpm_mvf(lc, pu);
1418 25615 }
1419
1420 15686 static void merge_data_ciip(VVCLocalContext *lc)
1421 {
1422 15686 const VVCFrameContext* fc = lc->fc;
1423 15686 const VVCSPS* sps = fc->ps.sps;
1424 15686 CodingUnit *cu = lc->cu;
1425 15686 MotionInfo *mi = &cu->pu.mi;
1426 15686 int merge_idx = 0;
1427 MvField mvf;
1428
1429
1/2
✓ Branch 0 taken 15686 times.
✗ Branch 1 not taken.
15686 if (sps->max_num_merge_cand > 1)
1430 15686 merge_idx = ff_vvc_merge_idx(lc);
1431 15686 ff_vvc_luma_mv_merge_mode(lc, merge_idx, 1, &mvf);
1432 15686 mv_merge_refine_pred_flag(&mvf, cu->cb_width, cu->cb_height);
1433 15686 ff_vvc_store_mvf(lc, &mvf);
1434 15686 mvf_to_mi(&mvf, mi);
1435 15686 cu->intra_pred_mode_y = cu->intra_pred_mode_c = INTRA_PLANAR;
1436 15686 cu->intra_luma_ref_idx = 0;
1437 15686 cu->intra_mip_flag = 0;
1438 15686 }
1439
1440 // block-based inter prediction data
1441 299026 static void merge_data_block(VVCLocalContext *lc)
1442 {
1443 299026 const VVCFrameContext* fc = lc->fc;
1444 299026 const VVCSPS *sps = fc->ps.sps;
1445 299026 const H266RawSliceHeader *rsh = lc->sc->sh.r;
1446 299026 CodingUnit *cu = lc->cu;
1447 299026 const int cb_width = cu->cb_width;
1448 299026 const int cb_height = cu->cb_height;
1449
4/4
✓ Branch 0 taken 281734 times.
✓ Branch 1 taken 17292 times.
✓ Branch 2 taken 1346 times.
✓ Branch 3 taken 280388 times.
299026 const int is_128 = cb_width == 128 || cb_height == 128;
1450 891914 const int ciip_avaiable = sps->r->sps_ciip_enabled_flag &&
1451
6/6
✓ Branch 0 taken 293862 times.
✓ Branch 1 taken 5164 times.
✓ Branch 2 taken 99782 times.
✓ Branch 3 taken 194080 times.
✓ Branch 4 taken 89097 times.
✓ Branch 5 taken 10685 times.
299026 !cu->skip_flag && (cb_width * cb_height >= 64);
1452
4/4
✓ Branch 0 taken 278688 times.
✓ Branch 1 taken 906 times.
✓ Branch 2 taken 244049 times.
✓ Branch 3 taken 34639 times.
279594 const int gpm_avaiable = sps->r->sps_gpm_enabled_flag && IS_B(rsh) &&
1453
2/2
✓ Branch 0 taken 217965 times.
✓ Branch 1 taken 26084 times.
244049 (cb_width >= 8) && (cb_height >=8) &&
1454
6/6
✓ Branch 0 taken 279594 times.
✓ Branch 1 taken 19432 times.
✓ Branch 2 taken 211881 times.
✓ Branch 3 taken 6084 times.
✓ Branch 4 taken 210032 times.
✓ Branch 5 taken 1849 times.
578620 (cb_width < 8 * cb_height) && (cb_height < 8 *cb_width);
1455
1456 299026 int regular_merge_flag = 1;
1457
1458
6/6
✓ Branch 0 taken 280388 times.
✓ Branch 1 taken 18638 times.
✓ Branch 2 taken 191650 times.
✓ Branch 3 taken 88738 times.
✓ Branch 4 taken 129273 times.
✓ Branch 5 taken 62377 times.
299026 if (!is_128 && (ciip_avaiable || gpm_avaiable))
1459 218011 regular_merge_flag = ff_vvc_regular_merge_flag(lc, cu->skip_flag);
1460
2/2
✓ Branch 0 taken 257725 times.
✓ Branch 1 taken 41301 times.
299026 if (regular_merge_flag) {
1461 257725 merge_data_regular(lc);
1462 } else {
1463 41301 cu->ciip_flag = ciip_flag_decode(lc, ciip_avaiable, gpm_avaiable, is_128);
1464
2/2
✓ Branch 0 taken 15686 times.
✓ Branch 1 taken 25615 times.
41301 if (cu->ciip_flag)
1465 15686 merge_data_ciip(lc);
1466 else
1467 25615 merge_data_gpm(lc);
1468 }
1469 299026 }
1470
1471 14146 static int merge_data_ibc(VVCLocalContext *lc)
1472 {
1473 14146 const VVCFrameContext* fc = lc->fc;
1474 14146 const VVCSPS* sps = fc->ps.sps;
1475 14146 MotionInfo *mi = &lc->cu->pu.mi;
1476 14146 int merge_idx = 0;
1477 int ret;
1478
1479 14146 mi->pred_flag = PF_IBC;
1480
1481
2/2
✓ Branch 0 taken 13906 times.
✓ Branch 1 taken 240 times.
14146 if (sps->max_num_ibc_merge_cand > 1)
1482 13906 merge_idx = ff_vvc_merge_idx(lc);
1483
1484 14146 ret = ff_vvc_luma_mv_merge_ibc(lc, merge_idx, &mi->mv[L0][0]);
1485
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14146 times.
14146 if (ret)
1486 return ret;
1487 14146 ff_vvc_store_mv(lc, mi);
1488
1489 14146 return 0;
1490 }
1491
1492 363261 static int hls_merge_data(VVCLocalContext *lc)
1493 {
1494 363261 const VVCFrameContext *fc = lc->fc;
1495 363261 const VVCPH *ph = &fc->ps.ph;
1496 363261 const CodingUnit *cu = lc->cu;
1497 363261 PredictionUnit *pu = &lc->cu->pu;
1498 int ret;
1499
1500 363261 pu->merge_gpm_flag = 0;
1501 363261 pu->mi.num_sb_x = pu->mi.num_sb_y = 1;
1502
2/2
✓ Branch 0 taken 14146 times.
✓ Branch 1 taken 349115 times.
363261 if (cu->pred_mode == MODE_IBC) {
1503 14146 ret = merge_data_ibc(lc);
1504
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14146 times.
14146 if (ret)
1505 return ret;
1506 } else {
1507
5/6
✓ Branch 0 taken 349115 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 312613 times.
✓ Branch 3 taken 36502 times.
✓ Branch 4 taken 284568 times.
✓ Branch 5 taken 28045 times.
349115 if (ph->max_num_subblock_merge_cand > 0 && cu->cb_width >= 8 && cu->cb_height >= 8)
1508 284568 pu->merge_subblock_flag = ff_vvc_merge_subblock_flag(lc);
1509
2/2
✓ Branch 0 taken 50089 times.
✓ Branch 1 taken 299026 times.
349115 if (pu->merge_subblock_flag)
1510 50089 merge_data_subblock(lc);
1511 else
1512 299026 merge_data_block(lc);
1513 }
1514 363261 return 0;
1515 }
1516
1517 117924 static void hls_mvd_coding(VVCLocalContext *lc, Mv* mvd)
1518 {
1519 int32_t mv[2];
1520
1521
2/2
✓ Branch 0 taken 235848 times.
✓ Branch 1 taken 117924 times.
353772 for (int i = 0; i < 2; i++) {
1522 235848 mv[i] = ff_vvc_abs_mvd_greater0_flag(lc);
1523 }
1524
1525
2/2
✓ Branch 0 taken 235848 times.
✓ Branch 1 taken 117924 times.
353772 for (int i = 0; i < 2; i++) {
1526
2/2
✓ Branch 0 taken 164462 times.
✓ Branch 1 taken 71386 times.
235848 if (mv[i])
1527 164462 mv[i] += ff_vvc_abs_mvd_greater1_flag(lc);
1528 }
1529
1530
2/2
✓ Branch 0 taken 235848 times.
✓ Branch 1 taken 117924 times.
353772 for (int i = 0; i < 2; i++) {
1531
2/2
✓ Branch 0 taken 164462 times.
✓ Branch 1 taken 71386 times.
235848 if (mv[i] > 0) {
1532
2/2
✓ Branch 0 taken 111369 times.
✓ Branch 1 taken 53093 times.
164462 if (mv[i] == 2)
1533 111369 mv[i] += ff_vvc_abs_mvd_minus2(lc);
1534 164462 mv[i] = (1 - 2 * ff_vvc_mvd_sign_flag(lc)) * mv[i];
1535 }
1536 }
1537 117924 mvd->x = mv[0];
1538 117924 mvd->y = mv[1];
1539 117924 }
1540
1541 74951 static int bcw_idx_decode(VVCLocalContext *lc, const MotionInfo *mi, const int cb_width, const int cb_height)
1542 {
1543 74951 const VVCFrameContext *fc = lc->fc;
1544 74951 const VVCSPS *sps = fc->ps.sps;
1545 74951 const VVCPPS *pps = fc->ps.pps;
1546 74951 const VVCPH *ph = &fc->ps.ph;
1547 74951 const VVCSH *sh = &lc->sc->sh;
1548
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 74951 times.
74951 const PredWeightTable *w = pps->r->pps_wp_info_in_ph_flag ? &ph->pwt : &sh->pwt;
1549 74951 int bcw_idx = 0;
1550
1551
4/4
✓ Branch 0 taken 71220 times.
✓ Branch 1 taken 3731 times.
✓ Branch 2 taken 19738 times.
✓ Branch 3 taken 51482 times.
74951 if (sps->r->sps_bcw_enabled_flag && mi->pred_flag == PF_BI &&
1552
2/2
✓ Branch 0 taken 18386 times.
✓ Branch 1 taken 1352 times.
19738 !w->weight_flag[L0][LUMA][mi->ref_idx[0]] &&
1553
2/2
✓ Branch 0 taken 17740 times.
✓ Branch 1 taken 646 times.
18386 !w->weight_flag[L1][LUMA][mi->ref_idx[1]] &&
1554
2/2
✓ Branch 0 taken 17316 times.
✓ Branch 1 taken 424 times.
17740 !w->weight_flag[L0][CHROMA][mi->ref_idx[0]] &&
1555
2/2
✓ Branch 0 taken 17154 times.
✓ Branch 1 taken 162 times.
17316 !w->weight_flag[L1][CHROMA][mi->ref_idx[1]] &&
1556
2/2
✓ Branch 0 taken 11245 times.
✓ Branch 1 taken 5909 times.
17154 cb_width * cb_height >= 256) {
1557 11245 bcw_idx = ff_vvc_bcw_idx(lc, ff_vvc_no_backward_pred_flag(lc));
1558 }
1559 74951 return bcw_idx;
1560 }
1561
1562 95525 static int8_t ref_idx_decode(VVCLocalContext *lc, const VVCSH *sh, const int sym_mvd_flag, const int lx)
1563 {
1564 95525 const H266RawSliceHeader *rsh = sh->r;
1565 95525 int ref_idx = 0;
1566
1567
4/4
✓ Branch 0 taken 78510 times.
✓ Branch 1 taken 17015 times.
✓ Branch 2 taken 66272 times.
✓ Branch 3 taken 12238 times.
95525 if (rsh->num_ref_idx_active[lx] > 1 && !sym_mvd_flag)
1568 66272 ref_idx = ff_vvc_ref_idx_lx(lc, rsh->num_ref_idx_active[lx]);
1569
2/2
✓ Branch 0 taken 12238 times.
✓ Branch 1 taken 17015 times.
29253 else if (sym_mvd_flag)
1570 12238 ref_idx = sh->ref_idx_sym[lx];
1571 95525 return ref_idx;
1572 }
1573
1574 95525 static int mvds_decode(VVCLocalContext *lc, Mv mvds[2][MAX_CONTROL_POINTS],
1575 const int num_cp_mv, const int lx)
1576 {
1577 95525 const VVCFrameContext *fc = lc->fc;
1578 95525 const VVCPH *ph = &fc->ps.ph;
1579 95525 const PredictionUnit *pu = &lc->cu->pu;
1580 95525 const MotionInfo *mi = &pu->mi;
1581 95525 int has_no_zero_mvd = 0;
1582
1583
6/6
✓ Branch 0 taken 33107 times.
✓ Branch 1 taken 62418 times.
✓ Branch 2 taken 4768 times.
✓ Branch 3 taken 28339 times.
✓ Branch 4 taken 4754 times.
✓ Branch 5 taken 14 times.
95525 if (lx == L1 && ph->r->ph_mvd_l1_zero_flag && mi->pred_flag == PF_BI) {
1584
2/2
✓ Branch 0 taken 6065 times.
✓ Branch 1 taken 4754 times.
10819 for (int j = 0; j < num_cp_mv; j++)
1585 6065 AV_ZERO64(&mvds[lx][j]);
1586 } else {
1587 90771 Mv *mvd0 = &mvds[lx][0];
1588
4/4
✓ Branch 0 taken 28353 times.
✓ Branch 1 taken 62418 times.
✓ Branch 2 taken 6119 times.
✓ Branch 3 taken 22234 times.
90771 if (lx == L1 && pu->sym_mvd_flag) {
1589 6119 mvd0->x = -mvds[L0][0].x;
1590 6119 mvd0->y = -mvds[L0][0].y;
1591 } else {
1592 84652 hls_mvd_coding(lc, mvd0);
1593 }
1594
4/4
✓ Branch 0 taken 21817 times.
✓ Branch 1 taken 68954 times.
✓ Branch 2 taken 13976 times.
✓ Branch 3 taken 7841 times.
90771 has_no_zero_mvd |= (mvd0->x || mvd0->y);
1595
2/2
✓ Branch 0 taken 16236 times.
✓ Branch 1 taken 90771 times.
107007 for (int j = 1; j < num_cp_mv; j++) {
1596 16236 Mv *mvd = &mvds[lx][j];
1597 16236 hls_mvd_coding(lc, mvd);
1598 16236 mvd->x += mvd0->x;
1599 16236 mvd->y += mvd0->y;
1600
4/4
✓ Branch 0 taken 2930 times.
✓ Branch 1 taken 13306 times.
✓ Branch 2 taken 2004 times.
✓ Branch 3 taken 926 times.
16236 has_no_zero_mvd |= (mvd->x || mvd->y);
1601 }
1602 }
1603 95525 return has_no_zero_mvd;
1604 }
1605
1606 74951 static void mvp_add_difference(MotionInfo *mi, const int num_cp_mv,
1607 const Mv mvds[2][MAX_CONTROL_POINTS], const int amvr_shift)
1608 {
1609
2/2
✓ Branch 0 taken 149902 times.
✓ Branch 1 taken 74951 times.
224853 for (int i = 0; i < 2; i++) {
1610 149902 const PredFlag mask = i + PF_L0;
1611
2/2
✓ Branch 0 taken 95525 times.
✓ Branch 1 taken 54377 times.
149902 if (mi->pred_flag & mask) {
1612
2/2
✓ Branch 0 taken 113072 times.
✓ Branch 1 taken 95525 times.
208597 for (int j = 0; j < num_cp_mv; j++) {
1613 113072 const Mv *mvd = &mvds[i][j];
1614 113072 mi->mv[i][j].x += mvd->x * (1 << amvr_shift);
1615 113072 mi->mv[i][j].y += mvd->y * (1 << amvr_shift);
1616 }
1617 }
1618 }
1619 74951 }
1620
1621 17036 static int mvp_data_ibc(VVCLocalContext *lc)
1622 {
1623 17036 const VVCFrameContext *fc = lc->fc;
1624 17036 const CodingUnit *cu = lc->cu;
1625 17036 const PredictionUnit *pu = &lc->cu->pu;
1626 17036 const VVCSPS *sps = fc->ps.sps;
1627 17036 MotionInfo *mi = &lc->cu->pu.mi;
1628 17036 int mvp_l0_flag = 0;
1629 17036 int amvr_shift = 4;
1630 17036 Mv *mv = &mi->mv[L0][0];
1631 int ret;
1632
1633 17036 mi->pred_flag = PF_IBC;
1634 17036 mi->num_sb_x = 1;
1635 17036 mi->num_sb_y = 1;
1636
1637 17036 hls_mvd_coding(lc, mv);
1638
2/2
✓ Branch 0 taken 15694 times.
✓ Branch 1 taken 1342 times.
17036 if (sps->max_num_ibc_merge_cand > 1)
1639 15694 mvp_l0_flag = ff_vvc_mvp_lx_flag(lc);
1640
5/6
✓ Branch 0 taken 17036 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10095 times.
✓ Branch 3 taken 6941 times.
✓ Branch 4 taken 2942 times.
✓ Branch 5 taken 7153 times.
17036 if (sps->r->sps_amvr_enabled_flag && (mv->x || mv->y))
1641 9883 amvr_shift = ff_vvc_amvr_shift(lc, pu->inter_affine_flag, cu->pred_mode, 1);
1642
1643 17036 ret = ff_vvc_mvp_ibc(lc, mvp_l0_flag, amvr_shift, mv);
1644
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17036 times.
17036 if (ret)
1645 return ret;
1646 17036 ff_vvc_store_mv(lc, mi);
1647
1648 17036 return 0;
1649 }
1650
1651 74951 static int mvp_data(VVCLocalContext *lc)
1652 {
1653 74951 const VVCFrameContext *fc = lc->fc;
1654 74951 const CodingUnit *cu = lc->cu;
1655 74951 PredictionUnit *pu = &lc->cu->pu;
1656 74951 const VVCSPS *sps = fc->ps.sps;
1657 74951 const VVCPH *ph = &fc->ps.ph;
1658 74951 const VVCSH *sh = &lc->sc->sh;
1659 74951 const H266RawSliceHeader *rsh = sh->r;
1660 74951 MotionInfo *mi = &pu->mi;
1661 74951 const int cb_width = cu->cb_width;
1662 74951 const int cb_height = cu->cb_height;
1663
1664 74951 int mvp_lx_flag[2] = {0};
1665 74951 int cu_affine_type_flag = 0;
1666 int num_cp_mv;
1667 74951 int amvr_enabled, has_no_zero_mvd = 0, amvr_shift;
1668 Mv mvds[2][MAX_CONTROL_POINTS];
1669
1670 74951 mi->pred_flag = ff_vvc_pred_flag(lc, IS_B(rsh));
1671
5/6
✓ Branch 0 taken 74951 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 40853 times.
✓ Branch 3 taken 34098 times.
✓ Branch 4 taken 28656 times.
✓ Branch 5 taken 12197 times.
74951 if (sps->r->sps_affine_enabled_flag && cb_width >= 16 && cb_height >= 16) {
1672 28656 pu->inter_affine_flag = ff_vvc_inter_affine_flag(lc);
1673 28656 set_cb_tab(lc, fc->tab.iaf, pu->inter_affine_flag);
1674
4/4
✓ Branch 0 taken 26310 times.
✓ Branch 1 taken 2346 times.
✓ Branch 2 taken 9103 times.
✓ Branch 3 taken 17207 times.
28656 if (sps->r->sps_6param_affine_enabled_flag && pu->inter_affine_flag)
1675 9103 cu_affine_type_flag = ff_vvc_cu_affine_type_flag(lc);
1676 }
1677 74951 mi->motion_model_idc = pu->inter_affine_flag + cu_affine_type_flag;
1678 74951 num_cp_mv = mi->motion_model_idc + 1;
1679
1680
4/4
✓ Branch 0 taken 62982 times.
✓ Branch 1 taken 11969 times.
✓ Branch 2 taken 52942 times.
✓ Branch 3 taken 10040 times.
74951 if (sps->r->sps_smvd_enabled_flag && !ph->r->ph_mvd_l1_zero_flag &&
1681
4/4
✓ Branch 0 taken 15224 times.
✓ Branch 1 taken 37718 times.
✓ Branch 2 taken 13921 times.
✓ Branch 3 taken 1303 times.
52942 mi->pred_flag == PF_BI && !pu->inter_affine_flag &&
1682
4/4
✓ Branch 0 taken 12823 times.
✓ Branch 1 taken 1098 times.
✓ Branch 2 taken 12092 times.
✓ Branch 3 taken 731 times.
13921 sh->ref_idx_sym[0] > -1 && sh->ref_idx_sym[1] > -1)
1683 12092 pu->sym_mvd_flag = ff_vvc_sym_mvd_flag(lc);
1684
1685
2/2
✓ Branch 0 taken 149902 times.
✓ Branch 1 taken 74951 times.
224853 for (int i = L0; i <= L1; i++) {
1686
2/2
✓ Branch 0 taken 74951 times.
✓ Branch 1 taken 74951 times.
149902 const PredFlag pred_flag = PF_L0 + !i;
1687
2/2
✓ Branch 0 taken 95525 times.
✓ Branch 1 taken 54377 times.
149902 if (mi->pred_flag != pred_flag) {
1688 95525 mi->ref_idx[i] = ref_idx_decode(lc, sh, pu->sym_mvd_flag, i);
1689 95525 has_no_zero_mvd |= mvds_decode(lc, mvds, num_cp_mv, i);
1690 95525 mvp_lx_flag[i] = ff_vvc_mvp_lx_flag(lc);
1691 }
1692 }
1693
1694 149902 amvr_enabled = mi->motion_model_idc == MOTION_TRANSLATION ?
1695
2/2
✓ Branch 0 taken 65004 times.
✓ Branch 1 taken 9947 times.
74951 sps->r->sps_amvr_enabled_flag : sps->r->sps_affine_amvr_enabled_flag;
1696 74951 amvr_enabled &= has_no_zero_mvd;
1697
1698 74951 amvr_shift = ff_vvc_amvr_shift(lc, pu->inter_affine_flag, cu->pred_mode, amvr_enabled);
1699
1700 74951 mi->hpel_if_idx = amvr_shift == 3;
1701 74951 mi->bcw_idx = bcw_idx_decode(lc, mi, cb_width, cb_height);
1702
1703
2/2
✓ Branch 0 taken 9947 times.
✓ Branch 1 taken 65004 times.
74951 if (mi->motion_model_idc)
1704 9947 ff_vvc_affine_mvp(lc, mvp_lx_flag, amvr_shift, mi);
1705 else
1706 65004 ff_vvc_mvp(lc, mvp_lx_flag, amvr_shift, mi);
1707
1708 74951 mvp_add_difference(mi, num_cp_mv, mvds, amvr_shift);
1709
1710
2/2
✓ Branch 0 taken 9947 times.
✓ Branch 1 taken 65004 times.
74951 if (mi->motion_model_idc)
1711 9947 ff_vvc_store_sb_mvs(lc, pu);
1712 else
1713 65004 ff_vvc_store_mv(lc, &pu->mi);
1714
1715 74951 return 0;
1716 }
1717
1718 // derive bdofFlag from 8.5.6 Decoding process for inter blocks
1719 // derive dmvr from 8.5.1 General decoding process for coding units coded in inter prediction mode
1720 338415 static void derive_dmvr_bdof_flag(const VVCLocalContext *lc, PredictionUnit *pu)
1721 {
1722 338415 const VVCFrameContext *fc = lc->fc;
1723 338415 const VVCPPS *pps = fc->ps.pps;
1724 338415 const VVCPH *ph = &fc->ps.ph;
1725 338415 const VVCSH *sh = &lc->sc->sh;
1726 338415 const int poc = ph->poc;
1727 338415 const MotionInfo *mi = &pu->mi;
1728 338415 const int8_t *ref_idx = mi->ref_idx;
1729 338415 const VVCRefPic *rp0 = &lc->sc->rpl[L0].refs[ref_idx[L0]];
1730 338415 const VVCRefPic *rp1 = &lc->sc->rpl[L1].refs[ref_idx[L1]];
1731 338415 const CodingUnit *cu = lc->cu;
1732
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 338415 times.
338415 const PredWeightTable *w = pps->r->pps_wp_info_in_ph_flag ? &fc->ps.ph.pwt : &sh->pwt;
1733
1734 338415 pu->bdof_flag = 0;
1735
1736
2/2
✓ Branch 0 taken 175583 times.
✓ Branch 1 taken 162832 times.
338415 if (mi->pred_flag == PF_BI &&
1737
2/2
✓ Branch 0 taken 117784 times.
✓ Branch 1 taken 57799 times.
175583 (poc - rp0->poc == rp1->poc - poc) &&
1738
4/4
✓ Branch 0 taken 117726 times.
✓ Branch 1 taken 58 times.
✓ Branch 2 taken 117693 times.
✓ Branch 3 taken 33 times.
117784 !rp0->is_lt && !rp1->is_lt &&
1739
2/2
✓ Branch 0 taken 114965 times.
✓ Branch 1 taken 2728 times.
117693 !cu->ciip_flag &&
1740
2/2
✓ Branch 0 taken 101469 times.
✓ Branch 1 taken 13496 times.
114965 !mi->bcw_idx &&
1741
4/4
✓ Branch 0 taken 100355 times.
✓ Branch 1 taken 1114 times.
✓ Branch 2 taken 100354 times.
✓ Branch 3 taken 1 times.
101469 !w->weight_flag[L0][LUMA][ref_idx[L0]] && !w->weight_flag[L1][LUMA][ref_idx[L1]] &&
1742
4/4
✓ Branch 0 taken 100336 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 100321 times.
✓ Branch 3 taken 15 times.
100354 !w->weight_flag[L0][CHROMA][ref_idx[L0]] && !w->weight_flag[L1][CHROMA][ref_idx[L1]] &&
1743
4/4
✓ Branch 0 taken 94569 times.
✓ Branch 1 taken 5752 times.
✓ Branch 2 taken 90981 times.
✓ Branch 3 taken 3588 times.
100321 cu->cb_width >= 8 && cu->cb_height >= 8 &&
1744
2/2
✓ Branch 0 taken 85083 times.
✓ Branch 1 taken 5898 times.
90981 (cu->cb_width * cu->cb_height >= 128) &&
1745
2/4
✓ Branch 0 taken 85083 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 85083 times.
✗ Branch 3 not taken.
85083 !rp0->is_scaled && !rp1->is_scaled) {
1746
2/2
✓ Branch 0 taken 83054 times.
✓ Branch 1 taken 2029 times.
85083 if (!ph->r->ph_bdof_disabled_flag &&
1747
1/2
✓ Branch 0 taken 83054 times.
✗ Branch 1 not taken.
83054 mi->motion_model_idc == MOTION_TRANSLATION &&
1748
1/2
✓ Branch 0 taken 83054 times.
✗ Branch 1 not taken.
83054 !pu->merge_subblock_flag &&
1749
2/2
✓ Branch 0 taken 80244 times.
✓ Branch 1 taken 2810 times.
83054 !pu->sym_mvd_flag)
1750 80244 pu->bdof_flag = 1;
1751
2/2
✓ Branch 0 taken 80597 times.
✓ Branch 1 taken 4486 times.
85083 if (!ph->r->ph_dmvr_disabled_flag &&
1752
2/2
✓ Branch 0 taken 75272 times.
✓ Branch 1 taken 5325 times.
80597 pu->general_merge_flag &&
1753
2/2
✓ Branch 0 taken 68245 times.
✓ Branch 1 taken 7027 times.
75272 !pu->mmvd_merge_flag)
1754 68245 pu->dmvr_flag = 1;
1755 }
1756 338415 }
1757
1758 // part of 8.5.1 General decoding process for coding units coded in inter prediction mode
1759 338415 static void refine_regular_subblock(const VVCLocalContext *lc)
1760 {
1761 338415 const CodingUnit *cu = lc->cu;
1762 338415 PredictionUnit *pu = &lc->cu->pu;
1763
1764 338415 derive_dmvr_bdof_flag(lc, pu);
1765
4/4
✓ Branch 0 taken 270170 times.
✓ Branch 1 taken 68245 times.
✓ Branch 2 taken 11999 times.
✓ Branch 3 taken 258171 times.
338415 if (pu->dmvr_flag || pu->bdof_flag) {
1766
2/2
✓ Branch 0 taken 47422 times.
✓ Branch 1 taken 32822 times.
80244 pu->mi.num_sb_x = (cu->cb_width > 16) ? (cu->cb_width >> 4) : 1;
1767
2/2
✓ Branch 0 taken 45341 times.
✓ Branch 1 taken 34903 times.
80244 pu->mi.num_sb_y = (cu->cb_height > 16) ? (cu->cb_height >> 4) : 1;
1768 }
1769 338415 }
1770
1771 387003 static void fill_dmvr_info(const VVCLocalContext *lc)
1772 {
1773 387003 const VVCFrameContext *fc = lc->fc;
1774 387003 const CodingUnit *cu = lc->cu;
1775
1776
3/4
✓ Branch 0 taken 355821 times.
✓ Branch 1 taken 31182 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 355821 times.
387003 if (cu->pred_mode == MODE_IBC || cu->pred_mode == MODE_PLT) {
1777
1/2
✓ Branch 0 taken 31182 times.
✗ Branch 1 not taken.
31182 ff_vvc_set_intra_mvf(lc, true, cu->pred_mode == MODE_IBC ? PF_IBC : PF_PLT, false);
1778 } else {
1779 355821 const VVCPPS *pps = fc->ps.pps;
1780 355821 const int w = cu->cb_width >> MIN_PU_LOG2;
1781
1782
2/2
✓ Branch 0 taken 1996451 times.
✓ Branch 1 taken 355821 times.
2352272 for (int y = cu->y0 >> MIN_PU_LOG2; y < (cu->y0 + cu->cb_height) >> MIN_PU_LOG2; y++) {
1783 1996451 const int idx = pps->min_pu_width * y + (cu->x0 >> MIN_PU_LOG2);
1784 1996451 const MvField *mvf = fc->tab.mvf + idx;
1785 1996451 MvField *dmvr_mvf = fc->ref->tab_dmvr_mvf + idx;
1786
1787 1996451 memcpy(dmvr_mvf, mvf, sizeof(MvField) * w);
1788 }
1789 }
1790 387003 }
1791
1792 455248 static int inter_data(VVCLocalContext *lc)
1793 {
1794 455248 const CodingUnit *cu = lc->cu;
1795 455248 PredictionUnit *pu = &lc->cu->pu;
1796 455248 const MotionInfo *mi = &pu->mi;
1797 455248 int ret = 0;
1798
1799 455248 pu->general_merge_flag = 1;
1800
2/2
✓ Branch 0 taken 209686 times.
✓ Branch 1 taken 245562 times.
455248 if (!cu->skip_flag)
1801 209686 pu->general_merge_flag = ff_vvc_general_merge_flag(lc);
1802
1803
2/2
✓ Branch 0 taken 363261 times.
✓ Branch 1 taken 91987 times.
455248 if (pu->general_merge_flag) {
1804 363261 ret = hls_merge_data(lc);
1805
2/2
✓ Branch 0 taken 17036 times.
✓ Branch 1 taken 74951 times.
91987 } else if (cu->pred_mode == MODE_IBC) {
1806 17036 ret = mvp_data_ibc(lc);
1807 } else {
1808 74951 ret = mvp_data(lc);
1809 }
1810
1811
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 455248 times.
455248 if (ret)
1812 return ret;
1813
1814
2/2
✓ Branch 0 taken 31182 times.
✓ Branch 1 taken 424066 times.
455248 if (cu->pred_mode == MODE_IBC) {
1815 31182 ff_vvc_update_hmvp(lc, mi);
1816
6/6
✓ Branch 0 taken 398451 times.
✓ Branch 1 taken 25615 times.
✓ Branch 2 taken 363728 times.
✓ Branch 3 taken 34723 times.
✓ Branch 4 taken 338415 times.
✓ Branch 5 taken 25313 times.
424066 } else if (!pu->merge_gpm_flag && !pu->inter_affine_flag && !pu->merge_subblock_flag) {
1817 338415 refine_regular_subblock(lc);
1818 338415 ff_vvc_update_hmvp(lc, mi);
1819 }
1820
1821
2/2
✓ Branch 0 taken 387003 times.
✓ Branch 1 taken 68245 times.
455248 if (!pu->dmvr_flag)
1822 387003 fill_dmvr_info(lc);
1823 455248 return ret;
1824 }
1825
1826 static TransformUnit* palette_add_tu(VVCLocalContext *lc, const int start, const int end, const VVCTreeType tree_type)
1827 {
1828 CodingUnit *cu = lc->cu;
1829 const VVCSPS *sps = lc->fc->ps.sps;
1830 TransformUnit *tu = add_tu(lc->fc, cu, cu->x0, cu->y0, cu->cb_width, cu->cb_height);
1831
1832 if (!tu)
1833 return NULL;
1834
1835 for (int c = start; c < end; c++) {
1836 const int w = tu->width >> sps->hshift[c];
1837 const int h = tu->height >> sps->vshift[c];
1838 TransformBlock *tb = add_tb(tu, lc, tu->x0, tu->y0, w, h, c);
1839 if (c != CR)
1840 set_tb_size(lc->fc, tb);
1841 }
1842
1843 for (int i = 0; i < FF_ARRAY_ELEMS(cu->plt); i++)
1844 cu->plt[i].size = 0;
1845
1846 return tu;
1847 }
1848
1849 static int palette_predicted(VVCLocalContext *lc, const bool local_dual_tree, int start, int end,
1850 bool *predictor_reused, const int predictor_size, const int max_entries)
1851 {
1852 CodingUnit *cu = lc->cu;
1853 int nb_predicted = 0;
1854
1855 if (local_dual_tree) {
1856 start = LUMA;
1857 end = VVC_MAX_SAMPLE_ARRAYS;
1858 }
1859
1860 for (int i = 0; i < predictor_size && nb_predicted < max_entries; i++) {
1861 const int run = ff_vvc_palette_predictor_run(lc, predictor_size - i);
1862 if (run < 0)
1863 return run;
1864
1865 if (run == 1)
1866 break;
1867
1868 if (run > 1)
1869 i += run - 1;
1870
1871 predictor_reused[i] = true;
1872 for (int c = start; c < end; c++)
1873 cu->plt[c].entries[nb_predicted] = lc->ep->pp[c].entries[i];
1874 nb_predicted++;
1875 }
1876
1877 for (int c = start; c < end; c++)
1878 cu->plt[c].size = nb_predicted;
1879
1880 return 0;
1881 }
1882
1883 static int palette_signaled(VVCLocalContext *lc, const bool local_dual_tree,
1884 const int start, const int end, const int max_entries)
1885 {
1886 const VVCSPS *sps = lc->fc->ps.sps;
1887 CodingUnit *cu = lc->cu;
1888 const int nb_predicted = cu->plt[start].size;
1889 const int nb_signaled = nb_predicted < max_entries ? ff_vvc_num_signalled_palette_entries(lc, max_entries - nb_predicted) : 0;
1890 const int size = nb_predicted + nb_signaled;
1891 const bool dual_tree_luma = local_dual_tree && cu->tree_type == DUAL_TREE_LUMA;
1892
1893 if (nb_signaled < 0)
1894 return AVERROR_INVALIDDATA;
1895
1896 for (int c = start; c < end; c++) {
1897 Palette *plt = cu->plt + c;
1898 for (int i = nb_predicted; i < size; i++) {
1899 plt->entries[i] = ff_vvc_new_palette_entries(lc, sps->bit_depth);
1900 if (dual_tree_luma) {
1901 plt[CB].entries[i] = 1 << (sps->bit_depth - 1);
1902 plt[CR].entries[i] = 1 << (sps->bit_depth - 1);
1903 }
1904 }
1905 plt->size = size;
1906 }
1907
1908 return 0;
1909 }
1910
1911 static void palette_update_predictor(VVCLocalContext *lc, const bool local_dual_tree, int start, int end,
1912 bool *predictor_reused, const int predictor_size)
1913 {
1914 CodingUnit *cu = lc->cu;
1915 const int max_predictor = VVC_MAX_NUM_PALETTE_PREDICTOR_SIZE >> (cu->tree_type != SINGLE_TREE && !local_dual_tree);
1916
1917 if (local_dual_tree) {
1918 start = LUMA;
1919 end = VVC_MAX_SAMPLE_ARRAYS;
1920 }
1921
1922 for (int c = start; c < end; c++) {
1923 Palette *pp = lc->ep->pp + c;
1924 Palette *plt = cu->plt + c;
1925 int i = cu->plt[start].size;;
1926
1927 // copy unused predictors to the end of plt
1928 for (int j = 0; j < predictor_size && i < max_predictor; j++) {
1929 if (!predictor_reused[j]) {
1930 plt->entries[i] = pp->entries[j];
1931 i++;
1932 }
1933 }
1934
1935 memcpy(pp->entries, plt->entries, i * sizeof(pp->entries[0]));
1936 pp->size = i;
1937 }
1938 }
1939
1940 static void palette_qp(VVCLocalContext *lc, VVCTreeType tree_type, const bool escape_present)
1941 {
1942 const VVCFrameContext *fc = lc->fc;
1943 const VVCPPS *pps = fc->ps.pps;
1944 const H266RawSliceHeader *rsh = lc->sc->sh.r;
1945 const CodingUnit *cu = lc->cu;
1946
1947 if (tree_type != DUAL_TREE_CHROMA) {
1948 const bool has_qp_delta = escape_present &&
1949 pps->r->pps_cu_qp_delta_enabled_flag && !lc->parse.is_cu_qp_delta_coded;
1950 set_qp_y(lc, cu->x0, cu->y0, has_qp_delta);
1951 }
1952
1953 if (tree_type != DUAL_TREE_LUMA) {
1954 if (rsh->sh_cu_chroma_qp_offset_enabled_flag && !lc->parse.is_cu_chroma_qp_offset_coded)
1955 chroma_qp_offset_decode(lc, 0, 1);
1956 set_qp_c(lc);
1957 }
1958 }
1959
1960 #define PALETTE_SET_PIXEL(xc, yc, pix) \
1961 do { \
1962 const int off = ((xc) >> hs) + ((yc) >> vs) * tb->tb_width; \
1963 if (sps->bit_depth == 8) \
1964 u8[off] = pix; \
1965 else \
1966 u16[off] = pix; \
1967 } while (0)
1968
1969 #define PALETTE_INDEX(x, y) index[(y) * cu->cb_width + (x)]
1970
1971 // 6.5.3 Horizontal and vertical traverse scan order array initialization process
1972 // The hTravScan and vTravScan tables require approximately 576 KB of memory.
1973 // To save space, we use a macro to achieve the same functionality.
1974 #define TRAV_COL(p, wlog, mask) ((p & mask) ^ (-((p >> wlog) & 1) & mask))
1975 #define TRAV_ROW(p, hlog) (p >> hlog)
1976 #define TRAV(trans, p, wlog, hlog, mask) (trans ? TRAV_ROW((p), hlog) : TRAV_COL((p), wlog, mask))
1977 #define TRAV_X(pos) TRAV(transpose, pos, wlog2, hlog2, wmask)
1978 #define TRAV_Y(pos) TRAV(!transpose, pos, hlog2, wlog2, hmask)
1979
1980 static int palette_subblock_data(VVCLocalContext *lc,
1981 const int max_index, const int subset_id, const bool transpose,
1982 uint8_t *run_type, uint8_t *index, int *prev_run_pos, bool *adjust)
1983 {
1984 const CodingUnit *cu = lc->cu;
1985 TransformUnit *tu = cu->tus.head;
1986 const VVCSPS *sps = lc->fc->ps.sps;
1987 const int min_pos = subset_id << 4;
1988 const int max_pos = FFMIN(min_pos + 16, cu->cb_width * cu->cb_height);
1989 const int wmask = cu->cb_width - 1;
1990 const int hmask = cu->cb_height - 1;
1991 const int wlog2 = av_log2(cu->cb_width);
1992 const int hlog2 = av_log2(cu->cb_height);
1993 const uint8_t esc = cu->plt[tu->tbs[0].c_idx].size;
1994 uint8_t run_copy[16] = { 0 };
1995
1996 for (int i = min_pos; i < max_pos; i++) {
1997 const int xc = TRAV_X(i);
1998 const int yc = TRAV_Y(i);
1999
2000 if (i > 0 && max_index > 0)
2001 run_copy[i - min_pos] = ff_vvc_run_copy_flag(lc, run_type[i - 1], *prev_run_pos, i);
2002
2003 run_type[i] = 0;
2004 if (max_index > 0 && !run_copy[i - min_pos]) {
2005 if (((!transpose && yc > 0) || (transpose && xc > 0))
2006 && i > 0 && !run_type[i - 1]) {
2007 run_type[i] = ff_vvc_copy_above_palette_indices_flag(lc);
2008 }
2009 *prev_run_pos = i;
2010 } else if (i > 0) {
2011 run_type[i] = run_type[i - 1];
2012 }
2013 }
2014
2015 for (int i = min_pos; i < max_pos; i++) {
2016 const int xc = TRAV_X(i);
2017 const int yc = TRAV_Y(i);
2018 const int prev_xc = i > 0 ? TRAV_X(i - 1) : 0;
2019 const int prev_yc = i > 0 ? TRAV_Y(i - 1) : 0;
2020
2021 int idx = 0;
2022 if (max_index > 0 && !run_copy[i - min_pos] && !run_type[i]) {
2023 if (max_index - *adjust > 0)
2024 idx = ff_vvc_palette_idx_idc(lc, max_index, *adjust);
2025 if (i > 0) {
2026 const int ref_idx = !run_type[i - 1] ?
2027 PALETTE_INDEX(prev_xc, prev_yc) : PALETTE_INDEX(xc - transpose, yc - !transpose);
2028 idx += (idx >= ref_idx);
2029 }
2030 *adjust = true;
2031 } else {
2032 idx = PALETTE_INDEX(prev_xc, prev_yc);
2033 }
2034
2035 if (!run_type[i])
2036 PALETTE_INDEX(xc, yc) = idx;
2037 else
2038 PALETTE_INDEX(xc, yc) = PALETTE_INDEX(xc - transpose, yc - !transpose);
2039 }
2040
2041 for (int c = 0; c < tu->nb_tbs; c++) {
2042 TransformBlock *tb = &tu->tbs[c];
2043 const Palette *plt = cu->plt + tb->c_idx;
2044 const int scale = ff_vvc_palette_derive_scale(lc, tu, tb);
2045 const int hs = sps->hshift[c];
2046 const int vs = sps->vshift[c];
2047 uint8_t *u8 = (uint8_t *)tb->coeffs;
2048 uint16_t *u16 = (uint16_t *)tb->coeffs;
2049
2050 for (int i = min_pos; i < max_pos; i++) {
2051 const int xc = TRAV_X(i);
2052 const int yc = TRAV_Y(i);
2053 if (!(xc & hs) && !(yc & vs)) {
2054 const int v = PALETTE_INDEX(xc, yc);
2055 if (v == esc) {
2056 const int coeff = ff_vvc_palette_escape_val(lc, (1 << sps->bit_depth) - 1);
2057 const int pixel = av_clip_intp2(RSHIFT(coeff * scale, 6), sps->bit_depth);
2058 if (coeff < 0)
2059 return AVERROR_INVALIDDATA;
2060 PALETTE_SET_PIXEL(xc, yc, pixel);
2061 } else {
2062 PALETTE_SET_PIXEL(xc, yc, plt->entries[v]);
2063 }
2064 }
2065 }
2066 }
2067
2068 return 0;
2069 }
2070
2071 static int hls_palette_coding(VVCLocalContext *lc, const VVCTreeType tree_type)
2072 {
2073 const VVCFrameContext *fc = lc->fc;
2074 const VVCSPS *sps = fc->ps.sps;
2075 const H266RawSliceHeader *rsh = lc->sc->sh.r;
2076 CodingUnit *cu = lc->cu;
2077 Palette *pp = lc->ep->pp;
2078 const int max_entries = tree_type == SINGLE_TREE ? 31 : 15;
2079 const bool local_dual_tree = tree_type != SINGLE_TREE &&
2080 (!IS_I(rsh) || (IS_I(rsh) && !sps->r->sps_qtbtt_dual_tree_intra_flag));
2081 bool escape_present = false;
2082 bool transpose = false;
2083 bool adjust = false;
2084 int max_index = 0;
2085 int prev_run_pos = 0;
2086
2087 int predictor_size, start, end, ret;
2088 bool reused[VVC_MAX_NUM_PALETTE_PREDICTOR_SIZE];
2089 uint8_t run_type[MAX_PALETTE_CU_SIZE * MAX_PALETTE_CU_SIZE];
2090 uint8_t index[MAX_PALETTE_CU_SIZE * MAX_PALETTE_CU_SIZE];
2091
2092 ff_vvc_channel_range(&start, &end, tree_type, sps->r->sps_chroma_format_idc);
2093
2094 if (!palette_add_tu(lc, start, end, tree_type))
2095 return AVERROR(ENOMEM);
2096
2097 predictor_size = pp[start].size;
2098 memset(reused, 0, sizeof(reused[0]) * predictor_size);
2099
2100 ret = palette_predicted(lc, local_dual_tree, start, end, reused, predictor_size, max_entries);
2101 if (ret < 0)
2102 return ret;
2103
2104 ret = palette_signaled(lc, local_dual_tree, start, end, max_entries);
2105 if (ret < 0)
2106 return ret;
2107
2108 palette_update_predictor(lc, local_dual_tree, start, end, reused, predictor_size);
2109
2110 if (cu->plt[start].size > 0)
2111 escape_present = ff_vvc_palette_escape_val_present_flag(lc);
2112
2113 max_index = cu->plt[start].size - 1 + escape_present;
2114 if (max_index > 0) {
2115 adjust = false;
2116 transpose = ff_vvc_palette_transpose_flag(lc);
2117 }
2118
2119 palette_qp(lc, tree_type, escape_present);
2120
2121 index[0] = 0;
2122 for (int i = 0; i <= (cu->cb_width * cu->cb_height - 1) >> 4; i++) {
2123 ret = palette_subblock_data(lc, max_index, i, transpose,
2124 run_type, index, &prev_run_pos, &adjust);
2125 if (ret < 0)
2126 return ret;
2127 }
2128
2129 return 0;
2130 }
2131
2132 777873 static int intra_data(VVCLocalContext *lc)
2133 {
2134 777873 const VVCSPS *sps = lc->fc->ps.sps;
2135 777873 const CodingUnit *cu = lc->cu;
2136 777873 const VVCTreeType tree_type = cu->tree_type;
2137 777873 const bool pred_mode_plt_flag = cu->pred_mode == MODE_PLT;
2138 777873 int ret = 0;
2139
2140
4/4
✓ Branch 0 taken 716525 times.
✓ Branch 1 taken 61348 times.
✓ Branch 2 taken 535368 times.
✓ Branch 3 taken 181157 times.
777873 if (tree_type == SINGLE_TREE || tree_type == DUAL_TREE_LUMA) {
2141
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 596716 times.
596716 if (pred_mode_plt_flag) {
2142 if ((ret = hls_palette_coding(lc, tree_type)) < 0)
2143 return ret;
2144 ff_vvc_set_intra_mvf(lc, false, PF_PLT, false);
2145 } else {
2146 596716 intra_luma_pred_modes(lc);
2147 596716 ff_vvc_set_intra_mvf(lc, false, PF_INTRA, cu->ciip_flag);
2148 }
2149 }
2150
6/6
✓ Branch 0 taken 716525 times.
✓ Branch 1 taken 61348 times.
✓ Branch 2 taken 181157 times.
✓ Branch 3 taken 535368 times.
✓ Branch 4 taken 227383 times.
✓ Branch 5 taken 15122 times.
777873 if ((tree_type == SINGLE_TREE || tree_type == DUAL_TREE_CHROMA) && sps->r->sps_chroma_format_idc) {
2151
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 227383 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
227383 if (pred_mode_plt_flag && tree_type == DUAL_TREE_CHROMA) {
2152 if ((ret = hls_palette_coding(lc, tree_type)) < 0)
2153 return ret;
2154
1/2
✓ Branch 0 taken 227383 times.
✗ Branch 1 not taken.
227383 } else if (!pred_mode_plt_flag) {
2155 227383 intra_chroma_pred_modes(lc);
2156 }
2157 }
2158
2159 777873 return ret;
2160 }
2161
2162 1233121 static int hls_coding_unit(VVCLocalContext *lc, int x0, int y0, int cb_width, int cb_height,
2163 int cqt_depth, const VVCTreeType tree_type, VVCModeType mode_type)
2164 {
2165 1233121 const VVCFrameContext *fc = lc->fc;
2166 1233121 const VVCSPS *sps = fc->ps.sps;
2167 1233121 const H266RawSliceHeader *rsh = lc->sc->sh.r;
2168
4/4
✓ Branch 0 taken 1210812 times.
✓ Branch 1 taken 22309 times.
✓ Branch 2 taken 2293 times.
✓ Branch 3 taken 1208519 times.
1233121 const int is_128 = cb_width > 64 || cb_height > 64;
2169 1233121 int ret = 0;
2170
2171 1233121 CodingUnit *cu = add_cu(lc, x0, y0, cb_width, cb_height, cqt_depth, tree_type);
2172
2173
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1233121 times.
1233121 if (!cu)
2174 return AVERROR(ENOMEM);
2175
2176 1233121 ff_vvc_set_neighbour_available(lc, cu->x0, cu->y0, cu->cb_width, cu->cb_height);
2177
2178
3/4
✓ Branch 0 taken 649380 times.
✓ Branch 1 taken 583741 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 649380 times.
1233121 if (IS_I(rsh) && is_128)
2179 mode_type = MODE_TYPE_INTRA;
2180 1233121 cu->pred_mode = pred_mode_decode(lc, tree_type, mode_type);
2181
2182
3/6
✓ Branch 0 taken 777873 times.
✓ Branch 1 taken 455248 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 777873 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
1233121 if (cu->pred_mode == MODE_INTRA && sps->r->sps_act_enabled_flag && tree_type == SINGLE_TREE)
2183 cu->act_enabled_flag = ff_vvc_cu_act_enabled_flag(lc);
2184
2185
3/4
✓ Branch 0 taken 455248 times.
✓ Branch 1 taken 777873 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 455248 times.
1233121 if (cu->pred_mode == MODE_INTRA || cu->pred_mode == MODE_PLT)
2186 777873 ret = intra_data(lc);
2187
1/2
✓ Branch 0 taken 455248 times.
✗ Branch 1 not taken.
455248 else if (tree_type != DUAL_TREE_CHROMA) /* MODE_INTER or MODE_IBC */
2188 455248 ret = inter_data(lc);
2189
2190
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1233121 times.
1233121 if (ret < 0)
2191 return ret;
2192
2193
5/6
✓ Branch 0 taken 455248 times.
✓ Branch 1 taken 777873 times.
✓ Branch 2 taken 455248 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 91987 times.
✓ Branch 5 taken 363261 times.
1233121 if (cu->pred_mode != MODE_INTRA && cu->pred_mode != MODE_PLT && !lc->cu->pu.general_merge_flag)
2194 91987 cu->coded_flag = ff_vvc_cu_coded_flag(lc);
2195 else
2196
3/4
✓ Branch 0 taken 895572 times.
✓ Branch 1 taken 245562 times.
✓ Branch 2 taken 895572 times.
✗ Branch 3 not taken.
1141134 cu->coded_flag = !(cu->skip_flag || cu->pred_mode == MODE_PLT);
2197
2198
2/2
✓ Branch 0 taken 938287 times.
✓ Branch 1 taken 294834 times.
1233121 if (cu->coded_flag) {
2199 938287 sbt_info(lc, sps);
2200
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 938287 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
938287 if (sps->r->sps_act_enabled_flag && cu->pred_mode != MODE_INTRA && tree_type == SINGLE_TREE)
2201 cu->act_enabled_flag = ff_vvc_cu_act_enabled_flag(lc);
2202 938287 lc->parse.lfnst_dc_only = 1;
2203 938287 lc->parse.lfnst_zero_out_sig_coeff_flag = 1;
2204 938287 lc->parse.mts_dc_only = 1;
2205 938287 lc->parse.mts_zero_out_sig_coeff_flag = 1;
2206 938287 ret = hls_transform_tree(lc, x0, y0, cb_width, cb_height, cu->ch_type);
2207
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 938287 times.
938287 if (ret < 0)
2208 return ret;
2209 938287 cu->lfnst_idx = lfnst_idx_decode(lc);
2210 938287 cu->mts_idx = mts_idx_decode(lc);
2211 938287 set_qp_c(lc);
2212
1/2
✓ Branch 0 taken 294834 times.
✗ Branch 1 not taken.
294834 } else if (cu->pred_mode != MODE_PLT) {
2213 294834 ret = skipped_transform_tree_unit(lc);
2214
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 294834 times.
294834 if (ret < 0)
2215 return ret;
2216 }
2217 1233121 set_cu_tabs(lc, cu);
2218
2219 1233121 return 0;
2220 }
2221
2222 799192 static int derive_mode_type_condition(const VVCLocalContext *lc,
2223 const VVCSplitMode split, const int cb_width, const int cb_height, const VVCModeType mode_type_curr)
2224 {
2225 799192 const H266RawSliceHeader *rsh = lc->sc->sh.r;
2226 799192 const VVCSPS *sps = lc->fc->ps.sps;
2227 799192 const int area = cb_width * cb_height;
2228
2229
6/6
✓ Branch 0 taken 435203 times.
✓ Branch 1 taken 363989 times.
✓ Branch 2 taken 10978 times.
✓ Branch 3 taken 424225 times.
✓ Branch 4 taken 340623 times.
✓ Branch 5 taken 34344 times.
799192 if ((IS_I(rsh) && sps->r->sps_qtbtt_dual_tree_intra_flag) ||
2230
2/2
✓ Branch 0 taken 316444 times.
✓ Branch 1 taken 24179 times.
340623 mode_type_curr != MODE_TYPE_ALL || !sps->r->sps_chroma_format_idc ||
2231
2/2
✓ Branch 0 taken 41943 times.
✓ Branch 1 taken 274501 times.
316444 sps->r->sps_chroma_format_idc == CHROMA_FORMAT_444)
2232 524691 return 0;
2233
8/10
✓ Branch 0 taken 20837 times.
✓ Branch 1 taken 253664 times.
✓ Branch 2 taken 18554 times.
✓ Branch 3 taken 2283 times.
✓ Branch 4 taken 18554 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 15678 times.
✓ Branch 7 taken 2876 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 269342 times.
274501 if ((area == 64 && (split == SPLIT_QT || split == SPLIT_TT_HOR || split == SPLIT_TT_VER)) ||
2234 (area == 32 && (split == SPLIT_BT_HOR || split == SPLIT_BT_VER)))
2235 5159 return 1;
2236
8/10
✓ Branch 0 taken 15678 times.
✓ Branch 1 taken 253664 times.
✓ Branch 2 taken 10067 times.
✓ Branch 3 taken 5611 times.
✓ Branch 4 taken 10067 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 15678 times.
✓ Branch 8 taken 30659 times.
✓ Branch 9 taken 223005 times.
269342 if ((area == 64 && (split == SPLIT_BT_HOR || split == SPLIT_BT_VER) && sps->r->sps_chroma_format_idc == CHROMA_FORMAT_420) ||
2237
7/8
✓ Branch 0 taken 27262 times.
✓ Branch 1 taken 3397 times.
✓ Branch 2 taken 5439 times.
✓ Branch 3 taken 21823 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 8836 times.
✓ Branch 6 taken 21471 times.
✓ Branch 7 taken 223357 times.
253664 (area == 128 && (split == SPLIT_TT_HOR || split == SPLIT_TT_VER) && sps->r->sps_chroma_format_idc == CHROMA_FORMAT_420) ||
2238
6/6
✓ Branch 0 taken 14300 times.
✓ Branch 1 taken 7171 times.
✓ Branch 2 taken 69699 times.
✓ Branch 3 taken 167958 times.
✓ Branch 4 taken 9832 times.
✓ Branch 5 taken 59867 times.
244828 (cb_width == 8 && split == SPLIT_BT_VER) || (cb_width == 16 && split == SPLIT_TT_VER))
2239
2/2
✓ Branch 0 taken 41362 times.
✓ Branch 1 taken 155 times.
41517 return 1 + !IS_I(rsh);
2240
2241 227825 return 0;
2242 }
2243
2244 799192 static VVCModeType mode_type_decode(VVCLocalContext *lc, const int x0, const int y0,
2245 const int cb_width, const int cb_height, const VVCSplitMode split, const int ch_type,
2246 const VVCModeType mode_type_curr)
2247 {
2248 VVCModeType mode_type;
2249 799192 const int mode_type_condition = derive_mode_type_condition(lc, split, cb_width, cb_height, mode_type_curr);
2250
2251
2/2
✓ Branch 0 taken 5314 times.
✓ Branch 1 taken 793878 times.
799192 if (mode_type_condition == 1)
2252 5314 mode_type = MODE_TYPE_INTRA;
2253
2/2
✓ Branch 0 taken 41362 times.
✓ Branch 1 taken 752516 times.
793878 else if (mode_type_condition == 2) {
2254
2/2
✓ Branch 1 taken 19181 times.
✓ Branch 2 taken 22181 times.
41362 mode_type = ff_vvc_non_inter_flag(lc, x0, y0, ch_type) ? MODE_TYPE_INTRA : MODE_TYPE_INTER;
2255 } else {
2256 752516 mode_type = mode_type_curr;
2257 }
2258
2259 799192 return mode_type;
2260 }
2261
2262 static int hls_coding_tree(VVCLocalContext *lc,
2263 int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2264 int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset, int part_idx,
2265 VVCSplitMode last_split_mode, VVCTreeType tree_type_curr, VVCModeType mode_type_curr);
2266
2267 240419 static int coding_tree_btv(VVCLocalContext *lc,
2268 int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2269 int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset,
2270 VVCTreeType tree_type, VVCModeType mode_type)
2271 {
2272 #define CODING_TREE(x, idx) do { \
2273 ret = hls_coding_tree(lc, x, y0, cb_width / 2, cb_height, \
2274 qg_on_y, qg_on_c, cb_sub_div + 1, cqt_depth, mtt_depth + 1, \
2275 depth_offset, idx, SPLIT_BT_VER, tree_type, mode_type); \
2276 if (ret < 0) \
2277 return ret; \
2278 } while (0);
2279
2280 240419 const VVCPPS *pps = lc->fc->ps.pps;
2281 240419 const int x1 = x0 + cb_width / 2;
2282 240419 int ret = 0;
2283
2284 240419 depth_offset += (x0 + cb_width > pps->width) ? 1 : 0;
2285
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 240419 times.
240419 CODING_TREE(x0, 0);
2286
2/2
✓ Branch 0 taken 238988 times.
✓ Branch 1 taken 1431 times.
240419 if (x1 < pps->width)
2287
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 238988 times.
238988 CODING_TREE(x1, 1);
2288
2289 240419 return 0;
2290
2291 #undef CODING_TREE
2292 }
2293
2294 294079 static int coding_tree_bth(VVCLocalContext *lc,
2295 int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2296 int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset,
2297 VVCTreeType tree_type, VVCModeType mode_type)
2298 {
2299 #define CODING_TREE(y, idx) do { \
2300 ret = hls_coding_tree(lc, x0, y, cb_width , cb_height / 2, \
2301 qg_on_y, qg_on_c, cb_sub_div + 1, cqt_depth, mtt_depth + 1, \
2302 depth_offset, idx, SPLIT_BT_HOR, tree_type, mode_type); \
2303 if (ret < 0) \
2304 return ret; \
2305 } while (0);
2306
2307 294079 const VVCPPS *pps = lc->fc->ps.pps;
2308 294079 const int y1 = y0 + (cb_height / 2);
2309 294079 int ret = 0;
2310
2311 294079 depth_offset += (y0 + cb_height > pps->height) ? 1 : 0;
2312
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 294079 times.
294079 CODING_TREE(y0, 0);
2313
2/2
✓ Branch 0 taken 276468 times.
✓ Branch 1 taken 17611 times.
294079 if (y1 < pps->height)
2314
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 276468 times.
276468 CODING_TREE(y1, 1);
2315
2316 294079 return 0;
2317
2318 #undef CODING_TREE
2319 }
2320
2321 80770 static int coding_tree_ttv(VVCLocalContext *lc,
2322 int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2323 int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset,
2324 VVCTreeType tree_type, VVCModeType mode_type)
2325 {
2326 #define CODING_TREE(x, w, sub_div, idx) do { \
2327 ret = hls_coding_tree(lc, x, y0, w, cb_height, \
2328 qg_on_y, qg_on_c, sub_div, cqt_depth, mtt_depth + 1, \
2329 depth_offset, idx, SPLIT_TT_VER, tree_type, mode_type); \
2330 if (ret < 0) \
2331 return ret; \
2332 } while (0);
2333
2334 80770 const VVCSH *sh = &lc->sc->sh;
2335 80770 const int x1 = x0 + cb_width / 4;
2336 80770 const int x2 = x0 + cb_width * 3 / 4;
2337 int ret;
2338
2339
3/4
✓ Branch 0 taken 47252 times.
✓ Branch 1 taken 33518 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 47252 times.
80770 qg_on_y = qg_on_y && (cb_sub_div + 2 <= sh->cu_qp_delta_subdiv);
2340
3/4
✓ Branch 0 taken 33933 times.
✓ Branch 1 taken 46837 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 33933 times.
80770 qg_on_c = qg_on_c && (cb_sub_div + 2 <= sh->cu_chroma_qp_offset_subdiv);
2341
2342
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 80770 times.
80770 CODING_TREE(x0, cb_width / 4, cb_sub_div + 2, 0);
2343
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 80770 times.
80770 CODING_TREE(x1, cb_width / 2, cb_sub_div + 1, 1);
2344
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 80770 times.
80770 CODING_TREE(x2, cb_width / 4, cb_sub_div + 2, 2);
2345
2346 80770 return 0;
2347
2348 #undef CODING_TREE
2349 }
2350
2351 84349 static int coding_tree_tth(VVCLocalContext *lc,
2352 int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2353 int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset,
2354 VVCTreeType tree_type, VVCModeType mode_type)
2355 {
2356 #define CODING_TREE(y, h, sub_div, idx) do { \
2357 ret = hls_coding_tree(lc, x0, y, cb_width, h, \
2358 qg_on_y, qg_on_c, sub_div, cqt_depth, mtt_depth + 1, \
2359 depth_offset, idx, SPLIT_TT_HOR, tree_type, mode_type); \
2360 if (ret < 0) \
2361 return ret; \
2362 } while (0);
2363
2364 84349 const VVCSH *sh = &lc->sc->sh;
2365 84349 const int y1 = y0 + (cb_height / 4);
2366 84349 const int y2 = y0 + (3 * cb_height / 4);
2367 int ret;
2368
2369
3/4
✓ Branch 0 taken 47704 times.
✓ Branch 1 taken 36645 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 47704 times.
84349 qg_on_y = qg_on_y && (cb_sub_div + 2 <= sh->cu_qp_delta_subdiv);
2370
3/4
✓ Branch 0 taken 30129 times.
✓ Branch 1 taken 54220 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 30129 times.
84349 qg_on_c = qg_on_c && (cb_sub_div + 2 <= sh->cu_chroma_qp_offset_subdiv);
2371
2372
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 84349 times.
84349 CODING_TREE(y0, cb_height / 4, cb_sub_div + 2, 0);
2373
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 84349 times.
84349 CODING_TREE(y1, cb_height / 2, cb_sub_div + 1, 1);
2374
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 84349 times.
84349 CODING_TREE(y2, cb_height / 4, cb_sub_div + 2, 2);
2375
2376 84349 return 0;
2377
2378 #undef CODING_TREE
2379 }
2380
2381 99575 static int coding_tree_qt(VVCLocalContext *lc,
2382 int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2383 int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset,
2384 VVCTreeType tree_type, VVCModeType mode_type)
2385 {
2386 #define CODING_TREE(x, y, idx) do { \
2387 ret = hls_coding_tree(lc, x, y, cb_width / 2, cb_height / 2, \
2388 qg_on_y, qg_on_c, cb_sub_div + 2, cqt_depth + 1, 0, 0, \
2389 idx, SPLIT_QT, tree_type, mode_type); \
2390 if (ret < 0) \
2391 return ret; \
2392 } while (0);
2393
2394 99575 const VVCPPS *pps = lc->fc->ps.pps;
2395 99575 const int x1 = x0 + cb_width / 2;
2396 99575 const int y1 = y0 + cb_height / 2;
2397 99575 int ret = 0;
2398
2399
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 99575 times.
99575 CODING_TREE(x0, y0, 0);
2400
2/2
✓ Branch 0 taken 96396 times.
✓ Branch 1 taken 3179 times.
99575 if (x1 < pps->width)
2401
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 96396 times.
96396 CODING_TREE(x1, y0, 1);
2402
2/2
✓ Branch 0 taken 94102 times.
✓ Branch 1 taken 5473 times.
99575 if (y1 < pps->height)
2403
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 94102 times.
94102 CODING_TREE(x0, y1, 2);
2404
2/2
✓ Branch 0 taken 96396 times.
✓ Branch 1 taken 3179 times.
99575 if (x1 < pps->width &&
2405
2/2
✓ Branch 0 taken 90931 times.
✓ Branch 1 taken 5465 times.
96396 y1 < pps->height)
2406
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 90931 times.
90931 CODING_TREE(x1, y1, 3);
2407
2408 99575 return 0;
2409
2410 #undef CODING_TREE
2411 }
2412
2413 typedef int (*coding_tree_fn)(VVCLocalContext *lc,
2414 int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2415 int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset,
2416 VVCTreeType tree_type, VVCModeType mode_type);
2417
2418 const static coding_tree_fn coding_tree[] = {
2419 coding_tree_tth,
2420 coding_tree_bth,
2421 coding_tree_ttv,
2422 coding_tree_btv,
2423 coding_tree_qt,
2424 };
2425
2426 2032313 static int hls_coding_tree(VVCLocalContext *lc,
2427 int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2428 int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset, int part_idx,
2429 VVCSplitMode last_split_mode, VVCTreeType tree_type_curr, VVCModeType mode_type_curr)
2430 {
2431 2032313 VVCFrameContext *fc = lc->fc;
2432 2032313 const VVCPPS *pps = fc->ps.pps;
2433 2032313 const VVCSH *sh = &lc->sc->sh;
2434 2032313 const H266RawSliceHeader *rsh = sh->r;
2435 2032313 const int ch_type = tree_type_curr == DUAL_TREE_CHROMA;
2436 int ret;
2437 VVCAllowedSplit allowed;
2438
2439
6/6
✓ Branch 0 taken 280702 times.
✓ Branch 1 taken 1751611 times.
✓ Branch 2 taken 70213 times.
✓ Branch 3 taken 210489 times.
✓ Branch 4 taken 2635 times.
✓ Branch 5 taken 67578 times.
2032313 if (pps->r->pps_cu_qp_delta_enabled_flag && qg_on_y && cb_sub_div <= sh->cu_qp_delta_subdiv) {
2440 2635 lc->parse.is_cu_qp_delta_coded = 0;
2441 2635 lc->parse.cu_qg_top_left_x = x0;
2442 2635 lc->parse.cu_qg_top_left_y = y0;
2443 }
2444
4/4
✓ Branch 0 taken 206481 times.
✓ Branch 1 taken 1825832 times.
✓ Branch 2 taken 17504 times.
✓ Branch 3 taken 188977 times.
2032313 if (rsh->sh_cu_chroma_qp_offset_enabled_flag && qg_on_c &&
2445
2/2
✓ Branch 0 taken 931 times.
✓ Branch 1 taken 16573 times.
17504 cb_sub_div <= sh->cu_chroma_qp_offset_subdiv) {
2446 931 lc->parse.is_cu_chroma_qp_offset_coded = 0;
2447 931 memset(lc->parse.chroma_qp_offset, 0, sizeof(lc->parse.chroma_qp_offset));
2448 }
2449
2450 2032313 can_split(lc, x0, y0, cb_width, cb_height, mtt_depth, depth_offset, part_idx,
2451 last_split_mode, tree_type_curr, mode_type_curr, &allowed);
2452
2/2
✓ Branch 1 taken 799192 times.
✓ Branch 2 taken 1233121 times.
2032313 if (ff_vvc_split_cu_flag(lc, x0, y0, cb_width, cb_height, ch_type, &allowed)) {
2453 799192 VVCSplitMode split = ff_vvc_split_mode(lc, x0, y0, cb_width, cb_height, cqt_depth, mtt_depth, ch_type, &allowed);
2454 799192 VVCModeType mode_type = mode_type_decode(lc, x0, y0, cb_width, cb_height, split, ch_type, mode_type_curr);
2455
2456
2/2
✓ Branch 0 taken 746164 times.
✓ Branch 1 taken 53028 times.
799192 VVCTreeType tree_type = (mode_type == MODE_TYPE_INTRA) ? DUAL_TREE_LUMA : tree_type_curr;
2457
2458
2/2
✓ Branch 0 taken 699617 times.
✓ Branch 1 taken 99575 times.
799192 if (split != SPLIT_QT) {
2459
6/6
✓ Branch 0 taken 425989 times.
✓ Branch 1 taken 273628 times.
✓ Branch 2 taken 277741 times.
✓ Branch 3 taken 148248 times.
✓ Branch 4 taken 233866 times.
✓ Branch 5 taken 43875 times.
699617 if (!(x0 & 31) && !(y0 & 31) && mtt_depth <= 1)
2460 233866 TAB_MSM(fc, mtt_depth, x0, y0) = split;
2461 }
2462 799192 ret = coding_tree[split - 1](lc, x0, y0, cb_width, cb_height, qg_on_y, qg_on_c,
2463 cb_sub_div, cqt_depth, mtt_depth, depth_offset, tree_type, mode_type);
2464
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 799192 times.
799192 if (ret < 0)
2465 return ret;
2466
4/4
✓ Branch 0 taken 764848 times.
✓ Branch 1 taken 34344 times.
✓ Branch 2 taken 24495 times.
✓ Branch 3 taken 740353 times.
799192 if (mode_type_curr == MODE_TYPE_ALL && mode_type == MODE_TYPE_INTRA) {
2467 24495 ret = hls_coding_tree(lc, x0, y0, cb_width, cb_height, 0, qg_on_c, cb_sub_div,
2468 cqt_depth, mtt_depth, 0, 0, split, DUAL_TREE_CHROMA, mode_type);
2469
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24495 times.
24495 if (ret < 0)
2470 return ret;
2471 }
2472 } else {
2473 1233121 ret = hls_coding_unit(lc, x0, y0, cb_width, cb_height, cqt_depth, tree_type_curr, mode_type_curr);
2474
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1233121 times.
1233121 if (ret < 0)
2475 return ret;
2476 }
2477
2478 2032313 return 0;
2479 }
2480
2481 25529 static int dual_tree_implicit_qt_split(VVCLocalContext *lc,
2482 const int x0, const int y0, const int cb_size, const int cqt_depth)
2483 {
2484 25529 const VVCSH *sh = &lc->sc->sh;
2485 25529 const H266RawSliceHeader *rsh = sh->r;
2486 25529 const VVCPPS *pps = lc->fc->ps.pps;
2487 25529 const int cb_subdiv = 2 * cqt_depth;
2488 int ret;
2489
2490
2/2
✓ Branch 0 taken 5284 times.
✓ Branch 1 taken 20245 times.
25529 if (cb_size > 64) {
2491 #define DUAL_TREE(x, y) do { \
2492 ret = dual_tree_implicit_qt_split(lc, x, y, cb_size / 2, cqt_depth + 1); \
2493 if (ret < 0) \
2494 return ret; \
2495 } while (0)
2496
2497 5284 const int x1 = x0 + (cb_size / 2);
2498 5284 const int y1 = y0 + (cb_size / 2);
2499
3/4
✓ Branch 0 taken 130 times.
✓ Branch 1 taken 5154 times.
✓ Branch 2 taken 130 times.
✗ Branch 3 not taken.
5284 if (pps->r->pps_cu_qp_delta_enabled_flag && cb_subdiv <= sh->cu_qp_delta_subdiv) {
2500 130 lc->parse.is_cu_qp_delta_coded = 0;
2501 130 lc->parse.cu_qg_top_left_x = x0;
2502 130 lc->parse.cu_qg_top_left_y = y0;
2503 }
2504
3/4
✓ Branch 0 taken 98 times.
✓ Branch 1 taken 5186 times.
✓ Branch 2 taken 98 times.
✗ Branch 3 not taken.
5284 if (rsh->sh_cu_chroma_qp_offset_enabled_flag && cb_subdiv <= sh->cu_chroma_qp_offset_subdiv) {
2505 98 lc->parse.is_cu_chroma_qp_offset_coded = 0;
2506 98 memset(lc->parse.chroma_qp_offset, 0, sizeof(lc->parse.chroma_qp_offset));
2507 }
2508
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 5284 times.
5284 DUAL_TREE(x0, y0);
2509
2/2
✓ Branch 0 taken 5121 times.
✓ Branch 1 taken 163 times.
5284 if (x1 < pps->width)
2510
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 5121 times.
5121 DUAL_TREE(x1, y0);
2511
2/2
✓ Branch 0 taken 4792 times.
✓ Branch 1 taken 492 times.
5284 if (y1 < pps->height)
2512
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4792 times.
4792 DUAL_TREE(x0, y1);
2513
4/4
✓ Branch 0 taken 5121 times.
✓ Branch 1 taken 163 times.
✓ Branch 2 taken 4632 times.
✓ Branch 3 taken 489 times.
5284 if (x1 < pps->width && y1 < pps->height)
2514
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4632 times.
4632 DUAL_TREE(x1, y1);
2515 #undef DUAL_TREE
2516 } else {
2517 #define CODING_TREE(tree_type) do { \
2518 const int qg_on_y = tree_type == DUAL_TREE_LUMA; \
2519 ret = hls_coding_tree(lc, x0, y0, cb_size, cb_size, qg_on_y, !qg_on_y, \
2520 cb_subdiv, cqt_depth, 0, 0, 0, SPLIT_NONE, tree_type, MODE_TYPE_ALL); \
2521 if (ret < 0) \
2522 return ret; \
2523 } while (0)
2524
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 20245 times.
20245 CODING_TREE(DUAL_TREE_LUMA);
2525
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 20245 times.
20245 CODING_TREE(DUAL_TREE_CHROMA);
2526 #undef CODING_TREE
2527 }
2528 25529 return 0;
2529 }
2530
2531 #define SET_SAO(elem, value) \
2532 do { \
2533 if (!sao_merge_up_flag && !sao_merge_left_flag) \
2534 sao->elem = value; \
2535 else if (sao_merge_left_flag) \
2536 sao->elem = CTB(fc->tab.sao, rx-1, ry).elem; \
2537 else if (sao_merge_up_flag) \
2538 sao->elem = CTB(fc->tab.sao, rx, ry-1).elem; \
2539 else \
2540 sao->elem = 0; \
2541 } while (0)
2542
2543 46713 static void hls_sao(VVCLocalContext *lc, const int rx, const int ry)
2544 {
2545 46713 VVCFrameContext *fc = lc->fc;
2546 46713 const H266RawSliceHeader *rsh = lc->sc->sh.r;
2547 46713 int sao_merge_left_flag = 0;
2548 46713 int sao_merge_up_flag = 0;
2549 46713 SAOParams *sao = &CTB(fc->tab.sao, rx, ry);
2550 int c_idx, i;
2551
2552
4/4
✓ Branch 0 taken 28597 times.
✓ Branch 1 taken 18116 times.
✓ Branch 2 taken 164 times.
✓ Branch 3 taken 28433 times.
46713 if (rsh->sh_sao_luma_used_flag || rsh->sh_sao_chroma_used_flag) {
2553
2/2
✓ Branch 0 taken 16476 times.
✓ Branch 1 taken 1804 times.
18280 if (rx > 0) {
2554
2/2
✓ Branch 0 taken 15659 times.
✓ Branch 1 taken 817 times.
16476 if (lc->ctb_left_flag)
2555 15659 sao_merge_left_flag = ff_vvc_sao_merge_flag_decode(lc);
2556 }
2557
4/4
✓ Branch 0 taken 15151 times.
✓ Branch 1 taken 3129 times.
✓ Branch 2 taken 8308 times.
✓ Branch 3 taken 6843 times.
18280 if (ry > 0 && !sao_merge_left_flag) {
2558
2/2
✓ Branch 0 taken 7507 times.
✓ Branch 1 taken 801 times.
8308 if (lc->ctb_up_flag)
2559 7507 sao_merge_up_flag = ff_vvc_sao_merge_flag_decode(lc);
2560 }
2561 }
2562
2563
4/4
✓ Branch 0 taken 184740 times.
✓ Branch 1 taken 1056 times.
✓ Branch 2 taken 139083 times.
✓ Branch 3 taken 46713 times.
185796 for (c_idx = 0; c_idx < (fc->ps.sps->r->sps_chroma_format_idc ? 3 : 1); c_idx++) {
2564
2/2
✓ Branch 0 taken 46713 times.
✓ Branch 1 taken 92370 times.
139083 const int sao_used_flag = !c_idx ? rsh->sh_sao_luma_used_flag : rsh->sh_sao_chroma_used_flag;
2565
2/2
✓ Branch 0 taken 99435 times.
✓ Branch 1 taken 39648 times.
139083 if (!sao_used_flag) {
2566 99435 sao->type_idx[c_idx] = SAO_NOT_APPLIED;
2567 99435 continue;
2568 }
2569
2570
2/2
✓ Branch 0 taken 10766 times.
✓ Branch 1 taken 28882 times.
39648 if (c_idx == 2) {
2571 10766 sao->type_idx[2] = sao->type_idx[1];
2572 10766 sao->eo_class[2] = sao->eo_class[1];
2573 } else {
2574
7/8
✓ Branch 0 taken 25369 times.
✓ Branch 1 taken 3513 times.
✓ Branch 2 taken 13142 times.
✓ Branch 3 taken 12227 times.
✓ Branch 5 taken 12227 times.
✓ Branch 6 taken 3513 times.
✓ Branch 7 taken 3513 times.
✗ Branch 8 not taken.
28882 SET_SAO(type_idx[c_idx], ff_vvc_sao_type_idx_decode(lc));
2575 }
2576
2577
2/2
✓ Branch 0 taken 25087 times.
✓ Branch 1 taken 14561 times.
39648 if (sao->type_idx[c_idx] == SAO_NOT_APPLIED)
2578 25087 continue;
2579
2580
2/2
✓ Branch 0 taken 58244 times.
✓ Branch 1 taken 14561 times.
72805 for (i = 0; i < 4; i++)
2581
7/8
✓ Branch 0 taken 49040 times.
✓ Branch 1 taken 9204 times.
✓ Branch 2 taken 22592 times.
✓ Branch 3 taken 26448 times.
✓ Branch 5 taken 26448 times.
✓ Branch 6 taken 9204 times.
✓ Branch 7 taken 9204 times.
✗ Branch 8 not taken.
58244 SET_SAO(offset_abs[c_idx][i], ff_vvc_sao_offset_abs_decode(lc));
2582
2583
2/2
✓ Branch 0 taken 5154 times.
✓ Branch 1 taken 9407 times.
14561 if (sao->type_idx[c_idx] == SAO_BAND) {
2584
2/2
✓ Branch 0 taken 20616 times.
✓ Branch 1 taken 5154 times.
25770 for (i = 0; i < 4; i++) {
2585
2/2
✓ Branch 0 taken 6974 times.
✓ Branch 1 taken 13642 times.
20616 if (sao->offset_abs[c_idx][i]) {
2586
7/8
✓ Branch 0 taken 6222 times.
✓ Branch 1 taken 752 times.
✓ Branch 2 taken 2475 times.
✓ Branch 3 taken 3747 times.
✓ Branch 5 taken 3747 times.
✓ Branch 6 taken 752 times.
✓ Branch 7 taken 752 times.
✗ Branch 8 not taken.
6974 SET_SAO(offset_sign[c_idx][i],
2587 ff_vvc_sao_offset_sign_decode(lc));
2588 } else {
2589 13642 sao->offset_sign[c_idx][i] = 0;
2590 }
2591 }
2592
7/8
✓ Branch 0 taken 4541 times.
✓ Branch 1 taken 613 times.
✓ Branch 2 taken 1357 times.
✓ Branch 3 taken 3184 times.
✓ Branch 5 taken 3184 times.
✓ Branch 6 taken 613 times.
✓ Branch 7 taken 613 times.
✗ Branch 8 not taken.
5154 SET_SAO(band_position[c_idx], ff_vvc_sao_band_position_decode(lc));
2593
2/2
✓ Branch 0 taken 7423 times.
✓ Branch 1 taken 1984 times.
9407 } else if (c_idx != 2) {
2594
7/8
✓ Branch 0 taken 6057 times.
✓ Branch 1 taken 1366 times.
✓ Branch 2 taken 3179 times.
✓ Branch 3 taken 2878 times.
✓ Branch 5 taken 2878 times.
✓ Branch 6 taken 1366 times.
✓ Branch 7 taken 1366 times.
✗ Branch 8 not taken.
7423 SET_SAO(eo_class[c_idx], ff_vvc_sao_eo_class_decode(lc));
2595 }
2596
2597 // Inferred parameters
2598 14561 sao->offset_val[c_idx][0] = 0;
2599
2/2
✓ Branch 0 taken 58244 times.
✓ Branch 1 taken 14561 times.
72805 for (i = 0; i < 4; i++) {
2600 58244 sao->offset_val[c_idx][i + 1] = sao->offset_abs[c_idx][i];
2601
2/2
✓ Branch 0 taken 37628 times.
✓ Branch 1 taken 20616 times.
58244 if (sao->type_idx[c_idx] == SAO_EDGE) {
2602
2/2
✓ Branch 0 taken 18814 times.
✓ Branch 1 taken 18814 times.
37628 if (i > 1)
2603 18814 sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1];
2604
2/2
✓ Branch 0 taken 5562 times.
✓ Branch 1 taken 15054 times.
20616 } else if (sao->offset_sign[c_idx][i]) {
2605 5562 sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1];
2606 }
2607 58244 sao->offset_val[c_idx][i + 1] *= 1 << (fc->ps.sps->bit_depth - FFMIN(10, fc->ps.sps->bit_depth));
2608 }
2609 }
2610 46713 }
2611
2612 46713 static void alf_params(VVCLocalContext *lc, const int rx, const int ry)
2613 {
2614 46713 const VVCFrameContext *fc = lc->fc;
2615 46713 const H266RawSliceHeader *sh = lc->sc->sh.r;
2616 46713 ALFParams *alf = &CTB(fc->tab.alf, rx, ry);
2617
2618 46713 alf->ctb_flag[LUMA] = alf->ctb_flag[CB] = alf->ctb_flag[CR] = 0;
2619 46713 alf->ctb_cc_idc[0] = alf->ctb_cc_idc[1] = 0;
2620
2/2
✓ Branch 0 taken 27186 times.
✓ Branch 1 taken 19527 times.
46713 if (sh->sh_alf_enabled_flag) {
2621 27186 alf->ctb_flag[LUMA] = ff_vvc_alf_ctb_flag(lc, rx, ry, LUMA);
2622
2/2
✓ Branch 0 taken 19555 times.
✓ Branch 1 taken 7631 times.
27186 if (alf->ctb_flag[LUMA]) {
2623 19555 uint8_t alf_use_aps_flag = 0;
2624
2/2
✓ Branch 0 taken 18747 times.
✓ Branch 1 taken 808 times.
19555 if (sh->sh_num_alf_aps_ids_luma > 0)
2625 18747 alf_use_aps_flag = ff_vvc_alf_use_aps_flag(lc);
2626
2/2
✓ Branch 0 taken 16780 times.
✓ Branch 1 taken 2775 times.
19555 if (alf_use_aps_flag) {
2627 16780 alf->ctb_filt_set_idx_y = 16;
2628
2/2
✓ Branch 0 taken 4928 times.
✓ Branch 1 taken 11852 times.
16780 if (sh->sh_num_alf_aps_ids_luma > 1)
2629 4928 alf->ctb_filt_set_idx_y += ff_vvc_alf_luma_prev_filter_idx(lc);
2630 } else {
2631 2775 alf->ctb_filt_set_idx_y = ff_vvc_alf_luma_fixed_filter_idx(lc);
2632 }
2633 }
2634
2/2
✓ Branch 0 taken 54372 times.
✓ Branch 1 taken 27186 times.
81558 for (int c_idx = CB; c_idx <= CR; c_idx++) {
2635
2/2
✓ Branch 0 taken 27186 times.
✓ Branch 1 taken 27186 times.
54372 const uint8_t alf_enabled_flag =
2636 c_idx == CB ? sh->sh_alf_cb_enabled_flag : sh->sh_alf_cr_enabled_flag;
2637
2/2
✓ Branch 0 taken 32256 times.
✓ Branch 1 taken 22116 times.
54372 if (alf_enabled_flag) {
2638 32256 const VVCALF *aps = fc->ps.alf_list[sh->sh_alf_aps_id_chroma];
2639 32256 alf->ctb_flag[c_idx] = ff_vvc_alf_ctb_flag(lc, rx, ry, c_idx);
2640 32256 alf->alf_ctb_filter_alt_idx[c_idx - 1] = 0;
2641
4/4
✓ Branch 0 taken 24205 times.
✓ Branch 1 taken 8051 times.
✓ Branch 2 taken 16033 times.
✓ Branch 3 taken 8172 times.
32256 if (alf->ctb_flag[c_idx] && aps->num_chroma_filters > 1)
2642 16033 alf->alf_ctb_filter_alt_idx[c_idx - 1] = ff_vvc_alf_ctb_filter_alt_idx(lc, c_idx, aps->num_chroma_filters);
2643 }
2644 }
2645 }
2646
2/2
✓ Branch 0 taken 36147 times.
✓ Branch 1 taken 10566 times.
46713 if (fc->ps.sps->r->sps_ccalf_enabled_flag) {
2647 36147 const uint8_t cc_enabled[] = { sh->sh_alf_cc_cb_enabled_flag, sh->sh_alf_cc_cr_enabled_flag };
2648 36147 const uint8_t cc_aps_id[] = { sh->sh_alf_cc_cb_aps_id, sh->sh_alf_cc_cr_aps_id };
2649
2/2
✓ Branch 0 taken 72294 times.
✓ Branch 1 taken 36147 times.
108441 for (int i = 0; i < 2; i++) {
2650
2/2
✓ Branch 0 taken 22625 times.
✓ Branch 1 taken 49669 times.
72294 if (cc_enabled[i]) {
2651 22625 const VVCALF *aps = fc->ps.alf_list[cc_aps_id[i]];
2652 22625 alf->ctb_cc_idc[i] = ff_vvc_alf_ctb_cc_idc(lc, rx, ry, i, aps->num_cc_filters[i]);
2653 }
2654 }
2655 }
2656 46713 }
2657
2658 46713 static void deblock_params(VVCLocalContext *lc, const int rx, const int ry)
2659 {
2660 46713 VVCFrameContext *fc = lc->fc;
2661 46713 const VVCSH *sh = &lc->sc->sh;
2662 46713 CTB(fc->tab.deblock, rx, ry) = sh->deblock;
2663 46713 }
2664
2665 46713 static int hls_coding_tree_unit(VVCLocalContext *lc,
2666 const int x0, const int y0, const int ctu_idx, const int rx, const int ry)
2667 {
2668 46713 const VVCFrameContext *fc = lc->fc;
2669 46713 const VVCSPS *sps = fc->ps.sps;
2670 46713 const VVCPPS *pps = fc->ps.pps;
2671 46713 const VVCSH *sh = &lc->sc->sh;
2672 46713 const H266RawSliceHeader *rsh = sh->r;
2673 46713 const unsigned int ctb_size = sps->ctb_size_y;
2674 46713 int ret = 0;
2675
2676 46713 memset(lc->parse.chroma_qp_offset, 0, sizeof(lc->parse.chroma_qp_offset));
2677
2678 46713 hls_sao(lc, x0 >> sps->ctb_log2_size_y, y0 >> sps->ctb_log2_size_y);
2679 46713 alf_params(lc, x0 >> sps->ctb_log2_size_y, y0 >> sps->ctb_log2_size_y);
2680 46713 deblock_params(lc, x0 >> sps->ctb_log2_size_y, y0 >> sps->ctb_log2_size_y);
2681
2682
4/4
✓ Branch 0 taken 5896 times.
✓ Branch 1 taken 40817 times.
✓ Branch 2 taken 5700 times.
✓ Branch 3 taken 196 times.
46713 if (IS_I(rsh) && sps->r->sps_qtbtt_dual_tree_intra_flag)
2683 5700 ret = dual_tree_implicit_qt_split(lc, x0, y0, ctb_size, 0);
2684 else
2685 41013 ret = hls_coding_tree(lc, x0, y0, ctb_size, ctb_size,
2686 1, 1, 0, 0, 0, 0, 0, SPLIT_NONE, SINGLE_TREE, MODE_TYPE_ALL);
2687
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46713 times.
46713 if (ret < 0)
2688 return ret;
2689
2690
2/2
✓ Branch 0 taken 5833 times.
✓ Branch 1 taken 40880 times.
46713 if (rx == pps->ctb_to_col_bd[rx + 1] - 1) {
2691
2/2
✓ Branch 0 taken 1711 times.
✓ Branch 1 taken 4122 times.
5833 if (ctu_idx == sh->num_ctus_in_curr_slice - 1) {
2692 1711 const int end_of_slice_one_bit = ff_vvc_end_of_slice_flag_decode(lc);
2693
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1711 times.
1711 if (!end_of_slice_one_bit)
2694 return AVERROR_INVALIDDATA;
2695 } else {
2696
2/2
✓ Branch 0 taken 493 times.
✓ Branch 1 taken 3629 times.
4122 if (ry == pps->ctb_to_row_bd[ry + 1] - 1) {
2697 493 const int end_of_tile_one_bit = ff_vvc_end_of_tile_one_bit(lc);
2698
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 493 times.
493 if (!end_of_tile_one_bit)
2699 return AVERROR_INVALIDDATA;
2700 } else {
2701
2/2
✓ Branch 0 taken 153 times.
✓ Branch 1 taken 3476 times.
3629 if (fc->ps.sps->r->sps_entropy_coding_sync_enabled_flag) {
2702 153 const int end_of_subset_one_bit = ff_vvc_end_of_subset_one_bit(lc);
2703
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 153 times.
153 if (!end_of_subset_one_bit)
2704 return AVERROR_INVALIDDATA;
2705 }
2706 }
2707 }
2708 }
2709
2710 46713 return 0;
2711 }
2712
2713 583741 static int has_inter_luma(const CodingUnit *cu)
2714 {
2715
4/6
✓ Branch 0 taken 447542 times.
✓ Branch 1 taken 136199 times.
✓ Branch 2 taken 447542 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 447542 times.
✗ Branch 5 not taken.
583741 return cu->pred_mode != MODE_INTRA && cu->pred_mode != MODE_PLT && cu->tree_type != DUAL_TREE_CHROMA;
2716 }
2717
2718 8050651 static int pred_get_y(const VVCLocalContext *lc, const int y0, const Mv *mv, const int height)
2719 {
2720 8050651 const VVCPPS *pps = lc->fc->ps.pps;
2721 8050651 const int idx = lc->sc->sh.r->curr_subpic_idx;
2722 8050651 const int top = pps->subpic_y[idx];
2723 8050651 const int bottom = top + pps->subpic_height[idx];
2724
2725 8050651 return av_clip(y0 + (mv->y >> 4) + height, top, bottom);
2726 }
2727
2728 447542 static void cu_get_max_y(const CodingUnit *cu, int max_y[2][VVC_MAX_REF_ENTRIES], const VVCLocalContext *lc)
2729 {
2730 447542 const VVCFrameContext *fc = lc->fc;
2731 447542 const PredictionUnit *pu = &cu->pu;
2732
2733
2/2
✓ Branch 0 taken 25615 times.
✓ Branch 1 taken 421927 times.
447542 if (pu->merge_gpm_flag) {
2734
2/2
✓ Branch 0 taken 51230 times.
✓ Branch 1 taken 25615 times.
76845 for (int i = 0; i < FF_ARRAY_ELEMS(pu->gpm_mv); i++) {
2735 51230 const MvField *mvf = pu->gpm_mv + i;
2736 51230 const int lx = mvf->pred_flag - PF_L0;
2737 51230 const int idx = mvf->ref_idx[lx];
2738 51230 const int y = pred_get_y(lc, cu->y0, mvf->mv + lx, cu->cb_height);
2739
2740 51230 max_y[lx][idx] = FFMAX(max_y[lx][idx], y);
2741 }
2742 } else {
2743 421927 const MotionInfo *mi = &pu->mi;
2744
4/4
✓ Branch 0 taken 387204 times.
✓ Branch 1 taken 34723 times.
✓ Branch 2 taken 68245 times.
✓ Branch 3 taken 318959 times.
421927 const int max_dmvr_off = (!pu->inter_affine_flag && pu->dmvr_flag) ? 2 : 0;
2745 421927 const int sbw = cu->cb_width / mi->num_sb_x;
2746 421927 const int sbh = cu->cb_height / mi->num_sb_y;
2747
2/2
✓ Branch 0 taken 886922 times.
✓ Branch 1 taken 421927 times.
1308849 for (int sby = 0; sby < mi->num_sb_y; sby++) {
2748
2/2
✓ Branch 0 taken 5545694 times.
✓ Branch 1 taken 886922 times.
6432616 for (int sbx = 0; sbx < mi->num_sb_x; sbx++) {
2749 5545694 const int x0 = cu->x0 + sbx * sbw;
2750 5545694 const int y0 = cu->y0 + sby * sbh;
2751 5545694 const MvField *mvf = ff_vvc_get_mvf(fc, x0, y0);
2752
2/2
✓ Branch 0 taken 11091388 times.
✓ Branch 1 taken 5545694 times.
16637082 for (int lx = 0; lx < 2; lx++) {
2753 11091388 const PredFlag mask = 1 << lx;
2754
2/2
✓ Branch 0 taken 7999421 times.
✓ Branch 1 taken 3091967 times.
11091388 if (mvf->pred_flag & mask) {
2755 7999421 const int idx = mvf->ref_idx[lx];
2756 7999421 const int y = pred_get_y(lc, y0, mvf->mv + lx, sbh);
2757
2758 7999421 max_y[lx][idx] = FFMAX(max_y[lx][idx], y + max_dmvr_off);
2759 }
2760 }
2761 }
2762 }
2763 }
2764 447542 }
2765
2766 46713 static void ctu_get_pred(VVCLocalContext *lc, const int rs)
2767 {
2768 46713 const VVCFrameContext *fc = lc->fc;
2769 46713 const H266RawSliceHeader *rsh = lc->sc->sh.r;
2770 46713 CTU *ctu = fc->tab.ctus + rs;
2771 46713 const CodingUnit *cu = fc->tab.cus[rs];
2772
2773 46713 ctu->has_dmvr = 0;
2774
2775
2/2
✓ Branch 0 taken 5896 times.
✓ Branch 1 taken 40817 times.
46713 if (IS_I(rsh))
2776 5896 return;
2777
2778
2/2
✓ Branch 0 taken 81634 times.
✓ Branch 1 taken 40817 times.
122451 for (int lx = 0; lx < 2; lx++)
2779 81634 memset(ctu->max_y[lx], -1, sizeof(ctu->max_y[0][0]) * rsh->num_ref_idx_active[lx]);
2780
2781
2/2
✓ Branch 0 taken 583741 times.
✓ Branch 1 taken 40817 times.
624558 while (cu) {
2782
2/2
✓ Branch 1 taken 447542 times.
✓ Branch 2 taken 136199 times.
583741 if (has_inter_luma(cu)) {
2783 447542 cu_get_max_y(cu, ctu->max_y, lc);
2784 447542 ctu->has_dmvr |= cu->pu.dmvr_flag;
2785 }
2786 583741 cu = cu->next;
2787 }
2788 40817 ctu->max_y_idx[0] = ctu->max_y_idx[1] = 0;
2789 }
2790
2791 46713 int ff_vvc_coding_tree_unit(VVCLocalContext *lc,
2792 const int ctu_idx, const int rs, const int rx, const int ry)
2793 {
2794 46713 const VVCFrameContext *fc = lc->fc;
2795 46713 const VVCSPS *sps = fc->ps.sps;
2796 46713 const VVCPPS *pps = fc->ps.pps;
2797 46713 const int x_ctb = rx << sps->ctb_log2_size_y;
2798 46713 const int y_ctb = ry << sps->ctb_log2_size_y;
2799 46713 const int ctb_size = 1 << sps->ctb_log2_size_y << sps->ctb_log2_size_y;
2800 46713 EntryPoint* ep = lc->ep;
2801 int ret;
2802
2803
2/2
✓ Branch 0 taken 5833 times.
✓ Branch 1 taken 40880 times.
46713 if (rx == pps->ctb_to_col_bd[rx]) {
2804 5833 ep->num_hmvp = 0;
2805 5833 ep->num_hmvp_ibc = 0;
2806
4/4
✓ Branch 0 taken 3741 times.
✓ Branch 1 taken 2092 times.
✓ Branch 2 taken 112 times.
✓ Branch 3 taken 3629 times.
5833 ep->is_first_qg = ry == pps->ctb_to_row_bd[ry] || !ctu_idx;
2807 }
2808
2809 46713 lc->coeffs = fc->tab.coeffs + rs * ctb_size * VVC_MAX_SAMPLE_ARRAYS;
2810 46713 lc->cu = NULL;
2811
2812 46713 ff_vvc_cabac_init(lc, ctu_idx, rx, ry);
2813 46713 ff_vvc_decode_neighbour(lc, x_ctb, y_ctb, rx, ry, rs);
2814 46713 ret = hls_coding_tree_unit(lc, x_ctb, y_ctb, ctu_idx, rx, ry);
2815
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46713 times.
46713 if (ret < 0)
2816 return ret;
2817 46713 ctu_get_pred(lc, rs);
2818
2819 46713 return 0;
2820 }
2821
2822 316521 void ff_vvc_decode_neighbour(VVCLocalContext *lc, const int x_ctb, const int y_ctb,
2823 const int rx, const int ry, const int rs)
2824 {
2825 316521 VVCFrameContext *fc = lc->fc;
2826 316521 const int ctb_size = fc->ps.sps->ctb_size_y;
2827
2828 316521 lc->end_of_tiles_x = fc->ps.pps->width;
2829 316521 lc->end_of_tiles_y = fc->ps.pps->height;
2830
2/2
✓ Branch 0 taken 40042 times.
✓ Branch 1 taken 276479 times.
316521 if (fc->ps.pps->ctb_to_col_bd[rx] != fc->ps.pps->ctb_to_col_bd[rx + 1])
2831 40042 lc->end_of_tiles_x = FFMIN(x_ctb + ctb_size, lc->end_of_tiles_x);
2832
2/2
✓ Branch 0 taken 64630 times.
✓ Branch 1 taken 251891 times.
316521 if (fc->ps.pps->ctb_to_row_bd[ry] != fc->ps.pps->ctb_to_row_bd[ry + 1])
2833 64630 lc->end_of_tiles_y = FFMIN(y_ctb + ctb_size, lc->end_of_tiles_y);
2834
2835 316521 lc->boundary_flags = 0;
2836
4/4
✓ Branch 0 taken 287658 times.
✓ Branch 1 taken 28863 times.
✓ Branch 2 taken 11179 times.
✓ Branch 3 taken 276479 times.
316521 if (rx > 0 && fc->ps.pps->ctb_to_col_bd[rx] != fc->ps.pps->ctb_to_col_bd[rx - 1])
2837 11179 lc->boundary_flags |= BOUNDARY_LEFT_TILE;
2838
4/4
✓ Branch 0 taken 287658 times.
✓ Branch 1 taken 28863 times.
✓ Branch 2 taken 5425 times.
✓ Branch 3 taken 282233 times.
316521 if (rx > 0 && fc->tab.slice_idx[rs] != fc->tab.slice_idx[rs - 1])
2839 5425 lc->boundary_flags |= BOUNDARY_LEFT_SLICE;
2840
4/4
✓ Branch 0 taken 266430 times.
✓ Branch 1 taken 50091 times.
✓ Branch 2 taken 14539 times.
✓ Branch 3 taken 251891 times.
316521 if (ry > 0 && fc->ps.pps->ctb_to_row_bd[ry] != fc->ps.pps->ctb_to_row_bd[ry - 1])
2841 14539 lc->boundary_flags |= BOUNDARY_UPPER_TILE;
2842
4/4
✓ Branch 0 taken 266430 times.
✓ Branch 1 taken 50091 times.
✓ Branch 2 taken 12341 times.
✓ Branch 3 taken 254089 times.
316521 if (ry > 0 && fc->tab.slice_idx[rs] != fc->tab.slice_idx[rs - fc->ps.pps->ctb_width])
2843 12341 lc->boundary_flags |= BOUNDARY_UPPER_SLICE;
2844
2/2
✓ Branch 0 taken 31026 times.
✓ Branch 1 taken 285495 times.
316521 if (fc->ps.sps->r->sps_subpic_ctu_top_left_x[lc->sc->sh.r->curr_subpic_idx] == rx)
2845 31026 lc->boundary_flags |= BOUNDARY_LEFT_SUBPIC;
2846
2/2
✓ Branch 0 taken 52674 times.
✓ Branch 1 taken 263847 times.
316521 if (fc->ps.sps->r->sps_subpic_ctu_top_left_y[lc->sc->sh.r->curr_subpic_idx] == ry)
2847 52674 lc->boundary_flags |= BOUNDARY_UPPER_SUBPIC;
2848
4/4
✓ Branch 0 taken 287658 times.
✓ Branch 1 taken 28863 times.
✓ Branch 2 taken 276479 times.
✓ Branch 3 taken 11179 times.
316521 lc->ctb_left_flag = rx > 0 && !(lc->boundary_flags & BOUNDARY_LEFT_TILE);
2849
6/6
✓ Branch 0 taken 266430 times.
✓ Branch 1 taken 50091 times.
✓ Branch 2 taken 251891 times.
✓ Branch 3 taken 14539 times.
✓ Branch 4 taken 249539 times.
✓ Branch 5 taken 2352 times.
316521 lc->ctb_up_flag = ry > 0 && !(lc->boundary_flags & BOUNDARY_UPPER_TILE) && !(lc->boundary_flags & BOUNDARY_UPPER_SLICE);
2850
4/4
✓ Branch 0 taken 249539 times.
✓ Branch 1 taken 66982 times.
✓ Branch 2 taken 224818 times.
✓ Branch 3 taken 24721 times.
541339 lc->ctb_up_right_flag = lc->ctb_up_flag && (fc->ps.pps->ctb_to_col_bd[rx] == fc->ps.pps->ctb_to_col_bd[rx + 1]) &&
2851
1/2
✓ Branch 0 taken 224818 times.
✗ Branch 1 not taken.
224818 (fc->ps.pps->ctb_to_row_bd[ry] == fc->ps.pps->ctb_to_row_bd[ry - 1]);
2852
4/4
✓ Branch 0 taken 276479 times.
✓ Branch 1 taken 40042 times.
✓ Branch 2 taken 224818 times.
✓ Branch 3 taken 51661 times.
316521 lc->ctb_up_left_flag = lc->ctb_left_flag && lc->ctb_up_flag;
2853 316521 }
2854
2855 2659049 void ff_vvc_set_neighbour_available(VVCLocalContext *lc,
2856 const int x0, const int y0, const int w, const int h)
2857 {
2858 2659049 const int log2_ctb_size = lc->fc->ps.sps->ctb_log2_size_y;
2859 2659049 const int x0b = av_zero_extend(x0, log2_ctb_size);
2860 2659049 const int y0b = av_zero_extend(y0, log2_ctb_size);
2861
2862
4/4
✓ Branch 0 taken 818345 times.
✓ Branch 1 taken 1840704 times.
✓ Branch 2 taken 732362 times.
✓ Branch 3 taken 85983 times.
2659049 lc->na.cand_up = (lc->ctb_up_flag || y0b);
2863
4/4
✓ Branch 0 taken 537818 times.
✓ Branch 1 taken 2121231 times.
✓ Branch 2 taken 468937 times.
✓ Branch 3 taken 68881 times.
2659049 lc->na.cand_left = (lc->ctb_left_flag || x0b);
2864
8/8
✓ Branch 0 taken 404060 times.
✓ Branch 1 taken 2254989 times.
✓ Branch 2 taken 297016 times.
✓ Branch 3 taken 107044 times.
✓ Branch 4 taken 2497125 times.
✓ Branch 5 taken 54880 times.
✓ Branch 6 taken 2434278 times.
✓ Branch 7 taken 62847 times.
2659049 lc->na.cand_up_left = (x0b || y0b) ? lc->na.cand_left && lc->na.cand_up : lc->ctb_up_left_flag;
2865 2659049 lc->na.cand_up_right_sap =
2866
6/6
✓ Branch 0 taken 374517 times.
✓ Branch 1 taken 2284532 times.
✓ Branch 2 taken 256784 times.
✓ Branch 3 taken 117733 times.
✓ Branch 4 taken 75350 times.
✓ Branch 5 taken 181434 times.
2659049 (x0b + w == 1 << log2_ctb_size) ? lc->ctb_up_right_flag && !y0b : lc->na.cand_up;
2867
4/4
✓ Branch 0 taken 2295356 times.
✓ Branch 1 taken 363693 times.
✓ Branch 2 taken 2273086 times.
✓ Branch 3 taken 22270 times.
2659049 lc->na.cand_up_right = lc->na.cand_up_right_sap && (x0 + w) < lc->end_of_tiles_x;
2868 2659049 }
2869
2870 93546 void ff_vvc_ctu_free_cus(CodingUnit **cus)
2871 {
2872
2/2
✓ Branch 0 taken 1233121 times.
✓ Branch 1 taken 93546 times.
1326667 while (*cus) {
2873 1233121 CodingUnit *cu = *cus;
2874 1233121 TransformUnit **head = &cu->tus.head;
2875
2876 1233121 *cus = cu->next;
2877
2878
2/2
✓ Branch 0 taken 1493040 times.
✓ Branch 1 taken 1233121 times.
2726161 while (*head) {
2879 1493040 TransformUnit *tu = *head;
2880 1493040 *head = tu->next;
2881 1493040 av_refstruct_unref(&tu);
2882 }
2883 1233121 cu->tus.tail = NULL;
2884
2885 1233121 av_refstruct_unref(&cu);
2886 }
2887 93546 }
2888
2889 15563970 int ff_vvc_get_qPy(const VVCFrameContext *fc, const int xc, const int yc)
2890 {
2891 15563970 const int min_cb_log2_size_y = fc->ps.sps->min_cb_log2_size_y;
2892 15563970 const int x = xc >> min_cb_log2_size_y;
2893 15563970 const int y = yc >> min_cb_log2_size_y;
2894 15563970 return fc->tab.qp[LUMA][x + y * fc->ps.pps->min_cb_width];
2895 }
2896
2897 2357 void ff_vvc_ep_init_stat_coeff(EntryPoint *ep,
2898 const int bit_depth, const int persistent_rice_adaptation_enabled_flag)
2899 {
2900
2/2
✓ Branch 0 taken 7071 times.
✓ Branch 1 taken 2357 times.
9428 for (size_t i = 0; i < FF_ARRAY_ELEMS(ep->stat_coeff); ++i) {
2901 7071 ep->stat_coeff[i] =
2902
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7071 times.
7071 persistent_rice_adaptation_enabled_flag ? 2 * (av_log2(bit_depth - 10)) : 0;
2903 }
2904 2357 }
2905
2906 484959 void ff_vvc_channel_range(int *start, int *end, const VVCTreeType tree_type, const uint8_t chroma_format_idc)
2907 {
2908
4/4
✓ Branch 0 taken 468448 times.
✓ Branch 1 taken 16511 times.
✓ Branch 2 taken 360116 times.
✓ Branch 3 taken 108332 times.
484959 const bool has_chroma = chroma_format_idc && tree_type != DUAL_TREE_LUMA;
2909 484959 const bool has_luma = tree_type != DUAL_TREE_CHROMA;
2910
2911 484959 *start = has_luma ? LUMA : CB;
2912
2/2
✓ Branch 0 taken 360116 times.
✓ Branch 1 taken 124843 times.
484959 *end = has_chroma ? VVC_MAX_SAMPLE_ARRAYS : CB;
2913 484959 }
2914