FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/vvc/ctu.c
Date: 2025-06-23 20:06:14
Exec Total Coverage
Lines: 1623 1857 87.4%
Functions: 82 89 92.1%
Branches: 1402 1740 80.6%

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