FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/vvc/ctu.c
Date: 2024-07-16 12:46:59
Exec Total Coverage
Lines: 1577 1649 95.6%
Functions: 79 79 100.0%
Branches: 1343 1562 86.0%

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 "libavcodec/refstruct.h"
24
25 #include "cabac.h"
26 #include "ctu.h"
27 #include "inter.h"
28 #include "mvs.h"
29
30 #define PROF_TEMP_SIZE (PROF_BLOCK_SIZE) * sizeof(int16_t)
31
32 #define TAB_MSM(fc, depth, x, y) fc->tab.msm[(depth)][((y) >> 5) * fc->ps.pps->width32 + ((x) >> 5)]
33 #define TAB_ISPMF(fc, x, y) fc->tab.ispmf[((y) >> 6) * fc->ps.pps->width64 + ((x) >> 6)]
34
35 typedef enum VVCModeType {
36 MODE_TYPE_ALL,
37 MODE_TYPE_INTER,
38 MODE_TYPE_INTRA,
39 } VVCModeType;
40
41 1657525 static void set_tb_pos(const VVCFrameContext *fc, const TransformBlock *tb)
42 {
43 1657525 const int x_tb = tb->x0 >> MIN_TU_LOG2;
44 1657525 const int y_tb = tb->y0 >> MIN_TU_LOG2;
45 1657525 const int hs = fc->ps.sps->hshift[tb->c_idx];
46 1657525 const int vs = fc->ps.sps->vshift[tb->c_idx];
47 1657525 const int is_chroma = tb->c_idx != 0;
48 1657525 const int width = FFMAX(1, tb->tb_width >> (MIN_TU_LOG2 - hs));
49 1657525 const int end = y_tb + FFMAX(1, tb->tb_height >> (MIN_TU_LOG2 - vs));
50
51
2/2
✓ Branch 0 taken 8651571 times.
✓ Branch 1 taken 1657525 times.
10309096 for (int y = y_tb; y < end; y++) {
52 8651571 const int off = y * fc->ps.pps->min_tu_width + x_tb;
53
2/2
✓ Branch 0 taken 80185728 times.
✓ Branch 1 taken 8651571 times.
88837299 for (int i = 0; i < width; i++) {
54 80185728 fc->tab.tb_pos_x0[is_chroma][off + i] = tb->x0;
55 80185728 fc->tab.tb_pos_y0[is_chroma][off + i] = tb->y0;
56 }
57 8651571 memset(fc->tab.tb_width [is_chroma] + off, tb->tb_width, width);
58 8651571 memset(fc->tab.tb_height[is_chroma] + off, tb->tb_height, width);
59 }
60 1657525 }
61
62 2278755 static void set_tb_tab(uint8_t *tab, uint8_t v, const VVCFrameContext *fc,
63 const TransformBlock *tb)
64 {
65 2278755 const int width = tb->tb_width << fc->ps.sps->hshift[tb->c_idx];
66 2278755 const int height = tb->tb_height << fc->ps.sps->vshift[tb->c_idx];
67
68
2/2
✓ Branch 0 taken 11490207 times.
✓ Branch 1 taken 2278755 times.
13768962 for (int h = 0; h < height; h += MIN_TU_SIZE) {
69 11490207 const int y = (tb->y0 + h) >> MIN_TU_LOG2;
70 11490207 const int off = y * fc->ps.pps->min_tu_width + (tb->x0 >> MIN_TU_LOG2);
71 11490207 const int w = FFMAX(1, width >> MIN_TU_LOG2);
72 11490207 memset(tab + off, v, w);
73 }
74 2278755 }
75
76 // 8.7.1 Derivation process for quantization parameters
77 488 static int get_qp_y_pred(const VVCLocalContext *lc)
78 {
79 488 const VVCFrameContext *fc = lc->fc;
80 488 const VVCSPS *sps = fc->ps.sps;
81 488 const VVCPPS *pps = fc->ps.pps;
82 488 const CodingUnit *cu = lc->cu;
83 488 const int ctb_log2_size = sps->ctb_log2_size_y;
84 488 const int ctb_size_mask = (1 << ctb_log2_size) - 1;
85 488 const int xQg = lc->parse.cu_qg_top_left_x;
86 488 const int yQg = lc->parse.cu_qg_top_left_y;
87 488 const int min_cb_width = fc->ps.pps->min_cb_width;
88 488 const int x_cb = cu->x0 >> sps->min_cb_log2_size_y;
89 488 const int y_cb = cu->y0 >> sps->min_cb_log2_size_y;
90 488 const int rx = cu->x0 >> ctb_log2_size;
91 488 const int ry = cu->y0 >> ctb_log2_size;
92
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 488 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
488 const int in_same_ctb_a = ((xQg - 1) >> ctb_log2_size) == rx && (yQg >> ctb_log2_size) == ry;
93
2/4
✓ Branch 0 taken 488 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 488 times.
488 const int in_same_ctb_b = (xQg >> ctb_log2_size) == rx && ((yQg - 1) >> ctb_log2_size) == ry;
94 int qPy_pred, qPy_a, qPy_b;
95
96
2/2
✓ Branch 0 taken 244 times.
✓ Branch 1 taken 244 times.
488 if (lc->na.cand_up) {
97
2/4
✓ Branch 0 taken 244 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 244 times.
✗ Branch 3 not taken.
244 const int first_qg_in_ctu = !(xQg & ctb_size_mask) && !(yQg & ctb_size_mask);
98 244 const int qPy_up = fc->tab.qp[LUMA][x_cb + (y_cb - 1) * min_cb_width];
99
3/4
✓ Branch 0 taken 244 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 61 times.
✓ Branch 3 taken 183 times.
244 if (first_qg_in_ctu && pps->ctb_to_col_bd[xQg >> ctb_log2_size] == xQg >> ctb_log2_size)
100 61 return qPy_up;
101 }
102
103 // qPy_pred
104
2/2
✓ Branch 0 taken 61 times.
✓ Branch 1 taken 366 times.
427 qPy_pred = lc->ep->is_first_qg ? lc->sc->sh.slice_qp_y : lc->ep->qp_y;
105
106 // qPy_b
107
3/4
✓ Branch 0 taken 183 times.
✓ Branch 1 taken 244 times.
✓ Branch 2 taken 183 times.
✗ Branch 3 not taken.
427 if (!lc->na.cand_up || !in_same_ctb_b)
108 427 qPy_b = qPy_pred;
109 else
110 qPy_b = fc->tab.qp[LUMA][x_cb + (y_cb - 1) * min_cb_width];
111
112 // qPy_a
113
3/4
✓ Branch 0 taken 366 times.
✓ Branch 1 taken 61 times.
✓ Branch 2 taken 366 times.
✗ Branch 3 not taken.
427 if (!lc->na.cand_left || !in_same_ctb_a)
114 427 qPy_a = qPy_pred;
115 else
116 qPy_a = fc->tab.qp[LUMA][(x_cb - 1) + y_cb * min_cb_width];
117
118 av_assert2(qPy_a >= -fc->ps.sps->qp_bd_offset && qPy_a < 63);
119 av_assert2(qPy_b >= -fc->ps.sps->qp_bd_offset && qPy_b < 63);
120
121 427 return (qPy_a + qPy_b + 1) >> 1;
122 }
123
124 3598903 static void set_cb_tab(const VVCLocalContext *lc, uint8_t *tab, const uint8_t v)
125 {
126 3598903 const VVCFrameContext *fc = lc->fc;
127 3598903 const VVCPPS *pps = fc->ps.pps;
128 3598903 const CodingUnit *cu = lc->cu;
129 3598903 const int log2_min_cb_size = fc->ps.sps->min_cb_log2_size_y;
130 3598903 const int x_cb = cu->x0 >> log2_min_cb_size;
131 3598903 const int y_cb = cu->y0 >> log2_min_cb_size;
132 3598903 const int cb_width = cu->cb_width;
133 3598903 const int cb_height = cu->cb_height;
134 3598903 int x = y_cb * pps->min_cb_width + x_cb;
135
136
2/2
✓ Branch 0 taken 16924265 times.
✓ Branch 1 taken 3598903 times.
20523168 for (int y = 0; y < (cb_height >> log2_min_cb_size); y++) {
137 16924265 const int width = cb_width >> log2_min_cb_size;
138
139 16924265 memset(&tab[x], v, width);
140 16924265 x += pps->min_cb_width;
141 }
142 3598903 }
143
144 960785 static int set_qp_y(VVCLocalContext *lc, const int x0, const int y0, const int has_qp_delta)
145 {
146 960785 const VVCSPS *sps = lc->fc->ps.sps;
147 960785 EntryPoint *ep = lc->ep;
148 960785 CodingUnit *cu = lc->cu;
149 960785 int cu_qp_delta = 0;
150
151
2/2
✓ Branch 0 taken 935889 times.
✓ Branch 1 taken 24896 times.
960785 if (!lc->fc->ps.pps->r->pps_cu_qp_delta_enabled_flag) {
152 935889 ep->qp_y = lc->sc->sh.slice_qp_y;
153
6/6
✓ Branch 0 taken 24835 times.
✓ Branch 1 taken 61 times.
✓ Branch 2 taken 2819 times.
✓ Branch 3 taken 22016 times.
✓ Branch 4 taken 427 times.
✓ Branch 5 taken 2392 times.
24896 } else if (ep->is_first_qg || (lc->parse.cu_qg_top_left_x == x0 && lc->parse.cu_qg_top_left_y == y0)) {
154 488 ep->qp_y = get_qp_y_pred(lc);
155 488 ep->is_first_qg = 0;
156 }
157
158
2/2
✓ Branch 0 taken 376 times.
✓ Branch 1 taken 960409 times.
960785 if (has_qp_delta) {
159 376 const int cu_qp_delta_abs = ff_vvc_cu_qp_delta_abs(lc);
160
161
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 376 times.
376 if (cu_qp_delta_abs)
162 cu_qp_delta = ff_vvc_cu_qp_delta_sign_flag(lc) ? -cu_qp_delta_abs : cu_qp_delta_abs;
163
2/4
✓ Branch 0 taken 376 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 376 times.
376 if (cu_qp_delta > (31 + sps->qp_bd_offset / 2) || cu_qp_delta < -(32 + sps->qp_bd_offset / 2))
164 return AVERROR_INVALIDDATA;
165 376 lc->parse.is_cu_qp_delta_coded = 1;
166
167
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 376 times.
376 if (cu_qp_delta) {
168 int off = sps->qp_bd_offset;
169 ep->qp_y = FFUMOD(ep->qp_y + cu_qp_delta + 64 + 2 * off, 64 + off) - off;
170 }
171 }
172
173 960785 set_cb_tab(lc, lc->fc->tab.qp[LUMA], ep->qp_y);
174 960785 cu->qp[LUMA] = ep->qp_y;
175
176 960785 return 0;
177 }
178
179 1269270 static void set_qp_c_tab(const VVCLocalContext *lc, const TransformUnit *tu, const TransformBlock *tb)
180 {
181
6/6
✓ Branch 0 taken 52828 times.
✓ Branch 1 taken 1216442 times.
✓ Branch 2 taken 42006 times.
✓ Branch 3 taken 10822 times.
✓ Branch 4 taken 20336 times.
✓ Branch 5 taken 21670 times.
1269270 const int is_jcbcr = tu->joint_cbcr_residual_flag && tu->coded_flag[CB] && tu->coded_flag[CR];
182
2/2
✓ Branch 0 taken 1248934 times.
✓ Branch 1 taken 20336 times.
1269270 const int idx = is_jcbcr ? JCBCR : tb->c_idx;
183
184 1269270 set_tb_tab(lc->fc->tab.qp[tb->c_idx], lc->cu->qp[idx], lc->fc, tb);
185 1269270 }
186
187 910492 static void set_qp_c(VVCLocalContext *lc)
188 {
189 910492 const VVCFrameContext *fc = lc->fc;
190 910492 const VVCSPS *sps = fc->ps.sps;
191 910492 const VVCPPS *pps = fc->ps.pps;
192 910492 const H266RawSliceHeader *rsh = lc->sc->sh.r;
193 910492 CodingUnit *cu = lc->cu;
194 910492 const int x_center = cu->x0 + cu->cb_width / 2;
195 910492 const int y_center = cu->y0 + cu->cb_height / 2;
196 910492 const int single_tree = cu->tree_type == SINGLE_TREE;
197
2/2
✓ Branch 0 taken 433141 times.
✓ Branch 1 taken 477351 times.
910492 const int qp_luma = (single_tree ? lc->ep->qp_y : ff_vvc_get_qPy(fc, x_center, y_center)) + sps->qp_bd_offset;
198 910492 const int qp_chroma = av_clip(qp_luma, 0, MAX_QP + sps->qp_bd_offset);
199 910492 const int sh_chroma_qp_offset[] = {
200 910492 rsh->sh_cb_qp_offset,
201 910492 rsh->sh_cr_qp_offset,
202 910492 rsh->sh_joint_cbcr_qp_offset,
203 };
204 int qp;
205
206
2/2
✓ Branch 0 taken 2714440 times.
✓ Branch 1 taken 910492 times.
3624932 for (int i = CB - 1; i < CR + sps->r->sps_joint_cbcr_enabled_flag; i++) {
207 2714440 qp = sps->chroma_qp_table[i][qp_chroma];
208 2714440 qp = qp + pps->chroma_qp_offset[i] + sh_chroma_qp_offset[i] + lc->parse.chroma_qp_offset[i];
209 2714440 qp = av_clip(qp, -sps->qp_bd_offset, MAX_QP) + sps->qp_bd_offset;
210 2714440 cu->qp[i + 1] = qp;
211 }
212 910492 }
213
214 1141528 static TransformUnit* alloc_tu(VVCFrameContext *fc, CodingUnit *cu)
215 {
216 1141528 TransformUnit *tu = ff_refstruct_pool_get(fc->tu_pool);
217
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1141528 times.
1141528 if (!tu)
218 return NULL;
219
220 1141528 tu->next = NULL;
221
222
2/2
✓ Branch 0 taken 213729 times.
✓ Branch 1 taken 927799 times.
1141528 if (cu->tus.tail)
223 213729 cu->tus.tail->next = tu;
224 else
225 927799 cu->tus.head = tu;
226 1141528 cu->tus.tail = tu;
227
228 1141528 return tu;
229 }
230
231 1141528 static TransformUnit* add_tu(VVCFrameContext *fc, CodingUnit *cu, const int x0, const int y0, const int tu_width, const int tu_height)
232 {
233 1141528 TransformUnit *tu = alloc_tu(fc, cu);
234
235
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1141528 times.
1141528 if (!tu)
236 return NULL;
237
238 1141528 tu->x0 = x0;
239 1141528 tu->y0 = y0;
240 1141528 tu->width = tu_width;
241 1141528 tu->height = tu_height;
242 1141528 tu->joint_cbcr_residual_flag = 0;
243 1141528 memset(tu->coded_flag, 0, sizeof(tu->coded_flag));
244 1141528 tu->nb_tbs = 0;
245
246 1141528 return tu;
247 }
248
249 2292160 static TransformBlock* add_tb(TransformUnit *tu, VVCLocalContext *lc,
250 const int x0, const int y0, const int tb_width, const int tb_height, const int c_idx)
251 {
252 TransformBlock *tb;
253
254 2292160 tb = &tu->tbs[tu->nb_tbs++];
255 2292160 tb->has_coeffs = 0;
256 2292160 tb->x0 = x0;
257 2292160 tb->y0 = y0;
258 2292160 tb->tb_width = tb_width;
259 2292160 tb->tb_height = tb_height;
260 2292160 tb->log2_tb_width = av_log2(tb_width);
261 2292160 tb->log2_tb_height = av_log2(tb_height);
262
263 2292160 tb->max_scan_x = tb->max_scan_y = 0;
264 2292160 tb->min_scan_x = tb->min_scan_y = 0;
265
266 2292160 tb->c_idx = c_idx;
267 2292160 tb->ts = 0;
268 2292160 tb->coeffs = lc->coeffs;
269 2292160 lc->coeffs += tb_width * tb_height;
270 2292160 return tb;
271 }
272
273 698738 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 698738 uint8_t tu_y_coded_flag = 0;
277 698738 const VVCSPS *sps = lc->fc->ps.sps;
278 698738 CodingUnit *cu = lc->cu;
279
280
2/2
✓ Branch 0 taken 661432 times.
✓ Branch 1 taken 37306 times.
698738 if (!is_sbt_not_coded) {
281
4/4
✓ Branch 0 taken 548887 times.
✓ Branch 1 taken 112545 times.
✓ Branch 2 taken 39629 times.
✓ Branch 3 taken 509258 times.
661432 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 499974 times.
✓ Branch 1 taken 161458 times.
661432 if (!is_isp) {
283
4/4
✓ Branch 0 taken 497762 times.
✓ Branch 1 taken 2212 times.
✓ Branch 2 taken 486 times.
✓ Branch 3 taken 497276 times.
499974 const int is_large = cu->cb_width > sps->max_tb_size_y || cu->cb_height > sps->max_tb_size_y;
284
7/8
✓ Branch 0 taken 361748 times.
✓ Branch 1 taken 138226 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 361748 times.
✓ Branch 4 taken 99937 times.
✓ Branch 5 taken 38289 times.
✓ Branch 6 taken 2298 times.
✓ Branch 7 taken 97639 times.
499974 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 554509 times.
✓ Branch 1 taken 106923 times.
661432 tu_y_coded_flag = has_y_coded_flag ? ff_vvc_tu_y_coded_flag(lc) : 1;
287 }
288
2/2
✓ Branch 0 taken 161458 times.
✓ Branch 1 taken 537280 times.
698738 if (is_isp)
289
4/4
✓ Branch 0 taken 80291 times.
✓ Branch 1 taken 81167 times.
✓ Branch 2 taken 31378 times.
✓ Branch 3 taken 48913 times.
161458 lc->parse.infer_tu_cbf_luma = lc->parse.infer_tu_cbf_luma && !tu_y_coded_flag;
290 698738 return tu_y_coded_flag;
291 }
292
293 364306 static void chroma_qp_offset_decode(VVCLocalContext *lc, const int is_128, const int is_chroma_coded)
294 {
295 364306 const VVCPPS *pps = lc->fc->ps.pps;
296 364306 const H266RawSliceHeader *rsh = lc->sc->sh.r;
297
298
4/4
✓ Branch 0 taken 361608 times.
✓ Branch 1 taken 2698 times.
✓ Branch 2 taken 120152 times.
✓ Branch 3 taken 241456 times.
364306 if ((is_128 || is_chroma_coded) &&
299
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 122850 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
122850 rsh->sh_cu_chroma_qp_offset_enabled_flag && !lc->parse.is_cu_chroma_qp_offset_coded) {
300 const int cu_chroma_qp_offset_flag = ff_vvc_cu_chroma_qp_offset_flag(lc);
301 if (cu_chroma_qp_offset_flag) {
302 int cu_chroma_qp_offset_idx = 0;
303 if (pps->r->pps_chroma_qp_offset_list_len_minus1 > 0)
304 cu_chroma_qp_offset_idx = ff_vvc_cu_chroma_qp_offset_idx(lc);
305 for (int i = CB - 1; i < JCBCR; i++)
306 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 lc->parse.is_cu_chroma_qp_offset_coded = 1;
311 }
312 364306 }
313
314 817376 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 817376 VVCFrameContext *fc = lc->fc;
317 817376 const VVCSPS *sps = fc->ps.sps;
318 817376 const VVCPPS *pps = fc->ps.pps;
319 817376 CodingUnit *cu = lc->cu;
320 817376 TransformUnit *tu = add_tu(fc, cu, x0, y0, tu_width, tu_height);
321 817376 const int min_cb_width = pps->min_cb_width;
322 817376 const VVCTreeType tree_type = cu->tree_type;
323
4/4
✓ Branch 0 taken 815164 times.
✓ Branch 1 taken 2212 times.
✓ Branch 2 taken 486 times.
✓ Branch 3 taken 814678 times.
817376 const int is_128 = cu->cb_width > 64 || cu->cb_height > 64;
324 817376 const int is_isp = cu->isp_split_type != ISP_NO_SPLIT;
325
4/4
✓ Branch 0 taken 161458 times.
✓ Branch 1 taken 655918 times.
✓ Branch 2 taken 48913 times.
✓ Branch 3 taken 112545 times.
817376 const int is_isp_last_tu = is_isp && (sub_tu_index == cu->num_intra_subpartitions - 1);
326
4/4
✓ Branch 0 taken 74612 times.
✓ Branch 1 taken 742764 times.
✓ Branch 2 taken 37306 times.
✓ Branch 3 taken 37306 times.
891988 const int is_sbt_not_coded = cu->sbt_flag &&
327
6/6
✓ Branch 0 taken 19540 times.
✓ Branch 1 taken 17766 times.
✓ Branch 2 taken 37306 times.
✓ Branch 3 taken 19540 times.
✓ Branch 4 taken 19540 times.
✓ Branch 5 taken 17766 times.
74612 ((sub_tu_index == 0 && cu->sbt_pos_flag) || (sub_tu_index == 1 && !cu->sbt_pos_flag));
328
6/6
✓ Branch 0 taken 364306 times.
✓ Branch 1 taken 453070 times.
✓ Branch 2 taken 343195 times.
✓ Branch 3 taken 21111 times.
✓ Branch 4 taken 20558 times.
✓ Branch 5 taken 322637 times.
837934 const int chroma_available = tree_type != DUAL_TREE_LUMA && sps->r->sps_chroma_format_idc &&
329
2/2
✓ Branch 0 taken 5153 times.
✓ Branch 1 taken 15405 times.
20558 (!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 817376 times.
817376 if (!tu)
333 return AVERROR_INVALIDDATA;
334
335
4/4
✓ Branch 0 taken 245668 times.
✓ Branch 1 taken 571708 times.
✓ Branch 2 taken 6742 times.
✓ Branch 3 taken 238926 times.
817376 if (tree_type == SINGLE_TREE && is_isp_last_tu) {
336 6742 const int x_cu = x0 >> fc->ps.sps->min_cb_log2_size_y;
337 6742 const int y_cu = y0 >> fc->ps.sps->min_cb_log2_size_y;
338 6742 xc = SAMPLE_CTB(fc->tab.cb_pos_x[ch_type], x_cu, y_cu);
339 6742 yc = SAMPLE_CTB(fc->tab.cb_pos_y[ch_type], x_cu, y_cu);
340 6742 wc = SAMPLE_CTB(fc->tab.cb_width[ch_type], x_cu, y_cu);
341 6742 hc = SAMPLE_CTB(fc->tab.cb_height[ch_type], x_cu, y_cu);
342 } else {
343 810634 xc = x0, yc = y0, wc = tu_width, hc = tu_height;
344 }
345
346
4/4
✓ Branch 0 taken 327790 times.
✓ Branch 1 taken 489586 times.
✓ Branch 2 taken 291776 times.
✓ Branch 3 taken 36014 times.
817376 if (chroma_available && !is_sbt_not_coded) {
347 291776 tu->coded_flag[CB] = ff_vvc_tu_cb_coded_flag(lc);
348 291776 tu->coded_flag[CR] = ff_vvc_tu_cr_coded_flag(lc, tu->coded_flag[CB]);
349 }
350
351
6/6
✓ Branch 0 taken 327790 times.
✓ Branch 1 taken 489586 times.
✓ Branch 2 taken 225300 times.
✓ Branch 3 taken 102490 times.
✓ Branch 4 taken 18062 times.
✓ Branch 5 taken 207238 times.
817376 is_chroma_coded = chroma_available && (tu->coded_flag[CB] || tu->coded_flag[CR]);
352
353
2/2
✓ Branch 0 taken 698738 times.
✓ Branch 1 taken 118638 times.
817376 if (tree_type != DUAL_TREE_CHROMA) {
354 int has_qp_delta;
355 698738 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 170211 times.
✓ Branch 1 taken 525829 times.
✓ Branch 2 taken 24052 times.
✓ Branch 3 taken 146159 times.
696040 has_qp_delta = (is_128 || tu->coded_flag[LUMA] || is_chroma_coded) &&
357
6/6
✓ Branch 0 taken 696040 times.
✓ Branch 1 taken 2698 times.
✓ Branch 2 taken 13787 times.
✓ Branch 3 taken 538792 times.
✓ Branch 4 taken 376 times.
✓ Branch 5 taken 13411 times.
1394778 pps->r->pps_cu_qp_delta_enabled_flag && !lc->parse.is_cu_qp_delta_coded;
358 698738 ret = set_qp_y(lc, x0, y0, has_qp_delta);
359
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 698738 times.
698738 if (ret < 0)
360 return ret;
361 698738 add_tb(tu, lc, x0, y0, tu_width, tu_height, LUMA);
362 }
363
2/2
✓ Branch 0 taken 364306 times.
✓ Branch 1 taken 453070 times.
817376 if (tree_type != DUAL_TREE_LUMA) {
364 364306 chroma_qp_offset_decode(lc, is_128, is_chroma_coded);
365
2/2
✓ Branch 0 taken 327790 times.
✓ Branch 1 taken 36516 times.
364306 if (chroma_available) {
366 327790 const int hs = sps->hshift[CHROMA];
367 327790 const int vs = sps->vshift[CHROMA];
368 327790 add_tb(tu, lc, xc, yc, wc >> hs, hc >> vs, CB);
369 327790 add_tb(tu, lc, xc, yc, wc >> hs, hc >> vs, CR);
370 }
371 }
372
4/4
✓ Branch 0 taken 796265 times.
✓ Branch 1 taken 21111 times.
✓ Branch 2 taken 626031 times.
✓ Branch 3 taken 170234 times.
817376 if (sps->r->sps_joint_cbcr_enabled_flag && ((cu->pred_mode == MODE_INTRA &&
373
4/4
✓ Branch 0 taken 558706 times.
✓ Branch 1 taken 67325 times.
✓ Branch 2 taken 543768 times.
✓ Branch 3 taken 14938 times.
626031 (tu->coded_flag[CB] || tu->coded_flag[CR])) ||
374
5/6
✓ Branch 0 taken 35165 times.
✓ Branch 1 taken 678837 times.
✓ Branch 2 taken 4217 times.
✓ Branch 3 taken 30948 times.
✓ Branch 4 taken 86480 times.
✗ Branch 5 not taken.
796265 (tu->coded_flag[CB] && tu->coded_flag[CR])) &&
375 chroma_available) {
376 86480 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 1354318 times.
✓ Branch 1 taken 817376 times.
2171694 for (int i = 0; i < tu->nb_tbs; i++) {
380 1354318 TransformBlock *tb = &tu->tbs[i];
381 1354318 const int is_chroma = tb->c_idx != LUMA;
382 1354318 tb->has_coeffs = tu->coded_flag[tb->c_idx];
383
4/4
✓ Branch 0 taken 691826 times.
✓ Branch 1 taken 662492 times.
✓ Branch 2 taken 164092 times.
✓ Branch 3 taken 527734 times.
1354318 if (tb->has_coeffs && is_chroma)
384
6/6
✓ Branch 0 taken 61602 times.
✓ Branch 1 taken 102490 times.
✓ Branch 2 taken 43540 times.
✓ Branch 3 taken 18062 times.
✓ Branch 4 taken 33372 times.
✓ Branch 5 taken 10168 times.
164092 tb->has_coeffs = tb->c_idx == CB ? 1 : !(tu->coded_flag[CB] && tu->joint_cbcr_residual_flag);
385
2/2
✓ Branch 0 taken 681658 times.
✓ Branch 1 taken 672660 times.
1354318 if (tb->has_coeffs) {
386 681658 tb->ts = cu->bdpcm_flag[tb->c_idx];
387
4/4
✓ Branch 0 taken 678568 times.
✓ Branch 1 taken 3090 times.
✓ Branch 2 taken 678559 times.
✓ Branch 3 taken 9 times.
681658 if (sps->r->sps_transform_skip_enabled_flag && !cu->bdpcm_flag[tb->c_idx] &&
388
4/4
✓ Branch 0 taken 663565 times.
✓ Branch 1 taken 14994 times.
✓ Branch 2 taken 656704 times.
✓ Branch 3 taken 6861 times.
678559 tb->tb_width <= sps->max_ts_size && tb->tb_height <= sps->max_ts_size &&
389
6/6
✓ Branch 0 taken 617058 times.
✓ Branch 1 taken 39646 times.
✓ Branch 2 taken 477256 times.
✓ Branch 3 taken 139802 times.
✓ Branch 4 taken 371851 times.
✓ Branch 5 taken 105405 times.
656704 !cu->sbt_flag && (is_chroma || !is_isp)) {
390 511653 tb->ts = ff_vvc_transform_skip_flag(lc, is_chroma);
391 }
392 681658 ret = ff_vvc_residual_coding(lc, tb);
393
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 681658 times.
681658 if (ret < 0)
394 return ret;
395 681658 set_tb_tab(fc->tab.tu_coded_flag[tb->c_idx], tu->coded_flag[tb->c_idx], fc, tb);
396 }
397
2/2
✓ Branch 0 taken 1026528 times.
✓ Branch 1 taken 327790 times.
1354318 if (tb->c_idx != CR)
398 1026528 set_tb_pos(fc, tb);
399
2/2
✓ Branch 0 taken 327790 times.
✓ Branch 1 taken 1026528 times.
1354318 if (tb->c_idx == CB)
400 327790 set_tb_tab(fc->tab.tu_joint_cbcr_residual_flag, tu->joint_cbcr_residual_flag, fc, tb);
401 }
402
403 817376 return 0;
404 }
405
406 669298 static int hls_transform_tree(VVCLocalContext *lc, int x0, int y0,int tu_width, int tu_height, int ch_type)
407 {
408 669298 const CodingUnit *cu = lc->cu;
409 669298 const VVCSPS *sps = lc->fc->ps.sps;
410 int ret;
411
412 669298 lc->parse.infer_tu_cbf_luma = 1;
413
4/4
✓ Branch 0 taken 620385 times.
✓ Branch 1 taken 48913 times.
✓ Branch 2 taken 583079 times.
✓ Branch 3 taken 37306 times.
669298 if (cu->isp_split_type == ISP_NO_SPLIT && !cu->sbt_flag) {
414
4/4
✓ Branch 0 taken 581549 times.
✓ Branch 1 taken 1530 times.
✓ Branch 2 taken 243 times.
✓ Branch 3 taken 581306 times.
584852 if (tu_width > sps->max_tb_size_y || tu_height > sps->max_tb_size_y) {
415
4/4
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 243 times.
✓ Branch 2 taken 1106 times.
✓ Branch 3 taken 424 times.
1773 const int ver_split_first = tu_width > sps->max_tb_size_y && tu_width > tu_height;
416
2/2
✓ Branch 0 taken 1106 times.
✓ Branch 1 taken 667 times.
1773 const int trafo_width = ver_split_first ? (tu_width / 2) : tu_width;
417
2/2
✓ Branch 0 taken 667 times.
✓ Branch 1 taken 1106 times.
1773 const int trafo_height = !ver_split_first ? (tu_height / 2) : tu_height;
418
419 #define TRANSFORM_TREE(x, y) do { \
420 ret = hls_transform_tree(lc, x, y, trafo_width, trafo_height, ch_type); \
421 if (ret < 0) \
422 return ret; \
423 } while (0)
424
425
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1773 times.
1773 TRANSFORM_TREE(x0, y0);
426
2/2
✓ Branch 0 taken 1106 times.
✓ Branch 1 taken 667 times.
1773 if (ver_split_first)
427
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1106 times.
1106 TRANSFORM_TREE(x0 + trafo_width, y0);
428 else
429
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 667 times.
667 TRANSFORM_TREE(x0, y0 + trafo_height);
430
431 } else {
432 581306 ret = hls_transform_unit(lc, x0, y0, tu_width, tu_height, 0, ch_type);
433
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 581306 times.
581306 if (ret < 0)
434 return ret;
435
436 }
437
2/2
✓ Branch 0 taken 37306 times.
✓ Branch 1 taken 48913 times.
86219 } else if (cu->sbt_flag) {
438
2/2
✓ Branch 0 taken 19479 times.
✓ Branch 1 taken 17827 times.
37306 if (!cu->sbt_horizontal_flag) {
439 #define TRANSFORM_UNIT(x, width, idx) do { \
440 ret = hls_transform_unit(lc, x, y0, width, tu_height, idx, ch_type); \
441 if (ret < 0) \
442 return ret; \
443 } while (0)
444
445 19479 const int trafo_width = tu_width * lc->parse.sbt_num_fourths_tb0 / 4;
446
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 19479 times.
19479 TRANSFORM_UNIT(x0, trafo_width, 0);
447
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 19479 times.
19479 TRANSFORM_UNIT(x0 + trafo_width, tu_width - trafo_width, 1);
448
449 #undef TRANSFORM_UNIT
450 } else {
451 #define TRANSFORM_UNIT(y, height, idx) do { \
452 ret = hls_transform_unit(lc, x0, y, tu_width, height, idx, ch_type); \
453 if (ret < 0) \
454 return ret; \
455 } while (0)
456
457 17827 const int trafo_height = tu_height * lc->parse.sbt_num_fourths_tb0 / 4;
458
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 17827 times.
17827 TRANSFORM_UNIT(y0, trafo_height, 0);
459
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 17827 times.
17827 TRANSFORM_UNIT(y0 + trafo_height, tu_height - trafo_height, 1);
460
461 #undef TRANSFORM_UNIT
462 }
463
2/2
✓ Branch 0 taken 30405 times.
✓ Branch 1 taken 18508 times.
48913 } else if (cu->isp_split_type == ISP_HOR_SPLIT) {
464 30405 const int trafo_height = tu_height / cu->num_intra_subpartitions;
465
2/2
✓ Branch 0 taken 103392 times.
✓ Branch 1 taken 30405 times.
133797 for (int i = 0; i < cu->num_intra_subpartitions; i++) {
466 103392 ret = hls_transform_unit(lc, x0, y0 + trafo_height * i, tu_width, trafo_height, i, 0);
467
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 103392 times.
103392 if (ret < 0)
468 return ret;
469 }
470
1/2
✓ Branch 0 taken 18508 times.
✗ Branch 1 not taken.
18508 } else if (cu->isp_split_type == ISP_VER_SPLIT) {
471 18508 const int trafo_width = tu_width / cu->num_intra_subpartitions;
472
2/2
✓ Branch 0 taken 58066 times.
✓ Branch 1 taken 18508 times.
76574 for (int i = 0; i < cu->num_intra_subpartitions; i++) {
473 58066 ret = hls_transform_unit(lc, x0 + trafo_width * i , y0, trafo_width, tu_height, i, 0);
474
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 58066 times.
58066 if (ret < 0)
475 return ret;
476 }
477 }
478
479 669298 return 0;
480 }
481
482 386257 static int skipped_transform_tree(VVCLocalContext *lc, int x0, int y0,int tu_width, int tu_height)
483 {
484 386257 VVCFrameContext *fc = lc->fc;
485 386257 const CodingUnit *cu = lc->cu;
486 386257 const VVCSPS *sps = fc->ps.sps;
487
488
4/4
✓ Branch 0 taken 326062 times.
✓ Branch 1 taken 60195 times.
✓ Branch 2 taken 1910 times.
✓ Branch 3 taken 324152 times.
448362 if (tu_width > sps->max_tb_size_y || tu_height > sps->max_tb_size_y) {
489
4/4
✓ Branch 0 taken 60195 times.
✓ Branch 1 taken 1910 times.
✓ Branch 2 taken 40745 times.
✓ Branch 3 taken 19450 times.
62105 const int ver_split_first = tu_width > sps->max_tb_size_y && tu_width > tu_height;
490
2/2
✓ Branch 0 taken 40745 times.
✓ Branch 1 taken 21360 times.
62105 const int trafo_width = ver_split_first ? (tu_width / 2) : tu_width;
491
2/2
✓ Branch 0 taken 21360 times.
✓ Branch 1 taken 40745 times.
62105 const int trafo_height = !ver_split_first ? (tu_height / 2) : tu_height;
492
493 #define SKIPPED_TRANSFORM_TREE(x, y) do { \
494 int ret = skipped_transform_tree(lc, x, y, trafo_width, trafo_height); \
495 if (ret < 0) \
496 return ret; \
497 } while (0)
498
499
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 62105 times.
62105 SKIPPED_TRANSFORM_TREE(x0, y0);
500
2/2
✓ Branch 0 taken 40745 times.
✓ Branch 1 taken 21360 times.
62105 if (ver_split_first)
501
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 40745 times.
40745 SKIPPED_TRANSFORM_TREE(x0 + trafo_width, y0);
502 else
503
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 21360 times.
21360 SKIPPED_TRANSFORM_TREE(x0, y0 + trafo_height);
504 } else {
505 324152 TransformUnit *tu = add_tu(fc, lc->cu, x0, y0, tu_width, tu_height);
506
4/4
✓ Branch 0 taken 307641 times.
✓ Branch 1 taken 16511 times.
✓ Branch 2 taken 306845 times.
✓ Branch 3 taken 796 times.
324152 const int has_chroma = sps->r->sps_chroma_format_idc && cu->tree_type != DUAL_TREE_LUMA;
507 324152 const int c_start = cu->tree_type == DUAL_TREE_CHROMA ? CB : LUMA;
508
2/2
✓ Branch 0 taken 306845 times.
✓ Branch 1 taken 17307 times.
324152 const int c_end = has_chroma ? VVC_MAX_SAMPLE_ARRAYS : CB;
509
510
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 324152 times.
324152 if (!tu)
511 return AVERROR_INVALIDDATA;
512
2/2
✓ Branch 0 taken 937842 times.
✓ Branch 1 taken 324152 times.
1261994 for (int i = c_start; i < c_end; i++) {
513 937842 TransformBlock *tb = add_tb(tu, lc, x0, y0, tu_width >> sps->hshift[i], tu_height >> sps->vshift[i], i);
514
2/2
✓ Branch 0 taken 630997 times.
✓ Branch 1 taken 306845 times.
937842 if (i != CR)
515 630997 set_tb_pos(fc, tb);
516 }
517 }
518
519 386257 return 0;
520 }
521
522 //6.4.1 Allowed quad split process
523 //6.4.2 Allowed binary split process
524 //6.4.3 Allowed ternary split process
525 1529932 static void can_split(const VVCLocalContext *lc, int x0, int y0,int cb_width, int cb_height,
526 int mtt_depth, int depth_offset, int part_idx, VVCSplitMode last_split_mode,
527 VVCTreeType tree_type, VVCModeType mode_type, VVCAllowedSplit* split)
528 {
529 int min_qt_size, max_bt_size, max_tt_size, max_mtt_depth;
530 1529932 const VVCFrameContext *fc = lc->fc;
531 1529932 const VVCSH *sh = &lc->sc->sh;
532 1529932 const VVCSPS *sps = fc->ps.sps;
533 1529932 const VVCPPS *pps = fc->ps.pps;
534 1529932 const int chroma = tree_type == DUAL_TREE_CHROMA;
535 1529932 int min_cb_size_y = sps->min_cb_size_y;
536 1529932 int *qt = &split->qt;
537 1529932 int *btv = &split->btv;
538 1529932 int *bth = &split->bth;
539 1529932 int *ttv = &split->ttv;
540 1529932 int *tth = &split->tth;
541
542 1529932 *qt = *bth = *btv = *tth = *ttv = 1;
543
544
2/2
✓ Branch 0 taken 1152859 times.
✓ Branch 1 taken 377073 times.
1529932 if (mtt_depth)
545 1152859 *qt = 0;
546
547 1529932 min_qt_size = sh->min_qt_size[chroma];
548
2/2
✓ Branch 0 taken 555918 times.
✓ Branch 1 taken 974014 times.
1529932 if (cb_width <= min_qt_size)
549 555918 *qt = 0;
550
551
2/2
✓ Branch 0 taken 190187 times.
✓ Branch 1 taken 1339745 times.
1529932 if (chroma) {
552 190187 int chroma_area = (cb_width >> sps->hshift[1]) * (cb_height >> sps->vshift[1]);
553 190187 int chroma_width = cb_width >> sps->hshift[1];
554
555
2/2
✓ Branch 0 taken 56162 times.
✓ Branch 1 taken 134025 times.
190187 if (chroma_width == 8)
556 56162 *ttv = 0;
557
2/2
✓ Branch 0 taken 42720 times.
✓ Branch 1 taken 91305 times.
134025 else if (chroma_width <= 4) {
558
1/2
✓ Branch 0 taken 42720 times.
✗ Branch 1 not taken.
42720 if (chroma_width == 4)
559 42720 *btv = 0;
560 42720 *qt = 0;
561 }
562
2/2
✓ Branch 0 taken 8196 times.
✓ Branch 1 taken 181991 times.
190187 if (mode_type == MODE_TYPE_INTRA)
563 8196 *qt = *btv = *bth = *ttv = *tth = 0;
564
2/2
✓ Branch 0 taken 60168 times.
✓ Branch 1 taken 130019 times.
190187 if (chroma_area <= 32) {
565 60168 *ttv = *tth = 0;
566
2/2
✓ Branch 0 taken 24244 times.
✓ Branch 1 taken 35924 times.
60168 if (chroma_area <= 16)
567 24244 *btv = *bth = 0;
568 }
569 }
570 1529932 max_bt_size = sh->max_bt_size[chroma];
571 1529932 max_tt_size = sh->max_tt_size[chroma];
572 1529932 max_mtt_depth = sh->max_mtt_depth[chroma] + depth_offset;
573
574
2/2
✓ Branch 0 taken 59865 times.
✓ Branch 1 taken 1470067 times.
1529932 if (mode_type == MODE_TYPE_INTER) {
575 59865 int area = cb_width * cb_height;
576
2/2
✓ Branch 0 taken 22852 times.
✓ Branch 1 taken 37013 times.
59865 if (area == 32)
577 22852 *btv = *bth = 0;
578
2/2
✓ Branch 0 taken 21705 times.
✓ Branch 1 taken 15308 times.
37013 else if (area == 64)
579 21705 *ttv = *tth = 0;
580 }
581
2/2
✓ Branch 0 taken 563809 times.
✓ Branch 1 taken 966123 times.
1529932 if (cb_width <= 2 * min_cb_size_y) {
582 563809 *ttv = 0;
583
2/2
✓ Branch 0 taken 186885 times.
✓ Branch 1 taken 376924 times.
563809 if (cb_width <= min_cb_size_y)
584 186885 *btv = 0;
585 }
586
2/2
✓ Branch 0 taken 604236 times.
✓ Branch 1 taken 925696 times.
1529932 if (cb_height <= 2 * min_cb_size_y) {
587 604236 *tth = 0;
588
2/2
✓ Branch 0 taken 210427 times.
✓ Branch 1 taken 393809 times.
604236 if (cb_height <= min_cb_size_y)
589 210427 *bth = 0;
590 }
591
4/4
✓ Branch 0 taken 1505261 times.
✓ Branch 1 taken 24671 times.
✓ Branch 2 taken 590 times.
✓ Branch 3 taken 1504671 times.
1529932 if (cb_width > max_bt_size || cb_height > max_bt_size)
592 25261 *btv = *bth = 0;
593 1529932 max_tt_size = FFMIN(64, max_tt_size);
594
4/4
✓ Branch 0 taken 1444912 times.
✓ Branch 1 taken 85020 times.
✓ Branch 2 taken 6975 times.
✓ Branch 3 taken 1437937 times.
1529932 if (cb_width > max_tt_size || cb_height > max_tt_size)
595 91995 *ttv = *tth = 0;
596
2/2
✓ Branch 0 taken 314400 times.
✓ Branch 1 taken 1215532 times.
1529932 if (mtt_depth >= max_mtt_depth)
597 314400 *btv = *bth = *ttv = *tth = 0;
598
2/2
✓ Branch 0 taken 3853 times.
✓ Branch 1 taken 1526079 times.
1529932 if (x0 + cb_width > pps->width) {
599 3853 *ttv = *tth = 0;
600
2/2
✓ Branch 0 taken 1318 times.
✓ Branch 1 taken 2535 times.
3853 if (cb_height > 64)
601 1318 *btv = 0;
602
2/2
✓ Branch 0 taken 2746 times.
✓ Branch 1 taken 1107 times.
3853 if (y0 + cb_height <= pps->height)
603 2746 *bth = 0;
604
1/2
✓ Branch 0 taken 1107 times.
✗ Branch 1 not taken.
1107 else if (cb_width > min_qt_size)
605 1107 *btv = *bth = 0;
606 }
607
2/2
✓ Branch 0 taken 45665 times.
✓ Branch 1 taken 1484267 times.
1529932 if (y0 + cb_height > pps->height) {
608 45665 *btv = *ttv = *tth = 0;
609
2/2
✓ Branch 0 taken 6167 times.
✓ Branch 1 taken 39498 times.
45665 if (cb_width > 64)
610 6167 *bth = 0;
611 }
612
4/4
✓ Branch 0 taken 1152859 times.
✓ Branch 1 taken 377073 times.
✓ Branch 2 taken 504528 times.
✓ Branch 3 taken 648331 times.
1529932 if (mtt_depth > 0 && part_idx == 1) {
613
2/2
✓ Branch 0 taken 59412 times.
✓ Branch 1 taken 445116 times.
504528 if (last_split_mode == SPLIT_TT_VER)
614 59412 *btv = 0;
615
2/2
✓ Branch 0 taken 61065 times.
✓ Branch 1 taken 384051 times.
445116 else if (last_split_mode == SPLIT_TT_HOR)
616 61065 *bth = 0;
617 }
618
4/4
✓ Branch 0 taken 1488028 times.
✓ Branch 1 taken 41904 times.
✓ Branch 2 taken 2994 times.
✓ Branch 3 taken 1485034 times.
1529932 if (cb_width <= 64 && cb_height > 64)
619 2994 *btv = 0;
620
4/4
✓ Branch 0 taken 41904 times.
✓ Branch 1 taken 1488028 times.
✓ Branch 2 taken 2954 times.
✓ Branch 3 taken 38950 times.
1529932 if (cb_width > 64 && cb_height <= 64)
621 2954 *bth = 0;
622 1529932 }
623
624 335676 static int get_num_intra_subpartitions(enum IspType isp_split_type, int cb_width, int cb_height)
625 {
626
2/2
✓ Branch 0 taken 286763 times.
✓ Branch 1 taken 48913 times.
335676 if (isp_split_type == ISP_NO_SPLIT)
627 286763 return 1;
628
8/8
✓ Branch 0 taken 11368 times.
✓ Branch 1 taken 37545 times.
✓ Branch 2 taken 3298 times.
✓ Branch 3 taken 8070 times.
✓ Branch 4 taken 17043 times.
✓ Branch 5 taken 23800 times.
✓ Branch 6 taken 9027 times.
✓ Branch 7 taken 8016 times.
48913 if ((cb_width == 4 && cb_height == 8) || (cb_width == 8 && cb_height == 4))
629 17097 return 2;
630 31816 return 4;
631 }
632
633 158300 static int get_cclm_enabled(const VVCLocalContext *lc, const int x0, const int y0)
634 {
635 158300 const VVCFrameContext *fc = lc->fc;
636 158300 const VVCSPS *sps = fc->ps.sps;
637 158300 int enabled = 0;
638
639
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 158300 times.
158300 if (!sps->r->sps_cclm_enabled_flag)
640 return 0;
641
5/6
✓ Branch 0 taken 158300 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 110439 times.
✓ Branch 3 taken 47861 times.
✓ Branch 4 taken 868 times.
✓ Branch 5 taken 109571 times.
158300 if (!sps->r->sps_qtbtt_dual_tree_intra_flag || !IS_I(lc->sc->sh.r) || sps->ctb_log2_size_y < 6)
642 48729 return 1;
643 else {
644 109571 const int x64 = x0 >> 6 << 6;
645 109571 const int y64 = y0 >> 6 << 6;
646 109571 const int y32 = y0 >> 5 << 5;
647 109571 const int x64_cu = x64 >> fc->ps.sps->min_cb_log2_size_y;
648 109571 const int y64_cu = y64 >> fc->ps.sps->min_cb_log2_size_y;
649 109571 const int y32_cu = y32 >> fc->ps.sps->min_cb_log2_size_y;
650 109571 const int min_cb_width = fc->ps.pps->min_cb_width;
651 109571 const int depth = SAMPLE_CTB(fc->tab.cqt_depth[1], x64_cu, y64_cu);
652 109571 const int min_depth = fc->ps.sps->ctb_log2_size_y - 6;
653 109571 const VVCSplitMode msm64 = (VVCSplitMode)TAB_MSM(fc, 0, x64, y64);
654 109571 const VVCSplitMode msm32 = (VVCSplitMode)TAB_MSM(fc, 1, x64, y32);
655
656
2/2
✓ Branch 0 taken 14096 times.
✓ Branch 1 taken 95475 times.
123667 enabled = SAMPLE_CTB(fc->tab.cb_width[1], x64_cu, y64_cu) == 64 &&
657
2/2
✓ Branch 0 taken 4890 times.
✓ Branch 1 taken 9206 times.
14096 SAMPLE_CTB(fc->tab.cb_height[1], x64_cu, y64_cu) == 64;
658
2/2
✓ Branch 0 taken 15423 times.
✓ Branch 1 taken 8986 times.
24409 enabled |= depth == min_depth && msm64 == SPLIT_BT_HOR &&
659
4/4
✓ Branch 0 taken 24409 times.
✓ Branch 1 taken 85162 times.
✓ Branch 2 taken 9188 times.
✓ Branch 3 taken 6235 times.
143168 SAMPLE_CTB(fc->tab.cb_width[1], x64_cu, y32_cu) == 64 &&
660
2/2
✓ Branch 0 taken 3581 times.
✓ Branch 1 taken 5607 times.
9188 SAMPLE_CTB(fc->tab.cb_height[1], x64_cu, y32_cu) == 32;
661 109571 enabled |= depth > min_depth;
662
6/6
✓ Branch 0 taken 24409 times.
✓ Branch 1 taken 85162 times.
✓ Branch 2 taken 15423 times.
✓ Branch 3 taken 8986 times.
✓ Branch 4 taken 5520 times.
✓ Branch 5 taken 9903 times.
109571 enabled |= depth == min_depth && msm64 == SPLIT_BT_HOR && msm32 == SPLIT_BT_VER;
663
664
2/2
✓ Branch 0 taken 98828 times.
✓ Branch 1 taken 10743 times.
109571 if (enabled) {
665 98828 const int w = SAMPLE_CTB(fc->tab.cb_width[0], x64_cu, y64_cu);
666 98828 const int h = SAMPLE_CTB(fc->tab.cb_height[0], x64_cu, y64_cu);
667 98828 const int depth0 = SAMPLE_CTB(fc->tab.cqt_depth[0], x64_cu, y64_cu);
668
7/8
✓ Branch 0 taken 3798 times.
✓ Branch 1 taken 95030 times.
✓ Branch 2 taken 3798 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3318 times.
✓ Branch 5 taken 480 times.
✓ Branch 6 taken 3318 times.
✓ Branch 7 taken 95030 times.
98828 if ((w == 64 && h == 64 && TAB_ISPMF(fc, x64, y64)) ||
669
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3318 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 95030 times.
98348 ((w < 64 || h < 64) && depth0 == min_depth))
670 480 return 0;
671 }
672
673 }
674
675 109091 return enabled;
676 }
677
678 549380 static int less(const void *a, const void *b)
679 {
680 549380 return *(const int*)a - *(const int*)b;
681 }
682
683 //8.4.2 Derivation process for luma intra prediction mode
684 335676 static enum IntraPredMode luma_intra_pred_mode(VVCLocalContext* lc, const int intra_subpartitions_mode_flag)
685 {
686 335676 VVCFrameContext *fc = lc->fc;
687 335676 CodingUnit *cu = lc->cu;
688 335676 const int x0 = cu->x0;
689 335676 const int y0 = cu->y0;
690 enum IntraPredMode pred;
691 335676 int intra_luma_not_planar_flag = 1;
692 335676 int intra_luma_mpm_remainder = 0;
693 335676 int intra_luma_mpm_flag = 1;
694 335676 int intra_luma_mpm_idx = 0;
695
696
2/2
✓ Branch 0 taken 312813 times.
✓ Branch 1 taken 22863 times.
335676 if (!cu->intra_luma_ref_idx)
697 312813 intra_luma_mpm_flag = ff_vvc_intra_luma_mpm_flag(lc);
698
2/2
✓ Branch 0 taken 257369 times.
✓ Branch 1 taken 78307 times.
335676 if (intra_luma_mpm_flag) {
699
2/2
✓ Branch 0 taken 234506 times.
✓ Branch 1 taken 22863 times.
257369 if (!cu->intra_luma_ref_idx)
700 234506 intra_luma_not_planar_flag = ff_vvc_intra_luma_not_planar_flag(lc, intra_subpartitions_mode_flag);
701
2/2
✓ Branch 0 taken 130431 times.
✓ Branch 1 taken 126938 times.
257369 if (intra_luma_not_planar_flag)
702 130431 intra_luma_mpm_idx = ff_vvc_intra_luma_mpm_idx(lc);
703 } else {
704 78307 intra_luma_mpm_remainder = ff_vvc_intra_luma_mpm_remainder(lc);
705 }
706
707
2/2
✓ Branch 0 taken 126938 times.
✓ Branch 1 taken 208738 times.
335676 if (!intra_luma_not_planar_flag) {
708 126938 pred = INTRA_PLANAR;
709 } else {
710 208738 const VVCSPS *sps = fc->ps.sps;
711 208738 const int x_a = (x0 - 1) >> sps->min_cb_log2_size_y;
712 208738 const int y_a = (y0 + cu->cb_height - 1) >> sps->min_cb_log2_size_y;
713 208738 const int x_b = (x0 + cu->cb_width - 1) >> sps->min_cb_log2_size_y;
714 208738 const int y_b = (y0 - 1) >> sps->min_cb_log2_size_y;
715 208738 int min_cb_width = fc->ps.pps->min_cb_width;
716 208738 int x0b = av_zero_extend(x0, sps->ctb_log2_size_y);
717 208738 int y0b = av_zero_extend(y0, sps->ctb_log2_size_y);
718
4/4
✓ Branch 0 taken 38800 times.
✓ Branch 1 taken 169938 times.
✓ Branch 2 taken 35358 times.
✓ Branch 3 taken 3442 times.
208738 const int available_l = lc->ctb_left_flag || x0b;
719
4/4
✓ Branch 0 taken 69591 times.
✓ Branch 1 taken 139147 times.
✓ Branch 2 taken 65721 times.
✓ Branch 3 taken 3870 times.
208738 const int available_u = lc->ctb_up_flag || y0b;
720
721 int a, b, cand[5];
722
723
4/4
✓ Branch 0 taken 205296 times.
✓ Branch 1 taken 3442 times.
✓ Branch 2 taken 193240 times.
✓ Branch 3 taken 12056 times.
208738 if (!available_l || (SAMPLE_CTB(fc->tab.cpm[0], x_a, y_a) != MODE_INTRA) ||
724
2/2
✓ Branch 0 taken 26276 times.
✓ Branch 1 taken 166964 times.
193240 SAMPLE_CTB(fc->tab.imf, x_a, y_a)) {
725 41774 a = INTRA_PLANAR;
726 } else {
727 166964 a = SAMPLE_CTB(fc->tab.ipm, x_a, y_a);
728 }
729
730
4/4
✓ Branch 0 taken 204868 times.
✓ Branch 1 taken 3870 times.
✓ Branch 2 taken 192821 times.
✓ Branch 3 taken 12047 times.
208738 if (!available_u || (SAMPLE_CTB(fc->tab.cpm[0], x_b, y_b) != MODE_INTRA) ||
731
4/4
✓ Branch 0 taken 166209 times.
✓ Branch 1 taken 26612 times.
✓ Branch 2 taken 10289 times.
✓ Branch 3 taken 155920 times.
192821 SAMPLE_CTB(fc->tab.imf, x_b, y_b) || !y0b) {
732 52818 b = INTRA_PLANAR;
733 } else {
734 155920 b = SAMPLE_CTB(fc->tab.ipm, x_b, y_b);
735 }
736
737
4/4
✓ Branch 0 taken 63818 times.
✓ Branch 1 taken 144920 times.
✓ Branch 2 taken 13576 times.
✓ Branch 3 taken 50242 times.
208738 if (a == b && a > INTRA_DC) {
738 13576 cand[0] = a;
739 13576 cand[1] = 2 + ((a + 61) % 64);
740 13576 cand[2] = 2 + ((a - 1) % 64);
741 13576 cand[3] = 2 + ((a + 60) % 64);
742 13576 cand[4] = 2 + (a % 64);
743 } else {
744 195162 const int minab = FFMIN(a, b);
745 195162 const int maxab = FFMAX(a, b);
746
4/4
✓ Branch 0 taken 96166 times.
✓ Branch 1 taken 98996 times.
✓ Branch 2 taken 48990 times.
✓ Branch 3 taken 47176 times.
244152 if (a > INTRA_DC && b > INTRA_DC) {
747 48990 const int diff = maxab - minab;
748 48990 cand[0] = a;
749 48990 cand[1] = b;
750
2/2
✓ Branch 0 taken 10483 times.
✓ Branch 1 taken 38507 times.
48990 if (diff == 1) {
751 10483 cand[2] = 2 + ((minab + 61) % 64);
752 10483 cand[3] = 2 + ((maxab - 1) % 64);
753 10483 cand[4] = 2 + ((minab + 60) % 64);
754
2/2
✓ Branch 0 taken 417 times.
✓ Branch 1 taken 38090 times.
38507 } else if (diff >= 62) {
755 417 cand[2] = 2 + ((minab - 1) % 64);
756 417 cand[3] = 2 + ((maxab + 61) % 64);
757 417 cand[4] = 2 + (minab % 64);
758
2/2
✓ Branch 0 taken 4669 times.
✓ Branch 1 taken 33421 times.
38090 } else if (diff == 2) {
759 4669 cand[2] = 2 + ((minab - 1) % 64);
760 4669 cand[3] = 2 + ((minab + 61) % 64);
761 4669 cand[4] = 2 + ((maxab - 1) % 64);
762 } else {
763 33421 cand[2] = 2 + ((minab + 61) % 64);
764 33421 cand[3] = 2 + ((minab - 1) % 64);
765 33421 cand[4] = 2 + ((maxab + 61) % 64);
766 }
767
4/4
✓ Branch 0 taken 98996 times.
✓ Branch 1 taken 47176 times.
✓ Branch 2 taken 38931 times.
✓ Branch 3 taken 60065 times.
146172 } else if (a > INTRA_DC || b > INTRA_DC) {
768 86107 cand[0] = maxab;
769 86107 cand[1] = 2 + ((maxab + 61 ) % 64);
770 86107 cand[2] = 2 + ((maxab - 1) % 64);
771 86107 cand[3] = 2 + ((maxab + 60 ) % 64);
772 86107 cand[4] = 2 + (maxab % 64);
773 } else {
774 60065 cand[0] = INTRA_DC;
775 60065 cand[1] = INTRA_VERT;
776 60065 cand[2] = INTRA_HORZ;
777 60065 cand[3] = INTRA_VERT - 4;
778 60065 cand[4] = INTRA_VERT + 4;
779 }
780 }
781
2/2
✓ Branch 0 taken 130431 times.
✓ Branch 1 taken 78307 times.
208738 if (intra_luma_mpm_flag) {
782 130431 pred = cand[intra_luma_mpm_idx];
783 } else {
784 78307 qsort(cand, FF_ARRAY_ELEMS(cand), sizeof(cand[0]), less);
785 78307 pred = intra_luma_mpm_remainder + 1;
786
2/2
✓ Branch 0 taken 391535 times.
✓ Branch 1 taken 78307 times.
469842 for (int i = 0; i < FF_ARRAY_ELEMS(cand); i++) {
787
2/2
✓ Branch 0 taken 192776 times.
✓ Branch 1 taken 198759 times.
391535 if (pred >= cand[i])
788 192776 pred++;
789 }
790 }
791 }
792 335676 return pred;
793 }
794
795 665752 static int lfnst_idx_decode(VVCLocalContext *lc)
796 {
797 665752 CodingUnit *cu = lc->cu;
798 665752 const VVCTreeType tree_type = cu->tree_type;
799 665752 const VVCSPS *sps = lc->fc->ps.sps;
800 665752 const int cb_width = cu->cb_width;
801 665752 const int cb_height = cu->cb_height;
802 665752 const TransformUnit *tu = cu->tus.head;
803 int lfnst_width, lfnst_height, min_lfnst;
804 665752 int lfnst_idx = 0;
805
806 665752 memset(cu->apply_lfnst_flag, 0, sizeof(cu->apply_lfnst_flag));
807
808
5/6
✓ Branch 0 taken 499301 times.
✓ Branch 1 taken 166451 times.
✓ Branch 2 taken 404228 times.
✓ Branch 3 taken 95073 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 404228 times.
665752 if (!sps->r->sps_lfnst_enabled_flag || cu->pred_mode != MODE_INTRA || FFMAX(cb_width, cb_height) > sps->max_tb_size_y)
809 261524 return 0;
810
811
2/2
✓ Branch 0 taken 490517 times.
✓ Branch 1 taken 393555 times.
884072 while (tu) {
812
2/2
✓ Branch 0 taken 646564 times.
✓ Branch 1 taken 479844 times.
1126408 for (int j = 0; j < tu->nb_tbs; j++) {
813 646564 const TransformBlock *tb = tu->tbs + j;
814
4/4
✓ Branch 0 taken 426015 times.
✓ Branch 1 taken 220549 times.
✓ Branch 2 taken 10673 times.
✓ Branch 3 taken 415342 times.
646564 if (tu->coded_flag[tb->c_idx] && tb->ts)
815 10673 return 0;
816 }
817 479844 tu = tu->next;
818 }
819
820
2/2
✓ Branch 0 taken 91110 times.
✓ Branch 1 taken 302445 times.
393555 if (tree_type == DUAL_TREE_CHROMA) {
821 91110 lfnst_width = cb_width >> sps->hshift[1];
822 91110 lfnst_height = cb_height >> sps->vshift[1];
823 } else {
824 302445 const int vs = cu->isp_split_type == ISP_VER_SPLIT;
825 302445 const int hs = cu->isp_split_type == ISP_HOR_SPLIT;
826
2/2
✓ Branch 0 taken 13568 times.
✓ Branch 1 taken 288877 times.
302445 lfnst_width = vs ? cb_width / cu->num_intra_subpartitions : cb_width;
827
2/2
✓ Branch 0 taken 24025 times.
✓ Branch 1 taken 278420 times.
302445 lfnst_height = hs ? cb_height / cu->num_intra_subpartitions : cb_height;
828 }
829 393555 min_lfnst = FFMIN(lfnst_width, lfnst_height);
830
6/6
✓ Branch 0 taken 302445 times.
✓ Branch 1 taken 91110 times.
✓ Branch 2 taken 72268 times.
✓ Branch 3 taken 230177 times.
✓ Branch 4 taken 56448 times.
✓ Branch 5 taken 15820 times.
393555 if (tree_type != DUAL_TREE_CHROMA && cu->intra_mip_flag && min_lfnst < 16)
831 56448 return 0;
832
833
2/2
✓ Branch 0 taken 314132 times.
✓ Branch 1 taken 22975 times.
337107 if (min_lfnst >= 4) {
834
6/6
✓ Branch 0 taken 292298 times.
✓ Branch 1 taken 21834 times.
✓ Branch 2 taken 132137 times.
✓ Branch 3 taken 160161 times.
✓ Branch 4 taken 131097 times.
✓ Branch 5 taken 22874 times.
314132 if ((cu->isp_split_type != ISP_NO_SPLIT || !lc->parse.lfnst_dc_only) && lc->parse.lfnst_zero_out_sig_coeff_flag)
835 131097 lfnst_idx = ff_vvc_lfnst_idx(lc, tree_type != SINGLE_TREE);
836 }
837
838
2/2
✓ Branch 0 taken 97254 times.
✓ Branch 1 taken 239853 times.
337107 if (lfnst_idx) {
839 97254 cu->apply_lfnst_flag[LUMA] = tree_type != DUAL_TREE_CHROMA;
840 97254 cu->apply_lfnst_flag[CB] = cu->apply_lfnst_flag[CR] = tree_type == DUAL_TREE_CHROMA;
841 }
842
843 337107 return lfnst_idx;
844 }
845
846 665752 static MtsIdx mts_idx_decode(VVCLocalContext *lc)
847 {
848 665752 const CodingUnit *cu = lc->cu;
849 665752 const VVCSPS *sps = lc->fc->ps.sps;
850 665752 const int cb_width = cu->cb_width;
851 665752 const int cb_height = cu->cb_height;
852 665752 const uint8_t transform_skip_flag = cu->tus.head->tbs[0].ts; //fix me
853 665752 int mts_idx = MTS_DCT2_DCT2;
854
6/6
✓ Branch 0 taken 547114 times.
✓ Branch 1 taken 118638 times.
✓ Branch 2 taken 470983 times.
✓ Branch 3 taken 76131 times.
✓ Branch 4 taken 450509 times.
✓ Branch 5 taken 20474 times.
665752 if (cu->tree_type != DUAL_TREE_CHROMA && !cu->lfnst_idx &&
855
2/2
✓ Branch 0 taken 432894 times.
✓ Branch 1 taken 17615 times.
450509 !transform_skip_flag && FFMAX(cb_width, cb_height) <= 32 &&
856
4/4
✓ Branch 0 taken 397575 times.
✓ Branch 1 taken 35319 times.
✓ Branch 2 taken 361806 times.
✓ Branch 3 taken 35769 times.
432894 cu->isp_split_type == ISP_NO_SPLIT && !cu->sbt_flag &&
857
4/4
✓ Branch 0 taken 355154 times.
✓ Branch 1 taken 6652 times.
✓ Branch 2 taken 238742 times.
✓ Branch 3 taken 116412 times.
361806 lc->parse.mts_zero_out_sig_coeff_flag && !lc->parse.mts_dc_only) {
858
3/4
✓ Branch 0 taken 51885 times.
✓ Branch 1 taken 186857 times.
✓ Branch 2 taken 51885 times.
✗ Branch 3 not taken.
238742 if ((cu->pred_mode == MODE_INTER && sps->r->sps_explicit_mts_inter_enabled_flag) ||
859
4/4
✓ Branch 0 taken 186812 times.
✓ Branch 1 taken 51930 times.
✓ Branch 2 taken 184660 times.
✓ Branch 3 taken 2152 times.
238742 (cu->pred_mode == MODE_INTRA && sps->r->sps_explicit_mts_intra_enabled_flag)) {
860 184660 mts_idx = ff_vvc_mts_idx(lc);
861 }
862 }
863
864 665752 return mts_idx;
865 }
866
867 158156 static enum IntraPredMode derive_center_luma_intra_pred_mode(const VVCFrameContext *fc, const VVCSPS *sps, const VVCPPS *pps, const CodingUnit *cu)
868 {
869 158156 const int x_center = (cu->x0 + cu->cb_width / 2) >> sps->min_cb_log2_size_y;
870 158156 const int y_center = (cu->y0 + cu->cb_height / 2) >> sps->min_cb_log2_size_y;
871 158156 const int min_cb_width = pps->min_cb_width;
872 158156 const int intra_mip_flag = SAMPLE_CTB(fc->tab.imf, x_center, y_center);
873 158156 const int cu_pred_mode = SAMPLE_CTB(fc->tab.cpm[0], x_center, y_center);
874 158156 const int intra_pred_mode_y = SAMPLE_CTB(fc->tab.ipm, x_center, y_center);
875
876
2/2
✓ Branch 0 taken 33286 times.
✓ Branch 1 taken 124870 times.
158156 if (intra_mip_flag) {
877
4/4
✓ Branch 0 taken 8686 times.
✓ Branch 1 taken 24600 times.
✓ Branch 2 taken 244 times.
✓ Branch 3 taken 8442 times.
33286 if (cu->tree_type == SINGLE_TREE && sps->r->sps_chroma_format_idc == CHROMA_FORMAT_444)
878 244 return INTRA_INVALID;
879 33042 return INTRA_PLANAR;
880 }
881
3/4
✓ Branch 0 taken 124764 times.
✓ Branch 1 taken 106 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 124764 times.
124870 if (cu_pred_mode == MODE_IBC || cu_pred_mode == MODE_PLT)
882 106 return INTRA_DC;
883 124764 return intra_pred_mode_y;
884 }
885
886 158300 static void derive_chroma_intra_pred_mode(VVCLocalContext *lc,
887 const int cclm_mode_flag, const int cclm_mode_idx, const int intra_chroma_pred_mode)
888 {
889 158300 const VVCFrameContext *fc = lc->fc;
890 158300 CodingUnit *cu = lc->cu;
891 158300 const VVCSPS *sps = fc->ps.sps;
892 158300 const VVCPPS *pps = fc->ps.pps;
893 158300 const int x_cb = cu->x0 >> sps->min_cb_log2_size_y;
894 158300 const int y_cb = cu->y0 >> sps->min_cb_log2_size_y;
895 158300 const int min_cb_width = pps->min_cb_width;
896 158300 const int intra_mip_flag = SAMPLE_CTB(fc->tab.imf, x_cb, y_cb);
897 158300 enum IntraPredMode luma_intra_pred_mode = SAMPLE_CTB(fc->tab.ipm, x_cb, y_cb);
898
899
6/6
✓ Branch 0 taken 39665 times.
✓ Branch 1 taken 118635 times.
✓ Branch 2 taken 2125 times.
✓ Branch 3 taken 37540 times.
✓ Branch 4 taken 679 times.
✓ Branch 5 taken 1446 times.
158300 if (cu->tree_type == SINGLE_TREE && sps->r->sps_chroma_format_idc == CHROMA_FORMAT_444 &&
900
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 535 times.
679 intra_chroma_pred_mode == 4 && intra_mip_flag) {
901 144 cu->mip_chroma_direct_flag = 1;
902 144 cu->intra_pred_mode_c = luma_intra_pred_mode;
903 144 return;
904 }
905 158156 luma_intra_pred_mode = derive_center_luma_intra_pred_mode(fc, sps, pps, cu);
906
907
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 158156 times.
158156 if (cu->act_enabled_flag) {
908 cu->intra_pred_mode_c = luma_intra_pred_mode;
909 return;
910 }
911
2/2
✓ Branch 0 taken 62091 times.
✓ Branch 1 taken 96065 times.
158156 if (cclm_mode_flag) {
912 62091 cu->intra_pred_mode_c = INTRA_LT_CCLM + cclm_mode_idx;
913
2/2
✓ Branch 0 taken 73013 times.
✓ Branch 1 taken 23052 times.
96065 } else if (intra_chroma_pred_mode == 4){
914 73013 cu->intra_pred_mode_c = luma_intra_pred_mode;
915 } else {
916 const static IntraPredMode pred_mode_c[][4 + 1] = {
917 {INTRA_VDIAG, INTRA_PLANAR, INTRA_PLANAR, INTRA_PLANAR, INTRA_PLANAR},
918 {INTRA_VERT, INTRA_VDIAG, INTRA_VERT, INTRA_VERT, INTRA_VERT},
919 {INTRA_HORZ, INTRA_HORZ, INTRA_VDIAG, INTRA_HORZ, INTRA_HORZ},
920 {INTRA_DC, INTRA_DC, INTRA_DC, INTRA_VDIAG, INTRA_DC},
921 };
922 23052 const int modes[4] = {INTRA_PLANAR, INTRA_VERT, INTRA_HORZ, INTRA_DC};
923 int idx;
924
925 // This workaround is necessary to have 4:4:4 video decode correctly
926 // See VVC ticket https://jvet.hhi.fraunhofer.de/trac/vvc/ticket/1602
927 // and VTM source https://vcgit.hhi.fraunhofer.de/jvet/VVCSoftware_VTM/-/blob/master/source/Lib/CommonLib/UnitTools.cpp#L736
928
6/6
✓ Branch 0 taken 1942 times.
✓ Branch 1 taken 21110 times.
✓ Branch 2 taken 243 times.
✓ Branch 3 taken 1699 times.
✓ Branch 4 taken 43 times.
✓ Branch 5 taken 200 times.
23052 if (cu->tree_type == SINGLE_TREE && sps->r->sps_chroma_format_idc == CHROMA_FORMAT_444 && intra_mip_flag) {
929 43 idx = 4;
930 } else {
931
2/2
✓ Branch 0 taken 51473 times.
✓ Branch 1 taken 7752 times.
59225 for (idx = 0; idx < FF_ARRAY_ELEMS(modes); idx++) {
932
2/2
✓ Branch 0 taken 15257 times.
✓ Branch 1 taken 36216 times.
51473 if (modes[idx] == luma_intra_pred_mode)
933 15257 break;
934 }
935 }
936
937 23052 cu->intra_pred_mode_c = pred_mode_c[intra_chroma_pred_mode][idx];
938 }
939
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 158156 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
158156 if (sps->r->sps_chroma_format_idc == CHROMA_FORMAT_422 && cu->intra_pred_mode_c <= INTRA_VDIAG) {
940 const static int mode_map_422[INTRA_VDIAG + 1] = {
941 0, 1, 61, 62, 63, 64, 65, 66, 2, 3, 5, 6, 8, 10, 12, 13,
942 14, 16, 18, 20, 22, 23, 24, 26, 28, 30, 31, 33, 34, 35, 36, 37,
943 38, 39, 40, 41, 41, 42, 43, 43, 44, 44, 45, 45, 46, 47, 48, 48,
944 49, 49, 50, 51, 51, 52, 52, 53, 54, 55, 55, 56, 56, 57, 57, 58,
945 59, 59, 60,
946 };
947 cu->intra_pred_mode_c = mode_map_422[cu->intra_pred_mode_c];
948 }
949 }
950
951 410661 static void intra_luma_pred_modes(VVCLocalContext *lc)
952 {
953 410661 VVCFrameContext *fc = lc->fc;
954 410661 const VVCSPS *sps = fc->ps.sps;
955 410661 const VVCPPS *pps = fc->ps.pps;
956 410661 CodingUnit *cu = lc->cu;
957 410661 const int log2_min_cb_size = sps->min_cb_log2_size_y;
958 410661 const int x0 = cu->x0;
959 410661 const int y0 = cu->y0;
960 410661 const int x_cb = x0 >> log2_min_cb_size;
961 410661 const int y_cb = y0 >> log2_min_cb_size;
962 410661 const int cb_width = cu->cb_width;
963 410661 const int cb_height = cu->cb_height;
964
965 410661 cu->intra_luma_ref_idx = 0;
966
6/6
✓ Branch 0 taken 22042 times.
✓ Branch 1 taken 388619 times.
✓ Branch 2 taken 21441 times.
✓ Branch 3 taken 601 times.
✓ Branch 4 taken 21430 times.
✓ Branch 5 taken 11 times.
410661 if (sps->r->sps_bdpcm_enabled_flag && cb_width <= sps->max_ts_size && cb_height <= sps->max_ts_size)
967 21430 cu->bdpcm_flag[LUMA] = ff_vvc_intra_bdpcm_luma_flag(lc);
968
2/2
✓ Branch 0 taken 34 times.
✓ Branch 1 taken 410627 times.
410661 if (cu->bdpcm_flag[LUMA]) {
969
2/2
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 16 times.
34 cu->intra_pred_mode_y = ff_vvc_intra_bdpcm_luma_dir_flag(lc) ? INTRA_VERT : INTRA_HORZ;
970 } else {
971
2/2
✓ Branch 0 taken 311631 times.
✓ Branch 1 taken 98996 times.
410627 if (sps->r->sps_mip_enabled_flag)
972 311631 cu->intra_mip_flag = ff_vvc_intra_mip_flag(lc, fc->tab.imf);
973
2/2
✓ Branch 0 taken 74951 times.
✓ Branch 1 taken 335676 times.
410627 if (cu->intra_mip_flag) {
974 74951 int intra_mip_transposed_flag = ff_vvc_intra_mip_transposed_flag(lc);
975 74951 int intra_mip_mode = ff_vvc_intra_mip_mode(lc);
976 74951 int x = y_cb * pps->min_cb_width + x_cb;
977
2/2
✓ Branch 0 taken 211095 times.
✓ Branch 1 taken 74951 times.
286046 for (int y = 0; y < (cb_height>>log2_min_cb_size); y++) {
978 211095 int width = cb_width>>log2_min_cb_size;
979 211095 memset(&fc->tab.imf[x], cu->intra_mip_flag, width);
980 211095 fc->tab.imtf[x] = intra_mip_transposed_flag;
981 211095 fc->tab.imm[x] = intra_mip_mode;
982 211095 x += pps->min_cb_width;
983 }
984 74951 cu->intra_pred_mode_y = intra_mip_mode;
985 } else {
986 335676 int intra_subpartitions_mode_flag = 0;
987
4/4
✓ Branch 0 taken 332183 times.
✓ Branch 1 taken 3493 times.
✓ Branch 2 taken 302809 times.
✓ Branch 3 taken 29374 times.
335676 if (sps->r->sps_mrl_enabled_flag && ((y0 % sps->ctb_size_y) > 0))
988 302809 cu->intra_luma_ref_idx = ff_vvc_intra_luma_ref_idx(lc);
989
4/4
✓ Branch 0 taken 332183 times.
✓ Branch 1 taken 3493 times.
✓ Branch 2 taken 309320 times.
✓ Branch 3 taken 22863 times.
335676 if (sps->r->sps_isp_enabled_flag && !cu->intra_luma_ref_idx &&
990
2/4
✓ Branch 0 taken 309320 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 309320 times.
✗ Branch 3 not taken.
309320 (cb_width <= sps->max_tb_size_y && cb_height <= sps->max_tb_size_y) &&
991
2/2
✓ Branch 0 taken 273413 times.
✓ Branch 1 taken 35907 times.
309320 (cb_width * cb_height > MIN_TU_SIZE * MIN_TU_SIZE) &&
992
1/2
✓ Branch 0 taken 273413 times.
✗ Branch 1 not taken.
273413 !cu->act_enabled_flag)
993 273413 intra_subpartitions_mode_flag = ff_vvc_intra_subpartitions_mode_flag(lc);
994
4/4
✓ Branch 0 taken 70637 times.
✓ Branch 1 taken 265039 times.
✓ Branch 2 taken 16040 times.
✓ Branch 3 taken 54597 times.
335676 if (!(x0 & 63) && !(y0 & 63))
995 16040 TAB_ISPMF(fc, x0, y0) = intra_subpartitions_mode_flag;
996 335676 cu->isp_split_type = ff_vvc_isp_split_type(lc, intra_subpartitions_mode_flag);
997 335676 cu->num_intra_subpartitions = get_num_intra_subpartitions(cu->isp_split_type, cb_width, cb_height);
998 335676 cu->intra_pred_mode_y = luma_intra_pred_mode(lc, intra_subpartitions_mode_flag);
999 }
1000 }
1001 410661 set_cb_tab(lc, fc->tab.ipm, cu->intra_pred_mode_y);
1002 410661 }
1003
1004 158303 static void intra_chroma_pred_modes(VVCLocalContext *lc)
1005 {
1006 158303 const VVCSPS *sps = lc->fc->ps.sps;
1007 158303 CodingUnit *cu = lc->cu;
1008 158303 const int hs = sps->hshift[CHROMA];
1009 158303 const int vs = sps->vshift[CHROMA];
1010
1011 158303 cu->mip_chroma_direct_flag = 0;
1012
2/2
✓ Branch 0 taken 20019 times.
✓ Branch 1 taken 138284 times.
158303 if (sps->r->sps_bdpcm_enabled_flag &&
1013
2/2
✓ Branch 0 taken 19046 times.
✓ Branch 1 taken 973 times.
20019 (cu->cb_width >> hs) <= sps->max_ts_size &&
1014
2/2
✓ Branch 0 taken 18703 times.
✓ Branch 1 taken 343 times.
19046 (cu->cb_height >> vs) <= sps->max_ts_size) {
1015 18703 cu->bdpcm_flag[CB] = cu->bdpcm_flag[CR] = ff_vvc_intra_bdpcm_chroma_flag(lc);
1016 }
1017
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 158300 times.
158303 if (cu->bdpcm_flag[CHROMA]) {
1018
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2 times.
3 cu->intra_pred_mode_c = ff_vvc_intra_bdpcm_chroma_dir_flag(lc) ? INTRA_VERT : INTRA_HORZ;
1019 } else {
1020 158300 const int cclm_enabled = get_cclm_enabled(lc, cu->x0, cu->y0);
1021 158300 int cclm_mode_flag = 0;
1022 158300 int cclm_mode_idx = 0;
1023 158300 int intra_chroma_pred_mode = 0;
1024
1025
2/2
✓ Branch 0 taken 147077 times.
✓ Branch 1 taken 11223 times.
158300 if (cclm_enabled)
1026 147077 cclm_mode_flag = ff_vvc_cclm_mode_flag(lc);
1027
1028
2/2
✓ Branch 0 taken 62091 times.
✓ Branch 1 taken 96209 times.
158300 if (cclm_mode_flag)
1029 62091 cclm_mode_idx = ff_vvc_cclm_mode_idx(lc);
1030 else
1031 96209 intra_chroma_pred_mode = ff_vvc_intra_chroma_pred_mode(lc);
1032 158300 derive_chroma_intra_pred_mode(lc, cclm_mode_flag, cclm_mode_idx, intra_chroma_pred_mode);
1033 }
1034 158303 }
1035
1036 927799 static PredMode pred_mode_decode(VVCLocalContext *lc,
1037 const VVCTreeType tree_type,
1038 const VVCModeType mode_type)
1039 {
1040 927799 const VVCFrameContext *fc = lc->fc;
1041 927799 CodingUnit *cu = lc->cu;
1042 927799 const VVCSPS *sps = fc->ps.sps;
1043 927799 const H266RawSliceHeader *rsh = lc->sc->sh.r;
1044 927799 const int ch_type = tree_type == DUAL_TREE_CHROMA ? 1 : 0;
1045
4/4
✓ Branch 0 taken 164203 times.
✓ Branch 1 taken 763596 times.
✓ Branch 2 taken 48262 times.
✓ Branch 3 taken 115941 times.
927799 const int is_4x4 = cu->cb_width == 4 && cu->cb_height == 4;
1046 int pred_mode_flag;
1047 int pred_mode_ibc_flag;
1048 PredMode pred_mode;
1049
1050 927799 cu->skip_flag = 0;
1051
4/4
✓ Branch 0 taken 451751 times.
✓ Branch 1 taken 476048 times.
✓ Branch 2 taken 2408 times.
✓ Branch 3 taken 449343 times.
927799 if (!IS_I(rsh) || sps->r->sps_ibc_enabled_flag) {
1052
4/4
✓ Branch 0 taken 456479 times.
✓ Branch 1 taken 21977 times.
✓ Branch 2 taken 2153 times.
✓ Branch 3 taken 454326 times.
478456 const int is_128 = cu->cb_width == 128 || cu->cb_height == 128;
1053
4/4
✓ Branch 0 taken 470100 times.
✓ Branch 1 taken 8356 times.
✓ Branch 2 taken 461892 times.
✓ Branch 3 taken 8208 times.
478456 if (tree_type != DUAL_TREE_CHROMA &&
1054
2/2
✓ Branch 0 taken 18718 times.
✓ Branch 1 taken 443174 times.
461892 ((!is_4x4 && mode_type != MODE_TYPE_INTRA) ||
1055
3/4
✓ Branch 0 taken 436 times.
✓ Branch 1 taken 26490 times.
✓ Branch 2 taken 436 times.
✗ Branch 3 not taken.
26926 (sps->r->sps_ibc_enabled_flag && !is_128))) {
1056 443610 cu->skip_flag = ff_vvc_cu_skip_flag(lc, fc->tab.skip);
1057 }
1058
1059
6/6
✓ Branch 0 taken 470248 times.
✓ Branch 1 taken 8208 times.
✓ Branch 2 taken 443334 times.
✓ Branch 3 taken 26914 times.
✓ Branch 4 taken 2112 times.
✓ Branch 5 taken 441222 times.
478456 if (is_4x4 || mode_type == MODE_TYPE_INTRA || IS_I(rsh)) {
1060 37234 pred_mode_flag = 1;
1061
4/4
✓ Branch 0 taken 385582 times.
✓ Branch 1 taken 55640 times.
✓ Branch 2 taken 204940 times.
✓ Branch 3 taken 180642 times.
441222 } else if (mode_type == MODE_TYPE_INTER || cu->skip_flag) {
1062 260580 pred_mode_flag = 0;
1063 } else {
1064 180642 pred_mode_flag = ff_vvc_pred_mode_flag(lc, ch_type);
1065 }
1066 478456 pred_mode = pred_mode_flag ? MODE_INTRA : MODE_INTER;
1067
1068
4/4
✓ Branch 0 taken 2408 times.
✓ Branch 1 taken 476048 times.
✓ Branch 2 taken 96 times.
✓ Branch 3 taken 2312 times.
478456 if (((IS_I(rsh) && !cu->skip_flag) ||
1069
6/6
✓ Branch 0 taken 476048 times.
✓ Branch 1 taken 96 times.
✓ Branch 2 taken 79091 times.
✓ Branch 3 taken 396957 times.
✓ Branch 4 taken 71179 times.
✓ Branch 5 taken 7912 times.
476144 (!IS_I(rsh) && (pred_mode != MODE_INTRA ||
1070
6/6
✓ Branch 0 taken 26914 times.
✓ Branch 1 taken 44265 times.
✓ Branch 2 taken 34802 times.
✓ Branch 3 taken 24 times.
✓ Branch 4 taken 409941 times.
✓ Branch 5 taken 24130 times.
478360 ((is_4x4 || mode_type == MODE_TYPE_INTRA) && !cu->skip_flag)))) &&
1071
6/6
✓ Branch 0 taken 354301 times.
✓ Branch 1 taken 55640 times.
✓ Branch 2 taken 3239 times.
✓ Branch 3 taken 351062 times.
✓ Branch 4 taken 3032 times.
✓ Branch 5 taken 207 times.
409941 !is_128 && mode_type != MODE_TYPE_INTER && sps->r->sps_ibc_enabled_flag &&
1072 tree_type != DUAL_TREE_CHROMA) {
1073 3032 pred_mode_ibc_flag = ff_vvc_pred_mode_ibc_flag(lc, ch_type);
1074
6/6
✓ Branch 0 taken 229690 times.
✓ Branch 1 taken 245734 times.
✓ Branch 2 taken 229663 times.
✓ Branch 3 taken 27 times.
✓ Branch 4 taken 15 times.
✓ Branch 5 taken 229648 times.
475424 } else if (cu->skip_flag && (is_4x4 || mode_type == MODE_TYPE_INTRA)) {
1075 42 pred_mode_ibc_flag = 1;
1076
6/6
✓ Branch 0 taken 451252 times.
✓ Branch 1 taken 24130 times.
✓ Branch 2 taken 395612 times.
✓ Branch 3 taken 55640 times.
✓ Branch 4 taken 8356 times.
✓ Branch 5 taken 387256 times.
475382 } else if (is_128 || mode_type == MODE_TYPE_INTER || tree_type == DUAL_TREE_CHROMA) {
1077 88126 pred_mode_ibc_flag = 0;
1078 } else {
1079
2/2
✓ Branch 0 taken 78 times.
✓ Branch 1 taken 387178 times.
387256 pred_mode_ibc_flag = (IS_I(rsh)) ? sps->r->sps_ibc_enabled_flag : 0;
1080 }
1081
2/2
✓ Branch 0 taken 1582 times.
✓ Branch 1 taken 476874 times.
478456 if (pred_mode_ibc_flag)
1082 1582 pred_mode = MODE_IBC;
1083 478456 return pred_mode;
1084 } else {
1085 449343 return MODE_INTRA;
1086 }
1087 }
1088
1089 665752 static void sbt_info(VVCLocalContext *lc, const VVCSPS *sps)
1090 {
1091 665752 CodingUnit *cu = lc->cu;
1092 665752 const int cb_width = cu->cb_width;
1093 665752 const int cb_height = cu->cb_height;
1094
1095
6/6
✓ Branch 0 taken 135689 times.
✓ Branch 1 taken 530063 times.
✓ Branch 2 taken 132984 times.
✓ Branch 3 taken 2705 times.
✓ Branch 4 taken 117891 times.
✓ Branch 5 taken 15093 times.
665752 if (cu->pred_mode == MODE_INTER && sps->r->sps_sbt_enabled_flag && !cu->ciip_flag
1096
4/4
✓ Branch 0 taken 117209 times.
✓ Branch 1 taken 682 times.
✓ Branch 2 taken 116966 times.
✓ Branch 3 taken 243 times.
117891 && cb_width <= sps->max_tb_size_y && cb_height <= sps->max_tb_size_y) {
1097 116966 const int sbt_ver_h = cb_width >= 8;
1098 116966 const int sbt_hor_h = cb_height >= 8;
1099 116966 cu->sbt_flag = 0;
1100
3/4
✓ Branch 0 taken 16948 times.
✓ Branch 1 taken 100018 times.
✓ Branch 2 taken 16948 times.
✗ Branch 3 not taken.
116966 if (sbt_ver_h || sbt_hor_h)
1101 116966 cu->sbt_flag = ff_vvc_sbt_flag(lc);
1102
2/2
✓ Branch 0 taken 37306 times.
✓ Branch 1 taken 79660 times.
116966 if (cu->sbt_flag) {
1103 37306 const int sbt_ver_q = cb_width >= 16;
1104 37306 const int sbt_hor_q = cb_height >= 16;
1105 37306 int cu_sbt_quad_flag = 0;
1106
1107
7/8
✓ Branch 0 taken 5966 times.
✓ Branch 1 taken 31340 times.
✓ Branch 2 taken 5966 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 20658 times.
✓ Branch 5 taken 16648 times.
✓ Branch 6 taken 10919 times.
✓ Branch 7 taken 9739 times.
37306 if ((sbt_ver_h || sbt_hor_h) && (sbt_ver_q || sbt_hor_q))
1108 27567 cu_sbt_quad_flag = ff_vvc_sbt_quad_flag(lc);
1109
2/2
✓ Branch 0 taken 9645 times.
✓ Branch 1 taken 27661 times.
37306 if (cu_sbt_quad_flag) {
1110 9645 cu->sbt_horizontal_flag = sbt_hor_q;
1111
4/4
✓ Branch 0 taken 6106 times.
✓ Branch 1 taken 3539 times.
✓ Branch 2 taken 3101 times.
✓ Branch 3 taken 3005 times.
9645 if (sbt_ver_q && sbt_hor_q)
1112 3101 cu->sbt_horizontal_flag = ff_vvc_sbt_horizontal_flag(lc);
1113 } else {
1114 27661 cu->sbt_horizontal_flag = sbt_hor_h;
1115
4/4
✓ Branch 0 taken 23046 times.
✓ Branch 1 taken 4615 times.
✓ Branch 2 taken 19107 times.
✓ Branch 3 taken 3939 times.
27661 if (sbt_ver_h && sbt_hor_h)
1116 19107 cu->sbt_horizontal_flag = ff_vvc_sbt_horizontal_flag(lc);
1117 }
1118 37306 cu->sbt_pos_flag = ff_vvc_sbt_pos_flag(lc);
1119
1120 {
1121
2/2
✓ Branch 0 taken 9645 times.
✓ Branch 1 taken 27661 times.
37306 const int sbt_min = cu_sbt_quad_flag ? 1 : 2;
1122
2/2
✓ Branch 0 taken 17766 times.
✓ Branch 1 taken 19540 times.
37306 lc->parse.sbt_num_fourths_tb0 = cu->sbt_pos_flag ? (4 - sbt_min) : sbt_min;
1123 }
1124 }
1125 }
1126 665752 }
1127
1128 262047 static int skipped_transform_tree_unit(VVCLocalContext *lc)
1129 {
1130 262047 const H266RawSPS *rsps = lc->fc->ps.sps->r;
1131 262047 const CodingUnit *cu = lc->cu;
1132 int ret;
1133
1134
1/2
✓ Branch 0 taken 262047 times.
✗ Branch 1 not taken.
262047 if (cu->tree_type != DUAL_TREE_CHROMA)
1135 262047 set_qp_y(lc, cu->x0, cu->y0, 0);
1136
4/4
✓ Branch 0 taken 245536 times.
✓ Branch 1 taken 16511 times.
✓ Branch 2 taken 244740 times.
✓ Branch 3 taken 796 times.
262047 if (rsps->sps_chroma_format_idc && cu->tree_type != DUAL_TREE_LUMA)
1137 244740 set_qp_c(lc);
1138 262047 ret = skipped_transform_tree(lc, cu->x0, cu->y0, cu->cb_width, cu->cb_height);
1139
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 262047 times.
262047 if (ret < 0)
1140 return ret;
1141 262047 return 0;
1142 }
1143
1144 927799 static void set_cb_pos(const VVCFrameContext *fc, const CodingUnit *cu)
1145 {
1146 927799 const VVCSPS *sps = fc->ps.sps;
1147 927799 const VVCPPS *pps = fc->ps.pps;
1148 927799 const int log2_min_cb_size = sps->min_cb_log2_size_y;
1149 927799 const int x_cb = cu->x0 >> log2_min_cb_size;
1150 927799 const int y_cb = cu->y0 >> log2_min_cb_size;
1151 927799 const int ch_type = cu->ch_type;
1152 int x, y;
1153
1154 927799 x = y_cb * pps->min_cb_width + x_cb;
1155
2/2
✓ Branch 0 taken 4308925 times.
✓ Branch 1 taken 927799 times.
5236724 for (y = 0; y < (cu->cb_height >> log2_min_cb_size); y++) {
1156 4308925 const int width = cu->cb_width >> log2_min_cb_size;
1157
1158
2/2
✓ Branch 0 taken 43981248 times.
✓ Branch 1 taken 4308925 times.
48290173 for (int i = 0; i < width; i++) {
1159 43981248 fc->tab.cb_pos_x[ch_type][x + i] = cu->x0;
1160 43981248 fc->tab.cb_pos_y[ch_type][x + i] = cu->y0;
1161 }
1162 4308925 memset(&fc->tab.cb_width[ch_type][x], cu->cb_width, width);
1163 4308925 memset(&fc->tab.cb_height[ch_type][x], cu->cb_height, width);
1164 4308925 memset(&fc->tab.cqt_depth[ch_type][x], cu->cqt_depth, width);
1165
1166 4308925 x += pps->min_cb_width;
1167 }
1168 927799 }
1169
1170 927799 static CodingUnit* alloc_cu(VVCLocalContext *lc, const int x0, const int y0)
1171 {
1172 927799 VVCFrameContext *fc = lc->fc;
1173 927799 const VVCSPS *sps = fc->ps.sps;
1174 927799 const VVCPPS *pps = fc->ps.pps;
1175 927799 const int rx = x0 >> sps->ctb_log2_size_y;
1176 927799 const int ry = y0 >> sps->ctb_log2_size_y;
1177 927799 CTU *ctu = fc->tab.ctus + ry * pps->ctb_width + rx;
1178 927799 CodingUnit *cu = ff_refstruct_pool_get(fc->cu_pool);
1179
1180
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 927799 times.
927799 if (!cu)
1181 return NULL;
1182 927799 cu->next = NULL;
1183
1184
2/2
✓ Branch 0 taken 884616 times.
✓ Branch 1 taken 43183 times.
927799 if (lc->cu)
1185 884616 lc->cu->next = cu;
1186 else
1187 43183 ctu->cus = cu;
1188 927799 lc->cu = cu;
1189
1190 927799 return cu;
1191 }
1192
1193 927799 static CodingUnit* add_cu(VVCLocalContext *lc, const int x0, const int y0,
1194 const int cb_width, const int cb_height, const int cqt_depth, const VVCTreeType tree_type)
1195 {
1196 927799 VVCFrameContext *fc = lc->fc;
1197 927799 const int ch_type = tree_type == DUAL_TREE_CHROMA ? 1 : 0;
1198 927799 CodingUnit *cu = alloc_cu(lc, x0, y0);
1199
1200
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 927799 times.
927799 if (!cu)
1201 return NULL;
1202
1203 927799 memset(&cu->pu, 0, sizeof(cu->pu));
1204
1205 927799 lc->parse.prev_tu_cbf_y = 0;
1206
1207 927799 cu->sbt_flag = 0;
1208 927799 cu->act_enabled_flag = 0;
1209
1210 927799 cu->tree_type = tree_type;
1211 927799 cu->x0 = x0;
1212 927799 cu->y0 = y0;
1213 927799 cu->cb_width = cb_width;
1214 927799 cu->cb_height = cb_height;
1215 927799 cu->ch_type = ch_type;
1216 927799 cu->cqt_depth = cqt_depth;
1217 927799 cu->tus.head = cu->tus.tail = NULL;
1218 927799 cu->bdpcm_flag[LUMA] = cu->bdpcm_flag[CB] = cu->bdpcm_flag[CR] = 0;
1219 927799 cu->isp_split_type = ISP_NO_SPLIT;
1220 927799 cu->intra_mip_flag = 0;
1221 927799 cu->ciip_flag = 0;
1222 927799 cu->coded_flag = 1;
1223 927799 cu->num_intra_subpartitions = 1;
1224 927799 cu->pu.dmvr_flag = 0;
1225
1226 927799 set_cb_pos(fc, cu);
1227 927799 return cu;
1228 }
1229
1230 927799 static void set_cu_tabs(const VVCLocalContext *lc, const CodingUnit *cu)
1231 {
1232 927799 const VVCFrameContext *fc = lc->fc;
1233 927799 const TransformUnit *tu = cu->tus.head;
1234
1235
2/2
✓ Branch 0 taken 809161 times.
✓ Branch 1 taken 118638 times.
927799 if (cu->tree_type != DUAL_TREE_CHROMA) {
1236 809161 set_cb_tab(lc, fc->tab.cpm[LUMA], cu->pred_mode);
1237 809161 set_cb_tab(lc, fc->tab.skip, cu->skip_flag);
1238 }
1239
4/4
✓ Branch 0 taken 894252 times.
✓ Branch 1 taken 33547 times.
✓ Branch 2 taken 534743 times.
✓ Branch 3 taken 359509 times.
927799 if (fc->ps.sps->r->sps_chroma_format_idc && cu->tree_type != DUAL_TREE_LUMA)
1240 534743 set_cb_tab(lc, fc->tab.cpm[CHROMA], cu->pred_mode);
1241
1242
2/2
✓ Branch 0 taken 1141528 times.
✓ Branch 1 taken 927799 times.
2069327 while (tu) {
1243
2/2
✓ Branch 0 taken 2292160 times.
✓ Branch 1 taken 1141528 times.
3433688 for (int j = 0; j < tu->nb_tbs; j++) {
1244 2292160 const TransformBlock *tb = tu->tbs + j;
1245
2/2
✓ Branch 0 taken 1269270 times.
✓ Branch 1 taken 1022890 times.
2292160 if (tb->c_idx != LUMA)
1246 1269270 set_qp_c_tab(lc, tu, tb);
1247
4/4
✓ Branch 0 taken 1657525 times.
✓ Branch 1 taken 634635 times.
✓ Branch 2 taken 37 times.
✓ Branch 3 taken 1657488 times.
2292160 if (tb->c_idx != CR && cu->bdpcm_flag[tb->c_idx])
1248 37 set_tb_tab(fc->tab.pcmf[tb->c_idx], 1, fc, tb);
1249 }
1250 1141528 tu = tu->next;
1251 }
1252 927799 }
1253
1254 //8.5.2.7 Derivation process for merge motion vector difference
1255 54381 static void derive_mmvd(const VVCLocalContext *lc, MvField *mvf, const Mv *mmvd_offset)
1256 {
1257 54381 const SliceContext *sc = lc->sc;
1258 Mv mmvd[2];
1259
1260
2/2
✓ Branch 0 taken 22866 times.
✓ Branch 1 taken 31515 times.
54381 if (mvf->pred_flag == PF_BI) {
1261 22866 const RefPicList *rpl = sc->rpl;
1262 22866 const int poc = lc->fc->ps.ph.poc;
1263 22866 const int diff[] = {
1264 22866 poc - rpl[L0].refs[mvf->ref_idx[L0]].poc,
1265 22866 poc - rpl[L1].refs[mvf->ref_idx[L1]].poc
1266 };
1267
4/4
✓ Branch 0 taken 21698 times.
✓ Branch 1 taken 1168 times.
✓ Branch 2 taken 8539 times.
✓ Branch 3 taken 14327 times.
22866 const int sign = FFSIGN(diff[0]) != FFSIGN(diff[1]);
1268
1269
2/2
✓ Branch 0 taken 7861 times.
✓ Branch 1 taken 15005 times.
22866 if (diff[0] == diff[1]) {
1270 7861 mmvd[1] = mmvd[0] = *mmvd_offset;
1271 }
1272 else {
1273 15005 const int i = FFABS(diff[0]) < FFABS(diff[1]);
1274 15005 const int o = !i;
1275 15005 mmvd[i] = *mmvd_offset;
1276
2/4
✓ Branch 0 taken 15005 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15005 times.
✗ Branch 3 not taken.
15005 if (!rpl[L0].refs[mvf->ref_idx[L0]].is_lt && !rpl[L1].refs[mvf->ref_idx[L1]].is_lt) {
1277 15005 ff_vvc_mv_scale(&mmvd[o], mmvd_offset, diff[i], diff[o]);
1278 }
1279 else {
1280 mmvd[o].x = sign ? -mmvd[i].x : mmvd[i].x;
1281 mmvd[o].y = sign ? -mmvd[i].y : mmvd[i].y;
1282 }
1283 }
1284 22866 mvf->mv[0].x += mmvd[0].x;
1285 22866 mvf->mv[0].y += mmvd[0].y;
1286 22866 mvf->mv[1].x += mmvd[1].x;
1287 22866 mvf->mv[1].y += mmvd[1].y;
1288 } else {
1289 31515 const int idx = mvf->pred_flag - PF_L0;
1290 31515 mvf->mv[idx].x += mmvd_offset->x;
1291 31515 mvf->mv[idx].y += mmvd_offset->y;
1292 }
1293
1294 54381 }
1295
1296 265675 static void mvf_to_mi(const MvField *mvf, MotionInfo *mi)
1297 {
1298 265675 mi->pred_flag = mvf->pred_flag;
1299 265675 mi->bcw_idx = mvf->bcw_idx;
1300 265675 mi->hpel_if_idx = mvf->hpel_if_idx;
1301
2/2
✓ Branch 0 taken 531350 times.
✓ Branch 1 taken 265675 times.
797025 for (int i = 0; i < 2; i++) {
1302 531350 const PredFlag mask = i + 1;
1303
2/2
✓ Branch 0 taken 418479 times.
✓ Branch 1 taken 112871 times.
531350 if (mvf->pred_flag & mask) {
1304 418479 mi->mv[i][0] = mvf->mv[i];
1305 418479 mi->ref_idx[i] = mvf->ref_idx[i];
1306 }
1307 }
1308 265675 }
1309
1310 265675 static void mv_merge_refine_pred_flag(MvField *mvf, const int width, const int height)
1311 {
1312
4/4
✓ Branch 0 taken 157573 times.
✓ Branch 1 taken 108102 times.
✓ Branch 2 taken 4769 times.
✓ Branch 3 taken 152804 times.
265675 if (mvf->pred_flag == PF_BI && (width + height) == 12) {
1313 4769 mvf->pred_flag = PF_L0;
1314 4769 mvf->bcw_idx = 0;
1315 }
1316 265675 }
1317
1318 // subblock-based inter prediction data
1319 48721 static void merge_data_subblock(VVCLocalContext *lc)
1320 {
1321 48721 const VVCFrameContext *fc = lc->fc;
1322 48721 const VVCPH *ph = &fc->ps.ph;
1323 48721 CodingUnit* cu = lc->cu;
1324 48721 PredictionUnit *pu = &cu->pu;
1325 48721 int merge_subblock_idx = 0;
1326
1327 48721 set_cb_tab(lc, fc->tab.msf, pu->merge_subblock_flag);
1328
1/2
✓ Branch 0 taken 48721 times.
✗ Branch 1 not taken.
48721 if (ph->max_num_subblock_merge_cand > 1) {
1329 48721 merge_subblock_idx = ff_vvc_merge_subblock_idx(lc, ph->max_num_subblock_merge_cand);
1330 }
1331 48721 ff_vvc_sb_mv_merge_mode(lc, merge_subblock_idx, pu);
1332 48721 }
1333
1334 250158 static void merge_data_regular(VVCLocalContext *lc)
1335 {
1336 250158 const VVCFrameContext *fc = lc->fc;
1337 250158 const VVCSPS *sps = fc->ps.sps;
1338 250158 const VVCPH *ph = &fc->ps.ph;
1339 250158 const CodingUnit* cu = lc->cu;
1340 250158 PredictionUnit *pu = &lc->cu->pu;
1341 250158 int merge_idx = 0;
1342 Mv mmvd_offset;
1343 MvField mvf;
1344
1345
1/2
✓ Branch 0 taken 250158 times.
✗ Branch 1 not taken.
250158 if (sps->r->sps_mmvd_enabled_flag)
1346 250158 pu->mmvd_merge_flag = ff_vvc_mmvd_merge_flag(lc);
1347
2/2
✓ Branch 0 taken 54381 times.
✓ Branch 1 taken 195777 times.
250158 if (pu->mmvd_merge_flag) {
1348 54381 int mmvd_cand_flag = 0;
1349
1/2
✓ Branch 0 taken 54381 times.
✗ Branch 1 not taken.
54381 if (sps->max_num_merge_cand > 1)
1350 54381 mmvd_cand_flag = ff_vvc_mmvd_cand_flag(lc);
1351 54381 ff_vvc_mmvd_offset_coding(lc, &mmvd_offset, ph->r->ph_mmvd_fullpel_only_flag);
1352 54381 merge_idx = mmvd_cand_flag;
1353
1/2
✓ Branch 0 taken 195777 times.
✗ Branch 1 not taken.
195777 } else if (sps->max_num_merge_cand > 1) {
1354 195777 merge_idx = ff_vvc_merge_idx(lc);
1355 }
1356 250158 ff_vvc_luma_mv_merge_mode(lc, merge_idx, 0, &mvf);
1357
2/2
✓ Branch 0 taken 54381 times.
✓ Branch 1 taken 195777 times.
250158 if (pu->mmvd_merge_flag)
1358 54381 derive_mmvd(lc, &mvf, &mmvd_offset);
1359 250158 mv_merge_refine_pred_flag(&mvf, cu->cb_width, cu->cb_height);
1360 250158 ff_vvc_store_mvf(lc, &mvf);
1361 250158 mvf_to_mi(&mvf, &pu->mi);
1362 250158 }
1363
1364 40254 static int ciip_flag_decode(VVCLocalContext *lc, const int ciip_avaiable, const int gpm_avaiable, const int is_128)
1365 {
1366 40254 const VVCFrameContext *fc = lc->fc;
1367 40254 const VVCSPS *sps = fc->ps.sps;
1368 40254 const CodingUnit *cu = lc->cu;
1369
1370
4/4
✓ Branch 0 taken 25226 times.
✓ Branch 1 taken 15028 times.
✓ Branch 2 taken 18681 times.
✓ Branch 3 taken 6545 times.
40254 if (ciip_avaiable && gpm_avaiable)
1371 18681 return ff_vvc_ciip_flag(lc);
1372
3/4
✓ Branch 0 taken 6545 times.
✓ Branch 1 taken 15028 times.
✓ Branch 2 taken 6545 times.
✗ Branch 3 not taken.
21573 return sps->r->sps_ciip_enabled_flag && !cu->skip_flag &&
1373
2/4
✓ Branch 0 taken 21573 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6545 times.
✗ Branch 3 not taken.
43146 !is_128 && (cu->cb_width * cu->cb_height >= 64);
1374 }
1375
1376 24737 static void merge_data_gpm(VVCLocalContext *lc)
1377 {
1378 24737 const VVCFrameContext *fc = lc->fc;
1379 24737 const VVCSPS *sps = fc->ps.sps;
1380 24737 PredictionUnit *pu = &lc->cu->pu;
1381 int merge_gpm_idx[2];
1382
1383 24737 pu->merge_gpm_flag = 1;
1384 24737 pu->gpm_partition_idx = ff_vvc_merge_gpm_partition_idx(lc);
1385 24737 merge_gpm_idx[0] = ff_vvc_merge_gpm_idx(lc, 0);
1386 24737 merge_gpm_idx[1] = 0;
1387
1/2
✓ Branch 0 taken 24737 times.
✗ Branch 1 not taken.
24737 if (sps->max_num_gpm_merge_cand > 2)
1388 24737 merge_gpm_idx[1] = ff_vvc_merge_gpm_idx(lc, 1);
1389
1390 24737 ff_vvc_luma_mv_merge_gpm(lc, merge_gpm_idx, pu->gpm_mv);
1391 24737 ff_vvc_store_gpm_mvf(lc, pu);
1392 24737 }
1393
1394 15517 static void merge_data_ciip(VVCLocalContext *lc)
1395 {
1396 15517 const VVCFrameContext* fc = lc->fc;
1397 15517 const VVCSPS* sps = fc->ps.sps;
1398 15517 CodingUnit *cu = lc->cu;
1399 15517 MotionInfo *mi = &cu->pu.mi;
1400 15517 int merge_idx = 0;
1401 MvField mvf;
1402
1403
1/2
✓ Branch 0 taken 15517 times.
✗ Branch 1 not taken.
15517 if (sps->max_num_merge_cand > 1)
1404 15517 merge_idx = ff_vvc_merge_idx(lc);
1405 15517 ff_vvc_luma_mv_merge_mode(lc, merge_idx, 1, &mvf);
1406 15517 mv_merge_refine_pred_flag(&mvf, cu->cb_width, cu->cb_height);
1407 15517 ff_vvc_store_mvf(lc, &mvf);
1408 15517 mvf_to_mi(&mvf, mi);
1409 15517 cu->intra_pred_mode_y = cu->intra_pred_mode_c = INTRA_PLANAR;
1410 15517 cu->intra_luma_ref_idx = 0;
1411 15517 cu->intra_mip_flag = 0;
1412 15517 }
1413
1414 // block-based inter prediction data
1415 290412 static void merge_data_block(VVCLocalContext *lc)
1416 {
1417 290412 const VVCFrameContext* fc = lc->fc;
1418 290412 const VVCSPS *sps = fc->ps.sps;
1419 290412 const H266RawSliceHeader *rsh = lc->sc->sh.r;
1420 290412 CodingUnit *cu = lc->cu;
1421 290412 const int cb_width = cu->cb_width;
1422 290412 const int cb_height = cu->cb_height;
1423
4/4
✓ Branch 0 taken 273143 times.
✓ Branch 1 taken 17269 times.
✓ Branch 2 taken 1327 times.
✓ Branch 3 taken 271816 times.
290412 const int is_128 = cb_width == 128 || cb_height == 128;
1424 871236 const int ciip_avaiable = sps->r->sps_ciip_enabled_flag &&
1425
5/6
✓ Branch 0 taken 290412 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96788 times.
✓ Branch 3 taken 193624 times.
✓ Branch 4 taken 86785 times.
✓ Branch 5 taken 10003 times.
290412 !cu->skip_flag && (cb_width * cb_height >= 64);
1426
3/4
✓ Branch 0 taken 276144 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 241923 times.
✓ Branch 3 taken 34221 times.
276144 const int gpm_avaiable = sps->r->sps_gpm_enabled_flag && IS_B(rsh) &&
1427
2/2
✓ Branch 0 taken 216496 times.
✓ Branch 1 taken 25427 times.
241923 (cb_width >= 8) && (cb_height >=8) &&
1428
6/6
✓ Branch 0 taken 276144 times.
✓ Branch 1 taken 14268 times.
✓ Branch 2 taken 210430 times.
✓ Branch 3 taken 6066 times.
✓ Branch 4 taken 208603 times.
✓ Branch 5 taken 1827 times.
566556 (cb_width < 8 * cb_height) && (cb_height < 8 *cb_width);
1429
1430 290412 int regular_merge_flag = 1;
1431
1432
6/6
✓ Branch 0 taken 271816 times.
✓ Branch 1 taken 18596 times.
✓ Branch 2 taken 185327 times.
✓ Branch 3 taken 86489 times.
✓ Branch 4 taken 129209 times.
✓ Branch 5 taken 56118 times.
290412 if (!is_128 && (ciip_avaiable || gpm_avaiable))
1433 215698 regular_merge_flag = ff_vvc_regular_merge_flag(lc, cu->skip_flag);
1434
2/2
✓ Branch 0 taken 250158 times.
✓ Branch 1 taken 40254 times.
290412 if (regular_merge_flag) {
1435 250158 merge_data_regular(lc);
1436 } else {
1437 40254 cu->ciip_flag = ciip_flag_decode(lc, ciip_avaiable, gpm_avaiable, is_128);
1438
2/2
✓ Branch 0 taken 15517 times.
✓ Branch 1 taken 24737 times.
40254 if (cu->ciip_flag)
1439 15517 merge_data_ciip(lc);
1440 else
1441 24737 merge_data_gpm(lc);
1442 }
1443 290412 }
1444
1445 240 static int merge_data_ibc(VVCLocalContext *lc)
1446 {
1447 240 const VVCFrameContext* fc = lc->fc;
1448 240 const VVCSPS* sps = fc->ps.sps;
1449 240 MotionInfo *mi = &lc->cu->pu.mi;
1450 240 int merge_idx = 0;
1451 int ret;
1452
1453 240 mi->pred_flag = PF_IBC;
1454
1455
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 240 times.
240 if (sps->max_num_ibc_merge_cand > 1)
1456 merge_idx = ff_vvc_merge_idx(lc);
1457
1458 240 ret = ff_vvc_luma_mv_merge_ibc(lc, merge_idx, &mi->mv[L0][0]);
1459
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 240 times.
240 if (ret)
1460 return ret;
1461 240 ff_vvc_store_mv(lc, mi);
1462
1463 240 return 0;
1464 }
1465
1466 339373 static int hls_merge_data(VVCLocalContext *lc)
1467 {
1468 339373 const VVCFrameContext *fc = lc->fc;
1469 339373 const VVCPH *ph = &fc->ps.ph;
1470 339373 const CodingUnit *cu = lc->cu;
1471 339373 PredictionUnit *pu = &lc->cu->pu;
1472 int ret;
1473
1474 339373 pu->merge_gpm_flag = 0;
1475 339373 pu->mi.num_sb_x = pu->mi.num_sb_y = 1;
1476
2/2
✓ Branch 0 taken 240 times.
✓ Branch 1 taken 339133 times.
339373 if (cu->pred_mode == MODE_IBC) {
1477 240 ret = merge_data_ibc(lc);
1478
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 240 times.
240 if (ret)
1479 return ret;
1480 } else {
1481
5/6
✓ Branch 0 taken 339133 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 303260 times.
✓ Branch 3 taken 35873 times.
✓ Branch 4 taken 276219 times.
✓ Branch 5 taken 27041 times.
339133 if (ph->max_num_subblock_merge_cand > 0 && cu->cb_width >= 8 && cu->cb_height >= 8)
1482 276219 pu->merge_subblock_flag = ff_vvc_merge_subblock_flag(lc);
1483
2/2
✓ Branch 0 taken 48721 times.
✓ Branch 1 taken 290412 times.
339133 if (pu->merge_subblock_flag)
1484 48721 merge_data_subblock(lc);
1485 else
1486 290412 merge_data_block(lc);
1487 }
1488 339373 return 0;
1489 }
1490
1491 81166 static void hls_mvd_coding(VVCLocalContext *lc, Mv* mvd)
1492 {
1493 int16_t mv[2];
1494
1495
2/2
✓ Branch 0 taken 162332 times.
✓ Branch 1 taken 81166 times.
243498 for (int i = 0; i < 2; i++) {
1496 162332 mv[i] = ff_vvc_abs_mvd_greater0_flag(lc);
1497 }
1498
1499
2/2
✓ Branch 0 taken 162332 times.
✓ Branch 1 taken 81166 times.
243498 for (int i = 0; i < 2; i++) {
1500
2/2
✓ Branch 0 taken 113271 times.
✓ Branch 1 taken 49061 times.
162332 if (mv[i])
1501 113271 mv[i] += ff_vvc_abs_mvd_greater1_flag(lc);
1502 }
1503
1504
2/2
✓ Branch 0 taken 162332 times.
✓ Branch 1 taken 81166 times.
243498 for (int i = 0; i < 2; i++) {
1505
2/2
✓ Branch 0 taken 113271 times.
✓ Branch 1 taken 49061 times.
162332 if (mv[i] > 0) {
1506
2/2
✓ Branch 0 taken 66424 times.
✓ Branch 1 taken 46847 times.
113271 if (mv[i] == 2)
1507 66424 mv[i] += ff_vvc_abs_mvd_minus2(lc);
1508 113271 mv[i] = (1 - 2 * ff_vvc_mvd_sign_flag(lc)) * mv[i];
1509 }
1510 }
1511 81166 mvd->x = mv[0];
1512 81166 mvd->y = mv[1];
1513 81166 }
1514
1515 57785 static int bcw_idx_decode(VVCLocalContext *lc, const MotionInfo *mi, const int cb_width, const int cb_height)
1516 {
1517 57785 const VVCFrameContext *fc = lc->fc;
1518 57785 const VVCSPS *sps = fc->ps.sps;
1519 57785 const VVCPPS *pps = fc->ps.pps;
1520 57785 const VVCPH *ph = &fc->ps.ph;
1521 57785 const VVCSH *sh = &lc->sc->sh;
1522
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 57785 times.
57785 const PredWeightTable *w = pps->r->pps_wp_info_in_ph_flag ? &ph->pwt : &sh->pwt;
1523 57785 int bcw_idx = 0;
1524
1525
4/4
✓ Branch 0 taken 55847 times.
✓ Branch 1 taken 1938 times.
✓ Branch 2 taken 17075 times.
✓ Branch 3 taken 38772 times.
57785 if (sps->r->sps_bcw_enabled_flag && mi->pred_flag == PF_BI &&
1526
2/2
✓ Branch 0 taken 16887 times.
✓ Branch 1 taken 188 times.
17075 !w->weight_flag[L0][LUMA][mi->ref_idx[0]] &&
1527
1/2
✓ Branch 0 taken 16887 times.
✗ Branch 1 not taken.
16887 !w->weight_flag[L1][LUMA][mi->ref_idx[1]] &&
1528
1/2
✓ Branch 0 taken 16887 times.
✗ Branch 1 not taken.
16887 !w->weight_flag[L0][CHROMA][mi->ref_idx[0]] &&
1529
1/2
✓ Branch 0 taken 16887 times.
✗ Branch 1 not taken.
16887 !w->weight_flag[L1][CHROMA][mi->ref_idx[1]] &&
1530
2/2
✓ Branch 0 taken 11078 times.
✓ Branch 1 taken 5809 times.
16887 cb_width * cb_height >= 256) {
1531 11078 bcw_idx = ff_vvc_bcw_idx(lc, ff_vvc_no_backward_pred_flag(lc));
1532 }
1533 57785 return bcw_idx;
1534 }
1535
1536 74860 static int8_t ref_idx_decode(VVCLocalContext *lc, const VVCSH *sh, const int sym_mvd_flag, const int lx)
1537 {
1538 74860 const H266RawSliceHeader *rsh = sh->r;
1539 74860 int ref_idx = 0;
1540
1541
4/4
✓ Branch 0 taken 58572 times.
✓ Branch 1 taken 16288 times.
✓ Branch 2 taken 47090 times.
✓ Branch 3 taken 11482 times.
74860 if (rsh->num_ref_idx_active[lx] > 1 && !sym_mvd_flag)
1542 47090 ref_idx = ff_vvc_ref_idx_lx(lc, rsh->num_ref_idx_active[lx]);
1543
2/2
✓ Branch 0 taken 11482 times.
✓ Branch 1 taken 16288 times.
27770 else if (sym_mvd_flag)
1544 11482 ref_idx = sh->ref_idx_sym[lx];
1545 74860 return ref_idx;
1546 }
1547
1548 74860 static int mvds_decode(VVCLocalContext *lc, Mv mvds[2][MAX_CONTROL_POINTS],
1549 const int num_cp_mv, const int lx)
1550 {
1551 74860 const VVCFrameContext *fc = lc->fc;
1552 74860 const VVCPH *ph = &fc->ps.ph;
1553 74860 const PredictionUnit *pu = &lc->cu->pu;
1554 74860 const MotionInfo *mi = &pu->mi;
1555 74860 int has_no_zero_mvd = 0;
1556
1557
5/6
✓ Branch 0 taken 25055 times.
✓ Branch 1 taken 49805 times.
✓ Branch 2 taken 4514 times.
✓ Branch 3 taken 20541 times.
✓ Branch 4 taken 4514 times.
✗ Branch 5 not taken.
74860 if (lx == L1 && ph->r->ph_mvd_l1_zero_flag && mi->pred_flag == PF_BI) {
1558
2/2
✓ Branch 0 taken 5825 times.
✓ Branch 1 taken 4514 times.
10339 for (int j = 0; j < num_cp_mv; j++)
1559 5825 AV_ZERO64(&mvds[lx][j]);
1560 } else {
1561 70346 Mv *mvd0 = &mvds[lx][0];
1562
4/4
✓ Branch 0 taken 20541 times.
✓ Branch 1 taken 49805 times.
✓ Branch 2 taken 5741 times.
✓ Branch 3 taken 14800 times.
70346 if (lx == L1 && pu->sym_mvd_flag) {
1563 5741 mvd0->x = -mvds[L0][0].x;
1564 5741 mvd0->y = -mvds[L0][0].y;
1565 } else {
1566 64605 hls_mvd_coding(lc, mvd0);
1567 }
1568
4/4
✓ Branch 0 taken 20836 times.
✓ Branch 1 taken 49510 times.
✓ Branch 2 taken 13288 times.
✓ Branch 3 taken 7548 times.
70346 has_no_zero_mvd |= (mvd0->x || mvd0->y);
1569
2/2
✓ Branch 0 taken 15219 times.
✓ Branch 1 taken 70346 times.
85565 for (int j = 1; j < num_cp_mv; j++) {
1570 15219 Mv *mvd = &mvds[lx][j];
1571 15219 hls_mvd_coding(lc, mvd);
1572 15219 mvd->x += mvd0->x;
1573 15219 mvd->y += mvd0->y;
1574
4/4
✓ Branch 0 taken 2925 times.
✓ Branch 1 taken 12294 times.
✓ Branch 2 taken 1999 times.
✓ Branch 3 taken 926 times.
15219 has_no_zero_mvd |= (mvd->x || mvd->y);
1575 }
1576 }
1577 74860 return has_no_zero_mvd;
1578 }
1579
1580 57785 static void mvp_add_difference(MotionInfo *mi, const int num_cp_mv,
1581 const Mv mvds[2][MAX_CONTROL_POINTS], const int amvr_shift)
1582 {
1583
2/2
✓ Branch 0 taken 115570 times.
✓ Branch 1 taken 57785 times.
173355 for (int i = 0; i < 2; i++) {
1584 115570 const PredFlag mask = i + PF_L0;
1585
2/2
✓ Branch 0 taken 74860 times.
✓ Branch 1 taken 40710 times.
115570 if (mi->pred_flag & mask) {
1586
2/2
✓ Branch 0 taken 91390 times.
✓ Branch 1 taken 74860 times.
166250 for (int j = 0; j < num_cp_mv; j++) {
1587 91390 const Mv *mvd = &mvds[i][j];
1588 91390 mi->mv[i][j].x += mvd->x * (1 << amvr_shift);
1589 91390 mi->mv[i][j].y += mvd->y * (1 << amvr_shift);
1590 }
1591 }
1592 }
1593 57785 }
1594
1595 1342 static int mvp_data_ibc(VVCLocalContext *lc)
1596 {
1597 1342 const VVCFrameContext *fc = lc->fc;
1598 1342 const CodingUnit *cu = lc->cu;
1599 1342 const PredictionUnit *pu = &lc->cu->pu;
1600 1342 const VVCSPS *sps = fc->ps.sps;
1601 1342 MotionInfo *mi = &lc->cu->pu.mi;
1602 1342 int mvp_l0_flag = 0;
1603 1342 int amvr_shift = 4;
1604 1342 Mv *mv = &mi->mv[L0][0];
1605 int ret;
1606
1607 1342 mi->pred_flag = PF_IBC;
1608 1342 mi->num_sb_x = 1;
1609 1342 mi->num_sb_y = 1;
1610
1611 1342 hls_mvd_coding(lc, mv);
1612
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1342 times.
1342 if (sps->max_num_ibc_merge_cand > 1)
1613 mvp_l0_flag = ff_vvc_mvp_lx_flag(lc);
1614
5/6
✓ Branch 0 taken 1342 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 317 times.
✓ Branch 3 taken 1025 times.
✓ Branch 4 taken 53 times.
✓ Branch 5 taken 264 times.
1342 if (sps->r->sps_amvr_enabled_flag && (mv->x || mv->y))
1615 1078 amvr_shift = ff_vvc_amvr_shift(lc, pu->inter_affine_flag, cu->pred_mode, 1);
1616
1617 1342 ret = ff_vvc_mvp_ibc(lc, mvp_l0_flag, amvr_shift, mv);
1618
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1342 times.
1342 if (ret)
1619 return ret;
1620 1342 ff_vvc_store_mv(lc, mi);
1621
1622 1342 return 0;
1623 }
1624
1625 57785 static int mvp_data(VVCLocalContext *lc)
1626 {
1627 57785 const VVCFrameContext *fc = lc->fc;
1628 57785 const CodingUnit *cu = lc->cu;
1629 57785 PredictionUnit *pu = &lc->cu->pu;
1630 57785 const VVCSPS *sps = fc->ps.sps;
1631 57785 const VVCPH *ph = &fc->ps.ph;
1632 57785 const VVCSH *sh = &lc->sc->sh;
1633 57785 const H266RawSliceHeader *rsh = sh->r;
1634 57785 MotionInfo *mi = &pu->mi;
1635 57785 const int cb_width = cu->cb_width;
1636 57785 const int cb_height = cu->cb_height;
1637
1638 57785 int mvp_lx_flag[2] = {0};
1639 57785 int cu_affine_type_flag = 0;
1640 int num_cp_mv;
1641 57785 int amvr_enabled, has_no_zero_mvd = 0, amvr_shift;
1642 Mv mvds[2][MAX_CONTROL_POINTS];
1643
1644 57785 mi->pred_flag = ff_vvc_pred_flag(lc, IS_B(rsh));
1645
5/6
✓ Branch 0 taken 57785 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 33237 times.
✓ Branch 3 taken 24548 times.
✓ Branch 4 taken 25671 times.
✓ Branch 5 taken 7566 times.
57785 if (sps->r->sps_affine_enabled_flag && cb_width >= 16 && cb_height >= 16) {
1646 25671 pu->inter_affine_flag = ff_vvc_inter_affine_flag(lc);
1647 25671 set_cb_tab(lc, fc->tab.iaf, pu->inter_affine_flag);
1648
3/4
✓ Branch 0 taken 25671 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9102 times.
✓ Branch 3 taken 16569 times.
25671 if (sps->r->sps_6param_affine_enabled_flag && pu->inter_affine_flag)
1649 9102 cu_affine_type_flag = ff_vvc_cu_affine_type_flag(lc);
1650 }
1651 57785 mi->motion_model_idc = pu->inter_affine_flag + cu_affine_type_flag;
1652 57785 num_cp_mv = mi->motion_model_idc + 1;
1653
1654
4/4
✓ Branch 0 taken 47609 times.
✓ Branch 1 taken 10176 times.
✓ Branch 2 taken 37569 times.
✓ Branch 3 taken 10040 times.
57785 if (sps->r->sps_smvd_enabled_flag && !ph->r->ph_mvd_l1_zero_flag &&
1655
4/4
✓ Branch 0 taken 12561 times.
✓ Branch 1 taken 25008 times.
✓ Branch 2 taken 11430 times.
✓ Branch 3 taken 1131 times.
37569 mi->pred_flag == PF_BI && !pu->inter_affine_flag &&
1656
2/4
✓ Branch 0 taken 11430 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11430 times.
✗ Branch 3 not taken.
11430 sh->ref_idx_sym[0] > -1 && sh->ref_idx_sym[1] > -1)
1657 11430 pu->sym_mvd_flag = ff_vvc_sym_mvd_flag(lc);
1658
1659
2/2
✓ Branch 0 taken 115570 times.
✓ Branch 1 taken 57785 times.
173355 for (int i = L0; i <= L1; i++) {
1660
2/2
✓ Branch 0 taken 57785 times.
✓ Branch 1 taken 57785 times.
115570 const PredFlag pred_flag = PF_L0 + !i;
1661
2/2
✓ Branch 0 taken 74860 times.
✓ Branch 1 taken 40710 times.
115570 if (mi->pred_flag != pred_flag) {
1662 74860 mi->ref_idx[i] = ref_idx_decode(lc, sh, pu->sym_mvd_flag, i);
1663 74860 has_no_zero_mvd |= mvds_decode(lc, mvds, num_cp_mv, i);
1664 74860 mvp_lx_flag[i] = ff_vvc_mvp_lx_flag(lc);
1665 }
1666 }
1667
1668 115570 amvr_enabled = mi->motion_model_idc == MOTION_TRANSLATION ?
1669
2/2
✓ Branch 0 taken 48683 times.
✓ Branch 1 taken 9102 times.
57785 sps->r->sps_amvr_enabled_flag : sps->r->sps_affine_amvr_enabled_flag;
1670 57785 amvr_enabled &= has_no_zero_mvd;
1671
1672 57785 amvr_shift = ff_vvc_amvr_shift(lc, pu->inter_affine_flag, cu->pred_mode, amvr_enabled);
1673
1674 57785 mi->hpel_if_idx = amvr_shift == 3;
1675 57785 mi->bcw_idx = bcw_idx_decode(lc, mi, cb_width, cb_height);
1676
1677
2/2
✓ Branch 0 taken 9102 times.
✓ Branch 1 taken 48683 times.
57785 if (mi->motion_model_idc)
1678 9102 ff_vvc_affine_mvp(lc, mvp_lx_flag, amvr_shift, mi);
1679 else
1680 48683 ff_vvc_mvp(lc, mvp_lx_flag, amvr_shift, mi);
1681
1682 57785 mvp_add_difference(mi, num_cp_mv, mvds, amvr_shift);
1683
1684
2/2
✓ Branch 0 taken 9102 times.
✓ Branch 1 taken 48683 times.
57785 if (mi->motion_model_idc)
1685 9102 ff_vvc_store_sb_mvs(lc, pu);
1686 else
1687 48683 ff_vvc_store_mv(lc, &pu->mi);
1688
1689 57785 return 0;
1690 }
1691
1692 // derive bdofFlag from 8.5.6 Decoding process for inter blocks
1693 // derive dmvr from 8.5.1 General decoding process for coding units coded in inter prediction mode
1694 314358 static void derive_dmvr_bdof_flag(const VVCLocalContext *lc, PredictionUnit *pu)
1695 {
1696 314358 const VVCFrameContext *fc = lc->fc;
1697 314358 const VVCPPS *pps = fc->ps.pps;
1698 314358 const VVCPH *ph = &fc->ps.ph;
1699 314358 const VVCSH *sh = &lc->sc->sh;
1700 314358 const int poc = ph->poc;
1701 314358 const MotionInfo *mi = &pu->mi;
1702 314358 const int8_t *ref_idx = mi->ref_idx;
1703 314358 const VVCRefPic *rp0 = &lc->sc->rpl[L0].refs[ref_idx[L0]];
1704 314358 const VVCRefPic *rp1 = &lc->sc->rpl[L1].refs[ref_idx[L1]];
1705 314358 const CodingUnit *cu = lc->cu;
1706
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 314358 times.
314358 const PredWeightTable *w = pps->r->pps_wp_info_in_ph_flag ? &fc->ps.ph.pwt : &sh->pwt;
1707
1708 314358 pu->bdof_flag = 0;
1709
1710
2/2
✓ Branch 0 taken 167832 times.
✓ Branch 1 taken 146526 times.
314358 if (mi->pred_flag == PF_BI &&
1711
2/2
✓ Branch 0 taken 114623 times.
✓ Branch 1 taken 53209 times.
167832 (poc - rp0->poc == rp1->poc - poc) &&
1712
2/4
✓ Branch 0 taken 114623 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 114623 times.
✗ Branch 3 not taken.
114623 !rp0->is_lt && !rp1->is_lt &&
1713
2/2
✓ Branch 0 taken 111903 times.
✓ Branch 1 taken 2720 times.
114623 !cu->ciip_flag &&
1714
2/2
✓ Branch 0 taken 98407 times.
✓ Branch 1 taken 13496 times.
111903 !mi->bcw_idx &&
1715
3/4
✓ Branch 0 taken 97437 times.
✓ Branch 1 taken 970 times.
✓ Branch 2 taken 97437 times.
✗ Branch 3 not taken.
98407 !w->weight_flag[L0][LUMA][ref_idx[L0]] && !w->weight_flag[L1][LUMA][ref_idx[L1]] &&
1716
2/4
✓ Branch 0 taken 97437 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 97437 times.
✗ Branch 3 not taken.
97437 !w->weight_flag[L0][CHROMA][ref_idx[L0]] && !w->weight_flag[L1][CHROMA][ref_idx[L1]] &&