FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/vvc/ctu.c
Date: 2025-08-19 23:55:23
Exec Total Coverage
Lines: 1821 1866 97.6%
Functions: 89 89 100.0%
Branches: 1589 1744 91.1%

Line Branch Exec Source
1 /*
2 * VVC CTU(Coding Tree Unit) parser
3 *
4 * Copyright (C) 2022 Nuo Mi
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include "libavutil/error.h"
24 #include "libavutil/refstruct.h"
25
26 #include "cabac.h"
27 #include "ctu.h"
28 #include "inter.h"
29 #include "intra.h"
30 #include "mvs.h"
31
32 #define PROF_TEMP_SIZE (PROF_BLOCK_SIZE) * sizeof(int16_t)
33
34 #define TAB_MSM(fc, depth, x, y) fc->tab.msm[(depth)][((y) >> 5) * fc->ps.pps->width32 + ((x) >> 5)]
35 #define TAB_ISPMF(fc, x, y) fc->tab.ispmf[((y) >> 6) * fc->ps.pps->width64 + ((x) >> 6)]
36
37 typedef enum VVCModeType {
38 MODE_TYPE_ALL,
39 MODE_TYPE_INTER,
40 MODE_TYPE_INTRA,
41 } VVCModeType;
42
43 2367841 static void set_tb_size(const VVCFrameContext *fc, const TransformBlock *tb)
44 {
45 2367841 const int x_tb = tb->x0 >> MIN_TU_LOG2;
46 2367841 const int y_tb = tb->y0 >> MIN_TU_LOG2;
47 2367841 const int hs = fc->ps.sps->hshift[tb->c_idx];
48 2367841 const int vs = fc->ps.sps->vshift[tb->c_idx];
49 2367841 const int is_chroma = tb->c_idx != 0;
50 2367841 const int width = FFMAX(1, tb->tb_width >> (MIN_TU_LOG2 - hs));
51 2367841 const int end = y_tb + FFMAX(1, tb->tb_height >> (MIN_TU_LOG2 - vs));
52
53
2/2
✓ Branch 0 taken 11301638 times.
✓ Branch 1 taken 2367841 times.
13669479 for (int y = y_tb; y < end; y++) {
54 11301638 const int off = y * fc->ps.pps->min_tu_width + x_tb;
55 11301638 memset(fc->tab.tb_width [is_chroma] + off, tb->tb_width, width);
56 11301638 memset(fc->tab.tb_height[is_chroma] + off, tb->tb_height, width);
57 }
58 2367841 }
59
60 3261949 static void set_tb_tab(uint8_t *tab, uint8_t v, const VVCFrameContext *fc,
61 const TransformBlock *tb)
62 {
63 3261949 const int width = tb->tb_width << fc->ps.sps->hshift[tb->c_idx];
64 3261949 const int height = tb->tb_height << fc->ps.sps->vshift[tb->c_idx];
65
66
2/2
✓ Branch 0 taken 15229013 times.
✓ Branch 1 taken 3261949 times.
18490962 for (int h = 0; h < height; h += MIN_TU_SIZE) {
67 15229013 const int y = (tb->y0 + h) >> MIN_TU_LOG2;
68 15229013 const int off = y * fc->ps.pps->min_tu_width + (tb->x0 >> MIN_TU_LOG2);
69 15229013 const int w = FFMAX(1, width >> MIN_TU_LOG2);
70 15229013 memset(tab + off, v, w);
71 }
72 3261949 }
73
74 // 8.7.1 Derivation process for quantization parameters
75 2765 static int get_qp_y_pred(const VVCLocalContext *lc)
76 {
77 2765 const VVCFrameContext *fc = lc->fc;
78 2765 const VVCSPS *sps = fc->ps.sps;
79 2765 const VVCPPS *pps = fc->ps.pps;
80 2765 const CodingUnit *cu = lc->cu;
81 2765 const int ctb_log2_size = sps->ctb_log2_size_y;
82 2765 const int ctb_size_mask = (1 << ctb_log2_size) - 1;
83 2765 const int xQg = lc->parse.cu_qg_top_left_x;
84 2765 const int yQg = lc->parse.cu_qg_top_left_y;
85 2765 const int min_cb_width = fc->ps.pps->min_cb_width;
86 2765 const int x_cb = cu->x0 >> sps->min_cb_log2_size_y;
87 2765 const int y_cb = cu->y0 >> sps->min_cb_log2_size_y;
88 2765 const int rx = cu->x0 >> ctb_log2_size;
89 2765 const int ry = cu->y0 >> ctb_log2_size;
90
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2765 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2765 const int in_same_ctb_a = ((xQg - 1) >> ctb_log2_size) == rx && (yQg >> ctb_log2_size) == ry;
91
2/4
✓ Branch 0 taken 2765 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2765 times.
2765 const int in_same_ctb_b = (xQg >> ctb_log2_size) == rx && ((yQg - 1) >> ctb_log2_size) == ry;
92 int qPy_pred, qPy_a, qPy_b;
93
94
2/2
✓ Branch 0 taken 1681 times.
✓ Branch 1 taken 1084 times.
2765 if (lc->na.cand_up) {
95
2/4
✓ Branch 0 taken 1681 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1681 times.
✗ Branch 3 not taken.
1681 const int first_qg_in_ctu = !(xQg & ctb_size_mask) && !(yQg & ctb_size_mask);
96 1681 const int qPy_up = fc->tab.qp[LUMA][x_cb + (y_cb - 1) * min_cb_width];
97
3/4
✓ Branch 0 taken 1681 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 438 times.
✓ Branch 3 taken 1243 times.
1681 if (first_qg_in_ctu && pps->ctb_to_col_bd[xQg >> ctb_log2_size] == xQg >> ctb_log2_size)
98 438 return qPy_up;
99 }
100
101 // qPy_pred
102
2/2
✓ Branch 0 taken 429 times.
✓ Branch 1 taken 1898 times.
2327 qPy_pred = lc->ep->is_first_qg ? lc->sc->sh.slice_qp_y : lc->ep->qp_y;
103
104 // qPy_b
105
3/4
✓ Branch 0 taken 1243 times.
✓ Branch 1 taken 1084 times.
✓ Branch 2 taken 1243 times.
✗ Branch 3 not taken.
2327 if (!lc->na.cand_up || !in_same_ctb_b)
106 2327 qPy_b = qPy_pred;
107 else
108 qPy_b = fc->tab.qp[LUMA][x_cb + (y_cb - 1) * min_cb_width];
109
110 // qPy_a
111
3/4
✓ Branch 0 taken 1898 times.
✓ Branch 1 taken 429 times.
✓ Branch 2 taken 1898 times.
✗ Branch 3 not taken.
2327 if (!lc->na.cand_left || !in_same_ctb_a)
112 2327 qPy_a = qPy_pred;
113 else
114 qPy_a = fc->tab.qp[LUMA][(x_cb - 1) + y_cb * min_cb_width];
115
116 av_assert2(qPy_a >= -fc->ps.sps->qp_bd_offset && qPy_a <= 63);
117 av_assert2(qPy_b >= -fc->ps.sps->qp_bd_offset && qPy_b <= 63);
118
119 2327 return (qPy_a + qPy_b + 1) >> 1;
120 }
121
122 9689310 static void set_cb_tab(const VVCLocalContext *lc, uint8_t *tab, const uint8_t v)
123 {
124 9689310 const VVCFrameContext *fc = lc->fc;
125 9689310 const VVCPPS *pps = fc->ps.pps;
126 9689310 const CodingUnit *cu = lc->cu;
127 9689310 const int log2_min_cb_size = fc->ps.sps->min_cb_log2_size_y;
128 9689310 const int x_cb = cu->x0 >> log2_min_cb_size;
129 9689310 const int y_cb = cu->y0 >> log2_min_cb_size;
130 9689310 const int cb_width = cu->cb_width;
131 9689310 const int cb_height = cu->cb_height;
132 9689310 int x = y_cb * pps->min_cb_width + x_cb;
133
134
2/2
✓ Branch 0 taken 41541733 times.
✓ Branch 1 taken 9689310 times.
51231043 for (int y = 0; y < (cb_height >> log2_min_cb_size); y++) {
135 41541733 const int width = cb_width >> log2_min_cb_size;
136
137 41541733 memset(&tab[x], v, width);
138 41541733 x += pps->min_cb_width;
139 }
140 9689310 }
141
142 1360483 static int set_qp_y(VVCLocalContext *lc, const int x0, const int y0, const int has_qp_delta)
143 {
144 1360483 const VVCSPS *sps = lc->fc->ps.sps;
145 1360483 EntryPoint *ep = lc->ep;
146 1360483 CodingUnit *cu = lc->cu;
147 1360483 int cu_qp_delta = 0;
148
149
2/2
✓ Branch 0 taken 1193033 times.
✓ Branch 1 taken 167450 times.
1360483 if (!lc->fc->ps.pps->r->pps_cu_qp_delta_enabled_flag) {
150 1193033 ep->qp_y = lc->sc->sh.slice_qp_y;
151
6/6
✓ Branch 0 taken 167021 times.
✓ Branch 1 taken 429 times.
✓ Branch 2 taken 15446 times.
✓ Branch 3 taken 151575 times.
✓ Branch 4 taken 2336 times.
✓ Branch 5 taken 13110 times.
167450 } else if (ep->is_first_qg || (lc->parse.cu_qg_top_left_x == x0 && lc->parse.cu_qg_top_left_y == y0)) {
152 2765 ep->qp_y = get_qp_y_pred(lc);
153 2765 ep->is_first_qg = 0;
154 }
155
156
2/2
✓ Branch 0 taken 1888 times.
✓ Branch 1 taken 1358595 times.
1360483 if (has_qp_delta) {
157 1888 const int cu_qp_delta_abs = ff_vvc_cu_qp_delta_abs(lc);
158
159
2/2
✓ Branch 0 taken 1106 times.
✓ Branch 1 taken 782 times.
1888 if (cu_qp_delta_abs)
160
2/2
✓ Branch 1 taken 649 times.
✓ Branch 2 taken 457 times.
1106 cu_qp_delta = ff_vvc_cu_qp_delta_sign_flag(lc) ? -cu_qp_delta_abs : cu_qp_delta_abs;
161
2/4
✓ Branch 0 taken 1888 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1888 times.
1888 if (cu_qp_delta > (31 + sps->qp_bd_offset / 2) || cu_qp_delta < -(32 + sps->qp_bd_offset / 2))
162 return AVERROR_INVALIDDATA;
163 1888 lc->parse.is_cu_qp_delta_coded = 1;
164
165
2/2
✓ Branch 0 taken 1106 times.
✓ Branch 1 taken 782 times.
1888 if (cu_qp_delta) {
166 1106 int off = sps->qp_bd_offset;
167
1/2
✓ Branch 0 taken 1106 times.
✗ Branch 1 not taken.
1106 ep->qp_y = FFUMOD(ep->qp_y + cu_qp_delta + 64 + 2 * off, 64 + off) - off;
168 }
169 }
170
171 1360483 set_cb_tab(lc, lc->fc->tab.qp[LUMA], ep->qp_y);
172 1360483 cu->qp[LUMA] = ep->qp_y;
173
174 1360483 return 0;
175 }
176
177 1785304 static void set_qp_c_tab(const VVCLocalContext *lc, const TransformUnit *tu, const TransformBlock *tb)
178 {
179
6/6
✓ Branch 0 taken 108450 times.
✓ Branch 1 taken 1676854 times.
✓ Branch 2 taken 92198 times.
✓ Branch 3 taken 16252 times.
✓ Branch 4 taken 62068 times.
✓ Branch 5 taken 30130 times.
1785304 const int is_jcbcr = tu->joint_cbcr_residual_flag && tu->coded_flag[CB] && tu->coded_flag[CR];
180
2/2
✓ Branch 0 taken 1723236 times.
✓ Branch 1 taken 62068 times.
1785304 const int idx = is_jcbcr ? JCBCR : tb->c_idx;
181
182 1785304 set_tb_tab(lc->fc->tab.qp[tb->c_idx], lc->cu->qp[idx], lc->fc, tb);
183 1785304 }
184
185 1296644 static void set_qp_c(VVCLocalContext *lc)
186 {
187 1296644 const VVCFrameContext *fc = lc->fc;
188 1296644 const VVCSPS *sps = fc->ps.sps;
189 1296644 const VVCPPS *pps = fc->ps.pps;
190 1296644 const H266RawSliceHeader *rsh = lc->sc->sh.r;
191 1296644 CodingUnit *cu = lc->cu;
192 1296644 const int x_center = cu->x0 + cu->cb_width / 2;
193 1296644 const int y_center = cu->y0 + cu->cb_height / 2;
194 1296644 const int single_tree = cu->tree_type == SINGLE_TREE;
195
2/2
✓ Branch 0 taken 553554 times.
✓ Branch 1 taken 743090 times.
1296644 const int qp_luma = (single_tree ? lc->ep->qp_y : ff_vvc_get_qPy(fc, x_center, y_center)) + sps->qp_bd_offset;
196 1296644 const int qp_chroma = av_clip(qp_luma, 0, MAX_QP + sps->qp_bd_offset);
197 1296644 const int sh_chroma_qp_offset[] = {
198 1296644 rsh->sh_cb_qp_offset,
199 1296644 rsh->sh_cr_qp_offset,
200 1296644 rsh->sh_joint_cbcr_qp_offset,
201 };
202 int qp;
203
204
2/2
✓ Branch 0 taken 3847037 times.
✓ Branch 1 taken 1296644 times.
5143681 for (int i = CB - 1; i < CR + sps->r->sps_joint_cbcr_enabled_flag; i++) {
205 3847037 qp = sps->chroma_qp_table[i][qp_chroma];
206 3847037 qp = qp + pps->chroma_qp_offset[i] + sh_chroma_qp_offset[i] + lc->parse.chroma_qp_offset[i];
207 3847037 qp = av_clip(qp, -sps->qp_bd_offset, MAX_QP) + sps->qp_bd_offset;
208 3847037 cu->qp[i + 1] = qp;
209 }
210 1296644 }
211
212 1663353 static TransformUnit* alloc_tu(VVCFrameContext *fc, CodingUnit *cu)
213 {
214 1663353 TransformUnit *tu = av_refstruct_pool_get(fc->tu_pool);
215
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1663353 times.
1663353 if (!tu)
216 return NULL;
217
218 1663353 tu->next = NULL;
219
220
2/2
✓ Branch 0 taken 319205 times.
✓ Branch 1 taken 1344148 times.
1663353 if (cu->tus.tail)
221 319205 cu->tus.tail->next = tu;
222 else
223 1344148 cu->tus.head = tu;
224 1663353 cu->tus.tail = tu;
225
226 1663353 return tu;
227 }
228
229 1663353 static TransformUnit* add_tu(VVCFrameContext *fc, CodingUnit *cu, const int x0, const int y0, const int tu_width, const int tu_height)
230 {
231 1663353 TransformUnit *tu = alloc_tu(fc, cu);
232
233
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1663353 times.
1663353 if (!tu)
234 return NULL;
235
236 1663353 tu->x0 = x0;
237 1663353 tu->y0 = y0;
238 1663353 tu->width = tu_width;
239 1663353 tu->height = tu_height;
240 1663353 tu->joint_cbcr_residual_flag = 0;
241 1663353 memset(tu->coded_flag, 0, sizeof(tu->coded_flag));
242 1663353 tu->avail[LUMA] = tu->avail[CHROMA] = 0;
243 1663353 tu->nb_tbs = 0;
244
245 1663353 return tu;
246 }
247
248 3260493 static TransformBlock* add_tb(TransformUnit *tu, VVCLocalContext *lc,
249 const int x0, const int y0, const int tb_width, const int tb_height, const int c_idx)
250 {
251 TransformBlock *tb;
252
253 3260493 tb = &tu->tbs[tu->nb_tbs++];
254 3260493 tb->has_coeffs = 0;
255 3260493 tb->x0 = x0;
256 3260493 tb->y0 = y0;
257 3260493 tb->tb_width = tb_width;
258 3260493 tb->tb_height = tb_height;
259 3260493 tb->log2_tb_width = av_log2(tb_width);
260 3260493 tb->log2_tb_height = av_log2(tb_height);
261
262 3260493 tb->max_scan_x = tb->max_scan_y = 0;
263 3260493 tb->min_scan_x = tb->min_scan_y = 0;
264
265 3260493 tb->c_idx = c_idx;
266 3260493 tb->ts = 0;
267 3260493 tb->coeffs = lc->coeffs;
268 3260493 lc->coeffs += tb_width * tb_height;
269 3260493 tu->avail[!!c_idx] = true;
270 3260493 return tb;
271 }
272
273 1006590 static uint8_t tu_y_coded_flag_decode(VVCLocalContext *lc, const int is_sbt_not_coded,
274 const int sub_tu_index, const int is_isp, const int is_chroma_coded)
275 {
276 1006590 uint8_t tu_y_coded_flag = 0;
277 1006590 const VVCSPS *sps = lc->fc->ps.sps;
278 1006590 CodingUnit *cu = lc->cu;
279
280
2/2
✓ Branch 0 taken 961139 times.
✓ Branch 1 taken 45451 times.
1006590 if (!is_sbt_not_coded) {
281
4/4
✓ Branch 0 taken 815022 times.
✓ Branch 1 taken 146117 times.
✓ Branch 2 taken 52356 times.
✓ Branch 3 taken 762666 times.
961139 int has_y_coded_flag = sub_tu_index < cu->num_intra_subpartitions - 1 || !lc->parse.infer_tu_cbf_luma;
282
2/2
✓ Branch 0 taken 750313 times.
✓ Branch 1 taken 210826 times.
961139 if (!is_isp) {
283
4/4
✓ Branch 0 taken 736033 times.
✓ Branch 1 taken 14280 times.
✓ Branch 2 taken 2942 times.
✓ Branch 3 taken 733091 times.
750313 const int is_large = cu->cb_width > sps->max_tb_size_y || cu->cb_height > sps->max_tb_size_y;
284
8/8
✓ Branch 0 taken 562303 times.
✓ Branch 1 taken 188010 times.
✓ Branch 2 taken 6377 times.
✓ Branch 3 taken 555926 times.
✓ Branch 4 taken 125708 times.
✓ Branch 5 taken 68679 times.
✓ Branch 6 taken 4877 times.
✓ Branch 7 taken 120831 times.
750313 has_y_coded_flag = (cu->pred_mode == MODE_INTRA && !cu->act_enabled_flag) || is_chroma_coded || is_large;
285 }
286
2/2
✓ Branch 0 taken 827955 times.
✓ Branch 1 taken 133184 times.
961139 tu_y_coded_flag = has_y_coded_flag ? ff_vvc_tu_y_coded_flag(lc) : 1;
287 }
288
2/2
✓ Branch 0 taken 210826 times.
✓ Branch 1 taken 795764 times.
1006590 if (is_isp)
289
4/4
✓ Branch 0 taken 105174 times.
✓ Branch 1 taken 105652 times.
✓ Branch 2 taken 40465 times.
✓ Branch 3 taken 64709 times.
210826 lc->parse.infer_tu_cbf_luma = lc->parse.infer_tu_cbf_luma && !tu_y_coded_flag;
290 1006590 return tu_y_coded_flag;
291 }
292
293 511878 static void chroma_qp_offset_decode(VVCLocalContext *lc, const int is_128, const int is_chroma_coded)
294 {
295 511878 const VVCPPS *pps = lc->fc->ps.pps;
296 511878 const H266RawSliceHeader *rsh = lc->sc->sh.r;
297
298
4/4
✓ Branch 0 taken 502944 times.
✓ Branch 1 taken 8934 times.
✓ Branch 2 taken 197839 times.
✓ Branch 3 taken 305105 times.
511878 if ((is_128 || is_chroma_coded) &&
299
4/4
✓ Branch 0 taken 39307 times.
✓ Branch 1 taken 167466 times.
✓ Branch 2 taken 1029 times.
✓ Branch 3 taken 38278 times.
206773 rsh->sh_cu_chroma_qp_offset_enabled_flag && !lc->parse.is_cu_chroma_qp_offset_coded) {
300 1029 const int cu_chroma_qp_offset_flag = ff_vvc_cu_chroma_qp_offset_flag(lc);
301
1/2
✓ Branch 0 taken 1029 times.
✗ Branch 1 not taken.
1029 if (cu_chroma_qp_offset_flag) {
302 1029 int cu_chroma_qp_offset_idx = 0;
303
2/2
✓ Branch 0 taken 931 times.
✓ Branch 1 taken 98 times.
1029 if (pps->r->pps_chroma_qp_offset_list_len_minus1 > 0)
304 931 cu_chroma_qp_offset_idx = ff_vvc_cu_chroma_qp_offset_idx(lc);
305
2/2
✓ Branch 0 taken 3087 times.
✓ Branch 1 taken 1029 times.
4116 for (int i = CB - 1; i < JCBCR; i++)
306 3087 lc->parse.chroma_qp_offset[i] = pps->chroma_qp_offset_list[cu_chroma_qp_offset_idx][i];
307 } else {
308 memset(lc->parse.chroma_qp_offset, 0, sizeof(lc->parse.chroma_qp_offset));
309 }
310 1029 lc->parse.is_cu_chroma_qp_offset_coded = 1;
311 }
312 511878 }
313
314 1194754 static int hls_transform_unit(VVCLocalContext *lc, int x0, int y0,int tu_width, int tu_height, int sub_tu_index, int ch_type)
315 {
316 1194754 VVCFrameContext *fc = lc->fc;
317 1194754 const VVCSPS *sps = fc->ps.sps;
318 1194754 const VVCPPS *pps = fc->ps.pps;
319 1194754 CodingUnit *cu = lc->cu;
320 1194754 TransformUnit *tu = add_tu(fc, cu, x0, y0, tu_width, tu_height);
321 1194754 const int min_cb_width = pps->min_cb_width;
322 1194754 const VVCTreeType tree_type = cu->tree_type;
323
4/4
✓ Branch 0 taken 1187506 times.
✓ Branch 1 taken 7248 times.
✓ Branch 2 taken 1686 times.
✓ Branch 3 taken 1185820 times.
1194754 const int is_128 = cu->cb_width > 64 || cu->cb_height > 64;
324 1194754 const int is_isp = cu->isp_split_type != ISP_NO_SPLIT;
325
4/4
✓ Branch 0 taken 210826 times.
✓ Branch 1 taken 983928 times.
✓ Branch 2 taken 64709 times.
✓ Branch 3 taken 146117 times.
1194754 const int is_isp_last_tu = is_isp && (sub_tu_index == cu->num_intra_subpartitions - 1);
326
4/4
✓ Branch 0 taken 90902 times.
✓ Branch 1 taken 1103852 times.
✓ Branch 2 taken 45451 times.
✓ Branch 3 taken 45451 times.
1285656 const int is_sbt_not_coded = cu->sbt_flag &&
327
6/6
✓ Branch 0 taken 23703 times.
✓ Branch 1 taken 21748 times.
✓ Branch 2 taken 45451 times.
✓ Branch 3 taken 23703 times.
✓ Branch 4 taken 23703 times.
✓ Branch 5 taken 21748 times.
90902 ((sub_tu_index == 0 && cu->sbt_pos_flag) || (sub_tu_index == 1 && !cu->sbt_pos_flag));
328
6/6
✓ Branch 0 taken 511878 times.
✓ Branch 1 taken 682876 times.
✓ Branch 2 taken 488406 times.
✓ Branch 3 taken 23472 times.
✓ Branch 4 taken 22306 times.
✓ Branch 5 taken 466100 times.
1217060 const int chroma_available = tree_type != DUAL_TREE_LUMA && sps->r->sps_chroma_format_idc &&
329
2/2
✓ Branch 0 taken 5627 times.
✓ Branch 1 taken 16679 times.
22306 (!is_isp || is_isp_last_tu);
330 int ret, xc, yc, wc, hc, is_chroma_coded;
331
332
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1194754 times.
1194754 if (!tu)
333 return AVERROR_INVALIDDATA;
334
335
4/4
✓ Branch 0 taken 323714 times.
✓ Branch 1 taken 871040 times.
✓ Branch 2 taken 7409 times.
✓ Branch 3 taken 316305 times.
1194754 if (tree_type == SINGLE_TREE && is_isp_last_tu) {
336 7409 const int x_cu = x0 >> fc->ps.sps->min_cb_log2_size_y;
337 7409 const int y_cu = y0 >> fc->ps.sps->min_cb_log2_size_y;
338 7409 xc = SAMPLE_CTB(fc->tab.cb_pos_x[ch_type], x_cu, y_cu);
339 7409 yc = SAMPLE_CTB(fc->tab.cb_pos_y[ch_type], x_cu, y_cu);
340 7409 wc = SAMPLE_CTB(fc->tab.cb_width[ch_type], x_cu, y_cu);
341 7409 hc = SAMPLE_CTB(fc->tab.cb_height[ch_type], x_cu, y_cu);
342 } else {
343 1187345 xc = x0, yc = y0, wc = tu_width, hc = tu_height;
344 }
345
346
4/4
✓ Branch 0 taken 471727 times.
✓ Branch 1 taken 723027 times.
✓ Branch 2 taken 427568 times.
✓ Branch 3 taken 44159 times.
1194754 if (chroma_available && !is_sbt_not_coded) {
347 427568 tu->coded_flag[CB] = ff_vvc_tu_cb_coded_flag(lc);
348 427568 tu->coded_flag[CR] = ff_vvc_tu_cr_coded_flag(lc, tu->coded_flag[CB]);
349 }
350
351
6/6
✓ Branch 0 taken 471727 times.
✓ Branch 1 taken 723027 times.
✓ Branch 2 taken 302225 times.
✓ Branch 3 taken 169502 times.
✓ Branch 4 taken 34268 times.
✓ Branch 5 taken 267957 times.
1194754 is_chroma_coded = chroma_available && (tu->coded_flag[CB] || tu->coded_flag[CR]);
352
353
2/2
✓ Branch 0 taken 1006590 times.
✓ Branch 1 taken 188164 times.
1194754 if (tree_type != DUAL_TREE_CHROMA) {
354 int has_qp_delta;
355 1006590 tu->coded_flag[LUMA] = tu_y_coded_flag_decode(lc, is_sbt_not_coded, sub_tu_index, is_isp, is_chroma_coded);
356
4/4
✓ Branch 0 taken 268705 times.
✓ Branch 1 taken 728951 times.
✓ Branch 2 taken 36248 times.
✓ Branch 3 taken 232457 times.
997656 has_qp_delta = (is_128 || tu->coded_flag[LUMA] || is_chroma_coded) &&
357
6/6
✓ Branch 0 taken 997656 times.
✓ Branch 1 taken 8934 times.
✓ Branch 2 taken 77901 times.
✓ Branch 3 taken 696232 times.
✓ Branch 4 taken 1888 times.
✓ Branch 5 taken 76013 times.
2004246 pps->r->pps_cu_qp_delta_enabled_flag && !lc->parse.is_cu_qp_delta_coded;
358 1006590 ret = set_qp_y(lc, x0, y0, has_qp_delta);
359
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1006590 times.
1006590 if (ret < 0)
360 return ret;
361 1006590 add_tb(tu, lc, x0, y0, tu_width, tu_height, LUMA);
362 }
363
2/2
✓ Branch 0 taken 511878 times.
✓ Branch 1 taken 682876 times.
1194754 if (tree_type != DUAL_TREE_LUMA) {
364 511878 chroma_qp_offset_decode(lc, is_128, is_chroma_coded);
365
2/2
✓ Branch 0 taken 471727 times.
✓ Branch 1 taken 40151 times.
511878 if (chroma_available) {
366 471727 const int hs = sps->hshift[CHROMA];
367 471727 const int vs = sps->vshift[CHROMA];
368 471727 add_tb(tu, lc, xc, yc, wc >> hs, hc >> vs, CB);
369 471727 add_tb(tu, lc, xc, yc, wc >> hs, hc >> vs, CR);
370 }
371 }
372
4/4
✓ Branch 0 taken 1151550 times.
✓ Branch 1 taken 43204 times.
✓ Branch 2 taken 926410 times.
✓ Branch 3 taken 225140 times.
1194754 if (sps->r->sps_joint_cbcr_enabled_flag && ((cu->pred_mode == MODE_INTRA &&
373
4/4
✓ Branch 0 taken 819716 times.
✓ Branch 1 taken 106694 times.
✓ Branch 2 taken 793776 times.
✓ Branch 3 taken 25940 times.
926410 (tu->coded_flag[CB] || tu->coded_flag[CR])) ||
374
5/6
✓ Branch 0 taken 57418 times.
✓ Branch 1 taken 961498 times.
✓ Branch 2 taken 25270 times.
✓ Branch 3 taken 32148 times.
✓ Branch 4 taken 157904 times.
✗ Branch 5 not taken.
1151550 (tu->coded_flag[CB] && tu->coded_flag[CR])) &&
375 chroma_available) {
376 157904 tu->joint_cbcr_residual_flag = ff_vvc_tu_joint_cbcr_residual_flag(lc, tu->coded_flag[1], tu->coded_flag[2]);
377 }
378
379
2/2
✓ Branch 0 taken 1950044 times.
✓ Branch 1 taken 1194754 times.
3144798 for (int i = 0; i < tu->nb_tbs; i++) {
380 1950044 TransformBlock *tb = &tu->tbs[i];
381 1950044 const int is_chroma = tb->c_idx != LUMA;
382 1950044 tb->has_coeffs = tu->coded_flag[tb->c_idx];
383
4/4
✓ Branch 0 taken 1035952 times.
✓ Branch 1 taken 914092 times.
✓ Branch 2 taken 300685 times.
✓ Branch 3 taken 735267 times.
1950044 if (tb->has_coeffs && is_chroma)
384
6/6
✓ Branch 0 taken 131183 times.
✓ Branch 1 taken 169502 times.
✓ Branch 2 taken 96915 times.
✓ Branch 3 taken 34268 times.
✓ Branch 4 taken 65881 times.
✓ Branch 5 taken 31034 times.
300685 tb->has_coeffs = tb->c_idx == CB ? 1 : !(tu->coded_flag[CB] && tu->joint_cbcr_residual_flag);
385
2/2
✓ Branch 0 taken 1004918 times.
✓ Branch 1 taken 945126 times.
1950044 if (tb->has_coeffs) {
386 1004918 tb->ts = cu->bdpcm_flag[tb->c_idx];
387
4/4
✓ Branch 0 taken 887290 times.
✓ Branch 1 taken 117628 times.
✓ Branch 2 taken 885085 times.
✓ Branch 3 taken 2205 times.
1004918 if (sps->r->sps_transform_skip_enabled_flag && !cu->bdpcm_flag[tb->c_idx] &&
388
4/4
✓ Branch 0 taken 868534 times.
✓ Branch 1 taken 16551 times.
✓ Branch 2 taken 861216 times.
✓ Branch 3 taken 7318 times.
885085 tb->tb_width <= sps->max_ts_size && tb->tb_height <= sps->max_ts_size &&
389
6/6
✓ Branch 0 taken 820707 times.
✓ Branch 1 taken 40509 times.
✓ Branch 2 taken 629783 times.
✓ Branch 3 taken 190924 times.
✓ Branch 4 taken 491999 times.
✓ Branch 5 taken 137784 times.
861216 !cu->sbt_flag && (is_chroma || !is_isp)) {
390 682923 tb->ts = ff_vvc_transform_skip_flag(lc, is_chroma);
391 }
392 1004918 ret = ff_vvc_residual_coding(lc, tb);
393
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1004918 times.
1004918 if (ret < 0)
394 return ret;
395 1004918 set_tb_tab(fc->tab.tu_coded_flag[tb->c_idx], tu->coded_flag[tb->c_idx], fc, tb);
396
2/2
✓ Branch 0 taken 24384 times.
✓ Branch 1 taken 920742 times.
945126 } else if (cu->act_enabled_flag) {
397 24384 memset(tb->coeffs, 0, tb->tb_width * tb->tb_height * sizeof(*tb->coeffs));
398 }
399
2/2
✓ Branch 0 taken 1478317 times.
✓ Branch 1 taken 471727 times.
1950044 if (tb->c_idx != CR)
400 1478317 set_tb_size(fc, tb);
401
2/2
✓ Branch 0 taken 471727 times.
✓ Branch 1 taken 1478317 times.
1950044 if (tb->c_idx == CB)
402 471727 set_tb_tab(fc->tab.tu_joint_cbcr_residual_flag, tu->joint_cbcr_residual_flag, fc, tb);
403 }
404
405 1194754 return 0;
406 }
407
408 1016117 static int hls_transform_tree(VVCLocalContext *lc, int x0, int y0,int tu_width, int tu_height, int ch_type)
409 {
410 1016117 const CodingUnit *cu = lc->cu;
411 1016117 const VVCSPS *sps = lc->fc->ps.sps;
412 int ret;
413
414 1016117 lc->parse.infer_tu_cbf_luma = 1;
415
4/4
✓ Branch 0 taken 951408 times.
✓ Branch 1 taken 64709 times.
✓ Branch 2 taken 905957 times.
✓ Branch 3 taken 45451 times.
1016117 if (cu->isp_split_type == ISP_NO_SPLIT && !cu->sbt_flag) {
416
4/4
✓ Branch 0 taken 894999 times.
✓ Branch 1 taken 10958 times.
✓ Branch 2 taken 1973 times.
✓ Branch 3 taken 893026 times.
918888 if (tu_width > sps->max_tb_size_y || tu_height > sps->max_tb_size_y) {
417
4/4
✓ Branch 0 taken 10958 times.
✓ Branch 1 taken 1973 times.
✓ Branch 2 taken 8064 times.
✓ Branch 3 taken 2894 times.
12931 const int ver_split_first = tu_width > sps->max_tb_size_y && tu_width > tu_height;
418
2/2
✓ Branch 0 taken 8064 times.
✓ Branch 1 taken 4867 times.
12931 const int trafo_width = ver_split_first ? (tu_width / 2) : tu_width;
419
2/2
✓ Branch 0 taken 4867 times.
✓ Branch 1 taken 8064 times.
12931 const int trafo_height = !ver_split_first ? (tu_height / 2) : tu_height;
420
421 #define TRANSFORM_TREE(x, y) do { \
422 ret = hls_transform_tree(lc, x, y, trafo_width, trafo_height, ch_type); \
423 if (ret < 0) \
424 return ret; \
425 } while (0)
426
427
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 12931 times.
12931 TRANSFORM_TREE(x0, y0);
428
2/2
✓ Branch 0 taken 8064 times.
✓ Branch 1 taken 4867 times.
12931 if (ver_split_first)
429
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 8064 times.
8064 TRANSFORM_TREE(x0 + trafo_width, y0);
430 else
431
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4867 times.
4867 TRANSFORM_TREE(x0, y0 + trafo_height);
432
433 } else {
434 893026 ret = hls_transform_unit(lc, x0, y0, tu_width, tu_height, 0, ch_type);
435
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 893026 times.
893026 if (ret < 0)
436 return ret;
437
438 }
439
2/2
✓ Branch 0 taken 45451 times.
✓ Branch 1 taken 64709 times.
110160 } else if (cu->sbt_flag) {
440
2/2
✓ Branch 0 taken 24022 times.
✓ Branch 1 taken 21429 times.
45451 if (!cu->sbt_horizontal_flag) {
441 #define TRANSFORM_UNIT(x, width, idx) do { \
442 ret = hls_transform_unit(lc, x, y0, width, tu_height, idx, ch_type); \
443 if (ret < 0) \
444 return ret; \
445 } while (0)
446
447 24022 const int trafo_width = tu_width * lc->parse.sbt_num_fourths_tb0 / 4;
448
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 24022 times.
24022 TRANSFORM_UNIT(x0, trafo_width, 0);
449
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 24022 times.
24022 TRANSFORM_UNIT(x0 + trafo_width, tu_width - trafo_width, 1);
450
451 #undef TRANSFORM_UNIT
452 } else {
453 #define TRANSFORM_UNIT(y, height, idx) do { \
454 ret = hls_transform_unit(lc, x0, y, tu_width, height, idx, ch_type); \
455 if (ret < 0) \
456 return ret; \
457 } while (0)
458
459 21429 const int trafo_height = tu_height * lc->parse.sbt_num_fourths_tb0 / 4;
460
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 21429 times.
21429 TRANSFORM_UNIT(y0, trafo_height, 0);
461
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 21429 times.
21429 TRANSFORM_UNIT(y0 + trafo_height, tu_height - trafo_height, 1);
462
463 #undef TRANSFORM_UNIT
464 }
465
2/2
✓ Branch 0 taken 40123 times.
✓ Branch 1 taken 24586 times.
64709 } else if (cu->isp_split_type == ISP_HOR_SPLIT) {
466 40123 const int trafo_height = tu_height / cu->num_intra_subpartitions;
467
2/2
✓ Branch 0 taken 134388 times.
✓ Branch 1 taken 40123 times.
174511 for (int i = 0; i < cu->num_intra_subpartitions; i++) {
468 134388 ret = hls_transform_unit(lc, x0, y0 + trafo_height * i, tu_width, trafo_height, i, 0);
469
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 134388 times.
134388 if (ret < 0)
470 return ret;
471 }
472
1/2
✓ Branch 0 taken 24586 times.
✗ Branch 1 not taken.
24586 } else if (cu->isp_split_type == ISP_VER_SPLIT) {
473 24586 const int trafo_width = tu_width / cu->num_intra_subpartitions;
474
2/2
✓ Branch 0 taken 76438 times.
✓ Branch 1 taken 24586 times.
101024 for (int i = 0; i < cu->num_intra_subpartitions; i++) {
475 76438 ret = hls_transform_unit(lc, x0 + trafo_width * i , y0, trafo_width, tu_height, i, 0);
476
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 76438 times.
76438 if (ret < 0)
477 return ret;
478 }
479 }
480
481 1016117 return 0;
482 }
483
484 578808 static int skipped_transform_tree(VVCLocalContext *lc, int x0, int y0,int tu_width, int tu_height)
485 {
486 578808 VVCFrameContext *fc = lc->fc;
487 578808 const CodingUnit *cu = lc->cu;
488 578808 const VVCSPS *sps = fc->ps.sps;
489
490
4/4
✓ Branch 0 taken 466921 times.
✓ Branch 1 taken 111887 times.
✓ Branch 2 taken 2819 times.
✓ Branch 3 taken 464102 times.
693514 if (tu_width > sps->max_tb_size_y || tu_height > sps->max_tb_size_y) {
491
4/4
✓ Branch 0 taken 111887 times.
✓ Branch 1 taken 2819 times.
✓ Branch 2 taken 76218 times.
✓ Branch 3 taken 35669 times.
114706 const int ver_split_first = tu_width > sps->max_tb_size_y && tu_width > tu_height;
492
2/2
✓ Branch 0 taken 76218 times.
✓ Branch 1 taken 38488 times.
114706 const int trafo_width = ver_split_first ? (tu_width / 2) : tu_width;
493
2/2
✓ Branch 0 taken 38488 times.
✓ Branch 1 taken 76218 times.
114706 const int trafo_height = !ver_split_first ? (tu_height / 2) : tu_height;
494
495 #define SKIPPED_TRANSFORM_TREE(x, y) do { \
496 int ret = skipped_transform_tree(lc, x, y, trafo_width, trafo_height); \
497 if (ret < 0) \
498 return ret; \
499 } while (0)
500
501
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 114706 times.
114706 SKIPPED_TRANSFORM_TREE(x0, y0);
502
2/2
✓ Branch 0 taken 76218 times.
✓ Branch 1 taken 38488 times.
114706 if (ver_split_first)
503
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 76218 times.
76218 SKIPPED_TRANSFORM_TREE(x0 + trafo_width, y0);
504 else
505
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 38488 times.
38488 SKIPPED_TRANSFORM_TREE(x0, y0 + trafo_height);
506 } else {
507 464102 TransformUnit *tu = add_tu(fc, lc->cu, x0, y0, tu_width, tu_height);
508 int start, end;
509
510
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 464102 times.
464102 if (!tu)
511 return AVERROR_INVALIDDATA;
512 464102 ff_vvc_channel_range(&start, &end, cu->tree_type, sps->r->sps_chroma_format_idc);
513
2/2
✓ Branch 0 taken 1297862 times.
✓ Branch 1 taken 464102 times.
1761964 for (int i = start; i < end; i++) {
514 1297862 TransformBlock *tb = add_tb(tu, lc, x0, y0, tu_width >> sps->hshift[i], tu_height >> sps->vshift[i], i);
515
2/2
✓ Branch 0 taken 880982 times.
✓ Branch 1 taken 416880 times.
1297862 if (i != CR)
516 880982 set_tb_size(fc, tb);
517 }
518 }
519
520 578808 return 0;
521 }
522
523 //6.4.1 Allowed quad split process
524 //6.4.2 Allowed binary split process
525 //6.4.3 Allowed ternary split process
526 2211333 static void can_split(const VVCLocalContext *lc, int x0, int y0,int cb_width, int cb_height,
527 int mtt_depth, int depth_offset, int part_idx, VVCSplitMode last_split_mode,
528 VVCTreeType tree_type, VVCModeType mode_type, VVCAllowedSplit* split)
529 {
530 int min_qt_size, max_bt_size, max_tt_size, max_mtt_depth;
531 2211333 const VVCFrameContext *fc = lc->fc;
532 2211333 const VVCSH *sh = &lc->sc->sh;
533 2211333 const VVCSPS *sps = fc->ps.sps;
534 2211333 const VVCPPS *pps = fc->ps.pps;
535 2211333 const int chroma = tree_type == DUAL_TREE_CHROMA;
536 2211333 int min_cb_size_y = sps->min_cb_size_y;
537 2211333 int *qt = &split->qt;
538 2211333 int *btv = &split->btv;
539 2211333 int *bth = &split->bth;
540 2211333 int *ttv = &split->ttv;
541 2211333 int *tth = &split->tth;
542
543 2211333 *qt = *bth = *btv = *tth = *ttv = 1;
544
545
2/2
✓ Branch 0 taken 1695550 times.
✓ Branch 1 taken 515783 times.
2211333 if (mtt_depth)
546 1695550 *qt = 0;
547
548 2211333 min_qt_size = sh->min_qt_size[chroma];
549
2/2
✓ Branch 0 taken 933527 times.
✓ Branch 1 taken 1277806 times.
2211333 if (cb_width <= min_qt_size)
550 933527 *qt = 0;
551
552
2/2
✓ Branch 0 taken 290701 times.
✓ Branch 1 taken 1920632 times.
2211333 if (chroma) {
553 290701 int chroma_area = (cb_width >> sps->hshift[1]) * (cb_height >> sps->vshift[1]);
554 290701 int chroma_width = cb_width >> sps->hshift[1];
555
556
2/2
✓ Branch 0 taken 90264 times.
✓ Branch 1 taken 200437 times.
290701 if (chroma_width == 8)
557 90264 *ttv = 0;
558
2/2
✓ Branch 0 taken 73021 times.
✓ Branch 1 taken 127416 times.
200437 else if (chroma_width <= 4) {
559
1/2
✓ Branch 0 taken 73021 times.
✗ Branch 1 not taken.
73021 if (chroma_width == 4)
560 73021 *btv = 0;
561 73021 *qt = 0;
562 }
563
2/2
✓ Branch 0 taken 29134 times.
✓ Branch 1 taken 261567 times.
290701 if (mode_type == MODE_TYPE_INTRA)
564 29134 *qt = *btv = *bth = *ttv = *tth = 0;
565
2/2
✓ Branch 0 taken 106631 times.
✓ Branch 1 taken 184070 times.
290701 if (chroma_area <= 32) {
566 106631 *ttv = *tth = 0;
567
2/2
✓ Branch 0 taken 48250 times.
✓ Branch 1 taken 58381 times.
106631 if (chroma_area <= 16)
568 48250 *btv = *bth = 0;
569 }
570 }
571 2211333 max_bt_size = sh->max_bt_size[chroma];
572 2211333 max_tt_size = sh->max_tt_size[chroma];
573 2211333 max_mtt_depth = sh->max_mtt_depth[chroma] + depth_offset;
574
575
2/2
✓ Branch 0 taken 71682 times.
✓ Branch 1 taken 2139651 times.
2211333 if (mode_type == MODE_TYPE_INTER) {
576 71682 int area = cb_width * cb_height;
577
2/2
✓ Branch 0 taken 29760 times.
✓ Branch 1 taken 41922 times.
71682 if (area == 32)
578 29760 *btv = *bth = 0;
579
2/2
✓ Branch 0 taken 24870 times.
✓ Branch 1 taken 17052 times.
41922 else if (area == 64)
580 24870 *ttv = *tth = 0;
581 }
582
2/2
✓ Branch 0 taken 918826 times.
✓ Branch 1 taken 1292507 times.
2211333 if (cb_width <= 2 * min_cb_size_y) {
583 918826 *ttv = 0;
584
2/2
✓ Branch 0 taken 349320 times.
✓ Branch 1 taken 569506 times.
918826 if (cb_width <= min_cb_size_y)
585 349320 *btv = 0;
586 }
587
2/2
✓ Branch 0 taken 1005558 times.
✓ Branch 1 taken 1205775 times.
2211333 if (cb_height <= 2 * min_cb_size_y) {
588 1005558 *tth = 0;
589
2/2
✓ Branch 0 taken 404313 times.
✓ Branch 1 taken 601245 times.
1005558 if (cb_height <= min_cb_size_y)
590 404313 *bth = 0;
591 }
592
4/4
✓ Branch 0 taken 2154261 times.
✓ Branch 1 taken 57072 times.
✓ Branch 2 taken 705 times.
✓ Branch 3 taken 2153556 times.
2211333 if (cb_width > max_bt_size || cb_height > max_bt_size)
593 57777 *btv = *bth = 0;
594 2211333 max_tt_size = FFMIN(64, max_tt_size);
595
4/4
✓ Branch 0 taken 2077976 times.
✓ Branch 1 taken 133357 times.
✓ Branch 2 taken 8544 times.
✓ Branch 3 taken 2069432 times.
2211333 if (cb_width > max_tt_size || cb_height > max_tt_size)
596 141901 *ttv = *tth = 0;
597
2/2
✓ Branch 0 taken 447302 times.
✓ Branch 1 taken 1764031 times.
2211333 if (mtt_depth >= max_mtt_depth)
598 447302 *btv = *bth = *ttv = *tth = 0;
599
2/2
✓ Branch 0 taken 4939 times.
✓ Branch 1 taken 2206394 times.
2211333 if (x0 + cb_width > pps->width) {
600 4939 *ttv = *tth = 0;
601
2/2
✓ Branch 0 taken 1461 times.
✓ Branch 1 taken 3478 times.
4939 if (cb_height > 64)
602 1461 *btv = 0;
603
2/2
✓ Branch 0 taken 3675 times.
✓ Branch 1 taken 1264 times.
4939 if (y0 + cb_height <= pps->height)
604 3675 *bth = 0;
605
2/2
✓ Branch 0 taken 1210 times.
✓ Branch 1 taken 54 times.
1264 else if (cb_width > min_qt_size)
606 1210 *btv = *bth = 0;
607 }
608
2/2
✓ Branch 0 taken 55415 times.
✓ Branch 1 taken 2155918 times.
2211333 if (y0 + cb_height > pps->height) {
609 55415 *btv = *ttv = *tth = 0;
610
2/2
✓ Branch 0 taken 7288 times.
✓ Branch 1 taken 48127 times.
55415 if (cb_width > 64)
611 7288 *bth = 0;
612 }
613
4/4
✓ Branch 0 taken 1695550 times.
✓ Branch 1 taken 515783 times.
✓ Branch 2 taken 734201 times.
✓ Branch 3 taken 961349 times.
2211333 if (mtt_depth > 0 && part_idx == 1) {
614
2/2
✓ Branch 0 taken 87583 times.
✓ Branch 1 taken 646618 times.
734201 if (last_split_mode == SPLIT_TT_VER)
615 87583 *btv = 0;
616
2/2
✓ Branch 0 taken 92645 times.
✓ Branch 1 taken 553973 times.
646618 else if (last_split_mode == SPLIT_TT_HOR)
617 92645 *bth = 0;
618 }
619
4/4
✓ Branch 0 taken 2161480 times.
✓ Branch 1 taken 49853 times.
✓ Branch 2 taken 3352 times.
✓ Branch 3 taken 2158128 times.
2211333 if (cb_width <= 64 && cb_height > 64)
620 3352 *btv = 0;
621
4/4
✓ Branch 0 taken 49853 times.
✓ Branch 1 taken 2161480 times.
✓ Branch 2 taken 3462 times.
✓ Branch 3 taken 46391 times.
2211333 if (cb_width > 64 && cb_height <= 64)
622 3462 *bth = 0;
623 2211333 }
624
625 503218 static int get_num_intra_subpartitions(enum IspType isp_split_type, int cb_width, int cb_height)
626 {
627
2/2
✓ Branch 0 taken 438509 times.
✓ Branch 1 taken 64709 times.
503218 if (isp_split_type == ISP_NO_SPLIT)
628 438509 return 1;
629
8/8
✓ Branch 0 taken 15455 times.
✓ Branch 1 taken 49254 times.
✓ Branch 2 taken 4345 times.
✓ Branch 3 taken 11110 times.
✓ Branch 4 taken 23500 times.
✓ Branch 5 taken 30099 times.
✓ Branch 6 taken 12895 times.
✓ Branch 7 taken 10605 times.
64709 if ((cb_width == 4 && cb_height == 8) || (cb_width == 8 && cb_height == 4))
630 24005 return 2;
631 40704 return 4;
632 }
633
634 243752 static int get_cclm_enabled(const VVCLocalContext *lc, const int x0, const int y0)
635 {
636 243752 const VVCFrameContext *fc = lc->fc;
637 243752 const VVCSPS *sps = fc->ps.sps;
638 243752 int enabled = 0;
639
640
2/2
✓ Branch 0 taken 449 times.
✓ Branch 1 taken 243303 times.
243752 if (!sps->r->sps_cclm_enabled_flag)
641 449 return 0;
642
6/6
✓ Branch 0 taken 222520 times.
✓ Branch 1 taken 20783 times.
✓ Branch 2 taken 158171 times.
✓ Branch 3 taken 64349 times.
✓ Branch 4 taken 1163 times.
✓ Branch 5 taken 157008 times.
243303 if (!sps->r->sps_qtbtt_dual_tree_intra_flag || !IS_I(lc->sc->sh.r) || sps->ctb_log2_size_y < 6)
643 86295 return 1;
644 else {
645 157008 const int x64 = x0 >> 6 << 6;
646 157008 const int y64 = y0 >> 6 << 6;
647 157008 const int y32 = y0 >> 5 << 5;
648 157008 const int x64_cu = x64 >> fc->ps.sps->min_cb_log2_size_y;
649 157008 const int y64_cu = y64 >> fc->ps.sps->min_cb_log2_size_y;
650 157008 const int y32_cu = y32 >> fc->ps.sps->min_cb_log2_size_y;
651 157008 const int min_cb_width = fc->ps.pps->min_cb_width;
652 157008 const int depth = SAMPLE_CTB(fc->tab.cqt_depth[1], x64_cu, y64_cu);
653 157008 const int min_depth = fc->ps.sps->ctb_log2_size_y - 6;
654 157008 const VVCSplitMode msm64 = (VVCSplitMode)TAB_MSM(fc, 0, x64, y64);
655 157008 const VVCSplitMode msm32 = (VVCSplitMode)TAB_MSM(fc, 1, x64, y32);
656
657
2/2
✓ Branch 0 taken 19375 times.
✓ Branch 1 taken 137633 times.
176383 enabled = SAMPLE_CTB(fc->tab.cb_width[1], x64_cu, y64_cu) == 64 &&
658
2/2
✓ Branch 0 taken 6527 times.
✓ Branch 1 taken 12848 times.
19375 SAMPLE_CTB(fc->tab.cb_height[1], x64_cu, y64_cu) == 64;
659
2/2
✓ Branch 0 taken 21666 times.
✓ Branch 1 taken 16231 times.
37897 enabled |= depth == min_depth && msm64 == SPLIT_BT_HOR &&
660
4/4
✓ Branch 0 taken 37897 times.
✓ Branch 1 taken 119111 times.
✓ Branch 2 taken 12084 times.
✓ Branch 3 taken 9582 times.
206989 SAMPLE_CTB(fc->tab.cb_width[1], x64_cu, y32_cu) == 64 &&
661
2/2
✓ Branch 0 taken 4734 times.
✓ Branch 1 taken 7350 times.
12084 SAMPLE_CTB(fc->tab.cb_height[1], x64_cu, y32_cu) == 32;
662 157008 enabled |= depth > min_depth;
663
6/6
✓ Branch 0 taken 37897 times.
✓ Branch 1 taken 119111 times.
✓ Branch 2 taken 21666 times.
✓ Branch 3 taken 16231 times.
✓ Branch 4 taken 7990 times.
✓ Branch 5 taken 13676 times.
157008 enabled |= depth == min_depth && msm64 == SPLIT_BT_HOR && msm32 == SPLIT_BT_VER;
664
665
2/2
✓ Branch 0 taken 137905 times.
✓ Branch 1 taken 19103 times.
157008 if (enabled) {
666 137905 const int w = SAMPLE_CTB(fc->tab.cb_width[0], x64_cu, y64_cu);
667 137905 const int h = SAMPLE_CTB(fc->tab.cb_height[0], x64_cu, y64_cu);
668 137905 const int depth0 = SAMPLE_CTB(fc->tab.cqt_depth[0], x64_cu, y64_cu);
669
8/8
✓ Branch 0 taken 5746 times.
✓ Branch 1 taken 132159 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 132159 times.
137905 if ((w == 64 && h == 64 && TAB_ISPMF(fc, x64, y64)) ||
670
4/4
✓ Branch 0 taken 190 times.
✓ Branch 1 taken 4964 times.
✓ Branch 2 taken 1286 times.
✓ Branch 3 taken 131063 times.
137313 ((w < 64 || h < 64) && depth0 == min_depth))
671 1878 return 0;
672 }
673
674 }
675
676 155130 return enabled;
677 }
678
679 893971 static int less(const void *a, const void *b)
680 {
681 893971 return *(const int*)a - *(const int*)b;
682 }
683
684 //8.4.2 Derivation process for luma intra prediction mode
685 503218 static enum IntraPredMode luma_intra_pred_mode(VVCLocalContext* lc, const int intra_subpartitions_mode_flag)
686 {
687 503218 VVCFrameContext *fc = lc->fc;
688 503218 CodingUnit *cu = lc->cu;
689 503218 const int x0 = cu->x0;
690 503218 const int y0 = cu->y0;
691 enum IntraPredMode pred;
692 503218 int intra_luma_not_planar_flag = 1;
693 503218 int intra_luma_mpm_remainder = 0;
694 503218 int intra_luma_mpm_flag = 1;
695 503218 int intra_luma_mpm_idx = 0;
696
697
2/2
✓ Branch 0 taken 458552 times.
✓ Branch 1 taken 44666 times.
503218 if (!cu->intra_luma_ref_idx)
698 458552 intra_luma_mpm_flag = ff_vvc_intra_luma_mpm_flag(lc);
699
2/2
✓ Branch 0 taken 375805 times.
✓ Branch 1 taken 127413 times.
503218 if (intra_luma_mpm_flag) {
700
2/2
✓ Branch 0 taken 331139 times.
✓ Branch 1 taken 44666 times.
375805 if (!cu->intra_luma_ref_idx)
701 331139 intra_luma_not_planar_flag = ff_vvc_intra_luma_not_planar_flag(lc, intra_subpartitions_mode_flag);
702
2/2
✓ Branch 0 taken 201212 times.
✓ Branch 1 taken 174593 times.
375805 if (intra_luma_not_planar_flag)
703 201212 intra_luma_mpm_idx = ff_vvc_intra_luma_mpm_idx(lc);
704 } else {
705 127413 intra_luma_mpm_remainder = ff_vvc_intra_luma_mpm_remainder(lc);
706 }
707
708
2/2
✓ Branch 0 taken 174593 times.
✓ Branch 1 taken 328625 times.
503218 if (!intra_luma_not_planar_flag) {
709 174593 pred = INTRA_PLANAR;
710 } else {
711 328625 const VVCSPS *sps = fc->ps.sps;
712 328625 const int x_a = (x0 - 1) >> sps->min_cb_log2_size_y;
713 328625 const int y_a = (y0 + cu->cb_height - 1) >> sps->min_cb_log2_size_y;
714 328625 const int x_b = (x0 + cu->cb_width - 1) >> sps->min_cb_log2_size_y;
715 328625 const int y_b = (y0 - 1) >> sps->min_cb_log2_size_y;
716 328625 int min_cb_width = fc->ps.pps->min_cb_width;
717 328625 int x0b = av_zero_extend(x0, sps->ctb_log2_size_y);
718 328625 int y0b = av_zero_extend(y0, sps->ctb_log2_size_y);
719
4/4
✓ Branch 0 taken 74041 times.
✓ Branch 1 taken 254584 times.
✓ Branch 2 taken 68035 times.
✓ Branch 3 taken 6006 times.
328625 const int available_l = lc->ctb_left_flag || x0b;
720
4/4
✓ Branch 0 taken 118009 times.
✓ Branch 1 taken 210616 times.
✓ Branch 2 taken 111455 times.
✓ Branch 3 taken 6554 times.
328625 const int available_u = lc->ctb_up_flag || y0b;
721
722 int a, b, cand[5];
723
724
4/4
✓ Branch 0 taken 322619 times.
✓ Branch 1 taken 6006 times.
✓ Branch 2 taken 289714 times.
✓ Branch 3 taken 32905 times.
328625 if (!available_l || (SAMPLE_CTB(fc->tab.cpm[0], x_a, y_a) != MODE_INTRA) ||
725
2/2
✓ Branch 0 taken 40058 times.
✓ Branch 1 taken 249656 times.
289714 SAMPLE_CTB(fc->tab.imf, x_a, y_a)) {
726 78969 a = INTRA_PLANAR;
727 } else {
728 249656 a = SAMPLE_CTB(fc->tab.ipm, x_a, y_a);
729 }
730
731
4/4
✓ Branch 0 taken 322071 times.
✓ Branch 1 taken 6554 times.
✓ Branch 2 taken 287269 times.
✓ Branch 3 taken 34802 times.
328625 if (!available_u || (SAMPLE_CTB(fc->tab.cpm[0], x_b, y_b) != MODE_INTRA) ||
732
4/4
✓ Branch 0 taken 246971 times.
✓ Branch 1 taken 40298 times.
✓ Branch 2 taken 14370 times.
✓ Branch 3 taken 232601 times.
287269 SAMPLE_CTB(fc->tab.imf, x_b, y_b) || !y0b) {
733 96024 b = INTRA_PLANAR;
734 } else {
735 232601 b = SAMPLE_CTB(fc->tab.ipm, x_b, y_b);
736 }
737
738
4/4
✓ Branch 0 taken 102246 times.
✓ Branch 1 taken 226379 times.
✓ Branch 2 taken 19846 times.
✓ Branch 3 taken 82400 times.
328625 if (a == b && a > INTRA_DC) {
739 19846 cand[0] = a;
740 19846 cand[1] = 2 + ((a + 61) % 64);
741 19846 cand[2] = 2 + ((a - 1) % 64);
742 19846 cand[3] = 2 + ((a + 60) % 64);
743 19846 cand[4] = 2 + (a % 64);
744 } else {
745 308779 const int minab = FFMIN(a, b);
746 308779 const int maxab = FFMAX(a, b);
747
4/4
✓ Branch 0 taken 149149 times.
✓ Branch 1 taken 159630 times.
✓ Branch 2 taken 73667 times.
✓ Branch 3 taken 75482 times.
382446 if (a > INTRA_DC && b > INTRA_DC) {
748 73667 const int diff = maxab - minab;
749 73667 cand[0] = a;
750 73667 cand[1] = b;
751
2/2
✓ Branch 0 taken 14566 times.
✓ Branch 1 taken 59101 times.
73667 if (diff == 1) {
752 14566 cand[2] = 2 + ((minab + 61) % 64);
753 14566 cand[3] = 2 + ((maxab - 1) % 64);
754 14566 cand[4] = 2 + ((minab + 60) % 64);
755
2/2
✓ Branch 0 taken 582 times.
✓ Branch 1 taken 58519 times.
59101 } else if (diff >= 62) {
756 582 cand[2] = 2 + ((minab - 1) % 64);
757 582 cand[3] = 2 + ((maxab + 61) % 64);
758 582 cand[4] = 2 + (minab % 64);
759
2/2
✓ Branch 0 taken 6924 times.
✓ Branch 1 taken 51595 times.
58519 } else if (diff == 2) {
760 6924 cand[2] = 2 + ((minab - 1) % 64);
761 6924 cand[3] = 2 + ((minab + 61) % 64);
762 6924 cand[4] = 2 + ((maxab - 1) % 64);
763 } else {
764 51595 cand[2] = 2 + ((minab + 61) % 64);
765 51595 cand[3] = 2 + ((minab - 1) % 64);
766 51595 cand[4] = 2 + ((maxab + 61) % 64);
767 }
768
4/4
✓ Branch 0 taken 159630 times.
✓ Branch 1 taken 75482 times.
✓ Branch 2 taken 62280 times.
✓ Branch 3 taken 97350 times.
235112 } else if (a > INTRA_DC || b > INTRA_DC) {
769 137762 cand[0] = maxab;
770 137762 cand[1] = 2 + ((maxab + 61 ) % 64);
771 137762 cand[2] = 2 + ((maxab - 1) % 64);
772 137762 cand[3] = 2 + ((maxab + 60 ) % 64);
773 137762 cand[4] = 2 + (maxab % 64);
774 } else {
775 97350 cand[0] = INTRA_DC;
776 97350 cand[1] = INTRA_VERT;
777 97350 cand[2] = INTRA_HORZ;
778 97350 cand[3] = INTRA_VERT - 4;
779 97350 cand[4] = INTRA_VERT + 4;
780 }
781 }
782
2/2
✓ Branch 0 taken 201212 times.
✓ Branch 1 taken 127413 times.
328625 if (intra_luma_mpm_flag) {
783 201212 pred = cand[intra_luma_mpm_idx];
784 } else {
785 127413 qsort(cand, FF_ARRAY_ELEMS(cand), sizeof(cand[0]), less);
786 127413 pred = intra_luma_mpm_remainder + 1;
787
2/2
✓ Branch 0 taken 637065 times.
✓ Branch 1 taken 127413 times.
764478 for (int i = 0; i < FF_ARRAY_ELEMS(cand); i++) {
788
2/2
✓ Branch 0 taken 312979 times.
✓ Branch 1 taken 324086 times.
637065 if (pred >= cand[i])
789 312979 pred++;
790 }
791 }
792 }
793 503218 return pred;
794 }
795
796 990255 static int lfnst_idx_decode(VVCLocalContext *lc)
797 {
798 990255 CodingUnit *cu = lc->cu;
799 990255 const VVCTreeType tree_type = cu->tree_type;
800 990255 const VVCSPS *sps = lc->fc->ps.sps;
801 990255 const int cb_width = cu->cb_width;
802 990255 const int cb_height = cu->cb_height;
803 990255 const TransformUnit *tu = cu->tus.head;
804 int lfnst_width, lfnst_height, min_lfnst;
805 990255 int lfnst_idx = 0;
806
807 990255 memset(cu->apply_lfnst_flag, 0, sizeof(cu->apply_lfnst_flag));
808
809
6/6
✓ Branch 0 taken 766688 times.
✓ Branch 1 taken 223567 times.
✓ Branch 2 taken 633164 times.
✓ Branch 3 taken 133524 times.
✓ Branch 4 taken 1990 times.
✓ Branch 5 taken 631174 times.
990255 if (!sps->r->sps_lfnst_enabled_flag || cu->pred_mode != MODE_INTRA || FFMAX(cb_width, cb_height) > sps->max_tb_size_y)
810 359081 return 0;
811
812
2/2
✓ Branch 0 taken 743410 times.
✓ Branch 1 taken 611085 times.
1354495 while (tu) {
813
2/2
✓ Branch 0 taken 984106 times.
✓ Branch 1 taken 723321 times.
1707427 for (int j = 0; j < tu->nb_tbs; j++) {
814 984106 const TransformBlock *tb = tu->tbs + j;
815
4/4
✓ Branch 0 taken 623188 times.
✓ Branch 1 taken 360918 times.
✓ Branch 2 taken 20089 times.
✓ Branch 3 taken 603099 times.
984106 if (tu->coded_flag[tb->c_idx] && tb->ts)
816 20089 return 0;
817 }
818 723321 tu = tu->next;
819 }
820
821
2/2
✓ Branch 0 taken 147717 times.
✓ Branch 1 taken 463368 times.
611085 if (tree_type == DUAL_TREE_CHROMA) {
822 147717 lfnst_width = cb_width >> sps->hshift[1];
823 147717 lfnst_height = cb_height >> sps->vshift[1];
824 } else {
825 463368 const int vs = cu->isp_split_type == ISP_VER_SPLIT;
826 463368 const int hs = cu->isp_split_type == ISP_HOR_SPLIT;
827
2/2
✓ Branch 0 taken 18121 times.
✓ Branch 1 taken 445247 times.
463368 lfnst_width = vs ? cb_width / cu->num_intra_subpartitions : cb_width;
828
2/2
✓ Branch 0 taken 31845 times.
✓ Branch 1 taken 431523 times.
463368 lfnst_height = hs ? cb_height / cu->num_intra_subpartitions : cb_height;
829 }
830 611085 min_lfnst = FFMIN(lfnst_width, lfnst_height);
831
6/6
✓ Branch 0 taken 463368 times.
✓ Branch 1 taken 147717 times.
✓ Branch 2 taken 106630 times.
✓ Branch 3 taken 356738 times.
✓ Branch 4 taken 86525 times.
✓ Branch 5 taken 20105 times.
611085 if (tree_type != DUAL_TREE_CHROMA && cu->intra_mip_flag && min_lfnst < 16)
832 86525 return 0;
833
834
2/2
✓ Branch 0 taken 485307 times.
✓ Branch 1 taken 39253 times.
524560 if (min_lfnst >= 4) {
835
6/6
✓ Branch 0 taken 456986 times.
✓ Branch 1 taken 28321 times.
✓ Branch 2 taken 194455 times.
✓ Branch 3 taken 262531 times.
✓ Branch 4 taken 189014 times.
✓ Branch 5 taken 33762 times.
485307 if ((cu->isp_split_type != ISP_NO_SPLIT || !lc->parse.lfnst_dc_only) && lc->parse.lfnst_zero_out_sig_coeff_flag)
836 189014 lfnst_idx = ff_vvc_lfnst_idx(lc, tree_type != SINGLE_TREE);
837 }
838
839
2/2
✓ Branch 0 taken 141328 times.
✓ Branch 1 taken 383232 times.
524560 if (lfnst_idx) {
840 141328 cu->apply_lfnst_flag[LUMA] = tree_type != DUAL_TREE_CHROMA;
841 141328 cu->apply_lfnst_flag[CB] = cu->apply_lfnst_flag[CR] = tree_type == DUAL_TREE_CHROMA;
842 }
843
844 524560 return lfnst_idx;
845 }
846
847 990255 static MtsIdx mts_idx_decode(VVCLocalContext *lc)
848 {
849 990255 const CodingUnit *cu = lc->cu;
850 990255 const VVCSPS *sps = lc->fc->ps.sps;
851 990255 const int cb_width = cu->cb_width;
852 990255 const int cb_height = cu->cb_height;
853 990255 const uint8_t transform_skip_flag = cu->tus.head->tbs[0].ts; //fix me
854 990255 int mts_idx = MTS_DCT2_DCT2;
855
6/6
✓ Branch 0 taken 802947 times.
✓ Branch 1 taken 187308 times.
✓ Branch 2 taken 695919 times.
✓ Branch 3 taken 107028 times.
✓ Branch 4 taken 653551 times.
✓ Branch 5 taken 42368 times.
990255 if (cu->tree_type != DUAL_TREE_CHROMA && !cu->lfnst_idx &&
856
2/2
✓ Branch 0 taken 630516 times.
✓ Branch 1 taken 23035 times.
653551 !transform_skip_flag && FFMAX(cb_width, cb_height) <= 32 &&
857
4/4
✓ Branch 0 taken 583069 times.
✓ Branch 1 taken 47447 times.
✓ Branch 2 taken 539217 times.
✓ Branch 3 taken 43852 times.
630516 cu->isp_split_type == ISP_NO_SPLIT && !cu->sbt_flag &&
858
4/4
✓ Branch 0 taken 530319 times.
✓ Branch 1 taken 8898 times.
✓ Branch 2 taken 332373 times.
✓ Branch 3 taken 197946 times.
539217 lc->parse.mts_zero_out_sig_coeff_flag && !lc->parse.mts_dc_only) {
859
4/4
✓ Branch 0 taken 58832 times.
✓ Branch 1 taken 273541 times.
✓ Branch 2 taken 56366 times.
✓ Branch 3 taken 2466 times.
332373 if ((cu->pred_mode == MODE_INTER && sps->r->sps_explicit_mts_inter_enabled_flag) ||
860
4/4
✓ Branch 0 taken 269199 times.
✓ Branch 1 taken 60708 times.
✓ Branch 2 taken 250208 times.
✓ Branch 3 taken 18991 times.
329907 (cu->pred_mode == MODE_INTRA && sps->r->sps_explicit_mts_intra_enabled_flag)) {
861 252674 mts_idx = ff_vvc_mts_idx(lc);
862 }
863 }
864
865 990255 return mts_idx;
866 }
867
868 249105 static enum IntraPredMode derive_center_luma_intra_pred_mode(const VVCFrameContext *fc, const VVCSPS *sps, const VVCPPS *pps, const CodingUnit *cu)
869 {
870 249105 const int x_center = (cu->x0 + cu->cb_width / 2) >> sps->min_cb_log2_size_y;
871 249105 const int y_center = (cu->y0 + cu->cb_height / 2) >> sps->min_cb_log2_size_y;
872 249105 const int min_cb_width = pps->min_cb_width;
873 249105 const int intra_mip_flag = SAMPLE_CTB(fc->tab.imf, x_center, y_center);
874 249105 const int cu_pred_mode = SAMPLE_CTB(fc->tab.cpm[0], x_center, y_center);
875 249105 const int intra_pred_mode_y = SAMPLE_CTB(fc->tab.ipm, x_center, y_center);
876
877
2/2
✓ Branch 0 taken 47278 times.
✓ Branch 1 taken 201827 times.
249105 if (intra_mip_flag) {
878
4/4
✓ Branch 0 taken 9506 times.
✓ Branch 1 taken 37772 times.
✓ Branch 2 taken 251 times.
✓ Branch 3 taken 9255 times.
47278 if (cu->tree_type == SINGLE_TREE && sps->r->sps_chroma_format_idc == CHROMA_FORMAT_444)
879 251 return INTRA_INVALID;
880 47027 return INTRA_PLANAR;
881 }
882
4/4
✓ Branch 0 taken 191336 times.
✓ Branch 1 taken 10491 times.
✓ Branch 2 taken 206 times.
✓ Branch 3 taken 191130 times.
201827 if (cu_pred_mode == MODE_IBC || cu_pred_mode == MODE_PLT)
883 10697 return INTRA_DC;
884 191130 return intra_pred_mode_y;
885 }
886
887 249892 static void derive_chroma_intra_pred_mode(VVCLocalContext *lc,
888 const int cclm_mode_flag, const int cclm_mode_idx, const int intra_chroma_pred_mode)
889 {
890 249892 const VVCFrameContext *fc = lc->fc;
891 249892 CodingUnit *cu = lc->cu;
892 249892 const VVCSPS *sps = fc->ps.sps;
893 249892 const VVCPPS *pps = fc->ps.pps;
894 249892 const int x_cb = cu->x0 >> sps->min_cb_log2_size_y;
895 249892 const int y_cb = cu->y0 >> sps->min_cb_log2_size_y;
896 249892 const int min_cb_width = pps->min_cb_width;
897 249892 const int intra_mip_flag = SAMPLE_CTB(fc->tab.imf, x_cb, y_cb);
898 249892 enum IntraPredMode luma_intra_pred_mode = SAMPLE_CTB(fc->tab.ipm, x_cb, y_cb);
899
900
6/6
✓ Branch 0 taken 62629 times.
✓ Branch 1 taken 187263 times.
✓ Branch 2 taken 10433 times.
✓ Branch 3 taken 52196 times.
✓ Branch 4 taken 7648 times.
✓ Branch 5 taken 2785 times.
249892 if (cu->tree_type == SINGLE_TREE && sps->r->sps_chroma_format_idc == CHROMA_FORMAT_444 &&
901
4/4
✓ Branch 0 taken 6140 times.
✓ Branch 1 taken 1508 times.
✓ Branch 2 taken 787 times.
✓ Branch 3 taken 8138 times.
10433 (intra_chroma_pred_mode == 4 || cu->act_enabled_flag) && intra_mip_flag) {
902 787 cu->mip_chroma_direct_flag = 1;
903 787 cu->intra_pred_mode_c = luma_intra_pred_mode;
904 787 return;
905 }
906 249105 luma_intra_pred_mode = derive_center_luma_intra_pred_mode(fc, sps, pps, cu);
907
908
2/2
✓ Branch 0 taken 5583 times.
✓ Branch 1 taken 243522 times.
249105 if (cu->act_enabled_flag) {
909 5583 cu->intra_pred_mode_c = luma_intra_pred_mode;
910 5583 return;
911 }
912
2/2
✓ Branch 0 taken 96828 times.
✓ Branch 1 taken 146694 times.
243522 if (cclm_mode_flag) {
913 96828 cu->intra_pred_mode_c = INTRA_LT_CCLM + cclm_mode_idx;
914
2/2
✓ Branch 0 taken 102948 times.
✓ Branch 1 taken 43746 times.
146694 } else if (intra_chroma_pred_mode == 4){
915 102948 cu->intra_pred_mode_c = luma_intra_pred_mode;
916 } else {
917 const static IntraPredMode pred_mode_c[][4 + 1] = {
918 {INTRA_VDIAG, INTRA_PLANAR, INTRA_PLANAR, INTRA_PLANAR, INTRA_PLANAR},
919 {INTRA_VERT, INTRA_VDIAG, INTRA_VERT, INTRA_VERT, INTRA_VERT},
920 {INTRA_HORZ, INTRA_HORZ, INTRA_VDIAG, INTRA_HORZ, INTRA_HORZ},
921 {INTRA_DC, INTRA_DC, INTRA_DC, INTRA_VDIAG, INTRA_DC},
922 };
923 43746 const int modes[4] = {INTRA_PLANAR, INTRA_VERT, INTRA_HORZ, INTRA_DC};
924 int idx;
925
926 // This workaround is necessary to have 4:4:4 video decode correctly
927 // See VVC ticket https://jvet.hhi.fraunhofer.de/trac/vvc/ticket/1602
928 // and VTM source https://vcgit.hhi.fraunhofer.de/jvet/VVCSoftware_VTM/-/blob/master/source/Lib/CommonLib/UnitTools.cpp#L736
929
6/6
✓ Branch 0 taken 3354 times.
✓ Branch 1 taken 40392 times.
✓ Branch 2 taken 246 times.
✓ Branch 3 taken 3108 times.
✓ Branch 4 taken 43 times.
✓ Branch 5 taken 203 times.
43746 if (cu->tree_type == SINGLE_TREE && sps->r->sps_chroma_format_idc == CHROMA_FORMAT_444 && intra_mip_flag) {
930 43 idx = 4;
931 } else {
932
2/2
✓ Branch 0 taken 110605 times.
✓ Branch 1 taken 15253 times.
125858 for (idx = 0; idx < FF_ARRAY_ELEMS(modes); idx++) {
933
2/2
✓ Branch 0 taken 28450 times.
✓ Branch 1 taken 82155 times.
110605 if (modes[idx] == luma_intra_pred_mode)
934 28450 break;
935 }
936 }
937
938 43746 cu->intra_pred_mode_c = pred_mode_c[intra_chroma_pred_mode][idx];
939 }
940
4/4
✓ Branch 0 taken 11978 times.
✓ Branch 1 taken 231544 times.
✓ Branch 2 taken 8009 times.
✓ Branch 3 taken 3969 times.
243522 if (sps->r->sps_chroma_format_idc == CHROMA_FORMAT_422 && cu->intra_pred_mode_c <= INTRA_VDIAG) {
941 const static int mode_map_422[INTRA_VDIAG + 1] = {
942 0, 1, 61, 62, 63, 64, 65, 66, 2, 3, 5, 6, 8, 10, 12, 13,
943 14, 16, 18, 20, 22, 23, 24, 26, 28, 30, 31, 33, 34, 35, 36, 37,
944 38, 39, 40, 41, 41, 42, 43, 43, 44, 44, 45, 45, 46, 47, 48, 48,
945 49, 49, 50, 51, 51, 52, 52, 53, 54, 55, 55, 56, 56, 57, 57, 58,
946 59, 59, 60,
947 };
948 8009 cu->intra_pred_mode_c = mode_map_422[cu->intra_pred_mode_c];
949 }
950 }
951
952 293947 static av_always_inline uint8_t pack_mip_info(int intra_mip_flag,
953 int intra_mip_transposed_flag, int intra_mip_mode)
954 {
955 293947 return (intra_mip_mode << 2) | (intra_mip_transposed_flag << 1) | intra_mip_flag;
956 }
957
958 625020 static void intra_luma_pred_modes(VVCLocalContext *lc)
959 {
960 625020 VVCFrameContext *fc = lc->fc;
961 625020 const VVCSPS *sps = fc->ps.sps;
962 625020 const VVCPPS *pps = fc->ps.pps;
963 625020 CodingUnit *cu = lc->cu;
964 625020 const int log2_min_cb_size = sps->min_cb_log2_size_y;
965 625020 const int x0 = cu->x0;
966 625020 const int y0 = cu->y0;
967 625020 const int x_cb = x0 >> log2_min_cb_size;
968 625020 const int y_cb = y0 >> log2_min_cb_size;
969 625020 const int cb_width = cu->cb_width;
970 625020 const int cb_height = cu->cb_height;
971
972 625020 cu->intra_luma_ref_idx = 0;
973
6/6
✓ Branch 0 taken 48105 times.
✓ Branch 1 taken 576915 times.
✓ Branch 2 taken 47020 times.
✓ Branch 3 taken 1085 times.
✓ Branch 4 taken 46942 times.
✓ Branch 5 taken 78 times.
625020 if (sps->r->sps_bdpcm_enabled_flag && cb_width <= sps->max_ts_size && cb_height <= sps->max_ts_size)
974 46942 cu->bdpcm_flag[LUMA] = ff_vvc_intra_bdpcm_luma_flag(lc);
975
2/2
✓ Branch 0 taken 10719 times.
✓ Branch 1 taken 614301 times.
625020 if (cu->bdpcm_flag[LUMA]) {
976
2/2
✓ Branch 1 taken 5499 times.
✓ Branch 2 taken 5220 times.
10719 cu->intra_pred_mode_y = ff_vvc_intra_bdpcm_luma_dir_flag(lc) ? INTRA_VERT : INTRA_HORZ;
977 } else {
978
2/2
✓ Branch 0 taken 471859 times.
✓ Branch 1 taken 142442 times.
614301 if (sps->r->sps_mip_enabled_flag)
979 471859 cu->intra_mip_flag = ff_vvc_intra_mip_flag(lc, fc->tab.imf);
980
2/2
✓ Branch 0 taken 111083 times.
✓ Branch 1 taken 503218 times.
614301 if (cu->intra_mip_flag) {
981 111083 int intra_mip_transposed_flag = ff_vvc_intra_mip_transposed_flag(lc);
982 111083 int intra_mip_mode = ff_vvc_intra_mip_mode(lc);
983 111083 int x = y_cb * pps->min_cb_width + x_cb;
984
2/2
✓ Branch 0 taken 293947 times.
✓ Branch 1 taken 111083 times.
405030 for (int y = 0; y < (cb_height>>log2_min_cb_size); y++) {
985 293947 int width = cb_width>>log2_min_cb_size;
986 293947 const uint8_t mip_info = pack_mip_info(cu->intra_mip_flag,
987 intra_mip_transposed_flag, intra_mip_mode);
988 293947 memset(&fc->tab.imf[x], mip_info, width);
989 293947 x += pps->min_cb_width;
990 }
991 111083 cu->intra_pred_mode_y = intra_mip_mode;
992 } else {
993 503218 int intra_subpartitions_mode_flag = 0;
994
4/4
✓ Branch 0 taken 484294 times.
✓ Branch 1 taken 18924 times.
✓ Branch 2 taken 443672 times.
✓ Branch 3 taken 40622 times.
503218 if (sps->r->sps_mrl_enabled_flag && ((y0 % sps->ctb_size_y) > 0))
995 443672 cu->intra_luma_ref_idx = ff_vvc_intra_luma_ref_idx(lc);
996
4/4
✓ Branch 0 taken 484294 times.
✓ Branch 1 taken 18924 times.
✓ Branch 2 taken 439628 times.
✓ Branch 3 taken 44666 times.
503218 if (sps->r->sps_isp_enabled_flag && !cu->intra_luma_ref_idx &&
997
4/4
✓ Branch 0 taken 439188 times.
✓ Branch 1 taken 440 times.
✓ Branch 2 taken 438860 times.
✓ Branch 3 taken 328 times.
439628 (cb_width <= sps->max_tb_size_y && cb_height <= sps->max_tb_size_y) &&
998
2/2
✓ Branch 0 taken 372829 times.
✓ Branch 1 taken 66031 times.
438860 (cb_width * cb_height > MIN_TU_SIZE * MIN_TU_SIZE) &&
999
2/2
✓ Branch 0 taken 369431 times.
✓ Branch 1 taken 3398 times.
372829 !cu->act_enabled_flag)
1000 369431 intra_subpartitions_mode_flag = ff_vvc_intra_subpartitions_mode_flag(lc);
1001
4/4
✓ Branch 0 taken 97570 times.
✓ Branch 1 taken 405648 times.
✓ Branch 2 taken 21217 times.
✓ Branch 3 taken 76353 times.
503218 if (!(x0 & 63) && !(y0 & 63))
1002 21217 TAB_ISPMF(fc, x0, y0) = intra_subpartitions_mode_flag;
1003 503218 cu->isp_split_type = ff_vvc_isp_split_type(lc, intra_subpartitions_mode_flag);
1004 503218 cu->num_intra_subpartitions = get_num_intra_subpartitions(cu->isp_split_type, cb_width, cb_height);
1005 503218 cu->intra_pred_mode_y = luma_intra_pred_mode(lc, intra_subpartitions_mode_flag);
1006 }
1007 }
1008 625020 set_cb_tab(lc, fc->tab.ipm, cu->intra_pred_mode_y);
1009 625020 }
1010
1011 250024 static void intra_chroma_pred_modes(VVCLocalContext *lc)
1012 {
1013 250024 const VVCSPS *sps = lc->fc->ps.sps;
1014 250024 CodingUnit *cu = lc->cu;
1015 250024 const int hs = sps->hshift[CHROMA];
1016 250024 const int vs = sps->vshift[CHROMA];
1017 250024 int cclm_mode_flag = 0;
1018 250024 int cclm_mode_idx = 0;
1019 250024 int intra_chroma_pred_mode = 0;
1020
1021
2/2
✓ Branch 0 taken 243884 times.
✓ Branch 1 taken 6140 times.
250024 if (!cu->act_enabled_flag) {
1022 243884 cu->mip_chroma_direct_flag = 0;
1023
2/2
✓ Branch 0 taken 40212 times.
✓ Branch 1 taken 203672 times.
243884 if (sps->r->sps_bdpcm_enabled_flag &&
1024
2/2
✓ Branch 0 taken 38812 times.
✓ Branch 1 taken 1400 times.
40212 (cu->cb_width >> hs) <= sps->max_ts_size &&
1025
2/2
✓ Branch 0 taken 38304 times.
✓ Branch 1 taken 508 times.
38812 (cu->cb_height >> vs) <= sps->max_ts_size) {
1026 38304 cu->bdpcm_flag[CB] = cu->bdpcm_flag[CR] = ff_vvc_intra_bdpcm_chroma_flag(lc);
1027 }
1028
2/2
✓ Branch 0 taken 132 times.
✓ Branch 1 taken 243752 times.
243884 if (cu->bdpcm_flag[CHROMA]) {
1029
2/2
✓ Branch 1 taken 121 times.
✓ Branch 2 taken 11 times.
132 cu->intra_pred_mode_c = ff_vvc_intra_bdpcm_chroma_dir_flag(lc) ? INTRA_VERT : INTRA_HORZ;
1030 } else {
1031 243752 const int cclm_enabled = get_cclm_enabled(lc, cu->x0, cu->y0);
1032
1033
2/2
✓ Branch 0 taken 222322 times.
✓ Branch 1 taken 21430 times.
243752 if (cclm_enabled)
1034 222322 cclm_mode_flag = ff_vvc_cclm_mode_flag(lc);
1035
1036
2/2
✓ Branch 0 taken 96828 times.
✓ Branch 1 taken 146924 times.
243752 if (cclm_mode_flag)
1037 96828 cclm_mode_idx = ff_vvc_cclm_mode_idx(lc);
1038 else
1039 146924 intra_chroma_pred_mode = ff_vvc_intra_chroma_pred_mode(lc);
1040 }
1041 }
1042
1043
2/2
✓ Branch 0 taken 249892 times.
✓ Branch 1 taken 132 times.
250024 if (!cu->bdpcm_flag[CHROMA])
1044 249892 derive_chroma_intra_pred_mode(lc, cclm_mode_flag, cclm_mode_idx, intra_chroma_pred_mode);
1045 250024 }
1046
1047 1344148 static PredMode pred_mode_decode(VVCLocalContext *lc,
1048 const VVCTreeType tree_type,
1049 const VVCModeType mode_type)
1050 {
1051 1344148 const VVCFrameContext *fc = lc->fc;
1052 1344148 CodingUnit *cu = lc->cu;
1053 1344148 const VVCSPS *sps = fc->ps.sps;
1054 1344148 const H266RawSliceHeader *rsh = lc->sc->sh.r;
1055 1344148 const int ch_type = tree_type == DUAL_TREE_CHROMA ? 1 : 0;
1056
4/4
✓ Branch 0 taken 300975 times.
✓ Branch 1 taken 1043173 times.
✓ Branch 2 taken 127632 times.
✓ Branch 3 taken 173343 times.
1344148 const int is_4x4 = cu->cb_width == 4 && cu->cb_height == 4;
1057
4/4
✓ Branch 0 taken 1317780 times.
✓ Branch 1 taken 26368 times.
✓ Branch 2 taken 2338 times.
✓ Branch 3 taken 1315442 times.
1344148 const int is_128 = cu->cb_width == 128 || cu->cb_height == 128;
1058 1344148 const int hs = sps->hshift[CHROMA];
1059 1344148 const int vs = sps->vshift[CHROMA];
1060 int pred_mode_flag;
1061 int pred_mode_ibc_flag;
1062 PredMode pred_mode;
1063
1064 1344148 cu->skip_flag = 0;
1065
4/4
✓ Branch 0 taken 717365 times.
✓ Branch 1 taken 626783 times.
✓ Branch 2 taken 85795 times.
✓ Branch 3 taken 631570 times.
1344148 if (!IS_I(rsh) || sps->r->sps_ibc_enabled_flag) {
1066
4/4
✓ Branch 0 taken 678024 times.
✓ Branch 1 taken 34554 times.
✓ Branch 2 taken 615422 times.
✓ Branch 3 taken 62602 times.
712578 if (tree_type != DUAL_TREE_CHROMA &&
1067
2/2
✓ Branch 0 taken 53502 times.
✓ Branch 1 taken 561920 times.
615422 ((!is_4x4 && mode_type != MODE_TYPE_INTRA) ||
1068
3/4
✓ Branch 0 taken 88020 times.
✓ Branch 1 taken 28084 times.
✓ Branch 2 taken 88020 times.
✗ Branch 3 not taken.
116104 (sps->r->sps_ibc_enabled_flag && !is_128))) {
1069 649940 cu->skip_flag = ff_vvc_cu_skip_flag(lc, fc->tab.skip);
1070 }
1071
1072
6/6
✓ Branch 0 taken 649976 times.
✓ Branch 1 taken 62602 times.
✓ Branch 2 taken 569502 times.
✓ Branch 3 taken 80474 times.
✓ Branch 4 taken 56533 times.
✓ Branch 5 taken 512969 times.
712578 if (is_4x4 || mode_type == MODE_TYPE_INTRA || IS_I(rsh)) {
1073 199609 pred_mode_flag = 1;
1074
4/4
✓ Branch 0 taken 447246 times.
✓ Branch 1 taken 65723 times.
✓ Branch 2 taken 236162 times.
✓ Branch 3 taken 211084 times.
512969 } else if (mode_type == MODE_TYPE_INTER || cu->skip_flag) {
1075 301885 pred_mode_flag = 0;
1076 } else {
1077 211084 pred_mode_flag = ff_vvc_pred_mode_flag(lc, ch_type);
1078 }
1079 712578 pred_mode = pred_mode_flag ? MODE_INTRA : MODE_INTER;
1080
1081
4/4
✓ Branch 0 taken 85795 times.
✓ Branch 1 taken 626783 times.
✓ Branch 2 taken 9881 times.
✓ Branch 3 taken 75914 times.
712578 if (((IS_I(rsh) && !cu->skip_flag) ||
1082
6/6
✓ Branch 0 taken 626783 times.
✓ Branch 1 taken 9881 times.
✓ Branch 2 taken 162772 times.
✓ Branch 3 taken 464011 times.
✓ Branch 4 taken 115908 times.
✓ Branch 5 taken 46864 times.
636664 (!IS_I(rsh) && (pred_mode != MODE_INTRA ||
1083
6/6
✓ Branch 0 taken 66950 times.
✓ Branch 1 taken 48958 times.
✓ Branch 2 taken 104210 times.
✓ Branch 3 taken 9604 times.
✓ Branch 4 taken 615488 times.
✓ Branch 5 taken 28647 times.
702697 ((is_4x4 || mode_type == MODE_TYPE_INTRA) && !cu->skip_flag)))) &&
1084
6/6
✓ Branch 0 taken 549765 times.
✓ Branch 1 taken 65723 times.
✓ Branch 2 taken 183378 times.
✓ Branch 3 taken 366387 times.
✓ Branch 4 taken 157419 times.
✓ Branch 5 taken 25959 times.
615488 !is_128 && mode_type != MODE_TYPE_INTER && sps->r->sps_ibc_enabled_flag &&
1085 tree_type != DUAL_TREE_CHROMA) {
1086 157419 pred_mode_ibc_flag = ff_vvc_pred_mode_ibc_flag(lc, ch_type);
1087
6/6
✓ Branch 0 taken 261662 times.
✓ Branch 1 taken 293497 times.
✓ Branch 2 taken 254551 times.
✓ Branch 3 taken 7111 times.
✓ Branch 4 taken 4237 times.
✓ Branch 5 taken 250314 times.
555159 } else if (cu->skip_flag && (is_4x4 || mode_type == MODE_TYPE_INTRA)) {
1088 11348 pred_mode_ibc_flag = 1;
1089
6/6
✓ Branch 0 taken 515105 times.
✓ Branch 1 taken 28706 times.
✓ Branch 2 taken 449382 times.
✓ Branch 3 taken 65723 times.
✓ Branch 4 taken 34554 times.
✓ Branch 5 taken 414828 times.
543811 } else if (is_128 || mode_type == MODE_TYPE_INTER || tree_type == DUAL_TREE_CHROMA) {
1090 128983 pred_mode_ibc_flag = 0;
1091 } else {
1092
2/2
✓ Branch 0 taken 8137 times.
✓ Branch 1 taken 406691 times.
414828 pred_mode_ibc_flag = (IS_I(rsh)) ? sps->r->sps_ibc_enabled_flag : 0;
1093 }
1094
2/2
✓ Branch 0 taken 67240 times.
✓ Branch 1 taken 645338 times.
712578 if (pred_mode_ibc_flag)
1095 67240 pred_mode = MODE_IBC;
1096 } else {
1097 631570 pred_mode = MODE_INTRA;
1098 }
1099
1100
7/10
✓ Branch 0 taken 816825 times.
✓ Branch 1 taken 527323 times.
✓ Branch 2 taken 28396 times.
✓ Branch 3 taken 788429 times.
✓ Branch 4 taken 28396 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 28396 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 28396 times.
✗ Branch 9 not taken.
1344148 if (pred_mode == MODE_INTRA && sps->r->sps_palette_enabled_flag && !is_128 && !cu->skip_flag &&
1101
2/2
✓ Branch 0 taken 25081 times.
✓ Branch 1 taken 3315 times.
28396 mode_type != MODE_TYPE_INTER && ((cu->cb_width * cu->cb_height) >
1102
4/4
✓ Branch 0 taken 4482 times.
✓ Branch 1 taken 23914 times.
✓ Branch 2 taken 6728 times.
✓ Branch 3 taken 18353 times.
53477 (tree_type != DUAL_TREE_CHROMA ? 16 : (16 << hs << vs))) &&
1103
2/2
✓ Branch 0 taken 2796 times.
✓ Branch 1 taken 3932 times.
6728 (mode_type != MODE_TYPE_INTRA || tree_type != DUAL_TREE_CHROMA)) {
1104
2/2
✓ Branch 1 taken 4497 times.
✓ Branch 2 taken 16652 times.
21149 if (ff_vvc_pred_mode_plt_flag(lc))
1105 4497 pred_mode = MODE_PLT;
1106 }
1107
1108 1344148 set_cb_tab(lc, fc->tab.cpm[cu->ch_type], pred_mode);
1109
2/2
✓ Branch 0 taken 570065 times.
✓ Branch 1 taken 774083 times.
1344148 if (tree_type == SINGLE_TREE)
1110 570065 set_cb_tab(lc, fc->tab.cpm[CHROMA], pred_mode);
1111
1112 1344148 return pred_mode;
1113 }
1114
1115 990255 static void sbt_info(VVCLocalContext *lc, const VVCSPS *sps)
1116 {
1117 990255 CodingUnit *cu = lc->cu;
1118 990255 const int cb_width = cu->cb_width;
1119 990255 const int cb_height = cu->cb_height;
1120
1121
6/6
✓ Branch 0 taken 161063 times.
✓ Branch 1 taken 829192 times.
✓ Branch 2 taken 155335 times.
✓ Branch 3 taken 5728 times.
✓ Branch 4 taken 139432 times.
✓ Branch 5 taken 15903 times.
990255 if (cu->pred_mode == MODE_INTER && sps->r->sps_sbt_enabled_flag && !cu->ciip_flag
1122
4/4
✓ Branch 0 taken 136579 times.
✓ Branch 1 taken 2853 times.
✓ Branch 2 taken 135696 times.
✓ Branch 3 taken 883 times.
139432 && cb_width <= sps->max_tb_size_y && cb_height <= sps->max_tb_size_y) {
1123 135696 const int sbt_ver_h = cb_width >= 8;
1124 135696 const int sbt_hor_h = cb_height >= 8;
1125 135696 cu->sbt_flag = 0;
1126
3/4
✓ Branch 0 taken 20760 times.
✓ Branch 1 taken 114936 times.
✓ Branch 2 taken 20760 times.
✗ Branch 3 not taken.
135696 if (sbt_ver_h || sbt_hor_h)
1127 135696 cu->sbt_flag = ff_vvc_sbt_flag(lc);
1128
2/2
✓ Branch 0 taken 45451 times.
✓ Branch 1 taken 90245 times.
135696 if (cu->sbt_flag) {
1129 45451 const int sbt_ver_q = cb_width >= 16;
1130 45451 const int sbt_hor_q = cb_height >= 16;
1131 45451 int cu_sbt_quad_flag = 0;
1132
1133
7/8
✓ Branch 0 taken 7617 times.
✓ Branch 1 taken 37834 times.
✓ Branch 2 taken 7617 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 25167 times.
✓ Branch 5 taken 20284 times.
✓ Branch 6 taken 12099 times.
✓ Branch 7 taken 13068 times.
45451 if ((sbt_ver_h || sbt_hor_h) && (sbt_ver_q || sbt_hor_q))
1134 32383 cu_sbt_quad_flag = ff_vvc_sbt_quad_flag(lc);
1135
2/2
✓ Branch 0 taken 11769 times.
✓ Branch 1 taken 33682 times.
45451 if (cu_sbt_quad_flag) {
1136 11769 cu->sbt_horizontal_flag = sbt_hor_q;
1137
4/4
✓ Branch 0 taken 7788 times.
✓ Branch 1 taken 3981 times.
✓ Branch 2 taken 3587 times.
✓ Branch 3 taken 4201 times.
11769 if (sbt_ver_q && sbt_hor_q)
1138 3587 cu->sbt_horizontal_flag = ff_vvc_sbt_horizontal_flag(lc);
1139 } else {
1140 33682 cu->sbt_horizontal_flag = sbt_hor_h;
1141
4/4
✓ Branch 0 taken 27600 times.
✓ Branch 1 taken 6082 times.
✓ Branch 2 taken 21948 times.
✓ Branch 3 taken 5652 times.
33682 if (sbt_ver_h && sbt_hor_h)
1142 21948 cu->sbt_horizontal_flag = ff_vvc_sbt_horizontal_flag(lc);
1143 }
1144 45451 cu->sbt_pos_flag = ff_vvc_sbt_pos_flag(lc);
1145
1146 {
1147
2/2
✓ Branch 0 taken 11769 times.
✓ Branch 1 taken 33682 times.
45451 const int sbt_min = cu_sbt_quad_flag ? 1 : 2;
1148
2/2
✓ Branch 0 taken 21748 times.
✓ Branch 1 taken 23703 times.
45451 lc->parse.sbt_num_fourths_tb0 = cu->sbt_pos_flag ? (4 - sbt_min) : sbt_min;
1149 }
1150 }
1151 }
1152 990255 }
1153
1154 349396 static int skipped_transform_tree_unit(VVCLocalContext *lc)
1155 {
1156 349396 const H266RawSPS *rsps = lc->fc->ps.sps->r;
1157 349396 const CodingUnit *cu = lc->cu;
1158 int ret;
1159
1160
1/2
✓ Branch 0 taken 349396 times.
✗ Branch 1 not taken.
349396 if (cu->tree_type != DUAL_TREE_CHROMA)
1161 349396 set_qp_y(lc, cu->x0, cu->y0, 0);
1162
4/4
✓ Branch 0 taken 332885 times.
✓ Branch 1 taken 16511 times.
✓ Branch 2 taken 302344 times.
✓ Branch 3 taken 30541 times.
349396 if (rsps->sps_chroma_format_idc && cu->tree_type != DUAL_TREE_LUMA)
1163 302344 set_qp_c(lc);
1164 349396 ret = skipped_transform_tree(lc, cu->x0, cu->y0, cu->cb_width, cu->cb_height);
1165
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 349396 times.
349396 if (ret < 0)
1166 return ret;
1167 349396 return 0;
1168 }
1169
1170 1344148 static void set_cb_pos(const VVCFrameContext *fc, const CodingUnit *cu)
1171 {
1172 1344148 const VVCSPS *sps = fc->ps.sps;
1173 1344148 const VVCPPS *pps = fc->ps.pps;
1174 1344148 const int log2_min_cb_size = sps->min_cb_log2_size_y;
1175 1344148 const int x_cb = cu->x0 >> log2_min_cb_size;
1176 1344148 const int y_cb = cu->y0 >> log2_min_cb_size;
1177 1344148 const int ch_type = cu->ch_type;
1178 int x, y;
1179
1180 1344148 x = y_cb * pps->min_cb_width + x_cb;
1181
2/2
✓ Branch 0 taken 5581292 times.
✓ Branch 1 taken 1344148 times.
6925440 for (y = 0; y < (cu->cb_height >> log2_min_cb_size); y++) {
1182 5581292 const int width = cu->cb_width >> log2_min_cb_size;
1183
1184
2/2
✓ Branch 0 taken 54125672 times.
✓ Branch 1 taken 5581292 times.
59706964 for (int i = 0; i < width; i++) {
1185 54125672 fc->tab.cb_pos_x[ch_type][x + i] = cu->x0;
1186 54125672 fc->tab.cb_pos_y[ch_type][x + i] = cu->y0;
1187 }
1188 5581292 memset(&fc->tab.cb_width[ch_type][x], cu->cb_width, width);
1189 5581292 memset(&fc->tab.cb_height[ch_type][x], cu->cb_height, width);
1190 5581292 memset(&fc->tab.cqt_depth[ch_type][x], cu->cqt_depth, width);
1191
1192 5581292 x += pps->min_cb_width;
1193 }
1194 1344148 }
1195
1196 1344148 static CodingUnit* alloc_cu(VVCLocalContext *lc, const int x0, const int y0)
1197 {
1198 1344148 VVCFrameContext *fc = lc->fc;
1199 1344148 const VVCSPS *sps = fc->ps.sps;
1200 1344148 const VVCPPS *pps = fc->ps.pps;
1201 1344148 const int rx = x0 >> sps->ctb_log2_size_y;
1202 1344148 const int ry = y0 >> sps->ctb_log2_size_y;
1203 1344148 CodingUnit **cus = fc->tab.cus + ry * pps->ctb_width + rx;
1204 1344148 CodingUnit *cu = av_refstruct_pool_get(fc->cu_pool);
1205
1206
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1344148 times.
1344148 if (!cu)
1207 return NULL;
1208 1344148 cu->next = NULL;
1209
1210
2/2
✓ Branch 0 taken 1290793 times.
✓ Branch 1 taken 53355 times.
1344148 if (lc->cu)
1211 1290793 lc->cu->next = cu;
1212 else
1213 53355 *cus = cu;
1214 1344148 lc->cu = cu;
1215
1216 1344148 return cu;
1217 }
1218
1219 1344148 static CodingUnit* add_cu(VVCLocalContext *lc, const int x0, const int y0,
1220 const int cb_width, const int cb_height, const int cqt_depth, const VVCTreeType tree_type)
1221 {
1222 1344148 VVCFrameContext *fc = lc->fc;
1223 1344148 const int ch_type = tree_type == DUAL_TREE_CHROMA ? 1 : 0;
1224 1344148 CodingUnit *cu = alloc_cu(lc, x0, y0);
1225
1226
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1344148 times.
1344148 if (!cu)
1227 return NULL;
1228
1229 1344148 memset(&cu->pu, 0, sizeof(cu->pu));
1230
1231 1344148 lc->parse.prev_tu_cbf_y = 0;
1232
1233 1344148 cu->sbt_flag = 0;
1234 1344148 cu->act_enabled_flag = 0;
1235
1236 1344148 cu->tree_type = tree_type;
1237 1344148 cu->x0 = x0;
1238 1344148 cu->y0 = y0;
1239 1344148 cu->cb_width = cb_width;
1240 1344148 cu->cb_height = cb_height;
1241 1344148 cu->ch_type = ch_type;
1242 1344148 cu->cqt_depth = cqt_depth;
1243 1344148 cu->tus.head = cu->tus.tail = NULL;
1244 1344148 cu->bdpcm_flag[LUMA] = cu->bdpcm_flag[CB] = cu->bdpcm_flag[CR] = 0;
1245 1344148 cu->isp_split_type = ISP_NO_SPLIT;
1246 1344148 cu->intra_mip_flag = 0;
1247 1344148 cu->ciip_flag = 0;
1248 1344148 cu->coded_flag = 1;
1249 1344148 cu->num_intra_subpartitions = 1;
1250 1344148 cu->pu.dmvr_flag = 0;
1251
1252 1344148 set_cb_pos(fc, cu);
1253 1344148 return cu;
1254 }
1255
1256 1344148 static void set_cu_tabs(const VVCLocalContext *lc, const CodingUnit *cu)
1257 {
1258 1344148 const VVCFrameContext *fc = lc->fc;
1259 1344148 const PredictionUnit *pu = &cu->pu;
1260 1344148 const TransformUnit *tu = cu->tus.head;
1261
1262 1344148 set_cb_tab(lc, fc->tab.mmi, pu->mi.motion_model_idc);
1263 1344148 set_cb_tab(lc, fc->tab.msf, pu->merge_subblock_flag);
1264
2/2
✓ Branch 0 taken 1156840 times.
✓ Branch 1 taken 187308 times.
1344148 if (cu->tree_type != DUAL_TREE_CHROMA) {
1265 1156840 set_cb_tab(lc, fc->tab.skip, cu->skip_flag);
1266 1156840 set_cb_tab(lc, fc->tab.pcmf[LUMA], cu->bdpcm_flag[LUMA]);
1267 }
1268
2/2
✓ Branch 0 taken 757373 times.
✓ Branch 1 taken 586775 times.
1344148 if (cu->tree_type != DUAL_TREE_LUMA)
1269 757373 set_cb_tab(lc, fc->tab.pcmf[CHROMA], cu->bdpcm_flag[CHROMA]);
1270
1271
2/2
✓ Branch 0 taken 1663353 times.
✓ Branch 1 taken 1344148 times.
3007501 while (tu) {
1272
2/2
✓ Branch 0 taken 3260493 times.
✓ Branch 1 taken 1663353 times.
4923846 for (int j = 0; j < tu->nb_tbs; j++) {
1273 3260493 const TransformBlock *tb = tu->tbs + j;
1274
2/2
✓ Branch 0 taken 1785304 times.
✓ Branch 1 taken 1475189 times.
3260493 if (tb->c_idx != LUMA)
1275 1785304 set_qp_c_tab(lc, tu, tb);
1276 }
1277 1663353 tu = tu->next;
1278 }
1279 1344148 }
1280
1281 //8.5.2.7 Derivation process for merge motion vector difference
1282 58025 static void derive_mmvd(const VVCLocalContext *lc, MvField *mvf, const Mv *mmvd_offset)
1283 {
1284 58025 const SliceContext *sc = lc->sc;
1285 Mv mmvd[2];
1286
1287
2/2
✓ Branch 0 taken 24450 times.
✓ Branch 1 taken 33575 times.
58025 if (mvf->pred_flag == PF_BI) {
1288 24450 const RefPicList *rpl = sc->rpl;
1289 24450 const int poc = lc->fc->ps.ph.poc;
1290 24450 const int diff[] = {
1291 24450 poc - rpl[L0].refs[mvf->ref_idx[L0]].poc,
1292 24450 poc - rpl[L1].refs[mvf->ref_idx[L1]].poc
1293 };
1294
4/4
✓ Branch 0 taken 23103 times.
✓ Branch 1 taken 1347 times.
✓ Branch 2 taken 9320 times.
✓ Branch 3 taken 15130 times.
24450 const int sign = FFSIGN(diff[0]) != FFSIGN(diff[1]);
1295
1296
2/2
✓ Branch 0 taken 8287 times.
✓ Branch 1 taken 16163 times.
24450 if (diff[0] == diff[1]) {
1297 8287 mmvd[1] = mmvd[0] = *mmvd_offset;
1298 }
1299 else {
1300 16163 const int i = FFABS(diff[0]) < FFABS(diff[1]);
1301 16163 const int o = !i;
1302 16163 mmvd[i] = *mmvd_offset;
1303
4/4
✓ Branch 0 taken 15919 times.
✓ Branch 1 taken 244 times.
✓ Branch 2 taken 15842 times.
✓ Branch 3 taken 77 times.
16163 if (!rpl[L0].refs[mvf->ref_idx[L0]].is_lt && !rpl[L1].refs[mvf->ref_idx[L1]].is_lt) {
1304 15842 ff_vvc_mv_scale(&mmvd[o], mmvd_offset, diff[i], diff[o]);
1305 }
1306 else {
1307
2/2
✓ Branch 0 taken 199 times.
✓ Branch 1 taken 122 times.
321 mmvd[o].x = sign ? -mmvd[i].x : mmvd[i].x;
1308
2/2
✓ Branch 0 taken 199 times.
✓ Branch 1 taken 122 times.
321 mmvd[o].y = sign ? -mmvd[i].y : mmvd[i].y;
1309 }
1310 }
1311 24450 mvf->mv[0].x += mmvd[0].x;
1312 24450 mvf->mv[0].y += mmvd[0].y;
1313 24450 mvf->mv[1].x += mmvd[1].x;
1314 24450 mvf->mv[1].y += mmvd[1].y;
1315 } else {
1316 33575 const int idx = mvf->pred_flag - PF_L0;
1317 33575 mvf->mv[idx].x += mmvd_offset->x;
1318 33575 mvf->mv[idx].y += mmvd_offset->y;
1319 }
1320
1321 58025 }
1322
1323 297332 static void mvf_to_mi(const MvField *mvf, MotionInfo *mi)
1324 {
1325 297332 mi->pred_flag = mvf->pred_flag;
1326 297332 mi->bcw_idx = mvf->bcw_idx;
1327 297332 mi->hpel_if_idx = mvf->hpel_if_idx;
1328
2/2
✓ Branch 0 taken 594664 times.
✓ Branch 1 taken 297332 times.
891996 for (int i = 0; i < 2; i++) {
1329 594664 const PredFlag mask = i + 1;
1330
2/2
✓ Branch 0 taken 464155 times.
✓ Branch 1 taken 130509 times.
594664 if (mvf->pred_flag & mask) {
1331 464155 mi->mv[i][0] = mvf->mv[i];
1332 464155 mi->ref_idx[i] = mvf->ref_idx[i];
1333 }
1334 }
1335 297332 }
1336
1337 297332 static void mv_merge_refine_pred_flag(MvField *mvf, const int width, const int height)
1338 {
1339
4/4
✓ Branch 0 taken 172076 times.
✓ Branch 1 taken 125256 times.
✓ Branch 2 taken 5253 times.
✓ Branch 3 taken 166823 times.
297332 if (mvf->pred_flag == PF_BI && (width + height) == 12) {
1340 5253 mvf->pred_flag = PF_L0;
1341 5253 mvf->bcw_idx = 0;
1342 }
1343 297332 }
1344
1345 // subblock-based inter prediction data
1346 54562 static void merge_data_subblock(VVCLocalContext *lc)
1347 {
1348 54562 const VVCFrameContext *fc = lc->fc;
1349 54562 const VVCPH *ph = &fc->ps.ph;
1350 54562 CodingUnit* cu = lc->cu;
1351 54562 PredictionUnit *pu = &cu->pu;
1352 54562 int merge_subblock_idx = 0;
1353
1354
1/2
✓ Branch 0 taken 54562 times.
✗ Branch 1 not taken.
54562 if (ph->max_num_subblock_merge_cand > 1) {
1355 54562 merge_subblock_idx = ff_vvc_merge_subblock_idx(lc, ph->max_num_subblock_merge_cand);
1356 }
1357 54562 ff_vvc_sb_mv_merge_mode(lc, merge_subblock_idx, pu);
1358 54562 }
1359
1360 281005 static void merge_data_regular(VVCLocalContext *lc)
1361 {
1362 281005 const VVCFrameContext *fc = lc->fc;
1363 281005 const VVCSPS *sps = fc->ps.sps;
1364 281005 const VVCPH *ph = &fc->ps.ph;
1365 281005 const CodingUnit* cu = lc->cu;
1366 281005 PredictionUnit *pu = &lc->cu->pu;
1367 281005 int merge_idx = 0;
1368 Mv mmvd_offset;
1369 MvField mvf;
1370
1371
2/2
✓ Branch 0 taken 275841 times.
✓ Branch 1 taken 5164 times.
281005 if (sps->r->sps_mmvd_enabled_flag)
1372 275841 pu->mmvd_merge_flag = ff_vvc_mmvd_merge_flag(lc);
1373
2/2
✓ Branch 0 taken 58025 times.
✓ Branch 1 taken 222980 times.
281005 if (pu->mmvd_merge_flag) {
1374 58025 int mmvd_cand_flag = 0;
1375
1/2
✓ Branch 0 taken 58025 times.
✗ Branch 1 not taken.
58025 if (sps->max_num_merge_cand > 1)
1376 58025 mmvd_cand_flag = ff_vvc_mmvd_cand_flag(lc);
1377 58025 ff_vvc_mmvd_offset_coding(lc, &mmvd_offset, ph->r->ph_mmvd_fullpel_only_flag);
1378 58025 merge_idx = mmvd_cand_flag;
1379
1/2
✓ Branch 0 taken 222980 times.
✗ Branch 1 not taken.
222980 } else if (sps->max_num_merge_cand > 1) {
1380 222980 merge_idx = ff_vvc_merge_idx(lc);
1381 }
1382 281005 ff_vvc_luma_mv_merge_mode(lc, merge_idx, 0, &mvf);
1383
2/2
✓ Branch 0 taken 58025 times.
✓ Branch 1 taken 222980 times.
281005 if (pu->mmvd_merge_flag)
1384 58025 derive_mmvd(lc, &mvf, &mmvd_offset);
1385 281005 mv_merge_refine_pred_flag(&mvf, cu->cb_width, cu->cb_height);
1386 281005 ff_vvc_store_mvf(lc, &mvf);
1387 281005 mvf_to_mi(&mvf, &pu->mi);
1388 281005 }
1389
1390 43918 static int ciip_flag_decode(VVCLocalContext *lc, const int ciip_avaiable, const int gpm_avaiable, const int is_128)
1391 {
1392 43918 const VVCFrameContext *fc = lc->fc;
1393 43918 const VVCSPS *sps = fc->ps.sps;
1394 43918 const CodingUnit *cu = lc->cu;
1395
1396
4/4
✓ Branch 0 taken 27094 times.
✓ Branch 1 taken 16824 times.
✓ Branch 2 taken 20147 times.
✓ Branch 3 taken 6947 times.
43918 if (ciip_avaiable && gpm_avaiable)
1397 20147 return ff_vvc_ciip_flag(lc);
1398
3/4
✓ Branch 0 taken 6947 times.
✓ Branch 1 taken 16824 times.
✓ Branch 2 taken 6947 times.
✗ Branch 3 not taken.
23771 return sps->r->sps_ciip_enabled_flag && !cu->skip_flag &&
1399
2/4
✓ Branch 0 taken 23771 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6947 times.
✗ Branch 3 not taken.
47542 !is_128 && (cu->cb_width * cu->cb_height >= 64);
1400 }
1401
1402 27591 static void merge_data_gpm(VVCLocalContext *lc)
1403 {
1404 27591 const VVCFrameContext *fc = lc->fc;
1405 27591 const VVCSPS *sps = fc->ps.sps;
1406 27591 PredictionUnit *pu = &lc->cu->pu;
1407 int merge_gpm_idx[2];
1408
1409 27591 pu->merge_gpm_flag = 1;
1410 27591 pu->gpm_partition_idx = ff_vvc_merge_gpm_partition_idx(lc);
1411 27591 merge_gpm_idx[0] = ff_vvc_merge_gpm_idx(lc, 0);
1412 27591 merge_gpm_idx[1] = 0;
1413
1/2
✓ Branch 0 taken 27591 times.
✗ Branch 1 not taken.
27591 if (sps->max_num_gpm_merge_cand > 2)
1414 27591 merge_gpm_idx[1] = ff_vvc_merge_gpm_idx(lc, 1);
1415
1416 27591 ff_vvc_luma_mv_merge_gpm(lc, merge_gpm_idx, pu->gpm_mv);
1417 27591 ff_vvc_store_gpm_mvf(lc, pu);
1418 27591 }
1419
1420 16327 static void merge_data_ciip(VVCLocalContext *lc)
1421 {
1422 16327 const VVCFrameContext* fc = lc->fc;
1423 16327 const VVCSPS* sps = fc->ps.sps;
1424 16327 CodingUnit *cu = lc->cu;
1425 16327 MotionInfo *mi = &cu->pu.mi;
1426 16327 int merge_idx = 0;
1427 MvField mvf;
1428
1429
1/2
✓ Branch 0 taken 16327 times.
✗ Branch 1 not taken.
16327 if (sps->max_num_merge_cand > 1)
1430 16327 merge_idx = ff_vvc_merge_idx(lc);
1431 16327 ff_vvc_luma_mv_merge_mode(lc, merge_idx, 1, &mvf);
1432 16327 mv_merge_refine_pred_flag(&mvf, cu->cb_width, cu->cb_height);
1433 16327 ff_vvc_store_mvf(lc, &mvf);
1434 16327 mvf_to_mi(&mvf, mi);
1435 16327 cu->intra_pred_mode_y = cu->intra_pred_mode_c = INTRA_PLANAR;
1436 16327 cu->intra_luma_ref_idx = 0;
1437 16327 cu->intra_mip_flag = 0;
1438 16327 }
1439
1440 // block-based inter prediction data
1441 324923 static void merge_data_block(VVCLocalContext *lc)
1442 {
1443 324923 const VVCFrameContext* fc = lc->fc;
1444 324923 const VVCSPS *sps = fc->ps.sps;
1445 324923 const H266RawSliceHeader *rsh = lc->sc->sh.r;
1446 324923 CodingUnit *cu = lc->cu;
1447 324923 const int cb_width = cu->cb_width;
1448 324923 const int cb_height = cu->cb_height;
1449
4/4
✓ Branch 0 taken 304590 times.
✓ Branch 1 taken 20333 times.
✓ Branch 2 taken 1376 times.
✓ Branch 3 taken 303214 times.
324923 const int is_128 = cb_width == 128 || cb_height == 128;
1450 969605 const int ciip_avaiable = sps->r->sps_ciip_enabled_flag &&
1451
6/6
✓ Branch 0 taken 319759 times.
✓ Branch 1 taken 5164 times.
✓ Branch 2 taken 103731 times.
✓ Branch 3 taken 216028 times.
✓ Branch 4 taken 92603 times.
✓ Branch 5 taken 11128 times.
324923 !cu->skip_flag && (cb_width * cb_height >= 64);
1452
4/4
✓ Branch 0 taken 304585 times.
✓ Branch 1 taken 906 times.
✓ Branch 2 taken 268330 times.
✓ Branch 3 taken 36255 times.
305491 const int gpm_avaiable = sps->r->sps_gpm_enabled_flag && IS_B(rsh) &&
1453
2/2
✓ Branch 0 taken 238831 times.
✓ Branch 1 taken 29499 times.
268330 (cb_width >= 8) && (cb_height >=8) &&
1454
6/6
✓ Branch 0 taken 305491 times.
✓ Branch 1 taken 19432 times.
✓ Branch 2 taken 231800 times.
✓ Branch 3 taken 7031 times.
✓ Branch 4 taken 229814 times.
✓ Branch 5 taken 1986 times.
630414 (cb_width < 8 * cb_height) && (cb_height < 8 *cb_width);
1455
1456 324923 int regular_merge_flag = 1;
1457
1458
6/6
✓ Branch 0 taken 303214 times.
✓ Branch 1 taken 21709 times.
✓ Branch 2 taken 210992 times.
✓ Branch 3 taken 92222 times.
✓ Branch 4 taken 143870 times.
✓ Branch 5 taken 67122 times.
324923 if (!is_128 && (ciip_avaiable || gpm_avaiable))
1459 236092 regular_merge_flag = ff_vvc_regular_merge_flag(lc, cu->skip_flag);
1460
2/2
✓ Branch 0 taken 281005 times.
✓ Branch 1 taken 43918 times.
324923 if (regular_merge_flag) {
1461 281005 merge_data_regular(lc);
1462 } else {
1463 43918 cu->ciip_flag = ciip_flag_decode(lc, ciip_avaiable, gpm_avaiable, is_128);
1464
2/2
✓ Branch 0 taken 16327 times.
✓ Branch 1 taken 27591 times.
43918 if (cu->ciip_flag)
1465 16327 merge_data_ciip(lc);
1466 else
1467 27591 merge_data_gpm(lc);
1468 }
1469 324923 }
1470
1471 28190 static int merge_data_ibc(VVCLocalContext *lc)
1472 {
1473 28190 const VVCFrameContext* fc = lc->fc;
1474 28190 const VVCSPS* sps = fc->ps.sps;
1475 28190 MotionInfo *mi = &lc->cu->pu.mi;
1476 28190 int merge_idx = 0;
1477 int ret;
1478
1479 28190 mi->pred_flag = PF_IBC;
1480
1481
2/2
✓ Branch 0 taken 27950 times.
✓ Branch 1 taken 240 times.
28190 if (sps->max_num_ibc_merge_cand > 1)
1482 27950 merge_idx = ff_vvc_merge_idx(lc);
1483
1484 28190 ret = ff_vvc_luma_mv_merge_ibc(lc, merge_idx, &mi->mv[L0][0]);
1485
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28190 times.
28190 if (ret)
1486 return ret;
1487 28190 ff_vvc_store_mv(lc, mi);
1488
1489 28190 return 0;
1490 }
1491
1492 407675 static int hls_merge_data(VVCLocalContext *lc)
1493 {
1494 407675 const VVCFrameContext *fc = lc->fc;
1495 407675 const VVCPH *ph = &fc->ps.ph;
1496 407675 const CodingUnit *cu = lc->cu;
1497 407675 PredictionUnit *pu = &lc->cu->pu;
1498 int ret;
1499
1500 407675 pu->merge_gpm_flag = 0;
1501 407675 pu->mi.num_sb_x = pu->mi.num_sb_y = 1;
1502
2/2
✓ Branch 0 taken 28190 times.
✓ Branch 1 taken 379485 times.
407675 if (cu->pred_mode == MODE_IBC) {
1503 28190 ret = merge_data_ibc(lc);
1504
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28190 times.
28190 if (ret)
1505 return ret;
1506 } else {
1507
5/6
✓ Branch 0 taken 379485 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 341367 times.
✓ Branch 3 taken 38118 times.
✓ Branch 4 taken 309907 times.
✓ Branch 5 taken 31460 times.
379485 if (ph->max_num_subblock_merge_cand > 0 && cu->cb_width >= 8 && cu->cb_height >= 8)
1508 309907 pu->merge_subblock_flag = ff_vvc_merge_subblock_flag(lc);
1509
2/2
✓ Branch 0 taken 54562 times.
✓ Branch 1 taken 324923 times.
379485 if (pu->merge_subblock_flag)
1510 54562 merge_data_subblock(lc);
1511 else
1512 324923 merge_data_block(lc);
1513 }
1514 407675 return 0;
1515 }
1516
1517 146567 static void hls_mvd_coding(VVCLocalContext *lc, Mv* mvd)
1518 {
1519 int32_t mv[2];
1520
1521
2/2
✓ Branch 0 taken 293134 times.
✓ Branch 1 taken 146567 times.
439701 for (int i = 0; i < 2; i++) {
1522 293134 mv[i] = ff_vvc_abs_mvd_greater0_flag(lc);
1523 }
1524
1525
2/2
✓ Branch 0 taken 293134 times.
✓ Branch 1 taken 146567 times.
439701 for (int i = 0; i < 2; i++) {
1526
2/2
✓ Branch 0 taken 191303 times.
✓ Branch 1 taken 101831 times.
293134 if (mv[i])
1527 191303 mv[i] += ff_vvc_abs_mvd_greater1_flag(lc);
1528 }
1529
1530
2/2
✓ Branch 0 taken 293134 times.
✓ Branch 1 taken 146567 times.
439701 for (int i = 0; i < 2; i++) {
1531
2/2
✓ Branch 0 taken 191303 times.
✓ Branch 1 taken 101831 times.
293134 if (mv[i] > 0) {
1532
2/2
✓ Branch 0 taken 134309 times.
✓ Branch 1 taken 56994 times.
191303 if (mv[i] == 2)
1533 134309 mv[i] += ff_vvc_abs_mvd_minus2(lc);
1534 191303 mv[i] = (1 - 2 * ff_vvc_mvd_sign_flag(lc)) * mv[i];
1535 }
1536 }
1537 146567 mvd->x = mv[0];
1538 146567 mvd->y = mv[1];
1539 146567 }
1540
1541 80598 static int bcw_idx_decode(VVCLocalContext *lc, const MotionInfo *mi, const int cb_width, const int cb_height)
1542 {
1543 80598 const VVCFrameContext *fc = lc->fc;
1544 80598 const VVCSPS *sps = fc->ps.sps;
1545 80598 const VVCPPS *pps = fc->ps.pps;
1546 80598 const VVCPH *ph = &fc->ps.ph;
1547 80598 const VVCSH *sh = &lc->sc->sh;
1548
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 80598 times.
80598 const PredWeightTable *w = pps->r->pps_wp_info_in_ph_flag ? &ph->pwt : &sh->pwt;
1549 80598 int bcw_idx = 0;
1550
1551
4/4
✓ Branch 0 taken 76867 times.
✓ Branch 1 taken 3731 times.
✓ Branch 2 taken 20931 times.
✓ Branch 3 taken 55936 times.
80598 if (sps->r->sps_bcw_enabled_flag && mi->pred_flag == PF_BI &&
1552
2/2
✓ Branch 0 taken 19579 times.
✓ Branch 1 taken 1352 times.
20931 !w->weight_flag[L0][LUMA][mi->ref_idx[0]] &&
1553
2/2
✓ Branch 0 taken 18933 times.
✓ Branch 1 taken 646 times.
19579 !w->weight_flag[L1][LUMA][mi->ref_idx[1]] &&
1554
2/2
✓ Branch 0 taken 18509 times.
✓ Branch 1 taken 424 times.
18933 !w->weight_flag[L0][CHROMA][mi->ref_idx[0]] &&
1555
2/2
✓ Branch 0 taken 18347 times.
✓ Branch 1 taken 162 times.
18509 !w->weight_flag[L1][CHROMA][mi->ref_idx[1]] &&
1556
2/2
✓ Branch 0 taken 12145 times.
✓ Branch 1 taken 6202 times.
18347 cb_width * cb_height >= 256) {
1557 12145 bcw_idx = ff_vvc_bcw_idx(lc, ff_vvc_no_backward_pred_flag(lc));
1558 }
1559 80598 return bcw_idx;
1560 }
1561
1562 102365 static int8_t ref_idx_decode(VVCLocalContext *lc, const VVCSH *sh, const int sym_mvd_flag, const int lx)
1563 {
1564 102365 const H266RawSliceHeader *rsh = sh->r;
1565 102365 int ref_idx = 0;
1566
1567
4/4
✓ Branch 0 taken 84702 times.
✓ Branch 1 taken 17663 times.
✓ Branch 2 taken 71726 times.
✓ Branch 3 taken 12976 times.
102365 if (rsh->num_ref_idx_active[lx] > 1 && !sym_mvd_flag)
1568 71726 ref_idx = ff_vvc_ref_idx_lx(lc, rsh->num_ref_idx_active[lx]);
1569
2/2
✓ Branch 0 taken 12976 times.
✓ Branch 1 taken 17663 times.
30639 else if (sym_mvd_flag)
1570 12976 ref_idx = sh->ref_idx_sym[lx];
1571 102365 return ref_idx;
1572 }
1573
1574 102365 static int mvds_decode(VVCLocalContext *lc, Mv mvds[2][MAX_CONTROL_POINTS],
1575 const int num_cp_mv, const int lx)
1576 {
1577 102365 const VVCFrameContext *fc = lc->fc;
1578 102365 const VVCPH *ph = &fc->ps.ph;
1579 102365 const PredictionUnit *pu = &lc->cu->pu;
1580 102365 const MotionInfo *mi = &pu->mi;
1581 102365 int has_no_zero_mvd = 0;
1582
1583
6/6
✓ Branch 0 taken 35422 times.
✓ Branch 1 taken 66943 times.
✓ Branch 2 taken 5040 times.
✓ Branch 3 taken 30382 times.
✓ Branch 4 taken 5026 times.
✓ Branch 5 taken 14 times.
102365 if (lx == L1 && ph->r->ph_mvd_l1_zero_flag && mi->pred_flag == PF_BI) {
1584
2/2
✓ Branch 0 taken 6400 times.
✓ Branch 1 taken 5026 times.
11426 for (int j = 0; j < num_cp_mv; j++)
1585 6400 AV_ZERO64(&mvds[lx][j]);
1586 } else {
1587 97339 Mv *mvd0 = &mvds[lx][0];
1588
4/4
✓ Branch 0 taken 30396 times.
✓ Branch 1 taken 66943 times.
✓ Branch 2 taken 6488 times.
✓ Branch 3 taken 23908 times.
97339 if (lx == L1 && pu->sym_mvd_flag) {
1589 6488 mvd0->x = -mvds[L0][0].x;
1590 6488 mvd0->y = -mvds[L0][0].y;
1591 } else {
1592 90851 hls_mvd_coding(lc, mvd0);
1593 }
1594
4/4
✓ Branch 0 taken 24121 times.
✓ Branch 1 taken 73218 times.
✓ Branch 2 taken 15176 times.
✓ Branch 3 taken 8945 times.
97339 has_no_zero_mvd |= (mvd0->x || mvd0->y);
1595
2/2
✓ Branch 0 taken 16666 times.
✓ Branch 1 taken 97339 times.
114005 for (int j = 1; j < num_cp_mv; j++) {
1596 16666 Mv *mvd = &mvds[lx][j];
1597 16666 hls_mvd_coding(lc, mvd);
1598 16666 mvd->x += mvd0->x;
1599 16666 mvd->y += mvd0->y;
1600
4/4
✓ Branch 0 taken 3077 times.
✓ Branch 1 taken 13589 times.
✓ Branch 2 taken 2044 times.
✓ Branch 3 taken 1033 times.
16666 has_no_zero_mvd |= (mvd->x || mvd->y);
1601 }
1602 }
1603 102365 return has_no_zero_mvd;
1604 }
1605
1606 80598 static void mvp_add_difference(MotionInfo *mi, const int num_cp_mv,
1607 const Mv mvds[2][MAX_CONTROL_POINTS], const int amvr_shift)
1608 {
1609
2/2
✓ Branch 0 taken 161196 times.
✓ Branch 1 taken 80598 times.
241794 for (int i = 0; i < 2; i++) {
1610 161196 const PredFlag mask = i + PF_L0;
1611
2/2
✓ Branch 0 taken 102365 times.
✓ Branch 1 taken 58831 times.
161196 if (mi->pred_flag & mask) {
1612
2/2
✓ Branch 0 taken 120405 times.
✓ Branch 1 taken 102365 times.
222770 for (int j = 0; j < num_cp_mv; j++) {
1613 120405 const Mv *mvd = &mvds[i][j];
1614 120405 mi->mv[i][j].x += mvd->x * (1 << amvr_shift);
1615 120405 mi->mv[i][j].y += mvd->y * (1 << amvr_shift);
1616 }
1617 }
1618 }
1619 80598 }
1620
1621 39050 static int mvp_data_ibc(VVCLocalContext *lc)
1622 {
1623 39050 const VVCFrameContext *fc = lc->fc;
1624 39050 const CodingUnit *cu = lc->cu;
1625 39050 const PredictionUnit *pu = &lc->cu->pu;
1626 39050 const VVCSPS *sps = fc->ps.sps;
1627 39050 MotionInfo *mi = &lc->cu->pu.mi;
1628 39050 int mvp_l0_flag = 0;
1629 39050 int amvr_shift = 4;
1630 39050 Mv *mv = &mi->mv[L0][0];
1631 int ret;
1632
1633 39050 mi->pred_flag = PF_IBC;
1634 39050 mi->num_sb_x = 1;
1635 39050 mi->num_sb_y = 1;
1636
1637 39050 hls_mvd_coding(lc, mv);
1638
2/2
✓ Branch 0 taken 37708 times.
✓ Branch 1 taken 1342 times.
39050 if (sps->max_num_ibc_merge_cand > 1)
1639 37708 mvp_l0_flag = ff_vvc_mvp_lx_flag(lc);
1640
5/6
✓ Branch 0 taken 39050 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19377 times.
✓ Branch 3 taken 19673 times.
✓ Branch 4 taken 4502 times.
✓ Branch 5 taken 14875 times.
39050 if (sps->r->sps_amvr_enabled_flag && (mv->x || mv->y))
1641 24175 amvr_shift = ff_vvc_amvr_shift(lc, pu->inter_affine_flag, cu->pred_mode, 1);
1642
1643 39050 ret = ff_vvc_mvp_ibc(lc, mvp_l0_flag, amvr_shift, mv);
1644
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 39050 times.
39050 if (ret)
1645 return ret;
1646 39050 ff_vvc_store_mv(lc, mi);
1647
1648 39050 return 0;
1649 }
1650
1651 80598 static int mvp_data(VVCLocalContext *lc)
1652 {
1653 80598 const VVCFrameContext *fc = lc->fc;
1654 80598 const CodingUnit *cu = lc->cu;
1655 80598 PredictionUnit *pu = &lc->cu->pu;
1656 80598 const VVCSPS *sps = fc->ps.sps;
1657 80598 const VVCPH *ph = &fc->ps.ph;
1658 80598 const VVCSH *sh = &lc->sc->sh;
1659 80598 const H266RawSliceHeader *rsh = sh->r;
1660 80598 MotionInfo *mi = &pu->mi;
1661 80598 const int cb_width = cu->cb_width;
1662 80598 const int cb_height = cu->cb_height;
1663
1664 80598 int mvp_lx_flag[2] = {0};
1665 80598 int cu_affine_type_flag = 0;
1666 int num_cp_mv;
1667 80598 int amvr_enabled, has_no_zero_mvd = 0, amvr_shift;
1668 Mv mvds[2][MAX_CONTROL_POINTS];
1669
1670 80598 mi->pred_flag = ff_vvc_pred_flag(lc, IS_B(rsh));
1671
5/6
✓ Branch 0 taken 80598 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 43807 times.
✓ Branch 3 taken 36791 times.
✓ Branch 4 taken 30245 times.
✓ Branch 5 taken 13562 times.
80598 if (sps->r->sps_affine_enabled_flag && cb_width >= 16 && cb_height >= 16) {
1672 30245 pu->inter_affine_flag = ff_vvc_inter_affine_flag(lc);
1673 30245 set_cb_tab(lc, fc->tab.iaf, pu->inter_affine_flag);
1674
4/4
✓ Branch 0 taken 27899 times.
✓ Branch 1 taken 2346 times.
✓ Branch 2 taken 9326 times.
✓ Branch 3 taken 18573 times.
30245 if (sps->r->sps_6param_affine_enabled_flag && pu->inter_affine_flag)
1675 9326 cu_affine_type_flag = ff_vvc_cu_affine_type_flag(lc);
1676 }
1677 80598 mi->motion_model_idc = pu->inter_affine_flag + cu_affine_type_flag;
1678 80598 num_cp_mv = mi->motion_model_idc + 1;
1679
1680
4/4
✓ Branch 0 taken 68629 times.
✓ Branch 1 taken 11969 times.
✓ Branch 2 taken 57475 times.
✓ Branch 3 taken 11154 times.
80598 if (sps->r->sps_smvd_enabled_flag && !ph->r->ph_mvd_l1_zero_flag &&
1681
4/4
✓ Branch 0 taken 16145 times.
✓ Branch 1 taken 41330 times.
✓ Branch 2 taken 14748 times.
✓ Branch 3 taken 1397 times.
57475 mi->pred_flag == PF_BI && !pu->inter_affine_flag &&
1682
4/4
✓ Branch 0 taken 13650 times.
✓ Branch 1 taken 1098 times.
✓ Branch 2 taken 12919 times.
✓ Branch 3 taken 731 times.
14748 sh->ref_idx_sym[0] > -1 && sh->ref_idx_sym[1] > -1)
1683 12919 pu->sym_mvd_flag = ff_vvc_sym_mvd_flag(lc);
1684
1685
2/2
✓ Branch 0 taken 161196 times.
✓ Branch 1 taken 80598 times.
241794 for (int i = L0; i <= L1; i++) {
1686
2/2
✓ Branch 0 taken 80598 times.
✓ Branch 1 taken 80598 times.
161196 const PredFlag pred_flag = PF_L0 + !i;
1687
2/2
✓ Branch 0 taken 102365 times.
✓ Branch 1 taken 58831 times.
161196 if (mi->pred_flag != pred_flag) {
1688 102365 mi->ref_idx[i] = ref_idx_decode(lc, sh, pu->sym_mvd_flag, i);
1689 102365 has_no_zero_mvd |= mvds_decode(lc, mvds, num_cp_mv, i);
1690 102365 mvp_lx_flag[i] = ff_vvc_mvp_lx_flag(lc);
1691 }
1692 }
1693
1694 161196 amvr_enabled = mi->motion_model_idc == MOTION_TRANSLATION ?
1695
2/2
✓ Branch 0 taken 70428 times.
✓ Branch 1 taken 10170 times.
80598 sps->r->sps_amvr_enabled_flag : sps->r->sps_affine_amvr_enabled_flag;
1696 80598 amvr_enabled &= has_no_zero_mvd;
1697
1698 80598 amvr_shift = ff_vvc_amvr_shift(lc, pu->inter_affine_flag, cu->pred_mode, amvr_enabled);
1699
1700 80598 mi->hpel_if_idx = amvr_shift == 3;
1701 80598 mi->bcw_idx = bcw_idx_decode(lc, mi, cb_width, cb_height);
1702
1703
2/2
✓ Branch 0 taken 10170 times.
✓ Branch 1 taken 70428 times.
80598 if (mi->motion_model_idc)
1704 10170 ff_vvc_affine_mvp(lc, mvp_lx_flag, amvr_shift, mi);
1705 else
1706 70428 ff_vvc_mvp(lc, mvp_lx_flag, amvr_shift, mi);
1707
1708 80598 mvp_add_difference(mi, num_cp_mv, mvds, amvr_shift);
1709
1710
2/2
✓ Branch 0 taken 10170 times.
✓ Branch 1 taken 70428 times.
80598 if (mi->motion_model_idc)
1711 10170 ff_vvc_store_sb_mvs(lc, pu);
1712 else
1713 70428 ff_vvc_store_mv(lc, &pu->mi);
1714
1715 80598 return 0;
1716 }
1717
1718 // derive bdofFlag from 8.5.6 Decoding process for inter blocks
1719 // derive dmvr from 8.5.1 General decoding process for coding units coded in inter prediction mode
1720 367760 static void derive_dmvr_bdof_flag(const VVCLocalContext *lc, PredictionUnit *pu)
1721 {
1722 367760 const VVCFrameContext *fc = lc->fc;
1723 367760 const VVCPPS *pps = fc->ps.pps;
1724 367760 const VVCPH *ph = &fc->ps.ph;
1725 367760 const VVCSH *sh = &lc->sc->sh;
1726 367760 const int poc = ph->poc;
1727 367760 const MotionInfo *mi = &pu->mi;
1728 367760 const int8_t *ref_idx = mi->ref_idx;
1729 367760 const VVCRefPic *rp0 = &lc->sc->rpl[L0].refs[ref_idx[L0]];
1730 367760 const VVCRefPic *rp1 = &lc->sc->rpl[L1].refs[ref_idx[L1]];
1731 367760 const CodingUnit *cu = lc->cu;
1732
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 367760 times.
367760 const PredWeightTable *w = pps->r->pps_wp_info_in_ph_flag ? &fc->ps.ph.pwt : &sh->pwt;
1733
1734 367760 pu->bdof_flag = 0;
1735
1736
2/2
✓ Branch 0 taken 186234 times.
✓ Branch 1 taken 181526 times.
367760 if (mi->pred_flag == PF_BI &&
1737
2/2
✓ Branch 0 taken 124734 times.
✓ Branch 1 taken 61500 times.
186234 (poc - rp0->poc == rp1->poc - poc) &&
1738
4/4
✓ Branch 0 taken 124676 times.
✓ Branch 1 taken 58 times.
✓ Branch 2 taken 124643 times.
✓ Branch 3 taken 33 times.
124734 !rp0->is_lt && !rp1->is_lt &&
1739
2/2
✓ Branch 0 taken 121811 times.
✓ Branch 1 taken 2832 times.
124643 !cu->ciip_flag &&
1740
2/2
✓ Branch 0 taken 107304 times.
✓ Branch 1 taken 14507 times.
121811 !mi->bcw_idx &&
1741
4/4
✓ Branch 0 taken 106190 times.
✓ Branch 1 taken 1114 times.
✓ Branch 2 taken 106189 times.
✓ Branch 3 taken 1 times.
107304 !w->weight_flag[L0][LUMA][ref_idx[L0]] && !w->weight_flag[L1][LUMA][ref_idx[L1]] &&
1742
4/4
✓ Branch 0 taken 106171 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 106156 times.
✓ Branch 3 taken 15 times.
106189 !w->weight_flag[L0][CHROMA][ref_idx[L0]] && !w->weight_flag[L1][CHROMA][ref_idx[L1]] &&
1743
4/4
✓ Branch 0 taken 100231 times.
✓ Branch 1 taken 5925 times.
✓ Branch 2 taken 96302 times.
✓ Branch 3 taken 3929 times.
106156 cu->cb_width >= 8 && cu->cb_height >= 8 &&
1744
2/2
✓ Branch 0 taken 90337 times.
✓ Branch 1 taken 5965 times.
96302 (cu->cb_width * cu->cb_height >= 128) &&
1745
2/4
✓ Branch 0 taken 90337 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 90337 times.
✗ Branch 3 not taken.
90337 !rp0->is_scaled && !rp1->is_scaled) {
1746
2/2
✓ Branch 0 taken 88308 times.
✓ Branch 1 taken 2029 times.
90337 if (!ph->r->ph_bdof_disabled_flag &&
1747
1/2
✓ Branch 0 taken 88308 times.
✗ Branch 1 not taken.
88308 mi->motion_model_idc == MOTION_TRANSLATION &&
1748
1/2
✓ Branch 0 taken 88308 times.
✗ Branch 1 not taken.
88308 !pu->merge_subblock_flag &&
1749
2/2
✓ Branch 0 taken 85363 times.
✓ Branch 1 taken 2945 times.
88308 !pu->sym_mvd_flag)
1750 85363 pu->bdof_flag = 1;
1751
2/2
✓ Branch 0 taken 85851 times.
✓ Branch 1 taken 4486 times.
90337 if (!ph->r->ph_dmvr_disabled_flag &&
1752
2/2
✓ Branch 0 taken 80285 times.
✓ Branch 1 taken 5566 times.
85851 pu->general_merge_flag &&
1753
2/2
✓ Branch 0 taken 73090 times.
✓ Branch 1 taken 7195 times.
80285 !pu->mmvd_merge_flag)
1754 73090 pu->dmvr_flag = 1;
1755 }
1756 367760 }
1757
1758 // part of 8.5.1 General decoding process for coding units coded in inter prediction mode
1759 367760 static void refine_regular_subblock(const VVCLocalContext *lc)
1760 {
1761 367760 const CodingUnit *cu = lc->cu;
1762 367760 PredictionUnit *pu = &lc->cu->pu;
1763
1764 367760 derive_dmvr_bdof_flag(lc, pu);
1765
4/4
✓ Branch 0 taken 294670 times.
✓ Branch 1 taken 73090 times.
✓ Branch 2 taken 12273 times.
✓ Branch 3 taken 282397 times.
367760 if (pu->dmvr_flag || pu->bdof_flag) {
1766
2/2
✓ Branch 0 taken 51729 times.
✓ Branch 1 taken 33634 times.
85363 pu->mi.num_sb_x = (cu->cb_width > 16) ? (cu->cb_width >> 4) : 1;
1767
2/2
✓ Branch 0 taken 48774 times.
✓ Branch 1 taken 36589 times.
85363 pu->mi.num_sb_y = (cu->cb_height > 16) ? (cu->cb_height >> 4) : 1;
1768 }
1769 367760 }
1770
1771 454233 static void fill_dmvr_info(const VVCLocalContext *lc)
1772 {
1773 454233 const VVCFrameContext *fc = lc->fc;
1774 454233 const CodingUnit *cu = lc->cu;
1775
1776
3/4
✓ Branch 0 taken 386993 times.
✓ Branch 1 taken 67240 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 386993 times.
454233 if (cu->pred_mode == MODE_IBC || cu->pred_mode == MODE_PLT) {
1777
1/2
✓ Branch 0 taken 67240 times.
✗ Branch 1 not taken.
67240 ff_vvc_set_intra_mvf(lc, true, cu->pred_mode == MODE_IBC ? PF_IBC : PF_PLT, false);
1778 } else {
1779 386993 const VVCPPS *pps = fc->ps.pps;
1780 386993 const int w = cu->cb_width >> MIN_PU_LOG2;
1781
1782
2/2
✓ Branch 0 taken 2216796 times.
✓ Branch 1 taken 386993 times.
2603789 for (int y = cu->y0 >> MIN_PU_LOG2; y < (cu->y0 + cu->cb_height) >> MIN_PU_LOG2; y++) {
1783 2216796 const int idx = pps->min_pu_width * y + (cu->x0 >> MIN_PU_LOG2);
1784 2216796 const MvField *mvf = fc->tab.mvf + idx;
1785 2216796 MvField *dmvr_mvf = fc->ref->tab_dmvr_mvf + idx;
1786
1787 2216796 memcpy(dmvr_mvf, mvf, sizeof(MvField) * w);
1788 }
1789 }
1790 454233 }
1791
1792 527323 static int inter_data(VVCLocalContext *lc)
1793 {
1794 527323 const CodingUnit *cu = lc->cu;
1795 527323 PredictionUnit *pu = &lc->cu->pu;
1796 527323 const MotionInfo *mi = &pu->mi;
1797 527323 int ret = 0;
1798
1799 527323 pu->general_merge_flag = 1;
1800
2/2
✓ Branch 0 taken 245106 times.
✓ Branch 1 taken 282217 times.
527323 if (!cu->skip_flag)
1801 245106 pu->general_merge_flag = ff_vvc_general_merge_flag(lc);
1802
1803
2/2
✓ Branch 0 taken 407675 times.
✓ Branch 1 taken 119648 times.
527323 if (pu->general_merge_flag) {
1804 407675 ret = hls_merge_data(lc);
1805
2/2
✓ Branch 0 taken 39050 times.
✓ Branch 1 taken 80598 times.
119648 } else if (cu->pred_mode == MODE_IBC) {
1806 39050 ret = mvp_data_ibc(lc);
1807 } else {
1808 80598 ret = mvp_data(lc);
1809 }
1810
1811
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 527323 times.
527323 if (ret)
1812 return ret;
1813
1814
2/2
✓ Branch 0 taken 67240 times.
✓ Branch 1 taken 460083 times.
527323 if (cu->pred_mode == MODE_IBC) {
1815 67240 ff_vvc_update_hmvp(lc, mi);
1816
6/6
✓ Branch 0 taken 432492 times.
✓ Branch 1 taken 27591 times.
✓ Branch 2 taken 396528 times.
✓ Branch 3 taken 35964 times.
✓ Branch 4 taken 367760 times.
✓ Branch 5 taken 28768 times.
460083 } else if (!pu->merge_gpm_flag && !pu->inter_affine_flag && !pu->merge_subblock_flag) {
1817 367760 refine_regular_subblock(lc);
1818 367760 ff_vvc_update_hmvp(lc, mi);
1819 }
1820
1821
2/2
✓ Branch 0 taken 454233 times.
✓ Branch 1 taken 73090 times.
527323 if (!pu->dmvr_flag)
1822 454233 fill_dmvr_info(lc);
1823 527323 return ret;
1824 }
1825
1826 4497 static TransformUnit* palette_add_tu(VVCLocalContext *lc, const int start, const int end, const VVCTreeType tree_type)
1827 {
1828 4497 CodingUnit *cu = lc->cu;
1829 4497 const VVCSPS *sps = lc->fc->ps.sps;
1830 4497 TransformUnit *tu = add_tu(lc->fc, cu, cu->x0, cu->y0, cu->cb_width, cu->cb_height);
1831
1832
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4497 times.
4497 if (!tu)
1833 return NULL;
1834
1835
2/2
✓ Branch 0 taken 12587 times.
✓ Branch 1 taken 4497 times.
17084 for (int c = start; c < end; c++) {
1836 12587 const int w = tu->width >> sps->hshift[c];
1837 12587 const int h = tu->height >> sps->vshift[c];
1838 12587 TransformBlock *tb = add_tb(tu, lc, tu->x0, tu->y0, w, h, c);
1839
2/2
✓ Branch 0 taken 8542 times.
✓ Branch 1 taken 4045 times.
12587 if (c != CR)
1840 8542 set_tb_size(lc->fc, tb);
1841 }
1842
1843
2/2
✓ Branch 0 taken 13491 times.
✓ Branch 1 taken 4497 times.
17988 for (int i = 0; i < FF_ARRAY_ELEMS(cu->plt); i++)
1844 13491 cu->plt[i].size = 0;
1845
1846 4497 return tu;
1847 }
1848
1849 4497 static int palette_predicted(VVCLocalContext *lc, const bool local_dual_tree, int start, int end,
1850 bool *predictor_reused, const int predictor_size, const int max_entries)
1851 {
1852 4497 CodingUnit *cu = lc->cu;
1853 4497 int nb_predicted = 0;
1854
1855
2/2
✓ Branch 0 taken 452 times.
✓ Branch 1 taken 4045 times.
4497 if (local_dual_tree) {
1856 452 start = LUMA;
1857 452 end = VVC_MAX_SAMPLE_ARRAYS;
1858 }
1859
1860
3/4
✓ Branch 0 taken 28514 times.
✓ Branch 1 taken 111 times.
✓ Branch 2 taken 28514 times.
✗ Branch 3 not taken.
28625 for (int i = 0; i < predictor_size && nb_predicted < max_entries; i++) {
1861 28514 const int run = ff_vvc_palette_predictor_run(lc, predictor_size - i);
1862
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28514 times.
28514 if (run < 0)
1863 return run;
1864
1865
2/2
✓ Branch 0 taken 4386 times.
✓ Branch 1 taken 24128 times.
28514 if (run == 1)
1866 4386 break;
1867
1868
2/2
✓ Branch 0 taken 10864 times.
✓ Branch 1 taken 13264 times.
24128 if (run > 1)
1869 10864 i += run - 1;
1870
1871 24128 predictor_reused[i] = true;
1872
2/2
✓ Branch 0 taken 72384 times.
✓ Branch 1 taken 24128 times.
96512 for (int c = start; c < end; c++)
1873 72384 cu->plt[c].entries[nb_predicted] = lc->ep->pp[c].entries[i];
1874 24128 nb_predicted++;
1875 }
1876
1877
2/2
✓ Branch 0 taken 13491 times.
✓ Branch 1 taken 4497 times.
17988 for (int c = start; c < end; c++)
1878 13491 cu->plt[c].size = nb_predicted;
1879
1880 4497 return 0;
1881 }
1882
1883 4497 static int palette_signaled(VVCLocalContext *lc, const bool local_dual_tree,
1884 const int start, const int end, const int max_entries)
1885 {
1886 4497 const VVCSPS *sps = lc->fc->ps.sps;
1887 4497 CodingUnit *cu = lc->cu;
1888 4497 const int nb_predicted = cu->plt[start].size;
1889
1/2
✓ Branch 0 taken 4497 times.
✗ Branch 1 not taken.
4497 const int nb_signaled = nb_predicted < max_entries ? ff_vvc_num_signalled_palette_entries(lc, max_entries - nb_predicted) : 0;
1890 4497 const int size = nb_predicted + nb_signaled;
1891
3/4
✓ Branch 0 taken 452 times.
✓ Branch 1 taken 4045 times.
✓ Branch 2 taken 452 times.
✗ Branch 3 not taken.
4497 const bool dual_tree_luma = local_dual_tree && cu->tree_type == DUAL_TREE_LUMA;
1892
1893
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4497 times.
4497 if (nb_signaled < 0)
1894 return AVERROR_INVALIDDATA;
1895
1896
2/2
✓ Branch 0 taken 12587 times.
✓ Branch 1 taken 4497 times.
17084 for (int c = start; c < end; c++) {
1897 12587 Palette *plt = cu->plt + c;
1898
2/2
✓ Branch 0 taken 3654 times.
✓ Branch 1 taken 12587 times.
16241 for (int i = nb_predicted; i < size; i++) {
1899 3654 plt->entries[i] = ff_vvc_new_palette_entries(lc, sps->bit_depth);
1900
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 3612 times.
3654 if (dual_tree_luma) {
1901 42 plt[CB].entries[i] = 1 << (sps->bit_depth - 1);
1902 42 plt[CR].entries[i] = 1 << (sps->bit_depth - 1);
1903 }
1904 }
1905 12587 plt->size = size;
1906 }
1907
1908 4497 return 0;
1909 }
1910
1911 4497 static void palette_update_predictor(VVCLocalContext *lc, const bool local_dual_tree, int start, int end,
1912 bool *predictor_reused, const int predictor_size)
1913 {
1914 4497 CodingUnit *cu = lc->cu;
1915
3/4
✓ Branch 0 taken 452 times.
✓ Branch 1 taken 4045 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 452 times.
4497 const int max_predictor = VVC_MAX_NUM_PALETTE_PREDICTOR_SIZE >> (cu->tree_type != SINGLE_TREE && !local_dual_tree);
1916
1917
2/2
✓ Branch 0 taken 452 times.
✓ Branch 1 taken 4045 times.
4497 if (local_dual_tree) {
1918 452 start = LUMA;
1919 452 end = VVC_MAX_SAMPLE_ARRAYS;
1920 }
1921
1922
2/2
✓ Branch 0 taken 13491 times.
✓ Branch 1 taken 4497 times.
17988 for (int c = start; c < end; c++) {
1923 13491 Palette *pp = lc->ep->pp + c;
1924 13491 Palette *plt = cu->plt + c;
1925 13491 int i = cu->plt[start].size;;
1926
1927 // copy unused predictors to the end of plt
1928
4/4
✓ Branch 0 taken 733860 times.
✓ Branch 1 taken 12354 times.
✓ Branch 2 taken 732723 times.
✓ Branch 3 taken 1137 times.
746214 for (int j = 0; j < predictor_size && i < max_predictor; j++) {
1929
2/2
✓ Branch 0 taken 660684 times.
✓ Branch 1 taken 72039 times.
732723 if (!predictor_reused[j]) {
1930 660684 plt->entries[i] = pp->entries[j];
1931 660684 i++;
1932 }
1933 }
1934
1935 13491 memcpy(pp->entries, plt->entries, i * sizeof(pp->entries[0]));
1936 13491 pp->size = i;
1937 }
1938 4497 }
1939
1940 4497 static void palette_qp(VVCLocalContext *lc, VVCTreeType tree_type, const bool escape_present)
1941 {
1942 4497 const VVCFrameContext *fc = lc->fc;
1943 4497 const VVCPPS *pps = fc->ps.pps;
1944 4497 const H266RawSliceHeader *rsh = lc->sc->sh.r;
1945 4497 const CodingUnit *cu = lc->cu;
1946
1947
1/2
✓ Branch 0 taken 4497 times.
✗ Branch 1 not taken.
4497 if (tree_type != DUAL_TREE_CHROMA) {
1948 4540 const bool has_qp_delta = escape_present &&
1949
3/6
✓ Branch 0 taken 43 times.
✓ Branch 1 taken 4454 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 43 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
4497 pps->r->pps_cu_qp_delta_enabled_flag && !lc->parse.is_cu_qp_delta_coded;
1950 4497 set_qp_y(lc, cu->x0, cu->y0, has_qp_delta);
1951 }
1952
1953
2/2
✓ Branch 0 taken 4045 times.
✓ Branch 1 taken 452 times.
4497 if (tree_type != DUAL_TREE_LUMA) {
1954
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4045 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4045 if (rsh->sh_cu_chroma_qp_offset_enabled_flag && !lc->parse.is_cu_chroma_qp_offset_coded)
1955 chroma_qp_offset_decode(lc, 0, 1);
1956 4045 set_qp_c(lc);
1957 }
1958 4497 }
1959
1960 #define PALETTE_SET_PIXEL(xc, yc, pix) \
1961 do { \
1962 const int off = ((xc) >> hs) + ((yc) >> vs) * tb->tb_width; \
1963 if (sps->bit_depth == 8) \
1964 u8[off] = pix; \
1965 else \
1966 u16[off] = pix; \
1967 } while (0)
1968
1969 #define PALETTE_INDEX(x, y) index[(y) * width + (x)]
1970
1971 // 6.5.3 Horizontal and vertical traverse scan order array initialization process
1972 // The hTravScan and vTravScan tables require approximately 576 KB of memory.
1973 // To save space, we use a macro to achieve the same functionality.
1974 #define TRAV_COL(p, wlog, mask) ((p & mask) ^ (-((p >> wlog) & 1) & mask))
1975 #define TRAV_ROW(p, hlog) (p >> hlog)
1976 #define TRAV(trans, p, wlog, hlog, mask) (trans ? TRAV_ROW((p), hlog) : TRAV_COL((p), wlog, mask))
1977 #define TRAV_X(pos) TRAV(transpose, pos, wlog2, hlog2, wmask)
1978 #define TRAV_Y(pos) TRAV(!transpose, pos, hlog2, wlog2, hmask)
1979
1980 60236 static int palette_subblock_data(VVCLocalContext *lc,
1981 const int max_index, const int subset_id, const bool transpose,
1982 uint8_t *run_type, uint8_t *index, int *prev_run_pos, bool *adjust)
1983 {
1984 60236 const CodingUnit *cu = lc->cu;
1985 60236 TransformUnit *tu = cu->tus.head;
1986 60236 const VVCSPS *sps = lc->fc->ps.sps;
1987 60236 const int width = tu->tbs[0].tb_width;
1988 60236 const int height = tu->tbs[0].tb_height;
1989 60236 const int min_pos = subset_id << 4;
1990
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 60236 times.
60236 const int max_pos = FFMIN(min_pos + 16, width * height);
1991 60236 const int wmask = width - 1;
1992 60236 const int hmask = height - 1;
1993 60236 const int wlog2 = av_log2(width);
1994 60236 const int hlog2 = av_log2(height);
1995 60236 const int start_idx = tu->tbs[0].c_idx;
1996 60236 const uint8_t esc = cu->plt[tu->tbs[0].c_idx].size;
1997 60236 uint8_t run_copy[16] = { 0 };
1998
1999
2/2
✓ Branch 0 taken 963776 times.
✓ Branch 1 taken 60236 times.
1024012 for (int i = min_pos; i < max_pos; i++) {
2000
2/2
✓ Branch 0 taken 109888 times.
✓ Branch 1 taken 853888 times.
963776 const int xc = TRAV_X(i);
2001
2/2
✓ Branch 0 taken 853888 times.
✓ Branch 1 taken 109888 times.
963776 const int yc = TRAV_Y(i);
2002
2003
4/4
✓ Branch 0 taken 959279 times.
✓ Branch 1 taken 4497 times.
✓ Branch 2 taken 608210 times.
✓ Branch 3 taken 351069 times.
963776 if (i > 0 && max_index > 0)
2004 608210 run_copy[i - min_pos] = ff_vvc_run_copy_flag(lc, run_type[i - 1], *prev_run_pos, i);
2005
2006 963776 run_type[i] = 0;
2007
4/4
✓ Branch 0 taken 612256 times.
✓ Branch 1 taken 351520 times.
✓ Branch 2 taken 97230 times.
✓ Branch 3 taken 515026 times.
963776 if (max_index > 0 && !run_copy[i - min_pos]) {
2008
8/8
✓ Branch 0 taken 79104 times.
✓ Branch 1 taken 18126 times.
✓ Branch 2 taken 12936 times.
✓ Branch 3 taken 66168 times.
✓ Branch 4 taken 18126 times.
✓ Branch 5 taken 12936 times.
✓ Branch 6 taken 14450 times.
✓ Branch 7 taken 3676 times.
97230 if (((!transpose && yc > 0) || (transpose && xc > 0))
2009
3/4
✓ Branch 0 taken 80618 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 68722 times.
✓ Branch 3 taken 11896 times.
80618 && i > 0 && !run_type[i - 1]) {
2010 68722 run_type[i] = ff_vvc_copy_above_palette_indices_flag(lc);
2011 }
2012 97230 *prev_run_pos = i;
2013
2/2
✓ Branch 0 taken 866095 times.
✓ Branch 1 taken 451 times.
866546 } else if (i > 0) {
2014 866095 run_type[i] = run_type[i - 1];
2015 }
2016 }
2017
2018
2/2
✓ Branch 0 taken 963776 times.
✓ Branch 1 taken 60236 times.
1024012 for (int i = min_pos; i < max_pos; i++) {
2019
2/2
✓ Branch 0 taken 109888 times.
✓ Branch 1 taken 853888 times.
963776 const int xc = TRAV_X(i);
2020
2/2
✓ Branch 0 taken 853888 times.
✓ Branch 1 taken 109888 times.
963776 const int yc = TRAV_Y(i);
2021
4/4
✓ Branch 0 taken 959279 times.
✓ Branch 1 taken 4497 times.
✓ Branch 2 taken 108832 times.
✓ Branch 3 taken 850447 times.
963776 const int prev_xc = i > 0 ? TRAV_X(i - 1) : 0;
2022
4/4
✓ Branch 0 taken 959279 times.
✓ Branch 1 taken 4497 times.
✓ Branch 2 taken 850447 times.
✓ Branch 3 taken 108832 times.
963776 const int prev_yc = i > 0 ? TRAV_Y(i - 1) : 0;
2023
2024 963776 int idx = 0;
2025
6/6
✓ Branch 0 taken 612256 times.
✓ Branch 1 taken 351520 times.
✓ Branch 2 taken 97230 times.
✓ Branch 3 taken 515026 times.
✓ Branch 4 taken 83845 times.
✓ Branch 5 taken 13385 times.
963776 if (max_index > 0 && !run_copy[i - min_pos] && !run_type[i]) {
2026
2/2
✓ Branch 0 taken 74987 times.
✓ Branch 1 taken 8858 times.
83845 if (max_index - *adjust > 0)
2027 74987 idx = ff_vvc_palette_idx_idc(lc, max_index, *adjust);
2028
2/2
✓ Branch 0 taken 79799 times.
✓ Branch 1 taken 4046 times.
83845 if (i > 0) {
2029 159598 const int ref_idx = !run_type[i - 1] ?
2030
2/2
✓ Branch 0 taken 67903 times.
✓ Branch 1 taken 11896 times.
79799 PALETTE_INDEX(prev_xc, prev_yc) : PALETTE_INDEX(xc - transpose, yc - !transpose);
2031 79799 idx += (idx >= ref_idx);
2032 }
2033 83845 *adjust = true;
2034 } else {
2035 879931 idx = PALETTE_INDEX(prev_xc, prev_yc);
2036 }
2037
2038
2/2
✓ Branch 0 taken 738229 times.
✓ Branch 1 taken 225547 times.
963776 if (!run_type[i])
2039 738229 PALETTE_INDEX(xc, yc) = idx;
2040 else
2041 225547 PALETTE_INDEX(xc, yc) = PALETTE_INDEX(xc - transpose, yc - !transpose);
2042 }
2043
2044
2/2
✓ Branch 0 taken 177356 times.
✓ Branch 1 taken 60236 times.
237592 for (int c = 0; c < tu->nb_tbs; c++) {
2045 177356 TransformBlock *tb = &tu->tbs[c];
2046 177356 const int c_idx = tb->c_idx;
2047 177356 const Palette *plt = &cu->plt[c_idx];
2048 177356 const int scale = ff_vvc_palette_derive_scale(lc, tu, tb);
2049 177356 const int hs = sps->hshift[c_idx] - sps->hshift[start_idx];
2050 177356 const int vs = sps->vshift[c_idx] - sps->vshift[start_idx];
2051 177356 uint8_t *u8 = (uint8_t *)tb->coeffs;
2052 177356 uint16_t *u16 = (uint16_t *)tb->coeffs;
2053
2054
2/2
✓ Branch 0 taken 2837696 times.
✓ Branch 1 taken 177356 times.
3015052 for (int i = min_pos; i < max_pos; i++) {
2055
2/2
✓ Branch 0 taken 309440 times.
✓ Branch 1 taken 2528256 times.
2837696 const int xc = TRAV_X(i);
2056
2/2
✓ Branch 0 taken 2528256 times.
✓ Branch 1 taken 309440 times.
2837696 const int yc = TRAV_Y(i);
2057
3/4
✓ Branch 0 taken 2444864 times.
✓ Branch 1 taken 392832 times.
✓ Branch 2 taken 2444864 times.
✗ Branch 3 not taken.
2837696 if (!(xc & hs) && !(yc & vs)) {
2058 2444864 const int v = PALETTE_INDEX(xc, yc);
2059
2/2
✓ Branch 0 taken 145 times.
✓ Branch 1 taken 2444719 times.
2444864 if (v == esc) {
2060 145 const int coeff = ff_vvc_palette_escape_val(lc, (1 << sps->bit_depth) - 1);
2061
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 145 times.
145 if (coeff < 0)
2062 return AVERROR_INVALIDDATA;
2063
2/2
✓ Branch 0 taken 116 times.
✓ Branch 1 taken 29 times.
145 const int pixel = av_clip_intp2(RSHIFT(coeff * scale, 6), sps->bit_depth);
2064
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 145 times.
145 PALETTE_SET_PIXEL(xc, yc, pixel);
2065 } else {
2066
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2444719 times.
2444719 PALETTE_SET_PIXEL(xc, yc, plt->entries[v]);
2067 }
2068 }
2069 }
2070 }
2071
2072 60236 return 0;
2073 }
2074
2075 4497 static int hls_palette_coding(VVCLocalContext *lc, const VVCTreeType tree_type)
2076 {
2077 4497 const VVCFrameContext *fc = lc->fc;
2078 4497 const VVCSPS *sps = fc->ps.sps;
2079 4497 const H266RawSliceHeader *rsh = lc->sc->sh.r;
2080 4497 CodingUnit *cu = lc->cu;
2081 4497 Palette *pp = lc->ep->pp;
2082
2/2
✓ Branch 0 taken 4045 times.
✓ Branch 1 taken 452 times.
4497 const int max_entries = tree_type == SINGLE_TREE ? 31 : 15;
2083
2/2
✓ Branch 0 taken 452 times.
✓ Branch 1 taken 4045 times.
4949 const bool local_dual_tree = tree_type != SINGLE_TREE &&
2084
3/6
✓ Branch 0 taken 452 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 452 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 452 times.
✗ Branch 5 not taken.
452 (!IS_I(rsh) || (IS_I(rsh) && !sps->r->sps_qtbtt_dual_tree_intra_flag));
2085 4497 bool escape_present = false;
2086 4497 bool transpose = false;
2087 4497 bool adjust = false;
2088 4497 int max_index = 0;
2089 4497 int prev_run_pos = 0;
2090
2091 int predictor_size, start, end, ret;
2092 bool reused[VVC_MAX_NUM_PALETTE_PREDICTOR_SIZE];
2093 uint8_t run_type[MAX_PALETTE_CU_SIZE * MAX_PALETTE_CU_SIZE];
2094 uint8_t index[MAX_PALETTE_CU_SIZE * MAX_PALETTE_CU_SIZE];
2095
2096 TransformUnit *tu;
2097
2098 4497 ff_vvc_channel_range(&start, &end, tree_type, sps->r->sps_chroma_format_idc);
2099
2100 4497 tu = palette_add_tu(lc, start, end, tree_type);
2101
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4497 times.
4497 if (!tu)
2102 return AVERROR(ENOMEM);
2103
2104 4497 predictor_size = pp[start].size;
2105 4497 memset(reused, 0, sizeof(reused[0]) * predictor_size);
2106
2107 4497 ret = palette_predicted(lc, local_dual_tree, start, end, reused, predictor_size, max_entries);
2108
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4497 times.
4497 if (ret < 0)
2109 return ret;
2110
2111 4497 ret = palette_signaled(lc, local_dual_tree, start, end, max_entries);
2112
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4497 times.
4497 if (ret < 0)
2113 return ret;
2114
2115 4497 palette_update_predictor(lc, local_dual_tree, start, end, reused, predictor_size);
2116
2117
1/2
✓ Branch 0 taken 4497 times.
✗ Branch 1 not taken.
4497 if (cu->plt[start].size > 0)
2118 4497 escape_present = ff_vvc_palette_escape_val_present_flag(lc);
2119
2120 4497 max_index = cu->plt[start].size - 1 + escape_present;
2121
2/2
✓ Branch 0 taken 4046 times.
✓ Branch 1 taken 451 times.
4497 if (max_index > 0) {
2122 4046 adjust = false;
2123 4046 transpose = ff_vvc_palette_transpose_flag(lc);
2124 }
2125
2126 4497 palette_qp(lc, tree_type, escape_present);
2127
2128 4497 index[0] = 0;
2129
2/2
✓ Branch 0 taken 60236 times.
✓ Branch 1 taken 4497 times.
64733 for (int i = 0; i <= (tu->tbs[0].tb_width * tu->tbs[0].tb_height - 1) >> 4; i++) {
2130 60236 ret = palette_subblock_data(lc, max_index, i, transpose,
2131 run_type, index, &prev_run_pos, &adjust);
2132
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 60236 times.
60236 if (ret < 0)
2133 return ret;
2134 }
2135
2136 4497 return 0;
2137 }
2138
2139 816825 static int intra_data(VVCLocalContext *lc)
2140 {
2141 816825 const VVCSPS *sps = lc->fc->ps.sps;
2142 816825 const CodingUnit *cu = lc->cu;
2143 816825 const VVCTreeType tree_type = cu->tree_type;
2144 816825 const bool pred_mode_plt_flag = cu->pred_mode == MODE_PLT;
2145 816825 int ret = 0;
2146
2147
4/4
✓ Branch 0 taken 734942 times.
✓ Branch 1 taken 81883 times.
✓ Branch 2 taken 547634 times.
✓ Branch 3 taken 187308 times.
816825 if (tree_type == SINGLE_TREE || tree_type == DUAL_TREE_LUMA) {
2148
2/2
✓ Branch 0 taken 4497 times.
✓ Branch 1 taken 625020 times.
629517 if (pred_mode_plt_flag) {
2149
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4497 times.
4497 if ((ret = hls_palette_coding(lc, tree_type)) < 0)
2150 return ret;
2151 4497 ff_vvc_set_intra_mvf(lc, false, PF_PLT, false);
2152 } else {
2153 625020 intra_luma_pred_modes(lc);
2154 625020 ff_vvc_set_intra_mvf(lc, false, PF_INTRA, cu->ciip_flag);
2155 }
2156 }
2157
6/6
✓ Branch 0 taken 734942 times.
✓ Branch 1 taken 81883 times.
✓ Branch 2 taken 187308 times.
✓ Branch 3 taken 547634 times.
✓ Branch 4 taken 254069 times.
✓ Branch 5 taken 15122 times.
816825 if ((tree_type == SINGLE_TREE || tree_type == DUAL_TREE_CHROMA) && sps->r->sps_chroma_format_idc) {
2158
3/4
✓ Branch 0 taken 4045 times.
✓ Branch 1 taken 250024 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4045 times.
254069 if (pred_mode_plt_flag && tree_type == DUAL_TREE_CHROMA) {
2159 if ((ret = hls_palette_coding(lc, tree_type)) < 0)
2160 return ret;
2161
2/2
✓ Branch 0 taken 250024 times.
✓ Branch 1 taken 4045 times.
254069 } else if (!pred_mode_plt_flag) {
2162 250024 intra_chroma_pred_modes(lc);
2163 }
2164 }
2165
2166 816825 return ret;
2167 }
2168
2169 1344148 static int hls_coding_unit(VVCLocalContext *lc, int x0, int y0, int cb_width, int cb_height,
2170 int cqt_depth, const VVCTreeType tree_type, VVCModeType mode_type)
2171 {
2172 1344148 const VVCFrameContext *fc = lc->fc;
2173 1344148 const VVCSPS *sps = fc->ps.sps;
2174 1344148 const H266RawSliceHeader *rsh = lc->sc->sh.r;
2175
4/4
✓ Branch 0 taken 1317780 times.
✓ Branch 1 taken 26368 times.
✓ Branch 2 taken 2338 times.
✓ Branch 3 taken 1315442 times.
1344148 const int is_128 = cb_width > 64 || cb_height > 64;
2176 1344148 int ret = 0;
2177
2178 1344148 CodingUnit *cu = add_cu(lc, x0, y0, cb_width, cb_height, cqt_depth, tree_type);
2179
2180
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1344148 times.
1344148 if (!cu)
2181 return AVERROR(ENOMEM);
2182
2183 1344148 ff_vvc_set_neighbour_available(lc, cu->x0, cu->y0, cu->cb_width, cu->cb_height);
2184
2185
3/4
✓ Branch 0 taken 717365 times.
✓ Branch 1 taken 626783 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 717365 times.
1344148 if (IS_I(rsh) && is_128)
2186 mode_type = MODE_TYPE_INTRA;
2187 1344148 cu->pred_mode = pred_mode_decode(lc, tree_type, mode_type);
2188
2189
5/6
✓ Branch 0 taken 812328 times.
✓ Branch 1 taken 531820 times.
✓ Branch 2 taken 8309 times.
✓ Branch 3 taken 804019 times.
✓ Branch 4 taken 8309 times.
✗ Branch 5 not taken.
1344148 if (cu->pred_mode == MODE_INTRA && sps->r->sps_act_enabled_flag && tree_type == SINGLE_TREE)
2190 8309 cu->act_enabled_flag = ff_vvc_cu_act_enabled_flag(lc);
2191
2192
4/4
✓ Branch 0 taken 531820 times.
✓ Branch 1 taken 812328 times.
✓ Branch 2 taken 4497 times.
✓ Branch 3 taken 527323 times.
1344148 if (cu->pred_mode == MODE_INTRA || cu->pred_mode == MODE_PLT)
2193 816825 ret = intra_data(lc);
2194
1/2
✓ Branch 0 taken 527323 times.
✗ Branch 1 not taken.
527323 else if (tree_type != DUAL_TREE_CHROMA) /* MODE_INTER or MODE_IBC */
2195 527323 ret = inter_data(lc);
2196
2197
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1344148 times.
1344148 if (ret < 0)
2198 return ret;
2199
2200
6/6
✓ Branch 0 taken 531820 times.
✓ Branch 1 taken 812328 times.
✓ Branch 2 taken 527323 times.
✓ Branch 3 taken 4497 times.
✓ Branch 4 taken 119648 times.
✓ Branch 5 taken 407675 times.
1344148 if (cu->pred_mode != MODE_INTRA && cu->pred_mode != MODE_PLT && !lc->cu->pu.general_merge_flag)
2201 119648 cu->coded_flag = ff_vvc_cu_coded_flag(lc);
2202 else
2203
4/4
✓ Branch 0 taken 942283 times.
✓ Branch 1 taken 282217 times.
✓ Branch 2 taken 937786 times.
✓ Branch 3 taken 4497 times.
1224500 cu->coded_flag = !(cu->skip_flag || cu->pred_mode == MODE_PLT);
2204
2205
2/2
✓ Branch 0 taken 990255 times.
✓ Branch 1 taken 353893 times.
1344148 if (cu->coded_flag) {
2206 990255 sbt_info(lc, sps);
2207
5/6
✓ Branch 0 taken 15652 times.
✓ Branch 1 taken 974603 times.
✓ Branch 2 taken 7343 times.
✓ Branch 3 taken 8309 times.
✓ Branch 4 taken 7343 times.
✗ Branch 5 not taken.
990255 if (sps->r->sps_act_enabled_flag && cu->pred_mode != MODE_INTRA && tree_type == SINGLE_TREE)
2208 7343 cu->act_enabled_flag = ff_vvc_cu_act_enabled_flag(lc);
2209 990255 lc->parse.lfnst_dc_only = 1;
2210 990255 lc->parse.lfnst_zero_out_sig_coeff_flag = 1;
2211 990255 lc->parse.mts_dc_only = 1;
2212 990255 lc->parse.mts_zero_out_sig_coeff_flag = 1;
2213 990255 ret = hls_transform_tree(lc, x0, y0, cb_width, cb_height, cu->ch_type);
2214
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 990255 times.
990255 if (ret < 0)
2215 return ret;
2216 990255 cu->lfnst_idx = lfnst_idx_decode(lc);
2217 990255 cu->mts_idx = mts_idx_decode(lc);
2218 990255 set_qp_c(lc);
2219
2/2
✓ Branch 0 taken 349396 times.
✓ Branch 1 taken 4497 times.
353893 } else if (cu->pred_mode != MODE_PLT) {
2220 349396 ret = skipped_transform_tree_unit(lc);
2221
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 349396 times.
349396 if (ret < 0)
2222 return ret;
2223 }
2224 1344148 set_cu_tabs(lc, cu);
2225
2226 1344148 return 0;
2227 }
2228
2229 867185 static int derive_mode_type_condition(const VVCLocalContext *lc,
2230 const VVCSplitMode split, const int cb_width, const int cb_height, const VVCModeType mode_type_curr)
2231 {
2232 867185 const H266RawSliceHeader *rsh = lc->sc->sh.r;
2233 867185 const VVCSPS *sps = lc->fc->ps.sps;
2234 867185 const int area = cb_width * cb_height;
2235
2236
6/6
✓ Branch 0 taken 477744 times.
✓ Branch 1 taken 389441 times.
✓ Branch 2 taken 46579 times.
✓ Branch 3 taken 431165 times.
✓ Branch 4 taken 400389 times.
✓ Branch 5 taken 35631 times.
867185 if ((IS_I(rsh) && sps->r->sps_qtbtt_dual_tree_intra_flag) ||
2237
2/2
✓ Branch 0 taken 376210 times.
✓ Branch 1 taken 24179 times.
400389 mode_type_curr != MODE_TYPE_ALL || !sps->r->sps_chroma_format_idc ||
2238
2/2
✓ Branch 0 taken 65766 times.
✓ Branch 1 taken 310444 times.
376210 sps->r->sps_chroma_format_idc == CHROMA_FORMAT_444)
2239 556741 return 0;
2240
9/10
✓ Branch 0 taken 24363 times.
✓ Branch 1 taken 286081 times.
✓ Branch 2 taken 22080 times.
✓ Branch 3 taken 2283 times.
✓ Branch 4 taken 22080 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 18861 times.
✓ Branch 7 taken 3219 times.
✓ Branch 8 taken 550 times.
✓ Branch 9 taken 304392 times.
310444 if ((area == 64 && (split == SPLIT_QT || split == SPLIT_TT_HOR || split == SPLIT_TT_VER)) ||
2241
2/4
✓ Branch 0 taken 550 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 550 times.
✗ Branch 3 not taken.
550 (area == 32 && (split == SPLIT_BT_HOR || split == SPLIT_BT_VER)))
2242 6052 return 1;
2243
9/10
✓ Branch 0 taken 18861 times.
✓ Branch 1 taken 285531 times.
✓ Branch 2 taken 12221 times.
✓ Branch 3 taken 6640 times.
✓ Branch 4 taken 12221 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2953 times.
✓ Branch 7 taken 15908 times.
✓ Branch 8 taken 36702 times.
✓ Branch 9 taken 251782 times.
304392 if ((area == 64 && (split == SPLIT_BT_HOR || split == SPLIT_BT_VER) && sps->r->sps_chroma_format_idc == CHROMA_FORMAT_420) ||
2244
8/8
✓ Branch 0 taken 32470 times.
✓ Branch 1 taken 4232 times.
✓ Branch 2 taken 6517 times.
✓ Branch 3 taken 25953 times.
✓ Branch 4 taken 1786 times.
✓ Branch 5 taken 8963 times.
✓ Branch 6 taken 27236 times.
✓ Branch 7 taken 252285 times.
288484 (area == 128 && (split == SPLIT_TT_HOR || split == SPLIT_TT_VER) && sps->r->sps_chroma_format_idc == CHROMA_FORMAT_420) ||
2245
6/6
✓ Branch 0 taken 17579 times.
✓ Branch 1 taken 9657 times.
✓ Branch 2 taken 82092 times.
✓ Branch 3 taken 187772 times.
✓ Branch 4 taken 11687 times.
✓ Branch 5 taken 70405 times.
279521 (cb_width == 8 && split == SPLIT_BT_VER) || (cb_width == 16 && split == SPLIT_TT_VER))
2246
2/2
✓ Branch 0 taken 42486 times.
✓ Branch 1 taken 3729 times.
46215 return 1 + !IS_I(rsh);
2247
2248 258177 return 0;
2249 }
2250
2251 867185 static VVCModeType mode_type_decode(VVCLocalContext *lc, const int x0, const int y0,
2252 const int cb_width, const int cb_height, const VVCSplitMode split, const int ch_type,
2253 const VVCModeType mode_type_curr)
2254 {
2255 VVCModeType mode_type;
2256 867185 const int mode_type_condition = derive_mode_type_condition(lc, split, cb_width, cb_height, mode_type_curr);
2257
2258
2/2
✓ Branch 0 taken 9781 times.
✓ Branch 1 taken 857404 times.
867185 if (mode_type_condition == 1)
2259 9781 mode_type = MODE_TYPE_INTRA;
2260
2/2
✓ Branch 0 taken 42486 times.
✓ Branch 1 taken 814918 times.
857404 else if (mode_type_condition == 2) {
2261
2/2
✓ Branch 1 taken 19353 times.
✓ Branch 2 taken 23133 times.
42486 mode_type = ff_vvc_non_inter_flag(lc, x0, y0, ch_type) ? MODE_TYPE_INTRA : MODE_TYPE_INTER;
2262 } else {
2263 814918 mode_type = mode_type_curr;
2264 }
2265
2266 867185 return mode_type;
2267 }
2268
2269 static int hls_coding_tree(VVCLocalContext *lc,
2270 int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2271 int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset, int part_idx,
2272 VVCSplitMode last_split_mode, VVCTreeType tree_type_curr, VVCModeType mode_type_curr);
2273
2274 258804 static int coding_tree_btv(VVCLocalContext *lc,
2275 int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2276 int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset,
2277 VVCTreeType tree_type, VVCModeType mode_type)
2278 {
2279 #define CODING_TREE(x, idx) do { \
2280 ret = hls_coding_tree(lc, x, y0, cb_width / 2, cb_height, \
2281 qg_on_y, qg_on_c, cb_sub_div + 1, cqt_depth, mtt_depth + 1, \
2282 depth_offset, idx, SPLIT_BT_VER, tree_type, mode_type); \
2283 if (ret < 0) \
2284 return ret; \
2285 } while (0);
2286
2287 258804 const VVCPPS *pps = lc->fc->ps.pps;
2288 258804 const int x1 = x0 + cb_width / 2;
2289 258804 int ret = 0;
2290
2291 258804 depth_offset += (x0 + cb_width > pps->width) ? 1 : 0;
2292
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 258804 times.
258804 CODING_TREE(x0, 0);
2293
2/2
✓ Branch 0 taken 257221 times.
✓ Branch 1 taken 1583 times.
258804 if (x1 < pps->width)
2294
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 257221 times.
257221 CODING_TREE(x1, 1);
2295
2296 258804 return 0;
2297
2298 #undef CODING_TREE
2299 }
2300
2301 317946 static int coding_tree_bth(VVCLocalContext *lc,
2302 int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2303 int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset,
2304 VVCTreeType tree_type, VVCModeType mode_type)
2305 {
2306 #define CODING_TREE(y, idx) do { \
2307 ret = hls_coding_tree(lc, x0, y, cb_width , cb_height / 2, \
2308 qg_on_y, qg_on_c, cb_sub_div + 1, cqt_depth, mtt_depth + 1, \
2309 depth_offset, idx, SPLIT_BT_HOR, tree_type, mode_type); \
2310 if (ret < 0) \
2311 return ret; \
2312 } while (0);
2313
2314 317946 const VVCPPS *pps = lc->fc->ps.pps;
2315 317946 const int y1 = y0 + (cb_height / 2);
2316 317946 int ret = 0;
2317
2318 317946 depth_offset += (y0 + cb_height > pps->height) ? 1 : 0;
2319
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 317946 times.
317946 CODING_TREE(y0, 0);
2320
2/2
✓ Branch 0 taken 296752 times.
✓ Branch 1 taken 21194 times.
317946 if (y1 < pps->height)
2321
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 296752 times.
296752 CODING_TREE(y1, 1);
2322
2323 317946 return 0;
2324
2325 #undef CODING_TREE
2326 }
2327
2328 87583 static int coding_tree_ttv(VVCLocalContext *lc,
2329 int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2330 int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset,
2331 VVCTreeType tree_type, VVCModeType mode_type)
2332 {
2333 #define CODING_TREE(x, w, sub_div, idx) do { \
2334 ret = hls_coding_tree(lc, x, y0, w, cb_height, \
2335 qg_on_y, qg_on_c, sub_div, cqt_depth, mtt_depth + 1, \
2336 depth_offset, idx, SPLIT_TT_VER, tree_type, mode_type); \
2337 if (ret < 0) \
2338 return ret; \
2339 } while (0);
2340
2341 87583 const VVCSH *sh = &lc->sc->sh;
2342 87583 const int x1 = x0 + cb_width / 4;
2343 87583 const int x2 = x0 + cb_width * 3 / 4;
2344 int ret;
2345
2346
3/4
✓ Branch 0 taken 51644 times.
✓ Branch 1 taken 35939 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 51644 times.
87583 qg_on_y = qg_on_y && (cb_sub_div + 2 <= sh->cu_qp_delta_subdiv);
2347
3/4
✓ Branch 0 taken 37971 times.
✓ Branch 1 taken 49612 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 37971 times.
87583 qg_on_c = qg_on_c && (cb_sub_div + 2 <= sh->cu_chroma_qp_offset_subdiv);
2348
2349
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 87583 times.
87583 CODING_TREE(x0, cb_width / 4, cb_sub_div + 2, 0);
2350
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 87583 times.
87583 CODING_TREE(x1, cb_width / 2, cb_sub_div + 1, 1);
2351
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 87583 times.
87583 CODING_TREE(x2, cb_width / 4, cb_sub_div + 2, 2);
2352
2353 87583 return 0;
2354
2355 #undef CODING_TREE
2356 }
2357
2358 92645 static int coding_tree_tth(VVCLocalContext *lc,
2359 int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2360 int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset,
2361 VVCTreeType tree_type, VVCModeType mode_type)
2362 {
2363 #define CODING_TREE(y, h, sub_div, idx) do { \
2364 ret = hls_coding_tree(lc, x0, y, cb_width, h, \
2365 qg_on_y, qg_on_c, sub_div, cqt_depth, mtt_depth + 1, \
2366 depth_offset, idx, SPLIT_TT_HOR, tree_type, mode_type); \
2367 if (ret < 0) \
2368 return ret; \
2369 } while (0);
2370
2371 92645 const VVCSH *sh = &lc->sc->sh;
2372 92645 const int y1 = y0 + (cb_height / 4);
2373 92645 const int y2 = y0 + (3 * cb_height / 4);
2374 int ret;
2375
2376
3/4
✓ Branch 0 taken 53829 times.
✓ Branch 1 taken 38816 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 53829 times.
92645 qg_on_y = qg_on_y && (cb_sub_div + 2 <= sh->cu_qp_delta_subdiv);
2377
3/4
✓ Branch 0 taken 36006 times.
✓ Branch 1 taken 56639 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 36006 times.
92645 qg_on_c = qg_on_c && (cb_sub_div + 2 <= sh->cu_chroma_qp_offset_subdiv);
2378
2379
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 92645 times.
92645 CODING_TREE(y0, cb_height / 4, cb_sub_div + 2, 0);
2380
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 92645 times.
92645 CODING_TREE(y1, cb_height / 2, cb_sub_div + 1, 1);
2381
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 92645 times.
92645 CODING_TREE(y2, cb_height / 4, cb_sub_div + 2, 2);
2382
2383 92645 return 0;
2384
2385 #undef CODING_TREE
2386 }
2387
2388 110207 static int coding_tree_qt(VVCLocalContext *lc,
2389 int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2390 int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset,
2391 VVCTreeType tree_type, VVCModeType mode_type)
2392 {
2393 #define CODING_TREE(x, y, idx) do { \
2394 ret = hls_coding_tree(lc, x, y, cb_width / 2, cb_height / 2, \
2395 qg_on_y, qg_on_c, cb_sub_div + 2, cqt_depth + 1, 0, 0, \
2396 idx, SPLIT_QT, tree_type, mode_type); \
2397 if (ret < 0) \
2398 return ret; \
2399 } while (0);
2400
2401 110207 const VVCPPS *pps = lc->fc->ps.pps;
2402 110207 const int x1 = x0 + cb_width / 2;
2403 110207 const int y1 = y0 + cb_height / 2;
2404 110207 int ret = 0;
2405
2406
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 110207 times.
110207 CODING_TREE(x0, y0, 0);
2407
2/2
✓ Branch 0 taken 106943 times.
✓ Branch 1 taken 3264 times.
110207 if (x1 < pps->width)
2408
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 106943 times.
106943 CODING_TREE(x1, y0, 1);
2409
2/2
✓ Branch 0 taken 104281 times.
✓ Branch 1 taken 5926 times.
110207 if (y1 < pps->height)
2410
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 104281 times.
104281 CODING_TREE(x0, y1, 2);
2411
2/2
✓ Branch 0 taken 106943 times.
✓ Branch 1 taken 3264 times.
110207 if (x1 < pps->width &&
2412
2/2
✓ Branch 0 taken 101048 times.
✓ Branch 1 taken 5895 times.
106943 y1 < pps->height)
2413
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 101048 times.
101048 CODING_TREE(x1, y1, 3);
2414
2415 110207 return 0;
2416
2417 #undef CODING_TREE
2418 }
2419
2420 typedef int (*coding_tree_fn)(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,
2423 VVCTreeType tree_type, VVCModeType mode_type);
2424
2425 const static coding_tree_fn coding_tree[] = {
2426 coding_tree_tth,
2427 coding_tree_bth,
2428 coding_tree_ttv,
2429 coding_tree_btv,
2430 coding_tree_qt,
2431 };
2432
2433 2211333 static int hls_coding_tree(VVCLocalContext *lc,
2434 int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2435 int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset, int part_idx,
2436 VVCSplitMode last_split_mode, VVCTreeType tree_type_curr, VVCModeType mode_type_curr)
2437 {
2438 2211333 VVCFrameContext *fc = lc->fc;
2439 2211333 const VVCPPS *pps = fc->ps.pps;
2440 2211333 const VVCSH *sh = &lc->sc->sh;
2441 2211333 const H266RawSliceHeader *rsh = sh->r;
2442 2211333 const int ch_type = tree_type_curr == DUAL_TREE_CHROMA;
2443 int ret;
2444 VVCAllowedSplit allowed;
2445
2446
6/6
✓ Branch 0 taken 280702 times.
✓ Branch 1 taken 1930631 times.
✓ Branch 2 taken 70213 times.
✓ Branch 3 taken 210489 times.
✓ Branch 4 taken 2635 times.
✓ Branch 5 taken 67578 times.
2211333 if (pps->r->pps_cu_qp_delta_enabled_flag && qg_on_y && cb_sub_div <= sh->cu_qp_delta_subdiv) {
2447 2635 lc->parse.is_cu_qp_delta_coded = 0;
2448 2635 lc->parse.cu_qg_top_left_x = x0;
2449 2635 lc->parse.cu_qg_top_left_y = y0;
2450 }
2451
4/4
✓ Branch 0 taken 206481 times.
✓ Branch 1 taken 2004852 times.
✓ Branch 2 taken 17504 times.
✓ Branch 3 taken 188977 times.
2211333 if (rsh->sh_cu_chroma_qp_offset_enabled_flag && qg_on_c &&
2452
2/2
✓ Branch 0 taken 931 times.
✓ Branch 1 taken 16573 times.
17504 cb_sub_div <= sh->cu_chroma_qp_offset_subdiv) {
2453 931 lc->parse.is_cu_chroma_qp_offset_coded = 0;
2454 931 memset(lc->parse.chroma_qp_offset, 0, sizeof(lc->parse.chroma_qp_offset));
2455 }
2456
2457 2211333 can_split(lc, x0, y0, cb_width, cb_height, mtt_depth, depth_offset, part_idx,
2458 last_split_mode, tree_type_curr, mode_type_curr, &allowed);
2459
2/2
✓ Branch 1 taken 867185 times.
✓ Branch 2 taken 1344148 times.
2211333 if (ff_vvc_split_cu_flag(lc, x0, y0, cb_width, cb_height, ch_type, &allowed)) {
2460 867185 VVCSplitMode split = ff_vvc_split_mode(lc, x0, y0, cb_width, cb_height, cqt_depth, mtt_depth, ch_type, &allowed);
2461 867185 VVCModeType mode_type = mode_type_decode(lc, x0, y0, cb_width, cb_height, split, ch_type, mode_type_curr);
2462
2463
2/2
✓ Branch 0 taken 808379 times.
✓ Branch 1 taken 58806 times.
867185 VVCTreeType tree_type = (mode_type == MODE_TYPE_INTRA) ? DUAL_TREE_LUMA : tree_type_curr;
2464
2465
2/2
✓ Branch 0 taken 756978 times.
✓ Branch 1 taken 110207 times.
867185 if (split != SPLIT_QT) {
2466
6/6
✓ Branch 0 taken 460268 times.
✓ Branch 1 taken 296710 times.
✓ Branch 2 taken 299101 times.
✓ Branch 3 taken 161167 times.
✓ Branch 4 taken 253019 times.
✓ Branch 5 taken 46082 times.
756978 if (!(x0 & 31) && !(y0 & 31) && mtt_depth <= 1)
2467 253019 TAB_MSM(fc, mtt_depth, x0, y0) = split;
2468 }
2469 867185 ret = coding_tree[split - 1](lc, x0, y0, cb_width, cb_height, qg_on_y, qg_on_c,
2470 cb_sub_div, cqt_depth, mtt_depth, depth_offset, tree_type, mode_type);
2471
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 867185 times.
867185 if (ret < 0)
2472 return ret;
2473
4/4
✓ Branch 0 taken 831554 times.
✓ Branch 1 taken 35631 times.
✓ Branch 2 taken 29134 times.
✓ Branch 3 taken 802420 times.
867185 if (mode_type_curr == MODE_TYPE_ALL && mode_type == MODE_TYPE_INTRA) {
2474 29134 ret = hls_coding_tree(lc, x0, y0, cb_width, cb_height, 0, qg_on_c, cb_sub_div,
2475 cqt_depth, mtt_depth, 0, 0, split, DUAL_TREE_CHROMA, mode_type);
2476
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 29134 times.
29134 if (ret < 0)
2477 return ret;
2478 }
2479 } else {
2480 1344148 ret = hls_coding_unit(lc, x0, y0, cb_width, cb_height, cqt_depth, tree_type_curr, mode_type_curr);
2481
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1344148 times.
1344148 if (ret < 0)
2482 return ret;
2483 }
2484
2485 2211333 return 0;
2486 }
2487
2488 25649 static int dual_tree_implicit_qt_split(VVCLocalContext *lc,
2489 const int x0, const int y0, const int cb_size, const int cqt_depth)
2490 {
2491 25649 const VVCSH *sh = &lc->sc->sh;
2492 25649 const H266RawSliceHeader *rsh = sh->r;
2493 25649 const VVCPPS *pps = lc->fc->ps.pps;
2494 25649 const int cb_subdiv = 2 * cqt_depth;
2495 int ret;
2496
2497
2/2
✓ Branch 0 taken 5308 times.
✓ Branch 1 taken 20341 times.
25649 if (cb_size > 64) {
2498 #define DUAL_TREE(x, y) do { \
2499 ret = dual_tree_implicit_qt_split(lc, x, y, cb_size / 2, cqt_depth + 1); \
2500 if (ret < 0) \
2501 return ret; \
2502 } while (0)
2503
2504 5308 const int x1 = x0 + (cb_size / 2);
2505 5308 const int y1 = y0 + (cb_size / 2);
2506
3/4
✓ Branch 0 taken 130 times.
✓ Branch 1 taken 5178 times.
✓ Branch 2 taken 130 times.
✗ Branch 3 not taken.
5308 if (pps->r->pps_cu_qp_delta_enabled_flag && cb_subdiv <= sh->cu_qp_delta_subdiv) {
2507 130 lc->parse.is_cu_qp_delta_coded = 0;
2508 130 lc->parse.cu_qg_top_left_x = x0;
2509 130 lc->parse.cu_qg_top_left_y = y0;
2510 }
2511
3/4
✓ Branch 0 taken 98 times.
✓ Branch 1 taken 5210 times.
✓ Branch 2 taken 98 times.
✗ Branch 3 not taken.
5308 if (rsh->sh_cu_chroma_qp_offset_enabled_flag && cb_subdiv <= sh->cu_chroma_qp_offset_subdiv) {
2512 98 lc->parse.is_cu_chroma_qp_offset_coded = 0;
2513 98 memset(lc->parse.chroma_qp_offset, 0, sizeof(lc->parse.chroma_qp_offset));
2514 }
2515
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 5308 times.
5308 DUAL_TREE(x0, y0);
2516
2/2
✓ Branch 0 taken 5145 times.
✓ Branch 1 taken 163 times.
5308 if (x1 < pps->width)
2517
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 5145 times.
5145 DUAL_TREE(x1, y0);
2518
2/2
✓ Branch 0 taken 4816 times.
✓ Branch 1 taken 492 times.
5308 if (y1 < pps->height)
2519
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4816 times.
4816 DUAL_TREE(x0, y1);
2520
4/4
✓ Branch 0 taken 5145 times.
✓ Branch 1 taken 163 times.
✓ Branch 2 taken 4656 times.
✓ Branch 3 taken 489 times.
5308 if (x1 < pps->width && y1 < pps->height)
2521
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4656 times.
4656 DUAL_TREE(x1, y1);
2522 #undef DUAL_TREE
2523 } else {
2524 #define CODING_TREE(tree_type) do { \
2525 const int qg_on_y = tree_type == DUAL_TREE_LUMA; \
2526 ret = hls_coding_tree(lc, x0, y0, cb_size, cb_size, qg_on_y, !qg_on_y, \
2527 cb_subdiv, cqt_depth, 0, 0, 0, SPLIT_NONE, tree_type, MODE_TYPE_ALL); \
2528 if (ret < 0) \
2529 return ret; \
2530 } while (0)
2531
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 20341 times.
20341 CODING_TREE(DUAL_TREE_LUMA);
2532
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 20341 times.
20341 CODING_TREE(DUAL_TREE_CHROMA);
2533 #undef CODING_TREE
2534 }
2535 25649 return 0;
2536 }
2537
2538 #define SET_SAO(elem, value) \
2539 do { \
2540 if (!sao_merge_up_flag && !sao_merge_left_flag) \
2541 sao->elem = value; \
2542 else if (sao_merge_left_flag) \
2543 sao->elem = CTB(fc->tab.sao, rx-1, ry).elem; \
2544 else if (sao_merge_up_flag) \
2545 sao->elem = CTB(fc->tab.sao, rx, ry-1).elem; \
2546 else \
2547 sao->elem = 0; \
2548 } while (0)
2549
2550 53355 static void hls_sao(VVCLocalContext *lc, const int rx, const int ry)
2551 {
2552 53355 VVCFrameContext *fc = lc->fc;
2553 53355 const H266RawSliceHeader *rsh = lc->sc->sh.r;
2554 53355 int sao_merge_left_flag = 0;
2555 53355 int sao_merge_up_flag = 0;
2556 53355 SAOParams *sao = &CTB(fc->tab.sao, rx, ry);
2557 int c_idx, i;
2558
2559
4/4
✓ Branch 0 taken 34171 times.
✓ Branch 1 taken 19184 times.
✓ Branch 2 taken 164 times.
✓ Branch 3 taken 34007 times.
53355 if (rsh->sh_sao_luma_used_flag || rsh->sh_sao_chroma_used_flag) {
2560
2/2
✓ Branch 0 taken 17452 times.
✓ Branch 1 taken 1896 times.
19348 if (rx > 0) {
2561
2/2
✓ Branch 0 taken 16635 times.
✓ Branch 1 taken 817 times.
17452 if (lc->ctb_left_flag)
2562 16635 sao_merge_left_flag = ff_vvc_sao_merge_flag_decode(lc);
2563 }
2564
4/4
✓ Branch 0 taken 16055 times.
✓ Branch 1 taken 3293 times.
✓ Branch 2 taken 8849 times.
✓ Branch 3 taken 7206 times.
19348 if (ry > 0 && !sao_merge_left_flag) {
2565
2/2
✓ Branch 0 taken 8048 times.
✓ Branch 1 taken 801 times.
8849 if (lc->ctb_up_flag)
2566 8048 sao_merge_up_flag = ff_vvc_sao_merge_flag_decode(lc);
2567 }
2568 }
2569
2570
4/4
✓ Branch 0 taken 211308 times.
✓ Branch 1 taken 1056 times.
✓ Branch 2 taken 159009 times.
✓ Branch 3 taken 53355 times.
212364 for (c_idx = 0; c_idx < (fc->ps.sps->r->sps_chroma_format_idc ? 3 : 1); c_idx++) {
2571
2/2
✓ Branch 0 taken 53355 times.
✓ Branch 1 taken 105654 times.
159009 const int sao_used_flag = !c_idx ? rsh->sh_sao_luma_used_flag : rsh->sh_sao_chroma_used_flag;
2572
2/2
✓ Branch 0 taken 116547 times.
✓ Branch 1 taken 42462 times.
159009 if (!sao_used_flag) {
2573 116547 sao->type_idx[c_idx] = SAO_NOT_APPLIED;
2574 116547 continue;
2575 }
2576
2577
2/2
✓ Branch 0 taken 11639 times.
✓ Branch 1 taken 30823 times.
42462 if (c_idx == 2) {
2578 11639 sao->type_idx[2] = sao->type_idx[1];
2579 11639 sao->eo_class[2] = sao->eo_class[1];
2580 } else {
2581
7/8
✓ Branch 0 taken 27167 times.
✓ Branch 1 taken 3656 times.
✓ Branch 2 taken 14160 times.
✓ Branch 3 taken 13007 times.
✓ Branch 5 taken 13007 times.
✓ Branch 6 taken 3656 times.
✓ Branch 7 taken 3656 times.
✗ Branch 8 not taken.
30823 SET_SAO(type_idx[c_idx], ff_vvc_sao_type_idx_decode(lc));
2582 }
2583
2584
2/2
✓ Branch 0 taken 26550 times.
✓ Branch 1 taken 15912 times.
42462 if (sao->type_idx[c_idx] == SAO_NOT_APPLIED)
2585 26550 continue;
2586
2587
2/2
✓ Branch 0 taken 63648 times.
✓ Branch 1 taken 15912 times.
79560 for (i = 0; i < 4; i++)
2588
7/8
✓ Branch 0 taken 54008 times.
✓ Branch 1 taken 9640 times.
✓ Branch 2 taken 24836 times.
✓ Branch 3 taken 29172 times.
✓ Branch 5 taken 29172 times.
✓ Branch 6 taken 9640 times.
✓ Branch 7 taken 9640 times.
✗ Branch 8 not taken.
63648 SET_SAO(offset_abs[c_idx][i], ff_vvc_sao_offset_abs_decode(lc));
2589
2590
2/2
✓ Branch 0 taken 5836 times.
✓ Branch 1 taken 10076 times.
15912 if (sao->type_idx[c_idx] == SAO_BAND) {
2591
2/2
✓ Branch 0 taken 23344 times.
✓ Branch 1 taken 5836 times.
29180 for (i = 0; i < 4; i++) {
2592
2/2
✓ Branch 0 taken 8291 times.
✓ Branch 1 taken 15053 times.
23344 if (sao->offset_abs[c_idx][i]) {
2593
7/8
✓ Branch 0 taken 7449 times.
✓ Branch 1 taken 842 times.
✓ Branch 2 taken 3042 times.
✓ Branch 3 taken 4407 times.
✓ Branch 5 taken 4407 times.
✓ Branch 6 taken 842 times.
✓ Branch 7 taken 842 times.
✗ Branch 8 not taken.
8291 SET_SAO(offset_sign[c_idx][i],
2594 ff_vvc_sao_offset_sign_decode(lc));
2595 } else {
2596 15053 sao->offset_sign[c_idx][i] = 0;
2597 }
2598 }
2599
7/8
✓ Branch 0 taken 5168 times.
✓ Branch 1 taken 668 times.
✓ Branch 2 taken 1633 times.
✓ Branch 3 taken 3535 times.
✓ Branch 5 taken 3535 times.
✓ Branch 6 taken 668 times.
✓ Branch 7 taken 668 times.
✗ Branch 8 not taken.
5836 SET_SAO(band_position[c_idx], ff_vvc_sao_band_position_decode(lc));
2600
2/2
✓ Branch 0 taken 7890 times.
✓ Branch 1 taken 2186 times.
10076 } else if (c_idx != 2) {
2601
7/8
✓ Branch 0 taken 6485 times.
✓ Branch 1 taken 1405 times.
✓ Branch 2 taken 3376 times.
✓ Branch 3 taken 3109 times.
✓ Branch 5 taken 3109 times.
✓ Branch 6 taken 1405 times.
✓ Branch 7 taken 1405 times.
✗ Branch 8 not taken.
7890 SET_SAO(eo_class[c_idx], ff_vvc_sao_eo_class_decode(lc));
2602 }
2603
2604 // Inferred parameters
2605 15912 sao->offset_val[c_idx][0] = 0;
2606
2/2
✓ Branch 0 taken 63648 times.
✓ Branch 1 taken 15912 times.
79560 for (i = 0; i < 4; i++) {
2607 63648 sao->offset_val[c_idx][i + 1] = sao->offset_abs[c_idx][i];
2608
2/2
✓ Branch 0 taken 40304 times.
✓ Branch 1 taken 23344 times.
63648 if (sao->type_idx[c_idx] == SAO_EDGE) {
2609
2/2
✓ Branch 0 taken 20152 times.
✓ Branch 1 taken 20152 times.
40304 if (i > 1)
2610 20152 sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1];
2611
2/2
✓ Branch 0 taken 6203 times.
✓ Branch 1 taken 17141 times.
23344 } else if (sao->offset_sign[c_idx][i]) {
2612 6203 sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1];
2613 }
2614 63648 sao->offset_val[c_idx][i + 1] *= 1 << (fc->ps.sps->bit_depth - FFMIN(10, fc->ps.sps->bit_depth));
2615 }
2616 }
2617 53355 }
2618
2619 53355 static void alf_params(VVCLocalContext *lc, const int rx, const int ry)
2620 {
2621 53355 const VVCFrameContext *fc = lc->fc;
2622 53355 const H266RawSliceHeader *sh = lc->sc->sh.r;
2623 53355 ALFParams *alf = &CTB(fc->tab.alf, rx, ry);
2624
2625 53355 alf->ctb_flag[LUMA] = alf->ctb_flag[CB] = alf->ctb_flag[CR] = 0;
2626 53355 alf->ctb_cc_idc[0] = alf->ctb_cc_idc[1] = 0;
2627
2/2
✓ Branch 0 taken 29433 times.
✓ Branch 1 taken 23922 times.
53355 if (sh->sh_alf_enabled_flag) {
2628 29433 alf->ctb_flag[LUMA] = ff_vvc_alf_ctb_flag(lc, rx, ry, LUMA);
2629
2/2
✓ Branch 0 taken 20795 times.
✓ Branch 1 taken 8638 times.
29433 if (alf->ctb_flag[LUMA]) {
2630 20795 uint8_t alf_use_aps_flag = 0;
2631
2/2
✓ Branch 0 taken 19987 times.
✓ Branch 1 taken 808 times.
20795 if (sh->sh_num_alf_aps_ids_luma > 0)
2632 19987 alf_use_aps_flag = ff_vvc_alf_use_aps_flag(lc);
2633
2/2
✓ Branch 0 taken 18004 times.
✓ Branch 1 taken 2791 times.
20795 if (alf_use_aps_flag) {
2634 18004 alf->ctb_filt_set_idx_y = 16;
2635
2/2
✓ Branch 0 taken 5167 times.
✓ Branch 1 taken 12837 times.
18004 if (sh->sh_num_alf_aps_ids_luma > 1)
2636 5167 alf->ctb_filt_set_idx_y += ff_vvc_alf_luma_prev_filter_idx(lc);
2637 } else {
2638 2791 alf->ctb_filt_set_idx_y = ff_vvc_alf_luma_fixed_filter_idx(lc);
2639 }
2640 }
2641
2/2
✓ Branch 0 taken 58866 times.
✓ Branch 1 taken 29433 times.
88299 for (int c_idx = CB; c_idx <= CR; c_idx++) {
2642
2/2
✓ Branch 0 taken 29433 times.
✓ Branch 1 taken 29433 times.
58866 const uint8_t alf_enabled_flag =
2643 c_idx == CB ? sh->sh_alf_cb_enabled_flag : sh->sh_alf_cr_enabled_flag;
2644
2/2
✓ Branch 0 taken 35508 times.
✓ Branch 1 taken 23358 times.
58866 if (alf_enabled_flag) {
2645 35508 const VVCALF *aps = fc->ps.alf_list[sh->sh_alf_aps_id_chroma];
2646 35508 alf->ctb_flag[c_idx] = ff_vvc_alf_ctb_flag(lc, rx, ry, c_idx);
2647 35508 alf->alf_ctb_filter_alt_idx[c_idx - 1] = 0;
2648
4/4
✓ Branch 0 taken 26209 times.
✓ Branch 1 taken 9299 times.
✓ Branch 2 taken 17909 times.
✓ Branch 3 taken 8300 times.
35508 if (alf->ctb_flag[c_idx] && aps->num_chroma_filters > 1)
2649 17909 alf->alf_ctb_filter_alt_idx[c_idx - 1] = ff_vvc_alf_ctb_filter_alt_idx(lc, c_idx, aps->num_chroma_filters);
2650 }
2651 }
2652 }
2653
2/2
✓ Branch 0 taken 42789 times.
✓ Branch 1 taken 10566 times.
53355 if (fc->ps.sps->r->sps_ccalf_enabled_flag) {
2654 42789 const uint8_t cc_enabled[] = { sh->sh_alf_cc_cb_enabled_flag, sh->sh_alf_cc_cr_enabled_flag };
2655 42789 const uint8_t cc_aps_id[] = { sh->sh_alf_cc_cb_aps_id, sh->sh_alf_cc_cr_aps_id };
2656
2/2
✓ Branch 0 taken 85578 times.
✓ Branch 1 taken 42789 times.
128367 for (int i = 0; i < 2; i++) {
2657
2/2
✓ Branch 0 taken 22625 times.
✓ Branch 1 taken 62953 times.
85578 if (cc_enabled[i]) {
2658 22625 const VVCALF *aps = fc->ps.alf_list[cc_aps_id[i]];
2659 22625 alf->ctb_cc_idc[i] = ff_vvc_alf_ctb_cc_idc(lc, rx, ry, i, aps->num_cc_filters[i]);
2660 }
2661 }
2662 }
2663 53355 }
2664
2665 53355 static void deblock_params(VVCLocalContext *lc, const int rx, const int ry)
2666 {
2667 53355 VVCFrameContext *fc = lc->fc;
2668 53355 const VVCSH *sh = &lc->sc->sh;
2669 53355 CTB(fc->tab.deblock, rx, ry) = sh->deblock;
2670 53355 }
2671
2672 53355 static int hls_coding_tree_unit(VVCLocalContext *lc,
2673 const int x0, const int y0, const int ctu_idx, const int rx, const int ry)
2674 {
2675 53355 const VVCFrameContext *fc = lc->fc;
2676 53355 const VVCSPS *sps = fc->ps.sps;
2677 53355 const VVCPPS *pps = fc->ps.pps;
2678 53355 const VVCSH *sh = &lc->sc->sh;
2679 53355 const H266RawSliceHeader *rsh = sh->r;
2680 53355 const unsigned int ctb_size = sps->ctb_size_y;
2681 53355 int ret = 0;
2682
2683 53355 memset(lc->parse.chroma_qp_offset, 0, sizeof(lc->parse.chroma_qp_offset));
2684
2685 53355 hls_sao(lc, x0 >> sps->ctb_log2_size_y, y0 >> sps->ctb_log2_size_y);
2686 53355 alf_params(lc, x0 >> sps->ctb_log2_size_y, y0 >> sps->ctb_log2_size_y);
2687 53355 deblock_params(lc, x0 >> sps->ctb_log2_size_y, y0 >> sps->ctb_log2_size_y);
2688
2689
4/4
✓ Branch 0 taken 6370 times.
✓ Branch 1 taken 46985 times.
✓ Branch 2 taken 5724 times.
✓ Branch 3 taken 646 times.
53355 if (IS_I(rsh) && sps->r->sps_qtbtt_dual_tree_intra_flag)
2690 5724 ret = dual_tree_implicit_qt_split(lc, x0, y0, ctb_size, 0);
2691 else
2692 47631 ret = hls_coding_tree(lc, x0, y0, ctb_size, ctb_size,
2693 1, 1, 0, 0, 0, 0, 0, SPLIT_NONE, SINGLE_TREE, MODE_TYPE_ALL);
2694
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 53355 times.
53355 if (ret < 0)
2695 return ret;
2696
2697
2/2
✓ Branch 0 taken 6433 times.
✓ Branch 1 taken 46922 times.
53355 if (rx == pps->ctb_to_col_bd[rx + 1] - 1) {
2698
2/2
✓ Branch 0 taken 1816 times.
✓ Branch 1 taken 4617 times.
6433 if (ctu_idx == sh->num_ctus_in_curr_slice - 1) {
2699 1816 const int end_of_slice_one_bit = ff_vvc_end_of_slice_flag_decode(lc);
2700
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1816 times.
1816 if (!end_of_slice_one_bit)
2701 return AVERROR_INVALIDDATA;
2702 } else {
2703
2/2
✓ Branch 0 taken 493 times.
✓ Branch 1 taken 4124 times.
4617 if (ry == pps->ctb_to_row_bd[ry + 1] - 1) {
2704 493 const int end_of_tile_one_bit = ff_vvc_end_of_tile_one_bit(lc);
2705
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 493 times.
493 if (!end_of_tile_one_bit)
2706 return AVERROR_INVALIDDATA;
2707 } else {
2708
2/2
✓ Branch 0 taken 153 times.
✓ Branch 1 taken 3971 times.
4124 if (fc->ps.sps->r->sps_entropy_coding_sync_enabled_flag) {
2709 153 const int end_of_subset_one_bit = ff_vvc_end_of_subset_one_bit(lc);
2710
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 153 times.
153 if (!end_of_subset_one_bit)
2711 return AVERROR_INVALIDDATA;
2712 }
2713 }
2714 }
2715 }
2716
2717 53355 return 0;
2718 }
2719
2720 626783 static int has_inter_luma(const CodingUnit *cu)
2721 {
2722
5/6
✓ Branch 0 taken 487929 times.
✓ Branch 1 taken 138854 times.
✓ Branch 2 taken 487713 times.
✓ Branch 3 taken 216 times.
✓ Branch 4 taken 487713 times.
✗ Branch 5 not taken.
626783 return cu->pred_mode != MODE_INTRA && cu->pred_mode != MODE_PLT && cu->tree_type != DUAL_TREE_CHROMA;
2723 }
2724
2725 9067359 static int pred_get_y(const VVCLocalContext *lc, const int y0, const Mv *mv, const int height)
2726 {
2727 9067359 const VVCPPS *pps = lc->fc->ps.pps;
2728 9067359 const int idx = lc->sc->sh.r->curr_subpic_idx;
2729 9067359 const int top = pps->subpic_y[idx];
2730 9067359 const int bottom = top + pps->subpic_height[idx];
2731
2732 9067359 return av_clip(y0 + (mv->y >> 4) + height, top, bottom);
2733 }
2734
2735 487713 static void cu_get_max_y(const CodingUnit *cu, int max_y[2][VVC_MAX_REF_ENTRIES], const VVCLocalContext *lc)
2736 {
2737 487713 const VVCFrameContext *fc = lc->fc;
2738 487713 const PredictionUnit *pu = &cu->pu;
2739
2740
2/2
✓ Branch 0 taken 27591 times.
✓ Branch 1 taken 460122 times.
487713 if (pu->merge_gpm_flag) {
2741
2/2
✓ Branch 0 taken 55182 times.
✓ Branch 1 taken 27591 times.
82773 for (int i = 0; i < FF_ARRAY_ELEMS(pu->gpm_mv); i++) {
2742 55182 const MvField *mvf = pu->gpm_mv + i;
2743 55182 const int lx = mvf->pred_flag - PF_L0;
2744 55182 const int idx = mvf->ref_idx[lx];
2745 55182 const int y = pred_get_y(lc, cu->y0, mvf->mv + lx, cu->cb_height);
2746
2747 55182 max_y[lx][idx] = FFMAX(max_y[lx][idx], y);
2748 }
2749 } else {
2750 460122 const MotionInfo *mi = &pu->mi;
2751
4/4
✓ Branch 0 taken 424158 times.
✓ Branch 1 taken 35964 times.
✓ Branch 2 taken 73090 times.
✓ Branch 3 taken 351068 times.
460122 const int max_dmvr_off = (!pu->inter_affine_flag && pu->dmvr_flag) ? 2 : 0;
2752 460122 const int sbw = cu->cb_width / mi->num_sb_x;
2753 460122 const int sbh = cu->cb_height / mi->num_sb_y;
2754
2/2
✓ Branch 0 taken 970361 times.
✓ Branch 1 taken 460122 times.
1430483 for (int sby = 0; sby < mi->num_sb_y; sby++) {
2755
2/2
✓ Branch 0 taken 6148938 times.
✓ Branch 1 taken 970361 times.
7119299 for (int sbx = 0; sbx < mi->num_sb_x; sbx++) {
2756 6148938 const int x0 = cu->x0 + sbx * sbw;
2757 6148938 const int y0 = cu->y0 + sby * sbh;
2758 6148938 const MvField *mvf = ff_vvc_get_mvf(fc, x0, y0);
2759
2/2
✓ Branch 0 taken 12297876 times.
✓ Branch 1 taken 6148938 times.
18446814 for (int lx = 0; lx < 2; lx++) {
2760 12297876 const PredFlag mask = 1 << lx;
2761
2/2
✓ Branch 0 taken 9012177 times.
✓ Branch 1 taken 3285699 times.
12297876 if (mvf->pred_flag & mask) {
2762 9012177 const int idx = mvf->ref_idx[lx];
2763 9012177 const int y = pred_get_y(lc, y0, mvf->mv + lx, sbh);
2764
2765 9012177 max_y[lx][idx] = FFMAX(max_y[lx][idx], y + max_dmvr_off);
2766 }
2767 }
2768 }
2769 }
2770 }
2771 487713 }
2772
2773 53355 static void ctu_get_pred(VVCLocalContext *lc, const int rs)
2774 {
2775 53355 const VVCFrameContext *fc = lc->fc;
2776 53355 const H266RawSliceHeader *rsh = lc->sc->sh.r;
2777 53355 CTU *ctu = fc->tab.ctus + rs;
2778 53355 const CodingUnit *cu = fc->tab.cus[rs];
2779
2780 53355 ctu->has_dmvr = 0;
2781
2782
2/2
✓ Branch 0 taken 6370 times.
✓ Branch 1 taken 46985 times.
53355 if (IS_I(rsh))
2783 6370 return;
2784
2785
2/2
✓ Branch 0 taken 93970 times.
✓ Branch 1 taken 46985 times.
140955 for (int lx = 0; lx < 2; lx++)
2786 93970 memset(ctu->max_y[lx], -1, sizeof(ctu->max_y[0][0]) * rsh->num_ref_idx_active[lx]);
2787
2788
2/2
✓ Branch 0 taken 626783 times.
✓ Branch 1 taken 46985 times.
673768 while (cu) {
2789
2/2
✓ Branch 1 taken 487713 times.
✓ Branch 2 taken 139070 times.
626783 if (has_inter_luma(cu)) {
2790 487713 cu_get_max_y(cu, ctu->max_y, lc);
2791 487713 ctu->has_dmvr |= cu->pu.dmvr_flag;
2792 }
2793 626783 cu = cu->next;
2794 }
2795 46985 ctu->max_y_idx[0] = ctu->max_y_idx[1] = 0;
2796 }
2797
2798 53355 int ff_vvc_coding_tree_unit(VVCLocalContext *lc,
2799 const int ctu_idx, const int rs, const int rx, const int ry)
2800 {
2801 53355 const VVCFrameContext *fc = lc->fc;
2802 53355 const VVCSPS *sps = fc->ps.sps;
2803 53355 const VVCPPS *pps = fc->ps.pps;
2804 53355 const int x_ctb = rx << sps->ctb_log2_size_y;
2805 53355 const int y_ctb = ry << sps->ctb_log2_size_y;
2806 53355 const int ctb_size = 1 << sps->ctb_log2_size_y << sps->ctb_log2_size_y;
2807 53355 EntryPoint* ep = lc->ep;
2808 int ret;
2809
2810
2/2
✓ Branch 0 taken 6433 times.
✓ Branch 1 taken 46922 times.
53355 if (rx == pps->ctb_to_col_bd[rx]) {
2811 6433 ep->num_hmvp = 0;
2812 6433 ep->num_hmvp_ibc = 0;
2813
4/4
✓ Branch 0 taken 4236 times.
✓ Branch 1 taken 2197 times.
✓ Branch 2 taken 112 times.
✓ Branch 3 taken 4124 times.
6433 ep->is_first_qg = ry == pps->ctb_to_row_bd[ry] || !ctu_idx;
2814 }
2815
2816 53355 lc->coeffs = fc->tab.coeffs + rs * ctb_size * VVC_MAX_SAMPLE_ARRAYS;
2817 53355 lc->cu = NULL;
2818
2819 53355 ff_vvc_cabac_init(lc, ctu_idx, rx, ry);
2820 53355 ff_vvc_decode_neighbour(lc, x_ctb, y_ctb, rx, ry, rs);
2821 53355 ret = hls_coding_tree_unit(lc, x_ctb, y_ctb, ctu_idx, rx, ry);
2822
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 53355 times.
53355 if (ret < 0)
2823 return ret;
2824 53355 ctu_get_pred(lc, rs);
2825
2826 53355 return 0;
2827 }
2828
2829 363015 void ff_vvc_decode_neighbour(VVCLocalContext *lc, const int x_ctb, const int y_ctb,
2830 const int rx, const int ry, const int rs)
2831 {
2832 363015 VVCFrameContext *fc = lc->fc;
2833 363015 const int ctb_size = fc->ps.sps->ctb_size_y;
2834
2835 363015 lc->end_of_tiles_x = fc->ps.pps->width;
2836 363015 lc->end_of_tiles_y = fc->ps.pps->height;
2837
2/2
✓ Branch 0 taken 44242 times.
✓ Branch 1 taken 318773 times.
363015 if (fc->ps.pps->ctb_to_col_bd[rx] != fc->ps.pps->ctb_to_col_bd[rx + 1])
2838 44242 lc->end_of_tiles_x = FFMIN(x_ctb + ctb_size, lc->end_of_tiles_x);
2839
2/2
✓ Branch 0 taken 72022 times.
✓ Branch 1 taken 290993 times.
363015 if (fc->ps.pps->ctb_to_row_bd[ry] != fc->ps.pps->ctb_to_row_bd[ry + 1])
2840 72022 lc->end_of_tiles_y = FFMIN(y_ctb + ctb_size, lc->end_of_tiles_y);
2841
2842 363015 lc->boundary_flags = 0;
2843
4/4
✓ Branch 0 taken 329952 times.
✓ Branch 1 taken 33063 times.
✓ Branch 2 taken 11179 times.
✓ Branch 3 taken 318773 times.
363015 if (rx > 0 && fc->ps.pps->ctb_to_col_bd[rx] != fc->ps.pps->ctb_to_col_bd[rx - 1])
2844 11179 lc->boundary_flags |= BOUNDARY_LEFT_TILE;
2845
4/4
✓ Branch 0 taken 329952 times.
✓ Branch 1 taken 33063 times.
✓ Branch 2 taken 5425 times.
✓ Branch 3 taken 324527 times.
363015 if (rx > 0 && fc->tab.slice_idx[rs] != fc->tab.slice_idx[rs - 1])
2846 5425 lc->boundary_flags |= BOUNDARY_LEFT_SLICE;
2847
4/4
✓ Branch 0 taken 305532 times.
✓ Branch 1 taken 57483 times.
✓ Branch 2 taken 14539 times.
✓ Branch 3 taken 290993 times.
363015 if (ry > 0 && fc->ps.pps->ctb_to_row_bd[ry] != fc->ps.pps->ctb_to_row_bd[ry - 1])
2848 14539 lc->boundary_flags |= BOUNDARY_UPPER_TILE;
2849
4/4
✓ Branch 0 taken 305532 times.
✓ Branch 1 taken 57483 times.
✓ Branch 2 taken 12341 times.
✓ Branch 3 taken 293191 times.
363015 if (ry > 0 && fc->tab.slice_idx[rs] != fc->tab.slice_idx[rs - fc->ps.pps->ctb_width])
2850 12341 lc->boundary_flags |= BOUNDARY_UPPER_SLICE;
2851
2/2
✓ Branch 0 taken 35226 times.
✓ Branch 1 taken 327789 times.
363015 if (fc->ps.sps->r->sps_subpic_ctu_top_left_x[lc->sc->sh.r->curr_subpic_idx] == rx)
2852 35226 lc->boundary_flags |= BOUNDARY_LEFT_SUBPIC;
2853
2/2
✓ Branch 0 taken 60066 times.
✓ Branch 1 taken 302949 times.
363015 if (fc->ps.sps->r->sps_subpic_ctu_top_left_y[lc->sc->sh.r->curr_subpic_idx] == ry)
2854 60066 lc->boundary_flags |= BOUNDARY_UPPER_SUBPIC;
2855
4/4
✓ Branch 0 taken 329952 times.
✓ Branch 1 taken 33063 times.
✓ Branch 2 taken 318773 times.
✓ Branch 3 taken 11179 times.
363015 lc->ctb_left_flag = rx > 0 && !(lc->boundary_flags & BOUNDARY_LEFT_TILE);
2856
6/6
✓ Branch 0 taken 305532 times.
✓ Branch 1 taken 57483 times.
✓ Branch 2 taken 290993 times.
✓ Branch 3 taken 14539 times.
✓ Branch 4 taken 288641 times.
✓ Branch 5 taken 2352 times.
363015 lc->ctb_up_flag = ry > 0 && !(lc->boundary_flags & BOUNDARY_UPPER_TILE) && !(lc->boundary_flags & BOUNDARY_UPPER_SLICE);
2857
4/4
✓ Branch 0 taken 288641 times.
✓ Branch 1 taken 74374 times.
✓ Branch 2 taken 260455 times.
✓ Branch 3 taken 28186 times.
623470 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]) &&
2858
1/2
✓ Branch 0 taken 260455 times.
✗ Branch 1 not taken.
260455 (fc->ps.pps->ctb_to_row_bd[ry] == fc->ps.pps->ctb_to_row_bd[ry - 1]);
2859
4/4
✓ Branch 0 taken 318773 times.
✓ Branch 1 taken 44242 times.
✓ Branch 2 taken 260455 times.
✓ Branch 3 taken 58318 times.
363015 lc->ctb_up_left_flag = lc->ctb_left_flag && lc->ctb_up_flag;
2860 363015 }
2861
2862 2898320 void ff_vvc_set_neighbour_available(VVCLocalContext *lc,
2863 const int x0, const int y0, const int w, const int h)
2864 {
2865 2898320 const int log2_ctb_size = lc->fc->ps.sps->ctb_log2_size_y;
2866 2898320 const int x0b = av_zero_extend(x0, log2_ctb_size);
2867 2898320 const int y0b = av_zero_extend(y0, log2_ctb_size);
2868
2869
4/4
✓ Branch 0 taken 876809 times.
✓ Branch 1 taken 2021511 times.
✓ Branch 2 taken 785501 times.
✓ Branch 3 taken 91308 times.
2898320 lc->na.cand_up = (lc->ctb_up_flag || y0b);
2870
4/4
✓ Branch 0 taken 562347 times.
✓ Branch 1 taken 2335973 times.
✓ Branch 2 taken 490274 times.
✓ Branch 3 taken 72073 times.
2898320 lc->na.cand_left = (lc->ctb_left_flag || x0b);
2871
8/8
✓ Branch 0 taken 443511 times.
✓ Branch 1 taken 2454809 times.
✓ Branch 2 taken 322864 times.
✓ Branch 3 taken 120647 times.
✓ Branch 4 taken 2720838 times.
✓ Branch 5 taken 56835 times.
✓ Branch 6 taken 2654870 times.
✓ Branch 7 taken 65968 times.
2898320 lc->na.cand_up_left = (x0b || y0b) ? lc->na.cand_left && lc->na.cand_up : lc->ctb_up_left_flag;
2872 2898320 lc->na.cand_up_right_sap =
2873
6/6
✓ Branch 0 taken 412212 times.
✓ Branch 1 taken 2486108 times.
✓ Branch 2 taken 285160 times.
✓ Branch 3 taken 127052 times.
✓ Branch 4 taken 85709 times.
✓ Branch 5 taken 199451 times.
2898320 (x0b + w == 1 << log2_ctb_size) ? lc->ctb_up_right_flag && !y0b : lc->na.cand_up;
2874
4/4
✓ Branch 0 taken 2504128 times.
✓ Branch 1 taken 394192 times.
✓ Branch 2 taken 2481305 times.
✓ Branch 3 taken 22823 times.
2898320 lc->na.cand_up_right = lc->na.cand_up_right_sap && (x0 + w) < lc->end_of_tiles_x;
2875 2898320 }
2876
2877 106830 void ff_vvc_ctu_free_cus(CodingUnit **cus)
2878 {
2879
2/2
✓ Branch 0 taken 1344148 times.
✓ Branch 1 taken 106830 times.
1450978 while (*cus) {
2880 1344148 CodingUnit *cu = *cus;
2881 1344148 TransformUnit **head = &cu->tus.head;
2882
2883 1344148 *cus = cu->next;
2884
2885
2/2
✓ Branch 0 taken 1663353 times.
✓ Branch 1 taken 1344148 times.
3007501 while (*head) {
2886 1663353 TransformUnit *tu = *head;
2887 1663353 *head = tu->next;
2888 1663353 av_refstruct_unref(&tu);
2889 }
2890 1344148 cu->tus.tail = NULL;
2891
2892 1344148 av_refstruct_unref(&cu);
2893 }
2894 106830 }
2895
2896 16643796 int ff_vvc_get_qPy(const VVCFrameContext *fc, const int xc, const int yc)
2897 {
2898 16643796 const int min_cb_log2_size_y = fc->ps.sps->min_cb_log2_size_y;
2899 16643796 const int x = xc >> min_cb_log2_size_y;
2900 16643796 const int y = yc >> min_cb_log2_size_y;
2901 16643796 return fc->tab.qp[LUMA][x + y * fc->ps.pps->min_cb_width];
2902 }
2903
2904 2462 void ff_vvc_ep_init_stat_coeff(EntryPoint *ep,
2905 const int bit_depth, const int persistent_rice_adaptation_enabled_flag)
2906 {
2907
2/2
✓ Branch 0 taken 7386 times.
✓ Branch 1 taken 2462 times.
9848 for (size_t i = 0; i < FF_ARRAY_ELEMS(ep->stat_coeff); ++i) {
2908 7386 ep->stat_coeff[i] =
2909
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7386 times.
7386 persistent_rice_adaptation_enabled_flag ? 2 * (av_log2(bit_depth - 10)) : 0;
2910 }
2911 2462 }
2912
2913 688889 void ff_vvc_channel_range(int *start, int *end, const VVCTreeType tree_type, const uint8_t chroma_format_idc)
2914 {
2915
4/4
✓ Branch 0 taken 672378 times.
✓ Branch 1 taken 16511 times.
✓ Branch 2 taken 546807 times.
✓ Branch 3 taken 125571 times.
688889 const bool has_chroma = chroma_format_idc && tree_type != DUAL_TREE_LUMA;
2916 688889 const bool has_luma = tree_type != DUAL_TREE_CHROMA;
2917
2918 688889 *start = has_luma ? LUMA : CB;
2919
2/2
✓ Branch 0 taken 546807 times.
✓ Branch 1 taken 142082 times.
688889 *end = has_chroma ? VVC_MAX_SAMPLE_ARRAYS : CB;
2920 688889 }
2921