FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/vvc/ctu.c
Date: 2026-05-02 03:33:10
Exec Total Coverage
Lines: 1826 1872 97.5%
Functions: 89 89 100.0%
Branches: 1602 1750 91.5%

Line Branch Exec Source
1 /*
2 * VVC CTU(Coding Tree Unit) parser
3 *
4 * Copyright (C) 2022 Nuo Mi
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include "libavutil/error.h"
24 #include "libavutil/refstruct.h"
25
26 #include "cabac.h"
27 #include "ctu.h"
28 #include "inter.h"
29 #include "intra.h"
30 #include "mvs.h"
31
32 #define PROF_TEMP_SIZE (PROF_BLOCK_SIZE) * sizeof(int16_t)
33
34 #define TAB_MSM(fc, depth, x, y) fc->tab.msm[(depth)][((y) >> 5) * fc->ps.pps->width32 + ((x) >> 5)]
35 #define TAB_ISPMF(fc, x, y) fc->tab.ispmf[((y) >> 6) * fc->ps.pps->width64 + ((x) >> 6)]
36
37 typedef enum VVCModeType {
38 MODE_TYPE_ALL,
39 MODE_TYPE_INTER,
40 MODE_TYPE_INTRA,
41 } VVCModeType;
42
43 2436334 static void set_tb_size(const VVCFrameContext *fc, const TransformBlock *tb)
44 {
45 2436334 const int x_tb = tb->x0 >> MIN_TU_LOG2;
46 2436334 const int y_tb = tb->y0 >> MIN_TU_LOG2;
47 2436334 const int hs = fc->ps.sps->hshift[tb->c_idx];
48 2436334 const int vs = fc->ps.sps->vshift[tb->c_idx];
49 2436334 const int is_chroma = tb->c_idx != 0;
50 2436334 const int width = FFMAX(1, tb->tb_width >> (MIN_TU_LOG2 - hs));
51 2436334 const int end = y_tb + FFMAX(1, tb->tb_height >> (MIN_TU_LOG2 - vs));
52
53
2/2
✓ Branch 0 taken 11515746 times.
✓ Branch 1 taken 2436334 times.
13952080 for (int y = y_tb; y < end; y++) {
54 11515746 const int off = y * fc->ps.pps->min_tu_width + x_tb;
55 11515746 memset(fc->tab.tb_width [is_chroma] + off, tb->tb_width, width);
56 11515746 memset(fc->tab.tb_height[is_chroma] + off, tb->tb_height, width);
57 }
58 2436334 }
59
60 3358745 static void set_tb_tab(uint8_t *tab, uint8_t v, const VVCFrameContext *fc,
61 const TransformBlock *tb)
62 {
63 3358745 const int width = tb->tb_width << fc->ps.sps->hshift[tb->c_idx];
64 3358745 const int height = tb->tb_height << fc->ps.sps->vshift[tb->c_idx];
65
66
2/2
✓ Branch 0 taken 15527855 times.
✓ Branch 1 taken 3358745 times.
18886600 for (int h = 0; h < height; h += MIN_TU_SIZE) {
67 15527855 const int y = (tb->y0 + h) >> MIN_TU_LOG2;
68 15527855 const int off = y * fc->ps.pps->min_tu_width + (tb->x0 >> MIN_TU_LOG2);
69 15527855 const int w = FFMAX(1, width >> MIN_TU_LOG2);
70 15527855 memset(tab + off, v, w);
71 }
72 3358745 }
73
74 // 8.7.1 Derivation process for quantization parameters
75 6185 static int get_qp_y_pred(const VVCLocalContext *lc)
76 {
77 6185 const VVCFrameContext *fc = lc->fc;
78 6185 const VVCSPS *sps = fc->ps.sps;
79 6185 const VVCPPS *pps = fc->ps.pps;
80 6185 const CodingUnit *cu = lc->cu;
81 6185 const int ctb_log2_size = sps->ctb_log2_size_y;
82 6185 const int ctb_size_mask = (1 << ctb_log2_size) - 1;
83 6185 const int xQg = lc->parse.cu_qg_top_left_x;
84 6185 const int yQg = lc->parse.cu_qg_top_left_y;
85 6185 const int min_cb_width = fc->ps.pps->min_cb_width;
86 6185 const int x_cb = cu->x0 >> sps->min_cb_log2_size_y;
87 6185 const int y_cb = cu->y0 >> sps->min_cb_log2_size_y;
88 6185 const int rx = cu->x0 >> ctb_log2_size;
89 6185 const int ry = cu->y0 >> ctb_log2_size;
90
3/4
✓ Branch 0 taken 920 times.
✓ Branch 1 taken 5265 times.
✓ Branch 2 taken 920 times.
✗ Branch 3 not taken.
6185 const int in_same_ctb_a = ((xQg - 1) >> ctb_log2_size) == rx && (yQg >> ctb_log2_size) == ry;
91
3/4
✓ Branch 0 taken 6185 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 920 times.
✓ Branch 3 taken 5265 times.
6185 const int in_same_ctb_b = (xQg >> ctb_log2_size) == rx && ((yQg - 1) >> ctb_log2_size) == ry;
92 int qPy_pred, qPy_a, qPy_b;
93
94
2/2
✓ Branch 0 taken 4682 times.
✓ Branch 1 taken 1503 times.
6185 if (lc->na.cand_up) {
95
4/4
✓ Branch 0 taken 3841 times.
✓ Branch 1 taken 841 times.
✓ Branch 2 taken 3381 times.
✓ Branch 3 taken 460 times.
4682 const int first_qg_in_ctu = !(xQg & ctb_size_mask) && !(yQg & ctb_size_mask);
96 4682 const int qPy_up = fc->tab.qp[LUMA][x_cb + (y_cb - 1) * min_cb_width];
97
4/4
✓ Branch 0 taken 3381 times.
✓ Branch 1 taken 1301 times.
✓ Branch 2 taken 778 times.
✓ Branch 3 taken 2603 times.
4682 if (first_qg_in_ctu && pps->ctb_to_col_bd[xQg >> ctb_log2_size] == xQg >> ctb_log2_size)
98 778 return qPy_up;
99 }
100
101 // qPy_pred
102
2/2
✓ Branch 0 taken 497 times.
✓ Branch 1 taken 4910 times.
5407 qPy_pred = lc->ep->is_first_qg ? lc->sc->sh.slice_qp_y : lc->ep->qp_y;
103
104 // qPy_b
105
4/4
✓ Branch 0 taken 3904 times.
✓ Branch 1 taken 1503 times.
✓ Branch 2 taken 2984 times.
✓ Branch 3 taken 920 times.
5407 if (!lc->na.cand_up || !in_same_ctb_b)
106 4487 qPy_b = qPy_pred;
107 else
108 920 qPy_b = fc->tab.qp[LUMA][x_cb + (y_cb - 1) * min_cb_width];
109
110 // qPy_a
111
4/4
✓ Branch 0 taken 4830 times.
✓ Branch 1 taken 577 times.
✓ Branch 2 taken 3910 times.
✓ Branch 3 taken 920 times.
5407 if (!lc->na.cand_left || !in_same_ctb_a)
112 4487 qPy_a = qPy_pred;
113 else
114 920 qPy_a = fc->tab.qp[LUMA][(x_cb - 1) + y_cb * min_cb_width];
115
116 av_assert2(qPy_a >= -fc->ps.sps->qp_bd_offset && qPy_a <= 63);
117 av_assert2(qPy_b >= -fc->ps.sps->qp_bd_offset && qPy_b <= 63);
118
119 5407 return (qPy_a + qPy_b + 1) >> 1;
120 }
121
122 9997068 static void set_cb_tab(const VVCLocalContext *lc, uint8_t *tab, const uint8_t v)
123 {
124 9997068 const VVCFrameContext *fc = lc->fc;
125 9997068 const VVCPPS *pps = fc->ps.pps;
126 9997068 const CodingUnit *cu = lc->cu;
127 9997068 const int log2_min_cb_size = fc->ps.sps->min_cb_log2_size_y;
128 9997068 const int x_cb = cu->x0 >> log2_min_cb_size;
129 9997068 const int y_cb = cu->y0 >> log2_min_cb_size;
130 9997068 const int cb_width = cu->cb_width;
131 9997068 const int cb_height = cu->cb_height;
132 9997068 int x = y_cb * pps->min_cb_width + x_cb;
133
134
2/2
✓ Branch 0 taken 42356040 times.
✓ Branch 1 taken 9997068 times.
52353108 for (int y = 0; y < (cb_height >> log2_min_cb_size); y++) {
135 42356040 const int width = cb_width >> log2_min_cb_size;
136
137 42356040 memset(&tab[x], v, width);
138 42356040 x += pps->min_cb_width;
139 }
140 9997068 }
141
142 1398913 static int set_qp_y(VVCLocalContext *lc, const int x0, const int y0, const int has_qp_delta)
143 {
144 1398913 const VVCSPS *sps = lc->fc->ps.sps;
145 1398913 EntryPoint *ep = lc->ep;
146 1398913 CodingUnit *cu = lc->cu;
147 1398913 int cu_qp_delta = 0;
148
149
2/2
✓ Branch 0 taken 1228043 times.
✓ Branch 1 taken 170870 times.
1398913 if (!lc->fc->ps.pps->r->pps_cu_qp_delta_enabled_flag) {
150 1228043 ep->qp_y = lc->sc->sh.slice_qp_y;
151
6/6
✓ Branch 0 taken 170373 times.
✓ Branch 1 taken 497 times.
✓ Branch 2 taken 18798 times.
✓ Branch 3 taken 151575 times.
✓ Branch 4 taken 5688 times.
✓ Branch 5 taken 13110 times.
170870 } else if (ep->is_first_qg || (lc->parse.cu_qg_top_left_x == x0 && lc->parse.cu_qg_top_left_y == y0)) {
152 6185 ep->qp_y = get_qp_y_pred(lc);
153 6185 ep->is_first_qg = 0;
154 }
155
156
2/2
✓ Branch 0 taken 3618 times.
✓ Branch 1 taken 1395295 times.
1398913 if (has_qp_delta) {
157 3618 const int cu_qp_delta_abs = ff_vvc_cu_qp_delta_abs(lc);
158
159
2/2
✓ Branch 0 taken 1325 times.
✓ Branch 1 taken 2293 times.
3618 if (cu_qp_delta_abs)
160
2/2
✓ Branch 1 taken 746 times.
✓ Branch 2 taken 579 times.
1325 cu_qp_delta = ff_vvc_cu_qp_delta_sign_flag(lc) ? -cu_qp_delta_abs : cu_qp_delta_abs;
161
2/4
✓ Branch 0 taken 3618 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3618 times.
3618 if (cu_qp_delta > (31 + sps->qp_bd_offset / 2) || cu_qp_delta < -(32 + sps->qp_bd_offset / 2))
162 return AVERROR_INVALIDDATA;
163 3618 lc->parse.is_cu_qp_delta_coded = 1;
164
165
2/2
✓ Branch 0 taken 1325 times.
✓ Branch 1 taken 2293 times.
3618 if (cu_qp_delta) {
166 1325 int off = sps->qp_bd_offset;
167
1/2
✓ Branch 0 taken 1325 times.
✗ Branch 1 not taken.
1325 ep->qp_y = FFUMOD(ep->qp_y + cu_qp_delta + 64 + 2 * off, 64 + off) - off;
168 }
169 }
170
171 1398913 set_cb_tab(lc, lc->fc->tab.qp[LUMA], ep->qp_y);
172 1398913 cu->qp[LUMA] = ep->qp_y;
173
174 1398913 return 0;
175 }
176
177 1845234 static void set_qp_c_tab(const VVCLocalContext *lc, const TransformUnit *tu, const TransformBlock *tb)
178 {
179
6/6
✓ Branch 0 taken 109842 times.
✓ Branch 1 taken 1735392 times.
✓ Branch 2 taken 93482 times.
✓ Branch 3 taken 16360 times.
✓ Branch 4 taken 63304 times.
✓ Branch 5 taken 30178 times.
1845234 const int is_jcbcr = tu->joint_cbcr_residual_flag && tu->coded_flag[CB] && tu->coded_flag[CR];
180
2/2
✓ Branch 0 taken 1781930 times.
✓ Branch 1 taken 63304 times.
1845234 const int idx = is_jcbcr ? JCBCR : tb->c_idx;
181
182 1845234 set_tb_tab(lc->fc->tab.qp[tb->c_idx], lc->cu->qp[idx], lc->fc, tb);
183 1845234 }
184
185 1334181 static void set_qp_c(VVCLocalContext *lc)
186 {
187 1334181 const VVCFrameContext *fc = lc->fc;
188 1334181 const VVCSPS *sps = fc->ps.sps;
189 1334181 const VVCPPS *pps = fc->ps.pps;
190 1334181 const H266RawSliceHeader *rsh = lc->sc->sh.r;
191 1334181 CodingUnit *cu = lc->cu;
192 1334181 const int x_center = cu->x0 + cu->cb_width / 2;
193 1334181 const int y_center = cu->y0 + cu->cb_height / 2;
194 1334181 const int single_tree = cu->tree_type == SINGLE_TREE;
195
2/2
✓ Branch 0 taken 578002 times.
✓ Branch 1 taken 756179 times.
1334181 const int qp_luma = (single_tree ? lc->ep->qp_y : ff_vvc_get_qPy(fc, x_center, y_center)) + sps->qp_bd_offset;
196 1334181 const int qp_chroma = av_clip(qp_luma, 0, MAX_QP + sps->qp_bd_offset);
197 1334181 const int sh_chroma_qp_offset[] = {
198 1334181 rsh->sh_cb_qp_offset,
199 1334181 rsh->sh_cr_qp_offset,
200 1334181 rsh->sh_joint_cbcr_qp_offset,
201 };
202 int qp;
203
204
2/2
✓ Branch 0 taken 3955238 times.
✓ Branch 1 taken 1334181 times.
5289419 for (int i = CB - 1; i < CR + sps->r->sps_joint_cbcr_enabled_flag; i++) {
205 3955238 qp = sps->chroma_qp_table[i][qp_chroma];
206 3955238 qp = qp + pps->chroma_qp_offset[i] + sh_chroma_qp_offset[i] + lc->parse.chroma_qp_offset[i];
207 3955238 qp = av_clip(qp, -sps->qp_bd_offset, MAX_QP) + sps->qp_bd_offset;
208 3955238 cu->qp[i + 1] = qp;
209 }
210 1334181 }
211
212 1707295 static TransformUnit* alloc_tu(VVCFrameContext *fc, CodingUnit *cu)
213 {
214 1707295 TransformUnit *tu = av_refstruct_pool_get(fc->tu_pool);
215
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1707295 times.
1707295 if (!tu)
216 return NULL;
217
218 1707295 tu->next = NULL;
219
220
2/2
✓ Branch 0 taken 320414 times.
✓ Branch 1 taken 1386881 times.
1707295 if (cu->tus.tail)
221 320414 cu->tus.tail->next = tu;
222 else
223 1386881 cu->tus.head = tu;
224 1707295 cu->tus.tail = tu;
225
226 1707295 return tu;
227 }
228
229 1707295 static TransformUnit* add_tu(VVCFrameContext *fc, CodingUnit *cu, const int x0, const int y0, const int tu_width, const int tu_height)
230 {
231 1707295 TransformUnit *tu = alloc_tu(fc, cu);
232
233
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1707295 times.
1707295 if (!tu)
234 return NULL;
235
236 1707295 tu->x0 = x0;
237 1707295 tu->y0 = y0;
238 1707295 tu->width = tu_width;
239 1707295 tu->height = tu_height;
240 1707295 tu->joint_cbcr_residual_flag = 0;
241 1707295 memset(tu->coded_flag, 0, sizeof(tu->coded_flag));
242 1707295 tu->avail[LUMA] = tu->avail[CHROMA] = 0;
243 1707295 tu->nb_tbs = 0;
244
245 1707295 return tu;
246 }
247
248 3358951 static TransformBlock* add_tb(TransformUnit *tu, VVCLocalContext *lc,
249 const int x0, const int y0, const int tb_width, const int tb_height, const int c_idx)
250 {
251 TransformBlock *tb;
252
253 3358951 tb = &tu->tbs[tu->nb_tbs++];
254 3358951 tb->has_coeffs = 0;
255 3358951 tb->x0 = x0;
256 3358951 tb->y0 = y0;
257 3358951 tb->tb_width = tb_width;
258 3358951 tb->tb_height = tb_height;
259 3358951 tb->log2_tb_width = av_log2(tb_width);
260 3358951 tb->log2_tb_height = av_log2(tb_height);
261
262 3358951 tb->max_scan_x = tb->max_scan_y = 0;
263 3358951 tb->min_scan_x = tb->min_scan_y = 0;
264
265 3358951 tb->c_idx = c_idx;
266 3358951 tb->ts = 0;
267 3358951 tb->coeffs = lc->coeffs;
268 3358951 lc->coeffs += tb_width * tb_height;
269 3358951 tu->avail[!!c_idx] = true;
270 3358951 return tb;
271 }
272
273 1027003 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 1027003 uint8_t tu_y_coded_flag = 0;
277 1027003 const VVCSPS *sps = lc->fc->ps.sps;
278 1027003 CodingUnit *cu = lc->cu;
279
280
2/2
✓ Branch 0 taken 981550 times.
✓ Branch 1 taken 45453 times.
1027003 if (!is_sbt_not_coded) {
281
4/4
✓ Branch 0 taken 834327 times.
✓ Branch 1 taken 147223 times.
✓ Branch 2 taken 52672 times.
✓ Branch 3 taken 781655 times.
981550 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 769120 times.
✓ Branch 1 taken 212430 times.
981550 if (!is_isp) {
283
4/4
✓ Branch 0 taken 754836 times.
✓ Branch 1 taken 14284 times.
✓ Branch 2 taken 2942 times.
✓ Branch 3 taken 751894 times.
769120 const int is_large = cu->cb_width > sps->max_tb_size_y || cu->cb_height > sps->max_tb_size_y;
284
8/8
✓ Branch 0 taken 573947 times.
✓ Branch 1 taken 195173 times.
✓ Branch 2 taken 6377 times.
✓ Branch 3 taken 567570 times.
✓ Branch 4 taken 131864 times.
✓ Branch 5 taken 69686 times.
✓ Branch 6 taken 4881 times.
✓ Branch 7 taken 126983 times.
769120 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 842032 times.
✓ Branch 1 taken 139518 times.
981550 tu_y_coded_flag = has_y_coded_flag ? ff_vvc_tu_y_coded_flag(lc) : 1;
287 }
288
2/2
✓ Branch 0 taken 212430 times.
✓ Branch 1 taken 814573 times.
1027003 if (is_isp)
289
4/4
✓ Branch 0 taken 106220 times.
✓ Branch 1 taken 106210 times.
✓ Branch 2 taken 41013 times.
✓ Branch 3 taken 65207 times.
212430 lc->parse.infer_tu_cbf_luma = lc->parse.infer_tu_cbf_luma && !tu_y_coded_flag;
290 1027003 return tu_y_coded_flag;
291 }
292
293 529646 static void chroma_qp_offset_decode(VVCLocalContext *lc, const int is_128, const int is_chroma_coded)
294 {
295 529646 const VVCPPS *pps = lc->fc->ps.pps;
296 529646 const H266RawSliceHeader *rsh = lc->sc->sh.r;
297
298
4/4
✓ Branch 0 taken 520708 times.
✓ Branch 1 taken 8938 times.
✓ Branch 2 taken 202424 times.
✓ Branch 3 taken 318284 times.
529646 if ((is_128 || is_chroma_coded) &&
299
4/4
✓ Branch 0 taken 39307 times.
✓ Branch 1 taken 172055 times.
✓ Branch 2 taken 1029 times.
✓ Branch 3 taken 38278 times.
211362 rsh->sh_cu_chroma_qp_offset_enabled_flag && !lc->parse.is_cu_chroma_qp_offset_coded) {
300 1029 const int cu_chroma_qp_offset_flag = ff_vvc_cu_chroma_qp_offset_flag(lc);
301
1/2
✓ Branch 0 taken 1029 times.
✗ Branch 1 not taken.
1029 if (cu_chroma_qp_offset_flag) {
302 1029 int cu_chroma_qp_offset_idx = 0;
303
2/2
✓ Branch 0 taken 931 times.
✓ Branch 1 taken 98 times.
1029 if (pps->r->pps_chroma_qp_offset_list_len_minus1 > 0)
304 931 cu_chroma_qp_offset_idx = ff_vvc_cu_chroma_qp_offset_idx(lc);
305
2/2
✓ Branch 0 taken 3087 times.
✓ Branch 1 taken 1029 times.
4116 for (int i = CB - 1; i < JCBCR; i++)
306 3087 lc->parse.chroma_qp_offset[i] = pps->chroma_qp_offset_list[cu_chroma_qp_offset_idx][i];
307 } else {
308 memset(lc->parse.chroma_qp_offset, 0, sizeof(lc->parse.chroma_qp_offset));
309 }
310 1029 lc->parse.is_cu_chroma_qp_offset_coded = 1;
311 }
312 529646 }
313
314 1220581 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 1220581 VVCFrameContext *fc = lc->fc;
317 1220581 const VVCSPS *sps = fc->ps.sps;
318 1220581 const VVCPPS *pps = fc->ps.pps;
319 1220581 CodingUnit *cu = lc->cu;
320 1220581 TransformUnit *tu = add_tu(fc, cu, x0, y0, tu_width, tu_height);
321 1220581 const int min_cb_width = pps->min_cb_width;
322 1220581 const VVCTreeType tree_type = cu->tree_type;
323
4/4
✓ Branch 0 taken 1213329 times.
✓ Branch 1 taken 7252 times.
✓ Branch 2 taken 1686 times.
✓ Branch 3 taken 1211643 times.
1220581 const int is_128 = cu->cb_width > 64 || cu->cb_height > 64;
324 1220581 const int is_isp = cu->isp_split_type != ISP_NO_SPLIT;
325
4/4
✓ Branch 0 taken 212430 times.
✓ Branch 1 taken 1008151 times.
✓ Branch 2 taken 65207 times.
✓ Branch 3 taken 147223 times.
1220581 const int is_isp_last_tu = is_isp && (sub_tu_index == cu->num_intra_subpartitions - 1);
326
4/4
✓ Branch 0 taken 90906 times.
✓ Branch 1 taken 1129675 times.
✓ Branch 2 taken 45453 times.
✓ Branch 3 taken 45453 times.
1311487 const int is_sbt_not_coded = cu->sbt_flag &&
327
6/6
✓ Branch 0 taken 23704 times.
✓ Branch 1 taken 21749 times.
✓ Branch 2 taken 45453 times.
✓ Branch 3 taken 23704 times.
✓ Branch 4 taken 23704 times.
✓ Branch 5 taken 21749 times.
90906 ((sub_tu_index == 0 && cu->sbt_pos_flag) || (sub_tu_index == 1 && !cu->sbt_pos_flag));
328
6/6
✓ Branch 0 taken 529646 times.
✓ Branch 1 taken 690935 times.
✓ Branch 2 taken 506174 times.
✓ Branch 3 taken 23472 times.
✓ Branch 4 taken 23318 times.
✓ Branch 5 taken 482856 times.
1243899 const int chroma_available = tree_type != DUAL_TREE_LUMA && sps->r->sps_chroma_format_idc &&
329
2/2
✓ Branch 0 taken 5917 times.
✓ Branch 1 taken 17401 times.
23318 (!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 1220581 times.
1220581 if (!tu)
333 return AVERROR_INVALIDDATA;
334
335
4/4
✓ Branch 0 taken 336068 times.
✓ Branch 1 taken 884513 times.
✓ Branch 2 taken 7699 times.
✓ Branch 3 taken 328369 times.
1220581 if (tree_type == SINGLE_TREE && is_isp_last_tu) {
336 7699 const int x_cu = x0 >> fc->ps.sps->min_cb_log2_size_y;
337 7699 const int y_cu = y0 >> fc->ps.sps->min_cb_log2_size_y;
338 7699 xc = SAMPLE_CTB(fc->tab.cb_pos_x[ch_type], x_cu, y_cu);
339 7699 yc = SAMPLE_CTB(fc->tab.cb_pos_y[ch_type], x_cu, y_cu);
340 7699 wc = SAMPLE_CTB(fc->tab.cb_width[ch_type], x_cu, y_cu);
341 7699 hc = SAMPLE_CTB(fc->tab.cb_height[ch_type], x_cu, y_cu);
342 } else {
343 1212882 xc = x0, yc = y0, wc = tu_width, hc = tu_height;
344 }
345
346
4/4
✓ Branch 0 taken 488773 times.
✓ Branch 1 taken 731808 times.
✓ Branch 2 taken 444612 times.
✓ Branch 3 taken 44161 times.
1220581 if (chroma_available && !is_sbt_not_coded) {
347 444612 tu->coded_flag[CB] = ff_vvc_tu_cb_coded_flag(lc);
348 444612 tu->coded_flag[CR] = ff_vvc_tu_cr_coded_flag(lc, tu->coded_flag[CB]);
349 }
350
351
6/6
✓ Branch 0 taken 488773 times.
✓ Branch 1 taken 731808 times.
✓ Branch 2 taken 315069 times.
✓ Branch 3 taken 173704 times.
✓ Branch 4 taken 34651 times.
✓ Branch 5 taken 280418 times.
1220581 is_chroma_coded = chroma_available && (tu->coded_flag[CB] || tu->coded_flag[CR]);
352
353
2/2
✓ Branch 0 taken 1027003 times.
✓ Branch 1 taken 193578 times.
1220581 if (tree_type != DUAL_TREE_CHROMA) {
354 int has_qp_delta;
355 1027003 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 276926 times.
✓ Branch 1 taken 741139 times.
✓ Branch 2 taken 36866 times.
✓ Branch 3 taken 240060 times.
1018065 has_qp_delta = (is_128 || tu->coded_flag[LUMA] || is_chroma_coded) &&
357
6/6
✓ Branch 0 taken 1018065 times.
✓ Branch 1 taken 8938 times.
✓ Branch 2 taken 79631 times.
✓ Branch 3 taken 707312 times.
✓ Branch 4 taken 3618 times.
✓ Branch 5 taken 76013 times.
2045068 pps->r->pps_cu_qp_delta_enabled_flag && !lc->parse.is_cu_qp_delta_coded;
358 1027003 ret = set_qp_y(lc, x0, y0, has_qp_delta);
359
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1027003 times.
1027003 if (ret < 0)
360 return ret;
361 1027003 add_tb(tu, lc, x0, y0, tu_width, tu_height, LUMA);
362 }
363
2/2
✓ Branch 0 taken 529646 times.
✓ Branch 1 taken 690935 times.
1220581 if (tree_type != DUAL_TREE_LUMA) {
364 529646 chroma_qp_offset_decode(lc, is_128, is_chroma_coded);
365
2/2
✓ Branch 0 taken 488773 times.
✓ Branch 1 taken 40873 times.
529646 if (chroma_available) {
366 488773 const int hs = sps->hshift[CHROMA];
367 488773 const int vs = sps->vshift[CHROMA];
368 488773 add_tb(tu, lc, xc, yc, wc >> hs, hc >> vs, CB);
369 488773 add_tb(tu, lc, xc, yc, wc >> hs, hc >> vs, CR);
370 }
371 }
372
4/4
✓ Branch 0 taken 1174656 times.
✓ Branch 1 taken 45925 times.
✓ Branch 2 taken 942966 times.
✓ Branch 3 taken 231690 times.
1220581 if (sps->r->sps_joint_cbcr_enabled_flag && ((cu->pred_mode == MODE_INTRA &&
373
4/4
✓ Branch 0 taken 833822 times.
✓ Branch 1 taken 109144 times.
✓ Branch 2 taken 807691 times.
✓ Branch 3 taken 26131 times.
942966 (tu->coded_flag[CB] || tu->coded_flag[CR])) ||
374
5/6
✓ Branch 0 taken 58206 times.
✓ Branch 1 taken 981175 times.
✓ Branch 2 taken 25970 times.
✓ Branch 3 taken 32236 times.
✓ Branch 4 taken 161245 times.
✗ Branch 5 not taken.
1174656 (tu->coded_flag[CB] && tu->coded_flag[CR])) &&
375 chroma_available) {
376 161245 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 2004549 times.
✓ Branch 1 taken 1220581 times.
3225130 for (int i = 0; i < tu->nb_tbs; i++) {
380 2004549 TransformBlock *tb = &tu->tbs[i];
381 2004549 const int is_chroma = tb->c_idx != LUMA;
382 2004549 tb->has_coeffs = tu->coded_flag[tb->c_idx];
383
4/4
✓ Branch 0 taken 1056390 times.
✓ Branch 1 taken 948159 times.
✓ Branch 2 taken 308933 times.
✓ Branch 3 taken 747457 times.
2004549 if (tb->has_coeffs && is_chroma)
384
6/6
✓ Branch 0 taken 135229 times.
✓ Branch 1 taken 173704 times.
✓ Branch 2 taken 100578 times.
✓ Branch 3 taken 34651 times.
✓ Branch 4 taken 68926 times.
✓ Branch 5 taken 31652 times.
308933 tb->has_coeffs = tb->c_idx == CB ? 1 : !(tu->coded_flag[CB] && tu->joint_cbcr_residual_flag);
385
2/2
✓ Branch 0 taken 1024738 times.
✓ Branch 1 taken 979811 times.
2004549 if (tb->has_coeffs) {
386 1024738 tb->ts = cu->bdpcm_flag[tb->c_idx];
387
4/4
✓ Branch 0 taken 903613 times.
✓ Branch 1 taken 121125 times.
✓ Branch 2 taken 899930 times.
✓ Branch 3 taken 3683 times.
1024738 if (sps->r->sps_transform_skip_enabled_flag && !cu->bdpcm_flag[tb->c_idx] &&
388
4/4
✓ Branch 0 taken 883374 times.
✓ Branch 1 taken 16556 times.
✓ Branch 2 taken 876053 times.
✓ Branch 3 taken 7321 times.
899930 tb->tb_width <= sps->max_ts_size && tb->tb_height <= sps->max_ts_size &&
389
6/6
✓ Branch 0 taken 835542 times.
✓ Branch 1 taken 40511 times.
✓ Branch 2 taken 638843 times.
✓ Branch 3 taken 196699 times.
✓ Branch 4 taken 500263 times.
✓ Branch 5 taken 138580 times.
876053 !cu->sbt_flag && (is_chroma || !is_isp)) {
390 696962 tb->ts = ff_vvc_transform_skip_flag(lc, is_chroma);
391 }
392 1024738 ret = ff_vvc_residual_coding(lc, tb);
393
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1024738 times.
1024738 if (ret < 0)
394 return ret;
395 1024738 set_tb_tab(fc->tab.tu_coded_flag[tb->c_idx], tu->coded_flag[tb->c_idx], fc, tb);
396
2/2
✓ Branch 0 taken 24384 times.
✓ Branch 1 taken 955427 times.
979811 } else if (cu->act_enabled_flag) {
397 24384 memset(tb->coeffs, 0, tb->tb_width * tb->tb_height * sizeof(*tb->coeffs));
398 }
399
2/2
✓ Branch 0 taken 1515776 times.
✓ Branch 1 taken 488773 times.
2004549 if (tb->c_idx != CR)
400 1515776 set_tb_size(fc, tb);
401
2/2
✓ Branch 0 taken 488773 times.
✓ Branch 1 taken 1515776 times.
2004549 if (tb->c_idx == CB)
402 488773 set_tb_tab(fc->tab.tu_joint_cbcr_residual_flag, tu->joint_cbcr_residual_flag, fc, tb);
403 }
404
405 1220581 return 0;
406 }
407
408 1040839 static int hls_transform_tree(VVCLocalContext *lc, int x0, int y0,int tu_width, int tu_height, int ch_type)
409 {
410 1040839 const CodingUnit *cu = lc->cu;
411 1040839 const VVCSPS *sps = lc->fc->ps.sps;
412 int ret;
413
414 1040839 lc->parse.infer_tu_cbf_luma = 1;
415
4/4
✓ Branch 0 taken 975632 times.
✓ Branch 1 taken 65207 times.
✓ Branch 2 taken 930179 times.
✓ Branch 3 taken 45453 times.
1040839 if (cu->isp_split_type == ISP_NO_SPLIT && !cu->sbt_flag) {
416
4/4
✓ Branch 0 taken 919218 times.
✓ Branch 1 taken 10961 times.
✓ Branch 2 taken 1973 times.
✓ Branch 3 taken 917245 times.
943113 if (tu_width > sps->max_tb_size_y || tu_height > sps->max_tb_size_y) {
417
4/4
✓ Branch 0 taken 10961 times.
✓ Branch 1 taken 1973 times.
✓ Branch 2 taken 8066 times.
✓ Branch 3 taken 2895 times.
12934 const int ver_split_first = tu_width > sps->max_tb_size_y && tu_width > tu_height;
418
2/2
✓ Branch 0 taken 8066 times.
✓ Branch 1 taken 4868 times.
12934 const int trafo_width = ver_split_first ? (tu_width / 2) : tu_width;
419
2/2
✓ Branch 0 taken 4868 times.
✓ Branch 1 taken 8066 times.
12934 const int trafo_height = !ver_split_first ? (tu_height / 2) : tu_height;
420
421 #define TRANSFORM_TREE(x, y) do { \
422 ret = hls_transform_tree(lc, x, y, trafo_width, trafo_height, ch_type); \
423 if (ret < 0) \
424 return ret; \
425 } while (0)
426
427
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 12934 times.
12934 TRANSFORM_TREE(x0, y0);
428
2/2
✓ Branch 0 taken 8066 times.
✓ Branch 1 taken 4868 times.
12934 if (ver_split_first)
429
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 8066 times.
8066 TRANSFORM_TREE(x0 + trafo_width, y0);
430 else
431
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4868 times.
4868 TRANSFORM_TREE(x0, y0 + trafo_height);
432
433 } else {
434 917245 ret = hls_transform_unit(lc, x0, y0, tu_width, tu_height, 0, ch_type);
435
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 917245 times.
917245 if (ret < 0)
436 return ret;
437
438 }
439
2/2
✓ Branch 0 taken 45453 times.
✓ Branch 1 taken 65207 times.
110660 } else if (cu->sbt_flag) {
440
2/2
✓ Branch 0 taken 24022 times.
✓ Branch 1 taken 21431 times.
45453 if (!cu->sbt_horizontal_flag) {
441 #define TRANSFORM_UNIT(x, width, idx) do { \
442 ret = hls_transform_unit(lc, x, y0, width, tu_height, idx, ch_type); \
443 if (ret < 0) \
444 return ret; \
445 } while (0)
446
447 24022 const int trafo_width = tu_width * lc->parse.sbt_num_fourths_tb0 / 4;
448
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 24022 times.
24022 TRANSFORM_UNIT(x0, trafo_width, 0);
449
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 24022 times.
24022 TRANSFORM_UNIT(x0 + trafo_width, tu_width - trafo_width, 1);
450
451 #undef TRANSFORM_UNIT
452 } else {
453 #define TRANSFORM_UNIT(y, height, idx) do { \
454 ret = hls_transform_unit(lc, x0, y, tu_width, height, idx, ch_type); \
455 if (ret < 0) \
456 return ret; \
457 } while (0)
458
459 21431 const int trafo_height = tu_height * lc->parse.sbt_num_fourths_tb0 / 4;
460
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 21431 times.
21431 TRANSFORM_UNIT(y0, trafo_height, 0);
461
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 21431 times.
21431 TRANSFORM_UNIT(y0 + trafo_height, tu_height - trafo_height, 1);
462
463 #undef TRANSFORM_UNIT
464 }
465
2/2
✓ Branch 0 taken 40327 times.
✓ Branch 1 taken 24880 times.
65207 } else if (cu->isp_split_type == ISP_HOR_SPLIT) {
466 40327 const int trafo_height = tu_height / cu->num_intra_subpartitions;
467
2/2
✓ Branch 0 taken 135048 times.
✓ Branch 1 taken 40327 times.
175375 for (int i = 0; i < cu->num_intra_subpartitions; i++) {
468 135048 ret = hls_transform_unit(lc, x0, y0 + trafo_height * i, tu_width, trafo_height, i, 0);
469
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 135048 times.
135048 if (ret < 0)
470 return ret;
471 }
472
1/2
✓ Branch 0 taken 24880 times.
✗ Branch 1 not taken.
24880 } else if (cu->isp_split_type == ISP_VER_SPLIT) {
473 24880 const int trafo_width = tu_width / cu->num_intra_subpartitions;
474
2/2
✓ Branch 0 taken 77382 times.
✓ Branch 1 taken 24880 times.
102262 for (int i = 0; i < cu->num_intra_subpartitions; i++) {
475 77382 ret = hls_transform_unit(lc, x0 + trafo_width * i , y0, trafo_width, tu_height, i, 0);
476
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 77382 times.
77382 if (ret < 0)
477 return ret;
478 }
479 }
480
481 1040839 return 0;
482 }
483
484 594541 static int skipped_transform_tree(VVCLocalContext *lc, int x0, int y0,int tu_width, int tu_height)
485 {
486 594541 VVCFrameContext *fc = lc->fc;
487 594541 const CodingUnit *cu = lc->cu;
488 594541 const VVCSPS *sps = fc->ps.sps;
489
490
4/4
✓ Branch 0 taken 482560 times.
✓ Branch 1 taken 111981 times.
✓ Branch 2 taken 2823 times.
✓ Branch 3 taken 479737 times.
709345 if (tu_width > sps->max_tb_size_y || tu_height > sps->max_tb_size_y) {
491
4/4
✓ Branch 0 taken 111981 times.
✓ Branch 1 taken 2823 times.
✓ Branch 2 taken 76282 times.
✓ Branch 3 taken 35699 times.
114804 const int ver_split_first = tu_width > sps->max_tb_size_y && tu_width > tu_height;
492
2/2
✓ Branch 0 taken 76282 times.
✓ Branch 1 taken 38522 times.
114804 const int trafo_width = ver_split_first ? (tu_width / 2) : tu_width;
493
2/2
✓ Branch 0 taken 38522 times.
✓ Branch 1 taken 76282 times.
114804 const int trafo_height = !ver_split_first ? (tu_height / 2) : tu_height;
494
495 #define SKIPPED_TRANSFORM_TREE(x, y) do { \
496 int ret = skipped_transform_tree(lc, x, y, trafo_width, trafo_height); \
497 if (ret < 0) \
498 return ret; \
499 } while (0)
500
501
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 114804 times.
114804 SKIPPED_TRANSFORM_TREE(x0, y0);
502
2/2
✓ Branch 0 taken 76282 times.
✓ Branch 1 taken 38522 times.
114804 if (ver_split_first)
503
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 76282 times.
76282 SKIPPED_TRANSFORM_TREE(x0 + trafo_width, y0);
504 else
505
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 38522 times.
38522 SKIPPED_TRANSFORM_TREE(x0, y0 + trafo_height);
506 } else {
507 479737 TransformUnit *tu = add_tu(fc, lc->cu, x0, y0, tu_width, tu_height);
508 int start, end;
509
510
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 479737 times.
479737 if (!tu)
511 return AVERROR_INVALIDDATA;
512 479737 ff_vvc_channel_range(&start, &end, cu->tree_type, sps->r->sps_chroma_format_idc);
513
2/2
✓ Branch 0 taken 1335279 times.
✓ Branch 1 taken 479737 times.
1815016 for (int i = start; i < end; i++) {
514 1335279 TransformBlock *tb = add_tb(tu, lc, x0, y0, tu_width >> sps->hshift[i], tu_height >> sps->vshift[i], i);
515
2/2
✓ Branch 0 taken 907508 times.
✓ Branch 1 taken 427771 times.
1335279 if (i != CR)
516 907508 set_tb_size(fc, tb);
517 }
518 }
519
520 594541 return 0;
521 }
522
523 //6.4.1 Allowed quad split process
524 //6.4.2 Allowed binary split process
525 //6.4.3 Allowed ternary split process
526 2277042 static void can_split(const VVCLocalContext *lc, int x0, int y0,int cb_width, int cb_height,
527 int mtt_depth, int depth_offset, int part_idx, VVCSplitMode last_split_mode,
528 VVCTreeType tree_type, VVCModeType mode_type, VVCAllowedSplit* split)
529 {
530 int min_qt_size, max_bt_size, max_tt_size, max_mtt_depth;
531 2277042 const VVCFrameContext *fc = lc->fc;
532 2277042 const VVCSH *sh = &lc->sc->sh;
533 2277042 const VVCSPS *sps = fc->ps.sps;
534 2277042 const VVCPPS *pps = fc->ps.pps;
535 2277042 const int chroma = tree_type == DUAL_TREE_CHROMA;
536 2277042 int min_cb_size_y = sps->min_cb_size_y;
537 2277042 int *qt = &split->qt;
538 2277042 int *btv = &split->btv;
539 2277042 int *bth = &split->bth;
540 2277042 int *ttv = &split->ttv;
541 2277042 int *tth = &split->tth;
542
543 2277042 *qt = *bth = *btv = *tth = *ttv = 1;
544
545
2/2
✓ Branch 0 taken 1741893 times.
✓ Branch 1 taken 535149 times.
2277042 if (mtt_depth)
546 1741893 *qt = 0;
547
548 2277042 min_qt_size = sh->min_qt_size[chroma];
549
2/2
✓ Branch 0 taken 966923 times.
✓ Branch 1 taken 1310119 times.
2277042 if (cb_width <= min_qt_size)
550 966923 *qt = 0;
551
552
2/2
✓ Branch 0 taken 296345 times.
✓ Branch 1 taken 1980697 times.
2277042 if (chroma) {
553 296345 int chroma_area = (cb_width >> sps->hshift[1]) * (cb_height >> sps->vshift[1]);
554 296345 int chroma_width = cb_width >> sps->hshift[1];
555
556
2/2
✓ Branch 0 taken 92792 times.
✓ Branch 1 taken 203553 times.
296345 if (chroma_width == 8)
557 92792 *ttv = 0;
558
2/2
✓ Branch 0 taken 75837 times.
✓ Branch 1 taken 127716 times.
203553 else if (chroma_width <= 4) {
559
1/2
✓ Branch 0 taken 75837 times.
✗ Branch 1 not taken.
75837 if (chroma_width == 4)
560 75837 *btv = 0;
561 75837 *qt = 0;
562 }
563
2/2
✓ Branch 0 taken 33558 times.
✓ Branch 1 taken 262787 times.
296345 if (mode_type == MODE_TYPE_INTRA)
564 33558 *qt = *btv = *bth = *ttv = *tth = 0;
565
2/2
✓ Branch 0 taken 108891 times.
✓ Branch 1 taken 187454 times.
296345 if (chroma_area <= 32) {
566 108891 *ttv = *tth = 0;
567
2/2
✓ Branch 0 taken 48796 times.
✓ Branch 1 taken 60095 times.
108891 if (chroma_area <= 16)
568 48796 *btv = *bth = 0;
569 }
570 }
571 2277042 max_bt_size = sh->max_bt_size[chroma];
572 2277042 max_tt_size = sh->max_tt_size[chroma];
573 2277042 max_mtt_depth = sh->max_mtt_depth[chroma] + depth_offset;
574
575
2/2
✓ Branch 0 taken 71682 times.
✓ Branch 1 taken 2205360 times.
2277042 if (mode_type == MODE_TYPE_INTER) {
576 71682 int area = cb_width * cb_height;
577
2/2
✓ Branch 0 taken 29760 times.
✓ Branch 1 taken 41922 times.
71682 if (area == 32)
578 29760 *btv = *bth = 0;
579
2/2
✓ Branch 0 taken 24870 times.
✓ Branch 1 taken 17052 times.
41922 else if (area == 64)
580 24870 *ttv = *tth = 0;
581 }
582
2/2
✓ Branch 0 taken 957378 times.
✓ Branch 1 taken 1319664 times.
2277042 if (cb_width <= 2 * min_cb_size_y) {
583 957378 *ttv = 0;
584
2/2
✓ Branch 0 taken 362872 times.
✓ Branch 1 taken 594506 times.
957378 if (cb_width <= min_cb_size_y)
585 362872 *btv = 0;
586 }
587
2/2
✓ Branch 0 taken 1043968 times.
✓ Branch 1 taken 1233074 times.
2277042 if (cb_height <= 2 * min_cb_size_y) {
588 1043968 *tth = 0;
589
2/2
✓ Branch 0 taken 418879 times.
✓ Branch 1 taken 625089 times.
1043968 if (cb_height <= min_cb_size_y)
590 418879 *bth = 0;
591 }
592
4/4
✓ Branch 0 taken 2211916 times.
✓ Branch 1 taken 65126 times.
✓ Branch 2 taken 705 times.
✓ Branch 3 taken 2211211 times.
2277042 if (cb_width > max_bt_size || cb_height > max_bt_size)
593 65831 *btv = *bth = 0;
594 2277042 max_tt_size = FFMIN(64, max_tt_size);
595
4/4
✓ Branch 0 taken 2135507 times.
✓ Branch 1 taken 141535 times.
✓ Branch 2 taken 8548 times.
✓ Branch 3 taken 2126959 times.
2277042 if (cb_width > max_tt_size || cb_height > max_tt_size)
596 150083 *ttv = *tth = 0;
597
2/2
✓ Branch 0 taken 468508 times.
✓ Branch 1 taken 1808534 times.
2277042 if (mtt_depth >= max_mtt_depth)
598 468508 *btv = *bth = *ttv = *tth = 0;
599
2/2
✓ Branch 0 taken 5029 times.
✓ Branch 1 taken 2272013 times.
2277042 if (x0 + cb_width > pps->width) {
600 5029 *ttv = *tth = 0;
601
2/2
✓ Branch 0 taken 1491 times.
✓ Branch 1 taken 3538 times.
5029 if (cb_height > 64)
602 1491 *btv = 0;
603
2/2
✓ Branch 0 taken 3735 times.
✓ Branch 1 taken 1294 times.
5029 if (y0 + cb_height <= pps->height)
604 3735 *bth = 0;
605
2/2
✓ Branch 0 taken 1240 times.
✓ Branch 1 taken 54 times.
1294 else if (cb_width > min_qt_size)
606 1240 *btv = *bth = 0;
607 }
608
2/2
✓ Branch 0 taken 56041 times.
✓ Branch 1 taken 2221001 times.
2277042 if (y0 + cb_height > pps->height) {
609 56041 *btv = *ttv = *tth = 0;
610
2/2
✓ Branch 0 taken 7378 times.
✓ Branch 1 taken 48663 times.
56041 if (cb_width > 64)
611 7378 *bth = 0;
612 }
613
4/4
✓ Branch 0 taken 1741893 times.
✓ Branch 1 taken 535149 times.
✓ Branch 2 taken 752854 times.
✓ Branch 3 taken 989039 times.
2277042 if (mtt_depth > 0 && part_idx == 1) {
614
2/2
✓ Branch 0 taken 89934 times.
✓ Branch 1 taken 662920 times.
752854 if (last_split_mode == SPLIT_TT_VER)
615 89934 *btv = 0;
616
2/2
✓ Branch 0 taken 95287 times.
✓ Branch 1 taken 567633 times.
662920 else if (last_split_mode == SPLIT_TT_HOR)
617 95287 *bth = 0;
618 }
619
4/4
✓ Branch 0 taken 2226795 times.
✓ Branch 1 taken 50247 times.
✓ Branch 2 taken 3356 times.
✓ Branch 3 taken 2223439 times.
2277042 if (cb_width <= 64 && cb_height > 64)
620 3356 *btv = 0;
621
4/4
✓ Branch 0 taken 50247 times.
✓ Branch 1 taken 2226795 times.
✓ Branch 2 taken 3466 times.
✓ Branch 3 taken 46781 times.
2277042 if (cb_width > 64 && cb_height <= 64)
622 3466 *bth = 0;
623 2277042 }
624
625 506878 static int get_num_intra_subpartitions(enum IspType isp_split_type, int cb_width, int cb_height)
626 {
627
2/2
✓ Branch 0 taken 441671 times.
✓ Branch 1 taken 65207 times.
506878 if (isp_split_type == ISP_NO_SPLIT)
628 441671 return 1;
629
8/8
✓ Branch 0 taken 15617 times.
✓ Branch 1 taken 49590 times.
✓ Branch 2 taken 4401 times.
✓ Branch 3 taken 11216 times.
✓ Branch 4 taken 23710 times.
✓ Branch 5 taken 30281 times.
✓ Branch 6 taken 12983 times.
✓ Branch 7 taken 10727 times.
65207 if ((cb_width == 4 && cb_height == 8) || (cb_width == 8 && cb_height == 4))
630 24199 return 2;
631 41008 return 4;
632 }
633
634 256621 static int get_cclm_enabled(const VVCLocalContext *lc, const int x0, const int y0)
635 {
636 256621 const VVCFrameContext *fc = lc->fc;
637 256621 const VVCSPS *sps = fc->ps.sps;
638 256621 int enabled = 0;
639
640
2/2
✓ Branch 0 taken 449 times.
✓ Branch 1 taken 256172 times.
256621 if (!sps->r->sps_cclm_enabled_flag)
641 449 return 0;
642
6/6
✓ Branch 0 taken 223533 times.
✓ Branch 1 taken 32639 times.
✓ Branch 2 taken 159161 times.
✓ Branch 3 taken 64372 times.
✓ Branch 4 taken 2153 times.
✓ Branch 5 taken 157008 times.
256172 if (!sps->r->sps_qtbtt_dual_tree_intra_flag || !IS_I(lc->sc->sh.r) || sps->ctb_log2_size_y < 6)
643 99164 return 1;
644 else {
645 157008 const int x64 = x0 >> 6 << 6;
646 157008 const int y64 = y0 >> 6 << 6;
647 157008 const int y32 = y0 >> 5 << 5;
648 157008 const int x64_cu = x64 >> fc->ps.sps->min_cb_log2_size_y;
649 157008 const int y64_cu = y64 >> fc->ps.sps->min_cb_log2_size_y;
650 157008 const int y32_cu = y32 >> fc->ps.sps->min_cb_log2_size_y;
651 157008 const int min_cb_width = fc->ps.pps->min_cb_width;
652 157008 const int depth = SAMPLE_CTB(fc->tab.cqt_depth[1], x64_cu, y64_cu);
653 157008 const int min_depth = fc->ps.sps->ctb_log2_size_y - 6;
654 157008 const VVCSplitMode msm64 = (VVCSplitMode)TAB_MSM(fc, 0, x64, y64);
655 157008 const VVCSplitMode msm32 = (VVCSplitMode)TAB_MSM(fc, 1, x64, y32);
656
657
2/2
✓ Branch 0 taken 19375 times.
✓ Branch 1 taken 137633 times.
176383 enabled = SAMPLE_CTB(fc->tab.cb_width[1], x64_cu, y64_cu) == 64 &&
658
2/2
✓ Branch 0 taken 6527 times.
✓ Branch 1 taken 12848 times.
19375 SAMPLE_CTB(fc->tab.cb_height[1], x64_cu, y64_cu) == 64;
659
2/2
✓ Branch 0 taken 21666 times.
✓ Branch 1 taken 16231 times.
37897 enabled |= depth == min_depth && msm64 == SPLIT_BT_HOR &&
660
4/4
✓ Branch 0 taken 37897 times.
✓ Branch 1 taken 119111 times.
✓ Branch 2 taken 12084 times.
✓ Branch 3 taken 9582 times.
206989 SAMPLE_CTB(fc->tab.cb_width[1], x64_cu, y32_cu) == 64 &&
661
2/2
✓ Branch 0 taken 4734 times.
✓ Branch 1 taken 7350 times.
12084 SAMPLE_CTB(fc->tab.cb_height[1], x64_cu, y32_cu) == 32;
662 157008 enabled |= depth > min_depth;
663
6/6
✓ Branch 0 taken 37897 times.
✓ Branch 1 taken 119111 times.
✓ Branch 2 taken 21666 times.
✓ Branch 3 taken 16231 times.
✓ Branch 4 taken 7990 times.
✓ Branch 5 taken 13676 times.
157008 enabled |= depth == min_depth && msm64 == SPLIT_BT_HOR && msm32 == SPLIT_BT_VER;
664
665
2/2
✓ Branch 0 taken 137905 times.
✓ Branch 1 taken 19103 times.
157008 if (enabled) {
666 137905 const int w = SAMPLE_CTB(fc->tab.cb_width[0], x64_cu, y64_cu);
667 137905 const int h = SAMPLE_CTB(fc->tab.cb_height[0], x64_cu, y64_cu);
668 137905 const int depth0 = SAMPLE_CTB(fc->tab.cqt_depth[0], x64_cu, y64_cu);
669
8/8
✓ Branch 0 taken 5746 times.
✓ Branch 1 taken 132159 times.
✓ Branch 2 taken 5556 times.
✓ Branch 3 taken 190 times.
✓ Branch 4 taken 4964 times.
✓ Branch 5 taken 592 times.
✓ Branch 6 taken 5154 times.
✓ Branch 7 taken 132159 times.
137905 if ((w == 64 && h == 64 && TAB_ISPMF(fc, x64, y64)) ||
670
4/4
✓ Branch 0 taken 190 times.
✓ Branch 1 taken 4964 times.
✓ Branch 2 taken 1286 times.
✓ Branch 3 taken 131063 times.
137313 ((w < 64 || h < 64) && depth0 == min_depth))
671 1878 return 0;
672 }
673
674 }
675
676 155130 return enabled;
677 }
678
679 900485 static int less(const void *a, const void *b)
680 {
681 900485 return *(const int*)a - *(const int*)b;
682 }
683
684 //8.4.2 Derivation process for luma intra prediction mode
685 506878 static enum IntraPredMode luma_intra_pred_mode(VVCLocalContext* lc, const int intra_subpartitions_mode_flag)
686 {
687 506878 VVCFrameContext *fc = lc->fc;
688 506878 CodingUnit *cu = lc->cu;
689 506878 const int x0 = cu->x0;
690 506878 const int y0 = cu->y0;
691 enum IntraPredMode pred;
692 506878 int intra_luma_not_planar_flag = 1;
693 506878 int intra_luma_mpm_remainder = 0;
694 506878 int intra_luma_mpm_flag = 1;
695 506878 int intra_luma_mpm_idx = 0;
696
697
2/2
✓ Branch 0 taken 461746 times.
✓ Branch 1 taken 45132 times.
506878 if (!cu->intra_luma_ref_idx)
698 461746 intra_luma_mpm_flag = ff_vvc_intra_luma_mpm_flag(lc);
699
2/2
✓ Branch 0 taken 378538 times.
✓ Branch 1 taken 128340 times.
506878 if (intra_luma_mpm_flag) {
700
2/2
✓ Branch 0 taken 333406 times.
✓ Branch 1 taken 45132 times.
378538 if (!cu->intra_luma_ref_idx)
701 333406 intra_luma_not_planar_flag = ff_vvc_intra_luma_not_planar_flag(lc, intra_subpartitions_mode_flag);
702
2/2
✓ Branch 0 taken 203367 times.
✓ Branch 1 taken 175171 times.
378538 if (intra_luma_not_planar_flag)
703 203367 intra_luma_mpm_idx = ff_vvc_intra_luma_mpm_idx(lc);
704 } else {
705 128340 intra_luma_mpm_remainder = ff_vvc_intra_luma_mpm_remainder(lc);
706 }
707
708
2/2
✓ Branch 0 taken 175171 times.
✓ Branch 1 taken 331707 times.
506878 if (!intra_luma_not_planar_flag) {
709 175171 pred = INTRA_PLANAR;
710 } else {
711 331707 const VVCSPS *sps = fc->ps.sps;
712 331707 const int x_a = (x0 - 1) >> sps->min_cb_log2_size_y;
713 331707 const int y_a = (y0 + cu->cb_height - 1) >> sps->min_cb_log2_size_y;
714 331707 const int x_b = (x0 + cu->cb_width - 1) >> sps->min_cb_log2_size_y;
715 331707 const int y_b = (y0 - 1) >> sps->min_cb_log2_size_y;
716 331707 int min_cb_width = fc->ps.pps->min_cb_width;
717 331707 int x0b = av_zero_extend(x0, sps->ctb_log2_size_y);
718 331707 int y0b = av_zero_extend(y0, sps->ctb_log2_size_y);
719
4/4
✓ Branch 0 taken 74484 times.
✓ Branch 1 taken 257223 times.
✓ Branch 2 taken 68418 times.
✓ Branch 3 taken 6066 times.
331707 const int available_l = lc->ctb_left_flag || x0b;
720
4/4
✓ Branch 0 taken 118817 times.
✓ Branch 1 taken 212890 times.
✓ Branch 2 taken 112174 times.
✓ Branch 3 taken 6643 times.
331707 const int available_u = lc->ctb_up_flag || y0b;
721
722 int a, b, cand[5];
723
724
4/4
✓ Branch 0 taken 325641 times.
✓ Branch 1 taken 6066 times.
✓ Branch 2 taken 291917 times.
✓ Branch 3 taken 33724 times.
331707 if (!available_l || (SAMPLE_CTB(fc->tab.cpm[0], x_a, y_a) != MODE_INTRA) ||
725
2/2
✓ Branch 0 taken 40146 times.
✓ Branch 1 taken 251771 times.
291917 SAMPLE_CTB(fc->tab.imf, x_a, y_a)) {
726 79936 a = INTRA_PLANAR;
727 } else {
728 251771 a = SAMPLE_CTB(fc->tab.ipm, x_a, y_a);
729 }
730
731
4/4
✓ Branch 0 taken 325064 times.
✓ Branch 1 taken 6643 times.
✓ Branch 2 taken 289465 times.
✓ Branch 3 taken 35599 times.
331707 if (!available_u || (SAMPLE_CTB(fc->tab.cpm[0], x_b, y_b) != MODE_INTRA) ||
732
4/4
✓ Branch 0 taken 249111 times.
✓ Branch 1 taken 40354 times.
✓ Branch 2 taken 14772 times.
✓ Branch 3 taken 234339 times.
289465 SAMPLE_CTB(fc->tab.imf, x_b, y_b) || !y0b) {
733 97368 b = INTRA_PLANAR;
734 } else {
735 234339 b = SAMPLE_CTB(fc->tab.ipm, x_b, y_b);
736 }
737
738
4/4
✓ Branch 0 taken 103340 times.
✓ Branch 1 taken 228367 times.
✓ Branch 2 taken 20235 times.
✓ Branch 3 taken 83105 times.
331707 if (a == b && a > INTRA_DC) {
739 20235 cand[0] = a;
740 20235 cand[1] = 2 + ((a + 61) % 64);
741 20235 cand[2] = 2 + ((a - 1) % 64);
742 20235 cand[3] = 2 + ((a + 60) % 64);
743 20235 cand[4] = 2 + (a % 64);
744 } else {
745 311472 const int minab = FFMIN(a, b);
746 311472 const int maxab = FFMAX(a, b);
747
4/4
✓ Branch 0 taken 150381 times.
✓ Branch 1 taken 161091 times.
✓ Branch 2 taken 74141 times.
✓ Branch 3 taken 76240 times.
385613 if (a > INTRA_DC && b > INTRA_DC) {
748 74141 const int diff = maxab - minab;
749 74141 cand[0] = a;
750 74141 cand[1] = b;
751
2/2
✓ Branch 0 taken 14592 times.
✓ Branch 1 taken 59549 times.
74141 if (diff == 1) {
752 14592 cand[2] = 2 + ((minab + 61) % 64);
753 14592 cand[3] = 2 + ((maxab - 1) % 64);
754 14592 cand[4] = 2 + ((minab + 60) % 64);
755
2/2
✓ Branch 0 taken 587 times.
✓ Branch 1 taken 58962 times.
59549 } else if (diff >= 62) {
756 587 cand[2] = 2 + ((minab - 1) % 64);
757 587 cand[3] = 2 + ((maxab + 61) % 64);
758 587 cand[4] = 2 + (minab % 64);
759
2/2
✓ Branch 0 taken 6930 times.
✓ Branch 1 taken 52032 times.
58962 } else if (diff == 2) {
760 6930 cand[2] = 2 + ((minab - 1) % 64);
761 6930 cand[3] = 2 + ((minab + 61) % 64);
762 6930 cand[4] = 2 + ((maxab - 1) % 64);
763 } else {
764 52032 cand[2] = 2 + ((minab + 61) % 64);
765 52032 cand[3] = 2 + ((minab - 1) % 64);
766 52032 cand[4] = 2 + ((maxab + 61) % 64);
767 }
768
4/4
✓ Branch 0 taken 161091 times.
✓ Branch 1 taken 76240 times.
✓ Branch 2 taken 62838 times.
✓ Branch 3 taken 98253 times.
237331 } else if (a > INTRA_DC || b > INTRA_DC) {
769 139078 cand[0] = maxab;
770 139078 cand[1] = 2 + ((maxab + 61 ) % 64);
771 139078 cand[2] = 2 + ((maxab - 1) % 64);
772 139078 cand[3] = 2 + ((maxab + 60 ) % 64);
773 139078 cand[4] = 2 + (maxab % 64);
774 } else {
775 98253 cand[0] = INTRA_DC;
776 98253 cand[1] = INTRA_VERT;
777 98253 cand[2] = INTRA_HORZ;
778 98253 cand[3] = INTRA_VERT - 4;
779 98253 cand[4] = INTRA_VERT + 4;
780 }
781 }
782
2/2
✓ Branch 0 taken 203367 times.
✓ Branch 1 taken 128340 times.
331707 if (intra_luma_mpm_flag) {
783 203367 pred = cand[intra_luma_mpm_idx];
784 } else {
785 128340 qsort(cand, FF_ARRAY_ELEMS(cand), sizeof(cand[0]), less);
786 128340 pred = intra_luma_mpm_remainder + 1;
787
2/2
✓ Branch 0 taken 641700 times.
✓ Branch 1 taken 128340 times.
770040 for (int i = 0; i < FF_ARRAY_ELEMS(cand); i++) {
788
2/2
✓ Branch 0 taken 315375 times.
✓ Branch 1 taken 326325 times.
641700 if (pred >= cand[i])
789 315375 pred++;
790 }
791 }
792 }
793 506878 return pred;
794 }
795
796 1014971 static int lfnst_idx_decode(VVCLocalContext *lc)
797 {
798 1014971 CodingUnit *cu = lc->cu;
799 1014971 const VVCTreeType tree_type = cu->tree_type;
800 1014971 const VVCSPS *sps = lc->fc->ps.sps;
801 1014971 const int cb_width = cu->cb_width;
802 1014971 const int cb_height = cu->cb_height;
803 1014971 const TransformUnit *tu = cu->tus.head;
804 int lfnst_width, lfnst_height, min_lfnst;
805 1014971 int lfnst_idx = 0;
806
807 1014971 memset(cu->apply_lfnst_flag, 0, sizeof(cu->apply_lfnst_flag));
808
809
6/6
✓ Branch 0 taken 788683 times.
✓ Branch 1 taken 226288 times.
✓ Branch 2 taken 648614 times.
✓ Branch 3 taken 140069 times.
✓ Branch 4 taken 1990 times.
✓ Branch 5 taken 646624 times.
1014971 if (!sps->r->sps_lfnst_enabled_flag || cu->pred_mode != MODE_INTRA || FFMAX(cb_width, cb_height) > sps->max_tb_size_y)
810 368347 return 0;
811
812
2/2
✓ Branch 0 taken 759966 times.
✓ Branch 1 taken 623845 times.
1383811 while (tu) {
813
2/2
✓ Branch 0 taken 1017030 times.
✓ Branch 1 taken 737187 times.
1754217 for (int j = 0; j < tu->nb_tbs; j++) {
814 1017030 const TransformBlock *tb = tu->tbs + j;
815
4/4
✓ Branch 0 taken 631345 times.
✓ Branch 1 taken 385685 times.
✓ Branch 2 taken 22779 times.
✓ Branch 3 taken 608566 times.
1017030 if (tu->coded_flag[tb->c_idx] && tb->ts)
816 22779 return 0;
817 }
818 737187 tu = tu->next;
819 }
820
821
2/2
✓ Branch 0 taken 152087 times.
✓ Branch 1 taken 471758 times.
623845 if (tree_type == DUAL_TREE_CHROMA) {
822 152087 lfnst_width = cb_width >> sps->hshift[1];
823 152087 lfnst_height = cb_height >> sps->vshift[1];
824 } else {
825 471758 const int vs = cu->isp_split_type == ISP_VER_SPLIT;
826 471758 const int hs = cu->isp_split_type == ISP_HOR_SPLIT;
827
2/2
✓ Branch 0 taken 18415 times.
✓ Branch 1 taken 453343 times.
471758 lfnst_width = vs ? cb_width / cu->num_intra_subpartitions : cb_width;
828
2/2
✓ Branch 0 taken 32047 times.
✓ Branch 1 taken 439711 times.
471758 lfnst_height = hs ? cb_height / cu->num_intra_subpartitions : cb_height;
829 }
830 623845 min_lfnst = FFMIN(lfnst_width, lfnst_height);
831
6/6
✓ Branch 0 taken 471758 times.
✓ Branch 1 taken 152087 times.
✓ Branch 2 taken 106776 times.
✓ Branch 3 taken 364982 times.
✓ Branch 4 taken 86667 times.
✓ Branch 5 taken 20109 times.
623845 if (tree_type != DUAL_TREE_CHROMA && cu->intra_mip_flag && min_lfnst < 16)
832 86667 return 0;
833
834
2/2
✓ Branch 0 taken 497583 times.
✓ Branch 1 taken 39595 times.
537178 if (min_lfnst >= 4) {
835
6/6
✓ Branch 0 taken 469108 times.
✓ Branch 1 taken 28475 times.
✓ Branch 2 taken 196087 times.
✓ Branch 3 taken 273021 times.
✓ Branch 4 taken 190512 times.
✓ Branch 5 taken 34050 times.
497583 if ((cu->isp_split_type != ISP_NO_SPLIT || !lc->parse.lfnst_dc_only) && lc->parse.lfnst_zero_out_sig_coeff_flag)
836 190512 lfnst_idx = ff_vvc_lfnst_idx(lc, tree_type != SINGLE_TREE);
837 }
838
839
2/2
✓ Branch 0 taken 141772 times.
✓ Branch 1 taken 395406 times.
537178 if (lfnst_idx) {
840 141772 cu->apply_lfnst_flag[LUMA] = tree_type != DUAL_TREE_CHROMA;
841 141772 cu->apply_lfnst_flag[CB] = cu->apply_lfnst_flag[CR] = tree_type == DUAL_TREE_CHROMA;
842 }
843
844 537178 return lfnst_idx;
845 }
846
847 1014971 static MtsIdx mts_idx_decode(VVCLocalContext *lc)
848 {
849 1014971 const CodingUnit *cu = lc->cu;
850 1014971 const VVCSPS *sps = lc->fc->ps.sps;
851 1014971 const int cb_width = cu->cb_width;
852 1014971 const int cb_height = cu->cb_height;
853 1014971 const uint8_t transform_skip_flag = cu->tus.head->tbs[0].ts; //fix me
854 1014971 int mts_idx = MTS_DCT2_DCT2;
855
6/6
✓ Branch 0 taken 822249 times.
✓ Branch 1 taken 192722 times.
✓ Branch 2 taken 715045 times.
✓ Branch 3 taken 107204 times.
✓ Branch 4 taken 664115 times.
✓ Branch 5 taken 50930 times.
1014971 if (cu->tree_type != DUAL_TREE_CHROMA && !cu->lfnst_idx &&
856
2/2
✓ Branch 0 taken 641049 times.
✓ Branch 1 taken 23066 times.
664115 !transform_skip_flag && FFMAX(cb_width, cb_height) <= 32 &&
857
4/4
✓ Branch 0 taken 593160 times.
✓ Branch 1 taken 47889 times.
✓ Branch 2 taken 549306 times.
✓ Branch 3 taken 43854 times.
641049 cu->isp_split_type == ISP_NO_SPLIT && !cu->sbt_flag &&
858
4/4
✓ Branch 0 taken 540353 times.
✓ Branch 1 taken 8953 times.
✓ Branch 2 taken 334696 times.
✓ Branch 3 taken 205657 times.
549306 lc->parse.mts_zero_out_sig_coeff_flag && !lc->parse.mts_dc_only) {
859
4/4
✓ Branch 0 taken 59423 times.
✓ Branch 1 taken 275273 times.
✓ Branch 2 taken 56957 times.
✓ Branch 3 taken 2466 times.
334696 if ((cu->pred_mode == MODE_INTER && sps->r->sps_explicit_mts_inter_enabled_flag) ||
860
4/4
✓ Branch 0 taken 270713 times.
✓ Branch 1 taken 61517 times.
✓ Branch 2 taken 250644 times.
✓ Branch 3 taken 20069 times.
332230 (cu->pred_mode == MODE_INTRA && sps->r->sps_explicit_mts_intra_enabled_flag)) {
861 253110 mts_idx = ff_vvc_mts_idx(lc);
862 }
863 }
864
865 1014971 return mts_idx;
866 }
867
868 261974 static enum IntraPredMode derive_center_luma_intra_pred_mode(const VVCFrameContext *fc, const VVCSPS *sps, const VVCPPS *pps, const CodingUnit *cu)
869 {
870 261974 const int x_center = (cu->x0 + cu->cb_width / 2) >> sps->min_cb_log2_size_y;
871 261974 const int y_center = (cu->y0 + cu->cb_height / 2) >> sps->min_cb_log2_size_y;
872 261974 const int min_cb_width = pps->min_cb_width;
873 261974 const int intra_mip_flag = SAMPLE_CTB(fc->tab.imf, x_center, y_center);
874 261974 const int cu_pred_mode = SAMPLE_CTB(fc->tab.cpm[0], x_center, y_center);
875 261974 const int intra_pred_mode_y = SAMPLE_CTB(fc->tab.ipm, x_center, y_center);
876
877
2/2
✓ Branch 0 taken 47430 times.
✓ Branch 1 taken 214544 times.
261974 if (intra_mip_flag) {
878
4/4
✓ Branch 0 taken 9600 times.
✓ Branch 1 taken 37830 times.
✓ Branch 2 taken 251 times.
✓ Branch 3 taken 9349 times.
47430 if (cu->tree_type == SINGLE_TREE && sps->r->sps_chroma_format_idc == CHROMA_FORMAT_444)
879 251 return INTRA_INVALID;
880 47179 return INTRA_PLANAR;
881 }
882
4/4
✓ Branch 0 taken 201011 times.
✓ Branch 1 taken 13533 times.
✓ Branch 2 taken 412 times.
✓ Branch 3 taken 200599 times.
214544 if (cu_pred_mode == MODE_IBC || cu_pred_mode == MODE_PLT)
883 13945 return INTRA_DC;
884 200599 return intra_pred_mode_y;
885 }
886
887 262761 static void derive_chroma_intra_pred_mode(VVCLocalContext *lc,
888 const int cclm_mode_flag, const int cclm_mode_idx, const int intra_chroma_pred_mode)
889 {
890 262761 const VVCFrameContext *fc = lc->fc;
891 262761 CodingUnit *cu = lc->cu;
892 262761 const VVCSPS *sps = fc->ps.sps;
893 262761 const VVCPPS *pps = fc->ps.pps;
894 262761 const int x_cb = cu->x0 >> sps->min_cb_log2_size_y;
895 262761 const int y_cb = cu->y0 >> sps->min_cb_log2_size_y;
896 262761 const int min_cb_width = pps->min_cb_width;
897 262761 const int intra_mip_flag = SAMPLE_CTB(fc->tab.imf, x_cb, y_cb);
898 262761 enum IntraPredMode luma_intra_pred_mode = SAMPLE_CTB(fc->tab.ipm, x_cb, y_cb);
899
900
6/6
✓ Branch 0 taken 70126 times.
✓ Branch 1 taken 192635 times.
✓ Branch 2 taken 10433 times.
✓ Branch 3 taken 59693 times.
✓ Branch 4 taken 7648 times.
✓ Branch 5 taken 2785 times.
262761 if (cu->tree_type == SINGLE_TREE && sps->r->sps_chroma_format_idc == CHROMA_FORMAT_444 &&
901
4/4
✓ Branch 0 taken 6140 times.
✓ Branch 1 taken 1508 times.
✓ Branch 2 taken 787 times.
✓ Branch 3 taken 8138 times.
10433 (intra_chroma_pred_mode == 4 || cu->act_enabled_flag) && intra_mip_flag) {
902 787 cu->mip_chroma_direct_flag = 1;
903 787 cu->intra_pred_mode_c = luma_intra_pred_mode;
904 787 return;
905 }
906 261974 luma_intra_pred_mode = derive_center_luma_intra_pred_mode(fc, sps, pps, cu);
907
908
2/2
✓ Branch 0 taken 5583 times.
✓ Branch 1 taken 256391 times.
261974 if (cu->act_enabled_flag) {
909 5583 cu->intra_pred_mode_c = luma_intra_pred_mode;
910 5583 return;
911 }
912
2/2
✓ Branch 0 taken 101418 times.
✓ Branch 1 taken 154973 times.
256391 if (cclm_mode_flag) {
913 101418 cu->intra_pred_mode_c = INTRA_LT_CCLM + cclm_mode_idx;
914
2/2
✓ Branch 0 taken 110520 times.
✓ Branch 1 taken 44453 times.
154973 } else if (intra_chroma_pred_mode == 4){
915 110520 cu->intra_pred_mode_c = luma_intra_pred_mode;
916 } else {
917 const static IntraPredMode pred_mode_c[][4 + 1] = {
918 {INTRA_VDIAG, INTRA_PLANAR, INTRA_PLANAR, INTRA_PLANAR, INTRA_PLANAR},
919 {INTRA_VERT, INTRA_VDIAG, INTRA_VERT, INTRA_VERT, INTRA_VERT},
920 {INTRA_HORZ, INTRA_HORZ, INTRA_VDIAG, INTRA_HORZ, INTRA_HORZ},
921 {INTRA_DC, INTRA_DC, INTRA_DC, INTRA_VDIAG, INTRA_DC},
922 };
923 44453 const int modes[4] = {INTRA_PLANAR, INTRA_VERT, INTRA_HORZ, INTRA_DC};
924 int idx;
925
926 // This workaround is necessary to have 4:4:4 video decode correctly
927 // See VVC ticket https://jvet.hhi.fraunhofer.de/trac/vvc/ticket/1602
928 // and VTM source https://vcgit.hhi.fraunhofer.de/jvet/VVCSoftware_VTM/-/blob/master/source/Lib/CommonLib/UnitTools.cpp#L736
929
6/6
✓ Branch 0 taken 3416 times.
✓ Branch 1 taken 41037 times.
✓ Branch 2 taken 246 times.
✓ Branch 3 taken 3170 times.
✓ Branch 4 taken 43 times.
✓ Branch 5 taken 203 times.
44453 if (cu->tree_type == SINGLE_TREE && sps->r->sps_chroma_format_idc == CHROMA_FORMAT_444 && intra_mip_flag) {
930 43 idx = 4;
931 } else {
932
2/2
✓ Branch 0 taken 113053 times.
✓ Branch 1 taken 15333 times.
128386 for (idx = 0; idx < FF_ARRAY_ELEMS(modes); idx++) {
933
2/2
✓ Branch 0 taken 29077 times.
✓ Branch 1 taken 83976 times.
113053 if (modes[idx] == luma_intra_pred_mode)
934 29077 break;
935 }
936 }
937
938 44453 cu->intra_pred_mode_c = pred_mode_c[intra_chroma_pred_mode][idx];
939 }
940
4/4
✓ Branch 0 taken 23834 times.
✓ Branch 1 taken 232557 times.
✓ Branch 2 taken 15903 times.
✓ Branch 3 taken 7931 times.
256391 if (sps->r->sps_chroma_format_idc == CHROMA_FORMAT_422 && cu->intra_pred_mode_c <= INTRA_VDIAG) {
941 const static int mode_map_422[INTRA_VDIAG + 1] = {
942 0, 1, 61, 62, 63, 64, 65, 66, 2, 3, 5, 6, 8, 10, 12, 13,
943 14, 16, 18, 20, 22, 23, 24, 26, 28, 30, 31, 33, 34, 35, 36, 37,
944 38, 39, 40, 41, 41, 42, 43, 43, 44, 44, 45, 45, 46, 47, 48, 48,
945 49, 49, 50, 51, 51, 52, 52, 53, 54, 55, 55, 56, 56, 57, 57, 58,
946 59, 59, 60,
947 };
948 15903 cu->intra_pred_mode_c = mode_map_422[cu->intra_pred_mode_c];
949 }
950 }
951
952 294433 static av_always_inline uint8_t pack_mip_info(int intra_mip_flag,
953 int intra_mip_transposed_flag, int intra_mip_mode)
954 {
955 294433 return (intra_mip_mode << 2) | (intra_mip_transposed_flag << 1) | intra_mip_flag;
956 }
957
958 637162 static void intra_luma_pred_modes(VVCLocalContext *lc)
959 {
960 637162 VVCFrameContext *fc = lc->fc;
961 637162 const VVCSPS *sps = fc->ps.sps;
962 637162 const VVCPPS *pps = fc->ps.pps;
963 637162 CodingUnit *cu = lc->cu;
964 637162 const int log2_min_cb_size = sps->min_cb_log2_size_y;
965 637162 const int x0 = cu->x0;
966 637162 const int y0 = cu->y0;
967 637162 const int x_cb = x0 >> log2_min_cb_size;
968 637162 const int y_cb = y0 >> log2_min_cb_size;
969 637162 const int cb_width = cu->cb_width;
970 637162 const int cb_height = cu->cb_height;
971
972 637162 cu->intra_luma_ref_idx = 0;
973
6/6
✓ Branch 0 taken 59129 times.
✓ Branch 1 taken 578033 times.
✓ Branch 2 taken 58016 times.
✓ Branch 3 taken 1113 times.
✓ Branch 4 taken 57938 times.
✓ Branch 5 taken 78 times.
637162 if (sps->r->sps_bdpcm_enabled_flag && cb_width <= sps->max_ts_size && cb_height <= sps->max_ts_size)
974 57938 cu->bdpcm_flag[LUMA] = ff_vvc_intra_bdpcm_luma_flag(lc);
975
2/2
✓ Branch 0 taken 18949 times.
✓ Branch 1 taken 618213 times.
637162 if (cu->bdpcm_flag[LUMA]) {
976
2/2
✓ Branch 1 taken 9847 times.
✓ Branch 2 taken 9102 times.
18949 cu->intra_pred_mode_y = ff_vvc_intra_bdpcm_luma_dir_flag(lc) ? INTRA_VERT : INTRA_HORZ;
977 } else {
978
2/2
✓ Branch 0 taken 474655 times.
✓ Branch 1 taken 143558 times.
618213 if (sps->r->sps_mip_enabled_flag)
979 474655 cu->intra_mip_flag = ff_vvc_intra_mip_flag(lc, fc->tab.imf);
980
2/2
✓ Branch 0 taken 111335 times.
✓ Branch 1 taken 506878 times.
618213 if (cu->intra_mip_flag) {
981 111335 int intra_mip_transposed_flag = ff_vvc_intra_mip_transposed_flag(lc);
982 111335 int intra_mip_mode = ff_vvc_intra_mip_mode(lc);
983 111335 int x = y_cb * pps->min_cb_width + x_cb;
984
2/2
✓ Branch 0 taken 294433 times.
✓ Branch 1 taken 111335 times.
405768 for (int y = 0; y < (cb_height>>log2_min_cb_size); y++) {
985 294433 int width = cb_width>>log2_min_cb_size;
986 294433 const uint8_t mip_info = pack_mip_info(cu->intra_mip_flag,
987 intra_mip_transposed_flag, intra_mip_mode);
988 294433 memset(&fc->tab.imf[x], mip_info, width);
989 294433 x += pps->min_cb_width;
990 }
991 111335 cu->intra_pred_mode_y = intra_mip_mode;
992 } else {
993 506878 int intra_subpartitions_mode_flag = 0;
994
4/4
✓ Branch 0 taken 486838 times.
✓ Branch 1 taken 20040 times.
✓ Branch 2 taken 445971 times.
✓ Branch 3 taken 40867 times.
506878 if (sps->r->sps_mrl_enabled_flag && ((y0 % sps->ctb_size_y) > 0))
995 445971 cu->intra_luma_ref_idx = ff_vvc_intra_luma_ref_idx(lc);
996
4/4
✓ Branch 0 taken 486838 times.
✓ Branch 1 taken 20040 times.
✓ Branch 2 taken 441706 times.
✓ Branch 3 taken 45132 times.
506878 if (sps->r->sps_isp_enabled_flag && !cu->intra_luma_ref_idx &&
997
4/4
✓ Branch 0 taken 441266 times.
✓ Branch 1 taken 440 times.
✓ Branch 2 taken 440938 times.
✓ Branch 3 taken 328 times.
441706 (cb_width <= sps->max_tb_size_y && cb_height <= sps->max_tb_size_y) &&
998
2/2
✓ Branch 0 taken 374623 times.
✓ Branch 1 taken 66315 times.
440938 (cb_width * cb_height > MIN_TU_SIZE * MIN_TU_SIZE) &&
999
2/2
✓ Branch 0 taken 371225 times.
✓ Branch 1 taken 3398 times.
374623 !cu->act_enabled_flag)
1000 371225 intra_subpartitions_mode_flag = ff_vvc_intra_subpartitions_mode_flag(lc);
1001
4/4
✓ Branch 0 taken 98278 times.
✓ Branch 1 taken 408600 times.
✓ Branch 2 taken 21404 times.
✓ Branch 3 taken 76874 times.
506878 if (!(x0 & 63) && !(y0 & 63))
1002 21404 TAB_ISPMF(fc, x0, y0) = intra_subpartitions_mode_flag;
1003 506878 cu->isp_split_type = ff_vvc_isp_split_type(lc, intra_subpartitions_mode_flag);
1004 506878 cu->num_intra_subpartitions = get_num_intra_subpartitions(cu->isp_split_type, cb_width, cb_height);
1005 506878 cu->intra_pred_mode_y = luma_intra_pred_mode(lc, intra_subpartitions_mode_flag);
1006 }
1007 }
1008 637162 set_cb_tab(lc, fc->tab.ipm, cu->intra_pred_mode_y);
1009 637162 }
1010
1011 263019 static void intra_chroma_pred_modes(VVCLocalContext *lc)
1012 {
1013 263019 const VVCSPS *sps = lc->fc->ps.sps;
1014 263019 CodingUnit *cu = lc->cu;
1015 263019 const int hs = sps->hshift[CHROMA];
1016 263019 const int vs = sps->vshift[CHROMA];
1017 263019 int cclm_mode_flag = 0;
1018 263019 int cclm_mode_idx = 0;
1019 263019 int intra_chroma_pred_mode = 0;
1020
1021
2/2
✓ Branch 0 taken 256879 times.
✓ Branch 1 taken 6140 times.
263019 if (!cu->act_enabled_flag) {
1022 256879 cu->mip_chroma_direct_flag = 0;
1023
2/2
✓ Branch 0 taken 52194 times.
✓ Branch 1 taken 204685 times.
256879 if (sps->r->sps_bdpcm_enabled_flag &&
1024
2/2
✓ Branch 0 taken 50794 times.
✓ Branch 1 taken 1400 times.
52194 (cu->cb_width >> hs) <= sps->max_ts_size &&
1025
2/2
✓ Branch 0 taken 50258 times.
✓ Branch 1 taken 536 times.
50794 (cu->cb_height >> vs) <= sps->max_ts_size) {
1026 50258 cu->bdpcm_flag[CB] = cu->bdpcm_flag[CR] = ff_vvc_intra_bdpcm_chroma_flag(lc);
1027 }
1028
2/2
✓ Branch 0 taken 258 times.
✓ Branch 1 taken 256621 times.
256879 if (cu->bdpcm_flag[CHROMA]) {
1029
2/2
✓ Branch 1 taken 239 times.
✓ Branch 2 taken 19 times.
258 cu->intra_pred_mode_c = ff_vvc_intra_bdpcm_chroma_dir_flag(lc) ? INTRA_VERT : INTRA_HORZ;
1030 } else {
1031 256621 const int cclm_enabled = get_cclm_enabled(lc, cu->x0, cu->y0);
1032
1033
2/2
✓ Branch 0 taken 235191 times.
✓ Branch 1 taken 21430 times.
256621 if (cclm_enabled)
1034 235191 cclm_mode_flag = ff_vvc_cclm_mode_flag(lc);
1035
1036
2/2
✓ Branch 0 taken 101418 times.
✓ Branch 1 taken 155203 times.
256621 if (cclm_mode_flag)
1037 101418 cclm_mode_idx = ff_vvc_cclm_mode_idx(lc);
1038 else
1039 155203 intra_chroma_pred_mode = ff_vvc_intra_chroma_pred_mode(lc);
1040 }
1041 }
1042
1043
2/2
✓ Branch 0 taken 262761 times.
✓ Branch 1 taken 258 times.
263019 if (!cu->bdpcm_flag[CHROMA])
1044 262761 derive_chroma_intra_pred_mode(lc, cclm_mode_flag, cclm_mode_idx, intra_chroma_pred_mode);
1045 263019 }
1046
1047 1386881 static PredMode pred_mode_decode(VVCLocalContext *lc,
1048 const VVCTreeType tree_type,
1049 const VVCModeType mode_type)
1050 {
1051 1386881 const VVCFrameContext *fc = lc->fc;
1052 1386881 CodingUnit *cu = lc->cu;
1053 1386881 const VVCSPS *sps = fc->ps.sps;
1054 1386881 const H266RawSliceHeader *rsh = lc->sc->sh.r;
1055 1386881 const int ch_type = tree_type == DUAL_TREE_CHROMA ? 1 : 0;
1056
4/4
✓ Branch 0 taken 310963 times.
✓ Branch 1 taken 1075918 times.
✓ Branch 2 taken 130308 times.
✓ Branch 3 taken 180655 times.
1386881 const int is_4x4 = cu->cb_width == 4 && cu->cb_height == 4;
1057
4/4
✓ Branch 0 taken 1360478 times.
✓ Branch 1 taken 26403 times.
✓ Branch 2 taken 2342 times.
✓ Branch 3 taken 1358136 times.
1386881 const int is_128 = cu->cb_width == 128 || cu->cb_height == 128;
1058 1386881 const int hs = sps->hshift[CHROMA];
1059 1386881 const int vs = sps->vshift[CHROMA];
1060 int pred_mode_flag;
1061 int pred_mode_ibc_flag;
1062 PredMode pred_mode;
1063
1064 1386881 cu->skip_flag = 0;
1065
4/4
✓ Branch 0 taken 757312 times.
✓ Branch 1 taken 629569 times.
✓ Branch 2 taken 123657 times.
✓ Branch 3 taken 633655 times.
1386881 if (!IS_I(rsh) || sps->r->sps_ibc_enabled_flag) {
1066
4/4
✓ Branch 0 taken 714248 times.
✓ Branch 1 taken 38978 times.
✓ Branch 2 taken 648970 times.
✓ Branch 3 taken 65278 times.
753226 if (tree_type != DUAL_TREE_CHROMA &&
1067
2/2
✓ Branch 0 taken 62602 times.
✓ Branch 1 taken 586368 times.
648970 ((!is_4x4 && mode_type != MODE_TYPE_INTRA) ||
1068
3/4
✓ Branch 0 taken 99796 times.
✓ Branch 1 taken 28084 times.
✓ Branch 2 taken 99796 times.
✗ Branch 3 not taken.
127880 (sps->r->sps_ibc_enabled_flag && !is_128))) {
1069 686164 cu->skip_flag = ff_vvc_cu_skip_flag(lc, fc->tab.skip);
1070 }
1071
1072
6/6
✓ Branch 0 taken 687948 times.
✓ Branch 1 taken 65278 times.
✓ Branch 2 taken 593950 times.
✓ Branch 3 taken 93998 times.
✓ Branch 4 taken 78195 times.
✓ Branch 5 taken 515755 times.
753226 if (is_4x4 || mode_type == MODE_TYPE_INTRA || IS_I(rsh)) {
1073 237471 pred_mode_flag = 1;
1074
4/4
✓ Branch 0 taken 450032 times.
✓ Branch 1 taken 65723 times.
✓ Branch 2 taken 238107 times.
✓ Branch 3 taken 211925 times.
515755 } else if (mode_type == MODE_TYPE_INTER || cu->skip_flag) {
1075 303830 pred_mode_flag = 0;
1076 } else {
1077 211925 pred_mode_flag = ff_vvc_pred_mode_flag(lc, ch_type);
1078 }
1079 753226 pred_mode = pred_mode_flag ? MODE_INTRA : MODE_INTER;
1080
1081
4/4
✓ Branch 0 taken 123657 times.
✓ Branch 1 taken 629569 times.
✓ Branch 2 taken 11715 times.
✓ Branch 3 taken 111942 times.
753226 if (((IS_I(rsh) && !cu->skip_flag) ||
1082
6/6
✓ Branch 0 taken 629569 times.
✓ Branch 1 taken 11715 times.
✓ Branch 2 taken 162795 times.
✓ Branch 3 taken 466774 times.
✓ Branch 4 taken 115931 times.
✓ Branch 5 taken 46864 times.
641284 (!IS_I(rsh) && (pred_mode != MODE_INTRA ||
1083
6/6
✓ Branch 0 taken 66950 times.
✓ Branch 1 taken 48981 times.
✓ Branch 2 taken 104210 times.
✓ Branch 3 taken 9604 times.
✓ Branch 4 taken 654240 times.
✓ Branch 5 taken 28686 times.
741511 ((is_4x4 || mode_type == MODE_TYPE_INTRA) && !cu->skip_flag)))) &&
1084
6/6
✓ Branch 0 taken 588517 times.
✓ Branch 1 taken 65723 times.
✓ Branch 2 taken 219406 times.
✓ Branch 3 taken 369111 times.
✓ Branch 4 taken 189023 times.
✓ Branch 5 taken 30383 times.
654240 !is_128 && mode_type != MODE_TYPE_INTER && sps->r->sps_ibc_enabled_flag &&
1085 tree_type != DUAL_TREE_CHROMA) {
1086 189023 pred_mode_ibc_flag = ff_vvc_pred_mode_ibc_flag(lc, ch_type);
1087
6/6
✓ Branch 0 taken 265441 times.
✓ Branch 1 taken 298762 times.
✓ Branch 2 taken 258194 times.
✓ Branch 3 taken 7247 times.
✓ Branch 4 taken 4687 times.
✓ Branch 5 taken 253507 times.
564203 } else if (cu->skip_flag && (is_4x4 || mode_type == MODE_TYPE_INTRA)) {
1088 11934 pred_mode_ibc_flag = 1;
1089
6/6
✓ Branch 0 taken 523524 times.
✓ Branch 1 taken 28745 times.
✓ Branch 2 taken 457801 times.
✓ Branch 3 taken 65723 times.
✓ Branch 4 taken 38978 times.
✓ Branch 5 taken 418823 times.
552269 } else if (is_128 || mode_type == MODE_TYPE_INTER || tree_type == DUAL_TREE_CHROMA) {
1090 133446 pred_mode_ibc_flag = 0;
1091 } else {
1092
2/2
✓ Branch 0 taken 9385 times.
✓ Branch 1 taken 409438 times.
418823 pred_mode_ibc_flag = (IS_I(rsh)) ? sps->r->sps_ibc_enabled_flag : 0;
1093 }
1094
2/2
✓ Branch 0 taken 87174 times.
✓ Branch 1 taken 666052 times.
753226 if (pred_mode_ibc_flag)
1095 87174 pred_mode = MODE_IBC;
1096 } else {
1097 633655 pred_mode = MODE_INTRA;
1098 }
1099
1100
7/10
✓ Branch 0 taken 836861 times.
✓ Branch 1 taken 550020 times.
✓ Branch 2 taken 46324 times.
✓ Branch 3 taken 790537 times.
✓ Branch 4 taken 46324 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 46324 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 46324 times.
✗ Branch 9 not taken.
1386881 if (pred_mode == MODE_INTRA && sps->r->sps_palette_enabled_flag && !is_128 && !cu->skip_flag &&
1101
2/2
✓ Branch 0 taken 41331 times.
✓ Branch 1 taken 4993 times.
46324 mode_type != MODE_TYPE_INTER && ((cu->cb_width * cu->cb_height) >
1102
4/4
✓ Branch 0 taken 8906 times.
✓ Branch 1 taken 37418 times.
✓ Branch 2 taken 13392 times.
✓ Branch 3 taken 27939 times.
87655 (tree_type != DUAL_TREE_CHROMA ? 16 : (16 << hs << vs))) &&
1103
2/2
✓ Branch 0 taken 5582 times.
✓ Branch 1 taken 7810 times.
13392 (mode_type != MODE_TYPE_INTRA || tree_type != DUAL_TREE_CHROMA)) {
1104
2/2
✓ Branch 1 taken 6977 times.
✓ Branch 2 taken 26544 times.
33521 if (ff_vvc_pred_mode_plt_flag(lc))
1105 6977 pred_mode = MODE_PLT;
1106 }
1107
1108 1386881 set_cb_tab(lc, fc->tab.cpm[cu->ch_type], pred_mode);
1109
2/2
✓ Branch 0 taken 594513 times.
✓ Branch 1 taken 792368 times.
1386881 if (tree_type == SINGLE_TREE)
1110 594513 set_cb_tab(lc, fc->tab.cpm[CHROMA], pred_mode);
1111
1112 1386881 return pred_mode;
1113 }
1114
1115 1014971 static void sbt_info(VVCLocalContext *lc, const VVCSPS *sps)
1116 {
1117 1014971 CodingUnit *cu = lc->cu;
1118 1014971 const int cb_width = cu->cb_width;
1119 1014971 const int cb_height = cu->cb_height;
1120
1121
6/6
✓ Branch 0 taken 161683 times.
✓ Branch 1 taken 853288 times.
✓ Branch 2 taken 155340 times.
✓ Branch 3 taken 6343 times.
✓ Branch 4 taken 139437 times.
✓ Branch 5 taken 15903 times.
1014971 if (cu->pred_mode == MODE_INTER && sps->r->sps_sbt_enabled_flag && !cu->ciip_flag
1122
4/4
✓ Branch 0 taken 136583 times.
✓ Branch 1 taken 2854 times.
✓ Branch 2 taken 135700 times.
✓ Branch 3 taken 883 times.
139437 && cb_width <= sps->max_tb_size_y && cb_height <= sps->max_tb_size_y) {
1123 135700 const int sbt_ver_h = cb_width >= 8;
1124 135700 const int sbt_hor_h = cb_height >= 8;
1125 135700 cu->sbt_flag = 0;
1126
3/4
✓ Branch 0 taken 20760 times.
✓ Branch 1 taken 114940 times.
✓ Branch 2 taken 20760 times.
✗ Branch 3 not taken.
135700 if (sbt_ver_h || sbt_hor_h)
1127 135700 cu->sbt_flag = ff_vvc_sbt_flag(lc);
1128
2/2
✓ Branch 0 taken 45453 times.
✓ Branch 1 taken 90247 times.
135700 if (cu->sbt_flag) {
1129 45453 const int sbt_ver_q = cb_width >= 16;
1130 45453 const int sbt_hor_q = cb_height >= 16;
1131 45453 int cu_sbt_quad_flag = 0;
1132
1133
7/8
✓ Branch 0 taken 7617 times.
✓ Branch 1 taken 37836 times.
✓ Branch 2 taken 7617 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 25167 times.
✓ Branch 5 taken 20286 times.
✓ Branch 6 taken 12099 times.
✓ Branch 7 taken 13068 times.
45453 if ((sbt_ver_h || sbt_hor_h) && (sbt_ver_q || sbt_hor_q))
1134 32385 cu_sbt_quad_flag = ff_vvc_sbt_quad_flag(lc);
1135
2/2
✓ Branch 0 taken 11769 times.
✓ Branch 1 taken 33684 times.
45453 if (cu_sbt_quad_flag) {
1136 11769 cu->sbt_horizontal_flag = sbt_hor_q;
1137
4/4
✓ Branch 0 taken 7788 times.
✓ Branch 1 taken 3981 times.
✓ Branch 2 taken 3587 times.
✓ Branch 3 taken 4201 times.
11769 if (sbt_ver_q && sbt_hor_q)
1138 3587 cu->sbt_horizontal_flag = ff_vvc_sbt_horizontal_flag(lc);
1139 } else {
1140 33684 cu->sbt_horizontal_flag = sbt_hor_h;
1141
4/4
✓ Branch 0 taken 27602 times.
✓ Branch 1 taken 6082 times.
✓ Branch 2 taken 21950 times.
✓ Branch 3 taken 5652 times.
33684 if (sbt_ver_h && sbt_hor_h)
1142 21950 cu->sbt_horizontal_flag = ff_vvc_sbt_horizontal_flag(lc);
1143 }
1144 45453 cu->sbt_pos_flag = ff_vvc_sbt_pos_flag(lc);
1145
1146 {
1147
2/2
✓ Branch 0 taken 11769 times.
✓ Branch 1 taken 33684 times.
45453 const int sbt_min = cu_sbt_quad_flag ? 1 : 2;
1148
2/2
✓ Branch 0 taken 21749 times.
✓ Branch 1 taken 23704 times.
45453 lc->parse.sbt_num_fourths_tb0 = cu->sbt_pos_flag ? (4 - sbt_min) : sbt_min;
1149 }
1150 }
1151 }
1152 1014971 }
1153
1154 364933 static int skipped_transform_tree_unit(VVCLocalContext *lc)
1155 {
1156 364933 const H266RawSPS *rsps = lc->fc->ps.sps->r;
1157 364933 const CodingUnit *cu = lc->cu;
1158 int ret;
1159
1160
1/2
✓ Branch 0 taken 364933 times.
✗ Branch 1 not taken.
364933 if (cu->tree_type != DUAL_TREE_CHROMA) {
1161 364933 ret = set_qp_y(lc, cu->x0, cu->y0, 0);
1162
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 364933 times.
364933 if (ret < 0)
1163 return ret;
1164 }
1165
4/4
✓ Branch 0 taken 348422 times.
✓ Branch 1 taken 16511 times.
✓ Branch 2 taken 313137 times.
✓ Branch 3 taken 35285 times.
364933 if (rsps->sps_chroma_format_idc && cu->tree_type != DUAL_TREE_LUMA)
1166 313137 set_qp_c(lc);
1167 364933 ret = skipped_transform_tree(lc, cu->x0, cu->y0, cu->cb_width, cu->cb_height);
1168
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 364933 times.
364933 if (ret < 0)
1169 return ret;
1170 364933 return 0;
1171 }
1172
1173 1386881 static void set_cb_pos(const VVCFrameContext *fc, const CodingUnit *cu)
1174 {
1175 1386881 const VVCSPS *sps = fc->ps.sps;
1176 1386881 const VVCPPS *pps = fc->ps.pps;
1177 1386881 const int log2_min_cb_size = sps->min_cb_log2_size_y;
1178 1386881 const int x_cb = cu->x0 >> log2_min_cb_size;
1179 1386881 const int y_cb = cu->y0 >> log2_min_cb_size;
1180 1386881 const int ch_type = cu->ch_type;
1181 int x, y;
1182
1183 1386881 x = y_cb * pps->min_cb_width + x_cb;
1184
2/2
✓ Branch 0 taken 5692358 times.
✓ Branch 1 taken 1386881 times.
7079239 for (y = 0; y < (cu->cb_height >> log2_min_cb_size); y++) {
1185 5692358 const int width = cu->cb_width >> log2_min_cb_size;
1186
1187
2/2
✓ Branch 0 taken 54520740 times.
✓ Branch 1 taken 5692358 times.
60213098 for (int i = 0; i < width; i++) {
1188 54520740 fc->tab.cb_pos_x[ch_type][x + i] = cu->x0;
1189 54520740 fc->tab.cb_pos_y[ch_type][x + i] = cu->y0;
1190 }
1191 5692358 memset(&fc->tab.cb_width[ch_type][x], cu->cb_width, width);
1192 5692358 memset(&fc->tab.cb_height[ch_type][x], cu->cb_height, width);
1193 5692358 memset(&fc->tab.cqt_depth[ch_type][x], cu->cqt_depth, width);
1194
1195 5692358 x += pps->min_cb_width;
1196 }
1197 1386881 }
1198
1199 1386881 static CodingUnit* alloc_cu(VVCLocalContext *lc, const int x0, const int y0)
1200 {
1201 1386881 VVCFrameContext *fc = lc->fc;
1202 1386881 const VVCSPS *sps = fc->ps.sps;
1203 1386881 const VVCPPS *pps = fc->ps.pps;
1204 1386881 const int rx = x0 >> sps->ctb_log2_size_y;
1205 1386881 const int ry = y0 >> sps->ctb_log2_size_y;
1206 1386881 CodingUnit **cus = fc->tab.cus + ry * pps->ctb_width + rx;
1207 1386881 CodingUnit *cu = av_refstruct_pool_get(fc->cu_pool);
1208
1209
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1386881 times.
1386881 if (!cu)
1210 return NULL;
1211 1386881 cu->next = NULL;
1212
1213
2/2
✓ Branch 0 taken 1331096 times.
✓ Branch 1 taken 55785 times.
1386881 if (lc->cu)
1214 1331096 lc->cu->next = cu;
1215 else
1216 55785 *cus = cu;
1217 1386881 lc->cu = cu;
1218
1219 1386881 return cu;
1220 }
1221
1222 1386881 static CodingUnit* add_cu(VVCLocalContext *lc, const int x0, const int y0,
1223 const int cb_width, const int cb_height, const int cqt_depth, const VVCTreeType tree_type)
1224 {
1225 1386881 VVCFrameContext *fc = lc->fc;
1226 1386881 const int ch_type = tree_type == DUAL_TREE_CHROMA ? 1 : 0;
1227 1386881 CodingUnit *cu = alloc_cu(lc, x0, y0);
1228
1229
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1386881 times.
1386881 if (!cu)
1230 return NULL;
1231
1232 1386881 memset(&cu->pu, 0, sizeof(cu->pu));
1233
1234 1386881 lc->parse.prev_tu_cbf_y = 0;
1235
1236 1386881 cu->sbt_flag = 0;
1237 1386881 cu->act_enabled_flag = 0;
1238
1239 1386881 cu->tree_type = tree_type;
1240 1386881 cu->x0 = x0;
1241 1386881 cu->y0 = y0;
1242 1386881 cu->cb_width = cb_width;
1243 1386881 cu->cb_height = cb_height;
1244 1386881 cu->ch_type = ch_type;
1245 1386881 cu->cqt_depth = cqt_depth;
1246 1386881 cu->tus.head = cu->tus.tail = NULL;
1247 1386881 cu->bdpcm_flag[LUMA] = cu->bdpcm_flag[CB] = cu->bdpcm_flag[CR] = 0;
1248 1386881 cu->isp_split_type = ISP_NO_SPLIT;
1249 1386881 cu->intra_mip_flag = 0;
1250 1386881 cu->ciip_flag = 0;
1251 1386881 cu->coded_flag = 1;
1252 1386881 cu->num_intra_subpartitions = 1;
1253 1386881 cu->pu.dmvr_flag = 0;
1254
1255 1386881 set_cb_pos(fc, cu);
1256 1386881 return cu;
1257 }
1258
1259 1386881 static void set_cu_tabs(const VVCLocalContext *lc, const CodingUnit *cu)
1260 {
1261 1386881 const VVCFrameContext *fc = lc->fc;
1262 1386881 const PredictionUnit *pu = &cu->pu;
1263 1386881 const TransformUnit *tu = cu->tus.head;
1264
1265 1386881 set_cb_tab(lc, fc->tab.mmi, pu->mi.motion_model_idc);
1266 1386881 set_cb_tab(lc, fc->tab.msf, pu->merge_subblock_flag);
1267
2/2
✓ Branch 0 taken 1194159 times.
✓ Branch 1 taken 192722 times.
1386881 if (cu->tree_type != DUAL_TREE_CHROMA) {
1268 1194159 set_cb_tab(lc, fc->tab.skip, cu->skip_flag);
1269 1194159 set_cb_tab(lc, fc->tab.pcmf[LUMA], cu->bdpcm_flag[LUMA]);
1270 }
1271
2/2
✓ Branch 0 taken 787235 times.
✓ Branch 1 taken 599646 times.
1386881 if (cu->tree_type != DUAL_TREE_LUMA)
1272 787235 set_cb_tab(lc, fc->tab.pcmf[CHROMA], cu->bdpcm_flag[CHROMA]);
1273
1274
2/2
✓ Branch 0 taken 1707295 times.
✓ Branch 1 taken 1386881 times.
3094176 while (tu) {
1275
2/2
✓ Branch 0 taken 3358951 times.
✓ Branch 1 taken 1707295 times.
5066246 for (int j = 0; j < tu->nb_tbs; j++) {
1276 3358951 const TransformBlock *tb = tu->tbs + j;
1277
2/2
✓ Branch 0 taken 1845234 times.
✓ Branch 1 taken 1513717 times.
3358951 if (tb->c_idx != LUMA)
1278 1845234 set_qp_c_tab(lc, tu, tb);
1279 }
1280 1707295 tu = tu->next;
1281 }
1282 1386881 }
1283
1284 //8.5.2.7 Derivation process for merge motion vector difference
1285 58026 static void derive_mmvd(const VVCLocalContext *lc, MvField *mvf, const Mv *mmvd_offset)
1286 {
1287 58026 const SliceContext *sc = lc->sc;
1288 Mv mmvd[2];
1289
1290
2/2
✓ Branch 0 taken 24450 times.
✓ Branch 1 taken 33576 times.
58026 if (mvf->pred_flag == PF_BI) {
1291 24450 const RefPicList *rpl = sc->rpl;
1292 24450 const int poc = lc->fc->ps.ph.poc;
1293 24450 const int diff[] = {
1294 24450 poc - rpl[L0].refs[mvf->ref_idx[L0]].poc,
1295 24450 poc - rpl[L1].refs[mvf->ref_idx[L1]].poc
1296 };
1297
4/4
✓ Branch 0 taken 23103 times.
✓ Branch 1 taken 1347 times.
✓ Branch 2 taken 9320 times.
✓ Branch 3 taken 15130 times.
24450 const int sign = FFSIGN(diff[0]) != FFSIGN(diff[1]);
1298
1299
2/2
✓ Branch 0 taken 8287 times.
✓ Branch 1 taken 16163 times.
24450 if (diff[0] == diff[1]) {
1300 8287 mmvd[1] = mmvd[0] = *mmvd_offset;
1301 }
1302 else {
1303 16163 const int i = FFABS(diff[0]) < FFABS(diff[1]);
1304 16163 const int o = !i;
1305 16163 mmvd[i] = *mmvd_offset;
1306
4/4
✓ Branch 0 taken 15919 times.
✓ Branch 1 taken 244 times.
✓ Branch 2 taken 15842 times.
✓ Branch 3 taken 77 times.
16163 if (!rpl[L0].refs[mvf->ref_idx[L0]].is_lt && !rpl[L1].refs[mvf->ref_idx[L1]].is_lt) {
1307 15842 ff_vvc_mv_scale(&mmvd[o], mmvd_offset, diff[i], diff[o]);
1308 }
1309 else {
1310
2/2
✓ Branch 0 taken 199 times.
✓ Branch 1 taken 122 times.
321 mmvd[o].x = sign ? -mmvd[i].x : mmvd[i].x;
1311
2/2
✓ Branch 0 taken 199 times.
✓ Branch 1 taken 122 times.
321 mmvd[o].y = sign ? -mmvd[i].y : mmvd[i].y;
1312 }
1313 }
1314 24450 mvf->mv[0].x += mmvd[0].x;
1315 24450 mvf->mv[0].y += mmvd[0].y;
1316 24450 mvf->mv[1].x += mmvd[1].x;
1317 24450 mvf->mv[1].y += mmvd[1].y;
1318 } else {
1319 33576 const int idx = mvf->pred_flag - PF_L0;
1320 33576 mvf->mv[idx].x += mmvd_offset->x;
1321 33576 mvf->mv[idx].y += mmvd_offset->y;
1322 }
1323
1324 58026 }
1325
1326 299491 static void mvf_to_mi(const MvField *mvf, MotionInfo *mi)
1327 {
1328 299491 mi->pred_flag = mvf->pred_flag;
1329 299491 mi->bcw_idx = mvf->bcw_idx;
1330 299491 mi->hpel_if_idx = mvf->hpel_if_idx;
1331
2/2
✓ Branch 0 taken 598982 times.
✓ Branch 1 taken 299491 times.
898473 for (int i = 0; i < 2; i++) {
1332 598982 const PredFlag mask = i + 1;
1333
2/2
✓ Branch 0 taken 467192 times.
✓ Branch 1 taken 131790 times.
598982 if (mvf->pred_flag & mask) {
1334 467192 mi->mv[i][0] = mvf->mv[i];
1335 467192 mi->ref_idx[i] = mvf->ref_idx[i];
1336 }
1337 }
1338 299491 }
1339
1340 299491 static void mv_merge_refine_pred_flag(MvField *mvf, const int width, const int height)
1341 {
1342
4/4
✓ Branch 0 taken 172954 times.
✓ Branch 1 taken 126537 times.
✓ Branch 2 taken 5253 times.
✓ Branch 3 taken 167701 times.
299491 if (mvf->pred_flag == PF_BI && (width + height) == 12) {
1343 5253 mvf->pred_flag = PF_L0;
1344 5253 mvf->bcw_idx = 0;
1345 }
1346 299491 }
1347
1348 // subblock-based inter prediction data
1349 54720 static void merge_data_subblock(VVCLocalContext *lc)
1350 {
1351 54720 const VVCFrameContext *fc = lc->fc;
1352 54720 const VVCPH *ph = &fc->ps.ph;
1353 54720 CodingUnit* cu = lc->cu;
1354 54720 PredictionUnit *pu = &cu->pu;
1355 54720 int merge_subblock_idx = 0;
1356
1357
1/2
✓ Branch 0 taken 54720 times.
✗ Branch 1 not taken.
54720 if (ph->max_num_subblock_merge_cand > 1) {
1358 54720 merge_subblock_idx = ff_vvc_merge_subblock_idx(lc, ph->max_num_subblock_merge_cand);
1359 }
1360 54720 ff_vvc_sb_mv_merge_mode(lc, merge_subblock_idx, pu);
1361 54720 }
1362
1363 283164 static void merge_data_regular(VVCLocalContext *lc)
1364 {
1365 283164 const VVCFrameContext *fc = lc->fc;
1366 283164 const VVCSPS *sps = fc->ps.sps;
1367 283164 const VVCPH *ph = &fc->ps.ph;
1368 283164 const CodingUnit* cu = lc->cu;
1369 283164 PredictionUnit *pu = &lc->cu->pu;
1370 283164 int merge_idx = 0;
1371 Mv mmvd_offset;
1372 MvField mvf;
1373
1374
2/2
✓ Branch 0 taken 276100 times.
✓ Branch 1 taken 7064 times.
283164 if (sps->r->sps_mmvd_enabled_flag)
1375 276100 pu->mmvd_merge_flag = ff_vvc_mmvd_merge_flag(lc);
1376
2/2
✓ Branch 0 taken 58026 times.
✓ Branch 1 taken 225138 times.
283164 if (pu->mmvd_merge_flag) {
1377 58026 int mmvd_cand_flag = 0;
1378
1/2
✓ Branch 0 taken 58026 times.
✗ Branch 1 not taken.
58026 if (sps->max_num_merge_cand > 1)
1379 58026 mmvd_cand_flag = ff_vvc_mmvd_cand_flag(lc);
1380 58026 ff_vvc_mmvd_offset_coding(lc, &mmvd_offset, ph->r->ph_mmvd_fullpel_only_flag);
1381 58026 merge_idx = mmvd_cand_flag;
1382
1/2
✓ Branch 0 taken 225138 times.
✗ Branch 1 not taken.
225138 } else if (sps->max_num_merge_cand > 1) {
1383 225138 merge_idx = ff_vvc_merge_idx(lc);
1384 }
1385 283164 ff_vvc_luma_mv_merge_mode(lc, merge_idx, 0, &mvf);
1386
2/2
✓ Branch 0 taken 58026 times.
✓ Branch 1 taken 225138 times.
283164 if (pu->mmvd_merge_flag)
1387 58026 derive_mmvd(lc, &mvf, &mmvd_offset);
1388 283164 mv_merge_refine_pred_flag(&mvf, cu->cb_width, cu->cb_height);
1389 283164 ff_vvc_store_mvf(lc, &mvf);
1390 283164 mvf_to_mi(&mvf, &pu->mi);
1391 283164 }
1392
1393 43921 static int ciip_flag_decode(VVCLocalContext *lc, const int ciip_avaiable, const int gpm_avaiable, const int is_128)
1394 {
1395 43921 const VVCFrameContext *fc = lc->fc;
1396 43921 const VVCSPS *sps = fc->ps.sps;
1397 43921 const CodingUnit *cu = lc->cu;
1398
1399
4/4
✓ Branch 0 taken 27094 times.
✓ Branch 1 taken 16827 times.
✓ Branch 2 taken 20147 times.
✓ Branch 3 taken 6947 times.
43921 if (ciip_avaiable && gpm_avaiable)
1400 20147 return ff_vvc_ciip_flag(lc);
1401
3/4
✓ Branch 0 taken 6947 times.
✓ Branch 1 taken 16827 times.
✓ Branch 2 taken 6947 times.
✗ Branch 3 not taken.
23774 return sps->r->sps_ciip_enabled_flag && !cu->skip_flag &&
1402
2/4
✓ Branch 0 taken 23774 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6947 times.
✗ Branch 3 not taken.
47548 !is_128 && (cu->cb_width * cu->cb_height >= 64);
1403 }
1404
1405 27594 static void merge_data_gpm(VVCLocalContext *lc)
1406 {
1407 27594 const VVCFrameContext *fc = lc->fc;
1408 27594 const VVCSPS *sps = fc->ps.sps;
1409 27594 PredictionUnit *pu = &lc->cu->pu;
1410 int merge_gpm_idx[2];
1411
1412 27594 pu->merge_gpm_flag = 1;
1413 27594 pu->gpm_partition_idx = ff_vvc_merge_gpm_partition_idx(lc);
1414 27594 merge_gpm_idx[0] = ff_vvc_merge_gpm_idx(lc, 0);
1415 27594 merge_gpm_idx[1] = 0;
1416
1/2
✓ Branch 0 taken 27594 times.
✗ Branch 1 not taken.
27594 if (sps->max_num_gpm_merge_cand > 2)
1417 27594 merge_gpm_idx[1] = ff_vvc_merge_gpm_idx(lc, 1);
1418
1419 27594 ff_vvc_luma_mv_merge_gpm(lc, merge_gpm_idx, pu->gpm_mv);
1420 27594 ff_vvc_store_gpm_mvf(lc, pu);
1421 27594 }
1422
1423 16327 static void merge_data_ciip(VVCLocalContext *lc)
1424 {
1425 16327 const VVCFrameContext* fc = lc->fc;
1426 16327 const VVCSPS* sps = fc->ps.sps;
1427 16327 CodingUnit *cu = lc->cu;
1428 16327 MotionInfo *mi = &cu->pu.mi;
1429 16327 int merge_idx = 0;
1430 MvField mvf;
1431
1432
1/2
✓ Branch 0 taken 16327 times.
✗ Branch 1 not taken.
16327 if (sps->max_num_merge_cand > 1)
1433 16327 merge_idx = ff_vvc_merge_idx(lc);
1434 16327 ff_vvc_luma_mv_merge_mode(lc, merge_idx, 1, &mvf);
1435 16327 mv_merge_refine_pred_flag(&mvf, cu->cb_width, cu->cb_height);
1436 16327 ff_vvc_store_mvf(lc, &mvf);
1437 16327 mvf_to_mi(&mvf, mi);
1438 16327 cu->intra_pred_mode_y = cu->intra_pred_mode_c = INTRA_PLANAR;
1439 16327 cu->intra_luma_ref_idx = 0;
1440 16327 cu->intra_mip_flag = 0;
1441 16327 }
1442
1443 // block-based inter prediction data
1444 327085 static void merge_data_block(VVCLocalContext *lc)
1445 {
1446 327085 const VVCFrameContext* fc = lc->fc;
1447 327085 const VVCSPS *sps = fc->ps.sps;
1448 327085 const H266RawSliceHeader *rsh = lc->sc->sh.r;
1449 327085 CodingUnit *cu = lc->cu;
1450 327085 const int cb_width = cu->cb_width;
1451 327085 const int cb_height = cu->cb_height;
1452
4/4
✓ Branch 0 taken 306732 times.
✓ Branch 1 taken 20353 times.
✓ Branch 2 taken 1377 times.
✓ Branch 3 taken 305355 times.
327085 const int is_128 = cb_width == 128 || cb_height == 128;
1453 974191 const int ciip_avaiable = sps->r->sps_ciip_enabled_flag &&
1454
6/6
✓ Branch 0 taken 320021 times.
✓ Branch 1 taken 7064 times.
✓ Branch 2 taken 103733 times.
✓ Branch 3 taken 216288 times.
✓ Branch 4 taken 92605 times.
✓ Branch 5 taken 11128 times.
327085 !cu->skip_flag && (cb_width * cb_height >= 64);
1455
4/4
✓ Branch 0 taken 304847 times.
✓ Branch 1 taken 906 times.
✓ Branch 2 taken 268592 times.
✓ Branch 3 taken 36255 times.
305753 const int gpm_avaiable = sps->r->sps_gpm_enabled_flag && IS_B(rsh) &&
1456
2/2
✓ Branch 0 taken 239093 times.
✓ Branch 1 taken 29499 times.
268592 (cb_width >= 8) && (cb_height >=8) &&
1457
6/6
✓ Branch 0 taken 305753 times.
✓ Branch 1 taken 21332 times.
✓ Branch 2 taken 232062 times.
✓ Branch 3 taken 7031 times.
✓ Branch 4 taken 230076 times.
✓ Branch 5 taken 1986 times.
632838 (cb_width < 8 * cb_height) && (cb_height < 8 *cb_width);
1458
1459 327085 int regular_merge_flag = 1;
1460
1461
6/6
✓ Branch 0 taken 305355 times.
✓ Branch 1 taken 21730 times.
✓ Branch 2 taken 213131 times.
✓ Branch 3 taken 92224 times.
✓ Branch 4 taken 144109 times.
✓ Branch 5 taken 69022 times.
327085 if (!is_128 && (ciip_avaiable || gpm_avaiable))
1462 236333 regular_merge_flag = ff_vvc_regular_merge_flag(lc, cu->skip_flag);
1463
2/2
✓ Branch 0 taken 283164 times.
✓ Branch 1 taken 43921 times.
327085 if (regular_merge_flag) {
1464 283164 merge_data_regular(lc);
1465 } else {
1466 43921 cu->ciip_flag = ciip_flag_decode(lc, ciip_avaiable, gpm_avaiable, is_128);
1467
2/2
✓ Branch 0 taken 16327 times.
✓ Branch 1 taken 27594 times.
43921 if (cu->ciip_flag)
1468 16327 merge_data_ciip(lc);
1469 else
1470 27594 merge_data_gpm(lc);
1471 }
1472 327085 }
1473
1474 31034 static int merge_data_ibc(VVCLocalContext *lc)
1475 {
1476 31034 const VVCFrameContext* fc = lc->fc;
1477 31034 const VVCSPS* sps = fc->ps.sps;
1478 31034 MotionInfo *mi = &lc->cu->pu.mi;
1479 31034 int merge_idx = 0;
1480 int ret;
1481
1482 31034 mi->pred_flag = PF_IBC;
1483
1484
2/2
✓ Branch 0 taken 30794 times.
✓ Branch 1 taken 240 times.
31034 if (sps->max_num_ibc_merge_cand > 1)
1485 30794 merge_idx = ff_vvc_merge_idx(lc);
1486
1487 31034 ret = ff_vvc_luma_mv_merge_ibc(lc, merge_idx, &mi->mv[L0][0]);
1488
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 31034 times.
31034 if (ret)
1489 return ret;
1490 31034 ff_vvc_store_mv(lc, mi);
1491
1492 31034 return 0;
1493 }
1494
1495 412839 static int hls_merge_data(VVCLocalContext *lc)
1496 {
1497 412839 const VVCFrameContext *fc = lc->fc;
1498 412839 const VVCPH *ph = &fc->ps.ph;
1499 412839 const CodingUnit *cu = lc->cu;
1500 412839 PredictionUnit *pu = &lc->cu->pu;
1501 int ret;
1502
1503 412839 pu->merge_gpm_flag = 0;
1504 412839 pu->mi.num_sb_x = pu->mi.num_sb_y = 1;
1505
2/2
✓ Branch 0 taken 31034 times.
✓ Branch 1 taken 381805 times.
412839 if (cu->pred_mode == MODE_IBC) {
1506 31034 ret = merge_data_ibc(lc);
1507
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 31034 times.
31034 if (ret)
1508 return ret;
1509 } else {
1510
6/6
✓ Branch 0 taken 379905 times.
✓ Branch 1 taken 1900 times.
✓ Branch 2 taken 341787 times.
✓ Branch 3 taken 38118 times.
✓ Branch 4 taken 310327 times.
✓ Branch 5 taken 31460 times.
381805 if (ph->max_num_subblock_merge_cand > 0 && cu->cb_width >= 8 && cu->cb_height >= 8)
1511 310327 pu->merge_subblock_flag = ff_vvc_merge_subblock_flag(lc);
1512
2/2
✓ Branch 0 taken 54720 times.
✓ Branch 1 taken 327085 times.
381805 if (pu->merge_subblock_flag)
1513 54720 merge_data_subblock(lc);
1514 else
1515 327085 merge_data_block(lc);
1516 }
1517 412839 return 0;
1518 }
1519
1520 164126 static void hls_mvd_coding(VVCLocalContext *lc, Mv* mvd)
1521 {
1522 int32_t mv[2];
1523
1524
2/2
✓ Branch 0 taken 328252 times.
✓ Branch 1 taken 164126 times.
492378 for (int i = 0; i < 2; i++) {
1525 328252 mv[i] = ff_vvc_abs_mvd_greater0_flag(lc);
1526 }
1527
1528
2/2
✓ Branch 0 taken 328252 times.
✓ Branch 1 taken 164126 times.
492378 for (int i = 0; i < 2; i++) {
1529
2/2
✓ Branch 0 taken 204640 times.
✓ Branch 1 taken 123612 times.
328252 if (mv[i])
1530 204640 mv[i] += ff_vvc_abs_mvd_greater1_flag(lc);
1531 }
1532
1533
2/2
✓ Branch 0 taken 328252 times.
✓ Branch 1 taken 164126 times.
492378 for (int i = 0; i < 2; i++) {
1534
2/2
✓ Branch 0 taken 204640 times.
✓ Branch 1 taken 123612 times.
328252 if (mv[i] > 0) {
1535
2/2
✓ Branch 0 taken 146119 times.
✓ Branch 1 taken 58521 times.
204640 if (mv[i] == 2)
1536 146119 mv[i] += ff_vvc_abs_mvd_minus2(lc);
1537 204640 mv[i] = (1 - 2 * ff_vvc_mvd_sign_flag(lc)) * mv[i];
1538 }
1539 }
1540 164126 mvd->x = mv[0];
1541 164126 mvd->y = mv[1];
1542 164126 }
1543
1544 81041 static int bcw_idx_decode(VVCLocalContext *lc, const MotionInfo *mi, const int cb_width, const int cb_height)
1545 {
1546 81041 const VVCFrameContext *fc = lc->fc;
1547 81041 const VVCSPS *sps = fc->ps.sps;
1548 81041 const VVCPPS *pps = fc->ps.pps;
1549 81041 const VVCPH *ph = &fc->ps.ph;
1550 81041 const VVCSH *sh = &lc->sc->sh;
1551
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 81041 times.
81041 const PredWeightTable *w = pps->r->pps_wp_info_in_ph_flag ? &ph->pwt : &sh->pwt;
1552 81041 int bcw_idx = 0;
1553
1554
4/4
✓ Branch 0 taken 76906 times.
✓ Branch 1 taken 4135 times.
✓ Branch 2 taken 20933 times.
✓ Branch 3 taken 55973 times.
81041 if (sps->r->sps_bcw_enabled_flag && mi->pred_flag == PF_BI &&
1555
2/2
✓ Branch 0 taken 19581 times.
✓ Branch 1 taken 1352 times.
20933 !w->weight_flag[L0][LUMA][mi->ref_idx[0]] &&
1556
2/2
✓ Branch 0 taken 18935 times.
✓ Branch 1 taken 646 times.
19581 !w->weight_flag[L1][LUMA][mi->ref_idx[1]] &&
1557
2/2
✓ Branch 0 taken 18511 times.
✓ Branch 1 taken 424 times.
18935 !w->weight_flag[L0][CHROMA][mi->ref_idx[0]] &&
1558
2/2
✓ Branch 0 taken 18349 times.
✓ Branch 1 taken 162 times.
18511 !w->weight_flag[L1][CHROMA][mi->ref_idx[1]] &&
1559
2/2
✓ Branch 0 taken 12147 times.
✓ Branch 1 taken 6202 times.
18349 cb_width * cb_height >= 256) {
1560 12147 bcw_idx = ff_vvc_bcw_idx(lc, ff_vvc_no_backward_pred_flag(lc));
1561 }
1562 81041 return bcw_idx;
1563 }
1564
1565 102825 static int8_t ref_idx_decode(VVCLocalContext *lc, const VVCSH *sh, const int sym_mvd_flag, const int lx)
1566 {
1567 102825 const H266RawSliceHeader *rsh = sh->r;
1568 102825 int ref_idx = 0;
1569
1570
4/4
✓ Branch 0 taken 84743 times.
✓ Branch 1 taken 18082 times.
✓ Branch 2 taken 71767 times.
✓ Branch 3 taken 12976 times.
102825 if (rsh->num_ref_idx_active[lx] > 1 && !sym_mvd_flag)
1571 71767 ref_idx = ff_vvc_ref_idx_lx(lc, rsh->num_ref_idx_active[lx]);
1572
2/2
✓ Branch 0 taken 12976 times.
✓ Branch 1 taken 18082 times.
31058 else if (sym_mvd_flag)
1573 12976 ref_idx = sh->ref_idx_sym[lx];
1574 102825 return ref_idx;
1575 }
1576
1577 102825 static int mvds_decode(VVCLocalContext *lc, Mv mvds[2][MAX_CONTROL_POINTS],
1578 const int num_cp_mv, const int lx)
1579 {
1580 102825 const VVCFrameContext *fc = lc->fc;
1581 102825 const VVCPH *ph = &fc->ps.ph;
1582 102825 const PredictionUnit *pu = &lc->cu->pu;
1583 102825 const MotionInfo *mi = &pu->mi;
1584 102825 int has_no_zero_mvd = 0;
1585
1586
6/6
✓ Branch 0 taken 35473 times.
✓ Branch 1 taken 67352 times.
✓ Branch 2 taken 5040 times.
✓ Branch 3 taken 30433 times.
✓ Branch 4 taken 5026 times.
✓ Branch 5 taken 14 times.
102825 if (lx == L1 && ph->r->ph_mvd_l1_zero_flag && mi->pred_flag == PF_BI) {
1587
2/2
✓ Branch 0 taken 6400 times.
✓ Branch 1 taken 5026 times.
11426 for (int j = 0; j < num_cp_mv; j++)
1588 6400 AV_ZERO64(&mvds[lx][j]);
1589 } else {
1590 97799 Mv *mvd0 = &mvds[lx][0];
1591
4/4
✓ Branch 0 taken 30447 times.
✓ Branch 1 taken 67352 times.
✓ Branch 2 taken 6488 times.
✓ Branch 3 taken 23959 times.
97799 if (lx == L1 && pu->sym_mvd_flag) {
1592 6488 mvd0->x = -mvds[L0][0].x;
1593 6488 mvd0->y = -mvds[L0][0].y;
1594 } else {
1595 91311 hls_mvd_coding(lc, mvd0);
1596 }
1597
4/4
✓ Branch 0 taken 24272 times.
✓ Branch 1 taken 73527 times.
✓ Branch 2 taken 15243 times.
✓ Branch 3 taken 9029 times.
97799 has_no_zero_mvd |= (mvd0->x || mvd0->y);
1598
2/2
✓ Branch 0 taken 16675 times.
✓ Branch 1 taken 97799 times.
114474 for (int j = 1; j < num_cp_mv; j++) {
1599 16675 Mv *mvd = &mvds[lx][j];
1600 16675 hls_mvd_coding(lc, mvd);
1601 16675 mvd->x += mvd0->x;
1602 16675 mvd->y += mvd0->y;
1603
4/4
✓ Branch 0 taken 3077 times.
✓ Branch 1 taken 13598 times.
✓ Branch 2 taken 2044 times.
✓ Branch 3 taken 1033 times.
16675 has_no_zero_mvd |= (mvd->x || mvd->y);
1604 }
1605 }
1606 102825 return has_no_zero_mvd;
1607 }
1608
1609 81041 static void mvp_add_difference(MotionInfo *mi, const int num_cp_mv,
1610 const Mv mvds[2][MAX_CONTROL_POINTS], const int amvr_shift)
1611 {
1612
2/2
✓ Branch 0 taken 162082 times.
✓ Branch 1 taken 81041 times.
243123 for (int i = 0; i < 2; i++) {
1613 162082 const PredFlag mask = i + PF_L0;
1614
2/2
✓ Branch 0 taken 102825 times.
✓ Branch 1 taken 59257 times.
162082 if (mi->pred_flag & mask) {
1615
2/2
✓ Branch 0 taken 120874 times.
✓ Branch 1 taken 102825 times.
223699 for (int j = 0; j < num_cp_mv; j++) {
1616 120874 const Mv *mvd = &mvds[i][j];
1617 120874 mi->mv[i][j].x += mvd->x * (1 << amvr_shift);
1618 120874 mi->mv[i][j].y += mvd->y * (1 << amvr_shift);
1619 }
1620 }
1621 }
1622 81041 }
1623
1624 56140 static int mvp_data_ibc(VVCLocalContext *lc)
1625 {
1626 56140 const VVCFrameContext *fc = lc->fc;
1627 56140 const CodingUnit *cu = lc->cu;
1628 56140 const PredictionUnit *pu = &lc->cu->pu;
1629 56140 const VVCSPS *sps = fc->ps.sps;
1630 56140 MotionInfo *mi = &lc->cu->pu.mi;
1631 56140 int mvp_l0_flag = 0;
1632 56140 int amvr_shift = 4;
1633 56140 Mv *mv = &mi->mv[L0][0];
1634 int ret;
1635
1636 56140 mi->pred_flag = PF_IBC;
1637 56140 mi->num_sb_x = 1;
1638 56140 mi->num_sb_y = 1;
1639
1640 56140 hls_mvd_coding(lc, mv);
1641
2/2
✓ Branch 0 taken 54798 times.
✓ Branch 1 taken 1342 times.
56140 if (sps->max_num_ibc_merge_cand > 1)
1642 54798 mvp_l0_flag = ff_vvc_mvp_lx_flag(lc);
1643
5/6
✓ Branch 0 taken 56140 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 27887 times.
✓ Branch 3 taken 28253 times.
✓ Branch 4 taken 5392 times.
✓ Branch 5 taken 22495 times.
56140 if (sps->r->sps_amvr_enabled_flag && (mv->x || mv->y))
1644 33645 amvr_shift = ff_vvc_amvr_shift(lc, pu->inter_affine_flag, cu->pred_mode, 1);
1645
1646 56140 ret = ff_vvc_mvp_ibc(lc, mvp_l0_flag, amvr_shift, mv);
1647
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 56140 times.
56140 if (ret)
1648 return ret;
1649 56140 ff_vvc_store_mv(lc, mi);
1650
1651 56140 return 0;
1652 }
1653
1654 81041 static int mvp_data(VVCLocalContext *lc)
1655 {
1656 81041 const VVCFrameContext *fc = lc->fc;
1657 81041 const CodingUnit *cu = lc->cu;
1658 81041 PredictionUnit *pu = &lc->cu->pu;
1659 81041 const VVCSPS *sps = fc->ps.sps;
1660 81041 const VVCPH *ph = &fc->ps.ph;
1661 81041 const VVCSH *sh = &lc->sc->sh;
1662 81041 const H266RawSliceHeader *rsh = sh->r;
1663 81041 MotionInfo *mi = &pu->mi;
1664 81041 const int cb_width = cu->cb_width;
1665 81041 const int cb_height = cu->cb_height;
1666
1667 81041 int mvp_lx_flag[2] = {0};
1668 81041 int cu_affine_type_flag = 0;
1669 int num_cp_mv;
1670 81041 int amvr_enabled, has_no_zero_mvd = 0, amvr_shift;
1671 Mv mvds[2][MAX_CONTROL_POINTS];
1672
1673 81041 mi->pred_flag = ff_vvc_pred_flag(lc, IS_B(rsh));
1674
6/6
✓ Branch 0 taken 80637 times.
✓ Branch 1 taken 404 times.
✓ Branch 2 taken 43846 times.
✓ Branch 3 taken 36791 times.
✓ Branch 4 taken 30284 times.
✓ Branch 5 taken 13562 times.
81041 if (sps->r->sps_affine_enabled_flag && cb_width >= 16 && cb_height >= 16) {
1675 30284 pu->inter_affine_flag = ff_vvc_inter_affine_flag(lc);
1676 30284 set_cb_tab(lc, fc->tab.iaf, pu->inter_affine_flag);
1677
4/4
✓ Branch 0 taken 27938 times.
✓ Branch 1 taken 2346 times.
✓ Branch 2 taken 9332 times.
✓ Branch 3 taken 18606 times.
30284 if (sps->r->sps_6param_affine_enabled_flag && pu->inter_affine_flag)
1678 9332 cu_affine_type_flag = ff_vvc_cu_affine_type_flag(lc);
1679 }
1680 81041 mi->motion_model_idc = pu->inter_affine_flag + cu_affine_type_flag;
1681 81041 num_cp_mv = mi->motion_model_idc + 1;
1682
1683
4/4
✓ Branch 0 taken 68668 times.
✓ Branch 1 taken 12373 times.
✓ Branch 2 taken 57514 times.
✓ Branch 3 taken 11154 times.
81041 if (sps->r->sps_smvd_enabled_flag && !ph->r->ph_mvd_l1_zero_flag &&
1684
4/4
✓ Branch 0 taken 16147 times.
✓ Branch 1 taken 41367 times.
✓ Branch 2 taken 14750 times.
✓ Branch 3 taken 1397 times.
57514 mi->pred_flag == PF_BI && !pu->inter_affine_flag &&
1685
4/4
✓ Branch 0 taken 13652 times.
✓ Branch 1 taken 1098 times.
✓ Branch 2 taken 12921 times.
✓ Branch 3 taken 731 times.
14750 sh->ref_idx_sym[0] > -1 && sh->ref_idx_sym[1] > -1)
1686 12921 pu->sym_mvd_flag = ff_vvc_sym_mvd_flag(lc);
1687
1688
2/2
✓ Branch 0 taken 162082 times.
✓ Branch 1 taken 81041 times.
243123 for (int i = L0; i <= L1; i++) {
1689
2/2
✓ Branch 0 taken 81041 times.
✓ Branch 1 taken 81041 times.
162082 const PredFlag pred_flag = PF_L0 + !i;
1690
2/2
✓ Branch 0 taken 102825 times.
✓ Branch 1 taken 59257 times.
162082 if (mi->pred_flag != pred_flag) {
1691 102825 mi->ref_idx[i] = ref_idx_decode(lc, sh, pu->sym_mvd_flag, i);
1692 102825 has_no_zero_mvd |= mvds_decode(lc, mvds, num_cp_mv, i);
1693 102825 mvp_lx_flag[i] = ff_vvc_mvp_lx_flag(lc);
1694 }
1695 }
1696
1697 162082 amvr_enabled = mi->motion_model_idc == MOTION_TRANSLATION ?
1698
2/2
✓ Branch 0 taken 70865 times.
✓ Branch 1 taken 10176 times.
81041 sps->r->sps_amvr_enabled_flag : sps->r->sps_affine_amvr_enabled_flag;
1699 81041 amvr_enabled &= has_no_zero_mvd;
1700
1701 81041 amvr_shift = ff_vvc_amvr_shift(lc, pu->inter_affine_flag, cu->pred_mode, amvr_enabled);
1702
1703 81041 mi->hpel_if_idx = amvr_shift == 3;
1704 81041 mi->bcw_idx = bcw_idx_decode(lc, mi, cb_width, cb_height);
1705
1706
2/2
✓ Branch 0 taken 10176 times.
✓ Branch 1 taken 70865 times.
81041 if (mi->motion_model_idc)
1707 10176 ff_vvc_affine_mvp(lc, mvp_lx_flag, amvr_shift, mi);
1708 else
1709 70865 ff_vvc_mvp(lc, mvp_lx_flag, amvr_shift, mi);
1710
1711 81041 mvp_add_difference(mi, num_cp_mv, mvds, amvr_shift);
1712
1713
2/2
✓ Branch 0 taken 10176 times.
✓ Branch 1 taken 70865 times.
81041 if (mi->motion_model_idc)
1714 10176 ff_vvc_store_sb_mvs(lc, pu);
1715 else
1716 70865 ff_vvc_store_mv(lc, &pu->mi);
1717
1718 81041 return 0;
1719 }
1720
1721 // derive bdofFlag from 8.5.6 Decoding process for inter blocks
1722 // derive dmvr from 8.5.1 General decoding process for coding units coded in inter prediction mode
1723 370356 static void derive_dmvr_bdof_flag(const VVCLocalContext *lc, PredictionUnit *pu)
1724 {
1725 370356 const VVCFrameContext *fc = lc->fc;
1726 370356 const VVCPPS *pps = fc->ps.pps;
1727 370356 const VVCPH *ph = &fc->ps.ph;
1728 370356 const VVCSH *sh = &lc->sc->sh;
1729 370356 const int poc = ph->poc;
1730 370356 const MotionInfo *mi = &pu->mi;
1731 370356 const int8_t *ref_idx = mi->ref_idx;
1732 370356 const VVCRefPic *rp0 = &lc->sc->rpl[L0].refs[ref_idx[L0]];
1733 370356 const VVCRefPic *rp1 = &lc->sc->rpl[L1].refs[ref_idx[L1]];
1734 370356 const CodingUnit *cu = lc->cu;
1735
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 370356 times.
370356 const PredWeightTable *w = pps->r->pps_wp_info_in_ph_flag ? &fc->ps.ph.pwt : &sh->pwt;
1736
1737 370356 pu->bdof_flag = 0;
1738
1739
2/2
✓ Branch 0 taken 187129 times.
✓ Branch 1 taken 183227 times.
370356 if (mi->pred_flag == PF_BI &&
1740
2/2
✓ Branch 0 taken 125469 times.
✓ Branch 1 taken 61660 times.
187129 (poc - rp0->poc == rp1->poc - poc) &&
1741
4/4
✓ Branch 0 taken 125411 times.
✓ Branch 1 taken 58 times.
✓ Branch 2 taken 125378 times.
✓ Branch 3 taken 33 times.
125469 !rp0->is_lt && !rp1->is_lt &&
1742
2/2
✓ Branch 0 taken 122546 times.
✓ Branch 1 taken 2832 times.
125378 !cu->ciip_flag &&
1743
2/2
✓ Branch 0 taken 108039 times.
✓ Branch 1 taken 14507 times.
122546 !mi->bcw_idx &&
1744
4/4
✓ Branch 0 taken 106925 times.
✓ Branch 1 taken 1114 times.
✓ Branch 2 taken 106924 times.
✓ Branch 3 taken 1 times.
108039 !w->weight_flag[L0][LUMA][ref_idx[L0]] && !w->weight_flag[L1][LUMA][ref_idx[L1]] &&
1745
4/4
✓ Branch 0 taken 106906 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 106891 times.
✓ Branch 3 taken 15 times.
106924 !w->weight_flag[L0][CHROMA][ref_idx[L0]] && !w->weight_flag[L1][CHROMA][ref_idx[L1]] &&
1746
4/4
✓ Branch 0 taken 100966 times.
✓ Branch 1 taken 5925 times.
✓ Branch 2 taken 97037 times.
✓ Branch 3 taken 3929 times.
106891 cu->cb_width >= 8 && cu->cb_height >= 8 &&
1747
2/2
✓ Branch 0 taken 91072 times.
✓ Branch 1 taken 5965 times.
97037 (cu->cb_width * cu->cb_height >= 128) &&
1748
2/4
✓ Branch 0 taken 91072 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 91072 times.
✗ Branch 3 not taken.
91072 !rp0->is_scaled && !rp1->is_scaled) {
1749
2/2
✓ Branch 0 taken 88518 times.
✓ Branch 1 taken 2554 times.
91072 if (!ph->r->ph_bdof_disabled_flag &&
1750
1/2
✓ Branch 0 taken 88518 times.
✗ Branch 1 not taken.
88518 mi->motion_model_idc == MOTION_TRANSLATION &&
1751
1/2
✓ Branch 0 taken 88518 times.
✗ Branch 1 not taken.
88518 !pu->merge_subblock_flag &&
1752
2/2
✓ Branch 0 taken 85573 times.
✓ Branch 1 taken 2945 times.
88518 !pu->sym_mvd_flag)
1753 85573 pu->bdof_flag = 1;
1754
2/2
✓ Branch 0 taken 86061 times.
✓ Branch 1 taken 5011 times.
91072 if (!ph->r->ph_dmvr_disabled_flag &&
1755
2/2
✓ Branch 0 taken 80493 times.
✓ Branch 1 taken 5568 times.
86061 pu->general_merge_flag &&
1756
2/2
✓ Branch 0 taken 73298 times.
✓ Branch 1 taken 7195 times.
80493 !pu->mmvd_merge_flag)
1757 73298 pu->dmvr_flag = 1;
1758 }
1759 370356 }
1760
1761 // part of 8.5.1 General decoding process for coding units coded in inter prediction mode
1762 370356 static void refine_regular_subblock(const VVCLocalContext *lc)
1763 {
1764 370356 const CodingUnit *cu = lc->cu;
1765 370356 PredictionUnit *pu = &lc->cu->pu;
1766
1767 370356 derive_dmvr_bdof_flag(lc, pu);
1768
4/4
✓ Branch 0 taken 297058 times.
✓ Branch 1 taken 73298 times.
✓ Branch 2 taken 12275 times.
✓ Branch 3 taken 284783 times.
370356 if (pu->dmvr_flag || pu->bdof_flag) {
1769
2/2
✓ Branch 0 taken 51939 times.
✓ Branch 1 taken 33634 times.
85573 pu->mi.num_sb_x = (cu->cb_width > 16) ? (cu->cb_width >> 4) : 1;
1770
2/2
✓ Branch 0 taken 48935 times.
✓ Branch 1 taken 36638 times.
85573 pu->mi.num_sb_y = (cu->cb_height > 16) ? (cu->cb_height >> 4) : 1;
1771 }
1772 370356 }
1773
1774 476722 static void fill_dmvr_info(const VVCLocalContext *lc)
1775 {
1776 476722 const VVCFrameContext *fc = lc->fc;
1777 476722 const CodingUnit *cu = lc->cu;
1778
1779
3/4
✓ Branch 0 taken 389548 times.
✓ Branch 1 taken 87174 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 389548 times.
476722 if (cu->pred_mode == MODE_IBC || cu->pred_mode == MODE_PLT) {
1780
1/2
✓ Branch 0 taken 87174 times.
✗ Branch 1 not taken.
87174 ff_vvc_set_intra_mvf(lc, true, cu->pred_mode == MODE_IBC ? PF_IBC : PF_PLT, false);
1781 } else {
1782 389548 const VVCPPS *pps = fc->ps.pps;
1783 389548 const int w = cu->cb_width >> MIN_PU_LOG2;
1784
1785
2/2
✓ Branch 0 taken 2235144 times.
✓ Branch 1 taken 389548 times.
2624692 for (int y = cu->y0 >> MIN_PU_LOG2; y < (cu->y0 + cu->cb_height) >> MIN_PU_LOG2; y++) {
1786 2235144 const int idx = pps->min_pu_width * y + (cu->x0 >> MIN_PU_LOG2);
1787 2235144 const MvField *mvf = fc->tab.mvf + idx;
1788 2235144 MvField *dmvr_mvf = fc->ref->tab_dmvr_mvf + idx;
1789
1790 2235144 memcpy(dmvr_mvf, mvf, sizeof(MvField) * w);
1791 }
1792 }
1793 476722 }
1794
1795 550020 static int inter_data(VVCLocalContext *lc)
1796 {
1797 550020 const CodingUnit *cu = lc->cu;
1798 550020 PredictionUnit *pu = &lc->cu->pu;
1799 550020 const MotionInfo *mi = &pu->mi;
1800 550020 int ret = 0;
1801
1802 550020 pu->general_merge_flag = 1;
1803
2/2
✓ Branch 0 taken 264024 times.
✓ Branch 1 taken 285996 times.
550020 if (!cu->skip_flag)
1804 264024 pu->general_merge_flag = ff_vvc_general_merge_flag(lc);
1805
1806
2/2
✓ Branch 0 taken 412839 times.
✓ Branch 1 taken 137181 times.
550020 if (pu->general_merge_flag) {
1807 412839 ret = hls_merge_data(lc);
1808
2/2
✓ Branch 0 taken 56140 times.
✓ Branch 1 taken 81041 times.
137181 } else if (cu->pred_mode == MODE_IBC) {
1809 56140 ret = mvp_data_ibc(lc);
1810 } else {
1811 81041 ret = mvp_data(lc);
1812 }
1813
1814
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 550020 times.
550020 if (ret)
1815 return ret;
1816
1817
2/2
✓ Branch 0 taken 87174 times.
✓ Branch 1 taken 462846 times.
550020 if (cu->pred_mode == MODE_IBC) {
1818 87174 ff_vvc_update_hmvp(lc, mi);
1819
6/6
✓ Branch 0 taken 435252 times.
✓ Branch 1 taken 27594 times.
✓ Branch 2 taken 399274 times.
✓ Branch 3 taken 35978 times.
✓ Branch 4 taken 370356 times.
✓ Branch 5 taken 28918 times.
462846 } else if (!pu->merge_gpm_flag && !pu->inter_affine_flag && !pu->merge_subblock_flag) {
1820 370356 refine_regular_subblock(lc);
1821 370356 ff_vvc_update_hmvp(lc, mi);
1822 }
1823
1824
2/2
✓ Branch 0 taken 476722 times.
✓ Branch 1 taken 73298 times.
550020 if (!pu->dmvr_flag)
1825 476722 fill_dmvr_info(lc);
1826 550020 return ret;
1827 }
1828
1829 6977 static TransformUnit* palette_add_tu(VVCLocalContext *lc, const int start, const int end, const VVCTreeType tree_type)
1830 {
1831 6977 CodingUnit *cu = lc->cu;
1832 6977 const VVCSPS *sps = lc->fc->ps.sps;
1833 6977 TransformUnit *tu = add_tu(lc->fc, cu, cu->x0, cu->y0, cu->cb_width, cu->cb_height);
1834
1835
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6977 times.
6977 if (!tu)
1836 return NULL;
1837
1838
2/2
✓ Branch 0 taken 19123 times.
✓ Branch 1 taken 6977 times.
26100 for (int c = start; c < end; c++) {
1839 19123 const int w = tu->width >> sps->hshift[c];
1840 19123 const int h = tu->height >> sps->vshift[c];
1841 19123 TransformBlock *tb = add_tb(tu, lc, tu->x0, tu->y0, w, h, c);
1842
2/2
✓ Branch 0 taken 13050 times.
✓ Branch 1 taken 6073 times.
19123 if (c != CR)
1843 13050 set_tb_size(lc->fc, tb);
1844 }
1845
1846
2/2
✓ Branch 0 taken 20931 times.
✓ Branch 1 taken 6977 times.
27908 for (int i = 0; i < FF_ARRAY_ELEMS(cu->plt); i++)
1847 20931 cu->plt[i].size = 0;
1848
1849 6977 return tu;
1850 }
1851
1852 6977 static int palette_predicted(VVCLocalContext *lc, const bool local_dual_tree, int start, int end,
1853 bool *predictor_reused, const int predictor_size, const int max_entries)
1854 {
1855 6977 CodingUnit *cu = lc->cu;
1856 6977 int nb_predicted = 0;
1857
1858
2/2
✓ Branch 0 taken 904 times.
✓ Branch 1 taken 6073 times.
6977 if (local_dual_tree) {
1859 904 start = LUMA;
1860 904 end = VVC_MAX_SAMPLE_ARRAYS;
1861 }
1862
1863
3/4
✓ Branch 0 taken 43246 times.
✓ Branch 1 taken 131 times.
✓ Branch 2 taken 43246 times.
✗ Branch 3 not taken.
43377 for (int i = 0; i < predictor_size && nb_predicted < max_entries; i++) {
1864 43246 const int run = ff_vvc_palette_predictor_run(lc, predictor_size - i);
1865
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43246 times.
43246 if (run < 0)
1866 return run;
1867
1868
2/2
✓ Branch 0 taken 6846 times.
✓ Branch 1 taken 36400 times.
43246 if (run == 1)
1869 6846 break;
1870
1871
2/2
✓ Branch 0 taken 16254 times.
✓ Branch 1 taken 20146 times.
36400 if (run > 1)
1872 16254 i += run - 1;
1873
1874 36400 predictor_reused[i] = true;
1875
2/2
✓ Branch 0 taken 109200 times.
✓ Branch 1 taken 36400 times.
145600 for (int c = start; c < end; c++)
1876 109200 cu->plt[c].entries[nb_predicted] = lc->ep->pp[c].entries[i];
1877 36400 nb_predicted++;
1878 }
1879
1880
2/2
✓ Branch 0 taken 20931 times.
✓ Branch 1 taken 6977 times.
27908 for (int c = start; c < end; c++)
1881 20931 cu->plt[c].size = nb_predicted;
1882
1883 6977 return 0;
1884 }
1885
1886 6977 static int palette_signaled(VVCLocalContext *lc, const bool local_dual_tree,
1887 const int start, const int end, const int max_entries)
1888 {
1889 6977 const VVCSPS *sps = lc->fc->ps.sps;
1890 6977 CodingUnit *cu = lc->cu;
1891 6977 const int nb_predicted = cu->plt[start].size;
1892
1/2
✓ Branch 0 taken 6977 times.
✗ Branch 1 not taken.
6977 const int nb_signaled = nb_predicted < max_entries ? ff_vvc_num_signalled_palette_entries(lc, max_entries - nb_predicted) : 0;
1893 6977 const int size = nb_predicted + nb_signaled;
1894
3/4
✓ Branch 0 taken 904 times.
✓ Branch 1 taken 6073 times.
✓ Branch 2 taken 904 times.
✗ Branch 3 not taken.
6977 const bool dual_tree_luma = local_dual_tree && cu->tree_type == DUAL_TREE_LUMA;
1895
1896
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6977 times.
6977 if (nb_signaled < 0)
1897 return AVERROR_INVALIDDATA;
1898
1899
2/2
✓ Branch 0 taken 19123 times.
✓ Branch 1 taken 6977 times.
26100 for (int c = start; c < end; c++) {
1900 19123 Palette *plt = cu->plt + c;
1901
2/2
✓ Branch 0 taken 4254 times.
✓ Branch 1 taken 19123 times.
23377 for (int i = nb_predicted; i < size; i++) {
1902 4254 plt->entries[i] = ff_vvc_new_palette_entries(lc, sps->bit_depth);
1903
2/2
✓ Branch 0 taken 84 times.
✓ Branch 1 taken 4170 times.
4254 if (dual_tree_luma) {
1904 84 plt[CB].entries[i] = 1 << (sps->bit_depth - 1);
1905 84 plt[CR].entries[i] = 1 << (sps->bit_depth - 1);
1906 }
1907 }
1908 19123 plt->size = size;
1909 }
1910
1911 6977 return 0;
1912 }
1913
1914 6977 static void palette_update_predictor(VVCLocalContext *lc, const bool local_dual_tree, int start, int end,
1915 bool *predictor_reused, const int predictor_size)
1916 {
1917 6977 CodingUnit *cu = lc->cu;
1918
3/4
✓ Branch 0 taken 904 times.
✓ Branch 1 taken 6073 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 904 times.
6977 const int max_predictor = VVC_MAX_NUM_PALETTE_PREDICTOR_SIZE >> (cu->tree_type != SINGLE_TREE && !local_dual_tree);
1919
1920
2/2
✓ Branch 0 taken 904 times.
✓ Branch 1 taken 6073 times.
6977 if (local_dual_tree) {
1921 904 start = LUMA;
1922 904 end = VVC_MAX_SAMPLE_ARRAYS;
1923 }
1924
1925
2/2
✓ Branch 0 taken 20931 times.
✓ Branch 1 taken 6977 times.
27908 for (int c = start; c < end; c++) {
1926 20931 Palette *pp = lc->ep->pp + c;
1927 20931 Palette *plt = cu->plt + c;
1928 20931 int i = cu->plt[start].size;;
1929
1930 // copy unused predictors to the end of plt
1931
4/4
✓ Branch 0 taken 1126350 times.
✓ Branch 1 taken 19560 times.
✓ Branch 2 taken 1124979 times.
✓ Branch 3 taken 1371 times.
1145910 for (int j = 0; j < predictor_size && i < max_predictor; j++) {
1932
2/2
✓ Branch 0 taken 1016130 times.
✓ Branch 1 taken 108849 times.
1124979 if (!predictor_reused[j]) {
1933 1016130 plt->entries[i] = pp->entries[j];
1934 1016130 i++;
1935 }
1936 }
1937
1938 20931 memcpy(pp->entries, plt->entries, i * sizeof(pp->entries[0]));
1939 20931 pp->size = i;
1940 }
1941 6977 }
1942
1943 6977 static int palette_qp(VVCLocalContext *lc, VVCTreeType tree_type, const bool escape_present)
1944 {
1945 6977 const VVCFrameContext *fc = lc->fc;
1946 6977 const VVCPPS *pps = fc->ps.pps;
1947 6977 const H266RawSliceHeader *rsh = lc->sc->sh.r;
1948 6977 const CodingUnit *cu = lc->cu;
1949 int ret;
1950
1951
1/2
✓ Branch 0 taken 6977 times.
✗ Branch 1 not taken.
6977 if (tree_type != DUAL_TREE_CHROMA) {
1952 7024 const bool has_qp_delta = escape_present &&
1953
3/6
✓ Branch 0 taken 47 times.
✓ Branch 1 taken 6930 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 47 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
6977 pps->r->pps_cu_qp_delta_enabled_flag && !lc->parse.is_cu_qp_delta_coded;
1954 6977 ret = set_qp_y(lc, cu->x0, cu->y0, has_qp_delta);
1955
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6977 times.
6977 if (ret < 0)
1956 return ret;
1957 }
1958
1959
2/2
✓ Branch 0 taken 6073 times.
✓ Branch 1 taken 904 times.
6977 if (tree_type != DUAL_TREE_LUMA) {
1960
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6073 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6073 if (rsh->sh_cu_chroma_qp_offset_enabled_flag && !lc->parse.is_cu_chroma_qp_offset_coded)
1961 chroma_qp_offset_decode(lc, 0, 1);
1962 6073 set_qp_c(lc);
1963 }
1964
1965 6977 return 0;
1966 }
1967
1968 #define PALETTE_SET_PIXEL(xc, yc, pix) \
1969 do { \
1970 const int off = ((xc) >> hs) + ((yc) >> vs) * tb->tb_width; \
1971 if (sps->bit_depth == 8) \
1972 u8[off] = pix; \
1973 else \
1974 u16[off] = pix; \
1975 } while (0)
1976
1977 #define PALETTE_INDEX(x, y) index[(y) * width + (x)]
1978
1979 // 6.5.3 Horizontal and vertical traverse scan order array initialization process
1980 // The hTravScan and vTravScan tables require approximately 576 KB of memory.
1981 // To save space, we use a macro to achieve the same functionality.
1982 #define TRAV_COL(p, wlog, mask) ((p & mask) ^ (-((p >> wlog) & 1) & mask))
1983 #define TRAV_ROW(p, hlog) (p >> hlog)
1984 #define TRAV(trans, p, wlog, hlog, mask) (trans ? TRAV_ROW((p), hlog) : TRAV_COL((p), wlog, mask))
1985 #define TRAV_X(pos) TRAV(transpose, pos, wlog2, hlog2, wmask)
1986 #define TRAV_Y(pos) TRAV(!transpose, pos, hlog2, wlog2, hmask)
1987
1988 86464 static int palette_subblock_data(VVCLocalContext *lc,
1989 const int max_index, const int subset_id, const bool transpose,
1990 uint8_t *run_type, uint8_t *index, int *prev_run_pos, bool *adjust)
1991 {
1992 86464 const CodingUnit *cu = lc->cu;
1993 86464 TransformUnit *tu = cu->tus.head;
1994 86464 const VVCSPS *sps = lc->fc->ps.sps;
1995 86464 const int width = tu->tbs[0].tb_width;
1996 86464 const int height = tu->tbs[0].tb_height;
1997 86464 const int min_pos = subset_id << 4;
1998
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 86464 times.
86464 const int max_pos = FFMIN(min_pos + 16, width * height);
1999 86464 const int wmask = width - 1;
2000 86464 const int hmask = height - 1;
2001 86464 const int wlog2 = av_log2(width);
2002 86464 const int hlog2 = av_log2(height);
2003 86464 const int start_idx = tu->tbs[0].c_idx;
2004 86464 const uint8_t esc = cu->plt[tu->tbs[0].c_idx].size;
2005 86464 uint8_t run_copy[16] = { 0 };
2006
2007
2/2
✓ Branch 0 taken 1383424 times.
✓ Branch 1 taken 86464 times.
1469888 for (int i = min_pos; i < max_pos; i++) {
2008
2/2
✓ Branch 0 taken 186304 times.
✓ Branch 1 taken 1197120 times.
1383424 const int xc = TRAV_X(i);
2009
2/2
✓ Branch 0 taken 1197120 times.
✓ Branch 1 taken 186304 times.
1383424 const int yc = TRAV_Y(i);
2010
2011
4/4
✓ Branch 0 taken 1376447 times.
✓ Branch 1 taken 6977 times.
✓ Branch 2 taken 1000866 times.
✓ Branch 3 taken 375581 times.
1383424 if (i > 0 && max_index > 0)
2012 1000866 run_copy[i - min_pos] = ff_vvc_run_copy_flag(lc, run_type[i - 1], *prev_run_pos, i);
2013
2014 1383424 run_type[i] = 0;
2015
4/4
✓ Branch 0 taken 1007328 times.
✓ Branch 1 taken 376096 times.
✓ Branch 2 taken 150412 times.
✓ Branch 3 taken 856916 times.
1383424 if (max_index > 0 && !run_copy[i - min_pos]) {
2016
8/8
✓ Branch 0 taken 119284 times.
✓ Branch 1 taken 31128 times.
✓ Branch 2 taken 19742 times.
✓ Branch 3 taken 99542 times.
✓ Branch 4 taken 31128 times.
✓ Branch 5 taken 19742 times.
✓ Branch 6 taken 24732 times.
✓ Branch 7 taken 6396 times.
150412 if (((!transpose && yc > 0) || (transpose && xc > 0))
2017
3/4
✓ Branch 0 taken 124274 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 105524 times.
✓ Branch 3 taken 18750 times.
124274 && i > 0 && !run_type[i - 1]) {
2018 105524 run_type[i] = ff_vvc_copy_above_palette_indices_flag(lc);
2019 }
2020 150412 *prev_run_pos = i;
2021
2/2
✓ Branch 0 taken 1232497 times.
✓ Branch 1 taken 515 times.
1233012 } else if (i > 0) {
2022 1232497 run_type[i] = run_type[i - 1];
2023 }
2024 }
2025
2026
2/2
✓ Branch 0 taken 1383424 times.
✓ Branch 1 taken 86464 times.
1469888 for (int i = min_pos; i < max_pos; i++) {
2027
2/2
✓ Branch 0 taken 186304 times.
✓ Branch 1 taken 1197120 times.
1383424 const int xc = TRAV_X(i);
2028
2/2
✓ Branch 0 taken 1197120 times.
✓ Branch 1 taken 186304 times.
1383424 const int yc = TRAV_Y(i);
2029
4/4
✓ Branch 0 taken 1376447 times.
✓ Branch 1 taken 6977 times.
✓ Branch 2 taken 184488 times.
✓ Branch 3 taken 1191959 times.
1383424 const int prev_xc = i > 0 ? TRAV_X(i - 1) : 0;
2030
4/4
✓ Branch 0 taken 1376447 times.
✓ Branch 1 taken 6977 times.
✓ Branch 2 taken 1191959 times.
✓ Branch 3 taken 184488 times.
1383424 const int prev_yc = i > 0 ? TRAV_Y(i - 1) : 0;
2031
2032 1383424 int idx = 0;
2033
6/6
✓ Branch 0 taken 1007328 times.
✓ Branch 1 taken 376096 times.
✓ Branch 2 taken 150412 times.
✓ Branch 3 taken 856916 times.
✓ Branch 4 taken 129241 times.
✓ Branch 5 taken 21171 times.
1383424 if (max_index > 0 && !run_copy[i - min_pos] && !run_type[i]) {
2034
2/2
✓ Branch 0 taken 111753 times.
✓ Branch 1 taken 17488 times.
129241 if (max_index - *adjust > 0)
2035 111753 idx = ff_vvc_palette_idx_idc(lc, max_index, *adjust);
2036
2/2
✓ Branch 0 taken 122779 times.
✓ Branch 1 taken 6462 times.
129241 if (i > 0) {
2037 245558 const int ref_idx = !run_type[i - 1] ?
2038
2/2
✓ Branch 0 taken 104029 times.
✓ Branch 1 taken 18750 times.
122779 PALETTE_INDEX(prev_xc, prev_yc) : PALETTE_INDEX(xc - transpose, yc - !transpose);
2039 122779 idx += (idx >= ref_idx);
2040 }
2041 129241 *adjust = true;
2042 } else {
2043 1254183 idx = PALETTE_INDEX(prev_xc, prev_yc);
2044 }
2045
2046
2/2
✓ Branch 0 taken 1002075 times.
✓ Branch 1 taken 381349 times.
1383424 if (!run_type[i])
2047 1002075 PALETTE_INDEX(xc, yc) = idx;
2048 else
2049 381349 PALETTE_INDEX(xc, yc) = PALETTE_INDEX(xc - transpose, yc - !transpose);
2050 }
2051
2052
2/2
✓ Branch 0 taken 252688 times.
✓ Branch 1 taken 86464 times.
339152 for (int c = 0; c < tu->nb_tbs; c++) {
2053 252688 TransformBlock *tb = &tu->tbs[c];
2054 252688 const int c_idx = tb->c_idx;
2055 252688 const Palette *plt = &cu->plt[c_idx];
2056 252688 const int scale = ff_vvc_palette_derive_scale(lc, tu, tb);
2057 252688 const int hs = sps->hshift[c_idx] - sps->hshift[start_idx];
2058 252688 const int vs = sps->vshift[c_idx] - sps->vshift[start_idx];
2059 252688 uint8_t *u8 = (uint8_t *)tb->coeffs;
2060 252688 uint16_t *u16 = (uint16_t *)tb->coeffs;
2061
2062
2/2
✓ Branch 0 taken 4043008 times.
✓ Branch 1 taken 252688 times.
4295696 for (int i = min_pos; i < max_pos; i++) {
2063
2/2
✓ Branch 0 taken 518464 times.
✓ Branch 1 taken 3524544 times.
4043008 const int xc = TRAV_X(i);
2064
2/2
✓ Branch 0 taken 3524544 times.
✓ Branch 1 taken 518464 times.
4043008 const int yc = TRAV_Y(i);
2065
3/4
✓ Branch 0 taken 3257344 times.
✓ Branch 1 taken 785664 times.
✓ Branch 2 taken 3257344 times.
✗ Branch 3 not taken.
4043008 if (!(xc & hs) && !(yc & vs)) {
2066 3257344 const int v = PALETTE_INDEX(xc, yc);
2067
2/2
✓ Branch 0 taken 149 times.
✓ Branch 1 taken 3257195 times.
3257344 if (v == esc) {
2068 149 const int coeff = ff_vvc_palette_escape_val(lc, (1 << sps->bit_depth) - 1);
2069
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 149 times.
149 if (coeff < 0)
2070 return AVERROR_INVALIDDATA;
2071
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 29 times.
149 const int pixel = av_clip_intp2(RSHIFT(coeff * scale, 6), sps->bit_depth);
2072
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 149 times.
149 PALETTE_SET_PIXEL(xc, yc, pixel);
2073 } else {
2074
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3257195 times.
3257195 PALETTE_SET_PIXEL(xc, yc, plt->entries[v]);
2075 }
2076 }
2077 }
2078 }
2079
2080 86464 return 0;
2081 }
2082
2083 6977 static int hls_palette_coding(VVCLocalContext *lc, const VVCTreeType tree_type)
2084 {
2085 6977 const VVCFrameContext *fc = lc->fc;
2086 6977 const VVCSPS *sps = fc->ps.sps;
2087 6977 const H266RawSliceHeader *rsh = lc->sc->sh.r;
2088 6977 CodingUnit *cu = lc->cu;
2089 6977 Palette *pp = lc->ep->pp;
2090
2/2
✓ Branch 0 taken 6073 times.
✓ Branch 1 taken 904 times.
6977 const int max_entries = tree_type == SINGLE_TREE ? 31 : 15;
2091
2/2
✓ Branch 0 taken 904 times.
✓ Branch 1 taken 6073 times.
7881 const bool local_dual_tree = tree_type != SINGLE_TREE &&
2092
3/6
✓ Branch 0 taken 904 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 904 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 904 times.
✗ Branch 5 not taken.
904 (!IS_I(rsh) || (IS_I(rsh) && !sps->r->sps_qtbtt_dual_tree_intra_flag));
2093 6977 bool escape_present = false;
2094 6977 bool transpose = false;
2095 6977 bool adjust = false;
2096 6977 int max_index = 0;
2097 6977 int prev_run_pos = 0;
2098
2099 int predictor_size, start, end, ret;
2100 bool reused[VVC_MAX_NUM_PALETTE_PREDICTOR_SIZE];
2101 uint8_t run_type[MAX_PALETTE_CU_SIZE * MAX_PALETTE_CU_SIZE];
2102 uint8_t index[MAX_PALETTE_CU_SIZE * MAX_PALETTE_CU_SIZE];
2103
2104 TransformUnit *tu;
2105
2106 6977 ff_vvc_channel_range(&start, &end, tree_type, sps->r->sps_chroma_format_idc);
2107
2108 6977 tu = palette_add_tu(lc, start, end, tree_type);
2109
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6977 times.
6977 if (!tu)
2110 return AVERROR(ENOMEM);
2111
2112 6977 predictor_size = pp[start].size;
2113 6977 memset(reused, 0, sizeof(reused[0]) * predictor_size);
2114
2115 6977 ret = palette_predicted(lc, local_dual_tree, start, end, reused, predictor_size, max_entries);
2116
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6977 times.
6977 if (ret < 0)
2117 return ret;
2118
2119 6977 ret = palette_signaled(lc, local_dual_tree, start, end, max_entries);
2120
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6977 times.
6977 if (ret < 0)
2121 return ret;
2122
2123 6977 palette_update_predictor(lc, local_dual_tree, start, end, reused, predictor_size);
2124
2125
1/2
✓ Branch 0 taken 6977 times.
✗ Branch 1 not taken.
6977 if (cu->plt[start].size > 0)
2126 6977 escape_present = ff_vvc_palette_escape_val_present_flag(lc);
2127
2128 6977 max_index = cu->plt[start].size - 1 + escape_present;
2129
2/2
✓ Branch 0 taken 6462 times.
✓ Branch 1 taken 515 times.
6977 if (max_index > 0) {
2130 6462 adjust = false;
2131 6462 transpose = ff_vvc_palette_transpose_flag(lc);
2132 }
2133
2134 6977 ret = palette_qp(lc, tree_type, escape_present);
2135
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6977 times.
6977 if (ret < 0)
2136 return ret;
2137
2138 6977 index[0] = 0;
2139
2/2
✓ Branch 0 taken 86464 times.
✓ Branch 1 taken 6977 times.
93441 for (int i = 0; i <= (tu->tbs[0].tb_width * tu->tbs[0].tb_height - 1) >> 4; i++) {
2140 86464 ret = palette_subblock_data(lc, max_index, i, transpose,
2141 run_type, index, &prev_run_pos, &adjust);
2142
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 86464 times.
86464 if (ret < 0)
2143 return ret;
2144 }
2145
2146 6977 return 0;
2147 }
2148
2149 836861 static int intra_data(VVCLocalContext *lc)
2150 {
2151 836861 const VVCSPS *sps = lc->fc->ps.sps;
2152 836861 const CodingUnit *cu = lc->cu;
2153 836861 const VVCTreeType tree_type = cu->tree_type;
2154 836861 const bool pred_mode_plt_flag = cu->pred_mode == MODE_PLT;
2155 836861 int ret = 0;
2156
2157
4/4
✓ Branch 0 taken 745369 times.
✓ Branch 1 taken 91492 times.
✓ Branch 2 taken 552647 times.
✓ Branch 3 taken 192722 times.
836861 if (tree_type == SINGLE_TREE || tree_type == DUAL_TREE_LUMA) {
2158
2/2
✓ Branch 0 taken 6977 times.
✓ Branch 1 taken 637162 times.
644139 if (pred_mode_plt_flag) {
2159
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6977 times.
6977 if ((ret = hls_palette_coding(lc, tree_type)) < 0)
2160 return ret;
2161 6977 ff_vvc_set_intra_mvf(lc, false, PF_PLT, false);
2162 } else {
2163 637162 intra_luma_pred_modes(lc);
2164 637162 ff_vvc_set_intra_mvf(lc, false, PF_INTRA, cu->ciip_flag);
2165 }
2166 }
2167
6/6
✓ Branch 0 taken 745369 times.
✓ Branch 1 taken 91492 times.
✓ Branch 2 taken 192722 times.
✓ Branch 3 taken 552647 times.
✓ Branch 4 taken 269092 times.
✓ Branch 5 taken 15122 times.
836861 if ((tree_type == SINGLE_TREE || tree_type == DUAL_TREE_CHROMA) && sps->r->sps_chroma_format_idc) {
2168
3/4
✓ Branch 0 taken 6073 times.
✓ Branch 1 taken 263019 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6073 times.
269092 if (pred_mode_plt_flag && tree_type == DUAL_TREE_CHROMA) {
2169 if ((ret = hls_palette_coding(lc, tree_type)) < 0)
2170 return ret;
2171
2/2
✓ Branch 0 taken 263019 times.
✓ Branch 1 taken 6073 times.
269092 } else if (!pred_mode_plt_flag) {
2172 263019 intra_chroma_pred_modes(lc);
2173 }
2174 }
2175
2176 836861 return ret;
2177 }
2178
2179 1386881 static int hls_coding_unit(VVCLocalContext *lc, int x0, int y0, int cb_width, int cb_height,
2180 int cqt_depth, const VVCTreeType tree_type, VVCModeType mode_type)
2181 {
2182 1386881 const VVCFrameContext *fc = lc->fc;
2183 1386881 const VVCSPS *sps = fc->ps.sps;
2184 1386881 const H266RawSliceHeader *rsh = lc->sc->sh.r;
2185
4/4
✓ Branch 0 taken 1360478 times.
✓ Branch 1 taken 26403 times.
✓ Branch 2 taken 2342 times.
✓ Branch 3 taken 1358136 times.
1386881 const int is_128 = cb_width > 64 || cb_height > 64;
2186 1386881 int ret = 0;
2187
2188 1386881 CodingUnit *cu = add_cu(lc, x0, y0, cb_width, cb_height, cqt_depth, tree_type);
2189
2190
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1386881 times.
1386881 if (!cu)
2191 return AVERROR(ENOMEM);
2192
2193 1386881 ff_vvc_set_neighbour_available(lc, cu->x0, cu->y0, cu->cb_width, cu->cb_height);
2194
2195
3/4
✓ Branch 0 taken 757312 times.
✓ Branch 1 taken 629569 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 757312 times.
1386881 if (IS_I(rsh) && is_128)
2196 mode_type = MODE_TYPE_INTRA;
2197 1386881 cu->pred_mode = pred_mode_decode(lc, tree_type, mode_type);
2198
2199
5/6
✓ Branch 0 taken 829884 times.
✓ Branch 1 taken 556997 times.
✓ Branch 2 taken 8309 times.
✓ Branch 3 taken 821575 times.
✓ Branch 4 taken 8309 times.
✗ Branch 5 not taken.
1386881 if (cu->pred_mode == MODE_INTRA && sps->r->sps_act_enabled_flag && tree_type == SINGLE_TREE)
2200 8309 cu->act_enabled_flag = ff_vvc_cu_act_enabled_flag(lc);
2201
2202
4/4
✓ Branch 0 taken 556997 times.
✓ Branch 1 taken 829884 times.
✓ Branch 2 taken 6977 times.
✓ Branch 3 taken 550020 times.
1386881 if (cu->pred_mode == MODE_INTRA || cu->pred_mode == MODE_PLT)
2203 836861 ret = intra_data(lc);
2204
1/2
✓ Branch 0 taken 550020 times.
✗ Branch 1 not taken.
550020 else if (tree_type != DUAL_TREE_CHROMA) /* MODE_INTER or MODE_IBC */
2205 550020 ret = inter_data(lc);
2206
2207
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1386881 times.
1386881 if (ret < 0)
2208 return ret;
2209
2210
6/6
✓ Branch 0 taken 556997 times.
✓ Branch 1 taken 829884 times.
✓ Branch 2 taken 550020 times.
✓ Branch 3 taken 6977 times.
✓ Branch 4 taken 137181 times.
✓ Branch 5 taken 412839 times.
1386881 if (cu->pred_mode != MODE_INTRA && cu->pred_mode != MODE_PLT && !lc->cu->pu.general_merge_flag)
2211 137181 cu->coded_flag = ff_vvc_cu_coded_flag(lc);
2212 else
2213
4/4
✓ Branch 0 taken 963704 times.
✓ Branch 1 taken 285996 times.
✓ Branch 2 taken 956727 times.
✓ Branch 3 taken 6977 times.
1249700 cu->coded_flag = !(cu->skip_flag || cu->pred_mode == MODE_PLT);
2214
2215
2/2
✓ Branch 0 taken 1014971 times.
✓ Branch 1 taken 371910 times.
1386881 if (cu->coded_flag) {
2216 1014971 sbt_info(lc, sps);
2217
5/6
✓ Branch 0 taken 15652 times.
✓ Branch 1 taken 999319 times.
✓ Branch 2 taken 7343 times.
✓ Branch 3 taken 8309 times.
✓ Branch 4 taken 7343 times.
✗ Branch 5 not taken.
1014971 if (sps->r->sps_act_enabled_flag && cu->pred_mode != MODE_INTRA && tree_type == SINGLE_TREE)
2218 7343 cu->act_enabled_flag = ff_vvc_cu_act_enabled_flag(lc);
2219 1014971 lc->parse.lfnst_dc_only = 1;
2220 1014971 lc->parse.lfnst_zero_out_sig_coeff_flag = 1;
2221 1014971 lc->parse.mts_dc_only = 1;
2222 1014971 lc->parse.mts_zero_out_sig_coeff_flag = 1;
2223 1014971 ret = hls_transform_tree(lc, x0, y0, cb_width, cb_height, cu->ch_type);
2224
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1014971 times.
1014971 if (ret < 0)
2225 return ret;
2226 1014971 cu->lfnst_idx = lfnst_idx_decode(lc);
2227 1014971 cu->mts_idx = mts_idx_decode(lc);
2228 1014971 set_qp_c(lc);
2229
2/2
✓ Branch 0 taken 364933 times.
✓ Branch 1 taken 6977 times.
371910 } else if (cu->pred_mode != MODE_PLT) {
2230 364933 ret = skipped_transform_tree_unit(lc);
2231
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 364933 times.
364933 if (ret < 0)
2232 return ret;
2233 }
2234 1386881 set_cu_tabs(lc, cu);
2235
2236 1386881 return 0;
2237 }
2238
2239 890161 static int derive_mode_type_condition(const VVCLocalContext *lc,
2240 const VVCSplitMode split, const int cb_width, const int cb_height, const VVCModeType mode_type_curr)
2241 {
2242 890161 const H266RawSliceHeader *rsh = lc->sc->sh.r;
2243 890161 const VVCSPS *sps = lc->fc->ps.sps;
2244 890161 const int area = cb_width * cb_height;
2245
2246
6/6
✓ Branch 0 taken 500153 times.
✓ Branch 1 taken 390008 times.
✓ Branch 2 taken 68493 times.
✓ Branch 3 taken 431660 times.
✓ Branch 4 taken 421790 times.
✓ Branch 5 taken 36711 times.
890161 if ((IS_I(rsh) && sps->r->sps_qtbtt_dual_tree_intra_flag) ||
2247
2/2
✓ Branch 0 taken 397611 times.
✓ Branch 1 taken 24179 times.
421790 mode_type_curr != MODE_TYPE_ALL || !sps->r->sps_chroma_format_idc ||
2248
2/2
✓ Branch 0 taken 65766 times.
✓ Branch 1 taken 331845 times.
397611 sps->r->sps_chroma_format_idc == CHROMA_FORMAT_444)
2249 558316 return 0;
2250
9/10
✓ Branch 0 taken 27461 times.
✓ Branch 1 taken 304384 times.
✓ Branch 2 taken 25178 times.
✓ Branch 3 taken 2283 times.
✓ Branch 4 taken 25178 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 21655 times.
✓ Branch 7 taken 3523 times.
✓ Branch 8 taken 1096 times.
✓ Branch 9 taken 324943 times.
331845 if ((area == 64 && (split == SPLIT_QT || split == SPLIT_TT_HOR || split == SPLIT_TT_VER)) ||
2251
2/4
✓ Branch 0 taken 1096 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1096 times.
✗ Branch 3 not taken.
1096 (area == 32 && (split == SPLIT_BT_HOR || split == SPLIT_BT_VER)))
2252 6902 return 1;
2253
9/10
✓ Branch 0 taken 21655 times.
✓ Branch 1 taken 303288 times.
✓ Branch 2 taken 14135 times.
✓ Branch 3 taken 7520 times.
✓ Branch 4 taken 14135 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5747 times.
✓ Branch 7 taken 15908 times.
✓ Branch 8 taken 41274 times.
✓ Branch 9 taken 267761 times.
324943 if ((area == 64 && (split == SPLIT_BT_HOR || split == SPLIT_BT_VER) && sps->r->sps_chroma_format_idc == CHROMA_FORMAT_420) ||
2254
8/8
✓ Branch 0 taken 36402 times.
✓ Branch 1 taken 4872 times.
✓ Branch 2 taken 7269 times.
✓ Branch 3 taken 29133 times.
✓ Branch 4 taken 3178 times.
✓ Branch 5 taken 8963 times.
✓ Branch 6 taken 32198 times.
✓ Branch 7 taken 267874 times.
309035 (area == 128 && (split == SPLIT_TT_HOR || split == SPLIT_TT_VER) && sps->r->sps_chroma_format_idc == CHROMA_FORMAT_420) ||
2255
6/6
✓ Branch 0 taken 20271 times.
✓ Branch 1 taken 11927 times.
✓ Branch 2 taken 90859 times.
✓ Branch 3 taken 197286 times.
✓ Branch 4 taken 12991 times.
✓ Branch 5 taken 77868 times.
300072 (cb_width == 8 && split == SPLIT_BT_VER) || (cb_width == 16 && split == SPLIT_TT_VER))
2256
2/2
✓ Branch 0 taken 42486 times.
✓ Branch 1 taken 7303 times.
49789 return 1 + !IS_I(rsh);
2257
2258 275154 return 0;
2259 }
2260
2261 890161 static VVCModeType mode_type_decode(VVCLocalContext *lc, const int x0, const int y0,
2262 const int cb_width, const int cb_height, const VVCSplitMode split, const int ch_type,
2263 const VVCModeType mode_type_curr)
2264 {
2265 VVCModeType mode_type;
2266 890161 const int mode_type_condition = derive_mode_type_condition(lc, split, cb_width, cb_height, mode_type_curr);
2267
2268
2/2
✓ Branch 0 taken 14205 times.
✓ Branch 1 taken 875956 times.
890161 if (mode_type_condition == 1)
2269 14205 mode_type = MODE_TYPE_INTRA;
2270
2/2
✓ Branch 0 taken 42486 times.
✓ Branch 1 taken 833470 times.
875956 else if (mode_type_condition == 2) {
2271
2/2
✓ Branch 1 taken 19353 times.
✓ Branch 2 taken 23133 times.
42486 mode_type = ff_vvc_non_inter_flag(lc, x0, y0, ch_type) ? MODE_TYPE_INTRA : MODE_TYPE_INTER;
2272 } else {
2273 833470 mode_type = mode_type_curr;
2274 }
2275
2276 890161 return mode_type;
2277 }
2278
2279 static int hls_coding_tree(VVCLocalContext *lc,
2280 int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2281 int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset, int part_idx,
2282 VVCSplitMode last_split_mode, VVCTreeType tree_type_curr, VVCModeType mode_type_curr);
2283
2284 266781 static int coding_tree_btv(VVCLocalContext *lc,
2285 int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2286 int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset,
2287 VVCTreeType tree_type, VVCModeType mode_type)
2288 {
2289 #define CODING_TREE(x, idx) do { \
2290 ret = hls_coding_tree(lc, x, y0, cb_width / 2, cb_height, \
2291 qg_on_y, qg_on_c, cb_sub_div + 1, cqt_depth, mtt_depth + 1, \
2292 depth_offset, idx, SPLIT_BT_VER, tree_type, mode_type); \
2293 if (ret < 0) \
2294 return ret; \
2295 } while (0);
2296
2297 266781 const VVCPPS *pps = lc->fc->ps.pps;
2298 266781 const int x1 = x0 + cb_width / 2;
2299 266781 int ret = 0;
2300
2301 266781 depth_offset += (x0 + cb_width > pps->width) ? 1 : 0;
2302
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 266781 times.
266781 CODING_TREE(x0, 0);
2303
2/2
✓ Branch 0 taken 265153 times.
✓ Branch 1 taken 1628 times.
266781 if (x1 < pps->width)
2304
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 265153 times.
265153 CODING_TREE(x1, 1);
2305
2306 266781 return 0;
2307
2308 #undef CODING_TREE
2309 }
2310
2311 323923 static int coding_tree_bth(VVCLocalContext *lc,
2312 int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2313 int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset,
2314 VVCTreeType tree_type, VVCModeType mode_type)
2315 {
2316 #define CODING_TREE(y, idx) do { \
2317 ret = hls_coding_tree(lc, x0, y, cb_width , cb_height / 2, \
2318 qg_on_y, qg_on_c, cb_sub_div + 1, cqt_depth, mtt_depth + 1, \
2319 depth_offset, idx, SPLIT_BT_HOR, tree_type, mode_type); \
2320 if (ret < 0) \
2321 return ret; \
2322 } while (0);
2323
2324 323923 const VVCPPS *pps = lc->fc->ps.pps;
2325 323923 const int y1 = y0 + (cb_height / 2);
2326 323923 int ret = 0;
2327
2328 323923 depth_offset += (y0 + cb_height > pps->height) ? 1 : 0;
2329
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 323923 times.
323923 CODING_TREE(y0, 0);
2330
2/2
✓ Branch 0 taken 302480 times.
✓ Branch 1 taken 21443 times.
323923 if (y1 < pps->height)
2331
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 302480 times.
302480 CODING_TREE(y1, 1);
2332
2333 323923 return 0;
2334
2335 #undef CODING_TREE
2336 }
2337
2338 89934 static int coding_tree_ttv(VVCLocalContext *lc,
2339 int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2340 int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset,
2341 VVCTreeType tree_type, VVCModeType mode_type)
2342 {
2343 #define CODING_TREE(x, w, sub_div, idx) do { \
2344 ret = hls_coding_tree(lc, x, y0, w, cb_height, \
2345 qg_on_y, qg_on_c, sub_div, cqt_depth, mtt_depth + 1, \
2346 depth_offset, idx, SPLIT_TT_VER, tree_type, mode_type); \
2347 if (ret < 0) \
2348 return ret; \
2349 } while (0);
2350
2351 89934 const VVCSH *sh = &lc->sc->sh;
2352 89934 const int x1 = x0 + cb_width / 4;
2353 89934 const int x2 = x0 + cb_width * 3 / 4;
2354 int ret;
2355
2356
3/4
✓ Branch 0 taken 53105 times.
✓ Branch 1 taken 36829 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 53105 times.
89934 qg_on_y = qg_on_y && (cb_sub_div + 2 <= sh->cu_qp_delta_subdiv);
2357
3/4
✓ Branch 0 taken 39432 times.
✓ Branch 1 taken 50502 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 39432 times.
89934 qg_on_c = qg_on_c && (cb_sub_div + 2 <= sh->cu_chroma_qp_offset_subdiv);
2358
2359
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 89934 times.
89934 CODING_TREE(x0, cb_width / 4, cb_sub_div + 2, 0);
2360
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 89934 times.
89934 CODING_TREE(x1, cb_width / 2, cb_sub_div + 1, 1);
2361
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 89934 times.
89934 CODING_TREE(x2, cb_width / 4, cb_sub_div + 2, 2);
2362
2363 89934 return 0;
2364
2365 #undef CODING_TREE
2366 }
2367
2368 95287 static int coding_tree_tth(VVCLocalContext *lc,
2369 int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2370 int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset,
2371 VVCTreeType tree_type, VVCModeType mode_type)
2372 {
2373 #define CODING_TREE(y, h, sub_div, idx) do { \
2374 ret = hls_coding_tree(lc, x0, y, cb_width, h, \
2375 qg_on_y, qg_on_c, sub_div, cqt_depth, mtt_depth + 1, \
2376 depth_offset, idx, SPLIT_TT_HOR, tree_type, mode_type); \
2377 if (ret < 0) \
2378 return ret; \
2379 } while (0);
2380
2381 95287 const VVCSH *sh = &lc->sc->sh;
2382 95287 const int y1 = y0 + (cb_height / 4);
2383 95287 const int y2 = y0 + (3 * cb_height / 4);
2384 int ret;
2385
2386
3/4
✓ Branch 0 taken 55906 times.
✓ Branch 1 taken 39381 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 55906 times.
95287 qg_on_y = qg_on_y && (cb_sub_div + 2 <= sh->cu_qp_delta_subdiv);
2387
3/4
✓ Branch 0 taken 38083 times.
✓ Branch 1 taken 57204 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 38083 times.
95287 qg_on_c = qg_on_c && (cb_sub_div + 2 <= sh->cu_chroma_qp_offset_subdiv);
2388
2389
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 95287 times.
95287 CODING_TREE(y0, cb_height / 4, cb_sub_div + 2, 0);
2390
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 95287 times.
95287 CODING_TREE(y1, cb_height / 2, cb_sub_div + 1, 1);
2391
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 95287 times.
95287 CODING_TREE(y2, cb_height / 4, cb_sub_div + 2, 2);
2392
2393 95287 return 0;
2394
2395 #undef CODING_TREE
2396 }
2397
2398 114236 static int coding_tree_qt(VVCLocalContext *lc,
2399 int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2400 int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset,
2401 VVCTreeType tree_type, VVCModeType mode_type)
2402 {
2403 #define CODING_TREE(x, y, idx) do { \
2404 ret = hls_coding_tree(lc, x, y, cb_width / 2, cb_height / 2, \
2405 qg_on_y, qg_on_c, cb_sub_div + 2, cqt_depth + 1, 0, 0, \
2406 idx, SPLIT_QT, tree_type, mode_type); \
2407 if (ret < 0) \
2408 return ret; \
2409 } while (0);
2410
2411 114236 const VVCPPS *pps = lc->fc->ps.pps;
2412 114236 const int x1 = x0 + cb_width / 2;
2413 114236 const int y1 = y0 + cb_height / 2;
2414 114236 int ret = 0;
2415
2416
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 114236 times.
114236 CODING_TREE(x0, y0, 0);
2417
2/2
✓ Branch 0 taken 110927 times.
✓ Branch 1 taken 3309 times.
114236 if (x1 < pps->width)
2418
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 110927 times.
110927 CODING_TREE(x1, y0, 1);
2419
2/2
✓ Branch 0 taken 108278 times.
✓ Branch 1 taken 5958 times.
114236 if (y1 < pps->height)
2420
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 108278 times.
108278 CODING_TREE(x0, y1, 2);
2421
2/2
✓ Branch 0 taken 110927 times.
✓ Branch 1 taken 3309 times.
114236 if (x1 < pps->width &&
2422
2/2
✓ Branch 0 taken 105000 times.
✓ Branch 1 taken 5927 times.
110927 y1 < pps->height)
2423
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 105000 times.
105000 CODING_TREE(x1, y1, 3);
2424
2425 114236 return 0;
2426
2427 #undef CODING_TREE
2428 }
2429
2430 typedef int (*coding_tree_fn)(VVCLocalContext *lc,
2431 int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2432 int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset,
2433 VVCTreeType tree_type, VVCModeType mode_type);
2434
2435 const static coding_tree_fn coding_tree[] = {
2436 coding_tree_tth,
2437 coding_tree_bth,
2438 coding_tree_ttv,
2439 coding_tree_btv,
2440 coding_tree_qt,
2441 };
2442
2443 2277042 static int hls_coding_tree(VVCLocalContext *lc,
2444 int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2445 int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset, int part_idx,
2446 VVCSplitMode last_split_mode, VVCTreeType tree_type_curr, VVCModeType mode_type_curr)
2447 {
2448 2277042 VVCFrameContext *fc = lc->fc;
2449 2277042 const VVCPPS *pps = fc->ps.pps;
2450 2277042 const VVCSH *sh = &lc->sc->sh;
2451 2277042 const H266RawSliceHeader *rsh = sh->r;
2452 2277042 const int ch_type = tree_type_curr == DUAL_TREE_CHROMA;
2453 int ret;
2454 VVCAllowedSplit allowed;
2455
2456
6/6
✓ Branch 0 taken 285802 times.
✓ Branch 1 taken 1991240 times.
✓ Branch 2 taken 74093 times.
✓ Branch 3 taken 211709 times.
✓ Branch 4 taken 6515 times.
✓ Branch 5 taken 67578 times.
2277042 if (pps->r->pps_cu_qp_delta_enabled_flag && qg_on_y && cb_sub_div <= sh->cu_qp_delta_subdiv) {
2457 6515 lc->parse.is_cu_qp_delta_coded = 0;
2458 6515 lc->parse.cu_qg_top_left_x = x0;
2459 6515 lc->parse.cu_qg_top_left_y = y0;
2460 }
2461
4/4
✓ Branch 0 taken 206481 times.
✓ Branch 1 taken 2070561 times.
✓ Branch 2 taken 17504 times.
✓ Branch 3 taken 188977 times.
2277042 if (rsh->sh_cu_chroma_qp_offset_enabled_flag && qg_on_c &&
2462
2/2
✓ Branch 0 taken 931 times.
✓ Branch 1 taken 16573 times.
17504 cb_sub_div <= sh->cu_chroma_qp_offset_subdiv) {
2463 931 lc->parse.is_cu_chroma_qp_offset_coded = 0;
2464 931 memset(lc->parse.chroma_qp_offset, 0, sizeof(lc->parse.chroma_qp_offset));
2465 }
2466
2467 2277042 can_split(lc, x0, y0, cb_width, cb_height, mtt_depth, depth_offset, part_idx,
2468 last_split_mode, tree_type_curr, mode_type_curr, &allowed);
2469
2/2
✓ Branch 1 taken 890161 times.
✓ Branch 2 taken 1386881 times.
2277042 if (ff_vvc_split_cu_flag(lc, x0, y0, cb_width, cb_height, ch_type, &allowed)) {
2470 890161 VVCSplitMode split = ff_vvc_split_mode(lc, x0, y0, cb_width, cb_height, cqt_depth, mtt_depth, ch_type, &allowed);
2471 890161 VVCModeType mode_type = mode_type_decode(lc, x0, y0, cb_width, cb_height, split, ch_type, mode_type_curr);
2472
2473
2/2
✓ Branch 0 taken 825851 times.
✓ Branch 1 taken 64310 times.
890161 VVCTreeType tree_type = (mode_type == MODE_TYPE_INTRA) ? DUAL_TREE_LUMA : tree_type_curr;
2474
2475
2/2
✓ Branch 0 taken 775925 times.
✓ Branch 1 taken 114236 times.
890161 if (split != SPLIT_QT) {
2476
6/6
✓ Branch 0 taken 469829 times.
✓ Branch 1 taken 306096 times.
✓ Branch 2 taken 304326 times.
✓ Branch 3 taken 165503 times.
✓ Branch 4 taken 257602 times.
✓ Branch 5 taken 46724 times.
775925 if (!(x0 & 31) && !(y0 & 31) && mtt_depth <= 1)
2477 257602 TAB_MSM(fc, mtt_depth, x0, y0) = split;
2478 }
2479 890161 ret = coding_tree[split - 1](lc, x0, y0, cb_width, cb_height, qg_on_y, qg_on_c,
2480 cb_sub_div, cqt_depth, mtt_depth, depth_offset, tree_type, mode_type);
2481
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 890161 times.
890161 if (ret < 0)
2482 return ret;
2483
4/4
✓ Branch 0 taken 853450 times.
✓ Branch 1 taken 36711 times.
✓ Branch 2 taken 33558 times.
✓ Branch 3 taken 819892 times.
890161 if (mode_type_curr == MODE_TYPE_ALL && mode_type == MODE_TYPE_INTRA) {
2484 33558 ret = hls_coding_tree(lc, x0, y0, cb_width, cb_height, 0, qg_on_c, cb_sub_div,
2485 cqt_depth, mtt_depth, 0, 0, split, DUAL_TREE_CHROMA, mode_type);
2486
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33558 times.
33558 if (ret < 0)
2487 return ret;
2488 }
2489 } else {
2490 1386881 ret = hls_coding_unit(lc, x0, y0, cb_width, cb_height, cqt_depth, tree_type_curr, mode_type_curr);
2491
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1386881 times.
1386881 if (ret < 0)
2492 return ret;
2493 }
2494
2495 2277042 return 0;
2496 }
2497
2498 25949 static int dual_tree_implicit_qt_split(VVCLocalContext *lc,
2499 const int x0, const int y0, const int cb_size, const int cqt_depth)
2500 {
2501 25949 const VVCSH *sh = &lc->sc->sh;
2502 25949 const H266RawSliceHeader *rsh = sh->r;
2503 25949 const VVCPPS *pps = lc->fc->ps.pps;
2504 25949 const int cb_subdiv = 2 * cqt_depth;
2505 int ret;
2506
2507
2/2
✓ Branch 0 taken 5308 times.
✓ Branch 1 taken 20641 times.
25949 if (cb_size > 64) {
2508 #define DUAL_TREE(x, y) do { \
2509 ret = dual_tree_implicit_qt_split(lc, x, y, cb_size / 2, cqt_depth + 1); \
2510 if (ret < 0) \
2511 return ret; \
2512 } while (0)
2513
2514 5308 const int x1 = x0 + (cb_size / 2);
2515 5308 const int y1 = y0 + (cb_size / 2);
2516
3/4
✓ Branch 0 taken 130 times.
✓ Branch 1 taken 5178 times.
✓ Branch 2 taken 130 times.
✗ Branch 3 not taken.
5308 if (pps->r->pps_cu_qp_delta_enabled_flag && cb_subdiv <= sh->cu_qp_delta_subdiv) {
2517 130 lc->parse.is_cu_qp_delta_coded = 0;
2518 130 lc->parse.cu_qg_top_left_x = x0;
2519 130 lc->parse.cu_qg_top_left_y = y0;
2520 }
2521
3/4
✓ Branch 0 taken 98 times.
✓ Branch 1 taken 5210 times.
✓ Branch 2 taken 98 times.
✗ Branch 3 not taken.
5308 if (rsh->sh_cu_chroma_qp_offset_enabled_flag && cb_subdiv <= sh->cu_chroma_qp_offset_subdiv) {
2522 98 lc->parse.is_cu_chroma_qp_offset_coded = 0;
2523 98 memset(lc->parse.chroma_qp_offset, 0, sizeof(lc->parse.chroma_qp_offset));
2524 }
2525
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 5308 times.
5308 DUAL_TREE(x0, y0);
2526
2/2
✓ Branch 0 taken 5145 times.
✓ Branch 1 taken 163 times.
5308 if (x1 < pps->width)
2527
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 5145 times.
5145 DUAL_TREE(x1, y0);
2528
2/2
✓ Branch 0 taken 4816 times.
✓ Branch 1 taken 492 times.
5308 if (y1 < pps->height)
2529
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4816 times.
4816 DUAL_TREE(x0, y1);
2530
4/4
✓ Branch 0 taken 5145 times.
✓ Branch 1 taken 163 times.
✓ Branch 2 taken 4656 times.
✓ Branch 3 taken 489 times.
5308 if (x1 < pps->width && y1 < pps->height)
2531
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4656 times.
4656 DUAL_TREE(x1, y1);
2532 #undef DUAL_TREE
2533 } else {
2534 #define CODING_TREE(tree_type) do { \
2535 const int qg_on_y = tree_type == DUAL_TREE_LUMA; \
2536 ret = hls_coding_tree(lc, x0, y0, cb_size, cb_size, qg_on_y, !qg_on_y, \
2537 cb_subdiv, cqt_depth, 0, 0, 0, SPLIT_NONE, tree_type, MODE_TYPE_ALL); \
2538 if (ret < 0) \
2539 return ret; \
2540 } while (0)
2541
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 20641 times.
20641 CODING_TREE(DUAL_TREE_LUMA);
2542
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 20641 times.
20641 CODING_TREE(DUAL_TREE_CHROMA);
2543 #undef CODING_TREE
2544 }
2545 25949 return 0;
2546 }
2547
2548 #define SET_SAO(elem, value) \
2549 do { \
2550 if (!sao_merge_up_flag && !sao_merge_left_flag) \
2551 sao->elem = value; \
2552 else if (sao_merge_left_flag) \
2553 sao->elem = CTB(fc->tab.sao, rx-1, ry).elem; \
2554 else if (sao_merge_up_flag) \
2555 sao->elem = CTB(fc->tab.sao, rx, ry-1).elem; \
2556 else \
2557 sao->elem = 0; \
2558 } while (0)
2559
2560 55785 static void hls_sao(VVCLocalContext *lc, const int rx, const int ry)
2561 {
2562 55785 VVCFrameContext *fc = lc->fc;
2563 55785 const H266RawSliceHeader *rsh = lc->sc->sh.r;
2564 55785 int sao_merge_left_flag = 0;
2565 55785 int sao_merge_up_flag = 0;
2566 55785 SAOParams *sao = &CTB(fc->tab.sao, rx, ry);
2567 int c_idx, i;
2568
2569
4/4
✓ Branch 0 taken 36331 times.
✓ Branch 1 taken 19454 times.
✓ Branch 2 taken 164 times.
✓ Branch 3 taken 36167 times.
55785 if (rsh->sh_sao_luma_used_flag || rsh->sh_sao_chroma_used_flag) {
2570
2/2
✓ Branch 0 taken 17704 times.
✓ Branch 1 taken 1914 times.
19618 if (rx > 0) {
2571
2/2
✓ Branch 0 taken 16887 times.
✓ Branch 1 taken 817 times.
17704 if (lc->ctb_left_flag)
2572 16887 sao_merge_left_flag = ff_vvc_sao_merge_flag_decode(lc);
2573 }
2574
4/4
✓ Branch 0 taken 16295 times.
✓ Branch 1 taken 3323 times.
✓ Branch 2 taken 8957 times.
✓ Branch 3 taken 7338 times.
19618 if (ry > 0 && !sao_merge_left_flag) {
2575
2/2
✓ Branch 0 taken 8156 times.
✓ Branch 1 taken 801 times.
8957 if (lc->ctb_up_flag)
2576 8156 sao_merge_up_flag = ff_vvc_sao_merge_flag_decode(lc);
2577 }
2578 }
2579
2580
4/4
✓ Branch 0 taken 221028 times.
✓ Branch 1 taken 1056 times.
✓ Branch 2 taken 166299 times.
✓ Branch 3 taken 55785 times.
222084 for (c_idx = 0; c_idx < (fc->ps.sps->r->sps_chroma_format_idc ? 3 : 1); c_idx++) {
2581
2/2
✓ Branch 0 taken 55785 times.
✓ Branch 1 taken 110514 times.
166299 const int sao_used_flag = !c_idx ? rsh->sh_sao_luma_used_flag : rsh->sh_sao_chroma_used_flag;
2582
2/2
✓ Branch 0 taken 123027 times.
✓ Branch 1 taken 43272 times.
166299 if (!sao_used_flag) {
2583 123027 sao->type_idx[c_idx] = SAO_NOT_APPLIED;
2584 123027 continue;
2585 }
2586
2587
2/2
✓ Branch 0 taken 11909 times.
✓ Branch 1 taken 31363 times.
43272 if (c_idx == 2) {
2588 11909 sao->type_idx[2] = sao->type_idx[1];
2589 11909 sao->eo_class[2] = sao->eo_class[1];
2590 } else {
2591
7/8
✓ Branch 0 taken 27643 times.
✓ Branch 1 taken 3720 times.
✓ Branch 2 taken 14344 times.
✓ Branch 3 taken 13299 times.
✓ Branch 5 taken 13299 times.
✓ Branch 6 taken 3720 times.
✓ Branch 7 taken 3720 times.
✗ Branch 8 not taken.
31363 SET_SAO(type_idx[c_idx], ff_vvc_sao_type_idx_decode(lc));
2592 }
2593
2594
2/2
✓ Branch 0 taken 26750 times.
✓ Branch 1 taken 16522 times.
43272 if (sao->type_idx[c_idx] == SAO_NOT_APPLIED)
2595 26750 continue;
2596
2597
2/2
✓ Branch 0 taken 66088 times.
✓ Branch 1 taken 16522 times.
82610 for (i = 0; i < 4; i++)
2598
7/8
✓ Branch 0 taken 56192 times.
✓ Branch 1 taken 9896 times.
✓ Branch 2 taken 25700 times.
✓ Branch 3 taken 30492 times.
✓ Branch 5 taken 30492 times.
✓ Branch 6 taken 9896 times.
✓ Branch 7 taken 9896 times.
✗ Branch 8 not taken.
66088 SET_SAO(offset_abs[c_idx][i], ff_vvc_sao_offset_abs_decode(lc));
2599
2600
2/2
✓ Branch 0 taken 6152 times.
✓ Branch 1 taken 10370 times.
16522 if (sao->type_idx[c_idx] == SAO_BAND) {
2601
2/2
✓ Branch 0 taken 24608 times.
✓ Branch 1 taken 6152 times.
30760 for (i = 0; i < 4; i++) {
2602
2/2
✓ Branch 0 taken 8959 times.
✓ Branch 1 taken 15649 times.
24608 if (sao->offset_abs[c_idx][i]) {
2603
7/8
✓ Branch 0 taken 8071 times.
✓ Branch 1 taken 888 times.
✓ Branch 2 taken 3338 times.
✓ Branch 3 taken 4733 times.
✓ Branch 5 taken 4733 times.
✓ Branch 6 taken 888 times.
✓ Branch 7 taken 888 times.
✗ Branch 8 not taken.
8959 SET_SAO(offset_sign[c_idx][i],
2604 ff_vvc_sao_offset_sign_decode(lc));
2605 } else {
2606 15649 sao->offset_sign[c_idx][i] = 0;
2607 }
2608 }
2609
7/8
✓ Branch 0 taken 5462 times.
✓ Branch 1 taken 690 times.
✓ Branch 2 taken 1773 times.
✓ Branch 3 taken 3689 times.
✓ Branch 5 taken 3689 times.
✓ Branch 6 taken 690 times.
✓ Branch 7 taken 690 times.
✗ Branch 8 not taken.
6152 SET_SAO(band_position[c_idx], ff_vvc_sao_band_position_decode(lc));
2610
2/2
✓ Branch 0 taken 8102 times.
✓ Branch 1 taken 2268 times.
10370 } else if (c_idx != 2) {
2611
7/8
✓ Branch 0 taken 6667 times.
✓ Branch 1 taken 1435 times.
✓ Branch 2 taken 3430 times.
✓ Branch 3 taken 3237 times.
✓ Branch 5 taken 3237 times.
✓ Branch 6 taken 1435 times.
✓ Branch 7 taken 1435 times.
✗ Branch 8 not taken.
8102 SET_SAO(eo_class[c_idx], ff_vvc_sao_eo_class_decode(lc));
2612 }
2613
2614 // Inferred parameters
2615 16522 sao->offset_val[c_idx][0] = 0;
2616
2/2
✓ Branch 0 taken 66088 times.
✓ Branch 1 taken 16522 times.
82610 for (i = 0; i < 4; i++) {
2617 66088 sao->offset_val[c_idx][i + 1] = sao->offset_abs[c_idx][i];
2618
2/2
✓ Branch 0 taken 41480 times.
✓ Branch 1 taken 24608 times.
66088 if (sao->type_idx[c_idx] == SAO_EDGE) {
2619
2/2
✓ Branch 0 taken 20740 times.
✓ Branch 1 taken 20740 times.
41480 if (i > 1)
2620 20740 sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1];
2621
2/2
✓ Branch 0 taken 6495 times.
✓ Branch 1 taken 18113 times.
24608 } else if (sao->offset_sign[c_idx][i]) {
2622 6495 sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1];
2623 }
2624 66088 sao->offset_val[c_idx][i + 1] *= 1 << (fc->ps.sps->bit_depth - FFMIN(10, fc->ps.sps->bit_depth));
2625 }
2626 }
2627 55785 }
2628
2629 55785 static void alf_params(VVCLocalContext *lc, const int rx, const int ry)
2630 {
2631 55785 const VVCFrameContext *fc = lc->fc;
2632 55785 const H266RawSliceHeader *sh = lc->sc->sh.r;
2633 55785 ALFParams *alf = &CTB(fc->tab.alf, rx, ry);
2634
2635 55785 alf->ctb_flag[LUMA] = alf->ctb_flag[CB] = alf->ctb_flag[CR] = 0;
2636 55785 alf->ctb_cc_idc[0] = alf->ctb_cc_idc[1] = 0;
2637
2/2
✓ Branch 0 taken 29703 times.
✓ Branch 1 taken 26082 times.
55785 if (sh->sh_alf_enabled_flag) {
2638 29703 alf->ctb_flag[LUMA] = ff_vvc_alf_ctb_flag(lc, rx, ry, LUMA);
2639
2/2
✓ Branch 0 taken 21045 times.
✓ Branch 1 taken 8658 times.
29703 if (alf->ctb_flag[LUMA]) {
2640 21045 uint8_t alf_use_aps_flag = 0;
2641
2/2
✓ Branch 0 taken 20237 times.
✓ Branch 1 taken 808 times.
21045 if (sh->sh_num_alf_aps_ids_luma > 0)
2642 20237 alf_use_aps_flag = ff_vvc_alf_use_aps_flag(lc);
2643
2/2
✓ Branch 0 taken 18242 times.
✓ Branch 1 taken 2803 times.
21045 if (alf_use_aps_flag) {
2644 18242 alf->ctb_filt_set_idx_y = 16;
2645
2/2
✓ Branch 0 taken 5167 times.
✓ Branch 1 taken 13075 times.
18242 if (sh->sh_num_alf_aps_ids_luma > 1)
2646 5167 alf->ctb_filt_set_idx_y += ff_vvc_alf_luma_prev_filter_idx(lc);
2647 } else {
2648 2803 alf->ctb_filt_set_idx_y = ff_vvc_alf_luma_fixed_filter_idx(lc);
2649 }
2650 }
2651
2/2
✓ Branch 0 taken 59406 times.
✓ Branch 1 taken 29703 times.
89109 for (int c_idx = CB; c_idx <= CR; c_idx++) {
2652
2/2
✓ Branch 0 taken 29703 times.
✓ Branch 1 taken 29703 times.
59406 const uint8_t alf_enabled_flag =
2653 c_idx == CB ? sh->sh_alf_cb_enabled_flag : sh->sh_alf_cr_enabled_flag;
2654
2/2
✓ Branch 0 taken 36048 times.
✓ Branch 1 taken 23358 times.
59406 if (alf_enabled_flag) {
2655 36048 const VVCALF *aps = fc->ps.alf_list[sh->sh_alf_aps_id_chroma];
2656 36048 alf->ctb_flag[c_idx] = ff_vvc_alf_ctb_flag(lc, rx, ry, c_idx);
2657 36048 alf->alf_ctb_filter_alt_idx[c_idx - 1] = 0;
2658
4/4
✓ Branch 0 taken 26721 times.
✓ Branch 1 taken 9327 times.
✓ Branch 2 taken 18421 times.
✓ Branch 3 taken 8300 times.
36048 if (alf->ctb_flag[c_idx] && aps->num_chroma_filters > 1)
2659 18421 alf->alf_ctb_filter_alt_idx[c_idx - 1] = ff_vvc_alf_ctb_filter_alt_idx(lc, c_idx, aps->num_chroma_filters);
2660 }
2661 }
2662 }
2663
2/2
✓ Branch 0 taken 43179 times.
✓ Branch 1 taken 12606 times.
55785 if (fc->ps.sps->r->sps_ccalf_enabled_flag) {
2664 43179 const uint8_t cc_enabled[] = { sh->sh_alf_cc_cb_enabled_flag, sh->sh_alf_cc_cr_enabled_flag };
2665 43179 const uint8_t cc_aps_id[] = { sh->sh_alf_cc_cb_aps_id, sh->sh_alf_cc_cr_aps_id };
2666
2/2
✓ Branch 0 taken 86358 times.
✓ Branch 1 taken 43179 times.
129537 for (int i = 0; i < 2; i++) {
2667
2/2
✓ Branch 0 taken 22625 times.
✓ Branch 1 taken 63733 times.
86358 if (cc_enabled[i]) {
2668 22625 const VVCALF *aps = fc->ps.alf_list[cc_aps_id[i]];
2669 22625 alf->ctb_cc_idc[i] = ff_vvc_alf_ctb_cc_idc(lc, rx, ry, i, aps->num_cc_filters[i]);
2670 }
2671 }
2672 }
2673 55785 }
2674
2675 55785 static void deblock_params(VVCLocalContext *lc, const int rx, const int ry)
2676 {
2677 55785 VVCFrameContext *fc = lc->fc;
2678 55785 const VVCSH *sh = &lc->sc->sh;
2679 55785 CTB(fc->tab.deblock, rx, ry) = sh->deblock;
2680 55785 }
2681
2682 55785 static int hls_coding_tree_unit(VVCLocalContext *lc,
2683 const int x0, const int y0, const int ctu_idx, const int rx, const int ry)
2684 {
2685 55785 const VVCFrameContext *fc = lc->fc;
2686 55785 const VVCSPS *sps = fc->ps.sps;
2687 55785 const VVCPPS *pps = fc->ps.pps;
2688 55785 const VVCSH *sh = &lc->sc->sh;
2689 55785 const H266RawSliceHeader *rsh = sh->r;
2690 55785 const unsigned int ctb_size = sps->ctb_size_y;
2691 55785 int ret = 0;
2692
2693 55785 memset(lc->parse.chroma_qp_offset, 0, sizeof(lc->parse.chroma_qp_offset));
2694
2695 55785 hls_sao(lc, x0 >> sps->ctb_log2_size_y, y0 >> sps->ctb_log2_size_y);
2696 55785 alf_params(lc, x0 >> sps->ctb_log2_size_y, y0 >> sps->ctb_log2_size_y);
2697 55785 deblock_params(lc, x0 >> sps->ctb_log2_size_y, y0 >> sps->ctb_log2_size_y);
2698
2699
4/4
✓ Branch 0 taken 6940 times.
✓ Branch 1 taken 48845 times.
✓ Branch 2 taken 6024 times.
✓ Branch 3 taken 916 times.
55785 if (IS_I(rsh) && sps->r->sps_qtbtt_dual_tree_intra_flag)
2700 6024 ret = dual_tree_implicit_qt_split(lc, x0, y0, ctb_size, 0);
2701 else
2702 49761 ret = hls_coding_tree(lc, x0, y0, ctb_size, ctb_size,
2703 1, 1, 0, 0, 0, 0, 0, SPLIT_NONE, SINGLE_TREE, MODE_TYPE_ALL);
2704
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55785 times.
55785 if (ret < 0)
2705 return ret;
2706
2707
2/2
✓ Branch 0 taken 6889 times.
✓ Branch 1 taken 48896 times.
55785 if (rx == pps->ctb_to_col_bd[rx + 1] - 1) {
2708
2/2
✓ Branch 0 taken 1867 times.
✓ Branch 1 taken 5022 times.
6889 if (ctu_idx == sh->num_ctus_in_curr_slice - 1) {
2709 1867 const int end_of_slice_one_bit = ff_vvc_end_of_slice_flag_decode(lc);
2710
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1867 times.
1867 if (!end_of_slice_one_bit)
2711 return AVERROR_INVALIDDATA;
2712 } else {
2713
2/2
✓ Branch 0 taken 527 times.
✓ Branch 1 taken 4495 times.
5022 if (ry == pps->ctb_to_row_bd[ry + 1] - 1) {
2714 527 const int end_of_tile_one_bit = ff_vvc_end_of_tile_one_bit(lc);
2715
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 527 times.
527 if (!end_of_tile_one_bit)
2716 return AVERROR_INVALIDDATA;
2717 } else {
2718
2/2
✓ Branch 0 taken 153 times.
✓ Branch 1 taken 4342 times.
4495 if (fc->ps.sps->r->sps_entropy_coding_sync_enabled_flag) {
2719 153 const int end_of_subset_one_bit = ff_vvc_end_of_subset_one_bit(lc);
2720
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 153 times.
153 if (!end_of_subset_one_bit)
2721 return AVERROR_INVALIDDATA;
2722 }
2723 }
2724 }
2725 }
2726
2727 55785 return 0;
2728 }
2729
2730 629569 static int has_inter_luma(const CodingUnit *cu)
2731 {
2732
5/6
✓ Branch 0 taken 490692 times.
✓ Branch 1 taken 138877 times.
✓ Branch 2 taken 490476 times.
✓ Branch 3 taken 216 times.
✓ Branch 4 taken 490476 times.
✗ Branch 5 not taken.
629569 return cu->pred_mode != MODE_INTRA && cu->pred_mode != MODE_PLT && cu->tree_type != DUAL_TREE_CHROMA;
2733 }
2734
2735 9091196 static int pred_get_y(const VVCLocalContext *lc, const int y0, const Mv *mv, const int height)
2736 {
2737 9091196 const VVCPPS *pps = lc->fc->ps.pps;
2738 9091196 const int idx = lc->sc->sh.r->curr_subpic_idx;
2739 9091196 const int top = pps->subpic_y[idx];
2740 9091196 const int bottom = top + pps->subpic_height[idx];
2741
2742 9091196 return av_clip(y0 + (mv->y >> 4) + height, top, bottom);
2743 }
2744
2745 490476 static void cu_get_max_y(const CodingUnit *cu, int max_y[2][VVC_MAX_REF_ENTRIES], const VVCLocalContext *lc)
2746 {
2747 490476 const VVCFrameContext *fc = lc->fc;
2748 490476 const PredictionUnit *pu = &cu->pu;
2749
2750
2/2
✓ Branch 0 taken 27594 times.
✓ Branch 1 taken 462882 times.
490476 if (pu->merge_gpm_flag) {
2751
2/2
✓ Branch 0 taken 55188 times.
✓ Branch 1 taken 27594 times.
82782 for (int i = 0; i < FF_ARRAY_ELEMS(pu->gpm_mv); i++) {
2752 55188 const MvField *mvf = pu->gpm_mv + i;
2753 55188 const int lx = mvf->pred_flag - PF_L0;
2754 55188 const int idx = mvf->ref_idx[lx];
2755 55188 const int y = pred_get_y(lc, cu->y0, mvf->mv + lx, cu->cb_height);
2756
2757 55188 max_y[lx][idx] = FFMAX(max_y[lx][idx], y);
2758 }
2759 } else {
2760 462882 const MotionInfo *mi = &pu->mi;
2761
4/4
✓ Branch 0 taken 426904 times.
✓ Branch 1 taken 35978 times.
✓ Branch 2 taken 73298 times.
✓ Branch 3 taken 353606 times.
462882 const int max_dmvr_off = (!pu->inter_affine_flag && pu->dmvr_flag) ? 2 : 0;
2762 462882 const int sbw = cu->cb_width / mi->num_sb_x;
2763 462882 const int sbh = cu->cb_height / mi->num_sb_y;
2764
2/2
✓ Branch 0 taken 974488 times.
✓ Branch 1 taken 462882 times.
1437370 for (int sby = 0; sby < mi->num_sb_y; sby++) {
2765
2/2
✓ Branch 0 taken 6164572 times.
✓ Branch 1 taken 974488 times.
7139060 for (int sbx = 0; sbx < mi->num_sb_x; sbx++) {
2766 6164572 const int x0 = cu->x0 + sbx * sbw;
2767 6164572 const int y0 = cu->y0 + sby * sbh;
2768 6164572 const MvField *mvf = ff_vvc_get_mvf(fc, x0, y0);
2769
2/2
✓ Branch 0 taken 12329144 times.
✓ Branch 1 taken 6164572 times.
18493716 for (int lx = 0; lx < 2; lx++) {
2770 12329144 const PredFlag mask = 1 << lx;
2771
2/2
✓ Branch 0 taken 9036008 times.
✓ Branch 1 taken 3293136 times.
12329144 if (mvf->pred_flag & mask) {
2772 9036008 const int idx = mvf->ref_idx[lx];
2773 9036008 const int y = pred_get_y(lc, y0, mvf->mv + lx, sbh);
2774
2775 9036008 max_y[lx][idx] = FFMAX(max_y[lx][idx], y + max_dmvr_off);
2776 }
2777 }
2778 }
2779 }
2780 }
2781 490476 }
2782
2783 55785 static void ctu_get_pred(VVCLocalContext *lc, const int rs)
2784 {
2785 55785 const VVCFrameContext *fc = lc->fc;
2786 55785 const H266RawSliceHeader *rsh = lc->sc->sh.r;
2787 55785 CTU *ctu = fc->tab.ctus + rs;
2788 55785 const CodingUnit *cu = fc->tab.cus[rs];
2789
2790 55785 ctu->has_dmvr = 0;
2791
2792
2/2
✓ Branch 0 taken 6940 times.
✓ Branch 1 taken 48845 times.
55785 if (IS_I(rsh))
2793 6940 return;
2794
2795
2/2
✓ Branch 0 taken 97690 times.
✓ Branch 1 taken 48845 times.
146535 for (int lx = 0; lx < 2; lx++)
2796 97690 memset(ctu->max_y[lx], -1, sizeof(ctu->max_y[0][0]) * rsh->num_ref_idx_active[lx]);
2797
2798
2/2
✓ Branch 0 taken 629569 times.
✓ Branch 1 taken 48845 times.
678414 while (cu) {
2799
2/2
✓ Branch 1 taken 490476 times.
✓ Branch 2 taken 139093 times.
629569 if (has_inter_luma(cu)) {
2800 490476 cu_get_max_y(cu, ctu->max_y, lc);
2801 490476 ctu->has_dmvr |= cu->pu.dmvr_flag;
2802 }
2803 629569 cu = cu->next;
2804 }
2805 48845 ctu->max_y_idx[0] = ctu->max_y_idx[1] = 0;
2806 }
2807
2808 55785 int ff_vvc_coding_tree_unit(VVCLocalContext *lc,
2809 const int ctu_idx, const int rs, const int rx, const int ry)
2810 {
2811 55785 const VVCFrameContext *fc = lc->fc;
2812 55785 const VVCSPS *sps = fc->ps.sps;
2813 55785 const VVCPPS *pps = fc->ps.pps;
2814 55785 const int x_ctb = rx << sps->ctb_log2_size_y;
2815 55785 const int y_ctb = ry << sps->ctb_log2_size_y;
2816 55785 const int ctb_size = 1 << sps->ctb_log2_size_y << sps->ctb_log2_size_y;
2817 55785 EntryPoint* ep = lc->ep;
2818 int ret;
2819
2820
2/2
✓ Branch 0 taken 6889 times.
✓ Branch 1 taken 48896 times.
55785 if (rx == pps->ctb_to_col_bd[rx]) {
2821 6889 ep->num_hmvp = 0;
2822 6889 ep->num_hmvp_ibc = 0;
2823
4/4
✓ Branch 0 taken 4607 times.
✓ Branch 1 taken 2282 times.
✓ Branch 2 taken 112 times.
✓ Branch 3 taken 4495 times.
6889 ep->is_first_qg = ry == pps->ctb_to_row_bd[ry] || !ctu_idx;
2824 }
2825
2826 55785 lc->coeffs = fc->tab.coeffs + rs * ctb_size * VVC_MAX_SAMPLE_ARRAYS;
2827 55785 lc->cu = NULL;
2828
2829 55785 ff_vvc_cabac_init(lc, ctu_idx, rx, ry);
2830 55785 ff_vvc_decode_neighbour(lc, x_ctb, y_ctb, rx, ry, rs);
2831 55785 ret = hls_coding_tree_unit(lc, x_ctb, y_ctb, ctu_idx, rx, ry);
2832
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55785 times.
55785 if (ret < 0)
2833 return ret;
2834 55785 ctu_get_pred(lc, rs);
2835
2836 55785 return 0;
2837 }
2838
2839 373785 void ff_vvc_decode_neighbour(VVCLocalContext *lc, const int x_ctb, const int y_ctb,
2840 const int rx, const int ry, const int rs)
2841 {
2842 373785 VVCFrameContext *fc = lc->fc;
2843 373785 const int ctb_size = fc->ps.sps->ctb_size_y;
2844
2845 373785 lc->end_of_tiles_x = fc->ps.pps->width;
2846 373785 lc->end_of_tiles_y = fc->ps.pps->height;
2847
2/2
✓ Branch 0 taken 46186 times.
✓ Branch 1 taken 327599 times.
373785 if (fc->ps.pps->ctb_to_col_bd[rx] != fc->ps.pps->ctb_to_col_bd[rx + 1])
2848 46186 lc->end_of_tiles_x = FFMIN(x_ctb + ctb_size, lc->end_of_tiles_x);
2849
2/2
✓ Branch 0 taken 73992 times.
✓ Branch 1 taken 299793 times.
373785 if (fc->ps.pps->ctb_to_row_bd[ry] != fc->ps.pps->ctb_to_row_bd[ry + 1])
2850 73992 lc->end_of_tiles_y = FFMIN(y_ctb + ctb_size, lc->end_of_tiles_y);
2851
2852 373785 lc->boundary_flags = 0;
2853
4/4
✓ Branch 0 taken 339582 times.
✓ Branch 1 taken 34203 times.
✓ Branch 2 taken 11983 times.
✓ Branch 3 taken 327599 times.
373785 if (rx > 0 && fc->ps.pps->ctb_to_col_bd[rx] != fc->ps.pps->ctb_to_col_bd[rx - 1])
2854 11983 lc->boundary_flags |= BOUNDARY_LEFT_TILE;
2855
4/4
✓ Branch 0 taken 339582 times.
✓ Branch 1 taken 34203 times.
✓ Branch 2 taken 5425 times.
✓ Branch 3 taken 334157 times.
373785 if (rx > 0 && fc->tab.slice_idx[rs] != fc->tab.slice_idx[rs - 1])
2856 5425 lc->boundary_flags |= BOUNDARY_LEFT_SLICE;
2857
4/4
✓ Branch 0 taken 314332 times.
✓ Branch 1 taken 59453 times.
✓ Branch 2 taken 14539 times.
✓ Branch 3 taken 299793 times.
373785 if (ry > 0 && fc->ps.pps->ctb_to_row_bd[ry] != fc->ps.pps->ctb_to_row_bd[ry - 1])
2858 14539 lc->boundary_flags |= BOUNDARY_UPPER_TILE;
2859
4/4
✓ Branch 0 taken 314332 times.
✓ Branch 1 taken 59453 times.
✓ Branch 2 taken 12341 times.
✓ Branch 3 taken 301991 times.
373785 if (ry > 0 && fc->tab.slice_idx[rs] != fc->tab.slice_idx[rs - fc->ps.pps->ctb_width])
2860 12341 lc->boundary_flags |= BOUNDARY_UPPER_SLICE;
2861
2/2
✓ Branch 0 taken 36366 times.
✓ Branch 1 taken 337419 times.
373785 if (fc->ps.sps->r->sps_subpic_ctu_top_left_x[lc->sc->sh.r->curr_subpic_idx] == rx)
2862 36366 lc->boundary_flags |= BOUNDARY_LEFT_SUBPIC;
2863
2/2
✓ Branch 0 taken 62036 times.
✓ Branch 1 taken 311749 times.
373785 if (fc->ps.sps->r->sps_subpic_ctu_top_left_y[lc->sc->sh.r->curr_subpic_idx] == ry)
2864 62036 lc->boundary_flags |= BOUNDARY_UPPER_SUBPIC;
2865
4/4
✓ Branch 0 taken 339582 times.
✓ Branch 1 taken 34203 times.
✓ Branch 2 taken 327599 times.
✓ Branch 3 taken 11983 times.
373785 lc->ctb_left_flag = rx > 0 && !(lc->boundary_flags & BOUNDARY_LEFT_TILE);
2866
6/6
✓ Branch 0 taken 314332 times.
✓ Branch 1 taken 59453 times.
✓ Branch 2 taken 299793 times.
✓ Branch 3 taken 14539 times.
✓ Branch 4 taken 297441 times.
✓ Branch 5 taken 2352 times.
373785 lc->ctb_up_flag = ry > 0 && !(lc->boundary_flags & BOUNDARY_UPPER_TILE) && !(lc->boundary_flags & BOUNDARY_UPPER_SLICE);
2867
4/4
✓ Branch 0 taken 297441 times.
✓ Branch 1 taken 76344 times.
✓ Branch 2 taken 267698 times.
✓ Branch 3 taken 29743 times.
641483 lc->ctb_up_right_flag = lc->ctb_up_flag && (fc->ps.pps->ctb_to_col_bd[rx] == fc->ps.pps->ctb_to_col_bd[rx + 1]) &&
2868
1/2
✓ Branch 0 taken 267698 times.
✗ Branch 1 not taken.
267698 (fc->ps.pps->ctb_to_row_bd[ry] == fc->ps.pps->ctb_to_row_bd[ry - 1]);
2869
4/4
✓ Branch 0 taken 327599 times.
✓ Branch 1 taken 46186 times.
✓ Branch 2 taken 267698 times.
✓ Branch 3 taken 59901 times.
373785 lc->ctb_up_left_flag = lc->ctb_left_flag && lc->ctb_up_flag;
2870 373785 }
2871
2872 2989599 void ff_vvc_set_neighbour_available(VVCLocalContext *lc,
2873 const int x0, const int y0, const int w, const int h)
2874 {
2875 2989599 const int log2_ctb_size = lc->fc->ps.sps->ctb_log2_size_y;
2876 2989599 const int x0b = av_zero_extend(x0, log2_ctb_size);
2877 2989599 const int y0b = av_zero_extend(y0, log2_ctb_size);
2878
2879
4/4
✓ Branch 0 taken 890054 times.
✓ Branch 1 taken 2099545 times.
✓ Branch 2 taken 797042 times.
✓ Branch 3 taken 93012 times.
2989599 lc->na.cand_up = (lc->ctb_up_flag || y0b);
2880
4/4
✓ Branch 0 taken 570127 times.
✓ Branch 1 taken 2419472 times.
✓ Branch 2 taken 496492 times.
✓ Branch 3 taken 73635 times.
2989599 lc->na.cand_left = (lc->ctb_left_flag || x0b);
2881
8/8
✓ Branch 0 taken 457016 times.
✓ Branch 1 taken 2532583 times.
✓ Branch 2 taken 330762 times.
✓ Branch 3 taken 126254 times.
✓ Branch 4 taken 2805994 times.
✓ Branch 5 taken 57351 times.
✓ Branch 6 taken 2739308 times.
✓ Branch 7 taken 66686 times.
2989599 lc->na.cand_up_left = (x0b || y0b) ? lc->na.cand_left && lc->na.cand_up : lc->ctb_up_left_flag;
2882 2989599 lc->na.cand_up_right_sap =
2883
6/6
✓ Branch 0 taken 425496 times.
✓ Branch 1 taken 2564103 times.
✓ Branch 2 taken 294999 times.
✓ Branch 3 taken 130497 times.
✓ Branch 4 taken 89474 times.
✓ Branch 5 taken 205525 times.
2989599 (x0b + w == 1 << log2_ctb_size) ? lc->ctb_up_right_flag && !y0b : lc->na.cand_up;
2884
4/4
✓ Branch 0 taken 2585142 times.
✓ Branch 1 taken 404457 times.
✓ Branch 2 taken 2562199 times.
✓ Branch 3 taken 22943 times.
2989599 lc->na.cand_up_right = lc->na.cand_up_right_sap && (x0 + w) < lc->end_of_tiles_x;
2885 2989599 }
2886
2887 111570 void ff_vvc_ctu_free_cus(CodingUnit **cus)
2888 {
2889
2/2
✓ Branch 0 taken 1386881 times.
✓ Branch 1 taken 111570 times.
1498451 while (*cus) {
2890 1386881 CodingUnit *cu = *cus;
2891 1386881 TransformUnit **head = &cu->tus.head;
2892
2893 1386881 *cus = cu->next;
2894
2895
2/2
✓ Branch 0 taken 1707295 times.
✓ Branch 1 taken 1386881 times.
3094176 while (*head) {
2896 1707295 TransformUnit *tu = *head;
2897 1707295 *head = tu->next;
2898 1707295 av_refstruct_unref(&tu);
2899 }
2900 1386881 cu->tus.tail = NULL;
2901
2902 1386881 av_refstruct_unref(&cu);
2903 }
2904 111570 }
2905
2906 16956859 int ff_vvc_get_qPy(const VVCFrameContext *fc, const int xc, const int yc)
2907 {
2908 16956859 const int min_cb_log2_size_y = fc->ps.sps->min_cb_log2_size_y;
2909 16956859 const int x = xc >> min_cb_log2_size_y;
2910 16956859 const int y = yc >> min_cb_log2_size_y;
2911 16956859 return fc->tab.qp[LUMA][x + y * fc->ps.pps->min_cb_width];
2912 }
2913
2914 2547 void ff_vvc_ep_init_stat_coeff(EntryPoint *ep,
2915 const int bit_depth, const int persistent_rice_adaptation_enabled_flag)
2916 {
2917
2/2
✓ Branch 0 taken 7641 times.
✓ Branch 1 taken 2547 times.
10188 for (size_t i = 0; i < FF_ARRAY_ELEMS(ep->stat_coeff); ++i) {
2918 7641 ep->stat_coeff[i] =
2919
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7641 times.
7641 persistent_rice_adaptation_enabled_flag ? 2 * (av_log2(bit_depth - 10)) : 0;
2920 }
2921 2547 }
2922
2923 744866 void ff_vvc_channel_range(int *start, int *end, const VVCTreeType tree_type, const uint8_t chroma_format_idc)
2924 {
2925
4/4
✓ Branch 0 taken 728355 times.
✓ Branch 1 taken 16511 times.
✓ Branch 2 taken 585812 times.
✓ Branch 3 taken 142543 times.
744866 const bool has_chroma = chroma_format_idc && tree_type != DUAL_TREE_LUMA;
2926 744866 const bool has_luma = tree_type != DUAL_TREE_CHROMA;
2927
2928 744866 *start = has_luma ? LUMA : CB;
2929
2/2
✓ Branch 0 taken 585812 times.
✓ Branch 1 taken 159054 times.
744866 *end = has_chroma ? VVC_MAX_SAMPLE_ARRAYS : CB;
2930 744866 }
2931